14e342025SAlexander Graf /* 24e342025SAlexander Graf * This program is free software; you can redistribute it and/or modify 34e342025SAlexander Graf * it under the terms of the GNU General Public License, version 2, as 44e342025SAlexander Graf * published by the Free Software Foundation. 54e342025SAlexander Graf * 64e342025SAlexander Graf * This program is distributed in the hope that it will be useful, 74e342025SAlexander Graf * but WITHOUT ANY WARRANTY; without even the implied warranty of 84e342025SAlexander Graf * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 94e342025SAlexander Graf * GNU General Public License for more details. 104e342025SAlexander Graf * 114e342025SAlexander Graf * You should have received a copy of the GNU General Public License 124e342025SAlexander Graf * along with this program; if not, write to the Free Software 134e342025SAlexander Graf * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 144e342025SAlexander Graf * 154e342025SAlexander Graf * Copyright SUSE Linux Products GmbH 2009 164e342025SAlexander Graf * 174e342025SAlexander Graf * Authors: Alexander Graf <agraf@suse.de> 184e342025SAlexander Graf */ 194e342025SAlexander Graf 204e342025SAlexander Graf #ifndef __ASM_KVM_BOOK3S_H__ 214e342025SAlexander Graf #define __ASM_KVM_BOOK3S_H__ 224e342025SAlexander Graf 234e342025SAlexander Graf #include <linux/types.h> 244e342025SAlexander Graf #include <linux/kvm_host.h> 252191d657SAlexander Graf #include <asm/kvm_book3s_asm.h> 264e342025SAlexander Graf 274e342025SAlexander Graf struct kvmppc_slb { 284e342025SAlexander Graf u64 esid; 294e342025SAlexander Graf u64 vsid; 304e342025SAlexander Graf u64 orige; 314e342025SAlexander Graf u64 origv; 323ed9c6d2SAlexander Graf bool valid : 1; 333ed9c6d2SAlexander Graf bool Ks : 1; 343ed9c6d2SAlexander Graf bool Kp : 1; 353ed9c6d2SAlexander Graf bool nx : 1; 363ed9c6d2SAlexander Graf bool large : 1; /* PTEs are 16MB */ 373ed9c6d2SAlexander Graf bool tb : 1; /* 1TB segment */ 383ed9c6d2SAlexander Graf bool class : 1; 394e342025SAlexander Graf }; 404e342025SAlexander Graf 414e342025SAlexander Graf struct kvmppc_sr { 424e342025SAlexander Graf u32 raw; 434e342025SAlexander Graf u32 vsid; 443ed9c6d2SAlexander Graf bool Ks : 1; 453ed9c6d2SAlexander Graf bool Kp : 1; 463ed9c6d2SAlexander Graf bool nx : 1; 473ed9c6d2SAlexander Graf bool valid : 1; 484e342025SAlexander Graf }; 494e342025SAlexander Graf 504e342025SAlexander Graf struct kvmppc_bat { 51e15a1137SAlexander Graf u64 raw; 524e342025SAlexander Graf u32 bepi; 534e342025SAlexander Graf u32 bepi_mask; 544e342025SAlexander Graf u32 brpn; 554e342025SAlexander Graf u8 wimg; 564e342025SAlexander Graf u8 pp; 573ed9c6d2SAlexander Graf bool vs : 1; 583ed9c6d2SAlexander Graf bool vp : 1; 594e342025SAlexander Graf }; 604e342025SAlexander Graf 614e342025SAlexander Graf struct kvmppc_sid_map { 624e342025SAlexander Graf u64 guest_vsid; 634e342025SAlexander Graf u64 guest_esid; 644e342025SAlexander Graf u64 host_vsid; 653ed9c6d2SAlexander Graf bool valid : 1; 664e342025SAlexander Graf }; 674e342025SAlexander Graf 684e342025SAlexander Graf #define SID_MAP_BITS 9 694e342025SAlexander Graf #define SID_MAP_NUM (1 << SID_MAP_BITS) 704e342025SAlexander Graf #define SID_MAP_MASK (SID_MAP_NUM - 1) 714e342025SAlexander Graf 724e342025SAlexander Graf struct kvmppc_vcpu_book3s { 734e342025SAlexander Graf struct kvm_vcpu vcpu; 747e57cba0SAlexander Graf struct kvmppc_book3s_shadow_vcpu shadow_vcpu; 754e342025SAlexander Graf struct kvmppc_sid_map sid_map[SID_MAP_NUM]; 764e342025SAlexander Graf struct kvmppc_slb slb[64]; 774e342025SAlexander Graf struct { 784e342025SAlexander Graf u64 esid; 794e342025SAlexander Graf u64 vsid; 804e342025SAlexander Graf } slb_shadow[64]; 814e342025SAlexander Graf u8 slb_shadow_max; 824e342025SAlexander Graf struct kvmppc_sr sr[16]; 834e342025SAlexander Graf struct kvmppc_bat ibat[8]; 844e342025SAlexander Graf struct kvmppc_bat dbat[8]; 854e342025SAlexander Graf u64 hid[6]; 86d6d549b2SAlexander Graf u64 gqr[8]; 874e342025SAlexander Graf int slb_nr; 88c8027f16SAlexander Graf u32 dsisr; 894e342025SAlexander Graf u64 sdr1; 904e342025SAlexander Graf u64 hior; 914e342025SAlexander Graf u64 msr_mask; 924e342025SAlexander Graf u64 vsid_first; 934e342025SAlexander Graf u64 vsid_next; 944e342025SAlexander Graf u64 vsid_max; 954e342025SAlexander Graf int context_id; 9625a8a02dSAlexander Graf ulong prog_flags; /* flags to inject when giving a 700 trap */ 974e342025SAlexander Graf }; 984e342025SAlexander Graf 994e342025SAlexander Graf #define CONTEXT_HOST 0 1004e342025SAlexander Graf #define CONTEXT_GUEST 1 1014e342025SAlexander Graf #define CONTEXT_GUEST_END 2 1024e342025SAlexander Graf 1035a1b419fSAlexander Graf #define VSID_REAL_DR 0x7ffffffffff00000ULL 1045a1b419fSAlexander Graf #define VSID_REAL_IR 0x7fffffffffe00000ULL 1055a1b419fSAlexander Graf #define VSID_SPLIT_MASK 0x7fffffffffe00000ULL 1065a1b419fSAlexander Graf #define VSID_REAL 0x7fffffffffc00000ULL 1075a1b419fSAlexander Graf #define VSID_BAT 0x7fffffffffb00000ULL 1085a1b419fSAlexander Graf #define VSID_PR 0x8000000000000000ULL 1094e342025SAlexander Graf 1104e342025SAlexander Graf extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 ea, u64 ea_mask); 1114e342025SAlexander Graf extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask); 1124e342025SAlexander Graf extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 pa_end); 1134e342025SAlexander Graf extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr); 1144e342025SAlexander Graf extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu); 1154e342025SAlexander Graf extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu); 1164e342025SAlexander Graf extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte); 1174e342025SAlexander Graf extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr); 1184e342025SAlexander Graf extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu); 1194e342025SAlexander Graf extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data); 1205467a97dSAlexander Graf extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); 1215467a97dSAlexander Graf extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); 1224e342025SAlexander Graf extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec); 123e15a1137SAlexander Graf extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, 124e15a1137SAlexander Graf bool upper, u32 val); 125aba3bd7fSAlexander Graf extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr); 126831317b6SAlexander Graf extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu); 1274e342025SAlexander Graf 1284e342025SAlexander Graf extern u32 kvmppc_trampoline_lowmem; 1294e342025SAlexander Graf extern u32 kvmppc_trampoline_enter; 130021ec9c6SAlexander Graf extern void kvmppc_rmcall(ulong srr0, ulong srr1); 131d5e52813SAlexander Graf extern void kvmppc_load_up_fpu(void); 132d5e52813SAlexander Graf extern void kvmppc_load_up_altivec(void); 133d5e52813SAlexander Graf extern void kvmppc_load_up_vsx(void); 134ca7f4203SAlexander Graf extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst); 135ca7f4203SAlexander Graf extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst); 1364e342025SAlexander Graf 1374e342025SAlexander Graf static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu) 1384e342025SAlexander Graf { 1394e342025SAlexander Graf return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu); 1404e342025SAlexander Graf } 1414e342025SAlexander Graf 1424e342025SAlexander Graf static inline ulong dsisr(void) 1434e342025SAlexander Graf { 1444e342025SAlexander Graf ulong r; 1454e342025SAlexander Graf asm ( "mfdsisr %0 " : "=r" (r) ); 1464e342025SAlexander Graf return r; 1474e342025SAlexander Graf } 1484e342025SAlexander Graf 1494e342025SAlexander Graf extern void kvm_return_point(void); 1504e342025SAlexander Graf 151ad0a048bSAlexander Graf /* Magic register values loaded into r3 and r4 before the 'sc' assembly 152ad0a048bSAlexander Graf * instruction for the OSI hypercalls */ 153ad0a048bSAlexander Graf #define OSI_SC_MAGIC_R3 0x113724FA 154ad0a048bSAlexander Graf #define OSI_SC_MAGIC_R4 0x77810F9B 155ad0a048bSAlexander Graf 1564e342025SAlexander Graf #define INS_DCBZ 0x7c0007ec 1574e342025SAlexander Graf 1584e342025SAlexander Graf #endif /* __ASM_KVM_BOOK3S_H__ */ 159