irq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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. struct irq_handler_data *data = get_irq_chip_data(virt_irq);
  229. if (likely(data)) {
  230. unsigned long cpuid, imap;
  231. unsigned int tid;
  232. cpuid = irq_choose_cpu(virt_irq);
  233. imap = data->imap;
  234. tid = sun4u_compute_tid(imap, cpuid);
  235. upa_writel(tid | IMAP_VALID, imap);
  236. }
  237. }
  238. static void sun4u_irq_disable(unsigned int virt_irq)
  239. {
  240. struct irq_handler_data *data = get_irq_chip_data(virt_irq);
  241. if (likely(data)) {
  242. unsigned long imap = data->imap;
  243. u32 tmp = upa_readl(imap);
  244. tmp &= ~IMAP_VALID;
  245. upa_writel(tmp, imap);
  246. }
  247. }
  248. static void sun4u_irq_end(unsigned int virt_irq)
  249. {
  250. struct irq_handler_data *data = get_irq_chip_data(virt_irq);
  251. if (likely(data))
  252. upa_writel(ICLR_IDLE, data->iclr);
  253. }
  254. static void sun4v_irq_enable(unsigned int virt_irq)
  255. {
  256. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  257. unsigned int ino = bucket - &ivector_table[0];
  258. if (likely(bucket)) {
  259. unsigned long cpuid;
  260. int err;
  261. cpuid = irq_choose_cpu(virt_irq);
  262. err = sun4v_intr_settarget(ino, cpuid);
  263. if (err != HV_EOK)
  264. printk("sun4v_intr_settarget(%x,%lu): err(%d)\n",
  265. ino, cpuid, err);
  266. err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
  267. if (err != HV_EOK)
  268. printk("sun4v_intr_setenabled(%x): err(%d)\n",
  269. ino, err);
  270. }
  271. }
  272. static void sun4v_irq_disable(unsigned int virt_irq)
  273. {
  274. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  275. unsigned int ino = bucket - &ivector_table[0];
  276. if (likely(bucket)) {
  277. int err;
  278. err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
  279. if (err != HV_EOK)
  280. printk("sun4v_intr_setenabled(%x): "
  281. "err(%d)\n", ino, err);
  282. }
  283. }
  284. static void sun4v_irq_end(unsigned int virt_irq)
  285. {
  286. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  287. unsigned int ino = bucket - &ivector_table[0];
  288. if (likely(bucket)) {
  289. int err;
  290. err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
  291. if (err != HV_EOK)
  292. printk("sun4v_intr_setstate(%x): "
  293. "err(%d)\n", ino, err);
  294. }
  295. }
  296. static void run_pre_handler(unsigned int virt_irq)
  297. {
  298. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  299. struct irq_handler_data *data = get_irq_chip_data(virt_irq);
  300. if (likely(data->pre_handler)) {
  301. data->pre_handler(__irq_ino(__irq(bucket)),
  302. data->pre_handler_arg1,
  303. data->pre_handler_arg2);
  304. }
  305. }
  306. static struct irq_chip sun4u_irq = {
  307. .typename = "sun4u",
  308. .enable = sun4u_irq_enable,
  309. .disable = sun4u_irq_disable,
  310. .end = sun4u_irq_end,
  311. };
  312. static struct irq_chip sun4u_irq_ack = {
  313. .typename = "sun4u+ack",
  314. .enable = sun4u_irq_enable,
  315. .disable = sun4u_irq_disable,
  316. .ack = run_pre_handler,
  317. .end = sun4u_irq_end,
  318. };
  319. static struct irq_chip sun4v_irq = {
  320. .typename = "sun4v",
  321. .enable = sun4v_irq_enable,
  322. .disable = sun4v_irq_disable,
  323. .end = sun4v_irq_end,
  324. };
  325. static struct irq_chip sun4v_irq_ack = {
  326. .typename = "sun4v+ack",
  327. .enable = sun4v_irq_enable,
  328. .disable = sun4v_irq_disable,
  329. .ack = run_pre_handler,
  330. .end = sun4v_irq_end,
  331. };
  332. void irq_install_pre_handler(int virt_irq,
  333. void (*func)(unsigned int, void *, void *),
  334. void *arg1, void *arg2)
  335. {
  336. struct irq_handler_data *data = get_irq_chip_data(virt_irq);
  337. struct irq_chip *chip;
  338. data->pre_handler = func;
  339. data->pre_handler_arg1 = arg1;
  340. data->pre_handler_arg2 = arg2;
  341. chip = get_irq_chip(virt_irq);
  342. if (chip == &sun4u_irq_ack ||
  343. chip == &sun4v_irq_ack)
  344. return;
  345. chip = (chip == &sun4u_irq ?
  346. &sun4u_irq_ack : &sun4v_irq_ack);
  347. set_irq_chip(virt_irq, chip);
  348. }
  349. unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
  350. {
  351. struct ino_bucket *bucket;
  352. struct irq_handler_data *data;
  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. set_irq_chip(bucket->virt_irq, &sun4u_irq);
  360. }
  361. data = get_irq_chip_data(bucket->virt_irq);
  362. if (unlikely(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. set_irq_chip_data(bucket->virt_irq, 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. BUG_ON(tlb_type != hypervisor);
  381. sysino = sun4v_devino_to_sysino(devhandle, devino);
  382. bucket = &ivector_table[sysino];
  383. if (!bucket->virt_irq) {
  384. bucket->virt_irq = virt_irq_alloc(__irq(bucket));
  385. set_irq_chip(bucket->virt_irq, &sun4v_irq);
  386. }
  387. data = get_irq_chip_data(bucket->virt_irq);
  388. if (unlikely(data))
  389. goto out;
  390. data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
  391. if (unlikely(!data)) {
  392. prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
  393. prom_halt();
  394. }
  395. set_irq_chip_data(bucket->virt_irq, data);
  396. /* Catch accidental accesses to these things. IMAP/ICLR handling
  397. * is done by hypervisor calls on sun4v platforms, not by direct
  398. * register accesses.
  399. */
  400. data->imap = ~0UL;
  401. data->iclr = ~0UL;
  402. out:
  403. return bucket->virt_irq;
  404. }
  405. void ack_bad_irq(unsigned int virt_irq)
  406. {
  407. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  408. unsigned int ino = 0xdeadbeef;
  409. if (bucket)
  410. ino = bucket - &ivector_table[0];
  411. printk(KERN_CRIT "Unexpected IRQ from ino[%x] virt_irq[%u]\n",
  412. ino, virt_irq);
  413. }
  414. #ifndef CONFIG_SMP
  415. extern irqreturn_t timer_interrupt(int, void *);
  416. void timer_irq(int irq, struct pt_regs *regs)
  417. {
  418. unsigned long clr_mask = 1 << irq;
  419. unsigned long tick_mask = tick_ops->softint_mask;
  420. struct pt_regs *old_regs;
  421. if (get_softint() & tick_mask) {
  422. irq = 0;
  423. clr_mask = tick_mask;
  424. }
  425. clear_softint(clr_mask);
  426. old_regs = set_irq_regs(regs);
  427. irq_enter();
  428. kstat_this_cpu.irqs[0]++;
  429. timer_interrupt(irq, NULL);
  430. irq_exit();
  431. set_irq_regs(old_regs);
  432. }
  433. #endif
  434. void handler_irq(int irq, struct pt_regs *regs)
  435. {
  436. struct ino_bucket *bucket;
  437. struct pt_regs *old_regs;
  438. clear_softint(1 << irq);
  439. old_regs = set_irq_regs(regs);
  440. irq_enter();
  441. /* Sliiiick... */
  442. bucket = __bucket(xchg32(irq_work(smp_processor_id()), 0));
  443. while (bucket) {
  444. struct ino_bucket *next = __bucket(bucket->irq_chain);
  445. bucket->irq_chain = 0;
  446. __do_IRQ(bucket->virt_irq);
  447. bucket = next;
  448. }
  449. irq_exit();
  450. set_irq_regs(old_regs);
  451. }
  452. struct sun5_timer {
  453. u64 count0;
  454. u64 limit0;
  455. u64 count1;
  456. u64 limit1;
  457. };
  458. static struct sun5_timer *prom_timers;
  459. static u64 prom_limit0, prom_limit1;
  460. static void map_prom_timers(void)
  461. {
  462. struct device_node *dp;
  463. unsigned int *addr;
  464. /* PROM timer node hangs out in the top level of device siblings... */
  465. dp = of_find_node_by_path("/");
  466. dp = dp->child;
  467. while (dp) {
  468. if (!strcmp(dp->name, "counter-timer"))
  469. break;
  470. dp = dp->sibling;
  471. }
  472. /* Assume if node is not present, PROM uses different tick mechanism
  473. * which we should not care about.
  474. */
  475. if (!dp) {
  476. prom_timers = (struct sun5_timer *) 0;
  477. return;
  478. }
  479. /* If PROM is really using this, it must be mapped by him. */
  480. addr = of_get_property(dp, "address", NULL);
  481. if (!addr) {
  482. prom_printf("PROM does not have timer mapped, trying to continue.\n");
  483. prom_timers = (struct sun5_timer *) 0;
  484. return;
  485. }
  486. prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
  487. }
  488. static void kill_prom_timer(void)
  489. {
  490. if (!prom_timers)
  491. return;
  492. /* Save them away for later. */
  493. prom_limit0 = prom_timers->limit0;
  494. prom_limit1 = prom_timers->limit1;
  495. /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
  496. * We turn both off here just to be paranoid.
  497. */
  498. prom_timers->limit0 = 0;
  499. prom_timers->limit1 = 0;
  500. /* Wheee, eat the interrupt packet too... */
  501. __asm__ __volatile__(
  502. " mov 0x40, %%g2\n"
  503. " ldxa [%%g0] %0, %%g1\n"
  504. " ldxa [%%g2] %1, %%g1\n"
  505. " stxa %%g0, [%%g0] %0\n"
  506. " membar #Sync\n"
  507. : /* no outputs */
  508. : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
  509. : "g1", "g2");
  510. }
  511. void init_irqwork_curcpu(void)
  512. {
  513. int cpu = hard_smp_processor_id();
  514. trap_block[cpu].irq_worklist = 0;
  515. }
  516. static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type)
  517. {
  518. unsigned long num_entries = 128;
  519. unsigned long status;
  520. status = sun4v_cpu_qconf(type, paddr, num_entries);
  521. if (status != HV_EOK) {
  522. prom_printf("SUN4V: sun4v_cpu_qconf(%lu:%lx:%lu) failed, "
  523. "err %lu\n", type, paddr, num_entries, status);
  524. prom_halt();
  525. }
  526. }
  527. static void __cpuinit sun4v_register_mondo_queues(int this_cpu)
  528. {
  529. struct trap_per_cpu *tb = &trap_block[this_cpu];
  530. register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO);
  531. register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO);
  532. register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR);
  533. register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR);
  534. }
  535. static void __cpuinit alloc_one_mondo(unsigned long *pa_ptr, int use_bootmem)
  536. {
  537. void *page;
  538. if (use_bootmem)
  539. page = alloc_bootmem_low_pages(PAGE_SIZE);
  540. else
  541. page = (void *) get_zeroed_page(GFP_ATOMIC);
  542. if (!page) {
  543. prom_printf("SUN4V: Error, cannot allocate mondo queue.\n");
  544. prom_halt();
  545. }
  546. *pa_ptr = __pa(page);
  547. }
  548. static void __cpuinit alloc_one_kbuf(unsigned long *pa_ptr, int use_bootmem)
  549. {
  550. void *page;
  551. if (use_bootmem)
  552. page = alloc_bootmem_low_pages(PAGE_SIZE);
  553. else
  554. page = (void *) get_zeroed_page(GFP_ATOMIC);
  555. if (!page) {
  556. prom_printf("SUN4V: Error, cannot allocate kbuf page.\n");
  557. prom_halt();
  558. }
  559. *pa_ptr = __pa(page);
  560. }
  561. static void __cpuinit init_cpu_send_mondo_info(struct trap_per_cpu *tb, int use_bootmem)
  562. {
  563. #ifdef CONFIG_SMP
  564. void *page;
  565. BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
  566. if (use_bootmem)
  567. page = alloc_bootmem_low_pages(PAGE_SIZE);
  568. else
  569. page = (void *) get_zeroed_page(GFP_ATOMIC);
  570. if (!page) {
  571. prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
  572. prom_halt();
  573. }
  574. tb->cpu_mondo_block_pa = __pa(page);
  575. tb->cpu_list_pa = __pa(page + 64);
  576. #endif
  577. }
  578. /* Allocate and register the mondo and error queues for this cpu. */
  579. void __cpuinit sun4v_init_mondo_queues(int use_bootmem, int cpu, int alloc, int load)
  580. {
  581. struct trap_per_cpu *tb = &trap_block[cpu];
  582. if (alloc) {
  583. alloc_one_mondo(&tb->cpu_mondo_pa, use_bootmem);
  584. alloc_one_mondo(&tb->dev_mondo_pa, use_bootmem);
  585. alloc_one_mondo(&tb->resum_mondo_pa, use_bootmem);
  586. alloc_one_kbuf(&tb->resum_kernel_buf_pa, use_bootmem);
  587. alloc_one_mondo(&tb->nonresum_mondo_pa, use_bootmem);
  588. alloc_one_kbuf(&tb->nonresum_kernel_buf_pa, use_bootmem);
  589. init_cpu_send_mondo_info(tb, use_bootmem);
  590. }
  591. if (load) {
  592. if (cpu != hard_smp_processor_id()) {
  593. prom_printf("SUN4V: init mondo on cpu %d not %d\n",
  594. cpu, hard_smp_processor_id());
  595. prom_halt();
  596. }
  597. sun4v_register_mondo_queues(cpu);
  598. }
  599. }
  600. static struct irqaction timer_irq_action = {
  601. .name = "timer",
  602. };
  603. /* Only invoked on boot processor. */
  604. void __init init_IRQ(void)
  605. {
  606. map_prom_timers();
  607. kill_prom_timer();
  608. memset(&ivector_table[0], 0, sizeof(ivector_table));
  609. if (tlb_type == hypervisor)
  610. sun4v_init_mondo_queues(1, hard_smp_processor_id(), 1, 1);
  611. /* We need to clear any IRQ's pending in the soft interrupt
  612. * registers, a spurious one could be left around from the
  613. * PROM timer which we just disabled.
  614. */
  615. clear_softint(get_softint());
  616. /* Now that ivector table is initialized, it is safe
  617. * to receive IRQ vector traps. We will normally take
  618. * one or two right now, in case some device PROM used
  619. * to boot us wants to speak to us. We just ignore them.
  620. */
  621. __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
  622. "or %%g1, %0, %%g1\n\t"
  623. "wrpr %%g1, 0x0, %%pstate"
  624. : /* No outputs */
  625. : "i" (PSTATE_IE)
  626. : "g1");
  627. irq_desc[0].action = &timer_irq_action;
  628. }