a9gtimer.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Global peripheral timer block for ARM A9MP
  3. *
  4. * (C) 2013 Xilinx Inc.
  5. *
  6. * Written by François LEGAL
  7. * Written by Peter Crosthwaite <peter.crosthwaite@xilinx.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your 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. See the
  17. * 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. #ifndef A9GTIMER_H
  23. #define A9GTIMER_H
  24. #include "hw/sysbus.h"
  25. #include "qom/object.h"
  26. #define A9_GTIMER_MAX_CPUS 4
  27. #define TYPE_A9_GTIMER "arm.cortex-a9-global-timer"
  28. OBJECT_DECLARE_SIMPLE_TYPE(A9GTimerState, A9_GTIMER)
  29. #define R_COUNTER_LO 0x00
  30. #define R_COUNTER_HI 0x04
  31. #define R_CONTROL 0x08
  32. #define R_CONTROL_TIMER_ENABLE (1 << 0)
  33. #define R_CONTROL_COMP_ENABLE (1 << 1)
  34. #define R_CONTROL_IRQ_ENABLE (1 << 2)
  35. #define R_CONTROL_AUTO_INCREMENT (1 << 3)
  36. #define R_CONTROL_PRESCALER_SHIFT 8
  37. #define R_CONTROL_PRESCALER_LEN 8
  38. #define R_CONTROL_PRESCALER_MASK (((1 << R_CONTROL_PRESCALER_LEN) - 1) << \
  39. R_CONTROL_PRESCALER_SHIFT)
  40. #define R_CONTROL_BANKED (R_CONTROL_COMP_ENABLE | \
  41. R_CONTROL_IRQ_ENABLE | \
  42. R_CONTROL_AUTO_INCREMENT)
  43. #define R_CONTROL_NEEDS_SYNC (R_CONTROL_TIMER_ENABLE | \
  44. R_CONTROL_PRESCALER_MASK)
  45. #define R_INTERRUPT_STATUS 0x0C
  46. #define R_COMPARATOR_LO 0x10
  47. #define R_COMPARATOR_HI 0x14
  48. #define R_AUTO_INCREMENT 0x18
  49. typedef struct A9GTimerPerCPU A9GTimerPerCPU;
  50. struct A9GTimerPerCPU {
  51. A9GTimerState *parent;
  52. uint32_t control; /* only per cpu banked bits valid */
  53. uint64_t compare;
  54. uint32_t status;
  55. uint32_t inc;
  56. MemoryRegion iomem;
  57. qemu_irq irq; /* PPI interrupts */
  58. };
  59. struct A9GTimerState {
  60. /*< private >*/
  61. SysBusDevice parent_obj;
  62. /*< public >*/
  63. MemoryRegion iomem;
  64. /* static props */
  65. uint32_t num_cpu;
  66. QEMUTimer *timer;
  67. uint64_t counter; /* current timer value */
  68. uint64_t ref_counter;
  69. uint64_t cpu_ref_time; /* the cpu time as of last update of ref_counter */
  70. uint32_t control; /* only non per cpu banked bits valid */
  71. A9GTimerPerCPU per_cpu[A9_GTIMER_MAX_CPUS];
  72. };
  73. typedef struct A9GTimerUpdate {
  74. uint64_t now;
  75. uint64_t new;
  76. } A9GTimerUpdate;
  77. #endif /* A9GTIMER_H */