7 /* PXE API interface for Etherboot.
9 * Copyright (C) 2004 Michael Brown <mbrown@fensystems.co.uk>.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <gpxe/uaccess.h>
30 #include <gpxe/dhcp.h>
32 #include "pxe_callbacks.h"
35 * UNLOAD BASE CODE STACK
41 PXENV_EXIT_t pxenv_unload_stack ( struct s_PXENV_UNLOAD_STACK *unload_stack ) {
42 DBG ( "PXENV_UNLOAD_STACK" );
45 /* We need to call cleanup() at some point. The network card
46 * has already been disabled by ENSURE_CAN_UNLOAD(), but for
47 * the sake of completeness we should call the console_fini()
48 * etc. that are part of cleanup().
50 * There seems to be a lack of consensus on which is the final
51 * PXE API call to make, but it's a fairly safe bet that all
52 * the potential shutdown sequences will include a call to
53 * PXENV_UNLOAD_STACK at some point, so we may as well do it
59 unload_stack->Status = PXENV_STATUS_KEEP_ALL;
60 return PXENV_EXIT_FAILURE;
64 unload_stack->Status = PXENV_STATUS_SUCCESS;
65 return PXENV_EXIT_SUCCESS;
68 /* PXENV_GET_CACHED_INFO
72 PXENV_EXIT_t pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO
74 struct dhcp_packet dhcppkt;
78 struct dhcp_option_block *options;
82 DBG ( "PXENV_GET_CACHED_INFO %d", get_cached_info->PacketType );
84 /* This is really, really awkward to support with our multiple
87 if ( get_cached_info->BufferLimit == 0 ) {
88 DBG ( " without an external buffer. Aargh." );
92 DBG ( " to %04x:%04x+%x\n", get_cached_info->Buffer.segment,
93 get_cached_info->Buffer.offset, get_cached_info->BufferLimit );
95 /* Allocate space for temporary copy */
96 len = get_cached_info->BufferLimit;
97 data = malloc ( len );
99 DBG ( " out of memory" );
103 /* Construct DHCP packet */
104 if ( get_cached_info->PacketType == PXENV_PACKET_TYPE_DHCP_DISCOVER ) {
105 msgtype = DHCPDISCOVER;
106 options = &dhcp_request_options;
111 if ( ( rc = create_dhcp_packet ( pxe_netdev, msgtype, data, len,
112 &dhcppkt ) ) != 0 ) {
113 DBG ( " failed to build packet" );
116 if ( ( rc = copy_dhcp_packet_options ( &dhcppkt, options ) ) != 0 ) {
117 DBG ( " failed to copy options" );
121 /* Copy packet to client buffer */
122 buffer = real_to_user ( get_cached_info->Buffer.segment,
123 get_cached_info->Buffer.offset );
124 copy_to_user ( buffer, 0, data, len );
127 get_cached_info->Status = PXENV_STATUS_SUCCESS;
128 return PXENV_EXIT_SUCCESS;
133 get_cached_info->Status = PXENV_STATUS_OUT_OF_RESOURCES;
134 return PXENV_EXIT_FAILURE;
137 /* PXENV_RESTART_TFTP
141 PXENV_EXIT_t pxenv_restart_tftp ( struct s_PXENV_TFTP_READ_FILE
143 DBG ( "PXENV_RESTART_TFTP" );
146 /* Words cannot describe the complete mismatch between the PXE
147 * specification and any possible version of reality...
149 restart_tftp->Buffer = PXE_LOAD_ADDRESS; /* Fixed by spec, apparently */
150 restart_tftp->BufferSize = get_free_base_memory() - PXE_LOAD_ADDRESS; /* Near enough */
152 tftp_exit = pxe_api_call ( PXENV_TFTP_READ_FILE, (union u_PXENV_ANY*)restart_tftp );
154 if ( tftp_exit != PXENV_EXIT_SUCCESS ) return tftp_exit;
156 /* Fire up the new NBP */
157 restart_tftp->Status = xstartpxe();
160 /* Not sure what "SUCCESS" actually means, since we can only
161 * return if the new NBP failed to boot...
163 return PXENV_EXIT_SUCCESS;
170 PXENV_EXIT_t pxenv_start_undi ( struct s_PXENV_START_UNDI *start_undi ) {
172 DBG ( "PXENV_START_UNDI" );
175 /* Record PCI bus & devfn passed by caller, so we know which
176 * NIC they want to use.
178 * If they don't match our already-existing NIC structure, set
179 * values to ensure that the specified NIC is used at the next
180 * call to pxe_intialise_nic().
182 bus = ( start_undi->AX >> 8 ) & 0xff;
183 devfn = start_undi->AX & 0xff;
185 #warning "device probing mechanism has completely changed"
187 if ( ( pci->dev.driver == NULL ) ||
188 ( pci->dev.bus != bus ) || ( pci->dev.devfn != devfn ) ) {
189 /* This is quite a bit of a hack and relies on
190 * knowledge of the internal operation of Etherboot's
193 DBG ( " set PCI %hhx:%hhx.%hhx",
194 bus, PCI_SLOT(devfn), PCI_FUNC(devfn) );
195 dev->type = BOOT_NIC;
196 dev->to_probe = PROBE_PCI;
197 memset ( &dev->state, 0, sizeof(dev->state) );
199 pci->dev.use_specified = 1;
201 pci->dev.devfn = devfn;
207 start_undi->Status = PXENV_STATUS_SUCCESS;
208 return PXENV_EXIT_SUCCESS;
215 PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
216 DBG ( "PXENV_STOP_UNDI" );
219 if ( ! ensure_pxe_state(CAN_UNLOAD) ) {
220 stop_undi->Status = PXENV_STATUS_KEEP_UNDI;
221 return PXENV_EXIT_FAILURE;
225 stop_undi->Status = PXENV_STATUS_SUCCESS;
226 return PXENV_EXIT_SUCCESS;
231 * Status: won't implement (requires major structural changes)
233 PXENV_EXIT_t pxenv_start_base ( struct s_PXENV_START_BASE *start_base ) {
234 DBG ( "PXENV_START_BASE" );
236 start_base->Status = PXENV_STATUS_UNSUPPORTED;
237 return PXENV_EXIT_FAILURE;
244 PXENV_EXIT_t pxenv_stop_base ( struct s_PXENV_STOP_BASE *stop_base ) {
245 DBG ( "PXENV_STOP_BASE" );
247 /* The only time we will be called is when the NBP is trying
248 * to shut down the PXE stack. There's nothing we need to do
252 stop_base->Status = PXENV_STATUS_SUCCESS;
253 return PXENV_EXIT_SUCCESS;