mirror of https://github.com/ipxe/ipxe.git
New device probing mechanism
parent
707720c4e5
commit
17c1ca90e7
|
@ -0,0 +1,44 @@
|
||||||
|
#include "etherboot.h"
|
||||||
|
#include "stddef.h"
|
||||||
|
#include "dev.h"
|
||||||
|
|
||||||
|
/* Defined by linker */
|
||||||
|
extern struct boot_driver boot_drivers[];
|
||||||
|
extern struct boot_driver boot_drivers_end[];
|
||||||
|
|
||||||
|
/* Current attempted boot driver */
|
||||||
|
static struct boot_driver *boot_driver = boot_drivers;
|
||||||
|
|
||||||
|
/* Current boot device */
|
||||||
|
struct dev dev;
|
||||||
|
|
||||||
|
/* Print all drivers */
|
||||||
|
void print_drivers ( void ) {
|
||||||
|
struct boot_driver *driver;
|
||||||
|
|
||||||
|
for ( driver = boot_drivers ; driver < boot_drivers_end ; driver++ ) {
|
||||||
|
printf ( "%s ", driver->name );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the next available boot device */
|
||||||
|
int probe ( struct dev *dev ) {
|
||||||
|
|
||||||
|
for ( ; boot_driver < boot_drivers_end ; boot_driver++ ) {
|
||||||
|
dev->name = "unknown";
|
||||||
|
if ( boot_driver->probe ( dev ) )
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No more boot devices found */
|
||||||
|
boot_driver = boot_drivers;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disable a device */
|
||||||
|
void disable ( struct dev *dev ) {
|
||||||
|
if ( dev->dev_op ) {
|
||||||
|
dev->dev_op->disable ( dev );
|
||||||
|
dev->dev_op = NULL;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,126 +1,58 @@
|
||||||
#ifndef DEV_H
|
#ifndef DEV_H
|
||||||
#define DEV_H
|
#define DEV_H
|
||||||
|
|
||||||
#include "isa.h"
|
#include "stdint.h"
|
||||||
#include "pci.h"
|
#include "nic.h"
|
||||||
|
|
||||||
/* Need to check the packing of this struct if Etherboot is ported */
|
/* Need to check the packing of this struct if Etherboot is ported */
|
||||||
struct dev_id
|
struct dev_id {
|
||||||
{
|
uint16_t vendor_id;
|
||||||
unsigned short vendor_id;
|
uint16_t device_id;
|
||||||
unsigned short device_id;
|
uint8_t bus_type;
|
||||||
unsigned char bus_type;
|
|
||||||
#define PCI_BUS_TYPE 1
|
#define PCI_BUS_TYPE 1
|
||||||
#define ISA_BUS_TYPE 2
|
#define ISA_BUS_TYPE 2
|
||||||
};
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
/* Dont use sizeof, that will include the padding */
|
/* Dont use sizeof, that will include the padding */
|
||||||
#define DEV_ID_SIZE 8
|
#define DEV_ID_SIZE 8
|
||||||
|
|
||||||
|
struct dev {
|
||||||
struct pci_probe_state
|
const char *name;
|
||||||
{
|
|
||||||
#ifdef CONFIG_PCI
|
|
||||||
struct pci_device dev;
|
|
||||||
int advance;
|
|
||||||
#else
|
|
||||||
int dummy;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
struct isa_probe_state
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_ISA
|
|
||||||
const struct isa_driver *driver;
|
|
||||||
int advance;
|
|
||||||
#else
|
|
||||||
int dummy;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
union probe_state
|
|
||||||
{
|
|
||||||
struct pci_probe_state pci;
|
|
||||||
struct isa_probe_state isa;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dev
|
|
||||||
{
|
|
||||||
void (*disable)P((struct dev *));
|
|
||||||
struct dev_id devid; /* device ID string (sent to DHCP server) */
|
struct dev_id devid; /* device ID string (sent to DHCP server) */
|
||||||
int index; /* Index of next device on this controller to probe */
|
struct dev_operations *dev_op;
|
||||||
int type; /* Type of device I am probing for */
|
/* All possible device types */
|
||||||
int how_probe; /* First, next or awake */
|
union {
|
||||||
int to_probe; /* Flavor of device I am probing */
|
struct nic nic;
|
||||||
int failsafe; /* Failsafe probe requested */
|
};
|
||||||
int type_index; /* Index of this device (within type) */
|
|
||||||
#define PROBE_NONE 0
|
|
||||||
#define PROBE_PCI 1
|
|
||||||
#define PROBE_ISA 2
|
|
||||||
union probe_state state;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct dev_operations {
|
||||||
|
void ( *disable ) ( struct dev * );
|
||||||
|
int ( *load_configuration ) ( struct dev * );
|
||||||
|
int ( *load ) ( struct dev * );
|
||||||
|
};
|
||||||
|
|
||||||
#define NIC_DRIVER 0
|
struct boot_driver {
|
||||||
#define DISK_DRIVER 1
|
char *name;
|
||||||
#define FLOPPY_DRIVER 2
|
int (*probe) ( struct dev * );
|
||||||
|
};
|
||||||
|
|
||||||
#define BRIDGE_DRIVER 1000
|
#define BOOT_DRIVER( driver_name, probe_func ) \
|
||||||
|
static struct boot_driver boot_driver \
|
||||||
|
__attribute__ ((used,__section__(".boot_drivers"))) = { \
|
||||||
|
.name = driver_name, \
|
||||||
|
.probe = probe_func, \
|
||||||
|
};
|
||||||
|
|
||||||
#define PROBE_FIRST (-1)
|
/* Functions in dev.c */
|
||||||
#define PROBE_NEXT 0
|
extern void print_drivers ( void );
|
||||||
#define PROBE_AWAKE 1 /* After calling disable bring up the same device */
|
extern int probe ( struct dev *dev );
|
||||||
|
extern void disable ( struct dev *dev );
|
||||||
/* The probe result codes are selected
|
static inline int load_configuration ( struct dev *dev ) {
|
||||||
* to allow them to be fed back into the probe
|
return dev->dev_op->load_configuration ( dev );
|
||||||
* routine and get a successful probe.
|
}
|
||||||
*/
|
static inline int load ( struct dev *dev ) {
|
||||||
#define PROBE_FAILED PROBE_FIRST
|
return dev->dev_op->load ( dev );
|
||||||
#define PROBE_WORKED PROBE_NEXT
|
}
|
||||||
|
|
||||||
extern int probe(struct dev *dev);
|
|
||||||
extern void disable(struct dev *dev);
|
|
||||||
|
|
||||||
/* Boot option values
|
|
||||||
* option & BOOT_TYPE_MASK should equal a driver for probing
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define BOOT_NIC 0x0 /* Boot from a nic */
|
|
||||||
#define BOOT_DISK 0x1 /* Boot from disk */
|
|
||||||
#define BOOT_FLOPPY 0x2 /* Boot from a floppy */
|
|
||||||
|
|
||||||
#define BOOT_NOTHING 0x3 /* Last valid boot choice */
|
|
||||||
|
|
||||||
/* Do magic failsafe boot processing */
|
|
||||||
#define BOOT_FAILSAFE 0x8
|
|
||||||
|
|
||||||
#define BOOT_BITS 4
|
|
||||||
#define BOOT_MASK ((1 << (BOOT_BITS)) - 1)
|
|
||||||
#define BOOT_TYPE_MASK ((1 << (BOOT_BITS - 1)) - 1)
|
|
||||||
|
|
||||||
#define MAX_BOOT_ENTRIES 3
|
|
||||||
|
|
||||||
#define BOOT_ALL_VALUE (1<<BOOT_FIRST|1<<BOOT_SECOND|1<<BOOT_THIRD)
|
|
||||||
|
|
||||||
/* These could be customised for different languages perhaps */
|
|
||||||
#if BOOT_ALL_VALUE&(1<<BOOT_DISK)
|
|
||||||
#define BOOT_DISK_PROMPT "(D)isk "
|
|
||||||
#else
|
|
||||||
#define BOOT_DISK_PROMPT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BOOT_ALL_VALUE&(1<<BOOT_FLOPPY)
|
|
||||||
#define BOOT_FLOPPY_PROMPT "(F)loppy "
|
|
||||||
#else
|
|
||||||
#define BOOT_FLOPPY_PROMPT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ASK_PROMPT \
|
|
||||||
"Boot from (N)etwork " BOOT_DISK_PROMPT BOOT_FLOPPY_PROMPT "or (Q)uit? "
|
|
||||||
|
|
||||||
#define ANS_NETWORK 'N'
|
|
||||||
#define ANS_DISK 'D'
|
|
||||||
#define ANS_FLOPPY 'F'
|
|
||||||
#define ANS_QUIT 'Q'
|
|
||||||
#define ANS_DEFAULT '\n'
|
|
||||||
|
|
||||||
#endif /* DEV_H */
|
#endif /* DEV_H */
|
||||||
|
|
Loading…
Reference in New Issue