From patchwork Mon Dec 22 20:43:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 42548 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F03B425BA1 for ; Mon, 22 Dec 2014 20:45:15 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf3355016eek.5 for ; Mon, 22 Dec 2014 12:45:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=ZBcYq3eV0QW31dXe+DGzN0b24LDs67e6ThEYrbZk6bg=; b=cpBizkbFgYDmgtjcdI9kVwCni8TmxHjJ+DhlniyNhc5YQKfBqSlQzjzA2xjjds2kp3 ZViDQQhTEcxC7EmxPm1fXwn8qrCyohKMyrr76to1/L/Yj46Z7zLF3+KIY9dO6nL2VLSU q2HL2ODJVIyFgMxLDik6bTwdtQIhhnkOUKYHBvm41lvbDVHi0KcrSUKAKrQvARe8DPut ze5Aps1zImRdvRcg0ZUYehTHdszWF2yK2tFJNUKvGi+9fJpQBNEepDYUpwXyeMnm1oNA vAieL/9Q5TuF6flFOO0QTWMy9VCYKNPxuN5yEh/eRt/rnZzWYE+Da8UWgTkdYywQtIvN OaDg== X-Gm-Message-State: ALoCoQkGD5zV2330MLxubkh8rtaNgB+wpQOO6NUciJ4cm7YKV7zpClmdKD10o+i3RXN/G/JYqXaf X-Received: by 10.180.99.227 with SMTP id et3mr2355499wib.3.1419281115236; Mon, 22 Dec 2014 12:45:15 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.5 with SMTP id m5ls1468891laj.71.gmail; Mon, 22 Dec 2014 12:45:15 -0800 (PST) X-Received: by 10.112.159.129 with SMTP id xc1mr23895180lbb.24.1419281115069; Mon, 22 Dec 2014 12:45:15 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id bf5si19564361lab.62.2014.12.22.12.45.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Dec 2014 12:45:14 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id gq15so4641386lab.18 for ; Mon, 22 Dec 2014 12:45:14 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr24086274laa.80.1419281114762; Mon, 22 Dec 2014 12:45:14 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp1140424lbb; Mon, 22 Dec 2014 12:45:13 -0800 (PST) X-Received: by 10.224.32.134 with SMTP id c6mr39818227qad.75.1419281113563; Mon, 22 Dec 2014 12:45:13 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 31si21168874qgi.56.2014.12.22.12.45.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 22 Dec 2014 12:45:13 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:41852 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y39qq-0008M5-D2 for patch@linaro.org; Mon, 22 Dec 2014 15:45:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y39pg-0006m7-NH for qemu-devel@nongnu.org; Mon, 22 Dec 2014 15:44:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y39pZ-0007ju-Fo for qemu-devel@nongnu.org; Mon, 22 Dec 2014 15:44:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y39pZ-0007jm-8U for qemu-devel@nongnu.org; Mon, 22 Dec 2014 15:43:53 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBMKhqrk013399 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 22 Dec 2014 15:43:52 -0500 Received: from bling.home (ovpn-113-45.phx2.redhat.com [10.3.113.45]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBMKhprb002279; Mon, 22 Dec 2014 15:43:52 -0500 From: Alex Williamson To: qemu-devel@nongnu.org Date: Mon, 22 Dec 2014 13:43:52 -0700 Message-ID: <20141222204351.31398.64545.stgit@bling.home> In-Reply-To: <20141222204144.31398.31803.stgit@bling.home> References: <20141222204144.31398.31803.stgit@bling.home> User-Agent: StGit/0.17-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: alex.williamson@redhat.com Subject: [Qemu-devel] [PULL 07/14] hw/vfio/pci: add type, name and group fields in VFIODevice 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.williamson@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Eric Auger Add 3 new fields in the VFIODevice struct. Type is set to VFIO_DEVICE_TYPE_PCI. The type enum value will later be used to discriminate between VFIO PCI and platform devices. The name is set to domain:bus:slot:function. Currently used to test whether the device already is attached to the group. Later on, the name will be used to simplify all traces. The group is simply moved from VFIOPCIDevice to VFIODevice. Signed-off-by: Eric Auger [Fix g_strdup_printf() usage] Signed-off-by: Alex Williamson --- hw/vfio/pci.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 22d0c85..be7b8ff 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -48,6 +48,10 @@ #define VFIO_ALLOW_KVM_MSI 1 #define VFIO_ALLOW_KVM_MSIX 1 +enum { + VFIO_DEVICE_TYPE_PCI = 0, +}; + struct VFIOPCIDevice; typedef struct VFIOQuirk { @@ -186,7 +190,10 @@ typedef struct VFIOMSIXInfo { } VFIOMSIXInfo; typedef struct VFIODevice { + struct VFIOGroup *group; + char *name; int fd; + int type; } VFIODevice; typedef struct VFIOPCIDevice { @@ -208,7 +215,6 @@ typedef struct VFIOPCIDevice { VFIOVGA vga; /* 0xa0000, 0x3b0, 0x3c0 */ PCIHostDeviceAddress host; QLIST_ENTRY(VFIOPCIDevice) next; - struct VFIOGroup *group; EventNotifier err_notifier; uint32_t features; #define VFIO_FEATURE_ENABLE_VGA_BIT 0 @@ -3924,7 +3930,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name, } vdev->vbasedev.fd = ret; - vdev->group = group; + vdev->vbasedev.group = group; QLIST_INSERT_HEAD(&group->device_list, vdev, next); /* Sanity check device */ @@ -4054,7 +4060,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name, error: if (ret) { QLIST_REMOVE(vdev, next); - vdev->group = NULL; + vdev->vbasedev.group = NULL; close(vdev->vbasedev.fd); } return ret; @@ -4063,9 +4069,10 @@ error: static void vfio_put_device(VFIOPCIDevice *vdev) { QLIST_REMOVE(vdev, next); - vdev->group = NULL; + vdev->vbasedev.group = NULL; trace_vfio_put_device(vdev->vbasedev.fd); close(vdev->vbasedev.fd); + g_free(vdev->vbasedev.name); if (vdev->msix) { g_free(vdev->msix); vdev->msix = NULL; @@ -4197,6 +4204,11 @@ static int vfio_initfn(PCIDevice *pdev) return -errno; } + vdev->vbasedev.type = VFIO_DEVICE_TYPE_PCI; + vdev->vbasedev.name = g_strdup_printf("%04x:%02x:%02x.%01x", + vdev->host.domain, vdev->host.bus, + vdev->host.slot, vdev->host.function); + strncat(path, "iommu_group", sizeof(path) - strlen(path) - 1); len = readlink(path, iommu_group_path, sizeof(path)); @@ -4227,10 +4239,7 @@ static int vfio_initfn(PCIDevice *pdev) vdev->host.function); QLIST_FOREACH(pvdev, &group->device_list, next) { - if (pvdev->host.domain == vdev->host.domain && - pvdev->host.bus == vdev->host.bus && - pvdev->host.slot == vdev->host.slot && - pvdev->host.function == vdev->host.function) { + if (strcmp(pvdev->vbasedev.name, vdev->vbasedev.name) == 0) { error_report("vfio: error: device %s is already attached", path); vfio_put_group(group); @@ -4333,7 +4342,7 @@ out_put: static void vfio_exitfn(PCIDevice *pdev) { VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); - VFIOGroup *group = vdev->group; + VFIOGroup *group = vdev->vbasedev.group; vfio_unregister_err_notifier(vdev); pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);