boot.c 41 KB

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