From patchwork Wed Nov 16 04:53:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 125925 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 EDC53B6F8F for ; Wed, 16 Nov 2011 15:53:36 +1100 (EST) Received: from localhost ([::1]:51494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQXV7-0001U3-Cn for incoming@patchwork.ozlabs.org; Tue, 15 Nov 2011 23:53:33 -0500 Received: from eggs.gnu.org ([140.186.70.92]:35868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQXUy-0001Ty-CV for qemu-devel@nongnu.org; Tue, 15 Nov 2011 23:53:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RQXUt-0008CA-MG for qemu-devel@nongnu.org; Tue, 15 Nov 2011 23:53:24 -0500 Received: from ozlabs.org ([203.10.76.45]:46688) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQXUt-0008B2-Bh; Tue, 15 Nov 2011 23:53:19 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 28231B6FA6; Wed, 16 Nov 2011 15:53:17 +1100 (EST) From: David Gibson To: agraf@suse.de Date: Wed, 16 Nov 2011 15:53:13 +1100 Message-Id: <1321419193-31627-1-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.7.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 203.10.76.45 Cc: michael@ellerman.id.au, qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] pseries: Fix qdev.id handling in the VIO bus code 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 When the user creates a device on the command line with -device, they can specify the id, using id=foo. Currently the VIO bus code overwrites this id with it's own value. We should only set qdev.id if it is not already set by the user. The device tree code uses qdev.id for the device tree node name, however we can't rely on the user specifiying the id using proper device tree syntax, ie. device@reg. So separate the device tree node name from the qdev.id, but use the same syntax, so they will match by default. Signed-off-by: Michael Ellerman --- hw/spapr_vio.c | 36 +++++++++++++++++++++++++++++------- 1 files changed, 29 insertions(+), 7 deletions(-) diff --git a/hw/spapr_vio.c b/hw/spapr_vio.c index b7b3ddd..2dcc036 100644 --- a/hw/spapr_vio.c +++ b/hw/spapr_vio.c @@ -73,20 +73,39 @@ VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg) return NULL; } +static char *vio_format_dev_name(VIOsPAPRDevice *dev) +{ + VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)dev->qdev.info; + char *name; + + /* Device tree style name device@reg */ + if (asprintf(&name, "%s@%x", info->dt_name, dev->reg) < 0) { + return NULL; + } + + return name; +} + #ifdef CONFIG_FDT static int vio_make_devnode(VIOsPAPRDevice *dev, void *fdt) { VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)dev->qdev.info; - int vdevice_off, node_off; - int ret; + int vdevice_off, node_off, ret; + char *dt_name; vdevice_off = fdt_path_offset(fdt, "/vdevice"); if (vdevice_off < 0) { return vdevice_off; } - node_off = fdt_add_subnode(fdt, vdevice_off, dev->qdev.id); + dt_name = vio_format_dev_name(dev); + if (!dt_name) { + return -ENOMEM; + } + + node_off = fdt_add_subnode(fdt, vdevice_off, dt_name); + free(dt_name); if (node_off < 0) { return node_off; } @@ -608,12 +627,15 @@ static int spapr_vio_busdev_init(DeviceState *qdev, DeviceInfo *qinfo) VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev; char *id; - if (asprintf(&id, "%s@%x", info->dt_name, dev->reg) < 0) { - return -1; + /* Don't overwrite ids assigned on the command line */ + if (!dev->qdev.id) { + id = vio_format_dev_name(dev); + if (!id) { + return -1; + } + dev->qdev.id = id; } - dev->qdev.id = id; - dev->qirq = spapr_allocate_irq(dev->vio_irq_num, &dev->vio_irq_num); if (!dev->qirq) { return -1;