crmfb.c revision 1.11 1 1.11 macallan /* $NetBSD: crmfb.c,v 1.11 2008/02/05 21:39:25 macallan Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2007 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill * 3. All advertising materials mentioning features or use of this software
16 1.1 jmcneill * must display the following acknowledgement:
17 1.1 jmcneill * This product includes software developed by Jared D. McNeill.
18 1.1 jmcneill * 4. Neither the name of The NetBSD Foundation nor the names of its
19 1.1 jmcneill * contributors may be used to endorse or promote products derived
20 1.1 jmcneill * from this software without specific prior written permission.
21 1.1 jmcneill *
22 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.1 jmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.1 jmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.1 jmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.1 jmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1 jmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1 jmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1 jmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1 jmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1 jmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1 jmcneill * POSSIBILITY OF SUCH DAMAGE.
33 1.1 jmcneill */
34 1.1 jmcneill
35 1.1 jmcneill /*
36 1.1 jmcneill * SGI-CRM (O2) Framebuffer driver
37 1.1 jmcneill */
38 1.1 jmcneill
39 1.1 jmcneill #include <sys/cdefs.h>
40 1.11 macallan __KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1.11 2008/02/05 21:39:25 macallan Exp $");
41 1.1 jmcneill
42 1.1 jmcneill #include <sys/param.h>
43 1.1 jmcneill #include <sys/systm.h>
44 1.1 jmcneill #include <sys/device.h>
45 1.1 jmcneill #include <sys/malloc.h>
46 1.1 jmcneill
47 1.1 jmcneill #define _SGIMIPS_BUS_DMA_PRIVATE
48 1.1 jmcneill #include <machine/autoconf.h>
49 1.1 jmcneill #include <machine/bus.h>
50 1.1 jmcneill #include <machine/machtype.h>
51 1.1 jmcneill #include <machine/vmparam.h>
52 1.1 jmcneill
53 1.2 jmcneill #include <dev/arcbios/arcbios.h>
54 1.2 jmcneill #include <dev/arcbios/arcbiosvar.h>
55 1.2 jmcneill
56 1.1 jmcneill #include <dev/wscons/wsdisplayvar.h>
57 1.1 jmcneill #include <dev/wscons/wsconsio.h>
58 1.1 jmcneill #include <dev/wsfont/wsfont.h>
59 1.1 jmcneill #include <dev/rasops/rasops.h>
60 1.1 jmcneill #include <dev/wscons/wsdisplay_vconsvar.h>
61 1.1 jmcneill
62 1.7 macallan #include <arch/sgimips/dev/crmfbreg.h>
63 1.7 macallan
64 1.11 macallan /* #define CRMFB_DEBUG */
65 1.3 jmcneill
66 1.1 jmcneill struct wsscreen_descr crmfb_defaultscreen = {
67 1.1 jmcneill "default",
68 1.1 jmcneill 0, 0,
69 1.1 jmcneill NULL,
70 1.1 jmcneill 8, 16,
71 1.1 jmcneill WSSCREEN_WSCOLORS,
72 1.1 jmcneill NULL,
73 1.1 jmcneill };
74 1.1 jmcneill
75 1.1 jmcneill const struct wsscreen_descr *_crmfb_scrlist[] = {
76 1.1 jmcneill &crmfb_defaultscreen,
77 1.1 jmcneill };
78 1.1 jmcneill
79 1.1 jmcneill struct wsscreen_list crmfb_screenlist = {
80 1.1 jmcneill sizeof(_crmfb_scrlist) / sizeof(struct wsscreen_descr *),
81 1.1 jmcneill _crmfb_scrlist
82 1.1 jmcneill };
83 1.1 jmcneill
84 1.1 jmcneill static struct vcons_screen crmfb_console_screen;
85 1.1 jmcneill
86 1.1 jmcneill static int crmfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
87 1.1 jmcneill static paddr_t crmfb_mmap(void *, void *, off_t, int);
88 1.1 jmcneill static void crmfb_init_screen(void *, struct vcons_screen *, int, long *);
89 1.1 jmcneill
90 1.1 jmcneill struct wsdisplay_accessops crmfb_accessops = {
91 1.1 jmcneill crmfb_ioctl,
92 1.1 jmcneill crmfb_mmap,
93 1.1 jmcneill NULL, /* alloc_screen */
94 1.1 jmcneill NULL, /* free_screen */
95 1.1 jmcneill NULL, /* show_screen */
96 1.1 jmcneill NULL, /* load_font */
97 1.1 jmcneill NULL, /* pollc */
98 1.1 jmcneill NULL, /* scroll */
99 1.1 jmcneill };
100 1.1 jmcneill
101 1.1 jmcneill /* Memory to allocate to SGI-CRM -- remember, this is stolen from
102 1.1 jmcneill * host memory!
103 1.1 jmcneill */
104 1.1 jmcneill #define CRMFB_TILESIZE (512*128)
105 1.1 jmcneill
106 1.1 jmcneill static int crmfb_match(struct device *, struct cfdata *, void *);
107 1.1 jmcneill static void crmfb_attach(struct device *, struct device *, void *);
108 1.1 jmcneill int crmfb_probe(void);
109 1.1 jmcneill
110 1.1 jmcneill #define KERNADDR(p) ((void *)((p).addr))
111 1.1 jmcneill #define DMAADDR(p) ((p).map->dm_segs[0].ds_addr)
112 1.1 jmcneill
113 1.10 sekiya #define CRMFB_REG_MASK(msb, lsb) \
114 1.10 sekiya ( (((uint32_t) 1 << ((msb)-(lsb)+1)) - 1) << (lsb) )
115 1.10 sekiya
116 1.10 sekiya
117 1.1 jmcneill struct crmfb_dma {
118 1.1 jmcneill bus_dmamap_t map;
119 1.1 jmcneill void *addr;
120 1.1 jmcneill bus_dma_segment_t segs[1];
121 1.1 jmcneill int nsegs;
122 1.1 jmcneill size_t size;
123 1.1 jmcneill };
124 1.1 jmcneill
125 1.1 jmcneill struct crmfb_softc {
126 1.1 jmcneill struct device sc_dev;
127 1.1 jmcneill struct vcons_data sc_vd;
128 1.1 jmcneill
129 1.1 jmcneill bus_space_tag_t sc_iot;
130 1.1 jmcneill bus_space_handle_t sc_ioh;
131 1.11 macallan bus_space_handle_t sc_reh;
132 1.7 macallan
133 1.1 jmcneill bus_dma_tag_t sc_dmat;
134 1.1 jmcneill
135 1.1 jmcneill struct crmfb_dma sc_dma;
136 1.1 jmcneill struct crmfb_dma sc_dmai;
137 1.1 jmcneill
138 1.1 jmcneill int sc_width;
139 1.1 jmcneill int sc_height;
140 1.1 jmcneill int sc_depth;
141 1.11 macallan int sc_tiles_x, sc_tiles_y;
142 1.1 jmcneill uint32_t sc_fbsize;
143 1.11 macallan uint8_t *sc_scratch;
144 1.11 macallan struct rasops_info sc_rasops;
145 1.11 macallan int sc_cells;
146 1.11 macallan int sc_current_cell;
147 1.1 jmcneill int sc_wsmode;
148 1.6 macallan
149 1.6 macallan /* cursor stuff */
150 1.6 macallan int sc_cur_x;
151 1.6 macallan int sc_cur_y;
152 1.6 macallan int sc_hot_x;
153 1.6 macallan int sc_hot_y;
154 1.6 macallan
155 1.1 jmcneill u_char sc_cmap_red[256];
156 1.1 jmcneill u_char sc_cmap_green[256];
157 1.1 jmcneill u_char sc_cmap_blue[256];
158 1.1 jmcneill };
159 1.1 jmcneill
160 1.1 jmcneill static int crmfb_putcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
161 1.1 jmcneill static int crmfb_getcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
162 1.1 jmcneill static void crmfb_set_palette(struct crmfb_softc *,
163 1.1 jmcneill int, uint8_t, uint8_t, uint8_t);
164 1.6 macallan static int crmfb_set_curpos(struct crmfb_softc *, int, int);
165 1.6 macallan static int crmfb_gcursor(struct crmfb_softc *, struct wsdisplay_cursor *);
166 1.6 macallan static int crmfb_scursor(struct crmfb_softc *, struct wsdisplay_cursor *);
167 1.7 macallan static inline void crmfb_write_reg(struct crmfb_softc *, int, uint32_t);
168 1.11 macallan static inline uint32_t crmfb_read_reg(struct crmfb_softc *, int);
169 1.11 macallan static int crmfb_wait_dma_idle(struct crmfb_softc *);
170 1.7 macallan
171 1.7 macallan /* setup video hw in given colour depth */
172 1.7 macallan static int crmfb_setup_video(struct crmfb_softc *, int);
173 1.7 macallan static void crmfb_setup_palette(struct crmfb_softc *);
174 1.1 jmcneill
175 1.11 macallan #ifdef CRMFB_DEBUG
176 1.11 macallan void crmfb_test_mte(struct crmfb_softc *);
177 1.11 macallan #endif
178 1.11 macallan
179 1.11 macallan static void crmfb_fill_rect(struct crmfb_softc *, int, int, int, int, uint32_t);
180 1.11 macallan static void crmfb_bitblt(struct crmfb_softc *, int, int, int, int, int, int,
181 1.11 macallan uint32_t);
182 1.11 macallan
183 1.11 macallan static void crmfb_copycols(void *, int, int, int, int);
184 1.11 macallan static void crmfb_erasecols(void *, int, int, int, long);
185 1.11 macallan static void crmfb_copyrows(void *, int, int, int);
186 1.11 macallan static void crmfb_eraserows(void *, int, int, long);
187 1.11 macallan //static void crmfb_putchar(void *, int, int, u_int, long);
188 1.11 macallan static void crmfb_cursor(void *, int, int, int);
189 1.11 macallan static void crmfb_putchar(void *, int, int, u_int, long);
190 1.11 macallan
191 1.1 jmcneill CFATTACH_DECL(crmfb, sizeof(struct crmfb_softc),
192 1.1 jmcneill crmfb_match, crmfb_attach, NULL, NULL);
193 1.1 jmcneill
194 1.1 jmcneill static int
195 1.1 jmcneill crmfb_match(struct device *parent, struct cfdata *cf, void *opaque)
196 1.1 jmcneill {
197 1.1 jmcneill return crmfb_probe();
198 1.1 jmcneill }
199 1.1 jmcneill
200 1.1 jmcneill static void
201 1.1 jmcneill crmfb_attach(struct device *parent, struct device *self, void *opaque)
202 1.1 jmcneill {
203 1.1 jmcneill struct mainbus_attach_args *ma;
204 1.1 jmcneill struct crmfb_softc *sc;
205 1.1 jmcneill struct rasops_info *ri;
206 1.1 jmcneill struct wsemuldisplaydev_attach_args aa;
207 1.1 jmcneill uint32_t d, h;
208 1.1 jmcneill uint16_t *p;
209 1.1 jmcneill unsigned long v;
210 1.1 jmcneill long defattr;
211 1.2 jmcneill const char *consdev;
212 1.11 macallan int rv, i;
213 1.1 jmcneill
214 1.1 jmcneill sc = (struct crmfb_softc *)self;
215 1.1 jmcneill ma = (struct mainbus_attach_args *)opaque;
216 1.1 jmcneill
217 1.1 jmcneill sc->sc_iot = SGIMIPS_BUS_SPACE_CRIME;
218 1.1 jmcneill sc->sc_dmat = &sgimips_default_bus_dma_tag;
219 1.1 jmcneill sc->sc_wsmode = WSDISPLAYIO_MODE_EMUL;
220 1.1 jmcneill
221 1.1 jmcneill aprint_normal(": SGI CRIME Graphics Display Engine\n");
222 1.1 jmcneill rv = bus_space_map(sc->sc_iot, ma->ma_addr, 0 /* XXX */,
223 1.1 jmcneill BUS_SPACE_MAP_LINEAR, &sc->sc_ioh);
224 1.1 jmcneill if (rv)
225 1.1 jmcneill panic("crmfb_attach: can't map I/O space");
226 1.11 macallan rv = bus_space_map(sc->sc_iot, 0x15000000, 0x6000, 0, &sc->sc_reh);
227 1.11 macallan if (rv)
228 1.11 macallan panic("crmfb_attach: can't map rendering engine");
229 1.1 jmcneill
230 1.1 jmcneill /* determine mode configured by firmware */
231 1.9 jmcneill d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_HCMAP);
232 1.9 jmcneill sc->sc_width = (d >> CRMFB_VT_HCMAP_ON_SHIFT) & 0xfff;
233 1.1 jmcneill d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_VCMAP);
234 1.9 jmcneill sc->sc_height = (d >> CRMFB_VT_VCMAP_ON_SHIFT) & 0xfff;
235 1.1 jmcneill d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
236 1.1 jmcneill h = (d >> CRMFB_FRM_TILESIZE_DEPTH_SHIFT) & 0x3;
237 1.1 jmcneill if (h == 0)
238 1.1 jmcneill sc->sc_depth = 8;
239 1.1 jmcneill else if (h == 1)
240 1.1 jmcneill sc->sc_depth = 16;
241 1.1 jmcneill else
242 1.1 jmcneill sc->sc_depth = 32;
243 1.1 jmcneill
244 1.4 martin if (sc->sc_width == 0 || sc->sc_height == 0) {
245 1.4 martin printf("%s: device unusable if not setup by firmware\n",
246 1.4 martin sc->sc_dev.dv_xname);
247 1.4 martin bus_space_unmap(sc->sc_iot, sc->sc_ioh, 0 /* XXX */);
248 1.4 martin return;
249 1.4 martin }
250 1.4 martin
251 1.7 macallan printf("%s: initial resolution %dx%d\n",
252 1.7 macallan sc->sc_dev.dv_xname, sc->sc_width, sc->sc_height);
253 1.1 jmcneill
254 1.7 macallan /*
255 1.7 macallan * first determine how many tiles we need
256 1.7 macallan * in 32bit each tile is 128x128 pixels
257 1.7 macallan */
258 1.11 macallan sc->sc_tiles_x = (sc->sc_width + 127) >> 7;
259 1.11 macallan sc->sc_tiles_y = (sc->sc_height + 127) >> 7;
260 1.11 macallan sc->sc_fbsize = 0x10000 * sc->sc_tiles_x * sc->sc_tiles_y;
261 1.11 macallan printf("so we need %d x %d tiles -> %08x\n", sc->sc_tiles_x,
262 1.11 macallan sc->sc_tiles_y, sc->sc_fbsize);
263 1.1 jmcneill
264 1.7 macallan sc->sc_dmai.size = 256 * sizeof(uint16_t);
265 1.1 jmcneill rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dmai.size, 65536, 0,
266 1.1 jmcneill sc->sc_dmai.segs,
267 1.1 jmcneill sizeof(sc->sc_dmai.segs) / sizeof(sc->sc_dmai.segs[0]),
268 1.1 jmcneill &sc->sc_dmai.nsegs, BUS_DMA_NOWAIT);
269 1.1 jmcneill if (rv)
270 1.1 jmcneill panic("crmfb_attach: can't allocate DMA memory");
271 1.1 jmcneill rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dmai.segs, sc->sc_dmai.nsegs,
272 1.1 jmcneill sc->sc_dmai.size, &sc->sc_dmai.addr,
273 1.1 jmcneill BUS_DMA_NOWAIT);
274 1.1 jmcneill if (rv)
275 1.1 jmcneill panic("crmfb_attach: can't map DMA memory");
276 1.1 jmcneill rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dmai.size, 1,
277 1.1 jmcneill sc->sc_dmai.size, 0, BUS_DMA_NOWAIT, &sc->sc_dmai.map);
278 1.1 jmcneill if (rv)
279 1.1 jmcneill panic("crmfb_attach: can't create DMA map");
280 1.1 jmcneill rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dmai.map, sc->sc_dmai.addr,
281 1.1 jmcneill sc->sc_dmai.size, NULL, BUS_DMA_NOWAIT);
282 1.1 jmcneill if (rv)
283 1.1 jmcneill panic("crmfb_attach: can't load DMA map");
284 1.1 jmcneill
285 1.11 macallan /* allocate an extra tile for character drawing */
286 1.11 macallan sc->sc_dma.size = sc->sc_fbsize + 0x10000;
287 1.1 jmcneill rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dma.size, 65536, 0,
288 1.1 jmcneill sc->sc_dma.segs,
289 1.1 jmcneill sizeof(sc->sc_dma.segs) / sizeof(sc->sc_dma.segs[0]),
290 1.1 jmcneill &sc->sc_dma.nsegs, BUS_DMA_NOWAIT);
291 1.1 jmcneill if (rv)
292 1.1 jmcneill panic("crmfb_attach: can't allocate DMA memory");
293 1.1 jmcneill rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dma.segs, sc->sc_dma.nsegs,
294 1.1 jmcneill sc->sc_dma.size, &sc->sc_dma.addr,
295 1.1 jmcneill BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
296 1.1 jmcneill if (rv)
297 1.1 jmcneill panic("crmfb_attach: can't map DMA memory");
298 1.1 jmcneill rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dma.size, 1,
299 1.1 jmcneill sc->sc_dma.size, 0, BUS_DMA_NOWAIT, &sc->sc_dma.map);
300 1.1 jmcneill if (rv)
301 1.1 jmcneill panic("crmfb_attach: can't create DMA map");
302 1.1 jmcneill rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dma.map, sc->sc_dma.addr,
303 1.1 jmcneill sc->sc_dma.size, NULL, BUS_DMA_NOWAIT);
304 1.1 jmcneill if (rv)
305 1.1 jmcneill panic("crmfb_attach: can't load DMA map");
306 1.1 jmcneill
307 1.1 jmcneill p = KERNADDR(sc->sc_dmai);
308 1.1 jmcneill v = (unsigned long)DMAADDR(sc->sc_dma);
309 1.11 macallan for (i = 0; i < (sc->sc_tiles_x * sc->sc_tiles_y); i++) {
310 1.1 jmcneill p[i] = ((uint32_t)v >> 16) + i;
311 1.1 jmcneill }
312 1.11 macallan sc->sc_scratch = (char *)KERNADDR(sc->sc_dma) + sc->sc_fbsize;
313 1.1 jmcneill
314 1.1 jmcneill printf("%s: allocated %d byte fb @ %p (%p)\n", sc->sc_dev.dv_xname,
315 1.1 jmcneill sc->sc_fbsize, KERNADDR(sc->sc_dmai), KERNADDR(sc->sc_dma));
316 1.1 jmcneill
317 1.11 macallan sc->sc_current_cell = 0;
318 1.3 jmcneill
319 1.1 jmcneill ri = &crmfb_console_screen.scr_ri;
320 1.1 jmcneill memset(ri, 0, sizeof(struct rasops_info));
321 1.1 jmcneill
322 1.1 jmcneill vcons_init(&sc->sc_vd, sc, &crmfb_defaultscreen, &crmfb_accessops);
323 1.1 jmcneill sc->sc_vd.init_screen = crmfb_init_screen;
324 1.1 jmcneill crmfb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
325 1.1 jmcneill vcons_init_screen(&sc->sc_vd, &crmfb_console_screen, 1, &defattr);
326 1.1 jmcneill
327 1.1 jmcneill crmfb_defaultscreen.ncols = ri->ri_cols;
328 1.1 jmcneill crmfb_defaultscreen.nrows = ri->ri_rows;
329 1.1 jmcneill crmfb_defaultscreen.textops = &ri->ri_ops;
330 1.1 jmcneill crmfb_defaultscreen.capabilities = ri->ri_caps;
331 1.1 jmcneill crmfb_defaultscreen.modecookie = NULL;
332 1.1 jmcneill
333 1.7 macallan crmfb_setup_video(sc, 8);
334 1.11 macallan crmfb_fill_rect(sc, 0, 0, sc->sc_width, sc->sc_height, 0xf);
335 1.11 macallan
336 1.7 macallan crmfb_setup_palette(sc);
337 1.1 jmcneill
338 1.2 jmcneill consdev = ARCBIOS->GetEnvironmentVariable("ConsoleOut");
339 1.2 jmcneill if (consdev != NULL && strcmp(consdev, "video()") == 0) {
340 1.2 jmcneill wsdisplay_cnattach(&crmfb_defaultscreen, ri, 0, 0, defattr);
341 1.2 jmcneill aa.console = 1;
342 1.2 jmcneill } else
343 1.2 jmcneill aa.console = 0;
344 1.1 jmcneill aa.scrdata = &crmfb_screenlist;
345 1.1 jmcneill aa.accessops = &crmfb_accessops;
346 1.1 jmcneill aa.accesscookie = &sc->sc_vd;
347 1.1 jmcneill
348 1.1 jmcneill config_found(self, &aa, wsemuldisplaydevprint);
349 1.1 jmcneill
350 1.6 macallan sc->sc_cur_x = 0;
351 1.6 macallan sc->sc_cur_y = 0;
352 1.6 macallan sc->sc_hot_x = 0;
353 1.6 macallan sc->sc_hot_y = 0;
354 1.6 macallan
355 1.11 macallan #ifdef CRMFB_DEBUG
356 1.11 macallan crmfb_test_mte(sc);
357 1.11 macallan #endif
358 1.1 jmcneill return;
359 1.1 jmcneill }
360 1.1 jmcneill
361 1.1 jmcneill int
362 1.1 jmcneill crmfb_probe(void)
363 1.1 jmcneill {
364 1.1 jmcneill
365 1.1 jmcneill if (mach_type != MACH_SGI_IP32)
366 1.1 jmcneill return 0;
367 1.1 jmcneill
368 1.1 jmcneill return 1;
369 1.1 jmcneill }
370 1.1 jmcneill
371 1.1 jmcneill static int
372 1.1 jmcneill crmfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
373 1.1 jmcneill {
374 1.1 jmcneill struct vcons_data *vd;
375 1.1 jmcneill struct crmfb_softc *sc;
376 1.1 jmcneill struct vcons_screen *ms;
377 1.1 jmcneill struct wsdisplay_fbinfo *wdf;
378 1.1 jmcneill int nmode;
379 1.1 jmcneill
380 1.1 jmcneill vd = (struct vcons_data *)v;
381 1.1 jmcneill sc = (struct crmfb_softc *)vd->cookie;
382 1.1 jmcneill ms = (struct vcons_screen *)vd->active;
383 1.1 jmcneill
384 1.1 jmcneill switch (cmd) {
385 1.1 jmcneill case WSDISPLAYIO_GTYPE:
386 1.1 jmcneill /* not really, but who cares? */
387 1.7 macallan /* wsfb does */
388 1.7 macallan *(u_int *)data = WSDISPLAY_TYPE_CRIME;
389 1.1 jmcneill return 0;
390 1.1 jmcneill case WSDISPLAYIO_GINFO:
391 1.1 jmcneill if (vd->active != NULL) {
392 1.1 jmcneill wdf = (void *)data;
393 1.1 jmcneill wdf->height = sc->sc_height;
394 1.1 jmcneill wdf->width = sc->sc_width;
395 1.7 macallan wdf->depth = 32;
396 1.1 jmcneill wdf->cmsize = 256;
397 1.1 jmcneill return 0;
398 1.1 jmcneill } else
399 1.1 jmcneill return ENODEV;
400 1.1 jmcneill case WSDISPLAYIO_GETCMAP:
401 1.1 jmcneill if (sc->sc_depth == 8)
402 1.1 jmcneill return crmfb_getcmap(sc, (struct wsdisplay_cmap *)data);
403 1.1 jmcneill else
404 1.1 jmcneill return EINVAL;
405 1.1 jmcneill case WSDISPLAYIO_PUTCMAP:
406 1.1 jmcneill if (sc->sc_depth == 8)
407 1.1 jmcneill return crmfb_putcmap(sc, (struct wsdisplay_cmap *)data);
408 1.1 jmcneill else
409 1.1 jmcneill return EINVAL;
410 1.1 jmcneill case WSDISPLAYIO_LINEBYTES:
411 1.1 jmcneill *(u_int *)data = sc->sc_width * sc->sc_depth / 8;
412 1.1 jmcneill return 0;
413 1.1 jmcneill case WSDISPLAYIO_SMODE:
414 1.1 jmcneill nmode = *(int *)data;
415 1.1 jmcneill if (nmode != sc->sc_wsmode) {
416 1.1 jmcneill sc->sc_wsmode = nmode;
417 1.7 macallan if (nmode == WSDISPLAYIO_MODE_EMUL) {
418 1.7 macallan crmfb_setup_video(sc, 8);
419 1.7 macallan crmfb_setup_palette(sc);
420 1.1 jmcneill vcons_redraw_screen(vd->active);
421 1.7 macallan } else {
422 1.7 macallan crmfb_setup_video(sc, 32);
423 1.7 macallan }
424 1.1 jmcneill }
425 1.1 jmcneill return 0;
426 1.5 jmcneill case WSDISPLAYIO_SVIDEO:
427 1.5 jmcneill case WSDISPLAYIO_GVIDEO:
428 1.5 jmcneill return ENODEV; /* not supported yet */
429 1.6 macallan
430 1.6 macallan case WSDISPLAYIO_GCURPOS:
431 1.6 macallan {
432 1.6 macallan struct wsdisplay_curpos *pos;
433 1.6 macallan
434 1.6 macallan pos = (struct wsdisplay_curpos *)data;
435 1.6 macallan pos->x = sc->sc_cur_x;
436 1.6 macallan pos->y = sc->sc_cur_y;
437 1.6 macallan }
438 1.6 macallan return 0;
439 1.6 macallan case WSDISPLAYIO_SCURPOS:
440 1.6 macallan {
441 1.6 macallan struct wsdisplay_curpos *pos;
442 1.6 macallan
443 1.6 macallan pos = (struct wsdisplay_curpos *)data;
444 1.6 macallan crmfb_set_curpos(sc, pos->x, pos->y);
445 1.6 macallan }
446 1.6 macallan return 0;
447 1.6 macallan case WSDISPLAYIO_GCURMAX:
448 1.6 macallan {
449 1.6 macallan struct wsdisplay_curpos *pos;
450 1.6 macallan
451 1.6 macallan pos = (struct wsdisplay_curpos *)data;
452 1.6 macallan pos->x = 32;
453 1.6 macallan pos->y = 32;
454 1.6 macallan }
455 1.6 macallan return 0;
456 1.6 macallan case WSDISPLAYIO_GCURSOR:
457 1.6 macallan {
458 1.6 macallan struct wsdisplay_cursor *cu;
459 1.6 macallan
460 1.6 macallan cu = (struct wsdisplay_cursor *)data;
461 1.6 macallan return crmfb_gcursor(sc, cu);
462 1.6 macallan }
463 1.6 macallan case WSDISPLAYIO_SCURSOR:
464 1.6 macallan {
465 1.6 macallan struct wsdisplay_cursor *cu;
466 1.6 macallan
467 1.6 macallan cu = (struct wsdisplay_cursor *)data;
468 1.6 macallan return crmfb_scursor(sc, cu);
469 1.6 macallan }
470 1.1 jmcneill }
471 1.1 jmcneill return EPASSTHROUGH;
472 1.1 jmcneill }
473 1.1 jmcneill
474 1.1 jmcneill static paddr_t
475 1.1 jmcneill crmfb_mmap(void *v, void *vs, off_t offset, int prot)
476 1.1 jmcneill {
477 1.1 jmcneill struct vcons_data *vd;
478 1.1 jmcneill struct crmfb_softc *sc;
479 1.1 jmcneill paddr_t pa;
480 1.1 jmcneill
481 1.1 jmcneill vd = (struct vcons_data *)v;
482 1.1 jmcneill sc = (struct crmfb_softc *)vd->cookie;
483 1.1 jmcneill
484 1.7 macallan #if 1
485 1.1 jmcneill if (offset >= 0 && offset < sc->sc_fbsize) {
486 1.1 jmcneill pa = bus_dmamem_mmap(sc->sc_dmat, sc->sc_dma.segs,
487 1.1 jmcneill sc->sc_dma.nsegs, offset, prot,
488 1.3 jmcneill BUS_DMA_WAITOK | BUS_DMA_COHERENT);
489 1.1 jmcneill return pa;
490 1.1 jmcneill }
491 1.7 macallan #else
492 1.7 macallan if (offset >= 0 && offset < sc->sc_fbsize) {
493 1.7 macallan pa = bus_space_mmap(SGIMIPS_BUS_SPACE_NORMAL, sc->sc_fbh,
494 1.7 macallan offset, prot, SGIMIPS_BUS_SPACE_NORMAL);
495 1.7 macallan printf("%s: %08llx -> %llx\n", __func__, offset, pa);
496 1.7 macallan return pa;
497 1.7 macallan }
498 1.7 macallan #endif
499 1.1 jmcneill return -1;
500 1.1 jmcneill }
501 1.1 jmcneill
502 1.1 jmcneill static void
503 1.1 jmcneill crmfb_init_screen(void *c, struct vcons_screen *scr, int existing,
504 1.1 jmcneill long *defattr)
505 1.1 jmcneill {
506 1.1 jmcneill struct crmfb_softc *sc;
507 1.1 jmcneill struct rasops_info *ri;
508 1.1 jmcneill
509 1.1 jmcneill sc = (struct crmfb_softc *)c;
510 1.1 jmcneill ri = &scr->scr_ri;
511 1.1 jmcneill
512 1.11 macallan ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
513 1.1 jmcneill ri->ri_depth = sc->sc_depth;
514 1.1 jmcneill ri->ri_width = sc->sc_width;
515 1.1 jmcneill ri->ri_height = sc->sc_height;
516 1.1 jmcneill ri->ri_stride = ri->ri_width * (ri->ri_depth / 8);
517 1.1 jmcneill
518 1.1 jmcneill switch (ri->ri_depth) {
519 1.1 jmcneill case 16:
520 1.1 jmcneill ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5;
521 1.1 jmcneill ri->ri_rpos = 10;
522 1.1 jmcneill ri->ri_gpos = 5;
523 1.1 jmcneill ri->ri_bpos = 0;
524 1.1 jmcneill break;
525 1.1 jmcneill case 32:
526 1.1 jmcneill ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8;
527 1.1 jmcneill ri->ri_rpos = 8;
528 1.1 jmcneill ri->ri_gpos = 16;
529 1.1 jmcneill ri->ri_bpos = 24;
530 1.1 jmcneill break;
531 1.1 jmcneill }
532 1.1 jmcneill
533 1.11 macallan ri->ri_bits = KERNADDR(sc->sc_dma);
534 1.1 jmcneill
535 1.1 jmcneill if (existing)
536 1.1 jmcneill ri->ri_flg |= RI_CLEAR;
537 1.1 jmcneill
538 1.1 jmcneill rasops_init(ri, ri->ri_height / 16, ri->ri_width / 8);
539 1.1 jmcneill ri->ri_caps = WSSCREEN_WSCOLORS;
540 1.1 jmcneill rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
541 1.1 jmcneill ri->ri_width / ri->ri_font->fontwidth);
542 1.1 jmcneill ri->ri_hw = scr;
543 1.1 jmcneill
544 1.11 macallan /* now make a fake rasops_info for drawing into the scratch tile */
545 1.11 macallan memcpy(&sc->sc_rasops, ri, sizeof(struct rasops_info));
546 1.11 macallan sc->sc_rasops.ri_width = 512; /* assume we're always in 8bit here */
547 1.11 macallan sc->sc_rasops.ri_stride = 512;
548 1.11 macallan sc->sc_rasops.ri_height = 128;
549 1.11 macallan sc->sc_rasops.ri_xorigin = 0;
550 1.11 macallan sc->sc_rasops.ri_yorigin = 0;
551 1.11 macallan sc->sc_rasops.ri_bits = sc->sc_scratch;
552 1.11 macallan sc->sc_cells = 512 / ri->ri_font->fontwidth;
553 1.11 macallan
554 1.11 macallan ri->ri_ops.cursor = crmfb_cursor;
555 1.11 macallan ri->ri_ops.copyrows = crmfb_copyrows;
556 1.11 macallan ri->ri_ops.eraserows = crmfb_eraserows;
557 1.11 macallan ri->ri_ops.copycols = crmfb_copycols;
558 1.11 macallan ri->ri_ops.erasecols = crmfb_erasecols;
559 1.11 macallan ri->ri_ops.putchar = crmfb_putchar;
560 1.11 macallan
561 1.1 jmcneill return;
562 1.1 jmcneill }
563 1.1 jmcneill
564 1.1 jmcneill static int
565 1.1 jmcneill crmfb_putcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
566 1.1 jmcneill {
567 1.1 jmcneill u_int idx, cnt;
568 1.1 jmcneill u_char r[256], g[256], b[256];
569 1.1 jmcneill u_char *rp, *gp, *bp;
570 1.1 jmcneill int rv, i;
571 1.1 jmcneill
572 1.1 jmcneill idx = cm->index;
573 1.1 jmcneill cnt = cm->count;
574 1.1 jmcneill
575 1.1 jmcneill if (idx >= 255 || cnt > 256 || idx + cnt > 256)
576 1.1 jmcneill return EINVAL;
577 1.1 jmcneill
578 1.1 jmcneill rv = copyin(cm->red, &r[idx], cnt);
579 1.1 jmcneill if (rv)
580 1.1 jmcneill return rv;
581 1.1 jmcneill rv = copyin(cm->green, &g[idx], cnt);
582 1.1 jmcneill if (rv)
583 1.1 jmcneill return rv;
584 1.1 jmcneill rv = copyin(cm->blue, &b[idx], cnt);
585 1.1 jmcneill if (rv)
586 1.1 jmcneill return rv;
587 1.1 jmcneill
588 1.1 jmcneill memcpy(&sc->sc_cmap_red[idx], &r[idx], cnt);
589 1.1 jmcneill memcpy(&sc->sc_cmap_green[idx], &g[idx], cnt);
590 1.1 jmcneill memcpy(&sc->sc_cmap_blue[idx], &b[idx], cnt);
591 1.1 jmcneill
592 1.1 jmcneill rp = &sc->sc_cmap_red[idx];
593 1.1 jmcneill gp = &sc->sc_cmap_green[idx];
594 1.1 jmcneill bp = &sc->sc_cmap_blue[idx];
595 1.1 jmcneill
596 1.1 jmcneill for (i = 0; i < cnt; i++) {
597 1.1 jmcneill crmfb_set_palette(sc, idx, *rp, *gp, *bp);
598 1.1 jmcneill idx++;
599 1.1 jmcneill rp++, gp++, bp++;
600 1.1 jmcneill }
601 1.1 jmcneill
602 1.1 jmcneill return 0;
603 1.1 jmcneill }
604 1.1 jmcneill
605 1.1 jmcneill static int
606 1.1 jmcneill crmfb_getcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
607 1.1 jmcneill {
608 1.1 jmcneill u_int idx, cnt;
609 1.1 jmcneill int rv;
610 1.1 jmcneill
611 1.1 jmcneill idx = cm->index;
612 1.1 jmcneill cnt = cm->count;
613 1.1 jmcneill
614 1.1 jmcneill if (idx >= 255 || cnt > 256 || idx + cnt > 256)
615 1.1 jmcneill return EINVAL;
616 1.1 jmcneill
617 1.1 jmcneill rv = copyout(&sc->sc_cmap_red[idx], cm->red, cnt);
618 1.1 jmcneill if (rv)
619 1.1 jmcneill return rv;
620 1.1 jmcneill rv = copyout(&sc->sc_cmap_green[idx], cm->green, cnt);
621 1.1 jmcneill if (rv)
622 1.1 jmcneill return rv;
623 1.1 jmcneill rv = copyout(&sc->sc_cmap_blue[idx], cm->blue, cnt);
624 1.1 jmcneill if (rv)
625 1.1 jmcneill return rv;
626 1.1 jmcneill
627 1.1 jmcneill return 0;
628 1.1 jmcneill }
629 1.1 jmcneill
630 1.1 jmcneill static void
631 1.1 jmcneill crmfb_set_palette(struct crmfb_softc *sc, int reg, uint8_t r, uint8_t g,
632 1.1 jmcneill uint8_t b)
633 1.1 jmcneill {
634 1.1 jmcneill uint32_t val;
635 1.1 jmcneill
636 1.1 jmcneill if (reg > 255 || sc->sc_depth != 8)
637 1.1 jmcneill return;
638 1.1 jmcneill
639 1.1 jmcneill while (bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_CMAP_FIFO) >= 63)
640 1.1 jmcneill DELAY(10);
641 1.1 jmcneill
642 1.1 jmcneill val = (r << 24) | (g << 16) | (b << 8);
643 1.7 macallan crmfb_write_reg(sc, CRMFB_CMAP + (reg * 4), val);
644 1.1 jmcneill
645 1.1 jmcneill return;
646 1.1 jmcneill }
647 1.6 macallan
648 1.6 macallan static int
649 1.6 macallan crmfb_set_curpos(struct crmfb_softc *sc, int x, int y)
650 1.6 macallan {
651 1.6 macallan uint32_t val;
652 1.6 macallan
653 1.6 macallan sc->sc_cur_x = x;
654 1.6 macallan sc->sc_cur_y = y;
655 1.6 macallan
656 1.6 macallan val = ((x - sc->sc_hot_x) & 0xffff) | ((y - sc->sc_hot_y) << 16);
657 1.7 macallan crmfb_write_reg(sc, CRMFB_CURSOR_POS, val);
658 1.6 macallan
659 1.6 macallan return 0;
660 1.6 macallan }
661 1.6 macallan
662 1.6 macallan static int
663 1.6 macallan crmfb_gcursor(struct crmfb_softc *sc, struct wsdisplay_cursor *cur)
664 1.6 macallan {
665 1.6 macallan /* do nothing for now */
666 1.6 macallan return 0;
667 1.6 macallan }
668 1.6 macallan
669 1.6 macallan static int
670 1.6 macallan crmfb_scursor(struct crmfb_softc *sc, struct wsdisplay_cursor *cur)
671 1.6 macallan {
672 1.6 macallan if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
673 1.6 macallan
674 1.7 macallan crmfb_write_reg(sc, CRMFB_CURSOR_CONTROL, cur->enable ? 1 : 0);
675 1.6 macallan }
676 1.6 macallan if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
677 1.6 macallan
678 1.6 macallan sc->sc_hot_x = cur->hot.x;
679 1.6 macallan sc->sc_hot_y = cur->hot.y;
680 1.6 macallan }
681 1.6 macallan if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
682 1.6 macallan
683 1.6 macallan crmfb_set_curpos(sc, cur->pos.x, cur->pos.y);
684 1.6 macallan }
685 1.6 macallan if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
686 1.6 macallan int i;
687 1.6 macallan uint32_t val;
688 1.6 macallan
689 1.6 macallan for (i = 0; i < cur->cmap.count; i++) {
690 1.6 macallan val = (cur->cmap.red[i] << 24) |
691 1.6 macallan (cur->cmap.green[i] << 16) |
692 1.6 macallan (cur->cmap.blue[i] << 8);
693 1.7 macallan crmfb_write_reg(sc, CRMFB_CURSOR_CMAP0 +
694 1.7 macallan ((i + cur->cmap.index) << 2), val);
695 1.6 macallan }
696 1.6 macallan }
697 1.6 macallan if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
698 1.6 macallan
699 1.6 macallan int i, j, cnt = 0;
700 1.6 macallan uint32_t latch = 0, omask;
701 1.6 macallan uint8_t imask;
702 1.6 macallan for (i = 0; i < 64; i++) {
703 1.6 macallan omask = 0x80000000;
704 1.6 macallan imask = 0x01;
705 1.6 macallan cur->image[cnt] &= cur->mask[cnt];
706 1.6 macallan for (j = 0; j < 8; j++) {
707 1.6 macallan if (cur->image[cnt] & imask)
708 1.6 macallan latch |= omask;
709 1.6 macallan omask >>= 1;
710 1.6 macallan if (cur->mask[cnt] & imask)
711 1.6 macallan latch |= omask;
712 1.6 macallan omask >>= 1;
713 1.6 macallan imask <<= 1;
714 1.6 macallan }
715 1.6 macallan cnt++;
716 1.6 macallan imask = 0x01;
717 1.6 macallan cur->image[cnt] &= cur->mask[cnt];
718 1.6 macallan for (j = 0; j < 8; j++) {
719 1.6 macallan if (cur->image[cnt] & imask)
720 1.6 macallan latch |= omask;
721 1.6 macallan omask >>= 1;
722 1.6 macallan if (cur->mask[cnt] & imask)
723 1.6 macallan latch |= omask;
724 1.6 macallan omask >>= 1;
725 1.6 macallan imask <<= 1;
726 1.6 macallan }
727 1.6 macallan cnt++;
728 1.7 macallan crmfb_write_reg(sc, CRMFB_CURSOR_BITMAP + (i << 2),
729 1.7 macallan latch);
730 1.6 macallan latch = 0;
731 1.6 macallan }
732 1.6 macallan }
733 1.6 macallan return 0;
734 1.6 macallan }
735 1.7 macallan
736 1.7 macallan static inline void
737 1.7 macallan crmfb_write_reg(struct crmfb_softc *sc, int offset, uint32_t val)
738 1.7 macallan {
739 1.7 macallan
740 1.7 macallan bus_space_write_4(sc->sc_iot, sc->sc_ioh, offset, val);
741 1.7 macallan wbflush();
742 1.7 macallan }
743 1.7 macallan
744 1.11 macallan static inline uint32_t
745 1.11 macallan crmfb_read_reg(struct crmfb_softc *sc, int offset)
746 1.11 macallan {
747 1.11 macallan
748 1.11 macallan return bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset);
749 1.11 macallan }
750 1.11 macallan
751 1.11 macallan static int
752 1.11 macallan crmfb_wait_dma_idle(struct crmfb_softc *sc)
753 1.11 macallan {
754 1.11 macallan int bail = 100000, idle;
755 1.11 macallan
756 1.11 macallan do {
757 1.11 macallan idle = ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
758 1.11 macallan CRMFB_OVR_CONTROL) & 1) == 0) &&
759 1.11 macallan ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
760 1.11 macallan CRMFB_FRM_CONTROL) & 1) == 0) &&
761 1.11 macallan ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
762 1.11 macallan CRMFB_DID_CONTROL) & 1) == 0);
763 1.11 macallan if (!idle)
764 1.11 macallan delay(10);
765 1.11 macallan bail--;
766 1.11 macallan } while ((!idle) && (bail > 0));
767 1.11 macallan return idle;
768 1.11 macallan }
769 1.11 macallan
770 1.7 macallan static int
771 1.7 macallan crmfb_setup_video(struct crmfb_softc *sc, int depth)
772 1.7 macallan {
773 1.11 macallan uint64_t reg;
774 1.11 macallan uint32_t d, h, mode;
775 1.11 macallan int i, bail, tile_width, tlbptr, j, tx, shift;
776 1.10 sekiya const char *wantsync;
777 1.11 macallan uint16_t v;
778 1.11 macallan
779 1.7 macallan /* disable DMA */
780 1.7 macallan d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_OVR_CONTROL);
781 1.7 macallan d &= ~(1 << CRMFB_OVR_CONTROL_DMAEN_SHIFT);
782 1.7 macallan crmfb_write_reg(sc, CRMFB_OVR_CONTROL, d);
783 1.7 macallan DELAY(50000);
784 1.7 macallan d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
785 1.7 macallan d &= ~(1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
786 1.7 macallan crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
787 1.7 macallan DELAY(50000);
788 1.7 macallan crmfb_write_reg(sc, CRMFB_DID_CONTROL, 0);
789 1.7 macallan DELAY(50000);
790 1.7 macallan
791 1.11 macallan if (!crmfb_wait_dma_idle(sc))
792 1.11 macallan aprint_error("crmfb: crmfb_wait_dma_idle timed out\n");
793 1.11 macallan
794 1.7 macallan /* ensure that CRM starts drawing at the top left of the screen
795 1.7 macallan * when we re-enable DMA later
796 1.7 macallan */
797 1.7 macallan d = (1 << CRMFB_VT_XY_FREEZE_SHIFT);
798 1.7 macallan crmfb_write_reg(sc, CRMFB_VT_XY, d);
799 1.7 macallan delay(1000);
800 1.7 macallan d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
801 1.7 macallan d &= ~(1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
802 1.7 macallan crmfb_write_reg(sc, CRMFB_DOTCLOCK, d);
803 1.11 macallan
804 1.11 macallan /* wait for dotclock to turn off */
805 1.11 macallan bail = 10000;
806 1.11 macallan while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK) &
807 1.11 macallan (1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT)) && (bail > 0)) {
808 1.11 macallan delay(10);
809 1.11 macallan bail--;
810 1.11 macallan }
811 1.7 macallan
812 1.7 macallan /* reset FIFO */
813 1.7 macallan d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
814 1.7 macallan d |= (1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
815 1.7 macallan crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
816 1.7 macallan d &= ~(1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
817 1.7 macallan crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
818 1.7 macallan
819 1.7 macallan /* setup colour mode */
820 1.7 macallan switch (depth) {
821 1.7 macallan case 8:
822 1.7 macallan h = CRMFB_MODE_TYP_I8;
823 1.11 macallan tile_width = 512;
824 1.7 macallan break;
825 1.7 macallan case 16:
826 1.7 macallan h = CRMFB_MODE_TYP_ARGB5;
827 1.11 macallan tile_width = 256;
828 1.7 macallan break;
829 1.7 macallan case 32:
830 1.7 macallan h = CRMFB_MODE_TYP_RGB8;
831 1.11 macallan tile_width = 128;
832 1.7 macallan break;
833 1.7 macallan default:
834 1.7 macallan panic("Unsupported depth");
835 1.7 macallan }
836 1.7 macallan d = h << CRMFB_MODE_TYP_SHIFT;
837 1.7 macallan d |= CRMFB_MODE_BUF_BOTH << CRMFB_MODE_BUF_SHIFT;
838 1.7 macallan for (i = 0; i < (32 * 4); i += 4)
839 1.7 macallan bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_MODE + i, d);
840 1.7 macallan wbflush();
841 1.7 macallan
842 1.7 macallan /* setup tile pointer, but don't turn on DMA yet! */
843 1.7 macallan h = DMAADDR(sc->sc_dmai);
844 1.7 macallan d = (h >> 9) << CRMFB_FRM_CONTROL_TILEPTR_SHIFT;
845 1.11 macallan printf("CRMFB_FRM_CONTROL %08x -> %08x", crmfb_read_reg(sc, CRMFB_FRM_CONTROL), d);
846 1.7 macallan crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
847 1.7 macallan
848 1.7 macallan /* init framebuffer width and pixel size */
849 1.11 macallan /*d = (1 << CRMFB_FRM_TILESIZE_WIDTH_SHIFT);*/
850 1.11 macallan
851 1.11 macallan d = ((int)(sc->sc_width / tile_width)) <<
852 1.11 macallan CRMFB_FRM_TILESIZE_WIDTH_SHIFT;
853 1.11 macallan if ((sc->sc_width & (tile_width - 1)) != 0)
854 1.11 macallan d |= sc->sc_tiles_y;
855 1.11 macallan
856 1.7 macallan switch (depth) {
857 1.7 macallan case 8:
858 1.7 macallan h = CRMFB_FRM_TILESIZE_DEPTH_8;
859 1.7 macallan break;
860 1.7 macallan case 16:
861 1.7 macallan h = CRMFB_FRM_TILESIZE_DEPTH_16;
862 1.7 macallan break;
863 1.7 macallan case 32:
864 1.7 macallan h = CRMFB_FRM_TILESIZE_DEPTH_32;
865 1.7 macallan break;
866 1.7 macallan default:
867 1.7 macallan panic("Unsupported depth");
868 1.7 macallan }
869 1.7 macallan d |= (h << CRMFB_FRM_TILESIZE_DEPTH_SHIFT);
870 1.11 macallan printf("CRMFB_FRM_TILESIZE %08x -> %08x", crmfb_read_reg(sc, CRMFB_FRM_TILESIZE), d);
871 1.7 macallan crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
872 1.7 macallan
873 1.7 macallan /* init framebuffer height, we use the trick that the Linux
874 1.7 macallan * driver uses to fool the CRM out of tiled mode and into
875 1.7 macallan * linear mode
876 1.7 macallan */
877 1.11 macallan /*h = sc->sc_width * sc->sc_height / (512 / (depth >> 3));*/
878 1.11 macallan h = sc->sc_height;
879 1.7 macallan d = h << CRMFB_FRM_PIXSIZE_HEIGHT_SHIFT;
880 1.11 macallan printf("CRMFB_FRM_PIXSIZE %08x -> %08x", crmfb_read_reg(sc, CRMFB_FRM_PIXSIZE), d);
881 1.7 macallan crmfb_write_reg(sc, CRMFB_FRM_PIXSIZE, d);
882 1.7 macallan
883 1.7 macallan /* turn off firmware overlay and hardware cursor */
884 1.7 macallan crmfb_write_reg(sc, CRMFB_OVR_WIDTH_TILE, 0);
885 1.7 macallan crmfb_write_reg(sc, CRMFB_CURSOR_CONTROL, 0);
886 1.7 macallan
887 1.7 macallan /* enable drawing again */
888 1.7 macallan d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
889 1.7 macallan d |= (1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
890 1.7 macallan crmfb_write_reg(sc, CRMFB_DOTCLOCK, d);
891 1.7 macallan crmfb_write_reg(sc, CRMFB_VT_XY, 0);
892 1.7 macallan
893 1.7 macallan /* turn on DMA for the framebuffer */
894 1.7 macallan d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
895 1.7 macallan d |= (1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
896 1.7 macallan crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
897 1.7 macallan
898 1.10 sekiya /* turn off sync-on-green */
899 1.10 sekiya
900 1.10 sekiya wantsync = ARCBIOS->GetEnvironmentVariable("SyncOnGreen");
901 1.10 sekiya if ( (wantsync != NULL) && (wantsync[0] == 'n') ) {
902 1.10 sekiya d = ( 1 << CRMFB_VT_FLAGS_SYNC_LOW_LSB) & CRMFB_REG_MASK(CRMFB_VT_FLAGS_SYNC_LOW_MSB, CRMFB_VT_FLAGS_SYNC_LOW_LSB);
903 1.10 sekiya crmfb_write_reg(sc, CRMFB_VT_FLAGS, d);
904 1.10 sekiya }
905 1.10 sekiya
906 1.7 macallan sc->sc_depth = depth;
907 1.11 macallan
908 1.11 macallan /* finally set up the drawing engine's TLB A */
909 1.11 macallan v = (DMAADDR(sc->sc_dma) >> 16) & 0xffff;
910 1.11 macallan tlbptr = 0;
911 1.11 macallan tx = ((sc->sc_width + (tile_width - 1)) & ~(tile_width - 1)) / tile_width;
912 1.11 macallan printf("tx: %d\n", tx);
913 1.11 macallan for (i = 0; i < sc->sc_tiles_y; i++) {
914 1.11 macallan reg = 0;
915 1.11 macallan shift = 64;
916 1.11 macallan for (j = 0; j < tx; j++) {
917 1.11 macallan shift -= 16;
918 1.11 macallan reg |= (((uint64_t)(v | 0x8000)) << shift);
919 1.11 macallan if (shift == 0) {
920 1.11 macallan shift = 64;
921 1.11 macallan bus_space_write_8(sc->sc_iot, sc->sc_reh,
922 1.11 macallan CRIME_RE_TLB_A + tlbptr + (j & 0xffc) * 2, reg);
923 1.11 macallan printf("%08x: %016llx\n", tlbptr + (j & 0xffc) * 2, reg);
924 1.11 macallan }
925 1.11 macallan v++;
926 1.11 macallan }
927 1.11 macallan if (shift != 64) {
928 1.11 macallan bus_space_write_8(sc->sc_iot, sc->sc_reh,
929 1.11 macallan CRIME_RE_TLB_A + tlbptr + (j & 0xffc) * 2, reg);
930 1.11 macallan printf("%08x: %016llx\n", tlbptr + (j & 0xffc) * 2, reg);
931 1.11 macallan }
932 1.11 macallan tlbptr += 32;
933 1.11 macallan }
934 1.11 macallan
935 1.11 macallan /* put the scratch page into the lower left of the fb */
936 1.11 macallan reg = (((uint64_t)(DMAADDR(sc->sc_dma) + sc->sc_fbsize) | 0x80000000) &
937 1.11 macallan 0xffff0000) << 32;
938 1.11 macallan bus_space_write_8(sc->sc_iot, sc->sc_reh, CRIME_RE_TLB_A + 0x1e0, reg);
939 1.11 macallan
940 1.11 macallan wbflush();
941 1.11 macallan
942 1.11 macallan for (i = 0; i < 0x80; i += 8)
943 1.11 macallan printf("%04x: %016llx\n", i, bus_space_read_8(sc->sc_iot, sc->sc_reh,
944 1.11 macallan CRIME_RE_TLB_A + i));
945 1.11 macallan
946 1.11 macallan /* do some very basic engine setup */
947 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_CLIPMODE, 0);
948 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_WINOFFSET_SRC, 0);
949 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_WINOFFSET_DST, 0);
950 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PLANEMASK, 0xffffffff);
951 1.11 macallan
952 1.11 macallan bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x20, 0);
953 1.11 macallan bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x28, 0);
954 1.11 macallan bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x30, 0);
955 1.11 macallan bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x38, 0);
956 1.11 macallan bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x40, 0);
957 1.11 macallan
958 1.11 macallan switch (depth) {
959 1.11 macallan case 8:
960 1.11 macallan mode = DE_MODE_TLB_A | DE_MODE_BUFDEPTH_8 |
961 1.11 macallan DE_MODE_TYPE_CI | DE_MODE_PIXDEPTH_8;
962 1.11 macallan break;
963 1.11 macallan case 16:
964 1.11 macallan mode = DE_MODE_TLB_A | DE_MODE_BUFDEPTH_16 |
965 1.11 macallan DE_MODE_TYPE_RGB | DE_MODE_PIXDEPTH_16;
966 1.11 macallan case 32:
967 1.11 macallan mode = DE_MODE_TLB_A | DE_MODE_BUFDEPTH_32 |
968 1.11 macallan DE_MODE_TYPE_RGBA | DE_MODE_PIXDEPTH_32;
969 1.11 macallan default:
970 1.11 macallan panic("%s: unsuported colour depth %d\n", __func__,
971 1.11 macallan depth);
972 1.11 macallan }
973 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_DST, mode);
974 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_SRC, mode);
975 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_STEP_X, 1);
976 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_STEP_Y, 1);
977 1.7 macallan return 0;
978 1.7 macallan }
979 1.7 macallan
980 1.7 macallan static void
981 1.7 macallan crmfb_setup_palette(struct crmfb_softc *sc)
982 1.7 macallan {
983 1.7 macallan int i;
984 1.7 macallan
985 1.7 macallan for (i = 0; i < 256; i++) {
986 1.7 macallan crmfb_set_palette(sc, i, rasops_cmap[(i * 3) + 2],
987 1.7 macallan rasops_cmap[(i * 3) + 1], rasops_cmap[(i * 3) + 0]);
988 1.7 macallan sc->sc_cmap_red[i] = rasops_cmap[(i * 3) + 2];
989 1.7 macallan sc->sc_cmap_green[i] = rasops_cmap[(i * 3) + 1];
990 1.7 macallan sc->sc_cmap_blue[i] = rasops_cmap[(i * 3) + 0];
991 1.7 macallan }
992 1.7 macallan }
993 1.11 macallan
994 1.11 macallan static inline void
995 1.11 macallan crmfb_wait_idle(struct crmfb_softc *sc)
996 1.11 macallan {
997 1.11 macallan int i = 0;
998 1.11 macallan
999 1.11 macallan do {
1000 1.11 macallan i++;
1001 1.11 macallan delay(1);
1002 1.11 macallan } while (((bus_space_read_4(sc->sc_iot, sc->sc_reh, CRIME_DE_STATUS) &
1003 1.11 macallan CRIME_DE_IDLE) == 0) && (i < 100000000));
1004 1.11 macallan if (i >= 100000000)
1005 1.11 macallan aprint_error("crmfb_wait_idle() timed out\n");
1006 1.11 macallan }
1007 1.11 macallan
1008 1.11 macallan static void
1009 1.11 macallan crmfb_fill_rect(struct crmfb_softc *sc, int x, int y, int width, int height,
1010 1.11 macallan uint32_t colour)
1011 1.11 macallan {
1012 1.11 macallan crmfb_wait_idle(sc);
1013 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_DRAWMODE,
1014 1.11 macallan DE_DRAWMODE_PLANEMASK | DE_DRAWMODE_BYTEMASK);
1015 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_FG, colour);
1016 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PRIMITIVE,
1017 1.11 macallan DE_PRIM_RECTANGLE | DE_PRIM_TB);
1018 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_X_VERTEX_0,
1019 1.11 macallan (x << 16) | (y & 0xffff));
1020 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh,
1021 1.11 macallan CRIME_DE_X_VERTEX_1 | CRIME_DE_START,
1022 1.11 macallan ((x + width - 1) << 16) | ((y + height - 1) & 0xffff));
1023 1.11 macallan }
1024 1.11 macallan
1025 1.11 macallan static void
1026 1.11 macallan crmfb_bitblt(struct crmfb_softc *sc, int xs, int ys, int xd, int yd,
1027 1.11 macallan int wi, int he, uint32_t rop)
1028 1.11 macallan {
1029 1.11 macallan uint32_t prim = DE_PRIM_RECTANGLE;
1030 1.11 macallan int rxa, rya, rxe, rye, rxs, rys;
1031 1.11 macallan crmfb_wait_idle(sc);
1032 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_DRAWMODE,
1033 1.11 macallan DE_DRAWMODE_PLANEMASK | DE_DRAWMODE_BYTEMASK | DE_DRAWMODE_ROP |
1034 1.11 macallan DE_DRAWMODE_XFER_EN);
1035 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_ROP, rop);
1036 1.11 macallan if (xs < xd) {
1037 1.11 macallan prim |= DE_PRIM_RL;
1038 1.11 macallan rxe = xd;
1039 1.11 macallan rxa = xd + wi - 1;
1040 1.11 macallan rxs = xs + wi - 1;
1041 1.11 macallan } else {
1042 1.11 macallan prim |= DE_PRIM_LR;
1043 1.11 macallan rxe = xd + wi - 1;
1044 1.11 macallan rxa = xd;
1045 1.11 macallan rxs = xs;
1046 1.11 macallan }
1047 1.11 macallan if (ys < yd) {
1048 1.11 macallan prim |= DE_PRIM_BT;
1049 1.11 macallan rye = yd;
1050 1.11 macallan rya = yd + he - 1;
1051 1.11 macallan rys = ys + he - 1;
1052 1.11 macallan } else {
1053 1.11 macallan prim |= DE_PRIM_TB;
1054 1.11 macallan rye = yd + he - 1;
1055 1.11 macallan rya = yd;
1056 1.11 macallan rys = ys;
1057 1.11 macallan }
1058 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PRIMITIVE, prim);
1059 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_ADDR_SRC,
1060 1.11 macallan (rxs << 16) | (rys & 0xffff));
1061 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_X_VERTEX_0,
1062 1.11 macallan (rxa << 16) | (rya & 0xffff));
1063 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh,
1064 1.11 macallan CRIME_DE_X_VERTEX_1 | CRIME_DE_START,
1065 1.11 macallan (rxe << 16) | (rye & 0xffff));
1066 1.11 macallan }
1067 1.11 macallan
1068 1.11 macallan #ifdef CRMFB_DEBUG
1069 1.11 macallan void
1070 1.11 macallan crmfb_test_mte(struct crmfb_softc *sc)
1071 1.11 macallan {
1072 1.11 macallan uint32_t status[10];
1073 1.11 macallan int i;
1074 1.11 macallan
1075 1.11 macallan crmfb_fill_rect(sc, 1, 1, 100, 100, 1);
1076 1.11 macallan crmfb_fill_rect(sc, 102, 1, 100, 100, 2);
1077 1.11 macallan crmfb_fill_rect(sc, 203, 1, 100, 100, 3);
1078 1.11 macallan crmfb_fill_rect(sc, 1024, 1, 100, 100, 4);
1079 1.11 macallan
1080 1.11 macallan crmfb_bitblt(sc, 10, 10, 400, 0, 300, 300, 12);
1081 1.11 macallan crmfb_wait_idle(sc);
1082 1.11 macallan printf("ROP: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_reh, CRIME_DE_ROP));
1083 1.11 macallan #if 0
1084 1.11 macallan delay(4000000);
1085 1.11 macallan
1086 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_NULL, 0x0);
1087 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_BG, 0x05050505);
1088 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
1089 1.11 macallan MTE_MODE_DST_ECC |
1090 1.11 macallan (MTE_TLB_A << MTE_DST_TLB_SHIFT) |
1091 1.11 macallan (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
1092 1.11 macallan (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
1093 1.11 macallan 0/*MTE_MODE_COPY*/);
1094 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST_STRIDE, 1);
1095 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC_STRIDE, 1);
1096 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC0, 0x00000000);
1097 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC1, 0x02000200);
1098 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST0, 0x03000000);
1099 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST1 | CRIME_DE_START, 0x02000200);
1100 1.11 macallan status[9] = bus_space_read_4(sc->sc_iot, sc->sc_reh, CRIME_DE_STATUS);
1101 1.11 macallan #endif
1102 1.11 macallan #if 1
1103 1.11 macallan bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
1104 1.11 macallan MTE_MODE_DST_ECC |
1105 1.11 macallan (MTE_TLB_A << MTE_DST_TLB_SHIFT) |
1106 1.11 macallan (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
1107 1.11 macallan (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
1108 1.11 macallan 0/*MTE_MODE_COPY*/);
1109 1.11 macallan #endif
1110 1.11 macallan delay(4000000);
1111 1.11 macallan #if 0
1112 1.11 macallan printf("flush: %08x\n",
1113 1.11 macallan bus_space_read_4(sc->sc_iot, sc->sc_reh, CRIME_DE_FLUSH));
1114 1.11 macallan #endif
1115 1.11 macallan
1116 1.11 macallan for (i = 0; i < 10; i++)
1117 1.11 macallan printf("%08x ", status[i]);
1118 1.11 macallan printf("\n");
1119 1.11 macallan }
1120 1.11 macallan #endif /* CRMFB_DEBUG */
1121 1.11 macallan
1122 1.11 macallan static void
1123 1.11 macallan crmfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
1124 1.11 macallan {
1125 1.11 macallan struct rasops_info *ri = cookie;
1126 1.11 macallan struct vcons_screen *scr = ri->ri_hw;
1127 1.11 macallan int32_t xs, xd, y, width, height;
1128 1.11 macallan
1129 1.11 macallan xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
1130 1.11 macallan xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
1131 1.11 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1132 1.11 macallan width = ri->ri_font->fontwidth * ncols;
1133 1.11 macallan height = ri->ri_font->fontheight;
1134 1.11 macallan crmfb_bitblt(scr->scr_cookie, xs, y, xd, y, width, height, 3);
1135 1.11 macallan }
1136 1.11 macallan
1137 1.11 macallan static void
1138 1.11 macallan crmfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
1139 1.11 macallan {
1140 1.11 macallan struct rasops_info *ri = cookie;
1141 1.11 macallan struct vcons_screen *scr = ri->ri_hw;
1142 1.11 macallan int32_t x, y, width, height, bg;
1143 1.11 macallan
1144 1.11 macallan x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
1145 1.11 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1146 1.11 macallan width = ri->ri_font->fontwidth * ncols;
1147 1.11 macallan height = ri->ri_font->fontheight;
1148 1.11 macallan bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
1149 1.11 macallan crmfb_fill_rect(scr->scr_cookie, x, y, width, height, bg);
1150 1.11 macallan }
1151 1.11 macallan
1152 1.11 macallan static void
1153 1.11 macallan crmfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
1154 1.11 macallan {
1155 1.11 macallan struct rasops_info *ri = cookie;
1156 1.11 macallan struct vcons_screen *scr = ri->ri_hw;
1157 1.11 macallan int32_t x, ys, yd, width, height;
1158 1.11 macallan
1159 1.11 macallan x = ri->ri_xorigin;
1160 1.11 macallan ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
1161 1.11 macallan yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
1162 1.11 macallan width = ri->ri_emuwidth;
1163 1.11 macallan height = ri->ri_font->fontheight * nrows;
1164 1.11 macallan crmfb_bitblt(scr->scr_cookie, x, ys, x, yd, width, height, 3);
1165 1.11 macallan }
1166 1.11 macallan
1167 1.11 macallan static void
1168 1.11 macallan crmfb_eraserows(void *cookie, int row, int nrows, long fillattr)
1169 1.11 macallan {
1170 1.11 macallan struct rasops_info *ri = cookie;
1171 1.11 macallan struct vcons_screen *scr = ri->ri_hw;
1172 1.11 macallan int32_t x, y, width, height, bg;
1173 1.11 macallan
1174 1.11 macallan if ((row == 0) && (nrows == ri->ri_rows)) {
1175 1.11 macallan x = y = 0;
1176 1.11 macallan width = ri->ri_width;
1177 1.11 macallan height = ri->ri_height;
1178 1.11 macallan } else {
1179 1.11 macallan x = ri->ri_xorigin;
1180 1.11 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1181 1.11 macallan width = ri->ri_emuwidth;
1182 1.11 macallan height = ri->ri_font->fontheight * nrows;
1183 1.11 macallan }
1184 1.11 macallan bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
1185 1.11 macallan crmfb_fill_rect(scr->scr_cookie, x, y, width, height, bg);
1186 1.11 macallan }
1187 1.11 macallan
1188 1.11 macallan static void
1189 1.11 macallan crmfb_cursor(void *cookie, int on, int row, int col)
1190 1.11 macallan {
1191 1.11 macallan struct rasops_info *ri = cookie;
1192 1.11 macallan struct vcons_screen *scr = ri->ri_hw;
1193 1.11 macallan struct crmfb_softc *sc = scr->scr_cookie;
1194 1.11 macallan int x, y, wi,he;
1195 1.11 macallan
1196 1.11 macallan wi = ri->ri_font->fontwidth;
1197 1.11 macallan he = ri->ri_font->fontheight;
1198 1.11 macallan
1199 1.11 macallan if (ri->ri_flg & RI_CURSOR) {
1200 1.11 macallan x = ri->ri_ccol * wi + ri->ri_xorigin;
1201 1.11 macallan y = ri->ri_crow * he + ri->ri_yorigin;
1202 1.11 macallan crmfb_bitblt(sc, x, y, x, y, wi, he, 12);
1203 1.11 macallan ri->ri_flg &= ~RI_CURSOR;
1204 1.11 macallan }
1205 1.11 macallan
1206 1.11 macallan ri->ri_crow = row;
1207 1.11 macallan ri->ri_ccol = col;
1208 1.11 macallan
1209 1.11 macallan if (on)
1210 1.11 macallan {
1211 1.11 macallan x = ri->ri_ccol * wi + ri->ri_xorigin;
1212 1.11 macallan y = ri->ri_crow * he + ri->ri_yorigin;
1213 1.11 macallan crmfb_bitblt(sc, x, y, x, y, wi, he, 12);
1214 1.11 macallan ri->ri_flg |= RI_CURSOR;
1215 1.11 macallan }
1216 1.11 macallan }
1217 1.11 macallan
1218 1.11 macallan static void
1219 1.11 macallan crmfb_putchar(void *cookie, int row, int col, u_int c, long attr)
1220 1.11 macallan {
1221 1.11 macallan struct rasops_info *ri = cookie;
1222 1.11 macallan struct vcons_screen *scr = ri->ri_hw;
1223 1.11 macallan struct crmfb_softc *sc = scr->scr_cookie;
1224 1.11 macallan struct rasops_info *fri = &sc->sc_rasops;
1225 1.11 macallan int bg;
1226 1.11 macallan int x, y, wi, he, xs;
1227 1.11 macallan
1228 1.11 macallan wi = ri->ri_font->fontwidth;
1229 1.11 macallan he = ri->ri_font->fontheight;
1230 1.11 macallan
1231 1.11 macallan x = ri->ri_xorigin + col * wi;
1232 1.11 macallan y = ri->ri_yorigin + row * he;
1233 1.11 macallan
1234 1.11 macallan bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xff];
1235 1.11 macallan if (c == 0x20) {
1236 1.11 macallan crmfb_fill_rect(sc, x, y, wi, he, bg);
1237 1.11 macallan } else {
1238 1.11 macallan /*
1239 1.11 macallan * we rotate over all available character cells in the scratch
1240 1.11 macallan * tile. The idea is to have more cells than there's room for
1241 1.11 macallan * drawing commands in the engine's pipeline so we don't have
1242 1.11 macallan * to wait for the engine until we're done drawing the
1243 1.11 macallan * character and ready to blit it into place
1244 1.11 macallan */
1245 1.11 macallan fri->ri_ops.putchar(fri, 0, sc->sc_current_cell, c, attr);
1246 1.11 macallan xs = sc->sc_current_cell * wi;
1247 1.11 macallan sc->sc_current_cell++;
1248 1.11 macallan if (sc->sc_current_cell >= sc->sc_cells)
1249 1.11 macallan sc->sc_current_cell = 0;
1250 1.11 macallan crmfb_bitblt(sc, xs, 2048-128, x, y, wi, he, 3);
1251 1.11 macallan }
1252 1.11 macallan }
1253