irq.c 20 KB

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