exynos4210_combiner.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. //#define DEBUG_COMBINER
  37. #ifdef DEBUG_COMBINER
  38. #define DPRINTF(fmt, ...) \
  39. do { fprintf(stdout, "COMBINER: [%s:%d] " fmt, __func__ , __LINE__, \
  40. ## __VA_ARGS__); } while (0)
  41. #else
  42. #define DPRINTF(fmt, ...) do {} while (0)
  43. #endif
  44. #define IIC_NGRP 64 /* Internal Interrupt Combiner
  45. Groups number */
  46. #define IIC_NIRQ (IIC_NGRP * 8)/* Internal Interrupt Combiner
  47. Interrupts number */
  48. #define IIC_REGION_SIZE 0x108 /* Size of memory mapped region */
  49. #define IIC_REGSET_SIZE 0x41
  50. /*
  51. * State for each output signal of internal combiner
  52. */
  53. typedef struct CombinerGroupState {
  54. uint8_t src_mask; /* 1 - source enabled, 0 - disabled */
  55. uint8_t src_pending; /* Pending source interrupts before masking */
  56. } CombinerGroupState;
  57. #define TYPE_EXYNOS4210_COMBINER "exynos4210.combiner"
  58. #define EXYNOS4210_COMBINER(obj) \
  59. OBJECT_CHECK(Exynos4210CombinerState, (obj), TYPE_EXYNOS4210_COMBINER)
  60. typedef 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. } Exynos4210CombinerState;
  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. return 0;
  202. }
  203. return val;
  204. }
  205. static void exynos4210_combiner_update(void *opaque, uint8_t group_n)
  206. {
  207. struct Exynos4210CombinerState *s =
  208. (struct Exynos4210CombinerState *)opaque;
  209. /* Send interrupt if needed */
  210. if (s->group[group_n].src_mask & s->group[group_n].src_pending) {
  211. #ifdef DEBUG_COMBINER
  212. if (group_n != 26) {
  213. /* skip uart */
  214. DPRINTF("%s raise IRQ[%d]\n", s->external ? "EXT" : "INT", group_n);
  215. }
  216. #endif
  217. /* Set Combiner interrupt pending status after masking */
  218. if (group_n >= 32) {
  219. s->icipsr[1] |= 1 << (group_n - 32);
  220. } else {
  221. s->icipsr[0] |= 1 << group_n;
  222. }
  223. qemu_irq_raise(s->output_irq[group_n]);
  224. } else {
  225. #ifdef DEBUG_COMBINER
  226. if (group_n != 26) {
  227. /* skip uart */
  228. DPRINTF("%s lower IRQ[%d]\n", s->external ? "EXT" : "INT", group_n);
  229. }
  230. #endif
  231. /* Set Combiner interrupt pending status after masking */
  232. if (group_n >= 32) {
  233. s->icipsr[1] &= ~(1 << (group_n - 32));
  234. } else {
  235. s->icipsr[0] &= ~(1 << group_n);
  236. }
  237. qemu_irq_lower(s->output_irq[group_n]);
  238. }
  239. }
  240. static void exynos4210_combiner_write(void *opaque, hwaddr offset,
  241. uint64_t val, unsigned size)
  242. {
  243. struct Exynos4210CombinerState *s =
  244. (struct Exynos4210CombinerState *)opaque;
  245. uint32_t req_quad_base_n; /* Base of registers quad. Multiply it by 4 and
  246. get a start of corresponding group quad */
  247. uint32_t grp_quad_base_n; /* Base of group quad */
  248. uint32_t reg_n; /* Register number inside the quad */
  249. req_quad_base_n = offset >> 4;
  250. grp_quad_base_n = req_quad_base_n << 2;
  251. reg_n = (offset - (req_quad_base_n << 4)) >> 2;
  252. if (req_quad_base_n >= IIC_NGRP) {
  253. hw_error("exynos4210.combiner: unallowed write access at offset 0x"
  254. TARGET_FMT_plx "\n", offset);
  255. return;
  256. }
  257. if (reg_n > 1) {
  258. hw_error("exynos4210.combiner: unallowed write access at offset 0x"
  259. TARGET_FMT_plx "\n", offset);
  260. return;
  261. }
  262. if (offset >> 2 >= IIC_REGSET_SIZE) {
  263. hw_error("exynos4210.combiner: overflow of reg_set by 0x"
  264. TARGET_FMT_plx "offset\n", offset);
  265. }
  266. s->reg_set[offset >> 2] = val;
  267. switch (reg_n) {
  268. /* IIESR */
  269. case 0:
  270. /* FIXME: what if irq is pending, allowed by mask, and we allow it
  271. * again. Interrupt will rise again! */
  272. DPRINTF("%s enable IRQ for groups %d, %d, %d, %d\n",
  273. s->external ? "EXT" : "INT",
  274. grp_quad_base_n,
  275. grp_quad_base_n + 1,
  276. grp_quad_base_n + 2,
  277. grp_quad_base_n + 3);
  278. /* Enable interrupt sources */
  279. s->group[grp_quad_base_n].src_mask |= val & 0xFF;
  280. s->group[grp_quad_base_n + 1].src_mask |= (val & 0xFF00) >> 8;
  281. s->group[grp_quad_base_n + 2].src_mask |= (val & 0xFF0000) >> 16;
  282. s->group[grp_quad_base_n + 3].src_mask |= (val & 0xFF000000) >> 24;
  283. exynos4210_combiner_update(s, grp_quad_base_n);
  284. exynos4210_combiner_update(s, grp_quad_base_n + 1);
  285. exynos4210_combiner_update(s, grp_quad_base_n + 2);
  286. exynos4210_combiner_update(s, grp_quad_base_n + 3);
  287. break;
  288. /* IIECR */
  289. case 1:
  290. DPRINTF("%s disable IRQ for groups %d, %d, %d, %d\n",
  291. s->external ? "EXT" : "INT",
  292. grp_quad_base_n,
  293. grp_quad_base_n + 1,
  294. grp_quad_base_n + 2,
  295. grp_quad_base_n + 3);
  296. /* Disable interrupt sources */
  297. s->group[grp_quad_base_n].src_mask &= ~(val & 0xFF);
  298. s->group[grp_quad_base_n + 1].src_mask &= ~((val & 0xFF00) >> 8);
  299. s->group[grp_quad_base_n + 2].src_mask &= ~((val & 0xFF0000) >> 16);
  300. s->group[grp_quad_base_n + 3].src_mask &= ~((val & 0xFF000000) >> 24);
  301. exynos4210_combiner_update(s, grp_quad_base_n);
  302. exynos4210_combiner_update(s, grp_quad_base_n + 1);
  303. exynos4210_combiner_update(s, grp_quad_base_n + 2);
  304. exynos4210_combiner_update(s, grp_quad_base_n + 3);
  305. break;
  306. default:
  307. hw_error("exynos4210.combiner: unallowed write access at offset 0x"
  308. TARGET_FMT_plx "\n", offset);
  309. break;
  310. }
  311. }
  312. /* Get combiner group and bit from irq number */
  313. static uint8_t get_combiner_group_and_bit(int irq, uint8_t *bit)
  314. {
  315. *bit = irq - ((irq >> 3) << 3);
  316. return irq >> 3;
  317. }
  318. /* Process a change in an external IRQ input. */
  319. static void exynos4210_combiner_handler(void *opaque, int irq, int level)
  320. {
  321. struct Exynos4210CombinerState *s =
  322. (struct Exynos4210CombinerState *)opaque;
  323. uint8_t bit_n, group_n;
  324. group_n = get_combiner_group_and_bit(irq, &bit_n);
  325. if (s->external && group_n >= EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ) {
  326. DPRINTF("%s unallowed IRQ group 0x%x\n", s->external ? "EXT" : "INT"
  327. , group_n);
  328. return;
  329. }
  330. if (level) {
  331. s->group[group_n].src_pending |= 1 << bit_n;
  332. } else {
  333. s->group[group_n].src_pending &= ~(1 << bit_n);
  334. }
  335. exynos4210_combiner_update(s, group_n);
  336. }
  337. static void exynos4210_combiner_reset(DeviceState *d)
  338. {
  339. struct Exynos4210CombinerState *s = (struct Exynos4210CombinerState *)d;
  340. memset(&s->group, 0, sizeof(s->group));
  341. memset(&s->reg_set, 0, sizeof(s->reg_set));
  342. s->reg_set[0xC0 >> 2] = 0x01010101;
  343. s->reg_set[0xC4 >> 2] = 0x01010101;
  344. s->reg_set[0xD0 >> 2] = 0x01010101;
  345. s->reg_set[0xD4 >> 2] = 0x01010101;
  346. }
  347. static const MemoryRegionOps exynos4210_combiner_ops = {
  348. .read = exynos4210_combiner_read,
  349. .write = exynos4210_combiner_write,
  350. .endianness = DEVICE_NATIVE_ENDIAN,
  351. };
  352. /*
  353. * Internal Combiner initialization.
  354. */
  355. static void exynos4210_combiner_init(Object *obj)
  356. {
  357. DeviceState *dev = DEVICE(obj);
  358. Exynos4210CombinerState *s = EXYNOS4210_COMBINER(obj);
  359. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  360. unsigned int i;
  361. /* Allocate general purpose input signals and connect a handler to each of
  362. * them */
  363. qdev_init_gpio_in(dev, exynos4210_combiner_handler, IIC_NIRQ);
  364. /* Connect SysBusDev irqs to device specific irqs */
  365. for (i = 0; i < IIC_NGRP; i++) {
  366. sysbus_init_irq(sbd, &s->output_irq[i]);
  367. }
  368. memory_region_init_io(&s->iomem, obj, &exynos4210_combiner_ops, s,
  369. "exynos4210-combiner", IIC_REGION_SIZE);
  370. sysbus_init_mmio(sbd, &s->iomem);
  371. }
  372. static Property exynos4210_combiner_properties[] = {
  373. DEFINE_PROP_UINT32("external", Exynos4210CombinerState, external, 0),
  374. DEFINE_PROP_END_OF_LIST(),
  375. };
  376. static void exynos4210_combiner_class_init(ObjectClass *klass, void *data)
  377. {
  378. DeviceClass *dc = DEVICE_CLASS(klass);
  379. dc->reset = exynos4210_combiner_reset;
  380. device_class_set_props(dc, exynos4210_combiner_properties);
  381. dc->vmsd = &vmstate_exynos4210_combiner;
  382. }
  383. static const TypeInfo exynos4210_combiner_info = {
  384. .name = TYPE_EXYNOS4210_COMBINER,
  385. .parent = TYPE_SYS_BUS_DEVICE,
  386. .instance_size = sizeof(Exynos4210CombinerState),
  387. .instance_init = exynos4210_combiner_init,
  388. .class_init = exynos4210_combiner_class_init,
  389. };
  390. static void exynos4210_combiner_register_types(void)
  391. {
  392. type_register_static(&exynos4210_combiner_info);
  393. }
  394. type_init(exynos4210_combiner_register_types)