Skip to content

Commit

Permalink
Add "name" field to struct device to allow human-readable hardware de…
Browse files Browse the repository at this point in the history
…vice

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).
  • Loading branch information
Michael Brown committed Jan 10, 2007
1 parent cc9b32c commit dad5274
Show file tree
Hide file tree
Showing 51 changed files with 184 additions and 135 deletions.
3 changes: 3 additions & 0 deletions src/arch/i386/drivers/net/undi.c
Expand Up @@ -19,6 +19,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <vsprintf.h>
#include <gpxe/pci.h>
#include <undi.h>
#include <undirom.h>
Expand Down Expand Up @@ -96,6 +97,8 @@ static int undipci_probe ( struct pci_device *pci,
}

/* Add to device hierarchy */
snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
"UNDI%04x:%04x", undi->entry.segment, undi->entry.offset );
undi->dev.parent = &pci->dev;
INIT_LIST_HEAD ( &undi->dev.children );
list_add ( &undi->dev.siblings, &pci->dev.children );
Expand Down
1 change: 1 addition & 0 deletions src/arch/i386/drivers/net/undinet.c
Expand Up @@ -577,6 +577,7 @@ int undinet_probe ( struct undi_device *undi ) {
return -ENOMEM;
undinic = netdev->priv;
undi_set_drvdata ( undi, netdev );
netdev->dev = &undi->dev;
memset ( undinic, 0, sizeof ( *undinic ) );
undinic->entry = undi->entry;
DBGC ( undinic, "UNDINIC %p using UNDI %p\n", undinic, undi );
Expand Down
4 changes: 3 additions & 1 deletion src/arch/i386/drivers/net/undionly.c
Expand Up @@ -58,6 +58,8 @@ static int undibus_probe ( struct root_device *rootdev ) {
}

/* Add to device hierarchy */
strncpy ( preloaded_undi.dev.name, "UNDI",
( sizeof ( preloaded_undi.dev.name ) - 1 ) );
preloaded_undi.dev.parent = &rootdev->dev;
list_add ( &preloaded_undi.dev.siblings, &rootdev->dev.children);
INIT_LIST_HEAD ( &preloaded_undi.dev.children );
Expand Down Expand Up @@ -91,6 +93,6 @@ static struct root_driver undi_root_driver = {

/** UNDI bus root device */
struct root_device undi_root_device __root_device = {
.name = "UNDI",
.dev = { .name = "UNDI" },
.driver = &undi_root_driver,
};
6 changes: 4 additions & 2 deletions src/core/background.c
@@ -1,7 +1,9 @@
#include "background.h"

static struct background backgrounds[0] __table_start ( background );
static struct background backgrounds_end[0] __table_end ( background );
static struct background backgrounds[0]
__table_start ( struct background, background );
static struct background backgrounds_end[0]
__table_end ( struct background, background );

/** @file */

Expand Down
6 changes: 4 additions & 2 deletions src/core/console.c
Expand Up @@ -6,8 +6,10 @@

#include "bios.h"

static struct console_driver console_drivers[0] __table_start ( console );
static struct console_driver console_drivers_end[0] __table_end ( console );
static struct console_driver console_drivers[0]
__table_start ( struct console_driver, console );
static struct console_driver console_drivers_end[0]
__table_end ( struct console_driver, console );

/**
* Write a single character to each console device.
Expand Down
12 changes: 8 additions & 4 deletions src/core/dev.c
Expand Up @@ -10,10 +10,14 @@
*/

/* Linker symbols for the various tables */
static struct bus_driver bus_drivers[0] __table_start ( bus_driver );
static struct bus_driver bus_drivers_end[0] __table_end ( bus_driver );
static struct device_driver device_drivers[0] __table_start ( device_driver );
static struct device_driver device_drivers_end[0] __table_end (device_driver );
static struct bus_driver bus_drivers[0]
__table_start ( struct bus_driver, bus_driver );
static struct bus_driver bus_drivers_end[0]
__table_end ( struct bus_driver, bus_driver );
static struct device_driver device_drivers[0]
__table_start ( struct device_driver, device_driver );
static struct device_driver device_drivers_end[0]
__table_end ( struct device_driver, device_driver );

/* Current attempted boot device */
struct dev dev = {
Expand Down
12 changes: 7 additions & 5 deletions src/core/device.c
Expand Up @@ -28,8 +28,10 @@
*
*/

static struct root_device root_devices[0] __table_start ( root_devices );
static struct root_device root_devices_end[0] __table_end ( root_devices );
static struct root_device root_devices[0]
__table_start ( struct root_device, root_devices );
static struct root_device root_devices_end[0]
__table_end ( struct root_device, root_devices );

/** Registered root devices */
static LIST_HEAD ( devices );
Expand All @@ -43,10 +45,10 @@ static LIST_HEAD ( devices );
static int rootdev_probe ( struct root_device *rootdev ) {
int rc;

DBG ( "Adding %s root bus\n", rootdev->name );
DBG ( "Adding %s root bus\n", rootdev->dev.name );
if ( ( rc = rootdev->driver->probe ( rootdev ) ) != 0 ) {
DBG ( "Failed to add %s root bus: %s\n",
rootdev->name, strerror ( rc ) );
rootdev->dev.name, strerror ( rc ) );
return rc;
}

Expand All @@ -60,7 +62,7 @@ static int rootdev_probe ( struct root_device *rootdev ) {
*/
static void rootdev_remove ( struct root_device *rootdev ) {
rootdev->driver->remove ( rootdev );
DBG ( "Removed %s root bus\n", rootdev->name );
DBG ( "Removed %s root bus\n", rootdev->dev.name );
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/core/exec.c
Expand Up @@ -33,8 +33,10 @@
*
*/

static struct command commands[0] __table_start ( commands );
static struct command commands_end[0] __table_end ( commands );
static struct command commands[0]
__table_start ( struct command, commands );
static struct command commands_end[0]
__table_end ( struct command, commands );

/* Avoid dragging in getopt.o unless a command really uses it */
int optind;
Expand Down
6 changes: 4 additions & 2 deletions src/core/init.c
Expand Up @@ -9,8 +9,10 @@

#include <gpxe/init.h>

static struct init_fn init_fns[0] __table_start(init_fn);
static struct init_fn init_fns_end[0] __table_end(init_fn);
static struct init_fn init_fns[0]
__table_start ( struct init_fn, init_fn );
static struct init_fn init_fns_end[0]
__table_end ( struct init_fn, init_fn );

void call_init_fns ( void ) {
struct init_fn *init_fn;
Expand Down
6 changes: 4 additions & 2 deletions src/core/resolv.c
@@ -1,7 +1,9 @@
#include "resolv.h"

static struct resolver resolvers[0] __table_start(resolver);
static struct resolver resolvers_end[0] __table_end(resolver);
static struct resolver resolvers[0]
__table_start ( struct resolver, resolver );
static struct resolver resolvers_end[0]
__table_end ( struct resolver, resolver );

/*
* Resolve a name (which may be just a dotted quad IP address) to an
Expand Down
16 changes: 8 additions & 8 deletions src/core/settings.c
Expand Up @@ -34,16 +34,16 @@
*/

/** Registered configuration setting types */
static struct config_setting_type
config_setting_types[0] __table_start ( config_setting_types );
static struct config_setting_type
config_setting_types_end[0] __table_end ( config_setting_types );
static struct config_setting_type config_setting_types[0]
__table_start ( struct config_setting_type, config_setting_types );
static struct config_setting_type config_setting_types_end[0]
__table_end ( struct config_setting_type, config_setting_types );

/** Registered configuration settings */
static struct config_setting
config_settings[0] __table_start ( config_settings );
static struct config_setting
config_settings_end[0] __table_end ( config_settings );
static struct config_setting config_settings[0]
__table_start ( struct config_setting, config_settings );
static struct config_setting config_settings_end[0]
__table_end ( struct config_setting, config_settings );

/**
* Find configuration setting type
Expand Down
6 changes: 4 additions & 2 deletions src/drivers/bus/isa.c
Expand Up @@ -45,8 +45,10 @@ static isa_probe_addr_t isa_extra_probe_addrs[] = {
* Symbols defined by linker
*
*/
static struct isa_driver isa_drivers[0] __table_start ( isa_driver );
static struct isa_driver isa_drivers_end[0] __table_end ( isa_driver );
static struct isa_driver isa_drivers[0]
__table_start ( struct isa_driver, isa_driver );
static struct isa_driver isa_drivers_end[0]
__table_end ( struct isa_driver, isa_driver );

/*
* Increment a bus_loc structure to the next possible ISA location.
Expand Down
16 changes: 11 additions & 5 deletions src/drivers/bus/pci.c
Expand Up @@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <vsprintf.h>
#include <gpxe/tables.h>
#include <gpxe/device.h>
#include <gpxe/pci.h>
Expand All @@ -33,8 +34,10 @@
*
*/

static struct pci_driver pci_drivers[0] __table_start ( pci_drivers );
static struct pci_driver pci_drivers_end[0] __table_end ( pci_drivers );
static struct pci_driver pci_drivers[0]
__table_start ( struct pci_driver, pci_drivers );
static struct pci_driver pci_drivers_end[0]
__table_end ( struct pci_driver, pci_drivers );

static void pcibus_remove ( struct root_device *rootdev );

Expand Down Expand Up @@ -194,8 +197,8 @@ static int pci_probe ( struct pci_device *pci ) {
( id->device != pci->device ) )
continue;
pci->driver = driver;
pci->name = id->name;
DBG ( "...using driver %s\n", pci->name );
pci->driver_name = id->name;
DBG ( "...using driver %s\n", pci->driver_name );
if ( ( rc = driver->probe ( pci, id ) ) != 0 ) {
DBG ( "......probe failed\n" );
continue;
Expand Down Expand Up @@ -276,6 +279,9 @@ static int pcibus_probe ( struct root_device *rootdev ) {
pci_read_bases ( pci );

/* Add to device hierarchy */
snprintf ( pci->dev.name, sizeof ( pci->dev.name ),
"PCI%02x:%02x.%x", bus,
PCI_SLOT ( devfn ), PCI_FUNC ( devfn ) );
pci->dev.parent = &rootdev->dev;
list_add ( &pci->dev.siblings, &rootdev->dev.children);
INIT_LIST_HEAD ( &pci->dev.children );
Expand Down Expand Up @@ -325,6 +331,6 @@ static struct root_driver pci_root_driver = {

/** PCI bus root device */
struct root_device pci_root_device __root_device = {
.name = "PCI",
.dev = { .name = "PCI" },
.driver = &pci_root_driver,
};
4 changes: 2 additions & 2 deletions src/drivers/net/dmfe.c
Expand Up @@ -457,7 +457,7 @@ static int dmfe_probe ( struct nic *nic, struct pci_device *pci ) {

BASE = pci->ioaddr;
printf("dmfe.c: Found %s Vendor=0x%hX Device=0x%hX\n",
pci->name, pci->vendor, pci->device);
pci->driver_name, pci->vendor, pci->device);

/* Read Chip revision */
pci_read_config_dword(pci, PCI_REVISION_ID, &dev_rev);
Expand Down Expand Up @@ -488,7 +488,7 @@ static int dmfe_probe ( struct nic *nic, struct pci_device *pci ) {
nic->node_addr[i] = db->srom[20 + i];

/* Print out some hardware info */
DBG ( "%s: %s at ioaddr %4.4lx\n", pci->name, eth_ntoa ( nic->node_addr ), BASE );
DBG ( "%s: %s at ioaddr %4.4lx\n", pci->driver_name, eth_ntoa ( nic->node_addr ), BASE );

/* Set the card as PCI Bus Master */
adjust_pci_device(pci);
Expand Down
10 changes: 5 additions & 5 deletions src/drivers/net/forcedeth.c
Expand Up @@ -1246,7 +1246,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) {
return 0;

printf("forcedeth.c: Found %s, vendor=0x%hX, device=0x%hX\n",
pci->name, pci->vendor, pci->device);
pci->driver_name, pci->vendor, pci->device);

pci_fill_nic ( nic, pci );

Expand Down Expand Up @@ -1306,7 +1306,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) {
}
#endif

DBG ( "%s: MAC Address %s\n", pci->name, eth_ntoa ( nic->node_addr ) );
DBG ( "%s: MAC Address %s\n", pci->driver_name, eth_ntoa ( nic->node_addr ) );

/* disable WOL */
writel(0, base + NvRegWakeUpFlags);
Expand Down Expand Up @@ -1381,7 +1381,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) {
id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
dprintf
(("%s: open: Found PHY %hX:%hX at address %d.\n",
pci->name, id1, id2, i));
pci->driver_name, id1, id2, i));
np->phyaddr = i;
np->phy_oui = id1 | id2;
break;
Expand All @@ -1391,7 +1391,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) {
* test loopback? Very odd, but can be correct.
*/
printf
("%s: open: Could not find a valid PHY.\n", pci->name);
("%s: open: Could not find a valid PHY.\n", pci->driver_name);
}

if (i != 32) {
Expand All @@ -1400,7 +1400,7 @@ static int forcedeth_probe ( struct nic *nic, struct pci_device *pci ) {
}

dprintf(("%s: forcedeth.c: subsystem: %hX:%hX bound to %s\n",
pci->name, pci->vendor, pci->dev_id, pci->name));
pci->driver_name, pci->vendor, pci->dev_id, pci->driver_name));
if(!forcedeth_reset(nic)) return 0; // no valid link

/* point to NIC specific routines */
Expand Down
1 change: 1 addition & 0 deletions src/drivers/net/legacy.c
Expand Up @@ -84,6 +84,7 @@ int legacy_probe ( struct pci_device *pci,
netdev->priv = &nic;
memset ( &nic, 0, sizeof ( nic ) );
pci_set_drvdata ( pci, netdev );
netdev->dev = &pci->dev;

netdev->open = legacy_open;
netdev->close = legacy_close;
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/net/mtd80x.c
Expand Up @@ -677,7 +677,7 @@ static int mtd_probe ( struct nic *nic, struct pci_device *pci ) {
pci_fill_nic ( nic, pci );
adjust_pci_device(pci);

mtdx.nic_name = pci->name;
mtdx.nic_name = pci->driver_name;
mtdx.dev_id = pci->device;
mtdx.ioaddr = nic->ioaddr;

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/net/natsemi.c
Expand Up @@ -262,7 +262,7 @@ natsemi_probe ( struct nic *nic, struct pci_device *pci ) {
ioaddr = pci->ioaddr;
vendor = pci->vendor;
dev_id = pci->device;
nic_name = pci->name;
nic_name = pci->driver_name;

/* natsemi has a non-standard PM control register
* in PCI config space. Some boards apparently need
Expand Down
14 changes: 7 additions & 7 deletions src/drivers/net/ns83820.c
Expand Up @@ -821,7 +821,7 @@ static int ns83820_probe ( struct nic *nic, struct pci_device *pci ) {
return 0;

printf("ns83820.c: Found %s, vendor=0x%hX, device=0x%hX\n",
pci->name, pci->vendor, pci->device);
pci->driver_name, pci->vendor, pci->device);

/* point to private storage */
ns = &nsx;
Expand Down Expand Up @@ -860,12 +860,12 @@ static int ns83820_probe ( struct nic *nic, struct pci_device *pci ) {
ns->CFG_cache = readl(ns->base + CFG);

if ((ns->CFG_cache & CFG_PCI64_DET)) {
printf("%s: detected 64 bit PCI data bus.\n", pci->name);
printf("%s: detected 64 bit PCI data bus.\n", pci->driver_name);
/*dev->CFG_cache |= CFG_DATA64_EN; */
if (!(ns->CFG_cache & CFG_DATA64_EN))
printf
("%s: EEPROM did not enable 64 bit bus. Disabled.\n",
pci->name);
pci->driver_name);
} else
ns->CFG_cache &= ~(CFG_DATA64_EN);

Expand Down Expand Up @@ -895,7 +895,7 @@ static int ns83820_probe ( struct nic *nic, struct pci_device *pci ) {

/* setup optical transceiver if we have one */
if (ns->CFG_cache & CFG_TBI_EN) {
dprintf(("%s: enabling optical transceiver\n", pci->name));
dprintf(("%s: enabling optical transceiver\n", pci->driver_name));
writel(readl(ns->base + GPIOR) | 0x3e8, ns->base + GPIOR);

/* setup auto negotiation feature advertisement */
Expand All @@ -916,7 +916,7 @@ static int ns83820_probe ( struct nic *nic, struct pci_device *pci ) {

/* FIXME: reset_phy is defaulted to 0, should we reset anyway? */
if (reset_phy) {
dprintf(("%s: resetting phy\n", pci->name));
dprintf(("%s: resetting phy\n", pci->driver_name));
writel(ns->CFG_cache | CFG_PHY_RST, ns->base + CFG);
writel(ns->CFG_cache, ns->base + CFG);
}
Expand Down Expand Up @@ -981,11 +981,11 @@ static int ns83820_probe ( struct nic *nic, struct pci_device *pci ) {
ns83820_getmac(nic, nic->node_addr);

if (using_dac) {
dprintf(("%s: using 64 bit addressing.\n", pci->name));
dprintf(("%s: using 64 bit addressing.\n", pci->driver_name));
}

dprintf(("%s: DP83820 %d.%d: %! io=0x%hX\n",
pci->name,
pci->driver_name,
(unsigned) readl(ns->base + SRR) >> 8,
(unsigned) readl(ns->base + SRR) & 0xff,
nic->node_addr, pci->ioaddr));
Expand Down

0 comments on commit dad5274

Please sign in to comment.