io_apic.c 103 KB

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