implement device_register() for ofppc.

use ofcons_cnprobe().
This commit is contained in:
chs 2002-09-18 01:44:12 +00:00
parent 976b0910c4
commit b5e02d5677
8 changed files with 186 additions and 72 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: firepower.c,v 1.3 2002/07/05 18:45:18 matt Exp $ */
/* $NetBSD: firepower.c,v 1.4 2002/09/18 01:44:12 chs Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@ -49,7 +49,14 @@
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
#include <dev/scsipi/scsi_all.h>
#include <dev/scsipi/scsipi_all.h>
#include <dev/scsipi/scsiconf.h>
#include <dev/ata/atavar.h>
#include <dev/ata/wdvar.h>
#include <dev/ic/wdcvar.h>
#include <machine/autoconf.h>
#include <machine/bat.h>
#include <machine/intr.h>
#include <machine/platform.h>
@ -63,6 +70,9 @@ void firepower_init(void);
void firepower_cons_init(void);
void firepower_device_register(struct device *, void *);
extern char bootpath[];
extern char cbootpath[];
/*
* firepower_init:
*
@ -74,6 +84,7 @@ firepower_init(void)
platform.cons_init = firepower_cons_init;
platform.device_register = firepower_device_register;
platform.softintr_init = firepower_softintr_init;
/*
* Map VA==PA the region that includes ISA I/O, PCI Config,
@ -108,6 +119,11 @@ firepower_cons_init(void)
{
}
#define DEVICE_IS(dev, name) \
(!strncmp((dev)->dv_xname, (name), sizeof(name) - 1) && \
(dev)->dv_xname[sizeof(name) - 1] >= '0' && \
(dev)->dv_xname[sizeof(name) - 1] <= '9')
/*
* firepower_device_register:
*
@ -117,6 +133,93 @@ firepower_cons_init(void)
void
firepower_device_register(struct device *dev, void *aux)
{
static struct device *parent;
static char *bp = bootpath + 1, *cp = cbootpath + 1;
unsigned long addr;
char *pnext, *paddr;
int clen;
if (booted_device)
return;
/* Skip over devices not represented in the OF tree. */
if (DEVICE_IS(dev, "mainbus")) {
parent = dev;
return;
}
if (DEVICE_IS(dev, "atapibus") || DEVICE_IS(dev, "scsibus"))
return;
if (DEVICE_IS(dev->dv_parent, "atapibus") ||
DEVICE_IS(dev->dv_parent, "scsibus")) {
if (dev->dv_parent->dv_parent != parent)
return;
} else if (dev->dv_parent != parent) {
return;
}
/*
* Get the address part of the current path component.
*/
pnext = strchr(cp, '/');
if (pnext) {
clen = pnext - cp;
pnext++;
} else {
clen = strlen(cp);
}
addr = 0;
paddr = strchr(cp, '@');
if (pnext && paddr > pnext) {
paddr = NULL;
} else if (!paddr && bp) {
paddr = strchr(bp, '@');
}
if (paddr) {
addr = strtoul(paddr + 1, NULL, 0x10);
}
if (DEVICE_IS(dev->dv_parent, "mainbus")) {
struct ofbus_attach_args *oba = aux;
if (strcmp(oba->oba_busname, "cpu") == 0)
return;
} else if (DEVICE_IS(dev->dv_parent, "ofbus")) {
struct ofbus_attach_args *oba = aux;
if (strncmp(oba->oba_ofname, cp, clen))
return;
} else if (DEVICE_IS(dev->dv_parent, "pci")) {
struct pci_attach_args *pa = aux;
if (addr != pa->pa_device)
return;
} else if (DEVICE_IS(dev->dv_parent, "scsibus") ||
DEVICE_IS(dev->dv_parent, "atapibus")) {
struct scsipibus_attach_args *sa = aux;
/* periph_target is target for scsi, drive # for atapi */
if (addr != sa->sa_periph->periph_target)
return;
} else
return;
/*
* If we reach this point, then dev is a match for the current
* path component.
*/
if (pnext && *pnext) {
parent = dev;
cp = pnext;
bp = strchr(bp, '/');
if (bp)
bp++;
return;
} else {
booted_device = dev;
return;
}
}
/*

View File

@ -1,20 +1,29 @@
#ifndef _MACHINE_AUTOCONF_H_
#define _MACHINE_AUTOCONF_H_
/* $NetBSD: autoconf.h,v 1.5 2002/09/18 01:44:13 chs Exp $ */
#ifndef _OFPPC_AUTOCONF_H_
#define _OFPPC_AUTOCONF_H_
struct confargs {
const char *ca_name;
u_int ca_node;
int ca_nreg;
u_int *ca_reg;
int ca_nintr;
int *ca_intr;
u_int ca_baseaddr;
/* bus_space_tag_t ca_tag; */
};
#ifdef _KERNEL
void initppc (u_int, u_int, char *);
void strayintr (int);
void inittodr (time_t);
void resettodr (void);
void cpu_initclocks (void);
void decr_intr (struct clockframe *);
void setstatclockrate (int);
#ifdef __BROKEN_DK_ESTABLISH
void dk_cleanup(void);
#endif
void initppc(u_int, u_int, char *);
void strayintr(int);
void inittodr(time_t);
void resettodr(void);
void cpu_initclocks(void);
void decr_intr(struct clockframe *);
void setstatclockrate(int);
#endif /* _KERNEL */
#endif /* _MACHINE_AUTOCONF_H_ */
#endif /* _OFPPC_AUTOCONF_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.h,v 1.18 2001/10/22 23:01:18 thorpej Exp $ */
/* $NetBSD: cpu.h,v 1.19 2002/09/18 01:44:13 chs Exp $ */
/*
* Copyright (C) 1995-1997 Wolfgang Solfrank.
@ -42,7 +42,6 @@ struct cpu_softc {
#if defined(_KERNEL)
#define CPU_MAXNUM 1
extern char *bootpath;
extern struct cfdriver cpu_cd;
#endif

View File

@ -1,5 +1,5 @@
/* $NetBSD: types.h,v 1.3 2000/05/16 05:45:49 thorpej Exp $ */
/* $NetBSD: types.h,v 1.4 2002/09/18 01:44:13 chs Exp $ */
#include <powerpc/types.h>
#define __BROKEN_DK_ESTABLISH
#define __HAVE_DEVICE_REGISTER

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.77 2002/07/09 19:21:05 matt Exp $ */
/* $NetBSD: machdep.c,v 1.78 2002/09/18 01:44:13 chs Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@ -73,7 +73,7 @@
/*
* Global variables used here and there
*/
char *bootpath;
char bootpath[256];
int lcsplx(int); /* called from locore.S */
@ -136,7 +136,7 @@ initppc(startkernel, endkernel, args)
/*
* Parse arg string.
*/
bootpath = args;
strcpy(bootpath, args);
while (*++args && *args != ' ');
if (*args) {
for(*args++ = 0; *args; args++)
@ -174,30 +174,30 @@ initppc(startkernel, endkernel, args)
void
cpu_startup()
{
int msr;
mpc6xx_startup(NULL);
/*
* Now allow hardware interrupts.
*/
splhigh();
asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
: "=r"(msr)
: "K"((u_short)(PSL_EE|PSL_RI)));
mtmsr(mfmsr() | PSL_EE | PSL_RI);
(*platform.softintr_init)();
}
void
consinit()
{
/* Nothing to do; console is already initialized. */
(*cn_tab->cn_probe)(cn_tab);
}
void ofcons_cnprobe(struct consdev *);
int ofppc_cngetc(dev_t);
void ofppc_cnputc(dev_t, int);
struct consdev ofppc_bootcons = {
NULL, NULL, ofppc_cngetc, ofppc_cnputc, nullcnpollc, NULL,
ofcons_cnprobe, NULL, ofppc_cngetc, ofppc_cnputc, nullcnpollc, NULL,
makedev(0,0), 1,
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: mainbus.c,v 1.7 2001/10/23 22:52:14 thorpej Exp $ */
/* $NetBSD: mainbus.c,v 1.8 2002/09/18 01:44:13 chs Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@ -108,40 +108,35 @@ mainbus_attach(struct device *parent, struct device *self, void *aux)
* see CPUs after other devices in the boot messages.
*/
node = OF_finddevice("/cpus");
if (node != -1) {
for (node = OF_child(node); node != 0; node = OF_peer(node)) {
oba.oba_busname = "cpu";
oba.oba_phandle = node;
(void) config_found(self, &oba, mainbus_print);
}
} else {
if (node == -1) {
/*
* No /cpus node; assume they're all children of the
* root OFW node.
*/
for (node = OF_child(OF_peer(0)); node != 0;
node = OF_peer(node)) {
if (OF_getprop(node, "device_type",
buf, sizeof(buf)) <= 0)
continue;
if (strcmp(buf, "cpu") != 0)
continue;
oba.oba_busname = "cpu";
oba.oba_phandle = node;
(void) config_found(self, &oba, mainbus_print);
}
node = OF_peer(0);
}
for (node = OF_child(node); node != 0; node = OF_peer(node)) {
if (OF_getprop(node, "device_type", buf, sizeof(buf)) <= 0)
continue;
if (strcmp(buf, "cpu") != 0)
continue;
oba.oba_busname = "cpu";
of_packagename(node, oba.oba_ofname, sizeof oba.oba_ofname);
oba.oba_phandle = node;
(void) config_found(self, &oba, mainbus_print);
}
/*
* Now attach the rest of the devices on the system.
*/
for (node = OF_child(OF_peer(0)); node != 0; node = OF_peer(node)) {
/*
* Make sure it's not a CPU (we've already attached
* those).
* Make sure it's not a CPU (we've already attached those).
*/
if (OF_getprop(node, "device_type",
buf, sizeof(buf)) > 0 &&
if (OF_getprop(node, "device_type", buf, sizeof(buf)) > 0 &&
strcmp(buf, "cpu") == 0)
continue;
@ -157,6 +152,7 @@ mainbus_attach(struct device *parent, struct device *self, void *aux)
continue;
oba.oba_busname = "ofw";
of_packagename(node, oba.oba_ofname, sizeof oba.oba_ofname);
oba.oba_phandle = node;
(void) config_found(self, &oba, mainbus_print);
}
@ -166,12 +162,10 @@ int
mainbus_print(void *aux, const char *pnp)
{
struct ofbus_attach_args *oba = aux;
char name[64];
if (pnp) {
OF_getprop(oba->oba_phandle, "name", name, sizeof(name));
printf("%s at %s", name, pnp);
}
if (pnp)
printf("%s at %s", oba->oba_ofname, pnp);
else
printf(" (%s)", oba->oba_ofname);
return (UNCONF);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ofbus.c,v 1.12 2001/11/13 07:26:28 lukem Exp $ */
/* $NetBSD: ofbus.c,v 1.13 2002/09/18 01:44:13 chs Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ofbus.c,v 1.12 2001/11/13 07:26:28 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: ofbus.c,v 1.13 2002/09/18 01:44:13 chs Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -54,13 +54,11 @@ ofbus_print(aux, pnp)
const char *pnp;
{
struct ofbus_attach_args *oba = aux;
char name[64];
(void)of_packagename(oba->oba_phandle, name, sizeof name);
if (pnp)
printf("%s at %s", name, pnp);
printf("%s at %s", oba->oba_ofname, pnp);
else
printf(" (%s)", name);
printf(" (%s)", oba->oba_ofname);
return UNCONF;
}
@ -84,11 +82,10 @@ ofbus_attach(parent, dev, aux)
struct device *parent, *dev;
void *aux;
{
int child;
char name[5];
struct ofbus_attach_args *oba = aux;
struct ofbus_attach_args oba2;
int units;
char name[64];
int child, units;
printf("\n");
@ -98,6 +95,7 @@ ofbus_attach(parent, dev, aux)
* DEVICES ON THESE BUSSES.
*/
units = 1;
name[0] = 0;
if (OF_getprop(oba->oba_phandle, "name", name, sizeof name) > 0) {
if (!strcmp(name, "scsi"))
units = 7; /* What about wide or hostid != 7? XXX */
@ -108,8 +106,17 @@ ofbus_attach(parent, dev, aux)
for (child = OF_child(oba->oba_phandle); child != 0;
child = OF_peer(child)) {
oba2.oba_busname = "ofw";
of_packagename(child, name, sizeof name);
oba2.oba_phandle = child;
for (oba2.oba_unit = 0; oba2.oba_unit < units; oba2.oba_unit++)
for (oba2.oba_unit = 0; oba2.oba_unit < units;
oba2.oba_unit++) {
if (units > 1) {
sprintf(oba2.oba_ofname, "%s@%d", name,
oba2.oba_unit);
} else {
strcpy(oba2.oba_ofname, name);
}
config_found(dev, &oba2, ofbus_print);
}
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: openfirm.h,v 1.17 2001/06/19 08:24:07 simonb Exp $ */
/* $NetBSD: openfirm.h,v 1.18 2002/09/18 01:44:13 chs Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@ -48,8 +48,10 @@
* in order to support generic OpenFirmware device drivers.
*/
struct ofbus_attach_args {
char *oba_busname;
int oba_phandle;
const char *oba_busname;
char oba_ofname[64];
int oba_phandle;
/*
* Special unit field for disk devices.
* This is a KLUDGE to work around the fact that OpenFirmware
@ -57,7 +59,7 @@ struct ofbus_attach_args {
* YES, I THINK THIS IS A BUG IN THE OPENFIRMWARE DEFINITION!!! XXX
* See also ofdisk.c.
*/
int oba_unit;
int oba_unit;
};
/*