irq.c 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  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. register struct irq_work_struct *workp asm("o2");
  716. register unsigned long tmp asm("o3");
  717. int cpu = hard_smp_processor_id();
  718. memset(__irq_work + cpu, 0, sizeof(*workp));
  719. /* Make sure we are called with PSTATE_IE disabled. */
  720. __asm__ __volatile__("rdpr %%pstate, %0\n\t"
  721. : "=r" (tmp));
  722. if (tmp & PSTATE_IE) {
  723. prom_printf("BUG: init_irqwork_curcpu() called with "
  724. "PSTATE_IE enabled, bailing.\n");
  725. __asm__ __volatile__("mov %%i7, %0\n\t"
  726. : "=r" (tmp));
  727. prom_printf("BUG: Called from %lx\n", tmp);
  728. prom_halt();
  729. }
  730. /* Set interrupt globals. */
  731. workp = &__irq_work[cpu];
  732. __asm__ __volatile__(
  733. "rdpr %%pstate, %0\n\t"
  734. "wrpr %0, %1, %%pstate\n\t"
  735. "mov %2, %%g6\n\t"
  736. "wrpr %0, 0x0, %%pstate\n\t"
  737. : "=&r" (tmp)
  738. : "i" (PSTATE_IG), "r" (workp));
  739. }
  740. /* Only invoked on boot processor. */
  741. void __init init_IRQ(void)
  742. {
  743. map_prom_timers();
  744. kill_prom_timer();
  745. memset(&ivector_table[0], 0, sizeof(ivector_table));
  746. /* We need to clear any IRQ's pending in the soft interrupt
  747. * registers, a spurious one could be left around from the
  748. * PROM timer which we just disabled.
  749. */
  750. clear_softint(get_softint());
  751. /* Now that ivector table is initialized, it is safe
  752. * to receive IRQ vector traps. We will normally take
  753. * one or two right now, in case some device PROM used
  754. * to boot us wants to speak to us. We just ignore them.
  755. */
  756. __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
  757. "or %%g1, %0, %%g1\n\t"
  758. "wrpr %%g1, 0x0, %%pstate"
  759. : /* No outputs */
  760. : "i" (PSTATE_IE)
  761. : "g1");
  762. }
  763. static struct proc_dir_entry * root_irq_dir;
  764. static struct proc_dir_entry * irq_dir [NUM_IVECS];
  765. #ifdef CONFIG_SMP
  766. static int irq_affinity_read_proc (char *page, char **start, off_t off,
  767. int count, int *eof, void *data)
  768. {
  769. struct ino_bucket *bp = ivector_table + (long)data;
  770. struct irq_desc *desc = bp->irq_info;
  771. struct irqaction *ap = desc->action;
  772. cpumask_t mask;
  773. int len;
  774. mask = get_smpaff_in_irqaction(ap);
  775. if (cpus_empty(mask))
  776. mask = cpu_online_map;
  777. len = cpumask_scnprintf(page, count, mask);
  778. if (count - len < 2)
  779. return -EINVAL;
  780. len += sprintf(page + len, "\n");
  781. return len;
  782. }
  783. static inline void set_intr_affinity(int irq, cpumask_t hw_aff)
  784. {
  785. struct ino_bucket *bp = ivector_table + irq;
  786. struct irq_desc *desc = bp->irq_info;
  787. struct irqaction *ap = desc->action;
  788. /* Users specify affinity in terms of hw cpu ids.
  789. * As soon as we do this, handler_irq() might see and take action.
  790. */
  791. put_smpaff_in_irqaction(ap, hw_aff);
  792. /* Migration is simply done by the next cpu to service this
  793. * interrupt.
  794. */
  795. }
  796. static int irq_affinity_write_proc (struct file *file, const char __user *buffer,
  797. unsigned long count, void *data)
  798. {
  799. int irq = (long) data, full_count = count, err;
  800. cpumask_t new_value;
  801. err = cpumask_parse(buffer, count, new_value);
  802. /*
  803. * Do not allow disabling IRQs completely - it's a too easy
  804. * way to make the system unusable accidentally :-) At least
  805. * one online CPU still has to be targeted.
  806. */
  807. cpus_and(new_value, new_value, cpu_online_map);
  808. if (cpus_empty(new_value))
  809. return -EINVAL;
  810. set_intr_affinity(irq, new_value);
  811. return full_count;
  812. }
  813. #endif
  814. #define MAX_NAMELEN 10
  815. static void register_irq_proc (unsigned int irq)
  816. {
  817. char name [MAX_NAMELEN];
  818. if (!root_irq_dir || irq_dir[irq])
  819. return;
  820. memset(name, 0, MAX_NAMELEN);
  821. sprintf(name, "%x", irq);
  822. /* create /proc/irq/1234 */
  823. irq_dir[irq] = proc_mkdir(name, root_irq_dir);
  824. #ifdef CONFIG_SMP
  825. /* XXX SMP affinity not supported on starfire yet. */
  826. if (this_is_starfire == 0) {
  827. struct proc_dir_entry *entry;
  828. /* create /proc/irq/1234/smp_affinity */
  829. entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
  830. if (entry) {
  831. entry->nlink = 1;
  832. entry->data = (void *)(long)irq;
  833. entry->read_proc = irq_affinity_read_proc;
  834. entry->write_proc = irq_affinity_write_proc;
  835. }
  836. }
  837. #endif
  838. }
  839. void init_irq_proc (void)
  840. {
  841. /* create /proc/irq */
  842. root_irq_dir = proc_mkdir("irq", NULL);
  843. }