1 /* $FreeBSD$ */
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(struct ct_bus_access_handle *chp)
94 {
95 u_int8_t regv;
96
97 regv = bus_read_1(chp->ch_io, stat_port);
98 CT_BUS_WEIGHT(chp)
99 return regv;
100 }
101
102 static __inline void
103 cthw_set_count(struct ct_bus_access_handle *chp, u_int count)
104 {
105
106 bus_write_1(chp->ch_io, addr_port, wd3s_cnt);
107 CT_BUS_WEIGHT(chp)
108 bus_write_1(chp->ch_io, ctrl_port, count >> 16);
109 CT_BUS_WEIGHT(chp)
110 bus_write_1(chp->ch_io, ctrl_port, count >> 8);
111 CT_BUS_WEIGHT(chp)
112 bus_write_1(chp->ch_io, ctrl_port, count);
113 CT_BUS_WEIGHT(chp)
114 }
115
116 static __inline u_int
117 cthw_get_count(struct ct_bus_access_handle *chp)
118 {
119 u_int count;
120
121 bus_write_1(chp->ch_io, addr_port, wd3s_cnt);
122 CT_BUS_WEIGHT(chp)
123 count = (((u_int) bus_read_1(chp->ch_io, ctrl_port)) << 16);
124 CT_BUS_WEIGHT(chp)
125 count += (((u_int) bus_read_1(chp->ch_io, ctrl_port)) << 8);
126 CT_BUS_WEIGHT(chp)
127 count += ((u_int) bus_read_1(chp->ch_io, ctrl_port));
128 CT_BUS_WEIGHT(chp)
129 return count;
130 }
131
132 static __inline void
133 ct_write_cmds(struct ct_bus_access_handle *chp, u_int8_t *cmd, int len)
134 {
135 int i;
136
137 bus_write_1(chp->ch_io, addr_port, wd3s_cdb);
138 CT_BUS_WEIGHT(chp)
139 for (i = 0; i < len; i ++)
140 {
141 bus_write_1(chp->ch_io, ctrl_port, cmd[i]);
142 CT_BUS_WEIGHT(chp)
143 }
144 }
145
146 static __inline u_int8_t
147 ct_cr_read_1(struct ct_bus_access_handle *chp, bus_addr_t offs)
148 {
149 u_int8_t regv;
150
151 bus_write_1(chp->ch_io, addr_port, offs);
152 CT_BUS_WEIGHT(chp)
153 regv = bus_read_1(chp->ch_io, ctrl_port);
154 CT_BUS_WEIGHT(chp)
155 return regv;
156 }
157
158 static __inline void
159 ct_cr_write_1(struct ct_bus_access_handle *chp, bus_addr_t offs, u_int8_t val)
160 {
161
162 bus_write_1(chp->ch_io, addr_port, offs);
163 CT_BUS_WEIGHT(chp)
164 bus_write_1(chp->ch_io, ctrl_port, val);
165 CT_BUS_WEIGHT(chp)
166 }
167
168 static __inline u_int8_t
169 ct_cmdp_read_1(struct ct_bus_access_handle *chp)
170 {
171 u_int8_t regv;
172
173 regv = bus_read_1(chp->ch_io, cmd_port);
174 CT_BUS_WEIGHT(chp)
175 return regv;
176 }
177
178 static __inline void
179 ct_cmdp_write_1(struct ct_bus_access_handle *chp, u_int8_t val)
180 {
181
182 bus_write_1(chp->ch_io, cmd_port, val);
183 CT_BUS_WEIGHT(chp)
184 }
185
186 #endif /* !_CT_MACHDEP_H_ */
Cache object: 80f9397640713fe84e0c089658307a5d
|