2017-10-24 01:05:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-06-26 03:53:54 +08:00
|
|
|
#include <drivers/i2c.h>
|
2018-04-05 07:15:06 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <syscall_handler.h>
|
2017-10-24 01:05:09 +08:00
|
|
|
|
2019-08-14 01:27:12 +08:00
|
|
|
static inline int z_vrfy_i2c_configure(struct device *dev, u32_t dev_config)
|
2017-10-24 01:05:09 +08:00
|
|
|
{
|
2018-05-05 06:57:57 +08:00
|
|
|
Z_OOPS(Z_SYSCALL_DRIVER_I2C(dev, configure));
|
2019-03-09 05:19:05 +08:00
|
|
|
return z_impl_i2c_configure((struct device *)dev, dev_config);
|
2017-10-24 01:05:09 +08:00
|
|
|
}
|
2019-08-14 01:27:12 +08:00
|
|
|
#include <syscalls/i2c_configure_mrsh.c>
|
2017-10-24 01:05:09 +08:00
|
|
|
|
2018-04-05 07:15:06 +08:00
|
|
|
static u32_t copy_msgs_and_transfer(struct device *dev,
|
|
|
|
const struct i2c_msg *msgs,
|
|
|
|
u8_t num_msgs,
|
2019-08-14 01:27:12 +08:00
|
|
|
u16_t addr)
|
2017-10-24 01:05:09 +08:00
|
|
|
{
|
2018-04-05 07:15:06 +08:00
|
|
|
struct i2c_msg copy[num_msgs];
|
|
|
|
u8_t i;
|
2017-10-24 01:05:09 +08:00
|
|
|
|
2018-04-05 07:15:06 +08:00
|
|
|
/* Use a local copy to avoid switcheroo attacks. */
|
|
|
|
memcpy(copy, msgs, num_msgs * sizeof(*msgs));
|
2017-10-24 01:05:09 +08:00
|
|
|
|
|
|
|
/* Validate the buffers in each message struct. Read options require
|
|
|
|
* that the target buffer be writable
|
|
|
|
*/
|
2018-11-30 03:12:22 +08:00
|
|
|
for (i = 0U; i < num_msgs; i++) {
|
2018-05-05 06:57:57 +08:00
|
|
|
Z_OOPS(Z_SYSCALL_MEMORY(copy[i].buf, copy[i].len,
|
|
|
|
copy[i].flags & I2C_MSG_READ));
|
2017-10-24 01:05:09 +08:00
|
|
|
}
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
return z_impl_i2c_transfer(dev, copy, num_msgs, addr);
|
2018-04-05 07:15:06 +08:00
|
|
|
}
|
|
|
|
|
2019-08-14 01:27:12 +08:00
|
|
|
static inline int z_vrfy_i2c_transfer(struct device *dev,
|
|
|
|
struct i2c_msg *msgs, u8_t num_msgs,
|
|
|
|
u16_t addr)
|
2018-04-05 07:15:06 +08:00
|
|
|
{
|
2018-05-05 06:57:57 +08:00
|
|
|
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_I2C));
|
2018-04-05 07:15:06 +08:00
|
|
|
|
|
|
|
/* copy_msgs_and_transfer() will allocate a copy on the stack using
|
|
|
|
* VLA, so ensure this won't blow the stack. Most functions defined
|
|
|
|
* in i2c.h use only a handful of messages, so up to 32 messages
|
|
|
|
* should be more than sufficient.
|
|
|
|
*/
|
2018-05-05 06:57:57 +08:00
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY(num_msgs >= 1 && num_msgs < 32));
|
2018-04-05 07:15:06 +08:00
|
|
|
|
|
|
|
/* We need to be able to read the overall array of messages */
|
2018-05-05 06:57:57 +08:00
|
|
|
Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(msgs, num_msgs,
|
|
|
|
sizeof(struct i2c_msg)));
|
2018-04-05 07:15:06 +08:00
|
|
|
|
|
|
|
return copy_msgs_and_transfer((struct device *)dev,
|
|
|
|
(struct i2c_msg *)msgs,
|
2019-08-14 01:27:12 +08:00
|
|
|
(u8_t)num_msgs, (u16_t)addr);
|
2017-10-24 01:05:09 +08:00
|
|
|
}
|
2019-08-14 01:27:12 +08:00
|
|
|
#include <syscalls/i2c_transfer_mrsh.c>
|
2017-11-30 23:36:38 +08:00
|
|
|
|
2019-08-14 01:27:12 +08:00
|
|
|
static inline int z_vrfy_i2c_slave_driver_register(struct device *dev)
|
|
|
|
{
|
|
|
|
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_I2C));
|
|
|
|
return z_impl_i2c_slave_driver_register(dev);
|
|
|
|
}
|
|
|
|
#include <syscalls/i2c_slave_driver_register_mrsh.c>
|
2017-11-30 23:36:38 +08:00
|
|
|
|
2019-08-14 01:27:12 +08:00
|
|
|
static inline int z_vrfy_i2c_slave_driver_unregister(struct device *dev)
|
|
|
|
{
|
|
|
|
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_I2C));
|
|
|
|
return z_vrfy_i2c_slave_driver_unregister(dev);
|
|
|
|
}
|
|
|
|
#include <syscalls/i2c_slave_driver_unregister_mrsh.c>
|