Home | History | Annotate | Line # | Download | only in pci
icp_pci.c revision 1.2.6.2
      1  1.2.6.2  nathanw /*	$NetBSD: icp_pci.c,v 1.2.6.2 2002/06/20 03:45:23 nathanw Exp $	*/
      2  1.2.6.2  nathanw 
      3  1.2.6.2  nathanw /*-
      4  1.2.6.2  nathanw  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  1.2.6.2  nathanw  * All rights reserved.
      6  1.2.6.2  nathanw  *
      7  1.2.6.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.6.2  nathanw  * by Andrew Doran.
      9  1.2.6.2  nathanw  *
     10  1.2.6.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.2.6.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.2.6.2  nathanw  * are met:
     13  1.2.6.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.2.6.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.2.6.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.6.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.6.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.2.6.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.2.6.2  nathanw  *    must display the following acknowledgement:
     20  1.2.6.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.2.6.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.2.6.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2.6.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.2.6.2  nathanw  *    from this software without specific prior written permission.
     25  1.2.6.2  nathanw  *
     26  1.2.6.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2.6.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2.6.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2.6.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2.6.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2.6.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2.6.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2.6.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2.6.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2.6.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2.6.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2.6.2  nathanw  */
     38  1.2.6.2  nathanw 
     39  1.2.6.2  nathanw /*
     40  1.2.6.2  nathanw  * Copyright (c) 1999, 2000 Niklas Hallqvist.  All rights reserved.
     41  1.2.6.2  nathanw  *
     42  1.2.6.2  nathanw  * Redistribution and use in source and binary forms, with or without
     43  1.2.6.2  nathanw  * modification, are permitted provided that the following conditions
     44  1.2.6.2  nathanw  * are met:
     45  1.2.6.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     46  1.2.6.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     47  1.2.6.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     48  1.2.6.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     49  1.2.6.2  nathanw  *    documentation and/or other materials provided with the distribution.
     50  1.2.6.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     51  1.2.6.2  nathanw  *    must display the following acknowledgement:
     52  1.2.6.2  nathanw  *	This product includes software developed by Niklas Hallqvist.
     53  1.2.6.2  nathanw  * 4. The name of the author may not be used to endorse or promote products
     54  1.2.6.2  nathanw  *    derived from this software without specific prior written permission.
     55  1.2.6.2  nathanw  *
     56  1.2.6.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     57  1.2.6.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     58  1.2.6.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     59  1.2.6.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     60  1.2.6.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     61  1.2.6.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     62  1.2.6.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     63  1.2.6.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     64  1.2.6.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     65  1.2.6.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     66  1.2.6.2  nathanw  *
     67  1.2.6.2  nathanw  * from OpenBSD: icp_pci.c,v 1.11 2001/06/12 15:40:30 niklas Exp
     68  1.2.6.2  nathanw  */
     69  1.2.6.2  nathanw 
     70  1.2.6.2  nathanw /*
     71  1.2.6.2  nathanw  * This driver would not have written if it was not for the hardware donations
     72  1.2.6.2  nathanw  * from both ICP-Vortex and ko.neT.  I want to thank them for their support.
     73  1.2.6.2  nathanw  *
     74  1.2.6.2  nathanw  * Re-worked for NetBSD by Andrew Doran.  Test hardware kindly supplied by
     75  1.2.6.2  nathanw  * Intel.
     76  1.2.6.2  nathanw  */
     77  1.2.6.2  nathanw 
     78  1.2.6.2  nathanw #include <sys/cdefs.h>
     79  1.2.6.2  nathanw __KERNEL_RCSID(0, "$NetBSD: icp_pci.c,v 1.2.6.2 2002/06/20 03:45:23 nathanw Exp $");
     80  1.2.6.2  nathanw 
     81  1.2.6.2  nathanw #include <sys/param.h>
     82  1.2.6.2  nathanw #include <sys/systm.h>
     83  1.2.6.2  nathanw #include <sys/device.h>
     84  1.2.6.2  nathanw #include <sys/kernel.h>
     85  1.2.6.2  nathanw #include <sys/queue.h>
     86  1.2.6.2  nathanw #include <sys/buf.h>
     87  1.2.6.2  nathanw #include <sys/endian.h>
     88  1.2.6.2  nathanw #include <sys/conf.h>
     89  1.2.6.2  nathanw 
     90  1.2.6.2  nathanw #include <uvm/uvm_extern.h>
     91  1.2.6.2  nathanw 
     92  1.2.6.2  nathanw #include <machine/bus.h>
     93  1.2.6.2  nathanw 
     94  1.2.6.2  nathanw #include <dev/pci/pcireg.h>
     95  1.2.6.2  nathanw #include <dev/pci/pcivar.h>
     96  1.2.6.2  nathanw #include <dev/pci/pcidevs.h>
     97  1.2.6.2  nathanw 
     98  1.2.6.2  nathanw #include <dev/ic/icpreg.h>
     99  1.2.6.2  nathanw #include <dev/ic/icpvar.h>
    100  1.2.6.2  nathanw 
    101  1.2.6.2  nathanw /* Product numbers for Fibre-Channel are greater than or equal to 0x200 */
    102  1.2.6.2  nathanw #define	ICP_PCI_PRODUCT_FC	0x200
    103  1.2.6.2  nathanw 
    104  1.2.6.2  nathanw /* Mapping registers for various areas */
    105  1.2.6.2  nathanw #define	ICP_PCI_DPMEM		0x10
    106  1.2.6.2  nathanw #define	ICP_PCINEW_IOMEM	0x10
    107  1.2.6.2  nathanw #define	ICP_PCINEW_IO		0x14
    108  1.2.6.2  nathanw #define	ICP_PCINEW_DPMEM	0x18
    109  1.2.6.2  nathanw 
    110  1.2.6.2  nathanw /* PCI SRAM structure */
    111  1.2.6.2  nathanw #define	ICP_MAGIC	0x00	/* u_int32_t, controller ID from BIOS */
    112  1.2.6.2  nathanw #define	ICP_NEED_DEINIT	0x04	/* u_int16_t, switch between BIOS/driver */
    113  1.2.6.2  nathanw #define	ICP_SWITCH_SUPPORT 0x06	/* u_int8_t, see ICP_NEED_DEINIT */
    114  1.2.6.2  nathanw #define	ICP_OS_USED	0x10	/* u_int8_t [16], OS code per service */
    115  1.2.6.2  nathanw #define	ICP_FW_MAGIC	0x3c	/* u_int8_t, controller ID from firmware */
    116  1.2.6.2  nathanw #define	ICP_SRAM_SZ	0x40
    117  1.2.6.2  nathanw 
    118  1.2.6.2  nathanw /* DPRAM PCI controllers */
    119  1.2.6.2  nathanw #define	ICP_DPR_IF	0x00	/* interface area */
    120  1.2.6.2  nathanw #define	ICP_6SR		(0xff0 - ICP_SRAM_SZ)
    121  1.2.6.2  nathanw #define	ICP_SEMA1	0xff1	/* volatile u_int8_t, command semaphore */
    122  1.2.6.2  nathanw #define	ICP_IRQEN	0xff5	/* u_int8_t, board interrupts enable */
    123  1.2.6.2  nathanw #define	ICP_EVENT	0xff8	/* u_int8_t, release event */
    124  1.2.6.2  nathanw #define	ICP_IRQDEL	0xffc	/* u_int8_t, acknowledge board interrupt */
    125  1.2.6.2  nathanw #define	ICP_DPRAM_SZ	0x1000
    126  1.2.6.2  nathanw 
    127  1.2.6.2  nathanw /* PLX register structure (new PCI controllers) */
    128  1.2.6.2  nathanw #define	ICP_CFG_REG	0x00	/* u_int8_t, DPRAM cfg. (2: < 1MB, 0: any) */
    129  1.2.6.2  nathanw #define	ICP_SEMA0_REG	0x40	/* volatile u_int8_t, command semaphore */
    130  1.2.6.2  nathanw #define	ICP_SEMA1_REG	0x41	/* volatile u_int8_t, status semaphore */
    131  1.2.6.2  nathanw #define	ICP_PLX_STATUS	0x44	/* volatile u_int16_t, command status */
    132  1.2.6.2  nathanw #define	ICP_PLX_SERVICE	0x46	/* u_int16_t, service */
    133  1.2.6.2  nathanw #define	ICP_PLX_INFO	0x48	/* u_int32_t [2], additional info */
    134  1.2.6.2  nathanw #define	ICP_LDOOR_REG	0x60	/* u_int8_t, PCI to local doorbell */
    135  1.2.6.2  nathanw #define	ICP_EDOOR_REG	0x64	/* volatile u_int8_t, local to PCI doorbell */
    136  1.2.6.2  nathanw #define	ICP_CONTROL0	0x68	/* u_int8_t, control0 register (unused) */
    137  1.2.6.2  nathanw #define	ICP_CONTROL1	0x69	/* u_int8_t, board interrupts enable */
    138  1.2.6.2  nathanw #define	ICP_PLX_SZ	0x80
    139  1.2.6.2  nathanw 
    140  1.2.6.2  nathanw /* DPRAM new PCI controllers */
    141  1.2.6.2  nathanw #define	ICP_IC		0x00	/* interface */
    142  1.2.6.2  nathanw #define	ICP_PCINEW_6SR	(0x4000 - ICP_SRAM_SZ)
    143  1.2.6.2  nathanw 				/* SRAM structure */
    144  1.2.6.2  nathanw #define	ICP_PCINEW_SZ	0x4000
    145  1.2.6.2  nathanw 
    146  1.2.6.2  nathanw /* i960 register structure (PCI MPR controllers) */
    147  1.2.6.2  nathanw #define	ICP_MPR_SEMA0	0x10	/* volatile u_int8_t, command semaphore */
    148  1.2.6.2  nathanw #define	ICP_MPR_SEMA1	0x12	/* volatile u_int8_t, status semaphore */
    149  1.2.6.2  nathanw #define	ICP_MPR_STATUS	0x14	/* volatile u_int16_t, command status */
    150  1.2.6.2  nathanw #define	ICP_MPR_SERVICE	0x16	/* u_int16_t, service */
    151  1.2.6.2  nathanw #define	ICP_MPR_INFO	0x18	/* u_int32_t [2], additional info */
    152  1.2.6.2  nathanw #define	ICP_MPR_LDOOR	0x20	/* u_int8_t, PCI to local doorbell */
    153  1.2.6.2  nathanw #define	ICP_MPR_EDOOR	0x2c	/* volatile u_int8_t, locl to PCI doorbell */
    154  1.2.6.2  nathanw #define	ICP_EDOOR_EN	0x34	/* u_int8_t, board interrupts enable */
    155  1.2.6.2  nathanw #define	ICP_I960_SZ	0x1000
    156  1.2.6.2  nathanw 
    157  1.2.6.2  nathanw /* DPRAM PCI MPR controllers */
    158  1.2.6.2  nathanw #define	ICP_I960R	0x00	/* 4KB i960 registers */
    159  1.2.6.2  nathanw #define	ICP_MPR_IC	ICP_I960_SZ
    160  1.2.6.2  nathanw 				/* interface area */
    161  1.2.6.2  nathanw #define	ICP_MPR_6SR	(ICP_I960_SZ + 0x3000 - ICP_SRAM_SZ)
    162  1.2.6.2  nathanw 				/* SRAM structure */
    163  1.2.6.2  nathanw #define	ICP_MPR_SZ	0x4000
    164  1.2.6.2  nathanw 
    165  1.2.6.2  nathanw int	icp_pci_match(struct device *, struct cfdata *, void *);
    166  1.2.6.2  nathanw void	icp_pci_attach(struct device *, struct device *, void *);
    167  1.2.6.2  nathanw void	icp_pci_enable_intr(struct icp_softc *);
    168  1.2.6.2  nathanw int	icp_pci_find_class(struct pci_attach_args *);
    169  1.2.6.2  nathanw 
    170  1.2.6.2  nathanw void	icp_pci_copy_cmd(struct icp_softc *, struct icp_ccb *);
    171  1.2.6.2  nathanw u_int8_t icp_pci_get_status(struct icp_softc *);
    172  1.2.6.2  nathanw void	icp_pci_intr(struct icp_softc *, struct icp_intr_ctx *);
    173  1.2.6.2  nathanw void	icp_pci_release_event(struct icp_softc *, struct icp_ccb *);
    174  1.2.6.2  nathanw void	icp_pci_set_sema0(struct icp_softc *);
    175  1.2.6.2  nathanw int	icp_pci_test_busy(struct icp_softc *);
    176  1.2.6.2  nathanw 
    177  1.2.6.2  nathanw void	icp_pcinew_copy_cmd(struct icp_softc *, struct icp_ccb *);
    178  1.2.6.2  nathanw u_int8_t icp_pcinew_get_status(struct icp_softc *);
    179  1.2.6.2  nathanw void	icp_pcinew_intr(struct icp_softc *, struct icp_intr_ctx *);
    180  1.2.6.2  nathanw void	icp_pcinew_release_event(struct icp_softc *, struct icp_ccb *);
    181  1.2.6.2  nathanw void	icp_pcinew_set_sema0(struct icp_softc *);
    182  1.2.6.2  nathanw int	icp_pcinew_test_busy(struct icp_softc *);
    183  1.2.6.2  nathanw 
    184  1.2.6.2  nathanw void	icp_mpr_copy_cmd(struct icp_softc *, struct icp_ccb *);
    185  1.2.6.2  nathanw u_int8_t icp_mpr_get_status(struct icp_softc *);
    186  1.2.6.2  nathanw void	icp_mpr_intr(struct icp_softc *, struct icp_intr_ctx *);
    187  1.2.6.2  nathanw void	icp_mpr_release_event(struct icp_softc *, struct icp_ccb *);
    188  1.2.6.2  nathanw void	icp_mpr_set_sema0(struct icp_softc *);
    189  1.2.6.2  nathanw int	icp_mpr_test_busy(struct icp_softc *);
    190  1.2.6.2  nathanw 
    191  1.2.6.2  nathanw struct cfattach icp_pci_ca = {
    192  1.2.6.2  nathanw 	sizeof(struct icp_softc), icp_pci_match, icp_pci_attach
    193  1.2.6.2  nathanw };
    194  1.2.6.2  nathanw 
    195  1.2.6.2  nathanw struct icp_pci_ident {
    196  1.2.6.2  nathanw 	u_short	gpi_vendor;
    197  1.2.6.2  nathanw 	u_short	gpi_product;
    198  1.2.6.2  nathanw 	u_short	gpi_class;
    199  1.2.6.2  nathanw } const icp_pci_ident[] = {
    200  1.2.6.2  nathanw 	{ PCI_VENDOR_VORTEX,	PCI_PRODUCT_VORTEX_GDT_60x0,	ICP_PCI },
    201  1.2.6.2  nathanw 	{ PCI_VENDOR_VORTEX,	PCI_PRODUCT_VORTEX_GDT_6000B,	ICP_PCI },
    202  1.2.6.2  nathanw 
    203  1.2.6.2  nathanw 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_GDT_RAID1,	ICP_MPR },
    204  1.2.6.2  nathanw 	{ PCI_VENDOR_INTEL,	PCI_PRODUCT_INTEL_GDT_RAID2,	ICP_MPR },
    205  1.2.6.2  nathanw };
    206  1.2.6.2  nathanw 
    207  1.2.6.2  nathanw int
    208  1.2.6.2  nathanw icp_pci_find_class(struct pci_attach_args *pa)
    209  1.2.6.2  nathanw {
    210  1.2.6.2  nathanw 	const struct icp_pci_ident *gpi, *maxgpi;
    211  1.2.6.2  nathanw 
    212  1.2.6.2  nathanw 	gpi = icp_pci_ident;
    213  1.2.6.2  nathanw 	maxgpi = gpi + sizeof(icp_pci_ident) / sizeof(icp_pci_ident[0]);
    214  1.2.6.2  nathanw 
    215  1.2.6.2  nathanw 	for (; gpi < maxgpi; gpi++)
    216  1.2.6.2  nathanw 		if (PCI_VENDOR(pa->pa_id) == gpi->gpi_vendor &&
    217  1.2.6.2  nathanw 		    PCI_PRODUCT(pa->pa_id) == gpi->gpi_product)
    218  1.2.6.2  nathanw 			return (gpi->gpi_class);
    219  1.2.6.2  nathanw 
    220  1.2.6.2  nathanw 	/*
    221  1.2.6.2  nathanw 	 * ICP-Vortex only make RAID controllers, so we employ a heuristic
    222  1.2.6.2  nathanw 	 * to match unlisted boards.
    223  1.2.6.2  nathanw 	 */
    224  1.2.6.2  nathanw 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VORTEX)
    225  1.2.6.2  nathanw 		return (PCI_PRODUCT(pa->pa_id) < 0x100 ? ICP_PCINEW : ICP_MPR);
    226  1.2.6.2  nathanw 
    227  1.2.6.2  nathanw 	return (-1);
    228  1.2.6.2  nathanw }
    229  1.2.6.2  nathanw 
    230  1.2.6.2  nathanw int
    231  1.2.6.2  nathanw icp_pci_match(struct device *parent, struct cfdata *match, void *aux)
    232  1.2.6.2  nathanw {
    233  1.2.6.2  nathanw 	struct pci_attach_args *pa;
    234  1.2.6.2  nathanw 
    235  1.2.6.2  nathanw 	pa = aux;
    236  1.2.6.2  nathanw 
    237  1.2.6.2  nathanw 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_I2O)
    238  1.2.6.2  nathanw 		return (0);
    239  1.2.6.2  nathanw 
    240  1.2.6.2  nathanw 	return (icp_pci_find_class(pa) != -1);
    241  1.2.6.2  nathanw }
    242  1.2.6.2  nathanw 
    243  1.2.6.2  nathanw void
    244  1.2.6.2  nathanw icp_pci_attach(struct device *parent, struct device *self, void *aux)
    245  1.2.6.2  nathanw {
    246  1.2.6.2  nathanw 	struct pci_attach_args *pa;
    247  1.2.6.2  nathanw 	struct icp_softc *icp;
    248  1.2.6.2  nathanw 	bus_space_tag_t dpmemt, iomemt, iot;
    249  1.2.6.2  nathanw 	bus_space_handle_t dpmemh, iomemh, ioh;
    250  1.2.6.2  nathanw 	bus_addr_t dpmembase, iomembase, iobase;
    251  1.2.6.2  nathanw 	bus_size_t dpmemsize, iomemsize, iosize;
    252  1.2.6.2  nathanw 	u_int32_t status;
    253  1.2.6.2  nathanw #define	DPMEM_MAPPED		1
    254  1.2.6.2  nathanw #define	IOMEM_MAPPED		2
    255  1.2.6.2  nathanw #define	IO_MAPPED		4
    256  1.2.6.2  nathanw #define	INTR_ESTABLISHED	8
    257  1.2.6.2  nathanw 	int retries;
    258  1.2.6.2  nathanw 	u_int8_t protocol;
    259  1.2.6.2  nathanw 	pci_intr_handle_t ih;
    260  1.2.6.2  nathanw 	const char *intrstr;
    261  1.2.6.2  nathanw 
    262  1.2.6.2  nathanw 	pa = aux;
    263  1.2.6.2  nathanw 	status = 0;
    264  1.2.6.2  nathanw 	icp = (struct icp_softc *)self;
    265  1.2.6.2  nathanw 	icp->icp_class = icp_pci_find_class(pa);
    266  1.2.6.2  nathanw 
    267  1.2.6.2  nathanw 	printf(": ");
    268  1.2.6.2  nathanw 
    269  1.2.6.2  nathanw 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VORTEX &&
    270  1.2.6.2  nathanw 	    PCI_PRODUCT(pa->pa_id) >= ICP_PCI_PRODUCT_FC)
    271  1.2.6.2  nathanw 		icp->icp_class |= ICP_FC;
    272  1.2.6.2  nathanw 
    273  1.2.6.2  nathanw 	if (pci_mapreg_map(pa,
    274  1.2.6.2  nathanw 	    ICP_CLASS(icp) == ICP_PCINEW ? ICP_PCINEW_DPMEM : ICP_PCI_DPMEM,
    275  1.2.6.2  nathanw 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, &dpmemt,
    276  1.2.6.2  nathanw 	    &dpmemh, &dpmembase, &dpmemsize)) {
    277  1.2.6.2  nathanw 		if (pci_mapreg_map(pa,
    278  1.2.6.2  nathanw 		    ICP_CLASS(icp) == ICP_PCINEW ? ICP_PCINEW_DPMEM :
    279  1.2.6.2  nathanw 		    ICP_PCI_DPMEM,
    280  1.2.6.2  nathanw 		    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT_1M, 0,
    281  1.2.6.2  nathanw 		    &dpmemt, &dpmemh, &dpmembase, &dpmemsize)) {
    282  1.2.6.2  nathanw 			printf("cannot map DPMEM\n");
    283  1.2.6.2  nathanw 			goto bail_out;
    284  1.2.6.2  nathanw 		}
    285  1.2.6.2  nathanw 	}
    286  1.2.6.2  nathanw 	status |= DPMEM_MAPPED;
    287  1.2.6.2  nathanw 	icp->icp_dpmemt = dpmemt;
    288  1.2.6.2  nathanw 	icp->icp_dpmemh = dpmemh;
    289  1.2.6.2  nathanw 	icp->icp_dpmembase = dpmembase;
    290  1.2.6.2  nathanw 	icp->icp_dmat = pa->pa_dmat;
    291  1.2.6.2  nathanw 
    292  1.2.6.2  nathanw 	/*
    293  1.2.6.2  nathanw 	 * The ICP_PCINEW series also has two other regions to map.
    294  1.2.6.2  nathanw 	 */
    295  1.2.6.2  nathanw 	if (ICP_CLASS(icp) == ICP_PCINEW) {
    296  1.2.6.2  nathanw 		if (pci_mapreg_map(pa, ICP_PCINEW_IOMEM, PCI_MAPREG_TYPE_MEM,
    297  1.2.6.2  nathanw 		    0, &iomemt, &iomemh, &iomembase, &iomemsize)) {
    298  1.2.6.2  nathanw 			printf("cannot map memory mapped I/O ports\n");
    299  1.2.6.2  nathanw 			goto bail_out;
    300  1.2.6.2  nathanw 		}
    301  1.2.6.2  nathanw 		status |= IOMEM_MAPPED;
    302  1.2.6.2  nathanw 
    303  1.2.6.2  nathanw 		if (pci_mapreg_map(pa, ICP_PCINEW_IO, PCI_MAPREG_TYPE_IO, 0,
    304  1.2.6.2  nathanw 		    &iot, &ioh, &iobase, &iosize)) {
    305  1.2.6.2  nathanw 			printf("cannot map I/O ports\n");
    306  1.2.6.2  nathanw 			goto bail_out;
    307  1.2.6.2  nathanw 		}
    308  1.2.6.2  nathanw 		status |= IO_MAPPED;
    309  1.2.6.2  nathanw 		icp->icp_iot = iot;
    310  1.2.6.2  nathanw 		icp->icp_ioh = ioh;
    311  1.2.6.2  nathanw 		icp->icp_iobase = iobase;
    312  1.2.6.2  nathanw 	}
    313  1.2.6.2  nathanw 
    314  1.2.6.2  nathanw 	switch (ICP_CLASS(icp)) {
    315  1.2.6.2  nathanw 	case ICP_PCI:
    316  1.2.6.2  nathanw 		bus_space_set_region_4(dpmemt, dpmemh, 0, 0,
    317  1.2.6.2  nathanw 		    ICP_DPR_IF_SZ >> 2);
    318  1.2.6.2  nathanw 		if (bus_space_read_1(dpmemt, dpmemh, 0) != 0) {
    319  1.2.6.2  nathanw 			printf("cannot write to DPMEM\n");
    320  1.2.6.2  nathanw 			goto bail_out;
    321  1.2.6.2  nathanw 		}
    322  1.2.6.2  nathanw 
    323  1.2.6.2  nathanw #if 0
    324  1.2.6.2  nathanw 		/* disable board interrupts, deinit services */
    325  1.2.6.2  nathanw 		icph_writeb(0xff, &dp6_ptr->io.irqdel);
    326  1.2.6.2  nathanw 		icph_writeb(0x00, &dp6_ptr->io.irqen);;
    327  1.2.6.2  nathanw 		icph_writeb(0x00, &dp6_ptr->u.ic.S_Status);
    328  1.2.6.2  nathanw 		icph_writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
    329  1.2.6.2  nathanw 
    330  1.2.6.2  nathanw 		icph_writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
    331  1.2.6.2  nathanw 		icph_writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
    332  1.2.6.2  nathanw 		icph_writeb(0, &dp6_ptr->io.event);
    333  1.2.6.2  nathanw 		retries = INIT_RETRIES;
    334  1.2.6.2  nathanw 		icph_delay(20);
    335  1.2.6.2  nathanw 		while (icph_readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
    336  1.2.6.2  nathanw 		  if (--retries == 0) {
    337  1.2.6.2  nathanw 		    printk("initialization error (DEINIT failed)\n");
    338  1.2.6.2  nathanw 		    icph_munmap(ha->brd);
    339  1.2.6.2  nathanw 		    return 0;
    340  1.2.6.2  nathanw 		  }
    341  1.2.6.2  nathanw 		  icph_delay(1);
    342  1.2.6.2  nathanw 		}
    343  1.2.6.2  nathanw 		prot_ver = (unchar)icph_readl(&dp6_ptr->u.ic.S_Info[0]);
    344  1.2.6.2  nathanw 		icph_writeb(0, &dp6_ptr->u.ic.S_Status);
    345  1.2.6.2  nathanw 		icph_writeb(0xff, &dp6_ptr->io.irqdel);
    346  1.2.6.2  nathanw 		if (prot_ver != PROTOCOL_VERSION) {
    347  1.2.6.2  nathanw 		  printk("illegal protocol version\n");
    348  1.2.6.2  nathanw 		  icph_munmap(ha->brd);
    349  1.2.6.2  nathanw 		  return 0;
    350  1.2.6.2  nathanw 		}
    351  1.2.6.2  nathanw 
    352  1.2.6.2  nathanw 		ha->type = ICP_PCI;
    353  1.2.6.2  nathanw 		ha->ic_all_size = sizeof(dp6_ptr->u);
    354  1.2.6.2  nathanw 
    355  1.2.6.2  nathanw 		/* special command to controller BIOS */
    356  1.2.6.2  nathanw 		icph_writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
    357  1.2.6.2  nathanw 		icph_writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
    358  1.2.6.2  nathanw 		icph_writel(0x01, &dp6_ptr->u.ic.S_Info[2]);
    359  1.2.6.2  nathanw 		icph_writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
    360  1.2.6.2  nathanw 		icph_writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
    361  1.2.6.2  nathanw 		icph_writeb(0, &dp6_ptr->io.event);
    362  1.2.6.2  nathanw 		retries = INIT_RETRIES;
    363  1.2.6.2  nathanw 		icph_delay(20);
    364  1.2.6.2  nathanw 		while (icph_readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
    365  1.2.6.2  nathanw 		  if (--retries == 0) {
    366  1.2.6.2  nathanw 		    printk("initialization error\n");
    367  1.2.6.2  nathanw 		    icph_munmap(ha->brd);
    368  1.2.6.2  nathanw 		    return 0;
    369  1.2.6.2  nathanw 		  }
    370  1.2.6.2  nathanw 		  icph_delay(1);
    371  1.2.6.2  nathanw 		}
    372  1.2.6.2  nathanw 		icph_writeb(0, &dp6_ptr->u.ic.S_Status);
    373  1.2.6.2  nathanw 		icph_writeb(0xff, &dp6_ptr->io.irqdel);
    374  1.2.6.2  nathanw #endif
    375  1.2.6.2  nathanw 
    376  1.2.6.2  nathanw 		icp->icp_ic_all_size = ICP_DPRAM_SZ;
    377  1.2.6.2  nathanw 
    378  1.2.6.2  nathanw 		icp->icp_copy_cmd = icp_pci_copy_cmd;
    379  1.2.6.2  nathanw 		icp->icp_get_status = icp_pci_get_status;
    380  1.2.6.2  nathanw 		icp->icp_intr = icp_pci_intr;
    381  1.2.6.2  nathanw 		icp->icp_release_event = icp_pci_release_event;
    382  1.2.6.2  nathanw 		icp->icp_set_sema0 = icp_pci_set_sema0;
    383  1.2.6.2  nathanw 		icp->icp_test_busy = icp_pci_test_busy;
    384  1.2.6.2  nathanw 
    385  1.2.6.2  nathanw 		break;
    386  1.2.6.2  nathanw 
    387  1.2.6.2  nathanw 	case ICP_PCINEW:
    388  1.2.6.2  nathanw 		bus_space_set_region_4(dpmemt, dpmemh, 0, 0,
    389  1.2.6.2  nathanw 		    ICP_DPR_IF_SZ >> 2);
    390  1.2.6.2  nathanw 		if (bus_space_read_1(dpmemt, dpmemh, 0) != 0) {
    391  1.2.6.2  nathanw 			printf("cannot write to DPMEM\n");
    392  1.2.6.2  nathanw 			goto bail_out;
    393  1.2.6.2  nathanw 		}
    394  1.2.6.2  nathanw 
    395  1.2.6.2  nathanw #if 0
    396  1.2.6.2  nathanw 		/* disable board interrupts, deinit services */
    397  1.2.6.2  nathanw 		outb(0x00,PTR2USHORT(&ha->plx->control1));
    398  1.2.6.2  nathanw 		outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
    399  1.2.6.2  nathanw 
    400  1.2.6.2  nathanw 		icph_writeb(0x00, &dp6c_ptr->u.ic.S_Status);
    401  1.2.6.2  nathanw 		icph_writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
    402  1.2.6.2  nathanw 
    403  1.2.6.2  nathanw 		icph_writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
    404  1.2.6.2  nathanw 		icph_writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
    405  1.2.6.2  nathanw 
    406  1.2.6.2  nathanw 		outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
    407  1.2.6.2  nathanw 
    408  1.2.6.2  nathanw 		retries = INIT_RETRIES;
    409  1.2.6.2  nathanw 		icph_delay(20);
    410  1.2.6.2  nathanw 		while (icph_readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
    411  1.2.6.2  nathanw 		  if (--retries == 0) {
    412  1.2.6.2  nathanw 		    printk("initialization error (DEINIT failed)\n");
    413  1.2.6.2  nathanw 		    icph_munmap(ha->brd);
    414  1.2.6.2  nathanw 		    return 0;
    415  1.2.6.2  nathanw 		  }
    416  1.2.6.2  nathanw 		  icph_delay(1);
    417  1.2.6.2  nathanw 		}
    418  1.2.6.2  nathanw 		prot_ver = (unchar)icph_readl(&dp6c_ptr->u.ic.S_Info[0]);
    419  1.2.6.2  nathanw 		icph_writeb(0, &dp6c_ptr->u.ic.Status);
    420  1.2.6.2  nathanw 		if (prot_ver != PROTOCOL_VERSION) {
    421  1.2.6.2  nathanw 		  printk("illegal protocol version\n");
    422  1.2.6.2  nathanw 		  icph_munmap(ha->brd);
    423  1.2.6.2  nathanw 		  return 0;
    424  1.2.6.2  nathanw 		}
    425  1.2.6.2  nathanw 
    426  1.2.6.2  nathanw 		ha->type = ICP_PCINEW;
    427  1.2.6.2  nathanw 		ha->ic_all_size = sizeof(dp6c_ptr->u);
    428  1.2.6.2  nathanw 
    429  1.2.6.2  nathanw 		/* special command to controller BIOS */
    430  1.2.6.2  nathanw 		icph_writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
    431  1.2.6.2  nathanw 		icph_writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
    432  1.2.6.2  nathanw 		icph_writel(0x01, &dp6c_ptr->u.ic.S_Info[2]);
    433  1.2.6.2  nathanw 		icph_writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
    434  1.2.6.2  nathanw 		icph_writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
    435  1.2.6.2  nathanw 
    436  1.2.6.2  nathanw 		outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
    437  1.2.6.2  nathanw 
    438  1.2.6.2  nathanw 		retries = INIT_RETRIES;
    439  1.2.6.2  nathanw 		icph_delay(20);
    440  1.2.6.2  nathanw 		while (icph_readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
    441  1.2.6.2  nathanw 		  if (--retries == 0) {
    442  1.2.6.2  nathanw 		    printk("initialization error\n");
    443  1.2.6.2  nathanw 		    icph_munmap(ha->brd);
    444  1.2.6.2  nathanw 		    return 0;
    445  1.2.6.2  nathanw 		  }
    446  1.2.6.2  nathanw 		  icph_delay(1);
    447  1.2.6.2  nathanw 		}
    448  1.2.6.2  nathanw 		icph_writeb(0, &dp6c_ptr->u.ic.S_Status);
    449  1.2.6.2  nathanw #endif
    450  1.2.6.2  nathanw 
    451  1.2.6.2  nathanw 		icp->icp_ic_all_size = ICP_PCINEW_SZ;
    452  1.2.6.2  nathanw 
    453  1.2.6.2  nathanw 		icp->icp_copy_cmd = icp_pcinew_copy_cmd;
    454  1.2.6.2  nathanw 		icp->icp_get_status = icp_pcinew_get_status;
    455  1.2.6.2  nathanw 		icp->icp_intr = icp_pcinew_intr;
    456  1.2.6.2  nathanw 		icp->icp_release_event = icp_pcinew_release_event;
    457  1.2.6.2  nathanw 		icp->icp_set_sema0 = icp_pcinew_set_sema0;
    458  1.2.6.2  nathanw 		icp->icp_test_busy = icp_pcinew_test_busy;
    459  1.2.6.2  nathanw 
    460  1.2.6.2  nathanw 		break;
    461  1.2.6.2  nathanw 
    462  1.2.6.2  nathanw 	case ICP_MPR:
    463  1.2.6.2  nathanw 		bus_space_write_4(dpmemt, dpmemh, ICP_MPR_IC, ICP_MPR_MAGIC);
    464  1.2.6.2  nathanw 		if (bus_space_read_4(dpmemt, dpmemh, ICP_MPR_IC) !=
    465  1.2.6.2  nathanw 		    ICP_MPR_MAGIC) {
    466  1.2.6.2  nathanw 			printf("cannot access DPMEM at 0x%lx (shadowed?)\n",
    467  1.2.6.2  nathanw 			    (u_long)dpmembase);
    468  1.2.6.2  nathanw 			goto bail_out;
    469  1.2.6.2  nathanw 		}
    470  1.2.6.2  nathanw 
    471  1.2.6.2  nathanw 		/*
    472  1.2.6.2  nathanw 		 * XXX Here the Linux driver has a weird remapping logic I
    473  1.2.6.2  nathanw 		 * don't understand.  My controller does not need it, and I
    474  1.2.6.2  nathanw 		 * cannot see what purpose it serves, therefore I did not
    475  1.2.6.2  nathanw 		 * do anything similar.
    476  1.2.6.2  nathanw 		 */
    477  1.2.6.2  nathanw 
    478  1.2.6.2  nathanw 		bus_space_set_region_4(dpmemt, dpmemh, ICP_I960_SZ, 0,
    479  1.2.6.2  nathanw 		    ICP_DPR_IF_SZ >> 2);
    480  1.2.6.2  nathanw 
    481  1.2.6.2  nathanw 		/* Disable everything. */
    482  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_EDOOR_EN,
    483  1.2.6.2  nathanw 		    bus_space_read_1(dpmemt, dpmemh, ICP_EDOOR_EN) | 4);
    484  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_MPR_EDOOR, 0xff);
    485  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_MPR_IC + ICP_S_STATUS,
    486  1.2.6.2  nathanw 		    0);
    487  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_MPR_IC + ICP_CMD_INDEX,
    488  1.2.6.2  nathanw 		    0);
    489  1.2.6.2  nathanw 
    490  1.2.6.2  nathanw 		bus_space_write_4(dpmemt, dpmemh, ICP_MPR_IC + ICP_S_INFO,
    491  1.2.6.2  nathanw 		    htole32(dpmembase));
    492  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_MPR_IC + ICP_S_CMD_INDX,
    493  1.2.6.2  nathanw 		    0xff);
    494  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_MPR_LDOOR, 1);
    495  1.2.6.2  nathanw 
    496  1.2.6.2  nathanw 		DELAY(20);
    497  1.2.6.2  nathanw 		retries = 1000000;
    498  1.2.6.2  nathanw 		while (bus_space_read_1(dpmemt, dpmemh,
    499  1.2.6.2  nathanw 		    ICP_MPR_IC + ICP_S_STATUS) != 0xff) {
    500  1.2.6.2  nathanw 			if (--retries == 0) {
    501  1.2.6.2  nathanw 				printf("DEINIT failed\n");
    502  1.2.6.2  nathanw 				goto bail_out;
    503  1.2.6.2  nathanw 			}
    504  1.2.6.2  nathanw 			DELAY(1);
    505  1.2.6.2  nathanw 		}
    506  1.2.6.2  nathanw 
    507  1.2.6.2  nathanw 		protocol = (u_int8_t)bus_space_read_4(dpmemt, dpmemh,
    508  1.2.6.2  nathanw 		    ICP_MPR_IC + ICP_S_INFO);
    509  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_MPR_IC + ICP_S_STATUS,
    510  1.2.6.2  nathanw 		    0);
    511  1.2.6.2  nathanw 		if (protocol != ICP_PROTOCOL_VERSION) {
    512  1.2.6.2  nathanw 		 	printf("unsupported protocol %d\n", protocol);
    513  1.2.6.2  nathanw 			goto bail_out;
    514  1.2.6.2  nathanw 		}
    515  1.2.6.2  nathanw 
    516  1.2.6.2  nathanw 		/* special commnd to controller BIOS */
    517  1.2.6.2  nathanw 		bus_space_write_4(dpmemt, dpmemh, ICP_MPR_IC + ICP_S_INFO, 0);
    518  1.2.6.2  nathanw 		bus_space_write_4(dpmemt, dpmemh,
    519  1.2.6.2  nathanw 		    ICP_MPR_IC + ICP_S_INFO + sizeof(u_int32_t), 0);
    520  1.2.6.2  nathanw 		bus_space_write_4(dpmemt, dpmemh,
    521  1.2.6.2  nathanw 		    ICP_MPR_IC + ICP_S_INFO + 2 * sizeof(u_int32_t), 1);
    522  1.2.6.2  nathanw 		bus_space_write_4(dpmemt, dpmemh,
    523  1.2.6.2  nathanw 		    ICP_MPR_IC + ICP_S_INFO + 3 * sizeof(u_int32_t), 0);
    524  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_MPR_IC + ICP_S_CMD_INDX,
    525  1.2.6.2  nathanw 		    0xfe);
    526  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_MPR_LDOOR, 1);
    527  1.2.6.2  nathanw 
    528  1.2.6.2  nathanw 		DELAY(20);
    529  1.2.6.2  nathanw 		retries = 1000000;
    530  1.2.6.2  nathanw 		while (bus_space_read_1(dpmemt, dpmemh,
    531  1.2.6.2  nathanw 		    ICP_MPR_IC + ICP_S_STATUS) != 0xfe) {
    532  1.2.6.2  nathanw 			if (--retries == 0) {
    533  1.2.6.2  nathanw 				printf("initialization error\n");
    534  1.2.6.2  nathanw 				goto bail_out;
    535  1.2.6.2  nathanw 			}
    536  1.2.6.2  nathanw 			DELAY(1);
    537  1.2.6.2  nathanw 		}
    538  1.2.6.2  nathanw 
    539  1.2.6.2  nathanw 		bus_space_write_1(dpmemt, dpmemh, ICP_MPR_IC + ICP_S_STATUS,
    540  1.2.6.2  nathanw 		    0);
    541  1.2.6.2  nathanw 
    542  1.2.6.2  nathanw 		icp->icp_copy_cmd = icp_mpr_copy_cmd;
    543  1.2.6.2  nathanw 		icp->icp_get_status = icp_mpr_get_status;
    544  1.2.6.2  nathanw 		icp->icp_intr = icp_mpr_intr;
    545  1.2.6.2  nathanw 		icp->icp_release_event = icp_mpr_release_event;
    546  1.2.6.2  nathanw 		icp->icp_set_sema0 = icp_mpr_set_sema0;
    547  1.2.6.2  nathanw 		icp->icp_test_busy = icp_mpr_test_busy;
    548  1.2.6.2  nathanw 		break;
    549  1.2.6.2  nathanw 	}
    550  1.2.6.2  nathanw 
    551  1.2.6.2  nathanw 	if (pci_intr_map(pa, &ih)) {
    552  1.2.6.2  nathanw 		printf("couldn't map interrupt\n");
    553  1.2.6.2  nathanw 		goto bail_out;
    554  1.2.6.2  nathanw 	}
    555  1.2.6.2  nathanw 	intrstr = pci_intr_string(pa->pa_pc, ih);
    556  1.2.6.2  nathanw 	icp->icp_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, icp_intr, icp);
    557  1.2.6.2  nathanw 	if (icp->icp_ih == NULL) {
    558  1.2.6.2  nathanw 		printf("couldn't establish interrupt");
    559  1.2.6.2  nathanw 		if (intrstr != NULL)
    560  1.2.6.2  nathanw 			printf(" at %s", intrstr);
    561  1.2.6.2  nathanw 		printf("\n");
    562  1.2.6.2  nathanw 		goto bail_out;
    563  1.2.6.2  nathanw 	}
    564  1.2.6.2  nathanw 	status |= INTR_ESTABLISHED;
    565  1.2.6.2  nathanw 
    566  1.2.6.2  nathanw 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL)
    567  1.2.6.2  nathanw 		printf("Intel Storage RAID controller\n");
    568  1.2.6.2  nathanw 	else
    569  1.2.6.2  nathanw 		printf("ICP-Vortex RAID controller\n");
    570  1.2.6.2  nathanw 
    571  1.2.6.2  nathanw 	if (icp_init(icp, intrstr))
    572  1.2.6.2  nathanw 		goto bail_out;
    573  1.2.6.2  nathanw 
    574  1.2.6.2  nathanw 	icp_pci_enable_intr(icp);
    575  1.2.6.2  nathanw 	return;
    576  1.2.6.2  nathanw 
    577  1.2.6.2  nathanw  bail_out:
    578  1.2.6.2  nathanw 	if ((status & DPMEM_MAPPED) != 0)
    579  1.2.6.2  nathanw 		bus_space_unmap(dpmemt, dpmemh, dpmemsize);
    580  1.2.6.2  nathanw 	if ((status & IOMEM_MAPPED) != 0)
    581  1.2.6.2  nathanw 		bus_space_unmap(iomemt, iomemh, iomembase);
    582  1.2.6.2  nathanw 	if ((status & IO_MAPPED) != 0)
    583  1.2.6.2  nathanw 		bus_space_unmap(iot, ioh, iosize);
    584  1.2.6.2  nathanw 	if ((status & INTR_ESTABLISHED) != 0)
    585  1.2.6.2  nathanw 		pci_intr_disestablish(pa->pa_pc, icp->icp_ih);
    586  1.2.6.2  nathanw }
    587  1.2.6.2  nathanw 
    588  1.2.6.2  nathanw /*
    589  1.2.6.2  nathanw  * Enable interrupts.
    590  1.2.6.2  nathanw  */
    591  1.2.6.2  nathanw void
    592  1.2.6.2  nathanw icp_pci_enable_intr(struct icp_softc *icp)
    593  1.2.6.2  nathanw {
    594  1.2.6.2  nathanw 
    595  1.2.6.2  nathanw 	switch (ICP_CLASS(icp)) {
    596  1.2.6.2  nathanw 	case ICP_PCI:
    597  1.2.6.2  nathanw 		bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh, ICP_IRQDEL,
    598  1.2.6.2  nathanw 		    1);
    599  1.2.6.2  nathanw 		bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh,
    600  1.2.6.2  nathanw 		    ICP_CMD_INDEX, 0);
    601  1.2.6.2  nathanw 		bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh, ICP_IRQEN,
    602  1.2.6.2  nathanw 		    1);
    603  1.2.6.2  nathanw 		break;
    604  1.2.6.2  nathanw 
    605  1.2.6.2  nathanw 	case ICP_PCINEW:
    606  1.2.6.2  nathanw 		bus_space_write_1(icp->icp_iot, icp->icp_ioh, ICP_EDOOR_REG,
    607  1.2.6.2  nathanw 		    0xff);
    608  1.2.6.2  nathanw 		bus_space_write_1(icp->icp_iot, icp->icp_ioh, ICP_CONTROL1, 3);
    609  1.2.6.2  nathanw 		break;
    610  1.2.6.2  nathanw 
    611  1.2.6.2  nathanw 	case ICP_MPR:
    612  1.2.6.2  nathanw 		bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh,
    613  1.2.6.2  nathanw 		    ICP_MPR_EDOOR, 0xff);
    614  1.2.6.2  nathanw 		bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh, ICP_EDOOR_EN,
    615  1.2.6.2  nathanw 		    bus_space_read_1(icp->icp_dpmemt, icp->icp_dpmemh,
    616  1.2.6.2  nathanw 		    ICP_EDOOR_EN) & ~4);
    617  1.2.6.2  nathanw 		break;
    618  1.2.6.2  nathanw 	}
    619  1.2.6.2  nathanw }
    620  1.2.6.2  nathanw 
    621  1.2.6.2  nathanw /*
    622  1.2.6.2  nathanw  * "Old" PCI controller-specific functions.
    623  1.2.6.2  nathanw  */
    624  1.2.6.2  nathanw 
    625  1.2.6.2  nathanw void
    626  1.2.6.2  nathanw icp_pci_copy_cmd(struct icp_softc *icp, struct icp_ccb *ccb)
    627  1.2.6.2  nathanw {
    628  1.2.6.2  nathanw 
    629  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    630  1.2.6.2  nathanw }
    631  1.2.6.2  nathanw 
    632  1.2.6.2  nathanw u_int8_t
    633  1.2.6.2  nathanw icp_pci_get_status(struct icp_softc *icp)
    634  1.2.6.2  nathanw {
    635  1.2.6.2  nathanw 
    636  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    637  1.2.6.2  nathanw 	return (0);
    638  1.2.6.2  nathanw }
    639  1.2.6.2  nathanw 
    640  1.2.6.2  nathanw void
    641  1.2.6.2  nathanw icp_pci_intr(struct icp_softc *icp, struct icp_intr_ctx *ctx)
    642  1.2.6.2  nathanw {
    643  1.2.6.2  nathanw 
    644  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    645  1.2.6.2  nathanw }
    646  1.2.6.2  nathanw 
    647  1.2.6.2  nathanw void
    648  1.2.6.2  nathanw icp_pci_release_event(struct icp_softc *icp, struct icp_ccb *ccb)
    649  1.2.6.2  nathanw {
    650  1.2.6.2  nathanw 
    651  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    652  1.2.6.2  nathanw }
    653  1.2.6.2  nathanw 
    654  1.2.6.2  nathanw void
    655  1.2.6.2  nathanw icp_pci_set_sema0(struct icp_softc *icp)
    656  1.2.6.2  nathanw {
    657  1.2.6.2  nathanw 
    658  1.2.6.2  nathanw 	bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh, ICP_SEMA0, 1);
    659  1.2.6.2  nathanw }
    660  1.2.6.2  nathanw 
    661  1.2.6.2  nathanw int
    662  1.2.6.2  nathanw icp_pci_test_busy(struct icp_softc *icp)
    663  1.2.6.2  nathanw {
    664  1.2.6.2  nathanw 
    665  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    666  1.2.6.2  nathanw 	return (0);
    667  1.2.6.2  nathanw }
    668  1.2.6.2  nathanw 
    669  1.2.6.2  nathanw /*
    670  1.2.6.2  nathanw  * "New" PCI controller-specific functions.
    671  1.2.6.2  nathanw  */
    672  1.2.6.2  nathanw 
    673  1.2.6.2  nathanw void
    674  1.2.6.2  nathanw icp_pcinew_copy_cmd(struct icp_softc *icp, struct icp_ccb *ccb)
    675  1.2.6.2  nathanw {
    676  1.2.6.2  nathanw 
    677  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    678  1.2.6.2  nathanw }
    679  1.2.6.2  nathanw 
    680  1.2.6.2  nathanw u_int8_t
    681  1.2.6.2  nathanw icp_pcinew_get_status(struct icp_softc *icp)
    682  1.2.6.2  nathanw {
    683  1.2.6.2  nathanw 
    684  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    685  1.2.6.2  nathanw 	return (0);
    686  1.2.6.2  nathanw }
    687  1.2.6.2  nathanw 
    688  1.2.6.2  nathanw void
    689  1.2.6.2  nathanw icp_pcinew_intr(struct icp_softc *icp, struct icp_intr_ctx *ctx)
    690  1.2.6.2  nathanw {
    691  1.2.6.2  nathanw 
    692  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    693  1.2.6.2  nathanw }
    694  1.2.6.2  nathanw 
    695  1.2.6.2  nathanw void
    696  1.2.6.2  nathanw icp_pcinew_release_event(struct icp_softc *icp, struct icp_ccb *ccb)
    697  1.2.6.2  nathanw {
    698  1.2.6.2  nathanw 
    699  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    700  1.2.6.2  nathanw }
    701  1.2.6.2  nathanw 
    702  1.2.6.2  nathanw void
    703  1.2.6.2  nathanw icp_pcinew_set_sema0(struct icp_softc *icp)
    704  1.2.6.2  nathanw {
    705  1.2.6.2  nathanw 
    706  1.2.6.2  nathanw 	bus_space_write_1(icp->icp_iot, icp->icp_ioh, ICP_SEMA0_REG, 1);
    707  1.2.6.2  nathanw }
    708  1.2.6.2  nathanw 
    709  1.2.6.2  nathanw int
    710  1.2.6.2  nathanw icp_pcinew_test_busy(struct icp_softc *icp)
    711  1.2.6.2  nathanw {
    712  1.2.6.2  nathanw 
    713  1.2.6.2  nathanw 	/* XXX Not yet implemented */
    714  1.2.6.2  nathanw 	return (0);
    715  1.2.6.2  nathanw }
    716  1.2.6.2  nathanw 
    717  1.2.6.2  nathanw /*
    718  1.2.6.2  nathanw  * MPR PCI controller-specific functions
    719  1.2.6.2  nathanw  */
    720  1.2.6.2  nathanw 
    721  1.2.6.2  nathanw void
    722  1.2.6.2  nathanw icp_mpr_copy_cmd(struct icp_softc *icp, struct icp_ccb *ic)
    723  1.2.6.2  nathanw {
    724  1.2.6.2  nathanw 
    725  1.2.6.2  nathanw 	bus_space_write_2(icp->icp_dpmemt, icp->icp_dpmemh,
    726  1.2.6.2  nathanw 	    ICP_MPR_IC + ICP_COMM_QUEUE + 0 * ICP_COMM_Q_SZ + ICP_OFFSET,
    727  1.2.6.2  nathanw 	    ICP_DPR_CMD);
    728  1.2.6.2  nathanw 	bus_space_write_2(icp->icp_dpmemt, icp->icp_dpmemh,
    729  1.2.6.2  nathanw 	    ICP_MPR_IC + ICP_COMM_QUEUE + 0 * ICP_COMM_Q_SZ + ICP_SERV_ID,
    730  1.2.6.2  nathanw 	    ic->ic_service);
    731  1.2.6.2  nathanw 	bus_space_write_region_4(icp->icp_dpmemt, icp->icp_dpmemh,
    732  1.2.6.2  nathanw 	    ICP_MPR_IC + ICP_DPR_CMD, (u_int32_t *)&ic->ic_cmd,
    733  1.2.6.2  nathanw 	    ic->ic_cmdlen >> 2);
    734  1.2.6.2  nathanw }
    735  1.2.6.2  nathanw 
    736  1.2.6.2  nathanw u_int8_t
    737  1.2.6.2  nathanw icp_mpr_get_status(struct icp_softc *icp)
    738  1.2.6.2  nathanw {
    739  1.2.6.2  nathanw 
    740  1.2.6.2  nathanw 	return (bus_space_read_1(icp->icp_dpmemt, icp->icp_dpmemh,
    741  1.2.6.2  nathanw 	    ICP_MPR_EDOOR));
    742  1.2.6.2  nathanw }
    743  1.2.6.2  nathanw 
    744  1.2.6.2  nathanw void
    745  1.2.6.2  nathanw icp_mpr_intr(struct icp_softc *icp, struct icp_intr_ctx *ctx)
    746  1.2.6.2  nathanw {
    747  1.2.6.2  nathanw 
    748  1.2.6.2  nathanw 	if ((ctx->istatus & 0x80) != 0) {	/* error flag */
    749  1.2.6.2  nathanw 		ctx->istatus &= ~0x80;
    750  1.2.6.2  nathanw 		ctx->cmd_status = bus_space_read_2(icp->icp_dpmemt,
    751  1.2.6.2  nathanw 		    icp->icp_dpmemh, ICP_MPR_STATUS);
    752  1.2.6.2  nathanw 	} else
    753  1.2.6.2  nathanw 		ctx->cmd_status = ICP_S_OK;
    754  1.2.6.2  nathanw 
    755  1.2.6.2  nathanw 	ctx->service = bus_space_read_2(icp->icp_dpmemt, icp->icp_dpmemh,
    756  1.2.6.2  nathanw 	    ICP_MPR_SERVICE);
    757  1.2.6.2  nathanw 	ctx->info = bus_space_read_4(icp->icp_dpmemt, icp->icp_dpmemh,
    758  1.2.6.2  nathanw 	    ICP_MPR_INFO);
    759  1.2.6.2  nathanw 	ctx->info2 = bus_space_read_4(icp->icp_dpmemt, icp->icp_dpmemh,
    760  1.2.6.2  nathanw 	    ICP_MPR_INFO + sizeof(u_int32_t));
    761  1.2.6.2  nathanw 
    762  1.2.6.2  nathanw 	/*
    763  1.2.6.2  nathanw 	 * XXX Read async event string here.
    764  1.2.6.2  nathanw 	 */
    765  1.2.6.2  nathanw 
    766  1.2.6.2  nathanw 	bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh, ICP_MPR_EDOOR,
    767  1.2.6.2  nathanw 	    0xff);
    768  1.2.6.2  nathanw 	bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh, ICP_MPR_SEMA1, 0);
    769  1.2.6.2  nathanw }
    770  1.2.6.2  nathanw 
    771  1.2.6.2  nathanw void
    772  1.2.6.2  nathanw icp_mpr_release_event(struct icp_softc *icp, struct icp_ccb *ic)
    773  1.2.6.2  nathanw {
    774  1.2.6.2  nathanw 
    775  1.2.6.2  nathanw 	bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh, ICP_MPR_LDOOR, 1);
    776  1.2.6.2  nathanw }
    777  1.2.6.2  nathanw 
    778  1.2.6.2  nathanw void
    779  1.2.6.2  nathanw icp_mpr_set_sema0(struct icp_softc *icp)
    780  1.2.6.2  nathanw {
    781  1.2.6.2  nathanw 
    782  1.2.6.2  nathanw 	bus_space_write_1(icp->icp_dpmemt, icp->icp_dpmemh, ICP_MPR_SEMA0, 1);
    783  1.2.6.2  nathanw }
    784  1.2.6.2  nathanw 
    785  1.2.6.2  nathanw int
    786  1.2.6.2  nathanw icp_mpr_test_busy(struct icp_softc *icp)
    787  1.2.6.2  nathanw {
    788  1.2.6.2  nathanw 
    789  1.2.6.2  nathanw 	return (bus_space_read_1(icp->icp_dpmemt, icp->icp_dpmemh,
    790  1.2.6.2  nathanw 	    ICP_MPR_SEMA0) & 1);
    791  1.2.6.2  nathanw }
    792