iPXE
undiload.h File Reference

UNDI load/unload. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
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.
static int undi_load_pci (struct undi_device *undi, struct undi_rom *undirom, unsigned int pci_busdevfn)
 Call UNDI loader to create a pixie.

Detailed Description

UNDI load/unload.

Definition in file undiload.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ undi_load()

int undi_load ( struct undi_device * undi,
struct undi_rom * undirom )
extern

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.

66 {
67 struct s_PXE ppxe;
68 unsigned int fbms_seg;
69 uint16_t exit;
70 int rc;
71
72 /* Only one UNDI instance may be loaded at any given time */
73 if ( undi_loader_entry.segment ) {
74 DBG ( "UNDI %p cannot load multiple instances\n", undi );
75 rc = -EBUSY;
76 goto err_multiple;
77 }
78
79 /* Set up START_UNDI parameters */
80 memset ( &undi_loader, 0, sizeof ( undi_loader ) );
81 undi_loader.AX = undi->pci_busdevfn;
82 undi_loader.BX = undi->isapnp_csn;
86
87 /* Allocate base memory for PXE stack */
88 undi->restore_fbms = get_fbms();
89 fbms_seg = ( undi->restore_fbms << 6 );
90 fbms_seg -= ( ( undirom->code_size + 0x0f ) >> 4 );
91 undi_loader.UNDI_CS = fbms_seg;
92 fbms_seg -= ( ( undirom->data_size + 0x0f ) >> 4 );
93 undi_loader.UNDI_DS = fbms_seg;
94 undi->fbms = ( fbms_seg >> 6 );
95 set_fbms ( undi->fbms );
96 DBGC ( undi, "UNDI %p allocated [%d,%d) kB of base memory\n",
97 undi, undi->fbms, undi->restore_fbms );
98
99 /* Debug info */
100 DBGC ( undi, "UNDI %p loading ROM %p to CS %04x:%04zx DS %04x:%04zx "
101 "for ", undi, undirom, undi_loader.UNDI_CS, undirom->code_size,
102 undi_loader.UNDI_DS, undirom->data_size );
103 if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
104 unsigned int bus = ( undi->pci_busdevfn >> 8 );
105 unsigned int devfn = ( undi->pci_busdevfn & 0xff );
106 DBGC ( undi, "PCI %02x:%02x.%x\n",
107 bus, PCI_SLOT ( devfn ), PCI_FUNC ( devfn ) );
108 }
109 if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
110 DBGC ( undi, "ISAPnP(%04x) CSN %04x\n",
111 undi->isapnp_read_port, undi->isapnp_csn );
112 }
113
114 /* Call loader */
116 __asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t" /* gcc bug */
117 "pushw %%ds\n\t"
118 "pushw %%ax\n\t"
119 "lcall *undi_loader_entry\n\t"
120 "popl %%ebp\n\t" /* discard */
121 "popl %%ebp\n\t" /* gcc bug */ )
122 : "=a" ( exit )
123 : "a" ( __from_data16 ( &undi_loader ) )
124 : "ebx", "ecx", "edx", "esi", "edi" );
125 if ( exit != PXENV_EXIT_SUCCESS ) {
126 rc = -EUNDILOAD ( undi_loader.Status );
127 DBGC ( undi, "UNDI %p loader failed: %s\n",
128 undi, strerror ( rc ) );
129 goto err_loader;
130 }
131
132 /* Populate PXE device structure */
133 undi->pxenv = undi_loader.PXENVptr;
134 undi->ppxe = undi_loader.PXEptr;
135 copy_from_real ( &ppxe, undi->ppxe.segment, undi->ppxe.offset,
136 sizeof ( ppxe ) );
137 undi->entry = ppxe.EntryPointSP;
138 DBGC ( undi, "UNDI %p loaded PXENV+ %04x:%04x !PXE %04x:%04x "
139 "entry %04x:%04x\n", undi, undi->pxenv.segment,
140 undi->pxenv.offset, undi->ppxe.segment, undi->ppxe.offset,
141 undi->entry.segment, undi->entry.offset );
142
143 return 0;
144
145 err_loader:
146 set_fbms ( undi->restore_fbms );
147 memset ( &undi_loader_entry, 0, sizeof ( undi_loader_entry ) );
148 err_multiple:
149 return rc;
150}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
unsigned short uint16_t
Definition stdint.h:11
void set_fbms(unsigned int new_fbms)
Set the BIOS free base memory counter.
Definition basemem.c:43
static unsigned int get_fbms(void)
Read the BIOS free base memory counter.
Definition basemem.h:21
uint8_t bus
Bus.
Definition edd.h:1
#define DBGC(...)
Definition compiler.h:505
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define EBUSY
Device or resource busy.
Definition errno.h:339
#define PXENV_EXIT_SUCCESS
No error occurred.
Definition pxe_types.h:45
void * memset(void *dest, int character, size_t len) __nonnull
#define REAL_CODE(asm_code_str)
Definition libkir.h:226
#define __from_data16(pointer)
Definition libkir.h:22
#define copy_from_real
Definition libkir.h:79
#define PCI_FUNC(busdevfn)
Definition pci.h:286
#define PCI_SLOT(busdevfn)
Definition pci.h:285
int find_pnp_bios(void)
Locate Plug-and-Play BIOS.
Definition pnpbios.c:101
#define BIOS_SEG
Definition pnpbios.h:13
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define ppxe
Definition pxe_call.h:28
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
The !PXE structure.
Definition pxe_api.h:129
UINT16_t pci_busdevfn
PCI bus:dev.fn, or UNDI_NO_PCI_BUSDEVFN.
Definition undi.h:34
UINT16_t isapnp_csn
ISAPnP card select number, or UNDI_NO_ISAPNP_CSN.
Definition undi.h:36
UINT16_t isapnp_read_port
ISAPnP read port, or UNDI_NO_ISAPNP_READ_PORT.
Definition undi.h:38
SEGOFF16_t ppxe
!PXE structure address
Definition undi.h:26
SEGOFF16_t pxenv
PXENV+ structure address.
Definition undi.h:24
UINT16_t restore_fbms
Free base memory prior to load.
Definition undi.h:32
UINT16_t fbms
Free base memory after load.
Definition undi.h:30
SEGOFF16_t entry
Entry point.
Definition undi.h:28
size_t data_size
Data segment size.
Definition undirom.h:39
size_t code_size
Code segment size.
Definition undirom.h:37
SEGOFF16_t loader_entry
UNDI loader entry point.
Definition undirom.h:35
#define UNDI_NO_PCI_BUSDEVFN
PCI bus:dev.fn field is invalid.
Definition undi.h:87
#define UNDI_NO_ISAPNP_CSN
ISAPnP card select number field is invalid.
Definition undi.h:90
#define undi_loader
Definition undiload.c:53
#define EUNDILOAD(status)
Definition undiload.c:49
#define undi_loader_entry
Definition undiload.c:57

References __asm__(), __from_data16, __volatile__(), BIOS_SEG, bus, undi_rom::code_size, copy_from_real, undi_rom::data_size, DBG, DBGC, EBUSY, undi_device::entry, 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, ppxe, 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().

◆ undi_unload()

int undi_unload ( struct undi_device * undi)
extern

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.

161 {
162 static uint32_t dead = 0xdeaddead;
163
164 DBGC ( undi, "UNDI %p unloading\n", undi );
165
166 /* Clear entry point */
167 memset ( &undi_loader_entry, 0, sizeof ( undi_loader_entry ) );
168
169 /* Erase signatures */
170 if ( undi->pxenv.segment )
171 put_real ( dead, undi->pxenv.segment, undi->pxenv.offset );
172 if ( undi->ppxe.segment )
173 put_real ( dead, undi->ppxe.segment, undi->ppxe.offset );
174
175 /* Free base memory, if possible */
176 if ( undi->fbms == get_fbms() ) {
177 DBGC ( undi, "UNDI %p freeing [%d,%d) kB of base memory\n",
178 undi, undi->fbms, undi->restore_fbms );
179 set_fbms ( undi->restore_fbms );
180 return 0;
181 } else {
182 DBGC ( undi, "UNDI %p leaking [%d,%d) kB of base memory\n",
183 undi, undi->fbms, undi->restore_fbms );
184 return -EBUSY;
185 }
186}
unsigned int uint32_t
Definition stdint.h:12
#define put_real
Definition libkir.h:150

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().

◆ undi_load_pci()

int undi_load_pci ( struct undi_device * undi,
struct undi_rom * undirom,
unsigned int pci_busdevfn )
inlinestatic

Call UNDI loader to create a pixie.

Parameters
undiUNDI device
undiromUNDI ROM
pci_busdevfnPCI bus:dev.fn
Return values
rcReturn status code

Definition at line 26 of file undiload.h.

28 {
29 undi->pci_busdevfn = pci_busdevfn;
32 return undi_load ( undi, undirom );
33}
#define UNDI_NO_ISAPNP_READ_PORT
ISAPnP read port field is invalid.
Definition undi.h:93
int undi_load(struct undi_device *undi, struct undi_rom *undirom)
Call UNDI loader to create a pixie.
Definition undiload.c:66

References undi_device::isapnp_csn, undi_device::isapnp_read_port, undi_device::pci_busdevfn, undi_load(), UNDI_NO_ISAPNP_CSN, and UNDI_NO_ISAPNP_READ_PORT.

Referenced by undipci_probe().