riscv_aplic.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * RISC-V APLIC (Advanced Platform Level Interrupt Controller) interface
  3. *
  4. * Copyright (c) 2021 Western Digital Corporation or its affiliates.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2 or later, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef HW_RISCV_APLIC_H
  19. #define HW_RISCV_APLIC_H
  20. #include "hw/sysbus.h"
  21. #include "qom/object.h"
  22. #define TYPE_RISCV_APLIC "riscv.aplic"
  23. typedef struct RISCVAPLICState RISCVAPLICState;
  24. DECLARE_INSTANCE_CHECKER(RISCVAPLICState, RISCV_APLIC, TYPE_RISCV_APLIC)
  25. #define APLIC_MIN_SIZE 0x4000
  26. #define APLIC_SIZE_ALIGN(__x) (((__x) + (APLIC_MIN_SIZE - 1)) & \
  27. ~(APLIC_MIN_SIZE - 1))
  28. #define APLIC_SIZE(__num_harts) (APLIC_MIN_SIZE + \
  29. APLIC_SIZE_ALIGN(32 * (__num_harts)))
  30. struct RISCVAPLICState {
  31. /*< private >*/
  32. SysBusDevice parent_obj;
  33. qemu_irq *external_irqs;
  34. /*< public >*/
  35. MemoryRegion mmio;
  36. uint32_t bitfield_words;
  37. uint32_t domaincfg;
  38. uint32_t mmsicfgaddr;
  39. uint32_t mmsicfgaddrH;
  40. uint32_t smsicfgaddr;
  41. uint32_t smsicfgaddrH;
  42. uint32_t genmsi;
  43. uint32_t *sourcecfg;
  44. uint32_t *state;
  45. uint32_t *target;
  46. uint32_t *idelivery;
  47. uint32_t *iforce;
  48. uint32_t *ithreshold;
  49. /* topology */
  50. #define QEMU_APLIC_MAX_CHILDREN 16
  51. struct RISCVAPLICState *parent;
  52. struct RISCVAPLICState *children[QEMU_APLIC_MAX_CHILDREN];
  53. uint16_t num_children;
  54. /* config */
  55. uint32_t aperture_size;
  56. uint32_t hartid_base;
  57. uint32_t num_harts;
  58. uint32_t iprio_mask;
  59. uint32_t num_irqs;
  60. bool msimode;
  61. bool mmode;
  62. /* To support KVM aia=aplic-imsic with irqchip split mode */
  63. bool kvm_splitmode;
  64. uint32_t kvm_msicfgaddr;
  65. uint32_t kvm_msicfgaddrH;
  66. };
  67. void riscv_aplic_add_child(DeviceState *parent, DeviceState *child);
  68. bool riscv_is_kvm_aia_aplic_imsic(bool msimode);
  69. bool riscv_use_emulated_aplic(bool msimode);
  70. void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr);
  71. DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size,
  72. uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources,
  73. uint32_t iprio_bits, bool msimode, bool mmode, DeviceState *parent);
  74. #endif