This source file includes following definitions.
- agtenmatch
- agtenattach
- agten_ioctl
- agten_mmap
- agten_setcolor
- agten_alloc_screen
- agten_free_screen
- agten_show_screen
- agten_getcmap
- agten_putcmap
- ibm561_write
- agten_loadcmap
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 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/buf.h>
61 #include <sys/device.h>
62 #include <sys/ioctl.h>
63 #include <sys/malloc.h>
64 #include <sys/mman.h>
65 #include <sys/tty.h>
66 #include <sys/conf.h>
67
68 #include <uvm/uvm_extern.h>
69
70 #include <machine/autoconf.h>
71 #include <machine/pmap.h>
72 #include <machine/cpu.h>
73 #include <machine/conf.h>
74
75 #include <dev/wscons/wsconsio.h>
76 #include <dev/wscons/wsdisplayvar.h>
77 #include <dev/rasops/rasops.h>
78 #include <machine/fbvar.h>
79
80 #include <dev/ic/p9000.h>
81 #include <dev/ic/ibm561reg.h>
82
83 #include <dev/sbus/sbusvar.h>
84
85 struct agten_cmap {
86 u_int8_t cm_red[256];
87 u_int8_t cm_green[256];
88 u_int8_t cm_blue[256];
89 };
90
91
92 struct agten_softc {
93 struct sunfb sc_sunfb;
94
95 bus_space_tag_t sc_bustag;
96 bus_addr_t sc_paddr;
97 off_t sc_physoffset;
98
99 volatile u_int8_t *sc_p9100;
100 struct agten_cmap sc_cmap;
101
102 volatile u_int32_t *sc_i128_fb;
103
104 int sc_nscreens;
105 };
106
107 int agten_ioctl(void *, u_long, caddr_t, int, struct proc *);
108 int agten_alloc_screen(void *, const struct wsscreen_descr *, void **,
109 int *, int *, long *);
110 void agten_free_screen(void *, void *);
111 int agten_show_screen(void *, void *, int, void (*cb)(void *, int, int),
112 void *);
113 paddr_t agten_mmap(void *, off_t, int);
114 void agten_reset(struct agten_softc *);
115 void agten_setcolor(void *, u_int, u_int8_t, u_int8_t, u_int8_t);
116
117 static __inline__ void ibm561_write(struct agten_softc *, u_int32_t, u_int32_t);
118 int agten_getcmap(struct agten_cmap *, struct wsdisplay_cmap *);
119 int agten_putcmap(struct agten_cmap *, struct wsdisplay_cmap *);
120 void agten_loadcmap(struct agten_softc *, u_int, u_int);
121
122 struct wsdisplay_accessops agten_accessops = {
123 agten_ioctl,
124 agten_mmap,
125 agten_alloc_screen,
126 agten_free_screen,
127 agten_show_screen,
128 NULL,
129 NULL,
130 NULL,
131 NULL,
132 };
133
134 int agtenmatch(struct device *, void *, void *);
135 void agtenattach(struct device *, struct device *, void *);
136
137 struct cfattach agten_ca = {
138 sizeof(struct agten_softc), agtenmatch, agtenattach
139 };
140
141 struct cfdriver agten_cd = {
142 NULL, "agten", DV_DULL
143 };
144
145 int
146 agtenmatch(struct device *parent, void *vcf, void *aux)
147 {
148 struct sbus_attach_args *sa = aux;
149
150 if (strcmp(sa->sa_name, "PFU,aga") != 0)
151 return (0);
152
153 return (1);
154 }
155
156 void
157 agtenattach(struct device *parent, struct device *self, void *args)
158 {
159 struct agten_softc *sc = (struct agten_softc *)self;
160 struct sbus_attach_args *sa = args;
161 bus_space_tag_t bt;
162 bus_space_handle_t bh;
163 int node, isconsole;
164 char *nam;
165
166 bt = sa->sa_bustag;
167 node = sa->sa_node;
168 nam = getpropstring(node, "model");
169 printf(": model %s", nam);
170
171 isconsole = node == fbnode;
172
173
174
175
176
177 sc->sc_bustag = bt;
178 sc->sc_paddr = sbus_bus_addr(bt, sa->sa_slot, sa->sa_offset);
179
180 sc->sc_physoffset =
181 (off_t)getpropint(node, "i128_fb_physaddr", 0x8000000);
182
183 if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset + sc->sc_physoffset,
184 getpropint(node, "i128_fb_size", 0x400000), BUS_SPACE_MAP_LINEAR,
185 0, &bh) != 0) {
186 printf("\n%s: couldn't map video memory\n", self->dv_xname);
187 return;
188 }
189 sc->sc_i128_fb = bus_space_vaddr(bt, bh);
190 if (sbus_bus_map(bt, sa->sa_slot, sa->sa_offset +
191 getpropint(node, "p9100_reg_physaddr", 0x10a0000), 0x4000,
192 BUS_SPACE_MAP_LINEAR, 0, &bh) != 0) {
193 printf("\n%s: couldn't map control registers\n", self->dv_xname);
194 return;
195 }
196 sc->sc_p9100 = bus_space_vaddr(bt, bh);
197
198
199
200
201
202
203
204
205
206 #ifdef notyet
207 sc->sc_sunfb.sf_depth = 32;
208 #else
209 sc->sc_sunfb.sf_depth = getpropint(node, "ffb_depth", 8);
210 #endif
211 sc->sc_sunfb.sf_width = getpropint(node, "ffb_width", 1152);
212 sc->sc_sunfb.sf_height = getpropint(node, "ffb_height", 900);
213 sc->sc_sunfb.sf_linebytes =
214 roundup(sc->sc_sunfb.sf_width, sc->sc_sunfb.sf_depth) *
215 sc->sc_sunfb.sf_depth / 8;
216 sc->sc_sunfb.sf_fbsize =
217 sc->sc_sunfb.sf_height * sc->sc_sunfb.sf_linebytes;
218
219 printf(", %dx%d, depth %d\n",
220 sc->sc_sunfb.sf_width, sc->sc_sunfb.sf_height,
221 sc->sc_sunfb.sf_depth);
222
223 sc->sc_sunfb.sf_ro.ri_bits = (void *)sc->sc_i128_fb;
224
225 sc->sc_sunfb.sf_ro.ri_hw = sc;
226 fbwscons_init(&sc->sc_sunfb, isconsole ? 0 : RI_CLEAR);
227 fbwscons_setcolormap(&sc->sc_sunfb, agten_setcolor);
228
229 if (isconsole) {
230 fbwscons_console_init(&sc->sc_sunfb, -1);
231 }
232
233 fbwscons_attach(&sc->sc_sunfb, &agten_accessops, isconsole);
234 }
235
236 int
237 agten_ioctl(dev, cmd, data, flags, p)
238 void *dev;
239 u_long cmd;
240 caddr_t data;
241 int flags;
242 struct proc *p;
243 {
244 struct agten_softc *sc = dev;
245 struct wsdisplay_cmap *cm;
246 struct wsdisplay_fbinfo *wdf;
247 int error;
248
249 switch (cmd) {
250 case WSDISPLAYIO_GTYPE:
251 *(u_int *)data = WSDISPLAY_TYPE_SUN24;
252 break;
253 case WSDISPLAYIO_GINFO:
254 wdf = (struct wsdisplay_fbinfo *)data;
255 wdf->height = sc->sc_sunfb.sf_height;
256 wdf->width = sc->sc_sunfb.sf_width;
257 wdf->depth = sc->sc_sunfb.sf_depth;
258 wdf->cmsize = (sc->sc_sunfb.sf_depth == 8) ? 256 : 0;
259 break;
260 case WSDISPLAYIO_LINEBYTES:
261 *(u_int *)data = sc->sc_sunfb.sf_linebytes;
262 break;
263
264 case WSDISPLAYIO_GETCMAP:
265 if (sc->sc_sunfb.sf_depth == 8) {
266 cm = (struct wsdisplay_cmap *)data;
267 error = agten_getcmap(&sc->sc_cmap, cm);
268 if (error)
269 return (error);
270 }
271 break;
272 case WSDISPLAYIO_PUTCMAP:
273 if (sc->sc_sunfb.sf_depth == 8) {
274 cm = (struct wsdisplay_cmap *)data;
275 error = agten_putcmap(&sc->sc_cmap, cm);
276 if (error)
277 return (error);
278 agten_loadcmap(sc, 0, 256);
279 }
280 break;
281
282 case WSDISPLAYIO_SVIDEO:
283 case WSDISPLAYIO_GVIDEO:
284 break;
285
286 case WSDISPLAYIO_GCURPOS:
287 case WSDISPLAYIO_SCURPOS:
288 case WSDISPLAYIO_GCURMAX:
289 case WSDISPLAYIO_GCURSOR:
290 case WSDISPLAYIO_SCURSOR:
291 default:
292 return (-1);
293 }
294
295 return (0);
296 }
297
298
299
300
301
302 paddr_t
303 agten_mmap(v, offset, prot)
304 void *v;
305 off_t offset;
306 int prot;
307 {
308 struct agten_softc *sc = v;
309
310 if (offset & PGOFSET)
311 return (-1);
312
313
314 if (offset >= 0 && offset < sc->sc_sunfb.sf_fbsize) {
315 return (bus_space_mmap(sc->sc_bustag, sc->sc_paddr,
316 sc->sc_physoffset + offset, prot, BUS_SPACE_MAP_LINEAR));
317 }
318
319 return (-1);
320 }
321
322 void
323 agten_setcolor(v, index, r, g, b)
324 void *v;
325 u_int index;
326 u_int8_t r, g, b;
327 {
328 struct agten_softc *sc = v;
329
330 sc->sc_cmap.cm_red[index] = r;
331 sc->sc_cmap.cm_green[index] = g;
332 sc->sc_cmap.cm_blue[index] = b;
333
334 agten_loadcmap(sc, index, 1);
335 }
336
337 int
338 agten_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
339 void *v;
340 const struct wsscreen_descr *type;
341 void **cookiep;
342 int *curxp, *curyp;
343 long *attrp;
344 {
345 struct agten_softc *sc = v;
346
347 if (sc->sc_nscreens > 0)
348 return (ENOMEM);
349
350 *cookiep = &sc->sc_sunfb.sf_ro;
351 *curyp = 0;
352 *curxp = 0;
353 sc->sc_sunfb.sf_ro.ri_ops.alloc_attr(&sc->sc_sunfb.sf_ro,
354 WSCOL_BLACK, WSCOL_WHITE, WSATTR_WSCOLORS, attrp);
355 sc->sc_nscreens++;
356 return (0);
357 }
358
359 void
360 agten_free_screen(v, cookie)
361 void *v;
362 void *cookie;
363 {
364 struct agten_softc *sc = v;
365
366 sc->sc_nscreens--;
367 }
368
369 int
370 agten_show_screen(v, cookie, waitok, cb, cbarg)
371 void *v;
372 void *cookie;
373 int waitok;
374 void (*cb)(void *, int, int);
375 void *cbarg;
376 {
377 return (0);
378 }
379
380 int
381 agten_getcmap(struct agten_cmap *cm, struct wsdisplay_cmap *rcm)
382 {
383 u_int index = rcm->index, count = rcm->count;
384 int error;
385
386 if (index >= 256 || count > 256 - index)
387 return (EINVAL);
388
389 if ((error = copyout(&cm->cm_red[index], rcm->red, count)) != 0)
390 return (error);
391 if ((error = copyout(&cm->cm_green[index], rcm->green, count)) != 0)
392 return (error);
393 if ((error = copyout(&cm->cm_blue[index], rcm->blue, count)) != 0)
394 return (error);
395
396 return (0);
397 }
398
399 int
400 agten_putcmap(struct agten_cmap *cm, struct wsdisplay_cmap *rcm)
401 {
402 u_int index = rcm->index, count = rcm->count;
403 int error;
404
405 if (index >= 256 || count > 256 - index)
406 return (EINVAL);
407
408 if ((error = copyin(rcm->red, &cm->cm_red[index], count)) != 0)
409 return (error);
410 if ((error = copyin(rcm->green, &cm->cm_green[index], count)) != 0)
411 return (error);
412 if ((error = copyin(rcm->blue, &cm->cm_blue[index], count)) != 0)
413 return (error);
414
415 return (0);
416 }
417
418 static __inline__ void
419 ibm561_write(struct agten_softc *sc, u_int32_t reg, u_int32_t value)
420 {
421
422
423
424
425 *(volatile u_int32_t *)(sc->sc_p9100 + P9100_RAMDAC_REGISTER(reg)) =
426 (value) << 16;
427 }
428
429 void
430 agten_loadcmap(struct agten_softc *sc, u_int start, u_int ncolors)
431 {
432 int i;
433 u_int8_t *red, *green, *blue;
434
435 ibm561_write(sc, IBM561_ADDR_LOW,
436 (IBM561_CMAP_TABLE + start) & 0xff);
437 ibm561_write(sc, IBM561_ADDR_HIGH,
438 ((IBM561_CMAP_TABLE + start) >> 8) & 0xff);
439
440 red = sc->sc_cmap.cm_red;
441 green = sc->sc_cmap.cm_green;
442 blue = sc->sc_cmap.cm_blue;
443 for (i = start; i < start + ncolors; i++) {
444 ibm561_write(sc, IBM561_CMD_CMAP, *red++);
445 ibm561_write(sc, IBM561_CMD_CMAP, *green++);
446 ibm561_write(sc, IBM561_CMD_CMAP, *blue++);
447 }
448 }