iPXE
Defines | Functions
undiload.c File Reference

UNDI load/unload. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <pxe.h>
#include <realmode.h>
#include <bios.h>
#include <pnpbios.h>
#include <basemem.h>
#include <ipxe/pci.h>
#include <undi.h>
#include <undirom.h>
#include <undiload.h>

Go to the source code of this file.

Defines

#define EINFO_EUNDILOAD
#define EUNDILOAD(status)   EPLATFORM ( EINFO_EUNDILOAD, status )
#define undi_loader   __use_data16 ( undi_loader )
#define undi_loader_entry   __use_data16 ( undi_loader_entry )

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static struct s_UNDI_LOADER __bss16 (undi_loader)
 Parameter block for calling UNDI loader.
static SEGOFF16_t __bss16 (undi_loader_entry)
 UNDI loader entry point.
int undi_load (struct undi_device *undi, struct undi_rom *undirom)
 Call UNDI loader to create a pixie.
int undi_unload (struct undi_device *undi)
 Unload a pixie.

Detailed Description

UNDI load/unload.

Definition in file undiload.c.


Define Documentation

#define EINFO_EUNDILOAD
Value:
__einfo_uniqify ( EINFO_EPLATFORM, 0x01,                        \
                          "UNDI loader error" )

Definition at line 46 of file undiload.c.

#define EUNDILOAD (   status)    EPLATFORM ( EINFO_EUNDILOAD, status )

Definition at line 49 of file undiload.c.

Referenced by undi_load().

Definition at line 53 of file undiload.c.

Referenced by pxe_loader_call(), and undi_load().

Definition at line 57 of file undiload.c.

Referenced by undi_load(), and undi_unload().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static struct s_UNDI_LOADER __bss16 ( undi_loader  ) [static, read]

Parameter block for calling UNDI loader.

static SEGOFF16_t __bss16 ( undi_loader_entry  ) [static]

UNDI loader entry point.

int undi_load ( struct undi_device undi,
struct undi_rom undirom 
)

Call UNDI loader to create a pixie.

Parameters:
undiUNDI device
undiromUNDI ROM
Return values:
rcReturn status code

Definition at line 66 of file undiload.c.

References __asm__(), __from_data16, BIOS_SEG, bus, undi_rom::code_size, copy_from_real, undi_rom::data_size, DBG, DBGC, EBUSY, undi_device::entry, s_PXE::EntryPointSP, EUNDILOAD, undi_device::fbms, find_pnp_bios(), get_fbms(), undi_device::isapnp_csn, undi_device::isapnp_read_port, undi_rom::loader_entry, memset(), undi_device::pci_busdevfn, PCI_FUNC, PCI_SLOT, undi_device::ppxe, undi_device::pxenv, PXENV_EXIT_SUCCESS, rc, REAL_CODE, undi_device::restore_fbms, set_fbms(), strerror(), undi_loader, undi_loader_entry, UNDI_NO_ISAPNP_CSN, and UNDI_NO_PCI_BUSDEVFN.

Referenced by undi_load_pci().

                                                                     {
        struct s_PXE ppxe;
        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 );
                rc = -EBUSY;
                goto err_multiple;
        }

        /* Set up START_UNDI parameters */
        memset ( &undi_loader, 0, sizeof ( undi_loader ) );
        undi_loader.AX = undi->pci_busdevfn;
        undi_loader.BX = undi->isapnp_csn;
        undi_loader.DX = undi->isapnp_read_port;
        undi_loader.ES = BIOS_SEG;
        undi_loader.DI = find_pnp_bios();

        /* Allocate base memory for PXE stack */
        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 );
        undi_loader.UNDI_DS = fbms_seg;
        undi->fbms = ( fbms_seg >> 6 );
        set_fbms ( undi->fbms );
        DBGC ( undi, "UNDI %p allocated [%d,%d) kB of base memory\n",
               undi, undi->fbms, undi->restore_fbms );

        /* Debug info */
        DBGC ( undi, "UNDI %p loading ROM %p to CS %04x:%04zx DS %04x:%04zx "
               "for ", undi, undirom, undi_loader.UNDI_CS, undirom->code_size,
               undi_loader.UNDI_DS, undirom->data_size );
        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 != UNDI_NO_ISAPNP_CSN ) {
                DBGC ( undi, "ISAPnP(%04x) CSN %04x\n",
                       undi->isapnp_read_port, undi->isapnp_csn );
        }

        /* Call loader */
        undi_loader_entry = undirom->loader_entry;
        __asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t" /* gcc bug */
                                           "pushw %%ds\n\t"
                                           "pushw %%ax\n\t"
                                           "lcall *undi_loader_entry\n\t"
                                           "popl %%ebp\n\t" /* discard */
                                           "popl %%ebp\n\t" /* gcc bug */ )
                               : "=a" ( exit )
                               : "a" ( __from_data16 ( &undi_loader ) )
                               : "ebx", "ecx", "edx", "esi", "edi" );
        if ( exit != PXENV_EXIT_SUCCESS ) {
                rc = -EUNDILOAD ( undi_loader.Status );
                DBGC ( undi, "UNDI %p loader failed: %s\n",
                       undi, strerror ( rc ) );
                goto err_loader;
        }

        /* Populate PXE device structure */
        undi->pxenv = undi_loader.PXENVptr;
        undi->ppxe = undi_loader.PXEptr;
        copy_from_real ( &ppxe, undi->ppxe.segment, undi->ppxe.offset,
                         sizeof ( ppxe ) );
        undi->entry = ppxe.EntryPointSP;
        DBGC ( undi, "UNDI %p loaded PXENV+ %04x:%04x !PXE %04x:%04x "
               "entry %04x:%04x\n", undi, undi->pxenv.segment,
               undi->pxenv.offset, undi->ppxe.segment, undi->ppxe.offset,
               undi->entry.segment, undi->entry.offset );

        return 0;

 err_loader:
        set_fbms ( undi->restore_fbms );
        memset ( &undi_loader_entry, 0, sizeof ( undi_loader_entry ) );
 err_multiple:
        return rc;
}
int undi_unload ( struct undi_device undi)

Unload a pixie.

Parameters:
undiUNDI device
Return values:
rcReturn status code

Erases the PXENV+ and !PXE signatures, and frees the used base memory (if possible).

Definition at line 161 of file undiload.c.

References DBGC, EBUSY, undi_device::fbms, get_fbms(), memset(), undi_device::ppxe, put_real, undi_device::pxenv, undi_device::restore_fbms, set_fbms(), and undi_loader_entry.

Referenced by undipci_probe(), and undipci_remove().

                                             {
        static uint32_t dead = 0xdeaddead;

        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 )
                put_real ( dead, undi->ppxe.segment, undi->ppxe.offset );

        /* Free base memory, if possible */
        if ( undi->fbms == get_fbms() ) {
                DBGC ( undi, "UNDI %p freeing [%d,%d) kB of base memory\n",
                       undi, undi->fbms, undi->restore_fbms );
                set_fbms ( undi->restore_fbms );
                return 0;
        } else {
                DBGC ( undi, "UNDI %p leaking [%d,%d) kB of base memory\n",
                       undi, undi->fbms, undi->restore_fbms );
                return -EBUSY;
        }
}