18c2ecf20Sopenharmony_ci/****************************************************************************** 28c2ecf20Sopenharmony_ci * hypercall.S 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Xen hypercall wrappers 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Stefano Stabellini <stefano.stabellini@eu.citrix.com>, Citrix, 2012 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or 98c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License version 2 108c2ecf20Sopenharmony_ci * as published by the Free Software Foundation; or, when distributed 118c2ecf20Sopenharmony_ci * separately from the Linux kernel or incorporated into other 128c2ecf20Sopenharmony_ci * software packages, subject to the following license: 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 158c2ecf20Sopenharmony_ci * of this source file (the "Software"), to deal in the Software without 168c2ecf20Sopenharmony_ci * restriction, including without limitation the rights to use, copy, modify, 178c2ecf20Sopenharmony_ci * merge, publish, distribute, sublicense, and/or sell copies of the Software, 188c2ecf20Sopenharmony_ci * and to permit persons to whom the Software is furnished to do so, subject to 198c2ecf20Sopenharmony_ci * the following conditions: 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 228c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 258c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 268c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 278c2ecf20Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 288c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 298c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 308c2ecf20Sopenharmony_ci * IN THE SOFTWARE. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* 348c2ecf20Sopenharmony_ci * The Xen hypercall calling convention is very similar to the ARM 358c2ecf20Sopenharmony_ci * procedure calling convention: the first paramter is passed in r0, the 368c2ecf20Sopenharmony_ci * second in r1, the third in r2 and the fourth in r3. Considering that 378c2ecf20Sopenharmony_ci * Xen hypercalls have 5 arguments at most, the fifth paramter is passed 388c2ecf20Sopenharmony_ci * in r4, differently from the procedure calling convention of using the 398c2ecf20Sopenharmony_ci * stack for that case. 408c2ecf20Sopenharmony_ci * 418c2ecf20Sopenharmony_ci * The hypercall number is passed in r12. 428c2ecf20Sopenharmony_ci * 438c2ecf20Sopenharmony_ci * The return value is in r0. 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * The hvc ISS is required to be 0xEA1, that is the Xen specific ARM 468c2ecf20Sopenharmony_ci * hypercall tag. 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#include <linux/linkage.h> 508c2ecf20Sopenharmony_ci#include <asm/assembler.h> 518c2ecf20Sopenharmony_ci#include <asm/opcodes-virt.h> 528c2ecf20Sopenharmony_ci#include <xen/interface/xen.h> 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define XEN_IMM 0xEA1 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define HYPERCALL_SIMPLE(hypercall) \ 588c2ecf20Sopenharmony_ciENTRY(HYPERVISOR_##hypercall) \ 598c2ecf20Sopenharmony_ci mov r12, #__HYPERVISOR_##hypercall; \ 608c2ecf20Sopenharmony_ci __HVC(XEN_IMM); \ 618c2ecf20Sopenharmony_ci ret lr; \ 628c2ecf20Sopenharmony_ciENDPROC(HYPERVISOR_##hypercall) 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define HYPERCALL0 HYPERCALL_SIMPLE 658c2ecf20Sopenharmony_ci#define HYPERCALL1 HYPERCALL_SIMPLE 668c2ecf20Sopenharmony_ci#define HYPERCALL2 HYPERCALL_SIMPLE 678c2ecf20Sopenharmony_ci#define HYPERCALL3 HYPERCALL_SIMPLE 688c2ecf20Sopenharmony_ci#define HYPERCALL4 HYPERCALL_SIMPLE 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define HYPERCALL5(hypercall) \ 718c2ecf20Sopenharmony_ciENTRY(HYPERVISOR_##hypercall) \ 728c2ecf20Sopenharmony_ci stmdb sp!, {r4} \ 738c2ecf20Sopenharmony_ci ldr r4, [sp, #4] \ 748c2ecf20Sopenharmony_ci mov r12, #__HYPERVISOR_##hypercall; \ 758c2ecf20Sopenharmony_ci __HVC(XEN_IMM); \ 768c2ecf20Sopenharmony_ci ldm sp!, {r4} \ 778c2ecf20Sopenharmony_ci ret lr \ 788c2ecf20Sopenharmony_ciENDPROC(HYPERVISOR_##hypercall) 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci .text 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ciHYPERCALL2(xen_version); 838c2ecf20Sopenharmony_ciHYPERCALL3(console_io); 848c2ecf20Sopenharmony_ciHYPERCALL3(grant_table_op); 858c2ecf20Sopenharmony_ciHYPERCALL2(sched_op); 868c2ecf20Sopenharmony_ciHYPERCALL2(event_channel_op); 878c2ecf20Sopenharmony_ciHYPERCALL2(hvm_op); 888c2ecf20Sopenharmony_ciHYPERCALL2(memory_op); 898c2ecf20Sopenharmony_ciHYPERCALL2(physdev_op); 908c2ecf20Sopenharmony_ciHYPERCALL3(vcpu_op); 918c2ecf20Sopenharmony_ciHYPERCALL1(tmem_op); 928c2ecf20Sopenharmony_ciHYPERCALL1(platform_op_raw); 938c2ecf20Sopenharmony_ciHYPERCALL2(multicall); 948c2ecf20Sopenharmony_ciHYPERCALL2(vm_assist); 958c2ecf20Sopenharmony_ciHYPERCALL3(dm_op); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ciENTRY(privcmd_call) 988c2ecf20Sopenharmony_ci stmdb sp!, {r4} 998c2ecf20Sopenharmony_ci mov r12, r0 1008c2ecf20Sopenharmony_ci mov r0, r1 1018c2ecf20Sopenharmony_ci mov r1, r2 1028c2ecf20Sopenharmony_ci mov r2, r3 1038c2ecf20Sopenharmony_ci ldr r3, [sp, #8] 1048c2ecf20Sopenharmony_ci /* 1058c2ecf20Sopenharmony_ci * Privcmd calls are issued by the userspace. We need to allow the 1068c2ecf20Sopenharmony_ci * kernel to access the userspace memory before issuing the hypercall. 1078c2ecf20Sopenharmony_ci */ 1088c2ecf20Sopenharmony_ci uaccess_enable r4 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci /* r4 is loaded now as we use it as scratch register before */ 1118c2ecf20Sopenharmony_ci ldr r4, [sp, #4] 1128c2ecf20Sopenharmony_ci __HVC(XEN_IMM) 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci /* 1158c2ecf20Sopenharmony_ci * Disable userspace access from kernel. This is fine to do it 1168c2ecf20Sopenharmony_ci * unconditionally as no set_fs(KERNEL_DS) is called before. 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_ci uaccess_disable r4 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci ldm sp!, {r4} 1218c2ecf20Sopenharmony_ci ret lr 1228c2ecf20Sopenharmony_ciENDPROC(privcmd_call); 123