kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / dev / disk / i386 / bs / bsif.h
1 /*      $NecBSD: bsif.h,v 1.5 1997/10/23 20:52:34 honda Exp $   */
2 /* $FreeBSD: src/sys/i386/isa/bs/bsif.h,v 1.12.2.2 2001/07/26 02:32:18 nyan Exp $ */
3 /* $DragonFly: src/sys/dev/disk/i386/bs/Attic/bsif.h,v 1.4 2003/08/07 21:16:52 dillon Exp $ */
4 /*
5  * Copyright (c) HONDA Naofumi, KATO Takenori, 1996.  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  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer as
13  *    the first lines of this file unmodified.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *   notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * The name of the author may not be used to endorse or promote products
18  * derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 /***************************************************
33  * misc device header in bs_softc
34  ***************************************************/
35 #ifdef __NetBSD__
36 #define OS_DEPEND_DEVICE_HEADER                 \
37         struct device sc_dev;                   \
38         void *sc_ih;
39
40 #define OS_DEPEND_SCSI_HEADER                   \
41         struct scsi_link sc_link;
42
43 #define OS_DEPEND_MISC_HEADER                   \
44         pisa_device_handle_t sc_dh;             \
45         bus_space_tag_t sc_iot;                 \
46         bus_space_tag_t sc_memt;                \
47         bus_space_handle_t sc_ioh;              \
48         bus_space_handle_t sc_delaybah;         \
49         bus_space_handle_t sc_memh;             \
50         bus_dma_tag_t sc_dmat;          
51
52 #endif  /* __NetBSD__ */
53 #ifdef __FreeBSD__
54 #define OS_DEPEND_DEVICE_HEADER                 \
55         int unit;
56
57 #define OS_DEPEND_SCSI_HEADER                   \
58         struct scsi_link sc_link;
59
60 #define OS_DEPEND_MISC_HEADER                   \
61         struct callout_handle timeout_ch;
62 #endif  /* __FreeBSD__ */
63
64 #if     defined(__NetBSD__)
65 #define BSHW_NBPG       NBPG
66 #endif
67 #if     defined(__FreeBSD__)
68 #define BSHW_NBPG       PAGE_SIZE
69 #endif
70
71 /***************************************************
72  * include
73  ***************************************************/
74 /* (I) common include */
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/kernel.h>
78 #include <sys/disklabel.h>
79 #include <sys/buf.h>
80 #include <sys/queue.h>
81 #include <sys/malloc.h>
82 #include <sys/errno.h>
83
84 #include <vm/vm.h>
85
86 /* (II) os depend include */
87 #ifdef  __NetBSD__
88 #include <sys/device.h>
89
90 #include <dev/isa/isareg.h>
91 #include <dev/isa/isavar.h>
92 #include <dev/isa/pisaif.h>
93 #include <dev/isa/isadmavar.h>
94 #include <dev/isa/isadmareg.h>
95
96 #include <dev/cons.h>
97
98 #include <machine/cpufunc.h>
99 #include <machine/bus.h>
100 #include <machine/intr.h>
101 #include <machine/dvcfg.h>
102
103 #include <scsi/scsi_all.h>
104 #include <scsi/scsiconf.h>
105 #include <scsi/scsi_disk.h>
106 #endif  /* __NetBSD__ */
107
108 #ifdef __FreeBSD__
109 #include <sys/conf.h>
110 #include <vm/vm_extern.h>
111 #include <vm/vm_kern.h>
112 #include <vm/pmap.h>
113
114 #include <machine/clock.h>
115 #include <machine/cpu.h>
116 #include <machine/md_var.h>
117 #include <machine/vmparam.h>
118 #include <machine/ipl.h>
119 #include <machine/dvcfg.h>
120
121 #include <bus/cam/scsi/scsi_all.h>
122 #if 0
123 #include <bus/cam/scsi/scsiconf.h>
124 #endif
125 #include <bus/cam/scsi/scsi_da.h>
126
127 #include <pc98/pc98/pc98.h>
128 #include <bus/isa/i386/isa_device.h>
129 #include <i386/isa/icu.h>
130 #endif  /* __FreeBSD__ */
131
132 /***************************************************
133  * BUS IO MAPPINGS & BS specific inclusion
134  ***************************************************/
135 #ifdef  __NetBSD__
136 #define BUS_IO_DELAY ((void) bus_space_read_1(bsc->sc_iot, bsc->sc_delaybah, 0))
137 #define BUS_IO_WEIGHT (bus_space_write_1(bsc->sc_iot, bsc->sc_delaybah, 0, 0))
138 #define BUS_IOR(offs) (bus_space_read_1(bsc->sc_iot, bsc->sc_ioh, (offs)))
139 #define BUS_IOW(offs, val) (bus_space_write_1(bsc->sc_iot, bsc->sc_ioh, (offs), (val)))
140
141 #include <dev/ic/wd33c93reg.h>
142 #include <dev/isa/ccbque.h>
143
144 #include <i386/Cbus/dev/scsi_dvcfg.h>
145 #include <i386/Cbus/dev/bs/bsvar.h>
146 #include <i386/Cbus/dev/bs/bshw.h>
147 #include <i386/Cbus/dev/bs/bsfunc.h>
148 #endif  /* __NetBSD__ */
149
150 #ifdef  __FreeBSD__
151 #define BUS_IO_DELAY ((void) inb(0x5f))
152 #define BUS_IO_WEIGHT (outb(0x5f, 0))
153 #define BUS_IOR(offs) (BUS_IO_DELAY, inb(bsc->sc_iobase + (offs)))
154 #define BUS_IOW(offs, val) (BUS_IO_DELAY, outb(bsc->sc_iobase + (offs), (val)))
155
156 #include <dev/ic/wd33c93reg.h>
157 #include <i386/isa/ccbque.h>
158
159 #include <bus/cam/scsi/scsi_dvcfg.h>
160 #include "bsvar.h"
161 #include "bshw.h"
162 #include "bsfunc.h"
163 #endif  /* __FreeBSD__ */
164
165 /***************************************************
166  * XS return type
167  ***************************************************/
168 #ifdef  __NetBSD__
169 #define XSBS_INT32T     int
170 #endif  /* __NetBSD__ */
171 #ifdef  __FreeBSD__
172 #define XSBS_INT32T     int32_t
173 #endif  /* __FreeBSD__ */
174
175 /***************************************************
176  * xs flags's abstraction (all currently used)
177  ***************************************************/
178 #define XSBS_ITSDONE    ITSDONE
179 #ifdef __NetBSD__
180 #define XSBS_SCSI_NOSLEEP       SCSI_NOSLEEP
181 #define XSBS_SCSI_POLL  SCSI_POLL
182 #endif  /* __NetBSD__ */
183 #ifdef __FreeBSD__
184 #define XSBS_SCSI_POLL  SCSI_NOMASK
185 #endif  /* __FreeBSD__ */
186
187 /***************************************************
188  * declare
189  ***************************************************/
190 /* (I) common declare */
191 void bs_alloc_buf __P((struct targ_info *));
192 #ifdef __NetBSD__
193 XSBS_INT32T bs_target_open __P((struct scsi_link *, struct cfdata *));
194 XSBS_INT32T bs_scsi_cmd __P((struct scsi_xfer *));
195 #endif
196 #ifdef __FreeBSD__
197 void bs_scsi_cmd(struct cam_sim *sim, union ccb *ccb);
198 #endif
199 extern int delaycount;
200
201 /* (II) os depend declare */
202 #ifdef __NetBSD__
203 int bsintr __P((void *));
204 int bsprint __P((void *, const char *));
205 #endif  /* __NetBSD__ */
206
207 #ifdef __FreeBSD__
208 static BS_INLINE void memcopy __P((void *from, void *to, register size_t len));
209 u_int32_t bs_adapter_info __P((int));
210 #define delay(y) DELAY(y)
211 extern int dma_init_flag;
212 #ifdef SMP
213 #error XXX see comments in i386/isa/bs/bsif.h for details
214 /*
215  * ipending is 'opaque' in SMP, and can't be accessed this way.
216  * Since its my belief that this is PC98 code, and that PC98 and SMP
217  * are mutually exclusive, the above compile-time error is the "fix".
218  * Please inform smp@freebsd.org if this is NOT the case.
219  */
220 #else
221 #define softintr(y) ipending |= (1 << y)
222 #endif /* SMP */
223
224 static BS_INLINE void
225 memcopy(from, to, len)
226         void *from, *to;
227         size_t len;
228 {
229         len >>= 2;
230         __asm __volatile("                      \n\
231                 cld                             \n\
232                 rep                             \n\
233                 movsl"                          :
234             "=D" (to), "=c" (len), "=S" (from)  :
235             "0" (to), "1" (len), "2" (from)     :
236             "memory", "cc");
237 }
238 #endif  /* __FreeBSD__ */