wcfb.c revision 1.6.2.2 1 1.6.2.2 yamt /* $NetBSD: wcfb.c,v 1.6.2.2 2010/03/11 15:03:59 yamt Exp $ */
2 1.6.2.2 yamt
3 1.6.2.2 yamt /*-
4 1.6.2.2 yamt * Copyright (c) 2010 Michael Lorenz
5 1.6.2.2 yamt * All rights reserved.
6 1.6.2.2 yamt *
7 1.6.2.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.6.2.2 yamt * modification, are permitted provided that the following conditions
9 1.6.2.2 yamt * are met:
10 1.6.2.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.6.2.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.6.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.6.2.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.6.2.2 yamt * documentation and/or other materials provided with the distribution.
15 1.6.2.2 yamt *
16 1.6.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.6.2.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.6.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.6.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.6.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.6.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.6.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.6.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.6.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.6.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.6.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
27 1.6.2.2 yamt */
28 1.6.2.2 yamt
29 1.6.2.2 yamt #include <sys/cdefs.h>
30 1.6.2.2 yamt __KERNEL_RCSID(0, "$NetBSD: wcfb.c,v 1.6.2.2 2010/03/11 15:03:59 yamt Exp $");
31 1.6.2.2 yamt
32 1.6.2.2 yamt #include <sys/param.h>
33 1.6.2.2 yamt #include <sys/systm.h>
34 1.6.2.2 yamt #include <sys/kernel.h>
35 1.6.2.2 yamt #include <sys/device.h>
36 1.6.2.2 yamt #include <sys/proc.h>
37 1.6.2.2 yamt #include <sys/mutex.h>
38 1.6.2.2 yamt #include <sys/ioctl.h>
39 1.6.2.2 yamt #include <sys/kernel.h>
40 1.6.2.2 yamt #include <sys/systm.h>
41 1.6.2.2 yamt #include <sys/kauth.h>
42 1.6.2.2 yamt #include <sys/kmem.h>
43 1.6.2.2 yamt
44 1.6.2.2 yamt #include <dev/pci/pcidevs.h>
45 1.6.2.2 yamt #include <dev/pci/pcireg.h>
46 1.6.2.2 yamt #include <dev/pci/pcivar.h>
47 1.6.2.2 yamt #include <dev/pci/pciio.h>
48 1.6.2.2 yamt #include <dev/pci/wcfbreg.h>
49 1.6.2.2 yamt
50 1.6.2.2 yamt #include <dev/wscons/wsdisplayvar.h>
51 1.6.2.2 yamt #include <dev/wscons/wsconsio.h>
52 1.6.2.2 yamt #include <dev/wsfont/wsfont.h>
53 1.6.2.2 yamt #include <dev/rasops/rasops.h>
54 1.6.2.2 yamt #include <dev/wscons/wsdisplay_vconsvar.h>
55 1.6.2.2 yamt
56 1.6.2.2 yamt #include "opt_wsfb.h"
57 1.6.2.2 yamt #include "opt_wsdisplay_compat.h"
58 1.6.2.2 yamt
59 1.6.2.2 yamt #ifdef WCFB_DEBUG
60 1.6.2.2 yamt # define DPRINTF printf
61 1.6.2.2 yamt #else
62 1.6.2.2 yamt # define DPRINTF while (0) printf
63 1.6.2.2 yamt #endif
64 1.6.2.2 yamt
65 1.6.2.2 yamt static int wcfb_match(device_t, cfdata_t, void *);
66 1.6.2.2 yamt static void wcfb_attach(device_t, device_t, void *);
67 1.6.2.2 yamt static int wcfb_ioctl(void *, void *, u_long, void *, int,
68 1.6.2.2 yamt struct lwp *);
69 1.6.2.2 yamt static paddr_t wcfb_mmap(void *, void *, off_t, int);
70 1.6.2.2 yamt
71 1.6.2.2 yamt struct wcfb_softc {
72 1.6.2.2 yamt device_t sc_dev;
73 1.6.2.2 yamt
74 1.6.2.2 yamt pci_chipset_tag_t sc_pc;
75 1.6.2.2 yamt pcitag_t sc_pcitag;
76 1.6.2.2 yamt
77 1.6.2.2 yamt bus_space_tag_t sc_memt;
78 1.6.2.2 yamt bus_space_tag_t sc_regt, sc_wtft;
79 1.6.2.2 yamt bus_space_tag_t sc_iot;
80 1.6.2.2 yamt
81 1.6.2.2 yamt bus_space_handle_t sc_fbh, sc_wtfh;
82 1.6.2.2 yamt bus_space_handle_t sc_regh;
83 1.6.2.2 yamt bus_addr_t sc_fb, sc_reg, sc_wtf;
84 1.6.2.2 yamt bus_size_t sc_fbsize, sc_regsize, sc_wtfsize;
85 1.6.2.2 yamt
86 1.6.2.2 yamt int sc_width, sc_height, sc_stride;
87 1.6.2.2 yamt int sc_locked;
88 1.6.2.2 yamt uint8_t *sc_fbaddr, *sc_fb0, *sc_fb1, *sc_shadow;
89 1.6.2.2 yamt struct vcons_screen sc_console_screen;
90 1.6.2.2 yamt struct wsscreen_descr sc_defaultscreen_descr;
91 1.6.2.2 yamt const struct wsscreen_descr *sc_screens[1];
92 1.6.2.2 yamt struct wsscreen_list sc_screenlist;
93 1.6.2.2 yamt struct vcons_data vd;
94 1.6.2.2 yamt int sc_mode;
95 1.6.2.2 yamt u_char sc_cmap_red[256];
96 1.6.2.2 yamt u_char sc_cmap_green[256];
97 1.6.2.2 yamt u_char sc_cmap_blue[256];
98 1.6.2.2 yamt uint32_t sc_fb0off, sc_fb1off;
99 1.6.2.2 yamt
100 1.6.2.2 yamt void (*copycols)(void *, int, int, int, int);
101 1.6.2.2 yamt void (*erasecols)(void *, int, int, int, long);
102 1.6.2.2 yamt void (*copyrows)(void *, int, int, int);
103 1.6.2.2 yamt void (*eraserows)(void *, int, int, long);
104 1.6.2.2 yamt void (*putchar)(void *, int, int, u_int, long);
105 1.6.2.2 yamt void (*cursor)(void *, int, int, int);
106 1.6.2.2 yamt
107 1.6.2.2 yamt };
108 1.6.2.2 yamt
109 1.6.2.2 yamt static void wcfb_init_screen(void *, struct vcons_screen *, int, long *);
110 1.6.2.2 yamt
111 1.6.2.2 yamt CFATTACH_DECL_NEW(wcfb, sizeof(struct wcfb_softc),
112 1.6.2.2 yamt wcfb_match, wcfb_attach, NULL, NULL);
113 1.6.2.2 yamt
114 1.6.2.2 yamt struct wsdisplay_accessops wcfb_accessops = {
115 1.6.2.2 yamt wcfb_ioctl,
116 1.6.2.2 yamt wcfb_mmap,
117 1.6.2.2 yamt NULL, /* alloc_screen */
118 1.6.2.2 yamt NULL, /* free_screen */
119 1.6.2.2 yamt NULL, /* show_screen */
120 1.6.2.2 yamt NULL, /* load_font */
121 1.6.2.2 yamt NULL, /* pollc */
122 1.6.2.2 yamt NULL /* scroll */
123 1.6.2.2 yamt };
124 1.6.2.2 yamt
125 1.6.2.2 yamt static void wcfb_putchar(void *, int, int, u_int, long);
126 1.6.2.2 yamt static void wcfb_cursor(void *, int, int, int);
127 1.6.2.2 yamt static void wcfb_copycols(void *, int, int, int, int);
128 1.6.2.2 yamt static void wcfb_erasecols(void *, int, int, int, long);
129 1.6.2.2 yamt static void wcfb_copyrows(void *, int, int, int);
130 1.6.2.2 yamt static void wcfb_eraserows(void *, int, int, long);
131 1.6.2.2 yamt
132 1.6.2.2 yamt static void wcfb_putpalreg(struct wcfb_softc *, int, int, int, int);
133 1.6.2.2 yamt
134 1.6.2.2 yamt static int
135 1.6.2.2 yamt wcfb_match(device_t parent, cfdata_t match, void *aux)
136 1.6.2.2 yamt {
137 1.6.2.2 yamt struct pci_attach_args *pa = aux;
138 1.6.2.2 yamt
139 1.6.2.2 yamt if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_3DLABS &&
140 1.6.2.2 yamt PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_WILDCAT5110)
141 1.6.2.2 yamt return 100;
142 1.6.2.2 yamt
143 1.6.2.2 yamt return 0;
144 1.6.2.2 yamt }
145 1.6.2.2 yamt
146 1.6.2.2 yamt static void
147 1.6.2.2 yamt wcfb_attach(device_t parent, device_t self, void *aux)
148 1.6.2.2 yamt {
149 1.6.2.2 yamt struct wcfb_softc *sc = device_private(self);
150 1.6.2.2 yamt struct pci_attach_args *pa = aux;
151 1.6.2.2 yamt struct rasops_info *ri;
152 1.6.2.2 yamt prop_dictionary_t dict;
153 1.6.2.2 yamt struct wsemuldisplaydev_attach_args aa;
154 1.6.2.2 yamt int i, j;
155 1.6.2.2 yamt uint32_t reg;
156 1.6.2.2 yamt unsigned long defattr;
157 1.6.2.2 yamt bool is_console = 0;
158 1.6.2.2 yamt char devinfo[256];
159 1.6.2.2 yamt void *wtf;
160 1.6.2.2 yamt
161 1.6.2.2 yamt sc->sc_dev = self;
162 1.6.2.2 yamt sc->putchar = NULL;
163 1.6.2.2 yamt pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
164 1.6.2.2 yamt aprint_naive("\n");
165 1.6.2.2 yamt aprint_normal(": %s\n", devinfo);
166 1.6.2.2 yamt
167 1.6.2.2 yamt dict = device_properties(self);
168 1.6.2.2 yamt prop_dictionary_get_bool(dict, "is_console", &is_console);
169 1.6.2.2 yamt #ifndef WCFB_DEBUG
170 1.6.2.2 yamt if (!is_console) return;
171 1.6.2.2 yamt #endif
172 1.6.2.2 yamt sc->sc_memt = pa->pa_memt;
173 1.6.2.2 yamt sc->sc_iot = pa->pa_iot;
174 1.6.2.2 yamt sc->sc_pc = pa->pa_pc;
175 1.6.2.2 yamt sc->sc_pcitag = pa->pa_tag;
176 1.6.2.2 yamt
177 1.6.2.2 yamt if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_MEM, 0,
178 1.6.2.2 yamt &sc->sc_regt, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
179 1.6.2.2 yamt aprint_error("%s: failed to map registers.\n",
180 1.6.2.2 yamt device_xname(sc->sc_dev));
181 1.6.2.2 yamt }
182 1.6.2.2 yamt
183 1.6.2.2 yamt if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
184 1.6.2.2 yamt &sc->sc_memt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
185 1.6.2.2 yamt aprint_error("%s: failed to map framebuffer.\n",
186 1.6.2.2 yamt device_xname(sc->sc_dev));
187 1.6.2.2 yamt }
188 1.6.2.2 yamt
189 1.6.2.2 yamt if (pci_mapreg_map(pa, 0x18, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
190 1.6.2.2 yamt &sc->sc_wtft, &sc->sc_wtfh, &sc->sc_wtf, &sc->sc_wtfsize)) {
191 1.6.2.2 yamt aprint_error("%s: failed to map wtf.\n",
192 1.6.2.2 yamt device_xname(sc->sc_dev));
193 1.6.2.2 yamt }
194 1.6.2.2 yamt wtf = bus_space_vaddr(sc->sc_wtft, sc->sc_wtfh);
195 1.6.2.2 yamt memset(wtf, 0, 0x100000);
196 1.6.2.2 yamt
197 1.6.2.2 yamt sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
198 1.6.2.2 yamt
199 1.6.2.2 yamt sc->sc_fb0off =
200 1.6.2.2 yamt bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_FB8_ADDR0) - sc->sc_fb;
201 1.6.2.2 yamt sc->sc_fb0 = sc->sc_fbaddr + sc->sc_fb0off;
202 1.6.2.2 yamt sc->sc_fb1off =
203 1.6.2.2 yamt bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_FB8_ADDR1) - sc->sc_fb;
204 1.6.2.2 yamt sc->sc_fb1 = sc->sc_fbaddr + sc->sc_fb1off;
205 1.6.2.2 yamt
206 1.6.2.2 yamt reg = bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_RESOLUTION);
207 1.6.2.2 yamt sc->sc_height = (reg >> 16) + 1;
208 1.6.2.2 yamt sc->sc_width = (reg & 0xffff) + 1;
209 1.6.2.2 yamt sc->sc_stride = 1 <<
210 1.6.2.2 yamt ((bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_CONFIG) &
211 1.6.2.2 yamt 0x00ff0000) >> 16);
212 1.6.2.2 yamt printf("%s: %d x %d, %d\n", device_xname(sc->sc_dev),
213 1.6.2.2 yamt sc->sc_width, sc->sc_height, sc->sc_stride);
214 1.6.2.2 yamt
215 1.6.2.2 yamt sc->sc_shadow = kmem_alloc(sc->sc_stride * sc->sc_height, KM_SLEEP);
216 1.6.2.2 yamt if (sc->sc_shadow == NULL) {
217 1.6.2.2 yamt printf("%s: failed to allocate shadow buffer\n",
218 1.6.2.2 yamt device_xname(self));
219 1.6.2.2 yamt return;
220 1.6.2.2 yamt }
221 1.6.2.2 yamt
222 1.6.2.2 yamt for (i = 0x40; i < 0x100; i += 16) {
223 1.6.2.2 yamt printf("%04x:", i);
224 1.6.2.2 yamt for (j = 0; j < 16; j += 4) {
225 1.6.2.2 yamt printf(" %08x", bus_space_read_4(sc->sc_regt,
226 1.6.2.2 yamt sc->sc_regh, 0x8000 + i + j));
227 1.6.2.2 yamt }
228 1.6.2.2 yamt printf("\n");
229 1.6.2.2 yamt }
230 1.6.2.2 yamt
231 1.6.2.2 yamt /* make sure video output is on */
232 1.6.2.2 yamt bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_DPMS_STATE, WC_DPMS_ON);
233 1.6.2.2 yamt
234 1.6.2.2 yamt sc->sc_defaultscreen_descr = (struct wsscreen_descr){
235 1.6.2.2 yamt "default",
236 1.6.2.2 yamt 0, 0,
237 1.6.2.2 yamt NULL,
238 1.6.2.2 yamt 8, 16,
239 1.6.2.2 yamt WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
240 1.6.2.2 yamt NULL
241 1.6.2.2 yamt };
242 1.6.2.2 yamt sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
243 1.6.2.2 yamt sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
244 1.6.2.2 yamt sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
245 1.6.2.2 yamt sc->sc_locked = 0;
246 1.6.2.2 yamt
247 1.6.2.2 yamt vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
248 1.6.2.2 yamt &wcfb_accessops);
249 1.6.2.2 yamt sc->vd.init_screen = wcfb_init_screen;
250 1.6.2.2 yamt
251 1.6.2.2 yamt /* init engine here */
252 1.6.2.2 yamt #if 0
253 1.6.2.2 yamt wcfb_init(sc);
254 1.6.2.2 yamt #endif
255 1.6.2.2 yamt
256 1.6.2.2 yamt ri = &sc->sc_console_screen.scr_ri;
257 1.6.2.2 yamt
258 1.6.2.2 yamt j = 0;
259 1.6.2.2 yamt for (i = 0; i < 256; i++) {
260 1.6.2.2 yamt
261 1.6.2.2 yamt sc->sc_cmap_red[i] = rasops_cmap[j];
262 1.6.2.2 yamt sc->sc_cmap_green[i] = rasops_cmap[j + 1];
263 1.6.2.2 yamt sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
264 1.6.2.2 yamt wcfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
265 1.6.2.2 yamt rasops_cmap[j + 2]);
266 1.6.2.2 yamt j += 3;
267 1.6.2.2 yamt }
268 1.6.2.2 yamt
269 1.6.2.2 yamt if (is_console) {
270 1.6.2.2 yamt vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
271 1.6.2.2 yamt &defattr);
272 1.6.2.2 yamt sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
273 1.6.2.2 yamt
274 1.6.2.2 yamt memset(sc->sc_fb0, ri->ri_devcmap[(defattr >> 16) & 0xff],
275 1.6.2.2 yamt sc->sc_stride * sc->sc_height);
276 1.6.2.2 yamt memset(sc->sc_fb1, ri->ri_devcmap[(defattr >> 16) & 0xff],
277 1.6.2.2 yamt sc->sc_stride * sc->sc_height);
278 1.6.2.2 yamt sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
279 1.6.2.2 yamt sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
280 1.6.2.2 yamt sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
281 1.6.2.2 yamt sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
282 1.6.2.2 yamt wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
283 1.6.2.2 yamt defattr);
284 1.6.2.2 yamt vcons_replay_msgbuf(&sc->sc_console_screen);
285 1.6.2.2 yamt } else {
286 1.6.2.2 yamt /*
287 1.6.2.2 yamt * since we're not the console we can postpone the rest
288 1.6.2.2 yamt * until someone actually allocates a screen for us
289 1.6.2.2 yamt */
290 1.6.2.2 yamt memset(sc->sc_fb0, WS_DEFAULT_BG,
291 1.6.2.2 yamt sc->sc_stride * sc->sc_height);
292 1.6.2.2 yamt memset(sc->sc_fb1, WS_DEFAULT_BG,
293 1.6.2.2 yamt sc->sc_stride * sc->sc_height);
294 1.6.2.2 yamt return;
295 1.6.2.2 yamt }
296 1.6.2.2 yamt
297 1.6.2.2 yamt aa.console = is_console;
298 1.6.2.2 yamt aa.scrdata = &sc->sc_screenlist;
299 1.6.2.2 yamt aa.accessops = &wcfb_accessops;
300 1.6.2.2 yamt aa.accesscookie = &sc->vd;
301 1.6.2.2 yamt
302 1.6.2.2 yamt config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
303 1.6.2.2 yamt }
304 1.6.2.2 yamt
305 1.6.2.2 yamt static int
306 1.6.2.2 yamt wcfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
307 1.6.2.2 yamt struct lwp *l)
308 1.6.2.2 yamt {
309 1.6.2.2 yamt struct wcfb_softc *sc = v;
310 1.6.2.2 yamt
311 1.6.2.2 yamt switch (cmd) {
312 1.6.2.2 yamt case WSDISPLAYIO_GTYPE:
313 1.6.2.2 yamt *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
314 1.6.2.2 yamt return 0;
315 1.6.2.2 yamt
316 1.6.2.2 yamt /* PCI config read/write passthrough. */
317 1.6.2.2 yamt case PCI_IOC_CFGREAD:
318 1.6.2.2 yamt case PCI_IOC_CFGWRITE:
319 1.6.2.2 yamt return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
320 1.6.2.2 yamt cmd, data, flag, l));
321 1.6.2.2 yamt case WSDISPLAYIO_SMODE:
322 1.6.2.2 yamt {
323 1.6.2.2 yamt /*int new_mode = *(int*)data, i;*/
324 1.6.2.2 yamt }
325 1.6.2.2 yamt return 0;
326 1.6.2.2 yamt }
327 1.6.2.2 yamt
328 1.6.2.2 yamt return EPASSTHROUGH;
329 1.6.2.2 yamt }
330 1.6.2.2 yamt
331 1.6.2.2 yamt static paddr_t
332 1.6.2.2 yamt wcfb_mmap(void *v, void *vs, off_t offset, int prot)
333 1.6.2.2 yamt {
334 1.6.2.2 yamt struct wcfb_softc *sc = v;
335 1.6.2.2 yamt
336 1.6.2.2 yamt /* no point in allowing a wsfb map if we can't provide one */
337 1.6.2.2 yamt /*
338 1.6.2.2 yamt * restrict all other mappings to processes with superuser privileges
339 1.6.2.2 yamt * or the kernel itself
340 1.6.2.2 yamt */
341 1.6.2.2 yamt if (kauth_authorize_generic(kauth_cred_get(), KAUTH_GENERIC_ISSUSER,
342 1.6.2.2 yamt NULL) != 0) {
343 1.6.2.2 yamt aprint_normal_dev(sc->sc_dev, "mmap() rejected.\n");
344 1.6.2.2 yamt return -1;
345 1.6.2.2 yamt }
346 1.6.2.2 yamt
347 1.6.2.2 yamt #ifdef WSFB_FAKE_VGA_FB
348 1.6.2.2 yamt if ((offset >= 0xa0000) && (offset < 0xbffff)) {
349 1.6.2.2 yamt
350 1.6.2.2 yamt return bus_space_mmap(sc->sc_memt, sc->sc_gen.sc_fboffset,
351 1.6.2.2 yamt offset - 0xa0000, prot, BUS_SPACE_MAP_LINEAR);
352 1.6.2.2 yamt }
353 1.6.2.2 yamt #endif
354 1.6.2.2 yamt
355 1.6.2.2 yamt return -1;
356 1.6.2.2 yamt }
357 1.6.2.2 yamt
358 1.6.2.2 yamt static void
359 1.6.2.2 yamt wcfb_init_screen(void *cookie, struct vcons_screen *scr,
360 1.6.2.2 yamt int existing, long *defattr)
361 1.6.2.2 yamt {
362 1.6.2.2 yamt struct wcfb_softc *sc = cookie;
363 1.6.2.2 yamt struct rasops_info *ri = &scr->scr_ri;
364 1.6.2.2 yamt
365 1.6.2.2 yamt ri->ri_depth = 8;
366 1.6.2.2 yamt ri->ri_width = sc->sc_width;
367 1.6.2.2 yamt ri->ri_height = sc->sc_height;
368 1.6.2.2 yamt ri->ri_stride = sc->sc_stride;
369 1.6.2.2 yamt ri->ri_flg = RI_CENTER /*| RI_FULLCLEAR*/;
370 1.6.2.2 yamt
371 1.6.2.2 yamt ri->ri_bits = sc->sc_shadow;
372 1.6.2.2 yamt
373 1.6.2.2 yamt if (existing) {
374 1.6.2.2 yamt ri->ri_flg |= RI_CLEAR;
375 1.6.2.2 yamt }
376 1.6.2.2 yamt
377 1.6.2.2 yamt rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
378 1.6.2.2 yamt ri->ri_caps = WSSCREEN_WSCOLORS;
379 1.6.2.2 yamt
380 1.6.2.2 yamt rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
381 1.6.2.2 yamt sc->sc_width / ri->ri_font->fontwidth);
382 1.6.2.2 yamt
383 1.6.2.2 yamt ri->ri_hw = scr;
384 1.6.2.2 yamt sc->putchar = ri->ri_ops.putchar;
385 1.6.2.2 yamt sc->copyrows = ri->ri_ops.copyrows;
386 1.6.2.2 yamt sc->eraserows = ri->ri_ops.eraserows;
387 1.6.2.2 yamt sc->copycols = ri->ri_ops.copycols;
388 1.6.2.2 yamt sc->erasecols = ri->ri_ops.erasecols;
389 1.6.2.2 yamt
390 1.6.2.2 yamt ri->ri_ops.copyrows = wcfb_copyrows;
391 1.6.2.2 yamt ri->ri_ops.copycols = wcfb_copycols;
392 1.6.2.2 yamt ri->ri_ops.eraserows = wcfb_eraserows;
393 1.6.2.2 yamt ri->ri_ops.erasecols = wcfb_erasecols;
394 1.6.2.2 yamt ri->ri_ops.putchar = wcfb_putchar;
395 1.6.2.2 yamt ri->ri_ops.cursor = wcfb_cursor;
396 1.6.2.2 yamt }
397 1.6.2.2 yamt
398 1.6.2.2 yamt static void
399 1.6.2.2 yamt wcfb_putchar(void *cookie, int row, int col, u_int c, long attr)
400 1.6.2.2 yamt {
401 1.6.2.2 yamt struct rasops_info *ri = cookie;
402 1.6.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
403 1.6.2.2 yamt struct wcfb_softc *sc = scr->scr_cookie;
404 1.6.2.2 yamt int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
405 1.6.2.2 yamt sc->sc_stride + ri->ri_xorigin + col * ri->ri_font->fontwidth;
406 1.6.2.2 yamt uint8_t *from, *to0, *to1;
407 1.6.2.2 yamt int i;
408 1.6.2.2 yamt
409 1.6.2.2 yamt sc->putchar(ri, row, col, c, attr);
410 1.6.2.2 yamt from = sc->sc_shadow + offset;
411 1.6.2.2 yamt to0 = sc->sc_fb0 + offset;
412 1.6.2.2 yamt to1 = sc->sc_fb1 + offset;
413 1.6.2.2 yamt for (i = 0; i < ri->ri_font->fontheight; i++) {
414 1.6.2.2 yamt memcpy(to0, from, ri->ri_font->fontwidth);
415 1.6.2.2 yamt memcpy(to1, from, ri->ri_font->fontwidth);
416 1.6.2.2 yamt to0 += sc->sc_stride;
417 1.6.2.2 yamt to1 += sc->sc_stride;
418 1.6.2.2 yamt from += sc->sc_stride;
419 1.6.2.2 yamt }
420 1.6.2.2 yamt }
421 1.6.2.2 yamt
422 1.6.2.2 yamt static void
423 1.6.2.2 yamt wcfb_putpalreg(struct wcfb_softc *sc, int i, int r, int g, int b)
424 1.6.2.2 yamt {
425 1.6.2.2 yamt uint32_t rgb;
426 1.6.2.2 yamt
427 1.6.2.2 yamt bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_INDEX, i);
428 1.6.2.2 yamt rgb = (b << 22) | (g << 12) | (r << 2);
429 1.6.2.2 yamt bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_DATA, rgb);
430 1.6.2.2 yamt }
431 1.6.2.2 yamt
432 1.6.2.2 yamt static void
433 1.6.2.2 yamt wcfb_cursor(void *cookie, int on, int row, int col)
434 1.6.2.2 yamt {
435 1.6.2.2 yamt struct rasops_info *ri = cookie;
436 1.6.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
437 1.6.2.2 yamt struct wcfb_softc *sc = scr->scr_cookie;
438 1.6.2.2 yamt int coffset;
439 1.6.2.2 yamt
440 1.6.2.2 yamt if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
441 1.6.2.2 yamt
442 1.6.2.2 yamt if (ri->ri_flg & RI_CURSOR) {
443 1.6.2.2 yamt /* remove cursor */
444 1.6.2.2 yamt coffset = ri->ri_ccol + (ri->ri_crow * ri->ri_cols);
445 1.6.2.2 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
446 1.6.2.2 yamt coffset += scr->scr_offset_to_zero;
447 1.6.2.2 yamt #endif
448 1.6.2.2 yamt wcfb_putchar(cookie, ri->ri_crow,
449 1.6.2.2 yamt ri->ri_ccol, scr->scr_chars[coffset],
450 1.6.2.2 yamt scr->scr_attrs[coffset]);
451 1.6.2.2 yamt ri->ri_flg &= ~RI_CURSOR;
452 1.6.2.2 yamt }
453 1.6.2.2 yamt ri->ri_crow = row;
454 1.6.2.2 yamt ri->ri_ccol = col;
455 1.6.2.2 yamt if (on) {
456 1.6.2.2 yamt long attr, revattr;
457 1.6.2.2 yamt coffset = col + (row * ri->ri_cols);
458 1.6.2.2 yamt #ifdef WSDISPLAY_SCROLLSUPPORT
459 1.6.2.2 yamt coffset += scr->scr_offset_to_zero;
460 1.6.2.2 yamt #endif
461 1.6.2.2 yamt attr = scr->scr_attrs[coffset];
462 1.6.2.2 yamt revattr = attr ^ 0xffff0000;
463 1.6.2.2 yamt
464 1.6.2.2 yamt wcfb_putchar(cookie, ri->ri_crow, ri->ri_ccol,
465 1.6.2.2 yamt scr->scr_chars[coffset], revattr);
466 1.6.2.2 yamt ri->ri_flg |= RI_CURSOR;
467 1.6.2.2 yamt }
468 1.6.2.2 yamt } else {
469 1.6.2.2 yamt ri->ri_crow = row;
470 1.6.2.2 yamt ri->ri_ccol = col;
471 1.6.2.2 yamt ri->ri_flg &= ~RI_CURSOR;
472 1.6.2.2 yamt }
473 1.6.2.2 yamt }
474 1.6.2.2 yamt
475 1.6.2.2 yamt static void
476 1.6.2.2 yamt wcfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
477 1.6.2.2 yamt {
478 1.6.2.2 yamt struct rasops_info *ri = cookie;
479 1.6.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
480 1.6.2.2 yamt struct wcfb_softc *sc = scr->scr_cookie;
481 1.6.2.2 yamt int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
482 1.6.2.2 yamt sc->sc_stride + ri->ri_xorigin + dstcol * ri->ri_font->fontwidth;
483 1.6.2.2 yamt uint8_t *from, *to0, *to1;
484 1.6.2.2 yamt int i;
485 1.6.2.2 yamt
486 1.6.2.2 yamt sc->copycols(ri, row, srccol, dstcol, ncols);
487 1.6.2.2 yamt from = sc->sc_shadow + offset;
488 1.6.2.2 yamt to0 = sc->sc_fb0 + offset;
489 1.6.2.2 yamt to1 = sc->sc_fb1 + offset;
490 1.6.2.2 yamt for (i = 0; i < ri->ri_font->fontheight; i++) {
491 1.6.2.2 yamt memcpy(to0, from, ri->ri_font->fontwidth * ncols);
492 1.6.2.2 yamt memcpy(to1, from, ri->ri_font->fontwidth * ncols);
493 1.6.2.2 yamt to0 += sc->sc_stride;
494 1.6.2.2 yamt to1 += sc->sc_stride;
495 1.6.2.2 yamt from += sc->sc_stride;
496 1.6.2.2 yamt }
497 1.6.2.2 yamt }
498 1.6.2.2 yamt
499 1.6.2.2 yamt static void
500 1.6.2.2 yamt wcfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
501 1.6.2.2 yamt {
502 1.6.2.2 yamt struct rasops_info *ri = cookie;
503 1.6.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
504 1.6.2.2 yamt struct wcfb_softc *sc = scr->scr_cookie;
505 1.6.2.2 yamt int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
506 1.6.2.2 yamt sc->sc_stride + ri->ri_xorigin + startcol * ri->ri_font->fontwidth;
507 1.6.2.2 yamt uint8_t *to0, *to1;
508 1.6.2.2 yamt int i;
509 1.6.2.2 yamt
510 1.6.2.2 yamt sc->erasecols(ri, row, startcol, ncols, fillattr);
511 1.6.2.2 yamt
512 1.6.2.2 yamt to0 = sc->sc_fb0 + offset;
513 1.6.2.2 yamt to1 = sc->sc_fb1 + offset;
514 1.6.2.2 yamt for (i = 0; i < ri->ri_font->fontheight; i++) {
515 1.6.2.2 yamt memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
516 1.6.2.2 yamt ri->ri_font->fontwidth * ncols);
517 1.6.2.2 yamt memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
518 1.6.2.2 yamt ri->ri_font->fontwidth * ncols);
519 1.6.2.2 yamt to0 += sc->sc_stride;
520 1.6.2.2 yamt to1 += sc->sc_stride;
521 1.6.2.2 yamt }
522 1.6.2.2 yamt }
523 1.6.2.2 yamt
524 1.6.2.2 yamt static void
525 1.6.2.2 yamt wcfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
526 1.6.2.2 yamt {
527 1.6.2.2 yamt struct rasops_info *ri = cookie;
528 1.6.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
529 1.6.2.2 yamt struct wcfb_softc *sc = scr->scr_cookie;
530 1.6.2.2 yamt int offset = (ri->ri_yorigin + dstrow * ri->ri_font->fontheight) *
531 1.6.2.2 yamt sc->sc_stride + ri->ri_xorigin;
532 1.6.2.2 yamt uint8_t *from, *to0, *to1;
533 1.6.2.2 yamt int i;
534 1.6.2.2 yamt
535 1.6.2.2 yamt sc->copyrows(ri, srcrow, dstrow, nrows);
536 1.6.2.2 yamt
537 1.6.2.2 yamt from = sc->sc_shadow + offset;
538 1.6.2.2 yamt to0 = sc->sc_fb0 + offset;
539 1.6.2.2 yamt to1 = sc->sc_fb1 + offset;
540 1.6.2.2 yamt for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
541 1.6.2.2 yamt memcpy(to0, from, ri->ri_emuwidth);
542 1.6.2.2 yamt memcpy(to1, from, ri->ri_emuwidth);
543 1.6.2.2 yamt to0 += sc->sc_stride;
544 1.6.2.2 yamt to1 += sc->sc_stride;
545 1.6.2.2 yamt from += sc->sc_stride;
546 1.6.2.2 yamt }
547 1.6.2.2 yamt }
548 1.6.2.2 yamt
549 1.6.2.2 yamt static void
550 1.6.2.2 yamt wcfb_eraserows(void *cookie, int row, int nrows, long fillattr)
551 1.6.2.2 yamt {
552 1.6.2.2 yamt struct rasops_info *ri = cookie;
553 1.6.2.2 yamt struct vcons_screen *scr = ri->ri_hw;
554 1.6.2.2 yamt struct wcfb_softc *sc = scr->scr_cookie;
555 1.6.2.2 yamt int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
556 1.6.2.2 yamt sc->sc_stride + ri->ri_xorigin;
557 1.6.2.2 yamt uint8_t *to0, *to1;
558 1.6.2.2 yamt int i;
559 1.6.2.2 yamt
560 1.6.2.2 yamt sc->eraserows(ri, row, nrows, fillattr);
561 1.6.2.2 yamt
562 1.6.2.2 yamt to0 = sc->sc_fb0 + offset;
563 1.6.2.2 yamt to1 = sc->sc_fb1 + offset;
564 1.6.2.2 yamt for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
565 1.6.2.2 yamt memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
566 1.6.2.2 yamt ri->ri_emuwidth);
567 1.6.2.2 yamt memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
568 1.6.2.2 yamt ri->ri_emuwidth);
569 1.6.2.2 yamt to0 += sc->sc_stride;
570 1.6.2.2 yamt to1 += sc->sc_stride;
571 1.6.2.2 yamt }
572 1.6.2.2 yamt }
573