boot.c 42 KB

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