Statistics
| Branch: | Revision:

root / hw / sun4m.c @ deb54399

History | View | Annotate | Download (53.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 87ecb68b pbrook
#include "hw.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 8b17de88 blueswir1
#include "scsi.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 d2c63fc1 blueswir1
40 b3a23197 blueswir1
//#define DEBUG_IRQ
41 420557e8 bellard
42 36cd9210 blueswir1
/*
43 36cd9210 blueswir1
 * Sun4m architecture was used in the following machines:
44 36cd9210 blueswir1
 *
45 36cd9210 blueswir1
 * SPARCserver 6xxMP/xx
46 77f193da blueswir1
 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
47 77f193da blueswir1
 * SPARCclassic X (4/10)
48 36cd9210 blueswir1
 * SPARCstation LX/ZX (4/30)
49 36cd9210 blueswir1
 * SPARCstation Voyager
50 36cd9210 blueswir1
 * SPARCstation 10/xx, SPARCserver 10/xx
51 36cd9210 blueswir1
 * SPARCstation 5, SPARCserver 5
52 36cd9210 blueswir1
 * SPARCstation 20/xx, SPARCserver 20
53 36cd9210 blueswir1
 * SPARCstation 4
54 36cd9210 blueswir1
 *
55 7d85892b blueswir1
 * Sun4d architecture was used in the following machines:
56 7d85892b blueswir1
 *
57 7d85892b blueswir1
 * SPARCcenter 2000
58 7d85892b blueswir1
 * SPARCserver 1000
59 7d85892b blueswir1
 *
60 ee76f82e blueswir1
 * Sun4c architecture was used in the following machines:
61 ee76f82e blueswir1
 * SPARCstation 1/1+, SPARCserver 1/1+
62 ee76f82e blueswir1
 * SPARCstation SLC
63 ee76f82e blueswir1
 * SPARCstation IPC
64 ee76f82e blueswir1
 * SPARCstation ELC
65 ee76f82e blueswir1
 * SPARCstation IPX
66 ee76f82e blueswir1
 *
67 36cd9210 blueswir1
 * See for example: http://www.sunhelp.org/faq/sunref1.html
68 36cd9210 blueswir1
 */
69 36cd9210 blueswir1
70 b3a23197 blueswir1
#ifdef DEBUG_IRQ
71 b3a23197 blueswir1
#define DPRINTF(fmt, args...)                           \
72 b3a23197 blueswir1
    do { printf("CPUIRQ: " fmt , ##args); } while (0)
73 b3a23197 blueswir1
#else
74 b3a23197 blueswir1
#define DPRINTF(fmt, args...)
75 b3a23197 blueswir1
#endif
76 b3a23197 blueswir1
77 420557e8 bellard
#define KERNEL_LOAD_ADDR     0x00004000
78 b6f479d3 bellard
#define CMDLINE_ADDR         0x007ff000
79 713c45fa bellard
#define INITRD_LOAD_ADDR     0x00800000
80 a7227727 blueswir1
#define PROM_SIZE_MAX        (1024 * 1024)
81 40ce0a9a blueswir1
#define PROM_VADDR           0xffd00000
82 f930d07e blueswir1
#define PROM_FILENAME        "openbios-sparc32"
83 3cce6243 blueswir1
#define CFG_ADDR             0xd00000510ULL
84 fbfcf955 blueswir1
#define FW_CFG_SUN4M_DEPTH   (FW_CFG_ARCH_LOCAL + 0x00)
85 b8174937 bellard
86 ac2e9d66 blueswir1
// Control plane, 8-bit and 24-bit planes
87 ac2e9d66 blueswir1
#define TCX_SIZE             (9 * 1024 * 1024)
88 ac2e9d66 blueswir1
89 ba3c64fb bellard
#define MAX_CPUS 16
90 b3a23197 blueswir1
#define MAX_PILS 16
91 420557e8 bellard
92 b4ed08e0 blueswir1
#define ESCC_CLOCK 4915200
93 b4ed08e0 blueswir1
94 8137cde8 blueswir1
struct sun4m_hwdef {
95 5dcb6b91 blueswir1
    target_phys_addr_t iommu_base, slavio_base;
96 5dcb6b91 blueswir1
    target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
97 5dcb6b91 blueswir1
    target_phys_addr_t serial_base, fd_base;
98 4c2485de blueswir1
    target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
99 0019ad53 blueswir1
    target_phys_addr_t tcx_base, cs_base, apc_base, aux1_base, aux2_base;
100 7eb0c8e8 blueswir1
    target_phys_addr_t ecc_base;
101 7eb0c8e8 blueswir1
    uint32_t ecc_version;
102 36cd9210 blueswir1
    long vram_size, nvram_size;
103 6341fdcb blueswir1
    // IRQ numbers are not PIL ones, but master interrupt controller
104 e3a79bca blueswir1
    // register bit numbers
105 1572a18c blueswir1
    int esp_irq, le_irq, clock_irq, clock1_irq;
106 e42c20b4 blueswir1
    int ser_irq, ms_kb_irq, fd_irq, me_irq, cs_irq, ecc_irq;
107 905fdcb5 blueswir1
    uint8_t nvram_machine_id;
108 905fdcb5 blueswir1
    uint16_t machine_id;
109 7fbfb139 blueswir1
    uint32_t iommu_version;
110 e0353fe2 blueswir1
    uint32_t intbit_to_level[32];
111 3ebf5aaf blueswir1
    uint64_t max_mem;
112 3ebf5aaf blueswir1
    const char * const default_cpu_model;
113 36cd9210 blueswir1
};
114 36cd9210 blueswir1
115 7d85892b blueswir1
#define MAX_IOUNITS 5
116 7d85892b blueswir1
117 7d85892b blueswir1
struct sun4d_hwdef {
118 7d85892b blueswir1
    target_phys_addr_t iounit_bases[MAX_IOUNITS], slavio_base;
119 7d85892b blueswir1
    target_phys_addr_t counter_base, nvram_base, ms_kb_base;
120 7d85892b blueswir1
    target_phys_addr_t serial_base;
121 7d85892b blueswir1
    target_phys_addr_t espdma_base, esp_base;
122 7d85892b blueswir1
    target_phys_addr_t ledma_base, le_base;
123 7d85892b blueswir1
    target_phys_addr_t tcx_base;
124 7d85892b blueswir1
    target_phys_addr_t sbi_base;
125 7d85892b blueswir1
    unsigned long vram_size, nvram_size;
126 7d85892b blueswir1
    // IRQ numbers are not PIL ones, but SBI register bit numbers
127 7d85892b blueswir1
    int esp_irq, le_irq, clock_irq, clock1_irq;
128 7d85892b blueswir1
    int ser_irq, ms_kb_irq, me_irq;
129 905fdcb5 blueswir1
    uint8_t nvram_machine_id;
130 905fdcb5 blueswir1
    uint16_t machine_id;
131 7d85892b blueswir1
    uint32_t iounit_version;
132 7d85892b blueswir1
    uint64_t max_mem;
133 7d85892b blueswir1
    const char * const default_cpu_model;
134 7d85892b blueswir1
};
135 7d85892b blueswir1
136 8137cde8 blueswir1
struct sun4c_hwdef {
137 8137cde8 blueswir1
    target_phys_addr_t iommu_base, slavio_base;
138 8137cde8 blueswir1
    target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
139 8137cde8 blueswir1
    target_phys_addr_t serial_base, fd_base;
140 8137cde8 blueswir1
    target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
141 1572a18c blueswir1
    target_phys_addr_t tcx_base, aux1_base;
142 8137cde8 blueswir1
    long vram_size, nvram_size;
143 8137cde8 blueswir1
    // IRQ numbers are not PIL ones, but master interrupt controller
144 8137cde8 blueswir1
    // register bit numbers
145 1572a18c blueswir1
    int esp_irq, le_irq, clock_irq, clock1_irq;
146 1572a18c blueswir1
    int ser_irq, ms_kb_irq, fd_irq, me_irq;
147 8137cde8 blueswir1
    uint8_t nvram_machine_id;
148 8137cde8 blueswir1
    uint16_t machine_id;
149 8137cde8 blueswir1
    uint32_t iommu_version;
150 8137cde8 blueswir1
    uint32_t intbit_to_level[32];
151 8137cde8 blueswir1
    uint64_t max_mem;
152 8137cde8 blueswir1
    const char * const default_cpu_model;
153 8137cde8 blueswir1
};
154 8137cde8 blueswir1
155 6f7e9aec bellard
int DMA_get_channel_mode (int nchan)
156 6f7e9aec bellard
{
157 6f7e9aec bellard
    return 0;
158 6f7e9aec bellard
}
159 6f7e9aec bellard
int DMA_read_memory (int nchan, void *buf, int pos, int size)
160 6f7e9aec bellard
{
161 6f7e9aec bellard
    return 0;
162 6f7e9aec bellard
}
163 6f7e9aec bellard
int DMA_write_memory (int nchan, void *buf, int pos, int size)
164 6f7e9aec bellard
{
165 6f7e9aec bellard
    return 0;
166 6f7e9aec bellard
}
167 6f7e9aec bellard
void DMA_hold_DREQ (int nchan) {}
168 6f7e9aec bellard
void DMA_release_DREQ (int nchan) {}
169 6f7e9aec bellard
void DMA_schedule(int nchan) {}
170 6f7e9aec bellard
void DMA_init (int high_page_enable) {}
171 6f7e9aec bellard
void DMA_register_channel (int nchan,
172 6f7e9aec bellard
                           DMA_transfer_handler transfer_handler,
173 6f7e9aec bellard
                           void *opaque)
174 6f7e9aec bellard
{
175 6f7e9aec bellard
}
176 6f7e9aec bellard
177 81864572 blueswir1
static int nvram_boot_set(void *opaque, const char *boot_device)
178 81864572 blueswir1
{
179 81864572 blueswir1
    unsigned int i;
180 81864572 blueswir1
    uint8_t image[sizeof(ohwcfg_v3_t)];
181 81864572 blueswir1
    ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ
182 81864572 blueswir1
    m48t59_t *nvram = (m48t59_t *)opaque;
183 81864572 blueswir1
184 81864572 blueswir1
    for (i = 0; i < sizeof(image); i++)
185 81864572 blueswir1
        image[i] = m48t59_read(nvram, i) & 0xff;
186 81864572 blueswir1
187 363a37d5 blueswir1
    pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
188 363a37d5 blueswir1
            boot_device);
189 81864572 blueswir1
    header->nboot_devices = strlen(boot_device) & 0xff;
190 81864572 blueswir1
    header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
191 81864572 blueswir1
192 81864572 blueswir1
    for (i = 0; i < sizeof(image); i++)
193 81864572 blueswir1
        m48t59_write(nvram, i, image[i]);
194 81864572 blueswir1
195 81864572 blueswir1
    return 0;
196 81864572 blueswir1
}
197 81864572 blueswir1
198 819385c5 bellard
static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
199 6ef05b95 blueswir1
                       const char *boot_devices, ram_addr_t RAM_size,
200 f930d07e blueswir1
                       uint32_t kernel_size,
201 f930d07e blueswir1
                       int width, int height, int depth,
202 905fdcb5 blueswir1
                       int nvram_machine_id, const char *arch)
203 e80cfcfc bellard
{
204 d2c63fc1 blueswir1
    unsigned int i;
205 66508601 blueswir1
    uint32_t start, end;
206 d2c63fc1 blueswir1
    uint8_t image[0x1ff0];
207 d2c63fc1 blueswir1
    ohwcfg_v3_t *header = (ohwcfg_v3_t *)&image;
208 d2c63fc1 blueswir1
    struct sparc_arch_cfg *sparc_header;
209 d2c63fc1 blueswir1
    struct OpenBIOS_nvpart_v1 *part_header;
210 d2c63fc1 blueswir1
211 d2c63fc1 blueswir1
    memset(image, '\0', sizeof(image));
212 e80cfcfc bellard
213 6f7e9aec bellard
    // Try to match PPC NVRAM
214 363a37d5 blueswir1
    pstrcpy((char *)header->struct_ident, sizeof(header->struct_ident),
215 363a37d5 blueswir1
            "QEMU_BIOS");
216 d2c63fc1 blueswir1
    header->struct_version = cpu_to_be32(3); /* structure v3 */
217 d2c63fc1 blueswir1
218 d2c63fc1 blueswir1
    header->nvram_size = cpu_to_be16(0x2000);
219 d2c63fc1 blueswir1
    header->nvram_arch_ptr = cpu_to_be16(sizeof(ohwcfg_v3_t));
220 d2c63fc1 blueswir1
    header->nvram_arch_size = cpu_to_be16(sizeof(struct sparc_arch_cfg));
221 363a37d5 blueswir1
    pstrcpy((char *)header->arch, sizeof(header->arch), arch);
222 d2c63fc1 blueswir1
    header->nb_cpus = smp_cpus & 0xff;
223 d2c63fc1 blueswir1
    header->RAM0_base = 0;
224 d2c63fc1 blueswir1
    header->RAM0_size = cpu_to_be64((uint64_t)RAM_size);
225 363a37d5 blueswir1
    pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
226 363a37d5 blueswir1
            boot_devices);
227 d2c63fc1 blueswir1
    header->nboot_devices = strlen(boot_devices) & 0xff;
228 d2c63fc1 blueswir1
    header->kernel_image = cpu_to_be64((uint64_t)KERNEL_LOAD_ADDR);
229 d2c63fc1 blueswir1
    header->kernel_size = cpu_to_be64((uint64_t)kernel_size);
230 b6f479d3 bellard
    if (cmdline) {
231 293f78bc blueswir1
        pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, cmdline);
232 d2c63fc1 blueswir1
        header->cmdline = cpu_to_be64((uint64_t)CMDLINE_ADDR);
233 d2c63fc1 blueswir1
        header->cmdline_size = cpu_to_be64((uint64_t)strlen(cmdline));
234 b6f479d3 bellard
    }
235 d2c63fc1 blueswir1
    // XXX add initrd_image, initrd_size
236 d2c63fc1 blueswir1
    header->width = cpu_to_be16(width);
237 d2c63fc1 blueswir1
    header->height = cpu_to_be16(height);
238 d2c63fc1 blueswir1
    header->depth = cpu_to_be16(depth);
239 d2c63fc1 blueswir1
    if (nographic)
240 d2c63fc1 blueswir1
        header->graphic_flags = cpu_to_be16(OHW_GF_NOGRAPHICS);
241 d2c63fc1 blueswir1
242 d2c63fc1 blueswir1
    header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
243 d2c63fc1 blueswir1
244 d2c63fc1 blueswir1
    // Architecture specific header
245 d2c63fc1 blueswir1
    start = sizeof(ohwcfg_v3_t);
246 d2c63fc1 blueswir1
    sparc_header = (struct sparc_arch_cfg *)&image[start];
247 d2c63fc1 blueswir1
    sparc_header->valid = 0;
248 d2c63fc1 blueswir1
    start += sizeof(struct sparc_arch_cfg);
249 b6f479d3 bellard
250 66508601 blueswir1
    // OpenBIOS nvram variables
251 66508601 blueswir1
    // Variable partition
252 d2c63fc1 blueswir1
    part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
253 d2c63fc1 blueswir1
    part_header->signature = OPENBIOS_PART_SYSTEM;
254 363a37d5 blueswir1
    pstrcpy(part_header->name, sizeof(part_header->name), "system");
255 66508601 blueswir1
256 d2c63fc1 blueswir1
    end = start + sizeof(struct OpenBIOS_nvpart_v1);
257 66508601 blueswir1
    for (i = 0; i < nb_prom_envs; i++)
258 d2c63fc1 blueswir1
        end = OpenBIOS_set_var(image, end, prom_envs[i]);
259 d2c63fc1 blueswir1
260 d2c63fc1 blueswir1
    // End marker
261 d2c63fc1 blueswir1
    image[end++] = '\0';
262 66508601 blueswir1
263 66508601 blueswir1
    end = start + ((end - start + 15) & ~15);
264 d2c63fc1 blueswir1
    OpenBIOS_finish_partition(part_header, end - start);
265 66508601 blueswir1
266 66508601 blueswir1
    // free partition
267 66508601 blueswir1
    start = end;
268 d2c63fc1 blueswir1
    part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
269 d2c63fc1 blueswir1
    part_header->signature = OPENBIOS_PART_FREE;
270 363a37d5 blueswir1
    pstrcpy(part_header->name, sizeof(part_header->name), "free");
271 66508601 blueswir1
272 66508601 blueswir1
    end = 0x1fd0;
273 d2c63fc1 blueswir1
    OpenBIOS_finish_partition(part_header, end - start);
274 d2c63fc1 blueswir1
275 905fdcb5 blueswir1
    Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
276 905fdcb5 blueswir1
                    nvram_machine_id);
277 d2c63fc1 blueswir1
278 d2c63fc1 blueswir1
    for (i = 0; i < sizeof(image); i++)
279 d2c63fc1 blueswir1
        m48t59_write(nvram, i, image[i]);
280 81864572 blueswir1
281 81864572 blueswir1
    qemu_register_boot_set(nvram_boot_set, nvram);
282 e80cfcfc bellard
}
283 e80cfcfc bellard
284 e80cfcfc bellard
static void *slavio_intctl;
285 e80cfcfc bellard
286 22548760 blueswir1
void pic_info(void)
287 e80cfcfc bellard
{
288 7d85892b blueswir1
    if (slavio_intctl)
289 7d85892b blueswir1
        slavio_pic_info(slavio_intctl);
290 e80cfcfc bellard
}
291 e80cfcfc bellard
292 22548760 blueswir1
void irq_info(void)
293 e80cfcfc bellard
{
294 7d85892b blueswir1
    if (slavio_intctl)
295 7d85892b blueswir1
        slavio_irq_info(slavio_intctl);
296 e80cfcfc bellard
}
297 e80cfcfc bellard
298 327ac2e7 blueswir1
void cpu_check_irqs(CPUState *env)
299 327ac2e7 blueswir1
{
300 327ac2e7 blueswir1
    if (env->pil_in && (env->interrupt_index == 0 ||
301 327ac2e7 blueswir1
                        (env->interrupt_index & ~15) == TT_EXTINT)) {
302 327ac2e7 blueswir1
        unsigned int i;
303 327ac2e7 blueswir1
304 327ac2e7 blueswir1
        for (i = 15; i > 0; i--) {
305 327ac2e7 blueswir1
            if (env->pil_in & (1 << i)) {
306 327ac2e7 blueswir1
                int old_interrupt = env->interrupt_index;
307 327ac2e7 blueswir1
308 327ac2e7 blueswir1
                env->interrupt_index = TT_EXTINT | i;
309 f32d7ec5 blueswir1
                if (old_interrupt != env->interrupt_index) {
310 f32d7ec5 blueswir1
                    DPRINTF("Set CPU IRQ %d\n", i);
311 327ac2e7 blueswir1
                    cpu_interrupt(env, CPU_INTERRUPT_HARD);
312 f32d7ec5 blueswir1
                }
313 327ac2e7 blueswir1
                break;
314 327ac2e7 blueswir1
            }
315 327ac2e7 blueswir1
        }
316 327ac2e7 blueswir1
    } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
317 f32d7ec5 blueswir1
        DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15);
318 327ac2e7 blueswir1
        env->interrupt_index = 0;
319 327ac2e7 blueswir1
        cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
320 327ac2e7 blueswir1
    }
321 327ac2e7 blueswir1
}
322 327ac2e7 blueswir1
323 b3a23197 blueswir1
static void cpu_set_irq(void *opaque, int irq, int level)
324 b3a23197 blueswir1
{
325 b3a23197 blueswir1
    CPUState *env = opaque;
326 b3a23197 blueswir1
327 b3a23197 blueswir1
    if (level) {
328 b3a23197 blueswir1
        DPRINTF("Raise CPU IRQ %d\n", irq);
329 b3a23197 blueswir1
        env->halted = 0;
330 327ac2e7 blueswir1
        env->pil_in |= 1 << irq;
331 327ac2e7 blueswir1
        cpu_check_irqs(env);
332 b3a23197 blueswir1
    } else {
333 b3a23197 blueswir1
        DPRINTF("Lower CPU IRQ %d\n", irq);
334 327ac2e7 blueswir1
        env->pil_in &= ~(1 << irq);
335 327ac2e7 blueswir1
        cpu_check_irqs(env);
336 b3a23197 blueswir1
    }
337 b3a23197 blueswir1
}
338 b3a23197 blueswir1
339 b3a23197 blueswir1
static void dummy_cpu_set_irq(void *opaque, int irq, int level)
340 b3a23197 blueswir1
{
341 b3a23197 blueswir1
}
342 b3a23197 blueswir1
343 3475187d bellard
static void *slavio_misc;
344 3475187d bellard
345 3475187d bellard
void qemu_system_powerdown(void)
346 3475187d bellard
{
347 3475187d bellard
    slavio_set_power_fail(slavio_misc, 1);
348 3475187d bellard
}
349 3475187d bellard
350 c68ea704 bellard
static void main_cpu_reset(void *opaque)
351 c68ea704 bellard
{
352 c68ea704 bellard
    CPUState *env = opaque;
353 3d29fbef blueswir1
354 3d29fbef blueswir1
    cpu_reset(env);
355 3d29fbef blueswir1
    env->halted = 0;
356 3d29fbef blueswir1
}
357 3d29fbef blueswir1
358 3d29fbef blueswir1
static void secondary_cpu_reset(void *opaque)
359 3d29fbef blueswir1
{
360 3d29fbef blueswir1
    CPUState *env = opaque;
361 3d29fbef blueswir1
362 c68ea704 bellard
    cpu_reset(env);
363 3d29fbef blueswir1
    env->halted = 1;
364 c68ea704 bellard
}
365 c68ea704 bellard
366 6d0c293d blueswir1
static void cpu_halt_signal(void *opaque, int irq, int level)
367 6d0c293d blueswir1
{
368 6d0c293d blueswir1
    if (level && cpu_single_env)
369 6d0c293d blueswir1
        cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT);
370 6d0c293d blueswir1
}
371 6d0c293d blueswir1
372 3ebf5aaf blueswir1
static unsigned long sun4m_load_kernel(const char *kernel_filename,
373 293f78bc blueswir1
                                       const char *initrd_filename,
374 293f78bc blueswir1
                                       ram_addr_t RAM_size)
375 3ebf5aaf blueswir1
{
376 3ebf5aaf blueswir1
    int linux_boot;
377 3ebf5aaf blueswir1
    unsigned int i;
378 3ebf5aaf blueswir1
    long initrd_size, kernel_size;
379 3ebf5aaf blueswir1
380 3ebf5aaf blueswir1
    linux_boot = (kernel_filename != NULL);
381 3ebf5aaf blueswir1
382 3ebf5aaf blueswir1
    kernel_size = 0;
383 3ebf5aaf blueswir1
    if (linux_boot) {
384 3ebf5aaf blueswir1
        kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL,
385 3ebf5aaf blueswir1
                               NULL);
386 3ebf5aaf blueswir1
        if (kernel_size < 0)
387 293f78bc blueswir1
            kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
388 293f78bc blueswir1
                                    RAM_size - KERNEL_LOAD_ADDR);
389 3ebf5aaf blueswir1
        if (kernel_size < 0)
390 293f78bc blueswir1
            kernel_size = load_image_targphys(kernel_filename,
391 293f78bc blueswir1
                                              KERNEL_LOAD_ADDR,
392 293f78bc blueswir1
                                              RAM_size - KERNEL_LOAD_ADDR);
393 3ebf5aaf blueswir1
        if (kernel_size < 0) {
394 3ebf5aaf blueswir1
            fprintf(stderr, "qemu: could not load kernel '%s'\n",
395 3ebf5aaf blueswir1
                    kernel_filename);
396 3ebf5aaf blueswir1
            exit(1);
397 3ebf5aaf blueswir1
        }
398 3ebf5aaf blueswir1
399 3ebf5aaf blueswir1
        /* load initrd */
400 3ebf5aaf blueswir1
        initrd_size = 0;
401 3ebf5aaf blueswir1
        if (initrd_filename) {
402 293f78bc blueswir1
            initrd_size = load_image_targphys(initrd_filename,
403 293f78bc blueswir1
                                              INITRD_LOAD_ADDR,
404 293f78bc blueswir1
                                              RAM_size - INITRD_LOAD_ADDR);
405 3ebf5aaf blueswir1
            if (initrd_size < 0) {
406 3ebf5aaf blueswir1
                fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
407 3ebf5aaf blueswir1
                        initrd_filename);
408 3ebf5aaf blueswir1
                exit(1);
409 3ebf5aaf blueswir1
            }
410 3ebf5aaf blueswir1
        }
411 3ebf5aaf blueswir1
        if (initrd_size > 0) {
412 3ebf5aaf blueswir1
            for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
413 293f78bc blueswir1
                if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
414 293f78bc blueswir1
                    stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
415 293f78bc blueswir1
                    stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
416 3ebf5aaf blueswir1
                    break;
417 3ebf5aaf blueswir1
                }
418 3ebf5aaf blueswir1
            }
419 3ebf5aaf blueswir1
        }
420 3ebf5aaf blueswir1
    }
421 3ebf5aaf blueswir1
    return kernel_size;
422 3ebf5aaf blueswir1
}
423 3ebf5aaf blueswir1
424 8137cde8 blueswir1
static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
425 3ebf5aaf blueswir1
                          const char *boot_device,
426 3023f332 aliguori
                          const char *kernel_filename,
427 3ebf5aaf blueswir1
                          const char *kernel_cmdline,
428 3ebf5aaf blueswir1
                          const char *initrd_filename, const char *cpu_model)
429 36cd9210 blueswir1
430 420557e8 bellard
{
431 ba3c64fb bellard
    CPUState *env, *envs[MAX_CPUS];
432 713c45fa bellard
    unsigned int i;
433 b3ceef24 blueswir1
    void *iommu, *espdma, *ledma, *main_esp, *nvram;
434 b3a23197 blueswir1
    qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
435 d7edfd27 blueswir1
        *espdma_irq, *ledma_irq;
436 2d069bab blueswir1
    qemu_irq *esp_reset, *le_reset;
437 2be17ebd blueswir1
    qemu_irq *fdc_tc;
438 6d0c293d blueswir1
    qemu_irq *cpu_halt;
439 5c6602c5 blueswir1
    ram_addr_t ram_offset, prom_offset, tcx_offset, idreg_offset;
440 5c6602c5 blueswir1
    unsigned long kernel_size;
441 3ebf5aaf blueswir1
    int ret;
442 3ebf5aaf blueswir1
    char buf[1024];
443 e4bcb14c ths
    BlockDriverState *fd[MAX_FD];
444 22548760 blueswir1
    int drive_index;
445 3cce6243 blueswir1
    void *fw_cfg;
446 420557e8 bellard
447 ba3c64fb bellard
    /* init CPUs */
448 3ebf5aaf blueswir1
    if (!cpu_model)
449 3ebf5aaf blueswir1
        cpu_model = hwdef->default_cpu_model;
450 b3a23197 blueswir1
451 ba3c64fb bellard
    for(i = 0; i < smp_cpus; i++) {
452 aaed909a bellard
        env = cpu_init(cpu_model);
453 aaed909a bellard
        if (!env) {
454 8e82c6a8 blueswir1
            fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
455 aaed909a bellard
            exit(1);
456 aaed909a bellard
        }
457 aaed909a bellard
        cpu_sparc_set_id(env, i);
458 ba3c64fb bellard
        envs[i] = env;
459 3d29fbef blueswir1
        if (i == 0) {
460 3d29fbef blueswir1
            qemu_register_reset(main_cpu_reset, env);
461 3d29fbef blueswir1
        } else {
462 3d29fbef blueswir1
            qemu_register_reset(secondary_cpu_reset, env);
463 ba3c64fb bellard
            env->halted = 1;
464 3d29fbef blueswir1
        }
465 b3a23197 blueswir1
        cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
466 3ebf5aaf blueswir1
        env->prom_addr = hwdef->slavio_base;
467 ba3c64fb bellard
    }
468 b3a23197 blueswir1
469 b3a23197 blueswir1
    for (i = smp_cpus; i < MAX_CPUS; i++)
470 b3a23197 blueswir1
        cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
471 b3a23197 blueswir1
472 3ebf5aaf blueswir1
473 420557e8 bellard
    /* allocate RAM */
474 3ebf5aaf blueswir1
    if ((uint64_t)RAM_size > hwdef->max_mem) {
475 77f193da blueswir1
        fprintf(stderr,
476 77f193da blueswir1
                "qemu: Too much memory for this machine: %d, maximum %d\n",
477 6ef05b95 blueswir1
                (unsigned int)(RAM_size / (1024 * 1024)),
478 3ebf5aaf blueswir1
                (unsigned int)(hwdef->max_mem / (1024 * 1024)));
479 3ebf5aaf blueswir1
        exit(1);
480 3ebf5aaf blueswir1
    }
481 5c6602c5 blueswir1
    ram_offset = qemu_ram_alloc(RAM_size);
482 5c6602c5 blueswir1
    cpu_register_physical_memory(0, RAM_size, ram_offset);
483 420557e8 bellard
484 3ebf5aaf blueswir1
    /* load boot prom */
485 5c6602c5 blueswir1
    prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
486 3ebf5aaf blueswir1
    cpu_register_physical_memory(hwdef->slavio_base,
487 3ebf5aaf blueswir1
                                 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
488 3ebf5aaf blueswir1
                                 TARGET_PAGE_MASK,
489 3ebf5aaf blueswir1
                                 prom_offset | IO_MEM_ROM);
490 3ebf5aaf blueswir1
491 3ebf5aaf blueswir1
    if (bios_name == NULL)
492 3ebf5aaf blueswir1
        bios_name = PROM_FILENAME;
493 3ebf5aaf blueswir1
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
494 3ebf5aaf blueswir1
    ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
495 3ebf5aaf blueswir1
    if (ret < 0 || ret > PROM_SIZE_MAX)
496 e01f4a1c blueswir1
        ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
497 3ebf5aaf blueswir1
    if (ret < 0 || ret > PROM_SIZE_MAX) {
498 3ebf5aaf blueswir1
        fprintf(stderr, "qemu: could not load prom '%s'\n",
499 3ebf5aaf blueswir1
                buf);
500 3ebf5aaf blueswir1
        exit(1);
501 3ebf5aaf blueswir1
    }
502 3ebf5aaf blueswir1
503 3ebf5aaf blueswir1
    /* set up devices */
504 36cd9210 blueswir1
    slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
505 5dcb6b91 blueswir1
                                       hwdef->intctl_base + 0x10000ULL,
506 d537cf6c pbrook
                                       &hwdef->intbit_to_level[0],
507 d7edfd27 blueswir1
                                       &slavio_irq, &slavio_cpu_irq,
508 b3a23197 blueswir1
                                       cpu_irqs,
509 d7edfd27 blueswir1
                                       hwdef->clock_irq);
510 b3a23197 blueswir1
511 fe096129 blueswir1
    if (hwdef->idreg_base) {
512 293f78bc blueswir1
        static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
513 4c2485de blueswir1
514 5c6602c5 blueswir1
        idreg_offset = qemu_ram_alloc(sizeof(idreg_data));
515 293f78bc blueswir1
        cpu_register_physical_memory(hwdef->idreg_base, sizeof(idreg_data),
516 5c6602c5 blueswir1
                                     idreg_offset | IO_MEM_ROM);
517 293f78bc blueswir1
        cpu_physical_memory_write_rom(hwdef->idreg_base, idreg_data,
518 293f78bc blueswir1
                                      sizeof(idreg_data));
519 4c2485de blueswir1
    }
520 4c2485de blueswir1
521 ff403da6 blueswir1
    iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
522 ff403da6 blueswir1
                       slavio_irq[hwdef->me_irq]);
523 ff403da6 blueswir1
524 5aca8c3b blueswir1
    espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
525 2d069bab blueswir1
                              iommu, &espdma_irq, &esp_reset);
526 2d069bab blueswir1
527 5aca8c3b blueswir1
    ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
528 2d069bab blueswir1
                             slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
529 2d069bab blueswir1
                             &le_reset);
530 ba3c64fb bellard
531 eee0b836 blueswir1
    if (graphic_depth != 8 && graphic_depth != 24) {
532 eee0b836 blueswir1
        fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
533 eee0b836 blueswir1
        exit (1);
534 eee0b836 blueswir1
    }
535 5c6602c5 blueswir1
    tcx_offset = qemu_ram_alloc(hwdef->vram_size);
536 3023f332 aliguori
    tcx_init(hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset,
537 eee0b836 blueswir1
             hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
538 dbe06e18 blueswir1
539 0ae18cee aliguori
    lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
540 dbe06e18 blueswir1
541 d537cf6c pbrook
    nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
542 d537cf6c pbrook
                        hwdef->nvram_size, 8);
543 81732d19 blueswir1
544 81732d19 blueswir1
    slavio_timer_init_all(hwdef->counter_base, slavio_irq[hwdef->clock1_irq],
545 19f8e5dd blueswir1
                          slavio_cpu_irq, smp_cpus);
546 81732d19 blueswir1
547 577390ff blueswir1
    slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
548 b4ed08e0 blueswir1
                              nographic, ESCC_CLOCK, 1);
549 b81b3b10 bellard
    // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
550 b81b3b10 bellard
    // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
551 aeeb69c7 aurel32
    escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], slavio_irq[hwdef->ser_irq],
552 aeeb69c7 aurel32
              serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
553 741402f9 blueswir1
554 6d0c293d blueswir1
    cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
555 2be17ebd blueswir1
    slavio_misc = slavio_misc_init(hwdef->slavio_base, hwdef->apc_base,
556 2be17ebd blueswir1
                                   hwdef->aux1_base, hwdef->aux2_base,
557 6d0c293d blueswir1
                                   slavio_irq[hwdef->me_irq], cpu_halt[0],
558 2be17ebd blueswir1
                                   &fdc_tc);
559 2be17ebd blueswir1
560 fe096129 blueswir1
    if (hwdef->fd_base) {
561 e4bcb14c ths
        /* there is zero or one floppy drive */
562 309e60bd blueswir1
        memset(fd, 0, sizeof(fd));
563 22548760 blueswir1
        drive_index = drive_get_index(IF_FLOPPY, 0, 0);
564 22548760 blueswir1
        if (drive_index != -1)
565 22548760 blueswir1
            fd[0] = drives_table[drive_index].bdrv;
566 2d069bab blueswir1
567 2be17ebd blueswir1
        sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
568 2be17ebd blueswir1
                          fdc_tc);
569 e4bcb14c ths
    }
570 e4bcb14c ths
571 e4bcb14c ths
    if (drive_get_max_bus(IF_SCSI) > 0) {
572 e4bcb14c ths
        fprintf(stderr, "qemu: too many SCSI bus\n");
573 e4bcb14c ths
        exit(1);
574 e4bcb14c ths
    }
575 e4bcb14c ths
576 5d20fa6b blueswir1
    main_esp = esp_init(hwdef->esp_base, 2,
577 8b17de88 blueswir1
                        espdma_memory_read, espdma_memory_write,
578 8b17de88 blueswir1
                        espdma, *espdma_irq, esp_reset);
579 f1587550 ths
580 e4bcb14c ths
    for (i = 0; i < ESP_MAX_DEVS; i++) {
581 22548760 blueswir1
        drive_index = drive_get_index(IF_SCSI, 0, i);
582 22548760 blueswir1
        if (drive_index == -1)
583 e4bcb14c ths
            continue;
584 22548760 blueswir1
        esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
585 f1587550 ths
    }
586 f1587550 ths
587 fe096129 blueswir1
    if (hwdef->cs_base)
588 803b3c7b blueswir1
        cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl);
589 b3ceef24 blueswir1
590 293f78bc blueswir1
    kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
591 293f78bc blueswir1
                                    RAM_size);
592 36cd9210 blueswir1
593 36cd9210 blueswir1
    nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
594 b3ceef24 blueswir1
               boot_device, RAM_size, kernel_size, graphic_width,
595 905fdcb5 blueswir1
               graphic_height, graphic_depth, hwdef->nvram_machine_id,
596 905fdcb5 blueswir1
               "Sun4m");
597 7eb0c8e8 blueswir1
598 fe096129 blueswir1
    if (hwdef->ecc_base)
599 e42c20b4 blueswir1
        ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq],
600 e42c20b4 blueswir1
                 hwdef->ecc_version);
601 3cce6243 blueswir1
602 3cce6243 blueswir1
    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
603 3cce6243 blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
604 905fdcb5 blueswir1
    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
605 905fdcb5 blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
606 fbfcf955 blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
607 36cd9210 blueswir1
}
608 36cd9210 blueswir1
609 905fdcb5 blueswir1
enum {
610 905fdcb5 blueswir1
    ss2_id = 0,
611 905fdcb5 blueswir1
    ss5_id = 32,
612 905fdcb5 blueswir1
    vger_id,
613 905fdcb5 blueswir1
    lx_id,
614 905fdcb5 blueswir1
    ss4_id,
615 905fdcb5 blueswir1
    scls_id,
616 905fdcb5 blueswir1
    sbook_id,
617 905fdcb5 blueswir1
    ss10_id = 64,
618 905fdcb5 blueswir1
    ss20_id,
619 905fdcb5 blueswir1
    ss600mp_id,
620 905fdcb5 blueswir1
    ss1000_id = 96,
621 905fdcb5 blueswir1
    ss2000_id,
622 905fdcb5 blueswir1
};
623 905fdcb5 blueswir1
624 8137cde8 blueswir1
static const struct sun4m_hwdef sun4m_hwdefs[] = {
625 36cd9210 blueswir1
    /* SS-5 */
626 36cd9210 blueswir1
    {
627 36cd9210 blueswir1
        .iommu_base   = 0x10000000,
628 36cd9210 blueswir1
        .tcx_base     = 0x50000000,
629 36cd9210 blueswir1
        .cs_base      = 0x6c000000,
630 384ccb5d blueswir1
        .slavio_base  = 0x70000000,
631 36cd9210 blueswir1
        .ms_kb_base   = 0x71000000,
632 36cd9210 blueswir1
        .serial_base  = 0x71100000,
633 36cd9210 blueswir1
        .nvram_base   = 0x71200000,
634 36cd9210 blueswir1
        .fd_base      = 0x71400000,
635 36cd9210 blueswir1
        .counter_base = 0x71d00000,
636 36cd9210 blueswir1
        .intctl_base  = 0x71e00000,
637 4c2485de blueswir1
        .idreg_base   = 0x78000000,
638 36cd9210 blueswir1
        .dma_base     = 0x78400000,
639 36cd9210 blueswir1
        .esp_base     = 0x78800000,
640 36cd9210 blueswir1
        .le_base      = 0x78c00000,
641 127fc407 blueswir1
        .apc_base     = 0x6a000000,
642 0019ad53 blueswir1
        .aux1_base    = 0x71900000,
643 0019ad53 blueswir1
        .aux2_base    = 0x71910000,
644 36cd9210 blueswir1
        .vram_size    = 0x00100000,
645 36cd9210 blueswir1
        .nvram_size   = 0x2000,
646 36cd9210 blueswir1
        .esp_irq = 18,
647 36cd9210 blueswir1
        .le_irq = 16,
648 e3a79bca blueswir1
        .clock_irq = 7,
649 36cd9210 blueswir1
        .clock1_irq = 19,
650 36cd9210 blueswir1
        .ms_kb_irq = 14,
651 36cd9210 blueswir1
        .ser_irq = 15,
652 36cd9210 blueswir1
        .fd_irq = 22,
653 36cd9210 blueswir1
        .me_irq = 30,
654 36cd9210 blueswir1
        .cs_irq = 5,
655 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
656 905fdcb5 blueswir1
        .machine_id = ss5_id,
657 cf3102ac blueswir1
        .iommu_version = 0x05000000,
658 e0353fe2 blueswir1
        .intbit_to_level = {
659 f930d07e blueswir1
            2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
660 f930d07e blueswir1
            6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
661 e0353fe2 blueswir1
        },
662 3ebf5aaf blueswir1
        .max_mem = 0x10000000,
663 3ebf5aaf blueswir1
        .default_cpu_model = "Fujitsu MB86904",
664 e0353fe2 blueswir1
    },
665 e0353fe2 blueswir1
    /* SS-10 */
666 e0353fe2 blueswir1
    {
667 5dcb6b91 blueswir1
        .iommu_base   = 0xfe0000000ULL,
668 5dcb6b91 blueswir1
        .tcx_base     = 0xe20000000ULL,
669 5dcb6b91 blueswir1
        .slavio_base  = 0xff0000000ULL,
670 5dcb6b91 blueswir1
        .ms_kb_base   = 0xff1000000ULL,
671 5dcb6b91 blueswir1
        .serial_base  = 0xff1100000ULL,
672 5dcb6b91 blueswir1
        .nvram_base   = 0xff1200000ULL,
673 5dcb6b91 blueswir1
        .fd_base      = 0xff1700000ULL,
674 5dcb6b91 blueswir1
        .counter_base = 0xff1300000ULL,
675 5dcb6b91 blueswir1
        .intctl_base  = 0xff1400000ULL,
676 4c2485de blueswir1
        .idreg_base   = 0xef0000000ULL,
677 5dcb6b91 blueswir1
        .dma_base     = 0xef0400000ULL,
678 5dcb6b91 blueswir1
        .esp_base     = 0xef0800000ULL,
679 5dcb6b91 blueswir1
        .le_base      = 0xef0c00000ULL,
680 0019ad53 blueswir1
        .apc_base     = 0xefa000000ULL, // XXX should not exist
681 127fc407 blueswir1
        .aux1_base    = 0xff1800000ULL,
682 127fc407 blueswir1
        .aux2_base    = 0xff1a01000ULL,
683 7eb0c8e8 blueswir1
        .ecc_base     = 0xf00000000ULL,
684 7eb0c8e8 blueswir1
        .ecc_version  = 0x10000000, // version 0, implementation 1
685 e0353fe2 blueswir1
        .vram_size    = 0x00100000,
686 e0353fe2 blueswir1
        .nvram_size   = 0x2000,
687 e0353fe2 blueswir1
        .esp_irq = 18,
688 e0353fe2 blueswir1
        .le_irq = 16,
689 e3a79bca blueswir1
        .clock_irq = 7,
690 e0353fe2 blueswir1
        .clock1_irq = 19,
691 e0353fe2 blueswir1
        .ms_kb_irq = 14,
692 e0353fe2 blueswir1
        .ser_irq = 15,
693 e0353fe2 blueswir1
        .fd_irq = 22,
694 e0353fe2 blueswir1
        .me_irq = 30,
695 e42c20b4 blueswir1
        .ecc_irq = 28,
696 905fdcb5 blueswir1
        .nvram_machine_id = 0x72,
697 905fdcb5 blueswir1
        .machine_id = ss10_id,
698 7fbfb139 blueswir1
        .iommu_version = 0x03000000,
699 e0353fe2 blueswir1
        .intbit_to_level = {
700 f930d07e blueswir1
            2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
701 f930d07e blueswir1
            6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
702 e0353fe2 blueswir1
        },
703 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
704 3ebf5aaf blueswir1
        .default_cpu_model = "TI SuperSparc II",
705 36cd9210 blueswir1
    },
706 6a3b9cc9 blueswir1
    /* SS-600MP */
707 6a3b9cc9 blueswir1
    {
708 6a3b9cc9 blueswir1
        .iommu_base   = 0xfe0000000ULL,
709 6a3b9cc9 blueswir1
        .tcx_base     = 0xe20000000ULL,
710 6a3b9cc9 blueswir1
        .slavio_base  = 0xff0000000ULL,
711 6a3b9cc9 blueswir1
        .ms_kb_base   = 0xff1000000ULL,
712 6a3b9cc9 blueswir1
        .serial_base  = 0xff1100000ULL,
713 6a3b9cc9 blueswir1
        .nvram_base   = 0xff1200000ULL,
714 6a3b9cc9 blueswir1
        .counter_base = 0xff1300000ULL,
715 6a3b9cc9 blueswir1
        .intctl_base  = 0xff1400000ULL,
716 6a3b9cc9 blueswir1
        .dma_base     = 0xef0081000ULL,
717 6a3b9cc9 blueswir1
        .esp_base     = 0xef0080000ULL,
718 6a3b9cc9 blueswir1
        .le_base      = 0xef0060000ULL,
719 0019ad53 blueswir1
        .apc_base     = 0xefa000000ULL, // XXX should not exist
720 127fc407 blueswir1
        .aux1_base    = 0xff1800000ULL,
721 127fc407 blueswir1
        .aux2_base    = 0xff1a01000ULL, // XXX should not exist
722 7eb0c8e8 blueswir1
        .ecc_base     = 0xf00000000ULL,
723 7eb0c8e8 blueswir1
        .ecc_version  = 0x00000000, // version 0, implementation 0
724 6a3b9cc9 blueswir1
        .vram_size    = 0x00100000,
725 6a3b9cc9 blueswir1
        .nvram_size   = 0x2000,
726 6a3b9cc9 blueswir1
        .esp_irq = 18,
727 6a3b9cc9 blueswir1
        .le_irq = 16,
728 e3a79bca blueswir1
        .clock_irq = 7,
729 6a3b9cc9 blueswir1
        .clock1_irq = 19,
730 6a3b9cc9 blueswir1
        .ms_kb_irq = 14,
731 6a3b9cc9 blueswir1
        .ser_irq = 15,
732 6a3b9cc9 blueswir1
        .fd_irq = 22,
733 6a3b9cc9 blueswir1
        .me_irq = 30,
734 e42c20b4 blueswir1
        .ecc_irq = 28,
735 905fdcb5 blueswir1
        .nvram_machine_id = 0x71,
736 905fdcb5 blueswir1
        .machine_id = ss600mp_id,
737 7fbfb139 blueswir1
        .iommu_version = 0x01000000,
738 6a3b9cc9 blueswir1
        .intbit_to_level = {
739 6a3b9cc9 blueswir1
            2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
740 6a3b9cc9 blueswir1
            6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
741 6a3b9cc9 blueswir1
        },
742 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
743 3ebf5aaf blueswir1
        .default_cpu_model = "TI SuperSparc II",
744 6a3b9cc9 blueswir1
    },
745 ae40972f blueswir1
    /* SS-20 */
746 ae40972f blueswir1
    {
747 ae40972f blueswir1
        .iommu_base   = 0xfe0000000ULL,
748 ae40972f blueswir1
        .tcx_base     = 0xe20000000ULL,
749 ae40972f blueswir1
        .slavio_base  = 0xff0000000ULL,
750 ae40972f blueswir1
        .ms_kb_base   = 0xff1000000ULL,
751 ae40972f blueswir1
        .serial_base  = 0xff1100000ULL,
752 ae40972f blueswir1
        .nvram_base   = 0xff1200000ULL,
753 ae40972f blueswir1
        .fd_base      = 0xff1700000ULL,
754 ae40972f blueswir1
        .counter_base = 0xff1300000ULL,
755 ae40972f blueswir1
        .intctl_base  = 0xff1400000ULL,
756 4c2485de blueswir1
        .idreg_base   = 0xef0000000ULL,
757 ae40972f blueswir1
        .dma_base     = 0xef0400000ULL,
758 ae40972f blueswir1
        .esp_base     = 0xef0800000ULL,
759 ae40972f blueswir1
        .le_base      = 0xef0c00000ULL,
760 0019ad53 blueswir1
        .apc_base     = 0xefa000000ULL, // XXX should not exist
761 577d8dd4 blueswir1
        .aux1_base    = 0xff1800000ULL,
762 577d8dd4 blueswir1
        .aux2_base    = 0xff1a01000ULL,
763 ae40972f blueswir1
        .ecc_base     = 0xf00000000ULL,
764 ae40972f blueswir1
        .ecc_version  = 0x20000000, // version 0, implementation 2
765 ae40972f blueswir1
        .vram_size    = 0x00100000,
766 ae40972f blueswir1
        .nvram_size   = 0x2000,
767 ae40972f blueswir1
        .esp_irq = 18,
768 ae40972f blueswir1
        .le_irq = 16,
769 e3a79bca blueswir1
        .clock_irq = 7,
770 ae40972f blueswir1
        .clock1_irq = 19,
771 ae40972f blueswir1
        .ms_kb_irq = 14,
772 ae40972f blueswir1
        .ser_irq = 15,
773 ae40972f blueswir1
        .fd_irq = 22,
774 ae40972f blueswir1
        .me_irq = 30,
775 e42c20b4 blueswir1
        .ecc_irq = 28,
776 905fdcb5 blueswir1
        .nvram_machine_id = 0x72,
777 905fdcb5 blueswir1
        .machine_id = ss20_id,
778 ae40972f blueswir1
        .iommu_version = 0x13000000,
779 ae40972f blueswir1
        .intbit_to_level = {
780 ae40972f blueswir1
            2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
781 ae40972f blueswir1
            6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
782 ae40972f blueswir1
        },
783 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
784 ae40972f blueswir1
        .default_cpu_model = "TI SuperSparc II",
785 ae40972f blueswir1
    },
786 a526a31c blueswir1
    /* Voyager */
787 a526a31c blueswir1
    {
788 a526a31c blueswir1
        .iommu_base   = 0x10000000,
789 a526a31c blueswir1
        .tcx_base     = 0x50000000,
790 a526a31c blueswir1
        .slavio_base  = 0x70000000,
791 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
792 a526a31c blueswir1
        .serial_base  = 0x71100000,
793 a526a31c blueswir1
        .nvram_base   = 0x71200000,
794 a526a31c blueswir1
        .fd_base      = 0x71400000,
795 a526a31c blueswir1
        .counter_base = 0x71d00000,
796 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
797 a526a31c blueswir1
        .idreg_base   = 0x78000000,
798 a526a31c blueswir1
        .dma_base     = 0x78400000,
799 a526a31c blueswir1
        .esp_base     = 0x78800000,
800 a526a31c blueswir1
        .le_base      = 0x78c00000,
801 a526a31c blueswir1
        .apc_base     = 0x71300000, // pmc
802 a526a31c blueswir1
        .aux1_base    = 0x71900000,
803 a526a31c blueswir1
        .aux2_base    = 0x71910000,
804 a526a31c blueswir1
        .vram_size    = 0x00100000,
805 a526a31c blueswir1
        .nvram_size   = 0x2000,
806 a526a31c blueswir1
        .esp_irq = 18,
807 a526a31c blueswir1
        .le_irq = 16,
808 a526a31c blueswir1
        .clock_irq = 7,
809 a526a31c blueswir1
        .clock1_irq = 19,
810 a526a31c blueswir1
        .ms_kb_irq = 14,
811 a526a31c blueswir1
        .ser_irq = 15,
812 a526a31c blueswir1
        .fd_irq = 22,
813 a526a31c blueswir1
        .me_irq = 30,
814 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
815 905fdcb5 blueswir1
        .machine_id = vger_id,
816 a526a31c blueswir1
        .iommu_version = 0x05000000,
817 a526a31c blueswir1
        .intbit_to_level = {
818 a526a31c blueswir1
            2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
819 a526a31c blueswir1
            6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
820 a526a31c blueswir1
        },
821 a526a31c blueswir1
        .max_mem = 0x10000000,
822 a526a31c blueswir1
        .default_cpu_model = "Fujitsu MB86904",
823 a526a31c blueswir1
    },
824 a526a31c blueswir1
    /* LX */
825 a526a31c blueswir1
    {
826 a526a31c blueswir1
        .iommu_base   = 0x10000000,
827 a526a31c blueswir1
        .tcx_base     = 0x50000000,
828 a526a31c blueswir1
        .slavio_base  = 0x70000000,
829 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
830 a526a31c blueswir1
        .serial_base  = 0x71100000,
831 a526a31c blueswir1
        .nvram_base   = 0x71200000,
832 a526a31c blueswir1
        .fd_base      = 0x71400000,
833 a526a31c blueswir1
        .counter_base = 0x71d00000,
834 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
835 a526a31c blueswir1
        .idreg_base   = 0x78000000,
836 a526a31c blueswir1
        .dma_base     = 0x78400000,
837 a526a31c blueswir1
        .esp_base     = 0x78800000,
838 a526a31c blueswir1
        .le_base      = 0x78c00000,
839 a526a31c blueswir1
        .aux1_base    = 0x71900000,
840 a526a31c blueswir1
        .aux2_base    = 0x71910000,
841 a526a31c blueswir1
        .vram_size    = 0x00100000,
842 a526a31c blueswir1
        .nvram_size   = 0x2000,
843 a526a31c blueswir1
        .esp_irq = 18,
844 a526a31c blueswir1
        .le_irq = 16,
845 a526a31c blueswir1
        .clock_irq = 7,
846 a526a31c blueswir1
        .clock1_irq = 19,
847 a526a31c blueswir1
        .ms_kb_irq = 14,
848 a526a31c blueswir1
        .ser_irq = 15,
849 a526a31c blueswir1
        .fd_irq = 22,
850 a526a31c blueswir1
        .me_irq = 30,
851 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
852 905fdcb5 blueswir1
        .machine_id = lx_id,
853 a526a31c blueswir1
        .iommu_version = 0x04000000,
854 a526a31c blueswir1
        .intbit_to_level = {
855 a526a31c blueswir1
            2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
856 a526a31c blueswir1
            6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
857 a526a31c blueswir1
        },
858 a526a31c blueswir1
        .max_mem = 0x10000000,
859 a526a31c blueswir1
        .default_cpu_model = "TI MicroSparc I",
860 a526a31c blueswir1
    },
861 a526a31c blueswir1
    /* SS-4 */
862 a526a31c blueswir1
    {
863 a526a31c blueswir1
        .iommu_base   = 0x10000000,
864 a526a31c blueswir1
        .tcx_base     = 0x50000000,
865 a526a31c blueswir1
        .cs_base      = 0x6c000000,
866 a526a31c blueswir1
        .slavio_base  = 0x70000000,
867 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
868 a526a31c blueswir1
        .serial_base  = 0x71100000,
869 a526a31c blueswir1
        .nvram_base   = 0x71200000,
870 a526a31c blueswir1
        .fd_base      = 0x71400000,
871 a526a31c blueswir1
        .counter_base = 0x71d00000,
872 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
873 a526a31c blueswir1
        .idreg_base   = 0x78000000,
874 a526a31c blueswir1
        .dma_base     = 0x78400000,
875 a526a31c blueswir1
        .esp_base     = 0x78800000,
876 a526a31c blueswir1
        .le_base      = 0x78c00000,
877 a526a31c blueswir1
        .apc_base     = 0x6a000000,
878 a526a31c blueswir1
        .aux1_base    = 0x71900000,
879 a526a31c blueswir1
        .aux2_base    = 0x71910000,
880 a526a31c blueswir1
        .vram_size    = 0x00100000,
881 a526a31c blueswir1
        .nvram_size   = 0x2000,
882 a526a31c blueswir1
        .esp_irq = 18,
883 a526a31c blueswir1
        .le_irq = 16,
884 a526a31c blueswir1
        .clock_irq = 7,
885 a526a31c blueswir1
        .clock1_irq = 19,
886 a526a31c blueswir1
        .ms_kb_irq = 14,
887 a526a31c blueswir1
        .ser_irq = 15,
888 a526a31c blueswir1
        .fd_irq = 22,
889 a526a31c blueswir1
        .me_irq = 30,
890 a526a31c blueswir1
        .cs_irq = 5,
891 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
892 905fdcb5 blueswir1
        .machine_id = ss4_id,
893 a526a31c blueswir1
        .iommu_version = 0x05000000,
894 a526a31c blueswir1
        .intbit_to_level = {
895 a526a31c blueswir1
            2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
896 a526a31c blueswir1
            6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
897 a526a31c blueswir1
        },
898 a526a31c blueswir1
        .max_mem = 0x10000000,
899 a526a31c blueswir1
        .default_cpu_model = "Fujitsu MB86904",
900 a526a31c blueswir1
    },
901 a526a31c blueswir1
    /* SPARCClassic */
902 a526a31c blueswir1
    {
903 a526a31c blueswir1
        .iommu_base   = 0x10000000,
904 a526a31c blueswir1
        .tcx_base     = 0x50000000,
905 a526a31c blueswir1
        .slavio_base  = 0x70000000,
906 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
907 a526a31c blueswir1
        .serial_base  = 0x71100000,
908 a526a31c blueswir1
        .nvram_base   = 0x71200000,
909 a526a31c blueswir1
        .fd_base      = 0x71400000,
910 a526a31c blueswir1
        .counter_base = 0x71d00000,
911 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
912 a526a31c blueswir1
        .idreg_base   = 0x78000000,
913 a526a31c blueswir1
        .dma_base     = 0x78400000,
914 a526a31c blueswir1
        .esp_base     = 0x78800000,
915 a526a31c blueswir1
        .le_base      = 0x78c00000,
916 a526a31c blueswir1
        .apc_base     = 0x6a000000,
917 a526a31c blueswir1
        .aux1_base    = 0x71900000,
918 a526a31c blueswir1
        .aux2_base    = 0x71910000,
919 a526a31c blueswir1
        .vram_size    = 0x00100000,
920 a526a31c blueswir1
        .nvram_size   = 0x2000,
921 a526a31c blueswir1
        .esp_irq = 18,
922 a526a31c blueswir1
        .le_irq = 16,
923 a526a31c blueswir1
        .clock_irq = 7,
924 a526a31c blueswir1
        .clock1_irq = 19,
925 a526a31c blueswir1
        .ms_kb_irq = 14,
926 a526a31c blueswir1
        .ser_irq = 15,
927 a526a31c blueswir1
        .fd_irq = 22,
928 a526a31c blueswir1
        .me_irq = 30,
929 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
930 905fdcb5 blueswir1
        .machine_id = scls_id,
931 a526a31c blueswir1
        .iommu_version = 0x05000000,
932 a526a31c blueswir1
        .intbit_to_level = {
933 a526a31c blueswir1
            2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
934 a526a31c blueswir1
            6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
935 a526a31c blueswir1
        },
936 a526a31c blueswir1
        .max_mem = 0x10000000,
937 a526a31c blueswir1
        .default_cpu_model = "TI MicroSparc I",
938 a526a31c blueswir1
    },
939 a526a31c blueswir1
    /* SPARCbook */
940 a526a31c blueswir1
    {
941 a526a31c blueswir1
        .iommu_base   = 0x10000000,
942 a526a31c blueswir1
        .tcx_base     = 0x50000000, // XXX
943 a526a31c blueswir1
        .slavio_base  = 0x70000000,
944 a526a31c blueswir1
        .ms_kb_base   = 0x71000000,
945 a526a31c blueswir1
        .serial_base  = 0x71100000,
946 a526a31c blueswir1
        .nvram_base   = 0x71200000,
947 a526a31c blueswir1
        .fd_base      = 0x71400000,
948 a526a31c blueswir1
        .counter_base = 0x71d00000,
949 a526a31c blueswir1
        .intctl_base  = 0x71e00000,
950 a526a31c blueswir1
        .idreg_base   = 0x78000000,
951 a526a31c blueswir1
        .dma_base     = 0x78400000,
952 a526a31c blueswir1
        .esp_base     = 0x78800000,
953 a526a31c blueswir1
        .le_base      = 0x78c00000,
954 a526a31c blueswir1
        .apc_base     = 0x6a000000,
955 a526a31c blueswir1
        .aux1_base    = 0x71900000,
956 a526a31c blueswir1
        .aux2_base    = 0x71910000,
957 a526a31c blueswir1
        .vram_size    = 0x00100000,
958 a526a31c blueswir1
        .nvram_size   = 0x2000,
959 a526a31c blueswir1
        .esp_irq = 18,
960 a526a31c blueswir1
        .le_irq = 16,
961 a526a31c blueswir1
        .clock_irq = 7,
962 a526a31c blueswir1
        .clock1_irq = 19,
963 a526a31c blueswir1
        .ms_kb_irq = 14,
964 a526a31c blueswir1
        .ser_irq = 15,
965 a526a31c blueswir1
        .fd_irq = 22,
966 a526a31c blueswir1
        .me_irq = 30,
967 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
968 905fdcb5 blueswir1
        .machine_id = sbook_id,
969 a526a31c blueswir1
        .iommu_version = 0x05000000,
970 a526a31c blueswir1
        .intbit_to_level = {
971 a526a31c blueswir1
            2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
972 a526a31c blueswir1
            6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
973 a526a31c blueswir1
        },
974 a526a31c blueswir1
        .max_mem = 0x10000000,
975 a526a31c blueswir1
        .default_cpu_model = "TI MicroSparc I",
976 a526a31c blueswir1
    },
977 36cd9210 blueswir1
};
978 36cd9210 blueswir1
979 36cd9210 blueswir1
/* SPARCstation 5 hardware initialisation */
980 00f82b8a aurel32
static void ss5_init(ram_addr_t RAM_size, int vga_ram_size,
981 3023f332 aliguori
                     const char *boot_device,
982 b881c2c6 blueswir1
                     const char *kernel_filename, const char *kernel_cmdline,
983 b881c2c6 blueswir1
                     const char *initrd_filename, const char *cpu_model)
984 36cd9210 blueswir1
{
985 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
986 3ebf5aaf blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
987 420557e8 bellard
}
988 c0e564d5 bellard
989 e0353fe2 blueswir1
/* SPARCstation 10 hardware initialisation */
990 00f82b8a aurel32
static void ss10_init(ram_addr_t RAM_size, int vga_ram_size,
991 3023f332 aliguori
                      const char *boot_device,
992 b881c2c6 blueswir1
                      const char *kernel_filename, const char *kernel_cmdline,
993 b881c2c6 blueswir1
                      const char *initrd_filename, const char *cpu_model)
994 e0353fe2 blueswir1
{
995 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
996 3ebf5aaf blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
997 e0353fe2 blueswir1
}
998 e0353fe2 blueswir1
999 6a3b9cc9 blueswir1
/* SPARCserver 600MP hardware initialisation */
1000 00f82b8a aurel32
static void ss600mp_init(ram_addr_t RAM_size, int vga_ram_size,
1001 3023f332 aliguori
                         const char *boot_device,
1002 77f193da blueswir1
                         const char *kernel_filename,
1003 77f193da blueswir1
                         const char *kernel_cmdline,
1004 6a3b9cc9 blueswir1
                         const char *initrd_filename, const char *cpu_model)
1005 6a3b9cc9 blueswir1
{
1006 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
1007 3ebf5aaf blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1008 6a3b9cc9 blueswir1
}
1009 6a3b9cc9 blueswir1
1010 ae40972f blueswir1
/* SPARCstation 20 hardware initialisation */
1011 00f82b8a aurel32
static void ss20_init(ram_addr_t RAM_size, int vga_ram_size,
1012 3023f332 aliguori
                      const char *boot_device,
1013 ae40972f blueswir1
                      const char *kernel_filename, const char *kernel_cmdline,
1014 ae40972f blueswir1
                      const char *initrd_filename, const char *cpu_model)
1015 ae40972f blueswir1
{
1016 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
1017 ee76f82e blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1018 ee76f82e blueswir1
}
1019 ee76f82e blueswir1
1020 a526a31c blueswir1
/* SPARCstation Voyager hardware initialisation */
1021 6ef05b95 blueswir1
static void vger_init(ram_addr_t RAM_size, int vga_ram_size,
1022 3023f332 aliguori
                      const char *boot_device,
1023 a526a31c blueswir1
                      const char *kernel_filename, const char *kernel_cmdline,
1024 a526a31c blueswir1
                      const char *initrd_filename, const char *cpu_model)
1025 a526a31c blueswir1
{
1026 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
1027 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1028 a526a31c blueswir1
}
1029 a526a31c blueswir1
1030 a526a31c blueswir1
/* SPARCstation LX hardware initialisation */
1031 6ef05b95 blueswir1
static void ss_lx_init(ram_addr_t RAM_size, int vga_ram_size,
1032 3023f332 aliguori
                       const char *boot_device,
1033 a526a31c blueswir1
                       const char *kernel_filename, const char *kernel_cmdline,
1034 a526a31c blueswir1
                       const char *initrd_filename, const char *cpu_model)
1035 a526a31c blueswir1
{
1036 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
1037 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1038 a526a31c blueswir1
}
1039 a526a31c blueswir1
1040 a526a31c blueswir1
/* SPARCstation 4 hardware initialisation */
1041 6ef05b95 blueswir1
static void ss4_init(ram_addr_t RAM_size, int vga_ram_size,
1042 3023f332 aliguori
                     const char *boot_device,
1043 a526a31c blueswir1
                     const char *kernel_filename, const char *kernel_cmdline,
1044 a526a31c blueswir1
                     const char *initrd_filename, const char *cpu_model)
1045 a526a31c blueswir1
{
1046 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
1047 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1048 a526a31c blueswir1
}
1049 a526a31c blueswir1
1050 a526a31c blueswir1
/* SPARCClassic hardware initialisation */
1051 6ef05b95 blueswir1
static void scls_init(ram_addr_t RAM_size, int vga_ram_size,
1052 3023f332 aliguori
                      const char *boot_device,
1053 a526a31c blueswir1
                      const char *kernel_filename, const char *kernel_cmdline,
1054 a526a31c blueswir1
                      const char *initrd_filename, const char *cpu_model)
1055 a526a31c blueswir1
{
1056 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
1057 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1058 a526a31c blueswir1
}
1059 a526a31c blueswir1
1060 a526a31c blueswir1
/* SPARCbook hardware initialisation */
1061 6ef05b95 blueswir1
static void sbook_init(ram_addr_t RAM_size, int vga_ram_size,
1062 3023f332 aliguori
                       const char *boot_device,
1063 a526a31c blueswir1
                       const char *kernel_filename, const char *kernel_cmdline,
1064 a526a31c blueswir1
                       const char *initrd_filename, const char *cpu_model)
1065 a526a31c blueswir1
{
1066 3023f332 aliguori
    sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
1067 a526a31c blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1068 a526a31c blueswir1
}
1069 a526a31c blueswir1
1070 36cd9210 blueswir1
QEMUMachine ss5_machine = {
1071 66de733b blueswir1
    .name = "SS-5",
1072 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation 5",
1073 66de733b blueswir1
    .init = ss5_init,
1074 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1075 f88e4b91 blueswir1
    .nodisk_ok = 1,
1076 c9b1ae2c blueswir1
    .use_scsi = 1,
1077 c0e564d5 bellard
};
1078 e0353fe2 blueswir1
1079 e0353fe2 blueswir1
QEMUMachine ss10_machine = {
1080 66de733b blueswir1
    .name = "SS-10",
1081 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation 10",
1082 66de733b blueswir1
    .init = ss10_init,
1083 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1084 f88e4b91 blueswir1
    .nodisk_ok = 1,
1085 c9b1ae2c blueswir1
    .use_scsi = 1,
1086 1bcee014 blueswir1
    .max_cpus = 4,
1087 e0353fe2 blueswir1
};
1088 6a3b9cc9 blueswir1
1089 6a3b9cc9 blueswir1
QEMUMachine ss600mp_machine = {
1090 66de733b blueswir1
    .name = "SS-600MP",
1091 66de733b blueswir1
    .desc = "Sun4m platform, SPARCserver 600MP",
1092 66de733b blueswir1
    .init = ss600mp_init,
1093 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1094 f88e4b91 blueswir1
    .nodisk_ok = 1,
1095 c9b1ae2c blueswir1
    .use_scsi = 1,
1096 1bcee014 blueswir1
    .max_cpus = 4,
1097 6a3b9cc9 blueswir1
};
1098 ae40972f blueswir1
1099 ae40972f blueswir1
QEMUMachine ss20_machine = {
1100 66de733b blueswir1
    .name = "SS-20",
1101 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation 20",
1102 66de733b blueswir1
    .init = ss20_init,
1103 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1104 f88e4b91 blueswir1
    .nodisk_ok = 1,
1105 c9b1ae2c blueswir1
    .use_scsi = 1,
1106 1bcee014 blueswir1
    .max_cpus = 4,
1107 ae40972f blueswir1
};
1108 ae40972f blueswir1
1109 a526a31c blueswir1
QEMUMachine voyager_machine = {
1110 66de733b blueswir1
    .name = "Voyager",
1111 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation Voyager",
1112 66de733b blueswir1
    .init = vger_init,
1113 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1114 f88e4b91 blueswir1
    .nodisk_ok = 1,
1115 c9b1ae2c blueswir1
    .use_scsi = 1,
1116 a526a31c blueswir1
};
1117 a526a31c blueswir1
1118 a526a31c blueswir1
QEMUMachine ss_lx_machine = {
1119 66de733b blueswir1
    .name = "LX",
1120 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation LX",
1121 66de733b blueswir1
    .init = ss_lx_init,
1122 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1123 f88e4b91 blueswir1
    .nodisk_ok = 1,
1124 c9b1ae2c blueswir1
    .use_scsi = 1,
1125 a526a31c blueswir1
};
1126 a526a31c blueswir1
1127 a526a31c blueswir1
QEMUMachine ss4_machine = {
1128 66de733b blueswir1
    .name = "SS-4",
1129 66de733b blueswir1
    .desc = "Sun4m platform, SPARCstation 4",
1130 66de733b blueswir1
    .init = ss4_init,
1131 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1132 f88e4b91 blueswir1
    .nodisk_ok = 1,
1133 c9b1ae2c blueswir1
    .use_scsi = 1,
1134 a526a31c blueswir1
};
1135 a526a31c blueswir1
1136 a526a31c blueswir1
QEMUMachine scls_machine = {
1137 66de733b blueswir1
    .name = "SPARCClassic",
1138 66de733b blueswir1
    .desc = "Sun4m platform, SPARCClassic",
1139 66de733b blueswir1
    .init = scls_init,
1140 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1141 f88e4b91 blueswir1
    .nodisk_ok = 1,
1142 c9b1ae2c blueswir1
    .use_scsi = 1,
1143 a526a31c blueswir1
};
1144 a526a31c blueswir1
1145 a526a31c blueswir1
QEMUMachine sbook_machine = {
1146 66de733b blueswir1
    .name = "SPARCbook",
1147 66de733b blueswir1
    .desc = "Sun4m platform, SPARCbook",
1148 66de733b blueswir1
    .init = sbook_init,
1149 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1150 f88e4b91 blueswir1
    .nodisk_ok = 1,
1151 c9b1ae2c blueswir1
    .use_scsi = 1,
1152 a526a31c blueswir1
};
1153 a526a31c blueswir1
1154 7d85892b blueswir1
static const struct sun4d_hwdef sun4d_hwdefs[] = {
1155 7d85892b blueswir1
    /* SS-1000 */
1156 7d85892b blueswir1
    {
1157 7d85892b blueswir1
        .iounit_bases   = {
1158 7d85892b blueswir1
            0xfe0200000ULL,
1159 7d85892b blueswir1
            0xfe1200000ULL,
1160 7d85892b blueswir1
            0xfe2200000ULL,
1161 7d85892b blueswir1
            0xfe3200000ULL,
1162 7d85892b blueswir1
            -1,
1163 7d85892b blueswir1
        },
1164 7d85892b blueswir1
        .tcx_base     = 0x820000000ULL,
1165 7d85892b blueswir1
        .slavio_base  = 0xf00000000ULL,
1166 7d85892b blueswir1
        .ms_kb_base   = 0xf00240000ULL,
1167 7d85892b blueswir1
        .serial_base  = 0xf00200000ULL,
1168 7d85892b blueswir1
        .nvram_base   = 0xf00280000ULL,
1169 7d85892b blueswir1
        .counter_base = 0xf00300000ULL,
1170 7d85892b blueswir1
        .espdma_base  = 0x800081000ULL,
1171 7d85892b blueswir1
        .esp_base     = 0x800080000ULL,
1172 7d85892b blueswir1
        .ledma_base   = 0x800040000ULL,
1173 7d85892b blueswir1
        .le_base      = 0x800060000ULL,
1174 7d85892b blueswir1
        .sbi_base     = 0xf02800000ULL,
1175 c1d00dc0 blueswir1
        .vram_size    = 0x00100000,
1176 7d85892b blueswir1
        .nvram_size   = 0x2000,
1177 7d85892b blueswir1
        .esp_irq = 3,
1178 7d85892b blueswir1
        .le_irq = 4,
1179 7d85892b blueswir1
        .clock_irq = 14,
1180 7d85892b blueswir1
        .clock1_irq = 10,
1181 7d85892b blueswir1
        .ms_kb_irq = 12,
1182 7d85892b blueswir1
        .ser_irq = 12,
1183 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1184 905fdcb5 blueswir1
        .machine_id = ss1000_id,
1185 7d85892b blueswir1
        .iounit_version = 0x03000000,
1186 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
1187 7d85892b blueswir1
        .default_cpu_model = "TI SuperSparc II",
1188 7d85892b blueswir1
    },
1189 7d85892b blueswir1
    /* SS-2000 */
1190 7d85892b blueswir1
    {
1191 7d85892b blueswir1
        .iounit_bases   = {
1192 7d85892b blueswir1
            0xfe0200000ULL,
1193 7d85892b blueswir1
            0xfe1200000ULL,
1194 7d85892b blueswir1
            0xfe2200000ULL,
1195 7d85892b blueswir1
            0xfe3200000ULL,
1196 7d85892b blueswir1
            0xfe4200000ULL,
1197 7d85892b blueswir1
        },
1198 7d85892b blueswir1
        .tcx_base     = 0x820000000ULL,
1199 7d85892b blueswir1
        .slavio_base  = 0xf00000000ULL,
1200 7d85892b blueswir1
        .ms_kb_base   = 0xf00240000ULL,
1201 7d85892b blueswir1
        .serial_base  = 0xf00200000ULL,
1202 7d85892b blueswir1
        .nvram_base   = 0xf00280000ULL,
1203 7d85892b blueswir1
        .counter_base = 0xf00300000ULL,
1204 7d85892b blueswir1
        .espdma_base  = 0x800081000ULL,
1205 7d85892b blueswir1
        .esp_base     = 0x800080000ULL,
1206 7d85892b blueswir1
        .ledma_base   = 0x800040000ULL,
1207 7d85892b blueswir1
        .le_base      = 0x800060000ULL,
1208 7d85892b blueswir1
        .sbi_base     = 0xf02800000ULL,
1209 c1d00dc0 blueswir1
        .vram_size    = 0x00100000,
1210 7d85892b blueswir1
        .nvram_size   = 0x2000,
1211 7d85892b blueswir1
        .esp_irq = 3,
1212 7d85892b blueswir1
        .le_irq = 4,
1213 7d85892b blueswir1
        .clock_irq = 14,
1214 7d85892b blueswir1
        .clock1_irq = 10,
1215 7d85892b blueswir1
        .ms_kb_irq = 12,
1216 7d85892b blueswir1
        .ser_irq = 12,
1217 905fdcb5 blueswir1
        .nvram_machine_id = 0x80,
1218 905fdcb5 blueswir1
        .machine_id = ss2000_id,
1219 7d85892b blueswir1
        .iounit_version = 0x03000000,
1220 6ef05b95 blueswir1
        .max_mem = 0xf00000000ULL,
1221 7d85892b blueswir1
        .default_cpu_model = "TI SuperSparc II",
1222 7d85892b blueswir1
    },
1223 7d85892b blueswir1
};
1224 7d85892b blueswir1
1225 6ef05b95 blueswir1
static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1226 7d85892b blueswir1
                          const char *boot_device,
1227 3023f332 aliguori
                          const char *kernel_filename,
1228 7d85892b blueswir1
                          const char *kernel_cmdline,
1229 7d85892b blueswir1
                          const char *initrd_filename, const char *cpu_model)
1230 7d85892b blueswir1
{
1231 7d85892b blueswir1
    CPUState *env, *envs[MAX_CPUS];
1232 7d85892b blueswir1
    unsigned int i;
1233 7d85892b blueswir1
    void *iounits[MAX_IOUNITS], *espdma, *ledma, *main_esp, *nvram, *sbi;
1234 7d85892b blueswir1
    qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1235 7d85892b blueswir1
        *espdma_irq, *ledma_irq;
1236 7d85892b blueswir1
    qemu_irq *esp_reset, *le_reset;
1237 5c6602c5 blueswir1
    ram_addr_t ram_offset, prom_offset, tcx_offset;
1238 5c6602c5 blueswir1
    unsigned long kernel_size;
1239 7d85892b blueswir1
    int ret;
1240 7d85892b blueswir1
    char buf[1024];
1241 22548760 blueswir1
    int drive_index;
1242 3cce6243 blueswir1
    void *fw_cfg;
1243 7d85892b blueswir1
1244 7d85892b blueswir1
    /* init CPUs */
1245 7d85892b blueswir1
    if (!cpu_model)
1246 7d85892b blueswir1
        cpu_model = hwdef->default_cpu_model;
1247 7d85892b blueswir1
1248 7d85892b blueswir1
    for (i = 0; i < smp_cpus; i++) {
1249 7d85892b blueswir1
        env = cpu_init(cpu_model);
1250 7d85892b blueswir1
        if (!env) {
1251 8e82c6a8 blueswir1
            fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1252 7d85892b blueswir1
            exit(1);
1253 7d85892b blueswir1
        }
1254 7d85892b blueswir1
        cpu_sparc_set_id(env, i);
1255 7d85892b blueswir1
        envs[i] = env;
1256 7d85892b blueswir1
        if (i == 0) {
1257 7d85892b blueswir1
            qemu_register_reset(main_cpu_reset, env);
1258 7d85892b blueswir1
        } else {
1259 7d85892b blueswir1
            qemu_register_reset(secondary_cpu_reset, env);
1260 7d85892b blueswir1
            env->halted = 1;
1261 7d85892b blueswir1
        }
1262 7d85892b blueswir1
        cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
1263 7d85892b blueswir1
        env->prom_addr = hwdef->slavio_base;
1264 7d85892b blueswir1
    }
1265 7d85892b blueswir1
1266 7d85892b blueswir1
    for (i = smp_cpus; i < MAX_CPUS; i++)
1267 7d85892b blueswir1
        cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1268 7d85892b blueswir1
1269 7d85892b blueswir1
    /* allocate RAM */
1270 7d85892b blueswir1
    if ((uint64_t)RAM_size > hwdef->max_mem) {
1271 77f193da blueswir1
        fprintf(stderr,
1272 77f193da blueswir1
                "qemu: Too much memory for this machine: %d, maximum %d\n",
1273 6ef05b95 blueswir1
                (unsigned int)(RAM_size / (1024 * 1024)),
1274 7d85892b blueswir1
                (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1275 7d85892b blueswir1
        exit(1);
1276 7d85892b blueswir1
    }
1277 5c6602c5 blueswir1
    ram_offset = qemu_ram_alloc(RAM_size);
1278 5c6602c5 blueswir1
    cpu_register_physical_memory(0, RAM_size, ram_offset);
1279 7d85892b blueswir1
1280 7d85892b blueswir1
    /* load boot prom */
1281 5c6602c5 blueswir1
    prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
1282 7d85892b blueswir1
    cpu_register_physical_memory(hwdef->slavio_base,
1283 7d85892b blueswir1
                                 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1284 7d85892b blueswir1
                                 TARGET_PAGE_MASK,
1285 7d85892b blueswir1
                                 prom_offset | IO_MEM_ROM);
1286 7d85892b blueswir1
1287 7d85892b blueswir1
    if (bios_name == NULL)
1288 7d85892b blueswir1
        bios_name = PROM_FILENAME;
1289 7d85892b blueswir1
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1290 7d85892b blueswir1
    ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1291 7d85892b blueswir1
    if (ret < 0 || ret > PROM_SIZE_MAX)
1292 e01f4a1c blueswir1
        ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
1293 7d85892b blueswir1
    if (ret < 0 || ret > PROM_SIZE_MAX) {
1294 7d85892b blueswir1
        fprintf(stderr, "qemu: could not load prom '%s'\n",
1295 7d85892b blueswir1
                buf);
1296 7d85892b blueswir1
        exit(1);
1297 7d85892b blueswir1
    }
1298 7d85892b blueswir1
1299 7d85892b blueswir1
    /* set up devices */
1300 7d85892b blueswir1
    sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs);
1301 7d85892b blueswir1
1302 7d85892b blueswir1
    for (i = 0; i < MAX_IOUNITS; i++)
1303 7d85892b blueswir1
        if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
1304 ff403da6 blueswir1
            iounits[i] = iommu_init(hwdef->iounit_bases[i],
1305 ff403da6 blueswir1
                                    hwdef->iounit_version,
1306 ff403da6 blueswir1
                                    sbi_irq[hwdef->me_irq]);
1307 7d85892b blueswir1
1308 7d85892b blueswir1
    espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[hwdef->esp_irq],
1309 7d85892b blueswir1
                              iounits[0], &espdma_irq, &esp_reset);
1310 7d85892b blueswir1
1311 7d85892b blueswir1
    ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[hwdef->le_irq],
1312 7d85892b blueswir1
                             iounits[0], &ledma_irq, &le_reset);
1313 7d85892b blueswir1
1314 7d85892b blueswir1
    if (graphic_depth != 8 && graphic_depth != 24) {
1315 7d85892b blueswir1
        fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1316 7d85892b blueswir1
        exit (1);
1317 7d85892b blueswir1
    }
1318 5c6602c5 blueswir1
    tcx_offset = qemu_ram_alloc(hwdef->vram_size);
1319 3023f332 aliguori
    tcx_init(hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset,
1320 7d85892b blueswir1
             hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1321 7d85892b blueswir1
1322 0ae18cee aliguori
    lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1323 7d85892b blueswir1
1324 7d85892b blueswir1
    nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
1325 7d85892b blueswir1
                        hwdef->nvram_size, 8);
1326 7d85892b blueswir1
1327 7d85892b blueswir1
    slavio_timer_init_all(hwdef->counter_base, sbi_irq[hwdef->clock1_irq],
1328 7d85892b blueswir1
                          sbi_cpu_irq, smp_cpus);
1329 7d85892b blueswir1
1330 7d85892b blueswir1
    slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq],
1331 b4ed08e0 blueswir1
                              nographic, ESCC_CLOCK, 1);
1332 7d85892b blueswir1
    // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1333 7d85892b blueswir1
    // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1334 aeeb69c7 aurel32
    escc_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq], sbi_irq[hwdef->ser_irq],
1335 aeeb69c7 aurel32
              serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
1336 7d85892b blueswir1
1337 7d85892b blueswir1
    if (drive_get_max_bus(IF_SCSI) > 0) {
1338 7d85892b blueswir1
        fprintf(stderr, "qemu: too many SCSI bus\n");
1339 7d85892b blueswir1
        exit(1);
1340 7d85892b blueswir1
    }
1341 7d85892b blueswir1
1342 5d20fa6b blueswir1
    main_esp = esp_init(hwdef->esp_base, 2,
1343 8b17de88 blueswir1
                        espdma_memory_read, espdma_memory_write,
1344 8b17de88 blueswir1
                        espdma, *espdma_irq, esp_reset);
1345 7d85892b blueswir1
1346 7d85892b blueswir1
    for (i = 0; i < ESP_MAX_DEVS; i++) {
1347 22548760 blueswir1
        drive_index = drive_get_index(IF_SCSI, 0, i);
1348 22548760 blueswir1
        if (drive_index == -1)
1349 7d85892b blueswir1
            continue;
1350 22548760 blueswir1
        esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
1351 7d85892b blueswir1
    }
1352 7d85892b blueswir1
1353 293f78bc blueswir1
    kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1354 293f78bc blueswir1
                                    RAM_size);
1355 7d85892b blueswir1
1356 7d85892b blueswir1
    nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1357 7d85892b blueswir1
               boot_device, RAM_size, kernel_size, graphic_width,
1358 905fdcb5 blueswir1
               graphic_height, graphic_depth, hwdef->nvram_machine_id,
1359 905fdcb5 blueswir1
               "Sun4d");
1360 3cce6243 blueswir1
1361 3cce6243 blueswir1
    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1362 3cce6243 blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1363 905fdcb5 blueswir1
    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1364 905fdcb5 blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1365 7d85892b blueswir1
}
1366 7d85892b blueswir1
1367 7d85892b blueswir1
/* SPARCserver 1000 hardware initialisation */
1368 00f82b8a aurel32
static void ss1000_init(ram_addr_t RAM_size, int vga_ram_size,
1369 3023f332 aliguori
                        const char *boot_device,
1370 7d85892b blueswir1
                        const char *kernel_filename, const char *kernel_cmdline,
1371 7d85892b blueswir1
                        const char *initrd_filename, const char *cpu_model)
1372 7d85892b blueswir1
{
1373 3023f332 aliguori
    sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename,
1374 7d85892b blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1375 7d85892b blueswir1
}
1376 7d85892b blueswir1
1377 7d85892b blueswir1
/* SPARCcenter 2000 hardware initialisation */
1378 00f82b8a aurel32
static void ss2000_init(ram_addr_t RAM_size, int vga_ram_size,
1379 3023f332 aliguori
                        const char *boot_device,
1380 7d85892b blueswir1
                        const char *kernel_filename, const char *kernel_cmdline,
1381 7d85892b blueswir1
                        const char *initrd_filename, const char *cpu_model)
1382 7d85892b blueswir1
{
1383 3023f332 aliguori
    sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename,
1384 7d85892b blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1385 7d85892b blueswir1
}
1386 7d85892b blueswir1
1387 7d85892b blueswir1
QEMUMachine ss1000_machine = {
1388 66de733b blueswir1
    .name = "SS-1000",
1389 66de733b blueswir1
    .desc = "Sun4d platform, SPARCserver 1000",
1390 66de733b blueswir1
    .init = ss1000_init,
1391 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1392 f88e4b91 blueswir1
    .nodisk_ok = 1,
1393 c9b1ae2c blueswir1
    .use_scsi = 1,
1394 1bcee014 blueswir1
    .max_cpus = 8,
1395 7d85892b blueswir1
};
1396 7d85892b blueswir1
1397 7d85892b blueswir1
QEMUMachine ss2000_machine = {
1398 66de733b blueswir1
    .name = "SS-2000",
1399 66de733b blueswir1
    .desc = "Sun4d platform, SPARCcenter 2000",
1400 66de733b blueswir1
    .init = ss2000_init,
1401 66de733b blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1402 f88e4b91 blueswir1
    .nodisk_ok = 1,
1403 c9b1ae2c blueswir1
    .use_scsi = 1,
1404 1bcee014 blueswir1
    .max_cpus = 20,
1405 7d85892b blueswir1
};
1406 8137cde8 blueswir1
1407 8137cde8 blueswir1
static const struct sun4c_hwdef sun4c_hwdefs[] = {
1408 8137cde8 blueswir1
    /* SS-2 */
1409 8137cde8 blueswir1
    {
1410 8137cde8 blueswir1
        .iommu_base   = 0xf8000000,
1411 8137cde8 blueswir1
        .tcx_base     = 0xfe000000,
1412 8137cde8 blueswir1
        .slavio_base  = 0xf6000000,
1413 8137cde8 blueswir1
        .intctl_base  = 0xf5000000,
1414 8137cde8 blueswir1
        .counter_base = 0xf3000000,
1415 8137cde8 blueswir1
        .ms_kb_base   = 0xf0000000,
1416 8137cde8 blueswir1
        .serial_base  = 0xf1000000,
1417 8137cde8 blueswir1
        .nvram_base   = 0xf2000000,
1418 8137cde8 blueswir1
        .fd_base      = 0xf7200000,
1419 8137cde8 blueswir1
        .dma_base     = 0xf8400000,
1420 8137cde8 blueswir1
        .esp_base     = 0xf8800000,
1421 8137cde8 blueswir1
        .le_base      = 0xf8c00000,
1422 8137cde8 blueswir1
        .aux1_base    = 0xf7400003,
1423 8137cde8 blueswir1
        .vram_size    = 0x00100000,
1424 8137cde8 blueswir1
        .nvram_size   = 0x800,
1425 8137cde8 blueswir1
        .esp_irq = 2,
1426 8137cde8 blueswir1
        .le_irq = 3,
1427 8137cde8 blueswir1
        .clock_irq = 5,
1428 8137cde8 blueswir1
        .clock1_irq = 7,
1429 8137cde8 blueswir1
        .ms_kb_irq = 1,
1430 8137cde8 blueswir1
        .ser_irq = 1,
1431 8137cde8 blueswir1
        .fd_irq = 1,
1432 8137cde8 blueswir1
        .me_irq = 1,
1433 8137cde8 blueswir1
        .nvram_machine_id = 0x55,
1434 8137cde8 blueswir1
        .machine_id = ss2_id,
1435 8137cde8 blueswir1
        .max_mem = 0x10000000,
1436 8137cde8 blueswir1
        .default_cpu_model = "Cypress CY7C601",
1437 8137cde8 blueswir1
    },
1438 8137cde8 blueswir1
};
1439 8137cde8 blueswir1
1440 8137cde8 blueswir1
static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1441 8137cde8 blueswir1
                          const char *boot_device,
1442 3023f332 aliguori
                          const char *kernel_filename,
1443 8137cde8 blueswir1
                          const char *kernel_cmdline,
1444 8137cde8 blueswir1
                          const char *initrd_filename, const char *cpu_model)
1445 8137cde8 blueswir1
{
1446 8137cde8 blueswir1
    CPUState *env;
1447 8137cde8 blueswir1
    unsigned int i;
1448 8137cde8 blueswir1
    void *iommu, *espdma, *ledma, *main_esp, *nvram;
1449 8137cde8 blueswir1
    qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq;
1450 8137cde8 blueswir1
    qemu_irq *esp_reset, *le_reset;
1451 8137cde8 blueswir1
    qemu_irq *fdc_tc;
1452 5c6602c5 blueswir1
    ram_addr_t ram_offset, prom_offset, tcx_offset;
1453 5c6602c5 blueswir1
    unsigned long kernel_size;
1454 8137cde8 blueswir1
    int ret;
1455 8137cde8 blueswir1
    char buf[1024];
1456 8137cde8 blueswir1
    BlockDriverState *fd[MAX_FD];
1457 8137cde8 blueswir1
    int drive_index;
1458 8137cde8 blueswir1
    void *fw_cfg;
1459 8137cde8 blueswir1
1460 8137cde8 blueswir1
    /* init CPU */
1461 8137cde8 blueswir1
    if (!cpu_model)
1462 8137cde8 blueswir1
        cpu_model = hwdef->default_cpu_model;
1463 8137cde8 blueswir1
1464 8137cde8 blueswir1
    env = cpu_init(cpu_model);
1465 8137cde8 blueswir1
    if (!env) {
1466 8137cde8 blueswir1
        fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1467 8137cde8 blueswir1
        exit(1);
1468 8137cde8 blueswir1
    }
1469 8137cde8 blueswir1
1470 8137cde8 blueswir1
    cpu_sparc_set_id(env, 0);
1471 8137cde8 blueswir1
1472 8137cde8 blueswir1
    qemu_register_reset(main_cpu_reset, env);
1473 8137cde8 blueswir1
    cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
1474 8137cde8 blueswir1
    env->prom_addr = hwdef->slavio_base;
1475 8137cde8 blueswir1
1476 8137cde8 blueswir1
    /* allocate RAM */
1477 8137cde8 blueswir1
    if ((uint64_t)RAM_size > hwdef->max_mem) {
1478 8137cde8 blueswir1
        fprintf(stderr,
1479 8137cde8 blueswir1
                "qemu: Too much memory for this machine: %d, maximum %d\n",
1480 8137cde8 blueswir1
                (unsigned int)(RAM_size / (1024 * 1024)),
1481 8137cde8 blueswir1
                (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1482 8137cde8 blueswir1
        exit(1);
1483 8137cde8 blueswir1
    }
1484 5c6602c5 blueswir1
    ram_offset = qemu_ram_alloc(RAM_size);
1485 5c6602c5 blueswir1
    cpu_register_physical_memory(0, RAM_size, ram_offset);
1486 8137cde8 blueswir1
1487 8137cde8 blueswir1
    /* load boot prom */
1488 5c6602c5 blueswir1
    prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
1489 8137cde8 blueswir1
    cpu_register_physical_memory(hwdef->slavio_base,
1490 8137cde8 blueswir1
                                 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1491 8137cde8 blueswir1
                                 TARGET_PAGE_MASK,
1492 8137cde8 blueswir1
                                 prom_offset | IO_MEM_ROM);
1493 8137cde8 blueswir1
1494 8137cde8 blueswir1
    if (bios_name == NULL)
1495 8137cde8 blueswir1
        bios_name = PROM_FILENAME;
1496 8137cde8 blueswir1
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1497 8137cde8 blueswir1
    ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1498 8137cde8 blueswir1
    if (ret < 0 || ret > PROM_SIZE_MAX)
1499 8137cde8 blueswir1
        ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
1500 8137cde8 blueswir1
    if (ret < 0 || ret > PROM_SIZE_MAX) {
1501 8137cde8 blueswir1
        fprintf(stderr, "qemu: could not load prom '%s'\n",
1502 8137cde8 blueswir1
                buf);
1503 8137cde8 blueswir1
        exit(1);
1504 8137cde8 blueswir1
    }
1505 8137cde8 blueswir1
1506 8137cde8 blueswir1
    /* set up devices */
1507 8137cde8 blueswir1
    slavio_intctl = sun4c_intctl_init(hwdef->intctl_base,
1508 8137cde8 blueswir1
                                      &slavio_irq, cpu_irqs);
1509 8137cde8 blueswir1
1510 8137cde8 blueswir1
    iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
1511 8137cde8 blueswir1
                       slavio_irq[hwdef->me_irq]);
1512 8137cde8 blueswir1
1513 8137cde8 blueswir1
    espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
1514 8137cde8 blueswir1
                              iommu, &espdma_irq, &esp_reset);
1515 8137cde8 blueswir1
1516 8137cde8 blueswir1
    ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
1517 8137cde8 blueswir1
                             slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
1518 8137cde8 blueswir1
                             &le_reset);
1519 8137cde8 blueswir1
1520 8137cde8 blueswir1
    if (graphic_depth != 8 && graphic_depth != 24) {
1521 8137cde8 blueswir1
        fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1522 8137cde8 blueswir1
        exit (1);
1523 8137cde8 blueswir1
    }
1524 5c6602c5 blueswir1
    tcx_offset = qemu_ram_alloc(hwdef->vram_size);
1525 3023f332 aliguori
    tcx_init(hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset,
1526 8137cde8 blueswir1
             hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1527 8137cde8 blueswir1
1528 0ae18cee aliguori
    lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1529 8137cde8 blueswir1
1530 8137cde8 blueswir1
    nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
1531 8137cde8 blueswir1
                        hwdef->nvram_size, 2);
1532 8137cde8 blueswir1
1533 8137cde8 blueswir1
    slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
1534 b4ed08e0 blueswir1
                              nographic, ESCC_CLOCK, 1);
1535 8137cde8 blueswir1
    // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1536 8137cde8 blueswir1
    // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1537 aeeb69c7 aurel32
    escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
1538 aeeb69c7 aurel32
              slavio_irq[hwdef->ser_irq], serial_hds[0], serial_hds[1],
1539 aeeb69c7 aurel32
              ESCC_CLOCK, 1);
1540 8137cde8 blueswir1
1541 fe096129 blueswir1
    slavio_misc = slavio_misc_init(0, 0, hwdef->aux1_base, 0,
1542 6d0c293d blueswir1
                                   slavio_irq[hwdef->me_irq], NULL, &fdc_tc);
1543 8137cde8 blueswir1
1544 8137cde8 blueswir1
    if (hwdef->fd_base != (target_phys_addr_t)-1) {
1545 8137cde8 blueswir1
        /* there is zero or one floppy drive */
1546 ce802585 blueswir1
        memset(fd, 0, sizeof(fd));
1547 8137cde8 blueswir1
        drive_index = drive_get_index(IF_FLOPPY, 0, 0);
1548 8137cde8 blueswir1
        if (drive_index != -1)
1549 8137cde8 blueswir1
            fd[0] = drives_table[drive_index].bdrv;
1550 8137cde8 blueswir1
1551 8137cde8 blueswir1
        sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
1552 8137cde8 blueswir1
                          fdc_tc);
1553 8137cde8 blueswir1
    }
1554 8137cde8 blueswir1
1555 8137cde8 blueswir1
    if (drive_get_max_bus(IF_SCSI) > 0) {
1556 8137cde8 blueswir1
        fprintf(stderr, "qemu: too many SCSI bus\n");
1557 8137cde8 blueswir1
        exit(1);
1558 8137cde8 blueswir1
    }
1559 8137cde8 blueswir1
1560 8137cde8 blueswir1
    main_esp = esp_init(hwdef->esp_base, 2,
1561 8137cde8 blueswir1
                        espdma_memory_read, espdma_memory_write,
1562 8137cde8 blueswir1
                        espdma, *espdma_irq, esp_reset);
1563 8137cde8 blueswir1
1564 8137cde8 blueswir1
    for (i = 0; i < ESP_MAX_DEVS; i++) {
1565 8137cde8 blueswir1
        drive_index = drive_get_index(IF_SCSI, 0, i);
1566 8137cde8 blueswir1
        if (drive_index == -1)
1567 8137cde8 blueswir1
            continue;
1568 8137cde8 blueswir1
        esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
1569 8137cde8 blueswir1
    }
1570 8137cde8 blueswir1
1571 8137cde8 blueswir1
    kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1572 8137cde8 blueswir1
                                    RAM_size);
1573 8137cde8 blueswir1
1574 8137cde8 blueswir1
    nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1575 8137cde8 blueswir1
               boot_device, RAM_size, kernel_size, graphic_width,
1576 8137cde8 blueswir1
               graphic_height, graphic_depth, hwdef->nvram_machine_id,
1577 8137cde8 blueswir1
               "Sun4c");
1578 8137cde8 blueswir1
1579 8137cde8 blueswir1
    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1580 8137cde8 blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1581 8137cde8 blueswir1
    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1582 8137cde8 blueswir1
    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1583 8137cde8 blueswir1
}
1584 8137cde8 blueswir1
1585 8137cde8 blueswir1
/* SPARCstation 2 hardware initialisation */
1586 8137cde8 blueswir1
static void ss2_init(ram_addr_t RAM_size, int vga_ram_size,
1587 3023f332 aliguori
                     const char *boot_device,
1588 8137cde8 blueswir1
                     const char *kernel_filename, const char *kernel_cmdline,
1589 8137cde8 blueswir1
                     const char *initrd_filename, const char *cpu_model)
1590 8137cde8 blueswir1
{
1591 3023f332 aliguori
    sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename,
1592 8137cde8 blueswir1
                  kernel_cmdline, initrd_filename, cpu_model);
1593 8137cde8 blueswir1
}
1594 8137cde8 blueswir1
1595 8137cde8 blueswir1
QEMUMachine ss2_machine = {
1596 8137cde8 blueswir1
    .name = "SS-2",
1597 8137cde8 blueswir1
    .desc = "Sun4c platform, SPARCstation 2",
1598 8137cde8 blueswir1
    .init = ss2_init,
1599 8137cde8 blueswir1
    .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1600 8137cde8 blueswir1
    .nodisk_ok = 1,
1601 8137cde8 blueswir1
    .use_scsi = 1,
1602 8137cde8 blueswir1
};