master
h 71 lines 1.75 KB
Raw
1 /*
2 * Nitro Enclave Vsock Bus
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef HW_NITRO_VSOCK_BUS_H
8 #define HW_NITRO_VSOCK_BUS_H
9
10 #include "hw/core/qdev.h"
11 #include "hw/core/sysbus.h"
12 #include "qom/object.h"
13
14 #define TYPE_NITRO_VSOCK_BUS "nitro-vsock-bus"
15 OBJECT_DECLARE_SIMPLE_TYPE(NitroVsockBus, NITRO_VSOCK_BUS)
16
17 #define TYPE_NITRO_VSOCK_BRIDGE "nitro-vsock-bridge"
18 OBJECT_DECLARE_SIMPLE_TYPE(NitroVsockBridge, NITRO_VSOCK_BRIDGE)
19
20 #define TYPE_NITRO_VSOCK_DEVICE "nitro-vsock-device"
21 OBJECT_DECLARE_TYPE(NitroVsockDevice, NitroVsockDeviceClass,
22 NITRO_VSOCK_DEVICE)
23
24 struct NitroVsockBus {
25 BusState parent_obj;
26 };
27
28 struct NitroVsockBridge {
29 SysBusDevice parent_obj;
30
31 NitroVsockBus bus;
32 uint32_t enclave_cid;
33 };
34
35 struct NitroVsockDevice {
36 DeviceState parent_obj;
37 };
38
39 struct NitroVsockDeviceClass {
40 DeviceClass parent_class;
41
42 /*
43 * Called after the enclave has been started and the CID is known.
44 * Devices use this to establish vsock connections to the enclave.
45 */
46 void (*enclave_started)(NitroVsockDevice *dev, uint32_t enclave_cid,
47 Error **errp);
48 };
49
50 /*
51 * Machine helper to create the Nitro vsock bridge sysbus device.
52 */
53 NitroVsockBridge *nitro_vsock_bridge_create(void);
54
55 /*
56 * Find the Nitro vsock bridge on the sysbus.
57 */
58 static inline NitroVsockBridge *nitro_vsock_bridge_find(void)
59 {
60 return NITRO_VSOCK_BRIDGE(
61 object_resolve_path_type("", TYPE_NITRO_VSOCK_BRIDGE, NULL));
62 }
63
64 /*
65 * Notify the bridge that the enclave has started. Dispatches
66 * enclave_started() to all devices on the bus.
67 */
68 void nitro_vsock_bridge_start_enclave(NitroVsockBridge *bridge,
69 uint32_t enclave_cid, Error **errp);
70
71 #endif /* HW_NITRO_VSOCK_BUS_H */