Home | History | Annotate | Line # | Download | only in pci
sis85c503.c revision 1.2.4.2
      1  1.2.4.2  bouyer /*	$NetBSD: sis85c503.c,v 1.2.4.2 2000/11/20 20:09:35 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 SiS 85c503 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 
     73  1.2.4.2  bouyer #include <machine/intr.h>
     74  1.2.4.2  bouyer #include <machine/bus.h>
     75  1.2.4.2  bouyer 
     76  1.2.4.2  bouyer #include <dev/pci/pcivar.h>
     77  1.2.4.2  bouyer #include <dev/pci/pcireg.h>
     78  1.2.4.2  bouyer #include <dev/pci/pcidevs.h>
     79  1.2.4.2  bouyer 
     80  1.2.4.2  bouyer #include <i386/pci/pci_intr_fixup.h>
     81  1.2.4.2  bouyer #include <i386/pci/sis85c503reg.h>
     82  1.2.4.2  bouyer #include <i386/pci/piixvar.h>
     83  1.2.4.2  bouyer 
     84  1.2.4.2  bouyer int	sis85c503_getclink __P((pciintr_icu_handle_t, int, int *));
     85  1.2.4.2  bouyer int	sis85c503_get_intr __P((pciintr_icu_handle_t, int, int *));
     86  1.2.4.2  bouyer int	sis85c503_set_intr __P((pciintr_icu_handle_t, int, int));
     87  1.2.4.2  bouyer 
     88  1.2.4.2  bouyer const struct pciintr_icu sis85c503_pci_icu = {
     89  1.2.4.2  bouyer 	sis85c503_getclink,
     90  1.2.4.2  bouyer 	sis85c503_get_intr,
     91  1.2.4.2  bouyer 	sis85c503_set_intr,
     92  1.2.4.2  bouyer 	piix_get_trigger,
     93  1.2.4.2  bouyer 	piix_set_trigger,
     94  1.2.4.2  bouyer };
     95  1.2.4.2  bouyer 
     96  1.2.4.2  bouyer int
     97  1.2.4.2  bouyer sis85c503_init(pc, iot, tag, ptagp, phandp)
     98  1.2.4.2  bouyer 	pci_chipset_tag_t pc;
     99  1.2.4.2  bouyer 	bus_space_tag_t iot;
    100  1.2.4.2  bouyer 	pcitag_t tag;
    101  1.2.4.2  bouyer 	pciintr_icu_tag_t *ptagp;
    102  1.2.4.2  bouyer 	pciintr_icu_handle_t *phandp;
    103  1.2.4.2  bouyer {
    104  1.2.4.2  bouyer 
    105  1.2.4.2  bouyer 	if (piix_init(pc, iot, tag, ptagp, phandp) == 0) {
    106  1.2.4.2  bouyer 		*ptagp = &sis85c503_pci_icu;
    107  1.2.4.2  bouyer 		return (0);
    108  1.2.4.2  bouyer 	}
    109  1.2.4.2  bouyer 
    110  1.2.4.2  bouyer 	return (1);
    111  1.2.4.2  bouyer }
    112  1.2.4.2  bouyer 
    113  1.2.4.2  bouyer int
    114  1.2.4.2  bouyer sis85c503_getclink(v, link, clinkp)
    115  1.2.4.2  bouyer 	pciintr_icu_handle_t v;
    116  1.2.4.2  bouyer 	int link, *clinkp;
    117  1.2.4.2  bouyer {
    118  1.2.4.2  bouyer 
    119  1.2.4.2  bouyer 	/* Pattern 1: simple. */
    120  1.2.4.2  bouyer 	if (link >= 1 && link <= 4) {
    121  1.2.4.2  bouyer 		*clinkp = SIS85C503_CFG_PIRQ_REGSTART + link - 1;
    122  1.2.4.2  bouyer 		return (0);
    123  1.2.4.2  bouyer 	}
    124  1.2.4.2  bouyer 
    125  1.2.4.2  bouyer 	/* Pattern 2: configuration register offset */
    126  1.2.4.2  bouyer 	if (link >= SIS85C503_CFG_PIRQ_REGSTART &&
    127  1.2.4.2  bouyer 	    link <= SIS85C503_CFG_PIRQ_REGEND) {
    128  1.2.4.2  bouyer 		*clinkp = link;
    129  1.2.4.2  bouyer 		return (0);
    130  1.2.4.2  bouyer 	}
    131  1.2.4.2  bouyer 
    132  1.2.4.2  bouyer 	return (1);
    133  1.2.4.2  bouyer }
    134  1.2.4.2  bouyer 
    135  1.2.4.2  bouyer int
    136  1.2.4.2  bouyer sis85c503_get_intr(v, clink, irqp)
    137  1.2.4.2  bouyer 	pciintr_icu_handle_t v;
    138  1.2.4.2  bouyer 	int clink, *irqp;
    139  1.2.4.2  bouyer {
    140  1.2.4.2  bouyer 	struct piix_handle *ph = v;
    141  1.2.4.2  bouyer 	pcireg_t reg;
    142  1.2.4.2  bouyer 
    143  1.2.4.2  bouyer 	if (SIS85C503_LEGAL_LINK(clink) == 0)
    144  1.2.4.2  bouyer 		return (1);
    145  1.2.4.2  bouyer 
    146  1.2.4.2  bouyer 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag,
    147  1.2.4.2  bouyer 	    SIS85C503_CFG_PIRQ_REGOFS(clink));
    148  1.2.4.2  bouyer 	reg = SIS85C503_CFG_PIRQ_REG(reg, clink);
    149  1.2.4.2  bouyer 
    150  1.2.4.2  bouyer 	if (reg & SIS85C503_CFG_PIRQ_ROUTE_DISABLE)
    151  1.2.4.2  bouyer 		*irqp = I386_PCI_INTERRUPT_LINE_NO_CONNECTION;
    152  1.2.4.2  bouyer 	else
    153  1.2.4.2  bouyer 		*irqp = reg & SIS85C503_CFG_PIRQ_INTR_MASK;
    154  1.2.4.2  bouyer 
    155  1.2.4.2  bouyer 	return (0);
    156  1.2.4.2  bouyer }
    157  1.2.4.2  bouyer 
    158  1.2.4.2  bouyer int
    159  1.2.4.2  bouyer sis85c503_set_intr(v, clink, irq)
    160  1.2.4.2  bouyer 	pciintr_icu_handle_t v;
    161  1.2.4.2  bouyer 	int clink, irq;
    162  1.2.4.2  bouyer {
    163  1.2.4.2  bouyer 	struct piix_handle *ph = v;
    164  1.2.4.2  bouyer 	int shift;
    165  1.2.4.2  bouyer 	pcireg_t reg;
    166  1.2.4.2  bouyer 
    167  1.2.4.2  bouyer 	if (SIS85C503_LEGAL_LINK(clink) == 0 || SIS85C503_LEGAL_IRQ(irq) == 0)
    168  1.2.4.2  bouyer 		return (1);
    169  1.2.4.2  bouyer 
    170  1.2.4.2  bouyer 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag,
    171  1.2.4.2  bouyer 	    SIS85C503_CFG_PIRQ_REGOFS(clink));
    172  1.2.4.2  bouyer 	shift = SIS85C503_CFG_PIRQ_SHIFT(clink);
    173  1.2.4.2  bouyer 	reg &= ~((SIS85C503_CFG_PIRQ_ROUTE_DISABLE |
    174  1.2.4.2  bouyer 	    SIS85C503_CFG_PIRQ_INTR_MASK) << shift);
    175  1.2.4.2  bouyer 	reg |= (irq << shift);
    176  1.2.4.2  bouyer 	pci_conf_write(ph->ph_pc, ph->ph_tag, SIS85C503_CFG_PIRQ_REGOFS(clink),
    177  1.2.4.2  bouyer 	    reg);
    178  1.2.4.2  bouyer 
    179  1.2.4.2  bouyer 	return (0);
    180  1.2.4.2  bouyer }
    181