Home | History | Annotate | Line # | Download | only in pci
      1  1.50   thorpej /* $NetBSD: pci_eb164.c,v 1.50 2021/07/04 22:42:36 thorpej Exp $ */
      2  1.14   thorpej 
      3  1.14   thorpej /*-
      4  1.14   thorpej  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.14   thorpej  * All rights reserved.
      6  1.14   thorpej  *
      7  1.14   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.14   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.14   thorpej  * NASA Ames Research Center.
     10  1.14   thorpej  *
     11  1.14   thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.14   thorpej  * modification, are permitted provided that the following conditions
     13  1.14   thorpej  * are met:
     14  1.14   thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.14   thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.14   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.14   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.14   thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.14   thorpej  *
     20  1.14   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  1.14   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.14   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.14   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  1.14   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.14   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.14   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.14   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.14   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.14   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.14   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     31  1.14   thorpej  */
     32   1.1       cgd 
     33   1.1       cgd /*
     34   1.1       cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     35   1.1       cgd  * All rights reserved.
     36   1.1       cgd  *
     37   1.1       cgd  * Author: Chris G. Demetriou
     38  1.44      matt  *
     39   1.1       cgd  * Permission to use, copy, modify and distribute this software and
     40   1.1       cgd  * its documentation is hereby granted, provided that both the copyright
     41   1.1       cgd  * notice and this permission notice appear in all copies of the
     42   1.1       cgd  * software, derivative works or modified versions, and any portions
     43   1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     44  1.44      matt  *
     45  1.44      matt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     46  1.44      matt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     47   1.1       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     48  1.44      matt  *
     49   1.1       cgd  * Carnegie Mellon requests users of this software to return to
     50   1.1       cgd  *
     51   1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     52   1.1       cgd  *  School of Computer Science
     53   1.1       cgd  *  Carnegie Mellon University
     54   1.1       cgd  *  Pittsburgh PA 15213-3890
     55   1.1       cgd  *
     56   1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     57   1.1       cgd  * rights to redistribute these changes.
     58   1.1       cgd  */
     59   1.5       cgd 
     60   1.6       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     61   1.6       cgd 
     62  1.50   thorpej __KERNEL_RCSID(0, "$NetBSD: pci_eb164.c,v 1.50 2021/07/04 22:42:36 thorpej Exp $");
     63   1.1       cgd 
     64   1.1       cgd #include <sys/types.h>
     65   1.1       cgd #include <sys/param.h>
     66   1.1       cgd #include <sys/time.h>
     67   1.1       cgd #include <sys/systm.h>
     68   1.1       cgd #include <sys/errno.h>
     69   1.1       cgd #include <sys/device.h>
     70   1.1       cgd #include <sys/syslog.h>
     71   1.1       cgd 
     72   1.1       cgd #include <machine/autoconf.h>
     73  1.18   thorpej #include <machine/rpb.h>
     74   1.1       cgd 
     75   1.1       cgd #include <dev/pci/pcireg.h>
     76   1.1       cgd #include <dev/pci/pcivar.h>
     77  1.14   thorpej #include <dev/pci/pciidereg.h>
     78  1.14   thorpej #include <dev/pci/pciidevar.h>
     79   1.1       cgd 
     80   1.1       cgd #include <alpha/pci/ciareg.h>
     81   1.1       cgd #include <alpha/pci/ciavar.h>
     82   1.1       cgd 
     83   1.1       cgd #include "sio.h"
     84   1.1       cgd #if NSIO
     85   1.1       cgd #include <alpha/pci/siovar.h>
     86   1.1       cgd #endif
     87   1.1       cgd 
     88  1.46   thorpej static int	dec_eb164_intr_map(const struct pci_attach_args *,
     89  1.46   thorpej 		    pci_intr_handle_t *);
     90  1.14   thorpej 
     91  1.44      matt #define	EB164_SIO_IRQ	4
     92   1.3       cgd #define	EB164_MAX_IRQ	24
     93   1.3       cgd #define	PCI_STRAY_MAX	5
     94   1.3       cgd 
     95  1.46   thorpej static bus_space_tag_t eb164_intrgate_iot;
     96  1.46   thorpej static bus_space_handle_t eb164_intrgate_ioh;
     97   1.3       cgd 
     98  1.46   thorpej /* See pci_eb164_intr.s */
     99  1.46   thorpej extern void	eb164_intr_enable(pci_chipset_tag_t, int irq);
    100  1.46   thorpej extern void	eb164_intr_disable(pci_chipset_tag_t, int irq);
    101   1.1       cgd 
    102  1.47   thorpej static void
    103  1.47   thorpej pci_eb164_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
    104  1.47   thorpej     pci_chipset_tag_t pc)
    105   1.1       cgd {
    106  1.47   thorpej 	struct cia_config *ccp = core;
    107   1.3       cgd 	int i;
    108   1.1       cgd 
    109  1.47   thorpej 	pc->pc_intr_v = core;
    110  1.44      matt 	pc->pc_intr_map = dec_eb164_intr_map;
    111  1.46   thorpej 	pc->pc_intr_string = alpha_pci_generic_intr_string;
    112  1.46   thorpej 	pc->pc_intr_evcnt = alpha_pci_generic_intr_evcnt;
    113  1.46   thorpej 	pc->pc_intr_establish = alpha_pci_generic_intr_establish;
    114  1.46   thorpej 	pc->pc_intr_disestablish = alpha_pci_generic_intr_disestablish;
    115   1.1       cgd 
    116  1.14   thorpej 	pc->pc_pciide_compat_intr_establish =
    117  1.46   thorpej 	    sio_pciide_compat_intr_establish;
    118  1.14   thorpej 
    119   1.3       cgd 	eb164_intrgate_iot = iot;
    120   1.3       cgd 	if (bus_space_map(eb164_intrgate_iot, 0x804, 3, 0,
    121   1.3       cgd 	    &eb164_intrgate_ioh) != 0)
    122   1.3       cgd 		panic("pci_eb164_pickintr: couldn't map interrupt PLD");
    123   1.3       cgd 
    124  1.48   thorpej 	pc->pc_intr_desc = "eb164";
    125  1.46   thorpej 	pc->pc_vecbase = 0x900;
    126  1.46   thorpej 	pc->pc_nirq = EB164_MAX_IRQ;
    127  1.46   thorpej 
    128  1.46   thorpej 	pc->pc_intr_enable = eb164_intr_enable;
    129  1.46   thorpej 	pc->pc_intr_disable = eb164_intr_disable;
    130  1.46   thorpej 
    131  1.20   thorpej 	for (i = 0; i < EB164_MAX_IRQ; i++) {
    132  1.49   thorpej 		eb164_intr_disable(pc, i);
    133  1.20   thorpej 	}
    134   1.3       cgd 
    135  1.49   thorpej 	/*
    136  1.49   thorpej 	 * Systems with a Pyxis seem to have problems with
    137  1.49   thorpej 	 * stray interrupts, so just ignore them.
    138  1.49   thorpej 	 */
    139  1.49   thorpej 	alpha_pci_intr_alloc(pc,
    140  1.49   thorpej 	    (ccp->cc_flags & CCF_ISPYXIS) ? 0 : PCI_STRAY_MAX);
    141  1.49   thorpej 
    142   1.1       cgd #if NSIO
    143  1.11   thorpej 	sio_intr_setup(pc, iot);
    144  1.46   thorpej 	eb164_intr_enable(pc, EB164_SIO_IRQ);
    145   1.1       cgd #endif
    146   1.1       cgd }
    147  1.47   thorpej ALPHA_PCI_INTR_INIT(ST_EB164, pci_eb164_pickintr)
    148   1.1       cgd 
    149  1.46   thorpej static int
    150  1.42    dyoung dec_eb164_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    151   1.1       cgd {
    152  1.44      matt 	pcitag_t bustag = pa->pa_intrtag;
    153  1.46   thorpej 	int buspin = pa->pa_intrpin;
    154  1.29  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
    155  1.16   thorpej 	int bus, device, function;
    156  1.44      matt 	uint64_t variation;
    157   1.1       cgd 
    158  1.15   thorpej 	if (buspin == 0) {
    159  1.15   thorpej 		/* No IRQ used. */
    160  1.15   thorpej 		return 1;
    161  1.15   thorpej 	}
    162  1.46   thorpej 	if (buspin < 0 || buspin > 4) {
    163  1.15   thorpej 		printf("dec_eb164_intr_map: bad interrupt pin %d\n", buspin);
    164  1.15   thorpej 		return 1;
    165  1.15   thorpej 	}
    166   1.1       cgd 
    167  1.31   thorpej 	pci_decompose_tag(pc, bustag, &bus, &device, &function);
    168  1.16   thorpej 
    169  1.18   thorpej 	variation = hwrpb->rpb_variation & SV_ST_MASK;
    170  1.18   thorpej 
    171  1.12   thorpej 	/*
    172  1.18   thorpej 	 *
    173  1.18   thorpej 	 * The AlphaPC 164 and AlphaPC 164LX have a CMD PCI IDE controller
    174  1.18   thorpej 	 * at bus 0 device 11.  These are wired to compatibility mode,
    175  1.18   thorpej 	 * so do not map their interrupts.
    176  1.18   thorpej 	 *
    177  1.18   thorpej 	 * The AlphaPC 164SX has PCI IDE on functions 1 and 2 of the
    178  1.18   thorpej 	 * Cypress PCI-ISA bridge at bus 0 device 8.  These, too, are
    179  1.18   thorpej 	 * wired to compatibility mode.
    180  1.18   thorpej 	 *
    181  1.18   thorpej 	 * Real EB164s have ISA IDE on the Super I/O chip.
    182  1.12   thorpej 	 */
    183  1.18   thorpej 	if (bus == 0) {
    184  1.18   thorpej 		if (variation >= SV_ST_ALPHAPC164_366 &&
    185  1.18   thorpej 		    variation <= SV_ST_ALPHAPC164LX_600) {
    186  1.18   thorpej 			if (device == 8)
    187  1.18   thorpej 				panic("dec_eb164_intr_map: SIO device");
    188  1.18   thorpej 			if (device == 11)
    189  1.18   thorpej 				return (1);
    190  1.18   thorpej 		} else if (variation >= SV_ST_ALPHAPC164SX_400 &&
    191  1.18   thorpej 			   variation <= SV_ST_ALPHAPC164SX_600) {
    192  1.18   thorpej 			if (device == 8) {
    193  1.18   thorpej 				if (function == 0)
    194  1.18   thorpej 					panic("dec_eb164_intr_map: SIO device");
    195  1.18   thorpej 				return (1);
    196  1.18   thorpej 			}
    197  1.18   thorpej 		} else {
    198  1.18   thorpej 			if (device == 8)
    199  1.18   thorpej 				panic("dec_eb164_intr_map: SIO device");
    200  1.18   thorpej 		}
    201  1.16   thorpej 	}
    202  1.16   thorpej 
    203  1.46   thorpej 	return alpha_pci_generic_intr_map(pa, ihp);
    204   1.3       cgd }
    205   1.3       cgd 
    206   1.4       cgd #if 0		/* THIS DOES NOT WORK!  see pci_eb164_intr.S. */
    207  1.44      matt uint8_t eb164_intr_mask[3] = { 0xff, 0xff, 0xff };
    208   1.3       cgd 
    209   1.3       cgd void
    210  1.46   thorpej eb164_intr_enable(pci_chipset_tag_t pc __unused, int irq)
    211   1.3       cgd {
    212   1.3       cgd 	int byte = (irq / 8), bit = (irq % 8);
    213   1.3       cgd 
    214   1.3       cgd #if 1
    215   1.4       cgd 	printf("eb164_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
    216   1.3       cgd #endif
    217   1.3       cgd 	eb164_intr_mask[byte] &= ~(1 << bit);
    218   1.3       cgd 
    219   1.3       cgd 	bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
    220   1.3       cgd 	    eb164_intr_mask[byte]);
    221   1.3       cgd }
    222   1.3       cgd 
    223   1.3       cgd void
    224  1.46   thorpej eb164_intr_disable(pci_chipset_tag_t pc __unused, int irq)
    225   1.3       cgd {
    226   1.3       cgd 	int byte = (irq / 8), bit = (irq % 8);
    227   1.3       cgd 
    228   1.3       cgd #if 1
    229   1.4       cgd 	printf("eb164_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
    230   1.3       cgd #endif
    231   1.3       cgd 	eb164_intr_mask[byte] |= (1 << bit);
    232   1.3       cgd 
    233   1.3       cgd 	bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
    234   1.3       cgd 	    eb164_intr_mask[byte]);
    235   1.1       cgd }
    236   1.4       cgd #endif
    237