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.

pxeparent.c 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (C) 2007 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 <ipxe/dhcp.h>
  21. #include <pxeparent.h>
  22. #include <pxe_api.h>
  23. #include <pxe_types.h>
  24. #include <pxe.h>
  25. /** @file
  26. *
  27. * Call interface to parent PXE stack
  28. *
  29. */
  30. /**
  31. * Name PXE API call
  32. *
  33. * @v function API call number
  34. * @ret name API call name
  35. */
  36. static inline __attribute__ (( always_inline )) const char *
  37. pxeparent_function_name ( unsigned int function ) {
  38. switch ( function ) {
  39. case PXENV_START_UNDI:
  40. return "PXENV_START_UNDI";
  41. case PXENV_STOP_UNDI:
  42. return "PXENV_STOP_UNDI";
  43. case PXENV_UNDI_STARTUP:
  44. return "PXENV_UNDI_STARTUP";
  45. case PXENV_UNDI_CLEANUP:
  46. return "PXENV_UNDI_CLEANUP";
  47. case PXENV_UNDI_INITIALIZE:
  48. return "PXENV_UNDI_INITIALIZE";
  49. case PXENV_UNDI_RESET_ADAPTER:
  50. return "PXENV_UNDI_RESET_ADAPTER";
  51. case PXENV_UNDI_SHUTDOWN:
  52. return "PXENV_UNDI_SHUTDOWN";
  53. case PXENV_UNDI_OPEN:
  54. return "PXENV_UNDI_OPEN";
  55. case PXENV_UNDI_CLOSE:
  56. return "PXENV_UNDI_CLOSE";
  57. case PXENV_UNDI_TRANSMIT:
  58. return "PXENV_UNDI_TRANSMIT";
  59. case PXENV_UNDI_SET_MCAST_ADDRESS:
  60. return "PXENV_UNDI_SET_MCAST_ADDRESS";
  61. case PXENV_UNDI_SET_STATION_ADDRESS:
  62. return "PXENV_UNDI_SET_STATION_ADDRESS";
  63. case PXENV_UNDI_SET_PACKET_FILTER:
  64. return "PXENV_UNDI_SET_PACKET_FILTER";
  65. case PXENV_UNDI_GET_INFORMATION:
  66. return "PXENV_UNDI_GET_INFORMATION";
  67. case PXENV_UNDI_GET_STATISTICS:
  68. return "PXENV_UNDI_GET_STATISTICS";
  69. case PXENV_UNDI_CLEAR_STATISTICS:
  70. return "PXENV_UNDI_CLEAR_STATISTICS";
  71. case PXENV_UNDI_INITIATE_DIAGS:
  72. return "PXENV_UNDI_INITIATE_DIAGS";
  73. case PXENV_UNDI_FORCE_INTERRUPT:
  74. return "PXENV_UNDI_FORCE_INTERRUPT";
  75. case PXENV_UNDI_GET_MCAST_ADDRESS:
  76. return "PXENV_UNDI_GET_MCAST_ADDRESS";
  77. case PXENV_UNDI_GET_NIC_TYPE:
  78. return "PXENV_UNDI_GET_NIC_TYPE";
  79. case PXENV_UNDI_GET_IFACE_INFO:
  80. return "PXENV_UNDI_GET_IFACE_INFO";
  81. /*
  82. * Duplicate case value; this is a bug in the PXE specification.
  83. *
  84. * case PXENV_UNDI_GET_STATE:
  85. * return "PXENV_UNDI_GET_STATE";
  86. */
  87. case PXENV_UNDI_ISR:
  88. return "PXENV_UNDI_ISR";
  89. case PXENV_GET_CACHED_INFO:
  90. return "PXENV_GET_CACHED_INFO";
  91. default:
  92. return "UNKNOWN API CALL";
  93. }
  94. }
  95. /**
  96. * PXE parent parameter block
  97. *
  98. * Used as the paramter block for all parent PXE API calls. Resides in base
  99. * memory.
  100. */
  101. static union u_PXENV_ANY __bss16 ( pxeparent_params );
  102. #define pxeparent_params __use_data16 ( pxeparent_params )
  103. /** PXE parent entry point
  104. *
  105. * Used as the indirection vector for all parent PXE API calls. Resides in
  106. * base memory.
  107. */
  108. SEGOFF16_t __bss16 ( pxeparent_entry_point );
  109. #define pxeparent_entry_point __use_data16 ( pxeparent_entry_point )
  110. /**
  111. * Issue parent PXE API call
  112. *
  113. * @v entry Parent PXE stack entry point
  114. * @v function API call number
  115. * @v params PXE parameter block
  116. * @v params_len Length of PXE parameter block
  117. * @ret rc Return status code
  118. */
  119. int pxeparent_call ( SEGOFF16_t entry, unsigned int function,
  120. void *params, size_t params_len ) {
  121. PXENV_EXIT_t exit;
  122. int discard_b, discard_D;
  123. int rc;
  124. /* Copy parameter block and entry point */
  125. assert ( params_len <= sizeof ( pxeparent_params ) );
  126. memcpy ( &pxeparent_params, params, params_len );
  127. memcpy ( &pxeparent_entry_point, &entry, sizeof ( entry ) );
  128. /* Call real-mode entry point. This calling convention will
  129. * work with both the !PXE and the PXENV+ entry points.
  130. */
  131. __asm__ __volatile__ ( REAL_CODE ( "pushw %%es\n\t"
  132. "pushw %%di\n\t"
  133. "pushw %%bx\n\t"
  134. "lcall *pxeparent_entry_point\n\t"
  135. "addw $6, %%sp\n\t" )
  136. : "=a" ( exit ), "=b" ( discard_b ),
  137. "=D" ( discard_D )
  138. : "b" ( function ),
  139. "D" ( __from_data16 ( &pxeparent_params ) )
  140. : "ecx", "edx", "esi", "ebp" );
  141. /* Determine return status code based on PXENV_EXIT and
  142. * PXENV_STATUS
  143. */
  144. if ( exit == PXENV_EXIT_SUCCESS ) {
  145. rc = 0;
  146. } else {
  147. rc = -pxeparent_params.Status;
  148. /* Paranoia; don't return success for the combination
  149. * of PXENV_EXIT_FAILURE but PXENV_STATUS_SUCCESS
  150. */
  151. if ( rc == 0 )
  152. rc = -EIO;
  153. }
  154. /* If anything goes wrong, print as much debug information as
  155. * it's possible to give.
  156. */
  157. if ( rc != 0 ) {
  158. SEGOFF16_t rm_params = {
  159. .segment = rm_ds,
  160. .offset = __from_data16 ( &pxeparent_params ),
  161. };
  162. DBG ( "PXEPARENT %s failed: %s\n",
  163. pxeparent_function_name ( function ), strerror ( rc ) );
  164. DBG ( "PXEPARENT parameters at %04x:%04x length "
  165. "%#02zx, entry point at %04x:%04x\n",
  166. rm_params.segment, rm_params.offset, params_len,
  167. pxeparent_entry_point.segment,
  168. pxeparent_entry_point.offset );
  169. DBG ( "PXEPARENT parameters provided:\n" );
  170. DBG_HDA ( rm_params, params, params_len );
  171. DBG ( "PXEPARENT parameters returned:\n" );
  172. DBG_HDA ( rm_params, &pxeparent_params, params_len );
  173. }
  174. /* Copy parameter block back */
  175. memcpy ( params, &pxeparent_params, params_len );
  176. return rc;
  177. }