openpic.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef OPENPIC_H
  2. #define OPENPIC_H
  3. #include "hw/sysbus.h"
  4. #include "hw/core/cpu.h"
  5. #include "qom/object.h"
  6. #define MAX_CPU 32
  7. #define MAX_MSI 8
  8. #define VID 0x03 /* MPIC version ID */
  9. /* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */
  10. enum {
  11. OPENPIC_OUTPUT_INT = 0, /* IRQ */
  12. OPENPIC_OUTPUT_CINT, /* critical IRQ */
  13. OPENPIC_OUTPUT_MCK, /* Machine check event */
  14. OPENPIC_OUTPUT_DEBUG, /* Unconditional debug event */
  15. OPENPIC_OUTPUT_RESET, /* Core reset event */
  16. OPENPIC_OUTPUT_NB,
  17. };
  18. typedef struct IrqLines { qemu_irq irq[OPENPIC_OUTPUT_NB]; } IrqLines;
  19. #define OPENPIC_MODEL_FSL_MPIC_20 1
  20. #define OPENPIC_MODEL_FSL_MPIC_42 2
  21. #define OPENPIC_MODEL_KEYLARGO 3
  22. #define OPENPIC_MAX_SRC 256
  23. #define OPENPIC_MAX_TMR 4
  24. #define OPENPIC_MAX_IPI 4
  25. #define OPENPIC_MAX_IRQ (OPENPIC_MAX_SRC + OPENPIC_MAX_IPI + \
  26. OPENPIC_MAX_TMR)
  27. /* KeyLargo */
  28. #define KEYLARGO_MAX_CPU 4
  29. #define KEYLARGO_MAX_EXT 64
  30. #define KEYLARGO_MAX_IPI 4
  31. #define KEYLARGO_MAX_IRQ (64 + KEYLARGO_MAX_IPI)
  32. #define KEYLARGO_MAX_TMR 0
  33. #define KEYLARGO_IPI_IRQ (KEYLARGO_MAX_EXT) /* First IPI IRQ */
  34. /* Timers don't exist but this makes the code happy... */
  35. #define KEYLARGO_TMR_IRQ (KEYLARGO_IPI_IRQ + KEYLARGO_MAX_IPI)
  36. typedef struct FslMpicInfo {
  37. int max_ext;
  38. } FslMpicInfo;
  39. typedef enum IRQType {
  40. IRQ_TYPE_NORMAL = 0,
  41. IRQ_TYPE_FSLINT, /* FSL internal interrupt -- level only */
  42. IRQ_TYPE_FSLSPECIAL, /* FSL timer/IPI interrupt, edge, no polarity */
  43. } IRQType;
  44. /*
  45. * Round up to the nearest 64 IRQs so that the queue length
  46. * won't change when moving between 32 and 64 bit hosts.
  47. */
  48. #define IRQQUEUE_SIZE_BITS ROUND_UP(OPENPIC_MAX_IRQ, 64)
  49. typedef struct IRQQueue {
  50. unsigned long *queue;
  51. int32_t queue_size; /* Only used for VMSTATE_BITMAP */
  52. int next;
  53. int priority;
  54. } IRQQueue;
  55. typedef struct IRQSource {
  56. uint32_t ivpr; /* IRQ vector/priority register */
  57. uint32_t idr; /* IRQ destination register */
  58. uint32_t destmask; /* bitmap of CPU destinations */
  59. int last_cpu;
  60. int output; /* IRQ level, e.g. OPENPIC_OUTPUT_INT */
  61. int pending; /* TRUE if IRQ is pending */
  62. IRQType type;
  63. bool level:1; /* level-triggered */
  64. bool nomask:1; /* critical interrupts ignore mask on some FSL MPICs */
  65. } IRQSource;
  66. #define IVPR_MASK_SHIFT 31
  67. #define IVPR_MASK_MASK (1U << IVPR_MASK_SHIFT)
  68. #define IVPR_ACTIVITY_SHIFT 30
  69. #define IVPR_ACTIVITY_MASK (1U << IVPR_ACTIVITY_SHIFT)
  70. #define IVPR_MODE_SHIFT 29
  71. #define IVPR_MODE_MASK (1U << IVPR_MODE_SHIFT)
  72. #define IVPR_POLARITY_SHIFT 23
  73. #define IVPR_POLARITY_MASK (1U << IVPR_POLARITY_SHIFT)
  74. #define IVPR_SENSE_SHIFT 22
  75. #define IVPR_SENSE_MASK (1U << IVPR_SENSE_SHIFT)
  76. #define IVPR_PRIORITY_MASK (0xFU << 16)
  77. #define IVPR_PRIORITY(_ivprr_) ((int)(((_ivprr_) & IVPR_PRIORITY_MASK) >> 16))
  78. #define IVPR_VECTOR(opp, _ivprr_) ((_ivprr_) & (opp)->vector_mask)
  79. /* IDR[EP/CI] are only for FSL MPIC prior to v4.0 */
  80. #define IDR_EP 0x80000000 /* external pin */
  81. #define IDR_CI 0x40000000 /* critical interrupt */
  82. typedef struct OpenPICTimer {
  83. uint32_t tccr; /* Global timer current count register */
  84. uint32_t tbcr; /* Global timer base count register */
  85. int n_IRQ;
  86. bool qemu_timer_active; /* Is the qemu_timer is running? */
  87. struct QEMUTimer *qemu_timer;
  88. struct OpenPICState *opp; /* Device timer is part of. */
  89. /*
  90. * The QEMU_CLOCK_VIRTUAL time (in ns) corresponding to the last
  91. * current_count written or read, only defined if qemu_timer_active.
  92. */
  93. uint64_t origin_time;
  94. } OpenPICTimer;
  95. typedef struct OpenPICMSI {
  96. uint32_t msir; /* Shared Message Signaled Interrupt Register */
  97. } OpenPICMSI;
  98. typedef struct IRQDest {
  99. int32_t ctpr; /* CPU current task priority */
  100. IRQQueue raised;
  101. IRQQueue servicing;
  102. qemu_irq *irqs;
  103. /* Count of IRQ sources asserting on non-INT outputs */
  104. uint32_t outputs_active[OPENPIC_OUTPUT_NB];
  105. } IRQDest;
  106. #define TYPE_OPENPIC "openpic"
  107. OBJECT_DECLARE_SIMPLE_TYPE(OpenPICState, OPENPIC)
  108. struct OpenPICState {
  109. /*< private >*/
  110. SysBusDevice parent_obj;
  111. /*< public >*/
  112. MemoryRegion mem;
  113. /* Behavior control */
  114. FslMpicInfo *fsl;
  115. uint32_t model;
  116. uint32_t flags;
  117. uint32_t nb_irqs;
  118. uint32_t vid;
  119. uint32_t vir; /* Vendor identification register */
  120. uint32_t vector_mask;
  121. uint32_t tfrr_reset;
  122. uint32_t ivpr_reset;
  123. uint32_t idr_reset;
  124. uint32_t brr1;
  125. uint32_t mpic_mode_mask;
  126. /* Sub-regions */
  127. MemoryRegion sub_io_mem[6];
  128. /* Global registers */
  129. uint32_t frr; /* Feature reporting register */
  130. uint32_t gcr; /* Global configuration register */
  131. uint32_t pir; /* Processor initialization register */
  132. uint32_t spve; /* Spurious vector register */
  133. uint32_t tfrr; /* Timer frequency reporting register */
  134. /* Source registers */
  135. IRQSource src[OPENPIC_MAX_IRQ];
  136. /* Local registers per output pin */
  137. IRQDest dst[MAX_CPU];
  138. uint32_t nb_cpus;
  139. /* Timer registers */
  140. OpenPICTimer timers[OPENPIC_MAX_TMR];
  141. uint32_t max_tmr;
  142. /* Shared MSI registers */
  143. OpenPICMSI msi[MAX_MSI];
  144. uint32_t max_irq;
  145. uint32_t irq_ipi0;
  146. uint32_t irq_tim0;
  147. uint32_t irq_msi;
  148. };
  149. #endif /* OPENPIC_H */