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 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 <ipxe/profile.h>
  22. #include <pxeparent.h>
  23. #include <pxe_api.h>
  24. #include <pxe_types.h>
  25. #include <pxe.h>
  26. /** @file
  27. *
  28. * Call interface to parent PXE stack
  29. *
  30. */
  31. /* Disambiguate the various error causes */
  32. #define EINFO_EPXECALL \
  33. __einfo_uniqify ( EINFO_EPLATFORM, 0x01, \
  34. "External PXE API error" )
  35. #define EPXECALL( status ) EPLATFORM ( EINFO_EPXECALL, status )
  36. /** A parent PXE API call profiler */
  37. struct pxeparent_profiler {
  38. /** Total time spent performing REAL_CALL() */
  39. struct profiler total;
  40. /** Time spent transitioning to real mode */
  41. struct profiler p2r;
  42. /** Time spent in external code */
  43. struct profiler ext;
  44. /** Time spent transitioning back to protected mode */
  45. struct profiler r2p;
  46. };
  47. /** PXENV_UNDI_TRANSMIT profiler */
  48. static struct pxeparent_profiler pxeparent_tx_profiler __profiler = {
  49. { .name = "pxeparent.tx" },
  50. { .name = "pxeparent.tx_p2r" },
  51. { .name = "pxeparent.tx_ext" },
  52. { .name = "pxeparent.tx_r2p" },
  53. };
  54. /** PXENV_UNDI_ISR profiler
  55. *
  56. * Note that this profiler will not see calls to
  57. * PXENV_UNDI_ISR_IN_START, which are handled by the UNDI ISR and do
  58. * not go via pxeparent_call().
  59. */
  60. static struct pxeparent_profiler pxeparent_isr_profiler __profiler = {
  61. { .name = "pxeparent.isr" },
  62. { .name = "pxeparent.isr_p2r" },
  63. { .name = "pxeparent.isr_ext" },
  64. { .name = "pxeparent.isr_r2p" },
  65. };
  66. /** PXE unknown API call profiler
  67. *
  68. * This profiler can be used to measure the overhead of a dummy PXE
  69. * API call.
  70. */
  71. static struct pxeparent_profiler pxeparent_unknown_profiler __profiler = {
  72. { .name = "pxeparent.unknown" },
  73. { .name = "pxeparent.unknown_p2r" },
  74. { .name = "pxeparent.unknown_ext" },
  75. { .name = "pxeparent.unknown_r2p" },
  76. };
  77. /** Miscellaneous PXE API call profiler */
  78. static struct pxeparent_profiler pxeparent_misc_profiler __profiler = {
  79. { .name = "pxeparent.misc" },
  80. { .name = "pxeparent.misc_p2r" },
  81. { .name = "pxeparent.misc_ext" },
  82. { .name = "pxeparent.misc_r2p" },
  83. };
  84. /**
  85. * Name PXE API call
  86. *
  87. * @v function API call number
  88. * @ret name API call name
  89. */
  90. static inline __attribute__ (( always_inline )) const char *
  91. pxeparent_function_name ( unsigned int function ) {
  92. switch ( function ) {
  93. case PXENV_START_UNDI:
  94. return "PXENV_START_UNDI";
  95. case PXENV_STOP_UNDI:
  96. return "PXENV_STOP_UNDI";
  97. case PXENV_UNDI_STARTUP:
  98. return "PXENV_UNDI_STARTUP";
  99. case PXENV_UNDI_CLEANUP:
  100. return "PXENV_UNDI_CLEANUP";
  101. case PXENV_UNDI_INITIALIZE:
  102. return "PXENV_UNDI_INITIALIZE";
  103. case PXENV_UNDI_RESET_ADAPTER:
  104. return "PXENV_UNDI_RESET_ADAPTER";
  105. case PXENV_UNDI_SHUTDOWN:
  106. return "PXENV_UNDI_SHUTDOWN";
  107. case PXENV_UNDI_OPEN:
  108. return "PXENV_UNDI_OPEN";
  109. case PXENV_UNDI_CLOSE:
  110. return "PXENV_UNDI_CLOSE";
  111. case PXENV_UNDI_TRANSMIT:
  112. return "PXENV_UNDI_TRANSMIT";
  113. case PXENV_UNDI_SET_MCAST_ADDRESS:
  114. return "PXENV_UNDI_SET_MCAST_ADDRESS";
  115. case PXENV_UNDI_SET_STATION_ADDRESS:
  116. return "PXENV_UNDI_SET_STATION_ADDRESS";
  117. case PXENV_UNDI_SET_PACKET_FILTER:
  118. return "PXENV_UNDI_SET_PACKET_FILTER";
  119. case PXENV_UNDI_GET_INFORMATION:
  120. return "PXENV_UNDI_GET_INFORMATION";
  121. case PXENV_UNDI_GET_STATISTICS:
  122. return "PXENV_UNDI_GET_STATISTICS";
  123. case PXENV_UNDI_CLEAR_STATISTICS:
  124. return "PXENV_UNDI_CLEAR_STATISTICS";
  125. case PXENV_UNDI_INITIATE_DIAGS:
  126. return "PXENV_UNDI_INITIATE_DIAGS";
  127. case PXENV_UNDI_FORCE_INTERRUPT:
  128. return "PXENV_UNDI_FORCE_INTERRUPT";
  129. case PXENV_UNDI_GET_MCAST_ADDRESS:
  130. return "PXENV_UNDI_GET_MCAST_ADDRESS";
  131. case PXENV_UNDI_GET_NIC_TYPE:
  132. return "PXENV_UNDI_GET_NIC_TYPE";
  133. case PXENV_UNDI_GET_IFACE_INFO:
  134. return "PXENV_UNDI_GET_IFACE_INFO";
  135. /*
  136. * Duplicate case value; this is a bug in the PXE specification.
  137. *
  138. * case PXENV_UNDI_GET_STATE:
  139. * return "PXENV_UNDI_GET_STATE";
  140. */
  141. case PXENV_UNDI_ISR:
  142. return "PXENV_UNDI_ISR";
  143. case PXENV_GET_CACHED_INFO:
  144. return "PXENV_GET_CACHED_INFO";
  145. default:
  146. return "UNKNOWN API CALL";
  147. }
  148. }
  149. /**
  150. * Determine applicable profiler pair (for debugging)
  151. *
  152. * @v function API call number
  153. * @ret profiler Profiler
  154. */
  155. static struct pxeparent_profiler * pxeparent_profiler ( unsigned int function ){
  156. /* Determine applicable profiler */
  157. switch ( function ) {
  158. case PXENV_UNDI_TRANSMIT:
  159. return &pxeparent_tx_profiler;
  160. case PXENV_UNDI_ISR:
  161. return &pxeparent_isr_profiler;
  162. case PXENV_UNKNOWN:
  163. return &pxeparent_unknown_profiler;
  164. default:
  165. return &pxeparent_misc_profiler;
  166. }
  167. }
  168. /**
  169. * PXE parent parameter block
  170. *
  171. * Used as the parameter block for all parent PXE API calls. Resides
  172. * in base memory.
  173. */
  174. static union u_PXENV_ANY __bss16 ( pxeparent_params );
  175. #define pxeparent_params __use_data16 ( pxeparent_params )
  176. /** PXE parent entry point
  177. *
  178. * Used as the indirection vector for all parent PXE API calls. Resides in
  179. * base memory.
  180. */
  181. SEGOFF16_t __bss16 ( pxeparent_entry_point );
  182. #define pxeparent_entry_point __use_data16 ( pxeparent_entry_point )
  183. /**
  184. * Issue parent PXE API call
  185. *
  186. * @v entry Parent PXE stack entry point
  187. * @v function API call number
  188. * @v params PXE parameter block
  189. * @v params_len Length of PXE parameter block
  190. * @ret rc Return status code
  191. */
  192. int pxeparent_call ( SEGOFF16_t entry, unsigned int function,
  193. void *params, size_t params_len ) {
  194. struct pxeparent_profiler *profiler = pxeparent_profiler ( function );
  195. PXENV_EXIT_t exit;
  196. unsigned long started;
  197. unsigned long stopped;
  198. int discard_D;
  199. int rc;
  200. /* Copy parameter block and entry point */
  201. assert ( params_len <= sizeof ( pxeparent_params ) );
  202. memcpy ( &pxeparent_params, params, params_len );
  203. memcpy ( &pxeparent_entry_point, &entry, sizeof ( entry ) );
  204. /* Call real-mode entry point. This calling convention will
  205. * work with both the !PXE and the PXENV+ entry points.
  206. */
  207. profile_start ( &profiler->total );
  208. __asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t" /* gcc bug */
  209. "rdtsc\n\t"
  210. "pushl %%eax\n\t"
  211. "pushw %%es\n\t"
  212. "pushw %%di\n\t"
  213. "pushw %%bx\n\t"
  214. "lcall *pxeparent_entry_point\n\t"
  215. "movw %%ax, %%bx\n\t"
  216. "rdtsc\n\t"
  217. "addw $6, %%sp\n\t"
  218. "popl %%edx\n\t"
  219. "popl %%ebp\n\t" /* gcc bug */ )
  220. : "=a" ( stopped ), "=d" ( started ),
  221. "=b" ( exit ), "=D" ( discard_D )
  222. : "b" ( function ),
  223. "D" ( __from_data16 ( &pxeparent_params ) )
  224. : "ecx", "esi" );
  225. profile_stop ( &profiler->total );
  226. profile_start_at ( &profiler->p2r, profiler->total.started );
  227. profile_stop_at ( &profiler->p2r, started );
  228. profile_start_at ( &profiler->ext, started );
  229. profile_stop_at ( &profiler->ext, stopped );
  230. profile_start_at ( &profiler->r2p, stopped );
  231. profile_stop_at ( &profiler->r2p, profiler->total.stopped );
  232. /* Determine return status code based on PXENV_EXIT and
  233. * PXENV_STATUS
  234. */
  235. rc = ( ( exit == PXENV_EXIT_SUCCESS ) ?
  236. 0 : -EPXECALL ( pxeparent_params.Status ) );
  237. /* If anything goes wrong, print as much debug information as
  238. * it's possible to give.
  239. */
  240. if ( rc != 0 ) {
  241. SEGOFF16_t rm_params = {
  242. .segment = rm_ds,
  243. .offset = __from_data16 ( &pxeparent_params ),
  244. };
  245. DBG ( "PXEPARENT %s failed: %s\n",
  246. pxeparent_function_name ( function ), strerror ( rc ) );
  247. DBG ( "PXEPARENT parameters at %04x:%04x length "
  248. "%#02zx, entry point at %04x:%04x\n",
  249. rm_params.segment, rm_params.offset, params_len,
  250. pxeparent_entry_point.segment,
  251. pxeparent_entry_point.offset );
  252. DBG ( "PXEPARENT parameters provided:\n" );
  253. DBG_HDA ( rm_params, params, params_len );
  254. DBG ( "PXEPARENT parameters returned:\n" );
  255. DBG_HDA ( rm_params, &pxeparent_params, params_len );
  256. }
  257. /* Copy parameter block back */
  258. memcpy ( params, &pxeparent_params, params_len );
  259. return rc;
  260. }