* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+FILE_LICENCE ( GPL2_OR_LATER );
+
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <realmode.h>
#include <bios.h>
#include <pnpbios.h>
+#include <basemem.h>
#include <gpxe/pci.h>
#include <undi.h>
#include <undirom.h>
*/
/** Parameter block for calling UNDI loader */
-static struct s_UNDI_LOADER __data16 ( undi_loader );
+static struct s_UNDI_LOADER __bss16 ( undi_loader );
#define undi_loader __use_data16 ( undi_loader )
/** UNDI loader entry point */
-static SEGOFF16_t __data16 ( undi_loader_entry );
+static SEGOFF16_t __bss16 ( undi_loader_entry );
#define undi_loader_entry __use_data16 ( undi_loader_entry )
/**
* @v undirom UNDI ROM
* @ret rc Return status code
*/
-static int undi_load ( struct undi_device *undi, struct undi_rom *undirom ) {
+int undi_load ( struct undi_device *undi, struct undi_rom *undirom ) {
struct s_PXE ppxe;
- uint16_t fbms;
unsigned int fbms_seg;
uint16_t exit;
int rc;
+ /* Only one UNDI instance may be loaded at any given time */
+ if ( undi_loader_entry.segment ) {
+ DBG ( "UNDI %p cannot load multiple instances\n", undi );
+ return -EBUSY;
+ }
+
/* Set up START_UNDI parameters */
memset ( &undi_loader, 0, sizeof ( undi_loader ) );
undi_loader.AX = undi->pci_busdevfn;
undi_loader.DI = find_pnp_bios();
/* Allocate base memory for PXE stack */
- get_real ( fbms, BDA_SEG, BDA_FBMS );
- undi->restore_fbms = fbms;
- fbms_seg = ( fbms << 6 );
+ undi->restore_fbms = get_fbms();
+ fbms_seg = ( undi->restore_fbms << 6 );
fbms_seg -= ( ( undirom->code_size + 0x0f ) >> 4 );
undi_loader.UNDI_CS = fbms_seg;
fbms_seg -= ( ( undirom->data_size + 0x0f ) >> 4 );
/* Debug info */
DBGC ( undi, "UNDI %p loading UNDI ROM %p to CS %04x DS %04x for ",
undi, undirom, undi_loader.UNDI_CS, undi_loader.UNDI_DS );
- if ( undi->pci_busdevfn != 0xffff ) {
+ if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
unsigned int bus = ( undi->pci_busdevfn >> 8 );
unsigned int devfn = ( undi->pci_busdevfn & 0xff );
DBGC ( undi, "PCI %02x:%02x.%x\n",
bus, PCI_SLOT ( devfn ), PCI_FUNC ( devfn ) );
}
- if ( undi->isapnp_csn != 0xffff ) {
+ if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
DBGC ( undi, "ISAPnP(%04x) CSN %04x\n",
undi->isapnp_read_port, undi->isapnp_csn );
}
undi_loader_entry = undirom->loader_entry;
__asm__ __volatile__ ( REAL_CODE ( "pushw %%ds\n\t"
"pushw %%ax\n\t"
- "lcall *%c2\n\t"
+ "lcall *undi_loader_entry\n\t"
"addw $4, %%sp\n\t" )
: "=a" ( exit )
- : "a" ( & __from_data16 ( undi_loader ) ),
- "p" ( & __from_data16 ( undi_loader_entry ) )
+ : "a" ( __from_data16 ( &undi_loader ) )
: "ebx", "ecx", "edx", "esi", "edi", "ebp" );
- /* UNDI API calls may rudely change the status of A20 and not
- * bother to restore it afterwards. Intel is known to be
- * guilty of this.
- *
- * Note that we will return to this point even if A20 gets
- * screwed up by the UNDI driver, because Etherboot always
- * resides in an even megabyte of RAM.
- */
- gateA20_set();
-
if ( exit != PXENV_EXIT_SUCCESS ) {
+ /* Clear entry point */
+ memset ( &undi_loader_entry, 0, sizeof ( undi_loader_entry ) );
+
rc = -undi_loader.Status;
if ( rc == 0 ) /* Paranoia */
rc = -EIO;
undi->entry.segment, undi->entry.offset );
/* Update free base memory counter */
- fbms = ( fbms_seg >> 6 );
- put_real ( fbms, BDA_SEG, BDA_FBMS );
- undi->fbms = fbms;
+ undi->fbms = ( fbms_seg >> 6 );
+ set_fbms ( undi->fbms );
DBGC ( undi, "UNDI %p using [%d,%d) kB of base memory\n",
undi, undi->fbms, undi->restore_fbms );
return 0;
}
-/**
- * Call UNDI loader to create a pixie
- *
- * @v undi UNDI device
- * @v undirom UNDI ROM
- * @v pci_busdevfn PCI bus:dev.fn
- * @ret rc Return status code
- */
-int undi_load_pci ( struct undi_device *undi, struct undi_rom *undirom,
- unsigned int bus, unsigned int devfn ) {
- undi->pci_busdevfn = ( ( bus << 8 ) | devfn );
- undi->isapnp_csn = 0xffff;
- undi->isapnp_read_port = 0xffff;
- return undi_load ( undi, undirom );
-}
-
/**
* Unload a pixie
*
*/
int undi_unload ( struct undi_device *undi ) {
static uint32_t dead = 0xdeaddead;
- uint16_t fbms;
DBGC ( undi, "UNDI %p unloading\n", undi );
+ /* Clear entry point */
+ memset ( &undi_loader_entry, 0, sizeof ( undi_loader_entry ) );
+
/* Erase signatures */
if ( undi->pxenv.segment )
put_real ( dead, undi->pxenv.segment, undi->pxenv.offset );
- if ( undi->ppxe_segment )
+ if ( undi->ppxe.segment )
put_real ( dead, undi->ppxe.segment, undi->ppxe.offset );
/* Free base memory, if possible */
- get_real ( fbms, BDA_SEG, BDA_FBMS );
- if ( fbms == undi->fbms ) {
+ if ( undi->fbms == get_fbms() ) {
DBGC ( undi, "UNDI %p freeing [%d,%d) kB of base memory\n",
undi, undi->fbms, undi->restore_fbms );
- fbms = undi->restore_fbms;
- put_real ( fbms, BDA_SEG, BDA_FBMS );
+ set_fbms ( undi->restore_fbms );
return 0;
} else {
DBGC ( undi, "UNDI %p leaking [%d,%d) kB of base memory\n",