github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/ipc.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 _IPC_H
    16  #define _IPC_H
    17  
    18  #include "local_apic.h"
    19  #include "vmm_objects.h"
    20  #include "common_types.h"
    21  
    22  /// %VT% typedef struct _GUEST_CPU       *GUEST_CPU_HANDLE;
    23  
    24  typedef struct _IPC_DESTINATION
    25  {
    26      LOCAL_APIC_IPI_DESTINATION_SHORTHAND addr_shorthand;
    27      UINT8 addr;
    28      UINT8 padding[3];
    29      UINT64 CoreBitMap[CPU_BITMAP_MAX];
    30  } IPC_DESTINATION;
    31  
    32  typedef enum
    33  {
    34      IPC_TYPE_NORMAL,
    35      IPC_TYPE_START,
    36      IPC_TYPE_STOP,
    37      IPC_TYPE_SYNC,
    38      IPC_TYPE_LAST
    39  } IPC_MESSAGE_TYPE;
    40  
    41  
    42  // FUNCTION:        ipc_initialize
    43  // DESCRIPTION:     Initialize IPC engine. Must be called before any IPCs can be generated.
    44  // RETURN VALUE:    TRUE for success, FALSE for failure
    45  BOOLEAN ipc_initialize(UINT16 number_of_host_processors);
    46  
    47  // FUNCTION:        ipc_guest_initialize
    48  // DESCRIPTION:     Initialize stop/start context and initialize IPC engine for a guest. Must be called when new guest is added.
    49  // RETURN VALUE:    TRUE for success, FALSE for failure
    50  BOOLEAN ipc_guest_initialize(GUEST_ID guest_id);
    51  
    52  // FUNCTION:        ipc_finalize
    53  // DESCRIPTION:     Destroy IPC engine. ipc_initialize must be called before any IPCs can be generated.
    54  void ipc_finalize(void);
    55  
    56  // FUNCTION:        ipc_change_state_to_active
    57  // DESCRIPTION:     CPU cannot receive IPC if in Wait-for-SIPI state.
    58  //                  This function marks the CPU on which it is executed
    59  //                  as capable of receiving IPCs after leaving Wait-for-SIPI state.
    60  void ipc_change_state_to_active(GUEST_CPU_HANDLE gcpu);
    61  
    62  // FUNCTION:        ipc_change_state_to_sipi
    63  // DESCRIPTION:     CPU cannot receive IPC if in Wait-for-SIPI state.
    64  //                  This function marks the CPU on which it is executed
    65  //                  as NOT capable of receiving IPCs due to transitioning to Wait-for-SIPI state.
    66  void ipc_change_state_to_sipi(GUEST_CPU_HANDLE gcpu);
    67  
    68  // FUNCTION:        ipc_process_one_ipc
    69  // DESCRIPTION:     Process single IPC from this CPU's IPC queue.
    70  // RETURN VALUE:    TRUE if a message was processed, FALSE if the queue was empty
    71  BOOLEAN ipc_process_one_ipc(void);
    72  
    73  // IPC_HANDLER_FN -- type of function that is executed on other CPUs
    74  typedef void (*IPC_HANDLER_FN)(CPU_ID from, void* arg);
    75  
    76  // FUNCTION:        ipc_execute_handler
    77  // DESCRIPTION:     Execute handler on other CPUs. This function returns when all destination
    78  //                  CPUs are about to execute the handler
    79  // ARGUMENTS:       dst -- destination CPU(s)
    80  //                  handler -- handler for execution
    81  //                  arg -- argument to pass to the handler
    82  // RETURN VALUE:    number of CPUs on which handler is about to execute
    83  UINT32 ipc_execute_handler(IPC_DESTINATION dst, IPC_HANDLER_FN handler, void* arg);
    84  
    85  // FUNCTION:        ipc_execute_handler
    86  // DESCRIPTION:     Execute handler on other CPUs. This function returns when all destination
    87  //                  CPUs finished to execute the handler
    88  // ARGUMENTS:       dst -- destination CPU(s)
    89  //                  handler -- handler for execution
    90  //                  arg -- argument to pass to the handler
    91  // RETURN VALUE:    number of CPUs on which handler is about to execute
    92  UINT32 ipc_execute_handler_sync(IPC_DESTINATION dst, IPC_HANDLER_FN handler, void* arg);
    93  
    94  // FUNCTION:        stop_all_cpus
    95  // DESCRIPTION:     Stop all other CPUs. Other CPUs will be executing the busy loop until
    96  //                  they are resumed by calling start_all_cpus()
    97  // RETURN VALUE:    TRUE if all processors has stopped, FALSE in case of failure
    98  BOOLEAN stop_all_cpus(void);
    99  
   100  // FUNCTION:        start_all_cpus
   101  // DESCRIPTION:     Start all other CPUs previously stopped by stop_all_cpus().
   102  //                  Execute handler upon start.
   103  // RETURN VALUE:    number of CPUs on which handler is about to execute
   104  UINT32 start_all_cpus(IPC_HANDLER_FN handler, void* arg);
   105  
   106  // FUNCTION:        stop_all_guest_cpus
   107  // DESCRIPTION:     Stop all CPUs running given guest. These CPUs will be executing the busy loop until
   108  //                  they are resumed by calling start_all_guest_cpus()
   109  // RETURN VALUE:    TRUE if CPUs running guest has stopped, FALSE in case of failure
   110  BOOLEAN stop_all_guest_cpus(GUEST_HANDLE guest);
   111  
   112  // FUNCTION:        start_all_guest_cpus
   113  // DESCRIPTION:     Start all CPUs running given guest, previously stopped by stop_all_guest_cpus().
   114  //                  Execute handler upon start.
   115  // RETURN VALUE:    number of CPUs on which handler is about to execute
   116  UINT32 start_all_guest_cpus(GUEST_HANDLE guest, IPC_HANDLER_FN handler, void* arg);
   117  
   118  // FUNCTION:        ipc_mni_injection_failed
   119  // DESCRIPTION:     Called when NMI injection to guest failed and should be performed once more later.
   120  void ipc_mni_injection_failed(void);
   121  
   122  // FUNCTION:        ipc_send_message
   123  // DESCRIPTION:     Send IPC to destination CPUs. Returns just before handlers are about to execute.
   124  // RETURN VALUE:    number of CPUs on which handler is about to execute
   125  UINT32 ipc_send_message(IPC_DESTINATION dst, IPC_MESSAGE_TYPE type, IPC_HANDLER_FN handler, void* arg);
   126  
   127  // FUNCTION:        ipc_send_message_sync
   128  // DESCRIPTION:     Send IPC to destination CPUs. Returns after handlers finished their execution
   129  // RETURN VALUE:    number of CPUs on which handler is about to execute
   130  UINT32 ipc_send_message_sync(IPC_DESTINATION dst, IPC_MESSAGE_TYPE type, IPC_HANDLER_FN handler, void* arg);
   131  
   132  // FUNCTION:        ipc_nmi_vmexit_handler
   133  // DESCRIPTION:     NMI Vmexit handler.
   134  // RETURN VALUE:    TRUE, if NMI handled by handler, FALSE if it should be handled by guest.
   135  BOOLEAN ipc_nmi_vmexit_handler(GUEST_CPU_HANDLE gcpu);
   136  
   137  // FUNCTION:        ipc_nmi_window_vmexit_handler
   138  // DESCRIPTION:     NMI Window Vmexit handler.
   139  // RETURN VALUE:    TRUE, if NMI handled by handler, FALSE if it should be handled by guest.
   140  BOOLEAN ipc_nmi_window_vmexit_handler(GUEST_CPU_HANDLE gcpu);
   141  
   142  // FUNCTION:        ipc_sipi_vmexit_handler
   143  // DESCRIPTION:     Handle IPC if SIPI was due to IPC.
   144  // RETURN VALUE:    TRUE, if SIPI was due to IPC, FALSE otherwise.
   145  BOOLEAN ipc_sipi_vmexit_handler(GUEST_CPU_HANDLE gcpu);
   146  
   147  void ipc_print_cpu_context(CPU_ID cpu_id, BOOLEAN use_lock);
   148  
   149  #endif