Add qemu 2.4.0
[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
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 #include <errno.h>
23 #include <ipxe/efi/efi.h>
24 #include <ipxe/efi/efi_driver.h>
25 #include <ipxe/efi/efi_snp.h>
26 #include "snpnet.h"
27 #include "nii.h"
28
29 /** @file
30  *
31  * SNP driver
32  *
33  */
34
35 /**
36  * Check to see if driver supports a device
37  *
38  * @v device            EFI device handle
39  * @ret rc              Return status code
40  */
41 static int snp_supported ( EFI_HANDLE device ) {
42         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
43         EFI_STATUS efirc;
44
45         /* Check that this is not a device we are providing ourselves */
46         if ( find_snpdev ( device ) != NULL ) {
47                 DBGCP ( device, "SNP %p %s is provided by this binary\n",
48                         device, efi_handle_name ( device ) );
49                 return -ENOTTY;
50         }
51
52         /* Test for presence of simple network protocol */
53         if ( ( efirc = bs->OpenProtocol ( device,
54                                           &efi_simple_network_protocol_guid,
55                                           NULL, efi_image_handle, device,
56                                           EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){
57                 DBGCP ( device, "SNP %p %s is not an SNP device\n",
58                         device, efi_handle_name ( device ) );
59                 return -EEFI ( efirc );
60         }
61         DBGC ( device, "SNP %p %s is an SNP device\n",
62                device, efi_handle_name ( device ) );
63
64         return 0;
65 }
66
67 /**
68  * Check to see if driver supports a device
69  *
70  * @v device            EFI device handle
71  * @ret rc              Return status code
72  */
73 static int nii_supported ( EFI_HANDLE device ) {
74         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
75         EFI_STATUS efirc;
76
77         /* Check that this is not a device we are providing ourselves */
78         if ( find_snpdev ( device ) != NULL ) {
79                 DBGCP ( device, "NII %p %s is provided by this binary\n",
80                         device, efi_handle_name ( device ) );
81                 return -ENOTTY;
82         }
83
84         /* Test for presence of NII protocol */
85         if ( ( efirc = bs->OpenProtocol ( device,
86                                           &efi_nii31_protocol_guid,
87                                           NULL, efi_image_handle, device,
88                                           EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){
89                 DBGCP ( device, "NII %p %s is not an NII device\n",
90                         device, efi_handle_name ( device ) );
91                 return -EEFI ( efirc );
92         }
93         DBGC ( device, "NII %p %s is an NII device\n",
94                device, efi_handle_name ( device ) );
95
96         return 0;
97 }
98
99 /** EFI SNP driver */
100 struct efi_driver snp_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
101         .name = "SNP",
102         .supported = snp_supported,
103         .start = snpnet_start,
104         .stop = snpnet_stop,
105 };
106
107 /** EFI NII driver */
108 struct efi_driver nii_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
109         .name = "NII",
110         .supported = nii_supported,
111         .start = nii_start,
112         .stop = nii_stop,
113 };