boot.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773
  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_table_init()) {
  1324. disable_acpi();
  1325. return;
  1326. }
  1327. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1328. /*
  1329. * blacklist may disable ACPI entirely
  1330. */
  1331. if (acpi_blacklisted()) {
  1332. if (acpi_force) {
  1333. printk(KERN_WARNING PREFIX "acpi=force override\n");
  1334. } else {
  1335. printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
  1336. disable_acpi();
  1337. return;
  1338. }
  1339. }
  1340. }
  1341. int __init early_acpi_boot_init(void)
  1342. {
  1343. /*
  1344. * If acpi_disabled, bail out
  1345. */
  1346. if (acpi_disabled)
  1347. return 1;
  1348. /*
  1349. * Process the Multiple APIC Description Table (MADT), if present
  1350. */
  1351. early_acpi_process_madt();
  1352. /*
  1353. * Hardware-reduced ACPI mode initialization:
  1354. */
  1355. acpi_reduced_hw_init();
  1356. return 0;
  1357. }
  1358. int __init acpi_boot_init(void)
  1359. {
  1360. /* those are executed after early-quirks are executed */
  1361. dmi_check_system(acpi_dmi_table_late);
  1362. /*
  1363. * If acpi_disabled, bail out
  1364. */
  1365. if (acpi_disabled)
  1366. return 1;
  1367. acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
  1368. /*
  1369. * set sci_int and PM timer address
  1370. */
  1371. acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
  1372. /*
  1373. * Process the Multiple APIC Description Table (MADT), if present
  1374. */
  1375. acpi_process_madt();
  1376. acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
  1377. if (IS_ENABLED(CONFIG_ACPI_BGRT))
  1378. acpi_table_parse(ACPI_SIG_BGRT, acpi_parse_bgrt);
  1379. if (!acpi_noirq)
  1380. x86_init.pci.init = pci_acpi_init;
  1381. /* Do not enable ACPI SPCR console by default */
  1382. acpi_parse_spcr(earlycon_acpi_spcr_enable, false);
  1383. return 0;
  1384. }
  1385. static int __init parse_acpi(char *arg)
  1386. {
  1387. if (!arg)
  1388. return -EINVAL;
  1389. /* "acpi=off" disables both ACPI table parsing and interpreter */
  1390. if (strcmp(arg, "off") == 0) {
  1391. disable_acpi();
  1392. }
  1393. /* acpi=force to over-ride black-list */
  1394. else if (strcmp(arg, "force") == 0) {
  1395. acpi_force = 1;
  1396. acpi_disabled = 0;
  1397. }
  1398. /* acpi=strict disables out-of-spec workarounds */
  1399. else if (strcmp(arg, "strict") == 0) {
  1400. acpi_strict = 1;
  1401. }
  1402. /* acpi=rsdt use RSDT instead of XSDT */
  1403. else if (strcmp(arg, "rsdt") == 0) {
  1404. acpi_gbl_do_not_use_xsdt = TRUE;
  1405. }
  1406. /* "acpi=noirq" disables ACPI interrupt routing */
  1407. else if (strcmp(arg, "noirq") == 0) {
  1408. acpi_noirq_set();
  1409. }
  1410. /* "acpi=copy_dsdt" copys DSDT */
  1411. else if (strcmp(arg, "copy_dsdt") == 0) {
  1412. acpi_gbl_copy_dsdt_locally = 1;
  1413. }
  1414. /* "acpi=nocmcff" disables FF mode for corrected errors */
  1415. else if (strcmp(arg, "nocmcff") == 0) {
  1416. acpi_disable_cmcff = 1;
  1417. } else {
  1418. /* Core will printk when we return error. */
  1419. return -EINVAL;
  1420. }
  1421. return 0;
  1422. }
  1423. early_param("acpi", parse_acpi);
  1424. /* FIXME: Using pci= for an ACPI parameter is a travesty. */
  1425. static int __init parse_pci(char *arg)
  1426. {
  1427. if (arg && strcmp(arg, "noacpi") == 0)
  1428. acpi_disable_pci();
  1429. return 0;
  1430. }
  1431. early_param("pci", parse_pci);
  1432. int __init acpi_mps_check(void)
  1433. {
  1434. #if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
  1435. /* mptable code is not built-in*/
  1436. if (acpi_disabled || acpi_noirq) {
  1437. printk(KERN_WARNING "MPS support code is not built-in.\n"
  1438. "Using acpi=off or acpi=noirq or pci=noacpi "
  1439. "may have problem\n");
  1440. return 1;
  1441. }
  1442. #endif
  1443. return 0;
  1444. }
  1445. #ifdef CONFIG_X86_IO_APIC
  1446. static int __init parse_acpi_skip_timer_override(char *arg)
  1447. {
  1448. acpi_skip_timer_override = 1;
  1449. return 0;
  1450. }
  1451. early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
  1452. static int __init parse_acpi_use_timer_override(char *arg)
  1453. {
  1454. acpi_use_timer_override = 1;
  1455. return 0;
  1456. }
  1457. early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
  1458. #endif /* CONFIG_X86_IO_APIC */
  1459. static int __init setup_acpi_sci(char *s)
  1460. {
  1461. if (!s)
  1462. return -EINVAL;
  1463. if (!strcmp(s, "edge"))
  1464. acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
  1465. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1466. else if (!strcmp(s, "level"))
  1467. acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
  1468. (acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
  1469. else if (!strcmp(s, "high"))
  1470. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
  1471. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1472. else if (!strcmp(s, "low"))
  1473. acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
  1474. (acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
  1475. else
  1476. return -EINVAL;
  1477. return 0;
  1478. }
  1479. early_param("acpi_sci", setup_acpi_sci);
  1480. int __acpi_acquire_global_lock(unsigned int *lock)
  1481. {
  1482. unsigned int old, new, val;
  1483. do {
  1484. old = *lock;
  1485. new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
  1486. val = cmpxchg(lock, old, new);
  1487. } while (unlikely (val != old));
  1488. return (new < 3) ? -1 : 0;
  1489. }
  1490. int __acpi_release_global_lock(unsigned int *lock)
  1491. {
  1492. unsigned int old, new, val;
  1493. do {
  1494. old = *lock;
  1495. new = old & ~0x3;
  1496. val = cmpxchg(lock, old, new);
  1497. } while (unlikely (val != old));
  1498. return old & 0x1;
  1499. }
  1500. void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
  1501. {
  1502. e820__range_add(addr, size, E820_TYPE_ACPI);
  1503. e820__update_table_print();
  1504. }