2 * Copyright 2012 Michael Ellerman, IBM Corporation.
3 * Copyright 2012 Benjamin Herrenschmidt, IBM Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2, as
7 * published by the Free Software Foundation.
10 #ifndef _KVM_PPC_BOOK3S_XICS_H
11 #define _KVM_PPC_BOOK3S_XICS_H
14 * We use a two-level tree to store interrupt source information.
15 * There are up to 1024 ICS nodes, each of which can represent
18 #define KVMPPC_XICS_MAX_ICS_ID 1023
19 #define KVMPPC_XICS_ICS_SHIFT 10
20 #define KVMPPC_XICS_IRQ_PER_ICS (1 << KVMPPC_XICS_ICS_SHIFT)
21 #define KVMPPC_XICS_SRC_MASK (KVMPPC_XICS_IRQ_PER_ICS - 1)
24 * Interrupt source numbers below this are reserved, for example
25 * 0 is "no interrupt", and 2 is used for IPIs.
27 #define KVMPPC_XICS_FIRST_IRQ 16
28 #define KVMPPC_XICS_NR_IRQS ((KVMPPC_XICS_MAX_ICS_ID + 1) * \
29 KVMPPC_XICS_IRQ_PER_ICS)
31 /* Priority value to use for disabling an interrupt */
34 /* State for one irq source */
35 struct ics_irq_state
{
42 u8 asserted
; /* Only for LSI */
46 /* Atomic ICP state, updated with a single compare & swap */
47 union kvmppc_icp_state
{
60 #define ICP_RESEND_MAP_SIZE (KVMPPC_XICS_MAX_ICS_ID / BITS_PER_LONG + 1)
63 struct kvm_vcpu
*vcpu
;
64 unsigned long server_num
;
65 union kvmppc_icp_state state
;
66 unsigned long resend_map
[ICP_RESEND_MAP_SIZE
];
68 /* Real mode might find something too hard, here's the action
69 * it might request from virtual mode
71 #define XICS_RM_KICK_VCPU 0x1
72 #define XICS_RM_CHECK_RESEND 0x2
73 #define XICS_RM_REJECT 0x4
75 struct kvm_vcpu
*rm_kick_target
;
78 /* Debug stuff for real mode */
79 union kvmppc_icp_state rm_dbgstate
;
80 struct kvm_vcpu
*rm_dbgtgt
;
86 struct ics_irq_state irq_state
[KVMPPC_XICS_IRQ_PER_ICS
];
91 struct kvm_device
*dev
;
92 struct dentry
*dentry
;
96 struct kvmppc_ics
*ics
[KVMPPC_XICS_MAX_ICS_ID
+ 1];
99 static inline struct kvmppc_icp
*kvmppc_xics_find_server(struct kvm
*kvm
,
102 struct kvm_vcpu
*vcpu
= NULL
;
105 kvm_for_each_vcpu(i
, vcpu
, kvm
) {
106 if (vcpu
->arch
.icp
&& nr
== vcpu
->arch
.icp
->server_num
)
107 return vcpu
->arch
.icp
;
112 static inline struct kvmppc_ics
*kvmppc_xics_find_ics(struct kvmppc_xics
*xics
,
113 u32 irq
, u16
*source
)
115 u32 icsid
= irq
>> KVMPPC_XICS_ICS_SHIFT
;
116 u16 src
= irq
& KVMPPC_XICS_SRC_MASK
;
117 struct kvmppc_ics
*ics
;
121 if (icsid
> KVMPPC_XICS_MAX_ICS_ID
)
123 ics
= xics
->ics
[icsid
];
130 #endif /* _KVM_PPC_BOOK3S_XICS_H */