Re: Fix level-triggered ACPI GPIO interrupts on amd64

2022-10-03 Thread Matthias Schmidt
Hi Mark,

* Mark Kettenis wrote:
> The diff below adds the hooks to disable and enable GPIO interrupts
> for amdgpio(4), aplgpio(4), bytgpio(4), chvgpio(4), glkgpio(4) and
> pchgpio(4).  This is similar to what I did for qcgpio(4) a few weeks
> ago.  This should fix potential interrupt storms related to
> level-triggered interrupts.
> 
> I can't really test this myself.  But if you have a machine with a
> line like this:
> 
> ihidev0 at iic7 addr 0x2c gpio 18, vendor 0x6cb product 0x8253, SYNA2B43

I have a Tuxedo Infinitbook with the following:

ihidev0 at iic1 addr 0x2c gpio 327, vendor 0x93a product 0x255, UNIW0001

> that contains the string "gpio", please give this a shot and check
> whether your keyboard and touchpad still work with it and report back
> with a fullk dmesg.

I can confirm that both devices still work as expected.  However, the
spdmem device is "gone".  Here's a diff between dmesg before and after

--- dmesg.now   Mon Oct  3 22:22:11 2022
+++ dmesg.beforeMon Oct  3 22:16:16 2022
@@ -1,7 +1,7 @@
-OpenBSD 7.2-current (GENERIC.MP) #9: Mon Oct  3 22:18:38 CEST 2022
-x...@kronos.xosc.net:/usr/src/sys/arch/amd64/compile/GENERIC.MP
+OpenBSD 7.2-current (GENERIC.MP) #759: Sat Oct  1 22:48:03 MDT 2022
+dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
 real mem = 34064420864 (32486MB)
-avail mem = 33014628352 (31485MB)
+avail mem = 33014640640 (31485MB)
 random: good seed from bootblocks
 mpath0 at root
 scsibus0 at mpath0: 256 targets
@@ -32,12 +32,12 @@
 cpu1: 48KB 64b/line 12-way D-cache, 32KB 64b/line 8-way I-cache, 1MB 64b/line 
20-way L2 cache, 12MB 64b/line 12-way L3 cache
 cpu1: smt 0, core 1, package 0
 cpu2 at mainbus0: apid 4 (application processor)
-cpu2: 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz, 4290.12 MHz, 06-8c-01
+cpu2: 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz, 4290.14 MHz, 06-8c-01
 cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,TSC_ADJUST,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,AVX512F,AVX512DQ,RDSEED,ADX,SMAP,AVX512IFMA,CLFLUSHOPT,CLWB,PT,AVX512CD,SHA,AVX512BW,AVX512VL,AVX512VBMI,UMIP,PKU,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES
 cpu2: 48KB 64b/line 12-way D-cache, 32KB 64b/line 8-way I-cache, 1MB 64b/line 
20-way L2 cache, 12MB 64b/line 12-way L3 cache
 cpu2: smt 0, core 2, package 0
 cpu3 at mainbus0: apid 6 (application processor)
-cpu3: 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz, 4290.12 MHz, 06-8c-01
+cpu3: 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz, 4290.11 MHz, 06-8c-01
 cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,TSC_ADJUST,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,AVX512F,AVX512DQ,RDSEED,ADX,SMAP,AVX512IFMA,CLFLUSHOPT,CLWB,PT,AVX512CD,SHA,AVX512BW,AVX512VL,AVX512VBMI,UMIP,PKU,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES
 cpu3: 48KB 64b/line 12-way D-cache, 32KB 64b/line 8-way I-cache, 1MB 64b/line 
20-way L2 cache, 12MB 64b/line 12-way L3 cache
 cpu3: smt 0, core 3, package 0
@@ -80,7 +80,7 @@
 acpibtn1 at acpi0: PWRB
 "PNP0C14" at acpi0 not configured
 "PNP0C14" at acpi0 not configured
-acpiac0 at acpi0: AC unit online
+acpiac0 at acpi0: AC unit offline
 acpibat0 at acpi0: BAT0 model "standard" serial 1 type LiON oem "OEM"
 acpibtn2 at acpi0: LID1
 "PNP0C14" at acpi0 not configured
@@ -174,8 +174,8 @@
 audio0 at azalia0
 ichiic0 at pci0 dev 31 function 4 "Intel 500 Series SMBus" rev 0x20: apic 2 
int 16
 iic2 at ichiic0
-iic2: addr 0x20 01=80 03=52 08=63 09=64 0c=7f 15=30 16=39 19=14 1b=45 1d=08 
1e=02 21=a1 24=ff 25=92 26=5b 2d=6a 2e=01 2f=73 30=df 35=26 36=22 38=f6 3a=80 
3b=80 3c=80 3d=80 3e=80 3f=80 55=c0 58=24 6d=08 6e=1b 6f=70 70=33 72=07 73=15 
74=20 75=06 78=02 79=02 7a=20 7e=e0 88=96 8b=2d 8c=25 8d=45 96=0f 97=01 b0=28 
b1=0c b2=25 b4=42 b5=21 b6=09 b7=42 b8=80 bb=15 bd=bc be=7a bf=40 c0=13 c1=04 
c2=81 c3=0a c4=19 c5=14 c6=05 c7=81 c8=38 ca=03 cc=db cd=32 ce=06 cf=c8 d0=1f 
d1=48 d2=19 d3=48 d4=13 d5=64 d6=09 d7=24 d8=08 d9=39 da=03 db=7a dc=03 dd=7a 
de=e7 df=05 e0=0a e1=a0 e2=0a e3=1a e4=10 e5=a1 e6=30 e8=0a e9=7b ea=a4 ee=1c 
ef=41 f0=14 f1=5d f2=1e f3=78 f5=1e f6=d0 f7=59 f8=64 f9=e2 fa=43 fb=b2 fc=80 
fd=03 fe=af ff=ff words 00=00d5 01=8037 02= 03=5200 04= 05= 06= 
07=
-"eeprom" at iic2 addr 0x52 not configured
+iic2: addr 0x20 01=80 03=52 08=63 09=64 0c=7f 15=30 16=39 19=14 1b=45 1d=08 
1e=02 21=a1 24=ff 25=92 26=5b 2d=6a 2e=01 

Re: [patch] Fix vmd for user VMs

2022-10-03 Thread Matthew Martin
On Sat, Sep 24, 2022 at 08:32:55AM -0400, Dave Voutila wrote:
> 
> Matthew Martin  writes:
> 
> > When vmd/vmctl switched to handling memory in bytes, seems a few places
> > for user VMs were missed. Additionally the first hunk removes the quota
> > hit if the VM will not be created.
> >
> 
> Thanks, I'll take a deeper look this week. I don't use the user quota
> pieces, so I'll need to read through some of this to confirm. If you
> don't hear from me by end of week (October) you're welcome to nudge me.

October nudge

> > diff --git config.c config.c
> > index 374d7de6629..425c901f36a 100644
> > --- config.c
> > +++ config.c
> > @@ -241,8 +241,10 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, 
> > uint32_t peerid, uid_t uid)
> > /* increase the user reference counter and check user limits */
> > if (vm->vm_user != NULL && user_get(vm->vm_user->usr_id.uid) != NULL) {
> > user_inc(vcp, vm->vm_user, 1);
> > -   if (user_checklimit(vm->vm_user, vcp) == -1)
> > +   if (user_checklimit(vm->vm_user, vcp) == -1) {
> > +   user_inc(vcp, vm->vm_user, 0);
> > return (EPERM);
> > +   }
> > }
> >
> > /*
> > diff --git vmd.c vmd.c
> > index 2f3ac1a76f2..a7687d6ce93 100644
> > --- vmd.c
> > +++ vmd.c
> > @@ -1966,7 +1966,7 @@ user_inc(struct vm_create_params *vcp, struct 
> > vmd_user *usr, int inc)
> > usr->usr_maxifs += vcp->vcp_nnics * inc;
> >
> > if (log_getverbose() > 1) {
> > -   (void)fmt_scaled(usr->usr_maxmem * 1024 * 1024, mem);
> > +   (void)fmt_scaled(usr->usr_maxmem, mem);
> > log_debug("%s: %c uid %d ref %d cpu %llu mem %s ifs %llu",
> > __func__, inc == 1 ? '+' : '-',
> > usr->usr_id.uid, usr->usr_refcnt,
> > diff --git vmd.h vmd.h
> > index 9010ad6eb9f..8be7db3d059 100644
> > --- vmd.h
> > +++ vmd.h
> > @@ -67,7 +67,7 @@
> >
> >  /* default user instance limits */
> >  #define VM_DEFAULT_USER_MAXCPU 4
> > -#define VM_DEFAULT_USER_MAXMEM 2048
> > +#define VM_DEFAULT_USER_MAXMEM 2L * 1024 * 1024 * 1024 /* 2 GiB */
> >  #define VM_DEFAULT_USER_MAXIFS 8
> >
> >  /* vmd -> vmctl error codes */



Re: tftpd: add -R for read-only mode/reduced pledges

2022-10-03 Thread Theo de Raadt
David Gwynne  wrote:

> On Sun, Oct 02, 2022 at 06:32:04PM +, Klemens Nanni wrote:
> > diskless(8) just needs tftpd(8) to deliver files, none of the possibly
> > untrusted clients are supposed to ever write anything.
> > 
> > Either way, even when run without -c, a single file writable by _tftpd
> > might be enough for a malicious client to fill up the server's disk.
> > 
> > A proper read-only mode ("stdio rpath dns inet") seems much safer.
> 
> agreed. i'm ok with this diff, but it's worth asking if we can make the
> default read-only and ask people to opt in for write (and create) before
> this specific diff goes in. ie, read-only be default, '-w' to enable
> write mode, '-c' to enable write+create?

we were read-only believers a long time ago, and it seems the world has
caught up to our way of thinking so yes maybe it is time to make it an
option you must specify.



Re: tftpd: add -R for read-only mode/reduced pledges

2022-10-03 Thread David Gwynne
On Sun, Oct 02, 2022 at 06:32:04PM +, Klemens Nanni wrote:
> diskless(8) just needs tftpd(8) to deliver files, none of the possibly
> untrusted clients are supposed to ever write anything.
> 
> Either way, even when run without -c, a single file writable by _tftpd
> might be enough for a malicious client to fill up the server's disk.
> 
> A proper read-only mode ("stdio rpath dns inet") seems much safer.

agreed. i'm ok with this diff, but it's worth asking if we can make the
default read-only and ask people to opt in for write (and create) before
this specific diff goes in. ie, read-only be default, '-w' to enable
write mode, '-c' to enable write+create?

> 
> diskless(8) setup and manual testing runs fine with this, clients get
> proper error responses (just like trying to write /etc/random.seed) and
> the server keeps running without any pledge violations:
> 
>   $ doas ./obj/tfpd -dvR ./_tftpd
> 
>   $ touch file
>   $ echo put file | tftp localhost
>   tftp> Error code 2: Access violation
> 
>   tftpd: 127.0.0.1: write request for 'file'
>   tftpd: 127.0.0.1: nak: Access violation
> 
> 
> tftpd(8) is nicely written such that all file access goes through a
> single validation function, so adding read-only logic seems trivial.
> 
> Did I miss anything?
> Feedback? OK?
> 
> This applies cleanly to -current but conflicts with the -c/cpath diff
> on tech@, so one needs rebasing after the other lands.
> 
> Index: tftpd.8
> ===
> RCS file: /cvs/src/usr.sbin/tftpd/tftpd.8,v
> retrieving revision 1.8
> diff -u -p -r1.8 tftpd.8
> --- tftpd.8   4 Mar 2019 01:06:03 -   1.8
> +++ tftpd.8   1 Oct 2022 17:30:27 -
> @@ -37,7 +37,7 @@
>  .Nd Trivial File Transfer Protocol daemon
>  .Sh SYNOPSIS
>  .Nm tftpd
> -.Op Fl 46cdiv
> +.Op Fl 46cdivR
>  .Op Fl l Ar address
>  .Op Fl p Ar port
>  .Op Fl r Ar socket
> @@ -56,6 +56,8 @@ will allow only publicly readable files 
>  Files may be written only if they already exist and are publicly writable,
>  unless the
>  .Fl c
> +or
> +.Fl R
>  flag is specified
>  .Pq see below .
>  Note that this extends the concept of
> @@ -145,6 +147,8 @@ to
>  on startup;
>  the remote host is not expected to pass the directory
>  as part of the file name to transfer.
> +.Fl R
> +Prevent creating or writing to files.
>  .El
>  .Sh SEE ALSO
>  .Xr tftp 1 ,
> Index: tftpd.c
> ===
> RCS file: /cvs/src/usr.sbin/tftpd/tftpd.c,v
> retrieving revision 1.47
> diff -u -p -r1.47 tftpd.c
> --- tftpd.c   24 Oct 2021 21:24:19 -  1.47
> +++ tftpd.c   2 Oct 2022 18:12:25 -
> @@ -289,6 +289,7 @@ usage(void)
>  }
>  
>  intcancreate = 0;
> +intreadonly = 0;
>  intverbose = 0;
>  intdebug = 0;
>  intiflag = 0;
> @@ -309,7 +310,7 @@ main(int argc, char *argv[])
>   int family = AF_UNSPEC;
>   int devnull = -1;
>  
> - while ((c = getopt(argc, argv, "46cdil:p:r:v")) != -1) {
> + while ((c = getopt(argc, argv, "46cdil:p:r:vR")) != -1) {
>   switch (c) {
>   case '4':
>   family = AF_INET;
> @@ -342,6 +343,9 @@ main(int argc, char *argv[])
>   case 'v':
>   verbose = 1;
>   break;
> + case 'R':
> + readonly = 1;
> + break;
>   default:
>   usage();
>   /* NOTREACHED */
> @@ -351,6 +355,9 @@ main(int argc, char *argv[])
>   argc -= optind;
>   argv += optind;
>  
> + if (cancreate && readonly)
> + errx(1, "options -c and -R are incompatible");
> +
>   if (argc != 1)
>   usage();
>  
> @@ -391,8 +398,13 @@ main(int argc, char *argv[])
>   if (!debug && rdaemon(devnull) == -1)
>   err(1, "unable to daemonize");
>  
> - if (pledge("stdio rpath wpath cpath fattr dns inet", NULL) == -1)
> - lerr(1, "pledge");
> + if (readonly) {
> + if (pledge("stdio rpath dns inet", NULL) == -1)
> + lerr(1, "pledge");
> + } else {
> + if (pledge("stdio rpath wpath cpath fattr dns inet", NULL) == 
> -1)
> + lerr(1, "pledge");
> + }
>  
>   event_init();
>  
> @@ -964,6 +976,9 @@ validate_access(struct tftp_client *clie
>   int  fd, wmode;
>   const char  *errstr, *filename;
>   char rewritten[PATH_MAX];
> +
> + if (readonly && mode != RRQ)
> + return (EACCESS);
>  
>   if (strcmp(requested, SEEDPATH) == 0) {
>   char *buf;
> 



Re: tzset(3): update man page to reality

2022-10-03 Thread Sebastian Benoit
Todd C. Miller(mill...@openbsd.org) on 2022.10.03 13:32:22 -0600:
> On Mon, 03 Oct 2022 13:27:05 -0600, "Todd C. Miller" wrote:
> 
> > We did not document tzname, timezone or daylight and the rules
> > regarding pathnames was not entirely clear.

reads ok to me

> > I think it is worth mentioning that unless your program calls
> > chroot(2), you probably don't need to call tzset(3).

good idea

> > Opinions?
> 
> Now including examples of the pathname format.

ok benno@

>  - todd
> 
> Index: lib/libc/time/tzset.3
> ===
> RCS file: /cvs/src/lib/libc/time/tzset.3,v
> retrieving revision 1.25
> diff -u -p -u -r1.25 tzset.3
> --- lib/libc/time/tzset.3 23 Sep 2022 17:29:22 -  1.25
> +++ lib/libc/time/tzset.3 3 Oct 2022 19:32:05 -
> @@ -8,62 +8,103 @@
>  .Nd initialize time conversion information
>  .Sh SYNOPSIS
>  .In time.h
> +.Vt extern char *tzname[2];
> +.Vt extern long  timezone;
> +.Vt extern long  daylight;
>  .Ft void
>  .Fn tzset "void"
>  .Ft void
>  .Fn tzsetwall "void"
>  .Sh DESCRIPTION
> +The
>  .Fn tzset
> -uses the value of the environment variable
> +function uses the value of the environment variable
>  .Ev TZ
> -to set time conversion information used by
> +to set the time conversion information used by
>  .Xr localtime 3 .
> -If
> -.Ev TZ
> -does not appear in the environment,
> -or if the calling process has changed its user or group ID,
> -the best available approximation to local wall clock time, as specified
> -by the
> -.Xr tzfile 5
> -format file
> -.Pa /etc/localtime ,
> -is used by
> +It also sets the following external variables:
> +.Bl -tag -width "tzname[2]"
> +.It Vt tzname[2]
> +the designations for standard and daylight saving time, see the description 
> of
> +.Ar std No and Ar dst
> +below
> +.It Vt timezone
> +the number of seconds West of UTC
> +.It Vt daylight
> +0 if the time zone has never observed daylight saving time, otherwise
> +non-zero
> +.El
> +.Pp
> +Most programs do not need to call
> +.Fn tzset
> +directly, it will be called automatically as needed by the functions
> +described in
>  .Xr localtime 3 .
> +Privileged processes that use
> +.Xr chroot 2
> +may wish to call
> +.Fn tzset
> +to initialize the time conversion information before changing to
> +a restricted root directory that does not include time conversion
> +data files.
>  .Pp
>  If
>  .Ev TZ
> -appears in the environment but its value is a null string,
> -Coordinated Universal Time (UTC) is used (without leap second
> -correction).
> +does not appear in the environment, or if the calling process has
> +changed its user or group ID, the system time zone file,
> +.Pa /etc/localtime ,
> +is used.
>  .Pp
>  If
>  .Ev TZ
> -appears in the environment and its value begins with a colon,
> -it is used as the pathname of a file
> -from which to read the time conversion information.
> +appears in the environment it may be one of two formats:
> +.Bl -bullet
> +.It
> +the pathname of a
> +.Xr tzfile 5
> +format file from which to read the time conversion information,
> +optionally prefixed with a colon
> +.Pq Ql \&: ,
> +such as
> +.Dq :America/Denver
> +or
> +.Dq Europe/Berlin .
> +.It
> +a string that directly specifies the time conversion information
> +(see below) which may not begin with a colon
> +.Pq Ql \&:
> +.El
>  .Pp
>  If
>  .Ev TZ
>  appears in the environment and its value does not begin with a colon,
>  it is first used as the
> -pathname of a file from which to read the time conversion information,
> +pathname of a
> +.Xr tzfile 5
> +format file from which to read the time conversion information,
>  and, if that file cannot be read, is used directly as a specification of
>  the time conversion information.
> +A value beginning with a colon
> +.Pq Ql \&:
> +is always treated as a pathname.
> +.Pp
> +If
> +.Ev TZ
> +it set to the empty string, Coordinated Universal Time (UTC) is
> +used (without leap second correction).
>  .Pp
>  When
>  .Ev TZ
> -is used as a pathname, it must be relative to the system time
> +is used as a pathname, it must either be a path relative to the system time
>  conversion information directory,
> -.Pa /usr/share/zoneinfo .
> -If
> -.Ev TZ
> -begins with a
> -.Ql /
> -or contains
> +.Pa /usr/share/zoneinfo
> +or an absolute path that begins with
> +.Pa /usr/share/zoneinfo/ .
> +Other absolute paths, or paths that contain
>  .Ql \&../ ,
> -it is ignored and the system local time zone file,
> +will be ignored and the system local time zone file,
>  .Pa /etc/localtime ,
> -is used instead.
> +will be used instead.
>  The file must be in the format specified in
>  .Xr tzfile 5 .
>  .Pp
> @@ -74,7 +115,7 @@ it must have the following syntax (witho
>  .Ar std
>  and
>  .Ar offset ) :
> -.Bd -ragged -offset indent
> +.Bd -offset indent
>  .Ar std
>  .Sm off
>  .Ar offset
> @@ -88,23 +129,23 @@ Where:
>  .It Ar std No and Ar dst
>  Three or more bytes that are the designation for the standard
> 

Re: tzset(3): update man page to reality

2022-10-03 Thread Todd C . Miller
On Mon, 03 Oct 2022 13:27:05 -0600, "Todd C. Miller" wrote:

> We did not document tzname, timezone or daylight and the rules
> regarding pathnames was not entirely clear.
>
> I think it is worth mentioning that unless your program calls
> chroot(2), you probably don't need to call tzset(3).
>
> Opinions?

Now including examples of the pathname format.

 - todd

Index: lib/libc/time/tzset.3
===
RCS file: /cvs/src/lib/libc/time/tzset.3,v
retrieving revision 1.25
diff -u -p -u -r1.25 tzset.3
--- lib/libc/time/tzset.3   23 Sep 2022 17:29:22 -  1.25
+++ lib/libc/time/tzset.3   3 Oct 2022 19:32:05 -
@@ -8,62 +8,103 @@
 .Nd initialize time conversion information
 .Sh SYNOPSIS
 .In time.h
+.Vt extern char *tzname[2];
+.Vt extern long  timezone;
+.Vt extern long  daylight;
 .Ft void
 .Fn tzset "void"
 .Ft void
 .Fn tzsetwall "void"
 .Sh DESCRIPTION
+The
 .Fn tzset
-uses the value of the environment variable
+function uses the value of the environment variable
 .Ev TZ
-to set time conversion information used by
+to set the time conversion information used by
 .Xr localtime 3 .
-If
-.Ev TZ
-does not appear in the environment,
-or if the calling process has changed its user or group ID,
-the best available approximation to local wall clock time, as specified
-by the
-.Xr tzfile 5
-format file
-.Pa /etc/localtime ,
-is used by
+It also sets the following external variables:
+.Bl -tag -width "tzname[2]"
+.It Vt tzname[2]
+the designations for standard and daylight saving time, see the description of
+.Ar std No and Ar dst
+below
+.It Vt timezone
+the number of seconds West of UTC
+.It Vt daylight
+0 if the time zone has never observed daylight saving time, otherwise
+non-zero
+.El
+.Pp
+Most programs do not need to call
+.Fn tzset
+directly, it will be called automatically as needed by the functions
+described in
 .Xr localtime 3 .
+Privileged processes that use
+.Xr chroot 2
+may wish to call
+.Fn tzset
+to initialize the time conversion information before changing to
+a restricted root directory that does not include time conversion
+data files.
 .Pp
 If
 .Ev TZ
-appears in the environment but its value is a null string,
-Coordinated Universal Time (UTC) is used (without leap second
-correction).
+does not appear in the environment, or if the calling process has
+changed its user or group ID, the system time zone file,
+.Pa /etc/localtime ,
+is used.
 .Pp
 If
 .Ev TZ
-appears in the environment and its value begins with a colon,
-it is used as the pathname of a file
-from which to read the time conversion information.
+appears in the environment it may be one of two formats:
+.Bl -bullet
+.It
+the pathname of a
+.Xr tzfile 5
+format file from which to read the time conversion information,
+optionally prefixed with a colon
+.Pq Ql \&: ,
+such as
+.Dq :America/Denver
+or
+.Dq Europe/Berlin .
+.It
+a string that directly specifies the time conversion information
+(see below) which may not begin with a colon
+.Pq Ql \&:
+.El
 .Pp
 If
 .Ev TZ
 appears in the environment and its value does not begin with a colon,
 it is first used as the
-pathname of a file from which to read the time conversion information,
+pathname of a
+.Xr tzfile 5
+format file from which to read the time conversion information,
 and, if that file cannot be read, is used directly as a specification of
 the time conversion information.
+A value beginning with a colon
+.Pq Ql \&:
+is always treated as a pathname.
+.Pp
+If
+.Ev TZ
+it set to the empty string, Coordinated Universal Time (UTC) is
+used (without leap second correction).
 .Pp
 When
 .Ev TZ
-is used as a pathname, it must be relative to the system time
+is used as a pathname, it must either be a path relative to the system time
 conversion information directory,
-.Pa /usr/share/zoneinfo .
-If
-.Ev TZ
-begins with a
-.Ql /
-or contains
+.Pa /usr/share/zoneinfo
+or an absolute path that begins with
+.Pa /usr/share/zoneinfo/ .
+Other absolute paths, or paths that contain
 .Ql \&../ ,
-it is ignored and the system local time zone file,
+will be ignored and the system local time zone file,
 .Pa /etc/localtime ,
-is used instead.
+will be used instead.
 The file must be in the format specified in
 .Xr tzfile 5 .
 .Pp
@@ -74,7 +115,7 @@ it must have the following syntax (witho
 .Ar std
 and
 .Ar offset ) :
-.Bd -ragged -offset indent
+.Bd -offset indent
 .Ar std
 .Sm off
 .Ar offset
@@ -88,23 +129,23 @@ Where:
 .It Ar std No and Ar dst
 Three or more bytes that are the designation for the standard
 .Pq Ar std
-or summer
+or the daylight saving
 .Pq Ar dst
 time zone.
 Only
 .Ar std
 is required; if
 .Ar dst
-is missing, then summer time does not apply in this locale.
+is missing, then daylight saving time does not apply in this locale.
 Upper and lowercase letters are explicitly allowed.
 Any characters except a leading colon
-.Pq Sq \&: ,
+.Pq Ql \&: ,
 digits, comma
-.Pq Sq \&, ,
+.Pq Ql \&, ,
 minus
-.Pq Sq \&- ,

tzset(3): update man page to reality

2022-10-03 Thread Todd C . Miller
We did not document tzname, timezone or daylight and the rules
regarding pathnames was not entirely clear.

I think it is worth mentioning that unless your program calls
chroot(2), you probably don't need to call tzset(3).

Opinions?

 - todd

Index: lib/libc/time/tzset.3
===
RCS file: /cvs/src/lib/libc/time/tzset.3,v
retrieving revision 1.25
diff -u -p -u -r1.25 tzset.3
--- lib/libc/time/tzset.3   23 Sep 2022 17:29:22 -  1.25
+++ lib/libc/time/tzset.3   3 Oct 2022 19:24:02 -
@@ -8,62 +8,99 @@
 .Nd initialize time conversion information
 .Sh SYNOPSIS
 .In time.h
+.Vt extern char *tzname[2];
+.Vt extern long  timezone;
+.Vt extern long  daylight;
 .Ft void
 .Fn tzset "void"
 .Ft void
 .Fn tzsetwall "void"
 .Sh DESCRIPTION
+The
 .Fn tzset
-uses the value of the environment variable
+function uses the value of the environment variable
 .Ev TZ
-to set time conversion information used by
+to set the time conversion information used by
 .Xr localtime 3 .
-If
-.Ev TZ
-does not appear in the environment,
-or if the calling process has changed its user or group ID,
-the best available approximation to local wall clock time, as specified
-by the
-.Xr tzfile 5
-format file
-.Pa /etc/localtime ,
-is used by
+It also sets the following external variables:
+.Bl -tag -width "tzname[2]"
+.It Vt tzname[2]
+the designations for standard and daylight saving time, see the description of
+.Ar std No and Ar dst
+below
+.It Vt timezone
+the number of seconds West of UTC
+.It Vt daylight
+0 if the time zone has never observed daylight saving time, otherwise
+non-zero
+.El
+.Pp
+Most programs do not need to call
+.Fn tzset
+directly, it will be called automatically as needed by the functions
+described in
 .Xr localtime 3 .
+Privileged processes that use
+.Xr chroot 2
+may wish to call
+.Fn tzset
+to initialize the time conversion information before changing to
+a restricted root directory that does not include time conversion
+data files.
 .Pp
 If
 .Ev TZ
-appears in the environment but its value is a null string,
-Coordinated Universal Time (UTC) is used (without leap second
-correction).
+does not appear in the environment, or if the calling process has
+changed its user or group ID, the system time zone file,
+.Pa /etc/localtime ,
+is used.
 .Pp
 If
 .Ev TZ
-appears in the environment and its value begins with a colon,
-it is used as the pathname of a file
-from which to read the time conversion information.
+appears in the environment it may be one of two formats:
+.Bl -bullet
+.It
+the pathname of a
+.Xr tzfile 5
+format file from which to read the time conversion information,
+optionally prefixed with a colon
+.Pq Ql \&:
+.It
+a string containing the time conversion information (see below)
+which may not begin with a colon
+.Pq Ql \&:
+.El
 .Pp
 If
 .Ev TZ
 appears in the environment and its value does not begin with a colon,
 it is first used as the
-pathname of a file from which to read the time conversion information,
+pathname of a
+.Xr tzfile 5
+format file from which to read the time conversion information,
 and, if that file cannot be read, is used directly as a specification of
 the time conversion information.
+A value beginning with a colon
+.Pq Ql \&:
+is always treated as a pathname.
+.Pp
+If
+.Ev TZ
+it set to the empty string, Coordinated Universal Time (UTC) is
+used (without leap second correction).
 .Pp
 When
 .Ev TZ
-is used as a pathname, it must be relative to the system time
+is used as a pathname, it must either be a path relative to the system time
 conversion information directory,
-.Pa /usr/share/zoneinfo .
-If
-.Ev TZ
-begins with a
-.Ql /
-or contains
+.Pa /usr/share/zoneinfo
+or an absolute path that begins with
+.Pa /usr/share/zoneinfo/ .
+Other absolute paths, or paths that contain
 .Ql \&../ ,
-it is ignored and the system local time zone file,
+will be ignored and the system local time zone file,
 .Pa /etc/localtime ,
-is used instead.
+will be used instead.
 The file must be in the format specified in
 .Xr tzfile 5 .
 .Pp
@@ -74,7 +111,7 @@ it must have the following syntax (witho
 .Ar std
 and
 .Ar offset ) :
-.Bd -ragged -offset indent
+.Bd -offset indent
 .Ar std
 .Sm off
 .Ar offset
@@ -88,23 +125,23 @@ Where:
 .It Ar std No and Ar dst
 Three or more bytes that are the designation for the standard
 .Pq Ar std
-or summer
+or the daylight saving
 .Pq Ar dst
 time zone.
 Only
 .Ar std
 is required; if
 .Ar dst
-is missing, then summer time does not apply in this locale.
+is missing, then daylight saving time does not apply in this locale.
 Upper and lowercase letters are explicitly allowed.
 Any characters except a leading colon
-.Pq Sq \&: ,
+.Pq Ql \&: ,
 digits, comma
-.Pq Sq \&, ,
+.Pq Ql \&, ,
 minus
-.Pq Sq \&- ,
+.Pq Ql \&- ,
 plus
-.Pq Sq \&+ ,
+.Pq Ql \&+ ,
 and ASCII NUL are allowed.
 .It Ar offset
 Indicates the value one must add to the local time to arrive at
@@ -131,7 +168,7 @@ If no
 .Ar 

Fix level-triggered ACPI GPIO interrupts on amd64

2022-10-03 Thread Mark Kettenis
The diff below adds the hooks to disable and enable GPIO interrupts
for amdgpio(4), aplgpio(4), bytgpio(4), chvgpio(4), glkgpio(4) and
pchgpio(4).  This is similar to what I did for qcgpio(4) a few weeks
ago.  This should fix potential interrupt storms related to
level-triggered interrupts.

I can't really test this myself.  But if you have a machine with a
line like this:

ihidev0 at iic7 addr 0x2c gpio 18, vendor 0x6cb product 0x8253, SYNA2B43
  

that contains the string "gpio", please give this a shot and check
whether your keyboard and touchpad still work with it and report back
with a fullk dmesg.

Thanks,

Mark


Index: dev/acpi/amdgpio.c
===
RCS file: /cvs/src/sys/dev/acpi/amdgpio.c,v
retrieving revision 1.9
diff -u -p -r1.9 amdgpio.c
--- dev/acpi/amdgpio.c  27 Jun 2022 08:00:31 -  1.9
+++ dev/acpi/amdgpio.c  3 Oct 2022 19:10:03 -
@@ -92,6 +92,8 @@ const char *amdgpio_hids[] = {
 intamdgpio_read_pin(void *, int);
 void   amdgpio_write_pin(void *, int, int);
 void   amdgpio_intr_establish(void *, int, int, int (*)(void *), void *);
+void   amdgpio_intr_enable(void *, int);
+void   amdgpio_intr_disable(void *, int);
 intamdgpio_pin_intr(struct amdgpio_softc *, int);
 intamdgpio_intr(void *);
 void   amdgpio_save_pin(struct amdgpio_softc *, int pin);
@@ -163,6 +165,8 @@ amdgpio_attach(struct device *parent, st
sc->sc_gpio.read_pin = amdgpio_read_pin;
sc->sc_gpio.write_pin = amdgpio_write_pin;
sc->sc_gpio.intr_establish = amdgpio_intr_establish;
+   sc->sc_gpio.intr_enable = amdgpio_intr_enable;
+   sc->sc_gpio.intr_disable = amdgpio_intr_disable;
sc->sc_node->gpio = >sc_gpio;
 
printf(", %d pins\n", sc->sc_npins);
@@ -275,6 +279,32 @@ amdgpio_intr_establish(void *cookie, int
if ((flags & LR_GPIO_POLARITY) == LR_GPIO_ACTBOTH)
reg |= AMDGPIO_CONF_ACTBOTH;
reg |= (AMDGPIO_CONF_INT_MASK | AMDGPIO_CONF_INT_EN);
+   bus_space_write_4(sc->sc_memt, sc->sc_memh, pin * 4, reg);
+}
+
+void
+amdgpio_intr_enable(void *cookie, int pin)
+{
+   struct amdgpio_softc *sc = cookie;
+   uint32_t reg;
+
+   KASSERT(pin >= 0 && pin != 63 && pin < sc->sc_npins);
+
+   reg = bus_space_read_4(sc->sc_memt, sc->sc_memh, pin * 4);
+   reg |= (AMDGPIO_CONF_INT_MASK | AMDGPIO_CONF_INT_EN);
+   bus_space_write_4(sc->sc_memt, sc->sc_memh, pin * 4, reg);
+}
+
+void
+amdgpio_intr_disable(void *cookie, int pin)
+{
+   struct amdgpio_softc *sc = cookie;
+   uint32_t reg;
+
+   KASSERT(pin >= 0 && pin != 63 && pin < sc->sc_npins);
+
+   reg = bus_space_read_4(sc->sc_memt, sc->sc_memh, pin * 4);
+   reg &= ~(AMDGPIO_CONF_INT_MASK | AMDGPIO_CONF_INT_EN);
bus_space_write_4(sc->sc_memt, sc->sc_memh, pin * 4, reg);
 }
 
Index: dev/acpi/aplgpio.c
===
RCS file: /cvs/src/sys/dev/acpi/aplgpio.c,v
retrieving revision 1.5
diff -u -p -r1.5 aplgpio.c
--- dev/acpi/aplgpio.c  6 Apr 2022 18:59:27 -   1.5
+++ dev/acpi/aplgpio.c  3 Oct 2022 19:10:03 -
@@ -76,6 +76,8 @@ const char *aplgpio_hids[] = {
 intaplgpio_read_pin(void *, int);
 void   aplgpio_write_pin(void *, int, int);
 void   aplgpio_intr_establish(void *, int, int, int (*)(void *), void *);
+void   aplgpio_intr_enable(void *, int);
+void   aplgpio_intr_disable(void *, int);
 intaplgpio_intr(void *);
 
 int
@@ -150,6 +152,8 @@ aplgpio_attach(struct device *parent, st
sc->sc_gpio.read_pin = aplgpio_read_pin;
sc->sc_gpio.write_pin = aplgpio_write_pin;
sc->sc_gpio.intr_establish = aplgpio_intr_establish;
+   sc->sc_gpio.intr_enable = aplgpio_intr_enable;
+   sc->sc_gpio.intr_disable = aplgpio_intr_disable;
sc->sc_node->gpio = >sc_gpio;
 
/* Mask and clear all interrupts. */
@@ -227,6 +231,36 @@ aplgpio_intr_establish(void *cookie, int
reg = bus_space_read_4(sc->sc_memt, sc->sc_memh,
APLGPIO_IRQ_EN + (pin / 32) * 4);
reg |= (1 << (pin % 32));
+   bus_space_write_4(sc->sc_memt, sc->sc_memh,
+   APLGPIO_IRQ_EN + (pin / 32) * 4, reg);
+}
+
+void
+aplgpio_intr_enable(void *cookie, int pin)
+{
+   struct aplgpio_softc *sc = cookie;
+   uint32_t reg;
+
+   KASSERT(pin >= 0 && pin < sc->sc_npins);
+
+   reg = bus_space_read_4(sc->sc_memt, sc->sc_memh,
+   APLGPIO_IRQ_EN + (pin / 32) * 4);
+   reg |= (1 << (pin % 32));
+   bus_space_write_4(sc->sc_memt, sc->sc_memh,
+   APLGPIO_IRQ_EN + (pin / 32) * 4, reg);
+}
+
+void
+aplgpio_intr_disable(void *cookie, int pin)
+{
+   struct aplgpio_softc *sc = cookie;
+   uint32_t reg;
+
+   KASSERT(pin >= 0 && pin < sc->sc_npins);
+
+   reg = bus_space_read_4(sc->sc_memt, sc->sc_memh,
+   APLGPIO_IRQ_EN + (pin / 32) * 4);
+   reg &= ~(1 << (pin % 32));

Re: vnconfig: don't print device when passed as an argument

2022-10-03 Thread Brian Conway
Corrected mandoc(1) style, thanks.

Index: vnconfig.8
===
RCS file: /cvs/src/sbin/vnconfig/vnconfig.8,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 vnconfig.8
--- vnconfig.8  16 Aug 2022 13:59:51 -  1.7
+++ vnconfig.8  3 Oct 2022 16:08:54 -
@@ -83,8 +83,8 @@ with the regular file
 allowing the latter to be accessed as though it were a disk.
 If
 .Ar vnd_dev
-is not specified, an unused one will be allocated and the name printed
-to
+is not specified, an unused one will be allocated.
+The name is printed to
 .Va stdout .
 .Pp
 The options are as follows:
@@ -147,6 +147,7 @@ Configure a CD-ROM or DVD image file as 
 and mount the ISO 9660 file system contained in it:
 .Bd -literal -offset indent
 # vnconfig vnd0 /tmp/diskimage
+vnd0
 # mount -t cd9660 /dev/vnd0c /mnt
 .Ed
 .Pp
@@ -160,6 +161,7 @@ a salt file with 2 rounds:
 # vnconfig -K 2 vnd0 /tmp/cryptimg
 Encryption key:
 Salt file: /tmp/cryptsalt
+vnd0
 # mount /dev/vnd0a /mnt
 .Ed
 .Sh SEE ALSO
Index: vnconfig.c
===
RCS file: /cvs/src/sbin/vnconfig/vnconfig.c,v
retrieving revision 1.11
diff -u -p -u -p -r1.11 vnconfig.c
--- vnconfig.c  1 Sep 2022 01:52:08 -   1.11
+++ vnconfig.c  3 Oct 2022 16:08:54 -
@@ -284,11 +284,12 @@ config(char *file, char *dev, struct dis
struct vnd_ioctl vndio;
char *rdev;
int fd, rv = -1;
-   int unit;
+   int unit, print_dev = 0;
 
if (dev == NULL) {
if (getinfo(NULL, ) == -1)
err(1, "no devices available");
+   print_dev = 1;
asprintf(, "vnd%d", unit);
}
 
@@ -312,7 +313,8 @@ config(char *file, char *dev, struct dis
if (rv)
warn("VNDIOCSET");
else {
-   printf("%s\n", dev);
+   if (print_dev)
+   printf("%s\n", dev);
if (verbose)
fprintf(stderr, "%s: %llu bytes on %s\n", dev,
vndio.vnd_size, file);

Brian

On Mon, Oct 3, 2022, at 10:56 AM, Brian Conway wrote:
> In d52ebfd8e572596739b84b5138ef7c090a3dc442 
> (https://marc.info/?t=16619957111), vnconfig was changed to not 
> print an auto-allocated device on errors, however it now prints it 
> unconditionally, including when passed as an argument. One might 
> consider this superfluous, but it is surely contrary to the manual.
>
> # dd if=/dev/zero of=/tmp/test.img bs=1m count=0 seek=1 
> 0+0 records in
> 0+0 records out
> 0 bytes transferred in 0.000 secs (0 bytes/sec)
> # vnconfig /tmp/test.img
> 
> vnd0
> # vnconfig -u vnd0  
>  
> # vnconfig vnd0 /tmp/test.img   
> vnd0
>
> Two patches are below, one to change the printing to auto-allocation 
> only, and the other to update the manual to reflect the current 
> behavior. I suggest either or neither, but not both. Thanks.
>
> Brian Conway
> Lead Software Engineer, Owner
> RCE Software, LLC
>
> Index: vnconfig.8
> ===
> RCS file: /cvs/src/sbin/vnconfig/vnconfig.8,v
> retrieving revision 1.7
> diff -u -p -u -p -r1.7 vnconfig.8
> --- vnconfig.816 Aug 2022 13:59:51 -  1.7
> +++ vnconfig.83 Oct 2022 15:52:31 -
> @@ -83,7 +83,7 @@ with the regular file
>  allowing the latter to be accessed as though it were a disk.
>  If
>  .Ar vnd_dev
> -is not specified, an unused one will be allocated and the name printed
> +is not specified, an unused one will be allocated. The name is printed
>  to
>  .Va stdout .
>  .Pp
> @@ -147,6 +147,7 @@ Configure a CD-ROM or DVD image file as 
>  and mount the ISO 9660 file system contained in it:
>  .Bd -literal -offset indent
>  # vnconfig vnd0 /tmp/diskimage
> +vnd0
>  # mount -t cd9660 /dev/vnd0c /mnt
>  .Ed
>  .Pp
> @@ -160,6 +161,7 @@ a salt file with 2 rounds:
>  # vnconfig -K 2 vnd0 /tmp/cryptimg
>  Encryption key:
>  Salt file: /tmp/cryptsalt
> +vnd0
>  # mount /dev/vnd0a /mnt
>  .Ed
>  .Sh SEE ALSO
> Index: vnconfig.c
> ===
> RCS file: /cvs/src/sbin/vnconfig/vnconfig.c,v
> retrieving revision 1.11
> diff -u -p -u -p -r1.11 vnconfig.c
> --- vnconfig.c1 Sep 2022 01:52:08 -   1.11
> +++ vnconfig.c3 Oct 2022 15:52:31 -
> @@ -284,11 +284,12 @@ config(char *file, char *dev, struct dis
>   struct vnd_ioctl vndio;
>   char *rdev;
>   int fd, rv = -1;
> - int unit;
> + int unit, print_dev = 0;
> 
>   if (dev == NULL) {
>   if (getinfo(NULL, ) == -1)
>   err(1, "no devices available");
> + print_dev = 1;
>   asprintf(, "vnd%d", 

vnconfig: don't print device when passed as an argument

2022-10-03 Thread Brian Conway
In d52ebfd8e572596739b84b5138ef7c090a3dc442 
(https://marc.info/?t=16619957111), vnconfig was changed to not print an 
auto-allocated device on errors, however it now prints it unconditionally, 
including when passed as an argument. One might consider this superfluous, but 
it is surely contrary to the manual.

# dd if=/dev/zero of=/tmp/test.img bs=1m count=0 seek=1 
0+0 records in
0+0 records out
0 bytes transferred in 0.000 secs (0 bytes/sec)
# vnconfig /tmp/test.img

vnd0
# vnconfig -u vnd0  
 
# vnconfig vnd0 /tmp/test.img   
vnd0

Two patches are below, one to change the printing to auto-allocation only, and 
the other to update the manual to reflect the current behavior. I suggest 
either or neither, but not both. Thanks.

Brian Conway
Lead Software Engineer, Owner
RCE Software, LLC

Index: vnconfig.8
===
RCS file: /cvs/src/sbin/vnconfig/vnconfig.8,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 vnconfig.8
--- vnconfig.8  16 Aug 2022 13:59:51 -  1.7
+++ vnconfig.8  3 Oct 2022 15:52:31 -
@@ -83,7 +83,7 @@ with the regular file
 allowing the latter to be accessed as though it were a disk.
 If
 .Ar vnd_dev
-is not specified, an unused one will be allocated and the name printed
+is not specified, an unused one will be allocated. The name is printed
 to
 .Va stdout .
 .Pp
@@ -147,6 +147,7 @@ Configure a CD-ROM or DVD image file as 
 and mount the ISO 9660 file system contained in it:
 .Bd -literal -offset indent
 # vnconfig vnd0 /tmp/diskimage
+vnd0
 # mount -t cd9660 /dev/vnd0c /mnt
 .Ed
 .Pp
@@ -160,6 +161,7 @@ a salt file with 2 rounds:
 # vnconfig -K 2 vnd0 /tmp/cryptimg
 Encryption key:
 Salt file: /tmp/cryptsalt
+vnd0
 # mount /dev/vnd0a /mnt
 .Ed
 .Sh SEE ALSO
Index: vnconfig.c
===
RCS file: /cvs/src/sbin/vnconfig/vnconfig.c,v
retrieving revision 1.11
diff -u -p -u -p -r1.11 vnconfig.c
--- vnconfig.c  1 Sep 2022 01:52:08 -   1.11
+++ vnconfig.c  3 Oct 2022 15:52:31 -
@@ -284,11 +284,12 @@ config(char *file, char *dev, struct dis
struct vnd_ioctl vndio;
char *rdev;
int fd, rv = -1;
-   int unit;
+   int unit, print_dev = 0;
 
if (dev == NULL) {
if (getinfo(NULL, ) == -1)
err(1, "no devices available");
+   print_dev = 1;
asprintf(, "vnd%d", unit);
}
 
@@ -312,7 +313,8 @@ config(char *file, char *dev, struct dis
if (rv)
warn("VNDIOCSET");
else {
-   printf("%s\n", dev);
+   if (print_dev)
+   printf("%s\n", dev);
if (verbose)
fprintf(stderr, "%s: %llu bytes on %s\n", dev,
vndio.vnd_size, file);



Re: HiFive Unmatched clean poweroff using the power button

2022-10-03 Thread Mark Kettenis
> From: Jeremie Courreges-Anglas 
> Date: Sat, 01 Oct 2022 18:36:35 +0200
> 
> On Thu, Aug 18 2022, Jeremie Courreges-Anglas  wrote:
> > Some time ago I wanted to get a clean poweroff from the power button on
> > my Unmatched, so that I don't get fsck at reboot the morning after
> > someone sleeps in the room where the machine lives.  kettenis kindly
> > provided sfgpio(4) to get interrupts working on dapmic(4) instead of my
> > initial hack that used polling.
> >
> > One issue I struggled with for a bit is that masking irqs also masks the
> > wake-up events, particularly the events we use for dapmic_reset().
> > With the diff below most interrupt events are masked off during runtime,
> > until we're shutting down/rebooting.  Maybe this is too paranoid and
> > I should let more events go through the intr handler, eg for wake-up
> > events that I don't envision yet?  (I would love to get wake on lan
> > support in cad(4) but my attempts led nowhere so far.)
> >
> > Also interesting, the fault register needs to be cleared at boot, else
> > the interrupt will keep triggering after eg a hard button-driven poweroff.
> > We could log the faults found in FAULT_LOG at boot time to know why the
> > machine has stopped.  But I'm more concerned about what to do if we get
> > a fault at runtime (see the XXX).  When I tried to disestablish the
> > interrupt handler with fdt_intr_disestablish(sc->sc_ih) from
> > dapmic_reset(), I got a fault. Maybe something worth investigating.
> 
> The FAULT_LOG register handling seems appropriate after reading entry
> 6.2 in:
> 
>   
> https://www.renesas.com/eu/en/document/apn/shared-irq-line-considerations-pm-059
> 
> I wish I had read this document earlier. :)
> 
> > The code below is based off da9063_datasheet_2v2.pdf.  I don't know of
> > other machines we run on that use this controller, the only entry in
> > dmesglog is matthieu's Unmatched machine.
> >
> > Tests, input and oks welcome.
> 
> In the case where my hifive unmatched lives, I have wired both the
> shutdown and the reset buttons. Yesterday I tried to see whether the
> reset button could be handled as a clean reboot, but looking at the
> hifive unmatched board schematics it seems that the PMIC has no control
> over it (even if tweaking nRES_MODE).  So the diff stands for scrutiny.
> I would like input and maybe oks to get this in. ;)

Finally managed to get this tested.  It works for my chassis as well!

A few nits below.  With those fixed, ok kettenis@

> Index: dev/fdt/dapmic.c
> ===
> RCS file: /cvs/src/sys/dev/fdt/dapmic.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 dapmic.c
> --- dev/fdt/dapmic.c  6 Apr 2022 18:59:28 -   1.2
> +++ dev/fdt/dapmic.c  17 Aug 2022 21:59:57 -
> @@ -19,6 +19,9 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
> +#include 
>  
>  #include 
>  #include 
> @@ -28,11 +31,31 @@
>  
>  #include 
>  
> +#include 
> +
>  extern void (*cpuresetfn)(void);
>  extern void (*powerdownfn)(void);
>  
>  /* Registers */
> +#define FAULT_LOG0x05
>  #define EVENT_A  0x06
> +#define  EVENT_A_EVENTS_D(1 << 7)
> +#define  EVENT_A_EVENTS_C(1 << 6)
> +#define  EVENT_A_EVENTS_B(1 << 5)
> +#define  EVENT_A_E_nONKEY(1 << 0)
> +#define EVENT_B  0x07
> +#define EVENT_C  0x08
> +#define EVENT_D  0x09
> +#define IRQ_MASK_A   0x0a
> +#define  IRQ_MASK_A_M_RESERVED   ((1 << 7) | (1 << 6) | (1 << 5))
> +#define  IRQ_MASK_A_M_SEQ_RDY(1 << 4)
> +#define  IRQ_MASK_A_M_ADC_RDY(1 << 3)
> +#define  IRQ_MASK_A_M_TICK   (1 << 2)
> +#define  IRQ_MASK_A_M_ALARM  (1 << 1)
> +#define  IRQ_MASK_A_M_nONKEY (1 << 0)
> +#define IRQ_MASK_B   0x0b
> +#define IRQ_MASK_C   0x0c
> +#define IRQ_MASK_D   0x0d
>  #define CONTROL_F0x13
>  #define  CONTROL_F_WAKE_UP   (1 << 2)
>  #define  CONTROL_F_SHUTDOWN  (1 << 1)
> @@ -55,11 +78,20 @@ extern void (*powerdownfn)(void);
>  #define ALARM_Y  0x4b
>  #define  ALARM_Y_TICK_ON (1 << 7)
>  
> +#ifdef DAPMIC_DEBUG
> +# define DPRINTF(args) do { printf args; } while (0)
> +#else
> +# define DPRINTF(args) do {} while (0)
> +#endif
> +
>  struct dapmic_softc {
>   struct device sc_dev;
>   i2c_tag_t sc_tag;
>   i2c_addr_t sc_addr;
>  
> + int (*sc_ih)(void *);
> + struct task sc_task;
> +
>   struct todr_chip_handle sc_todr;
>  };
>  
> @@ -80,8 +112,11 @@ int   dapmic_clock_read(struct dapmic_soft
>  int  dapmic_clock_write(struct dapmic_softc *, struct clock_ymdhms *);
>  int  dapmic_gettime(struct todr_chip_handle *, struct timeval *);
>  int  dapmic_settime(struct todr_chip_handle *, struct timeval *);
> +void dapmic_reset_irq_mask(struct dapmic_softc *);
>  void