Add v_uvcount field to vnode(9) definition

2019-02-18 Thread Fasse
The vnode definition on vnode(9) is missing the v_uvcount field.

Also, some of the fields use a tab between the data type and name while
others use spaces. The same is true for the code at /src/sys/sys/vnode.h


Index: share/man/man9/vnode.9
===
RCS file: /cvs/src/share/man/man9/vnode.9,v
retrieving revision 1.29
diff -u -p -u -p -r1.29 vnode.9
--- share/man/man9/vnode.9  4 Jun 2018 19:42:54 -   1.29
+++ share/man/man9/vnode.9  18 Feb 2019 21:03:39 -
@@ -72,6 +72,7 @@ struct vnode {
enumvtagtype v_tag; /* type of underlying data */
u_int   v_flag; /* vnode flags (see below) */
u_int   v_usecount; /* reference count of users */
+   u_int   v_uvcount;  /* unveil references */
/* reference count of writers */
u_int   v_writecount;
/* Flags that can be read/written in interrupts */



Fix compilation warning/error when using ACPIVIDEO_DEBUG

2017-06-28 Thread Fasse
When building OpenBSD with the ACPIVIDEO_DEBUG option set the
compilation fails:

cc1: warnings being treated as errors
/usr/src/sys/dev/acpi/acpivideo.c: In function 'acpivideo_set_policy':
/usr/src/sys/dev/acpi/acpivideo.c:136: warning: format '%X' expects type 
'unsigned int', but argument 3 has type 'int64_t'
/usr/src/sys/dev/acpi/acpivideo.c:136: error: expected expression before '/' 
token
*** Error 1 in /usr/src/sys/arch/amd64/compile/CUSTOM (Makefile:960 
'acpivideo.o')


The return type of aml_val2int (AML_EVALNODE(9)) is int64_t.
The 'patch' below switches to the format specifier %lld. According to
C99 long long must be at least 64 bit wide so it should be fine!?
Otherwise,  and PRId64 might be an option. However, quickly
searching the src-tree reveals PRId64 is seldom used.


Index: src/sys/dev/acpi/acpivideo.c
===
RCS file: /cvs/src/sys/dev/acpi/acpivideo.c,v
retrieving revision 1.10
diff -u -p -u -r1.10 acpivideo.c
--- src/sys/dev/acpi/acpivideo.c14 Mar 2015 03:38:47 -  1.10
+++ src/sys/dev/acpi/acpivideo.c28 Jun 2017 18:39:48 -
@@ -132,7 +132,7 @@ acpivideo_set_policy(struct acpivideo_so
args.type = AML_OBJTYPE_INTEGER;
 
aml_evalname(sc->sc_acpi, sc->sc_devnode, "_DOS", 1, , );
-   DPRINTF(("%s: set policy to %X\n", DEVNAME(sc), aml_val2int()));
+   DPRINTF(("%s: set policy to %lld\n", DEVNAME(sc), aml_val2int()));
 
aml_freevalue();
 }



Re: add support for crc_enabled Elantech v3 touchpads

2015-04-02 Thread Fasse
On Thu, 2 Apr 2015 18:51:38 +0200
Martin Pieuchot m...@openbsd.org wrote:
 Even if that's true, nothing prevent us to commit this diff first, as
 long as it does not introduce regression and then work on the possible
 refactoring needed to support debounce packets :)

That is great to hear.
Because the way pms_sync_elantech_v3 now handles crc mode 
pms_proc_elantech_v3 can't possibly receive a debounce packet. Therefore
I moved the debounce packet check in pms_proc_elantech_v3 into the part
that handles non-crc packets.
Below is the full diff for anyone that wants to try out these changes.

Index: sys/dev/pckbc/pms.c
===
RCS file: /cvs/src/sys/dev/pckbc/pms.c,v
retrieving revision 1.58
diff -u -p -r1.58 pms.c
--- sys/dev/pckbc/pms.c 26 Mar 2015 01:30:22 -  1.58
+++ sys/dev/pckbc/pms.c 2 Apr 2015 20:43:23 -
@@ -137,6 +137,7 @@ struct elantech_softc {
 #define ELANTECH_F_HAS_ROCKER  0x02
 #define ELANTECH_F_2FINGER_PACKET  0x04
 #define ELANTECH_F_HW_V1_OLD   0x08
+#define ELANTECH_F_CRC_ENABLED 0x10
int fw_version;
 
int min_x, min_y;
@@ -1812,6 +1813,9 @@ elantech_get_hwinfo_v3(struct pms_softc 
elantech-fw_version = fw_version;
elantech-flags |= ELANTECH_F_REPORTS_PRESSURE;
 
+   if ((fw_version  0x4000) == 0x4000)
+   elantech-flags |= ELANTECH_F_CRC_ENABLED;
+
if (elantech_set_absolute_mode_v3(sc))
return (-1);
 
@@ -2164,14 +2168,23 @@ pms_sync_elantech_v2(struct pms_softc *s
 int
 pms_sync_elantech_v3(struct pms_softc *sc, int data)
 {
+   struct elantech_softc *elantech = sc-elantech;
+
switch (sc-inputstate) {
case 0:
+   if (elantech-flags  ELANTECH_F_CRC_ENABLED)
+   break;
if ((data  0x0c) != 0x04  (data  0x0c) != 0x0c)
return (-1);
break;
case 3:
-   if ((data  0xcf) != 0x02  (data  0xce) != 0x0c)
-   return (-1);
+   if (elantech-flags  ELANTECH_F_CRC_ENABLED) {
+   if ((data  0x09) != 0x08  (data  0x09) != 0x09)
+   return (-1);
+   } else {
+   if ((data  0xcf) != 0x02  (data  0xce) != 0x0c)
+   return (-1);
+   }
break;
}
 
@@ -2256,11 +2269,6 @@ pms_proc_elantech_v3(struct pms_softc *s
struct elantech_softc *elantech = sc-elantech;
int x, y, w, z;
 
-   /* The hardware sends this packet when in debounce state.
-* The packet should be ignored. */
-   if (!memcmp(sc-packet, debounce_pkt, sizeof(debounce_pkt)))
-   return;
-
x = ((sc-packet[1]  0x0f)  8 | sc-packet[2]);
y = ((sc-packet[4]  0x0f)  8 | sc-packet[5]);
z = 0;
@@ -2271,10 +2279,19 @@ pms_proc_elantech_v3(struct pms_softc *s
 * and a tail packet. We report a single event and ignore
 * the tail packet.
 */
-   if ((sc-packet[0]  0x0c) != 0x04 
-   (sc-packet[3]  0xcf) != 0x02) {
-   /* not the head packet -- ignore */
-   return;
+   if (elantech-flags  ELANTECH_F_CRC_ENABLED) {
+   if ((sc-packet[3]  0x09) != 0x08)
+   return;
+   } else {
+   /* The hardware sends this packet when in debounce 
state.
+* The packet should be ignored. */
+   if (!memcmp(sc-packet, debounce_pkt, 
sizeof(debounce_pkt)))
+   return;
+   if ((sc-packet[0]  0x0c) != 0x04 
+   (sc-packet[3]  0xcf) != 0x02) {
+   /* not the head packet -- ignore */
+   return;
+   }
}
}
 



add support for crc_enabled Elantech v3 touchpads

2015-04-01 Thread Fasse
This diff adds support for Elantech v3 touchpads using the crc_enabled
integrity check. I tested this patch with my Elantech v3 touchpad using
firmware version 0x454f00, it now works correctly. 
Other hardware versions should not be affected by this change. I could
not check if this introduces regression with other firmware versions.
If you have an elantech touchpad, particularly v3, could you please try
this diff and see if it causes any issues.

Index: sys/dev/pckbc/pms.c
===
RCS file: /cvs/src/sys/dev/pckbc/pms.c,v
retrieving revision 1.58
diff -u -p -r1.58 pms.c
--- sys/dev/pckbc/pms.c 26 Mar 2015 01:30:22 -  1.58
+++ sys/dev/pckbc/pms.c 1 Apr 2015 14:22:10 -
@@ -137,6 +137,7 @@ struct elantech_softc {
 #define ELANTECH_F_HAS_ROCKER  0x02
 #define ELANTECH_F_2FINGER_PACKET  0x04
 #define ELANTECH_F_HW_V1_OLD   0x08
+#define ELANTECH_F_CRC_ENABLED 0x10
int fw_version;
 
int min_x, min_y;
@@ -1812,6 +1813,9 @@ elantech_get_hwinfo_v3(struct pms_softc 
elantech-fw_version = fw_version;
elantech-flags |= ELANTECH_F_REPORTS_PRESSURE;
 
+   if ((fw_version  0x4000) == 0x4000)
+   elantech-flags |= ELANTECH_F_CRC_ENABLED;
+
if (elantech_set_absolute_mode_v3(sc))
return (-1);
 
@@ -2164,14 +2168,23 @@ pms_sync_elantech_v2(struct pms_softc *s
 int
 pms_sync_elantech_v3(struct pms_softc *sc, int data)
 {
+   struct elantech_softc *elantech = sc-elantech;
+
switch (sc-inputstate) {
case 0:
+   if (elantech-flags  ELANTECH_F_CRC_ENABLED)
+   break;
if ((data  0x0c) != 0x04  (data  0x0c) != 0x0c)
return (-1);
break;
case 3:
-   if ((data  0xcf) != 0x02  (data  0xce) != 0x0c)
-   return (-1);
+   if (elantech-flags  ELANTECH_F_CRC_ENABLED) {
+   if ((data  0x09) != 0x08  (data  0x09) != 0x09)
+   return (-1);
+   } else {
+   if ((data  0xcf) != 0x02  (data  0xce) != 0x0c)
+   return (-1);
+   }
break;
}
 
@@ -2271,11 +2284,18 @@ pms_proc_elantech_v3(struct pms_softc *s
 * and a tail packet. We report a single event and ignore
 * the tail packet.
 */
-   if ((sc-packet[0]  0x0c) != 0x04 
-   (sc-packet[3]  0xcf) != 0x02) {
-   /* not the head packet -- ignore */
-   return;
+   switch (elantech-flags  ELANTECH_F_CRC_ENABLED) {
+   case 0:
+   if ((sc-packet[0]  0x0c) != 0x04 
+   (sc-packet[3]  0xcf) != 0x02) {
+   /* not the head packet -- ignore */
+   return;
+   }
+   case ELANTECH_F_CRC_ENABLED:
+   if ((sc-packet[3]  0x09) != 0x08)
+   return;
}
+   
}
 
/* Prevent juming cursor if pad isn't touched or reports garbage. */



Re: add support for crc_enabled Elantech v3 touchpads

2015-04-01 Thread Fasse
On Wed, 01 Apr 2015 20:05:46 +0200
Ulf Brosziewski ulf.brosziew...@t-online.de wrote:

 Hi,
 
 there might be a problem. The Linux driver for that touchpad type also
 accepts debounce packets, which have the same format as for the
 non-crc version. I have no idea whether that is correct and if those
 packets do occur in practice, but if they do they wouldn't pass this
 version of sync() (byte 3 would be 0x02 then).
 

You are right. I haven't had issues so far with debounce packets
missing but I obviously only have a very small sample size so there is
that. Since the debounce packet is ignored anyways I don't know if it
matters that it is thrown out early. Although if it didn't matter there
probably wouldn't even be a debounce packet? We could allow byte 3 to 
pass if its value after the check is 0x02 but that kind of defeats the 
purpose  of the integrity check I guess. 
Fortunately the values of debounce and head packets match up for non crc
elantech v3 touchpads. I don't think there is an elegant way to solve
this problem because pms_sync_elantech_v3 is called before the packet is
complete and you need the whole packet to check if it is a debounce
packet. To solve this we would have to do somthing similar to the linux
driver by only checking complete packets.



Re: add support for crc_enabled Elantech v3 touchpads

2015-04-01 Thread Fasse
On Wed, 1 Apr 2015 18:02:59 +0200
Stefan Sperling s...@stsp.name wrote:
 Interesting, thanks.
 
 If you don't hear from anyone else about this please ask me again in
 a week from now. I can test on v3 hardware by then but not any earlier.
 
 Please write this as if-else instead of switch:
 
  @@ -2271,11 +2284,18 @@ pms_proc_elantech_v3(struct pms_softc *s
   * and a tail packet. We report a single event and ignore
   * the tail packet.
   */
  -   if ((sc-packet[0]  0x0c) != 0x04 
  -   (sc-packet[3]  0xcf) != 0x02) {
  -   /* not the head packet -- ignore */
  -   return;
  +   switch (elantech-flags  ELANTECH_F_CRC_ENABLED) {
  +   case 0:
  +   if ((sc-packet[0]  0x0c) != 0x04 
  +   (sc-packet[3]  0xcf) != 0x02) {
  +   /* not the head packet -- ignore */
  +   return;
  +   }
  +   case ELANTECH_F_CRC_ENABLED:
  +   if ((sc-packet[3]  0x09) != 0x08)
  +   return;
  }

Thanks for the offer I will propably take you up on that.
Below is the modified diff with the switch statement transformed.

Index: sys/dev/pckbc/pms.c
===
RCS file: /cvs/src/sys/dev/pckbc/pms.c,v
retrieving revision 1.58
diff -u -p -r1.58 pms.c
--- sys/dev/pckbc/pms.c 26 Mar 2015 01:30:22 -  1.58
+++ sys/dev/pckbc/pms.c 1 Apr 2015 16:31:33 -
@@ -137,6 +137,7 @@ struct elantech_softc {
 #define ELANTECH_F_HAS_ROCKER  0x02
 #define ELANTECH_F_2FINGER_PACKET  0x04
 #define ELANTECH_F_HW_V1_OLD   0x08
+#define ELANTECH_F_CRC_ENABLED 0x10
int fw_version;
 
int min_x, min_y;
@@ -1812,6 +1813,9 @@ elantech_get_hwinfo_v3(struct pms_softc 
elantech-fw_version = fw_version;
elantech-flags |= ELANTECH_F_REPORTS_PRESSURE;
 
+   if ((fw_version  0x4000) == 0x4000)
+   elantech-flags |= ELANTECH_F_CRC_ENABLED;
+
if (elantech_set_absolute_mode_v3(sc))
return (-1);
 
@@ -2164,14 +2168,23 @@ pms_sync_elantech_v2(struct pms_softc *s
 int
 pms_sync_elantech_v3(struct pms_softc *sc, int data)
 {
+   struct elantech_softc *elantech = sc-elantech;
+
switch (sc-inputstate) {
case 0:
+   if (elantech-flags  ELANTECH_F_CRC_ENABLED)
+   break;
if ((data  0x0c) != 0x04  (data  0x0c) != 0x0c)
return (-1);
break;
case 3:
-   if ((data  0xcf) != 0x02  (data  0xce) != 0x0c)
-   return (-1);
+   if (elantech-flags  ELANTECH_F_CRC_ENABLED) {
+   if ((data  0x09) != 0x08  (data  0x09) != 0x09)
+   return (-1);
+   } else {
+   if ((data  0xcf) != 0x02  (data  0xce) != 0x0c)
+   return (-1);
+   }
break;
}
 
@@ -2271,10 +2284,15 @@ pms_proc_elantech_v3(struct pms_softc *s
 * and a tail packet. We report a single event and ignore
 * the tail packet.
 */
-   if ((sc-packet[0]  0x0c) != 0x04 
-   (sc-packet[3]  0xcf) != 0x02) {
-   /* not the head packet -- ignore */
-   return;
+   if (elantech-flags  ELANTECH_F_CRC_ENABLED) {
+   if ((sc-packet[3]  0x09) != 0x08)
+   return;
+   } else {
+   if ((sc-packet[0]  0x0c) != 0x04 
+   (sc-packet[3]  0xcf) != 0x02) {
+   /* not the head packet -- ignore */
+   return;
+   }
}
}