io_apic_32.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031
  1. /*
  2. * Intel IO-APIC support for multi-Pentium hosts.
  3. *
  4. * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar, Hajnalka Szabo
  5. *
  6. * Many thanks to Stig Venaas for trying out countless experimental
  7. * patches and reporting/debugging problems patiently!
  8. *
  9. * (c) 1999, Multiple IO-APIC support, developed by
  10. * Ken-ichi Yaku <yaku@css1.kbnes.nec.co.jp> and
  11. * Hidemi Kishimoto <kisimoto@css1.kbnes.nec.co.jp>,
  12. * further tested and cleaned up by Zach Brown <zab@redhat.com>
  13. * and Ingo Molnar <mingo@redhat.com>
  14. *
  15. * Fixes
  16. * Maciej W. Rozycki : Bits for genuine 82489DX APICs;
  17. * thanks to Eric Gilmore
  18. * and Rolf G. Tews
  19. * for testing these extensively
  20. * Paul Diefenbaugh : Added full ACPI support
  21. */
  22. #include <linux/mm.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/sched.h>
  27. #include <linux/bootmem.h>
  28. #include <linux/mc146818rtc.h>
  29. #include <linux/compiler.h>
  30. #include <linux/acpi.h>
  31. #include <linux/module.h>
  32. #include <linux/sysdev.h>
  33. #include <linux/pci.h>
  34. #include <linux/msi.h>
  35. #include <linux/htirq.h>
  36. #include <linux/freezer.h>
  37. #include <linux/kthread.h>
  38. #include <linux/jiffies.h> /* time_after() */
  39. #include <asm/io.h>
  40. #include <asm/smp.h>
  41. #include <asm/desc.h>
  42. #include <asm/timer.h>
  43. #include <asm/i8259.h>
  44. #include <asm/nmi.h>
  45. #include <asm/msidef.h>
  46. #include <asm/hypertransport.h>
  47. #include <asm/setup.h>
  48. #include <mach_ipi.h>
  49. #include <mach_apic.h>
  50. #include <mach_apicdef.h>
  51. #define __apicdebuginit(type) static type __init
  52. int (*ioapic_renumber_irq)(int ioapic, int irq);
  53. atomic_t irq_mis_count;
  54. /* Where if anywhere is the i8259 connect in external int mode */
  55. static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
  56. static DEFINE_SPINLOCK(ioapic_lock);
  57. static DEFINE_SPINLOCK(vector_lock);
  58. int timer_through_8259 __initdata;
  59. /*
  60. * Is the SiS APIC rmw bug present ?
  61. * -1 = don't know, 0 = no, 1 = yes
  62. */
  63. int sis_apic_bug = -1;
  64. int first_free_entry;
  65. /*
  66. * # of IRQ routing registers
  67. */
  68. int nr_ioapic_registers[MAX_IO_APICS];
  69. /* I/O APIC entries */
  70. struct mp_config_ioapic mp_ioapics[MAX_IO_APICS];
  71. int nr_ioapics;
  72. /* MP IRQ source entries */
  73. struct mp_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
  74. /* # of MP IRQ source entries */
  75. int mp_irq_entries;
  76. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  77. int mp_bus_id_to_type[MAX_MP_BUSSES];
  78. #endif
  79. DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
  80. static int disable_timer_pin_1 __initdata;
  81. struct irq_cfg;
  82. struct irq_pin_list;
  83. struct irq_cfg {
  84. unsigned int irq;
  85. struct irq_cfg *next;
  86. struct irq_pin_list *irq_2_pin;
  87. cpumask_t domain;
  88. cpumask_t old_domain;
  89. unsigned move_cleanup_count;
  90. u8 vector;
  91. u8 move_in_progress : 1;
  92. };
  93. /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
  94. static struct irq_cfg irq_cfg_legacy[] __initdata = {
  95. [0] = { .irq = 0, .domain = CPU_MASK_ALL, .vector = IRQ0_VECTOR, },
  96. [1] = { .irq = 1, .domain = CPU_MASK_ALL, .vector = IRQ1_VECTOR, },
  97. [2] = { .irq = 2, .domain = CPU_MASK_ALL, .vector = IRQ2_VECTOR, },
  98. [3] = { .irq = 3, .domain = CPU_MASK_ALL, .vector = IRQ3_VECTOR, },
  99. [4] = { .irq = 4, .domain = CPU_MASK_ALL, .vector = IRQ4_VECTOR, },
  100. [5] = { .irq = 5, .domain = CPU_MASK_ALL, .vector = IRQ5_VECTOR, },
  101. [6] = { .irq = 6, .domain = CPU_MASK_ALL, .vector = IRQ6_VECTOR, },
  102. [7] = { .irq = 7, .domain = CPU_MASK_ALL, .vector = IRQ7_VECTOR, },
  103. [8] = { .irq = 8, .domain = CPU_MASK_ALL, .vector = IRQ8_VECTOR, },
  104. [9] = { .irq = 9, .domain = CPU_MASK_ALL, .vector = IRQ9_VECTOR, },
  105. [10] = { .irq = 10, .domain = CPU_MASK_ALL, .vector = IRQ10_VECTOR, },
  106. [11] = { .irq = 11, .domain = CPU_MASK_ALL, .vector = IRQ11_VECTOR, },
  107. [12] = { .irq = 12, .domain = CPU_MASK_ALL, .vector = IRQ12_VECTOR, },
  108. [13] = { .irq = 13, .domain = CPU_MASK_ALL, .vector = IRQ13_VECTOR, },
  109. [14] = { .irq = 14, .domain = CPU_MASK_ALL, .vector = IRQ14_VECTOR, },
  110. [15] = { .irq = 15, .domain = CPU_MASK_ALL, .vector = IRQ15_VECTOR, },
  111. };
  112. static struct irq_cfg irq_cfg_init = { .irq = -1U, };
  113. /* need to be biger than size of irq_cfg_legacy */
  114. static int nr_irq_cfg = 32;
  115. static int __init parse_nr_irq_cfg(char *arg)
  116. {
  117. if (arg) {
  118. nr_irq_cfg = simple_strtoul(arg, NULL, 0);
  119. if (nr_irq_cfg < 32)
  120. nr_irq_cfg = 32;
  121. }
  122. return 0;
  123. }
  124. early_param("nr_irq_cfg", parse_nr_irq_cfg);
  125. static void init_one_irq_cfg(struct irq_cfg *cfg)
  126. {
  127. memcpy(cfg, &irq_cfg_init, sizeof(struct irq_cfg));
  128. }
  129. static struct irq_cfg *irq_cfgx;
  130. static struct irq_cfg *irq_cfgx_free;
  131. static void __init init_work(void *data)
  132. {
  133. struct dyn_array *da = data;
  134. struct irq_cfg *cfg;
  135. int legacy_count;
  136. int i;
  137. cfg = *da->name;
  138. memcpy(cfg, irq_cfg_legacy, sizeof(irq_cfg_legacy));
  139. legacy_count = sizeof(irq_cfg_legacy)/sizeof(irq_cfg_legacy[0]);
  140. for (i = legacy_count; i < *da->nr; i++)
  141. init_one_irq_cfg(&cfg[i]);
  142. for (i = 1; i < *da->nr; i++)
  143. cfg[i-1].next = &cfg[i];
  144. irq_cfgx_free = &irq_cfgx[legacy_count];
  145. irq_cfgx[legacy_count - 1].next = NULL;
  146. }
  147. #define for_each_irq_cfg(cfg) \
  148. for (cfg = irq_cfgx; cfg; cfg = cfg->next)
  149. DEFINE_DYN_ARRAY(irq_cfgx, sizeof(struct irq_cfg), nr_irq_cfg, PAGE_SIZE, init_work);
  150. static struct irq_cfg *irq_cfg(unsigned int irq)
  151. {
  152. struct irq_cfg *cfg;
  153. cfg = irq_cfgx;
  154. while (cfg) {
  155. if (cfg->irq == irq)
  156. return cfg;
  157. cfg = cfg->next;
  158. }
  159. return NULL;
  160. }
  161. static struct irq_cfg *irq_cfg_alloc(unsigned int irq)
  162. {
  163. struct irq_cfg *cfg, *cfg_pri;
  164. int i;
  165. int count = 0;
  166. cfg_pri = cfg = irq_cfgx;
  167. while (cfg) {
  168. if (cfg->irq == irq)
  169. return cfg;
  170. cfg_pri = cfg;
  171. cfg = cfg->next;
  172. count++;
  173. }
  174. if (!irq_cfgx_free) {
  175. unsigned long phys;
  176. unsigned long total_bytes;
  177. /*
  178. * we run out of pre-allocate ones, allocate more
  179. */
  180. printk(KERN_DEBUG "try to get more irq_cfg %d\n", nr_irq_cfg);
  181. total_bytes = sizeof(struct irq_cfg) * nr_irq_cfg;
  182. if (after_bootmem)
  183. cfg = kzalloc(total_bytes, GFP_ATOMIC);
  184. else
  185. cfg = __alloc_bootmem_nopanic(total_bytes, PAGE_SIZE, 0);
  186. if (!cfg)
  187. panic("please boot with nr_irq_cfg= %d\n", count * 2);
  188. phys = __pa(cfg);
  189. printk(KERN_DEBUG "irq_irq ==> [%#lx - %#lx]\n", phys, phys + total_bytes);
  190. for (i = 0; i < nr_irq_cfg; i++)
  191. init_one_irq_cfg(&cfg[i]);
  192. for (i = 1; i < nr_irq_cfg; i++)
  193. cfg[i-1].next = &cfg[i];
  194. irq_cfgx_free = cfg;
  195. }
  196. cfg = irq_cfgx_free;
  197. irq_cfgx_free = irq_cfgx_free->next;
  198. cfg->next = NULL;
  199. if (cfg_pri)
  200. cfg_pri->next = cfg;
  201. else
  202. irq_cfgx = cfg;
  203. cfg->irq = irq;
  204. printk(KERN_DEBUG "found new irq_cfg for irq %d\n", cfg->irq);
  205. #ifdef CONFIG_HAVE_SPARSE_IRQ_DEBUG
  206. {
  207. /* dump the results */
  208. struct irq_cfg *cfg;
  209. unsigned long phys;
  210. unsigned long bytes = sizeof(struct irq_cfg);
  211. printk(KERN_DEBUG "=========================== %d\n", irq);
  212. printk(KERN_DEBUG "irq_cfg dump after get that for %d\n", irq);
  213. for_each_irq_cfg(cfg) {
  214. phys = __pa(cfg);
  215. printk(KERN_DEBUG "irq_cfg %d ==> [%#lx - %#lx]\n", cfg->irq, phys, phys + bytes);
  216. }
  217. printk(KERN_DEBUG "===========================\n");
  218. }
  219. #endif
  220. return cfg;
  221. }
  222. static int assign_irq_vector(int irq, cpumask_t mask);
  223. /*
  224. * Rough estimation of how many shared IRQs there are, can
  225. * be changed anytime.
  226. */
  227. int pin_map_size;
  228. /*
  229. * This is performance-critical, we want to do it O(1)
  230. *
  231. * the indexing order of this array favors 1:1 mappings
  232. * between pins and IRQs.
  233. */
  234. struct irq_pin_list {
  235. int apic, pin;
  236. struct irq_pin_list *next;
  237. };
  238. static struct irq_pin_list *irq_2_pin_head;
  239. /* fill one page ? */
  240. static int nr_irq_2_pin = 0x100;
  241. static struct irq_pin_list *irq_2_pin_ptr;
  242. static void __init irq_2_pin_init_work(void *data)
  243. {
  244. struct dyn_array *da = data;
  245. struct irq_pin_list *pin;
  246. int i;
  247. pin = *da->name;
  248. for (i = 1; i < *da->nr; i++)
  249. pin[i-1].next = &pin[i];
  250. irq_2_pin_ptr = &pin[0];
  251. }
  252. DEFINE_DYN_ARRAY(irq_2_pin_head, sizeof(struct irq_pin_list), nr_irq_2_pin, PAGE_SIZE, irq_2_pin_init_work);
  253. static struct irq_pin_list *get_one_free_irq_2_pin(void)
  254. {
  255. struct irq_pin_list *pin;
  256. int i;
  257. pin = irq_2_pin_ptr;
  258. if (pin) {
  259. irq_2_pin_ptr = pin->next;
  260. pin->next = NULL;
  261. return pin;
  262. }
  263. /*
  264. * we run out of pre-allocate ones, allocate more
  265. */
  266. printk(KERN_DEBUG "try to get more irq_2_pin %d\n", nr_irq_2_pin);
  267. if (after_bootmem)
  268. pin = kzalloc(sizeof(struct irq_pin_list)*nr_irq_2_pin,
  269. GFP_ATOMIC);
  270. else
  271. pin = __alloc_bootmem_nopanic(sizeof(struct irq_pin_list) *
  272. nr_irq_2_pin, PAGE_SIZE, 0);
  273. if (!pin)
  274. panic("can not get more irq_2_pin\n");
  275. for (i = 1; i < nr_irq_2_pin; i++)
  276. pin[i-1].next = &pin[i];
  277. irq_2_pin_ptr = pin->next;
  278. pin->next = NULL;
  279. return pin;
  280. }
  281. struct io_apic {
  282. unsigned int index;
  283. unsigned int unused[3];
  284. unsigned int data;
  285. };
  286. static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
  287. {
  288. return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx)
  289. + (mp_ioapics[idx].mp_apicaddr & ~PAGE_MASK);
  290. }
  291. static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
  292. {
  293. struct io_apic __iomem *io_apic = io_apic_base(apic);
  294. writel(reg, &io_apic->index);
  295. return readl(&io_apic->data);
  296. }
  297. static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value)
  298. {
  299. struct io_apic __iomem *io_apic = io_apic_base(apic);
  300. writel(reg, &io_apic->index);
  301. writel(value, &io_apic->data);
  302. }
  303. /*
  304. * Re-write a value: to be used for read-modify-write
  305. * cycles where the read already set up the index register.
  306. *
  307. * Older SiS APIC requires we rewrite the index register
  308. */
  309. static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value)
  310. {
  311. volatile struct io_apic __iomem *io_apic = io_apic_base(apic);
  312. if (sis_apic_bug)
  313. writel(reg, &io_apic->index);
  314. writel(value, &io_apic->data);
  315. }
  316. union entry_union {
  317. struct { u32 w1, w2; };
  318. struct IO_APIC_route_entry entry;
  319. };
  320. static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
  321. {
  322. union entry_union eu;
  323. unsigned long flags;
  324. spin_lock_irqsave(&ioapic_lock, flags);
  325. eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
  326. eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
  327. spin_unlock_irqrestore(&ioapic_lock, flags);
  328. return eu.entry;
  329. }
  330. /*
  331. * When we write a new IO APIC routing entry, we need to write the high
  332. * word first! If the mask bit in the low word is clear, we will enable
  333. * the interrupt, and we need to make sure the entry is fully populated
  334. * before that happens.
  335. */
  336. static void
  337. __ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
  338. {
  339. union entry_union eu;
  340. eu.entry = e;
  341. io_apic_write(apic, 0x11 + 2*pin, eu.w2);
  342. io_apic_write(apic, 0x10 + 2*pin, eu.w1);
  343. }
  344. static void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
  345. {
  346. unsigned long flags;
  347. spin_lock_irqsave(&ioapic_lock, flags);
  348. __ioapic_write_entry(apic, pin, e);
  349. spin_unlock_irqrestore(&ioapic_lock, flags);
  350. }
  351. /*
  352. * When we mask an IO APIC routing entry, we need to write the low
  353. * word first, in order to set the mask bit before we change the
  354. * high bits!
  355. */
  356. static void ioapic_mask_entry(int apic, int pin)
  357. {
  358. unsigned long flags;
  359. union entry_union eu = { .entry.mask = 1 };
  360. spin_lock_irqsave(&ioapic_lock, flags);
  361. io_apic_write(apic, 0x10 + 2*pin, eu.w1);
  362. io_apic_write(apic, 0x11 + 2*pin, eu.w2);
  363. spin_unlock_irqrestore(&ioapic_lock, flags);
  364. }
  365. #ifdef CONFIG_SMP
  366. static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, u8 vector)
  367. {
  368. int apic, pin;
  369. struct irq_cfg *cfg;
  370. struct irq_pin_list *entry;
  371. cfg = irq_cfg(irq);
  372. entry = cfg->irq_2_pin;
  373. for (;;) {
  374. unsigned int reg;
  375. if (!entry)
  376. break;
  377. apic = entry->apic;
  378. pin = entry->pin;
  379. io_apic_write(apic, 0x11 + pin*2, dest);
  380. reg = io_apic_read(apic, 0x10 + pin*2);
  381. reg &= ~IO_APIC_REDIR_VECTOR_MASK;
  382. reg |= vector;
  383. io_apic_modify(apic, 0x10 + pin *2, reg);
  384. if (!entry->next)
  385. break;
  386. entry = entry->next;
  387. }
  388. }
  389. static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t mask)
  390. {
  391. struct irq_cfg *cfg;
  392. unsigned long flags;
  393. unsigned int dest;
  394. cpumask_t tmp;
  395. cfg = irq_cfg(irq);
  396. cpus_and(tmp, mask, cpu_online_map);
  397. if (cpus_empty(tmp))
  398. return;
  399. if (assign_irq_vector(irq, mask))
  400. return;
  401. cpus_and(tmp, cfg->domain, mask);
  402. dest = cpu_mask_to_apicid(tmp);
  403. /*
  404. * Only the high 8 bits are valid.
  405. */
  406. dest = SET_APIC_LOGICAL_ID(dest);
  407. spin_lock_irqsave(&ioapic_lock, flags);
  408. __target_IO_APIC_irq(irq, dest, cfg->vector);
  409. irq_to_desc(irq)->affinity = mask;
  410. spin_unlock_irqrestore(&ioapic_lock, flags);
  411. }
  412. #endif /* CONFIG_SMP */
  413. /*
  414. * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
  415. * shared ISA-space IRQs, so we have to support them. We are super
  416. * fast in the common case, and fast for shared ISA-space IRQs.
  417. */
  418. static void add_pin_to_irq(unsigned int irq, int apic, int pin)
  419. {
  420. struct irq_cfg *cfg;
  421. struct irq_pin_list *entry;
  422. /* first time to refer irq_cfg, so with new */
  423. cfg = irq_cfg_alloc(irq);
  424. entry = cfg->irq_2_pin;
  425. if (!entry) {
  426. entry = get_one_free_irq_2_pin();
  427. cfg->irq_2_pin = entry;
  428. entry->apic = apic;
  429. entry->pin = pin;
  430. printk(KERN_DEBUG " 0 add_pin_to_irq: irq %d --> apic %d pin %d\n", irq, apic, pin);
  431. return;
  432. }
  433. while (entry->next) {
  434. /* not again, please */
  435. if (entry->apic == apic && entry->pin == pin)
  436. return;
  437. entry = entry->next;
  438. }
  439. entry->next = get_one_free_irq_2_pin();
  440. entry = entry->next;
  441. entry->apic = apic;
  442. entry->pin = pin;
  443. printk(KERN_DEBUG " x add_pin_to_irq: irq %d --> apic %d pin %d\n", irq, apic, pin);
  444. }
  445. /*
  446. * Reroute an IRQ to a different pin.
  447. */
  448. static void __init replace_pin_at_irq(unsigned int irq,
  449. int oldapic, int oldpin,
  450. int newapic, int newpin)
  451. {
  452. struct irq_cfg *cfg = irq_cfg(irq);
  453. struct irq_pin_list *entry = cfg->irq_2_pin;
  454. int replaced = 0;
  455. while (entry) {
  456. if (entry->apic == oldapic && entry->pin == oldpin) {
  457. entry->apic = newapic;
  458. entry->pin = newpin;
  459. replaced = 1;
  460. /* every one is different, right? */
  461. break;
  462. }
  463. entry = entry->next;
  464. }
  465. /* why? call replace before add? */
  466. if (!replaced)
  467. add_pin_to_irq(irq, newapic, newpin);
  468. }
  469. static void __modify_IO_APIC_irq(unsigned int irq, unsigned long enable, unsigned long disable)
  470. {
  471. struct irq_cfg *cfg;
  472. struct irq_pin_list *entry;
  473. unsigned int pin, reg;
  474. cfg = irq_cfg(irq);
  475. entry = cfg->irq_2_pin;
  476. for (;;) {
  477. if (!entry)
  478. break;
  479. pin = entry->pin;
  480. reg = io_apic_read(entry->apic, 0x10 + pin*2);
  481. reg &= ~disable;
  482. reg |= enable;
  483. io_apic_modify(entry->apic, 0x10 + pin*2, reg);
  484. if (!entry->next)
  485. break;
  486. entry = entry->next;
  487. }
  488. }
  489. /* mask = 1 */
  490. static void __mask_IO_APIC_irq(unsigned int irq)
  491. {
  492. __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED, 0);
  493. }
  494. /* mask = 0 */
  495. static void __unmask_IO_APIC_irq(unsigned int irq)
  496. {
  497. __modify_IO_APIC_irq(irq, 0, IO_APIC_REDIR_MASKED);
  498. }
  499. /* mask = 1, trigger = 0 */
  500. static void __mask_and_edge_IO_APIC_irq(unsigned int irq)
  501. {
  502. __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED,
  503. IO_APIC_REDIR_LEVEL_TRIGGER);
  504. }
  505. /* mask = 0, trigger = 1 */
  506. static void __unmask_and_level_IO_APIC_irq(unsigned int irq)
  507. {
  508. __modify_IO_APIC_irq(irq, IO_APIC_REDIR_LEVEL_TRIGGER,
  509. IO_APIC_REDIR_MASKED);
  510. }
  511. static void mask_IO_APIC_irq(unsigned int irq)
  512. {
  513. unsigned long flags;
  514. spin_lock_irqsave(&ioapic_lock, flags);
  515. __mask_IO_APIC_irq(irq);
  516. spin_unlock_irqrestore(&ioapic_lock, flags);
  517. }
  518. static void unmask_IO_APIC_irq(unsigned int irq)
  519. {
  520. unsigned long flags;
  521. spin_lock_irqsave(&ioapic_lock, flags);
  522. __unmask_IO_APIC_irq(irq);
  523. spin_unlock_irqrestore(&ioapic_lock, flags);
  524. }
  525. static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
  526. {
  527. struct IO_APIC_route_entry entry;
  528. /* Check delivery_mode to be sure we're not clearing an SMI pin */
  529. entry = ioapic_read_entry(apic, pin);
  530. if (entry.delivery_mode == dest_SMI)
  531. return;
  532. /*
  533. * Disable it in the IO-APIC irq-routing table:
  534. */
  535. ioapic_mask_entry(apic, pin);
  536. }
  537. static void clear_IO_APIC(void)
  538. {
  539. int apic, pin;
  540. for (apic = 0; apic < nr_ioapics; apic++)
  541. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
  542. clear_IO_APIC_pin(apic, pin);
  543. }
  544. #ifndef CONFIG_SMP
  545. void send_IPI_self(int vector)
  546. {
  547. unsigned int cfg;
  548. /*
  549. * Wait for idle.
  550. */
  551. apic_wait_icr_idle();
  552. cfg = APIC_DM_FIXED | APIC_DEST_SELF | vector | APIC_DEST_LOGICAL;
  553. /*
  554. * Send the IPI. The write to APIC_ICR fires this off.
  555. */
  556. apic_write(APIC_ICR, cfg);
  557. }
  558. #endif /* !CONFIG_SMP */
  559. /*
  560. * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
  561. * specific CPU-side IRQs.
  562. */
  563. #define MAX_PIRQS 8
  564. static int pirq_entries [MAX_PIRQS];
  565. static int pirqs_enabled;
  566. int skip_ioapic_setup;
  567. static int __init ioapic_pirq_setup(char *str)
  568. {
  569. int i, max;
  570. int ints[MAX_PIRQS+1];
  571. get_options(str, ARRAY_SIZE(ints), ints);
  572. for (i = 0; i < MAX_PIRQS; i++)
  573. pirq_entries[i] = -1;
  574. pirqs_enabled = 1;
  575. apic_printk(APIC_VERBOSE, KERN_INFO
  576. "PIRQ redirection, working around broken MP-BIOS.\n");
  577. max = MAX_PIRQS;
  578. if (ints[0] < MAX_PIRQS)
  579. max = ints[0];
  580. for (i = 0; i < max; i++) {
  581. apic_printk(APIC_VERBOSE, KERN_DEBUG
  582. "... PIRQ%d -> IRQ %d\n", i, ints[i+1]);
  583. /*
  584. * PIRQs are mapped upside down, usually.
  585. */
  586. pirq_entries[MAX_PIRQS-i-1] = ints[i+1];
  587. }
  588. return 1;
  589. }
  590. __setup("pirq=", ioapic_pirq_setup);
  591. /*
  592. * Find the IRQ entry number of a certain pin.
  593. */
  594. static int find_irq_entry(int apic, int pin, int type)
  595. {
  596. int i;
  597. for (i = 0; i < mp_irq_entries; i++)
  598. if (mp_irqs[i].mp_irqtype == type &&
  599. (mp_irqs[i].mp_dstapic == mp_ioapics[apic].mp_apicid ||
  600. mp_irqs[i].mp_dstapic == MP_APIC_ALL) &&
  601. mp_irqs[i].mp_dstirq == pin)
  602. return i;
  603. return -1;
  604. }
  605. /*
  606. * Find the pin to which IRQ[irq] (ISA) is connected
  607. */
  608. static int __init find_isa_irq_pin(int irq, int type)
  609. {
  610. int i;
  611. for (i = 0; i < mp_irq_entries; i++) {
  612. int lbus = mp_irqs[i].mp_srcbus;
  613. if (test_bit(lbus, mp_bus_not_pci) &&
  614. (mp_irqs[i].mp_irqtype == type) &&
  615. (mp_irqs[i].mp_srcbusirq == irq))
  616. return mp_irqs[i].mp_dstirq;
  617. }
  618. return -1;
  619. }
  620. static int __init find_isa_irq_apic(int irq, int type)
  621. {
  622. int i;
  623. for (i = 0; i < mp_irq_entries; i++) {
  624. int lbus = mp_irqs[i].mp_srcbus;
  625. if (test_bit(lbus, mp_bus_not_pci) &&
  626. (mp_irqs[i].mp_irqtype == type) &&
  627. (mp_irqs[i].mp_srcbusirq == irq))
  628. break;
  629. }
  630. if (i < mp_irq_entries) {
  631. int apic;
  632. for (apic = 0; apic < nr_ioapics; apic++) {
  633. if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic)
  634. return apic;
  635. }
  636. }
  637. return -1;
  638. }
  639. /*
  640. * Find a specific PCI IRQ entry.
  641. * Not an __init, possibly needed by modules
  642. */
  643. static int pin_2_irq(int idx, int apic, int pin);
  644. int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
  645. {
  646. int apic, i, best_guess = -1;
  647. apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, "
  648. "slot:%d, pin:%d.\n", bus, slot, pin);
  649. if (test_bit(bus, mp_bus_not_pci)) {
  650. printk(KERN_WARNING "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
  651. return -1;
  652. }
  653. for (i = 0; i < mp_irq_entries; i++) {
  654. int lbus = mp_irqs[i].mp_srcbus;
  655. for (apic = 0; apic < nr_ioapics; apic++)
  656. if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic ||
  657. mp_irqs[i].mp_dstapic == MP_APIC_ALL)
  658. break;
  659. if (!test_bit(lbus, mp_bus_not_pci) &&
  660. !mp_irqs[i].mp_irqtype &&
  661. (bus == lbus) &&
  662. (slot == ((mp_irqs[i].mp_srcbusirq >> 2) & 0x1f))) {
  663. int irq = pin_2_irq(i, apic, mp_irqs[i].mp_dstirq);
  664. if (!(apic || IO_APIC_IRQ(irq)))
  665. continue;
  666. if (pin == (mp_irqs[i].mp_srcbusirq & 3))
  667. return irq;
  668. /*
  669. * Use the first all-but-pin matching entry as a
  670. * best-guess fuzzy result for broken mptables.
  671. */
  672. if (best_guess < 0)
  673. best_guess = irq;
  674. }
  675. }
  676. return best_guess;
  677. }
  678. EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
  679. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  680. /*
  681. * EISA Edge/Level control register, ELCR
  682. */
  683. static int EISA_ELCR(unsigned int irq)
  684. {
  685. if (irq < 16) {
  686. unsigned int port = 0x4d0 + (irq >> 3);
  687. return (inb(port) >> (irq & 7)) & 1;
  688. }
  689. apic_printk(APIC_VERBOSE, KERN_INFO
  690. "Broken MPtable reports ISA irq %d\n", irq);
  691. return 0;
  692. }
  693. #endif
  694. /* ISA interrupts are always polarity zero edge triggered,
  695. * when listed as conforming in the MP table. */
  696. #define default_ISA_trigger(idx) (0)
  697. #define default_ISA_polarity(idx) (0)
  698. /* EISA interrupts are always polarity zero and can be edge or level
  699. * trigger depending on the ELCR value. If an interrupt is listed as
  700. * EISA conforming in the MP table, that means its trigger type must
  701. * be read in from the ELCR */
  702. #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].mp_srcbusirq))
  703. #define default_EISA_polarity(idx) default_ISA_polarity(idx)
  704. /* PCI interrupts are always polarity one level triggered,
  705. * when listed as conforming in the MP table. */
  706. #define default_PCI_trigger(idx) (1)
  707. #define default_PCI_polarity(idx) (1)
  708. /* MCA interrupts are always polarity zero level triggered,
  709. * when listed as conforming in the MP table. */
  710. #define default_MCA_trigger(idx) (1)
  711. #define default_MCA_polarity(idx) default_ISA_polarity(idx)
  712. static int MPBIOS_polarity(int idx)
  713. {
  714. int bus = mp_irqs[idx].mp_srcbus;
  715. int polarity;
  716. /*
  717. * Determine IRQ line polarity (high active or low active):
  718. */
  719. switch (mp_irqs[idx].mp_irqflag & 3) {
  720. case 0: /* conforms, ie. bus-type dependent polarity */
  721. {
  722. polarity = test_bit(bus, mp_bus_not_pci)?
  723. default_ISA_polarity(idx):
  724. default_PCI_polarity(idx);
  725. break;
  726. }
  727. case 1: /* high active */
  728. {
  729. polarity = 0;
  730. break;
  731. }
  732. case 2: /* reserved */
  733. {
  734. printk(KERN_WARNING "broken BIOS!!\n");
  735. polarity = 1;
  736. break;
  737. }
  738. case 3: /* low active */
  739. {
  740. polarity = 1;
  741. break;
  742. }
  743. default: /* invalid */
  744. {
  745. printk(KERN_WARNING "broken BIOS!!\n");
  746. polarity = 1;
  747. break;
  748. }
  749. }
  750. return polarity;
  751. }
  752. static int MPBIOS_trigger(int idx)
  753. {
  754. int bus = mp_irqs[idx].mp_srcbus;
  755. int trigger;
  756. /*
  757. * Determine IRQ trigger mode (edge or level sensitive):
  758. */
  759. switch ((mp_irqs[idx].mp_irqflag>>2) & 3) {
  760. case 0: /* conforms, ie. bus-type dependent */
  761. {
  762. trigger = test_bit(bus, mp_bus_not_pci)?
  763. default_ISA_trigger(idx):
  764. default_PCI_trigger(idx);
  765. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  766. switch (mp_bus_id_to_type[bus]) {
  767. case MP_BUS_ISA: /* ISA pin */
  768. {
  769. /* set before the switch */
  770. break;
  771. }
  772. case MP_BUS_EISA: /* EISA pin */
  773. {
  774. trigger = default_EISA_trigger(idx);
  775. break;
  776. }
  777. case MP_BUS_PCI: /* PCI pin */
  778. {
  779. /* set before the switch */
  780. break;
  781. }
  782. case MP_BUS_MCA: /* MCA pin */
  783. {
  784. trigger = default_MCA_trigger(idx);
  785. break;
  786. }
  787. default:
  788. {
  789. printk(KERN_WARNING "broken BIOS!!\n");
  790. trigger = 1;
  791. break;
  792. }
  793. }
  794. #endif
  795. break;
  796. }
  797. case 1: /* edge */
  798. {
  799. trigger = 0;
  800. break;
  801. }
  802. case 2: /* reserved */
  803. {
  804. printk(KERN_WARNING "broken BIOS!!\n");
  805. trigger = 1;
  806. break;
  807. }
  808. case 3: /* level */
  809. {
  810. trigger = 1;
  811. break;
  812. }
  813. default: /* invalid */
  814. {
  815. printk(KERN_WARNING "broken BIOS!!\n");
  816. trigger = 0;
  817. break;
  818. }
  819. }
  820. return trigger;
  821. }
  822. static inline int irq_polarity(int idx)
  823. {
  824. return MPBIOS_polarity(idx);
  825. }
  826. static inline int irq_trigger(int idx)
  827. {
  828. return MPBIOS_trigger(idx);
  829. }
  830. static int pin_2_irq(int idx, int apic, int pin)
  831. {
  832. int irq, i;
  833. int bus = mp_irqs[idx].mp_srcbus;
  834. /*
  835. * Debugging check, we are in big trouble if this message pops up!
  836. */
  837. if (mp_irqs[idx].mp_dstirq != pin)
  838. printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
  839. if (test_bit(bus, mp_bus_not_pci))
  840. irq = mp_irqs[idx].mp_srcbusirq;
  841. else {
  842. /*
  843. * PCI IRQs are mapped in order
  844. */
  845. i = irq = 0;
  846. while (i < apic)
  847. irq += nr_ioapic_registers[i++];
  848. irq += pin;
  849. /*
  850. * For MPS mode, so far only needed by ES7000 platform
  851. */
  852. if (ioapic_renumber_irq)
  853. irq = ioapic_renumber_irq(apic, irq);
  854. }
  855. /*
  856. * PCI IRQ command line redirection. Yes, limits are hardcoded.
  857. */
  858. if ((pin >= 16) && (pin <= 23)) {
  859. if (pirq_entries[pin-16] != -1) {
  860. if (!pirq_entries[pin-16]) {
  861. apic_printk(APIC_VERBOSE, KERN_DEBUG
  862. "disabling PIRQ%d\n", pin-16);
  863. } else {
  864. irq = pirq_entries[pin-16];
  865. apic_printk(APIC_VERBOSE, KERN_DEBUG
  866. "using PIRQ%d -> IRQ %d\n",
  867. pin-16, irq);
  868. }
  869. }
  870. }
  871. return irq;
  872. }
  873. static inline int IO_APIC_irq_trigger(int irq)
  874. {
  875. int apic, idx, pin;
  876. for (apic = 0; apic < nr_ioapics; apic++) {
  877. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  878. idx = find_irq_entry(apic, pin, mp_INT);
  879. if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
  880. return irq_trigger(idx);
  881. }
  882. }
  883. /*
  884. * nonexistent IRQs are edge default
  885. */
  886. return 0;
  887. }
  888. void lock_vector_lock(void)
  889. {
  890. /* Used to the online set of cpus does not change
  891. * during assign_irq_vector.
  892. */
  893. spin_lock(&vector_lock);
  894. }
  895. void unlock_vector_lock(void)
  896. {
  897. spin_unlock(&vector_lock);
  898. }
  899. static int __assign_irq_vector(int irq, cpumask_t mask)
  900. {
  901. static int current_vector = FIRST_DEVICE_VECTOR, current_offset = 0;
  902. unsigned int old_vector;
  903. int cpu;
  904. struct irq_cfg *cfg;
  905. cfg = irq_cfg(irq);
  906. /* Only try and allocate irqs on cpus that are present */
  907. cpus_and(mask, mask, cpu_online_map);
  908. if ((cfg->move_in_progress) || cfg->move_cleanup_count)
  909. return -EBUSY;
  910. old_vector = cfg->vector;
  911. if (old_vector) {
  912. cpumask_t tmp;
  913. cpus_and(tmp, cfg->domain, mask);
  914. if (!cpus_empty(tmp))
  915. return 0;
  916. }
  917. for_each_cpu_mask_nr(cpu, mask) {
  918. cpumask_t domain, new_mask;
  919. int new_cpu;
  920. int vector, offset;
  921. domain = vector_allocation_domain(cpu);
  922. cpus_and(new_mask, domain, cpu_online_map);
  923. vector = current_vector;
  924. offset = current_offset;
  925. next:
  926. vector += 8;
  927. if (vector >= first_system_vector) {
  928. /* If we run out of vectors on large boxen, must share them. */
  929. offset = (offset + 1) % 8;
  930. vector = FIRST_DEVICE_VECTOR + offset;
  931. }
  932. if (unlikely(current_vector == vector))
  933. continue;
  934. if (vector == SYSCALL_VECTOR)
  935. goto next;
  936. for_each_cpu_mask_nr(new_cpu, new_mask)
  937. if (per_cpu(vector_irq, new_cpu)[vector] != -1)
  938. goto next;
  939. /* Found one! */
  940. current_vector = vector;
  941. current_offset = offset;
  942. if (old_vector) {
  943. cfg->move_in_progress = 1;
  944. cfg->old_domain = cfg->domain;
  945. }
  946. printk(KERN_DEBUG "assign_irq_vector: irq %d vector %#x cpu ", irq, vector);
  947. for_each_cpu_mask_nr(new_cpu, new_mask) {
  948. per_cpu(vector_irq, new_cpu)[vector] = irq;
  949. printk(KERN_CONT " %d ", new_cpu);
  950. }
  951. printk(KERN_CONT "\n");
  952. cfg->vector = vector;
  953. cfg->domain = domain;
  954. return 0;
  955. }
  956. return -ENOSPC;
  957. }
  958. static int assign_irq_vector(int irq, cpumask_t mask)
  959. {
  960. int err;
  961. unsigned long flags;
  962. spin_lock_irqsave(&vector_lock, flags);
  963. err = __assign_irq_vector(irq, mask);
  964. spin_unlock_irqrestore(&vector_lock, flags);
  965. return err;
  966. }
  967. static void __clear_irq_vector(int irq)
  968. {
  969. struct irq_cfg *cfg;
  970. cpumask_t mask;
  971. int cpu, vector;
  972. cfg = irq_cfg(irq);
  973. BUG_ON(!cfg->vector);
  974. vector = cfg->vector;
  975. cpus_and(mask, cfg->domain, cpu_online_map);
  976. for_each_cpu_mask_nr(cpu, mask)
  977. per_cpu(vector_irq, cpu)[vector] = -1;
  978. cfg->vector = 0;
  979. cpus_clear(cfg->domain);
  980. }
  981. void __setup_vector_irq(int cpu)
  982. {
  983. /* Initialize vector_irq on a new cpu */
  984. /* This function must be called with vector_lock held */
  985. int irq, vector;
  986. struct irq_cfg *cfg;
  987. /* Mark the inuse vectors */
  988. for_each_irq_cfg(cfg) {
  989. if (!cpu_isset(cpu, cfg->domain))
  990. continue;
  991. vector = cfg->vector;
  992. irq = cfg->irq;
  993. per_cpu(vector_irq, cpu)[vector] = irq;
  994. }
  995. /* Mark the free vectors */
  996. for (vector = 0; vector < NR_VECTORS; ++vector) {
  997. irq = per_cpu(vector_irq, cpu)[vector];
  998. if (irq < 0)
  999. continue;
  1000. cfg = irq_cfg(irq);
  1001. if (!cpu_isset(cpu, cfg->domain))
  1002. per_cpu(vector_irq, cpu)[vector] = -1;
  1003. }
  1004. }
  1005. static struct irq_chip ioapic_chip;
  1006. #define IOAPIC_AUTO -1
  1007. #define IOAPIC_EDGE 0
  1008. #define IOAPIC_LEVEL 1
  1009. static void ioapic_register_intr(int irq, unsigned long trigger)
  1010. {
  1011. struct irq_desc *desc;
  1012. /* first time to use this irq_desc */
  1013. if (irq < 16)
  1014. desc = irq_to_desc(irq);
  1015. else
  1016. desc = irq_to_desc_alloc(irq);
  1017. if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
  1018. trigger == IOAPIC_LEVEL) {
  1019. desc->status |= IRQ_LEVEL;
  1020. set_irq_chip_and_handler_name(irq, &ioapic_chip,
  1021. handle_fasteoi_irq, "fasteoi");
  1022. } else {
  1023. desc->status &= ~IRQ_LEVEL;
  1024. set_irq_chip_and_handler_name(irq, &ioapic_chip,
  1025. handle_edge_irq, "edge");
  1026. }
  1027. }
  1028. static int setup_ioapic_entry(int apic, int irq,
  1029. struct IO_APIC_route_entry *entry,
  1030. unsigned int destination, int trigger,
  1031. int polarity, int vector)
  1032. {
  1033. /*
  1034. * add it to the IO-APIC irq-routing table:
  1035. */
  1036. memset(entry,0,sizeof(*entry));
  1037. entry->delivery_mode = INT_DELIVERY_MODE;
  1038. entry->dest_mode = INT_DEST_MODE;
  1039. entry->dest.logical.logical_dest = destination;
  1040. entry->mask = 0; /* enable IRQ */
  1041. entry->trigger = trigger;
  1042. entry->polarity = polarity;
  1043. entry->vector = vector;
  1044. /* Mask level triggered irqs.
  1045. * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
  1046. */
  1047. if (trigger)
  1048. entry->mask = 1;
  1049. return 0;
  1050. }
  1051. static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq,
  1052. int trigger, int polarity)
  1053. {
  1054. struct irq_cfg *cfg;
  1055. struct IO_APIC_route_entry entry;
  1056. cpumask_t mask;
  1057. if (!IO_APIC_IRQ(irq))
  1058. return;
  1059. cfg = irq_cfg(irq);
  1060. mask = TARGET_CPUS;
  1061. if (assign_irq_vector(irq, mask))
  1062. return;
  1063. cpus_and(mask, cfg->domain, mask);
  1064. apic_printk(APIC_VERBOSE,KERN_DEBUG
  1065. "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
  1066. "IRQ %d Mode:%i Active:%i)\n",
  1067. apic, mp_ioapics[apic].mp_apicid, pin, cfg->vector,
  1068. irq, trigger, polarity);
  1069. if (setup_ioapic_entry(mp_ioapics[apic].mp_apicid, irq, &entry,
  1070. cpu_mask_to_apicid(mask), trigger, polarity,
  1071. cfg->vector)) {
  1072. printk("Failed to setup ioapic entry for ioapic %d, pin %d\n",
  1073. mp_ioapics[apic].mp_apicid, pin);
  1074. __clear_irq_vector(irq);
  1075. return;
  1076. }
  1077. ioapic_register_intr(irq, trigger);
  1078. if (irq < 16)
  1079. disable_8259A_irq(irq);
  1080. ioapic_write_entry(apic, pin, entry);
  1081. }
  1082. static void __init setup_IO_APIC_irqs(void)
  1083. {
  1084. int apic, pin, idx, irq, first_notcon = 1;
  1085. apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
  1086. for (apic = 0; apic < nr_ioapics; apic++) {
  1087. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  1088. idx = find_irq_entry(apic,pin,mp_INT);
  1089. if (idx == -1) {
  1090. if (first_notcon) {
  1091. apic_printk(APIC_VERBOSE, KERN_DEBUG " IO-APIC (apicid-pin) %d-%d", mp_ioapics[apic].mp_apicid, pin);
  1092. first_notcon = 0;
  1093. } else
  1094. apic_printk(APIC_VERBOSE, ", %d-%d", mp_ioapics[apic].mp_apicid, pin);
  1095. continue;
  1096. }
  1097. if (!first_notcon) {
  1098. apic_printk(APIC_VERBOSE, " not connected.\n");
  1099. first_notcon = 1;
  1100. }
  1101. irq = pin_2_irq(idx, apic, pin);
  1102. if (multi_timer_check(apic, irq))
  1103. continue;
  1104. add_pin_to_irq(irq, apic, pin);
  1105. setup_IO_APIC_irq(apic, pin, irq,
  1106. irq_trigger(idx), irq_polarity(idx));
  1107. }
  1108. }
  1109. if (!first_notcon)
  1110. apic_printk(APIC_VERBOSE, " not connected.\n");
  1111. }
  1112. /*
  1113. * Set up the timer pin, possibly with the 8259A-master behind.
  1114. */
  1115. static void __init setup_timer_IRQ0_pin(unsigned int apic, unsigned int pin,
  1116. int vector)
  1117. {
  1118. struct IO_APIC_route_entry entry;
  1119. memset(&entry, 0, sizeof(entry));
  1120. /*
  1121. * We use logical delivery to get the timer IRQ
  1122. * to the first CPU.
  1123. */
  1124. entry.dest_mode = INT_DEST_MODE;
  1125. entry.mask = 1; /* mask IRQ now */
  1126. entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
  1127. entry.delivery_mode = INT_DELIVERY_MODE;
  1128. entry.polarity = 0;
  1129. entry.trigger = 0;
  1130. entry.vector = vector;
  1131. /*
  1132. * The timer IRQ doesn't have to know that behind the
  1133. * scene we may have a 8259A-master in AEOI mode ...
  1134. */
  1135. ioapic_register_intr(0, IOAPIC_EDGE);
  1136. /*
  1137. * Add it to the IO-APIC irq-routing table:
  1138. */
  1139. ioapic_write_entry(apic, pin, entry);
  1140. }
  1141. __apicdebuginit(void) print_IO_APIC(void)
  1142. {
  1143. int apic, i;
  1144. union IO_APIC_reg_00 reg_00;
  1145. union IO_APIC_reg_01 reg_01;
  1146. union IO_APIC_reg_02 reg_02;
  1147. union IO_APIC_reg_03 reg_03;
  1148. unsigned long flags;
  1149. struct irq_cfg *cfg;
  1150. if (apic_verbosity == APIC_QUIET)
  1151. return;
  1152. printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
  1153. for (i = 0; i < nr_ioapics; i++)
  1154. printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
  1155. mp_ioapics[i].mp_apicid, nr_ioapic_registers[i]);
  1156. /*
  1157. * We are a bit conservative about what we expect. We have to
  1158. * know about every hardware change ASAP.
  1159. */
  1160. printk(KERN_INFO "testing the IO APIC.......................\n");
  1161. for (apic = 0; apic < nr_ioapics; apic++) {
  1162. spin_lock_irqsave(&ioapic_lock, flags);
  1163. reg_00.raw = io_apic_read(apic, 0);
  1164. reg_01.raw = io_apic_read(apic, 1);
  1165. if (reg_01.bits.version >= 0x10)
  1166. reg_02.raw = io_apic_read(apic, 2);
  1167. if (reg_01.bits.version >= 0x20)
  1168. reg_03.raw = io_apic_read(apic, 3);
  1169. spin_unlock_irqrestore(&ioapic_lock, flags);
  1170. printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mp_apicid);
  1171. printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
  1172. printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
  1173. printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type);
  1174. printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS);
  1175. printk(KERN_DEBUG ".... register #01: %08X\n", reg_01.raw);
  1176. printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries);
  1177. printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
  1178. printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version);
  1179. /*
  1180. * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
  1181. * but the value of reg_02 is read as the previous read register
  1182. * value, so ignore it if reg_02 == reg_01.
  1183. */
  1184. if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) {
  1185. printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
  1186. printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
  1187. }
  1188. /*
  1189. * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
  1190. * or reg_03, but the value of reg_0[23] is read as the previous read
  1191. * register value, so ignore it if reg_03 == reg_0[12].
  1192. */
  1193. if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw &&
  1194. reg_03.raw != reg_01.raw) {
  1195. printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw);
  1196. printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT);
  1197. }
  1198. printk(KERN_DEBUG ".... IRQ redirection table:\n");
  1199. printk(KERN_DEBUG " NR Log Phy Mask Trig IRR Pol"
  1200. " Stat Dest Deli Vect: \n");
  1201. for (i = 0; i <= reg_01.bits.entries; i++) {
  1202. struct IO_APIC_route_entry entry;
  1203. entry = ioapic_read_entry(apic, i);
  1204. printk(KERN_DEBUG " %02x %03X %02X ",
  1205. i,
  1206. entry.dest.logical.logical_dest,
  1207. entry.dest.physical.physical_dest
  1208. );
  1209. printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
  1210. entry.mask,
  1211. entry.trigger,
  1212. entry.irr,
  1213. entry.polarity,
  1214. entry.delivery_status,
  1215. entry.dest_mode,
  1216. entry.delivery_mode,
  1217. entry.vector
  1218. );
  1219. }
  1220. }
  1221. printk(KERN_DEBUG "IRQ to pin mappings:\n");
  1222. for_each_irq_cfg(cfg) {
  1223. struct irq_pin_list *entry = cfg->irq_2_pin;
  1224. if (!entry)
  1225. continue;
  1226. printk(KERN_DEBUG "IRQ%d ", i);
  1227. for (;;) {
  1228. printk("-> %d:%d", entry->apic, entry->pin);
  1229. if (!entry->next)
  1230. break;
  1231. entry = entry->next;
  1232. }
  1233. printk("\n");
  1234. }
  1235. printk(KERN_INFO ".................................... done.\n");
  1236. return;
  1237. }
  1238. __apicdebuginit(void) print_APIC_bitfield(int base)
  1239. {
  1240. unsigned int v;
  1241. int i, j;
  1242. if (apic_verbosity == APIC_QUIET)
  1243. return;
  1244. printk(KERN_DEBUG "0123456789abcdef0123456789abcdef\n" KERN_DEBUG);
  1245. for (i = 0; i < 8; i++) {
  1246. v = apic_read(base + i*0x10);
  1247. for (j = 0; j < 32; j++) {
  1248. if (v & (1<<j))
  1249. printk("1");
  1250. else
  1251. printk("0");
  1252. }
  1253. printk("\n");
  1254. }
  1255. }
  1256. __apicdebuginit(void) print_local_APIC(void *dummy)
  1257. {
  1258. unsigned int v, ver, maxlvt;
  1259. u64 icr;
  1260. if (apic_verbosity == APIC_QUIET)
  1261. return;
  1262. printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
  1263. smp_processor_id(), hard_smp_processor_id());
  1264. v = apic_read(APIC_ID);
  1265. printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v,
  1266. GET_APIC_ID(v));
  1267. v = apic_read(APIC_LVR);
  1268. printk(KERN_INFO "... APIC VERSION: %08x\n", v);
  1269. ver = GET_APIC_VERSION(v);
  1270. maxlvt = lapic_get_maxlvt();
  1271. v = apic_read(APIC_TASKPRI);
  1272. printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
  1273. if (APIC_INTEGRATED(ver)) { /* !82489DX */
  1274. v = apic_read(APIC_ARBPRI);
  1275. printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
  1276. v & APIC_ARBPRI_MASK);
  1277. v = apic_read(APIC_PROCPRI);
  1278. printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
  1279. }
  1280. v = apic_read(APIC_EOI);
  1281. printk(KERN_DEBUG "... APIC EOI: %08x\n", v);
  1282. v = apic_read(APIC_RRR);
  1283. printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
  1284. v = apic_read(APIC_LDR);
  1285. printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
  1286. v = apic_read(APIC_DFR);
  1287. printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
  1288. v = apic_read(APIC_SPIV);
  1289. printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
  1290. printk(KERN_DEBUG "... APIC ISR field:\n");
  1291. print_APIC_bitfield(APIC_ISR);
  1292. printk(KERN_DEBUG "... APIC TMR field:\n");
  1293. print_APIC_bitfield(APIC_TMR);
  1294. printk(KERN_DEBUG "... APIC IRR field:\n");
  1295. print_APIC_bitfield(APIC_IRR);
  1296. if (APIC_INTEGRATED(ver)) { /* !82489DX */
  1297. if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
  1298. apic_write(APIC_ESR, 0);
  1299. v = apic_read(APIC_ESR);
  1300. printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
  1301. }
  1302. icr = apic_icr_read();
  1303. printk(KERN_DEBUG "... APIC ICR: %08x\n", icr);
  1304. printk(KERN_DEBUG "... APIC ICR2: %08x\n", icr >> 32);
  1305. v = apic_read(APIC_LVTT);
  1306. printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
  1307. if (maxlvt > 3) { /* PC is LVT#4. */
  1308. v = apic_read(APIC_LVTPC);
  1309. printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
  1310. }
  1311. v = apic_read(APIC_LVT0);
  1312. printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
  1313. v = apic_read(APIC_LVT1);
  1314. printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
  1315. if (maxlvt > 2) { /* ERR is LVT#3. */
  1316. v = apic_read(APIC_LVTERR);
  1317. printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
  1318. }
  1319. v = apic_read(APIC_TMICT);
  1320. printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
  1321. v = apic_read(APIC_TMCCT);
  1322. printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
  1323. v = apic_read(APIC_TDCR);
  1324. printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
  1325. printk("\n");
  1326. }
  1327. __apicdebuginit(void) print_all_local_APICs(void)
  1328. {
  1329. on_each_cpu(print_local_APIC, NULL, 1);
  1330. }
  1331. __apicdebuginit(void) print_PIC(void)
  1332. {
  1333. unsigned int v;
  1334. unsigned long flags;
  1335. if (apic_verbosity == APIC_QUIET)
  1336. return;
  1337. printk(KERN_DEBUG "\nprinting PIC contents\n");
  1338. spin_lock_irqsave(&i8259A_lock, flags);
  1339. v = inb(0xa1) << 8 | inb(0x21);
  1340. printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
  1341. v = inb(0xa0) << 8 | inb(0x20);
  1342. printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
  1343. outb(0x0b, 0xa0);
  1344. outb(0x0b, 0x20);
  1345. v = inb(0xa0) << 8 | inb(0x20);
  1346. outb(0x0a, 0xa0);
  1347. outb(0x0a, 0x20);
  1348. spin_unlock_irqrestore(&i8259A_lock, flags);
  1349. printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
  1350. v = inb(0x4d1) << 8 | inb(0x4d0);
  1351. printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
  1352. }
  1353. __apicdebuginit(int) print_all_ICs(void)
  1354. {
  1355. print_PIC();
  1356. print_all_local_APICs();
  1357. print_IO_APIC();
  1358. return 0;
  1359. }
  1360. fs_initcall(print_all_ICs);
  1361. static void __init enable_IO_APIC(void)
  1362. {
  1363. union IO_APIC_reg_01 reg_01;
  1364. int i8259_apic, i8259_pin;
  1365. int i, apic;
  1366. unsigned long flags;
  1367. if (!pirqs_enabled)
  1368. for (i = 0; i < MAX_PIRQS; i++)
  1369. pirq_entries[i] = -1;
  1370. /*
  1371. * The number of IO-APIC IRQ registers (== #pins):
  1372. */
  1373. for (apic = 0; apic < nr_ioapics; apic++) {
  1374. spin_lock_irqsave(&ioapic_lock, flags);
  1375. reg_01.raw = io_apic_read(apic, 1);
  1376. spin_unlock_irqrestore(&ioapic_lock, flags);
  1377. nr_ioapic_registers[apic] = reg_01.bits.entries+1;
  1378. }
  1379. for (apic = 0; apic < nr_ioapics; apic++) {
  1380. int pin;
  1381. /* See if any of the pins is in ExtINT mode */
  1382. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  1383. struct IO_APIC_route_entry entry;
  1384. entry = ioapic_read_entry(apic, pin);
  1385. /* If the interrupt line is enabled and in ExtInt mode
  1386. * I have found the pin where the i8259 is connected.
  1387. */
  1388. if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
  1389. ioapic_i8259.apic = apic;
  1390. ioapic_i8259.pin = pin;
  1391. goto found_i8259;
  1392. }
  1393. }
  1394. }
  1395. found_i8259:
  1396. /* Look to see what if the MP table has reported the ExtINT */
  1397. /* If we could not find the appropriate pin by looking at the ioapic
  1398. * the i8259 probably is not connected the ioapic but give the
  1399. * mptable a chance anyway.
  1400. */
  1401. i8259_pin = find_isa_irq_pin(0, mp_ExtINT);
  1402. i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
  1403. /* Trust the MP table if nothing is setup in the hardware */
  1404. if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
  1405. printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
  1406. ioapic_i8259.pin = i8259_pin;
  1407. ioapic_i8259.apic = i8259_apic;
  1408. }
  1409. /* Complain if the MP table and the hardware disagree */
  1410. if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
  1411. (i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
  1412. {
  1413. printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
  1414. }
  1415. /*
  1416. * Do not trust the IO-APIC being empty at bootup
  1417. */
  1418. clear_IO_APIC();
  1419. }
  1420. /*
  1421. * Not an __init, needed by the reboot code
  1422. */
  1423. void disable_IO_APIC(void)
  1424. {
  1425. /*
  1426. * Clear the IO-APIC before rebooting:
  1427. */
  1428. clear_IO_APIC();
  1429. /*
  1430. * If the i8259 is routed through an IOAPIC
  1431. * Put that IOAPIC in virtual wire mode
  1432. * so legacy interrupts can be delivered.
  1433. */
  1434. if (ioapic_i8259.pin != -1) {
  1435. struct IO_APIC_route_entry entry;
  1436. memset(&entry, 0, sizeof(entry));
  1437. entry.mask = 0; /* Enabled */
  1438. entry.trigger = 0; /* Edge */
  1439. entry.irr = 0;
  1440. entry.polarity = 0; /* High */
  1441. entry.delivery_status = 0;
  1442. entry.dest_mode = 0; /* Physical */
  1443. entry.delivery_mode = dest_ExtINT; /* ExtInt */
  1444. entry.vector = 0;
  1445. entry.dest.physical.physical_dest = read_apic_id();
  1446. /*
  1447. * Add it to the IO-APIC irq-routing table:
  1448. */
  1449. ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
  1450. }
  1451. disconnect_bsp_APIC(ioapic_i8259.pin != -1);
  1452. }
  1453. /*
  1454. * function to set the IO-APIC physical IDs based on the
  1455. * values stored in the MPC table.
  1456. *
  1457. * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
  1458. */
  1459. static void __init setup_ioapic_ids_from_mpc(void)
  1460. {
  1461. union IO_APIC_reg_00 reg_00;
  1462. physid_mask_t phys_id_present_map;
  1463. int apic;
  1464. int i;
  1465. unsigned char old_id;
  1466. unsigned long flags;
  1467. if (x86_quirks->setup_ioapic_ids && x86_quirks->setup_ioapic_ids())
  1468. return;
  1469. /*
  1470. * Don't check I/O APIC IDs for xAPIC systems. They have
  1471. * no meaning without the serial APIC bus.
  1472. */
  1473. if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
  1474. || APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  1475. return;
  1476. /*
  1477. * This is broken; anything with a real cpu count has to
  1478. * circumvent this idiocy regardless.
  1479. */
  1480. phys_id_present_map = ioapic_phys_id_map(phys_cpu_present_map);
  1481. /*
  1482. * Set the IOAPIC ID to the value stored in the MPC table.
  1483. */
  1484. for (apic = 0; apic < nr_ioapics; apic++) {
  1485. /* Read the register 0 value */
  1486. spin_lock_irqsave(&ioapic_lock, flags);
  1487. reg_00.raw = io_apic_read(apic, 0);
  1488. spin_unlock_irqrestore(&ioapic_lock, flags);
  1489. old_id = mp_ioapics[apic].mp_apicid;
  1490. if (mp_ioapics[apic].mp_apicid >= get_physical_broadcast()) {
  1491. printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
  1492. apic, mp_ioapics[apic].mp_apicid);
  1493. printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
  1494. reg_00.bits.ID);
  1495. mp_ioapics[apic].mp_apicid = reg_00.bits.ID;
  1496. }
  1497. /*
  1498. * Sanity check, is the ID really free? Every APIC in a
  1499. * system must have a unique ID or we get lots of nice
  1500. * 'stuck on smp_invalidate_needed IPI wait' messages.
  1501. */
  1502. if (check_apicid_used(phys_id_present_map,
  1503. mp_ioapics[apic].mp_apicid)) {
  1504. printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n",
  1505. apic, mp_ioapics[apic].mp_apicid);
  1506. for (i = 0; i < get_physical_broadcast(); i++)
  1507. if (!physid_isset(i, phys_id_present_map))
  1508. break;
  1509. if (i >= get_physical_broadcast())
  1510. panic("Max APIC ID exceeded!\n");
  1511. printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
  1512. i);
  1513. physid_set(i, phys_id_present_map);
  1514. mp_ioapics[apic].mp_apicid = i;
  1515. } else {
  1516. physid_mask_t tmp;
  1517. tmp = apicid_to_cpu_present(mp_ioapics[apic].mp_apicid);
  1518. apic_printk(APIC_VERBOSE, "Setting %d in the "
  1519. "phys_id_present_map\n",
  1520. mp_ioapics[apic].mp_apicid);
  1521. physids_or(phys_id_present_map, phys_id_present_map, tmp);
  1522. }
  1523. /*
  1524. * We need to adjust the IRQ routing table
  1525. * if the ID changed.
  1526. */
  1527. if (old_id != mp_ioapics[apic].mp_apicid)
  1528. for (i = 0; i < mp_irq_entries; i++)
  1529. if (mp_irqs[i].mp_dstapic == old_id)
  1530. mp_irqs[i].mp_dstapic
  1531. = mp_ioapics[apic].mp_apicid;
  1532. /*
  1533. * Read the right value from the MPC table and
  1534. * write it into the ID register.
  1535. */
  1536. apic_printk(APIC_VERBOSE, KERN_INFO
  1537. "...changing IO-APIC physical APIC ID to %d ...",
  1538. mp_ioapics[apic].mp_apicid);
  1539. reg_00.bits.ID = mp_ioapics[apic].mp_apicid;
  1540. spin_lock_irqsave(&ioapic_lock, flags);
  1541. io_apic_write(apic, 0, reg_00.raw);
  1542. spin_unlock_irqrestore(&ioapic_lock, flags);
  1543. /*
  1544. * Sanity check
  1545. */
  1546. spin_lock_irqsave(&ioapic_lock, flags);
  1547. reg_00.raw = io_apic_read(apic, 0);
  1548. spin_unlock_irqrestore(&ioapic_lock, flags);
  1549. if (reg_00.bits.ID != mp_ioapics[apic].mp_apicid)
  1550. printk("could not set ID!\n");
  1551. else
  1552. apic_printk(APIC_VERBOSE, " ok.\n");
  1553. }
  1554. }
  1555. int no_timer_check __initdata;
  1556. static int __init notimercheck(char *s)
  1557. {
  1558. no_timer_check = 1;
  1559. return 1;
  1560. }
  1561. __setup("no_timer_check", notimercheck);
  1562. /*
  1563. * There is a nasty bug in some older SMP boards, their mptable lies
  1564. * about the timer IRQ. We do the following to work around the situation:
  1565. *
  1566. * - timer IRQ defaults to IO-APIC IRQ
  1567. * - if this function detects that timer IRQs are defunct, then we fall
  1568. * back to ISA timer IRQs
  1569. */
  1570. static int __init timer_irq_works(void)
  1571. {
  1572. unsigned long t1 = jiffies;
  1573. unsigned long flags;
  1574. if (no_timer_check)
  1575. return 1;
  1576. local_save_flags(flags);
  1577. local_irq_enable();
  1578. /* Let ten ticks pass... */
  1579. mdelay((10 * 1000) / HZ);
  1580. local_irq_restore(flags);
  1581. /*
  1582. * Expect a few ticks at least, to be sure some possible
  1583. * glue logic does not lock up after one or two first
  1584. * ticks in a non-ExtINT mode. Also the local APIC
  1585. * might have cached one ExtINT interrupt. Finally, at
  1586. * least one tick may be lost due to delays.
  1587. */
  1588. if (time_after(jiffies, t1 + 4))
  1589. return 1;
  1590. return 0;
  1591. }
  1592. /*
  1593. * In the SMP+IOAPIC case it might happen that there are an unspecified
  1594. * number of pending IRQ events unhandled. These cases are very rare,
  1595. * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
  1596. * better to do it this way as thus we do not have to be aware of
  1597. * 'pending' interrupts in the IRQ path, except at this point.
  1598. */
  1599. /*
  1600. * Edge triggered needs to resend any interrupt
  1601. * that was delayed but this is now handled in the device
  1602. * independent code.
  1603. */
  1604. /*
  1605. * Startup quirk:
  1606. *
  1607. * Starting up a edge-triggered IO-APIC interrupt is
  1608. * nasty - we need to make sure that we get the edge.
  1609. * If it is already asserted for some reason, we need
  1610. * return 1 to indicate that is was pending.
  1611. *
  1612. * This is not complete - we should be able to fake
  1613. * an edge even if it isn't on the 8259A...
  1614. *
  1615. * (We do this for level-triggered IRQs too - it cannot hurt.)
  1616. */
  1617. static unsigned int startup_ioapic_irq(unsigned int irq)
  1618. {
  1619. int was_pending = 0;
  1620. unsigned long flags;
  1621. spin_lock_irqsave(&ioapic_lock, flags);
  1622. if (irq < 16) {
  1623. disable_8259A_irq(irq);
  1624. if (i8259A_irq_pending(irq))
  1625. was_pending = 1;
  1626. }
  1627. __unmask_IO_APIC_irq(irq);
  1628. spin_unlock_irqrestore(&ioapic_lock, flags);
  1629. return was_pending;
  1630. }
  1631. static void irq_complete_move(unsigned int irq);
  1632. static void ack_ioapic_irq(unsigned int irq)
  1633. {
  1634. irq_complete_move(irq);
  1635. move_native_irq(irq);
  1636. ack_APIC_irq();
  1637. }
  1638. static void ack_ioapic_quirk_irq(unsigned int irq)
  1639. {
  1640. unsigned long v;
  1641. int i;
  1642. irq_complete_move(irq);
  1643. move_native_irq(irq);
  1644. /*
  1645. * It appears there is an erratum which affects at least version 0x11
  1646. * of I/O APIC (that's the 82093AA and cores integrated into various
  1647. * chipsets). Under certain conditions a level-triggered interrupt is
  1648. * erroneously delivered as edge-triggered one but the respective IRR
  1649. * bit gets set nevertheless. As a result the I/O unit expects an EOI
  1650. * message but it will never arrive and further interrupts are blocked
  1651. * from the source. The exact reason is so far unknown, but the
  1652. * phenomenon was observed when two consecutive interrupt requests
  1653. * from a given source get delivered to the same CPU and the source is
  1654. * temporarily disabled in between.
  1655. *
  1656. * A workaround is to simulate an EOI message manually. We achieve it
  1657. * by setting the trigger mode to edge and then to level when the edge
  1658. * trigger mode gets detected in the TMR of a local APIC for a
  1659. * level-triggered interrupt. We mask the source for the time of the
  1660. * operation to prevent an edge-triggered interrupt escaping meanwhile.
  1661. * The idea is from Manfred Spraul. --macro
  1662. */
  1663. i = irq_cfg(irq)->vector;
  1664. v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
  1665. ack_APIC_irq();
  1666. if (!(v & (1 << (i & 0x1f)))) {
  1667. atomic_inc(&irq_mis_count);
  1668. spin_lock(&ioapic_lock);
  1669. __mask_and_edge_IO_APIC_irq(irq);
  1670. __unmask_and_level_IO_APIC_irq(irq);
  1671. spin_unlock(&ioapic_lock);
  1672. }
  1673. }
  1674. static int ioapic_retrigger_irq(unsigned int irq)
  1675. {
  1676. send_IPI_self(irq_cfg(irq)->vector);
  1677. return 1;
  1678. }
  1679. #ifdef CONFIG_SMP
  1680. asmlinkage void smp_irq_move_cleanup_interrupt(void)
  1681. {
  1682. unsigned vector, me;
  1683. ack_APIC_irq();
  1684. irq_enter();
  1685. me = smp_processor_id();
  1686. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
  1687. unsigned int irq;
  1688. struct irq_desc *desc;
  1689. struct irq_cfg *cfg;
  1690. irq = __get_cpu_var(vector_irq)[vector];
  1691. desc = irq_to_desc(irq);
  1692. if (!desc)
  1693. continue;
  1694. cfg = irq_cfg(irq);
  1695. spin_lock(&desc->lock);
  1696. if (!cfg->move_cleanup_count)
  1697. goto unlock;
  1698. if ((vector == cfg->vector) && cpu_isset(me, cfg->domain))
  1699. goto unlock;
  1700. __get_cpu_var(vector_irq)[vector] = -1;
  1701. cfg->move_cleanup_count--;
  1702. unlock:
  1703. spin_unlock(&desc->lock);
  1704. }
  1705. irq_exit();
  1706. }
  1707. static void irq_complete_move(unsigned int irq)
  1708. {
  1709. struct irq_cfg *cfg = irq_cfg(irq);
  1710. unsigned vector, me;
  1711. if (likely(!cfg->move_in_progress))
  1712. return;
  1713. vector = ~get_irq_regs()->orig_ax;
  1714. me = smp_processor_id();
  1715. if ((vector == cfg->vector) && cpu_isset(me, cfg->domain)) {
  1716. cpumask_t cleanup_mask;
  1717. cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map);
  1718. cfg->move_cleanup_count = cpus_weight(cleanup_mask);
  1719. send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
  1720. cfg->move_in_progress = 0;
  1721. }
  1722. }
  1723. #else
  1724. static inline void irq_complete_move(unsigned int irq) {}
  1725. #endif
  1726. static struct irq_chip ioapic_chip __read_mostly = {
  1727. .name = "IO-APIC",
  1728. .startup = startup_ioapic_irq,
  1729. .mask = mask_IO_APIC_irq,
  1730. .unmask = unmask_IO_APIC_irq,
  1731. .ack = ack_ioapic_irq,
  1732. .eoi = ack_ioapic_quirk_irq,
  1733. #ifdef CONFIG_SMP
  1734. .set_affinity = set_ioapic_affinity_irq,
  1735. #endif
  1736. .retrigger = ioapic_retrigger_irq,
  1737. };
  1738. static inline void init_IO_APIC_traps(void)
  1739. {
  1740. int irq;
  1741. struct irq_desc *desc;
  1742. struct irq_cfg *cfg;
  1743. /*
  1744. * NOTE! The local APIC isn't very good at handling
  1745. * multiple interrupts at the same interrupt level.
  1746. * As the interrupt level is determined by taking the
  1747. * vector number and shifting that right by 4, we
  1748. * want to spread these out a bit so that they don't
  1749. * all fall in the same interrupt level.
  1750. *
  1751. * Also, we've got to be careful not to trash gate
  1752. * 0x80, because int 0x80 is hm, kind of importantish. ;)
  1753. */
  1754. for_each_irq_cfg(cfg) {
  1755. irq = cfg->irq;
  1756. if (IO_APIC_IRQ(irq) && !cfg->vector) {
  1757. /*
  1758. * Hmm.. We don't have an entry for this,
  1759. * so default to an old-fashioned 8259
  1760. * interrupt if we can..
  1761. */
  1762. if (irq < 16)
  1763. make_8259A_irq(irq);
  1764. else {
  1765. desc = irq_to_desc(irq);
  1766. /* Strange. Oh, well.. */
  1767. desc->chip = &no_irq_chip;
  1768. }
  1769. }
  1770. }
  1771. }
  1772. /*
  1773. * The local APIC irq-chip implementation:
  1774. */
  1775. static void ack_lapic_irq(unsigned int irq)
  1776. {
  1777. ack_APIC_irq();
  1778. }
  1779. static void mask_lapic_irq(unsigned int irq)
  1780. {
  1781. unsigned long v;
  1782. v = apic_read(APIC_LVT0);
  1783. apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
  1784. }
  1785. static void unmask_lapic_irq(unsigned int irq)
  1786. {
  1787. unsigned long v;
  1788. v = apic_read(APIC_LVT0);
  1789. apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
  1790. }
  1791. static struct irq_chip lapic_chip __read_mostly = {
  1792. .name = "local-APIC",
  1793. .mask = mask_lapic_irq,
  1794. .unmask = unmask_lapic_irq,
  1795. .ack = ack_lapic_irq,
  1796. };
  1797. static void lapic_register_intr(int irq)
  1798. {
  1799. struct irq_desc *desc;
  1800. desc = irq_to_desc(irq);
  1801. desc->status &= ~IRQ_LEVEL;
  1802. set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
  1803. "edge");
  1804. }
  1805. static void __init setup_nmi(void)
  1806. {
  1807. /*
  1808. * Dirty trick to enable the NMI watchdog ...
  1809. * We put the 8259A master into AEOI mode and
  1810. * unmask on all local APICs LVT0 as NMI.
  1811. *
  1812. * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
  1813. * is from Maciej W. Rozycki - so we do not have to EOI from
  1814. * the NMI handler or the timer interrupt.
  1815. */
  1816. apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");
  1817. enable_NMI_through_LVT0();
  1818. apic_printk(APIC_VERBOSE, " done.\n");
  1819. }
  1820. /*
  1821. * This looks a bit hackish but it's about the only one way of sending
  1822. * a few INTA cycles to 8259As and any associated glue logic. ICR does
  1823. * not support the ExtINT mode, unfortunately. We need to send these
  1824. * cycles as some i82489DX-based boards have glue logic that keeps the
  1825. * 8259A interrupt line asserted until INTA. --macro
  1826. */
  1827. static inline void __init unlock_ExtINT_logic(void)
  1828. {
  1829. int apic, pin, i;
  1830. struct IO_APIC_route_entry entry0, entry1;
  1831. unsigned char save_control, save_freq_select;
  1832. pin = find_isa_irq_pin(8, mp_INT);
  1833. if (pin == -1) {
  1834. WARN_ON_ONCE(1);
  1835. return;
  1836. }
  1837. apic = find_isa_irq_apic(8, mp_INT);
  1838. if (apic == -1) {
  1839. WARN_ON_ONCE(1);
  1840. return;
  1841. }
  1842. entry0 = ioapic_read_entry(apic, pin);
  1843. clear_IO_APIC_pin(apic, pin);
  1844. memset(&entry1, 0, sizeof(entry1));
  1845. entry1.dest_mode = 0; /* physical delivery */
  1846. entry1.mask = 0; /* unmask IRQ now */
  1847. entry1.dest.physical.physical_dest = hard_smp_processor_id();
  1848. entry1.delivery_mode = dest_ExtINT;
  1849. entry1.polarity = entry0.polarity;
  1850. entry1.trigger = 0;
  1851. entry1.vector = 0;
  1852. ioapic_write_entry(apic, pin, entry1);
  1853. save_control = CMOS_READ(RTC_CONTROL);
  1854. save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
  1855. CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
  1856. RTC_FREQ_SELECT);
  1857. CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
  1858. i = 100;
  1859. while (i-- > 0) {
  1860. mdelay(10);
  1861. if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
  1862. i -= 10;
  1863. }
  1864. CMOS_WRITE(save_control, RTC_CONTROL);
  1865. CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
  1866. clear_IO_APIC_pin(apic, pin);
  1867. ioapic_write_entry(apic, pin, entry0);
  1868. }
  1869. /*
  1870. * This code may look a bit paranoid, but it's supposed to cooperate with
  1871. * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
  1872. * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
  1873. * fanatically on his truly buggy board.
  1874. */
  1875. static inline void __init check_timer(void)
  1876. {
  1877. struct irq_cfg *cfg = irq_cfg(0);
  1878. int apic1, pin1, apic2, pin2;
  1879. int no_pin1 = 0;
  1880. unsigned int ver;
  1881. unsigned long flags;
  1882. local_irq_save(flags);
  1883. ver = apic_read(APIC_LVR);
  1884. ver = GET_APIC_VERSION(ver);
  1885. /*
  1886. * get/set the timer IRQ vector:
  1887. */
  1888. disable_8259A_irq(0);
  1889. assign_irq_vector(0, TARGET_CPUS);
  1890. /*
  1891. * As IRQ0 is to be enabled in the 8259A, the virtual
  1892. * wire has to be disabled in the local APIC. Also
  1893. * timer interrupts need to be acknowledged manually in
  1894. * the 8259A for the i82489DX when using the NMI
  1895. * watchdog as that APIC treats NMIs as level-triggered.
  1896. * The AEOI mode will finish them in the 8259A
  1897. * automatically.
  1898. */
  1899. apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
  1900. init_8259A(1);
  1901. timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver));
  1902. pin1 = find_isa_irq_pin(0, mp_INT);
  1903. apic1 = find_isa_irq_apic(0, mp_INT);
  1904. pin2 = ioapic_i8259.pin;
  1905. apic2 = ioapic_i8259.apic;
  1906. apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X "
  1907. "apic1=%d pin1=%d apic2=%d pin2=%d\n",
  1908. cfg->vector, apic1, pin1, apic2, pin2);
  1909. /*
  1910. * Some BIOS writers are clueless and report the ExtINTA
  1911. * I/O APIC input from the cascaded 8259A as the timer
  1912. * interrupt input. So just in case, if only one pin
  1913. * was found above, try it both directly and through the
  1914. * 8259A.
  1915. */
  1916. if (pin1 == -1) {
  1917. pin1 = pin2;
  1918. apic1 = apic2;
  1919. no_pin1 = 1;
  1920. } else if (pin2 == -1) {
  1921. pin2 = pin1;
  1922. apic2 = apic1;
  1923. }
  1924. if (pin1 != -1) {
  1925. /*
  1926. * Ok, does IRQ0 through the IOAPIC work?
  1927. */
  1928. if (no_pin1) {
  1929. add_pin_to_irq(0, apic1, pin1);
  1930. setup_timer_IRQ0_pin(apic1, pin1, cfg->vector);
  1931. }
  1932. unmask_IO_APIC_irq(0);
  1933. if (timer_irq_works()) {
  1934. if (nmi_watchdog == NMI_IO_APIC) {
  1935. setup_nmi();
  1936. enable_8259A_irq(0);
  1937. }
  1938. if (disable_timer_pin_1 > 0)
  1939. clear_IO_APIC_pin(0, pin1);
  1940. goto out;
  1941. }
  1942. clear_IO_APIC_pin(apic1, pin1);
  1943. if (!no_pin1)
  1944. apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: "
  1945. "8254 timer not connected to IO-APIC\n");
  1946. apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer "
  1947. "(IRQ0) through the 8259A ...\n");
  1948. apic_printk(APIC_QUIET, KERN_INFO
  1949. "..... (found apic %d pin %d) ...\n", apic2, pin2);
  1950. /*
  1951. * legacy devices should be connected to IO APIC #0
  1952. */
  1953. replace_pin_at_irq(0, apic1, pin1, apic2, pin2);
  1954. setup_timer_IRQ0_pin(apic2, pin2, cfg->vector);
  1955. unmask_IO_APIC_irq(0);
  1956. enable_8259A_irq(0);
  1957. if (timer_irq_works()) {
  1958. apic_printk(APIC_QUIET, KERN_INFO "....... works.\n");
  1959. timer_through_8259 = 1;
  1960. if (nmi_watchdog == NMI_IO_APIC) {
  1961. disable_8259A_irq(0);
  1962. setup_nmi();
  1963. enable_8259A_irq(0);
  1964. }
  1965. goto out;
  1966. }
  1967. /*
  1968. * Cleanup, just in case ...
  1969. */
  1970. disable_8259A_irq(0);
  1971. clear_IO_APIC_pin(apic2, pin2);
  1972. apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n");
  1973. }
  1974. if (nmi_watchdog == NMI_IO_APIC) {
  1975. apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work "
  1976. "through the IO-APIC - disabling NMI Watchdog!\n");
  1977. nmi_watchdog = NMI_NONE;
  1978. }
  1979. timer_ack = 0;
  1980. apic_printk(APIC_QUIET, KERN_INFO
  1981. "...trying to set up timer as Virtual Wire IRQ...\n");
  1982. lapic_register_intr(0);
  1983. apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */
  1984. enable_8259A_irq(0);
  1985. if (timer_irq_works()) {
  1986. apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
  1987. goto out;
  1988. }
  1989. disable_8259A_irq(0);
  1990. apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector);
  1991. apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n");
  1992. apic_printk(APIC_QUIET, KERN_INFO
  1993. "...trying to set up timer as ExtINT IRQ...\n");
  1994. init_8259A(0);
  1995. make_8259A_irq(0);
  1996. apic_write(APIC_LVT0, APIC_DM_EXTINT);
  1997. unlock_ExtINT_logic();
  1998. if (timer_irq_works()) {
  1999. apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
  2000. goto out;
  2001. }
  2002. apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n");
  2003. panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
  2004. "report. Then try booting with the 'noapic' option.\n");
  2005. out:
  2006. local_irq_restore(flags);
  2007. }
  2008. /*
  2009. * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
  2010. * to devices. However there may be an I/O APIC pin available for
  2011. * this interrupt regardless. The pin may be left unconnected, but
  2012. * typically it will be reused as an ExtINT cascade interrupt for
  2013. * the master 8259A. In the MPS case such a pin will normally be
  2014. * reported as an ExtINT interrupt in the MP table. With ACPI
  2015. * there is no provision for ExtINT interrupts, and in the absence
  2016. * of an override it would be treated as an ordinary ISA I/O APIC
  2017. * interrupt, that is edge-triggered and unmasked by default. We
  2018. * used to do this, but it caused problems on some systems because
  2019. * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
  2020. * the same ExtINT cascade interrupt to drive the local APIC of the
  2021. * bootstrap processor. Therefore we refrain from routing IRQ2 to
  2022. * the I/O APIC in all cases now. No actual device should request
  2023. * it anyway. --macro
  2024. */
  2025. #define PIC_IRQS (1 << PIC_CASCADE_IR)
  2026. void __init setup_IO_APIC(void)
  2027. {
  2028. enable_IO_APIC();
  2029. io_apic_irqs = ~PIC_IRQS;
  2030. printk("ENABLING IO-APIC IRQs\n");
  2031. /*
  2032. * Set up IO-APIC IRQ routing.
  2033. */
  2034. if (!acpi_ioapic)
  2035. setup_ioapic_ids_from_mpc();
  2036. sync_Arb_IDs();
  2037. setup_IO_APIC_irqs();
  2038. init_IO_APIC_traps();
  2039. check_timer();
  2040. }
  2041. /*
  2042. * Called after all the initialization is done. If we didnt find any
  2043. * APIC bugs then we can allow the modify fast path
  2044. */
  2045. static int __init io_apic_bug_finalize(void)
  2046. {
  2047. if (sis_apic_bug == -1)
  2048. sis_apic_bug = 0;
  2049. return 0;
  2050. }
  2051. late_initcall(io_apic_bug_finalize);
  2052. struct sysfs_ioapic_data {
  2053. struct sys_device dev;
  2054. struct IO_APIC_route_entry entry[0];
  2055. };
  2056. static struct sysfs_ioapic_data *mp_ioapic_data[MAX_IO_APICS];
  2057. static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
  2058. {
  2059. struct IO_APIC_route_entry *entry;
  2060. struct sysfs_ioapic_data *data;
  2061. int i;
  2062. data = container_of(dev, struct sysfs_ioapic_data, dev);
  2063. entry = data->entry;
  2064. for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
  2065. entry[i] = ioapic_read_entry(dev->id, i);
  2066. return 0;
  2067. }
  2068. static int ioapic_resume(struct sys_device *dev)
  2069. {
  2070. struct IO_APIC_route_entry *entry;
  2071. struct sysfs_ioapic_data *data;
  2072. unsigned long flags;
  2073. union IO_APIC_reg_00 reg_00;
  2074. int i;
  2075. data = container_of(dev, struct sysfs_ioapic_data, dev);
  2076. entry = data->entry;
  2077. spin_lock_irqsave(&ioapic_lock, flags);
  2078. reg_00.raw = io_apic_read(dev->id, 0);
  2079. if (reg_00.bits.ID != mp_ioapics[dev->id].mp_apicid) {
  2080. reg_00.bits.ID = mp_ioapics[dev->id].mp_apicid;
  2081. io_apic_write(dev->id, 0, reg_00.raw);
  2082. }
  2083. spin_unlock_irqrestore(&ioapic_lock, flags);
  2084. for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
  2085. ioapic_write_entry(dev->id, i, entry[i]);
  2086. return 0;
  2087. }
  2088. static struct sysdev_class ioapic_sysdev_class = {
  2089. .name = "ioapic",
  2090. .suspend = ioapic_suspend,
  2091. .resume = ioapic_resume,
  2092. };
  2093. static int __init ioapic_init_sysfs(void)
  2094. {
  2095. struct sys_device *dev;
  2096. int i, size, error = 0;
  2097. error = sysdev_class_register(&ioapic_sysdev_class);
  2098. if (error)
  2099. return error;
  2100. for (i = 0; i < nr_ioapics; i++) {
  2101. size = sizeof(struct sys_device) + nr_ioapic_registers[i]
  2102. * sizeof(struct IO_APIC_route_entry);
  2103. mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL);
  2104. if (!mp_ioapic_data[i]) {
  2105. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  2106. continue;
  2107. }
  2108. dev = &mp_ioapic_data[i]->dev;
  2109. dev->id = i;
  2110. dev->cls = &ioapic_sysdev_class;
  2111. error = sysdev_register(dev);
  2112. if (error) {
  2113. kfree(mp_ioapic_data[i]);
  2114. mp_ioapic_data[i] = NULL;
  2115. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  2116. continue;
  2117. }
  2118. }
  2119. return 0;
  2120. }
  2121. device_initcall(ioapic_init_sysfs);
  2122. /*
  2123. * Dynamic irq allocate and deallocation
  2124. */
  2125. unsigned int create_irq_nr(unsigned int irq_want)
  2126. {
  2127. /* Allocate an unused irq */
  2128. unsigned int irq, new;
  2129. unsigned long flags;
  2130. struct irq_cfg *cfg_new;
  2131. #ifndef CONFIG_HAVE_SPARSE_IRQ
  2132. /* only can use bus/dev/fn.. when per_cpu vector is used */
  2133. irq_want = nr_irqs - 1;
  2134. #endif
  2135. irq = 0;
  2136. spin_lock_irqsave(&vector_lock, flags);
  2137. for (new = (nr_irqs - 1); new > 0; new--) {
  2138. if (platform_legacy_irq(new))
  2139. continue;
  2140. cfg_new = irq_cfg(new);
  2141. if (cfg_new && cfg_new->vector != 0)
  2142. continue;
  2143. if (!cfg_new)
  2144. cfg_new = irq_cfg_alloc(new);
  2145. if (__assign_irq_vector(new, TARGET_CPUS) == 0)
  2146. irq = new;
  2147. break;
  2148. }
  2149. spin_unlock_irqrestore(&vector_lock, flags);
  2150. if (irq > 0) {
  2151. dynamic_irq_init(irq);
  2152. }
  2153. return irq;
  2154. }
  2155. int create_irq(void)
  2156. {
  2157. return create_irq_nr(nr_irqs - 1);
  2158. }
  2159. void destroy_irq(unsigned int irq)
  2160. {
  2161. unsigned long flags;
  2162. dynamic_irq_cleanup(irq);
  2163. spin_lock_irqsave(&vector_lock, flags);
  2164. __clear_irq_vector(irq);
  2165. spin_unlock_irqrestore(&vector_lock, flags);
  2166. }
  2167. /*
  2168. * MSI message composition
  2169. */
  2170. #ifdef CONFIG_PCI_MSI
  2171. static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_msg *msg)
  2172. {
  2173. struct irq_cfg *cfg;
  2174. int err;
  2175. unsigned dest;
  2176. cpumask_t tmp;
  2177. tmp = TARGET_CPUS;
  2178. err = assign_irq_vector(irq, tmp);
  2179. if (err)
  2180. return err;
  2181. cfg = irq_cfg(irq);
  2182. cpus_and(tmp, cfg->domain, tmp);
  2183. dest = cpu_mask_to_apicid(tmp);
  2184. msg->address_hi = MSI_ADDR_BASE_HI;
  2185. msg->address_lo =
  2186. MSI_ADDR_BASE_LO |
  2187. ((INT_DEST_MODE == 0) ?
  2188. MSI_ADDR_DEST_MODE_PHYSICAL:
  2189. MSI_ADDR_DEST_MODE_LOGICAL) |
  2190. ((INT_DELIVERY_MODE != dest_LowestPrio) ?
  2191. MSI_ADDR_REDIRECTION_CPU:
  2192. MSI_ADDR_REDIRECTION_LOWPRI) |
  2193. MSI_ADDR_DEST_ID(dest);
  2194. msg->data =
  2195. MSI_DATA_TRIGGER_EDGE |
  2196. MSI_DATA_LEVEL_ASSERT |
  2197. ((INT_DELIVERY_MODE != dest_LowestPrio) ?
  2198. MSI_DATA_DELIVERY_FIXED:
  2199. MSI_DATA_DELIVERY_LOWPRI) |
  2200. MSI_DATA_VECTOR(cfg->vector);
  2201. return err;
  2202. }
  2203. #ifdef CONFIG_SMP
  2204. static void set_msi_irq_affinity(unsigned int irq, cpumask_t mask)
  2205. {
  2206. struct irq_cfg *cfg;
  2207. struct msi_msg msg;
  2208. unsigned int dest;
  2209. cpumask_t tmp;
  2210. cpus_and(tmp, mask, cpu_online_map);
  2211. if (cpus_empty(tmp))
  2212. return;
  2213. if (assign_irq_vector(irq, mask))
  2214. return;
  2215. cfg = irq_cfg(irq);
  2216. cpus_and(tmp, cfg->domain, mask);
  2217. dest = cpu_mask_to_apicid(tmp);
  2218. read_msi_msg(irq, &msg);
  2219. msg.data &= ~MSI_DATA_VECTOR_MASK;
  2220. msg.data |= MSI_DATA_VECTOR(cfg->vector);
  2221. msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
  2222. msg.address_lo |= MSI_ADDR_DEST_ID(dest);
  2223. write_msi_msg(irq, &msg);
  2224. irq_to_desc(irq)->affinity = mask;
  2225. }
  2226. #endif /* CONFIG_SMP */
  2227. /*
  2228. * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
  2229. * which implement the MSI or MSI-X Capability Structure.
  2230. */
  2231. static struct irq_chip msi_chip = {
  2232. .name = "PCI-MSI",
  2233. .unmask = unmask_msi_irq,
  2234. .mask = mask_msi_irq,
  2235. .ack = ack_ioapic_irq,
  2236. #ifdef CONFIG_SMP
  2237. .set_affinity = set_msi_irq_affinity,
  2238. #endif
  2239. .retrigger = ioapic_retrigger_irq,
  2240. };
  2241. static unsigned int build_irq_for_pci_dev(struct pci_dev *dev)
  2242. {
  2243. unsigned int irq;
  2244. irq = dev->bus->number;
  2245. irq <<= 8;
  2246. irq |= dev->devfn;
  2247. irq <<= 12;
  2248. return irq;
  2249. }
  2250. int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)
  2251. {
  2252. struct msi_msg msg;
  2253. int irq, ret;
  2254. unsigned int irq_want;
  2255. irq_want = build_irq_for_pci_dev(dev) + 0x100;
  2256. irq = create_irq_nr(irq_want);
  2257. if (irq == 0)
  2258. return -1;
  2259. ret = msi_compose_msg(dev, irq, &msg);
  2260. if (ret < 0) {
  2261. destroy_irq(irq);
  2262. return ret;
  2263. }
  2264. set_irq_msi(irq, desc);
  2265. write_msi_msg(irq, &msg);
  2266. set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq,
  2267. "edge");
  2268. return 0;
  2269. }
  2270. void arch_teardown_msi_irq(unsigned int irq)
  2271. {
  2272. destroy_irq(irq);
  2273. }
  2274. #endif /* CONFIG_PCI_MSI */
  2275. /*
  2276. * Hypertransport interrupt support
  2277. */
  2278. #ifdef CONFIG_HT_IRQ
  2279. #ifdef CONFIG_SMP
  2280. static void target_ht_irq(unsigned int irq, unsigned int dest, u8 vector)
  2281. {
  2282. struct ht_irq_msg msg;
  2283. fetch_ht_irq_msg(irq, &msg);
  2284. msg.address_lo &= ~(HT_IRQ_LOW_VECTOR_MASK | HT_IRQ_LOW_DEST_ID_MASK);
  2285. msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK);
  2286. msg.address_lo |= HT_IRQ_LOW_VECTOR(vector) | HT_IRQ_LOW_DEST_ID(dest);
  2287. msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest);
  2288. write_ht_irq_msg(irq, &msg);
  2289. }
  2290. static void set_ht_irq_affinity(unsigned int irq, cpumask_t mask)
  2291. {
  2292. struct irq_cfg *cfg;
  2293. unsigned int dest;
  2294. cpumask_t tmp;
  2295. cpus_and(tmp, mask, cpu_online_map);
  2296. if (cpus_empty(tmp))
  2297. return;
  2298. if (assign_irq_vector(irq, mask))
  2299. return;
  2300. cfg = irq_cfg(irq);
  2301. cpus_and(tmp, cfg->domain, mask);
  2302. dest = cpu_mask_to_apicid(tmp);
  2303. target_ht_irq(irq, dest, cfg->vector);
  2304. irq_to_desc(irq)->affinity = mask;
  2305. }
  2306. #endif
  2307. static struct irq_chip ht_irq_chip = {
  2308. .name = "PCI-HT",
  2309. .mask = mask_ht_irq,
  2310. .unmask = unmask_ht_irq,
  2311. .ack = ack_ioapic_irq,
  2312. #ifdef CONFIG_SMP
  2313. .set_affinity = set_ht_irq_affinity,
  2314. #endif
  2315. .retrigger = ioapic_retrigger_irq,
  2316. };
  2317. int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
  2318. {
  2319. struct irq_cfg *cfg;
  2320. int err;
  2321. cpumask_t tmp;
  2322. tmp = TARGET_CPUS;
  2323. err = assign_irq_vector(irq, tmp);
  2324. if ( !err) {
  2325. struct ht_irq_msg msg;
  2326. unsigned dest;
  2327. cfg = irq_cfg(irq);
  2328. cpus_and(tmp, cfg->domain, tmp);
  2329. dest = cpu_mask_to_apicid(tmp);
  2330. msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest);
  2331. msg.address_lo =
  2332. HT_IRQ_LOW_BASE |
  2333. HT_IRQ_LOW_DEST_ID(dest) |
  2334. HT_IRQ_LOW_VECTOR(cfg->vector) |
  2335. ((INT_DEST_MODE == 0) ?
  2336. HT_IRQ_LOW_DM_PHYSICAL :
  2337. HT_IRQ_LOW_DM_LOGICAL) |
  2338. HT_IRQ_LOW_RQEOI_EDGE |
  2339. ((INT_DELIVERY_MODE != dest_LowestPrio) ?
  2340. HT_IRQ_LOW_MT_FIXED :
  2341. HT_IRQ_LOW_MT_ARBITRATED) |
  2342. HT_IRQ_LOW_IRQ_MASKED;
  2343. write_ht_irq_msg(irq, &msg);
  2344. set_irq_chip_and_handler_name(irq, &ht_irq_chip,
  2345. handle_edge_irq, "edge");
  2346. }
  2347. return err;
  2348. }
  2349. #endif /* CONFIG_HT_IRQ */
  2350. /* --------------------------------------------------------------------------
  2351. ACPI-based IOAPIC Configuration
  2352. -------------------------------------------------------------------------- */
  2353. #ifdef CONFIG_ACPI
  2354. int __init io_apic_get_unique_id(int ioapic, int apic_id)
  2355. {
  2356. union IO_APIC_reg_00 reg_00;
  2357. static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
  2358. physid_mask_t tmp;
  2359. unsigned long flags;
  2360. int i = 0;
  2361. /*
  2362. * The P4 platform supports up to 256 APIC IDs on two separate APIC
  2363. * buses (one for LAPICs, one for IOAPICs), where predecessors only
  2364. * supports up to 16 on one shared APIC bus.
  2365. *
  2366. * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
  2367. * advantage of new APIC bus architecture.
  2368. */
  2369. if (physids_empty(apic_id_map))
  2370. apic_id_map = ioapic_phys_id_map(phys_cpu_present_map);
  2371. spin_lock_irqsave(&ioapic_lock, flags);
  2372. reg_00.raw = io_apic_read(ioapic, 0);
  2373. spin_unlock_irqrestore(&ioapic_lock, flags);
  2374. if (apic_id >= get_physical_broadcast()) {
  2375. printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
  2376. "%d\n", ioapic, apic_id, reg_00.bits.ID);
  2377. apic_id = reg_00.bits.ID;
  2378. }
  2379. /*
  2380. * Every APIC in a system must have a unique ID or we get lots of nice
  2381. * 'stuck on smp_invalidate_needed IPI wait' messages.
  2382. */
  2383. if (check_apicid_used(apic_id_map, apic_id)) {
  2384. for (i = 0; i < get_physical_broadcast(); i++) {
  2385. if (!check_apicid_used(apic_id_map, i))
  2386. break;
  2387. }
  2388. if (i == get_physical_broadcast())
  2389. panic("Max apic_id exceeded!\n");
  2390. printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
  2391. "trying %d\n", ioapic, apic_id, i);
  2392. apic_id = i;
  2393. }
  2394. tmp = apicid_to_cpu_present(apic_id);
  2395. physids_or(apic_id_map, apic_id_map, tmp);
  2396. if (reg_00.bits.ID != apic_id) {
  2397. reg_00.bits.ID = apic_id;
  2398. spin_lock_irqsave(&ioapic_lock, flags);
  2399. io_apic_write(ioapic, 0, reg_00.raw);
  2400. reg_00.raw = io_apic_read(ioapic, 0);
  2401. spin_unlock_irqrestore(&ioapic_lock, flags);
  2402. /* Sanity check */
  2403. if (reg_00.bits.ID != apic_id) {
  2404. printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic);
  2405. return -1;
  2406. }
  2407. }
  2408. apic_printk(APIC_VERBOSE, KERN_INFO
  2409. "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
  2410. return apic_id;
  2411. }
  2412. int __init io_apic_get_version(int ioapic)
  2413. {
  2414. union IO_APIC_reg_01 reg_01;
  2415. unsigned long flags;
  2416. spin_lock_irqsave(&ioapic_lock, flags);
  2417. reg_01.raw = io_apic_read(ioapic, 1);
  2418. spin_unlock_irqrestore(&ioapic_lock, flags);
  2419. return reg_01.bits.version;
  2420. }
  2421. int __init io_apic_get_redir_entries(int ioapic)
  2422. {
  2423. union IO_APIC_reg_01 reg_01;
  2424. unsigned long flags;
  2425. spin_lock_irqsave(&ioapic_lock, flags);
  2426. reg_01.raw = io_apic_read(ioapic, 1);
  2427. spin_unlock_irqrestore(&ioapic_lock, flags);
  2428. return reg_01.bits.entries;
  2429. }
  2430. int io_apic_set_pci_routing(int ioapic, int pin, int irq, int triggering, int polarity)
  2431. {
  2432. if (!IO_APIC_IRQ(irq)) {
  2433. printk(KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
  2434. ioapic);
  2435. return -EINVAL;
  2436. }
  2437. /*
  2438. * IRQs < 16 are already in the irq_2_pin[] map
  2439. */
  2440. if (irq >= 16)
  2441. add_pin_to_irq(irq, ioapic, pin);
  2442. setup_IO_APIC_irq(ioapic, pin, irq, triggering, polarity);
  2443. return 0;
  2444. }
  2445. int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity)
  2446. {
  2447. int i;
  2448. if (skip_ioapic_setup)
  2449. return -1;
  2450. for (i = 0; i < mp_irq_entries; i++)
  2451. if (mp_irqs[i].mp_irqtype == mp_INT &&
  2452. mp_irqs[i].mp_srcbusirq == bus_irq)
  2453. break;
  2454. if (i >= mp_irq_entries)
  2455. return -1;
  2456. *trigger = irq_trigger(i);
  2457. *polarity = irq_polarity(i);
  2458. return 0;
  2459. }
  2460. #endif /* CONFIG_ACPI */
  2461. /*
  2462. * This function currently is only a helper for the i386 smp boot process where
  2463. * we need to reprogram the ioredtbls to cater for the cpus which have come online
  2464. * so mask in all cases should simply be TARGET_CPUS
  2465. */
  2466. #ifdef CONFIG_SMP
  2467. void __init setup_ioapic_dest(void)
  2468. {
  2469. int pin, ioapic, irq, irq_entry;
  2470. struct irq_cfg *cfg;
  2471. struct irq_desc *desc;
  2472. if (skip_ioapic_setup == 1)
  2473. return;
  2474. for (ioapic = 0; ioapic < nr_ioapics; ioapic++) {
  2475. for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
  2476. irq_entry = find_irq_entry(ioapic, pin, mp_INT);
  2477. if (irq_entry == -1)
  2478. continue;
  2479. irq = pin_2_irq(irq_entry, ioapic, pin);
  2480. /* setup_IO_APIC_irqs could fail to get vector for some device
  2481. * when you have too many devices, because at that time only boot
  2482. * cpu is online.
  2483. */
  2484. cfg = irq_cfg(irq);
  2485. if (!cfg->vector)
  2486. setup_IO_APIC_irq(ioapic, pin, irq,
  2487. irq_trigger(irq_entry),
  2488. irq_polarity(irq_entry));
  2489. else {
  2490. desc = irq_to_desc(irq);
  2491. set_ioapic_affinity_irq(irq, TARGET_CPUS);
  2492. }
  2493. }
  2494. }
  2495. }
  2496. #endif
  2497. static int __init parse_disable_timer_pin_1(char *arg)
  2498. {
  2499. disable_timer_pin_1 = 1;
  2500. return 0;
  2501. }
  2502. early_param("disable_timer_pin_1", parse_disable_timer_pin_1);
  2503. static int __init parse_enable_timer_pin_1(char *arg)
  2504. {
  2505. disable_timer_pin_1 = -1;
  2506. return 0;
  2507. }
  2508. early_param("enable_timer_pin_1", parse_enable_timer_pin_1);
  2509. static int __init parse_noapic(char *arg)
  2510. {
  2511. /* disable IO-APIC */
  2512. disable_ioapic_setup();
  2513. return 0;
  2514. }
  2515. early_param("noapic", parse_noapic);
  2516. void __init ioapic_init_mappings(void)
  2517. {
  2518. unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
  2519. int i;
  2520. for (i = 0; i < nr_ioapics; i++) {
  2521. if (smp_found_config) {
  2522. ioapic_phys = mp_ioapics[i].mp_apicaddr;
  2523. if (!ioapic_phys) {
  2524. printk(KERN_ERR
  2525. "WARNING: bogus zero IO-APIC "
  2526. "address found in MPTABLE, "
  2527. "disabling IO/APIC support!\n");
  2528. smp_found_config = 0;
  2529. skip_ioapic_setup = 1;
  2530. goto fake_ioapic_page;
  2531. }
  2532. } else {
  2533. fake_ioapic_page:
  2534. ioapic_phys = (unsigned long)
  2535. alloc_bootmem_pages(PAGE_SIZE);
  2536. ioapic_phys = __pa(ioapic_phys);
  2537. }
  2538. set_fixmap_nocache(idx, ioapic_phys);
  2539. printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n",
  2540. __fix_to_virt(idx), ioapic_phys);
  2541. idx++;
  2542. }
  2543. }