TianoCore EDK2 master
Loading...
Searching...
No Matches
SpiHcDxe.c
Go to the documentation of this file.
1
9#include <Base.h>
10#include <Library/BaseLib.h>
11#include <Library/DebugLib.h>
12#include <Library/PcdLib.h>
13#include <Library/UefiLib.h>
18#include <Protocol/SpiHc.h>
20#include "SpiHc.h"
21
22EFI_HANDLE mSpiHcHandle = 0;
23
36EFIAPI
38 IN EFI_HANDLE ImageHandle,
39 IN EFI_SYSTEM_TABLE *SystemTable
40 )
41{
42 EFI_STATUS Status;
43 EFI_SPI_HC_PROTOCOL *HcProtocol;
44 EFI_DEVICE_PATH_PROTOCOL *HcDevicePath;
45
46 DEBUG ((DEBUG_VERBOSE, "%a - ENTRY\n", __func__));
47
48 // Allocate the SPI Host Controller protocol
49 HcProtocol = AllocateZeroPool (sizeof (EFI_SPI_HC_PROTOCOL));
50 ASSERT (HcProtocol != NULL);
51 if (HcProtocol == NULL) {
52 return EFI_OUT_OF_RESOURCES;
53 }
54
55 // Fill in the SPI Host Controller Protocol
57 &HcProtocol->Attributes,
58 &HcProtocol->FrameSizeSupportMask,
59 &HcProtocol->MaximumTransferBytes
60 );
61
62 if (EFI_ERROR (Status)) {
63 DEBUG ((DEBUG_VERBOSE, "Error, no Platform SPI HC details\n"));
64 return Status;
65 }
66
67 HcProtocol->ChipSelect = ChipSelect;
68 HcProtocol->Clock = Clock;
69 HcProtocol->Transaction = Transaction;
70
71 // Install Host Controller protocol
72 Status = gBS->InstallProtocolInterface (
73 &mSpiHcHandle,
74 &gEfiSpiHcProtocolGuid,
76 HcProtocol
77 );
78
79 if (EFI_ERROR (Status)) {
80 DEBUG ((DEBUG_VERBOSE, "Error installing gEfiSpiHcProtocolGuid\n"));
81 return Status;
82 }
83
84 Status = GetSpiHcDevicePath (&HcDevicePath);
85
86 // Install HC device path here on this handle as well
87 Status = gBS->InstallProtocolInterface (
88 &mSpiHcHandle,
89 &gEfiDevicePathProtocolGuid,
91 HcDevicePath
92 );
93
94 if (EFI_ERROR (Status)) {
95 DEBUG ((DEBUG_VERBOSE, "Error installing gEfiDevicePathProtocolGuid\n"));
96 }
97
98 DEBUG ((DEBUG_VERBOSE, "%a - EXIT Status=%r\n", __func__, Status));
99
100 return Status;
101}
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI Transaction(IN CONST EFI_SPI_IO_PROTOCOL *This, IN EFI_SPI_TRANSACTION_TYPE TransactionType, IN BOOLEAN DebugTransaction, IN UINT32 ClockHz OPTIONAL, IN UINT32 BusWidth, IN UINT32 FrameSize, IN UINT32 WriteBytes, IN UINT8 *WriteBuffer, IN UINT32 ReadBytes, OUT UINT8 *ReadBuffer)
Definition: SpiBus.c:231
EFI_STATUS EFIAPI Clock(IN CONST EFI_SPI_HC_PROTOCOL *This, IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral, IN UINT32 *ClockHz)
Definition: SpiHc.c:75
EFI_STATUS EFIAPI ChipSelect(IN CONST EFI_SPI_HC_PROTOCOL *This, IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral, IN BOOLEAN PinValue)
Definition: SpiHc.c:38
EFI_STATUS EFIAPI SpiHcProtocolEntry(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: SpiHcDxe.c:37
EFI_STATUS EFIAPI GetPlatformSpiHcDetails(OUT UINT32 *Attributes, OUT UINT32 *FrameSizeSupportMask, OUT UINT32 *MaximumTransferBytes)
EFI_STATUS EFIAPI GetSpiHcDevicePath(OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
EFI_SPI_HC_PROTOCOL_TRANSACTION Transaction
Definition: SpiHc.h:197
EFI_SPI_HC_PROTOCOL_CLOCK Clock
Definition: SpiHc.h:191
UINT32 Attributes
Definition: SpiHc.h:168
UINT32 MaximumTransferBytes
Definition: SpiHc.h:180
UINT32 FrameSizeSupportMask
Definition: SpiHc.h:175
EFI_SPI_HC_PROTOCOL_CHIP_SELECT ChipSelect
Definition: SpiHc.h:185