Add WinNtBusDriverDxe into Nt32Pkg.
[mirror_edk2.git] / Nt32Pkg / WinNtBusDriverDxe / ComponentName.c
1 /*++
2
3 Copyright (c) 2006, 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 // The package level header files this module uses
22 //
23 #include <Uefi.h>
24 #include <WinNtDxe.h>
25 //
26 // The protocols, PPI and GUID defintions for this module
27 //
28 #include <Protocol/WinNtThunk.h>
29 #include <Protocol/WinNtIo.h>
30 #include <Protocol/ComponentName.h>
31 #include <Protocol/DriverBinding.h>
32 #include <Protocol/DevicePath.h>
33
34
35 #include "WinNtBusDriver.h"
36
37 //
38 // EFI Component Name Functions
39 //
40 EFI_STATUS
41 EFIAPI
42 WinNtBusDriverComponentNameGetDriverName (
43 IN EFI_COMPONENT_NAME_PROTOCOL *This,
44 IN CHAR8 *Language,
45 OUT CHAR16 **DriverName
46 );
47
48 EFI_STATUS
49 EFIAPI
50 WinNtBusDriverComponentNameGetControllerName (
51 IN EFI_COMPONENT_NAME_PROTOCOL *This,
52 IN EFI_HANDLE ControllerHandle,
53 IN EFI_HANDLE ChildHandle OPTIONAL,
54 IN CHAR8 *Language,
55 OUT CHAR16 **ControllerName
56 );
57
58 //
59 // EFI Component Name Protocol
60 //
61 EFI_COMPONENT_NAME_PROTOCOL gWinNtBusDriverComponentName = {
62 WinNtBusDriverComponentNameGetDriverName,
63 WinNtBusDriverComponentNameGetControllerName,
64 "eng"
65 };
66
67 static EFI_UNICODE_STRING_TABLE mWinNtBusDriverNameTable[] = {
68 { "eng", L"Windows Bus Driver" },
69 { NULL , NULL }
70 };
71
72 EFI_STATUS
73 EFIAPI
74 WinNtBusDriverComponentNameGetDriverName (
75 IN EFI_COMPONENT_NAME_PROTOCOL *This,
76 IN CHAR8 *Language,
77 OUT CHAR16 **DriverName
78 )
79 /*++
80
81 Routine Description:
82 Retrieves a Unicode string that is the user readable name of the EFI Driver.
83
84 Arguments:
85 This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
86 Language - A pointer to a three character ISO 639-2 language identifier.
87 This is the language of the driver name that that the caller
88 is requesting, and it must match one of the languages specified
89 in SupportedLanguages. The number of languages supported by a
90 driver is up to the driver writer.
91 DriverName - A pointer to the Unicode string to return. This Unicode string
92 is the name of the driver specified by This in the language
93 specified by Language.
94
95 Returns:
96 EFI_SUCCESS - The Unicode string for the Driver specified by This
97 and the language specified by Language was returned
98 in DriverName.
99 EFI_INVALID_PARAMETER - Language is NULL.
100 EFI_INVALID_PARAMETER - DriverName is NULL.
101 EFI_UNSUPPORTED - The driver specified by This does not support the
102 language specified by Language.
103
104 --*/
105 {
106 return LookupUnicodeString (
107 Language,
108 gWinNtBusDriverComponentName.SupportedLanguages,
109 mWinNtBusDriverNameTable,
110 DriverName
111 );
112 }
113
114 EFI_STATUS
115 EFIAPI
116 WinNtBusDriverComponentNameGetControllerName (
117 IN EFI_COMPONENT_NAME_PROTOCOL *This,
118 IN EFI_HANDLE ControllerHandle,
119 IN EFI_HANDLE ChildHandle OPTIONAL,
120 IN CHAR8 *Language,
121 OUT CHAR16 **ControllerName
122 )
123 /*++
124
125 Routine Description:
126 Retrieves a Unicode string that is the user readable name of the controller
127 that is being managed by an EFI Driver.
128
129 Arguments:
130 This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
131 ControllerHandle - The handle of a controller that the driver specified by
132 This is managing. This handle specifies the controller
133 whose name is to be returned.
134 ChildHandle - The handle of the child controller to retrieve the name
135 of. This is an optional parameter that may be NULL. It
136 will be NULL for device drivers. It will also be NULL
137 for a bus drivers that wish to retrieve the name of the
138 bus controller. It will not be NULL for a bus driver
139 that wishes to retrieve the name of a child controller.
140 Language - A pointer to a three character ISO 639-2 language
141 identifier. This is the language of the controller name
142 that that the caller is requesting, and it must match one
143 of the languages specified in SupportedLanguages. The
144 number of languages supported by a driver is up to the
145 driver writer.
146 ControllerName - A pointer to the Unicode string to return. This Unicode
147 string is the name of the controller specified by
148 ControllerHandle and ChildHandle in the language specified
149 by Language from the point of view of the driver specified
150 by This.
151
152 Returns:
153 EFI_SUCCESS - The Unicode string for the user readable name in the
154 language specified by Language for the driver
155 specified by This was returned in DriverName.
156 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
157 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
158 EFI_INVALID_PARAMETER - Language is NULL.
159 EFI_INVALID_PARAMETER - ControllerName is NULL.
160 EFI_UNSUPPORTED - The driver specified by This is not currently managing
161 the controller specified by ControllerHandle and
162 ChildHandle.
163 EFI_UNSUPPORTED - The driver specified by This does not support the
164 language specified by Language.
165
166 --*/
167 {
168 EFI_STATUS Status;
169 EFI_WIN_NT_IO_PROTOCOL *WinNtIo;
170 WIN_NT_IO_DEVICE *Private;
171
172 //
173 // Make sure this driver is currently managing ControllHandle
174 //
175 Status = EfiTestManagedDevice (
176 ControllerHandle,
177 gWinNtBusDriverBinding.DriverBindingHandle,
178 &gEfiWinNtThunkProtocolGuid
179 );
180 if (EFI_ERROR (Status)) {
181 return Status;
182 }
183
184 //
185 // This is a bus driver, so ChildHandle can not be NULL.
186 //
187 if (ChildHandle == NULL) {
188 return EFI_UNSUPPORTED;
189 }
190
191 Status = EfiTestChildHandle (
192 ControllerHandle,
193 ChildHandle,
194 &gEfiWinNtThunkProtocolGuid
195 );
196 if (EFI_ERROR (Status)) {
197 return Status;
198 }
199
200 //
201 // Get our context back
202 //
203 Status = gBS->OpenProtocol (
204 ChildHandle,
205 &gEfiWinNtIoProtocolGuid,
206 &WinNtIo,
207 gWinNtBusDriverBinding.DriverBindingHandle,
208 ChildHandle,
209 EFI_OPEN_PROTOCOL_GET_PROTOCOL
210 );
211 if (EFI_ERROR (Status)) {
212 return EFI_UNSUPPORTED;
213 }
214
215 Private = WIN_NT_IO_DEVICE_FROM_THIS (WinNtIo);
216
217 return LookupUnicodeString (
218 Language,
219 gWinNtBusDriverComponentName.SupportedLanguages,
220 Private->ControllerNameTable,
221 ControllerName
222 );
223 }