You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

arch-arm.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. FILE_LICENCE ( MIT );
  29. /*
  30. * `incontents 50 arm_abi Hypercall Calling Convention
  31. *
  32. * A hypercall is issued using the ARM HVC instruction.
  33. *
  34. * A hypercall can take up to 5 arguments. These are passed in
  35. * registers, the first argument in x0/r0 (for arm64/arm32 guests
  36. * respectively irrespective of whether the underlying hypervisor is
  37. * 32- or 64-bit), the second argument in x1/r1, the third in x2/r2,
  38. * the forth in x3/r3 and the fifth in x4/r4.
  39. *
  40. * The hypercall number is passed in r12 (arm) or x16 (arm64). In both
  41. * cases the relevant ARM procedure calling convention specifies this
  42. * is an inter-procedure-call scratch register (e.g. for use in linker
  43. * stubs). This use does not conflict with use during a hypercall.
  44. *
  45. * The HVC ISS must contain a Xen specific TAG: XEN_HYPERCALL_TAG.
  46. *
  47. * The return value is in x0/r0.
  48. *
  49. * The hypercall will clobber x16/r12 and the argument registers used
  50. * by that hypercall (except r0 which is the return value) i.e. in
  51. * addition to x16/r12 a 2 argument hypercall will clobber x1/r1 and a
  52. * 4 argument hypercall will clobber x1/r1, x2/r2 and x3/r3.
  53. *
  54. * Parameter structs passed to hypercalls are laid out according to
  55. * the Procedure Call Standard for the ARM Architecture (AAPCS, AKA
  56. * EABI) and Procedure Call Standard for the ARM 64-bit Architecture
  57. * (AAPCS64). Where there is a conflict the 64-bit standard should be
  58. * used regardless of guest type. Structures which are passed as
  59. * hypercall arguments are always little endian.
  60. *
  61. * All memory which is shared with other entities in the system
  62. * (including the hypervisor and other guests) must reside in memory
  63. * which is mapped as Normal Inner-cacheable. 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 Inner cache allocation strategy (Write-Back, Write-Through etc)
  71. * is acceptable. There is no restriction on the Outer-cacheability.
  72. */
  73. /*
  74. * `incontents 55 arm_hcall Supported Hypercalls
  75. *
  76. * Xen on ARM makes extensive use of hardware facilities and therefore
  77. * only a subset of the potential hypercalls are required.
  78. *
  79. * Since ARM uses second stage paging any machine/physical addresses
  80. * passed to hypercalls are Guest Physical Addresses (Intermediate
  81. * Physical Addresses) unless otherwise noted.
  82. *
  83. * The following hypercalls (and sub operations) are supported on the
  84. * ARM platform. Other hypercalls should be considered
  85. * unavailable/unsupported.
  86. *
  87. * HYPERVISOR_memory_op
  88. * All generic sub-operations.
  89. *
  90. * In addition the following arch specific sub-ops:
  91. * * XENMEM_add_to_physmap
  92. * * XENMEM_add_to_physmap_batch
  93. *
  94. * HYPERVISOR_domctl
  95. * All generic sub-operations, with the exception of:
  96. * * XEN_DOMCTL_iomem_permission (not yet implemented)
  97. * * XEN_DOMCTL_irq_permission (not yet implemented)
  98. *
  99. * HYPERVISOR_sched_op
  100. * All generic sub-operations, with the exception of:
  101. * * SCHEDOP_block -- prefer wfi hardware instruction
  102. *
  103. * HYPERVISOR_console_io
  104. * All generic sub-operations
  105. *
  106. * HYPERVISOR_xen_version
  107. * All generic sub-operations
  108. *
  109. * HYPERVISOR_event_channel_op
  110. * All generic sub-operations
  111. *
  112. * HYPERVISOR_physdev_op
  113. * No sub-operations are currenty supported
  114. *
  115. * HYPERVISOR_sysctl
  116. * All generic sub-operations, with the exception of:
  117. * * XEN_SYSCTL_page_offline_op
  118. * * XEN_SYSCTL_get_pmstat
  119. * * XEN_SYSCTL_pm_op
  120. *
  121. * HYPERVISOR_hvm_op
  122. * Exactly these sub-operations are supported:
  123. * * HVMOP_set_param
  124. * * HVMOP_get_param
  125. *
  126. * HYPERVISOR_grant_table_op
  127. * All generic sub-operations
  128. *
  129. * HYPERVISOR_vcpu_op
  130. * Exactly these sub-operations are supported:
  131. * * VCPUOP_register_vcpu_info
  132. * * VCPUOP_register_runstate_memory_area
  133. *
  134. *
  135. * Other notes on the ARM ABI:
  136. *
  137. * - struct start_info is not exported to ARM guests.
  138. *
  139. * - struct shared_info is mapped by ARM guests using the
  140. * HYPERVISOR_memory_op sub-op XENMEM_add_to_physmap, passing
  141. * XENMAPSPACE_shared_info as space parameter.
  142. *
  143. * - All the per-cpu struct vcpu_info are mapped by ARM guests using the
  144. * HYPERVISOR_vcpu_op sub-op VCPUOP_register_vcpu_info, including cpu0
  145. * struct vcpu_info.
  146. *
  147. * - The grant table is mapped using the HYPERVISOR_memory_op sub-op
  148. * XENMEM_add_to_physmap, passing XENMAPSPACE_grant_table as space
  149. * parameter. The memory range specified under the Xen compatible
  150. * hypervisor node on device tree can be used as target gpfn for the
  151. * mapping.
  152. *
  153. * - Xenstore is initialized by using the two hvm_params
  154. * HVM_PARAM_STORE_PFN and HVM_PARAM_STORE_EVTCHN. They can be read
  155. * with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
  156. *
  157. * - The paravirtualized console is initialized by using the two
  158. * hvm_params HVM_PARAM_CONSOLE_PFN and HVM_PARAM_CONSOLE_EVTCHN. They
  159. * can be read with the HYPERVISOR_hvm_op sub-op HVMOP_get_param.
  160. *
  161. * - Event channel notifications are delivered using the percpu GIC
  162. * interrupt specified under the Xen compatible hypervisor node on
  163. * device tree.
  164. *
  165. * - The device tree Xen compatible node is fully described under Linux
  166. * at Documentation/devicetree/bindings/arm/xen.txt.
  167. */
  168. #define XEN_HYPERCALL_TAG 0XEA1
  169. #define uint64_aligned_t uint64_t __attribute__((aligned(8)))
  170. #ifndef __ASSEMBLY__
  171. #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
  172. typedef union { type *p; unsigned long q; } \
  173. __guest_handle_ ## name; \
  174. typedef union { type *p; uint64_aligned_t q; } \
  175. __guest_handle_64_ ## name;
  176. /*
  177. * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
  178. * in a struct in memory. On ARM is always 8 bytes sizes and 8 bytes
  179. * aligned.
  180. * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an
  181. * hypercall argument. It is 4 bytes on aarch and 8 bytes on aarch64.
  182. */
  183. #define __DEFINE_XEN_GUEST_HANDLE(name, type) \
  184. ___DEFINE_XEN_GUEST_HANDLE(name, type); \
  185. ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
  186. #define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name)
  187. #define __XEN_GUEST_HANDLE(name) __guest_handle_64_ ## name
  188. #define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name)
  189. /* this is going to be changed on 64 bit */
  190. #define XEN_GUEST_HANDLE_PARAM(name) __guest_handle_ ## name
  191. #define set_xen_guest_handle_raw(hnd, val) \
  192. do { \
  193. typeof(&(hnd)) _sxghr_tmp = &(hnd); \
  194. _sxghr_tmp->q = 0; \
  195. _sxghr_tmp->p = val; \
  196. } while ( 0 )
  197. #ifdef __XEN_TOOLS__
  198. #define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0)
  199. #endif
  200. #define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
  201. #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  202. /* Anonymous union includes both 32- and 64-bit names (e.g., r0/x0). */
  203. # define __DECL_REG(n64, n32) union { \
  204. uint64_t n64; \
  205. uint32_t n32; \
  206. }
  207. #else
  208. /* Non-gcc sources must always use the proper 64-bit name (e.g., x0). */
  209. #define __DECL_REG(n64, n32) uint64_t n64
  210. #endif
  211. struct vcpu_guest_core_regs
  212. {
  213. /* Aarch64 Aarch32 */
  214. __DECL_REG(x0, r0_usr);
  215. __DECL_REG(x1, r1_usr);
  216. __DECL_REG(x2, r2_usr);
  217. __DECL_REG(x3, r3_usr);
  218. __DECL_REG(x4, r4_usr);
  219. __DECL_REG(x5, r5_usr);
  220. __DECL_REG(x6, r6_usr);
  221. __DECL_REG(x7, r7_usr);
  222. __DECL_REG(x8, r8_usr);
  223. __DECL_REG(x9, r9_usr);
  224. __DECL_REG(x10, r10_usr);
  225. __DECL_REG(x11, r11_usr);
  226. __DECL_REG(x12, r12_usr);
  227. __DECL_REG(x13, sp_usr);
  228. __DECL_REG(x14, lr_usr);
  229. __DECL_REG(x15, __unused_sp_hyp);
  230. __DECL_REG(x16, lr_irq);
  231. __DECL_REG(x17, sp_irq);
  232. __DECL_REG(x18, lr_svc);
  233. __DECL_REG(x19, sp_svc);
  234. __DECL_REG(x20, lr_abt);
  235. __DECL_REG(x21, sp_abt);
  236. __DECL_REG(x22, lr_und);
  237. __DECL_REG(x23, sp_und);
  238. __DECL_REG(x24, r8_fiq);
  239. __DECL_REG(x25, r9_fiq);
  240. __DECL_REG(x26, r10_fiq);
  241. __DECL_REG(x27, r11_fiq);
  242. __DECL_REG(x28, r12_fiq);
  243. __DECL_REG(x29, sp_fiq);
  244. __DECL_REG(x30, lr_fiq);
  245. /* Return address and mode */
  246. __DECL_REG(pc64, pc32); /* ELR_EL2 */
  247. uint32_t cpsr; /* SPSR_EL2 */
  248. union {
  249. uint32_t spsr_el1; /* AArch64 */
  250. uint32_t spsr_svc; /* AArch32 */
  251. };
  252. /* AArch32 guests only */
  253. uint32_t spsr_fiq, spsr_irq, spsr_und, spsr_abt;
  254. /* AArch64 guests only */
  255. uint64_t sp_el0;
  256. uint64_t sp_el1, elr_el1;
  257. };
  258. typedef struct vcpu_guest_core_regs vcpu_guest_core_regs_t;
  259. DEFINE_XEN_GUEST_HANDLE(vcpu_guest_core_regs_t);
  260. #undef __DECL_REG
  261. typedef uint64_t xen_pfn_t;
  262. #define PRI_xen_pfn PRIx64
  263. /* Maximum number of virtual CPUs in legacy multi-processor guests. */
  264. /* Only one. All other VCPUS must use VCPUOP_register_vcpu_info */
  265. #define XEN_LEGACY_MAX_VCPUS 1
  266. typedef uint64_t xen_ulong_t;
  267. #define PRI_xen_ulong PRIx64
  268. #if defined(__XEN__) || defined(__XEN_TOOLS__)
  269. struct vcpu_guest_context {
  270. #define _VGCF_online 0
  271. #define VGCF_online (1<<_VGCF_online)
  272. uint32_t flags; /* VGCF_* */
  273. struct vcpu_guest_core_regs user_regs; /* Core CPU registers */
  274. uint32_t sctlr;
  275. uint64_t ttbcr, ttbr0, ttbr1;
  276. };
  277. typedef struct vcpu_guest_context vcpu_guest_context_t;
  278. DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
  279. #endif
  280. struct arch_vcpu_info {
  281. };
  282. typedef struct arch_vcpu_info arch_vcpu_info_t;
  283. struct arch_shared_info {
  284. };
  285. typedef struct arch_shared_info arch_shared_info_t;
  286. typedef uint64_t xen_callback_t;
  287. #endif
  288. #if defined(__XEN__) || defined(__XEN_TOOLS__)
  289. /* PSR bits (CPSR, SPSR)*/
  290. #define PSR_THUMB (1<<5) /* Thumb Mode enable */
  291. #define PSR_FIQ_MASK (1<<6) /* Fast Interrupt mask */
  292. #define PSR_IRQ_MASK (1<<7) /* Interrupt mask */
  293. #define PSR_ABT_MASK (1<<8) /* Asynchronous Abort mask */
  294. #define PSR_BIG_ENDIAN (1<<9) /* arm32: Big Endian Mode */
  295. #define PSR_DBG_MASK (1<<9) /* arm64: Debug Exception mask */
  296. #define PSR_IT_MASK (0x0600fc00) /* Thumb If-Then Mask */
  297. #define PSR_JAZELLE (1<<24) /* Jazelle Mode */
  298. /* 32 bit modes */
  299. #define PSR_MODE_USR 0x10
  300. #define PSR_MODE_FIQ 0x11
  301. #define PSR_MODE_IRQ 0x12
  302. #define PSR_MODE_SVC 0x13
  303. #define PSR_MODE_MON 0x16
  304. #define PSR_MODE_ABT 0x17
  305. #define PSR_MODE_HYP 0x1a
  306. #define PSR_MODE_UND 0x1b
  307. #define PSR_MODE_SYS 0x1f
  308. /* 64 bit modes */
  309. #define PSR_MODE_BIT 0x10 /* Set iff AArch32 */
  310. #define PSR_MODE_EL3h 0x0d
  311. #define PSR_MODE_EL3t 0x0c
  312. #define PSR_MODE_EL2h 0x09
  313. #define PSR_MODE_EL2t 0x08
  314. #define PSR_MODE_EL1h 0x05
  315. #define PSR_MODE_EL1t 0x04
  316. #define PSR_MODE_EL0t 0x00
  317. #define PSR_GUEST32_INIT (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_SVC)
  318. #define PSR_GUEST64_INIT (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_EL1h)
  319. #define SCTLR_GUEST_INIT 0x00c50078
  320. /*
  321. * Virtual machine platform (memory layout, interrupts)
  322. *
  323. * These are defined for consistency between the tools and the
  324. * hypervisor. Guests must not rely on these hardcoded values but
  325. * should instead use the FDT.
  326. */
  327. /* Physical Address Space */
  328. #define GUEST_GICD_BASE 0x03001000ULL
  329. #define GUEST_GICD_SIZE 0x00001000ULL
  330. #define GUEST_GICC_BASE 0x03002000ULL
  331. #define GUEST_GICC_SIZE 0x00000100ULL
  332. /* 16MB == 4096 pages reserved for guest to use as a region to map its
  333. * grant table in.
  334. */
  335. #define GUEST_GNTTAB_BASE 0x38000000ULL
  336. #define GUEST_GNTTAB_SIZE 0x01000000ULL
  337. #define GUEST_MAGIC_BASE 0x39000000ULL
  338. #define GUEST_MAGIC_SIZE 0x01000000ULL
  339. #define GUEST_RAM_BANKS 2
  340. #define GUEST_RAM0_BASE 0x40000000ULL /* 3GB of low RAM @ 1GB */
  341. #define GUEST_RAM0_SIZE 0xc0000000ULL
  342. #define GUEST_RAM1_BASE 0x0200000000ULL /* 1016GB of RAM @ 8GB */
  343. #define GUEST_RAM1_SIZE 0xfe00000000ULL
  344. #define GUEST_RAM_BASE GUEST_RAM0_BASE /* Lowest RAM address */
  345. /* Largest amount of actual RAM, not including holes */
  346. #define GUEST_RAM_MAX (GUEST_RAM0_SIZE + GUEST_RAM1_SIZE)
  347. /* Suitable for e.g. const uint64_t ramfoo[] = GUEST_RAM_BANK_FOOS; */
  348. #define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE, GUEST_RAM1_BASE }
  349. #define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE }
  350. /* Interrupts */
  351. #define GUEST_TIMER_VIRT_PPI 27
  352. #define GUEST_TIMER_PHYS_S_PPI 29
  353. #define GUEST_TIMER_PHYS_NS_PPI 30
  354. #define GUEST_EVTCHN_PPI 31
  355. /* PSCI functions */
  356. #define PSCI_cpu_suspend 0
  357. #define PSCI_cpu_off 1
  358. #define PSCI_cpu_on 2
  359. #define PSCI_migrate 3
  360. #endif
  361. #endif /* __XEN_PUBLIC_ARCH_ARM_H__ */
  362. /*
  363. * Local variables:
  364. * mode: C
  365. * c-file-style: "BSD"
  366. * c-basic-offset: 4
  367. * tab-width: 4
  368. * indent-tabs-mode: nil
  369. * End:
  370. */