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