Re: errors in usage.c - libusbhid

2018-07-02 Thread Martin Pieuchot
On 02/07/18(Mon) 23:08, David Bern wrote:
> > Is it necessary to parse these examples?  Or maybe we can live with
> > your strtonum() fix for now.
> I can live with that.
> 
> > I don't know.  So unless somebody else gives us some input I'd suggest
> > we move forward with your safe diff even if it doesn't fix all the
> > cases.
> > 
> > If it fixes your use case it is already an improvement.
> 
> I have attached a strtonum() fix.
> To give a short summary on how it works. 
> In us == -1 cases, I locate the '%'-symbol stored page_contents[j].name
> to calculate length. The length is then used to compare the function
> input "name" with page_contents[j].name.
> 
> If name match, I then use "len" to position "name" to the
> strtonum-function and use the return value to calculate the usage
> number.
> 
> For people who want to test this patch;
> hid_start()
> snprintf(usage, sizeof(usage), "%s:%s",
>hid_usage_page(HID_PAGE(test_val)), 
>hid_usage_in_page(test_val));
> test_val == hid_parse_usage_in_page(usage)
> 
> As mentioned earlier the usage = (16 << 16) | 0xA (16 Unicode) and
> higher will fail, but 0 to 9 succeeds.
> 
> If wanted I can send the code I used to test this.

It would be great if you could turn that into a regression test to put
in /usr/src/regress/lib/libusbhid/nameofyourtest :)

> Index: usage.c
> ===
> RCS file: /cvs/src/lib/libusbhid/usage.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 usage.c
> --- usage.c   8 Oct 2014 04:49:36 -   1.16
> +++ usage.c   2 Jul 2018 19:51:13 -
> @@ -264,9 +264,9 @@ hid_parse_usage_page(const char *name)
>  int
>  hid_parse_usage_in_page(const char *name)
>  {
> - const char *sep;
> + const char *sep, *fmtsep, *errstr, *fmtname;
>   unsigned int l;
> - int k, j;
> + int k, j, us, pu, len;
>  
>   sep = strchr(name, ':');
>   if (sep == NULL)
> @@ -278,9 +278,21 @@ hid_parse_usage_in_page(const char *name
>   return -1;
>   found:
>   sep++;
> - for (j = 0; j < pages[k].pagesize; j++)
> + for (j = 0; j < pages[k].pagesize; j++) {
> + us = pages[k].page_contents[j].usage;
> + if (us == -1) {
> + fmtname = pages[k].page_contents[j].name;
> + fmtsep = strchr(fmtname, '%');
> + len = fmtsep - fmtname;
> + if (fmtsep != NULL && strncmp(sep, fmtname, len) == 0) {
> + pu = strtonum(sep + len, 0x1, 0x, );
> + if (errstr == NULL)
> + return (pages[k].usage << 16) | pu;
> + }
> + }
>   if (strcmp(pages[k].page_contents[j].name, sep) == 0)
>   return (pages[k].usage << 16) |
>   pages[k].page_contents[j].usage;
> + }
>   return -1;
>  }



teach tcpdump about gre-in-udp encapsulation

2018-07-02 Thread David Gwynne
this is the simplest diff i could make that adds gre in udp handling
to tcpdump.

ok?

Index: print-udp.c
===
RCS file: /cvs/src/usr.sbin/tcpdump/print-udp.c,v
retrieving revision 1.40
diff -u -p -r1.40 print-udp.c
--- print-udp.c 22 Dec 2015 21:01:07 -  1.40
+++ print-udp.c 3 Jul 2018 02:48:13 -
@@ -374,6 +374,7 @@ static int udp6_cksum(const struct ip6_h
 #define GTP_U_PORT 2152
 #define GTP_PRIME_PORT 3386
 #define UDPENCAP_PORT  4500/*XXX*/
+#define GRE_PORT   4754
 #define MULTICASTDNS_PORT  5353
 
 #ifdef INET6
@@ -640,6 +641,10 @@ udp_print(const u_char *bp, u_int length
iapp_print((const u_char *)(up + 1), length);
else if (ISPORT(VQP_PORT))
vqp_print((const u_char *)(up + 1), length);
+   else if (ISPORT(GRE_PORT)) {
+   printf(" ");
+   gre_print((const u_char *)(up + 1), length);
+   }
 #ifdef INET6
else if (ISPORT(RIPNG_PORT))
ripng_print((const u_char *)(up + 1), length);



/etc/services lines for gre-in-udp

2018-07-02 Thread David Gwynne
RFC8086 and IANA say that the following ports are defined for gre
in udp encapsulations.

ok?



Re: errors in usage.c - libusbhid

2018-07-02 Thread David Bern
> Is it necessary to parse these examples?  Or maybe we can live with
> your strtonum() fix for now.
I can live with that.

> I don't know.  So unless somebody else gives us some input I'd suggest
> we move forward with your safe diff even if it doesn't fix all the
> cases.
> 
> If it fixes your use case it is already an improvement.

I have attached a strtonum() fix.
To give a short summary on how it works. 
In us == -1 cases, I locate the '%'-symbol stored page_contents[j].name
to calculate length. The length is then used to compare the function
input "name" with page_contents[j].name.

If name match, I then use "len" to position "name" to the
strtonum-function and use the return value to calculate the usage
number.

For people who want to test this patch;
hid_start()
snprintf(usage, sizeof(usage), "%s:%s",
   hid_usage_page(HID_PAGE(test_val)), 
   hid_usage_in_page(test_val));
test_val == hid_parse_usage_in_page(usage)

As mentioned earlier the usage = (16 << 16) | 0xA (16 Unicode) and
higher will fail, but 0 to 9 succeeds.

If wanted I can send the code I used to test this.

Index: usage.c
===
RCS file: /cvs/src/lib/libusbhid/usage.c,v
retrieving revision 1.16
diff -u -p -r1.16 usage.c
--- usage.c 8 Oct 2014 04:49:36 -   1.16
+++ usage.c 2 Jul 2018 19:51:13 -
@@ -264,9 +264,9 @@ hid_parse_usage_page(const char *name)
 int
 hid_parse_usage_in_page(const char *name)
 {
-   const char *sep;
+   const char *sep, *fmtsep, *errstr, *fmtname;
unsigned int l;
-   int k, j;
+   int k, j, us, pu, len;
 
sep = strchr(name, ':');
if (sep == NULL)
@@ -278,9 +278,21 @@ hid_parse_usage_in_page(const char *name
return -1;
  found:
sep++;
-   for (j = 0; j < pages[k].pagesize; j++)
+   for (j = 0; j < pages[k].pagesize; j++) {
+   us = pages[k].page_contents[j].usage;
+   if (us == -1) {
+   fmtname = pages[k].page_contents[j].name;
+   fmtsep = strchr(fmtname, '%');
+   len = fmtsep - fmtname;
+   if (fmtsep != NULL && strncmp(sep, fmtname, len) == 0) {
+   pu = strtonum(sep + len, 0x1, 0x, );
+   if (errstr == NULL)
+   return (pages[k].usage << 16) | pu;
+   }
+   }
if (strcmp(pages[k].page_contents[j].name, sep) == 0)
return (pages[k].usage << 16) |
pages[k].page_contents[j].usage;
+   }
return -1;
 }



Re: add a bunch of logitech webcam ids to usbdevs

2018-07-02 Thread Landry Breuil
On Mon, Jul 02, 2018 at 09:29:04PM +0200, Mark Kettenis wrote:
> > Date: Mon, 2 Jul 2018 21:10:26 +0200
> > From: Landry Breuil 
> > 
> > ok ?
> 
> Why?  How do they show up right now?  We typically only add USB IDs
> for hardware that needs quirks or doesn't have a useful string
> embedded in the hardware.

the C210 & C270 ones are needed for a new quirk i'm working on to fix
uaudio(4) detection. The other ones appear properly, so i can add only
the ones that need a quirk if preferred.

Landry



Re: add a bunch of logitech webcam ids to usbdevs

2018-07-02 Thread Theo Buehler
On Mon, Jul 02, 2018 at 09:29:04PM +0200, Mark Kettenis wrote:
> > Date: Mon, 2 Jul 2018 21:10:26 +0200
> > From: Landry Breuil 
> > 
> > ok ?
> 
> Why?  How do they show up right now?  We typically only add USB IDs
> for hardware that needs quirks or doesn't have a useful string
> embedded in the hardware.

My Logitech C210 camera with built-in mic shows up as:

uvideo0 at uhub0 port 2 configuration 1 interface 0 "Logitech product 0x0825" 
rev 2.00/0.12 addr 2
video0 at uvideo0
uaudio0 at uhub0 port 2 configuration 1 interface 2 "Logitech product 0x0825" 
rev 2.00/0.12 addr 2
uaudio0: audio descriptors make no sense, error=4



Re: add a bunch of logitech webcam ids to usbdevs

2018-07-02 Thread Mark Kettenis
> Date: Mon, 2 Jul 2018 21:10:26 +0200
> From: Landry Breuil 
> 
> ok ?

Why?  How do they show up right now?  We typically only add USB IDs
for hardware that needs quirks or doesn't have a useful string
embedded in the hardware.

> Index: usbdevs
> ===
> RCS file: /cvs/src/sys/dev/usb/usbdevs,v
> retrieving revision 1.686
> diff -u -r1.686 usbdevs
> --- usbdevs   28 Jun 2018 15:02:06 -  1.686
> +++ usbdevs   2 Jul 2018 19:08:08 -
> @@ -2575,8 +2575,12 @@
>  product LOGITECH WEBCAMC200  0x0802  Webcam C200
>  product LOGITECH WEBCAMC500  0x0807  Webcam C500
>  product LOGITECH QUICKCAMPRO 0x0810  QuickCam Pro
> +product LOGITECH WEBCAMC210  0x0819  Webcam C210
>  product LOGITECH WEBCAMC310  0x081b  Webcam C310
> +product LOGITECH WEBCAMC510  0x081d  HD Webcam C510
>  product LOGITECH HDPROC910   0x0821  HD Pro Webcam C910
> +product LOGITECH WEBCAMC270  0x0825  Webcam C270
> +product LOGITECH HDPROC920   0x082d  HD Pro Webcam C920
>  product LOGITECH QUICKCAMEXP 0x0840  QuickCam Express
>  product LOGITECH QUICKCAM0x0850  QuickCam
>  product LOGITECH QUICKCAMNBDLX   0x08a9  QuickCam Notebook Deluxe
> Index: usbdevs.h
> ===
> RCS file: /cvs/src/sys/dev/usb/usbdevs.h,v
> retrieving revision 1.698
> diff -u -r1.698 usbdevs.h
> --- usbdevs.h 28 Jun 2018 15:04:00 -  1.698
> +++ usbdevs.h 2 Jul 2018 19:08:10 -
> @@ -1,4 +1,4 @@
> -/*   $OpenBSD: usbdevs.h,v 1.698 2018/06/28 15:04:00 kevlo Exp $ */
> +/*   $OpenBSD$   */
>  
>  /*
>   * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
> @@ -2582,8 +2582,12 @@
>  #define  USB_PRODUCT_LOGITECH_WEBCAMC200 0x0802  /* Webcam C200 
> */
>  #define  USB_PRODUCT_LOGITECH_WEBCAMC500 0x0807  /* Webcam C500 
> */
>  #define  USB_PRODUCT_LOGITECH_QUICKCAMPRO0x0810  /* 
> QuickCam Pro */
> +#define  USB_PRODUCT_LOGITECH_WEBCAMC210 0x0819  /* Webcam C210 
> */
>  #define  USB_PRODUCT_LOGITECH_WEBCAMC310 0x081b  /* Webcam C310 
> */
> +#define  USB_PRODUCT_LOGITECH_WEBCAMC510 0x081d  /* HD Webcam 
> C510 */
>  #define  USB_PRODUCT_LOGITECH_HDPROC910  0x0821  /* HD Pro 
> Webcam C910 */
> +#define  USB_PRODUCT_LOGITECH_WEBCAMC270 0x0825  /* Webcam C270 
> */
> +#define  USB_PRODUCT_LOGITECH_HDPROC920  0x082d  /* HD Pro 
> Webcam C920 */
>  #define  USB_PRODUCT_LOGITECH_QUICKCAMEXP0x0840  /* 
> QuickCam Express */
>  #define  USB_PRODUCT_LOGITECH_QUICKCAM   0x0850  /* QuickCam */
>  #define  USB_PRODUCT_LOGITECH_QUICKCAMNBDLX  0x08a9  /* 
> QuickCam Notebook Deluxe */
> Index: usbdevs_data.h
> ===
> RCS file: /cvs/src/sys/dev/usb/usbdevs_data.h,v
> retrieving revision 1.692
> diff -u -r1.692 usbdevs_data.h
> --- usbdevs_data.h28 Jun 2018 15:04:00 -  1.692
> +++ usbdevs_data.h2 Jul 2018 19:08:12 -
> @@ -1,4 +1,4 @@
> -/*   $OpenBSD: usbdevs_data.h,v 1.692 2018/06/28 15:04:00 kevlo Exp $
> */
> +/*   $OpenBSD$   */
>  
>  /*
>   * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
> @@ -5714,12 +5714,28 @@
>   "QuickCam Pro",
>   },
>   {
> + USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_WEBCAMC210,
> + "Webcam C210",
> + },
> + {
>   USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_WEBCAMC310,
>   "Webcam C310",
>   },
>   {
> + USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_WEBCAMC510,
> + "HD Webcam C510",
> + },
> + {
>   USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_HDPROC910,
>   "HD Pro Webcam C910",
> + },
> + {
> + USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_WEBCAMC270,
> + "Webcam C270",
> + },
> + {
> + USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_HDPROC920,
> + "HD Pro Webcam C920",
>   },
>   {
>   USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_QUICKCAMEXP,
> 
> 



add a bunch of logitech webcam ids to usbdevs

2018-07-02 Thread Landry Breuil
ok ?

Index: usbdevs
===
RCS file: /cvs/src/sys/dev/usb/usbdevs,v
retrieving revision 1.686
diff -u -r1.686 usbdevs
--- usbdevs 28 Jun 2018 15:02:06 -  1.686
+++ usbdevs 2 Jul 2018 19:08:08 -
@@ -2575,8 +2575,12 @@
 product LOGITECH WEBCAMC2000x0802  Webcam C200
 product LOGITECH WEBCAMC5000x0807  Webcam C500
 product LOGITECH QUICKCAMPRO   0x0810  QuickCam Pro
+product LOGITECH WEBCAMC2100x0819  Webcam C210
 product LOGITECH WEBCAMC3100x081b  Webcam C310
+product LOGITECH WEBCAMC5100x081d  HD Webcam C510
 product LOGITECH HDPROC910 0x0821  HD Pro Webcam C910
+product LOGITECH WEBCAMC2700x0825  Webcam C270
+product LOGITECH HDPROC920 0x082d  HD Pro Webcam C920
 product LOGITECH QUICKCAMEXP   0x0840  QuickCam Express
 product LOGITECH QUICKCAM  0x0850  QuickCam
 product LOGITECH QUICKCAMNBDLX 0x08a9  QuickCam Notebook Deluxe
Index: usbdevs.h
===
RCS file: /cvs/src/sys/dev/usb/usbdevs.h,v
retrieving revision 1.698
diff -u -r1.698 usbdevs.h
--- usbdevs.h   28 Jun 2018 15:04:00 -  1.698
+++ usbdevs.h   2 Jul 2018 19:08:10 -
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdevs.h,v 1.698 2018/06/28 15:04:00 kevlo Exp $ */
+/* $OpenBSD$   */
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
@@ -2582,8 +2582,12 @@
 #defineUSB_PRODUCT_LOGITECH_WEBCAMC200 0x0802  /* Webcam C200 
*/
 #defineUSB_PRODUCT_LOGITECH_WEBCAMC500 0x0807  /* Webcam C500 
*/
 #defineUSB_PRODUCT_LOGITECH_QUICKCAMPRO0x0810  /* 
QuickCam Pro */
+#defineUSB_PRODUCT_LOGITECH_WEBCAMC210 0x0819  /* Webcam C210 
*/
 #defineUSB_PRODUCT_LOGITECH_WEBCAMC310 0x081b  /* Webcam C310 
*/
+#defineUSB_PRODUCT_LOGITECH_WEBCAMC510 0x081d  /* HD Webcam 
C510 */
 #defineUSB_PRODUCT_LOGITECH_HDPROC910  0x0821  /* HD Pro 
Webcam C910 */
+#defineUSB_PRODUCT_LOGITECH_WEBCAMC270 0x0825  /* Webcam C270 
*/
+#defineUSB_PRODUCT_LOGITECH_HDPROC920  0x082d  /* HD Pro 
Webcam C920 */
 #defineUSB_PRODUCT_LOGITECH_QUICKCAMEXP0x0840  /* 
QuickCam Express */
 #defineUSB_PRODUCT_LOGITECH_QUICKCAM   0x0850  /* QuickCam */
 #defineUSB_PRODUCT_LOGITECH_QUICKCAMNBDLX  0x08a9  /* 
QuickCam Notebook Deluxe */
Index: usbdevs_data.h
===
RCS file: /cvs/src/sys/dev/usb/usbdevs_data.h,v
retrieving revision 1.692
diff -u -r1.692 usbdevs_data.h
--- usbdevs_data.h  28 Jun 2018 15:04:00 -  1.692
+++ usbdevs_data.h  2 Jul 2018 19:08:12 -
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdevs_data.h,v 1.692 2018/06/28 15:04:00 kevlo Exp $
*/
+/* $OpenBSD$   */
 
 /*
  * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
@@ -5714,12 +5714,28 @@
"QuickCam Pro",
},
{
+   USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_WEBCAMC210,
+   "Webcam C210",
+   },
+   {
USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_WEBCAMC310,
"Webcam C310",
},
{
+   USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_WEBCAMC510,
+   "HD Webcam C510",
+   },
+   {
USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_HDPROC910,
"HD Pro Webcam C910",
+   },
+   {
+   USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_WEBCAMC270,
+   "Webcam C270",
+   },
+   {
+   USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_HDPROC920,
+   "HD Pro Webcam C920",
},
{
USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_QUICKCAMEXP,



Re: [PATCH] fix typo in if_aue.c

2018-07-02 Thread Rob Pierce
Ok rob@ 

> From: "Kevin Lo" 
> To: "tech" 
> Sent: Monday, July 2, 2018 10:23:39 AM
> Subject: [PATCH] fix typo in if_aue.c

> Hi,

> I've just noticed a little typo in the if_aue.c (s/read/write).
> The diff is below.

> Index: sys/dev/usb/if_aue.c
> ===
> RCS file: /cvs/src/sys/dev/usb/if_aue.c,v
> retrieving revision 1.106
> diff -u -p -u -p -r1.106 if_aue.c
> --- sys/dev/usb/if_aue.c 22 Jan 2017 10:17:39 - 1.106
> +++ sys/dev/usb/if_aue.c 2 Jul 2018 14:19:57 -
> @@ -509,7 +509,7 @@ aue_miibus_writereg(struct device *dev,
> }

> if (i == AUE_TIMEOUT) {
> - printf("%s: MII read timed out\n",
> + printf("%s: MII write timed out\n",
> sc->aue_dev.dv_xname);
> }
> aue_unlock_mii(sc);


Re: [PATCH] mos: nuke unused variable

2018-07-02 Thread Rob Pierce
Ok rob@ 

> From: "Kevin Lo" 
> To: "tech" 
> Sent: Monday, July 2, 2018 10:22:58 AM
> Subject: [PATCH] mos: nuke unused variable

> Ok ?

> Index: sys/dev/usb/if_mos.c
> ===
> RCS file: /cvs/src/sys/dev/usb/if_mos.c,v
> retrieving revision 1.38
> diff -u -p -u -p -r1.38 if_mos.c
> --- sys/dev/usb/if_mos.c 22 Jan 2017 10:17:39 - 1.38
> +++ sys/dev/usb/if_mos.c 2 Jul 2018 14:09:39 -
> @@ -376,15 +376,12 @@ int
> mos_miibus_readreg(struct device *dev, int phy, int reg)
> {
> struct mos_softc *sc = (void *)dev;
> - uWord val;
> int i,res;

> if (usbd_is_dying(sc->mos_udev)) {
> DPRINTF(("mos: dying\n"));
> return (0);
> }
> -
> - USETW(val, 0);

> mos_lock_mii(sc);


v_dirtyblkhd list macros

2018-07-02 Thread Alexander Bluhm
Hi,

Can we use more list macros for v_dirtyblkhd?  ok?

bluhm

Index: kern/spec_vnops.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/spec_vnops.c,v
retrieving revision 1.92
diff -u -p -r1.92 spec_vnops.c
--- kern/spec_vnops.c   2 May 2018 02:24:56 -   1.92
+++ kern/spec_vnops.c   2 Jul 2018 15:32:52 -
@@ -429,8 +429,7 @@ spec_fsync(void *v)
 */
 loop:
s = splbio();
-   for (bp = LIST_FIRST(>v_dirtyblkhd); bp != NULL; bp = nbp) {
-   nbp = LIST_NEXT(bp, b_vnbufs);
+   LIST_FOREACH_SAFE(bp, >v_dirtyblkhd, b_vnbufs, nbp) {
if ((bp->b_flags & B_BUSY))
continue;
if ((bp->b_flags & B_DELWRI) == 0)
Index: kern/vfs_subr.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/vfs_subr.c,v
retrieving revision 1.275
diff -u -p -r1.275 vfs_subr.c
--- kern/vfs_subr.c 6 Jun 2018 19:02:38 -   1.275
+++ kern/vfs_subr.c 2 Jul 2018 15:37:06 -
@@ -2025,7 +2025,7 @@ brelvp(struct buf *bp)
if (LIST_NEXT(bp, b_vnbufs) != NOLIST)
bufremvn(bp);
if ((vp->v_bioflag & VBIOONSYNCLIST) &&
-   LIST_FIRST(>v_dirtyblkhd) == NULL) {
+   LIST_EMPTY(>v_dirtyblkhd)) {
vp->v_bioflag &= ~VBIOONSYNCLIST;
LIST_REMOVE(vp, v_synclist);
}
@@ -2091,7 +2091,7 @@ reassignbuf(struct buf *bp)
if ((bp->b_flags & B_DELWRI) == 0) {
listheadp = >v_cleanblkhd;
if ((vp->v_bioflag & VBIOONSYNCLIST) &&
-   LIST_FIRST(>v_dirtyblkhd) == NULL) {
+   LIST_EMPTY(>v_dirtyblkhd)) {
vp->v_bioflag &= ~VBIOONSYNCLIST;
LIST_REMOVE(vp, v_synclist);
}
Index: nfs/nfs_subs.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/nfs/nfs_subs.c,v
retrieving revision 1.136
diff -u -p -r1.136 nfs_subs.c
--- nfs/nfs_subs.c  28 Apr 2018 03:13:05 -  1.136
+++ nfs/nfs_subs.c  2 Jul 2018 15:38:24 -
@@ -1519,10 +1519,9 @@ loop:
if (vp->v_mount != mp)  /* Paranoia */
goto loop;
nvp = LIST_NEXT(vp, v_mntvnodes);
-   for (bp = LIST_FIRST(>v_dirtyblkhd); bp != NULL; bp = nbp) {
-   nbp = LIST_NEXT(bp, b_vnbufs);
+   LIST_FOREACH_SAFE(bp, >v_dirtyblkhd, b_vnbufs, nbp) {
if ((bp->b_flags & (B_BUSY | B_DELWRI | B_NEEDCOMMIT))
-   == (B_DELWRI | B_NEEDCOMMIT))
+   == (B_DELWRI | B_NEEDCOMMIT))
bp->b_flags &= ~B_NEEDCOMMIT;
}
}
Index: nfs/nfs_vfsops.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/nfs/nfs_vfsops.c,v
retrieving revision 1.121
diff -u -p -r1.121 nfs_vfsops.c
--- nfs/nfs_vfsops.c27 May 2018 06:02:15 -  1.121
+++ nfs/nfs_vfsops.c2 Jul 2018 15:39:21 -
@@ -812,7 +812,7 @@ loop:
 */
if (vp->v_mount != mp)
goto loop;
-   if (VOP_ISLOCKED(vp) || LIST_FIRST(>v_dirtyblkhd) == NULL)
+   if (VOP_ISLOCKED(vp) || LIST_EMPTY(>v_dirtyblkhd))
continue;
if (vget(vp, LK_EXCLUSIVE))
goto loop;
Index: nfs/nfs_vnops.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/nfs/nfs_vnops.c,v
retrieving revision 1.178
diff -u -p -r1.178 nfs_vnops.c
--- nfs/nfs_vnops.c 21 Jun 2018 14:17:23 -  1.178
+++ nfs/nfs_vnops.c 2 Jul 2018 15:42:53 -
@@ -2867,18 +2867,15 @@ again:
bvecpos = 0;
if (NFS_ISV3(vp) && commit) {
s = splbio();
-   for (bp = LIST_FIRST(>v_dirtyblkhd); bp != NULL; bp = nbp) {
+   LIST_FOREACH_SAFE(bp, >v_dirtyblkhd, b_vnbufs, nbp) {
if (bvecpos >= NFS_COMMITBVECSIZ)
break;
if ((bp->b_flags & (B_BUSY | B_DELWRI | B_NEEDCOMMIT))
-   != (B_DELWRI | B_NEEDCOMMIT)) {
-   nbp = LIST_NEXT(bp, b_vnbufs);
+   != (B_DELWRI | B_NEEDCOMMIT))
continue;
-   }
bremfree(bp);
bp->b_flags |= B_WRITEINPROG;
buf_acquire(bp);
-   nbp = LIST_NEXT(bp, b_vnbufs);
 
/*
 * A list of these buffers is kept so that the
@@ -2939,8 +2936,7 @@ again:
 */
 loop:
s = splbio();
-   for (bp = LIST_FIRST(>v_dirtyblkhd); bp != NULL; bp = 

Re: fdexpand() & open file tracking

2018-07-02 Thread Martin Pieuchot
On 02/07/18(Mon) 11:22, Martin Pieuchot wrote:
> Let's use a array of structures to keep track of open files.  This will
> allow us to simplify locking when expending it.
> 
> While here consistently use M_ZERO when (re)allocating M_FILEDESC
> structures.  I doubt the memset() solution makes any difference these
> days and the resulting code is simpler to understand.
> 
> Finally passes a 'struct filedesc' to fdexpand() to be coherent with
> the other functions.

Updated diff now that Visa committed his nice refcounting code using
atomics.

Since flags are now part of the `fd_ofiles' array we can use the new
spinning `fd_fplock' to serialize access to them instead of fdplock().

Comments, oks?

Index: kern/kern_descrip.c
===
RCS file: /cvs/src/sys/kern/kern_descrip.c,v
retrieving revision 1.175
diff -u -p -r1.175 kern_descrip.c
--- kern/kern_descrip.c 2 Jul 2018 14:36:33 -   1.175
+++ kern/kern_descrip.c 2 Jul 2018 15:36:46 -
@@ -235,7 +235,7 @@ fd_getfile(struct filedesc *fdp, int fd)
return (NULL);
 
mtx_enter(>fd_fplock);
-   fp = fdp->fd_ofiles[fd];
+   fp = fdp->fd_ofiles[fd].fn_fp;
if (fp != NULL)
atomic_inc_int(>f_count);
mtx_leave(>fd_fplock);
@@ -288,7 +288,7 @@ restart:
if ((error = fdalloc(p, 0, )) != 0) {
FRELE(fp, p);
if (error == ENOSPC) {
-   fdexpand(p);
+   fdexpand(fdp);
fdpunlock(fdp);
goto restart;
}
@@ -363,7 +363,7 @@ restart:
if ((error = fdalloc(p, new, )) != 0) {
FRELE(fp, p);
if (error == ENOSPC) {
-   fdexpand(p);
+   fdexpand(fdp);
fdpunlock(fdp);
goto restart;
}
@@ -375,8 +375,11 @@ restart:
}
/* No need for FRELE(), finishdup() uses current ref. */
error = finishdup(p, fp, old, new, retval, 1);
-   if (!error && flags & O_CLOEXEC)
-   fdp->fd_ofileflags[new] |= UF_EXCLOSE;
+   if (!error && flags & O_CLOEXEC) {
+   mtx_enter(>fd_fplock);
+   fdp->fd_ofiles[new].fn_flags |= UF_EXCLOSE;
+   mtx_leave(>fd_fplock);
+   }
 
 out:
fdpunlock(fdp);
@@ -423,7 +426,7 @@ restart:
if ((error = fdalloc(p, newmin, )) != 0) {
FRELE(fp, p);
if (error == ENOSPC) {
-   fdexpand(p);
+   fdexpand(fdp);
fdpunlock(fdp);
goto restart;
}
@@ -431,26 +434,29 @@ restart:
/* No need for FRELE(), finishdup() uses current ref. */
error = finishdup(p, fp, fd, i, retval, 0);
 
-   if (!error && SCARG(uap, cmd) == F_DUPFD_CLOEXEC)
-   fdp->fd_ofileflags[i] |= UF_EXCLOSE;
+   if (!error && SCARG(uap, cmd) == F_DUPFD_CLOEXEC) {
+   mtx_enter(>fd_fplock);
+   fdp->fd_ofiles[i].fn_flags |= UF_EXCLOSE;
+   mtx_leave(>fd_fplock);
+   }
}
 
fdpunlock(fdp);
return (error);
 
case F_GETFD:
-   fdplock(fdp);
-   *retval = fdp->fd_ofileflags[fd] & UF_EXCLOSE ? 1 : 0;
-   fdpunlock(fdp);
+   mtx_enter(>fd_fplock);
+   *retval = fdp->fd_ofiles[fd].fn_flags & UF_EXCLOSE ? 1 : 0;
+   mtx_leave(>fd_fplock);
break;
 
case F_SETFD:
-   fdplock(fdp);
+   mtx_enter(>fd_fplock);
if ((long)SCARG(uap, arg) & 1)
-   fdp->fd_ofileflags[fd] |= UF_EXCLOSE;
+   fdp->fd_ofiles[fd].fn_flags |= UF_EXCLOSE;
else
-   fdp->fd_ofileflags[fd] &= ~UF_EXCLOSE;
-   fdpunlock(fdp);
+   fdp->fd_ofiles[fd].fn_flags &= ~UF_EXCLOSE;
+   mtx_leave(>fd_fplock);
break;
 
case F_GETFL:
@@ -679,10 +685,10 @@ finishdup(struct proc *p, struct file *f
 * the function no longer creates a new reference to the old file.
 */
mtx_enter(>fd_fplock);
-   fdp->fd_ofiles[new] = fp;
+   fdp->fd_ofiles[new].fn_fp = fp;
+   fdp->fd_ofiles[new].fn_flags =
+   fdp->fd_ofiles[old].fn_flags & ~UF_EXCLOSE;
mtx_leave(>fd_fplock);
-
-   fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] & ~UF_EXCLOSE;
*retval = new;
 
if (oldfp != NULL) {
@@ -703,7 +709,8 @@ fdinsert(struct filedesc 

Re: xhci@acpi

2018-07-02 Thread Mark Kettenis
> Date: Mon, 2 Jul 2018 08:31:23 -0700
> From: Mike Larkin 
> 
> On Mon, Jul 02, 2018 at 11:36:59AM +0200, Mark Kettenis wrote:
> > Totally straightforward.
> > 
> > ok?
> > 
> >
> 
> ok mlarkin
> 
> Just wondering if you need to update the man pages for ahci(4)
> and xhci(4) to include the "at acpi0" attachments?

good point!

> > Index: arch/arm64/conf/GENERIC
> > ===
> > RCS file: /cvs/src/sys/arch/arm64/conf/GENERIC,v
> > retrieving revision 1.74
> > diff -u -p -r1.74 GENERIC
> > --- arch/arm64/conf/GENERIC 1 Jul 2018 19:30:37 -   1.74
> > +++ arch/arm64/conf/GENERIC 2 Jul 2018 09:35:47 -
> > @@ -42,6 +42,7 @@ acpibtn*  at acpi?
> >  acpiec*at acpi?
> >  ahci*  at acpi?
> >  com*   at acpi?
> > +xhci*  at acpi?
> >  simplebus* at fdt?
> >  
> >  scsibus*   at scsi?
> > Index: arch/arm64/conf/RAMDISK
> > ===
> > RCS file: /cvs/src/sys/arch/arm64/conf/RAMDISK,v
> > retrieving revision 1.61
> > diff -u -p -r1.61 RAMDISK
> > --- arch/arm64/conf/RAMDISK 1 Jul 2018 19:30:37 -   1.61
> > +++ arch/arm64/conf/RAMDISK 2 Jul 2018 09:35:47 -
> > @@ -52,6 +52,7 @@ acpi0 at mainbus?
> >  acpiec*at acpi?
> >  ahci*  at acpi?
> >  com*   at acpi?
> > +xhci*  at acpi?
> >  simplebus* at fdt?
> >  
> >  scsibus*   at scsi?
> > Index: dev/acpi/files.acpi
> > ===
> > RCS file: /cvs/src/sys/dev/acpi/files.acpi,v
> > retrieving revision 1.47
> > diff -u -p -r1.47 files.acpi
> > --- dev/acpi/files.acpi 1 Jul 2018 15:54:59 -   1.47
> > +++ dev/acpi/files.acpi 2 Jul 2018 09:35:48 -
> > @@ -148,6 +148,10 @@ file   dev/acpi/com_acpi.c com_acpi
> >  attach sdhc at acpi with sdhc_acpi
> >  file   dev/acpi/sdhc_acpi.csdhc_acpi
> >  
> > +# XHCI
> > +attach xhci at acpi with xhci_acpi
> > +file   dev/acpi/xhci_acpi.cxhci_acpi
> > +
> >  # Synopsys DesignWare I2C controller
> >  attach dwiic at acpi with dwiic_acpi
> >  file   dev/acpi/dwiic_acpi.c   dwiic_acpi
> > Index: dev/acpi/xhci_acpi.c
> > ===
> > RCS file: dev/acpi/xhci_acpi.c
> > diff -N dev/acpi/xhci_acpi.c
> > --- /dev/null   1 Jan 1970 00:00:00 -
> > +++ dev/acpi/xhci_acpi.c2 Jul 2018 09:35:48 -
> > @@ -0,0 +1,163 @@
> > +/* $OpenBSD$   */
> > +/*
> > + * Copyright (c) 2018 Mark Kettenis
> > + *
> > + * Permission to use, copy, modify, and distribute this software for any
> > + * purpose with or without fee is hereby granted, provided that the above
> > + * copyright notice and this permission notice appear in all copies.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> > + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> > + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> > + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> > + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> > + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> > + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +
> > +struct xhci_acpi_softc {
> > +   struct xhci_softc sc;
> > +   struct acpi_softc *sc_acpi;
> > +   struct aml_node *sc_node;
> > +
> > +   bus_addr_t  sc_addr;
> > +   bus_size_t  sc_size;
> > +
> > +   int sc_irq;
> > +   int sc_irq_flags;
> > +   void*sc_ih;
> > +};
> > +
> > +intxhci_acpi_match(struct device *, void *, void *);
> > +void   xhci_acpi_attach(struct device *, struct device *, void *);
> > +
> > +struct cfattach xhci_acpi_ca = {
> > +   sizeof(struct xhci_acpi_softc), xhci_acpi_match, xhci_acpi_attach
> > +};
> > +
> > +const char *xhci_hids[] = {
> > +   "PNP0D10",
> > +   NULL
> > +};
> > +
> > +intxhci_acpi_parse_resources(int, union acpi_resource *, void *);
> > +
> > +int
> > +xhci_acpi_match(struct device *parent, void *match, void *aux)
> > +{
> > +   struct acpi_attach_args *aaa = aux;
> > +   struct cfdata *cf = match;
> > +
> > +   return acpi_matchhids(aaa, xhci_hids, cf->cf_driver->cd_name);
> > +}
> > +
> > +void
> > +xhci_acpi_attach(struct device *parent, struct device *self, void *aux)
> > +{
> > +   struct xhci_acpi_softc *sc = (struct xhci_acpi_softc *)self;
> > +   struct acpi_attach_args *aaa = aux;
> > +   struct aml_value res;
> > +   int 

Re: xhci@acpi

2018-07-02 Thread Mike Larkin
On Mon, Jul 02, 2018 at 11:36:59AM +0200, Mark Kettenis wrote:
> Totally straightforward.
> 
> ok?
> 
>

ok mlarkin

Just wondering if you need to update the man pages for ahci(4)
and xhci(4) to include the "at acpi0" attachments?

-ml
 
> Index: arch/arm64/conf/GENERIC
> ===
> RCS file: /cvs/src/sys/arch/arm64/conf/GENERIC,v
> retrieving revision 1.74
> diff -u -p -r1.74 GENERIC
> --- arch/arm64/conf/GENERIC   1 Jul 2018 19:30:37 -   1.74
> +++ arch/arm64/conf/GENERIC   2 Jul 2018 09:35:47 -
> @@ -42,6 +42,7 @@ acpibtn*at acpi?
>  acpiec*  at acpi?
>  ahci*at acpi?
>  com* at acpi?
> +xhci*at acpi?
>  simplebus*   at fdt?
>  
>  scsibus* at scsi?
> Index: arch/arm64/conf/RAMDISK
> ===
> RCS file: /cvs/src/sys/arch/arm64/conf/RAMDISK,v
> retrieving revision 1.61
> diff -u -p -r1.61 RAMDISK
> --- arch/arm64/conf/RAMDISK   1 Jul 2018 19:30:37 -   1.61
> +++ arch/arm64/conf/RAMDISK   2 Jul 2018 09:35:47 -
> @@ -52,6 +52,7 @@ acpi0   at mainbus?
>  acpiec*  at acpi?
>  ahci*at acpi?
>  com* at acpi?
> +xhci*at acpi?
>  simplebus*   at fdt?
>  
>  scsibus* at scsi?
> Index: dev/acpi/files.acpi
> ===
> RCS file: /cvs/src/sys/dev/acpi/files.acpi,v
> retrieving revision 1.47
> diff -u -p -r1.47 files.acpi
> --- dev/acpi/files.acpi   1 Jul 2018 15:54:59 -   1.47
> +++ dev/acpi/files.acpi   2 Jul 2018 09:35:48 -
> @@ -148,6 +148,10 @@ file dev/acpi/com_acpi.c com_acpi
>  attach   sdhc at acpi with sdhc_acpi
>  file dev/acpi/sdhc_acpi.csdhc_acpi
>  
> +# XHCI
> +attach   xhci at acpi with xhci_acpi
> +file dev/acpi/xhci_acpi.cxhci_acpi
> +
>  # Synopsys DesignWare I2C controller
>  attach   dwiic at acpi with dwiic_acpi
>  file dev/acpi/dwiic_acpi.c   dwiic_acpi
> Index: dev/acpi/xhci_acpi.c
> ===
> RCS file: dev/acpi/xhci_acpi.c
> diff -N dev/acpi/xhci_acpi.c
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ dev/acpi/xhci_acpi.c  2 Jul 2018 09:35:48 -
> @@ -0,0 +1,163 @@
> +/*   $OpenBSD$   */
> +/*
> + * Copyright (c) 2018 Mark Kettenis
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +
> +struct xhci_acpi_softc {
> + struct xhci_softc sc;
> + struct acpi_softc *sc_acpi;
> + struct aml_node *sc_node;
> +
> + bus_addr_t  sc_addr;
> + bus_size_t  sc_size;
> +
> + int sc_irq;
> + int sc_irq_flags;
> + void*sc_ih;
> +};
> +
> +int  xhci_acpi_match(struct device *, void *, void *);
> +void xhci_acpi_attach(struct device *, struct device *, void *);
> +
> +struct cfattach xhci_acpi_ca = {
> + sizeof(struct xhci_acpi_softc), xhci_acpi_match, xhci_acpi_attach
> +};
> +
> +const char *xhci_hids[] = {
> + "PNP0D10",
> + NULL
> +};
> +
> +int  xhci_acpi_parse_resources(int, union acpi_resource *, void *);
> +
> +int
> +xhci_acpi_match(struct device *parent, void *match, void *aux)
> +{
> + struct acpi_attach_args *aaa = aux;
> + struct cfdata *cf = match;
> +
> + return acpi_matchhids(aaa, xhci_hids, cf->cf_driver->cd_name);
> +}
> +
> +void
> +xhci_acpi_attach(struct device *parent, struct device *self, void *aux)
> +{
> + struct xhci_acpi_softc *sc = (struct xhci_acpi_softc *)self;
> + struct acpi_attach_args *aaa = aux;
> + struct aml_value res;
> + int error;
> +
> + sc->sc_acpi = (struct acpi_softc *)parent;
> + sc->sc_node = aaa->aaa_node;
> + printf(" %s", sc->sc_node->name);
> +
> + if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, )) {
> + printf(": can't find registers\n");
> + return;
> + }
> +
> + aml_parse_resource(, 

[PATCH] fix typo in if_aue.c

2018-07-02 Thread Kevin Lo
Hi,

I've just noticed a little typo in the if_aue.c (s/read/write).
The diff is below.

Index: sys/dev/usb/if_aue.c
===
RCS file: /cvs/src/sys/dev/usb/if_aue.c,v
retrieving revision 1.106
diff -u -p -u -p -r1.106 if_aue.c
--- sys/dev/usb/if_aue.c22 Jan 2017 10:17:39 -  1.106
+++ sys/dev/usb/if_aue.c2 Jul 2018 14:19:57 -
@@ -509,7 +509,7 @@ aue_miibus_writereg(struct device *dev, 
}
 
if (i == AUE_TIMEOUT) {
-   printf("%s: MII read timed out\n",
+   printf("%s: MII write timed out\n",
sc->aue_dev.dv_xname);
}
aue_unlock_mii(sc);



[PATCH] mos: nuke unused variable

2018-07-02 Thread Kevin Lo
Ok ?

Index: sys/dev/usb/if_mos.c
===
RCS file: /cvs/src/sys/dev/usb/if_mos.c,v
retrieving revision 1.38
diff -u -p -u -p -r1.38 if_mos.c
--- sys/dev/usb/if_mos.c22 Jan 2017 10:17:39 -  1.38
+++ sys/dev/usb/if_mos.c2 Jul 2018 14:09:39 -
@@ -376,15 +376,12 @@ int
 mos_miibus_readreg(struct device *dev, int phy, int reg)
 {
struct mos_softc*sc = (void *)dev;
-   uWord   val;
int i,res;
 
if (usbd_is_dying(sc->mos_udev)) {
DPRINTF(("mos: dying\n"));
return (0);
}
-
-   USETW(val, 0);
 
mos_lock_mii(sc);
 



xhci@acpi

2018-07-02 Thread Mark Kettenis
Totally straightforward.

ok?


Index: arch/arm64/conf/GENERIC
===
RCS file: /cvs/src/sys/arch/arm64/conf/GENERIC,v
retrieving revision 1.74
diff -u -p -r1.74 GENERIC
--- arch/arm64/conf/GENERIC 1 Jul 2018 19:30:37 -   1.74
+++ arch/arm64/conf/GENERIC 2 Jul 2018 09:35:47 -
@@ -42,6 +42,7 @@ acpibtn*  at acpi?
 acpiec*at acpi?
 ahci*  at acpi?
 com*   at acpi?
+xhci*  at acpi?
 simplebus* at fdt?
 
 scsibus*   at scsi?
Index: arch/arm64/conf/RAMDISK
===
RCS file: /cvs/src/sys/arch/arm64/conf/RAMDISK,v
retrieving revision 1.61
diff -u -p -r1.61 RAMDISK
--- arch/arm64/conf/RAMDISK 1 Jul 2018 19:30:37 -   1.61
+++ arch/arm64/conf/RAMDISK 2 Jul 2018 09:35:47 -
@@ -52,6 +52,7 @@ acpi0 at mainbus?
 acpiec*at acpi?
 ahci*  at acpi?
 com*   at acpi?
+xhci*  at acpi?
 simplebus* at fdt?
 
 scsibus*   at scsi?
Index: dev/acpi/files.acpi
===
RCS file: /cvs/src/sys/dev/acpi/files.acpi,v
retrieving revision 1.47
diff -u -p -r1.47 files.acpi
--- dev/acpi/files.acpi 1 Jul 2018 15:54:59 -   1.47
+++ dev/acpi/files.acpi 2 Jul 2018 09:35:48 -
@@ -148,6 +148,10 @@ file   dev/acpi/com_acpi.c com_acpi
 attach sdhc at acpi with sdhc_acpi
 file   dev/acpi/sdhc_acpi.csdhc_acpi
 
+# XHCI
+attach xhci at acpi with xhci_acpi
+file   dev/acpi/xhci_acpi.cxhci_acpi
+
 # Synopsys DesignWare I2C controller
 attach dwiic at acpi with dwiic_acpi
 file   dev/acpi/dwiic_acpi.c   dwiic_acpi
Index: dev/acpi/xhci_acpi.c
===
RCS file: dev/acpi/xhci_acpi.c
diff -N dev/acpi/xhci_acpi.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ dev/acpi/xhci_acpi.c2 Jul 2018 09:35:48 -
@@ -0,0 +1,163 @@
+/* $OpenBSD$   */
+/*
+ * Copyright (c) 2018 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+struct xhci_acpi_softc {
+   struct xhci_softc sc;
+   struct acpi_softc *sc_acpi;
+   struct aml_node *sc_node;
+
+   bus_addr_t  sc_addr;
+   bus_size_t  sc_size;
+
+   int sc_irq;
+   int sc_irq_flags;
+   void*sc_ih;
+};
+
+intxhci_acpi_match(struct device *, void *, void *);
+void   xhci_acpi_attach(struct device *, struct device *, void *);
+
+struct cfattach xhci_acpi_ca = {
+   sizeof(struct xhci_acpi_softc), xhci_acpi_match, xhci_acpi_attach
+};
+
+const char *xhci_hids[] = {
+   "PNP0D10",
+   NULL
+};
+
+intxhci_acpi_parse_resources(int, union acpi_resource *, void *);
+
+int
+xhci_acpi_match(struct device *parent, void *match, void *aux)
+{
+   struct acpi_attach_args *aaa = aux;
+   struct cfdata *cf = match;
+
+   return acpi_matchhids(aaa, xhci_hids, cf->cf_driver->cd_name);
+}
+
+void
+xhci_acpi_attach(struct device *parent, struct device *self, void *aux)
+{
+   struct xhci_acpi_softc *sc = (struct xhci_acpi_softc *)self;
+   struct acpi_attach_args *aaa = aux;
+   struct aml_value res;
+   int error;
+
+   sc->sc_acpi = (struct acpi_softc *)parent;
+   sc->sc_node = aaa->aaa_node;
+   printf(" %s", sc->sc_node->name);
+
+   if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, )) {
+   printf(": can't find registers\n");
+   return;
+   }
+
+   aml_parse_resource(, xhci_acpi_parse_resources, sc);
+   printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size);
+   if (sc->sc_addr == 0 || sc->sc_size == 0) {
+   printf("\n");
+   return;
+   }
+
+   printf(" irq %d", sc->sc_irq);
+
+   sc->sc.iot = aaa->aaa_memt;
+   sc->sc.sc_size = sc->sc_size;
+   sc->sc.sc_bus.dmatag = aaa->aaa_dmat;
+
+   if (bus_space_map(sc->sc.iot, sc->sc_addr, sc->sc_size, 0,
+   

fdexpand() & open file tracking

2018-07-02 Thread Martin Pieuchot
Let's use a array of structures to keep track of open files.  This will
allow us to simplify locking when expending it.

While here consistently use M_ZERO when (re)allocating M_FILEDESC
structures.  I doubt the memset() solution makes any difference these
days and the resulting code is simpler to understand.

Finally passes a 'struct filedesc' to fdexpand() to be coherent with
the other functions.

Comments?  Oks?

Index: kern/kern_descrip.c
===
RCS file: /cvs/src/sys/kern/kern_descrip.c,v
retrieving revision 1.173
diff -u -p -r1.173 kern_descrip.c
--- kern/kern_descrip.c 1 Jul 2018 16:33:15 -   1.173
+++ kern/kern_descrip.c 2 Jul 2018 09:12:30 -
@@ -229,7 +229,7 @@ fd_getfile(struct filedesc *fdp, int fd)
return (NULL);
 
mtx_enter();
-   fp = fdp->fd_ofiles[fd];
+   fp = fdp->fd_files[fd].fn_fp;
if (fp != NULL)
fp->f_count++;
mtx_leave();
@@ -282,7 +282,7 @@ restart:
if ((error = fdalloc(p, 0, )) != 0) {
FRELE(fp, p);
if (error == ENOSPC) {
-   fdexpand(p);
+   fdexpand(fdp);
fdpunlock(fdp);
goto restart;
}
@@ -357,7 +357,7 @@ restart:
if ((error = fdalloc(p, new, )) != 0) {
FRELE(fp, p);
if (error == ENOSPC) {
-   fdexpand(p);
+   fdexpand(fdp);
fdpunlock(fdp);
goto restart;
}
@@ -370,7 +370,7 @@ restart:
/* No need for FRELE(), finishdup() uses current ref. */
error = finishdup(p, fp, old, new, retval, 1);
if (!error && flags & O_CLOEXEC)
-   fdp->fd_ofileflags[new] |= UF_EXCLOSE;
+   fdp->fd_files[new].fn_flags |= UF_EXCLOSE;
 
 out:
fdpunlock(fdp);
@@ -417,7 +417,7 @@ restart:
if ((error = fdalloc(p, newmin, )) != 0) {
FRELE(fp, p);
if (error == ENOSPC) {
-   fdexpand(p);
+   fdexpand(fdp);
fdpunlock(fdp);
goto restart;
}
@@ -426,7 +426,7 @@ restart:
error = finishdup(p, fp, fd, i, retval, 0);
 
if (!error && SCARG(uap, cmd) == F_DUPFD_CLOEXEC)
-   fdp->fd_ofileflags[i] |= UF_EXCLOSE;
+   fdp->fd_files[i].fn_flags |= UF_EXCLOSE;
}
 
fdpunlock(fdp);
@@ -434,16 +434,16 @@ restart:
 
case F_GETFD:
fdplock(fdp);
-   *retval = fdp->fd_ofileflags[fd] & UF_EXCLOSE ? 1 : 0;
+   *retval = fdp->fd_files[fd].fn_flags & UF_EXCLOSE ? 1 : 0;
fdpunlock(fdp);
break;
 
case F_SETFD:
fdplock(fdp);
if ((long)SCARG(uap, arg) & 1)
-   fdp->fd_ofileflags[fd] |= UF_EXCLOSE;
+   fdp->fd_files[fd].fn_flags |= UF_EXCLOSE;
else
-   fdp->fd_ofileflags[fd] &= ~UF_EXCLOSE;
+   fdp->fd_files[fd].fn_flags &= ~UF_EXCLOSE;
fdpunlock(fdp);
break;
 
@@ -668,8 +668,8 @@ finishdup(struct proc *p, struct file *f
fd_used(fdp, new);
}
 
-   fdp->fd_ofiles[new] = fp;
-   fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] & ~UF_EXCLOSE;
+   fdp->fd_files[new].fn_fp = fp;
+   fdp->fd_files[new].fn_flags = fdp->fd_files[old].fn_flags & ~UF_EXCLOSE;
*retval = new;
 
if (oldfp != NULL) {
@@ -690,15 +690,15 @@ fdinsert(struct filedesc *fdp, int fd, i
mtx_enter();
if ((fp->f_iflags & FIF_INSERTED) == 0) {
fp->f_iflags |= FIF_INSERTED;
-   if ((fq = fdp->fd_ofiles[0]) != NULL) {
+   if ((fq = fdp->fd_files[0].fn_fp) != NULL) {
LIST_INSERT_AFTER(fq, fp, f_list);
} else {
LIST_INSERT_HEAD(, fp, f_list);
}
}
-   KASSERT(fdp->fd_ofiles[fd] == NULL);
-   fdp->fd_ofiles[fd] = fp;
-   fdp->fd_ofileflags[fd] |= (flags & UF_EXCLOSE);
+   KASSERT(fdp->fd_files[fd].fn_fp == NULL);
+   fdp->fd_files[fd].fn_fp = fp;
+   fdp->fd_files[fd].fn_flags |= (flags & UF_EXCLOSE);
mtx_leave();
 }
 
@@ -706,8 +706,8 @@ void
 fdremove(struct filedesc *fdp, int fd)
 {
fdpassertlocked(fdp);
-   fdp->fd_ofiles[fd] = NULL;
-   fdp->fd_ofileflags[fd] = 0;
+   fdp->fd_files[fd].fn_fp = NULL;
+   fdp->fd_files[fd].fn_flags = 0;
fd_unused(fdp, fd);
 }
 
@@ -872,9 +872,9 @@ restart: