irq.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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 <linux/irq.h>
  25. #include <asm/ptrace.h>
  26. #include <asm/processor.h>
  27. #include <asm/atomic.h>
  28. #include <asm/system.h>
  29. #include <asm/irq.h>
  30. #include <asm/io.h>
  31. #include <asm/sbus.h>
  32. #include <asm/iommu.h>
  33. #include <asm/upa.h>
  34. #include <asm/oplib.h>
  35. #include <asm/timer.h>
  36. #include <asm/smp.h>
  37. #include <asm/starfire.h>
  38. #include <asm/uaccess.h>
  39. #include <asm/cache.h>
  40. #include <asm/cpudata.h>
  41. #include <asm/auxio.h>
  42. #include <asm/head.h>
  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. * If you make changes to ino_bucket, please update hand coded assembler
  56. * of the vectored interrupt trap handler(s) in entry.S and sun4v_ivec.S
  57. */
  58. struct ino_bucket {
  59. /* Next handler in per-CPU IRQ worklist. We know that
  60. * bucket pointers have the high 32-bits clear, so to
  61. * save space we only store the bits we need.
  62. */
  63. /*0x00*/unsigned int irq_chain;
  64. /* Virtual interrupt number assigned to this INO. */
  65. /*0x04*/unsigned int virt_irq;
  66. };
  67. #define NUM_IVECS (IMAP_INR + 1)
  68. struct ino_bucket ivector_table[NUM_IVECS] __attribute__ ((aligned (SMP_CACHE_BYTES)));
  69. #define __irq_ino(irq) \
  70. (((struct ino_bucket *)(unsigned long)(irq)) - &ivector_table[0])
  71. #define __bucket(irq) ((struct ino_bucket *)(unsigned long)(irq))
  72. #define __irq(bucket) ((unsigned int)(unsigned long)(bucket))
  73. /* This has to be in the main kernel image, it cannot be
  74. * turned into per-cpu data. The reason is that the main
  75. * kernel image is locked into the TLB and this structure
  76. * is accessed from the vectored interrupt trap handler. If
  77. * access to this structure takes a TLB miss it could cause
  78. * the 5-level sparc v9 trap stack to overflow.
  79. */
  80. #define irq_work(__cpu) &(trap_block[(__cpu)].irq_worklist)
  81. static unsigned int virt_to_real_irq_table[NR_IRQS];
  82. static unsigned char virt_irq_cur = 1;
  83. static unsigned char virt_irq_alloc(unsigned int real_irq)
  84. {
  85. unsigned char ent;
  86. BUILD_BUG_ON(NR_IRQS >= 256);
  87. ent = virt_irq_cur;
  88. if (ent >= NR_IRQS) {
  89. printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
  90. return 0;
  91. }
  92. virt_irq_cur = ent + 1;
  93. virt_to_real_irq_table[ent] = real_irq;
  94. return ent;
  95. }
  96. #if 0 /* Currently unused. */
  97. static unsigned char real_to_virt_irq(unsigned int real_irq)
  98. {
  99. struct ino_bucket *bucket = __bucket(real_irq);
  100. return bucket->virt_irq;
  101. }
  102. #endif
  103. static unsigned int virt_to_real_irq(unsigned char virt_irq)
  104. {
  105. return virt_to_real_irq_table[virt_irq];
  106. }
  107. /*
  108. * /proc/interrupts printing:
  109. */
  110. int show_interrupts(struct seq_file *p, void *v)
  111. {
  112. int i = *(loff_t *) v, j;
  113. struct irqaction * action;
  114. unsigned long flags;
  115. if (i == 0) {
  116. seq_printf(p, " ");
  117. for_each_online_cpu(j)
  118. seq_printf(p, "CPU%d ",j);
  119. seq_putc(p, '\n');
  120. }
  121. if (i < NR_IRQS) {
  122. spin_lock_irqsave(&irq_desc[i].lock, flags);
  123. action = irq_desc[i].action;
  124. if (!action)
  125. goto skip;
  126. seq_printf(p, "%3d: ",i);
  127. #ifndef CONFIG_SMP
  128. seq_printf(p, "%10u ", kstat_irqs(i));
  129. #else
  130. for_each_online_cpu(j)
  131. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  132. #endif
  133. seq_printf(p, " %9s", irq_desc[i].handler->typename);
  134. seq_printf(p, " %s", action->name);
  135. for (action=action->next; action; action = action->next)
  136. seq_printf(p, ", %s", action->name);
  137. seq_putc(p, '\n');
  138. skip:
  139. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  140. }
  141. return 0;
  142. }
  143. extern unsigned long real_hard_smp_processor_id(void);
  144. static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid)
  145. {
  146. unsigned int tid;
  147. if (this_is_starfire) {
  148. tid = starfire_translate(imap, cpuid);
  149. tid <<= IMAP_TID_SHIFT;
  150. tid &= IMAP_TID_UPA;
  151. } else {
  152. if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  153. unsigned long ver;
  154. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  155. if ((ver >> 32UL) == __JALAPENO_ID ||
  156. (ver >> 32UL) == __SERRANO_ID) {
  157. tid = cpuid << IMAP_TID_SHIFT;
  158. tid &= IMAP_TID_JBUS;
  159. } else {
  160. unsigned int a = cpuid & 0x1f;
  161. unsigned int n = (cpuid >> 5) & 0x1f;
  162. tid = ((a << IMAP_AID_SHIFT) |
  163. (n << IMAP_NID_SHIFT));
  164. tid &= (IMAP_AID_SAFARI |
  165. IMAP_NID_SAFARI);;
  166. }
  167. } else {
  168. tid = cpuid << IMAP_TID_SHIFT;
  169. tid &= IMAP_TID_UPA;
  170. }
  171. }
  172. return tid;
  173. }
  174. struct irq_handler_data {
  175. unsigned long iclr;
  176. unsigned long imap;
  177. void (*pre_handler)(unsigned int, void *, void *);
  178. void *pre_handler_arg1;
  179. void *pre_handler_arg2;
  180. };
  181. static inline struct ino_bucket *virt_irq_to_bucket(unsigned int virt_irq)
  182. {
  183. unsigned int real_irq = virt_to_real_irq(virt_irq);
  184. struct ino_bucket *bucket = NULL;
  185. if (likely(real_irq))
  186. bucket = __bucket(real_irq);
  187. return bucket;
  188. }
  189. #ifdef CONFIG_SMP
  190. static int irq_choose_cpu(unsigned int virt_irq)
  191. {
  192. cpumask_t mask = irq_affinity[virt_irq];
  193. int cpuid;
  194. if (cpus_equal(mask, CPU_MASK_ALL)) {
  195. static int irq_rover;
  196. static DEFINE_SPINLOCK(irq_rover_lock);
  197. unsigned long flags;
  198. /* Round-robin distribution... */
  199. do_round_robin:
  200. spin_lock_irqsave(&irq_rover_lock, flags);
  201. while (!cpu_online(irq_rover)) {
  202. if (++irq_rover >= NR_CPUS)
  203. irq_rover = 0;
  204. }
  205. cpuid = irq_rover;
  206. do {
  207. if (++irq_rover >= NR_CPUS)
  208. irq_rover = 0;
  209. } while (!cpu_online(irq_rover));
  210. spin_unlock_irqrestore(&irq_rover_lock, flags);
  211. } else {
  212. cpumask_t tmp;
  213. cpus_and(tmp, cpu_online_map, mask);
  214. if (cpus_empty(tmp))
  215. goto do_round_robin;
  216. cpuid = first_cpu(tmp);
  217. }
  218. return cpuid;
  219. }
  220. #else
  221. static int irq_choose_cpu(unsigned int virt_irq)
  222. {
  223. return real_hard_smp_processor_id();
  224. }
  225. #endif
  226. static void sun4u_irq_enable(unsigned int virt_irq)
  227. {
  228. irq_desc_t *desc = irq_desc + virt_irq;
  229. struct irq_handler_data *data = desc->handler_data;
  230. if (likely(data)) {
  231. unsigned long cpuid, imap;
  232. unsigned int tid;
  233. cpuid = irq_choose_cpu(virt_irq);
  234. imap = data->imap;
  235. tid = sun4u_compute_tid(imap, cpuid);
  236. upa_writel(tid | IMAP_VALID, imap);
  237. }
  238. }
  239. static void sun4u_irq_disable(unsigned int virt_irq)
  240. {
  241. irq_desc_t *desc = irq_desc + virt_irq;
  242. struct irq_handler_data *data = desc->handler_data;
  243. if (likely(data)) {
  244. unsigned long imap = data->imap;
  245. u32 tmp = upa_readl(imap);
  246. tmp &= ~IMAP_VALID;
  247. upa_writel(tmp, imap);
  248. }
  249. }
  250. static void sun4u_irq_end(unsigned int virt_irq)
  251. {
  252. irq_desc_t *desc = irq_desc + virt_irq;
  253. struct irq_handler_data *data = desc->handler_data;
  254. if (likely(data))
  255. upa_writel(ICLR_IDLE, data->iclr);
  256. }
  257. static void sun4v_irq_enable(unsigned int virt_irq)
  258. {
  259. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  260. unsigned int ino = bucket - &ivector_table[0];
  261. if (likely(bucket)) {
  262. unsigned long cpuid;
  263. int err;
  264. cpuid = irq_choose_cpu(virt_irq);
  265. err = sun4v_intr_settarget(ino, cpuid);
  266. if (err != HV_EOK)
  267. printk("sun4v_intr_settarget(%x,%lu): err(%d)\n",
  268. ino, cpuid, err);
  269. err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
  270. if (err != HV_EOK)
  271. printk("sun4v_intr_setenabled(%x): err(%d)\n",
  272. ino, err);
  273. }
  274. }
  275. static void sun4v_irq_disable(unsigned int virt_irq)
  276. {
  277. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  278. unsigned int ino = bucket - &ivector_table[0];
  279. if (likely(bucket)) {
  280. int err;
  281. err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
  282. if (err != HV_EOK)
  283. printk("sun4v_intr_setenabled(%x): "
  284. "err(%d)\n", ino, err);
  285. }
  286. }
  287. static void sun4v_irq_end(unsigned int virt_irq)
  288. {
  289. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  290. unsigned int ino = bucket - &ivector_table[0];
  291. if (likely(bucket)) {
  292. int err;
  293. err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
  294. if (err != HV_EOK)
  295. printk("sun4v_intr_setstate(%x): "
  296. "err(%d)\n", ino, err);
  297. }
  298. }
  299. static void run_pre_handler(unsigned int virt_irq)
  300. {
  301. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  302. irq_desc_t *desc = irq_desc + virt_irq;
  303. struct irq_handler_data *data = desc->handler_data;
  304. if (likely(data->pre_handler)) {
  305. data->pre_handler(__irq_ino(__irq(bucket)),
  306. data->pre_handler_arg1,
  307. data->pre_handler_arg2);
  308. }
  309. }
  310. static struct hw_interrupt_type sun4u_irq = {
  311. .typename = "sun4u",
  312. .enable = sun4u_irq_enable,
  313. .disable = sun4u_irq_disable,
  314. .end = sun4u_irq_end,
  315. };
  316. static struct hw_interrupt_type sun4u_irq_ack = {
  317. .typename = "sun4u+ack",
  318. .enable = sun4u_irq_enable,
  319. .disable = sun4u_irq_disable,
  320. .ack = run_pre_handler,
  321. .end = sun4u_irq_end,
  322. };
  323. static struct hw_interrupt_type sun4v_irq = {
  324. .typename = "sun4v",
  325. .enable = sun4v_irq_enable,
  326. .disable = sun4v_irq_disable,
  327. .end = sun4v_irq_end,
  328. };
  329. static struct hw_interrupt_type sun4v_irq_ack = {
  330. .typename = "sun4v+ack",
  331. .enable = sun4v_irq_enable,
  332. .disable = sun4v_irq_disable,
  333. .ack = run_pre_handler,
  334. .end = sun4v_irq_end,
  335. };
  336. void irq_install_pre_handler(int virt_irq,
  337. void (*func)(unsigned int, void *, void *),
  338. void *arg1, void *arg2)
  339. {
  340. irq_desc_t *desc = irq_desc + virt_irq;
  341. struct irq_handler_data *data = desc->handler_data;
  342. data->pre_handler = func;
  343. data->pre_handler_arg1 = arg1;
  344. data->pre_handler_arg2 = arg2;
  345. desc->handler = (desc->handler == &sun4u_irq ?
  346. &sun4u_irq_ack : &sun4v_irq_ack);
  347. }
  348. unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
  349. {
  350. struct ino_bucket *bucket;
  351. struct irq_handler_data *data;
  352. irq_desc_t *desc;
  353. int ino;
  354. BUG_ON(tlb_type == hypervisor);
  355. ino = (upa_readl(imap) & (IMAP_IGN | IMAP_INO)) + inofixup;
  356. bucket = &ivector_table[ino];
  357. if (!bucket->virt_irq) {
  358. bucket->virt_irq = virt_irq_alloc(__irq(bucket));
  359. irq_desc[bucket->virt_irq].handler = &sun4u_irq;
  360. }
  361. desc = irq_desc + bucket->virt_irq;
  362. if (unlikely(desc->handler_data))
  363. goto out;
  364. data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
  365. if (unlikely(!data)) {
  366. prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
  367. prom_halt();
  368. }
  369. desc->handler_data = data;
  370. data->imap = imap;
  371. data->iclr = iclr;
  372. out:
  373. return bucket->virt_irq;
  374. }
  375. unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
  376. {
  377. struct ino_bucket *bucket;
  378. struct irq_handler_data *data;
  379. unsigned long sysino;
  380. irq_desc_t *desc;
  381. BUG_ON(tlb_type != hypervisor);
  382. sysino = sun4v_devino_to_sysino(devhandle, devino);
  383. bucket = &ivector_table[sysino];
  384. if (!bucket->virt_irq) {
  385. bucket->virt_irq = virt_irq_alloc(__irq(bucket));
  386. irq_desc[bucket->virt_irq].handler = &sun4v_irq;
  387. }
  388. desc = irq_desc + bucket->virt_irq;
  389. if (unlikely(desc->handler_data))
  390. goto out;
  391. data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
  392. if (unlikely(!data)) {
  393. prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
  394. prom_halt();
  395. }
  396. desc->handler_data = data;
  397. /* Catch accidental accesses to these things. IMAP/ICLR handling
  398. * is done by hypervisor calls on sun4v platforms, not by direct
  399. * register accesses.
  400. */
  401. data->imap = ~0UL;
  402. data->iclr = ~0UL;
  403. out:
  404. return bucket->virt_irq;
  405. }
  406. void hw_resend_irq(struct hw_interrupt_type *handler, unsigned int virt_irq)
  407. {
  408. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  409. unsigned long pstate;
  410. unsigned int *ent;
  411. __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
  412. __asm__ __volatile__("wrpr %0, %1, %%pstate"
  413. : : "r" (pstate), "i" (PSTATE_IE));
  414. ent = irq_work(smp_processor_id());
  415. bucket->irq_chain = *ent;
  416. *ent = __irq(bucket);
  417. set_softint(1 << PIL_DEVICE_IRQ);
  418. __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
  419. }
  420. void ack_bad_irq(unsigned int virt_irq)
  421. {
  422. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  423. unsigned int ino = 0xdeadbeef;
  424. if (bucket)
  425. ino = bucket - &ivector_table[0];
  426. printk(KERN_CRIT "Unexpected IRQ from ino[%x] virt_irq[%u]\n",
  427. ino, virt_irq);
  428. }
  429. #ifndef CONFIG_SMP
  430. extern irqreturn_t timer_interrupt(int, void *, struct pt_regs *);
  431. void timer_irq(int irq, struct pt_regs *regs)
  432. {
  433. unsigned long clr_mask = 1 << irq;
  434. unsigned long tick_mask = tick_ops->softint_mask;
  435. if (get_softint() & tick_mask) {
  436. irq = 0;
  437. clr_mask = tick_mask;
  438. }
  439. clear_softint(clr_mask);
  440. irq_enter();
  441. kstat_this_cpu.irqs[0]++;
  442. timer_interrupt(irq, NULL, regs);
  443. irq_exit();
  444. }
  445. #endif
  446. void handler_irq(int irq, struct pt_regs *regs)
  447. {
  448. struct ino_bucket *bucket;
  449. clear_softint(1 << irq);
  450. irq_enter();
  451. /* Sliiiick... */
  452. bucket = __bucket(xchg32(irq_work(smp_processor_id()), 0));
  453. while (bucket) {
  454. struct ino_bucket *next = __bucket(bucket->irq_chain);
  455. bucket->irq_chain = 0;
  456. __do_IRQ(bucket->virt_irq, regs);
  457. bucket = next;
  458. }
  459. irq_exit();
  460. }
  461. #ifdef CONFIG_BLK_DEV_FD
  462. extern irqreturn_t floppy_interrupt(int, void *, struct pt_regs *);
  463. /* XXX No easy way to include asm/floppy.h XXX */
  464. extern unsigned char *pdma_vaddr;
  465. extern unsigned long pdma_size;
  466. extern volatile int doing_pdma;
  467. extern unsigned long fdc_status;
  468. irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie, struct pt_regs *regs)
  469. {
  470. if (likely(doing_pdma)) {
  471. void __iomem *stat = (void __iomem *) fdc_status;
  472. unsigned char *vaddr = pdma_vaddr;
  473. unsigned long size = pdma_size;
  474. u8 val;
  475. while (size) {
  476. val = readb(stat);
  477. if (unlikely(!(val & 0x80))) {
  478. pdma_vaddr = vaddr;
  479. pdma_size = size;
  480. return IRQ_HANDLED;
  481. }
  482. if (unlikely(!(val & 0x20))) {
  483. pdma_vaddr = vaddr;
  484. pdma_size = size;
  485. doing_pdma = 0;
  486. goto main_interrupt;
  487. }
  488. if (val & 0x40) {
  489. /* read */
  490. *vaddr++ = readb(stat + 1);
  491. } else {
  492. unsigned char data = *vaddr++;
  493. /* write */
  494. writeb(data, stat + 1);
  495. }
  496. size--;
  497. }
  498. pdma_vaddr = vaddr;
  499. pdma_size = size;
  500. /* Send Terminal Count pulse to floppy controller. */
  501. val = readb(auxio_register);
  502. val |= AUXIO_AUX1_FTCNT;
  503. writeb(val, auxio_register);
  504. val &= ~AUXIO_AUX1_FTCNT;
  505. writeb(val, auxio_register);
  506. doing_pdma = 0;
  507. }
  508. main_interrupt:
  509. return floppy_interrupt(irq, dev_cookie, regs);
  510. }
  511. EXPORT_SYMBOL(sparc_floppy_irq);
  512. #endif
  513. struct sun5_timer {
  514. u64 count0;
  515. u64 limit0;
  516. u64 count1;
  517. u64 limit1;
  518. };
  519. static struct sun5_timer *prom_timers;
  520. static u64 prom_limit0, prom_limit1;
  521. static void map_prom_timers(void)
  522. {
  523. unsigned int addr[3];
  524. int tnode, err;
  525. /* PROM timer node hangs out in the top level of device siblings... */
  526. tnode = prom_finddevice("/counter-timer");
  527. /* Assume if node is not present, PROM uses different tick mechanism
  528. * which we should not care about.
  529. */
  530. if (tnode == 0 || tnode == -1) {
  531. prom_timers = (struct sun5_timer *) 0;
  532. return;
  533. }
  534. /* If PROM is really using this, it must be mapped by him. */
  535. err = prom_getproperty(tnode, "address", (char *)addr, sizeof(addr));
  536. if (err == -1) {
  537. prom_printf("PROM does not have timer mapped, trying to continue.\n");
  538. prom_timers = (struct sun5_timer *) 0;
  539. return;
  540. }
  541. prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
  542. }
  543. static void kill_prom_timer(void)
  544. {
  545. if (!prom_timers)
  546. return;
  547. /* Save them away for later. */
  548. prom_limit0 = prom_timers->limit0;
  549. prom_limit1 = prom_timers->limit1;
  550. /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
  551. * We turn both off here just to be paranoid.
  552. */
  553. prom_timers->limit0 = 0;
  554. prom_timers->limit1 = 0;
  555. /* Wheee, eat the interrupt packet too... */
  556. __asm__ __volatile__(
  557. " mov 0x40, %%g2\n"
  558. " ldxa [%%g0] %0, %%g1\n"
  559. " ldxa [%%g2] %1, %%g1\n"
  560. " stxa %%g0, [%%g0] %0\n"
  561. " membar #Sync\n"
  562. : /* no outputs */
  563. : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
  564. : "g1", "g2");
  565. }
  566. void init_irqwork_curcpu(void)
  567. {
  568. int cpu = hard_smp_processor_id();
  569. trap_block[cpu].irq_worklist = 0;
  570. }
  571. static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type)
  572. {
  573. unsigned long num_entries = 128;
  574. unsigned long status;
  575. status = sun4v_cpu_qconf(type, paddr, num_entries);
  576. if (status != HV_EOK) {
  577. prom_printf("SUN4V: sun4v_cpu_qconf(%lu:%lx:%lu) failed, "
  578. "err %lu\n", type, paddr, num_entries, status);
  579. prom_halt();
  580. }
  581. }
  582. static void __cpuinit sun4v_register_mondo_queues(int this_cpu)
  583. {
  584. struct trap_per_cpu *tb = &trap_block[this_cpu];
  585. register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO);
  586. register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO);
  587. register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR);
  588. register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR);
  589. }
  590. static void __cpuinit alloc_one_mondo(unsigned long *pa_ptr, int use_bootmem)
  591. {
  592. void *page;
  593. if (use_bootmem)
  594. page = alloc_bootmem_low_pages(PAGE_SIZE);
  595. else
  596. page = (void *) get_zeroed_page(GFP_ATOMIC);
  597. if (!page) {
  598. prom_printf("SUN4V: Error, cannot allocate mondo queue.\n");
  599. prom_halt();
  600. }
  601. *pa_ptr = __pa(page);
  602. }
  603. static void __cpuinit alloc_one_kbuf(unsigned long *pa_ptr, int use_bootmem)
  604. {
  605. void *page;
  606. if (use_bootmem)
  607. page = alloc_bootmem_low_pages(PAGE_SIZE);
  608. else
  609. page = (void *) get_zeroed_page(GFP_ATOMIC);
  610. if (!page) {
  611. prom_printf("SUN4V: Error, cannot allocate kbuf page.\n");
  612. prom_halt();
  613. }
  614. *pa_ptr = __pa(page);
  615. }
  616. static void __cpuinit init_cpu_send_mondo_info(struct trap_per_cpu *tb, int use_bootmem)
  617. {
  618. #ifdef CONFIG_SMP
  619. void *page;
  620. BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
  621. if (use_bootmem)
  622. page = alloc_bootmem_low_pages(PAGE_SIZE);
  623. else
  624. page = (void *) get_zeroed_page(GFP_ATOMIC);
  625. if (!page) {
  626. prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
  627. prom_halt();
  628. }
  629. tb->cpu_mondo_block_pa = __pa(page);
  630. tb->cpu_list_pa = __pa(page + 64);
  631. #endif
  632. }
  633. /* Allocate and register the mondo and error queues for this cpu. */
  634. void __cpuinit sun4v_init_mondo_queues(int use_bootmem, int cpu, int alloc, int load)
  635. {
  636. struct trap_per_cpu *tb = &trap_block[cpu];
  637. if (alloc) {
  638. alloc_one_mondo(&tb->cpu_mondo_pa, use_bootmem);
  639. alloc_one_mondo(&tb->dev_mondo_pa, use_bootmem);
  640. alloc_one_mondo(&tb->resum_mondo_pa, use_bootmem);
  641. alloc_one_kbuf(&tb->resum_kernel_buf_pa, use_bootmem);
  642. alloc_one_mondo(&tb->nonresum_mondo_pa, use_bootmem);
  643. alloc_one_kbuf(&tb->nonresum_kernel_buf_pa, use_bootmem);
  644. init_cpu_send_mondo_info(tb, use_bootmem);
  645. }
  646. if (load) {
  647. if (cpu != hard_smp_processor_id()) {
  648. prom_printf("SUN4V: init mondo on cpu %d not %d\n",
  649. cpu, hard_smp_processor_id());
  650. prom_halt();
  651. }
  652. sun4v_register_mondo_queues(cpu);
  653. }
  654. }
  655. static struct irqaction timer_irq_action = {
  656. .name = "timer",
  657. };
  658. /* Only invoked on boot processor. */
  659. void __init init_IRQ(void)
  660. {
  661. map_prom_timers();
  662. kill_prom_timer();
  663. memset(&ivector_table[0], 0, sizeof(ivector_table));
  664. if (tlb_type == hypervisor)
  665. sun4v_init_mondo_queues(1, hard_smp_processor_id(), 1, 1);
  666. /* We need to clear any IRQ's pending in the soft interrupt
  667. * registers, a spurious one could be left around from the
  668. * PROM timer which we just disabled.
  669. */
  670. clear_softint(get_softint());
  671. /* Now that ivector table is initialized, it is safe
  672. * to receive IRQ vector traps. We will normally take
  673. * one or two right now, in case some device PROM used
  674. * to boot us wants to speak to us. We just ignore them.
  675. */
  676. __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
  677. "or %%g1, %0, %%g1\n\t"
  678. "wrpr %%g1, 0x0, %%pstate"
  679. : /* No outputs */
  680. : "i" (PSTATE_IE)
  681. : "g1");
  682. irq_desc[0].action = &timer_irq_action;
  683. }