drivers/virtualization: Make ivshmem driver userspace ready
Exposing its public API to userspace. Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
e9cf9d0325
commit
4ee5101021
4 changed files with 85 additions and 11 deletions
|
@ -4,3 +4,5 @@ zephyr_library()
|
|||
|
||||
zephyr_library_sources_ifdef(CONFIG_IVSHMEM virt_ivshmem.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_IVSHMEM_SHELL virt_ivshmem_shell.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_USERSPACE virt_ivshmem_handlers.c)
|
||||
|
|
|
@ -160,7 +160,7 @@ static bool ivshmem_configure(const struct device *dev)
|
|||
|
||||
z_phys_map((uint8_t **)&data->shmem,
|
||||
mbar_mem.phys_addr, data->size,
|
||||
K_MEM_CACHE_WB | K_MEM_PERM_RW);
|
||||
K_MEM_CACHE_WB | K_MEM_PERM_RW | K_MEM_PERM_USER);
|
||||
|
||||
LOG_DBG("ivshmem configured:");
|
||||
LOG_DBG("- Registers at 0x%lx (mapped to 0x%lx)",
|
||||
|
|
56
drivers/virtualization/virt_ivshmem_handlers.c
Normal file
56
drivers/virtualization/virt_ivshmem_handlers.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <drivers/virtualization/ivshmem.h>
|
||||
#include <syscall_handler.h>
|
||||
#include <string.h>
|
||||
|
||||
static inline size_t z_vrfy_ivshmem_get_mem(const struct device *dev,
|
||||
uintptr_t *memmap)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_IVSHMEM(dev, get_mem));
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_WRITE(memmap, sizeof(uintptr_t)));
|
||||
|
||||
return z_impl_ivshmem_get_mem(dev, memmap);
|
||||
}
|
||||
#include <syscalls/ivshmem_get_mem_mrsh.c>
|
||||
|
||||
static inline uint32_t z_vrfy_ivshmem_get_id(const struct device *dev)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_IVSHMEM(dev, get_id));
|
||||
|
||||
return z_impl_ivshmem_get_id(dev);
|
||||
}
|
||||
#include <syscalls/ivshmem_get_id_mrsh.c>
|
||||
|
||||
static inline uint16_t z_vrfy_ivshmem_get_vectors(const struct device *dev)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_IVSHMEM(dev, get_vectors));
|
||||
|
||||
return z_impl_ivshmem_get_vectors(dev);
|
||||
}
|
||||
#include <syscalls/ivshmem_get_vectors_mrsh.c>
|
||||
|
||||
static inline int z_vrfy_ivshmem_int_peer(const struct device *dev,
|
||||
uint32_t peer_id, uint16_t vector)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_IVSHMEM(dev, int_peer));
|
||||
|
||||
return z_impl_ivshmem_int_peer(dev, peer_id, vector);
|
||||
}
|
||||
#include <syscalls/ivshmem_int_peer_mrsh.c>
|
||||
|
||||
static inline int z_vrfy_ivshmem_register_handler(const struct device *dev,
|
||||
struct k_poll_signal *signal,
|
||||
uint16_t vector)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_IVSHMEM(dev, register_handler));
|
||||
Z_OOPS(Z_SYSCALL_OBJ(signal, K_OBJ_POLL_SIGNAL));
|
||||
|
||||
return z_impl_ivshmem_register_handler(dev, signal, vector);
|
||||
}
|
||||
|
||||
#include <syscalls/ivshmem_register_handler_mrsh.c>
|
|
@ -35,7 +35,7 @@ typedef int (*ivshmem_register_handler_f)(const struct device *dev,
|
|||
struct k_poll_signal *signal,
|
||||
uint16_t vector);
|
||||
|
||||
struct ivshmem_driver_api {
|
||||
__subsystem struct ivshmem_driver_api {
|
||||
ivshmem_get_mem_f get_mem;
|
||||
ivshmem_get_id_f get_id;
|
||||
ivshmem_get_vectors_f get_vectors;
|
||||
|
@ -51,8 +51,11 @@ struct ivshmem_driver_api {
|
|||
*
|
||||
* @return the size of the memory mapped, or 0
|
||||
*/
|
||||
static inline size_t ivshmem_get_mem(const struct device *dev,
|
||||
uintptr_t *memmap)
|
||||
__syscall size_t ivshmem_get_mem(const struct device *dev,
|
||||
uintptr_t *memmap);
|
||||
|
||||
static inline size_t z_impl_ivshmem_get_mem(const struct device *dev,
|
||||
uintptr_t *memmap)
|
||||
{
|
||||
const struct ivshmem_driver_api *api =
|
||||
(const struct ivshmem_driver_api *)dev->api;
|
||||
|
@ -67,7 +70,9 @@ static inline size_t ivshmem_get_mem(const struct device *dev,
|
|||
*
|
||||
* @return our VM ID or 0 if we are not running on doorbell version
|
||||
*/
|
||||
static inline uint32_t ivshmem_get_id(const struct device *dev)
|
||||
__syscall uint32_t ivshmem_get_id(const struct device *dev);
|
||||
|
||||
static inline uint32_t z_impl_ivshmem_get_id(const struct device *dev)
|
||||
{
|
||||
const struct ivshmem_driver_api *api =
|
||||
(const struct ivshmem_driver_api *)dev->api;
|
||||
|
@ -82,7 +87,9 @@ static inline uint32_t ivshmem_get_id(const struct device *dev)
|
|||
*
|
||||
* @return the number of available interrupt vectors
|
||||
*/
|
||||
static inline uint16_t ivshmem_get_vectors(const struct device *dev)
|
||||
__syscall uint16_t ivshmem_get_vectors(const struct device *dev);
|
||||
|
||||
static inline uint16_t z_impl_ivshmem_get_vectors(const struct device *dev)
|
||||
{
|
||||
const struct ivshmem_driver_api *api =
|
||||
(const struct ivshmem_driver_api *)dev->api;
|
||||
|
@ -99,8 +106,11 @@ static inline uint16_t ivshmem_get_vectors(const struct device *dev)
|
|||
*
|
||||
* @return 0 on success, a negative errno otherwise
|
||||
*/
|
||||
static inline int ivshmem_int_peer(const struct device *dev,
|
||||
uint32_t peer_id, uint16_t vector)
|
||||
__syscall int ivshmem_int_peer(const struct device *dev,
|
||||
uint32_t peer_id, uint16_t vector);
|
||||
|
||||
static inline int z_impl_ivshmem_int_peer(const struct device *dev,
|
||||
uint32_t peer_id, uint16_t vector)
|
||||
{
|
||||
const struct ivshmem_driver_api *api =
|
||||
(const struct ivshmem_driver_api *)dev->api;
|
||||
|
@ -123,9 +133,13 @@ static inline int ivshmem_int_peer(const struct device *dev,
|
|||
*
|
||||
* @return 0 on success, a negative errno otherwise
|
||||
*/
|
||||
static inline int ivshmem_register_handler(const struct device *dev,
|
||||
struct k_poll_signal *signal,
|
||||
uint16_t vector)
|
||||
__syscall int ivshmem_register_handler(const struct device *dev,
|
||||
struct k_poll_signal *signal,
|
||||
uint16_t vector);
|
||||
|
||||
static inline int z_impl_ivshmem_register_handler(const struct device *dev,
|
||||
struct k_poll_signal *signal,
|
||||
uint16_t vector)
|
||||
{
|
||||
const struct ivshmem_driver_api *api =
|
||||
(const struct ivshmem_driver_api *)dev->api;
|
||||
|
@ -141,4 +155,6 @@ static inline int ivshmem_register_handler(const struct device *dev,
|
|||
* @}
|
||||
*/
|
||||
|
||||
#include <syscalls/ivshmem.h>
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_VIRTUALIZATION_IVSHMEM_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue