wsfontdev.c revision 1.17
11.17Schristos/* $NetBSD: wsfontdev.c,v 1.17 2015/08/20 14:40:18 christos Exp $ */ 21.1Sdrochner 31.1Sdrochner/* 41.1Sdrochner * Copyright (c) 2001 51.1Sdrochner * Matthias Drochner. All rights reserved. 61.1Sdrochner * 71.1Sdrochner * Redistribution and use in source and binary forms, with or without 81.1Sdrochner * modification, are permitted provided that the following conditions 91.1Sdrochner * are met: 101.1Sdrochner * 1. Redistributions of source code must retain the above copyright 111.1Sdrochner * notice, this list of conditions, and the following disclaimer. 121.1Sdrochner * 2. Redistributions in binary form must reproduce the above copyright 131.1Sdrochner * notice, this list of conditions and the following disclaimer in the 141.1Sdrochner * documentation and/or other materials provided with the distribution. 151.1Sdrochner * 161.1Sdrochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 171.1Sdrochner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 181.1Sdrochner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191.1Sdrochner * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 201.1Sdrochner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 211.1Sdrochner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 221.1Sdrochner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 231.1Sdrochner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 241.1Sdrochner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251.1Sdrochner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261.1Sdrochner * SUCH DAMAGE. 271.1Sdrochner */ 281.3Slukem 291.3Slukem#include <sys/cdefs.h> 301.17Schristos__KERNEL_RCSID(0, "$NetBSD: wsfontdev.c,v 1.17 2015/08/20 14:40:18 christos Exp $"); 311.1Sdrochner 321.1Sdrochner#include <sys/param.h> 331.1Sdrochner#include <sys/systm.h> 341.1Sdrochner#include <sys/conf.h> 351.1Sdrochner#include <sys/ioctl.h> 361.1Sdrochner#include <sys/malloc.h> 371.6Sjdolecek#include <sys/event.h> 381.1Sdrochner 391.1Sdrochner#include <dev/wsfont/wsfont.h> 401.1Sdrochner#include <dev/wscons/wsconsio.h> /* XXX */ 411.1Sdrochner 421.17Schristos#include "ioconf.h" 431.4Sgehenna 441.1Sdrochnerstatic int wsfont_isopen; 451.1Sdrochner 461.1Sdrochnervoid 471.13Schristoswsfontattach(int n) 481.1Sdrochner{ 491.1Sdrochner 501.1Sdrochner wsfont_init(); 511.1Sdrochner} 521.1Sdrochner 531.9Sthorpejstatic int 541.13Schristoswsfontopen(dev_t dev, int flag, int mode, 551.13Schristos struct lwp *l) 561.1Sdrochner{ 571.1Sdrochner 581.1Sdrochner if (wsfont_isopen) 591.1Sdrochner return (EBUSY); 601.1Sdrochner wsfont_isopen = 1; 611.1Sdrochner return (0); 621.1Sdrochner} 631.1Sdrochner 641.9Sthorpejstatic int 651.13Schristoswsfontclose(dev_t dev, int flag, int mode, 661.13Schristos struct lwp *l) 671.1Sdrochner{ 681.1Sdrochner 691.1Sdrochner wsfont_isopen = 0; 701.1Sdrochner return (0); 711.1Sdrochner} 721.1Sdrochner 731.9Sthorpejstatic int 741.14Schristoswsfontioctl(dev_t dev, u_long cmd, void *data, int flag, 751.13Schristos struct lwp *l) 761.1Sdrochner{ 771.1Sdrochner char nbuf[16]; 781.1Sdrochner void *buf; 791.1Sdrochner int res; 801.1Sdrochner 811.1Sdrochner switch (cmd) { 821.1Sdrochner case WSDISPLAYIO_LDFONT: 831.1Sdrochner#define d ((struct wsdisplay_font *)data) 841.1Sdrochner if (d->name) { 851.1Sdrochner res = copyinstr(d->name, nbuf, sizeof(nbuf), 0); 861.1Sdrochner if (res) 871.1Sdrochner return (res); 881.1Sdrochner d->name = nbuf; 891.1Sdrochner } else 901.1Sdrochner d->name = "loaded"; /* ??? */ 911.1Sdrochner buf = malloc(d->fontheight * d->stride * d->numchars, 921.1Sdrochner M_DEVBUF, M_WAITOK); 931.1Sdrochner res = copyin(d->data, buf, 941.1Sdrochner d->fontheight * d->stride * d->numchars); 951.1Sdrochner if (res) { 961.1Sdrochner free(buf, M_DEVBUF); 971.1Sdrochner return (res); 981.1Sdrochner } 991.1Sdrochner d->data = buf; 1001.1Sdrochner res = wsfont_add(d, 1); 1011.1Sdrochner free(buf, M_DEVBUF); 1021.1Sdrochner#undef d 1031.1Sdrochner return (res); 1041.1Sdrochner default: 1051.1Sdrochner return (EINVAL); 1061.1Sdrochner } 1071.1Sdrochner} 1081.9Sthorpej 1091.9Sthorpejconst struct cdevsw wsfont_cdevsw = { 1101.15Sdholland .d_open = wsfontopen, 1111.15Sdholland .d_close = wsfontclose, 1121.15Sdholland .d_read = noread, 1131.15Sdholland .d_write = nowrite, 1141.15Sdholland .d_ioctl = wsfontioctl, 1151.15Sdholland .d_stop = nostop, 1161.15Sdholland .d_tty = notty, 1171.15Sdholland .d_poll = nopoll, 1181.15Sdholland .d_mmap = nommap, 1191.15Sdholland .d_kqfilter = nokqfilter, 1201.16Sdholland .d_discard = nodiscard, 1211.15Sdholland .d_flag = D_OTHER 1221.9Sthorpej}; 123