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
41};
42
47int apic_init(enum apic_mode mode);
48
49static inline uint32_t apic_mmio_read(unsigned int reg)
50{
51 return *(volatile uint32_t *)(_p(APIC_DEFAULT_BASE) + reg);
52}
53
54static inline void apic_mmio_write(unsigned int reg, uint32_t val)
55{
56 *(volatile uint32_t *)(_p(APIC_DEFAULT_BASE) + reg) = val;
57}
58
59static inline void apic_mmio_icr_write(uint64_t val)
60{
61 apic_mmio_write(APIC_ICR2, (uint32_t)(val >> 32));
63}
64
65static 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
75static 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
82static 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
89extern enum apic_mode cur_apic_mode;
90
91static 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
99static 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
107static 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 */
apic_mode
Definition: apic.h:35
@ APIC_MODE_XAPIC
Definition: apic.h:39
@ APIC_MODE_X2APIC
Definition: apic.h:40
@ APIC_MODE_DISABLED
Definition: apic.h:38
@ APIC_MODE_NONE
Definition: apic.h:37
@ APIC_MODE_UNKNOWN
Definition: apic.h:36
static uint32_t apic_mmio_read(unsigned int reg)
Definition: apic.h:49
static void apic_msr_write(unsigned int reg, uint32_t val)
Definition: apic.h:75
enum apic_mode cur_apic_mode
Definition: apic.c:13
static void apic_msr_icr_write(uint64_t val)
Definition: apic.h:82
static void apic_mmio_write(unsigned int reg, uint32_t val)
Definition: apic.h:54
#define APIC_DEFAULT_BASE
Definition: apic.h:31
static void apic_icr_write(uint64_t val)
Definition: apic.h:107
static void apic_mmio_icr_write(uint64_t val)
Definition: apic.h:59
static uint32_t apic_read(unsigned int reg)
Definition: apic.h:91
#define APIC_ICR2
Definition: apic.h:29
static uint32_t apic_msr_read(unsigned int reg)
Definition: apic.h:65
static void apic_write(unsigned int reg, uint32_t val)
Definition: apic.h:99
int apic_init(enum apic_mode mode)
Discover and initialise the local APIC to the requested mode.
Definition: apic.c:33
#define APIC_ICR
Definition: apic.h:24
#define MSR_X2APIC_REGS
Definition: msr-index.h:47
#define _p(v)
Express an abitrary integer v as void *.
Definition: numbers.h:48
mode
Definition: main.c:102
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
Common declarations for all tests.