1d8bf5168SSepherosa Ziehau /*-
2d8bf5168SSepherosa Ziehau * Copyright (c) 2016 Microsoft Corp.
3d8bf5168SSepherosa Ziehau * All rights reserved.
4d8bf5168SSepherosa Ziehau *
5d8bf5168SSepherosa Ziehau * Redistribution and use in source and binary forms, with or without
6d8bf5168SSepherosa Ziehau * modification, are permitted provided that the following conditions
7d8bf5168SSepherosa Ziehau * are met:
8d8bf5168SSepherosa Ziehau * 1. Redistributions of source code must retain the above copyright
9d8bf5168SSepherosa Ziehau * notice unmodified, this list of conditions, and the following
10d8bf5168SSepherosa Ziehau * disclaimer.
11d8bf5168SSepherosa Ziehau * 2. Redistributions in binary form must reproduce the above copyright
12d8bf5168SSepherosa Ziehau * notice, this list of conditions and the following disclaimer in the
13d8bf5168SSepherosa Ziehau * documentation and/or other materials provided with the distribution.
14d8bf5168SSepherosa Ziehau *
15d8bf5168SSepherosa Ziehau * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16d8bf5168SSepherosa Ziehau * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17d8bf5168SSepherosa Ziehau * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18d8bf5168SSepherosa Ziehau * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19d8bf5168SSepherosa Ziehau * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20d8bf5168SSepherosa Ziehau * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21d8bf5168SSepherosa Ziehau * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22d8bf5168SSepherosa Ziehau * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23d8bf5168SSepherosa Ziehau * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24d8bf5168SSepherosa Ziehau * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25d8bf5168SSepherosa Ziehau */
26d8bf5168SSepherosa Ziehau
27d8bf5168SSepherosa Ziehau #include <sys/param.h>
28*9729f076SSouradeep Chakrabarti #include <dev/hyperv/vmbus/x86/hyperv_machdep.h>
29d8bf5168SSepherosa Ziehau
30d8bf5168SSepherosa Ziehau uint64_t
hypercall_md(volatile void * hc_addr,uint64_t in_val,uint64_t in_paddr,uint64_t out_paddr)31d8bf5168SSepherosa Ziehau hypercall_md(volatile void *hc_addr, uint64_t in_val,
32d8bf5168SSepherosa Ziehau uint64_t in_paddr, uint64_t out_paddr)
33d8bf5168SSepherosa Ziehau {
34d8bf5168SSepherosa Ziehau uint32_t in_val_hi = in_val >> 32;
35d8bf5168SSepherosa Ziehau uint32_t in_val_lo = in_val & 0xFFFFFFFF;
36d8bf5168SSepherosa Ziehau uint32_t status_hi, status_lo;
37d8bf5168SSepherosa Ziehau uint32_t in_paddr_hi = in_paddr >> 32;
38d8bf5168SSepherosa Ziehau uint32_t in_paddr_lo = in_paddr & 0xFFFFFFFF;
39d8bf5168SSepherosa Ziehau uint32_t out_paddr_hi = out_paddr >> 32;
40d8bf5168SSepherosa Ziehau uint32_t out_paddr_lo = out_paddr & 0xFFFFFFFF;
41d8bf5168SSepherosa Ziehau
42d8bf5168SSepherosa Ziehau __asm__ __volatile__ ("call *%8" : "=d"(status_hi), "=a"(status_lo) :
43d8bf5168SSepherosa Ziehau "d" (in_val_hi), "a" (in_val_lo),
44d8bf5168SSepherosa Ziehau "b" (in_paddr_hi), "c" (in_paddr_lo),
45d8bf5168SSepherosa Ziehau "D"(out_paddr_hi), "S"(out_paddr_lo),
46d8bf5168SSepherosa Ziehau "m" (hc_addr));
47d8bf5168SSepherosa Ziehau return (status_lo | ((uint64_t)status_hi << 32));
48d8bf5168SSepherosa Ziehau }
49