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