These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / drivers / net / efi / snp.c
1 /*
2  * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 #include <errno.h>
27 #include <ipxe/efi/efi.h>
28 #include <ipxe/efi/efi_driver.h>
29 #include <ipxe/efi/efi_snp.h>
30 #include "snpnet.h"
31 #include "nii.h"
32
33 /** @file
34  *
35  * SNP driver
36  *
37  */
38
39 /**
40  * Check to see if driver supports a device
41  *
42  * @v device            EFI device handle
43  * @ret rc              Return status code
44  */
45 static int snp_supported ( EFI_HANDLE device ) {
46         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
47         EFI_STATUS efirc;
48
49         /* Check that this is not a device we are providing ourselves */
50         if ( find_snpdev ( device ) != NULL ) {
51                 DBGCP ( device, "SNP %p %s is provided by this binary\n",
52                         device, efi_handle_name ( device ) );
53                 return -ENOTTY;
54         }
55
56         /* Test for presence of simple network protocol */
57         if ( ( efirc = bs->OpenProtocol ( device,
58                                           &efi_simple_network_protocol_guid,
59                                           NULL, efi_image_handle, device,
60                                           EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){
61                 DBGCP ( device, "SNP %p %s is not an SNP device\n",
62                         device, efi_handle_name ( device ) );
63                 return -EEFI ( efirc );
64         }
65         DBGC ( device, "SNP %p %s is an SNP device\n",
66                device, efi_handle_name ( device ) );
67
68         return 0;
69 }
70
71 /**
72  * Check to see if driver supports a device
73  *
74  * @v device            EFI device handle
75  * @ret rc              Return status code
76  */
77 static int nii_supported ( EFI_HANDLE device ) {
78         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
79         EFI_STATUS efirc;
80
81         /* Check that this is not a device we are providing ourselves */
82         if ( find_snpdev ( device ) != NULL ) {
83                 DBGCP ( device, "NII %p %s is provided by this binary\n",
84                         device, efi_handle_name ( device ) );
85                 return -ENOTTY;
86         }
87
88         /* Test for presence of NII protocol */
89         if ( ( efirc = bs->OpenProtocol ( device,
90                                           &efi_nii31_protocol_guid,
91                                           NULL, efi_image_handle, device,
92                                           EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){
93                 DBGCP ( device, "NII %p %s is not an NII device\n",
94                         device, efi_handle_name ( device ) );
95                 return -EEFI ( efirc );
96         }
97         DBGC ( device, "NII %p %s is an NII device\n",
98                device, efi_handle_name ( device ) );
99
100         return 0;
101 }
102
103 /** EFI SNP driver */
104 struct efi_driver snp_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
105         .name = "SNP",
106         .supported = snp_supported,
107         .start = snpnet_start,
108         .stop = snpnet_stop,
109 };
110
111 /** EFI NII driver */
112 struct efi_driver nii_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
113         .name = "NII",
114         .supported = nii_supported,
115         .start = nii_start,
116         .stop = nii_stop,
117 };