exynos4210_gic.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Samsung exynos4210 GIC implementation. Based on hw/arm_gic.c
  3. *
  4. * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * Evgeny Voevodin <e.voevodin@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. * See the GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include "qemu/osdep.h"
  23. #include "hw/sysbus.h"
  24. #include "migration/vmstate.h"
  25. #include "qapi/error.h"
  26. #include "qemu/module.h"
  27. #include "hw/irq.h"
  28. #include "hw/qdev-properties.h"
  29. #include "hw/intc/exynos4210_gic.h"
  30. #include "hw/arm/exynos4210.h"
  31. #include "qom/object.h"
  32. #define EXYNOS4210_GIC_NIRQ 160
  33. #define EXYNOS4210_EXT_GIC_CPU_REGION_SIZE 0x10000
  34. #define EXYNOS4210_EXT_GIC_DIST_REGION_SIZE 0x10000
  35. #define EXYNOS4210_EXT_GIC_PER_CPU_OFFSET 0x8000
  36. #define EXYNOS4210_EXT_GIC_CPU_GET_OFFSET(n) \
  37. ((n) * EXYNOS4210_EXT_GIC_PER_CPU_OFFSET)
  38. #define EXYNOS4210_EXT_GIC_DIST_GET_OFFSET(n) \
  39. ((n) * EXYNOS4210_EXT_GIC_PER_CPU_OFFSET)
  40. #define EXYNOS4210_GIC_CPU_REGION_SIZE 0x100
  41. #define EXYNOS4210_GIC_DIST_REGION_SIZE 0x1000
  42. static void exynos4210_gic_set_irq(void *opaque, int irq, int level)
  43. {
  44. Exynos4210GicState *s = (Exynos4210GicState *)opaque;
  45. qemu_set_irq(qdev_get_gpio_in(s->gic, irq), level);
  46. }
  47. static void exynos4210_gic_realize(DeviceState *dev, Error **errp)
  48. {
  49. Object *obj = OBJECT(dev);
  50. Exynos4210GicState *s = EXYNOS4210_GIC(obj);
  51. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  52. SysBusDevice *gicbusdev;
  53. uint32_t n = s->num_cpu;
  54. uint32_t i;
  55. s->gic = qdev_new("arm_gic");
  56. qdev_prop_set_uint32(s->gic, "num-cpu", s->num_cpu);
  57. qdev_prop_set_uint32(s->gic, "num-irq", EXYNOS4210_GIC_NIRQ);
  58. gicbusdev = SYS_BUS_DEVICE(s->gic);
  59. sysbus_realize_and_unref(gicbusdev, &error_fatal);
  60. /* Pass through outbound IRQ lines from the GIC */
  61. sysbus_pass_irq(sbd, gicbusdev);
  62. /* Pass through inbound GPIO lines to the GIC */
  63. qdev_init_gpio_in(dev, exynos4210_gic_set_irq,
  64. EXYNOS4210_GIC_NIRQ - 32);
  65. memory_region_init(&s->cpu_container, obj, "exynos4210-cpu-container",
  66. EXYNOS4210_EXT_GIC_CPU_REGION_SIZE);
  67. memory_region_init(&s->dist_container, obj, "exynos4210-dist-container",
  68. EXYNOS4210_EXT_GIC_DIST_REGION_SIZE);
  69. /*
  70. * This clues in gcc that our on-stack buffers do, in fact have
  71. * enough room for the cpu numbers. gcc 9.2.1 on 32-bit x86
  72. * doesn't figure this out, otherwise and gives spurious warnings.
  73. */
  74. assert(n <= EXYNOS4210_GIC_NCPUS);
  75. for (i = 0; i < n; i++) {
  76. g_autofree char *cpu_alias_name = g_strdup_printf("exynos4210-gic-alias_cpu%u", i);
  77. g_autofree char *dist_alias_name = g_strdup_printf("exynos4210-gic-alias_dist%u", i);
  78. /* Map CPU interface per SMP Core */
  79. memory_region_init_alias(&s->cpu_alias[i], obj,
  80. cpu_alias_name,
  81. sysbus_mmio_get_region(gicbusdev, 1),
  82. 0,
  83. EXYNOS4210_GIC_CPU_REGION_SIZE);
  84. memory_region_add_subregion(&s->cpu_container,
  85. EXYNOS4210_EXT_GIC_CPU_GET_OFFSET(i), &s->cpu_alias[i]);
  86. /* Map Distributor per SMP Core */
  87. memory_region_init_alias(&s->dist_alias[i], obj,
  88. dist_alias_name,
  89. sysbus_mmio_get_region(gicbusdev, 0),
  90. 0,
  91. EXYNOS4210_GIC_DIST_REGION_SIZE);
  92. memory_region_add_subregion(&s->dist_container,
  93. EXYNOS4210_EXT_GIC_DIST_GET_OFFSET(i), &s->dist_alias[i]);
  94. }
  95. sysbus_init_mmio(sbd, &s->cpu_container);
  96. sysbus_init_mmio(sbd, &s->dist_container);
  97. }
  98. static const Property exynos4210_gic_properties[] = {
  99. DEFINE_PROP_UINT32("num-cpu", Exynos4210GicState, num_cpu, 1),
  100. };
  101. static void exynos4210_gic_class_init(ObjectClass *klass, void *data)
  102. {
  103. DeviceClass *dc = DEVICE_CLASS(klass);
  104. device_class_set_props(dc, exynos4210_gic_properties);
  105. dc->realize = exynos4210_gic_realize;
  106. }
  107. static const TypeInfo exynos4210_gic_info = {
  108. .name = TYPE_EXYNOS4210_GIC,
  109. .parent = TYPE_SYS_BUS_DEVICE,
  110. .instance_size = sizeof(Exynos4210GicState),
  111. .class_init = exynos4210_gic_class_init,
  112. };
  113. static void exynos4210_gic_register_types(void)
  114. {
  115. type_register_static(&exynos4210_gic_info);
  116. }
  117. type_init(exynos4210_gic_register_types)