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