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