vgic-mmio.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (C) 2015, 2016 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __KVM_ARM_VGIC_MMIO_H__
  17. #define __KVM_ARM_VGIC_MMIO_H__
  18. struct vgic_register_region {
  19. unsigned int reg_offset;
  20. unsigned int len;
  21. unsigned int bits_per_irq;
  22. unsigned int access_flags;
  23. union {
  24. unsigned long (*read)(struct kvm_vcpu *vcpu, gpa_t addr,
  25. unsigned int len);
  26. unsigned long (*its_read)(struct kvm *kvm, struct vgic_its *its,
  27. gpa_t addr, unsigned int len);
  28. };
  29. union {
  30. void (*write)(struct kvm_vcpu *vcpu, gpa_t addr,
  31. unsigned int len, unsigned long val);
  32. void (*its_write)(struct kvm *kvm, struct vgic_its *its,
  33. gpa_t addr, unsigned int len,
  34. unsigned long val);
  35. };
  36. };
  37. extern struct kvm_io_device_ops kvm_io_gic_ops;
  38. #define VGIC_ACCESS_8bit 1
  39. #define VGIC_ACCESS_32bit 2
  40. #define VGIC_ACCESS_64bit 4
  41. /*
  42. * Generate a mask that covers the number of bytes required to address
  43. * up to 1024 interrupts, each represented by <bits> bits. This assumes
  44. * that <bits> is a power of two.
  45. */
  46. #define VGIC_ADDR_IRQ_MASK(bits) (((bits) * 1024 / 8) - 1)
  47. /*
  48. * (addr & mask) gives us the _byte_ offset for the INT ID.
  49. * We multiply this by 8 the get the _bit_ offset, then divide this by
  50. * the number of bits to learn the actual INT ID.
  51. * But instead of a division (which requires a "long long div" implementation),
  52. * we shift by the binary logarithm of <bits>.
  53. * This assumes that <bits> is a power of two.
  54. */
  55. #define VGIC_ADDR_TO_INTID(addr, bits) (((addr) & VGIC_ADDR_IRQ_MASK(bits)) * \
  56. 8 >> ilog2(bits))
  57. /*
  58. * Some VGIC registers store per-IRQ information, with a different number
  59. * of bits per IRQ. For those registers this macro is used.
  60. * The _WITH_LENGTH version instantiates registers with a fixed length
  61. * and is mutually exclusive with the _PER_IRQ version.
  62. */
  63. #define REGISTER_DESC_WITH_BITS_PER_IRQ(off, rd, wr, bpi, acc) \
  64. { \
  65. .reg_offset = off, \
  66. .bits_per_irq = bpi, \
  67. .len = bpi * 1024 / 8, \
  68. .access_flags = acc, \
  69. .read = rd, \
  70. .write = wr, \
  71. }
  72. #define REGISTER_DESC_WITH_LENGTH(off, rd, wr, length, acc) \
  73. { \
  74. .reg_offset = off, \
  75. .bits_per_irq = 0, \
  76. .len = length, \
  77. .access_flags = acc, \
  78. .read = rd, \
  79. .write = wr, \
  80. }
  81. int kvm_vgic_register_mmio_region(struct kvm *kvm, struct kvm_vcpu *vcpu,
  82. struct vgic_register_region *reg_desc,
  83. struct vgic_io_device *region,
  84. int nr_irqs, bool offset_private);
  85. unsigned long vgic_data_mmio_bus_to_host(const void *val, unsigned int len);
  86. void vgic_data_host_to_mmio_bus(void *buf, unsigned int len,
  87. unsigned long data);
  88. unsigned long extract_bytes(u64 data, unsigned int offset,
  89. unsigned int num);
  90. u64 update_64bit_reg(u64 reg, unsigned int offset, unsigned int len,
  91. unsigned long val);
  92. unsigned long vgic_mmio_read_raz(struct kvm_vcpu *vcpu,
  93. gpa_t addr, unsigned int len);
  94. unsigned long vgic_mmio_read_rao(struct kvm_vcpu *vcpu,
  95. gpa_t addr, unsigned int len);
  96. void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,
  97. unsigned int len, unsigned long val);
  98. unsigned long vgic_mmio_read_enable(struct kvm_vcpu *vcpu,
  99. gpa_t addr, unsigned int len);
  100. void vgic_mmio_write_senable(struct kvm_vcpu *vcpu,
  101. gpa_t addr, unsigned int len,
  102. unsigned long val);
  103. void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu,
  104. gpa_t addr, unsigned int len,
  105. unsigned long val);
  106. unsigned long vgic_mmio_read_pending(struct kvm_vcpu *vcpu,
  107. gpa_t addr, unsigned int len);
  108. void vgic_mmio_write_spending(struct kvm_vcpu *vcpu,
  109. gpa_t addr, unsigned int len,
  110. unsigned long val);
  111. void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu,
  112. gpa_t addr, unsigned int len,
  113. unsigned long val);
  114. unsigned long vgic_mmio_read_active(struct kvm_vcpu *vcpu,
  115. gpa_t addr, unsigned int len);
  116. void vgic_mmio_write_cactive(struct kvm_vcpu *vcpu,
  117. gpa_t addr, unsigned int len,
  118. unsigned long val);
  119. void vgic_mmio_write_sactive(struct kvm_vcpu *vcpu,
  120. gpa_t addr, unsigned int len,
  121. unsigned long val);
  122. unsigned long vgic_mmio_read_priority(struct kvm_vcpu *vcpu,
  123. gpa_t addr, unsigned int len);
  124. void vgic_mmio_write_priority(struct kvm_vcpu *vcpu,
  125. gpa_t addr, unsigned int len,
  126. unsigned long val);
  127. unsigned long vgic_mmio_read_config(struct kvm_vcpu *vcpu,
  128. gpa_t addr, unsigned int len);
  129. void vgic_mmio_write_config(struct kvm_vcpu *vcpu,
  130. gpa_t addr, unsigned int len,
  131. unsigned long val);
  132. unsigned int vgic_v2_init_dist_iodev(struct vgic_io_device *dev);
  133. unsigned int vgic_v3_init_dist_iodev(struct vgic_io_device *dev);
  134. u64 vgic_sanitise_outer_cacheability(u64 reg);
  135. u64 vgic_sanitise_inner_cacheability(u64 reg);
  136. u64 vgic_sanitise_shareability(u64 reg);
  137. u64 vgic_sanitise_field(u64 reg, u64 field_mask, int field_shift,
  138. u64 (*sanitise_fn)(u64));
  139. #endif