root / hw / lsi53c895a.c @ cc9f28bc
History | View | Annotate | Download (60.3 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | 7d8406be | pbrook | * QEMU LSI53C895A SCSI Host Bus Adapter emulation
|
3 | 7d8406be | pbrook | *
|
4 | 7d8406be | pbrook | * Copyright (c) 2006 CodeSourcery.
|
5 | 7d8406be | pbrook | * Written by Paul Brook
|
6 | 7d8406be | pbrook | *
|
7 | 7d8406be | pbrook | * This code is licenced under the LGPL.
|
8 | 7d8406be | pbrook | */
|
9 | 7d8406be | pbrook | |
10 | 7d8406be | pbrook | /* ??? Need to check if the {read,write}[wl] routines work properly on
|
11 | 7d8406be | pbrook | big-endian targets. */
|
12 | 7d8406be | pbrook | |
13 | a15fdf86 | Laszlo Ast | #include <assert.h> |
14 | 777aec7a | Nolan | |
15 | 87ecb68b | pbrook | #include "hw.h" |
16 | 87ecb68b | pbrook | #include "pci.h" |
17 | 43b443b6 | Gerd Hoffmann | #include "scsi.h" |
18 | b0a7b120 | aliguori | #include "block_int.h" |
19 | 7d8406be | pbrook | |
20 | 7d8406be | pbrook | //#define DEBUG_LSI
|
21 | 7d8406be | pbrook | //#define DEBUG_LSI_REG
|
22 | 7d8406be | pbrook | |
23 | 7d8406be | pbrook | #ifdef DEBUG_LSI
|
24 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) \
|
25 | 001faf32 | Blue Swirl | do { printf("lsi_scsi: " fmt , ## __VA_ARGS__); } while (0) |
26 | 001faf32 | Blue Swirl | #define BADF(fmt, ...) \
|
27 | 001faf32 | Blue Swirl | do { fprintf(stderr, "lsi_scsi: error: " fmt , ## __VA_ARGS__); exit(1);} while (0) |
28 | 7d8406be | pbrook | #else
|
29 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) do {} while(0) |
30 | 001faf32 | Blue Swirl | #define BADF(fmt, ...) \
|
31 | 001faf32 | Blue Swirl | do { fprintf(stderr, "lsi_scsi: error: " fmt , ## __VA_ARGS__);} while (0) |
32 | 7d8406be | pbrook | #endif
|
33 | 7d8406be | pbrook | |
34 | 18e08a55 | Michael S. Tsirkin | #define LSI_MAX_DEVS 7 |
35 | 18e08a55 | Michael S. Tsirkin | |
36 | 7d8406be | pbrook | #define LSI_SCNTL0_TRG 0x01 |
37 | 7d8406be | pbrook | #define LSI_SCNTL0_AAP 0x02 |
38 | 7d8406be | pbrook | #define LSI_SCNTL0_EPC 0x08 |
39 | 7d8406be | pbrook | #define LSI_SCNTL0_WATN 0x10 |
40 | 7d8406be | pbrook | #define LSI_SCNTL0_START 0x20 |
41 | 7d8406be | pbrook | |
42 | 7d8406be | pbrook | #define LSI_SCNTL1_SST 0x01 |
43 | 7d8406be | pbrook | #define LSI_SCNTL1_IARB 0x02 |
44 | 7d8406be | pbrook | #define LSI_SCNTL1_AESP 0x04 |
45 | 7d8406be | pbrook | #define LSI_SCNTL1_RST 0x08 |
46 | 7d8406be | pbrook | #define LSI_SCNTL1_CON 0x10 |
47 | 7d8406be | pbrook | #define LSI_SCNTL1_DHP 0x20 |
48 | 7d8406be | pbrook | #define LSI_SCNTL1_ADB 0x40 |
49 | 7d8406be | pbrook | #define LSI_SCNTL1_EXC 0x80 |
50 | 7d8406be | pbrook | |
51 | 7d8406be | pbrook | #define LSI_SCNTL2_WSR 0x01 |
52 | 7d8406be | pbrook | #define LSI_SCNTL2_VUE0 0x02 |
53 | 7d8406be | pbrook | #define LSI_SCNTL2_VUE1 0x04 |
54 | 7d8406be | pbrook | #define LSI_SCNTL2_WSS 0x08 |
55 | 7d8406be | pbrook | #define LSI_SCNTL2_SLPHBEN 0x10 |
56 | 7d8406be | pbrook | #define LSI_SCNTL2_SLPMD 0x20 |
57 | 7d8406be | pbrook | #define LSI_SCNTL2_CHM 0x40 |
58 | 7d8406be | pbrook | #define LSI_SCNTL2_SDU 0x80 |
59 | 7d8406be | pbrook | |
60 | 7d8406be | pbrook | #define LSI_ISTAT0_DIP 0x01 |
61 | 7d8406be | pbrook | #define LSI_ISTAT0_SIP 0x02 |
62 | 7d8406be | pbrook | #define LSI_ISTAT0_INTF 0x04 |
63 | 7d8406be | pbrook | #define LSI_ISTAT0_CON 0x08 |
64 | 7d8406be | pbrook | #define LSI_ISTAT0_SEM 0x10 |
65 | 7d8406be | pbrook | #define LSI_ISTAT0_SIGP 0x20 |
66 | 7d8406be | pbrook | #define LSI_ISTAT0_SRST 0x40 |
67 | 7d8406be | pbrook | #define LSI_ISTAT0_ABRT 0x80 |
68 | 7d8406be | pbrook | |
69 | 7d8406be | pbrook | #define LSI_ISTAT1_SI 0x01 |
70 | 7d8406be | pbrook | #define LSI_ISTAT1_SRUN 0x02 |
71 | 7d8406be | pbrook | #define LSI_ISTAT1_FLSH 0x04 |
72 | 7d8406be | pbrook | |
73 | 7d8406be | pbrook | #define LSI_SSTAT0_SDP0 0x01 |
74 | 7d8406be | pbrook | #define LSI_SSTAT0_RST 0x02 |
75 | 7d8406be | pbrook | #define LSI_SSTAT0_WOA 0x04 |
76 | 7d8406be | pbrook | #define LSI_SSTAT0_LOA 0x08 |
77 | 7d8406be | pbrook | #define LSI_SSTAT0_AIP 0x10 |
78 | 7d8406be | pbrook | #define LSI_SSTAT0_OLF 0x20 |
79 | 7d8406be | pbrook | #define LSI_SSTAT0_ORF 0x40 |
80 | 7d8406be | pbrook | #define LSI_SSTAT0_ILF 0x80 |
81 | 7d8406be | pbrook | |
82 | 7d8406be | pbrook | #define LSI_SIST0_PAR 0x01 |
83 | 7d8406be | pbrook | #define LSI_SIST0_RST 0x02 |
84 | 7d8406be | pbrook | #define LSI_SIST0_UDC 0x04 |
85 | 7d8406be | pbrook | #define LSI_SIST0_SGE 0x08 |
86 | 7d8406be | pbrook | #define LSI_SIST0_RSL 0x10 |
87 | 7d8406be | pbrook | #define LSI_SIST0_SEL 0x20 |
88 | 7d8406be | pbrook | #define LSI_SIST0_CMP 0x40 |
89 | 7d8406be | pbrook | #define LSI_SIST0_MA 0x80 |
90 | 7d8406be | pbrook | |
91 | 7d8406be | pbrook | #define LSI_SIST1_HTH 0x01 |
92 | 7d8406be | pbrook | #define LSI_SIST1_GEN 0x02 |
93 | 7d8406be | pbrook | #define LSI_SIST1_STO 0x04 |
94 | 7d8406be | pbrook | #define LSI_SIST1_SBMC 0x10 |
95 | 7d8406be | pbrook | |
96 | 7d8406be | pbrook | #define LSI_SOCL_IO 0x01 |
97 | 7d8406be | pbrook | #define LSI_SOCL_CD 0x02 |
98 | 7d8406be | pbrook | #define LSI_SOCL_MSG 0x04 |
99 | 7d8406be | pbrook | #define LSI_SOCL_ATN 0x08 |
100 | 7d8406be | pbrook | #define LSI_SOCL_SEL 0x10 |
101 | 7d8406be | pbrook | #define LSI_SOCL_BSY 0x20 |
102 | 7d8406be | pbrook | #define LSI_SOCL_ACK 0x40 |
103 | 7d8406be | pbrook | #define LSI_SOCL_REQ 0x80 |
104 | 7d8406be | pbrook | |
105 | 7d8406be | pbrook | #define LSI_DSTAT_IID 0x01 |
106 | 7d8406be | pbrook | #define LSI_DSTAT_SIR 0x04 |
107 | 7d8406be | pbrook | #define LSI_DSTAT_SSI 0x08 |
108 | 7d8406be | pbrook | #define LSI_DSTAT_ABRT 0x10 |
109 | 7d8406be | pbrook | #define LSI_DSTAT_BF 0x20 |
110 | 7d8406be | pbrook | #define LSI_DSTAT_MDPE 0x40 |
111 | 7d8406be | pbrook | #define LSI_DSTAT_DFE 0x80 |
112 | 7d8406be | pbrook | |
113 | 7d8406be | pbrook | #define LSI_DCNTL_COM 0x01 |
114 | 7d8406be | pbrook | #define LSI_DCNTL_IRQD 0x02 |
115 | 7d8406be | pbrook | #define LSI_DCNTL_STD 0x04 |
116 | 7d8406be | pbrook | #define LSI_DCNTL_IRQM 0x08 |
117 | 7d8406be | pbrook | #define LSI_DCNTL_SSM 0x10 |
118 | 7d8406be | pbrook | #define LSI_DCNTL_PFEN 0x20 |
119 | 7d8406be | pbrook | #define LSI_DCNTL_PFF 0x40 |
120 | 7d8406be | pbrook | #define LSI_DCNTL_CLSE 0x80 |
121 | 7d8406be | pbrook | |
122 | 7d8406be | pbrook | #define LSI_DMODE_MAN 0x01 |
123 | 7d8406be | pbrook | #define LSI_DMODE_BOF 0x02 |
124 | 7d8406be | pbrook | #define LSI_DMODE_ERMP 0x04 |
125 | 7d8406be | pbrook | #define LSI_DMODE_ERL 0x08 |
126 | 7d8406be | pbrook | #define LSI_DMODE_DIOM 0x10 |
127 | 7d8406be | pbrook | #define LSI_DMODE_SIOM 0x20 |
128 | 7d8406be | pbrook | |
129 | 7d8406be | pbrook | #define LSI_CTEST2_DACK 0x01 |
130 | 7d8406be | pbrook | #define LSI_CTEST2_DREQ 0x02 |
131 | 7d8406be | pbrook | #define LSI_CTEST2_TEOP 0x04 |
132 | 7d8406be | pbrook | #define LSI_CTEST2_PCICIE 0x08 |
133 | 7d8406be | pbrook | #define LSI_CTEST2_CM 0x10 |
134 | 7d8406be | pbrook | #define LSI_CTEST2_CIO 0x20 |
135 | 7d8406be | pbrook | #define LSI_CTEST2_SIGP 0x40 |
136 | 7d8406be | pbrook | #define LSI_CTEST2_DDIR 0x80 |
137 | 7d8406be | pbrook | |
138 | 7d8406be | pbrook | #define LSI_CTEST5_BL2 0x04 |
139 | 7d8406be | pbrook | #define LSI_CTEST5_DDIR 0x08 |
140 | 7d8406be | pbrook | #define LSI_CTEST5_MASR 0x10 |
141 | 7d8406be | pbrook | #define LSI_CTEST5_DFSN 0x20 |
142 | 7d8406be | pbrook | #define LSI_CTEST5_BBCK 0x40 |
143 | 7d8406be | pbrook | #define LSI_CTEST5_ADCK 0x80 |
144 | 7d8406be | pbrook | |
145 | 7d8406be | pbrook | #define LSI_CCNTL0_DILS 0x01 |
146 | 7d8406be | pbrook | #define LSI_CCNTL0_DISFC 0x10 |
147 | 7d8406be | pbrook | #define LSI_CCNTL0_ENNDJ 0x20 |
148 | 7d8406be | pbrook | #define LSI_CCNTL0_PMJCTL 0x40 |
149 | 7d8406be | pbrook | #define LSI_CCNTL0_ENPMJ 0x80 |
150 | 7d8406be | pbrook | |
151 | b25cf589 | aliguori | #define LSI_CCNTL1_EN64DBMV 0x01 |
152 | b25cf589 | aliguori | #define LSI_CCNTL1_EN64TIBMV 0x02 |
153 | b25cf589 | aliguori | #define LSI_CCNTL1_64TIMOD 0x04 |
154 | b25cf589 | aliguori | #define LSI_CCNTL1_DDAC 0x08 |
155 | b25cf589 | aliguori | #define LSI_CCNTL1_ZMOD 0x80 |
156 | b25cf589 | aliguori | |
157 | b25cf589 | aliguori | #define LSI_CCNTL1_40BIT (LSI_CCNTL1_EN64TIBMV|LSI_CCNTL1_64TIMOD)
|
158 | b25cf589 | aliguori | |
159 | 7d8406be | pbrook | #define PHASE_DO 0 |
160 | 7d8406be | pbrook | #define PHASE_DI 1 |
161 | 7d8406be | pbrook | #define PHASE_CMD 2 |
162 | 7d8406be | pbrook | #define PHASE_ST 3 |
163 | 7d8406be | pbrook | #define PHASE_MO 6 |
164 | 7d8406be | pbrook | #define PHASE_MI 7 |
165 | 7d8406be | pbrook | #define PHASE_MASK 7 |
166 | 7d8406be | pbrook | |
167 | a917d384 | pbrook | /* Maximum length of MSG IN data. */
|
168 | a917d384 | pbrook | #define LSI_MAX_MSGIN_LEN 8 |
169 | a917d384 | pbrook | |
170 | a917d384 | pbrook | /* Flag set if this is a tagged command. */
|
171 | a917d384 | pbrook | #define LSI_TAG_VALID (1 << 16) |
172 | a917d384 | pbrook | |
173 | a917d384 | pbrook | typedef struct { |
174 | a917d384 | pbrook | uint32_t tag; |
175 | a917d384 | pbrook | uint32_t pending; |
176 | a917d384 | pbrook | int out;
|
177 | a917d384 | pbrook | } lsi_queue; |
178 | 4d611c9a | pbrook | |
179 | 7d8406be | pbrook | typedef struct { |
180 | f305261f | Juan Quintela | PCIDevice dev; |
181 | 7d8406be | pbrook | int mmio_io_addr;
|
182 | 7d8406be | pbrook | int ram_io_addr;
|
183 | 7d8406be | pbrook | uint32_t script_ram_base; |
184 | 7d8406be | pbrook | |
185 | 7d8406be | pbrook | int carry; /* ??? Should this be an a visible register somewhere? */ |
186 | 7d8406be | pbrook | int sense;
|
187 | a917d384 | pbrook | /* Action to take at the end of a MSG IN phase.
|
188 | a15fdf86 | Laszlo Ast | 0 = COMMAND, 1 = disconnect, 2 = DATA OUT, 3 = DATA IN. */
|
189 | a917d384 | pbrook | int msg_action;
|
190 | a917d384 | pbrook | int msg_len;
|
191 | a917d384 | pbrook | uint8_t msg[LSI_MAX_MSGIN_LEN]; |
192 | 4d611c9a | pbrook | /* 0 if SCRIPTS are running or stopped.
|
193 | 4d611c9a | pbrook | * 1 if a Wait Reselect instruction has been issued.
|
194 | a917d384 | pbrook | * 2 if processing DMA from lsi_execute_script.
|
195 | a917d384 | pbrook | * 3 if a DMA operation is in progress. */
|
196 | 7d8406be | pbrook | int waiting;
|
197 | ca9c39fa | Gerd Hoffmann | SCSIBus bus; |
198 | 7d8406be | pbrook | SCSIDevice *current_dev; |
199 | 7d8406be | pbrook | int current_lun;
|
200 | a917d384 | pbrook | /* The tag is a combination of the device ID and the SCSI tag. */
|
201 | a917d384 | pbrook | uint32_t current_tag; |
202 | a917d384 | pbrook | uint32_t current_dma_len; |
203 | 8ccc2ace | ths | int command_complete;
|
204 | a917d384 | pbrook | uint8_t *dma_buf; |
205 | a917d384 | pbrook | lsi_queue *queue; |
206 | a917d384 | pbrook | int queue_len;
|
207 | a917d384 | pbrook | int active_commands;
|
208 | 7d8406be | pbrook | |
209 | 7d8406be | pbrook | uint32_t dsa; |
210 | 7d8406be | pbrook | uint32_t temp; |
211 | 7d8406be | pbrook | uint32_t dnad; |
212 | 7d8406be | pbrook | uint32_t dbc; |
213 | 7d8406be | pbrook | uint8_t istat0; |
214 | 7d8406be | pbrook | uint8_t istat1; |
215 | 7d8406be | pbrook | uint8_t dcmd; |
216 | 7d8406be | pbrook | uint8_t dstat; |
217 | 7d8406be | pbrook | uint8_t dien; |
218 | 7d8406be | pbrook | uint8_t sist0; |
219 | 7d8406be | pbrook | uint8_t sist1; |
220 | 7d8406be | pbrook | uint8_t sien0; |
221 | 7d8406be | pbrook | uint8_t sien1; |
222 | 7d8406be | pbrook | uint8_t mbox0; |
223 | 7d8406be | pbrook | uint8_t mbox1; |
224 | 7d8406be | pbrook | uint8_t dfifo; |
225 | 9167a69a | balrog | uint8_t ctest2; |
226 | 7d8406be | pbrook | uint8_t ctest3; |
227 | 7d8406be | pbrook | uint8_t ctest4; |
228 | 7d8406be | pbrook | uint8_t ctest5; |
229 | 7d8406be | pbrook | uint8_t ccntl0; |
230 | 7d8406be | pbrook | uint8_t ccntl1; |
231 | 7d8406be | pbrook | uint32_t dsp; |
232 | 7d8406be | pbrook | uint32_t dsps; |
233 | 7d8406be | pbrook | uint8_t dmode; |
234 | 7d8406be | pbrook | uint8_t dcntl; |
235 | 7d8406be | pbrook | uint8_t scntl0; |
236 | 7d8406be | pbrook | uint8_t scntl1; |
237 | 7d8406be | pbrook | uint8_t scntl2; |
238 | 7d8406be | pbrook | uint8_t scntl3; |
239 | 7d8406be | pbrook | uint8_t sstat0; |
240 | 7d8406be | pbrook | uint8_t sstat1; |
241 | 7d8406be | pbrook | uint8_t scid; |
242 | 7d8406be | pbrook | uint8_t sxfer; |
243 | 7d8406be | pbrook | uint8_t socl; |
244 | 7d8406be | pbrook | uint8_t sdid; |
245 | a917d384 | pbrook | uint8_t ssid; |
246 | 7d8406be | pbrook | uint8_t sfbr; |
247 | 7d8406be | pbrook | uint8_t stest1; |
248 | 7d8406be | pbrook | uint8_t stest2; |
249 | 7d8406be | pbrook | uint8_t stest3; |
250 | a917d384 | pbrook | uint8_t sidl; |
251 | 7d8406be | pbrook | uint8_t stime0; |
252 | 7d8406be | pbrook | uint8_t respid0; |
253 | 7d8406be | pbrook | uint8_t respid1; |
254 | 7d8406be | pbrook | uint32_t mmrs; |
255 | 7d8406be | pbrook | uint32_t mmws; |
256 | 7d8406be | pbrook | uint32_t sfs; |
257 | 7d8406be | pbrook | uint32_t drs; |
258 | 7d8406be | pbrook | uint32_t sbms; |
259 | ab57d967 | aliguori | uint32_t dbms; |
260 | 7d8406be | pbrook | uint32_t dnad64; |
261 | 7d8406be | pbrook | uint32_t pmjad1; |
262 | 7d8406be | pbrook | uint32_t pmjad2; |
263 | 7d8406be | pbrook | uint32_t rbc; |
264 | 7d8406be | pbrook | uint32_t ua; |
265 | 7d8406be | pbrook | uint32_t ia; |
266 | 7d8406be | pbrook | uint32_t sbc; |
267 | 7d8406be | pbrook | uint32_t csbc; |
268 | dcfb9014 | ths | uint32_t scratch[18]; /* SCRATCHA-SCRATCHR */ |
269 | bd8ee11a | Sebastian Herbszt | uint8_t sbr; |
270 | 7d8406be | pbrook | |
271 | 7d8406be | pbrook | /* Script ram is stored as 32-bit words in host byteorder. */
|
272 | 7d8406be | pbrook | uint32_t script_ram[2048];
|
273 | 7d8406be | pbrook | } LSIState; |
274 | 7d8406be | pbrook | |
275 | 7d8406be | pbrook | static void lsi_soft_reset(LSIState *s) |
276 | 7d8406be | pbrook | { |
277 | 7d8406be | pbrook | DPRINTF("Reset\n");
|
278 | 7d8406be | pbrook | s->carry = 0;
|
279 | 7d8406be | pbrook | |
280 | 7d8406be | pbrook | s->waiting = 0;
|
281 | 7d8406be | pbrook | s->dsa = 0;
|
282 | 7d8406be | pbrook | s->dnad = 0;
|
283 | 7d8406be | pbrook | s->dbc = 0;
|
284 | 7d8406be | pbrook | s->temp = 0;
|
285 | 7d8406be | pbrook | memset(s->scratch, 0, sizeof(s->scratch)); |
286 | 7d8406be | pbrook | s->istat0 = 0;
|
287 | 7d8406be | pbrook | s->istat1 = 0;
|
288 | 7d8406be | pbrook | s->dcmd = 0;
|
289 | 7d8406be | pbrook | s->dstat = 0;
|
290 | 7d8406be | pbrook | s->dien = 0;
|
291 | 7d8406be | pbrook | s->sist0 = 0;
|
292 | 7d8406be | pbrook | s->sist1 = 0;
|
293 | 7d8406be | pbrook | s->sien0 = 0;
|
294 | 7d8406be | pbrook | s->sien1 = 0;
|
295 | 7d8406be | pbrook | s->mbox0 = 0;
|
296 | 7d8406be | pbrook | s->mbox1 = 0;
|
297 | 7d8406be | pbrook | s->dfifo = 0;
|
298 | 9167a69a | balrog | s->ctest2 = 0;
|
299 | 7d8406be | pbrook | s->ctest3 = 0;
|
300 | 7d8406be | pbrook | s->ctest4 = 0;
|
301 | 7d8406be | pbrook | s->ctest5 = 0;
|
302 | 7d8406be | pbrook | s->ccntl0 = 0;
|
303 | 7d8406be | pbrook | s->ccntl1 = 0;
|
304 | 7d8406be | pbrook | s->dsp = 0;
|
305 | 7d8406be | pbrook | s->dsps = 0;
|
306 | 7d8406be | pbrook | s->dmode = 0;
|
307 | 7d8406be | pbrook | s->dcntl = 0;
|
308 | 7d8406be | pbrook | s->scntl0 = 0xc0;
|
309 | 7d8406be | pbrook | s->scntl1 = 0;
|
310 | 7d8406be | pbrook | s->scntl2 = 0;
|
311 | 7d8406be | pbrook | s->scntl3 = 0;
|
312 | 7d8406be | pbrook | s->sstat0 = 0;
|
313 | 7d8406be | pbrook | s->sstat1 = 0;
|
314 | 7d8406be | pbrook | s->scid = 7;
|
315 | 7d8406be | pbrook | s->sxfer = 0;
|
316 | 7d8406be | pbrook | s->socl = 0;
|
317 | 7d8406be | pbrook | s->stest1 = 0;
|
318 | 7d8406be | pbrook | s->stest2 = 0;
|
319 | 7d8406be | pbrook | s->stest3 = 0;
|
320 | a917d384 | pbrook | s->sidl = 0;
|
321 | 7d8406be | pbrook | s->stime0 = 0;
|
322 | 7d8406be | pbrook | s->respid0 = 0x80;
|
323 | 7d8406be | pbrook | s->respid1 = 0;
|
324 | 7d8406be | pbrook | s->mmrs = 0;
|
325 | 7d8406be | pbrook | s->mmws = 0;
|
326 | 7d8406be | pbrook | s->sfs = 0;
|
327 | 7d8406be | pbrook | s->drs = 0;
|
328 | 7d8406be | pbrook | s->sbms = 0;
|
329 | ab57d967 | aliguori | s->dbms = 0;
|
330 | 7d8406be | pbrook | s->dnad64 = 0;
|
331 | 7d8406be | pbrook | s->pmjad1 = 0;
|
332 | 7d8406be | pbrook | s->pmjad2 = 0;
|
333 | 7d8406be | pbrook | s->rbc = 0;
|
334 | 7d8406be | pbrook | s->ua = 0;
|
335 | 7d8406be | pbrook | s->ia = 0;
|
336 | 7d8406be | pbrook | s->sbc = 0;
|
337 | 7d8406be | pbrook | s->csbc = 0;
|
338 | bd8ee11a | Sebastian Herbszt | s->sbr = 0;
|
339 | 7d8406be | pbrook | } |
340 | 7d8406be | pbrook | |
341 | b25cf589 | aliguori | static int lsi_dma_40bit(LSIState *s) |
342 | b25cf589 | aliguori | { |
343 | b25cf589 | aliguori | if ((s->ccntl1 & LSI_CCNTL1_40BIT) == LSI_CCNTL1_40BIT)
|
344 | b25cf589 | aliguori | return 1; |
345 | b25cf589 | aliguori | return 0; |
346 | b25cf589 | aliguori | } |
347 | b25cf589 | aliguori | |
348 | dd8edf01 | aliguori | static int lsi_dma_ti64bit(LSIState *s) |
349 | dd8edf01 | aliguori | { |
350 | dd8edf01 | aliguori | if ((s->ccntl1 & LSI_CCNTL1_EN64TIBMV) == LSI_CCNTL1_EN64TIBMV)
|
351 | dd8edf01 | aliguori | return 1; |
352 | dd8edf01 | aliguori | return 0; |
353 | dd8edf01 | aliguori | } |
354 | dd8edf01 | aliguori | |
355 | dd8edf01 | aliguori | static int lsi_dma_64bit(LSIState *s) |
356 | dd8edf01 | aliguori | { |
357 | dd8edf01 | aliguori | if ((s->ccntl1 & LSI_CCNTL1_EN64DBMV) == LSI_CCNTL1_EN64DBMV)
|
358 | dd8edf01 | aliguori | return 1; |
359 | dd8edf01 | aliguori | return 0; |
360 | dd8edf01 | aliguori | } |
361 | dd8edf01 | aliguori | |
362 | 7d8406be | pbrook | static uint8_t lsi_reg_readb(LSIState *s, int offset); |
363 | 7d8406be | pbrook | static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val); |
364 | 4d611c9a | pbrook | static void lsi_execute_script(LSIState *s); |
365 | 7d8406be | pbrook | |
366 | 7d8406be | pbrook | static inline uint32_t read_dword(LSIState *s, uint32_t addr) |
367 | 7d8406be | pbrook | { |
368 | 7d8406be | pbrook | uint32_t buf; |
369 | 7d8406be | pbrook | |
370 | 7d8406be | pbrook | /* Optimize reading from SCRIPTS RAM. */
|
371 | 7d8406be | pbrook | if ((addr & 0xffffe000) == s->script_ram_base) { |
372 | 7d8406be | pbrook | return s->script_ram[(addr & 0x1fff) >> 2]; |
373 | 7d8406be | pbrook | } |
374 | 7d8406be | pbrook | cpu_physical_memory_read(addr, (uint8_t *)&buf, 4);
|
375 | 7d8406be | pbrook | return cpu_to_le32(buf);
|
376 | 7d8406be | pbrook | } |
377 | 7d8406be | pbrook | |
378 | 7d8406be | pbrook | static void lsi_stop_script(LSIState *s) |
379 | 7d8406be | pbrook | { |
380 | 7d8406be | pbrook | s->istat1 &= ~LSI_ISTAT1_SRUN; |
381 | 7d8406be | pbrook | } |
382 | 7d8406be | pbrook | |
383 | 7d8406be | pbrook | static void lsi_update_irq(LSIState *s) |
384 | 7d8406be | pbrook | { |
385 | 7d8406be | pbrook | int level;
|
386 | 7d8406be | pbrook | static int last_level; |
387 | 7d8406be | pbrook | |
388 | 7d8406be | pbrook | /* It's unclear whether the DIP/SIP bits should be cleared when the
|
389 | 7d8406be | pbrook | Interrupt Status Registers are cleared or when istat0 is read.
|
390 | 7d8406be | pbrook | We currently do the formwer, which seems to work. */
|
391 | 7d8406be | pbrook | level = 0;
|
392 | 7d8406be | pbrook | if (s->dstat) {
|
393 | 7d8406be | pbrook | if (s->dstat & s->dien)
|
394 | 7d8406be | pbrook | level = 1;
|
395 | 7d8406be | pbrook | s->istat0 |= LSI_ISTAT0_DIP; |
396 | 7d8406be | pbrook | } else {
|
397 | 7d8406be | pbrook | s->istat0 &= ~LSI_ISTAT0_DIP; |
398 | 7d8406be | pbrook | } |
399 | 7d8406be | pbrook | |
400 | 7d8406be | pbrook | if (s->sist0 || s->sist1) {
|
401 | 7d8406be | pbrook | if ((s->sist0 & s->sien0) || (s->sist1 & s->sien1))
|
402 | 7d8406be | pbrook | level = 1;
|
403 | 7d8406be | pbrook | s->istat0 |= LSI_ISTAT0_SIP; |
404 | 7d8406be | pbrook | } else {
|
405 | 7d8406be | pbrook | s->istat0 &= ~LSI_ISTAT0_SIP; |
406 | 7d8406be | pbrook | } |
407 | 7d8406be | pbrook | if (s->istat0 & LSI_ISTAT0_INTF)
|
408 | 7d8406be | pbrook | level = 1;
|
409 | 7d8406be | pbrook | |
410 | 7d8406be | pbrook | if (level != last_level) {
|
411 | 7d8406be | pbrook | DPRINTF("Update IRQ level %d dstat %02x sist %02x%02x\n",
|
412 | 7d8406be | pbrook | level, s->dstat, s->sist1, s->sist0); |
413 | 7d8406be | pbrook | last_level = level; |
414 | 7d8406be | pbrook | } |
415 | f305261f | Juan Quintela | qemu_set_irq(s->dev.irq[0], level);
|
416 | 7d8406be | pbrook | } |
417 | 7d8406be | pbrook | |
418 | 7d8406be | pbrook | /* Stop SCRIPTS execution and raise a SCSI interrupt. */
|
419 | 7d8406be | pbrook | static void lsi_script_scsi_interrupt(LSIState *s, int stat0, int stat1) |
420 | 7d8406be | pbrook | { |
421 | 7d8406be | pbrook | uint32_t mask0; |
422 | 7d8406be | pbrook | uint32_t mask1; |
423 | 7d8406be | pbrook | |
424 | 7d8406be | pbrook | DPRINTF("SCSI Interrupt 0x%02x%02x prev 0x%02x%02x\n",
|
425 | 7d8406be | pbrook | stat1, stat0, s->sist1, s->sist0); |
426 | 7d8406be | pbrook | s->sist0 |= stat0; |
427 | 7d8406be | pbrook | s->sist1 |= stat1; |
428 | 7d8406be | pbrook | /* Stop processor on fatal or unmasked interrupt. As a special hack
|
429 | 7d8406be | pbrook | we don't stop processing when raising STO. Instead continue
|
430 | 7d8406be | pbrook | execution and stop at the next insn that accesses the SCSI bus. */
|
431 | 7d8406be | pbrook | mask0 = s->sien0 | ~(LSI_SIST0_CMP | LSI_SIST0_SEL | LSI_SIST0_RSL); |
432 | 7d8406be | pbrook | mask1 = s->sien1 | ~(LSI_SIST1_GEN | LSI_SIST1_HTH); |
433 | 7d8406be | pbrook | mask1 &= ~LSI_SIST1_STO; |
434 | 7d8406be | pbrook | if (s->sist0 & mask0 || s->sist1 & mask1) {
|
435 | 7d8406be | pbrook | lsi_stop_script(s); |
436 | 7d8406be | pbrook | } |
437 | 7d8406be | pbrook | lsi_update_irq(s); |
438 | 7d8406be | pbrook | } |
439 | 7d8406be | pbrook | |
440 | 7d8406be | pbrook | /* Stop SCRIPTS execution and raise a DMA interrupt. */
|
441 | 7d8406be | pbrook | static void lsi_script_dma_interrupt(LSIState *s, int stat) |
442 | 7d8406be | pbrook | { |
443 | 7d8406be | pbrook | DPRINTF("DMA Interrupt 0x%x prev 0x%x\n", stat, s->dstat);
|
444 | 7d8406be | pbrook | s->dstat |= stat; |
445 | 7d8406be | pbrook | lsi_update_irq(s); |
446 | 7d8406be | pbrook | lsi_stop_script(s); |
447 | 7d8406be | pbrook | } |
448 | 7d8406be | pbrook | |
449 | 7d8406be | pbrook | static inline void lsi_set_phase(LSIState *s, int phase) |
450 | 7d8406be | pbrook | { |
451 | 7d8406be | pbrook | s->sstat1 = (s->sstat1 & ~PHASE_MASK) | phase; |
452 | 7d8406be | pbrook | } |
453 | 7d8406be | pbrook | |
454 | 7d8406be | pbrook | static void lsi_bad_phase(LSIState *s, int out, int new_phase) |
455 | 7d8406be | pbrook | { |
456 | 7d8406be | pbrook | /* Trigger a phase mismatch. */
|
457 | 7d8406be | pbrook | if (s->ccntl0 & LSI_CCNTL0_ENPMJ) {
|
458 | 7d8406be | pbrook | if ((s->ccntl0 & LSI_CCNTL0_PMJCTL) || out) {
|
459 | 7d8406be | pbrook | s->dsp = s->pmjad1; |
460 | 7d8406be | pbrook | } else {
|
461 | 7d8406be | pbrook | s->dsp = s->pmjad2; |
462 | 7d8406be | pbrook | } |
463 | 7d8406be | pbrook | DPRINTF("Data phase mismatch jump to %08x\n", s->dsp);
|
464 | 7d8406be | pbrook | } else {
|
465 | 7d8406be | pbrook | DPRINTF("Phase mismatch interrupt\n");
|
466 | 7d8406be | pbrook | lsi_script_scsi_interrupt(s, LSI_SIST0_MA, 0);
|
467 | 7d8406be | pbrook | lsi_stop_script(s); |
468 | 7d8406be | pbrook | } |
469 | 7d8406be | pbrook | lsi_set_phase(s, new_phase); |
470 | 7d8406be | pbrook | } |
471 | 7d8406be | pbrook | |
472 | a917d384 | pbrook | |
473 | a917d384 | pbrook | /* Resume SCRIPTS execution after a DMA operation. */
|
474 | a917d384 | pbrook | static void lsi_resume_script(LSIState *s) |
475 | a917d384 | pbrook | { |
476 | a917d384 | pbrook | if (s->waiting != 2) { |
477 | a917d384 | pbrook | s->waiting = 0;
|
478 | a917d384 | pbrook | lsi_execute_script(s); |
479 | a917d384 | pbrook | } else {
|
480 | a917d384 | pbrook | s->waiting = 0;
|
481 | a917d384 | pbrook | } |
482 | a917d384 | pbrook | } |
483 | a917d384 | pbrook | |
484 | 4d611c9a | pbrook | /* Initiate a SCSI layer data transfer. */
|
485 | 7d8406be | pbrook | static void lsi_do_dma(LSIState *s, int out) |
486 | 7d8406be | pbrook | { |
487 | 7d8406be | pbrook | uint32_t count; |
488 | c227f099 | Anthony Liguori | target_phys_addr_t addr; |
489 | 7d8406be | pbrook | |
490 | a917d384 | pbrook | if (!s->current_dma_len) {
|
491 | a917d384 | pbrook | /* Wait until data is available. */
|
492 | a917d384 | pbrook | DPRINTF("DMA no data available\n");
|
493 | a917d384 | pbrook | return;
|
494 | 7d8406be | pbrook | } |
495 | 7d8406be | pbrook | |
496 | a917d384 | pbrook | count = s->dbc; |
497 | a917d384 | pbrook | if (count > s->current_dma_len)
|
498 | a917d384 | pbrook | count = s->current_dma_len; |
499 | a917d384 | pbrook | |
500 | a917d384 | pbrook | addr = s->dnad; |
501 | dd8edf01 | aliguori | /* both 40 and Table Indirect 64-bit DMAs store upper bits in dnad64 */
|
502 | dd8edf01 | aliguori | if (lsi_dma_40bit(s) || lsi_dma_ti64bit(s))
|
503 | b25cf589 | aliguori | addr |= ((uint64_t)s->dnad64 << 32);
|
504 | dd8edf01 | aliguori | else if (s->dbms) |
505 | dd8edf01 | aliguori | addr |= ((uint64_t)s->dbms << 32);
|
506 | b25cf589 | aliguori | else if (s->sbms) |
507 | b25cf589 | aliguori | addr |= ((uint64_t)s->sbms << 32);
|
508 | b25cf589 | aliguori | |
509 | 3adae656 | aliguori | DPRINTF("DMA addr=0x" TARGET_FMT_plx " len=%d\n", addr, count); |
510 | 7d8406be | pbrook | s->csbc += count; |
511 | a917d384 | pbrook | s->dnad += count; |
512 | a917d384 | pbrook | s->dbc -= count; |
513 | a917d384 | pbrook | |
514 | a917d384 | pbrook | if (s->dma_buf == NULL) { |
515 | d52affa7 | Gerd Hoffmann | s->dma_buf = s->current_dev->info->get_buf(s->current_dev, |
516 | d52affa7 | Gerd Hoffmann | s->current_tag); |
517 | a917d384 | pbrook | } |
518 | 7d8406be | pbrook | |
519 | 7d8406be | pbrook | /* ??? Set SFBR to first data byte. */
|
520 | a917d384 | pbrook | if (out) {
|
521 | a917d384 | pbrook | cpu_physical_memory_read(addr, s->dma_buf, count); |
522 | a917d384 | pbrook | } else {
|
523 | a917d384 | pbrook | cpu_physical_memory_write(addr, s->dma_buf, count); |
524 | a917d384 | pbrook | } |
525 | a917d384 | pbrook | s->current_dma_len -= count; |
526 | a917d384 | pbrook | if (s->current_dma_len == 0) { |
527 | a917d384 | pbrook | s->dma_buf = NULL;
|
528 | a917d384 | pbrook | if (out) {
|
529 | a917d384 | pbrook | /* Write the data. */
|
530 | d52affa7 | Gerd Hoffmann | s->current_dev->info->write_data(s->current_dev, s->current_tag); |
531 | a917d384 | pbrook | } else {
|
532 | a917d384 | pbrook | /* Request any remaining data. */
|
533 | d52affa7 | Gerd Hoffmann | s->current_dev->info->read_data(s->current_dev, s->current_tag); |
534 | a917d384 | pbrook | } |
535 | a917d384 | pbrook | } else {
|
536 | a917d384 | pbrook | s->dma_buf += count; |
537 | a917d384 | pbrook | lsi_resume_script(s); |
538 | a917d384 | pbrook | } |
539 | a917d384 | pbrook | } |
540 | a917d384 | pbrook | |
541 | a917d384 | pbrook | |
542 | a917d384 | pbrook | /* Add a command to the queue. */
|
543 | a917d384 | pbrook | static void lsi_queue_command(LSIState *s) |
544 | a917d384 | pbrook | { |
545 | a917d384 | pbrook | lsi_queue *p; |
546 | a917d384 | pbrook | |
547 | a917d384 | pbrook | DPRINTF("Queueing tag=0x%x\n", s->current_tag);
|
548 | a917d384 | pbrook | if (s->queue_len == s->active_commands) {
|
549 | a917d384 | pbrook | s->queue_len++; |
550 | 2137b4cc | ths | s->queue = qemu_realloc(s->queue, s->queue_len * sizeof(lsi_queue));
|
551 | a917d384 | pbrook | } |
552 | a917d384 | pbrook | p = &s->queue[s->active_commands++]; |
553 | a917d384 | pbrook | p->tag = s->current_tag; |
554 | a917d384 | pbrook | p->pending = 0;
|
555 | a917d384 | pbrook | p->out = (s->sstat1 & PHASE_MASK) == PHASE_DO; |
556 | a917d384 | pbrook | } |
557 | a917d384 | pbrook | |
558 | a917d384 | pbrook | /* Queue a byte for a MSG IN phase. */
|
559 | a917d384 | pbrook | static void lsi_add_msg_byte(LSIState *s, uint8_t data) |
560 | a917d384 | pbrook | { |
561 | a917d384 | pbrook | if (s->msg_len >= LSI_MAX_MSGIN_LEN) {
|
562 | a917d384 | pbrook | BADF("MSG IN data too long\n");
|
563 | 4d611c9a | pbrook | } else {
|
564 | a917d384 | pbrook | DPRINTF("MSG IN 0x%02x\n", data);
|
565 | a917d384 | pbrook | s->msg[s->msg_len++] = data; |
566 | 7d8406be | pbrook | } |
567 | a917d384 | pbrook | } |
568 | a917d384 | pbrook | |
569 | a917d384 | pbrook | /* Perform reselection to continue a command. */
|
570 | a917d384 | pbrook | static void lsi_reselect(LSIState *s, uint32_t tag) |
571 | a917d384 | pbrook | { |
572 | a917d384 | pbrook | lsi_queue *p; |
573 | a917d384 | pbrook | int n;
|
574 | a917d384 | pbrook | int id;
|
575 | a917d384 | pbrook | |
576 | a917d384 | pbrook | p = NULL;
|
577 | a917d384 | pbrook | for (n = 0; n < s->active_commands; n++) { |
578 | a917d384 | pbrook | p = &s->queue[n]; |
579 | a917d384 | pbrook | if (p->tag == tag)
|
580 | a917d384 | pbrook | break;
|
581 | a917d384 | pbrook | } |
582 | a917d384 | pbrook | if (n == s->active_commands) {
|
583 | a917d384 | pbrook | BADF("Reselected non-existant command tag=0x%x\n", tag);
|
584 | a917d384 | pbrook | return;
|
585 | a917d384 | pbrook | } |
586 | a917d384 | pbrook | id = (tag >> 8) & 0xf; |
587 | a917d384 | pbrook | s->ssid = id | 0x80;
|
588 | cc9f28bc | Laszlo Ast | /* LSI53C700 Family Compatibility, see LSI53C895A 4-73 */
|
589 | cc9f28bc | Laszlo Ast | if (!s->dcntl & LSI_DCNTL_COM) {
|
590 | cc9f28bc | Laszlo Ast | s->sfbr = 1 << (id & 0x7); |
591 | cc9f28bc | Laszlo Ast | } |
592 | a917d384 | pbrook | DPRINTF("Reselected target %d\n", id);
|
593 | ca9c39fa | Gerd Hoffmann | s->current_dev = s->bus.devs[id]; |
594 | a917d384 | pbrook | s->current_tag = tag; |
595 | a917d384 | pbrook | s->scntl1 |= LSI_SCNTL1_CON; |
596 | a917d384 | pbrook | lsi_set_phase(s, PHASE_MI); |
597 | a917d384 | pbrook | s->msg_action = p->out ? 2 : 3; |
598 | a917d384 | pbrook | s->current_dma_len = p->pending; |
599 | a917d384 | pbrook | s->dma_buf = NULL;
|
600 | a917d384 | pbrook | lsi_add_msg_byte(s, 0x80);
|
601 | a917d384 | pbrook | if (s->current_tag & LSI_TAG_VALID) {
|
602 | a917d384 | pbrook | lsi_add_msg_byte(s, 0x20);
|
603 | a917d384 | pbrook | lsi_add_msg_byte(s, tag & 0xff);
|
604 | a917d384 | pbrook | } |
605 | a917d384 | pbrook | |
606 | a917d384 | pbrook | s->active_commands--; |
607 | a917d384 | pbrook | if (n != s->active_commands) {
|
608 | a917d384 | pbrook | s->queue[n] = s->queue[s->active_commands]; |
609 | a917d384 | pbrook | } |
610 | a917d384 | pbrook | } |
611 | a917d384 | pbrook | |
612 | a917d384 | pbrook | /* Record that data is available for a queued command. Returns zero if
|
613 | a917d384 | pbrook | the device was reselected, nonzero if the IO is deferred. */
|
614 | a917d384 | pbrook | static int lsi_queue_tag(LSIState *s, uint32_t tag, uint32_t arg) |
615 | a917d384 | pbrook | { |
616 | a917d384 | pbrook | lsi_queue *p; |
617 | a917d384 | pbrook | int i;
|
618 | a917d384 | pbrook | for (i = 0; i < s->active_commands; i++) { |
619 | a917d384 | pbrook | p = &s->queue[i]; |
620 | a917d384 | pbrook | if (p->tag == tag) {
|
621 | a917d384 | pbrook | if (p->pending) {
|
622 | a917d384 | pbrook | BADF("Multiple IO pending for tag %d\n", tag);
|
623 | a917d384 | pbrook | } |
624 | a917d384 | pbrook | p->pending = arg; |
625 | a917d384 | pbrook | if (s->waiting == 1) { |
626 | a917d384 | pbrook | /* Reselect device. */
|
627 | a917d384 | pbrook | lsi_reselect(s, tag); |
628 | a917d384 | pbrook | return 0; |
629 | a917d384 | pbrook | } else {
|
630 | a917d384 | pbrook | DPRINTF("Queueing IO tag=0x%x\n", tag);
|
631 | a917d384 | pbrook | p->pending = arg; |
632 | a917d384 | pbrook | return 1; |
633 | a917d384 | pbrook | } |
634 | a917d384 | pbrook | } |
635 | a917d384 | pbrook | } |
636 | a917d384 | pbrook | BADF("IO with unknown tag %d\n", tag);
|
637 | a917d384 | pbrook | return 1; |
638 | 7d8406be | pbrook | } |
639 | 7d8406be | pbrook | |
640 | 4d611c9a | pbrook | /* Callback to indicate that the SCSI layer has completed a transfer. */
|
641 | d52affa7 | Gerd Hoffmann | static void lsi_command_complete(SCSIBus *bus, int reason, uint32_t tag, |
642 | a917d384 | pbrook | uint32_t arg) |
643 | 4d611c9a | pbrook | { |
644 | d52affa7 | Gerd Hoffmann | LSIState *s = DO_UPCAST(LSIState, dev.qdev, bus->qbus.parent); |
645 | 4d611c9a | pbrook | int out;
|
646 | 4d611c9a | pbrook | |
647 | a917d384 | pbrook | out = (s->sstat1 & PHASE_MASK) == PHASE_DO; |
648 | 4d611c9a | pbrook | if (reason == SCSI_REASON_DONE) {
|
649 | a917d384 | pbrook | DPRINTF("Command complete sense=%d\n", (int)arg); |
650 | a917d384 | pbrook | s->sense = arg; |
651 | 8ccc2ace | ths | s->command_complete = 2;
|
652 | a917d384 | pbrook | if (s->waiting && s->dbc != 0) { |
653 | a917d384 | pbrook | /* Raise phase mismatch for short transfers. */
|
654 | a917d384 | pbrook | lsi_bad_phase(s, out, PHASE_ST); |
655 | a917d384 | pbrook | } else {
|
656 | a917d384 | pbrook | lsi_set_phase(s, PHASE_ST); |
657 | a917d384 | pbrook | } |
658 | a917d384 | pbrook | lsi_resume_script(s); |
659 | a917d384 | pbrook | return;
|
660 | 4d611c9a | pbrook | } |
661 | 4d611c9a | pbrook | |
662 | a917d384 | pbrook | if (s->waiting == 1 || tag != s->current_tag) { |
663 | a917d384 | pbrook | if (lsi_queue_tag(s, tag, arg))
|
664 | a917d384 | pbrook | return;
|
665 | a917d384 | pbrook | } |
666 | a917d384 | pbrook | DPRINTF("Data ready tag=0x%x len=%d\n", tag, arg);
|
667 | a917d384 | pbrook | s->current_dma_len = arg; |
668 | 8ccc2ace | ths | s->command_complete = 1;
|
669 | a917d384 | pbrook | if (!s->waiting)
|
670 | a917d384 | pbrook | return;
|
671 | a917d384 | pbrook | if (s->waiting == 1 || s->dbc == 0) { |
672 | a917d384 | pbrook | lsi_resume_script(s); |
673 | a917d384 | pbrook | } else {
|
674 | 4d611c9a | pbrook | lsi_do_dma(s, out); |
675 | 4d611c9a | pbrook | } |
676 | 4d611c9a | pbrook | } |
677 | 7d8406be | pbrook | |
678 | 7d8406be | pbrook | static void lsi_do_command(LSIState *s) |
679 | 7d8406be | pbrook | { |
680 | 7d8406be | pbrook | uint8_t buf[16];
|
681 | 7d8406be | pbrook | int n;
|
682 | 7d8406be | pbrook | |
683 | 7d8406be | pbrook | DPRINTF("Send command len=%d\n", s->dbc);
|
684 | 7d8406be | pbrook | if (s->dbc > 16) |
685 | 7d8406be | pbrook | s->dbc = 16;
|
686 | 7d8406be | pbrook | cpu_physical_memory_read(s->dnad, buf, s->dbc); |
687 | 7d8406be | pbrook | s->sfbr = buf[0];
|
688 | 8ccc2ace | ths | s->command_complete = 0;
|
689 | d52affa7 | Gerd Hoffmann | n = s->current_dev->info->send_command(s->current_dev, s->current_tag, buf, |
690 | d52affa7 | Gerd Hoffmann | s->current_lun); |
691 | 7d8406be | pbrook | if (n > 0) { |
692 | 7d8406be | pbrook | lsi_set_phase(s, PHASE_DI); |
693 | d52affa7 | Gerd Hoffmann | s->current_dev->info->read_data(s->current_dev, s->current_tag); |
694 | 7d8406be | pbrook | } else if (n < 0) { |
695 | 7d8406be | pbrook | lsi_set_phase(s, PHASE_DO); |
696 | d52affa7 | Gerd Hoffmann | s->current_dev->info->write_data(s->current_dev, s->current_tag); |
697 | a917d384 | pbrook | } |
698 | 8ccc2ace | ths | |
699 | 8ccc2ace | ths | if (!s->command_complete) {
|
700 | 8ccc2ace | ths | if (n) {
|
701 | 8ccc2ace | ths | /* Command did not complete immediately so disconnect. */
|
702 | 8ccc2ace | ths | lsi_add_msg_byte(s, 2); /* SAVE DATA POINTER */ |
703 | 8ccc2ace | ths | lsi_add_msg_byte(s, 4); /* DISCONNECT */ |
704 | 8ccc2ace | ths | /* wait data */
|
705 | 8ccc2ace | ths | lsi_set_phase(s, PHASE_MI); |
706 | 8ccc2ace | ths | s->msg_action = 1;
|
707 | 8ccc2ace | ths | lsi_queue_command(s); |
708 | 8ccc2ace | ths | } else {
|
709 | 8ccc2ace | ths | /* wait command complete */
|
710 | 8ccc2ace | ths | lsi_set_phase(s, PHASE_DI); |
711 | 8ccc2ace | ths | } |
712 | 7d8406be | pbrook | } |
713 | 7d8406be | pbrook | } |
714 | 7d8406be | pbrook | |
715 | 7d8406be | pbrook | static void lsi_do_status(LSIState *s) |
716 | 7d8406be | pbrook | { |
717 | a917d384 | pbrook | uint8_t sense; |
718 | 7d8406be | pbrook | DPRINTF("Get status len=%d sense=%d\n", s->dbc, s->sense);
|
719 | 7d8406be | pbrook | if (s->dbc != 1) |
720 | 7d8406be | pbrook | BADF("Bad Status move\n");
|
721 | 7d8406be | pbrook | s->dbc = 1;
|
722 | a917d384 | pbrook | sense = s->sense; |
723 | a917d384 | pbrook | s->sfbr = sense; |
724 | a917d384 | pbrook | cpu_physical_memory_write(s->dnad, &sense, 1);
|
725 | 7d8406be | pbrook | lsi_set_phase(s, PHASE_MI); |
726 | a917d384 | pbrook | s->msg_action = 1;
|
727 | a917d384 | pbrook | lsi_add_msg_byte(s, 0); /* COMMAND COMPLETE */ |
728 | 7d8406be | pbrook | } |
729 | 7d8406be | pbrook | |
730 | 7d8406be | pbrook | static void lsi_disconnect(LSIState *s) |
731 | 7d8406be | pbrook | { |
732 | 7d8406be | pbrook | s->scntl1 &= ~LSI_SCNTL1_CON; |
733 | 7d8406be | pbrook | s->sstat1 &= ~PHASE_MASK; |
734 | 7d8406be | pbrook | } |
735 | 7d8406be | pbrook | |
736 | 7d8406be | pbrook | static void lsi_do_msgin(LSIState *s) |
737 | 7d8406be | pbrook | { |
738 | a917d384 | pbrook | int len;
|
739 | a917d384 | pbrook | DPRINTF("Message in len=%d/%d\n", s->dbc, s->msg_len);
|
740 | a917d384 | pbrook | s->sfbr = s->msg[0];
|
741 | a917d384 | pbrook | len = s->msg_len; |
742 | a917d384 | pbrook | if (len > s->dbc)
|
743 | a917d384 | pbrook | len = s->dbc; |
744 | a917d384 | pbrook | cpu_physical_memory_write(s->dnad, s->msg, len); |
745 | a917d384 | pbrook | /* Linux drivers rely on the last byte being in the SIDL. */
|
746 | a917d384 | pbrook | s->sidl = s->msg[len - 1];
|
747 | a917d384 | pbrook | s->msg_len -= len; |
748 | a917d384 | pbrook | if (s->msg_len) {
|
749 | a917d384 | pbrook | memmove(s->msg, s->msg + len, s->msg_len); |
750 | 7d8406be | pbrook | } else {
|
751 | 7d8406be | pbrook | /* ??? Check if ATN (not yet implemented) is asserted and maybe
|
752 | 7d8406be | pbrook | switch to PHASE_MO. */
|
753 | a917d384 | pbrook | switch (s->msg_action) {
|
754 | a917d384 | pbrook | case 0: |
755 | a917d384 | pbrook | lsi_set_phase(s, PHASE_CMD); |
756 | a917d384 | pbrook | break;
|
757 | a917d384 | pbrook | case 1: |
758 | a917d384 | pbrook | lsi_disconnect(s); |
759 | a917d384 | pbrook | break;
|
760 | a917d384 | pbrook | case 2: |
761 | a917d384 | pbrook | lsi_set_phase(s, PHASE_DO); |
762 | a917d384 | pbrook | break;
|
763 | a917d384 | pbrook | case 3: |
764 | a917d384 | pbrook | lsi_set_phase(s, PHASE_DI); |
765 | a917d384 | pbrook | break;
|
766 | a917d384 | pbrook | default:
|
767 | a917d384 | pbrook | abort(); |
768 | a917d384 | pbrook | } |
769 | 7d8406be | pbrook | } |
770 | 7d8406be | pbrook | } |
771 | 7d8406be | pbrook | |
772 | a917d384 | pbrook | /* Read the next byte during a MSGOUT phase. */
|
773 | a917d384 | pbrook | static uint8_t lsi_get_msgbyte(LSIState *s)
|
774 | a917d384 | pbrook | { |
775 | a917d384 | pbrook | uint8_t data; |
776 | a917d384 | pbrook | cpu_physical_memory_read(s->dnad, &data, 1);
|
777 | a917d384 | pbrook | s->dnad++; |
778 | a917d384 | pbrook | s->dbc--; |
779 | a917d384 | pbrook | return data;
|
780 | a917d384 | pbrook | } |
781 | a917d384 | pbrook | |
782 | 7d8406be | pbrook | static void lsi_do_msgout(LSIState *s) |
783 | 7d8406be | pbrook | { |
784 | 7d8406be | pbrook | uint8_t msg; |
785 | a917d384 | pbrook | int len;
|
786 | 7d8406be | pbrook | |
787 | 7d8406be | pbrook | DPRINTF("MSG out len=%d\n", s->dbc);
|
788 | a917d384 | pbrook | while (s->dbc) {
|
789 | a917d384 | pbrook | msg = lsi_get_msgbyte(s); |
790 | a917d384 | pbrook | s->sfbr = msg; |
791 | a917d384 | pbrook | |
792 | a917d384 | pbrook | switch (msg) {
|
793 | a917d384 | pbrook | case 0x00: |
794 | a917d384 | pbrook | DPRINTF("MSG: Disconnect\n");
|
795 | a917d384 | pbrook | lsi_disconnect(s); |
796 | a917d384 | pbrook | break;
|
797 | a917d384 | pbrook | case 0x08: |
798 | a917d384 | pbrook | DPRINTF("MSG: No Operation\n");
|
799 | a917d384 | pbrook | lsi_set_phase(s, PHASE_CMD); |
800 | a917d384 | pbrook | break;
|
801 | a917d384 | pbrook | case 0x01: |
802 | a917d384 | pbrook | len = lsi_get_msgbyte(s); |
803 | a917d384 | pbrook | msg = lsi_get_msgbyte(s); |
804 | a917d384 | pbrook | DPRINTF("Extended message 0x%x (len %d)\n", msg, len);
|
805 | a917d384 | pbrook | switch (msg) {
|
806 | a917d384 | pbrook | case 1: |
807 | a917d384 | pbrook | DPRINTF("SDTR (ignored)\n");
|
808 | a917d384 | pbrook | s->dbc -= 2;
|
809 | a917d384 | pbrook | break;
|
810 | a917d384 | pbrook | case 3: |
811 | a917d384 | pbrook | DPRINTF("WDTR (ignored)\n");
|
812 | a917d384 | pbrook | s->dbc -= 1;
|
813 | a917d384 | pbrook | break;
|
814 | a917d384 | pbrook | default:
|
815 | a917d384 | pbrook | goto bad;
|
816 | a917d384 | pbrook | } |
817 | a917d384 | pbrook | break;
|
818 | a917d384 | pbrook | case 0x20: /* SIMPLE queue */ |
819 | a917d384 | pbrook | s->current_tag |= lsi_get_msgbyte(s) | LSI_TAG_VALID; |
820 | a917d384 | pbrook | DPRINTF("SIMPLE queue tag=0x%x\n", s->current_tag & 0xff); |
821 | a917d384 | pbrook | break;
|
822 | a917d384 | pbrook | case 0x21: /* HEAD of queue */ |
823 | a917d384 | pbrook | BADF("HEAD queue not implemented\n");
|
824 | a917d384 | pbrook | s->current_tag |= lsi_get_msgbyte(s) | LSI_TAG_VALID; |
825 | a917d384 | pbrook | break;
|
826 | a917d384 | pbrook | case 0x22: /* ORDERED queue */ |
827 | a917d384 | pbrook | BADF("ORDERED queue not implemented\n");
|
828 | a917d384 | pbrook | s->current_tag |= lsi_get_msgbyte(s) | LSI_TAG_VALID; |
829 | a917d384 | pbrook | break;
|
830 | a917d384 | pbrook | default:
|
831 | a917d384 | pbrook | if ((msg & 0x80) == 0) { |
832 | a917d384 | pbrook | goto bad;
|
833 | a917d384 | pbrook | } |
834 | a917d384 | pbrook | s->current_lun = msg & 7;
|
835 | a917d384 | pbrook | DPRINTF("Select LUN %d\n", s->current_lun);
|
836 | a917d384 | pbrook | lsi_set_phase(s, PHASE_CMD); |
837 | a917d384 | pbrook | break;
|
838 | a917d384 | pbrook | } |
839 | 7d8406be | pbrook | } |
840 | a917d384 | pbrook | return;
|
841 | a917d384 | pbrook | bad:
|
842 | a917d384 | pbrook | BADF("Unimplemented message 0x%02x\n", msg);
|
843 | a917d384 | pbrook | lsi_set_phase(s, PHASE_MI); |
844 | a917d384 | pbrook | lsi_add_msg_byte(s, 7); /* MESSAGE REJECT */ |
845 | a917d384 | pbrook | s->msg_action = 0;
|
846 | 7d8406be | pbrook | } |
847 | 7d8406be | pbrook | |
848 | 7d8406be | pbrook | /* Sign extend a 24-bit value. */
|
849 | 7d8406be | pbrook | static inline int32_t sxt24(int32_t n) |
850 | 7d8406be | pbrook | { |
851 | 7d8406be | pbrook | return (n << 8) >> 8; |
852 | 7d8406be | pbrook | } |
853 | 7d8406be | pbrook | |
854 | e20a8dff | Blue Swirl | #define LSI_BUF_SIZE 4096 |
855 | 7d8406be | pbrook | static void lsi_memcpy(LSIState *s, uint32_t dest, uint32_t src, int count) |
856 | 7d8406be | pbrook | { |
857 | 7d8406be | pbrook | int n;
|
858 | e20a8dff | Blue Swirl | uint8_t buf[LSI_BUF_SIZE]; |
859 | 7d8406be | pbrook | |
860 | 7d8406be | pbrook | DPRINTF("memcpy dest 0x%08x src 0x%08x count %d\n", dest, src, count);
|
861 | 7d8406be | pbrook | while (count) {
|
862 | e20a8dff | Blue Swirl | n = (count > LSI_BUF_SIZE) ? LSI_BUF_SIZE : count; |
863 | 7d8406be | pbrook | cpu_physical_memory_read(src, buf, n); |
864 | 7d8406be | pbrook | cpu_physical_memory_write(dest, buf, n); |
865 | 7d8406be | pbrook | src += n; |
866 | 7d8406be | pbrook | dest += n; |
867 | 7d8406be | pbrook | count -= n; |
868 | 7d8406be | pbrook | } |
869 | 7d8406be | pbrook | } |
870 | 7d8406be | pbrook | |
871 | a917d384 | pbrook | static void lsi_wait_reselect(LSIState *s) |
872 | a917d384 | pbrook | { |
873 | a917d384 | pbrook | int i;
|
874 | a917d384 | pbrook | DPRINTF("Wait Reselect\n");
|
875 | a917d384 | pbrook | if (s->current_dma_len)
|
876 | a917d384 | pbrook | BADF("Reselect with pending DMA\n");
|
877 | a917d384 | pbrook | for (i = 0; i < s->active_commands; i++) { |
878 | a917d384 | pbrook | if (s->queue[i].pending) {
|
879 | a917d384 | pbrook | lsi_reselect(s, s->queue[i].tag); |
880 | a917d384 | pbrook | break;
|
881 | a917d384 | pbrook | } |
882 | a917d384 | pbrook | } |
883 | a917d384 | pbrook | if (s->current_dma_len == 0) { |
884 | a917d384 | pbrook | s->waiting = 1;
|
885 | a917d384 | pbrook | } |
886 | a917d384 | pbrook | } |
887 | a917d384 | pbrook | |
888 | 7d8406be | pbrook | static void lsi_execute_script(LSIState *s) |
889 | 7d8406be | pbrook | { |
890 | 7d8406be | pbrook | uint32_t insn; |
891 | b25cf589 | aliguori | uint32_t addr, addr_high; |
892 | 7d8406be | pbrook | int opcode;
|
893 | ee4d919f | aliguori | int insn_processed = 0; |
894 | 7d8406be | pbrook | |
895 | 7d8406be | pbrook | s->istat1 |= LSI_ISTAT1_SRUN; |
896 | 7d8406be | pbrook | again:
|
897 | ee4d919f | aliguori | insn_processed++; |
898 | 7d8406be | pbrook | insn = read_dword(s, s->dsp); |
899 | 02b373ad | balrog | if (!insn) {
|
900 | 02b373ad | balrog | /* If we receive an empty opcode increment the DSP by 4 bytes
|
901 | 02b373ad | balrog | instead of 8 and execute the next opcode at that location */
|
902 | 02b373ad | balrog | s->dsp += 4;
|
903 | 02b373ad | balrog | goto again;
|
904 | 02b373ad | balrog | } |
905 | 7d8406be | pbrook | addr = read_dword(s, s->dsp + 4);
|
906 | b25cf589 | aliguori | addr_high = 0;
|
907 | 7d8406be | pbrook | DPRINTF("SCRIPTS dsp=%08x opcode %08x arg %08x\n", s->dsp, insn, addr);
|
908 | 7d8406be | pbrook | s->dsps = addr; |
909 | 7d8406be | pbrook | s->dcmd = insn >> 24;
|
910 | 7d8406be | pbrook | s->dsp += 8;
|
911 | 7d8406be | pbrook | switch (insn >> 30) { |
912 | 7d8406be | pbrook | case 0: /* Block move. */ |
913 | 7d8406be | pbrook | if (s->sist1 & LSI_SIST1_STO) {
|
914 | 7d8406be | pbrook | DPRINTF("Delayed select timeout\n");
|
915 | 7d8406be | pbrook | lsi_stop_script(s); |
916 | 7d8406be | pbrook | break;
|
917 | 7d8406be | pbrook | } |
918 | 7d8406be | pbrook | s->dbc = insn & 0xffffff;
|
919 | 7d8406be | pbrook | s->rbc = s->dbc; |
920 | dd8edf01 | aliguori | /* ??? Set ESA. */
|
921 | dd8edf01 | aliguori | s->ia = s->dsp - 8;
|
922 | 7d8406be | pbrook | if (insn & (1 << 29)) { |
923 | 7d8406be | pbrook | /* Indirect addressing. */
|
924 | 7d8406be | pbrook | addr = read_dword(s, addr); |
925 | 7d8406be | pbrook | } else if (insn & (1 << 28)) { |
926 | 7d8406be | pbrook | uint32_t buf[2];
|
927 | 7d8406be | pbrook | int32_t offset; |
928 | 7d8406be | pbrook | /* Table indirect addressing. */
|
929 | dd8edf01 | aliguori | |
930 | dd8edf01 | aliguori | /* 32-bit Table indirect */
|
931 | 7d8406be | pbrook | offset = sxt24(addr); |
932 | 7d8406be | pbrook | cpu_physical_memory_read(s->dsa + offset, (uint8_t *)buf, 8);
|
933 | b25cf589 | aliguori | /* byte count is stored in bits 0:23 only */
|
934 | b25cf589 | aliguori | s->dbc = cpu_to_le32(buf[0]) & 0xffffff; |
935 | 7faa239c | ths | s->rbc = s->dbc; |
936 | 7d8406be | pbrook | addr = cpu_to_le32(buf[1]);
|
937 | b25cf589 | aliguori | |
938 | b25cf589 | aliguori | /* 40-bit DMA, upper addr bits [39:32] stored in first DWORD of
|
939 | b25cf589 | aliguori | * table, bits [31:24] */
|
940 | b25cf589 | aliguori | if (lsi_dma_40bit(s))
|
941 | b25cf589 | aliguori | addr_high = cpu_to_le32(buf[0]) >> 24; |
942 | dd8edf01 | aliguori | else if (lsi_dma_ti64bit(s)) { |
943 | dd8edf01 | aliguori | int selector = (cpu_to_le32(buf[0]) >> 24) & 0x1f; |
944 | dd8edf01 | aliguori | switch (selector) {
|
945 | dd8edf01 | aliguori | case 0 ... 0x0f: |
946 | dd8edf01 | aliguori | /* offset index into scratch registers since
|
947 | dd8edf01 | aliguori | * TI64 mode can use registers C to R */
|
948 | dd8edf01 | aliguori | addr_high = s->scratch[2 + selector];
|
949 | dd8edf01 | aliguori | break;
|
950 | dd8edf01 | aliguori | case 0x10: |
951 | dd8edf01 | aliguori | addr_high = s->mmrs; |
952 | dd8edf01 | aliguori | break;
|
953 | dd8edf01 | aliguori | case 0x11: |
954 | dd8edf01 | aliguori | addr_high = s->mmws; |
955 | dd8edf01 | aliguori | break;
|
956 | dd8edf01 | aliguori | case 0x12: |
957 | dd8edf01 | aliguori | addr_high = s->sfs; |
958 | dd8edf01 | aliguori | break;
|
959 | dd8edf01 | aliguori | case 0x13: |
960 | dd8edf01 | aliguori | addr_high = s->drs; |
961 | dd8edf01 | aliguori | break;
|
962 | dd8edf01 | aliguori | case 0x14: |
963 | dd8edf01 | aliguori | addr_high = s->sbms; |
964 | dd8edf01 | aliguori | break;
|
965 | dd8edf01 | aliguori | case 0x15: |
966 | dd8edf01 | aliguori | addr_high = s->dbms; |
967 | dd8edf01 | aliguori | break;
|
968 | dd8edf01 | aliguori | default:
|
969 | dd8edf01 | aliguori | BADF("Illegal selector specified (0x%x > 0x15)"
|
970 | dd8edf01 | aliguori | " for 64-bit DMA block move", selector);
|
971 | dd8edf01 | aliguori | break;
|
972 | dd8edf01 | aliguori | } |
973 | dd8edf01 | aliguori | } |
974 | dd8edf01 | aliguori | } else if (lsi_dma_64bit(s)) { |
975 | dd8edf01 | aliguori | /* fetch a 3rd dword if 64-bit direct move is enabled and
|
976 | dd8edf01 | aliguori | only if we're not doing table indirect or indirect addressing */
|
977 | dd8edf01 | aliguori | s->dbms = read_dword(s, s->dsp); |
978 | dd8edf01 | aliguori | s->dsp += 4;
|
979 | dd8edf01 | aliguori | s->ia = s->dsp - 12;
|
980 | 7d8406be | pbrook | } |
981 | 7d8406be | pbrook | if ((s->sstat1 & PHASE_MASK) != ((insn >> 24) & 7)) { |
982 | 7d8406be | pbrook | DPRINTF("Wrong phase got %d expected %d\n",
|
983 | 7d8406be | pbrook | s->sstat1 & PHASE_MASK, (insn >> 24) & 7); |
984 | 7d8406be | pbrook | lsi_script_scsi_interrupt(s, LSI_SIST0_MA, 0);
|
985 | 7d8406be | pbrook | break;
|
986 | 7d8406be | pbrook | } |
987 | 7d8406be | pbrook | s->dnad = addr; |
988 | b25cf589 | aliguori | s->dnad64 = addr_high; |
989 | 7d8406be | pbrook | switch (s->sstat1 & 0x7) { |
990 | 7d8406be | pbrook | case PHASE_DO:
|
991 | a917d384 | pbrook | s->waiting = 2;
|
992 | 7d8406be | pbrook | lsi_do_dma(s, 1);
|
993 | a917d384 | pbrook | if (s->waiting)
|
994 | a917d384 | pbrook | s->waiting = 3;
|
995 | 7d8406be | pbrook | break;
|
996 | 7d8406be | pbrook | case PHASE_DI:
|
997 | a917d384 | pbrook | s->waiting = 2;
|
998 | 7d8406be | pbrook | lsi_do_dma(s, 0);
|
999 | a917d384 | pbrook | if (s->waiting)
|
1000 | a917d384 | pbrook | s->waiting = 3;
|
1001 | 7d8406be | pbrook | break;
|
1002 | 7d8406be | pbrook | case PHASE_CMD:
|
1003 | 7d8406be | pbrook | lsi_do_command(s); |
1004 | 7d8406be | pbrook | break;
|
1005 | 7d8406be | pbrook | case PHASE_ST:
|
1006 | 7d8406be | pbrook | lsi_do_status(s); |
1007 | 7d8406be | pbrook | break;
|
1008 | 7d8406be | pbrook | case PHASE_MO:
|
1009 | 7d8406be | pbrook | lsi_do_msgout(s); |
1010 | 7d8406be | pbrook | break;
|
1011 | 7d8406be | pbrook | case PHASE_MI:
|
1012 | 7d8406be | pbrook | lsi_do_msgin(s); |
1013 | 7d8406be | pbrook | break;
|
1014 | 7d8406be | pbrook | default:
|
1015 | 7d8406be | pbrook | BADF("Unimplemented phase %d\n", s->sstat1 & PHASE_MASK);
|
1016 | 7d8406be | pbrook | exit(1);
|
1017 | 7d8406be | pbrook | } |
1018 | 7d8406be | pbrook | s->dfifo = s->dbc & 0xff;
|
1019 | 7d8406be | pbrook | s->ctest5 = (s->ctest5 & 0xfc) | ((s->dbc >> 8) & 3); |
1020 | 7d8406be | pbrook | s->sbc = s->dbc; |
1021 | 7d8406be | pbrook | s->rbc -= s->dbc; |
1022 | 7d8406be | pbrook | s->ua = addr + s->dbc; |
1023 | 7d8406be | pbrook | break;
|
1024 | 7d8406be | pbrook | |
1025 | 7d8406be | pbrook | case 1: /* IO or Read/Write instruction. */ |
1026 | 7d8406be | pbrook | opcode = (insn >> 27) & 7; |
1027 | 7d8406be | pbrook | if (opcode < 5) { |
1028 | 7d8406be | pbrook | uint32_t id; |
1029 | 7d8406be | pbrook | |
1030 | 7d8406be | pbrook | if (insn & (1 << 25)) { |
1031 | 7d8406be | pbrook | id = read_dword(s, s->dsa + sxt24(insn)); |
1032 | 7d8406be | pbrook | } else {
|
1033 | 7d8406be | pbrook | id = addr; |
1034 | 7d8406be | pbrook | } |
1035 | 7d8406be | pbrook | id = (id >> 16) & 0xf; |
1036 | 7d8406be | pbrook | if (insn & (1 << 26)) { |
1037 | 7d8406be | pbrook | addr = s->dsp + sxt24(addr); |
1038 | 7d8406be | pbrook | } |
1039 | 7d8406be | pbrook | s->dnad = addr; |
1040 | 7d8406be | pbrook | switch (opcode) {
|
1041 | 7d8406be | pbrook | case 0: /* Select */ |
1042 | a917d384 | pbrook | s->sdid = id; |
1043 | a917d384 | pbrook | if (s->current_dma_len && (s->ssid & 0xf) == id) { |
1044 | a917d384 | pbrook | DPRINTF("Already reselected by target %d\n", id);
|
1045 | a917d384 | pbrook | break;
|
1046 | a917d384 | pbrook | } |
1047 | 7d8406be | pbrook | s->sstat0 |= LSI_SSTAT0_WOA; |
1048 | 7d8406be | pbrook | s->scntl1 &= ~LSI_SCNTL1_IARB; |
1049 | ca9c39fa | Gerd Hoffmann | if (id >= LSI_MAX_DEVS || !s->bus.devs[id]) {
|
1050 | 7d8406be | pbrook | DPRINTF("Selected absent target %d\n", id);
|
1051 | 7d8406be | pbrook | lsi_script_scsi_interrupt(s, 0, LSI_SIST1_STO);
|
1052 | 7d8406be | pbrook | lsi_disconnect(s); |
1053 | 7d8406be | pbrook | break;
|
1054 | 7d8406be | pbrook | } |
1055 | 7d8406be | pbrook | DPRINTF("Selected target %d%s\n",
|
1056 | 7d8406be | pbrook | id, insn & (1 << 3) ? " ATN" : ""); |
1057 | 7d8406be | pbrook | /* ??? Linux drivers compain when this is set. Maybe
|
1058 | 7d8406be | pbrook | it only applies in low-level mode (unimplemented).
|
1059 | 7d8406be | pbrook | lsi_script_scsi_interrupt(s, LSI_SIST0_CMP, 0); */
|
1060 | ca9c39fa | Gerd Hoffmann | s->current_dev = s->bus.devs[id]; |
1061 | a917d384 | pbrook | s->current_tag = id << 8;
|
1062 | 7d8406be | pbrook | s->scntl1 |= LSI_SCNTL1_CON; |
1063 | 7d8406be | pbrook | if (insn & (1 << 3)) { |
1064 | 7d8406be | pbrook | s->socl |= LSI_SOCL_ATN; |
1065 | 7d8406be | pbrook | } |
1066 | 7d8406be | pbrook | lsi_set_phase(s, PHASE_MO); |
1067 | 7d8406be | pbrook | break;
|
1068 | 7d8406be | pbrook | case 1: /* Disconnect */ |
1069 | a15fdf86 | Laszlo Ast | DPRINTF("Wait Disconnect\n");
|
1070 | 7d8406be | pbrook | s->scntl1 &= ~LSI_SCNTL1_CON; |
1071 | 7d8406be | pbrook | break;
|
1072 | 7d8406be | pbrook | case 2: /* Wait Reselect */ |
1073 | a917d384 | pbrook | lsi_wait_reselect(s); |
1074 | 7d8406be | pbrook | break;
|
1075 | 7d8406be | pbrook | case 3: /* Set */ |
1076 | 7d8406be | pbrook | DPRINTF("Set%s%s%s%s\n",
|
1077 | 7d8406be | pbrook | insn & (1 << 3) ? " ATN" : "", |
1078 | 7d8406be | pbrook | insn & (1 << 6) ? " ACK" : "", |
1079 | 7d8406be | pbrook | insn & (1 << 9) ? " TM" : "", |
1080 | 7d8406be | pbrook | insn & (1 << 10) ? " CC" : ""); |
1081 | 7d8406be | pbrook | if (insn & (1 << 3)) { |
1082 | 7d8406be | pbrook | s->socl |= LSI_SOCL_ATN; |
1083 | 7d8406be | pbrook | lsi_set_phase(s, PHASE_MO); |
1084 | 7d8406be | pbrook | } |
1085 | 7d8406be | pbrook | if (insn & (1 << 9)) { |
1086 | 7d8406be | pbrook | BADF("Target mode not implemented\n");
|
1087 | 7d8406be | pbrook | exit(1);
|
1088 | 7d8406be | pbrook | } |
1089 | 7d8406be | pbrook | if (insn & (1 << 10)) |
1090 | 7d8406be | pbrook | s->carry = 1;
|
1091 | 7d8406be | pbrook | break;
|
1092 | 7d8406be | pbrook | case 4: /* Clear */ |
1093 | 7d8406be | pbrook | DPRINTF("Clear%s%s%s%s\n",
|
1094 | 7d8406be | pbrook | insn & (1 << 3) ? " ATN" : "", |
1095 | 7d8406be | pbrook | insn & (1 << 6) ? " ACK" : "", |
1096 | 7d8406be | pbrook | insn & (1 << 9) ? " TM" : "", |
1097 | 7d8406be | pbrook | insn & (1 << 10) ? " CC" : ""); |
1098 | 7d8406be | pbrook | if (insn & (1 << 3)) { |
1099 | 7d8406be | pbrook | s->socl &= ~LSI_SOCL_ATN; |
1100 | 7d8406be | pbrook | } |
1101 | 7d8406be | pbrook | if (insn & (1 << 10)) |
1102 | 7d8406be | pbrook | s->carry = 0;
|
1103 | 7d8406be | pbrook | break;
|
1104 | 7d8406be | pbrook | } |
1105 | 7d8406be | pbrook | } else {
|
1106 | 7d8406be | pbrook | uint8_t op0; |
1107 | 7d8406be | pbrook | uint8_t op1; |
1108 | 7d8406be | pbrook | uint8_t data8; |
1109 | 7d8406be | pbrook | int reg;
|
1110 | 7d8406be | pbrook | int operator;
|
1111 | 7d8406be | pbrook | #ifdef DEBUG_LSI
|
1112 | 7d8406be | pbrook | static const char *opcode_names[3] = |
1113 | 7d8406be | pbrook | {"Write", "Read", "Read-Modify-Write"}; |
1114 | 7d8406be | pbrook | static const char *operator_names[8] = |
1115 | 7d8406be | pbrook | {"MOV", "SHL", "OR", "XOR", "AND", "SHR", "ADD", "ADC"}; |
1116 | 7d8406be | pbrook | #endif
|
1117 | 7d8406be | pbrook | |
1118 | 7d8406be | pbrook | reg = ((insn >> 16) & 0x7f) | (insn & 0x80); |
1119 | 7d8406be | pbrook | data8 = (insn >> 8) & 0xff; |
1120 | 7d8406be | pbrook | opcode = (insn >> 27) & 7; |
1121 | 7d8406be | pbrook | operator = (insn >> 24) & 7; |
1122 | a917d384 | pbrook | DPRINTF("%s reg 0x%x %s data8=0x%02x sfbr=0x%02x%s\n",
|
1123 | 7d8406be | pbrook | opcode_names[opcode - 5], reg,
|
1124 | a917d384 | pbrook | operator_names[operator], data8, s->sfbr, |
1125 | 7d8406be | pbrook | (insn & (1 << 23)) ? " SFBR" : ""); |
1126 | 7d8406be | pbrook | op0 = op1 = 0;
|
1127 | 7d8406be | pbrook | switch (opcode) {
|
1128 | 7d8406be | pbrook | case 5: /* From SFBR */ |
1129 | 7d8406be | pbrook | op0 = s->sfbr; |
1130 | 7d8406be | pbrook | op1 = data8; |
1131 | 7d8406be | pbrook | break;
|
1132 | 7d8406be | pbrook | case 6: /* To SFBR */ |
1133 | 7d8406be | pbrook | if (operator)
|
1134 | 7d8406be | pbrook | op0 = lsi_reg_readb(s, reg); |
1135 | 7d8406be | pbrook | op1 = data8; |
1136 | 7d8406be | pbrook | break;
|
1137 | 7d8406be | pbrook | case 7: /* Read-modify-write */ |
1138 | 7d8406be | pbrook | if (operator)
|
1139 | 7d8406be | pbrook | op0 = lsi_reg_readb(s, reg); |
1140 | 7d8406be | pbrook | if (insn & (1 << 23)) { |
1141 | 7d8406be | pbrook | op1 = s->sfbr; |
1142 | 7d8406be | pbrook | } else {
|
1143 | 7d8406be | pbrook | op1 = data8; |
1144 | 7d8406be | pbrook | } |
1145 | 7d8406be | pbrook | break;
|
1146 | 7d8406be | pbrook | } |
1147 | 7d8406be | pbrook | |
1148 | 7d8406be | pbrook | switch (operator) {
|
1149 | 7d8406be | pbrook | case 0: /* move */ |
1150 | 7d8406be | pbrook | op0 = op1; |
1151 | 7d8406be | pbrook | break;
|
1152 | 7d8406be | pbrook | case 1: /* Shift left */ |
1153 | 7d8406be | pbrook | op1 = op0 >> 7;
|
1154 | 7d8406be | pbrook | op0 = (op0 << 1) | s->carry;
|
1155 | 7d8406be | pbrook | s->carry = op1; |
1156 | 7d8406be | pbrook | break;
|
1157 | 7d8406be | pbrook | case 2: /* OR */ |
1158 | 7d8406be | pbrook | op0 |= op1; |
1159 | 7d8406be | pbrook | break;
|
1160 | 7d8406be | pbrook | case 3: /* XOR */ |
1161 | dcfb9014 | ths | op0 ^= op1; |
1162 | 7d8406be | pbrook | break;
|
1163 | 7d8406be | pbrook | case 4: /* AND */ |
1164 | 7d8406be | pbrook | op0 &= op1; |
1165 | 7d8406be | pbrook | break;
|
1166 | 7d8406be | pbrook | case 5: /* SHR */ |
1167 | 7d8406be | pbrook | op1 = op0 & 1;
|
1168 | 7d8406be | pbrook | op0 = (op0 >> 1) | (s->carry << 7); |
1169 | 687fa640 | ths | s->carry = op1; |
1170 | 7d8406be | pbrook | break;
|
1171 | 7d8406be | pbrook | case 6: /* ADD */ |
1172 | 7d8406be | pbrook | op0 += op1; |
1173 | 7d8406be | pbrook | s->carry = op0 < op1; |
1174 | 7d8406be | pbrook | break;
|
1175 | 7d8406be | pbrook | case 7: /* ADC */ |
1176 | 7d8406be | pbrook | op0 += op1 + s->carry; |
1177 | 7d8406be | pbrook | if (s->carry)
|
1178 | 7d8406be | pbrook | s->carry = op0 <= op1; |
1179 | 7d8406be | pbrook | else
|
1180 | 7d8406be | pbrook | s->carry = op0 < op1; |
1181 | 7d8406be | pbrook | break;
|
1182 | 7d8406be | pbrook | } |
1183 | 7d8406be | pbrook | |
1184 | 7d8406be | pbrook | switch (opcode) {
|
1185 | 7d8406be | pbrook | case 5: /* From SFBR */ |
1186 | 7d8406be | pbrook | case 7: /* Read-modify-write */ |
1187 | 7d8406be | pbrook | lsi_reg_writeb(s, reg, op0); |
1188 | 7d8406be | pbrook | break;
|
1189 | 7d8406be | pbrook | case 6: /* To SFBR */ |
1190 | 7d8406be | pbrook | s->sfbr = op0; |
1191 | 7d8406be | pbrook | break;
|
1192 | 7d8406be | pbrook | } |
1193 | 7d8406be | pbrook | } |
1194 | 7d8406be | pbrook | break;
|
1195 | 7d8406be | pbrook | |
1196 | 7d8406be | pbrook | case 2: /* Transfer Control. */ |
1197 | 7d8406be | pbrook | { |
1198 | 7d8406be | pbrook | int cond;
|
1199 | 7d8406be | pbrook | int jmp;
|
1200 | 7d8406be | pbrook | |
1201 | 7d8406be | pbrook | if ((insn & 0x002e0000) == 0) { |
1202 | 7d8406be | pbrook | DPRINTF("NOP\n");
|
1203 | 7d8406be | pbrook | break;
|
1204 | 7d8406be | pbrook | } |
1205 | 7d8406be | pbrook | if (s->sist1 & LSI_SIST1_STO) {
|
1206 | 7d8406be | pbrook | DPRINTF("Delayed select timeout\n");
|
1207 | 7d8406be | pbrook | lsi_stop_script(s); |
1208 | 7d8406be | pbrook | break;
|
1209 | 7d8406be | pbrook | } |
1210 | 7d8406be | pbrook | cond = jmp = (insn & (1 << 19)) != 0; |
1211 | 7d8406be | pbrook | if (cond == jmp && (insn & (1 << 21))) { |
1212 | 7d8406be | pbrook | DPRINTF("Compare carry %d\n", s->carry == jmp);
|
1213 | 7d8406be | pbrook | cond = s->carry != 0;
|
1214 | 7d8406be | pbrook | } |
1215 | 7d8406be | pbrook | if (cond == jmp && (insn & (1 << 17))) { |
1216 | 7d8406be | pbrook | DPRINTF("Compare phase %d %c= %d\n",
|
1217 | 7d8406be | pbrook | (s->sstat1 & PHASE_MASK), |
1218 | 7d8406be | pbrook | jmp ? '=' : '!', |
1219 | 7d8406be | pbrook | ((insn >> 24) & 7)); |
1220 | 7d8406be | pbrook | cond = (s->sstat1 & PHASE_MASK) == ((insn >> 24) & 7); |
1221 | 7d8406be | pbrook | } |
1222 | 7d8406be | pbrook | if (cond == jmp && (insn & (1 << 18))) { |
1223 | 7d8406be | pbrook | uint8_t mask; |
1224 | 7d8406be | pbrook | |
1225 | 7d8406be | pbrook | mask = (~insn >> 8) & 0xff; |
1226 | 7d8406be | pbrook | DPRINTF("Compare data 0x%x & 0x%x %c= 0x%x\n",
|
1227 | 7d8406be | pbrook | s->sfbr, mask, jmp ? '=' : '!', insn & mask); |
1228 | 7d8406be | pbrook | cond = (s->sfbr & mask) == (insn & mask); |
1229 | 7d8406be | pbrook | } |
1230 | 7d8406be | pbrook | if (cond == jmp) {
|
1231 | 7d8406be | pbrook | if (insn & (1 << 23)) { |
1232 | 7d8406be | pbrook | /* Relative address. */
|
1233 | 7d8406be | pbrook | addr = s->dsp + sxt24(addr); |
1234 | 7d8406be | pbrook | } |
1235 | 7d8406be | pbrook | switch ((insn >> 27) & 7) { |
1236 | 7d8406be | pbrook | case 0: /* Jump */ |
1237 | 7d8406be | pbrook | DPRINTF("Jump to 0x%08x\n", addr);
|
1238 | 7d8406be | pbrook | s->dsp = addr; |
1239 | 7d8406be | pbrook | break;
|
1240 | 7d8406be | pbrook | case 1: /* Call */ |
1241 | 7d8406be | pbrook | DPRINTF("Call 0x%08x\n", addr);
|
1242 | 7d8406be | pbrook | s->temp = s->dsp; |
1243 | 7d8406be | pbrook | s->dsp = addr; |
1244 | 7d8406be | pbrook | break;
|
1245 | 7d8406be | pbrook | case 2: /* Return */ |
1246 | 7d8406be | pbrook | DPRINTF("Return to 0x%08x\n", s->temp);
|
1247 | 7d8406be | pbrook | s->dsp = s->temp; |
1248 | 7d8406be | pbrook | break;
|
1249 | 7d8406be | pbrook | case 3: /* Interrupt */ |
1250 | 7d8406be | pbrook | DPRINTF("Interrupt 0x%08x\n", s->dsps);
|
1251 | 7d8406be | pbrook | if ((insn & (1 << 20)) != 0) { |
1252 | 7d8406be | pbrook | s->istat0 |= LSI_ISTAT0_INTF; |
1253 | 7d8406be | pbrook | lsi_update_irq(s); |
1254 | 7d8406be | pbrook | } else {
|
1255 | 7d8406be | pbrook | lsi_script_dma_interrupt(s, LSI_DSTAT_SIR); |
1256 | 7d8406be | pbrook | } |
1257 | 7d8406be | pbrook | break;
|
1258 | 7d8406be | pbrook | default:
|
1259 | 7d8406be | pbrook | DPRINTF("Illegal transfer control\n");
|
1260 | 7d8406be | pbrook | lsi_script_dma_interrupt(s, LSI_DSTAT_IID); |
1261 | 7d8406be | pbrook | break;
|
1262 | 7d8406be | pbrook | } |
1263 | 7d8406be | pbrook | } else {
|
1264 | 7d8406be | pbrook | DPRINTF("Control condition failed\n");
|
1265 | 7d8406be | pbrook | } |
1266 | 7d8406be | pbrook | } |
1267 | 7d8406be | pbrook | break;
|
1268 | 7d8406be | pbrook | |
1269 | 7d8406be | pbrook | case 3: |
1270 | 7d8406be | pbrook | if ((insn & (1 << 29)) == 0) { |
1271 | 7d8406be | pbrook | /* Memory move. */
|
1272 | 7d8406be | pbrook | uint32_t dest; |
1273 | 7d8406be | pbrook | /* ??? The docs imply the destination address is loaded into
|
1274 | 7d8406be | pbrook | the TEMP register. However the Linux drivers rely on
|
1275 | 7d8406be | pbrook | the value being presrved. */
|
1276 | 7d8406be | pbrook | dest = read_dword(s, s->dsp); |
1277 | 7d8406be | pbrook | s->dsp += 4;
|
1278 | 7d8406be | pbrook | lsi_memcpy(s, dest, addr, insn & 0xffffff);
|
1279 | 7d8406be | pbrook | } else {
|
1280 | 7d8406be | pbrook | uint8_t data[7];
|
1281 | 7d8406be | pbrook | int reg;
|
1282 | 7d8406be | pbrook | int n;
|
1283 | 7d8406be | pbrook | int i;
|
1284 | 7d8406be | pbrook | |
1285 | 7d8406be | pbrook | if (insn & (1 << 28)) { |
1286 | 7d8406be | pbrook | addr = s->dsa + sxt24(addr); |
1287 | 7d8406be | pbrook | } |
1288 | 7d8406be | pbrook | n = (insn & 7);
|
1289 | 7d8406be | pbrook | reg = (insn >> 16) & 0xff; |
1290 | 7d8406be | pbrook | if (insn & (1 << 24)) { |
1291 | 7d8406be | pbrook | cpu_physical_memory_read(addr, data, n); |
1292 | a917d384 | pbrook | DPRINTF("Load reg 0x%x size %d addr 0x%08x = %08x\n", reg, n,
|
1293 | a917d384 | pbrook | addr, *(int *)data);
|
1294 | 7d8406be | pbrook | for (i = 0; i < n; i++) { |
1295 | 7d8406be | pbrook | lsi_reg_writeb(s, reg + i, data[i]); |
1296 | 7d8406be | pbrook | } |
1297 | 7d8406be | pbrook | } else {
|
1298 | 7d8406be | pbrook | DPRINTF("Store reg 0x%x size %d addr 0x%08x\n", reg, n, addr);
|
1299 | 7d8406be | pbrook | for (i = 0; i < n; i++) { |
1300 | 7d8406be | pbrook | data[i] = lsi_reg_readb(s, reg + i); |
1301 | 7d8406be | pbrook | } |
1302 | 7d8406be | pbrook | cpu_physical_memory_write(addr, data, n); |
1303 | 7d8406be | pbrook | } |
1304 | 7d8406be | pbrook | } |
1305 | 7d8406be | pbrook | } |
1306 | ee4d919f | aliguori | if (insn_processed > 10000 && !s->waiting) { |
1307 | 64c68080 | pbrook | /* Some windows drivers make the device spin waiting for a memory
|
1308 | 64c68080 | pbrook | location to change. If we have been executed a lot of code then
|
1309 | 64c68080 | pbrook | assume this is the case and force an unexpected device disconnect.
|
1310 | 64c68080 | pbrook | This is apparently sufficient to beat the drivers into submission.
|
1311 | 64c68080 | pbrook | */
|
1312 | ee4d919f | aliguori | if (!(s->sien0 & LSI_SIST0_UDC))
|
1313 | ee4d919f | aliguori | fprintf(stderr, "inf. loop with UDC masked\n");
|
1314 | ee4d919f | aliguori | lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
|
1315 | ee4d919f | aliguori | lsi_disconnect(s); |
1316 | ee4d919f | aliguori | } else if (s->istat1 & LSI_ISTAT1_SRUN && !s->waiting) { |
1317 | 7d8406be | pbrook | if (s->dcntl & LSI_DCNTL_SSM) {
|
1318 | 7d8406be | pbrook | lsi_script_dma_interrupt(s, LSI_DSTAT_SSI); |
1319 | 7d8406be | pbrook | } else {
|
1320 | 7d8406be | pbrook | goto again;
|
1321 | 7d8406be | pbrook | } |
1322 | 7d8406be | pbrook | } |
1323 | 7d8406be | pbrook | DPRINTF("SCRIPTS execution stopped\n");
|
1324 | 7d8406be | pbrook | } |
1325 | 7d8406be | pbrook | |
1326 | 7d8406be | pbrook | static uint8_t lsi_reg_readb(LSIState *s, int offset) |
1327 | 7d8406be | pbrook | { |
1328 | 7d8406be | pbrook | uint8_t tmp; |
1329 | 75f76531 | aurel32 | #define CASE_GET_REG24(name, addr) \
|
1330 | 75f76531 | aurel32 | case addr: return s->name & 0xff; \ |
1331 | 75f76531 | aurel32 | case addr + 1: return (s->name >> 8) & 0xff; \ |
1332 | 75f76531 | aurel32 | case addr + 2: return (s->name >> 16) & 0xff; |
1333 | 75f76531 | aurel32 | |
1334 | 7d8406be | pbrook | #define CASE_GET_REG32(name, addr) \
|
1335 | 7d8406be | pbrook | case addr: return s->name & 0xff; \ |
1336 | 7d8406be | pbrook | case addr + 1: return (s->name >> 8) & 0xff; \ |
1337 | 7d8406be | pbrook | case addr + 2: return (s->name >> 16) & 0xff; \ |
1338 | 7d8406be | pbrook | case addr + 3: return (s->name >> 24) & 0xff; |
1339 | 7d8406be | pbrook | |
1340 | 7d8406be | pbrook | #ifdef DEBUG_LSI_REG
|
1341 | 7d8406be | pbrook | DPRINTF("Read reg %x\n", offset);
|
1342 | 7d8406be | pbrook | #endif
|
1343 | 7d8406be | pbrook | switch (offset) {
|
1344 | 7d8406be | pbrook | case 0x00: /* SCNTL0 */ |
1345 | 7d8406be | pbrook | return s->scntl0;
|
1346 | 7d8406be | pbrook | case 0x01: /* SCNTL1 */ |
1347 | 7d8406be | pbrook | return s->scntl1;
|
1348 | 7d8406be | pbrook | case 0x02: /* SCNTL2 */ |
1349 | 7d8406be | pbrook | return s->scntl2;
|
1350 | 7d8406be | pbrook | case 0x03: /* SCNTL3 */ |
1351 | 7d8406be | pbrook | return s->scntl3;
|
1352 | 7d8406be | pbrook | case 0x04: /* SCID */ |
1353 | 7d8406be | pbrook | return s->scid;
|
1354 | 7d8406be | pbrook | case 0x05: /* SXFER */ |
1355 | 7d8406be | pbrook | return s->sxfer;
|
1356 | 7d8406be | pbrook | case 0x06: /* SDID */ |
1357 | 7d8406be | pbrook | return s->sdid;
|
1358 | 7d8406be | pbrook | case 0x07: /* GPREG0 */ |
1359 | 7d8406be | pbrook | return 0x7f; |
1360 | 985a03b0 | ths | case 0x08: /* Revision ID */ |
1361 | 985a03b0 | ths | return 0x00; |
1362 | a917d384 | pbrook | case 0xa: /* SSID */ |
1363 | a917d384 | pbrook | return s->ssid;
|
1364 | 7d8406be | pbrook | case 0xb: /* SBCL */ |
1365 | 7d8406be | pbrook | /* ??? This is not correct. However it's (hopefully) only
|
1366 | 7d8406be | pbrook | used for diagnostics, so should be ok. */
|
1367 | 7d8406be | pbrook | return 0; |
1368 | 7d8406be | pbrook | case 0xc: /* DSTAT */ |
1369 | 7d8406be | pbrook | tmp = s->dstat | 0x80;
|
1370 | 7d8406be | pbrook | if ((s->istat0 & LSI_ISTAT0_INTF) == 0) |
1371 | 7d8406be | pbrook | s->dstat = 0;
|
1372 | 7d8406be | pbrook | lsi_update_irq(s); |
1373 | 7d8406be | pbrook | return tmp;
|
1374 | 7d8406be | pbrook | case 0x0d: /* SSTAT0 */ |
1375 | 7d8406be | pbrook | return s->sstat0;
|
1376 | 7d8406be | pbrook | case 0x0e: /* SSTAT1 */ |
1377 | 7d8406be | pbrook | return s->sstat1;
|
1378 | 7d8406be | pbrook | case 0x0f: /* SSTAT2 */ |
1379 | 7d8406be | pbrook | return s->scntl1 & LSI_SCNTL1_CON ? 0 : 2; |
1380 | 7d8406be | pbrook | CASE_GET_REG32(dsa, 0x10)
|
1381 | 7d8406be | pbrook | case 0x14: /* ISTAT0 */ |
1382 | 7d8406be | pbrook | return s->istat0;
|
1383 | ecabe8cc | aliguori | case 0x15: /* ISTAT1 */ |
1384 | ecabe8cc | aliguori | return s->istat1;
|
1385 | 7d8406be | pbrook | case 0x16: /* MBOX0 */ |
1386 | 7d8406be | pbrook | return s->mbox0;
|
1387 | 7d8406be | pbrook | case 0x17: /* MBOX1 */ |
1388 | 7d8406be | pbrook | return s->mbox1;
|
1389 | 7d8406be | pbrook | case 0x18: /* CTEST0 */ |
1390 | 7d8406be | pbrook | return 0xff; |
1391 | 7d8406be | pbrook | case 0x19: /* CTEST1 */ |
1392 | 7d8406be | pbrook | return 0; |
1393 | 7d8406be | pbrook | case 0x1a: /* CTEST2 */ |
1394 | 9167a69a | balrog | tmp = s->ctest2 | LSI_CTEST2_DACK | LSI_CTEST2_CM; |
1395 | 7d8406be | pbrook | if (s->istat0 & LSI_ISTAT0_SIGP) {
|
1396 | 7d8406be | pbrook | s->istat0 &= ~LSI_ISTAT0_SIGP; |
1397 | 7d8406be | pbrook | tmp |= LSI_CTEST2_SIGP; |
1398 | 7d8406be | pbrook | } |
1399 | 7d8406be | pbrook | return tmp;
|
1400 | 7d8406be | pbrook | case 0x1b: /* CTEST3 */ |
1401 | 7d8406be | pbrook | return s->ctest3;
|
1402 | 7d8406be | pbrook | CASE_GET_REG32(temp, 0x1c)
|
1403 | 7d8406be | pbrook | case 0x20: /* DFIFO */ |
1404 | 7d8406be | pbrook | return 0; |
1405 | 7d8406be | pbrook | case 0x21: /* CTEST4 */ |
1406 | 7d8406be | pbrook | return s->ctest4;
|
1407 | 7d8406be | pbrook | case 0x22: /* CTEST5 */ |
1408 | 7d8406be | pbrook | return s->ctest5;
|
1409 | 985a03b0 | ths | case 0x23: /* CTEST6 */ |
1410 | 985a03b0 | ths | return 0; |
1411 | 75f76531 | aurel32 | CASE_GET_REG24(dbc, 0x24)
|
1412 | 7d8406be | pbrook | case 0x27: /* DCMD */ |
1413 | 7d8406be | pbrook | return s->dcmd;
|
1414 | 4b9a2d6d | Sebastian Herbszt | CASE_GET_REG32(dnad, 0x28)
|
1415 | 7d8406be | pbrook | CASE_GET_REG32(dsp, 0x2c)
|
1416 | 7d8406be | pbrook | CASE_GET_REG32(dsps, 0x30)
|
1417 | 7d8406be | pbrook | CASE_GET_REG32(scratch[0], 0x34) |
1418 | 7d8406be | pbrook | case 0x38: /* DMODE */ |
1419 | 7d8406be | pbrook | return s->dmode;
|
1420 | 7d8406be | pbrook | case 0x39: /* DIEN */ |
1421 | 7d8406be | pbrook | return s->dien;
|
1422 | bd8ee11a | Sebastian Herbszt | case 0x3a: /* SBR */ |
1423 | bd8ee11a | Sebastian Herbszt | return s->sbr;
|
1424 | 7d8406be | pbrook | case 0x3b: /* DCNTL */ |
1425 | 7d8406be | pbrook | return s->dcntl;
|
1426 | 7d8406be | pbrook | case 0x40: /* SIEN0 */ |
1427 | 7d8406be | pbrook | return s->sien0;
|
1428 | 7d8406be | pbrook | case 0x41: /* SIEN1 */ |
1429 | 7d8406be | pbrook | return s->sien1;
|
1430 | 7d8406be | pbrook | case 0x42: /* SIST0 */ |
1431 | 7d8406be | pbrook | tmp = s->sist0; |
1432 | 7d8406be | pbrook | s->sist0 = 0;
|
1433 | 7d8406be | pbrook | lsi_update_irq(s); |
1434 | 7d8406be | pbrook | return tmp;
|
1435 | 7d8406be | pbrook | case 0x43: /* SIST1 */ |
1436 | 7d8406be | pbrook | tmp = s->sist1; |
1437 | 7d8406be | pbrook | s->sist1 = 0;
|
1438 | 7d8406be | pbrook | lsi_update_irq(s); |
1439 | 7d8406be | pbrook | return tmp;
|
1440 | 9167a69a | balrog | case 0x46: /* MACNTL */ |
1441 | 9167a69a | balrog | return 0x0f; |
1442 | 7d8406be | pbrook | case 0x47: /* GPCNTL0 */ |
1443 | 7d8406be | pbrook | return 0x0f; |
1444 | 7d8406be | pbrook | case 0x48: /* STIME0 */ |
1445 | 7d8406be | pbrook | return s->stime0;
|
1446 | 7d8406be | pbrook | case 0x4a: /* RESPID0 */ |
1447 | 7d8406be | pbrook | return s->respid0;
|
1448 | 7d8406be | pbrook | case 0x4b: /* RESPID1 */ |
1449 | 7d8406be | pbrook | return s->respid1;
|
1450 | 7d8406be | pbrook | case 0x4d: /* STEST1 */ |
1451 | 7d8406be | pbrook | return s->stest1;
|
1452 | 7d8406be | pbrook | case 0x4e: /* STEST2 */ |
1453 | 7d8406be | pbrook | return s->stest2;
|
1454 | 7d8406be | pbrook | case 0x4f: /* STEST3 */ |
1455 | 7d8406be | pbrook | return s->stest3;
|
1456 | a917d384 | pbrook | case 0x50: /* SIDL */ |
1457 | a917d384 | pbrook | /* This is needed by the linux drivers. We currently only update it
|
1458 | a917d384 | pbrook | during the MSG IN phase. */
|
1459 | a917d384 | pbrook | return s->sidl;
|
1460 | 7d8406be | pbrook | case 0x52: /* STEST4 */ |
1461 | 7d8406be | pbrook | return 0xe0; |
1462 | 7d8406be | pbrook | case 0x56: /* CCNTL0 */ |
1463 | 7d8406be | pbrook | return s->ccntl0;
|
1464 | 7d8406be | pbrook | case 0x57: /* CCNTL1 */ |
1465 | 7d8406be | pbrook | return s->ccntl1;
|
1466 | a917d384 | pbrook | case 0x58: /* SBDL */ |
1467 | a917d384 | pbrook | /* Some drivers peek at the data bus during the MSG IN phase. */
|
1468 | a917d384 | pbrook | if ((s->sstat1 & PHASE_MASK) == PHASE_MI)
|
1469 | a917d384 | pbrook | return s->msg[0]; |
1470 | a917d384 | pbrook | return 0; |
1471 | a917d384 | pbrook | case 0x59: /* SBDL high */ |
1472 | 7d8406be | pbrook | return 0; |
1473 | 7d8406be | pbrook | CASE_GET_REG32(mmrs, 0xa0)
|
1474 | 7d8406be | pbrook | CASE_GET_REG32(mmws, 0xa4)
|
1475 | 7d8406be | pbrook | CASE_GET_REG32(sfs, 0xa8)
|
1476 | 7d8406be | pbrook | CASE_GET_REG32(drs, 0xac)
|
1477 | 7d8406be | pbrook | CASE_GET_REG32(sbms, 0xb0)
|
1478 | ab57d967 | aliguori | CASE_GET_REG32(dbms, 0xb4)
|
1479 | 7d8406be | pbrook | CASE_GET_REG32(dnad64, 0xb8)
|
1480 | 7d8406be | pbrook | CASE_GET_REG32(pmjad1, 0xc0)
|
1481 | 7d8406be | pbrook | CASE_GET_REG32(pmjad2, 0xc4)
|
1482 | 7d8406be | pbrook | CASE_GET_REG32(rbc, 0xc8)
|
1483 | 7d8406be | pbrook | CASE_GET_REG32(ua, 0xcc)
|
1484 | 7d8406be | pbrook | CASE_GET_REG32(ia, 0xd4)
|
1485 | 7d8406be | pbrook | CASE_GET_REG32(sbc, 0xd8)
|
1486 | 7d8406be | pbrook | CASE_GET_REG32(csbc, 0xdc)
|
1487 | 7d8406be | pbrook | } |
1488 | 7d8406be | pbrook | if (offset >= 0x5c && offset < 0xa0) { |
1489 | 7d8406be | pbrook | int n;
|
1490 | 7d8406be | pbrook | int shift;
|
1491 | 7d8406be | pbrook | n = (offset - 0x58) >> 2; |
1492 | 7d8406be | pbrook | shift = (offset & 3) * 8; |
1493 | 7d8406be | pbrook | return (s->scratch[n] >> shift) & 0xff; |
1494 | 7d8406be | pbrook | } |
1495 | 7d8406be | pbrook | BADF("readb 0x%x\n", offset);
|
1496 | 7d8406be | pbrook | exit(1);
|
1497 | 75f76531 | aurel32 | #undef CASE_GET_REG24
|
1498 | 7d8406be | pbrook | #undef CASE_GET_REG32
|
1499 | 7d8406be | pbrook | } |
1500 | 7d8406be | pbrook | |
1501 | 7d8406be | pbrook | static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val) |
1502 | 7d8406be | pbrook | { |
1503 | 49c47daa | Sebastian Herbszt | #define CASE_SET_REG24(name, addr) \
|
1504 | 49c47daa | Sebastian Herbszt | case addr : s->name &= 0xffffff00; s->name |= val; break; \ |
1505 | 49c47daa | Sebastian Herbszt | case addr + 1: s->name &= 0xffff00ff; s->name |= val << 8; break; \ |
1506 | 49c47daa | Sebastian Herbszt | case addr + 2: s->name &= 0xff00ffff; s->name |= val << 16; break; |
1507 | 49c47daa | Sebastian Herbszt | |
1508 | 7d8406be | pbrook | #define CASE_SET_REG32(name, addr) \
|
1509 | 7d8406be | pbrook | case addr : s->name &= 0xffffff00; s->name |= val; break; \ |
1510 | 7d8406be | pbrook | case addr + 1: s->name &= 0xffff00ff; s->name |= val << 8; break; \ |
1511 | 7d8406be | pbrook | case addr + 2: s->name &= 0xff00ffff; s->name |= val << 16; break; \ |
1512 | 7d8406be | pbrook | case addr + 3: s->name &= 0x00ffffff; s->name |= val << 24; break; |
1513 | 7d8406be | pbrook | |
1514 | 7d8406be | pbrook | #ifdef DEBUG_LSI_REG
|
1515 | 7d8406be | pbrook | DPRINTF("Write reg %x = %02x\n", offset, val);
|
1516 | 7d8406be | pbrook | #endif
|
1517 | 7d8406be | pbrook | switch (offset) {
|
1518 | 7d8406be | pbrook | case 0x00: /* SCNTL0 */ |
1519 | 7d8406be | pbrook | s->scntl0 = val; |
1520 | 7d8406be | pbrook | if (val & LSI_SCNTL0_START) {
|
1521 | 7d8406be | pbrook | BADF("Start sequence not implemented\n");
|
1522 | 7d8406be | pbrook | } |
1523 | 7d8406be | pbrook | break;
|
1524 | 7d8406be | pbrook | case 0x01: /* SCNTL1 */ |
1525 | 7d8406be | pbrook | s->scntl1 = val & ~LSI_SCNTL1_SST; |
1526 | 7d8406be | pbrook | if (val & LSI_SCNTL1_IARB) {
|
1527 | 7d8406be | pbrook | BADF("Immediate Arbritration not implemented\n");
|
1528 | 7d8406be | pbrook | } |
1529 | 7d8406be | pbrook | if (val & LSI_SCNTL1_RST) {
|
1530 | 7d8406be | pbrook | s->sstat0 |= LSI_SSTAT0_RST; |
1531 | 7d8406be | pbrook | lsi_script_scsi_interrupt(s, LSI_SIST0_RST, 0);
|
1532 | 7d8406be | pbrook | } else {
|
1533 | 7d8406be | pbrook | s->sstat0 &= ~LSI_SSTAT0_RST; |
1534 | 7d8406be | pbrook | } |
1535 | 7d8406be | pbrook | break;
|
1536 | 7d8406be | pbrook | case 0x02: /* SCNTL2 */ |
1537 | 7d8406be | pbrook | val &= ~(LSI_SCNTL2_WSR | LSI_SCNTL2_WSS); |
1538 | 3d834c78 | ths | s->scntl2 = val; |
1539 | 7d8406be | pbrook | break;
|
1540 | 7d8406be | pbrook | case 0x03: /* SCNTL3 */ |
1541 | 7d8406be | pbrook | s->scntl3 = val; |
1542 | 7d8406be | pbrook | break;
|
1543 | 7d8406be | pbrook | case 0x04: /* SCID */ |
1544 | 7d8406be | pbrook | s->scid = val; |
1545 | 7d8406be | pbrook | break;
|
1546 | 7d8406be | pbrook | case 0x05: /* SXFER */ |
1547 | 7d8406be | pbrook | s->sxfer = val; |
1548 | 7d8406be | pbrook | break;
|
1549 | a917d384 | pbrook | case 0x06: /* SDID */ |
1550 | a917d384 | pbrook | if ((val & 0xf) != (s->ssid & 0xf)) |
1551 | a917d384 | pbrook | BADF("Destination ID does not match SSID\n");
|
1552 | a917d384 | pbrook | s->sdid = val & 0xf;
|
1553 | a917d384 | pbrook | break;
|
1554 | 7d8406be | pbrook | case 0x07: /* GPREG0 */ |
1555 | 7d8406be | pbrook | break;
|
1556 | a917d384 | pbrook | case 0x08: /* SFBR */ |
1557 | a917d384 | pbrook | /* The CPU is not allowed to write to this register. However the
|
1558 | a917d384 | pbrook | SCRIPTS register move instructions are. */
|
1559 | a917d384 | pbrook | s->sfbr = val; |
1560 | a917d384 | pbrook | break;
|
1561 | a15fdf86 | Laszlo Ast | case 0x0a: case 0x0b: |
1562 | 9167a69a | balrog | /* Openserver writes to these readonly registers on startup */
|
1563 | a15fdf86 | Laszlo Ast | return;
|
1564 | 7d8406be | pbrook | case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
1565 | 7d8406be | pbrook | /* Linux writes to these readonly registers on startup. */
|
1566 | 7d8406be | pbrook | return;
|
1567 | 7d8406be | pbrook | CASE_SET_REG32(dsa, 0x10)
|
1568 | 7d8406be | pbrook | case 0x14: /* ISTAT0 */ |
1569 | 7d8406be | pbrook | s->istat0 = (s->istat0 & 0x0f) | (val & 0xf0); |
1570 | 7d8406be | pbrook | if (val & LSI_ISTAT0_ABRT) {
|
1571 | 7d8406be | pbrook | lsi_script_dma_interrupt(s, LSI_DSTAT_ABRT); |
1572 | 7d8406be | pbrook | } |
1573 | 7d8406be | pbrook | if (val & LSI_ISTAT0_INTF) {
|
1574 | 7d8406be | pbrook | s->istat0 &= ~LSI_ISTAT0_INTF; |
1575 | 7d8406be | pbrook | lsi_update_irq(s); |
1576 | 7d8406be | pbrook | } |
1577 | 4d611c9a | pbrook | if (s->waiting == 1 && val & LSI_ISTAT0_SIGP) { |
1578 | 7d8406be | pbrook | DPRINTF("Woken by SIGP\n");
|
1579 | 7d8406be | pbrook | s->waiting = 0;
|
1580 | 7d8406be | pbrook | s->dsp = s->dnad; |
1581 | 7d8406be | pbrook | lsi_execute_script(s); |
1582 | 7d8406be | pbrook | } |
1583 | 7d8406be | pbrook | if (val & LSI_ISTAT0_SRST) {
|
1584 | 7d8406be | pbrook | lsi_soft_reset(s); |
1585 | 7d8406be | pbrook | } |
1586 | 92d88ecb | ths | break;
|
1587 | 7d8406be | pbrook | case 0x16: /* MBOX0 */ |
1588 | 7d8406be | pbrook | s->mbox0 = val; |
1589 | 92d88ecb | ths | break;
|
1590 | 7d8406be | pbrook | case 0x17: /* MBOX1 */ |
1591 | 7d8406be | pbrook | s->mbox1 = val; |
1592 | 92d88ecb | ths | break;
|
1593 | 9167a69a | balrog | case 0x1a: /* CTEST2 */ |
1594 | 9167a69a | balrog | s->ctest2 = val & LSI_CTEST2_PCICIE; |
1595 | 9167a69a | balrog | break;
|
1596 | 7d8406be | pbrook | case 0x1b: /* CTEST3 */ |
1597 | 7d8406be | pbrook | s->ctest3 = val & 0x0f;
|
1598 | 7d8406be | pbrook | break;
|
1599 | 7d8406be | pbrook | CASE_SET_REG32(temp, 0x1c)
|
1600 | 7d8406be | pbrook | case 0x21: /* CTEST4 */ |
1601 | 7d8406be | pbrook | if (val & 7) { |
1602 | 7d8406be | pbrook | BADF("Unimplemented CTEST4-FBL 0x%x\n", val);
|
1603 | 7d8406be | pbrook | } |
1604 | 7d8406be | pbrook | s->ctest4 = val; |
1605 | 7d8406be | pbrook | break;
|
1606 | 7d8406be | pbrook | case 0x22: /* CTEST5 */ |
1607 | 7d8406be | pbrook | if (val & (LSI_CTEST5_ADCK | LSI_CTEST5_BBCK)) {
|
1608 | 7d8406be | pbrook | BADF("CTEST5 DMA increment not implemented\n");
|
1609 | 7d8406be | pbrook | } |
1610 | 7d8406be | pbrook | s->ctest5 = val; |
1611 | 7d8406be | pbrook | break;
|
1612 | 49c47daa | Sebastian Herbszt | CASE_SET_REG24(dbc, 0x24)
|
1613 | 4b9a2d6d | Sebastian Herbszt | CASE_SET_REG32(dnad, 0x28)
|
1614 | 3d834c78 | ths | case 0x2c: /* DSP[0:7] */ |
1615 | 7d8406be | pbrook | s->dsp &= 0xffffff00;
|
1616 | 7d8406be | pbrook | s->dsp |= val; |
1617 | 7d8406be | pbrook | break;
|
1618 | 3d834c78 | ths | case 0x2d: /* DSP[8:15] */ |
1619 | 7d8406be | pbrook | s->dsp &= 0xffff00ff;
|
1620 | 7d8406be | pbrook | s->dsp |= val << 8;
|
1621 | 7d8406be | pbrook | break;
|
1622 | 3d834c78 | ths | case 0x2e: /* DSP[16:23] */ |
1623 | 7d8406be | pbrook | s->dsp &= 0xff00ffff;
|
1624 | 7d8406be | pbrook | s->dsp |= val << 16;
|
1625 | 7d8406be | pbrook | break;
|
1626 | 3d834c78 | ths | case 0x2f: /* DSP[24:31] */ |
1627 | 7d8406be | pbrook | s->dsp &= 0x00ffffff;
|
1628 | 7d8406be | pbrook | s->dsp |= val << 24;
|
1629 | 7d8406be | pbrook | if ((s->dmode & LSI_DMODE_MAN) == 0 |
1630 | 7d8406be | pbrook | && (s->istat1 & LSI_ISTAT1_SRUN) == 0)
|
1631 | 7d8406be | pbrook | lsi_execute_script(s); |
1632 | 7d8406be | pbrook | break;
|
1633 | 7d8406be | pbrook | CASE_SET_REG32(dsps, 0x30)
|
1634 | 7d8406be | pbrook | CASE_SET_REG32(scratch[0], 0x34) |
1635 | 7d8406be | pbrook | case 0x38: /* DMODE */ |
1636 | 7d8406be | pbrook | if (val & (LSI_DMODE_SIOM | LSI_DMODE_DIOM)) {
|
1637 | 7d8406be | pbrook | BADF("IO mappings not implemented\n");
|
1638 | 7d8406be | pbrook | } |
1639 | 7d8406be | pbrook | s->dmode = val; |
1640 | 7d8406be | pbrook | break;
|
1641 | 7d8406be | pbrook | case 0x39: /* DIEN */ |
1642 | 7d8406be | pbrook | s->dien = val; |
1643 | 7d8406be | pbrook | lsi_update_irq(s); |
1644 | 7d8406be | pbrook | break;
|
1645 | bd8ee11a | Sebastian Herbszt | case 0x3a: /* SBR */ |
1646 | bd8ee11a | Sebastian Herbszt | s->sbr = val; |
1647 | bd8ee11a | Sebastian Herbszt | break;
|
1648 | 7d8406be | pbrook | case 0x3b: /* DCNTL */ |
1649 | 7d8406be | pbrook | s->dcntl = val & ~(LSI_DCNTL_PFF | LSI_DCNTL_STD); |
1650 | 7d8406be | pbrook | if ((val & LSI_DCNTL_STD) && (s->istat1 & LSI_ISTAT1_SRUN) == 0) |
1651 | 7d8406be | pbrook | lsi_execute_script(s); |
1652 | 7d8406be | pbrook | break;
|
1653 | 7d8406be | pbrook | case 0x40: /* SIEN0 */ |
1654 | 7d8406be | pbrook | s->sien0 = val; |
1655 | 7d8406be | pbrook | lsi_update_irq(s); |
1656 | 7d8406be | pbrook | break;
|
1657 | 7d8406be | pbrook | case 0x41: /* SIEN1 */ |
1658 | 7d8406be | pbrook | s->sien1 = val; |
1659 | 7d8406be | pbrook | lsi_update_irq(s); |
1660 | 7d8406be | pbrook | break;
|
1661 | 7d8406be | pbrook | case 0x47: /* GPCNTL0 */ |
1662 | 7d8406be | pbrook | break;
|
1663 | 7d8406be | pbrook | case 0x48: /* STIME0 */ |
1664 | 7d8406be | pbrook | s->stime0 = val; |
1665 | 7d8406be | pbrook | break;
|
1666 | 7d8406be | pbrook | case 0x49: /* STIME1 */ |
1667 | 7d8406be | pbrook | if (val & 0xf) { |
1668 | 7d8406be | pbrook | DPRINTF("General purpose timer not implemented\n");
|
1669 | 7d8406be | pbrook | /* ??? Raising the interrupt immediately seems to be sufficient
|
1670 | 7d8406be | pbrook | to keep the FreeBSD driver happy. */
|
1671 | 7d8406be | pbrook | lsi_script_scsi_interrupt(s, 0, LSI_SIST1_GEN);
|
1672 | 7d8406be | pbrook | } |
1673 | 7d8406be | pbrook | break;
|
1674 | 7d8406be | pbrook | case 0x4a: /* RESPID0 */ |
1675 | 7d8406be | pbrook | s->respid0 = val; |
1676 | 7d8406be | pbrook | break;
|
1677 | 7d8406be | pbrook | case 0x4b: /* RESPID1 */ |
1678 | 7d8406be | pbrook | s->respid1 = val; |
1679 | 7d8406be | pbrook | break;
|
1680 | 7d8406be | pbrook | case 0x4d: /* STEST1 */ |
1681 | 7d8406be | pbrook | s->stest1 = val; |
1682 | 7d8406be | pbrook | break;
|
1683 | 7d8406be | pbrook | case 0x4e: /* STEST2 */ |
1684 | 7d8406be | pbrook | if (val & 1) { |
1685 | 7d8406be | pbrook | BADF("Low level mode not implemented\n");
|
1686 | 7d8406be | pbrook | } |
1687 | 7d8406be | pbrook | s->stest2 = val; |
1688 | 7d8406be | pbrook | break;
|
1689 | 7d8406be | pbrook | case 0x4f: /* STEST3 */ |
1690 | 7d8406be | pbrook | if (val & 0x41) { |
1691 | 7d8406be | pbrook | BADF("SCSI FIFO test mode not implemented\n");
|
1692 | 7d8406be | pbrook | } |
1693 | 7d8406be | pbrook | s->stest3 = val; |
1694 | 7d8406be | pbrook | break;
|
1695 | 7d8406be | pbrook | case 0x56: /* CCNTL0 */ |
1696 | 7d8406be | pbrook | s->ccntl0 = val; |
1697 | 7d8406be | pbrook | break;
|
1698 | 7d8406be | pbrook | case 0x57: /* CCNTL1 */ |
1699 | 7d8406be | pbrook | s->ccntl1 = val; |
1700 | 7d8406be | pbrook | break;
|
1701 | 7d8406be | pbrook | CASE_SET_REG32(mmrs, 0xa0)
|
1702 | 7d8406be | pbrook | CASE_SET_REG32(mmws, 0xa4)
|
1703 | 7d8406be | pbrook | CASE_SET_REG32(sfs, 0xa8)
|
1704 | 7d8406be | pbrook | CASE_SET_REG32(drs, 0xac)
|
1705 | 7d8406be | pbrook | CASE_SET_REG32(sbms, 0xb0)
|
1706 | ab57d967 | aliguori | CASE_SET_REG32(dbms, 0xb4)
|
1707 | 7d8406be | pbrook | CASE_SET_REG32(dnad64, 0xb8)
|
1708 | 7d8406be | pbrook | CASE_SET_REG32(pmjad1, 0xc0)
|
1709 | 7d8406be | pbrook | CASE_SET_REG32(pmjad2, 0xc4)
|
1710 | 7d8406be | pbrook | CASE_SET_REG32(rbc, 0xc8)
|
1711 | 7d8406be | pbrook | CASE_SET_REG32(ua, 0xcc)
|
1712 | 7d8406be | pbrook | CASE_SET_REG32(ia, 0xd4)
|
1713 | 7d8406be | pbrook | CASE_SET_REG32(sbc, 0xd8)
|
1714 | 7d8406be | pbrook | CASE_SET_REG32(csbc, 0xdc)
|
1715 | 7d8406be | pbrook | default:
|
1716 | 7d8406be | pbrook | if (offset >= 0x5c && offset < 0xa0) { |
1717 | 7d8406be | pbrook | int n;
|
1718 | 7d8406be | pbrook | int shift;
|
1719 | 7d8406be | pbrook | n = (offset - 0x58) >> 2; |
1720 | 7d8406be | pbrook | shift = (offset & 3) * 8; |
1721 | 7d8406be | pbrook | s->scratch[n] &= ~(0xff << shift);
|
1722 | 7d8406be | pbrook | s->scratch[n] |= (val & 0xff) << shift;
|
1723 | 7d8406be | pbrook | } else {
|
1724 | 7d8406be | pbrook | BADF("Unhandled writeb 0x%x = 0x%x\n", offset, val);
|
1725 | 7d8406be | pbrook | } |
1726 | 7d8406be | pbrook | } |
1727 | 49c47daa | Sebastian Herbszt | #undef CASE_SET_REG24
|
1728 | 7d8406be | pbrook | #undef CASE_SET_REG32
|
1729 | 7d8406be | pbrook | } |
1730 | 7d8406be | pbrook | |
1731 | c227f099 | Anthony Liguori | static void lsi_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
1732 | 7d8406be | pbrook | { |
1733 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1734 | 7d8406be | pbrook | |
1735 | 7d8406be | pbrook | lsi_reg_writeb(s, addr & 0xff, val);
|
1736 | 7d8406be | pbrook | } |
1737 | 7d8406be | pbrook | |
1738 | c227f099 | Anthony Liguori | static void lsi_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
1739 | 7d8406be | pbrook | { |
1740 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1741 | 7d8406be | pbrook | |
1742 | 7d8406be | pbrook | addr &= 0xff;
|
1743 | 7d8406be | pbrook | lsi_reg_writeb(s, addr, val & 0xff);
|
1744 | 7d8406be | pbrook | lsi_reg_writeb(s, addr + 1, (val >> 8) & 0xff); |
1745 | 7d8406be | pbrook | } |
1746 | 7d8406be | pbrook | |
1747 | c227f099 | Anthony Liguori | static void lsi_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
1748 | 7d8406be | pbrook | { |
1749 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1750 | 7d8406be | pbrook | |
1751 | 7d8406be | pbrook | addr &= 0xff;
|
1752 | 7d8406be | pbrook | lsi_reg_writeb(s, addr, val & 0xff);
|
1753 | 7d8406be | pbrook | lsi_reg_writeb(s, addr + 1, (val >> 8) & 0xff); |
1754 | 7d8406be | pbrook | lsi_reg_writeb(s, addr + 2, (val >> 16) & 0xff); |
1755 | 7d8406be | pbrook | lsi_reg_writeb(s, addr + 3, (val >> 24) & 0xff); |
1756 | 7d8406be | pbrook | } |
1757 | 7d8406be | pbrook | |
1758 | c227f099 | Anthony Liguori | static uint32_t lsi_mmio_readb(void *opaque, target_phys_addr_t addr) |
1759 | 7d8406be | pbrook | { |
1760 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1761 | 7d8406be | pbrook | |
1762 | 7d8406be | pbrook | return lsi_reg_readb(s, addr & 0xff); |
1763 | 7d8406be | pbrook | } |
1764 | 7d8406be | pbrook | |
1765 | c227f099 | Anthony Liguori | static uint32_t lsi_mmio_readw(void *opaque, target_phys_addr_t addr) |
1766 | 7d8406be | pbrook | { |
1767 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1768 | 7d8406be | pbrook | uint32_t val; |
1769 | 7d8406be | pbrook | |
1770 | 7d8406be | pbrook | addr &= 0xff;
|
1771 | 7d8406be | pbrook | val = lsi_reg_readb(s, addr); |
1772 | 7d8406be | pbrook | val |= lsi_reg_readb(s, addr + 1) << 8; |
1773 | 7d8406be | pbrook | return val;
|
1774 | 7d8406be | pbrook | } |
1775 | 7d8406be | pbrook | |
1776 | c227f099 | Anthony Liguori | static uint32_t lsi_mmio_readl(void *opaque, target_phys_addr_t addr) |
1777 | 7d8406be | pbrook | { |
1778 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1779 | 7d8406be | pbrook | uint32_t val; |
1780 | 7d8406be | pbrook | addr &= 0xff;
|
1781 | 7d8406be | pbrook | val = lsi_reg_readb(s, addr); |
1782 | 7d8406be | pbrook | val |= lsi_reg_readb(s, addr + 1) << 8; |
1783 | 7d8406be | pbrook | val |= lsi_reg_readb(s, addr + 2) << 16; |
1784 | 7d8406be | pbrook | val |= lsi_reg_readb(s, addr + 3) << 24; |
1785 | 7d8406be | pbrook | return val;
|
1786 | 7d8406be | pbrook | } |
1787 | 7d8406be | pbrook | |
1788 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const lsi_mmio_readfn[3] = { |
1789 | 7d8406be | pbrook | lsi_mmio_readb, |
1790 | 7d8406be | pbrook | lsi_mmio_readw, |
1791 | 7d8406be | pbrook | lsi_mmio_readl, |
1792 | 7d8406be | pbrook | }; |
1793 | 7d8406be | pbrook | |
1794 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const lsi_mmio_writefn[3] = { |
1795 | 7d8406be | pbrook | lsi_mmio_writeb, |
1796 | 7d8406be | pbrook | lsi_mmio_writew, |
1797 | 7d8406be | pbrook | lsi_mmio_writel, |
1798 | 7d8406be | pbrook | }; |
1799 | 7d8406be | pbrook | |
1800 | c227f099 | Anthony Liguori | static void lsi_ram_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
1801 | 7d8406be | pbrook | { |
1802 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1803 | 7d8406be | pbrook | uint32_t newval; |
1804 | 7d8406be | pbrook | int shift;
|
1805 | 7d8406be | pbrook | |
1806 | 7d8406be | pbrook | addr &= 0x1fff;
|
1807 | 7d8406be | pbrook | newval = s->script_ram[addr >> 2];
|
1808 | 7d8406be | pbrook | shift = (addr & 3) * 8; |
1809 | 7d8406be | pbrook | newval &= ~(0xff << shift);
|
1810 | 7d8406be | pbrook | newval |= val << shift; |
1811 | 7d8406be | pbrook | s->script_ram[addr >> 2] = newval;
|
1812 | 7d8406be | pbrook | } |
1813 | 7d8406be | pbrook | |
1814 | c227f099 | Anthony Liguori | static void lsi_ram_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
1815 | 7d8406be | pbrook | { |
1816 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1817 | 7d8406be | pbrook | uint32_t newval; |
1818 | 7d8406be | pbrook | |
1819 | 7d8406be | pbrook | addr &= 0x1fff;
|
1820 | 7d8406be | pbrook | newval = s->script_ram[addr >> 2];
|
1821 | 7d8406be | pbrook | if (addr & 2) { |
1822 | 7d8406be | pbrook | newval = (newval & 0xffff) | (val << 16); |
1823 | 7d8406be | pbrook | } else {
|
1824 | 7d8406be | pbrook | newval = (newval & 0xffff0000) | val;
|
1825 | 7d8406be | pbrook | } |
1826 | 7d8406be | pbrook | s->script_ram[addr >> 2] = newval;
|
1827 | 7d8406be | pbrook | } |
1828 | 7d8406be | pbrook | |
1829 | 7d8406be | pbrook | |
1830 | c227f099 | Anthony Liguori | static void lsi_ram_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
1831 | 7d8406be | pbrook | { |
1832 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1833 | 7d8406be | pbrook | |
1834 | 7d8406be | pbrook | addr &= 0x1fff;
|
1835 | 7d8406be | pbrook | s->script_ram[addr >> 2] = val;
|
1836 | 7d8406be | pbrook | } |
1837 | 7d8406be | pbrook | |
1838 | c227f099 | Anthony Liguori | static uint32_t lsi_ram_readb(void *opaque, target_phys_addr_t addr) |
1839 | 7d8406be | pbrook | { |
1840 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1841 | 7d8406be | pbrook | uint32_t val; |
1842 | 7d8406be | pbrook | |
1843 | 7d8406be | pbrook | addr &= 0x1fff;
|
1844 | 7d8406be | pbrook | val = s->script_ram[addr >> 2];
|
1845 | 7d8406be | pbrook | val >>= (addr & 3) * 8; |
1846 | 7d8406be | pbrook | return val & 0xff; |
1847 | 7d8406be | pbrook | } |
1848 | 7d8406be | pbrook | |
1849 | c227f099 | Anthony Liguori | static uint32_t lsi_ram_readw(void *opaque, target_phys_addr_t addr) |
1850 | 7d8406be | pbrook | { |
1851 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1852 | 7d8406be | pbrook | uint32_t val; |
1853 | 7d8406be | pbrook | |
1854 | 7d8406be | pbrook | addr &= 0x1fff;
|
1855 | 7d8406be | pbrook | val = s->script_ram[addr >> 2];
|
1856 | 7d8406be | pbrook | if (addr & 2) |
1857 | 7d8406be | pbrook | val >>= 16;
|
1858 | 7d8406be | pbrook | return le16_to_cpu(val);
|
1859 | 7d8406be | pbrook | } |
1860 | 7d8406be | pbrook | |
1861 | c227f099 | Anthony Liguori | static uint32_t lsi_ram_readl(void *opaque, target_phys_addr_t addr) |
1862 | 7d8406be | pbrook | { |
1863 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1864 | 7d8406be | pbrook | |
1865 | 7d8406be | pbrook | addr &= 0x1fff;
|
1866 | 7d8406be | pbrook | return le32_to_cpu(s->script_ram[addr >> 2]); |
1867 | 7d8406be | pbrook | } |
1868 | 7d8406be | pbrook | |
1869 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const lsi_ram_readfn[3] = { |
1870 | 7d8406be | pbrook | lsi_ram_readb, |
1871 | 7d8406be | pbrook | lsi_ram_readw, |
1872 | 7d8406be | pbrook | lsi_ram_readl, |
1873 | 7d8406be | pbrook | }; |
1874 | 7d8406be | pbrook | |
1875 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const lsi_ram_writefn[3] = { |
1876 | 7d8406be | pbrook | lsi_ram_writeb, |
1877 | 7d8406be | pbrook | lsi_ram_writew, |
1878 | 7d8406be | pbrook | lsi_ram_writel, |
1879 | 7d8406be | pbrook | }; |
1880 | 7d8406be | pbrook | |
1881 | 7d8406be | pbrook | static uint32_t lsi_io_readb(void *opaque, uint32_t addr) |
1882 | 7d8406be | pbrook | { |
1883 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1884 | 7d8406be | pbrook | return lsi_reg_readb(s, addr & 0xff); |
1885 | 7d8406be | pbrook | } |
1886 | 7d8406be | pbrook | |
1887 | 7d8406be | pbrook | static uint32_t lsi_io_readw(void *opaque, uint32_t addr) |
1888 | 7d8406be | pbrook | { |
1889 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1890 | 7d8406be | pbrook | uint32_t val; |
1891 | 7d8406be | pbrook | addr &= 0xff;
|
1892 | 7d8406be | pbrook | val = lsi_reg_readb(s, addr); |
1893 | 7d8406be | pbrook | val |= lsi_reg_readb(s, addr + 1) << 8; |
1894 | 7d8406be | pbrook | return val;
|
1895 | 7d8406be | pbrook | } |
1896 | 7d8406be | pbrook | |
1897 | 7d8406be | pbrook | static uint32_t lsi_io_readl(void *opaque, uint32_t addr) |
1898 | 7d8406be | pbrook | { |
1899 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1900 | 7d8406be | pbrook | uint32_t val; |
1901 | 7d8406be | pbrook | addr &= 0xff;
|
1902 | 7d8406be | pbrook | val = lsi_reg_readb(s, addr); |
1903 | 7d8406be | pbrook | val |= lsi_reg_readb(s, addr + 1) << 8; |
1904 | 7d8406be | pbrook | val |= lsi_reg_readb(s, addr + 2) << 16; |
1905 | 7d8406be | pbrook | val |= lsi_reg_readb(s, addr + 3) << 24; |
1906 | 7d8406be | pbrook | return val;
|
1907 | 7d8406be | pbrook | } |
1908 | 7d8406be | pbrook | |
1909 | 7d8406be | pbrook | static void lsi_io_writeb(void *opaque, uint32_t addr, uint32_t val) |
1910 | 7d8406be | pbrook | { |
1911 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1912 | 7d8406be | pbrook | lsi_reg_writeb(s, addr & 0xff, val);
|
1913 | 7d8406be | pbrook | } |
1914 | 7d8406be | pbrook | |
1915 | 7d8406be | pbrook | static void lsi_io_writew(void *opaque, uint32_t addr, uint32_t val) |
1916 | 7d8406be | pbrook | { |
1917 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1918 | 7d8406be | pbrook | addr &= 0xff;
|
1919 | 7d8406be | pbrook | lsi_reg_writeb(s, addr, val & 0xff);
|
1920 | 7d8406be | pbrook | lsi_reg_writeb(s, addr + 1, (val >> 8) & 0xff); |
1921 | 7d8406be | pbrook | } |
1922 | 7d8406be | pbrook | |
1923 | 7d8406be | pbrook | static void lsi_io_writel(void *opaque, uint32_t addr, uint32_t val) |
1924 | 7d8406be | pbrook | { |
1925 | eb40f984 | Juan Quintela | LSIState *s = opaque; |
1926 | 7d8406be | pbrook | addr &= 0xff;
|
1927 | 7d8406be | pbrook | lsi_reg_writeb(s, addr, val & 0xff);
|
1928 | 7d8406be | pbrook | lsi_reg_writeb(s, addr + 1, (val >> 8) & 0xff); |
1929 | 7d8406be | pbrook | lsi_reg_writeb(s, addr + 2, (val >> 16) & 0xff); |
1930 | dcfb9014 | ths | lsi_reg_writeb(s, addr + 3, (val >> 24) & 0xff); |
1931 | 7d8406be | pbrook | } |
1932 | 7d8406be | pbrook | |
1933 | 5fafdf24 | ths | static void lsi_io_mapfunc(PCIDevice *pci_dev, int region_num, |
1934 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type)
|
1935 | 7d8406be | pbrook | { |
1936 | f305261f | Juan Quintela | LSIState *s = DO_UPCAST(LSIState, dev, pci_dev); |
1937 | 7d8406be | pbrook | |
1938 | 7d8406be | pbrook | DPRINTF("Mapping IO at %08x\n", addr);
|
1939 | 7d8406be | pbrook | |
1940 | 7d8406be | pbrook | register_ioport_write(addr, 256, 1, lsi_io_writeb, s); |
1941 | 7d8406be | pbrook | register_ioport_read(addr, 256, 1, lsi_io_readb, s); |
1942 | 7d8406be | pbrook | register_ioport_write(addr, 256, 2, lsi_io_writew, s); |
1943 | 7d8406be | pbrook | register_ioport_read(addr, 256, 2, lsi_io_readw, s); |
1944 | 7d8406be | pbrook | register_ioport_write(addr, 256, 4, lsi_io_writel, s); |
1945 | 7d8406be | pbrook | register_ioport_read(addr, 256, 4, lsi_io_readl, s); |
1946 | 7d8406be | pbrook | } |
1947 | 7d8406be | pbrook | |
1948 | 5fafdf24 | ths | static void lsi_ram_mapfunc(PCIDevice *pci_dev, int region_num, |
1949 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type)
|
1950 | 7d8406be | pbrook | { |
1951 | f305261f | Juan Quintela | LSIState *s = DO_UPCAST(LSIState, dev, pci_dev); |
1952 | 7d8406be | pbrook | |
1953 | 7d8406be | pbrook | DPRINTF("Mapping ram at %08x\n", addr);
|
1954 | 7d8406be | pbrook | s->script_ram_base = addr; |
1955 | 7d8406be | pbrook | cpu_register_physical_memory(addr + 0, 0x2000, s->ram_io_addr); |
1956 | 7d8406be | pbrook | } |
1957 | 7d8406be | pbrook | |
1958 | 5fafdf24 | ths | static void lsi_mmio_mapfunc(PCIDevice *pci_dev, int region_num, |
1959 | 6e355d90 | Isaku Yamahata | pcibus_t addr, pcibus_t size, int type)
|
1960 | 7d8406be | pbrook | { |
1961 | f305261f | Juan Quintela | LSIState *s = DO_UPCAST(LSIState, dev, pci_dev); |
1962 | 7d8406be | pbrook | |
1963 | 7d8406be | pbrook | DPRINTF("Mapping registers at %08x\n", addr);
|
1964 | 7d8406be | pbrook | cpu_register_physical_memory(addr + 0, 0x400, s->mmio_io_addr); |
1965 | 7d8406be | pbrook | } |
1966 | 7d8406be | pbrook | |
1967 | 4a1b0f1c | Juan Quintela | static void lsi_pre_save(void *opaque) |
1968 | 777aec7a | Nolan | { |
1969 | 777aec7a | Nolan | LSIState *s = opaque; |
1970 | 777aec7a | Nolan | |
1971 | 777aec7a | Nolan | assert(s->dma_buf == NULL);
|
1972 | 777aec7a | Nolan | assert(s->current_dma_len == 0);
|
1973 | 777aec7a | Nolan | assert(s->active_commands == 0);
|
1974 | 777aec7a | Nolan | } |
1975 | 777aec7a | Nolan | |
1976 | 4a1b0f1c | Juan Quintela | static const VMStateDescription vmstate_lsi_scsi = { |
1977 | 4a1b0f1c | Juan Quintela | .name = "lsiscsi",
|
1978 | 4a1b0f1c | Juan Quintela | .version_id = 0,
|
1979 | 4a1b0f1c | Juan Quintela | .minimum_version_id = 0,
|
1980 | 4a1b0f1c | Juan Quintela | .minimum_version_id_old = 0,
|
1981 | 4a1b0f1c | Juan Quintela | .pre_save = lsi_pre_save, |
1982 | 4a1b0f1c | Juan Quintela | .fields = (VMStateField []) { |
1983 | 4a1b0f1c | Juan Quintela | VMSTATE_PCI_DEVICE(dev, LSIState), |
1984 | 4a1b0f1c | Juan Quintela | |
1985 | 4a1b0f1c | Juan Quintela | VMSTATE_INT32(carry, LSIState), |
1986 | 4a1b0f1c | Juan Quintela | VMSTATE_INT32(sense, LSIState), |
1987 | 4a1b0f1c | Juan Quintela | VMSTATE_INT32(msg_action, LSIState), |
1988 | 4a1b0f1c | Juan Quintela | VMSTATE_INT32(msg_len, LSIState), |
1989 | 4a1b0f1c | Juan Quintela | VMSTATE_BUFFER(msg, LSIState), |
1990 | 4a1b0f1c | Juan Quintela | VMSTATE_INT32(waiting, LSIState), |
1991 | 4a1b0f1c | Juan Quintela | |
1992 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(dsa, LSIState), |
1993 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(temp, LSIState), |
1994 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(dnad, LSIState), |
1995 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(dbc, LSIState), |
1996 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(istat0, LSIState), |
1997 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(istat1, LSIState), |
1998 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(dcmd, LSIState), |
1999 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(dstat, LSIState), |
2000 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(dien, LSIState), |
2001 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sist0, LSIState), |
2002 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sist1, LSIState), |
2003 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sien0, LSIState), |
2004 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sien1, LSIState), |
2005 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(mbox0, LSIState), |
2006 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(mbox1, LSIState), |
2007 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(dfifo, LSIState), |
2008 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(ctest2, LSIState), |
2009 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(ctest3, LSIState), |
2010 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(ctest4, LSIState), |
2011 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(ctest5, LSIState), |
2012 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(ccntl0, LSIState), |
2013 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(ccntl1, LSIState), |
2014 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(dsp, LSIState), |
2015 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(dsps, LSIState), |
2016 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(dmode, LSIState), |
2017 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(dcntl, LSIState), |
2018 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(scntl0, LSIState), |
2019 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(scntl1, LSIState), |
2020 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(scntl2, LSIState), |
2021 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(scntl3, LSIState), |
2022 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sstat0, LSIState), |
2023 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sstat1, LSIState), |
2024 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(scid, LSIState), |
2025 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sxfer, LSIState), |
2026 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(socl, LSIState), |
2027 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sdid, LSIState), |
2028 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(ssid, LSIState), |
2029 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sfbr, LSIState), |
2030 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(stest1, LSIState), |
2031 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(stest2, LSIState), |
2032 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(stest3, LSIState), |
2033 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sidl, LSIState), |
2034 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(stime0, LSIState), |
2035 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(respid0, LSIState), |
2036 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(respid1, LSIState), |
2037 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(mmrs, LSIState), |
2038 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(mmws, LSIState), |
2039 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(sfs, LSIState), |
2040 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(drs, LSIState), |
2041 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(sbms, LSIState), |
2042 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(dbms, LSIState), |
2043 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(dnad64, LSIState), |
2044 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(pmjad1, LSIState), |
2045 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(pmjad2, LSIState), |
2046 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(rbc, LSIState), |
2047 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(ua, LSIState), |
2048 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(ia, LSIState), |
2049 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(sbc, LSIState), |
2050 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT32(csbc, LSIState), |
2051 | 4a1b0f1c | Juan Quintela | VMSTATE_BUFFER_UNSAFE(scratch, LSIState, 0, 18 * sizeof(uint32_t)), |
2052 | 4a1b0f1c | Juan Quintela | VMSTATE_UINT8(sbr, LSIState), |
2053 | 4a1b0f1c | Juan Quintela | |
2054 | 4a1b0f1c | Juan Quintela | VMSTATE_BUFFER_UNSAFE(script_ram, LSIState, 0, 2048 * sizeof(uint32_t)), |
2055 | 4a1b0f1c | Juan Quintela | VMSTATE_END_OF_LIST() |
2056 | 777aec7a | Nolan | } |
2057 | 4a1b0f1c | Juan Quintela | }; |
2058 | 777aec7a | Nolan | |
2059 | 4b09be85 | aliguori | static int lsi_scsi_uninit(PCIDevice *d) |
2060 | 4b09be85 | aliguori | { |
2061 | f305261f | Juan Quintela | LSIState *s = DO_UPCAST(LSIState, dev, d); |
2062 | 4b09be85 | aliguori | |
2063 | 4b09be85 | aliguori | cpu_unregister_io_memory(s->mmio_io_addr); |
2064 | 4b09be85 | aliguori | cpu_unregister_io_memory(s->ram_io_addr); |
2065 | 4b09be85 | aliguori | |
2066 | 4b09be85 | aliguori | qemu_free(s->queue); |
2067 | 4b09be85 | aliguori | |
2068 | 4b09be85 | aliguori | return 0; |
2069 | 4b09be85 | aliguori | } |
2070 | 4b09be85 | aliguori | |
2071 | 81a322d4 | Gerd Hoffmann | static int lsi_scsi_init(PCIDevice *dev) |
2072 | 7d8406be | pbrook | { |
2073 | f305261f | Juan Quintela | LSIState *s = DO_UPCAST(LSIState, dev, dev); |
2074 | deb54399 | aliguori | uint8_t *pci_conf; |
2075 | 7d8406be | pbrook | |
2076 | f305261f | Juan Quintela | pci_conf = s->dev.config; |
2077 | deb54399 | aliguori | |
2078 | 9167a69a | balrog | /* PCI Vendor ID (word) */
|
2079 | deb54399 | aliguori | pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_LSI_LOGIC); |
2080 | 9167a69a | balrog | /* PCI device ID (word) */
|
2081 | deb54399 | aliguori | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_LSI_53C895A); |
2082 | 9167a69a | balrog | /* PCI base class code */
|
2083 | 173a543b | blueswir1 | pci_config_set_class(pci_conf, PCI_CLASS_STORAGE_SCSI); |
2084 | 9167a69a | balrog | /* PCI subsystem ID */
|
2085 | deb54399 | aliguori | pci_conf[0x2e] = 0x00; |
2086 | deb54399 | aliguori | pci_conf[0x2f] = 0x10; |
2087 | 9167a69a | balrog | /* PCI latency timer = 255 */
|
2088 | deb54399 | aliguori | pci_conf[0x0d] = 0xff; |
2089 | 9167a69a | balrog | /* Interrupt pin 1 */
|
2090 | deb54399 | aliguori | pci_conf[0x3d] = 0x01; |
2091 | 7d8406be | pbrook | |
2092 | 1eed09cb | Avi Kivity | s->mmio_io_addr = cpu_register_io_memory(lsi_mmio_readfn, |
2093 | 7d8406be | pbrook | lsi_mmio_writefn, s); |
2094 | 1eed09cb | Avi Kivity | s->ram_io_addr = cpu_register_io_memory(lsi_ram_readfn, |
2095 | 7d8406be | pbrook | lsi_ram_writefn, s); |
2096 | 7d8406be | pbrook | |
2097 | 28c2c264 | Avi Kivity | pci_register_bar((struct PCIDevice *)s, 0, 256, |
2098 | 0392a017 | Isaku Yamahata | PCI_BASE_ADDRESS_SPACE_IO, lsi_io_mapfunc); |
2099 | 28c2c264 | Avi Kivity | pci_register_bar((struct PCIDevice *)s, 1, 0x400, |
2100 | 0392a017 | Isaku Yamahata | PCI_BASE_ADDRESS_SPACE_MEMORY, lsi_mmio_mapfunc); |
2101 | 28c2c264 | Avi Kivity | pci_register_bar((struct PCIDevice *)s, 2, 0x2000, |
2102 | 0392a017 | Isaku Yamahata | PCI_BASE_ADDRESS_SPACE_MEMORY, lsi_ram_mapfunc); |
2103 | a917d384 | pbrook | s->queue = qemu_malloc(sizeof(lsi_queue));
|
2104 | a917d384 | pbrook | s->queue_len = 1;
|
2105 | a917d384 | pbrook | s->active_commands = 0;
|
2106 | 7d8406be | pbrook | |
2107 | 7d8406be | pbrook | lsi_soft_reset(s); |
2108 | 7d8406be | pbrook | |
2109 | ca9c39fa | Gerd Hoffmann | scsi_bus_new(&s->bus, &dev->qdev, 1, LSI_MAX_DEVS, lsi_command_complete);
|
2110 | 5b684b5a | Gerd Hoffmann | if (!dev->qdev.hotplugged) {
|
2111 | 5b684b5a | Gerd Hoffmann | scsi_bus_legacy_handle_cmdline(&s->bus); |
2112 | 5b684b5a | Gerd Hoffmann | } |
2113 | 4a1b0f1c | Juan Quintela | vmstate_register(-1, &vmstate_lsi_scsi, s);
|
2114 | 81a322d4 | Gerd Hoffmann | return 0; |
2115 | 7d8406be | pbrook | } |
2116 | 9be5dafe | Paul Brook | |
2117 | 0aab0d3a | Gerd Hoffmann | static PCIDeviceInfo lsi_info = {
|
2118 | d52affa7 | Gerd Hoffmann | .qdev.name = "lsi53c895a",
|
2119 | d52affa7 | Gerd Hoffmann | .qdev.alias = "lsi",
|
2120 | d52affa7 | Gerd Hoffmann | .qdev.size = sizeof(LSIState),
|
2121 | d52affa7 | Gerd Hoffmann | .init = lsi_scsi_init, |
2122 | e3936fa5 | Gerd Hoffmann | .exit = lsi_scsi_uninit, |
2123 | 0aab0d3a | Gerd Hoffmann | }; |
2124 | 0aab0d3a | Gerd Hoffmann | |
2125 | 9be5dafe | Paul Brook | static void lsi53c895a_register_devices(void) |
2126 | 9be5dafe | Paul Brook | { |
2127 | 0aab0d3a | Gerd Hoffmann | pci_qdev_register(&lsi_info); |
2128 | 9be5dafe | Paul Brook | } |
2129 | 9be5dafe | Paul Brook | |
2130 | 9be5dafe | Paul Brook | device_init(lsi53c895a_register_devices); |