Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Nov 2019 09:49:58 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r354331 - in stable/12: share/man/man4 share/man/man9 sys/amd64/conf sys/conf sys/dev/superio sys/i386/conf sys/modules sys/modules/superio
Message-ID:  <201911040949.xA49nwG7029183@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Mon Nov  4 09:49:58 2019
New Revision: 354331
URL: https://svnweb.freebsd.org/changeset/base/354331

Log:
  MFC r349580,r351740,r353432,r353433,r354079,r354080: add superio driver
  
  The goal of this driver is consolidate information about SuperIO chips
  and to provide for peaceful coexistence of drivers that need to access
  SuperIO configuration registers.
  
  While SuperIO chips can host various functions most of them are
  discoverable and accessible without any knowledge of the SuperIO.
  Examples are: keyboard and mouse controllers, UARTs, floppy disk
  controllers.  SuperIO-s also provide non-standard functions such as
  GPIO, watchdog timers and hardware monitoring.  Such functions do
  require drivers with a knowledge of a specific SuperIO.
  
  At this time the driver supports a number of ITE and Nuvoton (fka
  Winbond) SuperIO chips.
  There is a single driver for all devices.  So, I have not done the usual
  split between the hardware driver and the bus functionality.  Although,
  superio does act as a bus for devices that represent known non-standard
  functions of a SuperIO chip.  The bus provides enumeration of child
  devices based on the hardcoded knowledge of such functions.  The
  knowledge as extracted from datasheets and other drivers.
  As there is a single driver, I have not defined a kobj interface for it.
  So, its interface is currently made of simple functions.
  I think that we can the flexibility (and complications) when we actually
  need it.

Added:
  stable/12/share/man/man4/superio.4
     - copied, changed from r353432, head/share/man/man4/superio.4
  stable/12/share/man/man9/superio.9
     - copied unchanged from r353432, head/share/man/man9/superio.9
  stable/12/sys/dev/superio/
     - copied from r349580, head/sys/dev/superio/
  stable/12/sys/dev/superio/superio_io.h
     - copied, changed from r354079, head/sys/dev/superio/superio_io.h
  stable/12/sys/modules/superio/
     - copied from r349580, head/sys/modules/superio/
Modified:
  stable/12/share/man/man4/Makefile
  stable/12/share/man/man9/Makefile
  stable/12/sys/amd64/conf/NOTES
  stable/12/sys/conf/files.amd64
  stable/12/sys/conf/files.i386
  stable/12/sys/dev/superio/superio.c
  stable/12/sys/dev/superio/superio.h
  stable/12/sys/i386/conf/NOTES
  stable/12/sys/modules/Makefile
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/share/man/man4/Makefile
==============================================================================
--- stable/12/share/man/man4/Makefile	Mon Nov  4 06:35:48 2019	(r354330)
+++ stable/12/share/man/man4/Makefile	Mon Nov  4 09:49:58 2019	(r354331)
@@ -521,6 +521,7 @@ MAN=	aac.4 \
 	stf.4 \
 	stg.4 \
 	stge.4 \
+	${_superio.4} \
 	sym.4 \
 	syncache.4 \
 	syncer.4 \
@@ -830,6 +831,7 @@ _padlock.4=	padlock.4
 _rr232x.4=	rr232x.4
 _speaker.4=	speaker.4
 _spkr.4=	spkr.4
+_superio.4=	superio.4
 _tpm.4=		tpm.4
 _urtw.4=	urtw.4
 _viawd.4=	viawd.4

Copied and modified: stable/12/share/man/man4/superio.4 (from r353432, head/share/man/man4/superio.4)
==============================================================================
--- head/share/man/man4/superio.4	Fri Oct 11 11:13:47 2019	(r353432, copy source)
+++ stable/12/share/man/man4/superio.4	Mon Nov  4 09:49:58 2019	(r354331)
@@ -74,7 +74,7 @@ that can only be accessed or discovered using the cont
 Some of the Super I/O devices have standardized interfaces.
 Such devices either use well-known legacy resources or they are advertised
 via ACPI or both.
-They can be configured either using ISA bus hints or they are auto-aconfigured by
+They can be configured either using ISA bus hints or they are auto-configured by
 .Xr acpi 4 .
 The
 .Nm

Modified: stable/12/share/man/man9/Makefile
==============================================================================
--- stable/12/share/man/man9/Makefile	Mon Nov  4 06:35:48 2019	(r354330)
+++ stable/12/share/man/man9/Makefile	Mon Nov  4 09:49:58 2019	(r354331)
@@ -301,6 +301,7 @@ MAN=	accept_filter.9 \
 	store.9 \
 	style.9 \
 	style.lua.9 \
+	${_superio.9} \
 	swi.9 \
 	sx.9 \
 	syscall_helper_register.9 \
@@ -2295,5 +2296,24 @@ MLINKS+=zone.9 uma.9 \
 	zone.9 uma_zone_set_maxcache.9 \
 	zone.9 uma_zone_set_warning.9 \
 	zone.9 uma_zsecond_create.9
+
+.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
+_superio.9=	superio.9
+MLINKS+=superio.9 superio_devid.9 \
+	superio.9 superio_dev_disable.9 \
+	superio.9 superio_dev_enable.9 \
+	superio.9 superio_dev_enabled.9 \
+	superio.9 superio_find_dev.9 \
+	superio.9 superio_find_dev.9 \
+	superio.9 superio_get_dma.9 \
+	superio.9 superio_get_iobase.9 \
+	superio.9 superio_get_irq.9 \
+	superio.9 superio_get_ldn.9 \
+	superio.9 superio_get_type.9 \
+	superio.9 superio_read.9 \
+	superio.9 superio_revid.9 \
+	superio.9 superio_vendor.9 \
+	superio.9 superio_write.9
+.endif
 
 .include <bsd.prog.mk>

Copied: stable/12/share/man/man9/superio.9 (from r353432, head/share/man/man9/superio.9)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/12/share/man/man9/superio.9	Mon Nov  4 09:49:58 2019	(r354331, copy of r353432, head/share/man/man9/superio.9)
@@ -0,0 +1,189 @@
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+.\"
+.\" Copyright (c) 2019 Andriy Gapon <avg@FreeBSD.org>
+.\"
+.\" 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$
+.\"
+.Dd October 11, 2019
+.Dt SUPERIO 9
+.Os
+.Sh NAME
+.Nm superio ,
+.Nm superio_devid ,
+.Nm superio_dev_disable ,
+.Nm superio_dev_enable ,
+.Nm superio_dev_enabled ,
+.Nm superio_find_dev ,
+.Nm superio_get_dma ,
+.Nm superio_get_iobase ,
+.Nm superio_get_irq ,
+.Nm superio_get_ldn ,
+.Nm superio_get_type ,
+.Nm superio_read ,
+.Nm superio_revid ,
+.Nm superio_vendor ,
+.Nm superio_write
+.Nd Super I/O bus interface
+.Sh SYNOPSIS
+.In sys/bus.h
+.In dev/superio/superio.h
+.Ft uint16_t
+.Fn superio_devid "device_t dev"
+.Ft void
+.Fn superio_dev_disable "device_t dev" "uint8_t mask"
+.Ft void
+.Fn superio_dev_enable "device_t dev" "uint8_t mask"
+.Ft bool
+.Fn superio_dev_enabled "device_t dev" "uint8_t mask"
+.Ft device_t
+.Fn superio_find_dev "device_t dev" "superio_dev_type_t type" "int ldn"
+.Ft uint8_t
+.Fn superio_get_dma "device_t dev"
+.Ft uint16_t
+.Fn superio_get_iobase "device_t dev"
+.Ft uint8_t
+.Fn superio_get_irq "device_t dev"
+.Ft uint8_t
+.Fn superio_get_ldn "device_t dev"
+.Ft superio_dev_type_t
+.Fn superio_get_type "device_t dev"
+.Ft uint8_t
+.Fn superio_read "device_t dev" "uint8_t reg"
+.Ft uint8_t
+.Fn superio_revid "device_t dev"
+.Ft superio_vendor_t
+.Fn superio_vendor "device_t dev"
+.Ft void
+.Fn superio_write "device_t dev" "uint8_t reg" "uint8_t val"
+.Sh DESCRIPTION
+The
+.Nm
+set of functions are used for managing Super I/O devices.
+The functions provide support for
+raw configuration access,
+locating devices,
+device information,
+and
+device configuration.
+.Ss The controller interface
+The
+.Fn superio_vendor
+function is used to get a vendor of the Super I/O controller
+.Fa dev .
+Possible return values are
+.Dv SUPERIO_VENDOR_ITE
+and
+.Dv SUPERIO_VENDOR_NUVOTON .
+.Pp
+The
+.Fn superio_devid
+function is used to get a device ID of the Super I/O controller
+.Fa dev .
+.Pp
+The
+.Fn superio_revid
+function is used to get a revision ID of the Super I/O controller
+.Fa dev .
+.Pp
+The
+.Fn superio_find_dev
+function is used to find a device on the
+.Xr superio 4
+bus, specified by
+.Fa dev ,
+that has the requested type and logical device number.
+Either of those, but not both, can be a wildcard.
+Supported types are
+.Dv SUPERIO_DEV_GPIO ,
+.Dv SUPERIO_DEV_HWM ,
+and
+.Dv SUPERIO_DEV_WDT .
+The wildcard value for
+.Fa type
+is
+.Dv SUPERIO_DEV_NONE .
+The wildcard value for
+.Fa ldn
+is -1.
+.Ss The device interface
+The
+.Fn superio_read
+function is used to read data from the Super I/O configuration register
+of the device
+.Fa dev .
+.Pp
+The
+.Fn superio_write
+function is used to write data to the Super I/O configuration register
+of the device
+.Fa dev .
+.Pp
+The
+.Fn superio_dev_enable ,
+.Fn superio_dev_disable ,
+and
+.Fn superio_dev_enabled
+functions are used to enable, disable, or check status of the device
+.Fa dev .
+The
+.Fa mask
+parameter selects sub-functions of a device that supports them.
+For devices that do not have sub-functions,
+.Fa mask
+should be set to 1.
+.Ss The accessor interface
+The
+.Fn superio_get_dma
+is used to get a DMA channel number configured for the device
+.Fa dev .
+.Pp
+The
+.Fn superio_get_iobase
+is used to get a base I/O port configured for the device
+.Fa dev .
+The device may expose additional or alternative configuration access via
+the I/O ports.
+.Pp
+The
+.Fn superio_get_irq
+is used to get an interrupt number configured for the device
+.Fa dev .
+.Pp
+The
+.Fn superio_get_ldn
+is used to get a Logical Device Number of the device
+.Fa dev .
+.Pp
+The
+.Fn superio_get_type
+is used to get a type of the device
+.Fa dev .
+.Sh SEE ALSO
+.Xr superio 4 ,
+.Xr device 9 ,
+.Xr driver 9
+.Sh AUTHORS
+This manual page was written by
+.An Andriy Gapon Mt avg@FreeBSD.org

Modified: stable/12/sys/amd64/conf/NOTES
==============================================================================
--- stable/12/sys/amd64/conf/NOTES	Mon Nov  4 06:35:48 2019	(r354330)
+++ stable/12/sys/amd64/conf/NOTES	Mon Nov  4 09:49:58 2019	(r354331)
@@ -594,6 +594,11 @@ device		amdtemp
 device		cpuctl
 
 #
+# SuperIO driver.
+#
+device		superio
+
+#
 # System Management Bus (SMB)
 #
 options 	ENABLE_ALART		# Control alarm on Intel intpm driver

Modified: stable/12/sys/conf/files.amd64
==============================================================================
--- stable/12/sys/conf/files.amd64	Mon Nov  4 06:35:48 2019	(r354330)
+++ stable/12/sys/conf/files.amd64	Mon Nov  4 09:49:58 2019	(r354331)
@@ -491,6 +491,7 @@ dev/smartpqi/smartpqi_response.c	optional 	smartpqi
 dev/smartpqi/smartpqi_sis.c     optional 	smartpqi
 dev/smartpqi/smartpqi_tag.c     optional 	smartpqi
 dev/speaker/spkr.c		optional	speaker
+dev/superio/superio.c		optional	superio isa
 dev/syscons/apm/apm_saver.c	optional	apm_saver apm
 dev/syscons/scterm-teken.c	optional	sc
 dev/syscons/scvesactl.c		optional	sc vga vesa

Modified: stable/12/sys/conf/files.i386
==============================================================================
--- stable/12/sys/conf/files.i386	Mon Nov  4 06:35:48 2019	(r354330)
+++ stable/12/sys/conf/files.i386	Mon Nov  4 09:49:58 2019	(r354331)
@@ -318,6 +318,7 @@ dev/sio/sio_pccard.c		optional sio pccard
 dev/sio/sio_pci.c		optional sio pci
 dev/sio/sio_puc.c		optional sio puc
 dev/speaker/spkr.c		optional speaker
+dev/superio/superio.c		optional superio isa
 dev/syscons/apm/apm_saver.c	optional apm_saver apm
 dev/syscons/scterm-teken.c	optional sc
 dev/syscons/scvesactl.c		optional sc vga vesa

Modified: stable/12/sys/dev/superio/superio.c
==============================================================================
--- head/sys/dev/superio/superio.c	Mon Jul  1 17:05:41 2019	(r349580)
+++ stable/12/sys/dev/superio/superio.c	Mon Nov  4 09:49:58 2019	(r354331)
@@ -1,7 +1,8 @@
-/*
- * Copyright (c) 2016 Andriy Gapon
- * All rights reserved.
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
  *
+ * 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:
@@ -11,7 +12,7 @@
  *    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
+ * 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
@@ -22,6 +23,8 @@
  * 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$
  */
 
 #include <sys/cdefs.h>
@@ -47,6 +50,7 @@ __FBSDID("$FreeBSD$");
 #include <isa/isavar.h>
 
 #include <dev/superio/superio.h>
+#include <dev/superio/superio_io.h>
 
 #include "isa_if.h"
 
@@ -81,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;
@@ -93,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
@@ -617,6 +630,13 @@ 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");
+	else
+		sc->chardev->si_drv1 = sc;
 	return (0);
 }
 
@@ -629,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);
@@ -909,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;

Modified: stable/12/sys/dev/superio/superio.h
==============================================================================
--- head/sys/dev/superio/superio.h	Mon Jul  1 17:05:41 2019	(r349580)
+++ stable/12/sys/dev/superio/superio.h	Mon Nov  4 09:49:58 2019	(r354331)
@@ -1,6 +1,8 @@
-/*
- * Copyright (c) 2016 Andriy Gapon
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
  *
+ * 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:
@@ -10,7 +12,7 @@
  *    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
+ * 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

Copied and modified: stable/12/sys/dev/superio/superio_io.h (from r354079, head/sys/dev/superio/superio_io.h)
==============================================================================
--- head/sys/dev/superio/superio_io.h	Fri Oct 25 16:07:24 2019	(r354079, copy source)
+++ stable/12/sys/dev/superio/superio_io.h	Mon Nov  4 09:49:58 2019	(r354331)
@@ -1,4 +1,6 @@
-/*
+ /*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
  * Copyright (c) 2019 Andriy Gapon
  *
  * Redistribution and use in source and binary forms, with or without
@@ -10,7 +12,7 @@
  *    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
+ * 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

Modified: stable/12/sys/i386/conf/NOTES
==============================================================================
--- stable/12/sys/i386/conf/NOTES	Mon Nov  4 06:35:48 2019	(r354330)
+++ stable/12/sys/i386/conf/NOTES	Mon Nov  4 09:49:58 2019	(r354331)
@@ -878,6 +878,11 @@ device		amdtemp
 device		cpuctl
 
 #
+# SuperIO driver.
+#
+device		superio
+
+#
 # System Management Bus (SMB)
 #
 options 	ENABLE_ALART		# Control alarm on Intel intpm driver

Modified: stable/12/sys/modules/Makefile
==============================================================================
--- stable/12/sys/modules/Makefile	Mon Nov  4 06:35:48 2019	(r354330)
+++ stable/12/sys/modules/Makefile	Mon Nov  4 09:49:58 2019	(r354331)
@@ -368,6 +368,7 @@ SUBDIR=	\
 	ste \
 	${_stg} \
 	stge \
+	${_superio} \
 	${_sym} \
 	${_syscons} \
 	sysvipc \
@@ -716,6 +717,7 @@ _rdrand_rng=	rdrand_rng
 .endif
 _s3=		s3
 _sdhci_acpi=	sdhci_acpi
+_superio=	superio
 _tpm=		tpm
 _twa=		twa
 _vesa=		vesa



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201911040949.xA49nwG7029183>