summaryrefslogtreecommitdiff
path: root/sys/arch/alpha/pci/apecs_isa.c
blob: 1d2729475dc9f05d1f77ee687b41f312eec2e206 (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
/*	$NetBSD: apecs_isa.c,v 1.4 1995/11/23 02:37:13 cgd Exp $	*/

/*
 * Copyright (c) 1995 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Chris G. Demetriou
 * 
 * Permission to use, copy, modify and distribute this software and
 * its documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 * 
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 * 
 * Carnegie Mellon requests users of this software to return to
 *
 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 *
 * any improvements or extensions that they make and grant Carnegie the
 * rights to redistribute these changes.
 */

#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/syslog.h>
#include <sys/device.h>
#include <vm/vm.h>

#include <dev/isa/isavar.h>

#include <alpha/pci/apecsreg.h>
#include <alpha/pci/apecsvar.h>

/*
 * Allocation/deallocation functions.
 */
int	apecs_pio_alloc __P((void *, isa_iooffset_t, isa_iosize_t));
int	apecs_pio_dealloc __P((void *, isa_iooffset_t, isa_iosize_t));

/*
 * Byte functions.
 */
isa_byte_t	apecs_inb __P((void *, isa_iooffset_t));
#define	apecs_insb	0					/* XXX */
void		apecs_outb __P((void *, isa_iooffset_t, isa_byte_t));
#define	apecs_outsb	0					/* XXX */

/*
 * Word functions.
 */
isa_word_t	apecs_inw __P((void *, isa_iooffset_t));
#define	apecs_insw	0					/* XXX */
void		apecs_outw __P((void *, isa_iooffset_t, isa_word_t));
#define	apecs_outsw	0					/* XXX */

/*
 * Longword functions.
 */
isa_long_t	apecs_inl __P((void *, isa_iooffset_t));
#define	apecs_insl	0					/* XXX */
void		apecs_outl __P((void *, isa_iooffset_t, isa_long_t));
#define	apecs_outsl	0					/* XXX */

__const struct pci_pio_fns apecs_pio_fns = {
	/* Allocation/deallocation functions. */
	apecs_pio_alloc,	apecs_pio_dealloc,

	/* Byte functions. */
	apecs_inb,	apecs_insb,
	apecs_outb,	apecs_outsb,

	/* Word functions. */
	apecs_inw,	apecs_insw,
	apecs_outw,	apecs_outsw,

	/* Longword functions. */
	apecs_inl,	apecs_insl,
	apecs_outl,	apecs_outsl,
};

int
apecs_pio_alloc(ipfarg, start, size)
	void *ipfarg;
	isa_iooffset_t start;
	isa_iosize_t size;
{

	/* XXX should do something */
}

int
apecs_pio_dealloc(ipfarg, start, size)
	void *ipfarg;
	isa_iooffset_t start;
	isa_iosize_t size;
{

	/* XXX should do something */
}

isa_byte_t
apecs_inb(ipfa, ioaddr)
	void *ipfa;
	isa_iooffset_t ioaddr;
{
	u_int32_t *port, val;
	isa_byte_t rval;
	int offset;

	wbflush();
	offset = ioaddr & 3;
	port = (int32_t *)phystok0seg(APECS_PCI_SIO | 0 << 3 | ioaddr << 5);
	val = *port;
	rval = ((val) >> (8 * offset)) & 0xff;
/*	rval = val & 0xff; */

	return rval;
}

void
apecs_outb(ipfa, ioaddr, val)
	void *ipfa;
	isa_iooffset_t ioaddr;
	isa_byte_t val;
{
	u_int32_t *port, nval;
	int offset;

	offset = ioaddr & 3;
	nval = val /*<< (8 * offset)*/;
	nval = val << (8 * offset);
	port = (int32_t *)phystok0seg(APECS_PCI_SIO | 0 << 3 | ioaddr << 5);

	*port = nval;
	wbflush();
}

isa_word_t
apecs_inw(ipfa, ioaddr)
	void *ipfa;
	isa_iooffset_t ioaddr;
{
	u_int32_t *port, val;
	isa_word_t rval;
	int offset;

	wbflush();
	offset = ioaddr & 3;
	port = (int32_t *)phystok0seg(APECS_PCI_SIO | 1 << 3 | ioaddr << 5);
	val = *port;
	rval = ((val) >> (8 * offset)) & 0xffff;
	rval = val & 0xffff;

panic("inw(0x%x) => 0x%x @ %p => 0x%x\n", ioaddr, val, port, rval);

	return rval;
}

void
apecs_outw(ipfa, ioaddr, val)
	void *ipfa;
	isa_iooffset_t ioaddr;
	isa_word_t val;
{
	u_int32_t *port, nval;
	int offset;

	offset = ioaddr & 3;
	nval = val /*<< (8 * offset)*/;
	port = (int32_t *)phystok0seg(APECS_PCI_SIO | 1 << 3 | ioaddr << 5);

	*port = nval;
	wbflush();
}

isa_long_t
apecs_inl(ipfa, ioaddr)
	void *ipfa;
	isa_iooffset_t ioaddr;
{
	u_int32_t *port, val;
	isa_long_t rval;
	int offset;

	wbflush();
	offset = ioaddr & 3;
	port = (int32_t *)phystok0seg(APECS_PCI_SIO | 3 << 3 | ioaddr << 5);
	val = *port;
	rval = ((val) >> (8 * offset)) & 0xffffffff;
	rval = val & 0xffffffff;

	return rval;
}

void
apecs_outl(ipfa, ioaddr, val)
	void *ipfa;
	isa_iooffset_t ioaddr;
	isa_long_t val;
{
	u_int32_t *port, nval;
	int offset;

	offset = ioaddr & 3;
	nval = val /*<< (8 * offset)*/;
	port = (int32_t *)phystok0seg(APECS_PCI_SIO | 3 << 3 | ioaddr << 5);

	*port = nval;
	wbflush();
}

/* XXX XXX XXX */

#define pf(fn, args)	fn args { panic(__STRING(fn)); }

void	pf(apecs_dma_cascade, (void *idfa, isa_drq_t chan))
void	pf(apecs_dma_copytobuf, ())
void	pf(apecs_dma_copyfrombuf, ())
void	pf(apecs_dma_start, (void *idfa, vm_offset_t addr,
	    isa_msize_t size, isa_drq_t chan, int flags))
void	pf(apecs_dma_abort, (void *idfa, isa_drq_t chan))
void	pf(apecs_dma_done, (void *idfa, isa_drq_t chan))

int	apecs_dma_map __P((void *, vm_offset_t, isa_msize_t,
	    isa_moffset_t *, int));
void	apecs_dma_unmap __P((void *, vm_offset_t, isa_msize_t, int,
	    isa_moffset_t *));

__const struct isa_dma_fns apecs_dma_fns = {
	apecs_dma_cascade,
	apecs_dma_map,
	apecs_dma_unmap,
	apecs_dma_copytobuf,
	apecs_dma_copyfrombuf,
	apecs_dma_start,
	apecs_dma_abort,
	apecs_dma_done,
};

int
apecs_dma_map(idfa, va, isasize, mappingsp, flags)
	void *idfa;
	vm_offset_t va;
	isa_msize_t isasize;
	isa_moffset_t *mappingsp;
	int flags;
{
	struct apecs_config *acp = idfa;
	long todo;
	int i;

	if (ISA_DMA_NEEDCONTIG(flags) && isasize > NBPG ||
	    ISA_DMA_SIZEBOUND(flags) != ISA_DMA_SIZEBOUND_NONE ||
	    ISA_DMA_ADDRBOUND(flags) != ISA_DMA_ADDRBOUND_NONE)
		panic("apecs_dma_map: punt");

	i = 0;
	todo = isasize;

	while (todo > 0) {
		mappingsp[i] = vtophys(va) | 0x40000000;
#if 0
		printf("a_pd_m mapping %d: %lx -> %lx -> %lx\n", i, va,
		    vtophys(va), mappingsp[i]);
#endif
		i++;
		todo -= PAGE_SIZE - (va - trunc_page(va));
		va += PAGE_SIZE - (va - trunc_page(va));
	}
	return (i);
}

void
apecs_dma_unmap(idfa, va, isasize, nmappings, mappingsp)
	void *idfa;
	vm_offset_t va;
	isa_msize_t isasize;
	int nmappings;
	isa_moffset_t *mappingsp;
{

	printf("apecs_dma_unmap: called\n");
}

vm_offset_t	apecs_mem_map __P((void *, isa_moffset_t, isa_msize_t, int));
void		apecs_mem_unmap __P((void *, vm_offset_t, isa_msize_t));

#if 0
void		apecs_mem_copytoisa __P((void *, char *, vm_offset_t,
		    isa_moffset_t, isa_msize_t));
void		apecs_mem_copyfromisa __P((void *, char *, vm_offset_t,
		    isa_moffset_t, isa_msize_t));
void		apecs_mem_zero __P((void *, vm_offset_t, isa_moffset_t,
		    isa_msize_t));
#else
void		pf(apecs_mem_copytoisa, ())
void		pf(apecs_mem_copyfromisa, ())
void		pf(apecs_mem_zero, ())
#endif

__const struct isa_mem_fns apecs_mem_fns = {
	apecs_mem_map,
	apecs_mem_unmap,
	apecs_mem_copytoisa,
	apecs_mem_copyfromisa,
	apecs_mem_zero,
};

vm_offset_t
apecs_mem_map(imfa, isapa, isasize, cacheable)
	void *imfa;
	isa_moffset_t isapa;
	isa_msize_t isasize;
	int cacheable;
{
	vm_offset_t sbpa;

	/* XXX sanity checks on sizes, use of windows, etc. */

	/* XXX MAGIC NUMBERS */
	if (cacheable)
		sbpa = (isapa & 0xffffffff) | APECS_PCI_DENSE;
	else
		sbpa = ((isapa & 0x7ffffff) << 5) | APECS_PCI_SPARSE;

	return phystok0seg(sbpa);
}

void
apecs_mem_unmap(imfa, va, isasize)
	void *imfa;
	vm_offset_t va;
	isa_msize_t isasize;
{

	/* XXX sanity checks on va */

	/* Nothing to do; mapping was done in direct-mapped segment. */
}