]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPlatformPkg / Drivers / NorFlashDxe / NorFlashBlockIoDxe.c
1 /** @file NorFlashBlockIoDxe.c
2
3 Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Library/BaseMemoryLib.h>
10 #include <Library/UefiBootServicesTableLib.h>
11
12 #include "NorFlashDxe.h"
13
14 //
15 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset
16 //
17 EFI_STATUS
18 EFIAPI
19 NorFlashBlockIoReset (
20 IN EFI_BLOCK_IO_PROTOCOL *This,
21 IN BOOLEAN ExtendedVerification
22 )
23 {
24 NOR_FLASH_INSTANCE *Instance;
25
26 Instance = INSTANCE_FROM_BLKIO_THIS(This);
27
28 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));
29
30 return NorFlashReset (Instance);
31 }
32
33 //
34 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
35 //
36 EFI_STATUS
37 EFIAPI
38 NorFlashBlockIoReadBlocks (
39 IN EFI_BLOCK_IO_PROTOCOL *This,
40 IN UINT32 MediaId,
41 IN EFI_LBA Lba,
42 IN UINTN BufferSizeInBytes,
43 OUT VOID *Buffer
44 )
45 {
46 NOR_FLASH_INSTANCE *Instance;
47 EFI_STATUS Status;
48 EFI_BLOCK_IO_MEDIA *Media;
49
50 if (This == NULL) {
51 return EFI_INVALID_PARAMETER;
52 }
53
54 Instance = INSTANCE_FROM_BLKIO_THIS(This);
55 Media = This->Media;
56
57 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
58
59 if (!Media) {
60 Status = EFI_INVALID_PARAMETER;
61 } else if (!Media->MediaPresent) {
62 Status = EFI_NO_MEDIA;
63 } else if (Media->MediaId != MediaId) {
64 Status = EFI_MEDIA_CHANGED;
65 } else if ((Media->IoAlign > 2) && (((UINTN)Buffer & (Media->IoAlign - 1)) != 0)) {
66 Status = EFI_INVALID_PARAMETER;
67 } else {
68 Status = NorFlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
69 }
70
71 return Status;
72 }
73
74 //
75 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
76 //
77 EFI_STATUS
78 EFIAPI
79 NorFlashBlockIoWriteBlocks (
80 IN EFI_BLOCK_IO_PROTOCOL *This,
81 IN UINT32 MediaId,
82 IN EFI_LBA Lba,
83 IN UINTN BufferSizeInBytes,
84 IN VOID *Buffer
85 )
86 {
87 NOR_FLASH_INSTANCE *Instance;
88 EFI_STATUS Status;
89
90 Instance = INSTANCE_FROM_BLKIO_THIS(This);
91
92 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
93
94 if( !This->Media->MediaPresent ) {
95 Status = EFI_NO_MEDIA;
96 } else if( This->Media->MediaId != MediaId ) {
97 Status = EFI_MEDIA_CHANGED;
98 } else if( This->Media->ReadOnly ) {
99 Status = EFI_WRITE_PROTECTED;
100 } else {
101 Status = NorFlashWriteBlocks (Instance,Lba,BufferSizeInBytes,Buffer);
102 }
103
104 return Status;
105 }
106
107 //
108 // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
109 //
110 EFI_STATUS
111 EFIAPI
112 NorFlashBlockIoFlushBlocks (
113 IN EFI_BLOCK_IO_PROTOCOL *This
114 )
115 {
116 // No Flush required for the NOR Flash driver
117 // because cache operations are not permitted.
118
119 DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoFlushBlocks: Function NOT IMPLEMENTED (not required).\n"));
120
121 // Nothing to do so just return without error
122 return EFI_SUCCESS;
123 }