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