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