master
c 196 lines 7.48 KB
Raw
1 /*
2 * Model of Petalogix linux reference design targeting Xilinx Spartan 3ADSP-1800
3 * boards.
4 *
5 * Copyright (c) 2009 Edgar E. Iglesias.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26 #include "qemu/osdep.h"
27 #include "qemu/target-info.h"
28 #include "qemu/units.h"
29 #include "qapi/error.h"
30 #include "target/microblaze/cpu.h"
31 #include "hw/core/sysbus.h"
32 #include "net/net.h"
33 #include "hw/block/flash.h"
34 #include "system/system.h"
35 #include "hw/core/boards.h"
36 #include "hw/misc/unimp.h"
37 #include "system/address-spaces.h"
38 #include "hw/char/xilinx_uartlite.h"
39
40 #include "boot.h"
41
42 #define LMB_BRAM_SIZE (128 * KiB)
43 #define FLASH_SIZE (16 * MiB)
44
45 #define BINARY_DEVICE_TREE_FILE "petalogix-s3adsp1800.dtb"
46
47 #define MEMORY_BASEADDR 0x90000000
48 #define FLASH_BASEADDR 0xa0000000
49 #define GPIO_BASEADDR 0x81400000
50 #define INTC_BASEADDR 0x81800000
51 #define TIMER_BASEADDR 0x83c00000
52 #define UARTLITE_BASEADDR 0x84000000
53 #define ETHLITE_BASEADDR 0x81000000
54
55 #define TIMER_IRQ 0
56 #define ETHLITE_IRQ 1
57 #define UARTLITE_IRQ 3
58
59 #define TYPE_PETALOGIX_S3ADSP1800_MACHINE \
60 MACHINE_TYPE_NAME("petalogix-s3adsp1800")
61
62 struct S3Adsp1800MachineState {
63 MachineState parent_class;
64
65 EndianMode endianness;
66 };
67
68 OBJECT_DECLARE_TYPE(S3Adsp1800MachineState, MachineClass,
69 PETALOGIX_S3ADSP1800_MACHINE)
70
71
72 static void
73 petalogix_s3adsp1800_init(MachineState *machine)
74 {
75 S3Adsp1800MachineState *psms = PETALOGIX_S3ADSP1800_MACHINE(machine);
76 ram_addr_t ram_size = machine->ram_size;
77 DeviceState *dev;
78 MicroBlazeCPU *cpu;
79 DriveInfo *dinfo;
80 int i;
81 hwaddr ddr_base = MEMORY_BASEADDR;
82 MemoryRegion *phys_lmb_bram = g_new(MemoryRegion, 1);
83 MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
84 qemu_irq irq[32];
85 MemoryRegion *sysmem = get_system_memory();
86 EndianMode endianness = psms->endianness;
87
88 cpu = MICROBLAZE_CPU(object_new(TYPE_MICROBLAZE_CPU));
89 object_property_set_str(OBJECT(cpu), "version", "7.10.d", &error_abort);
90 object_property_set_bool(OBJECT(cpu), "little-endian",
91 endianness == ENDIAN_MODE_LITTLE, &error_abort);
92 qdev_realize(DEVICE(cpu), NULL, &error_abort);
93
94 /* Attach emulated BRAM through the LMB. */
95 memory_region_init_ram(phys_lmb_bram, NULL,
96 "petalogix_s3adsp1800.lmb_bram", LMB_BRAM_SIZE,
97 &error_fatal);
98 memory_region_add_subregion(sysmem, 0x00000000, phys_lmb_bram);
99
100 memory_region_init_ram(phys_ram, NULL, "petalogix_s3adsp1800.ram",
101 ram_size, &error_fatal);
102 memory_region_add_subregion(sysmem, ddr_base, phys_ram);
103
104 dinfo = drive_get(IF_PFLASH, 0, 0);
105 pflash_cfi01_register(FLASH_BASEADDR,
106 "petalogix_s3adsp1800.flash", FLASH_SIZE,
107 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
108 64 * KiB, 1, 0x89, 0x18, 0x0000, 0x0, 1);
109
110 dev = qdev_new("xlnx.xps-intc");
111 qdev_prop_set_enum(dev, "endianness", endianness);
112 qdev_prop_set_uint32(dev, "kind-of-intr",
113 1 << ETHLITE_IRQ | 1 << UARTLITE_IRQ);
114 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
115 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, INTC_BASEADDR);
116 sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
117 qdev_get_gpio_in(DEVICE(cpu), MB_CPU_IRQ));
118 for (i = 0; i < 32; i++) {
119 irq[i] = qdev_get_gpio_in(dev, i);
120 }
121
122 dev = qdev_new(TYPE_XILINX_UARTLITE);
123 qdev_prop_set_enum(dev, "endianness", endianness);
124 qdev_prop_set_chr(dev, "chardev", serial_hd(0));
125 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
126 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, UARTLITE_BASEADDR);
127 sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[UARTLITE_IRQ]);
128
129 /* 2 timers at irq 2 @ 62 Mhz. */
130 dev = qdev_new("xlnx.xps-timer");
131 qdev_prop_set_enum(dev, "endianness", endianness);
132 qdev_prop_set_uint32(dev, "one-timer-only", 0);
133 qdev_prop_set_uint32(dev, "clock-frequency", 62 * 1000000);
134 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
135 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, TIMER_BASEADDR);
136 sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[TIMER_IRQ]);
137
138 dev = qdev_new("xlnx.xps-ethernetlite");
139 qdev_prop_set_enum(dev, "endianness", endianness);
140 qemu_configure_nic_device(dev, true, NULL);
141 qdev_prop_set_uint32(dev, "tx-ping-pong", 0);
142 qdev_prop_set_uint32(dev, "rx-ping-pong", 0);
143 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
144 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, ETHLITE_BASEADDR);
145 sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[ETHLITE_IRQ]);
146
147 create_unimplemented_device("xps_gpio", GPIO_BASEADDR, 0x10000);
148
149 microblaze_load_kernel(cpu, endianness == ENDIAN_MODE_LITTLE, ddr_base,
150 ram_size, machine->initrd_filename,
151 BINARY_DEVICE_TREE_FILE,
152 NULL);
153 }
154
155 static int machine_get_endianness(Object *obj, Error **errp G_GNUC_UNUSED)
156 {
157 S3Adsp1800MachineState *ms = PETALOGIX_S3ADSP1800_MACHINE(obj);
158 return ms->endianness;
159 }
160
161 static void machine_set_endianness(Object *obj, int endianness, Error **errp)
162 {
163 S3Adsp1800MachineState *ms = PETALOGIX_S3ADSP1800_MACHINE(obj);
164 ms->endianness = endianness;
165 }
166
167 static void petalogix_s3adsp1800_machine_class_init(ObjectClass *oc,
168 const void *data)
169 {
170 MachineClass *mc = MACHINE_CLASS(oc);
171 ObjectProperty *prop;
172
173 mc->desc = "PetaLogix linux refdesign for xilinx Spartan 3ADSP1800";
174 mc->init = petalogix_s3adsp1800_init;
175 mc->is_default = true;
176
177 prop = object_class_property_add_enum(oc, "endianness", "EndianMode",
178 &EndianMode_lookup,
179 machine_get_endianness,
180 machine_set_endianness);
181 object_property_set_default_str(prop, target_big_endian() ? "big"
182 : "little");
183 object_class_property_set_description(oc, "endianness",
184 "Defines whether the machine runs in big or little endian mode");
185 }
186
187 static const TypeInfo petalogix_s3adsp1800_machine_types[] = {
188 {
189 .name = TYPE_PETALOGIX_S3ADSP1800_MACHINE,
190 .parent = TYPE_MACHINE,
191 .class_init = petalogix_s3adsp1800_machine_class_init,
192 .instance_size = sizeof(S3Adsp1800MachineState),
193 },
194 };
195
196 DEFINE_TYPES(petalogix_s3adsp1800_machine_types)