2
0

digic.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * QEMU model of the Canon DIGIC SoC.
  3. *
  4. * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
  5. *
  6. * This model is based on reverse engineering efforts
  7. * made by CHDK (http://chdk.wikia.com) and
  8. * Magic Lantern (http://www.magiclantern.fm) projects
  9. * contributors.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. */
  22. #include "qemu/osdep.h"
  23. #include "qapi/error.h"
  24. #include "qemu/module.h"
  25. #include "hw/arm/digic.h"
  26. #include "hw/qdev-properties.h"
  27. #include "system/system.h"
  28. #define DIGIC4_TIMER_BASE(n) (0xc0210000 + (n) * 0x100)
  29. #define DIGIC_UART_BASE 0xc0800000
  30. static void digic_init(Object *obj)
  31. {
  32. DigicState *s = DIGIC(obj);
  33. int i;
  34. object_initialize_child(obj, "cpu", &s->cpu, ARM_CPU_TYPE_NAME("arm946"));
  35. for (i = 0; i < DIGIC4_NB_TIMERS; i++) {
  36. g_autofree char *name = g_strdup_printf("timer[%d]", i);
  37. object_initialize_child(obj, name, &s->timer[i], TYPE_DIGIC_TIMER);
  38. }
  39. object_initialize_child(obj, "uart", &s->uart, TYPE_DIGIC_UART);
  40. }
  41. static void digic_realize(DeviceState *dev, Error **errp)
  42. {
  43. DigicState *s = DIGIC(dev);
  44. SysBusDevice *sbd;
  45. int i;
  46. if (!object_property_set_bool(OBJECT(&s->cpu), "reset-hivecs", true,
  47. errp)) {
  48. return;
  49. }
  50. if (!qdev_realize(DEVICE(&s->cpu), NULL, errp)) {
  51. return;
  52. }
  53. for (i = 0; i < DIGIC4_NB_TIMERS; i++) {
  54. if (!sysbus_realize(SYS_BUS_DEVICE(&s->timer[i]), errp)) {
  55. return;
  56. }
  57. sbd = SYS_BUS_DEVICE(&s->timer[i]);
  58. sysbus_mmio_map(sbd, 0, DIGIC4_TIMER_BASE(i));
  59. }
  60. qdev_prop_set_chr(DEVICE(&s->uart), "chardev", serial_hd(0));
  61. if (!sysbus_realize(SYS_BUS_DEVICE(&s->uart), errp)) {
  62. return;
  63. }
  64. sbd = SYS_BUS_DEVICE(&s->uart);
  65. sysbus_mmio_map(sbd, 0, DIGIC_UART_BASE);
  66. }
  67. static void digic_class_init(ObjectClass *oc, void *data)
  68. {
  69. DeviceClass *dc = DEVICE_CLASS(oc);
  70. dc->realize = digic_realize;
  71. /* Reason: Uses serial_hds in the realize function --> not usable twice */
  72. dc->user_creatable = false;
  73. }
  74. static const TypeInfo digic_type_info = {
  75. .name = TYPE_DIGIC,
  76. .parent = TYPE_DEVICE,
  77. .instance_size = sizeof(DigicState),
  78. .instance_init = digic_init,
  79. .class_init = digic_class_init,
  80. };
  81. static void digic_register_types(void)
  82. {
  83. type_register_static(&digic_type_info);
  84. }
  85. type_init(digic_register_types)