blob: 11ed0a596b5a49061ad6d3f1cf9bc0554cd2e3e6 [file] [log] [blame]
Heiko Carstensb0c632d2008-03-25 18:47:20 +01001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * definition for kvm on s390
Heiko Carstensb0c632d2008-03-25 18:47:20 +01003 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 2008, 2009
Heiko Carstensb0c632d2008-03-25 18:47:20 +01005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License (version 2 only)
8 * as published by the Free Software Foundation.
9 *
10 * Author(s): Carsten Otte <cotte@de.ibm.com>
11 * Christian Borntraeger <borntraeger@de.ibm.com>
Christian Ehrhardt628eb9b2009-05-25 13:40:51 +020012 * Christian Ehrhardt <ehrhardt@de.ibm.com>
Heiko Carstensb0c632d2008-03-25 18:47:20 +010013 */
14
15#ifndef ARCH_S390_KVM_S390_H
16#define ARCH_S390_KVM_S390_H
Christian Borntraeger8f2abe62008-03-25 18:47:23 +010017
Christian Borntraegerca872302009-05-12 17:21:49 +020018#include <linux/hrtimer.h>
Carsten Otteba5c1e92008-03-25 18:47:26 +010019#include <linux/kvm.h>
Christian Borntraeger8f2abe62008-03-25 18:47:23 +010020#include <linux/kvm_host.h>
21
22typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu);
23
Michael Mueller78c4b592013-07-26 15:04:04 +020024/* declare vfacilities extern */
25extern unsigned long *vfacilities;
26
Christian Borntraeger8f2abe62008-03-25 18:47:23 +010027int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu);
28
Michael Mueller7feb6bb2013-06-28 13:30:24 +020029/* Transactional Memory Execution related macros */
30#define IS_TE_ENABLED(vcpu) ((vcpu->arch.sie_block->ecb & 0x10))
31#define TDB_ADDR 0x1800UL
32#define TDB_FORMAT1 1
33#define IS_ITDB_VALID(vcpu) ((*(char *)vcpu->arch.sie_block->itdba == TDB_FORMAT1))
34
Heiko Carstensb0c632d2008-03-25 18:47:20 +010035#define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
36do { \
37 debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
38 d_args); \
39} while (0)
40
41#define VCPU_EVENT(d_vcpu, d_loglevel, d_string, d_args...)\
42do { \
43 debug_sprintf_event(d_vcpu->kvm->arch.dbf, d_loglevel, \
44 "%02d[%016lx-%016lx]: " d_string "\n", d_vcpu->vcpu_id, \
45 d_vcpu->arch.sie_block->gpsw.mask, d_vcpu->arch.sie_block->gpsw.addr,\
46 d_args); \
47} while (0)
Carsten Otteba5c1e92008-03-25 18:47:26 +010048
49static inline int __cpu_is_stopped(struct kvm_vcpu *vcpu)
50{
51 return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOP_INT;
52}
53
Carsten Ottee08b9632012-01-04 10:25:20 +010054static inline int kvm_is_ucontrol(struct kvm *kvm)
55{
56#ifdef CONFIG_KVM_S390_UCONTROL
57 if (kvm->arch.gmap)
58 return 0;
59 return 1;
60#else
61 return 0;
62#endif
63}
Christian Borntraeger8d26cf72012-01-11 11:19:32 +010064
65static inline void kvm_s390_set_prefix(struct kvm_vcpu *vcpu, u32 prefix)
66{
67 vcpu->arch.sie_block->prefix = prefix & 0x7fffe000u;
68 vcpu->arch.sie_block->ihcpu = 0xffff;
Christian Borntraeger2c70fe42013-05-17 14:41:36 +020069 kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu);
Christian Borntraeger8d26cf72012-01-11 11:19:32 +010070}
71
Cornelia Huckb1c571a2012-12-20 15:32:07 +010072static inline u64 kvm_s390_get_base_disp_s(struct kvm_vcpu *vcpu)
73{
Christian Borntraeger0c29b222013-01-25 15:34:17 +010074 u32 base2 = vcpu->arch.sie_block->ipb >> 28;
75 u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
Cornelia Huckb1c571a2012-12-20 15:32:07 +010076
77 return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
78}
79
80static inline void kvm_s390_get_base_disp_sse(struct kvm_vcpu *vcpu,
81 u64 *address1, u64 *address2)
82{
Christian Borntraeger0c29b222013-01-25 15:34:17 +010083 u32 base1 = (vcpu->arch.sie_block->ipb & 0xf0000000) >> 28;
84 u32 disp1 = (vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16;
85 u32 base2 = (vcpu->arch.sie_block->ipb & 0xf000) >> 12;
86 u32 disp2 = vcpu->arch.sie_block->ipb & 0x0fff;
Cornelia Huckb1c571a2012-12-20 15:32:07 +010087
88 *address1 = (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1;
89 *address2 = (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
90}
91
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +020092static inline void kvm_s390_get_regs_rre(struct kvm_vcpu *vcpu, int *r1, int *r2)
93{
Thomas Huthff7158b2013-09-12 10:33:46 +020094 if (r1)
95 *r1 = (vcpu->arch.sie_block->ipb & 0x00f00000) >> 20;
96 if (r2)
97 *r2 = (vcpu->arch.sie_block->ipb & 0x000f0000) >> 16;
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +020098}
99
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100100static inline u64 kvm_s390_get_base_disp_rsy(struct kvm_vcpu *vcpu)
101{
Christian Borntraeger0c29b222013-01-25 15:34:17 +0100102 u32 base2 = vcpu->arch.sie_block->ipb >> 28;
103 u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100104 ((vcpu->arch.sie_block->ipb & 0xff00) << 4);
Christian Borntraeger0c29b222013-01-25 15:34:17 +0100105 /* The displacement is a 20bit _SIGNED_ value */
106 if (disp2 & 0x80000)
107 disp2+=0xfff00000;
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100108
Christian Borntraeger0c29b222013-01-25 15:34:17 +0100109 return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + (long)(int)disp2;
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100110}
111
112static inline u64 kvm_s390_get_base_disp_rs(struct kvm_vcpu *vcpu)
113{
Christian Borntraeger0c29b222013-01-25 15:34:17 +0100114 u32 base2 = vcpu->arch.sie_block->ipb >> 28;
115 u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100116
117 return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
118}
119
Thomas Huthea828eb2013-07-26 15:04:06 +0200120/* Set the condition code in the guest program status word */
121static inline void kvm_s390_set_psw_cc(struct kvm_vcpu *vcpu, unsigned long cc)
122{
123 vcpu->arch.sie_block->gpsw.mask &= ~(3UL << 44);
124 vcpu->arch.sie_block->gpsw.mask |= cc << 44;
125}
126
Carsten Otteba5c1e92008-03-25 18:47:26 +0100127int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
Christian Borntraegerca872302009-05-12 17:21:49 +0200128enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
129void kvm_s390_tasklet(unsigned long parm);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100130void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
Cornelia Huck48a3e952012-12-20 15:32:09 +0100131void kvm_s390_deliver_pending_machine_checks(struct kvm_vcpu *vcpu);
Jens Freimann2ed10cc2014-02-11 13:48:07 +0100132void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu);
Heiko Carstensdb4a29c2013-03-25 17:22:53 +0100133int __must_check kvm_s390_inject_vm(struct kvm *kvm,
134 struct kvm_s390_interrupt *s390int);
135int __must_check kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
136 struct kvm_s390_interrupt *s390int);
137int __must_check kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code);
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100138struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
139 u64 cr6, u64 schid);
Cornelia Huck841b91c2013-07-15 13:36:01 +0200140int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100141
142/* implemented in priv.c */
Christian Borntraeger70455a32009-01-22 10:28:29 +0100143int kvm_s390_handle_b2(struct kvm_vcpu *vcpu);
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200144int kvm_s390_handle_e5(struct kvm_vcpu *vcpu);
Cornelia Huck8c3f61e2012-04-24 09:24:44 +0200145int kvm_s390_handle_01(struct kvm_vcpu *vcpu);
Cornelia Huck48a3e952012-12-20 15:32:09 +0100146int kvm_s390_handle_b9(struct kvm_vcpu *vcpu);
147int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu);
Thomas Huth953ed882013-06-20 17:22:04 +0200148int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu);
149int kvm_s390_handle_eb(struct kvm_vcpu *vcpu);
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100150
151/* implemented in sigp.c */
152int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
153
154/* implemented in kvm-s390.c */
Thomas Huthe8798922013-11-06 15:46:33 +0100155int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr);
156int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr);
Christian Borntraeger49b99e12013-05-17 14:41:35 +0200157void s390_vcpu_block(struct kvm_vcpu *vcpu);
158void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
159void exit_sie(struct kvm_vcpu *vcpu);
160void exit_sie_sync(struct kvm_vcpu *vcpu);
Dominik Dingelb31605c2014-03-25 13:47:11 +0100161int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu);
162void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu);
163/* is cmma enabled */
164bool kvm_s390_cmma_enabled(struct kvm *kvm);
Heiko Carstens280ef0f2013-12-17 09:08:28 +0100165int test_vfacility(unsigned long nr);
Dominik Dingelb31605c2014-03-25 13:47:11 +0100166
Christian Borntraegere28acfe2008-03-25 18:47:34 +0100167/* implemented in diag.c */
168int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
Jens Freimannbcd84682014-02-11 11:07:05 +0100169/* implemented in interrupt.c */
170int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu,
171 struct kvm_s390_pgm_info *pgm_info);
Christian Borntraegere28acfe2008-03-25 18:47:34 +0100172
Heiko Carstens1b0462e2014-01-01 16:31:49 +0100173/**
174 * kvm_s390_inject_prog_cond - conditionally inject a program check
175 * @vcpu: virtual cpu
176 * @rc: original return/error code
177 *
178 * This function is supposed to be used after regular guest access functions
179 * failed, to conditionally inject a program check to a vcpu. The typical
180 * pattern would look like
181 *
182 * rc = write_guest(vcpu, addr, data, len);
183 * if (rc)
184 * return kvm_s390_inject_prog_cond(vcpu, rc);
185 *
186 * A negative return code from guest access functions implies an internal error
187 * like e.g. out of memory. In these cases no program check should be injected
188 * to the guest.
189 * A positive value implies that an exception happened while accessing a guest's
190 * memory. In this case all data belonging to the corresponding program check
191 * has been stored in vcpu->arch.pgm and can be injected with
192 * kvm_s390_inject_prog_irq().
193 *
194 * Returns: - the original @rc value if @rc was negative (internal error)
195 * - zero if @rc was already zero
196 * - zero or error code from injecting if @rc was positive
197 * (program check injected to @vcpu)
198 */
199static inline int kvm_s390_inject_prog_cond(struct kvm_vcpu *vcpu, int rc)
200{
201 if (rc <= 0)
202 return rc;
203 return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm);
204}
205
Dominik Dingel3c038e62013-10-07 17:11:48 +0200206/* implemented in interrupt.c */
207int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);
208int psw_extint_disabled(struct kvm_vcpu *vcpu);
Cornelia Huck841b91c2013-07-15 13:36:01 +0200209void kvm_s390_destroy_adapters(struct kvm *kvm);
Dominik Dingel3c038e62013-10-07 17:11:48 +0200210
Heiko Carstensb0c632d2008-03-25 18:47:20 +0100211#endif