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