summitfb.c revision 1.34 1 1.34 macallan /* $NetBSD: summitfb.c,v 1.34 2025/04/28 04:46:58 macallan Exp $ */
2 1.1 macallan
3 1.1 macallan /* $OpenBSD: sti_pci.c,v 1.7 2009/02/06 22:51:04 miod Exp $ */
4 1.1 macallan
5 1.1 macallan /*
6 1.1 macallan * Copyright (c) 2006, 2007 Miodrag Vallat.
7 1.1 macallan ^ 2024 Michael Lorenz
8 1.1 macallan *
9 1.1 macallan * Permission to use, copy, modify, and distribute this software for any
10 1.1 macallan * purpose with or without fee is hereby granted, provided that the above
11 1.1 macallan * copyright notice, this permission notice, and the disclaimer below
12 1.1 macallan * appear in all copies.
13 1.1 macallan *
14 1.1 macallan * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 1.1 macallan * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 1.1 macallan * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 1.1 macallan * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 1.1 macallan * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 1.1 macallan * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 1.1 macallan * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 1.1 macallan */
22 1.1 macallan
23 1.1 macallan /*
24 1.10 macallan * a native driver for HP Visualize FX graphics cards, so far tested only on
25 1.10 macallan * my FX4
26 1.1 macallan * STI portions are from Miodrag Vallat's sti_pci.c
27 1.1 macallan */
28 1.1 macallan
29 1.2 riastrad #include <sys/cdefs.h>
30 1.34 macallan __KERNEL_RCSID(0, "$NetBSD: summitfb.c,v 1.34 2025/04/28 04:46:58 macallan Exp $");
31 1.2 riastrad
32 1.1 macallan #include <sys/param.h>
33 1.1 macallan #include <sys/systm.h>
34 1.1 macallan #include <sys/kmem.h>
35 1.1 macallan #include <sys/device.h>
36 1.1 macallan #include <sys/mutex.h>
37 1.1 macallan
38 1.1 macallan #include <dev/pci/pcivar.h>
39 1.1 macallan #include <dev/pci/pcireg.h>
40 1.1 macallan #include <dev/pci/pcidevs.h>
41 1.1 macallan #include <dev/pci/pciio.h>
42 1.1 macallan
43 1.1 macallan #include <dev/wscons/wsdisplayvar.h>
44 1.1 macallan #include <dev/wscons/wsconsio.h>
45 1.1 macallan #include <dev/wsfont/wsfont.h>
46 1.1 macallan #include <dev/rasops/rasops.h>
47 1.1 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
48 1.1 macallan #include <dev/pci/wsdisplay_pci.h>
49 1.1 macallan #include <dev/wscons/wsdisplay_glyphcachevar.h>
50 1.1 macallan
51 1.1 macallan #include <dev/ic/stireg.h>
52 1.5 macallan #include <dev/ic/summitreg.h>
53 1.1 macallan #include <dev/ic/stivar.h>
54 1.1 macallan
55 1.1 macallan #include "opt_summitfb.h"
56 1.1 macallan
57 1.1 macallan #ifdef SUMMITFB_DEBUG
58 1.3 riastrad #define DPRINTF(s) printf s
59 1.1 macallan #else
60 1.2 riastrad #define DPRINTF(s) __nothing
61 1.1 macallan #endif
62 1.1 macallan
63 1.1 macallan int summitfb_match(device_t, cfdata_t, void *);
64 1.1 macallan void summitfb_attach(device_t, device_t, void *);
65 1.1 macallan
66 1.1 macallan struct summitfb_softc {
67 1.1 macallan device_t sc_dev;
68 1.1 macallan pci_chipset_tag_t sc_pc;
69 1.1 macallan pcitag_t sc_tag;
70 1.1 macallan
71 1.1 macallan /* stuff we need in order to use the STI ROM */
72 1.1 macallan struct sti_softc sc_base;
73 1.1 macallan struct sti_screen sc_scr;
74 1.1 macallan bus_space_handle_t sc_romh;
75 1.1 macallan
76 1.1 macallan int sc_width, sc_height;
77 1.1 macallan int sc_locked;
78 1.1 macallan struct vcons_screen sc_console_screen;
79 1.1 macallan struct wsscreen_descr sc_defaultscreen_descr;
80 1.1 macallan const struct wsscreen_descr *sc_screens[1];
81 1.1 macallan struct wsscreen_list sc_screenlist;
82 1.1 macallan struct vcons_data vd;
83 1.1 macallan int sc_mode;
84 1.1 macallan u_char sc_cmap_red[256];
85 1.1 macallan u_char sc_cmap_green[256];
86 1.1 macallan u_char sc_cmap_blue[256];
87 1.27 macallan uint32_t sc_write_mode, sc_read_mode;
88 1.1 macallan /* cursor stuff */
89 1.1 macallan int sc_cursor_x, sc_cursor_y;
90 1.1 macallan int sc_hot_x, sc_hot_y, sc_enabled;
91 1.12 macallan /* font-in-vram */
92 1.12 macallan struct wsdisplay_font *sc_font;
93 1.12 macallan int sc_font_start; /* x of font area */
94 1.12 macallan int sc_cols; /* chars per line in font area */
95 1.30 macallan uint32_t sc_palette[16];
96 1.1 macallan int sc_video_on;
97 1.1 macallan glyphcache sc_gc;
98 1.1 macallan };
99 1.1 macallan
100 1.1 macallan CFATTACH_DECL_NEW(summitfb, sizeof(struct summitfb_softc),
101 1.1 macallan summitfb_match, summitfb_attach, NULL, NULL);
102 1.1 macallan
103 1.2 riastrad int summitfb_readbar(struct sti_softc *, struct pci_attach_args *, u_int,
104 1.2 riastrad int);
105 1.1 macallan int summitfb_check_rom(struct summitfb_softc *, struct pci_attach_args *);
106 1.1 macallan void summitfb_enable_rom(struct sti_softc *);
107 1.1 macallan void summitfb_disable_rom(struct sti_softc *);
108 1.1 macallan void summitfb_enable_rom_internal(struct summitfb_softc *);
109 1.1 macallan void summitfb_disable_rom_internal(struct summitfb_softc *);
110 1.1 macallan
111 1.1 macallan void summitfb_setup(struct summitfb_softc *);
112 1.1 macallan
113 1.1 macallan /* XXX these really need to go into their own header */
114 1.1 macallan int sti_pci_is_console(struct pci_attach_args *, bus_addr_t *);
115 1.1 macallan int sti_rom_setup(struct sti_rom *, bus_space_tag_t, bus_space_tag_t,
116 1.1 macallan bus_space_handle_t, bus_addr_t *, u_int);
117 1.1 macallan int sti_screen_setup(struct sti_screen *, int);
118 1.1 macallan void sti_describe_screen(struct sti_softc *, struct sti_screen *);
119 1.1 macallan
120 1.2 riastrad #define PCI_ROM_SIZE(mr) \
121 1.2 riastrad (PCI_MAPREG_ROM_ADDR(mr) & -PCI_MAPREG_ROM_ADDR(mr))
122 1.1 macallan
123 1.1 macallan /* wsdisplay stuff */
124 1.1 macallan static int summitfb_ioctl(void *, void *, u_long, void *, int,
125 1.2 riastrad struct lwp *);
126 1.1 macallan static paddr_t summitfb_mmap(void *, void *, off_t, int);
127 1.2 riastrad static void summitfb_init_screen(void *, struct vcons_screen *, int,
128 1.2 riastrad long *);
129 1.1 macallan
130 1.2 riastrad static int summitfb_putcmap(struct summitfb_softc *,
131 1.2 riastrad struct wsdisplay_cmap *);
132 1.2 riastrad static int summitfb_getcmap(struct summitfb_softc *,
133 1.2 riastrad struct wsdisplay_cmap *);
134 1.1 macallan static void summitfb_restore_palette(struct summitfb_softc *);
135 1.1 macallan static int summitfb_putpalreg(struct summitfb_softc *, uint8_t, uint8_t,
136 1.2 riastrad uint8_t, uint8_t);
137 1.1 macallan
138 1.1 macallan static inline void summitfb_setup_fb(struct summitfb_softc *);
139 1.29 macallan static void summitfb_clearfb(struct summitfb_softc *);
140 1.1 macallan static void summitfb_rectfill(struct summitfb_softc *, int, int, int, int,
141 1.2 riastrad uint32_t);
142 1.1 macallan static void summitfb_bitblt(void *, int, int, int, int, int,
143 1.2 riastrad int, int);
144 1.1 macallan
145 1.1 macallan static void summitfb_cursor(void *, int, int, int);
146 1.1 macallan static void summitfb_putchar(void *, int, int, u_int, long);
147 1.1 macallan static void summitfb_putchar_aa(void *, int, int, u_int, long);
148 1.1 macallan static void summitfb_copycols(void *, int, int, int, int);
149 1.1 macallan static void summitfb_erasecols(void *, int, int, int, long);
150 1.1 macallan static void summitfb_copyrows(void *, int, int, int);
151 1.1 macallan static void summitfb_eraserows(void *, int, int, long);
152 1.1 macallan
153 1.1 macallan static void summitfb_move_cursor(struct summitfb_softc *, int, int);
154 1.2 riastrad static int summitfb_do_cursor(struct summitfb_softc *,
155 1.2 riastrad struct wsdisplay_cursor *);
156 1.1 macallan
157 1.1 macallan static void summitfb_set_video(struct summitfb_softc *, int);
158 1.1 macallan
159 1.14 macallan static void summitfb_copyfont(struct summitfb_softc *);
160 1.14 macallan
161 1.1 macallan struct wsdisplay_accessops summitfb_accessops = {
162 1.2 riastrad .ioctl = summitfb_ioctl,
163 1.2 riastrad .mmap = summitfb_mmap,
164 1.2 riastrad .alloc_screen = NULL,
165 1.2 riastrad .free_screen = NULL,
166 1.2 riastrad .show_screen = NULL,
167 1.2 riastrad .load_font = NULL,
168 1.2 riastrad .pollc = NULL,
169 1.2 riastrad .scroll = NULL,
170 1.1 macallan };
171 1.1 macallan
172 1.1 macallan static inline void summitfb_wait_fifo(struct summitfb_softc *, uint32_t);
173 1.8 macallan static inline void summitfb_wait(struct summitfb_softc *);
174 1.1 macallan
175 1.14 macallan int sti_fetchfonts(struct sti_screen *, struct sti_inqconfout *, uint32_t,
176 1.14 macallan u_int);
177 1.14 macallan
178 1.1 macallan int
179 1.1 macallan summitfb_match(device_t parent, cfdata_t cf, void *aux)
180 1.1 macallan {
181 1.1 macallan struct pci_attach_args *paa = aux;
182 1.1 macallan
183 1.1 macallan if (PCI_VENDOR(paa->pa_id) != PCI_VENDOR_HP)
184 1.1 macallan return 0;
185 1.1 macallan
186 1.1 macallan if (PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FX4)
187 1.1 macallan return 10; /* beat out sti at pci */
188 1.1 macallan
189 1.1 macallan return 0;
190 1.1 macallan }
191 1.1 macallan
192 1.1 macallan static inline uint32_t
193 1.1 macallan summitfb_read4(struct summitfb_softc *sc, uint32_t offset)
194 1.1 macallan {
195 1.1 macallan struct sti_rom *rom = sc->sc_base.sc_rom;
196 1.1 macallan bus_space_tag_t memt = rom->memt;
197 1.1 macallan bus_space_handle_t memh = rom->regh[2];
198 1.2 riastrad
199 1.1 macallan return bus_space_read_stream_4(memt, memh, offset - 0x400000);
200 1.1 macallan }
201 1.1 macallan
202 1.1 macallan static inline void
203 1.1 macallan summitfb_write4(struct summitfb_softc *sc, uint32_t offset, uint32_t val)
204 1.1 macallan {
205 1.1 macallan struct sti_rom *rom = sc->sc_base.sc_rom;
206 1.1 macallan bus_space_tag_t memt = rom->memt;
207 1.1 macallan bus_space_handle_t memh = rom->regh[2];
208 1.2 riastrad
209 1.1 macallan bus_space_write_stream_4(memt, memh, offset - 0x400000, val);
210 1.1 macallan }
211 1.1 macallan
212 1.30 macallan static inline void
213 1.30 macallan summitfb_write_mode(struct summitfb_softc *sc, uint32_t mode)
214 1.30 macallan {
215 1.30 macallan if (sc->sc_write_mode == mode)
216 1.30 macallan return;
217 1.30 macallan summitfb_wait(sc);
218 1.30 macallan summitfb_write4(sc, VISFX_VRAM_WRITE_MODE, mode);
219 1.30 macallan sc->sc_write_mode = mode;
220 1.30 macallan }
221 1.30 macallan
222 1.30 macallan static inline void
223 1.30 macallan summitfb_read_mode(struct summitfb_softc *sc, uint32_t mode)
224 1.30 macallan {
225 1.30 macallan if (sc->sc_read_mode == mode)
226 1.30 macallan return;
227 1.30 macallan summitfb_wait(sc);
228 1.30 macallan summitfb_write4(sc, VISFX_VRAM_READ_MODE, mode);
229 1.30 macallan sc->sc_read_mode = mode;
230 1.30 macallan }
231 1.30 macallan
232 1.1 macallan void
233 1.1 macallan summitfb_attach(device_t parent, device_t self, void *aux)
234 1.1 macallan {
235 1.1 macallan struct summitfb_softc *sc = device_private(self);
236 1.1 macallan struct pci_attach_args *paa = aux;
237 1.1 macallan struct sti_rom *rom;
238 1.1 macallan struct rasops_info *ri;
239 1.1 macallan struct wsemuldisplaydev_attach_args aa;
240 1.24 macallan struct sti_dd *dd;
241 1.1 macallan unsigned long defattr = 0;
242 1.1 macallan int ret, is_console = 0;
243 1.1 macallan
244 1.1 macallan sc->sc_dev = self;
245 1.1 macallan
246 1.1 macallan sc->sc_pc = paa->pa_pc;
247 1.1 macallan sc->sc_tag = paa->pa_tag;
248 1.1 macallan sc->sc_base.sc_dev = self;
249 1.1 macallan sc->sc_base.sc_enable_rom = summitfb_enable_rom;
250 1.1 macallan sc->sc_base.sc_disable_rom = summitfb_disable_rom;
251 1.1 macallan
252 1.1 macallan aprint_normal("\n");
253 1.1 macallan
254 1.1 macallan if (summitfb_check_rom(sc, paa) != 0)
255 1.1 macallan return;
256 1.1 macallan
257 1.1 macallan ret = sti_pci_is_console(paa, sc->sc_base. bases);
258 1.1 macallan if (ret != 0) {
259 1.1 macallan sc->sc_base.sc_flags |= STI_CONSOLE;
260 1.1 macallan is_console = 1;
261 1.1 macallan }
262 1.2 riastrad rom = kmem_zalloc(sizeof(*rom), KM_SLEEP);
263 1.1 macallan rom->rom_softc = &sc->sc_base;
264 1.1 macallan ret = sti_rom_setup(rom, paa->pa_iot, paa->pa_memt, sc->sc_romh,
265 1.1 macallan sc->sc_base.bases, STI_CODEBASE_MAIN);
266 1.1 macallan if (ret != 0) {
267 1.1 macallan kmem_free(rom, sizeof(*rom));
268 1.1 macallan return;
269 1.1 macallan }
270 1.1 macallan
271 1.1 macallan sc->sc_base.sc_rom = rom;
272 1.24 macallan dd = &rom->rom_dd;
273 1.1 macallan
274 1.1 macallan sc->sc_scr.scr_rom = sc->sc_base.sc_rom;
275 1.1 macallan ret = sti_screen_setup(&sc->sc_scr, STI_FBMODE);
276 1.22 skrll
277 1.22 skrll sti_fetchfonts(&sc->sc_scr, NULL, dd->dd_fntaddr, 0);
278 1.24 macallan wsfont_init();
279 1.22 skrll summitfb_copyfont(sc);
280 1.22 skrll
281 1.1 macallan sc->sc_width = sc->sc_scr.scr_cfg.scr_width;
282 1.1 macallan sc->sc_height = sc->sc_scr.scr_cfg.scr_height;
283 1.8 macallan sc->sc_write_mode = 0xffffffff;
284 1.27 macallan sc->sc_read_mode = 0xffffffff;
285 1.1 macallan
286 1.1 macallan #ifdef SUMMITFB_DEBUG
287 1.1 macallan sc->sc_height -= 200;
288 1.1 macallan #endif
289 1.1 macallan
290 1.1 macallan sc->sc_defaultscreen_descr = (struct wsscreen_descr){
291 1.2 riastrad .name = "default",
292 1.2 riastrad .ncols = 0, .nrows = 0,
293 1.2 riastrad .textops = NULL,
294 1.2 riastrad .fontwidth = 8, .fontheight = 16,
295 1.2 riastrad .capabilities = WSSCREEN_WSCOLORS | WSSCREEN_HILIT |
296 1.2 riastrad WSSCREEN_UNDERLINE | WSSCREEN_RESIZE,
297 1.2 riastrad .modecookie = NULL,
298 1.1 macallan };
299 1.1 macallan
300 1.1 macallan sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
301 1.1 macallan sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
302 1.1 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
303 1.1 macallan sc->sc_locked = 0;
304 1.1 macallan
305 1.1 macallan vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
306 1.1 macallan &summitfb_accessops);
307 1.1 macallan sc->vd.init_screen = summitfb_init_screen;
308 1.1 macallan sc->vd.show_screen_cookie = &sc->sc_gc;
309 1.1 macallan sc->vd.show_screen_cb = glyphcache_adapt;
310 1.1 macallan ri = &sc->sc_console_screen.scr_ri;
311 1.1 macallan
312 1.1 macallan sc->sc_gc.gc_bitblt = summitfb_bitblt;
313 1.1 macallan sc->sc_gc.gc_blitcookie = sc;
314 1.1 macallan sc->sc_gc.gc_rop = RopSrc;
315 1.12 macallan
316 1.12 macallan summitfb_setup(sc);
317 1.1 macallan
318 1.1 macallan vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1, &defattr);
319 1.1 macallan sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
320 1.1 macallan
321 1.1 macallan sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
322 1.1 macallan sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
323 1.1 macallan sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
324 1.1 macallan sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
325 1.1 macallan
326 1.12 macallan /*
327 1.12 macallan * STI lies to us - it reports a 2048x2048 framebuffer but blitter
328 1.12 macallan * ops wrap around below 1024 and we seem to have only about 250
329 1.13 riastrad * usable columns to the right. Should still be enough to cache
330 1.12 macallan * a font or four.
331 1.12 macallan * So, the framebuffer seems to be 1536x1024, which is odd since the
332 1.12 macallan * FX4 is supposed to support resolutions higher than 1280x1024.
333 1.12 macallan * I guess video memory is allocated in 512x512 chunks
334 1.12 macallan */
335 1.28 riastrad glyphcache_init(&sc->sc_gc,
336 1.27 macallan sc->sc_height,
337 1.12 macallan sc->sc_height,
338 1.27 macallan (sc->sc_width + 511) & (~511),
339 1.2 riastrad ri->ri_font->fontwidth,
340 1.2 riastrad ri->ri_font->fontheight,
341 1.2 riastrad defattr);
342 1.1 macallan
343 1.1 macallan summitfb_restore_palette(sc);
344 1.1 macallan summitfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
345 1.1 macallan ri->ri_devcmap[(defattr >> 16) & 0xff]);
346 1.1 macallan summitfb_setup_fb(sc);
347 1.1 macallan
348 1.1 macallan if (is_console) {
349 1.1 macallan wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
350 1.1 macallan defattr);
351 1.1 macallan
352 1.1 macallan vcons_replay_msgbuf(&sc->sc_console_screen);
353 1.1 macallan }
354 1.1 macallan
355 1.17 macallan aprint_normal_dev(sc->sc_dev, "%s at %dx%d\n", sc->sc_scr.name,
356 1.17 macallan sc->sc_width, sc->sc_height);
357 1.17 macallan
358 1.1 macallan /* no suspend/resume support yet */
359 1.2 riastrad pmf_device_register(sc->sc_dev, NULL, NULL);
360 1.1 macallan
361 1.1 macallan aa.console = is_console;
362 1.1 macallan aa.scrdata = &sc->sc_screenlist;
363 1.1 macallan aa.accessops = &summitfb_accessops;
364 1.1 macallan aa.accesscookie = &sc->vd;
365 1.1 macallan
366 1.1 macallan config_found(sc->sc_dev, &aa, wsemuldisplaydevprint, CFARGS_NONE);
367 1.1 macallan }
368 1.1 macallan
369 1.1 macallan /*
370 1.1 macallan * Grovel the STI ROM image.
371 1.1 macallan */
372 1.1 macallan int
373 1.1 macallan summitfb_check_rom(struct summitfb_softc *spc, struct pci_attach_args *pa)
374 1.1 macallan {
375 1.1 macallan struct sti_softc *sc = &spc->sc_base;
376 1.1 macallan pcireg_t address, mask;
377 1.1 macallan bus_space_handle_t romh;
378 1.1 macallan bus_size_t romsize, subsize, stiromsize;
379 1.1 macallan bus_addr_t selected, offs, suboffs;
380 1.1 macallan uint32_t tmp;
381 1.1 macallan int i;
382 1.1 macallan int rc;
383 1.1 macallan
384 1.1 macallan /* sort of inline sti_pci_enable_rom(sc) */
385 1.1 macallan address = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM);
386 1.1 macallan pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM,
387 1.1 macallan ~PCI_MAPREG_ROM_ENABLE);
388 1.1 macallan mask = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM);
389 1.1 macallan address |= PCI_MAPREG_ROM_ENABLE;
390 1.1 macallan pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, address);
391 1.1 macallan sc->sc_flags |= STI_ROM_ENABLED;
392 1.2 riastrad
393 1.1 macallan /*
394 1.1 macallan * Map the complete ROM for now.
395 1.1 macallan */
396 1.1 macallan romsize = PCI_ROM_SIZE(mask);
397 1.1 macallan DPRINTF(("%s: mapping rom @ %lx for %lx\n", __func__,
398 1.1 macallan (long)PCI_MAPREG_ROM_ADDR(address), (long)romsize));
399 1.1 macallan
400 1.1 macallan rc = bus_space_map(pa->pa_memt, PCI_MAPREG_ROM_ADDR(address), romsize,
401 1.1 macallan 0, &romh);
402 1.1 macallan if (rc != 0) {
403 1.1 macallan aprint_error_dev(sc->sc_dev, "can't map PCI ROM (%d)\n", rc);
404 1.1 macallan goto fail2;
405 1.1 macallan }
406 1.1 macallan
407 1.1 macallan summitfb_disable_rom_internal(spc);
408 1.22 skrll
409 1.1 macallan /*
410 1.1 macallan * Iterate over the ROM images, pick the best candidate.
411 1.1 macallan */
412 1.1 macallan selected = (bus_addr_t)-1;
413 1.1 macallan for (offs = 0; offs < romsize; offs += subsize) {
414 1.1 macallan summitfb_enable_rom_internal(spc);
415 1.1 macallan /*
416 1.1 macallan * Check for a valid ROM header.
417 1.1 macallan */
418 1.1 macallan tmp = bus_space_read_4(pa->pa_memt, romh, offs + 0);
419 1.1 macallan tmp = le32toh(tmp);
420 1.1 macallan if (tmp != 0x55aa0000) {
421 1.1 macallan summitfb_disable_rom_internal(spc);
422 1.1 macallan if (offs == 0) {
423 1.1 macallan aprint_error_dev(sc->sc_dev,
424 1.2 riastrad "invalid PCI ROM header signature"
425 1.2 riastrad " (%08x)\n", tmp);
426 1.1 macallan rc = EINVAL;
427 1.1 macallan }
428 1.1 macallan break;
429 1.1 macallan }
430 1.1 macallan
431 1.1 macallan /*
432 1.1 macallan * Check ROM type.
433 1.1 macallan */
434 1.1 macallan tmp = bus_space_read_4(pa->pa_memt, romh, offs + 4);
435 1.1 macallan tmp = le32toh(tmp);
436 1.1 macallan if (tmp != 0x00000001) { /* 1 == STI ROM */
437 1.1 macallan summitfb_disable_rom_internal(spc);
438 1.1 macallan if (offs == 0) {
439 1.1 macallan aprint_error_dev(sc->sc_dev,
440 1.1 macallan "invalid PCI ROM type (%08x)\n", tmp);
441 1.1 macallan rc = EINVAL;
442 1.1 macallan }
443 1.1 macallan break;
444 1.1 macallan }
445 1.1 macallan
446 1.1 macallan subsize = (bus_addr_t)bus_space_read_2(pa->pa_memt, romh,
447 1.1 macallan offs + 0x0c);
448 1.1 macallan subsize <<= 9;
449 1.1 macallan
450 1.1 macallan #ifdef SUMMITFB_DEBUG
451 1.1 macallan summitfb_disable_rom_internal(spc);
452 1.1 macallan DPRINTF(("ROM offset %08x size %08x type %08x",
453 1.1 macallan (u_int)offs, (u_int)subsize, tmp));
454 1.1 macallan summitfb_enable_rom_internal(spc);
455 1.1 macallan #endif
456 1.1 macallan
457 1.1 macallan /*
458 1.1 macallan * Check for a valid ROM data structure.
459 1.1 macallan * We do not need it except to know what architecture the ROM
460 1.1 macallan * code is for.
461 1.1 macallan */
462 1.1 macallan
463 1.22 skrll suboffs = offs + bus_space_read_2(pa->pa_memt, romh,
464 1.1 macallan offs + 0x18);
465 1.1 macallan tmp = bus_space_read_4(pa->pa_memt, romh, suboffs + 0);
466 1.1 macallan tmp = le32toh(tmp);
467 1.1 macallan if (tmp != 0x50434952) { /* PCIR */
468 1.1 macallan summitfb_disable_rom_internal(spc);
469 1.1 macallan if (offs == 0) {
470 1.1 macallan aprint_error_dev(sc->sc_dev, "invalid PCI data"
471 1.1 macallan " signature (%08x)\n", tmp);
472 1.1 macallan rc = EINVAL;
473 1.1 macallan } else {
474 1.1 macallan DPRINTF((" invalid PCI data signature %08x\n",
475 1.1 macallan tmp));
476 1.1 macallan continue;
477 1.1 macallan }
478 1.1 macallan }
479 1.1 macallan
480 1.1 macallan tmp = bus_space_read_1(pa->pa_memt, romh, suboffs + 0x14);
481 1.1 macallan summitfb_disable_rom_internal(spc);
482 1.1 macallan DPRINTF((" code %02x", tmp));
483 1.1 macallan
484 1.1 macallan switch (tmp) {
485 1.1 macallan #ifdef __hppa__
486 1.1 macallan case 0x10:
487 1.1 macallan if (selected == (bus_addr_t)-1)
488 1.1 macallan selected = offs;
489 1.1 macallan break;
490 1.1 macallan #endif
491 1.1 macallan #ifdef __i386__
492 1.1 macallan case 0x00:
493 1.1 macallan if (selected == (bus_addr_t)-1)
494 1.1 macallan selected = offs;
495 1.1 macallan break;
496 1.1 macallan #endif
497 1.1 macallan default:
498 1.1 macallan DPRINTF((" (wrong architecture)"));
499 1.1 macallan break;
500 1.1 macallan }
501 1.1 macallan DPRINTF(("%s\n", selected == offs ? " -> SELECTED" : ""));
502 1.1 macallan }
503 1.1 macallan
504 1.1 macallan if (selected == (bus_addr_t)-1) {
505 1.1 macallan if (rc == 0) {
506 1.1 macallan aprint_error_dev(sc->sc_dev, "found no ROM with "
507 1.1 macallan "correct microcode architecture\n");
508 1.1 macallan rc = ENOEXEC;
509 1.1 macallan }
510 1.1 macallan goto fail;
511 1.1 macallan }
512 1.1 macallan
513 1.1 macallan /*
514 1.1 macallan * Read the STI region BAR assignments.
515 1.1 macallan */
516 1.1 macallan
517 1.1 macallan summitfb_enable_rom_internal(spc);
518 1.22 skrll offs = selected + bus_space_read_2(pa->pa_memt, romh, selected + 0x0e);
519 1.1 macallan for (i = 0; i < STI_REGION_MAX; i++) {
520 1.1 macallan rc = summitfb_readbar(sc, pa, i,
521 1.1 macallan bus_space_read_1(pa->pa_memt, romh, offs + i));
522 1.1 macallan if (rc != 0)
523 1.1 macallan goto fail;
524 1.1 macallan }
525 1.1 macallan
526 1.1 macallan /*
527 1.1 macallan * Find out where the STI ROM itself lies, and its size.
528 1.1 macallan */
529 1.1 macallan
530 1.1 macallan offs = selected +
531 1.22 skrll bus_space_read_4(pa->pa_memt, romh, selected + 0x08);
532 1.22 skrll stiromsize = bus_space_read_4(pa->pa_memt, romh, offs + 0x18);
533 1.1 macallan stiromsize = le32toh(stiromsize);
534 1.1 macallan summitfb_disable_rom_internal(spc);
535 1.1 macallan
536 1.1 macallan /*
537 1.1 macallan * Replace our mapping with a smaller mapping of only the area
538 1.1 macallan * we are interested in.
539 1.1 macallan */
540 1.1 macallan
541 1.1 macallan DPRINTF(("remapping rom @ %lx for %lx\n",
542 1.1 macallan (long)(PCI_MAPREG_ROM_ADDR(address) + offs), (long)stiromsize));
543 1.1 macallan bus_space_unmap(pa->pa_memt, romh, romsize);
544 1.1 macallan rc = bus_space_map(pa->pa_memt, PCI_MAPREG_ROM_ADDR(address) + offs,
545 1.1 macallan stiromsize, 0, &spc->sc_romh);
546 1.1 macallan if (rc != 0) {
547 1.1 macallan aprint_error_dev(sc->sc_dev, "can't map STI ROM (%d)\n",
548 1.1 macallan rc);
549 1.1 macallan goto fail2;
550 1.1 macallan }
551 1.1 macallan summitfb_disable_rom_internal(spc);
552 1.1 macallan sc->sc_flags &= ~STI_ROM_ENABLED;
553 1.1 macallan
554 1.1 macallan return 0;
555 1.1 macallan
556 1.1 macallan fail:
557 1.1 macallan bus_space_unmap(pa->pa_memt, romh, romsize);
558 1.1 macallan fail2:
559 1.1 macallan summitfb_disable_rom_internal(spc);
560 1.1 macallan
561 1.1 macallan return rc;
562 1.1 macallan }
563 1.1 macallan
564 1.1 macallan /*
565 1.1 macallan * Decode a BAR register.
566 1.1 macallan */
567 1.1 macallan int
568 1.2 riastrad summitfb_readbar(struct sti_softc *sc, struct pci_attach_args *pa,
569 1.2 riastrad u_int region, int bar)
570 1.1 macallan {
571 1.1 macallan bus_addr_t addr;
572 1.1 macallan bus_size_t size;
573 1.1 macallan uint32_t cf;
574 1.1 macallan int rc;
575 1.1 macallan
576 1.1 macallan if (bar == 0) {
577 1.1 macallan sc->bases[region] = 0;
578 1.2 riastrad return 0;
579 1.1 macallan }
580 1.1 macallan
581 1.1 macallan #ifdef DIAGNOSTIC
582 1.1 macallan if (bar < PCI_MAPREG_START || bar > PCI_MAPREG_PPB_END) {
583 1.1 macallan summitfb_disable_rom(sc);
584 1.1 macallan printf("%s: unexpected bar %02x for region %d\n",
585 1.1 macallan device_xname(sc->sc_dev), bar, region);
586 1.1 macallan summitfb_enable_rom(sc);
587 1.1 macallan }
588 1.1 macallan #endif
589 1.1 macallan
590 1.1 macallan cf = pci_conf_read(pa->pa_pc, pa->pa_tag, bar);
591 1.1 macallan
592 1.1 macallan rc = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, PCI_MAPREG_TYPE(cf),
593 1.1 macallan &addr, &size, NULL);
594 1.1 macallan
595 1.1 macallan if (rc != 0) {
596 1.1 macallan summitfb_disable_rom(sc);
597 1.2 riastrad aprint_error_dev(sc->sc_dev, "invalid bar %02x"
598 1.2 riastrad " for region %d\n",
599 1.1 macallan bar, region);
600 1.1 macallan summitfb_enable_rom(sc);
601 1.2 riastrad return rc;
602 1.1 macallan }
603 1.1 macallan
604 1.1 macallan sc->bases[region] = addr;
605 1.2 riastrad return 0;
606 1.1 macallan }
607 1.1 macallan
608 1.1 macallan /*
609 1.1 macallan * Enable PCI ROM.
610 1.1 macallan */
611 1.1 macallan void
612 1.1 macallan summitfb_enable_rom_internal(struct summitfb_softc *spc)
613 1.1 macallan {
614 1.1 macallan pcireg_t address;
615 1.1 macallan
616 1.1 macallan KASSERT(spc != NULL);
617 1.1 macallan
618 1.1 macallan address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM);
619 1.1 macallan address |= PCI_MAPREG_ROM_ENABLE;
620 1.1 macallan pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address);
621 1.1 macallan }
622 1.1 macallan
623 1.1 macallan void
624 1.1 macallan summitfb_enable_rom(struct sti_softc *sc)
625 1.1 macallan {
626 1.1 macallan struct summitfb_softc *spc = device_private(sc->sc_dev);
627 1.1 macallan
628 1.1 macallan if (!ISSET(sc->sc_flags, STI_ROM_ENABLED)) {
629 1.1 macallan summitfb_enable_rom_internal(spc);
630 1.1 macallan }
631 1.1 macallan SET(sc->sc_flags, STI_ROM_ENABLED);
632 1.1 macallan }
633 1.1 macallan
634 1.1 macallan /*
635 1.1 macallan * Disable PCI ROM.
636 1.1 macallan */
637 1.1 macallan void
638 1.1 macallan summitfb_disable_rom_internal(struct summitfb_softc *spc)
639 1.1 macallan {
640 1.1 macallan pcireg_t address;
641 1.1 macallan
642 1.1 macallan KASSERT(spc != NULL);
643 1.1 macallan
644 1.1 macallan address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM);
645 1.1 macallan address &= ~PCI_MAPREG_ROM_ENABLE;
646 1.1 macallan pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address);
647 1.1 macallan }
648 1.1 macallan
649 1.1 macallan void
650 1.1 macallan summitfb_disable_rom(struct sti_softc *sc)
651 1.1 macallan {
652 1.1 macallan struct summitfb_softc *spc = device_private(sc->sc_dev);
653 1.1 macallan
654 1.1 macallan if (ISSET(sc->sc_flags, STI_ROM_ENABLED)) {
655 1.1 macallan summitfb_disable_rom_internal(spc);
656 1.1 macallan }
657 1.1 macallan CLR(sc->sc_flags, STI_ROM_ENABLED);
658 1.1 macallan }
659 1.1 macallan
660 1.1 macallan static inline void
661 1.1 macallan summitfb_wait(struct summitfb_softc *sc)
662 1.1 macallan {
663 1.1 macallan
664 1.2 riastrad while (summitfb_read4(sc, VISFX_STATUS) != 0)
665 1.2 riastrad continue;
666 1.1 macallan }
667 1.1 macallan
668 1.1 macallan static inline void
669 1.1 macallan summitfb_setup_fb(struct summitfb_softc *sc)
670 1.1 macallan {
671 1.2 riastrad
672 1.20 macallan summitfb_wait(sc);
673 1.19 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
674 1.19 macallan summitfb_write_mode(sc, VISFX_WRITE_MODE_PLAIN);
675 1.27 macallan summitfb_read_mode(sc, VISFX_WRITE_MODE_PLAIN);
676 1.19 macallan summitfb_write4(sc, VISFX_APERTURE_ACCESS, VISFX_DEPTH_8);
677 1.30 macallan /* make overlay opaque */
678 1.30 macallan summitfb_write4(sc, VISFX_OTR, OTR_T | OTR_L1 | OTR_L0);
679 1.19 macallan } else {
680 1.19 macallan summitfb_write_mode(sc, OTC01 | BIN8F | BUFFL);
681 1.27 macallan summitfb_read_mode(sc, OTC01 | BIN8F | BUFFL);
682 1.19 macallan summitfb_write4(sc, VISFX_APERTURE_ACCESS, VISFX_DEPTH_32);
683 1.30 macallan /* make overlay transparent */
684 1.30 macallan summitfb_write4(sc, VISFX_OTR, OTR_A);
685 1.20 macallan }
686 1.20 macallan summitfb_write4(sc, VISFX_IBO, RopSrc);
687 1.1 macallan }
688 1.1 macallan
689 1.1 macallan void
690 1.1 macallan summitfb_setup(struct summitfb_softc *sc)
691 1.1 macallan {
692 1.19 macallan int i;
693 1.1 macallan
694 1.1 macallan sc->sc_hot_x = 0;
695 1.1 macallan sc->sc_hot_y = 0;
696 1.1 macallan sc->sc_enabled = 0;
697 1.1 macallan sc->sc_video_on = 1;
698 1.1 macallan
699 1.20 macallan summitfb_wait(sc);
700 1.1 macallan #if 1
701 1.25 macallan /* these control byte swapping */
702 1.25 macallan summitfb_write4(sc, 0xb08044, 0x1b); /* MFU_BSCTD */
703 1.25 macallan summitfb_write4(sc, 0xb08048, 0x1b); /* MFU_BSCCTL */
704 1.25 macallan
705 1.25 macallan summitfb_write4(sc, 0x920860, 0xe4); /* FBC_RBS */
706 1.29 macallan summitfb_write4(sc, 0x921114, 0); /* CPE, clip plane enable */
707 1.25 macallan summitfb_write4(sc, 0x9211d8, 0); /* FCDA */
708 1.25 macallan
709 1.25 macallan summitfb_write4(sc, 0xa00818, 0); /* WORG window origin */
710 1.25 macallan summitfb_write4(sc, 0xa0081c, 0); /* FBS front buffer select*/
711 1.25 macallan summitfb_write4(sc, 0xa00850, 0); /* MISC_CTL */
712 1.25 macallan summitfb_write4(sc, 0xa0086c, 0); /* WCE window clipping enable */
713 1.1 macallan #endif
714 1.25 macallan /* initialize drawiing engine */
715 1.25 macallan summitfb_wait(sc);
716 1.25 macallan summitfb_write4(sc, VISFX_CONTROL, 0); // clear WFC
717 1.25 macallan summitfb_write4(sc, VISFX_APERTURE_ACCESS, VISFX_DEPTH_8);
718 1.25 macallan summitfb_write4(sc, VISFX_PIXEL_MASK, 0xffffffff);
719 1.25 macallan summitfb_write4(sc, VISFX_PLANE_MASK, 0xffffffff);
720 1.25 macallan summitfb_write4(sc, VISFX_FOE, FOE_BLEND_ROP);
721 1.25 macallan summitfb_write4(sc, VISFX_IBO, RopSrc);
722 1.25 macallan summitfb_write_mode(sc, VISFX_WRITE_MODE_PLAIN);
723 1.29 macallan summitfb_read_mode(sc, OTC04 | BIN8I | BUFovl);
724 1.25 macallan summitfb_write4(sc, VISFX_CLIP_TL, 0);
725 1.25 macallan summitfb_write4(sc, VISFX_CLIP_WH,
726 1.25 macallan ((sc->sc_scr.fbwidth) << 16) | (sc->sc_scr.fbheight));
727 1.25 macallan /* turn off the cursor sprite */
728 1.25 macallan summitfb_write4(sc, VISFX_CURSOR_POS, 0);
729 1.30 macallan /* disable throttling by moving the throttle window way off screen */
730 1.30 macallan summitfb_write4(sc, VISFX_TCR, 0x10001000);
731 1.1 macallan
732 1.19 macallan /* make sure the overlay is opaque */
733 1.19 macallan summitfb_write4(sc, VISFX_OTR, OTR_T | OTR_L1 | OTR_L0);
734 1.25 macallan
735 1.19 macallan /*
736 1.27 macallan * initialize XLUT, I mean attribute table
737 1.27 macallan * set all to 24bit, CFS1
738 1.19 macallan */
739 1.21 riastrad for (i = 0; i < 16; i++)
740 1.27 macallan summitfb_write4(sc, VISFX_IAA(i), IAA_8F | IAA_CFS1);
741 1.27 macallan /* RGB8, no LUT */
742 1.19 macallan summitfb_write4(sc, VISFX_CFS(1), CFS_8F | CFS_BYPASS);
743 1.19 macallan /* overlay is 8bit, uses LUT 0 */
744 1.19 macallan summitfb_write4(sc, VISFX_CFS(16), CFS_8I | CFS_LUT0);
745 1.19 macallan summitfb_write4(sc, VISFX_CFS(17), CFS_8I | CFS_LUT0);
746 1.19 macallan
747 1.25 macallan /* zero the attribute plane */
748 1.25 macallan summitfb_write_mode(sc, OTC04 | BINapln);
749 1.29 macallan summitfb_wait_fifo(sc, 12);
750 1.25 macallan summitfb_write4(sc, VISFX_PLANE_MASK, 0xff);
751 1.27 macallan summitfb_write4(sc, VISFX_IBO, 0); /* GXclear */
752 1.29 macallan summitfb_write4(sc, VISFX_FG_COLOUR, 0);
753 1.25 macallan summitfb_write4(sc, VISFX_START, 0);
754 1.25 macallan summitfb_write4(sc, VISFX_SIZE, (sc->sc_width << 16) | sc->sc_height);
755 1.25 macallan summitfb_wait(sc);
756 1.25 macallan summitfb_write4(sc, VISFX_PLANE_MASK, 0xffffffff);
757 1.25 macallan
758 1.19 macallan /* turn off force attr so the above takes effect */
759 1.19 macallan summitfb_write4(sc, VISFX_FATTR, 0);
760 1.19 macallan
761 1.1 macallan summitfb_setup_fb(sc);
762 1.1 macallan }
763 1.1 macallan
764 1.1 macallan static int
765 1.1 macallan summitfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
766 1.2 riastrad struct lwp *l)
767 1.1 macallan {
768 1.1 macallan struct vcons_data *vd = v;
769 1.1 macallan struct summitfb_softc *sc = vd->cookie;
770 1.1 macallan struct wsdisplay_fbinfo *wdf;
771 1.1 macallan struct vcons_screen *ms = vd->active;
772 1.1 macallan
773 1.1 macallan switch (cmd) {
774 1.1 macallan case WSDISPLAYIO_GTYPE:
775 1.1 macallan *(u_int *)data = WSDISPLAY_TYPE_STI;
776 1.1 macallan return 0;
777 1.1 macallan
778 1.1 macallan case GCID:
779 1.4 macallan *(u_int *)data = sc->sc_scr.scr_rom->rom_dd.dd_grid[0];
780 1.1 macallan return 0;
781 1.1 macallan
782 1.1 macallan /* PCI config read/write passthrough. */
783 1.1 macallan case PCI_IOC_CFGREAD:
784 1.1 macallan case PCI_IOC_CFGWRITE:
785 1.1 macallan return pci_devioctl(sc->sc_pc, sc->sc_tag,
786 1.1 macallan cmd, data, flag, l);
787 1.1 macallan
788 1.1 macallan case WSDISPLAYIO_GET_BUSID:
789 1.1 macallan return wsdisplayio_busid_pci(sc->sc_dev, sc->sc_pc,
790 1.1 macallan sc->sc_tag, data);
791 1.1 macallan
792 1.1 macallan case WSDISPLAYIO_GINFO:
793 1.1 macallan if (ms == NULL)
794 1.1 macallan return ENODEV;
795 1.2 riastrad wdf = data;
796 1.1 macallan wdf->height = ms->scr_ri.ri_height;
797 1.1 macallan wdf->width = ms->scr_ri.ri_width;
798 1.1 macallan wdf->depth = ms->scr_ri.ri_depth;
799 1.1 macallan wdf->cmsize = 256;
800 1.1 macallan return 0;
801 1.1 macallan
802 1.1 macallan case WSDISPLAYIO_GETCMAP:
803 1.1 macallan return summitfb_getcmap(sc,
804 1.1 macallan (struct wsdisplay_cmap *)data);
805 1.1 macallan
806 1.1 macallan case WSDISPLAYIO_PUTCMAP:
807 1.1 macallan return summitfb_putcmap(sc,
808 1.1 macallan (struct wsdisplay_cmap *)data);
809 1.1 macallan
810 1.1 macallan case WSDISPLAYIO_LINEBYTES:
811 1.1 macallan *(u_int *)data = 2048;
812 1.1 macallan return 0;
813 1.1 macallan
814 1.1 macallan case WSDISPLAYIO_SMODE: {
815 1.2 riastrad int new_mode = *(int *)data;
816 1.2 riastrad
817 1.1 macallan if (new_mode != sc->sc_mode) {
818 1.1 macallan sc->sc_mode = new_mode;
819 1.1 macallan if(new_mode == WSDISPLAYIO_MODE_EMUL) {
820 1.1 macallan summitfb_setup(sc);
821 1.1 macallan summitfb_restore_palette(sc);
822 1.10 macallan glyphcache_wipe(&sc->sc_gc);
823 1.1 macallan summitfb_rectfill(sc, 0, 0, sc->sc_width,
824 1.1 macallan sc->sc_height, ms->scr_ri.ri_devcmap[
825 1.1 macallan (ms->scr_defattr >> 16) & 0xff]);
826 1.1 macallan vcons_redraw_screen(ms);
827 1.1 macallan summitfb_set_video(sc, 1);
828 1.29 macallan } else
829 1.29 macallan summitfb_clearfb(sc);
830 1.8 macallan summitfb_setup_fb(sc);
831 1.1 macallan }
832 1.1 macallan return 0;
833 1.2 riastrad }
834 1.1 macallan
835 1.2 riastrad case WSDISPLAYIO_GET_FBINFO: {
836 1.2 riastrad struct wsdisplayio_fbinfo *fbi = data;
837 1.2 riastrad int ret;
838 1.2 riastrad
839 1.2 riastrad ret = wsdisplayio_get_fbinfo(&ms->scr_ri, fbi);
840 1.19 macallan //fbi->fbi_fbsize = sc->sc_height * 2048;
841 1.19 macallan fbi->fbi_stride = 8192;
842 1.19 macallan fbi->fbi_bitsperpixel = 32;
843 1.19 macallan fbi->fbi_pixeltype = WSFB_RGB;
844 1.19 macallan fbi->fbi_subtype.fbi_rgbmasks.red_offset = 16;
845 1.19 macallan fbi->fbi_subtype.fbi_rgbmasks.red_size = 8;
846 1.19 macallan fbi->fbi_subtype.fbi_rgbmasks.green_offset = 8;
847 1.19 macallan fbi->fbi_subtype.fbi_rgbmasks.green_size = 8;
848 1.19 macallan fbi->fbi_subtype.fbi_rgbmasks.blue_offset = 0;
849 1.19 macallan fbi->fbi_subtype.fbi_rgbmasks.blue_size = 8;
850 1.19 macallan fbi->fbi_subtype.fbi_rgbmasks.alpha_size = 0;
851 1.19 macallan fbi->fbi_fbsize = sc->sc_scr.fbheight * 8192;
852 1.2 riastrad return ret;
853 1.2 riastrad }
854 1.1 macallan
855 1.2 riastrad case WSDISPLAYIO_GCURPOS: {
856 1.2 riastrad struct wsdisplay_curpos *cp = data;
857 1.1 macallan
858 1.2 riastrad cp->x = sc->sc_cursor_x;
859 1.2 riastrad cp->y = sc->sc_cursor_y;
860 1.1 macallan return 0;
861 1.2 riastrad }
862 1.1 macallan
863 1.2 riastrad case WSDISPLAYIO_SCURPOS: {
864 1.2 riastrad struct wsdisplay_curpos *cp = data;
865 1.1 macallan
866 1.2 riastrad summitfb_move_cursor(sc, cp->x, cp->y);
867 1.1 macallan return 0;
868 1.2 riastrad }
869 1.1 macallan
870 1.2 riastrad case WSDISPLAYIO_GCURMAX: {
871 1.2 riastrad struct wsdisplay_curpos *cp = data;
872 1.1 macallan
873 1.2 riastrad cp->x = 64;
874 1.2 riastrad cp->y = 64;
875 1.1 macallan return 0;
876 1.2 riastrad }
877 1.1 macallan
878 1.2 riastrad case WSDISPLAYIO_SCURSOR: {
879 1.2 riastrad struct wsdisplay_cursor *cursor = data;
880 1.1 macallan
881 1.2 riastrad return summitfb_do_cursor(sc, cursor);
882 1.2 riastrad }
883 1.1 macallan
884 1.1 macallan case WSDISPLAYIO_SVIDEO:
885 1.1 macallan summitfb_set_video(sc, *(int *)data);
886 1.1 macallan return 0;
887 1.1 macallan case WSDISPLAYIO_GVIDEO:
888 1.1 macallan *(u_int *)data = sc->sc_video_on ?
889 1.1 macallan WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF;
890 1.1 macallan return 0;
891 1.1 macallan }
892 1.1 macallan return EPASSTHROUGH;
893 1.1 macallan }
894 1.1 macallan
895 1.1 macallan static paddr_t
896 1.1 macallan summitfb_mmap(void *v, void *vs, off_t offset, int prot)
897 1.1 macallan {
898 1.1 macallan struct vcons_data *vd = v;
899 1.1 macallan struct summitfb_softc *sc = vd->cookie;
900 1.1 macallan struct sti_rom *rom = sc->sc_base.sc_rom;
901 1.1 macallan paddr_t pa = -1;
902 1.1 macallan
903 1.1 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)
904 1.1 macallan return -1;
905 1.1 macallan
906 1.24 macallan if (offset >= 0 && offset < 0x01000000) {
907 1.1 macallan /* framebuffer */
908 1.1 macallan pa = bus_space_mmap(rom->memt, sc->sc_scr.fbaddr, offset,
909 1.1 macallan prot, BUS_SPACE_MAP_LINEAR);
910 1.14 macallan } else if (offset >= 0x80000000 && offset < 0x81000000) {
911 1.1 macallan /* blitter registers etc. */
912 1.4 macallan pa = bus_space_mmap(rom->memt, rom->regh[0],
913 1.1 macallan offset - 0x80000000, prot, BUS_SPACE_MAP_LINEAR);
914 1.1 macallan }
915 1.1 macallan
916 1.1 macallan return pa;
917 1.1 macallan }
918 1.1 macallan
919 1.1 macallan static void
920 1.1 macallan summitfb_init_screen(void *cookie, struct vcons_screen *scr,
921 1.1 macallan int existing, long *defattr)
922 1.1 macallan {
923 1.1 macallan struct summitfb_softc *sc = cookie;
924 1.1 macallan struct rasops_info *ri = &scr->scr_ri;
925 1.1 macallan
926 1.1 macallan ri->ri_depth = 8;
927 1.1 macallan ri->ri_width = sc->sc_width;
928 1.1 macallan ri->ri_height = sc->sc_height;
929 1.1 macallan ri->ri_stride = 2048;
930 1.12 macallan ri->ri_flg = RI_CENTER | RI_8BIT_IS_RGB
931 1.12 macallan | RI_ENABLE_ALPHA | RI_PREFER_ALPHA
932 1.12 macallan ;
933 1.1 macallan
934 1.1 macallan ri->ri_bits = (void *)sc->sc_scr.fbaddr;
935 1.1 macallan rasops_init(ri, 0, 0);
936 1.1 macallan ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE |
937 1.2 riastrad WSSCREEN_RESIZE;
938 1.27 macallan scr->scr_flags |= VCONS_LOADFONT;
939 1.1 macallan
940 1.1 macallan rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
941 1.2 riastrad sc->sc_width / ri->ri_font->fontwidth);
942 1.1 macallan
943 1.1 macallan ri->ri_hw = scr;
944 1.6 macallan
945 1.1 macallan ri->ri_ops.copyrows = summitfb_copyrows;
946 1.1 macallan ri->ri_ops.copycols = summitfb_copycols;
947 1.1 macallan ri->ri_ops.eraserows = summitfb_eraserows;
948 1.1 macallan ri->ri_ops.erasecols = summitfb_erasecols;
949 1.20 macallan ri->ri_ops.cursor = summitfb_cursor;
950 1.27 macallan sc->sc_font = NULL;
951 1.1 macallan if (FONT_IS_ALPHA(ri->ri_font)) {
952 1.1 macallan ri->ri_ops.putchar = summitfb_putchar_aa;
953 1.1 macallan } else
954 1.34 macallan ri->ri_ops.putchar = summitfb_putchar;
955 1.1 macallan }
956 1.1 macallan
957 1.1 macallan static int
958 1.1 macallan summitfb_putcmap(struct summitfb_softc *sc, struct wsdisplay_cmap *cm)
959 1.1 macallan {
960 1.1 macallan u_char *r, *g, *b;
961 1.1 macallan u_int index = cm->index;
962 1.1 macallan u_int count = cm->count;
963 1.1 macallan int i, error;
964 1.1 macallan u_char rbuf[256], gbuf[256], bbuf[256];
965 1.1 macallan
966 1.1 macallan if (cm->index >= 256 || cm->count > 256 ||
967 1.1 macallan (cm->index + cm->count) > 256)
968 1.1 macallan return EINVAL;
969 1.1 macallan error = copyin(cm->red, &rbuf[index], count);
970 1.1 macallan if (error)
971 1.1 macallan return error;
972 1.1 macallan error = copyin(cm->green, &gbuf[index], count);
973 1.1 macallan if (error)
974 1.1 macallan return error;
975 1.1 macallan error = copyin(cm->blue, &bbuf[index], count);
976 1.1 macallan if (error)
977 1.1 macallan return error;
978 1.1 macallan
979 1.1 macallan memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
980 1.1 macallan memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
981 1.1 macallan memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
982 1.1 macallan
983 1.1 macallan r = &sc->sc_cmap_red[index];
984 1.1 macallan g = &sc->sc_cmap_green[index];
985 1.1 macallan b = &sc->sc_cmap_blue[index];
986 1.1 macallan
987 1.1 macallan for (i = 0; i < count; i++) {
988 1.1 macallan summitfb_putpalreg(sc, index, *r, *g, *b);
989 1.1 macallan index++;
990 1.1 macallan r++, g++, b++;
991 1.1 macallan }
992 1.1 macallan return 0;
993 1.1 macallan }
994 1.1 macallan
995 1.1 macallan static int
996 1.1 macallan summitfb_getcmap(struct summitfb_softc *sc, struct wsdisplay_cmap *cm)
997 1.1 macallan {
998 1.1 macallan u_int index = cm->index;
999 1.1 macallan u_int count = cm->count;
1000 1.1 macallan int error;
1001 1.1 macallan
1002 1.1 macallan if (index >= 255 || count > 256 || index + count > 256)
1003 1.1 macallan return EINVAL;
1004 1.1 macallan
1005 1.1 macallan error = copyout(&sc->sc_cmap_red[index], cm->red, count);
1006 1.1 macallan if (error)
1007 1.1 macallan return error;
1008 1.1 macallan error = copyout(&sc->sc_cmap_green[index], cm->green, count);
1009 1.1 macallan if (error)
1010 1.1 macallan return error;
1011 1.1 macallan error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
1012 1.1 macallan if (error)
1013 1.1 macallan return error;
1014 1.1 macallan
1015 1.1 macallan return 0;
1016 1.1 macallan }
1017 1.1 macallan
1018 1.1 macallan static void
1019 1.1 macallan summitfb_restore_palette(struct summitfb_softc *sc)
1020 1.1 macallan {
1021 1.1 macallan uint8_t cmap[768];
1022 1.1 macallan int i, j;
1023 1.1 macallan
1024 1.1 macallan j = 0;
1025 1.1 macallan rasops_get_cmap(&sc->sc_console_screen.scr_ri, cmap, sizeof(cmap));
1026 1.1 macallan for (i = 0; i < 256; i++) {
1027 1.1 macallan sc->sc_cmap_red[i] = cmap[j];
1028 1.1 macallan sc->sc_cmap_green[i] = cmap[j + 1];
1029 1.1 macallan sc->sc_cmap_blue[i] = cmap[j + 2];
1030 1.1 macallan summitfb_putpalreg(sc, i, cmap[j], cmap[j + 1], cmap[j + 2]);
1031 1.1 macallan j += 3;
1032 1.1 macallan }
1033 1.30 macallan for (i = 0; i < 16; i++) {
1034 1.30 macallan sc->sc_palette[i] = (rasops_cmap[i * 3] << 16) |
1035 1.31 skrll (rasops_cmap[i * 3 + 1] << 8) |
1036 1.30 macallan rasops_cmap[i * 3 + 2];
1037 1.30 macallan }
1038 1.30 macallan
1039 1.1 macallan }
1040 1.1 macallan
1041 1.1 macallan static int
1042 1.2 riastrad summitfb_putpalreg(struct summitfb_softc *sc, uint8_t idx,
1043 1.2 riastrad uint8_t r, uint8_t g, uint8_t b)
1044 1.1 macallan {
1045 1.2 riastrad
1046 1.19 macallan summitfb_write4(sc, VISFX_COLOR_INDEX, idx);
1047 1.1 macallan summitfb_write4(sc, VISFX_COLOR_VALUE, (r << 16) | ( g << 8) | b);
1048 1.1 macallan summitfb_write4(sc, VISFX_COLOR_MASK, 0xff);
1049 1.1 macallan return 0;
1050 1.1 macallan }
1051 1.1 macallan
1052 1.1 macallan static inline void
1053 1.1 macallan summitfb_wait_fifo(struct summitfb_softc *sc, uint32_t slots)
1054 1.1 macallan {
1055 1.1 macallan uint32_t reg;
1056 1.2 riastrad
1057 1.1 macallan do {
1058 1.20 macallan reg = summitfb_read4(sc, VISFX_FIFO);
1059 1.1 macallan } while (reg < slots);
1060 1.1 macallan }
1061 1.1 macallan
1062 1.1 macallan static void
1063 1.29 macallan summitfb_clearfb(struct summitfb_softc *sc)
1064 1.29 macallan {
1065 1.29 macallan summitfb_write_mode(sc, OTC32 | BIN8F | BUFBL | BUFFL | 0x8c0);
1066 1.29 macallan summitfb_wait_fifo(sc, 10);
1067 1.29 macallan summitfb_write4(sc, VISFX_IBO, RopSrc);
1068 1.29 macallan summitfb_write4(sc, VISFX_FG_COLOUR, 0);
1069 1.29 macallan summitfb_write4(sc, VISFX_START, 0);
1070 1.29 macallan summitfb_write4(sc, VISFX_SIZE, (sc->sc_width << 16) | sc->sc_height);
1071 1.29 macallan }
1072 1.29 macallan
1073 1.29 macallan static void
1074 1.1 macallan summitfb_rectfill(struct summitfb_softc *sc, int x, int y, int wi, int he,
1075 1.2 riastrad uint32_t bg)
1076 1.1 macallan {
1077 1.2 riastrad
1078 1.8 macallan summitfb_write_mode(sc, VISFX_WRITE_MODE_FILL);
1079 1.29 macallan summitfb_wait_fifo(sc, 10);
1080 1.20 macallan summitfb_write4(sc, VISFX_IBO, RopSrc);
1081 1.1 macallan summitfb_write4(sc, VISFX_FG_COLOUR, bg);
1082 1.1 macallan summitfb_write4(sc, VISFX_START, (x << 16) | y);
1083 1.1 macallan summitfb_write4(sc, VISFX_SIZE, (wi << 16) | he);
1084 1.1 macallan }
1085 1.1 macallan
1086 1.1 macallan static void
1087 1.1 macallan summitfb_bitblt(void *cookie, int xs, int ys, int xd, int yd, int wi,
1088 1.2 riastrad int he, int rop)
1089 1.1 macallan {
1090 1.1 macallan struct summitfb_softc *sc = cookie;
1091 1.27 macallan uint32_t read_mode, write_mode;
1092 1.6 macallan
1093 1.27 macallan read_mode = OTC04 | BIN8I;
1094 1.27 macallan write_mode = OTC04 | BIN8I;
1095 1.27 macallan if (ys >= sc->sc_height) {
1096 1.27 macallan read_mode |= BUFBL;
1097 1.27 macallan ys -= sc->sc_height;
1098 1.27 macallan }
1099 1.27 macallan if (yd >= sc->sc_height) {
1100 1.27 macallan write_mode |= BUFBL;
1101 1.27 macallan yd -= sc->sc_height;
1102 1.27 macallan }
1103 1.27 macallan summitfb_write_mode(sc, write_mode);
1104 1.27 macallan summitfb_read_mode(sc, read_mode);
1105 1.29 macallan summitfb_wait_fifo(sc, 10);
1106 1.20 macallan summitfb_write4(sc, VISFX_IBO, rop);
1107 1.6 macallan summitfb_write4(sc, VISFX_COPY_SRC, (xs << 16) | ys);
1108 1.6 macallan summitfb_write4(sc, VISFX_COPY_WH, (wi << 16) | he);
1109 1.6 macallan summitfb_write4(sc, VISFX_COPY_DST, (xd << 16) | yd);
1110 1.6 macallan
1111 1.1 macallan }
1112 1.1 macallan
1113 1.1 macallan static void
1114 1.1 macallan summitfb_nuke_cursor(struct rasops_info *ri)
1115 1.1 macallan {
1116 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
1117 1.1 macallan struct summitfb_softc *sc = scr->scr_cookie;
1118 1.1 macallan int wi, he, x, y;
1119 1.1 macallan
1120 1.1 macallan if (ri->ri_flg & RI_CURSOR) {
1121 1.1 macallan wi = ri->ri_font->fontwidth;
1122 1.1 macallan he = ri->ri_font->fontheight;
1123 1.1 macallan x = ri->ri_ccol * wi + ri->ri_xorigin;
1124 1.1 macallan y = ri->ri_crow * he + ri->ri_yorigin;
1125 1.20 macallan summitfb_bitblt(sc, x, y, x, y, wi, he, RopInv);
1126 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
1127 1.1 macallan }
1128 1.1 macallan }
1129 1.1 macallan
1130 1.1 macallan static void
1131 1.1 macallan summitfb_cursor(void *cookie, int on, int row, int col)
1132 1.1 macallan {
1133 1.1 macallan struct rasops_info *ri = cookie;
1134 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
1135 1.1 macallan struct summitfb_softc *sc = scr->scr_cookie;
1136 1.1 macallan int x, y, wi, he;
1137 1.1 macallan
1138 1.1 macallan wi = ri->ri_font->fontwidth;
1139 1.1 macallan he = ri->ri_font->fontheight;
1140 1.1 macallan
1141 1.1 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
1142 1.1 macallan if (on) {
1143 1.1 macallan if (ri->ri_flg & RI_CURSOR) {
1144 1.1 macallan summitfb_nuke_cursor(ri);
1145 1.1 macallan }
1146 1.1 macallan x = col * wi + ri->ri_xorigin;
1147 1.1 macallan y = row * he + ri->ri_yorigin;
1148 1.1 macallan summitfb_bitblt(sc, x, y, x, y, wi, he, RopInv);
1149 1.1 macallan ri->ri_flg |= RI_CURSOR;
1150 1.1 macallan }
1151 1.1 macallan ri->ri_crow = row;
1152 1.1 macallan ri->ri_ccol = col;
1153 1.2 riastrad } else {
1154 1.1 macallan ri->ri_crow = row;
1155 1.1 macallan ri->ri_ccol = col;
1156 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
1157 1.1 macallan }
1158 1.1 macallan
1159 1.1 macallan }
1160 1.1 macallan
1161 1.1 macallan static void
1162 1.1 macallan summitfb_putchar(void *cookie, int row, int col, u_int c, long attr)
1163 1.1 macallan {
1164 1.1 macallan struct rasops_info *ri = cookie;
1165 1.1 macallan struct wsdisplay_font *font = PICK_FONT(ri, c);
1166 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
1167 1.1 macallan struct summitfb_softc *sc = scr->scr_cookie;
1168 1.6 macallan void *data;
1169 1.12 macallan int i, x, y, wi, he;
1170 1.1 macallan uint32_t bg, fg, mask;
1171 1.1 macallan
1172 1.1 macallan if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
1173 1.1 macallan return;
1174 1.1 macallan
1175 1.1 macallan if (!CHAR_IN_FONT(c, font))
1176 1.1 macallan return;
1177 1.1 macallan
1178 1.1 macallan if (row == ri->ri_crow && col == ri->ri_ccol) {
1179 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
1180 1.1 macallan }
1181 1.20 macallan
1182 1.1 macallan wi = font->fontwidth;
1183 1.1 macallan he = font->fontheight;
1184 1.1 macallan
1185 1.1 macallan x = ri->ri_xorigin + col * wi;
1186 1.1 macallan y = ri->ri_yorigin + row * he;
1187 1.1 macallan
1188 1.1 macallan bg = ri->ri_devcmap[(attr >> 16) & 0xf];
1189 1.1 macallan
1190 1.1 macallan /* if we're drawing a space we're done here */
1191 1.1 macallan if (c == 0x20) {
1192 1.1 macallan summitfb_rectfill(sc, x, y, wi, he, bg);
1193 1.1 macallan return;
1194 1.1 macallan }
1195 1.1 macallan
1196 1.1 macallan fg = ri->ri_devcmap[(attr >> 24) & 0x0f];
1197 1.1 macallan
1198 1.8 macallan summitfb_write_mode(sc, VISFX_WRITE_MODE_EXPAND);
1199 1.29 macallan summitfb_wait_fifo(sc, 12);
1200 1.20 macallan summitfb_write4(sc, VISFX_IBO, RopSrc);
1201 1.6 macallan summitfb_write4(sc, VISFX_FG_COLOUR, fg);
1202 1.6 macallan summitfb_write4(sc, VISFX_BG_COLOUR, bg);
1203 1.6 macallan mask = 0xffffffff << (32 - wi);
1204 1.6 macallan summitfb_write4(sc, VISFX_PIXEL_MASK, mask);
1205 1.6 macallan /* not a tpyo, coordinates *are* backwards for this register */
1206 1.6 macallan summitfb_write4(sc, VISFX_VRAM_WRITE_DEST, (y << 16) | x);
1207 1.6 macallan
1208 1.6 macallan data = WSFONT_GLYPH(c, font);
1209 1.6 macallan
1210 1.6 macallan if (ri->ri_font->stride == 1) {
1211 1.6 macallan uint8_t *data8 = data;
1212 1.6 macallan for (i = 0; i < he; i++) {
1213 1.6 macallan mask = *data8;
1214 1.9 riastrad summitfb_write4(sc, VISFX_VRAM_WRITE_DATA_INCRY,
1215 1.9 riastrad mask << 24);
1216 1.6 macallan data8++;
1217 1.6 macallan }
1218 1.6 macallan } else {
1219 1.6 macallan uint16_t *data16 = data;
1220 1.6 macallan for (i = 0; i < he; i++) {
1221 1.6 macallan mask = *data16;
1222 1.9 riastrad summitfb_write4(sc, VISFX_VRAM_WRITE_DATA_INCRY,
1223 1.9 riastrad mask << 16);
1224 1.6 macallan data16++;
1225 1.6 macallan }
1226 1.6 macallan }
1227 1.12 macallan }
1228 1.12 macallan
1229 1.12 macallan static void
1230 1.1 macallan summitfb_putchar_aa(void *cookie, int row, int col, u_int c, long attr)
1231 1.1 macallan {
1232 1.1 macallan struct rasops_info *ri = cookie;
1233 1.1 macallan struct wsdisplay_font *font = PICK_FONT(ri, c);
1234 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
1235 1.1 macallan struct summitfb_softc *sc = scr->scr_cookie;
1236 1.30 macallan int x, y, wi, he, rv = GC_NOPE, i, j;
1237 1.30 macallan uint32_t bg, fg, tmp;
1238 1.30 macallan uint8_t *data;
1239 1.1 macallan
1240 1.1 macallan if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
1241 1.1 macallan return;
1242 1.1 macallan
1243 1.1 macallan if (!CHAR_IN_FONT(c, font))
1244 1.1 macallan return;
1245 1.1 macallan
1246 1.1 macallan if (row == ri->ri_crow && col == ri->ri_ccol) {
1247 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
1248 1.1 macallan }
1249 1.1 macallan
1250 1.1 macallan wi = font->fontwidth;
1251 1.1 macallan he = font->fontheight;
1252 1.1 macallan
1253 1.1 macallan x = ri->ri_xorigin + col * wi;
1254 1.1 macallan y = ri->ri_yorigin + row * he;
1255 1.1 macallan
1256 1.1 macallan bg = ri->ri_devcmap[(attr >> 16) & 0xf];
1257 1.1 macallan
1258 1.1 macallan if (c == 0x20) {
1259 1.1 macallan summitfb_rectfill(sc, x, y, wi, he, bg);
1260 1.1 macallan return;
1261 1.1 macallan }
1262 1.1 macallan
1263 1.1 macallan rv = glyphcache_try(&sc->sc_gc, c, x, y, attr);
1264 1.1 macallan if (rv == GC_OK)
1265 1.1 macallan return;
1266 1.1 macallan
1267 1.30 macallan /*
1268 1.30 macallan * first we clear the background - we should be able to use the CBR
1269 1.30 macallan * register as constant background but so far I couldn't make that work
1270 1.30 macallan */
1271 1.30 macallan summitfb_rectfill(sc, x, y, wi, he, bg);
1272 1.30 macallan
1273 1.30 macallan summitfb_write_mode(sc, OTC01 | BIN332F | BUFovl);
1274 1.30 macallan /* we need the foreground colour as full RGB8 */
1275 1.30 macallan fg = sc->sc_palette[(attr >> 24) & 0xf];
1276 1.30 macallan
1277 1.30 macallan /*
1278 1.30 macallan * set the blending equation to
1279 1.30 macallan * src_color * src_alpha + dst_color * (1 - src_alpha)
1280 1.30 macallan */
1281 1.30 macallan summitfb_write4(sc, VISFX_IBO,
1282 1.30 macallan IBO_ADD | SRC(IBO_SRC) | DST(IBO_ONE_MINUS_SRC));
1283 1.1 macallan
1284 1.30 macallan /* get the glyph */
1285 1.30 macallan data = WSFONT_GLYPH(c, font);
1286 1.30 macallan for (i = 0; i < he; i++) {
1287 1.30 macallan /*
1288 1.30 macallan * make some room in the pipeline
1289 1.30 macallan * with just plain ROPs we can just hammer the FIFO without
1290 1.30 macallan * having to worry about overflowing it but I suspect with
1291 1.30 macallan * alpha blending enabled things may be a little slower
1292 1.30 macallan */
1293 1.30 macallan summitfb_wait_fifo(sc, wi * 2);
1294 1.30 macallan /* start a new line */
1295 1.30 macallan summitfb_write4(sc, VISFX_VRAM_WRITE_DEST, ((y + i) << 16) | x);
1296 1.30 macallan for (j = 0; j < wi; j++) {
1297 1.30 macallan tmp = *data;
1298 1.30 macallan /* alpha & RGB -> ARGB */
1299 1.30 macallan summitfb_write4(sc, VISFX_VRAM_WRITE_DATA_INCRX,
1300 1.30 macallan (tmp << 24) | fg);
1301 1.30 macallan data++;
1302 1.30 macallan }
1303 1.30 macallan }
1304 1.31 skrll
1305 1.1 macallan if (rv == GC_ADD)
1306 1.1 macallan glyphcache_add(&sc->sc_gc, c, x, y);
1307 1.1 macallan }
1308 1.1 macallan
1309 1.1 macallan static void
1310 1.1 macallan summitfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
1311 1.1 macallan {
1312 1.1 macallan struct rasops_info *ri = cookie;
1313 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
1314 1.1 macallan struct summitfb_softc *sc = scr->scr_cookie;
1315 1.1 macallan int32_t xs, xd, y, width, height;
1316 1.1 macallan
1317 1.22 skrll if (sc->sc_locked == 0 && sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
1318 1.20 macallan
1319 1.1 macallan if (ri->ri_crow == row &&
1320 1.2 riastrad ri->ri_ccol >= srccol && ri->ri_ccol < (srccol + ncols) &&
1321 1.2 riastrad (ri->ri_flg & RI_CURSOR)) {
1322 1.1 macallan summitfb_nuke_cursor(ri);
1323 1.1 macallan }
1324 1.20 macallan
1325 1.1 macallan xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
1326 1.1 macallan xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
1327 1.1 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1328 1.1 macallan width = ri->ri_font->fontwidth * ncols;
1329 1.1 macallan height = ri->ri_font->fontheight;
1330 1.1 macallan summitfb_bitblt(sc, xs, y, xd, y, width, height, RopSrc);
1331 1.6 macallan
1332 1.1 macallan if (ri->ri_crow == row &&
1333 1.2 riastrad ri->ri_ccol >= dstcol && ri->ri_ccol < (dstcol + ncols))
1334 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
1335 1.1 macallan }
1336 1.1 macallan }
1337 1.1 macallan
1338 1.1 macallan static void
1339 1.2 riastrad summitfb_erasecols(void *cookie, int row, int startcol, int ncols,
1340 1.2 riastrad long fillattr)
1341 1.1 macallan {
1342 1.1 macallan struct rasops_info *ri = cookie;
1343 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
1344 1.1 macallan struct summitfb_softc *sc = scr->scr_cookie;
1345 1.1 macallan int32_t x, y, width, height, fg, bg, ul;
1346 1.1 macallan
1347 1.22 skrll if (sc->sc_locked == 0 && sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
1348 1.1 macallan x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
1349 1.1 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1350 1.1 macallan width = ri->ri_font->fontwidth * ncols;
1351 1.1 macallan height = ri->ri_font->fontheight;
1352 1.1 macallan rasops_unpack_attr(fillattr, &fg, &bg, &ul);
1353 1.1 macallan
1354 1.1 macallan summitfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
1355 1.6 macallan
1356 1.1 macallan if (ri->ri_crow == row &&
1357 1.2 riastrad ri->ri_ccol >= startcol &&
1358 1.2 riastrad ri->ri_ccol < (startcol + ncols))
1359 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
1360 1.1 macallan }
1361 1.1 macallan }
1362 1.1 macallan
1363 1.1 macallan static void
1364 1.1 macallan summitfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
1365 1.1 macallan {
1366 1.1 macallan struct rasops_info *ri = cookie;
1367 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
1368 1.1 macallan struct summitfb_softc *sc = scr->scr_cookie;
1369 1.1 macallan int32_t x, ys, yd, width, height;
1370 1.1 macallan
1371 1.22 skrll if (sc->sc_locked == 0 && sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
1372 1.20 macallan
1373 1.2 riastrad if (ri->ri_crow >= srcrow && ri->ri_crow < (srcrow + nrows) &&
1374 1.2 riastrad (ri->ri_flg & RI_CURSOR)) {
1375 1.1 macallan summitfb_nuke_cursor(ri);
1376 1.1 macallan }
1377 1.20 macallan
1378 1.1 macallan x = ri->ri_xorigin;
1379 1.1 macallan ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
1380 1.1 macallan yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
1381 1.1 macallan width = ri->ri_emuwidth;
1382 1.1 macallan height = ri->ri_font->fontheight * nrows;
1383 1.1 macallan summitfb_bitblt(sc, x, ys, x, yd, width, height, RopSrc);
1384 1.6 macallan
1385 1.1 macallan if (ri->ri_crow >= dstrow && ri->ri_crow < (dstrow + nrows))
1386 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
1387 1.1 macallan }
1388 1.1 macallan }
1389 1.1 macallan
1390 1.1 macallan static void
1391 1.1 macallan summitfb_eraserows(void *cookie, int row, int nrows, long fillattr)
1392 1.1 macallan {
1393 1.1 macallan struct rasops_info *ri = cookie;
1394 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
1395 1.1 macallan struct summitfb_softc *sc = scr->scr_cookie;
1396 1.1 macallan int32_t x, y, width, height, fg, bg, ul;
1397 1.1 macallan
1398 1.22 skrll if (sc->sc_locked == 0 && sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
1399 1.1 macallan x = ri->ri_xorigin;
1400 1.1 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1401 1.1 macallan width = ri->ri_emuwidth;
1402 1.1 macallan height = ri->ri_font->fontheight * nrows;
1403 1.1 macallan rasops_unpack_attr(fillattr, &fg, &bg, &ul);
1404 1.1 macallan
1405 1.1 macallan summitfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
1406 1.1 macallan
1407 1.1 macallan if (ri->ri_crow >= row && ri->ri_crow < (row + nrows))
1408 1.1 macallan ri->ri_flg &= ~RI_CURSOR;
1409 1.1 macallan }
1410 1.1 macallan }
1411 1.1 macallan
1412 1.1 macallan static void
1413 1.1 macallan summitfb_move_cursor(struct summitfb_softc *sc, int x, int y)
1414 1.1 macallan {
1415 1.1 macallan uint32_t pos;
1416 1.1 macallan
1417 1.1 macallan sc->sc_cursor_x = x;
1418 1.1 macallan x -= sc->sc_hot_x;
1419 1.1 macallan sc->sc_cursor_y = y;
1420 1.1 macallan y -= sc->sc_hot_y;
1421 1.1 macallan
1422 1.22 skrll if (x < 0)
1423 1.22 skrll x = 0x1000 - x;
1424 1.22 skrll if (y < 0)
1425 1.22 skrll y = 0x1000 - y;
1426 1.1 macallan pos = (x << 16) | y;
1427 1.22 skrll if (sc->sc_enabled)
1428 1.22 skrll pos |= 0x80000000;
1429 1.4 macallan summitfb_write4(sc, VISFX_CURSOR_POS, pos);
1430 1.1 macallan }
1431 1.1 macallan
1432 1.1 macallan static int
1433 1.1 macallan summitfb_do_cursor(struct summitfb_softc *sc, struct wsdisplay_cursor *cur)
1434 1.1 macallan {
1435 1.2 riastrad
1436 1.1 macallan if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
1437 1.1 macallan sc->sc_enabled = cur->enable;
1438 1.1 macallan cur->which |= WSDISPLAY_CURSOR_DOPOS;
1439 1.1 macallan }
1440 1.1 macallan if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
1441 1.1 macallan sc->sc_hot_x = cur->hot.x;
1442 1.1 macallan sc->sc_hot_y = cur->hot.y;
1443 1.1 macallan cur->which |= WSDISPLAY_CURSOR_DOPOS;
1444 1.1 macallan }
1445 1.1 macallan if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
1446 1.1 macallan summitfb_move_cursor(sc, cur->pos.x, cur->pos.y);
1447 1.1 macallan }
1448 1.1 macallan if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
1449 1.4 macallan uint32_t rgb;
1450 1.1 macallan uint8_t r[2], g[2], b[2];
1451 1.1 macallan
1452 1.1 macallan copyin(cur->cmap.blue, b, 2);
1453 1.1 macallan copyin(cur->cmap.green, g, 2);
1454 1.1 macallan copyin(cur->cmap.red, r, 2);
1455 1.4 macallan summitfb_write4(sc, VISFX_CURSOR_INDEX, 0);
1456 1.4 macallan rgb = r[0] << 16 | g[0] << 8 | b[0];
1457 1.18 macallan summitfb_write4(sc, VISFX_CURSOR_BG, rgb);
1458 1.4 macallan rgb = r[1] << 16 | g[1] << 8 | b[1];
1459 1.18 macallan summitfb_write4(sc, VISFX_CURSOR_FG, rgb);
1460 1.6 macallan
1461 1.1 macallan }
1462 1.1 macallan if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
1463 1.4 macallan
1464 1.1 macallan uint32_t buffer[128], latch, tmp;
1465 1.1 macallan int i;
1466 1.1 macallan
1467 1.1 macallan copyin(cur->mask, buffer, 512);
1468 1.4 macallan summitfb_write4(sc, VISFX_CURSOR_INDEX, 0);
1469 1.1 macallan for (i = 0; i < 128; i += 2) {
1470 1.1 macallan latch = 0;
1471 1.1 macallan tmp = buffer[i] & 0x80808080;
1472 1.1 macallan latch |= tmp >> 7;
1473 1.1 macallan tmp = buffer[i] & 0x40404040;
1474 1.1 macallan latch |= tmp >> 5;
1475 1.1 macallan tmp = buffer[i] & 0x20202020;
1476 1.1 macallan latch |= tmp >> 3;
1477 1.1 macallan tmp = buffer[i] & 0x10101010;
1478 1.1 macallan latch |= tmp >> 1;
1479 1.1 macallan tmp = buffer[i] & 0x08080808;
1480 1.1 macallan latch |= tmp << 1;
1481 1.1 macallan tmp = buffer[i] & 0x04040404;
1482 1.1 macallan latch |= tmp << 3;
1483 1.1 macallan tmp = buffer[i] & 0x02020202;
1484 1.1 macallan latch |= tmp << 5;
1485 1.1 macallan tmp = buffer[i] & 0x01010101;
1486 1.1 macallan latch |= tmp << 7;
1487 1.4 macallan summitfb_write4(sc, VISFX_CURSOR_DATA, latch);
1488 1.1 macallan latch = 0;
1489 1.1 macallan tmp = buffer[i + 1] & 0x80808080;
1490 1.1 macallan latch |= tmp >> 7;
1491 1.1 macallan tmp = buffer[i + 1] & 0x40404040;
1492 1.1 macallan latch |= tmp >> 5;
1493 1.1 macallan tmp = buffer[i + 1] & 0x20202020;
1494 1.1 macallan latch |= tmp >> 3;
1495 1.1 macallan tmp = buffer[i + 1] & 0x10101010;
1496 1.1 macallan latch |= tmp >> 1;
1497 1.1 macallan tmp = buffer[i + 1] & 0x08080808;
1498 1.1 macallan latch |= tmp << 1;
1499 1.1 macallan tmp = buffer[i + 1] & 0x04040404;
1500 1.1 macallan latch |= tmp << 3;
1501 1.1 macallan tmp = buffer[i + 1] & 0x02020202;
1502 1.1 macallan latch |= tmp << 5;
1503 1.1 macallan tmp = buffer[i + 1] & 0x01010101;
1504 1.1 macallan latch |= tmp << 7;
1505 1.4 macallan summitfb_write4(sc, VISFX_CURSOR_DATA, latch);
1506 1.1 macallan }
1507 1.1 macallan
1508 1.4 macallan summitfb_write4(sc, VISFX_CURSOR_INDEX, 0x80);
1509 1.1 macallan copyin(cur->image, buffer, 512);
1510 1.1 macallan for (i = 0; i < 128; i += 2) {
1511 1.1 macallan latch = 0;
1512 1.1 macallan tmp = buffer[i] & 0x80808080;
1513 1.1 macallan latch |= tmp >> 7;
1514 1.1 macallan tmp = buffer[i] & 0x40404040;
1515 1.1 macallan latch |= tmp >> 5;
1516 1.1 macallan tmp = buffer[i] & 0x20202020;
1517 1.1 macallan latch |= tmp >> 3;
1518 1.1 macallan tmp = buffer[i] & 0x10101010;
1519 1.1 macallan latch |= tmp >> 1;
1520 1.1 macallan tmp = buffer[i] & 0x08080808;
1521 1.1 macallan latch |= tmp << 1;
1522 1.1 macallan tmp = buffer[i] & 0x04040404;
1523 1.1 macallan latch |= tmp << 3;
1524 1.1 macallan tmp = buffer[i] & 0x02020202;
1525 1.1 macallan latch |= tmp << 5;
1526 1.1 macallan tmp = buffer[i] & 0x01010101;
1527 1.1 macallan latch |= tmp << 7;
1528 1.4 macallan summitfb_write4(sc, VISFX_CURSOR_DATA, latch);
1529 1.1 macallan latch = 0;
1530 1.1 macallan tmp = buffer[i + 1] & 0x80808080;
1531 1.1 macallan latch |= tmp >> 7;
1532 1.1 macallan tmp = buffer[i + 1] & 0x40404040;
1533 1.1 macallan latch |= tmp >> 5;
1534 1.1 macallan tmp = buffer[i + 1] & 0x20202020;
1535 1.1 macallan latch |= tmp >> 3;
1536 1.1 macallan tmp = buffer[i + 1] & 0x10101010;
1537 1.1 macallan latch |= tmp >> 1;
1538 1.1 macallan tmp = buffer[i + 1] & 0x08080808;
1539 1.1 macallan latch |= tmp << 1;
1540 1.1 macallan tmp = buffer[i + 1] & 0x04040404;
1541 1.1 macallan latch |= tmp << 3;
1542 1.1 macallan tmp = buffer[i + 1] & 0x02020202;
1543 1.1 macallan latch |= tmp << 5;
1544 1.1 macallan tmp = buffer[i + 1] & 0x01010101;
1545 1.1 macallan latch |= tmp << 7;
1546 1.4 macallan summitfb_write4(sc, VISFX_CURSOR_DATA, latch);
1547 1.1 macallan }
1548 1.1 macallan }
1549 1.1 macallan
1550 1.1 macallan return 0;
1551 1.1 macallan }
1552 1.1 macallan
1553 1.1 macallan static void
1554 1.1 macallan summitfb_set_video(struct summitfb_softc *sc, int on)
1555 1.1 macallan {
1556 1.2 riastrad
1557 1.1 macallan if (sc->sc_video_on == on)
1558 1.1 macallan return;
1559 1.1 macallan
1560 1.1 macallan sc->sc_video_on = on;
1561 1.1 macallan
1562 1.1 macallan summitfb_wait(sc);
1563 1.1 macallan if (on) {
1564 1.19 macallan summitfb_write4(sc, VISFX_MPC, MPC_VIDEO_ON);
1565 1.1 macallan } else {
1566 1.19 macallan summitfb_write4(sc, VISFX_MPC, MPC_VSYNC_OFF | MPC_HSYNC_OFF);
1567 1.1 macallan }
1568 1.1 macallan }
1569 1.14 macallan
1570 1.14 macallan static void
1571 1.14 macallan summitfb_copyfont(struct summitfb_softc *sc)
1572 1.14 macallan {
1573 1.14 macallan struct sti_font *fp = &sc->sc_scr.scr_curfont;
1574 1.14 macallan uint8_t *font = sc->sc_scr.scr_romfont;
1575 1.14 macallan uint8_t *fontbuf, *fontdata, *src, *dst;
1576 1.14 macallan struct wsdisplay_font *f;
1577 1.14 macallan int bufsize, i, si;
1578 1.14 macallan
1579 1.22 skrll if (font == NULL)
1580 1.22 skrll return;
1581 1.26 skrll
1582 1.26 skrll bufsize = sizeof(struct wsdisplay_font) + 32 + fp->bpc * (fp->last - fp->first);
1583 1.17 macallan DPRINTF(("%s: %dx%d %d\n", __func__, fp->width, fp->height, bufsize));
1584 1.26 skrll fontbuf = kmem_alloc(bufsize, KM_SLEEP);
1585 1.14 macallan f = (struct wsdisplay_font *)fontbuf;
1586 1.14 macallan f->name = fontbuf + sizeof(struct wsdisplay_font);
1587 1.14 macallan fontdata = fontbuf + sizeof(struct wsdisplay_font) + 32;
1588 1.14 macallan strcpy(fontbuf + sizeof(struct wsdisplay_font), "HP ROM");
1589 1.14 macallan f->firstchar = fp->first;
1590 1.14 macallan f->numchars = (fp->last + 1) - fp->first;
1591 1.14 macallan f->encoding = WSDISPLAY_FONTENC_ISO;
1592 1.14 macallan f->fontwidth = fp->width;
1593 1.14 macallan f->fontheight = fp->height;
1594 1.14 macallan f->stride = (fp->width + 7) >> 3;
1595 1.14 macallan f->bitorder = WSDISPLAY_FONTORDER_L2R;
1596 1.14 macallan f->byteorder = WSDISPLAY_FONTORDER_L2R;
1597 1.14 macallan f->data = fontdata;
1598 1.14 macallan /* skip over font struct */
1599 1.14 macallan font += sizeof(struct sti_font);
1600 1.14 macallan /* now copy and rearrange the glyphs into ISO order */
1601 1.14 macallan /* first, copy the characters up to 0x7f */
1602 1.14 macallan memcpy(fontdata, font, (0x80 - fp->first) * fp->bpc);
1603 1.14 macallan /* zero 0x80 to 0x9f */
1604 1.14 macallan memset(fontdata + 0x80 * fp->bpc, 0, 0x20 * fp->bpc);
1605 1.14 macallan /* rearrange 0xa0 till last */
1606 1.14 macallan for (i = 0xa0; i < (fp->last + 1); i++) {
1607 1.14 macallan dst = fontdata + fp->bpc * i;
1608 1.14 macallan si = sti_unitoroman[i - 0xa0];
1609 1.14 macallan if (si != 0) {
1610 1.14 macallan src = font + fp->bpc * si;
1611 1.14 macallan memcpy(dst, src, fp->bpc);
1612 1.14 macallan } else {
1613 1.32 andvar /* no mapping - zero this cell */
1614 1.14 macallan memset(dst, 0, fp->bpc);
1615 1.14 macallan }
1616 1.14 macallan }
1617 1.14 macallan wsfont_add(f, 0);
1618 1.14 macallan }
1619