summaryrefslogtreecommitdiffstats
path: root/sys/i386/isa/bs/bshw.h
blob: b58f1a0d9d4853cef1f33801798bad706e9c4618 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*	$NecBSD: bshw.h,v 1.2 1997/10/31 17:43:38 honda Exp $	*/
/*	$NetBSD$	*/
/*
 * [NetBSD for NEC PC98 series]
 *  Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
 *  All rights reserved.
 * 
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *  1. Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *  3. The name of the author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */
/*
 * Copyright (c) 1994, 1995, 1996 Naofumi HONDA.  All rights reserved.
 */

/* NEC port offsets */
#define	BSHW_DEFAULT_PORT	0xcc0
#define	BSHW_IOSZ	5

#define	addr_port	0
#define	stat_port	0
#define	ctrl_port	2
#define	cmd_port	4

#define	BSHW_MAX_OFFSET		12
#define	BSHW_SEL_TIMEOUT	0x80

#define	BSHW_READ		BSR_IOR
#define	BSHW_WRITE		0x0

#define	BSHW_SMITFIFO_OFFSET	0x1000

#define	BSHW_CMD_CHECK(CCB, CAT) (bshw_cmd[(CCB)->cmd[0]] & (CAT))
/*********************************************************
 * static inline declare.
 *********************************************************/
static BS_INLINE void write_wd33c93(struct bs_softc *, u_int, u_int8_t);
static BS_INLINE u_int8_t read_wd33c93(struct bs_softc *, u_int);
static BS_INLINE u_int8_t bshw_get_auxstat(struct bs_softc *);
static BS_INLINE u_int8_t bshw_get_busstat(struct bs_softc *);
static BS_INLINE u_int8_t bshw_get_status_insat(struct bs_softc *);
static BS_INLINE u_int8_t bshw_read_data(struct bs_softc *);
static BS_INLINE void bshw_write_data(struct bs_softc *, u_int8_t);
static BS_INLINE void bshw_set_count(struct bs_softc *, u_int);
static BS_INLINE u_int bshw_get_count(struct bs_softc *);
static BS_INLINE void bshw_set_dst_id(struct bs_softc *, u_int, u_int);
static BS_INLINE void bshw_set_lun(struct bs_softc *, u_int);
static BS_INLINE u_int bshw_get_src_id(struct bs_softc *);
static BS_INLINE void bshw_negate_ack(struct bs_softc *);
static BS_INLINE void bshw_assert_atn(struct bs_softc *);
static BS_INLINE void bshw_assert_select(struct bs_softc *);
static BS_INLINE void bshw_start_xfer(struct bs_softc *);
static BS_INLINE void bshw_start_sxfer(struct bs_softc *);
static BS_INLINE void bshw_cmd_pass(struct bs_softc *, u_int);
static BS_INLINE void bshw_start_sat(struct bs_softc *, u_int);
static BS_INLINE void bshw_abort_cmd(struct bs_softc *);
static BS_INLINE void bshw_set_sync_reg(struct bs_softc *, u_int);
static BS_INLINE void bshw_set_poll_trans(struct bs_softc *, u_int);
static BS_INLINE void bshw_set_dma_trans(struct bs_softc *, u_int);

/*********************************************************
 * global declare
 *********************************************************/
void bs_dma_xfer(struct targ_info *, u_int);
void bs_dma_xfer_end(struct targ_info *);
void bshw_dmaabort(struct bs_softc *, struct targ_info *);

void bshw_adj_syncdata(struct syncdata *);
void bshw_set_synchronous(struct bs_softc *, struct targ_info *);

void bs_smit_xfer_end(struct targ_info *);
void bshw_smitabort(struct bs_softc *);

void bshw_setup_ctrl_reg(struct bs_softc *, u_int);
int bshw_chip_reset(struct bs_softc *);
void bshw_bus_reset(struct bs_softc *);
int bshw_board_probe(struct bs_softc *, u_int *, u_int *);
void bshw_lock(struct bs_softc *);
void bshw_unlock(struct bs_softc *);
void bshw_get_syncreg(struct bs_softc *);
void bshw_issue_satcmd(struct bs_softc *, struct bsccb *, int);
void bshw_print_port(struct bs_softc *);

void bs_lc_smit_xfer(struct targ_info *, u_int);

extern struct dvcfg_hwsel bshw_hwsel;
extern u_int8_t bshw_cmd[];

/*********************************************************
 * hw
 *********************************************************/
struct bshw {
#define	BSHW_SYNC_RELOAD	0x01
#define	BSHW_SMFIFO		0x02
#define	BSHW_DOUBLE_DMACHAN	0x04
	u_int hw_flags;

	u_int sregaddr;

	int ((*dma_init)(struct bs_softc *));
	void ((*dma_start)(struct bs_softc *));
	void ((*dma_stop)(struct bs_softc *));
};

/*********************************************************
 * inline funcs.
 *********************************************************/
/*
 * XXX: If your board does not work well, Please try BS_NEEDS_WEIGHT.
 */
static BS_INLINE void
write_wd33c93(bsc, addr, data)
	struct bs_softc *bsc;
	u_int addr;
	u_int8_t data;
{

	BUS_IOW(addr_port, addr);
	BUS_IOW(ctrl_port, data);
}

static BS_INLINE u_int8_t
read_wd33c93(bsc, addr)
	struct bs_softc *bsc;
	u_int addr;
{

	BUS_IOW(addr_port, addr);
	return BUS_IOR(ctrl_port);
}

/* status */
static BS_INLINE u_int8_t
bshw_get_auxstat(bsc)
	struct bs_softc *bsc;
{

	return BUS_IOR(stat_port);
}

static BS_INLINE u_int8_t
bshw_get_busstat(bsc)
	struct bs_softc *bsc;
{

	return read_wd33c93(bsc, wd3s_stat);
}

static BS_INLINE u_int8_t
bshw_get_status_insat(bsc)
	struct bs_softc *bsc;
{

	return read_wd33c93(bsc, wd3s_lun);
}

/* data */
static BS_INLINE u_int8_t
bshw_read_data(bsc)
	struct bs_softc *bsc;
{

	return read_wd33c93(bsc, wd3s_data);
}

static BS_INLINE void
bshw_write_data(bsc, data)
	struct bs_softc *bsc;
	u_int8_t data;
{

	write_wd33c93(bsc, wd3s_data, data);
}

/* counter */
static BS_INLINE void
bshw_set_count(bsc, count)
	struct bs_softc *bsc;
	u_int count;
{

	BUS_IOW(addr_port, wd3s_cnt);
	BUS_IOW(ctrl_port, count >> 16);
	BUS_IOW(ctrl_port, count >> 8);
	BUS_IOW(ctrl_port, count);
}

static BS_INLINE u_int
bshw_get_count(bsc)
	struct bs_softc *bsc;
{
	u_int count;

	BUS_IOW(addr_port, wd3s_cnt);
	count = (((u_int) BUS_IOR(ctrl_port)) << 16);
	count += (((u_int) BUS_IOR(ctrl_port)) << 8);
	count += ((u_int) BUS_IOR(ctrl_port));
	return count;
}

/* ID */
static BS_INLINE void
bshw_set_lun(bsc, lun)
	struct bs_softc *bsc;
	u_int lun;
{

	write_wd33c93(bsc, wd3s_lun, lun);
}

static BS_INLINE void
bshw_set_dst_id(bsc, target, lun)
	struct bs_softc *bsc;
	u_int target, lun;
{

	write_wd33c93(bsc, wd3s_did, target);
	write_wd33c93(bsc, wd3s_lun, lun);
}

static BS_INLINE u_int
bshw_get_src_id(bsc)
	struct bs_softc *bsc;
{

	return (read_wd33c93(bsc, wd3s_sid) & SIDR_IDM);
}

/* phase */
static BS_INLINE void
bshw_negate_ack(bsc)
	struct bs_softc *bsc;
{

	write_wd33c93(bsc, wd3s_cmd, WD3S_NEGATE_ACK);
}

static BS_INLINE void
bshw_assert_atn(bsc)
	struct bs_softc *bsc;
{

	write_wd33c93(bsc, wd3s_cmd, WD3S_ASSERT_ATN);
}

static BS_INLINE void
bshw_assert_select(bsc)
	struct bs_softc *bsc;
{

	write_wd33c93(bsc, wd3s_cmd, WD3S_SELECT_ATN);
}

static BS_INLINE void
bshw_start_xfer(bsc)
	struct bs_softc *bsc;
{

	write_wd33c93(bsc, wd3s_cmd, WD3S_TFR_INFO);
}

static BS_INLINE void
bshw_start_sxfer(bsc)
	struct bs_softc *bsc;
{

	write_wd33c93(bsc, wd3s_cmd, WD3S_SBT | WD3S_TFR_INFO);
}

static BS_INLINE void
bshw_cmd_pass(bsc, ph)
	struct bs_softc *bsc;
	u_int ph;
{

	write_wd33c93(bsc, wd3s_cph, ph);
}

static BS_INLINE void
bshw_start_sat(bsc, flag)
	struct bs_softc *bsc;
	u_int flag;
{

	write_wd33c93(bsc, wd3s_cmd,
		      (flag ? WD3S_SELECT_ATN_TFR : WD3S_SELECT_NO_ATN_TFR));
}


static BS_INLINE void
bshw_abort_cmd(bsc)
	struct bs_softc *bsc;
{

	write_wd33c93(bsc, wd3s_cmd, WD3S_ABORT);
}

/* transfer mode */
static BS_INLINE void
bshw_set_sync_reg(bsc, val)
	struct bs_softc *bsc;
	u_int val;
{

	write_wd33c93(bsc, wd3s_synch, val);
}

static BS_INLINE void
bshw_set_poll_trans(bsc, flags)
	struct bs_softc *bsc;
	u_int flags;
{

	if (bsc->sc_flags & BSDMATRANSFER)
	{
		bsc->sc_flags &= ~BSDMATRANSFER;
		bshw_setup_ctrl_reg(bsc, flags);
	}
}

static BS_INLINE void
bshw_set_dma_trans(bsc, flags)
	struct bs_softc *bsc;
	u_int flags;
{

	if ((bsc->sc_flags & BSDMATRANSFER) == 0)
	{
		bsc->sc_flags |= BSDMATRANSFER;
		bshw_setup_ctrl_reg(bsc, flags);
	}
}
OpenPOWER on IntegriCloud