From owner-svn-src-all@freebsd.org Fri Oct 25 16:07:25 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 82F6A1748EA; Fri, 25 Oct 2019 16:07:25 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4708C12wRXz3D8C; Fri, 25 Oct 2019 16:07:25 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 42EC328CCB; Fri, 25 Oct 2019 16:07:25 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9PG7PuB046985; Fri, 25 Oct 2019 16:07:25 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9PG7OR8046983; Fri, 25 Oct 2019 16:07:24 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201910251607.x9PG7OR8046983@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Fri, 25 Oct 2019 16:07:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354079 - head/sys/dev/superio X-SVN-Group: head X-SVN-Commit-Author: avg X-SVN-Commit-Paths: head/sys/dev/superio X-SVN-Commit-Revision: 354079 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Oct 2019 16:07:25 -0000 Author: avg Date: Fri Oct 25 16:07:24 2019 New Revision: 354079 URL: https://svnweb.freebsd.org/changeset/base/354079 Log: superio: add a simple ioctl interface MFC after: 1 week Added: head/sys/dev/superio/superio_io.h (contents, props changed) Modified: head/sys/dev/superio/superio.c Modified: head/sys/dev/superio/superio.c ============================================================================== --- head/sys/dev/superio/superio.c Fri Oct 25 15:46:54 2019 (r354078) +++ head/sys/dev/superio/superio.c Fri Oct 25 16:07:24 2019 (r354079) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "isa_if.h" @@ -84,6 +85,7 @@ struct siosc { struct mtx conf_lock; STAILQ_HEAD(, superio_devinfo) devlist; struct resource* io_res; + struct cdev *chardev; int io_rid; uint16_t io_port; const struct sio_conf_methods *methods; @@ -96,6 +98,14 @@ struct siosc { uint8_t enable_reg; }; +static d_ioctl_t superio_ioctl; + +static struct cdevsw superio_cdevsw = { + .d_version = D_VERSION, + .d_ioctl = superio_ioctl, + .d_name = "superio", +}; + #define NUMPORTS 2 static uint8_t @@ -621,6 +631,12 @@ superio_attach(device_t dev) bus_generic_probe(dev); bus_generic_attach(dev); + + sc->chardev = make_dev(&superio_cdevsw, device_get_unit(dev), + UID_ROOT, GID_WHEEL, 0600, "superio%d", device_get_unit(dev)); + if (sc->chardev == NULL) + device_printf(dev, "failed to create character device\n"); + sc->chardev->si_drv1 = sc; return (0); } @@ -633,6 +649,8 @@ superio_detach(device_t dev) error = bus_generic_detach(dev); if (error != 0) return (error); + if (sc->chardev != NULL) + destroy_dev(sc->chardev); device_delete_children(dev); bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res); mtx_destroy(&sc->conf_lock); @@ -913,6 +931,31 @@ superio_find_dev(device_t superio, superio_dev_type_t return (dinfo->dev); } return (NULL); +} + +static int +superio_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, + struct thread *td) +{ + struct siosc *sc; + struct superiocmd *s; + + sc = dev->si_drv1; + s = (struct superiocmd *)data; + switch (cmd) { + case SUPERIO_CR_READ: + sio_conf_enter(sc); + s->val = sio_ldn_read(sc, s->ldn, s->cr); + sio_conf_exit(sc); + return (0); + case SUPERIO_CR_WRITE: + sio_conf_enter(sc); + sio_ldn_write(sc, s->ldn, s->cr, s->val); + sio_conf_exit(sc); + return (0); + default: + return (ENOTTY); + } } static devclass_t superio_devclass; Added: head/sys/dev/superio/superio_io.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/superio/superio_io.h Fri Oct 25 16:07:24 2019 (r354079) @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 Andriy Gapon + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef SUPERIO_IO_H +#define SUPERIO_IO_H + +#include + +struct superiocmd { + uint8_t ldn; + uint8_t cr; + uint8_t val; +}; + +#define SUPERIO_CR_READ _IOWR('s', 0, struct superiocmd) +#define SUPERIO_CR_WRITE _IOW('s', 1, struct superiocmd) + +#endif /*SUPERIO_IO_H*/