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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
/* $OpenBSD: creator.c,v 1.10 2002/05/22 22:02:08 fgsch Exp $ */
/*
* Copyright (c) 2002 Jason L. Wright (jason@thought.net)
* 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 Jason L. Wright
* 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.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/timeout.h>
#include <machine/bus.h>
#include <machine/autoconf.h>
#include <machine/openfirm.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/wscons/wscons_raster.h>
#include <dev/rasops/rasops.h>
/* Number of register sets */
#define FFB_NREGS 24
/* Register set numbers */
#define FFB_REG_PROM 0
#define FFB_REG_DAC 1
#define FFB_REG_FBC 2
#define FFB_REG_DFB8R 3
#define FFB_REG_DFB8G 4
#define FFB_REG_DFB8B 5
#define FFB_REG_DFB8X 6
#define FFB_REG_DFB24 7
#define FFB_REG_DFB32 8
#define FFB_REG_SFB8R 9
#define FFB_REG_SFB8G 10
#define FFB_REG_SFB8B 11
#define FFB_REG_SFB8X 12
#define FFB_REG_SFB32 13
#define FFB_REG_SFB64 14
#define FFB_REG_DFB422A 15
#define FFB_REG_DFB422AD 16
#define FFB_REG_DFB24B 17
#define FFB_REG_DFB422B 18
#define FFB_REG_DFB422BD 19
#define FFB_REG_SFB8Z 20
#define FFB_REG_SFB16Z 21
#define FFB_REG_SFB422 22
#define FFB_REG_SFB422D 23
struct wsscreen_descr creator_stdscreen = {
"std",
0, 0, /* will be filled in -- XXX shouldn't, it's global. */
0,
0, 0,
WSSCREEN_REVERSE | WSSCREEN_WSCOLORS
};
const struct wsscreen_descr *creator_scrlist[] = {
&creator_stdscreen,
/* XXX other formats? */
};
struct wsscreen_list creator_screenlist = {
sizeof(creator_scrlist) / sizeof(struct wsscreen_descr *),
creator_scrlist
};
int creator_ioctl(void *, u_long, caddr_t, int, struct proc *);
int creator_alloc_screen(void *, const struct wsscreen_descr *, void **,
int *, int *, long *);
void creator_free_screen(void *, void *);
int creator_show_screen(void *, void *, int, void (*cb)(void *, int, int),
void *);
paddr_t creator_mmap(void *, off_t, int);
static int a2int(char *, int);
struct wsdisplay_accessops creator_accessops = {
creator_ioctl,
creator_mmap,
creator_alloc_screen,
creator_free_screen,
creator_show_screen,
NULL, /* load_font */
NULL, /* scrollback */
NULL, /* getchar */
NULL, /* burner */
};
struct creator_softc {
struct device sc_dv;
bus_space_tag_t sc_bt;
bus_space_handle_t sc_pixel_h;
bus_addr_t sc_addrs[FFB_NREGS];
bus_size_t sc_sizes[FFB_NREGS];
int sc_height, sc_width, sc_linebytes, sc_depth;
int sc_nscreens, sc_nreg;
u_int sc_mode;
struct rasops_info sc_rasops;
};
int creator_match(struct device *, void *, void *);
void creator_attach(struct device *, struct device *, void *);
struct cfattach creator_ca = {
sizeof(struct creator_softc), creator_match, creator_attach
};
struct cfdriver creator_cd = {
NULL, "creator", DV_DULL
};
int
creator_match(parent, match, aux)
struct device *parent;
void *match, *aux;
{
struct mainbus_attach_args *ma = aux;
if (strcmp(ma->ma_name, "SUNW,ffb") == 0 ||
strcmp(ma->ma_name, "SUNW,afb") == 0)
return (1);
return (0);
}
void
creator_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct creator_softc *sc = (struct creator_softc *)self;
struct mainbus_attach_args *ma = aux;
struct wsemuldisplaydev_attach_args waa;
long defattr;
extern int fbnode;
int i, btype, console, nregs;
sc->sc_bt = ma->ma_bustag;
nregs = min(ma->ma_nreg, FFB_NREGS);
printf(":");
btype = getpropint(ma->ma_node, "board_type", 0);
if (strcmp(ma->ma_name, "SUNW,afb") != 0) {
if ((btype & 7) == 3)
printf(" Creator3D");
else
printf(" Creator");
} else
printf(" Elite3D");
printf(", type %d\n", btype);
if (nregs < FFB_REG_DFB32) {
printf(": no dfb32 regs found\n");
goto fail;
}
if (bus_space_map2(sc->sc_bt, 0, ma->ma_reg[FFB_REG_DFB32].ur_paddr,
ma->ma_reg[FFB_REG_DFB32].ur_len, 0, NULL, &sc->sc_pixel_h)) {
printf("%s: failed to map dfb32\n", sc->sc_dv.dv_xname);
goto fail;
}
for (i = 0; i < nregs; i++) {
sc->sc_addrs[i] = ma->ma_reg[i].ur_paddr;
sc->sc_sizes[i] = ma->ma_reg[i].ur_len;
}
sc->sc_nreg = nregs;
console = (fbnode == ma->ma_node);
sc->sc_depth = 32;
sc->sc_linebytes = 8192;
sc->sc_height = getpropint(ma->ma_node, "height", 0);
sc->sc_width = getpropint(ma->ma_node, "width", 0);
sc->sc_rasops.ri_depth = sc->sc_depth;
sc->sc_rasops.ri_stride = sc->sc_linebytes;
sc->sc_rasops.ri_flg = RI_CENTER;
sc->sc_rasops.ri_bits = (void *)bus_space_vaddr(sc->sc_bt,
sc->sc_pixel_h);
sc->sc_rasops.ri_width = sc->sc_width;
sc->sc_rasops.ri_height = sc->sc_height;
sc->sc_rasops.ri_hw = sc;
rasops_init(&sc->sc_rasops,
a2int(getpropstring(optionsnode, "screen-#rows"), 34),
a2int(getpropstring(optionsnode, "screen-#columns"), 80));
creator_stdscreen.nrows = sc->sc_rasops.ri_rows;
creator_stdscreen.ncols = sc->sc_rasops.ri_cols;
creator_stdscreen.textops = &sc->sc_rasops.ri_ops;
sc->sc_rasops.ri_ops.alloc_attr(&sc->sc_rasops, 0, 0, 0, &defattr);
if (console) {
int *ccolp, *crowp;
if (romgetcursoraddr(&crowp, &ccolp))
ccolp = crowp = NULL;
if (ccolp != NULL)
sc->sc_rasops.ri_ccol = *ccolp;
if (crowp != NULL)
sc->sc_rasops.ri_crow = *crowp;
wsdisplay_cnattach(&creator_stdscreen, &sc->sc_rasops,
sc->sc_rasops.ri_ccol, sc->sc_rasops.ri_crow, defattr);
}
waa.console = console;
waa.scrdata = &creator_screenlist;
waa.accessops = &creator_accessops;
waa.accesscookie = sc;
config_found(self, &waa, wsemuldisplaydevprint);
return;
fail:
if (sc->sc_pixel_h != 0)
bus_space_unmap(sc->sc_bt, sc->sc_pixel_h,
ma->ma_reg[FFB_REG_DFB32].ur_len);
}
int
creator_ioctl(v, cmd, data, flags, p)
void *v;
u_long cmd;
caddr_t data;
int flags;
struct proc *p;
{
struct creator_softc *sc = v;
struct wsdisplay_fbinfo *wdf;
switch (cmd) {
case WSDISPLAYIO_GTYPE:
*(u_int *)data = WSDISPLAY_TYPE_SUNFFB;
break;
case WSDISPLAYIO_SMODE:
sc->sc_mode = *(u_int *)data;
break;
case WSDISPLAYIO_GINFO:
wdf = (void *)data;
wdf->height = sc->sc_height;
wdf->width = sc->sc_width;
wdf->depth = sc->sc_depth;
wdf->cmsize = 256;/*XXX*/
break;
case WSDISPLAYIO_LINEBYTES:
*(u_int *)data = sc->sc_linebytes;
break;
case WSDISPLAYIO_GETCMAP:
break;/* XXX */
case WSDISPLAYIO_PUTCMAP:
break;/* XXX */
case WSDISPLAYIO_SVIDEO:
case WSDISPLAYIO_GVIDEO:
case WSDISPLAYIO_GCURPOS:
case WSDISPLAYIO_SCURPOS:
case WSDISPLAYIO_GCURMAX:
case WSDISPLAYIO_GCURSOR:
case WSDISPLAYIO_SCURSOR:
default:
return -1; /* not supported yet */
}
return (0);
}
int
creator_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
void *v;
const struct wsscreen_descr *type;
void **cookiep;
int *curxp, *curyp;
long *attrp;
{
struct creator_softc *sc = v;
if (sc->sc_nscreens > 0)
return (ENOMEM);
*cookiep = &sc->sc_rasops;
*curyp = 0;
*curxp = 0;
sc->sc_rasops.ri_ops.alloc_attr(&sc->sc_rasops, 0, 0, 0, attrp);
sc->sc_nscreens++;
return (0);
}
void
creator_free_screen(v, cookie)
void *v;
void *cookie;
{
struct creator_softc *sc = v;
sc->sc_nscreens--;
}
int
creator_show_screen(v, cookie, waitok, cb, cbarg)
void *v;
void *cookie;
int waitok;
void (*cb)(void *, int, int);
void *cbarg;
{
return (0);
}
paddr_t
creator_mmap(vsc, off, prot)
void *vsc;
off_t off;
int prot;
{
struct creator_softc *sc = vsc;
int i;
switch (sc->sc_mode) {
case WSDISPLAYIO_MODE_MAPPED:
for (i = 0; i < sc->sc_nreg; i++) {
/* Before this set? */
if (off < sc->sc_addrs[i])
continue;
/* After this set? */
if (off >= (sc->sc_addrs[i] + sc->sc_sizes[i]))
continue;
return (bus_space_mmap(sc->sc_bt, sc->sc_addrs[i],
off - sc->sc_addrs[i], prot, BUS_SPACE_MAP_LINEAR));
}
break;
case WSDISPLAYIO_MODE_DUMBFB:
if (sc->sc_nreg < FFB_REG_DFB24)
break;
if (off >= 0 && off < sc->sc_sizes[FFB_REG_DFB24])
return (bus_space_mmap(sc->sc_bt,
sc->sc_addrs[FFB_REG_DFB24], off, prot,
BUS_SPACE_MAP_LINEAR));
break;
}
return (-1);
}
static int
a2int(char *cp, int deflt)
{
int i = 0;
if (*cp == '\0')
return (deflt);
while (*cp != '\0')
i = i * 10 + *cp++ - '0';
return (i);
}
|