]>
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 |
f4dfad05 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
1e57a462 | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <Library/BaseMemoryLib.h>\r | |
10 | #include <Library/UefiBootServicesTableLib.h>\r | |
11 | \r | |
c2d1cf1b | 12 | #include "NorFlash.h"\r |
1e57a462 | 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 | |
40b0b23e | 24 | NOR_FLASH_INSTANCE *Instance;\r |
1e57a462 | 25 | \r |
40b0b23e | 26 | Instance = INSTANCE_FROM_BLKIO_THIS (This);\r |
1e57a462 | 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 | |
40b0b23e MK |
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 | |
1e57a462 | 44 | )\r |
45 | {\r | |
46 | NOR_FLASH_INSTANCE *Instance;\r | |
47 | EFI_STATUS Status;\r | |
3d783074 | 48 | EFI_BLOCK_IO_MEDIA *Media;\r |
49 | \r | |
50 | if (This == NULL) {\r | |
51 | return EFI_INVALID_PARAMETER;\r | |
52 | }\r | |
1e57a462 | 53 | \r |
40b0b23e MK |
54 | Instance = INSTANCE_FROM_BLKIO_THIS (This);\r |
55 | Media = This->Media;\r | |
1e57a462 | 56 | \r |
917a7e3f | 57 | DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, BufferSizeInBytes, Buffer));\r |
1e57a462 | 58 | \r |
3d783074 | 59 | if (!Media) {\r |
60 | Status = EFI_INVALID_PARAMETER;\r | |
61 | } else if (!Media->MediaPresent) {\r | |
1e57a462 | 62 | Status = EFI_NO_MEDIA;\r |
3d783074 | 63 | } else if (Media->MediaId != MediaId) {\r |
1e57a462 | 64 | Status = EFI_MEDIA_CHANGED;\r |
3d783074 | 65 | } else if ((Media->IoAlign > 2) && (((UINTN)Buffer & (Media->IoAlign - 1)) != 0)) {\r |
66 | Status = EFI_INVALID_PARAMETER;\r | |
1e57a462 | 67 | } else {\r |
3d783074 | 68 | Status = NorFlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffer);\r |
1e57a462 | 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 | |
40b0b23e MK |
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 | |
1e57a462 | 85 | )\r |
86 | {\r | |
87 | NOR_FLASH_INSTANCE *Instance;\r | |
88 | EFI_STATUS Status;\r | |
89 | \r | |
40b0b23e | 90 | Instance = INSTANCE_FROM_BLKIO_THIS (This);\r |
1e57a462 | 91 | \r |
917a7e3f | 92 | DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes, BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));\r |
1e57a462 | 93 | \r |
40b0b23e | 94 | if ( !This->Media->MediaPresent ) {\r |
1e57a462 | 95 | Status = EFI_NO_MEDIA;\r |
40b0b23e | 96 | } else if ( This->Media->MediaId != MediaId ) {\r |
1e57a462 | 97 | Status = EFI_MEDIA_CHANGED;\r |
40b0b23e | 98 | } else if ( This->Media->ReadOnly ) {\r |
1e57a462 | 99 | Status = EFI_WRITE_PROTECTED;\r |
100 | } else {\r | |
40b0b23e | 101 | Status = NorFlashWriteBlocks (Instance, Lba, BufferSizeInBytes, Buffer);\r |
1e57a462 | 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 |