boot.c 41 KB

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