1 | /* $NetBSD: wsfontdev.c,v 1.17 2015/08/20 14:40:18 christos 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.17 2015/08/20 14:40:18 christos 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 | |
42 | #include "ioconf.h" |
43 | |
44 | static int wsfont_isopen; |
45 | |
46 | void |
47 | wsfontattach(int n) |
48 | { |
49 | |
50 | wsfont_init(); |
51 | } |
52 | |
53 | static int |
54 | wsfontopen(dev_t dev, int flag, int mode, |
55 | struct lwp *l) |
56 | { |
57 | |
58 | if (wsfont_isopen) |
59 | return (EBUSY); |
60 | wsfont_isopen = 1; |
61 | return (0); |
62 | } |
63 | |
64 | static int |
65 | wsfontclose(dev_t dev, int flag, int mode, |
66 | struct lwp *l) |
67 | { |
68 | |
69 | wsfont_isopen = 0; |
70 | return (0); |
71 | } |
72 | |
73 | static int |
74 | wsfontioctl(dev_t dev, u_long cmd, void *data, int flag, |
75 | struct lwp *l) |
76 | { |
77 | char nbuf[16]; |
78 | void *buf; |
79 | int res; |
80 | |
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); |
98 | } |
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); |
106 | } |
107 | } |
108 | |
109 | const struct cdevsw wsfont_cdevsw = { |
110 | .d_open = wsfontopen, |
111 | .d_close = wsfontclose, |
112 | .d_read = noread, |
113 | .d_write = nowrite, |
114 | .d_ioctl = wsfontioctl, |
115 | .d_stop = nostop, |
116 | .d_tty = notty, |
117 | .d_poll = nopoll, |
118 | .d_mmap = nommap, |
119 | .d_kqfilter = nokqfilter, |
120 | .d_discard = nodiscard, |
121 | .d_flag = D_OTHER |
122 | }; |
123 | |