From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:32875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaJup-0002zZ-PS for qemu-devel@nongnu.org; Mon, 12 Dec 2011 23:24:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaJum-0006Pn-Ip for qemu-devel@nongnu.org; Mon, 12 Dec 2011 23:24:31 -0500 From: David Gibson Date: Tue, 13 Dec 2011 15:24:35 +1100 Message-Id: <1323750275-947-9-git-send-email-david@gibson.dropbear.id.au> In-Reply-To: <1323750275-947-1-git-send-email-david@gibson.dropbear.id.au> References: <1323750275-947-1-git-send-email-david@gibson.dropbear.id.au> Subject: [Qemu-devel] [PATCH 8/8] pseries: Check for duplicate addresses on the spapr-vio bus List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: agraf@suse.de Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org From: Michael Ellerman Check that devices on the spapr vio bus aren't given duplicate addresses. Currently we will not run with duplicate devices, the fdt code will spot it, but the error reporting is not great. With this patch we can report the error nicely in terms of the device names given by the user. Signed-off-by: Michael Ellerman Signed-off-by: David Gibson --- hw/spapr_vio.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/hw/spapr_vio.c b/hw/spapr_vio.c index b188a71..0e5581c 100644 --- a/hw/spapr_vio.c +++ b/hw/spapr_vio.c @@ -621,11 +621,43 @@ static void rtas_quiesce(sPAPREnvironment *spapr, uint32_t token, rtas_st(rets, 0, 0); } +static int spapr_vio_check_reg(VIOsPAPRDevice *sdev, VIOsPAPRDeviceInfo *info) +{ + VIOsPAPRDevice *other_sdev; + DeviceState *qdev; + VIOsPAPRBus *sbus; + + sbus = DO_UPCAST(VIOsPAPRBus, bus, sdev->qdev.parent_bus); + + /* + * Check two device aren't given clashing addresses by the user (or some + * other mechanism). We have to open code this because we have to check + * for matches with devices other than us. + */ + QTAILQ_FOREACH(qdev, &sbus->bus.children, sibling) { + other_sdev = DO_UPCAST(VIOsPAPRDevice, qdev, qdev); + + if (other_sdev != sdev && other_sdev->reg == sdev->reg) { + fprintf(stderr, "vio: %s and %s devices conflict at address %#x\n", + info->qdev.name, other_sdev->qdev.info->name, sdev->reg); + return -EEXIST; + } + } + + return 0; +} + static int spapr_vio_busdev_init(DeviceState *qdev, DeviceInfo *qinfo) { VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo; VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev; char *id; + int ret; + + ret = spapr_vio_check_reg(dev, info); + if (ret) { + return ret; + } /* Don't overwrite ids assigned on the command line */ if (!dev->qdev.id) { -- 1.7.7.3