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