@@ -1238,6 +1238,62 @@ static int __init map_device_children(struct domain *d,
return 0;
}
+/*
+ * handle_device_interrupts retrieves the interrupts configuration from
+ * a device tree node and maps those interrupts to the target domain.
+ *
+ * Returns:
+ * < 0 error
+ * 0 success
+ */
+static int __init handle_device_interrupts(struct domain *d,
+ struct dt_device_node *dev,
+ bool need_mapping)
+{
+ unsigned int i, nirq;
+ int res;
+ struct dt_raw_irq rirq;
+
+ nirq = dt_number_of_irq(dev);
+
+ /* Give permission and map IRQs */
+ for ( i = 0; i < nirq; i++ )
+ {
+ res = dt_device_get_raw_irq(dev, i, &rirq);
+ if ( res )
+ {
+ printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n",
+ i, dt_node_full_name(dev));
+ return res;
+ }
+
+ /*
+ * Don't map IRQ that have no physical meaning
+ * ie: IRQ whose controller is not the GIC
+ */
+ if ( rirq.controller != dt_interrupt_controller )
+ {
+ dt_dprintk("irq %u not connected to primary controller. Connected to %s\n",
+ i, dt_node_full_name(rirq.controller));
+ continue;
+ }
+
+ res = platform_get_irq(dev, i);
+ if ( res < 0 )
+ {
+ printk(XENLOG_ERR "Unable to get irq %u for %s\n",
+ i, dt_node_full_name(dev));
+ return res;
+ }
+
+ res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev));
+ if ( res )
+ return res;
+ }
+
+ return 0;
+}
+
/*
* For a given device node:
* - Give permission to the guest to manage IRQ and MMIO range
@@ -1250,19 +1306,16 @@ static int __init map_device_children(struct domain *d,
static int __init handle_device(struct domain *d, struct dt_device_node *dev,
p2m_type_t p2mt)
{
- unsigned int nirq;
unsigned int naddr;
unsigned int i;
int res;
- struct dt_raw_irq rirq;
u64 addr, size;
bool need_mapping = !dt_device_for_passthrough(dev);
- nirq = dt_number_of_irq(dev);
naddr = dt_number_of_address(dev);
- dt_dprintk("%s passthrough = %d nirq = %d naddr = %u\n",
- dt_node_full_name(dev), need_mapping, nirq, naddr);
+ dt_dprintk("%s passthrough = %d naddr = %u\n",
+ dt_node_full_name(dev), need_mapping, naddr);
if ( need_mapping )
{
@@ -1290,40 +1343,9 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev,
}
}
- /* Give permission and map IRQs */
- for ( i = 0; i < nirq; i++ )
- {
- res = dt_device_get_raw_irq(dev, i, &rirq);
- if ( res )
- {
- printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n",
- i, dt_node_full_name(dev));
- return res;
- }
-
- /*
- * Don't map IRQ that have no physical meaning
- * ie: IRQ whose controller is not the GIC
- */
- if ( rirq.controller != dt_interrupt_controller )
- {
- dt_dprintk("irq %u not connected to primary controller. Connected to %s\n",
- i, dt_node_full_name(rirq.controller));
- continue;
- }
-
- res = platform_get_irq(dev, i);
- if ( res < 0 )
- {
- printk(XENLOG_ERR "Unable to get irq %u for %s\n",
- i, dt_node_full_name(dev));
- return res;
- }
-
- res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev));
- if ( res )
- return res;
- }
+ res = handle_device_interrupts(d, dev, need_mapping);
+ if ( res < 0 )
+ return res;
/* Give permission and map MMIOs */
for ( i = 0; i < naddr; i++ )