xref: /aosp_15_r20/trusty/kernel/lib/trusty/trusty_virtio.h (revision 344aa361028b423587d4ef3fa52a23d194628137)
1 
2 /*
3  * Copyright (c) 2014, Google, Inc. All rights reserved
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files
7  * (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include <lib/sm.h>
28 #include <list.h>
29 #include <sys/types.h>
30 
31 __BEGIN_CDECLS
32 
33 enum {
34     VDEV_STATE_RESET = 0,
35     VDEV_STATE_ACTIVE,
36 };
37 
38 struct vdev;
39 
40 struct vdev_ops {
41     size_t (*descr_sz)(struct vdev* vd);
42     ssize_t (*get_descr)(struct vdev* vd, void* descr);
43     status_t (*probe)(struct vdev* vd, void* descr);
44     status_t (*reset)(struct vdev* vd);
45     status_t (*kick_vqueue)(struct vdev* vd, uint vqid);
46 };
47 
48 struct vdev {
49     volatile int state;
50     uint devid;
51     uint descr_offset;
52     ext_mem_client_id_t client_id;
53     struct list_node node;
54     const struct vdev_ops* ops;
55 };
56 
57 struct trusty_virtio_bus;
58 
59 typedef uint64_t ns_paddr_t;
60 
61 /*
62  * Register virtio device
63  */
64 status_t virtio_register_device(struct trusty_virtio_bus* vb, struct vdev* vd);
65 
66 /*
67  * Retrieve device description to be shared with NS side
68  */
69 ssize_t virtio_get_description(ext_mem_client_id_t client_id,
70                                ext_mem_obj_id_t descr_id,
71                                ns_size_t sz,
72                                uint mmu_flags);
73 
74 /*
75  * Called by NS side to finilize initialization
76  */
77 status_t virtio_start(ext_mem_client_id_t client_id,
78                       ext_mem_obj_id_t descr_id,
79                       ns_size_t sz,
80                       uint mmu_flags);
81 
82 /*
83  * Called by NS side to deinitialize virtio subsystem
84  */
85 status_t virtio_stop(ext_mem_client_id_t client_id,
86                      ext_mem_obj_id_t descr_id,
87                      ns_size_t sz,
88                      uint mmu_flags);
89 
90 /*
91  *  Reset virtio device with specified device id
92  */
93 status_t virtio_device_reset(ext_mem_client_id_t client_id, uint devid);
94 
95 /*
96  *  Kick vq for specified device
97  */
98 status_t virtio_kick_vq(ext_mem_client_id_t client_id, uint devid, uint vqid);
99 
100 struct trusty_virtio_bus_notifier {
101     struct list_node node;
102     status_t (*on_create)(struct trusty_virtio_bus* vb);
103 };
104 
105 void trusty_virtio_register_bus_notifier(struct trusty_virtio_bus_notifier* n);
106 
107 __END_CDECLS
108