Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.1
      1  1.1  tsubai #include <sys/types.h>
      2  1.1  tsubai #include <sys/param.h>
      3  1.1  tsubai #include <sys/systm.h>
      4  1.1  tsubai #include <sys/kernel.h>
      5  1.1  tsubai #include <sys/device.h>
      6  1.1  tsubai 
      7  1.1  tsubai #include <dev/pci/pcivar.h>
      8  1.1  tsubai #include <dev/pci/pcidevs.h>
      9  1.1  tsubai 
     10  1.1  tsubai #include <dev/ofw/openfirm.h>
     11  1.1  tsubai 
     12  1.1  tsubai #include <machine/autoconf.h>
     13  1.1  tsubai 
     14  1.1  tsubai static void obio_attach __P((struct device *, struct device *, void *));
     15  1.1  tsubai static int obio_match __P((struct device *, struct cfdata *, void *));
     16  1.1  tsubai static int obio_print __P((void *, const char *));
     17  1.1  tsubai 
     18  1.1  tsubai struct obio_softc {
     19  1.1  tsubai 	struct device sc_dev;
     20  1.1  tsubai 	int sc_node;
     21  1.1  tsubai };
     22  1.1  tsubai 
     23  1.1  tsubai 
     24  1.1  tsubai struct cfattach obio_ca = {
     25  1.1  tsubai 	sizeof(struct obio_softc), obio_match, obio_attach
     26  1.1  tsubai };
     27  1.1  tsubai 
     28  1.1  tsubai int
     29  1.1  tsubai obio_match(parent, cf, aux)
     30  1.1  tsubai 	struct device *parent;
     31  1.1  tsubai 	struct cfdata *cf;
     32  1.1  tsubai 	void *aux;
     33  1.1  tsubai {
     34  1.1  tsubai 	struct pci_attach_args *pa = aux;
     35  1.1  tsubai 
     36  1.1  tsubai 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
     37  1.1  tsubai 	    PCI_PRODUCT(pa->pa_id) == 2)
     38  1.1  tsubai 		return 1;
     39  1.1  tsubai 
     40  1.1  tsubai 	return 0;
     41  1.1  tsubai }
     42  1.1  tsubai 
     43  1.1  tsubai /*
     44  1.1  tsubai  * Attach all the sub-devices we can find
     45  1.1  tsubai  */
     46  1.1  tsubai void
     47  1.1  tsubai obio_attach(parent, self, aux)
     48  1.1  tsubai 	struct device *parent, *self;
     49  1.1  tsubai 	void *aux;
     50  1.1  tsubai {
     51  1.1  tsubai 	struct obio_softc *sc = (struct obio_softc *)self;
     52  1.1  tsubai 	struct confargs ca;
     53  1.1  tsubai 	int node, child, namelen;
     54  1.1  tsubai 	u_int reg[20];
     55  1.1  tsubai 	int intr[5];
     56  1.1  tsubai 	char name[32];
     57  1.1  tsubai 
     58  1.1  tsubai 	node = OF_finddevice("/bandit/gc");		/* XXX */
     59  1.1  tsubai 	sc->sc_node = node;
     60  1.1  tsubai 
     61  1.1  tsubai 	if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 12)
     62  1.1  tsubai 		return;
     63  1.1  tsubai 	ca.ca_baseaddr = reg[2];
     64  1.1  tsubai 
     65  1.1  tsubai 	printf(": addr 0x%x\n", ca.ca_baseaddr);
     66  1.1  tsubai 
     67  1.1  tsubai 	for (child = OF_child(node); child; child = OF_peer(child)) {
     68  1.1  tsubai 		namelen = OF_getprop(child, "name", name, sizeof(name));
     69  1.1  tsubai 		if (namelen < 0)
     70  1.1  tsubai 			continue;
     71  1.1  tsubai 		if (namelen >= sizeof(name))
     72  1.1  tsubai 			continue;
     73  1.1  tsubai 
     74  1.1  tsubai 		name[namelen] = 0;
     75  1.1  tsubai 		ca.ca_name = name;
     76  1.1  tsubai 		ca.ca_node = child;
     77  1.1  tsubai 
     78  1.1  tsubai 		ca.ca_nreg  = OF_getprop(child, "reg", reg, sizeof(reg));
     79  1.1  tsubai 		ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
     80  1.1  tsubai 				sizeof(intr));
     81  1.1  tsubai 		ca.ca_reg = reg;
     82  1.1  tsubai 		ca.ca_intr = intr;
     83  1.1  tsubai 
     84  1.1  tsubai 		config_found(self, &ca, obio_print);
     85  1.1  tsubai 	}
     86  1.1  tsubai }
     87  1.1  tsubai 
     88  1.1  tsubai int
     89  1.1  tsubai obio_print(aux, obio)
     90  1.1  tsubai 	void *aux;
     91  1.1  tsubai 	const char *obio;
     92  1.1  tsubai {
     93  1.1  tsubai 	struct confargs *ca = aux;
     94  1.1  tsubai 
     95  1.1  tsubai 	if (obio)
     96  1.1  tsubai 		printf("%s at %s", ca->ca_name, obio);
     97  1.1  tsubai 
     98  1.1  tsubai 	if (ca->ca_nreg > 0)
     99  1.1  tsubai 		printf(" offset 0x%x", ca->ca_reg[0]);
    100  1.1  tsubai 
    101  1.1  tsubai 	return UNCONF;
    102  1.1  tsubai }
    103