irq.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. /* $Id: irq.c,v 1.114 2002/01/11 08:45:38 davem Exp $
  2. * irq.c: UltraSparc IRQ handling/init/registry.
  3. *
  4. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
  6. * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz)
  7. */
  8. #include <linux/config.h>
  9. #include <linux/module.h>
  10. #include <linux/sched.h>
  11. #include <linux/ptrace.h>
  12. #include <linux/errno.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/signal.h>
  15. #include <linux/mm.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/slab.h>
  18. #include <linux/random.h>
  19. #include <linux/init.h>
  20. #include <linux/delay.h>
  21. #include <linux/proc_fs.h>
  22. #include <linux/seq_file.h>
  23. #include <asm/ptrace.h>
  24. #include <asm/processor.h>
  25. #include <asm/atomic.h>
  26. #include <asm/system.h>
  27. #include <asm/irq.h>
  28. #include <asm/io.h>
  29. #include <asm/sbus.h>
  30. #include <asm/iommu.h>
  31. #include <asm/upa.h>
  32. #include <asm/oplib.h>
  33. #include <asm/timer.h>
  34. #include <asm/smp.h>
  35. #include <asm/starfire.h>
  36. #include <asm/uaccess.h>
  37. #include <asm/cache.h>
  38. #include <asm/cpudata.h>
  39. #include <asm/auxio.h>
  40. #ifdef CONFIG_SMP
  41. static void distribute_irqs(void);
  42. #endif
  43. /* UPA nodes send interrupt packet to UltraSparc with first data reg
  44. * value low 5 (7 on Starfire) bits holding the IRQ identifier being
  45. * delivered. We must translate this into a non-vector IRQ so we can
  46. * set the softint on this cpu.
  47. *
  48. * To make processing these packets efficient and race free we use
  49. * an array of irq buckets below. The interrupt vector handler in
  50. * entry.S feeds incoming packets into per-cpu pil-indexed lists.
  51. * The IVEC handler does not need to act atomically, the PIL dispatch
  52. * code uses CAS to get an atomic snapshot of the list and clear it
  53. * at the same time.
  54. */
  55. struct ino_bucket ivector_table[NUM_IVECS] __attribute__ ((aligned (SMP_CACHE_BYTES)));
  56. /* This has to be in the main kernel image, it cannot be
  57. * turned into per-cpu data. The reason is that the main
  58. * kernel image is locked into the TLB and this structure
  59. * is accessed from the vectored interrupt trap handler. If
  60. * access to this structure takes a TLB miss it could cause
  61. * the 5-level sparc v9 trap stack to overflow.
  62. */
  63. struct irq_work_struct {
  64. unsigned int irq_worklists[16];
  65. };
  66. struct irq_work_struct __irq_work[NR_CPUS];
  67. #define irq_work(__cpu, __pil) &(__irq_work[(__cpu)].irq_worklists[(__pil)])
  68. static struct irqaction *irq_action[NR_IRQS+1];
  69. /* This only synchronizes entities which modify IRQ handler
  70. * state and some selected user-level spots that want to
  71. * read things in the table. IRQ handler processing orders
  72. * its' accesses such that no locking is needed.
  73. */
  74. static DEFINE_SPINLOCK(irq_action_lock);
  75. static void register_irq_proc (unsigned int irq);
  76. /*
  77. * Upper 2b of irqaction->flags holds the ino.
  78. * irqaction->mask holds the smp affinity information.
  79. */
  80. #define put_ino_in_irqaction(action, irq) \
  81. action->flags &= 0xffffffffffffUL; \
  82. if (__bucket(irq) == &pil0_dummy_bucket) \
  83. action->flags |= 0xdeadUL << 48; \
  84. else \
  85. action->flags |= __irq_ino(irq) << 48;
  86. #define get_ino_in_irqaction(action) (action->flags >> 48)
  87. #define put_smpaff_in_irqaction(action, smpaff) (action)->mask = (smpaff)
  88. #define get_smpaff_in_irqaction(action) ((action)->mask)
  89. int show_interrupts(struct seq_file *p, void *v)
  90. {
  91. unsigned long flags;
  92. int i = *(loff_t *) v;
  93. struct irqaction *action;
  94. #ifdef CONFIG_SMP
  95. int j;
  96. #endif
  97. spin_lock_irqsave(&irq_action_lock, flags);
  98. if (i <= NR_IRQS) {
  99. if (!(action = *(i + irq_action)))
  100. goto out_unlock;
  101. seq_printf(p, "%3d: ", i);
  102. #ifndef CONFIG_SMP
  103. seq_printf(p, "%10u ", kstat_irqs(i));
  104. #else
  105. for (j = 0; j < NR_CPUS; j++) {
  106. if (!cpu_online(j))
  107. continue;
  108. seq_printf(p, "%10u ",
  109. kstat_cpu(j).irqs[i]);
  110. }
  111. #endif
  112. seq_printf(p, " %s:%lx", action->name,
  113. get_ino_in_irqaction(action));
  114. for (action = action->next; action; action = action->next) {
  115. seq_printf(p, ", %s:%lx", action->name,
  116. get_ino_in_irqaction(action));
  117. }
  118. seq_putc(p, '\n');
  119. }
  120. out_unlock:
  121. spin_unlock_irqrestore(&irq_action_lock, flags);
  122. return 0;
  123. }
  124. /* Now these are always passed a true fully specified sun4u INO. */
  125. void enable_irq(unsigned int irq)
  126. {
  127. struct ino_bucket *bucket = __bucket(irq);
  128. unsigned long imap;
  129. unsigned long tid;
  130. imap = bucket->imap;
  131. if (imap == 0UL)
  132. return;
  133. preempt_disable();
  134. if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  135. unsigned long ver;
  136. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  137. if ((ver >> 32) == 0x003e0016) {
  138. /* We set it to our JBUS ID. */
  139. __asm__ __volatile__("ldxa [%%g0] %1, %0"
  140. : "=r" (tid)
  141. : "i" (ASI_JBUS_CONFIG));
  142. tid = ((tid & (0x1fUL<<17)) << 9);
  143. tid &= IMAP_TID_JBUS;
  144. } else {
  145. /* We set it to our Safari AID. */
  146. __asm__ __volatile__("ldxa [%%g0] %1, %0"
  147. : "=r" (tid)
  148. : "i" (ASI_SAFARI_CONFIG));
  149. tid = ((tid & (0x3ffUL<<17)) << 9);
  150. tid &= IMAP_AID_SAFARI;
  151. }
  152. } else if (this_is_starfire == 0) {
  153. /* We set it to our UPA MID. */
  154. __asm__ __volatile__("ldxa [%%g0] %1, %0"
  155. : "=r" (tid)
  156. : "i" (ASI_UPA_CONFIG));
  157. tid = ((tid & UPA_CONFIG_MID) << 9);
  158. tid &= IMAP_TID_UPA;
  159. } else {
  160. tid = (starfire_translate(imap, smp_processor_id()) << 26);
  161. tid &= IMAP_TID_UPA;
  162. }
  163. /* NOTE NOTE NOTE, IGN and INO are read-only, IGN is a product
  164. * of this SYSIO's preconfigured IGN in the SYSIO Control
  165. * Register, the hardware just mirrors that value here.
  166. * However for Graphics and UPA Slave devices the full
  167. * IMAP_INR field can be set by the programmer here.
  168. *
  169. * Things like FFB can now be handled via the new IRQ mechanism.
  170. */
  171. upa_writel(tid | IMAP_VALID, imap);
  172. preempt_enable();
  173. }
  174. /* This now gets passed true ino's as well. */
  175. void disable_irq(unsigned int irq)
  176. {
  177. struct ino_bucket *bucket = __bucket(irq);
  178. unsigned long imap;
  179. imap = bucket->imap;
  180. if (imap != 0UL) {
  181. u32 tmp;
  182. /* NOTE: We do not want to futz with the IRQ clear registers
  183. * and move the state to IDLE, the SCSI code does call
  184. * disable_irq() to assure atomicity in the queue cmd
  185. * SCSI adapter driver code. Thus we'd lose interrupts.
  186. */
  187. tmp = upa_readl(imap);
  188. tmp &= ~IMAP_VALID;
  189. upa_writel(tmp, imap);
  190. }
  191. }
  192. /* The timer is the one "weird" interrupt which is generated by
  193. * the CPU %tick register and not by some normal vectored interrupt
  194. * source. To handle this special case, we use this dummy INO bucket.
  195. */
  196. static struct irq_desc pil0_dummy_desc;
  197. static struct ino_bucket pil0_dummy_bucket = {
  198. .irq_info = &pil0_dummy_desc,
  199. };
  200. static void build_irq_error(const char *msg, unsigned int ino, int pil, int inofixup,
  201. unsigned long iclr, unsigned long imap,
  202. struct ino_bucket *bucket)
  203. {
  204. prom_printf("IRQ: INO %04x (%d:%016lx:%016lx) --> "
  205. "(%d:%d:%016lx:%016lx), halting...\n",
  206. ino, bucket->pil, bucket->iclr, bucket->imap,
  207. pil, inofixup, iclr, imap);
  208. prom_halt();
  209. }
  210. unsigned int build_irq(int pil, int inofixup, unsigned long iclr, unsigned long imap)
  211. {
  212. struct ino_bucket *bucket;
  213. int ino;
  214. if (pil == 0) {
  215. if (iclr != 0UL || imap != 0UL) {
  216. prom_printf("Invalid dummy bucket for PIL0 (%lx:%lx)\n",
  217. iclr, imap);
  218. prom_halt();
  219. }
  220. return __irq(&pil0_dummy_bucket);
  221. }
  222. /* RULE: Both must be specified in all other cases. */
  223. if (iclr == 0UL || imap == 0UL) {
  224. prom_printf("Invalid build_irq %d %d %016lx %016lx\n",
  225. pil, inofixup, iclr, imap);
  226. prom_halt();
  227. }
  228. ino = (upa_readl(imap) & (IMAP_IGN | IMAP_INO)) + inofixup;
  229. if (ino > NUM_IVECS) {
  230. prom_printf("Invalid INO %04x (%d:%d:%016lx:%016lx)\n",
  231. ino, pil, inofixup, iclr, imap);
  232. prom_halt();
  233. }
  234. bucket = &ivector_table[ino];
  235. if (bucket->flags & IBF_ACTIVE)
  236. build_irq_error("IRQ: Trying to build active INO bucket.\n",
  237. ino, pil, inofixup, iclr, imap, bucket);
  238. if (bucket->irq_info) {
  239. if (bucket->imap != imap || bucket->iclr != iclr)
  240. build_irq_error("IRQ: Trying to reinit INO bucket.\n",
  241. ino, pil, inofixup, iclr, imap, bucket);
  242. goto out;
  243. }
  244. bucket->irq_info = kmalloc(sizeof(struct irq_desc), GFP_ATOMIC);
  245. if (!bucket->irq_info) {
  246. prom_printf("IRQ: Error, kmalloc(irq_desc) failed.\n");
  247. prom_halt();
  248. }
  249. memset(bucket->irq_info, 0, sizeof(struct irq_desc));
  250. /* Ok, looks good, set it up. Don't touch the irq_chain or
  251. * the pending flag.
  252. */
  253. bucket->imap = imap;
  254. bucket->iclr = iclr;
  255. bucket->pil = pil;
  256. bucket->flags = 0;
  257. out:
  258. return __irq(bucket);
  259. }
  260. static void atomic_bucket_insert(struct ino_bucket *bucket)
  261. {
  262. unsigned long pstate;
  263. unsigned int *ent;
  264. __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
  265. __asm__ __volatile__("wrpr %0, %1, %%pstate"
  266. : : "r" (pstate), "i" (PSTATE_IE));
  267. ent = irq_work(smp_processor_id(), bucket->pil);
  268. bucket->irq_chain = *ent;
  269. *ent = __irq(bucket);
  270. __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
  271. }
  272. static int check_irq_sharing(int pil, unsigned long irqflags)
  273. {
  274. struct irqaction *action, *tmp;
  275. action = *(irq_action + pil);
  276. if (action) {
  277. if ((action->flags & SA_SHIRQ) && (irqflags & SA_SHIRQ)) {
  278. for (tmp = action; tmp->next; tmp = tmp->next)
  279. ;
  280. } else {
  281. return -EBUSY;
  282. }
  283. }
  284. return 0;
  285. }
  286. static void append_irq_action(int pil, struct irqaction *action)
  287. {
  288. struct irqaction **pp = irq_action + pil;
  289. while (*pp)
  290. pp = &((*pp)->next);
  291. *pp = action;
  292. }
  293. static struct irqaction *get_action_slot(struct ino_bucket *bucket)
  294. {
  295. struct irq_desc *desc = bucket->irq_info;
  296. int max_irq, i;
  297. max_irq = 1;
  298. if (bucket->flags & IBF_PCI)
  299. max_irq = MAX_IRQ_DESC_ACTION;
  300. for (i = 0; i < max_irq; i++) {
  301. struct irqaction *p = &desc->action[i];
  302. u32 mask = (1 << i);
  303. if (desc->action_active_mask & mask)
  304. continue;
  305. desc->action_active_mask |= mask;
  306. return p;
  307. }
  308. return NULL;
  309. }
  310. int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *),
  311. unsigned long irqflags, const char *name, void *dev_id)
  312. {
  313. struct irqaction *action;
  314. struct ino_bucket *bucket = __bucket(irq);
  315. unsigned long flags;
  316. int pending = 0;
  317. if (unlikely(!handler))
  318. return -EINVAL;
  319. if (unlikely(!bucket->irq_info))
  320. return -ENODEV;
  321. if ((bucket != &pil0_dummy_bucket) && (irqflags & SA_SAMPLE_RANDOM)) {
  322. /*
  323. * This function might sleep, we want to call it first,
  324. * outside of the atomic block. In SA_STATIC_ALLOC case,
  325. * random driver's kmalloc will fail, but it is safe.
  326. * If already initialized, random driver will not reinit.
  327. * Yes, this might clear the entropy pool if the wrong
  328. * driver is attempted to be loaded, without actually
  329. * installing a new handler, but is this really a problem,
  330. * only the sysadmin is able to do this.
  331. */
  332. rand_initialize_irq(irq);
  333. }
  334. spin_lock_irqsave(&irq_action_lock, flags);
  335. if (check_irq_sharing(bucket->pil, irqflags)) {
  336. spin_unlock_irqrestore(&irq_action_lock, flags);
  337. return -EBUSY;
  338. }
  339. action = get_action_slot(bucket);
  340. if (!action) {
  341. spin_unlock_irqrestore(&irq_action_lock, flags);
  342. return -ENOMEM;
  343. }
  344. bucket->flags |= IBF_ACTIVE;
  345. pending = 0;
  346. if (bucket != &pil0_dummy_bucket) {
  347. pending = bucket->pending;
  348. if (pending)
  349. bucket->pending = 0;
  350. }
  351. action->handler = handler;
  352. action->flags = irqflags;
  353. action->name = name;
  354. action->next = NULL;
  355. action->dev_id = dev_id;
  356. put_ino_in_irqaction(action, irq);
  357. put_smpaff_in_irqaction(action, CPU_MASK_NONE);
  358. append_irq_action(bucket->pil, action);
  359. enable_irq(irq);
  360. /* We ate the IVEC already, this makes sure it does not get lost. */
  361. if (pending) {
  362. atomic_bucket_insert(bucket);
  363. set_softint(1 << bucket->pil);
  364. }
  365. spin_unlock_irqrestore(&irq_action_lock, flags);
  366. if (bucket != &pil0_dummy_bucket)
  367. register_irq_proc(__irq_ino(irq));
  368. #ifdef CONFIG_SMP
  369. distribute_irqs();
  370. #endif
  371. return 0;
  372. }
  373. EXPORT_SYMBOL(request_irq);
  374. static struct irqaction *unlink_irq_action(unsigned int irq, void *dev_id)
  375. {
  376. struct ino_bucket *bucket = __bucket(irq);
  377. struct irqaction *action, **pp;
  378. pp = irq_action + bucket->pil;
  379. action = *pp;
  380. if (unlikely(!action))
  381. return NULL;
  382. if (unlikely(!action->handler)) {
  383. printk("Freeing free IRQ %d\n", bucket->pil);
  384. return NULL;
  385. }
  386. while (action && action->dev_id != dev_id) {
  387. pp = &action->next;
  388. action = *pp;
  389. }
  390. if (likely(action))
  391. *pp = action->next;
  392. return action;
  393. }
  394. void free_irq(unsigned int irq, void *dev_id)
  395. {
  396. struct irqaction *action;
  397. struct ino_bucket *bucket;
  398. unsigned long flags;
  399. spin_lock_irqsave(&irq_action_lock, flags);
  400. action = unlink_irq_action(irq, dev_id);
  401. spin_unlock_irqrestore(&irq_action_lock, flags);
  402. if (unlikely(!action))
  403. return;
  404. synchronize_irq(irq);
  405. spin_lock_irqsave(&irq_action_lock, flags);
  406. bucket = __bucket(irq);
  407. if (bucket != &pil0_dummy_bucket) {
  408. struct irq_desc *desc = bucket->irq_info;
  409. unsigned long imap = bucket->imap;
  410. int ent, i;
  411. for (i = 0; i < MAX_IRQ_DESC_ACTION; i++) {
  412. struct irqaction *p = &desc->action[i];
  413. if (p == action) {
  414. desc->action_active_mask &= ~(1 << i);
  415. break;
  416. }
  417. }
  418. if (!desc->action_active_mask) {
  419. /* This unique interrupt source is now inactive. */
  420. bucket->flags &= ~IBF_ACTIVE;
  421. /* See if any other buckets share this bucket's IMAP
  422. * and are still active.
  423. */
  424. for (ent = 0; ent < NUM_IVECS; ent++) {
  425. struct ino_bucket *bp = &ivector_table[ent];
  426. if (bp != bucket &&
  427. bp->imap == imap &&
  428. (bp->flags & IBF_ACTIVE) != 0)
  429. break;
  430. }
  431. /* Only disable when no other sub-irq levels of
  432. * the same IMAP are active.
  433. */
  434. if (ent == NUM_IVECS)
  435. disable_irq(irq);
  436. }
  437. }
  438. spin_unlock_irqrestore(&irq_action_lock, flags);
  439. }
  440. EXPORT_SYMBOL(free_irq);
  441. #ifdef CONFIG_SMP
  442. void synchronize_irq(unsigned int irq)
  443. {
  444. struct ino_bucket *bucket = __bucket(irq);
  445. #if 0
  446. /* The following is how I wish I could implement this.
  447. * Unfortunately the ICLR registers are read-only, you can
  448. * only write ICLR_foo values to them. To get the current
  449. * IRQ status you would need to get at the IRQ diag registers
  450. * in the PCI/SBUS controller and the layout of those vary
  451. * from one controller to the next, sigh... -DaveM
  452. */
  453. unsigned long iclr = bucket->iclr;
  454. while (1) {
  455. u32 tmp = upa_readl(iclr);
  456. if (tmp == ICLR_TRANSMIT ||
  457. tmp == ICLR_PENDING) {
  458. cpu_relax();
  459. continue;
  460. }
  461. break;
  462. }
  463. #else
  464. /* So we have to do this with a INPROGRESS bit just like x86. */
  465. while (bucket->flags & IBF_INPROGRESS)
  466. cpu_relax();
  467. #endif
  468. }
  469. #endif /* CONFIG_SMP */
  470. static void process_bucket(int irq, struct ino_bucket *bp, struct pt_regs *regs)
  471. {
  472. struct irq_desc *desc = bp->irq_info;
  473. unsigned char flags = bp->flags;
  474. u32 action_mask, i;
  475. int random;
  476. bp->flags |= IBF_INPROGRESS;
  477. if (unlikely(!(flags & IBF_ACTIVE))) {
  478. bp->pending = 1;
  479. goto out;
  480. }
  481. if (desc->pre_handler)
  482. desc->pre_handler(bp,
  483. desc->pre_handler_arg1,
  484. desc->pre_handler_arg2);
  485. action_mask = desc->action_active_mask;
  486. random = 0;
  487. for (i = 0; i < MAX_IRQ_DESC_ACTION; i++) {
  488. struct irqaction *p = &desc->action[i];
  489. u32 mask = (1 << i);
  490. if (!(action_mask & mask))
  491. continue;
  492. action_mask &= ~mask;
  493. if (p->handler(__irq(bp), p->dev_id, regs) == IRQ_HANDLED)
  494. random |= p->flags;
  495. if (!action_mask)
  496. break;
  497. }
  498. if (bp->pil != 0) {
  499. upa_writel(ICLR_IDLE, bp->iclr);
  500. /* Test and add entropy */
  501. if (random & SA_SAMPLE_RANDOM)
  502. add_interrupt_randomness(irq);
  503. }
  504. out:
  505. bp->flags &= ~IBF_INPROGRESS;
  506. }
  507. void handler_irq(int irq, struct pt_regs *regs)
  508. {
  509. struct ino_bucket *bp;
  510. int cpu = smp_processor_id();
  511. #ifndef CONFIG_SMP
  512. /*
  513. * Check for TICK_INT on level 14 softint.
  514. */
  515. {
  516. unsigned long clr_mask = 1 << irq;
  517. unsigned long tick_mask = tick_ops->softint_mask;
  518. if ((irq == 14) && (get_softint() & tick_mask)) {
  519. irq = 0;
  520. clr_mask = tick_mask;
  521. }
  522. clear_softint(clr_mask);
  523. }
  524. #else
  525. clear_softint(1 << irq);
  526. #endif
  527. irq_enter();
  528. kstat_this_cpu.irqs[irq]++;
  529. /* Sliiiick... */
  530. #ifndef CONFIG_SMP
  531. bp = ((irq != 0) ?
  532. __bucket(xchg32(irq_work(cpu, irq), 0)) :
  533. &pil0_dummy_bucket);
  534. #else
  535. bp = __bucket(xchg32(irq_work(cpu, irq), 0));
  536. #endif
  537. while (bp) {
  538. struct ino_bucket *nbp = __bucket(bp->irq_chain);
  539. bp->irq_chain = 0;
  540. process_bucket(irq, bp, regs);
  541. bp = nbp;
  542. }
  543. irq_exit();
  544. }
  545. #ifdef CONFIG_BLK_DEV_FD
  546. extern irqreturn_t floppy_interrupt(int, void *, struct pt_regs *);;
  547. /* XXX No easy way to include asm/floppy.h XXX */
  548. extern unsigned char *pdma_vaddr;
  549. extern unsigned long pdma_size;
  550. extern volatile int doing_pdma;
  551. extern unsigned long fdc_status;
  552. irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie, struct pt_regs *regs)
  553. {
  554. if (likely(doing_pdma)) {
  555. void __iomem *stat = (void __iomem *) fdc_status;
  556. unsigned char *vaddr = pdma_vaddr;
  557. unsigned long size = pdma_size;
  558. u8 val;
  559. while (size) {
  560. val = readb(stat);
  561. if (unlikely(!(val & 0x80))) {
  562. pdma_vaddr = vaddr;
  563. pdma_size = size;
  564. return IRQ_HANDLED;
  565. }
  566. if (unlikely(!(val & 0x20))) {
  567. pdma_vaddr = vaddr;
  568. pdma_size = size;
  569. doing_pdma = 0;
  570. goto main_interrupt;
  571. }
  572. if (val & 0x40) {
  573. /* read */
  574. *vaddr++ = readb(stat + 1);
  575. } else {
  576. unsigned char data = *vaddr++;
  577. /* write */
  578. writeb(data, stat + 1);
  579. }
  580. size--;
  581. }
  582. pdma_vaddr = vaddr;
  583. pdma_size = size;
  584. /* Send Terminal Count pulse to floppy controller. */
  585. val = readb(auxio_register);
  586. val |= AUXIO_AUX1_FTCNT;
  587. writeb(val, auxio_register);
  588. val &= ~AUXIO_AUX1_FTCNT;
  589. writeb(val, auxio_register);
  590. doing_pdma = 0;
  591. }
  592. main_interrupt:
  593. return floppy_interrupt(irq, dev_cookie, regs);
  594. }
  595. EXPORT_SYMBOL(sparc_floppy_irq);
  596. #endif
  597. /* We really don't need these at all on the Sparc. We only have
  598. * stubs here because they are exported to modules.
  599. */
  600. unsigned long probe_irq_on(void)
  601. {
  602. return 0;
  603. }
  604. EXPORT_SYMBOL(probe_irq_on);
  605. int probe_irq_off(unsigned long mask)
  606. {
  607. return 0;
  608. }
  609. EXPORT_SYMBOL(probe_irq_off);
  610. #ifdef CONFIG_SMP
  611. static int retarget_one_irq(struct irqaction *p, int goal_cpu)
  612. {
  613. struct ino_bucket *bucket = get_ino_in_irqaction(p) + ivector_table;
  614. unsigned long imap = bucket->imap;
  615. unsigned int tid;
  616. while (!cpu_online(goal_cpu)) {
  617. if (++goal_cpu >= NR_CPUS)
  618. goal_cpu = 0;
  619. }
  620. if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  621. tid = goal_cpu << 26;
  622. tid &= IMAP_AID_SAFARI;
  623. } else if (this_is_starfire == 0) {
  624. tid = goal_cpu << 26;
  625. tid &= IMAP_TID_UPA;
  626. } else {
  627. tid = (starfire_translate(imap, goal_cpu) << 26);
  628. tid &= IMAP_TID_UPA;
  629. }
  630. upa_writel(tid | IMAP_VALID, imap);
  631. do {
  632. if (++goal_cpu >= NR_CPUS)
  633. goal_cpu = 0;
  634. } while (!cpu_online(goal_cpu));
  635. return goal_cpu;
  636. }
  637. /* Called from request_irq. */
  638. static void distribute_irqs(void)
  639. {
  640. unsigned long flags;
  641. int cpu, level;
  642. spin_lock_irqsave(&irq_action_lock, flags);
  643. cpu = 0;
  644. /*
  645. * Skip the timer at [0], and very rare error/power intrs at [15].
  646. * Also level [12], it causes problems on Ex000 systems.
  647. */
  648. for (level = 1; level < NR_IRQS; level++) {
  649. struct irqaction *p = irq_action[level];
  650. if (level == 12)
  651. continue;
  652. while(p) {
  653. cpu = retarget_one_irq(p, cpu);
  654. p = p->next;
  655. }
  656. }
  657. spin_unlock_irqrestore(&irq_action_lock, flags);
  658. }
  659. #endif
  660. struct sun5_timer {
  661. u64 count0;
  662. u64 limit0;
  663. u64 count1;
  664. u64 limit1;
  665. };
  666. static struct sun5_timer *prom_timers;
  667. static u64 prom_limit0, prom_limit1;
  668. static void map_prom_timers(void)
  669. {
  670. unsigned int addr[3];
  671. int tnode, err;
  672. /* PROM timer node hangs out in the top level of device siblings... */
  673. tnode = prom_finddevice("/counter-timer");
  674. /* Assume if node is not present, PROM uses different tick mechanism
  675. * which we should not care about.
  676. */
  677. if (tnode == 0 || tnode == -1) {
  678. prom_timers = (struct sun5_timer *) 0;
  679. return;
  680. }
  681. /* If PROM is really using this, it must be mapped by him. */
  682. err = prom_getproperty(tnode, "address", (char *)addr, sizeof(addr));
  683. if (err == -1) {
  684. prom_printf("PROM does not have timer mapped, trying to continue.\n");
  685. prom_timers = (struct sun5_timer *) 0;
  686. return;
  687. }
  688. prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
  689. }
  690. static void kill_prom_timer(void)
  691. {
  692. if (!prom_timers)
  693. return;
  694. /* Save them away for later. */
  695. prom_limit0 = prom_timers->limit0;
  696. prom_limit1 = prom_timers->limit1;
  697. /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
  698. * We turn both off here just to be paranoid.
  699. */
  700. prom_timers->limit0 = 0;
  701. prom_timers->limit1 = 0;
  702. /* Wheee, eat the interrupt packet too... */
  703. __asm__ __volatile__(
  704. " mov 0x40, %%g2\n"
  705. " ldxa [%%g0] %0, %%g1\n"
  706. " ldxa [%%g2] %1, %%g1\n"
  707. " stxa %%g0, [%%g0] %0\n"
  708. " membar #Sync\n"
  709. : /* no outputs */
  710. : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
  711. : "g1", "g2");
  712. }
  713. void init_irqwork_curcpu(void)
  714. {
  715. int cpu = hard_smp_processor_id();
  716. memset(__irq_work + cpu, 0, sizeof(struct irq_work_struct));
  717. }
  718. /* Only invoked on boot processor. */
  719. void __init init_IRQ(void)
  720. {
  721. map_prom_timers();
  722. kill_prom_timer();
  723. memset(&ivector_table[0], 0, sizeof(ivector_table));
  724. /* We need to clear any IRQ's pending in the soft interrupt
  725. * registers, a spurious one could be left around from the
  726. * PROM timer which we just disabled.
  727. */
  728. clear_softint(get_softint());
  729. /* Now that ivector table is initialized, it is safe
  730. * to receive IRQ vector traps. We will normally take
  731. * one or two right now, in case some device PROM used
  732. * to boot us wants to speak to us. We just ignore them.
  733. */
  734. __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
  735. "or %%g1, %0, %%g1\n\t"
  736. "wrpr %%g1, 0x0, %%pstate"
  737. : /* No outputs */
  738. : "i" (PSTATE_IE)
  739. : "g1");
  740. }
  741. static struct proc_dir_entry * root_irq_dir;
  742. static struct proc_dir_entry * irq_dir [NUM_IVECS];
  743. #ifdef CONFIG_SMP
  744. static int irq_affinity_read_proc (char *page, char **start, off_t off,
  745. int count, int *eof, void *data)
  746. {
  747. struct ino_bucket *bp = ivector_table + (long)data;
  748. struct irq_desc *desc = bp->irq_info;
  749. struct irqaction *ap = desc->action;
  750. cpumask_t mask;
  751. int len;
  752. mask = get_smpaff_in_irqaction(ap);
  753. if (cpus_empty(mask))
  754. mask = cpu_online_map;
  755. len = cpumask_scnprintf(page, count, mask);
  756. if (count - len < 2)
  757. return -EINVAL;
  758. len += sprintf(page + len, "\n");
  759. return len;
  760. }
  761. static inline void set_intr_affinity(int irq, cpumask_t hw_aff)
  762. {
  763. struct ino_bucket *bp = ivector_table + irq;
  764. struct irq_desc *desc = bp->irq_info;
  765. struct irqaction *ap = desc->action;
  766. /* Users specify affinity in terms of hw cpu ids.
  767. * As soon as we do this, handler_irq() might see and take action.
  768. */
  769. put_smpaff_in_irqaction(ap, hw_aff);
  770. /* Migration is simply done by the next cpu to service this
  771. * interrupt.
  772. */
  773. }
  774. static int irq_affinity_write_proc (struct file *file, const char __user *buffer,
  775. unsigned long count, void *data)
  776. {
  777. int irq = (long) data, full_count = count, err;
  778. cpumask_t new_value;
  779. err = cpumask_parse(buffer, count, new_value);
  780. /*
  781. * Do not allow disabling IRQs completely - it's a too easy
  782. * way to make the system unusable accidentally :-) At least
  783. * one online CPU still has to be targeted.
  784. */
  785. cpus_and(new_value, new_value, cpu_online_map);
  786. if (cpus_empty(new_value))
  787. return -EINVAL;
  788. set_intr_affinity(irq, new_value);
  789. return full_count;
  790. }
  791. #endif
  792. #define MAX_NAMELEN 10
  793. static void register_irq_proc (unsigned int irq)
  794. {
  795. char name [MAX_NAMELEN];
  796. if (!root_irq_dir || irq_dir[irq])
  797. return;
  798. memset(name, 0, MAX_NAMELEN);
  799. sprintf(name, "%x", irq);
  800. /* create /proc/irq/1234 */
  801. irq_dir[irq] = proc_mkdir(name, root_irq_dir);
  802. #ifdef CONFIG_SMP
  803. /* XXX SMP affinity not supported on starfire yet. */
  804. if (this_is_starfire == 0) {
  805. struct proc_dir_entry *entry;
  806. /* create /proc/irq/1234/smp_affinity */
  807. entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
  808. if (entry) {
  809. entry->nlink = 1;
  810. entry->data = (void *)(long)irq;
  811. entry->read_proc = irq_affinity_read_proc;
  812. entry->write_proc = irq_affinity_write_proc;
  813. }
  814. }
  815. #endif
  816. }
  817. void init_irq_proc (void)
  818. {
  819. /* create /proc/irq */
  820. root_irq_dir = proc_mkdir("irq", NULL);
  821. }