Home | History | Annotate | Line # | Download | only in pci
adw_pci.c revision 1.2
      1 /* $NetBSD: adw_pci.c,v 1.2 1998/09/26 19:53:34 dante Exp $	 */
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
      5  *
      6  * Author: Baldassare Dante Profeta <dante (at) mclink.it>
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *        This product includes software developed by the NetBSD
     19  *        Foundation, Inc. and its contributors.
     20  * 4. Neither the name of The NetBSD Foundation nor the names of its
     21  *    contributors may be used to endorse or promote products derived
     22  *    from this software without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     27  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34  * POSSIBILITY OF SUCH DAMAGE.
     35  */
     36 /*
     37  * Device probe and attach routines for the following
     38  * Advanced Systems Inc. SCSI controllers:
     39  *
     40  *   Single Channel Products:
     41  *      ABP940UW - Bus-Master PCI Ultra-Wide (240 CDB)
     42  */
     43 
     44 #include <sys/types.h>
     45 #include <sys/param.h>
     46 #include <sys/systm.h>
     47 #include <sys/malloc.h>
     48 #include <sys/kernel.h>
     49 #include <sys/queue.h>
     50 #include <sys/device.h>
     51 
     52 #include <machine/bus.h>
     53 #include <machine/intr.h>
     54 
     55 #include <dev/scsipi/scsi_all.h>
     56 #include <dev/scsipi/scsipi_all.h>
     57 #include <dev/scsipi/scsiconf.h>
     58 
     59 #include <dev/pci/pcireg.h>
     60 #include <dev/pci/pcivar.h>
     61 #include <dev/pci/pcidevs.h>
     62 
     63 #include <dev/ic/adwlib.h>
     64 #include <dev/ic/adw.h>
     65 
     66 /******************************************************************************/
     67 
     68 #define PCI_BASEADR_IO        0x10
     69 
     70 /******************************************************************************/
     71 
     72 int adw_pci_match __P((struct device *, struct cfdata *, void *));
     73 void adw_pci_attach __P((struct device *, struct device *, void *));
     74 
     75 struct cfattach adw_pci_ca =
     76 {
     77 	sizeof(ADW_SOFTC), adw_pci_match, adw_pci_attach
     78 };
     79 
     80 /******************************************************************************/
     81 /*
     82  * Check the slots looking for a board we recognise
     83  * If we find one, note it's address (slot) and call
     84  * the actual probe routine to check it out.
     85  */
     86 int
     87 adw_pci_match(parent, match, aux)
     88 	struct device  *parent;
     89 	struct cfdata  *match;
     90 	void           *aux;
     91 {
     92 	struct pci_attach_args *pa = aux;
     93 
     94 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
     95 		switch (PCI_PRODUCT(pa->pa_id)) {
     96 		case PCI_PRODUCT_ADVSYS_WIDE:
     97 			return (1);
     98 		}
     99 
    100 	return 0;
    101 }
    102 
    103 
    104 void
    105 adw_pci_attach(parent, self, aux)
    106 	struct device  *parent, *self;
    107 	void           *aux;
    108 {
    109 	struct pci_attach_args *pa = aux;
    110 	ADW_SOFTC      *sc = (void *) self;
    111 	bus_space_tag_t iot;
    112 	bus_space_handle_t ioh;
    113 	pci_intr_handle_t ih;
    114 	pci_chipset_tag_t pc = pa->pa_pc;
    115 	u_int32_t       command;
    116 	const char     *intrstr;
    117 
    118 
    119 	sc->sc_flags = 0x0;
    120 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
    121 		switch (PCI_PRODUCT(pa->pa_id)) {
    122 		case PCI_PRODUCT_ADVSYS_WIDE:
    123 			sc->sc_flags |= ADW_WIDE_BOARD;
    124 			printf(": AdvanSys ABP-9xxUW SCSI adapter\n");
    125 			break;
    126 
    127 		default:
    128 			printf(": unknown model!\n");
    129 			return;
    130 		}
    131 
    132 
    133 	/*
    134 	 * Make sure IO/MEM/MASTER are enabled
    135 	 */
    136 	command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    137 	if ((command & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    138 			PCI_COMMAND_MASTER_ENABLE)) !=
    139 	    (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    140 	     PCI_COMMAND_MASTER_ENABLE)) {
    141 		pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    142 		 command | (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    143 			    PCI_COMMAND_MASTER_ENABLE));
    144 	}
    145 	/*
    146 	 * Latency timer settings.
    147 	 */
    148 	{
    149 		u_int32_t       bhlcr;
    150 
    151 		bhlcr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
    152 
    153 		if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_WIDE) &&
    154 		    (PCI_LATTIMER(bhlcr) < 0x20)) {
    155 			bhlcr &= 0xFFFF00FFUL;
    156 			bhlcr |= 0x00002000UL;
    157 			pci_conf_write(pa->pa_pc, pa->pa_tag,
    158 				       PCI_BHLC_REG, bhlcr);
    159 		}
    160 	}
    161 
    162 
    163 	if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_WIDE) &&
    164 	    (command & PCI_COMMAND_PARITY_ENABLE) == 0) {
    165 		sc->cfg.control_flag |= CONTROL_FLAG_IGNORE_PERR;
    166 	}
    167 	/*
    168 	 * Map Device Registers for I/O
    169 	 */
    170 	if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0,
    171 			   &iot, &ioh, NULL, NULL)) {
    172 		printf("%s: unable to map device registers\n",
    173 		       sc->sc_dev.dv_xname);
    174 		return;
    175 	}
    176 	sc->sc_iot = iot;
    177 	sc->sc_ioh = ioh;
    178 	sc->sc_dmat = pa->pa_dmat;
    179 
    180 	/*
    181 	 * Initialize the board
    182 	 */
    183 	if (adw_init(sc))
    184 		panic("adw_pci_attach: adw_init failed");
    185 
    186 	/*
    187 	 * Map Interrupt line
    188 	 */
    189 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    190 			 pa->pa_intrline, &ih)) {
    191 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    192 		return;
    193 	}
    194 	intrstr = pci_intr_string(pc, ih);
    195 
    196 	/*
    197 	 * Establish Interrupt handler
    198 	 */
    199 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adw_intr, sc);
    200 	if (sc->sc_ih == NULL) {
    201 		printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
    202 		if (intrstr != NULL)
    203 			printf(" at %s", intrstr);
    204 		printf("\n");
    205 		return;
    206 	}
    207 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    208 
    209 	/*
    210 	 * Attach all the sub-devices we can find
    211 	 */
    212 	adw_attach(sc);
    213 }
    214 /******************************************************************************/
    215