cmsdk-apb-dualtimer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * ARM CMSDK APB dual-timer emulation
  3. *
  4. * Copyright (c) 2018 Linaro Limited
  5. * Written by Peter Maydell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 or
  9. * (at your option) any later version.
  10. */
  11. /*
  12. * This is a model of the "APB dual-input timer" which is part of the Cortex-M
  13. * System Design Kit (CMSDK) and documented in the Cortex-M System
  14. * Design Kit Technical Reference Manual (ARM DDI0479C):
  15. * https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit
  16. *
  17. * QEMU interface:
  18. * + Clock input "TIMCLK": clock (for both timers)
  19. * + sysbus MMIO region 0: the register bank
  20. * + sysbus IRQ 0: combined timer interrupt TIMINTC
  21. * + sysbus IRO 1: timer block 1 interrupt TIMINT1
  22. * + sysbus IRQ 2: timer block 2 interrupt TIMINT2
  23. */
  24. #ifndef CMSDK_APB_DUALTIMER_H
  25. #define CMSDK_APB_DUALTIMER_H
  26. #include "hw/sysbus.h"
  27. #include "hw/ptimer.h"
  28. #include "hw/clock.h"
  29. #include "qom/object.h"
  30. #define TYPE_CMSDK_APB_DUALTIMER "cmsdk-apb-dualtimer"
  31. OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBDualTimer, CMSDK_APB_DUALTIMER)
  32. /* One of the two identical timer modules in the dual-timer module */
  33. typedef struct CMSDKAPBDualTimerModule {
  34. CMSDKAPBDualTimer *parent;
  35. struct ptimer_state *timer;
  36. qemu_irq timerint;
  37. /*
  38. * We must track the guest LOAD and VALUE register state by hand
  39. * rather than leaving this state only in the ptimer limit/count,
  40. * because if CONTROL.SIZE is 0 then only the low 16 bits of the
  41. * counter actually counts, but the high half is still guest
  42. * accessible.
  43. */
  44. uint32_t load;
  45. uint32_t value;
  46. uint32_t control;
  47. uint32_t intstatus;
  48. } CMSDKAPBDualTimerModule;
  49. #define CMSDK_APB_DUALTIMER_NUM_MODULES 2
  50. struct CMSDKAPBDualTimer {
  51. /*< private >*/
  52. SysBusDevice parent_obj;
  53. /*< public >*/
  54. MemoryRegion iomem;
  55. qemu_irq timerintc;
  56. Clock *timclk;
  57. CMSDKAPBDualTimerModule timermod[CMSDK_APB_DUALTIMER_NUM_MODULES];
  58. uint32_t timeritcr;
  59. uint32_t timeritop;
  60. };
  61. #endif