Home | History | Annotate | Line # | Download | only in pci
ali1543.c revision 1.3.2.2
      1  1.3.2.2  lukem /*	$NetBSD: ali1543.c,v 1.3.2.2 2001/11/15 07:03:34 lukem Exp $	*/
      2  1.3.2.2  lukem 
      3  1.3.2.2  lukem /*
      4  1.3.2.2  lukem  * Copyright (c) 2001
      5  1.3.2.2  lukem  *       HAYAKAWA Koichi.  All rights reserved.
      6  1.3.2.2  lukem  *
      7  1.3.2.2  lukem  * Redistribution and use in source and binary forms, with or without
      8  1.3.2.2  lukem  * modification, are permitted provided that the following conditions
      9  1.3.2.2  lukem  * are met:
     10  1.3.2.2  lukem  * 1. Redistributions of source code must retain the above copyright
     11  1.3.2.2  lukem  *    notice, this list of conditions and the following disclaimer.
     12  1.3.2.2  lukem  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.3.2.2  lukem  *    notice, this list of conditions and the following disclaimer in the
     14  1.3.2.2  lukem  *    documentation and/or other materials provided with the distribution.
     15  1.3.2.2  lukem  * 3. The name of the author may not be used to endorse or promote products
     16  1.3.2.2  lukem  *    derived from this software without specific prior written permission.
     17  1.3.2.2  lukem  *
     18  1.3.2.2  lukem  *
     19  1.3.2.2  lukem  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  1.3.2.2  lukem  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     21  1.3.2.2  lukem  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     22  1.3.2.2  lukem  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     23  1.3.2.2  lukem  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24  1.3.2.2  lukem  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25  1.3.2.2  lukem  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.3.2.2  lukem  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     27  1.3.2.2  lukem  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     28  1.3.2.2  lukem  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.3.2.2  lukem  * POSSIBILITY OF SUCH DAMAGE.
     30  1.3.2.2  lukem  */
     31  1.3.2.2  lukem 
     32  1.3.2.2  lukem /*-
     33  1.3.2.2  lukem  * Copyright (c) 1999 The NetBSD Foundation, Inc.
     34  1.3.2.2  lukem  * All rights reserved.
     35  1.3.2.2  lukem  *
     36  1.3.2.2  lukem  * This code is derived from software contributed to The NetBSD Foundation
     37  1.3.2.2  lukem  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     38  1.3.2.2  lukem  * NASA Ames Research Center.
     39  1.3.2.2  lukem  *
     40  1.3.2.2  lukem  * Redistribution and use in source and binary forms, with or without
     41  1.3.2.2  lukem  * modification, are permitted provided that the following conditions
     42  1.3.2.2  lukem  * are met:
     43  1.3.2.2  lukem  * 1. Redistributions of source code must retain the above copyright
     44  1.3.2.2  lukem  *    notice, this list of conditions and the following disclaimer.
     45  1.3.2.2  lukem  * 2. Redistributions in binary form must reproduce the above copyright
     46  1.3.2.2  lukem  *    notice, this list of conditions and the following disclaimer in the
     47  1.3.2.2  lukem  *    documentation and/or other materials provided with the distribution.
     48  1.3.2.2  lukem  * 3. All advertising materials mentioning features or use of this software
     49  1.3.2.2  lukem  *    must display the following acknowledgement:
     50  1.3.2.2  lukem  *	This product includes software developed by the NetBSD
     51  1.3.2.2  lukem  *	Foundation, Inc. and its contributors.
     52  1.3.2.2  lukem  * 4. Neither the name of The NetBSD Foundation nor the names of its
     53  1.3.2.2  lukem  *    contributors may be used to endorse or promote products derived
     54  1.3.2.2  lukem  *    from this software without specific prior written permission.
     55  1.3.2.2  lukem  *
     56  1.3.2.2  lukem  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     57  1.3.2.2  lukem  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     58  1.3.2.2  lukem  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     59  1.3.2.2  lukem  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     60  1.3.2.2  lukem  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     61  1.3.2.2  lukem  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     62  1.3.2.2  lukem  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     63  1.3.2.2  lukem  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     64  1.3.2.2  lukem  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     65  1.3.2.2  lukem  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     66  1.3.2.2  lukem  * POSSIBILITY OF SUCH DAMAGE.
     67  1.3.2.2  lukem  */
     68  1.3.2.2  lukem 
     69  1.3.2.2  lukem /*
     70  1.3.2.2  lukem  * Copyright (c) 1999, by UCHIYAMA Yasushi
     71  1.3.2.2  lukem  * All rights reserved.
     72  1.3.2.2  lukem  *
     73  1.3.2.2  lukem  * Redistribution and use in source and binary forms, with or without
     74  1.3.2.2  lukem  * modification, are permitted provided that the following conditions
     75  1.3.2.2  lukem  * are met:
     76  1.3.2.2  lukem  * 1. Redistributions of source code must retain the above copyright
     77  1.3.2.2  lukem  *    notice, this list of conditions and the following disclaimer.
     78  1.3.2.2  lukem  * 2. The name of the developer may NOT be used to endorse or promote products
     79  1.3.2.2  lukem  *    derived from this software without specific prior written permission.
     80  1.3.2.2  lukem  *
     81  1.3.2.2  lukem  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     82  1.3.2.2  lukem  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     83  1.3.2.2  lukem  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     84  1.3.2.2  lukem  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     85  1.3.2.2  lukem  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     86  1.3.2.2  lukem  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     87  1.3.2.2  lukem  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     88  1.3.2.2  lukem  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     89  1.3.2.2  lukem  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     90  1.3.2.2  lukem  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     91  1.3.2.2  lukem  * SUCH DAMAGE.
     92  1.3.2.2  lukem  */
     93  1.3.2.2  lukem 
     94  1.3.2.2  lukem /* HAYAKAWA Koichi wrote ALi 1543 PCI ICU code basing on VIA82C586 driver */
     95  1.3.2.2  lukem 
     96  1.3.2.2  lukem #include <sys/cdefs.h>
     97  1.3.2.2  lukem __KERNEL_RCSID(0, "$NetBSD: ali1543.c,v 1.3.2.2 2001/11/15 07:03:34 lukem Exp $");
     98  1.3.2.2  lukem 
     99  1.3.2.2  lukem #include <sys/param.h>
    100  1.3.2.2  lukem #include <sys/systm.h>
    101  1.3.2.2  lukem #include <sys/errno.h>
    102  1.3.2.2  lukem #include <sys/device.h>
    103  1.3.2.2  lukem #include <sys/malloc.h>
    104  1.3.2.2  lukem #include <sys/proc.h>
    105  1.3.2.2  lukem 
    106  1.3.2.2  lukem #include <machine/intr.h>
    107  1.3.2.2  lukem #include <machine/bus.h>
    108  1.3.2.2  lukem 
    109  1.3.2.2  lukem #include <dev/pci/pcivar.h>
    110  1.3.2.2  lukem #include <dev/pci/pcireg.h>
    111  1.3.2.2  lukem #include <dev/pci/pcidevs.h>
    112  1.3.2.2  lukem 
    113  1.3.2.2  lukem #include <i386/pci/pci_intr_fixup.h>
    114  1.3.2.2  lukem #include <i386/pci/piixvar.h>
    115  1.3.2.2  lukem 
    116  1.3.2.2  lukem 
    117  1.3.2.2  lukem int ali1543_getclink (pciintr_icu_handle_t, int, int *);
    118  1.3.2.2  lukem int ali1543_get_intr (pciintr_icu_handle_t, int, int *);
    119  1.3.2.2  lukem int ali1543_set_intr (pciintr_icu_handle_t, int, int);
    120  1.3.2.2  lukem 
    121  1.3.2.2  lukem 
    122  1.3.2.2  lukem const struct pciintr_icu ali1543_icu = {
    123  1.3.2.2  lukem 	ali1543_getclink,
    124  1.3.2.2  lukem 	ali1543_get_intr,
    125  1.3.2.2  lukem 	ali1543_set_intr,
    126  1.3.2.2  lukem 	piix_get_trigger,
    127  1.3.2.2  lukem 	piix_set_trigger,
    128  1.3.2.2  lukem };
    129  1.3.2.2  lukem 
    130  1.3.2.2  lukem 
    131  1.3.2.2  lukem /*
    132  1.3.2.2  lukem  * Linux source code (linux/arch/i386/kernel/pci-irq.c) says that the
    133  1.3.2.2  lukem  * irq order of ALi PCI ICU is shuffled.
    134  1.3.2.2  lukem  */
    135  1.3.2.2  lukem const static int ali1543_intr_shuffle_get[16] = {
    136  1.3.2.2  lukem 	0, 9, 3, 10, 4, 5, 7, 6, 1, 11, 0, 12, 0, 14, 0, 15
    137  1.3.2.2  lukem };
    138  1.3.2.2  lukem const static int ali1543_intr_shuffle_set[16] = {
    139  1.3.2.2  lukem 	0, 8, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15
    140  1.3.2.2  lukem };
    141  1.3.2.2  lukem 
    142  1.3.2.2  lukem #define ALI1543_IRQ_MASK		0xdefa
    143  1.3.2.2  lukem 
    144  1.3.2.2  lukem #define ALI1543_LEGAL_LINK(link)	(((link) >= 0) && ((link) <= 7))
    145  1.3.2.2  lukem #define ALI1543_LEGAL_IRQ(irq)		((1 << (irq)) & ALI1543_IRQ_MASK)
    146  1.3.2.2  lukem 
    147  1.3.2.2  lukem #define ALI1543_INTR_CFG_REG		0x48
    148  1.3.2.2  lukem 
    149  1.3.2.2  lukem #define ALI1543_INTR_PIRQA_SHIFT	0
    150  1.3.2.2  lukem #define ALI1543_INTR_PIRQA_MASK		0x0000000f
    151  1.3.2.2  lukem #define ALI1543_INTR_PIRQB_SHIFT	4
    152  1.3.2.2  lukem #define ALI1543_INTR_PIRQB_MASK		0x000000f0
    153  1.3.2.2  lukem #define ALI1543_INTR_PIRQC_SHIFT	8
    154  1.3.2.2  lukem #define ALI1543_INTR_PIRQC_MASK		0x00000f00
    155  1.3.2.2  lukem #define ALI1543_INTR_PIRQD_SHIFT	12
    156  1.3.2.2  lukem #define ALI1543_INTR_PIRQD_MASK		0x0000f000
    157  1.3.2.2  lukem 
    158  1.3.2.2  lukem #define ALI1543_INTR_PIRQ_SHIFT(clink)	((clink)*4)
    159  1.3.2.2  lukem #define ALI1543_INTR_PIRQ_IRQ(reg, clink)				\
    160  1.3.2.2  lukem 	(((reg) >> ((clink)*4)) & 0x0f)
    161  1.3.2.2  lukem #define ALI1543_PIRQ(reg, clink)					\
    162  1.3.2.2  lukem 	ali1543_intr_shuffle_get[ALI1543_INTR_PIRQ_IRQ((reg), (clink))]
    163  1.3.2.2  lukem 
    164  1.3.2.2  lukem 
    165  1.3.2.2  lukem int
    166  1.3.2.2  lukem ali1543_init(pci_chipset_tag_t pc, bus_space_tag_t iot, pcitag_t tag,
    167  1.3.2.2  lukem     pciintr_icu_tag_t *ptagp, pciintr_icu_handle_t *phandp)
    168  1.3.2.2  lukem {
    169  1.3.2.2  lukem 
    170  1.3.2.2  lukem 	if (piix_init(pc, iot, tag, ptagp, phandp) == 0) {
    171  1.3.2.2  lukem 		*ptagp = &ali1543_icu;
    172  1.3.2.2  lukem 
    173  1.3.2.2  lukem 		return (0);
    174  1.3.2.2  lukem 	}
    175  1.3.2.2  lukem 
    176  1.3.2.2  lukem 	return (1);
    177  1.3.2.2  lukem }
    178  1.3.2.2  lukem 
    179  1.3.2.2  lukem int
    180  1.3.2.2  lukem ali1543_getclink(pciintr_icu_handle_t v, int link, int *clinkp)
    181  1.3.2.2  lukem {
    182  1.3.2.2  lukem 
    183  1.3.2.2  lukem 	if (ALI1543_LEGAL_LINK(link - 1)) {
    184  1.3.2.2  lukem 		*clinkp = link - 1;
    185  1.3.2.2  lukem 		return (0);
    186  1.3.2.2  lukem 	}
    187  1.3.2.2  lukem 
    188  1.3.2.2  lukem 	return (1);
    189  1.3.2.2  lukem }
    190  1.3.2.2  lukem 
    191  1.3.2.2  lukem int
    192  1.3.2.2  lukem ali1543_get_intr(pciintr_icu_handle_t v, int clink, int *irqp)
    193  1.3.2.2  lukem {
    194  1.3.2.2  lukem 	struct piix_handle *ph = v;
    195  1.3.2.2  lukem 	pcireg_t reg;
    196  1.3.2.2  lukem 	int val;
    197  1.3.2.2  lukem 
    198  1.3.2.2  lukem 	if (ALI1543_LEGAL_LINK(clink) == 0)
    199  1.3.2.2  lukem 		return (1);
    200  1.3.2.2  lukem 
    201  1.3.2.2  lukem 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag, ALI1543_INTR_CFG_REG);
    202  1.3.2.2  lukem #ifdef DEBUG_1543
    203  1.3.2.2  lukem 	printf("ali1543: PIRQ reg 0x%08x\n", reg); /* XXX debug */
    204  1.3.2.2  lukem #endif /* DEBUG_1543 */
    205  1.3.2.2  lukem 	val = ALI1543_PIRQ(reg, clink);
    206  1.3.2.2  lukem 	*irqp = (val == 0) ?
    207  1.3.2.2  lukem 	    I386_PCI_INTERRUPT_LINE_NO_CONNECTION : val;
    208  1.3.2.2  lukem 
    209  1.3.2.2  lukem 	return (0);
    210  1.3.2.2  lukem }
    211  1.3.2.2  lukem 
    212  1.3.2.2  lukem int
    213  1.3.2.2  lukem ali1543_set_intr(pciintr_icu_handle_t v, int clink, int irq)
    214  1.3.2.2  lukem {
    215  1.3.2.2  lukem 	struct piix_handle *ph = v;
    216  1.3.2.2  lukem 	int shift, val;
    217  1.3.2.2  lukem 	pcireg_t reg;
    218  1.3.2.2  lukem 
    219  1.3.2.2  lukem 	if (ALI1543_LEGAL_LINK(clink) == 0 || ALI1543_LEGAL_IRQ(irq) == 0)
    220  1.3.2.2  lukem 		return (1);
    221  1.3.2.2  lukem 
    222  1.3.2.2  lukem 	reg = pci_conf_read(ph->ph_pc, ph->ph_tag, ALI1543_INTR_CFG_REG);
    223  1.3.2.2  lukem 	ali1543_get_intr(v, clink, &val);
    224  1.3.2.2  lukem 	shift = ALI1543_INTR_PIRQ_SHIFT(clink);
    225  1.3.2.2  lukem 	reg &= ~(0x0f << shift);
    226  1.3.2.2  lukem 	reg |= (ali1543_intr_shuffle_set[irq] << shift);
    227  1.3.2.2  lukem 	pci_conf_write(ph->ph_pc, ph->ph_tag, ALI1543_INTR_CFG_REG, reg);
    228  1.3.2.2  lukem 	if (ali1543_get_intr(v, clink, &val) != 0 || val != irq)
    229  1.3.2.2  lukem 		return (1);
    230  1.3.2.2  lukem 
    231  1.3.2.2  lukem 	return (0);
    232  1.3.2.2  lukem }
    233