Revision 5fafdf24 hw/cuda.c

b/hw/cuda.c
1 1
/*
2 2
 * QEMU CUDA support
3
 * 
3
 *
4 4
 * Copyright (c) 2004 Fabrice Bellard
5
 * 
5
 *
6 6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7
 * of this software and associated documentation files (the "Software"), to deal
8 8
 * in the Software without restriction, including without limitation the rights
......
94 94
#define RTC_OFFSET                      2082844800
95 95

  
96 96
typedef struct CUDATimer {
97
    int index; 
97
    int index;
98 98
    uint16_t latch;
99 99
    uint16_t counter_value; /* counter value at load time */
100 100
    int64_t load_time;
......
116 116
    uint8_t anh;    /* A-side data, no handshake */
117 117

  
118 118
    CUDATimer timers[2];
119
    
119
   
120 120
    uint8_t last_b; /* last value of B register */
121 121
    uint8_t last_acr; /* last value of B register */
122
    
122
   
123 123
    int data_in_size;
124 124
    int data_in_index;
125 125
    int data_out_index;
......
135 135
ADBBusState adb_bus;
136 136

  
137 137
static void cuda_update(CUDAState *s);
138
static void cuda_receive_packet_from_host(CUDAState *s, 
138
static void cuda_receive_packet_from_host(CUDAState *s,
139 139
                                          const uint8_t *data, int len);
140
static void cuda_timer_update(CUDAState *s, CUDATimer *ti, 
140
static void cuda_timer_update(CUDAState *s, CUDATimer *ti,
141 141
                              int64_t current_time);
142 142

  
143 143
static void cuda_update_irq(CUDAState *s)
......
154 154
    int64_t d;
155 155
    unsigned int counter;
156 156

  
157
    d = muldiv64(qemu_get_clock(vm_clock) - s->load_time, 
157
    d = muldiv64(qemu_get_clock(vm_clock) - s->load_time,
158 158
                 CUDA_TIMER_FREQ, ticks_per_sec);
159 159
    if (s->index == 0) {
160 160
        /* the timer goes down from latch to -1 (period of latch + 2) */
......
162 162
            counter = (s->counter_value - d) & 0xffff;
163 163
        } else {
164 164
            counter = (d - (s->counter_value + 1)) % (s->latch + 2);
165
            counter = (s->latch - counter) & 0xffff; 
165
            counter = (s->latch - counter) & 0xffff;
166 166
        }
167 167
    } else {
168 168
        counter = (s->counter_value - d) & 0xffff;
......
187 187
    unsigned int counter;
188 188

  
189 189
    /* current counter value */
190
    d = muldiv64(current_time - s->load_time, 
190
    d = muldiv64(current_time - s->load_time,
191 191
                 CUDA_TIMER_FREQ, ticks_per_sec);
192 192
    /* the timer goes down from latch to -1 (period of latch + 2) */
193 193
    if (d <= (s->counter_value + 1)) {
194 194
        counter = (s->counter_value - d) & 0xffff;
195 195
    } else {
196 196
        counter = (d - (s->counter_value + 1)) % (s->latch + 2);
197
        counter = (s->latch - counter) & 0xffff; 
197
        counter = (s->latch - counter) & 0xffff;
198 198
    }
199
    
199
   
200 200
    /* Note: we consider the irq is raised on 0 */
201 201
    if (counter == 0xffff) {
202 202
        next_time = d + s->latch + 1;
......
207 207
    }
208 208
#if 0
209 209
#ifdef DEBUG_CUDA
210
    printf("latch=%d counter=%" PRId64 " delta_next=%" PRId64 "\n", 
210
    printf("latch=%d counter=%" PRId64 " delta_next=%" PRId64 "\n",
211 211
           s->latch, d, next_time - d);
212 212
#endif
213 213
#endif
214
    next_time = muldiv64(next_time, ticks_per_sec, CUDA_TIMER_FREQ) + 
214
    next_time = muldiv64(next_time, ticks_per_sec, CUDA_TIMER_FREQ) +
215 215
        s->load_time;
216 216
    if (next_time <= current_time)
217 217
        next_time = current_time + 1;
218 218
    return next_time;
219 219
}
220 220

  
221
static void cuda_timer_update(CUDAState *s, CUDATimer *ti, 
221
static void cuda_timer_update(CUDAState *s, CUDATimer *ti,
222 222
                              int64_t current_time)
223 223
{
224 224
    if (!ti->timer)
......
296 296
        break;
297 297
    case 13:
298 298
        val = s->ifr;
299
        if (s->ifr & s->ier) 
299
        if (s->ifr & s->ier)
300 300
            val |= 0x80;
301 301
        break;
302 302
    case 14:
......
317 317
static void cuda_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
318 318
{
319 319
    CUDAState *s = opaque;
320
    
320
   
321 321
    addr = (addr >> 9) & 0xf;
322 322
#ifdef DEBUG_CUDA
323 323
    printf("cuda: write: reg=0x%x val=%02x\n", addr, val);
......
470 470
    }
471 471
}
472 472

  
473
static void cuda_send_packet_to_host(CUDAState *s, 
473
static void cuda_send_packet_to_host(CUDAState *s,
474 474
                                     const uint8_t *data, int len)
475 475
{
476 476
#ifdef DEBUG_CUDA_PACKET
......
502 502
        obuf[1] = 0x40; /* polled data */
503 503
        cuda_send_packet_to_host(s, obuf, olen + 2);
504 504
    }
505
    qemu_mod_timer(s->adb_poll_timer, 
506
                   qemu_get_clock(vm_clock) + 
505
    qemu_mod_timer(s->adb_poll_timer,
506
                   qemu_get_clock(vm_clock) +
507 507
                   (ticks_per_sec / CUDA_ADB_POLL_FREQ));
508 508
}
509 509

  
510
static void cuda_receive_packet(CUDAState *s, 
510
static void cuda_receive_packet(CUDAState *s,
511 511
                                const uint8_t *data, int len)
512 512
{
513 513
    uint8_t obuf[16];
......
519 519
        if (autopoll != s->autopoll) {
520 520
            s->autopoll = autopoll;
521 521
            if (autopoll) {
522
                qemu_mod_timer(s->adb_poll_timer, 
523
                               qemu_get_clock(vm_clock) + 
522
                qemu_mod_timer(s->adb_poll_timer,
523
                               qemu_get_clock(vm_clock) +
524 524
                               (ticks_per_sec / CUDA_ADB_POLL_FREQ));
525 525
            } else {
526 526
                qemu_del_timer(s->adb_poll_timer);
......
562 562
    }
563 563
}
564 564

  
565
static void cuda_receive_packet_from_host(CUDAState *s, 
565
static void cuda_receive_packet_from_host(CUDAState *s,
566 566
                                          const uint8_t *data, int len)
567 567
{
568 568
#ifdef DEBUG_CUDA_PACKET

Also available in: Unified diff