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