iPXE
snp.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <errno.h>
00027 #include <ipxe/efi/efi.h>
00028 #include <ipxe/efi/efi_driver.h>
00029 #include <ipxe/efi/efi_snp.h>
00030 #include "snpnet.h"
00031 #include "nii.h"
00032 
00033 /** @file
00034  *
00035  * SNP driver
00036  *
00037  */
00038 
00039 /**
00040  * Check to see if driver supports a device
00041  *
00042  * @v device            EFI device handle
00043  * @ret rc              Return status code
00044  */
00045 static int snp_supported ( EFI_HANDLE device ) {
00046         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
00047         EFI_STATUS efirc;
00048 
00049         /* Check that this is not a device we are providing ourselves */
00050         if ( find_snpdev ( device ) != NULL ) {
00051                 DBGCP ( device, "SNP %s is provided by this binary\n",
00052                         efi_handle_name ( device ) );
00053                 return -ENOTTY;
00054         }
00055 
00056         /* Test for presence of simple network protocol */
00057         if ( ( efirc = bs->OpenProtocol ( device,
00058                                           &efi_simple_network_protocol_guid,
00059                                           NULL, efi_image_handle, device,
00060                                           EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){
00061                 DBGCP ( device, "SNP %s is not an SNP device\n",
00062                         efi_handle_name ( device ) );
00063                 return -EEFI ( efirc );
00064         }
00065         DBGC ( device, "SNP %s is an SNP device\n",
00066                efi_handle_name ( device ) );
00067 
00068         return 0;
00069 }
00070 
00071 /**
00072  * Check to see if driver supports a device
00073  *
00074  * @v device            EFI device handle
00075  * @ret rc              Return status code
00076  */
00077 static int nii_supported ( EFI_HANDLE device ) {
00078         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
00079         EFI_STATUS efirc;
00080 
00081         /* Check that this is not a device we are providing ourselves */
00082         if ( find_snpdev ( device ) != NULL ) {
00083                 DBGCP ( device, "NII %s is provided by this binary\n",
00084                         efi_handle_name ( device ) );
00085                 return -ENOTTY;
00086         }
00087 
00088         /* Test for presence of NII protocol */
00089         if ( ( efirc = bs->OpenProtocol ( device,
00090                                           &efi_nii31_protocol_guid,
00091                                           NULL, efi_image_handle, device,
00092                                           EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){
00093                 DBGCP ( device, "NII %s is not an NII device\n",
00094                         efi_handle_name ( device ) );
00095                 return -EEFI ( efirc );
00096         }
00097         DBGC ( device, "NII %s is an NII device\n",
00098                efi_handle_name ( device ) );
00099 
00100         return 0;
00101 }
00102 
00103 /** EFI SNP driver */
00104 struct efi_driver snp_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
00105         .name = "SNP",
00106         .supported = snp_supported,
00107         .start = snpnet_start,
00108         .stop = snpnet_stop,
00109 };
00110 
00111 /** EFI NII driver */
00112 struct efi_driver nii_driver __efi_driver ( EFI_DRIVER_NORMAL ) = {
00113         .name = "NII",
00114         .supported = nii_supported,
00115         .start = nii_start,
00116         .stop = nii_stop,
00117 };