root / hw / cuda.c @ 44ae28f3
History | View | Annotate | Download (21.1 kB)
1 | 267002cd | bellard | /*
|
---|---|---|---|
2 | 3cbee15b | j_mayer | * QEMU PowerMac CUDA device support
|
3 | 5fafdf24 | ths | *
|
4 | 3cbee15b | j_mayer | * Copyright (c) 2004-2007 Fabrice Bellard
|
5 | 3cbee15b | j_mayer | * Copyright (c) 2007 Jocelyn Mayer
|
6 | 5fafdf24 | ths | *
|
7 | 267002cd | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | 267002cd | bellard | * of this software and associated documentation files (the "Software"), to deal
|
9 | 267002cd | bellard | * in the Software without restriction, including without limitation the rights
|
10 | 267002cd | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | 267002cd | bellard | * copies of the Software, and to permit persons to whom the Software is
|
12 | 267002cd | bellard | * furnished to do so, subject to the following conditions:
|
13 | 267002cd | bellard | *
|
14 | 267002cd | bellard | * The above copyright notice and this permission notice shall be included in
|
15 | 267002cd | bellard | * all copies or substantial portions of the Software.
|
16 | 267002cd | bellard | *
|
17 | 267002cd | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | 267002cd | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | 267002cd | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | 267002cd | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | 267002cd | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | 267002cd | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | 267002cd | bellard | * THE SOFTWARE.
|
24 | 267002cd | bellard | */
|
25 | 87ecb68b | pbrook | #include "hw.h" |
26 | 3cbee15b | j_mayer | #include "ppc_mac.h" |
27 | 87ecb68b | pbrook | #include "qemu-timer.h" |
28 | 87ecb68b | pbrook | #include "sysemu.h" |
29 | 267002cd | bellard | |
30 | 61271e5c | bellard | /* XXX: implement all timer modes */
|
31 | 61271e5c | bellard | |
32 | ea026b2f | blueswir1 | /* debug CUDA */
|
33 | 819e712b | bellard | //#define DEBUG_CUDA
|
34 | ea026b2f | blueswir1 | |
35 | ea026b2f | blueswir1 | /* debug CUDA packets */
|
36 | 819e712b | bellard | //#define DEBUG_CUDA_PACKET
|
37 | 819e712b | bellard | |
38 | ea026b2f | blueswir1 | #ifdef DEBUG_CUDA
|
39 | 001faf32 | Blue Swirl | #define CUDA_DPRINTF(fmt, ...) \
|
40 | 001faf32 | Blue Swirl | do { printf("CUDA: " fmt , ## __VA_ARGS__); } while (0) |
41 | ea026b2f | blueswir1 | #else
|
42 | 001faf32 | Blue Swirl | #define CUDA_DPRINTF(fmt, ...)
|
43 | ea026b2f | blueswir1 | #endif
|
44 | ea026b2f | blueswir1 | |
45 | 267002cd | bellard | /* Bits in B data register: all active low */
|
46 | 267002cd | bellard | #define TREQ 0x08 /* Transfer request (input) */ |
47 | 267002cd | bellard | #define TACK 0x10 /* Transfer acknowledge (output) */ |
48 | 267002cd | bellard | #define TIP 0x20 /* Transfer in progress (output) */ |
49 | 267002cd | bellard | |
50 | 267002cd | bellard | /* Bits in ACR */
|
51 | 267002cd | bellard | #define SR_CTRL 0x1c /* Shift register control bits */ |
52 | 267002cd | bellard | #define SR_EXT 0x0c /* Shift on external clock */ |
53 | 267002cd | bellard | #define SR_OUT 0x10 /* Shift out if 1 */ |
54 | 267002cd | bellard | |
55 | 267002cd | bellard | /* Bits in IFR and IER */
|
56 | 267002cd | bellard | #define IER_SET 0x80 /* set bits in IER */ |
57 | 267002cd | bellard | #define IER_CLR 0 /* clear bits in IER */ |
58 | 267002cd | bellard | #define SR_INT 0x04 /* Shift register full/empty */ |
59 | 267002cd | bellard | #define T1_INT 0x40 /* Timer 1 interrupt */ |
60 | 61271e5c | bellard | #define T2_INT 0x20 /* Timer 2 interrupt */ |
61 | 267002cd | bellard | |
62 | 267002cd | bellard | /* Bits in ACR */
|
63 | 267002cd | bellard | #define T1MODE 0xc0 /* Timer 1 mode */ |
64 | 267002cd | bellard | #define T1MODE_CONT 0x40 /* continuous interrupts */ |
65 | 267002cd | bellard | |
66 | 267002cd | bellard | /* commands (1st byte) */
|
67 | 267002cd | bellard | #define ADB_PACKET 0 |
68 | 267002cd | bellard | #define CUDA_PACKET 1 |
69 | 267002cd | bellard | #define ERROR_PACKET 2 |
70 | 267002cd | bellard | #define TIMER_PACKET 3 |
71 | 267002cd | bellard | #define POWER_PACKET 4 |
72 | 267002cd | bellard | #define MACIIC_PACKET 5 |
73 | 267002cd | bellard | #define PMU_PACKET 6 |
74 | 267002cd | bellard | |
75 | 267002cd | bellard | |
76 | 267002cd | bellard | /* CUDA commands (2nd byte) */
|
77 | 267002cd | bellard | #define CUDA_WARM_START 0x0 |
78 | 267002cd | bellard | #define CUDA_AUTOPOLL 0x1 |
79 | 267002cd | bellard | #define CUDA_GET_6805_ADDR 0x2 |
80 | 267002cd | bellard | #define CUDA_GET_TIME 0x3 |
81 | 267002cd | bellard | #define CUDA_GET_PRAM 0x7 |
82 | 267002cd | bellard | #define CUDA_SET_6805_ADDR 0x8 |
83 | 267002cd | bellard | #define CUDA_SET_TIME 0x9 |
84 | 267002cd | bellard | #define CUDA_POWERDOWN 0xa |
85 | 267002cd | bellard | #define CUDA_POWERUP_TIME 0xb |
86 | 267002cd | bellard | #define CUDA_SET_PRAM 0xc |
87 | 267002cd | bellard | #define CUDA_MS_RESET 0xd |
88 | 267002cd | bellard | #define CUDA_SEND_DFAC 0xe |
89 | 267002cd | bellard | #define CUDA_BATTERY_SWAP_SENSE 0x10 |
90 | 267002cd | bellard | #define CUDA_RESET_SYSTEM 0x11 |
91 | 267002cd | bellard | #define CUDA_SET_IPL 0x12 |
92 | 267002cd | bellard | #define CUDA_FILE_SERVER_FLAG 0x13 |
93 | 267002cd | bellard | #define CUDA_SET_AUTO_RATE 0x14 |
94 | 267002cd | bellard | #define CUDA_GET_AUTO_RATE 0x16 |
95 | 267002cd | bellard | #define CUDA_SET_DEVICE_LIST 0x19 |
96 | 267002cd | bellard | #define CUDA_GET_DEVICE_LIST 0x1a |
97 | 267002cd | bellard | #define CUDA_SET_ONE_SECOND_MODE 0x1b |
98 | 267002cd | bellard | #define CUDA_SET_POWER_MESSAGES 0x21 |
99 | 267002cd | bellard | #define CUDA_GET_SET_IIC 0x22 |
100 | 267002cd | bellard | #define CUDA_WAKEUP 0x23 |
101 | 267002cd | bellard | #define CUDA_TIMER_TICKLE 0x24 |
102 | 267002cd | bellard | #define CUDA_COMBINED_FORMAT_IIC 0x25 |
103 | 267002cd | bellard | |
104 | 267002cd | bellard | #define CUDA_TIMER_FREQ (4700000 / 6) |
105 | e2733d20 | bellard | #define CUDA_ADB_POLL_FREQ 50 |
106 | 267002cd | bellard | |
107 | d7ce296f | bellard | /* CUDA returns time_t's offset from Jan 1, 1904, not 1970 */
|
108 | d7ce296f | bellard | #define RTC_OFFSET 2082844800 |
109 | d7ce296f | bellard | |
110 | 267002cd | bellard | typedef struct CUDATimer { |
111 | 5fafdf24 | ths | int index;
|
112 | 61271e5c | bellard | uint16_t latch; |
113 | 267002cd | bellard | uint16_t counter_value; /* counter value at load time */
|
114 | 267002cd | bellard | int64_t load_time; |
115 | 267002cd | bellard | int64_t next_irq_time; |
116 | 267002cd | bellard | QEMUTimer *timer; |
117 | 267002cd | bellard | } CUDATimer; |
118 | 267002cd | bellard | |
119 | 267002cd | bellard | typedef struct CUDAState { |
120 | 267002cd | bellard | /* cuda registers */
|
121 | 267002cd | bellard | uint8_t b; /* B-side data */
|
122 | 267002cd | bellard | uint8_t a; /* A-side data */
|
123 | 267002cd | bellard | uint8_t dirb; /* B-side direction (1=output) */
|
124 | 267002cd | bellard | uint8_t dira; /* A-side direction (1=output) */
|
125 | 267002cd | bellard | uint8_t sr; /* Shift register */
|
126 | 267002cd | bellard | uint8_t acr; /* Auxiliary control register */
|
127 | 267002cd | bellard | uint8_t pcr; /* Peripheral control register */
|
128 | 267002cd | bellard | uint8_t ifr; /* Interrupt flag register */
|
129 | 267002cd | bellard | uint8_t ier; /* Interrupt enable register */
|
130 | 267002cd | bellard | uint8_t anh; /* A-side data, no handshake */
|
131 | 267002cd | bellard | |
132 | 267002cd | bellard | CUDATimer timers[2];
|
133 | 3b46e624 | ths | |
134 | 5703c174 | aurel32 | uint32_t tick_offset; |
135 | 5703c174 | aurel32 | |
136 | 267002cd | bellard | uint8_t last_b; /* last value of B register */
|
137 | 267002cd | bellard | uint8_t last_acr; /* last value of B register */
|
138 | 3b46e624 | ths | |
139 | 267002cd | bellard | int data_in_size;
|
140 | 267002cd | bellard | int data_in_index;
|
141 | 267002cd | bellard | int data_out_index;
|
142 | 267002cd | bellard | |
143 | d537cf6c | pbrook | qemu_irq irq; |
144 | 267002cd | bellard | uint8_t autopoll; |
145 | 267002cd | bellard | uint8_t data_in[128];
|
146 | 267002cd | bellard | uint8_t data_out[16];
|
147 | e2733d20 | bellard | QEMUTimer *adb_poll_timer; |
148 | 267002cd | bellard | } CUDAState; |
149 | 267002cd | bellard | |
150 | 267002cd | bellard | static CUDAState cuda_state;
|
151 | 267002cd | bellard | ADBBusState adb_bus; |
152 | 267002cd | bellard | |
153 | 267002cd | bellard | static void cuda_update(CUDAState *s); |
154 | 5fafdf24 | ths | static void cuda_receive_packet_from_host(CUDAState *s, |
155 | 267002cd | bellard | const uint8_t *data, int len); |
156 | 5fafdf24 | ths | static void cuda_timer_update(CUDAState *s, CUDATimer *ti, |
157 | 819e712b | bellard | int64_t current_time); |
158 | 267002cd | bellard | |
159 | 267002cd | bellard | static void cuda_update_irq(CUDAState *s) |
160 | 267002cd | bellard | { |
161 | 819e712b | bellard | if (s->ifr & s->ier & (SR_INT | T1_INT)) {
|
162 | d537cf6c | pbrook | qemu_irq_raise(s->irq); |
163 | 267002cd | bellard | } else {
|
164 | d537cf6c | pbrook | qemu_irq_lower(s->irq); |
165 | 267002cd | bellard | } |
166 | 267002cd | bellard | } |
167 | 267002cd | bellard | |
168 | 267002cd | bellard | static unsigned int get_counter(CUDATimer *s) |
169 | 267002cd | bellard | { |
170 | 267002cd | bellard | int64_t d; |
171 | 267002cd | bellard | unsigned int counter; |
172 | 267002cd | bellard | |
173 | 5fafdf24 | ths | d = muldiv64(qemu_get_clock(vm_clock) - s->load_time, |
174 | 6ee093c9 | Juan Quintela | CUDA_TIMER_FREQ, get_ticks_per_sec()); |
175 | 61271e5c | bellard | if (s->index == 0) { |
176 | 61271e5c | bellard | /* the timer goes down from latch to -1 (period of latch + 2) */
|
177 | 61271e5c | bellard | if (d <= (s->counter_value + 1)) { |
178 | 61271e5c | bellard | counter = (s->counter_value - d) & 0xffff;
|
179 | 61271e5c | bellard | } else {
|
180 | 61271e5c | bellard | counter = (d - (s->counter_value + 1)) % (s->latch + 2); |
181 | 5fafdf24 | ths | counter = (s->latch - counter) & 0xffff;
|
182 | 61271e5c | bellard | } |
183 | 267002cd | bellard | } else {
|
184 | 61271e5c | bellard | counter = (s->counter_value - d) & 0xffff;
|
185 | 267002cd | bellard | } |
186 | 267002cd | bellard | return counter;
|
187 | 267002cd | bellard | } |
188 | 267002cd | bellard | |
189 | 819e712b | bellard | static void set_counter(CUDAState *s, CUDATimer *ti, unsigned int val) |
190 | 267002cd | bellard | { |
191 | ea026b2f | blueswir1 | CUDA_DPRINTF("T%d.counter=%d\n", 1 + (ti->timer == NULL), val); |
192 | 819e712b | bellard | ti->load_time = qemu_get_clock(vm_clock); |
193 | 819e712b | bellard | ti->counter_value = val; |
194 | 819e712b | bellard | cuda_timer_update(s, ti, ti->load_time); |
195 | 267002cd | bellard | } |
196 | 267002cd | bellard | |
197 | 267002cd | bellard | static int64_t get_next_irq_time(CUDATimer *s, int64_t current_time)
|
198 | 267002cd | bellard | { |
199 | 61271e5c | bellard | int64_t d, next_time; |
200 | 61271e5c | bellard | unsigned int counter; |
201 | 61271e5c | bellard | |
202 | 267002cd | bellard | /* current counter value */
|
203 | 5fafdf24 | ths | d = muldiv64(current_time - s->load_time, |
204 | 6ee093c9 | Juan Quintela | CUDA_TIMER_FREQ, get_ticks_per_sec()); |
205 | 61271e5c | bellard | /* the timer goes down from latch to -1 (period of latch + 2) */
|
206 | 61271e5c | bellard | if (d <= (s->counter_value + 1)) { |
207 | 61271e5c | bellard | counter = (s->counter_value - d) & 0xffff;
|
208 | 61271e5c | bellard | } else {
|
209 | 61271e5c | bellard | counter = (d - (s->counter_value + 1)) % (s->latch + 2); |
210 | 5fafdf24 | ths | counter = (s->latch - counter) & 0xffff;
|
211 | 61271e5c | bellard | } |
212 | 3b46e624 | ths | |
213 | 61271e5c | bellard | /* Note: we consider the irq is raised on 0 */
|
214 | 61271e5c | bellard | if (counter == 0xffff) { |
215 | 61271e5c | bellard | next_time = d + s->latch + 1;
|
216 | 61271e5c | bellard | } else if (counter == 0) { |
217 | 61271e5c | bellard | next_time = d + s->latch + 2;
|
218 | 61271e5c | bellard | } else {
|
219 | 61271e5c | bellard | next_time = d + counter; |
220 | 267002cd | bellard | } |
221 | ea026b2f | blueswir1 | CUDA_DPRINTF("latch=%d counter=%" PRId64 " delta_next=%" PRId64 "\n", |
222 | ea026b2f | blueswir1 | s->latch, d, next_time - d); |
223 | 6ee093c9 | Juan Quintela | next_time = muldiv64(next_time, get_ticks_per_sec(), CUDA_TIMER_FREQ) + |
224 | 267002cd | bellard | s->load_time; |
225 | 267002cd | bellard | if (next_time <= current_time)
|
226 | 267002cd | bellard | next_time = current_time + 1;
|
227 | 267002cd | bellard | return next_time;
|
228 | 267002cd | bellard | } |
229 | 267002cd | bellard | |
230 | 5fafdf24 | ths | static void cuda_timer_update(CUDAState *s, CUDATimer *ti, |
231 | 819e712b | bellard | int64_t current_time) |
232 | 819e712b | bellard | { |
233 | 819e712b | bellard | if (!ti->timer)
|
234 | 819e712b | bellard | return;
|
235 | 819e712b | bellard | if ((s->acr & T1MODE) != T1MODE_CONT) {
|
236 | 819e712b | bellard | qemu_del_timer(ti->timer); |
237 | 819e712b | bellard | } else {
|
238 | 819e712b | bellard | ti->next_irq_time = get_next_irq_time(ti, current_time); |
239 | 819e712b | bellard | qemu_mod_timer(ti->timer, ti->next_irq_time); |
240 | 819e712b | bellard | } |
241 | 819e712b | bellard | } |
242 | 819e712b | bellard | |
243 | 267002cd | bellard | static void cuda_timer1(void *opaque) |
244 | 267002cd | bellard | { |
245 | 267002cd | bellard | CUDAState *s = opaque; |
246 | 267002cd | bellard | CUDATimer *ti = &s->timers[0];
|
247 | 267002cd | bellard | |
248 | 819e712b | bellard | cuda_timer_update(s, ti, ti->next_irq_time); |
249 | 267002cd | bellard | s->ifr |= T1_INT; |
250 | 267002cd | bellard | cuda_update_irq(s); |
251 | 267002cd | bellard | } |
252 | 267002cd | bellard | |
253 | c227f099 | Anthony Liguori | static uint32_t cuda_readb(void *opaque, target_phys_addr_t addr) |
254 | 267002cd | bellard | { |
255 | 267002cd | bellard | CUDAState *s = opaque; |
256 | 267002cd | bellard | uint32_t val; |
257 | 267002cd | bellard | |
258 | 267002cd | bellard | addr = (addr >> 9) & 0xf; |
259 | 267002cd | bellard | switch(addr) {
|
260 | 267002cd | bellard | case 0: |
261 | 267002cd | bellard | val = s->b; |
262 | 267002cd | bellard | break;
|
263 | 267002cd | bellard | case 1: |
264 | 267002cd | bellard | val = s->a; |
265 | 267002cd | bellard | break;
|
266 | 267002cd | bellard | case 2: |
267 | 267002cd | bellard | val = s->dirb; |
268 | 267002cd | bellard | break;
|
269 | 267002cd | bellard | case 3: |
270 | 267002cd | bellard | val = s->dira; |
271 | 267002cd | bellard | break;
|
272 | 267002cd | bellard | case 4: |
273 | 267002cd | bellard | val = get_counter(&s->timers[0]) & 0xff; |
274 | 267002cd | bellard | s->ifr &= ~T1_INT; |
275 | 267002cd | bellard | cuda_update_irq(s); |
276 | 267002cd | bellard | break;
|
277 | 267002cd | bellard | case 5: |
278 | 267002cd | bellard | val = get_counter(&s->timers[0]) >> 8; |
279 | 267002cd | bellard | cuda_update_irq(s); |
280 | 267002cd | bellard | break;
|
281 | 267002cd | bellard | case 6: |
282 | 267002cd | bellard | val = s->timers[0].latch & 0xff; |
283 | 267002cd | bellard | break;
|
284 | 267002cd | bellard | case 7: |
285 | 61271e5c | bellard | /* XXX: check this */
|
286 | 267002cd | bellard | val = (s->timers[0].latch >> 8) & 0xff; |
287 | 267002cd | bellard | break;
|
288 | 267002cd | bellard | case 8: |
289 | 267002cd | bellard | val = get_counter(&s->timers[1]) & 0xff; |
290 | 61271e5c | bellard | s->ifr &= ~T2_INT; |
291 | 267002cd | bellard | break;
|
292 | 267002cd | bellard | case 9: |
293 | 267002cd | bellard | val = get_counter(&s->timers[1]) >> 8; |
294 | 267002cd | bellard | break;
|
295 | 267002cd | bellard | case 10: |
296 | 819e712b | bellard | val = s->sr; |
297 | 819e712b | bellard | s->ifr &= ~SR_INT; |
298 | 819e712b | bellard | cuda_update_irq(s); |
299 | 267002cd | bellard | break;
|
300 | 267002cd | bellard | case 11: |
301 | 267002cd | bellard | val = s->acr; |
302 | 267002cd | bellard | break;
|
303 | 267002cd | bellard | case 12: |
304 | 267002cd | bellard | val = s->pcr; |
305 | 267002cd | bellard | break;
|
306 | 267002cd | bellard | case 13: |
307 | 267002cd | bellard | val = s->ifr; |
308 | 5fafdf24 | ths | if (s->ifr & s->ier)
|
309 | b7c7b181 | bellard | val |= 0x80;
|
310 | 267002cd | bellard | break;
|
311 | 267002cd | bellard | case 14: |
312 | b7c7b181 | bellard | val = s->ier | 0x80;
|
313 | 267002cd | bellard | break;
|
314 | 267002cd | bellard | default:
|
315 | 267002cd | bellard | case 15: |
316 | 267002cd | bellard | val = s->anh; |
317 | 267002cd | bellard | break;
|
318 | 267002cd | bellard | } |
319 | 3c83eb4f | Blue Swirl | if (addr != 13 || val != 0) { |
320 | ea026b2f | blueswir1 | CUDA_DPRINTF("read: reg=0x%x val=%02x\n", (int)addr, val); |
321 | 3c83eb4f | Blue Swirl | } |
322 | 3c83eb4f | Blue Swirl | |
323 | 267002cd | bellard | return val;
|
324 | 267002cd | bellard | } |
325 | 267002cd | bellard | |
326 | c227f099 | Anthony Liguori | static void cuda_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
327 | 267002cd | bellard | { |
328 | 267002cd | bellard | CUDAState *s = opaque; |
329 | 3b46e624 | ths | |
330 | 267002cd | bellard | addr = (addr >> 9) & 0xf; |
331 | ea026b2f | blueswir1 | CUDA_DPRINTF("write: reg=0x%x val=%02x\n", (int)addr, val); |
332 | 267002cd | bellard | |
333 | 267002cd | bellard | switch(addr) {
|
334 | 267002cd | bellard | case 0: |
335 | 267002cd | bellard | s->b = val; |
336 | 267002cd | bellard | cuda_update(s); |
337 | 267002cd | bellard | break;
|
338 | 267002cd | bellard | case 1: |
339 | 267002cd | bellard | s->a = val; |
340 | 267002cd | bellard | break;
|
341 | 267002cd | bellard | case 2: |
342 | 267002cd | bellard | s->dirb = val; |
343 | 267002cd | bellard | break;
|
344 | 267002cd | bellard | case 3: |
345 | 267002cd | bellard | s->dira = val; |
346 | 267002cd | bellard | break;
|
347 | 267002cd | bellard | case 4: |
348 | 61271e5c | bellard | s->timers[0].latch = (s->timers[0].latch & 0xff00) | val; |
349 | 61271e5c | bellard | cuda_timer_update(s, &s->timers[0], qemu_get_clock(vm_clock));
|
350 | 267002cd | bellard | break;
|
351 | 267002cd | bellard | case 5: |
352 | 61271e5c | bellard | s->timers[0].latch = (s->timers[0].latch & 0xff) | (val << 8); |
353 | 61271e5c | bellard | s->ifr &= ~T1_INT; |
354 | 61271e5c | bellard | set_counter(s, &s->timers[0], s->timers[0].latch); |
355 | 267002cd | bellard | break;
|
356 | 267002cd | bellard | case 6: |
357 | 267002cd | bellard | s->timers[0].latch = (s->timers[0].latch & 0xff00) | val; |
358 | 819e712b | bellard | cuda_timer_update(s, &s->timers[0], qemu_get_clock(vm_clock));
|
359 | 267002cd | bellard | break;
|
360 | 267002cd | bellard | case 7: |
361 | 267002cd | bellard | s->timers[0].latch = (s->timers[0].latch & 0xff) | (val << 8); |
362 | 61271e5c | bellard | s->ifr &= ~T1_INT; |
363 | 819e712b | bellard | cuda_timer_update(s, &s->timers[0], qemu_get_clock(vm_clock));
|
364 | 267002cd | bellard | break;
|
365 | 267002cd | bellard | case 8: |
366 | 61271e5c | bellard | s->timers[1].latch = val;
|
367 | 819e712b | bellard | set_counter(s, &s->timers[1], val);
|
368 | 267002cd | bellard | break;
|
369 | 267002cd | bellard | case 9: |
370 | 61271e5c | bellard | set_counter(s, &s->timers[1], (val << 8) | s->timers[1].latch); |
371 | 267002cd | bellard | break;
|
372 | 267002cd | bellard | case 10: |
373 | 267002cd | bellard | s->sr = val; |
374 | 267002cd | bellard | break;
|
375 | 267002cd | bellard | case 11: |
376 | 267002cd | bellard | s->acr = val; |
377 | 819e712b | bellard | cuda_timer_update(s, &s->timers[0], qemu_get_clock(vm_clock));
|
378 | 267002cd | bellard | cuda_update(s); |
379 | 267002cd | bellard | break;
|
380 | 267002cd | bellard | case 12: |
381 | 267002cd | bellard | s->pcr = val; |
382 | 267002cd | bellard | break;
|
383 | 267002cd | bellard | case 13: |
384 | 267002cd | bellard | /* reset bits */
|
385 | 267002cd | bellard | s->ifr &= ~val; |
386 | 267002cd | bellard | cuda_update_irq(s); |
387 | 267002cd | bellard | break;
|
388 | 267002cd | bellard | case 14: |
389 | 267002cd | bellard | if (val & IER_SET) {
|
390 | 267002cd | bellard | /* set bits */
|
391 | 267002cd | bellard | s->ier |= val & 0x7f;
|
392 | 267002cd | bellard | } else {
|
393 | 267002cd | bellard | /* reset bits */
|
394 | 267002cd | bellard | s->ier &= ~val; |
395 | 267002cd | bellard | } |
396 | 267002cd | bellard | cuda_update_irq(s); |
397 | 267002cd | bellard | break;
|
398 | 267002cd | bellard | default:
|
399 | 267002cd | bellard | case 15: |
400 | 267002cd | bellard | s->anh = val; |
401 | 267002cd | bellard | break;
|
402 | 267002cd | bellard | } |
403 | 267002cd | bellard | } |
404 | 267002cd | bellard | |
405 | 267002cd | bellard | /* NOTE: TIP and TREQ are negated */
|
406 | 267002cd | bellard | static void cuda_update(CUDAState *s) |
407 | 267002cd | bellard | { |
408 | 819e712b | bellard | int packet_received, len;
|
409 | 819e712b | bellard | |
410 | 819e712b | bellard | packet_received = 0;
|
411 | 819e712b | bellard | if (!(s->b & TIP)) {
|
412 | 819e712b | bellard | /* transfer requested from host */
|
413 | 267002cd | bellard | |
414 | 819e712b | bellard | if (s->acr & SR_OUT) {
|
415 | 819e712b | bellard | /* data output */
|
416 | 819e712b | bellard | if ((s->b & (TACK | TIP)) != (s->last_b & (TACK | TIP))) {
|
417 | 819e712b | bellard | if (s->data_out_index < sizeof(s->data_out)) { |
418 | ea026b2f | blueswir1 | CUDA_DPRINTF("send: %02x\n", s->sr);
|
419 | 819e712b | bellard | s->data_out[s->data_out_index++] = s->sr; |
420 | 819e712b | bellard | s->ifr |= SR_INT; |
421 | 819e712b | bellard | cuda_update_irq(s); |
422 | 819e712b | bellard | } |
423 | 819e712b | bellard | } |
424 | 819e712b | bellard | } else {
|
425 | 819e712b | bellard | if (s->data_in_index < s->data_in_size) {
|
426 | 819e712b | bellard | /* data input */
|
427 | 819e712b | bellard | if ((s->b & (TACK | TIP)) != (s->last_b & (TACK | TIP))) {
|
428 | 819e712b | bellard | s->sr = s->data_in[s->data_in_index++]; |
429 | ea026b2f | blueswir1 | CUDA_DPRINTF("recv: %02x\n", s->sr);
|
430 | 819e712b | bellard | /* indicate end of transfer */
|
431 | 819e712b | bellard | if (s->data_in_index >= s->data_in_size) {
|
432 | 819e712b | bellard | s->b = (s->b | TREQ); |
433 | 819e712b | bellard | } |
434 | 819e712b | bellard | s->ifr |= SR_INT; |
435 | 819e712b | bellard | cuda_update_irq(s); |
436 | 819e712b | bellard | } |
437 | 267002cd | bellard | } |
438 | 819e712b | bellard | } |
439 | 819e712b | bellard | } else {
|
440 | 819e712b | bellard | /* no transfer requested: handle sync case */
|
441 | 819e712b | bellard | if ((s->last_b & TIP) && (s->b & TACK) != (s->last_b & TACK)) {
|
442 | 819e712b | bellard | /* update TREQ state each time TACK change state */
|
443 | 819e712b | bellard | if (s->b & TACK)
|
444 | 819e712b | bellard | s->b = (s->b | TREQ); |
445 | 819e712b | bellard | else
|
446 | 819e712b | bellard | s->b = (s->b & ~TREQ); |
447 | 267002cd | bellard | s->ifr |= SR_INT; |
448 | 267002cd | bellard | cuda_update_irq(s); |
449 | 819e712b | bellard | } else {
|
450 | 819e712b | bellard | if (!(s->last_b & TIP)) {
|
451 | e91c8a77 | ths | /* handle end of host to cuda transfer */
|
452 | 819e712b | bellard | packet_received = (s->data_out_index > 0);
|
453 | e91c8a77 | ths | /* always an IRQ at the end of transfer */
|
454 | 819e712b | bellard | s->ifr |= SR_INT; |
455 | 819e712b | bellard | cuda_update_irq(s); |
456 | 819e712b | bellard | } |
457 | 819e712b | bellard | /* signal if there is data to read */
|
458 | 819e712b | bellard | if (s->data_in_index < s->data_in_size) {
|
459 | 819e712b | bellard | s->b = (s->b & ~TREQ); |
460 | 819e712b | bellard | } |
461 | 267002cd | bellard | } |
462 | 267002cd | bellard | } |
463 | 267002cd | bellard | |
464 | 267002cd | bellard | s->last_acr = s->acr; |
465 | 267002cd | bellard | s->last_b = s->b; |
466 | 819e712b | bellard | |
467 | 819e712b | bellard | /* NOTE: cuda_receive_packet_from_host() can call cuda_update()
|
468 | 819e712b | bellard | recursively */
|
469 | 819e712b | bellard | if (packet_received) {
|
470 | 819e712b | bellard | len = s->data_out_index; |
471 | 819e712b | bellard | s->data_out_index = 0;
|
472 | 819e712b | bellard | cuda_receive_packet_from_host(s, s->data_out, len); |
473 | 819e712b | bellard | } |
474 | 267002cd | bellard | } |
475 | 267002cd | bellard | |
476 | 5fafdf24 | ths | static void cuda_send_packet_to_host(CUDAState *s, |
477 | 267002cd | bellard | const uint8_t *data, int len) |
478 | 267002cd | bellard | { |
479 | 819e712b | bellard | #ifdef DEBUG_CUDA_PACKET
|
480 | 819e712b | bellard | { |
481 | 819e712b | bellard | int i;
|
482 | 819e712b | bellard | printf("cuda_send_packet_to_host:\n");
|
483 | 819e712b | bellard | for(i = 0; i < len; i++) |
484 | 819e712b | bellard | printf(" %02x", data[i]);
|
485 | 819e712b | bellard | printf("\n");
|
486 | 819e712b | bellard | } |
487 | 819e712b | bellard | #endif
|
488 | 267002cd | bellard | memcpy(s->data_in, data, len); |
489 | 267002cd | bellard | s->data_in_size = len; |
490 | 267002cd | bellard | s->data_in_index = 0;
|
491 | 267002cd | bellard | cuda_update(s); |
492 | 267002cd | bellard | s->ifr |= SR_INT; |
493 | 267002cd | bellard | cuda_update_irq(s); |
494 | 267002cd | bellard | } |
495 | 267002cd | bellard | |
496 | 7db4eea6 | bellard | static void cuda_adb_poll(void *opaque) |
497 | e2733d20 | bellard | { |
498 | e2733d20 | bellard | CUDAState *s = opaque; |
499 | e2733d20 | bellard | uint8_t obuf[ADB_MAX_OUT_LEN + 2];
|
500 | e2733d20 | bellard | int olen;
|
501 | e2733d20 | bellard | |
502 | e2733d20 | bellard | olen = adb_poll(&adb_bus, obuf + 2);
|
503 | e2733d20 | bellard | if (olen > 0) { |
504 | e2733d20 | bellard | obuf[0] = ADB_PACKET;
|
505 | e2733d20 | bellard | obuf[1] = 0x40; /* polled data */ |
506 | e2733d20 | bellard | cuda_send_packet_to_host(s, obuf, olen + 2);
|
507 | e2733d20 | bellard | } |
508 | 5fafdf24 | ths | qemu_mod_timer(s->adb_poll_timer, |
509 | 5fafdf24 | ths | qemu_get_clock(vm_clock) + |
510 | 6ee093c9 | Juan Quintela | (get_ticks_per_sec() / CUDA_ADB_POLL_FREQ)); |
511 | e2733d20 | bellard | } |
512 | e2733d20 | bellard | |
513 | 5fafdf24 | ths | static void cuda_receive_packet(CUDAState *s, |
514 | 267002cd | bellard | const uint8_t *data, int len) |
515 | 267002cd | bellard | { |
516 | 267002cd | bellard | uint8_t obuf[16];
|
517 | 5703c174 | aurel32 | int autopoll;
|
518 | 5703c174 | aurel32 | uint32_t ti; |
519 | 267002cd | bellard | |
520 | 267002cd | bellard | switch(data[0]) { |
521 | 267002cd | bellard | case CUDA_AUTOPOLL:
|
522 | e2733d20 | bellard | autopoll = (data[1] != 0); |
523 | e2733d20 | bellard | if (autopoll != s->autopoll) {
|
524 | e2733d20 | bellard | s->autopoll = autopoll; |
525 | e2733d20 | bellard | if (autopoll) {
|
526 | 5fafdf24 | ths | qemu_mod_timer(s->adb_poll_timer, |
527 | 5fafdf24 | ths | qemu_get_clock(vm_clock) + |
528 | 6ee093c9 | Juan Quintela | (get_ticks_per_sec() / CUDA_ADB_POLL_FREQ)); |
529 | e2733d20 | bellard | } else {
|
530 | e2733d20 | bellard | qemu_del_timer(s->adb_poll_timer); |
531 | e2733d20 | bellard | } |
532 | e2733d20 | bellard | } |
533 | 267002cd | bellard | obuf[0] = CUDA_PACKET;
|
534 | 267002cd | bellard | obuf[1] = data[1]; |
535 | 267002cd | bellard | cuda_send_packet_to_host(s, obuf, 2);
|
536 | 267002cd | bellard | break;
|
537 | dccfafc4 | bellard | case CUDA_SET_TIME:
|
538 | 5703c174 | aurel32 | ti = (((uint32_t)data[1]) << 24) + (((uint32_t)data[2]) << 16) + (((uint32_t)data[3]) << 8) + data[4]; |
539 | 6ee093c9 | Juan Quintela | s->tick_offset = ti - (qemu_get_clock(vm_clock) / get_ticks_per_sec()); |
540 | 5703c174 | aurel32 | obuf[0] = CUDA_PACKET;
|
541 | 5703c174 | aurel32 | obuf[1] = 0; |
542 | 5703c174 | aurel32 | obuf[2] = 0; |
543 | 5703c174 | aurel32 | cuda_send_packet_to_host(s, obuf, 3);
|
544 | 5703c174 | aurel32 | break;
|
545 | 5703c174 | aurel32 | case CUDA_GET_TIME:
|
546 | 6ee093c9 | Juan Quintela | ti = s->tick_offset + (qemu_get_clock(vm_clock) / get_ticks_per_sec()); |
547 | 267002cd | bellard | obuf[0] = CUDA_PACKET;
|
548 | 267002cd | bellard | obuf[1] = 0; |
549 | 267002cd | bellard | obuf[2] = 0; |
550 | 267002cd | bellard | obuf[3] = ti >> 24; |
551 | 267002cd | bellard | obuf[4] = ti >> 16; |
552 | 267002cd | bellard | obuf[5] = ti >> 8; |
553 | 267002cd | bellard | obuf[6] = ti;
|
554 | 267002cd | bellard | cuda_send_packet_to_host(s, obuf, 7);
|
555 | 267002cd | bellard | break;
|
556 | 267002cd | bellard | case CUDA_FILE_SERVER_FLAG:
|
557 | 267002cd | bellard | case CUDA_SET_DEVICE_LIST:
|
558 | 267002cd | bellard | case CUDA_SET_AUTO_RATE:
|
559 | 267002cd | bellard | case CUDA_SET_POWER_MESSAGES:
|
560 | 267002cd | bellard | obuf[0] = CUDA_PACKET;
|
561 | 267002cd | bellard | obuf[1] = 0; |
562 | 267002cd | bellard | cuda_send_packet_to_host(s, obuf, 2);
|
563 | 267002cd | bellard | break;
|
564 | d7ce296f | bellard | case CUDA_POWERDOWN:
|
565 | d7ce296f | bellard | obuf[0] = CUDA_PACKET;
|
566 | d7ce296f | bellard | obuf[1] = 0; |
567 | d7ce296f | bellard | cuda_send_packet_to_host(s, obuf, 2);
|
568 | c76ee25d | aurel32 | qemu_system_shutdown_request(); |
569 | c76ee25d | aurel32 | break;
|
570 | 0686970f | j_mayer | case CUDA_RESET_SYSTEM:
|
571 | 0686970f | j_mayer | obuf[0] = CUDA_PACKET;
|
572 | 0686970f | j_mayer | obuf[1] = 0; |
573 | 0686970f | j_mayer | cuda_send_packet_to_host(s, obuf, 2);
|
574 | 0686970f | j_mayer | qemu_system_reset_request(); |
575 | 0686970f | j_mayer | break;
|
576 | 267002cd | bellard | default:
|
577 | 267002cd | bellard | break;
|
578 | 267002cd | bellard | } |
579 | 267002cd | bellard | } |
580 | 267002cd | bellard | |
581 | 5fafdf24 | ths | static void cuda_receive_packet_from_host(CUDAState *s, |
582 | 267002cd | bellard | const uint8_t *data, int len) |
583 | 267002cd | bellard | { |
584 | 819e712b | bellard | #ifdef DEBUG_CUDA_PACKET
|
585 | 819e712b | bellard | { |
586 | 819e712b | bellard | int i;
|
587 | cadae95f | bellard | printf("cuda_receive_packet_from_host:\n");
|
588 | 819e712b | bellard | for(i = 0; i < len; i++) |
589 | 819e712b | bellard | printf(" %02x", data[i]);
|
590 | 819e712b | bellard | printf("\n");
|
591 | 819e712b | bellard | } |
592 | 819e712b | bellard | #endif
|
593 | 267002cd | bellard | switch(data[0]) { |
594 | 267002cd | bellard | case ADB_PACKET:
|
595 | e2733d20 | bellard | { |
596 | e2733d20 | bellard | uint8_t obuf[ADB_MAX_OUT_LEN + 2];
|
597 | e2733d20 | bellard | int olen;
|
598 | e2733d20 | bellard | olen = adb_request(&adb_bus, obuf + 2, data + 1, len - 1); |
599 | 38f0b147 | bellard | if (olen > 0) { |
600 | e2733d20 | bellard | obuf[0] = ADB_PACKET;
|
601 | e2733d20 | bellard | obuf[1] = 0x00; |
602 | e2733d20 | bellard | } else {
|
603 | 38f0b147 | bellard | /* error */
|
604 | e2733d20 | bellard | obuf[0] = ADB_PACKET;
|
605 | 38f0b147 | bellard | obuf[1] = -olen;
|
606 | 38f0b147 | bellard | olen = 0;
|
607 | e2733d20 | bellard | } |
608 | e2733d20 | bellard | cuda_send_packet_to_host(s, obuf, olen + 2);
|
609 | e2733d20 | bellard | } |
610 | 267002cd | bellard | break;
|
611 | 267002cd | bellard | case CUDA_PACKET:
|
612 | 267002cd | bellard | cuda_receive_packet(s, data + 1, len - 1); |
613 | 267002cd | bellard | break;
|
614 | 267002cd | bellard | } |
615 | 267002cd | bellard | } |
616 | 267002cd | bellard | |
617 | c227f099 | Anthony Liguori | static void cuda_writew (void *opaque, target_phys_addr_t addr, uint32_t value) |
618 | 267002cd | bellard | { |
619 | 267002cd | bellard | } |
620 | 267002cd | bellard | |
621 | c227f099 | Anthony Liguori | static void cuda_writel (void *opaque, target_phys_addr_t addr, uint32_t value) |
622 | 267002cd | bellard | { |
623 | 267002cd | bellard | } |
624 | 267002cd | bellard | |
625 | c227f099 | Anthony Liguori | static uint32_t cuda_readw (void *opaque, target_phys_addr_t addr) |
626 | 267002cd | bellard | { |
627 | 267002cd | bellard | return 0; |
628 | 267002cd | bellard | } |
629 | 267002cd | bellard | |
630 | c227f099 | Anthony Liguori | static uint32_t cuda_readl (void *opaque, target_phys_addr_t addr) |
631 | 267002cd | bellard | { |
632 | 267002cd | bellard | return 0; |
633 | 267002cd | bellard | } |
634 | 267002cd | bellard | |
635 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const cuda_write[] = { |
636 | 267002cd | bellard | &cuda_writeb, |
637 | 267002cd | bellard | &cuda_writew, |
638 | 267002cd | bellard | &cuda_writel, |
639 | 267002cd | bellard | }; |
640 | 267002cd | bellard | |
641 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const cuda_read[] = { |
642 | 267002cd | bellard | &cuda_readb, |
643 | 267002cd | bellard | &cuda_readw, |
644 | 267002cd | bellard | &cuda_readl, |
645 | 267002cd | bellard | }; |
646 | 267002cd | bellard | |
647 | 9b64997f | blueswir1 | static void cuda_save_timer(QEMUFile *f, CUDATimer *s) |
648 | 9b64997f | blueswir1 | { |
649 | 9b64997f | blueswir1 | qemu_put_be16s(f, &s->latch); |
650 | 9b64997f | blueswir1 | qemu_put_be16s(f, &s->counter_value); |
651 | 9b64997f | blueswir1 | qemu_put_sbe64s(f, &s->load_time); |
652 | 9b64997f | blueswir1 | qemu_put_sbe64s(f, &s->next_irq_time); |
653 | 9b64997f | blueswir1 | if (s->timer)
|
654 | 9b64997f | blueswir1 | qemu_put_timer(f, s->timer); |
655 | 9b64997f | blueswir1 | } |
656 | 9b64997f | blueswir1 | |
657 | 9b64997f | blueswir1 | static void cuda_save(QEMUFile *f, void *opaque) |
658 | 9b64997f | blueswir1 | { |
659 | 9b64997f | blueswir1 | CUDAState *s = (CUDAState *)opaque; |
660 | 9b64997f | blueswir1 | |
661 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->b); |
662 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->a); |
663 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->dirb); |
664 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->dira); |
665 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->sr); |
666 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->acr); |
667 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->pcr); |
668 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->ifr); |
669 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->ier); |
670 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->anh); |
671 | 9b64997f | blueswir1 | qemu_put_sbe32s(f, &s->data_in_size); |
672 | 9b64997f | blueswir1 | qemu_put_sbe32s(f, &s->data_in_index); |
673 | 9b64997f | blueswir1 | qemu_put_sbe32s(f, &s->data_out_index); |
674 | 9b64997f | blueswir1 | qemu_put_ubyte(f, s->autopoll); |
675 | 9b64997f | blueswir1 | qemu_put_buffer(f, s->data_in, sizeof(s->data_in));
|
676 | 9b64997f | blueswir1 | qemu_put_buffer(f, s->data_out, sizeof(s->data_out));
|
677 | 5703c174 | aurel32 | qemu_put_be32s(f, &s->tick_offset); |
678 | 9b64997f | blueswir1 | cuda_save_timer(f, &s->timers[0]);
|
679 | 9b64997f | blueswir1 | cuda_save_timer(f, &s->timers[1]);
|
680 | 9b64997f | blueswir1 | } |
681 | 9b64997f | blueswir1 | |
682 | 9b64997f | blueswir1 | static void cuda_load_timer(QEMUFile *f, CUDATimer *s) |
683 | 9b64997f | blueswir1 | { |
684 | 9b64997f | blueswir1 | qemu_get_be16s(f, &s->latch); |
685 | 9b64997f | blueswir1 | qemu_get_be16s(f, &s->counter_value); |
686 | 9b64997f | blueswir1 | qemu_get_sbe64s(f, &s->load_time); |
687 | 9b64997f | blueswir1 | qemu_get_sbe64s(f, &s->next_irq_time); |
688 | 9b64997f | blueswir1 | if (s->timer)
|
689 | 9b64997f | blueswir1 | qemu_get_timer(f, s->timer); |
690 | 9b64997f | blueswir1 | } |
691 | 9b64997f | blueswir1 | |
692 | 9b64997f | blueswir1 | static int cuda_load(QEMUFile *f, void *opaque, int version_id) |
693 | 9b64997f | blueswir1 | { |
694 | 9b64997f | blueswir1 | CUDAState *s = (CUDAState *)opaque; |
695 | 9b64997f | blueswir1 | |
696 | 9b64997f | blueswir1 | if (version_id != 1) |
697 | 9b64997f | blueswir1 | return -EINVAL;
|
698 | 9b64997f | blueswir1 | |
699 | 9b64997f | blueswir1 | s->b = qemu_get_ubyte(f); |
700 | 9b64997f | blueswir1 | s->a = qemu_get_ubyte(f); |
701 | 9b64997f | blueswir1 | s->dirb = qemu_get_ubyte(f); |
702 | 9b64997f | blueswir1 | s->dira = qemu_get_ubyte(f); |
703 | 9b64997f | blueswir1 | s->sr = qemu_get_ubyte(f); |
704 | 9b64997f | blueswir1 | s->acr = qemu_get_ubyte(f); |
705 | 9b64997f | blueswir1 | s->pcr = qemu_get_ubyte(f); |
706 | 9b64997f | blueswir1 | s->ifr = qemu_get_ubyte(f); |
707 | 9b64997f | blueswir1 | s->ier = qemu_get_ubyte(f); |
708 | 9b64997f | blueswir1 | s->anh = qemu_get_ubyte(f); |
709 | 9b64997f | blueswir1 | qemu_get_sbe32s(f, &s->data_in_size); |
710 | 9b64997f | blueswir1 | qemu_get_sbe32s(f, &s->data_in_index); |
711 | 9b64997f | blueswir1 | qemu_get_sbe32s(f, &s->data_out_index); |
712 | 9b64997f | blueswir1 | s->autopoll = qemu_get_ubyte(f); |
713 | 9b64997f | blueswir1 | qemu_get_buffer(f, s->data_in, sizeof(s->data_in));
|
714 | 9b64997f | blueswir1 | qemu_get_buffer(f, s->data_out, sizeof(s->data_out));
|
715 | 5703c174 | aurel32 | qemu_get_be32s(f, &s->tick_offset); |
716 | 9b64997f | blueswir1 | cuda_load_timer(f, &s->timers[0]);
|
717 | 9b64997f | blueswir1 | cuda_load_timer(f, &s->timers[1]);
|
718 | 9b64997f | blueswir1 | |
719 | 9b64997f | blueswir1 | return 0; |
720 | 9b64997f | blueswir1 | } |
721 | 9b64997f | blueswir1 | |
722 | 6e6b7363 | blueswir1 | static void cuda_reset(void *opaque) |
723 | 6e6b7363 | blueswir1 | { |
724 | 6e6b7363 | blueswir1 | CUDAState *s = opaque; |
725 | 6e6b7363 | blueswir1 | |
726 | 6e6b7363 | blueswir1 | s->b = 0;
|
727 | 6e6b7363 | blueswir1 | s->a = 0;
|
728 | 6e6b7363 | blueswir1 | s->dirb = 0;
|
729 | 6e6b7363 | blueswir1 | s->dira = 0;
|
730 | 6e6b7363 | blueswir1 | s->sr = 0;
|
731 | 6e6b7363 | blueswir1 | s->acr = 0;
|
732 | 6e6b7363 | blueswir1 | s->pcr = 0;
|
733 | 6e6b7363 | blueswir1 | s->ifr = 0;
|
734 | 6e6b7363 | blueswir1 | s->ier = 0;
|
735 | 6e6b7363 | blueswir1 | // s->ier = T1_INT | SR_INT;
|
736 | 6e6b7363 | blueswir1 | s->anh = 0;
|
737 | 6e6b7363 | blueswir1 | s->data_in_size = 0;
|
738 | 6e6b7363 | blueswir1 | s->data_in_index = 0;
|
739 | 6e6b7363 | blueswir1 | s->data_out_index = 0;
|
740 | 6e6b7363 | blueswir1 | s->autopoll = 0;
|
741 | 6e6b7363 | blueswir1 | |
742 | 6e6b7363 | blueswir1 | s->timers[0].latch = 0xffff; |
743 | 6e6b7363 | blueswir1 | set_counter(s, &s->timers[0], 0xffff); |
744 | 6e6b7363 | blueswir1 | |
745 | 6e6b7363 | blueswir1 | s->timers[1].latch = 0; |
746 | 6e6b7363 | blueswir1 | set_counter(s, &s->timers[1], 0xffff); |
747 | 6e6b7363 | blueswir1 | } |
748 | 6e6b7363 | blueswir1 | |
749 | 3cbee15b | j_mayer | void cuda_init (int *cuda_mem_index, qemu_irq irq) |
750 | 267002cd | bellard | { |
751 | 5703c174 | aurel32 | struct tm tm;
|
752 | 267002cd | bellard | CUDAState *s = &cuda_state; |
753 | 267002cd | bellard | |
754 | 819e712b | bellard | s->irq = irq; |
755 | 819e712b | bellard | |
756 | 61271e5c | bellard | s->timers[0].index = 0; |
757 | 267002cd | bellard | s->timers[0].timer = qemu_new_timer(vm_clock, cuda_timer1, s);
|
758 | 61271e5c | bellard | |
759 | 61271e5c | bellard | s->timers[1].index = 1; |
760 | e2733d20 | bellard | |
761 | 9c554c1c | aurel32 | qemu_get_timedate(&tm, 0);
|
762 | 9c554c1c | aurel32 | s->tick_offset = (uint32_t)mktimegm(&tm) + RTC_OFFSET; |
763 | 5703c174 | aurel32 | |
764 | e2733d20 | bellard | s->adb_poll_timer = qemu_new_timer(vm_clock, cuda_adb_poll, s); |
765 | 1eed09cb | Avi Kivity | *cuda_mem_index = cpu_register_io_memory(cuda_read, cuda_write, s); |
766 | 9b64997f | blueswir1 | register_savevm("cuda", -1, 1, cuda_save, cuda_load, s); |
767 | a08d4367 | Jan Kiszka | qemu_register_reset(cuda_reset, s); |
768 | 267002cd | bellard | } |