x86: Tidy up the PIRQ routing code a little

This code could use a little tightening up. There is some repetition and
an odd use of fdtdec_get_int_array().

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
Simon Glass 2015-08-10 07:05:06 -06:00
parent 1adafd40bb
commit 9e3ff9c2b4

View File

@ -125,10 +125,10 @@ static int create_pirq_routing_table(void)
return -EINVAL; return -EINVAL;
} }
ret = fdtdec_get_int_array(blob, node, "intel,pirq-link", ret = fdtdec_get_int(blob, node, "intel,pirq-link", -1);
&irq_router.link_base, 1); if (ret == -1)
if (ret)
return ret; return ret;
irq_router.link_base = ret;
irq_router.irq_mask = fdtdec_get_int(blob, node, irq_router.irq_mask = fdtdec_get_int(blob, node,
"intel,pirq-mask", PIRQ_BITMAP); "intel,pirq-mask", PIRQ_BITMAP);
@ -156,18 +156,13 @@ static int create_pirq_routing_table(void)
} }
cell = fdt_getprop(blob, node, "intel,pirq-routing", &len); cell = fdt_getprop(blob, node, "intel,pirq-routing", &len);
if (!cell) if (!cell || len % sizeof(struct pirq_routing))
return -EINVAL; return -EINVAL;
count = len / sizeof(struct pirq_routing);
if ((len % sizeof(struct pirq_routing)) == 0) rt = calloc(1, sizeof(struct irq_routing_table));
count = len / sizeof(struct pirq_routing);
else
return -EINVAL;
rt = malloc(sizeof(struct irq_routing_table));
if (!rt) if (!rt)
return -ENOMEM; return -ENOMEM;
memset((char *)rt, 0, sizeof(struct irq_routing_table));
/* Populate the PIRQ table fields */ /* Populate the PIRQ table fields */
rt->signature = PIRQ_SIGNATURE; rt->signature = PIRQ_SIGNATURE;
@ -181,7 +176,8 @@ static int create_pirq_routing_table(void)
slot_base = rt->slots; slot_base = rt->slots;
/* Now fill in the irq_info entries in the PIRQ table */ /* Now fill in the irq_info entries in the PIRQ table */
for (i = 0; i < count; i++) { for (i = 0; i < count;
i++, cell += sizeof(struct pirq_routing) / sizeof(u32)) {
struct pirq_routing pr; struct pirq_routing pr;
pr.bdf = fdt_addr_to_cpu(cell[0]); pr.bdf = fdt_addr_to_cpu(cell[0]);
@ -212,25 +208,14 @@ static int create_pirq_routing_table(void)
if (slot->irq[pr.pin - 1].link != if (slot->irq[pr.pin - 1].link !=
LINK_N2V(pr.pirq, irq_router.link_base)) LINK_N2V(pr.pirq, irq_router.link_base))
debug("WARNING: Inconsistent PIRQ routing information\n"); debug("WARNING: Inconsistent PIRQ routing information\n");
cell += sizeof(struct pirq_routing) /
sizeof(u32);
continue;
} else {
debug("writing INT%c\n", 'A' + pr.pin - 1);
fill_irq_info(slot, PCI_BUS(pr.bdf),
PCI_DEV(pr.bdf), pr.pin, pr.pirq);
cell += sizeof(struct pirq_routing) /
sizeof(u32);
continue; continue;
} }
} else {
slot = slot_base + irq_entries++;
} }
debug("writing INT%c\n", 'A' + pr.pin - 1);
slot = slot_base + irq_entries; fill_irq_info(slot, PCI_BUS(pr.bdf), PCI_DEV(pr.bdf), pr.pin,
fill_irq_info(slot, PCI_BUS(pr.bdf), PCI_DEV(pr.bdf), pr.pirq);
pr.pin, pr.pirq);
irq_entries++;
cell += sizeof(struct pirq_routing) / sizeof(u32);
} }
rt->size = irq_entries * sizeof(struct irq_info) + 32; rt->size = irq_entries * sizeof(struct irq_info) + 32;