This source file includes following definitions.
- kvmppc_xive_select_irq
- kvmppc_xive_find_server
- kvmppc_xive_find_source
- kvmppc_xive_vp
- kvmppc_xive_vp_in_use
- xive_prio_from_guest
- xive_prio_to_guest
- __xive_read_eq
   1 
   2 
   3 
   4 
   5 
   6 #ifndef _KVM_PPC_BOOK3S_XIVE_H
   7 #define _KVM_PPC_BOOK3S_XIVE_H
   8 
   9 #ifdef CONFIG_KVM_XICS
  10 #include "book3s_xics.h"
  11 
  12 
  13 
  14 
  15 
  16 #define KVMPPC_XIVE_FIRST_IRQ   0
  17 #define KVMPPC_XIVE_NR_IRQS     KVMPPC_XICS_NR_IRQS
  18 
  19 
  20 
  21 
  22 
  23 
  24 
  25 
  26 
  27 
  28 
  29 
  30 
  31 
  32 struct kvmppc_xive_irq_state {
  33         bool valid;                     
  34 
  35         u32 number;                     
  36         u32 ipi_number;                 
  37         struct xive_irq_data ipi_data;  
  38         u32 pt_number;                  
  39         struct xive_irq_data *pt_data;  
  40 
  41         
  42         u8 guest_priority;              
  43         u8 saved_priority;              
  44 
  45         
  46         u32 act_server;                 
  47         u8 act_priority;                
  48 
  49         
  50         bool in_eoi;                    
  51         bool old_p;                     
  52         bool old_q;                     
  53         bool lsi;                       
  54         bool asserted;                  
  55 
  56         
  57         bool in_queue;
  58         bool saved_p;
  59         bool saved_q;
  60         u8 saved_scan_prio;
  61 
  62         
  63         u32 eisn;                       
  64 };
  65 
  66 
  67 static inline void kvmppc_xive_select_irq(struct kvmppc_xive_irq_state *state,
  68                                           u32 *out_hw_irq,
  69                                           struct xive_irq_data **out_xd)
  70 {
  71         if (state->pt_number) {
  72                 if (out_hw_irq)
  73                         *out_hw_irq = state->pt_number;
  74                 if (out_xd)
  75                         *out_xd = state->pt_data;
  76         } else {
  77                 if (out_hw_irq)
  78                         *out_hw_irq = state->ipi_number;
  79                 if (out_xd)
  80                         *out_xd = &state->ipi_data;
  81         }
  82 }
  83 
  84 
  85 
  86 
  87 
  88 struct kvmppc_xive_src_block {
  89         arch_spinlock_t lock;
  90         u16 id;
  91         struct kvmppc_xive_irq_state irq_state[KVMPPC_XICS_IRQ_PER_ICS];
  92 };
  93 
  94 struct kvmppc_xive;
  95 
  96 struct kvmppc_xive_ops {
  97         int (*reset_mapped)(struct kvm *kvm, unsigned long guest_irq);
  98 };
  99 
 100 struct kvmppc_xive {
 101         struct kvm *kvm;
 102         struct kvm_device *dev;
 103         struct dentry *dentry;
 104 
 105         
 106         u32     vp_base;
 107 
 108         
 109         struct kvmppc_xive_src_block *src_blocks[KVMPPC_XICS_MAX_ICS_ID + 1];
 110         u32     max_sbid;
 111 
 112         
 113 
 114 
 115 
 116 
 117 
 118 
 119         u32     src_count;
 120         u32     saved_src_count;
 121 
 122         
 123 
 124 
 125 
 126         u32     delayed_irqs;
 127 
 128         
 129         u8      qmap;
 130 
 131         
 132         u32     q_order;
 133         u32     q_page_order;
 134 
 135         
 136         u8      single_escalation;
 137 
 138         struct kvmppc_xive_ops *ops;
 139         struct address_space   *mapping;
 140         struct mutex mapping_lock;
 141         struct mutex lock;
 142 };
 143 
 144 #define KVMPPC_XIVE_Q_COUNT     8
 145 
 146 struct kvmppc_xive_vcpu {
 147         struct kvmppc_xive      *xive;
 148         struct kvm_vcpu         *vcpu;
 149         bool                    valid;
 150 
 151         
 152         u32                     server_num;
 153 
 154         
 155 
 156 
 157 
 158         u32                     vp_id;
 159         u32                     vp_chip_id;
 160         u32                     vp_cam;
 161 
 162         
 163         u32                     vp_ipi;
 164         struct xive_irq_data    vp_ipi_data;
 165 
 166         
 167         uint8_t                 cppr;   
 168         uint8_t                 hw_cppr;
 169         uint8_t                 mfrr;
 170         uint8_t                 pending;
 171 
 172         
 173         struct xive_q           queues[KVMPPC_XIVE_Q_COUNT];
 174         u32                     esc_virq[KVMPPC_XIVE_Q_COUNT];
 175         char                    *esc_virq_names[KVMPPC_XIVE_Q_COUNT];
 176 
 177         
 178         u32                     delayed_irq;
 179 
 180         
 181         u64                     stat_rm_h_xirr;
 182         u64                     stat_rm_h_ipoll;
 183         u64                     stat_rm_h_cppr;
 184         u64                     stat_rm_h_eoi;
 185         u64                     stat_rm_h_ipi;
 186         u64                     stat_vm_h_xirr;
 187         u64                     stat_vm_h_ipoll;
 188         u64                     stat_vm_h_cppr;
 189         u64                     stat_vm_h_eoi;
 190         u64                     stat_vm_h_ipi;
 191 };
 192 
 193 static inline struct kvm_vcpu *kvmppc_xive_find_server(struct kvm *kvm, u32 nr)
 194 {
 195         struct kvm_vcpu *vcpu = NULL;
 196         int i;
 197 
 198         kvm_for_each_vcpu(i, vcpu, kvm) {
 199                 if (vcpu->arch.xive_vcpu && nr == vcpu->arch.xive_vcpu->server_num)
 200                         return vcpu;
 201         }
 202         return NULL;
 203 }
 204 
 205 static inline struct kvmppc_xive_src_block *kvmppc_xive_find_source(struct kvmppc_xive *xive,
 206                 u32 irq, u16 *source)
 207 {
 208         u32 bid = irq >> KVMPPC_XICS_ICS_SHIFT;
 209         u16 src = irq & KVMPPC_XICS_SRC_MASK;
 210 
 211         if (source)
 212                 *source = src;
 213         if (bid > KVMPPC_XICS_MAX_ICS_ID)
 214                 return NULL;
 215         return xive->src_blocks[bid];
 216 }
 217 
 218 static inline u32 kvmppc_xive_vp(struct kvmppc_xive *xive, u32 server)
 219 {
 220         return xive->vp_base + kvmppc_pack_vcpu_id(xive->kvm, server);
 221 }
 222 
 223 static inline bool kvmppc_xive_vp_in_use(struct kvm *kvm, u32 vp_id)
 224 {
 225         struct kvm_vcpu *vcpu = NULL;
 226         int i;
 227 
 228         kvm_for_each_vcpu(i, vcpu, kvm) {
 229                 if (vcpu->arch.xive_vcpu && vp_id == vcpu->arch.xive_vcpu->vp_id)
 230                         return true;
 231         }
 232         return false;
 233 }
 234 
 235 
 236 
 237 
 238 
 239 
 240 
 241 
 242 
 243 
 244 static inline u8 xive_prio_from_guest(u8 prio)
 245 {
 246         if (prio == 0xff || prio < 6)
 247                 return prio;
 248         return 6;
 249 }
 250 
 251 static inline u8 xive_prio_to_guest(u8 prio)
 252 {
 253         return prio;
 254 }
 255 
 256 static inline u32 __xive_read_eq(__be32 *qpage, u32 msk, u32 *idx, u32 *toggle)
 257 {
 258         u32 cur;
 259 
 260         if (!qpage)
 261                 return 0;
 262         cur = be32_to_cpup(qpage + *idx);
 263         if ((cur >> 31) == *toggle)
 264                 return 0;
 265         *idx = (*idx + 1) & msk;
 266         if (*idx == 0)
 267                 (*toggle) ^= 1;
 268         return cur & 0x7fffffff;
 269 }
 270 
 271 extern unsigned long xive_rm_h_xirr(struct kvm_vcpu *vcpu);
 272 extern unsigned long xive_rm_h_ipoll(struct kvm_vcpu *vcpu, unsigned long server);
 273 extern int xive_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,
 274                          unsigned long mfrr);
 275 extern int xive_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr);
 276 extern int xive_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr);
 277 
 278 extern unsigned long (*__xive_vm_h_xirr)(struct kvm_vcpu *vcpu);
 279 extern unsigned long (*__xive_vm_h_ipoll)(struct kvm_vcpu *vcpu, unsigned long server);
 280 extern int (*__xive_vm_h_ipi)(struct kvm_vcpu *vcpu, unsigned long server,
 281                               unsigned long mfrr);
 282 extern int (*__xive_vm_h_cppr)(struct kvm_vcpu *vcpu, unsigned long cppr);
 283 extern int (*__xive_vm_h_eoi)(struct kvm_vcpu *vcpu, unsigned long xirr);
 284 
 285 
 286 
 287 
 288 void kvmppc_xive_disable_vcpu_interrupts(struct kvm_vcpu *vcpu);
 289 int kvmppc_xive_debug_show_queues(struct seq_file *m, struct kvm_vcpu *vcpu);
 290 struct kvmppc_xive_src_block *kvmppc_xive_create_src_block(
 291         struct kvmppc_xive *xive, int irq);
 292 void kvmppc_xive_free_sources(struct kvmppc_xive_src_block *sb);
 293 int kvmppc_xive_select_target(struct kvm *kvm, u32 *server, u8 prio);
 294 int kvmppc_xive_attach_escalation(struct kvm_vcpu *vcpu, u8 prio,
 295                                   bool single_escalation);
 296 struct kvmppc_xive *kvmppc_xive_get_device(struct kvm *kvm, u32 type);
 297 void xive_cleanup_single_escalation(struct kvm_vcpu *vcpu,
 298                                     struct kvmppc_xive_vcpu *xc, int irq);
 299 
 300 #endif 
 301 #endif