1 /* $FreeBSD: releng/7.4/sys/dev/ct/ct_machdep.h 139749 2005-01-06 01:43:34Z imp $ */
2 /* $NecBSD: ct_machdep.h,v 1.4.12.2 2001/06/20 06:13:34 honda Exp $ */
3 /* $NetBSD$ */
4
5 /*-
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.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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.
22 *
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.
34 */
35
36 #ifndef _CT_MACHDEP_H_
37 #define _CT_MACHDEP_H_
38
39 #include "opt_ct.h"
40
41 /*
42 * Principal rules:
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.
45 */
46
47 /* special weight if requried */
48 #ifdef CT_BUS_WEIGHT
49 #undef CT_BUS_WEIGHT
50 #define CT_BUS_WEIGHT(chp) \
51 { \
52 if ((chp)->ch_bus_weight != NULL) \
53 (chp)->ch_bus_weight((chp)); \
54 }
55 #else /* !CT_BUS_WEIGHT */
56 #define CT_BUS_WEIGHT(chp)
57 #endif /* !CT_BUS_WEIGHT */
58
59 /* port offset */
60 #ifndef CT_USE_RELOCATE_OFFSET
61 #define addr_port 0
62 #define stat_port 0
63 #define ctrl_port 2
64 #define cmd_port 4
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 */
71
72 /*
73 * All port accesses primitive methods
74 */
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);
91
92 static __inline u_int8_t
93 ct_stat_read_1(chp)
94 struct ct_bus_access_handle *chp;
95 {
96 u_int8_t regv;
97
98 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, stat_port);
99 CT_BUS_WEIGHT(chp)
100 return regv;
101 }
102
103 static __inline void
104 cthw_set_count(chp, count)
105 struct ct_bus_access_handle *chp;
106 u_int count;
107 {
108 bus_space_tag_t bst = chp->ch_iot;
109 bus_space_handle_t bsh = chp->ch_ioh;
110
111 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
112 CT_BUS_WEIGHT(chp)
113 bus_space_write_1(bst, bsh, ctrl_port, count >> 16);
114 CT_BUS_WEIGHT(chp)
115 bus_space_write_1(bst, bsh, ctrl_port, count >> 8);
116 CT_BUS_WEIGHT(chp)
117 bus_space_write_1(bst, bsh, ctrl_port, count);
118 CT_BUS_WEIGHT(chp)
119 }
120
121 static __inline u_int
122 cthw_get_count(chp)
123 struct ct_bus_access_handle *chp;
124 {
125 bus_space_tag_t bst = chp->ch_iot;
126 bus_space_handle_t bsh = chp->ch_ioh;
127 u_int count;
128
129 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
130 CT_BUS_WEIGHT(chp)
131 count = (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 16);
132 CT_BUS_WEIGHT(chp)
133 count += (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 8);
134 CT_BUS_WEIGHT(chp)
135 count += ((u_int) bus_space_read_1(bst, bsh, ctrl_port));
136 CT_BUS_WEIGHT(chp)
137 return count;
138 }
139
140 static __inline void
141 ct_write_cmds(chp, cmd, len)
142 struct ct_bus_access_handle *chp;
143 u_int8_t *cmd;
144 int len;
145 {
146 bus_space_tag_t bst = chp->ch_iot;
147 bus_space_handle_t bsh = chp->ch_ioh;
148 int i;
149
150 bus_space_write_1(bst, bsh, addr_port, wd3s_cdb);
151 CT_BUS_WEIGHT(chp)
152 for (i = 0; i < len; i ++)
153 {
154 bus_space_write_1(bst, bsh, ctrl_port, cmd[i]);
155 CT_BUS_WEIGHT(chp)
156 }
157 }
158
159 static __inline u_int8_t
160 ct_cr_read_1(chp, offs)
161 struct ct_bus_access_handle *chp;
162 bus_addr_t offs;
163 {
164 bus_space_tag_t bst = chp->ch_iot;
165 bus_space_handle_t bsh = chp->ch_ioh;
166 u_int8_t regv;
167
168 bus_space_write_1(bst, bsh, addr_port, offs);
169 CT_BUS_WEIGHT(chp)
170 regv = bus_space_read_1(bst, bsh, ctrl_port);
171 CT_BUS_WEIGHT(chp)
172 return regv;
173 }
174
175 static __inline void
176 ct_cr_write_1(chp, offs, val)
177 struct ct_bus_access_handle *chp;
178 bus_addr_t offs;
179 u_int8_t val;
180 {
181 bus_space_tag_t bst = chp->ch_iot;
182 bus_space_handle_t bsh = chp->ch_ioh;
183
184 bus_space_write_1(bst, bsh, addr_port, offs);
185 CT_BUS_WEIGHT(chp)
186 bus_space_write_1(bst, bsh, ctrl_port, val);
187 CT_BUS_WEIGHT(chp)
188 }
189
190 static __inline u_int8_t
191 ct_cmdp_read_1(chp)
192 struct ct_bus_access_handle *chp;
193 {
194 u_int8_t regv;
195
196 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, cmd_port);
197 CT_BUS_WEIGHT(chp)
198 return regv;
199 }
200
201 static __inline void
202 ct_cmdp_write_1(chp, val)
203 struct ct_bus_access_handle *chp;
204 u_int8_t val;
205 {
206
207 bus_space_write_1(chp->ch_iot, chp->ch_ioh, cmd_port, val);
208 CT_BUS_WEIGHT(chp)
209 }
210
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_ */
Cache object: 0f5703478389709e54fa530314557482
|