xref: /openbsd/sys/dev/pci/pciidevar.h (revision 404b540a)
1 /*	$OpenBSD: pciidevar.h,v 1.19 2009/10/05 20:01:40 jsg Exp $	*/
2 /*	$NetBSD: pciidevar.h,v 1.6 2001/01/12 16:04:00 bouyer Exp $	*/
3 
4 /*
5  * Copyright (c) 1998 Christopher G. Demetriou.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Christopher G. Demetriou
18  *	for the NetBSD Project.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _DEV_PCI_PCIIDEVAR_H_
35 #define _DEV_PCI_PCIIDEVAR_H_
36 
37 /*
38  * PCI IDE driver exported software structures.
39  *
40  * Author: Christopher G. Demetriou, March 2, 1998.
41  */
42 
43 #include <dev/ata/atavar.h>
44 #include <dev/ic/wdcreg.h>
45 #include <dev/ic/wdcvar.h>
46 
47 /*
48  * While standard PCI IDE controllers only have 2 channels, it is
49  * common for PCI SATA controllers to have more.  Here we define
50  * the maximum number of channels that any one PCI IDE device can
51  * have.
52  */
53 #define PCIIDE_MAX_CHANNELS	4
54 
55 struct pciide_softc {
56 	struct wdc_softc	sc_wdcdev;	/* common wdc definitions */
57 	pci_chipset_tag_t	sc_pc;		/* PCI registers info */
58 	pcitag_t		sc_tag;
59 	void			*sc_pci_ih;	/* PCI interrupt handle */
60 	int			sc_dma_ok;	/* bus-master DMA info */
61 	bus_space_tag_t		sc_dma_iot;
62 	bus_space_handle_t	sc_dma_ioh;
63 	bus_size_t		sc_dma_iosz;
64 	bus_dma_tag_t		sc_dmat;
65 
66 	/*
67 	 * Some controllers might have DMA restrictions other than
68 	 * the norm.
69 	 */
70 	bus_size_t		sc_dma_maxsegsz;
71 	bus_size_t		sc_dma_boundary;
72 
73 	/* Chip description */
74 	const struct pciide_product_desc *sc_pp;
75 	/* unmap/detach */
76 	void (*chip_unmap)(struct pciide_softc *, int);
77 	/* Chip revision */
78 	int sc_rev;
79 	/* common definitions */
80 	struct channel_softc *wdc_chanarray[PCIIDE_MAX_CHANNELS];
81 	/* internal bookkeeping */
82 	struct pciide_channel {			/* per-channel data */
83 		struct channel_softc wdc_channel; /* generic part */
84 		const char	*name;
85 		int		hw_ok;		/* hardware mapped & OK? */
86 		int		compat;		/* is it compat? */
87 		int             dma_in_progress;
88 		void		*ih;		/* compat or pci handle */
89 		bus_space_handle_t ctl_baseioh;	/* ctrl regs blk, native mode */
90 		/* DMA tables and DMA map for xfer, for each drive */
91 		struct pciide_dma_maps {
92 			bus_dmamap_t    dmamap_table;
93 			struct idedma_table *dma_table;
94 			bus_dmamap_t    dmamap_xfer;
95 			int dma_flags;
96 		} dma_maps[2];
97 		/*
98 		 * Some controllers require certain bits to
99 		 * always be set for proper operation of the
100 		 * controller.  Set those bits here, if they're
101 		 * required.
102 		 */
103 		uint8_t		idedma_cmd;
104 	} pciide_channels[PCIIDE_MAX_CHANNELS];
105 
106 	/* Chip-specific private data */
107 	void *sc_cookie;
108 
109 	/* DMA registers access functions */
110 	u_int8_t (*sc_dmacmd_read)(struct pciide_softc *, int);
111 	void (*sc_dmacmd_write)(struct pciide_softc *, int, u_int8_t);
112 	u_int8_t (*sc_dmactl_read)(struct pciide_softc *, int);
113 	void (*sc_dmactl_write)(struct pciide_softc *, int, u_int8_t);
114 	void (*sc_dmatbl_write)(struct pciide_softc *, int, u_int32_t);
115 };
116 
117 #define PCIIDE_DMACMD_READ(sc, chan) \
118 	(sc)->sc_dmacmd_read((sc), (chan))
119 #define PCIIDE_DMACMD_WRITE(sc, chan, val) \
120 	(sc)->sc_dmacmd_write((sc), (chan), (val))
121 #define PCIIDE_DMACTL_READ(sc, chan) \
122 	(sc)->sc_dmactl_read((sc), (chan))
123 #define PCIIDE_DMACTL_WRITE(sc, chan, val) \
124 	(sc)->sc_dmactl_write((sc), (chan), (val))
125 #define PCIIDE_DMATBL_WRITE(sc, chan, val) \
126 	(sc)->sc_dmatbl_write((sc), (chan), (val))
127 
128 int	pciide_mapregs_compat( struct pci_attach_args *,
129 	    struct pciide_channel *, int, bus_size_t *, bus_size_t *);
130 int	pciide_mapregs_native(struct pci_attach_args *,
131 	    struct pciide_channel *, bus_size_t *, bus_size_t *,
132 	    int (*pci_intr)(void *));
133 void	pciide_mapreg_dma(struct pciide_softc *,
134 	    struct pci_attach_args *);
135 int	pciide_chansetup(struct pciide_softc *, int, pcireg_t);
136 void	pciide_mapchan(struct pci_attach_args *,
137 	    struct pciide_channel *, pcireg_t, bus_size_t *, bus_size_t *,
138 	    int (*pci_intr)(void *));
139 int	pciide_chan_candisable(struct pciide_channel *);
140 void	pciide_map_compat_intr( struct pci_attach_args *,
141 	    struct pciide_channel *, int, int);
142 void	pciide_unmap_compat_intr( struct pci_attach_args *,
143 	    struct pciide_channel *, int, int);
144 int	pciide_compat_intr(void *);
145 int	pciide_pci_intr(void *);
146 int	pciide_intr_flag(struct pciide_channel *);
147 
148 u_int8_t pciide_dmacmd_read(struct pciide_softc *, int);
149 void	 pciide_dmacmd_write(struct pciide_softc *, int, u_int8_t);
150 u_int8_t pciide_dmactl_read(struct pciide_softc *, int);
151 void	 pciide_dmactl_write(struct pciide_softc *, int, u_int8_t);
152 void	 pciide_dmatbl_write(struct pciide_softc *, int, u_int32_t);
153 
154 void	 pciide_channel_dma_setup(struct pciide_channel *);
155 int	 pciide_dma_table_setup(struct pciide_softc *, int, int);
156 int	 pciide_dma_init(void *, int, int, void *, size_t, int);
157 void	 pciide_dma_start(void *, int, int);
158 int	 pciide_dma_finish(void *, int, int, int);
159 void	 pciide_irqack(struct channel_softc *);
160 void	 pciide_print_modes(struct pciide_channel *);
161 void	 pciide_print_channels(int, pcireg_t);
162 
163 void	 default_chip_unmap(struct pciide_softc *, int);
164 void	 pciide_unmapreg_dma(struct pciide_softc *);
165 void	 pciide_chanfree(struct pciide_softc *, int);
166 void	 pciide_unmap_chan(struct pciide_softc *, struct pciide_channel *, int);
167 int	 pciide_unmapregs_compat(struct pciide_softc *,
168 	     struct pciide_channel *);
169 int	 pciide_unmapregs_native(struct pciide_softc *,
170 	     struct pciide_channel *);
171 int	 pciide_dma_table_free(struct pciide_softc *, int, int);
172 void	 pciide_channel_dma_free(struct pciide_channel *);
173 
174 /*
175  * Functions defined by machine-dependent code.
176  */
177 
178 #ifdef __i386__
179 void gcsc_chip_map(struct pciide_softc *, struct pci_attach_args *);
180 #endif
181 
182 /* Attach compat interrupt handler, returning handle or NULL if failed. */
183 #if !defined(pciide_machdep_compat_intr_establish)
184 void	*pciide_machdep_compat_intr_establish(struct device *,
185 	    struct pci_attach_args *, int, int (*)(void *), void *);
186 void	pciide_machdep_compat_intr_disestablish(pci_chipset_tag_t pc,
187 	    void *);
188 #endif
189 
190 #endif	/* !_DEV_PCI_PCIIDEVAR_H_ */
191