tcx.c revision 1.1 1 1.1 pk /* $NetBSD: tcx.c,v 1.1 2000/08/20 22:27:07 pk Exp $ */
2 1.1 pk
3 1.1 pk /*
4 1.1 pk * Copyright (c) 1996,1998 The NetBSD Foundation, Inc.
5 1.1 pk * All rights reserved.
6 1.1 pk *
7 1.1 pk * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pk * by Paul Kranenburg.
9 1.1 pk *
10 1.1 pk * Redistribution and use in source and binary forms, with or without
11 1.1 pk * modification, are permitted provided that the following conditions
12 1.1 pk * are met:
13 1.1 pk * 1. Redistributions of source code must retain the above copyright
14 1.1 pk * notice, this list of conditions and the following disclaimer.
15 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pk * notice, this list of conditions and the following disclaimer in the
17 1.1 pk * documentation and/or other materials provided with the distribution.
18 1.1 pk * 3. All advertising materials mentioning features or use of this software
19 1.1 pk * must display the following acknowledgement:
20 1.1 pk * This product includes software developed by the NetBSD
21 1.1 pk * Foundation, Inc. and its contributors.
22 1.1 pk * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 pk * contributors may be used to endorse or promote products derived
24 1.1 pk * from this software without specific prior written permission.
25 1.1 pk *
26 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
37 1.1 pk */
38 1.1 pk
39 1.1 pk /*
40 1.1 pk * color display (TCX) driver.
41 1.1 pk *
42 1.1 pk * Does not handle interrupts, even though they can occur.
43 1.1 pk *
44 1.1 pk * XXX should defer colormap updates to vertical retrace interrupts
45 1.1 pk */
46 1.1 pk
47 1.1 pk #include <sys/param.h>
48 1.1 pk #include <sys/systm.h>
49 1.1 pk #include <sys/buf.h>
50 1.1 pk #include <sys/device.h>
51 1.1 pk #include <sys/ioctl.h>
52 1.1 pk #include <sys/malloc.h>
53 1.1 pk #include <sys/mman.h>
54 1.1 pk #include <sys/tty.h>
55 1.1 pk #include <sys/conf.h>
56 1.1 pk
57 1.1 pk #ifdef DEBUG
58 1.1 pk #include <sys/proc.h>
59 1.1 pk #include <sys/syslog.h>
60 1.1 pk #endif
61 1.1 pk
62 1.1 pk #include <machine/bus.h>
63 1.1 pk #include <machine/autoconf.h>
64 1.1 pk
65 1.1 pk #include <dev/sbus/sbusvar.h>
66 1.1 pk
67 1.1 pk #include <dev/sun/fbio.h>
68 1.1 pk #include <dev/sun/fbvar.h>
69 1.1 pk
70 1.1 pk #include <dev/sun/btreg.h>
71 1.1 pk #include <dev/sun/btvar.h>
72 1.1 pk #include <dev/sun/tcxreg.h>
73 1.1 pk
74 1.1 pk #include <machine/conf.h>
75 1.1 pk
76 1.1 pk /* per-display variables */
77 1.1 pk struct tcx_softc {
78 1.1 pk struct device sc_dev; /* base device */
79 1.1 pk struct sbusdev sc_sd; /* sbus device */
80 1.1 pk struct fbdevice sc_fb; /* frame buffer device */
81 1.1 pk bus_space_tag_t sc_bustag;
82 1.1 pk struct sbus_reg sc_physadr[TCX_NREG]; /* phys addr of h/w */
83 1.1 pk
84 1.1 pk volatile struct bt_regs *sc_bt; /* Brooktree registers */
85 1.1 pk volatile struct tcx_thc *sc_thc;/* THC registers */
86 1.1 pk short sc_blanked; /* true if blanked */
87 1.1 pk union bt_cmap sc_cmap; /* Brooktree color map */
88 1.1 pk };
89 1.1 pk
90 1.1 pk /* autoconfiguration driver */
91 1.1 pk static void tcxattach __P((struct device *, struct device *, void *));
92 1.1 pk static int tcxmatch __P((struct device *, struct cfdata *, void *));
93 1.1 pk static void tcx_unblank __P((struct device *));
94 1.1 pk
95 1.1 pk /* cdevsw prototypes */
96 1.1 pk cdev_decl(tcx);
97 1.1 pk
98 1.1 pk struct cfattach tcx_ca = {
99 1.1 pk sizeof(struct tcx_softc), tcxmatch, tcxattach
100 1.1 pk };
101 1.1 pk
102 1.1 pk extern struct cfdriver tcx_cd;
103 1.1 pk
104 1.1 pk /* frame buffer generic driver */
105 1.1 pk static struct fbdriver tcx_fbdriver = {
106 1.1 pk tcx_unblank, tcxopen, tcxclose, tcxioctl, tcxpoll, tcxmmap
107 1.1 pk };
108 1.1 pk
109 1.1 pk static void tcx_reset __P((struct tcx_softc *));
110 1.1 pk static void tcx_loadcmap __P((struct tcx_softc *, int, int));
111 1.1 pk
112 1.1 pk #define OBPNAME "SUNW,tcx"
113 1.1 pk /*
114 1.1 pk * Match a tcx.
115 1.1 pk */
116 1.1 pk int
117 1.1 pk tcxmatch(parent, cf, aux)
118 1.1 pk struct device *parent;
119 1.1 pk struct cfdata *cf;
120 1.1 pk void *aux;
121 1.1 pk {
122 1.1 pk struct sbus_attach_args *sa = aux;
123 1.1 pk
124 1.1 pk return (strcmp(sa->sa_name, OBPNAME) == 0);
125 1.1 pk }
126 1.1 pk
127 1.1 pk /*
128 1.1 pk * Attach a display.
129 1.1 pk */
130 1.1 pk void
131 1.1 pk tcxattach(parent, self, args)
132 1.1 pk struct device *parent, *self;
133 1.1 pk void *args;
134 1.1 pk {
135 1.1 pk struct tcx_softc *sc = (struct tcx_softc *)self;
136 1.1 pk struct sbus_attach_args *sa = args;
137 1.1 pk int node, ramsize;
138 1.1 pk volatile struct bt_regs *bt;
139 1.1 pk struct fbdevice *fb = &sc->sc_fb;
140 1.1 pk bus_space_handle_t bh;
141 1.1 pk int isconsole;
142 1.1 pk
143 1.1 pk sc->sc_bustag = sa->sa_bustag;
144 1.1 pk node = sa->sa_node;
145 1.1 pk
146 1.1 pk fb->fb_driver = &tcx_fbdriver;
147 1.1 pk fb->fb_device = &sc->sc_dev;
148 1.1 pk /* Mask out invalid flags from the user. */
149 1.1 pk fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
150 1.1 pk fb->fb_type.fb_depth = node_has_property(node, "tcx-24-bit")
151 1.1 pk ? 24
152 1.1 pk : (node_has_property(node, "tcx-8-bit")
153 1.1 pk ? 8
154 1.1 pk : 8);
155 1.1 pk
156 1.1 pk fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
157 1.1 pk
158 1.1 pk ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
159 1.1 pk fb->fb_type.fb_cmsize = 256;
160 1.1 pk fb->fb_type.fb_size = ramsize;
161 1.1 pk printf(": %s, %d x %d", OBPNAME,
162 1.1 pk fb->fb_type.fb_width,
163 1.1 pk fb->fb_type.fb_height);
164 1.1 pk
165 1.1 pk /*
166 1.1 pk * XXX - should be set to FBTYPE_TCX.
167 1.1 pk * XXX For CG3 emulation to work in current (96/6) X11 servers,
168 1.1 pk * XXX `fbtype' must point to an "unregocnised" entry.
169 1.1 pk */
170 1.1 pk fb->fb_type.fb_type = FBTYPE_RESERVED3;
171 1.1 pk
172 1.1 pk
173 1.1 pk if (sa->sa_nreg != TCX_NREG) {
174 1.1 pk printf("%s: only %d register sets\n",
175 1.1 pk self->dv_xname, sa->sa_nreg);
176 1.1 pk return;
177 1.1 pk }
178 1.1 pk bcopy(sa->sa_reg, sc->sc_physadr,
179 1.1 pk sa->sa_nreg * sizeof(struct sbus_reg));
180 1.1 pk
181 1.1 pk /* XXX - fix THC and TEC offsets */
182 1.1 pk sc->sc_physadr[TCX_REG_TEC].sbr_offset += 0x1000;
183 1.1 pk sc->sc_physadr[TCX_REG_THC].sbr_offset += 0x1000;
184 1.1 pk
185 1.1 pk /* Map the register banks we care about */
186 1.1 pk if (sbus_bus_map(sa->sa_bustag,
187 1.1 pk (bus_type_t)sc->sc_physadr[TCX_REG_THC].sbr_slot,
188 1.1 pk (bus_addr_t)sc->sc_physadr[TCX_REG_THC].sbr_offset,
189 1.1 pk sizeof (struct tcx_thc),
190 1.1 pk BUS_SPACE_MAP_LINEAR,
191 1.1 pk 0, &bh) != 0) {
192 1.1 pk printf("tcxattach: cannot map thc registers\n");
193 1.1 pk return;
194 1.1 pk }
195 1.1 pk sc->sc_thc = (volatile struct tcx_thc *)bh;
196 1.1 pk
197 1.1 pk if (sbus_bus_map(sa->sa_bustag,
198 1.1 pk (bus_type_t)sc->sc_physadr[TCX_REG_CMAP].sbr_slot,
199 1.1 pk (bus_addr_t)sc->sc_physadr[TCX_REG_CMAP].sbr_offset,
200 1.1 pk sizeof (struct bt_regs),
201 1.1 pk BUS_SPACE_MAP_LINEAR,
202 1.1 pk 0, &bh) != 0) {
203 1.1 pk printf("tcxattach: cannot map bt registers\n");
204 1.1 pk return;
205 1.1 pk }
206 1.1 pk sc->sc_bt = bt = (volatile struct bt_regs *)bh;
207 1.1 pk
208 1.1 pk isconsole = fb_is_console(node);
209 1.1 pk
210 1.1 pk printf(", id %d, rev %d, sense %d",
211 1.1 pk (sc->sc_thc->thc_config & THC_CFG_FBID) >> THC_CFG_FBID_SHIFT,
212 1.1 pk (sc->sc_thc->thc_config & THC_CFG_REV) >> THC_CFG_REV_SHIFT,
213 1.1 pk (sc->sc_thc->thc_config & THC_CFG_SENSE) >> THC_CFG_SENSE_SHIFT
214 1.1 pk );
215 1.1 pk
216 1.1 pk /* reset cursor & frame buffer controls */
217 1.1 pk tcx_reset(sc);
218 1.1 pk
219 1.1 pk /* Initialize the default color map. */
220 1.1 pk bt_initcmap(&sc->sc_cmap, 256);
221 1.1 pk tcx_loadcmap(sc, 0, 256);
222 1.1 pk
223 1.1 pk /* enable video */
224 1.1 pk sc->sc_thc->thc_hcmisc |= THC_MISC_VIDEN;
225 1.1 pk
226 1.1 pk if (isconsole) {
227 1.1 pk printf(" (console)\n");
228 1.1 pk } else
229 1.1 pk printf("\n");
230 1.1 pk
231 1.1 pk sbus_establish(&sc->sc_sd, &sc->sc_dev);
232 1.1 pk fb_attach(&sc->sc_fb, isconsole);
233 1.1 pk }
234 1.1 pk
235 1.1 pk int
236 1.1 pk tcxopen(dev, flags, mode, p)
237 1.1 pk dev_t dev;
238 1.1 pk int flags, mode;
239 1.1 pk struct proc *p;
240 1.1 pk {
241 1.1 pk int unit = minor(dev);
242 1.1 pk
243 1.1 pk if (unit >= tcx_cd.cd_ndevs || tcx_cd.cd_devs[unit] == NULL)
244 1.1 pk return (ENXIO);
245 1.1 pk return (0);
246 1.1 pk }
247 1.1 pk
248 1.1 pk int
249 1.1 pk tcxclose(dev, flags, mode, p)
250 1.1 pk dev_t dev;
251 1.1 pk int flags, mode;
252 1.1 pk struct proc *p;
253 1.1 pk {
254 1.1 pk struct tcx_softc *sc = tcx_cd.cd_devs[minor(dev)];
255 1.1 pk
256 1.1 pk tcx_reset(sc);
257 1.1 pk return (0);
258 1.1 pk }
259 1.1 pk
260 1.1 pk int
261 1.1 pk tcxioctl(dev, cmd, data, flags, p)
262 1.1 pk dev_t dev;
263 1.1 pk u_long cmd;
264 1.1 pk caddr_t data;
265 1.1 pk int flags;
266 1.1 pk struct proc *p;
267 1.1 pk {
268 1.1 pk struct tcx_softc *sc = tcx_cd.cd_devs[minor(dev)];
269 1.1 pk int error;
270 1.1 pk
271 1.1 pk switch (cmd) {
272 1.1 pk
273 1.1 pk case FBIOGTYPE:
274 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
275 1.1 pk break;
276 1.1 pk
277 1.1 pk case FBIOGATTR:
278 1.1 pk #define fba ((struct fbgattr *)data)
279 1.1 pk fba->real_type = sc->sc_fb.fb_type.fb_type;
280 1.1 pk fba->owner = 0; /* XXX ??? */
281 1.1 pk fba->fbtype = sc->sc_fb.fb_type;
282 1.1 pk fba->sattr.flags = 0;
283 1.1 pk fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
284 1.1 pk fba->sattr.dev_specific[0] = -1;
285 1.1 pk fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
286 1.1 pk fba->emu_types[1] = FBTYPE_SUN3COLOR;
287 1.1 pk fba->emu_types[2] = -1;
288 1.1 pk #undef fba
289 1.1 pk break;
290 1.1 pk
291 1.1 pk case FBIOGETCMAP:
292 1.1 pk #define p ((struct fbcmap *)data)
293 1.1 pk return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
294 1.1 pk
295 1.1 pk case FBIOPUTCMAP:
296 1.1 pk /* copy to software map */
297 1.1 pk error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
298 1.1 pk if (error)
299 1.1 pk return (error);
300 1.1 pk /* now blast them into the chip */
301 1.1 pk /* XXX should use retrace interrupt */
302 1.1 pk tcx_loadcmap(sc, p->index, p->count);
303 1.1 pk #undef p
304 1.1 pk break;
305 1.1 pk
306 1.1 pk case FBIOGVIDEO:
307 1.1 pk *(int *)data = sc->sc_blanked;
308 1.1 pk break;
309 1.1 pk
310 1.1 pk case FBIOSVIDEO:
311 1.1 pk if (*(int *)data)
312 1.1 pk tcx_unblank(&sc->sc_dev);
313 1.1 pk else if (!sc->sc_blanked) {
314 1.1 pk sc->sc_blanked = 1;
315 1.1 pk sc->sc_thc->thc_hcmisc &= ~THC_MISC_VIDEN;
316 1.1 pk /* Put monitor in `power-saving mode' */
317 1.1 pk sc->sc_thc->thc_hcmisc |= THC_MISC_VSYNC_DISABLE;
318 1.1 pk sc->sc_thc->thc_hcmisc |= THC_MISC_HSYNC_DISABLE;
319 1.1 pk }
320 1.1 pk break;
321 1.1 pk
322 1.1 pk default:
323 1.1 pk #ifdef DEBUG
324 1.1 pk log(LOG_NOTICE, "tcxioctl(0x%lx) (%s[%d])\n", cmd,
325 1.1 pk p->p_comm, p->p_pid);
326 1.1 pk #endif
327 1.1 pk return (ENOTTY);
328 1.1 pk }
329 1.1 pk return (0);
330 1.1 pk }
331 1.1 pk
332 1.1 pk int
333 1.1 pk tcxpoll(dev, events, p)
334 1.1 pk dev_t dev;
335 1.1 pk int events;
336 1.1 pk struct proc *p;
337 1.1 pk {
338 1.1 pk
339 1.1 pk return (seltrue(dev, events, p));
340 1.1 pk }
341 1.1 pk
342 1.1 pk /*
343 1.1 pk * Clean up hardware state (e.g., after bootup or after X crashes).
344 1.1 pk */
345 1.1 pk static void
346 1.1 pk tcx_reset(sc)
347 1.1 pk struct tcx_softc *sc;
348 1.1 pk {
349 1.1 pk volatile struct bt_regs *bt;
350 1.1 pk
351 1.1 pk /* Enable cursor in Brooktree DAC. */
352 1.1 pk bt = sc->sc_bt;
353 1.1 pk bt->bt_addr = 0x06 << 24;
354 1.1 pk bt->bt_ctrl |= 0x03 << 24;
355 1.1 pk }
356 1.1 pk
357 1.1 pk /*
358 1.1 pk * Load a subset of the current (new) colormap into the color DAC.
359 1.1 pk */
360 1.1 pk static void
361 1.1 pk tcx_loadcmap(sc, start, ncolors)
362 1.1 pk struct tcx_softc *sc;
363 1.1 pk int start, ncolors;
364 1.1 pk {
365 1.1 pk volatile struct bt_regs *bt;
366 1.1 pk u_int *ip, i;
367 1.1 pk int count;
368 1.1 pk
369 1.1 pk ip = &sc->sc_cmap.cm_chip[BT_D4M3(start)]; /* start/4 * 3 */
370 1.1 pk count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
371 1.1 pk bt = sc->sc_bt;
372 1.1 pk bt->bt_addr = BT_D4M4(start) << 24;
373 1.1 pk while (--count >= 0) {
374 1.1 pk i = *ip++;
375 1.1 pk /* hardware that makes one want to pound boards with hammers */
376 1.1 pk bt->bt_cmap = i;
377 1.1 pk bt->bt_cmap = i << 8;
378 1.1 pk bt->bt_cmap = i << 16;
379 1.1 pk bt->bt_cmap = i << 24;
380 1.1 pk }
381 1.1 pk }
382 1.1 pk
383 1.1 pk static void
384 1.1 pk tcx_unblank(dev)
385 1.1 pk struct device *dev;
386 1.1 pk {
387 1.1 pk struct tcx_softc *sc = (struct tcx_softc *)dev;
388 1.1 pk
389 1.1 pk if (sc->sc_blanked) {
390 1.1 pk sc->sc_blanked = 0;
391 1.1 pk sc->sc_thc->thc_hcmisc &= ~THC_MISC_VSYNC_DISABLE;
392 1.1 pk sc->sc_thc->thc_hcmisc &= ~THC_MISC_HSYNC_DISABLE;
393 1.1 pk sc->sc_thc->thc_hcmisc |= THC_MISC_VIDEN;
394 1.1 pk }
395 1.1 pk }
396 1.1 pk
397 1.1 pk /*
398 1.1 pk * Base addresses at which users can mmap() the various pieces of a tcx.
399 1.1 pk */
400 1.1 pk #define TCX_USER_RAM 0x00000000
401 1.1 pk #define TCX_USER_RAM24 0x01000000
402 1.1 pk #define TCX_USER_RAM_COMPAT 0x04000000 /* cg3 emulation */
403 1.1 pk #define TCX_USER_STIP 0x10000000
404 1.1 pk #define TCX_USER_BLIT 0x20000000
405 1.1 pk #define TCX_USER_RDFB32 0x28000000
406 1.1 pk #define TCX_USER_RSTIP 0x30000000
407 1.1 pk #define TCX_USER_RBLIT 0x38000000
408 1.1 pk #define TCX_USER_TEC 0x70001000
409 1.1 pk #define TCX_USER_BTREGS 0x70002000
410 1.1 pk #define TCX_USER_THC 0x70004000
411 1.1 pk #define TCX_USER_DHC 0x70008000
412 1.1 pk #define TCX_USER_ALT 0x7000a000
413 1.1 pk #define TCX_USER_UART 0x7000c000
414 1.1 pk #define TCX_USER_VRT 0x7000e000
415 1.1 pk #define TCX_USER_ROM 0x70010000
416 1.1 pk
417 1.1 pk struct mmo {
418 1.1 pk u_int mo_uaddr; /* user (virtual) address */
419 1.1 pk u_int mo_size; /* size, or 0 for video ram size */
420 1.1 pk u_int mo_bank; /* register bank number */
421 1.1 pk };
422 1.1 pk
423 1.1 pk /*
424 1.1 pk * Return the address that would map the given device at the given
425 1.1 pk * offset, allowing for the given protection, or return -1 for error.
426 1.1 pk *
427 1.1 pk * XXX needs testing against `demanding' applications (e.g., aviator)
428 1.1 pk */
429 1.1 pk paddr_t
430 1.1 pk tcxmmap(dev, off, prot)
431 1.1 pk dev_t dev;
432 1.1 pk off_t off;
433 1.1 pk int prot;
434 1.1 pk {
435 1.1 pk struct tcx_softc *sc = tcx_cd.cd_devs[minor(dev)];
436 1.1 pk bus_space_handle_t bh;
437 1.1 pk struct sbus_reg *rr = sc->sc_physadr;
438 1.1 pk struct mmo *mo;
439 1.1 pk u_int u, sz;
440 1.1 pk static struct mmo mmo[] = {
441 1.1 pk { TCX_USER_RAM, 0, TCX_REG_DFB8 },
442 1.1 pk { TCX_USER_RAM24, 0, TCX_REG_DFB24 },
443 1.1 pk { TCX_USER_RAM_COMPAT, 0, TCX_REG_DFB8 },
444 1.1 pk
445 1.1 pk { TCX_USER_STIP, 1, TCX_REG_STIP },
446 1.1 pk { TCX_USER_BLIT, 1, TCX_REG_BLIT },
447 1.1 pk { TCX_USER_RDFB32, 1, TCX_REG_RDFB32 },
448 1.1 pk { TCX_USER_RSTIP, 1, TCX_REG_RSTIP },
449 1.1 pk { TCX_USER_RBLIT, 1, TCX_REG_RBLIT },
450 1.1 pk { TCX_USER_TEC, 1, TCX_REG_TEC },
451 1.1 pk { TCX_USER_BTREGS, 8192 /* XXX */, TCX_REG_CMAP },
452 1.1 pk { TCX_USER_THC, sizeof(struct tcx_thc), TCX_REG_THC },
453 1.1 pk { TCX_USER_DHC, 1, TCX_REG_DHC },
454 1.1 pk { TCX_USER_ALT, 1, TCX_REG_ALT },
455 1.1 pk { TCX_USER_ROM, 65536, TCX_REG_ROM },
456 1.1 pk };
457 1.1 pk #define NMMO (sizeof mmo / sizeof *mmo)
458 1.1 pk
459 1.1 pk if (off & PGOFSET)
460 1.1 pk panic("tcxmmap");
461 1.1 pk
462 1.1 pk /*
463 1.1 pk * Entries with size 0 map video RAM (i.e., the size in fb data).
464 1.1 pk *
465 1.1 pk * Since we work in pages, the fact that the map offset table's
466 1.1 pk * sizes are sometimes bizarre (e.g., 1) is effectively ignored:
467 1.1 pk * one byte is as good as one page.
468 1.1 pk */
469 1.1 pk for (mo = mmo; mo < &mmo[NMMO]; mo++) {
470 1.1 pk if ((u_int)off < mo->mo_uaddr)
471 1.1 pk continue;
472 1.1 pk u = off - mo->mo_uaddr;
473 1.1 pk sz = mo->mo_size ? mo->mo_size : sc->sc_fb.fb_type.fb_size;
474 1.1 pk if (u < sz) {
475 1.1 pk bus_type_t t = (bus_type_t)rr[mo->mo_bank].sbr_slot;
476 1.1 pk bus_addr_t a = (bus_addr_t)rr[mo->mo_bank].sbr_offset;
477 1.1 pk
478 1.1 pk if (bus_space_mmap(sc->sc_bustag,
479 1.1 pk t,
480 1.1 pk a + u,
481 1.1 pk BUS_SPACE_MAP_LINEAR, &bh))
482 1.1 pk return (-1);
483 1.1 pk
484 1.1 pk return ((paddr_t)bh);
485 1.1 pk }
486 1.1 pk }
487 1.1 pk return (-1); /* not a user-map offset */
488 1.1 pk }
489