1 /* $NecBSD: bshw.h,v 1.2 1997/10/31 17:43:38 honda Exp $ */
3 /* $DragonFly: src/sys/dev/disk/i386/bs/Attic/bshw.h,v 1.2 2003/08/27 10:35:16 rob Exp $ */
5 * [NetBSD for NEC PC98 series]
6 * Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1994, 1995, 1996 Naofumi HONDA. All rights reserved.
36 /* NEC port offsets */
37 #define BSHW_DEFAULT_PORT 0xcc0
45 #define BSHW_MAX_OFFSET 12
46 #define BSHW_SEL_TIMEOUT 0x80
48 #define BSHW_READ BSR_IOR
49 #define BSHW_WRITE 0x0
51 #define BSHW_SMITFIFO_OFFSET 0x1000
53 #define BSHW_CMD_CHECK(CCB, CAT) (bshw_cmd[(CCB)->cmd[0]] & (CAT))
54 /*********************************************************
55 * static inline declare.
56 *********************************************************/
57 static BS_INLINE void write_wd33c93 (struct bs_softc *, u_int, u_int8_t);
58 static BS_INLINE u_int8_t read_wd33c93 (struct bs_softc *, u_int);
59 static BS_INLINE u_int8_t bshw_get_auxstat (struct bs_softc *);
60 static BS_INLINE u_int8_t bshw_get_busstat (struct bs_softc *);
61 static BS_INLINE u_int8_t bshw_get_status_insat (struct bs_softc *);
62 static BS_INLINE u_int8_t bshw_read_data (struct bs_softc *);
63 static BS_INLINE void bshw_write_data (struct bs_softc *, u_int8_t);
64 static BS_INLINE void bshw_set_count (struct bs_softc *, u_int);
65 static BS_INLINE u_int bshw_get_count (struct bs_softc *);
66 static BS_INLINE void bshw_set_dst_id (struct bs_softc *, u_int, u_int);
67 static BS_INLINE void bshw_set_lun (struct bs_softc *, u_int);
68 static BS_INLINE u_int bshw_get_src_id (struct bs_softc *);
69 static BS_INLINE void bshw_negate_ack (struct bs_softc *);
70 static BS_INLINE void bshw_assert_atn (struct bs_softc *);
71 static BS_INLINE void bshw_assert_select (struct bs_softc *);
72 static BS_INLINE void bshw_start_xfer (struct bs_softc *);
73 static BS_INLINE void bshw_start_sxfer (struct bs_softc *);
74 static BS_INLINE void bshw_cmd_pass (struct bs_softc *, u_int);
75 static BS_INLINE void bshw_start_sat (struct bs_softc *, u_int);
76 static BS_INLINE void bshw_abort_cmd (struct bs_softc *);
77 static BS_INLINE void bshw_set_sync_reg (struct bs_softc *, u_int);
78 static BS_INLINE void bshw_set_poll_trans (struct bs_softc *, u_int);
79 static BS_INLINE void bshw_set_dma_trans (struct bs_softc *, u_int);
81 /*********************************************************
83 *********************************************************/
84 void bs_dma_xfer (struct targ_info *, u_int);
85 void bs_dma_xfer_end (struct targ_info *);
86 void bshw_dmaabort (struct bs_softc *, struct targ_info *);
88 void bshw_adj_syncdata (struct syncdata *);
89 void bshw_set_synchronous (struct bs_softc *, struct targ_info *);
91 void bs_smit_xfer_end (struct targ_info *);
92 void bshw_smitabort (struct bs_softc *);
94 void bshw_setup_ctrl_reg (struct bs_softc *, u_int);
95 int bshw_chip_reset (struct bs_softc *);
96 void bshw_bus_reset (struct bs_softc *);
97 int bshw_board_probe (struct bs_softc *, u_int *, u_int *);
98 void bshw_lock (struct bs_softc *);
99 void bshw_unlock (struct bs_softc *);
100 void bshw_get_syncreg (struct bs_softc *);
101 void bshw_issue_satcmd (struct bs_softc *, struct bsccb *, int);
102 void bshw_print_port (struct bs_softc *);
104 void bs_lc_smit_xfer (struct targ_info *, u_int);
106 extern struct dvcfg_hwsel bshw_hwsel;
107 extern u_int8_t bshw_cmd[];
109 /*********************************************************
111 *********************************************************/
113 #define BSHW_SYNC_RELOAD 0x01
114 #define BSHW_SMFIFO 0x02
115 #define BSHW_DOUBLE_DMACHAN 0x04
120 int ((*dma_init) (struct bs_softc *));
121 void ((*dma_start) (struct bs_softc *));
122 void ((*dma_stop) (struct bs_softc *));
125 /*********************************************************
127 *********************************************************/
129 * XXX: If your board does not work well, Please try BS_NEEDS_WEIGHT.
131 static BS_INLINE void
132 write_wd33c93(bsc, addr, data)
133 struct bs_softc *bsc;
138 BUS_IOW(addr_port, addr);
139 BUS_IOW(ctrl_port, data);
142 static BS_INLINE u_int8_t
143 read_wd33c93(bsc, addr)
144 struct bs_softc *bsc;
148 BUS_IOW(addr_port, addr);
149 return BUS_IOR(ctrl_port);
153 static BS_INLINE u_int8_t
154 bshw_get_auxstat(bsc)
155 struct bs_softc *bsc;
158 return BUS_IOR(stat_port);
161 static BS_INLINE u_int8_t
162 bshw_get_busstat(bsc)
163 struct bs_softc *bsc;
166 return read_wd33c93(bsc, wd3s_stat);
169 static BS_INLINE u_int8_t
170 bshw_get_status_insat(bsc)
171 struct bs_softc *bsc;
174 return read_wd33c93(bsc, wd3s_lun);
178 static BS_INLINE u_int8_t
180 struct bs_softc *bsc;
183 return read_wd33c93(bsc, wd3s_data);
186 static BS_INLINE void
187 bshw_write_data(bsc, data)
188 struct bs_softc *bsc;
192 write_wd33c93(bsc, wd3s_data, data);
196 static BS_INLINE void
197 bshw_set_count(bsc, count)
198 struct bs_softc *bsc;
202 BUS_IOW(addr_port, wd3s_cnt);
203 BUS_IOW(ctrl_port, count >> 16);
204 BUS_IOW(ctrl_port, count >> 8);
205 BUS_IOW(ctrl_port, count);
208 static BS_INLINE u_int
210 struct bs_softc *bsc;
214 BUS_IOW(addr_port, wd3s_cnt);
215 count = (((u_int) BUS_IOR(ctrl_port)) << 16);
216 count += (((u_int) BUS_IOR(ctrl_port)) << 8);
217 count += ((u_int) BUS_IOR(ctrl_port));
222 static BS_INLINE void
223 bshw_set_lun(bsc, lun)
224 struct bs_softc *bsc;
228 write_wd33c93(bsc, wd3s_lun, lun);
231 static BS_INLINE void
232 bshw_set_dst_id(bsc, target, lun)
233 struct bs_softc *bsc;
237 write_wd33c93(bsc, wd3s_did, target);
238 write_wd33c93(bsc, wd3s_lun, lun);
241 static BS_INLINE u_int
243 struct bs_softc *bsc;
246 return (read_wd33c93(bsc, wd3s_sid) & SIDR_IDM);
250 static BS_INLINE void
252 struct bs_softc *bsc;
255 write_wd33c93(bsc, wd3s_cmd, WD3S_NEGATE_ACK);
258 static BS_INLINE void
260 struct bs_softc *bsc;
263 write_wd33c93(bsc, wd3s_cmd, WD3S_ASSERT_ATN);
266 static BS_INLINE void
267 bshw_assert_select(bsc)
268 struct bs_softc *bsc;
271 write_wd33c93(bsc, wd3s_cmd, WD3S_SELECT_ATN);
274 static BS_INLINE void
276 struct bs_softc *bsc;
279 write_wd33c93(bsc, wd3s_cmd, WD3S_TFR_INFO);
282 static BS_INLINE void
283 bshw_start_sxfer(bsc)
284 struct bs_softc *bsc;
287 write_wd33c93(bsc, wd3s_cmd, WD3S_SBT | WD3S_TFR_INFO);
290 static BS_INLINE void
291 bshw_cmd_pass(bsc, ph)
292 struct bs_softc *bsc;
296 write_wd33c93(bsc, wd3s_cph, ph);
299 static BS_INLINE void
300 bshw_start_sat(bsc, flag)
301 struct bs_softc *bsc;
305 write_wd33c93(bsc, wd3s_cmd,
306 (flag ? WD3S_SELECT_ATN_TFR : WD3S_SELECT_NO_ATN_TFR));
310 static BS_INLINE void
312 struct bs_softc *bsc;
315 write_wd33c93(bsc, wd3s_cmd, WD3S_ABORT);
319 static BS_INLINE void
320 bshw_set_sync_reg(bsc, val)
321 struct bs_softc *bsc;
325 write_wd33c93(bsc, wd3s_synch, val);
328 static BS_INLINE void
329 bshw_set_poll_trans(bsc, flags)
330 struct bs_softc *bsc;
334 if (bsc->sc_flags & BSDMATRANSFER)
336 bsc->sc_flags &= ~BSDMATRANSFER;
337 bshw_setup_ctrl_reg(bsc, flags);
341 static BS_INLINE void
342 bshw_set_dma_trans(bsc, flags)
343 struct bs_softc *bsc;
347 if ((bsc->sc_flags & BSDMATRANSFER) == 0)
349 bsc->sc_flags |= BSDMATRANSFER;
350 bshw_setup_ctrl_reg(bsc, flags);