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> 257e57cba0SAlexander Graf #include <asm/kvm_book3s_64_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; 324e342025SAlexander Graf bool valid; 334e342025SAlexander Graf bool Ks; 344e342025SAlexander Graf bool Kp; 354e342025SAlexander Graf bool nx; 364b5c9b7fSAlexander Graf bool large; /* PTEs are 16MB */ 374b5c9b7fSAlexander Graf bool tb; /* 1TB segment */ 384e342025SAlexander Graf bool class; 394e342025SAlexander Graf }; 404e342025SAlexander Graf 414e342025SAlexander Graf struct kvmppc_sr { 424e342025SAlexander Graf u32 raw; 434e342025SAlexander Graf u32 vsid; 444e342025SAlexander Graf bool Ks; 454e342025SAlexander Graf bool Kp; 464e342025SAlexander Graf bool nx; 474e342025SAlexander Graf }; 484e342025SAlexander Graf 494e342025SAlexander Graf struct kvmppc_bat { 50e15a1137SAlexander Graf u64 raw; 514e342025SAlexander Graf u32 bepi; 524e342025SAlexander Graf u32 bepi_mask; 534e342025SAlexander Graf bool vs; 544e342025SAlexander Graf bool vp; 554e342025SAlexander Graf u32 brpn; 564e342025SAlexander Graf u8 wimg; 574e342025SAlexander Graf u8 pp; 584e342025SAlexander Graf }; 594e342025SAlexander Graf 604e342025SAlexander Graf struct kvmppc_sid_map { 614e342025SAlexander Graf u64 guest_vsid; 624e342025SAlexander Graf u64 guest_esid; 634e342025SAlexander Graf u64 host_vsid; 644e342025SAlexander Graf bool valid; 654e342025SAlexander Graf }; 664e342025SAlexander Graf 674e342025SAlexander Graf #define SID_MAP_BITS 9 684e342025SAlexander Graf #define SID_MAP_NUM (1 << SID_MAP_BITS) 694e342025SAlexander Graf #define SID_MAP_MASK (SID_MAP_NUM - 1) 704e342025SAlexander Graf 714e342025SAlexander Graf struct kvmppc_vcpu_book3s { 724e342025SAlexander Graf struct kvm_vcpu vcpu; 737e57cba0SAlexander Graf struct kvmppc_book3s_shadow_vcpu shadow_vcpu; 744e342025SAlexander Graf struct kvmppc_sid_map sid_map[SID_MAP_NUM]; 754e342025SAlexander Graf struct kvmppc_slb slb[64]; 764e342025SAlexander Graf struct { 774e342025SAlexander Graf u64 esid; 784e342025SAlexander Graf u64 vsid; 794e342025SAlexander Graf } slb_shadow[64]; 804e342025SAlexander Graf u8 slb_shadow_max; 814e342025SAlexander Graf struct kvmppc_sr sr[16]; 824e342025SAlexander Graf struct kvmppc_bat ibat[8]; 834e342025SAlexander Graf struct kvmppc_bat dbat[8]; 844e342025SAlexander Graf u64 hid[6]; 85d6d549b2SAlexander Graf u64 gqr[8]; 864e342025SAlexander Graf int slb_nr; 874e342025SAlexander Graf u64 sdr1; 884e342025SAlexander Graf u64 dsisr; 894e342025SAlexander Graf u64 hior; 904e342025SAlexander Graf u64 msr_mask; 914e342025SAlexander Graf u64 vsid_first; 924e342025SAlexander Graf u64 vsid_next; 934e342025SAlexander Graf u64 vsid_max; 944e342025SAlexander Graf int context_id; 9525a8a02dSAlexander Graf ulong prog_flags; /* flags to inject when giving a 700 trap */ 964e342025SAlexander Graf }; 974e342025SAlexander Graf 984e342025SAlexander Graf #define CONTEXT_HOST 0 994e342025SAlexander Graf #define CONTEXT_GUEST 1 1004e342025SAlexander Graf #define CONTEXT_GUEST_END 2 1014e342025SAlexander Graf 1024e342025SAlexander Graf #define VSID_REAL 0xfffffffffff00000 1034e342025SAlexander Graf #define VSID_REAL_DR 0xffffffffffe00000 1044e342025SAlexander Graf #define VSID_REAL_IR 0xffffffffffd00000 1054e342025SAlexander Graf #define VSID_BAT 0xffffffffffc00000 1064e342025SAlexander Graf #define VSID_PR 0x8000000000000000 1074e342025SAlexander Graf 1084e342025SAlexander Graf extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 ea, u64 ea_mask); 1094e342025SAlexander Graf extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask); 1104e342025SAlexander Graf extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 pa_end); 1114e342025SAlexander Graf extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr); 1124e342025SAlexander Graf extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu); 1134e342025SAlexander Graf extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu); 1144e342025SAlexander Graf extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte); 1154e342025SAlexander Graf extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr); 1164e342025SAlexander Graf extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu); 1174e342025SAlexander Graf extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data); 1185467a97dSAlexander Graf extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); 1195467a97dSAlexander Graf extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); 1204e342025SAlexander Graf extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec); 121e15a1137SAlexander Graf extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, 122e15a1137SAlexander Graf bool upper, u32 val); 1234e342025SAlexander Graf 1244e342025SAlexander Graf extern u32 kvmppc_trampoline_lowmem; 1254e342025SAlexander Graf extern u32 kvmppc_trampoline_enter; 126021ec9c6SAlexander Graf extern void kvmppc_rmcall(ulong srr0, ulong srr1); 127d5e52813SAlexander Graf extern void kvmppc_load_up_fpu(void); 128d5e52813SAlexander Graf extern void kvmppc_load_up_altivec(void); 129d5e52813SAlexander Graf extern void kvmppc_load_up_vsx(void); 1304e342025SAlexander Graf 1314e342025SAlexander Graf static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu) 1324e342025SAlexander Graf { 1334e342025SAlexander Graf return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu); 1344e342025SAlexander Graf } 1354e342025SAlexander Graf 1364e342025SAlexander Graf static inline ulong dsisr(void) 1374e342025SAlexander Graf { 1384e342025SAlexander Graf ulong r; 1394e342025SAlexander Graf asm ( "mfdsisr %0 " : "=r" (r) ); 1404e342025SAlexander Graf return r; 1414e342025SAlexander Graf } 1424e342025SAlexander Graf 1434e342025SAlexander Graf extern void kvm_return_point(void); 1444e342025SAlexander Graf 1454e342025SAlexander Graf #define INS_DCBZ 0x7c0007ec 1464e342025SAlexander Graf 1474e342025SAlexander Graf #endif /* __ASM_KVM_BOOK3S_H__ */ 148