github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/hw/local_apic.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 _LOCAL_APIC_H
    16  #define _LOCAL_APIC_H
    17  
    18  #include "vmm_defs.h"
    19  #include "ia32_defs.h"
    20  
    21  #define CPUID_X2APIC_SUPPORTED_BIT  21
    22  
    23  #define LOCAL_APIC_REG_MSR_BASE             IA32_MSR_x2APIC_BASE
    24  
    25  typedef enum {
    26      LOCAL_APIC_ID_REG                   = 2,
    27      LOCAL_APIC_VERSION_REG              = 3,
    28      LOCAL_APIC_TASK_PRIORITY_REG        = 8,    // TPR
    29      LOCAL_APIC_PROCESSOR_PRIORITY_REG   = 0xA,  // PPR
    30      LOCAL_APIC_EOI_REG                  = 0xB,
    31      LOCAL_APIC_LOGICAL_DESTINATION_REG  = 0xD,
    32      LOCAL_APIC_DESTINATION_FORMAT_REG   = 0xE,  // !!not supported in x2APIC mode!!
    33      LOCAL_APIC_SPURIOUS_INTR_VECTOR_REG = 0xF,
    34      LOCAL_APIC_IN_SERVICE_REG           = 0x10, // ISR  8 sequential registers
    35      LOCAL_APIC_TRIGGER_MODE_REG         = 0x18, // TMR  8 sequential registers
    36      LOCAL_APIC_INTERRUPT_REQUEST_REG    = 0x20, // IRR  8 sequential registers
    37      LOCAL_APIC_ERROR_STATUS_REG         = 0x28,
    38      LOCAL_APIC_INTERRUPT_COMMAND_REG    = 0x30, // 64-bits
    39      LOCAL_APIC_INTERRUPT_COMMAND_HI_REG = 0x31,
    40      LOCAL_APIC_LVT_TIMER_REG            = 0x32,
    41      LOCAL_APIC_LVT_THERMAL_SENSOR_REG   = 0x33,
    42      LOCAL_APIC_LVT_PERF_MONITORING_REG  = 0x34,
    43      LOCAL_APIC_LVT_LINT0_REG            = 0x35,
    44      LOCAL_APIC_LVT_LINT1_REG            = 0x36,
    45      LOCAL_APIC_LVT_ERROR_REG            = 0x37,
    46      LOCAL_APIC_INITIAL_COUNTER_REG      = 0x38,
    47      LOCAL_APIC_CURRENT_COUNTER_REG      = 0x39,
    48      LOCAL_APIC_DIVIDE_CONFIGURATION_REG = 0x3E,
    49      LOCAL_APIC_SELF_IPI_REG             = 0x40 // !!valid for x2APIC mode only!!
    50  } LOCAL_APIC_REG_ID;
    51  
    52  typedef enum {
    53      LOCAL_APIC_DISABLED,
    54      LOCAL_APIC_ENABLED,
    55      LOCAL_APIC_X2_ENABLED
    56  } LOCAL_APIC_MODE;
    57  
    58  typedef enum {
    59      LOCAL_APIC_NOERROR = 0,
    60      LOCAL_APIC_ACCESS_WHILE_DISABLED_ERROR  = 1,
    61      LOCAL_APIC_X2_NOT_SUPPORTED             = 2,
    62      LOCAL_APIC_INVALID_REGISTER_ERROR       = 3,
    63      LOCAL_APIC_RESERVED_REGISTER_ERROR      = 4,
    64      LOCAL_APIC_INVALID_RW_ACCESS_ERROR      = 5,
    65      LOCAL_APIC_REGISTER_MMIO_ACCESS_DISABLED_ERROR = 6,
    66      LOCAL_APIC_REGISTER_MSR_ACCESS_DISABLED_ERROR = 7,
    67      LOCAL_APIC_REGISTER_ACCESS_LENGTH_ERROR = 8,
    68  } LOCAL_APIC_ERRNO;
    69  
    70  
    71  //   IPI-related
    72  typedef IA32_ICR_LOW  LOCAL_APIC_INTERRUPT_COMMAND_REGISTER_LOW;
    73  typedef IA32_ICR_HIGH LOCAL_APIC_INTERRUPT_COMMAND_REGISTER_HIGH;
    74  typedef IA32_ICR      LOCAL_APIC_INTERRUPT_COMMAND_REGISTER;
    75  
    76  typedef enum _LOCAL_APIC_IPI_DELIVERY_MODE
    77  {
    78      IPI_DELIVERY_MODE_FIXED           = LOCAL_APIC_DELIVERY_MODE_FIXED,
    79      IPI_DELIVERY_MODE_LOWEST_PRIORITY = LOCAL_APIC_DELIVERY_MODE_LOWEST_PRIORITY,
    80      IPI_DELIVERY_MODE_SMI             = LOCAL_APIC_DELIVERY_MODE_SMI,
    81      IPI_DELIVERY_REMOTE_READ          = LOCAL_APIC_DELIVERY_MODE_REMOTE_READ,
    82      IPI_DELIVERY_MODE_NMI             = LOCAL_APIC_DELIVERY_MODE_NMI,
    83      IPI_DELIVERY_MODE_INIT            = LOCAL_APIC_DELIVERY_MODE_INIT,
    84      IPI_DELIVERY_MODE_START_UP        = LOCAL_APIC_DELIVERY_MODE_SIPI
    85  } LOCAL_APIC_IPI_DELIVERY_MODE;
    86  
    87  typedef enum _LOCAL_APIC_IPI_DESTINATION_MODE
    88  {
    89      IPI_DESTINATION_MODE_PHYSICAL     = LOCAL_APIC_DESTINATION_MODE_PHYSICAL,
    90      IPI_DESTINATION_MODE_LOGICAL      = LOCAL_APIC_DESTINATION_MODE_LOGICAL
    91  } LOCAL_APIC_IPI_DESTINATION_MODE;
    92  
    93  typedef enum _LOCAL_APIC_IPI_DELIVERY_STATUS
    94  {
    95      IPI_DELIVERY_STATUS_IDLE          = LOCAL_APIC_DELIVERY_STATUS_IDLE,
    96      IPI_DELIVERY_STATUS_SEND_PENDING  = LOCAL_APIC_DELIVERY_STATUS_SEND_PENDING
    97  } LOCAL_APIC_IPI_DELIVERY_STATUS;
    98  
    99  typedef enum _LOCAL_APIC_IPI_LEVEL
   100  {
   101      IPI_DELIVERY_LEVEL_DEASSERT       = LOCAL_APIC_DELIVERY_LEVEL_DEASSERT,
   102      IPI_DELIVERY_LEVEL_ASSERT         = LOCAL_APIC_DELIVERY_LEVEL_ASSERT
   103  } LOCAL_APIC_IPI_LEVEL;
   104  
   105  typedef enum _LOCAL_APIC_IPI_TRIGGER_MODE
   106  {
   107      IPI_DELIVERY_TRIGGER_MODE_EDGE    = LOCAL_APIC_TRIGGER_MODE_EDGE,
   108      IPI_DELIVERY_TRIGGER_MODE_LEVEL   = LOCAL_APIC_TRIGGER_MODE_LEVEL
   109  } LOCAL_APIC_IPI_TRIGGER_MODE;
   110  
   111  typedef enum _LOCAL_APIC_IPI_DESTINATION_SHORTHAND
   112  {
   113      IPI_DST_NO_SHORTHAND              = LOCAL_APIC_BROADCAST_MODE_SPECIFY_CPU,
   114      IPI_DST_SELF                      = LOCAL_APIC_BROADCAST_MODE_SELF,
   115      IPI_DST_ALL_INCLUDING_SELF        = LOCAL_APIC_BROADCAST_MODE_ALL_INCLUDING_SELF,
   116      IPI_DST_ALL_EXCLUDING_SELF        = LOCAL_APIC_BROADCAST_MODE_ALL_EXCLUDING_SELF,
   117      //For vmm, not for APIC purpose, it behaves like IPI_DST_ALL_EXCLUDING_SELF
   118      IPI_DST_CORE_ID_BITMAP            = 0xFFF
   119  } LOCAL_APIC_IPI_DESTINATION_SHORTHAND;
   120  
   121  
   122  // must be called on BSP before any other function
   123  BOOLEAN local_apic_init( UINT16 num_of_cpus );
   124  
   125  // must be called on each host cpu (after local_apic_init())
   126  BOOLEAN local_apic_cpu_init(void);
   127  
   128  
   129  // update lapic cpu id. (must be called after S3 or  Local APIC host base was changed per cpu)
   130  BOOLEAN update_lapic_cpu_id(void);
   131  
   132  // must be called when Local APIC host base was changed per cpu
   133  void local_apic_setup_changed(void);
   134  
   135  BOOLEAN validate_APIC_BASE_change(UINT64);
   136  
   137  // return value for current host cpu
   138  ADDRESS lapic_base_address_hpa(void);
   139  ADDRESS lapic_base_address_hva(void);
   140  
   141  // control host Local APIC per cpu
   142  LOCAL_APIC_MODE  local_apic_get_mode(void);
   143  LOCAL_APIC_ERRNO local_apic_set_mode(LOCAL_APIC_MODE mode);
   144  
   145  LOCAL_APIC_ERRNO local_apic_access(
   146                      LOCAL_APIC_REG_ID    reg_id,
   147                      RW_ACCESS            rw_access,
   148                      void                *data,
   149                      INT32                bytes_to_deliver,
   150                      INT32               *p_bytes_delivered);
   151  
   152  
   153  BOOLEAN local_apic_send_ipi(
   154                      LOCAL_APIC_IPI_DESTINATION_SHORTHAND dst_shorthand,
   155                      UINT8  dst,
   156                      LOCAL_APIC_IPI_DESTINATION_MODE dst_mode,
   157                      LOCAL_APIC_IPI_DELIVERY_MODE delivery_mode,
   158                      UINT8  vector,
   159                      LOCAL_APIC_IPI_LEVEL level,
   160                      LOCAL_APIC_IPI_TRIGGER_MODE trigger_mode);
   161  
   162  // returns current Local APIC ID suitable for IPIs with FIXED destination mode
   163  UINT8 local_apic_get_current_id( void );
   164  
   165  // this function should not return
   166  void local_apic_send_init_to_self( void );
   167  
   168  void local_apic_send_init( CPU_ID dst );
   169  
   170  
   171  // returns TRUE is any of Local APIC modes is SW-enabled
   172  // If Local APIC is either HW disabled or SW-disabled, return FALSE
   173  BOOLEAN local_apic_is_sw_enabled(void);
   174  
   175  // Test for ready-to-be-accepted fixed interrupts.
   176  BOOLEAN local_apic_is_ready_interrupt_exist(void);
   177  
   178  #endif
   179