remove __P() from this directory
[dragonfly.git] / sys / dev / disk / ct / ct_machdep.h
CommitLineData
984263bc 1/* $FreeBSD: src/sys/dev/ct/ct_machdep.h,v 1.2.2.1 2001/07/26 02:32:18 nyan Exp $ */
38e94a25 2/* $DragonFly: src/sys/dev/disk/ct/Attic/ct_machdep.h,v 1.3 2003/08/27 10:35:16 rob Exp $ */
984263bc
MD
3/* $NecBSD: ct_machdep.h,v 1.4.12.2 2001/06/20 06:13:34 honda Exp $ */
4/* $NetBSD$ */
5
6/*
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.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
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.
23 *
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.
35 */
36
37#ifndef _CT_MACHDEP_H_
38#define _CT_MACHDEP_H_
39
40#include "opt_ct.h"
41
42/*
43 * Principal rules:
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.
46 */
47
48/* special weight if requried */
49#ifdef CT_BUS_WEIGHT
50#undef CT_BUS_WEIGHT
51#define CT_BUS_WEIGHT(chp) \
52{ \
53 if ((chp)->ch_bus_weight != NULL) \
54 (chp)->ch_bus_weight((chp)); \
55}
56#else /* !CT_BUS_WEIGHT */
57#define CT_BUS_WEIGHT(chp)
58#endif /* !CT_BUS_WEIGHT */
59
60/* port offset */
61#ifndef CT_USE_RELOCATE_OFFSET
62#define addr_port 0
63#define stat_port 0
64#define ctrl_port 2
65#define cmd_port 4
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 */
72
73/*
74 * All port accesses primitive methods
75 */
76static __inline u_int8_t ct_stat_read_1
38e94a25 77 (struct ct_bus_access_handle *);
984263bc 78static __inline u_int8_t ct_cmdp_read_1
38e94a25 79 (struct ct_bus_access_handle *);
984263bc 80static __inline void ct_cmdp_write_1
38e94a25 81 (struct ct_bus_access_handle *, u_int8_t);
984263bc 82static __inline u_int8_t ct_cr_read_1
38e94a25 83 (struct ct_bus_access_handle *, bus_addr_t);
984263bc 84static __inline void ct_cr_write_1
38e94a25 85 (struct ct_bus_access_handle *, bus_addr_t, u_int8_t);
984263bc 86static __inline void ct_write_cmds
38e94a25 87 (struct ct_bus_access_handle *, u_int8_t *, int);
984263bc 88static __inline u_int cthw_get_count
38e94a25 89 (struct ct_bus_access_handle *);
984263bc 90static __inline void cthw_set_count
38e94a25 91 (struct ct_bus_access_handle *, u_int);
984263bc
MD
92
93static __inline u_int8_t
94ct_stat_read_1(chp)
95 struct ct_bus_access_handle *chp;
96{
97 u_int8_t regv;
98
99 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, stat_port);
100 CT_BUS_WEIGHT(chp)
101 return regv;
102}
103
104static __inline void
105cthw_set_count(chp, count)
106 struct ct_bus_access_handle *chp;
107 u_int count;
108{
109 bus_space_tag_t bst = chp->ch_iot;
110 bus_space_handle_t bsh = chp->ch_ioh;
111
112 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
113 CT_BUS_WEIGHT(chp)
114 bus_space_write_1(bst, bsh, ctrl_port, count >> 16);
115 CT_BUS_WEIGHT(chp)
116 bus_space_write_1(bst, bsh, ctrl_port, count >> 8);
117 CT_BUS_WEIGHT(chp)
118 bus_space_write_1(bst, bsh, ctrl_port, count);
119 CT_BUS_WEIGHT(chp)
120}
121
122static __inline u_int
123cthw_get_count(chp)
124 struct ct_bus_access_handle *chp;
125{
126 bus_space_tag_t bst = chp->ch_iot;
127 bus_space_handle_t bsh = chp->ch_ioh;
128 u_int count;
129
130 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
131 CT_BUS_WEIGHT(chp)
132 count = (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 16);
133 CT_BUS_WEIGHT(chp)
134 count += (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 8);
135 CT_BUS_WEIGHT(chp)
136 count += ((u_int) bus_space_read_1(bst, bsh, ctrl_port));
137 CT_BUS_WEIGHT(chp)
138 return count;
139}
140
141static __inline void
142ct_write_cmds(chp, cmd, len)
143 struct ct_bus_access_handle *chp;
144 u_int8_t *cmd;
145 int len;
146{
147 bus_space_tag_t bst = chp->ch_iot;
148 bus_space_handle_t bsh = chp->ch_ioh;
149 int i;
150
151 bus_space_write_1(bst, bsh, addr_port, wd3s_cdb);
152 CT_BUS_WEIGHT(chp)
153 for (i = 0; i < len; i ++)
154 {
155 bus_space_write_1(bst, bsh, ctrl_port, cmd[i]);
156 CT_BUS_WEIGHT(chp)
157 }
158}
159
160static __inline u_int8_t
161ct_cr_read_1(chp, offs)
162 struct ct_bus_access_handle *chp;
163 bus_addr_t offs;
164{
165 bus_space_tag_t bst = chp->ch_iot;
166 bus_space_handle_t bsh = chp->ch_ioh;
167 u_int8_t regv;
168
169 bus_space_write_1(bst, bsh, addr_port, offs);
170 CT_BUS_WEIGHT(chp)
171 regv = bus_space_read_1(bst, bsh, ctrl_port);
172 CT_BUS_WEIGHT(chp)
173 return regv;
174}
175
176static __inline void
177ct_cr_write_1(chp, offs, val)
178 struct ct_bus_access_handle *chp;
179 bus_addr_t offs;
180 u_int8_t val;
181{
182 bus_space_tag_t bst = chp->ch_iot;
183 bus_space_handle_t bsh = chp->ch_ioh;
184
185 bus_space_write_1(bst, bsh, addr_port, offs);
186 CT_BUS_WEIGHT(chp)
187 bus_space_write_1(bst, bsh, ctrl_port, val);
188 CT_BUS_WEIGHT(chp)
189}
190
191static __inline u_int8_t
192ct_cmdp_read_1(chp)
193 struct ct_bus_access_handle *chp;
194{
195 u_int8_t regv;
196
197 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, cmd_port);
198 CT_BUS_WEIGHT(chp)
199 return regv;
200}
201
202static __inline void
203ct_cmdp_write_1(chp, val)
204 struct ct_bus_access_handle *chp;
205 u_int8_t val;
206{
207
208 bus_space_write_1(chp->ch_iot, chp->ch_ioh, cmd_port, val);
209 CT_BUS_WEIGHT(chp)
210}
211
212#if defined(i386)
213#define SOFT_INTR_REQUIRED(slp) (softintr((slp)->sl_irq))
214#else /* !i386 */
215#define SOFT_INTR_REQUIRED(slp)
216#endif /* !i386 */
217#endif /* !_CT_MACHDEP_H_ */