# # Grand Unified Makefile for Xen. # # Default target must appear before any include lines .PHONY: all all: dist -include config/Toplevel.mk SUBSYSTEMS?=xen kernels tools stubdom docs TARGS_DIST=$(patsubst %, dist-%, $(SUBSYSTEMS)) TARGS_INSTALL=$(patsubst %, install-%, $(SUBSYSTEMS)) export XEN_ROOT=$(CURDIR) include Config.mk SUBARCH := $(subst x86_32,i386,$(XEN_TARGET_ARCH)) export XEN_TARGET_ARCH SUBARCH XEN_SYSTYPE include buildconfigs/Rules.mk # build and install everything into the standard system directories .PHONY: install install: $(TARGS_INSTALL) .PHONY: build build: kernels $(MAKE) -C xen build $(MAKE) -C tools build $(MAKE) -C stubdom build ifeq (x86_64,$(XEN_TARGET_ARCH)) XEN_TARGET_ARCH=x86_32 $(MAKE) -C stubdom pv-grub endif $(MAKE) -C docs build # The test target is for unit tests that can run without an installation. Of # course, many tests require a machine running Xen itself, and these are # handled elsewhere. .PHONY: test test: $(MAKE) -C tools/python test # build and install everything into local dist directory .PHONY: dist dist: DESTDIR=$(DISTDIR)/install dist: $(TARGS_DIST) dist-misc dist-misc: $(INSTALL_DIR) $(DISTDIR)/ $(INSTALL_DATA) ./COPYING $(DISTDIR) $(INSTALL_DATA) ./README $(DISTDIR) $(INSTALL_PROG) ./install.sh $(DISTDIR) dist-%: DESTDIR=$(DISTDIR)/install dist-%: install-% @: # do nothing # Legacy dist targets .PHONY: xen tools stubdom kernels docs xen: dist-xen tools: dist-tools kernels: dist-kernels stubdom: dist-stubdom docs: dist-docs .PHONY: prep-kernels prep-kernels: for i in $(XKERNELS) ; do $(MAKE) $$i-prep || exit 1; done .PHONY: install-xen install-xen: $(MAKE) -C xen install ifeq ($(CONFIG_QEMU_TRAD),y) QEMU_TRAD_DIR_TGT := tools/qemu-xen-traditional-dir tools/qemu-xen-traditional-dir: $(MAKE) -C tools qemu-xen-traditional-dir-find .PHONY: tools/qemu-xen-traditional-dir-force-update tools/qemu-xen-traditional-dir-force-update: $(MAKE) -C tools qemu-xen-traditional-dir-force-update endif ifeq ($(CONFIG_QEMU_XEN),y) QEMU_XEN_DIR_TGT := tools/qemu-xen-dir tools/qemu-xen-dir: $(MAKE) -C tools qemu-xen-dir-find .PHONY: tools/qemu-xen-dir-force-update tools/qemu-xen-dir-force-update: $(MAKE) -C tools qemu-xen-dir-force-update endif .PHONY: install-tools install-tools: $(QEMU_TRAD_DIR_TARGET) $(QEMU_XEN_DIR_TARGET) $(MAKE) -C tools install .PHONY: install-kernels install-kernels: for i in $(XKERNELS) ; do $(MAKE) $$i-install || exit 1; done .PHONY: install-stubdom install-stubdom: $(QEMU_TRAD_DIR_TARGET) install-tools $(MAKE) -C stubdom install ifeq (x86_64,$(XEN_TARGET_ARCH)) XEN_TARGET_ARCH=x86_32 $(MAKE) -C stubdom install-grub endif .PHONY: tools/firmware/seabios-dir-force-update tools/firmware/seabios-dir-force-update: $(MAKE) -C tools/firmware seabios-dir-force-update .PHONY: install-docs install-docs: $(MAKE) -C docs install .PHONY: dev-docs dev-docs: $(MAKE) -C docs dev-docs # Build all the various kernels and modules .PHONY: kbuild kbuild: kernels # Delete the kernel build trees entirely .PHONY: kdelete kdelete: for i in $(XKERNELS) ; do $(MAKE) $$i-delete ; done # Clean the kernel build trees .PHONY: kclean kclean: for i in $(XKERNELS) ; do $(MAKE) $$i-clean ; done # build xen, the tools, and a domain 0 plus unprivileged linux-xen images, # and place them in the install directory. 'make install' should then # copy them to the normal system directories .PHONY: world world: $(MAKE) clean $(MAKE) kdelete $(MAKE) dist # Package a build in a debball file, that is inside a .deb format # container to allow for easy and clean removal. This is not intended # to be a full featured policy compliant .deb package. .PHONY: debball debball: dist fakeroot sh ./tools/misc/mkdeb $(XEN_ROOT) $$($(MAKE) -C xen xenversion | grep -v :) # clean doesn't do a kclean .PHONY: clean clean:: $(MAKE) -C xen clean $(MAKE) -C tools clean $(MAKE) -C stubdom crossclean ifeq (x86_64,$(XEN_TARGET_ARCH)) XEN_TARGET_ARCH=x86_32 $(MAKE) -C stubdom crossclean endif $(MAKE) -C docs clean # clean, but blow away kernel build tree plus tarballs .PHONY: distclean distclean: rm -f config/Toplevel.mk $(MAKE) -C xen distclean $(MAKE) -C tools distclean $(MAKE) -C stubdom distclean ifeq (x86_64,$(XEN_TARGET_ARCH)) XEN_TARGET_ARCH=x86_32 $(MAKE) -C stubdom distclean endif $(MAKE) -C docs distclean rm -rf dist patches/tmp for i in $(ALLKERNELS) ; do $(MAKE) $$i-delete ; done rm -rf patches/*/.makedep rm -rf config.log config.status config.cache autom4te.cache # Linux name for GNU distclean .PHONY: mrproper mrproper: distclean # Prepare for source tarball .PHONY: src-tarball src-tarball: distclean $(MAKE) -C xen .banner rm -rf xen/tools/figlet .[a-z]* $(MAKE) -C xen distclean .PHONY: help help: @echo 'Installation targets:' @echo ' install - build and install everything' @echo ' install-xen - build and install the Xen hypervisor' @echo ' install-tools - build and install the control tools' @echo ' install-kernels - build and install guest kernels' @echo ' install-stubdom - build and install the stubdomain images' @echo ' install-docs - build and install user documentation' @echo '' @echo 'Building targets:' @echo ' dist - build and install everything into local dist directory' @echo ' world - clean everything, delete guest kernel build' @echo ' trees then make dist' @echo ' xen - build and install Xen hypervisor' @echo ' tools - build and install tools' @echo ' stubdom - build and install the stubdomain images' @echo ' kernels - build and install guest kernels' @echo ' kbuild - synonym for make kernels' @echo ' docs - build and install user documentation' @echo ' dev-docs - build developer-only documentation' @echo '' @echo 'Cleaning targets:' @echo ' clean - clean the Xen, tools and docs (but not guest kernel trees)' @echo ' distclean - clean plus delete kernel build trees and' @echo ' local downloaded files' @echo ' kdelete - delete guest kernel build trees' @echo ' kclean - clean guest kernel build trees' @echo '' @echo 'Miscellaneous targets:' @echo ' prep-kernels - prepares kernel directories, does not build' @echo ' uninstall - attempt to remove installed Xen tools' @echo ' (use with extreme care!)' @echo @echo 'Trusted Boot (tboot) targets:' @echo ' build-tboot - download and build the tboot module' @echo ' install-tboot - download, build, and install the tboot module' @echo ' clean-tboot - clean the tboot module if it exists' @echo @echo 'Environment:' @echo ' [ this documentation is sadly not complete ]' # Use this target with extreme care! .PHONY: uninstall uninstall: D=$(DESTDIR) uninstall: [ -d $(D)$(XEN_CONFIG_DIR) ] && mv -f $(D)$(XEN_CONFIG_DIR) $(D)$(XEN_CONFIG_DIR).old-`date +%s` || true $(MAKE) -C xen uninstall rm -rf $(D)$(CONFIG_DIR)/init.d/xendomains $(D)$(CONFIG_DIR)/init.d/xend rm -rf $(D)$(CONFIG_DIR)/init.d/xencommons $(D)$(CONFIG_DIR)/init.d/xen-watchdog rm -f $(D)$(CONFIG_DIR)/udev/rules.d/xen-backend.rules rm -f $(D)$(CONFIG_DIR)/udev/rules.d/xend.rules rm -f $(D)$(SYSCONFIG_DIR)/xendomains rm -f $(D)$(SYSCONFIG_DIR)/xencommons rm -rf $(D)/var/run/xen* $(D)/var/lib/xen* make -C tools uninstall rm -rf $(D)/boot/tboot* # Legacy targets for compatibility .PHONY: linux26 linux26: $(MAKE) 'KERNELS=linux-2.6*' kernels .PHONY: xenversion xenversion: @$(MAKE) --no-print-directory -C xen xenversion # # tboot targets # TBOOT_TARFILE = tboot-20090330.tar.gz #TBOOT_BASE_URL = http://downloads.sourceforge.net/tboot TBOOT_BASE_URL = $(XEN_EXTFILES_URL) .PHONY: build-tboot build-tboot: download_tboot $(MAKE) -C tboot build .PHONY: install-tboot install-tboot: download_tboot $(MAKE) -C tboot install .PHONY: dist-tboot dist-tboot: download_tboot $(MAKE) DESTDIR=$(DISTDIR)/install -C tboot dist .PHONY: clean-tboot clean-tboot: [ ! -d tboot ] || $(MAKE) -C tboot clean .PHONY: distclean-tboot distclean-tboot: [ ! -d tboot ] || $(MAKE) -C tboot distclean .PHONY: download_tboot download_tboot: tboot/Makefile tboot/Makefile: tboot/$(TBOOT_TARFILE) [ -e tboot/Makefile ] || tar -xzf tboot/$(TBOOT_TARFILE) -C tboot/ --strip-components 1 tboot/$(TBOOT_TARFILE): mkdir -p tboot wget -O tboot/$(TBOOT_TARFILE) $(TBOOT_BASE_URL)/$(TBOOT_TARFILE) 169'>169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
/*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
2011,2012 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file can.c
* @brief CAN Driver code.
*
* @addtogroup CAN
* @{
*/
#include "ch.h"
#include "hal.h"
#if HAL_USE_CAN || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/**
* @brief CAN Driver initialization.
* @note This function is implicitly invoked by @p halInit(), there is
* no need to explicitly initialize the driver.
*
* @init
*/
void canInit(void) {
can_lld_init();
}
/**
* @brief Initializes the standard part of a @p CANDriver structure.
*
* @param[out] canp pointer to the @p CANDriver object
*
* @init
*/
void canObjectInit(CANDriver *canp) {
canp->state = CAN_STOP;
canp->config = NULL;
chSemInit(&canp->txsem, 0);
chSemInit(&canp->rxsem, 0);
chEvtInit(&canp->rxfull_event);
chEvtInit(&canp->txempty_event);
chEvtInit(&canp->error_event);
#if CAN_USE_SLEEP_MODE
chEvtInit(&canp->sleep_event);
chEvtInit(&canp->wakeup_event);
#endif /* CAN_USE_SLEEP_MODE */
}
/**
* @brief Configures and activates the CAN peripheral.
* @note Activating the CAN bus can be a slow operation this this function
* is not atomic, it waits internally for the initialization to
* complete.
*
* @param[in] canp pointer to the @p CANDriver object
* @param[in] config pointer to the @p CANConfig object. Depending on
* the implementation the value can be @p NULL.
*
* @api
*/
void canStart(CANDriver *canp, const CANConfig *config) {
chDbgCheck(canp != NULL, "canStart");
chSysLock();
chDbgAssert((canp->state == CAN_STOP) ||
(canp->state == CAN_STARTING) ||
(canp->state == CAN_READY),
"canStart(), #1", "invalid state");
while (canp->state == CAN_STARTING)
chThdSleepS(1);
if (canp->state == CAN_STOP) {
canp->config = config;
can_lld_start(canp);
canp->state = CAN_READY;
}
chSysUnlock();
}
/**
* @brief Deactivates the CAN peripheral.
*
* @param[in] canp pointer to the @p CANDriver object
*
* @api
*/
void canStop(CANDriver *canp) {
chDbgCheck(canp != NULL, "canStop");
chSysLock();
chDbgAssert((canp->state == CAN_STOP) || (canp->state == CAN_READY),
"canStop(), #1", "invalid state");
can_lld_stop(canp);
chSemResetI(&canp->rxsem, 0);
chSemResetI(&canp->txsem, 0);
chSchRescheduleS();
canp->state = CAN_STOP;
chSysUnlock();
}
/**
* @brief Can frame transmission.
* @details The specified frame is queued for transmission, if the hardware
* queue is full then the invoking thread is queued.
* @note Trying to transmit while in sleep mode simply enqueues the thread.
*
* @param[in] canp pointer to the @p CANDriver object
* @param[in] ctfp pointer to the CAN frame to be transmitted
* @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
* .
* @return The operation result.
* @retval RDY_OK the frame has been queued for transmission.
* @retval RDY_TIMEOUT The operation has timed out.
* @retval RDY_RESET The driver has been stopped while waiting.
*
* @api
*/
msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) {
chDbgCheck((canp != NULL) && (ctfp != NULL), "canTransmit");
chSysLock();
chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP),
"canTransmit(), #1", "invalid state");
while ((canp->state == CAN_SLEEP) || !can_lld_can_transmit(canp)) {
msg_t msg = chSemWaitTimeoutS(&canp->txsem, timeout);
if (msg != RDY_OK) {
chSysUnlock();
return msg;
}
}
can_lld_transmit(canp, ctfp);
chSysUnlock();
return RDY_OK;
}
/**
* @brief Can frame receive.
* @details The function waits until a frame is received.
* @note Trying to receive while in sleep mode simply enqueues the thread.
*
* @param[in] canp pointer to the @p CANDriver object
* @param[out] crfp pointer to the buffer where the CAN frame is copied
* @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout (useful in an
* event driven scenario where a thread never blocks
* for I/O).
* - @a TIME_INFINITE no timeout.
* .
* @return The operation result.
* @retval RDY_OK a frame has been received and placed in the buffer.
* @retval RDY_TIMEOUT The operation has timed out.
* @retval RDY_RESET The driver has been stopped while waiting.
*
* @api
*/
msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) {
chDbgCheck((canp != NULL) && (crfp != NULL), "canReceive");
chSysLock();
chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP),
"canReceive(), #1", "invalid state");
while ((canp->state == CAN_SLEEP) || !can_lld_can_receive(canp)) {
msg_t msg = chSemWaitTimeoutS(&canp->rxsem, timeout);
if (msg != RDY_OK) {
chSysUnlock();
return msg;
}
}
can_lld_receive(canp, crfp);
chSysUnlock();
return RDY_OK;
}
#if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__)
/**
* @brief Enters the sleep mode.
* @details This function puts the CAN driver in sleep mode and broadcasts
* the @p sleep_event event source.
* @pre In order to use this function the option @p CAN_USE_SLEEP_MODE must
* be enabled and the @p CAN_SUPPORTS_SLEEP mode must be supported
* by the low level driver.
*
* @param[in] canp pointer to the @p CANDriver object
*
* @api
*/
void canSleep(CANDriver *canp) {
chDbgCheck(canp != NULL, "canSleep");
chSysLock();
chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP),
"canSleep(), #1", "invalid state");
if (canp->state == CAN_READY) {
can_lld_sleep(canp);
canp->state = CAN_SLEEP;
chEvtBroadcastI(&canp->sleep_event);
chSchRescheduleS();
}
chSysUnlock();
}
/**
* @brief Enforces leaving the sleep mode.
* @note The sleep mode is supposed to be usually exited automatically by
* an hardware event.
*
* @param[in] canp pointer to the @p CANDriver object
*/
void canWakeup(CANDriver *canp) {
chDbgCheck(canp != NULL, "canWakeup");
chSysLock();
chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP),
"canWakeup(), #1", "invalid state");
if (canp->state == CAN_SLEEP) {
can_lld_wakeup(canp);
canp->state = CAN_READY;
chEvtBroadcastI(&canp->wakeup_event);
chSchRescheduleS();
}
chSysUnlock();
}
#endif /* CAN_USE_SLEEP_MODE */
#endif /* HAL_USE_CAN */
/** @} */