Home | History | Annotate | Line # | Download | only in pci
      1  1.51    andvar /*	$NetBSD: pciidevar.h,v 1.51 2021/12/26 16:08:21 andvar 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.23   thorpej #ifndef _DEV_PCI_PCIIDEVAR_H_
     34  1.23   thorpej #define	_DEV_PCI_PCIIDEVAR_H_
     35  1.23   thorpej 
     36   1.1       cgd /*
     37   1.1       cgd  * PCI IDE driver exported software structures.
     38   1.1       cgd  *
     39   1.1       cgd  * Author: Christopher G. Demetriou, March 2, 1998.
     40   1.1       cgd  */
     41   1.1       cgd 
     42  1.47     pooka #ifdef _KERNEL_OPT
     43  1.47     pooka #include "opt_pciide.h"
     44  1.47     pooka #endif
     45  1.47     pooka 
     46   1.3     soren #include <dev/ata/atavar.h>
     47   1.3     soren #include <dev/ic/wdcreg.h>
     48   1.3     soren #include <dev/ic/wdcvar.h>
     49  1.40    cegger #include <sys/device_if.h>
     50  1.12    bouyer 
     51  1.16   thorpej /* options passed via the 'flags' config keyword */
     52  1.16   thorpej #define	PCIIDE_OPTIONS_DMA	0x01
     53  1.16   thorpej #define	PCIIDE_OPTIONS_NODMA	0x02
     54  1.16   thorpej 
     55  1.21   thorpej #ifndef ATADEBUG
     56  1.21   thorpej #define ATADEBUG
     57  1.12    bouyer #endif
     58  1.12    bouyer 
     59  1.12    bouyer #define DEBUG_DMA   0x01
     60  1.12    bouyer #define DEBUG_XFERS  0x02
     61  1.12    bouyer #define DEBUG_FUNCS  0x08
     62  1.12    bouyer #define DEBUG_PROBE  0x10
     63  1.21   thorpej #ifdef ATADEBUG
     64  1.21   thorpej extern int atadebug_pciide_mask;
     65  1.21   thorpej #define ATADEBUG_PRINT(args, level) \
     66  1.21   thorpej 	if (atadebug_pciide_mask & (level)) printf args
     67  1.12    bouyer #else
     68  1.21   thorpej #define ATADEBUG_PRINT(args, level)
     69  1.12    bouyer #endif
     70   1.3     soren 
     71  1.19   thorpej /*
     72  1.19   thorpej  * While standard PCI IDE controllers only have 2 channels, it is
     73  1.19   thorpej  * common for PCI SATA controllers to have more.  Here we define
     74  1.19   thorpej  * the maximum number of channels that any one PCI IDE device can
     75  1.19   thorpej  * have.
     76  1.19   thorpej  */
     77  1.19   thorpej #define	PCIIDE_MAX_CHANNELS	4
     78  1.19   thorpej 
     79   1.3     soren struct pciide_softc {
     80   1.3     soren 	struct wdc_softc	sc_wdcdev;	/* common wdc definitions */
     81   1.3     soren 	pci_chipset_tag_t	sc_pc;		/* PCI registers info */
     82   1.3     soren 	pcitag_t		sc_tag;
     83   1.3     soren 	void			*sc_pci_ih;	/* PCI interrupt handle */
     84  1.35     itohy #if NATA_DMA
     85   1.3     soren 	int			sc_dma_ok;	/* bus-master DMA info */
     86  1.14      fvdl 	/*
     87  1.14      fvdl 	 * sc_dma_ioh may only be used to allocate the dma_iohs
     88  1.14      fvdl 	 * array in the channels (see below), or by chip-dependent
     89  1.14      fvdl 	 * code that knows what it's doing, as the registers may
     90  1.14      fvdl 	 * be laid out differently. All code in pciide_common.c
     91  1.14      fvdl 	 * must use the channel->dma_iohs array.
     92  1.14      fvdl 	 */
     93   1.3     soren 	bus_space_tag_t		sc_dma_iot;
     94   1.3     soren 	bus_space_handle_t	sc_dma_ioh;
     95  1.41  jakllsch 	bus_size_t		sc_dma_ios;
     96   1.3     soren 	bus_dma_tag_t		sc_dmat;
     97  1.10   thorpej 
     98  1.10   thorpej 	/*
     99  1.10   thorpej 	 * Some controllers might have DMA restrictions other than
    100  1.10   thorpej 	 * the norm.
    101  1.10   thorpej 	 */
    102  1.10   thorpej 	bus_size_t		sc_dma_maxsegsz;
    103  1.10   thorpej 	bus_size_t		sc_dma_boundary;
    104   1.5   thorpej 
    105  1.12    bouyer 	/* For VIA/AMD/nVidia */
    106  1.12    bouyer 	bus_addr_t sc_apo_regbase;
    107   1.8   thorpej 
    108   1.5   thorpej 	/* For Cypress */
    109   1.5   thorpej 	const struct cy82c693_handle *sc_cy_handle;
    110   1.5   thorpej 	int sc_cy_compatchan;
    111   1.9    bouyer 
    112   1.9    bouyer 	/* for SiS */
    113   1.9    bouyer 	u_int8_t sis_type;
    114   1.5   thorpej 
    115  1.33    bouyer 	/*
    116  1.33    bouyer 	 * For Silicon Image SATALink, Serverworks SATA, Artisea SATA
    117  1.33    bouyer 	 * and Promise SATA
    118  1.33    bouyer 	 */
    119  1.15   thorpej 	bus_space_tag_t sc_ba5_st;
    120  1.15   thorpej 	bus_space_handle_t sc_ba5_sh;
    121  1.41  jakllsch 	bus_size_t sc_ba5_ss;
    122  1.15   thorpej 	int sc_ba5_en;
    123  1.35     itohy #endif	/* NATA_DMA */
    124  1.15   thorpej 
    125  1.49  jdolecek 	/* for CMD Technology 064x */
    126  1.49  jdolecek 	uint sc_cmd_act_channel;
    127  1.49  jdolecek 
    128   1.8   thorpej 	/* Vendor info (for interpreting Chip description) */
    129  1.12    bouyer 	pcireg_t sc_pci_id;
    130   1.3     soren 	/* Chip description */
    131   1.3     soren 	const struct pciide_product_desc *sc_pp;
    132   1.3     soren 	/* common definitions */
    133  1.22   thorpej 	struct ata_channel *wdc_chanarray[PCIIDE_MAX_CHANNELS];
    134   1.3     soren 	/* internal bookkeeping */
    135   1.3     soren 	struct pciide_channel {			/* per-channel data */
    136  1.22   thorpej 		struct ata_channel ata_channel; /* generic part */
    137  1.17   thorpej 		const char	*name;
    138   1.6    bouyer 		int		compat;	/* is it compat? */
    139   1.6    bouyer 		void		*ih;	/* compat or pci handle */
    140   1.6    bouyer 		bus_space_handle_t ctl_baseioh; /* ctrl regs blk, native mode */
    141  1.41  jakllsch 		bus_size_t      ctl_ios;
    142  1.35     itohy #if NATA_DMA
    143   1.3     soren 		/* DMA tables and DMA map for xfer, for each drive */
    144   1.3     soren 		struct pciide_dma_maps {
    145  1.41  jakllsch 			bus_dma_segment_t dmamap_table_seg;
    146  1.41  jakllsch 			int             dmamap_table_nseg;
    147   1.3     soren 			bus_dmamap_t    dmamap_table;
    148   1.3     soren 			struct idedma_table *dma_table;
    149   1.3     soren 			bus_dmamap_t    dmamap_xfer;
    150   1.4    bouyer 			int dma_flags;
    151  1.46    bouyer 		} dma_maps[WDC_MAXDRIVES];
    152  1.14      fvdl 		bus_space_handle_t	dma_iohs[IDEDMA_NREGS];
    153  1.18   thorpej 		/*
    154  1.18   thorpej 		 * Some controllers require certain bits to
    155  1.18   thorpej 		 * always be set for proper operation of the
    156  1.18   thorpej 		 * controller.  Set those bits here, if they're
    157  1.18   thorpej 		 * required.
    158  1.18   thorpej 		 */
    159  1.18   thorpej 		uint8_t		idedma_cmd;
    160  1.35     itohy #endif	/* NATA_DMA */
    161  1.19   thorpej 	} pciide_channels[PCIIDE_MAX_CHANNELS];
    162  1.27  jmcneill 
    163  1.36     joerg 	pcireg_t		sc_pm_reg[4];
    164   1.3     soren };
    165   1.1       cgd 
    166  1.24   thorpej /* Given an ata_channel, get the pciide_softc. */
    167  1.25   thorpej #define	CHAN_TO_PCIIDE(chp)	((struct pciide_softc *) (chp)->ch_atac)
    168  1.24   thorpej 
    169  1.24   thorpej /* Given an ata_channel, get the pciide_channel. */
    170  1.24   thorpej #define	CHAN_TO_PCHAN(chp)	((struct pciide_channel *) (chp))
    171  1.24   thorpej 
    172  1.12    bouyer struct pciide_product_desc {
    173  1.12    bouyer 	u_int32_t ide_product;
    174  1.12    bouyer 	int ide_flags;
    175  1.12    bouyer 	const char *ide_name;
    176  1.12    bouyer 	/* map and setup chip, probe drives */
    177  1.43    dyoung 	void (*chip_map)(struct pciide_softc*, const struct pci_attach_args*);
    178  1.12    bouyer };
    179  1.12    bouyer 
    180  1.12    bouyer /* Flags for ide_flags */
    181  1.12    bouyer #define	IDE_16BIT_IOSPACE	0x0002 /* I/O space BARS ignore upper word */
    182  1.51    andvar #define	IDE_SHARED_CHANNELS	0x0004 /* channels are not independent */
    183  1.12    bouyer 
    184  1.12    bouyer 
    185  1.12    bouyer /* inlines for reading/writing 8-bit PCI registers */
    186  1.50  christos static __inline u_int8_t pciide_pci_read(pci_chipset_tag_t, pcitag_t, int);
    187  1.50  christos static __inline void pciide_pci_write(pci_chipset_tag_t, pcitag_t,
    188  1.28     perry 					   int, u_int8_t);
    189  1.12    bouyer 
    190  1.50  christos static __inline u_int8_t
    191  1.37    cegger pciide_pci_read(pci_chipset_tag_t pc, pcitag_t pa, int reg)
    192  1.12    bouyer {
    193  1.12    bouyer 
    194  1.12    bouyer 	return (pci_conf_read(pc, pa, (reg & ~0x03)) >>
    195  1.12    bouyer 	    ((reg & 0x03) * 8) & 0xff);
    196  1.12    bouyer }
    197  1.12    bouyer 
    198  1.50  christos static __inline void
    199  1.37    cegger pciide_pci_write(pci_chipset_tag_t pc, pcitag_t pa, int reg, uint8_t val)
    200  1.12    bouyer {
    201  1.12    bouyer 	pcireg_t pcival;
    202  1.12    bouyer 
    203  1.12    bouyer 	pcival = pci_conf_read(pc, pa, (reg & ~0x03));
    204  1.12    bouyer 	pcival &= ~(0xff << ((reg & 0x03) * 8));
    205  1.12    bouyer 	pcival |= (val << ((reg & 0x03) * 8));
    206  1.12    bouyer 	pci_conf_write(pc, pa, (reg & ~0x03), pcival);
    207  1.12    bouyer }
    208  1.12    bouyer 
    209  1.43    dyoung void default_chip_map(struct pciide_softc*, const struct pci_attach_args*);
    210  1.28     perry void sata_setup_channel(struct ata_channel*);
    211  1.12    bouyer 
    212  1.28     perry void pciide_channel_dma_setup(struct pciide_channel *);
    213  1.28     perry int  pciide_dma_table_setup(struct pciide_softc*, int, int);
    214  1.41  jakllsch void pciide_dma_table_teardown(struct pciide_softc *, int, int);
    215  1.41  jakllsch 
    216  1.28     perry int  pciide_dma_dmamap_setup(struct pciide_softc *, int, int,
    217  1.28     perry 				void *, size_t, int);
    218  1.28     perry int  pciide_dma_init(void*, int, int, void *, size_t, int);
    219  1.28     perry void pciide_dma_start(void*, int, int);
    220  1.28     perry int  pciide_dma_finish(void*, int, int, int);
    221  1.28     perry void pciide_irqack(struct ata_channel *);
    222  1.12    bouyer 
    223   1.1       cgd /*
    224   1.1       cgd  * Functions defined by machine-dependent code.
    225   1.1       cgd  */
    226   1.1       cgd 
    227   1.1       cgd /* Attach compat interrupt handler, returning handle or NULL if failed. */
    228   1.7    simonb #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    229  1.38    cegger void	*pciide_machdep_compat_intr_establish(device_t,
    230  1.43    dyoung 	    const struct pci_attach_args *, int, int (*)(void *), void *);
    231   1.7    simonb #endif
    232  1.42  jakllsch #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_DISESTABLISH
    233  1.42  jakllsch void	pciide_machdep_compat_intr_disestablish(device_t,
    234  1.42  jakllsch 	    pci_chipset_tag_t, int,  void *);
    235  1.42  jakllsch #endif
    236  1.12    bouyer 
    237  1.12    bouyer const struct pciide_product_desc* pciide_lookup_product
    238  1.28     perry 	(u_int32_t, const struct pciide_product_desc *);
    239  1.43    dyoung void	pciide_common_attach(struct pciide_softc *,
    240  1.43    dyoung 		const struct pci_attach_args *,
    241  1.28     perry 		const struct pciide_product_desc *);
    242  1.41  jakllsch int	pciide_common_detach(struct pciide_softc *, int);
    243  1.42  jakllsch int	pciide_detach(device_t, int);
    244  1.28     perry 
    245  1.43    dyoung int	pciide_chipen(struct pciide_softc *, const struct pci_attach_args *);
    246  1.43    dyoung void	pciide_mapregs_compat(const struct pci_attach_args *,
    247  1.41  jakllsch 	    struct pciide_channel *, int);
    248  1.43    dyoung void	pciide_mapregs_native(const struct pci_attach_args *,
    249  1.41  jakllsch 	    struct pciide_channel *, int (*pci_intr)(void *));
    250  1.28     perry void	pciide_mapreg_dma(struct pciide_softc *,
    251  1.43    dyoung 	    const struct pci_attach_args *);
    252  1.28     perry int	pciide_chansetup(struct pciide_softc *, int, pcireg_t);
    253  1.43    dyoung void	pciide_mapchan(const struct pci_attach_args *,
    254  1.41  jakllsch 	    struct pciide_channel *, pcireg_t, int (*pci_intr)(void *));
    255  1.43    dyoung void	pciide_map_compat_intr(const struct pci_attach_args *,
    256  1.28     perry 	    struct pciide_channel *, int);
    257  1.42  jakllsch void	pciide_unmap_compat_intr(pci_chipset_tag_t,
    258  1.42  jakllsch 	    struct pciide_channel *, int);
    259  1.28     perry int	pciide_compat_intr(void *);
    260  1.28     perry int	pciide_pci_intr(void *);
    261  1.23   thorpej 
    262  1.23   thorpej #endif /* _DEV_PCI_PCIIDEVAR_H_ */
    263