[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 05/20] nubus: move slot bitmap checks from NubusDevice rea
From: |
Laurent Vivier |
Subject: |
Re: [PATCH v4 05/20] nubus: move slot bitmap checks from NubusDevice realize() to BusClass check_address() |
Date: |
Mon, 20 Sep 2021 21:56:06 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 |
Le 17/09/2021 à 09:50, 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>
> ---
> hw/nubus/nubus-bus.c | 37 +++++++++++++++++++++++++++++++++++++
> hw/nubus/nubus-device.c | 29 -----------------------------
> 2 files changed, 37 insertions(+), 29 deletions(-)
>
> diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
> index 404c1032e0..141876b579 100644
> --- a/hw/nubus/nubus-bus.c
> +++ b/hw/nubus/nubus-bus.c
> @@ -87,11 +87,48 @@ static void nubus_init(Object *obj)
> nubus->slot_available_mask = MAKE_64BIT_MASK(0, 16);
> }
>
> +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;
> + }
> + }
> +
> + if (nd->slot < NUBUS_FIRST_SLOT || nd->slot > NUBUS_LAST_SLOT) {
> + error_setg(errp, "Cannot register nubus card, slot must be "
> + "between %d and %d", NUBUS_FIRST_SLOT,
> + NUBUS_LAST_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 d91a1e4af3..7a32c8c95b 100644
> --- a/hw/nubus/nubus-device.c
> +++ b/hw/nubus/nubus-device.c
> @@ -160,35 +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;
> - }
> - }
> -
> - if (nd->slot < NUBUS_FIRST_SLOT || nd->slot > NUBUS_LAST_SLOT) {
> - error_setg(errp, "Cannot register nubus card, slot must be "
> - "between %d and %d", NUBUS_FIRST_SLOT,
> - NUBUS_LAST_SLOT);
> - return;
> - }
> -
> - nubus->slot_available_mask &= ~BIT(nd->slot);
>
> /* Super */
> slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
>
For the code move (but I think it needs some update in patch 4):
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
- [PATCH v4 02/20] nubus-device: expose separate super slot memory region, (continued)
- [PATCH v4 02/20] nubus-device: expose separate super slot memory region, Mark Cave-Ayland, 2021/09/17
- [PATCH v4 03/20] nubus-device: add device slot parameter, Mark Cave-Ayland, 2021/09/17
- [PATCH v4 04/20] nubus: use bitmap to manage available slots, Mark Cave-Ayland, 2021/09/17
- [PATCH v4 05/20] nubus: move slot bitmap checks from NubusDevice realize() to BusClass check_address(), Mark Cave-Ayland, 2021/09/17
- Re: [PATCH v4 05/20] nubus: move slot bitmap checks from NubusDevice realize() to BusClass check_address(),
Laurent Vivier <=
- [PATCH v4 06/20] nubus: implement BusClass get_dev_path(), Mark Cave-Ayland, 2021/09/17
- [PATCH v4 11/20] nubus-device: add romfile property for loading declaration ROMs, Mark Cave-Ayland, 2021/09/17
- [PATCH v4 08/20] nubus: generate bus error when attempting to access empty slots, Mark Cave-Ayland, 2021/09/17
- [PATCH v4 10/20] nubus-device: remove nubus_register_rom() and nubus_register_format_block(), Mark Cave-Ayland, 2021/09/17
- [PATCH v4 07/20] nubus: add trace-events for empty slot accesses, Mark Cave-Ayland, 2021/09/17