io_apic.c 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287
  1. /*
  2. * Intel IO-APIC support for multi-Pentium hosts.
  3. *
  4. * Copyright (C) 1997, 1998, 1999, 2000, 2009 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/pci.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/msi.h>
  34. #include <linux/htirq.h>
  35. #include <linux/freezer.h>
  36. #include <linux/kthread.h>
  37. #include <linux/jiffies.h> /* time_after() */
  38. #include <linux/slab.h>
  39. #ifdef CONFIG_ACPI
  40. #include <acpi/acpi_bus.h>
  41. #endif
  42. #include <linux/bootmem.h>
  43. #include <linux/dmar.h>
  44. #include <linux/hpet.h>
  45. #include <asm/idle.h>
  46. #include <asm/io.h>
  47. #include <asm/smp.h>
  48. #include <asm/cpu.h>
  49. #include <asm/desc.h>
  50. #include <asm/proto.h>
  51. #include <asm/acpi.h>
  52. #include <asm/dma.h>
  53. #include <asm/timer.h>
  54. #include <asm/i8259.h>
  55. #include <asm/nmi.h>
  56. #include <asm/msidef.h>
  57. #include <asm/hypertransport.h>
  58. #include <asm/setup.h>
  59. #include <asm/irq_remapping.h>
  60. #include <asm/hpet.h>
  61. #include <asm/hw_irq.h>
  62. #include <asm/apic.h>
  63. #define __apicdebuginit(type) static type __init
  64. #define for_each_irq_pin(entry, head) \
  65. for (entry = head; entry; entry = entry->next)
  66. /*
  67. * Is the SiS APIC rmw bug present ?
  68. * -1 = don't know, 0 = no, 1 = yes
  69. */
  70. int sis_apic_bug = -1;
  71. static DEFINE_RAW_SPINLOCK(ioapic_lock);
  72. static DEFINE_RAW_SPINLOCK(vector_lock);
  73. /*
  74. * # of IRQ routing registers
  75. */
  76. int nr_ioapic_registers[MAX_IO_APICS];
  77. /* I/O APIC entries */
  78. struct mpc_ioapic mp_ioapics[MAX_IO_APICS];
  79. int nr_ioapics;
  80. /* IO APIC gsi routing info */
  81. struct mp_ioapic_gsi mp_gsi_routing[MAX_IO_APICS];
  82. /* The one past the highest gsi number used */
  83. u32 gsi_top;
  84. /* MP IRQ source entries */
  85. struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES];
  86. /* # of MP IRQ source entries */
  87. int mp_irq_entries;
  88. /* GSI interrupts */
  89. static int nr_irqs_gsi = NR_IRQS_LEGACY;
  90. #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
  91. int mp_bus_id_to_type[MAX_MP_BUSSES];
  92. #endif
  93. DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
  94. int skip_ioapic_setup;
  95. void arch_disable_smp_support(void)
  96. {
  97. #ifdef CONFIG_PCI
  98. noioapicquirk = 1;
  99. noioapicreroute = -1;
  100. #endif
  101. skip_ioapic_setup = 1;
  102. }
  103. static int __init parse_noapic(char *str)
  104. {
  105. /* disable IO-APIC */
  106. arch_disable_smp_support();
  107. return 0;
  108. }
  109. early_param("noapic", parse_noapic);
  110. struct irq_pin_list {
  111. int apic, pin;
  112. struct irq_pin_list *next;
  113. };
  114. static struct irq_pin_list *get_one_free_irq_2_pin(int node)
  115. {
  116. struct irq_pin_list *pin;
  117. pin = kzalloc_node(sizeof(*pin), GFP_ATOMIC, node);
  118. return pin;
  119. }
  120. /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
  121. #ifdef CONFIG_SPARSE_IRQ
  122. static struct irq_cfg irq_cfgx[NR_IRQS_LEGACY];
  123. #else
  124. static struct irq_cfg irq_cfgx[NR_IRQS];
  125. #endif
  126. int __init arch_early_irq_init(void)
  127. {
  128. struct irq_cfg *cfg;
  129. struct irq_desc *desc;
  130. int count;
  131. int node;
  132. int i;
  133. if (!legacy_pic->nr_legacy_irqs) {
  134. nr_irqs_gsi = 0;
  135. io_apic_irqs = ~0UL;
  136. }
  137. cfg = irq_cfgx;
  138. count = ARRAY_SIZE(irq_cfgx);
  139. node = cpu_to_node(0);
  140. for (i = 0; i < count; i++) {
  141. desc = irq_to_desc(i);
  142. desc->chip_data = &cfg[i];
  143. zalloc_cpumask_var_node(&cfg[i].domain, GFP_NOWAIT, node);
  144. zalloc_cpumask_var_node(&cfg[i].old_domain, GFP_NOWAIT, node);
  145. /*
  146. * For legacy IRQ's, start with assigning irq0 to irq15 to
  147. * IRQ0_VECTOR to IRQ15_VECTOR on cpu 0.
  148. */
  149. if (i < legacy_pic->nr_legacy_irqs) {
  150. cfg[i].vector = IRQ0_VECTOR + i;
  151. cpumask_set_cpu(0, cfg[i].domain);
  152. }
  153. }
  154. return 0;
  155. }
  156. #ifdef CONFIG_SPARSE_IRQ
  157. struct irq_cfg *irq_cfg(unsigned int irq)
  158. {
  159. struct irq_cfg *cfg = NULL;
  160. struct irq_desc *desc;
  161. desc = irq_to_desc(irq);
  162. if (desc)
  163. cfg = get_irq_desc_chip_data(desc);
  164. return cfg;
  165. }
  166. static struct irq_cfg *get_one_free_irq_cfg(int node)
  167. {
  168. struct irq_cfg *cfg;
  169. cfg = kzalloc_node(sizeof(*cfg), GFP_ATOMIC, node);
  170. if (cfg) {
  171. if (!zalloc_cpumask_var_node(&cfg->domain, GFP_ATOMIC, node)) {
  172. kfree(cfg);
  173. cfg = NULL;
  174. } else if (!zalloc_cpumask_var_node(&cfg->old_domain,
  175. GFP_ATOMIC, node)) {
  176. free_cpumask_var(cfg->domain);
  177. kfree(cfg);
  178. cfg = NULL;
  179. }
  180. }
  181. return cfg;
  182. }
  183. int arch_init_chip_data(struct irq_desc *desc, int node)
  184. {
  185. struct irq_cfg *cfg;
  186. cfg = get_irq_desc_chip_data(desc);
  187. if (!cfg) {
  188. cfg = get_one_free_irq_cfg(node);
  189. desc->chip_data = cfg;
  190. if (!cfg) {
  191. printk(KERN_ERR "can not alloc irq_cfg\n");
  192. BUG_ON(1);
  193. }
  194. }
  195. return 0;
  196. }
  197. /* for move_irq_desc */
  198. static void
  199. init_copy_irq_2_pin(struct irq_cfg *old_cfg, struct irq_cfg *cfg, int node)
  200. {
  201. struct irq_pin_list *old_entry, *head, *tail, *entry;
  202. cfg->irq_2_pin = NULL;
  203. old_entry = old_cfg->irq_2_pin;
  204. if (!old_entry)
  205. return;
  206. entry = get_one_free_irq_2_pin(node);
  207. if (!entry)
  208. return;
  209. entry->apic = old_entry->apic;
  210. entry->pin = old_entry->pin;
  211. head = entry;
  212. tail = entry;
  213. old_entry = old_entry->next;
  214. while (old_entry) {
  215. entry = get_one_free_irq_2_pin(node);
  216. if (!entry) {
  217. entry = head;
  218. while (entry) {
  219. head = entry->next;
  220. kfree(entry);
  221. entry = head;
  222. }
  223. /* still use the old one */
  224. return;
  225. }
  226. entry->apic = old_entry->apic;
  227. entry->pin = old_entry->pin;
  228. tail->next = entry;
  229. tail = entry;
  230. old_entry = old_entry->next;
  231. }
  232. tail->next = NULL;
  233. cfg->irq_2_pin = head;
  234. }
  235. static void free_irq_2_pin(struct irq_cfg *old_cfg, struct irq_cfg *cfg)
  236. {
  237. struct irq_pin_list *entry, *next;
  238. if (old_cfg->irq_2_pin == cfg->irq_2_pin)
  239. return;
  240. entry = old_cfg->irq_2_pin;
  241. while (entry) {
  242. next = entry->next;
  243. kfree(entry);
  244. entry = next;
  245. }
  246. old_cfg->irq_2_pin = NULL;
  247. }
  248. void arch_init_copy_chip_data(struct irq_desc *old_desc,
  249. struct irq_desc *desc, int node)
  250. {
  251. struct irq_cfg *cfg;
  252. struct irq_cfg *old_cfg;
  253. cfg = get_one_free_irq_cfg(node);
  254. if (!cfg)
  255. return;
  256. desc->chip_data = cfg;
  257. old_cfg = old_desc->chip_data;
  258. cfg->vector = old_cfg->vector;
  259. cfg->move_in_progress = old_cfg->move_in_progress;
  260. cpumask_copy(cfg->domain, old_cfg->domain);
  261. cpumask_copy(cfg->old_domain, old_cfg->old_domain);
  262. init_copy_irq_2_pin(old_cfg, cfg, node);
  263. }
  264. static void free_irq_cfg(struct irq_cfg *cfg)
  265. {
  266. free_cpumask_var(cfg->domain);
  267. free_cpumask_var(cfg->old_domain);
  268. kfree(cfg);
  269. }
  270. void arch_free_chip_data(struct irq_desc *old_desc, struct irq_desc *desc)
  271. {
  272. struct irq_cfg *old_cfg, *cfg;
  273. old_cfg = get_irq_desc_chip_data(old_desc);
  274. cfg = get_irq_desc_chip_data(desc);
  275. if (old_cfg == cfg)
  276. return;
  277. if (old_cfg) {
  278. free_irq_2_pin(old_cfg, cfg);
  279. free_irq_cfg(old_cfg);
  280. old_desc->chip_data = NULL;
  281. }
  282. }
  283. /* end for move_irq_desc */
  284. #else
  285. struct irq_cfg *irq_cfg(unsigned int irq)
  286. {
  287. return irq < nr_irqs ? irq_cfgx + irq : NULL;
  288. }
  289. #endif
  290. struct io_apic {
  291. unsigned int index;
  292. unsigned int unused[3];
  293. unsigned int data;
  294. unsigned int unused2[11];
  295. unsigned int eoi;
  296. };
  297. static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
  298. {
  299. return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx)
  300. + (mp_ioapics[idx].apicaddr & ~PAGE_MASK);
  301. }
  302. static inline void io_apic_eoi(unsigned int apic, unsigned int vector)
  303. {
  304. struct io_apic __iomem *io_apic = io_apic_base(apic);
  305. writel(vector, &io_apic->eoi);
  306. }
  307. static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
  308. {
  309. struct io_apic __iomem *io_apic = io_apic_base(apic);
  310. writel(reg, &io_apic->index);
  311. return readl(&io_apic->data);
  312. }
  313. static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value)
  314. {
  315. struct io_apic __iomem *io_apic = io_apic_base(apic);
  316. writel(reg, &io_apic->index);
  317. writel(value, &io_apic->data);
  318. }
  319. /*
  320. * Re-write a value: to be used for read-modify-write
  321. * cycles where the read already set up the index register.
  322. *
  323. * Older SiS APIC requires we rewrite the index register
  324. */
  325. static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value)
  326. {
  327. struct io_apic __iomem *io_apic = io_apic_base(apic);
  328. if (sis_apic_bug)
  329. writel(reg, &io_apic->index);
  330. writel(value, &io_apic->data);
  331. }
  332. static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
  333. {
  334. struct irq_pin_list *entry;
  335. unsigned long flags;
  336. raw_spin_lock_irqsave(&ioapic_lock, flags);
  337. for_each_irq_pin(entry, cfg->irq_2_pin) {
  338. unsigned int reg;
  339. int pin;
  340. pin = entry->pin;
  341. reg = io_apic_read(entry->apic, 0x10 + pin*2);
  342. /* Is the remote IRR bit set? */
  343. if (reg & IO_APIC_REDIR_REMOTE_IRR) {
  344. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  345. return true;
  346. }
  347. }
  348. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  349. return false;
  350. }
  351. union entry_union {
  352. struct { u32 w1, w2; };
  353. struct IO_APIC_route_entry entry;
  354. };
  355. static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
  356. {
  357. union entry_union eu;
  358. unsigned long flags;
  359. raw_spin_lock_irqsave(&ioapic_lock, flags);
  360. eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
  361. eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
  362. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  363. return eu.entry;
  364. }
  365. /*
  366. * When we write a new IO APIC routing entry, we need to write the high
  367. * word first! If the mask bit in the low word is clear, we will enable
  368. * the interrupt, and we need to make sure the entry is fully populated
  369. * before that happens.
  370. */
  371. static void
  372. __ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
  373. {
  374. union entry_union eu = {{0, 0}};
  375. eu.entry = e;
  376. io_apic_write(apic, 0x11 + 2*pin, eu.w2);
  377. io_apic_write(apic, 0x10 + 2*pin, eu.w1);
  378. }
  379. void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
  380. {
  381. unsigned long flags;
  382. raw_spin_lock_irqsave(&ioapic_lock, flags);
  383. __ioapic_write_entry(apic, pin, e);
  384. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  385. }
  386. /*
  387. * When we mask an IO APIC routing entry, we need to write the low
  388. * word first, in order to set the mask bit before we change the
  389. * high bits!
  390. */
  391. static void ioapic_mask_entry(int apic, int pin)
  392. {
  393. unsigned long flags;
  394. union entry_union eu = { .entry.mask = 1 };
  395. raw_spin_lock_irqsave(&ioapic_lock, flags);
  396. io_apic_write(apic, 0x10 + 2*pin, eu.w1);
  397. io_apic_write(apic, 0x11 + 2*pin, eu.w2);
  398. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  399. }
  400. /*
  401. * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
  402. * shared ISA-space IRQs, so we have to support them. We are super
  403. * fast in the common case, and fast for shared ISA-space IRQs.
  404. */
  405. static int
  406. add_pin_to_irq_node_nopanic(struct irq_cfg *cfg, int node, int apic, int pin)
  407. {
  408. struct irq_pin_list **last, *entry;
  409. /* don't allow duplicates */
  410. last = &cfg->irq_2_pin;
  411. for_each_irq_pin(entry, cfg->irq_2_pin) {
  412. if (entry->apic == apic && entry->pin == pin)
  413. return 0;
  414. last = &entry->next;
  415. }
  416. entry = get_one_free_irq_2_pin(node);
  417. if (!entry) {
  418. printk(KERN_ERR "can not alloc irq_pin_list (%d,%d,%d)\n",
  419. node, apic, pin);
  420. return -ENOMEM;
  421. }
  422. entry->apic = apic;
  423. entry->pin = pin;
  424. *last = entry;
  425. return 0;
  426. }
  427. static void add_pin_to_irq_node(struct irq_cfg *cfg, int node, int apic, int pin)
  428. {
  429. if (add_pin_to_irq_node_nopanic(cfg, node, apic, pin))
  430. panic("IO-APIC: failed to add irq-pin. Can not proceed\n");
  431. }
  432. /*
  433. * Reroute an IRQ to a different pin.
  434. */
  435. static void __init replace_pin_at_irq_node(struct irq_cfg *cfg, int node,
  436. int oldapic, int oldpin,
  437. int newapic, int newpin)
  438. {
  439. struct irq_pin_list *entry;
  440. for_each_irq_pin(entry, cfg->irq_2_pin) {
  441. if (entry->apic == oldapic && entry->pin == oldpin) {
  442. entry->apic = newapic;
  443. entry->pin = newpin;
  444. /* every one is different, right? */
  445. return;
  446. }
  447. }
  448. /* old apic/pin didn't exist, so just add new ones */
  449. add_pin_to_irq_node(cfg, node, newapic, newpin);
  450. }
  451. static void __io_apic_modify_irq(struct irq_pin_list *entry,
  452. int mask_and, int mask_or,
  453. void (*final)(struct irq_pin_list *entry))
  454. {
  455. unsigned int reg, pin;
  456. pin = entry->pin;
  457. reg = io_apic_read(entry->apic, 0x10 + pin * 2);
  458. reg &= mask_and;
  459. reg |= mask_or;
  460. io_apic_modify(entry->apic, 0x10 + pin * 2, reg);
  461. if (final)
  462. final(entry);
  463. }
  464. static void io_apic_modify_irq(struct irq_cfg *cfg,
  465. int mask_and, int mask_or,
  466. void (*final)(struct irq_pin_list *entry))
  467. {
  468. struct irq_pin_list *entry;
  469. for_each_irq_pin(entry, cfg->irq_2_pin)
  470. __io_apic_modify_irq(entry, mask_and, mask_or, final);
  471. }
  472. static void __mask_and_edge_IO_APIC_irq(struct irq_pin_list *entry)
  473. {
  474. __io_apic_modify_irq(entry, ~IO_APIC_REDIR_LEVEL_TRIGGER,
  475. IO_APIC_REDIR_MASKED, NULL);
  476. }
  477. static void __unmask_and_level_IO_APIC_irq(struct irq_pin_list *entry)
  478. {
  479. __io_apic_modify_irq(entry, ~IO_APIC_REDIR_MASKED,
  480. IO_APIC_REDIR_LEVEL_TRIGGER, NULL);
  481. }
  482. static void io_apic_sync(struct irq_pin_list *entry)
  483. {
  484. /*
  485. * Synchronize the IO-APIC and the CPU by doing
  486. * a dummy read from the IO-APIC
  487. */
  488. struct io_apic __iomem *io_apic;
  489. io_apic = io_apic_base(entry->apic);
  490. readl(&io_apic->data);
  491. }
  492. static void mask_ioapic(struct irq_cfg *cfg)
  493. {
  494. unsigned long flags;
  495. raw_spin_lock_irqsave(&ioapic_lock, flags);
  496. io_apic_modify_irq(cfg, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync);
  497. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  498. }
  499. static void mask_ioapic_irq(unsigned int irq)
  500. {
  501. struct irq_cfg *cfg = get_irq_chip_data(irq);
  502. mask_ioapic(cfg);
  503. }
  504. static void __unmask_ioapic(struct irq_cfg *cfg)
  505. {
  506. io_apic_modify_irq(cfg, ~IO_APIC_REDIR_MASKED, 0, NULL);
  507. }
  508. static void unmask_ioapic(struct irq_cfg *cfg)
  509. {
  510. unsigned long flags;
  511. raw_spin_lock_irqsave(&ioapic_lock, flags);
  512. __unmask_ioapic(cfg);
  513. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  514. }
  515. static void unmask_ioapic_irq(unsigned int irq)
  516. {
  517. struct irq_cfg *cfg = get_irq_chip_data(irq);
  518. unmask_ioapic(cfg);
  519. }
  520. static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
  521. {
  522. struct IO_APIC_route_entry entry;
  523. /* Check delivery_mode to be sure we're not clearing an SMI pin */
  524. entry = ioapic_read_entry(apic, pin);
  525. if (entry.delivery_mode == dest_SMI)
  526. return;
  527. /*
  528. * Disable it in the IO-APIC irq-routing table:
  529. */
  530. ioapic_mask_entry(apic, pin);
  531. }
  532. static void clear_IO_APIC (void)
  533. {
  534. int apic, pin;
  535. for (apic = 0; apic < nr_ioapics; apic++)
  536. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
  537. clear_IO_APIC_pin(apic, pin);
  538. }
  539. #ifdef CONFIG_X86_32
  540. /*
  541. * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
  542. * specific CPU-side IRQs.
  543. */
  544. #define MAX_PIRQS 8
  545. static int pirq_entries[MAX_PIRQS] = {
  546. [0 ... MAX_PIRQS - 1] = -1
  547. };
  548. static int __init ioapic_pirq_setup(char *str)
  549. {
  550. int i, max;
  551. int ints[MAX_PIRQS+1];
  552. get_options(str, ARRAY_SIZE(ints), ints);
  553. apic_printk(APIC_VERBOSE, KERN_INFO
  554. "PIRQ redirection, working around broken MP-BIOS.\n");
  555. max = MAX_PIRQS;
  556. if (ints[0] < MAX_PIRQS)
  557. max = ints[0];
  558. for (i = 0; i < max; i++) {
  559. apic_printk(APIC_VERBOSE, KERN_DEBUG
  560. "... PIRQ%d -> IRQ %d\n", i, ints[i+1]);
  561. /*
  562. * PIRQs are mapped upside down, usually.
  563. */
  564. pirq_entries[MAX_PIRQS-i-1] = ints[i+1];
  565. }
  566. return 1;
  567. }
  568. __setup("pirq=", ioapic_pirq_setup);
  569. #endif /* CONFIG_X86_32 */
  570. struct IO_APIC_route_entry **alloc_ioapic_entries(void)
  571. {
  572. int apic;
  573. struct IO_APIC_route_entry **ioapic_entries;
  574. ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
  575. GFP_ATOMIC);
  576. if (!ioapic_entries)
  577. return 0;
  578. for (apic = 0; apic < nr_ioapics; apic++) {
  579. ioapic_entries[apic] =
  580. kzalloc(sizeof(struct IO_APIC_route_entry) *
  581. nr_ioapic_registers[apic], GFP_ATOMIC);
  582. if (!ioapic_entries[apic])
  583. goto nomem;
  584. }
  585. return ioapic_entries;
  586. nomem:
  587. while (--apic >= 0)
  588. kfree(ioapic_entries[apic]);
  589. kfree(ioapic_entries);
  590. return 0;
  591. }
  592. /*
  593. * Saves all the IO-APIC RTE's
  594. */
  595. int save_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries)
  596. {
  597. int apic, pin;
  598. if (!ioapic_entries)
  599. return -ENOMEM;
  600. for (apic = 0; apic < nr_ioapics; apic++) {
  601. if (!ioapic_entries[apic])
  602. return -ENOMEM;
  603. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
  604. ioapic_entries[apic][pin] =
  605. ioapic_read_entry(apic, pin);
  606. }
  607. return 0;
  608. }
  609. /*
  610. * Mask all IO APIC entries.
  611. */
  612. void mask_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries)
  613. {
  614. int apic, pin;
  615. if (!ioapic_entries)
  616. return;
  617. for (apic = 0; apic < nr_ioapics; apic++) {
  618. if (!ioapic_entries[apic])
  619. break;
  620. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  621. struct IO_APIC_route_entry entry;
  622. entry = ioapic_entries[apic][pin];
  623. if (!entry.mask) {
  624. entry.mask = 1;
  625. ioapic_write_entry(apic, pin, entry);
  626. }
  627. }
  628. }
  629. }
  630. /*
  631. * Restore IO APIC entries which was saved in ioapic_entries.
  632. */
  633. int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries)
  634. {
  635. int apic, pin;
  636. if (!ioapic_entries)
  637. return -ENOMEM;
  638. for (apic = 0; apic < nr_ioapics; apic++) {
  639. if (!ioapic_entries[apic])
  640. return -ENOMEM;
  641. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
  642. ioapic_write_entry(apic, pin,
  643. ioapic_entries[apic][pin]);
  644. }
  645. return 0;
  646. }
  647. void free_ioapic_entries(struct IO_APIC_route_entry **ioapic_entries)
  648. {
  649. int apic;
  650. for (apic = 0; apic < nr_ioapics; apic++)
  651. kfree(ioapic_entries[apic]);
  652. kfree(ioapic_entries);
  653. }
  654. /*
  655. * Find the IRQ entry number of a certain pin.
  656. */
  657. static int find_irq_entry(int apic, int pin, int type)
  658. {
  659. int i;
  660. for (i = 0; i < mp_irq_entries; i++)
  661. if (mp_irqs[i].irqtype == type &&
  662. (mp_irqs[i].dstapic == mp_ioapics[apic].apicid ||
  663. mp_irqs[i].dstapic == MP_APIC_ALL) &&
  664. mp_irqs[i].dstirq == pin)
  665. return i;
  666. return -1;
  667. }
  668. /*
  669. * Find the pin to which IRQ[irq] (ISA) is connected
  670. */
  671. static int __init find_isa_irq_pin(int irq, int type)
  672. {
  673. int i;
  674. for (i = 0; i < mp_irq_entries; i++) {
  675. int lbus = mp_irqs[i].srcbus;
  676. if (test_bit(lbus, mp_bus_not_pci) &&
  677. (mp_irqs[i].irqtype == type) &&
  678. (mp_irqs[i].srcbusirq == irq))
  679. return mp_irqs[i].dstirq;
  680. }
  681. return -1;
  682. }
  683. static int __init find_isa_irq_apic(int irq, int type)
  684. {
  685. int i;
  686. for (i = 0; i < mp_irq_entries; i++) {
  687. int lbus = mp_irqs[i].srcbus;
  688. if (test_bit(lbus, mp_bus_not_pci) &&
  689. (mp_irqs[i].irqtype == type) &&
  690. (mp_irqs[i].srcbusirq == irq))
  691. break;
  692. }
  693. if (i < mp_irq_entries) {
  694. int apic;
  695. for(apic = 0; apic < nr_ioapics; apic++) {
  696. if (mp_ioapics[apic].apicid == mp_irqs[i].dstapic)
  697. return apic;
  698. }
  699. }
  700. return -1;
  701. }
  702. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  703. /*
  704. * EISA Edge/Level control register, ELCR
  705. */
  706. static int EISA_ELCR(unsigned int irq)
  707. {
  708. if (irq < legacy_pic->nr_legacy_irqs) {
  709. unsigned int port = 0x4d0 + (irq >> 3);
  710. return (inb(port) >> (irq & 7)) & 1;
  711. }
  712. apic_printk(APIC_VERBOSE, KERN_INFO
  713. "Broken MPtable reports ISA irq %d\n", irq);
  714. return 0;
  715. }
  716. #endif
  717. /* ISA interrupts are always polarity zero edge triggered,
  718. * when listed as conforming in the MP table. */
  719. #define default_ISA_trigger(idx) (0)
  720. #define default_ISA_polarity(idx) (0)
  721. /* EISA interrupts are always polarity zero and can be edge or level
  722. * trigger depending on the ELCR value. If an interrupt is listed as
  723. * EISA conforming in the MP table, that means its trigger type must
  724. * be read in from the ELCR */
  725. #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].srcbusirq))
  726. #define default_EISA_polarity(idx) default_ISA_polarity(idx)
  727. /* PCI interrupts are always polarity one level triggered,
  728. * when listed as conforming in the MP table. */
  729. #define default_PCI_trigger(idx) (1)
  730. #define default_PCI_polarity(idx) (1)
  731. /* MCA interrupts are always polarity zero level triggered,
  732. * when listed as conforming in the MP table. */
  733. #define default_MCA_trigger(idx) (1)
  734. #define default_MCA_polarity(idx) default_ISA_polarity(idx)
  735. static int MPBIOS_polarity(int idx)
  736. {
  737. int bus = mp_irqs[idx].srcbus;
  738. int polarity;
  739. /*
  740. * Determine IRQ line polarity (high active or low active):
  741. */
  742. switch (mp_irqs[idx].irqflag & 3)
  743. {
  744. case 0: /* conforms, ie. bus-type dependent polarity */
  745. if (test_bit(bus, mp_bus_not_pci))
  746. polarity = default_ISA_polarity(idx);
  747. else
  748. polarity = default_PCI_polarity(idx);
  749. break;
  750. case 1: /* high active */
  751. {
  752. polarity = 0;
  753. break;
  754. }
  755. case 2: /* reserved */
  756. {
  757. printk(KERN_WARNING "broken BIOS!!\n");
  758. polarity = 1;
  759. break;
  760. }
  761. case 3: /* low active */
  762. {
  763. polarity = 1;
  764. break;
  765. }
  766. default: /* invalid */
  767. {
  768. printk(KERN_WARNING "broken BIOS!!\n");
  769. polarity = 1;
  770. break;
  771. }
  772. }
  773. return polarity;
  774. }
  775. static int MPBIOS_trigger(int idx)
  776. {
  777. int bus = mp_irqs[idx].srcbus;
  778. int trigger;
  779. /*
  780. * Determine IRQ trigger mode (edge or level sensitive):
  781. */
  782. switch ((mp_irqs[idx].irqflag>>2) & 3)
  783. {
  784. case 0: /* conforms, ie. bus-type dependent */
  785. if (test_bit(bus, mp_bus_not_pci))
  786. trigger = default_ISA_trigger(idx);
  787. else
  788. trigger = default_PCI_trigger(idx);
  789. #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
  790. switch (mp_bus_id_to_type[bus]) {
  791. case MP_BUS_ISA: /* ISA pin */
  792. {
  793. /* set before the switch */
  794. break;
  795. }
  796. case MP_BUS_EISA: /* EISA pin */
  797. {
  798. trigger = default_EISA_trigger(idx);
  799. break;
  800. }
  801. case MP_BUS_PCI: /* PCI pin */
  802. {
  803. /* set before the switch */
  804. break;
  805. }
  806. case MP_BUS_MCA: /* MCA pin */
  807. {
  808. trigger = default_MCA_trigger(idx);
  809. break;
  810. }
  811. default:
  812. {
  813. printk(KERN_WARNING "broken BIOS!!\n");
  814. trigger = 1;
  815. break;
  816. }
  817. }
  818. #endif
  819. break;
  820. case 1: /* edge */
  821. {
  822. trigger = 0;
  823. break;
  824. }
  825. case 2: /* reserved */
  826. {
  827. printk(KERN_WARNING "broken BIOS!!\n");
  828. trigger = 1;
  829. break;
  830. }
  831. case 3: /* level */
  832. {
  833. trigger = 1;
  834. break;
  835. }
  836. default: /* invalid */
  837. {
  838. printk(KERN_WARNING "broken BIOS!!\n");
  839. trigger = 0;
  840. break;
  841. }
  842. }
  843. return trigger;
  844. }
  845. static inline int irq_polarity(int idx)
  846. {
  847. return MPBIOS_polarity(idx);
  848. }
  849. static inline int irq_trigger(int idx)
  850. {
  851. return MPBIOS_trigger(idx);
  852. }
  853. static int pin_2_irq(int idx, int apic, int pin)
  854. {
  855. int irq;
  856. int bus = mp_irqs[idx].srcbus;
  857. /*
  858. * Debugging check, we are in big trouble if this message pops up!
  859. */
  860. if (mp_irqs[idx].dstirq != pin)
  861. printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
  862. if (test_bit(bus, mp_bus_not_pci)) {
  863. irq = mp_irqs[idx].srcbusirq;
  864. } else {
  865. u32 gsi = mp_gsi_routing[apic].gsi_base + pin;
  866. if (gsi >= NR_IRQS_LEGACY)
  867. irq = gsi;
  868. else
  869. irq = gsi_top + gsi;
  870. }
  871. #ifdef CONFIG_X86_32
  872. /*
  873. * PCI IRQ command line redirection. Yes, limits are hardcoded.
  874. */
  875. if ((pin >= 16) && (pin <= 23)) {
  876. if (pirq_entries[pin-16] != -1) {
  877. if (!pirq_entries[pin-16]) {
  878. apic_printk(APIC_VERBOSE, KERN_DEBUG
  879. "disabling PIRQ%d\n", pin-16);
  880. } else {
  881. irq = pirq_entries[pin-16];
  882. apic_printk(APIC_VERBOSE, KERN_DEBUG
  883. "using PIRQ%d -> IRQ %d\n",
  884. pin-16, irq);
  885. }
  886. }
  887. }
  888. #endif
  889. return irq;
  890. }
  891. /*
  892. * Find a specific PCI IRQ entry.
  893. * Not an __init, possibly needed by modules
  894. */
  895. int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
  896. struct io_apic_irq_attr *irq_attr)
  897. {
  898. int apic, i, best_guess = -1;
  899. apic_printk(APIC_DEBUG,
  900. "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
  901. bus, slot, pin);
  902. if (test_bit(bus, mp_bus_not_pci)) {
  903. apic_printk(APIC_VERBOSE,
  904. "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
  905. return -1;
  906. }
  907. for (i = 0; i < mp_irq_entries; i++) {
  908. int lbus = mp_irqs[i].srcbus;
  909. for (apic = 0; apic < nr_ioapics; apic++)
  910. if (mp_ioapics[apic].apicid == mp_irqs[i].dstapic ||
  911. mp_irqs[i].dstapic == MP_APIC_ALL)
  912. break;
  913. if (!test_bit(lbus, mp_bus_not_pci) &&
  914. !mp_irqs[i].irqtype &&
  915. (bus == lbus) &&
  916. (slot == ((mp_irqs[i].srcbusirq >> 2) & 0x1f))) {
  917. int irq = pin_2_irq(i, apic, mp_irqs[i].dstirq);
  918. if (!(apic || IO_APIC_IRQ(irq)))
  919. continue;
  920. if (pin == (mp_irqs[i].srcbusirq & 3)) {
  921. set_io_apic_irq_attr(irq_attr, apic,
  922. mp_irqs[i].dstirq,
  923. irq_trigger(i),
  924. irq_polarity(i));
  925. return irq;
  926. }
  927. /*
  928. * Use the first all-but-pin matching entry as a
  929. * best-guess fuzzy result for broken mptables.
  930. */
  931. if (best_guess < 0) {
  932. set_io_apic_irq_attr(irq_attr, apic,
  933. mp_irqs[i].dstirq,
  934. irq_trigger(i),
  935. irq_polarity(i));
  936. best_guess = irq;
  937. }
  938. }
  939. }
  940. return best_guess;
  941. }
  942. EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
  943. void lock_vector_lock(void)
  944. {
  945. /* Used to the online set of cpus does not change
  946. * during assign_irq_vector.
  947. */
  948. raw_spin_lock(&vector_lock);
  949. }
  950. void unlock_vector_lock(void)
  951. {
  952. raw_spin_unlock(&vector_lock);
  953. }
  954. static int
  955. __assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
  956. {
  957. /*
  958. * NOTE! The local APIC isn't very good at handling
  959. * multiple interrupts at the same interrupt level.
  960. * As the interrupt level is determined by taking the
  961. * vector number and shifting that right by 4, we
  962. * want to spread these out a bit so that they don't
  963. * all fall in the same interrupt level.
  964. *
  965. * Also, we've got to be careful not to trash gate
  966. * 0x80, because int 0x80 is hm, kind of importantish. ;)
  967. */
  968. static int current_vector = FIRST_EXTERNAL_VECTOR + VECTOR_OFFSET_START;
  969. static int current_offset = VECTOR_OFFSET_START % 8;
  970. unsigned int old_vector;
  971. int cpu, err;
  972. cpumask_var_t tmp_mask;
  973. if (cfg->move_in_progress)
  974. return -EBUSY;
  975. if (!alloc_cpumask_var(&tmp_mask, GFP_ATOMIC))
  976. return -ENOMEM;
  977. old_vector = cfg->vector;
  978. if (old_vector) {
  979. cpumask_and(tmp_mask, mask, cpu_online_mask);
  980. cpumask_and(tmp_mask, cfg->domain, tmp_mask);
  981. if (!cpumask_empty(tmp_mask)) {
  982. free_cpumask_var(tmp_mask);
  983. return 0;
  984. }
  985. }
  986. /* Only try and allocate irqs on cpus that are present */
  987. err = -ENOSPC;
  988. for_each_cpu_and(cpu, mask, cpu_online_mask) {
  989. int new_cpu;
  990. int vector, offset;
  991. apic->vector_allocation_domain(cpu, tmp_mask);
  992. vector = current_vector;
  993. offset = current_offset;
  994. next:
  995. vector += 8;
  996. if (vector >= first_system_vector) {
  997. /* If out of vectors on large boxen, must share them. */
  998. offset = (offset + 1) % 8;
  999. vector = FIRST_EXTERNAL_VECTOR + offset;
  1000. }
  1001. if (unlikely(current_vector == vector))
  1002. continue;
  1003. if (test_bit(vector, used_vectors))
  1004. goto next;
  1005. for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask)
  1006. if (per_cpu(vector_irq, new_cpu)[vector] != -1)
  1007. goto next;
  1008. /* Found one! */
  1009. current_vector = vector;
  1010. current_offset = offset;
  1011. if (old_vector) {
  1012. cfg->move_in_progress = 1;
  1013. cpumask_copy(cfg->old_domain, cfg->domain);
  1014. }
  1015. for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask)
  1016. per_cpu(vector_irq, new_cpu)[vector] = irq;
  1017. cfg->vector = vector;
  1018. cpumask_copy(cfg->domain, tmp_mask);
  1019. err = 0;
  1020. break;
  1021. }
  1022. free_cpumask_var(tmp_mask);
  1023. return err;
  1024. }
  1025. int assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
  1026. {
  1027. int err;
  1028. unsigned long flags;
  1029. raw_spin_lock_irqsave(&vector_lock, flags);
  1030. err = __assign_irq_vector(irq, cfg, mask);
  1031. raw_spin_unlock_irqrestore(&vector_lock, flags);
  1032. return err;
  1033. }
  1034. static void __clear_irq_vector(int irq, struct irq_cfg *cfg)
  1035. {
  1036. int cpu, vector;
  1037. BUG_ON(!cfg->vector);
  1038. vector = cfg->vector;
  1039. for_each_cpu_and(cpu, cfg->domain, cpu_online_mask)
  1040. per_cpu(vector_irq, cpu)[vector] = -1;
  1041. cfg->vector = 0;
  1042. cpumask_clear(cfg->domain);
  1043. if (likely(!cfg->move_in_progress))
  1044. return;
  1045. for_each_cpu_and(cpu, cfg->old_domain, cpu_online_mask) {
  1046. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS;
  1047. vector++) {
  1048. if (per_cpu(vector_irq, cpu)[vector] != irq)
  1049. continue;
  1050. per_cpu(vector_irq, cpu)[vector] = -1;
  1051. break;
  1052. }
  1053. }
  1054. cfg->move_in_progress = 0;
  1055. }
  1056. void __setup_vector_irq(int cpu)
  1057. {
  1058. /* Initialize vector_irq on a new cpu */
  1059. int irq, vector;
  1060. struct irq_cfg *cfg;
  1061. struct irq_desc *desc;
  1062. /*
  1063. * vector_lock will make sure that we don't run into irq vector
  1064. * assignments that might be happening on another cpu in parallel,
  1065. * while we setup our initial vector to irq mappings.
  1066. */
  1067. raw_spin_lock(&vector_lock);
  1068. /* Mark the inuse vectors */
  1069. for_each_irq_desc(irq, desc) {
  1070. cfg = get_irq_desc_chip_data(desc);
  1071. /*
  1072. * If it is a legacy IRQ handled by the legacy PIC, this cpu
  1073. * will be part of the irq_cfg's domain.
  1074. */
  1075. if (irq < legacy_pic->nr_legacy_irqs && !IO_APIC_IRQ(irq))
  1076. cpumask_set_cpu(cpu, cfg->domain);
  1077. if (!cpumask_test_cpu(cpu, cfg->domain))
  1078. continue;
  1079. vector = cfg->vector;
  1080. per_cpu(vector_irq, cpu)[vector] = irq;
  1081. }
  1082. /* Mark the free vectors */
  1083. for (vector = 0; vector < NR_VECTORS; ++vector) {
  1084. irq = per_cpu(vector_irq, cpu)[vector];
  1085. if (irq < 0)
  1086. continue;
  1087. cfg = irq_cfg(irq);
  1088. if (!cpumask_test_cpu(cpu, cfg->domain))
  1089. per_cpu(vector_irq, cpu)[vector] = -1;
  1090. }
  1091. raw_spin_unlock(&vector_lock);
  1092. }
  1093. static struct irq_chip ioapic_chip;
  1094. static struct irq_chip ir_ioapic_chip;
  1095. #define IOAPIC_AUTO -1
  1096. #define IOAPIC_EDGE 0
  1097. #define IOAPIC_LEVEL 1
  1098. #ifdef CONFIG_X86_32
  1099. static inline int IO_APIC_irq_trigger(int irq)
  1100. {
  1101. int apic, idx, pin;
  1102. for (apic = 0; apic < nr_ioapics; apic++) {
  1103. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  1104. idx = find_irq_entry(apic, pin, mp_INT);
  1105. if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
  1106. return irq_trigger(idx);
  1107. }
  1108. }
  1109. /*
  1110. * nonexistent IRQs are edge default
  1111. */
  1112. return 0;
  1113. }
  1114. #else
  1115. static inline int IO_APIC_irq_trigger(int irq)
  1116. {
  1117. return 1;
  1118. }
  1119. #endif
  1120. static void ioapic_register_intr(int irq, struct irq_desc *desc, unsigned long trigger)
  1121. {
  1122. if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
  1123. trigger == IOAPIC_LEVEL)
  1124. desc->status |= IRQ_LEVEL;
  1125. else
  1126. desc->status &= ~IRQ_LEVEL;
  1127. if (irq_remapped(irq)) {
  1128. desc->status |= IRQ_MOVE_PCNTXT;
  1129. if (trigger)
  1130. set_irq_chip_and_handler_name(irq, &ir_ioapic_chip,
  1131. handle_fasteoi_irq,
  1132. "fasteoi");
  1133. else
  1134. set_irq_chip_and_handler_name(irq, &ir_ioapic_chip,
  1135. handle_edge_irq, "edge");
  1136. return;
  1137. }
  1138. if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
  1139. trigger == IOAPIC_LEVEL)
  1140. set_irq_chip_and_handler_name(irq, &ioapic_chip,
  1141. handle_fasteoi_irq,
  1142. "fasteoi");
  1143. else
  1144. set_irq_chip_and_handler_name(irq, &ioapic_chip,
  1145. handle_edge_irq, "edge");
  1146. }
  1147. int setup_ioapic_entry(int apic_id, int irq,
  1148. struct IO_APIC_route_entry *entry,
  1149. unsigned int destination, int trigger,
  1150. int polarity, int vector, int pin)
  1151. {
  1152. /*
  1153. * add it to the IO-APIC irq-routing table:
  1154. */
  1155. memset(entry,0,sizeof(*entry));
  1156. if (intr_remapping_enabled) {
  1157. struct intel_iommu *iommu = map_ioapic_to_ir(apic_id);
  1158. struct irte irte;
  1159. struct IR_IO_APIC_route_entry *ir_entry =
  1160. (struct IR_IO_APIC_route_entry *) entry;
  1161. int index;
  1162. if (!iommu)
  1163. panic("No mapping iommu for ioapic %d\n", apic_id);
  1164. index = alloc_irte(iommu, irq, 1);
  1165. if (index < 0)
  1166. panic("Failed to allocate IRTE for ioapic %d\n", apic_id);
  1167. prepare_irte(&irte, vector, destination);
  1168. /* Set source-id of interrupt request */
  1169. set_ioapic_sid(&irte, apic_id);
  1170. modify_irte(irq, &irte);
  1171. ir_entry->index2 = (index >> 15) & 0x1;
  1172. ir_entry->zero = 0;
  1173. ir_entry->format = 1;
  1174. ir_entry->index = (index & 0x7fff);
  1175. /*
  1176. * IO-APIC RTE will be configured with virtual vector.
  1177. * irq handler will do the explicit EOI to the io-apic.
  1178. */
  1179. ir_entry->vector = pin;
  1180. } else {
  1181. entry->delivery_mode = apic->irq_delivery_mode;
  1182. entry->dest_mode = apic->irq_dest_mode;
  1183. entry->dest = destination;
  1184. entry->vector = vector;
  1185. }
  1186. entry->mask = 0; /* enable IRQ */
  1187. entry->trigger = trigger;
  1188. entry->polarity = polarity;
  1189. /* Mask level triggered irqs.
  1190. * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
  1191. */
  1192. if (trigger)
  1193. entry->mask = 1;
  1194. return 0;
  1195. }
  1196. static void setup_IO_APIC_irq(int apic_id, int pin, unsigned int irq, struct irq_desc *desc,
  1197. int trigger, int polarity)
  1198. {
  1199. struct irq_cfg *cfg;
  1200. struct IO_APIC_route_entry entry;
  1201. unsigned int dest;
  1202. if (!IO_APIC_IRQ(irq))
  1203. return;
  1204. cfg = get_irq_desc_chip_data(desc);
  1205. /*
  1206. * For legacy irqs, cfg->domain starts with cpu 0 for legacy
  1207. * controllers like 8259. Now that IO-APIC can handle this irq, update
  1208. * the cfg->domain.
  1209. */
  1210. if (irq < legacy_pic->nr_legacy_irqs && cpumask_test_cpu(0, cfg->domain))
  1211. apic->vector_allocation_domain(0, cfg->domain);
  1212. if (assign_irq_vector(irq, cfg, apic->target_cpus()))
  1213. return;
  1214. dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
  1215. apic_printk(APIC_VERBOSE,KERN_DEBUG
  1216. "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
  1217. "IRQ %d Mode:%i Active:%i)\n",
  1218. apic_id, mp_ioapics[apic_id].apicid, pin, cfg->vector,
  1219. irq, trigger, polarity);
  1220. if (setup_ioapic_entry(mp_ioapics[apic_id].apicid, irq, &entry,
  1221. dest, trigger, polarity, cfg->vector, pin)) {
  1222. printk("Failed to setup ioapic entry for ioapic %d, pin %d\n",
  1223. mp_ioapics[apic_id].apicid, pin);
  1224. __clear_irq_vector(irq, cfg);
  1225. return;
  1226. }
  1227. ioapic_register_intr(irq, desc, trigger);
  1228. if (irq < legacy_pic->nr_legacy_irqs)
  1229. legacy_pic->mask(irq);
  1230. ioapic_write_entry(apic_id, pin, entry);
  1231. }
  1232. static struct {
  1233. DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
  1234. } mp_ioapic_routing[MAX_IO_APICS];
  1235. static void __init setup_IO_APIC_irqs(void)
  1236. {
  1237. int apic_id, pin, idx, irq;
  1238. int notcon = 0;
  1239. struct irq_desc *desc;
  1240. struct irq_cfg *cfg;
  1241. int node = cpu_to_node(0);
  1242. apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
  1243. for (apic_id = 0; apic_id < nr_ioapics; apic_id++)
  1244. for (pin = 0; pin < nr_ioapic_registers[apic_id]; pin++) {
  1245. idx = find_irq_entry(apic_id, pin, mp_INT);
  1246. if (idx == -1) {
  1247. if (!notcon) {
  1248. notcon = 1;
  1249. apic_printk(APIC_VERBOSE,
  1250. KERN_DEBUG " %d-%d",
  1251. mp_ioapics[apic_id].apicid, pin);
  1252. } else
  1253. apic_printk(APIC_VERBOSE, " %d-%d",
  1254. mp_ioapics[apic_id].apicid, pin);
  1255. continue;
  1256. }
  1257. if (notcon) {
  1258. apic_printk(APIC_VERBOSE,
  1259. " (apicid-pin) not connected\n");
  1260. notcon = 0;
  1261. }
  1262. irq = pin_2_irq(idx, apic_id, pin);
  1263. if ((apic_id > 0) && (irq > 16))
  1264. continue;
  1265. /*
  1266. * Skip the timer IRQ if there's a quirk handler
  1267. * installed and if it returns 1:
  1268. */
  1269. if (apic->multi_timer_check &&
  1270. apic->multi_timer_check(apic_id, irq))
  1271. continue;
  1272. desc = irq_to_desc_alloc_node(irq, node);
  1273. if (!desc) {
  1274. printk(KERN_INFO "can not get irq_desc for %d\n", irq);
  1275. continue;
  1276. }
  1277. cfg = get_irq_desc_chip_data(desc);
  1278. add_pin_to_irq_node(cfg, node, apic_id, pin);
  1279. /*
  1280. * don't mark it in pin_programmed, so later acpi could
  1281. * set it correctly when irq < 16
  1282. */
  1283. setup_IO_APIC_irq(apic_id, pin, irq, desc,
  1284. irq_trigger(idx), irq_polarity(idx));
  1285. }
  1286. if (notcon)
  1287. apic_printk(APIC_VERBOSE,
  1288. " (apicid-pin) not connected\n");
  1289. }
  1290. /*
  1291. * for the gsit that is not in first ioapic
  1292. * but could not use acpi_register_gsi()
  1293. * like some special sci in IBM x3330
  1294. */
  1295. void setup_IO_APIC_irq_extra(u32 gsi)
  1296. {
  1297. int apic_id = 0, pin, idx, irq;
  1298. int node = cpu_to_node(0);
  1299. struct irq_desc *desc;
  1300. struct irq_cfg *cfg;
  1301. /*
  1302. * Convert 'gsi' to 'ioapic.pin'.
  1303. */
  1304. apic_id = mp_find_ioapic(gsi);
  1305. if (apic_id < 0)
  1306. return;
  1307. pin = mp_find_ioapic_pin(apic_id, gsi);
  1308. idx = find_irq_entry(apic_id, pin, mp_INT);
  1309. if (idx == -1)
  1310. return;
  1311. irq = pin_2_irq(idx, apic_id, pin);
  1312. #ifdef CONFIG_SPARSE_IRQ
  1313. desc = irq_to_desc(irq);
  1314. if (desc)
  1315. return;
  1316. #endif
  1317. desc = irq_to_desc_alloc_node(irq, node);
  1318. if (!desc) {
  1319. printk(KERN_INFO "can not get irq_desc for %d\n", irq);
  1320. return;
  1321. }
  1322. cfg = get_irq_desc_chip_data(desc);
  1323. add_pin_to_irq_node(cfg, node, apic_id, pin);
  1324. if (test_bit(pin, mp_ioapic_routing[apic_id].pin_programmed)) {
  1325. pr_debug("Pin %d-%d already programmed\n",
  1326. mp_ioapics[apic_id].apicid, pin);
  1327. return;
  1328. }
  1329. set_bit(pin, mp_ioapic_routing[apic_id].pin_programmed);
  1330. setup_IO_APIC_irq(apic_id, pin, irq, desc,
  1331. irq_trigger(idx), irq_polarity(idx));
  1332. }
  1333. /*
  1334. * Set up the timer pin, possibly with the 8259A-master behind.
  1335. */
  1336. static void __init setup_timer_IRQ0_pin(unsigned int apic_id, unsigned int pin,
  1337. int vector)
  1338. {
  1339. struct IO_APIC_route_entry entry;
  1340. if (intr_remapping_enabled)
  1341. return;
  1342. memset(&entry, 0, sizeof(entry));
  1343. /*
  1344. * We use logical delivery to get the timer IRQ
  1345. * to the first CPU.
  1346. */
  1347. entry.dest_mode = apic->irq_dest_mode;
  1348. entry.mask = 0; /* don't mask IRQ for edge */
  1349. entry.dest = apic->cpu_mask_to_apicid(apic->target_cpus());
  1350. entry.delivery_mode = apic->irq_delivery_mode;
  1351. entry.polarity = 0;
  1352. entry.trigger = 0;
  1353. entry.vector = vector;
  1354. /*
  1355. * The timer IRQ doesn't have to know that behind the
  1356. * scene we may have a 8259A-master in AEOI mode ...
  1357. */
  1358. set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge");
  1359. /*
  1360. * Add it to the IO-APIC irq-routing table:
  1361. */
  1362. ioapic_write_entry(apic_id, pin, entry);
  1363. }
  1364. __apicdebuginit(void) print_IO_APIC(void)
  1365. {
  1366. int apic, i;
  1367. union IO_APIC_reg_00 reg_00;
  1368. union IO_APIC_reg_01 reg_01;
  1369. union IO_APIC_reg_02 reg_02;
  1370. union IO_APIC_reg_03 reg_03;
  1371. unsigned long flags;
  1372. struct irq_cfg *cfg;
  1373. struct irq_desc *desc;
  1374. unsigned int irq;
  1375. printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
  1376. for (i = 0; i < nr_ioapics; i++)
  1377. printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
  1378. mp_ioapics[i].apicid, nr_ioapic_registers[i]);
  1379. /*
  1380. * We are a bit conservative about what we expect. We have to
  1381. * know about every hardware change ASAP.
  1382. */
  1383. printk(KERN_INFO "testing the IO APIC.......................\n");
  1384. for (apic = 0; apic < nr_ioapics; apic++) {
  1385. raw_spin_lock_irqsave(&ioapic_lock, flags);
  1386. reg_00.raw = io_apic_read(apic, 0);
  1387. reg_01.raw = io_apic_read(apic, 1);
  1388. if (reg_01.bits.version >= 0x10)
  1389. reg_02.raw = io_apic_read(apic, 2);
  1390. if (reg_01.bits.version >= 0x20)
  1391. reg_03.raw = io_apic_read(apic, 3);
  1392. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  1393. printk("\n");
  1394. printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].apicid);
  1395. printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
  1396. printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
  1397. printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type);
  1398. printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS);
  1399. printk(KERN_DEBUG ".... register #01: %08X\n", *(int *)&reg_01);
  1400. printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries);
  1401. printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
  1402. printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version);
  1403. /*
  1404. * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
  1405. * but the value of reg_02 is read as the previous read register
  1406. * value, so ignore it if reg_02 == reg_01.
  1407. */
  1408. if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) {
  1409. printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
  1410. printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
  1411. }
  1412. /*
  1413. * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
  1414. * or reg_03, but the value of reg_0[23] is read as the previous read
  1415. * register value, so ignore it if reg_03 == reg_0[12].
  1416. */
  1417. if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw &&
  1418. reg_03.raw != reg_01.raw) {
  1419. printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw);
  1420. printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT);
  1421. }
  1422. printk(KERN_DEBUG ".... IRQ redirection table:\n");
  1423. printk(KERN_DEBUG " NR Dst Mask Trig IRR Pol"
  1424. " Stat Dmod Deli Vect:\n");
  1425. for (i = 0; i <= reg_01.bits.entries; i++) {
  1426. struct IO_APIC_route_entry entry;
  1427. entry = ioapic_read_entry(apic, i);
  1428. printk(KERN_DEBUG " %02x %03X ",
  1429. i,
  1430. entry.dest
  1431. );
  1432. printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
  1433. entry.mask,
  1434. entry.trigger,
  1435. entry.irr,
  1436. entry.polarity,
  1437. entry.delivery_status,
  1438. entry.dest_mode,
  1439. entry.delivery_mode,
  1440. entry.vector
  1441. );
  1442. }
  1443. }
  1444. printk(KERN_DEBUG "IRQ to pin mappings:\n");
  1445. for_each_irq_desc(irq, desc) {
  1446. struct irq_pin_list *entry;
  1447. cfg = get_irq_desc_chip_data(desc);
  1448. if (!cfg)
  1449. continue;
  1450. entry = cfg->irq_2_pin;
  1451. if (!entry)
  1452. continue;
  1453. printk(KERN_DEBUG "IRQ%d ", irq);
  1454. for_each_irq_pin(entry, cfg->irq_2_pin)
  1455. printk("-> %d:%d", entry->apic, entry->pin);
  1456. printk("\n");
  1457. }
  1458. printk(KERN_INFO ".................................... done.\n");
  1459. return;
  1460. }
  1461. __apicdebuginit(void) print_APIC_field(int base)
  1462. {
  1463. int i;
  1464. printk(KERN_DEBUG);
  1465. for (i = 0; i < 8; i++)
  1466. printk(KERN_CONT "%08x", apic_read(base + i*0x10));
  1467. printk(KERN_CONT "\n");
  1468. }
  1469. __apicdebuginit(void) print_local_APIC(void *dummy)
  1470. {
  1471. unsigned int i, v, ver, maxlvt;
  1472. u64 icr;
  1473. printk(KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
  1474. smp_processor_id(), hard_smp_processor_id());
  1475. v = apic_read(APIC_ID);
  1476. printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, read_apic_id());
  1477. v = apic_read(APIC_LVR);
  1478. printk(KERN_INFO "... APIC VERSION: %08x\n", v);
  1479. ver = GET_APIC_VERSION(v);
  1480. maxlvt = lapic_get_maxlvt();
  1481. v = apic_read(APIC_TASKPRI);
  1482. printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
  1483. if (APIC_INTEGRATED(ver)) { /* !82489DX */
  1484. if (!APIC_XAPIC(ver)) {
  1485. v = apic_read(APIC_ARBPRI);
  1486. printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
  1487. v & APIC_ARBPRI_MASK);
  1488. }
  1489. v = apic_read(APIC_PROCPRI);
  1490. printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
  1491. }
  1492. /*
  1493. * Remote read supported only in the 82489DX and local APIC for
  1494. * Pentium processors.
  1495. */
  1496. if (!APIC_INTEGRATED(ver) || maxlvt == 3) {
  1497. v = apic_read(APIC_RRR);
  1498. printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
  1499. }
  1500. v = apic_read(APIC_LDR);
  1501. printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
  1502. if (!x2apic_enabled()) {
  1503. v = apic_read(APIC_DFR);
  1504. printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
  1505. }
  1506. v = apic_read(APIC_SPIV);
  1507. printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
  1508. printk(KERN_DEBUG "... APIC ISR field:\n");
  1509. print_APIC_field(APIC_ISR);
  1510. printk(KERN_DEBUG "... APIC TMR field:\n");
  1511. print_APIC_field(APIC_TMR);
  1512. printk(KERN_DEBUG "... APIC IRR field:\n");
  1513. print_APIC_field(APIC_IRR);
  1514. if (APIC_INTEGRATED(ver)) { /* !82489DX */
  1515. if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
  1516. apic_write(APIC_ESR, 0);
  1517. v = apic_read(APIC_ESR);
  1518. printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
  1519. }
  1520. icr = apic_icr_read();
  1521. printk(KERN_DEBUG "... APIC ICR: %08x\n", (u32)icr);
  1522. printk(KERN_DEBUG "... APIC ICR2: %08x\n", (u32)(icr >> 32));
  1523. v = apic_read(APIC_LVTT);
  1524. printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
  1525. if (maxlvt > 3) { /* PC is LVT#4. */
  1526. v = apic_read(APIC_LVTPC);
  1527. printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
  1528. }
  1529. v = apic_read(APIC_LVT0);
  1530. printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
  1531. v = apic_read(APIC_LVT1);
  1532. printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
  1533. if (maxlvt > 2) { /* ERR is LVT#3. */
  1534. v = apic_read(APIC_LVTERR);
  1535. printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
  1536. }
  1537. v = apic_read(APIC_TMICT);
  1538. printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
  1539. v = apic_read(APIC_TMCCT);
  1540. printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
  1541. v = apic_read(APIC_TDCR);
  1542. printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
  1543. if (boot_cpu_has(X86_FEATURE_EXTAPIC)) {
  1544. v = apic_read(APIC_EFEAT);
  1545. maxlvt = (v >> 16) & 0xff;
  1546. printk(KERN_DEBUG "... APIC EFEAT: %08x\n", v);
  1547. v = apic_read(APIC_ECTRL);
  1548. printk(KERN_DEBUG "... APIC ECTRL: %08x\n", v);
  1549. for (i = 0; i < maxlvt; i++) {
  1550. v = apic_read(APIC_EILVTn(i));
  1551. printk(KERN_DEBUG "... APIC EILVT%d: %08x\n", i, v);
  1552. }
  1553. }
  1554. printk("\n");
  1555. }
  1556. __apicdebuginit(void) print_local_APICs(int maxcpu)
  1557. {
  1558. int cpu;
  1559. if (!maxcpu)
  1560. return;
  1561. preempt_disable();
  1562. for_each_online_cpu(cpu) {
  1563. if (cpu >= maxcpu)
  1564. break;
  1565. smp_call_function_single(cpu, print_local_APIC, NULL, 1);
  1566. }
  1567. preempt_enable();
  1568. }
  1569. __apicdebuginit(void) print_PIC(void)
  1570. {
  1571. unsigned int v;
  1572. unsigned long flags;
  1573. if (!legacy_pic->nr_legacy_irqs)
  1574. return;
  1575. printk(KERN_DEBUG "\nprinting PIC contents\n");
  1576. raw_spin_lock_irqsave(&i8259A_lock, flags);
  1577. v = inb(0xa1) << 8 | inb(0x21);
  1578. printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
  1579. v = inb(0xa0) << 8 | inb(0x20);
  1580. printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
  1581. outb(0x0b,0xa0);
  1582. outb(0x0b,0x20);
  1583. v = inb(0xa0) << 8 | inb(0x20);
  1584. outb(0x0a,0xa0);
  1585. outb(0x0a,0x20);
  1586. raw_spin_unlock_irqrestore(&i8259A_lock, flags);
  1587. printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
  1588. v = inb(0x4d1) << 8 | inb(0x4d0);
  1589. printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
  1590. }
  1591. static int __initdata show_lapic = 1;
  1592. static __init int setup_show_lapic(char *arg)
  1593. {
  1594. int num = -1;
  1595. if (strcmp(arg, "all") == 0) {
  1596. show_lapic = CONFIG_NR_CPUS;
  1597. } else {
  1598. get_option(&arg, &num);
  1599. if (num >= 0)
  1600. show_lapic = num;
  1601. }
  1602. return 1;
  1603. }
  1604. __setup("show_lapic=", setup_show_lapic);
  1605. __apicdebuginit(int) print_ICs(void)
  1606. {
  1607. if (apic_verbosity == APIC_QUIET)
  1608. return 0;
  1609. print_PIC();
  1610. /* don't print out if apic is not there */
  1611. if (!cpu_has_apic && !apic_from_smp_config())
  1612. return 0;
  1613. print_local_APICs(show_lapic);
  1614. print_IO_APIC();
  1615. return 0;
  1616. }
  1617. fs_initcall(print_ICs);
  1618. /* Where if anywhere is the i8259 connect in external int mode */
  1619. static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
  1620. void __init enable_IO_APIC(void)
  1621. {
  1622. int i8259_apic, i8259_pin;
  1623. int apic;
  1624. if (!legacy_pic->nr_legacy_irqs)
  1625. return;
  1626. for(apic = 0; apic < nr_ioapics; apic++) {
  1627. int pin;
  1628. /* See if any of the pins is in ExtINT mode */
  1629. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  1630. struct IO_APIC_route_entry entry;
  1631. entry = ioapic_read_entry(apic, pin);
  1632. /* If the interrupt line is enabled and in ExtInt mode
  1633. * I have found the pin where the i8259 is connected.
  1634. */
  1635. if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
  1636. ioapic_i8259.apic = apic;
  1637. ioapic_i8259.pin = pin;
  1638. goto found_i8259;
  1639. }
  1640. }
  1641. }
  1642. found_i8259:
  1643. /* Look to see what if the MP table has reported the ExtINT */
  1644. /* If we could not find the appropriate pin by looking at the ioapic
  1645. * the i8259 probably is not connected the ioapic but give the
  1646. * mptable a chance anyway.
  1647. */
  1648. i8259_pin = find_isa_irq_pin(0, mp_ExtINT);
  1649. i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
  1650. /* Trust the MP table if nothing is setup in the hardware */
  1651. if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
  1652. printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
  1653. ioapic_i8259.pin = i8259_pin;
  1654. ioapic_i8259.apic = i8259_apic;
  1655. }
  1656. /* Complain if the MP table and the hardware disagree */
  1657. if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
  1658. (i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
  1659. {
  1660. printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
  1661. }
  1662. /*
  1663. * Do not trust the IO-APIC being empty at bootup
  1664. */
  1665. clear_IO_APIC();
  1666. }
  1667. /*
  1668. * Not an __init, needed by the reboot code
  1669. */
  1670. void disable_IO_APIC(void)
  1671. {
  1672. /*
  1673. * Clear the IO-APIC before rebooting:
  1674. */
  1675. clear_IO_APIC();
  1676. if (!legacy_pic->nr_legacy_irqs)
  1677. return;
  1678. /*
  1679. * If the i8259 is routed through an IOAPIC
  1680. * Put that IOAPIC in virtual wire mode
  1681. * so legacy interrupts can be delivered.
  1682. *
  1683. * With interrupt-remapping, for now we will use virtual wire A mode,
  1684. * as virtual wire B is little complex (need to configure both
  1685. * IOAPIC RTE aswell as interrupt-remapping table entry).
  1686. * As this gets called during crash dump, keep this simple for now.
  1687. */
  1688. if (ioapic_i8259.pin != -1 && !intr_remapping_enabled) {
  1689. struct IO_APIC_route_entry entry;
  1690. memset(&entry, 0, sizeof(entry));
  1691. entry.mask = 0; /* Enabled */
  1692. entry.trigger = 0; /* Edge */
  1693. entry.irr = 0;
  1694. entry.polarity = 0; /* High */
  1695. entry.delivery_status = 0;
  1696. entry.dest_mode = 0; /* Physical */
  1697. entry.delivery_mode = dest_ExtINT; /* ExtInt */
  1698. entry.vector = 0;
  1699. entry.dest = read_apic_id();
  1700. /*
  1701. * Add it to the IO-APIC irq-routing table:
  1702. */
  1703. ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
  1704. }
  1705. /*
  1706. * Use virtual wire A mode when interrupt remapping is enabled.
  1707. */
  1708. if (cpu_has_apic || apic_from_smp_config())
  1709. disconnect_bsp_APIC(!intr_remapping_enabled &&
  1710. ioapic_i8259.pin != -1);
  1711. }
  1712. #ifdef CONFIG_X86_32
  1713. /*
  1714. * function to set the IO-APIC physical IDs based on the
  1715. * values stored in the MPC table.
  1716. *
  1717. * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
  1718. */
  1719. void __init setup_ioapic_ids_from_mpc(void)
  1720. {
  1721. union IO_APIC_reg_00 reg_00;
  1722. physid_mask_t phys_id_present_map;
  1723. int apic_id;
  1724. int i;
  1725. unsigned char old_id;
  1726. unsigned long flags;
  1727. if (acpi_ioapic)
  1728. return;
  1729. /*
  1730. * Don't check I/O APIC IDs for xAPIC systems. They have
  1731. * no meaning without the serial APIC bus.
  1732. */
  1733. if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
  1734. || APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  1735. return;
  1736. /*
  1737. * This is broken; anything with a real cpu count has to
  1738. * circumvent this idiocy regardless.
  1739. */
  1740. apic->ioapic_phys_id_map(&phys_cpu_present_map, &phys_id_present_map);
  1741. /*
  1742. * Set the IOAPIC ID to the value stored in the MPC table.
  1743. */
  1744. for (apic_id = 0; apic_id < nr_ioapics; apic_id++) {
  1745. /* Read the register 0 value */
  1746. raw_spin_lock_irqsave(&ioapic_lock, flags);
  1747. reg_00.raw = io_apic_read(apic_id, 0);
  1748. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  1749. old_id = mp_ioapics[apic_id].apicid;
  1750. if (mp_ioapics[apic_id].apicid >= get_physical_broadcast()) {
  1751. printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
  1752. apic_id, mp_ioapics[apic_id].apicid);
  1753. printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
  1754. reg_00.bits.ID);
  1755. mp_ioapics[apic_id].apicid = reg_00.bits.ID;
  1756. }
  1757. /*
  1758. * Sanity check, is the ID really free? Every APIC in a
  1759. * system must have a unique ID or we get lots of nice
  1760. * 'stuck on smp_invalidate_needed IPI wait' messages.
  1761. */
  1762. if (apic->check_apicid_used(&phys_id_present_map,
  1763. mp_ioapics[apic_id].apicid)) {
  1764. printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n",
  1765. apic_id, mp_ioapics[apic_id].apicid);
  1766. for (i = 0; i < get_physical_broadcast(); i++)
  1767. if (!physid_isset(i, phys_id_present_map))
  1768. break;
  1769. if (i >= get_physical_broadcast())
  1770. panic("Max APIC ID exceeded!\n");
  1771. printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
  1772. i);
  1773. physid_set(i, phys_id_present_map);
  1774. mp_ioapics[apic_id].apicid = i;
  1775. } else {
  1776. physid_mask_t tmp;
  1777. apic->apicid_to_cpu_present(mp_ioapics[apic_id].apicid, &tmp);
  1778. apic_printk(APIC_VERBOSE, "Setting %d in the "
  1779. "phys_id_present_map\n",
  1780. mp_ioapics[apic_id].apicid);
  1781. physids_or(phys_id_present_map, phys_id_present_map, tmp);
  1782. }
  1783. /*
  1784. * We need to adjust the IRQ routing table
  1785. * if the ID changed.
  1786. */
  1787. if (old_id != mp_ioapics[apic_id].apicid)
  1788. for (i = 0; i < mp_irq_entries; i++)
  1789. if (mp_irqs[i].dstapic == old_id)
  1790. mp_irqs[i].dstapic
  1791. = mp_ioapics[apic_id].apicid;
  1792. /*
  1793. * Read the right value from the MPC table and
  1794. * write it into the ID register.
  1795. */
  1796. apic_printk(APIC_VERBOSE, KERN_INFO
  1797. "...changing IO-APIC physical APIC ID to %d ...",
  1798. mp_ioapics[apic_id].apicid);
  1799. reg_00.bits.ID = mp_ioapics[apic_id].apicid;
  1800. raw_spin_lock_irqsave(&ioapic_lock, flags);
  1801. io_apic_write(apic_id, 0, reg_00.raw);
  1802. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  1803. /*
  1804. * Sanity check
  1805. */
  1806. raw_spin_lock_irqsave(&ioapic_lock, flags);
  1807. reg_00.raw = io_apic_read(apic_id, 0);
  1808. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  1809. if (reg_00.bits.ID != mp_ioapics[apic_id].apicid)
  1810. printk("could not set ID!\n");
  1811. else
  1812. apic_printk(APIC_VERBOSE, " ok.\n");
  1813. }
  1814. }
  1815. #endif
  1816. int no_timer_check __initdata;
  1817. static int __init notimercheck(char *s)
  1818. {
  1819. no_timer_check = 1;
  1820. return 1;
  1821. }
  1822. __setup("no_timer_check", notimercheck);
  1823. /*
  1824. * There is a nasty bug in some older SMP boards, their mptable lies
  1825. * about the timer IRQ. We do the following to work around the situation:
  1826. *
  1827. * - timer IRQ defaults to IO-APIC IRQ
  1828. * - if this function detects that timer IRQs are defunct, then we fall
  1829. * back to ISA timer IRQs
  1830. */
  1831. static int __init timer_irq_works(void)
  1832. {
  1833. unsigned long t1 = jiffies;
  1834. unsigned long flags;
  1835. if (no_timer_check)
  1836. return 1;
  1837. local_save_flags(flags);
  1838. local_irq_enable();
  1839. /* Let ten ticks pass... */
  1840. mdelay((10 * 1000) / HZ);
  1841. local_irq_restore(flags);
  1842. /*
  1843. * Expect a few ticks at least, to be sure some possible
  1844. * glue logic does not lock up after one or two first
  1845. * ticks in a non-ExtINT mode. Also the local APIC
  1846. * might have cached one ExtINT interrupt. Finally, at
  1847. * least one tick may be lost due to delays.
  1848. */
  1849. /* jiffies wrap? */
  1850. if (time_after(jiffies, t1 + 4))
  1851. return 1;
  1852. return 0;
  1853. }
  1854. /*
  1855. * In the SMP+IOAPIC case it might happen that there are an unspecified
  1856. * number of pending IRQ events unhandled. These cases are very rare,
  1857. * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
  1858. * better to do it this way as thus we do not have to be aware of
  1859. * 'pending' interrupts in the IRQ path, except at this point.
  1860. */
  1861. /*
  1862. * Edge triggered needs to resend any interrupt
  1863. * that was delayed but this is now handled in the device
  1864. * independent code.
  1865. */
  1866. /*
  1867. * Starting up a edge-triggered IO-APIC interrupt is
  1868. * nasty - we need to make sure that we get the edge.
  1869. * If it is already asserted for some reason, we need
  1870. * return 1 to indicate that is was pending.
  1871. *
  1872. * This is not complete - we should be able to fake
  1873. * an edge even if it isn't on the 8259A...
  1874. */
  1875. static unsigned int startup_ioapic_irq(struct irq_data *data)
  1876. {
  1877. int was_pending = 0, irq = data->irq;
  1878. unsigned long flags;
  1879. raw_spin_lock_irqsave(&ioapic_lock, flags);
  1880. if (irq < legacy_pic->nr_legacy_irqs) {
  1881. legacy_pic->mask(irq);
  1882. if (legacy_pic->irq_pending(irq))
  1883. was_pending = 1;
  1884. }
  1885. __unmask_ioapic(data->chip_data);
  1886. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  1887. return was_pending;
  1888. }
  1889. static int ioapic_retrigger_irq(unsigned int irq)
  1890. {
  1891. struct irq_cfg *cfg = irq_cfg(irq);
  1892. unsigned long flags;
  1893. raw_spin_lock_irqsave(&vector_lock, flags);
  1894. apic->send_IPI_mask(cpumask_of(cpumask_first(cfg->domain)), cfg->vector);
  1895. raw_spin_unlock_irqrestore(&vector_lock, flags);
  1896. return 1;
  1897. }
  1898. /*
  1899. * Level and edge triggered IO-APIC interrupts need different handling,
  1900. * so we use two separate IRQ descriptors. Edge triggered IRQs can be
  1901. * handled with the level-triggered descriptor, but that one has slightly
  1902. * more overhead. Level-triggered interrupts cannot be handled with the
  1903. * edge-triggered handler, without risking IRQ storms and other ugly
  1904. * races.
  1905. */
  1906. #ifdef CONFIG_SMP
  1907. void send_cleanup_vector(struct irq_cfg *cfg)
  1908. {
  1909. cpumask_var_t cleanup_mask;
  1910. if (unlikely(!alloc_cpumask_var(&cleanup_mask, GFP_ATOMIC))) {
  1911. unsigned int i;
  1912. for_each_cpu_and(i, cfg->old_domain, cpu_online_mask)
  1913. apic->send_IPI_mask(cpumask_of(i), IRQ_MOVE_CLEANUP_VECTOR);
  1914. } else {
  1915. cpumask_and(cleanup_mask, cfg->old_domain, cpu_online_mask);
  1916. apic->send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
  1917. free_cpumask_var(cleanup_mask);
  1918. }
  1919. cfg->move_in_progress = 0;
  1920. }
  1921. static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, struct irq_cfg *cfg)
  1922. {
  1923. int apic, pin;
  1924. struct irq_pin_list *entry;
  1925. u8 vector = cfg->vector;
  1926. for_each_irq_pin(entry, cfg->irq_2_pin) {
  1927. unsigned int reg;
  1928. apic = entry->apic;
  1929. pin = entry->pin;
  1930. /*
  1931. * With interrupt-remapping, destination information comes
  1932. * from interrupt-remapping table entry.
  1933. */
  1934. if (!irq_remapped(irq))
  1935. io_apic_write(apic, 0x11 + pin*2, dest);
  1936. reg = io_apic_read(apic, 0x10 + pin*2);
  1937. reg &= ~IO_APIC_REDIR_VECTOR_MASK;
  1938. reg |= vector;
  1939. io_apic_modify(apic, 0x10 + pin*2, reg);
  1940. }
  1941. }
  1942. /*
  1943. * Either sets desc->affinity to a valid value, and returns
  1944. * ->cpu_mask_to_apicid of that in dest_id, or returns -1 and
  1945. * leaves desc->affinity untouched.
  1946. */
  1947. unsigned int
  1948. set_desc_affinity(struct irq_desc *desc, const struct cpumask *mask,
  1949. unsigned int *dest_id)
  1950. {
  1951. struct irq_cfg *cfg;
  1952. unsigned int irq;
  1953. if (!cpumask_intersects(mask, cpu_online_mask))
  1954. return -1;
  1955. irq = desc->irq;
  1956. cfg = get_irq_desc_chip_data(desc);
  1957. if (assign_irq_vector(irq, cfg, mask))
  1958. return -1;
  1959. cpumask_copy(desc->affinity, mask);
  1960. *dest_id = apic->cpu_mask_to_apicid_and(desc->affinity, cfg->domain);
  1961. return 0;
  1962. }
  1963. static int
  1964. set_ioapic_affinity_irq_desc(struct irq_desc *desc, const struct cpumask *mask)
  1965. {
  1966. struct irq_cfg *cfg;
  1967. unsigned long flags;
  1968. unsigned int dest;
  1969. unsigned int irq;
  1970. int ret = -1;
  1971. irq = desc->irq;
  1972. cfg = get_irq_desc_chip_data(desc);
  1973. raw_spin_lock_irqsave(&ioapic_lock, flags);
  1974. ret = set_desc_affinity(desc, mask, &dest);
  1975. if (!ret) {
  1976. /* Only the high 8 bits are valid. */
  1977. dest = SET_APIC_LOGICAL_ID(dest);
  1978. __target_IO_APIC_irq(irq, dest, cfg);
  1979. }
  1980. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  1981. return ret;
  1982. }
  1983. static int
  1984. set_ioapic_affinity_irq(unsigned int irq, const struct cpumask *mask)
  1985. {
  1986. struct irq_desc *desc;
  1987. desc = irq_to_desc(irq);
  1988. return set_ioapic_affinity_irq_desc(desc, mask);
  1989. }
  1990. #ifdef CONFIG_INTR_REMAP
  1991. /*
  1992. * Migrate the IO-APIC irq in the presence of intr-remapping.
  1993. *
  1994. * For both level and edge triggered, irq migration is a simple atomic
  1995. * update(of vector and cpu destination) of IRTE and flush the hardware cache.
  1996. *
  1997. * For level triggered, we eliminate the io-apic RTE modification (with the
  1998. * updated vector information), by using a virtual vector (io-apic pin number).
  1999. * Real vector that is used for interrupting cpu will be coming from
  2000. * the interrupt-remapping table entry.
  2001. */
  2002. static int
  2003. migrate_ioapic_irq_desc(struct irq_desc *desc, const struct cpumask *mask)
  2004. {
  2005. struct irq_cfg *cfg;
  2006. struct irte irte;
  2007. unsigned int dest;
  2008. unsigned int irq;
  2009. int ret = -1;
  2010. if (!cpumask_intersects(mask, cpu_online_mask))
  2011. return ret;
  2012. irq = desc->irq;
  2013. if (get_irte(irq, &irte))
  2014. return ret;
  2015. cfg = get_irq_desc_chip_data(desc);
  2016. if (assign_irq_vector(irq, cfg, mask))
  2017. return ret;
  2018. dest = apic->cpu_mask_to_apicid_and(cfg->domain, mask);
  2019. irte.vector = cfg->vector;
  2020. irte.dest_id = IRTE_DEST(dest);
  2021. /*
  2022. * Modified the IRTE and flushes the Interrupt entry cache.
  2023. */
  2024. modify_irte(irq, &irte);
  2025. if (cfg->move_in_progress)
  2026. send_cleanup_vector(cfg);
  2027. cpumask_copy(desc->affinity, mask);
  2028. return 0;
  2029. }
  2030. /*
  2031. * Migrates the IRQ destination in the process context.
  2032. */
  2033. static int set_ir_ioapic_affinity_irq_desc(struct irq_desc *desc,
  2034. const struct cpumask *mask)
  2035. {
  2036. return migrate_ioapic_irq_desc(desc, mask);
  2037. }
  2038. static int set_ir_ioapic_affinity_irq(unsigned int irq,
  2039. const struct cpumask *mask)
  2040. {
  2041. struct irq_desc *desc = irq_to_desc(irq);
  2042. return set_ir_ioapic_affinity_irq_desc(desc, mask);
  2043. }
  2044. #else
  2045. static inline int set_ir_ioapic_affinity_irq_desc(struct irq_desc *desc,
  2046. const struct cpumask *mask)
  2047. {
  2048. return 0;
  2049. }
  2050. #endif
  2051. asmlinkage void smp_irq_move_cleanup_interrupt(void)
  2052. {
  2053. unsigned vector, me;
  2054. ack_APIC_irq();
  2055. exit_idle();
  2056. irq_enter();
  2057. me = smp_processor_id();
  2058. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
  2059. unsigned int irq;
  2060. unsigned int irr;
  2061. struct irq_desc *desc;
  2062. struct irq_cfg *cfg;
  2063. irq = __get_cpu_var(vector_irq)[vector];
  2064. if (irq == -1)
  2065. continue;
  2066. desc = irq_to_desc(irq);
  2067. if (!desc)
  2068. continue;
  2069. cfg = irq_cfg(irq);
  2070. raw_spin_lock(&desc->lock);
  2071. /*
  2072. * Check if the irq migration is in progress. If so, we
  2073. * haven't received the cleanup request yet for this irq.
  2074. */
  2075. if (cfg->move_in_progress)
  2076. goto unlock;
  2077. if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
  2078. goto unlock;
  2079. irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
  2080. /*
  2081. * Check if the vector that needs to be cleanedup is
  2082. * registered at the cpu's IRR. If so, then this is not
  2083. * the best time to clean it up. Lets clean it up in the
  2084. * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
  2085. * to myself.
  2086. */
  2087. if (irr & (1 << (vector % 32))) {
  2088. apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
  2089. goto unlock;
  2090. }
  2091. __get_cpu_var(vector_irq)[vector] = -1;
  2092. unlock:
  2093. raw_spin_unlock(&desc->lock);
  2094. }
  2095. irq_exit();
  2096. }
  2097. static void __irq_complete_move(struct irq_cfg *cfg, unsigned vector)
  2098. {
  2099. unsigned me;
  2100. if (likely(!cfg->move_in_progress))
  2101. return;
  2102. me = smp_processor_id();
  2103. if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
  2104. send_cleanup_vector(cfg);
  2105. }
  2106. static void irq_complete_move(struct irq_cfg *cfg)
  2107. {
  2108. __irq_complete_move(cfg, ~get_irq_regs()->orig_ax);
  2109. }
  2110. void irq_force_complete_move(int irq)
  2111. {
  2112. struct irq_cfg *cfg = get_irq_chip_data(irq);
  2113. if (!cfg)
  2114. return;
  2115. __irq_complete_move(cfg, cfg->vector);
  2116. }
  2117. #else
  2118. static inline void irq_complete_move(struct irq_cfg *cfg) { }
  2119. #endif
  2120. static void ack_apic_edge(unsigned int irq)
  2121. {
  2122. struct irq_cfg *cfg = get_irq_chip_data(irq);
  2123. irq_complete_move(cfg);
  2124. move_native_irq(irq);
  2125. ack_APIC_irq();
  2126. }
  2127. atomic_t irq_mis_count;
  2128. /*
  2129. * IO-APIC versions below 0x20 don't support EOI register.
  2130. * For the record, here is the information about various versions:
  2131. * 0Xh 82489DX
  2132. * 1Xh I/OAPIC or I/O(x)APIC which are not PCI 2.2 Compliant
  2133. * 2Xh I/O(x)APIC which is PCI 2.2 Compliant
  2134. * 30h-FFh Reserved
  2135. *
  2136. * Some of the Intel ICH Specs (ICH2 to ICH5) documents the io-apic
  2137. * version as 0x2. This is an error with documentation and these ICH chips
  2138. * use io-apic's of version 0x20.
  2139. *
  2140. * For IO-APIC's with EOI register, we use that to do an explicit EOI.
  2141. * Otherwise, we simulate the EOI message manually by changing the trigger
  2142. * mode to edge and then back to level, with RTE being masked during this.
  2143. */
  2144. static void eoi_ioapic_irq(unsigned int irq, struct irq_cfg *cfg)
  2145. {
  2146. struct irq_pin_list *entry;
  2147. unsigned long flags;
  2148. raw_spin_lock_irqsave(&ioapic_lock, flags);
  2149. for_each_irq_pin(entry, cfg->irq_2_pin) {
  2150. if (mp_ioapics[entry->apic].apicver >= 0x20) {
  2151. /*
  2152. * Intr-remapping uses pin number as the virtual vector
  2153. * in the RTE. Actual vector is programmed in
  2154. * intr-remapping table entry. Hence for the io-apic
  2155. * EOI we use the pin number.
  2156. */
  2157. if (irq_remapped(irq))
  2158. io_apic_eoi(entry->apic, entry->pin);
  2159. else
  2160. io_apic_eoi(entry->apic, cfg->vector);
  2161. } else {
  2162. __mask_and_edge_IO_APIC_irq(entry);
  2163. __unmask_and_level_IO_APIC_irq(entry);
  2164. }
  2165. }
  2166. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  2167. }
  2168. static void ack_apic_level(unsigned int irq)
  2169. {
  2170. struct irq_desc *desc = irq_to_desc(irq);
  2171. struct irq_cfg *cfg = get_irq_desc_chip_data(desc);
  2172. int i, do_unmask_irq = 0;
  2173. unsigned long v;
  2174. irq_complete_move(cfg);
  2175. #ifdef CONFIG_GENERIC_PENDING_IRQ
  2176. /* If we are moving the irq we need to mask it */
  2177. if (unlikely(desc->status & IRQ_MOVE_PENDING)) {
  2178. do_unmask_irq = 1;
  2179. mask_ioapic(cfg);
  2180. }
  2181. #endif
  2182. /*
  2183. * It appears there is an erratum which affects at least version 0x11
  2184. * of I/O APIC (that's the 82093AA and cores integrated into various
  2185. * chipsets). Under certain conditions a level-triggered interrupt is
  2186. * erroneously delivered as edge-triggered one but the respective IRR
  2187. * bit gets set nevertheless. As a result the I/O unit expects an EOI
  2188. * message but it will never arrive and further interrupts are blocked
  2189. * from the source. The exact reason is so far unknown, but the
  2190. * phenomenon was observed when two consecutive interrupt requests
  2191. * from a given source get delivered to the same CPU and the source is
  2192. * temporarily disabled in between.
  2193. *
  2194. * A workaround is to simulate an EOI message manually. We achieve it
  2195. * by setting the trigger mode to edge and then to level when the edge
  2196. * trigger mode gets detected in the TMR of a local APIC for a
  2197. * level-triggered interrupt. We mask the source for the time of the
  2198. * operation to prevent an edge-triggered interrupt escaping meanwhile.
  2199. * The idea is from Manfred Spraul. --macro
  2200. *
  2201. * Also in the case when cpu goes offline, fixup_irqs() will forward
  2202. * any unhandled interrupt on the offlined cpu to the new cpu
  2203. * destination that is handling the corresponding interrupt. This
  2204. * interrupt forwarding is done via IPI's. Hence, in this case also
  2205. * level-triggered io-apic interrupt will be seen as an edge
  2206. * interrupt in the IRR. And we can't rely on the cpu's EOI
  2207. * to be broadcasted to the IO-APIC's which will clear the remoteIRR
  2208. * corresponding to the level-triggered interrupt. Hence on IO-APIC's
  2209. * supporting EOI register, we do an explicit EOI to clear the
  2210. * remote IRR and on IO-APIC's which don't have an EOI register,
  2211. * we use the above logic (mask+edge followed by unmask+level) from
  2212. * Manfred Spraul to clear the remote IRR.
  2213. */
  2214. i = cfg->vector;
  2215. v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
  2216. /*
  2217. * We must acknowledge the irq before we move it or the acknowledge will
  2218. * not propagate properly.
  2219. */
  2220. ack_APIC_irq();
  2221. /*
  2222. * Tail end of clearing remote IRR bit (either by delivering the EOI
  2223. * message via io-apic EOI register write or simulating it using
  2224. * mask+edge followed by unnask+level logic) manually when the
  2225. * level triggered interrupt is seen as the edge triggered interrupt
  2226. * at the cpu.
  2227. */
  2228. if (!(v & (1 << (i & 0x1f)))) {
  2229. atomic_inc(&irq_mis_count);
  2230. eoi_ioapic_irq(irq, cfg);
  2231. }
  2232. /* Now we can move and renable the irq */
  2233. if (unlikely(do_unmask_irq)) {
  2234. /* Only migrate the irq if the ack has been received.
  2235. *
  2236. * On rare occasions the broadcast level triggered ack gets
  2237. * delayed going to ioapics, and if we reprogram the
  2238. * vector while Remote IRR is still set the irq will never
  2239. * fire again.
  2240. *
  2241. * To prevent this scenario we read the Remote IRR bit
  2242. * of the ioapic. This has two effects.
  2243. * - On any sane system the read of the ioapic will
  2244. * flush writes (and acks) going to the ioapic from
  2245. * this cpu.
  2246. * - We get to see if the ACK has actually been delivered.
  2247. *
  2248. * Based on failed experiments of reprogramming the
  2249. * ioapic entry from outside of irq context starting
  2250. * with masking the ioapic entry and then polling until
  2251. * Remote IRR was clear before reprogramming the
  2252. * ioapic I don't trust the Remote IRR bit to be
  2253. * completey accurate.
  2254. *
  2255. * However there appears to be no other way to plug
  2256. * this race, so if the Remote IRR bit is not
  2257. * accurate and is causing problems then it is a hardware bug
  2258. * and you can go talk to the chipset vendor about it.
  2259. */
  2260. if (!io_apic_level_ack_pending(cfg))
  2261. move_masked_irq(irq);
  2262. unmask_ioapic(cfg);
  2263. }
  2264. }
  2265. #ifdef CONFIG_INTR_REMAP
  2266. static void ir_ack_apic_edge(unsigned int irq)
  2267. {
  2268. ack_APIC_irq();
  2269. }
  2270. static void ir_ack_apic_level(unsigned int irq)
  2271. {
  2272. struct irq_cfg *cfg = get_irq_chip_data(irq);
  2273. ack_APIC_irq();
  2274. eoi_ioapic_irq(irq, cfg);
  2275. }
  2276. #endif /* CONFIG_INTR_REMAP */
  2277. static struct irq_chip ioapic_chip __read_mostly = {
  2278. .name = "IO-APIC",
  2279. .irq_startup = startup_ioapic_irq,
  2280. .mask = mask_ioapic_irq,
  2281. .unmask = unmask_ioapic_irq,
  2282. .ack = ack_apic_edge,
  2283. .eoi = ack_apic_level,
  2284. #ifdef CONFIG_SMP
  2285. .set_affinity = set_ioapic_affinity_irq,
  2286. #endif
  2287. .retrigger = ioapic_retrigger_irq,
  2288. };
  2289. static struct irq_chip ir_ioapic_chip __read_mostly = {
  2290. .name = "IR-IO-APIC",
  2291. .irq_startup = startup_ioapic_irq,
  2292. .mask = mask_ioapic_irq,
  2293. .unmask = unmask_ioapic_irq,
  2294. #ifdef CONFIG_INTR_REMAP
  2295. .ack = ir_ack_apic_edge,
  2296. .eoi = ir_ack_apic_level,
  2297. #ifdef CONFIG_SMP
  2298. .set_affinity = set_ir_ioapic_affinity_irq,
  2299. #endif
  2300. #endif
  2301. .retrigger = ioapic_retrigger_irq,
  2302. };
  2303. static inline void init_IO_APIC_traps(void)
  2304. {
  2305. int irq;
  2306. struct irq_desc *desc;
  2307. struct irq_cfg *cfg;
  2308. /*
  2309. * NOTE! The local APIC isn't very good at handling
  2310. * multiple interrupts at the same interrupt level.
  2311. * As the interrupt level is determined by taking the
  2312. * vector number and shifting that right by 4, we
  2313. * want to spread these out a bit so that they don't
  2314. * all fall in the same interrupt level.
  2315. *
  2316. * Also, we've got to be careful not to trash gate
  2317. * 0x80, because int 0x80 is hm, kind of importantish. ;)
  2318. */
  2319. for_each_irq_desc(irq, desc) {
  2320. cfg = get_irq_desc_chip_data(desc);
  2321. if (IO_APIC_IRQ(irq) && cfg && !cfg->vector) {
  2322. /*
  2323. * Hmm.. We don't have an entry for this,
  2324. * so default to an old-fashioned 8259
  2325. * interrupt if we can..
  2326. */
  2327. if (irq < legacy_pic->nr_legacy_irqs)
  2328. legacy_pic->make_irq(irq);
  2329. else
  2330. /* Strange. Oh, well.. */
  2331. desc->chip = &no_irq_chip;
  2332. }
  2333. }
  2334. }
  2335. /*
  2336. * The local APIC irq-chip implementation:
  2337. */
  2338. static void mask_lapic_irq(unsigned int irq)
  2339. {
  2340. unsigned long v;
  2341. v = apic_read(APIC_LVT0);
  2342. apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
  2343. }
  2344. static void unmask_lapic_irq(unsigned int irq)
  2345. {
  2346. unsigned long v;
  2347. v = apic_read(APIC_LVT0);
  2348. apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
  2349. }
  2350. static void ack_lapic_irq(unsigned int irq)
  2351. {
  2352. ack_APIC_irq();
  2353. }
  2354. static struct irq_chip lapic_chip __read_mostly = {
  2355. .name = "local-APIC",
  2356. .mask = mask_lapic_irq,
  2357. .unmask = unmask_lapic_irq,
  2358. .ack = ack_lapic_irq,
  2359. };
  2360. static void lapic_register_intr(int irq, struct irq_desc *desc)
  2361. {
  2362. desc->status &= ~IRQ_LEVEL;
  2363. set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
  2364. "edge");
  2365. }
  2366. static void __init setup_nmi(void)
  2367. {
  2368. /*
  2369. * Dirty trick to enable the NMI watchdog ...
  2370. * We put the 8259A master into AEOI mode and
  2371. * unmask on all local APICs LVT0 as NMI.
  2372. *
  2373. * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
  2374. * is from Maciej W. Rozycki - so we do not have to EOI from
  2375. * the NMI handler or the timer interrupt.
  2376. */
  2377. apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");
  2378. enable_NMI_through_LVT0();
  2379. apic_printk(APIC_VERBOSE, " done.\n");
  2380. }
  2381. /*
  2382. * This looks a bit hackish but it's about the only one way of sending
  2383. * a few INTA cycles to 8259As and any associated glue logic. ICR does
  2384. * not support the ExtINT mode, unfortunately. We need to send these
  2385. * cycles as some i82489DX-based boards have glue logic that keeps the
  2386. * 8259A interrupt line asserted until INTA. --macro
  2387. */
  2388. static inline void __init unlock_ExtINT_logic(void)
  2389. {
  2390. int apic, pin, i;
  2391. struct IO_APIC_route_entry entry0, entry1;
  2392. unsigned char save_control, save_freq_select;
  2393. pin = find_isa_irq_pin(8, mp_INT);
  2394. if (pin == -1) {
  2395. WARN_ON_ONCE(1);
  2396. return;
  2397. }
  2398. apic = find_isa_irq_apic(8, mp_INT);
  2399. if (apic == -1) {
  2400. WARN_ON_ONCE(1);
  2401. return;
  2402. }
  2403. entry0 = ioapic_read_entry(apic, pin);
  2404. clear_IO_APIC_pin(apic, pin);
  2405. memset(&entry1, 0, sizeof(entry1));
  2406. entry1.dest_mode = 0; /* physical delivery */
  2407. entry1.mask = 0; /* unmask IRQ now */
  2408. entry1.dest = hard_smp_processor_id();
  2409. entry1.delivery_mode = dest_ExtINT;
  2410. entry1.polarity = entry0.polarity;
  2411. entry1.trigger = 0;
  2412. entry1.vector = 0;
  2413. ioapic_write_entry(apic, pin, entry1);
  2414. save_control = CMOS_READ(RTC_CONTROL);
  2415. save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
  2416. CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
  2417. RTC_FREQ_SELECT);
  2418. CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
  2419. i = 100;
  2420. while (i-- > 0) {
  2421. mdelay(10);
  2422. if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
  2423. i -= 10;
  2424. }
  2425. CMOS_WRITE(save_control, RTC_CONTROL);
  2426. CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
  2427. clear_IO_APIC_pin(apic, pin);
  2428. ioapic_write_entry(apic, pin, entry0);
  2429. }
  2430. static int disable_timer_pin_1 __initdata;
  2431. /* Actually the next is obsolete, but keep it for paranoid reasons -AK */
  2432. static int __init disable_timer_pin_setup(char *arg)
  2433. {
  2434. disable_timer_pin_1 = 1;
  2435. return 0;
  2436. }
  2437. early_param("disable_timer_pin_1", disable_timer_pin_setup);
  2438. int timer_through_8259 __initdata;
  2439. /*
  2440. * This code may look a bit paranoid, but it's supposed to cooperate with
  2441. * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
  2442. * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
  2443. * fanatically on his truly buggy board.
  2444. *
  2445. * FIXME: really need to revamp this for all platforms.
  2446. */
  2447. static inline void __init check_timer(void)
  2448. {
  2449. struct irq_desc *desc = irq_to_desc(0);
  2450. struct irq_cfg *cfg = get_irq_desc_chip_data(desc);
  2451. int node = cpu_to_node(0);
  2452. int apic1, pin1, apic2, pin2;
  2453. unsigned long flags;
  2454. int no_pin1 = 0;
  2455. local_irq_save(flags);
  2456. /*
  2457. * get/set the timer IRQ vector:
  2458. */
  2459. legacy_pic->mask(0);
  2460. assign_irq_vector(0, cfg, apic->target_cpus());
  2461. /*
  2462. * As IRQ0 is to be enabled in the 8259A, the virtual
  2463. * wire has to be disabled in the local APIC. Also
  2464. * timer interrupts need to be acknowledged manually in
  2465. * the 8259A for the i82489DX when using the NMI
  2466. * watchdog as that APIC treats NMIs as level-triggered.
  2467. * The AEOI mode will finish them in the 8259A
  2468. * automatically.
  2469. */
  2470. apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
  2471. legacy_pic->init(1);
  2472. #ifdef CONFIG_X86_32
  2473. {
  2474. unsigned int ver;
  2475. ver = apic_read(APIC_LVR);
  2476. ver = GET_APIC_VERSION(ver);
  2477. timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver));
  2478. }
  2479. #endif
  2480. pin1 = find_isa_irq_pin(0, mp_INT);
  2481. apic1 = find_isa_irq_apic(0, mp_INT);
  2482. pin2 = ioapic_i8259.pin;
  2483. apic2 = ioapic_i8259.apic;
  2484. apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X "
  2485. "apic1=%d pin1=%d apic2=%d pin2=%d\n",
  2486. cfg->vector, apic1, pin1, apic2, pin2);
  2487. /*
  2488. * Some BIOS writers are clueless and report the ExtINTA
  2489. * I/O APIC input from the cascaded 8259A as the timer
  2490. * interrupt input. So just in case, if only one pin
  2491. * was found above, try it both directly and through the
  2492. * 8259A.
  2493. */
  2494. if (pin1 == -1) {
  2495. if (intr_remapping_enabled)
  2496. panic("BIOS bug: timer not connected to IO-APIC");
  2497. pin1 = pin2;
  2498. apic1 = apic2;
  2499. no_pin1 = 1;
  2500. } else if (pin2 == -1) {
  2501. pin2 = pin1;
  2502. apic2 = apic1;
  2503. }
  2504. if (pin1 != -1) {
  2505. /*
  2506. * Ok, does IRQ0 through the IOAPIC work?
  2507. */
  2508. if (no_pin1) {
  2509. add_pin_to_irq_node(cfg, node, apic1, pin1);
  2510. setup_timer_IRQ0_pin(apic1, pin1, cfg->vector);
  2511. } else {
  2512. /* for edge trigger, setup_IO_APIC_irq already
  2513. * leave it unmasked.
  2514. * so only need to unmask if it is level-trigger
  2515. * do we really have level trigger timer?
  2516. */
  2517. int idx;
  2518. idx = find_irq_entry(apic1, pin1, mp_INT);
  2519. if (idx != -1 && irq_trigger(idx))
  2520. unmask_ioapic(cfg);
  2521. }
  2522. if (timer_irq_works()) {
  2523. if (nmi_watchdog == NMI_IO_APIC) {
  2524. setup_nmi();
  2525. legacy_pic->unmask(0);
  2526. }
  2527. if (disable_timer_pin_1 > 0)
  2528. clear_IO_APIC_pin(0, pin1);
  2529. goto out;
  2530. }
  2531. if (intr_remapping_enabled)
  2532. panic("timer doesn't work through Interrupt-remapped IO-APIC");
  2533. local_irq_disable();
  2534. clear_IO_APIC_pin(apic1, pin1);
  2535. if (!no_pin1)
  2536. apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: "
  2537. "8254 timer not connected to IO-APIC\n");
  2538. apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer "
  2539. "(IRQ0) through the 8259A ...\n");
  2540. apic_printk(APIC_QUIET, KERN_INFO
  2541. "..... (found apic %d pin %d) ...\n", apic2, pin2);
  2542. /*
  2543. * legacy devices should be connected to IO APIC #0
  2544. */
  2545. replace_pin_at_irq_node(cfg, node, apic1, pin1, apic2, pin2);
  2546. setup_timer_IRQ0_pin(apic2, pin2, cfg->vector);
  2547. legacy_pic->unmask(0);
  2548. if (timer_irq_works()) {
  2549. apic_printk(APIC_QUIET, KERN_INFO "....... works.\n");
  2550. timer_through_8259 = 1;
  2551. if (nmi_watchdog == NMI_IO_APIC) {
  2552. legacy_pic->mask(0);
  2553. setup_nmi();
  2554. legacy_pic->unmask(0);
  2555. }
  2556. goto out;
  2557. }
  2558. /*
  2559. * Cleanup, just in case ...
  2560. */
  2561. local_irq_disable();
  2562. legacy_pic->mask(0);
  2563. clear_IO_APIC_pin(apic2, pin2);
  2564. apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n");
  2565. }
  2566. if (nmi_watchdog == NMI_IO_APIC) {
  2567. apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work "
  2568. "through the IO-APIC - disabling NMI Watchdog!\n");
  2569. nmi_watchdog = NMI_NONE;
  2570. }
  2571. #ifdef CONFIG_X86_32
  2572. timer_ack = 0;
  2573. #endif
  2574. apic_printk(APIC_QUIET, KERN_INFO
  2575. "...trying to set up timer as Virtual Wire IRQ...\n");
  2576. lapic_register_intr(0, desc);
  2577. apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */
  2578. legacy_pic->unmask(0);
  2579. if (timer_irq_works()) {
  2580. apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
  2581. goto out;
  2582. }
  2583. local_irq_disable();
  2584. legacy_pic->mask(0);
  2585. apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector);
  2586. apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n");
  2587. apic_printk(APIC_QUIET, KERN_INFO
  2588. "...trying to set up timer as ExtINT IRQ...\n");
  2589. legacy_pic->init(0);
  2590. legacy_pic->make_irq(0);
  2591. apic_write(APIC_LVT0, APIC_DM_EXTINT);
  2592. unlock_ExtINT_logic();
  2593. if (timer_irq_works()) {
  2594. apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
  2595. goto out;
  2596. }
  2597. local_irq_disable();
  2598. apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n");
  2599. panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
  2600. "report. Then try booting with the 'noapic' option.\n");
  2601. out:
  2602. local_irq_restore(flags);
  2603. }
  2604. /*
  2605. * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
  2606. * to devices. However there may be an I/O APIC pin available for
  2607. * this interrupt regardless. The pin may be left unconnected, but
  2608. * typically it will be reused as an ExtINT cascade interrupt for
  2609. * the master 8259A. In the MPS case such a pin will normally be
  2610. * reported as an ExtINT interrupt in the MP table. With ACPI
  2611. * there is no provision for ExtINT interrupts, and in the absence
  2612. * of an override it would be treated as an ordinary ISA I/O APIC
  2613. * interrupt, that is edge-triggered and unmasked by default. We
  2614. * used to do this, but it caused problems on some systems because
  2615. * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
  2616. * the same ExtINT cascade interrupt to drive the local APIC of the
  2617. * bootstrap processor. Therefore we refrain from routing IRQ2 to
  2618. * the I/O APIC in all cases now. No actual device should request
  2619. * it anyway. --macro
  2620. */
  2621. #define PIC_IRQS (1UL << PIC_CASCADE_IR)
  2622. void __init setup_IO_APIC(void)
  2623. {
  2624. /*
  2625. * calling enable_IO_APIC() is moved to setup_local_APIC for BP
  2626. */
  2627. io_apic_irqs = legacy_pic->nr_legacy_irqs ? ~PIC_IRQS : ~0UL;
  2628. apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n");
  2629. /*
  2630. * Set up IO-APIC IRQ routing.
  2631. */
  2632. x86_init.mpparse.setup_ioapic_ids();
  2633. sync_Arb_IDs();
  2634. setup_IO_APIC_irqs();
  2635. init_IO_APIC_traps();
  2636. if (legacy_pic->nr_legacy_irqs)
  2637. check_timer();
  2638. }
  2639. /*
  2640. * Called after all the initialization is done. If we didnt find any
  2641. * APIC bugs then we can allow the modify fast path
  2642. */
  2643. static int __init io_apic_bug_finalize(void)
  2644. {
  2645. if (sis_apic_bug == -1)
  2646. sis_apic_bug = 0;
  2647. return 0;
  2648. }
  2649. late_initcall(io_apic_bug_finalize);
  2650. struct sysfs_ioapic_data {
  2651. struct sys_device dev;
  2652. struct IO_APIC_route_entry entry[0];
  2653. };
  2654. static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS];
  2655. static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
  2656. {
  2657. struct IO_APIC_route_entry *entry;
  2658. struct sysfs_ioapic_data *data;
  2659. int i;
  2660. data = container_of(dev, struct sysfs_ioapic_data, dev);
  2661. entry = data->entry;
  2662. for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ )
  2663. *entry = ioapic_read_entry(dev->id, i);
  2664. return 0;
  2665. }
  2666. static int ioapic_resume(struct sys_device *dev)
  2667. {
  2668. struct IO_APIC_route_entry *entry;
  2669. struct sysfs_ioapic_data *data;
  2670. unsigned long flags;
  2671. union IO_APIC_reg_00 reg_00;
  2672. int i;
  2673. data = container_of(dev, struct sysfs_ioapic_data, dev);
  2674. entry = data->entry;
  2675. raw_spin_lock_irqsave(&ioapic_lock, flags);
  2676. reg_00.raw = io_apic_read(dev->id, 0);
  2677. if (reg_00.bits.ID != mp_ioapics[dev->id].apicid) {
  2678. reg_00.bits.ID = mp_ioapics[dev->id].apicid;
  2679. io_apic_write(dev->id, 0, reg_00.raw);
  2680. }
  2681. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  2682. for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
  2683. ioapic_write_entry(dev->id, i, entry[i]);
  2684. return 0;
  2685. }
  2686. static struct sysdev_class ioapic_sysdev_class = {
  2687. .name = "ioapic",
  2688. .suspend = ioapic_suspend,
  2689. .resume = ioapic_resume,
  2690. };
  2691. static int __init ioapic_init_sysfs(void)
  2692. {
  2693. struct sys_device * dev;
  2694. int i, size, error;
  2695. error = sysdev_class_register(&ioapic_sysdev_class);
  2696. if (error)
  2697. return error;
  2698. for (i = 0; i < nr_ioapics; i++ ) {
  2699. size = sizeof(struct sys_device) + nr_ioapic_registers[i]
  2700. * sizeof(struct IO_APIC_route_entry);
  2701. mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL);
  2702. if (!mp_ioapic_data[i]) {
  2703. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  2704. continue;
  2705. }
  2706. dev = &mp_ioapic_data[i]->dev;
  2707. dev->id = i;
  2708. dev->cls = &ioapic_sysdev_class;
  2709. error = sysdev_register(dev);
  2710. if (error) {
  2711. kfree(mp_ioapic_data[i]);
  2712. mp_ioapic_data[i] = NULL;
  2713. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  2714. continue;
  2715. }
  2716. }
  2717. return 0;
  2718. }
  2719. device_initcall(ioapic_init_sysfs);
  2720. /*
  2721. * Dynamic irq allocate and deallocation
  2722. */
  2723. unsigned int create_irq_nr(unsigned int irq_want, int node)
  2724. {
  2725. /* Allocate an unused irq */
  2726. unsigned int irq;
  2727. unsigned int new;
  2728. unsigned long flags;
  2729. struct irq_cfg *cfg_new = NULL;
  2730. struct irq_desc *desc_new = NULL;
  2731. irq = 0;
  2732. if (irq_want < nr_irqs_gsi)
  2733. irq_want = nr_irqs_gsi;
  2734. raw_spin_lock_irqsave(&vector_lock, flags);
  2735. for (new = irq_want; new < nr_irqs; new++) {
  2736. desc_new = irq_to_desc_alloc_node(new, node);
  2737. if (!desc_new) {
  2738. printk(KERN_INFO "can not get irq_desc for %d\n", new);
  2739. continue;
  2740. }
  2741. cfg_new = get_irq_desc_chip_data(desc_new);
  2742. if (cfg_new->vector != 0)
  2743. continue;
  2744. desc_new = move_irq_desc(desc_new, node);
  2745. cfg_new = get_irq_desc_chip_data(desc_new);
  2746. if (__assign_irq_vector(new, cfg_new, apic->target_cpus()) == 0)
  2747. irq = new;
  2748. break;
  2749. }
  2750. raw_spin_unlock_irqrestore(&vector_lock, flags);
  2751. if (irq > 0)
  2752. dynamic_irq_init_keep_chip_data(irq);
  2753. return irq;
  2754. }
  2755. int create_irq(void)
  2756. {
  2757. int node = cpu_to_node(0);
  2758. unsigned int irq_want;
  2759. int irq;
  2760. irq_want = nr_irqs_gsi;
  2761. irq = create_irq_nr(irq_want, node);
  2762. if (irq == 0)
  2763. irq = -1;
  2764. return irq;
  2765. }
  2766. void destroy_irq(unsigned int irq)
  2767. {
  2768. unsigned long flags;
  2769. dynamic_irq_cleanup_keep_chip_data(irq);
  2770. free_irte(irq);
  2771. raw_spin_lock_irqsave(&vector_lock, flags);
  2772. __clear_irq_vector(irq, get_irq_chip_data(irq));
  2773. raw_spin_unlock_irqrestore(&vector_lock, flags);
  2774. }
  2775. /*
  2776. * MSI message composition
  2777. */
  2778. #ifdef CONFIG_PCI_MSI
  2779. static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq,
  2780. struct msi_msg *msg, u8 hpet_id)
  2781. {
  2782. struct irq_cfg *cfg;
  2783. int err;
  2784. unsigned dest;
  2785. if (disable_apic)
  2786. return -ENXIO;
  2787. cfg = irq_cfg(irq);
  2788. err = assign_irq_vector(irq, cfg, apic->target_cpus());
  2789. if (err)
  2790. return err;
  2791. dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
  2792. if (irq_remapped(irq)) {
  2793. struct irte irte;
  2794. int ir_index;
  2795. u16 sub_handle;
  2796. ir_index = map_irq_to_irte_handle(irq, &sub_handle);
  2797. BUG_ON(ir_index == -1);
  2798. prepare_irte(&irte, cfg->vector, dest);
  2799. /* Set source-id of interrupt request */
  2800. if (pdev)
  2801. set_msi_sid(&irte, pdev);
  2802. else
  2803. set_hpet_sid(&irte, hpet_id);
  2804. modify_irte(irq, &irte);
  2805. msg->address_hi = MSI_ADDR_BASE_HI;
  2806. msg->data = sub_handle;
  2807. msg->address_lo = MSI_ADDR_BASE_LO | MSI_ADDR_IR_EXT_INT |
  2808. MSI_ADDR_IR_SHV |
  2809. MSI_ADDR_IR_INDEX1(ir_index) |
  2810. MSI_ADDR_IR_INDEX2(ir_index);
  2811. } else {
  2812. if (x2apic_enabled())
  2813. msg->address_hi = MSI_ADDR_BASE_HI |
  2814. MSI_ADDR_EXT_DEST_ID(dest);
  2815. else
  2816. msg->address_hi = MSI_ADDR_BASE_HI;
  2817. msg->address_lo =
  2818. MSI_ADDR_BASE_LO |
  2819. ((apic->irq_dest_mode == 0) ?
  2820. MSI_ADDR_DEST_MODE_PHYSICAL:
  2821. MSI_ADDR_DEST_MODE_LOGICAL) |
  2822. ((apic->irq_delivery_mode != dest_LowestPrio) ?
  2823. MSI_ADDR_REDIRECTION_CPU:
  2824. MSI_ADDR_REDIRECTION_LOWPRI) |
  2825. MSI_ADDR_DEST_ID(dest);
  2826. msg->data =
  2827. MSI_DATA_TRIGGER_EDGE |
  2828. MSI_DATA_LEVEL_ASSERT |
  2829. ((apic->irq_delivery_mode != dest_LowestPrio) ?
  2830. MSI_DATA_DELIVERY_FIXED:
  2831. MSI_DATA_DELIVERY_LOWPRI) |
  2832. MSI_DATA_VECTOR(cfg->vector);
  2833. }
  2834. return err;
  2835. }
  2836. #ifdef CONFIG_SMP
  2837. static int set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
  2838. {
  2839. struct irq_desc *desc = irq_to_desc(irq);
  2840. struct irq_cfg *cfg;
  2841. struct msi_msg msg;
  2842. unsigned int dest;
  2843. if (set_desc_affinity(desc, mask, &dest))
  2844. return -1;
  2845. cfg = get_irq_desc_chip_data(desc);
  2846. __get_cached_msi_msg(desc->irq_data.msi_desc, &msg);
  2847. msg.data &= ~MSI_DATA_VECTOR_MASK;
  2848. msg.data |= MSI_DATA_VECTOR(cfg->vector);
  2849. msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
  2850. msg.address_lo |= MSI_ADDR_DEST_ID(dest);
  2851. __write_msi_msg(desc->irq_data.msi_desc, &msg);
  2852. return 0;
  2853. }
  2854. #ifdef CONFIG_INTR_REMAP
  2855. /*
  2856. * Migrate the MSI irq to another cpumask. This migration is
  2857. * done in the process context using interrupt-remapping hardware.
  2858. */
  2859. static int
  2860. ir_set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
  2861. {
  2862. struct irq_desc *desc = irq_to_desc(irq);
  2863. struct irq_cfg *cfg = get_irq_desc_chip_data(desc);
  2864. unsigned int dest;
  2865. struct irte irte;
  2866. if (get_irte(irq, &irte))
  2867. return -1;
  2868. if (set_desc_affinity(desc, mask, &dest))
  2869. return -1;
  2870. irte.vector = cfg->vector;
  2871. irte.dest_id = IRTE_DEST(dest);
  2872. /*
  2873. * atomically update the IRTE with the new destination and vector.
  2874. */
  2875. modify_irte(irq, &irte);
  2876. /*
  2877. * After this point, all the interrupts will start arriving
  2878. * at the new destination. So, time to cleanup the previous
  2879. * vector allocation.
  2880. */
  2881. if (cfg->move_in_progress)
  2882. send_cleanup_vector(cfg);
  2883. return 0;
  2884. }
  2885. #endif
  2886. #endif /* CONFIG_SMP */
  2887. /*
  2888. * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
  2889. * which implement the MSI or MSI-X Capability Structure.
  2890. */
  2891. static struct irq_chip msi_chip = {
  2892. .name = "PCI-MSI",
  2893. .irq_unmask = unmask_msi_irq,
  2894. .irq_mask = mask_msi_irq,
  2895. .ack = ack_apic_edge,
  2896. #ifdef CONFIG_SMP
  2897. .set_affinity = set_msi_irq_affinity,
  2898. #endif
  2899. .retrigger = ioapic_retrigger_irq,
  2900. };
  2901. static struct irq_chip msi_ir_chip = {
  2902. .name = "IR-PCI-MSI",
  2903. .irq_unmask = unmask_msi_irq,
  2904. .irq_mask = mask_msi_irq,
  2905. #ifdef CONFIG_INTR_REMAP
  2906. .ack = ir_ack_apic_edge,
  2907. #ifdef CONFIG_SMP
  2908. .set_affinity = ir_set_msi_irq_affinity,
  2909. #endif
  2910. #endif
  2911. .retrigger = ioapic_retrigger_irq,
  2912. };
  2913. /*
  2914. * Map the PCI dev to the corresponding remapping hardware unit
  2915. * and allocate 'nvec' consecutive interrupt-remapping table entries
  2916. * in it.
  2917. */
  2918. static int msi_alloc_irte(struct pci_dev *dev, int irq, int nvec)
  2919. {
  2920. struct intel_iommu *iommu;
  2921. int index;
  2922. iommu = map_dev_to_ir(dev);
  2923. if (!iommu) {
  2924. printk(KERN_ERR
  2925. "Unable to map PCI %s to iommu\n", pci_name(dev));
  2926. return -ENOENT;
  2927. }
  2928. index = alloc_irte(iommu, irq, nvec);
  2929. if (index < 0) {
  2930. printk(KERN_ERR
  2931. "Unable to allocate %d IRTE for PCI %s\n", nvec,
  2932. pci_name(dev));
  2933. return -ENOSPC;
  2934. }
  2935. return index;
  2936. }
  2937. static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq)
  2938. {
  2939. int ret;
  2940. struct msi_msg msg;
  2941. ret = msi_compose_msg(dev, irq, &msg, -1);
  2942. if (ret < 0)
  2943. return ret;
  2944. set_irq_msi(irq, msidesc);
  2945. write_msi_msg(irq, &msg);
  2946. if (irq_remapped(irq)) {
  2947. struct irq_desc *desc = irq_to_desc(irq);
  2948. /*
  2949. * irq migration in process context
  2950. */
  2951. desc->status |= IRQ_MOVE_PCNTXT;
  2952. set_irq_chip_and_handler_name(irq, &msi_ir_chip, handle_edge_irq, "edge");
  2953. } else
  2954. set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge");
  2955. dev_printk(KERN_DEBUG, &dev->dev, "irq %d for MSI/MSI-X\n", irq);
  2956. return 0;
  2957. }
  2958. int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
  2959. {
  2960. unsigned int irq;
  2961. int ret, sub_handle;
  2962. struct msi_desc *msidesc;
  2963. unsigned int irq_want;
  2964. struct intel_iommu *iommu = NULL;
  2965. int index = 0;
  2966. int node;
  2967. /* x86 doesn't support multiple MSI yet */
  2968. if (type == PCI_CAP_ID_MSI && nvec > 1)
  2969. return 1;
  2970. node = dev_to_node(&dev->dev);
  2971. irq_want = nr_irqs_gsi;
  2972. sub_handle = 0;
  2973. list_for_each_entry(msidesc, &dev->msi_list, list) {
  2974. irq = create_irq_nr(irq_want, node);
  2975. if (irq == 0)
  2976. return -1;
  2977. irq_want = irq + 1;
  2978. if (!intr_remapping_enabled)
  2979. goto no_ir;
  2980. if (!sub_handle) {
  2981. /*
  2982. * allocate the consecutive block of IRTE's
  2983. * for 'nvec'
  2984. */
  2985. index = msi_alloc_irte(dev, irq, nvec);
  2986. if (index < 0) {
  2987. ret = index;
  2988. goto error;
  2989. }
  2990. } else {
  2991. iommu = map_dev_to_ir(dev);
  2992. if (!iommu) {
  2993. ret = -ENOENT;
  2994. goto error;
  2995. }
  2996. /*
  2997. * setup the mapping between the irq and the IRTE
  2998. * base index, the sub_handle pointing to the
  2999. * appropriate interrupt remap table entry.
  3000. */
  3001. set_irte_irq(irq, iommu, index, sub_handle);
  3002. }
  3003. no_ir:
  3004. ret = setup_msi_irq(dev, msidesc, irq);
  3005. if (ret < 0)
  3006. goto error;
  3007. sub_handle++;
  3008. }
  3009. return 0;
  3010. error:
  3011. destroy_irq(irq);
  3012. return ret;
  3013. }
  3014. void arch_teardown_msi_irq(unsigned int irq)
  3015. {
  3016. destroy_irq(irq);
  3017. }
  3018. #if defined (CONFIG_DMAR) || defined (CONFIG_INTR_REMAP)
  3019. #ifdef CONFIG_SMP
  3020. static int dmar_msi_set_affinity(unsigned int irq, const struct cpumask *mask)
  3021. {
  3022. struct irq_desc *desc = irq_to_desc(irq);
  3023. struct irq_cfg *cfg;
  3024. struct msi_msg msg;
  3025. unsigned int dest;
  3026. if (set_desc_affinity(desc, mask, &dest))
  3027. return -1;
  3028. cfg = get_irq_desc_chip_data(desc);
  3029. dmar_msi_read(irq, &msg);
  3030. msg.data &= ~MSI_DATA_VECTOR_MASK;
  3031. msg.data |= MSI_DATA_VECTOR(cfg->vector);
  3032. msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
  3033. msg.address_lo |= MSI_ADDR_DEST_ID(dest);
  3034. dmar_msi_write(irq, &msg);
  3035. return 0;
  3036. }
  3037. #endif /* CONFIG_SMP */
  3038. static struct irq_chip dmar_msi_type = {
  3039. .name = "DMAR_MSI",
  3040. .unmask = dmar_msi_unmask,
  3041. .mask = dmar_msi_mask,
  3042. .ack = ack_apic_edge,
  3043. #ifdef CONFIG_SMP
  3044. .set_affinity = dmar_msi_set_affinity,
  3045. #endif
  3046. .retrigger = ioapic_retrigger_irq,
  3047. };
  3048. int arch_setup_dmar_msi(unsigned int irq)
  3049. {
  3050. int ret;
  3051. struct msi_msg msg;
  3052. ret = msi_compose_msg(NULL, irq, &msg, -1);
  3053. if (ret < 0)
  3054. return ret;
  3055. dmar_msi_write(irq, &msg);
  3056. set_irq_chip_and_handler_name(irq, &dmar_msi_type, handle_edge_irq,
  3057. "edge");
  3058. return 0;
  3059. }
  3060. #endif
  3061. #ifdef CONFIG_HPET_TIMER
  3062. #ifdef CONFIG_SMP
  3063. static int hpet_msi_set_affinity(unsigned int irq, const struct cpumask *mask)
  3064. {
  3065. struct irq_desc *desc = irq_to_desc(irq);
  3066. struct irq_cfg *cfg;
  3067. struct msi_msg msg;
  3068. unsigned int dest;
  3069. if (set_desc_affinity(desc, mask, &dest))
  3070. return -1;
  3071. cfg = get_irq_desc_chip_data(desc);
  3072. hpet_msi_read(irq, &msg);
  3073. msg.data &= ~MSI_DATA_VECTOR_MASK;
  3074. msg.data |= MSI_DATA_VECTOR(cfg->vector);
  3075. msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
  3076. msg.address_lo |= MSI_ADDR_DEST_ID(dest);
  3077. hpet_msi_write(irq, &msg);
  3078. return 0;
  3079. }
  3080. #endif /* CONFIG_SMP */
  3081. static struct irq_chip ir_hpet_msi_type = {
  3082. .name = "IR-HPET_MSI",
  3083. .unmask = hpet_msi_unmask,
  3084. .mask = hpet_msi_mask,
  3085. #ifdef CONFIG_INTR_REMAP
  3086. .ack = ir_ack_apic_edge,
  3087. #ifdef CONFIG_SMP
  3088. .set_affinity = ir_set_msi_irq_affinity,
  3089. #endif
  3090. #endif
  3091. .retrigger = ioapic_retrigger_irq,
  3092. };
  3093. static struct irq_chip hpet_msi_type = {
  3094. .name = "HPET_MSI",
  3095. .unmask = hpet_msi_unmask,
  3096. .mask = hpet_msi_mask,
  3097. .ack = ack_apic_edge,
  3098. #ifdef CONFIG_SMP
  3099. .set_affinity = hpet_msi_set_affinity,
  3100. #endif
  3101. .retrigger = ioapic_retrigger_irq,
  3102. };
  3103. int arch_setup_hpet_msi(unsigned int irq, unsigned int id)
  3104. {
  3105. int ret;
  3106. struct msi_msg msg;
  3107. struct irq_desc *desc = irq_to_desc(irq);
  3108. if (intr_remapping_enabled) {
  3109. struct intel_iommu *iommu = map_hpet_to_ir(id);
  3110. int index;
  3111. if (!iommu)
  3112. return -1;
  3113. index = alloc_irte(iommu, irq, 1);
  3114. if (index < 0)
  3115. return -1;
  3116. }
  3117. ret = msi_compose_msg(NULL, irq, &msg, id);
  3118. if (ret < 0)
  3119. return ret;
  3120. hpet_msi_write(irq, &msg);
  3121. desc->status |= IRQ_MOVE_PCNTXT;
  3122. if (irq_remapped(irq))
  3123. set_irq_chip_and_handler_name(irq, &ir_hpet_msi_type,
  3124. handle_edge_irq, "edge");
  3125. else
  3126. set_irq_chip_and_handler_name(irq, &hpet_msi_type,
  3127. handle_edge_irq, "edge");
  3128. return 0;
  3129. }
  3130. #endif
  3131. #endif /* CONFIG_PCI_MSI */
  3132. /*
  3133. * Hypertransport interrupt support
  3134. */
  3135. #ifdef CONFIG_HT_IRQ
  3136. #ifdef CONFIG_SMP
  3137. static void target_ht_irq(unsigned int irq, unsigned int dest, u8 vector)
  3138. {
  3139. struct ht_irq_msg msg;
  3140. fetch_ht_irq_msg(irq, &msg);
  3141. msg.address_lo &= ~(HT_IRQ_LOW_VECTOR_MASK | HT_IRQ_LOW_DEST_ID_MASK);
  3142. msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK);
  3143. msg.address_lo |= HT_IRQ_LOW_VECTOR(vector) | HT_IRQ_LOW_DEST_ID(dest);
  3144. msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest);
  3145. write_ht_irq_msg(irq, &msg);
  3146. }
  3147. static int set_ht_irq_affinity(unsigned int irq, const struct cpumask *mask)
  3148. {
  3149. struct irq_desc *desc = irq_to_desc(irq);
  3150. struct irq_cfg *cfg;
  3151. unsigned int dest;
  3152. if (set_desc_affinity(desc, mask, &dest))
  3153. return -1;
  3154. cfg = get_irq_desc_chip_data(desc);
  3155. target_ht_irq(irq, dest, cfg->vector);
  3156. return 0;
  3157. }
  3158. #endif
  3159. static struct irq_chip ht_irq_chip = {
  3160. .name = "PCI-HT",
  3161. .mask = mask_ht_irq,
  3162. .unmask = unmask_ht_irq,
  3163. .ack = ack_apic_edge,
  3164. #ifdef CONFIG_SMP
  3165. .set_affinity = set_ht_irq_affinity,
  3166. #endif
  3167. .retrigger = ioapic_retrigger_irq,
  3168. };
  3169. int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
  3170. {
  3171. struct irq_cfg *cfg;
  3172. int err;
  3173. if (disable_apic)
  3174. return -ENXIO;
  3175. cfg = irq_cfg(irq);
  3176. err = assign_irq_vector(irq, cfg, apic->target_cpus());
  3177. if (!err) {
  3178. struct ht_irq_msg msg;
  3179. unsigned dest;
  3180. dest = apic->cpu_mask_to_apicid_and(cfg->domain,
  3181. apic->target_cpus());
  3182. msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest);
  3183. msg.address_lo =
  3184. HT_IRQ_LOW_BASE |
  3185. HT_IRQ_LOW_DEST_ID(dest) |
  3186. HT_IRQ_LOW_VECTOR(cfg->vector) |
  3187. ((apic->irq_dest_mode == 0) ?
  3188. HT_IRQ_LOW_DM_PHYSICAL :
  3189. HT_IRQ_LOW_DM_LOGICAL) |
  3190. HT_IRQ_LOW_RQEOI_EDGE |
  3191. ((apic->irq_delivery_mode != dest_LowestPrio) ?
  3192. HT_IRQ_LOW_MT_FIXED :
  3193. HT_IRQ_LOW_MT_ARBITRATED) |
  3194. HT_IRQ_LOW_IRQ_MASKED;
  3195. write_ht_irq_msg(irq, &msg);
  3196. set_irq_chip_and_handler_name(irq, &ht_irq_chip,
  3197. handle_edge_irq, "edge");
  3198. dev_printk(KERN_DEBUG, &dev->dev, "irq %d for HT\n", irq);
  3199. }
  3200. return err;
  3201. }
  3202. #endif /* CONFIG_HT_IRQ */
  3203. int __init io_apic_get_redir_entries (int ioapic)
  3204. {
  3205. union IO_APIC_reg_01 reg_01;
  3206. unsigned long flags;
  3207. raw_spin_lock_irqsave(&ioapic_lock, flags);
  3208. reg_01.raw = io_apic_read(ioapic, 1);
  3209. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  3210. /* The register returns the maximum index redir index
  3211. * supported, which is one less than the total number of redir
  3212. * entries.
  3213. */
  3214. return reg_01.bits.entries + 1;
  3215. }
  3216. void __init probe_nr_irqs_gsi(void)
  3217. {
  3218. int nr;
  3219. nr = gsi_top + NR_IRQS_LEGACY;
  3220. if (nr > nr_irqs_gsi)
  3221. nr_irqs_gsi = nr;
  3222. printk(KERN_DEBUG "nr_irqs_gsi: %d\n", nr_irqs_gsi);
  3223. }
  3224. #ifdef CONFIG_SPARSE_IRQ
  3225. int __init arch_probe_nr_irqs(void)
  3226. {
  3227. int nr;
  3228. if (nr_irqs > (NR_VECTORS * nr_cpu_ids))
  3229. nr_irqs = NR_VECTORS * nr_cpu_ids;
  3230. nr = nr_irqs_gsi + 8 * nr_cpu_ids;
  3231. #if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ)
  3232. /*
  3233. * for MSI and HT dyn irq
  3234. */
  3235. nr += nr_irqs_gsi * 16;
  3236. #endif
  3237. if (nr < nr_irqs)
  3238. nr_irqs = nr;
  3239. return NR_IRQS_LEGACY;
  3240. }
  3241. #endif
  3242. static int __io_apic_set_pci_routing(struct device *dev, int irq,
  3243. struct io_apic_irq_attr *irq_attr)
  3244. {
  3245. struct irq_desc *desc;
  3246. struct irq_cfg *cfg;
  3247. int node;
  3248. int ioapic, pin;
  3249. int trigger, polarity;
  3250. ioapic = irq_attr->ioapic;
  3251. if (!IO_APIC_IRQ(irq)) {
  3252. apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
  3253. ioapic);
  3254. return -EINVAL;
  3255. }
  3256. if (dev)
  3257. node = dev_to_node(dev);
  3258. else
  3259. node = cpu_to_node(0);
  3260. desc = irq_to_desc_alloc_node(irq, node);
  3261. if (!desc) {
  3262. printk(KERN_INFO "can not get irq_desc %d\n", irq);
  3263. return 0;
  3264. }
  3265. pin = irq_attr->ioapic_pin;
  3266. trigger = irq_attr->trigger;
  3267. polarity = irq_attr->polarity;
  3268. /*
  3269. * IRQs < 16 are already in the irq_2_pin[] map
  3270. */
  3271. if (irq >= legacy_pic->nr_legacy_irqs) {
  3272. cfg = get_irq_desc_chip_data(desc);
  3273. if (add_pin_to_irq_node_nopanic(cfg, node, ioapic, pin)) {
  3274. printk(KERN_INFO "can not add pin %d for irq %d\n",
  3275. pin, irq);
  3276. return 0;
  3277. }
  3278. }
  3279. setup_IO_APIC_irq(ioapic, pin, irq, desc, trigger, polarity);
  3280. return 0;
  3281. }
  3282. int io_apic_set_pci_routing(struct device *dev, int irq,
  3283. struct io_apic_irq_attr *irq_attr)
  3284. {
  3285. int ioapic, pin;
  3286. /*
  3287. * Avoid pin reprogramming. PRTs typically include entries
  3288. * with redundant pin->gsi mappings (but unique PCI devices);
  3289. * we only program the IOAPIC on the first.
  3290. */
  3291. ioapic = irq_attr->ioapic;
  3292. pin = irq_attr->ioapic_pin;
  3293. if (test_bit(pin, mp_ioapic_routing[ioapic].pin_programmed)) {
  3294. pr_debug("Pin %d-%d already programmed\n",
  3295. mp_ioapics[ioapic].apicid, pin);
  3296. return 0;
  3297. }
  3298. set_bit(pin, mp_ioapic_routing[ioapic].pin_programmed);
  3299. return __io_apic_set_pci_routing(dev, irq, irq_attr);
  3300. }
  3301. u8 __init io_apic_unique_id(u8 id)
  3302. {
  3303. #ifdef CONFIG_X86_32
  3304. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
  3305. !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
  3306. return io_apic_get_unique_id(nr_ioapics, id);
  3307. else
  3308. return id;
  3309. #else
  3310. int i;
  3311. DECLARE_BITMAP(used, 256);
  3312. bitmap_zero(used, 256);
  3313. for (i = 0; i < nr_ioapics; i++) {
  3314. struct mpc_ioapic *ia = &mp_ioapics[i];
  3315. __set_bit(ia->apicid, used);
  3316. }
  3317. if (!test_bit(id, used))
  3318. return id;
  3319. return find_first_zero_bit(used, 256);
  3320. #endif
  3321. }
  3322. #ifdef CONFIG_X86_32
  3323. int __init io_apic_get_unique_id(int ioapic, int apic_id)
  3324. {
  3325. union IO_APIC_reg_00 reg_00;
  3326. static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
  3327. physid_mask_t tmp;
  3328. unsigned long flags;
  3329. int i = 0;
  3330. /*
  3331. * The P4 platform supports up to 256 APIC IDs on two separate APIC
  3332. * buses (one for LAPICs, one for IOAPICs), where predecessors only
  3333. * supports up to 16 on one shared APIC bus.
  3334. *
  3335. * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
  3336. * advantage of new APIC bus architecture.
  3337. */
  3338. if (physids_empty(apic_id_map))
  3339. apic->ioapic_phys_id_map(&phys_cpu_present_map, &apic_id_map);
  3340. raw_spin_lock_irqsave(&ioapic_lock, flags);
  3341. reg_00.raw = io_apic_read(ioapic, 0);
  3342. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  3343. if (apic_id >= get_physical_broadcast()) {
  3344. printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
  3345. "%d\n", ioapic, apic_id, reg_00.bits.ID);
  3346. apic_id = reg_00.bits.ID;
  3347. }
  3348. /*
  3349. * Every APIC in a system must have a unique ID or we get lots of nice
  3350. * 'stuck on smp_invalidate_needed IPI wait' messages.
  3351. */
  3352. if (apic->check_apicid_used(&apic_id_map, apic_id)) {
  3353. for (i = 0; i < get_physical_broadcast(); i++) {
  3354. if (!apic->check_apicid_used(&apic_id_map, i))
  3355. break;
  3356. }
  3357. if (i == get_physical_broadcast())
  3358. panic("Max apic_id exceeded!\n");
  3359. printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
  3360. "trying %d\n", ioapic, apic_id, i);
  3361. apic_id = i;
  3362. }
  3363. apic->apicid_to_cpu_present(apic_id, &tmp);
  3364. physids_or(apic_id_map, apic_id_map, tmp);
  3365. if (reg_00.bits.ID != apic_id) {
  3366. reg_00.bits.ID = apic_id;
  3367. raw_spin_lock_irqsave(&ioapic_lock, flags);
  3368. io_apic_write(ioapic, 0, reg_00.raw);
  3369. reg_00.raw = io_apic_read(ioapic, 0);
  3370. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  3371. /* Sanity check */
  3372. if (reg_00.bits.ID != apic_id) {
  3373. printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic);
  3374. return -1;
  3375. }
  3376. }
  3377. apic_printk(APIC_VERBOSE, KERN_INFO
  3378. "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
  3379. return apic_id;
  3380. }
  3381. #endif
  3382. int __init io_apic_get_version(int ioapic)
  3383. {
  3384. union IO_APIC_reg_01 reg_01;
  3385. unsigned long flags;
  3386. raw_spin_lock_irqsave(&ioapic_lock, flags);
  3387. reg_01.raw = io_apic_read(ioapic, 1);
  3388. raw_spin_unlock_irqrestore(&ioapic_lock, flags);
  3389. return reg_01.bits.version;
  3390. }
  3391. int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity)
  3392. {
  3393. int ioapic, pin, idx;
  3394. if (skip_ioapic_setup)
  3395. return -1;
  3396. ioapic = mp_find_ioapic(gsi);
  3397. if (ioapic < 0)
  3398. return -1;
  3399. pin = mp_find_ioapic_pin(ioapic, gsi);
  3400. if (pin < 0)
  3401. return -1;
  3402. idx = find_irq_entry(ioapic, pin, mp_INT);
  3403. if (idx < 0)
  3404. return -1;
  3405. *trigger = irq_trigger(idx);
  3406. *polarity = irq_polarity(idx);
  3407. return 0;
  3408. }
  3409. /*
  3410. * This function currently is only a helper for the i386 smp boot process where
  3411. * we need to reprogram the ioredtbls to cater for the cpus which have come online
  3412. * so mask in all cases should simply be apic->target_cpus()
  3413. */
  3414. #ifdef CONFIG_SMP
  3415. void __init setup_ioapic_dest(void)
  3416. {
  3417. int pin, ioapic, irq, irq_entry;
  3418. struct irq_desc *desc;
  3419. const struct cpumask *mask;
  3420. if (skip_ioapic_setup == 1)
  3421. return;
  3422. for (ioapic = 0; ioapic < nr_ioapics; ioapic++)
  3423. for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
  3424. irq_entry = find_irq_entry(ioapic, pin, mp_INT);
  3425. if (irq_entry == -1)
  3426. continue;
  3427. irq = pin_2_irq(irq_entry, ioapic, pin);
  3428. if ((ioapic > 0) && (irq > 16))
  3429. continue;
  3430. desc = irq_to_desc(irq);
  3431. /*
  3432. * Honour affinities which have been set in early boot
  3433. */
  3434. if (desc->status &
  3435. (IRQ_NO_BALANCING | IRQ_AFFINITY_SET))
  3436. mask = desc->affinity;
  3437. else
  3438. mask = apic->target_cpus();
  3439. if (intr_remapping_enabled)
  3440. set_ir_ioapic_affinity_irq_desc(desc, mask);
  3441. else
  3442. set_ioapic_affinity_irq_desc(desc, mask);
  3443. }
  3444. }
  3445. #endif
  3446. #define IOAPIC_RESOURCE_NAME_SIZE 11
  3447. static struct resource *ioapic_resources;
  3448. static struct resource * __init ioapic_setup_resources(int nr_ioapics)
  3449. {
  3450. unsigned long n;
  3451. struct resource *res;
  3452. char *mem;
  3453. int i;
  3454. if (nr_ioapics <= 0)
  3455. return NULL;
  3456. n = IOAPIC_RESOURCE_NAME_SIZE + sizeof(struct resource);
  3457. n *= nr_ioapics;
  3458. mem = alloc_bootmem(n);
  3459. res = (void *)mem;
  3460. mem += sizeof(struct resource) * nr_ioapics;
  3461. for (i = 0; i < nr_ioapics; i++) {
  3462. res[i].name = mem;
  3463. res[i].flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  3464. snprintf(mem, IOAPIC_RESOURCE_NAME_SIZE, "IOAPIC %u", i);
  3465. mem += IOAPIC_RESOURCE_NAME_SIZE;
  3466. }
  3467. ioapic_resources = res;
  3468. return res;
  3469. }
  3470. void __init ioapic_init_mappings(void)
  3471. {
  3472. unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
  3473. struct resource *ioapic_res;
  3474. int i;
  3475. ioapic_res = ioapic_setup_resources(nr_ioapics);
  3476. for (i = 0; i < nr_ioapics; i++) {
  3477. if (smp_found_config) {
  3478. ioapic_phys = mp_ioapics[i].apicaddr;
  3479. #ifdef CONFIG_X86_32
  3480. if (!ioapic_phys) {
  3481. printk(KERN_ERR
  3482. "WARNING: bogus zero IO-APIC "
  3483. "address found in MPTABLE, "
  3484. "disabling IO/APIC support!\n");
  3485. smp_found_config = 0;
  3486. skip_ioapic_setup = 1;
  3487. goto fake_ioapic_page;
  3488. }
  3489. #endif
  3490. } else {
  3491. #ifdef CONFIG_X86_32
  3492. fake_ioapic_page:
  3493. #endif
  3494. ioapic_phys = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
  3495. ioapic_phys = __pa(ioapic_phys);
  3496. }
  3497. set_fixmap_nocache(idx, ioapic_phys);
  3498. apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n",
  3499. __fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK),
  3500. ioapic_phys);
  3501. idx++;
  3502. ioapic_res->start = ioapic_phys;
  3503. ioapic_res->end = ioapic_phys + IO_APIC_SLOT_SIZE - 1;
  3504. ioapic_res++;
  3505. }
  3506. }
  3507. void __init ioapic_insert_resources(void)
  3508. {
  3509. int i;
  3510. struct resource *r = ioapic_resources;
  3511. if (!r) {
  3512. if (nr_ioapics > 0)
  3513. printk(KERN_ERR
  3514. "IO APIC resources couldn't be allocated.\n");
  3515. return;
  3516. }
  3517. for (i = 0; i < nr_ioapics; i++) {
  3518. insert_resource(&iomem_resource, r);
  3519. r++;
  3520. }
  3521. }
  3522. int mp_find_ioapic(u32 gsi)
  3523. {
  3524. int i = 0;
  3525. /* Find the IOAPIC that manages this GSI. */
  3526. for (i = 0; i < nr_ioapics; i++) {
  3527. if ((gsi >= mp_gsi_routing[i].gsi_base)
  3528. && (gsi <= mp_gsi_routing[i].gsi_end))
  3529. return i;
  3530. }
  3531. printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
  3532. return -1;
  3533. }
  3534. int mp_find_ioapic_pin(int ioapic, u32 gsi)
  3535. {
  3536. if (WARN_ON(ioapic == -1))
  3537. return -1;
  3538. if (WARN_ON(gsi > mp_gsi_routing[ioapic].gsi_end))
  3539. return -1;
  3540. return gsi - mp_gsi_routing[ioapic].gsi_base;
  3541. }
  3542. static int bad_ioapic(unsigned long address)
  3543. {
  3544. if (nr_ioapics >= MAX_IO_APICS) {
  3545. printk(KERN_WARNING "WARING: Max # of I/O APICs (%d) exceeded "
  3546. "(found %d), skipping\n", MAX_IO_APICS, nr_ioapics);
  3547. return 1;
  3548. }
  3549. if (!address) {
  3550. printk(KERN_WARNING "WARNING: Bogus (zero) I/O APIC address"
  3551. " found in table, skipping!\n");
  3552. return 1;
  3553. }
  3554. return 0;
  3555. }
  3556. void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
  3557. {
  3558. int idx = 0;
  3559. int entries;
  3560. if (bad_ioapic(address))
  3561. return;
  3562. idx = nr_ioapics;
  3563. mp_ioapics[idx].type = MP_IOAPIC;
  3564. mp_ioapics[idx].flags = MPC_APIC_USABLE;
  3565. mp_ioapics[idx].apicaddr = address;
  3566. set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
  3567. mp_ioapics[idx].apicid = io_apic_unique_id(id);
  3568. mp_ioapics[idx].apicver = io_apic_get_version(idx);
  3569. /*
  3570. * Build basic GSI lookup table to facilitate gsi->io_apic lookups
  3571. * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
  3572. */
  3573. entries = io_apic_get_redir_entries(idx);
  3574. mp_gsi_routing[idx].gsi_base = gsi_base;
  3575. mp_gsi_routing[idx].gsi_end = gsi_base + entries - 1;
  3576. /*
  3577. * The number of IO-APIC IRQ registers (== #pins):
  3578. */
  3579. nr_ioapic_registers[idx] = entries;
  3580. if (mp_gsi_routing[idx].gsi_end >= gsi_top)
  3581. gsi_top = mp_gsi_routing[idx].gsi_end + 1;
  3582. printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
  3583. "GSI %d-%d\n", idx, mp_ioapics[idx].apicid,
  3584. mp_ioapics[idx].apicver, mp_ioapics[idx].apicaddr,
  3585. mp_gsi_routing[idx].gsi_base, mp_gsi_routing[idx].gsi_end);
  3586. nr_ioapics++;
  3587. }
  3588. /* Enable IOAPIC early just for system timer */
  3589. void __init pre_init_apic_IRQ0(void)
  3590. {
  3591. struct irq_cfg *cfg;
  3592. struct irq_desc *desc;
  3593. printk(KERN_INFO "Early APIC setup for system timer0\n");
  3594. #ifndef CONFIG_SMP
  3595. phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid);
  3596. #endif
  3597. desc = irq_to_desc_alloc_node(0, 0);
  3598. setup_local_APIC();
  3599. cfg = irq_cfg(0);
  3600. add_pin_to_irq_node(cfg, 0, 0, 0);
  3601. set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge");
  3602. setup_IO_APIC_irq(0, 0, 0, desc, 0, 0);
  3603. }