Home | History | Annotate | Line # | Download | only in pci
siop_pci_common.c revision 1.34.18.1
      1       1.34  uebayasi /*	$NetBSD: siop_pci_common.c,v 1.34.18.1 2014/08/20 00:03:48 tls Exp $	*/
      2        1.1    bouyer 
      3        1.1    bouyer /*
      4        1.1    bouyer  * Copyright (c) 2000 Manuel Bouyer.
      5        1.1    bouyer  *
      6        1.1    bouyer  * Redistribution and use in source and binary forms, with or without
      7        1.1    bouyer  * modification, are permitted provided that the following conditions
      8        1.1    bouyer  * are met:
      9        1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     10        1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     11        1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     13        1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     14        1.1    bouyer  *
     15        1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16        1.1    bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17        1.1    bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18       1.24     perry  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19        1.1    bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20        1.1    bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21        1.1    bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22        1.1    bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23        1.1    bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24        1.1    bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25        1.1    bouyer  */
     26        1.1    bouyer 
     27        1.1    bouyer /* SYM53c8xx PCI-SCSI I/O Processors driver: PCI front-end */
     28        1.9     lukem 
     29        1.9     lukem #include <sys/cdefs.h>
     30       1.34  uebayasi __KERNEL_RCSID(0, "$NetBSD: siop_pci_common.c,v 1.34.18.1 2014/08/20 00:03:48 tls Exp $");
     31        1.1    bouyer 
     32        1.1    bouyer #include <sys/param.h>
     33        1.1    bouyer #include <sys/systm.h>
     34        1.1    bouyer #include <sys/device.h>
     35        1.1    bouyer #include <sys/malloc.h>
     36        1.1    bouyer #include <sys/buf.h>
     37        1.1    bouyer #include <sys/kernel.h>
     38       1.19   thorpej 
     39        1.1    bouyer #include <machine/endian.h>
     40        1.1    bouyer 
     41        1.1    bouyer #include <dev/pci/pcireg.h>
     42        1.1    bouyer #include <dev/pci/pcivar.h>
     43        1.1    bouyer #include <dev/pci/pcidevs.h>
     44        1.1    bouyer 
     45        1.1    bouyer #include <dev/scsipi/scsipi_all.h>
     46        1.1    bouyer #include <dev/scsipi/scsipiconf.h>
     47        1.1    bouyer 
     48        1.1    bouyer #include <dev/ic/siopreg.h>
     49       1.11    bouyer #include <dev/ic/siopvar_common.h>
     50        1.1    bouyer #include <dev/pci/siop_pci_common.h>
     51        1.1    bouyer 
     52        1.1    bouyer /* List (array, really :) of chips we know how to handle */
     53       1.25   thorpej static const struct siop_product_desc siop_products[] = {
     54        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_810,
     55        1.1    bouyer 	0x00,
     56        1.1    bouyer 	"Symbios Logic 53c810 (fast scsi)",
     57        1.1    bouyer 	SF_PCI_RL | SF_CHIP_LS,
     58        1.3    bouyer 	4, 8, 3, 250, 0
     59        1.1    bouyer 	},
     60        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_810,
     61        1.1    bouyer 	0x10,
     62        1.1    bouyer 	"Symbios Logic 53c810a (fast scsi)",
     63        1.1    bouyer 	SF_PCI_RL | SF_PCI_BOF | SF_CHIP_PF | SF_CHIP_LS,
     64        1.3    bouyer 	4, 8, 3, 250, 0
     65        1.1    bouyer 	},
     66        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_815,
     67        1.1    bouyer 	0x00,
     68        1.1    bouyer 	"Symbios Logic 53c815 (fast scsi)",
     69        1.1    bouyer 	SF_PCI_RL | SF_PCI_BOF,
     70        1.3    bouyer 	4, 8, 3, 250, 0
     71        1.1    bouyer 	},
     72        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_820,
     73        1.1    bouyer 	0x00,
     74        1.1    bouyer 	"Symbios Logic 53c820 (fast wide scsi)",
     75        1.1    bouyer 	SF_PCI_RL | SF_CHIP_LS | SF_BUS_WIDE,
     76        1.3    bouyer 	4, 8, 3, 250, 0
     77        1.1    bouyer 	},
     78        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_825,
     79        1.1    bouyer 	0x00,
     80        1.1    bouyer 	"Symbios Logic 53c825 (fast wide scsi)",
     81        1.1    bouyer 	SF_PCI_RL | SF_PCI_BOF | SF_BUS_WIDE,
     82        1.3    bouyer 	4, 8, 3, 250, 0
     83        1.1    bouyer 	},
     84        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_825,
     85        1.1    bouyer 	0x10,
     86        1.1    bouyer 	"Symbios Logic 53c825a (fast wide scsi)",
     87        1.1    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
     88        1.1    bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_LS | SF_CHIP_10REGS |
     89        1.1    bouyer 	SF_BUS_WIDE,
     90        1.3    bouyer 	7, 8, 3, 250, 4096
     91        1.1    bouyer 	},
     92        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_860,
     93        1.1    bouyer 	0x00,
     94        1.1    bouyer 	"Symbios Logic 53c860 (ultra scsi)",
     95        1.1    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
     96        1.1    bouyer 	SF_CHIP_PF | SF_CHIP_LS |
     97        1.1    bouyer 	SF_BUS_ULTRA,
     98        1.3    bouyer 	4, 8, 5, 125, 0
     99        1.1    bouyer 	},
    100        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_875,
    101        1.1    bouyer 	0x00,
    102        1.1    bouyer 	"Symbios Logic 53c875 (ultra-wide scsi)",
    103        1.1    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    104        1.1    bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_LS | SF_CHIP_10REGS |
    105        1.1    bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    106        1.3    bouyer 	7, 16, 5, 125, 4096
    107        1.1    bouyer 	},
    108        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_875,
    109        1.1    bouyer 	0x02,
    110        1.1    bouyer 	"Symbios Logic 53c875 (ultra-wide scsi)",
    111        1.1    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    112        1.1    bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
    113        1.1    bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    114        1.1    bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    115        1.3    bouyer 	7, 16, 5, 125, 4096
    116        1.1    bouyer 	},
    117        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_875J,
    118        1.1    bouyer 	0x00,
    119        1.1    bouyer 	"Symbios Logic 53c875j (ultra-wide scsi)",
    120        1.1    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    121        1.1    bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
    122        1.1    bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    123        1.1    bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    124        1.3    bouyer 	7, 16, 5, 125, 4096
    125        1.1    bouyer 	},
    126        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_885,
    127        1.1    bouyer 	0x00,
    128        1.1    bouyer 	"Symbios Logic 53c885 (ultra-wide scsi)",
    129        1.1    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    130        1.1    bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
    131        1.1    bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    132        1.1    bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    133        1.3    bouyer 	7, 16, 5, 125, 4096
    134        1.1    bouyer 	},
    135        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_895,
    136        1.1    bouyer 	0x00,
    137        1.1    bouyer 	"Symbios Logic 53c895 (ultra2-wide scsi)",
    138        1.1    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    139        1.1    bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
    140        1.1    bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    141        1.1    bouyer 	SF_BUS_ULTRA2 | SF_BUS_WIDE,
    142        1.3    bouyer 	7, 31, 7, 62, 4096
    143        1.1    bouyer 	},
    144        1.1    bouyer 	{ PCI_PRODUCT_SYMBIOS_896,
    145        1.1    bouyer 	0x00,
    146        1.1    bouyer 	"Symbios Logic 53c896 (ultra2-wide scsi)",
    147        1.1    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    148       1.12    bouyer 	SF_CHIP_LEDC | SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
    149        1.1    bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    150        1.1    bouyer 	SF_BUS_ULTRA2 | SF_BUS_WIDE,
    151        1.3    bouyer 	7, 31, 7, 62, 8192
    152        1.6   thorpej 	},
    153        1.6   thorpej 	{ PCI_PRODUCT_SYMBIOS_895A,
    154        1.6   thorpej 	0x00,
    155        1.6   thorpej 	"Symbios Logic 53c895a (ultra2-wide scsi)",
    156        1.6   thorpej 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    157       1.12    bouyer 	SF_CHIP_LEDC | SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
    158        1.6   thorpej 	SF_CHIP_LS | SF_CHIP_10REGS |
    159        1.6   thorpej 	SF_BUS_ULTRA2 | SF_BUS_WIDE,
    160        1.7    bouyer 	7, 31, 7, 62, 8192
    161        1.7    bouyer 	},
    162        1.7    bouyer 	{ PCI_PRODUCT_SYMBIOS_1010,
    163        1.7    bouyer 	0x00,
    164       1.16   thorpej 	"Symbios Logic 53c1010-33 rev 0 (ultra3-wide scsi)",
    165       1.14    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    166       1.14    bouyer 	SF_CHIP_LEDC | SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM |
    167       1.14    bouyer 	SF_CHIP_LS | SF_CHIP_10REGS | SF_CHIP_DFBC | SF_CHIP_DBLR |
    168       1.17    bouyer 	SF_CHIP_GEBUG |
    169       1.14    bouyer 	SF_BUS_ULTRA3 | SF_BUS_WIDE,
    170       1.14    bouyer 	7, 31, 0, 62, 8192
    171       1.14    bouyer 	},
    172       1.14    bouyer 	{ PCI_PRODUCT_SYMBIOS_1010,
    173       1.14    bouyer 	0x01,
    174       1.16   thorpej 	"Symbios Logic 53c1010-33 (ultra3-wide scsi)",
    175       1.10    briggs 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    176       1.12    bouyer 	SF_CHIP_LEDC | SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM |
    177       1.14    bouyer 	SF_CHIP_LS | SF_CHIP_10REGS | SF_CHIP_DFBC | SF_CHIP_DBLR | SF_CHIP_DT |
    178       1.17    bouyer 	SF_CHIP_GEBUG |
    179       1.14    bouyer 	SF_BUS_ULTRA3 | SF_BUS_WIDE,
    180       1.14    bouyer 	7, 62, 0, 62, 8192
    181       1.10    briggs 	},
    182       1.10    briggs 	{ PCI_PRODUCT_SYMBIOS_1010_2,
    183       1.10    briggs 	0x00,
    184       1.16   thorpej 	"Symbios Logic 53c1010-66 (ultra3-wide scsi)",
    185        1.7    bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    186       1.12    bouyer 	SF_CHIP_LEDC | SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM |
    187       1.14    bouyer 	SF_CHIP_LS | SF_CHIP_10REGS | SF_CHIP_DFBC | SF_CHIP_DBLR | SF_CHIP_DT |
    188       1.22    bouyer 	SF_CHIP_AAIP |
    189       1.24     perry 	SF_BUS_ULTRA3 | SF_BUS_WIDE,
    190       1.14    bouyer 	7, 62, 0, 62, 8192
    191        1.6   thorpej 	},
    192        1.6   thorpej 	{ PCI_PRODUCT_SYMBIOS_1510D,
    193        1.6   thorpej 	0x00,
    194        1.6   thorpej 	"Symbios Logic 53c1510d (ultra2-wide scsi)",
    195        1.6   thorpej 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    196        1.6   thorpej 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
    197        1.6   thorpej 	SF_CHIP_LS | SF_CHIP_10REGS |
    198        1.6   thorpej 	SF_BUS_ULTRA2 | SF_BUS_WIDE,
    199        1.6   thorpej 	7, 31, 7, 62, 4096
    200        1.1    bouyer 	},
    201        1.1    bouyer 	{ 0,
    202        1.1    bouyer 	0x00,
    203        1.1    bouyer 	NULL,
    204        1.1    bouyer 	0x00,
    205        1.3    bouyer 	0, 0, 0, 0, 0
    206        1.1    bouyer 	},
    207        1.1    bouyer };
    208        1.1    bouyer 
    209        1.1    bouyer const struct siop_product_desc *
    210       1.31   tsutsui siop_lookup_product(uint32_t id, int rev)
    211        1.1    bouyer {
    212        1.1    bouyer 	const struct siop_product_desc *pp;
    213        1.1    bouyer 	const struct siop_product_desc *rp = NULL;
    214        1.1    bouyer 
    215        1.1    bouyer 	if (PCI_VENDOR(id) != PCI_VENDOR_SYMBIOS)
    216        1.1    bouyer 		return NULL;
    217        1.1    bouyer 
    218        1.1    bouyer 	for (pp = siop_products; pp->name != NULL; pp++) {
    219        1.1    bouyer 		if (PCI_PRODUCT(id) == pp->product && pp->revision <= rev)
    220        1.1    bouyer 			if (rp == NULL || pp->revision > rp->revision)
    221        1.1    bouyer 				rp = pp;
    222        1.1    bouyer 	}
    223        1.1    bouyer 	return rp;
    224        1.1    bouyer }
    225        1.1    bouyer 
    226        1.1    bouyer int
    227       1.25   thorpej siop_pci_attach_common(struct siop_pci_common_softc *pci_sc,
    228       1.25   thorpej     struct siop_common_softc *siop_sc, struct pci_attach_args *pa,
    229       1.25   thorpej     int (*intr)(void *))
    230        1.1    bouyer {
    231        1.1    bouyer 	pci_chipset_tag_t pc = pa->pa_pc;
    232       1.24     perry 	pcitag_t tag = pa->pa_tag;
    233        1.1    bouyer 	const char *intrstr;
    234        1.1    bouyer 	pci_intr_handle_t intrhandle;
    235        1.1    bouyer 	bus_space_tag_t iot, memt;
    236        1.1    bouyer 	bus_space_handle_t ioh, memh;
    237        1.1    bouyer 	pcireg_t memtype;
    238       1.28  kiyohara 	prop_dictionary_t dict;
    239        1.1    bouyer 	int memh_valid, ioh_valid;
    240        1.1    bouyer 	bus_addr_t ioaddr, memaddr;
    241       1.28  kiyohara 	bool use_pciclock;
    242  1.34.18.1       tls 	char intrbuf[PCI_INTRSTR_LEN];
    243        1.1    bouyer 
    244       1.18   thorpej 	aprint_naive(": SCSI controller\n");
    245       1.18   thorpej 
    246       1.11    bouyer 	pci_sc->sc_pp =
    247       1.11    bouyer 	    siop_lookup_product(pa->pa_id, PCI_REVISION(pa->pa_class));
    248       1.11    bouyer 	if (pci_sc->sc_pp == NULL) {
    249       1.18   thorpej 		aprint_error("sym: broken match/attach!!\n");
    250        1.1    bouyer 		return 0;
    251        1.1    bouyer 	}
    252        1.2    bouyer 	/* copy interesting infos about the chip */
    253       1.11    bouyer 	siop_sc->features = pci_sc->sc_pp->features;
    254       1.13    bouyer #ifdef SIOP_SYMLED    /* XXX Should be a devprop! */
    255       1.13    bouyer 	siop_sc->features |= SF_CHIP_LED0;
    256       1.13    bouyer #endif
    257       1.30   tsutsui 	dict = device_properties(siop_sc->sc_dev);
    258       1.28  kiyohara 	if (prop_dictionary_get_bool(dict, "use_pciclock", &use_pciclock))
    259       1.28  kiyohara 		if (use_pciclock)
    260       1.28  kiyohara 			siop_sc->features |= SF_CHIP_USEPCIC;
    261       1.11    bouyer 	siop_sc->maxburst = pci_sc->sc_pp->maxburst;
    262       1.11    bouyer 	siop_sc->maxoff = pci_sc->sc_pp->maxoff;
    263       1.11    bouyer 	siop_sc->clock_div = pci_sc->sc_pp->clock_div;
    264       1.11    bouyer 	siop_sc->clock_period = pci_sc->sc_pp->clock_period;
    265       1.11    bouyer 	siop_sc->ram_size = pci_sc->sc_pp->ram_size;
    266       1.11    bouyer 
    267       1.11    bouyer 	siop_sc->sc_reset = siop_pci_reset;
    268       1.18   thorpej 	aprint_normal(": %s\n", pci_sc->sc_pp->name);
    269       1.11    bouyer 	pci_sc->sc_pc = pc;
    270       1.11    bouyer 	pci_sc->sc_tag = tag;
    271       1.11    bouyer 	siop_sc->sc_dmat = pa->pa_dmat;
    272        1.1    bouyer 
    273        1.1    bouyer 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, 0x14);
    274        1.1    bouyer 	switch (memtype) {
    275        1.1    bouyer 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
    276        1.1    bouyer 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
    277        1.1    bouyer 		memh_valid = (pci_mapreg_map(pa, 0x14, memtype, 0,
    278        1.1    bouyer 		    &memt, &memh, &memaddr, NULL) == 0);
    279        1.1    bouyer 		break;
    280        1.1    bouyer 	default:
    281        1.1    bouyer 		memh_valid = 0;
    282        1.1    bouyer 	}
    283        1.1    bouyer 
    284        1.1    bouyer 	ioh_valid = (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_IO, 0,
    285        1.1    bouyer 	    &iot, &ioh, &ioaddr, NULL) == 0);
    286        1.1    bouyer 
    287        1.1    bouyer 	if (memh_valid) {
    288       1.11    bouyer 		siop_sc->sc_rt = memt;
    289       1.11    bouyer 		siop_sc->sc_rh = memh;
    290       1.11    bouyer 		siop_sc->sc_raddr = memaddr;
    291        1.1    bouyer 	} else if (ioh_valid) {
    292       1.11    bouyer 		siop_sc->sc_rt = iot;
    293       1.11    bouyer 		siop_sc->sc_rh = ioh;
    294       1.11    bouyer 		siop_sc->sc_raddr = ioaddr;
    295        1.1    bouyer 	} else {
    296       1.31   tsutsui 		aprint_error_dev(siop_sc->sc_dev,
    297       1.31   tsutsui 		    "unable to map device registers\n");
    298        1.1    bouyer 		return 0;
    299        1.1    bouyer 	}
    300        1.1    bouyer 
    301       1.11    bouyer 	if (siop_sc->features & SF_CHIP_RAM) {
    302        1.4      matt 		int bar;
    303        1.4      matt 		switch (memtype) {
    304        1.4      matt 		case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
    305        1.4      matt 			bar = 0x18;
    306        1.4      matt 			break;
    307        1.4      matt 		case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
    308        1.4      matt 			bar = 0x1c;
    309       1.20  christos 			break;
    310       1.20  christos 		default:
    311       1.31   tsutsui 			aprint_error_dev(siop_sc->sc_dev,
    312       1.31   tsutsui 			    "invalid memory type %d\n",
    313       1.27    cegger 			    memtype);
    314       1.21  christos 			return 0;
    315        1.4      matt 		}
    316        1.4      matt 		if (pci_mapreg_map(pa, bar, memtype, 0,
    317       1.11    bouyer                     &siop_sc->sc_ramt, &siop_sc->sc_ramh,
    318       1.11    bouyer 		    &siop_sc->sc_scriptaddr, NULL) == 0) {
    319       1.31   tsutsui 			aprint_normal_dev(siop_sc->sc_dev,
    320       1.31   tsutsui 			    "using on-board RAM\n");
    321        1.2    bouyer 		} else {
    322       1.31   tsutsui 			aprint_error_dev(siop_sc->sc_dev,
    323       1.31   tsutsui 			    "can't map on-board RAM\n");
    324       1.11    bouyer 			siop_sc->features &= ~SF_CHIP_RAM;
    325        1.2    bouyer 		}
    326        1.2    bouyer 	}
    327        1.2    bouyer 
    328        1.5  sommerfe 	if (pci_intr_map(pa, &intrhandle) != 0) {
    329       1.30   tsutsui 		aprint_error_dev(siop_sc->sc_dev, "couldn't map interrupt\n");
    330        1.1    bouyer 		return 0;
    331        1.1    bouyer 	}
    332  1.34.18.1       tls 	intrstr = pci_intr_string(pa->pa_pc, intrhandle, intrbuf, sizeof(intrbuf));
    333       1.11    bouyer 	pci_sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_BIO,
    334       1.11    bouyer 	    intr, siop_sc);
    335       1.11    bouyer 	if (pci_sc->sc_ih != NULL) {
    336       1.30   tsutsui 		aprint_normal_dev(siop_sc->sc_dev, "interrupting at %s\n",
    337        1.1    bouyer 		    intrstr ? intrstr : "unknown interrupt");
    338        1.1    bouyer 	} else {
    339       1.31   tsutsui 		aprint_error_dev(siop_sc->sc_dev,
    340       1.31   tsutsui 		    "couldn't establish interrupt");
    341        1.1    bouyer 		if (intrstr != NULL)
    342       1.33     njoly 			aprint_error(" at %s", intrstr);
    343       1.33     njoly 		aprint_error("\n");
    344        1.1    bouyer 		return 0;
    345        1.1    bouyer 	}
    346       1.29    bouyer 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    347       1.29    bouyer 	    pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    348       1.29    bouyer 	    PCI_COMMAND_MASTER_ENABLE);
    349        1.1    bouyer 	return 1;
    350        1.1    bouyer }
    351        1.1    bouyer 
    352        1.1    bouyer void
    353       1.25   thorpej siop_pci_reset(struct siop_common_softc *sc)
    354        1.1    bouyer {
    355        1.1    bouyer 	int dmode;
    356        1.1    bouyer 
    357        1.1    bouyer 	dmode = bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_DMODE);
    358        1.1    bouyer 	if (sc->features & SF_PCI_RL)
    359        1.1    bouyer 		dmode |= DMODE_ERL;
    360        1.1    bouyer 	if (sc->features & SF_PCI_RM)
    361        1.1    bouyer 		dmode |= DMODE_ERMP;
    362        1.1    bouyer 	if (sc->features & SF_PCI_BOF)
    363        1.1    bouyer 		dmode |= DMODE_BOF;
    364        1.1    bouyer 	if (sc->features & SF_PCI_CLS)
    365        1.1    bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_DCNTL,
    366        1.1    bouyer 		    bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_DCNTL) |
    367        1.1    bouyer 		    DCNTL_CLSE);
    368        1.1    bouyer 	if (sc->features & SF_PCI_WRI)
    369        1.1    bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3,
    370        1.1    bouyer 		    bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3) |
    371        1.1    bouyer 		    CTEST3_WRIE);
    372        1.1    bouyer 	if (sc->maxburst) {
    373        1.1    bouyer 		int ctest5 = bus_space_read_1(sc->sc_rt, sc->sc_rh,
    374        1.1    bouyer 		    SIOP_CTEST5);
    375        1.1    bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST4,
    376        1.1    bouyer 		    bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST4) &
    377        1.1    bouyer 		    ~CTEST4_BDIS);
    378        1.1    bouyer 		dmode &= ~DMODE_BL_MASK;
    379        1.1    bouyer 		dmode |= ((sc->maxburst - 1) << DMODE_BL_SHIFT) & DMODE_BL_MASK;
    380        1.1    bouyer 		ctest5 &= ~CTEST5_BBCK;
    381        1.1    bouyer 		ctest5 |= (sc->maxburst - 1) & CTEST5_BBCK;
    382        1.1    bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST5, ctest5);
    383        1.1    bouyer 	} else {
    384        1.1    bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST4,
    385        1.1    bouyer 		    bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST4) |
    386        1.1    bouyer 		    CTEST4_BDIS);
    387        1.1    bouyer 	}
    388        1.1    bouyer 	bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_DMODE, dmode);
    389        1.1    bouyer }
    390