[IA64] fix generic/up builds
[sfrench/cifs-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 <linux/nodemask.h>
47 #include <asm/io.h>
48 #include <asm/iosapic.h>
49 #include <asm/machvec.h>
50 #include <asm/page.h>
51 #include <asm/system.h>
52 #include <asm/numa.h>
53 #include <asm/sal.h>
54 #include <asm/cyclone.h>
55
56 #define BAD_MADT_ENTRY(entry, end) (                                        \
57                 (!entry) || (unsigned long)entry + sizeof(*entry) > end ||  \
58                 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
59
60 #define PREFIX                  "ACPI: "
61
62 void (*pm_idle) (void);
63 EXPORT_SYMBOL(pm_idle);
64 void (*pm_power_off) (void);
65 EXPORT_SYMBOL(pm_power_off);
66
67 unsigned char acpi_kbd_controller_present = 1;
68 unsigned char acpi_legacy_devices;
69
70 #define MAX_SAPICS 256
71 u16 ia64_acpiid_to_sapicid[MAX_SAPICS] =
72         { [0 ... MAX_SAPICS - 1] = -1 };
73 EXPORT_SYMBOL(ia64_acpiid_to_sapicid);
74
75 const char *
76 acpi_get_sysname (void)
77 {
78 #ifdef CONFIG_IA64_GENERIC
79         unsigned long rsdp_phys;
80         struct acpi20_table_rsdp *rsdp;
81         struct acpi_table_xsdt *xsdt;
82         struct acpi_table_header *hdr;
83
84         rsdp_phys = acpi_find_rsdp();
85         if (!rsdp_phys) {
86                 printk(KERN_ERR "ACPI 2.0 RSDP not found, default to \"dig\"\n");
87                 return "dig";
88         }
89
90         rsdp = (struct acpi20_table_rsdp *) __va(rsdp_phys);
91         if (strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1)) {
92                 printk(KERN_ERR "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
93                 return "dig";
94         }
95
96         xsdt = (struct acpi_table_xsdt *) __va(rsdp->xsdt_address);
97         hdr = &xsdt->header;
98         if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1)) {
99                 printk(KERN_ERR "ACPI 2.0 XSDT signature incorrect, default to \"dig\"\n");
100                 return "dig";
101         }
102
103         if (!strcmp(hdr->oem_id, "HP")) {
104                 return "hpzx1";
105         }
106         else if (!strcmp(hdr->oem_id, "SGI")) {
107                 return "sn2";
108         }
109
110         return "dig";
111 #else
112 # if defined (CONFIG_IA64_HP_SIM)
113         return "hpsim";
114 # elif defined (CONFIG_IA64_HP_ZX1)
115         return "hpzx1";
116 # elif defined (CONFIG_IA64_HP_ZX1_SWIOTLB)
117         return "hpzx1_swiotlb";
118 # elif defined (CONFIG_IA64_SGI_SN2)
119         return "sn2";
120 # elif defined (CONFIG_IA64_DIG)
121         return "dig";
122 # else
123 #       error Unknown platform.  Fix acpi.c.
124 # endif
125 #endif
126 }
127
128 #ifdef CONFIG_ACPI_BOOT
129
130 #define ACPI_MAX_PLATFORM_INTERRUPTS    256
131
132 /* Array to record platform interrupt vectors for generic interrupt routing. */
133 int platform_intr_list[ACPI_MAX_PLATFORM_INTERRUPTS] = {
134         [0 ... ACPI_MAX_PLATFORM_INTERRUPTS - 1] = -1
135 };
136
137 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_IOSAPIC;
138
139 /*
140  * Interrupt routing API for device drivers.  Provides interrupt vector for
141  * a generic platform event.  Currently only CPEI is implemented.
142  */
143 int
144 acpi_request_vector (u32 int_type)
145 {
146         int vector = -1;
147
148         if (int_type < ACPI_MAX_PLATFORM_INTERRUPTS) {
149                 /* corrected platform error interrupt */
150                 vector = platform_intr_list[int_type];
151         } else
152                 printk(KERN_ERR "acpi_request_vector(): invalid interrupt type\n");
153         return vector;
154 }
155
156 char *
157 __acpi_map_table (unsigned long phys_addr, unsigned long size)
158 {
159         return __va(phys_addr);
160 }
161
162 /* --------------------------------------------------------------------------
163                             Boot-time Table Parsing
164    -------------------------------------------------------------------------- */
165
166 static int                      total_cpus __initdata;
167 static int                      available_cpus __initdata;
168 struct acpi_table_madt *        acpi_madt __initdata;
169 static u8                       has_8259;
170
171
172 static int __init
173 acpi_parse_lapic_addr_ovr (
174         acpi_table_entry_header *header, const unsigned long end)
175 {
176         struct acpi_table_lapic_addr_ovr *lapic;
177
178         lapic = (struct acpi_table_lapic_addr_ovr *) header;
179
180         if (BAD_MADT_ENTRY(lapic, end))
181                 return -EINVAL;
182
183         if (lapic->address) {
184                 iounmap(ipi_base_addr);
185                 ipi_base_addr = ioremap(lapic->address, 0);
186         }
187         return 0;
188 }
189
190
191 static int __init
192 acpi_parse_lsapic (acpi_table_entry_header *header, const unsigned long end)
193 {
194         struct acpi_table_lsapic *lsapic;
195
196         lsapic = (struct acpi_table_lsapic *) header;
197
198         if (BAD_MADT_ENTRY(lsapic, end))
199                 return -EINVAL;
200
201         if (lsapic->flags.enabled) {
202 #ifdef CONFIG_SMP
203                 smp_boot_data.cpu_phys_id[available_cpus] = (lsapic->id << 8) | lsapic->eid;
204 #endif
205                 ia64_acpiid_to_sapicid[lsapic->acpi_id] = (lsapic->id << 8) | lsapic->eid;
206                 ++available_cpus;
207         }
208
209         total_cpus++;
210         return 0;
211 }
212
213
214 static int __init
215 acpi_parse_lapic_nmi (acpi_table_entry_header *header, const unsigned long end)
216 {
217         struct acpi_table_lapic_nmi *lacpi_nmi;
218
219         lacpi_nmi = (struct acpi_table_lapic_nmi*) header;
220
221         if (BAD_MADT_ENTRY(lacpi_nmi, end))
222                 return -EINVAL;
223
224         /* TBD: Support lapic_nmi entries */
225         return 0;
226 }
227
228
229 static int __init
230 acpi_parse_iosapic (acpi_table_entry_header *header, const unsigned long end)
231 {
232         struct acpi_table_iosapic *iosapic;
233
234         iosapic = (struct acpi_table_iosapic *) header;
235
236         if (BAD_MADT_ENTRY(iosapic, end))
237                 return -EINVAL;
238
239         return iosapic_init(iosapic->address, iosapic->global_irq_base);
240 }
241
242
243 static int __init
244 acpi_parse_plat_int_src (
245         acpi_table_entry_header *header, const unsigned long end)
246 {
247         struct acpi_table_plat_int_src *plintsrc;
248         int vector;
249
250         plintsrc = (struct acpi_table_plat_int_src *) header;
251
252         if (BAD_MADT_ENTRY(plintsrc, end))
253                 return -EINVAL;
254
255         /*
256          * Get vector assignment for this interrupt, set attributes,
257          * and program the IOSAPIC routing table.
258          */
259         vector = iosapic_register_platform_intr(plintsrc->type,
260                                                 plintsrc->global_irq,
261                                                 plintsrc->iosapic_vector,
262                                                 plintsrc->eid,
263                                                 plintsrc->id,
264                                                 (plintsrc->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
265                                                 (plintsrc->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
266
267         platform_intr_list[plintsrc->type] = vector;
268         return 0;
269 }
270
271
272 static int __init
273 acpi_parse_int_src_ovr (
274         acpi_table_entry_header *header, const unsigned long end)
275 {
276         struct acpi_table_int_src_ovr *p;
277
278         p = (struct acpi_table_int_src_ovr *) header;
279
280         if (BAD_MADT_ENTRY(p, end))
281                 return -EINVAL;
282
283         iosapic_override_isa_irq(p->bus_irq, p->global_irq,
284                                  (p->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
285                                  (p->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
286         return 0;
287 }
288
289
290 static int __init
291 acpi_parse_nmi_src (acpi_table_entry_header *header, const unsigned long end)
292 {
293         struct acpi_table_nmi_src *nmi_src;
294
295         nmi_src = (struct acpi_table_nmi_src*) header;
296
297         if (BAD_MADT_ENTRY(nmi_src, end))
298                 return -EINVAL;
299
300         /* TBD: Support nimsrc entries */
301         return 0;
302 }
303
304 static void __init
305 acpi_madt_oem_check (char *oem_id, char *oem_table_id)
306 {
307         if (!strncmp(oem_id, "IBM", 3) &&
308             (!strncmp(oem_table_id, "SERMOW", 6))) {
309
310                 /*
311                  * Unfortunately ITC_DRIFT is not yet part of the
312                  * official SAL spec, so the ITC_DRIFT bit is not
313                  * set by the BIOS on this hardware.
314                  */
315                 sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
316
317                 cyclone_setup();
318         }
319 }
320
321 static int __init
322 acpi_parse_madt (unsigned long phys_addr, unsigned long size)
323 {
324         if (!phys_addr || !size)
325                 return -EINVAL;
326
327         acpi_madt = (struct acpi_table_madt *) __va(phys_addr);
328
329         /* remember the value for reference after free_initmem() */
330 #ifdef CONFIG_ITANIUM
331         has_8259 = 1; /* Firmware on old Itanium systems is broken */
332 #else
333         has_8259 = acpi_madt->flags.pcat_compat;
334 #endif
335         iosapic_system_init(has_8259);
336
337         /* Get base address of IPI Message Block */
338
339         if (acpi_madt->lapic_address)
340                 ipi_base_addr = ioremap(acpi_madt->lapic_address, 0);
341
342         printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
343
344         acpi_madt_oem_check(acpi_madt->header.oem_id,
345                 acpi_madt->header.oem_table_id);
346
347         return 0;
348 }
349
350
351 #ifdef CONFIG_ACPI_NUMA
352
353 #undef SLIT_DEBUG
354
355 #define PXM_FLAG_LEN ((MAX_PXM_DOMAINS + 1)/32)
356
357 static int __initdata srat_num_cpus;                    /* number of cpus */
358 static u32 __devinitdata pxm_flag[PXM_FLAG_LEN];
359 #define pxm_bit_set(bit)        (set_bit(bit,(void *)pxm_flag))
360 #define pxm_bit_test(bit)       (test_bit(bit,(void *)pxm_flag))
361 /* maps to convert between proximity domain and logical node ID */
362 int __devinitdata pxm_to_nid_map[MAX_PXM_DOMAINS];
363 int __initdata nid_to_pxm_map[MAX_NUMNODES];
364 static struct acpi_table_slit __initdata *slit_table;
365
366 /*
367  * ACPI 2.0 SLIT (System Locality Information Table)
368  * http://devresource.hp.com/devresource/Docs/TechPapers/IA64/slit.pdf
369  */
370 void __init
371 acpi_numa_slit_init (struct acpi_table_slit *slit)
372 {
373         u32 len;
374
375         len = sizeof(struct acpi_table_header) + 8
376                 + slit->localities * slit->localities;
377         if (slit->header.length != len) {
378                 printk(KERN_ERR "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
379                        len, slit->header.length);
380                 memset(numa_slit, 10, sizeof(numa_slit));
381                 return;
382         }
383         slit_table = slit;
384 }
385
386 void __init
387 acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa)
388 {
389         /* record this node in proximity bitmap */
390         pxm_bit_set(pa->proximity_domain);
391
392         node_cpuid[srat_num_cpus].phys_id = (pa->apic_id << 8) | (pa->lsapic_eid);
393         /* nid should be overridden as logical node id later */
394         node_cpuid[srat_num_cpus].nid = pa->proximity_domain;
395         srat_num_cpus++;
396 }
397
398 void __init
399 acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma)
400 {
401         unsigned long paddr, size;
402         u8 pxm;
403         struct node_memblk_s *p, *q, *pend;
404
405         pxm = ma->proximity_domain;
406
407         /* fill node memory chunk structure */
408         paddr = ma->base_addr_hi;
409         paddr = (paddr << 32) | ma->base_addr_lo;
410         size = ma->length_hi;
411         size = (size << 32) | ma->length_lo;
412
413         /* Ignore disabled entries */
414         if (!ma->flags.enabled)
415                 return;
416
417         /* record this node in proximity bitmap */
418         pxm_bit_set(pxm);
419
420         /* Insertion sort based on base address */
421         pend = &node_memblk[num_node_memblks];
422         for (p = &node_memblk[0]; p < pend; p++) {
423                 if (paddr < p->start_paddr)
424                         break;
425         }
426         if (p < pend) {
427                 for (q = pend - 1; q >= p; q--)
428                         *(q + 1) = *q;
429         }
430         p->start_paddr = paddr;
431         p->size = size;
432         p->nid = pxm;
433         num_node_memblks++;
434 }
435
436 void __init
437 acpi_numa_arch_fixup (void)
438 {
439         int i, j, node_from, node_to;
440
441         /* If there's no SRAT, fix the phys_id and mark node 0 online */
442         if (srat_num_cpus == 0) {
443                 node_set_online(0);
444                 node_cpuid[0].phys_id = hard_smp_processor_id();
445                 return;
446         }
447
448         /*
449          * MCD - This can probably be dropped now.  No need for pxm ID to node ID
450          * mapping with sparse node numbering iff MAX_PXM_DOMAINS <= MAX_NUMNODES.
451          */
452         /* calculate total number of nodes in system from PXM bitmap */
453         memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map));
454         memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map));
455         nodes_clear(node_online_map);
456         for (i = 0; i < MAX_PXM_DOMAINS; i++) {
457                 if (pxm_bit_test(i)) {
458                         int nid = num_online_nodes();
459                         pxm_to_nid_map[i] = nid;
460                         nid_to_pxm_map[nid] = i;
461                         node_set_online(nid);
462                 }
463         }
464
465         /* set logical node id in memory chunk structure */
466         for (i = 0; i < num_node_memblks; i++)
467                 node_memblk[i].nid = pxm_to_nid_map[node_memblk[i].nid];
468
469         /* assign memory bank numbers for each chunk on each node */
470         for_each_online_node(i) {
471                 int bank;
472
473                 bank = 0;
474                 for (j = 0; j < num_node_memblks; j++)
475                         if (node_memblk[j].nid == i)
476                                 node_memblk[j].bank = bank++;
477         }
478
479         /* set logical node id in cpu structure */
480         for (i = 0; i < srat_num_cpus; i++)
481                 node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid];
482
483         printk(KERN_INFO "Number of logical nodes in system = %d\n", num_online_nodes());
484         printk(KERN_INFO "Number of memory chunks in system = %d\n", num_node_memblks);
485
486         if (!slit_table) return;
487         memset(numa_slit, -1, sizeof(numa_slit));
488         for (i=0; i<slit_table->localities; i++) {
489                 if (!pxm_bit_test(i))
490                         continue;
491                 node_from = pxm_to_nid_map[i];
492                 for (j=0; j<slit_table->localities; j++) {
493                         if (!pxm_bit_test(j))
494                                 continue;
495                         node_to = pxm_to_nid_map[j];
496                         node_distance(node_from, node_to) =
497                                 slit_table->entry[i*slit_table->localities + j];
498                 }
499         }
500
501 #ifdef SLIT_DEBUG
502         printk("ACPI 2.0 SLIT locality table:\n");
503         for_each_online_node(i) {
504                 for_each_online_node(j)
505                         printk("%03d ", node_distance(i,j));
506                 printk("\n");
507         }
508 #endif
509 }
510 #endif /* CONFIG_ACPI_NUMA */
511
512 unsigned int
513 acpi_register_gsi (u32 gsi, int edge_level, int active_high_low)
514 {
515         if (has_8259 && gsi < 16)
516                 return isa_irq_to_vector(gsi);
517
518         return iosapic_register_intr(gsi,
519                         (active_high_low == ACPI_ACTIVE_HIGH) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
520                         (edge_level == ACPI_EDGE_SENSITIVE) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
521 }
522 EXPORT_SYMBOL(acpi_register_gsi);
523
524 #ifdef CONFIG_ACPI_DEALLOCATE_IRQ
525 void
526 acpi_unregister_gsi (u32 gsi)
527 {
528         iosapic_unregister_intr(gsi);
529 }
530 EXPORT_SYMBOL(acpi_unregister_gsi);
531 #endif /* CONFIG_ACPI_DEALLOCATE_IRQ */
532
533 static int __init
534 acpi_parse_fadt (unsigned long phys_addr, unsigned long size)
535 {
536         struct acpi_table_header *fadt_header;
537         struct fadt_descriptor_rev2 *fadt;
538
539         if (!phys_addr || !size)
540                 return -EINVAL;
541
542         fadt_header = (struct acpi_table_header *) __va(phys_addr);
543         if (fadt_header->revision != 3)
544                 return -ENODEV;         /* Only deal with ACPI 2.0 FADT */
545
546         fadt = (struct fadt_descriptor_rev2 *) fadt_header;
547
548         if (!(fadt->iapc_boot_arch & BAF_8042_KEYBOARD_CONTROLLER))
549                 acpi_kbd_controller_present = 0;
550
551         if (fadt->iapc_boot_arch & BAF_LEGACY_DEVICES)
552                 acpi_legacy_devices = 1;
553
554         acpi_register_gsi(fadt->sci_int, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
555         return 0;
556 }
557
558
559 unsigned long __init
560 acpi_find_rsdp (void)
561 {
562         unsigned long rsdp_phys = 0;
563
564         if (efi.acpi20)
565                 rsdp_phys = __pa(efi.acpi20);
566         else if (efi.acpi)
567                 printk(KERN_WARNING PREFIX "v1.0/r0.71 tables no longer supported\n");
568         return rsdp_phys;
569 }
570
571
572 int __init
573 acpi_boot_init (void)
574 {
575
576         /*
577          * MADT
578          * ----
579          * Parse the Multiple APIC Description Table (MADT), if exists.
580          * Note that this table provides platform SMP configuration
581          * information -- the successor to MPS tables.
582          */
583
584         if (acpi_table_parse(ACPI_APIC, acpi_parse_madt) < 1) {
585                 printk(KERN_ERR PREFIX "Can't find MADT\n");
586                 goto skip_madt;
587         }
588
589         /* Local APIC */
590
591         if (acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0) < 0)
592                 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
593
594         if (acpi_table_parse_madt(ACPI_MADT_LSAPIC, acpi_parse_lsapic, NR_CPUS) < 1)
595                 printk(KERN_ERR PREFIX "Error parsing MADT - no LAPIC entries\n");
596
597         if (acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0) < 0)
598                 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
599
600         /* I/O APIC */
601
602         if (acpi_table_parse_madt(ACPI_MADT_IOSAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1)
603                 printk(KERN_ERR PREFIX "Error parsing MADT - no IOSAPIC entries\n");
604
605         /* System-Level Interrupt Routing */
606
607         if (acpi_table_parse_madt(ACPI_MADT_PLAT_INT_SRC, acpi_parse_plat_int_src, ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
608                 printk(KERN_ERR PREFIX "Error parsing platform interrupt source entry\n");
609
610         if (acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, 0) < 0)
611                 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
612
613         if (acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, 0) < 0)
614                 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
615   skip_madt:
616
617         /*
618          * FADT says whether a legacy keyboard controller is present.
619          * The FADT also contains an SCI_INT line, by which the system
620          * gets interrupts such as power and sleep buttons.  If it's not
621          * on a Legacy interrupt, it needs to be setup.
622          */
623         if (acpi_table_parse(ACPI_FADT, acpi_parse_fadt) < 1)
624                 printk(KERN_ERR PREFIX "Can't find FADT\n");
625
626 #ifdef CONFIG_SMP
627         if (available_cpus == 0) {
628                 printk(KERN_INFO "ACPI: Found 0 CPUS; assuming 1\n");
629                 printk(KERN_INFO "CPU 0 (0x%04x)", hard_smp_processor_id());
630                 smp_boot_data.cpu_phys_id[available_cpus] = hard_smp_processor_id();
631                 available_cpus = 1; /* We've got at least one of these, no? */
632         }
633         smp_boot_data.cpu_count = available_cpus;
634
635         smp_build_cpu_map();
636 # ifdef CONFIG_ACPI_NUMA
637         if (srat_num_cpus == 0) {
638                 int cpu, i = 1;
639                 for (cpu = 0; cpu < smp_boot_data.cpu_count; cpu++)
640                         if (smp_boot_data.cpu_phys_id[cpu] != hard_smp_processor_id())
641                                 node_cpuid[i++].phys_id = smp_boot_data.cpu_phys_id[cpu];
642         }
643 # endif
644 #endif
645 #ifdef CONFIG_ACPI_NUMA
646         build_cpu_to_node_map();
647 #endif
648         /* Make boot-up look pretty */
649         printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus, total_cpus);
650         return 0;
651 }
652
653 int
654 acpi_gsi_to_irq (u32 gsi, unsigned int *irq)
655 {
656         int vector;
657
658         if (has_8259 && gsi < 16)
659                 *irq = isa_irq_to_vector(gsi);
660         else {
661                 vector = gsi_to_vector(gsi);
662                 if (vector == -1)
663                         return -1;
664
665                 *irq = vector;
666         }
667         return 0;
668 }
669
670 /*
671  *  ACPI based hotplug CPU support
672  */
673 #ifdef CONFIG_ACPI_HOTPLUG_CPU
674 static
675 int
676 acpi_map_cpu2node(acpi_handle handle, int cpu, long physid)
677 {
678 #ifdef CONFIG_ACPI_NUMA
679         int                     pxm_id;
680
681         pxm_id = acpi_get_pxm(handle);
682
683         /*
684          * Assuming that the container driver would have set the proximity
685          * domain and would have initialized pxm_to_nid_map[pxm_id] && pxm_flag
686          */
687         node_cpuid[cpu].nid = (pxm_id < 0) ? 0:
688                         pxm_to_nid_map[pxm_id];
689
690         node_cpuid[cpu].phys_id =  physid;
691 #endif
692         return(0);
693 }
694
695
696 int
697 acpi_map_lsapic(acpi_handle handle, int *pcpu)
698 {
699         struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
700         union acpi_object *obj;
701         struct acpi_table_lsapic *lsapic;
702         cpumask_t tmp_map;
703         long physid;
704         int cpu;
705  
706         if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
707                 return -EINVAL;
708
709         if (!buffer.length ||  !buffer.pointer)
710                 return -EINVAL;
711  
712         obj = buffer.pointer;
713         if (obj->type != ACPI_TYPE_BUFFER ||
714             obj->buffer.length < sizeof(*lsapic)) {
715                 acpi_os_free(buffer.pointer);
716                 return -EINVAL;
717         }
718
719         lsapic = (struct acpi_table_lsapic *)obj->buffer.pointer;
720
721         if ((lsapic->header.type != ACPI_MADT_LSAPIC) ||
722             (!lsapic->flags.enabled)) {
723                 acpi_os_free(buffer.pointer);
724                 return -EINVAL;
725         }
726
727         physid = ((lsapic->id <<8) | (lsapic->eid));
728
729         acpi_os_free(buffer.pointer);
730         buffer.length = ACPI_ALLOCATE_BUFFER;
731         buffer.pointer = NULL;
732
733         cpus_complement(tmp_map, cpu_present_map);
734         cpu = first_cpu(tmp_map);
735         if(cpu >= NR_CPUS)
736                 return -EINVAL;
737
738         acpi_map_cpu2node(handle, cpu, physid);
739
740         cpu_set(cpu, cpu_present_map);
741         ia64_cpu_to_sapicid[cpu] = physid;
742         ia64_acpiid_to_sapicid[lsapic->acpi_id] = ia64_cpu_to_sapicid[cpu];
743
744         *pcpu = cpu;
745         return(0);
746 }
747 EXPORT_SYMBOL(acpi_map_lsapic);
748
749
750 int
751 acpi_unmap_lsapic(int cpu)
752 {
753         int i;
754
755         for (i=0; i<MAX_SAPICS; i++) {
756                 if (ia64_acpiid_to_sapicid[i] == ia64_cpu_to_sapicid[cpu]) {
757                         ia64_acpiid_to_sapicid[i] = -1;
758                         break;
759                 }
760         }
761         ia64_cpu_to_sapicid[cpu] = -1;
762         cpu_clear(cpu,cpu_present_map);
763
764 #ifdef CONFIG_ACPI_NUMA
765         /* NUMA specific cleanup's */
766 #endif
767
768         return(0);
769 }
770 EXPORT_SYMBOL(acpi_unmap_lsapic);
771 #endif /* CONFIG_ACPI_HOTPLUG_CPU */
772  
773
774 #ifdef CONFIG_ACPI_NUMA
775 acpi_status __devinit
776 acpi_map_iosapic (acpi_handle handle, u32 depth, void *context, void **ret)
777 {
778         struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
779         union acpi_object *obj;
780         struct acpi_table_iosapic *iosapic;
781         unsigned int gsi_base;
782         int pxm, node;
783
784         /* Only care about objects w/ a method that returns the MADT */
785         if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
786                 return AE_OK;
787
788         if (!buffer.length || !buffer.pointer)
789                 return AE_OK;
790
791         obj = buffer.pointer;
792         if (obj->type != ACPI_TYPE_BUFFER ||
793             obj->buffer.length < sizeof(*iosapic)) {
794                 acpi_os_free(buffer.pointer);
795                 return AE_OK;
796         }
797
798         iosapic = (struct acpi_table_iosapic *)obj->buffer.pointer;
799
800         if (iosapic->header.type != ACPI_MADT_IOSAPIC) {
801                 acpi_os_free(buffer.pointer);
802                 return AE_OK;
803         }
804
805         gsi_base = iosapic->global_irq_base;
806
807         acpi_os_free(buffer.pointer);
808
809         /*
810          * OK, it's an IOSAPIC MADT entry, look for a _PXM value to tell
811          * us which node to associate this with.
812          */
813         pxm = acpi_get_pxm(handle);
814         if (pxm < 0)
815                 return AE_OK;
816
817         node = pxm_to_nid_map[pxm];
818
819         if (node >= MAX_NUMNODES || !node_online(node) ||
820             cpus_empty(node_to_cpumask(node)))
821                 return AE_OK;
822
823         /* We know a gsi to node mapping! */
824         map_iosapic_to_node(gsi_base, node);
825         return AE_OK;
826 }
827 #endif /* CONFIG_NUMA */
828
829 int
830 acpi_register_ioapic (acpi_handle handle, u64 phys_addr, u32 gsi_base)
831 {
832         int err;
833
834         if ((err = iosapic_init(phys_addr, gsi_base)))
835                 return err;
836
837 #if CONFIG_ACPI_NUMA
838         acpi_map_iosapic(handle, 0, NULL, NULL);
839 #endif /* CONFIG_ACPI_NUMA */
840
841         return 0;
842 }
843 EXPORT_SYMBOL(acpi_register_ioapic);
844
845 int
846 acpi_unregister_ioapic (acpi_handle handle, u32 gsi_base)
847 {
848         return iosapic_remove(gsi_base);
849 }
850 EXPORT_SYMBOL(acpi_unregister_ioapic);
851
852 #endif /* CONFIG_ACPI_BOOT */