VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FlashCore.h

Last change on this file was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: FlashCore.h 106061 2024-09-16 14:03:52Z 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-2024 Oracle and/or its affiliates.
14 *
15 * This file is part of VirtualBox base platform packages, as
16 * available from https://www.virtualbox.org.
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation, in version 3 of the
21 * License.
22 *
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, see <https://www.gnu.org/licenses>.
30 *
31 * SPDX-License-Identifier: GPL-3.0-only
32 */
33
34#ifndef VBOX_INCLUDED_SRC_EFI_FlashCore_h
35#define VBOX_INCLUDED_SRC_EFI_FlashCore_h
36#ifndef RT_WITHOUT_PRAGMA_ONCE
37# pragma once
38#endif
39
40/*********************************************************************************************************************************
41* Header Files *
42*********************************************************************************************************************************/
43#include <VBox/vmm/pdmdev.h>
44#include <VBox/vmm/pdmifs.h>
45#include <VBox/log.h>
46#include <VBox/err.h>
47#include <iprt/assert.h>
48#include <iprt/string.h>
49#include <iprt/file.h>
50
51#include "VBoxDD.h"
52
53RT_C_DECLS_BEGIN
54
55/*********************************************************************************************************************************
56* Defined Constants And Macros *
57*********************************************************************************************************************************/
58/** The current version of the saved state. */
59#define FLASH_SAVED_STATE_VERSION 1
60
61#if 0
62/** Enables the ring-0/raw-mode read cache optimization, giving the size in
63 * uint64_t units. */
64#define FLASH_WITH_RZ_READ_CACHE_SIZE 32
65#endif
66
67
68/*********************************************************************************************************************************
69* Structures and Typedefs *
70*********************************************************************************************************************************/
71/**
72 * The flash device core structure.
73 */
74typedef struct FLASHCORE
75{
76 /** The current command. */
77 uint8_t bCmd;
78 /** The status register. */
79 uint8_t bStatus;
80 /** Current bus cycle. */
81 uint8_t cBusCycle;
82
83 /** @name The following state does not change at runtime
84 * @{ */
85 /** When set, indicates the state was saved. */
86 bool fStateSaved;
87 /** Manufacturer (high byte) and device (low byte) ID. */
88 uint16_t u16FlashId;
89 /** The configured block size of the device. */
90 uint16_t cbBlockSize;
91 /** The actual flash memory data. */
92 R3PTRTYPE(uint8_t *) pbFlash;
93 /** The flash memory region size. */
94 uint32_t cbFlashSize;
95 /** @} */
96
97#ifdef FLASH_WITH_RZ_READ_CACHE_SIZE
98 /** @name Read cache for non-ring-3 code.
99 * @{ */
100 /** The cache offset, UINT32_MAX if invalid. */
101 uint32_t offCache;
102# if ARCH_BITS == 32
103 uint32_t uPadding;
104# endif
105 /** The cache data. */
106 union
107 {
108 uint64_t au64[FLASH_WITH_RZ_READ_CACHE_SIZE];
109 uint8_t ab[FLASH_WITH_RZ_READ_CACHE_SIZE * 8];
110 } CacheData;
111 /** @} */
112#endif
113} FLASHCORE;
114
115/** Pointer to the Flash device state. */
116typedef FLASHCORE *PFLASHCORE;
117
118#ifndef VBOX_DEVICE_STRUCT_TESTCASE
119
120DECLHIDDEN(VBOXSTRICTRC) flashWrite(PFLASHCORE pThis, uint32_t off, const void *pv, size_t cb);
121DECLHIDDEN(VBOXSTRICTRC) flashRead(PFLASHCORE pThis, uint32_t off, void *pv, size_t cb);
122
123# ifdef IN_RING3
124DECLHIDDEN(int) flashR3Init(PFLASHCORE pThis, PPDMDEVINS pDevIns, uint16_t idFlashDev, uint32_t cbFlash, uint16_t cbBlock);
125DECLHIDDEN(void) flashR3Destruct(PFLASHCORE pThis, PPDMDEVINS pDevIns);
126DECLHIDDEN(int) flashR3LoadFromFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename);
127DECLHIDDEN(int) flashR3LoadFromBuf(PFLASHCORE pThis, void const *pvBuf, size_t cbBuf);
128DECLHIDDEN(int) flashR3LoadFromVfs(PFLASHCORE pThis, PPDMDEVINS pDevIns, PPDMIVFSCONNECTOR pDrvVfs,
129 const char *pszNamespace, const char *pszPath);
130DECLHIDDEN(int) flashR3SaveToFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename);
131DECLHIDDEN(int) flashR3SaveToBuf(PFLASHCORE pThis, void *pvBuf, size_t cbBuf);
132DECLHIDDEN(int) flashR3SaveToVfs(PFLASHCORE pThis, PPDMDEVINS pDevIns, PPDMIVFSCONNECTOR pDrvVfs,
133 const char *pszNamespace, const char *pszPath);
134DECLHIDDEN(void) flashR3Reset(PFLASHCORE pThis);
135DECLHIDDEN(int) flashR3SaveExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
136DECLHIDDEN(int) flashR3LoadExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
137# endif /* IN_RING3 */
138
139#endif /* VBOX_DEVICE_STRUCT_TESTCASE */
140
141RT_C_DECLS_END
142
143#endif /* !VBOX_INCLUDED_SRC_EFI_FlashCore_h */
144
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette