Xen Test Framework
apic.h
Go to the documentation of this file.
1 
10 #ifndef XTF_X86_APIC_H
11 #define XTF_X86_APIC_H
12 
13 #include <xtf/types.h>
14 #include <xen/errno.h>
15 
16 #include <arch/msr-index.h>
17 
18 /* Local APIC register definitions. */
19 #define APIC_ID 0x020
20 #define APIC_LVR 0x030
21 #define APIC_SPIV 0x0f0
22 #define APIC_SPIV_APIC_ENABLED 0x00100
23 
24 #define APIC_ICR 0x300
25 #define APIC_DM_NMI 0x00400
26 #define APIC_ICR_BUSY 0x01000
27 #define APIC_DEST_SELF 0x40000
28 
29 #define APIC_ICR2 0x310
30 
31 #define APIC_DEFAULT_BASE 0xfee00000ul
32 
33 /* Utilities. */
34 
35 enum apic_mode {
41 };
42 
47 int apic_init(enum apic_mode mode);
48 
49 static inline uint32_t apic_mmio_read(unsigned int reg)
50 {
51  return *(volatile uint32_t *)(_p(APIC_DEFAULT_BASE) + reg);
52 }
53 
54 static inline void apic_mmio_write(unsigned int reg, uint32_t val)
55 {
56  *(volatile uint32_t *)(_p(APIC_DEFAULT_BASE) + reg) = val;
57 }
58 
59 static inline void apic_mmio_icr_write(uint64_t val)
60 {
61  apic_mmio_write(APIC_ICR2, (uint32_t)(val >> 32));
63 }
64 
65 static inline uint32_t apic_msr_read(unsigned int reg)
66 {
67  unsigned long val;
68 
69  asm volatile ("rdmsr" : "=a" (val)
70  : "c" (MSR_X2APIC_REGS + (reg >> 4)) : "edx");
71 
72  return val;
73 }
74 
75 static inline void apic_msr_write(unsigned int reg, uint32_t val)
76 {
77  asm volatile ("wrmsr" ::
78  "a" (val), "d" (0),
79  "c" (MSR_X2APIC_REGS + (reg >> 4)));
80 }
81 
82 static inline void apic_msr_icr_write(uint64_t val)
83 {
84  asm volatile ("wrmsr" ::
85  "a" ((uint32_t)val), "d" ((uint32_t)(val >> 32)),
86  "c" (MSR_X2APIC_REGS + (APIC_ICR >> 4)));
87 }
88 
89 extern enum apic_mode cur_apic_mode;
90 
91 static inline uint32_t apic_read(unsigned int reg)
92 {
94  return apic_mmio_read(reg);
95  else
96  return apic_msr_read(reg);
97 }
98 
99 static inline void apic_write(unsigned int reg, uint32_t val)
100 {
102  return apic_mmio_write(reg, val);
103  else
104  return apic_msr_write(reg, val);
105 }
106 
107 static inline void apic_icr_write(uint64_t val)
108 {
110  return apic_mmio_icr_write(val);
111  else
112  return apic_msr_icr_write(val);
113 }
114 
115 #endif /* XTF_X86_APIC_H */
116 
117 /*
118  * Local variables:
119  * mode: C
120  * c-file-style: "BSD"
121  * c-basic-offset: 4
122  * tab-width: 4
123  * indent-tabs-mode: nil
124  * End:
125  */
Common declarations for all tests.
static uint32_t apic_mmio_read(unsigned int reg)
Definition: apic.h:49
enum apic_mode cur_apic_mode
Definition: apic.c:13
mode
Definition: main.c:102
static void apic_msr_write(unsigned int reg, uint32_t val)
Definition: apic.h:75
static void apic_write(unsigned int reg, uint32_t val)
Definition: apic.h:99
static void apic_mmio_icr_write(uint64_t val)
Definition: apic.h:59
static void apic_mmio_write(unsigned int reg, uint32_t val)
Definition: apic.h:54
int apic_init(enum apic_mode mode)
Discover and initialise the local APIC to the requested mode.
Definition: apic.c:33
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
static uint32_t apic_msr_read(unsigned int reg)
Definition: apic.h:65
#define APIC_ICR
Definition: apic.h:24
#define APIC_ICR2
Definition: apic.h:29
static void apic_icr_write(uint64_t val)
Definition: apic.h:107
apic_mode
Definition: apic.h:35
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
#define MSR_X2APIC_REGS
Definition: msr-index.h:47
#define _p(v)
Express an abitrary integer v as void *.
Definition: numbers.h:48
static void apic_msr_icr_write(uint64_t val)
Definition: apic.h:82
#define APIC_DEFAULT_BASE
Definition: apic.h:31
static uint32_t apic_read(unsigned int reg)
Definition: apic.h:91