nubus: Adopt standard linked list implementation
This increases code re-use and improves readability. Cc: "David S. Miller" <davem@davemloft.net> Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Tested-by: Stan Johnson <userm57@yahoo.com> Signed-off-by: Finn Thain <fthain@telegraphics.com.au> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
This commit is contained in:
parent
189e19e8cb
commit
41b848160e
7 changed files with 40 additions and 60 deletions
|
@ -416,8 +416,11 @@ struct net_device * __init mac8390_probe(int unit)
|
||||||
if (unit >= 0)
|
if (unit >= 0)
|
||||||
sprintf(dev->name, "eth%d", unit);
|
sprintf(dev->name, "eth%d", unit);
|
||||||
|
|
||||||
while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET,
|
for_each_func_rsrc(ndev) {
|
||||||
ndev))) {
|
if (ndev->category != NUBUS_CAT_NETWORK ||
|
||||||
|
ndev->type != NUBUS_TYPE_ETHERNET)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Have we seen it already? */
|
/* Have we seen it already? */
|
||||||
if (slots & (1 << ndev->board->slot))
|
if (slots & (1 << ndev->board->slot))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -187,6 +187,7 @@ struct net_device * __init mac89x0_probe(int unit)
|
||||||
unsigned long ioaddr;
|
unsigned long ioaddr;
|
||||||
unsigned short sig;
|
unsigned short sig;
|
||||||
int err = -ENODEV;
|
int err = -ENODEV;
|
||||||
|
struct nubus_rsrc *fres;
|
||||||
|
|
||||||
if (!MACH_IS_MAC)
|
if (!MACH_IS_MAC)
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_PTR(-ENODEV);
|
||||||
|
@ -207,8 +208,9 @@ struct net_device * __init mac89x0_probe(int unit)
|
||||||
/* We might have to parameterize this later */
|
/* We might have to parameterize this later */
|
||||||
slot = 0xE;
|
slot = 0xE;
|
||||||
/* Get out now if there's a real NuBus card in slot E */
|
/* Get out now if there's a real NuBus card in slot E */
|
||||||
if (nubus_find_slot(slot, NULL) != NULL)
|
for_each_func_rsrc(fres)
|
||||||
goto out;
|
if (fres->board->slot == slot)
|
||||||
|
goto out;
|
||||||
|
|
||||||
/* The pseudo-ISA bits always live at offset 0x300 (gee,
|
/* The pseudo-ISA bits always live at offset 0x300 (gee,
|
||||||
wonder why...) */
|
wonder why...) */
|
||||||
|
|
|
@ -464,9 +464,11 @@ static int mac_nubus_sonic_probe(struct net_device *dev)
|
||||||
int reg_offset, dma_bitmode;
|
int reg_offset, dma_bitmode;
|
||||||
|
|
||||||
/* Find the first SONIC that hasn't been initialized already */
|
/* Find the first SONIC that hasn't been initialized already */
|
||||||
while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
|
for_each_func_rsrc(ndev) {
|
||||||
NUBUS_TYPE_ETHERNET, ndev)) != NULL)
|
if (ndev->category != NUBUS_CAT_NETWORK ||
|
||||||
{
|
ndev->type != NUBUS_TYPE_ETHERNET)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Have we seen it already? */
|
/* Have we seen it already? */
|
||||||
if (slots & (1<<ndev->board->slot))
|
if (slots & (1<<ndev->board->slot))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
/* Globals */
|
/* Globals */
|
||||||
|
|
||||||
struct nubus_rsrc *nubus_func_rsrcs;
|
LIST_HEAD(nubus_func_rsrcs);
|
||||||
struct nubus_board *nubus_boards;
|
struct nubus_board *nubus_boards;
|
||||||
|
|
||||||
/* Meaning of "bytelanes":
|
/* Meaning of "bytelanes":
|
||||||
|
@ -305,33 +305,20 @@ EXPORT_SYMBOL(nubus_rewinddir);
|
||||||
|
|
||||||
/* Driver interface functions, more or less like in pci.c */
|
/* Driver interface functions, more or less like in pci.c */
|
||||||
|
|
||||||
struct nubus_rsrc *nubus_find_type(unsigned short category, unsigned short type,
|
struct nubus_rsrc *nubus_first_rsrc_or_null(void)
|
||||||
const struct nubus_rsrc *from)
|
|
||||||
{
|
{
|
||||||
struct nubus_rsrc *itor = from ? from->next : nubus_func_rsrcs;
|
return list_first_entry_or_null(&nubus_func_rsrcs, struct nubus_rsrc,
|
||||||
|
list);
|
||||||
while (itor) {
|
|
||||||
if (itor->category == category && itor->type == type)
|
|
||||||
return itor;
|
|
||||||
itor = itor->next;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(nubus_find_type);
|
EXPORT_SYMBOL(nubus_first_rsrc_or_null);
|
||||||
|
|
||||||
struct nubus_rsrc *nubus_find_slot(unsigned int slot,
|
struct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from)
|
||||||
const struct nubus_rsrc *from)
|
|
||||||
{
|
{
|
||||||
struct nubus_rsrc *itor = from ? from->next : nubus_func_rsrcs;
|
if (list_is_last(&from->list, &nubus_func_rsrcs))
|
||||||
|
return NULL;
|
||||||
while (itor) {
|
return list_next_entry(from, list);
|
||||||
if (itor->board->slot == slot)
|
|
||||||
return itor;
|
|
||||||
itor = itor->next;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(nubus_find_slot);
|
EXPORT_SYMBOL(nubus_next_rsrc_or_null);
|
||||||
|
|
||||||
int
|
int
|
||||||
nubus_find_rsrc(struct nubus_dir *dir, unsigned char rsrc_type,
|
nubus_find_rsrc(struct nubus_dir *dir, unsigned char rsrc_type,
|
||||||
|
@ -819,7 +806,6 @@ static struct nubus_board * __init nubus_add_board(int slot, int bytelanes)
|
||||||
|
|
||||||
while (nubus_readdir(&dir, &ent) != -1) {
|
while (nubus_readdir(&dir, &ent) != -1) {
|
||||||
struct nubus_rsrc *fres;
|
struct nubus_rsrc *fres;
|
||||||
struct nubus_rsrc **fresp;
|
|
||||||
|
|
||||||
fres = nubus_get_functional_resource(board, slot, &ent);
|
fres = nubus_get_functional_resource(board, slot, &ent);
|
||||||
if (fres == NULL)
|
if (fres == NULL)
|
||||||
|
@ -834,16 +820,7 @@ static struct nubus_board * __init nubus_add_board(int slot, int bytelanes)
|
||||||
}
|
}
|
||||||
prev_resid = fres->resid;
|
prev_resid = fres->resid;
|
||||||
|
|
||||||
/* We zeroed this out above */
|
list_add_tail(&fres->list, &nubus_func_rsrcs);
|
||||||
if (board->first_func_rsrc == NULL)
|
|
||||||
board->first_func_rsrc = fres;
|
|
||||||
|
|
||||||
/* Put it on the func. resource list. Keep entries in order. */
|
|
||||||
for (fresp = &nubus_func_rsrcs; *fresp != NULL;
|
|
||||||
fresp = &((*fresp)->next))
|
|
||||||
/* spin */;
|
|
||||||
*fresp = fres;
|
|
||||||
fres->next = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Put it on the global NuBus board chain. Keep entries in order. */
|
/* Put it on the global NuBus board chain. Keep entries in order. */
|
||||||
|
|
|
@ -36,15 +36,12 @@
|
||||||
static int
|
static int
|
||||||
nubus_devices_proc_show(struct seq_file *m, void *v)
|
nubus_devices_proc_show(struct seq_file *m, void *v)
|
||||||
{
|
{
|
||||||
struct nubus_rsrc *fres = nubus_func_rsrcs;
|
struct nubus_rsrc *fres;
|
||||||
|
|
||||||
while (fres) {
|
for_each_func_rsrc(fres)
|
||||||
seq_printf(m, "%x\t%04x %04x %04x %04x",
|
seq_printf(m, "%x\t%04x %04x %04x %04x\t%08lx\n",
|
||||||
fres->board->slot, fres->category, fres->type,
|
fres->board->slot, fres->category, fres->type,
|
||||||
fres->dr_sw, fres->dr_hw);
|
fres->dr_sw, fres->dr_hw, fres->board->slot_addr);
|
||||||
seq_printf(m, "\t%08lx\n", fres->board->slot_addr);
|
|
||||||
fres = fres->next;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -670,15 +670,17 @@ static int __init macfb_init(void)
|
||||||
* code is really broken :-)
|
* code is really broken :-)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
while ((ndev = nubus_find_type(NUBUS_CAT_DISPLAY,
|
for_each_func_rsrc(ndev) {
|
||||||
NUBUS_TYPE_VIDEO, ndev)))
|
|
||||||
{
|
|
||||||
unsigned long base = ndev->board->slot_addr;
|
unsigned long base = ndev->board->slot_addr;
|
||||||
|
|
||||||
if (mac_bi_data.videoaddr < base ||
|
if (mac_bi_data.videoaddr < base ||
|
||||||
mac_bi_data.videoaddr - base > 0xFFFFFF)
|
mac_bi_data.videoaddr - base > 0xFFFFFF)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (ndev->category != NUBUS_CAT_DISPLAY ||
|
||||||
|
ndev->type != NUBUS_TYPE_VIDEO)
|
||||||
|
continue;
|
||||||
|
|
||||||
video_is_nubus = 1;
|
video_is_nubus = 1;
|
||||||
slot_addr = (unsigned char *)base;
|
slot_addr = (unsigned char *)base;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ struct nubus_dirent {
|
||||||
|
|
||||||
struct nubus_board {
|
struct nubus_board {
|
||||||
struct nubus_board *next;
|
struct nubus_board *next;
|
||||||
struct nubus_rsrc *first_func_rsrc;
|
|
||||||
|
|
||||||
/* Only 9-E actually exist, though 0-8 are also theoretically
|
/* Only 9-E actually exist, though 0-8 are also theoretically
|
||||||
possible, and 0 is a special case which represents the
|
possible, and 0 is a special case which represents the
|
||||||
|
@ -63,8 +62,7 @@ struct nubus_board {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nubus_rsrc {
|
struct nubus_rsrc {
|
||||||
/* Next link in list */
|
struct list_head list;
|
||||||
struct nubus_rsrc *next;
|
|
||||||
|
|
||||||
/* The functional resource ID */
|
/* The functional resource ID */
|
||||||
unsigned char resid;
|
unsigned char resid;
|
||||||
|
@ -82,7 +80,7 @@ struct nubus_rsrc {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This is all NuBus functional resources (used to find devices later on) */
|
/* This is all NuBus functional resources (used to find devices later on) */
|
||||||
extern struct nubus_rsrc *nubus_func_rsrcs;
|
extern struct list_head nubus_func_rsrcs;
|
||||||
/* This is all NuBus cards */
|
/* This is all NuBus cards */
|
||||||
extern struct nubus_board *nubus_boards;
|
extern struct nubus_board *nubus_boards;
|
||||||
|
|
||||||
|
@ -115,12 +113,11 @@ static inline void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
|
||||||
const struct nubus_dirent *ent) {}
|
const struct nubus_dirent *ent) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct nubus_rsrc *nubus_find_type(unsigned short category,
|
struct nubus_rsrc *nubus_first_rsrc_or_null(void);
|
||||||
unsigned short type,
|
struct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from);
|
||||||
const struct nubus_rsrc *from);
|
|
||||||
|
|
||||||
struct nubus_rsrc *nubus_find_slot(unsigned int slot,
|
#define for_each_func_rsrc(f) \
|
||||||
const struct nubus_rsrc *from);
|
for (f = nubus_first_rsrc_or_null(); f; f = nubus_next_rsrc_or_null(f))
|
||||||
|
|
||||||
/* These are somewhat more NuBus-specific. They all return 0 for
|
/* These are somewhat more NuBus-specific. They all return 0 for
|
||||||
success and -1 for failure, as you'd expect. */
|
success and -1 for failure, as you'd expect. */
|
||||||
|
|
Loading…
Reference in a new issue