irq.c 20 KB

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