-
Notifications
You must be signed in to change notification settings - Fork 0
/
cellconfig.py
executable file
·279 lines (243 loc) · 8.01 KB
/
cellconfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import enum
import ctypes
_U8 = ctypes.c_uint8
_U16 = ctypes.c_uint16
_U32 = ctypes.c_uint32
_U64 = ctypes.c_uint64
_CHAR = ctypes.c_char
JAILHOUSE_CELL_NAME_MAXLEN = 31
JAILHOUSE_SYSTEM_SIGNATURE = b"JHSYST"
JAILHOUSE_SYS_VIRTUAL_DEBUG_CONSOLE = 0x0001
JAILHOUSE_CELL_DESC_SIGNATURE = b"JHCELL"
JAILHOUSE_CELL_PASSIVE_COMMREG = 0x00000001
JAILHOUSE_CELL_TEST_DEVICE = 0x00000002
JAILHOUSE_CELL_AARCH32 = 0x00000004
JAILHOUSE_CELL_VIRT_CPUID = 0x00000100
JAILHOUSE_CELL_VIRTUAL_CONSOLE_PERMITTED = 0x40000000
JAILHOUSE_CELL_VIRTUAL_CONSOLE_ACTIVATE = 0x80000000
class JailhouseConType(enum.Enum):
JAILHOUSE_CON_TYPE_NONE = 0x0000
JAILHOUSE_CON_TYPE_EFIFB = 0x0001
JAILHOUSE_CON_TYPE_8250 = 0x0002
JAILHOUSE_CON_TYPE_PL011 = 0x0003
JAILHOUSE_CON_TYPE_XUARTPS = 0x0004
JAILHOUSE_CON_TYPE_MVEBU = 0x0005
JAILHOUSE_CON_TYPE_HSCIF = 0x0006
JAILHOUSE_CON_TYPE_SCIFA = 0x0007
JAILHOUSE_CON_TYPE_IMX = 0x0008
def jailhouse_con_type_form_str( name ):
for item in JailhouseConType.__members__:
if name.upper() in item:
return JailhouseConType.__members__[item]
return None
JAILHOUSE_CON_ACCESS_PIO = 0x0000
JAILHOUSE_CON_ACCESS_MMIO = 0x0001
JAILHOUSE_CON_REGDIST_1 = 0x0000
JAILHOUSE_CON_REGDIST_4 = 0x0002
JAILHOUSE_PCI_TYPE_DEVICE = 0x01
JAILHOUSE_PCI_TYPE_BRIDGE = 0x02
JAILHOUSE_PCI_TYPE_IVSHMEM = 0x03
JAILHOUSE_SHMEM_PROTO_UNDEFINED = 0x0000
JAILHOUSE_SHMEM_PROTO_VETH = 0x0001
JAILHOUSE_SHMEM_PROTO_CUSTOM = 0x4000
JAILHOUSE_SHMEM_PROTO_VIRTIO_FRONT = 0x8000
JAILHOUSE_SHMEM_PROTO_VIRTIO_BACK = 0xc000
JAILHOUSE_IVSHMEM_BAR_MASK_INTX = (ctypes.c_uint32*6)(0xfffff000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000)
JAILHOUSE_PCI_EXT_CAP = 0x8000
JAILHOUSE_PCICAPS_WRITE = 0x0001
class jailhouse_memory(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('phys_start', ctypes.c_uint64),
('virt_start', ctypes.c_uint64),
('size', ctypes.c_uint64),
('flags', ctypes.c_uint64),
]
class jailhouse_iommu(ctypes.LittleEndianStructure):
class PltUnion(ctypes.Union):
class AMD(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('bdf', _U16),
('base_cap', _U8),
('msi_cap', _U8),
('features', _U32)
]
class TIPVU(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('tlb_base', _U64),
('tlb_size', _U32),
]
_fields_ = [
('amd', AMD),
('vipvu', TIPVU)
]
_pack_ = 1
_fields_ = [
('type', _U32),
('base', _U64),
('size', _U32),
('plt', PltUnion)
]
class jailhouse_console(ctypes.Structure):
_pack_ = 1
_fields_ = [
('address', _U64),
('size', _U32),
('type', _U16),
('flags', _U16),
('divider', _U32),
('gate_nr', _U32),
('clock_reg', _U64),
]
class jailhouse_irqchip(ctypes.Structure):
_pack_ = 1
_fields_ = [
('address', _U64),
('id', _U32),
('pin_base', _U32),
('pin_bitmap', _U32*4),
]
class jailhouse_pci_device_r13(ctypes.Structure):
_pack_ = 1
_fields_ = [
('type', _U8),
('iommu', _U8),
('domain', _U16),
('bdf', _U16),
('bar_mask', _U32*6),
('caps_start', _U16),
('num_caps', _U16),
('num_msi_vectors', _U8),
# ctypes不支持位域, [0]: 64bit [1]: maskable
('msi', _U8),
('num_msix_vectors', _U16),
('msix_region_size', _U16),
('msix_address', _U64),
('shmem_regions_start', _U32),
('shmem_dev_id', _U8),
('shmem_peers', _U8),
('shmem_protocol', _U16),
]
class jailhouse_pci_device_r14(ctypes.Structure):
_pack_ = 1
_fields_ = [
('type', _U8),
('iommu', _U8),
('domain', _U16),
('bdf', _U16),
('virt_bdf', _U32),
('bar_mask', _U32*6),
('caps_start', _U16),
('num_caps', _U16),
('num_msi_vectors', _U8),
# ctypes不支持位域, [0]: 64bit [1]: maskable
('msi', _U8),
('num_msix_vectors', _U16),
('msix_region_size', _U16),
('msix_address', _U64),
('shmem_regions_start', _U32),
('shmem_dev_id', _U8),
('shmem_peers', _U8),
('shmem_protocol', _U16),
]
class jailhouse_pci_capability(ctypes.Structure):
_pack_ = 1
_fields_ = [
('id', _U16),
('start', _U16),
('len', _U16),
('flags', _U16),
]
class jailhouse_cell_desc(ctypes.Structure):
_pack_ = 1
_fields_ = [
('signature', _CHAR*6),
('revision', _U16),
('name', _CHAR*(JAILHOUSE_CELL_NAME_MAXLEN+1)),
('id', _U32),
('flags', _U32),
('cpu_set_size', _U32),
('num_memory_regions', _U32),
('num_cache_regions', _U32),
('num_irqchips', _U32),
('num_pio_regions', _U32),
('num_pci_devices', _U32),
('num_pci_caps', _U32),
('num_stream_ids', _U32),
('vpci_irq_base', _U32),
('cpu_reset_address', _U64),
('msg_reply_timeout', _U64),
('console', jailhouse_console)
]
class jailhouse_system(ctypes.LittleEndianStructure):
class PlatformInfo(ctypes.LittleEndianStructure):
class PlatformInfoUnion(ctypes.Union):
class PlatformInfoX86(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('pm_timer_address', _U16),
('apic_mode', _U8),
('padding', _U8),
('vtd_interrupt_limit', _U32),
('tsc_khz', _U32),
('apic_khz', _U32),
]
class PlatformInfoARM(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('maintenance_irq', _U8),
('gic_version', _U8),
('padding', _U8*2),
('gicd_base', _U64),
('gicc_base', _U64),
('gich_base', _U64),
('gicv_base', _U64),
('gicr_base', _U64),
]
_pack_ = 1
_fields_ = [
('x86', PlatformInfoX86),
('arm', PlatformInfoARM),
]
_pack_ = 1
_fields_ = [
('pci_mmconfig_base', _U64),
('pci_machine_mmconfig_base', _U64),
('pci_mmconfig_end_bus', _U8),
('pci_is_virtual', _U8),
('pci_domain', _U16),
('iommu_units', jailhouse_iommu*8),
('plt', PlatformInfoUnion)
]
_pack_ = 1
_fields_ = [
('signature', ctypes.c_char*6),
('revision', ctypes.c_uint16),
('flags', ctypes.c_uint32),
('hypervisor_memory', jailhouse_memory),
('debug_console', jailhouse_console),
('platform_info', PlatformInfo),
('root_cell', jailhouse_cell_desc)
]
class Revision13:
revision = 13
sys_signature = JAILHOUSE_SYSTEM_SIGNATURE
cell_signature = JAILHOUSE_CELL_DESC_SIGNATURE
system = jailhouse_system
cell_desc = jailhouse_cell_desc
memory = jailhouse_memory
irqchip = jailhouse_irqchip
pci_device = jailhouse_pci_device_r13
pci_capability = jailhouse_pci_capability
class Revision14:
revision = 14
sys_signature = JAILHOUSE_SYSTEM_SIGNATURE
cell_signature = JAILHOUSE_CELL_DESC_SIGNATURE
system = jailhouse_system
cell_desc = jailhouse_cell_desc
memory = jailhouse_memory
irqchip = jailhouse_irqchip
pci_device = jailhouse_pci_device_r14
pci_capability = jailhouse_pci_capability