From: Laszlo Ersek Date: Tue, 22 Sep 2015 11:18:27 +0000 (+0000) Subject: OvmfPkg: SataControllerDxe: enable IO / mem access and DMA when binding X-Git-Tag: edk2-stable201903~8829 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=bcab71413407e61c144994925556725dd65eede9 OvmfPkg: SataControllerDxe: enable IO / mem access and DMA when binding When we bind the SATA controller in SataControllerStart(), we read the NP ("Number of Ports") bitfield from the CAP ("HBA Capabilities") register of the controller. (See the AHCI 1.3.1 spec.) This register is memory mapped. If we'd like to access it, we must at least enable memory space access for the device. In addition, Feng Tian recommended enabling Bus Master DMA in . We also enable IO space access for completeness. Further, because we change the PCI attributes of the device with the above when binding it, we must also restore its original PCI attributes when unbinding it. See the Driver Writer's Guide for UEFI 2.3.1 v1.01, section 18.3 "PCI drivers" | 18.3.2 "Start() and Stop()". (OvmfPkg's copy of SataControllerDxe differs from the same in DuetPkg because Duet inherits a pre-configured SATA controller from the BIOS, as explained by Feng. Technically, DuetPkg's SataControllerDxe could also apply the technique seen in this patch.) Cc: Alexander Graf Cc: Reza Jelveh Cc: Jordan Justen Cc: Hannes Reinecke Cc: Gabriel L. Somlo Cc: Feng Tian Suggested-by: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Feng Tian Tested-by: Gabriel Somlo Reviewed-by: Jordan Justen git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18528 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/OvmfPkg/SataControllerDxe/SataController.c b/OvmfPkg/SataControllerDxe/SataController.c index 5e7e23b261..ba21717cad 100644 --- a/OvmfPkg/SataControllerDxe/SataController.c +++ b/OvmfPkg/SataControllerDxe/SataController.c @@ -390,6 +390,7 @@ SataControllerStart ( { EFI_STATUS Status; EFI_PCI_IO_PROTOCOL *PciIo; + UINT64 OriginalPciAttributes; PCI_TYPE00 PciData; EFI_SATA_CONTROLLER_PRIVATE_DATA *SataPrivateData; UINT32 Data32; @@ -414,13 +415,28 @@ SataControllerStart ( goto Bail; } + // + // Save original PCI attributes, and enable IO space access, memory space + // access, and Bus Master (DMA). + // + Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationGet, 0, + &OriginalPciAttributes); + if (EFI_ERROR (Status)) { + goto ClosePciIo; + } + Status = PciIo->Attributes (PciIo, EfiPciIoAttributeOperationEnable, + EFI_PCI_DEVICE_ENABLE, NULL); + if (EFI_ERROR (Status)) { + goto ClosePciIo; + } + // // Allocate Sata Private Data structure // SataPrivateData = AllocateZeroPool (sizeof (EFI_SATA_CONTROLLER_PRIVATE_DATA)); if (SataPrivateData == NULL) { Status = EFI_OUT_OF_RESOURCES; - goto ClosePciIo; + goto RestorePciAttributes; } // @@ -428,6 +444,7 @@ SataControllerStart ( // SataPrivateData->Signature = SATA_CONTROLLER_SIGNATURE; SataPrivateData->PciIo = PciIo; + SataPrivateData->OriginalPciAttributes = OriginalPciAttributes; SataPrivateData->IdeInit.GetChannelInfo = IdeInitGetChannelInfo; SataPrivateData->IdeInit.NotifyPhase = IdeInitNotifyPhase; SataPrivateData->IdeInit.SubmitData = IdeInitSubmitData; @@ -512,6 +529,10 @@ FreeDisqualifiedModes: FreeSataPrivateData: FreePool (SataPrivateData); +RestorePciAttributes: + PciIo->Attributes (PciIo, EfiPciIoAttributeOperationSet, + OriginalPciAttributes, NULL); + ClosePciIo: gBS->CloseProtocol ( Controller, @@ -594,6 +615,16 @@ SataControllerStop ( FreePool (SataPrivateData); } + // + // Restore original PCI attributes + // + SataPrivateData->PciIo->Attributes ( + SataPrivateData->PciIo, + EfiPciIoAttributeOperationSet, + SataPrivateData->OriginalPciAttributes, + NULL + ); + // // Close protocols opened by Sata Controller driver // diff --git a/OvmfPkg/SataControllerDxe/SataController.h b/OvmfPkg/SataControllerDxe/SataController.h index a6c6c168df..e5b719e76d 100644 --- a/OvmfPkg/SataControllerDxe/SataController.h +++ b/OvmfPkg/SataControllerDxe/SataController.h @@ -85,6 +85,11 @@ typedef struct _EFI_SATA_CONTROLLER_PRIVATE_DATA { // EFI_PCI_IO_PROTOCOL *PciIo; + // + // Original PCI attributes + // + UINT64 OriginalPciAttributes; + // // The number of devices that are supported by this channel //