1 /** @file
2   Component Name functions implementation for XenBus Bus driver.
3 
4   Copyright (C) 2014, Citrix Ltd.
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 #include "XenBusDxe.h"
17 
18 ///
19 /// Component Name Protocol instance
20 ///
21 GLOBAL_REMOVE_IF_UNREFERENCED
22 EFI_COMPONENT_NAME_PROTOCOL  gXenBusDxeComponentName = {
23   (EFI_COMPONENT_NAME_GET_DRIVER_NAME)    XenBusDxeComponentNameGetDriverName,
24   (EFI_COMPONENT_NAME_GET_CONTROLLER_NAME)XenBusDxeComponentNameGetControllerName,
25   "eng"
26 };
27 
28 ///
29 /// Component Name 2 Protocol instance
30 ///
31 GLOBAL_REMOVE_IF_UNREFERENCED
32 EFI_COMPONENT_NAME2_PROTOCOL  gXenBusDxeComponentName2 = {
33   XenBusDxeComponentNameGetDriverName,
34   XenBusDxeComponentNameGetControllerName,
35   "en"
36 };
37 
38 ///
39 /// Table of driver names
40 ///
41 GLOBAL_REMOVE_IF_UNREFERENCED
42 EFI_UNICODE_STRING_TABLE mXenBusDxeDriverNameTable[] = {
43   { "eng;en", (CHAR16 *)L"XenBus Bus Driver" },
44   { NULL, NULL }
45 };
46 
47 ///
48 /// Table of controller names
49 ///
50 GLOBAL_REMOVE_IF_UNREFERENCED
51 EFI_UNICODE_STRING_TABLE mXenBusDxeControllerNameTable[] = {
52   { "eng;en", (CHAR16 *)L"XenBus Controller" },
53   { NULL, NULL }
54 };
55 
56 /**
57   Retrieves a Unicode string that is the user-readable name of the EFI Driver.
58 
59   @param  This       A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
60   @param  Language   A pointer to a three-character ISO 639-2 language identifier.
61                      This is the language of the driver name that that the caller
62                      is requesting, and it must match one of the languages specified
63                      in SupportedLanguages.  The number of languages supported by a
64                      driver is up to the driver writer.
65   @param  DriverName A pointer to the Unicode string to return.  This Unicode string
66                      is the name of the driver specified by This in the language
67                      specified by Language.
68 
69   @retval EFI_SUCCESS           The Unicode string for the Driver specified by This
70                                 and the language specified by Language was returned
71                                 in DriverName.
72   @retval EFI_INVALID_PARAMETER Language is NULL.
73   @retval EFI_INVALID_PARAMETER DriverName is NULL.
74   @retval EFI_UNSUPPORTED       The driver specified by This does not support the
75                                 language specified by Language.
76 
77 **/
78 EFI_STATUS
79 EFIAPI
XenBusDxeComponentNameGetDriverName(IN EFI_COMPONENT_NAME2_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)80 XenBusDxeComponentNameGetDriverName (
81   IN EFI_COMPONENT_NAME2_PROTOCOL  *This,
82   IN  CHAR8                        *Language,
83   OUT CHAR16                       **DriverName
84   )
85 {
86   return LookupUnicodeString2 (
87            Language,
88            This->SupportedLanguages,
89            mXenBusDxeDriverNameTable,
90            DriverName,
91            (BOOLEAN)(This != &gXenBusDxeComponentName2)
92            );
93 }
94 
95 /**
96   Retrieves a Unicode string that is the user readable name of the controller
97   that is being managed by an EFI Driver.
98 
99   @param  This             A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
100   @param  ControllerHandle The handle of a controller that the driver specified by
101                            This is managing.  This handle specifies the controller
102                            whose name is to be returned.
103   @param  ChildHandle      The handle of the child controller to retrieve the name
104                            of.  This is an optional parameter that may be NULL.  It
105                            will be NULL for device drivers.  It will also be NULL
106                            for a bus drivers that wish to retrieve the name of the
107                            bus controller.  It will not be NULL for a bus driver
108                            that wishes to retrieve the name of a child controller.
109   @param  Language         A pointer to a three character ISO 639-2 language
110                            identifier.  This is the language of the controller name
111                            that the caller is requesting, and it must match one
112                            of the languages specified in SupportedLanguages.  The
113                            number of languages supported by a driver is up to the
114                            driver writer.
115   @param  ControllerName   A pointer to the Unicode string to return.  This Unicode
116                            string is the name of the controller specified by
117                            ControllerHandle and ChildHandle in the language specified
118                            by Language, from the point of view of the driver specified
119                            by This.
120 
121   @retval EFI_SUCCESS           The Unicode string for the user-readable name in the
122                                 language specified by Language for the driver
123                                 specified by This was returned in DriverName.
124   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
125   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
126   @retval EFI_INVALID_PARAMETER Language is NULL.
127   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
128   @retval EFI_UNSUPPORTED       The driver specified by This is not currently managing
129                                 the controller specified by ControllerHandle and
130                                 ChildHandle.
131   @retval EFI_UNSUPPORTED       The driver specified by This does not support the
132                                 language specified by Language.
133 
134 **/
135 EFI_STATUS
136 EFIAPI
XenBusDxeComponentNameGetControllerName(IN EFI_COMPONENT_NAME2_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)137 XenBusDxeComponentNameGetControllerName (
138   IN  EFI_COMPONENT_NAME2_PROTOCOL  *This,
139   IN  EFI_HANDLE                    ControllerHandle,
140   IN  EFI_HANDLE                    ChildHandle        OPTIONAL,
141   IN  CHAR8                         *Language,
142   OUT CHAR16                        **ControllerName
143   )
144 {
145   EFI_STATUS  Status;
146 
147   if (ChildHandle != NULL) {
148     // TODO Get controller name for a child.
149     return EFI_UNSUPPORTED;
150   }
151 
152   //
153   // Make sure this driver is currently managing ControllerHandle
154   //
155   Status = EfiTestManagedDevice (
156              ControllerHandle,
157              gXenBusDxeDriverBinding.DriverBindingHandle,
158              &gXenIoProtocolGuid
159              );
160   if (EFI_ERROR (Status)) {
161     return Status;
162   }
163 
164   //
165   // Lookup name of controller specified by ControllerHandle
166   //
167   return LookupUnicodeString2 (
168            Language,
169            This->SupportedLanguages,
170            mXenBusDxeControllerNameTable,
171            ControllerName,
172            (BOOLEAN)(This != &gXenBusDxeComponentName2)
173            );
174 }
175