From dad52745227fd06090e73ea535e0b0fe0f667c60 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 10 Jan 2007 04:22:09 +0000 Subject: Add "name" field to struct device to allow human-readable hardware device names. Add "dev" pointer in struct net_device to tie network interfaces back to a hardware device. Force natural alignment of data types in __table() macros. This seems to prevent gcc from taking the unilateral decision to occasionally increase their alignment (which screws up the table packing). --- src/include/gpxe/arp.h | 3 ++- src/include/gpxe/command.h | 2 +- src/include/gpxe/device.h | 6 +++--- src/include/gpxe/errortab.h | 2 +- src/include/gpxe/init.h | 2 +- src/include/gpxe/netdevice.h | 7 +++++-- src/include/gpxe/pci.h | 6 +++--- src/include/gpxe/settings.h | 5 +++-- src/include/gpxe/tables.h | 24 ++++++++++++------------ src/include/gpxe/tcpip.h | 6 ++++-- 10 files changed, 35 insertions(+), 28 deletions(-) (limited to 'src/include/gpxe') diff --git a/src/include/gpxe/arp.h b/src/include/gpxe/arp.h index 8ff1cff0..1c702b00 100644 --- a/src/include/gpxe/arp.h +++ b/src/include/gpxe/arp.h @@ -27,7 +27,8 @@ struct arp_net_protocol { }; /** Declare an ARP protocol */ -#define __arp_net_protocol __table ( arp_net_protocols, 01 ) +#define __arp_net_protocol \ + __table ( struct arp_net_protocol, arp_net_protocols, 01 ) extern int arp_resolve ( struct net_device *netdev, struct net_protocol *net_protocol, diff --git a/src/include/gpxe/command.h b/src/include/gpxe/command.h index 95f6c5ed..5d8057ab 100644 --- a/src/include/gpxe/command.h +++ b/src/include/gpxe/command.h @@ -17,6 +17,6 @@ struct command { int ( * exec ) ( int argc, char **argv ); }; -#define __command __table ( commands, 01 ) +#define __command __table ( struct command, commands, 01 ) #endif /* _GPXE_COMMAND_H */ diff --git a/src/include/gpxe/device.h b/src/include/gpxe/device.h index 43bbf604..9f670cfd 100644 --- a/src/include/gpxe/device.h +++ b/src/include/gpxe/device.h @@ -13,6 +13,8 @@ /** A hardware device */ struct device { + /** Name */ + char name[16]; /** Devices on the same bus */ struct list_head siblings; /** Devices attached to this device */ @@ -28,8 +30,6 @@ struct device { * */ struct root_device { - /** Name */ - const char *name; /** Device chain * * A root device has a NULL parent field. @@ -62,7 +62,7 @@ struct root_driver { }; /** Declare a root device */ -#define __root_device __table ( root_devices, 01 ) +#define __root_device __table ( struct root_device, root_devices, 01 ) extern int probe_devices ( void ); extern void remove_devices ( void ); diff --git a/src/include/gpxe/errortab.h b/src/include/gpxe/errortab.h index 1ca7fe55..470f7e79 100644 --- a/src/include/gpxe/errortab.h +++ b/src/include/gpxe/errortab.h @@ -15,6 +15,6 @@ struct errortab { const char *text; }; -#define __errortab __table ( errortab, 01 ) +#define __errortab __table ( struct errortab, errortab, 01 ) #endif /* _GPXE_ERRORTAB_H */ diff --git a/src/include/gpxe/init.h b/src/include/gpxe/init.h index 3881da45..0a2eb0bf 100644 --- a/src/include/gpxe/init.h +++ b/src/include/gpxe/init.h @@ -46,7 +46,7 @@ struct init_fn { /* Macro for creating an initialisation function table entry */ #define INIT_FN( init_order, init_func, reset_func, exit_func ) \ struct init_fn PREFIX_OBJECT(init_fn__) \ - __table ( init_fn, init_order ) = { \ + __table ( struct init_fn, init_fn, init_order ) = { \ .init = init_func, \ .reset = reset_func, \ .exit = exit_func, \ diff --git a/src/include/gpxe/netdevice.h b/src/include/gpxe/netdevice.h index e1dddd63..b029d16a 100644 --- a/src/include/gpxe/netdevice.h +++ b/src/include/gpxe/netdevice.h @@ -16,6 +16,7 @@ struct pk_buff; struct net_device; struct net_protocol; struct ll_protocol; +struct device; /** Maximum length of a link-layer address */ #define MAX_LL_ADDR_LEN 6 @@ -140,6 +141,8 @@ struct net_device { struct list_head list; /** Name of this network device */ char name[8]; + /** Underlying hardware device */ + struct device *dev; /** List of persistent reference holders */ struct list_head references; @@ -219,10 +222,10 @@ struct net_device { #define NETDEV_OPEN 0x0001 /** Declare a link-layer protocol */ -#define __ll_protocol __table ( ll_protocols, 01 ) +#define __ll_protocol __table ( struct ll_protocol, ll_protocols, 01 ) /** Declare a network-layer protocol */ -#define __net_protocol __table ( net_protocols, 01 ) +#define __net_protocol __table ( struct net_protocol, net_protocols, 01 ) extern struct list_head net_devices; diff --git a/src/include/gpxe/pci.h b/src/include/gpxe/pci.h index a27d6f1f..8269dfaa 100644 --- a/src/include/gpxe/pci.h +++ b/src/include/gpxe/pci.h @@ -277,8 +277,8 @@ struct pci_device { * field. */ void *priv; - /** Device name */ - const char *name; + /** Driver name */ + const char *driver_name; }; /** A PCI driver */ @@ -305,7 +305,7 @@ struct pci_driver { }; /** Declare a PCI driver */ -#define __pci_driver __table ( pci_drivers, 01 ) +#define __pci_driver __table ( struct pci_driver, pci_drivers, 01 ) #define PCI_DEVFN( slot, func ) ( ( (slot) << 3 ) | (func) ) #define PCI_SLOT( devfn ) ( ( (devfn) >> 3 ) & 0x1f ) diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h index d5be524d..f30bbfbc 100644 --- a/src/include/gpxe/settings.h +++ b/src/include/gpxe/settings.h @@ -66,7 +66,8 @@ struct config_setting_type { }; /** Declare a configuration setting type */ -#define __config_setting_type __table ( config_setting_types, 01 ) +#define __config_setting_type \ + __table ( struct config_setting_type, config_setting_types, 01 ) /** * A configuration setting @@ -98,7 +99,7 @@ struct config_setting { }; /** Declare a configuration setting */ -#define __config_setting __table ( config_settings, 01 ) +#define __config_setting __table ( struct config_setting, config_settings, 01 ) /** * Show value of setting diff --git a/src/include/gpxe/tables.h b/src/include/gpxe/tables.h index 385bb525..b2c56ab6 100644 --- a/src/include/gpxe/tables.h +++ b/src/include/gpxe/tables.h @@ -165,16 +165,17 @@ */ #ifdef DOXYGEN -#define __attribute__(x) +#define __attribute__( x ) #endif -#define __table_str(x) #x -#define __table_section(table,idx) \ - __section__ ( ".tbl." __table_str(table) "." __table_str(idx) ) +#define __table_str( x ) #x +#define __table_section( table, idx ) \ + __section__ ( ".tbl." __table_str ( table ) "." __table_str ( idx ) ) -#define __table_section_start(table) __table_section(table,00) -#define __table_section_end(table) __table_section(table,99) +#define __table_section_start( table ) __table_section ( table, 00 ) +#define __table_section_end( table ) __table_section ( table, 99 ) +#define __natural_alignment( type ) __aligned__ ( __alignof__ ( type ) ) /** * Linker table entry. @@ -191,8 +192,9 @@ * @endcode * */ -#define __table(table,idx) \ - __attribute__ (( __table_section(table,idx) )) +#define __table( type, table, idx ) \ + __attribute__ (( __table_section ( table, idx ), \ + __natural_alignment ( type ) )) /** * Linker table start marker. @@ -207,8 +209,7 @@ * @endcode * */ -#define __table_start(table) \ - __attribute__ (( __table_section_start(table) )) +#define __table_start( type, table ) __table ( type, table, 00 ) /** * Linker table end marker. @@ -223,7 +224,6 @@ * @endcode * */ -#define __table_end(table) \ - __attribute__ (( __table_section_end(table) )) +#define __table_end( type, table ) __table ( type, table, 99 ) #endif /* _GPXE_TABLES_H */ diff --git a/src/include/gpxe/tcpip.h b/src/include/gpxe/tcpip.h index 1fdb8b71..2508d5f5 100644 --- a/src/include/gpxe/tcpip.h +++ b/src/include/gpxe/tcpip.h @@ -99,10 +99,12 @@ struct tcpip_net_protocol { }; /** Declare a TCP/IP transport-layer protocol */ -#define __tcpip_protocol __table ( tcpip_protocols, 01 ) +#define __tcpip_protocol \ + __table ( struct tcpip_protocol, tcpip_protocols, 01 ) /** Declare a TCP/IP network-layer protocol */ -#define __tcpip_net_protocol __table ( tcpip_net_protocols, 01 ) +#define __tcpip_net_protocol \ + __table ( struct tcpip_net_protocol, tcpip_net_protocols, 01 ) extern int tcpip_rx ( struct pk_buff *pkb, uint8_t tcpip_proto, struct sockaddr_tcpip *st_src, -- cgit v1.2.3-55-g7522