]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/x86/xen/apic.c
xen/PMU: Initialization code for Xen PMU
[karo-tx-linux.git] / arch / x86 / xen / apic.c
1 #include <linux/init.h>
2
3 #include <asm/x86_init.h>
4 #include <asm/apic.h>
5 #include <asm/xen/hypercall.h>
6
7 #include <xen/xen.h>
8 #include <xen/interface/physdev.h>
9 #include "xen-ops.h"
10 #include "smp.h"
11
12 static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
13 {
14         struct physdev_apic apic_op;
15         int ret;
16
17         apic_op.apic_physbase = mpc_ioapic_addr(apic);
18         apic_op.reg = reg;
19         ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
20         if (!ret)
21                 return apic_op.value;
22
23         /* fallback to return an emulated IO_APIC values */
24         if (reg == 0x1)
25                 return 0x00170020;
26         else if (reg == 0x0)
27                 return apic << 24;
28
29         return 0xfd;
30 }
31
32 static unsigned long xen_set_apic_id(unsigned int x)
33 {
34         WARN_ON(1);
35         return x;
36 }
37
38 static unsigned int xen_get_apic_id(unsigned long x)
39 {
40         return ((x)>>24) & 0xFFu;
41 }
42
43 static u32 xen_apic_read(u32 reg)
44 {
45         struct xen_platform_op op = {
46                 .cmd = XENPF_get_cpuinfo,
47                 .interface_version = XENPF_INTERFACE_VERSION,
48                 .u.pcpu_info.xen_cpuid = 0,
49         };
50         int ret = 0;
51
52         /* Shouldn't need this as APIC is turned off for PV, and we only
53          * get called on the bootup processor. But just in case. */
54         if (!xen_initial_domain() || smp_processor_id())
55                 return 0;
56
57         if (reg == APIC_LVR)
58                 return 0x10;
59 #ifdef CONFIG_X86_32
60         if (reg == APIC_LDR)
61                 return SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
62 #endif
63         if (reg != APIC_ID)
64                 return 0;
65
66         ret = HYPERVISOR_dom0_op(&op);
67         if (ret)
68                 return 0;
69
70         return op.u.pcpu_info.apic_id << 24;
71 }
72
73 static void xen_apic_write(u32 reg, u32 val)
74 {
75         if (reg == APIC_LVTPC)
76                 return;
77
78         /* Warn to see if there's any stray references */
79         WARN(1,"register: %x, value: %x\n", reg, val);
80 }
81
82 static u64 xen_apic_icr_read(void)
83 {
84         return 0;
85 }
86
87 static void xen_apic_icr_write(u32 low, u32 id)
88 {
89         /* Warn to see if there's any stray references */
90         WARN_ON(1);
91 }
92
93 static u32 xen_safe_apic_wait_icr_idle(void)
94 {
95         return 0;
96 }
97
98 static int xen_apic_probe_pv(void)
99 {
100         if (xen_pv_domain())
101                 return 1;
102
103         return 0;
104 }
105
106 static int xen_madt_oem_check(char *oem_id, char *oem_table_id)
107 {
108         return xen_pv_domain();
109 }
110
111 static int xen_id_always_valid(int apicid)
112 {
113         return 1;
114 }
115
116 static int xen_id_always_registered(void)
117 {
118         return 1;
119 }
120
121 static int xen_phys_pkg_id(int initial_apic_id, int index_msb)
122 {
123         return initial_apic_id >> index_msb;
124 }
125
126 #ifdef CONFIG_X86_32
127 static int xen_x86_32_early_logical_apicid(int cpu)
128 {
129         /* Match with APIC_LDR read. Otherwise setup_local_APIC complains. */
130         return 1 << cpu;
131 }
132 #endif
133
134 static void xen_noop(void)
135 {
136 }
137
138 static void xen_silent_inquire(int apicid)
139 {
140 }
141
142 static struct apic xen_pv_apic = {
143         .name                           = "Xen PV",
144         .probe                          = xen_apic_probe_pv,
145         .acpi_madt_oem_check            = xen_madt_oem_check,
146         .apic_id_valid                  = xen_id_always_valid,
147         .apic_id_registered             = xen_id_always_registered,
148
149         /* .irq_delivery_mode - used in native_compose_msi_msg only */
150         /* .irq_dest_mode     - used in native_compose_msi_msg only */
151
152         .target_cpus                    = default_target_cpus,
153         .disable_esr                    = 0,
154         /* .dest_logical      -  default_send_IPI_ use it but we use our own. */
155         .check_apicid_used              = default_check_apicid_used, /* Used on 32-bit */
156
157         .vector_allocation_domain       = flat_vector_allocation_domain,
158         .init_apic_ldr                  = xen_noop, /* setup_local_APIC calls it */
159
160         .ioapic_phys_id_map             = default_ioapic_phys_id_map, /* Used on 32-bit */
161         .setup_apic_routing             = NULL,
162         .cpu_present_to_apicid          = default_cpu_present_to_apicid,
163         .apicid_to_cpu_present          = physid_set_mask_of_physid, /* Used on 32-bit */
164         .check_phys_apicid_present      = default_check_phys_apicid_present, /* smp_sanity_check needs it */
165         .phys_pkg_id                    = xen_phys_pkg_id, /* detect_ht */
166
167         .get_apic_id                    = xen_get_apic_id,
168         .set_apic_id                    = xen_set_apic_id, /* Can be NULL on 32-bit. */
169         .apic_id_mask                   = 0xFF << 24, /* Used by verify_local_APIC. Match with what xen_get_apic_id does. */
170
171         .cpu_mask_to_apicid_and         = flat_cpu_mask_to_apicid_and,
172
173 #ifdef CONFIG_SMP
174         .send_IPI_mask                  = xen_send_IPI_mask,
175         .send_IPI_mask_allbutself       = xen_send_IPI_mask_allbutself,
176         .send_IPI_allbutself            = xen_send_IPI_allbutself,
177         .send_IPI_all                   = xen_send_IPI_all,
178         .send_IPI_self                  = xen_send_IPI_self,
179 #endif
180         /* .wait_for_init_deassert- used  by AP bootup - smp_callin which we don't use */
181         .inquire_remote_apic            = xen_silent_inquire,
182
183         .read                           = xen_apic_read,
184         .write                          = xen_apic_write,
185         .eoi_write                      = xen_apic_write,
186
187         .icr_read                       = xen_apic_icr_read,
188         .icr_write                      = xen_apic_icr_write,
189         .wait_icr_idle                  = xen_noop,
190         .safe_wait_icr_idle             = xen_safe_apic_wait_icr_idle,
191
192 #ifdef CONFIG_X86_32
193         /* generic_processor_info and setup_local_APIC. */
194         .x86_32_early_logical_apicid    = xen_x86_32_early_logical_apicid,
195 #endif
196 };
197
198 static void __init xen_apic_check(void)
199 {
200         if (apic == &xen_pv_apic)
201                 return;
202
203         pr_info("Switched APIC routing from %s to %s.\n", apic->name,
204                 xen_pv_apic.name);
205         apic = &xen_pv_apic;
206 }
207 void __init xen_init_apic(void)
208 {
209         x86_io_apic_ops.read = xen_io_apic_read;
210         /* On PV guests the APIC CPUID bit is disabled so none of the
211          * routines end up executing. */
212         if (!xen_initial_domain())
213                 apic = &xen_pv_apic;
214
215         x86_platform.apic_post_init = xen_apic_check;
216 }
217 apic_driver(xen_pv_apic);