]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ComponentName.c
Add compiler hint of "GLOBAL_REMOVE_IF_UNREFERENCED" to prevent static unicode string...
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiDiskDxe / ComponentName.c
1 /*++
2
3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ComponentName.c
15
16 Abstract:
17
18 --*/
19
20
21 #include <PiDxe.h>
22
23
24 #include <Protocol/ScsiIo.h>
25 #include <Protocol/ComponentName.h>
26 #include <Protocol/BlockIo.h>
27 #include <Protocol/DriverBinding.h>
28
29 #include <Library/DebugLib.h>
30 #include <Library/UefiDriverEntryPoint.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/ScsiLib.h>
34 #include <Library/UefiBootServicesTableLib.h>
35
36 #include "ScsiDisk.h"
37
38 //
39 // EFI Component Name Protocol
40 //
41 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName = {
42 ScsiDiskComponentNameGetDriverName,
43 ScsiDiskComponentNameGetControllerName,
44 "eng"
45 };
46
47 //
48 // EFI Component Name 2 Protocol
49 //
50 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2 = {
51 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) ScsiDiskComponentNameGetDriverName,
52 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) ScsiDiskComponentNameGetControllerName,
53 "en"
54 };
55
56
57 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mScsiDiskDriverNameTable[] = {
58 { "eng;en", (CHAR16 *) L"Scsi Disk Driver" },
59 { NULL , NULL }
60 };
61
62 /**
63 Retrieves a Unicode string that is the user readable name of the driver.
64
65 This function retrieves the user readable name of a driver in the form of a
66 Unicode string. If the driver specified by This has a user readable name in
67 the language specified by Language, then a pointer to the driver name is
68 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
69 by This does not support the language specified by Language,
70 then EFI_UNSUPPORTED is returned.
71
72 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
73 EFI_COMPONENT_NAME_PROTOCOL instance.
74
75 @param Language[in] A pointer to a Null-terminated ASCII string
76 array indicating the language. This is the
77 language of the driver name that the caller is
78 requesting, and it must match one of the
79 languages specified in SupportedLanguages. The
80 number of languages supported by a driver is up
81 to the driver writer. Language is specified
82 in RFC 3066 or ISO 639-2 language code format.
83
84 @param DriverName[out] A pointer to the Unicode string to return.
85 This Unicode string is the name of the
86 driver specified by This in the language
87 specified by Language.
88
89 @retval EFI_SUCCESS The Unicode string for the Driver specified by
90 This and the language specified by Language was
91 returned in DriverName.
92
93 @retval EFI_INVALID_PARAMETER Language is NULL.
94
95 @retval EFI_INVALID_PARAMETER DriverName is NULL.
96
97 @retval EFI_UNSUPPORTED The driver specified by This does not support
98 the language specified by Language.
99
100 **/
101 EFI_STATUS
102 EFIAPI
103 ScsiDiskComponentNameGetDriverName (
104 IN EFI_COMPONENT_NAME_PROTOCOL *This,
105 IN CHAR8 *Language,
106 OUT CHAR16 **DriverName
107 )
108 {
109 return LookupUnicodeString2 (
110 Language,
111 This->SupportedLanguages,
112 mScsiDiskDriverNameTable,
113 DriverName,
114 (BOOLEAN)(This == &gScsiDiskComponentName)
115 );
116 }
117
118 /**
119 Retrieves a Unicode string that is the user readable name of the controller
120 that is being managed by a driver.
121
122 This function retrieves the user readable name of the controller specified by
123 ControllerHandle and ChildHandle in the form of a Unicode string. If the
124 driver specified by This has a user readable name in the language specified by
125 Language, then a pointer to the controller name is returned in ControllerName,
126 and EFI_SUCCESS is returned. If the driver specified by This is not currently
127 managing the controller specified by ControllerHandle and ChildHandle,
128 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
129 support the language specified by Language, then EFI_UNSUPPORTED is returned.
130
131 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
132 EFI_COMPONENT_NAME_PROTOCOL instance.
133
134 @param ControllerHandle[in] The handle of a controller that the driver
135 specified by This is managing. This handle
136 specifies the controller whose name is to be
137 returned.
138
139 @param ChildHandle[in] The handle of the child controller to retrieve
140 the name of. This is an optional parameter that
141 may be NULL. It will be NULL for device
142 drivers. It will also be NULL for a bus drivers
143 that wish to retrieve the name of the bus
144 controller. It will not be NULL for a bus
145 driver that wishes to retrieve the name of a
146 child controller.
147
148 @param Language[in] A pointer to a Null-terminated ASCII string
149 array indicating the language. This is the
150 language of the driver name that the caller is
151 requesting, and it must match one of the
152 languages specified in SupportedLanguages. The
153 number of languages supported by a driver is up
154 to the driver writer. Language is specified in
155 RFC 3066 or ISO 639-2 language code format.
156
157 @param ControllerName[out] A pointer to the Unicode string to return.
158 This Unicode string is the name of the
159 controller specified by ControllerHandle and
160 ChildHandle in the language specified by
161 Language from the point of view of the driver
162 specified by This.
163
164 @retval EFI_SUCCESS The Unicode string for the user readable name in
165 the language specified by Language for the
166 driver specified by This was returned in
167 DriverName.
168
169 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
170
171 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
172 EFI_HANDLE.
173
174 @retval EFI_INVALID_PARAMETER Language is NULL.
175
176 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
177
178 @retval EFI_UNSUPPORTED The driver specified by This is not currently
179 managing the controller specified by
180 ControllerHandle and ChildHandle.
181
182 @retval EFI_UNSUPPORTED The driver specified by This does not support
183 the language specified by Language.
184
185 **/
186 EFI_STATUS
187 EFIAPI
188 ScsiDiskComponentNameGetControllerName (
189 IN EFI_COMPONENT_NAME_PROTOCOL *This,
190 IN EFI_HANDLE ControllerHandle,
191 IN EFI_HANDLE ChildHandle OPTIONAL,
192 IN CHAR8 *Language,
193 OUT CHAR16 **ControllerName
194 )
195 {
196 EFI_STATUS Status;
197 SCSI_DISK_DEV *ScsiDiskDevice;
198 EFI_BLOCK_IO_PROTOCOL *BlockIo;
199
200 //
201 // This is a device driver, so ChildHandle must be NULL.
202 //
203 if (ChildHandle != NULL) {
204 return EFI_UNSUPPORTED;
205 }
206
207 //
208 // Make sure this driver is currently managing ControllerHandle
209 //
210 Status = EfiTestManagedDevice (
211 ControllerHandle,
212 gScsiDiskDriverBinding.DriverBindingHandle,
213 &gEfiScsiIoProtocolGuid
214 );
215 if (EFI_ERROR (Status)) {
216 return Status;
217 }
218 //
219 // Get the device context
220 //
221 Status = gBS->OpenProtocol (
222 ControllerHandle,
223 &gEfiBlockIoProtocolGuid,
224 (VOID **) &BlockIo,
225 gScsiDiskDriverBinding.DriverBindingHandle,
226 ControllerHandle,
227 EFI_OPEN_PROTOCOL_GET_PROTOCOL
228 );
229
230 if (EFI_ERROR (Status)) {
231 return Status;
232 }
233
234 ScsiDiskDevice = SCSI_DISK_DEV_FROM_THIS (BlockIo);
235
236 return LookupUnicodeString2 (
237 Language,
238 This->SupportedLanguages,
239 ScsiDiskDevice->ControllerNameTable,
240 ControllerName,
241 (BOOLEAN)(This == &gScsiDiskComponentName)
242 );
243
244 }