]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/ArmVExpressPkg/NorFlashDxe/NorFlashBlockIoDxe.c
ArmPlatformPkg/SP804Timer: Introduce gArmPlatformTokenSpaceGuid.PcdSP804FrequencyInMHz
[mirror_edk2.git] / ArmPlatformPkg / ArmVExpressPkg / NorFlashDxe / NorFlashBlockIoDxe.c
CommitLineData
1d5d0ae9 1/** @file NorFlashBlockIoDxe.c
2
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
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/DebugLib.h>
15#include <Library/BaseMemoryLib.h>
16#include <Library/UefiBootServicesTableLib.h>
17
18#include "NorFlashDxe.h"
19
20EFI_STATUS
21EFIAPI
22NorFlashBlkIoInitialize (
23 IN NOR_FLASH_INSTANCE* Instance
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,
40 P30_CFI_ADDR_QUERY_UNIQUE_QRY,
41 3,
42 &Reply
43 );
44 if (EFI_ERROR(Status)) {
45 goto EXIT;
46 }
47
48 if ( Reply != CFI_QRY ) {
49 DEBUG((EFI_D_ERROR, "NorFlashBlkIoInitialize: CFI QRY=0x%x (expected 0x595251)\n", Reply));
50 Status = EFI_DEVICE_ERROR;
51 goto EXIT;
52 }
53
54EXIT:
55 // Reset the device
56 Status = NorFlashBlockIoReset( &Instance->BlockIoProtocol, FALSE );
57 if (EFI_ERROR(Status)) {
58 goto EXIT;
59 }
60
61 Instance->Initialized = TRUE;
62 return EFI_SUCCESS;
63}
64
65
66//
67// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
68//
69EFI_STATUS
70EFIAPI
71NorFlashBlockIoReset (
72 IN EFI_BLOCK_IO_PROTOCOL *This,
73 IN BOOLEAN ExtendedVerification
74 )
75{
76 EFI_STATUS Status;
77 NOR_FLASH_INSTANCE *Instance;
78
79 Instance = INSTANCE_FROM_BLKIO_THIS(This);
80
81 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));
82
83 Status = NorFlashReset(Instance);
84
85 return Status;
86
87}
88
89//
90// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
91//
92EFI_STATUS
93EFIAPI
94NorFlashBlockIoReadBlocks (
95 IN EFI_BLOCK_IO_PROTOCOL *This,
96 IN UINT32 MediaId,
97 IN EFI_LBA Lba,
98 IN UINTN BufferSizeInBytes,
99 OUT VOID *Buffer
100 )
101{
102 NOR_FLASH_INSTANCE *Instance;
103
104 Instance = INSTANCE_FROM_BLKIO_THIS(This);
105
106 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
107
108 return NorFlashReadBlocks(Instance,Lba,BufferSizeInBytes,Buffer);
109}
110
111//
112// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
113//
114EFI_STATUS
115EFIAPI
116NorFlashBlockIoWriteBlocks (
117 IN EFI_BLOCK_IO_PROTOCOL *This,
118 IN UINT32 MediaId,
119 IN EFI_LBA Lba,
120 IN UINTN BufferSizeInBytes,
121 IN VOID *Buffer
122 )
123{
124 NOR_FLASH_INSTANCE *Instance;
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 return NorFlashWriteBlocks(Instance,Lba,BufferSizeInBytes,Buffer);
131}
132
133//
134// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
135//
136EFI_STATUS
137EFIAPI
138NorFlashBlockIoFlushBlocks (
139 IN EFI_BLOCK_IO_PROTOCOL *This
140 )
141{
142 // No Flush required for the NOR Flash driver
143 // because cache operations are not permitted.
144
145 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
146
147 // Nothing to do so just return without error
148 return EFI_SUCCESS;
149}