]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / NvmExpressPei / NvmExpressPeiS3.c
CommitLineData
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
9d510e61 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
05fd2a92
HW
8\r
9**/\r
10\r
11#include "NvmExpressPei.h"\r
12\r
13#include <Guid/S3StorageDeviceInitList.h>\r
14\r
15#include <Library/LockBoxLib.h>\r
16\r
17/**\r
18 Determine if a specific NVM Express controller can be skipped for S3 phase.\r
19\r
20 @param[in] HcDevicePath Device path of the controller.\r
21 @param[in] HcDevicePathLength Length of the device path specified by\r
22 HcDevicePath.\r
23\r
24 @retval The number of ports that need to be enumerated.\r
25\r
26**/\r
27BOOLEAN\r
28NvmeS3SkipThisController (\r
29 IN EFI_DEVICE_PATH_PROTOCOL *HcDevicePath,\r
30 IN UINTN HcDevicePathLength\r
31 )\r
32{\r
33 EFI_STATUS Status;\r
34 UINT8 DummyData;\r
35 UINTN S3InitDevicesLength;\r
36 EFI_DEVICE_PATH_PROTOCOL *S3InitDevices;\r
37 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
38 UINTN DevicePathInstLength;\r
39 BOOLEAN EntireEnd;\r
40 BOOLEAN Skip;\r
41\r
42 //\r
43 // From the LockBox, get the list of device paths for devices need to be\r
44 // initialized in S3.\r
45 //\r
46 S3InitDevices = NULL;\r
47 S3InitDevicesLength = sizeof (DummyData);\r
48 EntireEnd = FALSE;\r
49 Skip = TRUE;\r
50 Status = RestoreLockBox (&gS3StorageDeviceInitListGuid, &DummyData, &S3InitDevicesLength);\r
51 if (Status != EFI_BUFFER_TOO_SMALL) {\r
52 return Skip;\r
53 } else {\r
54 S3InitDevices = AllocatePool (S3InitDevicesLength);\r
55 if (S3InitDevices == NULL) {\r
56 return Skip;\r
57 }\r
58\r
59 Status = RestoreLockBox (&gS3StorageDeviceInitListGuid, S3InitDevices, &S3InitDevicesLength);\r
60 if (EFI_ERROR (Status)) {\r
61 return Skip;\r
62 }\r
63 }\r
64\r
65 if (S3InitDevices == NULL) {\r
66 return Skip;\r
67 }\r
68\r
69 //\r
70 // Only need to initialize the controllers that exist in the device list.\r
71 //\r
72 do {\r
73 //\r
74 // Fetch the size of current device path instance.\r
75 //\r
76 Status = GetDevicePathInstanceSize (\r
77 S3InitDevices,\r
78 &DevicePathInstLength,\r
79 &EntireEnd\r
80 );\r
81 if (EFI_ERROR (Status)) {\r
82 break;\r
83 }\r
84\r
85 DevicePathInst = S3InitDevices;\r
86 S3InitDevices = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN) S3InitDevices + DevicePathInstLength);\r
87\r
88 if (HcDevicePathLength >= DevicePathInstLength) {\r
89 continue;\r
90 }\r
91\r
92 //\r
93 // Compare the device paths to determine if the device is managed by this\r
94 // controller.\r
95 //\r
96 if (CompareMem (\r
97 DevicePathInst,\r
98 HcDevicePath,\r
99 HcDevicePathLength - sizeof (EFI_DEVICE_PATH_PROTOCOL)\r
100 ) == 0) {\r
101 Skip = FALSE;\r
102 break;\r
103 }\r
104 } while (!EntireEnd);\r
105\r
106 return Skip;\r
107}\r