xref: /netbsd-src/sys/dev/wsfont/wsfontdev.c (revision 27578b9aac214cc7796ead81dcc5427e79d5f2a0)
1 /* $NetBSD: wsfontdev.c,v 1.1 2001/09/03 17:05:20 drochner 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(n)
45 	int n;
46 {
47 
48 	wsfont_init();
49 }
50 
51 int
52 wsfontopen(dev, flag, mode, p)
53 	dev_t dev;
54 	int flag, mode;
55 	struct proc *p;
56 {
57 
58 	if (wsfont_isopen)
59 		return (EBUSY);
60 	wsfont_isopen = 1;
61 	return (0);
62 }
63 
64 int
65 wsfontclose(dev, flag, mode, p)
66 	dev_t dev;
67 	int flag, mode;
68 	struct proc *p;
69 {
70 
71 	wsfont_isopen = 0;
72 	return (0);
73 }
74 
75 int
76 wsfontioctl(dev, cmd, data, flag, p)
77 	dev_t dev;
78 	u_long cmd;
79 	caddr_t data;
80 	int flag;
81 	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 	return (0);
115 }
116