vserver 1.9.3
[linux-2.6.git] / arch / ia64 / kernel / acpi.c
1 /*
2  *  acpi.c - Architecture-Specific Low-Level ACPI Support
3  *
4  *  Copyright (C) 1999 VA Linux Systems
5  *  Copyright (C) 1999,2000 Walt Drummond <drummond@valinux.com>
6  *  Copyright (C) 2000, 2002-2003 Hewlett-Packard Co.
7  *      David Mosberger-Tang <davidm@hpl.hp.com>
8  *  Copyright (C) 2000 Intel Corp.
9  *  Copyright (C) 2000,2001 J.I. Lee <jung-ik.lee@intel.com>
10  *  Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
11  *  Copyright (C) 2001 Jenna Hall <jenna.s.hall@intel.com>
12  *  Copyright (C) 2001 Takayoshi Kochi <t-kochi@bq.jp.nec.com>
13  *  Copyright (C) 2002 Erich Focht <efocht@ess.nec.de>
14  *
15  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16  *
17  *  This program is free software; you can redistribute it and/or modify
18  *  it under the terms of the GNU General Public License as published by
19  *  the Free Software Foundation; either version 2 of the License, or
20  *  (at your option) any later version.
21  *
22  *  This program is distributed in the hope that it will be useful,
23  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  *  GNU General Public License for more details.
26  *
27  *  You should have received a copy of the GNU General Public License
28  *  along with this program; if not, write to the Free Software
29  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  *
31  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32  */
33
34 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/smp.h>
40 #include <linux/string.h>
41 #include <linux/types.h>
42 #include <linux/irq.h>
43 #include <linux/acpi.h>
44 #include <linux/efi.h>
45 #include <linux/mmzone.h>
46 #include <asm/io.h>
47 #include <asm/iosapic.h>
48 #include <asm/machvec.h>
49 #include <asm/page.h>
50 #include <asm/system.h>
51 #include <asm/numa.h>
52 #include <asm/sal.h>
53 #include <asm/cyclone.h>
54
55 #define BAD_MADT_ENTRY(entry, end) (                                        \
56                 (!entry) || (unsigned long)entry + sizeof(*entry) > end ||  \
57                 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
58
59 #define PREFIX                  "ACPI: "
60
61 void (*pm_idle) (void);
62 EXPORT_SYMBOL(pm_idle);
63 void (*pm_power_off) (void);
64 EXPORT_SYMBOL(pm_power_off);
65
66 unsigned char acpi_kbd_controller_present = 1;
67 unsigned char acpi_legacy_devices;
68
69 #define MAX_SAPICS 256
70 u16 ia64_acpiid_to_sapicid[MAX_SAPICS] =
71         { [0 ... MAX_SAPICS - 1] = -1 };
72 EXPORT_SYMBOL(ia64_acpiid_to_sapicid);
73
74 const char *
75 acpi_get_sysname (void)
76 {
77 #ifdef CONFIG_IA64_GENERIC
78         unsigned long rsdp_phys;
79         struct acpi20_table_rsdp *rsdp;
80         struct acpi_table_xsdt *xsdt;
81         struct acpi_table_header *hdr;
82
83         rsdp_phys = acpi_find_rsdp();
84         if (!rsdp_phys) {
85                 printk(KERN_ERR "ACPI 2.0 RSDP not found, default to \"dig\"\n");
86                 return "dig";
87         }
88
89         rsdp = (struct acpi20_table_rsdp *) __va(rsdp_phys);
90         if (strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1)) {
91                 printk(KERN_ERR "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
92                 return "dig";
93         }
94
95         xsdt = (struct acpi_table_xsdt *) __va(rsdp->xsdt_address);
96         hdr = &xsdt->header;
97         if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1)) {
98                 printk(KERN_ERR "ACPI 2.0 XSDT signature incorrect, default to \"dig\"\n");
99                 return "dig";
100         }
101
102         if (!strcmp(hdr->oem_id, "HP")) {
103                 return "hpzx1";
104         }
105         else if (!strcmp(hdr->oem_id, "SGI")) {
106                 return "sn2";
107         }
108
109         return "dig";
110 #else
111 # if defined (CONFIG_IA64_HP_SIM)
112         return "hpsim";
113 # elif defined (CONFIG_IA64_HP_ZX1)
114         return "hpzx1";
115 # elif defined (CONFIG_IA64_SGI_SN2)
116         return "sn2";
117 # elif defined (CONFIG_IA64_DIG)
118         return "dig";
119 # else
120 #       error Unknown platform.  Fix acpi.c.
121 # endif
122 #endif
123 }
124
125 #ifdef CONFIG_ACPI_BOOT
126
127 #define ACPI_MAX_PLATFORM_INTERRUPTS    256
128
129 /* Array to record platform interrupt vectors for generic interrupt routing. */
130 int platform_intr_list[ACPI_MAX_PLATFORM_INTERRUPTS] = {
131         [0 ... ACPI_MAX_PLATFORM_INTERRUPTS - 1] = -1
132 };
133
134 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_IOSAPIC;
135
136 /*
137  * Interrupt routing API for device drivers.  Provides interrupt vector for
138  * a generic platform event.  Currently only CPEI is implemented.
139  */
140 int
141 acpi_request_vector (u32 int_type)
142 {
143         int vector = -1;
144
145         if (int_type < ACPI_MAX_PLATFORM_INTERRUPTS) {
146                 /* corrected platform error interrupt */
147                 vector = platform_intr_list[int_type];
148         } else
149                 printk(KERN_ERR "acpi_request_vector(): invalid interrupt type\n");
150         return vector;
151 }
152
153 char *
154 __acpi_map_table (unsigned long phys_addr, unsigned long size)
155 {
156         return __va(phys_addr);
157 }
158
159 /* --------------------------------------------------------------------------
160                             Boot-time Table Parsing
161    -------------------------------------------------------------------------- */
162
163 static int                      total_cpus __initdata;
164 static int                      available_cpus __initdata;
165 struct acpi_table_madt *        acpi_madt __initdata;
166 static u8                       has_8259;
167
168
169 static int __init
170 acpi_parse_lapic_addr_ovr (
171         acpi_table_entry_header *header, const unsigned long end)
172 {
173         struct acpi_table_lapic_addr_ovr *lapic;
174
175         lapic = (struct acpi_table_lapic_addr_ovr *) header;
176
177         if (BAD_MADT_ENTRY(lapic, end))
178                 return -EINVAL;
179
180         if (lapic->address) {
181                 iounmap(ipi_base_addr);
182                 ipi_base_addr = ioremap(lapic->address, 0);
183         }
184         return 0;
185 }
186
187
188 static int __init
189 acpi_parse_lsapic (acpi_table_entry_header *header, const unsigned long end)
190 {
191         struct acpi_table_lsapic *lsapic;
192
193         lsapic = (struct acpi_table_lsapic *) header;
194
195         if (BAD_MADT_ENTRY(lsapic, end))
196                 return -EINVAL;
197
198         if (lsapic->flags.enabled) {
199 #ifdef CONFIG_SMP
200                 smp_boot_data.cpu_phys_id[available_cpus] = (lsapic->id << 8) | lsapic->eid;
201 #endif
202                 ia64_acpiid_to_sapicid[lsapic->acpi_id] = (lsapic->id << 8) | lsapic->eid;
203                 ++available_cpus;
204         }
205
206         total_cpus++;
207         return 0;
208 }
209
210
211 static int __init
212 acpi_parse_lapic_nmi (acpi_table_entry_header *header, const unsigned long end)
213 {
214         struct acpi_table_lapic_nmi *lacpi_nmi;
215
216         lacpi_nmi = (struct acpi_table_lapic_nmi*) header;
217
218         if (BAD_MADT_ENTRY(lacpi_nmi, end))
219                 return -EINVAL;
220
221         /* TBD: Support lapic_nmi entries */
222         return 0;
223 }
224
225
226 static int __init
227 acpi_parse_iosapic (acpi_table_entry_header *header, const unsigned long end)
228 {
229         struct acpi_table_iosapic *iosapic;
230
231         iosapic = (struct acpi_table_iosapic *) header;
232
233         if (BAD_MADT_ENTRY(iosapic, end))
234                 return -EINVAL;
235
236         iosapic_init(iosapic->address, iosapic->global_irq_base);
237
238         return 0;
239 }
240
241
242 static int __init
243 acpi_parse_plat_int_src (
244         acpi_table_entry_header *header, const unsigned long end)
245 {
246         struct acpi_table_plat_int_src *plintsrc;
247         int vector;
248
249         plintsrc = (struct acpi_table_plat_int_src *) header;
250
251         if (BAD_MADT_ENTRY(plintsrc, end))
252                 return -EINVAL;
253
254         /*
255          * Get vector assignment for this interrupt, set attributes,
256          * and program the IOSAPIC routing table.
257          */
258         vector = iosapic_register_platform_intr(plintsrc->type,
259                                                 plintsrc->global_irq,
260                                                 plintsrc->iosapic_vector,
261                                                 plintsrc->eid,
262                                                 plintsrc->id,
263                                                 (plintsrc->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
264                                                 (plintsrc->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
265
266         platform_intr_list[plintsrc->type] = vector;
267         return 0;
268 }
269
270
271 static int __init
272 acpi_parse_int_src_ovr (
273         acpi_table_entry_header *header, const unsigned long end)
274 {
275         struct acpi_table_int_src_ovr *p;
276
277         p = (struct acpi_table_int_src_ovr *) header;
278
279         if (BAD_MADT_ENTRY(p, end))
280                 return -EINVAL;
281
282         iosapic_override_isa_irq(p->bus_irq, p->global_irq,
283                                  (p->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
284                                  (p->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
285         return 0;
286 }
287
288
289 static int __init
290 acpi_parse_nmi_src (acpi_table_entry_header *header, const unsigned long end)
291 {
292         struct acpi_table_nmi_src *nmi_src;
293
294         nmi_src = (struct acpi_table_nmi_src*) header;
295
296         if (BAD_MADT_ENTRY(nmi_src, end))
297                 return -EINVAL;
298
299         /* TBD: Support nimsrc entries */
300         return 0;
301 }
302
303 static void __init
304 acpi_madt_oem_check (char *oem_id, char *oem_table_id)
305 {
306         if (!strncmp(oem_id, "IBM", 3) &&
307             (!strncmp(oem_table_id, "SERMOW", 6))) {
308
309                 /*
310                  * Unfortunately ITC_DRIFT is not yet part of the
311                  * official SAL spec, so the ITC_DRIFT bit is not
312                  * set by the BIOS on this hardware.
313                  */
314                 sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
315
316                 cyclone_setup();
317         }
318 }
319
320 static int __init
321 acpi_parse_madt (unsigned long phys_addr, unsigned long size)
322 {
323         if (!phys_addr || !size)
324                 return -EINVAL;
325
326         acpi_madt = (struct acpi_table_madt *) __va(phys_addr);
327
328         /* remember the value for reference after free_initmem() */
329 #ifdef CONFIG_ITANIUM
330         has_8259 = 1; /* Firmware on old Itanium systems is broken */
331 #else
332         has_8259 = acpi_madt->flags.pcat_compat;
333 #endif
334         iosapic_system_init(has_8259);
335
336         /* Get base address of IPI Message Block */
337
338         if (acpi_madt->lapic_address)
339                 ipi_base_addr = ioremap(acpi_madt->lapic_address, 0);
340
341         printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
342
343         acpi_madt_oem_check(acpi_madt->header.oem_id,
344                 acpi_madt->header.oem_table_id);
345
346         return 0;
347 }
348
349
350 #ifdef CONFIG_ACPI_NUMA
351
352 #undef SLIT_DEBUG
353
354 #define PXM_FLAG_LEN ((MAX_PXM_DOMAINS + 1)/32)
355
356 static int __initdata srat_num_cpus;                    /* number of cpus */
357 static u32 __initdata pxm_flag[PXM_FLAG_LEN];
358 #define pxm_bit_set(bit)        (set_bit(bit,(void *)pxm_flag))
359 #define pxm_bit_test(bit)       (test_bit(bit,(void *)pxm_flag))
360 /* maps to convert between proximity domain and logical node ID */
361 int __initdata pxm_to_nid_map[MAX_PXM_DOMAINS];
362 int __initdata nid_to_pxm_map[MAX_NUMNODES];
363 static struct acpi_table_slit __initdata *slit_table;
364
365 /*
366  * ACPI 2.0 SLIT (System Locality Information Table)
367  * http://devresource.hp.com/devresource/Docs/TechPapers/IA64/slit.pdf
368  */
369 void __init
370 acpi_numa_slit_init (struct acpi_table_slit *slit)
371 {
372         u32 len;
373
374         len = sizeof(struct acpi_table_header) + 8
375                 + slit->localities * slit->localities;
376         if (slit->header.length != len) {
377                 printk(KERN_ERR "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
378                        len, slit->header.length);
379                 memset(numa_slit, 10, sizeof(numa_slit));
380                 return;
381         }
382         slit_table = slit;
383 }
384
385 void __init
386 acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa)
387 {
388         /* record this node in proximity bitmap */
389         pxm_bit_set(pa->proximity_domain);
390
391         node_cpuid[srat_num_cpus].phys_id = (pa->apic_id << 8) | (pa->lsapic_eid);
392         /* nid should be overridden as logical node id later */
393         node_cpuid[srat_num_cpus].nid = pa->proximity_domain;
394         srat_num_cpus++;
395 }
396
397 void __init
398 acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma)
399 {
400         unsigned long paddr, size;
401         u8 pxm;
402         struct node_memblk_s *p, *q, *pend;
403
404         pxm = ma->proximity_domain;
405
406         /* fill node memory chunk structure */
407         paddr = ma->base_addr_hi;
408         paddr = (paddr << 32) | ma->base_addr_lo;
409         size = ma->length_hi;
410         size = (size << 32) | ma->length_lo;
411
412         /* Ignore disabled entries */
413         if (!ma->flags.enabled)
414                 return;
415
416         /* record this node in proximity bitmap */
417         pxm_bit_set(pxm);
418
419         /* Insertion sort based on base address */
420         pend = &node_memblk[num_node_memblks];
421         for (p = &node_memblk[0]; p < pend; p++) {
422                 if (paddr < p->start_paddr)
423                         break;
424         }
425         if (p < pend) {
426                 for (q = pend - 1; q >= p; q--)
427                         *(q + 1) = *q;
428         }
429         p->start_paddr = paddr;
430         p->size = size;
431         p->nid = pxm;
432         num_node_memblks++;
433 }
434
435 void __init
436 acpi_numa_arch_fixup (void)
437 {
438         int i, j, node_from, node_to;
439
440         /* If there's no SRAT, fix the phys_id and mark node 0 online */
441         if (srat_num_cpus == 0) {
442                 node_set_online(0);
443                 node_cpuid[0].phys_id = hard_smp_processor_id();
444                 return;
445         }
446
447         /* calculate total number of nodes in system from PXM bitmap */
448         numnodes = 0;           /* init total nodes in system */
449
450         memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map));
451         memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map));
452         for (i = 0; i < MAX_PXM_DOMAINS; i++) {
453                 if (pxm_bit_test(i)) {
454                         pxm_to_nid_map[i] = numnodes;
455                         node_set_online(numnodes);
456                         nid_to_pxm_map[numnodes++] = i;
457                 }
458         }
459
460         /* set logical node id in memory chunk structure */
461         for (i = 0; i < num_node_memblks; i++)
462                 node_memblk[i].nid = pxm_to_nid_map[node_memblk[i].nid];
463
464         /* assign memory bank numbers for each chunk on each node */
465         for (i = 0; i < numnodes; i++) {
466                 int bank;
467
468                 bank = 0;
469                 for (j = 0; j < num_node_memblks; j++)
470                         if (node_memblk[j].nid == i)
471                                 node_memblk[j].bank = bank++;
472         }
473
474         /* set logical node id in cpu structure */
475         for (i = 0; i < srat_num_cpus; i++)
476                 node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid];
477
478         printk(KERN_INFO "Number of logical nodes in system = %d\n", numnodes);
479         printk(KERN_INFO "Number of memory chunks in system = %d\n", num_node_memblks);
480
481         if (!slit_table) return;
482         memset(numa_slit, -1, sizeof(numa_slit));
483         for (i=0; i<slit_table->localities; i++) {
484                 if (!pxm_bit_test(i))
485                         continue;
486                 node_from = pxm_to_nid_map[i];
487                 for (j=0; j<slit_table->localities; j++) {
488                         if (!pxm_bit_test(j))
489                                 continue;
490                         node_to = pxm_to_nid_map[j];
491                         node_distance(node_from, node_to) =
492                                 slit_table->entry[i*slit_table->localities + j];
493                 }
494         }
495
496 #ifdef SLIT_DEBUG
497         printk("ACPI 2.0 SLIT locality table:\n");
498         for (i = 0; i < numnodes; i++) {
499                 for (j = 0; j < numnodes; j++)
500                         printk("%03d ", node_distance(i,j));
501                 printk("\n");
502         }
503 #endif
504 }
505 #endif /* CONFIG_ACPI_NUMA */
506
507 unsigned int
508 acpi_register_gsi (u32 gsi, int edge_level, int active_high_low)
509 {
510         if (has_8259 && gsi < 16)
511                 return isa_irq_to_vector(gsi);
512
513         return iosapic_register_intr(gsi,
514                         (active_high_low == ACPI_ACTIVE_HIGH) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
515                         (edge_level == ACPI_EDGE_SENSITIVE) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
516 }
517 EXPORT_SYMBOL(acpi_register_gsi);
518
519 static int __init
520 acpi_parse_fadt (unsigned long phys_addr, unsigned long size)
521 {
522         struct acpi_table_header *fadt_header;
523         struct fadt_descriptor_rev2 *fadt;
524
525         if (!phys_addr || !size)
526                 return -EINVAL;
527
528         fadt_header = (struct acpi_table_header *) __va(phys_addr);
529         if (fadt_header->revision != 3)
530                 return -ENODEV;         /* Only deal with ACPI 2.0 FADT */
531
532         fadt = (struct fadt_descriptor_rev2 *) fadt_header;
533
534         if (!(fadt->iapc_boot_arch & BAF_8042_KEYBOARD_CONTROLLER))
535                 acpi_kbd_controller_present = 0;
536
537         if (fadt->iapc_boot_arch & BAF_LEGACY_DEVICES)
538                 acpi_legacy_devices = 1;
539
540         acpi_register_gsi(fadt->sci_int, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
541         return 0;
542 }
543
544
545 unsigned long __init
546 acpi_find_rsdp (void)
547 {
548         unsigned long rsdp_phys = 0;
549
550         if (efi.acpi20)
551                 rsdp_phys = __pa(efi.acpi20);
552         else if (efi.acpi)
553                 printk(KERN_WARNING PREFIX "v1.0/r0.71 tables no longer supported\n");
554         return rsdp_phys;
555 }
556
557
558 int __init
559 acpi_boot_init (void)
560 {
561
562         /*
563          * MADT
564          * ----
565          * Parse the Multiple APIC Description Table (MADT), if exists.
566          * Note that this table provides platform SMP configuration
567          * information -- the successor to MPS tables.
568          */
569
570         if (acpi_table_parse(ACPI_APIC, acpi_parse_madt) < 1) {
571                 printk(KERN_ERR PREFIX "Can't find MADT\n");
572                 goto skip_madt;
573         }
574
575         /* Local APIC */
576
577         if (acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0) < 0)
578                 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
579
580         if (acpi_table_parse_madt(ACPI_MADT_LSAPIC, acpi_parse_lsapic, NR_CPUS) < 1)
581                 printk(KERN_ERR PREFIX "Error parsing MADT - no LAPIC entries\n");
582
583         if (acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0) < 0)
584                 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
585
586         /* I/O APIC */
587
588         if (acpi_table_parse_madt(ACPI_MADT_IOSAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1)
589                 printk(KERN_ERR PREFIX "Error parsing MADT - no IOSAPIC entries\n");
590
591         /* System-Level Interrupt Routing */
592
593         if (acpi_table_parse_madt(ACPI_MADT_PLAT_INT_SRC, acpi_parse_plat_int_src, ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
594                 printk(KERN_ERR PREFIX "Error parsing platform interrupt source entry\n");
595
596         if (acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, 0) < 0)
597                 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
598
599         if (acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, 0) < 0)
600                 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
601   skip_madt:
602
603         /*
604          * FADT says whether a legacy keyboard controller is present.
605          * The FADT also contains an SCI_INT line, by which the system
606          * gets interrupts such as power and sleep buttons.  If it's not
607          * on a Legacy interrupt, it needs to be setup.
608          */
609         if (acpi_table_parse(ACPI_FADT, acpi_parse_fadt) < 1)
610                 printk(KERN_ERR PREFIX "Can't find FADT\n");
611
612 #ifdef CONFIG_SMP
613         if (available_cpus == 0) {
614                 printk(KERN_INFO "ACPI: Found 0 CPUS; assuming 1\n");
615                 printk(KERN_INFO "CPU 0 (0x%04x)", hard_smp_processor_id());
616                 smp_boot_data.cpu_phys_id[available_cpus] = hard_smp_processor_id();
617                 available_cpus = 1; /* We've got at least one of these, no? */
618         }
619         smp_boot_data.cpu_count = available_cpus;
620
621         smp_build_cpu_map();
622 # ifdef CONFIG_ACPI_NUMA
623         if (srat_num_cpus == 0) {
624                 int cpu, i = 1;
625                 for (cpu = 0; cpu < smp_boot_data.cpu_count; cpu++)
626                         if (smp_boot_data.cpu_phys_id[cpu] != hard_smp_processor_id())
627                                 node_cpuid[i++].phys_id = smp_boot_data.cpu_phys_id[cpu];
628         }
629         build_cpu_to_node_map();
630 # endif
631 #endif
632         /* Make boot-up look pretty */
633         printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus, total_cpus);
634         return 0;
635 }
636
637 int
638 acpi_gsi_to_irq (u32 gsi, unsigned int *irq)
639 {
640         int vector;
641
642         if (has_8259 && gsi < 16)
643                 *irq = isa_irq_to_vector(gsi);
644         else {
645                 vector = gsi_to_vector(gsi);
646                 if (vector == -1)
647                         return -1;
648
649                 *irq = vector;
650         }
651         return 0;
652 }
653
654 #ifdef CONFIG_NUMA
655 acpi_status __init
656 acpi_map_iosapic (acpi_handle handle, u32 depth, void *context, void **ret)
657 {
658         struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
659         union acpi_object *obj;
660         struct acpi_table_iosapic *iosapic;
661         unsigned int gsi_base;
662         int node;
663
664         /* Only care about objects w/ a method that returns the MADT */
665         if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
666                 return AE_OK;
667
668         if (!buffer.length || !buffer.pointer)
669                 return AE_OK;
670
671         obj = buffer.pointer;
672         if (obj->type != ACPI_TYPE_BUFFER ||
673             obj->buffer.length < sizeof(*iosapic)) {
674                 acpi_os_free(buffer.pointer);
675                 return AE_OK;
676         }
677
678         iosapic = (struct acpi_table_iosapic *)obj->buffer.pointer;
679
680         if (iosapic->header.type != ACPI_MADT_IOSAPIC) {
681                 acpi_os_free(buffer.pointer);
682                 return AE_OK;
683         }
684
685         gsi_base = iosapic->global_irq_base;
686
687         acpi_os_free(buffer.pointer);
688         buffer.length = ACPI_ALLOCATE_BUFFER;
689         buffer.pointer = NULL;
690
691         /*
692          * OK, it's an IOSAPIC MADT entry, look for a _PXM method to tell
693          * us which node to associate this with.
694          */
695         if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PXM", NULL, &buffer)))
696                 return AE_OK;
697
698         if (!buffer.length || !buffer.pointer)
699                 return AE_OK;
700
701         obj = buffer.pointer;
702
703         if (obj->type != ACPI_TYPE_INTEGER ||
704             obj->integer.value >= MAX_PXM_DOMAINS) {
705                 acpi_os_free(buffer.pointer);
706                 return AE_OK;
707         }
708
709         node = pxm_to_nid_map[obj->integer.value];
710         acpi_os_free(buffer.pointer);
711
712         if (node >= MAX_NUMNODES || !node_online(node) ||
713             cpus_empty(node_to_cpumask(node)))
714                 return AE_OK;
715
716         /* We know a gsi to node mapping! */
717         map_iosapic_to_node(gsi_base, node);
718         return AE_OK;
719 }
720 #endif /* CONFIG_NUMA */
721 #endif /* CONFIG_ACPI_BOOT */