Statistics
| Branch: | Revision:

root / hw / sun4m.c @ a74cdab4

History | View | Annotate | Download (56.5 kB)

1 420557e8 bellard
/*
2 ee76f82e blueswir1
 * QEMU Sun4m & Sun4d & Sun4c System Emulator
3 5fafdf24 ths
 *
4 b81b3b10 bellard
 * Copyright (c) 2003-2005 Fabrice Bellard
5 5fafdf24 ths
 *
6 420557e8 bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 420557e8 bellard
 * of this software and associated documentation files (the "Software"), to deal
8 420557e8 bellard
 * in the Software without restriction, including without limitation the rights
9 420557e8 bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 420557e8 bellard
 * copies of the Software, and to permit persons to whom the Software is
11 420557e8 bellard
 * furnished to do so, subject to the following conditions:
12 420557e8 bellard
 *
13 420557e8 bellard
 * The above copyright notice and this permission notice shall be included in
14 420557e8 bellard
 * all copies or substantial portions of the Software.
15 420557e8 bellard
 *
16 420557e8 bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 420557e8 bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 420557e8 bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 420557e8 bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 420557e8 bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 420557e8 bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 420557e8 bellard
 * THE SOFTWARE.
23 420557e8 bellard
 */
24 9d07d757 Paul Brook
#include "sysbus.h"
25 87ecb68b pbrook
#include "qemu-timer.h"
26 87ecb68b pbrook
#include "sun4m.h"
27 87ecb68b pbrook
#include "nvram.h"
28 87ecb68b pbrook
#include "sparc32_dma.h"
29 87ecb68b pbrook
#include "fdc.h"
30 87ecb68b pbrook
#include "sysemu.h"
31 87ecb68b pbrook
#include "net.h"
32 87ecb68b pbrook
#include "boards.h"
33 d2c63fc1 blueswir1
#include "firmware_abi.h"
34 1cd3af54 Gerd Hoffmann
#include "esp.h"
35 22548760 blueswir1
#include "pc.h"
36 22548760 blueswir1
#include "isa.h"
37 3cce6243 blueswir1
#include "fw_cfg.h"
38 b4ed08e0 blueswir1
#include "escc.h"
39 676d9b9b Artyom Tarasenko
#include "empty_slot.h"
40 4b48bf05 Blue Swirl
#include "qdev-addr.h"
41 ca20cf32 Blue Swirl
#include "loader.h"
42 ca20cf32 Blue Swirl
#include "elf.h"
43 2446333c Blue Swirl
#include "blockdev.h"
44 97bf4851 Blue Swirl
#include "trace.h"
45 420557e8 bellard
46 36cd9210 blueswir1
/*
47 36cd9210 blueswir1
 * Sun4m architecture was used in the following machines:
48 36cd9210 blueswir1
 *
49 36cd9210 blueswir1
 * SPARCserver 6xxMP/xx
50 77f193da blueswir1
 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
51 77f193da blueswir1
 * SPARCclassic X (4/10)
52 36cd9210 blueswir1
 * SPARCstation LX/ZX (4/30)
53 36cd9210 blueswir1
 * SPARCstation Voyager
54 36cd9210 blueswir1
 * SPARCstation 10/xx, SPARCserver 10/xx
55 36cd9210 blueswir1
 * SPARCstation 5, SPARCserver 5
56 36cd9210 blueswir1
 * SPARCstation 20/xx, SPARCserver 20
57 36cd9210 blueswir1
 * SPARCstation 4
58 36cd9210 blueswir1
 *
59 7d85892b blueswir1
 * Sun4d architecture was used in the following machines:
60 7d85892b blueswir1
 *
61 7d85892b blueswir1
 * SPARCcenter 2000
62 7d85892b blueswir1
 * SPARCserver 1000
63 7d85892b blueswir1
 *
64 ee76f82e blueswir1
 * Sun4c architecture was used in the following machines:
65 ee76f82e blueswir1
 * SPARCstation 1/1+, SPARCserver 1/1+
66 ee76f82e blueswir1
 * SPARCstation SLC
67 ee76f82e blueswir1
 * SPARCstation IPC
68 ee76f82e blueswir1
 * SPARCstation ELC
69 ee76f82e blueswir1
 * SPARCstation IPX
70 ee76f82e blueswir1
 *
71 36cd9210 blueswir1
 * See for example: http://www.sunhelp.org/faq/sunref1.html
72 36cd9210 blueswir1
 */
73 36cd9210 blueswir1
74 420557e8 bellard
#define KERNEL_LOAD_ADDR     0x00004000
75 b6f479d3 bellard
#define CMDLINE_ADDR         0x007ff000
76 713c45fa bellard
#define INITRD_LOAD_ADDR     0x00800000
77 a7227727 blueswir1
#define PROM_SIZE_MAX        (1024 * 1024)
78 40ce0a9a blueswir1
#define PROM_VADDR           0xffd00000
79 f930d07e blueswir1
#define PROM_FILENAME        "openbios-sparc32"
80 3cce6243 blueswir1
#define CFG_ADDR             0xd00000510ULL
81 fbfcf955 blueswir1
#define FW_CFG_SUN4M_DEPTH   (FW_CFG_ARCH_LOCAL + 0x00)
82 b8174937 bellard
83 ba3c64fb bellard
#define MAX_CPUS 16
84 b3a23197 blueswir1
#define MAX_PILS 16
85 9a62fb24 Bob Breuer
#define MAX_VSIMMS 4
86 420557e8 bellard
87 b4ed08e0 blueswir1
#define ESCC_CLOCK 4915200
88 b4ed08e0 blueswir1
89 8137cde8 blueswir1
struct sun4m_hwdef {
90 3386376c Artyom Tarasenko
    target_phys_addr_t iommu_base, iommu_pad_base, iommu_pad_len, slavio_base;
91 c227f099 Anthony Liguori
    target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
92 c227f099 Anthony Liguori
    target_phys_addr_t serial_base, fd_base;
93 c5de386a Artyom Tarasenko
    target_phys_addr_t afx_base, idreg_base, dma_base, esp_base, le_base;
94 c227f099 Anthony Liguori
    target_phys_addr_t tcx_base, cs_base, apc_base, aux1_base, aux2_base;
95 9a62fb24 Bob Breuer
    target_phys_addr_t bpp_base, dbri_base, sx_base;
96 9a62fb24 Bob Breuer
    struct {
97 9a62fb24 Bob Breuer
        target_phys_addr_t reg_base, vram_base;
98 9a62fb24 Bob Breuer
    } vsimm[MAX_VSIMMS];
99 c227f099 Anthony Liguori
    target_phys_addr_t ecc_base;
100 7eb0c8e8 blueswir1
    uint32_t ecc_version;
101 905fdcb5 blueswir1
    uint8_t nvram_machine_id;
102 905fdcb5 blueswir1
    uint16_t machine_id;
103 7fbfb139 blueswir1
    uint32_t iommu_version;
104 3ebf5aaf blueswir1
    uint64_t max_mem;
105 3ebf5aaf blueswir1
    const char * const default_cpu_model;
106 36cd9210 blueswir1
};
107 36cd9210 blueswir1
108 7d85892b blueswir1
#define MAX_IOUNITS 5
109 7d85892b blueswir1
110 7d85892b blueswir1
struct sun4d_hwdef {
111 c227f099 Anthony Liguori
    target_phys_addr_t iounit_bases[MAX_IOUNITS], slavio_base;
112 c227f099 Anthony Liguori
    target_phys_addr_t counter_base, nvram_base, ms_kb_base;
113 c227f099 Anthony Liguori
    target_phys_addr_t serial_base;
114 c227f099 Anthony Liguori
    target_phys_addr_t espdma_base, esp_base;
115 c227f099 Anthony Liguori
    target_phys_addr_t ledma_base, le_base;
116 c227f099 Anthony Liguori
    target_phys_addr_t tcx_base;
117 c227f099 Anthony Liguori
    target_phys_addr_t sbi_base;
118 905fdcb5 blueswir1
    uint8_t nvram_machine_id;
119 905fdcb5 blueswir1
    uint16_t machine_id;
120 7d85892b blueswir1
    uint32_t iounit_version;
121 7d85892b blueswir1
    uint64_t max_mem;
122 7d85892b blueswir1
    const char * const default_cpu_model;
123 7d85892b blueswir1
};
124 7d85892b blueswir1
125 8137cde8 blueswir1
struct sun4c_hwdef {
126 c227f099 Anthony Liguori
    target_phys_addr_t iommu_base, slavio_base;
127 c227f099 Anthony Liguori
    target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
128 c227f099 Anthony Liguori
    target_phys_addr_t serial_base, fd_base;
129 c227f099 Anthony Liguori
    target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
130 c227f099 Anthony Liguori
    target_phys_addr_t tcx_base, aux1_base;
131 8137cde8 blueswir1
    uint8_t nvram_machine_id;
132 8137cde8 blueswir1
    uint16_t machine_id;
133 8137cde8 blueswir1
    uint32_t iommu_version;
134 8137cde8 blueswir1
    uint64_t max_mem;
135 8137cde8 blueswir1
    const char * const default_cpu_model;
136 8137cde8 blueswir1
};
137 8137cde8 blueswir1
138 6f7e9aec bellard
int DMA_get_channel_mode (int nchan)
139 6f7e9aec bellard
{
140 6f7e9aec bellard
    return 0;
141 6f7e9aec bellard
}
142 6f7e9aec bellard
int DMA_read_memory (int nchan, void *buf, int pos, int size)
143 6f7e9aec bellard
{
144 6f7e9aec bellard
    return 0;
145 6f7e9aec bellard
}
146 6f7e9aec bellard
int DMA_write_memory (int nchan, void *buf, int pos, int size)
147 6f7e9aec bellard
{
148 6f7e9aec bellard
    return 0;
149 6f7e9aec bellard
}
150 6f7e9aec bellard
void DMA_hold_DREQ (int nchan) {}
151 6f7e9aec bellard
void DMA_release_DREQ (int nchan) {}
152 6f7e9aec bellard
void DMA_schedule(int nchan) {}
153 4556bd8b Blue Swirl
154 4556bd8b Blue Swirl
void DMA_init(int high_page_enable, qemu_irq *cpu_request_exit)
155 4556bd8b Blue Swirl
{
156 4556bd8b Blue Swirl
}
157 4556bd8b Blue Swirl
158 6f7e9aec bellard
void DMA_register_channel (int nchan,
159 6f7e9aec bellard
                           DMA_transfer_handler transfer_handler,
160 6f7e9aec bellard
                           void *opaque)
161 6f7e9aec bellard
{
162 6f7e9aec bellard
}
163 6f7e9aec bellard
164 513f789f blueswir1
static int fw_cfg_boot_set(void *opaque, const char *boot_device)
165 81864572 blueswir1
{
166 513f789f blueswir1
    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
167 81864572 blueswir1
    return 0;
168 81864572 blueswir1
}
169 81864572 blueswir1
170 43a34704 Blue Swirl
static void nvram_init(M48t59State *nvram, uint8_t *macaddr,
171 43a34704 Blue Swirl
                       const char *cmdline, const char *boot_devices,
172 43a34704 Blue Swirl
                       ram_addr_t RAM_size, uint32_t kernel_size,
173 f930d07e blueswir1
                       int width, int height, int depth,
174 905fdcb5 blueswir1
                       int nvram_machine_id, const char *arch)
175 e80cfcfc bellard
{
176 d2c63fc1 blueswir1
    unsigned int i;
177 66508601 blueswir1
    uint32_t start, end;
178 d2c63fc1 blueswir1
    uint8_t image[0x1ff0];
179 d2c63fc1 blueswir1
    struct OpenBIOS_nvpart_v1 *part_header;
180 d2c63fc1 blueswir1
181 d2c63fc1 blueswir1
    memset(image, '\0', sizeof(image));
182 e80cfcfc bellard
183 513f789f blueswir1
    start = 0;
184 b6f479d3 bellard
185 66508601 blueswir1
    // OpenBIOS nvram variables
186 66508601 blueswir1
    // Variable partition
187 d2c63fc1 blueswir1
    part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
188 d2c63fc1 blueswir1
    part_header->signature = OPENBIOS_PART_SYSTEM;
189 363a37d5 blueswir1
    pstrcpy(part_header->name, sizeof(part_header->name), "system");
190 66508601 blueswir1
191 d2c63fc1 blueswir1
    end = start + sizeof(struct OpenBIOS_nvpart_v1);
192 66508601 blueswir1
    for (i = 0; i < nb_prom_envs; i++)
193 d2c63fc1 blueswir1
        end = OpenBIOS_set_var(image, end, prom_envs[i]);
194 d2c63fc1 blueswir1
195 d2c63fc1 blueswir1
    // End marker
196 d2c63fc1 blueswir1
    image[end++] = '\0';
197 66508601 blueswir1
198 66508601 blueswir1
    end = start + ((end - start + 15) & ~15);
199 d2c63fc1 blueswir1
    OpenBIOS_finish_partition(part_header, end - start);
200 66508601 blueswir1
201 66508601 blueswir1
    // free partition
202 66508601 blueswir1
    start = end;
203 d2c63fc1 blueswir1
    part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
204 d2c63fc1 blueswir1
    part_header->signature = OPENBIOS_PART_FREE;
205 363a37d5 blueswir1
    pstrcpy(part_header->name, sizeof(part_header->name), "free");
206 66508601 blueswir1
207 66508601 blueswir1
    end = 0x1fd0;
208 d2c63fc1 blueswir1
    OpenBIOS_finish_partition(part_header, end - start);
209 d2c63fc1 blueswir1
210 905fdcb5 blueswir1
    Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
211 905fdcb5 blueswir1
                    nvram_machine_id);
212 d2c63fc1 blueswir1
213 d2c63fc1 blueswir1
    for (i = 0; i < sizeof(image); i++)
214 d2c63fc1 blueswir1
        m48t59_write(nvram, i, image[i]);
215 e80cfcfc bellard
}
216 e80cfcfc bellard
217 d453c2c3 Blue Swirl
static DeviceState *slavio_intctl;
218 e80cfcfc bellard
219 376253ec aliguori
void pic_info(Monitor *mon)
220 e80cfcfc bellard
{
221 7d85892b blueswir1
    if (slavio_intctl)
222 376253ec aliguori
        slavio_pic_info(mon, slavio_intctl);
223 e80cfcfc bellard
}
224 e80cfcfc bellard
225 376253ec aliguori
void irq_info(Monitor *mon)
226 e80cfcfc bellard
{
227 7d85892b blueswir1
    if (slavio_intctl)
228 376253ec aliguori
        slavio_irq_info(mon, slavio_intctl);
229 e80cfcfc bellard
}
230 e80cfcfc bellard
231 327ac2e7 blueswir1
void cpu_check_irqs(CPUState *env)
232 327ac2e7 blueswir1
{
233 327ac2e7 blueswir1
    if (env->pil_in && (env->interrupt_index == 0 ||
234 327ac2e7 blueswir1
                        (env->interrupt_index & ~15) == TT_EXTINT)) {
235 327ac2e7 blueswir1
        unsigned int i;
236 327ac2e7 blueswir1
237 327ac2e7 blueswir1
        for (i = 15; i > 0; i--) {
238 327ac2e7 blueswir1
            if (env->pil_in & (1 << i)) {
239 327ac2e7 blueswir1
                int old_interrupt = env->interrupt_index;
240 327ac2e7 blueswir1
241 327ac2e7 blueswir1
                env->interrupt_index = TT_EXTINT | i;
242 f32d7ec5 blueswir1
                if (old_interrupt != env->interrupt_index) {
243 97bf4851 Blue Swirl
                    trace_sun4m_cpu_interrupt(i);
244 327ac2e7 blueswir1
                    cpu_interrupt(env, CPU_INTERRUPT_HARD);
245 f32d7ec5 blueswir1
                }
246 327ac2e7 blueswir1
                break;
247 327ac2e7 blueswir1
            }
248 327ac2e7 blueswir1
        }
249 327ac2e7 blueswir1
    } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
250 97bf4851 Blue Swirl
        trace_sun4m_cpu_reset_interrupt(env->interrupt_index & 15);
251 327ac2e7 blueswir1
        env->interrupt_index = 0;
252 327ac2e7 blueswir1
        cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
253 327ac2e7 blueswir1
    }
254 327ac2e7 blueswir1
}
255 327ac2e7 blueswir1
256 94ad5b00 Paolo Bonzini
static void cpu_kick_irq(CPUState *env)
257 94ad5b00 Paolo Bonzini
{
258 94ad5b00 Paolo Bonzini
    env->halted = 0;
259 94ad5b00 Paolo Bonzini
    cpu_check_irqs(env);
260 94ad5b00 Paolo Bonzini
    qemu_cpu_kick(env);
261 94ad5b00 Paolo Bonzini
}
262 94ad5b00 Paolo Bonzini
263 b3a23197 blueswir1
static void cpu_set_irq(void *opaque, int irq, int level)
264 b3a23197 blueswir1
{
265 b3a23197 blueswir1
    CPUState *env = opaque;
266 b3a23197 blueswir1
267 b3a23197 blueswir1
    if (level) {
268 97bf4851 Blue Swirl
        trace_sun4m_cpu_set_irq_raise(irq);
269 327ac2e7 blueswir1
        env->pil_in |= 1 << irq;
270 94ad5b00 Paolo Bonzini
        cpu_kick_irq(env);
271 b3a23197 blueswir1
    } else {
272 97bf4851 Blue Swirl
        trace_sun4m_cpu_set_irq_lower(irq);
273 327ac2e7 blueswir1
        env->pil_in &= ~(1 << irq);
274 327ac2e7 blueswir1
        cpu_check_irqs(env);
275 b3a23197 blueswir1
    }
276 b3a23197 blueswir1
}
277 b3a23197 blueswir1
278 b3a23197 blueswir1
static void dummy_cpu_set_irq(void *opaque, int irq, int level)
279 b3a23197 blueswir1
{
280 b3a23197 blueswir1
}
281 b3a23197 blueswir1
282 c68ea704 bellard
static void main_cpu_reset(void *opaque)
283 c68ea704 bellard
{
284 c68ea704 bellard
    CPUState *env = opaque;
285 3d29fbef blueswir1
286 3d29fbef blueswir1
    cpu_reset(env);
287 3d29fbef blueswir1
    env->halted = 0;
288 3d29fbef blueswir1
}
289 3d29fbef blueswir1
290 3d29fbef blueswir1
static void secondary_cpu_reset(void *opaque)
291 3d29fbef blueswir1
{
292 3d29fbef blueswir1
    CPUState *env = opaque;
293 3d29fbef blueswir1
294 c68ea704 bellard
    cpu_reset(env);
295 3d29fbef blueswir1
    env->halted = 1;
296 c68ea704 bellard
}
297 c68ea704 bellard
298 6d0c293d blueswir1
static void cpu_halt_signal(void *opaque, int irq, int level)
299 6d0c293d blueswir1
{
300 6d0c293d blueswir1
    if (level && cpu_single_env)
301 6d0c293d blueswir1
        cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT);
302 6d0c293d blueswir1
}
303 6d0c293d blueswir1
304 409dbce5 Aurelien Jarno
static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
305 409dbce5 Aurelien Jarno
{
306 409dbce5 Aurelien Jarno
    return addr - 0xf0000000ULL;
307 409dbce5 Aurelien Jarno
}
308 409dbce5 Aurelien Jarno
309 3ebf5aaf blueswir1
static unsigned long sun4m_load_kernel(const char *kernel_filename,
310 293f78bc blueswir1
                                       const char *initrd_filename,
311 c227f099 Anthony Liguori
                                       ram_addr_t RAM_size)
312 3ebf5aaf blueswir1
{
313 3ebf5aaf blueswir1
    int linux_boot;
314 3ebf5aaf blueswir1
    unsigned int i;
315 3ebf5aaf blueswir1
    long initrd_size, kernel_size;
316 3c178e72 Gerd Hoffmann
    uint8_t *ptr;
317 3ebf5aaf blueswir1
318 3ebf5aaf blueswir1
    linux_boot = (kernel_filename != NULL);
319 3ebf5aaf blueswir1
320 3ebf5aaf blueswir1
    kernel_size = 0;
321 3ebf5aaf blueswir1
    if (linux_boot) {
322 ca20cf32 Blue Swirl
        int bswap_needed;
323 ca20cf32 Blue Swirl
324 ca20cf32 Blue Swirl
#ifdef BSWAP_NEEDED
325 ca20cf32 Blue Swirl
        bswap_needed = 1;
326 ca20cf32 Blue Swirl
#else
327 ca20cf32 Blue Swirl
        bswap_needed = 0;
328 ca20cf32 Blue Swirl
#endif
329 409dbce5 Aurelien Jarno
        kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL,
330 409dbce5 Aurelien Jarno
                               NULL, NULL, NULL, 1, ELF_MACHINE, 0);
331 3ebf5aaf blueswir1
        if (kernel_size < 0)
332 293f78bc blueswir1
            kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
333 ca20cf32 Blue Swirl
                                    RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
334 ca20cf32 Blue Swirl
                                    TARGET_PAGE_SIZE);
335 3ebf5aaf blueswir1
        if (kernel_size < 0)
336 293f78bc blueswir1
            kernel_size = load_image_targphys(kernel_filename,
337 293f78bc blueswir1
                                              KERNEL_LOAD_ADDR,
338 293f78bc blueswir1
                                              RAM_size - KERNEL_LOAD_ADDR);
339 3ebf5aaf blueswir1
        if (kernel_size < 0) {
340 3ebf5aaf blueswir1
            fprintf(stderr, "qemu: could not load kernel '%s'\n",
341 3ebf5aaf blueswir1
                    kernel_filename);
342 3ebf5aaf blueswir1
            exit(1);
343 3ebf5aaf blueswir1
        }
344 3ebf5aaf blueswir1
345 3ebf5aaf blueswir1
        /* load initrd */
346 3ebf5aaf blueswir1
        initrd_size = 0;
347 3ebf5aaf blueswir1
        if (initrd_filename) {
348 293f78bc blueswir1
            initrd_size = load_image_targphys(initrd_filename,
349 293f78bc blueswir1
                                              INITRD_LOAD_ADDR,
350 293f78bc blueswir1
                                              RAM_size - INITRD_LOAD_ADDR);
351 3ebf5aaf blueswir1
            if (initrd_size < 0) {
352 3ebf5aaf blueswir1
                fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
353 3ebf5aaf blueswir1
                        initrd_filename);
354 3ebf5aaf blueswir1
                exit(1);
355 3ebf5aaf blueswir1
            }
356 3ebf5aaf blueswir1
        }
357 3ebf5aaf blueswir1
        if (initrd_size > 0) {
358 3ebf5aaf blueswir1
            for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
359 3c178e72 Gerd Hoffmann
                ptr = rom_ptr(KERNEL_LOAD_ADDR + i);
360 3c178e72 Gerd Hoffmann
                if (ldl_p(ptr) == 0x48647253) { // HdrS
361 3c178e72 Gerd Hoffmann
                    stl_p(ptr + 16, INITRD_LOAD_ADDR);
362 3c178e72 Gerd Hoffmann
                    stl_p(ptr + 20, initrd_size);
363 3ebf5aaf blueswir1
                    break;
364 3ebf5aaf blueswir1
                }
365 3ebf5aaf blueswir1
            }
366 3ebf5aaf blueswir1
        }
367 3ebf5aaf blueswir1
    }
368 3ebf5aaf blueswir1
    return kernel_size;
369 3ebf5aaf blueswir1
}
370 3ebf5aaf blueswir1
371 c227f099 Anthony Liguori
static void *iommu_init(target_phys_addr_t addr, uint32_t version, qemu_irq irq)
372 4b48bf05 Blue Swirl
{
373 4b48bf05 Blue Swirl
    DeviceState *dev;
374 4b48bf05 Blue Swirl
    SysBusDevice *s;
375 4b48bf05 Blue Swirl
376 4b48bf05 Blue Swirl
    dev = qdev_create(NULL, "iommu");
377 4b48bf05 Blue Swirl
    qdev_prop_set_uint32(dev, "version", version);
378 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
379 4b48bf05 Blue Swirl
    s = sysbus_from_qdev(dev);
380 4b48bf05 Blue Swirl
    sysbus_connect_irq(s, 0, irq);
381 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 0, addr);
382 4b48bf05 Blue Swirl
383 4b48bf05 Blue Swirl
    return s;
384 4b48bf05 Blue Swirl
}
385 4b48bf05 Blue Swirl
386 c227f099 Anthony Liguori
static void *sparc32_dma_init(target_phys_addr_t daddr, qemu_irq parent_irq,
387 86d1c388 Bob Breuer
                              void *iommu, qemu_irq *dev_irq, int is_ledma)
388 74ff8d90 Blue Swirl
{
389 74ff8d90 Blue Swirl
    DeviceState *dev;
390 74ff8d90 Blue Swirl
    SysBusDevice *s;
391 74ff8d90 Blue Swirl
392 74ff8d90 Blue Swirl
    dev = qdev_create(NULL, "sparc32_dma");
393 74ff8d90 Blue Swirl
    qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
394 86d1c388 Bob Breuer
    qdev_prop_set_uint32(dev, "is_ledma", is_ledma);
395 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
396 74ff8d90 Blue Swirl
    s = sysbus_from_qdev(dev);
397 74ff8d90 Blue Swirl
    sysbus_connect_irq(s, 0, parent_irq);
398 74ff8d90 Blue Swirl
    *dev_irq = qdev_get_gpio_in(dev, 0);
399 74ff8d90 Blue Swirl
    sysbus_mmio_map(s, 0, daddr);
400 74ff8d90 Blue Swirl
401 74ff8d90 Blue Swirl
    return s;
402 74ff8d90 Blue Swirl
}
403 74ff8d90 Blue Swirl
404 c227f099 Anthony Liguori
static void lance_init(NICInfo *nd, target_phys_addr_t leaddr,
405 74ff8d90 Blue Swirl
                       void *dma_opaque, qemu_irq irq)
406 9d07d757 Paul Brook
{
407 9d07d757 Paul Brook
    DeviceState *dev;
408 9d07d757 Paul Brook
    SysBusDevice *s;
409 74ff8d90 Blue Swirl
    qemu_irq reset;
410 9d07d757 Paul Brook
411 9d07d757 Paul Brook
    qemu_check_nic_model(&nd_table[0], "lance");
412 9d07d757 Paul Brook
413 9d07d757 Paul Brook
    dev = qdev_create(NULL, "lance");
414 76224833 Gerd Hoffmann
    qdev_set_nic_properties(dev, nd);
415 daa65491 Blue Swirl
    qdev_prop_set_ptr(dev, "dma", dma_opaque);
416 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
417 9d07d757 Paul Brook
    s = sysbus_from_qdev(dev);
418 9d07d757 Paul Brook
    sysbus_mmio_map(s, 0, leaddr);
419 9d07d757 Paul Brook
    sysbus_connect_irq(s, 0, irq);
420 74ff8d90 Blue Swirl
    reset = qdev_get_gpio_in(dev, 0);
421 74ff8d90 Blue Swirl
    qdev_connect_gpio_out(dma_opaque, 0, reset);
422 9d07d757 Paul Brook
}
423 9d07d757 Paul Brook
424 c227f099 Anthony Liguori
static DeviceState *slavio_intctl_init(target_phys_addr_t addr,
425 c227f099 Anthony Liguori
                                       target_phys_addr_t addrg,
426 462eda24 Blue Swirl
                                       qemu_irq **parent_irq)
427 4b48bf05 Blue Swirl
{
428 4b48bf05 Blue Swirl
    DeviceState *dev;
429 4b48bf05 Blue Swirl
    SysBusDevice *s;
430 4b48bf05 Blue Swirl
    unsigned int i, j;
431 4b48bf05 Blue Swirl
432 4b48bf05 Blue Swirl
    dev = qdev_create(NULL, "slavio_intctl");
433 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
434 4b48bf05 Blue Swirl
435 4b48bf05 Blue Swirl
    s = sysbus_from_qdev(dev);
436 4b48bf05 Blue Swirl
437 4b48bf05 Blue Swirl
    for (i = 0; i < MAX_CPUS; i++) {
438 4b48bf05 Blue Swirl
        for (j = 0; j < MAX_PILS; j++) {
439 4b48bf05 Blue Swirl
            sysbus_connect_irq(s, i * MAX_PILS + j, parent_irq[i][j]);
440 4b48bf05 Blue Swirl
        }
441 4b48bf05 Blue Swirl
    }
442 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 0, addrg);
443 4b48bf05 Blue Swirl
    for (i = 0; i < MAX_CPUS; i++) {
444 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, i + 1, addr + i * TARGET_PAGE_SIZE);
445 4b48bf05 Blue Swirl
    }
446 4b48bf05 Blue Swirl
447 4b48bf05 Blue Swirl
    return dev;
448 4b48bf05 Blue Swirl
}
449 4b48bf05 Blue Swirl
450 4b48bf05 Blue Swirl
#define SYS_TIMER_OFFSET      0x10000ULL
451 4b48bf05 Blue Swirl
#define CPU_TIMER_OFFSET(cpu) (0x1000ULL * cpu)
452 4b48bf05 Blue Swirl
453 c227f099 Anthony Liguori
static void slavio_timer_init_all(target_phys_addr_t addr, qemu_irq master_irq,
454 4b48bf05 Blue Swirl
                                  qemu_irq *cpu_irqs, unsigned int num_cpus)
455 4b48bf05 Blue Swirl
{
456 4b48bf05 Blue Swirl
    DeviceState *dev;
457 4b48bf05 Blue Swirl
    SysBusDevice *s;
458 4b48bf05 Blue Swirl
    unsigned int i;
459 4b48bf05 Blue Swirl
460 4b48bf05 Blue Swirl
    dev = qdev_create(NULL, "slavio_timer");
461 4b48bf05 Blue Swirl
    qdev_prop_set_uint32(dev, "num_cpus", num_cpus);
462 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
463 4b48bf05 Blue Swirl
    s = sysbus_from_qdev(dev);
464 4b48bf05 Blue Swirl
    sysbus_connect_irq(s, 0, master_irq);
465 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 0, addr + SYS_TIMER_OFFSET);
466 4b48bf05 Blue Swirl
467 4b48bf05 Blue Swirl
    for (i = 0; i < MAX_CPUS; i++) {
468 c227f099 Anthony Liguori
        sysbus_mmio_map(s, i + 1, addr + (target_phys_addr_t)CPU_TIMER_OFFSET(i));
469 4b48bf05 Blue Swirl
        sysbus_connect_irq(s, i + 1, cpu_irqs[i]);
470 4b48bf05 Blue Swirl
    }
471 4b48bf05 Blue Swirl
}
472 4b48bf05 Blue Swirl
473 4b48bf05 Blue Swirl
#define MISC_LEDS 0x01600000
474 4b48bf05 Blue Swirl
#define MISC_CFG  0x01800000
475 4b48bf05 Blue Swirl
#define MISC_DIAG 0x01a00000
476 4b48bf05 Blue Swirl
#define MISC_MDM  0x01b00000
477 4b48bf05 Blue Swirl
#define MISC_SYS  0x01f00000
478 4b48bf05 Blue Swirl
479 c227f099 Anthony Liguori
static void slavio_misc_init(target_phys_addr_t base,
480 c227f099 Anthony Liguori
                             target_phys_addr_t aux1_base,
481 c227f099 Anthony Liguori
                             target_phys_addr_t aux2_base, qemu_irq irq,
482 b2b6f6ec Blue Swirl
                             qemu_irq fdc_tc)
483 4b48bf05 Blue Swirl
{
484 4b48bf05 Blue Swirl
    DeviceState *dev;
485 4b48bf05 Blue Swirl
    SysBusDevice *s;
486 4b48bf05 Blue Swirl
487 4b48bf05 Blue Swirl
    dev = qdev_create(NULL, "slavio_misc");
488 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
489 4b48bf05 Blue Swirl
    s = sysbus_from_qdev(dev);
490 4b48bf05 Blue Swirl
    if (base) {
491 4b48bf05 Blue Swirl
        /* 8 bit registers */
492 4b48bf05 Blue Swirl
        /* Slavio control */
493 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 0, base + MISC_CFG);
494 4b48bf05 Blue Swirl
        /* Diagnostics */
495 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 1, base + MISC_DIAG);
496 4b48bf05 Blue Swirl
        /* Modem control */
497 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 2, base + MISC_MDM);
498 4b48bf05 Blue Swirl
        /* 16 bit registers */
499 4b48bf05 Blue Swirl
        /* ss600mp diag LEDs */
500 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 3, base + MISC_LEDS);
501 4b48bf05 Blue Swirl
        /* 32 bit registers */
502 4b48bf05 Blue Swirl
        /* System control */
503 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 4, base + MISC_SYS);
504 4b48bf05 Blue Swirl
    }
505 4b48bf05 Blue Swirl
    if (aux1_base) {
506 4b48bf05 Blue Swirl
        /* AUX 1 (Misc System Functions) */
507 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 5, aux1_base);
508 4b48bf05 Blue Swirl
    }
509 4b48bf05 Blue Swirl
    if (aux2_base) {
510 4b48bf05 Blue Swirl
        /* AUX 2 (Software Powerdown Control) */
511 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 6, aux2_base);
512 4b48bf05 Blue Swirl
    }
513 4b48bf05 Blue Swirl
    sysbus_connect_irq(s, 0, irq);
514 4b48bf05 Blue Swirl
    sysbus_connect_irq(s, 1, fdc_tc);
515 d9c32310 Blue Swirl
    qemu_system_powerdown = qdev_get_gpio_in(dev, 0);
516 4b48bf05 Blue Swirl
}
517 4b48bf05 Blue Swirl
518 c227f099 Anthony Liguori
static void ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version)
519 4b48bf05 Blue Swirl
{
520 4b48bf05 Blue Swirl
    DeviceState *dev;
521 4b48bf05 Blue Swirl
    SysBusDevice *s;
522 4b48bf05 Blue Swirl
523 4b48bf05 Blue Swirl
    dev = qdev_create(NULL, "eccmemctl");
524 4b48bf05 Blue Swirl
    qdev_prop_set_uint32(dev, "version", version);
525 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
526 4b48bf05 Blue Swirl
    s = sysbus_from_qdev(dev);
527 4b48bf05 Blue Swirl
    sysbus_connect_irq(s, 0, irq);
528 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 0, base);
529 4b48bf05 Blue Swirl
    if (version == 0) { // SS-600MP only
530 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 1, base + 0x1000);
531 4b48bf05 Blue Swirl
    }
532 4b48bf05 Blue Swirl
}
533 4b48bf05 Blue Swirl
534 c227f099 Anthony Liguori
static void apc_init(target_phys_addr_t power_base, qemu_irq cpu_halt)
535 4b48bf05 Blue Swirl
{
536 4b48bf05 Blue Swirl
    DeviceState *dev;
537 4b48bf05 Blue Swirl
    SysBusDevice *s;
538 4b48bf05 Blue Swirl
539 4b48bf05 Blue Swirl
    dev = qdev_create(NULL, "apc");
540 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
541 4b48bf05 Blue Swirl
    s = sysbus_from_qdev(dev);
542 4b48bf05 Blue Swirl
    /* Power management (APC) XXX: not a Slavio device */
543 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 0, power_base);
544 4b48bf05 Blue Swirl
    sysbus_connect_irq(s, 0, cpu_halt);
545 4b48bf05 Blue Swirl
}
546 4b48bf05 Blue Swirl
547 c227f099 Anthony Liguori
static void tcx_init(target_phys_addr_t addr, int vram_size, int width,
548 4b48bf05 Blue Swirl
                     int height, int depth)
549 4b48bf05 Blue Swirl
{
550 4b48bf05 Blue Swirl
    DeviceState *dev;
551 4b48bf05 Blue Swirl
    SysBusDevice *s;
552 4b48bf05 Blue Swirl
553 4b48bf05 Blue Swirl
    dev = qdev_create(NULL, "SUNW,tcx");
554 4b48bf05 Blue Swirl
    qdev_prop_set_taddr(dev, "addr", addr);
555 4b48bf05 Blue Swirl
    qdev_prop_set_uint32(dev, "vram_size", vram_size);
556 4b48bf05 Blue Swirl
    qdev_prop_set_uint16(dev, "width", width);
557 4b48bf05 Blue Swirl
    qdev_prop_set_uint16(dev, "height", height);
558 4b48bf05 Blue Swirl
    qdev_prop_set_uint16(dev, "depth", depth);
559 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
560 4b48bf05 Blue Swirl
    s = sysbus_from_qdev(dev);
561 4b48bf05 Blue Swirl
    /* 8-bit plane */
562 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 0, addr + 0x00800000ULL);
563 4b48bf05 Blue Swirl
    /* DAC */
564 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 1, addr + 0x00200000ULL);
565 4b48bf05 Blue Swirl
    /* TEC (dummy) */
566 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 2, addr + 0x00700000ULL);
567 4b48bf05 Blue Swirl
    /* THC 24 bit: NetBSD writes here even with 8-bit display: dummy */
568 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 3, addr + 0x00301000ULL);
569 4b48bf05 Blue Swirl
    if (depth == 24) {
570 4b48bf05 Blue Swirl
        /* 24-bit plane */
571 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 4, addr + 0x02000000ULL);
572 4b48bf05 Blue Swirl
        /* Control plane */
573 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 5, addr + 0x0a000000ULL);
574 4b48bf05 Blue Swirl
    } else {
575 4b48bf05 Blue Swirl
        /* THC 8 bit (dummy) */
576 4b48bf05 Blue Swirl
        sysbus_mmio_map(s, 4, addr + 0x00300000ULL);
577 4b48bf05 Blue Swirl
    }
578 4b48bf05 Blue Swirl
}
579 4b48bf05 Blue Swirl
580 325f2747 Blue Swirl
/* NCR89C100/MACIO Internal ID register */
581 325f2747 Blue Swirl
static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
582 325f2747 Blue Swirl
583 c227f099 Anthony Liguori
static void idreg_init(target_phys_addr_t addr)
584 325f2747 Blue Swirl
{
585 325f2747 Blue Swirl
    DeviceState *dev;
586 325f2747 Blue Swirl
    SysBusDevice *s;
587 325f2747 Blue Swirl
588 325f2747 Blue Swirl
    dev = qdev_create(NULL, "macio_idreg");
589 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
590 325f2747 Blue Swirl
    s = sysbus_from_qdev(dev);
591 325f2747 Blue Swirl
592 325f2747 Blue Swirl
    sysbus_mmio_map(s, 0, addr);
593 325f2747 Blue Swirl
    cpu_physical_memory_write_rom(addr, idreg_data, sizeof(idreg_data));
594 325f2747 Blue Swirl
}
595 325f2747 Blue Swirl
596 81a322d4 Gerd Hoffmann
static int idreg_init1(SysBusDevice *dev)
597 325f2747 Blue Swirl
{
598 c227f099 Anthony Liguori
    ram_addr_t idreg_offset;
599 325f2747 Blue Swirl
600 1724f049 Alex Williamson
    idreg_offset = qemu_ram_alloc(NULL, "sun4m.idreg", sizeof(idreg_data));
601 325f2747 Blue Swirl
    sysbus_init_mmio(dev, sizeof(idreg_data), idreg_offset | IO_MEM_ROM);
602 81a322d4 Gerd Hoffmann
    return 0;
603 325f2747 Blue Swirl
}
604 325f2747 Blue Swirl
605 325f2747 Blue Swirl
static SysBusDeviceInfo idreg_info = {
606 325f2747 Blue Swirl
    .init = idreg_init1,
607 325f2747 Blue Swirl
    .qdev.name  = "macio_idreg",
608 325f2747 Blue Swirl
    .qdev.size  = sizeof(SysBusDevice),
609 325f2747 Blue Swirl
};
610 325f2747 Blue Swirl
611 325f2747 Blue Swirl
static void idreg_register_devices(void)
612 325f2747 Blue Swirl
{
613 325f2747 Blue Swirl
    sysbus_register_withprop(&idreg_info);
614 325f2747 Blue Swirl
}
615 325f2747 Blue Swirl
616 325f2747 Blue Swirl
device_init(idreg_register_devices);
617 325f2747 Blue Swirl
618 c5de386a Artyom Tarasenko
/* SS-5 TCX AFX register */
619 c5de386a Artyom Tarasenko
static void afx_init(target_phys_addr_t addr)
620 c5de386a Artyom Tarasenko
{
621 c5de386a Artyom Tarasenko
    DeviceState *dev;
622 c5de386a Artyom Tarasenko
    SysBusDevice *s;
623 c5de386a Artyom Tarasenko
624 c5de386a Artyom Tarasenko
    dev = qdev_create(NULL, "tcx_afx");
625 c5de386a Artyom Tarasenko
    qdev_init_nofail(dev);
626 c5de386a Artyom Tarasenko
    s = sysbus_from_qdev(dev);
627 c5de386a Artyom Tarasenko
628 c5de386a Artyom Tarasenko
    sysbus_mmio_map(s, 0, addr);
629 c5de386a Artyom Tarasenko
}
630 c5de386a Artyom Tarasenko
631 c5de386a Artyom Tarasenko
static int afx_init1(SysBusDevice *dev)
632 c5de386a Artyom Tarasenko
{
633 c5de386a Artyom Tarasenko
    ram_addr_t afx_offset;
634 c5de386a Artyom Tarasenko
635 1724f049 Alex Williamson
    afx_offset = qemu_ram_alloc(NULL, "sun4m.afx", 4);
636 c5de386a Artyom Tarasenko
    sysbus_init_mmio(dev, 4, afx_offset | IO_MEM_RAM);
637 c5de386a Artyom Tarasenko
    return 0;
638 c5de386a Artyom Tarasenko
}
639 c5de386a Artyom Tarasenko
640 c5de386a Artyom Tarasenko
static SysBusDeviceInfo afx_info = {
641 c5de386a Artyom Tarasenko
    .init = afx_init1,
642 c5de386a Artyom Tarasenko
    .qdev.name  = "tcx_afx",
643 c5de386a Artyom Tarasenko
    .qdev.size  = sizeof(SysBusDevice),
644 c5de386a Artyom Tarasenko
};
645 c5de386a Artyom Tarasenko
646 c5de386a Artyom Tarasenko
static void afx_register_devices(void)
647 c5de386a Artyom Tarasenko
{
648 c5de386a Artyom Tarasenko
    sysbus_register_withprop(&afx_info);
649 c5de386a Artyom Tarasenko
}
650 c5de386a Artyom Tarasenko
651 c5de386a Artyom Tarasenko
device_init(afx_register_devices);
652 c5de386a Artyom Tarasenko
653 f48f6569 Blue Swirl
/* Boot PROM (OpenBIOS) */
654 409dbce5 Aurelien Jarno
static uint64_t translate_prom_address(void *opaque, uint64_t addr)
655 409dbce5 Aurelien Jarno
{
656 409dbce5 Aurelien Jarno
    target_phys_addr_t *base_addr = (target_phys_addr_t *)opaque;
657 409dbce5 Aurelien Jarno
    return addr + *base_addr - PROM_VADDR;
658 409dbce5 Aurelien Jarno
}
659 409dbce5 Aurelien Jarno
660 c227f099 Anthony Liguori
static void prom_init(target_phys_addr_t addr, const char *bios_name)
661 f48f6569 Blue Swirl
{
662 f48f6569 Blue Swirl
    DeviceState *dev;
663 f48f6569 Blue Swirl
    SysBusDevice *s;
664 f48f6569 Blue Swirl
    char *filename;
665 f48f6569 Blue Swirl
    int ret;
666 f48f6569 Blue Swirl
667 f48f6569 Blue Swirl
    dev = qdev_create(NULL, "openprom");
668 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
669 f48f6569 Blue Swirl
    s = sysbus_from_qdev(dev);
670 f48f6569 Blue Swirl
671 f48f6569 Blue Swirl
    sysbus_mmio_map(s, 0, addr);
672 f48f6569 Blue Swirl
673 f48f6569 Blue Swirl
    /* load boot prom */
674 f48f6569 Blue Swirl
    if (bios_name == NULL) {
675 f48f6569 Blue Swirl
        bios_name = PROM_FILENAME;
676 f48f6569 Blue Swirl
    }
677 f48f6569 Blue Swirl
    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
678 f48f6569 Blue Swirl
    if (filename) {
679 409dbce5 Aurelien Jarno
        ret = load_elf(filename, translate_prom_address, &addr, NULL,
680 409dbce5 Aurelien Jarno
                       NULL, NULL, 1, ELF_MACHINE, 0);
681 f48f6569 Blue Swirl
        if (ret < 0 || ret > PROM_SIZE_MAX) {
682 f48f6569 Blue Swirl
            ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
683 f48f6569 Blue Swirl
        }
684 f48f6569 Blue Swirl
        qemu_free(filename);
685 f48f6569 Blue Swirl
    } else {
686 f48f6569 Blue Swirl
        ret = -1;
687 f48f6569 Blue Swirl
    }
688 f48f6569 Blue Swirl
    if (ret < 0 || ret > PROM_SIZE_MAX) {
689 f48f6569 Blue Swirl
        fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name);
690 f48f6569 Blue Swirl
        exit(1);
691 f48f6569 Blue Swirl
    }
692 f48f6569 Blue Swirl
}
693 f48f6569 Blue Swirl
694 81a322d4 Gerd Hoffmann
static int prom_init1(SysBusDevice *dev)
695 f48f6569 Blue Swirl
{
696 c227f099 Anthony Liguori
    ram_addr_t prom_offset;
697 f48f6569 Blue Swirl
698 1724f049 Alex Williamson
    prom_offset = qemu_ram_alloc(NULL, "sun4m.prom", PROM_SIZE_MAX);
699 f48f6569 Blue Swirl
    sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM);
700 81a322d4 Gerd Hoffmann
    return 0;
701 f48f6569 Blue Swirl
}
702 f48f6569 Blue Swirl
703 f48f6569 Blue Swirl
static SysBusDeviceInfo prom_info = {
704 f48f6569 Blue Swirl
    .init = prom_init1,
705 f48f6569 Blue Swirl
    .qdev.name  = "openprom",
706 f48f6569 Blue Swirl
    .qdev.size  = sizeof(SysBusDevice),
707 ee6847d1 Gerd Hoffmann
    .qdev.props = (Property[]) {
708 ee6847d1 Gerd Hoffmann
        {/* end of property list */}
709 f48f6569 Blue Swirl
    }
710 f48f6569 Blue Swirl
};
711 f48f6569 Blue Swirl
712 f48f6569 Blue Swirl
static void prom_register_devices(void)
713 f48f6569 Blue Swirl
{
714 f48f6569 Blue Swirl
    sysbus_register_withprop(&prom_info);
715 f48f6569 Blue Swirl
}
716 f48f6569 Blue Swirl
717 f48f6569 Blue Swirl
device_init(prom_register_devices);
718 f48f6569 Blue Swirl
719 ee6847d1 Gerd Hoffmann
typedef struct RamDevice
720 ee6847d1 Gerd Hoffmann
{
721 ee6847d1 Gerd Hoffmann
    SysBusDevice busdev;
722 04843626 Blue Swirl
    uint64_t size;
723 ee6847d1 Gerd Hoffmann
} RamDevice;
724 ee6847d1 Gerd Hoffmann
725 a350db85 Blue Swirl
/* System RAM */
726 81a322d4 Gerd Hoffmann
static int ram_init1(SysBusDevice *dev)
727 a350db85 Blue Swirl
{
728 c227f099 Anthony Liguori
    ram_addr_t RAM_size, ram_offset;
729 ee6847d1 Gerd Hoffmann
    RamDevice *d = FROM_SYSBUS(RamDevice, dev);
730 a350db85 Blue Swirl
731 ee6847d1 Gerd Hoffmann
    RAM_size = d->size;
732 a350db85 Blue Swirl
733 1724f049 Alex Williamson
    ram_offset = qemu_ram_alloc(NULL, "sun4m.ram", RAM_size);
734 a350db85 Blue Swirl
    sysbus_init_mmio(dev, RAM_size, ram_offset);
735 81a322d4 Gerd Hoffmann
    return 0;
736 a350db85 Blue Swirl
}
737 a350db85 Blue Swirl
738 c227f099 Anthony Liguori
static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size,
739 a350db85 Blue Swirl
                     uint64_t max_mem)
740 a350db85 Blue Swirl
{
741 a350db85 Blue Swirl
    DeviceState *dev;
742 a350db85 Blue Swirl
    SysBusDevice *s;
743 ee6847d1 Gerd Hoffmann
    RamDevice *d;
744 a350db85 Blue Swirl
745 a350db85 Blue Swirl
    /* allocate RAM */
746 a350db85 Blue Swirl
    if ((uint64_t)RAM_size > max_mem) {
747 a350db85 Blue Swirl
        fprintf(stderr,
748 a350db85 Blue Swirl
                "qemu: Too much memory for this machine: %d, maximum %d\n",
749 a350db85 Blue Swirl
                (unsigned int)(RAM_size / (1024 * 1024)),
750 a350db85 Blue Swirl
                (unsigned int)(max_mem / (1024 * 1024)));
751 a350db85 Blue Swirl
        exit(1);
752 a350db85 Blue Swirl
    }
753 a350db85 Blue Swirl
    dev = qdev_create(NULL, "memory");
754 a350db85 Blue Swirl
    s = sysbus_from_qdev(dev);
755 a350db85 Blue Swirl
756 ee6847d1 Gerd Hoffmann
    d = FROM_SYSBUS(RamDevice, s);
757 ee6847d1 Gerd Hoffmann
    d->size = RAM_size;
758 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
759 ee6847d1 Gerd Hoffmann
760 a350db85 Blue Swirl
    sysbus_mmio_map(s, 0, addr);
761 a350db85 Blue Swirl
}
762 a350db85 Blue Swirl
763 a350db85 Blue Swirl
static SysBusDeviceInfo ram_info = {
764 a350db85 Blue Swirl
    .init = ram_init1,
765 a350db85 Blue Swirl
    .qdev.name  = "memory",
766 ee6847d1 Gerd Hoffmann
    .qdev.size  = sizeof(RamDevice),
767 ee6847d1 Gerd Hoffmann
    .qdev.props = (Property[]) {
768 c885159a Gerd Hoffmann
        DEFINE_PROP_UINT64("size", RamDevice, size, 0),
769 c885159a Gerd Hoffmann
        DEFINE_PROP_END_OF_LIST(),
770 a350db85 Blue Swirl
    }
771 a350db85 Blue Swirl
};
772 a350db85 Blue Swirl
773 a350db85 Blue Swirl
static void ram_register_devices(void)
774 a350db85 Blue Swirl
{
775 a350db85 Blue Swirl
    sysbus_register_withprop(&ram_info);
776 a350db85 Blue Swirl
}
777 a350db85 Blue Swirl
778 a350db85 Blue Swirl
device_init(ram_register_devices);
779 a350db85 Blue Swirl
780 89835363 Blue Swirl
static void cpu_devinit(const char *cpu_model, unsigned int id,
781 89835363 Blue Swirl
                        uint64_t prom_addr, qemu_irq **cpu_irqs)
782 666713c0 Blue Swirl
{
783 666713c0 Blue Swirl
    CPUState *env;
784 666713c0 Blue Swirl
785 666713c0 Blue Swirl
    env = cpu_init(cpu_model);
786 666713c0 Blue Swirl
    if (!env) {
787 666713c0 Blue Swirl
        fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
788 666713c0 Blue Swirl
        exit(1);
789 666713c0 Blue Swirl
    }
790 666713c0 Blue Swirl
791 666713c0 Blue Swirl
    cpu_sparc_set_id(env, id);
792 666713c0 Blue Swirl
    if (id == 0) {
793 666713c0 Blue Swirl
        qemu_register_reset(main_cpu_reset, env);
794 666713c0 Blue Swirl
    } else {
795 666713c0 Blue Swirl
        qemu_register_reset(secondary_cpu_reset, env);
796 666713c0 Blue Swirl
        env->halted = 1;
797 666713c0 Blue Swirl
    }
798 666713c0 Blue Swirl
    *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
799 666713c0 Blue Swirl
    env->prom_addr = prom_addr;
800 666713c0 Blue Swirl
}
801 666713c0 Blue Swirl
802 c227f099 Anthony Liguori
static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
803 3ebf5aaf blueswir1
                          const char *boot_device,
804 3023f332 aliguori
                          const char *kernel_filename,
805 3ebf5aaf blueswir1
                          const char *kernel_cmdline,
806 3ebf5aaf blueswir1
                          const char *initrd_filename, const char *cpu_model)
807 420557e8 bellard
{
808 713c45fa bellard
    unsigned int i;
809 cfb9de9c Paul Brook
    void *iommu, *espdma, *ledma, *nvram;
810 a1961a4b Blue Swirl
    qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
811 6f6260c7 Blue Swirl
        espdma_irq, ledma_irq;
812 73d74342 Blue Swirl
    qemu_irq esp_reset, dma_enable;
813 2582cfa0 Blue Swirl
    qemu_irq fdc_tc;
814 6d0c293d blueswir1
    qemu_irq *cpu_halt;
815 5c6602c5 blueswir1
    unsigned long kernel_size;
816 fd8014e1 Gerd Hoffmann
    DriveInfo *fd[MAX_FD];
817 3cce6243 blueswir1
    void *fw_cfg;
818 9a62fb24 Bob Breuer
    unsigned int num_vsimms;
819 420557e8 bellard
820 ba3c64fb bellard
    /* init CPUs */
821 3ebf5aaf blueswir1
    if (!cpu_model)
822 3ebf5aaf blueswir1
        cpu_model = hwdef->default_cpu_model;
823 b3a23197 blueswir1
824 ba3c64fb bellard
    for(i = 0; i < smp_cpus; i++) {
825 89835363 Blue Swirl
        cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
826 ba3c64fb bellard
    }
827 b3a23197 blueswir1
828 b3a23197 blueswir1
    for (i = smp_cpus; i < MAX_CPUS; i++)
829 b3a23197 blueswir1
        cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
830 b3a23197 blueswir1
831 3ebf5aaf blueswir1
832 3ebf5aaf blueswir1
    /* set up devices */
833 a350db85 Blue Swirl
    ram_init(0, RAM_size, hwdef->max_mem);
834 676d9b9b Artyom Tarasenko
    /* models without ECC don't trap when missing ram is accessed */
835 676d9b9b Artyom Tarasenko
    if (!hwdef->ecc_base) {
836 676d9b9b Artyom Tarasenko
        empty_slot_init(RAM_size, hwdef->max_mem - RAM_size);
837 676d9b9b Artyom Tarasenko
    }
838 a350db85 Blue Swirl
839 f48f6569 Blue Swirl
    prom_init(hwdef->slavio_base, bios_name);
840 f48f6569 Blue Swirl
841 d453c2c3 Blue Swirl
    slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
842 d453c2c3 Blue Swirl
                                       hwdef->intctl_base + 0x10000ULL,
843 462eda24 Blue Swirl
                                       cpu_irqs);
844 a1961a4b Blue Swirl
845 a1961a4b Blue Swirl
    for (i = 0; i < 32; i++) {
846 d453c2c3 Blue Swirl
        slavio_irq[i] = qdev_get_gpio_in(slavio_intctl, i);
847 a1961a4b Blue Swirl
    }
848 a1961a4b Blue Swirl
    for (i = 0; i < MAX_CPUS; i++) {
849 d453c2c3 Blue Swirl
        slavio_cpu_irq[i] = qdev_get_gpio_in(slavio_intctl, 32 + i);
850 a1961a4b Blue Swirl
    }
851 b3a23197 blueswir1
852 fe096129 blueswir1
    if (hwdef->idreg_base) {
853 325f2747 Blue Swirl
        idreg_init(hwdef->idreg_base);
854 4c2485de blueswir1
    }
855 4c2485de blueswir1
856 c5de386a Artyom Tarasenko
    if (hwdef->afx_base) {
857 c5de386a Artyom Tarasenko
        afx_init(hwdef->afx_base);
858 c5de386a Artyom Tarasenko
    }
859 c5de386a Artyom Tarasenko
860 ff403da6 blueswir1
    iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
861 c533e0b3 Blue Swirl
                       slavio_irq[30]);
862 ff403da6 blueswir1
863 3386376c Artyom Tarasenko
    if (hwdef->iommu_pad_base) {
864 3386376c Artyom Tarasenko
        /* On the real hardware (SS-5, LX) the MMU is not padded, but aliased.
865 3386376c Artyom Tarasenko
           Software shouldn't use aliased addresses, neither should it crash
866 3386376c Artyom Tarasenko
           when does. Using empty_slot instead of aliasing can help with
867 3386376c Artyom Tarasenko
           debugging such accesses */
868 3386376c Artyom Tarasenko
        empty_slot_init(hwdef->iommu_pad_base,hwdef->iommu_pad_len);
869 3386376c Artyom Tarasenko
    }
870 3386376c Artyom Tarasenko
871 c533e0b3 Blue Swirl
    espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[18],
872 86d1c388 Bob Breuer
                              iommu, &espdma_irq, 0);
873 2d069bab blueswir1
874 5aca8c3b blueswir1
    ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
875 86d1c388 Bob Breuer
                             slavio_irq[16], iommu, &ledma_irq, 1);
876 ba3c64fb bellard
877 eee0b836 blueswir1
    if (graphic_depth != 8 && graphic_depth != 24) {
878 eee0b836 blueswir1
        fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
879 eee0b836 blueswir1
        exit (1);
880 eee0b836 blueswir1
    }
881 9a62fb24 Bob Breuer
    num_vsimms = 0;
882 9a62fb24 Bob Breuer
    if (num_vsimms == 0) {
883 9a62fb24 Bob Breuer
        tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
884 9a62fb24 Bob Breuer
                 graphic_depth);
885 9a62fb24 Bob Breuer
    }
886 9a62fb24 Bob Breuer
887 9a62fb24 Bob Breuer
    for (i = num_vsimms; i < MAX_VSIMMS; i++) {
888 9a62fb24 Bob Breuer
        /* vsimm registers probed by OBP */
889 9a62fb24 Bob Breuer
        if (hwdef->vsimm[i].reg_base) {
890 9a62fb24 Bob Breuer
            empty_slot_init(hwdef->vsimm[i].reg_base, 0x2000);
891 9a62fb24 Bob Breuer
        }
892 9a62fb24 Bob Breuer
    }
893 9a62fb24 Bob Breuer
894 9a62fb24 Bob Breuer
    if (hwdef->sx_base) {
895 9a62fb24 Bob Breuer
        empty_slot_init(hwdef->sx_base, 0x2000);
896 9a62fb24 Bob Breuer
    }
897 dbe06e18 blueswir1
898 74ff8d90 Blue Swirl
    lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
899 dbe06e18 blueswir1
900 d95d8f1c Blue Swirl
    nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
901 81732d19 blueswir1
902 c533e0b3 Blue Swirl
    slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
903 81732d19 blueswir1
904 c533e0b3 Blue Swirl
    slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[14],
905 993fbfdb Anthony Liguori
                              display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
906 b81b3b10 bellard
    // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
907 b81b3b10 bellard
    // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
908 c533e0b3 Blue Swirl
    escc_init(hwdef->serial_base, slavio_irq[15], slavio_irq[15],
909 aeeb69c7 aurel32
              serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
910 741402f9 blueswir1
911 6d0c293d blueswir1
    cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
912 b2b6f6ec Blue Swirl
    slavio_misc_init(hwdef->slavio_base, hwdef->aux1_base, hwdef->aux2_base,
913 b2b6f6ec Blue Swirl
                     slavio_irq[30], fdc_tc);
914 b2b6f6ec Blue Swirl
915 2582cfa0 Blue Swirl
    if (hwdef->apc_base) {
916 2582cfa0 Blue Swirl
        apc_init(hwdef->apc_base, cpu_halt[0]);
917 2582cfa0 Blue Swirl
    }
918 2be17ebd blueswir1
919 fe096129 blueswir1
    if (hwdef->fd_base) {
920 e4bcb14c ths
        /* there is zero or one floppy drive */
921 309e60bd blueswir1
        memset(fd, 0, sizeof(fd));
922 fd8014e1 Gerd Hoffmann
        fd[0] = drive_get(IF_FLOPPY, 0, 0);
923 c533e0b3 Blue Swirl
        sun4m_fdctrl_init(slavio_irq[22], hwdef->fd_base, fd,
924 2582cfa0 Blue Swirl
                          &fdc_tc);
925 e4bcb14c ths
    }
926 e4bcb14c ths
927 e4bcb14c ths
    if (drive_get_max_bus(IF_SCSI) > 0) {
928 e4bcb14c ths
        fprintf(stderr, "qemu: too many SCSI bus\n");
929 e4bcb14c ths
        exit(1);
930 e4bcb14c ths
    }
931 e4bcb14c ths
932 cfb9de9c Paul Brook
    esp_init(hwdef->esp_base, 2,
933 cfb9de9c Paul Brook
             espdma_memory_read, espdma_memory_write,
934 73d74342 Blue Swirl
             espdma, espdma_irq, &esp_reset, &dma_enable);
935 74ff8d90 Blue Swirl
936 73d74342 Blue Swirl
    qdev_connect_gpio_out(espdma, 0, esp_reset);
937 73d74342 Blue Swirl
    qdev_connect_gpio_out(espdma, 1, dma_enable);
938 f1587550 ths
939 fa28ec52 Blue Swirl
    if (hwdef->cs_base) {
940 fa28ec52 Blue Swirl
        sysbus_create_simple("SUNW,CS4231", hwdef->cs_base,
941 c533e0b3 Blue Swirl
                             slavio_irq[5]);
942 fa28ec52 Blue Swirl
    }
943 b3ceef24 blueswir1
944 9a62fb24 Bob Breuer
    if (hwdef->dbri_base) {
945 9a62fb24 Bob Breuer
        /* ISDN chip with attached CS4215 audio codec */
946 9a62fb24 Bob Breuer
        /* prom space */
947 9a62fb24 Bob Breuer
        empty_slot_init(hwdef->dbri_base+0x1000, 0x30);
948 9a62fb24 Bob Breuer
        /* reg space */
949 9a62fb24 Bob Breuer
        empty_slot_init(hwdef->dbri_base+0x10000, 0x100);
950 9a62fb24 Bob Breuer
    }
951 9a62fb24 Bob Breuer
952 9a62fb24 Bob Breuer
    if (hwdef->bpp_base) {
953 9a62fb24 Bob Breuer
        /* parallel port */
954 9a62fb24 Bob Breuer
        empty_slot_init(hwdef->bpp_base, 0x20);
955 9a62fb24 Bob Breuer
    }
956 9a62fb24 Bob Breuer
957 293f78bc blueswir1
    kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
958 293f78bc blueswir1
                                    RAM_size);
959 36cd9210 blueswir1
960 36cd9210 blueswir1
    nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
961 b3ceef24 blueswir1
               boot_device, RAM_size, kernel_size, graphic_width,
962 905fdcb5 blueswir1
               graphic_height, graphic_depth, hwdef->nvram_machine_id,
963 905fdcb5 blueswir1
               "Sun4m");
964 7eb0c8e8 blueswir1
965 fe096129 blueswir1
    if (hwdef->ecc_base)
966 c533e0b3 Blue Swirl
        ecc_init(hwdef->ecc_base, slavio_irq[28],
967 e42c20b4 blueswir1
                 hwdef->ecc_version);
968 3cce6243 blueswir1
969 3cce6243 blueswir1
    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
970 3cce6243 blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
971 905fdcb5 blueswir1
    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
972 905fdcb5 blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
973 fbfcf955 blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
974 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
975 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
976 513f789f blueswir1
    if (kernel_cmdline) {
977 513f789f blueswir1
        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
978 3c178e72 Gerd Hoffmann
        pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
979 6bb4ca57 Blue Swirl
        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
980 6bb4ca57 Blue Swirl
                         (uint8_t*)strdup(kernel_cmdline),
981 6bb4ca57 Blue Swirl
                         strlen(kernel_cmdline) + 1);
982 748a4ee3 Blue Swirl
        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
983 748a4ee3 Blue Swirl
                       strlen(kernel_cmdline) + 1);
984 513f789f blueswir1
    } else {
985 513f789f blueswir1
        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
986 748a4ee3 Blue Swirl
        fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
987 513f789f blueswir1
    }
988 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
989 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
990 513f789f blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
991 513f789f blueswir1
    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
992 36cd9210 blueswir1
}
993 36cd9210 blueswir1
994 905fdcb5 blueswir1
enum {
995 905fdcb5 blueswir1
    ss2_id = 0,
996 905fdcb5 blueswir1
    ss5_id = 32,
997 905fdcb5 blueswir1
    vger_id,
998 905fdcb5 blueswir1
    lx_id,
999 905fdcb5 blueswir1
    ss4_id,
1000 905fdcb5 blueswir1
    scls_id,
1001 905fdcb5 blueswir1
    sbook_id,
1002 905fdcb5 blueswir1
    ss10_id = 64,
1003 905fdcb5 blueswir1
    ss20_id,
1004 905fdcb5 blueswir1
    ss600mp_id,
1005 905fdcb5 blueswir1
    ss1000_id = 96,
1006 905fdcb5 blueswir1
    ss2000_id,
1007 905fdcb5 blueswir1
};
1008 905fdcb5 blueswir1
1009 8137cde8 blueswir1
static const struct sun4m_hwdef sun4m_hwdefs[] = {
1010 36cd9210 blueswir1
    /* SS-5 */
1011 36cd9210 blueswir1
    {
1012 36cd9210 blueswir1
        .iommu_base   = 0x10000000,
1013 3386376c Artyom Tarasenko
        .iommu_pad_base = 0x10004000,
1014 3386376c Artyom Tarasenko
        .iommu_pad_len  = 0x0fffb000,
1015 36cd9210 blueswir1
        .tcx_base     = 0x50000000,
1016 36cd9210 blueswir1
        .cs_base      = 0x6c000000,
1017 384ccb5d blueswir1
        .slavio_base  = 0x70000000,
1018 36cd9210 blueswir1
        .ms_kb_base   = 0x71000000,
1019 36cd9210 blueswir1
        .serial_base  = 0x71100000,
1020 36cd9210 blueswir1
        .nvram_base   = 0x71200000,
1021 36cd9210 blueswir1
        .fd_base      = 0x71400000,
1022 36cd9210 blueswir1
        .counter_base = 0x71d00000,
1023 36cd9210 blueswir1
        .intctl_base  = 0x71e00000,
1024 4c2485de blueswir1
        .idreg_base   = 0x78000000,
1025 36cd9210 blueswir1
        .dma_base     = 0x78400000,
1026 36cd9210 blueswir1
        .esp_base     = 0x78800000,
1027 36cd9210 blueswir1
        .le_base      = 0x78c00000,
1028 127fc407 blueswir1
        .apc_base     = 0x6a000000,
1029 c5de386a Artyom Tarasenko
        .afx_base     = 0x6e000000,
1030 0019ad53 blueswir1
        .aux1_base    = 0x71900000,
1031 0019ad53 blueswir1
        .aux2_base    = 0x71910000,
1032 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1033 905fdcb5 blueswir1
        .machine_id = ss5_id,
1034 cf3102ac blueswir1
        .iommu_version = 0x05000000,
1035 3ebf5aaf blueswir1
        .max_mem = 0x10000000,
1036 3ebf5aaf blueswir1
        .default_cpu_model = "Fujitsu MB86904",
1037 e0353fe2 blueswir1
    },
1038 e0353fe2 blueswir1
    /* SS-10 */
1039 e0353fe2 blueswir1
    {
1040 5dcb6b91 blueswir1
        .iommu_base   = 0xfe0000000ULL,
1041 5dcb6b91 blueswir1
        .tcx_base     = 0xe20000000ULL,
1042 5dcb6b91 blueswir1
        .slavio_base  = 0xff0000000ULL,
1043 5dcb6b91 blueswir1
        .ms_kb_base   = 0xff1000000ULL,
1044 5dcb6b91 blueswir1
        .serial_base  = 0xff1100000ULL,
1045 5dcb6b91 blueswir1
        .nvram_base   = 0xff1200000ULL,
1046 5dcb6b91 blueswir1
        .fd_base      = 0xff1700000ULL,
1047 5dcb6b91 blueswir1
        .counter_base = 0xff1300000ULL,
1048 5dcb6b91 blueswir1
        .intctl_base  = 0xff1400000ULL,
1049 4c2485de blueswir1
        .idreg_base   = 0xef0000000ULL,
1050 5dcb6b91 blueswir1
        .dma_base     = 0xef0400000ULL,
1051 5dcb6b91 blueswir1
        .esp_base     = 0xef0800000ULL,
1052 5dcb6b91 blueswir1
        .le_base      = 0xef0c00000ULL,
1053 0019ad53 blueswir1
        .apc_base     = 0xefa000000ULL, // XXX should not exist
1054 127fc407 blueswir1
        .aux1_base    = 0xff1800000ULL,
1055 127fc407 blueswir1
        .aux2_base    = 0xff1a01000ULL,
1056 7eb0c8e8 blueswir1
        .ecc_base     = 0xf00000000ULL,
1057 7eb0c8e8 blueswir1
        .ecc_version  = 0x10000000, // version 0, implementation 1
1058 905fdcb5 blueswir1
        .nvram_machine_id = 0x72,
1059 905fdcb5 blueswir1
        .machine_id = ss10_id,
1060 7fbfb139 blueswir1
        .iommu_version = 0x03000000,
1061 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
1062 3ebf5aaf blueswir1
        .default_cpu_model = "TI SuperSparc II",
1063 36cd9210 blueswir1
    },
1064 6a3b9cc9 blueswir1
    /* SS-600MP */
1065 6a3b9cc9 blueswir1
    {
1066 6a3b9cc9 blueswir1
        .iommu_base   = 0xfe0000000ULL,
1067 6a3b9cc9 blueswir1
        .tcx_base     = 0xe20000000ULL,
1068 6a3b9cc9 blueswir1
        .slavio_base  = 0xff0000000ULL,
1069 6a3b9cc9 blueswir1
        .ms_kb_base   = 0xff1000000ULL,
1070 6a3b9cc9 blueswir1
        .serial_base  = 0xff1100000ULL,
1071 6a3b9cc9 blueswir1
        .nvram_base   = 0xff1200000ULL,
1072 6a3b9cc9 blueswir1
        .counter_base = 0xff1300000ULL,
1073 6a3b9cc9 blueswir1
        .intctl_base  = 0xff1400000ULL,
1074 6a3b9cc9 blueswir1
        .dma_base     = 0xef0081000ULL,
1075 6a3b9cc9 blueswir1
        .esp_base     = 0xef0080000ULL,
1076 6a3b9cc9 blueswir1
        .le_base      = 0xef0060000ULL,
1077 0019ad53 blueswir1
        .apc_base     = 0xefa000000ULL, // XXX should not exist
1078 127fc407 blueswir1
        .aux1_base    = 0xff1800000ULL,
1079 127fc407 blueswir1
        .aux2_base    = 0xff1a01000ULL, // XXX should not exist
1080 7eb0c8e8 blueswir1
        .ecc_base     = 0xf00000000ULL,
1081 7eb0c8e8 blueswir1
        .ecc_version  = 0x00000000, // version 0, implementation 0
1082 905fdcb5 blueswir1
        .nvram_machine_id = 0x71,
1083 905fdcb5 blueswir1
        .machine_id = ss600mp_id,
1084 7fbfb139 blueswir1
        .iommu_version = 0x01000000,
1085 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
1086 3ebf5aaf blueswir1
        .default_cpu_model = "TI SuperSparc II",
1087 6a3b9cc9 blueswir1
    },
1088 ae40972f blueswir1
    /* SS-20 */
1089 ae40972f blueswir1
    {
1090 ae40972f blueswir1
        .iommu_base   = 0xfe0000000ULL,
1091 ae40972f blueswir1
        .tcx_base     = 0xe20000000ULL,
1092 ae40972f blueswir1
        .slavio_base  = 0xff0000000ULL,
1093 ae40972f blueswir1
        .ms_kb_base   = 0xff1000000ULL,
1094 ae40972f blueswir1
        .serial_base  = 0xff1100000ULL,
1095 ae40972f blueswir1
        .nvram_base   = 0xff1200000ULL,
1096 ae40972f blueswir1
        .fd_base      = 0xff1700000ULL,
1097 ae40972f blueswir1
        .counter_base = 0xff1300000ULL,
1098 ae40972f blueswir1
        .intctl_base  = 0xff1400000ULL,
1099 4c2485de blueswir1
        .idreg_base   = 0xef0000000ULL,
1100 ae40972f blueswir1
        .dma_base     = 0xef0400000ULL,
1101 ae40972f blueswir1
        .esp_base     = 0xef0800000ULL,
1102 ae40972f blueswir1
        .le_base      = 0xef0c00000ULL,
1103 9a62fb24 Bob Breuer
        .bpp_base     = 0xef4800000ULL,
1104 0019ad53 blueswir1
        .apc_base     = 0xefa000000ULL, // XXX should not exist
1105 577d8dd4 blueswir1
        .aux1_base    = 0xff1800000ULL,
1106 577d8dd4 blueswir1
        .aux2_base    = 0xff1a01000ULL,
1107 9a62fb24 Bob Breuer
        .dbri_base    = 0xee0000000ULL,
1108 9a62fb24 Bob Breuer
        .sx_base      = 0xf80000000ULL,
1109 9a62fb24 Bob Breuer
        .vsimm        = {
1110 9a62fb24 Bob Breuer
            {
1111 9a62fb24 Bob Breuer
                .reg_base  = 0x9c000000ULL,
1112 9a62fb24 Bob Breuer
                .vram_base = 0xfc000000ULL
1113 9a62fb24 Bob Breuer
            }, {
1114 9a62fb24 Bob Breuer
                .reg_base  = 0x90000000ULL,
1115 9a62fb24 Bob Breuer
                .vram_base = 0xf0000000ULL
1116 9a62fb24 Bob Breuer
            }, {
1117 9a62fb24 Bob Breuer
                .reg_base  = 0x94000000ULL
1118 9a62fb24 Bob Breuer
            }, {
1119 9a62fb24 Bob Breuer
                .reg_base  = 0x98000000ULL
1120 9a62fb24 Bob Breuer
            }
1121 9a62fb24 Bob Breuer
        },
1122 ae40972f blueswir1
        .ecc_base     = 0xf00000000ULL,
1123 ae40972f blueswir1
        .ecc_version  = 0x20000000, // version 0, implementation 2
1124 905fdcb5 blueswir1
        .nvram_machine_id = 0x72,
1125 905fdcb5 blueswir1
        .machine_id = ss20_id,
1126 ae40972f blueswir1
        .iommu_version = 0x13000000,
1127 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
1128 ae40972f blueswir1
        .default_cpu_model = "TI SuperSparc II",
1129 ae40972f blueswir1
    },
1130 a526a31c blueswir1
    /* Voyager */
1131 a526a31c blueswir1
    {
1132 a526a31c blueswir1
        .iommu_base   = 0x10000000,
1133 a526a31c blueswir1
        .tcx_base     = 0x50000000,
1134 a526a31c blueswir1
        .slavio_base  = 0x70000000,
1135 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
1136 a526a31c blueswir1
        .serial_base  = 0x71100000,
1137 a526a31c blueswir1
        .nvram_base   = 0x71200000,
1138 a526a31c blueswir1
        .fd_base      = 0x71400000,
1139 a526a31c blueswir1
        .counter_base = 0x71d00000,
1140 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
1141 a526a31c blueswir1
        .idreg_base   = 0x78000000,
1142 a526a31c blueswir1
        .dma_base     = 0x78400000,
1143 a526a31c blueswir1
        .esp_base     = 0x78800000,
1144 a526a31c blueswir1
        .le_base      = 0x78c00000,
1145 a526a31c blueswir1
        .apc_base     = 0x71300000, // pmc
1146 a526a31c blueswir1
        .aux1_base    = 0x71900000,
1147 a526a31c blueswir1
        .aux2_base    = 0x71910000,
1148 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1149 905fdcb5 blueswir1
        .machine_id = vger_id,
1150 a526a31c blueswir1
        .iommu_version = 0x05000000,
1151 a526a31c blueswir1
        .max_mem = 0x10000000,
1152 a526a31c blueswir1
        .default_cpu_model = "Fujitsu MB86904",
1153 a526a31c blueswir1
    },
1154 a526a31c blueswir1
    /* LX */
1155 a526a31c blueswir1
    {
1156 a526a31c blueswir1
        .iommu_base   = 0x10000000,
1157 3386376c Artyom Tarasenko
        .iommu_pad_base = 0x10004000,
1158 3386376c Artyom Tarasenko
        .iommu_pad_len  = 0x0fffb000,
1159 a526a31c blueswir1
        .tcx_base     = 0x50000000,
1160 a526a31c blueswir1
        .slavio_base  = 0x70000000,
1161 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
1162 a526a31c blueswir1
        .serial_base  = 0x71100000,
1163 a526a31c blueswir1
        .nvram_base   = 0x71200000,
1164 a526a31c blueswir1
        .fd_base      = 0x71400000,
1165 a526a31c blueswir1
        .counter_base = 0x71d00000,
1166 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
1167 a526a31c blueswir1
        .idreg_base   = 0x78000000,
1168 a526a31c blueswir1
        .dma_base     = 0x78400000,
1169 a526a31c blueswir1
        .esp_base     = 0x78800000,
1170 a526a31c blueswir1
        .le_base      = 0x78c00000,
1171 a526a31c blueswir1
        .aux1_base    = 0x71900000,
1172 a526a31c blueswir1
        .aux2_base    = 0x71910000,
1173 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1174 905fdcb5 blueswir1
        .machine_id = lx_id,
1175 a526a31c blueswir1
        .iommu_version = 0x04000000,
1176 a526a31c blueswir1
        .max_mem = 0x10000000,
1177 a526a31c blueswir1
        .default_cpu_model = "TI MicroSparc I",
1178 a526a31c blueswir1
    },
1179 a526a31c blueswir1
    /* SS-4 */
1180 a526a31c blueswir1
    {
1181 a526a31c blueswir1
        .iommu_base   = 0x10000000,
1182 a526a31c blueswir1
        .tcx_base     = 0x50000000,
1183 a526a31c blueswir1
        .cs_base      = 0x6c000000,
1184 a526a31c blueswir1
        .slavio_base  = 0x70000000,
1185 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
1186 a526a31c blueswir1
        .serial_base  = 0x71100000,
1187 a526a31c blueswir1
        .nvram_base   = 0x71200000,
1188 a526a31c blueswir1
        .fd_base      = 0x71400000,
1189 a526a31c blueswir1
        .counter_base = 0x71d00000,
1190 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
1191 a526a31c blueswir1
        .idreg_base   = 0x78000000,
1192 a526a31c blueswir1
        .dma_base     = 0x78400000,
1193 a526a31c blueswir1
        .esp_base     = 0x78800000,
1194 a526a31c blueswir1
        .le_base      = 0x78c00000,
1195 a526a31c blueswir1
        .apc_base     = 0x6a000000,
1196 a526a31c blueswir1
        .aux1_base    = 0x71900000,
1197 a526a31c blueswir1
        .aux2_base    = 0x71910000,
1198 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1199 905fdcb5 blueswir1
        .machine_id = ss4_id,
1200 a526a31c blueswir1
        .iommu_version = 0x05000000,
1201 a526a31c blueswir1
        .max_mem = 0x10000000,
1202 a526a31c blueswir1
        .default_cpu_model = "Fujitsu MB86904",
1203 a526a31c blueswir1
    },
1204 a526a31c blueswir1
    /* SPARCClassic */
1205 a526a31c blueswir1
    {
1206 a526a31c blueswir1
        .iommu_base   = 0x10000000,
1207 a526a31c blueswir1
        .tcx_base     = 0x50000000,
1208 a526a31c blueswir1
        .slavio_base  = 0x70000000,
1209 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
1210 a526a31c blueswir1
        .serial_base  = 0x71100000,
1211 a526a31c blueswir1
        .nvram_base   = 0x71200000,
1212 a526a31c blueswir1
        .fd_base      = 0x71400000,
1213 a526a31c blueswir1
        .counter_base = 0x71d00000,
1214 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
1215 a526a31c blueswir1
        .idreg_base   = 0x78000000,
1216 a526a31c blueswir1
        .dma_base     = 0x78400000,
1217 a526a31c blueswir1
        .esp_base     = 0x78800000,
1218 a526a31c blueswir1
        .le_base      = 0x78c00000,
1219 a526a31c blueswir1
        .apc_base     = 0x6a000000,
1220 a526a31c blueswir1
        .aux1_base    = 0x71900000,
1221 a526a31c blueswir1
        .aux2_base    = 0x71910000,
1222 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1223 905fdcb5 blueswir1
        .machine_id = scls_id,
1224 a526a31c blueswir1
        .iommu_version = 0x05000000,
1225 a526a31c blueswir1
        .max_mem = 0x10000000,
1226 a526a31c blueswir1
        .default_cpu_model = "TI MicroSparc I",
1227 a526a31c blueswir1
    },
1228 a526a31c blueswir1
    /* SPARCbook */
1229 a526a31c blueswir1
    {
1230 a526a31c blueswir1
        .iommu_base   = 0x10000000,
1231 a526a31c blueswir1
        .tcx_base     = 0x50000000, // XXX
1232 a526a31c blueswir1
        .slavio_base  = 0x70000000,
1233 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
1234 a526a31c blueswir1
        .serial_base  = 0x71100000,
1235 a526a31c blueswir1
        .nvram_base   = 0x71200000,
1236 a526a31c blueswir1
        .fd_base      = 0x71400000,
1237 a526a31c blueswir1
        .counter_base = 0x71d00000,
1238 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
1239 a526a31c blueswir1
        .idreg_base   = 0x78000000,
1240 a526a31c blueswir1
        .dma_base     = 0x78400000,
1241 a526a31c blueswir1
        .esp_base     = 0x78800000,
1242 a526a31c blueswir1
        .le_base      = 0x78c00000,
1243 a526a31c blueswir1
        .apc_base     = 0x6a000000,
1244 a526a31c blueswir1
        .aux1_base    = 0x71900000,
1245 a526a31c blueswir1
        .aux2_base    = 0x71910000,
1246 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1247 905fdcb5 blueswir1
        .machine_id = sbook_id,
1248 a526a31c blueswir1
        .iommu_version = 0x05000000,
1249 a526a31c blueswir1
        .max_mem = 0x10000000,
1250 a526a31c blueswir1
        .default_cpu_model = "TI MicroSparc I",
1251 a526a31c blueswir1
    },
1252 36cd9210 blueswir1
};
1253 36cd9210 blueswir1
1254 36cd9210 blueswir1
/* SPARCstation 5 hardware initialisation */
1255 c227f099 Anthony Liguori
static void ss5_init(ram_addr_t RAM_size,
1256 3023f332 aliguori
                     const char *boot_device,
1257 b881c2c6 blueswir1
                     const char *kernel_filename, const char *kernel_cmdline,
1258 b881c2c6 blueswir1
                     const char *initrd_filename, const char *cpu_model)
1259 36cd9210 blueswir1
{
1260 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
1261 3ebf5aaf blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1262 420557e8 bellard
}
1263 c0e564d5 bellard
1264 e0353fe2 blueswir1
/* SPARCstation 10 hardware initialisation */
1265 c227f099 Anthony Liguori
static void ss10_init(ram_addr_t RAM_size,
1266 3023f332 aliguori
                      const char *boot_device,
1267 b881c2c6 blueswir1
                      const char *kernel_filename, const char *kernel_cmdline,
1268 b881c2c6 blueswir1
                      const char *initrd_filename, const char *cpu_model)
1269 e0353fe2 blueswir1
{
1270 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
1271 3ebf5aaf blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1272 e0353fe2 blueswir1
}
1273 e0353fe2 blueswir1
1274 6a3b9cc9 blueswir1
/* SPARCserver 600MP hardware initialisation */
1275 c227f099 Anthony Liguori
static void ss600mp_init(ram_addr_t RAM_size,
1276 3023f332 aliguori
                         const char *boot_device,
1277 77f193da blueswir1
                         const char *kernel_filename,
1278 77f193da blueswir1
                         const char *kernel_cmdline,
1279 6a3b9cc9 blueswir1
                         const char *initrd_filename, const char *cpu_model)
1280 6a3b9cc9 blueswir1
{
1281 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
1282 3ebf5aaf blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1283 6a3b9cc9 blueswir1
}
1284 6a3b9cc9 blueswir1
1285 ae40972f blueswir1
/* SPARCstation 20 hardware initialisation */
1286 c227f099 Anthony Liguori
static void ss20_init(ram_addr_t RAM_size,
1287 3023f332 aliguori
                      const char *boot_device,
1288 ae40972f blueswir1
                      const char *kernel_filename, const char *kernel_cmdline,
1289 ae40972f blueswir1
                      const char *initrd_filename, const char *cpu_model)
1290 ae40972f blueswir1
{
1291 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
1292 ee76f82e blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1293 ee76f82e blueswir1
}
1294 ee76f82e blueswir1
1295 a526a31c blueswir1
/* SPARCstation Voyager hardware initialisation */
1296 c227f099 Anthony Liguori
static void vger_init(ram_addr_t RAM_size,
1297 3023f332 aliguori
                      const char *boot_device,
1298 a526a31c blueswir1
                      const char *kernel_filename, const char *kernel_cmdline,
1299 a526a31c blueswir1
                      const char *initrd_filename, const char *cpu_model)
1300 a526a31c blueswir1
{
1301 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
1302 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1303 a526a31c blueswir1
}
1304 a526a31c blueswir1
1305 a526a31c blueswir1
/* SPARCstation LX hardware initialisation */
1306 c227f099 Anthony Liguori
static void ss_lx_init(ram_addr_t RAM_size,
1307 3023f332 aliguori
                       const char *boot_device,
1308 a526a31c blueswir1
                       const char *kernel_filename, const char *kernel_cmdline,
1309 a526a31c blueswir1
                       const char *initrd_filename, const char *cpu_model)
1310 a526a31c blueswir1
{
1311 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
1312 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1313 a526a31c blueswir1
}
1314 a526a31c blueswir1
1315 a526a31c blueswir1
/* SPARCstation 4 hardware initialisation */
1316 c227f099 Anthony Liguori
static void ss4_init(ram_addr_t RAM_size,
1317 3023f332 aliguori
                     const char *boot_device,
1318 a526a31c blueswir1
                     const char *kernel_filename, const char *kernel_cmdline,
1319 a526a31c blueswir1
                     const char *initrd_filename, const char *cpu_model)
1320 a526a31c blueswir1
{
1321 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
1322 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1323 a526a31c blueswir1
}
1324 a526a31c blueswir1
1325 a526a31c blueswir1
/* SPARCClassic hardware initialisation */
1326 c227f099 Anthony Liguori
static void scls_init(ram_addr_t RAM_size,
1327 3023f332 aliguori
                      const char *boot_device,
1328 a526a31c blueswir1
                      const char *kernel_filename, const char *kernel_cmdline,
1329 a526a31c blueswir1
                      const char *initrd_filename, const char *cpu_model)
1330 a526a31c blueswir1
{
1331 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
1332 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1333 a526a31c blueswir1
}
1334 a526a31c blueswir1
1335 a526a31c blueswir1
/* SPARCbook hardware initialisation */
1336 c227f099 Anthony Liguori
static void sbook_init(ram_addr_t RAM_size,
1337 3023f332 aliguori
                       const char *boot_device,
1338 a526a31c blueswir1
                       const char *kernel_filename, const char *kernel_cmdline,
1339 a526a31c blueswir1
                       const char *initrd_filename, const char *cpu_model)
1340 a526a31c blueswir1
{
1341 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
1342 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1343 a526a31c blueswir1
}
1344 a526a31c blueswir1
1345 f80f9ec9 Anthony Liguori
static QEMUMachine ss5_machine = {
1346 66de733b blueswir1
    .name = "SS-5",
1347 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation 5",
1348 66de733b blueswir1
    .init = ss5_init,
1349 c9b1ae2c blueswir1
    .use_scsi = 1,
1350 0c257437 Anthony Liguori
    .is_default = 1,
1351 c0e564d5 bellard
};
1352 e0353fe2 blueswir1
1353 f80f9ec9 Anthony Liguori
static QEMUMachine ss10_machine = {
1354 66de733b blueswir1
    .name = "SS-10",
1355 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation 10",
1356 66de733b blueswir1
    .init = ss10_init,
1357 c9b1ae2c blueswir1
    .use_scsi = 1,
1358 1bcee014 blueswir1
    .max_cpus = 4,
1359 e0353fe2 blueswir1
};
1360 6a3b9cc9 blueswir1
1361 f80f9ec9 Anthony Liguori
static QEMUMachine ss600mp_machine = {
1362 66de733b blueswir1
    .name = "SS-600MP",
1363 66de733b blueswir1
    .desc = "Sun4m platform, SPARCserver 600MP",
1364 66de733b blueswir1
    .init = ss600mp_init,
1365 c9b1ae2c blueswir1
    .use_scsi = 1,
1366 1bcee014 blueswir1
    .max_cpus = 4,
1367 6a3b9cc9 blueswir1
};
1368 ae40972f blueswir1
1369 f80f9ec9 Anthony Liguori
static QEMUMachine ss20_machine = {
1370 66de733b blueswir1
    .name = "SS-20",
1371 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation 20",
1372 66de733b blueswir1
    .init = ss20_init,
1373 c9b1ae2c blueswir1
    .use_scsi = 1,
1374 1bcee014 blueswir1
    .max_cpus = 4,
1375 ae40972f blueswir1
};
1376 ae40972f blueswir1
1377 f80f9ec9 Anthony Liguori
static QEMUMachine voyager_machine = {
1378 66de733b blueswir1
    .name = "Voyager",
1379 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation Voyager",
1380 66de733b blueswir1
    .init = vger_init,
1381 c9b1ae2c blueswir1
    .use_scsi = 1,
1382 a526a31c blueswir1
};
1383 a526a31c blueswir1
1384 f80f9ec9 Anthony Liguori
static QEMUMachine ss_lx_machine = {
1385 66de733b blueswir1
    .name = "LX",
1386 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation LX",
1387 66de733b blueswir1
    .init = ss_lx_init,
1388 c9b1ae2c blueswir1
    .use_scsi = 1,
1389 a526a31c blueswir1
};
1390 a526a31c blueswir1
1391 f80f9ec9 Anthony Liguori
static QEMUMachine ss4_machine = {
1392 66de733b blueswir1
    .name = "SS-4",
1393 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation 4",
1394 66de733b blueswir1
    .init = ss4_init,
1395 c9b1ae2c blueswir1
    .use_scsi = 1,
1396 a526a31c blueswir1
};
1397 a526a31c blueswir1
1398 f80f9ec9 Anthony Liguori
static QEMUMachine scls_machine = {
1399 66de733b blueswir1
    .name = "SPARCClassic",
1400 66de733b blueswir1
    .desc = "Sun4m platform, SPARCClassic",
1401 66de733b blueswir1
    .init = scls_init,
1402 c9b1ae2c blueswir1
    .use_scsi = 1,
1403 a526a31c blueswir1
};
1404 a526a31c blueswir1
1405 f80f9ec9 Anthony Liguori
static QEMUMachine sbook_machine = {
1406 66de733b blueswir1
    .name = "SPARCbook",
1407 66de733b blueswir1
    .desc = "Sun4m platform, SPARCbook",
1408 66de733b blueswir1
    .init = sbook_init,
1409 c9b1ae2c blueswir1
    .use_scsi = 1,
1410 a526a31c blueswir1
};
1411 a526a31c blueswir1
1412 7d85892b blueswir1
static const struct sun4d_hwdef sun4d_hwdefs[] = {
1413 7d85892b blueswir1
    /* SS-1000 */
1414 7d85892b blueswir1
    {
1415 7d85892b blueswir1
        .iounit_bases   = {
1416 7d85892b blueswir1
            0xfe0200000ULL,
1417 7d85892b blueswir1
            0xfe1200000ULL,
1418 7d85892b blueswir1
            0xfe2200000ULL,
1419 7d85892b blueswir1
            0xfe3200000ULL,
1420 7d85892b blueswir1
            -1,
1421 7d85892b blueswir1
        },
1422 7d85892b blueswir1
        .tcx_base     = 0x820000000ULL,
1423 7d85892b blueswir1
        .slavio_base  = 0xf00000000ULL,
1424 7d85892b blueswir1
        .ms_kb_base   = 0xf00240000ULL,
1425 7d85892b blueswir1
        .serial_base  = 0xf00200000ULL,
1426 7d85892b blueswir1
        .nvram_base   = 0xf00280000ULL,
1427 7d85892b blueswir1
        .counter_base = 0xf00300000ULL,
1428 7d85892b blueswir1
        .espdma_base  = 0x800081000ULL,
1429 7d85892b blueswir1
        .esp_base     = 0x800080000ULL,
1430 7d85892b blueswir1
        .ledma_base   = 0x800040000ULL,
1431 7d85892b blueswir1
        .le_base      = 0x800060000ULL,
1432 7d85892b blueswir1
        .sbi_base     = 0xf02800000ULL,
1433 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1434 905fdcb5 blueswir1
        .machine_id = ss1000_id,
1435 7d85892b blueswir1
        .iounit_version = 0x03000000,
1436 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
1437 7d85892b blueswir1
        .default_cpu_model = "TI SuperSparc II",
1438 7d85892b blueswir1
    },
1439 7d85892b blueswir1
    /* SS-2000 */
1440 7d85892b blueswir1
    {
1441 7d85892b blueswir1
        .iounit_bases   = {
1442 7d85892b blueswir1
            0xfe0200000ULL,
1443 7d85892b blueswir1
            0xfe1200000ULL,
1444 7d85892b blueswir1
            0xfe2200000ULL,
1445 7d85892b blueswir1
            0xfe3200000ULL,
1446 7d85892b blueswir1
            0xfe4200000ULL,
1447 7d85892b blueswir1
        },
1448 7d85892b blueswir1
        .tcx_base     = 0x820000000ULL,
1449 7d85892b blueswir1
        .slavio_base  = 0xf00000000ULL,
1450 7d85892b blueswir1
        .ms_kb_base   = 0xf00240000ULL,
1451 7d85892b blueswir1
        .serial_base  = 0xf00200000ULL,
1452 7d85892b blueswir1
        .nvram_base   = 0xf00280000ULL,
1453 7d85892b blueswir1
        .counter_base = 0xf00300000ULL,
1454 7d85892b blueswir1
        .espdma_base  = 0x800081000ULL,
1455 7d85892b blueswir1
        .esp_base     = 0x800080000ULL,
1456 7d85892b blueswir1
        .ledma_base   = 0x800040000ULL,
1457 7d85892b blueswir1
        .le_base      = 0x800060000ULL,
1458 7d85892b blueswir1
        .sbi_base     = 0xf02800000ULL,
1459 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1460 905fdcb5 blueswir1
        .machine_id = ss2000_id,
1461 7d85892b blueswir1
        .iounit_version = 0x03000000,
1462 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
1463 7d85892b blueswir1
        .default_cpu_model = "TI SuperSparc II",
1464 7d85892b blueswir1
    },
1465 7d85892b blueswir1
};
1466 7d85892b blueswir1
1467 c227f099 Anthony Liguori
static DeviceState *sbi_init(target_phys_addr_t addr, qemu_irq **parent_irq)
1468 4b48bf05 Blue Swirl
{
1469 4b48bf05 Blue Swirl
    DeviceState *dev;
1470 4b48bf05 Blue Swirl
    SysBusDevice *s;
1471 4b48bf05 Blue Swirl
    unsigned int i;
1472 4b48bf05 Blue Swirl
1473 4b48bf05 Blue Swirl
    dev = qdev_create(NULL, "sbi");
1474 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
1475 4b48bf05 Blue Swirl
1476 4b48bf05 Blue Swirl
    s = sysbus_from_qdev(dev);
1477 4b48bf05 Blue Swirl
1478 4b48bf05 Blue Swirl
    for (i = 0; i < MAX_CPUS; i++) {
1479 4b48bf05 Blue Swirl
        sysbus_connect_irq(s, i, *parent_irq[i]);
1480 4b48bf05 Blue Swirl
    }
1481 4b48bf05 Blue Swirl
1482 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 0, addr);
1483 4b48bf05 Blue Swirl
1484 4b48bf05 Blue Swirl
    return dev;
1485 4b48bf05 Blue Swirl
}
1486 4b48bf05 Blue Swirl
1487 c227f099 Anthony Liguori
static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1488 7d85892b blueswir1
                          const char *boot_device,
1489 3023f332 aliguori
                          const char *kernel_filename,
1490 7d85892b blueswir1
                          const char *kernel_cmdline,
1491 7d85892b blueswir1
                          const char *initrd_filename, const char *cpu_model)
1492 7d85892b blueswir1
{
1493 7d85892b blueswir1
    unsigned int i;
1494 7fc06735 Blue Swirl
    void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram;
1495 7fc06735 Blue Swirl
    qemu_irq *cpu_irqs[MAX_CPUS], sbi_irq[32], sbi_cpu_irq[MAX_CPUS],
1496 6f6260c7 Blue Swirl
        espdma_irq, ledma_irq;
1497 73d74342 Blue Swirl
    qemu_irq esp_reset, dma_enable;
1498 5c6602c5 blueswir1
    unsigned long kernel_size;
1499 3cce6243 blueswir1
    void *fw_cfg;
1500 7fc06735 Blue Swirl
    DeviceState *dev;
1501 7d85892b blueswir1
1502 7d85892b blueswir1
    /* init CPUs */
1503 7d85892b blueswir1
    if (!cpu_model)
1504 7d85892b blueswir1
        cpu_model = hwdef->default_cpu_model;
1505 7d85892b blueswir1
1506 666713c0 Blue Swirl
    for(i = 0; i < smp_cpus; i++) {
1507 89835363 Blue Swirl
        cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
1508 7d85892b blueswir1
    }
1509 7d85892b blueswir1
1510 7d85892b blueswir1
    for (i = smp_cpus; i < MAX_CPUS; i++)
1511 7d85892b blueswir1
        cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1512 7d85892b blueswir1
1513 7d85892b blueswir1
    /* set up devices */
1514 a350db85 Blue Swirl
    ram_init(0, RAM_size, hwdef->max_mem);
1515 a350db85 Blue Swirl
1516 f48f6569 Blue Swirl
    prom_init(hwdef->slavio_base, bios_name);
1517 f48f6569 Blue Swirl
1518 7fc06735 Blue Swirl
    dev = sbi_init(hwdef->sbi_base, cpu_irqs);
1519 7fc06735 Blue Swirl
1520 7fc06735 Blue Swirl
    for (i = 0; i < 32; i++) {
1521 7fc06735 Blue Swirl
        sbi_irq[i] = qdev_get_gpio_in(dev, i);
1522 7fc06735 Blue Swirl
    }
1523 7fc06735 Blue Swirl
    for (i = 0; i < MAX_CPUS; i++) {
1524 7fc06735 Blue Swirl
        sbi_cpu_irq[i] = qdev_get_gpio_in(dev, 32 + i);
1525 7fc06735 Blue Swirl
    }
1526 7d85892b blueswir1
1527 7d85892b blueswir1
    for (i = 0; i < MAX_IOUNITS; i++)
1528 c227f099 Anthony Liguori
        if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
1529 ff403da6 blueswir1
            iounits[i] = iommu_init(hwdef->iounit_bases[i],
1530 ff403da6 blueswir1
                                    hwdef->iounit_version,
1531 c533e0b3 Blue Swirl
                                    sbi_irq[0]);
1532 7d85892b blueswir1
1533 c533e0b3 Blue Swirl
    espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[3],
1534 86d1c388 Bob Breuer
                              iounits[0], &espdma_irq, 0);
1535 7d85892b blueswir1
1536 86d1c388 Bob Breuer
    /* should be lebuffer instead */
1537 c533e0b3 Blue Swirl
    ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[4],
1538 86d1c388 Bob Breuer
                             iounits[0], &ledma_irq, 0);
1539 7d85892b blueswir1
1540 7d85892b blueswir1
    if (graphic_depth != 8 && graphic_depth != 24) {
1541 7d85892b blueswir1
        fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1542 7d85892b blueswir1
        exit (1);
1543 7d85892b blueswir1
    }
1544 d95d8f1c Blue Swirl
    tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
1545 dc828ca1 pbrook
             graphic_depth);
1546 7d85892b blueswir1
1547 74ff8d90 Blue Swirl
    lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
1548 7d85892b blueswir1
1549 d95d8f1c Blue Swirl
    nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
1550 7d85892b blueswir1
1551 c533e0b3 Blue Swirl
    slavio_timer_init_all(hwdef->counter_base, sbi_irq[10], sbi_cpu_irq, smp_cpus);
1552 7d85892b blueswir1
1553 c533e0b3 Blue Swirl
    slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[12],
1554 993fbfdb Anthony Liguori
                              display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
1555 7d85892b blueswir1
    // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1556 7d85892b blueswir1
    // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1557 c533e0b3 Blue Swirl
    escc_init(hwdef->serial_base, sbi_irq[12], sbi_irq[12],
1558 aeeb69c7 aurel32
              serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
1559 7d85892b blueswir1
1560 7d85892b blueswir1
    if (drive_get_max_bus(IF_SCSI) > 0) {
1561 7d85892b blueswir1
        fprintf(stderr, "qemu: too many SCSI bus\n");
1562 7d85892b blueswir1
        exit(1);
1563 7d85892b blueswir1
    }
1564 7d85892b blueswir1
1565 cfb9de9c Paul Brook
    esp_init(hwdef->esp_base, 2,
1566 cfb9de9c Paul Brook
             espdma_memory_read, espdma_memory_write,
1567 73d74342 Blue Swirl
             espdma, espdma_irq, &esp_reset, &dma_enable);
1568 73d74342 Blue Swirl
1569 73d74342 Blue Swirl
    qdev_connect_gpio_out(espdma, 0, esp_reset);
1570 73d74342 Blue Swirl
    qdev_connect_gpio_out(espdma, 1, dma_enable);
1571 7d85892b blueswir1
1572 293f78bc blueswir1
    kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1573 293f78bc blueswir1
                                    RAM_size);
1574 7d85892b blueswir1
1575 7d85892b blueswir1
    nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1576 7d85892b blueswir1
               boot_device, RAM_size, kernel_size, graphic_width,
1577 905fdcb5 blueswir1
               graphic_height, graphic_depth, hwdef->nvram_machine_id,
1578 905fdcb5 blueswir1
               "Sun4d");
1579 3cce6243 blueswir1
1580 3cce6243 blueswir1
    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1581 3cce6243 blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1582 905fdcb5 blueswir1
    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1583 905fdcb5 blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1584 513f789f blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1585 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1586 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1587 513f789f blueswir1
    if (kernel_cmdline) {
1588 513f789f blueswir1
        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
1589 3c178e72 Gerd Hoffmann
        pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
1590 6bb4ca57 Blue Swirl
        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
1591 6bb4ca57 Blue Swirl
                         (uint8_t*)strdup(kernel_cmdline),
1592 6bb4ca57 Blue Swirl
                         strlen(kernel_cmdline) + 1);
1593 513f789f blueswir1
    } else {
1594 513f789f blueswir1
        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1595 513f789f blueswir1
    }
1596 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1597 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1598 513f789f blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1599 513f789f blueswir1
    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
1600 7d85892b blueswir1
}
1601 7d85892b blueswir1
1602 7d85892b blueswir1
/* SPARCserver 1000 hardware initialisation */
1603 c227f099 Anthony Liguori
static void ss1000_init(ram_addr_t RAM_size,
1604 3023f332 aliguori
                        const char *boot_device,
1605 7d85892b blueswir1
                        const char *kernel_filename, const char *kernel_cmdline,
1606 7d85892b blueswir1
                        const char *initrd_filename, const char *cpu_model)
1607 7d85892b blueswir1
{
1608 3023f332 aliguori
    sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename,
1609 7d85892b blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1610 7d85892b blueswir1
}
1611 7d85892b blueswir1
1612 7d85892b blueswir1
/* SPARCcenter 2000 hardware initialisation */
1613 c227f099 Anthony Liguori
static void ss2000_init(ram_addr_t RAM_size,
1614 3023f332 aliguori
                        const char *boot_device,
1615 7d85892b blueswir1
                        const char *kernel_filename, const char *kernel_cmdline,
1616 7d85892b blueswir1
                        const char *initrd_filename, const char *cpu_model)
1617 7d85892b blueswir1
{
1618 3023f332 aliguori
    sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename,
1619 7d85892b blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1620 7d85892b blueswir1
}
1621 7d85892b blueswir1
1622 f80f9ec9 Anthony Liguori
static QEMUMachine ss1000_machine = {
1623 66de733b blueswir1
    .name = "SS-1000",
1624 66de733b blueswir1
    .desc = "Sun4d platform, SPARCserver 1000",
1625 66de733b blueswir1
    .init = ss1000_init,
1626 c9b1ae2c blueswir1
    .use_scsi = 1,
1627 1bcee014 blueswir1
    .max_cpus = 8,
1628 7d85892b blueswir1
};
1629 7d85892b blueswir1
1630 f80f9ec9 Anthony Liguori
static QEMUMachine ss2000_machine = {
1631 66de733b blueswir1
    .name = "SS-2000",
1632 66de733b blueswir1
    .desc = "Sun4d platform, SPARCcenter 2000",
1633 66de733b blueswir1
    .init = ss2000_init,
1634 c9b1ae2c blueswir1
    .use_scsi = 1,
1635 1bcee014 blueswir1
    .max_cpus = 20,
1636 7d85892b blueswir1
};
1637 8137cde8 blueswir1
1638 8137cde8 blueswir1
static const struct sun4c_hwdef sun4c_hwdefs[] = {
1639 8137cde8 blueswir1
    /* SS-2 */
1640 8137cde8 blueswir1
    {
1641 8137cde8 blueswir1
        .iommu_base   = 0xf8000000,
1642 8137cde8 blueswir1
        .tcx_base     = 0xfe000000,
1643 8137cde8 blueswir1
        .slavio_base  = 0xf6000000,
1644 8137cde8 blueswir1
        .intctl_base  = 0xf5000000,
1645 8137cde8 blueswir1
        .counter_base = 0xf3000000,
1646 8137cde8 blueswir1
        .ms_kb_base   = 0xf0000000,
1647 8137cde8 blueswir1
        .serial_base  = 0xf1000000,
1648 8137cde8 blueswir1
        .nvram_base   = 0xf2000000,
1649 8137cde8 blueswir1
        .fd_base      = 0xf7200000,
1650 8137cde8 blueswir1
        .dma_base     = 0xf8400000,
1651 8137cde8 blueswir1
        .esp_base     = 0xf8800000,
1652 8137cde8 blueswir1
        .le_base      = 0xf8c00000,
1653 8137cde8 blueswir1
        .aux1_base    = 0xf7400003,
1654 8137cde8 blueswir1
        .nvram_machine_id = 0x55,
1655 8137cde8 blueswir1
        .machine_id = ss2_id,
1656 8137cde8 blueswir1
        .max_mem = 0x10000000,
1657 8137cde8 blueswir1
        .default_cpu_model = "Cypress CY7C601",
1658 8137cde8 blueswir1
    },
1659 8137cde8 blueswir1
};
1660 8137cde8 blueswir1
1661 c227f099 Anthony Liguori
static DeviceState *sun4c_intctl_init(target_phys_addr_t addr,
1662 4b48bf05 Blue Swirl
                                      qemu_irq *parent_irq)
1663 4b48bf05 Blue Swirl
{
1664 4b48bf05 Blue Swirl
    DeviceState *dev;
1665 4b48bf05 Blue Swirl
    SysBusDevice *s;
1666 4b48bf05 Blue Swirl
    unsigned int i;
1667 4b48bf05 Blue Swirl
1668 4b48bf05 Blue Swirl
    dev = qdev_create(NULL, "sun4c_intctl");
1669 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
1670 4b48bf05 Blue Swirl
1671 4b48bf05 Blue Swirl
    s = sysbus_from_qdev(dev);
1672 4b48bf05 Blue Swirl
1673 4b48bf05 Blue Swirl
    for (i = 0; i < MAX_PILS; i++) {
1674 4b48bf05 Blue Swirl
        sysbus_connect_irq(s, i, parent_irq[i]);
1675 4b48bf05 Blue Swirl
    }
1676 4b48bf05 Blue Swirl
    sysbus_mmio_map(s, 0, addr);
1677 4b48bf05 Blue Swirl
1678 4b48bf05 Blue Swirl
    return dev;
1679 4b48bf05 Blue Swirl
}
1680 4b48bf05 Blue Swirl
1681 c227f099 Anthony Liguori
static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1682 8137cde8 blueswir1
                          const char *boot_device,
1683 3023f332 aliguori
                          const char *kernel_filename,
1684 8137cde8 blueswir1
                          const char *kernel_cmdline,
1685 8137cde8 blueswir1
                          const char *initrd_filename, const char *cpu_model)
1686 8137cde8 blueswir1
{
1687 cfb9de9c Paul Brook
    void *iommu, *espdma, *ledma, *nvram;
1688 e32cba29 Blue Swirl
    qemu_irq *cpu_irqs, slavio_irq[8], espdma_irq, ledma_irq;
1689 73d74342 Blue Swirl
    qemu_irq esp_reset, dma_enable;
1690 2582cfa0 Blue Swirl
    qemu_irq fdc_tc;
1691 5c6602c5 blueswir1
    unsigned long kernel_size;
1692 fd8014e1 Gerd Hoffmann
    DriveInfo *fd[MAX_FD];
1693 8137cde8 blueswir1
    void *fw_cfg;
1694 e32cba29 Blue Swirl
    DeviceState *dev;
1695 e32cba29 Blue Swirl
    unsigned int i;
1696 8137cde8 blueswir1
1697 8137cde8 blueswir1
    /* init CPU */
1698 8137cde8 blueswir1
    if (!cpu_model)
1699 8137cde8 blueswir1
        cpu_model = hwdef->default_cpu_model;
1700 8137cde8 blueswir1
1701 89835363 Blue Swirl
    cpu_devinit(cpu_model, 0, hwdef->slavio_base, &cpu_irqs);
1702 8137cde8 blueswir1
1703 8137cde8 blueswir1
    /* set up devices */
1704 a350db85 Blue Swirl
    ram_init(0, RAM_size, hwdef->max_mem);
1705 a350db85 Blue Swirl
1706 f48f6569 Blue Swirl
    prom_init(hwdef->slavio_base, bios_name);
1707 f48f6569 Blue Swirl
1708 e32cba29 Blue Swirl
    dev = sun4c_intctl_init(hwdef->intctl_base, cpu_irqs);
1709 e32cba29 Blue Swirl
1710 e32cba29 Blue Swirl
    for (i = 0; i < 8; i++) {
1711 e32cba29 Blue Swirl
        slavio_irq[i] = qdev_get_gpio_in(dev, i);
1712 e32cba29 Blue Swirl
    }
1713 8137cde8 blueswir1
1714 8137cde8 blueswir1
    iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
1715 c533e0b3 Blue Swirl
                       slavio_irq[1]);
1716 8137cde8 blueswir1
1717 c533e0b3 Blue Swirl
    espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[2],
1718 86d1c388 Bob Breuer
                              iommu, &espdma_irq, 0);
1719 8137cde8 blueswir1
1720 8137cde8 blueswir1
    ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
1721 86d1c388 Bob Breuer
                             slavio_irq[3], iommu, &ledma_irq, 1);
1722 8137cde8 blueswir1
1723 8137cde8 blueswir1
    if (graphic_depth != 8 && graphic_depth != 24) {
1724 8137cde8 blueswir1
        fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1725 8137cde8 blueswir1
        exit (1);
1726 8137cde8 blueswir1
    }
1727 d95d8f1c Blue Swirl
    tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
1728 dc828ca1 pbrook
             graphic_depth);
1729 8137cde8 blueswir1
1730 74ff8d90 Blue Swirl
    lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
1731 8137cde8 blueswir1
1732 d95d8f1c Blue Swirl
    nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x800, 2);
1733 8137cde8 blueswir1
1734 c533e0b3 Blue Swirl
    slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[1],
1735 993fbfdb Anthony Liguori
                              display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
1736 8137cde8 blueswir1
    // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1737 8137cde8 blueswir1
    // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1738 c533e0b3 Blue Swirl
    escc_init(hwdef->serial_base, slavio_irq[1],
1739 c533e0b3 Blue Swirl
              slavio_irq[1], serial_hds[0], serial_hds[1],
1740 aeeb69c7 aurel32
              ESCC_CLOCK, 1);
1741 8137cde8 blueswir1
1742 b2b6f6ec Blue Swirl
    slavio_misc_init(0, hwdef->aux1_base, 0, slavio_irq[1], fdc_tc);
1743 8137cde8 blueswir1
1744 c227f099 Anthony Liguori
    if (hwdef->fd_base != (target_phys_addr_t)-1) {
1745 8137cde8 blueswir1
        /* there is zero or one floppy drive */
1746 ce802585 blueswir1
        memset(fd, 0, sizeof(fd));
1747 fd8014e1 Gerd Hoffmann
        fd[0] = drive_get(IF_FLOPPY, 0, 0);
1748 c533e0b3 Blue Swirl
        sun4m_fdctrl_init(slavio_irq[1], hwdef->fd_base, fd,
1749 2582cfa0 Blue Swirl
                          &fdc_tc);
1750 8137cde8 blueswir1
    }
1751 8137cde8 blueswir1
1752 8137cde8 blueswir1
    if (drive_get_max_bus(IF_SCSI) > 0) {
1753 8137cde8 blueswir1
        fprintf(stderr, "qemu: too many SCSI bus\n");
1754 8137cde8 blueswir1
        exit(1);
1755 8137cde8 blueswir1
    }
1756 8137cde8 blueswir1
1757 cfb9de9c Paul Brook
    esp_init(hwdef->esp_base, 2,
1758 cfb9de9c Paul Brook
             espdma_memory_read, espdma_memory_write,
1759 73d74342 Blue Swirl
             espdma, espdma_irq, &esp_reset, &dma_enable);
1760 73d74342 Blue Swirl
1761 73d74342 Blue Swirl
    qdev_connect_gpio_out(espdma, 0, esp_reset);
1762 73d74342 Blue Swirl
    qdev_connect_gpio_out(espdma, 1, dma_enable);
1763 8137cde8 blueswir1
1764 8137cde8 blueswir1
    kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1765 8137cde8 blueswir1
                                    RAM_size);
1766 8137cde8 blueswir1
1767 8137cde8 blueswir1
    nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1768 8137cde8 blueswir1
               boot_device, RAM_size, kernel_size, graphic_width,
1769 8137cde8 blueswir1
               graphic_height, graphic_depth, hwdef->nvram_machine_id,
1770 8137cde8 blueswir1
               "Sun4c");
1771 8137cde8 blueswir1
1772 8137cde8 blueswir1
    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1773 8137cde8 blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1774 8137cde8 blueswir1
    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1775 8137cde8 blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1776 513f789f blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1777 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1778 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1779 513f789f blueswir1
    if (kernel_cmdline) {
1780 513f789f blueswir1
        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
1781 3c178e72 Gerd Hoffmann
        pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
1782 6bb4ca57 Blue Swirl
        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
1783 6bb4ca57 Blue Swirl
                         (uint8_t*)strdup(kernel_cmdline),
1784 6bb4ca57 Blue Swirl
                         strlen(kernel_cmdline) + 1);
1785 513f789f blueswir1
    } else {
1786 513f789f blueswir1
        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1787 513f789f blueswir1
    }
1788 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1789 513f789f blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1790 513f789f blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1791 513f789f blueswir1
    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
1792 8137cde8 blueswir1
}
1793 8137cde8 blueswir1
1794 8137cde8 blueswir1
/* SPARCstation 2 hardware initialisation */
1795 c227f099 Anthony Liguori
static void ss2_init(ram_addr_t RAM_size,
1796 3023f332 aliguori
                     const char *boot_device,
1797 8137cde8 blueswir1
                     const char *kernel_filename, const char *kernel_cmdline,
1798 8137cde8 blueswir1
                     const char *initrd_filename, const char *cpu_model)
1799 8137cde8 blueswir1
{
1800 3023f332 aliguori
    sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename,
1801 8137cde8 blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1802 8137cde8 blueswir1
}
1803 8137cde8 blueswir1
1804 f80f9ec9 Anthony Liguori
static QEMUMachine ss2_machine = {
1805 8137cde8 blueswir1
    .name = "SS-2",
1806 8137cde8 blueswir1
    .desc = "Sun4c platform, SPARCstation 2",
1807 8137cde8 blueswir1
    .init = ss2_init,
1808 8137cde8 blueswir1
    .use_scsi = 1,
1809 8137cde8 blueswir1
};
1810 f80f9ec9 Anthony Liguori
1811 f80f9ec9 Anthony Liguori
static void ss2_machine_init(void)
1812 f80f9ec9 Anthony Liguori
{
1813 f80f9ec9 Anthony Liguori
    qemu_register_machine(&ss5_machine);
1814 f80f9ec9 Anthony Liguori
    qemu_register_machine(&ss10_machine);
1815 f80f9ec9 Anthony Liguori
    qemu_register_machine(&ss600mp_machine);
1816 f80f9ec9 Anthony Liguori
    qemu_register_machine(&ss20_machine);
1817 f80f9ec9 Anthony Liguori
    qemu_register_machine(&voyager_machine);
1818 f80f9ec9 Anthony Liguori
    qemu_register_machine(&ss_lx_machine);
1819 f80f9ec9 Anthony Liguori
    qemu_register_machine(&ss4_machine);
1820 f80f9ec9 Anthony Liguori
    qemu_register_machine(&scls_machine);
1821 f80f9ec9 Anthony Liguori
    qemu_register_machine(&sbook_machine);
1822 f80f9ec9 Anthony Liguori
    qemu_register_machine(&ss1000_machine);
1823 f80f9ec9 Anthony Liguori
    qemu_register_machine(&ss2000_machine);
1824 f80f9ec9 Anthony Liguori
    qemu_register_machine(&ss2_machine);
1825 f80f9ec9 Anthony Liguori
}
1826 f80f9ec9 Anthony Liguori
1827 f80f9ec9 Anthony Liguori
machine_init(ss2_machine_init);