1 /** @file
2   File to contain all the hardware specific stuff for the Smm Power Button dispatch protocol.
3 
4   Copyright (c) 2019 Intel Corporation. All rights reserved. <BR>
5 
6   SPDX-License-Identifier: BSD-2-Clause-Patent
7 **/
8 
9 #include <PchSmmHelpers.h>
10 #include <Private/Library/PmcPrivateLib.h>
11 
12 GLOBAL_REMOVE_IF_UNREFERENCED CONST PCH_SMM_SOURCE_DESC mPowerButtonSourceDesc = {
13   PCH_SMM_SCI_EN_DEPENDENT,
14   {
15     {
16       {
17         ACPI_ADDR_TYPE,
18         {R_ACPI_IO_PM1_EN}
19       },
20       S_ACPI_IO_PM1_EN,
21       N_ACPI_IO_PM1_EN_PWRBTN
22     },
23     NULL_BIT_DESC_INITIALIZER
24   },
25   {
26     {
27       {
28         ACPI_ADDR_TYPE,
29         {R_ACPI_IO_PM1_STS}
30       },
31       S_ACPI_IO_PM1_STS,
32       N_ACPI_IO_PM1_STS_PWRBTN
33     }
34   },
35   {
36     {
37       ACPI_ADDR_TYPE,
38       {R_ACPI_IO_SMI_STS}
39     },
40     S_ACPI_IO_SMI_STS,
41     N_ACPI_IO_SMI_STS_PM1_STS_REG
42   }
43 };
44 
45 /**
46   Get the power button status.
47 
48   @param[in] Record               The pointer to the DATABASE_RECORD.
49   @param[out] Context             Calling context from the hardware, will be updated with the current power button status.
50 
51 **/
52 VOID
53 EFIAPI
PowerButtonGetContext(IN DATABASE_RECORD * Record,OUT PCH_SMM_CONTEXT * Context)54 PowerButtonGetContext (
55   IN  DATABASE_RECORD    *Record,
56   OUT PCH_SMM_CONTEXT    *Context
57   )
58 {
59   if (PmcGetPwrBtnLevel ()) {
60     Context->PowerButton.Phase = EfiPowerButtonExit;
61   } else {
62     Context->PowerButton.Phase = EfiPowerButtonEntry;
63   }
64 }
65 
66 /**
67   Check whether Power Button status of two contexts match
68 
69   @param[in] Context1             Context 1 that includes Power Button status 1
70   @param[in] Context2             Context 2 that includes Power Button status 2
71 
72   @retval FALSE                   Power Button status match
73   @retval TRUE                    Power Button status don't match
74 **/
75 BOOLEAN
76 EFIAPI
PowerButtonCmpContext(IN PCH_SMM_CONTEXT * Context1,IN PCH_SMM_CONTEXT * Context2)77 PowerButtonCmpContext (
78   IN PCH_SMM_CONTEXT     *Context1,
79   IN PCH_SMM_CONTEXT     *Context2
80   )
81 {
82   return (BOOLEAN) (Context1->PowerButton.Phase == Context2->PowerButton.Phase);
83 }
84