orangepi.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Orange Pi emulation
  3. *
  4. * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "qemu/osdep.h"
  20. #include "qemu/units.h"
  21. #include "exec/address-spaces.h"
  22. #include "qapi/error.h"
  23. #include "qemu/error-report.h"
  24. #include "hw/boards.h"
  25. #include "hw/qdev-properties.h"
  26. #include "hw/arm/allwinner-h3.h"
  27. #include "hw/arm/boot.h"
  28. static struct arm_boot_info orangepi_binfo;
  29. static void orangepi_init(MachineState *machine)
  30. {
  31. AwH3State *h3;
  32. DriveInfo *di;
  33. BlockBackend *blk;
  34. BusState *bus;
  35. DeviceState *carddev;
  36. /* BIOS is not supported by this board */
  37. if (machine->firmware) {
  38. error_report("BIOS not supported for this machine");
  39. exit(1);
  40. }
  41. /* This board has fixed size RAM */
  42. if (machine->ram_size != 1 * GiB) {
  43. error_report("This machine can only be used with 1GiB of RAM");
  44. exit(1);
  45. }
  46. h3 = AW_H3(object_new(TYPE_AW_H3));
  47. object_property_add_child(OBJECT(machine), "soc", OBJECT(h3));
  48. object_unref(OBJECT(h3));
  49. /* Setup timer properties */
  50. object_property_set_int(OBJECT(h3), "clk0-freq", 32768, &error_abort);
  51. object_property_set_int(OBJECT(h3), "clk1-freq", 24 * 1000 * 1000,
  52. &error_abort);
  53. /* Setup SID properties. Currently using a default fixed SID identifier. */
  54. if (qemu_uuid_is_null(&h3->sid.identifier)) {
  55. qdev_prop_set_string(DEVICE(h3), "identifier",
  56. "02c00081-1111-2222-3333-000044556677");
  57. } else if (ldl_be_p(&h3->sid.identifier.data[0]) != 0x02c00081) {
  58. warn_report("Security Identifier value does not include H3 prefix");
  59. }
  60. /* Setup EMAC properties */
  61. object_property_set_int(OBJECT(&h3->emac), "phy-addr", 1, &error_abort);
  62. /* DRAMC */
  63. object_property_set_uint(OBJECT(h3), "ram-addr", h3->memmap[AW_H3_DEV_SDRAM],
  64. &error_abort);
  65. object_property_set_int(OBJECT(h3), "ram-size", machine->ram_size / MiB,
  66. &error_abort);
  67. /* Mark H3 object realized */
  68. qdev_realize(DEVICE(h3), NULL, &error_abort);
  69. /* Retrieve SD bus */
  70. di = drive_get(IF_SD, 0, 0);
  71. blk = di ? blk_by_legacy_dinfo(di) : NULL;
  72. bus = qdev_get_child_bus(DEVICE(h3), "sd-bus");
  73. /* Plug in SD card */
  74. carddev = qdev_new(TYPE_SD_CARD);
  75. qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
  76. qdev_realize_and_unref(carddev, bus, &error_fatal);
  77. /* SDRAM */
  78. memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_DEV_SDRAM],
  79. machine->ram);
  80. /* Load target kernel or start using BootROM */
  81. if (!machine->kernel_filename && blk && blk_is_available(blk)) {
  82. /* Use Boot ROM to copy data from SD card to SRAM */
  83. allwinner_h3_bootrom_setup(h3, blk);
  84. }
  85. orangepi_binfo.loader_start = h3->memmap[AW_H3_DEV_SDRAM];
  86. orangepi_binfo.ram_size = machine->ram_size;
  87. orangepi_binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC;
  88. arm_load_kernel(&h3->cpus[0], machine, &orangepi_binfo);
  89. }
  90. static void orangepi_machine_init(MachineClass *mc)
  91. {
  92. static const char * const valid_cpu_types[] = {
  93. ARM_CPU_TYPE_NAME("cortex-a7"),
  94. NULL
  95. };
  96. mc->desc = "Orange Pi PC (Cortex-A7)";
  97. mc->init = orangepi_init;
  98. mc->block_default_type = IF_SD;
  99. mc->units_per_default_bus = 1;
  100. mc->min_cpus = AW_H3_NUM_CPUS;
  101. mc->max_cpus = AW_H3_NUM_CPUS;
  102. mc->default_cpus = AW_H3_NUM_CPUS;
  103. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
  104. mc->valid_cpu_types = valid_cpu_types;
  105. mc->default_ram_size = 1 * GiB;
  106. mc->default_ram_id = "orangepi.ram";
  107. mc->auto_create_sdcard = true;
  108. }
  109. DEFINE_MACHINE("orangepi-pc", orangepi_machine_init)