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
93 ct_stat_read_1(struct ct_bus_access_handle *chp)
97 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, stat_port);
103 cthw_set_count(struct ct_bus_access_handle *chp, u_int count)
105 bus_space_tag_t bst = chp->ch_iot;
106 bus_space_handle_t bsh = chp->ch_ioh;
108 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
110 bus_space_write_1(bst, bsh, ctrl_port, count >> 16);
112 bus_space_write_1(bst, bsh, ctrl_port, count >> 8);
114 bus_space_write_1(bst, bsh, ctrl_port, count);
118 static __inline u_int
119 cthw_get_count(struct ct_bus_access_handle *chp)
121 bus_space_tag_t bst = chp->ch_iot;
122 bus_space_handle_t bsh = chp->ch_ioh;
125 bus_space_write_1(bst, bsh, addr_port, wd3s_cnt);
127 count = (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 16);
129 count += (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 8);
131 count += ((u_int) bus_space_read_1(bst, bsh, ctrl_port));
137 ct_write_cmds(struct ct_bus_access_handle *chp, u_int8_t *cmd, int len)
139 bus_space_tag_t bst = chp->ch_iot;
140 bus_space_handle_t bsh = chp->ch_ioh;
143 bus_space_write_1(bst, bsh, addr_port, wd3s_cdb);
145 for (i = 0; i < len; i ++)
147 bus_space_write_1(bst, bsh, ctrl_port, cmd[i]);
152 static __inline u_int8_t
153 ct_cr_read_1(struct ct_bus_access_handle *chp, bus_addr_t offs)
155 bus_space_tag_t bst = chp->ch_iot;
156 bus_space_handle_t bsh = chp->ch_ioh;
159 bus_space_write_1(bst, bsh, addr_port, offs);
161 regv = bus_space_read_1(bst, bsh, ctrl_port);
167 ct_cr_write_1(struct ct_bus_access_handle *chp, bus_addr_t offs, u_int8_t val)
169 bus_space_tag_t bst = chp->ch_iot;
170 bus_space_handle_t bsh = chp->ch_ioh;
172 bus_space_write_1(bst, bsh, addr_port, offs);
174 bus_space_write_1(bst, bsh, ctrl_port, val);
178 static __inline u_int8_t
179 ct_cmdp_read_1(struct ct_bus_access_handle *chp)
183 regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, cmd_port);
189 ct_cmdp_write_1(struct ct_bus_access_handle *chp, u_int8_t val)
192 bus_space_write_1(chp->ch_iot, chp->ch_ioh, cmd_port, val);
196 #endif /* !_CT_MACHDEP_H_ */