boot.c 38 KB

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