root / hw / ppc_chrp.c @ 46e50e9d
History | View | Annotate | Download (7.4 kB)
1 |
/*
|
---|---|
2 |
* QEMU PPC CHRP/PMAC hardware System Emulator
|
3 |
*
|
4 |
* Copyright (c) 2004 Fabrice Bellard
|
5 |
*
|
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:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be included in
|
14 |
* all copies or substantial portions of the Software.
|
15 |
*
|
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
|
22 |
* THE SOFTWARE.
|
23 |
*/
|
24 |
#include "vl.h" |
25 |
|
26 |
#define BIOS_FILENAME "ppc_rom.bin" |
27 |
#define NVRAM_SIZE 0x2000 |
28 |
|
29 |
#define KERNEL_LOAD_ADDR 0x01000000 |
30 |
#define INITRD_LOAD_ADDR 0x01800000 |
31 |
|
32 |
/* MacIO devices (mapped inside the MacIO address space): CUDA, DBDMA,
|
33 |
NVRAM (not implemented). */
|
34 |
|
35 |
static int dbdma_mem_index; |
36 |
static int cuda_mem_index; |
37 |
static int ide0_mem_index; |
38 |
static int ide1_mem_index; |
39 |
|
40 |
/* DBDMA: currently no op - should suffice right now */
|
41 |
|
42 |
static void dbdma_writeb (void *opaque, target_phys_addr_t addr, uint32_t value) |
43 |
{ |
44 |
printf("%s: 0x%08x <= 0x%08x\n", __func__, addr, value);
|
45 |
} |
46 |
|
47 |
static void dbdma_writew (void *opaque, target_phys_addr_t addr, uint32_t value) |
48 |
{ |
49 |
} |
50 |
|
51 |
static void dbdma_writel (void *opaque, target_phys_addr_t addr, uint32_t value) |
52 |
{ |
53 |
} |
54 |
|
55 |
static uint32_t dbdma_readb (void *opaque, target_phys_addr_t addr) |
56 |
{ |
57 |
printf("%s: 0x%08x => 0x00000000\n", __func__, addr);
|
58 |
return 0; |
59 |
} |
60 |
|
61 |
static uint32_t dbdma_readw (void *opaque, target_phys_addr_t addr) |
62 |
{ |
63 |
return 0; |
64 |
} |
65 |
|
66 |
static uint32_t dbdma_readl (void *opaque, target_phys_addr_t addr) |
67 |
{ |
68 |
return 0; |
69 |
} |
70 |
|
71 |
static CPUWriteMemoryFunc *dbdma_write[] = {
|
72 |
&dbdma_writeb, |
73 |
&dbdma_writew, |
74 |
&dbdma_writel, |
75 |
}; |
76 |
|
77 |
static CPUReadMemoryFunc *dbdma_read[] = {
|
78 |
&dbdma_readb, |
79 |
&dbdma_readw, |
80 |
&dbdma_readl, |
81 |
}; |
82 |
|
83 |
static void macio_map(PCIDevice *pci_dev, int region_num, |
84 |
uint32_t addr, uint32_t size, int type)
|
85 |
{ |
86 |
cpu_register_physical_memory(addr + 0x08000, 0x1000, dbdma_mem_index); |
87 |
cpu_register_physical_memory(addr + 0x16000, 0x2000, cuda_mem_index); |
88 |
cpu_register_physical_memory(addr + 0x1f000, 0x1000, ide0_mem_index); |
89 |
cpu_register_physical_memory(addr + 0x20000, 0x1000, ide1_mem_index); |
90 |
} |
91 |
|
92 |
static void macio_init(PCIBus *bus) |
93 |
{ |
94 |
PCIDevice *d; |
95 |
|
96 |
d = pci_register_device(bus, "macio", sizeof(PCIDevice), |
97 |
-1, NULL, NULL); |
98 |
/* Note: this code is strongly inspirated from the corresponding code
|
99 |
in PearPC */
|
100 |
d->config[0x00] = 0x6b; // vendor_id |
101 |
d->config[0x01] = 0x10; |
102 |
d->config[0x02] = 0x22; |
103 |
d->config[0x03] = 0x00; |
104 |
|
105 |
d->config[0x0a] = 0x00; // class_sub = pci2pci |
106 |
d->config[0x0b] = 0xff; // class_base = bridge |
107 |
d->config[0x0e] = 0x00; // header_type |
108 |
|
109 |
d->config[0x3d] = 0x01; // interrupt on pin 1 |
110 |
|
111 |
dbdma_mem_index = cpu_register_io_memory(0, dbdma_read, dbdma_write, NULL); |
112 |
|
113 |
pci_register_io_region(d, 0, 0x80000, |
114 |
PCI_ADDRESS_SPACE_MEM, macio_map); |
115 |
} |
116 |
|
117 |
/* PowerPC PREP hardware initialisation */
|
118 |
void ppc_chrp_init(int ram_size, int vga_ram_size, int boot_device, |
119 |
DisplayState *ds, const char **fd_filename, int snapshot, |
120 |
const char *kernel_filename, const char *kernel_cmdline, |
121 |
const char *initrd_filename) |
122 |
{ |
123 |
char buf[1024]; |
124 |
openpic_t *openpic; |
125 |
m48t59_t *nvram; |
126 |
int PPC_io_memory;
|
127 |
int ret, linux_boot, i, fd;
|
128 |
unsigned long bios_offset; |
129 |
uint32_t kernel_base, kernel_size, initrd_base, initrd_size; |
130 |
PCIBus *pci_bus; |
131 |
|
132 |
linux_boot = (kernel_filename != NULL);
|
133 |
|
134 |
/* allocate RAM */
|
135 |
cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
|
136 |
|
137 |
/* allocate and load BIOS */
|
138 |
bios_offset = ram_size + vga_ram_size; |
139 |
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); |
140 |
ret = load_image(buf, phys_ram_base + bios_offset); |
141 |
if (ret != BIOS_SIZE) {
|
142 |
fprintf(stderr, "qemu: could not load PPC PREP bios '%s'\n", buf);
|
143 |
exit(1);
|
144 |
} |
145 |
cpu_register_physical_memory((uint32_t)(-BIOS_SIZE), |
146 |
BIOS_SIZE, bios_offset | IO_MEM_ROM); |
147 |
cpu_single_env->nip = 0xfffffffc;
|
148 |
|
149 |
if (linux_boot) {
|
150 |
kernel_base = KERNEL_LOAD_ADDR; |
151 |
/* now we can load the kernel */
|
152 |
kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base); |
153 |
if (kernel_size < 0) { |
154 |
fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
155 |
kernel_filename); |
156 |
exit(1);
|
157 |
} |
158 |
/* load initrd */
|
159 |
if (initrd_filename) {
|
160 |
initrd_base = INITRD_LOAD_ADDR; |
161 |
initrd_size = load_image(initrd_filename, |
162 |
phys_ram_base + initrd_base); |
163 |
if (initrd_size < 0) { |
164 |
fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
165 |
initrd_filename); |
166 |
exit(1);
|
167 |
} |
168 |
} else {
|
169 |
initrd_base = 0;
|
170 |
initrd_size = 0;
|
171 |
} |
172 |
boot_device = 'm';
|
173 |
} else {
|
174 |
kernel_base = 0;
|
175 |
kernel_size = 0;
|
176 |
initrd_base = 0;
|
177 |
initrd_size = 0;
|
178 |
} |
179 |
/* Register CPU as a 74x/75x */
|
180 |
cpu_ppc_register(cpu_single_env, 0x00080000);
|
181 |
/* Set time-base frequency to 100 Mhz */
|
182 |
cpu_ppc_tb_init(cpu_single_env, 100UL * 1000UL * 1000UL); |
183 |
|
184 |
isa_mem_base = 0x80000000;
|
185 |
pci_bus = pci_pmac_init(); |
186 |
|
187 |
/* Register 8 MB of ISA IO space */
|
188 |
PPC_io_memory = cpu_register_io_memory(0, PPC_io_read, PPC_io_write, NULL); |
189 |
cpu_register_physical_memory(0xF2000000, 0x00800000, PPC_io_memory); |
190 |
|
191 |
/* init basic PC hardware */
|
192 |
vga_initialize(pci_bus, ds, phys_ram_base + ram_size, ram_size, |
193 |
vga_ram_size); |
194 |
openpic = openpic_init(pci_bus, 0x00000000, 0xF0000000, 1); |
195 |
pci_pmac_set_openpic(pci_bus, openpic); |
196 |
|
197 |
/* XXX: suppress that */
|
198 |
pic_init(); |
199 |
|
200 |
/* XXX: use Mac Serial port */
|
201 |
fd = serial_open_device(); |
202 |
serial_init(0x3f8, 4, fd); |
203 |
|
204 |
for(i = 0; i < nb_nics; i++) { |
205 |
pci_ne2000_init(pci_bus, &nd_table[i]); |
206 |
} |
207 |
|
208 |
ide0_mem_index = pmac_ide_init(&bs_table[0], openpic, 0x13); |
209 |
ide1_mem_index = pmac_ide_init(&bs_table[2], openpic, 0x13); |
210 |
|
211 |
/* cuda also initialize ADB */
|
212 |
cuda_mem_index = cuda_init(openpic, 0x19);
|
213 |
|
214 |
adb_kbd_init(&adb_bus); |
215 |
adb_mouse_init(&adb_bus); |
216 |
|
217 |
macio_init(pci_bus); |
218 |
|
219 |
nvram = m48t59_init(8, 0xFFF04000, 0x0074, NVRAM_SIZE); |
220 |
|
221 |
if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) |
222 |
graphic_depth = 15;
|
223 |
|
224 |
PPC_NVRAM_set_params(nvram, NVRAM_SIZE, "CHRP", ram_size, boot_device,
|
225 |
kernel_base, kernel_size, |
226 |
kernel_cmdline, |
227 |
initrd_base, initrd_size, |
228 |
/* XXX: need an option to load a NVRAM image */
|
229 |
0,
|
230 |
graphic_width, graphic_height, graphic_depth); |
231 |
/* No PCI init: the BIOS will do it */
|
232 |
} |