Home | History | Annotate | Line # | Download | only in pci
pci_kn300.c revision 1.32.4.2
      1  1.32.4.1     rmind /* $NetBSD: pci_kn300.c,v 1.32.4.2 2011/04/21 01:40:47 rmind Exp $ */
      2       1.1    mjacob 
      3       1.1    mjacob /*
      4       1.1    mjacob  * Copyright (c) 1998 by Matthew Jacob
      5       1.1    mjacob  * NASA AMES Research Center.
      6       1.1    mjacob  * All rights reserved.
      7       1.1    mjacob  *
      8       1.1    mjacob  * Redistribution and use in source and binary forms, with or without
      9       1.1    mjacob  * modification, are permitted provided that the following conditions
     10       1.1    mjacob  * are met:
     11       1.1    mjacob  * 1. Redistributions of source code must retain the above copyright
     12       1.1    mjacob  *    notice immediately at the beginning of the file, without modification,
     13       1.1    mjacob  *    this list of conditions, and the following disclaimer.
     14       1.1    mjacob  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1    mjacob  *    notice, this list of conditions and the following disclaimer in the
     16       1.1    mjacob  *    documentation and/or other materials provided with the distribution.
     17       1.1    mjacob  * 3. The name of the author may not be used to endorse or promote products
     18       1.1    mjacob  *    derived from this software without specific prior written permission.
     19       1.1    mjacob  *
     20       1.1    mjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     21       1.1    mjacob  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22       1.1    mjacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23       1.1    mjacob  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     24       1.1    mjacob  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25       1.1    mjacob  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26       1.1    mjacob  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27       1.1    mjacob  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28       1.1    mjacob  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29       1.1    mjacob  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30       1.1    mjacob  * SUCH DAMAGE.
     31       1.1    mjacob  */
     32       1.1    mjacob 
     33       1.1    mjacob #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     34       1.1    mjacob 
     35  1.32.4.1     rmind __KERNEL_RCSID(0, "$NetBSD: pci_kn300.c,v 1.32.4.2 2011/04/21 01:40:47 rmind Exp $");
     36       1.1    mjacob 
     37       1.1    mjacob #include <sys/types.h>
     38       1.1    mjacob #include <sys/param.h>
     39       1.1    mjacob #include <sys/time.h>
     40       1.1    mjacob #include <sys/systm.h>
     41       1.1    mjacob #include <sys/errno.h>
     42       1.1    mjacob #include <sys/malloc.h>
     43       1.1    mjacob #include <sys/device.h>
     44       1.1    mjacob #include <sys/syslog.h>
     45       1.1    mjacob 
     46       1.1    mjacob #include <machine/autoconf.h>
     47       1.1    mjacob 
     48       1.1    mjacob #include <dev/pci/pcireg.h>
     49       1.1    mjacob #include <dev/pci/pcivar.h>
     50       1.1    mjacob 
     51       1.1    mjacob #include <alpha/mcbus/mcbusvar.h>
     52       1.1    mjacob #include <alpha/mcbus/mcbusreg.h>
     53       1.1    mjacob #include <alpha/pci/mcpciareg.h>
     54       1.1    mjacob #include <alpha/pci/mcpciavar.h>
     55       1.1    mjacob #include <alpha/pci/pci_kn300.h>
     56       1.1    mjacob 
     57       1.1    mjacob #include "sio.h"
     58      1.16   thorpej #if NSIO > 0 || NPCEB > 0
     59       1.1    mjacob #include <alpha/pci/siovar.h>
     60       1.1    mjacob #endif
     61       1.1    mjacob 
     62  1.32.4.2     rmind int	dec_kn300_intr_map(const struct pci_attach_args *,
     63      1.30       dsl 	    pci_intr_handle_t *);
     64      1.30       dsl const char *dec_kn300_intr_string(void *, pci_intr_handle_t);
     65      1.30       dsl const struct evcnt *dec_kn300_intr_evcnt(void *, pci_intr_handle_t);
     66      1.30       dsl void	*dec_kn300_intr_establish(void *, pci_intr_handle_t,
     67      1.30       dsl 	    int, int (*func)(void *), void *);
     68      1.30       dsl void	dec_kn300_intr_disestablish(void *, void *);
     69       1.1    mjacob 
     70       1.1    mjacob #define	KN300_PCEB_IRQ	16
     71       1.6    mjacob #define	NPIN		4
     72       1.1    mjacob 
     73      1.12   thorpej #define	NIRQ	(MAX_MC_BUS * MCPCIA_PER_MCBUS * MCPCIA_MAXSLOT * NPIN)
     74      1.12   thorpej static int savirqs[NIRQ];
     75       1.1    mjacob 
     76       1.6    mjacob static struct alpha_shared_intr *kn300_pci_intr;
     77       1.6    mjacob 
     78      1.13    mjacob static struct mcpcia_config *mcpcia_eisaccp = NULL;
     79      1.13    mjacob 
     80      1.30       dsl void	kn300_iointr(void *, unsigned long);
     81      1.30       dsl void	kn300_enable_intr(struct mcpcia_config *, int);
     82      1.30       dsl void	kn300_disable_intr(struct mcpcia_config *, int);
     83       1.1    mjacob 
     84       1.1    mjacob void
     85      1.31       dsl pci_kn300_pickintr(struct mcpcia_config *ccp, int first)
     86       1.1    mjacob {
     87      1.20   thorpej 	char *cp;
     88       1.1    mjacob 	pci_chipset_tag_t pc = &ccp->cc_pc;
     89       1.1    mjacob 
     90       1.1    mjacob 	if (first) {
     91       1.1    mjacob 		int g;
     92       1.6    mjacob 
     93      1.20   thorpej 		kn300_pci_intr = alpha_shared_intr_alloc(NIRQ, 16);
     94      1.12   thorpej 		for (g = 0; g < NIRQ; g++) {
     95      1.18    mjacob 			alpha_shared_intr_set_maxstrays(kn300_pci_intr, g, 25);
     96      1.20   thorpej 			cp = alpha_shared_intr_string(kn300_pci_intr, g);
     97      1.20   thorpej 			sprintf(cp, "irq %d", g);
     98      1.20   thorpej 			evcnt_attach_dynamic(alpha_shared_intr_evcnt(
     99      1.20   thorpej 			    kn300_pci_intr, g), EVCNT_TYPE_INTR, NULL,
    100      1.20   thorpej 			    "kn300", cp);
    101       1.6    mjacob 			savirqs[g] = (char) -1;
    102       1.1    mjacob 		}
    103       1.1    mjacob 	}
    104       1.1    mjacob 
    105       1.1    mjacob 	pc->pc_intr_v = ccp;
    106       1.1    mjacob 	pc->pc_intr_map = dec_kn300_intr_map;
    107       1.1    mjacob 	pc->pc_intr_string = dec_kn300_intr_string;
    108      1.19       cgd 	pc->pc_intr_evcnt = dec_kn300_intr_evcnt;
    109       1.1    mjacob 	pc->pc_intr_establish = dec_kn300_intr_establish;
    110       1.1    mjacob 	pc->pc_intr_disestablish = dec_kn300_intr_disestablish;
    111       1.3   thorpej 
    112       1.4    mjacob 	/* Not supported on KN300. */
    113       1.3   thorpej 	pc->pc_pciide_compat_intr_establish = NULL;
    114       1.1    mjacob 
    115      1.13    mjacob 	if (EISA_PRESENT(REGVAL(MCPCIA_PCI_REV(ccp)))) {
    116      1.13    mjacob 		mcpcia_eisaccp = ccp;
    117      1.16   thorpej #if NSIO > 0 || NPCEB > 0
    118      1.11   thorpej 		sio_intr_setup(pc, &ccp->cc_iot);
    119       1.1    mjacob 		kn300_enable_intr(ccp, KN300_PCEB_IRQ);
    120      1.13    mjacob #endif
    121       1.1    mjacob 	}
    122       1.1    mjacob }
    123       1.1    mjacob 
    124       1.1    mjacob int
    125  1.32.4.2     rmind dec_kn300_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    126       1.1    mjacob {
    127      1.22  sommerfe 	pcitag_t bustag = pa->pa_intrtag;
    128      1.22  sommerfe 	int buspin = pa->pa_intrpin;
    129      1.22  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
    130      1.22  sommerfe 	struct mcpcia_config *ccp = (struct mcpcia_config *)pc->pc_intr_v;
    131       1.1    mjacob 	int device;
    132      1.12   thorpej 	int mcpcia_irq;
    133       1.1    mjacob 
    134       1.5   thorpej 	if (buspin == 0) {
    135       1.5   thorpej 		/* No IRQ used. */
    136       1.5   thorpej 		return 1;
    137       1.5   thorpej 	}
    138       1.5   thorpej 	if (buspin > 4 || buspin < 0) {
    139       1.5   thorpej 		printf("dec_kn300_intr_map: bad interrupt pin %d\n", buspin);
    140       1.5   thorpej 		return 1;
    141       1.5   thorpej 	}
    142       1.1    mjacob 
    143      1.24   thorpej 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    144       1.1    mjacob 
    145      1.11   thorpej 	/*
    146      1.11   thorpej 	 * On MID 5 device 1 is the internal NCR 53c810.
    147      1.11   thorpej 	 */
    148      1.11   thorpej 	if (ccp->cc_mid == 5 && device == 1) {
    149      1.12   thorpej 		mcpcia_irq = 16;
    150       1.1    mjacob 	} else if (device >= 2 && device <= 5) {
    151      1.26    mhitch 		mcpcia_irq = (device - 2) * 4 + buspin - 1;
    152       1.1    mjacob 	} else {
    153      1.15   thorpej 		printf("dec_kn300_intr_map: weird device number %d\n", device);
    154      1.15   thorpej 		return(1);
    155       1.1    mjacob 	}
    156      1.11   thorpej 
    157       1.1    mjacob 	/*
    158       1.1    mjacob 	 * handle layout:
    159       1.1    mjacob 	 *
    160      1.15   thorpej 	 *	Determine kn300 IRQ (encoded in SCB vector):
    161       1.6    mjacob 	 *	bits 0..1	buspin-1
    162       1.6    mjacob 	 *	bits 2..4	PCI Slot (0..7- yes, some don't exist)
    163       1.6    mjacob 	 *	bits 5..7	MID-4
    164       1.6    mjacob 	 *	bits 8..10	7-GID
    165      1.12   thorpej 	 *
    166      1.12   thorpej 	 *	Software only:
    167      1.12   thorpej 	 *	bits 11-15	MCPCIA IRQ
    168       1.1    mjacob 	 */
    169       1.1    mjacob 	*ihp = (pci_intr_handle_t)
    170       1.6    mjacob 		(buspin - 1			    )	|
    171       1.6    mjacob 		((device & 0x7)			<< 2)	|
    172      1.11   thorpej 		((ccp->cc_mid - 4)		<< 5)	|
    173      1.11   thorpej 		((7 - ccp->cc_gid)		<< 8)	|
    174      1.15   thorpej 		(mcpcia_irq			<< 11);
    175       1.1    mjacob 	return (0);
    176       1.1    mjacob }
    177       1.1    mjacob 
    178       1.1    mjacob const char *
    179      1.31       dsl dec_kn300_intr_string(void *ccv, pci_intr_handle_t ih)
    180       1.1    mjacob {
    181      1.15   thorpej 	static char irqstr[64];
    182      1.12   thorpej 
    183      1.12   thorpej 	sprintf(irqstr, "kn300 irq %ld", ih & 0x3ff);
    184       1.1    mjacob 	return (irqstr);
    185      1.19       cgd }
    186      1.19       cgd 
    187      1.19       cgd const struct evcnt *
    188      1.31       dsl dec_kn300_intr_evcnt(void *ccv, pci_intr_handle_t ih)
    189      1.19       cgd {
    190      1.19       cgd 
    191      1.20   thorpej 	return (alpha_shared_intr_evcnt(kn300_pci_intr, ih & 0x3ff));
    192       1.1    mjacob }
    193       1.1    mjacob 
    194       1.1    mjacob void *
    195       1.1    mjacob dec_kn300_intr_establish(ccv, ih, level, func, arg)
    196       1.1    mjacob         void *ccv;
    197       1.1    mjacob         pci_intr_handle_t ih;
    198       1.1    mjacob         int level;
    199      1.30       dsl         int (*func)(void *);
    200       1.1    mjacob         void *arg;
    201       1.1    mjacob {
    202      1.15   thorpej 	struct mcpcia_config *ccp = ccv;
    203       1.6    mjacob 	void *cookie;
    204      1.12   thorpej 	int irq;
    205       1.1    mjacob 
    206      1.12   thorpej 	irq = ih & 0x3ff;
    207      1.12   thorpej 	cookie = alpha_shared_intr_establish(kn300_pci_intr, irq, IST_LEVEL,
    208      1.12   thorpej 	    level, func, arg, "kn300 irq");
    209       1.6    mjacob 
    210      1.23   thorpej 	if (cookie != NULL &&
    211      1.23   thorpej 	    alpha_shared_intr_firstactive(kn300_pci_intr, irq)) {
    212      1.23   thorpej 		scb_set(MCPCIA_VEC_PCI + SCB_IDXTOVEC(irq),
    213      1.29        ad 		    kn300_iointr, NULL, level);
    214      1.15   thorpej 		alpha_shared_intr_set_private(kn300_pci_intr, irq, ccp);
    215      1.12   thorpej 		savirqs[irq] = (ih >> 11) & 0x1f;
    216      1.15   thorpej 		kn300_enable_intr(ccp, savirqs[irq]);
    217       1.6    mjacob 		alpha_mb();
    218       1.1    mjacob 	}
    219       1.1    mjacob 	return (cookie);
    220       1.1    mjacob }
    221       1.1    mjacob 
    222       1.1    mjacob void
    223      1.32       dsl dec_kn300_intr_disestablish(void *ccv, void *cookie)
    224       1.1    mjacob {
    225       1.6    mjacob 	panic("dec_kn300_intr_disestablish not implemented");
    226       1.1    mjacob }
    227       1.1    mjacob 
    228       1.1    mjacob void
    229      1.31       dsl kn300_iointr(void *arg, unsigned long vec)
    230       1.1    mjacob {
    231       1.6    mjacob 	struct mcpcia_softc *mcp;
    232      1.12   thorpej 	u_long irq;
    233       1.1    mjacob 
    234      1.23   thorpej 	irq = SCB_VECTOIDX(vec - MCPCIA_VEC_PCI);
    235       1.6    mjacob 
    236      1.17    mjacob 	if (alpha_shared_intr_dispatch(kn300_pci_intr, irq)) {
    237      1.17    mjacob 		/*
    238      1.17    mjacob 		 * Any claim of an interrupt at this level is a hint to
    239      1.17    mjacob 		 * reset the stray interrupt count- elsewise a slow leak
    240      1.17    mjacob 		 * over time will cause this level to be shutdown.
    241      1.17    mjacob 		 */
    242      1.27   thorpej 		alpha_shared_intr_reset_strays(kn300_pci_intr, irq);
    243      1.17    mjacob 		return;
    244      1.17    mjacob 	}
    245      1.17    mjacob 
    246      1.17    mjacob 	/*
    247      1.17    mjacob 	 * If we haven't finished configuring yet, or there is no mcp
    248      1.17    mjacob 	 * registered for this level yet, just return.
    249      1.17    mjacob 	 */
    250      1.17    mjacob 	mcp = alpha_shared_intr_get_private(kn300_pci_intr, irq);
    251      1.17    mjacob 	if (mcp == NULL || mcp->mcpcia_cc == NULL)
    252      1.17    mjacob 		return;
    253      1.17    mjacob 
    254      1.17    mjacob 	/*
    255      1.17    mjacob 	 * We're getting an interrupt for a device we haven't enabled.
    256      1.17    mjacob 	 * We had better not try and use -1 to find the right bit to disable.
    257      1.17    mjacob 	 */
    258      1.17    mjacob 	if (savirqs[irq] == -1) {
    259      1.17    mjacob 		printf("kn300_iointr: stray interrupt vector 0x%lx\n", vec);
    260       1.6    mjacob 		return;
    261      1.17    mjacob 	}
    262      1.11   thorpej 
    263       1.6    mjacob 	/*
    264      1.11   thorpej 	 * Stray interrupt; disable the IRQ on the appropriate MCPCIA
    265      1.11   thorpej 	 * if we've reached the limit.
    266       1.6    mjacob 	 */
    267      1.14   thorpej 	alpha_shared_intr_stray(kn300_pci_intr, irq, "kn300 irq");
    268      1.12   thorpej 	if (ALPHA_SHARED_INTR_DISABLE(kn300_pci_intr, irq) == 0)
    269       1.6    mjacob 		return;
    270      1.12   thorpej 	kn300_disable_intr(mcp->mcpcia_cc, savirqs[irq]);
    271       1.1    mjacob }
    272       1.1    mjacob 
    273       1.1    mjacob void
    274      1.31       dsl kn300_enable_intr(struct mcpcia_config *ccp, int irq)
    275       1.1    mjacob {
    276       1.1    mjacob 	alpha_mb();
    277      1.11   thorpej 	REGVAL(MCPCIA_INT_MASK0(ccp)) |= (1 << irq);
    278       1.1    mjacob 	alpha_mb();
    279       1.1    mjacob }
    280       1.1    mjacob 
    281       1.1    mjacob void
    282      1.31       dsl kn300_disable_intr(struct mcpcia_config *ccp, int irq)
    283       1.1    mjacob {
    284       1.1    mjacob 	alpha_mb();
    285      1.11   thorpej 	REGVAL(MCPCIA_INT_MASK0(ccp)) &= ~(1 << irq);
    286       1.1    mjacob 	alpha_mb();
    287       1.1    mjacob }
    288