r128fb.c revision 1.1.2.2 1 1.1.2.2 joerg /* $NetBSD: r128fb.c,v 1.1.2.2 2007/11/11 16:47:43 joerg Exp $ */
2 1.1.2.2 joerg
3 1.1.2.2 joerg /*
4 1.1.2.2 joerg * Copyright (c) 2007 Michael Lorenz
5 1.1.2.2 joerg * All rights reserved.
6 1.1.2.2 joerg *
7 1.1.2.2 joerg * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 joerg * modification, are permitted provided that the following conditions
9 1.1.2.2 joerg * are met:
10 1.1.2.2 joerg * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 joerg * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 joerg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 joerg * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 joerg * documentation and/or other materials provided with the distribution.
15 1.1.2.2 joerg * 3. The name of the author may not be used to endorse or promote products
16 1.1.2.2 joerg * derived from this software without specific prior written permission.
17 1.1.2.2 joerg *
18 1.1.2.2 joerg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1.2.2 joerg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1.2.2 joerg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1.2.2 joerg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1.2.2 joerg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1.2.2 joerg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1.2.2 joerg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1.2.2 joerg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1.2.2 joerg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1.2.2 joerg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 joerg */
29 1.1.2.2 joerg
30 1.1.2.2 joerg /*
31 1.1.2.2 joerg * A console driver for ATI Rage 128 graphics controllers
32 1.1.2.2 joerg * tested on macppc only so far
33 1.1.2.2 joerg */
34 1.1.2.2 joerg
35 1.1.2.2 joerg #include <sys/cdefs.h>
36 1.1.2.2 joerg __KERNEL_RCSID(0, "$NetBSD: r128fb.c,v 1.1.2.2 2007/11/11 16:47:43 joerg Exp $");
37 1.1.2.2 joerg
38 1.1.2.2 joerg #include <sys/param.h>
39 1.1.2.2 joerg #include <sys/systm.h>
40 1.1.2.2 joerg #include <sys/kernel.h>
41 1.1.2.2 joerg #include <sys/device.h>
42 1.1.2.2 joerg #include <sys/malloc.h>
43 1.1.2.2 joerg #include <sys/lwp.h>
44 1.1.2.2 joerg #include <sys/kauth.h>
45 1.1.2.2 joerg
46 1.1.2.2 joerg #include <uvm/uvm_extern.h>
47 1.1.2.2 joerg
48 1.1.2.2 joerg #include <dev/videomode/videomode.h>
49 1.1.2.2 joerg
50 1.1.2.2 joerg #include <dev/pci/pcivar.h>
51 1.1.2.2 joerg #include <dev/pci/pcireg.h>
52 1.1.2.2 joerg #include <dev/pci/pcidevs.h>
53 1.1.2.2 joerg #include <dev/pci/pciio.h>
54 1.1.2.2 joerg #include <dev/pci/r128fbreg.h>
55 1.1.2.2 joerg
56 1.1.2.2 joerg #include <dev/wscons/wsdisplayvar.h>
57 1.1.2.2 joerg #include <dev/wscons/wsconsio.h>
58 1.1.2.2 joerg #include <dev/wsfont/wsfont.h>
59 1.1.2.2 joerg #include <dev/rasops/rasops.h>
60 1.1.2.2 joerg #include <dev/wscons/wsdisplay_vconsvar.h>
61 1.1.2.2 joerg
62 1.1.2.2 joerg #include <dev/i2c/i2cvar.h>
63 1.1.2.2 joerg
64 1.1.2.2 joerg struct r128fb_softc {
65 1.1.2.2 joerg device_t sc_dev;
66 1.1.2.2 joerg
67 1.1.2.2 joerg pci_chipset_tag_t sc_pc;
68 1.1.2.2 joerg pcitag_t sc_pcitag;
69 1.1.2.2 joerg
70 1.1.2.2 joerg bus_space_tag_t sc_memt;
71 1.1.2.2 joerg bus_space_tag_t sc_iot;
72 1.1.2.2 joerg
73 1.1.2.2 joerg bus_space_handle_t sc_fbh;
74 1.1.2.2 joerg bus_space_handle_t sc_regh;
75 1.1.2.2 joerg bus_addr_t sc_fb, sc_reg;
76 1.1.2.2 joerg bus_size_t sc_fbsize, sc_regsize;
77 1.1.2.2 joerg
78 1.1.2.2 joerg int sc_width, sc_height, sc_depth, sc_stride;
79 1.1.2.2 joerg int sc_locked;
80 1.1.2.2 joerg void *sc_fbaddr;
81 1.1.2.2 joerg struct vcons_screen sc_console_screen;
82 1.1.2.2 joerg struct wsscreen_descr sc_defaultscreen_descr;
83 1.1.2.2 joerg const struct wsscreen_descr *sc_screens[1];
84 1.1.2.2 joerg struct wsscreen_list sc_screenlist;
85 1.1.2.2 joerg struct vcons_data vd;
86 1.1.2.2 joerg int sc_mode;
87 1.1.2.2 joerg u_char sc_cmap_red[256];
88 1.1.2.2 joerg u_char sc_cmap_green[256];
89 1.1.2.2 joerg u_char sc_cmap_blue[256];
90 1.1.2.2 joerg /* engine stuff */
91 1.1.2.2 joerg uint32_t sc_master_cntl;
92 1.1.2.2 joerg };
93 1.1.2.2 joerg
94 1.1.2.2 joerg static int r128fb_match(device_t, cfdata_t, void *);
95 1.1.2.2 joerg static void r128fb_attach(device_t, device_t, void *);
96 1.1.2.2 joerg
97 1.1.2.2 joerg CFATTACH_DECL_NEW(r128fb, sizeof(struct r128fb_softc),
98 1.1.2.2 joerg r128fb_match, r128fb_attach, NULL, NULL);
99 1.1.2.2 joerg
100 1.1.2.2 joerg extern const u_char rasops_cmap[768];
101 1.1.2.2 joerg
102 1.1.2.2 joerg static int r128fb_ioctl(void *, void *, u_long, void *, int,
103 1.1.2.2 joerg struct lwp *);
104 1.1.2.2 joerg static paddr_t r128fb_mmap(void *, void *, off_t, int);
105 1.1.2.2 joerg static void r128fb_init_screen(void *, struct vcons_screen *, int, long *);
106 1.1.2.2 joerg
107 1.1.2.2 joerg static int r128fb_putcmap(struct r128fb_softc *, struct wsdisplay_cmap *);
108 1.1.2.2 joerg static int r128fb_getcmap(struct r128fb_softc *, struct wsdisplay_cmap *);
109 1.1.2.2 joerg static void r128fb_restore_palette(struct r128fb_softc *);
110 1.1.2.2 joerg static int r128fb_putpalreg(struct r128fb_softc *, uint8_t, uint8_t,
111 1.1.2.2 joerg uint8_t, uint8_t);
112 1.1.2.2 joerg
113 1.1.2.2 joerg static void r128fb_init(struct r128fb_softc *);
114 1.1.2.2 joerg static void r128fb_flush_engine(struct r128fb_softc *);
115 1.1.2.2 joerg static void r128fb_rectfill(struct r128fb_softc *, int, int, int, int,
116 1.1.2.2 joerg uint32_t);
117 1.1.2.2 joerg static void r128fb_bitblt(struct r128fb_softc *, int, int, int, int, int,
118 1.1.2.2 joerg int, int);
119 1.1.2.2 joerg
120 1.1.2.2 joerg static void r128fb_cursor(void *, int, int, int);
121 1.1.2.2 joerg #if 0
122 1.1.2.2 joerg static void r128fb_putchar(void *, int, int, u_int, long);
123 1.1.2.2 joerg #endif
124 1.1.2.2 joerg static void r128fb_copycols(void *, int, int, int, int);
125 1.1.2.2 joerg static void r128fb_erasecols(void *, int, int, int, long);
126 1.1.2.2 joerg static void r128fb_copyrows(void *, int, int, int);
127 1.1.2.2 joerg static void r128fb_eraserows(void *, int, int, long);
128 1.1.2.2 joerg
129 1.1.2.2 joerg struct wsdisplay_accessops r128fb_accessops = {
130 1.1.2.2 joerg r128fb_ioctl,
131 1.1.2.2 joerg r128fb_mmap,
132 1.1.2.2 joerg NULL, /* alloc_screen */
133 1.1.2.2 joerg NULL, /* free_screen */
134 1.1.2.2 joerg NULL, /* show_screen */
135 1.1.2.2 joerg NULL, /* load_font */
136 1.1.2.2 joerg NULL, /* pollc */
137 1.1.2.2 joerg NULL /* scroll */
138 1.1.2.2 joerg };
139 1.1.2.2 joerg
140 1.1.2.2 joerg static inline void
141 1.1.2.2 joerg r128fb_wait(struct r128fb_softc *sc, int slots)
142 1.1.2.2 joerg {
143 1.1.2.2 joerg uint32_t reg;
144 1.1.2.2 joerg
145 1.1.2.2 joerg do {
146 1.1.2.2 joerg reg = (bus_space_read_4(sc->sc_memt, sc->sc_regh,
147 1.1.2.2 joerg R128_GUI_STAT) & R128_GUI_FIFOCNT_MASK);
148 1.1.2.2 joerg } while (reg <= slots);
149 1.1.2.2 joerg }
150 1.1.2.2 joerg
151 1.1.2.2 joerg static void
152 1.1.2.2 joerg r128fb_flush_engine(struct r128fb_softc *sc)
153 1.1.2.2 joerg {
154 1.1.2.2 joerg uint32_t reg;
155 1.1.2.2 joerg
156 1.1.2.2 joerg reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, R128_PC_NGUI_CTLSTAT);
157 1.1.2.2 joerg reg |= R128_PC_FLUSH_ALL;
158 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_PC_NGUI_CTLSTAT, reg);
159 1.1.2.2 joerg do {
160 1.1.2.2 joerg reg = bus_space_read_4(sc->sc_memt, sc->sc_regh,
161 1.1.2.2 joerg R128_PC_NGUI_CTLSTAT);
162 1.1.2.2 joerg } while (reg & R128_PC_BUSY);
163 1.1.2.2 joerg }
164 1.1.2.2 joerg
165 1.1.2.2 joerg static int
166 1.1.2.2 joerg r128fb_match(device_t parent, cfdata_t match, void *aux)
167 1.1.2.2 joerg {
168 1.1.2.2 joerg struct pci_attach_args *pa = (struct pci_attach_args *)aux;
169 1.1.2.2 joerg
170 1.1.2.2 joerg if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
171 1.1.2.2 joerg PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
172 1.1.2.2 joerg return 0;
173 1.1.2.2 joerg if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_ATI)
174 1.1.2.2 joerg return 0;
175 1.1.2.2 joerg
176 1.1.2.2 joerg /* only card tested on so far - likely need a list */
177 1.1.2.2 joerg if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ATI_RAGE1AGP4XT)
178 1.1.2.2 joerg return 100;
179 1.1.2.2 joerg return (0);
180 1.1.2.2 joerg }
181 1.1.2.2 joerg
182 1.1.2.2 joerg static void
183 1.1.2.2 joerg r128fb_attach(device_t parent, device_t self, void *aux)
184 1.1.2.2 joerg {
185 1.1.2.2 joerg struct r128fb_softc *sc = device_private(self);
186 1.1.2.2 joerg struct pci_attach_args *pa = aux;
187 1.1.2.2 joerg struct rasops_info *ri;
188 1.1.2.2 joerg char devinfo[256];
189 1.1.2.2 joerg struct wsemuldisplaydev_attach_args aa;
190 1.1.2.2 joerg prop_dictionary_t dict;
191 1.1.2.2 joerg unsigned long defattr;
192 1.1.2.2 joerg bool is_console;
193 1.1.2.2 joerg int i, j;
194 1.1.2.2 joerg
195 1.1.2.2 joerg sc->sc_pc = pa->pa_pc;
196 1.1.2.2 joerg sc->sc_pcitag = pa->pa_tag;
197 1.1.2.2 joerg sc->sc_memt = pa->pa_memt;
198 1.1.2.2 joerg sc->sc_iot = pa->pa_iot;
199 1.1.2.2 joerg sc->sc_dev = self;
200 1.1.2.2 joerg
201 1.1.2.2 joerg pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
202 1.1.2.2 joerg aprint_normal(": %s\n", devinfo);
203 1.1.2.2 joerg
204 1.1.2.2 joerg /* fill in parameters from properties */
205 1.1.2.2 joerg dict = device_properties(self);
206 1.1.2.2 joerg if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width)) {
207 1.1.2.2 joerg aprint_error("%s: no width property\n", device_xname(self));
208 1.1.2.2 joerg return;
209 1.1.2.2 joerg }
210 1.1.2.2 joerg if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height)) {
211 1.1.2.2 joerg aprint_error("%s: no height property\n", device_xname(self));
212 1.1.2.2 joerg return;
213 1.1.2.2 joerg }
214 1.1.2.2 joerg if (!prop_dictionary_get_uint32(dict, "depth", &sc->sc_depth)) {
215 1.1.2.2 joerg aprint_error("%s: no depth property\n", device_xname(self));
216 1.1.2.2 joerg return;
217 1.1.2.2 joerg }
218 1.1.2.2 joerg if (!prop_dictionary_get_uint32(dict, "linebytes", &sc->sc_stride)) {
219 1.1.2.2 joerg aprint_error("%s: no linebytes property\n",
220 1.1.2.2 joerg device_xname(self));
221 1.1.2.2 joerg return;
222 1.1.2.2 joerg }
223 1.1.2.2 joerg
224 1.1.2.2 joerg prop_dictionary_get_bool(dict, "is_console", &is_console);
225 1.1.2.2 joerg
226 1.1.2.2 joerg if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM,
227 1.1.2.2 joerg BUS_SPACE_MAP_LINEAR,
228 1.1.2.2 joerg &sc->sc_memt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
229 1.1.2.2 joerg aprint_error("%s: failed to map the frame buffer.\n",
230 1.1.2.2 joerg device_xname(sc->sc_dev));
231 1.1.2.2 joerg }
232 1.1.2.2 joerg sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
233 1.1.2.2 joerg
234 1.1.2.2 joerg if (pci_mapreg_map(pa, 0x18, PCI_MAPREG_TYPE_MEM, 0,
235 1.1.2.2 joerg &sc->sc_memt, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
236 1.1.2.2 joerg aprint_error("%s: failed to map registers.\n",
237 1.1.2.2 joerg device_xname(sc->sc_dev));
238 1.1.2.2 joerg }
239 1.1.2.2 joerg
240 1.1.2.2 joerg aprint_normal("%s: %d MB aperture at 0x%08x\n", device_xname(self),
241 1.1.2.2 joerg (sc->sc_fbsize >> 20), sc->sc_fb);
242 1.1.2.2 joerg
243 1.1.2.2 joerg sc->sc_defaultscreen_descr = (struct wsscreen_descr){
244 1.1.2.2 joerg "default",
245 1.1.2.2 joerg 0, 0,
246 1.1.2.2 joerg NULL,
247 1.1.2.2 joerg 8, 16,
248 1.1.2.2 joerg WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
249 1.1.2.2 joerg NULL
250 1.1.2.2 joerg };
251 1.1.2.2 joerg sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
252 1.1.2.2 joerg sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
253 1.1.2.2 joerg sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
254 1.1.2.2 joerg sc->sc_locked = 0;
255 1.1.2.2 joerg
256 1.1.2.2 joerg vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
257 1.1.2.2 joerg &r128fb_accessops);
258 1.1.2.2 joerg sc->vd.init_screen = r128fb_init_screen;
259 1.1.2.2 joerg
260 1.1.2.2 joerg /* init engine here */
261 1.1.2.2 joerg r128fb_init(sc);
262 1.1.2.2 joerg
263 1.1.2.2 joerg ri = &sc->sc_console_screen.scr_ri;
264 1.1.2.2 joerg
265 1.1.2.2 joerg if (is_console) {
266 1.1.2.2 joerg vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
267 1.1.2.2 joerg &defattr);
268 1.1.2.2 joerg sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
269 1.1.2.2 joerg
270 1.1.2.2 joerg sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
271 1.1.2.2 joerg sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
272 1.1.2.2 joerg sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
273 1.1.2.2 joerg sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
274 1.1.2.2 joerg wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
275 1.1.2.2 joerg defattr);
276 1.1.2.2 joerg } else {
277 1.1.2.2 joerg /*
278 1.1.2.2 joerg * since we're not the console we can postpone the rest
279 1.1.2.2 joerg * until someone actually allocates a screen for us
280 1.1.2.2 joerg */
281 1.1.2.2 joerg (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
282 1.1.2.2 joerg }
283 1.1.2.2 joerg
284 1.1.2.2 joerg j = 0;
285 1.1.2.2 joerg for (i = 0; i < (1 << sc->sc_depth); i++) {
286 1.1.2.2 joerg
287 1.1.2.2 joerg sc->sc_cmap_red[i] = rasops_cmap[j];
288 1.1.2.2 joerg sc->sc_cmap_green[i] = rasops_cmap[j + 1];
289 1.1.2.2 joerg sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
290 1.1.2.2 joerg r128fb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
291 1.1.2.2 joerg rasops_cmap[j + 2]);
292 1.1.2.2 joerg j += 3;
293 1.1.2.2 joerg }
294 1.1.2.2 joerg
295 1.1.2.2 joerg r128fb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
296 1.1.2.2 joerg ri->ri_devcmap[(defattr >> 16) & 0xff]);
297 1.1.2.2 joerg
298 1.1.2.2 joerg aa.console = is_console;
299 1.1.2.2 joerg aa.scrdata = &sc->sc_screenlist;
300 1.1.2.2 joerg aa.accessops = &r128fb_accessops;
301 1.1.2.2 joerg aa.accesscookie = &sc->vd;
302 1.1.2.2 joerg
303 1.1.2.2 joerg config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
304 1.1.2.2 joerg
305 1.1.2.2 joerg }
306 1.1.2.2 joerg
307 1.1.2.2 joerg static int
308 1.1.2.2 joerg r128fb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
309 1.1.2.2 joerg struct lwp *l)
310 1.1.2.2 joerg {
311 1.1.2.2 joerg struct vcons_data *vd = v;
312 1.1.2.2 joerg struct r128fb_softc *sc = vd->cookie;
313 1.1.2.2 joerg struct wsdisplay_fbinfo *wdf;
314 1.1.2.2 joerg struct vcons_screen *ms = vd->active;
315 1.1.2.2 joerg
316 1.1.2.2 joerg switch (cmd) {
317 1.1.2.2 joerg
318 1.1.2.2 joerg case WSDISPLAYIO_GTYPE:
319 1.1.2.2 joerg *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
320 1.1.2.2 joerg return 0;
321 1.1.2.2 joerg
322 1.1.2.2 joerg /* PCI config read/write passthrough. */
323 1.1.2.2 joerg case PCI_IOC_CFGREAD:
324 1.1.2.2 joerg case PCI_IOC_CFGWRITE:
325 1.1.2.2 joerg return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
326 1.1.2.2 joerg cmd, data, flag, l));
327 1.1.2.2 joerg
328 1.1.2.2 joerg case WSDISPLAYIO_GINFO:
329 1.1.2.2 joerg if (ms == NULL)
330 1.1.2.2 joerg return ENODEV;
331 1.1.2.2 joerg wdf = (void *)data;
332 1.1.2.2 joerg wdf->height = ms->scr_ri.ri_height;
333 1.1.2.2 joerg wdf->width = ms->scr_ri.ri_width;
334 1.1.2.2 joerg wdf->depth = ms->scr_ri.ri_depth;
335 1.1.2.2 joerg wdf->cmsize = 256;
336 1.1.2.2 joerg return 0;
337 1.1.2.2 joerg
338 1.1.2.2 joerg case WSDISPLAYIO_GETCMAP:
339 1.1.2.2 joerg return r128fb_getcmap(sc,
340 1.1.2.2 joerg (struct wsdisplay_cmap *)data);
341 1.1.2.2 joerg
342 1.1.2.2 joerg case WSDISPLAYIO_PUTCMAP:
343 1.1.2.2 joerg return r128fb_putcmap(sc,
344 1.1.2.2 joerg (struct wsdisplay_cmap *)data);
345 1.1.2.2 joerg
346 1.1.2.2 joerg case WSDISPLAYIO_LINEBYTES:
347 1.1.2.2 joerg *(u_int *)data = sc->sc_stride;
348 1.1.2.2 joerg return 0;
349 1.1.2.2 joerg
350 1.1.2.2 joerg case WSDISPLAYIO_SMODE:
351 1.1.2.2 joerg {
352 1.1.2.2 joerg int new_mode = *(int*)data;
353 1.1.2.2 joerg
354 1.1.2.2 joerg /* notify the bus backend */
355 1.1.2.2 joerg if (new_mode != sc->sc_mode) {
356 1.1.2.2 joerg sc->sc_mode = new_mode;
357 1.1.2.2 joerg if(new_mode == WSDISPLAYIO_MODE_EMUL) {
358 1.1.2.2 joerg r128fb_restore_palette(sc);
359 1.1.2.2 joerg vcons_redraw_screen(ms);
360 1.1.2.2 joerg }
361 1.1.2.2 joerg }
362 1.1.2.2 joerg }
363 1.1.2.2 joerg return 0;
364 1.1.2.2 joerg }
365 1.1.2.2 joerg return EPASSTHROUGH;
366 1.1.2.2 joerg }
367 1.1.2.2 joerg
368 1.1.2.2 joerg static paddr_t
369 1.1.2.2 joerg r128fb_mmap(void *v, void *vs, off_t offset, int prot)
370 1.1.2.2 joerg {
371 1.1.2.2 joerg struct vcons_data *vd = v;
372 1.1.2.2 joerg struct r128fb_softc *sc = vd->cookie;
373 1.1.2.2 joerg struct lwp *me;
374 1.1.2.2 joerg paddr_t pa;
375 1.1.2.2 joerg
376 1.1.2.2 joerg /* 'regular' framebuffer mmap()ing */
377 1.1.2.2 joerg if (offset < sc->sc_fbsize) {
378 1.1.2.2 joerg pa = bus_space_mmap(sc->sc_memt, sc->sc_fb + offset, 0, prot,
379 1.1.2.2 joerg BUS_SPACE_MAP_LINEAR);
380 1.1.2.2 joerg return pa;
381 1.1.2.2 joerg }
382 1.1.2.2 joerg
383 1.1.2.2 joerg /*
384 1.1.2.2 joerg * restrict all other mappings to processes with superuser privileges
385 1.1.2.2 joerg * or the kernel itself
386 1.1.2.2 joerg */
387 1.1.2.2 joerg me = curlwp;
388 1.1.2.2 joerg if (me != NULL) {
389 1.1.2.2 joerg if (kauth_authorize_generic(me->l_cred, KAUTH_GENERIC_ISSUSER,
390 1.1.2.2 joerg NULL) != 0) {
391 1.1.2.2 joerg aprint_normal("%s: mmap() rejected.\n",
392 1.1.2.2 joerg device_xname(sc->sc_dev));
393 1.1.2.2 joerg return -1;
394 1.1.2.2 joerg }
395 1.1.2.2 joerg }
396 1.1.2.2 joerg
397 1.1.2.2 joerg if ((offset >= sc->sc_fb) && (offset < (sc->sc_fb + sc->sc_fbsize))) {
398 1.1.2.2 joerg pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
399 1.1.2.2 joerg BUS_SPACE_MAP_LINEAR);
400 1.1.2.2 joerg return pa;
401 1.1.2.2 joerg }
402 1.1.2.2 joerg
403 1.1.2.2 joerg if ((offset >= sc->sc_reg) &&
404 1.1.2.2 joerg (offset < (sc->sc_reg + sc->sc_regsize))) {
405 1.1.2.2 joerg pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
406 1.1.2.2 joerg BUS_SPACE_MAP_LINEAR);
407 1.1.2.2 joerg return pa;
408 1.1.2.2 joerg }
409 1.1.2.2 joerg
410 1.1.2.2 joerg #ifdef macppc
411 1.1.2.2 joerg /* allow mapping of IO space */
412 1.1.2.2 joerg if ((offset >= 0xf2000000) && (offset < 0xf2800000)) {
413 1.1.2.2 joerg pa = bus_space_mmap(sc->sc_iot, offset - 0xf2000000, 0, prot,
414 1.1.2.2 joerg BUS_SPACE_MAP_LINEAR);
415 1.1.2.2 joerg return pa;
416 1.1.2.2 joerg }
417 1.1.2.2 joerg #endif
418 1.1.2.2 joerg
419 1.1.2.2 joerg #ifdef OFB_ALLOW_OTHERS
420 1.1.2.2 joerg if (offset >= 0x80000000) {
421 1.1.2.2 joerg pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
422 1.1.2.2 joerg BUS_SPACE_MAP_LINEAR);
423 1.1.2.2 joerg return pa;
424 1.1.2.2 joerg }
425 1.1.2.2 joerg #endif
426 1.1.2.2 joerg return -1;
427 1.1.2.2 joerg }
428 1.1.2.2 joerg
429 1.1.2.2 joerg static void
430 1.1.2.2 joerg r128fb_init_screen(void *cookie, struct vcons_screen *scr,
431 1.1.2.2 joerg int existing, long *defattr)
432 1.1.2.2 joerg {
433 1.1.2.2 joerg struct r128fb_softc *sc = cookie;
434 1.1.2.2 joerg struct rasops_info *ri = &scr->scr_ri;
435 1.1.2.2 joerg
436 1.1.2.2 joerg ri->ri_depth = sc->sc_depth;
437 1.1.2.2 joerg ri->ri_width = sc->sc_width;
438 1.1.2.2 joerg ri->ri_height = sc->sc_height;
439 1.1.2.2 joerg ri->ri_stride = sc->sc_stride;
440 1.1.2.2 joerg ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
441 1.1.2.2 joerg
442 1.1.2.2 joerg ri->ri_bits = (char *)sc->sc_fbaddr;
443 1.1.2.2 joerg
444 1.1.2.2 joerg if (existing) {
445 1.1.2.2 joerg ri->ri_flg |= RI_CLEAR;
446 1.1.2.2 joerg }
447 1.1.2.2 joerg
448 1.1.2.2 joerg rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
449 1.1.2.2 joerg ri->ri_caps = WSSCREEN_WSCOLORS;
450 1.1.2.2 joerg
451 1.1.2.2 joerg rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
452 1.1.2.2 joerg sc->sc_width / ri->ri_font->fontwidth);
453 1.1.2.2 joerg
454 1.1.2.2 joerg ri->ri_hw = scr;
455 1.1.2.2 joerg ri->ri_ops.copyrows = r128fb_copyrows;
456 1.1.2.2 joerg ri->ri_ops.copycols = r128fb_copycols;
457 1.1.2.2 joerg ri->ri_ops.eraserows = r128fb_eraserows;
458 1.1.2.2 joerg ri->ri_ops.erasecols = r128fb_erasecols;
459 1.1.2.2 joerg ri->ri_ops.cursor = r128fb_cursor;
460 1.1.2.2 joerg #if 0
461 1.1.2.2 joerg ri->ri_ops.putchar = r128fb_putchar;
462 1.1.2.2 joerg #endif
463 1.1.2.2 joerg }
464 1.1.2.2 joerg
465 1.1.2.2 joerg static int
466 1.1.2.2 joerg r128fb_putcmap(struct r128fb_softc *sc, struct wsdisplay_cmap *cm)
467 1.1.2.2 joerg {
468 1.1.2.2 joerg u_char *r, *g, *b;
469 1.1.2.2 joerg u_int index = cm->index;
470 1.1.2.2 joerg u_int count = cm->count;
471 1.1.2.2 joerg int i, error;
472 1.1.2.2 joerg u_char rbuf[256], gbuf[256], bbuf[256];
473 1.1.2.2 joerg
474 1.1.2.2 joerg #ifdef R128FB_DEBUG
475 1.1.2.2 joerg aprint_debug("putcmap: %d %d\n",index, count);
476 1.1.2.2 joerg #endif
477 1.1.2.2 joerg if (cm->index >= 256 || cm->count > 256 ||
478 1.1.2.2 joerg (cm->index + cm->count) > 256)
479 1.1.2.2 joerg return EINVAL;
480 1.1.2.2 joerg error = copyin(cm->red, &rbuf[index], count);
481 1.1.2.2 joerg if (error)
482 1.1.2.2 joerg return error;
483 1.1.2.2 joerg error = copyin(cm->green, &gbuf[index], count);
484 1.1.2.2 joerg if (error)
485 1.1.2.2 joerg return error;
486 1.1.2.2 joerg error = copyin(cm->blue, &bbuf[index], count);
487 1.1.2.2 joerg if (error)
488 1.1.2.2 joerg return error;
489 1.1.2.2 joerg
490 1.1.2.2 joerg memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
491 1.1.2.2 joerg memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
492 1.1.2.2 joerg memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
493 1.1.2.2 joerg
494 1.1.2.2 joerg r = &sc->sc_cmap_red[index];
495 1.1.2.2 joerg g = &sc->sc_cmap_green[index];
496 1.1.2.2 joerg b = &sc->sc_cmap_blue[index];
497 1.1.2.2 joerg
498 1.1.2.2 joerg for (i = 0; i < count; i++) {
499 1.1.2.2 joerg r128fb_putpalreg(sc, index, *r, *g, *b);
500 1.1.2.2 joerg index++;
501 1.1.2.2 joerg r++, g++, b++;
502 1.1.2.2 joerg }
503 1.1.2.2 joerg return 0;
504 1.1.2.2 joerg }
505 1.1.2.2 joerg
506 1.1.2.2 joerg static int
507 1.1.2.2 joerg r128fb_getcmap(struct r128fb_softc *sc, struct wsdisplay_cmap *cm)
508 1.1.2.2 joerg {
509 1.1.2.2 joerg u_int index = cm->index;
510 1.1.2.2 joerg u_int count = cm->count;
511 1.1.2.2 joerg int error;
512 1.1.2.2 joerg
513 1.1.2.2 joerg if (index >= 255 || count > 256 || index + count > 256)
514 1.1.2.2 joerg return EINVAL;
515 1.1.2.2 joerg
516 1.1.2.2 joerg error = copyout(&sc->sc_cmap_red[index], cm->red, count);
517 1.1.2.2 joerg if (error)
518 1.1.2.2 joerg return error;
519 1.1.2.2 joerg error = copyout(&sc->sc_cmap_green[index], cm->green, count);
520 1.1.2.2 joerg if (error)
521 1.1.2.2 joerg return error;
522 1.1.2.2 joerg error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
523 1.1.2.2 joerg if (error)
524 1.1.2.2 joerg return error;
525 1.1.2.2 joerg
526 1.1.2.2 joerg return 0;
527 1.1.2.2 joerg }
528 1.1.2.2 joerg
529 1.1.2.2 joerg static void
530 1.1.2.2 joerg r128fb_restore_palette(struct r128fb_softc *sc)
531 1.1.2.2 joerg {
532 1.1.2.2 joerg int i;
533 1.1.2.2 joerg
534 1.1.2.2 joerg for (i = 0; i < (1 << sc->sc_depth); i++) {
535 1.1.2.2 joerg r128fb_putpalreg(sc, i, sc->sc_cmap_red[i],
536 1.1.2.2 joerg sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
537 1.1.2.2 joerg }
538 1.1.2.2 joerg }
539 1.1.2.2 joerg
540 1.1.2.2 joerg static int
541 1.1.2.2 joerg r128fb_putpalreg(struct r128fb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
542 1.1.2.2 joerg uint8_t b)
543 1.1.2.2 joerg {
544 1.1.2.2 joerg uint32_t reg;
545 1.1.2.2 joerg
546 1.1.2.2 joerg /* whack the DAC */
547 1.1.2.2 joerg reg = (r << 16) | (g << 8) | b;
548 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_PALETTE_INDEX, idx);
549 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_PALETTE_DATA, reg);
550 1.1.2.2 joerg return 0;
551 1.1.2.2 joerg }
552 1.1.2.2 joerg
553 1.1.2.2 joerg static void
554 1.1.2.2 joerg r128fb_init(struct r128fb_softc *sc)
555 1.1.2.2 joerg {
556 1.1.2.2 joerg uint32_t datatype;
557 1.1.2.2 joerg
558 1.1.2.2 joerg r128fb_flush_engine(sc);
559 1.1.2.2 joerg
560 1.1.2.2 joerg r128fb_wait(sc, 8);
561 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_CRTC_OFFSET, 0);
562 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DEFAULT_OFFSET, 0);
563 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DEFAULT_PITCH,
564 1.1.2.2 joerg sc->sc_stride >> 3);
565 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_AUX_SC_CNTL, 0);
566 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh,
567 1.1.2.2 joerg R128_DEFAULT_SC_BOTTOM_RIGHT,
568 1.1.2.2 joerg R128_DEFAULT_SC_RIGHT_MAX | R128_DEFAULT_SC_BOTTOM_MAX);
569 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SC_TOP_LEFT, 0);
570 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SC_BOTTOM_RIGHT,
571 1.1.2.2 joerg R128_DEFAULT_SC_RIGHT_MAX | R128_DEFAULT_SC_BOTTOM_MAX);
572 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_DATATYPE,
573 1.1.2.2 joerg R128_HOST_BIG_ENDIAN_EN);
574 1.1.2.2 joerg
575 1.1.2.2 joerg r128fb_wait(sc, 5);
576 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SRC_PITCH,
577 1.1.2.2 joerg sc->sc_stride >> 3);
578 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_PITCH,
579 1.1.2.2 joerg sc->sc_stride >> 3);
580 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SRC_OFFSET, 0);
581 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_OFFSET, 0);
582 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_WRITE_MASK,
583 1.1.2.2 joerg 0xffffffff);
584 1.1.2.2 joerg
585 1.1.2.2 joerg switch (sc->sc_depth) {
586 1.1.2.2 joerg case 8:
587 1.1.2.2 joerg datatype = R128_GMC_DST_8BPP_CI;
588 1.1.2.2 joerg break;
589 1.1.2.2 joerg case 15:
590 1.1.2.2 joerg datatype = R128_GMC_DST_15BPP;
591 1.1.2.2 joerg break;
592 1.1.2.2 joerg case 16:
593 1.1.2.2 joerg datatype = R128_GMC_DST_16BPP;
594 1.1.2.2 joerg break;
595 1.1.2.2 joerg case 24:
596 1.1.2.2 joerg datatype = R128_GMC_DST_24BPP;
597 1.1.2.2 joerg break;
598 1.1.2.2 joerg case 32:
599 1.1.2.2 joerg datatype = R128_GMC_DST_32BPP;
600 1.1.2.2 joerg break;
601 1.1.2.2 joerg default:
602 1.1.2.2 joerg aprint_error("%s: unsupported depth %d\n",
603 1.1.2.2 joerg device_xname(sc->sc_dev), sc->sc_depth);
604 1.1.2.2 joerg return;
605 1.1.2.2 joerg }
606 1.1.2.2 joerg sc->sc_master_cntl = R128_GMC_CLR_CMP_CNTL_DIS |
607 1.1.2.2 joerg R128_GMC_AUX_CLIP_DIS | datatype;
608 1.1.2.2 joerg
609 1.1.2.2 joerg r128fb_flush_engine(sc);
610 1.1.2.2 joerg }
611 1.1.2.2 joerg
612 1.1.2.2 joerg static void
613 1.1.2.2 joerg r128fb_rectfill(struct r128fb_softc *sc, int x, int y, int wi, int he,
614 1.1.2.2 joerg uint32_t colour)
615 1.1.2.2 joerg {
616 1.1.2.2 joerg
617 1.1.2.2 joerg r128fb_wait(sc, 6);
618 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_GUI_MASTER_CNTL,
619 1.1.2.2 joerg R128_GMC_BRUSH_SOLID_COLOR |
620 1.1.2.2 joerg R128_GMC_SRC_DATATYPE_COLOR |
621 1.1.2.2 joerg R128_ROP3_P |
622 1.1.2.2 joerg sc->sc_master_cntl);
623 1.1.2.2 joerg
624 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_BRUSH_FRGD_CLR,
625 1.1.2.2 joerg colour);
626 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_CNTL,
627 1.1.2.2 joerg R128_DST_X_LEFT_TO_RIGHT | R128_DST_Y_TOP_TO_BOTTOM);
628 1.1.2.2 joerg /* now feed it coordinates */
629 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_X_Y,
630 1.1.2.2 joerg (x << 16) | y);
631 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_WIDTH_HEIGHT,
632 1.1.2.2 joerg (wi << 16) | he);
633 1.1.2.2 joerg r128fb_flush_engine(sc);
634 1.1.2.2 joerg }
635 1.1.2.2 joerg
636 1.1.2.2 joerg static void
637 1.1.2.2 joerg r128fb_bitblt(struct r128fb_softc *sc, int xs, int ys, int xd, int yd,
638 1.1.2.2 joerg int wi, int he, int rop)
639 1.1.2.2 joerg {
640 1.1.2.2 joerg uint32_t dp_cntl = 0;
641 1.1.2.2 joerg
642 1.1.2.2 joerg r128fb_wait(sc, 5);
643 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_GUI_MASTER_CNTL,
644 1.1.2.2 joerg R128_GMC_BRUSH_SOLID_COLOR |
645 1.1.2.2 joerg R128_GMC_SRC_DATATYPE_COLOR |
646 1.1.2.2 joerg rop |
647 1.1.2.2 joerg R128_DP_SRC_SOURCE_MEMORY |
648 1.1.2.2 joerg sc->sc_master_cntl);
649 1.1.2.2 joerg
650 1.1.2.2 joerg if (yd <= ys) {
651 1.1.2.2 joerg dp_cntl = R128_DST_Y_TOP_TO_BOTTOM;
652 1.1.2.2 joerg } else {
653 1.1.2.2 joerg ys += he - 1;
654 1.1.2.2 joerg yd += he - 1;
655 1.1.2.2 joerg }
656 1.1.2.2 joerg if (xd <= xs) {
657 1.1.2.2 joerg dp_cntl |= R128_DST_X_LEFT_TO_RIGHT;
658 1.1.2.2 joerg } else {
659 1.1.2.2 joerg xs += wi - 1;
660 1.1.2.2 joerg xd += wi - 1;
661 1.1.2.2 joerg }
662 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DP_CNTL, dp_cntl);
663 1.1.2.2 joerg
664 1.1.2.2 joerg /* now feed it coordinates */
665 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_SRC_X_Y,
666 1.1.2.2 joerg (xs << 16) | ys);
667 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_X_Y,
668 1.1.2.2 joerg (xd << 16) | yd);
669 1.1.2.2 joerg bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_DST_WIDTH_HEIGHT,
670 1.1.2.2 joerg (wi << 16) | he);
671 1.1.2.2 joerg r128fb_flush_engine(sc);
672 1.1.2.2 joerg }
673 1.1.2.2 joerg
674 1.1.2.2 joerg static void
675 1.1.2.2 joerg r128fb_cursor(void *cookie, int on, int row, int col)
676 1.1.2.2 joerg {
677 1.1.2.2 joerg struct rasops_info *ri = cookie;
678 1.1.2.2 joerg struct vcons_screen *scr = ri->ri_hw;
679 1.1.2.2 joerg struct r128fb_softc *sc = scr->scr_cookie;
680 1.1.2.2 joerg int x, y, wi, he;
681 1.1.2.2 joerg
682 1.1.2.2 joerg wi = ri->ri_font->fontwidth;
683 1.1.2.2 joerg he = ri->ri_font->fontheight;
684 1.1.2.2 joerg
685 1.1.2.2 joerg if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
686 1.1.2.2 joerg x = ri->ri_ccol * wi + ri->ri_xorigin;
687 1.1.2.2 joerg y = ri->ri_crow * he + ri->ri_yorigin;
688 1.1.2.2 joerg if (ri->ri_flg & RI_CURSOR) {
689 1.1.2.2 joerg r128fb_bitblt(sc, x, y, x, y, wi, he, R128_ROP3_Dn);
690 1.1.2.2 joerg ri->ri_flg &= ~RI_CURSOR;
691 1.1.2.2 joerg }
692 1.1.2.2 joerg ri->ri_crow = row;
693 1.1.2.2 joerg ri->ri_ccol = col;
694 1.1.2.2 joerg if (on) {
695 1.1.2.2 joerg x = ri->ri_ccol * wi + ri->ri_xorigin;
696 1.1.2.2 joerg y = ri->ri_crow * he + ri->ri_yorigin;
697 1.1.2.2 joerg r128fb_bitblt(sc, x, y, x, y, wi, he, R128_ROP3_Dn);
698 1.1.2.2 joerg ri->ri_flg |= RI_CURSOR;;
699 1.1.2.2 joerg }
700 1.1.2.2 joerg } else {
701 1.1.2.2 joerg scr->scr_ri.ri_crow = row;
702 1.1.2.2 joerg scr->scr_ri.ri_ccol = col;
703 1.1.2.2 joerg scr->scr_ri.ri_flg &= ~RI_CURSOR;
704 1.1.2.2 joerg }
705 1.1.2.2 joerg
706 1.1.2.2 joerg }
707 1.1.2.2 joerg
708 1.1.2.2 joerg #if 0
709 1.1.2.2 joerg static void
710 1.1.2.2 joerg r128fb_putchar(void *cookie, int row, int col, u_int c, long attr)
711 1.1.2.2 joerg {
712 1.1.2.2 joerg }
713 1.1.2.2 joerg #endif
714 1.1.2.2 joerg
715 1.1.2.2 joerg static void
716 1.1.2.2 joerg r128fb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
717 1.1.2.2 joerg {
718 1.1.2.2 joerg struct rasops_info *ri = cookie;
719 1.1.2.2 joerg struct vcons_screen *scr = ri->ri_hw;
720 1.1.2.2 joerg struct r128fb_softc *sc = scr->scr_cookie;
721 1.1.2.2 joerg int32_t xs, xd, y, width, height;
722 1.1.2.2 joerg
723 1.1.2.2 joerg if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
724 1.1.2.2 joerg xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
725 1.1.2.2 joerg xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
726 1.1.2.2 joerg y = ri->ri_yorigin + ri->ri_font->fontheight * row;
727 1.1.2.2 joerg width = ri->ri_font->fontwidth * ncols;
728 1.1.2.2 joerg height = ri->ri_font->fontheight;
729 1.1.2.2 joerg r128fb_bitblt(sc, xs, y, xd, y, width, height, R128_ROP3_S);
730 1.1.2.2 joerg }
731 1.1.2.2 joerg }
732 1.1.2.2 joerg
733 1.1.2.2 joerg static void
734 1.1.2.2 joerg r128fb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
735 1.1.2.2 joerg {
736 1.1.2.2 joerg struct rasops_info *ri = cookie;
737 1.1.2.2 joerg struct vcons_screen *scr = ri->ri_hw;
738 1.1.2.2 joerg struct r128fb_softc *sc = scr->scr_cookie;
739 1.1.2.2 joerg int32_t x, y, width, height, fg, bg, ul;
740 1.1.2.2 joerg
741 1.1.2.2 joerg if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
742 1.1.2.2 joerg x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
743 1.1.2.2 joerg y = ri->ri_yorigin + ri->ri_font->fontheight * row;
744 1.1.2.2 joerg width = ri->ri_font->fontwidth * ncols;
745 1.1.2.2 joerg height = ri->ri_font->fontheight;
746 1.1.2.2 joerg rasops_unpack_attr(fillattr, &fg, &bg, &ul);
747 1.1.2.2 joerg
748 1.1.2.2 joerg r128fb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
749 1.1.2.2 joerg }
750 1.1.2.2 joerg }
751 1.1.2.2 joerg
752 1.1.2.2 joerg static void
753 1.1.2.2 joerg r128fb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
754 1.1.2.2 joerg {
755 1.1.2.2 joerg struct rasops_info *ri = cookie;
756 1.1.2.2 joerg struct vcons_screen *scr = ri->ri_hw;
757 1.1.2.2 joerg struct r128fb_softc *sc = scr->scr_cookie;
758 1.1.2.2 joerg int32_t x, ys, yd, width, height;
759 1.1.2.2 joerg
760 1.1.2.2 joerg if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
761 1.1.2.2 joerg x = ri->ri_xorigin;
762 1.1.2.2 joerg ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
763 1.1.2.2 joerg yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
764 1.1.2.2 joerg width = ri->ri_emuwidth;
765 1.1.2.2 joerg height = ri->ri_font->fontheight*nrows;
766 1.1.2.2 joerg r128fb_bitblt(sc, x, ys, x, yd, width, height, R128_ROP3_S);
767 1.1.2.2 joerg }
768 1.1.2.2 joerg }
769 1.1.2.2 joerg
770 1.1.2.2 joerg static void
771 1.1.2.2 joerg r128fb_eraserows(void *cookie, int row, int nrows, long fillattr)
772 1.1.2.2 joerg {
773 1.1.2.2 joerg struct rasops_info *ri = cookie;
774 1.1.2.2 joerg struct vcons_screen *scr = ri->ri_hw;
775 1.1.2.2 joerg struct r128fb_softc *sc = scr->scr_cookie;
776 1.1.2.2 joerg int32_t x, y, width, height, fg, bg, ul;
777 1.1.2.2 joerg
778 1.1.2.2 joerg if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
779 1.1.2.2 joerg x = ri->ri_xorigin;
780 1.1.2.2 joerg y = ri->ri_yorigin + ri->ri_font->fontheight * row;
781 1.1.2.2 joerg width = ri->ri_emuwidth;
782 1.1.2.2 joerg height = ri->ri_font->fontheight * nrows;
783 1.1.2.2 joerg rasops_unpack_attr(fillattr, &fg, &bg, &ul);
784 1.1.2.2 joerg
785 1.1.2.2 joerg r128fb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
786 1.1.2.2 joerg }
787 1.1.2.2 joerg }
788 1.1.2.2 joerg
789