wsfontdev.c revision 1.6
1/* $NetBSD: wsfontdev.c,v 1.6 2002/10/23 09:14:10 jdolecek Exp $ */
2
3/*
4 * Copyright (c) 2001
5 * 	Matthias Drochner.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: wsfontdev.c,v 1.6 2002/10/23 09:14:10 jdolecek Exp $");
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/conf.h>
35#include <sys/ioctl.h>
36#include <sys/malloc.h>
37#include <sys/event.h>
38
39#include <dev/wsfont/wsfont.h>
40#include <dev/wscons/wsconsio.h> /* XXX */
41
42void wsfontattach(int);
43
44dev_type_open(wsfontopen);
45dev_type_close(wsfontclose);
46dev_type_ioctl(wsfontioctl);
47
48const struct cdevsw wsfont_cdevsw = {
49	wsfontopen, wsfontclose, noread, nowrite, wsfontioctl,
50	nostop, notty, nopoll, nommap, nokqfilter,
51};
52
53static int wsfont_isopen;
54
55void
56wsfontattach(int n)
57{
58
59	wsfont_init();
60}
61
62int
63wsfontopen(dev_t dev, int flag, int mode, struct proc *p)
64{
65
66	if (wsfont_isopen)
67		return (EBUSY);
68	wsfont_isopen = 1;
69	return (0);
70}
71
72int
73wsfontclose(dev_t dev, int flag, int mode, struct proc *p)
74{
75
76	wsfont_isopen = 0;
77	return (0);
78}
79
80int
81wsfontioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
82{
83	char nbuf[16];
84	void *buf;
85	int res;
86
87	switch (cmd) {
88	case WSDISPLAYIO_LDFONT:
89#define d ((struct wsdisplay_font *)data)
90		if (d->name) {
91			res = copyinstr(d->name, nbuf, sizeof(nbuf), 0);
92			if (res)
93				return (res);
94			d->name = nbuf;
95		} else
96			d->name = "loaded"; /* ??? */
97		buf = malloc(d->fontheight * d->stride * d->numchars,
98			     M_DEVBUF, M_WAITOK);
99		res = copyin(d->data, buf,
100			     d->fontheight * d->stride * d->numchars);
101		if (res) {
102			free(buf, M_DEVBUF);
103			return (res);
104		}
105		d->data = buf;
106		res = wsfont_add(d, 1);
107		free(buf, M_DEVBUF);
108#undef d
109		return (res);
110	default:
111		return (EINVAL);
112	}
113}
114