1 /* $FreeBSD: src/sys/dev/ct/ct_machdep.h,v 1.2.2.1 2001/07/26 02:32:18 nyan Exp $ */
2 /* $DragonFly: src/sys/dev/disk/ct/Attic/ct_machdep.h,v 1.3 2003/08/27 10:35:16 rob Exp $ */
3 /* $NecBSD: ct_machdep.h,v 1.4.12.2 2001/06/20 06:13:34 honda Exp $ */
7 * [NetBSD for NEC PC-98 series]
8 * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001
9 * NetBSD/pc98 porting staff. All rights reserved.
10 * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001
11 * Naofumi HONDA. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
37 #ifndef _CT_MACHDEP_H_
38 #define _CT_MACHDEP_H_
44 * 1) do not use bus_space_write/read_X directly in ct.c.
45 * 2) do not use port offset defs directly in ct.c.
48 /* special weight if requried */
51 #define CT_BUS_WEIGHT(chp) \
53 if ((chp)->ch_bus_weight != NULL) \
54 (chp)->ch_bus_weight((chp)); \
56 #else /* !CT_BUS_WEIGHT */
57 #define CT_BUS_WEIGHT(chp)
58 #endif /* !CT_BUS_WEIGHT */
61 #ifndef CT_USE_RELOCATE_OFFSET
66 #else /* CT_USE_RELOCATE_OFFSET */
67 #define addr_port ((chp)->ch_offset[0])
68 #define stat_port ((chp)->ch_offset[1])
69 #define ctrl_port ((chp)->ch_offset[2])
70 #define cmd_port ((chp)->ch_offset[3])
71 #endif /* CT_USE_RELOCATE_OFFSET */
74 * All port accesses primitive methods
76 static __inline u_int8_t ct_stat_read_1
77 (struct ct_bus_access_handle *);
78 static __inline u_int8_t ct_cmdp_read_1
79 (struct ct_bus_access_handle *);
80 static __inline void ct_cmdp_write_1
81 (struct ct_bus_access_handle *, u_int8_t);
82 static __inline u_int8_t ct_cr_read_1
83 (struct ct_bus_access_handle *, bus_addr_t);
84 static __inline void ct_cr_write_1
85 (struct ct_bus_access_handle *, bus_addr_t, u_int8_t);
86 static __inline void ct_write_cmds
87 (struct ct_bus_access_handle *, u_int8_t *, int);
88 static __inline u_int cthw_get_count
89 (struct ct_bus_access_handle *);
90 static __inline void cthw_set_count
91 (struct ct_bus_access_handle *, u_int);
93 static __inline u_int8_t
95 struct ct_bus_access_handle *chp;
99 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, stat_port);
105 cthw_set_count(chp, count)
106 struct ct_bus_access_handle *chp;
109 bus_space_tag_t bst = chp->ch_iot;
110 bus_space_handle_t bsh = chp->ch_ioh;
112 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
114 bus_space_write_1(bst, bsh, ctrl_port, count >> 16);
116 bus_space_write_1(bst, bsh, ctrl_port, count >> 8);
118 bus_space_write_1(bst, bsh, ctrl_port, count);
122 static __inline u_int
124 struct ct_bus_access_handle *chp;
126 bus_space_tag_t bst = chp->ch_iot;
127 bus_space_handle_t bsh = chp->ch_ioh;
130 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
132 count = (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 16);
134 count += (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 8);
136 count += ((u_int) bus_space_read_1(bst, bsh, ctrl_port));
142 ct_write_cmds(chp, cmd, len)
143 struct ct_bus_access_handle *chp;
147 bus_space_tag_t bst = chp->ch_iot;
148 bus_space_handle_t bsh = chp->ch_ioh;
151 bus_space_write_1(bst, bsh, addr_port, wd3s_cdb);
153 for (i = 0; i < len; i ++)
155 bus_space_write_1(bst, bsh, ctrl_port, cmd[i]);
160 static __inline u_int8_t
161 ct_cr_read_1(chp, offs)
162 struct ct_bus_access_handle *chp;
165 bus_space_tag_t bst = chp->ch_iot;
166 bus_space_handle_t bsh = chp->ch_ioh;
169 bus_space_write_1(bst, bsh, addr_port, offs);
171 regv = bus_space_read_1(bst, bsh, ctrl_port);
177 ct_cr_write_1(chp, offs, val)
178 struct ct_bus_access_handle *chp;
182 bus_space_tag_t bst = chp->ch_iot;
183 bus_space_handle_t bsh = chp->ch_ioh;
185 bus_space_write_1(bst, bsh, addr_port, offs);
187 bus_space_write_1(bst, bsh, ctrl_port, val);
191 static __inline u_int8_t
193 struct ct_bus_access_handle *chp;
197 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, cmd_port);
203 ct_cmdp_write_1(chp, val)
204 struct ct_bus_access_handle *chp;
208 bus_space_write_1(chp->ch_iot, chp->ch_ioh, cmd_port, val);
213 #define SOFT_INTR_REQUIRED(slp) (softintr((slp)->sl_irq))
215 #define SOFT_INTR_REQUIRED(slp)
217 #endif /* !_CT_MACHDEP_H_ */