boot.c 43 KB

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