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