Home | History | Annotate | Line # | Download | only in pci
opti82c558.c revision 1.2.4.2
      1  1.2.4.2  bouyer /*	$NetBSD: opti82c558.c,v 1.2.4.2 2000/11/20 20:09:34 bouyer Exp $	*/
      2  1.2.4.2  bouyer 
      3  1.2.4.2  bouyer /*-
      4  1.2.4.2  bouyer  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.2.4.2  bouyer  * All rights reserved.
      6  1.2.4.2  bouyer  *
      7  1.2.4.2  bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.4.2  bouyer  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.2.4.2  bouyer  * NASA Ames Research Center.
     10  1.2.4.2  bouyer  *
     11  1.2.4.2  bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.2.4.2  bouyer  * modification, are permitted provided that the following conditions
     13  1.2.4.2  bouyer  * are met:
     14  1.2.4.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.2.4.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     16  1.2.4.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.2.4.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     18  1.2.4.2  bouyer  *    documentation and/or other materials provided with the distribution.
     19  1.2.4.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     20  1.2.4.2  bouyer  *    must display the following acknowledgement:
     21  1.2.4.2  bouyer  *	This product includes software developed by the NetBSD
     22  1.2.4.2  bouyer  *	Foundation, Inc. and its contributors.
     23  1.2.4.2  bouyer  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.2.4.2  bouyer  *    contributors may be used to endorse or promote products derived
     25  1.2.4.2  bouyer  *    from this software without specific prior written permission.
     26  1.2.4.2  bouyer  *
     27  1.2.4.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.2.4.2  bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.2.4.2  bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.2.4.2  bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.2.4.2  bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.2.4.2  bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.2.4.2  bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.2.4.2  bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.2.4.2  bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.2.4.2  bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.2.4.2  bouyer  * POSSIBILITY OF SUCH DAMAGE.
     38  1.2.4.2  bouyer  */
     39  1.2.4.2  bouyer 
     40  1.2.4.2  bouyer /*
     41  1.2.4.2  bouyer  * Copyright (c) 1999, by UCHIYAMA Yasushi
     42  1.2.4.2  bouyer  * All rights reserved.
     43  1.2.4.2  bouyer  *
     44  1.2.4.2  bouyer  * Redistribution and use in source and binary forms, with or without
     45  1.2.4.2  bouyer  * modification, are permitted provided that the following conditions
     46  1.2.4.2  bouyer  * are met:
     47  1.2.4.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     48  1.2.4.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     49  1.2.4.2  bouyer  * 2. The name of the developer may NOT be used to endorse or promote products
     50  1.2.4.2  bouyer  *    derived from this software without specific prior written permission.
     51  1.2.4.2  bouyer  *
     52  1.2.4.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     53  1.2.4.2  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  1.2.4.2  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  1.2.4.2  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     56  1.2.4.2  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  1.2.4.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  1.2.4.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  1.2.4.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  1.2.4.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  1.2.4.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  1.2.4.2  bouyer  * SUCH DAMAGE.
     63  1.2.4.2  bouyer  */
     64  1.2.4.2  bouyer 
     65  1.2.4.2  bouyer /*
     66  1.2.4.2  bouyer  * Support for the Opti 82c558 PCI-ISA bridge interrupt controller.
     67  1.2.4.2  bouyer  */
     68  1.2.4.2  bouyer 
     69  1.2.4.2  bouyer #include <sys/param.h>
     70  1.2.4.2  bouyer #include <sys/systm.h>
     71  1.2.4.2  bouyer #include <sys/device.h>
     72  1.2.4.2  bouyer #include <sys/malloc.h>
     73  1.2.4.2  bouyer 
     74  1.2.4.2  bouyer #include <machine/intr.h>
     75  1.2.4.2  bouyer #include <machine/bus.h>
     76  1.2.4.2  bouyer 
     77  1.2.4.2  bouyer #include <dev/pci/pcivar.h>
     78  1.2.4.2  bouyer #include <dev/pci/pcireg.h>
     79  1.2.4.2  bouyer #include <dev/pci/pcidevs.h>
     80  1.2.4.2  bouyer 
     81  1.2.4.2  bouyer #include <i386/pci/pci_intr_fixup.h>
     82  1.2.4.2  bouyer #include <i386/pci/opti82c558reg.h>
     83  1.2.4.2  bouyer 
     84  1.2.4.2  bouyer int	opti82c558_getclink __P((pciintr_icu_handle_t, int, int *));
     85  1.2.4.2  bouyer int	opti82c558_get_intr __P((pciintr_icu_handle_t, int, int *));
     86  1.2.4.2  bouyer int	opti82c558_set_intr __P((pciintr_icu_handle_t, int, int));
     87  1.2.4.2  bouyer int	opti82c558_get_trigger __P((pciintr_icu_handle_t, int, int *));
     88  1.2.4.2  bouyer int	opti82c558_set_trigger __P((pciintr_icu_handle_t, int, int));
     89  1.2.4.2  bouyer 
     90  1.2.4.2  bouyer const struct pciintr_icu opti82c558_pci_icu = {
     91  1.2.4.2  bouyer 	opti82c558_getclink,
     92  1.2.4.2  bouyer 	opti82c558_get_intr,
     93  1.2.4.2  bouyer 	opti82c558_set_intr,
     94  1.2.4.2  bouyer 	opti82c558_get_trigger,
     95  1.2.4.2  bouyer 	opti82c558_set_trigger,
     96  1.2.4.2  bouyer };
     97  1.2.4.2  bouyer 
     98  1.2.4.2  bouyer struct opti82c558_handle {
     99  1.2.4.2  bouyer 	pci_chipset_tag_t ph_pc;
    100  1.2.4.2  bouyer 	pcitag_t ph_tag;
    101  1.2.4.2  bouyer };
    102  1.2.4.2  bouyer 
    103  1.2.4.2  bouyer static const int viper_pirq_decode[] = {
    104  1.2.4.2  bouyer 	-1, 5, 9, 10, 11, 12, 14, 15
    105  1.2.4.2  bouyer };
    106  1.2.4.2  bouyer 
    107  1.2.4.2  bouyer static const int viper_pirq_encode[] = {
    108  1.2.4.2  bouyer 	-1,		/* 0 */
    109  1.2.4.2  bouyer 	-1,		/* 1 */
    110  1.2.4.2  bouyer 	-1,		/* 2 */
    111  1.2.4.2  bouyer 	-1,		/* 3 */
    112  1.2.4.2  bouyer 	-1,		/* 4 */
    113  1.2.4.2  bouyer 	VIPER_PIRQ_5,	/* 5 */
    114  1.2.4.2  bouyer 	-1,		/* 6 */
    115  1.2.4.2  bouyer 	-1,		/* 7 */
    116  1.2.4.2  bouyer 	-1,		/* 8 */
    117  1.2.4.2  bouyer 	VIPER_PIRQ_9,	/* 9 */
    118  1.2.4.2  bouyer 	VIPER_PIRQ_10,	/* 10 */
    119  1.2.4.2  bouyer 	VIPER_PIRQ_11,	/* 11 */
    120  1.2.4.2  bouyer 	VIPER_PIRQ_12,	/* 12 */
    121  1.2.4.2  bouyer 	-1,		/* 13 */
    122  1.2.4.2  bouyer 	VIPER_PIRQ_14,	/* 14 */
    123  1.2.4.2  bouyer 	VIPER_PIRQ_15,	/* 15 */
    124  1.2.4.2  bouyer };
    125  1.2.4.2  bouyer 
    126  1.2.4.2  bouyer int
    127  1.2.4.2  bouyer opti82c558_init(pc, iot, tag, ptagp, phandp)
    128  1.2.4.2  bouyer 	pci_chipset_tag_t pc;
    129  1.2.4.2  bouyer 	bus_space_tag_t iot;
    130  1.2.4.2  bouyer 	pcitag_t tag;
    131  1.2.4.2  bouyer 	pciintr_icu_tag_t *ptagp;
    132  1.2.4.2  bouyer 	pciintr_icu_handle_t *phandp;
    133  1.2.4.2  bouyer {
    134  1.2.4.2  bouyer 	struct opti82c558_handle *ph;
    135  1.2.4.2  bouyer 
    136  1.2.4.2  bouyer 	ph = malloc(sizeof(*ph), M_DEVBUF, M_NOWAIT);
    137  1.2.4.2  bouyer 	if (ph == NULL)
    138  1.2.4.2  bouyer 		return (1);
    139  1.2.4.2  bouyer 
    140  1.2.4.2  bouyer 	ph->ph_pc = pc;
    141  1.2.4.2  bouyer 	ph->ph_tag = tag;
    142  1.2.4.2  bouyer 
    143  1.2.4.2  bouyer 	*ptagp = &opti82c558_pci_icu;
    144  1.2.4.2  bouyer 	*phandp = ph;
    145  1.2.4.2  bouyer 	return (0);
    146  1.2.4.2  bouyer }
    147  1.2.4.2  bouyer 
    148  1.2.4.2  bouyer int
    149  1.2.4.2  bouyer opti82c558_getclink(v, link, clinkp)
    150  1.2.4.2  bouyer 	pciintr_icu_handle_t v;
    151  1.2.4.2  bouyer 	int link, *clinkp;
    152  1.2.4.2  bouyer {
    153  1.2.4.2  bouyer 
    154  1.2.4.2  bouyer 	if (VIPER_LEGAL_LINK(link - 1)) {
    155  1.2.4.2  bouyer 		*clinkp = link - 1;
    156  1.2.4.2  bouyer 		return (0);
    157  1.2.4.2  bouyer 	}
    158  1.2.4.2  bouyer 
    159  1.2.4.2  bouyer 	return (1);
    160  1.2.4.2  bouyer }
    161  1.2.4.2  bouyer 
    162  1.2.4.2  bouyer int
    163  1.2.4.2  bouyer opti82c558_get_intr(v, clink, irqp)
    164  1.2.4.2  bouyer 	pciintr_icu_handle_t v;
    165  1.2.4.2  bouyer 	int clink, *irqp;
    166  1.2.4.2  bouyer {
    167  1.2.4.2  bouyer 	struct opti82c558_handle *ph = v;
    168  1.2.4.2  bouyer 	pcireg_t reg;
    169  1.2.4.2  bouyer 	int val;
    170  1.2.4.2  bouyer 
    171  1.2.4.2  bouyer 	if (VIPER_LEGAL_LINK(clink) == 0)
    172  1.2.4.2  bouyer 		return (1);
    173  1.2.4.2  bouyer 
    174  1.2.4.2  bouyer 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ);
    175  1.2.4.2  bouyer 	val = VIPER_PIRQ(reg, clink);
    176  1.2.4.2  bouyer 	*irqp = (val == VIPER_PIRQ_NONE) ?
    177  1.2.4.2  bouyer 	    I386_PCI_INTERRUPT_LINE_NO_CONNECTION : viper_pirq_decode[val];
    178  1.2.4.2  bouyer 
    179  1.2.4.2  bouyer 	return (0);
    180  1.2.4.2  bouyer }
    181  1.2.4.2  bouyer 
    182  1.2.4.2  bouyer int
    183  1.2.4.2  bouyer opti82c558_set_intr(v, clink, irq)
    184  1.2.4.2  bouyer 	pciintr_icu_handle_t v;
    185  1.2.4.2  bouyer 	int clink, irq;
    186  1.2.4.2  bouyer {
    187  1.2.4.2  bouyer 	struct opti82c558_handle *ph = v;
    188  1.2.4.2  bouyer 	int shift;
    189  1.2.4.2  bouyer 	pcireg_t reg;
    190  1.2.4.2  bouyer 
    191  1.2.4.2  bouyer 	if (VIPER_LEGAL_LINK(clink) == 0 || VIPER_LEGAL_IRQ(irq) == 0)
    192  1.2.4.2  bouyer 		return (1);
    193  1.2.4.2  bouyer 
    194  1.2.4.2  bouyer 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ);
    195  1.2.4.2  bouyer 	shift = VIPER_PIRQ_SELECT_SHIFT * clink;
    196  1.2.4.2  bouyer 	reg &= ~(VIPER_PIRQ_SELECT_MASK << shift);
    197  1.2.4.2  bouyer 	reg |= (viper_pirq_encode[irq] << shift);
    198  1.2.4.2  bouyer 	pci_conf_write(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ, reg);
    199  1.2.4.2  bouyer 
    200  1.2.4.2  bouyer 	return (0);
    201  1.2.4.2  bouyer }
    202  1.2.4.2  bouyer 
    203  1.2.4.2  bouyer int
    204  1.2.4.2  bouyer opti82c558_get_trigger(v, irq, triggerp)
    205  1.2.4.2  bouyer 	pciintr_icu_handle_t v;
    206  1.2.4.2  bouyer 	int irq, *triggerp;
    207  1.2.4.2  bouyer {
    208  1.2.4.2  bouyer 	struct opti82c558_handle *ph = v;
    209  1.2.4.2  bouyer 	pcireg_t reg;
    210  1.2.4.2  bouyer 
    211  1.2.4.2  bouyer 	if (VIPER_LEGAL_IRQ(irq) == 0) {
    212  1.2.4.2  bouyer 		/* ISA IRQ? */
    213  1.2.4.2  bouyer 		*triggerp = IST_EDGE;
    214  1.2.4.2  bouyer 		return (0);
    215  1.2.4.2  bouyer 	}
    216  1.2.4.2  bouyer 
    217  1.2.4.2  bouyer 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ);
    218  1.2.4.2  bouyer 	if ((reg >> (VIPER_CFG_TRIGGER_SHIFT + viper_pirq_encode[irq])) & 1)
    219  1.2.4.2  bouyer 		*triggerp = IST_LEVEL;
    220  1.2.4.2  bouyer 	else
    221  1.2.4.2  bouyer 		*triggerp = IST_EDGE;
    222  1.2.4.2  bouyer 
    223  1.2.4.2  bouyer 	return (0);
    224  1.2.4.2  bouyer }
    225  1.2.4.2  bouyer 
    226  1.2.4.2  bouyer int
    227  1.2.4.2  bouyer opti82c558_set_trigger(v, irq, trigger)
    228  1.2.4.2  bouyer 	pciintr_icu_handle_t v;
    229  1.2.4.2  bouyer 	int irq, trigger;
    230  1.2.4.2  bouyer {
    231  1.2.4.2  bouyer 	struct opti82c558_handle *ph = v;
    232  1.2.4.2  bouyer 	int shift;
    233  1.2.4.2  bouyer 	pcireg_t reg;
    234  1.2.4.2  bouyer 
    235  1.2.4.2  bouyer 	if (VIPER_LEGAL_IRQ(irq) == 0) {
    236  1.2.4.2  bouyer 		/* ISA IRQ? */
    237  1.2.4.2  bouyer 		return ((trigger != IST_LEVEL) ? 0 : 1);
    238  1.2.4.2  bouyer 	}
    239  1.2.4.2  bouyer 
    240  1.2.4.2  bouyer 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ);
    241  1.2.4.2  bouyer 	shift = (VIPER_CFG_TRIGGER_SHIFT + viper_pirq_encode[irq]);
    242  1.2.4.2  bouyer 	if (trigger == IST_LEVEL)
    243  1.2.4.2  bouyer 		reg |= (1 << shift);
    244  1.2.4.2  bouyer 	else
    245  1.2.4.2  bouyer 		reg &= ~(1 << shift);
    246  1.2.4.2  bouyer 	pci_conf_write(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ, reg);
    247  1.2.4.2  bouyer 
    248  1.2.4.2  bouyer 	return (0);
    249  1.2.4.2  bouyer }
    250