Home | History | Annotate | Line # | Download | only in pci
pci_alphabook1.c revision 1.11
      1 /* $NetBSD: pci_alphabook1.c,v 1.11 2009/03/14 15:35:59 dsl Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     35  * All rights reserved.
     36  *
     37  * Authors: Jeffrey Hsu and Chris G. Demetriou
     38  *
     39  * Permission to use, copy, modify and distribute this software and
     40  * its documentation is hereby granted, provided that both the copyright
     41  * notice and this permission notice appear in all copies of the
     42  * software, derivative works or modified versions, and any portions
     43  * thereof, and that both notices appear in supporting documentation.
     44  *
     45  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     46  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     47  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     48  *
     49  * Carnegie Mellon requests users of this software to return to
     50  *
     51  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     52  *  School of Computer Science
     53  *  Carnegie Mellon University
     54  *  Pittsburgh PA 15213-3890
     55  *
     56  * any improvements or extensions that they make and grant Carnegie the
     57  * rights to redistribute these changes.
     58  */
     59 
     60 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     61 
     62 __KERNEL_RCSID(0, "$NetBSD: pci_alphabook1.c,v 1.11 2009/03/14 15:35:59 dsl Exp $");
     63 
     64 #include <sys/types.h>
     65 #include <sys/param.h>
     66 #include <sys/time.h>
     67 #include <sys/systm.h>
     68 #include <sys/errno.h>
     69 #include <sys/device.h>
     70 
     71 #include <uvm/uvm_extern.h>
     72 
     73 #include <machine/autoconf.h>
     74 #include <machine/bus.h>
     75 #include <machine/intr.h>
     76 
     77 #include <dev/isa/isavar.h>
     78 #include <dev/pci/pcireg.h>
     79 #include <dev/pci/pcivar.h>
     80 
     81 #include <alpha/pci/lcavar.h>
     82 
     83 #include <alpha/pci/pci_alphabook1.h>
     84 #include <alpha/pci/siovar.h>
     85 #include <alpha/pci/sioreg.h>
     86 
     87 #include "sio.h"
     88 
     89 int     dec_alphabook1_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
     90 const char *dec_alphabook1_intr_string(void *, pci_intr_handle_t);
     91 const struct evcnt *dec_alphabook1_intr_evcnt(void *, pci_intr_handle_t);
     92 void    *dec_alphabook1_intr_establish(void *, pci_intr_handle_t,
     93 	    int, int (*func)(void *), void *);
     94 void    dec_alphabook1_intr_disestablish(void *, void *);
     95 
     96 #define	LCA_SIO_DEVICE	7	/* XXX */
     97 
     98 void
     99 pci_alphabook1_pickintr(struct lca_config *lcp)
    100 {
    101 	bus_space_tag_t iot = &lcp->lc_iot;
    102 	pci_chipset_tag_t pc = &lcp->lc_pc;
    103 	pcireg_t sioclass;
    104 	int sioII;
    105 
    106 	/* XXX MAGIC NUMBER */
    107 	sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
    108 	    PCI_CLASS_REG);
    109         sioII = (sioclass & 0xff) >= 3;
    110 
    111 	if (!sioII)
    112 		printf("WARNING: SIO NOT SIO II... NO BETS...\n");
    113 
    114 	pc->pc_intr_v = lcp;
    115 	pc->pc_intr_map = dec_alphabook1_intr_map;
    116 	pc->pc_intr_string = dec_alphabook1_intr_string;
    117 	pc->pc_intr_evcnt = dec_alphabook1_intr_evcnt;
    118 	pc->pc_intr_establish = dec_alphabook1_intr_establish;
    119 	pc->pc_intr_disestablish = dec_alphabook1_intr_disestablish;
    120 
    121 	/* Not supported on AlphaBook. */
    122 	pc->pc_pciide_compat_intr_establish = NULL;
    123 
    124 #if NSIO
    125 	sio_intr_setup(pc, iot);
    126 #else
    127 	panic("pci_alphabook1_pickintr: no I/O interrupt handler (no sio)");
    128 #endif
    129 }
    130 
    131 int
    132 dec_alphabook1_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    133 {
    134 	pcitag_t bustag = pa->pa_intrtag;
    135 	int buspin = pa->pa_intrpin;
    136 	pci_chipset_tag_t pc = pa->pa_pc;
    137 	int device, irq;
    138 
    139 	if (buspin == 0) {
    140 		/* No IRQ used. */
    141 		return 1;
    142 	}
    143 	if (buspin > 4) {
    144 		printf("dec_alphabook1_intr_map: bad interrupt pin %d\n",
    145 		    buspin);
    146 		return 1;
    147 	}
    148 
    149 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    150 
    151 	/*
    152 	 * There is only one interrupting PCI device on the AlphaBook: an
    153 	 * NCR SCSI at device 6.  Devices 7 and 8 are the SIO and a
    154 	 * Cirrus PD6729 PCMCIA controller.  There are no option slots
    155 	 * available.
    156 	 *
    157 	 * NOTE!  Apparently, there was a later AlphaBook which uses
    158 	 * a different interrupt scheme, and has a built-in Tulip Ethernet
    159 	 * interface!  We do not handle that here!
    160 	 */
    161 
    162 	switch (device) {
    163 	case 6:					/* NCR SCSI */
    164 		irq = 14;
    165 		break;
    166 
    167 	default:
    168                 printf("dec_alphabook1_intr_map: weird device number %d\n",
    169 		    device);
    170                 return 1;
    171 	}
    172 
    173 	*ihp = irq;
    174 	return (0);
    175 }
    176 
    177 const char *
    178 dec_alphabook1_intr_string(void *lcv, pci_intr_handle_t ih)
    179 {
    180 #if 0
    181 	struct lca_config *lcp = lcv;
    182 #endif
    183 
    184 	return sio_intr_string(NULL /*XXX*/, ih);
    185 }
    186 
    187 const struct evcnt *
    188 dec_alphabook1_intr_evcnt(void *lcv, pci_intr_handle_t ih)
    189 {
    190 #if 0
    191 	struct lca_config *lcp = lcv;
    192 #endif
    193 
    194 	return sio_intr_evcnt(NULL /*XXX*/, ih);
    195 }
    196 
    197 void *
    198 dec_alphabook1_intr_establish(lcv, ih, level, func, arg)
    199 	void *lcv, *arg;
    200 	pci_intr_handle_t ih;
    201 	int level;
    202 	int (*func)(void *);
    203 {
    204 #if 0
    205 	struct lca_config *lcp = lcv;
    206 #endif
    207 
    208 	return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
    209 	    arg);
    210 }
    211 
    212 void
    213 dec_alphabook1_intr_disestablish(lcv, cookie)
    214 	void *lcv, *cookie;
    215 {
    216 #if 0
    217 	struct lca_config *lcp = lcv;
    218 #endif
    219 
    220 	sio_intr_disestablish(NULL /*XXX*/, cookie);
    221 }
    222