Add two new interfaces to ofw_bus:

- ofw_bus_map_intr()
  Maps an (iparent, IRQ) tuple to a system-global interrupt number in some
  platform dependent way. This is meant to be implemented as a replacement
  for [FDT_]MAP_IRQ() that is an MI interface that knows about the bus
  hierarchy.
- ofw_bus_config_intr()
  Configures an interrupt (previously mapped) based on firmware sense flags.
  This replaces manual interpretation of the sense field in bus drivers and
  will, in a follow-up, allow that interpretation to be redirected to the PIC
  drivers where it belongs. This will eventually replace the tables in
  /sys/dev/fdt/fdt_ARCH.c

The PowerPC/AIM code has been converted to use these globally, with an
implementation in terms of MAP_IRQ() and powerpc_config_intr(), assuming
OpenPIC, at the bus root in nexus(4). The ofw_bus_config_intr() will shortly
be integrated into pic_if.m and bounced through nexus into the PIC tree.

FDT integration will happen significantly later due to larger testing
requirements. This patch in general also lays the groundwork for the removal
of /sys/dev/fdt/fdt_ARCH.c and machine/fdt.h.
This commit is contained in:
Nathan Whitehorn 2013-10-23 17:24:21 +00:00
parent 959bd87986
commit f214848258
7 changed files with 92 additions and 18 deletions

View File

@ -70,4 +70,16 @@ ofw_bus_get_type(device_t dev)
return (OFW_BUS_GET_TYPE(device_get_parent(dev), dev));
}
static __inline int
ofw_bus_map_intr(device_t dev, phandle_t iparent, int irq)
{
return (OFW_BUS_MAP_INTR(dev, dev, iparent, irq));
}
static __inline int
ofw_bus_config_intr(device_t dev, int irq, int sense)
{
return (OFW_BUS_CONFIG_INTR(dev, dev, irq, sense));
}
#endif /* !_DEV_OFW_OFW_BUS_H_ */

View File

@ -56,6 +56,8 @@ CODE {
static ofw_bus_get_name_t ofw_bus_default_get_name;
static ofw_bus_get_node_t ofw_bus_default_get_node;
static ofw_bus_get_type_t ofw_bus_default_get_type;
static ofw_bus_map_intr_t ofw_bus_default_map_intr;
static ofw_bus_config_intr_t ofw_bus_default_config_intr;
static const struct ofw_bus_devinfo *
ofw_bus_default_get_devinfo(device_t bus, device_t dev)
@ -98,6 +100,31 @@ CODE {
return (NULL);
}
int
ofw_bus_default_map_intr(device_t bus, device_t dev, phandle_t iparent,
int irq)
{
/* Propagate up the bus hierarchy until someone handles it. */
if (device_get_parent(bus) != NULL)
return OFW_BUS_MAP_INTR(device_get_parent(bus), dev,
iparent, irq);
/* If that fails, then assume a one-domain system */
return (irq);
}
int
ofw_bus_default_config_intr(device_t bus, device_t dev, int irq,
int sense)
{
/* Propagate up the bus hierarchy until someone handles it. */
if (device_get_parent(bus) != NULL)
return OFW_BUS_CONFIG_INTR(device_get_parent(bus), dev,
irq, sense);
return (ENXIO);
}
};
# Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus
@ -143,3 +170,22 @@ METHOD const char * get_type {
device_t bus;
device_t dev;
} DEFAULT ofw_bus_default_get_type;
# Map an (interrupt parent, IRQ) pair to a unique system-wide interrupt number.
METHOD int map_intr {
device_t bus;
device_t dev;
phandle_t iparent;
int irq;
} DEFAULT ofw_bus_default_map_intr;
# Configure an interrupt using the device-tree encoded sense key (the second
# value in the interrupts property if interrupt-cells is 2). IRQ should be
# encoded as from ofw_bus_map_intr().
METHOD int config_intr {
device_t bus;
device_t dev;
int irq;
int sense;
} DEFAULT ofw_bus_default_config_intr;

View File

@ -272,7 +272,7 @@ ofw_pci_route_interrupt(device_t bus, device_t dev, int pin)
if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), &sc->sc_pci_iinfo, &reg,
sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr),
&iparent, maskbuf))
return (MAP_IRQ(iparent, mintr));
return (ofw_bus_map_intr(dev, iparent, mintr));
/* Maybe it's a real interrupt, not an intpin */
if (pin > 4)

View File

@ -157,7 +157,7 @@ ofw_pcib_pci_route_interrupt(device_t bridge, device_t dev, int intpin)
* it again on higher levels - that causes problems
* in some cases, and never seems to be required.
*/
return (MAP_IRQ(iparent, mintr));
return (ofw_bus_map_intr(dev, iparent, mintr));
}
} else if (intpin >= 1 && intpin <= 4) {
/*

View File

@ -218,15 +218,13 @@ ofw_pcibus_enum_devtree(device_t dev, u_int domain, u_int busno)
OF_getprop(OF_xref_phandle(iparent),
"#interrupt-cells", &icells,
sizeof(icells));
intr[0] = MAP_IRQ(iparent, intr[0]);
intr[0] = ofw_bus_map_intr(dev, iparent,
intr[0]);
}
if (iparent != 0 && icells > 1) {
powerpc_config_intr(intr[0],
(intr[1] & 1) ? INTR_TRIGGER_LEVEL :
INTR_TRIGGER_EDGE,
INTR_POLARITY_LOW);
}
if (iparent != 0 && icells > 1)
ofw_bus_config_intr(dev, intr[0],
intr[1]);
resource_list_add(&dinfo->opd_dinfo.resources,
SYS_RES_IRQ, 0, intr[0], intr[0], 1);
@ -343,12 +341,13 @@ ofw_pcibus_assign_interrupt(device_t dev, device_t child)
isz = OF_getprop(node, "AAPL,interrupts", &intr, sizeof(intr));
if (isz == sizeof(intr))
return ((iparent == -1) ? intr : MAP_IRQ(iparent, intr));
return ((iparent == -1) ? intr : ofw_bus_map_intr(dev, iparent,
intr));
isz = OF_getprop(node, "interrupts", &intr, sizeof(intr));
if (isz == sizeof(intr)) {
if (iparent != -1)
intr = MAP_IRQ(iparent, intr);
intr = ofw_bus_map_intr(dev, iparent, intr);
} else {
/* No property: our best guess is the intpin. */
intr = pci_get_intpin(child);

View File

@ -96,6 +96,8 @@ static bus_get_resource_list_t nexus_get_resource_list;
static bus_bind_intr_t nexus_bind_intr;
#endif
static bus_config_intr_t nexus_config_intr;
static ofw_bus_map_intr_t nexus_ofw_map_intr;
static ofw_bus_config_intr_t nexus_ofw_config_intr;
static ofw_bus_get_devinfo_t nexus_get_devinfo;
static int nexus_inlist(const char *, const char *const *);
@ -141,6 +143,8 @@ static device_method_t nexus_methods[] = {
DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),
DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
DEVMETHOD(ofw_bus_map_intr, nexus_ofw_map_intr),
DEVMETHOD(ofw_bus_config_intr, nexus_ofw_config_intr),
DEVMETHOD_END
};
@ -370,6 +374,21 @@ nexus_config_intr(device_t dev, int irq, enum intr_trigger trig,
return (powerpc_config_intr(irq, trig, pol));
}
static int
nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent, int irq)
{
return (MAP_IRQ(iparent, irq));
}
static int
nexus_ofw_config_intr(device_t dev, device_t child, int irq, int sense)
{
return (bus_generic_config_intr(child, irq, (sense & 1) ?
INTR_TRIGGER_LEVEL : INTR_TRIGGER_EDGE,
INTR_POLARITY_LOW));
}
static struct resource *
nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
u_long start, u_long end, u_long count, u_int flags)
@ -600,14 +619,11 @@ nexus_setup_dinfo(device_t dev, phandle_t node)
OF_searchprop(iparent, "#interrupt-cells", &icells,
sizeof(icells));
for (i = 0; i < nintr; i+= icells) {
intr[i] = MAP_IRQ(iparent, intr[i]);
intr[i] = ofw_bus_map_intr(dev, iparent, intr[i]);
resource_list_add(&ndi->ndi_rl, SYS_RES_IRQ, i, intr[i],
intr[i], 1);
if (icells > 1) {
powerpc_config_intr(intr[i], (intr[i+1] & 1) ?
INTR_TRIGGER_LEVEL : INTR_TRIGGER_EDGE,
INTR_POLARITY_LOW);
}
if (icells > 1)
ofw_bus_config_intr(dev, intr[i], intr[i+1]);
}
free(intr, M_OFWPROP);
}

View File

@ -156,7 +156,8 @@ vdevice_attach(device_t dev)
for (i = 0; i < nintr; i += icells) {
u_int irq = intr[i];
if (iparent != -1)
irq = MAP_IRQ(iparent, intr[i]);
irq = ofw_bus_map_intr(dev, iparent,
intr[i]);
resource_list_add(&dinfo->mdi_resources,
SYS_RES_IRQ, i, irq, irq, i);