您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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