1 /* $NetBSD: wsfontdev.c,v 1.3 2001/11/13 06:11:50 lukem 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.3 2001/11/13 06:11:50 lukem 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 41 void wsfontattach(int); 42 cdev_decl(wsfont); 43 44 static int wsfont_isopen; 45 46 void 47 wsfontattach(int n) 48 { 49 50 wsfont_init(); 51 } 52 53 int 54 wsfontopen(dev_t dev, int flag, int mode, struct proc *p) 55 { 56 57 if (wsfont_isopen) 58 return (EBUSY); 59 wsfont_isopen = 1; 60 return (0); 61 } 62 63 int 64 wsfontclose(dev_t dev, int flag, int mode, struct proc *p) 65 { 66 67 wsfont_isopen = 0; 68 return (0); 69 } 70 71 int 72 wsfontioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) 73 { 74 char nbuf[16]; 75 void *buf; 76 int res; 77 78 switch (cmd) { 79 case WSDISPLAYIO_LDFONT: 80 #define d ((struct wsdisplay_font *)data) 81 if (d->name) { 82 res = copyinstr(d->name, nbuf, sizeof(nbuf), 0); 83 if (res) 84 return (res); 85 d->name = nbuf; 86 } else 87 d->name = "loaded"; /* ??? */ 88 buf = malloc(d->fontheight * d->stride * d->numchars, 89 M_DEVBUF, M_WAITOK); 90 res = copyin(d->data, buf, 91 d->fontheight * d->stride * d->numchars); 92 if (res) { 93 free(buf, M_DEVBUF); 94 return (res); 95 } 96 d->data = buf; 97 res = wsfont_add(d, 1); 98 free(buf, M_DEVBUF); 99 #undef d 100 return (res); 101 default: 102 return (EINVAL); 103 } 104 105 return (0); 106 } 107