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