boot.c 39 KB

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