Message ID | 20210923091308.13832-6-mark.cave-ayland@ilande.co.uk |
---|---|
State | New |
Headers | show |
Series | nubus: bus, device, bridge, IRQ and address space improvements | expand |
On 9/23/21 11:12, Mark Cave-Ayland wrote: > Allow Nubus to manage the slot allocations itself using the BusClass check_address() > virtual function rather than managing this during NubusDevice realize(). > > Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> > Reviewed-by: Laurent Vivier <laurent@vivier.eu> > --- > hw/nubus/nubus-bus.c | 30 ++++++++++++++++++++++++++++++ > hw/nubus/nubus-device.c | 22 ---------------------- > 2 files changed, 30 insertions(+), 22 deletions(-) > > diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c > index 3cd7534864..d4daaa36f2 100644 > --- a/hw/nubus/nubus-bus.c > +++ b/hw/nubus/nubus-bus.c > @@ -96,11 +96,41 @@ static void nubus_init(Object *obj) > NUBUS_SLOT_NB); > } > > +static bool nubus_check_address(BusState *bus, DeviceState *dev, Error **errp) > +{ > + NubusDevice *nd = NUBUS_DEVICE(dev); > + NubusBus *nubus = NUBUS_BUS(bus); > + uint16_t s; > + > + if (nd->slot == -1) { > + /* No slot specified, find first available free slot */ > + s = ctz32(nubus->slot_available_mask); Same comment than previous patch: int s = ctz32(nubus->slot_available_mask); Otherwise: Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > + if (s != 32) { > + nd->slot = s; > + } else { > + error_setg(errp, "Cannot register nubus card, no free slot " > + "available"); > + return false; > + } > + } else { > + /* Slot specified, make sure the slot is available */ > + if (!(nubus->slot_available_mask & BIT(nd->slot))) { > + error_setg(errp, "Cannot register nubus card, slot %d is " > + "unavailable or already occupied", nd->slot); > + return false; > + } > + } > + > + nubus->slot_available_mask &= ~BIT(nd->slot); > + return true; > +}
Le 23/09/2021 à 11:12, Mark Cave-Ayland a écrit : > Allow Nubus to manage the slot allocations itself using the BusClass check_address() > virtual function rather than managing this during NubusDevice realize(). > > Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> > Reviewed-by: Laurent Vivier <laurent@vivier.eu> > --- > hw/nubus/nubus-bus.c | 30 ++++++++++++++++++++++++++++++ > hw/nubus/nubus-device.c | 22 ---------------------- > 2 files changed, 30 insertions(+), 22 deletions(-) > > Reviewed-by: Laurent Vivier <laurent@vivier.eu>
On 23/09/2021 10:45, Philippe Mathieu-Daudé wrote: > On 9/23/21 11:12, Mark Cave-Ayland wrote: >> Allow Nubus to manage the slot allocations itself using the BusClass check_address() >> virtual function rather than managing this during NubusDevice realize(). >> >> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> >> Reviewed-by: Laurent Vivier <laurent@vivier.eu> >> --- >> hw/nubus/nubus-bus.c | 30 ++++++++++++++++++++++++++++++ >> hw/nubus/nubus-device.c | 22 ---------------------- >> 2 files changed, 30 insertions(+), 22 deletions(-) >> >> diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c >> index 3cd7534864..d4daaa36f2 100644 >> --- a/hw/nubus/nubus-bus.c >> +++ b/hw/nubus/nubus-bus.c >> @@ -96,11 +96,41 @@ static void nubus_init(Object *obj) >> NUBUS_SLOT_NB); >> } >> +static bool nubus_check_address(BusState *bus, DeviceState *dev, Error **errp) >> +{ >> + NubusDevice *nd = NUBUS_DEVICE(dev); >> + NubusBus *nubus = NUBUS_BUS(bus); >> + uint16_t s; >> + >> + if (nd->slot == -1) { >> + /* No slot specified, find first available free slot */ >> + s = ctz32(nubus->slot_available_mask); > > Same comment than previous patch: > > int s = ctz32(nubus->slot_available_mask); ... and same here. > Otherwise: > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > >> + if (s != 32) { >> + nd->slot = s; >> + } else { >> + error_setg(errp, "Cannot register nubus card, no free slot " >> + "available"); >> + return false; >> + } >> + } else { >> + /* Slot specified, make sure the slot is available */ >> + if (!(nubus->slot_available_mask & BIT(nd->slot))) { >> + error_setg(errp, "Cannot register nubus card, slot %d is " >> + "unavailable or already occupied", nd->slot); >> + return false; >> + } >> + } >> + >> + nubus->slot_available_mask &= ~BIT(nd->slot); >> + return true; >> +} ATB, Mark.
diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c index 3cd7534864..d4daaa36f2 100644 --- a/hw/nubus/nubus-bus.c +++ b/hw/nubus/nubus-bus.c @@ -96,11 +96,41 @@ static void nubus_init(Object *obj) NUBUS_SLOT_NB); } +static bool nubus_check_address(BusState *bus, DeviceState *dev, Error **errp) +{ + NubusDevice *nd = NUBUS_DEVICE(dev); + NubusBus *nubus = NUBUS_BUS(bus); + uint16_t s; + + if (nd->slot == -1) { + /* No slot specified, find first available free slot */ + s = ctz32(nubus->slot_available_mask); + if (s != 32) { + nd->slot = s; + } else { + error_setg(errp, "Cannot register nubus card, no free slot " + "available"); + return false; + } + } else { + /* Slot specified, make sure the slot is available */ + if (!(nubus->slot_available_mask & BIT(nd->slot))) { + error_setg(errp, "Cannot register nubus card, slot %d is " + "unavailable or already occupied", nd->slot); + return false; + } + } + + nubus->slot_available_mask &= ~BIT(nd->slot); + return true; +} + static void nubus_class_init(ObjectClass *oc, void *data) { BusClass *bc = BUS_CLASS(oc); bc->realize = nubus_realize; + bc->check_address = nubus_check_address; } static const TypeInfo nubus_bus_info = { diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c index 562650a05b..516b13d2d5 100644 --- a/hw/nubus/nubus-device.c +++ b/hw/nubus/nubus-device.c @@ -160,28 +160,6 @@ static void nubus_device_realize(DeviceState *dev, Error **errp) NubusDevice *nd = NUBUS_DEVICE(dev); char *name; hwaddr slot_offset; - uint16_t s; - - if (nd->slot == -1) { - /* No slot specified, find first available free slot */ - s = ctz32(nubus->slot_available_mask); - if (s != 32) { - nd->slot = s; - } else { - error_setg(errp, "Cannot register nubus card, no free slot " - "available"); - return; - } - } else { - /* Slot specified, make sure the slot is available */ - if (!(nubus->slot_available_mask & BIT(nd->slot))) { - error_setg(errp, "Cannot register nubus card, slot %d is " - "unavailable or already occupied", nd->slot); - return; - } - } - - nubus->slot_available_mask &= ~BIT(nd->slot); /* Super */ slot_offset = nd->slot * NUBUS_SUPER_SLOT_SIZE;