Home | History | Annotate | Line # | Download | only in dev
ofb.c revision 1.8
      1  1.8    tsubai /*	$NetBSD: ofb.c,v 1.8 1999/02/19 14:02:33 tsubai Exp $	*/
      2  1.1    tsubai 
      3  1.1    tsubai /*
      4  1.1    tsubai  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  1.1    tsubai  * All rights reserved.
      6  1.1    tsubai  *
      7  1.1    tsubai  * Author: Chris G. Demetriou
      8  1.1    tsubai  *
      9  1.1    tsubai  * Permission to use, copy, modify and distribute this software and
     10  1.1    tsubai  * its documentation is hereby granted, provided that both the copyright
     11  1.1    tsubai  * notice and this permission notice appear in all copies of the
     12  1.1    tsubai  * software, derivative works or modified versions, and any portions
     13  1.1    tsubai  * thereof, and that both notices appear in supporting documentation.
     14  1.1    tsubai  *
     15  1.1    tsubai  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.1    tsubai  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  1.1    tsubai  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.1    tsubai  *
     19  1.1    tsubai  * Carnegie Mellon requests users of this software to return to
     20  1.1    tsubai  *
     21  1.1    tsubai  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  1.1    tsubai  *  School of Computer Science
     23  1.1    tsubai  *  Carnegie Mellon University
     24  1.1    tsubai  *  Pittsburgh PA 15213-3890
     25  1.1    tsubai  *
     26  1.1    tsubai  * any improvements or extensions that they make and grant Carnegie the
     27  1.1    tsubai  * rights to redistribute these changes.
     28  1.1    tsubai  */
     29  1.1    tsubai 
     30  1.1    tsubai #include <sys/param.h>
     31  1.1    tsubai #include <sys/buf.h>
     32  1.1    tsubai #include <sys/conf.h>
     33  1.1    tsubai #include <sys/device.h>
     34  1.1    tsubai #include <sys/ioctl.h>
     35  1.1    tsubai #include <sys/kernel.h>
     36  1.1    tsubai #include <sys/malloc.h>
     37  1.1    tsubai #include <sys/systm.h>
     38  1.1    tsubai 
     39  1.3    tsubai #include <dev/pci/pcidevs.h>
     40  1.1    tsubai #include <dev/pci/pcireg.h>
     41  1.1    tsubai #include <dev/pci/pcivar.h>
     42  1.1    tsubai 
     43  1.1    tsubai #include <dev/rcons/raster.h>
     44  1.1    tsubai #include <dev/wscons/wsconsio.h>
     45  1.1    tsubai #include <dev/wscons/wscons_raster.h>
     46  1.1    tsubai #include <dev/wscons/wsdisplayvar.h>
     47  1.1    tsubai 
     48  1.1    tsubai #include <machine/bus.h>
     49  1.1    tsubai #include <machine/grfioctl.h>
     50  1.1    tsubai 
     51  1.1    tsubai #include <macppc/dev/ofbvar.h>
     52  1.1    tsubai 
     53  1.1    tsubai int	ofbmatch __P((struct device *, struct cfdata *, void *));
     54  1.1    tsubai void	ofbattach __P((struct device *, struct device *, void *));
     55  1.1    tsubai int	ofbprint __P((void *, const char *));
     56  1.1    tsubai 
     57  1.1    tsubai struct cfattach ofb_ca = {
     58  1.1    tsubai 	sizeof(struct ofb_softc), ofbmatch, ofbattach,
     59  1.1    tsubai };
     60  1.1    tsubai 
     61  1.1    tsubai struct ofb_devconfig ofb_console_dc;
     62  1.1    tsubai 
     63  1.1    tsubai struct wsdisplay_emulops ofb_emulops = {
     64  1.1    tsubai 	rcons_cursor,			/* could use hardware cursor; punt */
     65  1.1    tsubai 	rcons_mapchar,
     66  1.1    tsubai 	rcons_putchar,
     67  1.1    tsubai 	rcons_copycols,
     68  1.1    tsubai 	rcons_erasecols,
     69  1.1    tsubai 	rcons_copyrows,
     70  1.1    tsubai 	rcons_eraserows,
     71  1.1    tsubai 	rcons_alloc_attr
     72  1.1    tsubai };
     73  1.1    tsubai 
     74  1.1    tsubai struct wsscreen_descr ofb_stdscreen = {
     75  1.1    tsubai 	"std",
     76  1.1    tsubai 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
     77  1.1    tsubai 	&ofb_emulops,
     78  1.1    tsubai 	0, 0,
     79  1.1    tsubai 	WSSCREEN_REVERSE
     80  1.1    tsubai };
     81  1.1    tsubai 
     82  1.1    tsubai const struct wsscreen_descr *_ofb_scrlist[] = {
     83  1.1    tsubai 	&ofb_stdscreen,
     84  1.1    tsubai 	/* XXX other formats, graphics screen? */
     85  1.1    tsubai };
     86  1.1    tsubai 
     87  1.1    tsubai struct wsscreen_list ofb_screenlist = {
     88  1.1    tsubai 	sizeof(_ofb_scrlist) / sizeof(struct wsscreen_descr *), _ofb_scrlist
     89  1.1    tsubai };
     90  1.1    tsubai 
     91  1.1    tsubai static int ofb_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
     92  1.1    tsubai static int ofb_mmap __P((void *, off_t, int));
     93  1.1    tsubai static int ofb_alloc_screen __P((void *, const struct wsscreen_descr *,
     94  1.1    tsubai 				void **, int *, int *, long *));
     95  1.1    tsubai static void ofb_free_screen __P((void *, void *));
     96  1.1    tsubai static void ofb_show_screen __P((void *, void *));
     97  1.1    tsubai 
     98  1.1    tsubai struct wsdisplay_accessops ofb_accessops = {
     99  1.1    tsubai 	ofb_ioctl,
    100  1.1    tsubai 	ofb_mmap,
    101  1.1    tsubai 	ofb_alloc_screen,
    102  1.1    tsubai 	ofb_free_screen,
    103  1.1    tsubai 	ofb_show_screen,
    104  1.6  drochner 	0 /* load_font */
    105  1.1    tsubai };
    106  1.1    tsubai 
    107  1.1    tsubai static void ofb_common_init __P((int, struct ofb_devconfig *));
    108  1.1    tsubai 
    109  1.1    tsubai int
    110  1.1    tsubai ofbmatch(parent, match, aux)
    111  1.1    tsubai 	struct device *parent;
    112  1.1    tsubai 	struct cfdata *match;
    113  1.1    tsubai 	void *aux;
    114  1.1    tsubai {
    115  1.1    tsubai 	struct pci_attach_args *pa = aux;
    116  1.1    tsubai 
    117  1.3    tsubai 	/* /chaos/control */
    118  1.3    tsubai 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
    119  1.3    tsubai 	    PCI_PRODUCT(pa->pa_id) == 3)
    120  1.3    tsubai 		return 1;
    121  1.1    tsubai 
    122  1.3    tsubai 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY)
    123  1.3    tsubai 		return 1;
    124  1.3    tsubai 
    125  1.3    tsubai 	return 0;
    126  1.1    tsubai }
    127  1.1    tsubai 
    128  1.1    tsubai void
    129  1.1    tsubai ofbattach(parent, self, aux)
    130  1.1    tsubai 	struct device *parent, *self;
    131  1.1    tsubai 	void *aux;
    132  1.1    tsubai {
    133  1.1    tsubai 	struct ofb_softc *sc = (struct ofb_softc *)self;
    134  1.1    tsubai 	struct pci_attach_args *pa = aux;
    135  1.1    tsubai 	struct wsemuldisplaydev_attach_args a;
    136  1.1    tsubai 	int console;
    137  1.1    tsubai 	struct ofb_devconfig *dc;
    138  1.5    tsubai 	char devinfo[256];
    139  1.1    tsubai 
    140  1.1    tsubai 	console = ofb_is_console();
    141  1.1    tsubai 
    142  1.1    tsubai 	if (console) {
    143  1.1    tsubai 		dc = &ofb_console_dc;
    144  1.1    tsubai 		sc->nscreens = 1;
    145  1.1    tsubai 	} else {
    146  1.8    tsubai 		int node, i, screenbytes;
    147  1.1    tsubai 
    148  1.1    tsubai 		dc = malloc(sizeof(struct ofb_devconfig), M_DEVBUF, M_WAITOK);
    149  1.1    tsubai 		bzero(dc, sizeof(struct ofb_devconfig));
    150  1.5    tsubai 		node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
    151  1.3    tsubai 		if (node == 0) {
    152  1.3    tsubai 			printf(": ofdev not found\n");
    153  1.3    tsubai 			return;
    154  1.3    tsubai 		}
    155  1.1    tsubai 		ofb_common_init(node, dc);
    156  1.8    tsubai 
    157  1.8    tsubai 		/* Set colormap to black on white. */
    158  1.8    tsubai 		OF_call_method_1("color!", dc->dc_ih, 4, 0, 0, 0, 0xff);
    159  1.8    tsubai 		OF_call_method_1("color!", dc->dc_ih, 4, 255, 255, 255, 0);
    160  1.8    tsubai 		screenbytes = dc->dc_height * dc->dc_linebytes;
    161  1.8    tsubai 		for (i = 0; i < screenbytes; i += sizeof(u_int32_t))
    162  1.8    tsubai 			*(u_int32_t *)(dc->dc_paddr + i) = 0;
    163  1.1    tsubai 	}
    164  1.1    tsubai 	sc->sc_dc = dc;
    165  1.1    tsubai 
    166  1.1    tsubai 	if (dc->dc_paddr == 0) {
    167  1.1    tsubai 		printf(": cannot map framebuffer\n");
    168  1.1    tsubai 		return;
    169  1.1    tsubai 	}
    170  1.1    tsubai 
    171  1.5    tsubai 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    172  1.5    tsubai 	printf(": %s\n", devinfo);
    173  1.5    tsubai 	printf("%s: %d x %d, %dbpp\n", self->dv_xname,
    174  1.1    tsubai 	    dc->dc_raster.width, dc->dc_raster.height, dc->dc_raster.depth);
    175  1.1    tsubai 
    176  1.1    tsubai 	a.console = console;
    177  1.1    tsubai 	a.scrdata = &ofb_screenlist;
    178  1.1    tsubai 	a.accessops = &ofb_accessops;
    179  1.1    tsubai 	a.accesscookie = sc;
    180  1.1    tsubai 
    181  1.1    tsubai 	config_found(self, &a, wsemuldisplaydevprint);
    182  1.1    tsubai }
    183  1.1    tsubai 
    184  1.1    tsubai void
    185  1.1    tsubai ofb_common_init(node, dc)
    186  1.1    tsubai 	int node;
    187  1.1    tsubai 	struct ofb_devconfig *dc;
    188  1.1    tsubai {
    189  1.1    tsubai 	struct raster *rap;
    190  1.1    tsubai 	struct rcons *rcp;
    191  1.1    tsubai 	int i;
    192  1.1    tsubai 	int addr, width, height, linebytes, depth;
    193  1.1    tsubai 
    194  1.1    tsubai 	if (dc->dc_ih == 0) {
    195  1.1    tsubai 		char name[64];
    196  1.1    tsubai 
    197  1.1    tsubai 		bzero(name, 64);
    198  1.1    tsubai 		OF_package_to_path(node, name, sizeof(name));
    199  1.1    tsubai 		dc->dc_ih = OF_open(name);
    200  1.1    tsubai 	}
    201  1.3    tsubai 
    202  1.8    tsubai 	/* XXX /chaos/control doesn't have "width", "height", ... */
    203  1.3    tsubai 	width = height = -1;
    204  1.3    tsubai 	if (OF_getprop(node, "width", &width, sizeof(width)) != 4)
    205  1.3    tsubai 		OF_interpret("screen-width", 1, &width);
    206  1.3    tsubai 	if (OF_getprop(node, "height", &height, sizeof(height)) != 4)
    207  1.3    tsubai 		OF_interpret("screen-height", 1, &height);
    208  1.3    tsubai 	if (OF_getprop(node, "linebytes", &linebytes, sizeof(linebytes)) != 4)
    209  1.3    tsubai 		linebytes = width;			/* XXX */
    210  1.3    tsubai 	if (OF_getprop(node, "depth", &depth, sizeof(depth)) != 4)
    211  1.3    tsubai 		depth = 8;				/* XXX */
    212  1.3    tsubai 	if (width == -1 || height == -1)
    213  1.3    tsubai 		return;
    214  1.1    tsubai 
    215  1.1    tsubai 	OF_interpret("frame-buffer-adr", 1, &addr);
    216  1.8    tsubai 	if (addr == 0 || addr == -1)
    217  1.1    tsubai 		return;
    218  1.1    tsubai 	dc->dc_paddr = addr;	/* PA of the frame buffer */
    219  1.1    tsubai 
    220  1.1    tsubai 	/* initialize the raster */
    221  1.1    tsubai 	rap = &dc->dc_raster;
    222  1.1    tsubai 	rap->width = width;
    223  1.1    tsubai 	rap->height = height;
    224  1.1    tsubai 	rap->depth = depth;
    225  1.1    tsubai 	rap->linelongs = linebytes / sizeof(u_int32_t);
    226  1.1    tsubai 	rap->pixels = (u_int32_t *)addr;
    227  1.1    tsubai 
    228  1.1    tsubai 	/* initialize the raster console blitter */
    229  1.1    tsubai 	rcp = &dc->dc_rcons;
    230  1.1    tsubai 	rcp->rc_sp = rap;
    231  1.1    tsubai 	rcp->rc_crow = rcp->rc_ccol = -1;
    232  1.1    tsubai 	rcp->rc_crowp = &rcp->rc_crow;
    233  1.1    tsubai 	rcp->rc_ccolp = &rcp->rc_ccol;
    234  1.1    tsubai 	rcons_init(rcp, 128, 128);
    235  1.1    tsubai 
    236  1.8    tsubai 	/* If screen is smaller than 1024x768, use small font. */
    237  1.8    tsubai 	if ((width < 1024 || height < 768) && copy_rom_font() == 0) {
    238  1.8    tsubai 		rcp->rc_xorigin = 2;
    239  1.8    tsubai 		rcp->rc_yorigin = 4;
    240  1.8    tsubai 
    241  1.8    tsubai 		OF_interpret("#lines", 1, &dc->dc_rcons.rc_maxrow);
    242  1.8    tsubai 		OF_interpret("#columns", 1, &dc->dc_rcons.rc_maxcol);
    243  1.8    tsubai 	}
    244  1.8    tsubai 
    245  1.1    tsubai 	ofb_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
    246  1.1    tsubai 	ofb_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
    247  1.1    tsubai }
    248  1.1    tsubai 
    249  1.1    tsubai int
    250  1.1    tsubai ofb_is_console()
    251  1.1    tsubai {
    252  1.1    tsubai 	int chosen, stdout, node;
    253  1.1    tsubai 	char type[16];
    254  1.1    tsubai 
    255  1.1    tsubai 	chosen = OF_finddevice("/chosen");
    256  1.1    tsubai 	OF_getprop(chosen, "stdout", &stdout, 4);
    257  1.1    tsubai 	node = OF_instance_to_package(stdout);
    258  1.1    tsubai 	OF_getprop(node, "device_type", type, sizeof(type));
    259  1.1    tsubai 	if (strcmp(type, "display") == 0)
    260  1.1    tsubai 		return 1;
    261  1.1    tsubai 	else
    262  1.1    tsubai 		return 0;
    263  1.1    tsubai }
    264  1.1    tsubai 
    265  1.1    tsubai int
    266  1.1    tsubai ofb_ioctl(v, cmd, data, flag, p)
    267  1.1    tsubai 	void *v;
    268  1.1    tsubai 	u_long cmd;
    269  1.1    tsubai 	caddr_t data;
    270  1.1    tsubai 	int flag;
    271  1.1    tsubai 	struct proc *p;
    272  1.1    tsubai {
    273  1.1    tsubai 	struct ofb_softc *sc = v;
    274  1.1    tsubai 	struct ofb_devconfig *dc = sc->sc_dc;
    275  1.1    tsubai 	struct wsdisplay_fbinfo *wdf;
    276  1.1    tsubai 	struct grfinfo *gm;
    277  1.1    tsubai 
    278  1.1    tsubai 	switch (cmd) {
    279  1.1    tsubai 	case WSDISPLAYIO_GTYPE:
    280  1.1    tsubai 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;	/* XXX ? */
    281  1.1    tsubai 		return 0;
    282  1.1    tsubai 
    283  1.1    tsubai 	case WSDISPLAYIO_GINFO:
    284  1.1    tsubai 		wdf = (void *)data;
    285  1.1    tsubai 		wdf->height = sc->sc_dc->dc_raster.height;
    286  1.1    tsubai 		wdf->width = sc->sc_dc->dc_raster.width;
    287  1.1    tsubai 		wdf->depth = sc->sc_dc->dc_raster.depth;
    288  1.1    tsubai 		wdf->cmsize = 256;
    289  1.1    tsubai 		return 0;
    290  1.1    tsubai 
    291  1.1    tsubai 	case WSDISPLAYIO_PUTCMAP:
    292  1.1    tsubai 		return putcmap(sc, data);
    293  1.1    tsubai 
    294  1.1    tsubai 	/* XXX There are no way to know framebuffer pa from a user program. */
    295  1.1    tsubai 	case GRFIOCGINFO:
    296  1.1    tsubai 		gm = (void *)data;
    297  1.1    tsubai 		bzero(gm, sizeof(struct grfinfo));
    298  1.1    tsubai 		gm->gd_fbaddr = (caddr_t)sc->sc_dc->dc_paddr;
    299  1.1    tsubai 		gm->gd_fbrowbytes = sc->sc_dc->dc_linebytes;
    300  1.1    tsubai 		return 0;
    301  1.1    tsubai 	}
    302  1.1    tsubai 	return -1;
    303  1.1    tsubai }
    304  1.1    tsubai 
    305  1.1    tsubai int
    306  1.1    tsubai ofb_mmap(v, offset, prot)
    307  1.1    tsubai 	void *v;
    308  1.1    tsubai 	off_t offset;
    309  1.1    tsubai 	int prot;
    310  1.1    tsubai {
    311  1.1    tsubai 	struct ofb_softc *sc = v;
    312  1.1    tsubai 	struct ofb_devconfig *dc = sc->sc_dc;
    313  1.1    tsubai 
    314  1.4       mrg 	if (offset >= (dc->dc_linebytes * dc->dc_height) || offset < 0)
    315  1.1    tsubai 		return -1;
    316  1.1    tsubai 
    317  1.1    tsubai 	return dc->dc_paddr + offset;
    318  1.1    tsubai }
    319  1.1    tsubai 
    320  1.1    tsubai int
    321  1.1    tsubai ofb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
    322  1.1    tsubai 	void *v;
    323  1.1    tsubai 	const struct wsscreen_descr *type;
    324  1.1    tsubai 	void **cookiep;
    325  1.1    tsubai 	int *curxp, *curyp;
    326  1.1    tsubai 	long *attrp;
    327  1.1    tsubai {
    328  1.1    tsubai 	struct ofb_softc *sc = v;
    329  1.1    tsubai 	long defattr;
    330  1.1    tsubai 
    331  1.1    tsubai 	if (sc->nscreens > 0)
    332  1.1    tsubai 		return (ENOMEM);
    333  1.1    tsubai 
    334  1.1    tsubai 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    335  1.1    tsubai 	*curxp = 0;
    336  1.1    tsubai 	*curyp = 0;
    337  1.1    tsubai 	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
    338  1.1    tsubai 	*attrp = defattr;
    339  1.1    tsubai 	sc->nscreens++;
    340  1.1    tsubai 	return 0;
    341  1.1    tsubai }
    342  1.1    tsubai 
    343  1.1    tsubai void
    344  1.1    tsubai ofb_free_screen(v, cookie)
    345  1.1    tsubai 	void *v;
    346  1.1    tsubai 	void *cookie;
    347  1.1    tsubai {
    348  1.1    tsubai 	struct ofb_softc *sc = v;
    349  1.1    tsubai 
    350  1.1    tsubai 	if (sc->sc_dc == &ofb_console_dc)
    351  1.1    tsubai 		panic("ofb_free_screen: console");
    352  1.1    tsubai 
    353  1.1    tsubai 	sc->nscreens--;
    354  1.1    tsubai }
    355  1.1    tsubai 
    356  1.1    tsubai void
    357  1.1    tsubai ofb_show_screen(v, cookie)
    358  1.1    tsubai 	void *v;
    359  1.1    tsubai 	void *cookie;
    360  1.1    tsubai {
    361  1.1    tsubai }
    362  1.1    tsubai 
    363  1.1    tsubai int
    364  1.1    tsubai ofb_cnattach()
    365  1.1    tsubai {
    366  1.1    tsubai 	struct ofb_devconfig *dc = &ofb_console_dc;
    367  1.1    tsubai 	long defattr;
    368  1.8    tsubai 	int crow = 0, i, screenbytes;
    369  1.1    tsubai 	int chosen, stdout, node;
    370  1.1    tsubai 	char cmd[32];
    371  1.1    tsubai 
    372  1.1    tsubai 	chosen = OF_finddevice("/chosen");
    373  1.1    tsubai 	OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
    374  1.1    tsubai 	node = OF_instance_to_package(stdout);
    375  1.1    tsubai 	dc->dc_ih = stdout;
    376  1.1    tsubai 
    377  1.1    tsubai 	ofb_common_init(node, dc);
    378  1.8    tsubai 	screenbytes = dc->dc_height * dc->dc_linebytes;
    379  1.8    tsubai 
    380  1.8    tsubai 	/* Set colormap to black on white. */
    381  1.8    tsubai 	OF_call_method_1("color!", dc->dc_ih, 4, 0, 0, 0, 0xff);
    382  1.8    tsubai 	OF_call_method_1("color!", dc->dc_ih, 4, 255, 255, 255, 0xf0);
    383  1.8    tsubai 	for (i = 0; i < screenbytes; i += sizeof(u_int32_t))
    384  1.8    tsubai 		*(u_int32_t *)(dc->dc_paddr + i) ^= 0xffffffff;
    385  1.8    tsubai 	OF_call_method_1("color!", dc->dc_ih, 4, 255, 255, 255, 0);
    386  1.8    tsubai 
    387  1.1    tsubai 	/* get current cursor position */
    388  1.1    tsubai 	OF_interpret("line#", 1, &crow);
    389  1.1    tsubai 
    390  1.1    tsubai 	/* move (rom monitor) cursor to the lowest line */
    391  1.1    tsubai 	sprintf(cmd, "%x to line#", ofb_stdscreen.nrows - 1);
    392  1.1    tsubai 	OF_interpret(cmd, 0);
    393  1.8    tsubai 
    394  1.8    tsubai 	if (dc->dc_width >= 1024 && dc->dc_height >= 768) {
    395  1.8    tsubai 		for (i = 0; i < screenbytes; i += sizeof(u_int32_t))
    396  1.8    tsubai 			*(u_int32_t *)(dc->dc_paddr + i) = 0;
    397  1.8    tsubai 		crow = 0;
    398  1.8    tsubai 	}
    399  1.8    tsubai 
    400  1.1    tsubai 	rcons_alloc_attr(&dc->dc_rcons, 0, 0, 0, &defattr);
    401  1.8    tsubai 	wsdisplay_cnattach(&ofb_stdscreen, &dc->dc_rcons, 0, crow, defattr);
    402  1.8    tsubai 
    403  1.8    tsubai 	return 0;
    404  1.8    tsubai }
    405  1.8    tsubai 
    406  1.8    tsubai int
    407  1.8    tsubai copy_rom_font()
    408  1.8    tsubai {
    409  1.8    tsubai 	int i, j;
    410  1.8    tsubai 	u_char *romfont;
    411  1.8    tsubai 	int char_width, char_height;
    412  1.8    tsubai 	int chosen, mmu, m, e;
    413  1.8    tsubai 
    414  1.8    tsubai 	extern struct raster_font gallant19;		/* XXX */
    415  1.8    tsubai 
    416  1.8    tsubai 	/* Get ROM FONT address. */
    417  1.8    tsubai 	OF_interpret("font-adr", 1, &romfont);
    418  1.8    tsubai 	if (romfont == NULL)
    419  1.8    tsubai 		return -1;
    420  1.8    tsubai 
    421  1.8    tsubai 	chosen = OF_finddevice("/chosen");
    422  1.8    tsubai 	OF_getprop(chosen, "mmu", &mmu, 4);
    423  1.1    tsubai 
    424  1.8    tsubai 	/*
    425  1.8    tsubai 	 * Convert to physcal address.  We cannot access to Open Firmware's
    426  1.8    tsubai 	 * virtual address space.
    427  1.8    tsubai 	 */
    428  1.8    tsubai 	OF_call_method("translate", mmu, 1, 3, romfont, &romfont, &m, &e);
    429  1.8    tsubai 
    430  1.8    tsubai 	/* Get character size */
    431  1.8    tsubai 	OF_interpret("char-width", 1, &char_width);
    432  1.8    tsubai 	OF_interpret("char-height", 1, &char_height);
    433  1.8    tsubai 
    434  1.8    tsubai 	/* XXX but we cannot use malloc here... */
    435  1.8    tsubai 	gallant19.width = char_width;
    436  1.8    tsubai 	gallant19.height = char_height;
    437  1.8    tsubai 	gallant19.ascent = 0;
    438  1.8    tsubai 
    439  1.8    tsubai 	for (i = 32; i < 128; i++) {
    440  1.8    tsubai 		u_int *p;
    441  1.8    tsubai 
    442  1.8    tsubai 		if (gallant19.chars[i].r == NULL)
    443  1.8    tsubai 			continue;
    444  1.8    tsubai 
    445  1.8    tsubai 		gallant19.chars[i].r->width = char_width;
    446  1.8    tsubai 		gallant19.chars[i].r->height = char_height;
    447  1.8    tsubai 		p = gallant19.chars[i].r->pixels;
    448  1.8    tsubai 
    449  1.8    tsubai 		for (j = 0; j < char_height; j++)
    450  1.8    tsubai 			*p++ = romfont[(i - 32) * char_height + j] << 24;
    451  1.8    tsubai 	}
    452  1.1    tsubai 	return 0;
    453  1.1    tsubai }
    454  1.1    tsubai 
    455  1.1    tsubai int
    456  1.1    tsubai putcmap(sc, cm)
    457  1.1    tsubai 	struct ofb_softc *sc;
    458  1.1    tsubai 	struct wsdisplay_cmap *cm;
    459  1.1    tsubai {
    460  1.1    tsubai 	struct ofb_devconfig *dc = sc->sc_dc;
    461  1.1    tsubai 	int index = cm->index;
    462  1.1    tsubai 	int count = cm->count;
    463  1.7    tsubai 	int i;
    464  1.1    tsubai 	u_char *r, *g, *b;
    465  1.1    tsubai 
    466  1.1    tsubai 	if (cm->index >= 256 || cm->count > 256 ||
    467  1.1    tsubai 	    (cm->index + cm->count) > 256)
    468  1.1    tsubai 		return EINVAL;
    469  1.1    tsubai #if defined(UVM)
    470  1.1    tsubai 	if (!uvm_useracc(cm->red, cm->count, B_READ) ||
    471  1.1    tsubai 	    !uvm_useracc(cm->green, cm->count, B_READ) ||
    472  1.1    tsubai 	    !uvm_useracc(cm->blue, cm->count, B_READ))
    473  1.1    tsubai 		return EFAULT;
    474  1.1    tsubai #else
    475  1.1    tsubai 	if (!useracc(cm->red, cm->count, B_READ) ||
    476  1.1    tsubai 	    !useracc(cm->green, cm->count, B_READ) ||
    477  1.1    tsubai 	    !useracc(cm->blue, cm->count, B_READ))
    478  1.1    tsubai 		return EFAULT;
    479  1.1    tsubai #endif
    480  1.1    tsubai 	copyin(cm->red,   &sc->sc_cmap_red[index],   count);
    481  1.1    tsubai 	copyin(cm->green, &sc->sc_cmap_green[index], count);
    482  1.1    tsubai 	copyin(cm->blue,  &sc->sc_cmap_blue[index],  count);
    483  1.1    tsubai 
    484  1.1    tsubai 	r = &sc->sc_cmap_red[index];
    485  1.1    tsubai 	g = &sc->sc_cmap_green[index];
    486  1.1    tsubai 	b = &sc->sc_cmap_blue[index];
    487  1.1    tsubai 
    488  1.1    tsubai 	for (i = 0; i < count; i++) {
    489  1.1    tsubai 		OF_call_method_1("color!", dc->dc_ih, 4, *r, *g, *b, index);
    490  1.1    tsubai 		r++, g++, b++, index++;
    491  1.1    tsubai 	}
    492  1.1    tsubai 
    493  1.1    tsubai 	return 0;
    494  1.1    tsubai }
    495