irq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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 <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/prom.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].chip->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_desc[virt_irq].affinity;
  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 irq_chip sun4u_irq = {
  311. .typename = "sun4u",
  312. .enable = sun4u_irq_enable,
  313. .disable = sun4u_irq_disable,
  314. .end = sun4u_irq_end,
  315. };
  316. static struct irq_chip 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 irq_chip sun4v_irq = {
  324. .typename = "sun4v",
  325. .enable = sun4v_irq_enable,
  326. .disable = sun4v_irq_disable,
  327. .end = sun4v_irq_end,
  328. };
  329. static struct irq_chip 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. if (desc->chip == &sun4u_irq_ack ||
  346. desc->chip == &sun4v_irq_ack)
  347. return;
  348. desc->chip = (desc->chip == &sun4u_irq ?
  349. &sun4u_irq_ack : &sun4v_irq_ack);
  350. }
  351. unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
  352. {
  353. struct ino_bucket *bucket;
  354. struct irq_handler_data *data;
  355. irq_desc_t *desc;
  356. int ino;
  357. BUG_ON(tlb_type == hypervisor);
  358. ino = (upa_readl(imap) & (IMAP_IGN | IMAP_INO)) + inofixup;
  359. bucket = &ivector_table[ino];
  360. if (!bucket->virt_irq) {
  361. bucket->virt_irq = virt_irq_alloc(__irq(bucket));
  362. irq_desc[bucket->virt_irq].chip = &sun4u_irq;
  363. }
  364. desc = irq_desc + bucket->virt_irq;
  365. if (unlikely(desc->handler_data))
  366. goto out;
  367. data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
  368. if (unlikely(!data)) {
  369. prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
  370. prom_halt();
  371. }
  372. desc->handler_data = data;
  373. data->imap = imap;
  374. data->iclr = iclr;
  375. out:
  376. return bucket->virt_irq;
  377. }
  378. unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
  379. {
  380. struct ino_bucket *bucket;
  381. struct irq_handler_data *data;
  382. unsigned long sysino;
  383. irq_desc_t *desc;
  384. BUG_ON(tlb_type != hypervisor);
  385. sysino = sun4v_devino_to_sysino(devhandle, devino);
  386. bucket = &ivector_table[sysino];
  387. if (!bucket->virt_irq) {
  388. bucket->virt_irq = virt_irq_alloc(__irq(bucket));
  389. irq_desc[bucket->virt_irq].chip = &sun4v_irq;
  390. }
  391. desc = irq_desc + bucket->virt_irq;
  392. if (unlikely(desc->handler_data))
  393. goto out;
  394. data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
  395. if (unlikely(!data)) {
  396. prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
  397. prom_halt();
  398. }
  399. desc->handler_data = data;
  400. /* Catch accidental accesses to these things. IMAP/ICLR handling
  401. * is done by hypervisor calls on sun4v platforms, not by direct
  402. * register accesses.
  403. */
  404. data->imap = ~0UL;
  405. data->iclr = ~0UL;
  406. out:
  407. return bucket->virt_irq;
  408. }
  409. void ack_bad_irq(unsigned int virt_irq)
  410. {
  411. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  412. unsigned int ino = 0xdeadbeef;
  413. if (bucket)
  414. ino = bucket - &ivector_table[0];
  415. printk(KERN_CRIT "Unexpected IRQ from ino[%x] virt_irq[%u]\n",
  416. ino, virt_irq);
  417. }
  418. #ifndef CONFIG_SMP
  419. extern irqreturn_t timer_interrupt(int, void *);
  420. void timer_irq(int irq, struct pt_regs *regs)
  421. {
  422. unsigned long clr_mask = 1 << irq;
  423. unsigned long tick_mask = tick_ops->softint_mask;
  424. struct pt_regs *old_regs;
  425. if (get_softint() & tick_mask) {
  426. irq = 0;
  427. clr_mask = tick_mask;
  428. }
  429. clear_softint(clr_mask);
  430. old_regs = set_irq_regs(regs);
  431. irq_enter();
  432. kstat_this_cpu.irqs[0]++;
  433. timer_interrupt(irq, NULL);
  434. irq_exit();
  435. set_irq_regs(old_regs);
  436. }
  437. #endif
  438. void handler_irq(int irq, struct pt_regs *regs)
  439. {
  440. struct ino_bucket *bucket;
  441. struct pt_regs *old_regs;
  442. clear_softint(1 << irq);
  443. old_regs = set_irq_regs(regs);
  444. irq_enter();
  445. /* Sliiiick... */
  446. bucket = __bucket(xchg32(irq_work(smp_processor_id()), 0));
  447. while (bucket) {
  448. struct ino_bucket *next = __bucket(bucket->irq_chain);
  449. bucket->irq_chain = 0;
  450. __do_IRQ(bucket->virt_irq);
  451. bucket = next;
  452. }
  453. irq_exit();
  454. set_irq_regs(old_regs);
  455. }
  456. struct sun5_timer {
  457. u64 count0;
  458. u64 limit0;
  459. u64 count1;
  460. u64 limit1;
  461. };
  462. static struct sun5_timer *prom_timers;
  463. static u64 prom_limit0, prom_limit1;
  464. static void map_prom_timers(void)
  465. {
  466. struct device_node *dp;
  467. unsigned int *addr;
  468. /* PROM timer node hangs out in the top level of device siblings... */
  469. dp = of_find_node_by_path("/");
  470. dp = dp->child;
  471. while (dp) {
  472. if (!strcmp(dp->name, "counter-timer"))
  473. break;
  474. dp = dp->sibling;
  475. }
  476. /* Assume if node is not present, PROM uses different tick mechanism
  477. * which we should not care about.
  478. */
  479. if (!dp) {
  480. prom_timers = (struct sun5_timer *) 0;
  481. return;
  482. }
  483. /* If PROM is really using this, it must be mapped by him. */
  484. addr = of_get_property(dp, "address", NULL);
  485. if (!addr) {
  486. prom_printf("PROM does not have timer mapped, trying to continue.\n");
  487. prom_timers = (struct sun5_timer *) 0;
  488. return;
  489. }
  490. prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
  491. }
  492. static void kill_prom_timer(void)
  493. {
  494. if (!prom_timers)
  495. return;
  496. /* Save them away for later. */
  497. prom_limit0 = prom_timers->limit0;
  498. prom_limit1 = prom_timers->limit1;
  499. /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
  500. * We turn both off here just to be paranoid.
  501. */
  502. prom_timers->limit0 = 0;
  503. prom_timers->limit1 = 0;
  504. /* Wheee, eat the interrupt packet too... */
  505. __asm__ __volatile__(
  506. " mov 0x40, %%g2\n"
  507. " ldxa [%%g0] %0, %%g1\n"
  508. " ldxa [%%g2] %1, %%g1\n"
  509. " stxa %%g0, [%%g0] %0\n"
  510. " membar #Sync\n"
  511. : /* no outputs */
  512. : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
  513. : "g1", "g2");
  514. }
  515. void init_irqwork_curcpu(void)
  516. {
  517. int cpu = hard_smp_processor_id();
  518. trap_block[cpu].irq_worklist = 0;
  519. }
  520. static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type)
  521. {
  522. unsigned long num_entries = 128;
  523. unsigned long status;
  524. status = sun4v_cpu_qconf(type, paddr, num_entries);
  525. if (status != HV_EOK) {
  526. prom_printf("SUN4V: sun4v_cpu_qconf(%lu:%lx:%lu) failed, "
  527. "err %lu\n", type, paddr, num_entries, status);
  528. prom_halt();
  529. }
  530. }
  531. static void __cpuinit sun4v_register_mondo_queues(int this_cpu)
  532. {
  533. struct trap_per_cpu *tb = &trap_block[this_cpu];
  534. register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO);
  535. register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO);
  536. register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR);
  537. register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR);
  538. }
  539. static void __cpuinit alloc_one_mondo(unsigned long *pa_ptr, int use_bootmem)
  540. {
  541. void *page;
  542. if (use_bootmem)
  543. page = alloc_bootmem_low_pages(PAGE_SIZE);
  544. else
  545. page = (void *) get_zeroed_page(GFP_ATOMIC);
  546. if (!page) {
  547. prom_printf("SUN4V: Error, cannot allocate mondo queue.\n");
  548. prom_halt();
  549. }
  550. *pa_ptr = __pa(page);
  551. }
  552. static void __cpuinit alloc_one_kbuf(unsigned long *pa_ptr, int use_bootmem)
  553. {
  554. void *page;
  555. if (use_bootmem)
  556. page = alloc_bootmem_low_pages(PAGE_SIZE);
  557. else
  558. page = (void *) get_zeroed_page(GFP_ATOMIC);
  559. if (!page) {
  560. prom_printf("SUN4V: Error, cannot allocate kbuf page.\n");
  561. prom_halt();
  562. }
  563. *pa_ptr = __pa(page);
  564. }
  565. static void __cpuinit init_cpu_send_mondo_info(struct trap_per_cpu *tb, int use_bootmem)
  566. {
  567. #ifdef CONFIG_SMP
  568. void *page;
  569. BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
  570. if (use_bootmem)
  571. page = alloc_bootmem_low_pages(PAGE_SIZE);
  572. else
  573. page = (void *) get_zeroed_page(GFP_ATOMIC);
  574. if (!page) {
  575. prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
  576. prom_halt();
  577. }
  578. tb->cpu_mondo_block_pa = __pa(page);
  579. tb->cpu_list_pa = __pa(page + 64);
  580. #endif
  581. }
  582. /* Allocate and register the mondo and error queues for this cpu. */
  583. void __cpuinit sun4v_init_mondo_queues(int use_bootmem, int cpu, int alloc, int load)
  584. {
  585. struct trap_per_cpu *tb = &trap_block[cpu];
  586. if (alloc) {
  587. alloc_one_mondo(&tb->cpu_mondo_pa, use_bootmem);
  588. alloc_one_mondo(&tb->dev_mondo_pa, use_bootmem);
  589. alloc_one_mondo(&tb->resum_mondo_pa, use_bootmem);
  590. alloc_one_kbuf(&tb->resum_kernel_buf_pa, use_bootmem);
  591. alloc_one_mondo(&tb->nonresum_mondo_pa, use_bootmem);
  592. alloc_one_kbuf(&tb->nonresum_kernel_buf_pa, use_bootmem);
  593. init_cpu_send_mondo_info(tb, use_bootmem);
  594. }
  595. if (load) {
  596. if (cpu != hard_smp_processor_id()) {
  597. prom_printf("SUN4V: init mondo on cpu %d not %d\n",
  598. cpu, hard_smp_processor_id());
  599. prom_halt();
  600. }
  601. sun4v_register_mondo_queues(cpu);
  602. }
  603. }
  604. static struct irqaction timer_irq_action = {
  605. .name = "timer",
  606. };
  607. /* Only invoked on boot processor. */
  608. void __init init_IRQ(void)
  609. {
  610. map_prom_timers();
  611. kill_prom_timer();
  612. memset(&ivector_table[0], 0, sizeof(ivector_table));
  613. if (tlb_type == hypervisor)
  614. sun4v_init_mondo_queues(1, hard_smp_processor_id(), 1, 1);
  615. /* We need to clear any IRQ's pending in the soft interrupt
  616. * registers, a spurious one could be left around from the
  617. * PROM timer which we just disabled.
  618. */
  619. clear_softint(get_softint());
  620. /* Now that ivector table is initialized, it is safe
  621. * to receive IRQ vector traps. We will normally take
  622. * one or two right now, in case some device PROM used
  623. * to boot us wants to speak to us. We just ignore them.
  624. */
  625. __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
  626. "or %%g1, %0, %%g1\n\t"
  627. "wrpr %%g1, 0x0, %%pstate"
  628. : /* No outputs */
  629. : "i" (PSTATE_IE)
  630. : "g1");
  631. irq_desc[0].action = &timer_irq_action;
  632. }