boot.c 41 KB

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