Home | History | Annotate | Line # | Download | only in pci
pciidevar.h revision 1.16
      1  1.16  thorpej /*	$NetBSD: pciidevar.h,v 1.16 2003/12/19 05:16:57 thorpej Exp $	*/
      2   1.1      cgd 
      3   1.1      cgd /*
      4   1.1      cgd  * Copyright (c) 1998 Christopher G. Demetriou.  All rights reserved.
      5   1.1      cgd  *
      6   1.1      cgd  * Redistribution and use in source and binary forms, with or without
      7   1.1      cgd  * modification, are permitted provided that the following conditions
      8   1.1      cgd  * are met:
      9   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     10   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     11   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     13   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     14   1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     15   1.1      cgd  *    must display the following acknowledgement:
     16   1.1      cgd  *      This product includes software developed by Christopher G. Demetriou
     17   1.1      cgd  *	for the NetBSD Project.
     18   1.1      cgd  * 4. The name of the author may not be used to endorse or promote products
     19   1.1      cgd  *    derived from this software without specific prior written permission
     20   1.1      cgd  *
     21   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1      cgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1      cgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1      cgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1      cgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1      cgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1      cgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1      cgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1      cgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1      cgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1      cgd  */
     32   1.1      cgd 
     33   1.1      cgd /*
     34   1.1      cgd  * PCI IDE driver exported software structures.
     35   1.1      cgd  *
     36   1.1      cgd  * Author: Christopher G. Demetriou, March 2, 1998.
     37   1.1      cgd  */
     38   1.1      cgd 
     39   1.3    soren #include <dev/ata/atavar.h>
     40   1.3    soren #include <dev/ic/wdcreg.h>
     41   1.3    soren #include <dev/ic/wdcvar.h>
     42  1.12   bouyer #include "opt_pciide.h"
     43  1.12   bouyer 
     44  1.16  thorpej /* options passed via the 'flags' config keyword */
     45  1.16  thorpej #define	PCIIDE_OPTIONS_DMA	0x01
     46  1.16  thorpej #define	PCIIDE_OPTIONS_NODMA	0x02
     47  1.16  thorpej 
     48  1.12   bouyer #ifndef WDCDEBUG
     49  1.12   bouyer #define WDCDEBUG
     50  1.12   bouyer #endif
     51  1.12   bouyer 
     52  1.12   bouyer #define DEBUG_DMA   0x01
     53  1.12   bouyer #define DEBUG_XFERS  0x02
     54  1.12   bouyer #define DEBUG_FUNCS  0x08
     55  1.12   bouyer #define DEBUG_PROBE  0x10
     56  1.12   bouyer #ifdef WDCDEBUG
     57  1.12   bouyer extern int wdcdebug_pciide_mask;
     58  1.12   bouyer #define WDCDEBUG_PRINT(args, level) \
     59  1.12   bouyer 	if (wdcdebug_pciide_mask & (level)) printf args
     60  1.12   bouyer #else
     61  1.12   bouyer #define WDCDEBUG_PRINT(args, level)
     62  1.12   bouyer #endif
     63   1.3    soren 
     64   1.1      cgd struct device;
     65   1.3    soren 
     66   1.3    soren struct pciide_softc {
     67   1.3    soren 	struct wdc_softc	sc_wdcdev;	/* common wdc definitions */
     68   1.3    soren 	pci_chipset_tag_t	sc_pc;		/* PCI registers info */
     69   1.3    soren 	pcitag_t		sc_tag;
     70   1.3    soren 	void			*sc_pci_ih;	/* PCI interrupt handle */
     71   1.3    soren 	int			sc_dma_ok;	/* bus-master DMA info */
     72  1.14     fvdl 	/*
     73  1.14     fvdl 	 * sc_dma_ioh may only be used to allocate the dma_iohs
     74  1.14     fvdl 	 * array in the channels (see below), or by chip-dependent
     75  1.14     fvdl 	 * code that knows what it's doing, as the registers may
     76  1.14     fvdl 	 * be laid out differently. All code in pciide_common.c
     77  1.14     fvdl 	 * must use the channel->dma_iohs array.
     78  1.14     fvdl 	 */
     79   1.3    soren 	bus_space_tag_t		sc_dma_iot;
     80   1.3    soren 	bus_space_handle_t	sc_dma_ioh;
     81   1.3    soren 	bus_dma_tag_t		sc_dmat;
     82  1.10  thorpej 
     83  1.10  thorpej 	/*
     84  1.10  thorpej 	 * Some controllers might have DMA restrictions other than
     85  1.10  thorpej 	 * the norm.
     86  1.10  thorpej 	 */
     87  1.10  thorpej 	bus_size_t		sc_dma_maxsegsz;
     88  1.10  thorpej 	bus_size_t		sc_dma_boundary;
     89   1.5  thorpej 
     90  1.12   bouyer 	/* For VIA/AMD/nVidia */
     91  1.12   bouyer 	bus_addr_t sc_apo_regbase;
     92   1.8  thorpej 
     93   1.5  thorpej 	/* For Cypress */
     94   1.5  thorpej 	const struct cy82c693_handle *sc_cy_handle;
     95   1.5  thorpej 	int sc_cy_compatchan;
     96   1.9   bouyer 
     97   1.9   bouyer 	/* for SiS */
     98   1.9   bouyer 	u_int8_t sis_type;
     99   1.5  thorpej 
    100  1.15  thorpej 	/* For Silicon Image SATALink */
    101  1.15  thorpej 	bus_space_tag_t sc_ba5_st;
    102  1.15  thorpej 	bus_space_handle_t sc_ba5_sh;
    103  1.15  thorpej 	int sc_ba5_en;
    104  1.15  thorpej 
    105   1.8  thorpej 	/* Vendor info (for interpreting Chip description) */
    106  1.12   bouyer 	pcireg_t sc_pci_id;
    107   1.3    soren 	/* Chip description */
    108   1.3    soren 	const struct pciide_product_desc *sc_pp;
    109   1.3    soren 	/* common definitions */
    110   1.3    soren 	struct channel_softc *wdc_chanarray[PCIIDE_NUM_CHANNELS];
    111   1.3    soren 	/* internal bookkeeping */
    112   1.3    soren 	struct pciide_channel {			/* per-channel data */
    113   1.3    soren 		struct channel_softc wdc_channel; /* generic part */
    114   1.3    soren 		char		*name;
    115   1.6   bouyer 		int		compat;	/* is it compat? */
    116   1.6   bouyer 		void		*ih;	/* compat or pci handle */
    117   1.6   bouyer 		bus_space_handle_t ctl_baseioh; /* ctrl regs blk, native mode */
    118   1.3    soren 		/* DMA tables and DMA map for xfer, for each drive */
    119   1.3    soren 		struct pciide_dma_maps {
    120   1.3    soren 			bus_dmamap_t    dmamap_table;
    121   1.3    soren 			struct idedma_table *dma_table;
    122   1.3    soren 			bus_dmamap_t    dmamap_xfer;
    123   1.4   bouyer 			int dma_flags;
    124   1.3    soren 		} dma_maps[2];
    125  1.14     fvdl 		bus_space_handle_t	dma_iohs[IDEDMA_NREGS];
    126   1.3    soren 	} pciide_channels[PCIIDE_NUM_CHANNELS];
    127   1.3    soren };
    128   1.1      cgd 
    129  1.12   bouyer struct pciide_product_desc {
    130  1.12   bouyer 	u_int32_t ide_product;
    131  1.12   bouyer 	int ide_flags;
    132  1.12   bouyer 	const char *ide_name;
    133  1.12   bouyer 	/* map and setup chip, probe drives */
    134  1.12   bouyer 	void (*chip_map) __P((struct pciide_softc*, struct pci_attach_args*));
    135  1.12   bouyer };
    136  1.12   bouyer 
    137  1.12   bouyer /* Flags for ide_flags */
    138  1.12   bouyer #define	IDE_16BIT_IOSPACE	0x0002 /* I/O space BARS ignore upper word */
    139  1.12   bouyer 
    140  1.12   bouyer 
    141  1.12   bouyer /* inlines for reading/writing 8-bit PCI registers */
    142  1.12   bouyer static __inline u_int8_t pciide_pci_read __P((pci_chipset_tag_t, pcitag_t,
    143  1.12   bouyer 					      int));
    144  1.12   bouyer static __inline void pciide_pci_write __P((pci_chipset_tag_t, pcitag_t,
    145  1.12   bouyer 					   int, u_int8_t));
    146  1.12   bouyer 
    147  1.12   bouyer static __inline u_int8_t
    148  1.12   bouyer pciide_pci_read(pc, pa, reg)
    149  1.12   bouyer 	pci_chipset_tag_t pc;
    150  1.12   bouyer 	pcitag_t pa;
    151  1.12   bouyer 	int reg;
    152  1.12   bouyer {
    153  1.12   bouyer 
    154  1.12   bouyer 	return (pci_conf_read(pc, pa, (reg & ~0x03)) >>
    155  1.12   bouyer 	    ((reg & 0x03) * 8) & 0xff);
    156  1.12   bouyer }
    157  1.12   bouyer 
    158  1.12   bouyer static __inline void
    159  1.12   bouyer pciide_pci_write(pc, pa, reg, val)
    160  1.12   bouyer 	pci_chipset_tag_t pc;
    161  1.12   bouyer 	pcitag_t pa;
    162  1.12   bouyer 	int reg;
    163  1.12   bouyer 	u_int8_t val;
    164  1.12   bouyer {
    165  1.12   bouyer 	pcireg_t pcival;
    166  1.12   bouyer 
    167  1.12   bouyer 	pcival = pci_conf_read(pc, pa, (reg & ~0x03));
    168  1.12   bouyer 	pcival &= ~(0xff << ((reg & 0x03) * 8));
    169  1.12   bouyer 	pcival |= (val << ((reg & 0x03) * 8));
    170  1.12   bouyer 	pci_conf_write(pc, pa, (reg & ~0x03), pcival);
    171  1.12   bouyer }
    172  1.12   bouyer 
    173  1.12   bouyer void default_chip_map __P((struct pciide_softc*, struct pci_attach_args*));
    174  1.12   bouyer void sata_setup_channel __P((struct channel_softc*));
    175  1.12   bouyer 
    176  1.12   bouyer void pciide_channel_dma_setup __P((struct pciide_channel *));
    177  1.12   bouyer int  pciide_dma_table_setup __P((struct pciide_softc*, int, int));
    178  1.12   bouyer int  pciide_dma_init __P((void*, int, int, void *, size_t, int));
    179  1.12   bouyer void pciide_dma_start __P((void*, int, int));
    180  1.12   bouyer int  pciide_dma_finish __P((void*, int, int, int));
    181  1.12   bouyer void pciide_irqack __P((struct channel_softc *));
    182  1.12   bouyer 
    183   1.1      cgd /*
    184   1.1      cgd  * Functions defined by machine-dependent code.
    185   1.1      cgd  */
    186   1.1      cgd 
    187   1.1      cgd /* Attach compat interrupt handler, returning handle or NULL if failed. */
    188   1.7   simonb #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    189   1.1      cgd void	*pciide_machdep_compat_intr_establish __P((struct device *,
    190   1.1      cgd 	    struct pci_attach_args *, int, int (*)(void *), void *));
    191   1.7   simonb #endif
    192  1.12   bouyer 
    193  1.12   bouyer const struct pciide_product_desc* pciide_lookup_product
    194  1.12   bouyer 	__P((u_int32_t, const struct pciide_product_desc *));
    195  1.12   bouyer void	pciide_common_attach
    196  1.12   bouyer 	__P((struct pciide_softc *, struct pci_attach_args *,
    197  1.12   bouyer 		const struct pciide_product_desc *));
    198  1.12   bouyer 
    199  1.12   bouyer int	pciide_chipen __P((struct pciide_softc *, struct pci_attach_args *));
    200  1.12   bouyer void	pciide_mapregs_compat __P(( struct pci_attach_args *,
    201  1.12   bouyer 	    struct pciide_channel *, int, bus_size_t *, bus_size_t*));
    202  1.12   bouyer void	pciide_mapregs_native __P((struct pci_attach_args *,
    203  1.12   bouyer 	    struct pciide_channel *, bus_size_t *, bus_size_t *,
    204  1.12   bouyer 	    int (*pci_intr) __P((void *))));
    205  1.12   bouyer void	pciide_mapreg_dma __P((struct pciide_softc *,
    206  1.12   bouyer 	    struct pci_attach_args *));
    207  1.12   bouyer int	pciide_chansetup __P((struct pciide_softc *, int, pcireg_t));
    208  1.12   bouyer void	pciide_mapchan __P((struct pci_attach_args *,
    209  1.12   bouyer 	    struct pciide_channel *, pcireg_t, bus_size_t *, bus_size_t *,
    210  1.12   bouyer 	    int (*pci_intr) __P((void *))));
    211  1.12   bouyer void	pciide_map_compat_intr __P(( struct pci_attach_args *,
    212  1.12   bouyer 	    struct pciide_channel *, int));
    213  1.12   bouyer int	pciide_compat_intr __P((void *));
    214  1.12   bouyer int	pciide_pci_intr __P((void *));
    215