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