exynos4210_combiner.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /*
  2. * Samsung exynos4210 Interrupt Combiner
  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. /*
  23. * Exynos4210 Combiner represents an OR gate for SOC's IRQ lines. It combines
  24. * IRQ sources into groups and provides signal output to GIC from each group. It
  25. * is driven by common mask and enable/disable logic. Take a note that not all
  26. * IRQs are passed to GIC through Combiner.
  27. */
  28. #include "qemu/osdep.h"
  29. #include "hw/sysbus.h"
  30. #include "migration/vmstate.h"
  31. #include "qemu/module.h"
  32. #include "hw/arm/exynos4210.h"
  33. #include "hw/hw.h"
  34. #include "hw/irq.h"
  35. #include "hw/qdev-properties.h"
  36. #include "qom/object.h"
  37. //#define DEBUG_COMBINER
  38. #ifdef DEBUG_COMBINER
  39. #define DPRINTF(fmt, ...) \
  40. do { fprintf(stdout, "COMBINER: [%s:%d] " fmt, __func__ , __LINE__, \
  41. ## __VA_ARGS__); } while (0)
  42. #else
  43. #define DPRINTF(fmt, ...) do {} while (0)
  44. #endif
  45. #define IIC_NGRP 64 /* Internal Interrupt Combiner
  46. Groups number */
  47. #define IIC_NIRQ (IIC_NGRP * 8)/* Internal Interrupt Combiner
  48. Interrupts number */
  49. #define IIC_REGION_SIZE 0x108 /* Size of memory mapped region */
  50. #define IIC_REGSET_SIZE 0x41
  51. /*
  52. * State for each output signal of internal combiner
  53. */
  54. typedef struct CombinerGroupState {
  55. uint8_t src_mask; /* 1 - source enabled, 0 - disabled */
  56. uint8_t src_pending; /* Pending source interrupts before masking */
  57. } CombinerGroupState;
  58. #define TYPE_EXYNOS4210_COMBINER "exynos4210.combiner"
  59. OBJECT_DECLARE_SIMPLE_TYPE(Exynos4210CombinerState, EXYNOS4210_COMBINER)
  60. struct Exynos4210CombinerState {
  61. SysBusDevice parent_obj;
  62. MemoryRegion iomem;
  63. struct CombinerGroupState group[IIC_NGRP];
  64. uint32_t reg_set[IIC_REGSET_SIZE];
  65. uint32_t icipsr[2];
  66. uint32_t external; /* 1 means that this combiner is external */
  67. qemu_irq output_irq[IIC_NGRP];
  68. };
  69. static const VMStateDescription vmstate_exynos4210_combiner_group_state = {
  70. .name = "exynos4210.combiner.groupstate",
  71. .version_id = 1,
  72. .minimum_version_id = 1,
  73. .fields = (VMStateField[]) {
  74. VMSTATE_UINT8(src_mask, CombinerGroupState),
  75. VMSTATE_UINT8(src_pending, CombinerGroupState),
  76. VMSTATE_END_OF_LIST()
  77. }
  78. };
  79. static const VMStateDescription vmstate_exynos4210_combiner = {
  80. .name = "exynos4210.combiner",
  81. .version_id = 1,
  82. .minimum_version_id = 1,
  83. .fields = (VMStateField[]) {
  84. VMSTATE_STRUCT_ARRAY(group, Exynos4210CombinerState, IIC_NGRP, 0,
  85. vmstate_exynos4210_combiner_group_state, CombinerGroupState),
  86. VMSTATE_UINT32_ARRAY(reg_set, Exynos4210CombinerState,
  87. IIC_REGSET_SIZE),
  88. VMSTATE_UINT32_ARRAY(icipsr, Exynos4210CombinerState, 2),
  89. VMSTATE_UINT32(external, Exynos4210CombinerState),
  90. VMSTATE_END_OF_LIST()
  91. }
  92. };
  93. /*
  94. * Get Combiner input GPIO into irqs structure
  95. */
  96. void exynos4210_combiner_get_gpioin(Exynos4210Irq *irqs, DeviceState *dev,
  97. int ext)
  98. {
  99. int n;
  100. int bit;
  101. int max;
  102. qemu_irq *irq;
  103. max = ext ? EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ :
  104. EXYNOS4210_MAX_INT_COMBINER_IN_IRQ;
  105. irq = ext ? irqs->ext_combiner_irq : irqs->int_combiner_irq;
  106. /*
  107. * Some IRQs of Int/External Combiner are going to two Combiners groups,
  108. * so let split them.
  109. */
  110. for (n = 0; n < max; n++) {
  111. bit = EXYNOS4210_COMBINER_GET_BIT_NUM(n);
  112. switch (n) {
  113. /* MDNIE_LCD1 INTG1 */
  114. case EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 0) ...
  115. EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 3):
  116. irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
  117. irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(0, bit + 4)]);
  118. continue;
  119. /* TMU INTG3 */
  120. case EXYNOS4210_COMBINER_GET_IRQ_NUM(3, 4):
  121. irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
  122. irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(2, bit)]);
  123. continue;
  124. /* LCD1 INTG12 */
  125. case EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 0) ...
  126. EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 3):
  127. irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
  128. irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(11, bit + 4)]);
  129. continue;
  130. /* Multi-Core Timer INTG12 */
  131. case EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 4) ...
  132. EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 8):
  133. irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
  134. irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit + 4)]);
  135. continue;
  136. /* Multi-Core Timer INTG35 */
  137. case EXYNOS4210_COMBINER_GET_IRQ_NUM(35, 4) ...
  138. EXYNOS4210_COMBINER_GET_IRQ_NUM(35, 8):
  139. irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
  140. irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit + 4)]);
  141. continue;
  142. /* Multi-Core Timer INTG51 */
  143. case EXYNOS4210_COMBINER_GET_IRQ_NUM(51, 4) ...
  144. EXYNOS4210_COMBINER_GET_IRQ_NUM(51, 8):
  145. irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
  146. irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit + 4)]);
  147. continue;
  148. /* Multi-Core Timer INTG53 */
  149. case EXYNOS4210_COMBINER_GET_IRQ_NUM(53, 4) ...
  150. EXYNOS4210_COMBINER_GET_IRQ_NUM(53, 8):
  151. irq[n] = qemu_irq_split(qdev_get_gpio_in(dev, n),
  152. irq[EXYNOS4210_COMBINER_GET_IRQ_NUM(1, bit + 4)]);
  153. continue;
  154. }
  155. irq[n] = qdev_get_gpio_in(dev, n);
  156. }
  157. }
  158. static uint64_t
  159. exynos4210_combiner_read(void *opaque, hwaddr offset, unsigned size)
  160. {
  161. struct Exynos4210CombinerState *s =
  162. (struct Exynos4210CombinerState *)opaque;
  163. uint32_t req_quad_base_n; /* Base of registers quad. Multiply it by 4 and
  164. get a start of corresponding group quad */
  165. uint32_t grp_quad_base_n; /* Base of group quad */
  166. uint32_t reg_n; /* Register number inside the quad */
  167. uint32_t val;
  168. req_quad_base_n = offset >> 4;
  169. grp_quad_base_n = req_quad_base_n << 2;
  170. reg_n = (offset - (req_quad_base_n << 4)) >> 2;
  171. if (req_quad_base_n >= IIC_NGRP) {
  172. /* Read of ICIPSR register */
  173. return s->icipsr[reg_n];
  174. }
  175. val = 0;
  176. switch (reg_n) {
  177. /* IISTR */
  178. case 2:
  179. val |= s->group[grp_quad_base_n].src_pending;
  180. val |= s->group[grp_quad_base_n + 1].src_pending << 8;
  181. val |= s->group[grp_quad_base_n + 2].src_pending << 16;
  182. val |= s->group[grp_quad_base_n + 3].src_pending << 24;
  183. break;
  184. /* IIMSR */
  185. case 3:
  186. val |= s->group[grp_quad_base_n].src_mask &
  187. s->group[grp_quad_base_n].src_pending;
  188. val |= (s->group[grp_quad_base_n + 1].src_mask &
  189. s->group[grp_quad_base_n + 1].src_pending) << 8;
  190. val |= (s->group[grp_quad_base_n + 2].src_mask &
  191. s->group[grp_quad_base_n + 2].src_pending) << 16;
  192. val |= (s->group[grp_quad_base_n + 3].src_mask &
  193. s->group[grp_quad_base_n + 3].src_pending) << 24;
  194. break;
  195. default:
  196. if (offset >> 2 >= IIC_REGSET_SIZE) {
  197. hw_error("exynos4210.combiner: overflow of reg_set by 0x"
  198. TARGET_FMT_plx "offset\n", offset);
  199. }
  200. val = s->reg_set[offset >> 2];
  201. }
  202. return val;
  203. }
  204. static void exynos4210_combiner_update(void *opaque, uint8_t group_n)
  205. {
  206. struct Exynos4210CombinerState *s =
  207. (struct Exynos4210CombinerState *)opaque;
  208. /* Send interrupt if needed */
  209. if (s->group[group_n].src_mask & s->group[group_n].src_pending) {
  210. #ifdef DEBUG_COMBINER
  211. if (group_n != 26) {
  212. /* skip uart */
  213. DPRINTF("%s raise IRQ[%d]\n", s->external ? "EXT" : "INT", group_n);
  214. }
  215. #endif
  216. /* Set Combiner interrupt pending status after masking */
  217. if (group_n >= 32) {
  218. s->icipsr[1] |= 1 << (group_n - 32);
  219. } else {
  220. s->icipsr[0] |= 1 << group_n;
  221. }
  222. qemu_irq_raise(s->output_irq[group_n]);
  223. } else {
  224. #ifdef DEBUG_COMBINER
  225. if (group_n != 26) {
  226. /* skip uart */
  227. DPRINTF("%s lower IRQ[%d]\n", s->external ? "EXT" : "INT", group_n);
  228. }
  229. #endif
  230. /* Set Combiner interrupt pending status after masking */
  231. if (group_n >= 32) {
  232. s->icipsr[1] &= ~(1 << (group_n - 32));
  233. } else {
  234. s->icipsr[0] &= ~(1 << group_n);
  235. }
  236. qemu_irq_lower(s->output_irq[group_n]);
  237. }
  238. }
  239. static void exynos4210_combiner_write(void *opaque, hwaddr offset,
  240. uint64_t val, unsigned size)
  241. {
  242. struct Exynos4210CombinerState *s =
  243. (struct Exynos4210CombinerState *)opaque;
  244. uint32_t req_quad_base_n; /* Base of registers quad. Multiply it by 4 and
  245. get a start of corresponding group quad */
  246. uint32_t grp_quad_base_n; /* Base of group quad */
  247. uint32_t reg_n; /* Register number inside the quad */
  248. req_quad_base_n = offset >> 4;
  249. grp_quad_base_n = req_quad_base_n << 2;
  250. reg_n = (offset - (req_quad_base_n << 4)) >> 2;
  251. if (req_quad_base_n >= IIC_NGRP) {
  252. hw_error("exynos4210.combiner: unallowed write access at offset 0x"
  253. TARGET_FMT_plx "\n", offset);
  254. return;
  255. }
  256. if (reg_n > 1) {
  257. hw_error("exynos4210.combiner: unallowed write access at offset 0x"
  258. TARGET_FMT_plx "\n", offset);
  259. return;
  260. }
  261. if (offset >> 2 >= IIC_REGSET_SIZE) {
  262. hw_error("exynos4210.combiner: overflow of reg_set by 0x"
  263. TARGET_FMT_plx "offset\n", offset);
  264. }
  265. s->reg_set[offset >> 2] = val;
  266. switch (reg_n) {
  267. /* IIESR */
  268. case 0:
  269. /* FIXME: what if irq is pending, allowed by mask, and we allow it
  270. * again. Interrupt will rise again! */
  271. DPRINTF("%s enable IRQ for groups %d, %d, %d, %d\n",
  272. s->external ? "EXT" : "INT",
  273. grp_quad_base_n,
  274. grp_quad_base_n + 1,
  275. grp_quad_base_n + 2,
  276. grp_quad_base_n + 3);
  277. /* Enable interrupt sources */
  278. s->group[grp_quad_base_n].src_mask |= val & 0xFF;
  279. s->group[grp_quad_base_n + 1].src_mask |= (val & 0xFF00) >> 8;
  280. s->group[grp_quad_base_n + 2].src_mask |= (val & 0xFF0000) >> 16;
  281. s->group[grp_quad_base_n + 3].src_mask |= (val & 0xFF000000) >> 24;
  282. exynos4210_combiner_update(s, grp_quad_base_n);
  283. exynos4210_combiner_update(s, grp_quad_base_n + 1);
  284. exynos4210_combiner_update(s, grp_quad_base_n + 2);
  285. exynos4210_combiner_update(s, grp_quad_base_n + 3);
  286. break;
  287. /* IIECR */
  288. case 1:
  289. DPRINTF("%s disable IRQ for groups %d, %d, %d, %d\n",
  290. s->external ? "EXT" : "INT",
  291. grp_quad_base_n,
  292. grp_quad_base_n + 1,
  293. grp_quad_base_n + 2,
  294. grp_quad_base_n + 3);
  295. /* Disable interrupt sources */
  296. s->group[grp_quad_base_n].src_mask &= ~(val & 0xFF);
  297. s->group[grp_quad_base_n + 1].src_mask &= ~((val & 0xFF00) >> 8);
  298. s->group[grp_quad_base_n + 2].src_mask &= ~((val & 0xFF0000) >> 16);
  299. s->group[grp_quad_base_n + 3].src_mask &= ~((val & 0xFF000000) >> 24);
  300. exynos4210_combiner_update(s, grp_quad_base_n);
  301. exynos4210_combiner_update(s, grp_quad_base_n + 1);
  302. exynos4210_combiner_update(s, grp_quad_base_n + 2);
  303. exynos4210_combiner_update(s, grp_quad_base_n + 3);
  304. break;
  305. default:
  306. hw_error("exynos4210.combiner: unallowed write access at offset 0x"
  307. TARGET_FMT_plx "\n", offset);
  308. break;
  309. }
  310. }
  311. /* Get combiner group and bit from irq number */
  312. static uint8_t get_combiner_group_and_bit(int irq, uint8_t *bit)
  313. {
  314. *bit = irq - ((irq >> 3) << 3);
  315. return irq >> 3;
  316. }
  317. /* Process a change in an external IRQ input. */
  318. static void exynos4210_combiner_handler(void *opaque, int irq, int level)
  319. {
  320. struct Exynos4210CombinerState *s =
  321. (struct Exynos4210CombinerState *)opaque;
  322. uint8_t bit_n, group_n;
  323. group_n = get_combiner_group_and_bit(irq, &bit_n);
  324. if (s->external && group_n >= EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ) {
  325. DPRINTF("%s unallowed IRQ group 0x%x\n", s->external ? "EXT" : "INT"
  326. , group_n);
  327. return;
  328. }
  329. if (level) {
  330. s->group[group_n].src_pending |= 1 << bit_n;
  331. } else {
  332. s->group[group_n].src_pending &= ~(1 << bit_n);
  333. }
  334. exynos4210_combiner_update(s, group_n);
  335. }
  336. static void exynos4210_combiner_reset(DeviceState *d)
  337. {
  338. struct Exynos4210CombinerState *s = (struct Exynos4210CombinerState *)d;
  339. memset(&s->group, 0, sizeof(s->group));
  340. memset(&s->reg_set, 0, sizeof(s->reg_set));
  341. s->reg_set[0xC0 >> 2] = 0x01010101;
  342. s->reg_set[0xC4 >> 2] = 0x01010101;
  343. s->reg_set[0xD0 >> 2] = 0x01010101;
  344. s->reg_set[0xD4 >> 2] = 0x01010101;
  345. }
  346. static const MemoryRegionOps exynos4210_combiner_ops = {
  347. .read = exynos4210_combiner_read,
  348. .write = exynos4210_combiner_write,
  349. .endianness = DEVICE_NATIVE_ENDIAN,
  350. };
  351. /*
  352. * Internal Combiner initialization.
  353. */
  354. static void exynos4210_combiner_init(Object *obj)
  355. {
  356. DeviceState *dev = DEVICE(obj);
  357. Exynos4210CombinerState *s = EXYNOS4210_COMBINER(obj);
  358. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  359. unsigned int i;
  360. /* Allocate general purpose input signals and connect a handler to each of
  361. * them */
  362. qdev_init_gpio_in(dev, exynos4210_combiner_handler, IIC_NIRQ);
  363. /* Connect SysBusDev irqs to device specific irqs */
  364. for (i = 0; i < IIC_NGRP; i++) {
  365. sysbus_init_irq(sbd, &s->output_irq[i]);
  366. }
  367. memory_region_init_io(&s->iomem, obj, &exynos4210_combiner_ops, s,
  368. "exynos4210-combiner", IIC_REGION_SIZE);
  369. sysbus_init_mmio(sbd, &s->iomem);
  370. }
  371. static Property exynos4210_combiner_properties[] = {
  372. DEFINE_PROP_UINT32("external", Exynos4210CombinerState, external, 0),
  373. DEFINE_PROP_END_OF_LIST(),
  374. };
  375. static void exynos4210_combiner_class_init(ObjectClass *klass, void *data)
  376. {
  377. DeviceClass *dc = DEVICE_CLASS(klass);
  378. dc->reset = exynos4210_combiner_reset;
  379. device_class_set_props(dc, exynos4210_combiner_properties);
  380. dc->vmsd = &vmstate_exynos4210_combiner;
  381. }
  382. static const TypeInfo exynos4210_combiner_info = {
  383. .name = TYPE_EXYNOS4210_COMBINER,
  384. .parent = TYPE_SYS_BUS_DEVICE,
  385. .instance_size = sizeof(Exynos4210CombinerState),
  386. .instance_init = exynos4210_combiner_init,
  387. .class_init = exynos4210_combiner_class_init,
  388. };
  389. static void exynos4210_combiner_register_types(void)
  390. {
  391. type_register_static(&exynos4210_combiner_info);
  392. }
  393. type_init(exynos4210_combiner_register_types)