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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
|
/* $NetBSD: lynxfb.c,v 1.7 2021/08/07 16:19:14 thorpej Exp $ */
/* $OpenBSD: smfb.c,v 1.13 2011/07/21 20:36:12 miod Exp $ */
/*
* Copyright (c) 2012 NONAKA Kimihiro <nonaka@netbsd.org>
* Copyright (c) 2009, 2010 Miodrag Vallat.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* SiliconMotion SM712 frame buffer driver.
*
* Assumes its video output is an LCD panel, in 5:6:5 mode, and fixed
* 1024x600 resolution, depending on the system model.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lynxfb.c,v 1.7 2021/08/07 16:19:14 thorpej Exp $");
#include "opt_wsemul.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/endian.h>
#include <sys/kauth.h>
#include <sys/bus.h>
#include <dev/ic/vgareg.h>
#include <dev/isa/isareg.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
#include <dev/pci/pciio.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/rasops/rasops.h>
#include <dev/wscons/wsdisplay_vconsvar.h>
#include <dev/pci/wsdisplay_pci.h>
#include <dev/pci/lynxfbreg.h>
#include <dev/pci/lynxfbvar.h>
#ifndef LYNXFB_DEFAULT_WIDTH
#define LYNXFB_DEFAULT_WIDTH 1024
#endif
#ifndef LYNXFB_DEFAULT_HEIGHT
#define LYNXFB_DEFAULT_HEIGHT 600
#endif
#ifndef LYNXFB_DEFAULT_DEPTH
#define LYNXFB_DEFAULT_DEPTH 16
#endif
#ifndef LYNXFB_DEFAULT_STRIDE
#define LYNXFB_DEFAULT_STRIDE 0
#endif
#ifndef LYNXFB_DEFAULT_FLAGS
#ifdef __MIPSEL__
#define LYNXFB_DEFAULT_FLAGS LYNXFB_FLAG_SWAPBR
#else
#define LYNXFB_DEFAULT_FLAGS 0
#endif
#endif
struct lynxfb_softc;
/* minimal frame buffer information, suitable for early console */
struct lynxfb {
struct lynxfb_softc *sc;
void *fbaddr;
bus_space_tag_t memt;
bus_space_handle_t memh;
/* DPR registers */
bus_space_tag_t dprt;
bus_space_handle_t dprh;
/* MMIO space */
bus_space_tag_t mmiot;
bus_space_handle_t mmioh;
struct vcons_screen vcs;
struct wsscreen_descr wsd;
int width, height, depth, stride;
int accel;
int blank;
/* LYNXFB_FLAG_* */
int flags;
#define LYNXFB_FLAG_SWAPBR (1 << 0)
};
#define DPR_READ(fb, reg) \
bus_space_read_4((fb)->memt, (fb)->dprh, (reg))
#define DPR_WRITE(fb, reg, val) \
bus_space_write_4((fb)->memt, (fb)->dprh, (reg), (val))
struct lynxfb_softc {
device_t sc_dev;
bus_space_tag_t sc_memt;
bus_space_handle_t sc_memh;
pci_chipset_tag_t sc_pc;
pcitag_t sc_pcitag;
struct lynxfb *sc_fb;
struct lynxfb sc_fb_store;
bus_addr_t sc_fbaddr;
bus_size_t sc_fbsize;
struct vcons_data sc_vd;
struct wsscreen_list sc_screenlist;
const struct wsscreen_descr *sc_screens[1];
int sc_mode;
};
static int lynxfb_match_by_id(pcireg_t);
static int lynxfb_match(device_t, cfdata_t, void *);
static void lynxfb_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(lynxfb, sizeof(struct lynxfb_softc),
lynxfb_match, lynxfb_attach, NULL, NULL);
static int lynxfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
static paddr_t lynxfb_mmap(void *, void *, off_t, int);
static struct wsdisplay_accessops lynxfb_accessops = {
lynxfb_ioctl,
lynxfb_mmap,
NULL, /* alloc_screen */
NULL, /* free_screen */
NULL, /* show_screen */
NULL, /* load_font */
NULL, /* pollc */
NULL, /* scroll */
};
static bool lynxfb_is_console(struct lynxfb_softc *, pcitag_t);
static void lynxfb_init_screen(void *, struct vcons_screen *, int, long *);
static int lynxfb_setup(struct lynxfb *);
static int lynxfb_wait(struct lynxfb *);
static void lynxfb_copyrect(struct lynxfb *, int, int, int, int, int, int);
static void lynxfb_fillrect(struct lynxfb *, int, int, int, int, int);
static void lynxfb_copyrows(void *, int, int, int);
static void lynxfb_copycols(void *, int, int, int, int);
static void lynxfb_erasecols(void *, int, int, int, long);
static void lynxfb_eraserows(void *, int, int, long);
static void lynxfb_vcons_copyrows(void *, int, int, int);
static void lynxfb_vcons_copycols(void *, int, int, int, int);
static void lynxfb_vcons_erasecols(void *, int, int, int, long);
static void lynxfb_vcons_eraserows(void *, int, int, long);
static void lynxfb_blank(struct lynxfb *, int);
static struct {
bool is_console;
pcitag_t tag;
bus_space_tag_t memt;
bus_space_handle_t memh;
struct lynxfb fb;
bus_addr_t fbaddr;
bus_size_t fbsize;
} lynxfb_console;
int lynxfb_default_width = LYNXFB_DEFAULT_WIDTH;
int lynxfb_default_height = LYNXFB_DEFAULT_HEIGHT;
int lynxfb_default_depth = LYNXFB_DEFAULT_DEPTH;
int lynxfb_default_stride = LYNXFB_DEFAULT_STRIDE;
int lynxfb_default_flags = LYNXFB_DEFAULT_FLAGS;
static int
lynxfb_match_by_id(pcireg_t id)
{
if (PCI_VENDOR(id) != PCI_VENDOR_SILMOTION)
return (0);
if (PCI_PRODUCT(id) != PCI_PRODUCT_SILMOTION_SM712)
return (0);
return (1);
}
int
lynxfb_cnattach(bus_space_tag_t memt, bus_space_tag_t iot, pci_chipset_tag_t pc,
pcitag_t tag, pcireg_t id)
{
struct rasops_info *ri = &lynxfb_console.fb.vcs.scr_ri;
struct lynxfb *fb;
bus_space_handle_t memh;
bus_addr_t base;
bus_size_t size;
long defattr;
int mapflags;
int error;
if (!lynxfb_match_by_id(id))
return (ENODEV);
if (pci_mapreg_info(pc, tag, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM,
&base, &size, &mapflags))
return (EINVAL);
error = bus_space_map(memt, base, size, BUS_SPACE_MAP_LINEAR | mapflags,
&memh);
if (error)
return (error);
fb = &lynxfb_console.fb;
fb->memt = memt;
fb->memh = memh;
fb->width = lynxfb_default_width;
fb->height = lynxfb_default_height;
fb->depth = lynxfb_default_depth;
fb->stride = lynxfb_default_stride;
if (fb->stride == 0)
fb->stride = fb->width * fb->depth / 8;
fb->flags = lynxfb_default_flags;
error = lynxfb_setup(fb);
if (error) {
bus_space_unmap(memt, memh, size);
return (error);
}
lynxfb_console.is_console = true;
lynxfb_console.tag = tag;
lynxfb_console.fbaddr = base;
lynxfb_console.fbsize = size;
(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
wsdisplay_preattach(&fb->wsd, ri, 0, 0, defattr);
return (0);
}
static bool
lynxfb_is_console(struct lynxfb_softc *sc, pcitag_t tag)
{
return (lynxfb_console.is_console &&
!memcmp(&lynxfb_console.tag, &tag, sizeof(tag)));
}
static int
lynxfb_match(device_t parent, cfdata_t match, void *aux)
{
struct pci_attach_args *pa = (struct pci_attach_args *)aux;
if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY)
return (0);
if (!lynxfb_match_by_id(pa->pa_id))
return (0);
return (1);
}
static void
lynxfb_attach(device_t parent, device_t self, void *aux)
{
struct lynxfb_softc *sc = device_private(self);
struct pci_attach_args *pa = (struct pci_attach_args *)aux;
struct wsemuldisplaydev_attach_args waa;
struct lynxfb *fb;
struct rasops_info *ri;
prop_dictionary_t dict;
long defattr;
bool is_console;
sc->sc_dev = self;
sc->sc_pc = pa->pa_pc;
sc->sc_pcitag = pa->pa_tag;
pci_aprint_devinfo(pa, NULL);
is_console = lynxfb_is_console(sc, sc->sc_pcitag);
fb = is_console ? &lynxfb_console.fb : &sc->sc_fb_store;
sc->sc_fb = fb;
fb->sc = sc;
if (is_console) {
sc->sc_fbaddr = lynxfb_console.fbaddr;
sc->sc_fbsize = lynxfb_console.fbsize;
} else {
if (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM,
BUS_SPACE_MAP_LINEAR, &fb->memt, &fb->memh, &sc->sc_fbaddr,
&sc->sc_fbsize)) {
aprint_error_dev(self, "can't map frame buffer\n");
return;
}
dict = device_properties(self);
if (!prop_dictionary_get_uint32(dict, "width", &fb->width))
fb->width = lynxfb_default_width;
if (!prop_dictionary_get_uint32(dict, "height", &fb->height))
fb->height = lynxfb_default_height;
if (!prop_dictionary_get_uint32(dict, "depth", &fb->depth))
fb->depth = lynxfb_default_depth;
if (!prop_dictionary_get_uint32(dict, "linebytes", &fb->stride)) {
if (lynxfb_default_stride == 0)
fb->stride = fb->width * fb->depth / 8;
else
fb->stride = lynxfb_default_stride;
}
if (!prop_dictionary_get_uint32(dict, "flags", &fb->flags))
fb->flags = lynxfb_default_flags;
if (lynxfb_setup(fb)) {
aprint_error_dev(self, "can't setup frame buffer\n");
bus_space_unmap(fb->memt, fb->memh, sc->sc_fbsize);
return;
}
}
sc->sc_memt = fb->memt;
sc->sc_memh = fb->memh;
aprint_normal_dev(self, "%d x %d, %d bpp, stride %d\n", fb->width,
fb->height, fb->depth, fb->stride);
fb->wsd = (struct wsscreen_descr) {
"default",
0, 0,
NULL,
8, 16,
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
NULL,
};
sc->sc_screens[0] = &fb->wsd;
sc->sc_screenlist = (struct wsscreen_list){ 1, sc->sc_screens };
sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
vcons_init(&sc->sc_vd, sc, &fb->wsd, &lynxfb_accessops);
sc->sc_vd.init_screen = lynxfb_init_screen;
ri = &fb->vcs.scr_ri;
if (is_console) {
vcons_init_screen(&sc->sc_vd, &fb->vcs, 1, &defattr);
fb->vcs.scr_flags |= VCONS_SCREEN_IS_STATIC;
fb->wsd.textops = &ri->ri_ops;
fb->wsd.capabilities = ri->ri_caps;
fb->wsd.nrows = ri->ri_rows;
fb->wsd.ncols = ri->ri_cols;
wsdisplay_cnattach(&fb->wsd, ri, 0, 0, defattr);
vcons_replay_msgbuf(&fb->vcs);
} else {
/*
* since we're not the console we can postpone the rest
* until someone actually allocates a screen for us
*/
(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
}
waa.console = is_console;
waa.scrdata = &sc->sc_screenlist;
waa.accessops = &lynxfb_accessops;
waa.accesscookie = &sc->sc_vd;
config_found(self, &waa, wsemuldisplaydevprint, CFARGS_NONE);
}
/*
* vga sequencer access through MMIO space
*/
static __inline uint8_t
lynxfb_vgats_read(struct lynxfb *fb, uint regno)
{
bus_space_write_1(fb->mmiot, fb->mmioh, IO_VGA + VGA_TS_INDEX, regno);
return bus_space_read_1(fb->mmiot, fb->mmioh, IO_VGA + VGA_TS_DATA);
}
static __inline void
lynxfb_vgats_write(struct lynxfb *fb, uint regno, uint8_t value)
{
bus_space_write_1(fb->mmiot, fb->mmioh, IO_VGA + VGA_TS_INDEX, regno);
bus_space_write_1(fb->mmiot, fb->mmioh, IO_VGA + VGA_TS_DATA, value);
}
/*
* wsdisplay accesops
*/
static int
lynxfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flags,
struct lwp *l)
{
struct vcons_data *vd = v;
struct lynxfb_softc *sc = vd->cookie;
struct lynxfb *fb = sc->sc_fb;
struct vcons_screen *ms = vd->active;
struct wsdisplay_fbinfo *wdf;
struct wsdisplay_param *param;
switch (cmd) {
case WSDISPLAYIO_GTYPE:
*(uint *)data = WSDISPLAY_TYPE_PCIMISC;
return (0);
/* PCI config read/write passthrough. */
case PCI_IOC_CFGREAD:
case PCI_IOC_CFGWRITE:
return pci_devioctl(sc->sc_pc, sc->sc_pcitag,
cmd, data, flags, l);
case WSDISPLAYIO_GET_BUSID:
return wsdisplayio_busid_pci(sc->sc_dev, sc->sc_pc,
sc->sc_pcitag, data);
case WSDISPLAYIO_GINFO:
if (ms == NULL)
return (ENODEV);
wdf = (struct wsdisplay_fbinfo *)data;
wdf->width = ms->scr_ri.ri_width;
wdf->height = ms->scr_ri.ri_height;
wdf->depth = ms->scr_ri.ri_depth;
wdf->cmsize = 0;
return (0);
case WSDISPLAYIO_LINEBYTES:
*(uint *)data = fb->stride;
return (0);
case WSDISPLAYIO_GVIDEO:
*(int *)data = fb->blank ? WSDISPLAYIO_VIDEO_OFF :
WSDISPLAYIO_VIDEO_ON;
return (0);
case WSDISPLAYIO_SVIDEO:
lynxfb_blank(fb, *(int *)data);
return (0);
case WSDISPLAYIO_GETPARAM:
param = (struct wsdisplay_param *)data;
switch (param->param) {
case WSDISPLAYIO_PARAM_BACKLIGHT:
param->min = 0;
param->max = 1;
param->curval = fb->blank;
return (0);
}
break;
case WSDISPLAYIO_SETPARAM:
param = (struct wsdisplay_param *)data;
switch (param->param) {
case WSDISPLAYIO_PARAM_BACKLIGHT:
lynxfb_blank(fb, param->curval);
return (0);
}
break;
}
return (EPASSTHROUGH);
}
static paddr_t
lynxfb_mmap(void *v, void *vs, off_t offset, int prot)
{
struct vcons_data *vd = v;
struct lynxfb_softc *sc = vd->cookie;
struct rasops_info *ri = &sc->sc_fb->vcs.scr_ri;
/* 'regular' framebuffer mmap()ing */
if (offset < ri->ri_stride * ri->ri_height) {
return bus_space_mmap(sc->sc_memt, sc->sc_fbaddr + offset, 0,
prot, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE);
}
/*
* restrict all other mappings to processes with superuser privileges
* or the kernel itself
*/
if (kauth_authorize_machdep(kauth_cred_get(),
KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL) != 0) {
aprint_normal_dev(sc->sc_dev, "mmap() rejected.\n");
return (-1);
}
/* framebuffer mmap()ing */
if (offset >= sc->sc_fbaddr &&
offset < sc->sc_fbaddr + ri->ri_stride * ri->ri_height) {
return bus_space_mmap(sc->sc_memt, offset, 0, prot,
BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE);
}
/* register mmap()ing */
if (offset >= sc->sc_fbaddr + SM7XX_REG_BASE &&
offset < sc->sc_fbaddr + SM7XX_REG_BASE + SM7XX_REG_SIZE) {
return bus_space_mmap(sc->sc_memt, offset, 0, prot, 0);
}
return (-1);
}
static void
lynxfb_init_screen(void *cookie, struct vcons_screen *scr,
int existing, long *defattr)
{
struct lynxfb_softc *sc = cookie;
struct lynxfb *fb = sc->sc_fb;
struct rasops_info *ri = &scr->scr_ri;
ri->ri_width = fb->width;
ri->ri_height = fb->height;
ri->ri_depth = fb->depth;
ri->ri_stride = fb->stride;
ri->ri_flg = RI_CENTER;
ri->ri_bits = fb->fbaddr;
#ifdef VCONS_DRAW_INTR
scr->scr_flags |= VCONS_DONT_READ;
#endif
if (existing)
ri->ri_flg |= RI_CLEAR;
rasops_init(ri, 0, 0);
ri->ri_caps = WSSCREEN_WSCOLORS;
rasops_reconfig(ri, fb->height / ri->ri_font->fontheight,
fb->width / ri->ri_font->fontwidth);
ri->ri_hw = scr;
if (fb->accel) {
ri->ri_ops.copycols = lynxfb_vcons_copycols;
ri->ri_ops.copyrows = lynxfb_vcons_copyrows;
ri->ri_ops.erasecols = lynxfb_vcons_erasecols;
ri->ri_ops.eraserows = lynxfb_vcons_eraserows;
}
}
/*
* Frame buffer initialization.
*/
static int
lynxfb_setup(struct lynxfb *fb)
{
struct rasops_info *ri = &fb->vcs.scr_ri;
int error;
fb->dprt = fb->memt;
error = bus_space_subregion(fb->memt, fb->memh, SM7XX_DPR_BASE,
SMXXX_DPR_SIZE, &fb->dprh);
if (error != 0)
return (error);
fb->mmiot = fb->memt;
error = bus_space_subregion(fb->mmiot, fb->memh, SM7XX_MMIO_BASE,
SM7XX_MMIO_SIZE, &fb->mmioh);
if (error != 0)
return (error);
ri->ri_width = fb->width;
ri->ri_height = fb->height;
ri->ri_depth = fb->depth;
ri->ri_stride = fb->stride;
ri->ri_flg = RI_CENTER | RI_CLEAR | RI_NO_AUTO;
fb->fbaddr = ri->ri_bits = (void *)bus_space_vaddr(fb->memt, fb->memh);
ri->ri_hw = fb;
if (fb->flags & LYNXFB_FLAG_SWAPBR) {
switch (fb->depth) {
case 16:
ri->ri_rnum = 5;
ri->ri_rpos = 11;
ri->ri_gnum = 6;
ri->ri_gpos = 5;
ri->ri_bnum = 5;
ri->ri_bpos = 0;
break;
}
}
rasops_init(ri, 0, 0);
rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
ri->ri_width / ri->ri_font->fontwidth);
fb->wsd.name = "std";
fb->wsd.ncols = ri->ri_cols;
fb->wsd.nrows = ri->ri_rows;
fb->wsd.textops = &ri->ri_ops;
fb->wsd.fontwidth = ri->ri_font->fontwidth;
fb->wsd.fontheight = ri->ri_font->fontheight;
fb->wsd.capabilities = ri->ri_caps;
/*
* Setup 2D acceleration whenever possible
*/
if (lynxfb_wait(fb) == 0) {
fb->accel = 1;
DPR_WRITE(fb, DPR_CROP_TOPLEFT_COORDS, DPR_COORDS(0, 0));
/* use of width both times is intentional */
DPR_WRITE(fb, DPR_PITCH,
DPR_COORDS(ri->ri_width, ri->ri_width));
DPR_WRITE(fb, DPR_SRC_WINDOW,
DPR_COORDS(ri->ri_width, ri->ri_width));
DPR_WRITE(fb, DPR_BYTE_BIT_MASK, 0xffffffff);
DPR_WRITE(fb, DPR_COLOR_COMPARE_MASK, 0);
DPR_WRITE(fb, DPR_COLOR_COMPARE, 0);
DPR_WRITE(fb, DPR_SRC_BASE, 0);
DPR_WRITE(fb, DPR_DST_BASE, 0);
DPR_READ(fb, DPR_DST_BASE);
ri->ri_ops.copycols = lynxfb_copycols;
ri->ri_ops.copyrows = lynxfb_copyrows;
ri->ri_ops.erasecols = lynxfb_erasecols;
ri->ri_ops.eraserows = lynxfb_eraserows;
}
return (0);
}
static int
lynxfb_wait(struct lynxfb *fb)
{
uint32_t reg;
int i;
for (i = 10000; i > 0; i--) {
reg = lynxfb_vgats_read(fb, 0x16);
if ((reg & 0x18) == 0x10)
return (0);
delay(1);
}
return (EBUSY);
}
static void
lynxfb_copyrect(struct lynxfb *fb, int sx, int sy, int dx, int dy, int w, int h)
{
uint32_t dir;
/* Compute rop direction */
if (sy < dy || (sy == dy && sx <= dx)) {
sx += w - 1;
dx += w - 1;
sy += h - 1;
dy += h - 1;
dir = DE_CTRL_RTOL;
} else
dir = 0;
DPR_WRITE(fb, DPR_SRC_COORDS, DPR_COORDS(sx, sy));
DPR_WRITE(fb, DPR_DST_COORDS, DPR_COORDS(dx, dy));
DPR_WRITE(fb, DPR_SPAN_COORDS, DPR_COORDS(w, h));
DPR_WRITE(fb, DPR_DE_CTRL, DE_CTRL_START | DE_CTRL_ROP_ENABLE | dir |
(DE_CTRL_COMMAND_BITBLT << DE_CTRL_COMMAND_SHIFT) |
(DE_CTRL_ROP_SRC << DE_CTRL_ROP_SHIFT));
DPR_READ(fb, DPR_DE_CTRL);
lynxfb_wait(fb);
}
static void
lynxfb_fillrect(struct lynxfb *fb, int x, int y, int w, int h, int bg)
{
struct rasops_info *ri = &fb->vcs.scr_ri;
DPR_WRITE(fb, DPR_FG_COLOR, ri->ri_devcmap[bg]);
DPR_WRITE(fb, DPR_DST_COORDS, DPR_COORDS(x, y));
DPR_WRITE(fb, DPR_SPAN_COORDS, DPR_COORDS(w, h));
DPR_WRITE(fb, DPR_DE_CTRL, DE_CTRL_START | DE_CTRL_ROP_ENABLE |
(DE_CTRL_COMMAND_SOLIDFILL << DE_CTRL_COMMAND_SHIFT) |
(DE_CTRL_ROP_SRC << DE_CTRL_ROP_SHIFT));
DPR_READ(fb, DPR_DE_CTRL);
lynxfb_wait(fb);
}
static inline void
lynxfb_copyrows1(struct rasops_info *ri, int src, int dst, int num,
struct lynxfb *fb)
{
struct wsdisplay_font *f = ri->ri_font;
num *= f->fontheight;
src *= f->fontheight;
dst *= f->fontheight;
lynxfb_copyrect(fb, ri->ri_xorigin, ri->ri_yorigin + src,
ri->ri_xorigin, ri->ri_yorigin + dst, ri->ri_emuwidth, num);
}
static inline void
lynxfb_copycols1(struct rasops_info *ri, int row, int src, int dst, int num,
struct lynxfb *fb)
{
struct wsdisplay_font *f = ri->ri_font;
num *= f->fontwidth;
src *= f->fontwidth;
dst *= f->fontwidth;
row *= f->fontheight;
lynxfb_copyrect(fb, ri->ri_xorigin + src, ri->ri_yorigin + row,
ri->ri_xorigin + dst, ri->ri_yorigin + row, num, f->fontheight);
}
static inline void
lynxfb_erasecols1(struct rasops_info *ri, int row, int col, int num, long attr,
struct lynxfb *fb)
{
struct wsdisplay_font *f = ri->ri_font;
int32_t bg, fg, ul;
row *= f->fontheight;
col *= f->fontwidth;
num *= f->fontwidth;
rasops_unpack_attr(attr, &fg, &bg, &ul);
lynxfb_fillrect(fb, ri->ri_xorigin + col, ri->ri_yorigin + row,
num, f->fontheight, bg);
}
static inline void
lynxfb_eraserows1(struct rasops_info *ri, int row, int num, long attr,
struct lynxfb *fb)
{
struct wsdisplay_font *f = ri->ri_font;
int32_t bg, fg, ul;
int x, y, w;
if ((num == ri->ri_rows) && ISSET(ri->ri_flg, RI_FULLCLEAR)) {
num = ri->ri_height;
x = y = 0;
w = ri->ri_width;
} else {
num *= f->fontheight;
x = ri->ri_xorigin;
y = ri->ri_yorigin + row * f->fontheight;
w = ri->ri_emuwidth;
}
rasops_unpack_attr(attr, &fg, &bg, &ul);
lynxfb_fillrect(fb, x, y, w, num, bg);
}
static void
lynxfb_copyrows(void *cookie, int src, int dst, int num)
{
struct rasops_info *ri = cookie;
struct lynxfb *fb = ri->ri_hw;
lynxfb_copyrows1(ri, src, dst, num, fb);
}
static void
lynxfb_copycols(void *cookie, int row, int src, int dst, int num)
{
struct rasops_info *ri = cookie;
struct lynxfb *fb = ri->ri_hw;
lynxfb_copycols1(ri, row, src, dst, num, fb);
}
static void
lynxfb_erasecols(void *cookie, int row, int col, int num, long attr)
{
struct rasops_info *ri = cookie;
struct lynxfb *fb = ri->ri_hw;
lynxfb_erasecols1(ri, row, col, num, attr, fb);
}
static void
lynxfb_eraserows(void *cookie, int row, int num, long attr)
{
struct rasops_info *ri = cookie;
struct lynxfb *fb = ri->ri_hw;
lynxfb_eraserows1(ri, row, num, attr, fb);
}
static void
lynxfb_vcons_copyrows(void *cookie, int src, int dst, int num)
{
struct rasops_info *ri = cookie;
struct vcons_screen *scr = ri->ri_hw;
struct lynxfb_softc *sc = scr->scr_cookie;
struct lynxfb *fb = sc->sc_fb;
lynxfb_copyrows1(ri, src, dst, num, fb);
}
static void
lynxfb_vcons_copycols(void *cookie, int row, int src, int dst, int num)
{
struct rasops_info *ri = cookie;
struct vcons_screen *scr = ri->ri_hw;
struct lynxfb_softc *sc = scr->scr_cookie;
struct lynxfb *fb = sc->sc_fb;
lynxfb_copycols1(ri, row, src, dst, num, fb);
}
static void
lynxfb_vcons_erasecols(void *cookie, int row, int col, int num, long attr)
{
struct rasops_info *ri = cookie;
struct vcons_screen *scr = ri->ri_hw;
struct lynxfb_softc *sc = scr->scr_cookie;
struct lynxfb *fb = sc->sc_fb;
lynxfb_erasecols1(ri, row, col, num, attr, fb);
}
static void
lynxfb_vcons_eraserows(void *cookie, int row, int num, long attr)
{
struct rasops_info *ri = cookie;
struct vcons_screen *scr = ri->ri_hw;
struct lynxfb_softc *sc = scr->scr_cookie;
struct lynxfb *fb = sc->sc_fb;
lynxfb_eraserows1(ri, row, num, attr, fb);
}
static void
lynxfb_blank(struct lynxfb *fb, int enable)
{
fb->blank = !enable;
if (enable) {
lynxfb_vgats_write(fb, 0x31,
lynxfb_vgats_read(fb, 0x31) | 0x01);
} else {
lynxfb_vgats_write(fb, 0x21,
lynxfb_vgats_read(fb, 0x21) | 0x30);
lynxfb_vgats_write(fb, 0x31,
lynxfb_vgats_read(fb, 0x31) & ~0x01);
}
}
|