Hardware Abstraction Layer for FreeRTOS
vdev.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Author: Andreas Werner <kernel@andy89.org>
4  * Date: 2016
5  */
6 #ifndef VDEV_H_
7 #define VDEV_H_
8 #include <FreeRTOS.h>
9 #include <stdint.h>
10 #include <stdbool.h>
11 #include <system.h>
12 #include <semphr.h>
13 #include <hal.h>
14 struct vdev;
15 struct vdev_ops {
16  struct vdev *(*vdev_init)(uint32_t index, struct virtio *virtio, uint8_t size, struct vring_config *config);
17  int32_t vdev_deinit(struct vdev *vdev);
18 };
19 struct vdev_config {
20  enum vdev_type id;
21  uint32_t notifyid;
22  uint32_t features;
23  uint32_t configLen;
24  void *config;
25  uint8_t numOfVrings;
26  struct vring_config vrings[0];
27 };
28 struct vring_config {
29  uint32_t va;
30  uint32_t da;
31  uint32_t align;
32  uint32_t notifyid;
33 };
44 struct vdev_generic {
49  bool init;
50  struct vdev_config config;
51  struct virtio *virtio;
55  const struct vdev_ops *ops;
56 #ifdef CONFIG_INSTANCE_NAME
57 
60  const char *name;
61 #endif
62 #ifdef CONFIG_VDEV_THREAD_SAVE
63 
66  SemaphoreHandle_t lock;
67 #endif
68 };
69 inline struct vdev *vdev_init(uint32_t index, struct virtio *virtio, uint8_t size, struct vring_config *config) {
71  struct vdev_generic *gen = HAL_GET_DEV(vdev, index);
72  if (gen == NULL) {
73  return NULL;
74  }
75  return gen->ops->vdev_init(index, virtio, size, config);
76 }
77 inline int32_t vdev_deinit(struct vdev *vdev) {
78  struct vdev_generic *gen = vdev;
79  return gen->deinit(vdev);
80 }
81 inline int32_t vdev_getID(struct vdev *vdev) {
82  struct vdev_generic *gen = vdev;
83  return gen->config.id;
84 }
85 inline bool vdev_hasFeatures(struct vdev *vdev, uint32_t feature) {
86  struct vdev_generic *gen = vdev;
87  return (vdev.config->features & BIT(feature)) != 0;
88 }
89 #endif
vring_config::va
uint32_t va
Definition: vdev.h:29
vdev_generic::config
struct vdev_config config
Definition: vdev.h:50
vring_config::align
uint32_t align
Definition: vdev.h:31
vdev_ops::vdev_init
struct vdev *(* vdev_init)(uint32_t index, struct virtio *virtio, uint8_t size, struct vring_config *config)
Definition: vdev.h:16
vdev_config::config
void * config
Definition: vdev.h:24
vdev_init
struct vdev * vdev_init(uint32_t index, struct virtio *virtio, uint8_t size, struct vring_config *config)
Definition: vdev.h:69
vring_config::notifyid
uint32_t notifyid
Definition: vdev.h:32
vdev_generic::virtio
struct virtio * virtio
Definition: vdev.h:51
hal.h
vdev_generic::ops
const struct vdev_ops * ops
Definition: vdev.h:55
vdev_config::vrings
struct vring_config vrings[0]
Definition: vdev.h:26
BIT
#define BIT(x)
Definition: system.h:114
vdev_getID
int32_t vdev_getID(struct vdev *vdev)
Definition: vdev.h:81
vdev_hasFeatures
bool vdev_hasFeatures(struct vdev *vdev, uint32_t feature)
Definition: vdev.h:85
vdev_config::features
uint32_t features
Definition: vdev.h:22
vring_config
Definition: vdev.h:28
vdev_ops
Definition: vdev.h:15
vring_config::da
uint32_t da
Definition: vdev.h:30
HAL_DEFINE_GLOBAL_ARRAY
#define HAL_DEFINE_GLOBAL_ARRAY(gns)
Definition: hal.h:149
vdev_config::notifyid
uint32_t notifyid
Definition: vdev.h:21
HAL_GET_DEV
#define HAL_GET_DEV(gns, index)
Definition: hal.h:182
vdev_config::numOfVrings
uint8_t numOfVrings
Definition: vdev.h:25
vdev_config::configLen
uint32_t configLen
Definition: vdev.h:23
vdev_config::id
enum vdev_type id
Definition: vdev.h:20
system.h
vdev_generic
Definition: vdev.h:44
vdev_ops::vdev_deinit
int32_t vdev_deinit(struct vdev *vdev)
vdev_config
Definition: vdev.h:19
vdev_deinit
int32_t vdev_deinit(struct vdev *vdev)
Definition: vdev.h:77
vdev_generic::init
bool init
Definition: vdev.h:49