Alexander Graf | d17051c | 2010-07-29 14:47:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License, version 2, as |
| 4 | * published by the Free Software Foundation. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9 | * GNU General Public License for more details. |
| 10 | * |
| 11 | * You should have received a copy of the GNU General Public License |
| 12 | * along with this program; if not, write to the Free Software |
| 13 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 14 | * |
| 15 | * Copyright SUSE Linux Products GmbH 2010 |
| 16 | * |
| 17 | * Authors: Alexander Graf <agraf@suse.de> |
| 18 | */ |
| 19 | |
| 20 | #include <asm/ppc_asm.h> |
| 21 | #include <asm/kvm_asm.h> |
| 22 | #include <asm/reg.h> |
| 23 | #include <asm/page.h> |
| 24 | #include <asm/asm-offsets.h> |
| 25 | |
| 26 | /* Hypercall entry point. Will be patched with device tree instructions. */ |
| 27 | |
| 28 | .global kvm_hypercall_start |
| 29 | kvm_hypercall_start: |
| 30 | li r3, -1 |
| 31 | nop |
| 32 | nop |
| 33 | nop |
| 34 | blr |
| 35 | |
| 36 | #define KVM_MAGIC_PAGE (-4096) |
Alexander Graf | 9223472 | 2010-07-29 14:48:03 +0200 | [diff] [blame^] | 37 | |
| 38 | #ifdef CONFIG_64BIT |
| 39 | #define LL64(reg, offs, reg2) ld reg, (offs)(reg2) |
| 40 | #define STL64(reg, offs, reg2) std reg, (offs)(reg2) |
| 41 | #else |
| 42 | #define LL64(reg, offs, reg2) lwz reg, (offs + 4)(reg2) |
| 43 | #define STL64(reg, offs, reg2) stw reg, (offs + 4)(reg2) |
| 44 | #endif |
| 45 | |
| 46 | #define SCRATCH_SAVE \ |
| 47 | /* Enable critical section. We are critical if \ |
| 48 | shared->critical == r1 */ \ |
| 49 | STL64(r1, KVM_MAGIC_PAGE + KVM_MAGIC_CRITICAL, 0); \ |
| 50 | \ |
| 51 | /* Save state */ \ |
| 52 | PPC_STL r31, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH1)(0); \ |
| 53 | PPC_STL r30, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH2)(0); \ |
| 54 | mfcr r31; \ |
| 55 | stw r31, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH3)(0); |
| 56 | |
| 57 | #define SCRATCH_RESTORE \ |
| 58 | /* Restore state */ \ |
| 59 | PPC_LL r31, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH1)(0); \ |
| 60 | lwz r30, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH3)(0); \ |
| 61 | mtcr r30; \ |
| 62 | PPC_LL r30, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH2)(0); \ |
| 63 | \ |
| 64 | /* Disable critical section. We are critical if \ |
| 65 | shared->critical == r1 and r2 is always != r1 */ \ |
| 66 | STL64(r2, KVM_MAGIC_PAGE + KVM_MAGIC_CRITICAL, 0); |