chipsfb.c revision 1.12 1 1.12 he /* $NetBSD: chipsfb.c,v 1.12 2007/08/19 15:57:24 he Exp $ */
2 1.1 macallan
3 1.1 macallan /*
4 1.1 macallan * Copyright (c) 2006 Michael Lorenz
5 1.1 macallan * All rights reserved.
6 1.1 macallan *
7 1.1 macallan * Redistribution and use in source and binary forms, with or without
8 1.1 macallan * modification, are permitted provided that the following conditions
9 1.1 macallan * are met:
10 1.1 macallan * 1. Redistributions of source code must retain the above copyright
11 1.1 macallan * notice, this list of conditions and the following disclaimer.
12 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 macallan * notice, this list of conditions and the following disclaimer in the
14 1.1 macallan * documentation and/or other materials provided with the distribution.
15 1.1 macallan * 3. The name of the author may not be used to endorse or promote products
16 1.1 macallan * derived from this software without specific prior written permission.
17 1.1 macallan *
18 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 macallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 macallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 macallan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 macallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 macallan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 macallan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 macallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 macallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 macallan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 macallan */
29 1.1 macallan
30 1.8 macallan /*
31 1.1 macallan * A console driver for Chips & Technologies 65550 graphics controllers
32 1.8 macallan * tested on macppc only so far
33 1.1 macallan */
34 1.1 macallan
35 1.1 macallan #include <sys/cdefs.h>
36 1.12 he __KERNEL_RCSID(0, "$NetBSD: chipsfb.c,v 1.12 2007/08/19 15:57:24 he Exp $");
37 1.1 macallan
38 1.1 macallan #include <sys/param.h>
39 1.1 macallan #include <sys/systm.h>
40 1.1 macallan #include <sys/kernel.h>
41 1.1 macallan #include <sys/device.h>
42 1.1 macallan #include <sys/malloc.h>
43 1.1 macallan #include <sys/callout.h>
44 1.1 macallan #include <sys/lwp.h>
45 1.1 macallan #include <sys/kauth.h>
46 1.1 macallan
47 1.1 macallan #include <uvm/uvm_extern.h>
48 1.1 macallan
49 1.1 macallan #include <dev/videomode/videomode.h>
50 1.1 macallan
51 1.1 macallan #include <dev/pci/pcivar.h>
52 1.1 macallan #include <dev/pci/pcireg.h>
53 1.1 macallan #include <dev/pci/pcidevs.h>
54 1.1 macallan #include <dev/pci/pciio.h>
55 1.1 macallan #include <dev/pci/chipsfbreg.h>
56 1.1 macallan
57 1.1 macallan #include <dev/wscons/wsdisplayvar.h>
58 1.1 macallan #include <dev/wscons/wsconsio.h>
59 1.1 macallan #include <dev/wsfont/wsfont.h>
60 1.1 macallan #include <dev/rasops/rasops.h>
61 1.1 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
62 1.1 macallan
63 1.1 macallan #include <dev/i2c/i2cvar.h>
64 1.1 macallan
65 1.1 macallan #include "opt_wsemul.h"
66 1.8 macallan #include "opt_chipsfb.h"
67 1.1 macallan
68 1.1 macallan struct chipsfb_softc {
69 1.1 macallan struct device sc_dev;
70 1.1 macallan pci_chipset_tag_t sc_pc;
71 1.1 macallan pcitag_t sc_pcitag;
72 1.1 macallan
73 1.1 macallan bus_space_tag_t sc_memt;
74 1.1 macallan bus_space_tag_t sc_iot;
75 1.8 macallan bus_space_handle_t sc_memh;
76 1.1 macallan
77 1.1 macallan bus_space_tag_t sc_fbt;
78 1.1 macallan bus_space_tag_t sc_ioregt;
79 1.8 macallan bus_space_handle_t sc_fbh;
80 1.8 macallan bus_space_handle_t sc_ioregh;
81 1.1 macallan bus_addr_t sc_fb, sc_ioreg;
82 1.1 macallan bus_size_t sc_fbsize, sc_ioregsize;
83 1.1 macallan
84 1.1 macallan void *sc_ih;
85 1.8 macallan
86 1.1 macallan size_t memsize;
87 1.1 macallan
88 1.1 macallan int bits_per_pixel;
89 1.1 macallan int width, height, linebytes;
90 1.1 macallan
91 1.1 macallan int sc_mode;
92 1.1 macallan uint32_t sc_bg;
93 1.8 macallan
94 1.1 macallan u_char sc_cmap_red[256];
95 1.1 macallan u_char sc_cmap_green[256];
96 1.8 macallan u_char sc_cmap_blue[256];
97 1.1 macallan int sc_dacw;
98 1.1 macallan
99 1.8 macallan /*
100 1.8 macallan * I2C stuff
101 1.8 macallan * DDC2 clock is on GPIO1, data on GPIO0
102 1.8 macallan */
103 1.1 macallan struct i2c_controller sc_i2c;
104 1.1 macallan uint8_t sc_edid[1024];
105 1.1 macallan int sc_edidbytes; /* number of bytes read from the monitor */
106 1.1 macallan
107 1.1 macallan struct vcons_data vd;
108 1.1 macallan };
109 1.1 macallan
110 1.1 macallan static struct vcons_screen chipsfb_console_screen;
111 1.1 macallan
112 1.1 macallan extern const u_char rasops_cmap[768];
113 1.1 macallan
114 1.1 macallan static int chipsfb_match(struct device *, struct cfdata *, void *);
115 1.1 macallan static void chipsfb_attach(struct device *, struct device *, void *);
116 1.1 macallan
117 1.8 macallan CFATTACH_DECL(chipsfb, sizeof(struct chipsfb_softc), chipsfb_match,
118 1.1 macallan chipsfb_attach, NULL, NULL);
119 1.1 macallan
120 1.8 macallan static void chipsfb_init(struct chipsfb_softc *);
121 1.1 macallan
122 1.1 macallan static void chipsfb_cursor(void *, int, int, int);
123 1.1 macallan static void chipsfb_copycols(void *, int, int, int, int);
124 1.1 macallan static void chipsfb_erasecols(void *, int, int, int, long);
125 1.1 macallan static void chipsfb_copyrows(void *, int, int, int);
126 1.1 macallan static void chipsfb_eraserows(void *, int, int, long);
127 1.1 macallan
128 1.1 macallan #if 0
129 1.1 macallan static int chipsfb_allocattr(void *, int, int, int, long *);
130 1.1 macallan static void chipsfb_scroll(void *, void *, int);
131 1.1 macallan static int chipsfb_load_font(void *, void *, struct wsdisplay_font *);
132 1.1 macallan #endif
133 1.1 macallan
134 1.1 macallan static int chipsfb_putcmap(struct chipsfb_softc *,
135 1.1 macallan struct wsdisplay_cmap *);
136 1.1 macallan static int chipsfb_getcmap(struct chipsfb_softc *,
137 1.1 macallan struct wsdisplay_cmap *);
138 1.1 macallan static int chipsfb_putpalreg(struct chipsfb_softc *, uint8_t, uint8_t,
139 1.1 macallan uint8_t, uint8_t);
140 1.1 macallan
141 1.1 macallan static void chipsfb_bitblt(struct chipsfb_softc *, int, int, int, int,
142 1.1 macallan int, int, uint8_t);
143 1.1 macallan static void chipsfb_rectfill(struct chipsfb_softc *, int, int, int, int,
144 1.1 macallan int);
145 1.1 macallan static void chipsfb_putchar(void *, int, int, u_int, long);
146 1.1 macallan static void chipsfb_setup_mono(struct chipsfb_softc *, int, int, int,
147 1.8 macallan int, uint32_t, uint32_t);
148 1.2 macallan static void chipsfb_feed(struct chipsfb_softc *, int, uint8_t *);
149 1.2 macallan
150 1.8 macallan #if 0
151 1.1 macallan static void chipsfb_showpal(struct chipsfb_softc *);
152 1.1 macallan #endif
153 1.1 macallan static void chipsfb_restore_palette(struct chipsfb_softc *);
154 1.1 macallan
155 1.1 macallan static void chipsfb_wait_idle(struct chipsfb_softc *);
156 1.1 macallan
157 1.4 macallan static uint32_t chipsfb_probe_vram(struct chipsfb_softc *);
158 1.4 macallan
159 1.1 macallan struct wsscreen_descr chipsfb_defaultscreen = {
160 1.1 macallan "default",
161 1.1 macallan 0, 0,
162 1.1 macallan NULL,
163 1.1 macallan 8, 16,
164 1.1 macallan WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
165 1.1 macallan };
166 1.1 macallan
167 1.1 macallan const struct wsscreen_descr *_chipsfb_scrlist[] = {
168 1.1 macallan &chipsfb_defaultscreen,
169 1.1 macallan /* XXX other formats, graphics screen? */
170 1.1 macallan };
171 1.1 macallan
172 1.1 macallan struct wsscreen_list chipsfb_screenlist = {
173 1.1 macallan sizeof(_chipsfb_scrlist) / sizeof(struct wsscreen_descr *), _chipsfb_scrlist
174 1.1 macallan };
175 1.1 macallan
176 1.9 christos static int chipsfb_ioctl(void *, void *, u_long, void *, int,
177 1.1 macallan struct lwp *);
178 1.1 macallan static paddr_t chipsfb_mmap(void *, void *, off_t, int);
179 1.1 macallan static void chipsfb_clearscreen(struct chipsfb_softc *);
180 1.1 macallan static void chipsfb_init_screen(void *, struct vcons_screen *, int,
181 1.1 macallan long *);
182 1.1 macallan
183 1.1 macallan
184 1.1 macallan struct wsdisplay_accessops chipsfb_accessops = {
185 1.1 macallan chipsfb_ioctl,
186 1.1 macallan chipsfb_mmap,
187 1.1 macallan NULL, /* load_font */
188 1.1 macallan NULL, /* polls */
189 1.1 macallan NULL, /* scroll */
190 1.1 macallan };
191 1.1 macallan
192 1.1 macallan /*
193 1.1 macallan * Inline functions for getting access to register aperture.
194 1.1 macallan */
195 1.1 macallan static inline void
196 1.1 macallan chipsfb_write32(struct chipsfb_softc *sc, uint32_t reg, uint32_t val)
197 1.1 macallan {
198 1.1 macallan bus_space_write_4(sc->sc_fbt, sc->sc_fbh, reg, val);
199 1.1 macallan }
200 1.1 macallan
201 1.1 macallan static inline uint32_t
202 1.8 macallan chipsfb_read32(struct chipsfb_softc *sc, uint32_t reg)
203 1.1 macallan {
204 1.1 macallan return bus_space_read_4(sc->sc_fbt, sc->sc_fbh, reg);
205 1.1 macallan }
206 1.1 macallan
207 1.1 macallan static inline void
208 1.1 macallan chipsfb_write_vga(struct chipsfb_softc *sc, uint32_t reg, uint8_t val)
209 1.8 macallan {
210 1.8 macallan bus_space_write_1(sc->sc_iot, sc->sc_ioregh, reg, val);
211 1.1 macallan }
212 1.1 macallan
213 1.1 macallan static inline uint8_t
214 1.1 macallan chipsfb_read_vga(struct chipsfb_softc *sc, uint32_t reg)
215 1.8 macallan {
216 1.8 macallan return bus_space_read_1(sc->sc_iot, sc->sc_ioregh, reg);
217 1.1 macallan }
218 1.1 macallan
219 1.1 macallan static inline uint8_t
220 1.1 macallan chipsfb_read_indexed(struct chipsfb_softc *sc, uint32_t reg, uint8_t index)
221 1.1 macallan {
222 1.1 macallan
223 1.1 macallan chipsfb_write_vga(sc, reg & 0xfffe, index);
224 1.1 macallan return chipsfb_read_vga(sc, reg | 0x0001);
225 1.1 macallan }
226 1.1 macallan
227 1.1 macallan static inline void
228 1.8 macallan chipsfb_write_indexed(struct chipsfb_softc *sc, uint32_t reg, uint8_t index,
229 1.1 macallan uint8_t val)
230 1.1 macallan {
231 1.1 macallan
232 1.1 macallan chipsfb_write_vga(sc, reg & 0xfffe, index);
233 1.1 macallan chipsfb_write_vga(sc, reg | 0x0001, val);
234 1.1 macallan }
235 1.1 macallan
236 1.1 macallan static void
237 1.1 macallan chipsfb_wait_idle(struct chipsfb_softc *sc)
238 1.1 macallan {
239 1.1 macallan
240 1.3 macallan #ifdef CHIPSFB_DEBUG
241 1.3 macallan chipsfb_write32(sc, CT_OFF_FB + (800 * 598) - 4, 0);
242 1.3 macallan #endif
243 1.3 macallan
244 1.1 macallan /* spin until the blitter is idle */
245 1.1 macallan while ((chipsfb_read32(sc, CT_BLT_CONTROL) & BLT_IS_BUSY) != 0) {
246 1.1 macallan }
247 1.3 macallan
248 1.3 macallan #ifdef CHIPSFB_DEBUG
249 1.3 macallan chipsfb_write32(sc, CT_OFF_FB + (800 * 598) - 4, 0xffffffff);
250 1.3 macallan #endif
251 1.1 macallan }
252 1.1 macallan
253 1.1 macallan static int
254 1.1 macallan chipsfb_match(struct device *parent, struct cfdata *match, void *aux)
255 1.1 macallan {
256 1.1 macallan struct pci_attach_args *pa = (struct pci_attach_args *)aux;
257 1.1 macallan
258 1.1 macallan if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
259 1.1 macallan PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
260 1.1 macallan return 0;
261 1.8 macallan if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CHIPS) &&
262 1.1 macallan (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CHIPS_65550))
263 1.1 macallan return 100;
264 1.8 macallan if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CHIPS) &&
265 1.8 macallan (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CHIPS_65554))
266 1.8 macallan return 100;
267 1.1 macallan return 0;
268 1.1 macallan }
269 1.1 macallan
270 1.1 macallan static void
271 1.1 macallan chipsfb_attach(struct device *parent, struct device *self, void *aux)
272 1.1 macallan {
273 1.8 macallan struct chipsfb_softc *sc = (void *)self;
274 1.1 macallan struct pci_attach_args *pa = aux;
275 1.1 macallan char devinfo[256];
276 1.1 macallan struct wsemuldisplaydev_attach_args aa;
277 1.1 macallan struct rasops_info *ri;
278 1.8 macallan prop_dictionary_t dict;
279 1.1 macallan pcireg_t screg;
280 1.1 macallan ulong defattr;
281 1.12 he bool console = false;
282 1.12 he int width, height, i, j;
283 1.1 macallan uint32_t bg, fg, ul;
284 1.8 macallan
285 1.8 macallan dict = device_properties(self);
286 1.1 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
287 1.1 macallan sc->sc_pc = pa->pa_pc;
288 1.1 macallan sc->sc_pcitag = pa->pa_tag;
289 1.1 macallan sc->sc_dacw = -1;
290 1.1 macallan
291 1.1 macallan screg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, PCI_COMMAND_STATUS_REG);
292 1.1 macallan screg |= PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
293 1.1 macallan pci_conf_write(sc->sc_pc, sc->sc_pcitag,PCI_COMMAND_STATUS_REG,screg);
294 1.8 macallan
295 1.1 macallan pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
296 1.8 macallan aprint_normal(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
297 1.8 macallan #ifdef CHIPSFB_DEBUG
298 1.8 macallan printf(prop_dictionary_externalize(dict));
299 1.8 macallan #endif
300 1.1 macallan
301 1.1 macallan sc->sc_memt = pa->pa_memt;
302 1.1 macallan sc->sc_iot = pa->pa_iot;
303 1.1 macallan
304 1.1 macallan /* the framebuffer */
305 1.1 macallan if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM,
306 1.8 macallan BUS_SPACE_MAP_LINEAR,
307 1.1 macallan &sc->sc_fbt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
308 1.8 macallan aprint_error("%s: failed to map the frame buffer.\n",
309 1.1 macallan sc->sc_dev.dv_xname);
310 1.1 macallan }
311 1.1 macallan
312 1.1 macallan /* IO-mapped registers */
313 1.11 macallan if (bus_space_map(sc->sc_iot, 0x0, 0x400, 0, &sc->sc_ioregh) != 0) {
314 1.8 macallan aprint_error("%s: failed to map IO registers.\n",
315 1.1 macallan sc->sc_dev.dv_xname);
316 1.1 macallan }
317 1.1 macallan
318 1.4 macallan sc->memsize = chipsfb_probe_vram(sc);
319 1.1 macallan chipsfb_init(sc);
320 1.8 macallan
321 1.1 macallan /* we should read these from the chip instead of depending on OF */
322 1.1 macallan width = height = -1;
323 1.1 macallan
324 1.1 macallan /* detect panel size */
325 1.1 macallan width = chipsfb_read_indexed(sc, CT_FP_INDEX, FP_HSIZE_LSB);
326 1.1 macallan width |= (chipsfb_read_indexed(sc, CT_FP_INDEX, FP_HORZ_OVERFLOW_1)
327 1.1 macallan & 0x0f) << 8;
328 1.1 macallan width = (width + 1) * 8;
329 1.1 macallan height = chipsfb_read_indexed(sc, CT_FP_INDEX, FP_VSIZE_LSB);
330 1.1 macallan height |= (chipsfb_read_indexed(sc, CT_FP_INDEX, FP_VERT_OVERFLOW_1)
331 1.1 macallan & 0x0f) << 8;
332 1.1 macallan height++;
333 1.8 macallan aprint_verbose("Panel size: %d x %d\n", width, height);
334 1.8 macallan
335 1.8 macallan if (!prop_dictionary_get_uint32(dict, "width", &sc->width))
336 1.8 macallan sc->width = width;
337 1.8 macallan if (!prop_dictionary_get_uint32(dict, "height", &sc->height))
338 1.8 macallan sc->height = height;
339 1.8 macallan if (!prop_dictionary_get_uint32(dict, "depth", &sc->bits_per_pixel))
340 1.8 macallan sc->bits_per_pixel = 8;
341 1.8 macallan if (!prop_dictionary_get_uint32(dict, "linebytes", &sc->linebytes))
342 1.8 macallan sc->linebytes = (sc->width * sc->bits_per_pixel) >> 3;
343 1.1 macallan
344 1.8 macallan prop_dictionary_get_bool(dict, "is_console", &console);
345 1.1 macallan
346 1.2 macallan #ifdef notyet
347 1.1 macallan /* XXX this should at least be configurable via kernel config */
348 1.2 macallan chipsfb_set_videomode(sc, &videomode_list[16]);
349 1.2 macallan #endif
350 1.1 macallan
351 1.1 macallan vcons_init(&sc->vd, sc, &chipsfb_defaultscreen, &chipsfb_accessops);
352 1.1 macallan sc->vd.init_screen = chipsfb_init_screen;
353 1.1 macallan
354 1.1 macallan ri = &chipsfb_console_screen.scr_ri;
355 1.1 macallan if (console) {
356 1.1 macallan vcons_init_screen(&sc->vd, &chipsfb_console_screen, 1,
357 1.1 macallan &defattr);
358 1.1 macallan chipsfb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
359 1.1 macallan
360 1.1 macallan chipsfb_defaultscreen.textops = &ri->ri_ops;
361 1.1 macallan chipsfb_defaultscreen.capabilities = ri->ri_caps;
362 1.1 macallan chipsfb_defaultscreen.nrows = ri->ri_rows;
363 1.1 macallan chipsfb_defaultscreen.ncols = ri->ri_cols;
364 1.1 macallan wsdisplay_cnattach(&chipsfb_defaultscreen, ri, 0, 0, defattr);
365 1.1 macallan } else {
366 1.1 macallan /*
367 1.1 macallan * since we're not the console we can postpone the rest
368 1.1 macallan * until someone actually allocates a screen for us
369 1.1 macallan */
370 1.2 macallan #ifdef notyet
371 1.2 macallan chipsfb_set_videomode(sc, &videomode_list[0]);
372 1.2 macallan #endif
373 1.1 macallan }
374 1.1 macallan
375 1.1 macallan rasops_unpack_attr(defattr, &fg, &bg, &ul);
376 1.1 macallan sc->sc_bg = ri->ri_devcmap[bg];
377 1.1 macallan chipsfb_clearscreen(sc);
378 1.1 macallan
379 1.8 macallan aprint_normal("%s: %d MB aperture, %d MB VRAM at 0x%08x\n",
380 1.8 macallan sc->sc_dev.dv_xname, (u_int)(sc->sc_fbsize >> 20),
381 1.4 macallan sc->memsize >> 20, (u_int)sc->sc_fb);
382 1.8 macallan #ifdef CHIPSFB_DEBUG
383 1.8 macallan aprint_debug("fb: %08lx\n", (ulong)ri->ri_bits);
384 1.1 macallan #endif
385 1.8 macallan
386 1.1 macallan j = 0;
387 1.1 macallan for (i = 0; i < 256; i++) {
388 1.8 macallan chipsfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
389 1.1 macallan rasops_cmap[j + 2]);
390 1.1 macallan j += 3;
391 1.1 macallan }
392 1.1 macallan
393 1.1 macallan aa.console = console;
394 1.1 macallan aa.scrdata = &chipsfb_screenlist;
395 1.1 macallan aa.accessops = &chipsfb_accessops;
396 1.1 macallan aa.accesscookie = &sc->vd;
397 1.1 macallan
398 1.1 macallan config_found(self, &aa, wsemuldisplaydevprint);
399 1.1 macallan }
400 1.1 macallan
401 1.1 macallan static int
402 1.8 macallan chipsfb_putpalreg(struct chipsfb_softc *sc, uint8_t index, uint8_t r,
403 1.1 macallan uint8_t g, uint8_t b)
404 1.1 macallan {
405 1.8 macallan
406 1.1 macallan sc->sc_cmap_red[index] = r;
407 1.1 macallan sc->sc_cmap_green[index] = g;
408 1.1 macallan sc->sc_cmap_blue[index] = b;
409 1.1 macallan
410 1.1 macallan chipsfb_write_vga(sc, CT_DACMASK, 0xff);
411 1.1 macallan chipsfb_write_vga(sc, CT_WRITEINDEX, index);
412 1.1 macallan chipsfb_write_vga(sc, CT_DACDATA, r);
413 1.1 macallan chipsfb_write_vga(sc, CT_DACDATA, g);
414 1.1 macallan chipsfb_write_vga(sc, CT_DACDATA, b);
415 1.1 macallan
416 1.1 macallan return 0;
417 1.1 macallan }
418 1.1 macallan
419 1.1 macallan static int
420 1.1 macallan chipsfb_putcmap(struct chipsfb_softc *sc, struct wsdisplay_cmap *cm)
421 1.1 macallan {
422 1.1 macallan u_char *r, *g, *b;
423 1.1 macallan u_int index = cm->index;
424 1.1 macallan u_int count = cm->count;
425 1.1 macallan int i, error;
426 1.1 macallan u_char rbuf[256], gbuf[256], bbuf[256];
427 1.1 macallan
428 1.8 macallan #ifdef CHIPSFB_DEBUG
429 1.8 macallan aprint_debug("putcmap: %d %d\n",index, count);
430 1.8 macallan #endif
431 1.1 macallan if (cm->index >= 256 || cm->count > 256 ||
432 1.1 macallan (cm->index + cm->count) > 256)
433 1.1 macallan return EINVAL;
434 1.1 macallan error = copyin(cm->red, &rbuf[index], count);
435 1.1 macallan if (error)
436 1.1 macallan return error;
437 1.1 macallan error = copyin(cm->green, &gbuf[index], count);
438 1.1 macallan if (error)
439 1.1 macallan return error;
440 1.1 macallan error = copyin(cm->blue, &bbuf[index], count);
441 1.1 macallan if (error)
442 1.1 macallan return error;
443 1.1 macallan
444 1.1 macallan memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
445 1.1 macallan memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
446 1.1 macallan memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
447 1.1 macallan
448 1.1 macallan r = &sc->sc_cmap_red[index];
449 1.1 macallan g = &sc->sc_cmap_green[index];
450 1.1 macallan b = &sc->sc_cmap_blue[index];
451 1.8 macallan
452 1.1 macallan for (i = 0; i < count; i++) {
453 1.1 macallan chipsfb_putpalreg(sc, index, *r, *g, *b);
454 1.1 macallan index++;
455 1.1 macallan r++, g++, b++;
456 1.1 macallan }
457 1.1 macallan return 0;
458 1.1 macallan }
459 1.1 macallan
460 1.1 macallan static int
461 1.1 macallan chipsfb_getcmap(struct chipsfb_softc *sc, struct wsdisplay_cmap *cm)
462 1.1 macallan {
463 1.1 macallan u_int index = cm->index;
464 1.1 macallan u_int count = cm->count;
465 1.1 macallan int error;
466 1.1 macallan
467 1.1 macallan if (index >= 255 || count > 256 || index + count > 256)
468 1.1 macallan return EINVAL;
469 1.8 macallan
470 1.1 macallan error = copyout(&sc->sc_cmap_red[index], cm->red, count);
471 1.1 macallan if (error)
472 1.1 macallan return error;
473 1.1 macallan error = copyout(&sc->sc_cmap_green[index], cm->green, count);
474 1.1 macallan if (error)
475 1.1 macallan return error;
476 1.1 macallan error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
477 1.1 macallan if (error)
478 1.1 macallan return error;
479 1.1 macallan
480 1.1 macallan return 0;
481 1.1 macallan }
482 1.1 macallan
483 1.1 macallan static void
484 1.1 macallan chipsfb_clearscreen(struct chipsfb_softc *sc)
485 1.1 macallan {
486 1.1 macallan chipsfb_rectfill(sc, 0, 0, sc->width, sc->height, sc->sc_bg);
487 1.1 macallan }
488 1.1 macallan
489 1.1 macallan /*
490 1.1 macallan * wsdisplay_emulops
491 1.1 macallan */
492 1.1 macallan
493 1.1 macallan static void
494 1.1 macallan chipsfb_cursor(void *cookie, int on, int row, int col)
495 1.1 macallan {
496 1.1 macallan struct rasops_info *ri = cookie;
497 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
498 1.1 macallan struct chipsfb_softc *sc = scr->scr_cookie;
499 1.1 macallan int x, y, wi, he;
500 1.8 macallan
501 1.1 macallan wi = ri->ri_font->fontwidth;
502 1.1 macallan he = ri->ri_font->fontheight;
503 1.8 macallan
504 1.1 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
505 1.1 macallan x = ri->ri_ccol * wi + ri->ri_xorigin;
506 1.1 macallan y = ri->ri_crow * he + ri->ri_yorigin;
507 1.1 macallan if (ri->ri_flg & RI_CURSOR) {
508 1.1 macallan chipsfb_bitblt(sc, x, y, x, y, wi, he, ROP_NOT_DST);
509 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
510 1.1 macallan }
511 1.1 macallan ri->ri_crow = row;
512 1.1 macallan ri->ri_ccol = col;
513 1.1 macallan if (on) {
514 1.1 macallan x = ri->ri_ccol * wi + ri->ri_xorigin;
515 1.1 macallan y = ri->ri_crow * he + ri->ri_yorigin;
516 1.1 macallan chipsfb_bitblt(sc, x, y, x, y, wi, he, ROP_NOT_DST);
517 1.1 macallan ri->ri_flg |= RI_CURSOR;
518 1.1 macallan }
519 1.1 macallan } else {
520 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
521 1.1 macallan ri->ri_crow = row;
522 1.1 macallan ri->ri_ccol = col;
523 1.1 macallan }
524 1.1 macallan }
525 1.1 macallan
526 1.1 macallan #if 0
527 1.1 macallan int
528 1.1 macallan chipsfb_mapchar(void *cookie, int uni, u_int *index)
529 1.1 macallan {
530 1.1 macallan return 0;
531 1.1 macallan }
532 1.1 macallan #endif
533 1.1 macallan
534 1.1 macallan static void
535 1.1 macallan chipsfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
536 1.1 macallan {
537 1.1 macallan struct rasops_info *ri = cookie;
538 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
539 1.1 macallan struct chipsfb_softc *sc = scr->scr_cookie;
540 1.1 macallan int32_t xs, xd, y, width, height;
541 1.8 macallan
542 1.1 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
543 1.1 macallan xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
544 1.1 macallan xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
545 1.1 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
546 1.1 macallan width = ri->ri_font->fontwidth * ncols;
547 1.8 macallan height = ri->ri_font->fontheight;
548 1.1 macallan chipsfb_bitblt(sc, xs, y, xd, y, width, height, ROP_COPY);
549 1.1 macallan }
550 1.1 macallan }
551 1.1 macallan
552 1.1 macallan static void
553 1.8 macallan chipsfb_erasecols(void *cookie, int row, int startcol, int ncols,
554 1.1 macallan long fillattr)
555 1.1 macallan {
556 1.1 macallan struct rasops_info *ri = cookie;
557 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
558 1.1 macallan struct chipsfb_softc *sc = scr->scr_cookie;
559 1.1 macallan int32_t x, y, width, height, fg, bg, ul;
560 1.8 macallan
561 1.1 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
562 1.1 macallan x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
563 1.1 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
564 1.1 macallan width = ri->ri_font->fontwidth * ncols;
565 1.8 macallan height = ri->ri_font->fontheight;
566 1.1 macallan rasops_unpack_attr(fillattr, &fg, &bg, &ul);
567 1.8 macallan
568 1.1 macallan chipsfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
569 1.1 macallan }
570 1.1 macallan }
571 1.1 macallan
572 1.1 macallan static void
573 1.1 macallan chipsfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
574 1.1 macallan {
575 1.1 macallan struct rasops_info *ri = cookie;
576 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
577 1.1 macallan struct chipsfb_softc *sc = scr->scr_cookie;
578 1.1 macallan int32_t x, ys, yd, width, height;
579 1.1 macallan
580 1.1 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
581 1.1 macallan x = ri->ri_xorigin;
582 1.1 macallan ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
583 1.1 macallan yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
584 1.1 macallan width = ri->ri_emuwidth;
585 1.8 macallan height = ri->ri_font->fontheight * nrows;
586 1.1 macallan chipsfb_bitblt(sc, x, ys, x, yd, width, height, ROP_COPY);
587 1.1 macallan }
588 1.1 macallan }
589 1.1 macallan
590 1.1 macallan static void
591 1.1 macallan chipsfb_eraserows(void *cookie, int row, int nrows, long fillattr)
592 1.1 macallan {
593 1.1 macallan struct rasops_info *ri = cookie;
594 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
595 1.1 macallan struct chipsfb_softc *sc = scr->scr_cookie;
596 1.1 macallan int32_t x, y, width, height, fg, bg, ul;
597 1.1 macallan
598 1.1 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
599 1.1 macallan rasops_unpack_attr(fillattr, &fg, &bg, &ul);
600 1.1 macallan if ((row == 0) && (nrows == ri->ri_rows)) {
601 1.1 macallan /* clear the whole screen */
602 1.1 macallan chipsfb_rectfill(sc, 0, 0, ri->ri_width,
603 1.1 macallan ri->ri_height, ri->ri_devcmap[bg]);
604 1.1 macallan } else {
605 1.1 macallan x = ri->ri_xorigin;
606 1.1 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
607 1.1 macallan width = ri->ri_emuwidth;
608 1.8 macallan height = ri->ri_font->fontheight * nrows;
609 1.1 macallan chipsfb_rectfill(sc, x, y, width, height,
610 1.1 macallan ri->ri_devcmap[bg]);
611 1.1 macallan }
612 1.1 macallan }
613 1.1 macallan }
614 1.1 macallan
615 1.1 macallan static void
616 1.1 macallan chipsfb_bitblt(struct chipsfb_softc *sc, int xs, int ys, int xd, int yd,
617 1.8 macallan int width, int height, uint8_t rop)
618 1.1 macallan {
619 1.1 macallan uint32_t src, dst, cmd = rop, stride, size;
620 1.1 macallan
621 1.1 macallan cmd |= BLT_PAT_IS_SOLID;
622 1.1 macallan
623 1.1 macallan /* we assume 8 bit for now */
624 1.1 macallan src = xs + ys * sc->linebytes;
625 1.1 macallan dst = xd + yd * sc->linebytes;
626 1.1 macallan
627 1.1 macallan if (xs < xd) {
628 1.1 macallan /* right-to-left operation */
629 1.1 macallan cmd |= BLT_START_RIGHT;
630 1.5 macallan src += width - 1;
631 1.5 macallan dst += width - 1;
632 1.1 macallan }
633 1.1 macallan
634 1.1 macallan if (ys < yd) {
635 1.1 macallan /* bottom-to-top operation */
636 1.1 macallan cmd |= BLT_START_BOTTOM;
637 1.1 macallan src += (height - 1) * sc->linebytes;
638 1.1 macallan dst += (height - 1) * sc->linebytes;
639 1.1 macallan }
640 1.8 macallan
641 1.1 macallan stride = (sc->linebytes << 16) | sc->linebytes;
642 1.1 macallan size = (height << 16) | width;
643 1.8 macallan
644 1.2 macallan chipsfb_wait_idle(sc);
645 1.1 macallan chipsfb_write32(sc, CT_BLT_STRIDE, stride);
646 1.1 macallan chipsfb_write32(sc, CT_BLT_SRCADDR, src);
647 1.1 macallan chipsfb_write32(sc, CT_BLT_DSTADDR, dst);
648 1.1 macallan chipsfb_write32(sc, CT_BLT_CONTROL, cmd);
649 1.1 macallan chipsfb_write32(sc, CT_BLT_SIZE, size);
650 1.2 macallan #ifdef CHIPSFB_WAIT
651 1.1 macallan chipsfb_wait_idle(sc);
652 1.2 macallan #endif
653 1.1 macallan }
654 1.8 macallan
655 1.1 macallan static void
656 1.8 macallan chipsfb_rectfill(struct chipsfb_softc *sc, int x, int y, int width,
657 1.8 macallan int height, int colour)
658 1.1 macallan {
659 1.1 macallan uint32_t dst, cmd, stride, size;
660 1.1 macallan
661 1.1 macallan cmd = BLT_PAT_IS_SOLID | BLT_PAT_IS_MONO | ROP_PAT;
662 1.1 macallan
663 1.1 macallan /* we assume 8 bit for now */
664 1.1 macallan dst = x + y * sc->linebytes;
665 1.1 macallan
666 1.1 macallan stride = (sc->linebytes << 16) | sc->linebytes;
667 1.1 macallan size = (height << 16) | width;
668 1.8 macallan
669 1.2 macallan chipsfb_wait_idle(sc);
670 1.1 macallan chipsfb_write32(sc, CT_BLT_STRIDE, stride);
671 1.1 macallan chipsfb_write32(sc, CT_BLT_SRCADDR, dst);
672 1.1 macallan chipsfb_write32(sc, CT_BLT_DSTADDR, dst);
673 1.1 macallan chipsfb_write32(sc, CT_BLT_CONTROL, cmd);
674 1.1 macallan chipsfb_write32(sc, CT_BLT_BG, colour);
675 1.1 macallan chipsfb_write32(sc, CT_BLT_FG, colour);
676 1.1 macallan chipsfb_write32(sc, CT_BLT_SIZE, size);
677 1.2 macallan #ifdef CHIPSFB_WAIT
678 1.1 macallan chipsfb_wait_idle(sc);
679 1.2 macallan #endif
680 1.1 macallan }
681 1.1 macallan
682 1.1 macallan static void
683 1.1 macallan chipsfb_putchar(void *cookie, int row, int col, u_int c, long attr)
684 1.1 macallan {
685 1.1 macallan struct rasops_info *ri = cookie;
686 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
687 1.1 macallan struct chipsfb_softc *sc = scr->scr_cookie;
688 1.1 macallan
689 1.10 mjf if (__predict_false((unsigned int)row > ri->ri_rows ||
690 1.10 mjf (unsigned int)col > ri->ri_cols))
691 1.10 mjf return;
692 1.10 mjf
693 1.1 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
694 1.1 macallan uint8_t *data;
695 1.2 macallan int fg, bg, uc;
696 1.1 macallan int x, y, wi, he;
697 1.1 macallan
698 1.1 macallan wi = ri->ri_font->fontwidth;
699 1.1 macallan he = ri->ri_font->fontheight;
700 1.1 macallan
701 1.1 macallan if (!CHAR_IN_FONT(c, ri->ri_font))
702 1.1 macallan return;
703 1.1 macallan bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
704 1.1 macallan fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
705 1.1 macallan x = ri->ri_xorigin + col * wi;
706 1.1 macallan y = ri->ri_yorigin + row * he;
707 1.1 macallan if (c == 0x20) {
708 1.1 macallan chipsfb_rectfill(sc, x, y, wi, he, bg);
709 1.1 macallan } else {
710 1.1 macallan uc = c-ri->ri_font->firstchar;
711 1.8 macallan data = (uint8_t *)ri->ri_font->data + uc *
712 1.1 macallan ri->ri_fontscale;
713 1.2 macallan chipsfb_setup_mono(sc, x, y, wi, he, fg, bg);
714 1.2 macallan chipsfb_feed(sc, ri->ri_font->stride * he, data);
715 1.1 macallan }
716 1.1 macallan }
717 1.1 macallan }
718 1.1 macallan
719 1.8 macallan static void
720 1.1 macallan chipsfb_setup_mono(struct chipsfb_softc *sc, int xd, int yd, int width,
721 1.8 macallan int height, uint32_t fg, uint32_t bg)
722 1.1 macallan {
723 1.2 macallan uint32_t dst, cmd, stride, size;
724 1.2 macallan
725 1.2 macallan cmd = BLT_PAT_IS_SOLID | BLT_SRC_IS_CPU | BLT_SRC_IS_MONO | ROP_COPY;
726 1.2 macallan
727 1.2 macallan /* we assume 8 bit for now */
728 1.2 macallan dst = xd + yd * sc->linebytes;
729 1.8 macallan
730 1.2 macallan stride = (sc->linebytes << 16);
731 1.2 macallan size = (height << 16) | width;
732 1.8 macallan
733 1.2 macallan chipsfb_wait_idle(sc);
734 1.2 macallan chipsfb_write32(sc, CT_BLT_STRIDE, stride);
735 1.2 macallan chipsfb_write32(sc, CT_BLT_EXPCTL, MONO_SRC_ALIGN_BYTE);
736 1.2 macallan chipsfb_write32(sc, CT_BLT_DSTADDR, dst);
737 1.2 macallan chipsfb_write32(sc, CT_BLT_SRCADDR, 0);
738 1.2 macallan chipsfb_write32(sc, CT_BLT_CONTROL, cmd);
739 1.2 macallan chipsfb_write32(sc, CT_BLT_BG, bg);
740 1.2 macallan chipsfb_write32(sc, CT_BLT_FG, fg);
741 1.2 macallan chipsfb_write32(sc, CT_BLT_SIZE, size);
742 1.1 macallan }
743 1.1 macallan
744 1.8 macallan static void
745 1.2 macallan chipsfb_feed(struct chipsfb_softc *sc, int count, uint8_t *data)
746 1.1 macallan {
747 1.2 macallan int i;
748 1.2 macallan uint32_t latch = 0, bork;
749 1.2 macallan int shift = 0;
750 1.8 macallan
751 1.2 macallan for (i = 0; i < count; i++) {
752 1.2 macallan bork = data[i];
753 1.2 macallan latch |= (bork << shift);
754 1.2 macallan if (shift == 24) {
755 1.2 macallan chipsfb_write32(sc, CT_OFF_DATA, latch);
756 1.2 macallan latch = 0;
757 1.2 macallan shift = 0;
758 1.2 macallan } else
759 1.2 macallan shift += 8;
760 1.2 macallan }
761 1.8 macallan
762 1.2 macallan if (shift != 0) {
763 1.2 macallan chipsfb_write32(sc, CT_OFF_DATA, latch);
764 1.3 macallan }
765 1.8 macallan
766 1.3 macallan /* apparently the chip wants 64bit-aligned data or it won't go idle */
767 1.3 macallan if ((count + 3) & 0x04) {
768 1.2 macallan chipsfb_write32(sc, CT_OFF_DATA, 0);
769 1.8 macallan }
770 1.2 macallan #ifdef CHIPSFB_WAIT
771 1.2 macallan chipsfb_wait_idle(sc);
772 1.2 macallan #endif
773 1.8 macallan }
774 1.1 macallan
775 1.8 macallan #if 0
776 1.1 macallan static void
777 1.8 macallan chipsfb_showpal(struct chipsfb_softc *sc)
778 1.1 macallan {
779 1.1 macallan int i, x = 0;
780 1.8 macallan
781 1.1 macallan for (i = 0; i < 16; i++) {
782 1.1 macallan chipsfb_rectfill(sc, x, 0, 64, 64, i);
783 1.1 macallan x += 64;
784 1.1 macallan }
785 1.1 macallan }
786 1.1 macallan #endif
787 1.1 macallan
788 1.1 macallan #if 0
789 1.1 macallan static int
790 1.1 macallan chipsfb_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
791 1.1 macallan {
792 1.1 macallan
793 1.1 macallan return 0;
794 1.1 macallan }
795 1.1 macallan #endif
796 1.1 macallan
797 1.1 macallan static void
798 1.1 macallan chipsfb_restore_palette(struct chipsfb_softc *sc)
799 1.1 macallan {
800 1.1 macallan int i;
801 1.8 macallan
802 1.1 macallan for (i = 0; i < 256; i++) {
803 1.8 macallan chipsfb_putpalreg(sc,
804 1.8 macallan i,
805 1.8 macallan sc->sc_cmap_red[i],
806 1.1 macallan sc->sc_cmap_green[i],
807 1.1 macallan sc->sc_cmap_blue[i]);
808 1.1 macallan }
809 1.1 macallan }
810 1.1 macallan
811 1.1 macallan /*
812 1.1 macallan * wsdisplay_accessops
813 1.1 macallan */
814 1.1 macallan
815 1.1 macallan static int
816 1.9 christos chipsfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
817 1.1 macallan struct lwp *l)
818 1.1 macallan {
819 1.1 macallan struct vcons_data *vd = v;
820 1.1 macallan struct chipsfb_softc *sc = vd->cookie;
821 1.1 macallan struct wsdisplay_fbinfo *wdf;
822 1.1 macallan struct vcons_screen *ms = vd->active;
823 1.1 macallan
824 1.1 macallan switch (cmd) {
825 1.1 macallan case WSDISPLAYIO_GTYPE:
826 1.1 macallan *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
827 1.1 macallan return 0;
828 1.1 macallan
829 1.1 macallan case WSDISPLAYIO_GINFO:
830 1.1 macallan wdf = (void *)data;
831 1.1 macallan wdf->height = ms->scr_ri.ri_height;
832 1.1 macallan wdf->width = ms->scr_ri.ri_width;
833 1.1 macallan wdf->depth = ms->scr_ri.ri_depth;
834 1.1 macallan wdf->cmsize = 256;
835 1.1 macallan return 0;
836 1.8 macallan
837 1.1 macallan case WSDISPLAYIO_GETCMAP:
838 1.1 macallan return chipsfb_getcmap(sc,
839 1.1 macallan (struct wsdisplay_cmap *)data);
840 1.1 macallan
841 1.1 macallan case WSDISPLAYIO_PUTCMAP:
842 1.1 macallan return chipsfb_putcmap(sc,
843 1.1 macallan (struct wsdisplay_cmap *)data);
844 1.1 macallan
845 1.1 macallan /* PCI config read/write passthrough. */
846 1.1 macallan case PCI_IOC_CFGREAD:
847 1.1 macallan case PCI_IOC_CFGWRITE:
848 1.1 macallan return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
849 1.1 macallan cmd, data, flag, l));
850 1.8 macallan
851 1.1 macallan case WSDISPLAYIO_SMODE:
852 1.1 macallan {
853 1.1 macallan int new_mode = *(int*)data;
854 1.1 macallan if (new_mode != sc->sc_mode) {
855 1.1 macallan sc->sc_mode = new_mode;
856 1.1 macallan if(new_mode == WSDISPLAYIO_MODE_EMUL) {
857 1.8 macallan chipsfb_restore_palette(sc);
858 1.1 macallan vcons_redraw_screen(ms);
859 1.1 macallan }
860 1.1 macallan }
861 1.1 macallan }
862 1.1 macallan return 0;
863 1.1 macallan }
864 1.1 macallan return EPASSTHROUGH;
865 1.1 macallan }
866 1.1 macallan
867 1.1 macallan static paddr_t
868 1.1 macallan chipsfb_mmap(void *v, void *vs, off_t offset, int prot)
869 1.1 macallan {
870 1.1 macallan struct vcons_data *vd = v;
871 1.1 macallan struct chipsfb_softc *sc = vd->cookie;
872 1.1 macallan struct lwp *me;
873 1.1 macallan paddr_t pa;
874 1.8 macallan
875 1.1 macallan /* 'regular' framebuffer mmap()ing */
876 1.4 macallan if (offset < sc->memsize) {
877 1.8 macallan pa = bus_space_mmap(sc->sc_fbt, offset, 0, prot,
878 1.8 macallan BUS_SPACE_MAP_LINEAR);
879 1.1 macallan return pa;
880 1.1 macallan }
881 1.1 macallan
882 1.1 macallan /*
883 1.1 macallan * restrict all other mappings to processes with superuser privileges
884 1.1 macallan * or the kernel itself
885 1.1 macallan */
886 1.1 macallan me = curlwp;
887 1.1 macallan if (me != NULL) {
888 1.1 macallan if (kauth_authorize_generic(me->l_cred, KAUTH_GENERIC_ISSUSER,
889 1.1 macallan NULL) != 0) {
890 1.8 macallan aprint_normal("%s: mmap() rejected.\n", sc->sc_dev.dv_xname);
891 1.1 macallan return -1;
892 1.1 macallan }
893 1.1 macallan }
894 1.1 macallan
895 1.1 macallan if ((offset >= sc->sc_fb) && (offset < (sc->sc_fb + sc->sc_fbsize))) {
896 1.8 macallan pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
897 1.8 macallan BUS_SPACE_MAP_LINEAR);
898 1.1 macallan return pa;
899 1.1 macallan }
900 1.1 macallan
901 1.1 macallan #ifdef macppc
902 1.1 macallan /* allow mapping of IO space */
903 1.1 macallan if ((offset >= 0xf2000000) && (offset < 0xf2800000)) {
904 1.8 macallan pa = bus_space_mmap(sc->sc_iot, offset - 0xf2000000, 0, prot,
905 1.8 macallan BUS_SPACE_MAP_LINEAR);
906 1.1 macallan return pa;
907 1.8 macallan }
908 1.1 macallan #endif
909 1.8 macallan
910 1.1 macallan #ifdef OFB_ALLOW_OTHERS
911 1.1 macallan if (offset >= 0x80000000) {
912 1.8 macallan pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
913 1.8 macallan BUS_SPACE_MAP_LINEAR);
914 1.1 macallan return pa;
915 1.8 macallan }
916 1.1 macallan #endif
917 1.1 macallan return -1;
918 1.1 macallan }
919 1.1 macallan
920 1.1 macallan static void
921 1.1 macallan chipsfb_init_screen(void *cookie, struct vcons_screen *scr,
922 1.1 macallan int existing, long *defattr)
923 1.1 macallan {
924 1.1 macallan struct chipsfb_softc *sc = cookie;
925 1.1 macallan struct rasops_info *ri = &scr->scr_ri;
926 1.8 macallan
927 1.1 macallan ri->ri_depth = sc->bits_per_pixel;
928 1.1 macallan ri->ri_width = sc->width;
929 1.1 macallan ri->ri_height = sc->height;
930 1.1 macallan ri->ri_stride = sc->width;
931 1.1 macallan ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
932 1.1 macallan
933 1.1 macallan ri->ri_bits = bus_space_vaddr(sc->sc_fbt, sc->sc_fbh);
934 1.1 macallan
935 1.1 macallan #ifdef CHIPSFB_DEBUG
936 1.8 macallan aprint_debug("addr: %08lx\n", (ulong)ri->ri_bits);
937 1.1 macallan #endif
938 1.1 macallan if (existing) {
939 1.1 macallan ri->ri_flg |= RI_CLEAR;
940 1.1 macallan }
941 1.8 macallan
942 1.1 macallan rasops_init(ri, sc->height/8, sc->width/8);
943 1.1 macallan ri->ri_caps = WSSCREEN_WSCOLORS;
944 1.1 macallan
945 1.1 macallan rasops_reconfig(ri, sc->height / ri->ri_font->fontheight,
946 1.1 macallan sc->width / ri->ri_font->fontwidth);
947 1.1 macallan
948 1.1 macallan ri->ri_hw = scr;
949 1.1 macallan ri->ri_ops.copyrows = chipsfb_copyrows;
950 1.1 macallan ri->ri_ops.copycols = chipsfb_copycols;
951 1.1 macallan ri->ri_ops.eraserows = chipsfb_eraserows;
952 1.1 macallan ri->ri_ops.erasecols = chipsfb_erasecols;
953 1.1 macallan ri->ri_ops.cursor = chipsfb_cursor;
954 1.1 macallan ri->ri_ops.putchar = chipsfb_putchar;
955 1.1 macallan }
956 1.1 macallan
957 1.1 macallan #if 0
958 1.1 macallan int
959 1.1 macallan chipsfb_load_font(void *v, void *cookie, struct wsdisplay_font *data)
960 1.1 macallan {
961 1.1 macallan
962 1.1 macallan return 0;
963 1.1 macallan }
964 1.1 macallan #endif
965 1.1 macallan
966 1.1 macallan static void
967 1.1 macallan chipsfb_init(struct chipsfb_softc *sc)
968 1.1 macallan {
969 1.1 macallan
970 1.1 macallan chipsfb_wait_idle(sc);
971 1.8 macallan
972 1.1 macallan chipsfb_write_indexed(sc, CT_CONF_INDEX, XR_IO_CONTROL,
973 1.1 macallan ENABLE_CRTC_EXT | ENABLE_ATTR_EXT);
974 1.1 macallan chipsfb_write_indexed(sc, CT_CONF_INDEX, XR_ADDR_MAPPING,
975 1.1 macallan ENABLE_LINEAR);
976 1.1 macallan
977 1.1 macallan /* setup the blitter */
978 1.1 macallan }
979 1.4 macallan
980 1.4 macallan static uint32_t
981 1.4 macallan chipsfb_probe_vram(struct chipsfb_softc *sc)
982 1.4 macallan {
983 1.4 macallan uint32_t ofs = 0x00080000; /* 512kB */
984 1.8 macallan
985 1.4 macallan /*
986 1.4 macallan * advance in 0.5MB steps, see if we can read back what we wrote and
987 1.4 macallan * if what we wrote to 0 is left untouched. Max. fb size is 4MB so
988 1.4 macallan * we voluntarily stop there.
989 1.4 macallan */
990 1.4 macallan chipsfb_write32(sc, 0, 0xf0f0f0f0);
991 1.4 macallan chipsfb_write32(sc, ofs, 0x0f0f0f0f);
992 1.8 macallan while ((chipsfb_read32(sc, 0) == 0xf0f0f0f0) &&
993 1.4 macallan (chipsfb_read32(sc, ofs) == 0x0f0f0f0f) &&
994 1.4 macallan (ofs < 0x00400000)) {
995 1.8 macallan
996 1.4 macallan ofs += 0x00080000;
997 1.4 macallan chipsfb_write32(sc, ofs, 0x0f0f0f0f);
998 1.4 macallan }
999 1.8 macallan
1000 1.4 macallan return ofs;
1001 1.4 macallan }
1002