1 /** @file NorFlashBlockIoDxe.c
3 Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/UefiBootServicesTableLib.h>
18 #include "NorFlashDxe.h"
21 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
25 NorFlashBlockIoReset (
26 IN EFI_BLOCK_IO_PROTOCOL
*This
,
27 IN BOOLEAN ExtendedVerification
30 NOR_FLASH_INSTANCE
*Instance
;
32 Instance
= INSTANCE_FROM_BLKIO_THIS(This
);
34 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoReset(MediaId=0x%x)\n", This
->Media
->MediaId
));
36 return NorFlashReset (Instance
);
40 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
44 NorFlashBlockIoReadBlocks (
45 IN EFI_BLOCK_IO_PROTOCOL
*This
,
48 IN UINTN BufferSizeInBytes
,
52 NOR_FLASH_INSTANCE
*Instance
;
54 EFI_BLOCK_IO_MEDIA
*Media
;
57 return EFI_INVALID_PARAMETER
;
60 Instance
= INSTANCE_FROM_BLKIO_THIS(This
);
63 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId
, Lba
, BufferSizeInBytes
, Buffer
));
66 Status
= EFI_INVALID_PARAMETER
;
67 } else if (!Media
->MediaPresent
) {
68 Status
= EFI_NO_MEDIA
;
69 } else if (Media
->MediaId
!= MediaId
) {
70 Status
= EFI_MEDIA_CHANGED
;
71 } else if ((Media
->IoAlign
> 2) && (((UINTN
)Buffer
& (Media
->IoAlign
- 1)) != 0)) {
72 Status
= EFI_INVALID_PARAMETER
;
74 Status
= NorFlashReadBlocks (Instance
, Lba
, BufferSizeInBytes
, Buffer
);
81 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
85 NorFlashBlockIoWriteBlocks (
86 IN EFI_BLOCK_IO_PROTOCOL
*This
,
89 IN UINTN BufferSizeInBytes
,
93 NOR_FLASH_INSTANCE
*Instance
;
96 Instance
= INSTANCE_FROM_BLKIO_THIS(This
);
98 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId
, Lba
, BufferSizeInBytes
, Buffer
));
100 if( !This
->Media
->MediaPresent
) {
101 Status
= EFI_NO_MEDIA
;
102 } else if( This
->Media
->MediaId
!= MediaId
) {
103 Status
= EFI_MEDIA_CHANGED
;
104 } else if( This
->Media
->ReadOnly
) {
105 Status
= EFI_WRITE_PROTECTED
;
107 Status
= NorFlashWriteBlocks (Instance
,Lba
,BufferSizeInBytes
,Buffer
);
114 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
118 NorFlashBlockIoFlushBlocks (
119 IN EFI_BLOCK_IO_PROTOCOL
*This
122 // No Flush required for the NOR Flash driver
123 // because cache operations are not permitted.
125 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
127 // Nothing to do so just return without error