]>
Commit | Line | Data |
---|---|---|
05fd2a92 HW |
1 | /** @file\r |
2 | The NvmExpressPei driver is used to manage non-volatile memory subsystem\r | |
3 | which follows NVM Express specification at PEI phase.\r | |
4 | \r | |
5 | Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r | |
6 | \r | |
7 | This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions\r | |
9 | of the BSD License which accompanies this distribution. The\r | |
10 | full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #include "NvmExpressPei.h"\r | |
19 | \r | |
20 | #include <Guid/S3StorageDeviceInitList.h>\r | |
21 | \r | |
22 | #include <Library/LockBoxLib.h>\r | |
23 | \r | |
24 | /**\r | |
25 | Determine if a specific NVM Express controller can be skipped for S3 phase.\r | |
26 | \r | |
27 | @param[in] HcDevicePath Device path of the controller.\r | |
28 | @param[in] HcDevicePathLength Length of the device path specified by\r | |
29 | HcDevicePath.\r | |
30 | \r | |
31 | @retval The number of ports that need to be enumerated.\r | |
32 | \r | |
33 | **/\r | |
34 | BOOLEAN\r | |
35 | NvmeS3SkipThisController (\r | |
36 | IN EFI_DEVICE_PATH_PROTOCOL *HcDevicePath,\r | |
37 | IN UINTN HcDevicePathLength\r | |
38 | )\r | |
39 | {\r | |
40 | EFI_STATUS Status;\r | |
41 | UINT8 DummyData;\r | |
42 | UINTN S3InitDevicesLength;\r | |
43 | EFI_DEVICE_PATH_PROTOCOL *S3InitDevices;\r | |
44 | EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r | |
45 | UINTN DevicePathInstLength;\r | |
46 | BOOLEAN EntireEnd;\r | |
47 | BOOLEAN Skip;\r | |
48 | \r | |
49 | //\r | |
50 | // From the LockBox, get the list of device paths for devices need to be\r | |
51 | // initialized in S3.\r | |
52 | //\r | |
53 | S3InitDevices = NULL;\r | |
54 | S3InitDevicesLength = sizeof (DummyData);\r | |
55 | EntireEnd = FALSE;\r | |
56 | Skip = TRUE;\r | |
57 | Status = RestoreLockBox (&gS3StorageDeviceInitListGuid, &DummyData, &S3InitDevicesLength);\r | |
58 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
59 | return Skip;\r | |
60 | } else {\r | |
61 | S3InitDevices = AllocatePool (S3InitDevicesLength);\r | |
62 | if (S3InitDevices == NULL) {\r | |
63 | return Skip;\r | |
64 | }\r | |
65 | \r | |
66 | Status = RestoreLockBox (&gS3StorageDeviceInitListGuid, S3InitDevices, &S3InitDevicesLength);\r | |
67 | if (EFI_ERROR (Status)) {\r | |
68 | return Skip;\r | |
69 | }\r | |
70 | }\r | |
71 | \r | |
72 | if (S3InitDevices == NULL) {\r | |
73 | return Skip;\r | |
74 | }\r | |
75 | \r | |
76 | //\r | |
77 | // Only need to initialize the controllers that exist in the device list.\r | |
78 | //\r | |
79 | do {\r | |
80 | //\r | |
81 | // Fetch the size of current device path instance.\r | |
82 | //\r | |
83 | Status = GetDevicePathInstanceSize (\r | |
84 | S3InitDevices,\r | |
85 | &DevicePathInstLength,\r | |
86 | &EntireEnd\r | |
87 | );\r | |
88 | if (EFI_ERROR (Status)) {\r | |
89 | break;\r | |
90 | }\r | |
91 | \r | |
92 | DevicePathInst = S3InitDevices;\r | |
93 | S3InitDevices = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN) S3InitDevices + DevicePathInstLength);\r | |
94 | \r | |
95 | if (HcDevicePathLength >= DevicePathInstLength) {\r | |
96 | continue;\r | |
97 | }\r | |
98 | \r | |
99 | //\r | |
100 | // Compare the device paths to determine if the device is managed by this\r | |
101 | // controller.\r | |
102 | //\r | |
103 | if (CompareMem (\r | |
104 | DevicePathInst,\r | |
105 | HcDevicePath,\r | |
106 | HcDevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL)\r | |
107 | ) == 0) {\r | |
108 | Skip = FALSE;\r | |
109 | break;\r | |
110 | }\r | |
111 | } while (!EntireEnd);\r | |
112 | \r | |
113 | return Skip;\r | |
114 | }\r |