Skip to content

Commit ad4df68

Browse files
Andrew Boienashif
authored andcommitted
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 <[email protected]>
1 parent 76a160b commit ad4df68

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

drivers/i2s/i2s_handlers.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,38 @@
88
#include <syscall_handler.h>
99
#include <i2s.h>
1010

11+
12+
Z_SYSCALL_HANDLER(i2s_configure, dev, dir, cfg_ptr)
13+
{
14+
struct i2s_config config;
15+
int ret = -EINVAL;
16+
17+
if (Z_SYSCALL_DRIVER_I2S(dev, configure)) {
18+
goto out;
19+
}
20+
21+
Z_OOPS(z_user_from_copy(&config, (void *)cfg_ptr,
22+
sizeof(struct i2s_config)));
23+
24+
/* Check that the k_mem_slab provided is a valid pointer and that
25+
* the caller has permission on it
26+
*/
27+
if (Z_SYSCALL_OBJ(config.mem_slab, K_OBJ_MEM_SLAB)) {
28+
goto out;
29+
}
30+
31+
/* Ensure that the k_mem_slab's slabs are large enough for the
32+
* specified block size
33+
*/
34+
if (config.block_size > config.mem_slab->block_size) {
35+
goto out;
36+
}
37+
38+
ret = _impl_i2s_configure((struct device *)dev, dir, &config);
39+
out:
40+
return ret;
41+
}
42+
1143
Z_SYSCALL_HANDLER(i2s_buf_read, dev, buf, size)
1244
{
1345
void *mem_block;

include/i2s.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,11 @@ struct i2s_driver_api {
346346
* @retval 0 If successful.
347347
* @retval -EINVAL Invalid argument.
348348
*/
349-
static inline int i2s_configure(struct device *dev, enum i2s_dir dir,
350-
struct i2s_config *cfg)
349+
__syscall int i2s_configure(struct device *dev, enum i2s_dir dir,
350+
struct i2s_config *cfg);
351+
352+
static inline int _impl_i2s_configure(struct device *dev, enum i2s_dir dir,
353+
struct i2s_config *cfg)
351354
{
352355
const struct i2s_driver_api *api = dev->driver_api;
353356

0 commit comments

Comments
 (0)