2017-10-24 01:05:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/i2c.h>
|
2018-04-05 07:15:06 +08:00
|
|
|
#include <string.h>
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/syscall_handler.h>
|
2017-10-24 01:05:09 +08:00
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static inline int z_vrfy_i2c_configure(const struct device *dev,
|
|
|
|
uint32_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));
|
2020-05-01 02:33:38 +08:00
|
|
|
return z_impl_i2c_configure((const 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
|
|
|
|
2021-09-30 18:13:29 +08:00
|
|
|
static inline int z_vrfy_i2c_get_config(const struct device *dev,
|
|
|
|
uint32_t *dev_config)
|
|
|
|
{
|
|
|
|
Z_OOPS(Z_SYSCALL_DRIVER_I2C(dev, get_config));
|
|
|
|
Z_OOPS(Z_SYSCALL_MEMORY_WRITE(dev_config, sizeof(uint32_t)));
|
|
|
|
|
|
|
|
return z_impl_i2c_get_config(dev, dev_config);
|
|
|
|
}
|
|
|
|
#include <syscalls/i2c_get_config_mrsh.c>
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static uint32_t copy_msgs_and_transfer(const struct device *dev,
|
|
|
|
const struct i2c_msg *msgs,
|
|
|
|
uint8_t num_msgs,
|
|
|
|
uint16_t addr)
|
2017-10-24 01:05:09 +08:00
|
|
|
{
|
2018-04-05 07:15:06 +08:00
|
|
|
struct i2c_msg copy[num_msgs];
|
2020-05-28 00:26:57 +08:00
|
|
|
uint8_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
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static inline int z_vrfy_i2c_transfer(const struct device *dev,
|
|
|
|
struct i2c_msg *msgs, uint8_t num_msgs,
|
|
|
|
uint16_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
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
return copy_msgs_and_transfer((const struct device *)dev,
|
2018-04-05 07:15:06 +08:00
|
|
|
(struct i2c_msg *)msgs,
|
2020-05-28 00:26:57 +08:00
|
|
|
(uint8_t)num_msgs, (uint16_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
|
|
|
|
2022-05-24 01:15:02 +08:00
|
|
|
static inline int z_vrfy_i2c_target_driver_register(const struct device *dev)
|
2019-08-14 01:27:12 +08:00
|
|
|
{
|
|
|
|
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_I2C));
|
2022-05-24 01:15:02 +08:00
|
|
|
return z_impl_i2c_target_driver_register(dev);
|
2019-08-14 01:27:12 +08:00
|
|
|
}
|
2022-05-24 01:15:02 +08:00
|
|
|
#include <syscalls/i2c_target_driver_register_mrsh.c>
|
2017-11-30 23:36:38 +08:00
|
|
|
|
2022-05-24 01:15:02 +08:00
|
|
|
static inline int z_vrfy_i2c_target_driver_unregister(const struct device *dev)
|
2019-08-14 01:27:12 +08:00
|
|
|
{
|
|
|
|
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_I2C));
|
2022-05-24 01:15:02 +08:00
|
|
|
return z_impl_i2c_target_driver_unregister(dev);
|
2019-08-14 01:27:12 +08:00
|
|
|
}
|
2022-05-24 01:15:02 +08:00
|
|
|
#include <syscalls/i2c_target_driver_unregister_mrsh.c>
|
2020-03-13 21:03:12 +08:00
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static inline int z_vrfy_i2c_recover_bus(const struct device *dev)
|
2020-03-13 21:03:12 +08:00
|
|
|
{
|
|
|
|
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_I2C));
|
|
|
|
return z_impl_i2c_recover_bus(dev);
|
|
|
|
}
|
|
|
|
#include <syscalls/i2c_recover_bus_mrsh.c>
|