• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 File to contain all the hardware specific stuff for the Smm Sw dispatch protocol.
3 
4 Copyright (c) 2013-2015 Intel Corporation.
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 
17 //
18 // Include common header file for this module.
19 //
20 #include "CommonHeader.h"
21 
22 #include "QNCSmmHelpers.h"
23 
24 EFI_SMM_CPU_PROTOCOL  *mSmmCpu = NULL;
25 
26 CONST QNC_SMM_SOURCE_DESC SW_SOURCE_DESC = {
27   QNC_SMM_NO_FLAGS,
28   {
29     {
30       {GPE_ADDR_TYPE, {R_QNC_GPE0BLK_SMIE}}, S_QNC_GPE0BLK_SMIE, N_QNC_GPE0BLK_SMIE_APM
31     },
32     NULL_BIT_DESC_INITIALIZER
33   },
34   {
35     {
36       {GPE_ADDR_TYPE, {R_QNC_GPE0BLK_SMIS}}, S_QNC_GPE0BLK_SMIS, N_QNC_GPE0BLK_SMIS_APM
37     }
38   }
39 };
40 
41 VOID
SwGetContext(IN DATABASE_RECORD * Record,OUT QNC_SMM_CONTEXT * Context)42 SwGetContext(
43   IN  DATABASE_RECORD    *Record,
44   OUT QNC_SMM_CONTEXT    *Context
45   )
46 {
47   Context->Sw.SwSmiInputValue = IoRead8 (R_APM_CNT);
48 }
49 
50 BOOLEAN
SwCmpContext(IN QNC_SMM_CONTEXT * Context1,IN QNC_SMM_CONTEXT * Context2)51 SwCmpContext (
52   IN QNC_SMM_CONTEXT     *Context1,
53   IN QNC_SMM_CONTEXT     *Context2
54   )
55 {
56   return (BOOLEAN)( Context1->Sw.SwSmiInputValue == Context2->Sw.SwSmiInputValue );
57 }
58 
59 VOID
SwGetBuffer(IN DATABASE_RECORD * Record)60 SwGetBuffer (
61   IN  DATABASE_RECORD     * Record
62   )
63 {
64   EFI_STATUS                 Status;
65   UINTN                      Index;
66   UINTN                      CpuIndex;
67   EFI_SMM_SAVE_STATE_IO_INFO IoState;
68 
69   //
70   // Locate SMM CPU protocol to retrieve the CPU save state
71   //
72   if (mSmmCpu == NULL) {
73     Status = gSmst->SmmLocateProtocol (&gEfiSmmCpuProtocolGuid, NULL, (VOID **) &mSmmCpu);
74     ASSERT_EFI_ERROR (Status);
75   }
76 
77   //
78   // Find the CPU which generated the software SMI
79   //
80   CpuIndex = 0;
81   for (Index = 0; Index < gSmst->NumberOfCpus; Index++) {
82     Status = mSmmCpu->ReadSaveState (
83                         mSmmCpu,
84                         sizeof (EFI_SMM_SAVE_STATE_IO_INFO),
85                         EFI_SMM_SAVE_STATE_REGISTER_IO,
86                         Index,
87                         &IoState
88                         );
89     if (!EFI_ERROR (Status) && (IoState.IoPort == R_APM_CNT)) {
90       CpuIndex = Index;
91       break;
92     }
93   }
94 
95   Record->CommBuffer.Sw.SwSmiCpuIndex = CpuIndex;
96 }
97