1 /** @file NorFlashBlockIoDxe.c
3 Copyright (c) 2011-2012, 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
;
55 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
, Buffer
));
59 if( !This
->Media
->MediaPresent
) {
60 Status
= EFI_NO_MEDIA
;
61 } else if( This
->Media
->MediaId
!= MediaId
) {
62 Status
= EFI_MEDIA_CHANGED
;
64 Status
= NorFlashReadBlocks (Instance
,Lba
,BufferSizeInBytes
,Buffer
);
71 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
75 NorFlashBlockIoWriteBlocks (
76 IN EFI_BLOCK_IO_PROTOCOL
*This
,
79 IN UINTN BufferSizeInBytes
,
83 NOR_FLASH_INSTANCE
*Instance
;
86 Instance
= INSTANCE_FROM_BLKIO_THIS(This
);
88 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId
, Lba
, BufferSizeInBytes
, Buffer
));
90 if( !This
->Media
->MediaPresent
) {
91 Status
= EFI_NO_MEDIA
;
92 } else if( This
->Media
->MediaId
!= MediaId
) {
93 Status
= EFI_MEDIA_CHANGED
;
94 } else if( This
->Media
->ReadOnly
) {
95 Status
= EFI_WRITE_PROTECTED
;
97 Status
= NorFlashWriteBlocks (Instance
,Lba
,BufferSizeInBytes
,Buffer
);
104 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
108 NorFlashBlockIoFlushBlocks (
109 IN EFI_BLOCK_IO_PROTOCOL
*This
112 // No Flush required for the NOR Flash driver
113 // because cache operations are not permitted.
115 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
117 // Nothing to do so just return without error