wsfontdev.c revision 1.4
1/* $NetBSD: wsfontdev.c,v 1.4 2002/09/06 13:18:43 gehenna 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.4 2002/09/06 13:18:43 gehenna 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
38#include <dev/wsfont/wsfont.h>
39#include <dev/wscons/wsconsio.h> /* XXX */
40
41void wsfontattach(int);
42
43dev_type_open(wsfontopen);
44dev_type_close(wsfontclose);
45dev_type_ioctl(wsfontioctl);
46
47const struct cdevsw wsfont_cdevsw = {
48	wsfontopen, wsfontclose, noread, nowrite, wsfontioctl,
49	nostop, notty, nopoll, nommap,
50};
51
52static int wsfont_isopen;
53
54void
55wsfontattach(int n)
56{
57
58	wsfont_init();
59}
60
61int
62wsfontopen(dev_t dev, int flag, int mode, struct proc *p)
63{
64
65	if (wsfont_isopen)
66		return (EBUSY);
67	wsfont_isopen = 1;
68	return (0);
69}
70
71int
72wsfontclose(dev_t dev, int flag, int mode, struct proc *p)
73{
74
75	wsfont_isopen = 0;
76	return (0);
77}
78
79int
80wsfontioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
81{
82	char nbuf[16];
83	void *buf;
84	int res;
85
86	switch (cmd) {
87	case WSDISPLAYIO_LDFONT:
88#define d ((struct wsdisplay_font *)data)
89		if (d->name) {
90			res = copyinstr(d->name, nbuf, sizeof(nbuf), 0);
91			if (res)
92				return (res);
93			d->name = nbuf;
94		} else
95			d->name = "loaded"; /* ??? */
96		buf = malloc(d->fontheight * d->stride * d->numchars,
97			     M_DEVBUF, M_WAITOK);
98		res = copyin(d->data, buf,
99			     d->fontheight * d->stride * d->numchars);
100		if (res) {
101			free(buf, M_DEVBUF);
102			return (res);
103		}
104		d->data = buf;
105		res = wsfont_add(d, 1);
106		free(buf, M_DEVBUF);
107#undef d
108		return (res);
109	default:
110		return (EINVAL);
111	}
112
113	return (0);
114}
115