From nobody Fri Mar 29 15:38:48 2024 Delivered-To: importer@patchew.org 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+92017+1787277+3901457@groups.io; helo=mail02.groups.io; 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+92017+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1659373218; cv=none; d=zohomail.com; s=zohoarc; b=SAvJZkbDh2WzpdjlIRD/qB2bpFl7oRM0qRW1OqDIr1DzbA6Es9WdU8ES1es7kAu7zlUnRG544SOEz1POAyrDIGoF+5+E02ecF761/UNfbRYgkvLEMoeYUPs4iXIZvYZHX7W+Yb7P706ZYVRaBmUvSwxoAOFrcmgCD0ft1CEM4eI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659373218; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=KUu/UB747x0/C916Yis6sLlrq6c6y8Nh5of4BEbQa9s=; b=JZX6tj/xTw/iDvheIFhjS4l5coTdJvJat2eo9KMF/ZjpNR2HAl0v4wnGdwq2HZbz7ca+nbl2+IBkcTscHFiqLDZ6PozfyGaF2uCIuT34IdYD0HVg0dZWDPWwgiZh8FgBX9KIKlv9vIfi143u9/PJKj3sXYLfFboxjk6MsE6SxWM= ARC-Authentication-Results: i=1; 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+92017+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16593732185571001.4127577761598; Mon, 1 Aug 2022 10:00:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8YnwYY1788612xgo2GAugjIa; Mon, 01 Aug 2022 10:00:18 -0700 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web09.27610.1659373215312920184 for ; Mon, 01 Aug 2022 10:00:17 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10426"; a="353200207" X-IronPort-AV: E=Sophos;i="5.93,208,1654585200"; d="scan'208";a="353200207" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Aug 2022 10:00:17 -0700 X-IronPort-AV: E=Sophos;i="5.93,208,1654585200"; d="scan'208";a="661230457" X-Received: from mmamona-mobl.ger.corp.intel.com (HELO mczajkow-MOBL.ger.corp.intel.com) ([10.252.60.244]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Aug 2022 10:00:15 -0700 From: "Maciej Czajkowski" To: devel@edk2.groups.io Cc: Hao A Wu , Ray Ni , Liming Gao Subject: [edk2-devel] [PATCH v3 2/2] MdeModulePkg/AhciPei: Use PCI_DEVICE_PPI to manage AHCI device Date: Mon, 1 Aug 2022 19:00:09 +0200 Message-Id: <20220801170009.2113-3-maciej.czajkowski@intel.com> In-Reply-To: <20220801170009.2113-1-maciej.czajkowski@intel.com> References: <20220801170009.2113-1-maciej.czajkowski@intel.com> MIME-Version: 1.0 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,maciej.czajkowski@intel.com X-Gm-Message-State: 1i3gAQM1ONb09GxjroHWUFfNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1659373218; bh=lBIN90vSH92L+7IwWcd7AjYm7R+H0TXDJk/xXSFhtyI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=UXNmGYXZ7SV6yXz0MopxtkwnnB3cWJUfOrKTCMK+GmdTRO5mM7QpgGXC3Nlbr22ioM0 eR2sp52Wc+W4iVIMuZETYQhbUamoy6wuC0saJlbLuTfEMz4Z3MuCSPIV/o6Tv9KiMZ4OS UCgGUh7QGtBiC20v2sTH1Elb3KKVoHuUaJw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1659373219826100007 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3907 This change modifies AhciPei library to allow usage both EDKII_PCI_DEVICE_P= PI and EDKII_PEI_ATA_AHCI_HOST_CONTROLLER_PPI to manage ATA HDD working under AHCI mode. Cc: Hao A Wu Cc: Ray Ni Cc: Liming Gao Signed-off-by: Maciej Czajkowski Reviewed-by: Hao A Wu --- Notes: v2 changes: - added missing function descriptions - moved controller initialization from PCI_DEVICE_PPI to seperate funci= ton in order to reduce code duplication - added DevicePathLib BASE instance to the MdeModulePkg.dec to allow PE= IMs to consume it =20 v3 changes: - removed redundant locate PPI calls (if already installed, NotifyPpi e= xecutes callback) - aligned enabling HC device from PCI_DEVICE_PPI with flow from AtaAtap= iPassThru DXE driver - corrected function descriptions MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c | 505 +++++++++++++------- MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c | 44 -- MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h | 57 ++- MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf | 5 +- MdeModulePkg/MdeModulePkg.dsc | 1 + 5 files changed, 390 insertions(+), 222 deletions(-) diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c b/MdeModulePkg/Bus/Ata/= AhciPei/AhciPei.c index 208b7e9a3606..98dd732a4023 100644 --- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c +++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.c @@ -9,6 +9,9 @@ **/ =20 #include "AhciPei.h" +#include +#include +#include =20 EFI_PEI_PPI_DESCRIPTOR mAhciAtaPassThruPpiListTemplate =3D { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), @@ -40,6 +43,18 @@ EFI_PEI_NOTIFY_DESCRIPTOR mAhciEndOfPeiNotifyListTempla= te =3D { AhciPeimEndOfPei }; =20 +EFI_PEI_NOTIFY_DESCRIPTOR mAtaAhciHostControllerNotify =3D { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINA= TE_LIST), + &gEdkiiPeiAtaAhciHostControllerPpiGuid, + AtaAhciHostControllerPpiInstallationCallback +}; + +EFI_PEI_NOTIFY_DESCRIPTOR mPciDevicePpiNotify =3D { + (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINA= TE_LIST), + &gEdkiiPeiPciDevicePpiGuid, + AtaAhciPciDevicePpiInstallationCallback +}; + /** Free the DMA resources allocated by an ATA AHCI controller. =20 @@ -111,33 +126,30 @@ AhciPeimEndOfPei ( } =20 /** - Entry point of the PEIM. + Initialize and install PrivateData PPIs. =20 - @param[in] FileHandle Handle of the file being invoked. - @param[in] PeiServices Describes the list of possible PEI Services. - - @retval EFI_SUCCESS PPI successfully installed. + @param[in] MmioBase MMIO base address of specific AHCI contro= ller + @param[in] DevicePath A pointer to the EFI_DEVICE_PATH_PROTOCOL + structure. + @param[in] DevicePathLength Length of the device path. =20 + @retval EFI_SUCCESS AHCI controller initialized and PPIs installed + @retval others Failed to initialize AHCI controller **/ EFI_STATUS -EFIAPI -AtaAhciPeimEntry ( - IN EFI_PEI_FILE_HANDLE FileHandle, - IN CONST EFI_PEI_SERVICES **PeiServices +AtaAhciInitPrivateData ( + IN UINTN MmioBase, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, + IN UINTN DevicePathLength ) { - EFI_STATUS Status; - EFI_BOOT_MODE BootMode; - EDKII_ATA_AHCI_HOST_CONTROLLER_PPI *AhciHcPpi; - UINT8 Controller; - UINTN MmioBase; - UINTN DevicePathLength; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - UINT32 PortBitMap; - PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private; - UINT8 NumberOfPorts; + EFI_STATUS Status; + UINT32 PortBitMap; + UINT8 NumberOfPorts; + PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private; + EFI_BOOT_MODE BootMode; =20 - DEBUG ((DEBUG_INFO, "%a: Enters.\n", __FUNCTION__)); + DEBUG ((DEBUG_INFO, "Initializing private data for ATA\n")); =20 // // Get the current boot mode. @@ -149,19 +161,149 @@ AtaAhciPeimEntry ( } =20 // - // Locate the ATA AHCI host controller PPI. - // - Status =3D PeiServicesLocatePpi ( - &gEdkiiPeiAtaAhciHostControllerPpiGuid, - 0, - NULL, - (VOID **)&AhciHcPpi - ); + // Check validity of the device path of the ATA AHCI controller. + // + Status =3D AhciIsHcDevicePathValid (DevicePath, DevicePathLength); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: The device path is invalid.\n", + __FUNCTION__ + )); + return Status; + } + + // + // For S3 resume performance consideration, not all ports on an ATA AHCI + // controller will be enumerated/initialized. The driver consumes the + // content within S3StorageDeviceInitList LockBox to get the ports that + // will be enumerated/initialized during S3 resume. + // + if (BootMode =3D=3D BOOT_ON_S3_RESUME) { + NumberOfPorts =3D AhciS3GetEumeratePorts (DevicePath, DevicePathLength= , &PortBitMap); + if (NumberOfPorts =3D=3D 0) { + return EFI_SUCCESS; + } + } else { + PortBitMap =3D MAX_UINT32; + } + + // + // Memory allocation for controller private data. + // + Private =3D AllocateZeroPool (sizeof (PEI_AHCI_CONTROLLER_PRIVATE_DATA)); + if (Private =3D=3D NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Fail to allocate private data.\n", + __FUNCTION__ + )); + return EFI_OUT_OF_RESOURCES; + } + + // + // Initialize controller private data. + // + Private->Signature =3D AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATURE; + Private->MmioBase =3D MmioBase; + Private->DevicePathLength =3D DevicePathLength; + Private->DevicePath =3D DevicePath; + Private->PortBitMap =3D PortBitMap; + InitializeListHead (&Private->DeviceList); + + Status =3D AhciModeInitialization (Private); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Failed to locate AtaAhciHostControllerPpi.\n= ", __FUNCTION__)); - return EFI_UNSUPPORTED; + return Status; + } + + Private->AtaPassThruMode.Attributes =3D EFI_ATA_PASS_THRU_ATTRIBUTES_PHY= SICAL | + EFI_ATA_PASS_THRU_ATTRIBUTES_LOGIC= AL; + Private->AtaPassThruMode.IoAlign =3D sizeof (UINTN); + Private->AtaPassThruPpi.Revision =3D EDKII_PEI_ATA_PASS_THRU_PPI_RE= VISION; + Private->AtaPassThruPpi.Mode =3D &Private->AtaPassThruMode; + Private->AtaPassThruPpi.PassThru =3D AhciAtaPassThruPassThru; + Private->AtaPassThruPpi.GetNextPort =3D AhciAtaPassThruGetNextPort; + Private->AtaPassThruPpi.GetNextDevice =3D AhciAtaPassThruGetNextDevice; + Private->AtaPassThruPpi.GetDevicePath =3D AhciAtaPassThruGetDevicePath; + CopyMem ( + &Private->AtaPassThruPpiList, + &mAhciAtaPassThruPpiListTemplate, + sizeof (EFI_PEI_PPI_DESCRIPTOR) + ); + Private->AtaPassThruPpiList.Ppi =3D &Private->AtaPassThruPpi; + PeiServicesInstallPpi (&Private->AtaPassThruPpiList); + + Private->BlkIoPpi.GetNumberOfBlockDevices =3D AhciBlockIoGetDeviceNo; + Private->BlkIoPpi.GetBlockDeviceMediaInfo =3D AhciBlockIoGetMediaInfo; + Private->BlkIoPpi.ReadBlocks =3D AhciBlockIoReadBlocks; + CopyMem ( + &Private->BlkIoPpiList, + &mAhciBlkIoPpiListTemplate, + sizeof (EFI_PEI_PPI_DESCRIPTOR) + ); + Private->BlkIoPpiList.Ppi =3D &Private->BlkIoPpi; + PeiServicesInstallPpi (&Private->BlkIoPpiList); + + Private->BlkIo2Ppi.Revision =3D EFI_PEI_RECOVERY_BLOCK_IO= 2_PPI_REVISION; + Private->BlkIo2Ppi.GetNumberOfBlockDevices =3D AhciBlockIoGetDeviceNo2; + Private->BlkIo2Ppi.GetBlockDeviceMediaInfo =3D AhciBlockIoGetMediaInfo2; + Private->BlkIo2Ppi.ReadBlocks =3D AhciBlockIoReadBlocks2; + CopyMem ( + &Private->BlkIo2PpiList, + &mAhciBlkIo2PpiListTemplate, + sizeof (EFI_PEI_PPI_DESCRIPTOR) + ); + Private->BlkIo2PpiList.Ppi =3D &Private->BlkIo2Ppi; + PeiServicesInstallPpi (&Private->BlkIo2PpiList); + + if (Private->TrustComputingDevices !=3D 0) { + DEBUG (( + DEBUG_INFO, + "%a: Security Security Command PPI will be produced.\n", + __FUNCTION__ + )); + Private->StorageSecurityPpi.Revision =3D EDKII_STORAGE_SECUR= ITY_PPI_REVISION; + Private->StorageSecurityPpi.GetNumberofDevices =3D AhciStorageSecurity= GetDeviceNo; + Private->StorageSecurityPpi.GetDevicePath =3D AhciStorageSecurity= GetDevicePath; + Private->StorageSecurityPpi.ReceiveData =3D AhciStorageSecurity= ReceiveData; + Private->StorageSecurityPpi.SendData =3D AhciStorageSecurity= SendData; + CopyMem ( + &Private->StorageSecurityPpiList, + &mAhciStorageSecurityPpiListTemplate, + sizeof (EFI_PEI_PPI_DESCRIPTOR) + ); + Private->StorageSecurityPpiList.Ppi =3D &Private->StorageSecurityPpi; + PeiServicesInstallPpi (&Private->StorageSecurityPpiList); } =20 + CopyMem ( + &Private->EndOfPeiNotifyList, + &mAhciEndOfPeiNotifyListTemplate, + sizeof (EFI_PEI_NOTIFY_DESCRIPTOR) + ); + PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList); + + return EFI_SUCCESS; +} + +/** + Initialize AHCI controller from EDKII_ATA_AHCI_HOST_CONTROLLER_PPI insta= nce. + + @param[in] AhciHcPpi Pointer to the AHCI Host Controller PPI instance. + + @retval EFI_SUCCESS PPI successfully installed. +**/ +EFI_STATUS +AtaAhciInitPrivateDataFromHostControllerPpi ( + IN EDKII_ATA_AHCI_HOST_CONTROLLER_PPI *AhciHcPpi + ) +{ + UINT8 Controller; + UINTN MmioBase; + UINTN DevicePathLength; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_STATUS Status; + Controller =3D 0; MmioBase =3D 0; while (TRUE) { @@ -193,65 +335,7 @@ AtaAhciPeimEntry ( return Status; } =20 - // - // Check validity of the device path of the ATA AHCI controller. - // - Status =3D AhciIsHcDevicePathValid (DevicePath, DevicePathLength); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "%a: The device path is invalid for Controller %d.\n", - __FUNCTION__, - Controller - )); - Controller++; - continue; - } - - // - // For S3 resume performance consideration, not all ports on an ATA AH= CI - // controller will be enumerated/initialized. The driver consumes the - // content within S3StorageDeviceInitList LockBox to get the ports that - // will be enumerated/initialized during S3 resume. - // - if (BootMode =3D=3D BOOT_ON_S3_RESUME) { - NumberOfPorts =3D AhciS3GetEumeratePorts (DevicePath, DevicePathLeng= th, &PortBitMap); - if (NumberOfPorts =3D=3D 0) { - // - // No ports need to be enumerated for this controller. - // - Controller++; - continue; - } - } else { - PortBitMap =3D MAX_UINT32; - } - - // - // Memory allocation for controller private data. - // - Private =3D AllocateZeroPool (sizeof (PEI_AHCI_CONTROLLER_PRIVATE_DATA= )); - if (Private =3D=3D NULL) { - DEBUG (( - DEBUG_ERROR, - "%a: Fail to allocate private data for Controller %d.\n", - __FUNCTION__, - Controller - )); - return EFI_OUT_OF_RESOURCES; - } - - // - // Initialize controller private data. - // - Private->Signature =3D AHCI_PEI_CONTROLLER_PRIVATE_DATA_SIGNATU= RE; - Private->MmioBase =3D MmioBase; - Private->DevicePathLength =3D DevicePathLength; - Private->DevicePath =3D DevicePath; - Private->PortBitMap =3D PortBitMap; - InitializeListHead (&Private->DeviceList); - - Status =3D AhciModeInitialization (Private); + Status =3D AtaAhciInitPrivateData (MmioBase, DevicePath, DevicePathLen= gth); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -260,86 +344,187 @@ AtaAhciPeimEntry ( Controller, Status )); - Controller++; - continue; - } - - Private->AtaPassThruMode.Attributes =3D EFI_ATA_PASS_THRU_ATTRIBUTES_P= HYSICAL | - EFI_ATA_PASS_THRU_ATTRIBUTES_LOG= ICAL; - Private->AtaPassThruMode.IoAlign =3D sizeof (UINTN); - Private->AtaPassThruPpi.Revision =3D EDKII_PEI_ATA_PASS_THRU_PPI_= REVISION; - Private->AtaPassThruPpi.Mode =3D &Private->AtaPassThruMode; - Private->AtaPassThruPpi.PassThru =3D AhciAtaPassThruPassThru; - Private->AtaPassThruPpi.GetNextPort =3D AhciAtaPassThruGetNextPort; - Private->AtaPassThruPpi.GetNextDevice =3D AhciAtaPassThruGetNextDevice; - Private->AtaPassThruPpi.GetDevicePath =3D AhciAtaPassThruGetDevicePath; - CopyMem ( - &Private->AtaPassThruPpiList, - &mAhciAtaPassThruPpiListTemplate, - sizeof (EFI_PEI_PPI_DESCRIPTOR) - ); - Private->AtaPassThruPpiList.Ppi =3D &Private->AtaPassThruPpi; - PeiServicesInstallPpi (&Private->AtaPassThruPpiList); - - Private->BlkIoPpi.GetNumberOfBlockDevices =3D AhciBlockIoGetDeviceNo; - Private->BlkIoPpi.GetBlockDeviceMediaInfo =3D AhciBlockIoGetMediaInfo; - Private->BlkIoPpi.ReadBlocks =3D AhciBlockIoReadBlocks; - CopyMem ( - &Private->BlkIoPpiList, - &mAhciBlkIoPpiListTemplate, - sizeof (EFI_PEI_PPI_DESCRIPTOR) - ); - Private->BlkIoPpiList.Ppi =3D &Private->BlkIoPpi; - PeiServicesInstallPpi (&Private->BlkIoPpiList); - - Private->BlkIo2Ppi.Revision =3D EFI_PEI_RECOVERY_BLOCK_= IO2_PPI_REVISION; - Private->BlkIo2Ppi.GetNumberOfBlockDevices =3D AhciBlockIoGetDeviceNo2; - Private->BlkIo2Ppi.GetBlockDeviceMediaInfo =3D AhciBlockIoGetMediaInfo= 2; - Private->BlkIo2Ppi.ReadBlocks =3D AhciBlockIoReadBlocks2; - CopyMem ( - &Private->BlkIo2PpiList, - &mAhciBlkIo2PpiListTemplate, - sizeof (EFI_PEI_PPI_DESCRIPTOR) - ); - Private->BlkIo2PpiList.Ppi =3D &Private->BlkIo2Ppi; - PeiServicesInstallPpi (&Private->BlkIo2PpiList); - - if (Private->TrustComputingDevices !=3D 0) { + } else { DEBUG (( DEBUG_INFO, - "%a: Security Security Command PPI will be produced for Controller= %d.\n", + "%a: Controller %d has been successfully initialized.\n", __FUNCTION__, Controller )); - Private->StorageSecurityPpi.Revision =3D EDKII_STORAGE_SEC= URITY_PPI_REVISION; - Private->StorageSecurityPpi.GetNumberofDevices =3D AhciStorageSecuri= tyGetDeviceNo; - Private->StorageSecurityPpi.GetDevicePath =3D AhciStorageSecuri= tyGetDevicePath; - Private->StorageSecurityPpi.ReceiveData =3D AhciStorageSecuri= tyReceiveData; - Private->StorageSecurityPpi.SendData =3D AhciStorageSecuri= tySendData; - CopyMem ( - &Private->StorageSecurityPpiList, - &mAhciStorageSecurityPpiListTemplate, - sizeof (EFI_PEI_PPI_DESCRIPTOR) - ); - Private->StorageSecurityPpiList.Ppi =3D &Private->StorageSecurityPpi; - PeiServicesInstallPpi (&Private->StorageSecurityPpiList); } =20 - CopyMem ( - &Private->EndOfPeiNotifyList, - &mAhciEndOfPeiNotifyListTemplate, - sizeof (EFI_PEI_NOTIFY_DESCRIPTOR) - ); - PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList); - - DEBUG (( - DEBUG_INFO, - "%a: Controller %d has been successfully initialized.\n", - __FUNCTION__, - Controller - )); Controller++; } =20 return EFI_SUCCESS; } + +/** + Callback for EDKII_ATA_AHCI_HOST_CONTROLLER_PPI installation. + + @param[in] PeiServices Pointer to PEI Services Table. + @param[in] NotifyDescriptor Pointer to the descriptor for the Notific= ation + event that caused this function to execut= e. + @param[in] Ppi Pointer to the PPI data associated with t= his function. + + @retval EFI_SUCCESS The function completes successfully + @retval Others Cannot initialize AHCI controller from gi= ven EDKII_ATA_AHCI_HOST_CONTROLLER_PPI + +**/ +EFI_STATUS +EFIAPI +AtaAhciHostControllerPpiInstallationCallback ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + EDKII_ATA_AHCI_HOST_CONTROLLER_PPI *AhciHcPpi; + + if (Ppi =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + AhciHcPpi =3D (EDKII_ATA_AHCI_HOST_CONTROLLER_PPI *)Ppi; + + return AtaAhciInitPrivateDataFromHostControllerPpi (AhciHcPpi); +} + +/** + Initialize AHCI controller from fiven PCI_DEVICE_PPI. + + @param[in] PciDevice Pointer to the PCI Device PPI instance. + + @retval EFI_SUCCESS The function completes successfully + @retval Others Cannot initialize AHCI controller for given dev= ice +**/ +EFI_STATUS +AtaAhciInitPrivateDataFromPciDevice ( + EDKII_PCI_DEVICE_PPI *PciDevice + ) +{ + EFI_STATUS Status; + PCI_TYPE00 PciData; + UINTN MmioBase; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + UINTN DevicePathLength; + UINT64 EnabledPciAttributes; + + // + // Now further check the PCI header: Base Class (offset 0x0B) and + // Sub Class (offset 0x0A). This controller should be an SATA controller + // + Status =3D PciDevice->PciIo.Pci.Read ( + &PciDevice->PciIo, + EfiPciIoWidthUint8, + PCI_CLASSCODE_OFFSET, + sizeof (PciData.Hdr.ClassCode), + PciData.Hdr.ClassCode + ); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + if (!IS_PCI_IDE (&PciData) && !IS_PCI_SATADPA (&PciData)) { + return EFI_UNSUPPORTED; + } + + Status =3D PciDevice->PciIo.Attributes ( + &PciDevice->PciIo, + EfiPciIoAttributeOperationSupported, + 0, + &EnabledPciAttributes + ); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } else { + EnabledPciAttributes &=3D (UINT64)EFI_PCI_DEVICE_ENABLE; + Status =3D PciDevice->PciIo.Attributes ( + &PciDevice->PciIo, + EfiPciIoAttributeOperationE= nable, + EnabledPciAttributes, + NULL + ); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + } + + Status =3D PciDevice->PciIo.Pci.Read ( + &PciDevice->PciIo, + EfiPciIoWidthUint32, + 0x24, + sizeof (UINTN), + &MmioBase + ); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + DevicePathLength =3D GetDevicePathSize (PciDevice->DevicePath); + DevicePath =3D PciDevice->DevicePath; + + Status =3D AtaAhciInitPrivateData (MmioBase, DevicePath, DevicePathLengt= h); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_INFO, + "%a: Failed to init controller, with Status - %r\n", + __FUNCTION__, + Status + )); + } + + return EFI_SUCCESS; +} + +/** + Callback for EDKII_PCI_DEVICE_PPI installation. + + @param[in] PeiServices Pointer to PEI Services Table. + @param[in] NotifyDescriptor Pointer to the descriptor for the Notific= ation + event that caused this function to execut= e. + @param[in] Ppi Pointer to the PPI data associated with t= his function. + + @retval EFI_SUCCESS The function completes successfully + @retval Others Cannot initialize AHCI controller from gi= ven PCI_DEVICE_PPI + +**/ +EFI_STATUS +EFIAPI +AtaAhciPciDevicePpiInstallationCallback ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ) +{ + EDKII_PCI_DEVICE_PPI *PciDevice; + + PciDevice =3D (EDKII_PCI_DEVICE_PPI *)Ppi; + + return AtaAhciInitPrivateDataFromPciDevice (PciDevice); +} + +/** + Entry point of the PEIM. + + @param[in] FileHandle Handle of the file being invoked. + @param[in] PeiServices Describes the list of possible PEI Services. + + @retval EFI_SUCCESS PPI successfully installed. + +**/ +EFI_STATUS +EFIAPI +AtaAhciPeimEntry ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + DEBUG ((DEBUG_INFO, "%a: Enters.\n", __FUNCTION__)); + + PeiServicesNotifyPpi (&mAtaAhciHostControllerNotify); + + PeiServicesNotifyPpi (&mPciDevicePpiNotify); + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c b/MdeModulePkg/Bus/A= ta/AhciPei/DevicePath.c index 81f8743d40d8..cf0955929dde 100644 --- a/MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c +++ b/MdeModulePkg/Bus/Ata/AhciPei/DevicePath.c @@ -38,50 +38,6 @@ EFI_DEVICE_PATH_PROTOCOL mAhciEndDevicePathNodeTemplate= =3D { } }; =20 -/** - Returns the 16-bit Length field of a device path node. - - Returns the 16-bit Length field of the device path node specified by Nod= e. - Node is not required to be aligned on a 16-bit boundary, so it is recomm= ended - that a function such as ReadUnaligned16() be used to extract the content= s of - the Length field. - - If Node is NULL, then ASSERT(). - - @param Node A pointer to a device path node data structure. - - @return The 16-bit Length field of the device path node specified by Nod= e. - -**/ -UINTN -DevicePathNodeLength ( - IN CONST VOID *Node - ) -{ - ASSERT (Node !=3D NULL); - return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))-= >Length[0]); -} - -/** - Returns a pointer to the next node in a device path. - - If Node is NULL, then ASSERT(). - - @param Node A pointer to a device path node data structure. - - @return a pointer to the device path node that follows the device path n= ode - specified by Node. - -**/ -EFI_DEVICE_PATH_PROTOCOL * -NextDevicePathNode ( - IN CONST VOID *Node - ) -{ - ASSERT (Node !=3D NULL); - return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLeng= th (Node)); -} - /** Get the size of the current device path instance. =20 diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h b/MdeModulePkg/Bus/Ata/= AhciPei/AhciPei.h index 43ad4639bd77..4aed1cb7ad8a 100644 --- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h +++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h @@ -29,6 +29,7 @@ #include #include #include +#include =20 // // Structure forward declarations @@ -354,6 +355,46 @@ extern UINT32 mMaxTransferBlockNumber[2]; // Internal functions // =20 +/** + Callback for EDKII_ATA_AHCI_HOST_CONTROLLER_PPI installation. + + @param[in] PeiServices Pointer to PEI Services Table. + @param[in] NotifyDescriptor Pointer to the descriptor for the Notific= ation + event that caused this function to execut= e. + @param[in] Ppi Pointer to the PPI data associated with t= his function. + + @retval EFI_SUCCESS The function completes successfully + @retval Others Cannot initialize AHCI controller from gi= ven EDKII_ATA_AHCI_HOST_CONTROLLER_PPI + +**/ +EFI_STATUS +EFIAPI +AtaAhciHostControllerPpiInstallationCallback ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ); + +/** + Callback for EDKII_PCI_DEVICE_PPI installation. + + @param[in] PeiServices Pointer to PEI Services Table. + @param[in] NotifyDescriptor Pointer to the descriptor for the Notific= ation + event that caused this function to execut= e. + @param[in] Ppi Pointer to the PPI data associated with t= his function. + + @retval EFI_SUCCESS The function completes successfully + @retval Others Cannot initialize AHCI controller from gi= ven PCI_DEVICE_PPI + +**/ +EFI_STATUS +EFIAPI +AtaAhciPciDevicePpiInstallationCallback ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *Ppi + ); + /** Allocates pages that are suitable for an OperationBusMasterCommonBuffer = or OperationBusMasterCommonBuffer64 mapping. @@ -631,22 +672,6 @@ TrustTransferAtaDevice ( OUT UINTN *TransferLengthOut ); =20 -/** - Returns a pointer to the next node in a device path. - - If Node is NULL, then ASSERT(). - - @param Node A pointer to a device path node data structure. - - @return a pointer to the device path node that follows the device path n= ode - specified by Node. - -**/ -EFI_DEVICE_PATH_PROTOCOL * -NextDevicePathNode ( - IN CONST VOID *Node - ); - /** Get the size of the current device path instance. =20 diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf b/MdeModulePkg/Bus/At= a/AhciPei/AhciPei.inf index 912ff7a8ba4f..788660b33299 100644 --- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf +++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.inf @@ -50,11 +50,13 @@ [LibraryClasses] TimerLib LockBoxLib PeimEntryPoint + DevicePathLib =20 [Ppis] gEdkiiPeiAtaAhciHostControllerPpiGuid ## CONSUMES gEdkiiIoMmuPpiGuid ## CONSUMES gEfiEndOfPeiSignalPpiGuid ## CONSUMES + gEdkiiPeiPciDevicePpiGuid ## CONSUMES gEdkiiPeiAtaPassThruPpiGuid ## SOMETIMES_PRODUCES gEfiPeiVirtualBlockIoPpiGuid ## SOMETIMES_PRODUCES gEfiPeiVirtualBlockIo2PpiGuid ## SOMETIMES_PRODUCES @@ -65,8 +67,7 @@ [Guids] =20 [Depex] gEfiPeiMemoryDiscoveredPpiGuid AND - gEfiPeiMasterBootModePpiGuid AND - gEdkiiPeiAtaAhciHostControllerPpiGuid + gEfiPeiMasterBootModePpiGuid =20 [UserExtensions.TianoCore."ExtraFiles"] AhciPeiExtra.uni diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 90a0a7ec4a7c..45a8ec84ad69 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -117,6 +117,7 @@ [LibraryClasses.common.PEIM] MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAlloc= ationLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExt= ractGuidedSectionLib.inf LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibBase.inf =20 [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf --=20 2.27.0.windows.1 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydz= ial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-31= 6 | Kapital zakladowy 200.000 PLN. Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata= i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wi= adomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiek= olwiek przegladanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the s= ole use of the intended recipient(s). If you are not the intended recipient= , please contact the sender and delete all copies; any review or distributi= on by others is strictly prohibited. -=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 (#92017): https://edk2.groups.io/g/devel/message/92017 Mute This Topic: https://groups.io/mt/92752850/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-