-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: adc: add some missing system calls
Setting callbacks is forbidden from user mode. Some heavier code changes will be needed to support adc_read_async(), this patch just exposes the config and read functions for now. Test case updated to run partially in user mode. Signed-off-by: Andrew Boie <[email protected]>
- Loading branch information
Showing
5 changed files
with
93 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2019 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <adc.h> | ||
#include <syscall_handler.h> | ||
#include <kernel.h> | ||
|
||
Z_SYSCALL_HANDLER(adc_channel_setup, dev, user_channel_cfg) | ||
{ | ||
struct adc_channel_cfg channel_cfg; | ||
|
||
Z_OOPS(Z_SYSCALL_DRIVER_ADC(dev, channel_setup)); | ||
Z_OOPS(z_user_from_copy(&channel_cfg, | ||
(struct adc_channel_cfg *)user_channel_cfg, | ||
sizeof(struct adc_channel_cfg))); | ||
|
||
return z_impl_adc_channel_setup((struct device *)dev, &channel_cfg); | ||
} | ||
|
||
static bool copy_sequence(struct adc_sequence *dst, | ||
struct adc_sequence_options *options, | ||
struct adc_sequence *src) | ||
{ | ||
if (z_user_from_copy(dst, src, sizeof(struct adc_sequence)) != 0) { | ||
printk("couldn't copy adc_sequence struct\n"); | ||
return false; | ||
} | ||
|
||
if (dst->options) { | ||
if (z_user_from_copy(options, dst->options, | ||
sizeof(struct adc_sequence_options)) != 0) { | ||
printk("couldn't copy adc_options struct\n"); | ||
return false; | ||
} | ||
dst->options = options; | ||
} | ||
|
||
if (Z_SYSCALL_MEMORY_WRITE(dst->buffer, dst->buffer_size) != 0) { | ||
printk("no access to buffer memory\n"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
|
||
Z_SYSCALL_HANDLER(adc_read, dev, user_sequence) | ||
{ | ||
struct adc_sequence sequence; | ||
struct adc_sequence_options options; | ||
|
||
Z_OOPS(Z_SYSCALL_DRIVER_ADC(dev, read)); | ||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(copy_sequence(&sequence, &options, | ||
(struct adc_sequence *)user_sequence), | ||
"invalid ADC sequence")); | ||
if (sequence.options != NULL) { | ||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(sequence.options->callback == NULL, | ||
"ADC sequence callbacks forbidden from user mode")); | ||
} | ||
|
||
return z_impl_adc_read((struct device *)dev, &sequence); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters