root / hw / esp.c @ 4487fd34
History | View | Annotate | Download (17.8 kB)
1 | 6f7e9aec | bellard | /*
|
---|---|---|---|
2 | 67e999be | bellard | * QEMU ESP/NCR53C9x emulation
|
3 | 5fafdf24 | ths | *
|
4 | 4e9aec74 | pbrook | * Copyright (c) 2005-2006 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 6f7e9aec | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 6f7e9aec | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 6f7e9aec | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 6f7e9aec | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 6f7e9aec | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 6f7e9aec | bellard | * furnished to do so, subject to the following conditions:
|
12 | 6f7e9aec | bellard | *
|
13 | 6f7e9aec | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 6f7e9aec | bellard | * all copies or substantial portions of the Software.
|
15 | 6f7e9aec | bellard | *
|
16 | 6f7e9aec | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 6f7e9aec | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 6f7e9aec | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 6f7e9aec | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 6f7e9aec | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 6f7e9aec | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 6f7e9aec | bellard | * THE SOFTWARE.
|
23 | 6f7e9aec | bellard | */
|
24 | 5d20fa6b | blueswir1 | |
25 | 87ecb68b | pbrook | #include "hw.h" |
26 | 87ecb68b | pbrook | #include "scsi-disk.h" |
27 | 8b17de88 | blueswir1 | #include "scsi.h" |
28 | 6f7e9aec | bellard | |
29 | 6f7e9aec | bellard | /* debug ESP card */
|
30 | 2f275b8f | bellard | //#define DEBUG_ESP
|
31 | 6f7e9aec | bellard | |
32 | 67e999be | bellard | /*
|
33 | 5ad6bb97 | blueswir1 | * On Sparc32, this is the ESP (NCR53C90) part of chip STP2000 (Master I/O),
|
34 | 5ad6bb97 | blueswir1 | * also produced as NCR89C100. See
|
35 | 67e999be | bellard | * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C100.txt
|
36 | 67e999be | bellard | * and
|
37 | 67e999be | bellard | * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR53C9X.txt
|
38 | 67e999be | bellard | */
|
39 | 67e999be | bellard | |
40 | 6f7e9aec | bellard | #ifdef DEBUG_ESP
|
41 | 6f7e9aec | bellard | #define DPRINTF(fmt, args...) \
|
42 | 6f7e9aec | bellard | do { printf("ESP: " fmt , ##args); } while (0) |
43 | 6f7e9aec | bellard | #else
|
44 | 22548760 | blueswir1 | #define DPRINTF(fmt, args...) do {} while (0) |
45 | 6f7e9aec | bellard | #endif
|
46 | 6f7e9aec | bellard | |
47 | 5aca8c3b | blueswir1 | #define ESP_REGS 16 |
48 | 2e5d83bb | pbrook | #define TI_BUFSZ 32 |
49 | 67e999be | bellard | |
50 | 4e9aec74 | pbrook | typedef struct ESPState ESPState; |
51 | 6f7e9aec | bellard | |
52 | 4e9aec74 | pbrook | struct ESPState {
|
53 | 5d20fa6b | blueswir1 | uint32_t it_shift; |
54 | 70c0de96 | blueswir1 | qemu_irq irq; |
55 | 5aca8c3b | blueswir1 | uint8_t rregs[ESP_REGS]; |
56 | 5aca8c3b | blueswir1 | uint8_t wregs[ESP_REGS]; |
57 | 67e999be | bellard | int32_t ti_size; |
58 | 4f6200f0 | bellard | uint32_t ti_rptr, ti_wptr; |
59 | 4f6200f0 | bellard | uint8_t ti_buf[TI_BUFSZ]; |
60 | 22548760 | blueswir1 | uint32_t sense; |
61 | 22548760 | blueswir1 | uint32_t dma; |
62 | e4bcb14c | ths | SCSIDevice *scsi_dev[ESP_MAX_DEVS]; |
63 | 2e5d83bb | pbrook | SCSIDevice *current_dev; |
64 | 9f149aa9 | pbrook | uint8_t cmdbuf[TI_BUFSZ]; |
65 | 22548760 | blueswir1 | uint32_t cmdlen; |
66 | 22548760 | blueswir1 | uint32_t do_cmd; |
67 | 4d611c9a | pbrook | |
68 | 6787f5fa | pbrook | /* The amount of data left in the current DMA transfer. */
|
69 | 4d611c9a | pbrook | uint32_t dma_left; |
70 | 6787f5fa | pbrook | /* The size of the current DMA transfer. Zero if no transfer is in
|
71 | 6787f5fa | pbrook | progress. */
|
72 | 6787f5fa | pbrook | uint32_t dma_counter; |
73 | a917d384 | pbrook | uint8_t *async_buf; |
74 | 4d611c9a | pbrook | uint32_t async_len; |
75 | 8b17de88 | blueswir1 | |
76 | 8b17de88 | blueswir1 | espdma_memory_read_write dma_memory_read; |
77 | 8b17de88 | blueswir1 | espdma_memory_read_write dma_memory_write; |
78 | 67e999be | bellard | void *dma_opaque;
|
79 | 4e9aec74 | pbrook | }; |
80 | 6f7e9aec | bellard | |
81 | 5ad6bb97 | blueswir1 | #define ESP_TCLO 0x0 |
82 | 5ad6bb97 | blueswir1 | #define ESP_TCMID 0x1 |
83 | 5ad6bb97 | blueswir1 | #define ESP_FIFO 0x2 |
84 | 5ad6bb97 | blueswir1 | #define ESP_CMD 0x3 |
85 | 5ad6bb97 | blueswir1 | #define ESP_RSTAT 0x4 |
86 | 5ad6bb97 | blueswir1 | #define ESP_WBUSID 0x4 |
87 | 5ad6bb97 | blueswir1 | #define ESP_RINTR 0x5 |
88 | 5ad6bb97 | blueswir1 | #define ESP_WSEL 0x5 |
89 | 5ad6bb97 | blueswir1 | #define ESP_RSEQ 0x6 |
90 | 5ad6bb97 | blueswir1 | #define ESP_WSYNTP 0x6 |
91 | 5ad6bb97 | blueswir1 | #define ESP_RFLAGS 0x7 |
92 | 5ad6bb97 | blueswir1 | #define ESP_WSYNO 0x7 |
93 | 5ad6bb97 | blueswir1 | #define ESP_CFG1 0x8 |
94 | 5ad6bb97 | blueswir1 | #define ESP_RRES1 0x9 |
95 | 5ad6bb97 | blueswir1 | #define ESP_WCCF 0x9 |
96 | 5ad6bb97 | blueswir1 | #define ESP_RRES2 0xa |
97 | 5ad6bb97 | blueswir1 | #define ESP_WTEST 0xa |
98 | 5ad6bb97 | blueswir1 | #define ESP_CFG2 0xb |
99 | 5ad6bb97 | blueswir1 | #define ESP_CFG3 0xc |
100 | 5ad6bb97 | blueswir1 | #define ESP_RES3 0xd |
101 | 5ad6bb97 | blueswir1 | #define ESP_TCHI 0xe |
102 | 5ad6bb97 | blueswir1 | #define ESP_RES4 0xf |
103 | 5ad6bb97 | blueswir1 | |
104 | 5ad6bb97 | blueswir1 | #define CMD_DMA 0x80 |
105 | 5ad6bb97 | blueswir1 | #define CMD_CMD 0x7f |
106 | 5ad6bb97 | blueswir1 | |
107 | 5ad6bb97 | blueswir1 | #define CMD_NOP 0x00 |
108 | 5ad6bb97 | blueswir1 | #define CMD_FLUSH 0x01 |
109 | 5ad6bb97 | blueswir1 | #define CMD_RESET 0x02 |
110 | 5ad6bb97 | blueswir1 | #define CMD_BUSRESET 0x03 |
111 | 5ad6bb97 | blueswir1 | #define CMD_TI 0x10 |
112 | 5ad6bb97 | blueswir1 | #define CMD_ICCS 0x11 |
113 | 5ad6bb97 | blueswir1 | #define CMD_MSGACC 0x12 |
114 | 5ad6bb97 | blueswir1 | #define CMD_SATN 0x1a |
115 | 5ad6bb97 | blueswir1 | #define CMD_SELATN 0x42 |
116 | 5ad6bb97 | blueswir1 | #define CMD_SELATNS 0x43 |
117 | 5ad6bb97 | blueswir1 | #define CMD_ENSEL 0x44 |
118 | 5ad6bb97 | blueswir1 | |
119 | 2f275b8f | bellard | #define STAT_DO 0x00 |
120 | 2f275b8f | bellard | #define STAT_DI 0x01 |
121 | 2f275b8f | bellard | #define STAT_CD 0x02 |
122 | 2f275b8f | bellard | #define STAT_ST 0x03 |
123 | 2f275b8f | bellard | #define STAT_MI 0x06 |
124 | 2f275b8f | bellard | #define STAT_MO 0x07 |
125 | 5ad6bb97 | blueswir1 | #define STAT_PIO_MASK 0x06 |
126 | 2f275b8f | bellard | |
127 | 2f275b8f | bellard | #define STAT_TC 0x10 |
128 | 4d611c9a | pbrook | #define STAT_PE 0x20 |
129 | 4d611c9a | pbrook | #define STAT_GE 0x40 |
130 | c73f96fd | blueswir1 | #define STAT_INT 0x80 |
131 | 2f275b8f | bellard | |
132 | 2f275b8f | bellard | #define INTR_FC 0x08 |
133 | 2f275b8f | bellard | #define INTR_BS 0x10 |
134 | 2f275b8f | bellard | #define INTR_DC 0x20 |
135 | 9e61bde5 | bellard | #define INTR_RST 0x80 |
136 | 2f275b8f | bellard | |
137 | 2f275b8f | bellard | #define SEQ_0 0x0 |
138 | 2f275b8f | bellard | #define SEQ_CD 0x4 |
139 | 2f275b8f | bellard | |
140 | 5ad6bb97 | blueswir1 | #define CFG1_RESREPT 0x40 |
141 | 5ad6bb97 | blueswir1 | |
142 | 5ad6bb97 | blueswir1 | #define CFG2_MASK 0x15 |
143 | 5ad6bb97 | blueswir1 | |
144 | 5ad6bb97 | blueswir1 | #define TCHI_FAS100A 0x4 |
145 | 5ad6bb97 | blueswir1 | |
146 | c73f96fd | blueswir1 | static void esp_raise_irq(ESPState *s) |
147 | c73f96fd | blueswir1 | { |
148 | c73f96fd | blueswir1 | if (!(s->rregs[ESP_RSTAT] & STAT_INT)) {
|
149 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_INT; |
150 | c73f96fd | blueswir1 | qemu_irq_raise(s->irq); |
151 | c73f96fd | blueswir1 | } |
152 | c73f96fd | blueswir1 | } |
153 | c73f96fd | blueswir1 | |
154 | c73f96fd | blueswir1 | static void esp_lower_irq(ESPState *s) |
155 | c73f96fd | blueswir1 | { |
156 | c73f96fd | blueswir1 | if (s->rregs[ESP_RSTAT] & STAT_INT) {
|
157 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] &= ~STAT_INT; |
158 | c73f96fd | blueswir1 | qemu_irq_lower(s->irq); |
159 | c73f96fd | blueswir1 | } |
160 | c73f96fd | blueswir1 | } |
161 | c73f96fd | blueswir1 | |
162 | 22548760 | blueswir1 | static uint32_t get_cmd(ESPState *s, uint8_t *buf)
|
163 | 2f275b8f | bellard | { |
164 | a917d384 | pbrook | uint32_t dmalen; |
165 | 2f275b8f | bellard | int target;
|
166 | 2f275b8f | bellard | |
167 | 5ad6bb97 | blueswir1 | dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8);
|
168 | 5ad6bb97 | blueswir1 | target = s->wregs[ESP_WBUSID] & 7;
|
169 | 9f149aa9 | pbrook | DPRINTF("get_cmd: len %d target %d\n", dmalen, target);
|
170 | 4f6200f0 | bellard | if (s->dma) {
|
171 | 8b17de88 | blueswir1 | s->dma_memory_read(s->dma_opaque, buf, dmalen); |
172 | 4f6200f0 | bellard | } else {
|
173 | f930d07e | blueswir1 | buf[0] = 0; |
174 | f930d07e | blueswir1 | memcpy(&buf[1], s->ti_buf, dmalen);
|
175 | f930d07e | blueswir1 | dmalen++; |
176 | 4f6200f0 | bellard | } |
177 | 2e5d83bb | pbrook | |
178 | 2f275b8f | bellard | s->ti_size = 0;
|
179 | 4f6200f0 | bellard | s->ti_rptr = 0;
|
180 | 4f6200f0 | bellard | s->ti_wptr = 0;
|
181 | 2f275b8f | bellard | |
182 | a917d384 | pbrook | if (s->current_dev) {
|
183 | a917d384 | pbrook | /* Started a new command before the old one finished. Cancel it. */
|
184 | 8ccc2ace | ths | s->current_dev->cancel_io(s->current_dev, 0);
|
185 | a917d384 | pbrook | s->async_len = 0;
|
186 | a917d384 | pbrook | } |
187 | a917d384 | pbrook | |
188 | e4bcb14c | ths | if (target >= ESP_MAX_DEVS || !s->scsi_dev[target]) {
|
189 | 2e5d83bb | pbrook | // No such drive
|
190 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = 0;
|
191 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_DC; |
192 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_0; |
193 | c73f96fd | blueswir1 | esp_raise_irq(s); |
194 | f930d07e | blueswir1 | return 0; |
195 | 2f275b8f | bellard | } |
196 | 2e5d83bb | pbrook | s->current_dev = s->scsi_dev[target]; |
197 | 9f149aa9 | pbrook | return dmalen;
|
198 | 9f149aa9 | pbrook | } |
199 | 9f149aa9 | pbrook | |
200 | 9f149aa9 | pbrook | static void do_cmd(ESPState *s, uint8_t *buf) |
201 | 9f149aa9 | pbrook | { |
202 | 9f149aa9 | pbrook | int32_t datalen; |
203 | 9f149aa9 | pbrook | int lun;
|
204 | 9f149aa9 | pbrook | |
205 | 9f149aa9 | pbrook | DPRINTF("do_cmd: busid 0x%x\n", buf[0]); |
206 | 9f149aa9 | pbrook | lun = buf[0] & 7; |
207 | 8ccc2ace | ths | datalen = s->current_dev->send_command(s->current_dev, 0, &buf[1], lun); |
208 | 67e999be | bellard | s->ti_size = datalen; |
209 | 67e999be | bellard | if (datalen != 0) { |
210 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = STAT_TC; |
211 | a917d384 | pbrook | s->dma_left = 0;
|
212 | 6787f5fa | pbrook | s->dma_counter = 0;
|
213 | 2e5d83bb | pbrook | if (datalen > 0) { |
214 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_DI; |
215 | 8ccc2ace | ths | s->current_dev->read_data(s->current_dev, 0);
|
216 | 2e5d83bb | pbrook | } else {
|
217 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_DO; |
218 | 8ccc2ace | ths | s->current_dev->write_data(s->current_dev, 0);
|
219 | b9788fc4 | bellard | } |
220 | 2f275b8f | bellard | } |
221 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS | INTR_FC; |
222 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_CD; |
223 | c73f96fd | blueswir1 | esp_raise_irq(s); |
224 | 2f275b8f | bellard | } |
225 | 2f275b8f | bellard | |
226 | 9f149aa9 | pbrook | static void handle_satn(ESPState *s) |
227 | 9f149aa9 | pbrook | { |
228 | 9f149aa9 | pbrook | uint8_t buf[32];
|
229 | 9f149aa9 | pbrook | int len;
|
230 | 9f149aa9 | pbrook | |
231 | 9f149aa9 | pbrook | len = get_cmd(s, buf); |
232 | 9f149aa9 | pbrook | if (len)
|
233 | 9f149aa9 | pbrook | do_cmd(s, buf); |
234 | 9f149aa9 | pbrook | } |
235 | 9f149aa9 | pbrook | |
236 | 9f149aa9 | pbrook | static void handle_satn_stop(ESPState *s) |
237 | 9f149aa9 | pbrook | { |
238 | 9f149aa9 | pbrook | s->cmdlen = get_cmd(s, s->cmdbuf); |
239 | 9f149aa9 | pbrook | if (s->cmdlen) {
|
240 | 9f149aa9 | pbrook | DPRINTF("Set ATN & Stop: cmdlen %d\n", s->cmdlen);
|
241 | 9f149aa9 | pbrook | s->do_cmd = 1;
|
242 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = STAT_TC | STAT_CD; |
243 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS | INTR_FC; |
244 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_CD; |
245 | c73f96fd | blueswir1 | esp_raise_irq(s); |
246 | 9f149aa9 | pbrook | } |
247 | 9f149aa9 | pbrook | } |
248 | 9f149aa9 | pbrook | |
249 | 0fc5c15a | pbrook | static void write_response(ESPState *s) |
250 | 2f275b8f | bellard | { |
251 | 0fc5c15a | pbrook | DPRINTF("Transfer status (sense=%d)\n", s->sense);
|
252 | 0fc5c15a | pbrook | s->ti_buf[0] = s->sense;
|
253 | 0fc5c15a | pbrook | s->ti_buf[1] = 0; |
254 | 4f6200f0 | bellard | if (s->dma) {
|
255 | 8b17de88 | blueswir1 | s->dma_memory_write(s->dma_opaque, s->ti_buf, 2);
|
256 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = STAT_TC | STAT_ST; |
257 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS | INTR_FC; |
258 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_CD; |
259 | 4f6200f0 | bellard | } else {
|
260 | f930d07e | blueswir1 | s->ti_size = 2;
|
261 | f930d07e | blueswir1 | s->ti_rptr = 0;
|
262 | f930d07e | blueswir1 | s->ti_wptr = 0;
|
263 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RFLAGS] = 2;
|
264 | 4f6200f0 | bellard | } |
265 | c73f96fd | blueswir1 | esp_raise_irq(s); |
266 | 2f275b8f | bellard | } |
267 | 4f6200f0 | bellard | |
268 | a917d384 | pbrook | static void esp_dma_done(ESPState *s) |
269 | a917d384 | pbrook | { |
270 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_TC; |
271 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS; |
272 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = 0;
|
273 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RFLAGS] = 0;
|
274 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCLO] = 0;
|
275 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCMID] = 0;
|
276 | c73f96fd | blueswir1 | esp_raise_irq(s); |
277 | a917d384 | pbrook | } |
278 | a917d384 | pbrook | |
279 | 4d611c9a | pbrook | static void esp_do_dma(ESPState *s) |
280 | 4d611c9a | pbrook | { |
281 | 67e999be | bellard | uint32_t len; |
282 | 4d611c9a | pbrook | int to_device;
|
283 | a917d384 | pbrook | |
284 | 67e999be | bellard | to_device = (s->ti_size < 0);
|
285 | a917d384 | pbrook | len = s->dma_left; |
286 | 4d611c9a | pbrook | if (s->do_cmd) {
|
287 | 4d611c9a | pbrook | DPRINTF("command len %d + %d\n", s->cmdlen, len);
|
288 | 8b17de88 | blueswir1 | s->dma_memory_read(s->dma_opaque, &s->cmdbuf[s->cmdlen], len); |
289 | 4d611c9a | pbrook | s->ti_size = 0;
|
290 | 4d611c9a | pbrook | s->cmdlen = 0;
|
291 | 4d611c9a | pbrook | s->do_cmd = 0;
|
292 | 4d611c9a | pbrook | do_cmd(s, s->cmdbuf); |
293 | 4d611c9a | pbrook | return;
|
294 | a917d384 | pbrook | } |
295 | a917d384 | pbrook | if (s->async_len == 0) { |
296 | a917d384 | pbrook | /* Defer until data is available. */
|
297 | a917d384 | pbrook | return;
|
298 | a917d384 | pbrook | } |
299 | a917d384 | pbrook | if (len > s->async_len) {
|
300 | a917d384 | pbrook | len = s->async_len; |
301 | a917d384 | pbrook | } |
302 | a917d384 | pbrook | if (to_device) {
|
303 | 8b17de88 | blueswir1 | s->dma_memory_read(s->dma_opaque, s->async_buf, len); |
304 | 4d611c9a | pbrook | } else {
|
305 | 8b17de88 | blueswir1 | s->dma_memory_write(s->dma_opaque, s->async_buf, len); |
306 | a917d384 | pbrook | } |
307 | a917d384 | pbrook | s->dma_left -= len; |
308 | a917d384 | pbrook | s->async_buf += len; |
309 | a917d384 | pbrook | s->async_len -= len; |
310 | 6787f5fa | pbrook | if (to_device)
|
311 | 6787f5fa | pbrook | s->ti_size += len; |
312 | 6787f5fa | pbrook | else
|
313 | 6787f5fa | pbrook | s->ti_size -= len; |
314 | a917d384 | pbrook | if (s->async_len == 0) { |
315 | 4d611c9a | pbrook | if (to_device) {
|
316 | 67e999be | bellard | // ti_size is negative
|
317 | 8ccc2ace | ths | s->current_dev->write_data(s->current_dev, 0);
|
318 | 4d611c9a | pbrook | } else {
|
319 | 8ccc2ace | ths | s->current_dev->read_data(s->current_dev, 0);
|
320 | 6787f5fa | pbrook | /* If there is still data to be read from the device then
|
321 | 6787f5fa | pbrook | complete the DMA operation immeriately. Otherwise defer
|
322 | 6787f5fa | pbrook | until the scsi layer has completed. */
|
323 | 6787f5fa | pbrook | if (s->dma_left == 0 && s->ti_size > 0) { |
324 | 6787f5fa | pbrook | esp_dma_done(s); |
325 | 6787f5fa | pbrook | } |
326 | 4d611c9a | pbrook | } |
327 | 6787f5fa | pbrook | } else {
|
328 | 6787f5fa | pbrook | /* Partially filled a scsi buffer. Complete immediately. */
|
329 | a917d384 | pbrook | esp_dma_done(s); |
330 | a917d384 | pbrook | } |
331 | 4d611c9a | pbrook | } |
332 | 4d611c9a | pbrook | |
333 | a917d384 | pbrook | static void esp_command_complete(void *opaque, int reason, uint32_t tag, |
334 | a917d384 | pbrook | uint32_t arg) |
335 | 2e5d83bb | pbrook | { |
336 | 2e5d83bb | pbrook | ESPState *s = (ESPState *)opaque; |
337 | 2e5d83bb | pbrook | |
338 | 4d611c9a | pbrook | if (reason == SCSI_REASON_DONE) {
|
339 | 4d611c9a | pbrook | DPRINTF("SCSI Command complete\n");
|
340 | 4d611c9a | pbrook | if (s->ti_size != 0) |
341 | 4d611c9a | pbrook | DPRINTF("SCSI command completed unexpectedly\n");
|
342 | 4d611c9a | pbrook | s->ti_size = 0;
|
343 | a917d384 | pbrook | s->dma_left = 0;
|
344 | a917d384 | pbrook | s->async_len = 0;
|
345 | a917d384 | pbrook | if (arg)
|
346 | 4d611c9a | pbrook | DPRINTF("Command failed\n");
|
347 | a917d384 | pbrook | s->sense = arg; |
348 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] = STAT_ST; |
349 | a917d384 | pbrook | esp_dma_done(s); |
350 | a917d384 | pbrook | s->current_dev = NULL;
|
351 | 4d611c9a | pbrook | } else {
|
352 | 4d611c9a | pbrook | DPRINTF("transfer %d/%d\n", s->dma_left, s->ti_size);
|
353 | a917d384 | pbrook | s->async_len = arg; |
354 | 8ccc2ace | ths | s->async_buf = s->current_dev->get_buf(s->current_dev, 0);
|
355 | 6787f5fa | pbrook | if (s->dma_left) {
|
356 | a917d384 | pbrook | esp_do_dma(s); |
357 | 6787f5fa | pbrook | } else if (s->dma_counter != 0 && s->ti_size <= 0) { |
358 | 6787f5fa | pbrook | /* If this was the last part of a DMA transfer then the
|
359 | 6787f5fa | pbrook | completion interrupt is deferred to here. */
|
360 | 6787f5fa | pbrook | esp_dma_done(s); |
361 | 6787f5fa | pbrook | } |
362 | 4d611c9a | pbrook | } |
363 | 2e5d83bb | pbrook | } |
364 | 2e5d83bb | pbrook | |
365 | 2f275b8f | bellard | static void handle_ti(ESPState *s) |
366 | 2f275b8f | bellard | { |
367 | 4d611c9a | pbrook | uint32_t dmalen, minlen; |
368 | 2f275b8f | bellard | |
369 | 5ad6bb97 | blueswir1 | dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8);
|
370 | db59203d | pbrook | if (dmalen==0) { |
371 | db59203d | pbrook | dmalen=0x10000;
|
372 | db59203d | pbrook | } |
373 | 6787f5fa | pbrook | s->dma_counter = dmalen; |
374 | db59203d | pbrook | |
375 | 9f149aa9 | pbrook | if (s->do_cmd)
|
376 | 9f149aa9 | pbrook | minlen = (dmalen < 32) ? dmalen : 32; |
377 | 67e999be | bellard | else if (s->ti_size < 0) |
378 | 67e999be | bellard | minlen = (dmalen < -s->ti_size) ? dmalen : -s->ti_size; |
379 | 9f149aa9 | pbrook | else
|
380 | 9f149aa9 | pbrook | minlen = (dmalen < s->ti_size) ? dmalen : s->ti_size; |
381 | db59203d | pbrook | DPRINTF("Transfer Information len %d\n", minlen);
|
382 | 4f6200f0 | bellard | if (s->dma) {
|
383 | 4d611c9a | pbrook | s->dma_left = minlen; |
384 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] &= ~STAT_TC; |
385 | 4d611c9a | pbrook | esp_do_dma(s); |
386 | 9f149aa9 | pbrook | } else if (s->do_cmd) { |
387 | 9f149aa9 | pbrook | DPRINTF("command len %d\n", s->cmdlen);
|
388 | 9f149aa9 | pbrook | s->ti_size = 0;
|
389 | 9f149aa9 | pbrook | s->cmdlen = 0;
|
390 | 9f149aa9 | pbrook | s->do_cmd = 0;
|
391 | 9f149aa9 | pbrook | do_cmd(s, s->cmdbuf); |
392 | 9f149aa9 | pbrook | return;
|
393 | 9f149aa9 | pbrook | } |
394 | 2f275b8f | bellard | } |
395 | 2f275b8f | bellard | |
396 | 5aca8c3b | blueswir1 | static void esp_reset(void *opaque) |
397 | 6f7e9aec | bellard | { |
398 | 6f7e9aec | bellard | ESPState *s = opaque; |
399 | 67e999be | bellard | |
400 | c73f96fd | blueswir1 | esp_lower_irq(s); |
401 | c73f96fd | blueswir1 | |
402 | 5aca8c3b | blueswir1 | memset(s->rregs, 0, ESP_REGS);
|
403 | 5aca8c3b | blueswir1 | memset(s->wregs, 0, ESP_REGS);
|
404 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCHI] = TCHI_FAS100A; // Indicate fas100a
|
405 | 4e9aec74 | pbrook | s->ti_size = 0;
|
406 | 4e9aec74 | pbrook | s->ti_rptr = 0;
|
407 | 4e9aec74 | pbrook | s->ti_wptr = 0;
|
408 | 4e9aec74 | pbrook | s->dma = 0;
|
409 | 9f149aa9 | pbrook | s->do_cmd = 0;
|
410 | 6f7e9aec | bellard | } |
411 | 6f7e9aec | bellard | |
412 | 2d069bab | blueswir1 | static void parent_esp_reset(void *opaque, int irq, int level) |
413 | 2d069bab | blueswir1 | { |
414 | 2d069bab | blueswir1 | if (level)
|
415 | 2d069bab | blueswir1 | esp_reset(opaque); |
416 | 2d069bab | blueswir1 | } |
417 | 2d069bab | blueswir1 | |
418 | 6f7e9aec | bellard | static uint32_t esp_mem_readb(void *opaque, target_phys_addr_t addr) |
419 | 6f7e9aec | bellard | { |
420 | 6f7e9aec | bellard | ESPState *s = opaque; |
421 | 6f7e9aec | bellard | uint32_t saddr; |
422 | 6f7e9aec | bellard | |
423 | 5d20fa6b | blueswir1 | saddr = (addr >> s->it_shift) & (ESP_REGS - 1);
|
424 | 9e61bde5 | bellard | DPRINTF("read reg[%d]: 0x%2.2x\n", saddr, s->rregs[saddr]);
|
425 | 6f7e9aec | bellard | switch (saddr) {
|
426 | 5ad6bb97 | blueswir1 | case ESP_FIFO:
|
427 | f930d07e | blueswir1 | if (s->ti_size > 0) { |
428 | f930d07e | blueswir1 | s->ti_size--; |
429 | 5ad6bb97 | blueswir1 | if ((s->rregs[ESP_RSTAT] & STAT_PIO_MASK) == 0) { |
430 | 2e5d83bb | pbrook | /* Data in/out. */
|
431 | a917d384 | pbrook | fprintf(stderr, "esp: PIO data read not implemented\n");
|
432 | 5ad6bb97 | blueswir1 | s->rregs[ESP_FIFO] = 0;
|
433 | 2e5d83bb | pbrook | } else {
|
434 | 5ad6bb97 | blueswir1 | s->rregs[ESP_FIFO] = s->ti_buf[s->ti_rptr++]; |
435 | 2e5d83bb | pbrook | } |
436 | c73f96fd | blueswir1 | esp_raise_irq(s); |
437 | f930d07e | blueswir1 | } |
438 | f930d07e | blueswir1 | if (s->ti_size == 0) { |
439 | 4f6200f0 | bellard | s->ti_rptr = 0;
|
440 | 4f6200f0 | bellard | s->ti_wptr = 0;
|
441 | 4f6200f0 | bellard | } |
442 | f930d07e | blueswir1 | break;
|
443 | 5ad6bb97 | blueswir1 | case ESP_RINTR:
|
444 | 4d611c9a | pbrook | // Clear interrupt/error status bits
|
445 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] &= ~(STAT_GE | STAT_PE); |
446 | c73f96fd | blueswir1 | esp_lower_irq(s); |
447 | 9e61bde5 | bellard | break;
|
448 | 6f7e9aec | bellard | default:
|
449 | f930d07e | blueswir1 | break;
|
450 | 6f7e9aec | bellard | } |
451 | 2f275b8f | bellard | return s->rregs[saddr];
|
452 | 6f7e9aec | bellard | } |
453 | 6f7e9aec | bellard | |
454 | 6f7e9aec | bellard | static void esp_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
455 | 6f7e9aec | bellard | { |
456 | 6f7e9aec | bellard | ESPState *s = opaque; |
457 | 6f7e9aec | bellard | uint32_t saddr; |
458 | 6f7e9aec | bellard | |
459 | 5d20fa6b | blueswir1 | saddr = (addr >> s->it_shift) & (ESP_REGS - 1);
|
460 | 5ad6bb97 | blueswir1 | DPRINTF("write reg[%d]: 0x%2.2x -> 0x%2.2x\n", saddr, s->wregs[saddr],
|
461 | 5ad6bb97 | blueswir1 | val); |
462 | 6f7e9aec | bellard | switch (saddr) {
|
463 | 5ad6bb97 | blueswir1 | case ESP_TCLO:
|
464 | 5ad6bb97 | blueswir1 | case ESP_TCMID:
|
465 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] &= ~STAT_TC; |
466 | 4f6200f0 | bellard | break;
|
467 | 5ad6bb97 | blueswir1 | case ESP_FIFO:
|
468 | 9f149aa9 | pbrook | if (s->do_cmd) {
|
469 | 9f149aa9 | pbrook | s->cmdbuf[s->cmdlen++] = val & 0xff;
|
470 | 5ad6bb97 | blueswir1 | } else if ((s->rregs[ESP_RSTAT] & STAT_PIO_MASK) == 0) { |
471 | 2e5d83bb | pbrook | uint8_t buf; |
472 | 2e5d83bb | pbrook | buf = val & 0xff;
|
473 | 2e5d83bb | pbrook | s->ti_size--; |
474 | a917d384 | pbrook | fprintf(stderr, "esp: PIO data write not implemented\n");
|
475 | 2e5d83bb | pbrook | } else {
|
476 | 2e5d83bb | pbrook | s->ti_size++; |
477 | 2e5d83bb | pbrook | s->ti_buf[s->ti_wptr++] = val & 0xff;
|
478 | 2e5d83bb | pbrook | } |
479 | f930d07e | blueswir1 | break;
|
480 | 5ad6bb97 | blueswir1 | case ESP_CMD:
|
481 | 4f6200f0 | bellard | s->rregs[saddr] = val; |
482 | 5ad6bb97 | blueswir1 | if (val & CMD_DMA) {
|
483 | f930d07e | blueswir1 | s->dma = 1;
|
484 | 6787f5fa | pbrook | /* Reload DMA counter. */
|
485 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCLO] = s->wregs[ESP_TCLO]; |
486 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCMID] = s->wregs[ESP_TCMID]; |
487 | f930d07e | blueswir1 | } else {
|
488 | f930d07e | blueswir1 | s->dma = 0;
|
489 | f930d07e | blueswir1 | } |
490 | 5ad6bb97 | blueswir1 | switch(val & CMD_CMD) {
|
491 | 5ad6bb97 | blueswir1 | case CMD_NOP:
|
492 | f930d07e | blueswir1 | DPRINTF("NOP (%2.2x)\n", val);
|
493 | f930d07e | blueswir1 | break;
|
494 | 5ad6bb97 | blueswir1 | case CMD_FLUSH:
|
495 | f930d07e | blueswir1 | DPRINTF("Flush FIFO (%2.2x)\n", val);
|
496 | 9e61bde5 | bellard | //s->ti_size = 0;
|
497 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_FC; |
498 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = 0;
|
499 | a214c598 | blueswir1 | s->rregs[ESP_RFLAGS] = 0;
|
500 | f930d07e | blueswir1 | break;
|
501 | 5ad6bb97 | blueswir1 | case CMD_RESET:
|
502 | f930d07e | blueswir1 | DPRINTF("Chip reset (%2.2x)\n", val);
|
503 | f930d07e | blueswir1 | esp_reset(s); |
504 | f930d07e | blueswir1 | break;
|
505 | 5ad6bb97 | blueswir1 | case CMD_BUSRESET:
|
506 | f930d07e | blueswir1 | DPRINTF("Bus reset (%2.2x)\n", val);
|
507 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_RST; |
508 | 5ad6bb97 | blueswir1 | if (!(s->wregs[ESP_CFG1] & CFG1_RESREPT)) {
|
509 | c73f96fd | blueswir1 | esp_raise_irq(s); |
510 | 9e61bde5 | bellard | } |
511 | f930d07e | blueswir1 | break;
|
512 | 5ad6bb97 | blueswir1 | case CMD_TI:
|
513 | f930d07e | blueswir1 | handle_ti(s); |
514 | f930d07e | blueswir1 | break;
|
515 | 5ad6bb97 | blueswir1 | case CMD_ICCS:
|
516 | f930d07e | blueswir1 | DPRINTF("Initiator Command Complete Sequence (%2.2x)\n", val);
|
517 | f930d07e | blueswir1 | write_response(s); |
518 | f930d07e | blueswir1 | break;
|
519 | 5ad6bb97 | blueswir1 | case CMD_MSGACC:
|
520 | f930d07e | blueswir1 | DPRINTF("Message Accepted (%2.2x)\n", val);
|
521 | f930d07e | blueswir1 | write_response(s); |
522 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_DC; |
523 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = 0;
|
524 | f930d07e | blueswir1 | break;
|
525 | 5ad6bb97 | blueswir1 | case CMD_SATN:
|
526 | f930d07e | blueswir1 | DPRINTF("Set ATN (%2.2x)\n", val);
|
527 | f930d07e | blueswir1 | break;
|
528 | 5ad6bb97 | blueswir1 | case CMD_SELATN:
|
529 | f930d07e | blueswir1 | DPRINTF("Set ATN (%2.2x)\n", val);
|
530 | f930d07e | blueswir1 | handle_satn(s); |
531 | f930d07e | blueswir1 | break;
|
532 | 5ad6bb97 | blueswir1 | case CMD_SELATNS:
|
533 | f930d07e | blueswir1 | DPRINTF("Set ATN & stop (%2.2x)\n", val);
|
534 | f930d07e | blueswir1 | handle_satn_stop(s); |
535 | f930d07e | blueswir1 | break;
|
536 | 5ad6bb97 | blueswir1 | case CMD_ENSEL:
|
537 | 74ec6048 | blueswir1 | DPRINTF("Enable selection (%2.2x)\n", val);
|
538 | 74ec6048 | blueswir1 | break;
|
539 | f930d07e | blueswir1 | default:
|
540 | f930d07e | blueswir1 | DPRINTF("Unhandled ESP command (%2.2x)\n", val);
|
541 | f930d07e | blueswir1 | break;
|
542 | f930d07e | blueswir1 | } |
543 | f930d07e | blueswir1 | break;
|
544 | 5ad6bb97 | blueswir1 | case ESP_WBUSID ... ESP_WSYNO:
|
545 | f930d07e | blueswir1 | break;
|
546 | 5ad6bb97 | blueswir1 | case ESP_CFG1:
|
547 | 4f6200f0 | bellard | s->rregs[saddr] = val; |
548 | 4f6200f0 | bellard | break;
|
549 | 5ad6bb97 | blueswir1 | case ESP_WCCF ... ESP_WTEST:
|
550 | 4f6200f0 | bellard | break;
|
551 | 5ad6bb97 | blueswir1 | case ESP_CFG2:
|
552 | 5ad6bb97 | blueswir1 | s->rregs[saddr] = val & CFG2_MASK; |
553 | 9e61bde5 | bellard | break;
|
554 | 5ad6bb97 | blueswir1 | case ESP_CFG3 ... ESP_RES4:
|
555 | 4f6200f0 | bellard | s->rregs[saddr] = val; |
556 | 4f6200f0 | bellard | break;
|
557 | 6f7e9aec | bellard | default:
|
558 | f930d07e | blueswir1 | break;
|
559 | 6f7e9aec | bellard | } |
560 | 2f275b8f | bellard | s->wregs[saddr] = val; |
561 | 6f7e9aec | bellard | } |
562 | 6f7e9aec | bellard | |
563 | 6f7e9aec | bellard | static CPUReadMemoryFunc *esp_mem_read[3] = { |
564 | 6f7e9aec | bellard | esp_mem_readb, |
565 | 7c560456 | blueswir1 | NULL,
|
566 | 7c560456 | blueswir1 | NULL,
|
567 | 6f7e9aec | bellard | }; |
568 | 6f7e9aec | bellard | |
569 | 6f7e9aec | bellard | static CPUWriteMemoryFunc *esp_mem_write[3] = { |
570 | 6f7e9aec | bellard | esp_mem_writeb, |
571 | 7c560456 | blueswir1 | NULL,
|
572 | 7c560456 | blueswir1 | NULL,
|
573 | 6f7e9aec | bellard | }; |
574 | 6f7e9aec | bellard | |
575 | 6f7e9aec | bellard | static void esp_save(QEMUFile *f, void *opaque) |
576 | 6f7e9aec | bellard | { |
577 | 6f7e9aec | bellard | ESPState *s = opaque; |
578 | 2f275b8f | bellard | |
579 | 5aca8c3b | blueswir1 | qemu_put_buffer(f, s->rregs, ESP_REGS); |
580 | 5aca8c3b | blueswir1 | qemu_put_buffer(f, s->wregs, ESP_REGS); |
581 | cce40fcc | blueswir1 | qemu_put_be32s(f, (uint32_t *)&s->ti_size); |
582 | 4f6200f0 | bellard | qemu_put_be32s(f, &s->ti_rptr); |
583 | 4f6200f0 | bellard | qemu_put_be32s(f, &s->ti_wptr); |
584 | 4f6200f0 | bellard | qemu_put_buffer(f, s->ti_buf, TI_BUFSZ); |
585 | 5425a216 | blueswir1 | qemu_put_be32s(f, &s->sense); |
586 | 4f6200f0 | bellard | qemu_put_be32s(f, &s->dma); |
587 | 5425a216 | blueswir1 | qemu_put_buffer(f, s->cmdbuf, TI_BUFSZ); |
588 | 5425a216 | blueswir1 | qemu_put_be32s(f, &s->cmdlen); |
589 | 5425a216 | blueswir1 | qemu_put_be32s(f, &s->do_cmd); |
590 | 5425a216 | blueswir1 | qemu_put_be32s(f, &s->dma_left); |
591 | 5425a216 | blueswir1 | // There should be no transfers in progress, so dma_counter is not saved
|
592 | 6f7e9aec | bellard | } |
593 | 6f7e9aec | bellard | |
594 | 6f7e9aec | bellard | static int esp_load(QEMUFile *f, void *opaque, int version_id) |
595 | 6f7e9aec | bellard | { |
596 | 6f7e9aec | bellard | ESPState *s = opaque; |
597 | 3b46e624 | ths | |
598 | 5425a216 | blueswir1 | if (version_id != 3) |
599 | 5425a216 | blueswir1 | return -EINVAL; // Cannot emulate 2 |
600 | 6f7e9aec | bellard | |
601 | 5aca8c3b | blueswir1 | qemu_get_buffer(f, s->rregs, ESP_REGS); |
602 | 5aca8c3b | blueswir1 | qemu_get_buffer(f, s->wregs, ESP_REGS); |
603 | cce40fcc | blueswir1 | qemu_get_be32s(f, (uint32_t *)&s->ti_size); |
604 | 4f6200f0 | bellard | qemu_get_be32s(f, &s->ti_rptr); |
605 | 4f6200f0 | bellard | qemu_get_be32s(f, &s->ti_wptr); |
606 | 4f6200f0 | bellard | qemu_get_buffer(f, s->ti_buf, TI_BUFSZ); |
607 | 5425a216 | blueswir1 | qemu_get_be32s(f, &s->sense); |
608 | 4f6200f0 | bellard | qemu_get_be32s(f, &s->dma); |
609 | 5425a216 | blueswir1 | qemu_get_buffer(f, s->cmdbuf, TI_BUFSZ); |
610 | 5425a216 | blueswir1 | qemu_get_be32s(f, &s->cmdlen); |
611 | 5425a216 | blueswir1 | qemu_get_be32s(f, &s->do_cmd); |
612 | 5425a216 | blueswir1 | qemu_get_be32s(f, &s->dma_left); |
613 | 2f275b8f | bellard | |
614 | 6f7e9aec | bellard | return 0; |
615 | 6f7e9aec | bellard | } |
616 | 6f7e9aec | bellard | |
617 | fa1fb14c | ths | void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id) |
618 | fa1fb14c | ths | { |
619 | fa1fb14c | ths | ESPState *s = (ESPState *)opaque; |
620 | fa1fb14c | ths | |
621 | fa1fb14c | ths | if (id < 0) { |
622 | fa1fb14c | ths | for (id = 0; id < ESP_MAX_DEVS; id++) { |
623 | fa1fb14c | ths | if (s->scsi_dev[id] == NULL) |
624 | fa1fb14c | ths | break;
|
625 | fa1fb14c | ths | } |
626 | fa1fb14c | ths | } |
627 | fa1fb14c | ths | if (id >= ESP_MAX_DEVS) {
|
628 | fa1fb14c | ths | DPRINTF("Bad Device ID %d\n", id);
|
629 | fa1fb14c | ths | return;
|
630 | fa1fb14c | ths | } |
631 | fa1fb14c | ths | if (s->scsi_dev[id]) {
|
632 | fa1fb14c | ths | DPRINTF("Destroying device %d\n", id);
|
633 | 8ccc2ace | ths | s->scsi_dev[id]->destroy(s->scsi_dev[id]); |
634 | fa1fb14c | ths | } |
635 | fa1fb14c | ths | DPRINTF("Attaching block device %d\n", id);
|
636 | fa1fb14c | ths | /* Command queueing is not implemented. */
|
637 | 985a03b0 | ths | s->scsi_dev[id] = scsi_generic_init(bd, 0, esp_command_complete, s);
|
638 | 985a03b0 | ths | if (s->scsi_dev[id] == NULL) |
639 | 985a03b0 | ths | s->scsi_dev[id] = scsi_disk_init(bd, 0, esp_command_complete, s);
|
640 | fa1fb14c | ths | } |
641 | fa1fb14c | ths | |
642 | 5d20fa6b | blueswir1 | void *esp_init(target_phys_addr_t espaddr, int it_shift, |
643 | 8b17de88 | blueswir1 | espdma_memory_read_write dma_memory_read, |
644 | 8b17de88 | blueswir1 | espdma_memory_read_write dma_memory_write, |
645 | 2d069bab | blueswir1 | void *dma_opaque, qemu_irq irq, qemu_irq *reset)
|
646 | 6f7e9aec | bellard | { |
647 | 6f7e9aec | bellard | ESPState *s; |
648 | 67e999be | bellard | int esp_io_memory;
|
649 | 6f7e9aec | bellard | |
650 | 6f7e9aec | bellard | s = qemu_mallocz(sizeof(ESPState));
|
651 | 6f7e9aec | bellard | if (!s)
|
652 | 67e999be | bellard | return NULL; |
653 | 6f7e9aec | bellard | |
654 | 70c0de96 | blueswir1 | s->irq = irq; |
655 | 5d20fa6b | blueswir1 | s->it_shift = it_shift; |
656 | 8b17de88 | blueswir1 | s->dma_memory_read = dma_memory_read; |
657 | 8b17de88 | blueswir1 | s->dma_memory_write = dma_memory_write; |
658 | 67e999be | bellard | s->dma_opaque = dma_opaque; |
659 | 6f7e9aec | bellard | |
660 | 6f7e9aec | bellard | esp_io_memory = cpu_register_io_memory(0, esp_mem_read, esp_mem_write, s);
|
661 | 5d20fa6b | blueswir1 | cpu_register_physical_memory(espaddr, ESP_REGS << it_shift, esp_io_memory); |
662 | 6f7e9aec | bellard | |
663 | 6f7e9aec | bellard | esp_reset(s); |
664 | 6f7e9aec | bellard | |
665 | 5425a216 | blueswir1 | register_savevm("esp", espaddr, 3, esp_save, esp_load, s); |
666 | 6f7e9aec | bellard | qemu_register_reset(esp_reset, s); |
667 | 6f7e9aec | bellard | |
668 | 2d069bab | blueswir1 | *reset = *qemu_allocate_irqs(parent_esp_reset, s, 1);
|
669 | 2d069bab | blueswir1 | |
670 | 67e999be | bellard | return s;
|
671 | 67e999be | bellard | } |