2
* QEMU JAZZ RC4030 chipset
4
* Copyright (c) 2007-2008 Hervé Poussineau
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to deal
8
* in the Software without restriction, including without limitation the rights
9
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
* copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
#include "qemu-timer.h"
28
//#define DEBUG_RC4030
31
static const char* irq_names[] = { "parallel", "floppy", "sound", "video",
32
"network", "scsi", "keyboard", "mouse", "serial0", "serial1" };
35
typedef struct rc4030State
37
uint32_t config; /* 0x0000: RC4030 config register */
38
uint32_t invalid_address_register; /* 0x0010: Invalid Address register */
41
uint32_t dma_regs[8][4];
42
uint32_t dma_tl_base; /* 0x0018: DMA transl. table base */
43
uint32_t dma_tl_limit; /* 0x0020: DMA transl. table limit */
46
uint32_t remote_failed_address; /* 0x0038: Remote Failed Address */
47
uint32_t memory_failed_address; /* 0x0040: Memory Failed Address */
48
uint32_t cache_ptag; /* 0x0048: I/O Cache Physical Tag */
49
uint32_t cache_ltag; /* 0x0050: I/O Cache Logical Tag */
50
uint32_t cache_bmask; /* 0x0058: I/O Cache Byte Mask */
51
uint32_t cache_bwin; /* 0x0060: I/O Cache Buffer Window */
55
uint32_t nvram_protect; /* 0x0220: NV ram protect register */
57
uint32_t rem_speed[15];
58
uint32_t imr_jazz; /* Local bus int enable mask */
59
uint32_t isr_jazz; /* Local bus int source */
62
QEMUTimer *periodic_timer;
63
uint32_t itr; /* Interval timer reload */
67
qemu_irq jazz_bus_irq;
70
static void set_next_tick(rc4030State *s)
72
qemu_irq_lower(s->timer_irq);
75
hz = 1000 / (s->itr + 1);
77
qemu_mod_timer(s->periodic_timer, qemu_get_clock(vm_clock) + ticks_per_sec / hz);
80
/* called for accesses to rc4030 */
81
static uint32_t rc4030_readl(void *opaque, target_phys_addr_t addr)
83
rc4030State *s = opaque;
87
switch (addr & ~0x3) {
88
/* Global config register */
92
/* Invalid Address register */
94
val = s->invalid_address_register;
96
/* DMA transl. table base */
100
/* DMA transl. table limit */
102
val = s->dma_tl_limit;
104
/* Remote Failed Address */
106
val = s->remote_failed_address;
108
/* Memory Failed Address */
110
val = s->memory_failed_address;
112
/* I/O Cache Byte Mask */
114
val = s->cache_bmask;
116
if (s->cache_bmask == (uint32_t)-1)
119
/* Remote Speed Registers */
135
val = s->rem_speed[(addr - 0x0070) >> 3];
137
/* DMA channel base address */
171
int entry = (addr - 0x0100) >> 5;
172
int idx = (addr & 0x1f) >> 3;
173
val = s->dma_regs[entry][idx];
184
/* NV ram protect register */
186
val = s->nvram_protect;
188
/* Interval timer count */
191
qemu_irq_lower(s->timer_irq);
199
printf("rc4030: invalid read [" TARGET_FMT_lx "]\n", addr);
206
if ((addr & ~3) != 0x230)
207
printf("rc4030: read 0x%02x at " TARGET_FMT_lx "\n", val, addr);
213
static uint32_t rc4030_readw(void *opaque, target_phys_addr_t addr)
215
uint32_t v = rc4030_readl(opaque, addr & ~0x3);
222
static uint32_t rc4030_readb(void *opaque, target_phys_addr_t addr)
224
uint32_t v = rc4030_readl(opaque, addr & ~0x3);
225
return (v >> (8 * (addr & 0x3))) & 0xff;
228
static void rc4030_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
230
rc4030State *s = opaque;
234
printf("rc4030: write 0x%02x at " TARGET_FMT_lx "\n", val, addr);
237
switch (addr & ~0x3) {
238
/* Global config register */
242
/* DMA transl. table base */
244
s->dma_tl_base = val;
246
/* DMA transl. table limit */
248
s->dma_tl_limit = val;
250
/* I/O Cache Physical Tag */
254
/* I/O Cache Logical Tag */
258
/* I/O Cache Byte Mask */
260
s->cache_bmask |= val; /* HACK */
262
/* I/O Cache Buffer Window */
266
if (s->cache_ltag == 0x80000001 && s->cache_bmask == 0xf0f0f0f) {
267
target_phys_addr_t dests[] = { 4, 0, 8, 0x10 };
268
static int current = 0;
269
target_phys_addr_t dest = 0 + dests[current];
271
current = (current + 1) % (sizeof(dests)/sizeof(dests[0]));
272
buf = s->cache_bwin - 1;
273
cpu_physical_memory_rw(dest, &buf, 1, 1);
276
/* Remote Speed Registers */
292
s->rem_speed[(addr - 0x0070) >> 3] = val;
294
/* DMA channel base address */
328
int entry = (addr - 0x0100) >> 5;
329
int idx = (addr & 0x1f) >> 3;
330
s->dma_regs[entry][idx] = val;
337
/* Interval timer reload */
340
qemu_irq_lower(s->timer_irq);
345
printf("rc4030: invalid write of 0x%02x at [" TARGET_FMT_lx "]\n", val, addr);
351
static void rc4030_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
353
uint32_t old_val = rc4030_readl(opaque, addr & ~0x3);
356
val = (val << 16) | (old_val & 0x0000ffff);
358
val = val | (old_val & 0xffff0000);
359
rc4030_writel(opaque, addr & ~0x3, val);
362
static void rc4030_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
364
uint32_t old_val = rc4030_readl(opaque, addr & ~0x3);
368
val = val | (old_val & 0xffffff00);
371
val = (val << 8) | (old_val & 0xffff00ff);
374
val = (val << 16) | (old_val & 0xff00ffff);
377
val = (val << 24) | (old_val & 0x00ffffff);
380
rc4030_writel(opaque, addr & ~0x3, val);
383
static CPUReadMemoryFunc *rc4030_read[3] = {
389
static CPUWriteMemoryFunc *rc4030_write[3] = {
395
static void update_jazz_irq(rc4030State *s)
399
pending = s->isr_jazz & s->imr_jazz;
402
if (s->isr_jazz != 0) {
404
printf("jazz pending:");
405
for (irq = 0; irq < sizeof(irq_names)/sizeof(irq_names[0]); irq++) {
406
if (s->isr_jazz & (1 << irq)) {
407
printf(" %s", irq_names[irq]);
408
if (!(s->imr_jazz & (1 << irq))) {
418
qemu_irq_raise(s->jazz_bus_irq);
420
qemu_irq_lower(s->jazz_bus_irq);
423
static void rc4030_irq_jazz_request(void *opaque, int irq, int level)
425
rc4030State *s = opaque;
428
s->isr_jazz |= 1 << irq;
430
s->isr_jazz &= ~(1 << irq);
436
static void rc4030_periodic_timer(void *opaque)
438
rc4030State *s = opaque;
441
qemu_irq_raise(s->timer_irq);
444
static uint32_t int_readb(void *opaque, target_phys_addr_t addr)
446
rc4030State *s = opaque;
453
/* Local bus int source */
454
uint32_t pending = s->isr_jazz & s->imr_jazz;
459
//printf("returning irq %s\n", irq_names[irq]);
460
val = (irq + 1) << 2;
470
printf("rc4030: (interrupt controller) invalid read [" TARGET_FMT_lx "]\n", addr);
476
printf("rc4030: (interrupt controller) read 0x%02x at " TARGET_FMT_lx "\n", val, addr);
482
static uint32_t int_readw(void *opaque, target_phys_addr_t addr)
485
v = int_readb(opaque, addr);
486
v |= int_readb(opaque, addr + 1) << 8;
490
static uint32_t int_readl(void *opaque, target_phys_addr_t addr)
493
v = int_readb(opaque, addr);
494
v |= int_readb(opaque, addr + 1) << 8;
495
v |= int_readb(opaque, addr + 2) << 16;
496
v |= int_readb(opaque, addr + 3) << 24;
500
static void int_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
502
rc4030State *s = opaque;
506
printf("rc4030: (interrupt controller) write 0x%02x at " TARGET_FMT_lx "\n", val, addr);
510
/* Local bus int enable mask */
512
s->imr_jazz = (s->imr_jazz & 0xff00) | (val << 0); update_jazz_irq(s);
515
s->imr_jazz = (s->imr_jazz & 0x00ff) | (val << 8); update_jazz_irq(s);
519
printf("rc4030: (interrupt controller) invalid write of 0x%02x at [" TARGET_FMT_lx "]\n", val, addr);
525
static void int_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
527
int_writeb(opaque, addr, val & 0xff);
528
int_writeb(opaque, addr + 1, (val >> 8) & 0xff);
531
static void int_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
533
int_writeb(opaque, addr, val & 0xff);
534
int_writeb(opaque, addr + 1, (val >> 8) & 0xff);
535
int_writeb(opaque, addr + 2, (val >> 16) & 0xff);
536
int_writeb(opaque, addr + 3, (val >> 24) & 0xff);
539
static CPUReadMemoryFunc *int_read[3] = {
545
static CPUWriteMemoryFunc *int_write[3] = {
551
#define G364_512KB_RAM (0x0)
552
#define G364_2MB_RAM (0x1)
553
#define G364_8MB_RAM (0x2)
554
#define G364_32MB_RAM (0x3)
556
static void rc4030_reset(void *opaque)
558
rc4030State *s = opaque;
561
s->config = (G364_2MB_RAM << 8) | 0x04;
562
s->invalid_address_register = 0;
564
memset(s->dma_regs, 0, sizeof(s->dma_regs));
565
s->dma_tl_base = s->dma_tl_limit = 0;
567
s->remote_failed_address = s->memory_failed_address = 0;
568
s->cache_ptag = s->cache_ltag = 0;
569
s->cache_bmask = s->cache_bwin = 0;
572
s->offset210 = 0x18186;
573
s->nvram_protect = 7;
575
for (i = 0; i < 15; i++)
577
s->imr_jazz = s->isr_jazz = 0;
582
qemu_irq_lower(s->timer_irq);
583
qemu_irq_lower(s->jazz_bus_irq);
586
qemu_irq *rc4030_init(qemu_irq timer, qemu_irq jazz_bus)
589
int s_chipset, s_int;
591
s = qemu_mallocz(sizeof(rc4030State));
595
s->periodic_timer = qemu_new_timer(vm_clock, rc4030_periodic_timer, s);
596
s->timer_irq = timer;
597
s->jazz_bus_irq = jazz_bus;
599
qemu_register_reset(rc4030_reset, s);
602
s_chipset = cpu_register_io_memory(0, rc4030_read, rc4030_write, s);
603
cpu_register_physical_memory(0x80000000, 0x300, s_chipset);
604
s_int = cpu_register_io_memory(0, int_read, int_write, s);
605
cpu_register_physical_memory(0xf0000000, 0x00001000, s_int);
607
return qemu_allocate_irqs(rc4030_irq_jazz_request, s, 16);