2005-03-08 18:53:11 +00:00
|
|
|
#ifndef DEV_H
|
|
|
|
#define DEV_H
|
|
|
|
|
2005-04-12 16:38:23 +00:00
|
|
|
#include "stdint.h"
|
2005-04-13 12:20:59 +00:00
|
|
|
|
|
|
|
/* Device types */
|
|
|
|
#include "nic.h"
|
|
|
|
|
2005-03-08 18:53:11 +00:00
|
|
|
/* Need to check the packing of this struct if Etherboot is ported */
|
2005-04-12 16:38:23 +00:00
|
|
|
struct dev_id {
|
|
|
|
uint16_t vendor_id;
|
|
|
|
uint16_t device_id;
|
|
|
|
uint8_t bus_type;
|
2005-03-08 18:53:11 +00:00
|
|
|
#define PCI_BUS_TYPE 1
|
|
|
|
#define ISA_BUS_TYPE 2
|
2005-04-14 10:10:54 +00:00
|
|
|
#define MCA_BUS_TYPE 3
|
2005-04-12 16:38:23 +00:00
|
|
|
} __attribute__ ((packed));
|
2005-03-08 18:53:11 +00:00
|
|
|
|
|
|
|
/* Dont use sizeof, that will include the padding */
|
|
|
|
#define DEV_ID_SIZE 8
|
|
|
|
|
2005-04-12 16:38:23 +00:00
|
|
|
struct dev {
|
2005-04-12 18:04:03 +00:00
|
|
|
struct dev_operations *dev_op;
|
2005-04-12 16:38:23 +00:00
|
|
|
const char *name;
|
|
|
|
struct dev_id devid; /* device ID string (sent to DHCP server) */
|
2005-04-14 13:33:03 +00:00
|
|
|
struct boot_driver *driver; /* driver being used for boot */
|
2005-04-14 10:10:54 +00:00
|
|
|
/* Pointer to bus information for device. Whatever sets up
|
|
|
|
* the struct dev must make sure that this points to a buffer
|
|
|
|
* large enough for the required struct <bus>_device.
|
|
|
|
*/
|
2005-04-14 13:33:03 +00:00
|
|
|
struct bus_device *bus;
|
2005-04-12 16:38:23 +00:00
|
|
|
/* All possible device types */
|
|
|
|
union {
|
|
|
|
struct nic nic;
|
|
|
|
};
|
2005-03-08 18:53:11 +00:00
|
|
|
};
|
|
|
|
|
2005-04-14 10:10:54 +00:00
|
|
|
/*
|
|
|
|
* Macro to help create a common symbol with enough space for any
|
|
|
|
* struct <bus>_device.
|
|
|
|
*
|
|
|
|
* Use as e.g. DEV_BUS(struct pci_device);
|
|
|
|
*/
|
|
|
|
#define DEV_BUS(datatype,symbol) datatype symbol __asm__ ( "_dev_bus" );
|
|
|
|
|
2005-04-12 16:38:23 +00:00
|
|
|
struct dev_operations {
|
|
|
|
void ( *disable ) ( struct dev * );
|
2005-04-12 22:43:25 +00:00
|
|
|
void ( *print_info ) ( struct dev * );
|
2005-04-12 16:38:23 +00:00
|
|
|
int ( *load_configuration ) ( struct dev * );
|
|
|
|
int ( *load ) ( struct dev * );
|
2005-03-08 18:53:11 +00:00
|
|
|
};
|
|
|
|
|
2005-04-14 13:33:03 +00:00
|
|
|
/*
|
|
|
|
* Table to describe a bootable device driver. See comments in dev.c
|
|
|
|
* for an explanation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct bus_device {};
|
|
|
|
struct bus_driver {};
|
2005-04-12 16:38:23 +00:00
|
|
|
struct boot_driver {
|
|
|
|
char *name;
|
2005-04-14 13:33:03 +00:00
|
|
|
struct bus_device * ( *find_bus_boot_device ) ( struct dev *dev,
|
|
|
|
struct bus_driver *driver );
|
|
|
|
struct bus_driver *bus_driver;
|
|
|
|
int ( *probe ) ( struct dev *dev, struct bus_device *bus_device );
|
2005-03-08 18:53:11 +00:00
|
|
|
};
|
|
|
|
|
2005-04-14 13:33:03 +00:00
|
|
|
#define BOOT_DRIVER( _name, _find_bus_boot_device, _bus_driver, _probe ) \
|
2005-04-14 12:02:19 +00:00
|
|
|
static struct boot_driver boot_driver_ ## probe_func \
|
2005-04-12 16:38:23 +00:00
|
|
|
__attribute__ ((used,__section__(".boot_drivers"))) = { \
|
2005-04-14 13:33:03 +00:00
|
|
|
.name = _name, \
|
|
|
|
.find_bus_boot_device = ( void * ) _find_bus_boot_device, \
|
|
|
|
.bus_driver = ( void * ) _bus_driver, \
|
|
|
|
.probe = ( void * ) _probe, \
|
2005-04-12 16:38:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Functions in dev.c */
|
|
|
|
extern void print_drivers ( void );
|
2005-04-14 13:33:03 +00:00
|
|
|
extern int find_boot_device ( struct dev *dev );
|
2005-04-12 16:38:23 +00:00
|
|
|
extern int probe ( struct dev *dev );
|
|
|
|
extern void disable ( struct dev *dev );
|
2005-04-12 22:43:25 +00:00
|
|
|
static inline void print_info ( struct dev *dev ) {
|
|
|
|
dev->dev_op->print_info ( dev );
|
|
|
|
}
|
2005-04-12 16:38:23 +00:00
|
|
|
static inline int load_configuration ( struct dev *dev ) {
|
|
|
|
return dev->dev_op->load_configuration ( dev );
|
|
|
|
}
|
|
|
|
static inline int load ( struct dev *dev ) {
|
|
|
|
return dev->dev_op->load ( dev );
|
|
|
|
}
|
2005-03-08 18:53:11 +00:00
|
|
|
|
|
|
|
#endif /* DEV_H */
|