TianoCore EDK2 master
Loading...
Searching...
No Matches
AhciPeiBlockIo.c
Go to the documentation of this file.
1
11#include "AhciPei.h"
12
27 IN UINTN DeviceIndex
28 )
29{
30 PEI_AHCI_ATA_DEVICE_DATA *DeviceData;
31 LIST_ENTRY *Node;
32
33 if ((DeviceIndex == 0) || (DeviceIndex > Private->ActiveDevices)) {
34 return NULL;
35 }
36
37 Node = GetFirstNode (&Private->DeviceList);
38 while (!IsNull (&Private->DeviceList, Node)) {
39 DeviceData = AHCI_PEI_ATA_DEVICE_INFO_FROM_THIS (Node);
40
41 if (DeviceData->DeviceIndex == DeviceIndex) {
42 return DeviceData;
43 }
44
45 Node = GetNextNode (&Private->DeviceList, Node);
46 }
47
48 return NULL;
49}
50
69 IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData,
70 IN OUT UINT8 *Buffer,
71 IN EFI_LBA StartLba,
72 IN UINTN NumberOfBlocks
73 )
74{
75 EFI_STATUS Status;
76 UINTN MaxTransferBlockNumber;
77 UINTN TransferBlockNumber;
78 UINTN BlockSize;
79
80 //
81 // Ensure Lba48Bit is a valid boolean value
82 //
83 ASSERT ((UINTN)DeviceData->Lba48Bit < 2);
84 if ((UINTN)DeviceData->Lba48Bit >= 2) {
85 return EFI_INVALID_PARAMETER;
86 }
87
88 Status = EFI_SUCCESS;
89 MaxTransferBlockNumber = mMaxTransferBlockNumber[DeviceData->Lba48Bit];
90 BlockSize = DeviceData->Media.BlockSize;
91
92 do {
93 if (NumberOfBlocks > MaxTransferBlockNumber) {
94 TransferBlockNumber = MaxTransferBlockNumber;
95 NumberOfBlocks -= MaxTransferBlockNumber;
96 } else {
97 TransferBlockNumber = NumberOfBlocks;
98 NumberOfBlocks = 0;
99 }
100
101 DEBUG ((
102 DEBUG_BLKIO,
103 "%a: Blocking AccessAtaDevice, TransferBlockNumber = %x; StartLba = %x\n",
104 __func__,
105 TransferBlockNumber,
106 StartLba
107 ));
108
109 Status = TransferAtaDevice (
110 DeviceData,
111 Buffer,
112 StartLba,
113 (UINT32)TransferBlockNumber,
114 FALSE // Read
115 );
116 if (EFI_ERROR (Status)) {
117 return Status;
118 }
119
120 StartLba += TransferBlockNumber;
121 Buffer += TransferBlockNumber * BlockSize;
122 } while (NumberOfBlocks > 0);
123
124 return Status;
125}
126
141 IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData,
142 OUT VOID *Buffer,
143 IN EFI_LBA StartLba,
144 IN UINTN BufferSize
145 )
146{
147 EFI_STATUS Status;
148 UINTN BlockSize;
149 UINTN NumberOfBlocks;
150
151 //
152 // Check parameters.
153 //
154 if (Buffer == NULL) {
155 return EFI_INVALID_PARAMETER;
156 }
157
158 if (BufferSize == 0) {
159 return EFI_SUCCESS;
160 }
161
162 BlockSize = DeviceData->Media.BlockSize;
163 if ((BufferSize % BlockSize) != 0) {
164 return EFI_BAD_BUFFER_SIZE;
165 }
166
167 if (StartLba > DeviceData->Media.LastBlock) {
168 return EFI_INVALID_PARAMETER;
169 }
170
171 NumberOfBlocks = BufferSize / BlockSize;
172 if (NumberOfBlocks - 1 > DeviceData->Media.LastBlock - StartLba) {
173 return EFI_INVALID_PARAMETER;
174 }
175
176 //
177 // Invoke low level AtaDevice Access Routine.
178 //
179 Status = AccessAtaDevice (DeviceData, Buffer, StartLba, NumberOfBlocks);
180
181 return Status;
182}
183
201EFIAPI
203 IN EFI_PEI_SERVICES **PeiServices,
205 OUT UINTN *NumberBlockDevices
206 )
207{
209
210 if ((This == NULL) || (NumberBlockDevices == NULL)) {
211 return EFI_INVALID_PARAMETER;
212 }
213
214 Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO (This);
215 *NumberBlockDevices = Private->ActiveDevices;
216
217 return EFI_SUCCESS;
218}
219
262EFIAPI
264 IN EFI_PEI_SERVICES **PeiServices,
266 IN UINTN DeviceIndex,
267 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo
268 )
269{
271 PEI_AHCI_ATA_DEVICE_DATA *DeviceData;
272
273 if ((This == NULL) || (MediaInfo == NULL)) {
274 return EFI_INVALID_PARAMETER;
275 }
276
277 Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO (This);
278 DeviceData = SearchDeviceByIndex (Private, DeviceIndex);
279 if (DeviceData == NULL) {
280 return EFI_NOT_FOUND;
281 }
282
283 MediaInfo->DeviceType = (EFI_PEI_BLOCK_DEVICE_TYPE)EDKII_PEI_BLOCK_DEVICE_TYPE_ATA_HARD_DISK;
284 MediaInfo->MediaPresent = TRUE;
285 MediaInfo->LastBlock = (UINTN)DeviceData->Media.LastBlock;
286 MediaInfo->BlockSize = DeviceData->Media.BlockSize;
287
288 return EFI_SUCCESS;
289}
290
326EFIAPI
328 IN EFI_PEI_SERVICES **PeiServices,
330 IN UINTN DeviceIndex,
331 IN EFI_PEI_LBA StartLBA,
332 IN UINTN BufferSize,
333 OUT VOID *Buffer
334 )
335{
337 PEI_AHCI_ATA_DEVICE_DATA *DeviceData;
338
339 if (This == NULL) {
340 return EFI_INVALID_PARAMETER;
341 }
342
343 Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO (This);
344 DeviceData = SearchDeviceByIndex (Private, DeviceIndex);
345 if (DeviceData == NULL) {
346 return EFI_NOT_FOUND;
347 }
348
349 return AhciRead (DeviceData, Buffer, StartLBA, BufferSize);
350}
351
369EFIAPI
371 IN EFI_PEI_SERVICES **PeiServices,
373 OUT UINTN *NumberBlockDevices
374 )
375{
377
378 if ((This == NULL) || (NumberBlockDevices == NULL)) {
379 return EFI_INVALID_PARAMETER;
380 }
381
382 Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO2 (This);
383 *NumberBlockDevices = Private->ActiveDevices;
384
385 return EFI_SUCCESS;
386}
387
430EFIAPI
432 IN EFI_PEI_SERVICES **PeiServices,
434 IN UINTN DeviceIndex,
436 )
437{
439 PEI_AHCI_ATA_DEVICE_DATA *DeviceData;
440
441 if ((This == NULL) || (MediaInfo == NULL)) {
442 return EFI_INVALID_PARAMETER;
443 }
444
445 Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO2 (This);
446 DeviceData = SearchDeviceByIndex (Private, DeviceIndex);
447 if (DeviceData == NULL) {
448 return EFI_NOT_FOUND;
449 }
450
451 CopyMem (
452 MediaInfo,
453 &DeviceData->Media,
455 );
456
457 return EFI_SUCCESS;
458}
459
495EFIAPI
497 IN EFI_PEI_SERVICES **PeiServices,
499 IN UINTN DeviceIndex,
500 IN EFI_PEI_LBA StartLBA,
501 IN UINTN BufferSize,
502 OUT VOID *Buffer
503 )
504{
506
507 if (This == NULL) {
508 return EFI_INVALID_PARAMETER;
509 }
510
511 Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_BLKIO2 (This);
512 return AhciBlockIoReadBlocks (
513 PeiServices,
514 &Private->BlkIoPpi,
515 DeviceIndex,
516 StartLBA,
517 BufferSize,
518 Buffer
519 );
520}
UINT64 UINTN
EFI_STATUS TransferAtaDevice(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, IN OUT VOID *Buffer, IN EFI_LBA StartLba, IN UINT32 TransferLength, IN BOOLEAN IsWrite)
Definition: AhciMode.c:1924
EFI_STATUS EFIAPI AhciBlockIoGetDeviceNo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS AhciRead(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, OUT VOID *Buffer, IN EFI_LBA StartLba, IN UINTN BufferSize)
EFI_STATUS EFIAPI AhciBlockIoReadBlocks(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
PEI_AHCI_ATA_DEVICE_DATA * SearchDeviceByIndex(IN PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private, IN UINTN DeviceIndex)
EFI_STATUS EFIAPI AhciBlockIoGetMediaInfo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo)
EFI_STATUS AccessAtaDevice(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, IN OUT UINT8 *Buffer, IN EFI_LBA StartLba, IN UINTN NumberOfBlocks)
EFI_STATUS EFIAPI AhciBlockIoGetDeviceNo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, OUT UINTN *NumberBlockDevices)
EFI_STATUS EFIAPI AhciBlockIoGetMediaInfo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo)
EFI_STATUS EFIAPI AhciBlockIoReadBlocks2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:443
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:333
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_PEI_BLOCK_DEVICE_TYPE
Definition: BlockIo.h:46
UINT64 EFI_PEI_LBA
Definition: BlockIo.h:41
UINT64 EFI_LBA
Definition: UefiBaseType.h:45
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_PEI_LBA LastBlock
Definition: BlockIo2.h:64