boot.c 44 KB

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