iPXE
arch-arm.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 /******************************************************************************
3  * arch-arm.h
4  *
5  * Guest OS interface to ARM Xen.
6  *
7  * Copyright 2011 (C) Citrix Systems
8  */
9 
10 #ifndef __XEN_PUBLIC_ARCH_ARM_H__
11 #define __XEN_PUBLIC_ARCH_ARM_H__
12 
13 FILE_LICENCE ( MIT );
14 
15 /*
16  * `incontents 50 arm_abi Hypercall Calling Convention
17  *
18  * A hypercall is issued using the ARM HVC instruction.
19  *
20  * A hypercall can take up to 5 arguments. These are passed in
21  * registers, the first argument in x0/r0 (for arm64/arm32 guests
22  * respectively irrespective of whether the underlying hypervisor is
23  * 32- or 64-bit), the second argument in x1/r1, the third in x2/r2,
24  * the forth in x3/r3 and the fifth in x4/r4.
25  *
26  * The hypercall number is passed in r12 (arm) or x16 (arm64). In both
27  * cases the relevant ARM procedure calling convention specifies this
28  * is an inter-procedure-call scratch register (e.g. for use in linker
29  * stubs). This use does not conflict with use during a hypercall.
30  *
31  * The HVC ISS must contain a Xen specific TAG: XEN_HYPERCALL_TAG.
32  *
33  * The return value is in x0/r0.
34  *
35  * The hypercall will clobber x16/r12 and the argument registers used
36  * by that hypercall (except r0 which is the return value) i.e. in
37  * addition to x16/r12 a 2 argument hypercall will clobber x1/r1 and a
38  * 4 argument hypercall will clobber x1/r1, x2/r2 and x3/r3.
39  *
40  * Parameter structs passed to hypercalls are laid out according to
41  * the Procedure Call Standard for the ARM Architecture (AAPCS, AKA
42  * EABI) and Procedure Call Standard for the ARM 64-bit Architecture
43  * (AAPCS64). Where there is a conflict the 64-bit standard should be
44  * used regardless of guest type. Structures which are passed as
45  * hypercall arguments are always little endian.
46  *
47  * All memory which is shared with other entities in the system
48  * (including the hypervisor and other guests) must reside in memory
49  * which is mapped as Normal Inner Write-Back Outer Write-Back Inner-Shareable.
50  * This applies to:
51  * - hypercall arguments passed via a pointer to guest memory.
52  * - memory shared via the grant table mechanism (including PV I/O
53  * rings etc).
54  * - memory shared with the hypervisor (struct shared_info, struct
55  * vcpu_info, the grant table, etc).
56  *
57  * Any cache allocation hints are acceptable.
58  */
59 
60 /*
61  * `incontents 55 arm_hcall Supported Hypercalls
62  *
63  * Xen on ARM makes extensive use of hardware facilities and therefore
64  * only a subset of the potential hypercalls are required.
65  *
66  * Since ARM uses second stage paging any machine/physical addresses
67  * passed to hypercalls are Guest Physical Addresses (Intermediate
68  * Physical Addresses) unless otherwise noted.
69  *
70  * The following hypercalls (and sub operations) are supported on the
71  * ARM platform. Other hypercalls should be considered
72  * unavailable/unsupported.
73  *
74  * HYPERVISOR_memory_op
75  * All generic sub-operations
76  *
77  * HYPERVISOR_domctl
78  * All generic sub-operations, with the exception of:
79  * * XEN_DOMCTL_irq_permission (not yet implemented)
80  *
81  * HYPERVISOR_sched_op
82  * All generic sub-operations, with the exception of:
83  * * SCHEDOP_block -- prefer wfi hardware instruction
84  *
85  * HYPERVISOR_console_io
86  * All generic sub-operations
87  *
88  * HYPERVISOR_xen_version
89  * All generic sub-operations
90  *
91  * HYPERVISOR_event_channel_op
92  * All generic sub-operations
93  *
94  * HYPERVISOR_physdev_op
95  * Exactly these sub-operations are supported:
96  * PHYSDEVOP_pci_device_add
97  * PHYSDEVOP_pci_device_remove
98  *
99  * HYPERVISOR_sysctl
100  * All generic sub-operations, with the exception of:
101  * * XEN_SYSCTL_page_offline_op
102  * * XEN_SYSCTL_get_pmstat
103  * * XEN_SYSCTL_pm_op
104  *
105  * HYPERVISOR_hvm_op
106  * Exactly these sub-operations are supported:
107  * * HVMOP_set_param
108  * * HVMOP_get_param
109  *
110  * HYPERVISOR_grant_table_op
111  * All generic sub-operations
112  *
113  * HYPERVISOR_vcpu_op
114  * Exactly these sub-operations are supported:
115  * * VCPUOP_register_vcpu_info
116  * * VCPUOP_register_runstate_memory_area
117  *
118  * HYPERVISOR_argo_op
119  * All generic sub-operations
120  *
121  * Other notes on the ARM ABI:
122  *
123  * - struct start_info is not exported to ARM guests.
124  *
125  * - struct shared_info is mapped by ARM guests using the
126  * HYPERVISOR_memory_op sub-op XENMEM_add_to_physmap, passing
127  * XENMAPSPACE_shared_info as space parameter.
128  *
129  * - All the per-cpu struct vcpu_info are mapped by ARM guests using the
130  * HYPERVISOR_vcpu_op sub-op VCPUOP_register_vcpu_info, including cpu0
131  * struct vcpu_info.
132  *
133  * - The grant table is mapped using the HYPERVISOR_memory_op sub-op
134  * XENMEM_add_to_physmap, passing XENMAPSPACE_grant_table as space
135  * parameter. The memory range specified under the Xen compatible
136  * hypervisor node on device tree can be used as target gpfn for the
137  * mapping.
138  *
139  * - Xenstore is initialized by using the two hvm_params
140  * HVM_PARAM_STORE_PFN and HVM_PARAM_STORE_EVTCHN. They can be read
141  * with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
142  *
143  * - The paravirtualized console is initialized by using the two
144  * hvm_params HVM_PARAM_CONSOLE_PFN and HVM_PARAM_CONSOLE_EVTCHN. They
145  * can be read with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
146  *
147  * - Event channel notifications are delivered using the percpu GIC
148  * interrupt specified under the Xen compatible hypervisor node on
149  * device tree.
150  *
151  * - The device tree Xen compatible node is fully described under Linux
152  * at Documentation/devicetree/bindings/arm/xen.txt.
153  */
154 
155 #define XEN_HYPERCALL_TAG 0XEA1
156 
157 #define int64_aligned_t int64_t __attribute__((aligned(8)))
158 #define uint64_aligned_t uint64_t __attribute__((aligned(8)))
159 
160 #ifndef __ASSEMBLY__
161 #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
162  typedef union { type *p; unsigned long q; } \
163  __guest_handle_ ## name; \
164  typedef union { type *p; uint64_aligned_t q; } \
165  __guest_handle_64_ ## name
166 
167 /*
168  * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
169  * in a struct in memory. On ARM is always 8 bytes sizes and 8 bytes
170  * aligned.
171  * XEN_GUEST_HANDLE_PARAM represents a guest pointer, when passed as an
172  * hypercall argument. It is 4 bytes on aarch32 and 8 bytes on aarch64.
173  */
174 #define __DEFINE_XEN_GUEST_HANDLE(name, type) \
175  ___DEFINE_XEN_GUEST_HANDLE(name, type); \
176  ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
177 #define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name)
178 #define __XEN_GUEST_HANDLE(name) __guest_handle_64_ ## name
179 #define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name)
180 #define XEN_GUEST_HANDLE_PARAM(name) __guest_handle_ ## name
181 #define set_xen_guest_handle_raw(hnd, val) \
182  do { \
183  __typeof__(&(hnd)) _sxghr_tmp = &(hnd); \
184  _sxghr_tmp->q = 0; \
185  _sxghr_tmp->p = val; \
186  } while ( 0 )
187 #define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
188 
190 #define PRI_xen_pfn PRIx64
191 #define PRIu_xen_pfn PRIu64
192 
193 /*
194  * Maximum number of virtual CPUs in legacy multi-processor guests.
195  * Only one. All other VCPUS must use VCPUOP_register_vcpu_info.
196  */
197 #define XEN_LEGACY_MAX_VCPUS 1
198 
200 #define PRI_xen_ulong PRIx64
201 
202 #if defined(__XEN__) || defined(__XEN_TOOLS__)
203 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
204 /* Anonymous union includes both 32- and 64-bit names (e.g., r0/x0). */
205 # define __DECL_REG(n64, n32) union { \
206  uint64_t n64; \
207  uint32_t n32; \
208  }
209 #else
210 /* Non-gcc sources must always use the proper 64-bit name (e.g., x0). */
211 #define __DECL_REG(n64, n32) uint64_t n64
212 #endif
213 
214 struct vcpu_guest_core_regs
215 {
216  /* Aarch64 Aarch32 */
217  __DECL_REG(x0, r0_usr);
218  __DECL_REG(x1, r1_usr);
219  __DECL_REG(x2, r2_usr);
220  __DECL_REG(x3, r3_usr);
221  __DECL_REG(x4, r4_usr);
222  __DECL_REG(x5, r5_usr);
223  __DECL_REG(x6, r6_usr);
224  __DECL_REG(x7, r7_usr);
225  __DECL_REG(x8, r8_usr);
226  __DECL_REG(x9, r9_usr);
227  __DECL_REG(x10, r10_usr);
228  __DECL_REG(x11, r11_usr);
229  __DECL_REG(x12, r12_usr);
230 
231  __DECL_REG(x13, sp_usr);
232  __DECL_REG(x14, lr_usr);
233 
234  __DECL_REG(x15, __unused_sp_hyp);
235 
236  __DECL_REG(x16, lr_irq);
237  __DECL_REG(x17, sp_irq);
238 
239  __DECL_REG(x18, lr_svc);
240  __DECL_REG(x19, sp_svc);
241 
242  __DECL_REG(x20, lr_abt);
243  __DECL_REG(x21, sp_abt);
244 
245  __DECL_REG(x22, lr_und);
246  __DECL_REG(x23, sp_und);
247 
248  __DECL_REG(x24, r8_fiq);
249  __DECL_REG(x25, r9_fiq);
250  __DECL_REG(x26, r10_fiq);
251  __DECL_REG(x27, r11_fiq);
252  __DECL_REG(x28, r12_fiq);
253 
254  __DECL_REG(x29, sp_fiq);
255  __DECL_REG(x30, lr_fiq);
256 
257  /* Return address and mode */
258  __DECL_REG(pc64, pc32); /* ELR_EL2 */
259  uint64_t cpsr; /* SPSR_EL2 */
260 
261  union {
262  uint64_t spsr_el1; /* AArch64 */
263  uint32_t spsr_svc; /* AArch32 */
264  };
265 
266  /* AArch32 guests only */
267  uint32_t spsr_fiq, spsr_irq, spsr_und, spsr_abt;
268 
269  /* AArch64 guests only */
270  uint64_t sp_el0;
271  uint64_t sp_el1, elr_el1;
272 };
273 typedef struct vcpu_guest_core_regs vcpu_guest_core_regs_t;
274 DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t);
275 
276 #undef __DECL_REG
277 
278 struct vcpu_guest_context {
279 #define _VGCF_online 0
280 #define VGCF_online (1<<_VGCF_online)
281  uint32_t flags; /* VGCF_* */
282 
283  struct vcpu_guest_core_regs user_regs; /* Core CPU registers */
284 
285  uint64_t sctlr;
286  uint64_t ttbcr, ttbr0, ttbr1;
287 };
290 
291 /*
292  * struct xen_arch_domainconfig's ABI is covered by
293  * XEN_DOMCTL_INTERFACE_VERSION.
294  */
295 #define XEN_DOMCTL_CONFIG_GIC_NATIVE 0
296 #define XEN_DOMCTL_CONFIG_GIC_V2 1
297 #define XEN_DOMCTL_CONFIG_GIC_V3 2
298 
299 #define XEN_DOMCTL_CONFIG_TEE_NONE 0
300 #define XEN_DOMCTL_CONFIG_TEE_OPTEE 1
301 
302 struct xen_arch_domainconfig {
303  /* IN/OUT */
304  uint8_t gic_version;
305  /* IN */
306  uint16_t tee_type;
307  /* IN */
308  uint32_t nr_spis;
309  /*
310  * OUT
311  * Based on the property clock-frequency in the DT timer node.
312  * The property may be present when the bootloader/firmware doesn't
313  * set correctly CNTFRQ which hold the timer frequency.
314  *
315  * As it's not possible to trap this register, we have to replicate
316  * the value in the guest DT.
317  *
318  * = 0 => property not present
319  * > 0 => Value of the property
320  *
321  */
322  uint32_t clock_frequency;
323 };
324 #endif /* __XEN__ || __XEN_TOOLS__ */
325 
326 struct arch_vcpu_info {
327 };
329 
330 struct arch_shared_info {
331 };
334 
335 #endif
336 
337 #if defined(__XEN__) || defined(__XEN_TOOLS__)
338 
339 /* PSR bits (CPSR, SPSR) */
340 
341 #define PSR_THUMB (1<<5) /* Thumb Mode enable */
342 #define PSR_FIQ_MASK (1<<6) /* Fast Interrupt mask */
343 #define PSR_IRQ_MASK (1<<7) /* Interrupt mask */
344 #define PSR_ABT_MASK (1<<8) /* Asynchronous Abort mask */
345 #define PSR_BIG_ENDIAN (1<<9) /* arm32: Big Endian Mode */
346 #define PSR_DBG_MASK (1<<9) /* arm64: Debug Exception mask */
347 #define PSR_IT_MASK (0x0600fc00) /* Thumb If-Then Mask */
348 #define PSR_JAZELLE (1<<24) /* Jazelle Mode */
349 #define PSR_Z (1<<30) /* Zero condition flag */
350 
351 /* 32 bit modes */
352 #define PSR_MODE_USR 0x10
353 #define PSR_MODE_FIQ 0x11
354 #define PSR_MODE_IRQ 0x12
355 #define PSR_MODE_SVC 0x13
356 #define PSR_MODE_MON 0x16
357 #define PSR_MODE_ABT 0x17
358 #define PSR_MODE_HYP 0x1a
359 #define PSR_MODE_UND 0x1b
360 #define PSR_MODE_SYS 0x1f
361 
362 /* 64 bit modes */
363 #define PSR_MODE_BIT 0x10 /* Set iff AArch32 */
364 #define PSR_MODE_EL3h 0x0d
365 #define PSR_MODE_EL3t 0x0c
366 #define PSR_MODE_EL2h 0x09
367 #define PSR_MODE_EL2t 0x08
368 #define PSR_MODE_EL1h 0x05
369 #define PSR_MODE_EL1t 0x04
370 #define PSR_MODE_EL0t 0x00
371 
372 /*
373  * We set PSR_Z to be able to boot Linux kernel versions with an invalid
374  * encoding of the first 8 NOP instructions. See commit a92882a4d270 in
375  * Linux.
376  *
377  * Note that PSR_Z is also set by U-Boot and QEMU -kernel when loading
378  * zImage kernels on aarch32.
379  */
380 #define PSR_GUEST32_INIT (PSR_Z|PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_SVC)
381 #define PSR_GUEST64_INIT (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_EL1h)
382 
383 #define SCTLR_GUEST_INIT xen_mk_ullong(0x00c50078)
384 
385 /*
386  * Virtual machine platform (memory layout, interrupts)
387  *
388  * These are defined for consistency between the tools and the
389  * hypervisor. Guests must not rely on these hardcoded values but
390  * should instead use the FDT.
391  */
392 
393 /* Physical Address Space */
394 
395 /* Virtio MMIO mappings */
396 #define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000)
397 #define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000)
398 
399 /*
400  * vGIC mappings: Only one set of mapping is used by the guest.
401  * Therefore they can overlap.
402  */
403 
404 /* vGIC v2 mappings */
405 #define GUEST_GICD_BASE xen_mk_ullong(0x03001000)
406 #define GUEST_GICD_SIZE xen_mk_ullong(0x00001000)
407 #define GUEST_GICC_BASE xen_mk_ullong(0x03002000)
408 #define GUEST_GICC_SIZE xen_mk_ullong(0x00002000)
409 
410 /* vGIC v3 mappings */
411 #define GUEST_GICV3_GICD_BASE xen_mk_ullong(0x03001000)
412 #define GUEST_GICV3_GICD_SIZE xen_mk_ullong(0x00010000)
413 
414 #define GUEST_GICV3_RDIST_REGIONS 1
415 
416 #define GUEST_GICV3_GICR0_BASE xen_mk_ullong(0x03020000) /* vCPU0..127 */
417 #define GUEST_GICV3_GICR0_SIZE xen_mk_ullong(0x01000000)
418 
419 /*
420  * 256 MB is reserved for VPCI configuration space based on calculation
421  * 256 buses x 32 devices x 8 functions x 4 KB = 256 MB
422  */
423 #define GUEST_VPCI_ECAM_BASE xen_mk_ullong(0x10000000)
424 #define GUEST_VPCI_ECAM_SIZE xen_mk_ullong(0x10000000)
425 
426 /* ACPI tables physical address */
427 #define GUEST_ACPI_BASE xen_mk_ullong(0x20000000)
428 #define GUEST_ACPI_SIZE xen_mk_ullong(0x02000000)
429 
430 /* PL011 mappings */
431 #define GUEST_PL011_BASE xen_mk_ullong(0x22000000)
432 #define GUEST_PL011_SIZE xen_mk_ullong(0x00001000)
433 
434 /* Guest PCI-PCIe memory space where config space and BAR will be available.*/
435 #define GUEST_VPCI_ADDR_TYPE_MEM xen_mk_ullong(0x02000000)
436 #define GUEST_VPCI_MEM_ADDR xen_mk_ullong(0x23000000)
437 #define GUEST_VPCI_MEM_SIZE xen_mk_ullong(0x10000000)
438 
439 /*
440  * 16MB == 4096 pages reserved for guest to use as a region to map its
441  * grant table in.
442  */
443 #define GUEST_GNTTAB_BASE xen_mk_ullong(0x38000000)
444 #define GUEST_GNTTAB_SIZE xen_mk_ullong(0x01000000)
445 
446 #define GUEST_MAGIC_BASE xen_mk_ullong(0x39000000)
447 #define GUEST_MAGIC_SIZE xen_mk_ullong(0x01000000)
448 
449 #define GUEST_RAM_BANKS 2
450 
451 /*
452  * The way to find the extended regions (to be exposed to the guest as unused
453  * address space) relies on the fact that the regions reserved for the RAM
454  * below are big enough to also accommodate such regions.
455  */
456 #define GUEST_RAM0_BASE xen_mk_ullong(0x40000000) /* 3GB of low RAM @ 1GB */
457 #define GUEST_RAM0_SIZE xen_mk_ullong(0xc0000000)
458 
459 /* 4GB @ 4GB Prefetch Memory for VPCI */
460 #define GUEST_VPCI_ADDR_TYPE_PREFETCH_MEM xen_mk_ullong(0x42000000)
461 #define GUEST_VPCI_PREFETCH_MEM_ADDR xen_mk_ullong(0x100000000)
462 #define GUEST_VPCI_PREFETCH_MEM_SIZE xen_mk_ullong(0x100000000)
463 
464 #define GUEST_RAM1_BASE xen_mk_ullong(0x0200000000) /* 1016GB of RAM @ 8GB */
465 #define GUEST_RAM1_SIZE xen_mk_ullong(0xfe00000000)
466 
467 #define GUEST_RAM_BASE GUEST_RAM0_BASE /* Lowest RAM address */
468 /* Largest amount of actual RAM, not including holes */
469 #define GUEST_RAM_MAX (GUEST_RAM0_SIZE + GUEST_RAM1_SIZE)
470 /* Suitable for e.g. const uint64_t ramfoo[] = GUEST_RAM_BANK_FOOS; */
471 #define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE, GUEST_RAM1_BASE }
472 #define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE }
473 
474 /* Current supported guest VCPUs */
475 #define GUEST_MAX_VCPUS 128
476 
477 /* Interrupts */
478 #define GUEST_TIMER_VIRT_PPI 27
479 #define GUEST_TIMER_PHYS_S_PPI 29
480 #define GUEST_TIMER_PHYS_NS_PPI 30
481 #define GUEST_EVTCHN_PPI 31
482 
483 #define GUEST_VPL011_SPI 32
484 
485 #define GUEST_VIRTIO_MMIO_SPI_FIRST 33
486 #define GUEST_VIRTIO_MMIO_SPI_LAST 43
487 
488 /* PSCI functions */
489 #define PSCI_cpu_suspend 0
490 #define PSCI_cpu_off 1
491 #define PSCI_cpu_on 2
492 #define PSCI_migrate 3
493 
494 #endif
495 
496 #ifndef __ASSEMBLY__
497 /* Stub definition of PMU structure */
499 #endif
500 
501 #endif /* __XEN_PUBLIC_ARCH_ARM_H__ */
502 
503 /*
504  * Local variables:
505  * mode: C
506  * c-file-style: "BSD"
507  * c-basic-offset: 4
508  * tab-width: 4
509  * indent-tabs-mode: nil
510  * End:
511  */
unsigned short uint16_t
Definition: stdint.h:11
unsigned long long uint64_t
Definition: stdint.h:13
uint64_t xen_ulong_t
Definition: arch-arm.h:199
unsigned long flags
Definition: xen.h:179
#define DEFINE_XEN_GUEST_HANDLE(name)
Definition: arch-arm.h:177
#define __DECL_REG(name)
Definition: xen-x86_64.h:154
uint8_t dummy
Definition: arch-arm.h:498
struct xen_pmu_arch xen_pmu_arch_t
unsigned char uint8_t
Definition: stdint.h:10
struct cpu_user_regs user_regs
Definition: xen.h:180
unsigned int uint32_t
Definition: stdint.h:12
uint64_t xen_pfn_t
Definition: arch-arm.h:189
FILE_LICENCE(MIT)
uint64_t xen_callback_t
Definition: arch-arm.h:333