[BACK]Return to uni_n.c CVS log [TXT][DIR] Up to [local] / sys / arch / macppc / dev

Annotation of sys/arch/macppc/dev/uni_n.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: uni_n.c,v 1.15 2006/06/19 22:41:35 miod Exp $ */
                      2:
                      3: /*
                      4:  * Copyright (c) 1998-2001 Dale Rahn.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     17:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     18:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     19:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     20:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     21:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     22:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     23:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     24:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     25:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     26:  */
                     27:
                     28: #include <sys/param.h>
                     29: #include <sys/device.h>
                     30: #include <sys/systm.h>
                     31:
                     32: #include <machine/bus.h>
                     33: #include <machine/autoconf.h>
                     34:
                     35: #include <dev/ofw/openfirm.h>
                     36:
                     37: struct memc_softc {
                     38:        struct device sc_dev;
                     39:        struct ppc_bus_space sc_membus_space;
                     40:
                     41: };
                     42:
                     43: int    memcmatch(struct device *, void *, void *);
                     44: void   memcattach(struct device *, struct device *, void *);
                     45: void   memc_attach_children(struct memc_softc *sc, int memc_node);
                     46: int    memc_print(void *aux, const char *name);
                     47:
                     48: /* Driver definition */
                     49: struct cfdriver memc_cd = {
                     50:        NULL, "memc", DV_DULL
                     51: };
                     52: /* Driver definition */
                     53: struct cfattach memc_ca = {
                     54:        sizeof(struct memc_softc), memcmatch, memcattach
                     55: };
                     56:
                     57: void uni_n_config(char *, int);
                     58:
                     59: int
                     60: memcmatch(struct device *parent, void *cf, void *aux)
                     61: {
                     62:        struct confargs *ca = aux;
                     63:        static int memc_attached = 0;
                     64:
                     65:        /* allow only one instance */
                     66:        if (memc_attached == 0) {
                     67:                if (0 == strcmp (ca->ca_name, "memc"))
                     68:                        return 1;
                     69:        }
                     70:        return 0;
                     71: }
                     72:
                     73: void
                     74: memcattach(struct device *parent, struct device *self, void *aux)
                     75: {
                     76:        struct confargs *ca = aux;
                     77:        int len;
                     78:        char name[64];
                     79:        struct memc_softc *sc = (struct memc_softc *)self;
                     80:
                     81:        len = OF_getprop(ca->ca_node, "name", name, sizeof name);
                     82:        if (len > 0)
                     83:                name[len] = 0;
                     84:
                     85:        uni_n_config(name, ca->ca_node);
                     86:
                     87:        printf (": %s\n", name);
                     88:
                     89:        memc_attach_children(sc, ca->ca_node);
                     90: }
                     91:
                     92: void
                     93: memc_attach_children(struct memc_softc *sc, int memc_node)
                     94: {
                     95:        struct confargs ca;
                     96:        int node, namelen;
                     97:        u_int32_t reg[20];
                     98:        char    name[32];
                     99:
                    100:         sc->sc_membus_space.bus_base = ca.ca_baseaddr;
                    101:
                    102:        ca.ca_iot = &sc->sc_membus_space;
                    103:        ca.ca_dmat = 0; /* XXX */
                    104:        ca.ca_baseaddr = 0; /* XXX */
                    105:        sc->sc_membus_space.bus_base = ca.ca_baseaddr;
                    106:
                    107:         for (node = OF_child(memc_node); node; node = OF_peer(node)) {
                    108:                namelen = OF_getprop(node, "name", name, sizeof(name));
                    109:                if (namelen < 0)
                    110:                        continue;
                    111:                if (namelen >= sizeof(name))
                    112:                        continue;
                    113:                name[namelen] = 0;
                    114:
                    115:                ca.ca_name = name;
                    116:                ca.ca_node = node;
                    117:                ca.ca_nreg  = OF_getprop(node, "reg", reg, sizeof(reg));
                    118:                ca.ca_reg = reg;
                    119:                ca.ca_nintr = 0; /* XXX */
                    120:                ca.ca_intr = NULL; /* XXX */
                    121:
                    122:                config_found((struct device *)sc, &ca, memc_print);
                    123:        }
                    124: }
                    125:
                    126: int
                    127: memc_print(void *aux, const char *name)
                    128: {
                    129:        struct confargs *ca = aux;
                    130:        /* we dont want extra stuff printing */
                    131:        if (name)
                    132:                printf("\"%s\" at %s", ca->ca_name, name);
                    133:        if (ca->ca_nreg > 0)
                    134:                printf(" offset 0x%x", ca->ca_reg[0]);
                    135:        return UNCONF;
                    136: }
                    137:
                    138: void
                    139: uni_n_config(char *name, int handle)
                    140: {
                    141:        char *baseaddr;
                    142:        int *ctladdr;
                    143:        u_int32_t address;
                    144:
                    145:        /* sanity test */
                    146:        if (strcmp (name, "uni-n") == 0 || strcmp (name, "u3") == 0
                    147:            || strcmp (name, "u4") == 0) {
                    148:                if (OF_getprop(handle, "reg", &address,
                    149:                    sizeof address) > 0) {
                    150:                        baseaddr = mapiodev(address, NBPG);
                    151:                        ctladdr = (void *)(baseaddr + 0x20);
                    152:                        *ctladdr |= 0x02;
                    153:                }
                    154:        }
                    155: }

CVSweb