boot.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  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/acpi.h>
  27. #include <linux/acpi_pmtmr.h>
  28. #include <linux/efi.h>
  29. #include <linux/cpumask.h>
  30. #include <linux/module.h>
  31. #include <linux/dmi.h>
  32. #include <linux/irq.h>
  33. #include <linux/slab.h>
  34. #include <linux/bootmem.h>
  35. #include <linux/ioport.h>
  36. #include <linux/pci.h>
  37. #include <asm/pci_x86.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/io_apic.h>
  40. #include <asm/apic.h>
  41. #include <asm/io.h>
  42. #include <asm/mpspec.h>
  43. #include <asm/smp.h>
  44. static int __initdata acpi_force = 0;
  45. u32 acpi_rsdt_forced;
  46. int acpi_disabled;
  47. EXPORT_SYMBOL(acpi_disabled);
  48. #ifdef CONFIG_X86_64
  49. # include <asm/proto.h>
  50. # include <asm/numa_64.h>
  51. #endif /* X86 */
  52. #define BAD_MADT_ENTRY(entry, end) ( \
  53. (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
  54. ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
  55. #define PREFIX "ACPI: "
  56. int acpi_noirq; /* skip ACPI IRQ initialization */
  57. int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
  58. EXPORT_SYMBOL(acpi_pci_disabled);
  59. int acpi_ht __initdata = 1; /* enable HT */
  60. int acpi_lapic;
  61. int acpi_ioapic;
  62. int acpi_strict;
  63. u8 acpi_sci_flags __initdata;
  64. int acpi_sci_override_gsi __initdata;
  65. int acpi_skip_timer_override __initdata;
  66. int acpi_use_timer_override __initdata;
  67. #ifdef CONFIG_X86_LOCAL_APIC
  68. static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
  69. #endif
  70. #ifndef __HAVE_ARCH_CMPXCHG
  71. #warning ACPI uses CMPXCHG, i486 and later hardware
  72. #endif
  73. /* --------------------------------------------------------------------------
  74. Boot-time Configuration
  75. -------------------------------------------------------------------------- */
  76. /*
  77. * The default interrupt routing model is PIC (8259). This gets
  78. * overridden if IOAPICs are enumerated (below).
  79. */
  80. enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
  81. /*
  82. * ISA irqs by default are the first 16 gsis but can be
  83. * any gsi as specified by an interrupt source override.
  84. */
  85. static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
  86. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
  87. };
  88. static unsigned int gsi_to_irq(unsigned int gsi)
  89. {
  90. unsigned int irq = gsi + NR_IRQS_LEGACY;
  91. unsigned int i;
  92. for (i = 0; i < NR_IRQS_LEGACY; i++) {
  93. if (isa_irq_to_gsi[i] == gsi) {
  94. return i;
  95. }
  96. }
  97. /* Provide an identity mapping of gsi == irq
  98. * except on truly weird platforms that have
  99. * non isa irqs in the first 16 gsis.
  100. */
  101. if (gsi >= NR_IRQS_LEGACY)
  102. irq = gsi;
  103. else
  104. irq = gsi_end + 1 + gsi;
  105. return irq;
  106. }
  107. static u32 irq_to_gsi(int irq)
  108. {
  109. unsigned int gsi;
  110. if (irq < NR_IRQS_LEGACY)
  111. gsi = isa_irq_to_gsi[irq];
  112. else if (irq <= gsi_end)
  113. gsi = irq;
  114. else if (irq <= (gsi_end + NR_IRQS_LEGACY))
  115. gsi = irq - gsi_end;
  116. else
  117. gsi = 0xffffffff;
  118. return gsi;
  119. }
  120. /*
  121. * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
  122. * to map the target physical address. The problem is that set_fixmap()
  123. * provides a single page, and it is possible that the page is not
  124. * sufficient.
  125. * By using this area, we can map up to MAX_IO_APICS pages temporarily,
  126. * i.e. until the next __va_range() call.
  127. *
  128. * Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
  129. * from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
  130. * count idx down while incrementing the phys address.
  131. */
  132. char *__init __acpi_map_table(unsigned long phys, unsigned long size)
  133. {
  134. if (!phys || !size)
  135. return NULL;
  136. return early_ioremap(phys, size);
  137. }
  138. void __init __acpi_unmap_table(char *map, unsigned long size)
  139. {
  140. if (!map || !size)
  141. return;
  142. early_iounmap(map, size);
  143. }
  144. #ifdef CONFIG_X86_LOCAL_APIC
  145. static int __init acpi_parse_madt(struct acpi_table_header *table)
  146. {
  147. struct acpi_table_madt *madt = NULL;
  148. if (!cpu_has_apic)
  149. return -EINVAL;
  150. madt = (struct acpi_table_madt *)table;
  151. if (!madt) {
  152. printk(KERN_WARNING PREFIX "Unable to map MADT\n");
  153. return -ENODEV;
  154. }
  155. if (madt->address) {
  156. acpi_lapic_addr = (u64) madt->address;
  157. printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
  158. madt->address);
  159. }
  160. default_acpi_madt_oem_check(madt->header.oem_id,
  161. madt->header.oem_table_id);
  162. return 0;
  163. }
  164. static void __cpuinit acpi_register_lapic(int id, u8 enabled)
  165. {
  166. unsigned int ver = 0;
  167. if (!enabled) {
  168. ++disabled_cpus;
  169. return;
  170. }
  171. if (boot_cpu_physical_apicid != -1U)
  172. ver = apic_version[boot_cpu_physical_apicid];
  173. generic_processor_info(id, ver);
  174. }
  175. static int __init
  176. acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
  177. {
  178. struct acpi_madt_local_x2apic *processor = NULL;
  179. processor = (struct acpi_madt_local_x2apic *)header;
  180. if (BAD_MADT_ENTRY(processor, end))
  181. return -EINVAL;
  182. acpi_table_print_madt_entry(header);
  183. #ifdef CONFIG_X86_X2APIC
  184. /*
  185. * We need to register disabled CPU as well to permit
  186. * counting disabled CPUs. This allows us to size
  187. * cpus_possible_map more accurately, to permit
  188. * to not preallocating memory for all NR_CPUS
  189. * when we use CPU hotplug.
  190. */
  191. acpi_register_lapic(processor->local_apic_id, /* APIC ID */
  192. processor->lapic_flags & ACPI_MADT_ENABLED);
  193. #else
  194. printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
  195. #endif
  196. return 0;
  197. }
  198. static int __init
  199. acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
  200. {
  201. struct acpi_madt_local_apic *processor = NULL;
  202. processor = (struct acpi_madt_local_apic *)header;
  203. if (BAD_MADT_ENTRY(processor, end))
  204. return -EINVAL;
  205. acpi_table_print_madt_entry(header);
  206. /*
  207. * We need to register disabled CPU as well to permit
  208. * counting disabled CPUs. This allows us to size
  209. * cpus_possible_map more accurately, to permit
  210. * to not preallocating memory for all NR_CPUS
  211. * when we use CPU hotplug.
  212. */
  213. acpi_register_lapic(processor->id, /* APIC ID */
  214. processor->lapic_flags & ACPI_MADT_ENABLED);
  215. return 0;
  216. }
  217. static int __init
  218. acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
  219. {
  220. struct acpi_madt_local_sapic *processor = NULL;
  221. processor = (struct acpi_madt_local_sapic *)header;
  222. if (BAD_MADT_ENTRY(processor, end))
  223. return -EINVAL;
  224. acpi_table_print_madt_entry(header);
  225. acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
  226. processor->lapic_flags & ACPI_MADT_ENABLED);
  227. return 0;
  228. }
  229. static int __init
  230. acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
  231. const unsigned long end)
  232. {
  233. struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
  234. lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
  235. if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
  236. return -EINVAL;
  237. acpi_lapic_addr = lapic_addr_ovr->address;
  238. return 0;
  239. }
  240. static int __init
  241. acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
  242. const unsigned long end)
  243. {
  244. struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
  245. x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
  246. if (BAD_MADT_ENTRY(x2apic_nmi, end))
  247. return -EINVAL;
  248. acpi_table_print_madt_entry(header);
  249. if (x2apic_nmi->lint != 1)
  250. printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
  251. return 0;
  252. }
  253. static int __init
  254. acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
  255. {
  256. struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
  257. lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
  258. if (BAD_MADT_ENTRY(lapic_nmi, end))
  259. return -EINVAL;
  260. acpi_table_print_madt_entry(header);
  261. if (lapic_nmi->lint != 1)
  262. printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
  263. return 0;
  264. }
  265. #endif /*CONFIG_X86_LOCAL_APIC */
  266. #ifdef CONFIG_X86_IO_APIC
  267. static int __init
  268. acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
  269. {
  270. struct acpi_madt_io_apic *ioapic = NULL;
  271. ioapic = (struct acpi_madt_io_apic *)header;
  272. if (BAD_MADT_ENTRY(ioapic, end))
  273. return -EINVAL;
  274. acpi_table_print_madt_entry(header);
  275. mp_register_ioapic(ioapic->id,
  276. ioapic->address, ioapic->global_irq_base);
  277. return 0;
  278. }
  279. /*
  280. * Parse Interrupt Source Override for the ACPI SCI
  281. */
  282. static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
  283. {
  284. if (trigger == 0) /* compatible SCI trigger is level */
  285. trigger = 3;
  286. if (polarity == 0) /* compatible SCI polarity is low */
  287. polarity = 3;
  288. /* Command-line over-ride via acpi_sci= */
  289. if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
  290. trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
  291. if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
  292. polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
  293. /*
  294. * mp_config_acpi_legacy_irqs() already setup IRQs < 16
  295. * If GSI is < 16, this will update its flags,
  296. * else it will create a new mp_irqs[] entry.
  297. */
  298. mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
  299. /*
  300. * stash over-ride to indicate we've been here
  301. * and for later update of acpi_gbl_FADT
  302. */
  303. acpi_sci_override_gsi = gsi;
  304. return;
  305. }
  306. static int __init
  307. acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
  308. const unsigned long end)
  309. {
  310. struct acpi_madt_interrupt_override *intsrc = NULL;
  311. intsrc = (struct acpi_madt_interrupt_override *)header;
  312. if (BAD_MADT_ENTRY(intsrc, end))
  313. return -EINVAL;
  314. acpi_table_print_madt_entry(header);
  315. if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
  316. acpi_sci_ioapic_setup(intsrc->source_irq,
  317. intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
  318. (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
  319. intsrc->global_irq);
  320. return 0;
  321. }
  322. if (acpi_skip_timer_override &&
  323. intsrc->source_irq == 0 && intsrc->global_irq == 2) {
  324. printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
  325. return 0;
  326. }
  327. mp_override_legacy_irq(intsrc->source_irq,
  328. intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
  329. (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
  330. intsrc->global_irq);
  331. return 0;
  332. }
  333. static int __init
  334. acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
  335. {
  336. struct acpi_madt_nmi_source *nmi_src = NULL;
  337. nmi_src = (struct acpi_madt_nmi_source *)header;
  338. if (BAD_MADT_ENTRY(nmi_src, end))
  339. return -EINVAL;
  340. acpi_table_print_madt_entry(header);
  341. /* TBD: Support nimsrc entries? */
  342. return 0;
  343. }
  344. #endif /* CONFIG_X86_IO_APIC */
  345. /*
  346. * acpi_pic_sci_set_trigger()
  347. *
  348. * use ELCR to set PIC-mode trigger type for SCI
  349. *
  350. * If a PIC-mode SCI is not recognized or gives spurious IRQ7's
  351. * it may require Edge Trigger -- use "acpi_sci=edge"
  352. *
  353. * Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
  354. * for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
  355. * ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
  356. * ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
  357. */
  358. void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
  359. {
  360. unsigned int mask = 1 << irq;
  361. unsigned int old, new;
  362. /* Real old ELCR mask */
  363. old = inb(0x4d0) | (inb(0x4d1) << 8);
  364. /*
  365. * If we use ACPI to set PCI IRQs, then we should clear ELCR
  366. * since we will set it correctly as we enable the PCI irq
  367. * routing.
  368. */
  369. new = acpi_noirq ? old : 0;
  370. /*
  371. * Update SCI information in the ELCR, it isn't in the PCI
  372. * routing tables..
  373. */
  374. switch (trigger) {
  375. case 1: /* Edge - clear */
  376. new &= ~mask;
  377. break;
  378. case 3: /* Level - set */
  379. new |= mask;
  380. break;
  381. }
  382. if (old == new)
  383. return;
  384. printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
  385. outb(new, 0x4d0);
  386. outb(new >> 8, 0x4d1);
  387. }
  388. int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
  389. {
  390. *irq = gsi_to_irq(gsi);
  391. #ifdef CONFIG_X86_IO_APIC
  392. if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
  393. setup_IO_APIC_irq_extra(gsi);
  394. #endif
  395. return 0;
  396. }
  397. int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
  398. {
  399. if (isa_irq >= 16)
  400. return -1;
  401. *gsi = irq_to_gsi(isa_irq);
  402. return 0;
  403. }
  404. /*
  405. * success: return IRQ number (>=0)
  406. * failure: return < 0
  407. */
  408. int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
  409. {
  410. unsigned int irq;
  411. unsigned int plat_gsi = gsi;
  412. #ifdef CONFIG_PCI
  413. /*
  414. * Make sure all (legacy) PCI IRQs are set as level-triggered.
  415. */
  416. if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
  417. if (trigger == ACPI_LEVEL_SENSITIVE)
  418. eisa_set_level_irq(gsi);
  419. }
  420. #endif
  421. #ifdef CONFIG_X86_IO_APIC
  422. if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) {
  423. plat_gsi = mp_register_gsi(dev, gsi, trigger, polarity);
  424. }
  425. #endif
  426. irq = gsi_to_irq(plat_gsi);
  427. return irq;
  428. }
  429. /*
  430. * ACPI based hotplug support for CPU
  431. */
  432. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  433. #include <acpi/processor.h>
  434. static void acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
  435. {
  436. #ifdef CONFIG_ACPI_NUMA
  437. int nid;
  438. nid = acpi_get_node(handle);
  439. if (nid == -1 || !node_online(nid))
  440. return;
  441. #ifdef CONFIG_X86_64
  442. apicid_to_node[physid] = nid;
  443. numa_set_node(cpu, nid);
  444. #else /* CONFIG_X86_32 */
  445. apicid_2_node[physid] = nid;
  446. cpu_to_node_map[cpu] = nid;
  447. #endif
  448. #endif
  449. }
  450. static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
  451. {
  452. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  453. union acpi_object *obj;
  454. struct acpi_madt_local_apic *lapic;
  455. cpumask_var_t tmp_map, new_map;
  456. u8 physid;
  457. int cpu;
  458. int retval = -ENOMEM;
  459. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  460. return -EINVAL;
  461. if (!buffer.length || !buffer.pointer)
  462. return -EINVAL;
  463. obj = buffer.pointer;
  464. if (obj->type != ACPI_TYPE_BUFFER ||
  465. obj->buffer.length < sizeof(*lapic)) {
  466. kfree(buffer.pointer);
  467. return -EINVAL;
  468. }
  469. lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
  470. if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
  471. !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
  472. kfree(buffer.pointer);
  473. return -EINVAL;
  474. }
  475. physid = lapic->id;
  476. kfree(buffer.pointer);
  477. buffer.length = ACPI_ALLOCATE_BUFFER;
  478. buffer.pointer = NULL;
  479. if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
  480. goto out;
  481. if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
  482. goto free_tmp_map;
  483. cpumask_copy(tmp_map, cpu_present_mask);
  484. acpi_register_lapic(physid, lapic->lapic_flags & ACPI_MADT_ENABLED);
  485. /*
  486. * If mp_register_lapic successfully generates a new logical cpu
  487. * number, then the following will get us exactly what was mapped
  488. */
  489. cpumask_andnot(new_map, cpu_present_mask, tmp_map);
  490. if (cpumask_empty(new_map)) {
  491. printk ("Unable to map lapic to logical cpu number\n");
  492. retval = -EINVAL;
  493. goto free_new_map;
  494. }
  495. acpi_processor_set_pdc(handle);
  496. cpu = cpumask_first(new_map);
  497. acpi_map_cpu2node(handle, cpu, physid);
  498. *pcpu = cpu;
  499. retval = 0;
  500. free_new_map:
  501. free_cpumask_var(new_map);
  502. free_tmp_map:
  503. free_cpumask_var(tmp_map);
  504. out:
  505. return retval;
  506. }
  507. /* wrapper to silence section mismatch warning */
  508. int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
  509. {
  510. return _acpi_map_lsapic(handle, pcpu);
  511. }
  512. EXPORT_SYMBOL(acpi_map_lsapic);
  513. int acpi_unmap_lsapic(int cpu)
  514. {
  515. per_cpu(x86_cpu_to_apicid, cpu) = -1;
  516. set_cpu_present(cpu, false);
  517. num_processors--;
  518. return (0);
  519. }
  520. EXPORT_SYMBOL(acpi_unmap_lsapic);
  521. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  522. int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
  523. {
  524. /* TBD */
  525. return -EINVAL;
  526. }
  527. EXPORT_SYMBOL(acpi_register_ioapic);
  528. int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
  529. {
  530. /* TBD */
  531. return -EINVAL;
  532. }
  533. EXPORT_SYMBOL(acpi_unregister_ioapic);
  534. static int __init acpi_parse_sbf(struct acpi_table_header *table)
  535. {
  536. struct acpi_table_boot *sb;
  537. sb = (struct acpi_table_boot *)table;
  538. if (!sb) {
  539. printk(KERN_WARNING PREFIX "Unable to map SBF\n");
  540. return -ENODEV;
  541. }
  542. sbf_port = sb->cmos_index; /* Save CMOS port */
  543. return 0;
  544. }
  545. #ifdef CONFIG_HPET_TIMER
  546. #include <asm/hpet.h>
  547. static struct __initdata resource *hpet_res;
  548. static int __init acpi_parse_hpet(struct acpi_table_header *table)
  549. {
  550. struct acpi_table_hpet *hpet_tbl;
  551. hpet_tbl = (struct acpi_table_hpet *)table;
  552. if (!hpet_tbl) {
  553. printk(KERN_WARNING PREFIX "Unable to map HPET\n");
  554. return -ENODEV;
  555. }
  556. if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
  557. printk(KERN_WARNING PREFIX "HPET timers must be located in "
  558. "memory.\n");
  559. return -1;
  560. }
  561. hpet_address = hpet_tbl->address.address;
  562. hpet_blockid = hpet_tbl->sequence;
  563. /*
  564. * Some broken BIOSes advertise HPET at 0x0. We really do not
  565. * want to allocate a resource there.
  566. */
  567. if (!hpet_address) {
  568. printk(KERN_WARNING PREFIX
  569. "HPET id: %#x base: %#lx is invalid\n",
  570. hpet_tbl->id, hpet_address);
  571. return 0;
  572. }
  573. #ifdef CONFIG_X86_64
  574. /*
  575. * Some even more broken BIOSes advertise HPET at
  576. * 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
  577. * some noise:
  578. */
  579. if (hpet_address == 0xfed0000000000000UL) {
  580. if (!hpet_force_user) {
  581. printk(KERN_WARNING PREFIX "HPET id: %#x "
  582. "base: 0xfed0000000000000 is bogus\n "
  583. "try hpet=force on the kernel command line to "
  584. "fix it up to 0xfed00000.\n", hpet_tbl->id);
  585. hpet_address = 0;
  586. return 0;
  587. }
  588. printk(KERN_WARNING PREFIX
  589. "HPET id: %#x base: 0xfed0000000000000 fixed up "
  590. "to 0xfed00000.\n", hpet_tbl->id);
  591. hpet_address >>= 32;
  592. }
  593. #endif
  594. printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
  595. hpet_tbl->id, hpet_address);
  596. /*
  597. * Allocate and initialize the HPET firmware resource for adding into
  598. * the resource tree during the lateinit timeframe.
  599. */
  600. #define HPET_RESOURCE_NAME_SIZE 9
  601. hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
  602. hpet_res->name = (void *)&hpet_res[1];
  603. hpet_res->flags = IORESOURCE_MEM;
  604. snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
  605. hpet_tbl->sequence);
  606. hpet_res->start = hpet_address;
  607. hpet_res->end = hpet_address + (1 * 1024) - 1;
  608. return 0;
  609. }
  610. /*
  611. * hpet_insert_resource inserts the HPET resources used into the resource
  612. * tree.
  613. */
  614. static __init int hpet_insert_resource(void)
  615. {
  616. if (!hpet_res)
  617. return 1;
  618. return insert_resource(&iomem_resource, hpet_res);
  619. }
  620. late_initcall(hpet_insert_resource);
  621. #else
  622. #define acpi_parse_hpet NULL
  623. #endif
  624. static int __init acpi_parse_fadt(struct acpi_table_header *table)
  625. {
  626. #ifdef CONFIG_X86_PM_TIMER
  627. /* detect the location of the ACPI PM Timer */
  628. if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
  629. /* FADT rev. 2 */
  630. if (acpi_gbl_FADT.xpm_timer_block.space_id !=
  631. ACPI_ADR_SPACE_SYSTEM_IO)
  632. return 0;
  633. pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
  634. /*
  635. * "X" fields are optional extensions to the original V1.0
  636. * fields, so we must selectively expand V1.0 fields if the
  637. * corresponding X field is zero.
  638. */
  639. if (!pmtmr_ioport)
  640. pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
  641. } else {
  642. /* FADT rev. 1 */
  643. pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
  644. }
  645. if (pmtmr_ioport)
  646. printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
  647. pmtmr_ioport);
  648. #endif
  649. return 0;
  650. }
  651. #ifdef CONFIG_X86_LOCAL_APIC
  652. /*
  653. * Parse LAPIC entries in MADT
  654. * returns 0 on success, < 0 on error
  655. */
  656. static void __init acpi_register_lapic_address(unsigned long address)
  657. {
  658. mp_lapic_addr = address;
  659. set_fixmap_nocache(FIX_APIC_BASE, address);
  660. if (boot_cpu_physical_apicid == -1U) {
  661. boot_cpu_physical_apicid = read_apic_id();
  662. apic_version[boot_cpu_physical_apicid] =
  663. GET_APIC_VERSION(apic_read(APIC_LVR));
  664. }
  665. }
  666. static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
  667. {
  668. int count;
  669. if (!cpu_has_apic)
  670. return -ENODEV;
  671. /*
  672. * Note that the LAPIC address is obtained from the MADT (32-bit value)
  673. * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
  674. */
  675. count =
  676. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
  677. acpi_parse_lapic_addr_ovr, 0);
  678. if (count < 0) {
  679. printk(KERN_ERR PREFIX
  680. "Error parsing LAPIC address override entry\n");
  681. return count;
  682. }
  683. acpi_register_lapic_address(acpi_lapic_addr);
  684. return count;
  685. }
  686. static int __init acpi_parse_madt_lapic_entries(void)
  687. {
  688. int count;
  689. int x2count = 0;
  690. if (!cpu_has_apic)
  691. return -ENODEV;
  692. /*
  693. * Note that the LAPIC address is obtained from the MADT (32-bit value)
  694. * and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
  695. */
  696. count =
  697. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
  698. acpi_parse_lapic_addr_ovr, 0);
  699. if (count < 0) {
  700. printk(KERN_ERR PREFIX
  701. "Error parsing LAPIC address override entry\n");
  702. return count;
  703. }
  704. acpi_register_lapic_address(acpi_lapic_addr);
  705. count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
  706. acpi_parse_sapic, MAX_APICS);
  707. if (!count) {
  708. x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
  709. acpi_parse_x2apic, MAX_APICS);
  710. count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
  711. acpi_parse_lapic, MAX_APICS);
  712. }
  713. if (!count && !x2count) {
  714. printk(KERN_ERR PREFIX "No LAPIC entries present\n");
  715. /* TBD: Cleanup to allow fallback to MPS */
  716. return -ENODEV;
  717. } else if (count < 0 || x2count < 0) {
  718. printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
  719. /* TBD: Cleanup to allow fallback to MPS */
  720. return count;
  721. }
  722. x2count =
  723. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
  724. acpi_parse_x2apic_nmi, 0);
  725. count =
  726. acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
  727. if (count < 0 || x2count < 0) {
  728. printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
  729. /* TBD: Cleanup to allow fallback to MPS */
  730. return count;
  731. }
  732. return 0;
  733. }
  734. #endif /* CONFIG_X86_LOCAL_APIC */
  735. #ifdef CONFIG_X86_IO_APIC
  736. #define MP_ISA_BUS 0
  737. #ifdef CONFIG_X86_ES7000
  738. extern int es7000_plat;
  739. #endif
  740. static void assign_to_mp_irq(struct mpc_intsrc *m,
  741. struct mpc_intsrc *mp_irq)
  742. {
  743. memcpy(mp_irq, m, sizeof(struct mpc_intsrc));
  744. }
  745. static int mp_irq_cmp(struct mpc_intsrc *mp_irq,
  746. struct mpc_intsrc *m)
  747. {
  748. return memcmp(mp_irq, m, sizeof(struct mpc_intsrc));
  749. }
  750. static void save_mp_irq(struct mpc_intsrc *m)
  751. {
  752. int i;
  753. for (i = 0; i < mp_irq_entries; i++) {
  754. if (!mp_irq_cmp(&mp_irqs[i], m))
  755. return;
  756. }
  757. assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
  758. if (++mp_irq_entries == MAX_IRQ_SOURCES)
  759. panic("Max # of irq sources exceeded!!\n");
  760. }
  761. void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
  762. {
  763. int ioapic;
  764. int pin;
  765. struct mpc_intsrc mp_irq;
  766. /*
  767. * Convert 'gsi' to 'ioapic.pin'.
  768. */
  769. ioapic = mp_find_ioapic(gsi);
  770. if (ioapic < 0)
  771. return;
  772. pin = mp_find_ioapic_pin(ioapic, gsi);
  773. /*
  774. * TBD: This check is for faulty timer entries, where the override
  775. * erroneously sets the trigger to level, resulting in a HUGE
  776. * increase of timer interrupts!
  777. */
  778. if ((bus_irq == 0) && (trigger == 3))
  779. trigger = 1;
  780. mp_irq.type = MP_INTSRC;
  781. mp_irq.irqtype = mp_INT;
  782. mp_irq.irqflag = (trigger << 2) | polarity;
  783. mp_irq.srcbus = MP_ISA_BUS;
  784. mp_irq.srcbusirq = bus_irq; /* IRQ */
  785. mp_irq.dstapic = mp_ioapics[ioapic].apicid; /* APIC ID */
  786. mp_irq.dstirq = pin; /* INTIN# */
  787. save_mp_irq(&mp_irq);
  788. isa_irq_to_gsi[bus_irq] = gsi;
  789. }
  790. void __init mp_config_acpi_legacy_irqs(void)
  791. {
  792. int i;
  793. struct mpc_intsrc mp_irq;
  794. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  795. /*
  796. * Fabricate the legacy ISA bus (bus #31).
  797. */
  798. mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
  799. #endif
  800. set_bit(MP_ISA_BUS, mp_bus_not_pci);
  801. pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
  802. #ifdef CONFIG_X86_ES7000
  803. /*
  804. * Older generations of ES7000 have no legacy identity mappings
  805. */
  806. if (es7000_plat == 1)
  807. return;
  808. #endif
  809. /*
  810. * Use the default configuration for the IRQs 0-15. Unless
  811. * overridden by (MADT) interrupt source override entries.
  812. */
  813. for (i = 0; i < 16; i++) {
  814. int ioapic, pin;
  815. unsigned int dstapic;
  816. int idx;
  817. u32 gsi;
  818. /* Locate the gsi that irq i maps to. */
  819. if (acpi_isa_irq_to_gsi(i, &gsi))
  820. continue;
  821. /*
  822. * Locate the IOAPIC that manages the ISA IRQ.
  823. */
  824. ioapic = mp_find_ioapic(gsi);
  825. if (ioapic < 0)
  826. continue;
  827. pin = mp_find_ioapic_pin(ioapic, gsi);
  828. dstapic = mp_ioapics[ioapic].apicid;
  829. for (idx = 0; idx < mp_irq_entries; idx++) {
  830. struct mpc_intsrc *irq = mp_irqs + idx;
  831. /* Do we already have a mapping for this ISA IRQ? */
  832. if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
  833. break;
  834. /* Do we already have a mapping for this IOAPIC pin */
  835. if (irq->dstapic == dstapic && irq->dstirq == pin)
  836. break;
  837. }
  838. if (idx != mp_irq_entries) {
  839. printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
  840. continue; /* IRQ already used */
  841. }
  842. mp_irq.type = MP_INTSRC;
  843. mp_irq.irqflag = 0; /* Conforming */
  844. mp_irq.srcbus = MP_ISA_BUS;
  845. mp_irq.dstapic = dstapic;
  846. mp_irq.irqtype = mp_INT;
  847. mp_irq.srcbusirq = i; /* Identity mapped */
  848. mp_irq.dstirq = pin;
  849. save_mp_irq(&mp_irq);
  850. }
  851. }
  852. static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
  853. int polarity)
  854. {
  855. #ifdef CONFIG_X86_MPPARSE
  856. struct mpc_intsrc mp_irq;
  857. struct pci_dev *pdev;
  858. unsigned char number;
  859. unsigned int devfn;
  860. int ioapic;
  861. u8 pin;
  862. if (!acpi_ioapic)
  863. return 0;
  864. if (!dev)
  865. return 0;
  866. if (dev->bus != &pci_bus_type)
  867. return 0;
  868. pdev = to_pci_dev(dev);
  869. number = pdev->bus->number;
  870. devfn = pdev->devfn;
  871. pin = pdev->pin;
  872. /* print the entry should happen on mptable identically */
  873. mp_irq.type = MP_INTSRC;
  874. mp_irq.irqtype = mp_INT;
  875. mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
  876. (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
  877. mp_irq.srcbus = number;
  878. mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
  879. ioapic = mp_find_ioapic(gsi);
  880. mp_irq.dstapic = mp_ioapics[ioapic].apicid;
  881. mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
  882. save_mp_irq(&mp_irq);
  883. #endif
  884. return 0;
  885. }
  886. int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
  887. {
  888. int ioapic;
  889. int ioapic_pin;
  890. struct io_apic_irq_attr irq_attr;
  891. if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
  892. return gsi;
  893. /* Don't set up the ACPI SCI because it's already set up */
  894. if (acpi_gbl_FADT.sci_interrupt == gsi)
  895. return gsi;
  896. ioapic = mp_find_ioapic(gsi);
  897. if (ioapic < 0) {
  898. printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
  899. return gsi;
  900. }
  901. ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
  902. if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
  903. printk(KERN_ERR "Invalid reference to IOAPIC pin "
  904. "%d-%d\n", mp_ioapics[ioapic].apicid,
  905. ioapic_pin);
  906. return gsi;
  907. }
  908. if (enable_update_mptable)
  909. mp_config_acpi_gsi(dev, gsi, trigger, polarity);
  910. set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
  911. trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
  912. polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
  913. io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
  914. return gsi;
  915. }
  916. /*
  917. * Parse IOAPIC related entries in MADT
  918. * returns 0 on success, < 0 on error
  919. */
  920. static int __init acpi_parse_madt_ioapic_entries(void)
  921. {
  922. int count;
  923. /*
  924. * ACPI interpreter is required to complete interrupt setup,
  925. * so if it is off, don't enumerate the io-apics with ACPI.
  926. * If MPS is present, it will handle them,
  927. * otherwise the system will stay in PIC mode
  928. */
  929. if (acpi_disabled || acpi_noirq)
  930. return -ENODEV;
  931. if (!cpu_has_apic)
  932. return -ENODEV;
  933. /*
  934. * if "noapic" boot option, don't look for IO-APICs
  935. */
  936. if (skip_ioapic_setup) {
  937. printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
  938. "due to 'noapic' option.\n");
  939. return -ENODEV;
  940. }
  941. count =
  942. acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
  943. MAX_IO_APICS);
  944. if (!count) {
  945. printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
  946. return -ENODEV;
  947. } else if (count < 0) {
  948. printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
  949. return count;
  950. }
  951. count =
  952. acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
  953. nr_irqs);
  954. if (count < 0) {
  955. printk(KERN_ERR PREFIX
  956. "Error parsing interrupt source overrides entry\n");
  957. /* TBD: Cleanup to allow fallback to MPS */
  958. return count;
  959. }
  960. /*
  961. * If BIOS did not supply an INT_SRC_OVR for the SCI
  962. * pretend we got one so we can set the SCI flags.
  963. */
  964. if (!acpi_sci_override_gsi)
  965. acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
  966. acpi_gbl_FADT.sci_interrupt);
  967. /* Fill in identity legacy mappings where no override */
  968. mp_config_acpi_legacy_irqs();
  969. count =
  970. acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
  971. nr_irqs);
  972. if (count < 0) {
  973. printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
  974. /* TBD: Cleanup to allow fallback to MPS */
  975. return count;
  976. }
  977. return 0;
  978. }
  979. #else
  980. static inline int acpi_parse_madt_ioapic_entries(void)
  981. {
  982. return -1;
  983. }
  984. #endif /* !CONFIG_X86_IO_APIC */
  985. static void __init early_acpi_process_madt(void)
  986. {
  987. #ifdef CONFIG_X86_LOCAL_APIC
  988. int error;
  989. if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  990. /*
  991. * Parse MADT LAPIC entries
  992. */
  993. error = early_acpi_parse_madt_lapic_addr_ovr();
  994. if (!error) {
  995. acpi_lapic = 1;
  996. smp_found_config = 1;
  997. }
  998. if (error == -EINVAL) {
  999. /*
  1000. * Dell Precision Workstation 410, 610 come here.
  1001. */
  1002. printk(KERN_ERR PREFIX
  1003. "Invalid BIOS MADT, disabling ACPI\n");
  1004. disable_acpi();
  1005. }
  1006. }
  1007. #endif
  1008. }
  1009. static void __init acpi_process_madt(void)
  1010. {
  1011. #ifdef CONFIG_X86_LOCAL_APIC
  1012. int error;
  1013. if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  1014. /*
  1015. * Parse MADT LAPIC entries
  1016. */
  1017. error = acpi_parse_madt_lapic_entries();
  1018. if (!error) {
  1019. acpi_lapic = 1;
  1020. /*
  1021. * Parse MADT IO-APIC entries
  1022. */
  1023. error = acpi_parse_madt_ioapic_entries();
  1024. if (!error) {
  1025. acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
  1026. acpi_ioapic = 1;
  1027. smp_found_config = 1;
  1028. }
  1029. }
  1030. if (error == -EINVAL) {
  1031. /*
  1032. * Dell Precision Workstation 410, 610 come here.
  1033. */
  1034. printk(KERN_ERR PREFIX
  1035. "Invalid BIOS MADT, disabling ACPI\n");
  1036. disable_acpi();
  1037. }
  1038. } else {
  1039. /*
  1040. * ACPI found no MADT, and so ACPI wants UP PIC mode.
  1041. * In the event an MPS table was found, forget it.
  1042. * Boot with "acpi=off" to use MPS on such a system.
  1043. */
  1044. if (smp_found_config) {
  1045. printk(KERN_WARNING PREFIX
  1046. "No APIC-table, disabling MPS\n");
  1047. smp_found_config = 0;
  1048. }
  1049. }
  1050. /*
  1051. * ACPI supports both logical (e.g. Hyper-Threading) and physical
  1052. * processors, where MPS only supports physical.
  1053. */
  1054. if (acpi_lapic && acpi_ioapic)
  1055. printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
  1056. "information\n");
  1057. else if (acpi_lapic)
  1058. printk(KERN_INFO "Using ACPI for processor (LAPIC) "
  1059. "configuration information\n");
  1060. #endif
  1061. return;
  1062. }
  1063. static int __init disable_acpi_irq(const struct dmi_system_id *d)
  1064. {
  1065. if (!acpi_force) {
  1066. printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
  1067. d->ident);
  1068. acpi_noirq_set();
  1069. }
  1070. return 0;
  1071. }
  1072. static int __init disable_acpi_pci(const struct dmi_system_id *d)
  1073. {
  1074. if (!acpi_force) {
  1075. printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
  1076. d->ident);
  1077. acpi_disable_pci();
  1078. }
  1079. return 0;
  1080. }
  1081. static int __init dmi_disable_acpi(const struct dmi_system_id *d)
  1082. {
  1083. if (!acpi_force) {
  1084. printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
  1085. disable_acpi();
  1086. } else {
  1087. printk(KERN_NOTICE
  1088. "Warning: DMI blacklist says broken, but acpi forced\n");
  1089. }
  1090. return 0;
  1091. }
  1092. /*
  1093. * Force ignoring BIOS IRQ0 pin2 override
  1094. */
  1095. static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
  1096. {
  1097. /*
  1098. * The ati_ixp4x0_rev() early PCI quirk should have set
  1099. * the acpi_skip_timer_override flag already:
  1100. */
  1101. if (!acpi_skip_timer_override) {
  1102. WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
  1103. pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
  1104. d->ident);
  1105. acpi_skip_timer_override = 1;
  1106. }
  1107. return 0;
  1108. }
  1109. /*
  1110. * If your system is blacklisted here, but you find that acpi=force
  1111. * works for you, please contact linux-acpi@vger.kernel.org
  1112. */
  1113. static struct dmi_system_id __initdata acpi_dmi_table[] = {
  1114. /*
  1115. * Boxes that need ACPI disabled
  1116. */
  1117. {
  1118. .callback = dmi_disable_acpi,
  1119. .ident = "IBM Thinkpad",
  1120. .matches = {
  1121. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1122. DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
  1123. },
  1124. },
  1125. /*
  1126. * Boxes that need ACPI PCI IRQ routing disabled
  1127. */
  1128. {
  1129. .callback = disable_acpi_irq,
  1130. .ident = "ASUS A7V",
  1131. .matches = {
  1132. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
  1133. DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
  1134. /* newer BIOS, Revision 1011, does work */
  1135. DMI_MATCH(DMI_BIOS_VERSION,
  1136. "ASUS A7V ACPI BIOS Revision 1007"),
  1137. },
  1138. },
  1139. {
  1140. /*
  1141. * Latest BIOS for IBM 600E (1.16) has bad pcinum
  1142. * for LPC bridge, which is needed for the PCI
  1143. * interrupt links to work. DSDT fix is in bug 5966.
  1144. * 2645, 2646 model numbers are shared with 600/600E/600X
  1145. */
  1146. .callback = disable_acpi_irq,
  1147. .ident = "IBM Thinkpad 600 Series 2645",
  1148. .matches = {
  1149. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1150. DMI_MATCH(DMI_BOARD_NAME, "2645"),
  1151. },
  1152. },
  1153. {
  1154. .callback = disable_acpi_irq,
  1155. .ident = "IBM Thinkpad 600 Series 2646",
  1156. .matches = {
  1157. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
  1158. DMI_MATCH(DMI_BOARD_NAME, "2646"),
  1159. },
  1160. },
  1161. /*
  1162. * Boxes that need ACPI PCI IRQ routing and PCI scan disabled
  1163. */
  1164. { /* _BBN 0 bug */
  1165. .callback = disable_acpi_pci,
  1166. .ident = "ASUS PR-DLS",
  1167. .matches = {
  1168. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  1169. DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
  1170. DMI_MATCH(DMI_BIOS_VERSION,
  1171. "ASUS PR-DLS ACPI BIOS Revision 1010"),
  1172. DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
  1173. },
  1174. },
  1175. {
  1176. .callback = disable_acpi_pci,
  1177. .ident = "Acer TravelMate 36x Laptop",
  1178. .matches = {
  1179. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  1180. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
  1181. },
  1182. },
  1183. {}
  1184. };
  1185. /* second table for DMI checks that should run after early-quirks */
  1186. static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
  1187. /*
  1188. * HP laptops which use a DSDT reporting as HP/SB400/10000,
  1189. * which includes some code which overrides all temperature
  1190. * trip points to 16C if the INTIN2 input of the I/O APIC
  1191. * is enabled. This input is incorrectly designated the
  1192. * ISA IRQ 0 via an interrupt source override even though
  1193. * it is wired to the output of the master 8259A and INTIN0
  1194. * is not connected at all. Force ignoring BIOS IRQ0 pin2
  1195. * override in that cases.
  1196. */
  1197. {
  1198. .callback = dmi_ignore_irq0_timer_override,
  1199. .ident = "HP nx6115 laptop",
  1200. .matches = {
  1201. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1202. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
  1203. },
  1204. },
  1205. {
  1206. .callback = dmi_ignore_irq0_timer_override,
  1207. .ident = "HP NX6125 laptop",
  1208. .matches = {
  1209. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1210. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
  1211. },
  1212. },
  1213. {
  1214. .callback = dmi_ignore_irq0_timer_override,
  1215. .ident = "HP NX6325 laptop",
  1216. .matches = {
  1217. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1218. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
  1219. },
  1220. },
  1221. {
  1222. .callback = dmi_ignore_irq0_timer_override,
  1223. .ident = "HP 6715b laptop",
  1224. .matches = {
  1225. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1226. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
  1227. },
  1228. },
  1229. {}
  1230. };
  1231. /*
  1232. * acpi_boot_table_init() and acpi_boot_init()
  1233. * called from setup_arch(), always.
  1234. * 1. checksums all tables
  1235. * 2. enumerates lapics
  1236. * 3. enumerates io-apics
  1237. *
  1238. * acpi_table_init() is separate to allow reading SRAT without
  1239. * other side effects.
  1240. *
  1241. * side effects of acpi_boot_init:
  1242. * acpi_lapic = 1 if LAPIC found
  1243. * acpi_ioapic = 1 if IOAPIC found
  1244. * if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
  1245. * if acpi_blacklisted() acpi_disabled = 1;
  1246. * acpi_irq_model=...
  1247. * ...
  1248. */
  1249. void __init acpi_boot_table_init(void)
  1250. {
  1251. dmi_check_system(acpi_dmi_table);
  1252. /*
  1253. * If acpi_disabled, bail out
  1254. * One exception: acpi=ht continues far enough to enumerate LAPICs
  1255. */
  1256. if (acpi_disabled && !acpi_ht)
  1257. return;
  1258. /*
  1259. * Initialize the ACPI boot-time table parser.
  1260. */
  1261. if (acpi_table_init()) {
  1262. disable_acpi();
  1263. return;
  1264. }
  1265. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1266. /*
  1267. * blacklist may disable ACPI entirely
  1268. */
  1269. if (acpi_blacklisted()) {
  1270. if (acpi_force) {
  1271. printk(KERN_WARNING PREFIX "acpi=force override\n");
  1272. } else {
  1273. printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
  1274. disable_acpi();
  1275. return;
  1276. }
  1277. }
  1278. }
  1279. int __init early_acpi_boot_init(void)
  1280. {
  1281. /*
  1282. * If acpi_disabled, bail out
  1283. * One exception: acpi=ht continues far enough to enumerate LAPICs
  1284. */
  1285. if (acpi_disabled && !acpi_ht)
  1286. return 1;
  1287. /*
  1288. * Process the Multiple APIC Description Table (MADT), if present
  1289. */
  1290. early_acpi_process_madt();
  1291. return 0;
  1292. }
  1293. int __init acpi_boot_init(void)
  1294. {
  1295. /* those are executed after early-quirks are executed */
  1296. dmi_check_system(acpi_dmi_table_late);
  1297. /*
  1298. * If acpi_disabled, bail out
  1299. * One exception: acpi=ht continues far enough to enumerate LAPICs
  1300. */
  1301. if (acpi_disabled && !acpi_ht)
  1302. return 1;
  1303. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1304. /*
  1305. * set sci_int and PM timer address
  1306. */
  1307. acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
  1308. /*
  1309. * Process the Multiple APIC Description Table (MADT), if present
  1310. */
  1311. acpi_process_madt();
  1312. acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
  1313. if (!acpi_noirq)
  1314. x86_init.pci.init = pci_acpi_init;
  1315. return 0;
  1316. }
  1317. static int __init parse_acpi(char *arg)
  1318. {
  1319. if (!arg)
  1320. return -EINVAL;
  1321. /* "acpi=off" disables both ACPI table parsing and interpreter */
  1322. if (strcmp(arg, "off") == 0) {
  1323. disable_acpi();
  1324. }
  1325. /* acpi=force to over-ride black-list */
  1326. else if (strcmp(arg, "force") == 0) {
  1327. acpi_force = 1;
  1328. acpi_ht = 1;
  1329. acpi_disabled = 0;
  1330. }
  1331. /* acpi=strict disables out-of-spec workarounds */
  1332. else if (strcmp(arg, "strict") == 0) {
  1333. acpi_strict = 1;
  1334. }
  1335. /* Limit ACPI just to boot-time to enable HT */
  1336. else if (strcmp(arg, "ht") == 0) {
  1337. if (!acpi_force) {
  1338. printk(KERN_WARNING "acpi=ht will be removed in Linux-2.6.35\n");
  1339. disable_acpi();
  1340. }
  1341. acpi_ht = 1;
  1342. }
  1343. /* acpi=rsdt use RSDT instead of XSDT */
  1344. else if (strcmp(arg, "rsdt") == 0) {
  1345. acpi_rsdt_forced = 1;
  1346. }
  1347. /* "acpi=noirq" disables ACPI interrupt routing */
  1348. else if (strcmp(arg, "noirq") == 0) {
  1349. acpi_noirq_set();
  1350. }
  1351. /* "acpi=copy_dsdt" copys DSDT */
  1352. else if (strcmp(arg, "copy_dsdt") == 0) {
  1353. acpi_gbl_copy_dsdt_locally = 1;
  1354. } else {
  1355. /* Core will printk when we return error. */
  1356. return -EINVAL;
  1357. }
  1358. return 0;
  1359. }
  1360. early_param("acpi", parse_acpi);
  1361. /* FIXME: Using pci= for an ACPI parameter is a travesty. */
  1362. static int __init parse_pci(char *arg)
  1363. {
  1364. if (arg && strcmp(arg, "noacpi") == 0)
  1365. acpi_disable_pci();
  1366. return 0;
  1367. }
  1368. early_param("pci", parse_pci);
  1369. int __init acpi_mps_check(void)
  1370. {
  1371. #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
  1372. /* mptable code is not built-in*/
  1373. if (acpi_disabled || acpi_noirq) {
  1374. printk(KERN_WARNING "MPS support code is not built-in.\n"
  1375. "Using acpi=off or acpi=noirq or pci=noacpi "
  1376. "may have problem\n");
  1377. return 1;
  1378. }
  1379. #endif
  1380. return 0;
  1381. }
  1382. #ifdef CONFIG_X86_IO_APIC
  1383. static int __init parse_acpi_skip_timer_override(char *arg)
  1384. {
  1385. acpi_skip_timer_override = 1;
  1386. return 0;
  1387. }
  1388. early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
  1389. static int __init parse_acpi_use_timer_override(char *arg)
  1390. {
  1391. acpi_use_timer_override = 1;
  1392. return 0;
  1393. }
  1394. early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
  1395. #endif /* CONFIG_X86_IO_APIC */
  1396. static int __init setup_acpi_sci(char *s)
  1397. {
  1398. if (!s)
  1399. return -EINVAL;
  1400. if (!strcmp(s, "edge"))
  1401. acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
  1402. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1403. else if (!strcmp(s, "level"))
  1404. acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
  1405. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1406. else if (!strcmp(s, "high"))
  1407. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
  1408. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1409. else if (!strcmp(s, "low"))
  1410. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
  1411. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1412. else
  1413. return -EINVAL;
  1414. return 0;
  1415. }
  1416. early_param("acpi_sci", setup_acpi_sci);
  1417. int __acpi_acquire_global_lock(unsigned int *lock)
  1418. {
  1419. unsigned int old, new, val;
  1420. do {
  1421. old = *lock;
  1422. new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
  1423. val = cmpxchg(lock, old, new);
  1424. } while (unlikely (val != old));
  1425. return (new < 3) ? -1 : 0;
  1426. }
  1427. int __acpi_release_global_lock(unsigned int *lock)
  1428. {
  1429. unsigned int old, new, val;
  1430. do {
  1431. old = *lock;
  1432. new = old & ~0x3;
  1433. val = cmpxchg(lock, old, new);
  1434. } while (unlikely (val != old));
  1435. return old & 0x1;
  1436. }