Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / wsfont / wsfontdev.c
blob8fd3c10ab3ff339aa1022879d6ec809c4c2452cd
1 /* $NetBSD: wsfontdev.c,v 1.13 2006/11/16 01:33:31 christos Exp $ */
3 /*
4 * Copyright (c) 2001
5 * Matthias Drochner. All rights reserved.
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.
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.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: wsfontdev.c,v 1.13 2006/11/16 01:33:31 christos Exp $");
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>
39 #include <dev/wsfont/wsfont.h>
40 #include <dev/wscons/wsconsio.h> /* XXX */
42 void wsfontattach(int);
44 static int wsfont_isopen;
46 void
47 wsfontattach(int n)
50 wsfont_init();
53 static int
54 wsfontopen(dev_t dev, int flag, int mode,
55 struct lwp *l)
58 if (wsfont_isopen)
59 return (EBUSY);
60 wsfont_isopen = 1;
61 return (0);
64 static int
65 wsfontclose(dev_t dev, int flag, int mode,
66 struct lwp *l)
69 wsfont_isopen = 0;
70 return (0);
73 static int
74 wsfontioctl(dev_t dev, u_long cmd, void *data, int flag,
75 struct lwp *l)
77 char nbuf[16];
78 void *buf;
79 int res;
81 switch (cmd) {
82 case WSDISPLAYIO_LDFONT:
83 #define d ((struct wsdisplay_font *)data)
84 if (d->name) {
85 res = copyinstr(d->name, nbuf, sizeof(nbuf), 0);
86 if (res)
87 return (res);
88 d->name = nbuf;
89 } else
90 d->name = "loaded"; /* ??? */
91 buf = malloc(d->fontheight * d->stride * d->numchars,
92 M_DEVBUF, M_WAITOK);
93 res = copyin(d->data, buf,
94 d->fontheight * d->stride * d->numchars);
95 if (res) {
96 free(buf, M_DEVBUF);
97 return (res);
99 d->data = buf;
100 res = wsfont_add(d, 1);
101 free(buf, M_DEVBUF);
102 #undef d
103 return (res);
104 default:
105 return (EINVAL);
109 const struct cdevsw wsfont_cdevsw = {
110 wsfontopen, wsfontclose, noread, nowrite, wsfontioctl,
111 nostop, notty, nopoll, nommap, nokqfilter, D_OTHER,