[BACK]Return to mcpcia.c CVS log [TXT][DIR] Up to [local] / sys / arch / alpha / pci

Annotation of sys/arch/alpha/pci/mcpcia.c, Revision 1.1.1.1

1.1       nbrk        1: /* $OpenBSD: mcpcia.c,v 1.1 2007/03/16 21:22:27 robert Exp $ */
                      2: /* $NetBSD: mcpcia.c,v 1.20 2007/03/04 05:59:11 christos Exp $ */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1999 The NetBSD Foundation, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to The NetBSD Foundation
                      9:  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
                     10:  * NASA Ames Research Center.
                     11:  *
                     12:  * Redistribution and use in source and binary forms, with or without
                     13:  * modification, are permitted provided that the following conditions
                     14:  * are met:
                     15:  * 1. Redistributions of source code must retain the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer.
                     17:  * 2. Redistributions in binary form must reproduce the above copyright
                     18:  *    notice, this list of conditions and the following disclaimer in the
                     19:  *    documentation and/or other materials provided with the distribution.
                     20:  * 3. All advertising materials mentioning features or use of this software
                     21:  *    must display the following acknowledgement:
                     22:  *     This product includes software developed by the NetBSD
                     23:  *     Foundation, Inc. and its contributors.
                     24:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     25:  *    contributors may be used to endorse or promote products derived
                     26:  *    from this software without specific prior written permission.
                     27:  *
                     28:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     29:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     30:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     31:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     32:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     33:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     34:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     35:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     36:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     37:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     38:  * POSSIBILITY OF SUCH DAMAGE.
                     39:  */
                     40:
                     41: /*
                     42:  * Copyright (c) 1998 by Matthew Jacob
                     43:  * NASA AMES Research Center.
                     44:  * All rights reserved.
                     45:  *
                     46:  * Redistribution and use in source and binary forms, with or without
                     47:  * modification, are permitted provided that the following conditions
                     48:  * are met:
                     49:  * 1. Redistributions of source code must retain the above copyright
                     50:  *    notice immediately at the beginning of the file, without modification,
                     51:  *    this list of conditions, and the following disclaimer.
                     52:  * 2. Redistributions in binary form must reproduce the above copyright
                     53:  *    notice, this list of conditions and the following disclaimer in the
                     54:  *    documentation and/or other materials provided with the distribution.
                     55:  * 3. The name of the author may not be used to endorse or promote products
                     56:  *    derived from this software without specific prior written permission.
                     57:  *
                     58:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     59:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     60:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     61:  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
                     62:  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     63:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     64:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     65:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     66:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     67:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     68:  * SUCH DAMAGE.
                     69:  */
                     70:
                     71: /*
                     72:  * MCPCIA mcbus to PCI bus adapter
                     73:  * found on AlphaServer 4100 systems.
                     74:  */
                     75:
                     76: #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
                     77: #include <sys/param.h>
                     78: #include <sys/systm.h>
                     79: #include <sys/device.h>
                     80: #include <sys/malloc.h>
                     81:
                     82: #include <machine/autoconf.h>
                     83: #include <machine/rpb.h>
                     84: #include <machine/sysarch.h>
                     85:
                     86: #include <alpha/mcbus/mcbusreg.h>
                     87: #include <alpha/mcbus/mcbusvar.h>
                     88: #include <alpha/pci/mcpciareg.h>
                     89: #include <alpha/pci/mcpciavar.h>
                     90: #include <alpha/pci/pci_kn300.h>
                     91:
                     92: #define KV(_addr)      ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
                     93: #define        MCPCIA_SYSBASE(mc)      \
                     94:        ((((unsigned long) (mc)->cc_gid) << MCBUS_GID_SHIFT) | \
                     95:         (((unsigned long) (mc)->cc_mid) << MCBUS_MID_SHIFT) | \
                     96:         (MCBUS_IOSPACE))
                     97:
                     98: #define        MCPCIA_PROBE(mid, gid)  \
                     99:        badaddr((void *)KV(((((unsigned long) gid) << MCBUS_GID_SHIFT) | \
                    100:         (((unsigned long) mid) << MCBUS_MID_SHIFT) | \
                    101:         (MCBUS_IOSPACE) | MCPCIA_PCI_BRIDGE | _MCPCIA_PCI_REV)), \
                    102:        sizeof(u_int32_t))
                    103:
                    104: int    mcpciamatch (struct device *, void *, void *);
                    105: void   mcpciaattach (struct device *, struct device *, void *);
                    106: void   mcpcia_config_cleanup (void);
                    107:
                    108: int    mcpciaprint (void *, const char *);
                    109:
                    110: struct cfattach mcpcia_ca = {
                    111:        sizeof(struct mcpcia_softc), mcpciamatch, mcpciaattach
                    112: };
                    113:
                    114: struct cfdriver mcpcia_cd = {
                    115:         NULL, "mcpcia", DV_DULL,
                    116: };
                    117:
                    118: /*
                    119:  * We have one statically-allocated mcpcia_config structure; this is
                    120:  * the one used for the console (which, coincidentally, is the only
                    121:  * MCPCIA with an EISA adapter attached to it).
                    122:  */
                    123: struct mcpcia_config mcpcia_console_configuration;
                    124:
                    125: int
                    126: mcpciaprint(aux, pnp)
                    127:        void *aux;
                    128:        const char *pnp;
                    129: {
                    130:        register struct pcibus_attach_args *pba = aux;
                    131:        /* only PCIs can attach to MCPCIA for now */
                    132:        if (pnp)
                    133:                printf("%s at %s", pba->pba_busname, pnp);
                    134:        printf(" bus %d", pba->pba_bus);
                    135:        return (UNCONF);
                    136: }
                    137:
                    138: int
                    139: mcpciamatch(parent, cf, aux)
                    140:        struct device *parent;
                    141:        void *cf;
                    142:        void *aux;
                    143: {
                    144:        struct mcbus_dev_attach_args *ma = aux;
                    145:
                    146:        if (ma->ma_type == MCBUS_TYPE_PCI)
                    147:                return (1);
                    148:
                    149:        return (0);
                    150: }
                    151:
                    152: void
                    153: mcpciaattach(parent, self, aux)
                    154:        struct device *parent;
                    155:        struct device *self;
                    156:        void *aux;
                    157: {
                    158:        static int first = 1;
                    159:        struct mcbus_dev_attach_args *ma = aux;
                    160:        struct mcpcia_softc *mcp = (struct mcpcia_softc *)self;
                    161:        struct mcpcia_config *ccp;
                    162:        struct pcibus_attach_args pba;
                    163:        u_int32_t ctl;
                    164:
                    165:        /*
                    166:         * Make sure this MCPCIA exists...
                    167:         */
                    168:        if (MCPCIA_PROBE(ma->ma_mid, ma->ma_gid)) {
                    169:                mcp->mcpcia_cc = NULL;
                    170:                printf(" (not present)\n");
                    171:                return;
                    172:        }
                    173:        printf("\n");
                    174:
                    175:        /*
                    176:         * Determine if we're the console's MCPCIA.
                    177:         */
                    178:        if (ma->ma_mid == mcpcia_console_configuration.cc_mid &&
                    179:            ma->ma_gid == mcpcia_console_configuration.cc_gid)
                    180:                ccp = &mcpcia_console_configuration;
                    181:        else {
                    182:                ccp = malloc(sizeof(struct mcpcia_config), M_DEVBUF, M_WAITOK);
                    183:                memset(ccp, 0, sizeof(struct mcpcia_config));
                    184:
                    185:                ccp->cc_mid = ma->ma_mid;
                    186:                ccp->cc_gid = ma->ma_gid;
                    187:        }
                    188:        mcp->mcpcia_cc = ccp;
                    189:        ccp->cc_sc = mcp;
                    190:
                    191:        /* This initializes cc_sysbase so we can do register access. */
                    192:        mcpcia_init0(ccp, 1);
                    193:
                    194:        ctl = REGVAL(MCPCIA_PCI_REV(ccp));
                    195:        printf("%s: Horse Revision %d, %s Handed Saddle Revision %d,"
                    196:            " CAP Revision %d\n", mcp->mcpcia_dev.dv_xname, HORSE_REV(ctl),
                    197:            (SADDLE_TYPE(ctl) & 1)? "Right": "Left", SADDLE_REV(ctl),
                    198:            CAP_REV(ctl));
                    199:
                    200:        mcpcia_dma_init(ccp);
                    201:
                    202:        /*
                    203:         * Set up interrupts
                    204:         */
                    205:        pci_kn300_pickintr(ccp, first);
                    206:        first = 0;
                    207:
                    208:        /*
                    209:         * Attach PCI bus
                    210:         */
                    211:        pba.pba_busname = "pci";
                    212:        pba.pba_iot = &ccp->cc_iot;
                    213:        pba.pba_memt = &ccp->cc_memt;
                    214:        pba.pba_dmat =
                    215:            alphabus_dma_get_tag(&ccp->cc_dmat_direct, ALPHA_BUS_PCI);
                    216:        pba.pba_pc = &ccp->cc_pc;
                    217:        pba.pba_domain = pci_ndomains++;
                    218:        pba.pba_bus = 0;
                    219:        pba.pba_bridgetag = NULL;
                    220:
                    221:        (void) config_found(self, &pba, mcpciaprint);
                    222:
                    223:        /*
                    224:         * Clear any errors that may have occurred during the probe
                    225:         * sequence.
                    226:         */
                    227:        REGVAL(MCPCIA_CAP_ERR(ccp)) = 0xFFFFFFFF;
                    228:        alpha_mb();
                    229: }
                    230:
                    231: void
                    232: mcpcia_init()
                    233: {
                    234:        struct mcpcia_config *ccp = &mcpcia_console_configuration;
                    235:        int i;
                    236:
                    237:        /*
                    238:         * Look for all of the MCPCIAs on the system.  One of them
                    239:         * will have an EISA attached to it.  This MCPCIA is the
                    240:         * only one that can be used for the console.  Once we find
                    241:         * that one, initialize it.
                    242:         */
                    243:        for (i = 0; i < MCPCIA_PER_MCBUS; i++) {
                    244:                ccp->cc_mid = mcbus_mcpcia_probe_order[i];
                    245:                /*
                    246:                 * XXX If we ever support more than one MCBUS, we'll
                    247:                 * XXX have to probe for them, and map them to unit
                    248:                 * XXX numbers.
                    249:                 */
                    250:                ccp->cc_gid = MCBUS_GID_FROM_INSTANCE(0);
                    251:                ccp->cc_sysbase = MCPCIA_SYSBASE(ccp);
                    252:
                    253:                if (badaddr((void *)ALPHA_PHYS_TO_K0SEG(MCPCIA_PCI_REV(ccp)),
                    254:                    sizeof(u_int32_t)))
                    255:                        continue;
                    256:
                    257:                if (EISA_PRESENT(REGVAL(MCPCIA_PCI_REV(ccp)))) {
                    258:                        mcpcia_init0(ccp, 0);
                    259:                        return;
                    260:                }
                    261:        }
                    262:
                    263:        panic("mcpcia_init: unable to find EISA bus");
                    264: }
                    265:
                    266: void
                    267: mcpcia_init0(ccp, mallocsafe)
                    268:        struct mcpcia_config *ccp;
                    269:        int mallocsafe;
                    270: {
                    271:        u_int32_t ctl;
                    272:
                    273:        snprintf(ccp->pc_io_ex_name, sizeof ccp->pc_io_ex_name,
                    274:            "mcpcia%d_bus_io", ccp->cc_mid);
                    275:        snprintf(ccp->pc_mem_dex_name, sizeof ccp->pc_mem_dex_name,
                    276:            "mcpciad%d_bus_mem", ccp->cc_mid);
                    277:        snprintf(ccp->pc_mem_dex_name, sizeof ccp->pc_mem_sex_name,
                    278:            "mcpcias%d_bus_mem", ccp->cc_mid);
                    279:
                    280:        if (!ccp->cc_initted) {
                    281:                /* don't do these twice since they set up extents */
                    282:                mcpcia_bus_io_init(&ccp->cc_iot, ccp);
                    283:                mcpcia_bus_mem_init(&ccp->cc_memt, ccp);
                    284:        }
                    285:        ccp->cc_mallocsafe = mallocsafe;
                    286:
                    287:        mcpcia_pci_init(&ccp->cc_pc, ccp);
                    288:
                    289:         /*
                    290:          * Establish a precalculated base for convenience's sake.
                    291:          */
                    292:         ccp->cc_sysbase = MCPCIA_SYSBASE(ccp);
                    293:
                    294:         /*
                    295:          * Disable interrupts and clear errors prior to probing
                    296:          */
                    297:         REGVAL(MCPCIA_INT_MASK0(ccp)) = 0;
                    298:         REGVAL(MCPCIA_INT_MASK1(ccp)) = 0;
                    299:         REGVAL(MCPCIA_CAP_ERR(ccp)) = 0xFFFFFFFF;
                    300:         alpha_mb();
                    301:
                    302:         if (ccp == &mcpcia_console_configuration) {
                    303:                 /*
                    304:                  * Use this opportunity to also find out the MID and CPU
                    305:                  * type of the currently running CPU (that's us, billybob....)
                    306:                  */
                    307:                 ctl = REGVAL(MCPCIA_WHOAMI(ccp));
                    308:                 mcbus_primary.mcbus_cpu_mid = MCBUS_CPU_MID(ctl);
                    309:                 if ((MCBUS_CPU_INFO(ctl) & CPU_Fill_Err) == 0 &&
                    310:                     mcbus_primary.mcbus_valid == 0) {
                    311:                         mcbus_primary.mcbus_bcache =
                    312:                             MCBUS_CPU_INFO(ctl) & CPU_BCacheMask;
                    313:                         mcbus_primary.mcbus_valid = 1;
                    314:                 }
                    315:                 alpha_mb();
                    316:         }
                    317:
                    318:        alpha_pci_chipset = &ccp->cc_pc;
                    319:        alpha_pci_chipset->pc_name = "mcpcia";
                    320:        alpha_pci_chipset->pc_hae_mask = 0;
                    321:        alpha_pci_chipset->pc_dense = MCPCIA_PCI_DENSE;
                    322:
                    323:         ccp->cc_initted = 1;
                    324: }
                    325:
                    326: void
                    327: mcpcia_config_cleanup()
                    328: {
                    329:        volatile u_int32_t ctl;
                    330:        struct mcpcia_softc *mcp;
                    331:        struct mcpcia_config *ccp;
                    332:        int i;
                    333:        extern struct cfdriver mcpcia_cd;
                    334:
                    335:        /*
                    336:         * Turn on Hard, Soft error interrupts. Maybe i2c too.
                    337:         */
                    338:        for (i = 0; i < mcpcia_cd.cd_ndevs; i++) {
                    339:                if ((mcp = mcpcia_cd.cd_devs[i]) == NULL)
                    340:                        continue;
                    341:
                    342:                ccp = mcp->mcpcia_cc;
                    343:                if (ccp == NULL)
                    344:                        continue;
                    345:
                    346:                ctl = REGVAL(MCPCIA_INT_MASK0(ccp));
                    347:                ctl |= MCPCIA_GEN_IENABL;
                    348:                REGVAL(MCPCIA_INT_MASK0(ccp)) = ctl;
                    349:                alpha_mb();
                    350:
                    351:                /* force stall while write completes */
                    352:                ctl = REGVAL(MCPCIA_INT_MASK0(ccp));
                    353:        }
                    354: }

CVSweb