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