gic.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*
  2. * linux/arch/arm/common/gic.c
  3. *
  4. * Copyright (C) 2002 ARM Limited, All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Interrupt architecture for the GIC:
  11. *
  12. * o There is one Interrupt Distributor, which receives interrupts
  13. * from system devices and sends them to the Interrupt Controllers.
  14. *
  15. * o There is one CPU Interface per CPU, which sends interrupts sent
  16. * by the Distributor, and interrupts generated locally, to the
  17. * associated CPU. The base address of the CPU interface is usually
  18. * aliased so that the same address points to different chips depending
  19. * on the CPU it is accessed from.
  20. *
  21. * Note that IRQs 0-31 are special - they are local to each CPU.
  22. * As such, the enable set/clear, pending set/clear and active bit
  23. * registers are banked per-cpu for these sources.
  24. */
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/err.h>
  28. #include <linux/module.h>
  29. #include <linux/list.h>
  30. #include <linux/smp.h>
  31. #include <linux/cpu_pm.h>
  32. #include <linux/cpumask.h>
  33. #include <linux/io.h>
  34. #include <linux/of.h>
  35. #include <linux/of_address.h>
  36. #include <linux/of_irq.h>
  37. #include <linux/irqdomain.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/percpu.h>
  40. #include <linux/slab.h>
  41. #include <asm/irq.h>
  42. #include <asm/mach/irq.h>
  43. #include <asm/hardware/gic.h>
  44. static DEFINE_RAW_SPINLOCK(irq_controller_lock);
  45. /* Address of GIC 0 CPU interface */
  46. void __iomem *gic_cpu_base_addr __read_mostly;
  47. /*
  48. * Supported arch specific GIC irq extension.
  49. * Default make them NULL.
  50. */
  51. struct irq_chip gic_arch_extn = {
  52. .irq_eoi = NULL,
  53. .irq_mask = NULL,
  54. .irq_unmask = NULL,
  55. .irq_retrigger = NULL,
  56. .irq_set_type = NULL,
  57. .irq_set_wake = NULL,
  58. };
  59. #ifndef MAX_GIC_NR
  60. #define MAX_GIC_NR 1
  61. #endif
  62. static struct gic_chip_data gic_data[MAX_GIC_NR] __read_mostly;
  63. static inline void __iomem *gic_dist_base(struct irq_data *d)
  64. {
  65. struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
  66. return gic_data->dist_base;
  67. }
  68. static inline void __iomem *gic_cpu_base(struct irq_data *d)
  69. {
  70. struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
  71. return gic_data->cpu_base;
  72. }
  73. static inline unsigned int gic_irq(struct irq_data *d)
  74. {
  75. return d->hwirq;
  76. }
  77. /*
  78. * Routines to acknowledge, disable and enable interrupts
  79. */
  80. static void gic_mask_irq(struct irq_data *d)
  81. {
  82. u32 mask = 1 << (gic_irq(d) % 32);
  83. raw_spin_lock(&irq_controller_lock);
  84. writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_CLEAR + (gic_irq(d) / 32) * 4);
  85. if (gic_arch_extn.irq_mask)
  86. gic_arch_extn.irq_mask(d);
  87. raw_spin_unlock(&irq_controller_lock);
  88. }
  89. static void gic_unmask_irq(struct irq_data *d)
  90. {
  91. u32 mask = 1 << (gic_irq(d) % 32);
  92. raw_spin_lock(&irq_controller_lock);
  93. if (gic_arch_extn.irq_unmask)
  94. gic_arch_extn.irq_unmask(d);
  95. writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4);
  96. raw_spin_unlock(&irq_controller_lock);
  97. }
  98. static void gic_eoi_irq(struct irq_data *d)
  99. {
  100. if (gic_arch_extn.irq_eoi) {
  101. raw_spin_lock(&irq_controller_lock);
  102. gic_arch_extn.irq_eoi(d);
  103. raw_spin_unlock(&irq_controller_lock);
  104. }
  105. writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI);
  106. }
  107. static int gic_set_type(struct irq_data *d, unsigned int type)
  108. {
  109. void __iomem *base = gic_dist_base(d);
  110. unsigned int gicirq = gic_irq(d);
  111. u32 enablemask = 1 << (gicirq % 32);
  112. u32 enableoff = (gicirq / 32) * 4;
  113. u32 confmask = 0x2 << ((gicirq % 16) * 2);
  114. u32 confoff = (gicirq / 16) * 4;
  115. bool enabled = false;
  116. u32 val;
  117. /* Interrupt configuration for SGIs can't be changed */
  118. if (gicirq < 16)
  119. return -EINVAL;
  120. if (type != IRQ_TYPE_LEVEL_HIGH && type != IRQ_TYPE_EDGE_RISING)
  121. return -EINVAL;
  122. raw_spin_lock(&irq_controller_lock);
  123. if (gic_arch_extn.irq_set_type)
  124. gic_arch_extn.irq_set_type(d, type);
  125. val = readl_relaxed(base + GIC_DIST_CONFIG + confoff);
  126. if (type == IRQ_TYPE_LEVEL_HIGH)
  127. val &= ~confmask;
  128. else if (type == IRQ_TYPE_EDGE_RISING)
  129. val |= confmask;
  130. /*
  131. * As recommended by the spec, disable the interrupt before changing
  132. * the configuration
  133. */
  134. if (readl_relaxed(base + GIC_DIST_ENABLE_SET + enableoff) & enablemask) {
  135. writel_relaxed(enablemask, base + GIC_DIST_ENABLE_CLEAR + enableoff);
  136. enabled = true;
  137. }
  138. writel_relaxed(val, base + GIC_DIST_CONFIG + confoff);
  139. if (enabled)
  140. writel_relaxed(enablemask, base + GIC_DIST_ENABLE_SET + enableoff);
  141. raw_spin_unlock(&irq_controller_lock);
  142. return 0;
  143. }
  144. static int gic_retrigger(struct irq_data *d)
  145. {
  146. if (gic_arch_extn.irq_retrigger)
  147. return gic_arch_extn.irq_retrigger(d);
  148. return -ENXIO;
  149. }
  150. #ifdef CONFIG_SMP
  151. static int gic_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
  152. bool force)
  153. {
  154. void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + (gic_irq(d) & ~3);
  155. unsigned int shift = (gic_irq(d) % 4) * 8;
  156. unsigned int cpu = cpumask_any_and(mask_val, cpu_online_mask);
  157. u32 val, mask, bit;
  158. if (cpu >= 8 || cpu >= nr_cpu_ids)
  159. return -EINVAL;
  160. mask = 0xff << shift;
  161. bit = 1 << (cpu_logical_map(cpu) + shift);
  162. raw_spin_lock(&irq_controller_lock);
  163. val = readl_relaxed(reg) & ~mask;
  164. writel_relaxed(val | bit, reg);
  165. raw_spin_unlock(&irq_controller_lock);
  166. return IRQ_SET_MASK_OK;
  167. }
  168. #endif
  169. #ifdef CONFIG_PM
  170. static int gic_set_wake(struct irq_data *d, unsigned int on)
  171. {
  172. int ret = -ENXIO;
  173. if (gic_arch_extn.irq_set_wake)
  174. ret = gic_arch_extn.irq_set_wake(d, on);
  175. return ret;
  176. }
  177. #else
  178. #define gic_set_wake NULL
  179. #endif
  180. static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
  181. {
  182. struct gic_chip_data *chip_data = irq_get_handler_data(irq);
  183. struct irq_chip *chip = irq_get_chip(irq);
  184. unsigned int cascade_irq, gic_irq;
  185. unsigned long status;
  186. chained_irq_enter(chip, desc);
  187. raw_spin_lock(&irq_controller_lock);
  188. status = readl_relaxed(chip_data->cpu_base + GIC_CPU_INTACK);
  189. raw_spin_unlock(&irq_controller_lock);
  190. gic_irq = (status & 0x3ff);
  191. if (gic_irq == 1023)
  192. goto out;
  193. cascade_irq = irq_domain_to_irq(&chip_data->domain, gic_irq);
  194. if (unlikely(gic_irq < 32 || gic_irq > 1020 || cascade_irq >= NR_IRQS))
  195. do_bad_IRQ(cascade_irq, desc);
  196. else
  197. generic_handle_irq(cascade_irq);
  198. out:
  199. chained_irq_exit(chip, desc);
  200. }
  201. static struct irq_chip gic_chip = {
  202. .name = "GIC",
  203. .irq_mask = gic_mask_irq,
  204. .irq_unmask = gic_unmask_irq,
  205. .irq_eoi = gic_eoi_irq,
  206. .irq_set_type = gic_set_type,
  207. .irq_retrigger = gic_retrigger,
  208. #ifdef CONFIG_SMP
  209. .irq_set_affinity = gic_set_affinity,
  210. #endif
  211. .irq_set_wake = gic_set_wake,
  212. };
  213. void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq)
  214. {
  215. if (gic_nr >= MAX_GIC_NR)
  216. BUG();
  217. if (irq_set_handler_data(irq, &gic_data[gic_nr]) != 0)
  218. BUG();
  219. irq_set_chained_handler(irq, gic_handle_cascade_irq);
  220. }
  221. static void __init gic_dist_init(struct gic_chip_data *gic)
  222. {
  223. unsigned int i, irq;
  224. u32 cpumask;
  225. unsigned int gic_irqs = gic->gic_irqs;
  226. struct irq_domain *domain = &gic->domain;
  227. void __iomem *base = gic->dist_base;
  228. u32 cpu = 0;
  229. #ifdef CONFIG_SMP
  230. cpu = cpu_logical_map(smp_processor_id());
  231. #endif
  232. cpumask = 1 << cpu;
  233. cpumask |= cpumask << 8;
  234. cpumask |= cpumask << 16;
  235. writel_relaxed(0, base + GIC_DIST_CTRL);
  236. /*
  237. * Set all global interrupts to be level triggered, active low.
  238. */
  239. for (i = 32; i < gic_irqs; i += 16)
  240. writel_relaxed(0, base + GIC_DIST_CONFIG + i * 4 / 16);
  241. /*
  242. * Set all global interrupts to this CPU only.
  243. */
  244. for (i = 32; i < gic_irqs; i += 4)
  245. writel_relaxed(cpumask, base + GIC_DIST_TARGET + i * 4 / 4);
  246. /*
  247. * Set priority on all global interrupts.
  248. */
  249. for (i = 32; i < gic_irqs; i += 4)
  250. writel_relaxed(0xa0a0a0a0, base + GIC_DIST_PRI + i * 4 / 4);
  251. /*
  252. * Disable all interrupts. Leave the PPI and SGIs alone
  253. * as these enables are banked registers.
  254. */
  255. for (i = 32; i < gic_irqs; i += 32)
  256. writel_relaxed(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4 / 32);
  257. /*
  258. * Setup the Linux IRQ subsystem.
  259. */
  260. irq_domain_for_each_irq(domain, i, irq) {
  261. if (i < 32) {
  262. irq_set_percpu_devid(irq);
  263. irq_set_chip_and_handler(irq, &gic_chip,
  264. handle_percpu_devid_irq);
  265. set_irq_flags(irq, IRQF_VALID | IRQF_NOAUTOEN);
  266. } else {
  267. irq_set_chip_and_handler(irq, &gic_chip,
  268. handle_fasteoi_irq);
  269. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  270. }
  271. irq_set_chip_data(irq, gic);
  272. }
  273. writel_relaxed(1, base + GIC_DIST_CTRL);
  274. }
  275. static void __cpuinit gic_cpu_init(struct gic_chip_data *gic)
  276. {
  277. void __iomem *dist_base = gic->dist_base;
  278. void __iomem *base = gic->cpu_base;
  279. int i;
  280. /*
  281. * Deal with the banked PPI and SGI interrupts - disable all
  282. * PPI interrupts, ensure all SGI interrupts are enabled.
  283. */
  284. writel_relaxed(0xffff0000, dist_base + GIC_DIST_ENABLE_CLEAR);
  285. writel_relaxed(0x0000ffff, dist_base + GIC_DIST_ENABLE_SET);
  286. /*
  287. * Set priority on PPI and SGI interrupts
  288. */
  289. for (i = 0; i < 32; i += 4)
  290. writel_relaxed(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4 / 4);
  291. writel_relaxed(0xf0, base + GIC_CPU_PRIMASK);
  292. writel_relaxed(1, base + GIC_CPU_CTRL);
  293. }
  294. #ifdef CONFIG_CPU_PM
  295. /*
  296. * Saves the GIC distributor registers during suspend or idle. Must be called
  297. * with interrupts disabled but before powering down the GIC. After calling
  298. * this function, no interrupts will be delivered by the GIC, and another
  299. * platform-specific wakeup source must be enabled.
  300. */
  301. static void gic_dist_save(unsigned int gic_nr)
  302. {
  303. unsigned int gic_irqs;
  304. void __iomem *dist_base;
  305. int i;
  306. if (gic_nr >= MAX_GIC_NR)
  307. BUG();
  308. gic_irqs = gic_data[gic_nr].gic_irqs;
  309. dist_base = gic_data[gic_nr].dist_base;
  310. if (!dist_base)
  311. return;
  312. for (i = 0; i < DIV_ROUND_UP(gic_irqs, 16); i++)
  313. gic_data[gic_nr].saved_spi_conf[i] =
  314. readl_relaxed(dist_base + GIC_DIST_CONFIG + i * 4);
  315. for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++)
  316. gic_data[gic_nr].saved_spi_target[i] =
  317. readl_relaxed(dist_base + GIC_DIST_TARGET + i * 4);
  318. for (i = 0; i < DIV_ROUND_UP(gic_irqs, 32); i++)
  319. gic_data[gic_nr].saved_spi_enable[i] =
  320. readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4);
  321. }
  322. /*
  323. * Restores the GIC distributor registers during resume or when coming out of
  324. * idle. Must be called before enabling interrupts. If a level interrupt
  325. * that occured while the GIC was suspended is still present, it will be
  326. * handled normally, but any edge interrupts that occured will not be seen by
  327. * the GIC and need to be handled by the platform-specific wakeup source.
  328. */
  329. static void gic_dist_restore(unsigned int gic_nr)
  330. {
  331. unsigned int gic_irqs;
  332. unsigned int i;
  333. void __iomem *dist_base;
  334. if (gic_nr >= MAX_GIC_NR)
  335. BUG();
  336. gic_irqs = gic_data[gic_nr].gic_irqs;
  337. dist_base = gic_data[gic_nr].dist_base;
  338. if (!dist_base)
  339. return;
  340. writel_relaxed(0, dist_base + GIC_DIST_CTRL);
  341. for (i = 0; i < DIV_ROUND_UP(gic_irqs, 16); i++)
  342. writel_relaxed(gic_data[gic_nr].saved_spi_conf[i],
  343. dist_base + GIC_DIST_CONFIG + i * 4);
  344. for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++)
  345. writel_relaxed(0xa0a0a0a0,
  346. dist_base + GIC_DIST_PRI + i * 4);
  347. for (i = 0; i < DIV_ROUND_UP(gic_irqs, 4); i++)
  348. writel_relaxed(gic_data[gic_nr].saved_spi_target[i],
  349. dist_base + GIC_DIST_TARGET + i * 4);
  350. for (i = 0; i < DIV_ROUND_UP(gic_irqs, 32); i++)
  351. writel_relaxed(gic_data[gic_nr].saved_spi_enable[i],
  352. dist_base + GIC_DIST_ENABLE_SET + i * 4);
  353. writel_relaxed(1, dist_base + GIC_DIST_CTRL);
  354. }
  355. static void gic_cpu_save(unsigned int gic_nr)
  356. {
  357. int i;
  358. u32 *ptr;
  359. void __iomem *dist_base;
  360. void __iomem *cpu_base;
  361. if (gic_nr >= MAX_GIC_NR)
  362. BUG();
  363. dist_base = gic_data[gic_nr].dist_base;
  364. cpu_base = gic_data[gic_nr].cpu_base;
  365. if (!dist_base || !cpu_base)
  366. return;
  367. ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_enable);
  368. for (i = 0; i < DIV_ROUND_UP(32, 32); i++)
  369. ptr[i] = readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4);
  370. ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_conf);
  371. for (i = 0; i < DIV_ROUND_UP(32, 16); i++)
  372. ptr[i] = readl_relaxed(dist_base + GIC_DIST_CONFIG + i * 4);
  373. }
  374. static void gic_cpu_restore(unsigned int gic_nr)
  375. {
  376. int i;
  377. u32 *ptr;
  378. void __iomem *dist_base;
  379. void __iomem *cpu_base;
  380. if (gic_nr >= MAX_GIC_NR)
  381. BUG();
  382. dist_base = gic_data[gic_nr].dist_base;
  383. cpu_base = gic_data[gic_nr].cpu_base;
  384. if (!dist_base || !cpu_base)
  385. return;
  386. ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_enable);
  387. for (i = 0; i < DIV_ROUND_UP(32, 32); i++)
  388. writel_relaxed(ptr[i], dist_base + GIC_DIST_ENABLE_SET + i * 4);
  389. ptr = __this_cpu_ptr(gic_data[gic_nr].saved_ppi_conf);
  390. for (i = 0; i < DIV_ROUND_UP(32, 16); i++)
  391. writel_relaxed(ptr[i], dist_base + GIC_DIST_CONFIG + i * 4);
  392. for (i = 0; i < DIV_ROUND_UP(32, 4); i++)
  393. writel_relaxed(0xa0a0a0a0, dist_base + GIC_DIST_PRI + i * 4);
  394. writel_relaxed(0xf0, cpu_base + GIC_CPU_PRIMASK);
  395. writel_relaxed(1, cpu_base + GIC_CPU_CTRL);
  396. }
  397. static int gic_notifier(struct notifier_block *self, unsigned long cmd, void *v)
  398. {
  399. int i;
  400. for (i = 0; i < MAX_GIC_NR; i++) {
  401. switch (cmd) {
  402. case CPU_PM_ENTER:
  403. gic_cpu_save(i);
  404. break;
  405. case CPU_PM_ENTER_FAILED:
  406. case CPU_PM_EXIT:
  407. gic_cpu_restore(i);
  408. break;
  409. case CPU_CLUSTER_PM_ENTER:
  410. gic_dist_save(i);
  411. break;
  412. case CPU_CLUSTER_PM_ENTER_FAILED:
  413. case CPU_CLUSTER_PM_EXIT:
  414. gic_dist_restore(i);
  415. break;
  416. }
  417. }
  418. return NOTIFY_OK;
  419. }
  420. static struct notifier_block gic_notifier_block = {
  421. .notifier_call = gic_notifier,
  422. };
  423. static void __init gic_pm_init(struct gic_chip_data *gic)
  424. {
  425. gic->saved_ppi_enable = __alloc_percpu(DIV_ROUND_UP(32, 32) * 4,
  426. sizeof(u32));
  427. BUG_ON(!gic->saved_ppi_enable);
  428. gic->saved_ppi_conf = __alloc_percpu(DIV_ROUND_UP(32, 16) * 4,
  429. sizeof(u32));
  430. BUG_ON(!gic->saved_ppi_conf);
  431. if (gic == &gic_data[0])
  432. cpu_pm_register_notifier(&gic_notifier_block);
  433. }
  434. #else
  435. static void __init gic_pm_init(struct gic_chip_data *gic)
  436. {
  437. }
  438. #endif
  439. #ifdef CONFIG_OF
  440. static int gic_irq_domain_dt_translate(struct irq_domain *d,
  441. struct device_node *controller,
  442. const u32 *intspec, unsigned int intsize,
  443. unsigned long *out_hwirq, unsigned int *out_type)
  444. {
  445. if (d->of_node != controller)
  446. return -EINVAL;
  447. if (intsize < 3)
  448. return -EINVAL;
  449. /* Get the interrupt number and add 16 to skip over SGIs */
  450. *out_hwirq = intspec[1] + 16;
  451. /* For SPIs, we need to add 16 more to get the GIC irq ID number */
  452. if (!intspec[0])
  453. *out_hwirq += 16;
  454. *out_type = intspec[2] & IRQ_TYPE_SENSE_MASK;
  455. return 0;
  456. }
  457. #endif
  458. const struct irq_domain_ops gic_irq_domain_ops = {
  459. #ifdef CONFIG_OF
  460. .dt_translate = gic_irq_domain_dt_translate,
  461. #endif
  462. };
  463. void __init gic_init(unsigned int gic_nr, int irq_start,
  464. void __iomem *dist_base, void __iomem *cpu_base)
  465. {
  466. struct gic_chip_data *gic;
  467. struct irq_domain *domain;
  468. int gic_irqs;
  469. BUG_ON(gic_nr >= MAX_GIC_NR);
  470. gic = &gic_data[gic_nr];
  471. domain = &gic->domain;
  472. gic->dist_base = dist_base;
  473. gic->cpu_base = cpu_base;
  474. /*
  475. * For primary GICs, skip over SGIs.
  476. * For secondary GICs, skip over PPIs, too.
  477. */
  478. domain->hwirq_base = 32;
  479. if (gic_nr == 0) {
  480. gic_cpu_base_addr = cpu_base;
  481. if ((irq_start & 31) > 0) {
  482. domain->hwirq_base = 16;
  483. if (irq_start != -1)
  484. irq_start = (irq_start & ~31) + 16;
  485. }
  486. }
  487. /*
  488. * Find out how many interrupts are supported.
  489. * The GIC only supports up to 1020 interrupt sources.
  490. */
  491. gic_irqs = readl_relaxed(dist_base + GIC_DIST_CTR) & 0x1f;
  492. gic_irqs = (gic_irqs + 1) * 32;
  493. if (gic_irqs > 1020)
  494. gic_irqs = 1020;
  495. gic->gic_irqs = gic_irqs;
  496. domain->nr_irq = gic_irqs - domain->hwirq_base;
  497. domain->irq_base = irq_alloc_descs(irq_start, 16, domain->nr_irq,
  498. numa_node_id());
  499. if (IS_ERR_VALUE(domain->irq_base)) {
  500. WARN(1, "Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
  501. irq_start);
  502. domain->irq_base = irq_start;
  503. }
  504. domain->priv = gic;
  505. domain->ops = &gic_irq_domain_ops;
  506. irq_domain_add(domain);
  507. gic_chip.flags |= gic_arch_extn.flags;
  508. gic_dist_init(gic);
  509. gic_cpu_init(gic);
  510. gic_pm_init(gic);
  511. }
  512. void __cpuinit gic_secondary_init(unsigned int gic_nr)
  513. {
  514. BUG_ON(gic_nr >= MAX_GIC_NR);
  515. gic_cpu_init(&gic_data[gic_nr]);
  516. }
  517. #ifdef CONFIG_SMP
  518. void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
  519. {
  520. int cpu;
  521. unsigned long map = 0;
  522. /* Convert our logical CPU mask into a physical one. */
  523. for_each_cpu(cpu, mask)
  524. map |= 1 << cpu_logical_map(cpu);
  525. /*
  526. * Ensure that stores to Normal memory are visible to the
  527. * other CPUs before issuing the IPI.
  528. */
  529. dsb();
  530. /* this always happens on GIC0 */
  531. writel_relaxed(map << 16 | irq, gic_data[0].dist_base + GIC_DIST_SOFTINT);
  532. }
  533. #endif
  534. #ifdef CONFIG_OF
  535. static int gic_cnt __initdata = 0;
  536. int __init gic_of_init(struct device_node *node, struct device_node *parent)
  537. {
  538. void __iomem *cpu_base;
  539. void __iomem *dist_base;
  540. int irq;
  541. struct irq_domain *domain = &gic_data[gic_cnt].domain;
  542. if (WARN_ON(!node))
  543. return -ENODEV;
  544. dist_base = of_iomap(node, 0);
  545. WARN(!dist_base, "unable to map gic dist registers\n");
  546. cpu_base = of_iomap(node, 1);
  547. WARN(!cpu_base, "unable to map gic cpu registers\n");
  548. domain->of_node = of_node_get(node);
  549. gic_init(gic_cnt, -1, dist_base, cpu_base);
  550. if (parent) {
  551. irq = irq_of_parse_and_map(node, 0);
  552. gic_cascade_irq(gic_cnt, irq);
  553. }
  554. gic_cnt++;
  555. return 0;
  556. }
  557. #endif