2 /* $NecBSD: ct_machdep.h,v 1.4.12.2 2001/06/20 06:13:34 honda Exp $ */
6 * [NetBSD for NEC PC-98 series]
7 * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001
8 * NetBSD/pc98 porting staff. All rights reserved.
9 * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001
10 * Naofumi HONDA. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
36 #ifndef _CT_MACHDEP_H_
37 #define _CT_MACHDEP_H_
43 * 1) do not use bus_space_write/read_X directly in ct.c.
44 * 2) do not use port offset defs directly in ct.c.
47 /* special weight if requried */
50 #define CT_BUS_WEIGHT(chp) \
52 if ((chp)->ch_bus_weight != NULL) \
53 (chp)->ch_bus_weight((chp)); \
55 #else /* !CT_BUS_WEIGHT */
56 #define CT_BUS_WEIGHT(chp)
57 #endif /* !CT_BUS_WEIGHT */
60 #ifndef CT_USE_RELOCATE_OFFSET
65 #else /* CT_USE_RELOCATE_OFFSET */
66 #define addr_port ((chp)->ch_offset[0])
67 #define stat_port ((chp)->ch_offset[1])
68 #define ctrl_port ((chp)->ch_offset[2])
69 #define cmd_port ((chp)->ch_offset[3])
70 #endif /* CT_USE_RELOCATE_OFFSET */
73 * All port accesses primitive methods
75 static __inline u_int8_t ct_stat_read_1
76 (struct ct_bus_access_handle *);
77 static __inline u_int8_t ct_cmdp_read_1
78 (struct ct_bus_access_handle *);
79 static __inline void ct_cmdp_write_1
80 (struct ct_bus_access_handle *, u_int8_t);
81 static __inline u_int8_t ct_cr_read_1
82 (struct ct_bus_access_handle *, bus_addr_t);
83 static __inline void ct_cr_write_1
84 (struct ct_bus_access_handle *, bus_addr_t, u_int8_t);
85 static __inline void ct_write_cmds
86 (struct ct_bus_access_handle *, u_int8_t *, int);
87 static __inline u_int cthw_get_count
88 (struct ct_bus_access_handle *);
89 static __inline void cthw_set_count
90 (struct ct_bus_access_handle *, u_int);
92 static __inline u_int8_t
94 struct ct_bus_access_handle *chp;
98 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, stat_port);
104 cthw_set_count(chp, count)
105 struct ct_bus_access_handle *chp;
108 bus_space_tag_t bst = chp->ch_iot;
109 bus_space_handle_t bsh = chp->ch_ioh;
111 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
113 bus_space_write_1(bst, bsh, ctrl_port, count >> 16);
115 bus_space_write_1(bst, bsh, ctrl_port, count >> 8);
117 bus_space_write_1(bst, bsh, ctrl_port, count);
121 static __inline u_int
123 struct ct_bus_access_handle *chp;
125 bus_space_tag_t bst = chp->ch_iot;
126 bus_space_handle_t bsh = chp->ch_ioh;
129 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
131 count = (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 16);
133 count += (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 8);
135 count += ((u_int) bus_space_read_1(bst, bsh, ctrl_port));
141 ct_write_cmds(chp, cmd, len)
142 struct ct_bus_access_handle *chp;
146 bus_space_tag_t bst = chp->ch_iot;
147 bus_space_handle_t bsh = chp->ch_ioh;
150 bus_space_write_1(bst, bsh, addr_port, wd3s_cdb);
152 for (i = 0; i < len; i ++)
154 bus_space_write_1(bst, bsh, ctrl_port, cmd[i]);
159 static __inline u_int8_t
160 ct_cr_read_1(chp, offs)
161 struct ct_bus_access_handle *chp;
164 bus_space_tag_t bst = chp->ch_iot;
165 bus_space_handle_t bsh = chp->ch_ioh;
168 bus_space_write_1(bst, bsh, addr_port, offs);
170 regv = bus_space_read_1(bst, bsh, ctrl_port);
176 ct_cr_write_1(chp, offs, val)
177 struct ct_bus_access_handle *chp;
181 bus_space_tag_t bst = chp->ch_iot;
182 bus_space_handle_t bsh = chp->ch_ioh;
184 bus_space_write_1(bst, bsh, addr_port, offs);
186 bus_space_write_1(bst, bsh, ctrl_port, val);
190 static __inline u_int8_t
192 struct ct_bus_access_handle *chp;
196 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, cmd_port);
202 ct_cmdp_write_1(chp, val)
203 struct ct_bus_access_handle *chp;
207 bus_space_write_1(chp->ch_iot, chp->ch_ioh, cmd_port, val);
211 #if defined(__i386__) && 0
212 #define SOFT_INTR_REQUIRED(slp) (softintr((slp)->sl_irq))
213 #else /* !__i386__ */
214 #define SOFT_INTR_REQUIRED(slp)
215 #endif /* !__i386__ */
216 #endif /* !_CT_MACHDEP_H_ */