crmfb.c revision 1.5.4.2 1 1.5.4.2 ad /* $NetBSD: crmfb.c,v 1.5.4.2 2007/06/09 21:37:01 ad Exp $ */
2 1.5.4.2 ad
3 1.5.4.2 ad /*-
4 1.5.4.2 ad * Copyright (c) 2007 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.5.4.2 ad * All rights reserved.
6 1.5.4.2 ad *
7 1.5.4.2 ad * Redistribution and use in source and binary forms, with or without
8 1.5.4.2 ad * modification, are permitted provided that the following conditions
9 1.5.4.2 ad * are met:
10 1.5.4.2 ad * 1. Redistributions of source code must retain the above copyright
11 1.5.4.2 ad * notice, this list of conditions and the following disclaimer.
12 1.5.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.5.4.2 ad * notice, this list of conditions and the following disclaimer in the
14 1.5.4.2 ad * documentation and/or other materials provided with the distribution.
15 1.5.4.2 ad * 3. All advertising materials mentioning features or use of this software
16 1.5.4.2 ad * must display the following acknowledgement:
17 1.5.4.2 ad * This product includes software developed by Jared D. McNeill.
18 1.5.4.2 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
19 1.5.4.2 ad * contributors may be used to endorse or promote products derived
20 1.5.4.2 ad * from this software without specific prior written permission.
21 1.5.4.2 ad *
22 1.5.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.5.4.2 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.5.4.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.5.4.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.5.4.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.5.4.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.5.4.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.5.4.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.5.4.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.5.4.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.5.4.2 ad * POSSIBILITY OF SUCH DAMAGE.
33 1.5.4.2 ad */
34 1.5.4.2 ad
35 1.5.4.2 ad /*
36 1.5.4.2 ad * SGI-CRM (O2) Framebuffer driver
37 1.5.4.2 ad */
38 1.5.4.2 ad
39 1.5.4.2 ad #include <sys/cdefs.h>
40 1.5.4.2 ad __KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1.5.4.2 2007/06/09 21:37:01 ad Exp $");
41 1.5.4.2 ad
42 1.5.4.2 ad #include <sys/param.h>
43 1.5.4.2 ad #include <sys/systm.h>
44 1.5.4.2 ad #include <sys/device.h>
45 1.5.4.2 ad #include <sys/malloc.h>
46 1.5.4.2 ad
47 1.5.4.2 ad #define _SGIMIPS_BUS_DMA_PRIVATE
48 1.5.4.2 ad #include <machine/autoconf.h>
49 1.5.4.2 ad #include <machine/bus.h>
50 1.5.4.2 ad #include <machine/machtype.h>
51 1.5.4.2 ad #include <machine/vmparam.h>
52 1.5.4.2 ad
53 1.5.4.2 ad #include <dev/arcbios/arcbios.h>
54 1.5.4.2 ad #include <dev/arcbios/arcbiosvar.h>
55 1.5.4.2 ad
56 1.5.4.2 ad #include <dev/wscons/wsdisplayvar.h>
57 1.5.4.2 ad #include <dev/wscons/wsconsio.h>
58 1.5.4.2 ad #include <dev/wsfont/wsfont.h>
59 1.5.4.2 ad #include <dev/rasops/rasops.h>
60 1.5.4.2 ad #include <dev/wscons/wsdisplay_vconsvar.h>
61 1.5.4.2 ad
62 1.5.4.2 ad #define CRMFB_SHADOWFB
63 1.5.4.2 ad
64 1.5.4.2 ad struct wsscreen_descr crmfb_defaultscreen = {
65 1.5.4.2 ad "default",
66 1.5.4.2 ad 0, 0,
67 1.5.4.2 ad NULL,
68 1.5.4.2 ad 8, 16,
69 1.5.4.2 ad WSSCREEN_WSCOLORS,
70 1.5.4.2 ad NULL,
71 1.5.4.2 ad };
72 1.5.4.2 ad
73 1.5.4.2 ad const struct wsscreen_descr *_crmfb_scrlist[] = {
74 1.5.4.2 ad &crmfb_defaultscreen,
75 1.5.4.2 ad };
76 1.5.4.2 ad
77 1.5.4.2 ad struct wsscreen_list crmfb_screenlist = {
78 1.5.4.2 ad sizeof(_crmfb_scrlist) / sizeof(struct wsscreen_descr *),
79 1.5.4.2 ad _crmfb_scrlist
80 1.5.4.2 ad };
81 1.5.4.2 ad
82 1.5.4.2 ad static struct vcons_screen crmfb_console_screen;
83 1.5.4.2 ad
84 1.5.4.2 ad static int crmfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
85 1.5.4.2 ad static paddr_t crmfb_mmap(void *, void *, off_t, int);
86 1.5.4.2 ad static void crmfb_init_screen(void *, struct vcons_screen *, int, long *);
87 1.5.4.2 ad
88 1.5.4.2 ad struct wsdisplay_accessops crmfb_accessops = {
89 1.5.4.2 ad crmfb_ioctl,
90 1.5.4.2 ad crmfb_mmap,
91 1.5.4.2 ad NULL, /* alloc_screen */
92 1.5.4.2 ad NULL, /* free_screen */
93 1.5.4.2 ad NULL, /* show_screen */
94 1.5.4.2 ad NULL, /* load_font */
95 1.5.4.2 ad NULL, /* pollc */
96 1.5.4.2 ad NULL, /* scroll */
97 1.5.4.2 ad };
98 1.5.4.2 ad
99 1.5.4.2 ad /* Memory to allocate to SGI-CRM -- remember, this is stolen from
100 1.5.4.2 ad * host memory!
101 1.5.4.2 ad */
102 1.5.4.2 ad #define CRMFB_TILESIZE (512*128)
103 1.5.4.2 ad
104 1.5.4.2 ad #define CRMFB_DOTCLOCK 0x00000004
105 1.5.4.2 ad #define CRMFB_DOTCLOCK_CLKRUN_SHIFT 20
106 1.5.4.2 ad #define CRMFB_VT_XY 0x00010000
107 1.5.4.2 ad #define CRMFB_VT_XY_FREEZE_SHIFT 31
108 1.5.4.2 ad #define CRMFB_VT_INTR01 0x00010020
109 1.5.4.2 ad #define CRMFB_VT_INTR01_EN 0xffffffff
110 1.5.4.2 ad #define CRMFB_VT_INTR23 0x00010024
111 1.5.4.2 ad #define CRMFB_VT_INTR23_EN 0xffffffff
112 1.5.4.2 ad #define CRMFB_VT_VPIX_EN 0x00010038
113 1.5.4.2 ad #define CRMFB_VT_VPIX_EN_OFF_SHIFT 0
114 1.5.4.2 ad #define CRMFB_VT_VCMAP 0x0001003c
115 1.5.4.2 ad #define CRMFB_VT_VCMAP_ON_SHIFT 12
116 1.5.4.2 ad #define CRMFB_VT_HCMAP 0x00010040
117 1.5.4.2 ad #define CRMFB_VT_HCMAP_ON_SHIFT 12
118 1.5.4.2 ad #define CRMFB_OVR_WIDTH_TILE 0x00020000
119 1.5.4.2 ad #define CRMFB_OVR_CONTROL 0x00020008
120 1.5.4.2 ad #define CRMFB_OVR_CONTROL_DMAEN_SHIFT 0
121 1.5.4.2 ad #define CRMFB_FRM_TILESIZE 0x00030000
122 1.5.4.2 ad #define CRMFB_FRM_TILESIZE_RHS_SHIFT 0
123 1.5.4.2 ad #define CRMFB_FRM_TILESIZE_WIDTH_SHIFT 5
124 1.5.4.2 ad #define CRMFB_FRM_TILESIZE_DEPTH_SHIFT 13
125 1.5.4.2 ad #define CRMFB_FRM_TILESIZE_DEPTH_8 0
126 1.5.4.2 ad #define CRMFB_FRM_TILESIZE_DEPTH_16 1
127 1.5.4.2 ad #define CRMFB_FRM_TILESIZE_DEPTH_32 2
128 1.5.4.2 ad #define CRMFB_FRM_TILESIZE_FIFOR_SHIFT 15
129 1.5.4.2 ad #define CRMFB_FRM_PIXSIZE 0x00030004
130 1.5.4.2 ad #define CRMFB_FRM_PIXSIZE_HEIGHT_SHIFT 16
131 1.5.4.2 ad #define CRMFB_FRM_CONTROL 0x0003000c
132 1.5.4.2 ad #define CRMFB_FRM_CONTROL_DMAEN_SHIFT 0
133 1.5.4.2 ad #define CRMFB_FRM_CONTROL_LINEAR_SHIFT 1
134 1.5.4.2 ad #define CRMFB_FRM_CONTROL_TILEPTR_SHIFT 9
135 1.5.4.2 ad #define CRMFB_DID_CONTROL 0x00040004
136 1.5.4.2 ad #define CRMFB_DID_CONTROL_DMAEN_SHIFT 0
137 1.5.4.2 ad #define CRMFB_MODE 0x00048000
138 1.5.4.2 ad #define CRMFB_MODE_TYP_SHIFT 2
139 1.5.4.2 ad #define CRMFB_MODE_TYP_I8 0
140 1.5.4.2 ad #define CRMFB_MODE_TYP_ARGB5 4
141 1.5.4.2 ad #define CRMFB_MODE_TYP_RGB8 5
142 1.5.4.2 ad #define CRMFB_MODE_BUF_SHIFT 0
143 1.5.4.2 ad #define CRMFB_MODE_BUF_BOTH 3
144 1.5.4.2 ad #define CRMFB_CMAP 0x00050000
145 1.5.4.2 ad #define CRMFB_CMAP_FIFO 0x00058000
146 1.5.4.2 ad #define CRMFB_GMAP 0x00060000
147 1.5.4.2 ad #define CRMFB_CRS_CONTROL 0x00070004
148 1.5.4.2 ad
149 1.5.4.2 ad static int crmfb_match(struct device *, struct cfdata *, void *);
150 1.5.4.2 ad static void crmfb_attach(struct device *, struct device *, void *);
151 1.5.4.2 ad int crmfb_probe(void);
152 1.5.4.2 ad
153 1.5.4.2 ad #define KERNADDR(p) ((void *)((p).addr))
154 1.5.4.2 ad #define DMAADDR(p) ((p).map->dm_segs[0].ds_addr)
155 1.5.4.2 ad
156 1.5.4.2 ad struct crmfb_dma {
157 1.5.4.2 ad bus_dmamap_t map;
158 1.5.4.2 ad void *addr;
159 1.5.4.2 ad bus_dma_segment_t segs[1];
160 1.5.4.2 ad int nsegs;
161 1.5.4.2 ad size_t size;
162 1.5.4.2 ad };
163 1.5.4.2 ad
164 1.5.4.2 ad struct crmfb_softc {
165 1.5.4.2 ad struct device sc_dev;
166 1.5.4.2 ad struct vcons_data sc_vd;
167 1.5.4.2 ad
168 1.5.4.2 ad bus_space_tag_t sc_iot;
169 1.5.4.2 ad bus_space_handle_t sc_ioh;
170 1.5.4.2 ad bus_dma_tag_t sc_dmat;
171 1.5.4.2 ad
172 1.5.4.2 ad struct crmfb_dma sc_dma;
173 1.5.4.2 ad struct crmfb_dma sc_dmai;
174 1.5.4.2 ad
175 1.5.4.2 ad int sc_width;
176 1.5.4.2 ad int sc_height;
177 1.5.4.2 ad int sc_depth;
178 1.5.4.2 ad uint32_t sc_fbsize;
179 1.5.4.2 ad uint8_t *sc_shadowfb;
180 1.5.4.2 ad
181 1.5.4.2 ad int sc_wsmode;
182 1.5.4.2 ad u_char sc_cmap_red[256];
183 1.5.4.2 ad u_char sc_cmap_green[256];
184 1.5.4.2 ad u_char sc_cmap_blue[256];
185 1.5.4.2 ad };
186 1.5.4.2 ad
187 1.5.4.2 ad static int crmfb_putcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
188 1.5.4.2 ad static int crmfb_getcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
189 1.5.4.2 ad static void crmfb_set_palette(struct crmfb_softc *,
190 1.5.4.2 ad int, uint8_t, uint8_t, uint8_t);
191 1.5.4.2 ad
192 1.5.4.2 ad CFATTACH_DECL(crmfb, sizeof(struct crmfb_softc),
193 1.5.4.2 ad crmfb_match, crmfb_attach, NULL, NULL);
194 1.5.4.2 ad
195 1.5.4.2 ad static int
196 1.5.4.2 ad crmfb_match(struct device *parent, struct cfdata *cf, void *opaque)
197 1.5.4.2 ad {
198 1.5.4.2 ad return crmfb_probe();
199 1.5.4.2 ad }
200 1.5.4.2 ad
201 1.5.4.2 ad static void
202 1.5.4.2 ad crmfb_attach(struct device *parent, struct device *self, void *opaque)
203 1.5.4.2 ad {
204 1.5.4.2 ad struct mainbus_attach_args *ma;
205 1.5.4.2 ad struct crmfb_softc *sc;
206 1.5.4.2 ad struct rasops_info *ri;
207 1.5.4.2 ad struct wsemuldisplaydev_attach_args aa;
208 1.5.4.2 ad uint32_t d, h;
209 1.5.4.2 ad uint16_t *p;
210 1.5.4.2 ad unsigned long v;
211 1.5.4.2 ad long defattr;
212 1.5.4.2 ad const char *consdev;
213 1.5.4.2 ad int rv, i;
214 1.5.4.2 ad
215 1.5.4.2 ad sc = (struct crmfb_softc *)self;
216 1.5.4.2 ad ma = (struct mainbus_attach_args *)opaque;
217 1.5.4.2 ad
218 1.5.4.2 ad sc->sc_iot = SGIMIPS_BUS_SPACE_CRIME;
219 1.5.4.2 ad sc->sc_dmat = &sgimips_default_bus_dma_tag;
220 1.5.4.2 ad sc->sc_wsmode = WSDISPLAYIO_MODE_EMUL;
221 1.5.4.2 ad
222 1.5.4.2 ad aprint_normal(": SGI CRIME Graphics Display Engine\n");
223 1.5.4.2 ad rv = bus_space_map(sc->sc_iot, ma->ma_addr, 0 /* XXX */,
224 1.5.4.2 ad BUS_SPACE_MAP_LINEAR, &sc->sc_ioh);
225 1.5.4.2 ad if (rv)
226 1.5.4.2 ad panic("crmfb_attach: can't map I/O space");
227 1.5.4.2 ad
228 1.5.4.2 ad /* determine mode configured by firmware */
229 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_VCMAP);
230 1.5.4.2 ad sc->sc_width = (d >> CRMFB_VT_VCMAP_ON_SHIFT) & 0xfff;
231 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_HCMAP);
232 1.5.4.2 ad sc->sc_height = (d >> CRMFB_VT_HCMAP_ON_SHIFT) & 0xfff;
233 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
234 1.5.4.2 ad h = (d >> CRMFB_FRM_TILESIZE_DEPTH_SHIFT) & 0x3;
235 1.5.4.2 ad if (h == 0)
236 1.5.4.2 ad sc->sc_depth = 8;
237 1.5.4.2 ad else if (h == 1)
238 1.5.4.2 ad sc->sc_depth = 16;
239 1.5.4.2 ad else
240 1.5.4.2 ad sc->sc_depth = 32;
241 1.5.4.2 ad
242 1.5.4.2 ad if (sc->sc_width == 0 || sc->sc_height == 0) {
243 1.5.4.2 ad printf("%s: device unusable if not setup by firmware\n",
244 1.5.4.2 ad sc->sc_dev.dv_xname);
245 1.5.4.2 ad bus_space_unmap(sc->sc_iot, sc->sc_ioh, 0 /* XXX */);
246 1.5.4.2 ad return;
247 1.5.4.2 ad }
248 1.5.4.2 ad
249 1.5.4.2 ad printf("%s: initial resolution %dx%d %d bpp\n",
250 1.5.4.2 ad sc->sc_dev.dv_xname, sc->sc_width, sc->sc_height, sc->sc_depth);
251 1.5.4.2 ad
252 1.5.4.2 ad #if 0
253 1.5.4.2 ad /* Changing the colour depth is easy... */
254 1.5.4.2 ad sc->sc_depth = 32;
255 1.5.4.2 ad printf("%s: using resolution %dx%d %d bpp\n",
256 1.5.4.2 ad sc->sc_dev.dv_xname, sc->sc_width, sc->sc_height, sc->sc_depth);
257 1.5.4.2 ad #endif
258 1.5.4.2 ad
259 1.5.4.2 ad sc->sc_fbsize = sc->sc_width * sc->sc_height * sc->sc_depth / 8;
260 1.5.4.2 ad sc->sc_fbsize = (sc->sc_fbsize / CRMFB_TILESIZE) * CRMFB_TILESIZE;
261 1.5.4.2 ad
262 1.5.4.2 ad sc->sc_dmai.size = 128 * sizeof(uint16_t);
263 1.5.4.2 ad rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dmai.size, 65536, 0,
264 1.5.4.2 ad sc->sc_dmai.segs,
265 1.5.4.2 ad sizeof(sc->sc_dmai.segs) / sizeof(sc->sc_dmai.segs[0]),
266 1.5.4.2 ad &sc->sc_dmai.nsegs, BUS_DMA_NOWAIT);
267 1.5.4.2 ad if (rv)
268 1.5.4.2 ad panic("crmfb_attach: can't allocate DMA memory");
269 1.5.4.2 ad rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dmai.segs, sc->sc_dmai.nsegs,
270 1.5.4.2 ad sc->sc_dmai.size, &sc->sc_dmai.addr,
271 1.5.4.2 ad BUS_DMA_NOWAIT);
272 1.5.4.2 ad if (rv)
273 1.5.4.2 ad panic("crmfb_attach: can't map DMA memory");
274 1.5.4.2 ad rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dmai.size, 1,
275 1.5.4.2 ad sc->sc_dmai.size, 0, BUS_DMA_NOWAIT, &sc->sc_dmai.map);
276 1.5.4.2 ad if (rv)
277 1.5.4.2 ad panic("crmfb_attach: can't create DMA map");
278 1.5.4.2 ad rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dmai.map, sc->sc_dmai.addr,
279 1.5.4.2 ad sc->sc_dmai.size, NULL, BUS_DMA_NOWAIT);
280 1.5.4.2 ad if (rv)
281 1.5.4.2 ad panic("crmfb_attach: can't load DMA map");
282 1.5.4.2 ad
283 1.5.4.2 ad sc->sc_dma.size = sc->sc_fbsize;
284 1.5.4.2 ad rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dma.size, 65536, 0,
285 1.5.4.2 ad sc->sc_dma.segs,
286 1.5.4.2 ad sizeof(sc->sc_dma.segs) / sizeof(sc->sc_dma.segs[0]),
287 1.5.4.2 ad &sc->sc_dma.nsegs, BUS_DMA_NOWAIT);
288 1.5.4.2 ad if (rv)
289 1.5.4.2 ad panic("crmfb_attach: can't allocate DMA memory");
290 1.5.4.2 ad rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dma.segs, sc->sc_dma.nsegs,
291 1.5.4.2 ad sc->sc_dma.size, &sc->sc_dma.addr,
292 1.5.4.2 ad BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
293 1.5.4.2 ad if (rv)
294 1.5.4.2 ad panic("crmfb_attach: can't map DMA memory");
295 1.5.4.2 ad rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dma.size, 1,
296 1.5.4.2 ad sc->sc_dma.size, 0, BUS_DMA_NOWAIT, &sc->sc_dma.map);
297 1.5.4.2 ad if (rv)
298 1.5.4.2 ad panic("crmfb_attach: can't create DMA map");
299 1.5.4.2 ad rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dma.map, sc->sc_dma.addr,
300 1.5.4.2 ad sc->sc_dma.size, NULL, BUS_DMA_NOWAIT);
301 1.5.4.2 ad if (rv)
302 1.5.4.2 ad panic("crmfb_attach: can't load DMA map");
303 1.5.4.2 ad
304 1.5.4.2 ad p = KERNADDR(sc->sc_dmai);
305 1.5.4.2 ad v = (unsigned long)DMAADDR(sc->sc_dma);
306 1.5.4.2 ad for (i = 0; i < (sc->sc_fbsize >> 16); i++) {
307 1.5.4.2 ad p[i] = ((uint32_t)v >> 16) + i;
308 1.5.4.2 ad }
309 1.5.4.2 ad
310 1.5.4.2 ad memset(KERNADDR(sc->sc_dma), 0x00, sc->sc_fbsize);
311 1.5.4.2 ad
312 1.5.4.2 ad printf("%s: allocated %d byte fb @ %p (%p)\n", sc->sc_dev.dv_xname,
313 1.5.4.2 ad sc->sc_fbsize, KERNADDR(sc->sc_dmai), KERNADDR(sc->sc_dma));
314 1.5.4.2 ad
315 1.5.4.2 ad #ifdef CRMFB_SHADOWFB
316 1.5.4.2 ad /* setup shadow framebuffer */
317 1.5.4.2 ad sc->sc_shadowfb = malloc(sc->sc_fbsize, M_DEVBUF, M_NOWAIT | M_ZERO);
318 1.5.4.2 ad if (sc->sc_shadowfb == NULL)
319 1.5.4.2 ad aprint_error("%s: WARNING: couldn't allocate shadow fb\n",
320 1.5.4.2 ad sc->sc_dev.dv_xname);
321 1.5.4.2 ad #endif
322 1.5.4.2 ad
323 1.5.4.2 ad ri = &crmfb_console_screen.scr_ri;
324 1.5.4.2 ad memset(ri, 0, sizeof(struct rasops_info));
325 1.5.4.2 ad
326 1.5.4.2 ad vcons_init(&sc->sc_vd, sc, &crmfb_defaultscreen, &crmfb_accessops);
327 1.5.4.2 ad sc->sc_vd.init_screen = crmfb_init_screen;
328 1.5.4.2 ad crmfb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
329 1.5.4.2 ad vcons_init_screen(&sc->sc_vd, &crmfb_console_screen, 1, &defattr);
330 1.5.4.2 ad
331 1.5.4.2 ad crmfb_defaultscreen.ncols = ri->ri_cols;
332 1.5.4.2 ad crmfb_defaultscreen.nrows = ri->ri_rows;
333 1.5.4.2 ad crmfb_defaultscreen.textops = &ri->ri_ops;
334 1.5.4.2 ad crmfb_defaultscreen.capabilities = ri->ri_caps;
335 1.5.4.2 ad crmfb_defaultscreen.modecookie = NULL;
336 1.5.4.2 ad
337 1.5.4.2 ad /* disable DMA */
338 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_OVR_CONTROL);
339 1.5.4.2 ad d &= ~(1 << CRMFB_OVR_CONTROL_DMAEN_SHIFT);
340 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_OVR_CONTROL, d);
341 1.5.4.2 ad DELAY(10000);
342 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
343 1.5.4.2 ad d &= ~(1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
344 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL, d);
345 1.5.4.2 ad DELAY(10000);
346 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_DID_CONTROL, 0);
347 1.5.4.2 ad DELAY(10000);
348 1.5.4.2 ad
349 1.5.4.2 ad /* ensure that CRM starts drawing at the top left of the screen
350 1.5.4.2 ad * when we re-enable DMA later
351 1.5.4.2 ad */
352 1.5.4.2 ad d = (1 << CRMFB_VT_XY_FREEZE_SHIFT);
353 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_XY, d);
354 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
355 1.5.4.2 ad d &= ~(1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
356 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK, d);
357 1.5.4.2 ad
358 1.5.4.2 ad /* reset FIFO */
359 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
360 1.5.4.2 ad d |= (1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
361 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE, d);
362 1.5.4.2 ad d &= ~(1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
363 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE, d);
364 1.5.4.2 ad
365 1.5.4.2 ad /* setup colour mode */
366 1.5.4.2 ad switch (sc->sc_depth) {
367 1.5.4.2 ad case 8:
368 1.5.4.2 ad h = CRMFB_MODE_TYP_I8;
369 1.5.4.2 ad break;
370 1.5.4.2 ad case 16:
371 1.5.4.2 ad h = CRMFB_MODE_TYP_ARGB5;
372 1.5.4.2 ad break;
373 1.5.4.2 ad case 32:
374 1.5.4.2 ad h = CRMFB_MODE_TYP_RGB8;
375 1.5.4.2 ad break;
376 1.5.4.2 ad default:
377 1.5.4.2 ad panic("Unsupported depth");
378 1.5.4.2 ad }
379 1.5.4.2 ad d = h << CRMFB_MODE_TYP_SHIFT;
380 1.5.4.2 ad d |= CRMFB_MODE_BUF_BOTH << CRMFB_MODE_BUF_SHIFT;
381 1.5.4.2 ad for (i = 0; i < (32 * 4); i += 4)
382 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_MODE + i, d);
383 1.5.4.2 ad
384 1.5.4.2 ad /* setup tile pointer, but don't turn on DMA yet! */
385 1.5.4.2 ad h = DMAADDR(sc->sc_dmai);
386 1.5.4.2 ad d = (h >> 9) << CRMFB_FRM_CONTROL_TILEPTR_SHIFT;
387 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL, d);
388 1.5.4.2 ad
389 1.5.4.2 ad /* init framebuffer width and pixel size */
390 1.5.4.2 ad d = (1 << CRMFB_FRM_TILESIZE_WIDTH_SHIFT);
391 1.5.4.2 ad switch (sc->sc_depth) {
392 1.5.4.2 ad case 8:
393 1.5.4.2 ad h = CRMFB_FRM_TILESIZE_DEPTH_8;
394 1.5.4.2 ad break;
395 1.5.4.2 ad case 16:
396 1.5.4.2 ad h = CRMFB_FRM_TILESIZE_DEPTH_16;
397 1.5.4.2 ad break;
398 1.5.4.2 ad case 32:
399 1.5.4.2 ad h = CRMFB_FRM_TILESIZE_DEPTH_32;
400 1.5.4.2 ad break;
401 1.5.4.2 ad default:
402 1.5.4.2 ad panic("Unsupported depth");
403 1.5.4.2 ad }
404 1.5.4.2 ad d |= (h << CRMFB_FRM_TILESIZE_DEPTH_SHIFT);
405 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE, d);
406 1.5.4.2 ad
407 1.5.4.2 ad /* init framebuffer height, we use the trick that the Linux
408 1.5.4.2 ad * driver uses to fool the CRM out of tiled mode and into
409 1.5.4.2 ad * linear mode
410 1.5.4.2 ad */
411 1.5.4.2 ad h = sc->sc_width * sc->sc_height / (512 / (sc->sc_depth / 8));
412 1.5.4.2 ad d = h << CRMFB_FRM_PIXSIZE_HEIGHT_SHIFT;
413 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_PIXSIZE, d);
414 1.5.4.2 ad
415 1.5.4.2 ad /* turn off firmware overlay and hardware cursor */
416 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_OVR_WIDTH_TILE, 0);
417 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_CRS_CONTROL, 0);
418 1.5.4.2 ad
419 1.5.4.2 ad /* enable drawing again */
420 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
421 1.5.4.2 ad d |= (1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
422 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK, d);
423 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_XY, 0);
424 1.5.4.2 ad
425 1.5.4.2 ad /* turn on DMA for the framebuffer */
426 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
427 1.5.4.2 ad d |= (1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
428 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL, d);
429 1.5.4.2 ad
430 1.5.4.2 ad for (i = 0; i < 256; i++) {
431 1.5.4.2 ad crmfb_set_palette(sc, i, rasops_cmap[(i * 3) + 2],
432 1.5.4.2 ad rasops_cmap[(i * 3) + 1], rasops_cmap[(i * 3) + 0]);
433 1.5.4.2 ad sc->sc_cmap_red[i] = rasops_cmap[(i * 3) + 2];
434 1.5.4.2 ad sc->sc_cmap_green[i] = rasops_cmap[(i * 3) + 1];
435 1.5.4.2 ad sc->sc_cmap_blue[i] = rasops_cmap[(i * 3) + 0];
436 1.5.4.2 ad }
437 1.5.4.2 ad
438 1.5.4.2 ad consdev = ARCBIOS->GetEnvironmentVariable("ConsoleOut");
439 1.5.4.2 ad if (consdev != NULL && strcmp(consdev, "video()") == 0) {
440 1.5.4.2 ad wsdisplay_cnattach(&crmfb_defaultscreen, ri, 0, 0, defattr);
441 1.5.4.2 ad aa.console = 1;
442 1.5.4.2 ad } else
443 1.5.4.2 ad aa.console = 0;
444 1.5.4.2 ad aa.scrdata = &crmfb_screenlist;
445 1.5.4.2 ad aa.accessops = &crmfb_accessops;
446 1.5.4.2 ad aa.accesscookie = &sc->sc_vd;
447 1.5.4.2 ad
448 1.5.4.2 ad config_found(self, &aa, wsemuldisplaydevprint);
449 1.5.4.2 ad
450 1.5.4.2 ad return;
451 1.5.4.2 ad }
452 1.5.4.2 ad
453 1.5.4.2 ad int
454 1.5.4.2 ad crmfb_probe(void)
455 1.5.4.2 ad {
456 1.5.4.2 ad
457 1.5.4.2 ad if (mach_type != MACH_SGI_IP32)
458 1.5.4.2 ad return 0;
459 1.5.4.2 ad
460 1.5.4.2 ad return 1;
461 1.5.4.2 ad }
462 1.5.4.2 ad
463 1.5.4.2 ad static int
464 1.5.4.2 ad crmfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
465 1.5.4.2 ad {
466 1.5.4.2 ad struct vcons_data *vd;
467 1.5.4.2 ad struct crmfb_softc *sc;
468 1.5.4.2 ad struct vcons_screen *ms;
469 1.5.4.2 ad struct wsdisplay_fbinfo *wdf;
470 1.5.4.2 ad int nmode;
471 1.5.4.2 ad
472 1.5.4.2 ad vd = (struct vcons_data *)v;
473 1.5.4.2 ad sc = (struct crmfb_softc *)vd->cookie;
474 1.5.4.2 ad ms = (struct vcons_screen *)vd->active;
475 1.5.4.2 ad
476 1.5.4.2 ad switch (cmd) {
477 1.5.4.2 ad case WSDISPLAYIO_GTYPE:
478 1.5.4.2 ad /* not really, but who cares? */
479 1.5.4.2 ad *(u_int *)data = WSDISPLAY_TYPE_NEWPORT;
480 1.5.4.2 ad return 0;
481 1.5.4.2 ad case WSDISPLAYIO_GINFO:
482 1.5.4.2 ad if (vd->active != NULL) {
483 1.5.4.2 ad wdf = (void *)data;
484 1.5.4.2 ad wdf->height = sc->sc_height;
485 1.5.4.2 ad wdf->width = sc->sc_width;
486 1.5.4.2 ad wdf->depth = sc->sc_depth;
487 1.5.4.2 ad wdf->cmsize = 256;
488 1.5.4.2 ad return 0;
489 1.5.4.2 ad } else
490 1.5.4.2 ad return ENODEV;
491 1.5.4.2 ad case WSDISPLAYIO_GETCMAP:
492 1.5.4.2 ad if (sc->sc_depth == 8)
493 1.5.4.2 ad return crmfb_getcmap(sc, (struct wsdisplay_cmap *)data);
494 1.5.4.2 ad else
495 1.5.4.2 ad return EINVAL;
496 1.5.4.2 ad case WSDISPLAYIO_PUTCMAP:
497 1.5.4.2 ad if (sc->sc_depth == 8)
498 1.5.4.2 ad return crmfb_putcmap(sc, (struct wsdisplay_cmap *)data);
499 1.5.4.2 ad else
500 1.5.4.2 ad return EINVAL;
501 1.5.4.2 ad case WSDISPLAYIO_LINEBYTES:
502 1.5.4.2 ad *(u_int *)data = sc->sc_width * sc->sc_depth / 8;
503 1.5.4.2 ad return 0;
504 1.5.4.2 ad case WSDISPLAYIO_SMODE:
505 1.5.4.2 ad nmode = *(int *)data;
506 1.5.4.2 ad if (nmode != sc->sc_wsmode) {
507 1.5.4.2 ad sc->sc_wsmode = nmode;
508 1.5.4.2 ad if (nmode == WSDISPLAYIO_MODE_EMUL)
509 1.5.4.2 ad vcons_redraw_screen(vd->active);
510 1.5.4.2 ad }
511 1.5.4.2 ad return 0;
512 1.5.4.2 ad case WSDISPLAYIO_SVIDEO:
513 1.5.4.2 ad case WSDISPLAYIO_GVIDEO:
514 1.5.4.2 ad return ENODEV; /* not supported yet */
515 1.5.4.2 ad }
516 1.5.4.2 ad
517 1.5.4.2 ad return EPASSTHROUGH;
518 1.5.4.2 ad }
519 1.5.4.2 ad
520 1.5.4.2 ad static paddr_t
521 1.5.4.2 ad crmfb_mmap(void *v, void *vs, off_t offset, int prot)
522 1.5.4.2 ad {
523 1.5.4.2 ad struct vcons_data *vd;
524 1.5.4.2 ad struct crmfb_softc *sc;
525 1.5.4.2 ad paddr_t pa;
526 1.5.4.2 ad
527 1.5.4.2 ad vd = (struct vcons_data *)v;
528 1.5.4.2 ad sc = (struct crmfb_softc *)vd->cookie;
529 1.5.4.2 ad
530 1.5.4.2 ad if (offset >= 0 && offset < sc->sc_fbsize) {
531 1.5.4.2 ad pa = bus_dmamem_mmap(sc->sc_dmat, sc->sc_dma.segs,
532 1.5.4.2 ad sc->sc_dma.nsegs, offset, prot,
533 1.5.4.2 ad BUS_DMA_WAITOK | BUS_DMA_COHERENT);
534 1.5.4.2 ad return pa;
535 1.5.4.2 ad }
536 1.5.4.2 ad
537 1.5.4.2 ad return -1;
538 1.5.4.2 ad }
539 1.5.4.2 ad
540 1.5.4.2 ad static void
541 1.5.4.2 ad crmfb_init_screen(void *c, struct vcons_screen *scr, int existing,
542 1.5.4.2 ad long *defattr)
543 1.5.4.2 ad {
544 1.5.4.2 ad struct crmfb_softc *sc;
545 1.5.4.2 ad struct rasops_info *ri;
546 1.5.4.2 ad
547 1.5.4.2 ad sc = (struct crmfb_softc *)c;
548 1.5.4.2 ad ri = &scr->scr_ri;
549 1.5.4.2 ad
550 1.5.4.2 ad ri->ri_flg = RI_CENTER;
551 1.5.4.2 ad ri->ri_depth = sc->sc_depth;
552 1.5.4.2 ad ri->ri_width = sc->sc_width;
553 1.5.4.2 ad ri->ri_height = sc->sc_height;
554 1.5.4.2 ad ri->ri_stride = ri->ri_width * (ri->ri_depth / 8);
555 1.5.4.2 ad
556 1.5.4.2 ad switch (ri->ri_depth) {
557 1.5.4.2 ad case 16:
558 1.5.4.2 ad ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5;
559 1.5.4.2 ad ri->ri_rpos = 10;
560 1.5.4.2 ad ri->ri_gpos = 5;
561 1.5.4.2 ad ri->ri_bpos = 0;
562 1.5.4.2 ad break;
563 1.5.4.2 ad case 32:
564 1.5.4.2 ad ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8;
565 1.5.4.2 ad ri->ri_rpos = 8;
566 1.5.4.2 ad ri->ri_gpos = 16;
567 1.5.4.2 ad ri->ri_bpos = 24;
568 1.5.4.2 ad break;
569 1.5.4.2 ad }
570 1.5.4.2 ad
571 1.5.4.2 ad if (sc->sc_shadowfb == NULL)
572 1.5.4.2 ad ri->ri_bits = KERNADDR(sc->sc_dma);
573 1.5.4.2 ad else {
574 1.5.4.2 ad ri->ri_bits = sc->sc_shadowfb;
575 1.5.4.2 ad ri->ri_hwbits = KERNADDR(sc->sc_dma);
576 1.5.4.2 ad }
577 1.5.4.2 ad
578 1.5.4.2 ad if (existing)
579 1.5.4.2 ad ri->ri_flg |= RI_CLEAR;
580 1.5.4.2 ad
581 1.5.4.2 ad rasops_init(ri, ri->ri_height / 16, ri->ri_width / 8);
582 1.5.4.2 ad ri->ri_caps = WSSCREEN_WSCOLORS;
583 1.5.4.2 ad rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
584 1.5.4.2 ad ri->ri_width / ri->ri_font->fontwidth);
585 1.5.4.2 ad ri->ri_hw = scr;
586 1.5.4.2 ad
587 1.5.4.2 ad return;
588 1.5.4.2 ad }
589 1.5.4.2 ad
590 1.5.4.2 ad static int
591 1.5.4.2 ad crmfb_putcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
592 1.5.4.2 ad {
593 1.5.4.2 ad u_int idx, cnt;
594 1.5.4.2 ad u_char r[256], g[256], b[256];
595 1.5.4.2 ad u_char *rp, *gp, *bp;
596 1.5.4.2 ad int rv, i;
597 1.5.4.2 ad
598 1.5.4.2 ad idx = cm->index;
599 1.5.4.2 ad cnt = cm->count;
600 1.5.4.2 ad
601 1.5.4.2 ad if (idx >= 255 || cnt > 256 || idx + cnt > 256)
602 1.5.4.2 ad return EINVAL;
603 1.5.4.2 ad
604 1.5.4.2 ad rv = copyin(cm->red, &r[idx], cnt);
605 1.5.4.2 ad if (rv)
606 1.5.4.2 ad return rv;
607 1.5.4.2 ad rv = copyin(cm->green, &g[idx], cnt);
608 1.5.4.2 ad if (rv)
609 1.5.4.2 ad return rv;
610 1.5.4.2 ad rv = copyin(cm->blue, &b[idx], cnt);
611 1.5.4.2 ad if (rv)
612 1.5.4.2 ad return rv;
613 1.5.4.2 ad
614 1.5.4.2 ad memcpy(&sc->sc_cmap_red[idx], &r[idx], cnt);
615 1.5.4.2 ad memcpy(&sc->sc_cmap_green[idx], &g[idx], cnt);
616 1.5.4.2 ad memcpy(&sc->sc_cmap_blue[idx], &b[idx], cnt);
617 1.5.4.2 ad
618 1.5.4.2 ad rp = &sc->sc_cmap_red[idx];
619 1.5.4.2 ad gp = &sc->sc_cmap_green[idx];
620 1.5.4.2 ad bp = &sc->sc_cmap_blue[idx];
621 1.5.4.2 ad
622 1.5.4.2 ad for (i = 0; i < cnt; i++) {
623 1.5.4.2 ad crmfb_set_palette(sc, idx, *rp, *gp, *bp);
624 1.5.4.2 ad idx++;
625 1.5.4.2 ad rp++, gp++, bp++;
626 1.5.4.2 ad }
627 1.5.4.2 ad
628 1.5.4.2 ad return 0;
629 1.5.4.2 ad }
630 1.5.4.2 ad
631 1.5.4.2 ad static int
632 1.5.4.2 ad crmfb_getcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
633 1.5.4.2 ad {
634 1.5.4.2 ad u_int idx, cnt;
635 1.5.4.2 ad int rv;
636 1.5.4.2 ad
637 1.5.4.2 ad idx = cm->index;
638 1.5.4.2 ad cnt = cm->count;
639 1.5.4.2 ad
640 1.5.4.2 ad if (idx >= 255 || cnt > 256 || idx + cnt > 256)
641 1.5.4.2 ad return EINVAL;
642 1.5.4.2 ad
643 1.5.4.2 ad rv = copyout(&sc->sc_cmap_red[idx], cm->red, cnt);
644 1.5.4.2 ad if (rv)
645 1.5.4.2 ad return rv;
646 1.5.4.2 ad rv = copyout(&sc->sc_cmap_green[idx], cm->green, cnt);
647 1.5.4.2 ad if (rv)
648 1.5.4.2 ad return rv;
649 1.5.4.2 ad rv = copyout(&sc->sc_cmap_blue[idx], cm->blue, cnt);
650 1.5.4.2 ad if (rv)
651 1.5.4.2 ad return rv;
652 1.5.4.2 ad
653 1.5.4.2 ad return 0;
654 1.5.4.2 ad }
655 1.5.4.2 ad
656 1.5.4.2 ad static void
657 1.5.4.2 ad crmfb_set_palette(struct crmfb_softc *sc, int reg, uint8_t r, uint8_t g,
658 1.5.4.2 ad uint8_t b)
659 1.5.4.2 ad {
660 1.5.4.2 ad uint32_t val;
661 1.5.4.2 ad
662 1.5.4.2 ad if (reg > 255 || sc->sc_depth != 8)
663 1.5.4.2 ad return;
664 1.5.4.2 ad
665 1.5.4.2 ad while (bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_CMAP_FIFO) >= 63)
666 1.5.4.2 ad DELAY(10);
667 1.5.4.2 ad
668 1.5.4.2 ad val = (r << 24) | (g << 16) | (b << 8);
669 1.5.4.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_CMAP + (reg * 4), val);
670 1.5.4.2 ad
671 1.5.4.2 ad return;
672 1.5.4.2 ad }
673