From patchwork Sun Nov 30 18:35:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 41728 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f72.google.com (mail-ee0-f72.google.com [74.125.83.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C6D8B24001 for ; Sun, 30 Nov 2014 18:35:46 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id e53sf5854999eek.7 for ; Sun, 30 Nov 2014 10:35:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=JQECfDBvu+VJUbdA7FMzG0hWVY9bIfQ7n5jteDbkRpY=; b=TvoySnz8Tg0YxM9X6F5Z6F40otFAXgB6hHcQFbmeG8/WhXhjwUtNnxtLKAMRk4cWst uMJbspINWbWABTcYm3fde0i0KRr0aHqgloPtD5gIj3euQHVpGqIyDqEPuDlWLqMNa15b uqH+/m0nkDVrbBinLxrrJ6bmgVz2a143VoySF7sihkAzcsnfH7sbU+xz3e9q10SBPgUC zuEcDw7y7uqdLKJ0khxZBXHD58pkm4FmOd3jr4HsAoMUrEebVsRHtJ45SDGjT54D8dWZ EsaH8X77pXv1VlvB90+bFlOVhAgVKyoL/c+tAXwjB69uPEl5tgkufdxMI6j3HW95/2ns n/Qw== X-Gm-Message-State: ALoCoQk1r/Iv26Jsk+V8WnTKcanVrEKlKo3Dd53unFjfLrUsyjNmptZ2sDpOmDkLsP8jv0BXKmfq X-Received: by 10.152.18.136 with SMTP id w8mr739905lad.5.1417372545972; Sun, 30 Nov 2014 10:35:45 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.116.48 with SMTP id jt16ls938817lab.44.gmail; Sun, 30 Nov 2014 10:35:45 -0800 (PST) X-Received: by 10.152.6.97 with SMTP id z1mr30379072laz.4.1417372545471; Sun, 30 Nov 2014 10:35:45 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id rs2si15633253lbb.91.2014.11.30.10.35.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 10:35:45 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id w7so7445977lbi.5 for ; Sun, 30 Nov 2014 10:35:45 -0800 (PST) X-Received: by 10.152.3.67 with SMTP id a3mr9156524laa.56.1417372545368; Sun, 30 Nov 2014 10:35:45 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp172666lbc; Sun, 30 Nov 2014 10:35:44 -0800 (PST) X-Received: by 10.180.100.98 with SMTP id ex2mr8636386wib.58.1417372544656; Sun, 30 Nov 2014 10:35:44 -0800 (PST) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com. [209.85.212.181]) by mx.google.com with ESMTPS id ic9si26840745wjb.15.2014.11.30.10.35.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 10:35:44 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.181 as permitted sender) client-ip=209.85.212.181; Received: by mail-wi0-f181.google.com with SMTP id r20so15278943wiv.8 for ; Sun, 30 Nov 2014 10:35:44 -0800 (PST) X-Received: by 10.194.246.130 with SMTP id xw2mr83852400wjc.33.1417372544434; Sun, 30 Nov 2014 10:35:44 -0800 (PST) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id z7sm38794058wia.22.2014.11.30.10.35.43 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 10:35:43 -0800 (PST) From: Eric Auger To: eric.auger@st.com, christoffer.dall@linaro.org, qemu-devel@nongnu.org, agraf@suse.de, pbonzini@redhat.com, kim.phillips@freescale.com, a.rigo@virtualopensystems.com, manish.jaggi@caviumnetworks.com, joel.schopp@amd.com, zhaoshenglong@huawei.com, ard.biesheuvel@linaro.org Cc: eric.auger@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, alex.williamson@redhat.com, peter.maydell@linaro.org, will.deacon@arm.com, Bharat.Bhushan@freescale.com, stuart.yoder@freescale.com, a.motakis@virtualopensystems.com Subject: [PATCH v8 05/19] hw/vfio/pci: add type, name and group fields in VFIODevice Date: Sun, 30 Nov 2014 18:35:10 +0000 Message-Id: <1417372524-12936-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1417372524-12936-1-git-send-email-eric.auger@linaro.org> References: <1417372524-12936-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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 cd9ce4e..157e1a5 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; + g_strdup_printf(vdev->vbasedev.name, "%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);