You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

snp.c 3.3KB

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