[BACK]Return to bha_eisa.c CVS log [TXT][DIR] Up to [local] / sys / dev / eisa

Annotation of sys/dev/eisa/bha_eisa.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: bha_eisa.c,v 1.4 2007/04/10 17:47:55 miod Exp $       */
                      2: /*     $NetBSD: bha_eisa.c,v 1.16 1998/08/15 10:10:49 mycroft Exp $    */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1998 The NetBSD Foundation, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to The NetBSD Foundation
                      9:  * by Charles M. Hannum.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *        This product includes software developed by the NetBSD
                     22:  *        Foundation, Inc. and its contributors.
                     23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     24:  *    contributors may be used to endorse or promote products derived
                     25:  *    from this software without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     37:  * POSSIBILITY OF SUCH DAMAGE.
                     38:  */
                     39:
                     40: #include <sys/types.h>
                     41: #include <sys/param.h>
                     42: #include <sys/systm.h>
                     43: #include <sys/device.h>
                     44:
                     45: #include <machine/bus.h>
                     46: #include <machine/intr.h>
                     47:
                     48: #include <scsi/scsi_all.h>
                     49: #include <scsi/scsiconf.h>
                     50:
                     51: #include <dev/eisa/eisavar.h>
                     52: #include <dev/eisa/eisadevs.h>
                     53:
                     54: #include <dev/ic/bhareg.h>
                     55: #include <dev/ic/bhavar.h>
                     56:
                     57: #define BHA_EISA_SLOT_OFFSET   0x0c80
                     58: #define        BHA_EISA_IOSIZE         0x0010
                     59: #define        BHA_ISA_IOSIZE          0x0004
                     60:
                     61: #define        BHA_EISA_IOCONF         0x0c
                     62:
                     63: int    bha_eisa_address(bus_space_tag_t, bus_space_handle_t, int *);
                     64: int    bha_eisa_match(struct device *, void *, void *);
                     65: void   bha_eisa_attach(struct device *, struct device *, void *);
                     66:
                     67: struct cfattach bha_eisa_ca = {
                     68:        sizeof(struct bha_softc), bha_eisa_match, bha_eisa_attach
                     69: };
                     70:
                     71: int
                     72: bha_eisa_address(iot, ioh, portp)
                     73:        bus_space_tag_t iot;
                     74:        bus_space_handle_t ioh;
                     75:        int *portp;
                     76: {
                     77:        int port;
                     78:
                     79:        switch (bus_space_read_1(iot, ioh, BHA_EISA_IOCONF) & 0x07) {
                     80:        case 0x00:
                     81:                port = 0x330;
                     82:                break;
                     83:        case 0x01:
                     84:                port = 0x334;
                     85:                break;
                     86:        case 0x02:
                     87:                port = 0x230;
                     88:                break;
                     89:        case 0x03:
                     90:                port = 0x234;
                     91:                break;
                     92:        case 0x04:
                     93:                port = 0x130;
                     94:                break;
                     95:        case 0x05:
                     96:                port = 0x134;
                     97:                break;
                     98:        default:
                     99:                return (1);
                    100:        }
                    101:
                    102:        *portp = port;
                    103:        return (0);
                    104: }
                    105:
                    106: /*
                    107:  * Check the slots looking for a board we recognise
                    108:  * If we find one, note its address (slot) and call
                    109:  * the actual probe routine to check it out.
                    110:  */
                    111: int
                    112: bha_eisa_match(parent, match, aux)
                    113:        struct device *parent;
                    114:        void *aux, *match;
                    115: {
                    116:        struct eisa_attach_args *ea = aux;
                    117:        bus_space_tag_t iot = ea->ea_iot;
                    118:        bus_space_handle_t ioh, ioh2;
                    119:        int port;
                    120:        int rv;
                    121:
                    122:        /* must match one of our known ID strings */
                    123:        if (strcmp(ea->ea_idstring, "BUS4201") &&
                    124:            strcmp(ea->ea_idstring, "BUS4202"))
                    125:                return (0);
                    126:
                    127:        if (bus_space_map(iot,
                    128:            EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET, BHA_EISA_IOSIZE,
                    129:            0, &ioh))
                    130:                return (0);
                    131:
                    132:        if (bha_eisa_address(iot, ioh, &port) ||
                    133:            bus_space_map(iot, port, BHA_ISA_IOSIZE, 0, &ioh2)) {
                    134:                bus_space_unmap(iot, ioh, BHA_EISA_IOSIZE);
                    135:                return (0);
                    136:        }
                    137:
                    138:        rv = bha_find(iot, ioh2, NULL);
                    139:
                    140:        bus_space_unmap(iot, ioh2, BHA_ISA_IOSIZE);
                    141:        bus_space_unmap(iot, ioh, BHA_EISA_IOSIZE);
                    142:
                    143:        return (rv);
                    144: }
                    145:
                    146: /*
                    147:  * Attach all the sub-devices we can find
                    148:  */
                    149: void
                    150: bha_eisa_attach(parent, self, aux)
                    151:        struct device *parent, *self;
                    152:        void *aux;
                    153: {
                    154:        struct eisa_attach_args *ea = aux;
                    155:        struct bha_softc *sc = (void *)self;
                    156:        bus_space_tag_t iot = ea->ea_iot;
                    157:        bus_space_handle_t ioh, ioh2;
                    158:        int port;
                    159:        struct bha_probe_data bpd;
                    160:        eisa_chipset_tag_t ec = ea->ea_ec;
                    161:        eisa_intr_handle_t ih;
                    162:        const char *model, *intrstr;
                    163:
                    164:        if (!strcmp(ea->ea_idstring, "BUS4201"))
                    165:                model = EISA_PRODUCT_BUS4201;
                    166:        else if (!strcmp(ea->ea_idstring, "BUS4202"))
                    167:                model = EISA_PRODUCT_BUS4202;
                    168:        else
                    169:                model = "unknown model!";
                    170:
                    171:        if (bus_space_map(iot,
                    172:            EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET, BHA_EISA_IOSIZE,
                    173:            0, &ioh)) {
                    174:                printf(": could not map EISA slot\n");
                    175:                return;
                    176:        }
                    177:
                    178:        if (bha_eisa_address(iot, ioh, &port) ||
                    179:            bus_space_map(iot, port, BHA_ISA_IOSIZE, 0, &ioh2)) {
                    180:                printf(": could not map ISA address\n");
                    181:                return;
                    182:        }
                    183:
                    184:        sc->sc_iot = iot;
                    185:        sc->sc_ioh = ioh2;
                    186:        sc->sc_dmat = ea->ea_dmat;
                    187:        if (!bha_find(iot, ioh2, &bpd)) {
                    188:                printf(": bha_find failed\n");
                    189:                return;
                    190:        }
                    191:
                    192:        sc->sc_dmaflags = 0;
                    193:
                    194:        if (eisa_intr_map(ec, bpd.sc_irq, &ih)) {
                    195:                printf(": couldn't map interrupt (%d)\n", bpd.sc_irq);
                    196:                return;
                    197:        }
                    198:        intrstr = eisa_intr_string(ec, ih);
                    199:        sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
                    200:            bha_intr, sc, sc->sc_dev.dv_xname);
                    201:        if (sc->sc_ih == NULL) {
                    202:                printf(": couldn't establish interrupt");
                    203:                if (intrstr != NULL)
                    204:                        printf(" at %s", intrstr);
                    205:                printf("\n");
                    206:                return;
                    207:        }
                    208:        printf(": %s, %s\n", intrstr, model);
                    209:
                    210:        bha_attach(sc, &bpd);
                    211: }

CVSweb