summaryrefslogtreecommitdiff
path: root/sys/arch/alpha/pci/pcivga.c
blob: 5f62ab3fa73af00a426768f2d27b965046085414 (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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/*	$NetBSD: pcivga.c,v 1.4 1995/12/24 02:29:47 mycroft 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/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/malloc.h>

#include <machine/autoconf.h>
#include <machine/pte.h>

#include <dev/pseudo/ansicons.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>

#include <alpha/pci/pcivgavar.h>
#include <alpha/pci/wsconsvar.h>

int	pcivgamatch __P((struct device *, void *, void *));
void	pcivgaattach __P((struct device *, struct device *, void *));

struct cfdriver pcivgacd = {
	NULL, "pcivga", pcivgamatch, pcivgaattach, DV_DULL,
	    sizeof(struct pcivga_softc)
};

void	pcivga_getdevconfig __P((__const struct pci_conf_fns *, void *,
	    __const struct pci_mem_fns *, void *,
	    __const struct pci_pio_fns *, void *,
	    pci_conftag_t tag, struct pcivga_devconfig *dc));

struct pcivga_devconfig pcivga_console_dc;

void	pcivga_cursor __P((void *, int, int));
void	pcivga_putstr __P((void *, int, int, char *, int));
void	pcivga_copycols __P((void *, int, int, int,int));
void	pcivga_erasecols __P((void *, int, int, int));
void	pcivga_copyrows __P((void *, int, int, int));
void	pcivga_eraserows __P((void *, int, int));
void	pcivga_bell __P((void *));			/* XXX */

struct ansicons_functions pcivga_acf = {
	pcivga_bell,
	pcivga_cursor,
	pcivga_putstr,
	pcivga_copycols,
	pcivga_erasecols,
	pcivga_copyrows,
	pcivga_eraserows,
};

#define	PCIVGAUNIT(dev)	minor(dev)

int
pcivgamatch(parent, match, aux)
	struct device *parent;
	void *match, *aux;
{
	struct cfdata *cf = match;
	struct pcidev_attach_args *pda = aux;

	/*
	 * If it's prehistoric/vga or display/vga, we match.
	 */
	if (PCI_CLASS(pda->pda_class) == PCI_CLASS_PREHISTORIC &&
	    PCI_SUBCLASS(pda->pda_class) == PCI_SUBCLASS_PREHISTORIC_VGA)
		return (1);
	if (PCI_CLASS(pda->pda_class) == PCI_CLASS_DISPLAY &&
	     PCI_SUBCLASS(pda->pda_class) == PCI_SUBCLASS_DISPLAY_VGA)
		return (1);

	return (0);
}

void
pcivga_getdevconfig(pcf, pcfa, pmf, pmfa, ppf, ppfa, tag, dc)
	__const struct pci_conf_fns *pcf;
	__const struct pci_mem_fns *pmf;
	__const struct pci_pio_fns *ppf;
	void *pcfa, *pmfa, *ppfa;
	pci_conftag_t tag;
	struct pcivga_devconfig *dc;
{

	dc->dc_pcf = pcf;
	dc->dc_pcfa = pcfa;
	dc->dc_pmf = pmf;
	dc->dc_pmfa = pmfa;
	dc->dc_ppf = ppf;
	dc->dc_ppfa = ppfa;
	dc->dc_pcitag = tag;

	/* XXX deal with mapping foo */

	/* XXX */
	dc->dc_crtat = (u_short *)PCI_MEM_MAP(pmf, pmfa, 0xb8000, 0x8000, 1);
	dc->dc_iobase = 0x3d4;			/* XXX */

	dc->dc_nrow = 25;
	dc->dc_ncol = 80;
	dc->dc_ccol = dc->dc_crow = 0;

	dc->dc_so = 0;
	dc->dc_at = 0x00 | 0xf;		  /* black bg | white fg */
	dc->dc_so_at = 0x00 | 0xf | 0x80; /* black bg | white fg | blink */

	/* clear screen, frob cursor, etc.? */
	pcivga_eraserows(dc, 0, dc->dc_nrow);
}

void
pcivgaattach(parent, self, aux)
	struct device *parent, *self;
	void *aux;
{
	struct pcidev_attach_args *pda = aux;
	struct pcivga_softc *sc = (struct pcivga_softc *)self;
	char devinfo[256];
	int console;

	console = (pda->pda_tag == pcivga_console_dc.dc_pcitag);
	if (console)
		sc->sc_dc = &pcivga_console_dc;
	else {
		sc->sc_dc = (struct pcivga_devconfig *)
		    malloc(sizeof(struct pcivga_devconfig), M_DEVBUF, M_WAITOK);
		pcivga_getdevconfig(pda->pda_conffns, pda->pda_confarg,
		    pda->pda_memfns, pda->pda_memarg, pda->pda_piofns,
		    pda->pda_memarg, pda->pda_tag, sc->sc_dc);
	}
	if (sc->sc_dc->dc_crtat == NULL) {
		printf(": couldn't map memory space; punt!\n");
		return;
	}

	pci_devinfo(pda->pda_id, pda->pda_class, 0, devinfo);
	printf(": %s (rev. 0x%02x)\n", devinfo,
	    PCI_REVISION(pda->pda_class));

#if 0
	if (sc->sc_dc->dc_tgaconf == NULL) {
		printf("unknown board configuration\n");
		return;
	}
	printf("board type %s\n", sc->sc_dc->dc_tgaconf->tgac_name);
	printf("%s: %d x %d, %dbpp, %s RAMDAC\n", sc->sc_dev.dv_xname,
	    sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
	    sc->sc_dc->dc_tgaconf->tgac_phys_depth, 
	    sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_name);
#endif

#if 0
	pci_intrdata = pci_conf_read(sc->sc_pcitag, PCI_INTERRUPT_REG);
	if (PCI_INTERRUPT_PIN(pci_intrdata) != PCI_INTERRUPT_PIN_NONE) {
		sc->sc_intr = pci_map_int(sc->sc_pcitag, IPL_TTY, tgaintr, sc,
					  sc->sc_dev.dv_xname);
		if (sc->sc_intr == NULL)
			printf("%s: WARNING: couldn't map interrupt\n",
			    sc->sc_dev.dv_xname);
	}
#endif

	if (!wscattach_output(self, console, &sc->sc_dc->dc_ansicons,
	    &pcivga_acf, sc->sc_dc, sc->sc_dc->dc_nrow, sc->sc_dc->dc_ncol,
	    0, 0)) {
		panic("pcivgaattach: wscattach failed");
		/* NOTREACHED */
	}
}

#if 0
int
tgammap(dev, offset, nprot)
	dev_t dev;
	int offset;
	int nprot;
{
	struct pcivga_softc *sc = pcivgacd.cd_devs[TGAUNIT(dev)];

	if (offset > sc->sc_dc->dc_pcivgaconf->pcivgac_cspace_size)
		return -1;
	return alpha_btop(sc->sc_dc->dc_paddr + offset);
}
#endif

void
pcivga_console(pcf, pcfa, pmf, pmfa, ppf, ppfa, bus, device, function)
	__const struct pci_conf_fns *pcf;
	__const struct pci_mem_fns *pmf;
	__const struct pci_pio_fns *ppf;
	void *pcfa, *pmfa, *ppfa;
	pci_bus_t bus;
	pci_device_t device;
	pci_function_t function;
{
	struct pcivga_devconfig *dcp = &pcivga_console_dc;

	pcivga_getdevconfig(pcf, pcfa, pmf, pmfa, ppf, ppfa,
	    PCI_MAKE_TAG(bus, device, function), dcp);

	/* sanity checks */
	if (dcp->dc_crtat == NULL)
		panic("pcivga_console(%d, %d): couldn't map memory space",
		    device, function);
#if 0
	if (dcp->dc_pcivgaconf == NULL)
		panic("pcivga_console(%d, %d): unknown board configuration",
		    device, function);
#endif

	wsc_console(&dcp->dc_ansicons, &pcivga_acf, dcp,
	    dcp->dc_nrow, dcp->dc_ncol, 0, 0);
}

/*
 * The following functions implement the MI ANSI terminal emulation on
 * a VGA display.
 */
void							/* XXX */
pcivga_bell(id)						/* XXX */
	void *id;					/* XXX */
{							/* XXX */
							/* XXX */
	printf("pcivga_bell: unimplemented\n");		/* XXX */
}							/* XXX */

void
pcivga_cursor(id, row, col)
	void *id;
	int row, col;
{
	struct pcivga_devconfig *dc = id;
	int pos;

#if 0
	printf("pcivga_cursor: %d %d\n", row, col);
#endif
        /* turn the cursor off */
        if (row == -1 || col == -1) {
		dc->dc_crow = dc->dc_ccol = PCIVGA_CURSOR_OFF;

		/* XXX disable cursor??? */
        } else {
		dc->dc_crow = row;
		dc->dc_ccol = col;
        }

	pos = row * dc->dc_ncol + col;

	OUTB(dc->dc_ppf, dc->dc_ppfa, dc->dc_iobase, 14);
	OUTB(dc->dc_ppf, dc->dc_ppfa, dc->dc_iobase+1, pos >> 8);
	OUTB(dc->dc_ppf, dc->dc_ppfa, dc->dc_iobase, 15);
	OUTB(dc->dc_ppf, dc->dc_ppfa, dc->dc_iobase+1, pos);
}

void
pcivga_putstr(id, row, col, cp, len)
	void *id;
	int row, col;
	char *cp;
	int len;
{
	struct pcivga_devconfig *dc = id;
	char *dcp;
	int i;

	for (i = 0; i < len; i++, cp++) {
		dcp = (char *)&dc->dc_crtat[row * dc->dc_ncol + col];
#if 0
printf("*cp = %c, attr = 0x%x\n", *cp, dc->dc_so ? dc->dc_so_at : dc->dc_at);
printf("was: %c/", *dcp);
#endif
		*dcp++ = *cp;
#if 0
printf("0x%x\n", *dcp);
#endif
		*dcp++ = dc->dc_so ? dc->dc_so_at : dc->dc_at;
	}
}

void
pcivga_copycols(id, row, srccol, dstcol, ncols)
	void *id;
	int row, srccol, dstcol, ncols;
{
	struct pcivga_devconfig *dc = id;
	u_short *ssp, *dsp;
	int nclr;

#if 0
	printf("pcivga_copycols: row %d: %d, %d -> %d\n", row, srccol, ncols,
	    dstcol);
#endif
	ssp = &dc->dc_crtat[row * dc->dc_ncol + srccol];
	dsp = &dc->dc_crtat[row * dc->dc_ncol + dstcol];
	bcopy(ssp, dsp, ncols * sizeof(u_short));
}

void
pcivga_erasecols(id, row, startcol, ncols)
	void *id;
	int row, startcol, ncols;
{
	struct pcivga_devconfig *dc = id;
	u_short *ssp;
	int i;

#if 0
	printf("pcivga_erasecols: row %d: %d, %d\n", row, startcol, ncols);
#endif
	ssp = &dc->dc_crtat[row * dc->dc_ncol + startcol];
	for (i = 0; i < ncols; i++)
		*ssp++ = (dc->dc_at << 8) | ' ';
}

void
pcivga_copyrows(id, srcrow, dstrow, nrows)
	void *id;
	int srcrow, dstrow, nrows;
{
	struct pcivga_devconfig *dc = id;
	u_short *ssp, *dsp;
	int nclr;

#if 0
	printf("pcivga_copyrows: %d, %d -> %d\n", srcrow, nrows, dstrow);
#endif
	ssp = &dc->dc_crtat[srcrow * dc->dc_ncol + 0];
	dsp = &dc->dc_crtat[dstrow * dc->dc_ncol + 0];
	bcopy(ssp, dsp, nrows * dc->dc_ncol * sizeof(u_short));
}

void
pcivga_eraserows(id, startrow, nrows)
	void *id;
	int startrow, nrows;
{
	struct pcivga_devconfig *dc = id;
	u_short *ssp;
	int i;

#if 0
	printf("pcivga_eraserows: %d, %d\n", startrow, nrows);
#endif
	ssp = &dc->dc_crtat[startrow * dc->dc_ncol + 0];
	for (i = 0; i < nrows * dc->dc_ncol; i++)
		*ssp++ = (dc->dc_at << 8) | ' ';
}