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