From nobody Mon Feb 9 07:23:16 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1525469823068828.4857598885648; Fri, 4 May 2018 14:37:03 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D290020946065; Fri, 4 May 2018 14:36:51 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 351CF20946064 for ; Fri, 4 May 2018 14:36:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7BA6AA1BE2; Fri, 4 May 2018 21:36:49 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-129.rdu2.redhat.com [10.10.120.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5FE72023227; Fri, 4 May 2018 21:36:48 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 4 May 2018 23:36:37 +0200 Message-Id: <20180504213637.11266-8-lersek@redhat.com> In-Reply-To: <20180504213637.11266-1-lersek@redhat.com> References: <20180504213637.11266-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 04 May 2018 21:36:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 04 May 2018 21:36:49 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH 7/7] OvmfPkg/Virtio10Dxe: convert to PciCapLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Replace the manual capability list parsing in OvmfPkg/Virtio10Dxe with PciCapLib and PciCapPciIoLib API calls. The VIRTIO_PCI_CAP_LINK structure type is now superfluous. (Well, it always has been; we should have used EFI_PCI_CAPABILITY_HDR.) Also, EFI_PCI_CAPABILITY_VENDOR_HDR is now included at the front of VIRTIO_PCI_CAP. No driver other than Virtio10Dxe relies on VIRTIO_PCI_CAP. Cc: Ard Biesheuvel Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- OvmfPkg/Virtio10Dxe/Virtio10.inf | 2 + OvmfPkg/Include/IndustryStandard/Virtio10.h | 7 +- OvmfPkg/Virtio10Dxe/Virtio10.c | 135 +++++++------------- 3 files changed, 52 insertions(+), 92 deletions(-) diff --git a/OvmfPkg/Virtio10Dxe/Virtio10.inf b/OvmfPkg/Virtio10Dxe/Virtio1= 0.inf index c4ef15d94bfc..db0cb1189a29 100644 --- a/OvmfPkg/Virtio10Dxe/Virtio10.inf +++ b/OvmfPkg/Virtio10Dxe/Virtio10.inf @@ -32,6 +32,8 @@ [LibraryClasses] BaseMemoryLib DebugLib MemoryAllocationLib + PciCapLib + PciCapPciIoLib UefiBootServicesTableLib UefiDriverEntryPoint UefiLib diff --git a/OvmfPkg/Include/IndustryStandard/Virtio10.h b/OvmfPkg/Include/= IndustryStandard/Virtio10.h index c5efb5cfcb8a..7d51aa36b326 100644 --- a/OvmfPkg/Include/IndustryStandard/Virtio10.h +++ b/OvmfPkg/Include/IndustryStandard/Virtio10.h @@ -16,6 +16,7 @@ #ifndef _VIRTIO_1_0_H_ #define _VIRTIO_1_0_H_ =20 +#include #include =20 // @@ -29,11 +30,7 @@ // #pragma pack (1) typedef struct { - UINT8 CapId; // Capability identifier (generic) - UINT8 CapNext; // Link to next capability (generic) -} VIRTIO_PCI_CAP_LINK; - -typedef struct { + EFI_PCI_CAPABILITY_VENDOR_HDR VendorHdr; UINT8 ConfigType; // Identifies the specific VirtIo 1.0 config structure UINT8 Bar; // The BAR that contains the structure UINT8 Padding[3]; diff --git a/OvmfPkg/Virtio10Dxe/Virtio10.c b/OvmfPkg/Virtio10Dxe/Virtio10.c index e9b50b6e437b..9ebb72c76bfd 100644 --- a/OvmfPkg/Virtio10Dxe/Virtio10.c +++ b/OvmfPkg/Virtio10Dxe/Virtio10.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include =20 @@ -184,48 +186,6 @@ GetBarType ( } =20 =20 -/** - Read a slice from PCI config space at the given offset, then advance the - offset. - - @param [in] PciIo The EFI_PCI_IO_PROTOCOL instance that represents= the - device. - - @param [in,out] Offset On input, the offset in PCI config space to start - reading from. On output, the offset of the first= byte - that was not read. On error, Offset is not modif= ied. - - @param [in] Size The number of bytes to read. - - @param [out] Buffer On output, the bytes read from PCI config space = are - stored in this object. - - @retval EFI_SUCCESS Size bytes have been transferred from PCI config sp= ace - (from Offset) to Buffer, and Offset has been increm= ented - by Size. - - @return Error codes from PciIo->Pci.Read(). -**/ -STATIC -EFI_STATUS -ReadConfigSpace ( - IN EFI_PCI_IO_PROTOCOL *PciIo, - IN OUT UINT32 *Offset, - IN UINTN Size, - OUT VOID *Buffer - ) -{ - EFI_STATUS Status; - - Status =3D PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, *Offset, Size, Bu= ffer); - if (EFI_ERROR (Status)) { - return Status; - } - *Offset +=3D (UINT32)Size; - return EFI_SUCCESS; -} - - /* Traverse the PCI capabilities list of a virtio-1.0 device, and capture t= he locations of the interesting virtio-1.0 register blocks. @@ -239,57 +199,51 @@ ReadConfigSpace ( will have been updated from the PCI capabilities found. =20 - @param[in] CapabilityPtr The offset of the first capability in PCI - config space, taken from the standard PCI - device header. - @retval EFI_SUCCESS Traversal successful. =20 - @return Error codes from the ReadConfigSpace() and GetBarTy= pe() - helper functions. + @return Error codes from PciCapPciIoLib, PciCapLib, and the + GetBarType() helper function. */ STATIC EFI_STATUS ParseCapabilities ( - IN OUT VIRTIO_1_0_DEV *Device, - IN UINT8 CapabilityPtr + IN OUT VIRTIO_1_0_DEV *Device ) { - UINT32 Offset; - VIRTIO_PCI_CAP_LINK CapLink; + EFI_STATUS Status; + PCI_CAP_DEV *PciDevice; + PCI_CAP_LIST *CapList; + UINT16 VendorInstance; + PCI_CAP *VendorCap; =20 - for (Offset =3D CapabilityPtr & 0xFC; - Offset > 0; - Offset =3D CapLink.CapNext & 0xFC - ) { - EFI_STATUS Status; + Status =3D PciCapPciIoDeviceInit (Device->PciIo, &PciDevice); + if (EFI_ERROR (Status)) { + return Status; + } + Status =3D PciCapListInit (PciDevice, &CapList); + if (EFI_ERROR (Status)) { + goto UninitPciDevice; + } + + for (VendorInstance =3D 0; + !EFI_ERROR (PciCapListFindCap (CapList, PciCapNormal, + EFI_PCI_CAPABILITY_ID_VENDOR, VendorInstance, + &VendorCap)); + VendorInstance++) { UINT8 CapLen; VIRTIO_PCI_CAP VirtIoCap; VIRTIO_1_0_CONFIG *ParsedConfig; =20 - // - // Read capability identifier and link to next capability. - // - Status =3D ReadConfigSpace (Device->PciIo, &Offset, sizeof CapLink, - &CapLink); - if (EFI_ERROR (Status)) { - return Status; - } - if (CapLink.CapId !=3D 0x09) { - // - // Not a vendor-specific capability, move to the next one. - // - continue; - } - // // Big enough to accommodate a VIRTIO_PCI_CAP structure? // - Status =3D ReadConfigSpace (Device->PciIo, &Offset, sizeof CapLen, &Ca= pLen); + Status =3D PciCapRead (PciDevice, VendorCap, + OFFSET_OF (EFI_PCI_CAPABILITY_VENDOR_HDR, Length), &CapLen, + sizeof CapLen); if (EFI_ERROR (Status)) { - return Status; + goto UninitCapList; } - if (CapLen < sizeof CapLink + sizeof CapLen + sizeof VirtIoCap) { + if (CapLen < sizeof VirtIoCap) { // // Too small, move to next. // @@ -299,11 +253,11 @@ ParseCapabilities ( // // Read interesting part of capability. // - Status =3D ReadConfigSpace (Device->PciIo, &Offset, sizeof VirtIoCap, - &VirtIoCap); + Status =3D PciCapRead (PciDevice, VendorCap, 0, &VirtIoCap, sizeof Vir= tIoCap); if (EFI_ERROR (Status)) { - return Status; + goto UninitCapList; } + switch (VirtIoCap.ConfigType) { case VIRTIO_PCI_CAP_COMMON_CFG: ParsedConfig =3D &Device->CommonConfig; @@ -326,7 +280,7 @@ ParseCapabilities ( // Status =3D GetBarType (Device->PciIo, VirtIoCap.Bar, &ParsedConfig->Ba= rType); if (EFI_ERROR (Status)) { - return Status; + goto UninitCapList; } ParsedConfig->Bar =3D VirtIoCap.Bar; ParsedConfig->Offset =3D VirtIoCap.Offset; @@ -337,19 +291,18 @@ ParseCapabilities ( // This capability has an additional field called NotifyOffsetMultip= lier; // parse it too. // - if (CapLen < sizeof CapLink + sizeof CapLen + sizeof VirtIoCap + - sizeof Device->NotifyOffsetMultiplier) { + if (CapLen < sizeof VirtIoCap + sizeof Device->NotifyOffsetMultiplie= r) { // // Too small, move to next. // continue; } =20 - Status =3D ReadConfigSpace (Device->PciIo, &Offset, - sizeof Device->NotifyOffsetMultiplier, - &Device->NotifyOffsetMultiplier); + Status =3D PciCapRead (PciDevice, VendorCap, sizeof VirtIoCap, + &Device->NotifyOffsetMultiplier, + sizeof Device->NotifyOffsetMultiplier); if (EFI_ERROR (Status)) { - return Status; + goto UninitCapList; } } =20 @@ -359,7 +312,15 @@ ParseCapabilities ( ParsedConfig->Exists =3D TRUE; } =20 - return EFI_SUCCESS; + ASSERT_EFI_ERROR (Status); + +UninitCapList: + PciCapListUninit (CapList); + +UninitPciDevice: + PciCapPciIoDeviceUninit (PciDevice); + + return Status; } =20 =20 @@ -1015,7 +976,7 @@ Virtio10BindingStart ( =20 Device->VirtIo.SubSystemDeviceId =3D Pci.Hdr.DeviceId - 0x1040; =20 - Status =3D ParseCapabilities (Device, Pci.Device.CapabilityPtr); + Status =3D ParseCapabilities (Device); if (EFI_ERROR (Status)) { goto ClosePciIo; } --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel