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