drivers: adc: add system call handlers

Straightforward conversion for adc_enable/disable.

adc_read() uses a sequence table, which points to an array
of struct adc_seq_entry, each element pointing
to memory buffers. Need to validate all of these as being readable
by the caller, and the buffers writable.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-10-25 10:48:07 -07:00 committed by Andrew Boie
parent 2a2a855aa8
commit c93a4789cb
3 changed files with 43 additions and 3 deletions

View File

@ -4,3 +4,4 @@ obj-$(CONFIG_ADC_TI_ADC108S102) += adc_ti_adc108s102.o
obj-$(CONFIG_ADC_QMSI) += adc_qmsi.o
obj-$(CONFIG_ADC_QMSI_SS) += adc_qmsi_ss.o
obj-$(CONFIG_ADC_SAM_AFEC) += adc_sam_afec.o
obj-$(CONFIG_USERSPACE) += adc_handlers.o

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <adc.h>
#include <syscall_handler.h>
_SYSCALL_HANDLER1_SIMPLE_VOID(adc_enable, K_OBJ_DRIVER_ADC, struct device *);
_SYSCALL_HANDLER1_SIMPLE_VOID(adc_disable, K_OBJ_DRIVER_ADC, struct device *);
_SYSCALL_HANDLER(adc_read, dev, seq_table_p)
{
struct adc_seq_entry *entry;
struct adc_seq_table *seq_table = (struct adc_seq_table *)seq_table_p;
int i;
_SYSCALL_OBJ(dev, K_OBJ_DRIVER_ADC);
_SYSCALL_MEMORY_READ(seq_table, sizeof(struct adc_seq_table));
_SYSCALL_MEMORY_ARRAY_READ(seq_table->entries, seq_table->num_entries,
sizeof(struct adc_seq_entry));
for (entry = seq_table->entries, i = 0; i < seq_table->num_entries;
i++, entry++) {
_SYSCALL_MEMORY_WRITE(entry->buffer, entry->buffer_length);
}
return _impl_adc_read((struct device *)dev, seq_table);
}

View File

@ -89,7 +89,9 @@ struct adc_driver_api {
*
* @return N/A
*/
static inline void adc_enable(struct device *dev)
__syscall void adc_enable(struct device *dev);
static inline void _impl_adc_enable(struct device *dev)
{
const struct adc_driver_api *api = dev->driver_api;
@ -106,7 +108,9 @@ static inline void adc_enable(struct device *dev)
*
* @return N/A
*/
static inline void adc_disable(struct device *dev)
__syscall void adc_disable(struct device *dev);
static inline void _impl_adc_disable(struct device *dev)
{
const struct adc_driver_api *api = dev->driver_api;
@ -128,7 +132,10 @@ static inline void adc_disable(struct device *dev)
* @retval 0 On success
* @retval else Otherwise.
*/
static inline int adc_read(struct device *dev, struct adc_seq_table *seq_table)
__syscall int adc_read(struct device *dev, struct adc_seq_table *seq_table);
static inline int _impl_adc_read(struct device *dev,
struct adc_seq_table *seq_table)
{
const struct adc_driver_api *api = dev->driver_api;
@ -143,4 +150,6 @@ static inline int adc_read(struct device *dev, struct adc_seq_table *seq_table)
}
#endif
#include <syscalls/adc.h>
#endif /* __INCLUDE_ADC_H__ */