iPXE
Functions
undirom.c File Reference

UNDI expansion ROMs. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <pxe.h>
#include <realmode.h>
#include <undirom.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
static LIST_HEAD (undiroms)
 List of all UNDI ROMs. More...
 
static int undirom_parse_pxeromid (struct undi_rom *undirom, unsigned int pxeromid)
 Parse PXE ROM ID structure. More...
 
static int undirom_parse_pcirheader (struct undi_rom *undirom, unsigned int pcirheader)
 Parse PCI expansion header. More...
 
static int undirom_probe (unsigned int rom_segment)
 Probe UNDI ROM. More...
 
static void undirom_probe_all_roms (void)
 Create UNDI ROMs for all possible expansion ROMs. More...
 
struct undi_romundirom_find_pci (unsigned int vendor_id, unsigned int device_id, unsigned int rombase)
 Find UNDI ROM for PCI device. More...
 

Detailed Description

UNDI expansion ROMs.

Definition in file undirom.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ LIST_HEAD()

static LIST_HEAD ( undiroms  )
static

List of all UNDI ROMs.

◆ undirom_parse_pxeromid()

static int undirom_parse_pxeromid ( struct undi_rom undirom,
unsigned int  pxeromid 
)
static

Parse PXE ROM ID structure.

Parameters
undiromUNDI ROM
pxeromidOffset within ROM to PXE ROM ID structure
Return values
rcReturn status code

Definition at line 45 of file undirom.c.

46  {
47  struct undi_rom_id undi_rom_id;
48  unsigned int undiloader;
49 
50  DBGC ( undirom, "UNDIROM %p has PXE ROM ID at %04x:%04x\n", undirom,
51  undirom->rom_segment, pxeromid );
52 
53  /* Read PXE ROM ID structure and verify */
54  copy_from_real ( &undi_rom_id, undirom->rom_segment, pxeromid,
55  sizeof ( undi_rom_id ) );
57  DBGC ( undirom, "UNDIROM %p has bad PXE ROM ID signature "
58  "%08x\n", undirom, undi_rom_id.Signature );
59  return -EINVAL;
60  }
61 
62  /* Check for UNDI loader */
63  undiloader = undi_rom_id.UNDILoader;
64  if ( ! undiloader ) {
65  DBGC ( undirom, "UNDIROM %p has no UNDI loader\n", undirom );
66  return -EINVAL;
67  }
68 
69  /* Fill in UNDI ROM loader fields */
70  undirom->loader_entry.segment = undirom->rom_segment;
71  undirom->loader_entry.offset = undiloader;
72  undirom->code_size = undi_rom_id.CodeSize;
73  undirom->data_size = undi_rom_id.DataSize;
74 
75  DBGC ( undirom, "UNDIROM %p has UNDI loader at %04x:%04x "
76  "(code %04zx data %04zx)\n", undirom,
77  undirom->loader_entry.segment, undirom->loader_entry.offset,
78  undirom->code_size, undirom->data_size );
79  return 0;
80 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
unsigned int rom_segment
ROM segment address.
Definition: undirom.h:33
size_t code_size
Code segment size.
Definition: undirom.h:37
UINT16_t DataSize
Minimum required data segment size.
Definition: pxe.h:165
size_t data_size
Data segment size.
Definition: undirom.h:39
#define DBGC(...)
Definition: compiler.h:505
UINT16_t UNDILoader
Offset to UNDI loader.
Definition: pxe.h:161
An UNDI ROM ID structure.
Definition: pxe.h:140
#define UNDI_ROM_ID_SIGNATURE
Signature for an UNDI ROM ID structure.
Definition: pxe.h:171
SEGOFF16_t loader_entry
UNDI loader entry point.
Definition: undirom.h:35
UINT16_t CodeSize
Minimum required code segment size.
Definition: pxe.h:167
UINT32_t Signature
Signature.
Definition: pxe.h:145
#define copy_from_real
Definition: libkir.h:79

References undi_rom::code_size, undi_rom_id::CodeSize, copy_from_real, undi_rom::data_size, undi_rom_id::DataSize, DBGC, EINVAL, undi_rom::loader_entry, undi_rom::rom_segment, undi_rom_id::Signature, UNDI_ROM_ID_SIGNATURE, and undi_rom_id::UNDILoader.

Referenced by undirom_probe().

◆ undirom_parse_pcirheader()

static int undirom_parse_pcirheader ( struct undi_rom undirom,
unsigned int  pcirheader 
)
static

Parse PCI expansion header.

Parameters
undiromUNDI ROM
pcirheaderOffset within ROM to PCI expansion header

Definition at line 88 of file undirom.c.

89  {
90  struct pcir_header pcir_header;
91 
92  DBGC ( undirom, "UNDIROM %p has PCI expansion header at %04x:%04x\n",
93  undirom, undirom->rom_segment, pcirheader );
94 
95  /* Read PCI expansion header and verify */
96  copy_from_real ( &pcir_header, undirom->rom_segment, pcirheader,
97  sizeof ( pcir_header ) );
99  DBGC ( undirom, "UNDIROM %p has bad PCI expansion header "
100  "signature %08x\n", undirom, pcir_header.signature );
101  return -EINVAL;
102  }
103 
104  /* Fill in UNDI ROM PCI device fields */
105  undirom->bus_type = PCI_NIC;
108 
109  DBGC ( undirom, "UNDIROM %p is for PCI devices %04x:%04x\n", undirom,
110  undirom->bus_id.pci.vendor_id, undirom->bus_id.pci.device_id );
111  return 0;
112 
113 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
unsigned int rom_segment
ROM segment address.
Definition: undirom.h:33
#define PCI_NIC
PCI network card.
Definition: pxe_api.h:1301
#define DBGC(...)
Definition: compiler.h:505
A PCI expansion header.
Definition: pxe.h:175
unsigned int bus_type
Bus type.
Definition: undirom.h:44
uint32_t signature
Signature.
Definition: pxe.h:180
unsigned int vendor_id
PCI vendor ID.
Definition: undirom.h:17
#define PCIR_SIGNATURE
Signature for an UNDI ROM ID structure.
Definition: pxe.h:188
union undi_device_id bus_id
Device ID.
Definition: undirom.h:46
uint16_t vendor_id
PCI vendor ID.
Definition: pxe.h:182
unsigned int device_id
PCI device ID.
Definition: undirom.h:19
#define copy_from_real
Definition: libkir.h:79
uint16_t device_id
PCI device ID.
Definition: pxe.h:184
struct undi_pci_device_id pci
PCI device ID.
Definition: undirom.h:25

References undi_rom::bus_id, undi_rom::bus_type, copy_from_real, DBGC, undi_pci_device_id::device_id, pcir_header::device_id, EINVAL, undi_device_id::pci, PCI_NIC, PCIR_SIGNATURE, undi_rom::rom_segment, pcir_header::signature, undi_pci_device_id::vendor_id, and pcir_header::vendor_id.

Referenced by undirom_probe().

◆ undirom_probe()

static int undirom_probe ( unsigned int  rom_segment)
static

Probe UNDI ROM.

Parameters
rom_segmentROM segment address
Return values
rcReturn status code

Definition at line 121 of file undirom.c.

121  {
122  struct undi_rom *undirom = NULL;
123  struct undi_rom_header romheader;
124  size_t rom_len;
125  unsigned int pxeromid;
126  unsigned int pcirheader;
127  int rc;
128 
129  /* Read expansion ROM header and verify */
130  copy_from_real ( &romheader, rom_segment, 0, sizeof ( romheader ) );
131  if ( romheader.Signature != ROM_SIGNATURE ) {
132  rc = -EINVAL;
133  goto err;
134  }
135  rom_len = ( romheader.ROMLength * 512 );
136 
137  /* Allocate memory for UNDI ROM */
138  undirom = zalloc ( sizeof ( *undirom ) );
139  if ( ! undirom ) {
140  DBG ( "Could not allocate UNDI ROM structure\n" );
141  rc = -ENOMEM;
142  goto err;
143  }
144  DBGC ( undirom, "UNDIROM %p trying expansion ROM at %04x:0000 "
145  "(%zdkB)\n", undirom, rom_segment, ( rom_len / 1024 ) );
146  undirom->rom_segment = rom_segment;
147 
148  /* Check for and parse PXE ROM ID */
149  pxeromid = romheader.PXEROMID;
150  if ( ! pxeromid ) {
151  DBGC ( undirom, "UNDIROM %p has no PXE ROM ID\n", undirom );
152  rc = -EINVAL;
153  goto err;
154  }
155  if ( pxeromid > rom_len ) {
156  DBGC ( undirom, "UNDIROM %p PXE ROM ID outside ROM\n",
157  undirom );
158  rc = -EINVAL;
159  goto err;
160  }
161  if ( ( rc = undirom_parse_pxeromid ( undirom, pxeromid ) ) != 0 )
162  goto err;
163 
164  /* Parse PCIR header, if present */
165  pcirheader = romheader.PCIRHeader;
166  if ( pcirheader )
167  undirom_parse_pcirheader ( undirom, pcirheader );
168 
169  /* Add to UNDI ROM list and return */
170  DBGC ( undirom, "UNDIROM %p registered\n", undirom );
171  list_add_tail ( &undirom->list, &undiroms );
172  return 0;
173 
174  err:
175  free ( undirom );
176  return rc;
177 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
unsigned int rom_segment
ROM segment address.
Definition: undirom.h:33
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An UNDI expansion ROM header.
Definition: pxe.h:120
static int undirom_parse_pxeromid(struct undi_rom *undirom, unsigned int pxeromid)
Parse PXE ROM ID structure.
Definition: undirom.c:45
#define DBGC(...)
Definition: compiler.h:505
An UNDI ROM.
Definition: undirom.h:29
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
#define ROM_SIGNATURE
Signature for an expansion ROM.
Definition: pxe.h:137
struct list_head list
List of UNDI ROMs.
Definition: undirom.h:31
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static int undirom_parse_pcirheader(struct undi_rom *undirom, unsigned int pcirheader)
Parse PCI expansion header.
Definition: undirom.c:88
#define copy_from_real
Definition: libkir.h:79
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References copy_from_real, DBG, DBGC, EINVAL, ENOMEM, free, undi_rom::list, list_add_tail, NULL, undi_rom_header::PCIRHeader, undi_rom_header::PXEROMID, rc, undi_rom::rom_segment, ROM_SIGNATURE, undi_rom_header::ROMLength, undi_rom_header::Signature, undirom_parse_pcirheader(), undirom_parse_pxeromid(), and zalloc().

Referenced by undirom_probe_all_roms().

◆ undirom_probe_all_roms()

static void undirom_probe_all_roms ( void  )
static

Create UNDI ROMs for all possible expansion ROMs.

Return values

Definition at line 184 of file undirom.c.

184  {
185  static int probed = 0;
186  unsigned int rom_segment;
187 
188  /* Perform probe only once */
189  if ( probed )
190  return;
191 
192  DBG ( "Scanning for PXE expansion ROMs\n" );
193 
194  /* Scan through expansion ROM region at 512 byte intervals */
195  for ( rom_segment = 0xc000 ; rom_segment < 0x10000 ;
196  rom_segment += 0x20 ) {
197  undirom_probe ( rom_segment );
198  }
199 
200  probed = 1;
201 }
static int undirom_probe(unsigned int rom_segment)
Probe UNDI ROM.
Definition: undirom.c:121
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References DBG, and undirom_probe().

Referenced by undirom_find_pci().

◆ undirom_find_pci()

struct undi_rom* undirom_find_pci ( unsigned int  vendor_id,
unsigned int  device_id,
unsigned int  rombase 
)

Find UNDI ROM for PCI device.

Parameters
vendor_idPCI vendor ID
device_idPCI device ID
rombaseROM base address, or 0 for any
Return values
undiromUNDI ROM, or NULL

Definition at line 211 of file undirom.c.

213  {
214  struct undi_rom *undirom;
215 
217 
218  list_for_each_entry ( undirom, &undiroms, list ) {
219  if ( undirom->bus_type != PCI_NIC )
220  continue;
221  if ( undirom->bus_id.pci.vendor_id != vendor_id )
222  continue;
223  if ( undirom->bus_id.pci.device_id != device_id )
224  continue;
225  if ( rombase && ( ( undirom->rom_segment << 4 ) != rombase ) )
226  continue;
227  DBGC ( undirom, "UNDIROM %p matched PCI %04x:%04x (%08x)\n",
228  undirom, vendor_id, device_id, rombase );
229  return undirom;
230  }
231 
232  DBG ( "No UNDI ROM matched PCI %04x:%04x (%08x)\n",
233  vendor_id, device_id, rombase );
234  return NULL;
235 }
unsigned int rom_segment
ROM segment address.
Definition: undirom.h:33
#define PCI_NIC
PCI network card.
Definition: pxe_api.h:1301
uint16_t device_id
Definition: ib_mad.h:19
#define DBGC(...)
Definition: compiler.h:505
An UNDI ROM.
Definition: undirom.h:29
unsigned int bus_type
Bus type.
Definition: undirom.h:44
uint8_t vendor_id[3]
Definition: ib_mad.h:22
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
unsigned int vendor_id
PCI vendor ID.
Definition: undirom.h:17
struct list_head list
List of UNDI ROMs.
Definition: undirom.h:31
union undi_device_id bus_id
Device ID.
Definition: undirom.h:46
unsigned int device_id
PCI device ID.
Definition: undirom.h:19
struct undi_pci_device_id pci
PCI device ID.
Definition: undirom.h:25
static void undirom_probe_all_roms(void)
Create UNDI ROMs for all possible expansion ROMs.
Definition: undirom.c:184
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References undi_rom::bus_id, undi_rom::bus_type, DBG, DBGC, undi_pci_device_id::device_id, device_id, undi_rom::list, list_for_each_entry, NULL, undi_device_id::pci, PCI_NIC, undi_rom::rom_segment, undirom_probe_all_roms(), undi_pci_device_id::vendor_id, and vendor_id.

Referenced by undipci_find_rom().