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