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.
27 #include "pxe_callbacks.h"
30 * UNLOAD BASE CODE STACK
36 PXENV_EXIT_t pxenv_unload_stack ( struct s_PXENV_UNLOAD_STACK *unload_stack ) {
39 DBG ( "PXENV_UNLOAD_STACK" );
40 success = ensure_pxe_state ( CAN_UNLOAD );
42 /* We need to call cleanup() at some point. The network card
43 * has already been disabled by ENSURE_CAN_UNLOAD(), but for
44 * the sake of completeness we should call the console_fini()
45 * etc. that are part of cleanup().
47 * There seems to be a lack of consensus on which is the final
48 * PXE API call to make, but it's a fairly safe bet that all
49 * the potential shutdown sequences will include a call to
50 * PXENV_UNLOAD_STACK at some point, so we may as well do it
56 unload_stack->Status = PXENV_STATUS_KEEP_ALL;
57 return PXENV_EXIT_FAILURE;
60 unload_stack->Status = PXENV_STATUS_SUCCESS;
61 return PXENV_EXIT_SUCCESS;
64 /* PXENV_GET_CACHED_INFO
68 PXENV_EXIT_t pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO
70 BOOTPLAYER_t *cached_info = &pxe_stack->cached_info;
71 DBG ( "PXENV_GET_CACHED_INFO %d", get_cached_info->PacketType );
72 ENSURE_READY ( get_cached_info );
74 /* Fill in cached_info structure in our pxe_stack */
76 /* I don't think there's actually any way we can be called in
77 * the middle of a DHCP request...
79 cached_info->opcode = BOOTP_REP;
80 /* We only have Ethernet drivers */
81 cached_info->Hardware = ETHER_TYPE;
82 cached_info->Hardlen = ETH_ALEN;
83 /* PXESPEC: "Client sets" says the spec, but who's filling in
84 * this structure? It ain't the client.
86 cached_info->Gatehops = 0;
87 cached_info->ident = 0;
88 cached_info->seconds = 0;
89 cached_info->Flags = BOOTP_BCAST;
90 /* PXESPEC: What do 'Client' and 'Your' IP address refer to? */
91 cached_info->cip = arptable[ARP_CLIENT].ipaddr.s_addr;
92 cached_info->yip = arptable[ARP_CLIENT].ipaddr.s_addr;
93 cached_info->sip = arptable[ARP_SERVER].ipaddr.s_addr;
94 /* PXESPEC: Does "GIP" mean "Gateway" or "Relay agent"? */
95 cached_info->gip = arptable[ARP_GATEWAY].ipaddr.s_addr;
96 memcpy ( cached_info->CAddr, arptable[ARP_CLIENT].node, ETH_ALEN );
97 /* Nullify server name */
98 cached_info->Sname[0] = '\0';
99 memcpy ( cached_info->bootfile, KERNEL_BUF,
100 sizeof(cached_info->bootfile) );
101 /* Copy DHCP vendor options */
102 memcpy ( &cached_info->vendor.d, BOOTP_DATA_ADDR->bootp_reply.bp_vend,
103 sizeof(cached_info->vendor.d) );
105 /* Copy to user-specified buffer, or set pointer to our buffer */
106 get_cached_info->BufferLimit = sizeof(*cached_info);
107 /* PXESPEC: says to test for Buffer == NULL *and* BufferSize =
108 * 0, but what are we supposed to do with a null buffer of
111 if ( IS_NULL_SEGOFF16 ( get_cached_info->Buffer ) ) {
112 /* Point back to our buffer */
113 PTR_TO_SEGOFF16 ( cached_info, get_cached_info->Buffer );
114 get_cached_info->BufferSize = sizeof(*cached_info);
116 /* Copy to user buffer */
117 size_t size = sizeof(*cached_info);
118 void *buffer = SEGOFF16_TO_PTR ( get_cached_info->Buffer );
119 if ( get_cached_info->BufferSize < size )
120 size = get_cached_info->BufferSize;
121 DBG ( " to %x", virt_to_phys ( buffer ) );
122 memcpy ( buffer, cached_info, size );
123 /* PXESPEC: Should we return an error if the user
124 * buffer is too small? We do return the actual size
125 * of the buffer via BufferLimit, so the user does
126 * have a way to detect this already.
130 get_cached_info->Status = PXENV_STATUS_SUCCESS;
131 return PXENV_EXIT_SUCCESS;
134 /* PXENV_RESTART_TFTP
138 PXENV_EXIT_t pxenv_restart_tftp ( struct s_PXENV_TFTP_READ_FILE
140 PXENV_EXIT_t tftp_exit;
142 DBG ( "PXENV_RESTART_TFTP" );
143 ENSURE_READY ( restart_tftp );
145 /* Words cannot describe the complete mismatch between the PXE
146 * specification and any possible version of reality...
148 restart_tftp->Buffer = PXE_LOAD_ADDRESS; /* Fixed by spec, apparently */
149 restart_tftp->BufferSize = get_free_base_memory() - PXE_LOAD_ADDRESS; /* Near enough */
151 tftp_exit = pxe_api_call ( PXENV_TFTP_READ_FILE, (union u_PXENV_ANY*)restart_tftp );
153 if ( tftp_exit != PXENV_EXIT_SUCCESS ) return tftp_exit;
155 /* Fire up the new NBP */
156 restart_tftp->Status = xstartpxe();
158 /* Not sure what "SUCCESS" actually means, since we can only
159 * return if the new NBP failed to boot...
161 return PXENV_EXIT_SUCCESS;
168 PXENV_EXIT_t pxenv_start_undi ( struct s_PXENV_START_UNDI *start_undi ) {
169 unsigned char bus, devfn;
171 DBG ( "PXENV_START_UNDI" );
172 ENSURE_MIDWAY(start_undi);
174 /* Record PCI bus & devfn passed by caller, so we know which
175 * NIC they want to use.
177 * If they don't match our already-existing NIC structure, set
178 * values to ensure that the specified NIC is used at the next
179 * call to pxe_intialise_nic().
181 bus = ( start_undi->AX >> 8 ) & 0xff;
182 devfn = start_undi->AX & 0xff;
184 #warning "device probing mechanism has completely changed"
186 if ( ( pci->dev.driver == NULL ) ||
187 ( pci->dev.bus != bus ) || ( pci->dev.devfn != devfn ) ) {
188 /* This is quite a bit of a hack and relies on
189 * knowledge of the internal operation of Etherboot's
192 DBG ( " set PCI %hhx:%hhx.%hhx",
193 bus, PCI_SLOT(devfn), PCI_FUNC(devfn) );
194 dev->type = BOOT_NIC;
195 dev->to_probe = PROBE_PCI;
196 memset ( &dev->state, 0, sizeof(dev->state) );
198 pci->dev.use_specified = 1;
200 pci->dev.devfn = devfn;
204 start_undi->Status = PXENV_STATUS_SUCCESS;
205 return PXENV_EXIT_SUCCESS;
212 PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
213 DBG ( "PXENV_STOP_UNDI" );
215 if ( ! ensure_pxe_state(CAN_UNLOAD) ) {
216 stop_undi->Status = PXENV_STATUS_KEEP_UNDI;
217 return PXENV_EXIT_FAILURE;
220 stop_undi->Status = PXENV_STATUS_SUCCESS;
221 return PXENV_EXIT_SUCCESS;
226 * Status: won't implement (requires major structural changes)
228 PXENV_EXIT_t pxenv_start_base ( struct s_PXENV_START_BASE *start_base ) {
229 DBG ( "PXENV_START_BASE" );
230 /* ENSURE_READY ( start_base ); */
231 start_base->Status = PXENV_STATUS_UNSUPPORTED;
232 return PXENV_EXIT_FAILURE;
239 PXENV_EXIT_t pxenv_stop_base ( struct s_PXENV_STOP_BASE *stop_base ) {
240 DBG ( "PXENV_STOP_BASE" );
242 /* The only time we will be called is when the NBP is trying
243 * to shut down the PXE stack. There's nothing we need to do
247 stop_base->Status = PXENV_STATUS_SUCCESS;
248 return PXENV_EXIT_SUCCESS;