]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/aic7xxx/aic7xxx_osm.h
Use pci_find_extcap() to search for AGP capabilities (PCIY_AGP).
[FreeBSD/FreeBSD.git] / sys / dev / aic7xxx / aic7xxx_osm.h
1 /*-
2  * FreeBSD platform specific driver option settings, data structures,
3  * function declarations and includes.
4  *
5  * Copyright (c) 1994-2001 Justin T. Gibbs.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions, and the following disclaimer,
13  *    without modification.
14  * 2. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * Alternatively, this software may be distributed under the terms of the
18  * GNU Public License ("GPL").
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#18 $
33  *
34  * $FreeBSD$
35  */
36
37 #ifndef _AIC7XXX_FREEBSD_H_
38 #define _AIC7XXX_FREEBSD_H_
39
40 #include <opt_aic7xxx.h>        /* for config options */
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/bus.h>            /* For device_t */
45 #if __FreeBSD_version >= 500000
46 #include <sys/endian.h>
47 #endif
48 #include <sys/eventhandler.h>
49 #include <sys/kernel.h>
50 #include <sys/malloc.h>
51 #include <sys/module.h>
52 #include <sys/queue.h>
53
54 #if __FreeBSD_version < 500000
55 #include <pci.h>
56 #else
57 #define NPCI 1
58 #endif
59
60 #if NPCI > 0
61 #define AIC_PCI_CONFIG 1
62 #endif
63 #include <machine/bus.h>
64 #include <machine/endian.h>
65 #include <machine/clock.h>
66 #include <machine/resource.h>
67
68 #include <sys/rman.h>
69
70 #if NPCI > 0
71 #if __FreeBSD_version >= 500000
72 #include <dev/pci/pcireg.h>
73 #include <dev/pci/pcivar.h>
74 #else
75 #include <pci/pcireg.h>
76 #include <pci/pcivar.h>
77 #endif
78 #endif
79
80 #include <cam/cam.h>
81 #include <cam/cam_ccb.h>
82 #include <cam/cam_debug.h>
83 #include <cam/cam_sim.h>
84 #include <cam/cam_xpt_sim.h>
85
86 #include <cam/scsi/scsi_all.h>
87 #include <cam/scsi/scsi_message.h>
88
89 #ifdef CAM_NEW_TRAN_CODE
90 #define AHC_NEW_TRAN_SETTINGS
91 #endif /* CAM_NEW_TRAN_CODE */
92
93 /*************************** Attachment Bookkeeping ***************************/
94 extern devclass_t ahc_devclass;
95
96 /****************************** Platform Macros *******************************/
97 #define SIM_IS_SCSIBUS_B(ahc, sim)      \
98         ((sim) == ahc->platform_data->sim_b)
99 #define SIM_CHANNEL(ahc, sim)   \
100         (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
101 #define SIM_SCSI_ID(ahc, sim)   \
102         (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
103 #define SIM_PATH(ahc, sim)      \
104         (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
105                                               : ahc->platform_data->path)
106 #define BUILD_SCSIID(ahc, sim, target_id, our_id) \
107         ((((target_id) << TID_SHIFT) & TID) | (our_id) \
108         | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0))
109
110 #define SCB_GET_SIM(ahc, scb) \
111         (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
112                                           : (ahc)->platform_data->sim_b)
113
114 #ifndef offsetof
115 #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
116 #endif
117
118 /************************ Tunable Driver Parameters  **************************/
119 /*
120  * The number of dma segments supported.  The sequencer can handle any number
121  * of physically contiguous S/G entrys.  To reduce the driver's memory
122  * consumption, we limit the number supported to be sufficient to handle
123  * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
124  * transfer is as fragmented as possible and unaligned, this turns out to
125  * be the number of paged sized transfers in MAXPHYS plus an extra element
126  * to handle any unaligned residual.  The sequencer fetches SG elements
127  * in cacheline sized chucks, so make the number per-transaction an even
128  * multiple of 16 which should align us on even the largest of cacheline
129  * boundaries. 
130  */
131 #define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
132
133 /* This driver supports target mode */
134 #define AHC_TARGET_MODE 1
135
136 /************************** Softc/SCB Platform Data ***************************/
137 struct ahc_platform_data {
138         /*
139          * Hooks into the XPT.
140          */
141         struct  cam_sim         *sim;
142         struct  cam_sim         *sim_b;
143         struct  cam_path        *path;
144         struct  cam_path        *path_b;
145
146         int                      regs_res_type;
147         int                      regs_res_id;
148         int                      irq_res_type;
149         struct resource         *regs;
150         struct resource         *irq;
151         void                    *ih;
152         eventhandler_tag         eh;
153         struct proc             *recovery_thread;
154 };
155
156 struct scb_platform_data {
157 };
158
159 /***************************** Core Includes **********************************/
160 #ifdef AHC_REG_PRETTY_PRINT
161 #define AIC_DEBUG_REGISTERS 1
162 #else
163 #define AIC_DEBUG_REGISTERS 0
164 #endif
165 #define AIC_CORE_INCLUDE <dev/aic7xxx/aic7xxx.h>
166 #define AIC_LIB_PREFIX ahc
167 #define AIC_CONST_PREFIX AHC
168 #include <dev/aic7xxx/aic_osm_lib.h>
169
170 /*************************** Device Access ************************************/
171 #define ahc_inb(ahc, port)                              \
172         bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
173
174 #define ahc_outb(ahc, port, value)                      \
175         bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
176
177 #define ahc_outsb(ahc, port, valp, count)               \
178         bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
179
180 #define ahc_insb(ahc, port, valp, count)                \
181         bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
182
183 static __inline void ahc_flush_device_writes(struct ahc_softc *);
184
185 static __inline void
186 ahc_flush_device_writes(struct ahc_softc *ahc)
187 {
188         /* XXX Is this sufficient for all architectures??? */
189         ahc_inb(ahc, INTSTAT);
190 }
191
192 /**************************** Locking Primitives ******************************/
193 /* Lock protecting internal data structures */
194 static __inline void ahc_lockinit(struct ahc_softc *);
195 static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
196 static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
197
198 /* Lock held during command compeletion to the upper layer */
199 static __inline void ahc_done_lockinit(struct ahc_softc *);
200 static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags);
201 static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags);
202
203 /* Lock held during ahc_list manipulation and ahc softc frees */
204 static __inline void ahc_list_lockinit(void);
205 static __inline void ahc_list_lock(unsigned long *flags);
206 static __inline void ahc_list_unlock(unsigned long *flags);
207
208 static __inline void
209 ahc_lockinit(struct ahc_softc *ahc)
210 {
211 }
212
213 static __inline void
214 ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
215 {
216         *flags = splcam();
217 }
218
219 static __inline void
220 ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
221 {
222         splx(*flags);
223 }
224
225 /* Lock held during command compeletion to the upper layer */
226 static __inline void
227 ahc_done_lockinit(struct ahc_softc *ahc)
228 {
229 }
230
231 static __inline void
232 ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
233 {
234 }
235
236 static __inline void
237 ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
238 {
239 }
240
241 /* Lock held during ahc_list manipulation and ahc softc frees */
242 static __inline void
243 ahc_list_lockinit(void)
244 {
245 }
246
247 static __inline void
248 ahc_list_lock(unsigned long *flags)
249 {
250 }
251
252 static __inline void
253 ahc_list_unlock(unsigned long *flags)
254 {
255 }
256
257 /************************* Initialization/Teardown ****************************/
258 int       ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
259 void      ahc_platform_free(struct ahc_softc *ahc);
260 int       ahc_map_int(struct ahc_softc *ahc);
261 int       ahc_attach(struct ahc_softc *);
262 int       ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc);
263 int       ahc_detach(device_t);
264
265 /********************************** PCI ***************************************/
266 #ifdef AIC_PCI_CONFIG
267 int ahc_pci_map_registers(struct ahc_softc *ahc);
268 #define ahc_pci_map_int ahc_map_int
269 #endif /*AIC_PCI_CONFIG*/
270
271 /******************************** VL/EISA *************************************/
272 int aic7770_map_registers(struct ahc_softc *ahc, u_int port);
273 static __inline int aic7770_map_int(struct ahc_softc *, int);
274
275 static __inline int
276 aic7770_map_int(struct ahc_softc *ahc, int irq)
277 {
278         /*
279          * The IRQ is unused in the FreeBSD
280          * implementation since the EISA and
281          * ISA attachments register the IRQ
282          * with newbus before the core is called.
283          */
284         return ahc_map_int(ahc);
285 }
286
287 /********************************* Debug **************************************/
288 static __inline void    ahc_print_path(struct ahc_softc *, struct scb *);
289 static __inline void    ahc_platform_dump_card_state(struct ahc_softc *ahc);
290
291 static __inline void
292 ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
293 {
294         xpt_print_path(scb->io_ctx->ccb_h.path);
295 }
296
297 static __inline void
298 ahc_platform_dump_card_state(struct ahc_softc *ahc)
299 {
300         /* Nothing to do here for FreeBSD */
301 }
302 /**************************** Transfer Settings *******************************/
303 void      ahc_notify_xfer_settings_change(struct ahc_softc *,
304                                           struct ahc_devinfo *);
305 void      ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *,
306                                 int /*enable*/);
307
308 /****************************** Interrupts ************************************/
309 void                    ahc_platform_intr(void *);
310 static __inline void    ahc_platform_flushwork(struct ahc_softc *ahc);
311 static __inline void
312 ahc_platform_flushwork(struct ahc_softc *ahc)
313 {
314 }
315
316 /************************ Misc Function Declarations **************************/
317 void      ahc_done(struct ahc_softc *ahc, struct scb *scb);
318 void      ahc_send_async(struct ahc_softc *, char /*channel*/,
319                          u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
320 #endif  /* _AIC7XXX_FREEBSD_H_ */