From nobody Wed Dec 25 02:30:26 2024 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 Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1509082428035487.4942379400701; Thu, 26 Oct 2017 22:33:48 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C551C2034A88B; Thu, 26 Oct 2017 22:29:59 -0700 (PDT) Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by ml01.01.org (Postfix) with ESMTP id ABF662034A888 for ; Thu, 26 Oct 2017 22:29:57 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7FC4A1529; Thu, 26 Oct 2017 22:33:44 -0700 (PDT) Received: from usa.arm.com (dbox2.austin.arm.com [10.118.34.10]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2D8933F24A; Thu, 26 Oct 2017 22:33:44 -0700 (PDT) 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=217.140.101.70; helo=foss.arm.com; envelope-from=daniil.egranov@arm.com; receiver=edk2-devel@lists.01.org From: Daniil Egranov To: edk2-devel@lists.01.org Date: Fri, 27 Oct 2017 00:33:23 -0500 Message-Id: <20171027053326.48815-2-daniil.egranov@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171027053326.48815-1-daniil.egranov@arm.com> References: <20171027053326.48815-1-daniil.egranov@arm.com> Subject: [edk2] [PATCH 1/4] Drivers/SataSiI3132Dxe: Fixed PCI IO read and write operations X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org 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" The ATA pass through read should use PCI IO bus master write operation and ATA pass through write should use PCI IO bus master read operation as the read and write operations executed from the bus master's point of view. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Daniil Egranov Reviewed-by: Ard Biesheuvel --- EmbeddedPkg/Drivers/SataSiI3132Dxe/SiI3132AtaPassThru.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SiI3132AtaPassThru.c b/Embe= ddedPkg/Drivers/SataSiI3132Dxe/SiI3132AtaPassThru.c index 2fb5fd68db..a938563ebd 100644 --- a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SiI3132AtaPassThru.c +++ b/EmbeddedPkg/Drivers/SataSiI3132Dxe/SiI3132AtaPassThru.c @@ -104,7 +104,7 @@ SiI3132AtaPassThruCommand ( } =20 Status =3D PciIo->Map ( - PciIo, EfiPciIoOperationBusMasterRead, + PciIo, EfiPciIoOperationBusMasterWrite, Packet->InDataBuffer, &InDataBufferLength, &PhysInDataBuffe= r, &PciAllocMapping ); if (EFI_ERROR (Status)) { @@ -139,7 +139,7 @@ SiI3132AtaPassThruCommand ( OutDataBufferLength =3D Packet->OutTransferLength * SataDevice->BlockS= ize; =20 Status =3D PciIo->Map ( - PciIo, EfiPciIoOperationBusMasterWrite, + PciIo, EfiPciIoOperationBusMasterRead, Packet->OutDataBuffer, &OutDataBufferLength, &PhysOutDataBu= ffer, &PciAllocMapping ); if (EFI_ERROR (Status)) { --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Wed Dec 25 02:30:26 2024 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 Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1509082430651553.5069233380004; Thu, 26 Oct 2017 22:33:50 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0E5EE2034A88E; Thu, 26 Oct 2017 22:30:00 -0700 (PDT) Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by ml01.01.org (Postfix) with ESMTP id C8F532034A877 for ; Thu, 26 Oct 2017 22:29:58 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9097F15BE; Thu, 26 Oct 2017 22:33:45 -0700 (PDT) Received: from usa.arm.com (dbox2.austin.arm.com [10.118.34.10]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 351E13F24A; Thu, 26 Oct 2017 22:33:45 -0700 (PDT) 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=217.140.101.70; helo=foss.arm.com; envelope-from=daniil.egranov@arm.com; receiver=edk2-devel@lists.01.org From: Daniil Egranov To: edk2-devel@lists.01.org Date: Fri, 27 Oct 2017 00:33:24 -0500 Message-Id: <20171027053326.48815-3-daniil.egranov@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171027053326.48815-1-daniil.egranov@arm.com> References: <20171027053326.48815-1-daniil.egranov@arm.com> Subject: [edk2] [PATCH 2/4] Drivers/SataSiI3132Dxe: Allow 64-bit DMA transfer X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org 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" Set a PCI IO attribute allowing 64-bit DMA transfer. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Daniil Egranov Reviewed-by: Ard Biesheuvel --- EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c b/EmbeddedPkg= /Drivers/SataSiI3132Dxe/SataSiI3132.c index f4946552a0..c1760fdc1b 100644 --- a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c +++ b/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c @@ -384,7 +384,7 @@ SataSiI3132DriverBindingStart ( &Supports ); if (!EFI_ERROR (Status)) { - Supports &=3D EFI_PCI_DEVICE_ENABLE; + Supports &=3D EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_DUAL_ADDR= ESS_CYCLE; Status =3D PciIo->Attributes ( PciIo, EfiPciIoAttributeOperationEnable, --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Wed Dec 25 02:30:26 2024 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 Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1509082433466682.651664716871; Thu, 26 Oct 2017 22:33:53 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 48F162034A892; Thu, 26 Oct 2017 22:30:02 -0700 (PDT) Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by ml01.01.org (Postfix) with ESMTP id 90B1F2034A88A for ; Thu, 26 Oct 2017 22:29:59 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 786071650; Thu, 26 Oct 2017 22:33:46 -0700 (PDT) Received: from usa.arm.com (dbox2.austin.arm.com [10.118.34.10]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 264EF3F24A; Thu, 26 Oct 2017 22:33:46 -0700 (PDT) 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=217.140.101.70; helo=foss.arm.com; envelope-from=daniil.egranov@arm.com; receiver=edk2-devel@lists.01.org From: Daniil Egranov To: edk2-devel@lists.01.org Date: Fri, 27 Oct 2017 00:33:25 -0500 Message-Id: <20171027053326.48815-4-daniil.egranov@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171027053326.48815-1-daniil.egranov@arm.com> References: <20171027053326.48815-1-daniil.egranov@arm.com> Subject: [edk2] [PATCH 3/4] Drivers/SataSiI3132Dxe: Enable multi-controller support X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org 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" Saved controller specific data into the driver's information structure. Removed global variable indicating the driver's status and added check for the driver's status based on the available protocol. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Daniil Egranov --- EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c b/EmbeddedPkg= /Drivers/SataSiI3132Dxe/SataSiI3132.c index c1760fdc1b..50253b9160 100644 --- a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c +++ b/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c @@ -309,8 +309,6 @@ ON_EXIT: return Status; } =20 -BOOLEAN mbStarted =3D FALSE; - /** Starting the Pci SATA Driver. =20 @@ -342,9 +340,18 @@ SataSiI3132DriverBindingStart ( =20 SATA_TRACE ("SataSiI3132DriverBindingStart()"); =20 - //TODO: Find a nicer way to do it ! - if (mbStarted) { - return EFI_SUCCESS; // Don't restart me ! + Status =3D gBS->OpenProtocol ( + Controller, + &gEfiAtaPassThruProtocolGuid, + NULL, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + + if (!EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverBindingStart: driver already started"); + return Status; } =20 // @@ -426,6 +433,8 @@ SataSiI3132DriverBindingStart ( return Status; } =20 + SataSiI3132Instance->OriginalPciAttributes =3D OriginalPciAttributes; + // Initialize SiI3132 Sata Controller Status =3D SataSiI3132Initialization (SataSiI3132Instance); if (EFI_ERROR (Status)) { @@ -458,8 +467,6 @@ SataSiI3132DriverBindingStart ( goto UNINSTALL_USBHC; }*/ =20 - mbStarted =3D TRUE; - SATA_TRACE ("SataSiI3132DriverBindingStart() Success!"); return EFI_SUCCESS; =20 --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Wed Dec 25 02:30:26 2024 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 Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1509082436214525.6969466341789; Thu, 26 Oct 2017 22:33:56 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8A9832034A895; Thu, 26 Oct 2017 22:30:02 -0700 (PDT) Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by ml01.01.org (Postfix) with ESMTP id 87AE621CEB120 for ; Thu, 26 Oct 2017 22:30:00 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6E59D1529; Thu, 26 Oct 2017 22:33:47 -0700 (PDT) Received: from usa.arm.com (dbox2.austin.arm.com [10.118.34.10]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1BC883F24A; Thu, 26 Oct 2017 22:33:47 -0700 (PDT) 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=217.140.101.70; helo=foss.arm.com; envelope-from=daniil.egranov@arm.com; receiver=edk2-devel@lists.01.org From: Daniil Egranov To: edk2-devel@lists.01.org Date: Fri, 27 Oct 2017 00:33:26 -0500 Message-Id: <20171027053326.48815-5-daniil.egranov@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171027053326.48815-1-daniil.egranov@arm.com> References: <20171027053326.48815-1-daniil.egranov@arm.com> Subject: [edk2] [PATCH 4/4] Drivers/SataSiI3132Dxe: Fixed startup and shutdown procedures X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org 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" Corrected memory allocation during startup. Added driver stop procedure and exit boot event handler. Added driver memory and protocols cleanup procedures. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Daniil Egranov --- EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c | 281 ++++++++++++++++++-= ---- EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.h | 17 ++ 2 files changed, 236 insertions(+), 62 deletions(-) diff --git a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c b/EmbeddedPkg= /Drivers/SataSiI3132Dxe/SataSiI3132.c index 50253b9160..063086c956 100644 --- a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c +++ b/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.c @@ -89,20 +89,26 @@ SataSiI3132Constructor ( { SATA_SI3132_INSTANCE *Instance; EFI_ATA_PASS_THRU_MODE *AtaPassThruMode; + EFI_STATUS Status; =20 if (!SataSiI3132Instance) { return EFI_INVALID_PARAMETER; } =20 - Instance =3D (SATA_SI3132_INSTANCE*)AllocateZeroPool (sizeof (SATA_SI313= 2_INSTANCE)); - if (Instance =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; + Status =3D gBS->AllocatePool (EfiBootServicesData, sizeof (SATA_SI3132_I= NSTANCE), (VOID **)&Instance); + if (EFI_ERROR (Status)) { + return Status; } + gBS->SetMem (Instance, sizeof (SATA_SI3132_INSTANCE), 0); =20 Instance->Signature =3D SATA_SII3132_SIGNATURE; Instance->PciIo =3D PciIo; =20 - AtaPassThruMode =3D (EFI_ATA_PASS_THRU_MODE*)AllocatePool (sizeof (EFI_A= TA_PASS_THRU_MODE)); + Status =3D gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_ATA_PASS_= THRU_MODE), (VOID **)&AtaPassThruMode); + if (EFI_ERROR (Status)) { + return Status; + } + AtaPassThruMode->Attributes =3D EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL | = EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL; AtaPassThruMode->IoAlign =3D 0x1000; =20 @@ -200,7 +206,10 @@ SataSiI3132PortInitialization ( } =20 // Create Device - Device =3D (SATA_SI3132_DEVICE*)AllocatePool (sizeof (SAT= A_SI3132_DEVICE)); + Status =3D gBS->AllocatePool (EfiBootServicesData, sizeof (SATA_SI31= 32_DEVICE), (VOID **)&Device); + if (EFI_ERROR (Status)) { + return Status; + } Device->Index =3D Port->Index; //TODO: Could need to be fixed wh= en SATA Port Multiplier support Device->Port =3D Port; Device->BlockSize =3D 0; @@ -310,6 +319,118 @@ ON_EXIT: } =20 /** + Free memory allocated by the driver. + + @param SataSiI3132Instance pointer to the driver's data structure. + +**/ +STATIC +VOID +SataSiI3132DriverFreeMemory ( + IN SATA_SI3132_INSTANCE* SataSiI3132Instance + ) +{ + UINTN PortIndex; + SATA_SI3132_PORT *Port; + SATA_SI3132_DEVICE *Device; + LIST_ENTRY *Node; + EFI_STATUS Status; + UINTN NumberOfBytes; + + if (SataSiI3132Instance =3D=3D NULL) { + return; + } + + for (PortIndex =3D 0; PortIndex < SATA_SII3132_MAXPORT; PortIndex++) { + Port =3D &(SataSiI3132Instance->Ports[PortIndex]); + if (Port !=3D NULL) { + + //Free Device memory on each port + Node =3D Port->Devices.ForwardLink; + while (Node !=3D &Port->Devices) { + Device =3D (SATA_SI3132_DEVICE*)Node; + Node =3D Node->ForwardLink; + RemoveEntryList (&Device->Link); + gBS->FreePool (Device); + } + + //Unmap and deallocate PCI IO memory for each port + if (Port->PciAllocMappingPRB !=3D NULL) { + Status =3D SataSiI3132Instance->PciIo->Unmap (SataSiI3132Instance-= >PciIo, + Port->PciAllocMappingP= RB); + if (EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverFreeMemory: unable to unmap memory= "); + } + } + + if (Port->HostPRB !=3D 0) { + NumberOfBytes =3D sizeof (SATA_SI3132_PRB); + Status =3D SataSiI3132Instance->PciIo->FreeBuffer (SataSiI3132Inst= ance->PciIo, + EFI_SIZE_TO_PAGES= (NumberOfBytes), + Port->HostPRB); + if (EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverFreeMemory: unable to free memory"= ); + } + } + } + } + + if (SataSiI3132Instance->AtaPassThruProtocol.Mode !=3D NULL) { + gBS->FreePool (SataSiI3132Instance->AtaPassThruProtocol.Mode); + } +} + +/** + Uninstall and close protocols used by the driver. + + @param SataSiI3132Instance pointer to the driver's data structure. + +**/ +STATIC +VOID +SataSiI3132DriverCloseProtocols ( + IN SATA_SI3132_INSTANCE* SataSiI3132Instance + ) +{ + EFI_STATUS Status; + + if (SataSiI3132Instance =3D=3D NULL) { + return; + } + + // Uninstall ATA Pass-Through Protocol + Status =3D gBS->UninstallProtocolInterface (SataSiI3132Instance->Control= ler, + &gEfiAtaPassThruProtocolGuid, + &SataSiI3132Instance->AtaPassThruProtoc= ol); + if (EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverFreeMemory: unable to uninstall AtaPassT= hruProtocol"); + } + + if (SataSiI3132Instance->PciIo !=3D NULL) { + if (SataSiI3132Instance->OriginalPciAttributesValid) { + // Restore original PCI attributes + Status =3D SataSiI3132Instance->PciIo->Attributes (SataSiI3132Instan= ce->PciIo, + EfiPciIoAttributeOperationSe= t, + SataSiI3132Instance->Origina= lPciAttributes, + NULL); + if (EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverFreeMemory: unable to restore PCI at= tributes"); + } + } + + // Close PCI IO Protocol + Status =3D gBS->CloseProtocol (SataSiI3132Instance->Controller, + &gEfiPciIoProtocolGuid, + SataSiI3132Instance->SataDriver->DriverBindingHand= le, + SataSiI3132Instance->Controller); + if (EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverFreeMemory: unable to close PCI IO pro= tocol"); + } + } + +} + +/** Starting the Pci SATA Driver. =20 @param This Protocol instance pointer. @@ -333,8 +454,6 @@ SataSiI3132DriverBindingStart ( EFI_STATUS Status; EFI_PCI_IO_PROTOCOL *PciIo; UINT64 Supports; - UINT64 OriginalPciAttributes; - BOOLEAN PciAttributesSaved; UINT32 PciID; SATA_SI3132_INSTANCE *SataSiI3132Instance =3D NULL; =20 @@ -369,7 +488,22 @@ SataSiI3132DriverBindingStart ( return Status; } =20 - PciAttributesSaved =3D FALSE; + // Create SiI3132 Sata Instance + Status =3D SataSiI3132Constructor (PciIo, &SataSiI3132Instance); + if (EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverBindingStart: failed to allocate driver = structure"); + gBS->CloseProtocol ( + Controller, + &gEfiPciIoProtocolGuid, + This->DriverBindingHandle, + Controller + ); + return Status; + } + + SataSiI3132Instance->Controller =3D Controller; + SataSiI3132Instance->SataDriver =3D This; + // // Save original PCI attributes // @@ -377,12 +511,13 @@ SataSiI3132DriverBindingStart ( PciIo, EfiPciIoAttributeOperationGet, 0, - &OriginalPciAttributes + &SataSiI3132Instance->OriginalPciAttributes ); if (EFI_ERROR (Status)) { - goto CLOSE_PCIIO; + goto QUIT_ERROR; } - PciAttributesSaved =3D TRUE; + + SataSiI3132Instance->OriginalPciAttributesValid =3D TRUE; =20 Status =3D PciIo->Attributes ( PciIo, @@ -401,7 +536,7 @@ SataSiI3132DriverBindingStart ( } if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "SataSiI3132DriverBindingStart: failed to enable = controller\n")); - goto CLOSE_PCIIO; + goto QUIT_ERROR; } =20 // @@ -416,7 +551,7 @@ SataSiI3132DriverBindingStart ( ); if (EFI_ERROR (Status)) { Status =3D EFI_UNSUPPORTED; - goto CLOSE_PCIIO; + goto QUIT_ERROR; } =20 // @@ -424,21 +559,13 @@ SataSiI3132DriverBindingStart ( // if (PciID !=3D ((SATA_SII3132_DEVICE_ID << 16) | SATA_SII3132_VENDOR_ID)= ) { Status =3D EFI_UNSUPPORTED; - goto CLOSE_PCIIO; + goto QUIT_ERROR; } =20 - // Create SiI3132 Sata Instance - Status =3D SataSiI3132Constructor (PciIo, &SataSiI3132Instance); - if (EFI_ERROR (Status)) { - return Status; - } - - SataSiI3132Instance->OriginalPciAttributes =3D OriginalPciAttributes; - // Initialize SiI3132 Sata Controller Status =3D SataSiI3132Initialization (SataSiI3132Instance); if (EFI_ERROR (Status)) { - return Status; + goto QUIT_ERROR; } =20 // Install Ata Pass Thru Protocol @@ -449,49 +576,21 @@ SataSiI3132DriverBindingStart ( &(SataSiI3132Instance->AtaPassThruProtocol) ); if (EFI_ERROR (Status)) { - goto FREE_POOL; + goto QUIT_ERROR; } =20 -/* // - // Create event to stop the HC when exit boot service. - // - Status =3D gBS->CreateEventEx ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - EhcExitBootService, - Ehc, - &gEfiEventExitBootServicesGuid, - &Ehc->ExitBootServiceEvent - ); - if (EFI_ERROR (Status)) { - goto UNINSTALL_USBHC; - }*/ + Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK, + &SataSiI3132DriverExitBoot, SataSiI3132Instance, &Sata= SiI3132Instance->ExitBootEvent); =20 - SATA_TRACE ("SataSiI3132DriverBindingStart() Success!"); - return EFI_SUCCESS; - -FREE_POOL: - //TODO: Free SATA Instance - -CLOSE_PCIIO: - if (PciAttributesSaved) { - // - // Restore original PCI attributes - // - PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationSet, - OriginalPciAttributes, - NULL - ); + if (!EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverBindingStart() Success!"); + return EFI_SUCCESS; } =20 - gBS->CloseProtocol ( - Controller, - &gEfiPciIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); +QUIT_ERROR: + SataSiI3132DriverCloseProtocols (SataSiI3132Instance); + SataSiI3132DriverFreeMemory (SataSiI3132Instance); + gBS->FreePool (SataSiI3132Instance); =20 return Status; } @@ -518,8 +617,66 @@ SataSiI3132DriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer ) { + SATA_SI3132_INSTANCE *SataSiI3132Instance; + EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThruProtocol; + EFI_STATUS Status; + SATA_TRACE ("SataSiI3132DriverBindingStop()"); - return EFI_UNSUPPORTED; + + Status =3D gBS->OpenProtocol ( + Controller, + &gEfiAtaPassThruProtocolGuid, + (VOID **)&AtaPassThruProtocol, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + + if (EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverBindingStop: driver is not started"); + return Status; + } + + SataSiI3132Instance =3D INSTANCE_FROM_ATAPASSTHRU_THIS (AtaPassThruProto= col); + + gBS->CloseEvent (SataSiI3132Instance->ExitBootEvent); + + SataSiI3132DriverCloseProtocols (SataSiI3132Instance); + SataSiI3132DriverFreeMemory (SataSiI3132Instance); + gBS->FreePool (SataSiI3132Instance); + + return EFI_SUCCESS; +} + +/** + Process exit boot event. + + @param [in] Event Event id. + @param [in] Context Driver context. + +**/ +VOID +EFIAPI +SataSiI3132DriverExitBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + SATA_SI3132_INSTANCE *SataSiI3132Instance; + EFI_STATUS Status; + + if (Context =3D=3D NULL) { + SATA_TRACE ("SataSiI3132DriverExitBoot: invalid Context parameter"); + } else { + SataSiI3132Instance =3D (SATA_SI3132_INSTANCE*)Context; + Status =3D SataSiI3132Instance->SataDriver->Stop (SataSiI3132Instance-= >SataDriver, + SataSiI3132Instance->C= ontroller, + 0, + NULL); + if (EFI_ERROR (Status)) { + SATA_TRACE ("SataSiI3132DriverExitBoot: driver stop failed"); + } + } } =20 /** diff --git a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.h b/EmbeddedPkg= /Drivers/SataSiI3132Dxe/SataSiI3132.h index a7bc956b19..ab4510b97b 100644 --- a/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.h +++ b/EmbeddedPkg/Drivers/SataSiI3132Dxe/SataSiI3132.h @@ -144,6 +144,16 @@ typedef struct _SATA_SI3132_INSTANCE { EFI_ATA_PASS_THRU_PROTOCOL AtaPassThruProtocol; =20 EFI_PCI_IO_PROTOCOL *PciIo; + + EFI_DRIVER_BINDING_PROTOCOL *SataDriver; + + EFI_HANDLE Controller; + + UINT64 OriginalPciAttributes; + + BOOLEAN OriginalPciAttributesValid; + + EFI_EVENT ExitBootEvent; } SATA_SI3132_INSTANCE; =20 #define SATA_SII3132_SIGNATURE SIGNATURE_32('s', 'i', '3', '2= ') @@ -211,6 +221,13 @@ SataSiI3132DriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer ); =20 +VOID +EFIAPI +SataSiI3132DriverExitBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ); + EFI_STATUS SiI3132AtaPassThruCommand ( IN SATA_SI3132_INSTANCE *pSataSiI3132Instance, IN SATA_SI3132_PORT *pSataPort, --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel