1 /** @file NorFlashBlockIoDxe.c
3 Copyright (c) 2010, 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/DebugLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/UefiBootServicesTableLib.h>
18 #include "NorFlashDxe.h"
22 NorFlashBlkIoInitialize (
23 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
,
40 P30_CFI_ADDR_QUERY_UNIQUE_QRY
,
44 if (EFI_ERROR(Status
)) {
48 if ( Reply
!= CFI_QRY
) {
49 DEBUG((EFI_D_ERROR
, "NorFlashBlkIoInitialize: CFI QRY=0x%x (expected 0x595251)\n", Reply
));
50 Status
= EFI_DEVICE_ERROR
;
56 Status
= NorFlashBlockIoReset( &Instance
->BlockIoProtocol
, FALSE
);
57 if (EFI_ERROR(Status
)) {
61 Instance
->Initialized
= TRUE
;
67 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
71 NorFlashBlockIoReset (
72 IN EFI_BLOCK_IO_PROTOCOL
*This
,
73 IN BOOLEAN ExtendedVerification
77 NOR_FLASH_INSTANCE
*Instance
;
79 Instance
= INSTANCE_FROM_BLKIO_THIS(This
);
81 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoReset(MediaId=0x%x)\n", This
->Media
->MediaId
));
83 Status
= NorFlashReset(Instance
);
90 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
94 NorFlashBlockIoReadBlocks (
95 IN EFI_BLOCK_IO_PROTOCOL
*This
,
98 IN UINTN BufferSizeInBytes
,
102 NOR_FLASH_INSTANCE
*Instance
;
104 Instance
= INSTANCE_FROM_BLKIO_THIS(This
);
106 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId
, Lba
, BufferSizeInBytes
, Buffer
));
108 return NorFlashReadBlocks(Instance
,Lba
,BufferSizeInBytes
,Buffer
);
112 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
116 NorFlashBlockIoWriteBlocks (
117 IN EFI_BLOCK_IO_PROTOCOL
*This
,
120 IN UINTN BufferSizeInBytes
,
124 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 return NorFlashWriteBlocks(Instance
,Lba
,BufferSizeInBytes
,Buffer
);
134 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
138 NorFlashBlockIoFlushBlocks (
139 IN EFI_BLOCK_IO_PROTOCOL
*This
142 // No Flush required for the NOR Flash driver
143 // because cache operations are not permitted.
145 DEBUG ((DEBUG_BLKIO
, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
147 // Nothing to do so just return without error