1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2021 Western Digital Corporation or its affiliates.
4 * Copyright (C) 2022 Ventana Micro Systems Inc.
7 #define pr_fmt(fmt) "riscv-imsic: " fmt
9 #include <linux/bitmap.h>
10 #include <linux/interrupt.h>
11 #include <linux/irq.h>
12 #include <linux/module.h>
14 #include <linux/of_address.h>
15 #include <linux/of_irq.h>
16 #include <linux/seq_file.h>
17 #include <linux/spinlock.h>
18 #include <linux/smp.h>
19 #include <asm/hwcap.h>
21 #include "irq-riscv-imsic-state.h"
23 #define IMSIC_DISABLE_EIDELIVERY 0
24 #define IMSIC_ENABLE_EIDELIVERY 1
25 #define IMSIC_DISABLE_EITHRESHOLD 1
26 #define IMSIC_ENABLE_EITHRESHOLD 0
28 static inline void imsic_csr_write(unsigned long reg, unsigned long val)
30 csr_write(CSR_ISELECT, reg);
31 csr_write(CSR_IREG, val);
34 static inline unsigned long imsic_csr_read(unsigned long reg)
36 csr_write(CSR_ISELECT, reg);
37 return csr_read(CSR_IREG);
40 static inline unsigned long imsic_csr_read_clear(unsigned long reg, unsigned long val)
42 csr_write(CSR_ISELECT, reg);
43 return csr_read_clear(CSR_IREG, val);
46 static inline void imsic_csr_set(unsigned long reg, unsigned long val)
48 csr_write(CSR_ISELECT, reg);
49 csr_set(CSR_IREG, val);
52 static inline void imsic_csr_clear(unsigned long reg, unsigned long val)
54 csr_write(CSR_ISELECT, reg);
55 csr_clear(CSR_IREG, val);
58 struct imsic_priv *imsic;
60 const struct imsic_global_config *imsic_get_global_config(void)
62 return imsic ? &imsic->global : NULL;
64 EXPORT_SYMBOL_GPL(imsic_get_global_config);
66 static bool __imsic_eix_read_clear(unsigned long id, bool pend)
68 unsigned long isel, imask;
70 isel = id / BITS_PER_LONG;
71 isel *= BITS_PER_LONG / IMSIC_EIPx_BITS;
72 isel += pend ? IMSIC_EIP0 : IMSIC_EIE0;
73 imask = BIT(id & (__riscv_xlen - 1));
75 return !!(imsic_csr_read_clear(isel, imask) & imask);
78 static inline bool __imsic_id_read_clear_enabled(unsigned long id)
80 return __imsic_eix_read_clear(id, false);
83 static inline bool __imsic_id_read_clear_pending(unsigned long id)
85 return __imsic_eix_read_clear(id, true);
88 void __imsic_eix_update(unsigned long base_id, unsigned long num_id, bool pend, bool val)
90 unsigned long id = base_id, last_id = base_id + num_id;
91 unsigned long i, isel, ireg;
93 while (id < last_id) {
94 isel = id / BITS_PER_LONG;
95 isel *= BITS_PER_LONG / IMSIC_EIPx_BITS;
96 isel += pend ? IMSIC_EIP0 : IMSIC_EIE0;
99 * Prepare the ID mask to be programmed in the
100 * IMSIC EIEx and EIPx registers. These registers
101 * are XLEN-wide and we must not touch IDs which
102 * are < base_id and >= (base_id + num_id).
105 for (i = id & (__riscv_xlen - 1); id < last_id && i < __riscv_xlen; i++) {
111 * The IMSIC EIEx and EIPx registers are indirectly
112 * accessed via using ISELECT and IREG CSRs so we
113 * need to access these CSRs without getting preempted.
115 * All existing users of this function call this
116 * function with local IRQs disabled so we don't
117 * need to do anything special here.
120 imsic_csr_set(isel, ireg);
122 imsic_csr_clear(isel, ireg);
126 static void __imsic_local_sync(struct imsic_local_priv *lpriv)
128 struct imsic_local_config *mlocal;
129 struct imsic_vector *vec, *mvec;
132 lockdep_assert_held(&lpriv->lock);
134 for_each_set_bit(i, lpriv->dirty_bitmap, imsic->global.nr_ids + 1) {
135 if (!i || i == IMSIC_IPI_ID)
137 vec = &lpriv->vectors[i];
139 if (READ_ONCE(vec->enable))
140 __imsic_id_set_enable(i);
142 __imsic_id_clear_enable(i);
145 * If the ID was being moved to a new ID on some other CPU
146 * then we can get a MSI during the movement so check the
147 * ID pending bit and re-trigger the new ID on other CPU
150 mvec = READ_ONCE(vec->move);
151 WRITE_ONCE(vec->move, NULL);
152 if (mvec && mvec != vec) {
153 if (__imsic_id_read_clear_pending(i)) {
154 mlocal = per_cpu_ptr(imsic->global.local, mvec->cpu);
155 writel_relaxed(mvec->local_id, mlocal->msi_va);
158 imsic_vector_free(&lpriv->vectors[i]);
162 bitmap_clear(lpriv->dirty_bitmap, i, 1);
166 void imsic_local_sync_all(void)
168 struct imsic_local_priv *lpriv = this_cpu_ptr(imsic->lpriv);
171 raw_spin_lock_irqsave(&lpriv->lock, flags);
172 bitmap_fill(lpriv->dirty_bitmap, imsic->global.nr_ids + 1);
173 __imsic_local_sync(lpriv);
174 raw_spin_unlock_irqrestore(&lpriv->lock, flags);
177 void imsic_local_delivery(bool enable)
180 imsic_csr_write(IMSIC_EITHRESHOLD, IMSIC_ENABLE_EITHRESHOLD);
181 imsic_csr_write(IMSIC_EIDELIVERY, IMSIC_ENABLE_EIDELIVERY);
185 imsic_csr_write(IMSIC_EIDELIVERY, IMSIC_DISABLE_EIDELIVERY);
186 imsic_csr_write(IMSIC_EITHRESHOLD, IMSIC_DISABLE_EITHRESHOLD);
190 static void imsic_local_timer_callback(struct timer_list *timer)
192 struct imsic_local_priv *lpriv = this_cpu_ptr(imsic->lpriv);
195 raw_spin_lock_irqsave(&lpriv->lock, flags);
196 __imsic_local_sync(lpriv);
197 raw_spin_unlock_irqrestore(&lpriv->lock, flags);
200 static void __imsic_remote_sync(struct imsic_local_priv *lpriv, unsigned int cpu)
202 lockdep_assert_held(&lpriv->lock);
205 * The spinlock acquire/release semantics ensure that changes
206 * to vector enable, vector move and dirty bitmap are visible
211 * We schedule a timer on the target CPU if the target CPU is not
212 * same as the current CPU. An offline CPU will unconditionally
213 * synchronize IDs through imsic_starting_cpu() when the
216 if (cpu_online(cpu)) {
217 if (cpu == smp_processor_id()) {
218 __imsic_local_sync(lpriv);
222 if (!timer_pending(&lpriv->timer)) {
223 lpriv->timer.expires = jiffies + 1;
224 add_timer_on(&lpriv->timer, cpu);
229 static void __imsic_remote_sync(struct imsic_local_priv *lpriv, unsigned int cpu)
231 lockdep_assert_held(&lpriv->lock);
232 __imsic_local_sync(lpriv);
236 void imsic_vector_mask(struct imsic_vector *vec)
238 struct imsic_local_priv *lpriv;
240 lpriv = per_cpu_ptr(imsic->lpriv, vec->cpu);
241 if (WARN_ON_ONCE(&lpriv->vectors[vec->local_id] != vec))
245 * This function is called through Linux irq subsystem with
246 * irqs disabled so no need to save/restore irq flags.
249 raw_spin_lock(&lpriv->lock);
251 WRITE_ONCE(vec->enable, false);
252 bitmap_set(lpriv->dirty_bitmap, vec->local_id, 1);
253 __imsic_remote_sync(lpriv, vec->cpu);
255 raw_spin_unlock(&lpriv->lock);
258 void imsic_vector_unmask(struct imsic_vector *vec)
260 struct imsic_local_priv *lpriv;
262 lpriv = per_cpu_ptr(imsic->lpriv, vec->cpu);
263 if (WARN_ON_ONCE(&lpriv->vectors[vec->local_id] != vec))
267 * This function is called through Linux irq subsystem with
268 * irqs disabled so no need to save/restore irq flags.
271 raw_spin_lock(&lpriv->lock);
273 WRITE_ONCE(vec->enable, true);
274 bitmap_set(lpriv->dirty_bitmap, vec->local_id, 1);
275 __imsic_remote_sync(lpriv, vec->cpu);
277 raw_spin_unlock(&lpriv->lock);
280 static bool imsic_vector_move_update(struct imsic_local_priv *lpriv, struct imsic_vector *vec,
281 bool new_enable, struct imsic_vector *new_move)
286 raw_spin_lock_irqsave(&lpriv->lock, flags);
288 /* Update enable and move details */
289 enabled = READ_ONCE(vec->enable);
290 WRITE_ONCE(vec->enable, new_enable);
291 WRITE_ONCE(vec->move, new_move);
293 /* Mark the vector as dirty and synchronize */
294 bitmap_set(lpriv->dirty_bitmap, vec->local_id, 1);
295 __imsic_remote_sync(lpriv, vec->cpu);
297 raw_spin_unlock_irqrestore(&lpriv->lock, flags);
302 void imsic_vector_move(struct imsic_vector *old_vec, struct imsic_vector *new_vec)
304 struct imsic_local_priv *old_lpriv, *new_lpriv;
307 if (WARN_ON_ONCE(old_vec->cpu == new_vec->cpu))
310 old_lpriv = per_cpu_ptr(imsic->lpriv, old_vec->cpu);
311 if (WARN_ON_ONCE(&old_lpriv->vectors[old_vec->local_id] != old_vec))
314 new_lpriv = per_cpu_ptr(imsic->lpriv, new_vec->cpu);
315 if (WARN_ON_ONCE(&new_lpriv->vectors[new_vec->local_id] != new_vec))
319 * Move and re-trigger the new vector based on the pending
320 * state of the old vector because we might get a device
321 * interrupt on the old vector while device was being moved
324 enabled = imsic_vector_move_update(old_lpriv, old_vec, false, new_vec);
325 imsic_vector_move_update(new_lpriv, new_vec, enabled, new_vec);
328 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
329 void imsic_vector_debug_show(struct seq_file *m, struct imsic_vector *vec, int ind)
331 struct imsic_local_priv *lpriv;
332 struct imsic_vector *mvec;
335 lpriv = per_cpu_ptr(imsic->lpriv, vec->cpu);
336 if (WARN_ON_ONCE(&lpriv->vectors[vec->local_id] != vec))
339 is_enabled = imsic_vector_isenabled(vec);
340 mvec = imsic_vector_get_move(vec);
342 seq_printf(m, "%*starget_cpu : %5u\n", ind, "", vec->cpu);
343 seq_printf(m, "%*starget_local_id : %5u\n", ind, "", vec->local_id);
344 seq_printf(m, "%*sis_reserved : %5u\n", ind, "",
345 (vec->local_id <= IMSIC_IPI_ID) ? 1 : 0);
346 seq_printf(m, "%*sis_enabled : %5u\n", ind, "", is_enabled ? 1 : 0);
347 seq_printf(m, "%*sis_move_pending : %5u\n", ind, "", mvec ? 1 : 0);
349 seq_printf(m, "%*smove_cpu : %5u\n", ind, "", mvec->cpu);
350 seq_printf(m, "%*smove_local_id : %5u\n", ind, "", mvec->local_id);
354 void imsic_vector_debug_show_summary(struct seq_file *m, int ind)
356 irq_matrix_debug_show(m, imsic->matrix, ind);
360 struct imsic_vector *imsic_vector_from_local_id(unsigned int cpu, unsigned int local_id)
362 struct imsic_local_priv *lpriv = per_cpu_ptr(imsic->lpriv, cpu);
364 if (!lpriv || imsic->global.nr_ids < local_id)
367 return &lpriv->vectors[local_id];
370 struct imsic_vector *imsic_vector_alloc(unsigned int hwirq, const struct cpumask *mask)
372 struct imsic_vector *vec = NULL;
373 struct imsic_local_priv *lpriv;
378 raw_spin_lock_irqsave(&imsic->matrix_lock, flags);
379 local_id = irq_matrix_alloc(imsic->matrix, mask, false, &cpu);
380 raw_spin_unlock_irqrestore(&imsic->matrix_lock, flags);
384 lpriv = per_cpu_ptr(imsic->lpriv, cpu);
385 vec = &lpriv->vectors[local_id];
393 void imsic_vector_free(struct imsic_vector *vec)
397 raw_spin_lock_irqsave(&imsic->matrix_lock, flags);
398 vec->hwirq = UINT_MAX;
399 irq_matrix_free(imsic->matrix, vec->cpu, vec->local_id, false);
400 raw_spin_unlock_irqrestore(&imsic->matrix_lock, flags);
403 static void __init imsic_local_cleanup(void)
405 struct imsic_local_priv *lpriv;
408 for_each_possible_cpu(cpu) {
409 lpriv = per_cpu_ptr(imsic->lpriv, cpu);
411 bitmap_free(lpriv->dirty_bitmap);
412 kfree(lpriv->vectors);
415 free_percpu(imsic->lpriv);
418 static int __init imsic_local_init(void)
420 struct imsic_global_config *global = &imsic->global;
421 struct imsic_local_priv *lpriv;
422 struct imsic_vector *vec;
425 /* Allocate per-CPU private state */
426 imsic->lpriv = alloc_percpu(typeof(*imsic->lpriv));
430 /* Setup per-CPU private state */
431 for_each_possible_cpu(cpu) {
432 lpriv = per_cpu_ptr(imsic->lpriv, cpu);
434 raw_spin_lock_init(&lpriv->lock);
436 /* Allocate dirty bitmap */
437 lpriv->dirty_bitmap = bitmap_zalloc(global->nr_ids + 1, GFP_KERNEL);
438 if (!lpriv->dirty_bitmap)
439 goto fail_local_cleanup;
442 /* Setup lazy timer for synchronization */
443 timer_setup(&lpriv->timer, imsic_local_timer_callback, TIMER_PINNED);
446 /* Allocate vector array */
447 lpriv->vectors = kcalloc(global->nr_ids + 1, sizeof(*lpriv->vectors),
450 goto fail_local_cleanup;
452 /* Setup vector array */
453 for (i = 0; i <= global->nr_ids; i++) {
454 vec = &lpriv->vectors[i];
457 vec->hwirq = UINT_MAX;
464 imsic_local_cleanup();
468 void imsic_state_online(void)
472 raw_spin_lock_irqsave(&imsic->matrix_lock, flags);
473 irq_matrix_online(imsic->matrix);
474 raw_spin_unlock_irqrestore(&imsic->matrix_lock, flags);
477 void imsic_state_offline(void)
481 raw_spin_lock_irqsave(&imsic->matrix_lock, flags);
482 irq_matrix_offline(imsic->matrix);
483 raw_spin_unlock_irqrestore(&imsic->matrix_lock, flags);
486 struct imsic_local_priv *lpriv = this_cpu_ptr(imsic->lpriv);
488 raw_spin_lock_irqsave(&lpriv->lock, flags);
489 WARN_ON_ONCE(try_to_del_timer_sync(&lpriv->timer) < 0);
490 raw_spin_unlock_irqrestore(&lpriv->lock, flags);
494 static int __init imsic_matrix_init(void)
496 struct imsic_global_config *global = &imsic->global;
498 raw_spin_lock_init(&imsic->matrix_lock);
499 imsic->matrix = irq_alloc_matrix(global->nr_ids + 1,
500 0, global->nr_ids + 1);
504 /* Reserve ID#0 because it is special and never implemented */
505 irq_matrix_assign_system(imsic->matrix, 0, false);
507 /* Reserve IPI ID because it is special and used internally */
508 irq_matrix_assign_system(imsic->matrix, IMSIC_IPI_ID, false);
513 static int __init imsic_get_parent_hartid(struct fwnode_handle *fwnode,
514 u32 index, unsigned long *hartid)
516 struct of_phandle_args parent;
520 * Currently, only OF fwnode is supported so extend this
521 * function for ACPI support.
523 if (!is_of_node(fwnode))
526 rc = of_irq_parse_one(to_of_node(fwnode), index, &parent);
531 * Skip interrupts other than external interrupts for
532 * current privilege level.
534 if (parent.args[0] != RV_IRQ_EXT)
537 return riscv_of_parent_hartid(parent.np, hartid);
540 static int __init imsic_get_mmio_resource(struct fwnode_handle *fwnode,
541 u32 index, struct resource *res)
544 * Currently, only OF fwnode is supported so extend this
545 * function for ACPI support.
547 if (!is_of_node(fwnode))
550 return of_address_to_resource(to_of_node(fwnode), index, res);
553 static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode,
554 struct imsic_global_config *global,
558 unsigned long hartid;
564 * Currently, only OF fwnode is supported so extend this
565 * function for ACPI support.
567 if (!is_of_node(fwnode))
573 /* Find number of parent interrupts */
574 while (!imsic_get_parent_hartid(fwnode, *nr_parent_irqs, &hartid))
576 if (!*nr_parent_irqs) {
577 pr_err("%pfwP: no parent irqs available\n", fwnode);
581 /* Find number of guest index bits in MSI address */
582 rc = of_property_read_u32(to_of_node(fwnode), "riscv,guest-index-bits",
583 &global->guest_index_bits);
585 global->guest_index_bits = 0;
587 /* Find number of HART index bits */
588 rc = of_property_read_u32(to_of_node(fwnode), "riscv,hart-index-bits",
589 &global->hart_index_bits);
591 /* Assume default value */
592 global->hart_index_bits = __fls(*nr_parent_irqs);
593 if (BIT(global->hart_index_bits) < *nr_parent_irqs)
594 global->hart_index_bits++;
597 /* Find number of group index bits */
598 rc = of_property_read_u32(to_of_node(fwnode), "riscv,group-index-bits",
599 &global->group_index_bits);
601 global->group_index_bits = 0;
604 * Find first bit position of group index.
605 * If not specified assumed the default APLIC-IMSIC configuration.
607 rc = of_property_read_u32(to_of_node(fwnode), "riscv,group-index-shift",
608 &global->group_index_shift);
610 global->group_index_shift = IMSIC_MMIO_PAGE_SHIFT * 2;
612 /* Find number of interrupt identities */
613 rc = of_property_read_u32(to_of_node(fwnode), "riscv,num-ids",
616 pr_err("%pfwP: number of interrupt identities not found\n", fwnode);
620 /* Find number of guest interrupt identities */
621 rc = of_property_read_u32(to_of_node(fwnode), "riscv,num-guest-ids",
622 &global->nr_guest_ids);
624 global->nr_guest_ids = global->nr_ids;
626 /* Sanity check guest index bits */
627 i = BITS_PER_LONG - IMSIC_MMIO_PAGE_SHIFT;
628 if (i < global->guest_index_bits) {
629 pr_err("%pfwP: guest index bits too big\n", fwnode);
633 /* Sanity check HART index bits */
634 i = BITS_PER_LONG - IMSIC_MMIO_PAGE_SHIFT - global->guest_index_bits;
635 if (i < global->hart_index_bits) {
636 pr_err("%pfwP: HART index bits too big\n", fwnode);
640 /* Sanity check group index bits */
641 i = BITS_PER_LONG - IMSIC_MMIO_PAGE_SHIFT -
642 global->guest_index_bits - global->hart_index_bits;
643 if (i < global->group_index_bits) {
644 pr_err("%pfwP: group index bits too big\n", fwnode);
648 /* Sanity check group index shift */
649 i = global->group_index_bits + global->group_index_shift - 1;
650 if (i >= BITS_PER_LONG) {
651 pr_err("%pfwP: group index shift too big\n", fwnode);
655 /* Sanity check number of interrupt identities */
656 if (global->nr_ids < IMSIC_MIN_ID ||
657 global->nr_ids >= IMSIC_MAX_ID ||
658 (global->nr_ids & IMSIC_MIN_ID) != IMSIC_MIN_ID) {
659 pr_err("%pfwP: invalid number of interrupt identities\n", fwnode);
663 /* Sanity check number of guest interrupt identities */
664 if (global->nr_guest_ids < IMSIC_MIN_ID ||
665 global->nr_guest_ids >= IMSIC_MAX_ID ||
666 (global->nr_guest_ids & IMSIC_MIN_ID) != IMSIC_MIN_ID) {
667 pr_err("%pfwP: invalid number of guest interrupt identities\n", fwnode);
671 /* Compute base address */
672 rc = imsic_get_mmio_resource(fwnode, 0, &res);
674 pr_err("%pfwP: first MMIO resource not found\n", fwnode);
677 global->base_addr = res.start;
678 global->base_addr &= ~(BIT(global->guest_index_bits +
679 global->hart_index_bits +
680 IMSIC_MMIO_PAGE_SHIFT) - 1);
681 global->base_addr &= ~((BIT(global->group_index_bits) - 1) <<
682 global->group_index_shift);
684 /* Find number of MMIO register sets */
685 while (!imsic_get_mmio_resource(fwnode, *nr_mmios, &res))
691 int __init imsic_setup_state(struct fwnode_handle *fwnode)
693 u32 i, j, index, nr_parent_irqs, nr_mmios, nr_handlers = 0;
694 struct imsic_global_config *global;
695 struct imsic_local_config *local;
696 void __iomem **mmios_va = NULL;
697 struct resource *mmios = NULL;
698 unsigned long reloff, hartid;
699 phys_addr_t base_addr;
703 * Only one IMSIC instance allowed in a platform for clean
704 * implementation of SMP IRQ affinity and per-CPU IPIs.
706 * This means on a multi-socket (or multi-die) platform we
707 * will have multiple MMIO regions for one IMSIC instance.
710 pr_err("%pfwP: already initialized hence ignoring\n", fwnode);
714 if (!riscv_isa_extension_available(NULL, SxAIA)) {
715 pr_err("%pfwP: AIA support not available\n", fwnode);
719 imsic = kzalloc(sizeof(*imsic), GFP_KERNEL);
722 imsic->fwnode = fwnode;
723 global = &imsic->global;
725 global->local = alloc_percpu(typeof(*global->local));
726 if (!global->local) {
731 /* Parse IMSIC fwnode */
732 rc = imsic_parse_fwnode(fwnode, global, &nr_parent_irqs, &nr_mmios);
736 /* Allocate MMIO resource array */
737 mmios = kcalloc(nr_mmios, sizeof(*mmios), GFP_KERNEL);
743 /* Allocate MMIO virtual address array */
744 mmios_va = kcalloc(nr_mmios, sizeof(*mmios_va), GFP_KERNEL);
750 /* Parse and map MMIO register sets */
751 for (i = 0; i < nr_mmios; i++) {
752 rc = imsic_get_mmio_resource(fwnode, i, &mmios[i]);
754 pr_err("%pfwP: unable to parse MMIO regset %d\n", fwnode, i);
758 base_addr = mmios[i].start;
759 base_addr &= ~(BIT(global->guest_index_bits +
760 global->hart_index_bits +
761 IMSIC_MMIO_PAGE_SHIFT) - 1);
762 base_addr &= ~((BIT(global->group_index_bits) - 1) <<
763 global->group_index_shift);
764 if (base_addr != global->base_addr) {
766 pr_err("%pfwP: address mismatch for regset %d\n", fwnode, i);
770 mmios_va[i] = ioremap(mmios[i].start, resource_size(&mmios[i]));
773 pr_err("%pfwP: unable to map MMIO regset %d\n", fwnode, i);
778 /* Initialize local (or per-CPU )state */
779 rc = imsic_local_init();
781 pr_err("%pfwP: failed to initialize local state\n",
786 /* Configure handlers for target CPUs */
787 for (i = 0; i < nr_parent_irqs; i++) {
788 rc = imsic_get_parent_hartid(fwnode, i, &hartid);
790 pr_warn("%pfwP: hart ID for parent irq%d not found\n", fwnode, i);
794 cpu = riscv_hartid_to_cpuid(hartid);
796 pr_warn("%pfwP: invalid cpuid for parent irq%d\n", fwnode, i);
800 /* Find MMIO location of MSI page */
802 reloff = i * BIT(global->guest_index_bits) *
804 for (j = 0; nr_mmios; j++) {
805 if (reloff < resource_size(&mmios[j])) {
811 * MMIO region size may not be aligned to
812 * BIT(global->guest_index_bits) * IMSIC_MMIO_PAGE_SZ
813 * if holes are present.
815 reloff -= ALIGN(resource_size(&mmios[j]),
816 BIT(global->guest_index_bits) * IMSIC_MMIO_PAGE_SZ);
818 if (index >= nr_mmios) {
819 pr_warn("%pfwP: MMIO not found for parent irq%d\n", fwnode, i);
823 local = per_cpu_ptr(global->local, cpu);
824 local->msi_pa = mmios[index].start + reloff;
825 local->msi_va = mmios_va[index] + reloff;
830 /* If no CPU handlers found then can't take interrupts */
832 pr_err("%pfwP: No CPU handlers found\n", fwnode);
834 goto out_local_cleanup;
837 /* Initialize matrix allocator */
838 rc = imsic_matrix_init();
840 pr_err("%pfwP: failed to create matrix allocator\n", fwnode);
841 goto out_local_cleanup;
844 /* We don't need MMIO arrays anymore so let's free-up */
851 imsic_local_cleanup();
853 for (i = 0; i < nr_mmios; i++) {
855 iounmap(mmios_va[i]);
860 free_percpu(imsic->global.local);