From nobody Fri May 17 06:07:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+86624+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1644609251058998.4381364399757; Fri, 11 Feb 2022 11:54:11 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jheHYY1788612xHDbxdd8C8s; Fri, 11 Feb 2022 11:54:11 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.53]) by mx.groups.io with SMTP id smtpd.web12.686.1644609250520571214 for ; Fri, 11 Feb 2022 11:54:10 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NPpPV7V1dP5+hAEfhz0dLEGDaqpcjVsHUz4m5E5KtDDypmqhXf2Ei9zPV1UvR+6cb1Ax1mvssAwPpcc7/1jROgLSGCYqzxl6YB/SKNet2W1TvLmIzamyhziDgyDOokKhBKDhTT8tFKYD0m+x7c2BOBGlR0pZfrMyiKVnuKS+objEgRZsY5Ym7IOqKSF2IZSOj8tO8xePnbuGlfoag9XLlszothzZ1Hy+nG96Osq93PAsOeGIhnF3z59U7eL1we+SGIYWWDn0yhsnAYj6Kjh28QGtG9z90SPulmiSPKOSgkyRpIcgQUFdhUsBIJooJv1Baq5uesBe/xpS0D8G4QlWBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1yTzhfUL8a7JU44e1M+6SJcB7g8n2OEgoqfFBDkYy9A=; b=LUjXnMyEPxD9wdZCVN+OXO1mS03KsAdgZmW6/mzffgrqDm9EWRHIczOYRKwTIxvcqmPaOaiwFW37Tr8DG/LAF2OMosz0GxkTe3RsTO6DIJLBO82gK8iGLbKs3sDS7X4k6G8egwM1rRp9ZKlv3cB/pe3vaFQWPNfZn4ieyoyChcVmt8sEOnx6uDn4XlLm40QJYobPM02Pf7CiyYOO2ysVKyKFw2wpbcJoh5FaX2jBRCm2pwqyRuerCThgsndpyhj8oQYjaM9PznSsugsl98E7R8BhgnmQpaUR253gQwdiYPtjgUPvQjBYf/J0reKvqV3KF72c/7fcoTXf3nUTVpL/Zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none X-Received: from CO1PR15CA0113.namprd15.prod.outlook.com (2603:10b6:101:21::33) by CY4PR12MB1206.namprd12.prod.outlook.com (2603:10b6:903:3b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.17; Fri, 11 Feb 2022 19:54:09 +0000 X-Received: from CO1NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:101:21:cafe::b2) by CO1PR15CA0113.outlook.office365.com (2603:10b6:101:21::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.13 via Frontend Transport; Fri, 11 Feb 2022 19:54:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+86624+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; X-Received: from mail.nvidia.com (12.22.5.234) by CO1NAM11FT048.mail.protection.outlook.com (10.13.175.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4975.11 via Frontend Transport; Fri, 11 Feb 2022 19:54:08 +0000 X-Received: from rnnvmail203.nvidia.com (10.129.68.9) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 11 Feb 2022 19:54:08 +0000 X-Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Fri, 11 Feb 2022 11:54:07 -0800 X-Received: from build-jbrasen-20220128T084645396.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Fri, 11 Feb 2022 11:54:07 -0800 From: "Jeff Brasen via groups.io" To: CC: , , Jeff Brasen Subject: [edk2-devel] [PATCH] MdeModulePkg/NonDiscoverablePciDeviceDxe: Allow partial free Date: Fri, 11 Feb 2022 19:53:59 +0000 Message-ID: X-NVConfidentiality: public MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cdf2b3ec-db9d-4685-4928-08d9ed984463 X-MS-TrafficTypeDiagnostic: CY4PR12MB1206:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: iX67Jh0N02LumX/rm+aA6UEqfaYL46fC/moc7DY5J9mPaMXNf3LUZ7g6irHl9rQb+AfOks3P5yA+ts51La2YeB6I3Ld1SJkSBhyiKdjwoQmpALZHR6/kub0Fxlmnon2gkgAFbocs2fdW2OoO2hCq+Edw3ebAWJJvrZN2J7HUH2QKhlAuH9cCw0YgbOZWGKI4IV30UeFEAZey3Y8YJ4CH+SeSILHewhfxsL70B0fdBZuzGDYoImYwphpabYudGgbov32hiEXYG0i86losNsWs8StR5EgLBo+V5rEnM2WZM0tK7suIGp2v6Omf8vgt64tBkaxBrn3Iluok8U9pfXvU0pZS2xF4OVyfloWJmQEN87gtt45lQk9KRqmthOT2TtrRYiBSxfJtTw0+0D0RetRTimbhZvblhI/DCicmOatTTCDLFJagzNy683WBWjt/XEhbITGfr6ZAfGG2T0oEvA3GC+PqntMOWXsCZngy0Etdrb1xOMz7aNxPiKGVuwBxf36SZ/M3CM76j7/NIqYVxAtgE2F+9rSN9sRbDWrFReiWRlUA5Vo1ksk15N5csViFplKX86MkIIf3eP97EoNGdH9EgNOLe4QEn3I28z+lapbEFb7bWccEmrKoO9/zSF6w6WEIVwzZOeS8A/z2GsErTNpQ/0v3GyDCzvn13JwFYrPxnI4P3q8lKHemn0WMQyNuFCvwynpG6gGabTR4XvrRu0x/J5jIoQVHTjgY+Yw9CtiLZp4= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2022 19:54:08.6555 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cdf2b3ec-db9d-4685-4928-08d9ed984463 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[12.22.5.234];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1206 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jbrasen@nvidia.com X-Gm-Message-State: S5rPtrZbCrcL5AF5QNG3v0MSx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1644609251; bh=O6eMq8FJ+aSiE6MKExSCvZFNj8BPAvOqZKKkuxY9Blg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=irLs8ZTQXCEyblb/nrKz3Tsc0FjKXKQRSfeipQ3+e/Dw9ZawNJC2ZWe8IyqbbWV9Tgp psiJEb38W7YISRC9RCT6KG94pj2sucCie8gFQsQGUacnohL+gY4s/uYwvNYR7NPt2bMpf pmq70XNJ+KPdYdyxu620bBgkNwTs9dJ/9Io= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1644609281474100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for partial free of non cached buffers. If a request for less than the full size is requested new allocations for the remaining head and tail of the buffer are added to the list. The XHCI driver does this if the page size for the controller is >4KB. Signed-off-by: Jeff Brasen --- .../NonDiscoverablePciDeviceIo.c | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisco= verablePciDeviceIo.c index c1c5c6267c..858d953acf 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c @@ -960,12 +960,18 @@ NonCoherentPciIoFreeBuffer ( LIST_ENTRY *Entry; EFI_STATUS Status; NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION *Alloc; + NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION *AllocHead; + NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION *AllocTail; BOOLEAN Found; + UINTN StartPages; + UINTN EndPages; =20 Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO (This); =20 Found =3D FALSE; Alloc =3D NULL; + AllocHead =3D NULL; + AllocTail =3D NULL; =20 // // Find the uncached allocation list entry associated @@ -976,9 +982,13 @@ NonCoherentPciIoFreeBuffer ( Entry =3D Entry->ForwardLink) { Alloc =3D BASE_CR (Entry, NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION,= List); - if ((Alloc->HostAddress =3D=3D HostAddress) && (Alloc->NumPages =3D=3D= Pages)) { + StartPages =3D 0; + if (Alloc->HostAddress < HostAddress) { + StartPages =3D (HostAddress - Alloc->HostAddress) / EFI_PAGE_SIZE; + } + if ((Alloc->HostAddress <=3D HostAddress) && (Alloc->NumPages >=3D (Pa= ges + StartPages))) { // - // We are freeing the exact allocation we were given + // We are freeing at least part of what we were given // before by AllocateBuffer() // Found =3D TRUE; @@ -991,7 +1001,41 @@ NonCoherentPciIoFreeBuffer ( return EFI_NOT_FOUND; } =20 + EndPages =3D Alloc->NumPages - (Pages + StartPages); + + if (StartPages !=3D 0) { + AllocHead =3D AllocatePool (sizeof *AllocHead); + if (AllocHead =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + AllocHead->HostAddress =3D Alloc->HostAddress; + AllocHead->NumPages =3D StartPages; + AllocHead->Attributes =3D Alloc->Attributes; + } + + if (EndPages !=3D 0) { + AllocTail =3D AllocatePool (sizeof *AllocTail); + if (AllocTail =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + AllocTail->HostAddress =3D Alloc->HostAddress + ((Pages + StartPages) = * EFI_PAGE_SIZE); + AllocTail->NumPages =3D EndPages; + AllocTail->Attributes =3D Alloc->Attributes; + } + RemoveEntryList (&Alloc->List); + // + // Record this new sub allocations in the linked list, so we + // can restore the memory space attributes later + // + if (AllocHead !=3D NULL) { + InsertHeadList (&Dev->UncachedAllocationList, &AllocHead->List); + } + if (AllocTail !=3D NULL) { + InsertHeadList (&Dev->UncachedAllocationList, &AllocTail->List); + } =20 Status =3D gDS->SetMemorySpaceAttributes ( (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress, --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#86624): https://edk2.groups.io/g/devel/message/86624 Mute This Topic: https://groups.io/mt/89079887/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-