pciidevar.h revision 1.12 1 /* $NetBSD: pciidevar.h,v 1.12 2003/10/08 11:51:59 bouyer 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 #ifndef WDCDEBUG
45 #define WDCDEBUG
46 #endif
47
48 #define DEBUG_DMA 0x01
49 #define DEBUG_XFERS 0x02
50 #define DEBUG_FUNCS 0x08
51 #define DEBUG_PROBE 0x10
52 #ifdef WDCDEBUG
53 extern int wdcdebug_pciide_mask;
54 #define WDCDEBUG_PRINT(args, level) \
55 if (wdcdebug_pciide_mask & (level)) printf args
56 #else
57 #define WDCDEBUG_PRINT(args, level)
58 #endif
59
60 struct device;
61
62 struct pciide_softc {
63 struct wdc_softc sc_wdcdev; /* common wdc definitions */
64 pci_chipset_tag_t sc_pc; /* PCI registers info */
65 pcitag_t sc_tag;
66 void *sc_pci_ih; /* PCI interrupt handle */
67 int sc_dma_ok; /* bus-master DMA info */
68 bus_space_tag_t sc_dma_iot;
69 bus_space_handle_t sc_dma_ioh;
70 bus_dma_tag_t sc_dmat;
71
72 /*
73 * Some controllers might have DMA restrictions other than
74 * the norm.
75 */
76 bus_size_t sc_dma_maxsegsz;
77 bus_size_t sc_dma_boundary;
78
79 /* For VIA/AMD/nVidia */
80 bus_addr_t sc_apo_regbase;
81
82 /* For Cypress */
83 const struct cy82c693_handle *sc_cy_handle;
84 int sc_cy_compatchan;
85
86 /* for SiS */
87 u_int8_t sis_type;
88
89 /* Vendor info (for interpreting Chip description) */
90 pcireg_t sc_pci_id;
91 /* Chip description */
92 const struct pciide_product_desc *sc_pp;
93 /* common definitions */
94 struct channel_softc *wdc_chanarray[PCIIDE_NUM_CHANNELS];
95 /* internal bookkeeping */
96 struct pciide_channel { /* per-channel data */
97 struct channel_softc wdc_channel; /* generic part */
98 char *name;
99 int compat; /* is it compat? */
100 void *ih; /* compat or pci handle */
101 bus_space_handle_t ctl_baseioh; /* ctrl regs blk, native mode */
102 /* DMA tables and DMA map for xfer, for each drive */
103 struct pciide_dma_maps {
104 bus_dmamap_t dmamap_table;
105 struct idedma_table *dma_table;
106 bus_dmamap_t dmamap_xfer;
107 int dma_flags;
108 } dma_maps[2];
109 } pciide_channels[PCIIDE_NUM_CHANNELS];
110 };
111
112 struct pciide_product_desc {
113 u_int32_t ide_product;
114 int ide_flags;
115 const char *ide_name;
116 /* map and setup chip, probe drives */
117 void (*chip_map) __P((struct pciide_softc*, struct pci_attach_args*));
118 };
119
120 /* Flags for ide_flags */
121 #define IDE_PCI_CLASS_OVERRIDE 0x0001 /* accept even if class != pciide */
122 #define IDE_16BIT_IOSPACE 0x0002 /* I/O space BARS ignore upper word */
123
124
125 /* inlines for reading/writing 8-bit PCI registers */
126 static __inline u_int8_t pciide_pci_read __P((pci_chipset_tag_t, pcitag_t,
127 int));
128 static __inline void pciide_pci_write __P((pci_chipset_tag_t, pcitag_t,
129 int, u_int8_t));
130
131 static __inline u_int8_t
132 pciide_pci_read(pc, pa, reg)
133 pci_chipset_tag_t pc;
134 pcitag_t pa;
135 int reg;
136 {
137
138 return (pci_conf_read(pc, pa, (reg & ~0x03)) >>
139 ((reg & 0x03) * 8) & 0xff);
140 }
141
142 static __inline void
143 pciide_pci_write(pc, pa, reg, val)
144 pci_chipset_tag_t pc;
145 pcitag_t pa;
146 int reg;
147 u_int8_t val;
148 {
149 pcireg_t pcival;
150
151 pcival = pci_conf_read(pc, pa, (reg & ~0x03));
152 pcival &= ~(0xff << ((reg & 0x03) * 8));
153 pcival |= (val << ((reg & 0x03) * 8));
154 pci_conf_write(pc, pa, (reg & ~0x03), pcival);
155 }
156
157 void default_chip_map __P((struct pciide_softc*, struct pci_attach_args*));
158 void sata_setup_channel __P((struct channel_softc*));
159
160 void pciide_channel_dma_setup __P((struct pciide_channel *));
161 int pciide_dma_table_setup __P((struct pciide_softc*, int, int));
162 int pciide_dma_init __P((void*, int, int, void *, size_t, int));
163 void pciide_dma_start __P((void*, int, int));
164 int pciide_dma_finish __P((void*, int, int, int));
165 void pciide_irqack __P((struct channel_softc *));
166
167 /*
168 * Functions defined by machine-dependent code.
169 */
170
171 /* Attach compat interrupt handler, returning handle or NULL if failed. */
172 #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
173 void *pciide_machdep_compat_intr_establish __P((struct device *,
174 struct pci_attach_args *, int, int (*)(void *), void *));
175 #endif
176
177 const struct pciide_product_desc* pciide_lookup_product
178 __P((u_int32_t, const struct pciide_product_desc *));
179 void pciide_common_attach
180 __P((struct pciide_softc *, struct pci_attach_args *,
181 const struct pciide_product_desc *));
182
183 int pciide_chipen __P((struct pciide_softc *, struct pci_attach_args *));
184 void pciide_mapregs_compat __P(( struct pci_attach_args *,
185 struct pciide_channel *, int, bus_size_t *, bus_size_t*));
186 void pciide_mapregs_native __P((struct pci_attach_args *,
187 struct pciide_channel *, bus_size_t *, bus_size_t *,
188 int (*pci_intr) __P((void *))));
189 void pciide_mapreg_dma __P((struct pciide_softc *,
190 struct pci_attach_args *));
191 int pciide_chansetup __P((struct pciide_softc *, int, pcireg_t));
192 void pciide_mapchan __P((struct pci_attach_args *,
193 struct pciide_channel *, pcireg_t, bus_size_t *, bus_size_t *,
194 int (*pci_intr) __P((void *))));
195 void pciide_map_compat_intr __P(( struct pci_attach_args *,
196 struct pciide_channel *, int));
197 int pciide_compat_intr __P((void *));
198 int pciide_pci_intr __P((void *));
199