arch-arm.h 17 KB

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