1 | /* $Id: FlashCore.h 81250 2019-10-14 11:41:24Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * A simple Flash device
|
---|
4 | *
|
---|
5 | * A simple non-volatile byte-wide (x8) memory device modeled after Intel 28F008
|
---|
6 | * FlashFile. See 28F008SA datasheet, Intel order number 290429-007.
|
---|
7 | *
|
---|
8 | * Implemented as an MMIO device attached directly to the CPU, not behind any
|
---|
9 | * bus. Typically mapped as part of the firmware image.
|
---|
10 | */
|
---|
11 |
|
---|
12 | /*
|
---|
13 | * Copyright (C) 2018-2019 Oracle Corporation
|
---|
14 | *
|
---|
15 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
16 | * available from http://www.virtualbox.org. This file is free software;
|
---|
17 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
18 | * General Public License (GPL) as published by the Free Software
|
---|
19 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
20 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
21 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #ifndef VBOX_INCLUDED_SRC_EFI_FlashCore_h
|
---|
25 | #define VBOX_INCLUDED_SRC_EFI_FlashCore_h
|
---|
26 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
27 | # pragma once
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | /*********************************************************************************************************************************
|
---|
31 | * Header Files *
|
---|
32 | *********************************************************************************************************************************/
|
---|
33 | #include <VBox/vmm/pdmdev.h>
|
---|
34 | #include <VBox/log.h>
|
---|
35 | #include <VBox/err.h>
|
---|
36 | #include <iprt/assert.h>
|
---|
37 | #include <iprt/string.h>
|
---|
38 | #include <iprt/file.h>
|
---|
39 |
|
---|
40 | #include "VBoxDD.h"
|
---|
41 |
|
---|
42 | RT_C_DECLS_BEGIN
|
---|
43 |
|
---|
44 | /*********************************************************************************************************************************
|
---|
45 | * Defined Constants And Macros *
|
---|
46 | *********************************************************************************************************************************/
|
---|
47 | /** The current version of the saved state. */
|
---|
48 | #define FLASH_SAVED_STATE_VERSION 1
|
---|
49 |
|
---|
50 |
|
---|
51 | /*********************************************************************************************************************************
|
---|
52 | * Structures and Typedefs *
|
---|
53 | *********************************************************************************************************************************/
|
---|
54 | /**
|
---|
55 | * The flash device core structure.
|
---|
56 | */
|
---|
57 | typedef struct FLASHCORE
|
---|
58 | {
|
---|
59 | /** Owning device instance. */
|
---|
60 | PPDMDEVINS pDevIns;
|
---|
61 | /** The current command. */
|
---|
62 | uint8_t bCmd;
|
---|
63 | /** The status register. */
|
---|
64 | uint8_t bStatus;
|
---|
65 | /** Current bus cycle. */
|
---|
66 | uint8_t cBusCycle;
|
---|
67 |
|
---|
68 | uint8_t uPadding0;
|
---|
69 |
|
---|
70 | /* The following state does not change at runtime.*/
|
---|
71 | /** Manufacturer (high byte) and device (low byte) ID. */
|
---|
72 | uint16_t u16FlashId;
|
---|
73 | /** The configured block size of the device. */
|
---|
74 | uint16_t cbBlockSize;
|
---|
75 | /** The flash memory region size. */
|
---|
76 | uint32_t cbFlashSize;
|
---|
77 | /** The actual flash memory data. */
|
---|
78 | uint8_t *pbFlash;
|
---|
79 | /** When set, indicates the state was saved. */
|
---|
80 | bool fStateSaved;
|
---|
81 | } FLASHCORE;
|
---|
82 |
|
---|
83 | /** Pointer to the Flash device state. */
|
---|
84 | typedef FLASHCORE *PFLASHCORE;
|
---|
85 |
|
---|
86 | #ifndef VBOX_DEVICE_STRUCT_TESTCASE
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Performs a write to the given flash offset.
|
---|
90 | *
|
---|
91 | * @returns VBox status code.
|
---|
92 | * @param pThis The UART core instance.
|
---|
93 | * @param off Offset to start writing to.
|
---|
94 | * @param pv The value to write.
|
---|
95 | * @param cb Number of bytes to write.
|
---|
96 | */
|
---|
97 | DECLHIDDEN(int) flashWrite(PFLASHCORE pThis, uint32_t off, const void *pv, size_t cb);
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Performs a read from the given flash offset.
|
---|
101 | *
|
---|
102 | * @returns VBox status code.
|
---|
103 | * @param pThis The UART core instance.
|
---|
104 | * @param off Offset to start reading from.
|
---|
105 | * @param pv Where to store the read data.
|
---|
106 | * @param cb Number of bytes to read.
|
---|
107 | */
|
---|
108 | DECLHIDDEN(int) flashRead(PFLASHCORE pThis, uint32_t off, void *pv, size_t cb);
|
---|
109 |
|
---|
110 | # ifdef IN_RING3
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Initialiizes the given flash device instance.
|
---|
114 | *
|
---|
115 | * @returns VBox status code.
|
---|
116 | * @param pThis The flash device core instance.
|
---|
117 | * @param pDevIns Pointer to the owning device instance.
|
---|
118 | * @param idFlashDev The flash device ID.
|
---|
119 | * @param GCPhysFlashBase Base MMIO address where the flash is located.
|
---|
120 | * @param cbFlash Size of the flash device in bytes.
|
---|
121 | * @param cbBlock Size of a flash block.
|
---|
122 | */
|
---|
123 | DECLHIDDEN(int) flashR3Init(PFLASHCORE pThis, PPDMDEVINS pDevIns, uint16_t idFlashDev, uint32_t cbFlash, uint16_t cbBlock);
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Destroys the given flash device instance.
|
---|
127 | *
|
---|
128 | * @returns nothing.
|
---|
129 | * @param pThis The flash device core instance.
|
---|
130 | */
|
---|
131 | DECLHIDDEN(void) flashR3Destruct(PFLASHCORE pThis);
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Loads the flash content from the given file.
|
---|
135 | *
|
---|
136 | * @returns VBox status code.
|
---|
137 | * @param pThis The flash device core instance.
|
---|
138 | * @param pszFilename The file to load the flash content from.
|
---|
139 | */
|
---|
140 | DECLHIDDEN(int) flashR3LoadFromFile(PFLASHCORE pThis, const char *pszFilename);
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Loads the flash content from the given buffer.
|
---|
144 | *
|
---|
145 | * @returns VBox status code.
|
---|
146 | * @param pThis The flash device core instance.
|
---|
147 | * @param pvBuf The buffer to load the content from.
|
---|
148 | * @param cbBuf Size of the buffer in bytes.
|
---|
149 | */
|
---|
150 | DECLHIDDEN(int) flashR3LoadFromBuf(PFLASHCORE pThis, void *pvBuf, size_t cbBuf);
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Saves the flash content to the given file.
|
---|
154 | *
|
---|
155 | * @returns VBox status code.
|
---|
156 | * @param pThis The flash device core instance.
|
---|
157 | * @param pszFilename The file to save the flash content to.
|
---|
158 | */
|
---|
159 | DECLHIDDEN(int) flashR3SaveToFile(PFLASHCORE pThis, const char *pszFilename);
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Saves the flash content to the given buffer.
|
---|
163 | *
|
---|
164 | * @returns VBox status code.
|
---|
165 | * @param pThis The flash device core instance.
|
---|
166 | * @param pvBuf The buffer to save the content to.
|
---|
167 | * @param cbBuf Size of the buffer in bytes.
|
---|
168 | */
|
---|
169 | DECLHIDDEN(int) flashR3SaveToBuf(PFLASHCORE pThis, void *pvBuf, size_t cbBuf);
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Resets the dynamic part of the flash device state.
|
---|
173 | *
|
---|
174 | * @returns nothing.
|
---|
175 | * @param pThis The flash device core instance.
|
---|
176 | */
|
---|
177 | DECLHIDDEN(void) flashR3Reset(PFLASHCORE pThis);
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Saves the flash device state to the given SSM handle.
|
---|
181 | *
|
---|
182 | * @returns VBox status code.
|
---|
183 | * @param pThis The flash device core instance.
|
---|
184 | * @param pSSM The SSM handle to save to.
|
---|
185 | */
|
---|
186 | DECLHIDDEN(int) flashR3SsmSaveExec(PFLASHCORE pThis, PSSMHANDLE pSSM);
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Loads the flash device state from the given SSM handle.
|
---|
190 | *
|
---|
191 | * @returns VBox status code.
|
---|
192 | * @param pThis The flash device core instance.
|
---|
193 | * @param pSSM The SSM handle to load from.
|
---|
194 | */
|
---|
195 | DECLHIDDEN(int) flashR3SsmLoadExec(PFLASHCORE pThis, PSSMHANDLE pSSM);
|
---|
196 |
|
---|
197 | # endif /* IN_RING3 */
|
---|
198 |
|
---|
199 | #endif /* VBOX_DEVICE_STRUCT_TESTCASE */
|
---|
200 |
|
---|
201 | RT_C_DECLS_END
|
---|
202 |
|
---|
203 | #endif /* !VBOX_INCLUDED_SRC_EFI_FlashCore_h */
|
---|
204 |
|
---|