root / hw / esp.c @ dd4239d6
History | View | Annotate | Download (18.5 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 | 43b443b6 | Gerd Hoffmann | #include "scsi.h" |
27 | 1cd3af54 | Gerd Hoffmann | #include "esp.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 | ca9c39fa | Gerd Hoffmann | SCSIBus bus; |
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 | 0fd0eb21 | Blue Swirl | #define CMD_PAD 0x18 |
119 | 5ad6bb97 | blueswir1 | #define CMD_SATN 0x1a |
120 | 5e1e0a3b | Blue Swirl | #define CMD_SEL 0x41 |
121 | 5ad6bb97 | blueswir1 | #define CMD_SELATN 0x42 |
122 | 5ad6bb97 | blueswir1 | #define CMD_SELATNS 0x43 |
123 | 5ad6bb97 | blueswir1 | #define CMD_ENSEL 0x44 |
124 | 5ad6bb97 | blueswir1 | |
125 | 2f275b8f | bellard | #define STAT_DO 0x00 |
126 | 2f275b8f | bellard | #define STAT_DI 0x01 |
127 | 2f275b8f | bellard | #define STAT_CD 0x02 |
128 | 2f275b8f | bellard | #define STAT_ST 0x03 |
129 | 8dea1dd4 | blueswir1 | #define STAT_MO 0x06 |
130 | 8dea1dd4 | blueswir1 | #define STAT_MI 0x07 |
131 | 5ad6bb97 | blueswir1 | #define STAT_PIO_MASK 0x06 |
132 | 2f275b8f | bellard | |
133 | 2f275b8f | bellard | #define STAT_TC 0x10 |
134 | 4d611c9a | pbrook | #define STAT_PE 0x20 |
135 | 4d611c9a | pbrook | #define STAT_GE 0x40 |
136 | c73f96fd | blueswir1 | #define STAT_INT 0x80 |
137 | 2f275b8f | bellard | |
138 | 8dea1dd4 | blueswir1 | #define BUSID_DID 0x07 |
139 | 8dea1dd4 | blueswir1 | |
140 | 2f275b8f | bellard | #define INTR_FC 0x08 |
141 | 2f275b8f | bellard | #define INTR_BS 0x10 |
142 | 2f275b8f | bellard | #define INTR_DC 0x20 |
143 | 9e61bde5 | bellard | #define INTR_RST 0x80 |
144 | 2f275b8f | bellard | |
145 | 2f275b8f | bellard | #define SEQ_0 0x0 |
146 | 2f275b8f | bellard | #define SEQ_CD 0x4 |
147 | 2f275b8f | bellard | |
148 | 5ad6bb97 | blueswir1 | #define CFG1_RESREPT 0x40 |
149 | 5ad6bb97 | blueswir1 | |
150 | 5ad6bb97 | blueswir1 | #define TCHI_FAS100A 0x4 |
151 | 5ad6bb97 | blueswir1 | |
152 | c73f96fd | blueswir1 | static void esp_raise_irq(ESPState *s) |
153 | c73f96fd | blueswir1 | { |
154 | c73f96fd | blueswir1 | if (!(s->rregs[ESP_RSTAT] & STAT_INT)) {
|
155 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_INT; |
156 | c73f96fd | blueswir1 | qemu_irq_raise(s->irq); |
157 | c73f96fd | blueswir1 | } |
158 | c73f96fd | blueswir1 | } |
159 | c73f96fd | blueswir1 | |
160 | c73f96fd | blueswir1 | static void esp_lower_irq(ESPState *s) |
161 | c73f96fd | blueswir1 | { |
162 | c73f96fd | blueswir1 | if (s->rregs[ESP_RSTAT] & STAT_INT) {
|
163 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] &= ~STAT_INT; |
164 | c73f96fd | blueswir1 | qemu_irq_lower(s->irq); |
165 | c73f96fd | blueswir1 | } |
166 | c73f96fd | blueswir1 | } |
167 | c73f96fd | blueswir1 | |
168 | 22548760 | blueswir1 | static uint32_t get_cmd(ESPState *s, uint8_t *buf)
|
169 | 2f275b8f | bellard | { |
170 | a917d384 | pbrook | uint32_t dmalen; |
171 | 2f275b8f | bellard | int target;
|
172 | 2f275b8f | bellard | |
173 | 8dea1dd4 | blueswir1 | target = s->wregs[ESP_WBUSID] & BUSID_DID; |
174 | 4f6200f0 | bellard | if (s->dma) {
|
175 | fc4d65da | blueswir1 | dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8);
|
176 | 8b17de88 | blueswir1 | s->dma_memory_read(s->dma_opaque, buf, dmalen); |
177 | 4f6200f0 | bellard | } else {
|
178 | fc4d65da | blueswir1 | dmalen = s->ti_size; |
179 | fc4d65da | blueswir1 | memcpy(buf, s->ti_buf, dmalen); |
180 | f930d07e | blueswir1 | buf[0] = 0; |
181 | 4f6200f0 | bellard | } |
182 | fc4d65da | blueswir1 | DPRINTF("get_cmd: len %d target %d\n", dmalen, target);
|
183 | 2e5d83bb | pbrook | |
184 | 2f275b8f | bellard | s->ti_size = 0;
|
185 | 4f6200f0 | bellard | s->ti_rptr = 0;
|
186 | 4f6200f0 | bellard | s->ti_wptr = 0;
|
187 | 2f275b8f | bellard | |
188 | a917d384 | pbrook | if (s->current_dev) {
|
189 | a917d384 | pbrook | /* Started a new command before the old one finished. Cancel it. */
|
190 | d52affa7 | Gerd Hoffmann | s->current_dev->info->cancel_io(s->current_dev, 0);
|
191 | a917d384 | pbrook | s->async_len = 0;
|
192 | a917d384 | pbrook | } |
193 | a917d384 | pbrook | |
194 | ca9c39fa | Gerd Hoffmann | if (target >= ESP_MAX_DEVS || !s->bus.devs[target]) {
|
195 | 2e5d83bb | pbrook | // No such drive
|
196 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = 0;
|
197 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_DC; |
198 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_0; |
199 | c73f96fd | blueswir1 | esp_raise_irq(s); |
200 | f930d07e | blueswir1 | return 0; |
201 | 2f275b8f | bellard | } |
202 | ca9c39fa | Gerd Hoffmann | s->current_dev = s->bus.devs[target]; |
203 | 9f149aa9 | pbrook | return dmalen;
|
204 | 9f149aa9 | pbrook | } |
205 | 9f149aa9 | pbrook | |
206 | f2818f22 | Artyom Tarasenko | static void do_busid_cmd(ESPState *s, uint8_t *buf, uint8_t busid) |
207 | 9f149aa9 | pbrook | { |
208 | 9f149aa9 | pbrook | int32_t datalen; |
209 | 9f149aa9 | pbrook | int lun;
|
210 | 9f149aa9 | pbrook | |
211 | f2818f22 | Artyom Tarasenko | DPRINTF("do_busid_cmd: busid 0x%x\n", busid);
|
212 | f2818f22 | Artyom Tarasenko | lun = busid & 7;
|
213 | d52affa7 | Gerd Hoffmann | datalen = s->current_dev->info->send_command(s->current_dev, 0, buf, lun);
|
214 | 67e999be | bellard | s->ti_size = datalen; |
215 | 67e999be | bellard | if (datalen != 0) { |
216 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = STAT_TC; |
217 | a917d384 | pbrook | s->dma_left = 0;
|
218 | 6787f5fa | pbrook | s->dma_counter = 0;
|
219 | 2e5d83bb | pbrook | if (datalen > 0) { |
220 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_DI; |
221 | d52affa7 | Gerd Hoffmann | s->current_dev->info->read_data(s->current_dev, 0);
|
222 | 2e5d83bb | pbrook | } else {
|
223 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_DO; |
224 | d52affa7 | Gerd Hoffmann | s->current_dev->info->write_data(s->current_dev, 0);
|
225 | b9788fc4 | bellard | } |
226 | 2f275b8f | bellard | } |
227 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS | INTR_FC; |
228 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_CD; |
229 | c73f96fd | blueswir1 | esp_raise_irq(s); |
230 | 2f275b8f | bellard | } |
231 | 2f275b8f | bellard | |
232 | f2818f22 | Artyom Tarasenko | static void do_cmd(ESPState *s, uint8_t *buf) |
233 | f2818f22 | Artyom Tarasenko | { |
234 | f2818f22 | Artyom Tarasenko | uint8_t busid = buf[0];
|
235 | f2818f22 | Artyom Tarasenko | |
236 | f2818f22 | Artyom Tarasenko | do_busid_cmd(s, &buf[1], busid);
|
237 | f2818f22 | Artyom Tarasenko | } |
238 | f2818f22 | Artyom Tarasenko | |
239 | 9f149aa9 | pbrook | static void handle_satn(ESPState *s) |
240 | 9f149aa9 | pbrook | { |
241 | 9f149aa9 | pbrook | uint8_t buf[32];
|
242 | 9f149aa9 | pbrook | int len;
|
243 | 9f149aa9 | pbrook | |
244 | 9f149aa9 | pbrook | len = get_cmd(s, buf); |
245 | 9f149aa9 | pbrook | if (len)
|
246 | 9f149aa9 | pbrook | do_cmd(s, buf); |
247 | 9f149aa9 | pbrook | } |
248 | 9f149aa9 | pbrook | |
249 | f2818f22 | Artyom Tarasenko | static void handle_s_without_atn(ESPState *s) |
250 | f2818f22 | Artyom Tarasenko | { |
251 | f2818f22 | Artyom Tarasenko | uint8_t buf[32];
|
252 | f2818f22 | Artyom Tarasenko | int len;
|
253 | f2818f22 | Artyom Tarasenko | |
254 | f2818f22 | Artyom Tarasenko | len = get_cmd(s, buf); |
255 | f2818f22 | Artyom Tarasenko | if (len) {
|
256 | f2818f22 | Artyom Tarasenko | do_busid_cmd(s, buf, 0);
|
257 | f2818f22 | Artyom Tarasenko | } |
258 | f2818f22 | Artyom Tarasenko | } |
259 | f2818f22 | Artyom Tarasenko | |
260 | 9f149aa9 | pbrook | static void handle_satn_stop(ESPState *s) |
261 | 9f149aa9 | pbrook | { |
262 | 9f149aa9 | pbrook | s->cmdlen = get_cmd(s, s->cmdbuf); |
263 | 9f149aa9 | pbrook | if (s->cmdlen) {
|
264 | 9f149aa9 | pbrook | DPRINTF("Set ATN & Stop: cmdlen %d\n", s->cmdlen);
|
265 | 9f149aa9 | pbrook | s->do_cmd = 1;
|
266 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = STAT_TC | STAT_CD; |
267 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS | INTR_FC; |
268 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_CD; |
269 | c73f96fd | blueswir1 | esp_raise_irq(s); |
270 | 9f149aa9 | pbrook | } |
271 | 9f149aa9 | pbrook | } |
272 | 9f149aa9 | pbrook | |
273 | 0fc5c15a | pbrook | static void write_response(ESPState *s) |
274 | 2f275b8f | bellard | { |
275 | 0fc5c15a | pbrook | DPRINTF("Transfer status (sense=%d)\n", s->sense);
|
276 | 0fc5c15a | pbrook | s->ti_buf[0] = s->sense;
|
277 | 0fc5c15a | pbrook | s->ti_buf[1] = 0; |
278 | 4f6200f0 | bellard | if (s->dma) {
|
279 | 8b17de88 | blueswir1 | s->dma_memory_write(s->dma_opaque, s->ti_buf, 2);
|
280 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] = STAT_TC | STAT_ST; |
281 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS | INTR_FC; |
282 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = SEQ_CD; |
283 | 4f6200f0 | bellard | } else {
|
284 | f930d07e | blueswir1 | s->ti_size = 2;
|
285 | f930d07e | blueswir1 | s->ti_rptr = 0;
|
286 | f930d07e | blueswir1 | s->ti_wptr = 0;
|
287 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RFLAGS] = 2;
|
288 | 4f6200f0 | bellard | } |
289 | c73f96fd | blueswir1 | esp_raise_irq(s); |
290 | 2f275b8f | bellard | } |
291 | 4f6200f0 | bellard | |
292 | a917d384 | pbrook | static void esp_dma_done(ESPState *s) |
293 | a917d384 | pbrook | { |
294 | c73f96fd | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_TC; |
295 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_BS; |
296 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = 0;
|
297 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RFLAGS] = 0;
|
298 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCLO] = 0;
|
299 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCMID] = 0;
|
300 | c73f96fd | blueswir1 | esp_raise_irq(s); |
301 | a917d384 | pbrook | } |
302 | a917d384 | pbrook | |
303 | 4d611c9a | pbrook | static void esp_do_dma(ESPState *s) |
304 | 4d611c9a | pbrook | { |
305 | 67e999be | bellard | uint32_t len; |
306 | 4d611c9a | pbrook | int to_device;
|
307 | a917d384 | pbrook | |
308 | 67e999be | bellard | to_device = (s->ti_size < 0);
|
309 | a917d384 | pbrook | len = s->dma_left; |
310 | 4d611c9a | pbrook | if (s->do_cmd) {
|
311 | 4d611c9a | pbrook | DPRINTF("command len %d + %d\n", s->cmdlen, len);
|
312 | 8b17de88 | blueswir1 | s->dma_memory_read(s->dma_opaque, &s->cmdbuf[s->cmdlen], len); |
313 | 4d611c9a | pbrook | s->ti_size = 0;
|
314 | 4d611c9a | pbrook | s->cmdlen = 0;
|
315 | 4d611c9a | pbrook | s->do_cmd = 0;
|
316 | 4d611c9a | pbrook | do_cmd(s, s->cmdbuf); |
317 | 4d611c9a | pbrook | return;
|
318 | a917d384 | pbrook | } |
319 | a917d384 | pbrook | if (s->async_len == 0) { |
320 | a917d384 | pbrook | /* Defer until data is available. */
|
321 | a917d384 | pbrook | return;
|
322 | a917d384 | pbrook | } |
323 | a917d384 | pbrook | if (len > s->async_len) {
|
324 | a917d384 | pbrook | len = s->async_len; |
325 | a917d384 | pbrook | } |
326 | a917d384 | pbrook | if (to_device) {
|
327 | 8b17de88 | blueswir1 | s->dma_memory_read(s->dma_opaque, s->async_buf, len); |
328 | 4d611c9a | pbrook | } else {
|
329 | 8b17de88 | blueswir1 | s->dma_memory_write(s->dma_opaque, s->async_buf, len); |
330 | a917d384 | pbrook | } |
331 | a917d384 | pbrook | s->dma_left -= len; |
332 | a917d384 | pbrook | s->async_buf += len; |
333 | a917d384 | pbrook | s->async_len -= len; |
334 | 6787f5fa | pbrook | if (to_device)
|
335 | 6787f5fa | pbrook | s->ti_size += len; |
336 | 6787f5fa | pbrook | else
|
337 | 6787f5fa | pbrook | s->ti_size -= len; |
338 | a917d384 | pbrook | if (s->async_len == 0) { |
339 | 4d611c9a | pbrook | if (to_device) {
|
340 | 67e999be | bellard | // ti_size is negative
|
341 | d52affa7 | Gerd Hoffmann | s->current_dev->info->write_data(s->current_dev, 0);
|
342 | 4d611c9a | pbrook | } else {
|
343 | d52affa7 | Gerd Hoffmann | s->current_dev->info->read_data(s->current_dev, 0);
|
344 | 6787f5fa | pbrook | /* If there is still data to be read from the device then
|
345 | 8dea1dd4 | blueswir1 | complete the DMA operation immediately. Otherwise defer
|
346 | 6787f5fa | pbrook | until the scsi layer has completed. */
|
347 | 6787f5fa | pbrook | if (s->dma_left == 0 && s->ti_size > 0) { |
348 | 6787f5fa | pbrook | esp_dma_done(s); |
349 | 6787f5fa | pbrook | } |
350 | 4d611c9a | pbrook | } |
351 | 6787f5fa | pbrook | } else {
|
352 | 6787f5fa | pbrook | /* Partially filled a scsi buffer. Complete immediately. */
|
353 | a917d384 | pbrook | esp_dma_done(s); |
354 | a917d384 | pbrook | } |
355 | 4d611c9a | pbrook | } |
356 | 4d611c9a | pbrook | |
357 | d52affa7 | Gerd Hoffmann | static void esp_command_complete(SCSIBus *bus, int reason, uint32_t tag, |
358 | a917d384 | pbrook | uint32_t arg) |
359 | 2e5d83bb | pbrook | { |
360 | d52affa7 | Gerd Hoffmann | ESPState *s = DO_UPCAST(ESPState, busdev.qdev, bus->qbus.parent); |
361 | 2e5d83bb | pbrook | |
362 | 4d611c9a | pbrook | if (reason == SCSI_REASON_DONE) {
|
363 | 4d611c9a | pbrook | DPRINTF("SCSI Command complete\n");
|
364 | 4d611c9a | pbrook | if (s->ti_size != 0) |
365 | 4d611c9a | pbrook | DPRINTF("SCSI command completed unexpectedly\n");
|
366 | 4d611c9a | pbrook | s->ti_size = 0;
|
367 | a917d384 | pbrook | s->dma_left = 0;
|
368 | a917d384 | pbrook | s->async_len = 0;
|
369 | a917d384 | pbrook | if (arg)
|
370 | 4d611c9a | pbrook | DPRINTF("Command failed\n");
|
371 | a917d384 | pbrook | s->sense = arg; |
372 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] = STAT_ST; |
373 | a917d384 | pbrook | esp_dma_done(s); |
374 | a917d384 | pbrook | s->current_dev = NULL;
|
375 | 4d611c9a | pbrook | } else {
|
376 | 4d611c9a | pbrook | DPRINTF("transfer %d/%d\n", s->dma_left, s->ti_size);
|
377 | a917d384 | pbrook | s->async_len = arg; |
378 | d52affa7 | Gerd Hoffmann | s->async_buf = s->current_dev->info->get_buf(s->current_dev, 0);
|
379 | 6787f5fa | pbrook | if (s->dma_left) {
|
380 | a917d384 | pbrook | esp_do_dma(s); |
381 | 6787f5fa | pbrook | } else if (s->dma_counter != 0 && s->ti_size <= 0) { |
382 | 6787f5fa | pbrook | /* If this was the last part of a DMA transfer then the
|
383 | 6787f5fa | pbrook | completion interrupt is deferred to here. */
|
384 | 6787f5fa | pbrook | esp_dma_done(s); |
385 | 6787f5fa | pbrook | } |
386 | 4d611c9a | pbrook | } |
387 | 2e5d83bb | pbrook | } |
388 | 2e5d83bb | pbrook | |
389 | 2f275b8f | bellard | static void handle_ti(ESPState *s) |
390 | 2f275b8f | bellard | { |
391 | 4d611c9a | pbrook | uint32_t dmalen, minlen; |
392 | 2f275b8f | bellard | |
393 | 5ad6bb97 | blueswir1 | dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8);
|
394 | db59203d | pbrook | if (dmalen==0) { |
395 | db59203d | pbrook | dmalen=0x10000;
|
396 | db59203d | pbrook | } |
397 | 6787f5fa | pbrook | s->dma_counter = dmalen; |
398 | db59203d | pbrook | |
399 | 9f149aa9 | pbrook | if (s->do_cmd)
|
400 | 9f149aa9 | pbrook | minlen = (dmalen < 32) ? dmalen : 32; |
401 | 67e999be | bellard | else if (s->ti_size < 0) |
402 | 67e999be | bellard | minlen = (dmalen < -s->ti_size) ? dmalen : -s->ti_size; |
403 | 9f149aa9 | pbrook | else
|
404 | 9f149aa9 | pbrook | minlen = (dmalen < s->ti_size) ? dmalen : s->ti_size; |
405 | db59203d | pbrook | DPRINTF("Transfer Information len %d\n", minlen);
|
406 | 4f6200f0 | bellard | if (s->dma) {
|
407 | 4d611c9a | pbrook | s->dma_left = minlen; |
408 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] &= ~STAT_TC; |
409 | 4d611c9a | pbrook | esp_do_dma(s); |
410 | 9f149aa9 | pbrook | } else if (s->do_cmd) { |
411 | 9f149aa9 | pbrook | DPRINTF("command len %d\n", s->cmdlen);
|
412 | 9f149aa9 | pbrook | s->ti_size = 0;
|
413 | 9f149aa9 | pbrook | s->cmdlen = 0;
|
414 | 9f149aa9 | pbrook | s->do_cmd = 0;
|
415 | 9f149aa9 | pbrook | do_cmd(s, s->cmdbuf); |
416 | 9f149aa9 | pbrook | return;
|
417 | 9f149aa9 | pbrook | } |
418 | 2f275b8f | bellard | } |
419 | 2f275b8f | bellard | |
420 | 63235df8 | Blue Swirl | static void esp_reset(DeviceState *d) |
421 | 6f7e9aec | bellard | { |
422 | 63235df8 | Blue Swirl | ESPState *s = container_of(d, ESPState, busdev.qdev); |
423 | 67e999be | bellard | |
424 | 5aca8c3b | blueswir1 | memset(s->rregs, 0, ESP_REGS);
|
425 | 5aca8c3b | blueswir1 | memset(s->wregs, 0, ESP_REGS);
|
426 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCHI] = TCHI_FAS100A; // Indicate fas100a
|
427 | 4e9aec74 | pbrook | s->ti_size = 0;
|
428 | 4e9aec74 | pbrook | s->ti_rptr = 0;
|
429 | 4e9aec74 | pbrook | s->ti_wptr = 0;
|
430 | 4e9aec74 | pbrook | s->dma = 0;
|
431 | 9f149aa9 | pbrook | s->do_cmd = 0;
|
432 | 8dea1dd4 | blueswir1 | |
433 | 8dea1dd4 | blueswir1 | s->rregs[ESP_CFG1] = 7;
|
434 | 6f7e9aec | bellard | } |
435 | 6f7e9aec | bellard | |
436 | 2d069bab | blueswir1 | static void parent_esp_reset(void *opaque, int irq, int level) |
437 | 2d069bab | blueswir1 | { |
438 | 2d069bab | blueswir1 | if (level)
|
439 | 2d069bab | blueswir1 | esp_reset(opaque); |
440 | 2d069bab | blueswir1 | } |
441 | 2d069bab | blueswir1 | |
442 | c227f099 | Anthony Liguori | static uint32_t esp_mem_readb(void *opaque, target_phys_addr_t addr) |
443 | 6f7e9aec | bellard | { |
444 | 6f7e9aec | bellard | ESPState *s = opaque; |
445 | 2814df28 | Blue Swirl | uint32_t saddr, old_val; |
446 | 6f7e9aec | bellard | |
447 | e64d7d59 | blueswir1 | saddr = addr >> s->it_shift; |
448 | 9e61bde5 | bellard | DPRINTF("read reg[%d]: 0x%2.2x\n", saddr, s->rregs[saddr]);
|
449 | 6f7e9aec | bellard | switch (saddr) {
|
450 | 5ad6bb97 | blueswir1 | case ESP_FIFO:
|
451 | f930d07e | blueswir1 | if (s->ti_size > 0) { |
452 | f930d07e | blueswir1 | s->ti_size--; |
453 | 5ad6bb97 | blueswir1 | if ((s->rregs[ESP_RSTAT] & STAT_PIO_MASK) == 0) { |
454 | 8dea1dd4 | blueswir1 | /* Data out. */
|
455 | 8dea1dd4 | blueswir1 | ESP_ERROR("PIO data read not implemented\n");
|
456 | 5ad6bb97 | blueswir1 | s->rregs[ESP_FIFO] = 0;
|
457 | 2e5d83bb | pbrook | } else {
|
458 | 5ad6bb97 | blueswir1 | s->rregs[ESP_FIFO] = s->ti_buf[s->ti_rptr++]; |
459 | 2e5d83bb | pbrook | } |
460 | c73f96fd | blueswir1 | esp_raise_irq(s); |
461 | f930d07e | blueswir1 | } |
462 | f930d07e | blueswir1 | if (s->ti_size == 0) { |
463 | 4f6200f0 | bellard | s->ti_rptr = 0;
|
464 | 4f6200f0 | bellard | s->ti_wptr = 0;
|
465 | 4f6200f0 | bellard | } |
466 | f930d07e | blueswir1 | break;
|
467 | 5ad6bb97 | blueswir1 | case ESP_RINTR:
|
468 | 2814df28 | Blue Swirl | /* Clear sequence step, interrupt register and all status bits
|
469 | 2814df28 | Blue Swirl | except TC */
|
470 | 2814df28 | Blue Swirl | old_val = s->rregs[ESP_RINTR]; |
471 | 2814df28 | Blue Swirl | s->rregs[ESP_RINTR] = 0;
|
472 | 2814df28 | Blue Swirl | s->rregs[ESP_RSTAT] &= ~STAT_TC; |
473 | 2814df28 | Blue Swirl | s->rregs[ESP_RSEQ] = SEQ_CD; |
474 | c73f96fd | blueswir1 | esp_lower_irq(s); |
475 | 2814df28 | Blue Swirl | |
476 | 2814df28 | Blue Swirl | return old_val;
|
477 | 6f7e9aec | bellard | default:
|
478 | f930d07e | blueswir1 | break;
|
479 | 6f7e9aec | bellard | } |
480 | 2f275b8f | bellard | return s->rregs[saddr];
|
481 | 6f7e9aec | bellard | } |
482 | 6f7e9aec | bellard | |
483 | c227f099 | Anthony Liguori | static void esp_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
484 | 6f7e9aec | bellard | { |
485 | 6f7e9aec | bellard | ESPState *s = opaque; |
486 | 6f7e9aec | bellard | uint32_t saddr; |
487 | 6f7e9aec | bellard | |
488 | e64d7d59 | blueswir1 | saddr = addr >> s->it_shift; |
489 | 5ad6bb97 | blueswir1 | DPRINTF("write reg[%d]: 0x%2.2x -> 0x%2.2x\n", saddr, s->wregs[saddr],
|
490 | 5ad6bb97 | blueswir1 | val); |
491 | 6f7e9aec | bellard | switch (saddr) {
|
492 | 5ad6bb97 | blueswir1 | case ESP_TCLO:
|
493 | 5ad6bb97 | blueswir1 | case ESP_TCMID:
|
494 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSTAT] &= ~STAT_TC; |
495 | 4f6200f0 | bellard | break;
|
496 | 5ad6bb97 | blueswir1 | case ESP_FIFO:
|
497 | 9f149aa9 | pbrook | if (s->do_cmd) {
|
498 | 9f149aa9 | pbrook | s->cmdbuf[s->cmdlen++] = val & 0xff;
|
499 | 8dea1dd4 | blueswir1 | } else if (s->ti_size == TI_BUFSZ - 1) { |
500 | 8dea1dd4 | blueswir1 | ESP_ERROR("fifo overrun\n");
|
501 | 2e5d83bb | pbrook | } else {
|
502 | 2e5d83bb | pbrook | s->ti_size++; |
503 | 2e5d83bb | pbrook | s->ti_buf[s->ti_wptr++] = val & 0xff;
|
504 | 2e5d83bb | pbrook | } |
505 | f930d07e | blueswir1 | break;
|
506 | 5ad6bb97 | blueswir1 | case ESP_CMD:
|
507 | 4f6200f0 | bellard | s->rregs[saddr] = val; |
508 | 5ad6bb97 | blueswir1 | if (val & CMD_DMA) {
|
509 | f930d07e | blueswir1 | s->dma = 1;
|
510 | 6787f5fa | pbrook | /* Reload DMA counter. */
|
511 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCLO] = s->wregs[ESP_TCLO]; |
512 | 5ad6bb97 | blueswir1 | s->rregs[ESP_TCMID] = s->wregs[ESP_TCMID]; |
513 | f930d07e | blueswir1 | } else {
|
514 | f930d07e | blueswir1 | s->dma = 0;
|
515 | f930d07e | blueswir1 | } |
516 | 5ad6bb97 | blueswir1 | switch(val & CMD_CMD) {
|
517 | 5ad6bb97 | blueswir1 | case CMD_NOP:
|
518 | f930d07e | blueswir1 | DPRINTF("NOP (%2.2x)\n", val);
|
519 | f930d07e | blueswir1 | break;
|
520 | 5ad6bb97 | blueswir1 | case CMD_FLUSH:
|
521 | f930d07e | blueswir1 | DPRINTF("Flush FIFO (%2.2x)\n", val);
|
522 | 9e61bde5 | bellard | //s->ti_size = 0;
|
523 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_FC; |
524 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = 0;
|
525 | a214c598 | blueswir1 | s->rregs[ESP_RFLAGS] = 0;
|
526 | f930d07e | blueswir1 | break;
|
527 | 5ad6bb97 | blueswir1 | case CMD_RESET:
|
528 | f930d07e | blueswir1 | DPRINTF("Chip reset (%2.2x)\n", val);
|
529 | 63235df8 | Blue Swirl | esp_reset(&s->busdev.qdev); |
530 | f930d07e | blueswir1 | break;
|
531 | 5ad6bb97 | blueswir1 | case CMD_BUSRESET:
|
532 | f930d07e | blueswir1 | DPRINTF("Bus reset (%2.2x)\n", val);
|
533 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_RST; |
534 | 5ad6bb97 | blueswir1 | if (!(s->wregs[ESP_CFG1] & CFG1_RESREPT)) {
|
535 | c73f96fd | blueswir1 | esp_raise_irq(s); |
536 | 9e61bde5 | bellard | } |
537 | f930d07e | blueswir1 | break;
|
538 | 5ad6bb97 | blueswir1 | case CMD_TI:
|
539 | f930d07e | blueswir1 | handle_ti(s); |
540 | f930d07e | blueswir1 | break;
|
541 | 5ad6bb97 | blueswir1 | case CMD_ICCS:
|
542 | f930d07e | blueswir1 | DPRINTF("Initiator Command Complete Sequence (%2.2x)\n", val);
|
543 | f930d07e | blueswir1 | write_response(s); |
544 | 4bf5801d | blueswir1 | s->rregs[ESP_RINTR] = INTR_FC; |
545 | 4bf5801d | blueswir1 | s->rregs[ESP_RSTAT] |= STAT_MI; |
546 | f930d07e | blueswir1 | break;
|
547 | 5ad6bb97 | blueswir1 | case CMD_MSGACC:
|
548 | f930d07e | blueswir1 | DPRINTF("Message Accepted (%2.2x)\n", val);
|
549 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RINTR] = INTR_DC; |
550 | 5ad6bb97 | blueswir1 | s->rregs[ESP_RSEQ] = 0;
|
551 | 4e2a68c1 | Artyom Tarasenko | s->rregs[ESP_RFLAGS] = 0;
|
552 | 4e2a68c1 | Artyom Tarasenko | esp_raise_irq(s); |
553 | f930d07e | blueswir1 | break;
|
554 | 0fd0eb21 | Blue Swirl | case CMD_PAD:
|
555 | 0fd0eb21 | Blue Swirl | DPRINTF("Transfer padding (%2.2x)\n", val);
|
556 | 0fd0eb21 | Blue Swirl | s->rregs[ESP_RSTAT] = STAT_TC; |
557 | 0fd0eb21 | Blue Swirl | s->rregs[ESP_RINTR] = INTR_FC; |
558 | 0fd0eb21 | Blue Swirl | s->rregs[ESP_RSEQ] = 0;
|
559 | 0fd0eb21 | Blue Swirl | break;
|
560 | 5ad6bb97 | blueswir1 | case CMD_SATN:
|
561 | f930d07e | blueswir1 | DPRINTF("Set ATN (%2.2x)\n", val);
|
562 | f930d07e | blueswir1 | break;
|
563 | 5e1e0a3b | Blue Swirl | case CMD_SEL:
|
564 | 5e1e0a3b | Blue Swirl | DPRINTF("Select without ATN (%2.2x)\n", val);
|
565 | f2818f22 | Artyom Tarasenko | handle_s_without_atn(s); |
566 | 5e1e0a3b | Blue Swirl | break;
|
567 | 5ad6bb97 | blueswir1 | case CMD_SELATN:
|
568 | 5e1e0a3b | Blue Swirl | DPRINTF("Select with ATN (%2.2x)\n", val);
|
569 | f930d07e | blueswir1 | handle_satn(s); |
570 | f930d07e | blueswir1 | break;
|
571 | 5ad6bb97 | blueswir1 | case CMD_SELATNS:
|
572 | 5e1e0a3b | Blue Swirl | DPRINTF("Select with ATN & stop (%2.2x)\n", val);
|
573 | f930d07e | blueswir1 | handle_satn_stop(s); |
574 | f930d07e | blueswir1 | break;
|
575 | 5ad6bb97 | blueswir1 | case CMD_ENSEL:
|
576 | 74ec6048 | blueswir1 | DPRINTF("Enable selection (%2.2x)\n", val);
|
577 | e3926838 | blueswir1 | s->rregs[ESP_RINTR] = 0;
|
578 | 74ec6048 | blueswir1 | break;
|
579 | f930d07e | blueswir1 | default:
|
580 | 8dea1dd4 | blueswir1 | ESP_ERROR("Unhandled ESP command (%2.2x)\n", val);
|
581 | f930d07e | blueswir1 | break;
|
582 | f930d07e | blueswir1 | } |
583 | f930d07e | blueswir1 | break;
|
584 | 5ad6bb97 | blueswir1 | case ESP_WBUSID ... ESP_WSYNO:
|
585 | f930d07e | blueswir1 | break;
|
586 | 5ad6bb97 | blueswir1 | case ESP_CFG1:
|
587 | 4f6200f0 | bellard | s->rregs[saddr] = val; |
588 | 4f6200f0 | bellard | break;
|
589 | 5ad6bb97 | blueswir1 | case ESP_WCCF ... ESP_WTEST:
|
590 | 4f6200f0 | bellard | break;
|
591 | b44c08fa | blueswir1 | case ESP_CFG2 ... ESP_RES4:
|
592 | 4f6200f0 | bellard | s->rregs[saddr] = val; |
593 | 4f6200f0 | bellard | break;
|
594 | 6f7e9aec | bellard | default:
|
595 | 8dea1dd4 | blueswir1 | ESP_ERROR("invalid write of 0x%02x at [0x%x]\n", val, saddr);
|
596 | 8dea1dd4 | blueswir1 | return;
|
597 | 6f7e9aec | bellard | } |
598 | 2f275b8f | bellard | s->wregs[saddr] = val; |
599 | 6f7e9aec | bellard | } |
600 | 6f7e9aec | bellard | |
601 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const esp_mem_read[3] = { |
602 | 6f7e9aec | bellard | esp_mem_readb, |
603 | 7c560456 | blueswir1 | NULL,
|
604 | 7c560456 | blueswir1 | NULL,
|
605 | 6f7e9aec | bellard | }; |
606 | 6f7e9aec | bellard | |
607 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const esp_mem_write[3] = { |
608 | 6f7e9aec | bellard | esp_mem_writeb, |
609 | 7c560456 | blueswir1 | NULL,
|
610 | daa41b00 | blueswir1 | esp_mem_writeb, |
611 | 6f7e9aec | bellard | }; |
612 | 6f7e9aec | bellard | |
613 | cc9952f3 | Blue Swirl | static const VMStateDescription vmstate_esp = { |
614 | cc9952f3 | Blue Swirl | .name ="esp",
|
615 | cc9952f3 | Blue Swirl | .version_id = 3,
|
616 | cc9952f3 | Blue Swirl | .minimum_version_id = 3,
|
617 | cc9952f3 | Blue Swirl | .minimum_version_id_old = 3,
|
618 | cc9952f3 | Blue Swirl | .fields = (VMStateField []) { |
619 | cc9952f3 | Blue Swirl | VMSTATE_BUFFER(rregs, ESPState), |
620 | cc9952f3 | Blue Swirl | VMSTATE_BUFFER(wregs, ESPState), |
621 | cc9952f3 | Blue Swirl | VMSTATE_INT32(ti_size, ESPState), |
622 | cc9952f3 | Blue Swirl | VMSTATE_UINT32(ti_rptr, ESPState), |
623 | cc9952f3 | Blue Swirl | VMSTATE_UINT32(ti_wptr, ESPState), |
624 | cc9952f3 | Blue Swirl | VMSTATE_BUFFER(ti_buf, ESPState), |
625 | cc9952f3 | Blue Swirl | VMSTATE_UINT32(sense, ESPState), |
626 | cc9952f3 | Blue Swirl | VMSTATE_UINT32(dma, ESPState), |
627 | cc9952f3 | Blue Swirl | VMSTATE_BUFFER(cmdbuf, ESPState), |
628 | cc9952f3 | Blue Swirl | VMSTATE_UINT32(cmdlen, ESPState), |
629 | cc9952f3 | Blue Swirl | VMSTATE_UINT32(do_cmd, ESPState), |
630 | cc9952f3 | Blue Swirl | VMSTATE_UINT32(dma_left, ESPState), |
631 | cc9952f3 | Blue Swirl | VMSTATE_END_OF_LIST() |
632 | cc9952f3 | Blue Swirl | } |
633 | cc9952f3 | Blue Swirl | }; |
634 | 6f7e9aec | bellard | |
635 | c227f099 | Anthony Liguori | void esp_init(target_phys_addr_t espaddr, int it_shift, |
636 | cfb9de9c | Paul Brook | espdma_memory_read_write dma_memory_read, |
637 | cfb9de9c | Paul Brook | espdma_memory_read_write dma_memory_write, |
638 | cfb9de9c | Paul Brook | void *dma_opaque, qemu_irq irq, qemu_irq *reset)
|
639 | 6f7e9aec | bellard | { |
640 | cfb9de9c | Paul Brook | DeviceState *dev; |
641 | cfb9de9c | Paul Brook | SysBusDevice *s; |
642 | ee6847d1 | Gerd Hoffmann | ESPState *esp; |
643 | cfb9de9c | Paul Brook | |
644 | cfb9de9c | Paul Brook | dev = qdev_create(NULL, "esp"); |
645 | ee6847d1 | Gerd Hoffmann | esp = DO_UPCAST(ESPState, busdev.qdev, dev); |
646 | ee6847d1 | Gerd Hoffmann | esp->dma_memory_read = dma_memory_read; |
647 | ee6847d1 | Gerd Hoffmann | esp->dma_memory_write = dma_memory_write; |
648 | ee6847d1 | Gerd Hoffmann | esp->dma_opaque = dma_opaque; |
649 | ee6847d1 | Gerd Hoffmann | esp->it_shift = it_shift; |
650 | e23a1b33 | Markus Armbruster | qdev_init_nofail(dev); |
651 | cfb9de9c | Paul Brook | s = sysbus_from_qdev(dev); |
652 | cfb9de9c | Paul Brook | sysbus_connect_irq(s, 0, irq);
|
653 | cfb9de9c | Paul Brook | sysbus_mmio_map(s, 0, espaddr);
|
654 | 74ff8d90 | Blue Swirl | *reset = qdev_get_gpio_in(dev, 0);
|
655 | cfb9de9c | Paul Brook | } |
656 | 6f7e9aec | bellard | |
657 | 81a322d4 | Gerd Hoffmann | static int esp_init1(SysBusDevice *dev) |
658 | cfb9de9c | Paul Brook | { |
659 | cfb9de9c | Paul Brook | ESPState *s = FROM_SYSBUS(ESPState, dev); |
660 | cfb9de9c | Paul Brook | int esp_io_memory;
|
661 | 6f7e9aec | bellard | |
662 | cfb9de9c | Paul Brook | sysbus_init_irq(dev, &s->irq); |
663 | cfb9de9c | Paul Brook | assert(s->it_shift != -1);
|
664 | 6f7e9aec | bellard | |
665 | 1eed09cb | Avi Kivity | esp_io_memory = cpu_register_io_memory(esp_mem_read, esp_mem_write, s); |
666 | cfb9de9c | Paul Brook | sysbus_init_mmio(dev, ESP_REGS << s->it_shift, esp_io_memory); |
667 | 6f7e9aec | bellard | |
668 | 067a3ddc | Paul Brook | qdev_init_gpio_in(&dev->qdev, parent_esp_reset, 1);
|
669 | 2d069bab | blueswir1 | |
670 | ca9c39fa | Gerd Hoffmann | scsi_bus_new(&s->bus, &dev->qdev, 0, ESP_MAX_DEVS, esp_command_complete);
|
671 | ca9c39fa | Gerd Hoffmann | scsi_bus_legacy_handle_cmdline(&s->bus); |
672 | 81a322d4 | Gerd Hoffmann | return 0; |
673 | 67e999be | bellard | } |
674 | cfb9de9c | Paul Brook | |
675 | 63235df8 | Blue Swirl | static SysBusDeviceInfo esp_info = {
|
676 | 63235df8 | Blue Swirl | .init = esp_init1, |
677 | 63235df8 | Blue Swirl | .qdev.name = "esp",
|
678 | 63235df8 | Blue Swirl | .qdev.size = sizeof(ESPState),
|
679 | 63235df8 | Blue Swirl | .qdev.vmsd = &vmstate_esp, |
680 | 63235df8 | Blue Swirl | .qdev.reset = esp_reset, |
681 | 63235df8 | Blue Swirl | .qdev.props = (Property[]) { |
682 | 63235df8 | Blue Swirl | {.name = NULL}
|
683 | 63235df8 | Blue Swirl | } |
684 | 63235df8 | Blue Swirl | }; |
685 | 63235df8 | Blue Swirl | |
686 | cfb9de9c | Paul Brook | static void esp_register_devices(void) |
687 | cfb9de9c | Paul Brook | { |
688 | 63235df8 | Blue Swirl | sysbus_register_withprop(&esp_info); |
689 | cfb9de9c | Paul Brook | } |
690 | cfb9de9c | Paul Brook | |
691 | cfb9de9c | Paul Brook | device_init(esp_register_devices) |