aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/include/asm/kvm_ppc.h
diff options
context:
space:
mode:
authorAlexander Graf <agraf@suse.de>2010-02-19 05:00:42 -0500
committerAvi Kivity <avi@redhat.com>2010-04-25 05:35:21 -0400
commit0564ee8a8611326f28bae2a0455182b458826762 (patch)
treecef03027a7595370c0ca9bbd13e5446186aa39a1 /arch/powerpc/include/asm/kvm_ppc.h
parentdba2e123e7502870c965e4b445554bc8e56f78b2 (diff)
KVM: PPC: Add helpers to modify ppc fields
The PowerPC specification always lists bits from MSB to LSB. That is really confusing when you're trying to write C code, because it fits in pretty badly with the normal (1 << xx) schemes. So I came up with some nice wrappers that allow to get and set fields in a u64 with bit numbers exactly as given in the spec. That makes the code in KVM and the spec easier comparable. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/powerpc/include/asm/kvm_ppc.h')
-rw-r--r--arch/powerpc/include/asm/kvm_ppc.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index 07612189eb8..c7fcdd751f1 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -103,6 +103,39 @@ extern void kvmppc_booke_exit(void);
103 103
104extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu); 104extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu);
105 105
106/*
107 * Cuts out inst bits with ordering according to spec.
108 * That means the leftmost bit is zero. All given bits are included.
109 */
110static inline u32 kvmppc_get_field(u64 inst, int msb, int lsb)
111{
112 u32 r;
113 u32 mask;
114
115 BUG_ON(msb > lsb);
116
117 mask = (1 << (lsb - msb + 1)) - 1;
118 r = (inst >> (63 - lsb)) & mask;
119
120 return r;
121}
122
123/*
124 * Replaces inst bits with ordering according to spec.
125 */
126static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value)
127{
128 u32 r;
129 u32 mask;
130
131 BUG_ON(msb > lsb);
132
133 mask = ((1 << (lsb - msb + 1)) - 1) << (63 - lsb);
134 r = (inst & ~mask) | ((value << (63 - lsb)) & mask);
135
136 return r;
137}
138
106#ifdef CONFIG_PPC_BOOK3S 139#ifdef CONFIG_PPC_BOOK3S
107 140
108/* We assume we're always acting on the current vcpu */ 141/* We assume we're always acting on the current vcpu */