Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 OR MIT
0002 /*
0003  * Copyright 2021 VMware, Inc., Palo Alto, CA., USA
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the
0007  * "Software"), to deal in the Software without restriction, including
0008  * without limitation the rights to use, copy, modify, merge, publish,
0009  * distribute, sub license, and/or sell copies of the Software, and to
0010  * permit persons to whom the Software is furnished to do so, subject to
0011  * the following conditions:
0012  *
0013  * The above copyright notice and this permission notice (including the
0014  * next paragraph) shall be included in all copies or substantial portions
0015  * of the Software.
0016  *
0017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0019  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
0020  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
0021  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
0022  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
0023  * USE OR OTHER DEALINGS IN THE SOFTWARE.
0024  *
0025  */
0026 #ifndef _VMWGFX_MSG_ARM64_H
0027 #define _VMWGFX_MSG_ARM64_H
0028 
0029 #if defined(__aarch64__)
0030 
0031 #define VMWARE_HYPERVISOR_PORT    0x5658
0032 #define VMWARE_HYPERVISOR_PORT_HB 0x5659
0033 
0034 #define VMWARE_HYPERVISOR_HB  BIT(0)
0035 #define VMWARE_HYPERVISOR_OUT BIT(1)
0036 
0037 #define X86_IO_MAGIC 0x86
0038 
0039 #define X86_IO_W7_SIZE_SHIFT 0
0040 #define X86_IO_W7_SIZE_MASK (0x3 << X86_IO_W7_SIZE_SHIFT)
0041 #define X86_IO_W7_DIR       (1 << 2)
0042 #define X86_IO_W7_WITH      (1 << 3)
0043 #define X86_IO_W7_STR       (1 << 4)
0044 #define X86_IO_W7_DF        (1 << 5)
0045 #define X86_IO_W7_IMM_SHIFT  5
0046 #define X86_IO_W7_IMM_MASK  (0xff << X86_IO_W7_IMM_SHIFT)
0047 
0048 static inline void vmw_port(unsigned long cmd, unsigned long in_ebx,
0049                 unsigned long in_si, unsigned long in_di,
0050                 unsigned long flags, unsigned long magic,
0051                 unsigned long *eax, unsigned long *ebx,
0052                 unsigned long *ecx, unsigned long *edx,
0053                 unsigned long *si, unsigned long *di)
0054 {
0055     register u64 x0 asm("x0") = magic;
0056     register u64 x1 asm("x1") = in_ebx;
0057     register u64 x2 asm("x2") = cmd;
0058     register u64 x3 asm("x3") = flags | VMWARE_HYPERVISOR_PORT;
0059     register u64 x4 asm("x4") = in_si;
0060     register u64 x5 asm("x5") = in_di;
0061 
0062     register u64 x7 asm("x7") = ((u64)X86_IO_MAGIC << 32) |
0063                     X86_IO_W7_WITH |
0064                     X86_IO_W7_DIR |
0065                     (2 << X86_IO_W7_SIZE_SHIFT);
0066 
0067     asm volatile("mrs xzr, mdccsr_el0 \n\t"
0068              : "+r"(x0), "+r"(x1), "+r"(x2),
0069                "+r"(x3), "+r"(x4), "+r"(x5)
0070              : "r"(x7)
0071              :);
0072     *eax = x0;
0073     *ebx = x1;
0074     *ecx = x2;
0075     *edx = x3;
0076     *si = x4;
0077     *di = x5;
0078 }
0079 
0080 static inline void vmw_port_hb(unsigned long cmd, unsigned long in_ecx,
0081                    unsigned long in_si, unsigned long in_di,
0082                    unsigned long flags, unsigned long magic,
0083                    unsigned long bp, u32 w7dir,
0084                    unsigned long *eax, unsigned long *ebx,
0085                    unsigned long *ecx, unsigned long *edx,
0086                    unsigned long *si, unsigned long *di)
0087 {
0088     register u64 x0 asm("x0") = magic;
0089     register u64 x1 asm("x1") = cmd;
0090     register u64 x2 asm("x2") = in_ecx;
0091     register u64 x3 asm("x3") = flags | VMWARE_HYPERVISOR_PORT_HB;
0092     register u64 x4 asm("x4") = in_si;
0093     register u64 x5 asm("x5") = in_di;
0094     register u64 x6 asm("x6") = bp;
0095     register u64 x7 asm("x7") = ((u64)X86_IO_MAGIC << 32) |
0096                     X86_IO_W7_STR |
0097                     X86_IO_W7_WITH |
0098                     w7dir;
0099 
0100     asm volatile("mrs xzr, mdccsr_el0 \n\t"
0101              : "+r"(x0), "+r"(x1), "+r"(x2),
0102                "+r"(x3), "+r"(x4), "+r"(x5)
0103              : "r"(x6), "r"(x7)
0104              :);
0105     *eax = x0;
0106     *ebx = x1;
0107     *ecx = x2;
0108     *edx = x3;
0109     *si  = x4;
0110     *di  = x5;
0111 }
0112 
0113 #define VMW_PORT(cmd, in_ebx, in_si, in_di, flags, magic, eax, ebx, ecx, edx,  \
0114          si, di)                                                       \
0115     vmw_port(cmd, in_ebx, in_si, in_di, flags, magic, &eax, &ebx, &ecx,    \
0116          &edx, &si, &di)
0117 
0118 #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, flags, magic, bp, eax, ebx, \
0119                 ecx, edx, si, di)                                      \
0120     vmw_port_hb(cmd, in_ecx, in_si, in_di, flags, magic, bp,               \
0121                     0, &eax, &ebx, &ecx, &edx, &si, &di)
0122 
0123 #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, flags, magic, bp, eax, ebx,  \
0124                ecx, edx, si, di)                                       \
0125     vmw_port_hb(cmd, in_ecx, in_si, in_di, flags, magic, bp,               \
0126             X86_IO_W7_DIR, &eax, &ebx, &ecx, &edx, &si, &di)
0127 
0128 #endif
0129 
0130 #endif /* _VMWGFX_MSG_ARM64_H */