1 /** @file
2   Callbacks required by the HII of the Opal UEFI Driver to help display
3   Opal device information.
4 
5 Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7 
8 **/
9 
10 #include "OpalHii.h"
11 
12 /**
13   Get the driver image handle.
14 
15   @retval  the driver image handle.
16 
17 **/
18 EFI_HANDLE
HiiGetDriverImageHandleCB(VOID)19 HiiGetDriverImageHandleCB(
20   VOID
21   )
22 {
23   return gImageHandle;
24 }
25 
26 /**
27   Returns the opaque pointer to a physical disk context.
28 
29   @param  DiskIndex       Input the disk index.
30 
31   @retval The device pointer.
32 
33 **/
34 VOID *
HiiGetDiskContextCB(UINT8 DiskIndex)35 HiiGetDiskContextCB(
36   UINT8 DiskIndex
37   )
38 {
39   OPAL_DRIVER_DEVICE*                Dev;
40   UINT8                              CurrentDisk;
41 
42   Dev = OpalDriverGetDeviceList();
43   CurrentDisk = 0;
44 
45   if (DiskIndex >= GetDeviceCount()) {
46     return NULL;
47   }
48 
49   while (Dev != NULL) {
50     if (CurrentDisk == DiskIndex) {
51       return Dev;
52     } else {
53       Dev = Dev->Next;
54       CurrentDisk++;
55     }
56   }
57 
58   return NULL;
59 }
60 
61 /**
62   Returns the opaque pointer to a physical disk context.
63 
64   @param  DiskIndex       Input the disk index.
65 
66   @retval The device pointer.
67 
68 **/
69 OPAL_DISK*
HiiGetOpalDiskCB(UINT8 DiskIndex)70 HiiGetOpalDiskCB(
71   UINT8 DiskIndex
72   )
73 {
74   VOID                           *Ctx;
75   OPAL_DRIVER_DEVICE             *Tmp;
76 
77   Ctx = HiiGetDiskContextCB (DiskIndex);
78 
79   if (Ctx == NULL) {
80     return NULL;
81   }
82 
83   Tmp = (OPAL_DRIVER_DEVICE*) Ctx;
84 
85   return &Tmp->OpalDisk;
86 }
87 
88 /**
89   Returns the disk name.
90 
91   @param  DiskIndex       Input the disk index.
92 
93   @retval Returns the disk name.
94 
95 **/
96 CHAR8*
HiiDiskGetNameCB(UINT8 DiskIndex)97 HiiDiskGetNameCB(
98   UINT8 DiskIndex
99   )
100 {
101   OPAL_DRIVER_DEVICE*                Ctx;
102 
103   Ctx = (OPAL_DRIVER_DEVICE*) HiiGetDiskContextCB (DiskIndex);
104 
105   if (Ctx != NULL) {
106     if (Ctx->NameZ == NULL) {
107       OpalDriverGetDriverDeviceName (Ctx);
108     }
109     return Ctx->NameZ;
110   }
111   return NULL;
112 }
113