From patchwork Tue Jan 3 15:08:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 134010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AEB0A1007D6 for ; Wed, 4 Jan 2012 01:54:47 +1100 (EST) Received: from localhost ([::1]:43458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ri5lB-0002aB-72 for incoming@patchwork.ozlabs.org; Tue, 03 Jan 2012 09:54:41 -0500 Received: from eggs.gnu.org ([140.186.70.92]:44086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ri5kr-00028k-Np for qemu-devel@nongnu.org; Tue, 03 Jan 2012 09:54:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ri5kl-0000ZS-DG for qemu-devel@nongnu.org; Tue, 03 Jan 2012 09:54:21 -0500 Received: from cantor2.suse.de ([195.135.220.15]:40910 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ri5kl-0000Z6-4B for qemu-devel@nongnu.org; Tue, 03 Jan 2012 09:54:15 -0500 Received: from relay1.suse.de (nat.nue.novell.com [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 7657E8FB3C; Tue, 3 Jan 2012 15:54:14 +0100 (CET) From: Alexander Graf To: "qemu-devel@nongnu.org Developers" Date: Tue, 3 Jan 2012 16:08:21 +0100 Message-Id: <1325603302-12412-10-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1325603302-12412-1-git-send-email-agraf@suse.de> References: <1325603302-12412-1-git-send-email-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Blue Swirl , Michael Ellerman , Aurelien Jarno , David Gibson Subject: [Qemu-devel] [PATCH 09/10] pseries: Check for duplicate addresses on the spapr-vio bus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 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-bounces+incoming=patchwork.ozlabs.org@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 Signed-off-by: Alexander Graf --- 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 cd03416..7a86dc8 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) {