root / hw / esp.c @ 636aa70a
History | View | Annotate | Download (18.6 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 | cfb9de9c | Paul Brook | #include "sysbus.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 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) \
|
42 | 001faf32 | Blue Swirl | do { printf("ESP: " fmt , ## __VA_ARGS__); } while (0) |
43 | 6f7e9aec | bellard | #else
|
44 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) do {} while (0) |
45 | 6f7e9aec | bellard | #endif
|
46 | 6f7e9aec | bellard | |
47 | 001faf32 | Blue Swirl | #define ESP_ERROR(fmt, ...) \
|
48 | 001faf32 | Blue Swirl | do { printf("ESP ERROR: %s: " fmt, __func__ , ## __VA_ARGS__); } while (0) |
49 | 8dea1dd4 | blueswir1 | |
50 | 5aca8c3b | blueswir1 | #define ESP_REGS 16 |
51 | 8dea1dd4 | blueswir1 | #define TI_BUFSZ 16 |
52 | 67e999be | bellard | |
53 | 4e9aec74 | pbrook | typedef struct ESPState ESPState; |
54 | 6f7e9aec | bellard | |
55 | 4e9aec74 | pbrook | struct ESPState {
|
56 | cfb9de9c | Paul Brook | SysBusDevice busdev; |
57 | 5d20fa6b | blueswir1 | uint32_t it_shift; |
58 | 70c0de96 | blueswir1 | qemu_irq irq; |
59 | 5aca8c3b | blueswir1 | uint8_t rregs[ESP_REGS]; |
60 | 5aca8c3b | blueswir1 | uint8_t wregs[ESP_REGS]; |
61 | 67e999be | bellard | int32_t ti_size; |
62 | 4f6200f0 | bellard | uint32_t ti_rptr, ti_wptr; |
63 | 4f6200f0 | bellard | uint8_t ti_buf[TI_BUFSZ]; |
64 | 22548760 | blueswir1 | uint32_t sense; |
65 | 22548760 | blueswir1 | uint32_t dma; |
66 | e4bcb14c | ths | SCSIDevice *scsi_dev[ESP_MAX_DEVS]; |
67 | 2e5d83bb | pbrook | SCSIDevice *current_dev; |
68 | 9f149aa9 | pbrook | uint8_t cmdbuf[TI_BUFSZ]; |
69 | 22548760 | blueswir1 | uint32_t cmdlen; |
70 | 22548760 | blueswir1 | uint32_t do_cmd; |
71 | 4d611c9a | pbrook | |
72 | 6787f5fa | pbrook | /* The amount of data left in the current DMA transfer. */
|
73 | 4d611c9a | pbrook | uint32_t dma_left; |
74 | 6787f5fa | pbrook | /* The size of the current DMA transfer. Zero if no transfer is in
|
75 | 6787f5fa | pbrook | progress. */
|
76 | 6787f5fa | pbrook | uint32_t dma_counter; |
77 | a917d384 | pbrook | uint8_t *async_buf; |
78 | 4d611c9a | pbrook | uint32_t async_len; |
79 | 8b17de88 | blueswir1 | |
80 | 8b17de88 | blueswir1 | espdma_memory_read_write dma_memory_read; |
81 | 8b17de88 | blueswir1 | espdma_memory_read_write dma_memory_write; |
82 | 67e999be | bellard | void *dma_opaque;
|
83 | 4e9aec74 | pbrook | }; |
84 | 6f7e9aec | bellard | |
85 | 5ad6bb97 | blueswir1 | #define ESP_TCLO 0x0 |
86 | 5ad6bb97 | blueswir1 | #define ESP_TCMID 0x1 |
87 | 5ad6bb97 | blueswir1 | #define ESP_FIFO 0x2 |
88 | 5ad6bb97 | blueswir1 | #define ESP_CMD 0x3 |
89 | 5ad6bb97 | blueswir1 | #define ESP_RSTAT 0x4 |
90 | 5ad6bb97 | blueswir1 | #define ESP_WBUSID 0x4 |
91 | 5ad6bb97 | blueswir1 | #define ESP_RINTR 0x5 |
92 | 5ad6bb97 | blueswir1 | #define ESP_WSEL 0x5 |
93 | 5ad6bb97 | blueswir1 | #define ESP_RSEQ 0x6 |
94 | 5ad6bb97 | blueswir1 | #define ESP_WSYNTP 0x6 |
95 | 5ad6bb97 | blueswir1 | #define ESP_RFLAGS 0x7 |
96 | 5ad6bb97 | blueswir1 | #define ESP_WSYNO 0x7 |
97 | 5ad6bb97 | blueswir1 | #define ESP_CFG1 0x8 |
98 | 5ad6bb97 | blueswir1 | #define ESP_RRES1 0x9 |
99 | 5ad6bb97 | blueswir1 | #define ESP_WCCF 0x9 |
100 | 5ad6bb97 | blueswir1 | #define ESP_RRES2 0xa |
101 | 5ad6bb97 | blueswir1 | #define ESP_WTEST 0xa |
102 | 5ad6bb97 | blueswir1 | #define ESP_CFG2 0xb |
103 | 5ad6bb97 | blueswir1 | #define ESP_CFG3 0xc |
104 | 5ad6bb97 | blueswir1 | #define ESP_RES3 0xd |
105 | 5ad6bb97 | blueswir1 | #define ESP_TCHI 0xe |
106 | 5ad6bb97 | blueswir1 | #define ESP_RES4 0xf |
107 | 5ad6bb97 | blueswir1 | |
108 | 5ad6bb97 | blueswir1 | #define CMD_DMA 0x80 |
109 | 5ad6bb97 | blueswir1 | #define CMD_CMD 0x7f |
110 | 5ad6bb97 | blueswir1 | |
111 | 5ad6bb97 | blueswir1 | #define CMD_NOP 0x00 |
112 | 5ad6bb97 | blueswir1 | #define CMD_FLUSH 0x01 |
113 | 5ad6bb97 | blueswir1 | #define CMD_RESET 0x02 |
114 | 5ad6bb97 | blueswir1 | #define CMD_BUSRESET 0x03 |
115 | 5ad6bb97 | blueswir1 | #define CMD_TI 0x10 |
116 | 5ad6bb97 | blueswir1 | #define CMD_ICCS 0x11 |
117 | 5ad6bb97 | blueswir1 | #define CMD_MSGACC 0x12 |
118 | 5ad6bb97 | blueswir1 | #define CMD_SATN 0x1a |
119 | 5ad6bb97 | blueswir1 | #define CMD_SELATN 0x42 |
120 | 5ad6bb97 | blueswir1 | #define CMD_SELATNS 0x43 |
121 | 5ad6bb97 | blueswir1 | #define CMD_ENSEL 0x44 |
122 | 5ad6bb97 | blueswir1 | |
123 | 2f275b8f | bellard | #define STAT_DO 0x00 |
124 | 2f275b8f | bellard | #define STAT_DI 0x01 |
125 | 2f275b8f | bellard | #define STAT_CD 0x02 |
126 | 2f275b8f | bellard | #define STAT_ST 0x03 |
127 | 8dea1dd4 | blueswir1 | #define STAT_MO 0x06 |
128 | 8dea1dd4 | blueswir1 | #define STAT_MI 0x07 |
129 | 5ad6bb97 | blueswir1 | #define STAT_PIO_MASK 0x06 |
130 | 2f275b8f | bellard | |
131 | 2f275b8f | bellard | #define STAT_TC 0x10 |
132 | 4d611c9a | pbrook | #define STAT_PE 0x20 |
133 | 4d611c9a | pbrook | #define STAT_GE 0x40 |
134 | c73f96fd | blueswir1 | #define STAT_INT 0x80 |
135 | 2f275b8f | bellard | |
136 | 8dea1dd4 | blueswir1 | #define BUSID_DID 0x07 |
137 | 8dea1dd4 | blueswir1 | |
138 | 2f275b8f | bellard | #define INTR_FC 0x08 |
139 | 2f275b8f | bellard | #define INTR_BS 0x10 |
140 | 2f275b8f | bellard | #define INTR_DC 0x20 |
141 | 9e61bde5 | bellard | #define INTR_RST 0x80 |
142 | 2f275b8f | bellard | |
143 | 2f275b8f | bellard | #define SEQ_0 0x0 |
144 | 2f275b8f | bellard | #define SEQ_CD 0x4 |
145 | 2f275b8f | bellard | |
146 | 5ad6bb97 | blueswir1 | #define CFG1_RESREPT 0x40 |
147 | 5ad6bb97 | blueswir1 | |
148 | 5ad6bb97 | blueswir1 | #define TCHI_FAS100A 0x4 |
149 | 5ad6bb97 | blueswir1 | |
150 | c73f96fd | blueswir1 | static void esp_raise_irq(ESPState *s) |
151 | c73f96fd | blueswir1 | { |
152 | c73f96fd | blueswir1 | if (!(s->rregs[ESP_RSTAT] & STAT_INT)) {
|
153 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_INT; |
154 | c73f96fd | blueswir1 | qemu_irq_raise(s->irq); |
155 | c73f96fd | blueswir1 | } |
156 | c73f96fd | blueswir1 | } |
157 | c73f96fd | blueswir1 | |
158 | c73f96fd | blueswir1 | static void esp_lower_irq(ESPState *s) |
159 | c73f96fd | blueswir1 | { |
160 | c73f96fd | blueswir1 | if (s->rregs[ESP_RSTAT] & STAT_INT) {
|
161 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] &= ~STAT_INT; |
162 | c73f96fd | blueswir1 | qemu_irq_lower(s->irq); |
163 | c73f96fd | blueswir1 | } |
164 | c73f96fd | blueswir1 | } |
165 | c73f96fd | blueswir1 | |
166 | 22548760 | blueswir1 | static uint32_t get_cmd(ESPState *s, uint8_t *buf)
|
167 | 2f275b8f | bellard | { |
168 | a917d384 | pbrook | uint32_t dmalen; |
169 | 2f275b8f | bellard | int target;
|
170 | 2f275b8f | bellard | |
171 | 8dea1dd4 | blueswir1 | target = s->wregs[ESP_WBUSID] & BUSID_DID; |
172 | 4f6200f0 | bellard | if (s->dma) {
|
173 | fc4d65da | blueswir1 | dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8);
|
174 | 8b17de88 | blueswir1 | s->dma_memory_read(s->dma_opaque, buf, dmalen); |
175 | 4f6200f0 | bellard | } else {
|
176 | fc4d65da | blueswir1 | dmalen = s->ti_size; |
177 | fc4d65da | blueswir1 | memcpy(buf, s->ti_buf, dmalen); |
178 | f930d07e | blueswir1 | buf[0] = 0; |
179 | 4f6200f0 | bellard | } |
180 | fc4d65da | blueswir1 | DPRINTF("get_cmd: len %d target %d\n", dmalen, target);
|
181 | 2e5d83bb | pbrook | |
182 | 2f275b8f | bellard | s->ti_size = 0;
|
183 | 4f6200f0 | bellard | s->ti_rptr = 0;
|
184 | 4f6200f0 | bellard | s->ti_wptr = 0;
|
185 | 2f275b8f | bellard | |
186 | a917d384 | pbrook | if (s->current_dev) {
|
187 | a917d384 | pbrook | /* Started a new command before the old one finished. Cancel it. */
|
188 | 8ccc2ace | ths | s->current_dev->cancel_io(s->current_dev, 0);
|
189 | a917d384 | pbrook | s->async_len = 0;
|
190 | a917d384 | pbrook | } |
191 | a917d384 | pbrook | |
192 | e4bcb14c | ths | if (target >= ESP_MAX_DEVS || !s->scsi_dev[target]) {
|
193 | 2e5d83bb | pbrook | // No such drive
|
194 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = 0;
|
195 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_DC; |
196 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_0; |
197 | c73f96fd | blueswir1 | esp_raise_irq(s); |
198 | f930d07e | blueswir1 | return 0; |
199 | 2f275b8f | bellard | } |
200 | 2e5d83bb | pbrook | s->current_dev = s->scsi_dev[target]; |
201 | 9f149aa9 | pbrook | return dmalen;
|
202 | 9f149aa9 | pbrook | } |
203 | 9f149aa9 | pbrook | |
204 | 9f149aa9 | pbrook | static void do_cmd(ESPState *s, uint8_t *buf) |
205 | 9f149aa9 | pbrook | { |
206 | 9f149aa9 | pbrook | int32_t datalen; |
207 | 9f149aa9 | pbrook | int lun;
|
208 | 9f149aa9 | pbrook | |
209 | 9f149aa9 | pbrook | DPRINTF("do_cmd: busid 0x%x\n", buf[0]); |
210 | 9f149aa9 | pbrook | lun = buf[0] & 7; |
211 | 8ccc2ace | ths | datalen = s->current_dev->send_command(s->current_dev, 0, &buf[1], lun); |
212 | 67e999be | bellard | s->ti_size = datalen; |
213 | 67e999be | bellard | if (datalen != 0) { |
214 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = STAT_TC; |
215 | a917d384 | pbrook | s->dma_left = 0;
|
216 | 6787f5fa | pbrook | s->dma_counter = 0;
|
217 | 2e5d83bb | pbrook | if (datalen > 0) { |
218 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_DI; |
219 | 8ccc2ace | ths | s->current_dev->read_data(s->current_dev, 0);
|
220 | 2e5d83bb | pbrook | } else {
|
221 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_DO; |
222 | 8ccc2ace | ths | s->current_dev->write_data(s->current_dev, 0);
|
223 | b9788fc4 | bellard | } |
224 | 2f275b8f | bellard | } |
225 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS | INTR_FC; |
226 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_CD; |
227 | c73f96fd | blueswir1 | esp_raise_irq(s); |
228 | 2f275b8f | bellard | } |
229 | 2f275b8f | bellard | |
230 | 9f149aa9 | pbrook | static void handle_satn(ESPState *s) |
231 | 9f149aa9 | pbrook | { |
232 | 9f149aa9 | pbrook | uint8_t buf[32];
|
233 | 9f149aa9 | pbrook | int len;
|
234 | 9f149aa9 | pbrook | |
235 | 9f149aa9 | pbrook | len = get_cmd(s, buf); |
236 | 9f149aa9 | pbrook | if (len)
|
237 | 9f149aa9 | pbrook | do_cmd(s, buf); |
238 | 9f149aa9 | pbrook | } |
239 | 9f149aa9 | pbrook | |
240 | 9f149aa9 | pbrook | static void handle_satn_stop(ESPState *s) |
241 | 9f149aa9 | pbrook | { |
242 | 9f149aa9 | pbrook | s->cmdlen = get_cmd(s, s->cmdbuf); |
243 | 9f149aa9 | pbrook | if (s->cmdlen) {
|
244 | 9f149aa9 | pbrook | DPRINTF("Set ATN & Stop: cmdlen %d\n", s->cmdlen);
|
245 | 9f149aa9 | pbrook | s->do_cmd = 1;
|
246 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = STAT_TC | STAT_CD; |
247 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS | INTR_FC; |
248 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_CD; |
249 | c73f96fd | blueswir1 | esp_raise_irq(s); |
250 | 9f149aa9 | pbrook | } |
251 | 9f149aa9 | pbrook | } |
252 | 9f149aa9 | pbrook | |
253 | 0fc5c15a | pbrook | static void write_response(ESPState *s) |
254 | 2f275b8f | bellard | { |
255 | 0fc5c15a | pbrook | DPRINTF("Transfer status (sense=%d)\n", s->sense);
|
256 | 0fc5c15a | pbrook | s->ti_buf[0] = s->sense;
|
257 | 0fc5c15a | pbrook | s->ti_buf[1] = 0; |
258 | 4f6200f0 | bellard | if (s->dma) {
|
259 | 8b17de88 | blueswir1 | s->dma_memory_write(s->dma_opaque, s->ti_buf, 2);
|
260 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = STAT_TC | STAT_ST; |
261 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS | INTR_FC; |
262 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_CD; |
263 | 4f6200f0 | bellard | } else {
|
264 | f930d07e | blueswir1 | s->ti_size = 2;
|
265 | f930d07e | blueswir1 | s->ti_rptr = 0;
|
266 | f930d07e | blueswir1 | s->ti_wptr = 0;
|
267 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RFLAGS] = 2;
|
268 | 4f6200f0 | bellard | } |
269 | c73f96fd | blueswir1 | esp_raise_irq(s); |
270 | 2f275b8f | bellard | } |
271 | 4f6200f0 | bellard | |
272 | a917d384 | pbrook | static void esp_dma_done(ESPState *s) |
273 | a917d384 | pbrook | { |
274 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_TC; |
275 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS; |
276 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = 0;
|
277 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RFLAGS] = 0;
|
278 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCLO] = 0;
|
279 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCMID] = 0;
|
280 | c73f96fd | blueswir1 | esp_raise_irq(s); |
281 | a917d384 | pbrook | } |
282 | a917d384 | pbrook | |
283 | 4d611c9a | pbrook | static void esp_do_dma(ESPState *s) |
284 | 4d611c9a | pbrook | { |
285 | 67e999be | bellard | uint32_t len; |
286 | 4d611c9a | pbrook | int to_device;
|
287 | a917d384 | pbrook | |
288 | 67e999be | bellard | to_device = (s->ti_size < 0);
|
289 | a917d384 | pbrook | len = s->dma_left; |
290 | 4d611c9a | pbrook | if (s->do_cmd) {
|
291 | 4d611c9a | pbrook | DPRINTF("command len %d + %d\n", s->cmdlen, len);
|
292 | 8b17de88 | blueswir1 | s->dma_memory_read(s->dma_opaque, &s->cmdbuf[s->cmdlen], len); |
293 | 4d611c9a | pbrook | s->ti_size = 0;
|
294 | 4d611c9a | pbrook | s->cmdlen = 0;
|
295 | 4d611c9a | pbrook | s->do_cmd = 0;
|
296 | 4d611c9a | pbrook | do_cmd(s, s->cmdbuf); |
297 | 4d611c9a | pbrook | return;
|
298 | a917d384 | pbrook | } |
299 | a917d384 | pbrook | if (s->async_len == 0) { |
300 | a917d384 | pbrook | /* Defer until data is available. */
|
301 | a917d384 | pbrook | return;
|
302 | a917d384 | pbrook | } |
303 | a917d384 | pbrook | if (len > s->async_len) {
|
304 | a917d384 | pbrook | len = s->async_len; |
305 | a917d384 | pbrook | } |
306 | a917d384 | pbrook | if (to_device) {
|
307 | 8b17de88 | blueswir1 | s->dma_memory_read(s->dma_opaque, s->async_buf, len); |
308 | 4d611c9a | pbrook | } else {
|
309 | 8b17de88 | blueswir1 | s->dma_memory_write(s->dma_opaque, s->async_buf, len); |
310 | a917d384 | pbrook | } |
311 | a917d384 | pbrook | s->dma_left -= len; |
312 | a917d384 | pbrook | s->async_buf += len; |
313 | a917d384 | pbrook | s->async_len -= len; |
314 | 6787f5fa | pbrook | if (to_device)
|
315 | 6787f5fa | pbrook | s->ti_size += len; |
316 | 6787f5fa | pbrook | else
|
317 | 6787f5fa | pbrook | s->ti_size -= len; |
318 | a917d384 | pbrook | if (s->async_len == 0) { |
319 | 4d611c9a | pbrook | if (to_device) {
|
320 | 67e999be | bellard | // ti_size is negative
|
321 | 8ccc2ace | ths | s->current_dev->write_data(s->current_dev, 0);
|
322 | 4d611c9a | pbrook | } else {
|
323 | 8ccc2ace | ths | s->current_dev->read_data(s->current_dev, 0);
|
324 | 6787f5fa | pbrook | /* If there is still data to be read from the device then
|
325 | 8dea1dd4 | blueswir1 | complete the DMA operation immediately. Otherwise defer
|
326 | 6787f5fa | pbrook | until the scsi layer has completed. */
|
327 | 6787f5fa | pbrook | if (s->dma_left == 0 && s->ti_size > 0) { |
328 | 6787f5fa | pbrook | esp_dma_done(s); |
329 | 6787f5fa | pbrook | } |
330 | 4d611c9a | pbrook | } |
331 | 6787f5fa | pbrook | } else {
|
332 | 6787f5fa | pbrook | /* Partially filled a scsi buffer. Complete immediately. */
|
333 | a917d384 | pbrook | esp_dma_done(s); |
334 | a917d384 | pbrook | } |
335 | 4d611c9a | pbrook | } |
336 | 4d611c9a | pbrook | |
337 | a917d384 | pbrook | static void esp_command_complete(void *opaque, int reason, uint32_t tag, |
338 | a917d384 | pbrook | uint32_t arg) |
339 | 2e5d83bb | pbrook | { |
340 | 2e5d83bb | pbrook | ESPState *s = (ESPState *)opaque; |
341 | 2e5d83bb | pbrook | |
342 | 4d611c9a | pbrook | if (reason == SCSI_REASON_DONE) {
|
343 | 4d611c9a | pbrook | DPRINTF("SCSI Command complete\n");
|
344 | 4d611c9a | pbrook | if (s->ti_size != 0) |
345 | 4d611c9a | pbrook | DPRINTF("SCSI command completed unexpectedly\n");
|
346 | 4d611c9a | pbrook | s->ti_size = 0;
|
347 | a917d384 | pbrook | s->dma_left = 0;
|
348 | a917d384 | pbrook | s->async_len = 0;
|
349 | a917d384 | pbrook | if (arg)
|
350 | 4d611c9a | pbrook | DPRINTF("Command failed\n");
|
351 | a917d384 | pbrook | s->sense = arg; |
352 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] = STAT_ST; |
353 | a917d384 | pbrook | esp_dma_done(s); |
354 | a917d384 | pbrook | s->current_dev = NULL;
|
355 | 4d611c9a | pbrook | } else {
|
356 | 4d611c9a | pbrook | DPRINTF("transfer %d/%d\n", s->dma_left, s->ti_size);
|
357 | a917d384 | pbrook | s->async_len = arg; |
358 | 8ccc2ace | ths | s->async_buf = s->current_dev->get_buf(s->current_dev, 0);
|
359 | 6787f5fa | pbrook | if (s->dma_left) {
|
360 | a917d384 | pbrook | esp_do_dma(s); |
361 | 6787f5fa | pbrook | } else if (s->dma_counter != 0 && s->ti_size <= 0) { |
362 | 6787f5fa | pbrook | /* If this was the last part of a DMA transfer then the
|
363 | 6787f5fa | pbrook | completion interrupt is deferred to here. */
|
364 | 6787f5fa | pbrook | esp_dma_done(s); |
365 | 6787f5fa | pbrook | } |
366 | 4d611c9a | pbrook | } |
367 | 2e5d83bb | pbrook | } |
368 | 2e5d83bb | pbrook | |
369 | 2f275b8f | bellard | static void handle_ti(ESPState *s) |
370 | 2f275b8f | bellard | { |
371 | 4d611c9a | pbrook | uint32_t dmalen, minlen; |
372 | 2f275b8f | bellard | |
373 | 5ad6bb97 | blueswir1 | dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8);
|
374 | db59203d | pbrook | if (dmalen==0) { |
375 | db59203d | pbrook | dmalen=0x10000;
|
376 | db59203d | pbrook | } |
377 | 6787f5fa | pbrook | s->dma_counter = dmalen; |
378 | db59203d | pbrook | |
379 | 9f149aa9 | pbrook | if (s->do_cmd)
|
380 | 9f149aa9 | pbrook | minlen = (dmalen < 32) ? dmalen : 32; |
381 | 67e999be | bellard | else if (s->ti_size < 0) |
382 | 67e999be | bellard | minlen = (dmalen < -s->ti_size) ? dmalen : -s->ti_size; |
383 | 9f149aa9 | pbrook | else
|
384 | 9f149aa9 | pbrook | minlen = (dmalen < s->ti_size) ? dmalen : s->ti_size; |
385 | db59203d | pbrook | DPRINTF("Transfer Information len %d\n", minlen);
|
386 | 4f6200f0 | bellard | if (s->dma) {
|
387 | 4d611c9a | pbrook | s->dma_left = minlen; |
388 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] &= ~STAT_TC; |
389 | 4d611c9a | pbrook | esp_do_dma(s); |
390 | 9f149aa9 | pbrook | } else if (s->do_cmd) { |
391 | 9f149aa9 | pbrook | DPRINTF("command len %d\n", s->cmdlen);
|
392 | 9f149aa9 | pbrook | s->ti_size = 0;
|
393 | 9f149aa9 | pbrook | s->cmdlen = 0;
|
394 | 9f149aa9 | pbrook | s->do_cmd = 0;
|
395 | 9f149aa9 | pbrook | do_cmd(s, s->cmdbuf); |
396 | 9f149aa9 | pbrook | return;
|
397 | 9f149aa9 | pbrook | } |
398 | 2f275b8f | bellard | } |
399 | 2f275b8f | bellard | |
400 | 5aca8c3b | blueswir1 | static void esp_reset(void *opaque) |
401 | 6f7e9aec | bellard | { |
402 | 6f7e9aec | bellard | ESPState *s = opaque; |
403 | 67e999be | bellard | |
404 | 5aca8c3b | blueswir1 | memset(s->rregs, 0, ESP_REGS);
|
405 | 5aca8c3b | blueswir1 | memset(s->wregs, 0, ESP_REGS);
|
406 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCHI] = TCHI_FAS100A; // Indicate fas100a
|
407 | 4e9aec74 | pbrook | s->ti_size = 0;
|
408 | 4e9aec74 | pbrook | s->ti_rptr = 0;
|
409 | 4e9aec74 | pbrook | s->ti_wptr = 0;
|
410 | 4e9aec74 | pbrook | s->dma = 0;
|
411 | 9f149aa9 | pbrook | s->do_cmd = 0;
|
412 | 8dea1dd4 | blueswir1 | |
413 | 8dea1dd4 | blueswir1 | s->rregs[ESP_CFG1] = 7;
|
414 | 6f7e9aec | bellard | } |
415 | 6f7e9aec | bellard | |
416 | 2d069bab | blueswir1 | static void parent_esp_reset(void *opaque, int irq, int level) |
417 | 2d069bab | blueswir1 | { |
418 | 2d069bab | blueswir1 | if (level)
|
419 | 2d069bab | blueswir1 | esp_reset(opaque); |
420 | 2d069bab | blueswir1 | } |
421 | 2d069bab | blueswir1 | |
422 | 6f7e9aec | bellard | static uint32_t esp_mem_readb(void *opaque, target_phys_addr_t addr) |
423 | 6f7e9aec | bellard | { |
424 | 6f7e9aec | bellard | ESPState *s = opaque; |
425 | 6f7e9aec | bellard | uint32_t saddr; |
426 | 6f7e9aec | bellard | |
427 | e64d7d59 | blueswir1 | saddr = addr >> s->it_shift; |
428 | 9e61bde5 | bellard | DPRINTF("read reg[%d]: 0x%2.2x\n", saddr, s->rregs[saddr]);
|
429 | 6f7e9aec | bellard | switch (saddr) {
|
430 | 5ad6bb97 | blueswir1 | case ESP_FIFO:
|
431 | f930d07e | blueswir1 | if (s->ti_size > 0) { |
432 | f930d07e | blueswir1 | s->ti_size--; |
433 | 5ad6bb97 | blueswir1 | if ((s->rregs[ESP_RSTAT] & STAT_PIO_MASK) == 0) { |
434 | 8dea1dd4 | blueswir1 | /* Data out. */
|
435 | 8dea1dd4 | blueswir1 | ESP_ERROR("PIO data read not implemented\n");
|
436 | 5ad6bb97 | blueswir1 | s->rregs[ESP_FIFO] = 0;
|
437 | 2e5d83bb | pbrook | } else {
|
438 | 5ad6bb97 | blueswir1 | s->rregs[ESP_FIFO] = s->ti_buf[s->ti_rptr++]; |
439 | 2e5d83bb | pbrook | } |
440 | c73f96fd | blueswir1 | esp_raise_irq(s); |
441 | f930d07e | blueswir1 | } |
442 | f930d07e | blueswir1 | if (s->ti_size == 0) { |
443 | 4f6200f0 | bellard | s->ti_rptr = 0;
|
444 | 4f6200f0 | bellard | s->ti_wptr = 0;
|
445 | 4f6200f0 | bellard | } |
446 | f930d07e | blueswir1 | break;
|
447 | 5ad6bb97 | blueswir1 | case ESP_RINTR:
|
448 | 4d611c9a | pbrook | // Clear interrupt/error status bits
|
449 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] &= ~(STAT_GE | STAT_PE); |
450 | c73f96fd | blueswir1 | esp_lower_irq(s); |
451 | 9e61bde5 | bellard | break;
|
452 | 6f7e9aec | bellard | default:
|
453 | f930d07e | blueswir1 | break;
|
454 | 6f7e9aec | bellard | } |
455 | 2f275b8f | bellard | return s->rregs[saddr];
|
456 | 6f7e9aec | bellard | } |
457 | 6f7e9aec | bellard | |
458 | 6f7e9aec | bellard | static void esp_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
459 | 6f7e9aec | bellard | { |
460 | 6f7e9aec | bellard | ESPState *s = opaque; |
461 | 6f7e9aec | bellard | uint32_t saddr; |
462 | 6f7e9aec | bellard | |
463 | e64d7d59 | blueswir1 | saddr = addr >> s->it_shift; |
464 | 5ad6bb97 | blueswir1 | DPRINTF("write reg[%d]: 0x%2.2x -> 0x%2.2x\n", saddr, s->wregs[saddr],
|
465 | 5ad6bb97 | blueswir1 | val); |
466 | 6f7e9aec | bellard | switch (saddr) {
|
467 | 5ad6bb97 | blueswir1 | case ESP_TCLO:
|
468 | 5ad6bb97 | blueswir1 | case ESP_TCMID:
|
469 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] &= ~STAT_TC; |
470 | 4f6200f0 | bellard | break;
|
471 | 5ad6bb97 | blueswir1 | case ESP_FIFO:
|
472 | 9f149aa9 | pbrook | if (s->do_cmd) {
|
473 | 9f149aa9 | pbrook | s->cmdbuf[s->cmdlen++] = val & 0xff;
|
474 | 8dea1dd4 | blueswir1 | } else if (s->ti_size == TI_BUFSZ - 1) { |
475 | 8dea1dd4 | blueswir1 | ESP_ERROR("fifo overrun\n");
|
476 | 2e5d83bb | pbrook | } else {
|
477 | 2e5d83bb | pbrook | s->ti_size++; |
478 | 2e5d83bb | pbrook | s->ti_buf[s->ti_wptr++] = val & 0xff;
|
479 | 2e5d83bb | pbrook | } |
480 | f930d07e | blueswir1 | break;
|
481 | 5ad6bb97 | blueswir1 | case ESP_CMD:
|
482 | 4f6200f0 | bellard | s->rregs[saddr] = val; |
483 | 5ad6bb97 | blueswir1 | if (val & CMD_DMA) {
|
484 | f930d07e | blueswir1 | s->dma = 1;
|
485 | 6787f5fa | pbrook | /* Reload DMA counter. */
|
486 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCLO] = s->wregs[ESP_TCLO]; |
487 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCMID] = s->wregs[ESP_TCMID]; |
488 | f930d07e | blueswir1 | } else {
|
489 | f930d07e | blueswir1 | s->dma = 0;
|
490 | f930d07e | blueswir1 | } |
491 | 5ad6bb97 | blueswir1 | switch(val & CMD_CMD) {
|
492 | 5ad6bb97 | blueswir1 | case CMD_NOP:
|
493 | f930d07e | blueswir1 | DPRINTF("NOP (%2.2x)\n", val);
|
494 | f930d07e | blueswir1 | break;
|
495 | 5ad6bb97 | blueswir1 | case CMD_FLUSH:
|
496 | f930d07e | blueswir1 | DPRINTF("Flush FIFO (%2.2x)\n", val);
|
497 | 9e61bde5 | bellard | //s->ti_size = 0;
|
498 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_FC; |
499 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = 0;
|
500 | a214c598 | blueswir1 | s->rregs[ESP_RFLAGS] = 0;
|
501 | f930d07e | blueswir1 | break;
|
502 | 5ad6bb97 | blueswir1 | case CMD_RESET:
|
503 | f930d07e | blueswir1 | DPRINTF("Chip reset (%2.2x)\n", val);
|
504 | f930d07e | blueswir1 | esp_reset(s); |
505 | f930d07e | blueswir1 | break;
|
506 | 5ad6bb97 | blueswir1 | case CMD_BUSRESET:
|
507 | f930d07e | blueswir1 | DPRINTF("Bus reset (%2.2x)\n", val);
|
508 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_RST; |
509 | 5ad6bb97 | blueswir1 | if (!(s->wregs[ESP_CFG1] & CFG1_RESREPT)) {
|
510 | c73f96fd | blueswir1 | esp_raise_irq(s); |
511 | 9e61bde5 | bellard | } |
512 | f930d07e | blueswir1 | break;
|
513 | 5ad6bb97 | blueswir1 | case CMD_TI:
|
514 | f930d07e | blueswir1 | handle_ti(s); |
515 | f930d07e | blueswir1 | break;
|
516 | 5ad6bb97 | blueswir1 | case CMD_ICCS:
|
517 | f930d07e | blueswir1 | DPRINTF("Initiator Command Complete Sequence (%2.2x)\n", val);
|
518 | f930d07e | blueswir1 | write_response(s); |
519 | 4bf5801d | blueswir1 | s->rregs[ESP_RINTR] = INTR_FC; |
520 | 4bf5801d | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_MI; |
521 | f930d07e | blueswir1 | break;
|
522 | 5ad6bb97 | blueswir1 | case CMD_MSGACC:
|
523 | f930d07e | blueswir1 | DPRINTF("Message Accepted (%2.2x)\n", val);
|
524 | f930d07e | blueswir1 | write_response(s); |
525 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_DC; |
526 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = 0;
|
527 | f930d07e | blueswir1 | break;
|
528 | 5ad6bb97 | blueswir1 | case CMD_SATN:
|
529 | f930d07e | blueswir1 | DPRINTF("Set ATN (%2.2x)\n", val);
|
530 | f930d07e | blueswir1 | break;
|
531 | 5ad6bb97 | blueswir1 | case CMD_SELATN:
|
532 | f930d07e | blueswir1 | DPRINTF("Set ATN (%2.2x)\n", val);
|
533 | f930d07e | blueswir1 | handle_satn(s); |
534 | f930d07e | blueswir1 | break;
|
535 | 5ad6bb97 | blueswir1 | case CMD_SELATNS:
|
536 | f930d07e | blueswir1 | DPRINTF("Set ATN & stop (%2.2x)\n", val);
|
537 | f930d07e | blueswir1 | handle_satn_stop(s); |
538 | f930d07e | blueswir1 | break;
|
539 | 5ad6bb97 | blueswir1 | case CMD_ENSEL:
|
540 | 74ec6048 | blueswir1 | DPRINTF("Enable selection (%2.2x)\n", val);
|
541 | e3926838 | blueswir1 | s->rregs[ESP_RINTR] = 0;
|
542 | 74ec6048 | blueswir1 | break;
|
543 | f930d07e | blueswir1 | default:
|
544 | 8dea1dd4 | blueswir1 | ESP_ERROR("Unhandled ESP command (%2.2x)\n", val);
|
545 | f930d07e | blueswir1 | break;
|
546 | f930d07e | blueswir1 | } |
547 | f930d07e | blueswir1 | break;
|
548 | 5ad6bb97 | blueswir1 | case ESP_WBUSID ... ESP_WSYNO:
|
549 | f930d07e | blueswir1 | break;
|
550 | 5ad6bb97 | blueswir1 | case ESP_CFG1:
|
551 | 4f6200f0 | bellard | s->rregs[saddr] = val; |
552 | 4f6200f0 | bellard | break;
|
553 | 5ad6bb97 | blueswir1 | case ESP_WCCF ... ESP_WTEST:
|
554 | 4f6200f0 | bellard | break;
|
555 | b44c08fa | blueswir1 | case ESP_CFG2 ... ESP_RES4:
|
556 | 4f6200f0 | bellard | s->rregs[saddr] = val; |
557 | 4f6200f0 | bellard | break;
|
558 | 6f7e9aec | bellard | default:
|
559 | 8dea1dd4 | blueswir1 | ESP_ERROR("invalid write of 0x%02x at [0x%x]\n", val, saddr);
|
560 | 8dea1dd4 | blueswir1 | return;
|
561 | 6f7e9aec | bellard | } |
562 | 2f275b8f | bellard | s->wregs[saddr] = val; |
563 | 6f7e9aec | bellard | } |
564 | 6f7e9aec | bellard | |
565 | 6f7e9aec | bellard | static CPUReadMemoryFunc *esp_mem_read[3] = { |
566 | 6f7e9aec | bellard | esp_mem_readb, |
567 | 7c560456 | blueswir1 | NULL,
|
568 | 7c560456 | blueswir1 | NULL,
|
569 | 6f7e9aec | bellard | }; |
570 | 6f7e9aec | bellard | |
571 | 6f7e9aec | bellard | static CPUWriteMemoryFunc *esp_mem_write[3] = { |
572 | 6f7e9aec | bellard | esp_mem_writeb, |
573 | 7c560456 | blueswir1 | NULL,
|
574 | daa41b00 | blueswir1 | esp_mem_writeb, |
575 | 6f7e9aec | bellard | }; |
576 | 6f7e9aec | bellard | |
577 | 6f7e9aec | bellard | static void esp_save(QEMUFile *f, void *opaque) |
578 | 6f7e9aec | bellard | { |
579 | 6f7e9aec | bellard | ESPState *s = opaque; |
580 | 2f275b8f | bellard | |
581 | 5aca8c3b | blueswir1 | qemu_put_buffer(f, s->rregs, ESP_REGS); |
582 | 5aca8c3b | blueswir1 | qemu_put_buffer(f, s->wregs, ESP_REGS); |
583 | b6c4f71f | blueswir1 | qemu_put_sbe32s(f, &s->ti_size); |
584 | 4f6200f0 | bellard | qemu_put_be32s(f, &s->ti_rptr); |
585 | 4f6200f0 | bellard | qemu_put_be32s(f, &s->ti_wptr); |
586 | 4f6200f0 | bellard | qemu_put_buffer(f, s->ti_buf, TI_BUFSZ); |
587 | 5425a216 | blueswir1 | qemu_put_be32s(f, &s->sense); |
588 | 4f6200f0 | bellard | qemu_put_be32s(f, &s->dma); |
589 | 5425a216 | blueswir1 | qemu_put_buffer(f, s->cmdbuf, TI_BUFSZ); |
590 | 5425a216 | blueswir1 | qemu_put_be32s(f, &s->cmdlen); |
591 | 5425a216 | blueswir1 | qemu_put_be32s(f, &s->do_cmd); |
592 | 5425a216 | blueswir1 | qemu_put_be32s(f, &s->dma_left); |
593 | 5425a216 | blueswir1 | // There should be no transfers in progress, so dma_counter is not saved
|
594 | 6f7e9aec | bellard | } |
595 | 6f7e9aec | bellard | |
596 | 6f7e9aec | bellard | static int esp_load(QEMUFile *f, void *opaque, int version_id) |
597 | 6f7e9aec | bellard | { |
598 | 6f7e9aec | bellard | ESPState *s = opaque; |
599 | 3b46e624 | ths | |
600 | 5425a216 | blueswir1 | if (version_id != 3) |
601 | 5425a216 | blueswir1 | return -EINVAL; // Cannot emulate 2 |
602 | 6f7e9aec | bellard | |
603 | 5aca8c3b | blueswir1 | qemu_get_buffer(f, s->rregs, ESP_REGS); |
604 | 5aca8c3b | blueswir1 | qemu_get_buffer(f, s->wregs, ESP_REGS); |
605 | b6c4f71f | blueswir1 | qemu_get_sbe32s(f, &s->ti_size); |
606 | 4f6200f0 | bellard | qemu_get_be32s(f, &s->ti_rptr); |
607 | 4f6200f0 | bellard | qemu_get_be32s(f, &s->ti_wptr); |
608 | 4f6200f0 | bellard | qemu_get_buffer(f, s->ti_buf, TI_BUFSZ); |
609 | 5425a216 | blueswir1 | qemu_get_be32s(f, &s->sense); |
610 | 4f6200f0 | bellard | qemu_get_be32s(f, &s->dma); |
611 | 5425a216 | blueswir1 | qemu_get_buffer(f, s->cmdbuf, TI_BUFSZ); |
612 | 5425a216 | blueswir1 | qemu_get_be32s(f, &s->cmdlen); |
613 | 5425a216 | blueswir1 | qemu_get_be32s(f, &s->do_cmd); |
614 | 5425a216 | blueswir1 | qemu_get_be32s(f, &s->dma_left); |
615 | 2f275b8f | bellard | |
616 | 6f7e9aec | bellard | return 0; |
617 | 6f7e9aec | bellard | } |
618 | 6f7e9aec | bellard | |
619 | cfb9de9c | Paul Brook | static void esp_scsi_attach(DeviceState *host, BlockDriverState *bd, int id) |
620 | fa1fb14c | ths | { |
621 | cfb9de9c | Paul Brook | ESPState *s = FROM_SYSBUS(ESPState, sysbus_from_qdev(host)); |
622 | fa1fb14c | ths | |
623 | fa1fb14c | ths | if (id < 0) { |
624 | fa1fb14c | ths | for (id = 0; id < ESP_MAX_DEVS; id++) { |
625 | 8dea1dd4 | blueswir1 | if (id == (s->rregs[ESP_CFG1] & 0x7)) |
626 | 8dea1dd4 | blueswir1 | continue;
|
627 | fa1fb14c | ths | if (s->scsi_dev[id] == NULL) |
628 | fa1fb14c | ths | break;
|
629 | fa1fb14c | ths | } |
630 | fa1fb14c | ths | } |
631 | fa1fb14c | ths | if (id >= ESP_MAX_DEVS) {
|
632 | fa1fb14c | ths | DPRINTF("Bad Device ID %d\n", id);
|
633 | fa1fb14c | ths | return;
|
634 | fa1fb14c | ths | } |
635 | fa1fb14c | ths | if (s->scsi_dev[id]) {
|
636 | fa1fb14c | ths | DPRINTF("Destroying device %d\n", id);
|
637 | 8ccc2ace | ths | s->scsi_dev[id]->destroy(s->scsi_dev[id]); |
638 | fa1fb14c | ths | } |
639 | fa1fb14c | ths | DPRINTF("Attaching block device %d\n", id);
|
640 | fa1fb14c | ths | /* Command queueing is not implemented. */
|
641 | 985a03b0 | ths | s->scsi_dev[id] = scsi_generic_init(bd, 0, esp_command_complete, s);
|
642 | 985a03b0 | ths | if (s->scsi_dev[id] == NULL) |
643 | 985a03b0 | ths | s->scsi_dev[id] = scsi_disk_init(bd, 0, esp_command_complete, s);
|
644 | fa1fb14c | ths | } |
645 | fa1fb14c | ths | |
646 | cfb9de9c | Paul Brook | void esp_init(target_phys_addr_t espaddr, int it_shift, |
647 | cfb9de9c | Paul Brook | espdma_memory_read_write dma_memory_read, |
648 | cfb9de9c | Paul Brook | espdma_memory_read_write dma_memory_write, |
649 | cfb9de9c | Paul Brook | void *dma_opaque, qemu_irq irq, qemu_irq *reset)
|
650 | 6f7e9aec | bellard | { |
651 | cfb9de9c | Paul Brook | DeviceState *dev; |
652 | cfb9de9c | Paul Brook | SysBusDevice *s; |
653 | ee6847d1 | Gerd Hoffmann | ESPState *esp; |
654 | cfb9de9c | Paul Brook | |
655 | cfb9de9c | Paul Brook | dev = qdev_create(NULL, "esp"); |
656 | ee6847d1 | Gerd Hoffmann | esp = DO_UPCAST(ESPState, busdev.qdev, dev); |
657 | ee6847d1 | Gerd Hoffmann | esp->dma_memory_read = dma_memory_read; |
658 | ee6847d1 | Gerd Hoffmann | esp->dma_memory_write = dma_memory_write; |
659 | ee6847d1 | Gerd Hoffmann | esp->dma_opaque = dma_opaque; |
660 | ee6847d1 | Gerd Hoffmann | esp->it_shift = it_shift; |
661 | cfb9de9c | Paul Brook | qdev_init(dev); |
662 | cfb9de9c | Paul Brook | s = sysbus_from_qdev(dev); |
663 | cfb9de9c | Paul Brook | sysbus_connect_irq(s, 0, irq);
|
664 | cfb9de9c | Paul Brook | sysbus_mmio_map(s, 0, espaddr);
|
665 | cfb9de9c | Paul Brook | } |
666 | 6f7e9aec | bellard | |
667 | cfb9de9c | Paul Brook | static void esp_init1(SysBusDevice *dev) |
668 | cfb9de9c | Paul Brook | { |
669 | cfb9de9c | Paul Brook | ESPState *s = FROM_SYSBUS(ESPState, dev); |
670 | cfb9de9c | Paul Brook | int esp_io_memory;
|
671 | 6f7e9aec | bellard | |
672 | cfb9de9c | Paul Brook | sysbus_init_irq(dev, &s->irq); |
673 | cfb9de9c | Paul Brook | assert(s->it_shift != -1);
|
674 | 6f7e9aec | bellard | |
675 | 1eed09cb | Avi Kivity | esp_io_memory = cpu_register_io_memory(esp_mem_read, esp_mem_write, s); |
676 | cfb9de9c | Paul Brook | sysbus_init_mmio(dev, ESP_REGS << s->it_shift, esp_io_memory); |
677 | 6f7e9aec | bellard | |
678 | 6f7e9aec | bellard | esp_reset(s); |
679 | 6f7e9aec | bellard | |
680 | cfb9de9c | Paul Brook | register_savevm("esp", -1, 3, esp_save, esp_load, s); |
681 | a08d4367 | Jan Kiszka | qemu_register_reset(esp_reset, s); |
682 | 6f7e9aec | bellard | |
683 | 067a3ddc | Paul Brook | qdev_init_gpio_in(&dev->qdev, parent_esp_reset, 1);
|
684 | 2d069bab | blueswir1 | |
685 | cfb9de9c | Paul Brook | scsi_bus_new(&dev->qdev, esp_scsi_attach); |
686 | 67e999be | bellard | } |
687 | cfb9de9c | Paul Brook | |
688 | cfb9de9c | Paul Brook | static void esp_register_devices(void) |
689 | cfb9de9c | Paul Brook | { |
690 | cfb9de9c | Paul Brook | sysbus_register_dev("esp", sizeof(ESPState), esp_init1); |
691 | cfb9de9c | Paul Brook | } |
692 | cfb9de9c | Paul Brook | |
693 | cfb9de9c | Paul Brook | device_init(esp_register_devices) |