1 /** @file NorFlashBlockIoDxe.c
3 Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/BaseMemoryLib.h>
10 #include <Library/UefiBootServicesTableLib.h>
15 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
19 NorFlashBlockIoReset (
20 IN EFI_BLOCK_IO_PROTOCOL
*This
,
21 IN BOOLEAN ExtendedVerification
24 NOR_FLASH_INSTANCE
*Instance
;
26 Instance
= INSTANCE_FROM_BLKIO_THIS (This
);
28 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoReset(MediaId=0x%x)\n", This
->Media
->MediaId
));
30 return NorFlashReset (Instance
);
34 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
38 NorFlashBlockIoReadBlocks (
39 IN EFI_BLOCK_IO_PROTOCOL
*This
,
42 IN UINTN BufferSizeInBytes
,
46 NOR_FLASH_INSTANCE
*Instance
;
48 EFI_BLOCK_IO_MEDIA
*Media
;
51 return EFI_INVALID_PARAMETER
;
54 Instance
= INSTANCE_FROM_BLKIO_THIS (This
);
57 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId
, Lba
, BufferSizeInBytes
, BufferSizeInBytes
, Buffer
));
60 Status
= EFI_INVALID_PARAMETER
;
61 } else if (!Media
->MediaPresent
) {
62 Status
= EFI_NO_MEDIA
;
63 } else if (Media
->MediaId
!= MediaId
) {
64 Status
= EFI_MEDIA_CHANGED
;
65 } else if ((Media
->IoAlign
> 2) && (((UINTN
)Buffer
& (Media
->IoAlign
- 1)) != 0)) {
66 Status
= EFI_INVALID_PARAMETER
;
68 Status
= NorFlashReadBlocks (Instance
, Lba
, BufferSizeInBytes
, Buffer
);
75 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
79 NorFlashBlockIoWriteBlocks (
80 IN EFI_BLOCK_IO_PROTOCOL
*This
,
83 IN UINTN BufferSizeInBytes
,
87 NOR_FLASH_INSTANCE
*Instance
;
90 Instance
= INSTANCE_FROM_BLKIO_THIS (This
);
92 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes, BufferPtr @ 0x%08x)\n", MediaId
, Lba
, BufferSizeInBytes
, Buffer
));
94 if ( !This
->Media
->MediaPresent
) {
95 Status
= EFI_NO_MEDIA
;
96 } else if ( This
->Media
->MediaId
!= MediaId
) {
97 Status
= EFI_MEDIA_CHANGED
;
98 } else if ( This
->Media
->ReadOnly
) {
99 Status
= EFI_WRITE_PROTECTED
;
101 Status
= NorFlashWriteBlocks (Instance
, Lba
, BufferSizeInBytes
, Buffer
);
108 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
112 NorFlashBlockIoFlushBlocks (
113 IN EFI_BLOCK_IO_PROTOCOL
*This
116 // No Flush required for the NOR Flash driver
117 // because cache operations are not permitted.
119 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
121 // Nothing to do so just return without error