1 | /* $Id: DevEEPROM.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DevEEPROM - Microwire-compatible 64x16-bit 93C46 EEPROM Emulation, Header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VBOX_INCLUDED_SRC_Network_DevEEPROM_h
|
---|
29 | #define VBOX_INCLUDED_SRC_Network_DevEEPROM_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <iprt/types.h>
|
---|
35 |
|
---|
36 | /** The current Saved state version. */
|
---|
37 | #define EEPROM93C46_SAVEDSTATE_VERSION 1
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * 93C46-compatible EEPROM device emulation.
|
---|
41 | *
|
---|
42 | * @remarks This class is intended to be used in device
|
---|
43 | * emulation which imposes some restrictions if the
|
---|
44 | * device supports GC execution. This is why it is a
|
---|
45 | * plain-old-data structure.
|
---|
46 | */
|
---|
47 | struct EEPROM93C46
|
---|
48 | {
|
---|
49 | /** General definitions */
|
---|
50 | enum {
|
---|
51 | /** Size of EEPROM in words */
|
---|
52 | SIZE = 64,
|
---|
53 | /** Number of bits per word */
|
---|
54 | WORD_SIZE = 16,
|
---|
55 | /** Number of address bits */
|
---|
56 | ADDR_SIZE = 6,
|
---|
57 | /** Number of bits in opcode */
|
---|
58 | OPCODE_SIZE = 2,
|
---|
59 | /** The most significant bit mask in data word */
|
---|
60 | DATA_MSB = 1<<(WORD_SIZE-1),
|
---|
61 | /** Address mask */
|
---|
62 | ADDR_MASK = (1<<ADDR_SIZE)-1,
|
---|
63 | /** The most significant bit mask in op+addr bit sequence */
|
---|
64 | OPADDR_MSB = 1<<(OPCODE_SIZE+ADDR_SIZE-1)
|
---|
65 | };
|
---|
66 |
|
---|
67 | enum OP {
|
---|
68 | OP_READ,
|
---|
69 | OP_WRITE,
|
---|
70 | OP_WRITE_ALL,
|
---|
71 | OP_DECODE,
|
---|
72 | OP_32BIT_HACK = 0x7fffffff
|
---|
73 | };
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Names of signal wires
|
---|
77 | */
|
---|
78 | enum Wires {
|
---|
79 | WIRES_SK=0x1, ///< Clock
|
---|
80 | WIRES_CS=0x2, ///< Chip Select
|
---|
81 | WIRES_DI=0x4, ///< Data In
|
---|
82 | WIRES_DO=0x8 ///< Data Out
|
---|
83 | };
|
---|
84 |
|
---|
85 |
|
---|
86 | /** @todo save and load methods */
|
---|
87 | void save(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM);
|
---|
88 | int load(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM);
|
---|
89 |
|
---|
90 | /** Actual content of EEPROM */
|
---|
91 | uint16_t m_au16Data[SIZE];
|
---|
92 |
|
---|
93 | /** current state.
|
---|
94 | *
|
---|
95 | * EEPROM operates as a simple state machine. Events are primarily
|
---|
96 | * triggered at positive edge of clock signal (SK). Refer to the
|
---|
97 | * timing diagrams of 93C46 to get better understanding.
|
---|
98 | */
|
---|
99 | enum State {
|
---|
100 | /** Initial state. Waiting for start condition (CS, SK, DI high). */
|
---|
101 | STANDBY,
|
---|
102 | /** Reading data in, shifting in the bits into 'word'. */
|
---|
103 | READING_DI,
|
---|
104 | /** Writing data out, shifting out the bits from 'word'. */
|
---|
105 | WRITING_DO,
|
---|
106 | /** Waiting for CS=0 to indicate we are busy (DO=0). */
|
---|
107 | WAITING_CS_FALL,
|
---|
108 | /** Waiting for CS=1 to indicate we are ready (DO=1). */
|
---|
109 | WAITING_CS_RISE,
|
---|
110 | /** Make this enum 4-byte */
|
---|
111 | STATE_MAKE_32BIT_HACK = 0x7fffffff
|
---|
112 | } m_eState;
|
---|
113 | /** setting writeEnable to false prevents write and erase operations */
|
---|
114 | bool m_fWriteEnabled;
|
---|
115 | uint8_t Alignment1;
|
---|
116 | /** intermediate storage */
|
---|
117 | uint16_t m_u16Word;
|
---|
118 | /** currently processed bit in 'word' */
|
---|
119 | uint16_t m_u16Mask;
|
---|
120 | /** decoded address */
|
---|
121 | uint16_t m_u16Addr;
|
---|
122 | /** Data Out, Data In, Chip Select, Clock */
|
---|
123 | uint32_t m_u32InternalWires;
|
---|
124 |
|
---|
125 | /** Current opcode decoder. When no operation has been decoded yet
|
---|
126 | * it is set to OP_DECODE.
|
---|
127 | */
|
---|
128 | OP m_eOp;
|
---|
129 | #if HC_ARCH_BITS == 64
|
---|
130 | uint32_t Alignment2;
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | #ifdef IN_RING3
|
---|
134 | uint32_t read();
|
---|
135 | void write(uint32_t u32Wires);
|
---|
136 | bool readWord(uint32_t u32Addr, uint16_t *pu16Value);
|
---|
137 |
|
---|
138 | void init(const uint16_t *pu16Initial = 0);
|
---|
139 |
|
---|
140 | // Operation handlers
|
---|
141 | State opDecode();
|
---|
142 | State opRead();
|
---|
143 | State opWrite();
|
---|
144 | State opWriteAll();
|
---|
145 |
|
---|
146 | /** Helper method to implement write protection */
|
---|
147 | void storeWord(uint32_t u32Addr, uint16_t u16Value);
|
---|
148 | #endif /* IN_RING3 */
|
---|
149 | };
|
---|
150 |
|
---|
151 | #endif /* !VBOX_INCLUDED_SRC_Network_DevEEPROM_h */
|
---|