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