irq.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  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 hw_interrupt_type sun4u_irq = {
  311. .typename = "sun4u",
  312. .enable = sun4u_irq_enable,
  313. .disable = sun4u_irq_disable,
  314. .end = sun4u_irq_end,
  315. };
  316. static struct hw_interrupt_type sun4u_irq_ack = {
  317. .typename = "sun4u+ack",
  318. .enable = sun4u_irq_enable,
  319. .disable = sun4u_irq_disable,
  320. .ack = run_pre_handler,
  321. .end = sun4u_irq_end,
  322. };
  323. static struct hw_interrupt_type sun4v_irq = {
  324. .typename = "sun4v",
  325. .enable = sun4v_irq_enable,
  326. .disable = sun4v_irq_disable,
  327. .end = sun4v_irq_end,
  328. };
  329. static struct hw_interrupt_type sun4v_irq_ack = {
  330. .typename = "sun4v+ack",
  331. .enable = sun4v_irq_enable,
  332. .disable = sun4v_irq_disable,
  333. .ack = run_pre_handler,
  334. .end = sun4v_irq_end,
  335. };
  336. void irq_install_pre_handler(int virt_irq,
  337. void (*func)(unsigned int, void *, void *),
  338. void *arg1, void *arg2)
  339. {
  340. irq_desc_t *desc = irq_desc + virt_irq;
  341. struct irq_handler_data *data = desc->handler_data;
  342. data->pre_handler = func;
  343. data->pre_handler_arg1 = arg1;
  344. data->pre_handler_arg2 = arg2;
  345. 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 hw_resend_irq(struct hw_interrupt_type *handler, unsigned int virt_irq)
  410. {
  411. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  412. unsigned long pstate;
  413. unsigned int *ent;
  414. __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
  415. __asm__ __volatile__("wrpr %0, %1, %%pstate"
  416. : : "r" (pstate), "i" (PSTATE_IE));
  417. ent = irq_work(smp_processor_id());
  418. bucket->irq_chain = *ent;
  419. *ent = __irq(bucket);
  420. set_softint(1 << PIL_DEVICE_IRQ);
  421. __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
  422. }
  423. void ack_bad_irq(unsigned int virt_irq)
  424. {
  425. struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
  426. unsigned int ino = 0xdeadbeef;
  427. if (bucket)
  428. ino = bucket - &ivector_table[0];
  429. printk(KERN_CRIT "Unexpected IRQ from ino[%x] virt_irq[%u]\n",
  430. ino, virt_irq);
  431. }
  432. #ifndef CONFIG_SMP
  433. extern irqreturn_t timer_interrupt(int, void *, struct pt_regs *);
  434. void timer_irq(int irq, struct pt_regs *regs)
  435. {
  436. unsigned long clr_mask = 1 << irq;
  437. unsigned long tick_mask = tick_ops->softint_mask;
  438. if (get_softint() & tick_mask) {
  439. irq = 0;
  440. clr_mask = tick_mask;
  441. }
  442. clear_softint(clr_mask);
  443. irq_enter();
  444. kstat_this_cpu.irqs[0]++;
  445. timer_interrupt(irq, NULL, regs);
  446. irq_exit();
  447. }
  448. #endif
  449. void handler_irq(int irq, struct pt_regs *regs)
  450. {
  451. struct ino_bucket *bucket;
  452. clear_softint(1 << irq);
  453. irq_enter();
  454. /* Sliiiick... */
  455. bucket = __bucket(xchg32(irq_work(smp_processor_id()), 0));
  456. while (bucket) {
  457. struct ino_bucket *next = __bucket(bucket->irq_chain);
  458. bucket->irq_chain = 0;
  459. __do_IRQ(bucket->virt_irq, regs);
  460. bucket = next;
  461. }
  462. irq_exit();
  463. }
  464. struct sun5_timer {
  465. u64 count0;
  466. u64 limit0;
  467. u64 count1;
  468. u64 limit1;
  469. };
  470. static struct sun5_timer *prom_timers;
  471. static u64 prom_limit0, prom_limit1;
  472. static void map_prom_timers(void)
  473. {
  474. struct device_node *dp;
  475. unsigned int *addr;
  476. /* PROM timer node hangs out in the top level of device siblings... */
  477. dp = of_find_node_by_path("/");
  478. dp = dp->child;
  479. while (dp) {
  480. if (!strcmp(dp->name, "counter-timer"))
  481. break;
  482. dp = dp->sibling;
  483. }
  484. /* Assume if node is not present, PROM uses different tick mechanism
  485. * which we should not care about.
  486. */
  487. if (!dp) {
  488. prom_timers = (struct sun5_timer *) 0;
  489. return;
  490. }
  491. /* If PROM is really using this, it must be mapped by him. */
  492. addr = of_get_property(dp, "address", NULL);
  493. if (!addr) {
  494. prom_printf("PROM does not have timer mapped, trying to continue.\n");
  495. prom_timers = (struct sun5_timer *) 0;
  496. return;
  497. }
  498. prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
  499. }
  500. static void kill_prom_timer(void)
  501. {
  502. if (!prom_timers)
  503. return;
  504. /* Save them away for later. */
  505. prom_limit0 = prom_timers->limit0;
  506. prom_limit1 = prom_timers->limit1;
  507. /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
  508. * We turn both off here just to be paranoid.
  509. */
  510. prom_timers->limit0 = 0;
  511. prom_timers->limit1 = 0;
  512. /* Wheee, eat the interrupt packet too... */
  513. __asm__ __volatile__(
  514. " mov 0x40, %%g2\n"
  515. " ldxa [%%g0] %0, %%g1\n"
  516. " ldxa [%%g2] %1, %%g1\n"
  517. " stxa %%g0, [%%g0] %0\n"
  518. " membar #Sync\n"
  519. : /* no outputs */
  520. : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
  521. : "g1", "g2");
  522. }
  523. void init_irqwork_curcpu(void)
  524. {
  525. int cpu = hard_smp_processor_id();
  526. trap_block[cpu].irq_worklist = 0;
  527. }
  528. static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type)
  529. {
  530. unsigned long num_entries = 128;
  531. unsigned long status;
  532. status = sun4v_cpu_qconf(type, paddr, num_entries);
  533. if (status != HV_EOK) {
  534. prom_printf("SUN4V: sun4v_cpu_qconf(%lu:%lx:%lu) failed, "
  535. "err %lu\n", type, paddr, num_entries, status);
  536. prom_halt();
  537. }
  538. }
  539. static void __cpuinit sun4v_register_mondo_queues(int this_cpu)
  540. {
  541. struct trap_per_cpu *tb = &trap_block[this_cpu];
  542. register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO);
  543. register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO);
  544. register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR);
  545. register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR);
  546. }
  547. static void __cpuinit alloc_one_mondo(unsigned long *pa_ptr, int use_bootmem)
  548. {
  549. void *page;
  550. if (use_bootmem)
  551. page = alloc_bootmem_low_pages(PAGE_SIZE);
  552. else
  553. page = (void *) get_zeroed_page(GFP_ATOMIC);
  554. if (!page) {
  555. prom_printf("SUN4V: Error, cannot allocate mondo queue.\n");
  556. prom_halt();
  557. }
  558. *pa_ptr = __pa(page);
  559. }
  560. static void __cpuinit alloc_one_kbuf(unsigned long *pa_ptr, int use_bootmem)
  561. {
  562. void *page;
  563. if (use_bootmem)
  564. page = alloc_bootmem_low_pages(PAGE_SIZE);
  565. else
  566. page = (void *) get_zeroed_page(GFP_ATOMIC);
  567. if (!page) {
  568. prom_printf("SUN4V: Error, cannot allocate kbuf page.\n");
  569. prom_halt();
  570. }
  571. *pa_ptr = __pa(page);
  572. }
  573. static void __cpuinit init_cpu_send_mondo_info(struct trap_per_cpu *tb, int use_bootmem)
  574. {
  575. #ifdef CONFIG_SMP
  576. void *page;
  577. BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
  578. if (use_bootmem)
  579. page = alloc_bootmem_low_pages(PAGE_SIZE);
  580. else
  581. page = (void *) get_zeroed_page(GFP_ATOMIC);
  582. if (!page) {
  583. prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
  584. prom_halt();
  585. }
  586. tb->cpu_mondo_block_pa = __pa(page);
  587. tb->cpu_list_pa = __pa(page + 64);
  588. #endif
  589. }
  590. /* Allocate and register the mondo and error queues for this cpu. */
  591. void __cpuinit sun4v_init_mondo_queues(int use_bootmem, int cpu, int alloc, int load)
  592. {
  593. struct trap_per_cpu *tb = &trap_block[cpu];
  594. if (alloc) {
  595. alloc_one_mondo(&tb->cpu_mondo_pa, use_bootmem);
  596. alloc_one_mondo(&tb->dev_mondo_pa, use_bootmem);
  597. alloc_one_mondo(&tb->resum_mondo_pa, use_bootmem);
  598. alloc_one_kbuf(&tb->resum_kernel_buf_pa, use_bootmem);
  599. alloc_one_mondo(&tb->nonresum_mondo_pa, use_bootmem);
  600. alloc_one_kbuf(&tb->nonresum_kernel_buf_pa, use_bootmem);
  601. init_cpu_send_mondo_info(tb, use_bootmem);
  602. }
  603. if (load) {
  604. if (cpu != hard_smp_processor_id()) {
  605. prom_printf("SUN4V: init mondo on cpu %d not %d\n",
  606. cpu, hard_smp_processor_id());
  607. prom_halt();
  608. }
  609. sun4v_register_mondo_queues(cpu);
  610. }
  611. }
  612. static struct irqaction timer_irq_action = {
  613. .name = "timer",
  614. };
  615. /* Only invoked on boot processor. */
  616. void __init init_IRQ(void)
  617. {
  618. map_prom_timers();
  619. kill_prom_timer();
  620. memset(&ivector_table[0], 0, sizeof(ivector_table));
  621. if (tlb_type == hypervisor)
  622. sun4v_init_mondo_queues(1, hard_smp_processor_id(), 1, 1);
  623. /* We need to clear any IRQ's pending in the soft interrupt
  624. * registers, a spurious one could be left around from the
  625. * PROM timer which we just disabled.
  626. */
  627. clear_softint(get_softint());
  628. /* Now that ivector table is initialized, it is safe
  629. * to receive IRQ vector traps. We will normally take
  630. * one or two right now, in case some device PROM used
  631. * to boot us wants to speak to us. We just ignore them.
  632. */
  633. __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
  634. "or %%g1, %0, %%g1\n\t"
  635. "wrpr %%g1, 0x0, %%pstate"
  636. : /* No outputs */
  637. : "i" (PSTATE_IE)
  638. : "g1");
  639. irq_desc[0].action = &timer_irq_action;
  640. }