boot.c 41 KB

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