boot.c 40 KB

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