irq-armada-370-xp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*
  2. * Marvell Armada 370 and Armada XP SoC IRQ handling
  3. *
  4. * Copyright (C) 2012 Marvell
  5. *
  6. * Lior Amsalem <alior@marvell.com>
  7. * Gregory CLEMENT <gregory.clement@free-electrons.com>
  8. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  9. * Ben Dooks <ben.dooks@codethink.co.uk>
  10. *
  11. * This file is licensed under the terms of the GNU General Public
  12. * License version 2. This program is licensed "as is" without any
  13. * warranty of any kind, whether express or implied.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/irq.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/irqchip.h>
  21. #include <linux/irqchip/chained_irq.h>
  22. #include <linux/cpu.h>
  23. #include <linux/io.h>
  24. #include <linux/of_address.h>
  25. #include <linux/of_irq.h>
  26. #include <linux/of_pci.h>
  27. #include <linux/irqdomain.h>
  28. #include <linux/slab.h>
  29. #include <linux/syscore_ops.h>
  30. #include <linux/msi.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/exception.h>
  33. #include <asm/smp_plat.h>
  34. #include <asm/mach/irq.h>
  35. /* Interrupt Controller Registers Map */
  36. #define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48)
  37. #define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C)
  38. #define ARMADA_370_XP_INT_FABRIC_MASK_OFFS (0x54)
  39. #define ARMADA_370_XP_INT_CAUSE_PERF(cpu) (1 << cpu)
  40. #define ARMADA_370_XP_INT_CONTROL (0x00)
  41. #define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30)
  42. #define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34)
  43. #define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4)
  44. #define ARMADA_370_XP_INT_SOURCE_CPU_MASK 0xF
  45. #define ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid) ((BIT(0) | BIT(8)) << cpuid)
  46. #define ARMADA_370_XP_CPU_INTACK_OFFS (0x44)
  47. #define ARMADA_375_PPI_CAUSE (0x10)
  48. #define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x4)
  49. #define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0xc)
  50. #define ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS (0x8)
  51. #define ARMADA_370_XP_MAX_PER_CPU_IRQS (28)
  52. #define IPI_DOORBELL_START (0)
  53. #define IPI_DOORBELL_END (8)
  54. #define IPI_DOORBELL_MASK 0xFF
  55. #define PCI_MSI_DOORBELL_START (16)
  56. #define PCI_MSI_DOORBELL_NR (16)
  57. #define PCI_MSI_DOORBELL_END (32)
  58. #define PCI_MSI_DOORBELL_MASK 0xFFFF0000
  59. static void __iomem *per_cpu_int_base;
  60. static void __iomem *main_int_base;
  61. static struct irq_domain *armada_370_xp_mpic_domain;
  62. static u32 doorbell_mask_reg;
  63. static int parent_irq;
  64. #ifdef CONFIG_PCI_MSI
  65. static struct irq_domain *armada_370_xp_msi_domain;
  66. static DECLARE_BITMAP(msi_used, PCI_MSI_DOORBELL_NR);
  67. static DEFINE_MUTEX(msi_used_lock);
  68. static phys_addr_t msi_doorbell_addr;
  69. #endif
  70. static inline bool is_percpu_irq(irq_hw_number_t irq)
  71. {
  72. if (irq <= ARMADA_370_XP_MAX_PER_CPU_IRQS)
  73. return true;
  74. return false;
  75. }
  76. /*
  77. * In SMP mode:
  78. * For shared global interrupts, mask/unmask global enable bit
  79. * For CPU interrupts, mask/unmask the calling CPU's bit
  80. */
  81. static void armada_370_xp_irq_mask(struct irq_data *d)
  82. {
  83. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  84. if (!is_percpu_irq(hwirq))
  85. writel(hwirq, main_int_base +
  86. ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS);
  87. else
  88. writel(hwirq, per_cpu_int_base +
  89. ARMADA_370_XP_INT_SET_MASK_OFFS);
  90. }
  91. static void armada_370_xp_irq_unmask(struct irq_data *d)
  92. {
  93. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  94. if (!is_percpu_irq(hwirq))
  95. writel(hwirq, main_int_base +
  96. ARMADA_370_XP_INT_SET_ENABLE_OFFS);
  97. else
  98. writel(hwirq, per_cpu_int_base +
  99. ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
  100. }
  101. #ifdef CONFIG_PCI_MSI
  102. static int armada_370_xp_alloc_msi(void)
  103. {
  104. int hwirq;
  105. mutex_lock(&msi_used_lock);
  106. hwirq = find_first_zero_bit(&msi_used, PCI_MSI_DOORBELL_NR);
  107. if (hwirq >= PCI_MSI_DOORBELL_NR)
  108. hwirq = -ENOSPC;
  109. else
  110. set_bit(hwirq, msi_used);
  111. mutex_unlock(&msi_used_lock);
  112. return hwirq;
  113. }
  114. static void armada_370_xp_free_msi(int hwirq)
  115. {
  116. mutex_lock(&msi_used_lock);
  117. if (!test_bit(hwirq, msi_used))
  118. pr_err("trying to free unused MSI#%d\n", hwirq);
  119. else
  120. clear_bit(hwirq, msi_used);
  121. mutex_unlock(&msi_used_lock);
  122. }
  123. static int armada_370_xp_setup_msi_irq(struct msi_controller *chip,
  124. struct pci_dev *pdev,
  125. struct msi_desc *desc)
  126. {
  127. struct msi_msg msg;
  128. int virq, hwirq;
  129. /* We support MSI, but not MSI-X */
  130. if (desc->msi_attrib.is_msix)
  131. return -EINVAL;
  132. hwirq = armada_370_xp_alloc_msi();
  133. if (hwirq < 0)
  134. return hwirq;
  135. virq = irq_create_mapping(armada_370_xp_msi_domain, hwirq);
  136. if (!virq) {
  137. armada_370_xp_free_msi(hwirq);
  138. return -EINVAL;
  139. }
  140. irq_set_msi_desc(virq, desc);
  141. msg.address_lo = msi_doorbell_addr;
  142. msg.address_hi = 0;
  143. msg.data = 0xf00 | (hwirq + 16);
  144. pci_write_msi_msg(virq, &msg);
  145. return 0;
  146. }
  147. static void armada_370_xp_teardown_msi_irq(struct msi_controller *chip,
  148. unsigned int irq)
  149. {
  150. struct irq_data *d = irq_get_irq_data(irq);
  151. unsigned long hwirq = d->hwirq;
  152. irq_dispose_mapping(irq);
  153. armada_370_xp_free_msi(hwirq);
  154. }
  155. static struct irq_chip armada_370_xp_msi_irq_chip = {
  156. .name = "armada_370_xp_msi_irq",
  157. .irq_enable = pci_msi_unmask_irq,
  158. .irq_disable = pci_msi_mask_irq,
  159. .irq_mask = pci_msi_mask_irq,
  160. .irq_unmask = pci_msi_unmask_irq,
  161. };
  162. static int armada_370_xp_msi_map(struct irq_domain *domain, unsigned int virq,
  163. irq_hw_number_t hw)
  164. {
  165. irq_set_chip_and_handler(virq, &armada_370_xp_msi_irq_chip,
  166. handle_simple_irq);
  167. return 0;
  168. }
  169. static const struct irq_domain_ops armada_370_xp_msi_irq_ops = {
  170. .map = armada_370_xp_msi_map,
  171. };
  172. static int armada_370_xp_msi_init(struct device_node *node,
  173. phys_addr_t main_int_phys_base)
  174. {
  175. struct msi_controller *msi_chip;
  176. u32 reg;
  177. int ret;
  178. msi_doorbell_addr = main_int_phys_base +
  179. ARMADA_370_XP_SW_TRIG_INT_OFFS;
  180. msi_chip = kzalloc(sizeof(*msi_chip), GFP_KERNEL);
  181. if (!msi_chip)
  182. return -ENOMEM;
  183. msi_chip->setup_irq = armada_370_xp_setup_msi_irq;
  184. msi_chip->teardown_irq = armada_370_xp_teardown_msi_irq;
  185. msi_chip->of_node = node;
  186. armada_370_xp_msi_domain =
  187. irq_domain_add_linear(NULL, PCI_MSI_DOORBELL_NR,
  188. &armada_370_xp_msi_irq_ops,
  189. NULL);
  190. if (!armada_370_xp_msi_domain) {
  191. kfree(msi_chip);
  192. return -ENOMEM;
  193. }
  194. ret = of_pci_msi_chip_add(msi_chip);
  195. if (ret < 0) {
  196. irq_domain_remove(armada_370_xp_msi_domain);
  197. kfree(msi_chip);
  198. return ret;
  199. }
  200. reg = readl(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS)
  201. | PCI_MSI_DOORBELL_MASK;
  202. writel(reg, per_cpu_int_base +
  203. ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
  204. /* Unmask IPI interrupt */
  205. writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
  206. return 0;
  207. }
  208. #else
  209. static inline int armada_370_xp_msi_init(struct device_node *node,
  210. phys_addr_t main_int_phys_base)
  211. {
  212. return 0;
  213. }
  214. #endif
  215. #ifdef CONFIG_SMP
  216. static DEFINE_RAW_SPINLOCK(irq_controller_lock);
  217. static int armada_xp_set_affinity(struct irq_data *d,
  218. const struct cpumask *mask_val, bool force)
  219. {
  220. irq_hw_number_t hwirq = irqd_to_hwirq(d);
  221. unsigned long reg, mask;
  222. int cpu;
  223. /* Select a single core from the affinity mask which is online */
  224. cpu = cpumask_any_and(mask_val, cpu_online_mask);
  225. mask = 1UL << cpu_logical_map(cpu);
  226. raw_spin_lock(&irq_controller_lock);
  227. reg = readl(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
  228. reg = (reg & (~ARMADA_370_XP_INT_SOURCE_CPU_MASK)) | mask;
  229. writel(reg, main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
  230. raw_spin_unlock(&irq_controller_lock);
  231. return IRQ_SET_MASK_OK;
  232. }
  233. #endif
  234. static struct irq_chip armada_370_xp_irq_chip = {
  235. .name = "armada_370_xp_irq",
  236. .irq_mask = armada_370_xp_irq_mask,
  237. .irq_mask_ack = armada_370_xp_irq_mask,
  238. .irq_unmask = armada_370_xp_irq_unmask,
  239. #ifdef CONFIG_SMP
  240. .irq_set_affinity = armada_xp_set_affinity,
  241. #endif
  242. .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND,
  243. };
  244. static int armada_370_xp_mpic_irq_map(struct irq_domain *h,
  245. unsigned int virq, irq_hw_number_t hw)
  246. {
  247. armada_370_xp_irq_mask(irq_get_irq_data(virq));
  248. if (!is_percpu_irq(hw))
  249. writel(hw, per_cpu_int_base +
  250. ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
  251. else
  252. writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS);
  253. irq_set_status_flags(virq, IRQ_LEVEL);
  254. if (is_percpu_irq(hw)) {
  255. irq_set_percpu_devid(virq);
  256. irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
  257. handle_percpu_devid_irq);
  258. } else {
  259. irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
  260. handle_level_irq);
  261. }
  262. irq_set_probe(virq);
  263. irq_clear_status_flags(virq, IRQ_NOAUTOEN);
  264. return 0;
  265. }
  266. static void armada_xp_mpic_smp_cpu_init(void)
  267. {
  268. u32 control;
  269. int nr_irqs, i;
  270. control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
  271. nr_irqs = (control >> 2) & 0x3ff;
  272. for (i = 0; i < nr_irqs; i++)
  273. writel(i, per_cpu_int_base + ARMADA_370_XP_INT_SET_MASK_OFFS);
  274. /* Clear pending IPIs */
  275. writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
  276. /* Enable first 8 IPIs */
  277. writel(IPI_DOORBELL_MASK, per_cpu_int_base +
  278. ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
  279. /* Unmask IPI interrupt */
  280. writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
  281. }
  282. static void armada_xp_mpic_perf_init(void)
  283. {
  284. unsigned long cpuid = cpu_logical_map(smp_processor_id());
  285. /* Enable Performance Counter Overflow interrupts */
  286. writel(ARMADA_370_XP_INT_CAUSE_PERF(cpuid),
  287. per_cpu_int_base + ARMADA_370_XP_INT_FABRIC_MASK_OFFS);
  288. }
  289. #ifdef CONFIG_SMP
  290. static void armada_mpic_send_doorbell(const struct cpumask *mask,
  291. unsigned int irq)
  292. {
  293. int cpu;
  294. unsigned long map = 0;
  295. /* Convert our logical CPU mask into a physical one. */
  296. for_each_cpu(cpu, mask)
  297. map |= 1 << cpu_logical_map(cpu);
  298. /*
  299. * Ensure that stores to Normal memory are visible to the
  300. * other CPUs before issuing the IPI.
  301. */
  302. dsb();
  303. /* submit softirq */
  304. writel((map << 8) | irq, main_int_base +
  305. ARMADA_370_XP_SW_TRIG_INT_OFFS);
  306. }
  307. static int armada_xp_mpic_secondary_init(struct notifier_block *nfb,
  308. unsigned long action, void *hcpu)
  309. {
  310. if (action == CPU_STARTING || action == CPU_STARTING_FROZEN) {
  311. armada_xp_mpic_perf_init();
  312. armada_xp_mpic_smp_cpu_init();
  313. }
  314. return NOTIFY_OK;
  315. }
  316. static struct notifier_block armada_370_xp_mpic_cpu_notifier = {
  317. .notifier_call = armada_xp_mpic_secondary_init,
  318. .priority = 100,
  319. };
  320. static int mpic_cascaded_secondary_init(struct notifier_block *nfb,
  321. unsigned long action, void *hcpu)
  322. {
  323. if (action == CPU_STARTING || action == CPU_STARTING_FROZEN) {
  324. armada_xp_mpic_perf_init();
  325. enable_percpu_irq(parent_irq, IRQ_TYPE_NONE);
  326. }
  327. return NOTIFY_OK;
  328. }
  329. static struct notifier_block mpic_cascaded_cpu_notifier = {
  330. .notifier_call = mpic_cascaded_secondary_init,
  331. .priority = 100,
  332. };
  333. #endif /* CONFIG_SMP */
  334. static const struct irq_domain_ops armada_370_xp_mpic_irq_ops = {
  335. .map = armada_370_xp_mpic_irq_map,
  336. .xlate = irq_domain_xlate_onecell,
  337. };
  338. #ifdef CONFIG_PCI_MSI
  339. static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained)
  340. {
  341. u32 msimask, msinr;
  342. msimask = readl_relaxed(per_cpu_int_base +
  343. ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
  344. & PCI_MSI_DOORBELL_MASK;
  345. writel(~msimask, per_cpu_int_base +
  346. ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
  347. for (msinr = PCI_MSI_DOORBELL_START;
  348. msinr < PCI_MSI_DOORBELL_END; msinr++) {
  349. int irq;
  350. if (!(msimask & BIT(msinr)))
  351. continue;
  352. if (is_chained) {
  353. irq = irq_find_mapping(armada_370_xp_msi_domain,
  354. msinr - 16);
  355. generic_handle_irq(irq);
  356. } else {
  357. irq = msinr - 16;
  358. handle_domain_irq(armada_370_xp_msi_domain,
  359. irq, regs);
  360. }
  361. }
  362. }
  363. #else
  364. static void armada_370_xp_handle_msi_irq(struct pt_regs *r, bool b) {}
  365. #endif
  366. static void armada_370_xp_mpic_handle_cascade_irq(struct irq_desc *desc)
  367. {
  368. struct irq_chip *chip = irq_desc_get_chip(desc);
  369. unsigned long irqmap, irqn, irqsrc, cpuid;
  370. unsigned int cascade_irq;
  371. chained_irq_enter(chip, desc);
  372. irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE);
  373. cpuid = cpu_logical_map(smp_processor_id());
  374. for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) {
  375. irqsrc = readl_relaxed(main_int_base +
  376. ARMADA_370_XP_INT_SOURCE_CTL(irqn));
  377. /* Check if the interrupt is not masked on current CPU.
  378. * Test IRQ (0-1) and FIQ (8-9) mask bits.
  379. */
  380. if (!(irqsrc & ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid)))
  381. continue;
  382. if (irqn == 1) {
  383. armada_370_xp_handle_msi_irq(NULL, true);
  384. continue;
  385. }
  386. cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn);
  387. generic_handle_irq(cascade_irq);
  388. }
  389. chained_irq_exit(chip, desc);
  390. }
  391. static void __exception_irq_entry
  392. armada_370_xp_handle_irq(struct pt_regs *regs)
  393. {
  394. u32 irqstat, irqnr;
  395. do {
  396. irqstat = readl_relaxed(per_cpu_int_base +
  397. ARMADA_370_XP_CPU_INTACK_OFFS);
  398. irqnr = irqstat & 0x3FF;
  399. if (irqnr > 1022)
  400. break;
  401. if (irqnr > 1) {
  402. handle_domain_irq(armada_370_xp_mpic_domain,
  403. irqnr, regs);
  404. continue;
  405. }
  406. /* MSI handling */
  407. if (irqnr == 1)
  408. armada_370_xp_handle_msi_irq(regs, false);
  409. #ifdef CONFIG_SMP
  410. /* IPI Handling */
  411. if (irqnr == 0) {
  412. u32 ipimask, ipinr;
  413. ipimask = readl_relaxed(per_cpu_int_base +
  414. ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
  415. & IPI_DOORBELL_MASK;
  416. writel(~ipimask, per_cpu_int_base +
  417. ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
  418. /* Handle all pending doorbells */
  419. for (ipinr = IPI_DOORBELL_START;
  420. ipinr < IPI_DOORBELL_END; ipinr++) {
  421. if (ipimask & (0x1 << ipinr))
  422. handle_IPI(ipinr, regs);
  423. }
  424. continue;
  425. }
  426. #endif
  427. } while (1);
  428. }
  429. static int armada_370_xp_mpic_suspend(void)
  430. {
  431. doorbell_mask_reg = readl(per_cpu_int_base +
  432. ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
  433. return 0;
  434. }
  435. static void armada_370_xp_mpic_resume(void)
  436. {
  437. int nirqs;
  438. irq_hw_number_t irq;
  439. /* Re-enable interrupts */
  440. nirqs = (readl(main_int_base + ARMADA_370_XP_INT_CONTROL) >> 2) & 0x3ff;
  441. for (irq = 0; irq < nirqs; irq++) {
  442. struct irq_data *data;
  443. int virq;
  444. virq = irq_linear_revmap(armada_370_xp_mpic_domain, irq);
  445. if (virq == 0)
  446. continue;
  447. if (!is_percpu_irq(irq))
  448. writel(irq, per_cpu_int_base +
  449. ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
  450. else
  451. writel(irq, main_int_base +
  452. ARMADA_370_XP_INT_SET_ENABLE_OFFS);
  453. data = irq_get_irq_data(virq);
  454. if (!irqd_irq_disabled(data))
  455. armada_370_xp_irq_unmask(data);
  456. }
  457. /* Reconfigure doorbells for IPIs and MSIs */
  458. writel(doorbell_mask_reg,
  459. per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
  460. if (doorbell_mask_reg & IPI_DOORBELL_MASK)
  461. writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
  462. if (doorbell_mask_reg & PCI_MSI_DOORBELL_MASK)
  463. writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
  464. }
  465. struct syscore_ops armada_370_xp_mpic_syscore_ops = {
  466. .suspend = armada_370_xp_mpic_suspend,
  467. .resume = armada_370_xp_mpic_resume,
  468. };
  469. static int __init armada_370_xp_mpic_of_init(struct device_node *node,
  470. struct device_node *parent)
  471. {
  472. struct resource main_int_res, per_cpu_int_res;
  473. int nr_irqs, i;
  474. u32 control;
  475. BUG_ON(of_address_to_resource(node, 0, &main_int_res));
  476. BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res));
  477. BUG_ON(!request_mem_region(main_int_res.start,
  478. resource_size(&main_int_res),
  479. node->full_name));
  480. BUG_ON(!request_mem_region(per_cpu_int_res.start,
  481. resource_size(&per_cpu_int_res),
  482. node->full_name));
  483. main_int_base = ioremap(main_int_res.start,
  484. resource_size(&main_int_res));
  485. BUG_ON(!main_int_base);
  486. per_cpu_int_base = ioremap(per_cpu_int_res.start,
  487. resource_size(&per_cpu_int_res));
  488. BUG_ON(!per_cpu_int_base);
  489. control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
  490. nr_irqs = (control >> 2) & 0x3ff;
  491. for (i = 0; i < nr_irqs; i++)
  492. writel(i, main_int_base + ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS);
  493. armada_370_xp_mpic_domain =
  494. irq_domain_add_linear(node, nr_irqs,
  495. &armada_370_xp_mpic_irq_ops, NULL);
  496. BUG_ON(!armada_370_xp_mpic_domain);
  497. /* Setup for the boot CPU */
  498. armada_xp_mpic_perf_init();
  499. armada_xp_mpic_smp_cpu_init();
  500. armada_370_xp_msi_init(node, main_int_res.start);
  501. parent_irq = irq_of_parse_and_map(node, 0);
  502. if (parent_irq <= 0) {
  503. irq_set_default_host(armada_370_xp_mpic_domain);
  504. set_handle_irq(armada_370_xp_handle_irq);
  505. #ifdef CONFIG_SMP
  506. set_smp_cross_call(armada_mpic_send_doorbell);
  507. register_cpu_notifier(&armada_370_xp_mpic_cpu_notifier);
  508. #endif
  509. } else {
  510. #ifdef CONFIG_SMP
  511. register_cpu_notifier(&mpic_cascaded_cpu_notifier);
  512. #endif
  513. irq_set_chained_handler(parent_irq,
  514. armada_370_xp_mpic_handle_cascade_irq);
  515. }
  516. register_syscore_ops(&armada_370_xp_mpic_syscore_ops);
  517. return 0;
  518. }
  519. IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init);