xref: /openbmc/qemu/hw/sh4/r2d.c (revision 6cb943c361451991fd151ef0335969785ab847f3)
153018216SPaolo Bonzini /*
253018216SPaolo Bonzini  * Renesas SH7751R R2D-PLUS emulation
353018216SPaolo Bonzini  *
453018216SPaolo Bonzini  * Copyright (c) 2007 Magnus Damm
553018216SPaolo Bonzini  * Copyright (c) 2008 Paul Mundt
653018216SPaolo Bonzini  *
753018216SPaolo Bonzini  * Permission is hereby granted, free of charge, to any person obtaining a copy
853018216SPaolo Bonzini  * of this software and associated documentation files (the "Software"), to deal
953018216SPaolo Bonzini  * in the Software without restriction, including without limitation the rights
1053018216SPaolo Bonzini  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1153018216SPaolo Bonzini  * copies of the Software, and to permit persons to whom the Software is
1253018216SPaolo Bonzini  * furnished to do so, subject to the following conditions:
1353018216SPaolo Bonzini  *
1453018216SPaolo Bonzini  * The above copyright notice and this permission notice shall be included in
1553018216SPaolo Bonzini  * all copies or substantial portions of the Software.
1653018216SPaolo Bonzini  *
1753018216SPaolo Bonzini  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1853018216SPaolo Bonzini  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1953018216SPaolo Bonzini  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2053018216SPaolo Bonzini  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2153018216SPaolo Bonzini  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2253018216SPaolo Bonzini  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2353018216SPaolo Bonzini  * THE SOFTWARE.
2453018216SPaolo Bonzini  */
2553018216SPaolo Bonzini 
269d4c9946SPeter Maydell #include "qemu/osdep.h"
27e7dd191cSPhilippe Mathieu-Daudé #include "qemu/units.h"
28da34e65cSMarkus Armbruster #include "qapi/error.h"
296e5dd76fSBALATON Zoltan #include "qemu/error-report.h"
304771d756SPaolo Bonzini #include "cpu.h"
3153018216SPaolo Bonzini #include "hw/sysbus.h"
320d09e41aSPaolo Bonzini #include "hw/sh4/sh.h"
3371e8a915SMarkus Armbruster #include "sysemu/reset.h"
3454d31236SMarkus Armbruster #include "sysemu/runstate.h"
3553018216SPaolo Bonzini #include "sysemu/sysemu.h"
3653018216SPaolo Bonzini #include "hw/boards.h"
3753018216SPaolo Bonzini #include "hw/pci/pci.h"
38a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
3953018216SPaolo Bonzini #include "net/net.h"
4047b43a1fSPaolo Bonzini #include "sh7750_regs.h"
4101c43405SPhilippe Mathieu-Daudé #include "hw/ide/mmio.h"
4264552b6bSMarkus Armbruster #include "hw/irq.h"
4353018216SPaolo Bonzini #include "hw/loader.h"
4453018216SPaolo Bonzini #include "hw/usb.h"
450d09e41aSPaolo Bonzini #include "hw/block/flash.h"
4653018216SPaolo Bonzini 
4753018216SPaolo Bonzini #define FLASH_BASE 0x00000000
4884687134SMarkus Armbruster #define FLASH_SIZE (16 * MiB)
4953018216SPaolo Bonzini 
5053018216SPaolo Bonzini #define SDRAM_BASE 0x0c000000 /* Physical location of SDRAM: Area 3 */
5153018216SPaolo Bonzini #define SDRAM_SIZE 0x04000000
5253018216SPaolo Bonzini 
5353018216SPaolo Bonzini #define SM501_VRAM_SIZE 0x800000
5453018216SPaolo Bonzini 
5553018216SPaolo Bonzini #define BOOT_PARAMS_OFFSET 0x0010000
5653018216SPaolo Bonzini /* CONFIG_BOOT_LINK_OFFSET of Linux kernel */
5753018216SPaolo Bonzini #define LINUX_LOAD_OFFSET  0x0800000
5853018216SPaolo Bonzini #define INITRD_LOAD_OFFSET 0x1800000
5953018216SPaolo Bonzini 
6053018216SPaolo Bonzini #define PA_IRLMSK 0x00
6153018216SPaolo Bonzini #define PA_POWOFF 0x30
6253018216SPaolo Bonzini #define PA_VERREG 0x32
6353018216SPaolo Bonzini #define PA_OUTPORT 0x36
6453018216SPaolo Bonzini 
6553018216SPaolo Bonzini typedef struct {
6653018216SPaolo Bonzini     uint16_t bcr;
6753018216SPaolo Bonzini     uint16_t irlmsk;
6853018216SPaolo Bonzini     uint16_t irlmon;
6953018216SPaolo Bonzini     uint16_t cfctl;
7053018216SPaolo Bonzini     uint16_t cfpow;
7153018216SPaolo Bonzini     uint16_t dispctl;
7253018216SPaolo Bonzini     uint16_t sdmpow;
7353018216SPaolo Bonzini     uint16_t rtcce;
7453018216SPaolo Bonzini     uint16_t pcicd;
7553018216SPaolo Bonzini     uint16_t voyagerrts;
7653018216SPaolo Bonzini     uint16_t cfrst;
7753018216SPaolo Bonzini     uint16_t admrts;
7853018216SPaolo Bonzini     uint16_t extrst;
7953018216SPaolo Bonzini     uint16_t cfcdintclr;
8053018216SPaolo Bonzini     uint16_t keyctlclr;
8153018216SPaolo Bonzini     uint16_t pad0;
8253018216SPaolo Bonzini     uint16_t pad1;
8353018216SPaolo Bonzini     uint16_t verreg;
8453018216SPaolo Bonzini     uint16_t inport;
8553018216SPaolo Bonzini     uint16_t outport;
8653018216SPaolo Bonzini     uint16_t bverreg;
8753018216SPaolo Bonzini 
8853018216SPaolo Bonzini /* output pin */
8953018216SPaolo Bonzini     qemu_irq irl;
9053018216SPaolo Bonzini     MemoryRegion iomem;
9153018216SPaolo Bonzini } r2d_fpga_t;
9253018216SPaolo Bonzini 
9353018216SPaolo Bonzini enum r2d_fpga_irq {
9453018216SPaolo Bonzini     PCI_INTD, CF_IDE, CF_CD, PCI_INTC, SM501, KEY, RTC_A, RTC_T,
9553018216SPaolo Bonzini     SDCARD, PCI_INTA, PCI_INTB, EXT, TP,
9653018216SPaolo Bonzini     NR_IRQS
9753018216SPaolo Bonzini };
9853018216SPaolo Bonzini 
9953018216SPaolo Bonzini static const struct { short irl; uint16_t msk; } irqtab[NR_IRQS] = {
10053018216SPaolo Bonzini     [CF_IDE] =   {  1, 1 << 9 },
10153018216SPaolo Bonzini     [CF_CD] =    {  2, 1 << 8 },
10253018216SPaolo Bonzini     [PCI_INTA] = {  9, 1 << 14 },
10353018216SPaolo Bonzini     [PCI_INTB] = { 10, 1 << 13 },
10453018216SPaolo Bonzini     [PCI_INTC] = {  3, 1 << 12 },
10553018216SPaolo Bonzini     [PCI_INTD] = {  0, 1 << 11 },
10653018216SPaolo Bonzini     [SM501] =    {  4, 1 << 10 },
10753018216SPaolo Bonzini     [KEY] =      {  5, 1 << 6 },
10853018216SPaolo Bonzini     [RTC_A] =    {  6, 1 << 5 },
10953018216SPaolo Bonzini     [RTC_T] =    {  7, 1 << 4 },
11053018216SPaolo Bonzini     [SDCARD] =   {  8, 1 << 7 },
11153018216SPaolo Bonzini     [EXT] =      { 11, 1 << 0 },
11253018216SPaolo Bonzini     [TP] =       { 12, 1 << 15 },
11353018216SPaolo Bonzini };
11453018216SPaolo Bonzini 
update_irl(r2d_fpga_t * fpga)11553018216SPaolo Bonzini static void update_irl(r2d_fpga_t *fpga)
11653018216SPaolo Bonzini {
11753018216SPaolo Bonzini     int i, irl = 15;
118ac3c9e74SBALATON Zoltan     for (i = 0; i < NR_IRQS; i++) {
119ac3c9e74SBALATON Zoltan         if ((fpga->irlmon & fpga->irlmsk & irqtab[i].msk) &&
120ac3c9e74SBALATON Zoltan             irqtab[i].irl < irl) {
12153018216SPaolo Bonzini             irl = irqtab[i].irl;
122ac3c9e74SBALATON Zoltan         }
123ac3c9e74SBALATON Zoltan     }
12453018216SPaolo Bonzini     qemu_set_irq(fpga->irl, irl ^ 15);
12553018216SPaolo Bonzini }
12653018216SPaolo Bonzini 
r2d_fpga_irq_set(void * opaque,int n,int level)12753018216SPaolo Bonzini static void r2d_fpga_irq_set(void *opaque, int n, int level)
12853018216SPaolo Bonzini {
12953018216SPaolo Bonzini     r2d_fpga_t *fpga = opaque;
130ac3c9e74SBALATON Zoltan     if (level) {
13153018216SPaolo Bonzini         fpga->irlmon |= irqtab[n].msk;
132ac3c9e74SBALATON Zoltan     } else {
13353018216SPaolo Bonzini         fpga->irlmon &= ~irqtab[n].msk;
134ac3c9e74SBALATON Zoltan     }
13553018216SPaolo Bonzini     update_irl(fpga);
13653018216SPaolo Bonzini }
13753018216SPaolo Bonzini 
r2d_fpga_read(void * opaque,hwaddr addr,unsigned int size)13856380752SAurelien Jarno static uint64_t r2d_fpga_read(void *opaque, hwaddr addr, unsigned int size)
13953018216SPaolo Bonzini {
14053018216SPaolo Bonzini     r2d_fpga_t *s = opaque;
14153018216SPaolo Bonzini 
14253018216SPaolo Bonzini     switch (addr) {
14353018216SPaolo Bonzini     case PA_IRLMSK:
14453018216SPaolo Bonzini         return s->irlmsk;
14553018216SPaolo Bonzini     case PA_OUTPORT:
14653018216SPaolo Bonzini         return s->outport;
14753018216SPaolo Bonzini     case PA_POWOFF:
14853018216SPaolo Bonzini         return 0x00;
14953018216SPaolo Bonzini     case PA_VERREG:
15053018216SPaolo Bonzini         return 0x10;
15153018216SPaolo Bonzini     }
15253018216SPaolo Bonzini 
15353018216SPaolo Bonzini     return 0;
15453018216SPaolo Bonzini }
15553018216SPaolo Bonzini 
15653018216SPaolo Bonzini static void
r2d_fpga_write(void * opaque,hwaddr addr,uint64_t value,unsigned int size)15756380752SAurelien Jarno r2d_fpga_write(void *opaque, hwaddr addr, uint64_t value, unsigned int size)
15853018216SPaolo Bonzini {
15953018216SPaolo Bonzini     r2d_fpga_t *s = opaque;
16053018216SPaolo Bonzini 
16153018216SPaolo Bonzini     switch (addr) {
16253018216SPaolo Bonzini     case PA_IRLMSK:
16353018216SPaolo Bonzini         s->irlmsk = value;
16453018216SPaolo Bonzini         update_irl(s);
16553018216SPaolo Bonzini         break;
16653018216SPaolo Bonzini     case PA_OUTPORT:
16753018216SPaolo Bonzini         s->outport = value;
16853018216SPaolo Bonzini         break;
16953018216SPaolo Bonzini     case PA_POWOFF:
17053018216SPaolo Bonzini         if (value & 1) {
171cf83f140SEric Blake             qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
17253018216SPaolo Bonzini         }
17353018216SPaolo Bonzini         break;
17453018216SPaolo Bonzini     case PA_VERREG:
17553018216SPaolo Bonzini         /* Discard writes */
17653018216SPaolo Bonzini         break;
17753018216SPaolo Bonzini     }
17853018216SPaolo Bonzini }
17953018216SPaolo Bonzini 
18053018216SPaolo Bonzini static const MemoryRegionOps r2d_fpga_ops = {
18156380752SAurelien Jarno     .read = r2d_fpga_read,
18256380752SAurelien Jarno     .write = r2d_fpga_write,
18356380752SAurelien Jarno     .impl.min_access_size = 2,
18456380752SAurelien Jarno     .impl.max_access_size = 2,
18553018216SPaolo Bonzini     .endianness = DEVICE_NATIVE_ENDIAN,
18653018216SPaolo Bonzini };
18753018216SPaolo Bonzini 
r2d_fpga_init(MemoryRegion * sysmem,hwaddr base,qemu_irq irl)18853018216SPaolo Bonzini static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem,
18953018216SPaolo Bonzini                                hwaddr base, qemu_irq irl)
19053018216SPaolo Bonzini {
19153018216SPaolo Bonzini     r2d_fpga_t *s;
19253018216SPaolo Bonzini 
193b21e2380SMarkus Armbruster     s = g_new0(r2d_fpga_t, 1);
19453018216SPaolo Bonzini 
19553018216SPaolo Bonzini     s->irl = irl;
19653018216SPaolo Bonzini 
1972c9b15caSPaolo Bonzini     memory_region_init_io(&s->iomem, NULL, &r2d_fpga_ops, s, "r2d-fpga", 0x40);
19853018216SPaolo Bonzini     memory_region_add_subregion(sysmem, base, &s->iomem);
19953018216SPaolo Bonzini     return qemu_allocate_irqs(r2d_fpga_irq_set, s, NR_IRQS);
20053018216SPaolo Bonzini }
20153018216SPaolo Bonzini 
20253018216SPaolo Bonzini typedef struct ResetData {
20353018216SPaolo Bonzini     SuperHCPU *cpu;
20453018216SPaolo Bonzini     uint32_t vector;
20553018216SPaolo Bonzini } ResetData;
20653018216SPaolo Bonzini 
main_cpu_reset(void * opaque)20753018216SPaolo Bonzini static void main_cpu_reset(void *opaque)
20853018216SPaolo Bonzini {
20953018216SPaolo Bonzini     ResetData *s = (ResetData *)opaque;
21053018216SPaolo Bonzini     CPUSH4State *env = &s->cpu->env;
21153018216SPaolo Bonzini 
21253018216SPaolo Bonzini     cpu_reset(CPU(s->cpu));
21353018216SPaolo Bonzini     env->pc = s->vector;
21453018216SPaolo Bonzini }
21553018216SPaolo Bonzini 
21653018216SPaolo Bonzini static struct QEMU_PACKED
21753018216SPaolo Bonzini {
21853018216SPaolo Bonzini     int mount_root_rdonly;
21953018216SPaolo Bonzini     int ramdisk_flags;
22053018216SPaolo Bonzini     int orig_root_dev;
22153018216SPaolo Bonzini     int loader_type;
22253018216SPaolo Bonzini     int initrd_start;
22353018216SPaolo Bonzini     int initrd_size;
22453018216SPaolo Bonzini 
22553018216SPaolo Bonzini     char pad[232];
22653018216SPaolo Bonzini 
2277de7b608SMichael S. Tsirkin     char kernel_cmdline[256] QEMU_NONSTRING;
22853018216SPaolo Bonzini } boot_params;
22953018216SPaolo Bonzini 
r2d_init(MachineState * machine)2303ef96221SMarcel Apfelbaum static void r2d_init(MachineState *machine)
23153018216SPaolo Bonzini {
2323ef96221SMarcel Apfelbaum     const char *kernel_filename = machine->kernel_filename;
2333ef96221SMarcel Apfelbaum     const char *kernel_cmdline = machine->kernel_cmdline;
2343ef96221SMarcel Apfelbaum     const char *initrd_filename = machine->initrd_filename;
235cf2528a5SThomas Huth     MachineClass *mc = MACHINE_GET_CLASS(machine);
23653018216SPaolo Bonzini     SuperHCPU *cpu;
23753018216SPaolo Bonzini     CPUSH4State *env;
23853018216SPaolo Bonzini     ResetData *reset_info;
23953018216SPaolo Bonzini     struct SH7750State *s;
24053018216SPaolo Bonzini     MemoryRegion *sdram = g_new(MemoryRegion, 1);
24153018216SPaolo Bonzini     qemu_irq *irq;
24253018216SPaolo Bonzini     DriveInfo *dinfo;
24353018216SPaolo Bonzini     DeviceState *dev;
24453018216SPaolo Bonzini     SysBusDevice *busdev;
24553018216SPaolo Bonzini     MemoryRegion *address_space_mem = get_system_memory();
24629b358f9SDavid Gibson     PCIBus *pci_bus;
2471b31b677SPaolo Bonzini     USBBus *usb_bus;
24853018216SPaolo Bonzini 
24978f60b82SIgor Mammedov     cpu = SUPERH_CPU(cpu_create(machine->cpu_type));
25053018216SPaolo Bonzini     env = &cpu->env;
25153018216SPaolo Bonzini 
252b21e2380SMarkus Armbruster     reset_info = g_new0(ResetData, 1);
25353018216SPaolo Bonzini     reset_info->cpu = cpu;
25453018216SPaolo Bonzini     reset_info->vector = env->pc;
25553018216SPaolo Bonzini     qemu_register_reset(main_cpu_reset, reset_info);
25653018216SPaolo Bonzini 
25753018216SPaolo Bonzini     /* Allocate memory space */
25898a99ce0SPeter Maydell     memory_region_init_ram(sdram, NULL, "r2d.sdram", SDRAM_SIZE, &error_fatal);
25953018216SPaolo Bonzini     memory_region_add_subregion(address_space_mem, SDRAM_BASE, sdram);
26053018216SPaolo Bonzini     /* Register peripherals */
2612f493feeSAndreas Färber     s = sh7750_init(cpu, address_space_mem);
26253018216SPaolo Bonzini     irq = r2d_fpga_init(address_space_mem, 0x04000000, sh7750_irl(s));
26353018216SPaolo Bonzini 
2643e80f690SMarkus Armbruster     dev = qdev_new("sh_pci");
26553018216SPaolo Bonzini     busdev = SYS_BUS_DEVICE(dev);
2663c6ef471SMarkus Armbruster     sysbus_realize_and_unref(busdev, &error_fatal);
26729b358f9SDavid Gibson     pci_bus = PCI_BUS(qdev_get_child_bus(dev, "pci"));
26853018216SPaolo Bonzini     sysbus_mmio_map(busdev, 0, P4ADDR(0x1e200000));
26953018216SPaolo Bonzini     sysbus_mmio_map(busdev, 1, A7ADDR(0x1e200000));
27053018216SPaolo Bonzini     sysbus_connect_irq(busdev, 0, irq[PCI_INTA]);
27153018216SPaolo Bonzini     sysbus_connect_irq(busdev, 1, irq[PCI_INTB]);
27253018216SPaolo Bonzini     sysbus_connect_irq(busdev, 2, irq[PCI_INTC]);
27353018216SPaolo Bonzini     sysbus_connect_irq(busdev, 3, irq[PCI_INTD]);
27453018216SPaolo Bonzini 
2753e80f690SMarkus Armbruster     dev = qdev_new("sysbus-sm501");
276ca8a1104SBALATON Zoltan     busdev = SYS_BUS_DEVICE(dev);
277ca8a1104SBALATON Zoltan     qdev_prop_set_uint32(dev, "vram-size", SM501_VRAM_SIZE);
2786a015046SPhilippe Mathieu-Daudé     qdev_prop_set_uint64(dev, "dma-offset", 0x10000000);
2790ed40f16SMarc-André Lureau     qdev_prop_set_chr(dev, "chardev", serial_hd(2));
2803c6ef471SMarkus Armbruster     sysbus_realize_and_unref(busdev, &error_fatal);
281ca8a1104SBALATON Zoltan     sysbus_mmio_map(busdev, 0, 0x10000000);
282ca8a1104SBALATON Zoltan     sysbus_mmio_map(busdev, 1, 0x13e00000);
283ca8a1104SBALATON Zoltan     sysbus_connect_irq(busdev, 0, irq[SM501]);
28453018216SPaolo Bonzini 
28553018216SPaolo Bonzini     /* onboard CF (True IDE mode, Master only). */
28653018216SPaolo Bonzini     dinfo = drive_get(IF_IDE, 0, 0);
2873e80f690SMarkus Armbruster     dev = qdev_new("mmio-ide");
28853018216SPaolo Bonzini     busdev = SYS_BUS_DEVICE(dev);
289*6cb943c3SThomas Huth     sysbus_connect_irq(busdev, 0, irq[CF_IDE]);
29053018216SPaolo Bonzini     qdev_prop_set_uint32(dev, "shift", 1);
2913c6ef471SMarkus Armbruster     sysbus_realize_and_unref(busdev, &error_fatal);
29253018216SPaolo Bonzini     sysbus_mmio_map(busdev, 0, 0x14001000);
29353018216SPaolo Bonzini     sysbus_mmio_map(busdev, 1, 0x1400080c);
29453018216SPaolo Bonzini     mmio_ide_init_drives(dev, dinfo, NULL);
29553018216SPaolo Bonzini 
29684687134SMarkus Armbruster     /*
29784687134SMarkus Armbruster      * Onboard flash memory
29884687134SMarkus Armbruster      * According to the old board user document in Japanese (under
29984687134SMarkus Armbruster      * NDA) what is referred to as FROM (Area0) is connected via a
30084687134SMarkus Armbruster      * 32-bit bus and CS0 to CN8. The docs mention a Cypress
30184687134SMarkus Armbruster      * S29PL127J60TFI130 chipsset.  Per the 'S29PL-J 002-00615
30284687134SMarkus Armbruster      * Rev. *E' datasheet, it is a 128Mbit NOR parallel flash
30384687134SMarkus Armbruster      * addressable in words of 16bit.
30484687134SMarkus Armbruster      */
30553018216SPaolo Bonzini     dinfo = drive_get(IF_PFLASH, 0, 0);
306940d5b13SMarkus Armbruster     pflash_cfi02_register(0x0, "r2d.flash", FLASH_SIZE,
3074be74634SMarkus Armbruster                           dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
308ce14710fSMarkus Armbruster                           64 * KiB, 1, 2, 0x0001, 0x227e, 0x2220, 0x2200,
30953018216SPaolo Bonzini                           0x555, 0x2aa, 0);
31053018216SPaolo Bonzini 
31153018216SPaolo Bonzini     /* NIC: rtl8139 on-board, and 2 slots. */
3122d89ae0cSDavid Woodhouse     pci_init_nic_in_slot(pci_bus, mc->default_nic, NULL, "2");
3132d89ae0cSDavid Woodhouse     pci_init_nic_devices(pci_bus, mc->default_nic);
31453018216SPaolo Bonzini 
31553018216SPaolo Bonzini     /* USB keyboard */
3161b31b677SPaolo Bonzini     usb_bus = USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS,
3171b31b677SPaolo Bonzini                                                       &error_abort));
3181b31b677SPaolo Bonzini     usb_create_simple(usb_bus, "usb-kbd");
31953018216SPaolo Bonzini 
32053018216SPaolo Bonzini     /* Todo: register on board registers */
32153018216SPaolo Bonzini     memset(&boot_params, 0, sizeof(boot_params));
32253018216SPaolo Bonzini 
32353018216SPaolo Bonzini     if (kernel_filename) {
32453018216SPaolo Bonzini         int kernel_size;
32553018216SPaolo Bonzini 
32653018216SPaolo Bonzini         kernel_size = load_image_targphys(kernel_filename,
32753018216SPaolo Bonzini                                           SDRAM_BASE + LINUX_LOAD_OFFSET,
32853018216SPaolo Bonzini                                           INITRD_LOAD_OFFSET - LINUX_LOAD_OFFSET);
32953018216SPaolo Bonzini         if (kernel_size < 0) {
3306e5dd76fSBALATON Zoltan             error_report("qemu: could not load kernel '%s'", kernel_filename);
33153018216SPaolo Bonzini             exit(1);
33253018216SPaolo Bonzini         }
33353018216SPaolo Bonzini 
33453018216SPaolo Bonzini         /* initialization which should be done by firmware */
33542874d3aSPeter Maydell         address_space_stl(&address_space_memory, SH7750_BCR1, 1 << 3,
33642874d3aSPeter Maydell                           MEMTXATTRS_UNSPECIFIED, NULL); /* cs3 SDRAM */
33742874d3aSPeter Maydell         address_space_stw(&address_space_memory, SH7750_BCR2, 3 << (3 * 2),
33842874d3aSPeter Maydell                           MEMTXATTRS_UNSPECIFIED, NULL); /* cs3 32bit */
339f94bff13SBALATON Zoltan         /* Start from P2 area */
340f94bff13SBALATON Zoltan         reset_info->vector = (SDRAM_BASE + LINUX_LOAD_OFFSET) | 0xa0000000;
34153018216SPaolo Bonzini     }
34253018216SPaolo Bonzini 
34353018216SPaolo Bonzini     if (initrd_filename) {
34453018216SPaolo Bonzini         int initrd_size;
34553018216SPaolo Bonzini 
34653018216SPaolo Bonzini         initrd_size = load_image_targphys(initrd_filename,
34753018216SPaolo Bonzini                                           SDRAM_BASE + INITRD_LOAD_OFFSET,
34853018216SPaolo Bonzini                                           SDRAM_SIZE - INITRD_LOAD_OFFSET);
34953018216SPaolo Bonzini 
35053018216SPaolo Bonzini         if (initrd_size < 0) {
3516e5dd76fSBALATON Zoltan             error_report("qemu: could not load initrd '%s'", initrd_filename);
35253018216SPaolo Bonzini             exit(1);
35353018216SPaolo Bonzini         }
35453018216SPaolo Bonzini 
35553018216SPaolo Bonzini         /* initialization which should be done by firmware */
356cdd14a8cSGuenter Roeck         boot_params.loader_type = tswap32(1);
357cdd14a8cSGuenter Roeck         boot_params.initrd_start = tswap32(INITRD_LOAD_OFFSET);
358cdd14a8cSGuenter Roeck         boot_params.initrd_size = tswap32(initrd_size);
35953018216SPaolo Bonzini     }
36053018216SPaolo Bonzini 
36153018216SPaolo Bonzini     if (kernel_cmdline) {
36222138965SBALATON Zoltan         /*
36322138965SBALATON Zoltan          * I see no evidence that this .kernel_cmdline buffer requires
36422138965SBALATON Zoltan          * NUL-termination, so using strncpy should be ok.
36522138965SBALATON Zoltan          */
36653018216SPaolo Bonzini         strncpy(boot_params.kernel_cmdline, kernel_cmdline,
36753018216SPaolo Bonzini                 sizeof(boot_params.kernel_cmdline));
36853018216SPaolo Bonzini     }
36953018216SPaolo Bonzini 
37053018216SPaolo Bonzini     rom_add_blob_fixed("boot_params", &boot_params, sizeof(boot_params),
37153018216SPaolo Bonzini                        SDRAM_BASE + BOOT_PARAMS_OFFSET);
37253018216SPaolo Bonzini }
37353018216SPaolo Bonzini 
r2d_machine_init(MachineClass * mc)374e264d29dSEduardo Habkost static void r2d_machine_init(MachineClass *mc)
37553018216SPaolo Bonzini {
376e264d29dSEduardo Habkost     mc->desc = "r2d-plus board";
377e264d29dSEduardo Habkost     mc->init = r2d_init;
3782059839bSMarkus Armbruster     mc->block_default_type = IF_IDE;
37978f60b82SIgor Mammedov     mc->default_cpu_type = TYPE_SH7751R_CPU;
380cf2528a5SThomas Huth     mc->default_nic = "rtl8139";
38153018216SPaolo Bonzini }
38253018216SPaolo Bonzini 
383e264d29dSEduardo Habkost DEFINE_MACHINE("r2d", r2d_machine_init)
384