]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
ArmPlatformPkg/NorFlashDxe: Move NorFlash driver from ArmVExpressPkg to ArmPlatformPkg
[mirror_edk2.git] / ArmPlatformPkg / Drivers / NorFlashDxe / NorFlashBlockIoDxe.c
1 /** @file NorFlashBlockIoDxe.c
2
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
8
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.
11
12 **/
13
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/UefiBootServicesTableLib.h>
16
17 #include "NorFlashDxe.h"
18
19 EFI_STATUS
20 EFIAPI
21 NorFlashBlkIoInitialize (
22 IN NOR_FLASH_INSTANCE* Instance
23 )
24 {
25 UINT32 Reply;
26 EFI_STATUS Status = EFI_SUCCESS;
27
28 DEBUG((DEBUG_BLKIO,"NorFlashBlkIoInitialize()\n"));
29
30 //
31 // Verify that there is a physical hardware device where we expect it to be.
32 //
33
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);
37
38 // Read CFI 'QRY' data
39 Status = NorFlashReadCfiData (Instance->BaseAddress, P30_CFI_ADDR_QUERY_UNIQUE_QRY, 3, &Reply);
40 if (EFI_ERROR(Status)) {
41 return Status;
42 }
43
44 if (Reply != CFI_QRY) {
45 DEBUG((EFI_D_ERROR, "NorFlashBlkIoInitialize: CFI QRY=0x%x (expected 0x595251)\n", Reply));
46 return EFI_DEVICE_ERROR;
47 }
48
49 // Reset the device
50 Status = NorFlashBlockIoReset (&Instance->BlockIoProtocol, FALSE);
51 if (EFI_ERROR(Status)) {
52 return Status;
53 }
54
55 Instance->Initialized = TRUE;
56 return EFI_SUCCESS;
57 }
58
59
60 //
61 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
62 //
63 EFI_STATUS
64 EFIAPI
65 NorFlashBlockIoReset (
66 IN EFI_BLOCK_IO_PROTOCOL *This,
67 IN BOOLEAN ExtendedVerification
68 )
69 {
70 NOR_FLASH_INSTANCE *Instance;
71
72 Instance = INSTANCE_FROM_BLKIO_THIS(This);
73
74 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));
75
76 return NorFlashReset(Instance);
77 }
78
79 //
80 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
81 //
82 EFI_STATUS
83 EFIAPI
84 NorFlashBlockIoReadBlocks (
85 IN EFI_BLOCK_IO_PROTOCOL *This,
86 IN UINT32 MediaId,
87 IN EFI_LBA Lba,
88 IN UINTN BufferSizeInBytes,
89 OUT VOID *Buffer
90 )
91 {
92 NOR_FLASH_INSTANCE *Instance;
93 EFI_STATUS Status;
94
95 Instance = INSTANCE_FROM_BLKIO_THIS(This);
96
97 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
98
99 if( !This->Media->MediaPresent ) {
100 Status = EFI_NO_MEDIA;
101 } else if( This->Media->MediaId != MediaId ) {
102 Status = EFI_MEDIA_CHANGED;
103 } else {
104 Status = NorFlashReadBlocks(Instance,Lba,BufferSizeInBytes,Buffer);
105 }
106
107 return Status;
108 }
109
110 //
111 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
112 //
113 EFI_STATUS
114 EFIAPI
115 NorFlashBlockIoWriteBlocks (
116 IN EFI_BLOCK_IO_PROTOCOL *This,
117 IN UINT32 MediaId,
118 IN EFI_LBA Lba,
119 IN UINTN BufferSizeInBytes,
120 IN VOID *Buffer
121 )
122 {
123 NOR_FLASH_INSTANCE *Instance;
124 EFI_STATUS Status;
125
126 Instance = INSTANCE_FROM_BLKIO_THIS(This);
127
128 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
129
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;
136 } else {
137 Status = NorFlashWriteBlocks(Instance,Lba,BufferSizeInBytes,Buffer);
138 }
139
140 return Status;
141 }
142
143 //
144 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
145 //
146 EFI_STATUS
147 EFIAPI
148 NorFlashBlockIoFlushBlocks (
149 IN EFI_BLOCK_IO_PROTOCOL *This
150 )
151 {
152 // No Flush required for the NOR Flash driver
153 // because cache operations are not permitted.
154
155 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
156
157 // Nothing to do so just return without error
158 return EFI_SUCCESS;
159 }