2007-03-04 08:59:00 +03:00
|
|
|
/* $NetBSD: wsfontdev.c,v 1.14 2007/03/04 06:02:52 christos Exp $ */
|
2001-09-03 21:05:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2001
|
|
|
|
* Matthias Drochner. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:08:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-03-04 08:59:00 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wsfontdev.c,v 1.14 2007/03/04 06:02:52 christos Exp $");
|
2001-11-13 09:08:32 +03:00
|
|
|
|
2001-09-03 21:05:20 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/malloc.h>
|
2002-10-23 13:10:23 +04:00
|
|
|
#include <sys/event.h>
|
2001-09-03 21:05:20 +04:00
|
|
|
|
|
|
|
#include <dev/wsfont/wsfont.h>
|
|
|
|
#include <dev/wscons/wsconsio.h> /* XXX */
|
|
|
|
|
|
|
|
void wsfontattach(int);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
2001-09-03 21:05:20 +04:00
|
|
|
static int wsfont_isopen;
|
|
|
|
|
|
|
|
void
|
2006-11-16 04:32:37 +03:00
|
|
|
wsfontattach(int n)
|
2001-09-03 21:05:20 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
wsfont_init();
|
|
|
|
}
|
|
|
|
|
2005-06-28 04:44:22 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
wsfontopen(dev_t dev, int flag, int mode,
|
|
|
|
struct lwp *l)
|
2001-09-03 21:05:20 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (wsfont_isopen)
|
|
|
|
return (EBUSY);
|
|
|
|
wsfont_isopen = 1;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-06-28 04:44:22 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
wsfontclose(dev_t dev, int flag, int mode,
|
|
|
|
struct lwp *l)
|
2001-09-03 21:05:20 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
wsfont_isopen = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-06-28 04:44:22 +04:00
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
wsfontioctl(dev_t dev, u_long cmd, void *data, int flag,
|
2006-11-16 04:32:37 +03:00
|
|
|
struct lwp *l)
|
2001-09-03 21:05:20 +04:00
|
|
|
{
|
|
|
|
char nbuf[16];
|
|
|
|
void *buf;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case WSDISPLAYIO_LDFONT:
|
|
|
|
#define d ((struct wsdisplay_font *)data)
|
|
|
|
if (d->name) {
|
|
|
|
res = copyinstr(d->name, nbuf, sizeof(nbuf), 0);
|
|
|
|
if (res)
|
|
|
|
return (res);
|
|
|
|
d->name = nbuf;
|
|
|
|
} else
|
|
|
|
d->name = "loaded"; /* ??? */
|
|
|
|
buf = malloc(d->fontheight * d->stride * d->numchars,
|
|
|
|
M_DEVBUF, M_WAITOK);
|
|
|
|
res = copyin(d->data, buf,
|
|
|
|
d->fontheight * d->stride * d->numchars);
|
|
|
|
if (res) {
|
|
|
|
free(buf, M_DEVBUF);
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
d->data = buf;
|
|
|
|
res = wsfont_add(d, 1);
|
|
|
|
free(buf, M_DEVBUF);
|
|
|
|
#undef d
|
|
|
|
return (res);
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
}
|
2005-06-28 04:44:22 +04:00
|
|
|
|
|
|
|
const struct cdevsw wsfont_cdevsw = {
|
|
|
|
wsfontopen, wsfontclose, noread, nowrite, wsfontioctl,
|
2006-08-29 01:33:16 +04:00
|
|
|
nostop, notty, nopoll, nommap, nokqfilter, D_OTHER,
|
2005-06-28 04:44:22 +04:00
|
|
|
};
|