summaryrefslogtreecommitdiff
path: root/sys/arch/mac68k/dev/grf_iv.c
blob: 2edfac852be206fbdfd2af846a9b69336f992151 (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
/*	$OpenBSD: grf_iv.c,v 1.13 1997/03/29 03:16:18 briggs Exp $	*/
/*	$NetBSD: grf_iv.c,v 1.17 1997/02/20 00:23:27 scottr Exp $	*/

/*
 * Copyright (c) 1995 Allen Briggs.  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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Allen Briggs.
 * 4. 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.
 */
/*
 * Graphics display driver for the Macintosh internal video for machines
 * that don't map it into a fake nubus card.
 */

#include <sys/param.h>

#include <sys/device.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/proc.h>
#include <sys/systm.h>

#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/macinfo.h>
#include <machine/grfioctl.h>
#include <machine/viareg.h>

#include "nubus.h"
#include "obiovar.h"
#include "grfvar.h"

extern u_int32_t	mac68k_vidlog;
extern u_int32_t	mac68k_vidphys;
extern long		videorowbytes;
extern long		videobitdepth;
extern unsigned long	videosize;

static int	grfiv_mode __P((struct grf_softc *gp, int cmd, void *arg));
static caddr_t	grfiv_phys __P((struct grf_softc *gp, vm_offset_t addr));
static int	grfiv_match __P((struct device *, void *, void *));
static void	grfiv_attach __P((struct device *, struct device *, void *));

struct cfdriver intvid_cd = {
	NULL, "intvid", DV_DULL
};

struct cfattach intvid_ca = {
	sizeof(struct grfbus_softc), grfiv_match, grfiv_attach
};

/* XXX -- kludge */
#include <vm/vm.h>
#include <vm/vm_kern.h>
#include <vm/vm_map.h>

#define QUADRA_DAFB_BASE	0xF9800000

static int
grfiv_match(parent, vcf, aux)
	struct device *parent;
	void *vcf;
	void *aux;
{
	struct obio_attach_args *oa = (struct obio_attach_args *) aux;
	bus_space_handle_t	bsh;
	int			found, sense;

	found = 1;

        switch (current_mac_model->class) {
        case MACH_CLASSQ:
        case MACH_CLASSQ2:

		/* Assume DAFB for all of these */

		if (bus_space_map(oa->oa_tag, QUADRA_DAFB_BASE, 0x1000,
					0, &bsh)) {
			panic("failed to map space for DAFB regs.\n");
		}

		sense = (bus_space_read_4(oa->oa_tag, bsh, 0x1C) & 7);

		if (sense == 0)
			found = 0;

		/* Set "Turbo SCSI" configuration to default */
		bus_space_write_4(oa->oa_tag, bsh, 0x24, 0x1d1); /* ch0 */
		bus_space_write_4(oa->oa_tag, bsh, 0x28, 0x1d1); /* ch1 */

		/* Disable interrupts */
		bus_space_write_4(oa->oa_tag, bsh, 0x104, 0);

		/* Clear any interrupts */
		bus_space_write_4(oa->oa_tag, bsh, 0x10C, 0);
		bus_space_write_4(oa->oa_tag, bsh, 0x110, 0);
		bus_space_write_4(oa->oa_tag, bsh, 0x114, 0);

		bus_space_unmap(oa->oa_tag, bsh, 0x1000);

		break;

	default:
		if (mac68k_vidlog == 0) {
			found = 0;
		}

		break;
	}

	return found;
}

#define R4(sc, o) (bus_space_read_4((sc)->sc_tag, (sc)->sc_regh, o) & 0xfff)

static void
grfiv_attach(parent, self, aux)
	struct device *parent, *self;
	void   *aux;
{
	struct obio_attach_args *oa = (struct obio_attach_args *) aux;
	struct grfbus_softc	*sc;
	struct grfmode		*gm;

	sc = (struct grfbus_softc *) self;

	sc->card_id = 0;

        switch (current_mac_model->class) {
        case MACH_CLASSQ:
        case MACH_CLASSQ2:
		sc->sc_tag = oa->oa_tag;
		if (bus_space_map(sc->sc_tag, QUADRA_DAFB_BASE, 0x1000,
					0, &sc->sc_regh)) {
			panic("failed to map space for DAFB regs.\n");
		}
		/* Show off a bit -- no need to really set these. */
		printf(": DAFB: Monitor sense %x.\n", R4(sc,0x1C)&7);
		break;
	default:
		printf(": Internal Video\n");
		break;
	}

	gm = &(sc->curr_mode);
	gm->mode_id = 0;
	gm->psize = videobitdepth;
	gm->ptype = 0;
	gm->width = videosize & 0xffff;
	gm->height = (videosize >> 16) & 0xffff;
	gm->rowbytes = videorowbytes;
	gm->hres = 80;		/* XXX Hack */
	gm->vres = 80;		/* XXX Hack */
	gm->fbsize = gm->rowbytes * gm->height;
	gm->fbbase = (caddr_t) mac68k_trunc_page(mac68k_vidlog);
	gm->fboff = mac68k_vidlog & PGOFSET;

	/* Perform common video attachment. */
	grf_establish(sc, NULL, grfiv_mode, grfiv_phys);
}

static int
grfiv_mode(sc, cmd, arg)
	struct grf_softc *sc;
	int cmd;
	void *arg;
{
	switch (cmd) {
	case GM_GRFON:
	case GM_GRFOFF:
		return 0;
	case GM_CURRMODE:
		break;
	case GM_NEWMODE:
		break;
	case GM_LISTMODES:
		break;
	}
	return EINVAL;
}

static caddr_t
grfiv_phys(gp, addr)
	struct grf_softc *gp;
	vm_offset_t addr;
{
	/*
	 * If we're using IIsi or similar, this will be 0.
	 * If we're using IIvx or similar, this will be correct.
	 */
	return (caddr_t) mac68k_vidphys;
}