orangepi.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 "cpu.h"
  24. #include "hw/sysbus.h"
  25. #include "hw/boards.h"
  26. #include "hw/qdev-properties.h"
  27. #include "hw/arm/allwinner-h3.h"
  28. #include "sysemu/sysemu.h"
  29. static struct arm_boot_info orangepi_binfo = {
  30. .nb_cpus = AW_H3_NUM_CPUS,
  31. };
  32. static void orangepi_init(MachineState *machine)
  33. {
  34. AwH3State *h3;
  35. DriveInfo *di;
  36. BlockBackend *blk;
  37. BusState *bus;
  38. DeviceState *carddev;
  39. /* BIOS is not supported by this board */
  40. if (bios_name) {
  41. error_report("BIOS not supported for this machine");
  42. exit(1);
  43. }
  44. /* This board has fixed size RAM */
  45. if (machine->ram_size != 1 * GiB) {
  46. error_report("This machine can only be used with 1GiB of RAM");
  47. exit(1);
  48. }
  49. /* Only allow Cortex-A7 for this board */
  50. if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a7")) != 0) {
  51. error_report("This board can only be used with cortex-a7 CPU");
  52. exit(1);
  53. }
  54. h3 = AW_H3(object_new(TYPE_AW_H3));
  55. object_property_add_child(OBJECT(machine), "soc", OBJECT(h3));
  56. object_unref(OBJECT(h3));
  57. /* Setup timer properties */
  58. object_property_set_int(OBJECT(h3), "clk0-freq", 32768, &error_abort);
  59. object_property_set_int(OBJECT(h3), "clk1-freq", 24 * 1000 * 1000,
  60. &error_abort);
  61. /* Setup SID properties. Currently using a default fixed SID identifier. */
  62. if (qemu_uuid_is_null(&h3->sid.identifier)) {
  63. qdev_prop_set_string(DEVICE(h3), "identifier",
  64. "02c00081-1111-2222-3333-000044556677");
  65. } else if (ldl_be_p(&h3->sid.identifier.data[0]) != 0x02c00081) {
  66. warn_report("Security Identifier value does not include H3 prefix");
  67. }
  68. /* Setup EMAC properties */
  69. object_property_set_int(OBJECT(&h3->emac), "phy-addr", 1, &error_abort);
  70. /* DRAMC */
  71. object_property_set_uint(OBJECT(h3), "ram-addr", h3->memmap[AW_H3_SDRAM],
  72. &error_abort);
  73. object_property_set_int(OBJECT(h3), "ram-size", machine->ram_size / MiB,
  74. &error_abort);
  75. /* Mark H3 object realized */
  76. qdev_realize(DEVICE(h3), NULL, &error_abort);
  77. /* Retrieve SD bus */
  78. di = drive_get_next(IF_SD);
  79. blk = di ? blk_by_legacy_dinfo(di) : NULL;
  80. bus = qdev_get_child_bus(DEVICE(h3), "sd-bus");
  81. /* Plug in SD card */
  82. carddev = qdev_new(TYPE_SD_CARD);
  83. qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
  84. qdev_realize_and_unref(carddev, bus, &error_fatal);
  85. /* SDRAM */
  86. memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
  87. machine->ram);
  88. /* Load target kernel or start using BootROM */
  89. if (!machine->kernel_filename && blk && blk_is_available(blk)) {
  90. /* Use Boot ROM to copy data from SD card to SRAM */
  91. allwinner_h3_bootrom_setup(h3, blk);
  92. }
  93. orangepi_binfo.loader_start = h3->memmap[AW_H3_SDRAM];
  94. orangepi_binfo.ram_size = machine->ram_size;
  95. arm_load_kernel(ARM_CPU(first_cpu), machine, &orangepi_binfo);
  96. }
  97. static void orangepi_machine_init(MachineClass *mc)
  98. {
  99. mc->desc = "Orange Pi PC";
  100. mc->init = orangepi_init;
  101. mc->block_default_type = IF_SD;
  102. mc->units_per_default_bus = 1;
  103. mc->min_cpus = AW_H3_NUM_CPUS;
  104. mc->max_cpus = AW_H3_NUM_CPUS;
  105. mc->default_cpus = AW_H3_NUM_CPUS;
  106. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
  107. mc->default_ram_size = 1 * GiB;
  108. mc->default_ram_id = "orangepi.ram";
  109. }
  110. DEFINE_MACHINE("orangepi-pc", orangepi_machine_init)