11df7d1f9SAndrew Baumann /* 21df7d1f9SAndrew Baumann * Raspberry Pi emulation (c) 2012 Gregory Estrade 31df7d1f9SAndrew Baumann * Upstreaming code cleanup [including bcm2835_*] (c) 2013 Jan Petrous 41df7d1f9SAndrew Baumann * 51df7d1f9SAndrew Baumann * Rasperry Pi 2 emulation Copyright (c) 2015, Microsoft 61df7d1f9SAndrew Baumann * Written by Andrew Baumann 71df7d1f9SAndrew Baumann * 8bade5816SPekka Enberg * Raspberry Pi 3 emulation Copyright (c) 2018 Zoltán Baldaszti 9bade5816SPekka Enberg * Upstream code cleanup (c) 2018 Pekka Enberg 10bade5816SPekka Enberg * 116111a0c0SPhilippe Mathieu-Daudé * This work is licensed under the terms of the GNU GPL, version 2 or later. 126111a0c0SPhilippe Mathieu-Daudé * See the COPYING file in the top-level directory. 131df7d1f9SAndrew Baumann */ 141df7d1f9SAndrew Baumann 15c964b660SPeter Maydell #include "qemu/osdep.h" 16ff3dcf28SPeter Maydell #include "qemu/units.h" 17f5bb124eSPhilippe Mathieu-Daudé #include "qemu/cutils.h" 18da34e65cSMarkus Armbruster #include "qapi/error.h" 194771d756SPaolo Bonzini #include "cpu.h" 201df7d1f9SAndrew Baumann #include "hw/arm/bcm2836.h" 21cd6c9977SPhilippe Mathieu-Daudé #include "hw/registerfields.h" 221df7d1f9SAndrew Baumann #include "qemu/error-report.h" 231df7d1f9SAndrew Baumann #include "hw/boards.h" 241df7d1f9SAndrew Baumann #include "hw/loader.h" 2512ec8bd5SPeter Maydell #include "hw/arm/boot.h" 261df7d1f9SAndrew Baumann #include "sysemu/sysemu.h" 27db1015e9SEduardo Habkost #include "qom/object.h" 281df7d1f9SAndrew Baumann 291df7d1f9SAndrew Baumann #define SMPBOOT_ADDR 0x300 /* this should leave enough space for ATAGS */ 301df7d1f9SAndrew Baumann #define MVBAR_ADDR 0x400 /* secure vectors */ 311df7d1f9SAndrew Baumann #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */ 32bade5816SPekka Enberg #define FIRMWARE_ADDR_2 0x8000 /* Pi 2 loads kernel.img here by default */ 33bade5816SPekka Enberg #define FIRMWARE_ADDR_3 0x80000 /* Pi 3 loads kernel.img here by default */ 34ff72cb6bSPeter Maydell #define SPINTABLE_ADDR 0xd8 /* Pi 3 bootloader spintable */ 351df7d1f9SAndrew Baumann 36918c81a5SPhilippe Mathieu-Daudé /* Registered machine type (matches RPi Foundation bootloader and U-Boot) */ 37918c81a5SPhilippe Mathieu-Daudé #define MACH_TYPE_BCM2708 3138 381df7d1f9SAndrew Baumann 39db1015e9SEduardo Habkost struct RaspiMachineState { 40cb57df6fSPhilippe Mathieu-Daudé /*< private >*/ 41cb57df6fSPhilippe Mathieu-Daudé MachineState parent_obj; 42cb57df6fSPhilippe Mathieu-Daudé /*< public >*/ 43926dcdf0SPeter Maydell BCM283XState soc; 440f15c6e3SPhilippe Mathieu-Daudé struct arm_boot_info binfo; 45db1015e9SEduardo Habkost }; 46db1015e9SEduardo Habkost typedef struct RaspiMachineState RaspiMachineState; 47cb57df6fSPhilippe Mathieu-Daudé 48db1015e9SEduardo Habkost struct RaspiMachineClass { 49cb57df6fSPhilippe Mathieu-Daudé /*< private >*/ 50cb57df6fSPhilippe Mathieu-Daudé MachineClass parent_obj; 51cb57df6fSPhilippe Mathieu-Daudé /*< public >*/ 52c318c66cSPhilippe Mathieu-Daudé uint32_t board_rev; 53db1015e9SEduardo Habkost }; 54db1015e9SEduardo Habkost typedef struct RaspiMachineClass RaspiMachineClass; 55cb57df6fSPhilippe Mathieu-Daudé 56cb57df6fSPhilippe Mathieu-Daudé #define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") 578110fa1dSEduardo Habkost DECLARE_OBJ_CHECKERS(RaspiMachineState, RaspiMachineClass, 588110fa1dSEduardo Habkost RASPI_MACHINE, TYPE_RASPI_MACHINE) 59cb57df6fSPhilippe Mathieu-Daudé 601df7d1f9SAndrew Baumann 61cd6c9977SPhilippe Mathieu-Daudé /* 62cd6c9977SPhilippe Mathieu-Daudé * Board revision codes: 63cd6c9977SPhilippe Mathieu-Daudé * www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/ 64cd6c9977SPhilippe Mathieu-Daudé */ 65cd6c9977SPhilippe Mathieu-Daudé FIELD(REV_CODE, REVISION, 0, 4); 66cd6c9977SPhilippe Mathieu-Daudé FIELD(REV_CODE, TYPE, 4, 8); 67cd6c9977SPhilippe Mathieu-Daudé FIELD(REV_CODE, PROCESSOR, 12, 4); 68cd6c9977SPhilippe Mathieu-Daudé FIELD(REV_CODE, MANUFACTURER, 16, 4); 69cd6c9977SPhilippe Mathieu-Daudé FIELD(REV_CODE, MEMORY_SIZE, 20, 3); 70cd6c9977SPhilippe Mathieu-Daudé FIELD(REV_CODE, STYLE, 23, 1); 71cd6c9977SPhilippe Mathieu-Daudé 72*696788d6SPhilippe Mathieu-Daudé typedef enum RaspiProcessorId { 73*696788d6SPhilippe Mathieu-Daudé PROCESSOR_ID_BCM2836 = 1, 74*696788d6SPhilippe Mathieu-Daudé PROCESSOR_ID_BCM2837 = 2, 75*696788d6SPhilippe Mathieu-Daudé } RaspiProcessorId; 76*696788d6SPhilippe Mathieu-Daudé 77*696788d6SPhilippe Mathieu-Daudé static const struct { 78*696788d6SPhilippe Mathieu-Daudé const char *type; 79*696788d6SPhilippe Mathieu-Daudé int cores_count; 80*696788d6SPhilippe Mathieu-Daudé } soc_property[] = { 81*696788d6SPhilippe Mathieu-Daudé [PROCESSOR_ID_BCM2836] = {TYPE_BCM2836, BCM283X_NCPUS}, 82*696788d6SPhilippe Mathieu-Daudé [PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS}, 83*696788d6SPhilippe Mathieu-Daudé }; 84*696788d6SPhilippe Mathieu-Daudé 85f5bb124eSPhilippe Mathieu-Daudé static uint64_t board_ram_size(uint32_t board_rev) 86f5bb124eSPhilippe Mathieu-Daudé { 87f5bb124eSPhilippe Mathieu-Daudé assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */ 88f5bb124eSPhilippe Mathieu-Daudé return 256 * MiB << FIELD_EX32(board_rev, REV_CODE, MEMORY_SIZE); 89f5bb124eSPhilippe Mathieu-Daudé } 90f5bb124eSPhilippe Mathieu-Daudé 91*696788d6SPhilippe Mathieu-Daudé static RaspiProcessorId board_processor_id(uint32_t board_rev) 92cd6c9977SPhilippe Mathieu-Daudé { 93*696788d6SPhilippe Mathieu-Daudé int proc_id = FIELD_EX32(board_rev, REV_CODE, PROCESSOR); 94*696788d6SPhilippe Mathieu-Daudé 95cd6c9977SPhilippe Mathieu-Daudé assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */ 96*696788d6SPhilippe Mathieu-Daudé assert(proc_id < ARRAY_SIZE(soc_property) && soc_property[proc_id].type); 97*696788d6SPhilippe Mathieu-Daudé 98*696788d6SPhilippe Mathieu-Daudé return proc_id; 99cd6c9977SPhilippe Mathieu-Daudé } 100cd6c9977SPhilippe Mathieu-Daudé 101cd6c9977SPhilippe Mathieu-Daudé static int board_version(uint32_t board_rev) 102cd6c9977SPhilippe Mathieu-Daudé { 103cd6c9977SPhilippe Mathieu-Daudé return board_processor_id(board_rev) + 1; 104cd6c9977SPhilippe Mathieu-Daudé } 105cd6c9977SPhilippe Mathieu-Daudé 1062e664b45SPhilippe Mathieu-Daudé static const char *board_soc_type(uint32_t board_rev) 1072e664b45SPhilippe Mathieu-Daudé { 108*696788d6SPhilippe Mathieu-Daudé return soc_property[board_processor_id(board_rev)].type; 1092e664b45SPhilippe Mathieu-Daudé } 1102e664b45SPhilippe Mathieu-Daudé 111759f0f87SPhilippe Mathieu-Daudé static int cores_count(uint32_t board_rev) 112759f0f87SPhilippe Mathieu-Daudé { 113*696788d6SPhilippe Mathieu-Daudé return soc_property[board_processor_id(board_rev)].cores_count; 114759f0f87SPhilippe Mathieu-Daudé } 115759f0f87SPhilippe Mathieu-Daudé 11698b541e1SPhilippe Mathieu-Daudé static const char *board_type(uint32_t board_rev) 11798b541e1SPhilippe Mathieu-Daudé { 11898b541e1SPhilippe Mathieu-Daudé static const char *types[] = { 11998b541e1SPhilippe Mathieu-Daudé "A", "B", "A+", "B+", "2B", "Alpha", "CM1", NULL, "3B", "Zero", 12098b541e1SPhilippe Mathieu-Daudé "CM3", NULL, "Zero W", "3B+", "3A+", NULL, "CM3+", "4B", 12198b541e1SPhilippe Mathieu-Daudé }; 12298b541e1SPhilippe Mathieu-Daudé assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */ 12398b541e1SPhilippe Mathieu-Daudé int bt = FIELD_EX32(board_rev, REV_CODE, TYPE); 12498b541e1SPhilippe Mathieu-Daudé if (bt >= ARRAY_SIZE(types) || !types[bt]) { 12598b541e1SPhilippe Mathieu-Daudé return "Unknown"; 12698b541e1SPhilippe Mathieu-Daudé } 12798b541e1SPhilippe Mathieu-Daudé return types[bt]; 12898b541e1SPhilippe Mathieu-Daudé } 12998b541e1SPhilippe Mathieu-Daudé 1301df7d1f9SAndrew Baumann static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) 1311df7d1f9SAndrew Baumann { 1321df7d1f9SAndrew Baumann static const uint32_t smpboot[] = { 1331df7d1f9SAndrew Baumann 0xe1a0e00f, /* mov lr, pc */ 1341df7d1f9SAndrew Baumann 0xe3a0fe00 + (BOARDSETUP_ADDR >> 4), /* mov pc, BOARDSETUP_ADDR */ 1351df7d1f9SAndrew Baumann 0xee100fb0, /* mrc p15, 0, r0, c0, c0, 5;get core ID */ 1361df7d1f9SAndrew Baumann 0xe7e10050, /* ubfx r0, r0, #0, #2 ;extract LSB */ 1371df7d1f9SAndrew Baumann 0xe59f5014, /* ldr r5, =0x400000CC ;load mbox base */ 1381df7d1f9SAndrew Baumann 0xe320f001, /* 1: yield */ 1391df7d1f9SAndrew Baumann 0xe7953200, /* ldr r3, [r5, r0, lsl #4] ;read mbox for our core*/ 1401df7d1f9SAndrew Baumann 0xe3530000, /* cmp r3, #0 ;spin while zero */ 1411df7d1f9SAndrew Baumann 0x0afffffb, /* beq 1b */ 1421df7d1f9SAndrew Baumann 0xe7853200, /* str r3, [r5, r0, lsl #4] ;clear mbox */ 1431df7d1f9SAndrew Baumann 0xe12fff13, /* bx r3 ;jump to target */ 1441df7d1f9SAndrew Baumann 0x400000cc, /* (constant: mailbox 3 read/clear base) */ 1451df7d1f9SAndrew Baumann }; 1461df7d1f9SAndrew Baumann 1471df7d1f9SAndrew Baumann /* check that we don't overrun board setup vectors */ 1481df7d1f9SAndrew Baumann QEMU_BUILD_BUG_ON(SMPBOOT_ADDR + sizeof(smpboot) > MVBAR_ADDR); 1491df7d1f9SAndrew Baumann /* check that board setup address is correctly relocated */ 1501df7d1f9SAndrew Baumann QEMU_BUILD_BUG_ON((BOARDSETUP_ADDR & 0xf) != 0 1511df7d1f9SAndrew Baumann || (BOARDSETUP_ADDR >> 4) >= 0x100); 1521df7d1f9SAndrew Baumann 1530f073693SPhilippe Mathieu-Daudé rom_add_blob_fixed_as("raspi_smpboot", smpboot, sizeof(smpboot), 1540f073693SPhilippe Mathieu-Daudé info->smp_loader_start, 1550f073693SPhilippe Mathieu-Daudé arm_boot_address_space(cpu, info)); 1561df7d1f9SAndrew Baumann } 1571df7d1f9SAndrew Baumann 158ff72cb6bSPeter Maydell static void write_smpboot64(ARMCPU *cpu, const struct arm_boot_info *info) 159ff72cb6bSPeter Maydell { 1600f073693SPhilippe Mathieu-Daudé AddressSpace *as = arm_boot_address_space(cpu, info); 161ff72cb6bSPeter Maydell /* Unlike the AArch32 version we don't need to call the board setup hook. 162ff72cb6bSPeter Maydell * The mechanism for doing the spin-table is also entirely different. 163ff72cb6bSPeter Maydell * We must have four 64-bit fields at absolute addresses 164ff72cb6bSPeter Maydell * 0xd8, 0xe0, 0xe8, 0xf0 in RAM, which are the flag variables for 165ff72cb6bSPeter Maydell * our CPUs, and which we must ensure are zero initialized before 166ff72cb6bSPeter Maydell * the primary CPU goes into the kernel. We put these variables inside 167ff72cb6bSPeter Maydell * a rom blob, so that the reset for ROM contents zeroes them for us. 168ff72cb6bSPeter Maydell */ 169ff72cb6bSPeter Maydell static const uint32_t smpboot[] = { 170ff72cb6bSPeter Maydell 0xd2801b05, /* mov x5, 0xd8 */ 171ff72cb6bSPeter Maydell 0xd53800a6, /* mrs x6, mpidr_el1 */ 172ff72cb6bSPeter Maydell 0x924004c6, /* and x6, x6, #0x3 */ 173ff72cb6bSPeter Maydell 0xd503205f, /* spin: wfe */ 174ff72cb6bSPeter Maydell 0xf86678a4, /* ldr x4, [x5,x6,lsl #3] */ 175ff72cb6bSPeter Maydell 0xb4ffffc4, /* cbz x4, spin */ 176ff72cb6bSPeter Maydell 0xd2800000, /* mov x0, #0x0 */ 177ff72cb6bSPeter Maydell 0xd2800001, /* mov x1, #0x0 */ 178ff72cb6bSPeter Maydell 0xd2800002, /* mov x2, #0x0 */ 179ff72cb6bSPeter Maydell 0xd2800003, /* mov x3, #0x0 */ 180ff72cb6bSPeter Maydell 0xd61f0080, /* br x4 */ 181ff72cb6bSPeter Maydell }; 182ff72cb6bSPeter Maydell 183ff72cb6bSPeter Maydell static const uint64_t spintables[] = { 184ff72cb6bSPeter Maydell 0, 0, 0, 0 185ff72cb6bSPeter Maydell }; 186ff72cb6bSPeter Maydell 1870f073693SPhilippe Mathieu-Daudé rom_add_blob_fixed_as("raspi_smpboot", smpboot, sizeof(smpboot), 1880f073693SPhilippe Mathieu-Daudé info->smp_loader_start, as); 1890f073693SPhilippe Mathieu-Daudé rom_add_blob_fixed_as("raspi_spintables", spintables, sizeof(spintables), 1900f073693SPhilippe Mathieu-Daudé SPINTABLE_ADDR, as); 191ff72cb6bSPeter Maydell } 192ff72cb6bSPeter Maydell 1931df7d1f9SAndrew Baumann static void write_board_setup(ARMCPU *cpu, const struct arm_boot_info *info) 1941df7d1f9SAndrew Baumann { 1951df7d1f9SAndrew Baumann arm_write_secure_board_setup_dummy_smc(cpu, info, MVBAR_ADDR); 1961df7d1f9SAndrew Baumann } 1971df7d1f9SAndrew Baumann 1981df7d1f9SAndrew Baumann static void reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info) 1991df7d1f9SAndrew Baumann { 2001df7d1f9SAndrew Baumann CPUState *cs = CPU(cpu); 2011df7d1f9SAndrew Baumann cpu_set_pc(cs, info->smp_loader_start); 2021df7d1f9SAndrew Baumann } 2031df7d1f9SAndrew Baumann 2041df7d1f9SAndrew Baumann static void setup_boot(MachineState *machine, int version, size_t ram_size) 2051df7d1f9SAndrew Baumann { 20602058e4bSPhilippe Mathieu-Daudé RaspiMachineState *s = RASPI_MACHINE(machine); 2071df7d1f9SAndrew Baumann int r; 2081df7d1f9SAndrew Baumann 2090f15c6e3SPhilippe Mathieu-Daudé s->binfo.board_id = MACH_TYPE_BCM2708; 2100f15c6e3SPhilippe Mathieu-Daudé s->binfo.ram_size = ram_size; 2110f15c6e3SPhilippe Mathieu-Daudé s->binfo.nb_cpus = machine->smp.cpus; 21201e02f5aSPeter Maydell 21301e02f5aSPeter Maydell if (version <= 2) { 21401e02f5aSPeter Maydell /* The rpi1 and 2 require some custom setup code to run in Secure 21501e02f5aSPeter Maydell * mode before booting a kernel (to set up the SMC vectors so 21601e02f5aSPeter Maydell * that we get a no-op SMC; this is used by Linux to call the 21701e02f5aSPeter Maydell * firmware for some cache maintenance operations. 21801e02f5aSPeter Maydell * The rpi3 doesn't need this. 21901e02f5aSPeter Maydell */ 2200f15c6e3SPhilippe Mathieu-Daudé s->binfo.board_setup_addr = BOARDSETUP_ADDR; 2210f15c6e3SPhilippe Mathieu-Daudé s->binfo.write_board_setup = write_board_setup; 2220f15c6e3SPhilippe Mathieu-Daudé s->binfo.secure_board_setup = true; 2230f15c6e3SPhilippe Mathieu-Daudé s->binfo.secure_boot = true; 22401e02f5aSPeter Maydell } 2251df7d1f9SAndrew Baumann 226bade5816SPekka Enberg /* Pi2 and Pi3 requires SMP setup */ 227bade5816SPekka Enberg if (version >= 2) { 2280f15c6e3SPhilippe Mathieu-Daudé s->binfo.smp_loader_start = SMPBOOT_ADDR; 229ff72cb6bSPeter Maydell if (version == 2) { 2300f15c6e3SPhilippe Mathieu-Daudé s->binfo.write_secondary_boot = write_smpboot; 231ff72cb6bSPeter Maydell } else { 2320f15c6e3SPhilippe Mathieu-Daudé s->binfo.write_secondary_boot = write_smpboot64; 233ff72cb6bSPeter Maydell } 2340f15c6e3SPhilippe Mathieu-Daudé s->binfo.secondary_cpu_reset_hook = reset_secondary; 2351df7d1f9SAndrew Baumann } 2361df7d1f9SAndrew Baumann 2371df7d1f9SAndrew Baumann /* If the user specified a "firmware" image (e.g. UEFI), we bypass 2381df7d1f9SAndrew Baumann * the normal Linux boot process 2391df7d1f9SAndrew Baumann */ 2401df7d1f9SAndrew Baumann if (machine->firmware) { 241bade5816SPekka Enberg hwaddr firmware_addr = version == 3 ? FIRMWARE_ADDR_3 : FIRMWARE_ADDR_2; 2421df7d1f9SAndrew Baumann /* load the firmware image (typically kernel.img) */ 243bade5816SPekka Enberg r = load_image_targphys(machine->firmware, firmware_addr, 244bade5816SPekka Enberg ram_size - firmware_addr); 2451df7d1f9SAndrew Baumann if (r < 0) { 2461df7d1f9SAndrew Baumann error_report("Failed to load firmware from %s", machine->firmware); 2471df7d1f9SAndrew Baumann exit(1); 2481df7d1f9SAndrew Baumann } 2491df7d1f9SAndrew Baumann 2500f15c6e3SPhilippe Mathieu-Daudé s->binfo.entry = firmware_addr; 2510f15c6e3SPhilippe Mathieu-Daudé s->binfo.firmware_loaded = true; 2521df7d1f9SAndrew Baumann } 2531df7d1f9SAndrew Baumann 2540f15c6e3SPhilippe Mathieu-Daudé arm_load_kernel(&s->soc.cpu[0].core, machine, &s->binfo); 2551df7d1f9SAndrew Baumann } 2561df7d1f9SAndrew Baumann 25713c4e2c0SPhilippe Mathieu-Daudé static void raspi_machine_init(MachineState *machine) 2581df7d1f9SAndrew Baumann { 259c318c66cSPhilippe Mathieu-Daudé RaspiMachineClass *mc = RASPI_MACHINE_GET_CLASS(machine); 260cb57df6fSPhilippe Mathieu-Daudé RaspiMachineState *s = RASPI_MACHINE(machine); 261c318c66cSPhilippe Mathieu-Daudé uint32_t board_rev = mc->board_rev; 262cd6c9977SPhilippe Mathieu-Daudé int version = board_version(board_rev); 263f5bb124eSPhilippe Mathieu-Daudé uint64_t ram_size = board_ram_size(board_rev); 2645e9c2a8dSGrégory ESTRADE uint32_t vcram_size; 265a55b53a2SAndrew Baumann DriveInfo *di; 266a55b53a2SAndrew Baumann BlockBackend *blk; 267a55b53a2SAndrew Baumann BusState *bus; 268a55b53a2SAndrew Baumann DeviceState *carddev; 2691df7d1f9SAndrew Baumann 270f5bb124eSPhilippe Mathieu-Daudé if (machine->ram_size != ram_size) { 271f5bb124eSPhilippe Mathieu-Daudé char *size_str = size_to_str(ram_size); 272f5bb124eSPhilippe Mathieu-Daudé error_report("Invalid RAM size, should be %s", size_str); 273f5bb124eSPhilippe Mathieu-Daudé g_free(size_str); 274ff3dcf28SPeter Maydell exit(1); 275ff3dcf28SPeter Maydell } 276ff3dcf28SPeter Maydell 2771df7d1f9SAndrew Baumann /* FIXME: Remove when we have custom CPU address space support */ 278a4317ae8SIgor Mammedov memory_region_add_subregion_overlap(get_system_memory(), 0, 279a4317ae8SIgor Mammedov machine->ram, 0); 2801df7d1f9SAndrew Baumann 2811df7d1f9SAndrew Baumann /* Setup the SOC */ 2829fc7fc4dSMarkus Armbruster object_initialize_child(OBJECT(machine), "soc", &s->soc, 2839fc7fc4dSMarkus Armbruster board_soc_type(board_rev)); 284d2623129SMarkus Armbruster object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(machine->ram)); 2855325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->soc), "board-rev", board_rev, 286f0afa731SStephen Warren &error_abort); 287ce189ab2SMarkus Armbruster qdev_realize(DEVICE(&s->soc), NULL, &error_abort); 2881df7d1f9SAndrew Baumann 289a55b53a2SAndrew Baumann /* Create and plug in the SD cards */ 290a55b53a2SAndrew Baumann di = drive_get_next(IF_SD); 291a55b53a2SAndrew Baumann blk = di ? blk_by_legacy_dinfo(di) : NULL; 292a55b53a2SAndrew Baumann bus = qdev_get_child_bus(DEVICE(&s->soc), "sd-bus"); 293a55b53a2SAndrew Baumann if (bus == NULL) { 294a55b53a2SAndrew Baumann error_report("No SD bus found in SOC object"); 295a55b53a2SAndrew Baumann exit(1); 296a55b53a2SAndrew Baumann } 2973e80f690SMarkus Armbruster carddev = qdev_new(TYPE_SD_CARD); 298934df912SMarkus Armbruster qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal); 2993e80f690SMarkus Armbruster qdev_realize_and_unref(carddev, bus, &error_fatal); 300a55b53a2SAndrew Baumann 301c5c6c47cSMarc-André Lureau vcram_size = object_property_get_uint(OBJECT(&s->soc), "vcram-size", 3025e9c2a8dSGrégory ESTRADE &error_abort); 303bade5816SPekka Enberg setup_boot(machine, version, machine->ram_size - vcram_size); 304bade5816SPekka Enberg } 305bade5816SPekka Enberg 306f0eeb4b6SPhilippe Mathieu-Daudé static void raspi_machine_class_common_init(MachineClass *mc, 307f0eeb4b6SPhilippe Mathieu-Daudé uint32_t board_rev) 3081df7d1f9SAndrew Baumann { 30962f06f71SPhilippe Mathieu-Daudé mc->desc = g_strdup_printf("Raspberry Pi %s (revision 1.%u)", 31062f06f71SPhilippe Mathieu-Daudé board_type(board_rev), 31162f06f71SPhilippe Mathieu-Daudé FIELD_EX32(board_rev, REV_CODE, REVISION)); 31213c4e2c0SPhilippe Mathieu-Daudé mc->init = raspi_machine_init; 3131df7d1f9SAndrew Baumann mc->block_default_type = IF_SD; 3141df7d1f9SAndrew Baumann mc->no_parallel = 1; 3151df7d1f9SAndrew Baumann mc->no_floppy = 1; 3161df7d1f9SAndrew Baumann mc->no_cdrom = 1; 317759f0f87SPhilippe Mathieu-Daudé mc->default_cpus = mc->min_cpus = mc->max_cpus = cores_count(board_rev); 318975f3402SPhilippe Mathieu-Daudé mc->default_ram_size = board_ram_size(board_rev); 319a4317ae8SIgor Mammedov mc->default_ram_id = "ram"; 320a03bde36SPhilippe Mathieu-Daudé }; 321cb57df6fSPhilippe Mathieu-Daudé 322f0eeb4b6SPhilippe Mathieu-Daudé static void raspi2b_machine_class_init(ObjectClass *oc, void *data) 323f0eeb4b6SPhilippe Mathieu-Daudé { 324f0eeb4b6SPhilippe Mathieu-Daudé MachineClass *mc = MACHINE_CLASS(oc); 325f0eeb4b6SPhilippe Mathieu-Daudé RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); 326f0eeb4b6SPhilippe Mathieu-Daudé 327aa35ec22SPhilippe Mathieu-Daudé mc->alias = "raspi2"; 328f0eeb4b6SPhilippe Mathieu-Daudé rmc->board_rev = 0xa21041; 329f0eeb4b6SPhilippe Mathieu-Daudé raspi_machine_class_common_init(mc, rmc->board_rev); 330f0eeb4b6SPhilippe Mathieu-Daudé }; 331f0eeb4b6SPhilippe Mathieu-Daudé 332f0eeb4b6SPhilippe Mathieu-Daudé #ifdef TARGET_AARCH64 333f0eeb4b6SPhilippe Mathieu-Daudé static void raspi3b_machine_class_init(ObjectClass *oc, void *data) 334f0eeb4b6SPhilippe Mathieu-Daudé { 335f0eeb4b6SPhilippe Mathieu-Daudé MachineClass *mc = MACHINE_CLASS(oc); 336f0eeb4b6SPhilippe Mathieu-Daudé RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); 337f0eeb4b6SPhilippe Mathieu-Daudé 338aa35ec22SPhilippe Mathieu-Daudé mc->alias = "raspi3"; 339f0eeb4b6SPhilippe Mathieu-Daudé rmc->board_rev = 0xa02082; 340f0eeb4b6SPhilippe Mathieu-Daudé raspi_machine_class_common_init(mc, rmc->board_rev); 341f0eeb4b6SPhilippe Mathieu-Daudé }; 342f0eeb4b6SPhilippe Mathieu-Daudé #endif /* TARGET_AARCH64 */ 343f0eeb4b6SPhilippe Mathieu-Daudé 344cb57df6fSPhilippe Mathieu-Daudé static const TypeInfo raspi_machine_types[] = { 345cb57df6fSPhilippe Mathieu-Daudé { 346aa35ec22SPhilippe Mathieu-Daudé .name = MACHINE_TYPE_NAME("raspi2b"), 347cb57df6fSPhilippe Mathieu-Daudé .parent = TYPE_RASPI_MACHINE, 348f0eeb4b6SPhilippe Mathieu-Daudé .class_init = raspi2b_machine_class_init, 349cb57df6fSPhilippe Mathieu-Daudé #ifdef TARGET_AARCH64 350cb57df6fSPhilippe Mathieu-Daudé }, { 351aa35ec22SPhilippe Mathieu-Daudé .name = MACHINE_TYPE_NAME("raspi3b"), 352cb57df6fSPhilippe Mathieu-Daudé .parent = TYPE_RASPI_MACHINE, 353f0eeb4b6SPhilippe Mathieu-Daudé .class_init = raspi3b_machine_class_init, 354cb57df6fSPhilippe Mathieu-Daudé #endif 355cb57df6fSPhilippe Mathieu-Daudé }, { 356cb57df6fSPhilippe Mathieu-Daudé .name = TYPE_RASPI_MACHINE, 357cb57df6fSPhilippe Mathieu-Daudé .parent = TYPE_MACHINE, 358cb57df6fSPhilippe Mathieu-Daudé .instance_size = sizeof(RaspiMachineState), 359cb57df6fSPhilippe Mathieu-Daudé .class_size = sizeof(RaspiMachineClass), 360cb57df6fSPhilippe Mathieu-Daudé .abstract = true, 361cb57df6fSPhilippe Mathieu-Daudé } 362cb57df6fSPhilippe Mathieu-Daudé }; 363cb57df6fSPhilippe Mathieu-Daudé 364cb57df6fSPhilippe Mathieu-Daudé DEFINE_TYPES(raspi_machine_types) 365