acpi.c 24 KB

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