boot.c 40 KB

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