mirror of
				https://github.com/acidanthera/audk.git
				synced 2025-10-31 03:03:46 +01:00 
			
		
		
		
	Added SpiHc DXE and SMM drivers. This code receives bus transactions from the SpiBus layer and passes them onto the SpiHcPlatformLib Platform Initialization Spec 1.7 volume 5 section 18.1.7 Bugzilla #4753 Cc: Abner Chang <abner.chang@amd.com> Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com> Signed-off-by: Brit Chesley <brit.chesley@amd.com> Reviewed-by: Abner Chang <abner.chang@amd.com>
		
			
				
	
	
		
			102 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			102 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /** @file
 | |
| 
 | |
|   SPI Host controller entry point for DXE
 | |
| 
 | |
|   Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
 | |
|   SPDX-License-Identifier: BSD-2-Clause-Patent
 | |
| 
 | |
| **/
 | |
| #include <Base.h>
 | |
| #include <Library/BaseLib.h>
 | |
| #include <Library/DebugLib.h>
 | |
| #include <Library/PcdLib.h>
 | |
| #include <Library/UefiLib.h>
 | |
| #include <Library/MemoryAllocationLib.h>
 | |
| #include <Library/UefiBootServicesTableLib.h>
 | |
| #include <Library/UefiRuntimeServicesTableLib.h>
 | |
| #include <Library/SpiHcPlatformLib.h>
 | |
| #include <Protocol/SpiHc.h>
 | |
| #include <IndustryStandard/SpiNorFlashJedecSfdp.h>
 | |
| #include "SpiHc.h"
 | |
| 
 | |
| EFI_HANDLE  mSpiHcHandle = 0;
 | |
| 
 | |
| /**
 | |
|   Entry point of the SPI Host Controller driver. Installs the EFI_SPI_HC_PROTOCOL on mSpiHcHandle.
 | |
|   Also installs the EFI_DEVICE_PATH_PROTOCOL corresponding to the SPI Host controller on the same
 | |
|   mSpiHcHandle.
 | |
| 
 | |
|   @param[in] ImageHandle  Image handle of this driver.
 | |
|   @param[in] SystemTable  Pointer to standard EFI system table.
 | |
| 
 | |
|   @retval EFI_SUCCESS       Succeed.
 | |
|   @retval EFI_OUT_RESOURCES If the system has run out of memory
 | |
| **/
 | |
| EFI_STATUS
 | |
| EFIAPI
 | |
| SpiHcProtocolEntry (
 | |
|   IN EFI_HANDLE        ImageHandle,
 | |
|   IN EFI_SYSTEM_TABLE  *SystemTable
 | |
|   )
 | |
| {
 | |
|   EFI_STATUS                Status;
 | |
|   EFI_SPI_HC_PROTOCOL       *HcProtocol;
 | |
|   EFI_DEVICE_PATH_PROTOCOL  *HcDevicePath;
 | |
| 
 | |
|   DEBUG ((DEBUG_VERBOSE, "%a - ENTRY\n", __func__));
 | |
| 
 | |
|   // Allocate the SPI Host Controller protocol
 | |
|   HcProtocol = AllocateZeroPool (sizeof (EFI_SPI_HC_PROTOCOL));
 | |
|   ASSERT (HcProtocol != NULL);
 | |
|   if (HcProtocol == NULL) {
 | |
|     return EFI_OUT_OF_RESOURCES;
 | |
|   }
 | |
| 
 | |
|   // Fill in the SPI Host Controller Protocol
 | |
|   Status = GetPlatformSpiHcDetails (
 | |
|              &HcProtocol->Attributes,
 | |
|              &HcProtocol->FrameSizeSupportMask,
 | |
|              &HcProtocol->MaximumTransferBytes
 | |
|              );
 | |
| 
 | |
|   if (EFI_ERROR (Status)) {
 | |
|     DEBUG ((DEBUG_VERBOSE, "Error, no Platform SPI HC details\n"));
 | |
|     return Status;
 | |
|   }
 | |
| 
 | |
|   HcProtocol->ChipSelect  = ChipSelect;
 | |
|   HcProtocol->Clock       = Clock;
 | |
|   HcProtocol->Transaction = Transaction;
 | |
| 
 | |
|   // Install Host Controller protocol
 | |
|   Status = gBS->InstallProtocolInterface (
 | |
|                   &mSpiHcHandle,
 | |
|                   &gEfiSpiHcProtocolGuid,
 | |
|                   EFI_NATIVE_INTERFACE,
 | |
|                   HcProtocol
 | |
|                   );
 | |
| 
 | |
|   if (EFI_ERROR (Status)) {
 | |
|     DEBUG ((DEBUG_VERBOSE, "Error installing gEfiSpiHcProtocolGuid\n"));
 | |
|     return Status;
 | |
|   }
 | |
| 
 | |
|   Status = GetSpiHcDevicePath (&HcDevicePath);
 | |
| 
 | |
|   // Install HC device path here on this handle as well
 | |
|   Status = gBS->InstallProtocolInterface (
 | |
|                   &mSpiHcHandle,
 | |
|                   &gEfiDevicePathProtocolGuid,
 | |
|                   EFI_NATIVE_INTERFACE,
 | |
|                   HcDevicePath
 | |
|                   );
 | |
| 
 | |
|   if (EFI_ERROR (Status)) {
 | |
|     DEBUG ((DEBUG_VERBOSE, "Error installing gEfiDevicePathProtocolGuid\n"));
 | |
|   }
 | |
| 
 | |
|   DEBUG ((DEBUG_VERBOSE, "%a - EXIT Status=%r\n", __func__, Status));
 | |
| 
 | |
|   return Status;
 | |
| }
 |