Home | History | Annotate | Line # | Download | only in pci
pci_1000a.c revision 1.1
      1  1.1  ross /* $NetBSD: pci_1000a.c,v 1.1 1998/06/24 01:41:16 ross Exp $ */
      2  1.1  ross 
      3  1.1  ross /*
      4  1.1  ross  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.1  ross  * All rights reserved.
      6  1.1  ross  *
      7  1.1  ross  * This code is based on pci_kn20aa.c, written by Chris G. Demetriou at
      8  1.1  ross  * Carnegie-Mellon University. Platform support for Noritake, Pintake, and
      9  1.1  ross  * Corelle by Ross Harvey with copyright assignment by permission of Avalon
     10  1.1  ross  * Computer Systems, Inc.
     11  1.1  ross  *
     12  1.1  ross  * Redistribution and use in source and binary forms, with or without
     13  1.1  ross  * modification, are permitted provided that the following conditions
     14  1.1  ross  * are met:
     15  1.1  ross  * 1. Redistributions of source code must retain the above copyright
     16  1.1  ross  *    notice, this list of conditions and the following disclaimer.
     17  1.1  ross  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.1  ross  *    notice, this list of conditions and the following disclaimer in the
     19  1.1  ross  *    documentation and/or other materials provided with the distribution.
     20  1.1  ross  * 3. All advertising materials mentioning features or use of this software
     21  1.1  ross  *    must display the following acknowledgement:
     22  1.1  ross  *	This product includes software developed by the NetBSD
     23  1.1  ross  *	Foundation, Inc. and its contributors.
     24  1.1  ross  * 4. Neither the name of The NetBSD Foundation nor the names of its
     25  1.1  ross  *    contributors may be used to endorse or promote products derived
     26  1.1  ross  *    from this software without specific prior written permission.
     27  1.1  ross  *
     28  1.1  ross  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     29  1.1  ross  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     30  1.1  ross  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     31  1.1  ross  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     32  1.1  ross  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     33  1.1  ross  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     34  1.1  ross  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     35  1.1  ross  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     36  1.1  ross  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     37  1.1  ross  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38  1.1  ross  * POSSIBILITY OF SUCH DAMAGE.
     39  1.1  ross  */
     40  1.1  ross 
     41  1.1  ross /*
     42  1.1  ross  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     43  1.1  ross  * All rights reserved.
     44  1.1  ross  *
     45  1.1  ross  * Author: Chris G. Demetriou
     46  1.1  ross  *
     47  1.1  ross  * Permission to use, copy, modify and distribute this software and
     48  1.1  ross  * its documentation is hereby granted, provided that both the copyright
     49  1.1  ross  * notice and this permission notice appear in all copies of the
     50  1.1  ross  * software, derivative works or modified versions, and any portions
     51  1.1  ross  * thereof, and that both notices appear in supporting documentation.
     52  1.1  ross  *
     53  1.1  ross  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     54  1.1  ross  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     55  1.1  ross  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     56  1.1  ross  *
     57  1.1  ross  * Carnegie Mellon requests users of this software to return to
     58  1.1  ross  *
     59  1.1  ross  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     60  1.1  ross  *  School of Computer Science
     61  1.1  ross  *  Carnegie Mellon University
     62  1.1  ross  *  Pittsburgh PA 15213-3890
     63  1.1  ross  *
     64  1.1  ross  * any improvements or extensions that they make and grant Carnegie the
     65  1.1  ross  * rights to redistribute these changes.
     66  1.1  ross  */
     67  1.1  ross 
     68  1.1  ross #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     69  1.1  ross 
     70  1.1  ross __KERNEL_RCSID(0, "$NetBSD: pci_1000a.c,v 1.1 1998/06/24 01:41:16 ross Exp $");
     71  1.1  ross 
     72  1.1  ross #include <sys/types.h>
     73  1.1  ross #include <sys/param.h>
     74  1.1  ross #include <sys/time.h>
     75  1.1  ross #include <sys/systm.h>
     76  1.1  ross #include <sys/errno.h>
     77  1.1  ross #include <sys/malloc.h>
     78  1.1  ross #include <sys/device.h>
     79  1.1  ross #include <sys/syslog.h>
     80  1.1  ross 
     81  1.1  ross #include <vm/vm.h>
     82  1.1  ross 
     83  1.1  ross #include <machine/autoconf.h>
     84  1.1  ross 
     85  1.1  ross #include <dev/pci/pcireg.h>
     86  1.1  ross #include <dev/pci/pcivar.h>
     87  1.1  ross 
     88  1.1  ross #include <alpha/pci/pci_1000a.h>
     89  1.1  ross 
     90  1.1  ross #ifndef EVCNT_COUNTERS
     91  1.1  ross #include <machine/intrcnt.h>
     92  1.1  ross #endif
     93  1.1  ross 
     94  1.1  ross #include "sio.h"
     95  1.1  ross #if NSIO
     96  1.1  ross #include <alpha/pci/siovar.h>
     97  1.1  ross #endif
     98  1.1  ross 
     99  1.1  ross #define IMR2IRQ(bn) ((bn) - 1)
    100  1.1  ross #define IRQ2IMR(irq) ((irq) + 1)
    101  1.1  ross 
    102  1.1  ross static bus_space_tag_t mystery_icu_iot;
    103  1.1  ross static bus_space_handle_t mystery_icu_ioh[2];
    104  1.1  ross 
    105  1.1  ross int	dec_1000a_intr_map __P((void *, pcitag_t, int, int,
    106  1.1  ross 	    pci_intr_handle_t *));
    107  1.1  ross const char *dec_1000a_intr_string __P((void *, pci_intr_handle_t));
    108  1.1  ross void	*dec_1000a_intr_establish __P((void *, pci_intr_handle_t,
    109  1.1  ross 	    int, int (*func)(void *), void *));
    110  1.1  ross void	dec_1000a_intr_disestablish __P((void *, void *));
    111  1.1  ross 
    112  1.1  ross #define	DEC_1000A_MAX_IRQ	32
    113  1.1  ross #define	PCI_STRAY_MAX	5
    114  1.1  ross 
    115  1.1  ross struct alpha_shared_intr *dec_1000a_pci_intr;
    116  1.1  ross #ifdef EVCNT_COUNTERS
    117  1.1  ross struct evcnt dec_1000a_intr_evcnt;
    118  1.1  ross #endif
    119  1.1  ross 
    120  1.1  ross static void dec_1000a_iointr __P((void *framep, unsigned long vec));
    121  1.1  ross static void dec_1000a_enable_intr __P((int irq));
    122  1.1  ross static void dec_1000a_disable_intr __P((int irq));
    123  1.1  ross static void pci_1000a_imi __P((void));
    124  1.1  ross static pci_chipset_tag_t pc_tag;
    125  1.1  ross 
    126  1.1  ross int	ross_tmp_didr;			/* XXX XXX XXX */
    127  1.1  ross int	ross_tmp_didv;			/* XXX XXX XXX */
    128  1.1  ross 
    129  1.1  ross void
    130  1.1  ross pci_1000a_pickintr(core, iot, memt, pc)
    131  1.1  ross 	void *core;
    132  1.1  ross 	bus_space_tag_t iot, memt;
    133  1.1  ross 	pci_chipset_tag_t pc;
    134  1.1  ross {
    135  1.1  ross 	int i;
    136  1.1  ross 	mystery_icu_iot = iot;
    137  1.1  ross 
    138  1.1  ross 	pc_tag = pc;
    139  1.1  ross 	if (bus_space_map(iot, 0x54a, 2, 0, mystery_icu_ioh + 0)
    140  1.1  ross 	||  bus_space_map(iot, 0x54c, 2, 0, mystery_icu_ioh + 1))
    141  1.1  ross 		panic("pci_1000a_pickintr");
    142  1.1  ross         pc->pc_intr_v = core;
    143  1.1  ross         pc->pc_intr_map = dec_1000a_intr_map;
    144  1.1  ross         pc->pc_intr_string = dec_1000a_intr_string;
    145  1.1  ross         pc->pc_intr_establish = dec_1000a_intr_establish;
    146  1.1  ross         pc->pc_intr_disestablish = dec_1000a_intr_disestablish;
    147  1.1  ross 
    148  1.1  ross 	pc->pc_pciide_compat_intr_establish = NULL;
    149  1.1  ross 
    150  1.1  ross 	dec_1000a_pci_intr = alpha_shared_intr_alloc(DEC_1000A_MAX_IRQ);
    151  1.1  ross 	for (i = 0; i < DEC_1000A_MAX_IRQ; i++)
    152  1.1  ross 		alpha_shared_intr_set_maxstrays(dec_1000a_pci_intr, i,
    153  1.1  ross 		    PCI_STRAY_MAX);
    154  1.1  ross 
    155  1.1  ross 	pci_1000a_imi();
    156  1.1  ross #if NSIO
    157  1.1  ross 	sio_intr_setup(pc, iot);
    158  1.1  ross #endif
    159  1.1  ross 	set_iointr(dec_1000a_iointr);
    160  1.1  ross }
    161  1.1  ross 
    162  1.1  ross int
    163  1.1  ross dec_1000a_intr_map(ccv, bustag, buspin, line, ihp)
    164  1.1  ross         void *ccv;
    165  1.1  ross         pcitag_t bustag;
    166  1.1  ross         int buspin, line;
    167  1.1  ross         pci_intr_handle_t *ihp;
    168  1.1  ross {
    169  1.1  ross 	int imrbit, device;
    170  1.1  ross 	/*
    171  1.1  ross 	 * Get bit number in mystery ICU imr
    172  1.1  ross 	 */
    173  1.1  ross 	static const signed char imrmap[][4] = {
    174  1.1  ross #		define	IRQSPLIT(o) { (o), (o)+1, (o)+16, (o)+16+1 }
    175  1.1  ross #		define	IRQNONE		 { 0, 0, 0, 0 }
    176  1.1  ross 		/*  0  */ { 1, 0, 0, 0 },	/* Noritake and Pintake */
    177  1.1  ross 		/*  1  */ IRQSPLIT(8),
    178  1.1  ross 		/*  2  */ IRQSPLIT(10),
    179  1.1  ross 		/*  3  */ IRQSPLIT(12),
    180  1.1  ross 		/*  4  */ IRQSPLIT(14),
    181  1.1  ross 		/*  5  */ { 1, 0, 0, 0 },	/* Corelle */
    182  1.1  ross 		/*  6  */ { 10, 0, 0, 0 },	/* Corelle */
    183  1.1  ross 		/*  7  */ IRQNONE,
    184  1.1  ross 		/*  8  */ IRQNONE,
    185  1.1  ross 		/*  9  */ IRQNONE,
    186  1.1  ross 		/* 10  */ IRQNONE,
    187  1.1  ross 		/* 11  */ IRQSPLIT(2),
    188  1.1  ross 		/* 12  */ IRQSPLIT(4),
    189  1.1  ross 		/* 13  */ IRQSPLIT(6),
    190  1.1  ross 		/* 14  */ IRQSPLIT(8)		/* Corelle */
    191  1.1  ross 	};
    192  1.1  ross 
    193  1.1  ross 	if (buspin == 0)	/* No IRQ used. */
    194  1.1  ross 		return 1;
    195  1.1  ross 	if (!(1 <= buspin && buspin <= 4))
    196  1.1  ross 		goto bad;
    197  1.1  ross 	alpha_pci_decompose_tag(pc_tag, bustag, NULL, &device, NULL);
    198  1.1  ross 	if (0 <= device && device < sizeof imrmap / sizeof imrmap[0]) {
    199  1.1  ross 		imrbit = imrmap[device][buspin - 1];
    200  1.1  ross 		if (imrbit) {
    201  1.1  ross 			*ihp = IMR2IRQ(imrbit);
    202  1.1  ross 			return 0;
    203  1.1  ross 		}
    204  1.1  ross 	}
    205  1.1  ross bad:	printf("dec_1000a_intr_map: can't map dev %d pin %d\n", device, buspin);
    206  1.1  ross 	return 1;
    207  1.1  ross }
    208  1.1  ross 
    209  1.1  ross const char *
    210  1.1  ross dec_1000a_intr_string(ccv, ih)
    211  1.1  ross 	void *ccv;
    212  1.1  ross 	pci_intr_handle_t ih;
    213  1.1  ross {
    214  1.1  ross 	static const char irqmsg_fmt[] = "dec_1000a irq %ld";
    215  1.1  ross         static char irqstr[sizeof irqmsg_fmt];
    216  1.1  ross 
    217  1.1  ross 
    218  1.1  ross         if (ih > DEC_1000A_MAX_IRQ)
    219  1.1  ross                 panic("dec_1000a_intr_string: bogus dec_1000a IRQ 0x%x\n", ih);
    220  1.1  ross 
    221  1.1  ross         sprintf(irqstr, irqmsg_fmt, ih);
    222  1.1  ross         return (irqstr);
    223  1.1  ross }
    224  1.1  ross 
    225  1.1  ross void *
    226  1.1  ross dec_1000a_intr_establish(ccv, ih, level, func, arg)
    227  1.1  ross         void *ccv, *arg;
    228  1.1  ross         pci_intr_handle_t ih;
    229  1.1  ross         int level;
    230  1.1  ross         int (*func) __P((void *));
    231  1.1  ross {
    232  1.1  ross 	void *cookie;
    233  1.1  ross 
    234  1.1  ross         if (ih > DEC_1000A_MAX_IRQ)
    235  1.1  ross                 panic("dec_1000a_intr_establish: IRQ too high, 0x%x\n", ih);
    236  1.1  ross 
    237  1.1  ross 	cookie = alpha_shared_intr_establish(dec_1000a_pci_intr, ih, IST_LEVEL,
    238  1.1  ross 	    level, func, arg, "dec_1000a irq");
    239  1.1  ross 
    240  1.1  ross 	if (cookie != NULL &&
    241  1.1  ross 	    alpha_shared_intr_isactive(dec_1000a_pci_intr, ih))
    242  1.1  ross 		dec_1000a_enable_intr(ih);
    243  1.1  ross 	return (cookie);
    244  1.1  ross }
    245  1.1  ross 
    246  1.1  ross void
    247  1.1  ross dec_1000a_intr_disestablish(ccv, cookie)
    248  1.1  ross         void *ccv, *cookie;
    249  1.1  ross {
    250  1.1  ross 	panic("dec_1000a_intr_disestablish not implemented"); /* XXX */
    251  1.1  ross }
    252  1.1  ross 
    253  1.1  ross static void
    254  1.1  ross dec_1000a_iointr(framep, vec)
    255  1.1  ross 	void *framep;
    256  1.1  ross 	unsigned long vec;
    257  1.1  ross {
    258  1.1  ross 	int irq;
    259  1.1  ross 
    260  1.1  ross if (ross_tmp_didv)
    261  1.1  ross printf("\tvec 0x%x\n", vec);
    262  1.1  ross 	if (vec >= 0x900) {
    263  1.1  ross 		if (vec >= 0x900 + (DEC_1000A_MAX_IRQ << 4))
    264  1.1  ross 			panic("dec_1000a_iointr: vec 0x%x out of range\n", vec);
    265  1.1  ross 		irq = (vec - 0x900) >> 4;
    266  1.1  ross #ifdef EVCNT_COUNTERS
    267  1.1  ross 		dec_1000a_intr_evcnt.ev_count++;
    268  1.1  ross #else
    269  1.1  ross 		if (DEC_1000A_MAX_IRQ != INTRCNT_DEC_1000A_IRQ_LEN)
    270  1.1  ross 			panic("dec_1000a interrupt counter sizes inconsistent");
    271  1.1  ross 		intrcnt[INTRCNT_DEC_1000A_IRQ + irq]++;
    272  1.1  ross #endif
    273  1.1  ross 
    274  1.1  ross 		if (!alpha_shared_intr_dispatch(dec_1000a_pci_intr, irq)) {
    275  1.1  ross 			alpha_shared_intr_stray(dec_1000a_pci_intr, irq,
    276  1.1  ross 			    "dec_1000a irq");
    277  1.1  ross 			if (dec_1000a_pci_intr[irq].intr_nstrays ==
    278  1.1  ross 			    dec_1000a_pci_intr[irq].intr_maxstrays)
    279  1.1  ross 				dec_1000a_disable_intr(irq);
    280  1.1  ross 		}
    281  1.1  ross 		return;
    282  1.1  ross 	}
    283  1.1  ross #if NSIO
    284  1.1  ross 	if (vec >= 0x800) {
    285  1.1  ross 		sio_iointr(framep, vec);
    286  1.1  ross 		return;
    287  1.1  ross 	}
    288  1.1  ross #endif
    289  1.1  ross 	panic("dec_1000a_iointr: weird vec 0x%x\n", vec);
    290  1.1  ross }
    291  1.1  ross 
    292  1.1  ross /*
    293  1.1  ross  * Read and write the mystery ICU IMR registers
    294  1.1  ross  */
    295  1.1  ross 
    296  1.1  ross #define	IR(h) bus_space_read_2(mystery_icu_iot, mystery_icu_ioh[h], 0)
    297  1.1  ross #define	IW(h, v) bus_space_write_2(mystery_icu_iot, mystery_icu_ioh[h], 0, (v))
    298  1.1  ross 
    299  1.1  ross /*
    300  1.1  ross  * Enable and disable interrupts at the ICU level
    301  1.1  ross  */
    302  1.1  ross 
    303  1.1  ross static void
    304  1.1  ross dec_1000a_enable_intr(irq)
    305  1.1  ross 	int irq;
    306  1.1  ross {
    307  1.1  ross 	int imrval = IRQ2IMR(irq);
    308  1.1  ross 	int i = imrval >= 16;
    309  1.1  ross 
    310  1.1  ross if (ross_tmp_didr) {
    311  1.1  ross IW(0, ~0);
    312  1.1  ross IW(1, ~0);
    313  1.1  ross return;
    314  1.1  ross }
    315  1.1  ross 	IW(i, IR(i) | 1 << (imrval & 0xf));
    316  1.1  ross }
    317  1.1  ross 
    318  1.1  ross static void
    319  1.1  ross dec_1000a_disable_intr(irq)
    320  1.1  ross 	int irq;
    321  1.1  ross {
    322  1.1  ross 	int imrval = IRQ2IMR(irq);
    323  1.1  ross 	int i = imrval >= 16;
    324  1.1  ross 
    325  1.1  ross 	IW(i, IR(i) & ~(1 << (imrval & 0xf)));
    326  1.1  ross }
    327  1.1  ross /*
    328  1.1  ross  * Initialize mystery ICU
    329  1.1  ross  */
    330  1.1  ross static void
    331  1.1  ross pci_1000a_imi()
    332  1.1  ross {
    333  1.1  ross 	IW(0, IR(0) & 1);
    334  1.1  ross 	IW(1, IR(0) & 3);
    335  1.1  ross }
    336