summaryrefslogtreecommitdiffstats
path: root/sys/i4b/tina-dd/i4b_tina_dd.c
blob: e210d001888f58d9eec8600e1116993f4996acd8 (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
/*
 *   Copyright (c) 1994, 1998 Hellmuth Michaelis. 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.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
 *
 *---------------------------------------------------------------------------
 *
 *	i4b_tina_dd.c - i4b Stollman Tina-dd control device driver
 *	----------------------------------------------------------
 *
 *	$Id: i4b_tina_dd.c,v 1.1 1998/12/27 21:46:53 phk Exp $
 *
 *	last edit-date: [Sat Dec  5 18:41:38 1998]
 *
 *---------------------------------------------------------------------------*/

#include "tina.h"

#if NTINA > 0

#include <sys/param.h>
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
#include <sys/ioccom.h>
#else
#include <sys/ioctl.h>
#endif
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/mbuf.h>
#include <sys/proc.h>
#include <sys/fcntl.h>
#include <sys/socket.h>
#include <net/if.h>

#ifdef __FreeBSD__
#include <machine/i4b_debug.h>
#include <machine/i4b_ioctl.h>
#include <i386/isa/isa_device.h>
#else
#include <machine/bus.h>
#include <sys/device.h>
#include <i4b/i4b_debug.h>
#include <i4b/i4b_ioctl.h>
#endif

#include <i4b/include/i4b_mbuf.h>
#include <i4b/tina-dd/i4b_tina_ioctl.h>

static int openflag = 0;

int tinaprobe(struct isa_device *dev);
int tinaattach(struct isa_device *dev);
void tinaintr(int unit);

struct isa_driver tinadriver = {
	tinaprobe,
	tinaattach,
	"tina",
	0
};

static struct tina_softc {
	int sc_unit;
	int sc_iobase;
} tina_sc[NTINA];

static	d_open_t	tinaopen;
static	d_close_t	tinaclose;
static	d_ioctl_t	tinaioctl;
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
static d_poll_t		tinapoll;
#endif

#define CDEV_MAJOR 54
static struct cdevsw tina_cdevsw = 
	{ tinaopen,	tinaclose,	noread,		nowrite,
	  tinaioctl,	nostop,		nullreset,	nodevtotty,
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
	  tinapoll,	nommap,		NULL,	"tina", NULL,	-1 };
#else
	  noselect,	nommap,		NULL,	"tina", NULL,	-1 };
#endif

static void setupaddr(unsigned short iobase, unsigned int addr);
static void readblock(unsigned short iobase, unsigned int addr,
	  unsigned char *dst, unsigned int len);
static void writeblock(unsigned short iobase, unsigned char *src,
	  unsigned long addr, int len);

/*---------------------------------------------------------------------------*
 *	tina - device driver probe routine
 *---------------------------------------------------------------------------*/
int
tinaprobe(struct isa_device *dev)
{
	u_char byte;
	
#define SETLOW	0x55
#define SETMID	0xaa
#define SETHIGH 0x06

	outb((dev->id_iobase + ADDR_CNTL), SETLOW);

	if((byte = inb(dev->id_iobase + ADDR_CNTL)) != SETLOW)
	{
		printf("tina%d: probe low failed, 0x%x != 0x%x\n",
			dev->id_unit, byte, SETLOW);		
		return(0);
	}
	
	outb((dev->id_iobase + ADDR_CNTM), SETMID);
	if((byte = inb(dev->id_iobase + ADDR_CNTM)) != SETMID)
	{
		printf("tina%d: probe mid failed, 0x%x != 0x%x\n",
			dev->id_unit, byte, SETMID);		
		return(0);
	}
	
	outb((dev->id_iobase + ADDR_CNTH), SETHIGH);
	if(((byte = inb(dev->id_iobase + ADDR_CNTH)) & 0x0f) != SETHIGH)
	{
		printf("tina%d: probe high failed, 0x%x != 0x%x\n",
			dev->id_unit, byte, SETHIGH);		
		return(0);
	}

	printf("tina%d: status register = 0x%x\n",
			dev->id_unit, inb(dev->id_iobase + CTRL_STAT));
	
	return(1);			/* board found */
}
#undef SETLOW
#undef SETMID
#undef SETHIGH

/*---------------------------------------------------------------------------*
 *	tina - device driver attach routine
 *---------------------------------------------------------------------------*/
int
tinaattach(struct isa_device *dev)
{
	struct tina_softc *sc = &tina_sc[dev->id_unit];

	sc->sc_unit = dev->id_unit;
	sc->sc_iobase = dev->id_iobase;	

	printf("tina%d: attaching Tina-dd\n", dev->id_unit);

	return(1);
}

/*---------------------------------------------------------------------------*
 *	tina - device driver interrupt routine
 *---------------------------------------------------------------------------*/
void
tinaintr(int unit)
{
}

#if BSD > 199306 && defined(__FreeBSD__)
/*---------------------------------------------------------------------------*
 *	initialization at kernel load time
 *---------------------------------------------------------------------------*/
static void
tinainit(void *unused)
{
    dev_t dev;
    
    dev = makedev(CDEV_MAJOR, 0);

    cdevsw_add(&dev, &tina_cdevsw, NULL);
}

SYSINIT(tinadev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &tinainit, NULL);

#endif /* BSD > 199306 && defined(__FreeBSD__) */

/*---------------------------------------------------------------------------*
 *	tinaopen - device driver open routine
 *---------------------------------------------------------------------------*/
static int
tinaopen(dev_t dev, int flag, int fmt, struct proc *p)
{
	if(minor(dev))
		return (ENXIO);

	if(openflag)
		return (EBUSY);
	
	openflag = 1;
	
	return(0);
}

/*---------------------------------------------------------------------------*
 *	tinaclose - device driver close routine
 *---------------------------------------------------------------------------*/
static int
tinaclose(dev_t dev, int flag, int fmt, struct proc *p)
{
	openflag = 0;
	return(0);
}

/*---------------------------------------------------------------------------*
 *	tinaioctl - device driver ioctl routine
 *---------------------------------------------------------------------------*/
static int
tinaioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
{
	struct tina_softc *sc = &tina_sc[minor(dev)];
	u_short iobase = sc->sc_iobase;
	int error = 0;
	int s;

	if(minor(dev))
		return(ENODEV);

	s = splimp();
	
	switch(cmd)
	{
		/* hardware layer - control & status register */

		case ISDN_GETCSR:	/* return control register */
			*(unsigned char *)data = inb(iobase + CTRL_STAT);
			break;
			
		case ISDN_SETCSR:	/* set status register */
			outb((iobase + CTRL_STAT), *(unsigned char *)data);
			break;
			
		/* hardware layer - dual ported memory */
		
		case ISDN_GETBLK:	/* get block from dual port mem */
			readblock(iobase, (*(struct record *)data).addr,
					  (*(struct record *)data).data,
					  (*(struct record *)data).length);
			break;

		case ISDN_SETBLK:	/* write block to dual port mem */
			writeblock(iobase, (*(struct record *)data).data,
					   (*(struct record *)data).addr,
					   (*(struct record *)data).length);
			break;

		default:
			error = ENOTTY;
			break;
	}
	return(error);
}

/*---------------------------------------------------------------------------*
 *	tinapoll - device driver poll routine
 *---------------------------------------------------------------------------*/
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
static int
tinapoll (dev_t dev, int events, struct proc *p)
{
	return (ENODEV);
}
#endif

/*===========================================================================*
 *	tina dual ported memory access
 *===========================================================================*/
 
/*---------------------------------------------------------------------------*
 *	setup address for accessing tina-dd ram
 *---------------------------------------------------------------------------*/
static void
setupaddr(unsigned short iobase, unsigned int addr)
{
	outb((iobase + ADDR_CNTL), (unsigned char) addr & 0xff);
	outb((iobase + ADDR_CNTM), (unsigned char) ((addr >> 8) & 0xff));
	outb((iobase + ADDR_CNTH), (unsigned char) ((addr >> 16) & 0xff));
}


/*---------------------------------------------------------------------------*
 *	read block from tina-dd dual ported ram
 *---------------------------------------------------------------------------*/
static void
readblock(unsigned short iobase, unsigned int addr,
	  unsigned char *dst, unsigned int len)
{
	setupaddr(iobase, addr);	/* setup start address */

	while(len--)			/* tina-dd mem -> pc mem */
		*dst++ = inb(iobase + DATA_LOW_INC);
}

/*---------------------------------------------------------------------------*
 *	write block to tina-dd dual ported ram
 *---------------------------------------------------------------------------*/
static void
writeblock(unsigned short iobase, unsigned char *src,
	  unsigned long addr, int len)
{
	setupaddr(iobase, addr);	/* setup start address */

	while(len--)			/* pc mem -> tina-dd mem */
		outb((iobase + DATA_LOW_INC), *src++);
}

#endif /* NTINA > 0 */
OpenPOWER on IntegriCloud