From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77144C433EF for ; Wed, 29 Sep 2021 09:35:05 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 436DF610CC for ; Wed, 29 Sep 2021 09:35:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 436DF610CC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:47958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVVzU-0000hd-FC for qemu-devel@archiver.kernel.org; Wed, 29 Sep 2021 05:35:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVVtX-0001qg-9A for qemu-devel@nongnu.org; Wed, 29 Sep 2021 05:28:55 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:37851) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVVtS-0005kr-9p for qemu-devel@nongnu.org; Wed, 29 Sep 2021 05:28:55 -0400 Received: from quad ([82.142.21.142]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MRTAj-1m8kDT451Z-00NUpC; Wed, 29 Sep 2021 11:28:47 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 05/20] nubus: move slot bitmap checks from NubusDevice realize() to BusClass check_address() Date: Wed, 29 Sep 2021 11:28:28 +0200 Message-Id: <20210929092843.2686234-6-laurent@vivier.eu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210929092843.2686234-1-laurent@vivier.eu> References: <20210929092843.2686234-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:CUJ/J4uF2iaoVj70WBiThgw+Sj7VYK8vRxTQmPnbFp9LSYXZMSd 4nFu7mhmz8Q5ZADPHPOpzfr6WhNtzNdJ3QyDAO6wbXiW0YLt6mNnbpHyTNxPtbUP/LxE1Xs 3POKsa6OW5bH4RnK9PpZYG3IE/M/GUWrZlAtaCEEXLzO938FAH8MGhxm+UBTXnZ0Lv257s1 1I8pw/aXnJZZr1SGJh51w== X-UI-Out-Filterresults: notjunk:1;V03:K0:5Kg0lQvqvMU=:KqvkAmC5p36Asef9puvtGI 7gKrMKr+BsNEiqXggXoBwywRhTFcDG4ifnBv0rOsKld2GRpz4yrZ12hvmH/i/0q81Kdfs8duS erzC44ocZ71eNGY1vAEpy5/sFNg2sMDMcEqN2PC/BP9laQBzkCllluJczr55/Me3tsvY3ovaZ phqosD1n0xNiK/caLB8EtB1I5Pjla1k6ikTHhHdignz7lE7Wk2oRMwx/lG9Brq8H+o7gSmL3z g0syi0GPrYTm+fq2PQnlyTvWYQQvn21Ir+BzBFmpLVNPxe1kZr/81+/rCV4vWg2dVKFiod5Ml N53TCMdc9uv4BvLRjaAP6+0EBRl/CWQdz8k9TjKuP7yesFIfVBiCojX50uTeqGA8FwBFjs05J dphMDDMANC3nsLChgaZ/e0U2OV7oB6tY2deBG2HEzlHcBsvwH4Fs8+kPcP0QsAMVNSu4QE+uN 0BPD3Z5AY7MvY19617TeGA5rNBTMcztu5Vs47VaFkCSCQsFeoQ42AcEoSnGeYYWP+413qyXrw aMXSJ9mY2EEpMp/2K2qA2ILlOSZUuZMQLklTCilh/SIWLNuuOZxNk6f5T7HCpYWPO5h+o4Fs1 H25jhcEXNhe4NMuJ8z1V0fO0mU38t3hEdESudlpoSWLzoKiEeu/QbxJR5oLvR+ybPaJFO04C1 CAu5fi8j9GG8xYb2RYJyo9BEQZ/5zVqyjLfwDBcG0d9Fa8gR6kQOg9yK+TkIHzHPcvpNIdc/l HyZ0H2d+vhatzVVe3bh06n0GNVllCeBCGrsQJA== Received-SPF: none client-ip=212.227.126.187; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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: , Cc: Mark Cave-Ayland , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Mark Cave-Ayland 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é Message-Id: <20210924073808.1041-6-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- hw/nubus/nubus-bus.c | 29 +++++++++++++++++++++++++++++ hw/nubus/nubus-device.c | 21 --------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c index 3cd75348646b..96ef027bad26 100644 --- a/hw/nubus/nubus-bus.c +++ b/hw/nubus/nubus-bus.c @@ -96,11 +96,40 @@ 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); + + if (nd->slot == -1) { + /* No slot specified, find first available free slot */ + int 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 2e96d6b4fc39..516b13d2d53d 100644 --- a/hw/nubus/nubus-device.c +++ b/hw/nubus/nubus-device.c @@ -161,27 +161,6 @@ static void nubus_device_realize(DeviceState *dev, Error **errp) char *name; hwaddr slot_offset; - if (nd->slot == -1) { - /* No slot specified, find first available free slot */ - int 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; -- 2.31.1