TianoCore EDK2 master
Loading...
Searching...
No Matches
VirtNorFlash.h
1
9#ifndef __VIRT_NOR_FLASH__
10#define __VIRT_NOR_FLASH__
11
12#include <Base.h>
13#include <PiDxe.h>
14
15#include <Guid/EventGroup.h>
16
18
19#include <Library/DebugLib.h>
20#include <Library/IoLib.h>
21#include <Library/UefiLib.h>
24
25#define NOR_FLASH_ERASE_RETRY 10
26
27// Device access macros
28// These are necessary because we use 2 x 16bit parts to make up 32bit data
29
30#define HIGH_16_BITS 0xFFFF0000
31#define LOW_16_BITS 0x0000FFFF
32#define LOW_8_BITS 0x000000FF
33
34#define FOLD_32BIT_INTO_16BIT(value) ( ( value >> 16 ) | ( value & LOW_16_BITS ) )
35
36#define GET_LOW_BYTE(value) ( value & LOW_8_BITS )
37#define GET_HIGH_BYTE(value) ( GET_LOW_BYTE( value >> 16 ) )
38
39// Each command must be sent simultaneously to both chips,
40// i.e. at the lower 16 bits AND at the higher 16 bits
41#define CREATE_NOR_ADDRESS(BaseAddr, OffsetAddr) ((BaseAddr) + ((OffsetAddr) << 2))
42#define CREATE_DUAL_CMD(Cmd) ( ( Cmd << 16) | ( Cmd & LOW_16_BITS) )
43#define SEND_NOR_COMMAND(BaseAddr, Offset, Cmd) MmioWrite32 (CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))
44#define GET_NOR_BLOCK_ADDRESS(BaseAddr, Lba, LbaSize) ( BaseAddr + (UINTN)((Lba) * LbaSize) )
45
46// Status Register Bits
47#define P30_SR_BIT_WRITE (BIT7 << 16 | BIT7)
48#define P30_SR_BIT_ERASE_SUSPEND (BIT6 << 16 | BIT6)
49#define P30_SR_BIT_ERASE (BIT5 << 16 | BIT5)
50#define P30_SR_BIT_PROGRAM (BIT4 << 16 | BIT4)
51#define P30_SR_BIT_VPP (BIT3 << 16 | BIT3)
52#define P30_SR_BIT_PROGRAM_SUSPEND (BIT2 << 16 | BIT2)
53#define P30_SR_BIT_BLOCK_LOCKED (BIT1 << 16 | BIT1)
54#define P30_SR_BIT_BEFP (BIT0 << 16 | BIT0)
55
56// Device Commands for Intel StrataFlash(R) Embedded Memory (P30) Family
57
58// On chip buffer size for buffered programming operations
59// There are 2 chips, each chip can buffer up to 32 (16-bit)words, and each word is 2 bytes.
60// Therefore the total size of the buffer is 2 x 32 x 2 = 128 bytes
61#define P30_MAX_BUFFER_SIZE_IN_BYTES ((UINTN)128)
62#define P30_MAX_BUFFER_SIZE_IN_WORDS (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINTN)4))
63#define MAX_BUFFERED_PROG_ITERATIONS 10000000
64#define BOUNDARY_OF_32_WORDS ((UINTN)0x7F)
65
66// CFI Addresses
67#define P30_CFI_ADDR_QUERY_UNIQUE_QRY 0x10
68#define P30_CFI_ADDR_VENDOR_ID 0x13
69
70// CFI Data
71#define CFI_QRY 0x00595251
72
73// READ Commands
74#define P30_CMD_READ_DEVICE_ID 0x0090
75#define P30_CMD_READ_STATUS_REGISTER 0x0070
76#define P30_CMD_CLEAR_STATUS_REGISTER 0x0050
77#define P30_CMD_READ_ARRAY 0x00FF
78#define P30_CMD_READ_CFI_QUERY 0x0098
79
80// WRITE Commands
81#define P30_CMD_WORD_PROGRAM_SETUP 0x0040
82#define P30_CMD_ALTERNATE_WORD_PROGRAM_SETUP 0x0010
83#define P30_CMD_BUFFERED_PROGRAM_SETUP 0x00E8
84#define P30_CMD_BUFFERED_PROGRAM_CONFIRM 0x00D0
85#define P30_CMD_BEFP_SETUP 0x0080
86#define P30_CMD_BEFP_CONFIRM 0x00D0
87
88// ERASE Commands
89#define P30_CMD_BLOCK_ERASE_SETUP 0x0020
90#define P30_CMD_BLOCK_ERASE_CONFIRM 0x00D0
91
92// SUSPEND Commands
93#define P30_CMD_PROGRAM_OR_ERASE_SUSPEND 0x00B0
94#define P30_CMD_SUSPEND_RESUME 0x00D0
95
96// BLOCK LOCKING / UNLOCKING Commands
97#define P30_CMD_LOCK_BLOCK_SETUP 0x0060
98#define P30_CMD_LOCK_BLOCK 0x0001
99#define P30_CMD_UNLOCK_BLOCK 0x00D0
100#define P30_CMD_LOCK_DOWN_BLOCK 0x002F
101
102// PROTECTION Commands
103#define P30_CMD_PROGRAM_PROTECTION_REGISTER_SETUP 0x00C0
104
105// CONFIGURATION Commands
106#define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP 0x0060
107#define P30_CMD_READ_CONFIGURATION_REGISTER 0x0003
108
109#define NOR_FLASH_SIGNATURE SIGNATURE_32('n', 'o', 'r', '0')
110#define INSTANCE_FROM_FVB_THIS(a) CR(a, NOR_FLASH_INSTANCE, FvbProtocol, NOR_FLASH_SIGNATURE)
111
113
114#pragma pack (1)
115typedef struct {
116 VENDOR_DEVICE_PATH Vendor;
117 UINT8 Index;
120#pragma pack ()
121
123 UINT32 Signature;
124 EFI_HANDLE Handle;
125
126 UINTN DeviceBaseAddress;
127 UINTN RegionBaseAddress;
128 UINTN Size;
129 EFI_LBA StartLba;
130 EFI_LBA LastBlock;
131 UINT32 BlockSize;
132
134 VOID *ShadowBuffer;
135
136 NOR_FLASH_DEVICE_PATH DevicePath;
137};
138
140NorFlashReadCfiData (
141 IN UINTN DeviceBaseAddress,
142 IN UINTN CFI_Offset,
143 IN UINT32 NumberOfBytes,
144 OUT UINT32 *Data
145 );
146
148NorFlashWriteBuffer (
149 IN NOR_FLASH_INSTANCE *Instance,
150 IN UINTN TargetAddress,
151 IN UINTN BufferSizeInBytes,
152 IN UINT32 *Buffer
153 );
154
155//
156// NorFlashFvbDxe.c
157//
158
160EFIAPI
161FvbGetAttributes (
163 OUT EFI_FVB_ATTRIBUTES_2 *Attributes
164 );
165
167EFIAPI
168FvbSetAttributes (
170 IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
171 );
172
174EFIAPI
175FvbGetPhysicalAddress (
178 );
179
181EFIAPI
182FvbGetBlockSize (
184 IN EFI_LBA Lba,
185 OUT UINTN *BlockSize,
186 OUT UINTN *NumberOfBlocks
187 );
188
190EFIAPI
191FvbRead (
193 IN EFI_LBA Lba,
194 IN UINTN Offset,
195 IN OUT UINTN *NumBytes,
196 IN OUT UINT8 *Buffer
197 );
198
200EFIAPI
201FvbWrite (
203 IN EFI_LBA Lba,
204 IN UINTN Offset,
205 IN OUT UINTN *NumBytes,
206 IN UINT8 *Buffer
207 );
208
210EFIAPI
211FvbEraseBlocks (
213 ...
214 );
215
217ValidateFvHeader (
218 IN NOR_FLASH_INSTANCE *Instance
219 );
220
223 IN NOR_FLASH_INSTANCE *Instance
224 );
225
226VOID
227EFIAPI
228FvbVirtualNotifyEvent (
229 IN EFI_EVENT Event,
230 IN VOID *Context
231 );
232
233//
234// NorFlashDxe.c
235//
236
238NorFlashWriteFullBlock (
239 IN NOR_FLASH_INSTANCE *Instance,
240 IN EFI_LBA Lba,
241 IN UINT32 *DataBuffer,
242 IN UINT32 BlockSizeInWords
243 );
244
246NorFlashUnlockAndEraseSingleBlock (
247 IN NOR_FLASH_INSTANCE *Instance,
248 IN UINTN BlockAddress
249 );
250
252NorFlashCreateInstance (
253 IN UINTN NorFlashDeviceBase,
254 IN UINTN NorFlashRegionBase,
255 IN UINTN NorFlashSize,
256 IN UINT32 Index,
257 IN UINT32 BlockSize,
258 IN BOOLEAN SupportFvb,
259 OUT NOR_FLASH_INSTANCE **NorFlashInstance
260 );
261
263EFIAPI
264NorFlashFvbInitialize (
265 IN NOR_FLASH_INSTANCE *Instance
266 );
267
268//
269// NorFlash.c
270//
272NorFlashWriteSingleBlock (
273 IN NOR_FLASH_INSTANCE *Instance,
274 IN EFI_LBA Lba,
275 IN UINTN Offset,
276 IN OUT UINTN *NumBytes,
277 IN UINT8 *Buffer
278 );
279
281NorFlashWriteBlocks (
282 IN NOR_FLASH_INSTANCE *Instance,
283 IN EFI_LBA Lba,
284 IN UINTN BufferSizeInBytes,
285 IN VOID *Buffer
286 );
287
289NorFlashReadBlocks (
290 IN NOR_FLASH_INSTANCE *Instance,
291 IN EFI_LBA Lba,
292 IN UINTN BufferSizeInBytes,
293 OUT VOID *Buffer
294 );
295
297NorFlashRead (
298 IN NOR_FLASH_INSTANCE *Instance,
299 IN EFI_LBA Lba,
300 IN UINTN Offset,
301 IN UINTN BufferSizeInBytes,
302 OUT VOID *Buffer
303 );
304
306NorFlashWrite (
307 IN NOR_FLASH_INSTANCE *Instance,
308 IN EFI_LBA Lba,
309 IN UINTN Offset,
310 IN OUT UINTN *NumBytes,
311 IN UINT8 *Buffer
312 );
313
315NorFlashReset (
316 IN NOR_FLASH_INSTANCE *Instance
317 );
318
320NorFlashEraseSingleBlock (
321 IN NOR_FLASH_INSTANCE *Instance,
322 IN UINTN BlockAddress
323 );
324
326NorFlashUnlockSingleBlockIfNecessary (
327 IN NOR_FLASH_INSTANCE *Instance,
328 IN UINTN BlockAddress
329 );
330
332NorFlashWriteSingleWord (
333 IN NOR_FLASH_INSTANCE *Instance,
334 IN UINTN WordAddress,
335 IN UINT32 WriteData
336 );
337
338VOID
339EFIAPI
340NorFlashVirtualNotifyEvent (
341 IN EFI_EVENT Event,
342 IN VOID *Context
343 );
344
345#endif /* __VIRT_NOR_FLASH__ */
UINT64 UINTN
VOID InitializeFvAndVariableStoreHeaders(IN VOID *Ptr)
Definition: Fvb.c:606
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT32 EFI_FVB_ATTRIBUTES_2
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
UINT64 EFI_LBA
Definition: UefiBaseType.h:45
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33