From ad4df685f16054e3cc2df8e9f419f8ac4acbf1bf Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Wed, 14 Nov 2018 15:00:27 -0800 Subject: [PATCH] i2s: add i2s_configure() as a system call Now that k_mem_slabs are tracked as kernel objects, even though they have no user facing API, we can now accept a pointer to one in the configure API. Signed-off-by: Andrew Boie --- drivers/i2s/i2s_handlers.c | 32 ++++++++++++++++++++++++++++++++ include/i2s.h | 7 +++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/i2s/i2s_handlers.c b/drivers/i2s/i2s_handlers.c index d8123ef57cb..063024a7c75 100644 --- a/drivers/i2s/i2s_handlers.c +++ b/drivers/i2s/i2s_handlers.c @@ -8,6 +8,38 @@ #include #include + +Z_SYSCALL_HANDLER(i2s_configure, dev, dir, cfg_ptr) +{ + struct i2s_config config; + int ret = -EINVAL; + + if (Z_SYSCALL_DRIVER_I2S(dev, configure)) { + goto out; + } + + Z_OOPS(z_user_from_copy(&config, (void *)cfg_ptr, + sizeof(struct i2s_config))); + + /* Check that the k_mem_slab provided is a valid pointer and that + * the caller has permission on it + */ + if (Z_SYSCALL_OBJ(config.mem_slab, K_OBJ_MEM_SLAB)) { + goto out; + } + + /* Ensure that the k_mem_slab's slabs are large enough for the + * specified block size + */ + if (config.block_size > config.mem_slab->block_size) { + goto out; + } + + ret = _impl_i2s_configure((struct device *)dev, dir, &config); +out: + return ret; +} + Z_SYSCALL_HANDLER(i2s_buf_read, dev, buf, size) { void *mem_block; diff --git a/include/i2s.h b/include/i2s.h index a146cd6c56b..ee027c7606c 100644 --- a/include/i2s.h +++ b/include/i2s.h @@ -346,8 +346,11 @@ struct i2s_driver_api { * @retval 0 If successful. * @retval -EINVAL Invalid argument. */ -static inline int i2s_configure(struct device *dev, enum i2s_dir dir, - struct i2s_config *cfg) +__syscall int i2s_configure(struct device *dev, enum i2s_dir dir, + struct i2s_config *cfg); + +static inline int _impl_i2s_configure(struct device *dev, enum i2s_dir dir, + struct i2s_config *cfg) { const struct i2s_driver_api *api = dev->driver_api;