]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDriver.c
19db6cea97d9a1ac53f8161e90fcd3986bc71d69
[mirror_edk2.git] / MdeModulePkg / Universal / Network / VlanConfigDxe / VlanConfigDriver.c
1 /** @file
2 The driver binding for VLAN configuration module.
3
4 Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions
7 of the BSD License which accompanies this distribution. The full
8 text of the license may be found at<BR>
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 "VlanConfigImpl.h"
17
18 EFI_GUID gVlanConfigPrivateGuid = VLAN_CONFIG_PRIVATE_GUID;
19
20 EFI_DRIVER_BINDING_PROTOCOL gVlanConfigDriverBinding = {
21 VlanConfigDriverBindingSupported,
22 VlanConfigDriverBindingStart,
23 VlanConfigDriverBindingStop,
24 0xa,
25 NULL,
26 NULL
27 };
28
29 /**
30 The entry point for IP4 config driver which install the driver
31 binding and component name protocol on its image.
32
33 @param[in] ImageHandle The image handle of the driver.
34 @param[in] SystemTable The system table.
35
36 @retval EFI_SUCCES All the related protocols are installed on the driver.
37 @retval Others Failed to install protocols.
38
39 **/
40 EFI_STATUS
41 EFIAPI
42 VlanConfigDriverEntryPoint (
43 IN EFI_HANDLE ImageHandle,
44 IN EFI_SYSTEM_TABLE *SystemTable
45 )
46 {
47 return EfiLibInstallDriverBindingComponentName2 (
48 ImageHandle,
49 SystemTable,
50 &gVlanConfigDriverBinding,
51 ImageHandle,
52 &gVlanConfigComponentName,
53 &gVlanConfigComponentName2
54 );
55 }
56
57
58 /**
59 Test to see if this driver supports ControllerHandle.
60
61 @param[in] This Protocol instance pointer.
62 @param[in] ControllerHandle Handle of device to test
63 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
64 device to start.
65
66 @retval EFI_SUCCES This driver supports this device
67 @retval EFI_ALREADY_STARTED This driver is already running on this device
68 @retval other This driver does not support this device
69
70 **/
71 EFI_STATUS
72 EFIAPI
73 VlanConfigDriverBindingSupported (
74 IN EFI_DRIVER_BINDING_PROTOCOL *This,
75 IN EFI_HANDLE ControllerHandle,
76 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
77 )
78 {
79 EFI_STATUS Status;
80 EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;
81
82 Status = gBS->OpenProtocol (
83 ControllerHandle,
84 &gEfiVlanConfigProtocolGuid,
85 (VOID **) &VlanConfig,
86 This->DriverBindingHandle,
87 ControllerHandle,
88 EFI_OPEN_PROTOCOL_BY_DRIVER
89 );
90 if (EFI_ERROR (Status)) {
91 return Status;
92 }
93
94 //
95 // Close the VlanConfig protocol opened for supported test
96 //
97 gBS->CloseProtocol (
98 ControllerHandle,
99 &gEfiVlanConfigProtocolGuid,
100 This->DriverBindingHandle,
101 ControllerHandle
102 );
103
104 return Status;
105 }
106
107
108 /**
109 Start this driver on ControllerHandle.
110
111 @param[in] This Protocol instance pointer.
112 @param[in] ControllerHandle Handle of device to bind driver to
113 @param[in] RemainingDevicePath Optional parameter use to pick a specific child
114 device to start.
115
116 @retval EFI_SUCCES This driver is added to ControllerHandle
117 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
118 @retval other This driver does not support this device
119
120 **/
121 EFI_STATUS
122 EFIAPI
123 VlanConfigDriverBindingStart (
124 IN EFI_DRIVER_BINDING_PROTOCOL *This,
125 IN EFI_HANDLE ControllerHandle,
126 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
127 )
128 {
129 EFI_STATUS Status;
130 EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;
131 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
132 VLAN_CONFIG_PRIVATE_DATA *PrivateData;
133
134 //
135 // Check for multiple start
136 //
137 Status = gBS->OpenProtocol (
138 ControllerHandle,
139 &gVlanConfigPrivateGuid,
140 (VOID **) &PrivateData,
141 This->DriverBindingHandle,
142 ControllerHandle,
143 EFI_OPEN_PROTOCOL_GET_PROTOCOL
144 );
145 if (!EFI_ERROR (Status)) {
146 return EFI_ALREADY_STARTED;
147 }
148
149 //
150 // Open VlanConfig protocol by driver
151 //
152 Status = gBS->OpenProtocol (
153 ControllerHandle,
154 &gEfiVlanConfigProtocolGuid,
155 (VOID **) &VlanConfig,
156 This->DriverBindingHandle,
157 ControllerHandle,
158 EFI_OPEN_PROTOCOL_BY_DRIVER
159 );
160 if (EFI_ERROR (Status)) {
161 return Status;
162 }
163
164 //
165 // Get parent device path
166 //
167 Status = gBS->OpenProtocol (
168 ControllerHandle,
169 &gEfiDevicePathProtocolGuid,
170 (VOID **) &DevicePath,
171 This->DriverBindingHandle,
172 ControllerHandle,
173 EFI_OPEN_PROTOCOL_GET_PROTOCOL
174 );
175 if (EFI_ERROR (Status)) {
176 goto ErrorExit;
177 }
178
179 //
180 // Create a private data for this network device
181 //
182 PrivateData = AllocateCopyPool (sizeof (VLAN_CONFIG_PRIVATE_DATA), &mVlanConfigPrivateDateTemplate);
183 if (PrivateData == NULL) {
184 Status = EFI_OUT_OF_RESOURCES;
185 goto ErrorExit;
186 }
187
188 PrivateData->ImageHandle = This->DriverBindingHandle;
189 PrivateData->ControllerHandle = ControllerHandle;
190 PrivateData->VlanConfig = VlanConfig;
191 PrivateData->ParentDevicePath = DevicePath;
192
193 //
194 // Install VLAN configuration form
195 //
196 Status = InstallVlanConfigForm (PrivateData);
197 if (EFI_ERROR (Status)) {
198 goto ErrorExit;
199 }
200
201 //
202 // Install private GUID
203 //
204 Status = gBS->InstallMultipleProtocolInterfaces (
205 &ControllerHandle,
206 &gVlanConfigPrivateGuid,
207 PrivateData,
208 NULL
209 );
210 if (EFI_ERROR (Status)) {
211 goto ErrorExit;
212 }
213 return Status;
214
215 ErrorExit:
216 gBS->CloseProtocol (
217 ControllerHandle,
218 &gEfiVlanConfigProtocolGuid,
219 This->DriverBindingHandle,
220 ControllerHandle
221 );
222
223 gBS->CloseProtocol (
224 ControllerHandle,
225 &gEfiDevicePathProtocolGuid,
226 This->DriverBindingHandle,
227 ControllerHandle
228 );
229
230 if (PrivateData != NULL) {
231 UninstallVlanConfigForm (PrivateData);
232 FreePool (PrivateData);
233 }
234
235 return Status;
236 }
237
238
239 /**
240 Stop this driver on ControllerHandle.
241
242 @param[in] This Protocol instance pointer.
243 @param[in] ControllerHandle Handle of device to stop driver on
244 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
245 of children is zero stop the entire bus driver.
246 @param[in] ChildHandleBuffer List of Child Handles to Stop.
247
248 @retval EFI_SUCCES This driver is removed ControllerHandle
249 @retval other This driver was not removed from this device
250
251 **/
252 EFI_STATUS
253 EFIAPI
254 VlanConfigDriverBindingStop (
255 IN EFI_DRIVER_BINDING_PROTOCOL *This,
256 IN EFI_HANDLE ControllerHandle,
257 IN UINTN NumberOfChildren,
258 IN EFI_HANDLE *ChildHandleBuffer
259 )
260 {
261 EFI_STATUS Status;
262 VLAN_CONFIG_PRIVATE_DATA *PrivateData;
263
264 //
265 // Retrieve the PrivateData from ControllerHandle
266 //
267 Status = gBS->OpenProtocol (
268 ControllerHandle,
269 &gVlanConfigPrivateGuid,
270 (VOID **) &PrivateData,
271 This->DriverBindingHandle,
272 ControllerHandle,
273 EFI_OPEN_PROTOCOL_GET_PROTOCOL
274 );
275 if (EFI_ERROR (Status)) {
276 return Status;
277 }
278 ASSERT (PrivateData->Signature == VLAN_CONFIG_PRIVATE_DATA_SIGNATURE);
279
280 //
281 // Uninstall VLAN configuration Form
282 //
283 UninstallVlanConfigForm (PrivateData);
284
285 //
286 // Uninstall the private GUID
287 //
288 Status = gBS->UninstallMultipleProtocolInterfaces (
289 ControllerHandle,
290 &gVlanConfigPrivateGuid,
291 PrivateData,
292 NULL
293 );
294 if (EFI_ERROR (Status)) {
295 return Status;
296 }
297
298 Status = gBS->CloseProtocol (
299 ControllerHandle,
300 &gEfiVlanConfigProtocolGuid,
301 This->DriverBindingHandle,
302 ControllerHandle
303 );
304 return Status;
305 }