github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/common/include/vmcall_api.h (about)

     1  /*
     2   * Copyright (c) 2013 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *     http://www.apache.org/licenses/LICENSE-2.0
     8   * Unless required by applicable law or agreed to in writing, software
     9   * distributed under the License is distributed on an "AS IS" BASIS,
    10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11   * See the License for the specific language governing permissions and
    12   * limitations under the License.
    13   */
    14  
    15  #ifndef _VMCALL_API_H_
    16  #define _VMCALL_API_H_
    17  
    18  #include "vmm_defs.h"
    19  
    20  typedef enum _VMCALL_ID {
    21      VMCALL_IS_UVMM_RUNNING,
    22      VMCALL_EMULATOR_TERMINATE,
    23      VMCALL_EMULATOR_CLI_ACTIVATE,
    24      VMCALL_EMULATOR_PUTS,
    25      VMCALL_REGISTER_DEVICE_DRIVER,
    26      VMCALL_UNREGISTER_DEVICE_DRIVER,
    27      VMCALL_DEVICE_DRIVER_IOCTL,
    28      VMCALL_DEVICE_DRIVER_ACK_NOTIFICATION,
    29      VMCALL_PRINT_DEBUG_MESSAGE,
    30      VMCALL_ADD_SHARED_MEM,
    31      VMCALL_REMOVE_SHARED_MEM,
    32      VMCALL_WRITE_STRING,
    33      VMCALL_TMSL,
    34  
    35      VMCALL_UPDATE_LVT,        // Temporary for TSC deadline debugging
    36  
    37  #ifdef ENABLE_TMSL_PROFILING
    38           VMCALL_TMSL_PROFILING = 1022,  // for tmsl profiling.
    39  #endif
    40  
    41      VMCALL_LAST_USED_INTERNAL = 1024  // must be the last
    42  } VMCALL_ID;
    43  
    44  #ifdef __GNUC__
    45  
    46  #define API_FUNCTION
    47  #define ASM_FUNCTION
    48  #define CDECL
    49  #define STDCALL
    50  
    51  #else // MS Compiler
    52  
    53  #define API_FUNCTION    __stdcall
    54  #define ASM_FUNCTION    __stdcall
    55  #define STDCALL         __stdcall
    56  
    57  #ifndef UNITTESTING
    58  #define CDECL           __cdecl
    59  #endif
    60  
    61  #endif
    62  
    63  
    64  #define VMM_NATIVE_VMCALL_SIGNATURE                                            \
    65      (  ((UINT32)'$' << 24)                                                     \
    66      |  ((UINT32)'i' << 16)                                                     \
    67      |  ((UINT32)'M' << 8)                                                      \
    68      |  ((UINT32)'@' << 0)                                                      \
    69      )
    70  
    71  // FUNCTION : hw_vmcall()
    72  // PURPOSE  : Call for VMM service from the guest environment
    73  // ARGUMENTS: VMCALL_ID vmcall_id + 3 extra arguments
    74  // RETURNS  : VMM_OK = ok, other - error code
    75  #ifndef UVMM_DRIVER_BUILD
    76  VMM_STATUS ASM_FUNCTION hw_vmcall( VMCALL_ID vmcall_id, void* arg1, void* arg2, void* arg3 );
    77  #else
    78  VMM_STATUS CDECL hw_vmcall( VMCALL_ID vmcall_id, void* arg1, void* arg2, void* arg3 );
    79  #endif
    80  
    81  
    82  typedef struct VMM_IS_UVMM_RUNNING_PARAMS_S {
    83      VMCALL_ID vmcall_id;                   // IN must be "VMCALL_IS_UVMM_RUNNING"
    84  
    85      UINT32 version;                        // OUT - currently will be 0
    86  } VMM_IS_UVMM_RUNNING_PARAMS;
    87  
    88  // FUNCTION : hw_vmcall_is_uvmm_running()
    89  // PURPOSE  : Call for VMM service for quering whether uVMM is running
    90  // ARGUMENTS: param - pointer to "VMM_IS_UVMM_RUNNING_PARAMS" structure
    91  // RETURNS  : VMM_OK = ok, other - error code
    92  //
    93  // VMM_STATUS hw_vmcall_is_uvmm_running(VMM_IS_UVMM_RUNNING_PARAMS* param);
    94  #define hw_vmcall_is_uvmm_running(is_uvmm_running_params_ptr) \
    95      hw_vmcall(VMCALL_IS_UVMM_RUNNING, (is_uvmm_running_params_ptr), NULL, NULL)
    96  
    97  
    98  typedef struct VMM_DEVICE_DRIVER_REGISTRATION_PARAMS_S {
    99      VMCALL_ID vmcall_id;                   // IN must be "VMCALL_REGISTER_DEVICE_DRIVER"
   100      BOOLEAN is_initially_masked;           // IN
   101      volatile UINT64 notification_area_gva; // IN pointer to BOOLEAN polling variable
   102  
   103      UINT64 descriptor_handle;              // OUT
   104  } VMM_DEVICE_DRIVER_REGISTRATION_PARAMS;
   105  
   106  
   107  // FUNCTION : hw_vmcall_register_driver()
   108  // PURPOSE  : Call for VMM service for registering device driver
   109  // ARGUMENTS: param - pointer to "VMM_DEVICE_DRIVER_REGISTRATION_PARAMS" structure
   110  // RETURNS  : VMM_OK = ok, other - error code
   111  //
   112  // VMM_STATUS hw_vmcall_register_driver(VMM_DEVICE_DRIVER_REGISTRATION_PARAMS* param);
   113  #define hw_vmcall_register_driver(driver_registration_params_ptr) \
   114      hw_vmcall(VMCALL_REGISTER_DEVICE_DRIVER, (driver_registration_params_ptr), NULL, NULL)
   115  
   116  
   117  typedef struct VMM_DEVICE_DRIVER_UNREGISTRATION_PARAMS_S {
   118      VMCALL_ID vmcall_id;                   // IN must be "VMCALL_UNREGISTER_DEVICE_DRIVER"
   119      UINT8 padding[4];
   120      UINT64 descriptor_handle;              // IN descriptor_handle received upon registration
   121  } VMM_DEVICE_DRIVER_UNREGISTRATION_PARAMS;
   122  
   123  
   124  // FUNCTION : hw_vmcall_unregister_driver()
   125  // PURPOSE  : Call for VMM service for unregistering device driver
   126  // ARGUMENTS: param - pointer to "VMM_DEVICE_DRIVER_UNREGISTRATION_PARAMS" structure
   127  // RETURNS  : VMM_OK = ok, other - error code
   128  // VMM_STATUS hw_vmcall_unregister_driver(VMM_DEVICE_DRIVER_UNREGISTRATION_PARAMS* param);
   129  #define hw_vmcall_unregister_driver(driver_unregistration_params_ptr) \
   130      hw_vmcall(VMCALL_UNREGISTER_DEVICE_DRIVER, (driver_unregistration_params_ptr), NULL, NULL)
   131  
   132  typedef enum {
   133      VMM_DEVICE_DRIVER_IOCTL_MASK_NOTIFICATION,
   134      VMM_DEVICE_DRIVER_IOCTL_UNMASK_NOTIFICATION,
   135  } VMM_DEVICE_DRIVER_IOCTL_ID;
   136  
   137  typedef struct VMM_DEVICE_DRIVER_IOCTL_PARAMS_S {
   138     VMCALL_ID vmcall_id;                   // IN must be "VMCALL_DEVICE_DRIVER_IOCTL"
   139     VMM_DEVICE_DRIVER_IOCTL_ID ioctl_id;   // IN id of the ioctl operation
   140     UINT64 descriptor_handle;              // IN descriptor_handle received upon registration
   141  } VMM_DEVICE_DRIVER_IOCTL_PARAMS;
   142  
   143  /*-----------------------------------------------------------------------------*
   144  *  FUNCTION : hw_vmcall_driver_ioctl()
   145  *  PURPOSE  : Call for VMM service for controlling device driver
   146  *  ARGUMENTS: param - pointer to "VMM_DEVICE_DRIVER_IOCTL_PARAMS" structure
   147  *  RETURNS  : VMM_OK = ok, other - error code
   148  *
   149  *  VMM_STATUS hw_vmcall_driver_ioctl(VMM_DEVICE_DRIVER_IOCTL_PARAMS* param);
   150  *-----------------------------------------------------------------------------*/
   151  #define hw_vmcall_driver_ioctl(driver_ioctl_params_ptr) \
   152      hw_vmcall(VMCALL_DEVICE_DRIVER_IOCTL, (driver_ioctl_params_ptr), NULL, NULL)
   153  
   154  //=================================================================================
   155  
   156  typedef struct VMM_DEVICE_DRIVER_ACK_NOTIFICATION_PARAMS_S {
   157      VMCALL_ID vmcall_id;                   // IN must be "VMCALL_DEVICE_DRIVER_ACK_NOTIFICATION"
   158      UINT8 padding[4];
   159      UINT64 descriptor_handle;              // IN descriptor_handle received upon registration
   160  
   161      UINT64 compontents_that_require_attention; // OUT - bitmask of components that require attention
   162  } VMM_DEVICE_DRIVER_ACK_NOTIFICATION_PARAMS;
   163  
   164  
   165  // FUNCTION : hw_vmcall_driver_ack_notification()
   166  // PURPOSE  : Call for VMM service for acknoledging notification
   167  // ARGUMENTS: param - pointer to "DEVICE_DRIVER_ACK_NOTIFICATION_PARAMS" structure
   168  // RETURNS  : VMM_OK = ok, other - error code
   169  //
   170  // VMM_STATUS hw_vmcall_driver_ack_notification(DEVICE_DRIVER_ACK_NOTIFICATION_PARAMS* param);
   171  #define hw_vmcall_driver_ack_notification(driver_ioctl_params_ptr) \
   172      hw_vmcall(VMCALL_DEVICE_DRIVER_ACK_NOTIFICATION, (driver_ioctl_params_ptr), NULL, NULL)
   173  
   174  
   175  #define VMM_MAX_DEBUG_MESSAGE_SIZE      252
   176  typedef struct VMM_PRINT_DEBUG_MESSAGE_PARAMS_S {
   177      VMCALL_ID vmcall_id;                        // IN - must have "VMCALL_PRINT_DEBUG_MESSAGE" value
   178      char message[VMM_MAX_DEBUG_MESSAGE_SIZE];
   179  } VMM_PRINT_DEBUG_MESSAGE_PARAMS;
   180  
   181  // FUNCTION : hw_vmcall_print_debug_message()
   182  // PURPOSE  : Call for VMM service for printing debug message
   183  // ARGUMENTS: param - pointer to "VMM_PRINT_DEBUG_MESSAGE_PARAMS" structure
   184  // RETURNS  : VMM_OK = ok, other - error code
   185  //
   186  // VMM_STATUS hw_vmcall_print_debug_message(VMM_PRINT_DEBUG_MESSAGE_PARAMS* param);
   187  #define hw_vmcall_print_debug_message(debug_message_params_ptr) \
   188      hw_vmcall(VMCALL_PRINT_DEBUG_MESSAGE, (debug_message_params_ptr), NULL, NULL)
   189  
   190  
   191  typedef struct VMM_ADD_SHARED_MEM_PARAMS{
   192          VMCALL_ID vmcall_id;
   193          UINT8 padding[4];
   194          UINT64 GuestVirtualAddress;
   195          UINT32 BufSize;
   196          int uVMMMemHandle;
   197          VMM_STATUS status;
   198          UINT8 padding2[4];
   199  } VMM_ADD_SHARED_MEM_PARAMS;
   200  
   201  typedef struct VMM_REMOVE_SHARED_MEM_PARAMS{
   202          VMCALL_ID vmcall_id;
   203          int uVMMMemHandle;
   204          VMM_STATUS status;
   205  
   206  } VMM_REMOVE_SHARED_MEM_PARAMS;
   207  
   208  typedef struct VMM_WRITE_STRING_PARAMS{
   209          VMCALL_ID vmcall_id;
   210          int uVMMMemHandle;
   211          char  buf[100];
   212          UINT32 len;
   213          VMM_STATUS status;
   214  
   215  } VMM_WRITE_STRING_PARAMS;
   216  
   217  
   218  #endif // _VMCALL_API_H_