xref: /netbsd-src/sys/dev/wsfont/wsfontdev.c (revision 21a3d2f02241c56556f4b2305ef1b8036f268f70)
1 /* $NetBSD: wsfontdev.c,v 1.2 2001/10/13 16:05:42 augustss 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/param.h>
30 #include <sys/systm.h>
31 #include <sys/conf.h>
32 #include <sys/ioctl.h>
33 #include <sys/malloc.h>
34 
35 #include <dev/wsfont/wsfont.h>
36 #include <dev/wscons/wsconsio.h> /* XXX */
37 
38 void wsfontattach(int);
39 cdev_decl(wsfont);
40 
41 static int wsfont_isopen;
42 
43 void
44 wsfontattach(int n)
45 {
46 
47 	wsfont_init();
48 }
49 
50 int
51 wsfontopen(dev_t dev, int flag, int mode, struct proc *p)
52 {
53 
54 	if (wsfont_isopen)
55 		return (EBUSY);
56 	wsfont_isopen = 1;
57 	return (0);
58 }
59 
60 int
61 wsfontclose(dev_t dev, int flag, int mode, struct proc *p)
62 {
63 
64 	wsfont_isopen = 0;
65 	return (0);
66 }
67 
68 int
69 wsfontioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
70 {
71 	char nbuf[16];
72 	void *buf;
73 	int res;
74 
75 	switch (cmd) {
76 	case WSDISPLAYIO_LDFONT:
77 #define d ((struct wsdisplay_font *)data)
78 		if (d->name) {
79 			res = copyinstr(d->name, nbuf, sizeof(nbuf), 0);
80 			if (res)
81 				return (res);
82 			d->name = nbuf;
83 		} else
84 			d->name = "loaded"; /* ??? */
85 		buf = malloc(d->fontheight * d->stride * d->numchars,
86 			     M_DEVBUF, M_WAITOK);
87 		res = copyin(d->data, buf,
88 			     d->fontheight * d->stride * d->numchars);
89 		if (res) {
90 			free(buf, M_DEVBUF);
91 			return (res);
92 		}
93 		d->data = buf;
94 		res = wsfont_add(d, 1);
95 		free(buf, M_DEVBUF);
96 #undef d
97 		return (res);
98 	default:
99 		return (EINVAL);
100 	}
101 
102 	return (0);
103 }
104