]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/EmuSnpDxe/EmuSnpDxe.c
BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / EmulatorPkg / EmuSnpDxe / EmuSnpDxe.c
CommitLineData
572287f8 1/** @file\r
2\r
3 Copyright (c) 2010, Apple, Inc. All rights reserved.<BR>\r
d7dd9387 4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
572287f8 5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14Module Name:\r
15\r
16 EmuSnp.c\r
17\r
18Abstract:\r
19\r
20-**/\r
21\r
22#include "EmuSnpDxe.h"\r
23\r
24\r
25\r
26EFI_SIMPLE_NETWORK_PROTOCOL gEmuSnpTemplate = {\r
d18d8a1d 27 EFI_SIMPLE_NETWORK_PROTOCOL_REVISION,\r
28 EmuSnpStart,\r
29 EmuSnpStop,\r
30 EmuSnpInitialize,\r
31 EmuSnpReset,\r
32 EmuSnpShutdown,\r
33 EmuSnpReceiveFilters,\r
34 EmuSnpStationAddress,\r
35 EmuSnpStatistics,\r
36 EmuSnpMcastIptoMac,\r
37 EmuSnpNvdata,\r
38 EmuSnpGetStatus,\r
39 EmuSnpTransmit,\r
40 EmuSnpReceive,\r
572287f8 41 NULL, // WaitForPacket\r
42 NULL // Mode\r
43 };\r
44\r
f79fa76e 45EFI_SIMPLE_NETWORK_MODE gEmuSnpModeTemplate = { \r
46 EfiSimpleNetworkStopped, // State\r
47 NET_ETHER_ADDR_LEN, // HwAddressSize\r
48 NET_ETHER_HEADER_SIZE, // MediaHeaderSize\r
49 1500, // MaxPacketSize\r
50 0, // NvRamSize\r
51 0, // NvRamAccessSize\r
52 0, // ReceiveFilterMask\r
53 0, // ReceiveFilterSetting\r
54 MAX_MCAST_FILTER_CNT, // MaxMCastFilterCount\r
55 0, // MCastFilterCount\r
56 {\r
57 { { 0 } }\r
58 }, // MCastFilter\r
59 {\r
60 { 0 }\r
61 }, // CurrentAddress\r
62 {\r
63 { 0 }\r
64 }, // BroadcastAddress\r
65 {\r
66 { 0 }\r
67 }, // PermanentAddress\r
68 NET_IFTYPE_ETHERNET, // IfType\r
69 FALSE, // MacAddressChangeable\r
70 FALSE, // MultipleTxSupported\r
71 FALSE, // MediaPresentSupported\r
72 TRUE // MediaPresent\r
73};\r
572287f8 74\r
75\r
76/**\r
77 Changes the state of a network interface from "stopped" to "started".\r
78\r
79 @param This Protocol instance pointer.\r
80\r
81 @retval EFI_SUCCESS Always succeeds.\r
82\r
83**/\r
84EFI_STATUS\r
85EFIAPI\r
86EmuSnpStart(\r
87 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
88 )\r
89{\r
90 EFI_STATUS Status;\r
91 EMU_SNP_PRIVATE_DATA *Private;\r
92\r
93 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
94\r
95 Status = Private->Io->Start (Private->Io);\r
96 return Status;\r
97}\r
98\r
99\r
100/**\r
101 Changes the state of a network interface from "started" to "stopped".\r
102\r
103 @param This Protocol instance pointer.\r
104\r
105 @retval EFI_SUCCESS Always succeeds.\r
106\r
107**/\r
108EFI_STATUS\r
109EFIAPI\r
110EmuSnpStop (\r
111 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
112 )\r
113{\r
114 EFI_STATUS Status;\r
115 EMU_SNP_PRIVATE_DATA *Private;\r
116\r
117 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
118\r
119 Status = Private->Io->Stop (Private->Io);\r
120 return Status;\r
121}\r
122\r
123\r
124/**\r
d18d8a1d 125 Resets a network adapter and allocates the transmit and receive buffers\r
126 required by the network interface; optionally, also requests allocation\r
572287f8 127 of additional transmit and receive buffers.\r
128\r
129 @param This Protocol instance pointer.\r
130 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
131 that the driver should allocate for the network interface.\r
132 Some network interfaces will not be able to use the extra\r
133 buffer, and the caller will not know if it is actually\r
134 being used.\r
135 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
136 that the driver should allocate for the network interface.\r
137 Some network interfaces will not be able to use the extra\r
138 buffer, and the caller will not know if it is actually\r
139 being used.\r
140\r
141 @retval EFI_SUCCESS Always succeeds.\r
142\r
143**/\r
144EFI_STATUS\r
145EFIAPI\r
146EmuSnpInitialize (\r
147 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
148 IN UINTN ExtraRxBufferSize OPTIONAL,\r
149 IN UINTN ExtraTxBufferSize OPTIONAL\r
150 )\r
151{\r
152 EFI_STATUS Status;\r
153 EMU_SNP_PRIVATE_DATA *Private;\r
154\r
155 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
156\r
157 Status = Private->Io->Initialize (Private->Io, ExtraRxBufferSize, ExtraTxBufferSize);\r
158 return Status;\r
159}\r
160\r
161/**\r
d18d8a1d 162 Resets a network adapter and re-initializes it with the parameters that were\r
163 provided in the previous call to Initialize().\r
572287f8 164\r
165 @param This Protocol instance pointer.\r
166 @param ExtendedVerification Indicates that the driver may perform a more\r
167 exhaustive verification operation of the device\r
168 during reset.\r
169\r
170 @retval EFI_SUCCESS Always succeeds.\r
171\r
172**/\r
173EFI_STATUS\r
174EFIAPI\r
175EmuSnpReset (\r
176 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
177 IN BOOLEAN ExtendedVerification\r
178 )\r
179{\r
180 EFI_STATUS Status;\r
181 EMU_SNP_PRIVATE_DATA *Private;\r
182\r
183 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
184\r
185 Status = Private->Io->Reset (Private->Io, ExtendedVerification);\r
186 return Status;\r
187}\r
188\r
189/**\r
d18d8a1d 190 Resets a network adapter and leaves it in a state that is safe for\r
572287f8 191 another driver to initialize.\r
192\r
193 @param This Protocol instance pointer.\r
194\r
195 @retval EFI_SUCCESS Always succeeds.\r
196\r
197**/\r
198EFI_STATUS\r
199EFIAPI\r
200EmuSnpShutdown (\r
201 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
202 )\r
203{\r
204 EFI_STATUS Status;\r
205 EMU_SNP_PRIVATE_DATA *Private;\r
206\r
207 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
208\r
209 Status = Private->Io->Shutdown (Private->Io);\r
210 return Status;\r
211}\r
212\r
213/**\r
214 Manages the multicast receive filters of a network interface.\r
215\r
216 @param This Protocol instance pointer.\r
217 @param EnableBits A bit mask of receive filters to enable on the network interface.\r
218 @param DisableBits A bit mask of receive filters to disable on the network interface.\r
219 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive\r
220 filters on the network interface to their default values.\r
221 @param McastFilterCount Number of multicast HW MAC addresses in the new\r
222 MCastFilter list. This value must be less than or equal to\r
223 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This\r
224 field is optional if ResetMCastFilter is TRUE.\r
225 @param McastFilter A pointer to a list of new multicast receive filter HW MAC\r
226 addresses. This list will replace any existing multicast\r
227 HW MAC address list. This field is optional if\r
228 ResetMCastFilter is TRUE.\r
229\r
230 @retval EFI_SUCCESS The multicast receive filter list was updated.\r
231 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
232\r
233**/\r
234EFI_STATUS\r
235EFIAPI\r
236EmuSnpReceiveFilters (\r
237 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
238 IN UINT32 EnableBits,\r
239 IN UINT32 DisableBits,\r
240 IN BOOLEAN ResetMcastFilter,\r
241 IN UINTN McastFilterCount OPTIONAL,\r
242 IN EFI_MAC_ADDRESS *McastFilter OPTIONAL\r
243 )\r
244{\r
245 EFI_STATUS Status;\r
246 EMU_SNP_PRIVATE_DATA *Private;\r
247\r
248 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
249\r
250 Status = Private->Io->ReceiveFilters (\r
251 Private->Io,\r
252 EnableBits,\r
253 DisableBits,\r
254 ResetMcastFilter,\r
255 McastFilterCount,\r
256 McastFilter\r
257 );\r
258 return Status;\r
259}\r
260\r
261/**\r
262 Modifies or resets the current station address, if supported.\r
263\r
264 @param This Protocol instance pointer.\r
265 @param Reset Flag used to reset the station address to the network interfaces\r
266 permanent address.\r
267 @param NewMacAddr New station address to be used for the network interface.\r
268\r
269 @retval EFI_UNSUPPORTED Not supported yet.\r
270\r
271**/\r
272EFI_STATUS\r
273EFIAPI\r
274EmuSnpStationAddress (\r
275 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
276 IN BOOLEAN Reset,\r
277 IN EFI_MAC_ADDRESS *NewMacAddr OPTIONAL\r
278 )\r
279{\r
280 EFI_STATUS Status;\r
281 EMU_SNP_PRIVATE_DATA *Private;\r
282\r
283 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
284\r
285 Status = Private->Io->StationAddress (Private->Io, Reset, NewMacAddr);\r
286 return Status;\r
287}\r
288\r
289/**\r
290 Resets or collects the statistics on a network interface.\r
291\r
292 @param This Protocol instance pointer.\r
293 @param Reset Set to TRUE to reset the statistics for the network interface.\r
294 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On\r
295 output the size, in bytes, of the resulting table of\r
296 statistics.\r
297 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r
298 contains the statistics.\r
299\r
300 @retval EFI_SUCCESS The statistics were collected from the network interface.\r
301 @retval EFI_NOT_STARTED The network interface has not been started.\r
302 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
303 size needed to hold the statistics is returned in\r
304 StatisticsSize.\r
305 @retval EFI_UNSUPPORTED Not supported yet.\r
306\r
307**/\r
308EFI_STATUS\r
309EFIAPI\r
310EmuSnpStatistics (\r
311 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
312 IN BOOLEAN Reset,\r
313 IN OUT UINTN *StatisticsSize OPTIONAL,\r
314 OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL\r
315 )\r
316{\r
317 EFI_STATUS Status;\r
318 EMU_SNP_PRIVATE_DATA *Private;\r
319\r
320 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
321\r
322 Status = Private->Io->Statistics (Private->Io, Reset, StatisticsSize, StatisticsTable);\r
323 return Status;\r
324}\r
325\r
326/**\r
327 Converts a multicast IP address to a multicast HW MAC address.\r
328\r
329 @param This Protocol instance pointer.\r
330 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r
331 to FALSE if the multicast IP address is IPv4 [RFC 791].\r
332 @param Ip The multicast IP address that is to be converted to a multicast\r
333 HW MAC address.\r
334 @param Mac The multicast HW MAC address that is to be generated from IP.\r
335\r
336 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast\r
337 HW MAC address.\r
338 @retval EFI_NOT_STARTED The network interface has not been started.\r
339 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
340 size needed to hold the statistics is returned in\r
341 StatisticsSize.\r
342 @retval EFI_UNSUPPORTED Not supported yet.\r
343\r
344**/\r
345EFI_STATUS\r
346EFIAPI\r
347EmuSnpMcastIptoMac (\r
348 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
349 IN BOOLEAN Ipv6,\r
350 IN EFI_IP_ADDRESS *Ip,\r
351 OUT EFI_MAC_ADDRESS *Mac\r
352 )\r
353{\r
354 EFI_STATUS Status;\r
355 EMU_SNP_PRIVATE_DATA *Private;\r
356\r
357 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
358\r
359 Status = Private->Io->MCastIpToMac (Private->Io, Ipv6, Ip, Mac);\r
360 return Status;\r
361}\r
362\r
363\r
364/**\r
d18d8a1d 365 Performs read and write operations on the NVRAM device attached to a\r
572287f8 366 network interface.\r
367\r
368 @param This Protocol instance pointer.\r
369 @param ReadOrWrite TRUE for read operations, FALSE for write operations.\r
370 @param Offset Byte offset in the NVRAM device at which to start the read or\r
371 write operation. This must be a multiple of NvRamAccessSize and\r
372 less than NvRamSize.\r
373 @param BufferSize The number of bytes to read or write from the NVRAM device.\r
374 This must also be a multiple of NvramAccessSize.\r
375 @param Buffer A pointer to the data buffer.\r
376\r
377 @retval EFI_UNSUPPORTED Not supported yet.\r
378\r
379**/\r
380EFI_STATUS\r
381EFIAPI\r
382EmuSnpNvdata (\r
383 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
384 IN BOOLEAN ReadOrWrite,\r
385 IN UINTN Offset,\r
386 IN UINTN BufferSize,\r
387 IN OUT VOID *Buffer\r
388 )\r
389{\r
390 EFI_STATUS Status;\r
391 EMU_SNP_PRIVATE_DATA *Private;\r
392\r
393 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
394\r
395 Status = Private->Io->NvData (Private->Io, ReadOrWrite, Offset, BufferSize, Buffer);\r
396 return Status;\r
397}\r
398\r
399\r
400/**\r
d18d8a1d 401 Reads the current interrupt status and recycled transmit buffer status from\r
572287f8 402 a network interface.\r
403\r
404 @param This Protocol instance pointer.\r
405 @param InterruptStatus A pointer to the bit mask of the currently active interrupts\r
406 If this is NULL, the interrupt status will not be read from\r
407 the device. If this is not NULL, the interrupt status will\r
408 be read from the device. When the interrupt status is read,\r
409 it will also be cleared. Clearing the transmit interrupt\r
410 does not empty the recycled transmit buffer array.\r
411 @param TxBuffer Recycled transmit buffer address. The network interface will\r
412 not transmit if its internal recycled transmit buffer array\r
413 is full. Reading the transmit buffer does not clear the\r
414 transmit interrupt. If this is NULL, then the transmit buffer\r
415 status will not be read. If there are no transmit buffers to\r
416 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r
417\r
418 @retval EFI_SUCCESS Always succeeds.\r
419\r
420**/\r
421EFI_STATUS\r
422EFIAPI\r
423EmuSnpGetStatus (\r
424 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
425 OUT UINT32 *InterruptStatus,\r
426 OUT VOID **TxBuffer\r
427 )\r
428{\r
429 EFI_STATUS Status;\r
430 EMU_SNP_PRIVATE_DATA *Private;\r
431\r
432 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
433\r
434 Status = Private->Io->GetStatus (Private->Io, InterruptStatus, TxBuffer);\r
435 return Status;\r
436}\r
437\r
438\r
439/**\r
440 Places a packet in the transmit queue of a network interface.\r
441\r
442 @param This Protocol instance pointer.\r
443 @param HeaderSize The size, in bytes, of the media header to be filled in by\r
444 the Transmit() function. If HeaderSize is non-zero, then it\r
445 must be equal to This->Mode->MediaHeaderSize and the DestAddr\r
446 and Protocol parameters must not be NULL.\r
447 @param BufferSize The size, in bytes, of the entire packet (media header and\r
448 data) to be transmitted through the network interface.\r
449 @param Buffer A pointer to the packet (media header followed by data) to be\r
450 transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r
451 then the media header in Buffer must already be filled in by the\r
452 caller. If HeaderSize is non-zero, then the media header will be\r
453 filled in by the Transmit() function.\r
454 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter\r
455 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r
456 This->Mode->CurrentAddress is used for the source HW MAC address.\r
457 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this\r
458 parameter is ignored.\r
459 @param Protocol The type of header to build. If HeaderSize is zero, then this\r
460 parameter is ignored. See RFC 1700, section "Ether Types", for\r
461 examples.\r
462\r
463 @retval EFI_SUCCESS The packet was placed on the transmit queue.\r
464 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
465 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r
466 @retval EFI_NOT_STARTED The network interface has not been started.\r
467\r
468**/\r
469EFI_STATUS\r
470EFIAPI\r
471EmuSnpTransmit (\r
472 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
473 IN UINTN HeaderSize,\r
474 IN UINTN BufferSize,\r
475 IN VOID* Buffer,\r
476 IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,\r
477 IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,\r
478 IN UINT16 *Protocol OPTIONAL\r
479 )\r
480{\r
481 EFI_STATUS Status;\r
482 EMU_SNP_PRIVATE_DATA *Private;\r
483\r
484 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
485\r
486 Status = Private->Io->Transmit (\r
487 Private->Io,\r
488 HeaderSize,\r
489 BufferSize,\r
490 Buffer,\r
491 SrcAddr,\r
492 DestAddr,\r
493 Protocol\r
494 );\r
495 return Status;\r
496}\r
497\r
498/**\r
499 Receives a packet from a network interface.\r
500\r
501 @param This Protocol instance pointer.\r
502 @param HeaderSize The size, in bytes, of the media header received on the network\r
503 interface. If this parameter is NULL, then the media header size\r
504 will not be returned.\r
505 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r
506 bytes, of the packet that was received on the network interface.\r
507 @param Buffer A pointer to the data buffer to receive both the media header and\r
508 the data.\r
509 @param SourceAddr The source HW MAC address. If this parameter is NULL, the\r
510 HW MAC source address will not be extracted from the media\r
511 header.\r
512 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,\r
513 the HW MAC destination address will not be extracted from the\r
514 media header.\r
515 @param Protocol The media header type. If this parameter is NULL, then the\r
516 protocol will not be extracted from the media header. See\r
517 RFC 1700 section "Ether Types" for examples.\r
518\r
519 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has\r
520 been updated to the number of bytes received.\r
521 @retval EFI_NOT_READY The network interface is too busy to accept this transmit\r
522 request.\r
523 @retval EFI_NOT_STARTED The network interface has not been started.\r
524 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r
525 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
526\r
527**/\r
528EFI_STATUS\r
529EFIAPI\r
530EmuSnpReceive (\r
531 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
532 OUT UINTN *HeaderSize OPTIONAL,\r
533 IN OUT UINTN *BuffSize,\r
534 OUT VOID *Buffer,\r
535 OUT EFI_MAC_ADDRESS *SourceAddr OPTIONAL,\r
536 OUT EFI_MAC_ADDRESS *DestinationAddr OPTIONAL,\r
537 OUT UINT16 *Protocol OPTIONAL\r
538 )\r
539{\r
540 EFI_STATUS Status;\r
541 EMU_SNP_PRIVATE_DATA *Private;\r
542\r
543 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r
544\r
545 Status = Private->Io->Receive (\r
546 Private->Io,\r
547 HeaderSize,\r
548 BuffSize,\r
549 Buffer,\r
550 SourceAddr,\r
551 DestinationAddr,\r
552 Protocol\r
553 );\r
554 return Status;\r
555}\r
556\r
557\r
558\r
559/**\r
560 Test to see if this driver supports ControllerHandle. This service\r
561 is called by the EFI boot service ConnectController(). In\r
562 order to make drivers as small as possible, there are a few calling\r
563 restrictions for this service. ConnectController() must\r
564 follow these calling restrictions. If any other agent wishes to call\r
565 Supported() it must also follow these calling restrictions.\r
566\r
567 @param This Protocol instance pointer.\r
568 @param ControllerHandle Handle of device to test\r
569 @param RemainingDevicePath Optional parameter use to pick a specific child\r
570 device to start.\r
571\r
572 @retval EFI_SUCCESS This driver supports this device\r
573 @retval EFI_UNSUPPORTED This driver does not support this device\r
574\r
575**/\r
576EFI_STATUS\r
577EFIAPI\r
578EmuSnpDriverBindingSupported (\r
579 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
580 IN EFI_HANDLE ControllerHandle,\r
581 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
582 )\r
583{\r
584 EFI_STATUS Status;\r
585 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
586 MAC_ADDR_DEVICE_PATH *Node;\r
587 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
588\r
589 if (RemainingDevicePath != NULL) {\r
590 if (!IsDevicePathEnd (RemainingDevicePath)) {\r
591 Node = (MAC_ADDR_DEVICE_PATH *)RemainingDevicePath;\r
592 if (Node->Header.Type != MESSAGING_DEVICE_PATH ||\r
593 Node->Header.SubType != MSG_MAC_ADDR_DP) {\r
594 // If the remaining device path does not match we don't support the request\r
595 return EFI_UNSUPPORTED;\r
596 }\r
597 }\r
598 }\r
d18d8a1d 599\r
600\r
572287f8 601 //\r
602 // Open the IO Abstraction(s) needed to perform the supported test\r
603 //\r
604 Status = gBS->OpenProtocol (\r
605 ControllerHandle,\r
606 &gEmuIoThunkProtocolGuid,\r
607 (VOID **)&EmuIoThunk,\r
608 This->DriverBindingHandle,\r
609 ControllerHandle,\r
610 EFI_OPEN_PROTOCOL_BY_DRIVER\r
611 );\r
612 if (EFI_ERROR (Status)) {\r
613 return Status;\r
614 }\r
615\r
572287f8 616 //\r
617 // Close the I/O Abstraction(s) used to perform the supported test\r
618 //\r
619 gBS->CloseProtocol (\r
620 ControllerHandle,\r
621 &gEmuIoThunkProtocolGuid,\r
622 This->DriverBindingHandle,\r
623 ControllerHandle\r
624 );\r
d18d8a1d 625\r
626\r
572287f8 627 //\r
628 // Open the EFI Device Path protocol needed to perform the supported test\r
629 //\r
630 Status = gBS->OpenProtocol (\r
631 ControllerHandle,\r
632 &gEfiDevicePathProtocolGuid,\r
633 (VOID **) &ParentDevicePath,\r
634 This->DriverBindingHandle,\r
635 ControllerHandle,\r
636 EFI_OPEN_PROTOCOL_BY_DRIVER\r
637 );\r
638 if (Status == EFI_ALREADY_STARTED) {\r
639 return EFI_SUCCESS;\r
640 }\r
641\r
642 if (EFI_ERROR (Status)) {\r
643 return Status;\r
644 }\r
645\r
f79fa76e 646 //\r
647 // Make sure GUID is for a SNP handle.\r
648 //\r
649 Status = EFI_UNSUPPORTED;\r
650 if (CompareGuid (EmuIoThunk->Protocol, &gEmuSnpProtocolGuid)) {\r
651 Status = EFI_SUCCESS;\r
652 }\r
653\r
572287f8 654 //\r
655 // Close protocol, don't use device path protocol in the Support() function\r
656 //\r
657 gBS->CloseProtocol (\r
658 ControllerHandle,\r
659 &gEfiDevicePathProtocolGuid,\r
660 This->DriverBindingHandle,\r
661 ControllerHandle\r
662 );\r
663\r
664 return Status;\r
665}\r
666\r
667\r
668/**\r
669 Start this driver on ControllerHandle. This service is called by the\r
670 EFI boot service ConnectController(). In order to make\r
671 drivers as small as possible, there are a few calling restrictions for\r
672 this service. ConnectController() must follow these\r
673 calling restrictions. If any other agent wishes to call Start() it\r
674 must also follow these calling restrictions.\r
675\r
676 @param This Protocol instance pointer.\r
677 @param ControllerHandle Handle of device to bind driver to\r
678 @param RemainingDevicePath Optional parameter use to pick a specific child\r
679 device to start.\r
680\r
681 @retval EFI_SUCCESS Always succeeds.\r
682\r
683**/\r
684EFI_STATUS\r
685EFIAPI\r
686EmuSnpDriverBindingStart (\r
687 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
688 IN EFI_HANDLE ControllerHandle,\r
689 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
690 )\r
691{\r
692 EFI_STATUS Status;\r
693 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
694 EMU_SNP_PRIVATE_DATA *Private;\r
695 MAC_ADDR_DEVICE_PATH Node;\r
696 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
697\r
54e0b04c 698 Private = NULL;\r
699\r
572287f8 700 //\r
701 // Grab the protocols we need\r
702 //\r
572287f8 703 Status = gBS->OpenProtocol(\r
704 ControllerHandle,\r
705 &gEfiDevicePathProtocolGuid,\r
706 ( VOID ** ) &ParentDevicePath,\r
707 This->DriverBindingHandle,\r
708 ControllerHandle,\r
709 EFI_OPEN_PROTOCOL_BY_DRIVER\r
710 );\r
711 if (EFI_ERROR (Status) && Status) {\r
712 return Status;\r
713 }\r
714\r
715 Status = gBS->OpenProtocol (\r
716 ControllerHandle,\r
717 &gEmuIoThunkProtocolGuid,\r
718 (VOID **)&EmuIoThunk,\r
719 This->DriverBindingHandle,\r
720 ControllerHandle,\r
721 EFI_OPEN_PROTOCOL_BY_DRIVER\r
722 );\r
723 if (EFI_ERROR (Status)) {\r
724 return Status;\r
725 }\r
726\r
727 if (!CompareGuid (EmuIoThunk->Protocol, &gEmuSnpProtocolGuid)) {\r
728 return EFI_UNSUPPORTED;\r
729 }\r
730\r
731 Status = EmuIoThunk->Open (EmuIoThunk);\r
732 if (EFI_ERROR (Status)) {\r
733 goto Done;\r
734 }\r
735\r
736 //\r
737 // Allocate the private data.\r
738 //\r
739 Private = AllocateZeroPool (sizeof (EMU_SNP_PRIVATE_DATA));\r
740 if (Private == NULL) {\r
741 Status = EFI_OUT_OF_RESOURCES;\r
742 goto Done;\r
743 }\r
744\r
745 CopyMem (&Private->Snp, &gEmuSnpTemplate, sizeof (EFI_SIMPLE_NETWORK_PROTOCOL));\r
f79fa76e 746 CopyMem (&Private->Mode, &gEmuSnpModeTemplate, sizeof (EFI_SIMPLE_NETWORK_MODE));\r
572287f8 747\r
748 Private->Signature = EMU_SNP_PRIVATE_DATA_SIGNATURE;\r
749 Private->IoThunk = EmuIoThunk;\r
750 Private->Io = EmuIoThunk->Interface;\r
751 Private->EfiHandle = ControllerHandle;\r
752 Private->DeviceHandle = NULL;\r
753 Private->Snp.Mode = &Private->Mode;\r
754 Private->ControllerNameTable = NULL;\r
755\r
d18d8a1d 756\r
572287f8 757 Status = Private->Io->CreateMapping (Private->Io, &Private->Mode);\r
758 if (EFI_ERROR (Status)) {\r
759 goto Done;\r
760 }\r
761\r
762 //\r
763 // Build the device path by appending the MAC node to the ParentDevicePath\r
764 // from the EmuIo handle.\r
765 //\r
766 ZeroMem (&Node, sizeof (MAC_ADDR_DEVICE_PATH));\r
767\r
768 Node.Header.Type = MESSAGING_DEVICE_PATH;\r
769 Node.Header.SubType = MSG_MAC_ADDR_DP;\r
770 Node.IfType = Private->Mode.IfType;\r
771\r
772 SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL * )&Node, sizeof (MAC_ADDR_DEVICE_PATH));\r
773\r
774 CopyMem (&Node.MacAddress, &Private->Mode.CurrentAddress, sizeof (EFI_MAC_ADDRESS));\r
775\r
776 //\r
777 // Build the device path by appending the MAC node to the ParentDevicePath from the EmuIo handle.\r
778 //\r
779 Private->DevicePath = AppendDevicePathNode (ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&Node);\r
780 if ( Private->DevicePath == NULL ) {\r
781 Status = EFI_OUT_OF_RESOURCES;\r
782 goto Done;\r
783 }\r
784\r
785 AddUnicodeString2 (\r
786 "eng",\r
787 gEmuSnpDriverComponentName.SupportedLanguages,\r
788 &Private->ControllerNameTable,\r
789 EmuIoThunk->ConfigString,\r
790 TRUE\r
791 );\r
d18d8a1d 792\r
572287f8 793 AddUnicodeString2 (\r
794 "en",\r
795 gEmuSnpDriverComponentName2.SupportedLanguages,\r
796 &Private->ControllerNameTable,\r
797 EmuIoThunk->ConfigString,\r
798 FALSE\r
799 );\r
800\r
801 //\r
802 // Create Child Handle\r
803 //\r
804 Status = gBS->InstallMultipleProtocolInterfaces(\r
805 &Private->DeviceHandle,\r
806 &gEfiSimpleNetworkProtocolGuid, &Private->Snp,\r
807 &gEfiDevicePathProtocolGuid, Private->DevicePath,\r
808 NULL\r
809 );\r
810 if (EFI_ERROR (Status)) {\r
811 goto Done;\r
812 }\r
813\r
814 //\r
815 // Open For Child Device\r
816 //\r
817 Status = gBS->OpenProtocol (\r
818 ControllerHandle,\r
819 &gEmuIoThunkProtocolGuid,\r
820 (VOID **)&EmuIoThunk,\r
821 This->DriverBindingHandle,\r
822 Private->DeviceHandle,\r
823 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
824 );\r
825\r
826Done:\r
827 if (EFI_ERROR (Status)) {\r
828 if (Private != NULL) {\r
829 FreePool (Private);\r
830 }\r
831 if (ParentDevicePath != NULL) {\r
832 gBS->CloseProtocol(\r
833 ControllerHandle,\r
834 &gEfiDevicePathProtocolGuid,\r
835 This->DriverBindingHandle,\r
836 ControllerHandle\r
837 );\r
838 }\r
839 }\r
840\r
841 return Status;\r
842}\r
843\r
844/**\r
845 Stop this driver on ControllerHandle. This service is called by the\r
846 EFI boot service DisconnectController(). In order to\r
847 make drivers as small as possible, there are a few calling\r
848 restrictions for this service. DisconnectController()\r
849 must follow these calling restrictions. If any other agent wishes\r
850 to call Stop() it must also follow these calling restrictions.\r
d18d8a1d 851\r
572287f8 852 @param This Protocol instance pointer.\r
853 @param ControllerHandle Handle of device to stop driver on\r
854 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
855 children is zero stop the entire bus driver.\r
856 @param ChildHandleBuffer List of Child Handles to Stop.\r
857\r
858 @retval EFI_SUCCESS Always succeeds.\r
859\r
860**/\r
861EFI_STATUS\r
862EFIAPI\r
863EmuSnpDriverBindingStop (\r
864 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
865 IN EFI_HANDLE ControllerHandle,\r
866 IN UINTN NumberOfChildren,\r
867 IN EFI_HANDLE *ChildHandleBuffer\r
868 )\r
869{\r
870 EFI_STATUS Status;\r
871 EMU_SNP_PRIVATE_DATA *Private = NULL;\r
872 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
572287f8 873\r
874 //\r
875 // Complete all outstanding transactions to Controller.\r
876 // Don't allow any new transaction to Controller to be started.\r
877 //\r
878 if (NumberOfChildren == 0) {\r
879 //\r
880 // Close the bus driver\r
881 //\r
882 Status = gBS->CloseProtocol (\r
883 ControllerHandle,\r
884 &gEmuIoThunkProtocolGuid,\r
885 This->DriverBindingHandle,\r
886 ControllerHandle\r
887 );\r
888\r
889 Status = gBS->CloseProtocol (\r
890 ControllerHandle,\r
891 &gEfiDevicePathProtocolGuid,\r
892 This->DriverBindingHandle,\r
893 ControllerHandle\r
894 );\r
895 return Status;\r
896 }\r
897\r
898 ASSERT (NumberOfChildren == 1);\r
d18d8a1d 899\r
900\r
572287f8 901 //\r
902 // Get our context back.\r
903 //\r
904 Status = gBS->OpenProtocol(\r
905 ChildHandleBuffer[0],\r
906 &gEfiSimpleNetworkProtocolGuid,\r
907 ( VOID ** ) &Snp,\r
908 This->DriverBindingHandle,\r
909 ControllerHandle,\r
910 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
911 );\r
912 if (EFI_ERROR (Status)) {\r
913 return EFI_DEVICE_ERROR;\r
914 }\r
915\r
916 Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (Snp);\r
917 Status = Private->IoThunk->Close (Private->IoThunk);\r
918\r
919 Status = gBS->CloseProtocol(\r
920 ChildHandleBuffer[0],\r
921 &gEmuIoThunkProtocolGuid,\r
922 This->DriverBindingHandle,\r
923 Private->DeviceHandle\r
924 );\r
925\r
926 Status = gBS->UninstallMultipleProtocolInterfaces(\r
927 ChildHandleBuffer[0],\r
928 &gEfiSimpleNetworkProtocolGuid, &Private->Snp,\r
929 &gEfiDevicePathProtocolGuid, Private->DevicePath,\r
930 NULL\r
931 );\r
932\r
933 FreePool (Private->DevicePath);\r
934 FreeUnicodeStringTable (Private->ControllerNameTable);\r
935 FreePool (Private);\r
936\r
937 return EFI_SUCCESS;\r
938}\r
939\r
940\r
941EFI_DRIVER_BINDING_PROTOCOL gEmuSnpDriverBinding = {\r
942 EmuSnpDriverBindingSupported,\r
943 EmuSnpDriverBindingStart,\r
944 EmuSnpDriverBindingStop,\r
945 0xA,\r
946 NULL,\r
947 NULL\r
948};\r
949\r
950\r
951\r
952/**\r
953 This is the declaration of an EFI image entry point. This entry point is\r
954 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
955 both device drivers and bus drivers.\r
956\r
957 @param ImageHandle The firmware allocated handle for the UEFI image.\r
958 @param SystemTable A pointer to the EFI System Table.\r
959\r
960 @retval EFI_SUCCESS The operation completed successfully.\r
961 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
962\r
963**/\r
964EFI_STATUS\r
965EFIAPI\r
966InitializeEmuSnpDriver (\r
967 IN EFI_HANDLE ImageHandle,\r
968 IN EFI_SYSTEM_TABLE *SystemTable\r
969 )\r
970{\r
971 EFI_STATUS Status;\r
972\r
973 //\r
974 // Install the Driver Protocols\r
975 //\r
572287f8 976 Status = EfiLibInstallDriverBindingComponentName2(\r
977 ImageHandle,\r
978 SystemTable,\r
979 &gEmuSnpDriverBinding,\r
980 ImageHandle,\r
981 &gEmuSnpDriverComponentName,\r
982 &gEmuSnpDriverComponentName2\r
983 );\r
984\r
985 return Status;\r
986}\r