]>
Commit | Line | Data |
---|---|---|
b303605e MK |
1 | /** @file\r |
2 | Provides a secure platform-specific method to detect physically present user.\r | |
3 | \r | |
b7d5f6ca | 4 | Copyright (c) 2013 - 2016 Intel Corporation.\r |
b303605e MK |
5 | \r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include <PiDxe.h>\r | |
17 | #include <Library/PlatformHelperLib.h>\r | |
18 | #include <Library/DebugLib.h>\r | |
19 | #include <Library/UefiBootServicesTableLib.h>\r | |
20 | #include <Library/I2cLib.h>\r | |
21 | \r | |
22 | #include <PlatformBoards.h>\r | |
23 | #include <Pcal9555.h>\r | |
24 | #include <QNCAccess.h>\r | |
25 | \r | |
26 | //\r | |
27 | // Global variable to cache pointer to I2C protocol.\r | |
28 | //\r | |
29 | EFI_PLATFORM_TYPE mPlatformType = TypeUnknown;\r | |
30 | \r | |
31 | BOOLEAN\r | |
32 | CheckResetButtonState (\r | |
33 | VOID\r | |
34 | )\r | |
35 | {\r | |
36 | EFI_STATUS Status;\r | |
37 | EFI_I2C_DEVICE_ADDRESS I2CSlaveAddress;\r | |
38 | UINTN Length;\r | |
39 | UINTN ReadLength;\r | |
40 | UINT8 Buffer[2];\r | |
41 | \r | |
b7d5f6ca | 42 | DEBUG ((EFI_D_INFO, "CheckResetButtonState(): mPlatformType == %d\n", mPlatformType));\r |
b303605e | 43 | if (mPlatformType == GalileoGen2) {\r |
b303605e MK |
44 | //\r |
45 | // Read state of Reset Button - EXP2.P1_7\r | |
46 | // This GPIO is pulled high when the button is not pressed\r | |
47 | // This GPIO reads low when button is pressed\r | |
48 | //\r | |
49 | return PlatformPcal9555GpioGetState (\r | |
50 | GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR, // IO Expander 2.\r | |
51 | 15 // P1-7.\r | |
52 | );\r | |
53 | }\r | |
54 | if (mPlatformType == Galileo) {\r | |
55 | //\r | |
56 | // Detect the I2C Slave Address of the GPIO Expander\r | |
57 | //\r | |
58 | if (PlatformLegacyGpioGetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, GALILEO_DETERMINE_IOEXP_SLA_RESUMEWELL_GPIO)) {\r | |
59 | I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2HI_7BIT_SLAVE_ADDR;\r | |
60 | } else {\r | |
61 | I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2LO_7BIT_SLAVE_ADDR;\r | |
62 | }\r | |
b7d5f6ca | 63 | DEBUG ((EFI_D_INFO, "Galileo GPIO Expender Slave Address = %02x\n", I2CSlaveAddress.I2CDeviceAddress));\r |
b303605e MK |
64 | \r |
65 | //\r | |
b7d5f6ca | 66 | // Read state of RESET_N_SHLD (GPORT5_BIT0)\r |
b303605e MK |
67 | //\r |
68 | Buffer[1] = 5;\r | |
69 | Length = 1;\r | |
70 | ReadLength = 1;\r | |
b303605e MK |
71 | Status = I2cReadMultipleByte (\r |
72 | I2CSlaveAddress,\r | |
73 | EfiI2CSevenBitAddrMode,\r | |
74 | &Length,\r | |
75 | &ReadLength,\r | |
76 | &Buffer[1]\r | |
77 | );\r | |
78 | ASSERT_EFI_ERROR (Status);\r | |
79 | \r | |
80 | //\r | |
b7d5f6ca | 81 | // Return the state of GPORT5_BIT0\r |
b303605e MK |
82 | //\r |
83 | return ((Buffer[1] & BIT0) != 0);\r | |
84 | }\r | |
85 | return TRUE;\r | |
86 | }\r | |
87 | \r | |
88 | /**\r | |
89 | \r | |
90 | This function provides a platform-specific method to detect whether the platform\r | |
91 | is operating by a physically present user.\r | |
92 | \r | |
93 | Programmatic changing of platform security policy (such as disable Secure Boot,\r | |
94 | or switch between Standard/Custom Secure Boot mode) MUST NOT be possible during\r | |
95 | Boot Services or after exiting EFI Boot Services. Only a physically present user\r | |
96 | is allowed to perform these operations.\r | |
97 | \r | |
98 | NOTE THAT: This function cannot depend on any EFI Variable Service since they are\r | |
99 | not available when this function is called in AuthenticateVariable driver.\r | |
100 | \r | |
101 | @retval TRUE The platform is operated by a physically present user.\r | |
102 | @retval FALSE The platform is NOT operated by a physically present user.\r | |
103 | \r | |
104 | **/\r | |
105 | BOOLEAN\r | |
106 | EFIAPI\r | |
107 | UserPhysicalPresent (\r | |
108 | VOID\r | |
109 | )\r | |
110 | {\r | |
111 | EFI_STATUS Status;\r | |
112 | \r | |
113 | //\r | |
114 | // If user has already been detected as present, then return TRUE\r | |
115 | //\r | |
116 | if (PcdGetBool (PcdUserIsPhysicallyPresent)) {\r | |
117 | return TRUE;\r | |
118 | }\r | |
119 | \r | |
120 | //\r | |
121 | // Check to see if user is present now\r | |
122 | //\r | |
123 | if (CheckResetButtonState ()) {\r | |
124 | //\r | |
125 | // User is still not present, then return FALSE\r | |
126 | //\r | |
127 | return FALSE;\r | |
128 | }\r | |
129 | \r | |
130 | //\r | |
131 | // User has gone from not present to present state, so set\r | |
132 | // PcdUserIsPhysicallyPresent to TRUE\r | |
133 | //\r | |
134 | Status = PcdSetBoolS (PcdUserIsPhysicallyPresent, TRUE);\r | |
135 | ASSERT_EFI_ERROR (Status);\r | |
136 | \r | |
137 | return TRUE;\r | |
138 | }\r | |
139 | \r | |
140 | /**\r | |
141 | Determines if a user is physically present by reading the reset button state.\r | |
142 | \r | |
143 | @param ImageHandle The image handle of this driver.\r | |
144 | @param SystemTable A pointer to the EFI System Table.\r | |
145 | \r | |
146 | @retval EFI_SUCCESS Install the Secure Boot Helper Protocol successfully.\r | |
147 | \r | |
148 | **/\r | |
149 | EFI_STATUS\r | |
150 | EFIAPI\r | |
151 | PlatformSecureLibInitialize (\r | |
152 | IN EFI_HANDLE ImageHandle,\r | |
153 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
154 | )\r | |
155 | {\r | |
156 | EFI_STATUS Status;\r | |
157 | \r | |
158 | //\r | |
159 | // Get the platform type\r | |
160 | //\r | |
161 | mPlatformType = (EFI_PLATFORM_TYPE)PcdGet16 (PcdPlatformType);\r | |
162 | \r | |
163 | //\r | |
164 | // Read the state of the reset button when the library is initialized\r | |
165 | //\r | |
166 | Status = PcdSetBoolS (PcdUserIsPhysicallyPresent, !CheckResetButtonState ());\r | |
167 | ASSERT_EFI_ERROR (Status);\r | |
168 | \r | |
169 | return EFI_SUCCESS;\r | |
170 | }\r |