arch-arm.h 16 KB

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