boot.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. /*
  2. * boot.c - Architecture-Specific Low-Level ACPI Boot Support
  3. *
  4. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  5. * Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. #include <linux/init.h>
  26. #include <linux/config.h>
  27. #include <linux/acpi.h>
  28. #include <linux/efi.h>
  29. #include <linux/module.h>
  30. #include <linux/dmi.h>
  31. #include <linux/irq.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/io_apic.h>
  34. #include <asm/apic.h>
  35. #include <asm/io.h>
  36. #include <asm/mpspec.h>
  37. #ifdef CONFIG_X86_64
  38. extern void __init clustered_apic_check(void);
  39. extern int gsi_irq_sharing(int gsi);
  40. #include <asm/proto.h>
  41. #else /* X86 */
  42. #ifdef CONFIG_X86_LOCAL_APIC
  43. #include <mach_apic.h>
  44. #include <mach_mpparse.h>
  45. #endif /* CONFIG_X86_LOCAL_APIC */
  46. static inline int gsi_irq_sharing(int gsi) { return gsi; }
  47. #endif /* X86 */
  48. #define BAD_MADT_ENTRY(entry, end) ( \
  49. (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
  50. ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
  51. #define PREFIX "ACPI: "
  52. int acpi_noirq __initdata; /* skip ACPI IRQ initialization */
  53. int acpi_pci_disabled __initdata; /* skip ACPI PCI scan and IRQ initialization */
  54. int acpi_ht __initdata = 1; /* enable HT */
  55. int acpi_lapic;
  56. int acpi_ioapic;
  57. int acpi_strict;
  58. EXPORT_SYMBOL(acpi_strict);
  59. acpi_interrupt_flags acpi_sci_flags __initdata;
  60. int acpi_sci_override_gsi __initdata;
  61. int acpi_skip_timer_override __initdata;
  62. #ifdef CONFIG_X86_LOCAL_APIC
  63. static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
  64. #endif
  65. #ifndef __HAVE_ARCH_CMPXCHG
  66. #warning ACPI uses CMPXCHG, i486 and later hardware
  67. #endif
  68. #define MAX_MADT_ENTRIES 256
  69. u8 x86_acpiid_to_apicid[MAX_MADT_ENTRIES] =
  70. {[0 ... MAX_MADT_ENTRIES - 1] = 0xff };
  71. EXPORT_SYMBOL(x86_acpiid_to_apicid);
  72. /* --------------------------------------------------------------------------
  73. Boot-time Configuration
  74. -------------------------------------------------------------------------- */
  75. /*
  76. * The default interrupt routing model is PIC (8259). This gets
  77. * overriden if IOAPICs are enumerated (below).
  78. */
  79. enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
  80. #ifdef CONFIG_X86_64
  81. /* rely on all ACPI tables being in the direct mapping */
  82. char *__acpi_map_table(unsigned long phys_addr, unsigned long size)
  83. {
  84. if (!phys_addr || !size)
  85. return NULL;
  86. if (phys_addr+size <= (end_pfn_map << PAGE_SHIFT) + PAGE_SIZE)
  87. return __va(phys_addr);
  88. return NULL;
  89. }
  90. #else
  91. /*
  92. * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
  93. * to map the target physical address. The problem is that set_fixmap()
  94. * provides a single page, and it is possible that the page is not
  95. * sufficient.
  96. * By using this area, we can map up to MAX_IO_APICS pages temporarily,
  97. * i.e. until the next __va_range() call.
  98. *
  99. * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
  100. * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
  101. * count idx down while incrementing the phys address.
  102. */
  103. char *__acpi_map_table(unsigned long phys, unsigned long size)
  104. {
  105. unsigned long base, offset, mapped_size;
  106. int idx;
  107. if (phys + size < 8 * 1024 * 1024)
  108. return __va(phys);
  109. offset = phys & (PAGE_SIZE - 1);
  110. mapped_size = PAGE_SIZE - offset;
  111. set_fixmap(FIX_ACPI_END, phys);
  112. base = fix_to_virt(FIX_ACPI_END);
  113. /*
  114. * Most cases can be covered by the below.
  115. */
  116. idx = FIX_ACPI_END;
  117. while (mapped_size < size) {
  118. if (--idx < FIX_ACPI_BEGIN)
  119. return NULL; /* cannot handle this */
  120. phys += PAGE_SIZE;
  121. set_fixmap(idx, phys);
  122. mapped_size += PAGE_SIZE;
  123. }
  124. return ((unsigned char *)base + offset);
  125. }
  126. #endif
  127. #ifdef CONFIG_PCI_MMCONFIG
  128. /* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
  129. struct acpi_table_mcfg_config *pci_mmcfg_config;
  130. int pci_mmcfg_config_num;
  131. int __init acpi_parse_mcfg(unsigned long phys_addr, unsigned long size)
  132. {
  133. struct acpi_table_mcfg *mcfg;
  134. unsigned long i;
  135. int config_size;
  136. if (!phys_addr || !size)
  137. return -EINVAL;
  138. mcfg = (struct acpi_table_mcfg *)__acpi_map_table(phys_addr, size);
  139. if (!mcfg) {
  140. printk(KERN_WARNING PREFIX "Unable to map MCFG\n");
  141. return -ENODEV;
  142. }
  143. /* how many config structures do we have */
  144. pci_mmcfg_config_num = 0;
  145. i = size - sizeof(struct acpi_table_mcfg);
  146. while (i >= sizeof(struct acpi_table_mcfg_config)) {
  147. ++pci_mmcfg_config_num;
  148. i -= sizeof(struct acpi_table_mcfg_config);
  149. };
  150. if (pci_mmcfg_config_num == 0) {
  151. printk(KERN_ERR PREFIX "MMCONFIG has no entries\n");
  152. return -ENODEV;
  153. }
  154. config_size = pci_mmcfg_config_num * sizeof(*pci_mmcfg_config);
  155. pci_mmcfg_config = kmalloc(config_size, GFP_KERNEL);
  156. if (!pci_mmcfg_config) {
  157. printk(KERN_WARNING PREFIX
  158. "No memory for MCFG config tables\n");
  159. return -ENOMEM;
  160. }
  161. memcpy(pci_mmcfg_config, &mcfg->config, config_size);
  162. for (i = 0; i < pci_mmcfg_config_num; ++i) {
  163. if (mcfg->config[i].base_reserved) {
  164. printk(KERN_ERR PREFIX
  165. "MMCONFIG not in low 4GB of memory\n");
  166. return -ENODEV;
  167. }
  168. }
  169. return 0;
  170. }
  171. #endif /* CONFIG_PCI_MMCONFIG */
  172. #ifdef CONFIG_X86_LOCAL_APIC
  173. static int __init acpi_parse_madt(unsigned long phys_addr, unsigned long size)
  174. {
  175. struct acpi_table_madt *madt = NULL;
  176. if (!phys_addr || !size)
  177. return -EINVAL;
  178. madt = (struct acpi_table_madt *)__acpi_map_table(phys_addr, size);
  179. if (!madt) {
  180. printk(KERN_WARNING PREFIX "Unable to map MADT\n");
  181. return -ENODEV;
  182. }
  183. if (madt->lapic_address) {
  184. acpi_lapic_addr = (u64) madt->lapic_address;
  185. printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
  186. madt->lapic_address);
  187. }
  188. acpi_madt_oem_check(madt->header.oem_id, madt->header.oem_table_id);
  189. return 0;
  190. }
  191. static int __init
  192. acpi_parse_lapic(acpi_table_entry_header * header, const unsigned long end)
  193. {
  194. struct acpi_table_lapic *processor = NULL;
  195. processor = (struct acpi_table_lapic *)header;
  196. if (BAD_MADT_ENTRY(processor, end))
  197. return -EINVAL;
  198. acpi_table_print_madt_entry(header);
  199. /* Record local apic id only when enabled */
  200. if (processor->flags.enabled)
  201. x86_acpiid_to_apicid[processor->acpi_id] = processor->id;
  202. /*
  203. * We need to register disabled CPU as well to permit
  204. * counting disabled CPUs. This allows us to size
  205. * cpus_possible_map more accurately, to permit
  206. * to not preallocating memory for all NR_CPUS
  207. * when we use CPU hotplug.
  208. */
  209. mp_register_lapic(processor->id, /* APIC ID */
  210. processor->flags.enabled); /* Enabled? */
  211. return 0;
  212. }
  213. static int __init
  214. acpi_parse_lapic_addr_ovr(acpi_table_entry_header * header,
  215. const unsigned long end)
  216. {
  217. struct acpi_table_lapic_addr_ovr *lapic_addr_ovr = NULL;
  218. lapic_addr_ovr = (struct acpi_table_lapic_addr_ovr *)header;
  219. if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
  220. return -EINVAL;
  221. acpi_lapic_addr = lapic_addr_ovr->address;
  222. return 0;
  223. }
  224. static int __init
  225. acpi_parse_lapic_nmi(acpi_table_entry_header * header, const unsigned long end)
  226. {
  227. struct acpi_table_lapic_nmi *lapic_nmi = NULL;
  228. lapic_nmi = (struct acpi_table_lapic_nmi *)header;
  229. if (BAD_MADT_ENTRY(lapic_nmi, end))
  230. return -EINVAL;
  231. acpi_table_print_madt_entry(header);
  232. if (lapic_nmi->lint != 1)
  233. printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
  234. return 0;
  235. }
  236. #endif /*CONFIG_X86_LOCAL_APIC */
  237. #ifdef CONFIG_X86_IO_APIC
  238. static int __init
  239. acpi_parse_ioapic(acpi_table_entry_header * header, const unsigned long end)
  240. {
  241. struct acpi_table_ioapic *ioapic = NULL;
  242. ioapic = (struct acpi_table_ioapic *)header;
  243. if (BAD_MADT_ENTRY(ioapic, end))
  244. return -EINVAL;
  245. acpi_table_print_madt_entry(header);
  246. mp_register_ioapic(ioapic->id,
  247. ioapic->address, ioapic->global_irq_base);
  248. return 0;
  249. }
  250. /*
  251. * Parse Interrupt Source Override for the ACPI SCI
  252. */
  253. static void acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
  254. {
  255. if (trigger == 0) /* compatible SCI trigger is level */
  256. trigger = 3;
  257. if (polarity == 0) /* compatible SCI polarity is low */
  258. polarity = 3;
  259. /* Command-line over-ride via acpi_sci= */
  260. if (acpi_sci_flags.trigger)
  261. trigger = acpi_sci_flags.trigger;
  262. if (acpi_sci_flags.polarity)
  263. polarity = acpi_sci_flags.polarity;
  264. /*
  265. * mp_config_acpi_legacy_irqs() already setup IRQs < 16
  266. * If GSI is < 16, this will update its flags,
  267. * else it will create a new mp_irqs[] entry.
  268. */
  269. mp_override_legacy_irq(gsi, polarity, trigger, gsi);
  270. /*
  271. * stash over-ride to indicate we've been here
  272. * and for later update of acpi_fadt
  273. */
  274. acpi_sci_override_gsi = gsi;
  275. return;
  276. }
  277. static int __init
  278. acpi_parse_int_src_ovr(acpi_table_entry_header * header,
  279. const unsigned long end)
  280. {
  281. struct acpi_table_int_src_ovr *intsrc = NULL;
  282. intsrc = (struct acpi_table_int_src_ovr *)header;
  283. if (BAD_MADT_ENTRY(intsrc, end))
  284. return -EINVAL;
  285. acpi_table_print_madt_entry(header);
  286. if (intsrc->bus_irq == acpi_fadt.sci_int) {
  287. acpi_sci_ioapic_setup(intsrc->global_irq,
  288. intsrc->flags.polarity,
  289. intsrc->flags.trigger);
  290. return 0;
  291. }
  292. if (acpi_skip_timer_override &&
  293. intsrc->bus_irq == 0 && intsrc->global_irq == 2) {
  294. printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
  295. return 0;
  296. }
  297. mp_override_legacy_irq(intsrc->bus_irq,
  298. intsrc->flags.polarity,
  299. intsrc->flags.trigger, intsrc->global_irq);
  300. return 0;
  301. }
  302. static int __init
  303. acpi_parse_nmi_src(acpi_table_entry_header * header, const unsigned long end)
  304. {
  305. struct acpi_table_nmi_src *nmi_src = NULL;
  306. nmi_src = (struct acpi_table_nmi_src *)header;
  307. if (BAD_MADT_ENTRY(nmi_src, end))
  308. return -EINVAL;
  309. acpi_table_print_madt_entry(header);
  310. /* TBD: Support nimsrc entries? */
  311. return 0;
  312. }
  313. #endif /* CONFIG_X86_IO_APIC */
  314. /*
  315. * acpi_pic_sci_set_trigger()
  316. *
  317. * use ELCR to set PIC-mode trigger type for SCI
  318. *
  319. * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
  320. * it may require Edge Trigger -- use "acpi_sci=edge"
  321. *
  322. * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
  323. * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
  324. * ECLR1 is IRQ's 0-7 (IRQ 0, 1, 2 must be 0)
  325. * ECLR2 is IRQ's 8-15 (IRQ 8, 13 must be 0)
  326. */
  327. void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
  328. {
  329. unsigned int mask = 1 << irq;
  330. unsigned int old, new;
  331. /* Real old ELCR mask */
  332. old = inb(0x4d0) | (inb(0x4d1) << 8);
  333. /*
  334. * If we use ACPI to set PCI irq's, then we should clear ELCR
  335. * since we will set it correctly as we enable the PCI irq
  336. * routing.
  337. */
  338. new = acpi_noirq ? old : 0;
  339. /*
  340. * Update SCI information in the ELCR, it isn't in the PCI
  341. * routing tables..
  342. */
  343. switch (trigger) {
  344. case 1: /* Edge - clear */
  345. new &= ~mask;
  346. break;
  347. case 3: /* Level - set */
  348. new |= mask;
  349. break;
  350. }
  351. if (old == new)
  352. return;
  353. printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
  354. outb(new, 0x4d0);
  355. outb(new >> 8, 0x4d1);
  356. }
  357. int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
  358. {
  359. #ifdef CONFIG_X86_IO_APIC
  360. if (use_pci_vector() && !platform_legacy_irq(gsi))
  361. *irq = IO_APIC_VECTOR(gsi);
  362. else
  363. #endif
  364. *irq = gsi_irq_sharing(gsi);
  365. return 0;
  366. }
  367. /*
  368. * success: return IRQ number (>=0)
  369. * failure: return < 0
  370. */
  371. int acpi_register_gsi(u32 gsi, int triggering, int polarity)
  372. {
  373. unsigned int irq;
  374. unsigned int plat_gsi = gsi;
  375. #ifdef CONFIG_PCI
  376. /*
  377. * Make sure all (legacy) PCI IRQs are set as level-triggered.
  378. */
  379. if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
  380. extern void eisa_set_level_irq(unsigned int irq);
  381. if (triggering == ACPI_LEVEL_SENSITIVE)
  382. eisa_set_level_irq(gsi);
  383. }
  384. #endif
  385. #ifdef CONFIG_X86_IO_APIC
  386. if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
  387. plat_gsi = mp_register_gsi(gsi, triggering, polarity);
  388. }
  389. #endif
  390. acpi_gsi_to_irq(plat_gsi, &irq);
  391. return irq;
  392. }
  393. EXPORT_SYMBOL(acpi_register_gsi);
  394. /*
  395. * ACPI based hotplug support for CPU
  396. */
  397. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  398. int acpi_map_lsapic(acpi_handle handle, int *pcpu)
  399. {
  400. /* TBD */
  401. return -EINVAL;
  402. }
  403. EXPORT_SYMBOL(acpi_map_lsapic);
  404. int acpi_unmap_lsapic(int cpu)
  405. {
  406. /* TBD */
  407. return -EINVAL;
  408. }
  409. EXPORT_SYMBOL(acpi_unmap_lsapic);
  410. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  411. int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
  412. {
  413. /* TBD */
  414. return -EINVAL;
  415. }
  416. EXPORT_SYMBOL(acpi_register_ioapic);
  417. int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
  418. {
  419. /* TBD */
  420. return -EINVAL;
  421. }
  422. EXPORT_SYMBOL(acpi_unregister_ioapic);
  423. static unsigned long __init
  424. acpi_scan_rsdp(unsigned long start, unsigned long length)
  425. {
  426. unsigned long offset = 0;
  427. unsigned long sig_len = sizeof("RSD PTR ") - 1;
  428. /*
  429. * Scan all 16-byte boundaries of the physical memory region for the
  430. * RSDP signature.
  431. */
  432. for (offset = 0; offset < length; offset += 16) {
  433. if (strncmp((char *)(phys_to_virt(start) + offset), "RSD PTR ", sig_len))
  434. continue;
  435. return (start + offset);
  436. }
  437. return 0;
  438. }
  439. static int __init acpi_parse_sbf(unsigned long phys_addr, unsigned long size)
  440. {
  441. struct acpi_table_sbf *sb;
  442. if (!phys_addr || !size)
  443. return -EINVAL;
  444. sb = (struct acpi_table_sbf *)__acpi_map_table(phys_addr, size);
  445. if (!sb) {
  446. printk(KERN_WARNING PREFIX "Unable to map SBF\n");
  447. return -ENODEV;
  448. }
  449. sbf_port = sb->sbf_cmos; /* Save CMOS port */
  450. return 0;
  451. }
  452. #ifdef CONFIG_HPET_TIMER
  453. static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
  454. {
  455. struct acpi_table_hpet *hpet_tbl;
  456. if (!phys || !size)
  457. return -EINVAL;
  458. hpet_tbl = (struct acpi_table_hpet *)__acpi_map_table(phys, size);
  459. if (!hpet_tbl) {
  460. printk(KERN_WARNING PREFIX "Unable to map HPET\n");
  461. return -ENODEV;
  462. }
  463. if (hpet_tbl->addr.space_id != ACPI_SPACE_MEM) {
  464. printk(KERN_WARNING PREFIX "HPET timers must be located in "
  465. "memory.\n");
  466. return -1;
  467. }
  468. #ifdef CONFIG_X86_64
  469. vxtime.hpet_address = hpet_tbl->addr.addrl |
  470. ((long)hpet_tbl->addr.addrh << 32);
  471. printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
  472. hpet_tbl->id, vxtime.hpet_address);
  473. #else /* X86 */
  474. {
  475. extern unsigned long hpet_address;
  476. hpet_address = hpet_tbl->addr.addrl;
  477. printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
  478. hpet_tbl->id, hpet_address);
  479. }
  480. #endif /* X86 */
  481. return 0;
  482. }
  483. #else
  484. #define acpi_parse_hpet NULL
  485. #endif
  486. #ifdef CONFIG_X86_PM_TIMER
  487. extern u32 pmtmr_ioport;
  488. #endif
  489. static int __init acpi_parse_fadt(unsigned long phys, unsigned long size)
  490. {
  491. struct fadt_descriptor_rev2 *fadt = NULL;
  492. fadt = (struct fadt_descriptor_rev2 *)__acpi_map_table(phys, size);
  493. if (!fadt) {
  494. printk(KERN_WARNING PREFIX "Unable to map FADT\n");
  495. return 0;
  496. }
  497. /* initialize sci_int early for INT_SRC_OVR MADT parsing */
  498. acpi_fadt.sci_int = fadt->sci_int;
  499. /* initialize rev and apic_phys_dest_mode for x86_64 genapic */
  500. acpi_fadt.revision = fadt->revision;
  501. acpi_fadt.force_apic_physical_destination_mode =
  502. fadt->force_apic_physical_destination_mode;
  503. #ifdef CONFIG_X86_PM_TIMER
  504. /* detect the location of the ACPI PM Timer */
  505. if (fadt->revision >= FADT2_REVISION_ID) {
  506. /* FADT rev. 2 */
  507. if (fadt->xpm_tmr_blk.address_space_id !=
  508. ACPI_ADR_SPACE_SYSTEM_IO)
  509. return 0;
  510. pmtmr_ioport = fadt->xpm_tmr_blk.address;
  511. /*
  512. * "X" fields are optional extensions to the original V1.0
  513. * fields, so we must selectively expand V1.0 fields if the
  514. * corresponding X field is zero.
  515. */
  516. if (!pmtmr_ioport)
  517. pmtmr_ioport = fadt->V1_pm_tmr_blk;
  518. } else {
  519. /* FADT rev. 1 */
  520. pmtmr_ioport = fadt->V1_pm_tmr_blk;
  521. }
  522. if (pmtmr_ioport)
  523. printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
  524. pmtmr_ioport);
  525. #endif
  526. return 0;
  527. }
  528. unsigned long __init acpi_find_rsdp(void)
  529. {
  530. unsigned long rsdp_phys = 0;
  531. if (efi_enabled) {
  532. if (efi.acpi20)
  533. return __pa(efi.acpi20);
  534. else if (efi.acpi)
  535. return __pa(efi.acpi);
  536. }
  537. /*
  538. * Scan memory looking for the RSDP signature. First search EBDA (low
  539. * memory) paragraphs and then search upper memory (E0000-FFFFF).
  540. */
  541. rsdp_phys = acpi_scan_rsdp(0, 0x400);
  542. if (!rsdp_phys)
  543. rsdp_phys = acpi_scan_rsdp(0xE0000, 0x20000);
  544. return rsdp_phys;
  545. }
  546. #ifdef CONFIG_X86_LOCAL_APIC
  547. /*
  548. * Parse LAPIC entries in MADT
  549. * returns 0 on success, < 0 on error
  550. */
  551. static int __init acpi_parse_madt_lapic_entries(void)
  552. {
  553. int count;
  554. /*
  555. * Note that the LAPIC address is obtained from the MADT (32-bit value)
  556. * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
  557. */
  558. count =
  559. acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR,
  560. acpi_parse_lapic_addr_ovr, 0);
  561. if (count < 0) {
  562. printk(KERN_ERR PREFIX
  563. "Error parsing LAPIC address override entry\n");
  564. return count;
  565. }
  566. mp_register_lapic_address(acpi_lapic_addr);
  567. count = acpi_table_parse_madt(ACPI_MADT_LAPIC, acpi_parse_lapic,
  568. MAX_APICS);
  569. if (!count) {
  570. printk(KERN_ERR PREFIX "No LAPIC entries present\n");
  571. /* TBD: Cleanup to allow fallback to MPS */
  572. return -ENODEV;
  573. } else if (count < 0) {
  574. printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
  575. /* TBD: Cleanup to allow fallback to MPS */
  576. return count;
  577. }
  578. count =
  579. acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0);
  580. if (count < 0) {
  581. printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
  582. /* TBD: Cleanup to allow fallback to MPS */
  583. return count;
  584. }
  585. return 0;
  586. }
  587. #endif /* CONFIG_X86_LOCAL_APIC */
  588. #ifdef CONFIG_X86_IO_APIC
  589. /*
  590. * Parse IOAPIC related entries in MADT
  591. * returns 0 on success, < 0 on error
  592. */
  593. static int __init acpi_parse_madt_ioapic_entries(void)
  594. {
  595. int count;
  596. /*
  597. * ACPI interpreter is required to complete interrupt setup,
  598. * so if it is off, don't enumerate the io-apics with ACPI.
  599. * If MPS is present, it will handle them,
  600. * otherwise the system will stay in PIC mode
  601. */
  602. if (acpi_disabled || acpi_noirq) {
  603. return -ENODEV;
  604. }
  605. /*
  606. * if "noapic" boot option, don't look for IO-APICs
  607. */
  608. if (skip_ioapic_setup) {
  609. printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
  610. "due to 'noapic' option.\n");
  611. return -ENODEV;
  612. }
  613. count =
  614. acpi_table_parse_madt(ACPI_MADT_IOAPIC, acpi_parse_ioapic,
  615. MAX_IO_APICS);
  616. if (!count) {
  617. printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
  618. return -ENODEV;
  619. } else if (count < 0) {
  620. printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
  621. return count;
  622. }
  623. count =
  624. acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr,
  625. NR_IRQ_VECTORS);
  626. if (count < 0) {
  627. printk(KERN_ERR PREFIX
  628. "Error parsing interrupt source overrides entry\n");
  629. /* TBD: Cleanup to allow fallback to MPS */
  630. return count;
  631. }
  632. /*
  633. * If BIOS did not supply an INT_SRC_OVR for the SCI
  634. * pretend we got one so we can set the SCI flags.
  635. */
  636. if (!acpi_sci_override_gsi)
  637. acpi_sci_ioapic_setup(acpi_fadt.sci_int, 0, 0);
  638. /* Fill in identity legacy mapings where no override */
  639. mp_config_acpi_legacy_irqs();
  640. count =
  641. acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src,
  642. NR_IRQ_VECTORS);
  643. if (count < 0) {
  644. printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
  645. /* TBD: Cleanup to allow fallback to MPS */
  646. return count;
  647. }
  648. return 0;
  649. }
  650. #else
  651. static inline int acpi_parse_madt_ioapic_entries(void)
  652. {
  653. return -1;
  654. }
  655. #endif /* !CONFIG_X86_IO_APIC */
  656. static void __init acpi_process_madt(void)
  657. {
  658. #ifdef CONFIG_X86_LOCAL_APIC
  659. int count, error;
  660. count = acpi_table_parse(ACPI_APIC, acpi_parse_madt);
  661. if (count >= 1) {
  662. /*
  663. * Parse MADT LAPIC entries
  664. */
  665. error = acpi_parse_madt_lapic_entries();
  666. if (!error) {
  667. acpi_lapic = 1;
  668. #ifdef CONFIG_X86_GENERICARCH
  669. generic_bigsmp_probe();
  670. #endif
  671. /*
  672. * Parse MADT IO-APIC entries
  673. */
  674. error = acpi_parse_madt_ioapic_entries();
  675. if (!error) {
  676. acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
  677. acpi_irq_balance_set(NULL);
  678. acpi_ioapic = 1;
  679. smp_found_config = 1;
  680. clustered_apic_check();
  681. }
  682. }
  683. if (error == -EINVAL) {
  684. /*
  685. * Dell Precision Workstation 410, 610 come here.
  686. */
  687. printk(KERN_ERR PREFIX
  688. "Invalid BIOS MADT, disabling ACPI\n");
  689. disable_acpi();
  690. }
  691. }
  692. #endif
  693. return;
  694. }
  695. extern int acpi_force;
  696. #ifdef __i386__
  697. static int __init disable_acpi_irq(struct dmi_system_id *d)
  698. {
  699. if (!acpi_force) {
  700. printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
  701. d->ident);
  702. acpi_noirq_set();
  703. }
  704. return 0;
  705. }
  706. static int __init disable_acpi_pci(struct dmi_system_id *d)
  707. {
  708. if (!acpi_force) {
  709. printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
  710. d->ident);
  711. acpi_disable_pci();
  712. }
  713. return 0;
  714. }
  715. static int __init dmi_disable_acpi(struct dmi_system_id *d)
  716. {
  717. if (!acpi_force) {
  718. printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
  719. disable_acpi();
  720. } else {
  721. printk(KERN_NOTICE
  722. "Warning: DMI blacklist says broken, but acpi forced\n");
  723. }
  724. return 0;
  725. }
  726. /*
  727. * Limit ACPI to CPU enumeration for HT
  728. */
  729. static int __init force_acpi_ht(struct dmi_system_id *d)
  730. {
  731. if (!acpi_force) {
  732. printk(KERN_NOTICE "%s detected: force use of acpi=ht\n",
  733. d->ident);
  734. disable_acpi();
  735. acpi_ht = 1;
  736. } else {
  737. printk(KERN_NOTICE
  738. "Warning: acpi=force overrules DMI blacklist: acpi=ht\n");
  739. }
  740. return 0;
  741. }
  742. /*
  743. * If your system is blacklisted here, but you find that acpi=force
  744. * works for you, please contact acpi-devel@sourceforge.net
  745. */
  746. static struct dmi_system_id __initdata acpi_dmi_table[] = {
  747. /*
  748. * Boxes that need ACPI disabled
  749. */
  750. {
  751. .callback = dmi_disable_acpi,
  752. .ident = "IBM Thinkpad",
  753. .matches = {
  754. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  755. DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
  756. },
  757. },
  758. /*
  759. * Boxes that need acpi=ht
  760. */
  761. {
  762. .callback = force_acpi_ht,
  763. .ident = "FSC Primergy T850",
  764. .matches = {
  765. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  766. DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"),
  767. },
  768. },
  769. {
  770. .callback = force_acpi_ht,
  771. .ident = "DELL GX240",
  772. .matches = {
  773. DMI_MATCH(DMI_BOARD_VENDOR, "Dell Computer Corporation"),
  774. DMI_MATCH(DMI_BOARD_NAME, "OptiPlex GX240"),
  775. },
  776. },
  777. {
  778. .callback = force_acpi_ht,
  779. .ident = "HP VISUALIZE NT Workstation",
  780. .matches = {
  781. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  782. DMI_MATCH(DMI_PRODUCT_NAME, "HP VISUALIZE NT Workstation"),
  783. },
  784. },
  785. {
  786. .callback = force_acpi_ht,
  787. .ident = "Compaq Workstation W8000",
  788. .matches = {
  789. DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
  790. DMI_MATCH(DMI_PRODUCT_NAME, "Workstation W8000"),
  791. },
  792. },
  793. {
  794. .callback = force_acpi_ht,
  795. .ident = "ASUS P4B266",
  796. .matches = {
  797. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  798. DMI_MATCH(DMI_BOARD_NAME, "P4B266"),
  799. },
  800. },
  801. {
  802. .callback = force_acpi_ht,
  803. .ident = "ASUS P2B-DS",
  804. .matches = {
  805. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  806. DMI_MATCH(DMI_BOARD_NAME, "P2B-DS"),
  807. },
  808. },
  809. {
  810. .callback = force_acpi_ht,
  811. .ident = "ASUS CUR-DLS",
  812. .matches = {
  813. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  814. DMI_MATCH(DMI_BOARD_NAME, "CUR-DLS"),
  815. },
  816. },
  817. {
  818. .callback = force_acpi_ht,
  819. .ident = "ABIT i440BX-W83977",
  820. .matches = {
  821. DMI_MATCH(DMI_BOARD_VENDOR, "ABIT <http://www.abit.com>"),
  822. DMI_MATCH(DMI_BOARD_NAME, "i440BX-W83977 (BP6)"),
  823. },
  824. },
  825. {
  826. .callback = force_acpi_ht,
  827. .ident = "IBM Bladecenter",
  828. .matches = {
  829. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  830. DMI_MATCH(DMI_BOARD_NAME, "IBM eServer BladeCenter HS20"),
  831. },
  832. },
  833. {
  834. .callback = force_acpi_ht,
  835. .ident = "IBM eServer xSeries 360",
  836. .matches = {
  837. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  838. DMI_MATCH(DMI_BOARD_NAME, "eServer xSeries 360"),
  839. },
  840. },
  841. {
  842. .callback = force_acpi_ht,
  843. .ident = "IBM eserver xSeries 330",
  844. .matches = {
  845. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  846. DMI_MATCH(DMI_BOARD_NAME, "eserver xSeries 330"),
  847. },
  848. },
  849. {
  850. .callback = force_acpi_ht,
  851. .ident = "IBM eserver xSeries 440",
  852. .matches = {
  853. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  854. DMI_MATCH(DMI_PRODUCT_NAME, "eserver xSeries 440"),
  855. },
  856. },
  857. /*
  858. * Boxes that need ACPI PCI IRQ routing disabled
  859. */
  860. {
  861. .callback = disable_acpi_irq,
  862. .ident = "ASUS A7V",
  863. .matches = {
  864. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
  865. DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
  866. /* newer BIOS, Revision 1011, does work */
  867. DMI_MATCH(DMI_BIOS_VERSION,
  868. "ASUS A7V ACPI BIOS Revision 1007"),
  869. },
  870. },
  871. /*
  872. * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
  873. */
  874. { /* _BBN 0 bug */
  875. .callback = disable_acpi_pci,
  876. .ident = "ASUS PR-DLS",
  877. .matches = {
  878. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  879. DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
  880. DMI_MATCH(DMI_BIOS_VERSION,
  881. "ASUS PR-DLS ACPI BIOS Revision 1010"),
  882. DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
  883. },
  884. },
  885. {
  886. .callback = disable_acpi_pci,
  887. .ident = "Acer TravelMate 36x Laptop",
  888. .matches = {
  889. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  890. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  891. },
  892. },
  893. {}
  894. };
  895. #endif /* __i386__ */
  896. /*
  897. * acpi_boot_table_init() and acpi_boot_init()
  898. * called from setup_arch(), always.
  899. * 1. checksums all tables
  900. * 2. enumerates lapics
  901. * 3. enumerates io-apics
  902. *
  903. * acpi_table_init() is separate to allow reading SRAT without
  904. * other side effects.
  905. *
  906. * side effects of acpi_boot_init:
  907. * acpi_lapic = 1 if LAPIC found
  908. * acpi_ioapic = 1 if IOAPIC found
  909. * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
  910. * if acpi_blacklisted() acpi_disabled = 1;
  911. * acpi_irq_model=...
  912. * ...
  913. *
  914. * return value: (currently ignored)
  915. * 0: success
  916. * !0: failure
  917. */
  918. int __init acpi_boot_table_init(void)
  919. {
  920. int error;
  921. #ifdef __i386__
  922. dmi_check_system(acpi_dmi_table);
  923. #endif
  924. /*
  925. * If acpi_disabled, bail out
  926. * One exception: acpi=ht continues far enough to enumerate LAPICs
  927. */
  928. if (acpi_disabled && !acpi_ht)
  929. return 1;
  930. /*
  931. * Initialize the ACPI boot-time table parser.
  932. */
  933. error = acpi_table_init();
  934. if (error) {
  935. disable_acpi();
  936. return error;
  937. }
  938. #ifdef __i386__
  939. check_acpi_pci();
  940. #endif
  941. acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
  942. /*
  943. * blacklist may disable ACPI entirely
  944. */
  945. error = acpi_blacklisted();
  946. if (error) {
  947. if (acpi_force) {
  948. printk(KERN_WARNING PREFIX "acpi=force override\n");
  949. } else {
  950. printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
  951. disable_acpi();
  952. return error;
  953. }
  954. }
  955. return 0;
  956. }
  957. int __init acpi_boot_init(void)
  958. {
  959. /*
  960. * If acpi_disabled, bail out
  961. * One exception: acpi=ht continues far enough to enumerate LAPICs
  962. */
  963. if (acpi_disabled && !acpi_ht)
  964. return 1;
  965. acpi_table_parse(ACPI_BOOT, acpi_parse_sbf);
  966. /*
  967. * set sci_int and PM timer address
  968. */
  969. acpi_table_parse(ACPI_FADT, acpi_parse_fadt);
  970. /*
  971. * Process the Multiple APIC Description Table (MADT), if present
  972. */
  973. acpi_process_madt();
  974. acpi_table_parse(ACPI_HPET, acpi_parse_hpet);
  975. return 0;
  976. }