Home | History | Annotate | Download | only in CpuRuntimeDxe
      1 /*++ @file
      2 
      3 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
      4 Portions copyright (c) 2011, Apple Inc. All rights reserved.
      5 
      6 This program and the accompanying materials
      7 are licensed and made available under the terms and conditions of the BSD License
      8 which accompanies this distribution.  The full text of the license may be found at
      9 http://opensource.org/licenses/bsd-license.php
     10 
     11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #ifndef _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
     17 #define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
     18 
     19 
     20 #include <PiDxe.h>
     21 #include <IndustryStandard/SmBios.h>
     22 
     23 #include <Protocol/Cpu.h>
     24 #include <Protocol/Smbios.h>
     25 #include <Protocol/MpService.h>
     26 #include <Protocol/EmuThread.h>
     27 #include <Protocol/CpuIo2.h>
     28 
     29 #include <Guid/IdleLoopEvent.h>
     30 
     31 #include <Library/BaseLib.h>
     32 #include <Library/DebugLib.h>
     33 #include <Library/UefiDriverEntryPoint.h>
     34 #include <Library/BaseMemoryLib.h>
     35 #include <Library/MemoryAllocationLib.h>
     36 #include <Library/UefiBootServicesTableLib.h>
     37 #include <Library/EmuThunkLib.h>
     38 #include <Library/UefiLib.h>
     39 #include <Library/PcdLib.h>
     40 
     41 
     42 
     43 //
     44 // Internal Data Structures
     45 //
     46 #define CPU_ARCH_PROT_PRIVATE_SIGNATURE SIGNATURE_32 ('c', 'a', 'p', 'd')
     47 
     48 typedef struct {
     49   UINTN                 Signature;
     50   EFI_HANDLE            Handle;
     51 
     52   EFI_CPU_ARCH_PROTOCOL Cpu;
     53   EFI_CPU_IO2_PROTOCOL  CpuIo;
     54 
     55   //
     56   // Local Data for CPU interface goes here
     57   //
     58   BOOLEAN               InterruptState;
     59 
     60 } CPU_ARCH_PROTOCOL_PRIVATE;
     61 
     62 #define CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \
     63   CR (a, \
     64       CPU_ARCH_PROTOCOL_PRIVATE, \
     65       Cpu, \
     66       CPU_ARCH_PROT_PRIVATE_SIGNATURE \
     67       )
     68 
     69 
     70 
     71 typedef enum {
     72   CPU_STATE_IDLE,
     73   CPU_STATE_BLOCKED,
     74   CPU_STATE_READY,
     75   CPU_STATE_BUSY,
     76   CPU_STATE_FINISHED
     77 } PROCESSOR_STATE;
     78 
     79 
     80 //
     81 // Define Individual Processor Data block.
     82 //
     83 typedef struct {
     84   EFI_PROCESSOR_INFORMATION   Info;
     85   EFI_AP_PROCEDURE            Procedure;
     86   VOID                        *Parameter;
     87   VOID                        *StateLock;
     88   VOID                        *ProcedureLock;
     89   PROCESSOR_STATE             State;
     90   EFI_EVENT                   CheckThisAPEvent;
     91 } PROCESSOR_DATA_BLOCK;
     92 
     93 
     94 //
     95 // Define MP data block which consumes individual processor block.
     96 //
     97 typedef struct {
     98   UINTN                       NumberOfProcessors;
     99   UINTN                       NumberOfEnabledProcessors;
    100   EFI_EVENT                   CheckAllAPsEvent;
    101   EFI_EVENT                   WaitEvent;
    102   UINTN                       FinishCount;
    103   UINTN                       StartCount;
    104   EFI_AP_PROCEDURE            Procedure;
    105   VOID                        *ProcedureArgument;
    106   BOOLEAN                     SingleThread;
    107   UINTN                       StartedNumber;
    108   PROCESSOR_DATA_BLOCK        *ProcessorData;
    109   UINTN                       Timeout;
    110   UINTN                       *FailedList;
    111   UINTN                       FailedListIndex;
    112   BOOLEAN                     TimeoutActive;
    113 } MP_SYSTEM_DATA;
    114 
    115 
    116 
    117 
    118 
    119 EFI_STATUS
    120 EFIAPI
    121 CpuMemoryServiceRead (
    122   IN  EFI_CPU_IO2_PROTOCOL              *This,
    123   IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,
    124   IN  UINT64                            Address,
    125   IN  UINTN                             Count,
    126   IN  OUT VOID                          *Buffer
    127   );
    128 
    129 EFI_STATUS
    130 EFIAPI
    131 CpuMemoryServiceWrite (
    132   IN EFI_CPU_IO2_PROTOCOL               *This,
    133   IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,
    134   IN  UINT64                            Address,
    135   IN  UINTN                             Count,
    136   IN  OUT VOID                          *Buffer
    137   );
    138 
    139 EFI_STATUS
    140 EFIAPI
    141 CpuIoServiceRead (
    142   IN EFI_CPU_IO2_PROTOCOL               *This,
    143   IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,
    144   IN  UINT64                            UserAddress,
    145   IN  UINTN                             Count,
    146   IN  OUT VOID                          *UserBuffer
    147   );
    148 
    149 EFI_STATUS
    150 EFIAPI
    151 CpuIoServiceWrite (
    152   IN EFI_CPU_IO2_PROTOCOL               *This,
    153   IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,
    154   IN  UINT64                            UserAddress,
    155   IN  UINTN                             Count,
    156   IN  OUT VOID                          *UserBuffer
    157   );
    158 
    159 EFI_STATUS
    160 EFIAPI
    161 InitializeCpu (
    162   IN EFI_HANDLE        ImageHandle,
    163   IN EFI_SYSTEM_TABLE  *SystemTable
    164   );
    165 
    166 EFI_STATUS
    167 EFIAPI
    168 EmuFlushCpuDataCache (
    169   IN EFI_CPU_ARCH_PROTOCOL  *This,
    170   IN EFI_PHYSICAL_ADDRESS   Start,
    171   IN UINT64                 Length,
    172   IN EFI_CPU_FLUSH_TYPE     FlushType
    173   );
    174 
    175 EFI_STATUS
    176 EFIAPI
    177 EmuEnableInterrupt (
    178   IN EFI_CPU_ARCH_PROTOCOL  *This
    179   );
    180 
    181 EFI_STATUS
    182 EFIAPI
    183 EmuDisableInterrupt (
    184   IN EFI_CPU_ARCH_PROTOCOL  *This
    185   );
    186 
    187 EFI_STATUS
    188 EFIAPI
    189 EmuGetInterruptState (
    190   IN EFI_CPU_ARCH_PROTOCOL  *This,
    191   OUT BOOLEAN               *State
    192   );
    193 
    194 EFI_STATUS
    195 EFIAPI
    196 EmuInit (
    197   IN EFI_CPU_ARCH_PROTOCOL  *This,
    198   IN EFI_CPU_INIT_TYPE      InitType
    199   );
    200 
    201 EFI_STATUS
    202 EFIAPI
    203 EmuRegisterInterruptHandler (
    204   IN EFI_CPU_ARCH_PROTOCOL      *This,
    205   IN EFI_EXCEPTION_TYPE         InterruptType,
    206   IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler
    207   );
    208 
    209 EFI_STATUS
    210 EFIAPI
    211 EmuGetTimerValue (
    212   IN  EFI_CPU_ARCH_PROTOCOL *This,
    213   IN  UINT32                TimerIndex,
    214   OUT UINT64                *TimerValue,
    215   OUT UINT64                *TimerPeriod OPTIONAL
    216   );
    217 
    218 EFI_STATUS
    219 EFIAPI
    220 EmuSetMemoryAttributes (
    221   IN EFI_CPU_ARCH_PROTOCOL  *This,
    222   IN EFI_PHYSICAL_ADDRESS   BaseAddress,
    223   IN UINT64                 Length,
    224   IN UINT64                 Attributes
    225   );
    226 
    227 EFI_STATUS
    228 CpuMpServicesInit (
    229   OUT UINTN *MaxCores
    230   );
    231 
    232 EFI_STATUS
    233 EFIAPI
    234 CpuMpServicesWhoAmI (
    235   IN EFI_MP_SERVICES_PROTOCOL  *This,
    236   OUT UINTN                    *ProcessorNumber
    237   );
    238 
    239 extern EFI_MP_SERVICES_PROTOCOL  mMpServicesTemplate;
    240 
    241 
    242 #endif
    243