]> git.proxmox.com Git - mirror_qemu.git/blame - hw/arm/xlnx-ep108.c
sdhci_sysbus: Create SD card device in users, not the device itself
[mirror_qemu.git] / hw / arm / xlnx-ep108.c
CommitLineData
859a0c5b
PC
1/*
2 * Xilinx ZynqMP EP108 board
3 *
4 * Copyright (C) 2015 Xilinx Inc
5 * Written by Peter Crosthwaite <peter.crosthwaite@xilinx.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
12b16722 18#include "qemu/osdep.h"
859a0c5b
PC
19#include "hw/arm/xlnx-zynqmp.h"
20#include "hw/boards.h"
21#include "qemu/error-report.h"
b79b9d28 22#include "exec/address-spaces.h"
859a0c5b
PC
23
24typedef struct XlnxEP108 {
25 XlnxZynqMPState soc;
b79b9d28 26 MemoryRegion ddr_ram;
859a0c5b
PC
27} XlnxEP108;
28
082587b7
PC
29static struct arm_boot_info xlnx_ep108_binfo;
30
859a0c5b
PC
31static void xlnx_ep108_init(MachineState *machine)
32{
33 XlnxEP108 *s = g_new0(XlnxEP108, 1);
a4b26335 34 int i;
dc3b89ef
AF
35 uint64_t ram_size = machine->ram_size;
36
37 /* Create the memory region to pass to the SoC */
38 if (ram_size > XLNX_ZYNQMP_MAX_RAM_SIZE) {
39 error_report("ERROR: RAM size 0x%" PRIx64 " above max supported of "
40 "0x%llx", ram_size,
41 XLNX_ZYNQMP_MAX_RAM_SIZE);
42 exit(1);
43 }
44
45 if (ram_size < 0x08000000) {
46 qemu_log("WARNING: RAM size 0x%" PRIx64 " is small for EP108",
47 ram_size);
48 }
49
50 memory_region_allocate_system_memory(&s->ddr_ram, NULL, "ddr-ram",
51 ram_size);
859a0c5b
PC
52
53 object_initialize(&s->soc, sizeof(s->soc), TYPE_XLNX_ZYNQMP);
54 object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc),
55 &error_abort);
56
dc3b89ef
AF
57 object_property_set_link(OBJECT(&s->soc), OBJECT(&s->ddr_ram),
58 "ddr-ram", &error_abort);
59
07d04a02 60 object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_fatal);
b79b9d28 61
eb4f566b
PM
62 /* Create and plug in the SD cards */
63 for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
64 BusState *bus;
65 DriveInfo *di = drive_get_next(IF_SD);
66 BlockBackend *blk = di ? blk_by_legacy_dinfo(di) : NULL;
67 DeviceState *carddev;
68 char *bus_name;
69
70 bus_name = g_strdup_printf("sd-bus%d", i);
71 bus = qdev_get_child_bus(DEVICE(&s->soc), bus_name);
72 g_free(bus_name);
73 if (!bus) {
74 error_report("No SD bus found for SD card %d", i);
75 exit(1);
76 }
77 carddev = qdev_create(bus, TYPE_SD_CARD);
78 qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
79 object_property_set_bool(OBJECT(carddev), true, "realized",
80 &error_fatal);
81 }
82
a4b26335
AF
83 for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) {
84 SSIBus *spi_bus;
85 DeviceState *flash_dev;
86 qemu_irq cs_line;
87 gchar *bus_name = g_strdup_printf("spi%d", i);
88
89 spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(&s->soc), bus_name);
90 g_free(bus_name);
91
92 flash_dev = ssi_create_slave(spi_bus, "sst25wf080");
93 cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
94
95 sysbus_connect_irq(SYS_BUS_DEVICE(&s->soc.spi[i]), 1, cs_line);
96 }
97
dc3b89ef 98 xlnx_ep108_binfo.ram_size = ram_size;
082587b7
PC
99 xlnx_ep108_binfo.kernel_filename = machine->kernel_filename;
100 xlnx_ep108_binfo.kernel_cmdline = machine->kernel_cmdline;
101 xlnx_ep108_binfo.initrd_filename = machine->initrd_filename;
102 xlnx_ep108_binfo.loader_start = 0;
6396a193 103 arm_load_kernel(s->soc.boot_cpu_ptr, &xlnx_ep108_binfo);
859a0c5b
PC
104}
105
e264d29d 106static void xlnx_ep108_machine_init(MachineClass *mc)
859a0c5b 107{
e264d29d
EH
108 mc->desc = "Xilinx ZynqMP EP108 board";
109 mc->init = xlnx_ep108_init;
859a0c5b
PC
110}
111
e264d29d 112DEFINE_MACHINE("xlnx-ep108", xlnx_ep108_machine_init)