boot.c 48 KB

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