173149Snyan/* $FreeBSD$ */
279697Snon/*	$NecBSD: ct_machdep.h,v 1.4.12.2 2001/06/20 06:13:34 honda Exp $	*/
373149Snyan/*	$NetBSD$	*/
473149Snyan
5139749Simp/*-
673149Snyan * [NetBSD for NEC PC-98 series]
779697Snon *  Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001
873149Snyan *	NetBSD/pc98 porting staff. All rights reserved.
979697Snon *  Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001
1073149Snyan *	Naofumi HONDA. All rights reserved.
1173149Snyan *
1273149Snyan *  Redistribution and use in source and binary forms, with or without
1373149Snyan *  modification, are permitted provided that the following conditions
1473149Snyan *  are met:
1573149Snyan *  1. Redistributions of source code must retain the above copyright
1673149Snyan *     notice, this list of conditions and the following disclaimer.
1773149Snyan *  2. Redistributions in binary form must reproduce the above copyright
1873149Snyan *     notice, this list of conditions and the following disclaimer in the
1973149Snyan *     documentation and/or other materials provided with the distribution.
2073149Snyan *  3. The name of the author may not be used to endorse or promote products
2173149Snyan *     derived from this software without specific prior written permission.
2273149Snyan *
2373149Snyan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2473149Snyan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2573149Snyan * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2673149Snyan * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2773149Snyan * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2873149Snyan * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2973149Snyan * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3073149Snyan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3173149Snyan * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
3273149Snyan * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3373149Snyan * POSSIBILITY OF SUCH DAMAGE.
3473149Snyan */
3573149Snyan
3673149Snyan#ifndef	_CT_MACHDEP_H_
3773149Snyan#define	_CT_MACHDEP_H_
3873149Snyan
3979697Snon#include "opt_ct.h"
4079697Snon
4173149Snyan/*
4273149Snyan * Principal rules:
4373149Snyan * 1) do not use bus_space_write/read_X directly in ct.c.
4473149Snyan * 2) do not use port offset defs directly in ct.c.
4573149Snyan */
4673149Snyan
4773149Snyan/* special weight if requried */
4879697Snon#ifdef	CT_BUS_WEIGHT
4979697Snon#undef	CT_BUS_WEIGHT
5079697Snon#define	CT_BUS_WEIGHT(chp) 			\
5179697Snon{					 	\
5279697Snon	if ((chp)->ch_bus_weight != NULL) 	\
5379697Snon		(chp)->ch_bus_weight((chp));	\
5479697Snon}
5579697Snon#else	/* !CT_BUS_WEIGHT */
5679697Snon#define	CT_BUS_WEIGHT(chp)
5779697Snon#endif	/* !CT_BUS_WEIGHT */
5873149Snyan
5973149Snyan/* port offset */
6079697Snon#ifndef	CT_USE_RELOCATE_OFFSET
6173149Snyan#define	addr_port	0
6273149Snyan#define	stat_port	0
6373149Snyan#define	ctrl_port	2
6473149Snyan#define	cmd_port	4
6579697Snon#else	/* CT_USE_RELOCATE_OFFSET */
6679697Snon#define	addr_port	((chp)->ch_offset[0])
6779697Snon#define	stat_port	((chp)->ch_offset[1])
6879697Snon#define	ctrl_port	((chp)->ch_offset[2])
6979697Snon#define	cmd_port	((chp)->ch_offset[3])
7079697Snon#endif	/* CT_USE_RELOCATE_OFFSET */
7173149Snyan
7273149Snyan/*
7373149Snyan * All port accesses primitive methods
7473149Snyan */
7579697Snonstatic __inline u_int8_t ct_stat_read_1
7692739Salfred	(struct ct_bus_access_handle *);
7779697Snonstatic __inline u_int8_t ct_cmdp_read_1
7892739Salfred	(struct ct_bus_access_handle *);
7979697Snonstatic __inline void ct_cmdp_write_1
8092739Salfred	(struct ct_bus_access_handle *, u_int8_t);
8179697Snonstatic __inline u_int8_t ct_cr_read_1
8292739Salfred	(struct ct_bus_access_handle *, bus_addr_t);
8379697Snonstatic __inline void ct_cr_write_1
8492739Salfred	(struct ct_bus_access_handle *, bus_addr_t, u_int8_t);
8579697Snonstatic __inline void ct_write_cmds
8692739Salfred	(struct ct_bus_access_handle *, u_int8_t *, int);
8779697Snonstatic __inline u_int cthw_get_count
8892739Salfred	(struct ct_bus_access_handle *);
8979697Snonstatic __inline void cthw_set_count
9092739Salfred	(struct ct_bus_access_handle *, u_int);
9173149Snyan
9279697Snonstatic __inline u_int8_t
93242871Snyanct_stat_read_1(struct ct_bus_access_handle *chp)
9479697Snon{
9579697Snon	u_int8_t regv;
9673149Snyan
97274760Sjhb	regv = bus_read_1(chp->ch_io, stat_port);
9879697Snon	CT_BUS_WEIGHT(chp)
9979697Snon	return regv;
10079697Snon}
10179697Snon
10273149Snyanstatic __inline void
103242871Snyancthw_set_count(struct ct_bus_access_handle *chp, u_int count)
10473149Snyan{
10573149Snyan
106274760Sjhb	bus_write_1(chp->ch_io, addr_port, wd3s_cnt);
10779697Snon	CT_BUS_WEIGHT(chp)
108274760Sjhb	bus_write_1(chp->ch_io, ctrl_port, count >> 16);
10979697Snon	CT_BUS_WEIGHT(chp)
110274760Sjhb	bus_write_1(chp->ch_io, ctrl_port, count >> 8);
11179697Snon	CT_BUS_WEIGHT(chp)
112274760Sjhb	bus_write_1(chp->ch_io, ctrl_port, count);
11379697Snon	CT_BUS_WEIGHT(chp)
11473149Snyan}
11573149Snyan
11673149Snyanstatic __inline u_int
117242871Snyancthw_get_count(struct ct_bus_access_handle *chp)
11873149Snyan{
11973149Snyan	u_int count;
12073149Snyan
121274760Sjhb	bus_write_1(chp->ch_io, addr_port, wd3s_cnt);
12279697Snon	CT_BUS_WEIGHT(chp)
123274760Sjhb	count = (((u_int) bus_read_1(chp->ch_io, ctrl_port)) << 16);
12479697Snon	CT_BUS_WEIGHT(chp)
125274760Sjhb	count += (((u_int) bus_read_1(chp->ch_io, ctrl_port)) << 8);
12679697Snon	CT_BUS_WEIGHT(chp)
127274760Sjhb	count += ((u_int) bus_read_1(chp->ch_io, ctrl_port));
12879697Snon	CT_BUS_WEIGHT(chp)
12973149Snyan	return count;
13073149Snyan}
13173149Snyan
13273149Snyanstatic __inline void
133242871Snyanct_write_cmds(struct ct_bus_access_handle *chp, u_int8_t *cmd, int len)
13473149Snyan{
13573149Snyan	int i;
13673149Snyan
137274760Sjhb	bus_write_1(chp->ch_io, addr_port, wd3s_cdb);
13879697Snon	CT_BUS_WEIGHT(chp)
13973149Snyan	for (i = 0; i < len; i ++)
14079697Snon	{
141274760Sjhb		bus_write_1(chp->ch_io, ctrl_port, cmd[i]);
14279697Snon		CT_BUS_WEIGHT(chp)
14379697Snon	}
14473149Snyan}
14573149Snyan
14673149Snyanstatic __inline u_int8_t
147242871Snyanct_cr_read_1(struct ct_bus_access_handle *chp, bus_addr_t offs)
14873149Snyan{
14973149Snyan	u_int8_t regv;
15073149Snyan
151274760Sjhb	bus_write_1(chp->ch_io, addr_port, offs);
15279697Snon	CT_BUS_WEIGHT(chp)
153274760Sjhb	regv = bus_read_1(chp->ch_io, ctrl_port);
15479697Snon	CT_BUS_WEIGHT(chp)
15573149Snyan	return regv;
15673149Snyan}
15773149Snyan
15873149Snyanstatic __inline void
159242871Snyanct_cr_write_1(struct ct_bus_access_handle *chp, bus_addr_t offs, u_int8_t val)
16073149Snyan{
16173149Snyan
162274760Sjhb	bus_write_1(chp->ch_io, addr_port, offs);
16379697Snon	CT_BUS_WEIGHT(chp)
164274760Sjhb	bus_write_1(chp->ch_io, ctrl_port, val);
16579697Snon	CT_BUS_WEIGHT(chp)
16673149Snyan}
16773149Snyan
16879697Snonstatic __inline u_int8_t
169242871Snyanct_cmdp_read_1(struct ct_bus_access_handle *chp)
17079697Snon{
17179697Snon	u_int8_t regv;
17279697Snon
173274760Sjhb	regv = bus_read_1(chp->ch_io, cmd_port);
17479697Snon	CT_BUS_WEIGHT(chp)
17579697Snon	return regv;
17679697Snon}
17779697Snon
17879697Snonstatic __inline void
179242871Snyanct_cmdp_write_1(struct ct_bus_access_handle *chp, u_int8_t val)
18079697Snon{
18179697Snon
182274760Sjhb	bus_write_1(chp->ch_io, cmd_port, val);
18379697Snon	CT_BUS_WEIGHT(chp)
18479697Snon}
18579697Snon
18673149Snyan#endif	/* !_CT_MACHDEP_H_ */
187