irq.c 27 KB

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