Home | History | Annotate | Line # | Download | only in pci
pci_up1000.c revision 1.5.2.3
      1  1.5.2.3  bouyer /* $NetBSD: pci_up1000.c,v 1.5.2.3 2001/01/05 17:33:49 bouyer Exp $ */
      2  1.5.2.2  bouyer 
      3  1.5.2.2  bouyer /*-
      4  1.5.2.2  bouyer  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  1.5.2.2  bouyer  * All rights reserved.
      6  1.5.2.2  bouyer  *
      7  1.5.2.2  bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8  1.5.2.2  bouyer  * by Jason R. Thorpe.
      9  1.5.2.2  bouyer  *
     10  1.5.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     11  1.5.2.2  bouyer  * modification, are permitted provided that the following conditions
     12  1.5.2.2  bouyer  * are met:
     13  1.5.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     14  1.5.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     15  1.5.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.5.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     17  1.5.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     18  1.5.2.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     19  1.5.2.2  bouyer  *    must display the following acknowledgement:
     20  1.5.2.2  bouyer  *	This product includes software developed by the NetBSD
     21  1.5.2.2  bouyer  *	Foundation, Inc. and its contributors.
     22  1.5.2.2  bouyer  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.5.2.2  bouyer  *    contributors may be used to endorse or promote products derived
     24  1.5.2.2  bouyer  *    from this software without specific prior written permission.
     25  1.5.2.2  bouyer  *
     26  1.5.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.5.2.2  bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.5.2.2  bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.5.2.2  bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.5.2.2  bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.5.2.2  bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.5.2.2  bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.5.2.2  bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.5.2.2  bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.5.2.2  bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.5.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGE.
     37  1.5.2.2  bouyer  */
     38  1.5.2.2  bouyer 
     39  1.5.2.2  bouyer #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     40  1.5.2.2  bouyer 
     41  1.5.2.3  bouyer __KERNEL_RCSID(0, "$NetBSD: pci_up1000.c,v 1.5.2.3 2001/01/05 17:33:49 bouyer Exp $");
     42  1.5.2.2  bouyer 
     43  1.5.2.2  bouyer #include <sys/types.h>
     44  1.5.2.2  bouyer #include <sys/param.h>
     45  1.5.2.2  bouyer #include <sys/time.h>
     46  1.5.2.2  bouyer #include <sys/systm.h>
     47  1.5.2.2  bouyer #include <sys/errno.h>
     48  1.5.2.2  bouyer #include <sys/device.h>
     49  1.5.2.2  bouyer 
     50  1.5.2.2  bouyer #include <uvm/uvm_extern.h>
     51  1.5.2.2  bouyer 
     52  1.5.2.2  bouyer #include <machine/autoconf.h>
     53  1.5.2.2  bouyer #include <machine/bus.h>
     54  1.5.2.2  bouyer #include <machine/intr.h>
     55  1.5.2.2  bouyer 
     56  1.5.2.2  bouyer #include <dev/isa/isavar.h>
     57  1.5.2.2  bouyer 
     58  1.5.2.2  bouyer #include <dev/pci/pcireg.h>
     59  1.5.2.2  bouyer #include <dev/pci/pcivar.h>
     60  1.5.2.2  bouyer #include <dev/pci/pciidereg.h>
     61  1.5.2.2  bouyer #include <dev/pci/pciidevar.h>
     62  1.5.2.2  bouyer 
     63  1.5.2.2  bouyer #include <alpha/pci/irongatevar.h>
     64  1.5.2.2  bouyer 
     65  1.5.2.2  bouyer #include <alpha/pci/pci_up1000.h>
     66  1.5.2.2  bouyer #include <alpha/pci/siovar.h>
     67  1.5.2.2  bouyer #include <alpha/pci/sioreg.h>
     68  1.5.2.2  bouyer 
     69  1.5.2.2  bouyer #include "sio.h"
     70  1.5.2.2  bouyer 
     71  1.5.2.3  bouyer int     api_up1000_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
     72  1.5.2.2  bouyer const char *api_up1000_intr_string(void *, pci_intr_handle_t);
     73  1.5.2.2  bouyer const struct evcnt *api_up1000_intr_evcnt(void *, pci_intr_handle_t);
     74  1.5.2.2  bouyer void    *api_up1000_intr_establish(void *, pci_intr_handle_t,
     75  1.5.2.2  bouyer 	    int, int (*func)(void *), void *);
     76  1.5.2.2  bouyer void    api_up1000_intr_disestablish(void *, void *);
     77  1.5.2.2  bouyer 
     78  1.5.2.2  bouyer void	*api_up1000_pciide_compat_intr_establish(void *, struct device *,
     79  1.5.2.2  bouyer 	    struct pci_attach_args *, int, int (*)(void *), void *);
     80  1.5.2.2  bouyer 
     81  1.5.2.2  bouyer void
     82  1.5.2.2  bouyer pci_up1000_pickintr(struct irongate_config *icp)
     83  1.5.2.2  bouyer {
     84  1.5.2.2  bouyer 	bus_space_tag_t iot = &icp->ic_iot;
     85  1.5.2.2  bouyer 	pci_chipset_tag_t pc = &icp->ic_pc;
     86  1.5.2.2  bouyer 
     87  1.5.2.2  bouyer 	pc->pc_intr_v = icp;
     88  1.5.2.2  bouyer 	pc->pc_intr_map = api_up1000_intr_map;
     89  1.5.2.2  bouyer 	pc->pc_intr_string = api_up1000_intr_string;
     90  1.5.2.2  bouyer 	pc->pc_intr_evcnt = api_up1000_intr_evcnt;
     91  1.5.2.2  bouyer 	pc->pc_intr_establish = api_up1000_intr_establish;
     92  1.5.2.2  bouyer 	pc->pc_intr_disestablish = api_up1000_intr_disestablish;
     93  1.5.2.2  bouyer 
     94  1.5.2.2  bouyer 	pc->pc_pciide_compat_intr_establish =
     95  1.5.2.2  bouyer 	    api_up1000_pciide_compat_intr_establish;
     96  1.5.2.2  bouyer 
     97  1.5.2.2  bouyer #if NSIO
     98  1.5.2.2  bouyer 	sio_intr_setup(pc, iot);
     99  1.5.2.2  bouyer 	set_iointr(&sio_iointr);
    100  1.5.2.2  bouyer #else
    101  1.5.2.2  bouyer 	panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)");
    102  1.5.2.2  bouyer #endif
    103  1.5.2.2  bouyer }
    104  1.5.2.2  bouyer 
    105  1.5.2.2  bouyer int
    106  1.5.2.3  bouyer api_up1000_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    107  1.5.2.2  bouyer {
    108  1.5.2.3  bouyer 	pci_chipset_tag_t pc = pa->pa_pc;
    109  1.5.2.3  bouyer 	int buspin = pa->pa_intrpin;
    110  1.5.2.3  bouyer 	int bustag = pa->pa_intrtag;
    111  1.5.2.3  bouyer 	int line = pa->pa_intrline;
    112  1.5.2.2  bouyer 	int bus, device, function;
    113  1.5.2.2  bouyer 
    114  1.5.2.2  bouyer 	if (buspin == 0) {
    115  1.5.2.2  bouyer 		/* No IRQ used. */
    116  1.5.2.2  bouyer 		return 1;
    117  1.5.2.2  bouyer 	}
    118  1.5.2.2  bouyer 	if (buspin > 4) {
    119  1.5.2.2  bouyer 		printf("api_up1000_intr_map: bad interrupt pin %d\n",
    120  1.5.2.2  bouyer 		    buspin);
    121  1.5.2.2  bouyer 		return 1;
    122  1.5.2.2  bouyer 	}
    123  1.5.2.2  bouyer 
    124  1.5.2.2  bouyer 	alpha_pci_decompose_tag(pc, bustag, &bus, &device, &function);
    125  1.5.2.2  bouyer 
    126  1.5.2.2  bouyer 	/*
    127  1.5.2.2  bouyer 	 * The console places the interrupt mapping in the "line" value.
    128  1.5.2.2  bouyer 	 * A value of (char)-1 indicates there is no mapping.
    129  1.5.2.2  bouyer 	 */
    130  1.5.2.2  bouyer 	if (line == 0xff) {
    131  1.5.2.2  bouyer 		printf("api_up1000_intr_map: no mapping for %d/%d/%d\n",
    132  1.5.2.2  bouyer 		    bus, device, function);
    133  1.5.2.2  bouyer 		return (1);
    134  1.5.2.2  bouyer 	}
    135  1.5.2.2  bouyer 
    136  1.5.2.2  bouyer 	/* XXX Check for 0? */
    137  1.5.2.2  bouyer 	if (line > 15) {
    138  1.5.2.2  bouyer 		printf("api_up1000_intr_map: ISA IRQ too large (%d)\n",
    139  1.5.2.2  bouyer 		    line);
    140  1.5.2.2  bouyer 		return (1);
    141  1.5.2.2  bouyer 	}
    142  1.5.2.2  bouyer 	if (line == 2) {
    143  1.5.2.2  bouyer 		printf("api_up1000_intr_map: changed IRQ 2 to IRQ 9\n");
    144  1.5.2.2  bouyer 		line = 9;
    145  1.5.2.2  bouyer 	}
    146  1.5.2.2  bouyer 
    147  1.5.2.2  bouyer 	*ihp = line;
    148  1.5.2.2  bouyer 	return (0);
    149  1.5.2.2  bouyer }
    150  1.5.2.2  bouyer 
    151  1.5.2.2  bouyer const char *
    152  1.5.2.2  bouyer api_up1000_intr_string(void *icv, pci_intr_handle_t ih)
    153  1.5.2.2  bouyer {
    154  1.5.2.2  bouyer #if 0
    155  1.5.2.2  bouyer 	struct irongate_config *icp = icv;
    156  1.5.2.2  bouyer #endif
    157  1.5.2.2  bouyer 
    158  1.5.2.2  bouyer 	return sio_intr_string(NULL /*XXX*/, ih);
    159  1.5.2.2  bouyer }
    160  1.5.2.2  bouyer 
    161  1.5.2.2  bouyer const struct evcnt *
    162  1.5.2.2  bouyer api_up1000_intr_evcnt(void *icv, pci_intr_handle_t ih)
    163  1.5.2.2  bouyer {
    164  1.5.2.2  bouyer #if 0
    165  1.5.2.2  bouyer 	struct irongate_config *icp = icv;
    166  1.5.2.2  bouyer #endif
    167  1.5.2.2  bouyer 
    168  1.5.2.2  bouyer 	return sio_intr_evcnt(NULL /*XXX*/, ih);
    169  1.5.2.2  bouyer }
    170  1.5.2.2  bouyer 
    171  1.5.2.2  bouyer void *
    172  1.5.2.2  bouyer api_up1000_intr_establish(void *icv, pci_intr_handle_t ih, int level,
    173  1.5.2.2  bouyer     int (*func)(void *), void *arg)
    174  1.5.2.2  bouyer {
    175  1.5.2.2  bouyer #if 0
    176  1.5.2.2  bouyer 	struct irongate_config *icp = icv;
    177  1.5.2.2  bouyer #endif
    178  1.5.2.2  bouyer 
    179  1.5.2.2  bouyer 	return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
    180  1.5.2.2  bouyer 	    arg);
    181  1.5.2.2  bouyer }
    182  1.5.2.2  bouyer 
    183  1.5.2.2  bouyer void
    184  1.5.2.2  bouyer api_up1000_intr_disestablish(void *icv, void *cookie)
    185  1.5.2.2  bouyer {
    186  1.5.2.2  bouyer #if 0
    187  1.5.2.2  bouyer 	struct irongate_config *icp = icv;
    188  1.5.2.2  bouyer #endif
    189  1.5.2.2  bouyer 
    190  1.5.2.2  bouyer 	sio_intr_disestablish(NULL /*XXX*/, cookie);
    191  1.5.2.2  bouyer }
    192  1.5.2.2  bouyer 
    193  1.5.2.2  bouyer void *
    194  1.5.2.2  bouyer api_up1000_pciide_compat_intr_establish(void *icv, struct device *dev,
    195  1.5.2.2  bouyer     struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
    196  1.5.2.2  bouyer {
    197  1.5.2.2  bouyer 	pci_chipset_tag_t pc = pa->pa_pc;
    198  1.5.2.2  bouyer 	void *cookie = NULL;
    199  1.5.2.2  bouyer 	int bus, irq;
    200  1.5.2.2  bouyer 
    201  1.5.2.2  bouyer 	alpha_pci_decompose_tag(pc, pa->pa_tag, &bus, NULL, NULL);
    202  1.5.2.2  bouyer 
    203  1.5.2.2  bouyer 	/*
    204  1.5.2.2  bouyer 	 * If this isn't PCI bus #0, all bets are off.
    205  1.5.2.2  bouyer 	 */
    206  1.5.2.2  bouyer 	if (bus != 0)
    207  1.5.2.2  bouyer 		return (NULL);
    208  1.5.2.2  bouyer 
    209  1.5.2.2  bouyer 	irq = PCIIDE_COMPAT_IRQ(chan);
    210  1.5.2.2  bouyer #if NSIO
    211  1.5.2.2  bouyer 	cookie = sio_intr_establish(NULL /*XXX*/, irq, IST_EDGE, IPL_BIO,
    212  1.5.2.2  bouyer 	    func, arg);
    213  1.5.2.2  bouyer 	if (cookie == NULL)
    214  1.5.2.2  bouyer 		return (NULL);
    215  1.5.2.2  bouyer 	printf("%s: %s channel interrupting at %s\n", dev->dv_xname,
    216  1.5.2.2  bouyer 	    PCIIDE_CHANNEL_NAME(chan), sio_intr_string(NULL /*XXX*/, irq));
    217  1.5.2.2  bouyer #endif
    218  1.5.2.2  bouyer 	return (cookie);
    219  1.5.2.2  bouyer }
    220