1 /** @file NorFlashBlockIoDxe.c
3 Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/UefiBootServicesTableLib.h>
17 #include "NorFlashDxe.h"
21 NorFlashBlkIoInitialize (
22 IN NOR_FLASH_INSTANCE
* Instance
26 EFI_STATUS Status
= EFI_SUCCESS
;
28 DEBUG((DEBUG_BLKIO
,"NorFlashBlkIoInitialize()\n"));
31 // Verify that there is a physical hardware device where we expect it to be.
34 // Read a specific CFI query that returns back "QRY"
35 // This ensures that there is really a device present there
36 SEND_NOR_COMMAND (Instance
->BaseAddress
, 0, P30_CMD_READ_CFI_QUERY
);
38 // Read CFI 'QRY' data
39 Status
= NorFlashReadCfiData (Instance
->BaseAddress
, P30_CFI_ADDR_QUERY_UNIQUE_QRY
, 3, &Reply
);
40 if (EFI_ERROR(Status
)) {
44 if (Reply
!= CFI_QRY
) {
45 DEBUG((EFI_D_ERROR
, "NorFlashBlkIoInitialize: CFI QRY=0x%x (expected 0x595251)\n", Reply
));
46 return EFI_DEVICE_ERROR
;
50 Status
= NorFlashBlockIoReset (&Instance
->BlockIoProtocol
, FALSE
);
51 if (EFI_ERROR(Status
)) {
55 Instance
->Initialized
= TRUE
;
61 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
65 NorFlashBlockIoReset (
66 IN EFI_BLOCK_IO_PROTOCOL
*This
,
67 IN BOOLEAN ExtendedVerification
70 NOR_FLASH_INSTANCE
*Instance
;
72 Instance
= INSTANCE_FROM_BLKIO_THIS(This
);
74 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoReset(MediaId=0x%x)\n", This
->Media
->MediaId
));
76 return NorFlashReset(Instance
);
80 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
84 NorFlashBlockIoReadBlocks (
85 IN EFI_BLOCK_IO_PROTOCOL
*This
,
88 IN UINTN BufferSizeInBytes
,
92 NOR_FLASH_INSTANCE
*Instance
;
95 Instance
= INSTANCE_FROM_BLKIO_THIS(This
);
97 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId
, Lba
, BufferSizeInBytes
, Buffer
));
99 if( !This
->Media
->MediaPresent
) {
100 Status
= EFI_NO_MEDIA
;
101 } else if( This
->Media
->MediaId
!= MediaId
) {
102 Status
= EFI_MEDIA_CHANGED
;
104 Status
= NorFlashReadBlocks(Instance
,Lba
,BufferSizeInBytes
,Buffer
);
111 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
115 NorFlashBlockIoWriteBlocks (
116 IN EFI_BLOCK_IO_PROTOCOL
*This
,
119 IN UINTN BufferSizeInBytes
,
123 NOR_FLASH_INSTANCE
*Instance
;
126 Instance
= INSTANCE_FROM_BLKIO_THIS(This
);
128 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId
, Lba
, BufferSizeInBytes
, Buffer
));
130 if( !This
->Media
->MediaPresent
) {
131 Status
= EFI_NO_MEDIA
;
132 } else if( This
->Media
->MediaId
!= MediaId
) {
133 Status
= EFI_MEDIA_CHANGED
;
134 } else if( This
->Media
->ReadOnly
) {
135 Status
= EFI_WRITE_PROTECTED
;
137 Status
= NorFlashWriteBlocks(Instance
,Lba
,BufferSizeInBytes
,Buffer
);
144 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
148 NorFlashBlockIoFlushBlocks (
149 IN EFI_BLOCK_IO_PROTOCOL
*This
152 // No Flush required for the NOR Flash driver
153 // because cache operations are not permitted.
155 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
157 // Nothing to do so just return without error