boot.c 43 KB

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