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.8KB

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