diff --git a/drivers/dma/CMakeLists.txt b/drivers/dma/CMakeLists.txt index 748d89a8191..63813f546e8 100644 --- a/drivers/dma/CMakeLists.txt +++ b/drivers/dma/CMakeLists.txt @@ -1,3 +1,5 @@ zephyr_sources_ifdef(CONFIG_DMA_QMSI dma_qmsi.c) zephyr_sources_ifdef(CONFIG_DMA_SAM_XDMAC dma_sam_xdmac.c) zephyr_sources_ifdef(CONFIG_DMA_STM32F4X dma_stm32f4x.c) + +zephyr_sources_ifdef(CONFIG_USERSPACE dma_handlers.c) diff --git a/drivers/dma/dma_handlers.c b/drivers/dma/dma_handlers.c new file mode 100644 index 00000000000..8d20ed385b8 --- /dev/null +++ b/drivers/dma/dma_handlers.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* Both of these APIs are assuming that the drive implementations are checking + * the validity of the channel ID and returning -errno if it's bogus + */ + +_SYSCALL_HANDLER(dma_start, dev, channel) +{ + _SYSCALL_OBJ(dev, K_OBJ_DRIVER_DMA); + return _impl_dma_start((struct device *)dev, channel); +} + +_SYSCALL_HANDLER(dma_stop, dev, channel) +{ + _SYSCALL_OBJ(dev, K_OBJ_DRIVER_DMA); + return _impl_dma_stop((struct device *)dev, channel); +} + diff --git a/include/dma.h b/include/dma.h index bab824b8db2..4ab16906236 100644 --- a/include/dma.h +++ b/include/dma.h @@ -190,6 +190,9 @@ static inline int dma_config(struct device *dev, u32_t channel, * @brief Enables DMA channel and starts the transfer, the channel must be * configured beforehand. * + * Implementations must check the validity of the channel ID passed in and + * return -EINVAL if it is invalid. + * * @param dev Pointer to the device structure for the driver instance. * @param channel Numeric identification of the channel where the transfer will * be processed @@ -197,7 +200,9 @@ static inline int dma_config(struct device *dev, u32_t channel, * @retval 0 if successful. * @retval Negative errno code if failure. */ -static inline int dma_start(struct device *dev, u32_t channel) +__syscall int dma_start(struct device *dev, u32_t channel); + +static inline int _impl_dma_start(struct device *dev, u32_t channel) { const struct dma_driver_api *api = dev->driver_api; @@ -207,6 +212,9 @@ static inline int dma_start(struct device *dev, u32_t channel) /** * @brief Stops the DMA transfer and disables the channel. * + * Implementations must check the validity of the channel ID passed in and + * return -EINVAL if it is invalid. + * * @param dev Pointer to the device structure for the driver instance. * @param channel Numeric identification of the channel where the transfer was * being processed @@ -214,7 +222,9 @@ static inline int dma_start(struct device *dev, u32_t channel) * @retval 0 if successful. * @retval Negative errno code if failure. */ -static inline int dma_stop(struct device *dev, u32_t channel) +__syscall int dma_stop(struct device *dev, u32_t channel); + +static inline int _impl_dma_stop(struct device *dev, u32_t channel) { const struct dma_driver_api *api = dev->driver_api; diff --git a/include/kernel.h b/include/kernel.h index 544a9a5d173..f7994383494 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -150,6 +150,7 @@ enum k_objects { K_OBJ_DRIVER_AIO_CMP, K_OBJ_DRIVER_COUNTER, K_OBJ_DRIVER_CRYPTO, + K_OBJ_DRIVER_DMA, K_OBJ_DRIVER_FLASH, K_OBJ_DRIVER_GPIO, K_OBJ_DRIVER_I2C, diff --git a/kernel/userspace.c b/kernel/userspace.c index 9c68778c3bf..d1c75d924ab 100644 --- a/kernel/userspace.c +++ b/kernel/userspace.c @@ -53,6 +53,8 @@ const char *otype_to_str(enum k_objects otype) return "counter driver"; case K_OBJ_DRIVER_CRYPTO: return "crypto driver"; + case K_OBJ_DRIVER_DMA: + return "dma driver"; case K_OBJ_DRIVER_FLASH: return "flash driver"; case K_OBJ_DRIVER_GPIO: diff --git a/scripts/gen_kobject_list.py b/scripts/gen_kobject_list.py index 2fed49d098b..50b1ce51cb0 100755 --- a/scripts/gen_kobject_list.py +++ b/scripts/gen_kobject_list.py @@ -29,6 +29,7 @@ subsystems = [ "aio_cmp_driver_api", "counter_driver_api", "crypto_driver_api", + "dma_driver_api", "flash_driver_api", "gpio_driver_api", "i2c_driver_api",