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

Annotation of sys/arch/i386/pci/amd756.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: amd756.c,v 1.4 2006/09/19 11:06:34 jsg Exp $  */
        !             2: /*     $NetBSD$        */
        !             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) 1999, by UCHIYAMA Yasushi
        !            43:  * All rights reserved.
        !            44:  *
        !            45:  * Redistribution and use in source and binary forms, with or without
        !            46:  * modification, are permitted provided that the following conditions
        !            47:  * are met:
        !            48:  * 1. Redistributions of source code must retain the above copyright
        !            49:  *    notice, this list of conditions and the following disclaimer.
        !            50:  * 2. The name of the developer may NOT be used to endorse or promote products
        !            51:  *    derived from this software without specific prior written permission.
        !            52:  *
        !            53:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
        !            54:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            55:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            56:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
        !            57:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            58:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            59:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            60:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            61:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            62:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            63:  * SUCH DAMAGE.
        !            64:  */
        !            65:
        !            66: /*
        !            67:  * Support for the Advanced Micro Devices AMD756 Peripheral Bus Controller.
        !            68:  */
        !            69:
        !            70: #include <sys/param.h>
        !            71: #include <sys/systm.h>
        !            72: #include <sys/device.h>
        !            73: #include <sys/malloc.h>
        !            74:
        !            75: #include <machine/intr.h>
        !            76: #include <machine/bus.h>
        !            77:
        !            78: #include <dev/pci/pcivar.h>
        !            79: #include <dev/pci/pcireg.h>
        !            80: #include <dev/pci/pcidevs.h>
        !            81:
        !            82: #include <i386/pci/pcibiosvar.h>
        !            83: #include <i386/pci/amd756reg.h>
        !            84:
        !            85: struct viper_handle {
        !            86:        bus_space_tag_t ph_iot;
        !            87:        bus_space_handle_t ph_regs_ioh;
        !            88:        pci_chipset_tag_t ph_pc;
        !            89:        pcitag_t ph_tag;
        !            90: };
        !            91:
        !            92: int amd756_getclink(pciintr_icu_handle_t, int, int *);
        !            93: int amd756_get_intr(pciintr_icu_handle_t, int, int *);
        !            94: int amd756_set_intr(pciintr_icu_handle_t, int, int);
        !            95: int amd756_get_trigger(pciintr_icu_handle_t, int, int *);
        !            96: int amd756_set_trigger(pciintr_icu_handle_t, int, int);
        !            97: #ifdef VIPER_DEBUG
        !            98: static void amd756_pir_dump(struct viper_handle *);
        !            99: #endif
        !           100:
        !           101: const struct pciintr_icu amd756_pci_icu = {
        !           102:        amd756_getclink,
        !           103:        amd756_get_intr,
        !           104:        amd756_set_intr,
        !           105:        amd756_get_trigger,
        !           106:        amd756_set_trigger,
        !           107: };
        !           108:
        !           109:
        !           110: int
        !           111: amd756_init(pci_chipset_tag_t pc, bus_space_tag_t iot, pcitag_t tag,
        !           112:     pciintr_icu_tag_t *ptagp, pciintr_icu_handle_t *phandp)
        !           113: {
        !           114:        struct viper_handle *ph;
        !           115:
        !           116:        ph = malloc(sizeof(*ph), M_DEVBUF, M_NOWAIT);
        !           117:        if (ph == NULL)
        !           118:                return (1);
        !           119:
        !           120:        ph->ph_iot = iot;
        !           121:        ph->ph_pc = pc;
        !           122:        ph->ph_tag = tag;
        !           123:
        !           124:        *ptagp = &amd756_pci_icu;
        !           125:        *phandp = ph;
        !           126:
        !           127: #ifdef VIPER_DEBUG
        !           128:        amd756_pir_dump(ph);
        !           129: #endif
        !           130:
        !           131:        return 0;
        !           132: }
        !           133:
        !           134: int
        !           135: amd756_getclink(pciintr_icu_handle_t v, int link, int *clinkp)
        !           136: {
        !           137:        if (AMD756_LEGAL_LINK(link - 1) == 0)
        !           138:                return (1);
        !           139:
        !           140:        *clinkp = link - 1;
        !           141:        return (0);
        !           142: }
        !           143:
        !           144: int
        !           145: amd756_get_intr(pciintr_icu_handle_t v, int clink, int *irqp)
        !           146: {
        !           147:        struct viper_handle *ph = v;
        !           148:        pcireg_t reg;
        !           149:        int val;
        !           150:
        !           151:        if (AMD756_LEGAL_LINK(clink) == 0)
        !           152:                return (1);
        !           153:
        !           154:        reg = AMD756_GET_PIIRQSEL(ph);
        !           155:        val = (reg >> (4*clink)) & 0x0f;
        !           156:        *irqp = (val == 0) ?
        !           157:            I386_PCI_INTERRUPT_LINE_NO_CONNECTION : val;
        !           158:
        !           159:        return (0);
        !           160: }
        !           161:
        !           162: int
        !           163: amd756_set_intr(pciintr_icu_handle_t v, int clink, int irq)
        !           164: {
        !           165:        struct viper_handle *ph = v;
        !           166:        int val;
        !           167:        pcireg_t reg;
        !           168:
        !           169:        if (AMD756_LEGAL_LINK(clink) == 0 || AMD756_LEGAL_IRQ(irq) == 0)
        !           170:                return (1);
        !           171:
        !           172:        reg = AMD756_GET_PIIRQSEL(ph);
        !           173:        amd756_get_intr(v, clink, &val);
        !           174:        reg &= ~(0x000f << (4*clink));
        !           175:        reg |= irq << (4*clink);
        !           176:        AMD756_SET_PIIRQSEL(ph, reg);
        !           177:
        !           178:        return 0;
        !           179: }
        !           180:
        !           181: int
        !           182: amd756_get_trigger(pciintr_icu_handle_t v, int irq, int *triggerp)
        !           183: {
        !           184:        struct viper_handle *ph = v;
        !           185:        int i, pciirq;
        !           186:        pcireg_t reg;
        !           187:
        !           188:        if (AMD756_LEGAL_IRQ(irq) == 0)
        !           189:                return (1);
        !           190:
        !           191:        for (i = 0; i <= 3; i++) {
        !           192:                amd756_get_intr(v, i, &pciirq);
        !           193:                if (pciirq == irq) {
        !           194:                        reg = AMD756_GET_EDGESEL(ph);
        !           195:                        if (reg & (1 << i))
        !           196:                                *triggerp = IST_EDGE;
        !           197:                        else
        !           198:                                *triggerp = IST_LEVEL;
        !           199:                        break;
        !           200:                }
        !           201:        }
        !           202:
        !           203:        return 0;
        !           204: }
        !           205:
        !           206: int
        !           207: amd756_set_trigger(pciintr_icu_handle_t v, int irq, int trigger)
        !           208: {
        !           209:        struct viper_handle *ph = v;
        !           210:        int i, pciirq;
        !           211:        pcireg_t reg;
        !           212:
        !           213:        if (AMD756_LEGAL_IRQ(irq) == 0)
        !           214:                return (1);
        !           215:
        !           216:        for (i = 0; i <= 3; i++) {
        !           217:                amd756_get_intr(v, i, &pciirq);
        !           218:                if (pciirq == irq) {
        !           219:                        reg = AMD756_GET_PIIRQSEL(ph);
        !           220:                        if (trigger == IST_LEVEL)
        !           221:                                reg &= ~(1 << (4*i));
        !           222:                        else
        !           223:                                reg |= 1 << (4*i);
        !           224:                        AMD756_SET_PIIRQSEL(ph, reg);
        !           225:                        break;
        !           226:                }
        !           227:        }
        !           228:
        !           229:        return (0);
        !           230: }
        !           231:
        !           232: #ifdef VIPER_DEBUG
        !           233: static void
        !           234: amd756_pir_dump(struct viper_handle *ph)
        !           235: {
        !           236:        int a, b;
        !           237:
        !           238:        printf ("VIPER PCI INTERRUPT ROUTING REGISTERS:\n");
        !           239:
        !           240:        a = AMD756_GET_EDGESEL(ph);
        !           241:        b = AMD756_GET_PIIRQSEL(ph);
        !           242:
        !           243:        printf ("TRIGGER: %02x, ROUTING: %04x\n", a, b);
        !           244: }
        !           245: #endif

CVSweb