1 | /* $Id: FlashCore.h 81506 2019-10-24 02:51:43Z 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 | #if 0
|
---|
51 | /** Enables the ring-0/raw-mode read cache optimization, giving the size in
|
---|
52 | * uint64_t units. */
|
---|
53 | #define FLASH_WITH_RZ_READ_CACHE_SIZE 32
|
---|
54 | #endif
|
---|
55 |
|
---|
56 |
|
---|
57 | /*********************************************************************************************************************************
|
---|
58 | * Structures and Typedefs *
|
---|
59 | *********************************************************************************************************************************/
|
---|
60 | /**
|
---|
61 | * The flash device core structure.
|
---|
62 | */
|
---|
63 | typedef struct FLASHCORE
|
---|
64 | {
|
---|
65 | /** The current command. */
|
---|
66 | uint8_t bCmd;
|
---|
67 | /** The status register. */
|
---|
68 | uint8_t bStatus;
|
---|
69 | /** Current bus cycle. */
|
---|
70 | uint8_t cBusCycle;
|
---|
71 |
|
---|
72 | /** @name The following state does not change at runtime
|
---|
73 | * @{ */
|
---|
74 | /** When set, indicates the state was saved. */
|
---|
75 | bool fStateSaved;
|
---|
76 | /** Manufacturer (high byte) and device (low byte) ID. */
|
---|
77 | uint16_t u16FlashId;
|
---|
78 | /** The configured block size of the device. */
|
---|
79 | uint16_t cbBlockSize;
|
---|
80 | /** The actual flash memory data. */
|
---|
81 | R3PTRTYPE(uint8_t *) pbFlash;
|
---|
82 | /** The flash memory region size. */
|
---|
83 | uint32_t cbFlashSize;
|
---|
84 | /** @} */
|
---|
85 |
|
---|
86 | #ifdef FLASH_WITH_RZ_READ_CACHE_SIZE
|
---|
87 | /** @name Read cache for non-ring-3 code.
|
---|
88 | * @{ */
|
---|
89 | /** The cache offset, UINT32_MAX if invalid. */
|
---|
90 | uint32_t offCache;
|
---|
91 | # if ARCH_BITS == 32
|
---|
92 | uint32_t uPadding;
|
---|
93 | # endif
|
---|
94 | /** The cache data. */
|
---|
95 | union
|
---|
96 | {
|
---|
97 | uint64_t au64[FLASH_WITH_RZ_READ_CACHE_SIZE];
|
---|
98 | uint8_t ab[FLASH_WITH_RZ_READ_CACHE_SIZE * 8];
|
---|
99 | } CacheData;
|
---|
100 | /** @} */
|
---|
101 | #endif
|
---|
102 | } FLASHCORE;
|
---|
103 |
|
---|
104 | /** Pointer to the Flash device state. */
|
---|
105 | typedef FLASHCORE *PFLASHCORE;
|
---|
106 |
|
---|
107 | #ifndef VBOX_DEVICE_STRUCT_TESTCASE
|
---|
108 |
|
---|
109 | DECLHIDDEN(VBOXSTRICTRC) flashWrite(PFLASHCORE pThis, uint32_t off, const void *pv, size_t cb);
|
---|
110 | DECLHIDDEN(VBOXSTRICTRC) flashRead(PFLASHCORE pThis, uint32_t off, void *pv, size_t cb);
|
---|
111 |
|
---|
112 | # ifdef IN_RING3
|
---|
113 | DECLHIDDEN(int) flashR3Init(PFLASHCORE pThis, PPDMDEVINS pDevIns, uint16_t idFlashDev, uint32_t cbFlash, uint16_t cbBlock);
|
---|
114 | DECLHIDDEN(void) flashR3Destruct(PFLASHCORE pThis, PPDMDEVINS pDevIns);
|
---|
115 | DECLHIDDEN(int) flashR3LoadFromFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename);
|
---|
116 | DECLHIDDEN(int) flashR3LoadFromBuf(PFLASHCORE pThis, void const *pvBuf, size_t cbBuf);
|
---|
117 | DECLHIDDEN(int) flashR3SaveToFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename);
|
---|
118 | DECLHIDDEN(int) flashR3SaveToBuf(PFLASHCORE pThis, void *pvBuf, size_t cbBuf);
|
---|
119 | DECLHIDDEN(void) flashR3Reset(PFLASHCORE pThis);
|
---|
120 | DECLHIDDEN(int) flashR3SaveExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
|
---|
121 | DECLHIDDEN(int) flashR3LoadExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
|
---|
122 | # endif /* IN_RING3 */
|
---|
123 |
|
---|
124 | #endif /* VBOX_DEVICE_STRUCT_TESTCASE */
|
---|
125 |
|
---|
126 | RT_C_DECLS_END
|
---|
127 |
|
---|
128 | #endif /* !VBOX_INCLUDED_SRC_EFI_FlashCore_h */
|
---|
129 |
|
---|