]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/ct/ct_machdep.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / ct / ct_machdep.h
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_space_read_1(chp->ch_iot, chp->ch_ioh, 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         bus_space_tag_t bst = chp->ch_iot;
106         bus_space_handle_t bsh = chp->ch_ioh;
107
108         bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
109         CT_BUS_WEIGHT(chp)
110         bus_space_write_1(bst, bsh, ctrl_port, count >> 16);
111         CT_BUS_WEIGHT(chp)
112         bus_space_write_1(bst, bsh, ctrl_port, count >> 8);
113         CT_BUS_WEIGHT(chp)
114         bus_space_write_1(bst, bsh, ctrl_port, count);
115         CT_BUS_WEIGHT(chp)
116 }
117
118 static __inline u_int
119 cthw_get_count(struct ct_bus_access_handle *chp)
120 {
121         bus_space_tag_t bst = chp->ch_iot;
122         bus_space_handle_t bsh = chp->ch_ioh;
123         u_int count;
124
125         bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
126         CT_BUS_WEIGHT(chp)
127         count = (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 16);
128         CT_BUS_WEIGHT(chp)
129         count += (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 8);
130         CT_BUS_WEIGHT(chp)
131         count += ((u_int) bus_space_read_1(bst, bsh, ctrl_port));
132         CT_BUS_WEIGHT(chp)
133         return count;
134 }
135
136 static __inline void
137 ct_write_cmds(struct ct_bus_access_handle *chp, u_int8_t *cmd, int len)
138 {
139         bus_space_tag_t bst = chp->ch_iot;
140         bus_space_handle_t bsh = chp->ch_ioh;
141         int i;
142
143         bus_space_write_1(bst, bsh, addr_port, wd3s_cdb);
144         CT_BUS_WEIGHT(chp)
145         for (i = 0; i < len; i ++)
146         {
147                 bus_space_write_1(bst, bsh, ctrl_port, cmd[i]);
148                 CT_BUS_WEIGHT(chp)
149         }
150 }       
151
152 static __inline u_int8_t
153 ct_cr_read_1(struct ct_bus_access_handle *chp, bus_addr_t offs)
154 {
155         bus_space_tag_t bst = chp->ch_iot;
156         bus_space_handle_t bsh = chp->ch_ioh;
157         u_int8_t regv;
158
159         bus_space_write_1(bst, bsh, addr_port, offs);
160         CT_BUS_WEIGHT(chp)
161         regv = bus_space_read_1(bst, bsh, ctrl_port);
162         CT_BUS_WEIGHT(chp)
163         return regv;
164 }
165
166 static __inline void
167 ct_cr_write_1(struct ct_bus_access_handle *chp, bus_addr_t offs, u_int8_t val)
168 {
169         bus_space_tag_t bst = chp->ch_iot;
170         bus_space_handle_t bsh = chp->ch_ioh;
171
172         bus_space_write_1(bst, bsh, addr_port, offs);
173         CT_BUS_WEIGHT(chp)
174         bus_space_write_1(bst, bsh, ctrl_port, val);
175         CT_BUS_WEIGHT(chp)
176 }
177
178 static __inline u_int8_t
179 ct_cmdp_read_1(struct ct_bus_access_handle *chp)
180 {
181         u_int8_t regv;
182
183         regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, cmd_port);
184         CT_BUS_WEIGHT(chp)
185         return regv;
186 }
187
188 static __inline void
189 ct_cmdp_write_1(struct ct_bus_access_handle *chp, u_int8_t val)
190 {
191
192         bus_space_write_1(chp->ch_iot, chp->ch_ioh, cmd_port, val);
193         CT_BUS_WEIGHT(chp)
194 }
195
196 #endif  /* !_CT_MACHDEP_H_ */