Module Name: src
Committed By: mbalmer
Date: Sat Jul 25 16:20:11 UTC 2009
Modified Files:
src/etc: Makefile
src/etc/defaults: rc.conf
src/etc/mtree: special
src/etc/rc.d: Makefile
src/share/man/man4: gpio.4 gpioow.4
src/share/man/man5: Makefile rc.conf.5
src/share/man/man9: secmodel_securelevel.9
Added Files:
src/etc: gpio.conf
src/etc/rc.d: gpio
src/share/man/man5: gpio.conf.5
Log Message:
Document recent gpio(4) changes and introduce a new config file for GPIO.
Integrate with the startup scripts in /etc/rc.d. Introduce new variable
"gpio" for /etc/rc.conf.
To generate a diff of this commit:
cvs rdiff -u -r1.369 -r1.370 src/etc/Makefile
cvs rdiff -u -r0 -r1.1 src/etc/gpio.conf
cvs rdiff -u -r1.103 -r1.104 src/etc/defaults/rc.conf
cvs rdiff -u -r1.128 -r1.129 src/etc/mtree/special
cvs rdiff -u -r1.78 -r1.79 src/etc/rc.d/Makefile
cvs rdiff -u -r0 -r1.1 src/etc/rc.d/gpio
cvs rdiff -u -r1.8 -r1.9 src/share/man/man4/gpio.4
cvs rdiff -u -r1.2 -r1.3 src/share/man/man4/gpioow.4
cvs rdiff -u -r1.61 -r1.62 src/share/man/man5/Makefile
cvs rdiff -u -r0 -r1.1 src/share/man/man5/gpio.conf.5
cvs rdiff -u -r1.129 -r1.130 src/share/man/man5/rc.conf.5
cvs rdiff -u -r1.5 -r1.6 src/share/man/man9/secmodel_securelevel.9
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/etc/Makefile
diff -u src/etc/Makefile:1.369 src/etc/Makefile:1.370
--- src/etc/Makefile:1.369 Tue Jul 21 00:48:29 2009
+++ src/etc/Makefile Sat Jul 25 16:20:10 2009
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.369 2009/07/21 00:48:29 mrg Exp $
+# $NetBSD: Makefile,v 1.370 2009/07/25 16:20:10 mbalmer Exp $
# from: @(#)Makefile 8.7 (Berkeley) 5/25/95
# Environment variables without default values:
@@ -90,7 +90,7 @@
UTMPGRP= utmp
BIN1+= bootptab changelist csh.cshrc csh.login \
csh.logout daily daily.conf dm.conf envsys.conf floppytab ftpchroot \
- ftpusers gettytab group hosts hosts.lpd inetd.conf \
+ ftpusers gettytab gpio.conf group hosts hosts.lpd inetd.conf \
locate.conf login.conf mailer.conf man.conf monthly monthly.conf \
mrouted.conf named.conf netconfig networks newsyslog.conf \
nsswitch.conf ntp.conf passwd.conf phones printcap profile protocols \
Index: src/etc/defaults/rc.conf
diff -u src/etc/defaults/rc.conf:1.103 src/etc/defaults/rc.conf:1.104
--- src/etc/defaults/rc.conf:1.103 Tue Apr 28 23:30:34 2009
+++ src/etc/defaults/rc.conf Sat Jul 25 16:20:10 2009
@@ -1,4 +1,4 @@
-# $NetBSD: rc.conf,v 1.103 2009/04/28 23:30:34 roy Exp $
+# $NetBSD: rc.conf,v 1.104 2009/07/25 16:20:10 mbalmer Exp $
#
# /etc/defaults/rc.conf --
# default configuration of /etc/rc.conf
@@ -119,6 +119,7 @@
ldconfig=YES # rebuild a.out ldconfig cache
sysdb=YES # build system databases
rndctl=NO rndctl_flags="" # configure rndctl(8)
+gpio=NO # configure GPIO devices
# cope with other OSes using the real time clock at localtime on this
# machine (by adjusting kern.rtc_offset at boot)
Index: src/etc/mtree/special
diff -u src/etc/mtree/special:1.128 src/etc/mtree/special:1.129
--- src/etc/mtree/special:1.128 Tue Apr 21 16:08:57 2009
+++ src/etc/mtree/special Sat Jul 25 16:20:10 2009
@@ -1,4 +1,4 @@
-# $NetBSD: special,v 1.128 2009/04/21 16:08:57 joerg Exp $
+# $NetBSD: special,v 1.129 2009/07/25 16:20:10 mbalmer Exp $
# @(#)special 8.2 (Berkeley) 1/23/94
#
# This file may be overwritten on upgrades.
@@ -75,6 +75,7 @@
./etc/ftpwelcome type=file mode=0644 optional
./etc/gateways type=file mode=0644 optional
./etc/gettytab type=file mode=0644
+./etc/gpio.conf type=file mode=644
./etc/group type=file mode=0644
./etc/hesiod.conf type=file mode=0644 optional
./etc/hosts type=file mode=0644
@@ -206,6 +207,7 @@
./etc/rc.d/fsck_root type=file mode=0555
./etc/rc.d/ftp_proxy type=file mode=0555
./etc/rc.d/ftpd type=file mode=0555
+./etc/rc.d/gpio type=file mode=0555
./etc/rc.d/hostapd type=file mode=0555
./etc/rc.d/httpd type=file mode=0555
./etc/rc.d/identd type=file mode=0555
Index: src/etc/rc.d/Makefile
diff -u src/etc/rc.d/Makefile:1.78 src/etc/rc.d/Makefile:1.79
--- src/etc/rc.d/Makefile:1.78 Tue Apr 28 23:30:34 2009
+++ src/etc/rc.d/Makefile Sat Jul 25 16:20:10 2009
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.78 2009/04/28 23:30:34 roy Exp $
+# $NetBSD: Makefile,v 1.79 2009/07/25 16:20:10 mbalmer Exp $
.include <bsd.own.mk>
@@ -20,6 +20,7 @@
ccd cgd cleartmp cron \
dhclient dhcpcd dhcpd dhcrelay dmesg downinterfaces envsys \
fsck fsck_root ftp_proxy ftpd \
+ gpio \
hostapd httpd \
identd ifwatchd inetd ipfilter ipfs ipmon ipnat ipsec \
irdaattach iscsi_target isdnd \
Index: src/share/man/man4/gpio.4
diff -u src/share/man/man4/gpio.4:1.8 src/share/man/man4/gpio.4:1.9
--- src/share/man/man4/gpio.4:1.8 Fri Feb 27 03:13:55 2009
+++ src/share/man/man4/gpio.4 Sat Jul 25 16:20:11 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpio.4,v 1.8 2009/02/27 03:13:55 kenh Exp $
+.\" $NetBSD: gpio.4,v 1.9 2009/07/25 16:20:11 mbalmer Exp $
.\" $OpenBSD: gpio.4,v 1.5 2004/11/23 09:39:29 reyk Exp $
.\"
.\" Copyright (c) 2004 Alexander Yurchenko <[email protected]>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd January 9, 2008
+.Dd July 19, 2009
.Dt GPIO 4
.Os
.Sh NAME
@@ -50,6 +50,14 @@
Access from userland is performed through
.Xr ioctl 2
calls on these devices.
+.Pp
+The layout of the GPIO device is defined at a securelevel < 1, i.e. typically
+during system boot, and cannot be changed later.
+GPIO pins can be configured and given a symbolic name and device drivers
+that use GPIO pins can be attached to the
+.Nm
+device at a securelevel < 1.
+All other pins will not be accessible once the runlevel has been raised.
.Sh IOCTL INTERFACE
The following structures and constants are defined in the
.Aq Pa sys/gpio.h
@@ -68,22 +76,27 @@
};
.Ed
.Pp
-.It Dv GPIOPINREAD (struct gpio_pin_op)
+.It Dv GPIOREAD (struct gpio_req)
Returns the input pin value in the
.Fa gpio_pin_op
structure:
.Bd -literal
-struct gpio_pin_op {
- int gp_pin; /* pin number */
- int gp_value; /* value */
+#define GPIOMAXNAME 64
+
+struct gpio_req {
+ char gp_name[GPIOMAXNAME]; /* pin name */
+ int gp_pin; /* pin number */
+ int gp_value; /* value */
};
.Ed
.Pp
The
+.Fa gp_name
+or
.Fa gp_pin
field must be set before calling.
.Pp
-.It Dv GPIOPINWRITE (struct gpio_pin_op)
+.It Dv GPIOWRITE (struct gpio_req)
Writes the output value to the pin.
The value set in the
.Fa gp_value
@@ -96,20 +109,24 @@
.Fa gp_value
field contains the old pin state.
.Pp
-.It Dv GPIOPINTOGGLE (struct gpio_pin_op)
+.It Dv GPIOTOGGLE (struct gpio_req)
Toggles the pin output value, i.e. changes it to the opposite.
.Fa gp_value
field is ignored and on return contains the old pin state.
.Pp
-.It Dv GPIOPINCTL (struct gpio_pin_ctl)
+.It Dv GPIOSET (struct gpio_set)
Changes pin configuration flags with the new ones provided in the
-.Fa gpio_pin_ctl
+.Fa gpio_set
structure:
.Bd -literal
-struct gpio_pin_ctl {
- int gp_pin; /* pin number */
- int gp_caps; /* pin capabilities (read-only) */
- int gp_flags; /* pin configuration flags */
+#define GPIOMAXNAME 64
+
+struct gpio_set {
+ char gp_name[GPIOMAXNAME]; /* pin name */
+ int gp_pin; /* pin number */
+ int gp_caps; /* pin capabilities (ro) */
+ int gp_flags; /* pin configuration flags */
+ char gp_name2[GPIOMAXNAME]; /* new name */
};
.Ed
.Pp
@@ -140,14 +157,42 @@
invert output
.El
.Pp
-Note that the
-.Tn GPIO
-controller
+Note that the GPIO controller
may not support all of these flags.
On return the
.Fa gp_caps
field contains flags that are supported.
If no flags are specified, the pin configuration stays unchanged.
+.Pp
+Only GPIO pins that have been set using
+.Ar GPIOSET
+will be accessible at securelevels greater than 0.
+.Pp
+.It Dv GPIOUNSET (struct gpio_set)
+Unset the specified pin, i.e. clear its name and make it unaccessible
+at securelevels greater than 0.
+.It Dv GPIOATTACH (struct gpio_attach)
+Attach the device described in the
+.Fa gpio_attach
+structure on this gpio device.
+.Bd -literal
+struct gpio_attach {
+ char ga_dvname[16]; /* device name */
+ int ga_offset; /* pin number */
+ u_int32_t ga_mask; /* binary mask */
+};
+.Ed
+.It Dv GPIODETACH (struct gpio_attach)
+Detach a device from this gpio device that was previously attached using the
+.Dv GPIOATTACH
+.Xr ioctl 2 .
+The
+.Fa ga_offset
+and
+.Fa ga_mask
+fields of the
+.Fa gpio_attach
+structure are ignored.
.El
.Sh FILES
.Bl -tag -width "/dev/gpiou" -compact
@@ -177,5 +222,7 @@
.Nx
by
.An Jared D. McNeill Aq [email protected] .
+Runtime device attachment was added by
+.An Marc Balmer Aq [email protected] .
.Sh BUGS
Event capabilities are not supported.
Index: src/share/man/man4/gpioow.4
diff -u src/share/man/man4/gpioow.4:1.2 src/share/man/man4/gpioow.4:1.3
--- src/share/man/man4/gpioow.4:1.2 Sat Apr 8 23:10:40 2006
+++ src/share/man/man4/gpioow.4 Sat Jul 25 16:20:11 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpioow.4,v 1.2 2006/04/08 23:10:40 wiz Exp $
+.\" $NetBSD: gpioow.4,v 1.3 2009/07/25 16:20:11 mbalmer Exp $
.\" $OpenBSD: gpioow.4,v 1.3 2006/03/06 10:24:46 grange Exp $
.\"
.\" Copyright (c) 2006 Alexander Yurchenko <[email protected]>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd March 4, 2006
+.Dd July 19, 2009
.Dt GPIOOW 4
.Os
.Sh NAME
@@ -23,6 +23,7 @@
.Nd 1-Wire bus bit-banging through GPIO pin
.Sh SYNOPSIS
.Cd "gpioow* at gpio? offset 0 mask 0x1"
+.Cd "gpioow* at gpio?"
.Cd "onewire* at gpioow?"
.Sh DESCRIPTION
The
@@ -37,6 +38,18 @@
The
.Ar mask
locator should always be 0x1.
+The
+.Ar offset
+and
+.Ar mask
+can also be specified when
+.Nm
+is attached at runtime using the
+.Dv GPIOATTACH
+.Xr ioctl 2
+on the
+.Xr gpio 4
+device.
.Sh SEE ALSO
.Xr gpio 4 ,
.Xr intro 4 ,
Index: src/share/man/man5/Makefile
diff -u src/share/man/man5/Makefile:1.61 src/share/man/man5/Makefile:1.62
--- src/share/man/man5/Makefile:1.61 Wed Nov 12 12:35:53 2008
+++ src/share/man/man5/Makefile Sat Jul 25 16:20:11 2009
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.61 2008/11/12 12:35:53 ad Exp $
+# $NetBSD: Makefile,v 1.62 2009/07/25 16:20:11 mbalmer Exp $
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# missing: dump.5 plot.5
@@ -6,7 +6,7 @@
MAN= a.out.5 acct.5 ar.5 boot.cfg.5 \
core.5 daily.conf.5 dir.5 disktab.5 elf.5 \
ethers.5 forward.5 \
- fs.5 fstab.5 genassym.cf.5 group.5 hesiod.conf.5 \
+ fs.5 fstab.5 genassym.cf.5 gpio.conf.5 group.5 hesiod.conf.5 \
hosts.5 hosts.equiv.5 ifaliases.5 ifconfig.if.5 intro.5 \
ipsec.conf.5 ld.so.conf.5 link.5 locale.alias.5 \
locate.conf.5 login.conf.5 mixerctl.conf.5 mk.conf.5 monthly.conf.5 \
Index: src/share/man/man5/rc.conf.5
diff -u src/share/man/man5/rc.conf.5:1.129 src/share/man/man5/rc.conf.5:1.130
--- src/share/man/man5/rc.conf.5:1.129 Fri Apr 10 16:18:04 2009
+++ src/share/man/man5/rc.conf.5 Sat Jul 25 16:20:11 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: rc.conf.5,v 1.129 2009/04/10 16:18:04 joerg Exp $
+.\" $NetBSD: rc.conf.5,v 1.130 2009/07/25 16:20:11 mbalmer Exp $
.\"
.\" Copyright (c) 1996 Matthew R. Green
.\" All rights reserved.
@@ -318,6 +318,15 @@
.Xr dmesg 8 .
Passes
.Sy dmesg_flags .
+.It Sy gpio
+.Sq YES
+or
+.Sq NO .
+Configure
+.Xr gpio 4
+devices .
+See
+.Xr gpio.conf 5 .
.It Sy mixerctl
.Sq YES
or
Index: src/share/man/man9/secmodel_securelevel.9
diff -u src/share/man/man9/secmodel_securelevel.9:1.5 src/share/man/man9/secmodel_securelevel.9:1.6
--- src/share/man/man9/secmodel_securelevel.9:1.5 Tue Nov 11 00:10:39 2008
+++ src/share/man/man9/secmodel_securelevel.9 Sat Jul 25 16:20:11 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: secmodel_securelevel.9,v 1.5 2008/11/11 00:10:39 reed Exp $
+.\" $NetBSD: secmodel_securelevel.9,v 1.6 2009/07/25 16:20:11 mbalmer Exp $
.\"
.\" Copyright (c) 2006 Elad Efrat <[email protected]>
.\" Copyright (c) 2000 Hugh Graham
@@ -26,7 +26,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd November 10, 2008
+.Dd July 10, 2009
.Dt SECMODEL_SECURELEVEL 9
.Os
.Sh NAME
@@ -63,6 +63,8 @@
Immutable and append-only file flags may be changed
.It
All devices may be read or written subject to their permissions
+.It
+GPIO pins can be set and device drivers can be attached to them
.El
.It \ 1 Em Secure mode
.Bl -hyphen -compact
@@ -107,6 +109,8 @@
calls are denied
.It
Access to unmanaged memory is denied
+.It
+Only GPIO pins that have been set at securelevel 0 can be accessed
.El
.It \ 2 Em Highly secure mode
.Bl -hyphen -compact
Added files:
Index: src/etc/gpio.conf
diff -u /dev/null src/etc/gpio.conf:1.1
--- /dev/null Sat Jul 25 16:20:11 2009
+++ src/etc/gpio.conf Sat Jul 25 16:20:10 2009
@@ -0,0 +1,11 @@
+# $NetBSD: gpio.conf,v 1.1 2009/07/25 16:20:10 mbalmer Exp $
+#
+# GPIO device and pin configuration
+# The syntax is exactly like the gpioctl(8) command, but without the
+# gpioctl word.
+#
+# E.g. define pin 6 of /dev/gpio0 as output and name it error_led:
+# /dev/gpio0 6 set out error_led
+
+# Empty lines and lines starting with # are ignored.
+
Index: src/etc/rc.d/gpio
diff -u /dev/null src/etc/rc.d/gpio:1.1
--- /dev/null Sat Jul 25 16:20:11 2009
+++ src/etc/rc.d/gpio Sat Jul 25 16:20:10 2009
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# $NetBSD: gpio,v 1.1 2009/07/25 16:20:10 mbalmer Exp $
+#
+
+# PROVIDE: gpio
+# BEFORE: securelevel
+
+$_rc_subr_loaded . /etc/rc.subr
+
+name="gpio"
+rcvar=$name
+start_cmd="gpio_start"
+stop_cmd=":"
+
+gpio_start()
+{
+ if [ -f /etc/gpio.conf ]; then
+ echo "Configuring GPIO."
+ cat /etc/gpio.conf |
+ while read -r args; do
+ args=${args%%#*} # strip comments
+ test -z "$args" && continue
+ /usr/sbin/gpioctl -q $args
+ done
+ fi
+}
+
+load_rc_config $name
+run_rc_command "$1"
Index: src/share/man/man5/gpio.conf.5
diff -u /dev/null src/share/man/man5/gpio.conf.5:1.1
--- /dev/null Sat Jul 25 16:20:11 2009
+++ src/share/man/man5/gpio.conf.5 Sat Jul 25 16:20:11 2009
@@ -0,0 +1,69 @@
+.\" $NetBSD: gpio.conf.5,v 1.1 2009/07/25 16:20:11 mbalmer Exp $
+.\"
+.\" Copyright (c) 2009 Marc Balmer <[email protected]>
+.\" All rights reserved.
+.\"
+.\" 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 ``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 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.
+.\"
+.Dd July 16, 2009
+.Dt GPIO.CONF 5
+.Os
+.Sh NAME
+.Nm gpio.conf
+.Nd GPIO config file
+.Sh DESCRIPTION
+The
+.Nm
+file is read by the
+.Pa gpio
+rc.d script during system start-up and shutdown,
+and is intended for configuring GPIO pins.
+.Ss FILE FORMAT
+Lines starting with a hash
+.Pq Sq #
+and empty lines are ignored.
+All other lines are passed to
+.Xr gpioctl 8 .
+.Sh FILES
+.Bl -tag -width XXetcXgpioXconfXX
+.It Pa /etc/gpio.conf
+The
+.Nm
+configuration file resides in
+.Pa /etc .
+.It Pa /etc/rc.d/gpio
+.Xr rc.d 8
+script that parses
+.Nm .
+.El
+.Sh EXAMPLES
+In this example, if the
+.Pa /etc/gpio.conf
+config file is present pin 1 of
+.Pa /dev/gpio0
+is set as output and named "error_led".
+.Bd -literal -offset indent
+# Program pin 1 of /dev/gpio0 as output and name it "error_led"
+/dev/gpio0 1 set out error_led
+.Ed
+.Sh SEE ALSO
+.Xr gpioctl 8 ,
+.Xr rc 8