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