From patchwork Thu Sep 23 09:12:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Cave-Ayland X-Patchwork-Id: 1531662 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HFVCg5jDsz9sW5 for ; Thu, 23 Sep 2021 19:26:23 +1000 (AEST) Received: from localhost ([::1]:42880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTKzl-0001cB-Fk for incoming@patchwork.ozlabs.org; Thu, 23 Sep 2021 05:26:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTKnY-0001K8-4l for qemu-devel@nongnu.org; Thu, 23 Sep 2021 05:13:45 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]:48632 helo=mail.default.ilande.bv.iomart.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTKnV-0007RW-KK for qemu-devel@nongnu.org; Thu, 23 Sep 2021 05:13:43 -0400 Received: from [2a00:23c4:8b9d:4100:5d98:71b5:90ca:dad1] (helo=kentang.home) by mail.default.ilande.bv.iomart.io with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mTKnK-0003vl-UF; Thu, 23 Sep 2021 10:13:34 +0100 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, laurent@vivier.eu Date: Thu, 23 Sep 2021 10:12:53 +0100 Message-Id: <20210923091308.13832-6-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210923091308.13832-1-mark.cave-ayland@ilande.co.uk> References: <20210923091308.13832-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a00:23c4:8b9d:4100:5d98:71b5:90ca:dad1 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH v5 05/20] nubus: move slot bitmap checks from NubusDevice realize() to BusClass check_address() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.default.ilande.bv.iomart.io) Received-SPF: pass client-ip=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.default.ilande.bv.iomart.io X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Laurent Vivier --- 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); + 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;