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