Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Marc Espie
On Sat, Aug 12, 2023 at 05:22:38PM +0200, Peter J. Philipp wrote:
> On Sat, Aug 12, 2023 at 02:27:13PM +, Miod Vallat wrote:
> > Third time's (hopefully) the charm. How about that diff? Too much things
> > have been removed in uwacom.
> 
> partial success!  The wacom driver is recognized, no panics this time.  But
> the input is all over the place when I try to draw anything in gimp.  It opens
> windows and stuff that I didn't open.

I see stuff like that, but that's actually an improvement here: ask xev,
and you'll see some extra position information that's mapped to the 4th
axis, which needs to be remmapped manually in gimp, as far as I know (for
now)



Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Miod Vallat
> On Sat, Aug 12, 2023 at 02:27:13PM +, Miod Vallat wrote:
> > Third time's (hopefully) the charm. How about that diff? Too much things
> > have been removed in uwacom.
> 
> partial success!  The wacom driver is recognized, no panics this time.  But
> the input is all over the place when I try to draw anything in gimp.  It opens
> windows and stuff that I didn't open.

I think it was a mistake to try and have the wacom interrupt code
cover the "new" models as well as the existing ones, so I've split it
in two flavours.

New diff below.

Index: dev/hid/hid.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.c,v
retrieving revision 1.5
diff -u -p -r1.5 hid.c
--- dev/hid/hid.c   20 May 2022 05:03:45 -  1.5
+++ dev/hid/hid.c   12 Aug 2023 15:51:13 -
@@ -657,3 +657,52 @@ hid_is_collection(const void *desc, int 
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   hid_end_parse(hd);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return -1;
+}
Index: dev/hid/hid.h
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.h,v
retrieving revision 1.10
diff -u -p -r1.10 hid.h
--- dev/hid/hid.h   20 May 2022 05:03:45 -  1.10
+++ dev/hid/hid.h   12 Aug 2023 15:51:13 -
@@ -93,6 +93,10 @@ int  hid_locate(const void *, int, int32_
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
+   uint32_t);
+inthid_get_id_of_collection(const void *desc, int size, int32_t usage, 
+   uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +357,7 @@ int hid_is_collection(const void *, int,
 #define HUD_TOUCHSCREEN0x0004
 #define HUD_TOUCHPAD   0x0005
 #define HUD_CONFIG 0x000e
+#define HUD_STYLUS 0x0020
 #define HUD_FINGER 0x0022
 #define HUD_TIP_PRESSURE   0x0030
 #define HUD_BARREL_PRESSURE0x0031
@@ -387,6 +392,12 @@ inthid_is_collection(const void *, int,
 #define HUD_CONTACT_MAX0x0055
 #define HUD_SCAN_TIME  0x0056
 #define HUD_BUTTON_TYPE0x0059
+#define HUD_SECONDARY_BARREL_SWITCH0x005A
+#define HUD_WACOM_X0x0130
+#define HUD_WACOM_Y0x0131
+#define HUD_WACOM_DISTANCE 0x0132
+#define HUD_WACOM_PAD_BUTTONS000x0910
+#define HUD_WACOM_BATTERY  0x1013
 
 /* Usages, LED */
 #define HUL_NUM_LOCK   0x0001
Index: dev/hid/hidms.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hidms.c,v
retrieving revision 1.9
diff -u -p -r1.9 hidms.c
--- dev/hid/hidms.c 16 Jun 2022 20:52:38 -  1.9
+++ dev/hid/hidms.c 12 Aug 2023 15:51:13 -
@@ -61,6 +61,188 @@ int hidmsdebug = 0;
 #define MOUSE_FLAGS_MASK   (HIO_CONST | HIO_RELATIVE)
 #define NOTMOUSE(f)(((f) & MOUSE_FLAGS_MASK) != HIO_RELATIVE)
 
+void
+hidms_stylus_hid_parse(struct hidms *ms, struct hid_data *d,
+struct hid_location *loc_stylus_btn)
+{
+   struct hid_item h;
+
+   while (hid_get_item(d, )) {
+   if (h.kind == hid_endcollection)
+

Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Peter J. Philipp
On Sat, Aug 12, 2023 at 02:27:13PM +, Miod Vallat wrote:
> Third time's (hopefully) the charm. How about that diff? Too much things
> have been removed in uwacom.

partial success!  The wacom driver is recognized, no panics this time.  But
the input is all over the place when I try to draw anything in gimp.  It opens
windows and stuff that I didn't open.

spica$ dmesg | grep uwacom
uwacom0 at uhidev0 reportid 16: 3 buttons
wsmouse0 at uwacom0 mux 0
uwacom1 at uhidev0 reportid 192: 3 buttons
wsmouse1 at uwacom1 mux 0
spica$ usbdevs 
Controller /dev/usb0:
addr 01: 8086: Intel, xHCI root hub
addr 02: 056a:033b Wacom Co.,Ltd., Intuos PS
addr 03: 05ac:8290 Broadcom Corp., Bluetooth USB Host Controller
addr 04: 05ac:0273 Apple Inc., Apple Internal Keyboard / Trackpad
addr 05: 05ac:8406 Apple, Card Reader

Oh I see, it attached uwacom0 and uwacom1, odd!  I'll attach the full dmesg
on this one:

syncing disks... done
bwfm0: flowring not closing
bwfm0: flowring not closing
rebooting...
OpenBSD 7.3-current (GENERIC.MP) #4: Sat Aug 12 17:08:58 CEST 2023
p...@spica.delphinusdns.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 17059287040 (16269MB)
avail mem = 16522543104 (15757MB)
random: good seed from bootblocks
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0x8afac000 (32 entries)
bios0: vendor Apple Inc. version "186.0.0.0.0" date 06/14/2019
bios0: Apple Inc. MacBookPro12,1
efi0 at bios0: UEFI 1.1
acpi0 at bios0: ACPI 5.0
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP HPET APIC SBST ECDT SSDT SSDT SSDT SSDT SSDT SSDT SSDT 
SSDT DMAR MCFG
acpi0: wakeup devices PEG0(S3) EC__(S3) HDEF(S3) RP01(S3) RP02(S3) RP03(S4) 
ARPT(S4) RP05(S3) RP06(S3) SPIT(S3) XHC1(S3) ADP1(S3) LID0(S3)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz, 2800.02 MHz, 06-3d-04, patch 
002f
cpu0: 
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,RDSEED,ADX,SMAP,PT,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu0: 32KB 64b/line 8-way D-cache, 32KB 64b/line 8-way I-cache, 256KB 64b/line 
8-way L2 cache, 3MB 64b/line 12-way L3 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 100MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz, 2800.06 MHz, 06-3d-04, patch 
002f
cpu1: 
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,RDSEED,ADX,SMAP,PT,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu1: 32KB 64b/line 8-way D-cache, 32KB 64b/line 8-way I-cache, 256KB 64b/line 
8-way L2 cache, 3MB 64b/line 12-way L3 cache
cpu1: smt 0, core 1, package 0
cpu2 at mainbus0: apid 1 (application processor)
cpu2: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz, 2800.06 MHz, 06-3d-04, patch 
002f
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,RDSEED,ADX,SMAP,PT,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu2: 32KB 64b/line 8-way D-cache, 32KB 64b/line 8-way I-cache, 256KB 64b/line 
8-way L2 cache, 3MB 64b/line 12-way L3 cache
cpu2: smt 1, core 0, package 0
cpu3 at mainbus0: apid 3 (application processor)
cpu3: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz, 2800.08 MHz, 06-3d-04, patch 
002f
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,RDSEED,ADX,SMAP,PT,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu3: 32KB 64b/line 8-way D-cache, 32KB 

Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Miod Vallat
Third time's (hopefully) the charm. How about that diff? Too much things
have been removed in uwacom.

Index: dev/hid/hid.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.c,v
retrieving revision 1.5
diff -u -p -r1.5 hid.c
--- dev/hid/hid.c   20 May 2022 05:03:45 -  1.5
+++ dev/hid/hid.c   12 Aug 2023 14:24:53 -
@@ -657,3 +657,52 @@ hid_is_collection(const void *desc, int 
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   hid_end_parse(hd);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return 0;
+}
Index: dev/hid/hid.h
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.h,v
retrieving revision 1.10
diff -u -p -r1.10 hid.h
--- dev/hid/hid.h   20 May 2022 05:03:45 -  1.10
+++ dev/hid/hid.h   12 Aug 2023 14:24:53 -
@@ -93,6 +93,10 @@ int  hid_locate(const void *, int, int32_
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
+   uint32_t);
+inthid_get_id_of_collection(const void *desc, int size, int32_t usage, 
+   uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +357,7 @@ int hid_is_collection(const void *, int,
 #define HUD_TOUCHSCREEN0x0004
 #define HUD_TOUCHPAD   0x0005
 #define HUD_CONFIG 0x000e
+#define HUD_STYLUS 0x0020
 #define HUD_FINGER 0x0022
 #define HUD_TIP_PRESSURE   0x0030
 #define HUD_BARREL_PRESSURE0x0031
@@ -387,6 +392,12 @@ inthid_is_collection(const void *, int,
 #define HUD_CONTACT_MAX0x0055
 #define HUD_SCAN_TIME  0x0056
 #define HUD_BUTTON_TYPE0x0059
+#define HUD_SECONDARY_BARREL_SWITCH0x005A
+#define HUD_WACOM_X0x0130
+#define HUD_WACOM_Y0x0131
+#define HUD_WACOM_DISTANCE 0x0132
+#define HUD_WACOM_PAD_BUTTONS000x0910
+#define HUD_WACOM_BATTERY  0x1013
 
 /* Usages, LED */
 #define HUL_NUM_LOCK   0x0001
Index: dev/hid/hidms.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hidms.c,v
retrieving revision 1.9
diff -u -p -r1.9 hidms.c
--- dev/hid/hidms.c 16 Jun 2022 20:52:38 -  1.9
+++ dev/hid/hidms.c 12 Aug 2023 14:24:53 -
@@ -61,6 +61,188 @@ int hidmsdebug = 0;
 #define MOUSE_FLAGS_MASK   (HIO_CONST | HIO_RELATIVE)
 #define NOTMOUSE(f)(((f) & MOUSE_FLAGS_MASK) != HIO_RELATIVE)
 
+void
+hidms_stylus_hid_parse(struct hidms *ms, struct hid_data *d,
+struct hid_location *loc_stylus_btn)
+{
+   struct hid_item h;
+
+   while (hid_get_item(d, )) {
+   if (h.kind == hid_endcollection)
+   break;
+   if (h.kind != hid_input || (h.flags & HIO_CONST) != 0)
+   continue;
+   /* All the possible stylus reported usages go here */
+#ifdef HIDMS_DEBUG
+   printf("stylus usage: 0x%x\n", h.usage);
+#endif
+   switch (h.usage) {
+   /* Buttons */
+   case HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_TIP_SWITCH):
+   

Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Peter J. Philipp
On Sat, Aug 12, 2023 at 01:12:26PM +, Miod Vallat wrote:
> > On Sat, Aug 12, 2023 at 08:00:48AM +, Miod Vallat wrote:
> > > I have had a look at your diff and I think it's decent enough to go in
> > > after some polishing.
> > > 
> > > Can Wacom tablet users try this cleaned up diff?
> > 
> > Hi,
> > 
> > My WACOM tablet stopped working with this, here is a dmesg with the patch 
> > and
> > usbdevs -v output.  Let me know if there is any new patches I can test.
> > 
> > As you can see it doesn't even attach like it should (from the dmesg).
> 
> Thanks for reporting this. The changes in uhidev have been a bit too
> aggressive indeed.
> 
> Does this new version of the diff help? Only uhidev.c differs.

Hi!

I got an instant panic after attach of uwacom0.  Since I don't have a camera
nor do I have panic console access on this macbook pro because the keyboard is
USB, I wrote it down on 2 post-it notes.  Let me see if this helps you any:

uvm_fault(,,,)->e
pagefault trap code 0
stopped at config_search 0x100 cmpq %rax, 0x18(%r14)
...
config_search +0x100
config_found_sm +0x36
hidms_attach +0xe3
uwacom_attach +0x15c
config_attach +0x1f4

Now I believe there is offsets that only work on my compilation so I'll try to
get you some object dumps (objdump -D):

uwacom_attach:

00e0 :
  e0:   f3 0f 1e fa endbr64 
  e4:   4c 8b 1d 00 00 00 00mov0(%rip),%r11# eb 

  eb:   4c 33 1c 24 xor(%rsp),%r11
  ef:   55  push   %rbp
  f0:   48 89 e5mov%rsp,%rbp
  f3:   57  push   %rdi
  f4:   56  push   %rsi
  f5:   52  push   %rdx
  f6:   57  push   %rdi
  f7:   41 53   push   %r11
  f9:   41 57   push   %r15
  fb:   41 56   push   %r14
  fd:   41 55   push   %r13
  ff:   41 54   push   %r12
 101:   48 83 ec 18 sub$0x18,%rsp
 105:   49 89 d4mov%rdx,%r12
 108:   49 89 f7mov%rsi,%r15
 10b:   4c 8d 76 78 lea0x78(%rsi),%r14
 10f:   48 8b 02mov(%rdx),%rax
 112:   48 c7 46 60 00 00 00movq   $0x0,0x60(%rsi)
 119:   00 
 11a:   48 8b 4a 08 mov0x8(%rdx),%rcx
 11e:   48 89 4e 50 mov%rcx,0x50(%rsi)
 122:   48 8b 40 18 mov0x18(%rax),%rax
 126:   48 89 46 48 mov%rax,0x48(%rsi)
 12a:   8a 42 10mov0x10(%rdx),%al
 12d:   88 46 58mov%al,0x58(%rsi)
 130:   48 8b 42 08 mov0x8(%rdx),%rax
 134:   48 8b 78 48 mov0x48(%rax),%rdi
 138:   8b 70 58mov0x58(%rax),%esi
 13b:   31 d2   xor%edx,%edx
 13d:   31 c9   xor%ecx,%ecx
 13f:   e8 00 00 00 00  callq  144 
 144:   49 8b 7c 24 08  mov0x8(%r12),%rdi
 149:   48 8d 75 a8 lea0xffa8(%rbp),%rsi
 14d:   48 8d 55 b4 lea0xffb4(%rbp),%rdx
 151:   e8 00 00 00 00  callq  156 
 156:   45 0f b6 6c 24 10   movzbl 0x10(%r12),%r13d
 15c:   48 8b 7d a8 mov0xffa8(%rbp),%rdi
 160:   8b 75 b4mov0xffb4(%rbp),%esi
 163:   31 d2   xor%edx,%edx
...


hidms_attach:

0ca0 :
 ca0:   f3 0f 1e fa endbr64 
 ca4:   4c 8b 1d 00 00 00 00mov0(%rip),%r11# cab 

 cab:   4c 33 1c 24 xor(%rsp),%r11
 caf:   55  push   %rbp
 cb0:   48 89 e5mov%rsp,%rbp
 cb3:   57  push   %rdi
 cb4:   56  push   %rsi
 cb5:   41 53   push   %r11
 cb7:   41 57   push   %r15
 cb9:   41 56   push   %r14
 cbb:   48 83 ec 18 sub$0x18,%rsp
 cbf:   49 89 f7mov%rsi,%r15
 cc2:   49 89 femov%rdi,%r14
 cc5:   8b 77 18mov0x18(%rdi),%esi
 cc8:   83 fe 01cmp$0x1,%esi
 ccb:   48 c7 c0 00 00 00 00mov$0x0,%rax
 cd2:   48 87 d0xchg   %rdx,%rax
 cd5:   48 c7 c0 00 00 00 00mov$0x0,%rax
 cdc:   48 87 d0xchg   %rdx,%rax
 cdf:   48 0f 44 d0 cmove  %rax,%rdx
 ce3:   48 c7 c7 00 00 00 00mov$0x0,%rdi
 cea:   31 c0   xor%eax,%eax
 cec:   e8 00 00 00 00  callq  cf1 
 cf1:   41 8b 46 14 mov0x14(%r14),%eax
 cf5:   83 e0 0aand$0xa,%eax
 cf8:   83 f8 02cmp$0x2,%eax
 cfb:   74 13   je d10 
 cfd:   83 f8 0a

Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Miod Vallat
> On Sat, Aug 12, 2023 at 08:00:48AM +, Miod Vallat wrote:
> > I have had a look at your diff and I think it's decent enough to go in
> > after some polishing.
> > 
> > Can Wacom tablet users try this cleaned up diff?
> 
> Hi,
> 
> My WACOM tablet stopped working with this, here is a dmesg with the patch and
> usbdevs -v output.  Let me know if there is any new patches I can test.
> 
> As you can see it doesn't even attach like it should (from the dmesg).

Thanks for reporting this. The changes in uhidev have been a bit too
aggressive indeed.

Does this new version of the diff help? Only uhidev.c differs.

Index: dev/hid/hid.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.c,v
retrieving revision 1.5
diff -u -p -r1.5 hid.c
--- dev/hid/hid.c   20 May 2022 05:03:45 -  1.5
+++ dev/hid/hid.c   12 Aug 2023 13:11:22 -
@@ -657,3 +657,52 @@ hid_is_collection(const void *desc, int 
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   hid_end_parse(hd);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return 0;
+}
Index: dev/hid/hid.h
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.h,v
retrieving revision 1.10
diff -u -p -r1.10 hid.h
--- dev/hid/hid.h   20 May 2022 05:03:45 -  1.10
+++ dev/hid/hid.h   12 Aug 2023 13:11:22 -
@@ -93,6 +93,10 @@ int  hid_locate(const void *, int, int32_
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
+   uint32_t);
+inthid_get_id_of_collection(const void *desc, int size, int32_t usage, 
+   uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +357,7 @@ int hid_is_collection(const void *, int,
 #define HUD_TOUCHSCREEN0x0004
 #define HUD_TOUCHPAD   0x0005
 #define HUD_CONFIG 0x000e
+#define HUD_STYLUS 0x0020
 #define HUD_FINGER 0x0022
 #define HUD_TIP_PRESSURE   0x0030
 #define HUD_BARREL_PRESSURE0x0031
@@ -387,6 +392,12 @@ inthid_is_collection(const void *, int,
 #define HUD_CONTACT_MAX0x0055
 #define HUD_SCAN_TIME  0x0056
 #define HUD_BUTTON_TYPE0x0059
+#define HUD_SECONDARY_BARREL_SWITCH0x005A
+#define HUD_WACOM_X0x0130
+#define HUD_WACOM_Y0x0131
+#define HUD_WACOM_DISTANCE 0x0132
+#define HUD_WACOM_PAD_BUTTONS000x0910
+#define HUD_WACOM_BATTERY  0x1013
 
 /* Usages, LED */
 #define HUL_NUM_LOCK   0x0001
Index: dev/hid/hidms.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hidms.c,v
retrieving revision 1.9
diff -u -p -r1.9 hidms.c
--- dev/hid/hidms.c 16 Jun 2022 20:52:38 -  1.9
+++ dev/hid/hidms.c 12 Aug 2023 13:11:22 -
@@ -61,6 +61,188 @@ int hidmsdebug = 0;
 #define MOUSE_FLAGS_MASK   (HIO_CONST | HIO_RELATIVE)
 #define NOTMOUSE(f)(((f) & MOUSE_FLAGS_MASK) != HIO_RELATIVE)
 
+void
+hidms_stylus_hid_parse(struct hidms *ms, struct hid_data *d,
+struct hid_location *loc_stylus_btn)
+{
+   struct hid_item h;
+
+   while 

Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Peter J. Philipp
On Sat, Aug 12, 2023 at 08:00:48AM +, Miod Vallat wrote:
> I have had a look at your diff and I think it's decent enough to go in
> after some polishing.
> 
> Can Wacom tablet users try this cleaned up diff?

Hi,

My WACOM tablet stopped working with this, here is a dmesg with the patch and
usbdevs -v output.  Let me know if there is any new patches I can test.

As you can see it doesn't even attach like it should (from the dmesg).

Best Regards,
-peter


rebooting...
OpenBSD 7.3-current (GENERIC.MP) #1: Sat Aug 12 12:34:12 CEST 2023
p...@spica.delphinusdns.org:/sys/arch/amd64/compile/GENERIC.MP
real mem = 17059287040 (16269MB)
avail mem = 16522567680 (15757MB)
random: good seed from bootblocks
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0x8afac000 (32 entries)
bios0: vendor Apple Inc. version "186.0.0.0.0" date 06/14/2019
bios0: Apple Inc. MacBookPro12,1
efi0 at bios0: UEFI 1.1
acpi0 at bios0: ACPI 5.0
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP HPET APIC SBST ECDT SSDT SSDT SSDT SSDT SSDT SSDT SSDT 
SSDT DMAR MCFG
acpi0: wakeup devices PEG0(S3) EC__(S3) HDEF(S3) RP01(S3) RP02(S3) RP03(S4) 
ARPT(S4) RP05(S3) RP06(S3) SPIT(S3) XHC1(S3) ADP1(S3) LID0(S3)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz, 2800.02 MHz, 06-3d-04, patch 
002f
cpu0: 
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,RDSEED,ADX,SMAP,PT,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu0: 32KB 64b/line 8-way D-cache, 32KB 64b/line 8-way I-cache, 256KB 64b/line 
8-way L2 cache, 3MB 64b/line 12-way L3 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 100MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz, 2800.05 MHz, 06-3d-04, patch 
002f
cpu1: 
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,RDSEED,ADX,SMAP,PT,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu1: 32KB 64b/line 8-way D-cache, 32KB 64b/line 8-way I-cache, 256KB 64b/line 
8-way L2 cache, 3MB 64b/line 12-way L3 cache
cpu1: smt 0, core 1, package 0
cpu2 at mainbus0: apid 1 (application processor)
cpu2: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz, 2800.06 MHz, 06-3d-04, patch 
002f
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,RDSEED,ADX,SMAP,PT,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu2: 32KB 64b/line 8-way D-cache, 32KB 64b/line 8-way I-cache, 256KB 64b/line 
8-way L2 cache, 3MB 64b/line 12-way L3 cache
cpu2: smt 1, core 0, package 0
cpu3 at mainbus0: apid 3 (application processor)
cpu3: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz, 2800.05 MHz, 06-3d-04, patch 
002f
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,RDSEED,ADX,SMAP,PT,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,MELTDOWN
cpu3: 32KB 64b/line 8-way D-cache, 32KB 64b/line 8-way I-cache, 256KB 64b/line 
8-way L2 cache, 3MB 64b/line 12-way L3 cache
cpu3: smt 1, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 40 pins
acpiec0 at acpi0
acpimcfg0 at acpi0
acpimcfg0: addr 0xe000, bus 0-155
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (PEG0)
acpiprt2 at acpi0: bus 1 (RP01)
acpiprt3 at acpi0: bus 2 (RP02)
acpiprt4 at acpi0: bus 3 (RP03)
acpiprt5 at acpi0: bus 5 (RP05)
acpiprt6 at acpi0: bus 4 (RP06)
acpisbs0 at acpi0: SBS0 model "bq20z451" serial 24593 

Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Marc Espie
On Sat, Aug 12, 2023 at 08:00:48AM +, Miod Vallat wrote:
> I have had a look at your diff and I think it's decent enough to go in
> after some polishing.
> 
> Can Wacom tablet users try this cleaned up diff?

Works on the target tablet here (Wacom Intuos S)



Re: Diff for evaluation (WACOM tablet driver)

2023-08-12 Thread Miod Vallat
I have had a look at your diff and I think it's decent enough to go in
after some polishing.

Can Wacom tablet users try this cleaned up diff?

Index: dev/hid/hid.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.c,v
retrieving revision 1.5
diff -u -p -r1.5 hid.c
--- dev/hid/hid.c   20 May 2022 05:03:45 -  1.5
+++ dev/hid/hid.c   12 Aug 2023 07:59:14 -
@@ -657,3 +657,52 @@ hid_is_collection(const void *desc, int 
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage) {
+   DPRINTF("%s: found\n", __func__);
+   hid_end_parse(hd);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return 0;
+}
Index: dev/hid/hid.h
===
RCS file: /OpenBSD/src/sys/dev/hid/hid.h,v
retrieving revision 1.10
diff -u -p -r1.10 hid.h
--- dev/hid/hid.h   20 May 2022 05:03:45 -  1.10
+++ dev/hid/hid.h   12 Aug 2023 07:59:14 -
@@ -93,6 +93,10 @@ int  hid_locate(const void *, int, int32_
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
+   uint32_t);
+inthid_get_id_of_collection(const void *desc, int size, int32_t usage, 
+   uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +357,7 @@ int hid_is_collection(const void *, int,
 #define HUD_TOUCHSCREEN0x0004
 #define HUD_TOUCHPAD   0x0005
 #define HUD_CONFIG 0x000e
+#define HUD_STYLUS 0x0020
 #define HUD_FINGER 0x0022
 #define HUD_TIP_PRESSURE   0x0030
 #define HUD_BARREL_PRESSURE0x0031
@@ -387,6 +392,12 @@ inthid_is_collection(const void *, int,
 #define HUD_CONTACT_MAX0x0055
 #define HUD_SCAN_TIME  0x0056
 #define HUD_BUTTON_TYPE0x0059
+#define HUD_SECONDARY_BARREL_SWITCH0x005A
+#define HUD_WACOM_X0x0130
+#define HUD_WACOM_Y0x0131
+#define HUD_WACOM_DISTANCE 0x0132
+#define HUD_WACOM_PAD_BUTTONS000x0910
+#define HUD_WACOM_BATTERY  0x1013
 
 /* Usages, LED */
 #define HUL_NUM_LOCK   0x0001
Index: dev/hid/hidms.c
===
RCS file: /OpenBSD/src/sys/dev/hid/hidms.c,v
retrieving revision 1.9
diff -u -p -r1.9 hidms.c
--- dev/hid/hidms.c 16 Jun 2022 20:52:38 -  1.9
+++ dev/hid/hidms.c 12 Aug 2023 07:59:14 -
@@ -61,6 +61,188 @@ int hidmsdebug = 0;
 #define MOUSE_FLAGS_MASK   (HIO_CONST | HIO_RELATIVE)
 #define NOTMOUSE(f)(((f) & MOUSE_FLAGS_MASK) != HIO_RELATIVE)
 
+void
+hidms_stylus_hid_parse(struct hidms *ms, struct hid_data *d,
+struct hid_location *loc_stylus_btn)
+{
+   struct hid_item h;
+
+   while (hid_get_item(d, )) {
+   if (h.kind == hid_endcollection)
+   break;
+   if (h.kind != hid_input || (h.flags & HIO_CONST) != 0)
+   continue;
+   /* All the possible stylus reported usages go here */
+#ifdef HIDMS_DEBUG
+   printf("stylus usage: 0x%x\n", h.usage);
+#endif
+   switch (h.usage) {
+   /* Buttons */
+   case HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, 

Re: Diff for evaluation (WACOM tablet driver)

2023-07-08 Thread Vladimir Meshcheriakov
Please allow me to explain why I have written a custom parser pour the Wacom 
devices, instead of just using the already existent one.
The function of interest to us is hidms_setup, it is here that I have a special 
condition with as has been mentioned uses a quirk.
We need it because of the following reasons:

- HUG_X and HUG_Y are not he same for a Wacom tablet, so if I don't use my 
custom parser the tablet will have neither x, nor y.

- pad buttons, which do not have the same descriptor as the regular buttons, 
and instead use HUD_WACOM_PAD_BUTTONS00, so again if used with the classical 
parser it will not recognize the buttons correctly.

More smaller differences apply too, but these are the major two points!

I hope this answer will explain why this choice was made, however if someone 
sees a better way of parsing the Wacom HID without a custom parser I would be 
glad to hear it.


Re: Diff for evaluation (WACOM tablet driver)

2023-07-05 Thread Marc Espie
On Tue, Jul 04, 2023 at 07:20:51PM -0400, Thomas Frohwein wrote:
> Thanks, I built a kernel with this and no issues observed. I have a
> Wacom Bamboo (CTH-470, product id 0x00de) that doesn't attach yet, but
> this can be left for future work. I don't see anything glaring. hid.c
> could probably use some refactoring at some point in the future because
> at least 3 functions now share 99% identical code (hid_is_collection,
> hid_get_collection_data, hid_get_id_of_collection).

Yeah, I think it's better to get this in first, try to recognize more
tablets, then see how similar the code still is and how to refactor it.

It's likely there are still monsters hiding in the wacom hw.



Re: Diff for evaluation (WACOM tablet driver)

2023-07-04 Thread Thomas Frohwein
On Mon, Jul 03, 2023 at 11:22:45AM +0200, Marc Espie wrote:
> I hope Vladimir will find the time to complete this answer.
> 
> As far as Vlad's work goes, he did a presentation last week-end:
> https://www.lre.epita.fr/news_content/SS_summer_week_pres/Vladimir_Driver_OpenBSD.pptx
> 
> (sorry for the medium, fortunately we have libreoffice)
> 
> In the mean time, here is an updated diff.
> 
> I removed the Gaomon stuff, which if anything should be a different patch.
> 
> And I cleaned up the 20+ minor style violations I could find...
> (tabs instead of +4 spaces for continued lines, a few non-style compliant
> function declarations and/or code blocks, oh well)
> 
> plus an extra malloc.h that snuck in and is not at all needed.
> 
> And some typos in comments.
> And a C++ style comment. Oh well
> 
> I would really for some version of this to get in soonish.
> I can vouch that my tablet "works" with it (well, as good as it can work
> within the limitations of wscons not allowing it to be easily differentiated
> from the normal mouse, which is really a pain for programs like gimp)

Thanks, I built a kernel with this and no issues observed. I have a
Wacom Bamboo (CTH-470, product id 0x00de) that doesn't attach yet, but
this can be left for future work. I don't see anything glaring. hid.c
could probably use some refactoring at some point in the future because
at least 3 functions now share 99% identical code (hid_is_collection,
hid_get_collection_data, hid_get_id_of_collection).

I recommend getting an ok from someone with more track record with
dev/hid and/or dev/usb, but from my side this is ok thfr@.

> 
> dmesg for the tablet with the diff
> | uhidev1 at uhub1 port 4 configuration 1 interface 0 "Wacom Co.,Ltd. Intuos 
> S" rev 2.00/1.07 addr 6
> | uhidev1: iclass 3/0, 228 report ids
> | uwacom0 at uhidev1: 9 buttons, Z and W dir, tip, barrel
> | wsmouse5 at uwacom0 mux 0
> | uwacom1 at uhidev1: 9 buttons, Z and W dir, tip, barrel
> | wsmouse6 at uwacom1 mux 0
> | uwacom2 at uhidev1: 9 buttons, Z and W dir, tip, barrel
> | wsmouse7 at uwacom2 mux 0
> 
> as far as I understand, it appears as several mice because the stylus
> acts as totally different devices depending on the mode/end used
> (stuff that wscons completely hides from us).
> 
> Without the patch, that tablet appears as 42 different uhid devices (!)
> 
> The idea is that the parser for collections was really primitive. The
> debug stuff can show the details of various collection. There is the actual
> tablet mechanisms (which becomes one device) including scale, stylus, etc,
> and some other wacky collections (!): a debug collection that the wacom guys
> told us "oh some of our hw team needs that, but don't ever touch" and
> some other stuff we can't support yet (like battery support for some
> advanced models of stylus)
> 
> Index: dev/hid/hid.c
> ===
> RCS file: /cvs/src/sys/dev/hid/hid.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 hid.c
> --- dev/hid/hid.c 20 May 2022 05:03:45 -  1.5
> +++ dev/hid/hid.c 3 Jul 2023 09:04:50 -
> @@ -657,3 +657,51 @@ hid_is_collection(const void *desc, int 
>   hid_end_parse(hd);
>   return (0);
>  }
> +
> +struct hid_data *
> +hid_get_collection_data(const void *desc, int size, int32_t usage,
> +uint32_t collection)
> +{
> + struct hid_data *hd;
> + struct hid_item hi;
> +
> + hd = hid_start_parse(desc, size, hid_all);
> +
> + DPRINTF("%s: usage=0x%x\n", __func__, usage);
> + while (hid_get_item(hd, )) {
> + DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
> + hi.kind, hi.report_ID, hi.usage, usage);
> + if (hi.kind == hid_collection &&
> + hi.collection == collection && hi.usage == usage){
> + DPRINTF("%s: found\n", __func__);
> + return hd;
> + }
> + }
> + DPRINTF("%s: not found\n", __func__);
> + hid_end_parse(hd);
> + return NULL;
> +}
> +
> +int
> +hid_get_id_of_collection(const void *desc, int size, int32_t usage,
> +uint32_t collection)
> +{
> + struct hid_data *hd;
> + struct hid_item hi;
> +
> + hd = hid_start_parse(desc, size, hid_all);
> +
> + DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
> + while (hid_get_item(hd, )) {
> + DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
> + hi.kind, hi.report_ID, hi.usage, usage);
> + if (hi.kind == hid_collection &&
> + hi.collection == collection && hi.usage == usage){
> + DPRINTF("%s: found\n", __func__);
> + return hi.report_ID;
> + }
> + }
> + DPRINTF("%s: not found\n", __func__);
> + hid_end_parse(hd);
> + return 0;
> +}
> Index: dev/hid/hid.h
> ===
> RCS file: 

Re: Diff for evaluation (WACOM tablet driver)

2023-07-03 Thread Marc Espie
On Mon, Jul 03, 2023 at 03:20:33PM +0300, Matthieu Herrb wrote:
> > Index: dev/usb/usbdevs.h
> > ===
> > RCS file: /cvs/src/sys/dev/usb/usbdevs.h,v
> > retrieving revision 1.769
> > diff -u -p -r1.769 usbdevs.h
> > --- dev/usb/usbdevs.h   12 Jun 2023 11:26:54 -  1.769
> > +++ dev/usb/usbdevs.h   3 Jul 2023 09:04:50 -
> > @@ -1,4 +1,4 @@
> > -/* $OpenBSD: usbdevs.h,v 1.769 2023/06/12 11:26:54 jsg Exp $   */
> > +/* $OpenBSD$   */
> >  
> >  /*
> >   * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
> > @@ -2117,6 +2117,8 @@
> >  #defineUSB_PRODUCT_GARMIN_DAKOTA20 0x23c0  /* Dakota 20 */
> >  #defineUSB_PRODUCT_GARMIN_GPSMAP62S0x2459  /* GPSmap 62s */
> >  
> > +/* Gaomon */
> > +
> 
> Strange... looks like you edited the file instead of re-generating it.

Nah, I just forgot to re-regenerate after removing the Gaomon comment ;)

Since the commit has to be staged in twos, that's not a bother



Re: Diff for evaluation (WACOM tablet driver)

2023-07-03 Thread Matthieu Herrb
On Mon, Jul 03, 2023 at 11:22:45AM +0200, Marc Espie wrote:
> I hope Vladimir will find the time to complete this answer.
> 
> As far as Vlad's work goes, he did a presentation last week-end:
> https://www.lre.epita.fr/news_content/SS_summer_week_pres/Vladimir_Driver_OpenBSD.pptx
> 
> (sorry for the medium, fortunately we have libreoffice)
> 
> In the mean time, here is an updated diff.
> 
> I removed the Gaomon stuff, which if anything should be a different patch.
> 
> And I cleaned up the 20+ minor style violations I could find...
> (tabs instead of +4 spaces for continued lines, a few non-style compliant
> function declarations and/or code blocks, oh well)
> 
> plus an extra malloc.h that snuck in and is not at all needed.
> 
> And some typos in comments.
> And a C++ style comment. Oh well
> 
> I would really for some version of this to get in soonish.

A few nits below.
I can't really comment on the HID parser logic although I find it a
bit strange to need quirk to attach uwacom.

> Index: dev/hid/hidms.c
> ===
> RCS file: /cvs/src/sys/dev/hid/hidms.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 hidms.c
> --- dev/hid/hidms.c   16 Jun 2022 20:52:38 -  1.9
> +++ dev/hid/hidms.c   3 Jul 2023 09:04:50 -
> @@ -61,6 +61,210 @@ int   hidmsdebug = 0;
>  #define MOUSE_FLAGS_MASK (HIO_CONST | HIO_RELATIVE)
>  #define NOTMOUSE(f)  (((f) & MOUSE_FLAGS_MASK) != HIO_RELATIVE)
>  
> +
> +int
> +stylus_hid_parse(struct hidms *ms, struct hid_data *d, uint32_t *flags) 
> +{
> + /* Define stylus reported usages: (maybe macros?) */
> + const uint32_t stylus_usage_tip
> + = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_TIP_SWITCH);
> + const uint32_t stylus_usage_barrel
> + = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_BARREL_SWITCH);
> + const uint32_t stylus_usage_sec_barrel = HID_USAGE2(
> + HUP_WACOM | HUP_DIGITIZERS, HUD_SECONDARY_BARREL_SWITCH);
> + const uint32_t stylus_usage_in_range
> + = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_IN_RANGE);
> + const uint32_t stylus_usage_quality
> + = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_QUALITY);
> + const uint32_t stylus_usage_x
> + = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_WACOM_X);
> + const uint32_t stylus_usage_y
> + = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_WACOM_Y);
> + const uint32_t stylus_usage_pressure
> + = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_TIP_PRESSURE);
> + const uint32_t stylus_usage_distance
> + = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_WACOM_DISTANCE);
> + 
> + struct hid_item h;
> +
> + while (hid_get_item(d, )) {
> + if (h.kind == hid_input && !(h.flags & HIO_CONST)) {
> + /* All the possible stylus reported usages go here */
> +#ifdef HIDMS_DEBUG
> + printf("stylus usage: 0x%x\n", h.usage);
> +#endif
> + switch (h.usage) {
> + /* Buttons */
> + case stylus_usage_tip:
> + DPRINTF("Stylus usage tip set\n");
> + ms->sc_loc_stylus_btn
> + [ms->sc_num_stylus_buttons++] = h.loc;
> + ms->sc_flags |= HIDMS_TIP;
> + break;
> + case stylus_usage_barrel:
> + DPRINTF("Stylus usage barrel set\n");
> + ms->sc_loc_stylus_btn
> + [ms->sc_num_stylus_buttons++] = h.loc;
> + ms->sc_flags |= HIDMS_BARREL;
> + break;
> + case stylus_usage_sec_barrel:
> + DPRINTF("Stylus usage secondary barrel set\n");
> + ms->sc_loc_stylus_btn
> + [ms->sc_num_stylus_buttons++] = h.loc;
> + ms->sc_flags |= HIDMS_SEC_BARREL;
> + break;
> + case stylus_usage_in_range:
> + DPRINTF("Stylus usage in range set\n");
> + ms->sc_loc_stylus_btn
> + [ms->sc_num_stylus_buttons++] = h.loc;
> + break;
> + case stylus_usage_quality:
> + DPRINTF("Stylus usage quality set\n");
> + ms->sc_loc_stylus_btn
> + [ms->sc_num_stylus_buttons++] = h.loc;
> + break;
> + /* Axes */
> + case stylus_usage_x:
> + DPRINTF("Stylus usage x set\n");
> + ms->sc_loc_x = h.loc;
> + 

Re: Diff for evaluation (WACOM tablet driver)

2023-07-03 Thread Marc Espie
I hope Vladimir will find the time to complete this answer.

As far as Vlad's work goes, he did a presentation last week-end:
https://www.lre.epita.fr/news_content/SS_summer_week_pres/Vladimir_Driver_OpenBSD.pptx

(sorry for the medium, fortunately we have libreoffice)

In the mean time, here is an updated diff.

I removed the Gaomon stuff, which if anything should be a different patch.

And I cleaned up the 20+ minor style violations I could find...
(tabs instead of +4 spaces for continued lines, a few non-style compliant
function declarations and/or code blocks, oh well)

plus an extra malloc.h that snuck in and is not at all needed.

And some typos in comments.
And a C++ style comment. Oh well

I would really for some version of this to get in soonish.
I can vouch that my tablet "works" with it (well, as good as it can work
within the limitations of wscons not allowing it to be easily differentiated
from the normal mouse, which is really a pain for programs like gimp)

dmesg for the tablet with the diff
| uhidev1 at uhub1 port 4 configuration 1 interface 0 "Wacom Co.,Ltd. Intuos S" 
rev 2.00/1.07 addr 6
| uhidev1: iclass 3/0, 228 report ids
| uwacom0 at uhidev1: 9 buttons, Z and W dir, tip, barrel
| wsmouse5 at uwacom0 mux 0
| uwacom1 at uhidev1: 9 buttons, Z and W dir, tip, barrel
| wsmouse6 at uwacom1 mux 0
| uwacom2 at uhidev1: 9 buttons, Z and W dir, tip, barrel
| wsmouse7 at uwacom2 mux 0

as far as I understand, it appears as several mice because the stylus
acts as totally different devices depending on the mode/end used
(stuff that wscons completely hides from us).

Without the patch, that tablet appears as 42 different uhid devices (!)

The idea is that the parser for collections was really primitive. The
debug stuff can show the details of various collection. There is the actual
tablet mechanisms (which becomes one device) including scale, stylus, etc,
and some other wacky collections (!): a debug collection that the wacom guys
told us "oh some of our hw team needs that, but don't ever touch" and
some other stuff we can't support yet (like battery support for some
advanced models of stylus)

Index: dev/hid/hid.c
===
RCS file: /cvs/src/sys/dev/hid/hid.c,v
retrieving revision 1.5
diff -u -p -r1.5 hid.c
--- dev/hid/hid.c   20 May 2022 05:03:45 -  1.5
+++ dev/hid/hid.c   3 Jul 2023 09:04:50 -
@@ -657,3 +657,51 @@ hid_is_collection(const void *desc, int 
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage){
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage,
+uint32_t collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage){
+   DPRINTF("%s: found\n", __func__);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return 0;
+}
Index: dev/hid/hid.h
===
RCS file: /cvs/src/sys/dev/hid/hid.h,v
retrieving revision 1.10
diff -u -p -r1.10 hid.h
--- dev/hid/hid.h   20 May 2022 05:03:45 -  1.10
+++ dev/hid/hid.h   3 Jul 2023 09:04:50 -
@@ -93,6 +93,10 @@ int  hid_locate(const void *, int, int32_
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
+   uint32_t);
+inthid_get_id_of_collection(const void *desc, int size, int32_t usage, 
+   uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +357,7 @@ int 

Re: Diff for evaluation (WACOM tablet driver)

2023-06-30 Thread dsp
On Sun, Jun 18, 2023 at 09:36:25AM +, Vladimir Meshcheriakov wrote:
> Good day,
> 
> I am currently trying to work on an implementation
> of a driver for the WACOM tablet on openBSD
> I am therefore submitting this diff so that it could potentially be evaluated.
> Please if you have a moment, could you have a look at this diff?
> I have tested it with my Wacom tablet
> and it seems to work correctly,
> the coding style is normally respected,
> but I apologize in advance if my keen eyes have missed out something.

Hi there! i tested the diff with a wacom intuos s
(CS-4100). It attaches sucessfully 

uhidev1 at uhub1 port 1 configuration 1 interface 0 "Wacom Co.,Ltd. Intuos S" 
rev 2.00/1.11 addr 5
uhidev1: iclass 3/0, 228 report ids
uwacom0 at uhidev1: 9 buttons, Z and W dir, tip, barrel
wsmouse3 at uwacom0 mux 0
uwacom1 at uhidev1: 9 buttons, Z and W dir, tip, barrel
wsmouse4 at uwacom1 mux 0
uwacom2 at uhidev1: 9 buttons, Z and W dir, tip, barrel
wsmouse5 at uwacom2 mux 0

I don't have any of the previous wacom products to see
if they still work. One thing i am trying to do is 
to somehow scale the tablet so that it is actually
usable. I looked a bit into running xtsscale 
but it outputs

xtsscale -v -d /dev/wsmouse1
XRandR extension version 1.6 present
Unable to find the "WS Pointer Axis Calibration" device property.
There are probably no calibrable devices on this system.

Finally in the patch it seems there is another rogue
usbdevs entry (a GAOMON M10k device). 

Thanks for taking the time to write this.
 
> 
> diff --git a/sys/dev/hid/hid.c b/sys/dev/hid/hid.c
> index c758764f17a..20c0c501e91 100644
> --- a/sys/dev/hid/hid.c
> +++ b/sys/dev/hid/hid.c
> @@ -657,3 +657,49 @@ hid_is_collection(const void *desc, int size, uint8_t 
> id, int32_t usage)
>   hid_end_parse(hd);
>   return (0);
>  }
> +
> +struct hid_data *
> +hid_get_collection_data(const void *desc, int size, int32_t usage, uint32_t 
> collection)
> +{
> + struct hid_data *hd;
> + struct hid_item hi;
> +
> + hd = hid_start_parse(desc, size, hid_all);
> +
> + DPRINTF("%s: usage=0x%x\n", __func__, usage);
> + while (hid_get_item(hd, )) {
> + DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
> + hi.kind, hi.report_ID, hi.usage, usage);
> + if (hi.kind == hid_collection &&
> + hi.collection == collection && hi.usage == usage){
> + DPRINTF("%s: found\n", __func__);
> + return hd;
> + }
> + }
> + DPRINTF("%s: not found\n", __func__);
> + hid_end_parse(hd);
> + return NULL;
> +}
> +
> +int
> +hid_get_id_of_collection(const void *desc, int size, int32_t usage, uint32_t 
> collection)
> +{
> + struct hid_data *hd;
> + struct hid_item hi;
> +
> + hd = hid_start_parse(desc, size, hid_all);
> +
> + DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
> + while (hid_get_item(hd, )) {
> + DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
> + hi.kind, hi.report_ID, hi.usage, usage);
> + if (hi.kind == hid_collection &&
> + hi.collection == collection && hi.usage == usage){
> + DPRINTF("%s: found\n", __func__);
> + return hi.report_ID;
> + }
> + }
> + DPRINTF("%s: not found\n", __func__);
> + hid_end_parse(hd);
> + return 0;
> +}
> diff --git a/sys/dev/hid/hid.h b/sys/dev/hid/hid.h
> index 7400e920bc2..78bc4c403c5 100644
> --- a/sys/dev/hid/hid.h
> +++ b/sys/dev/hid/hid.h
> @@ -93,6 +93,8 @@ int hid_locate(const void *, int, int32_t, uint8_t, enum 
> hid_kind,
>  int32_t  hid_get_data(const uint8_t *buf, int, struct hid_location *);
>  uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
>  int  hid_is_collection(const void *, int, uint8_t, int32_t);
> +struct hid_data *hid_get_collection_data(const void *, int, int32_t, 
> uint32_t);
> +int hid_get_id_of_collection(const void *desc, int size, int32_t usage, 
> uint32_t collection);
>  
>  #endif /* _KERNEL */
>  
> @@ -353,6 +355,7 @@ int   hid_is_collection(const void *, int, uint8_t, 
> int32_t);
>  #define HUD_TOUCHSCREEN  0x0004
>  #define HUD_TOUCHPAD 0x0005
>  #define HUD_CONFIG   0x000e
> +#define HUD_STYLUS   0x0020
>  #define HUD_FINGER   0x0022
>  #define HUD_TIP_PRESSURE 0x0030
>  #define HUD_BARREL_PRESSURE  0x0031
> @@ -387,6 +390,12 @@ int  hid_is_collection(const void *, int, uint8_t, 
> int32_t);
>  #define HUD_CONTACT_MAX  0x0055
>  #define HUD_SCAN_TIME0x0056
>  #define HUD_BUTTON_TYPE  0x0059
> +#define HUD_SECONDARY_BARREL_SWITCH  0x005A
> +#define HUD_WACOM_X  0x0130
> +#define HUD_WACOM_Y  0x0131
> +#define HUD_WACOM_DISTANCE   0x0132
> +#define HUD_WACOM_PAD_BUTTONS00  0x0910
> +#define 

Re: Diff for evaluation (WACOM tablet driver)

2023-06-19 Thread Matthieu Herrb
On Sun, Jun 18, 2023 at 09:36:25AM +, Vladimir Meshcheriakov wrote:
> Good day,
> 
> I am currently trying to work on an implementation
> of a driver for the WACOM tablet on openBSD
> I am therefore submitting this diff so that it could potentially be evaluated.
> Please if you have a moment, could you have a look at this diff?
> I have tested it with my Wacom tablet
> and it seems to work correctly,
> the coding style is normally respected,
> but I apologize in advance if my keen eyes have missed out
> something.

Hi,

I have some interest in your diff, unfortunatly I can't really comment
on the code itself because it's a bit outside of my expertize area.

I do have a Wacom Bamboo tablet (00d8), but it's not recognized by
uwacom(4), with or without your patch. I've tried to add its USB id to
uwacom_devs[], but no luck, uwacom_match() fails because
UHIDEV_CLAIM_MULTIPLE_REPORTID(uha) is true for this device.

It would be nice for other reviwers if you could describe the issues
you found in the current code, and what your change do appart from
adding support for some models. Owners of devices already supported by
uwacom(4) could then check if their device still work or benifit from
the enhancements in you code. 

Appart from this, there are a few KNF issues in you code, for instance
CPP directives (#if & such) should be on column 0.

Hope this helps,

> 
> diff --git a/sys/dev/hid/hid.c b/sys/dev/hid/hid.c
> index c758764f17a..20c0c501e91 100644
> --- a/sys/dev/hid/hid.c
> +++ b/sys/dev/hid/hid.c
> @@ -657,3 +657,49 @@ hid_is_collection(const void *desc, int size, uint8_t 
> id, int32_t usage)
>   hid_end_parse(hd);
>   return (0);
>  }
> +
> +struct hid_data *
> +hid_get_collection_data(const void *desc, int size, int32_t usage, uint32_t 
> collection)
> +{
> + struct hid_data *hd;
> + struct hid_item hi;
> +
> + hd = hid_start_parse(desc, size, hid_all);
> +
> + DPRINTF("%s: usage=0x%x\n", __func__, usage);
> + while (hid_get_item(hd, )) {
> + DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
> + hi.kind, hi.report_ID, hi.usage, usage);
> + if (hi.kind == hid_collection &&
> + hi.collection == collection && hi.usage == usage){
> + DPRINTF("%s: found\n", __func__);
> + return hd;
> + }
> + }
> + DPRINTF("%s: not found\n", __func__);
> + hid_end_parse(hd);
> + return NULL;
> +}
> +
> +int
> +hid_get_id_of_collection(const void *desc, int size, int32_t usage, uint32_t 
> collection)
> +{
> + struct hid_data *hd;
> + struct hid_item hi;
> +
> + hd = hid_start_parse(desc, size, hid_all);
> +
> + DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
> + while (hid_get_item(hd, )) {
> + DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
> + hi.kind, hi.report_ID, hi.usage, usage);
> + if (hi.kind == hid_collection &&
> + hi.collection == collection && hi.usage == usage){
> + DPRINTF("%s: found\n", __func__);
> + return hi.report_ID;
> + }
> + }
> + DPRINTF("%s: not found\n", __func__);
> + hid_end_parse(hd);
> + return 0;
> +}
> diff --git a/sys/dev/hid/hid.h b/sys/dev/hid/hid.h
> index 7400e920bc2..78bc4c403c5 100644
> --- a/sys/dev/hid/hid.h
> +++ b/sys/dev/hid/hid.h
> @@ -93,6 +93,8 @@ int hid_locate(const void *, int, int32_t, uint8_t, enum 
> hid_kind,
>  int32_t  hid_get_data(const uint8_t *buf, int, struct hid_location *);
>  uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
>  int  hid_is_collection(const void *, int, uint8_t, int32_t);
> +struct hid_data *hid_get_collection_data(const void *, int, int32_t, 
> uint32_t);
> +int hid_get_id_of_collection(const void *desc, int size, int32_t usage, 
> uint32_t collection);
>  
>  #endif /* _KERNEL */
>  
> @@ -353,6 +355,7 @@ int   hid_is_collection(const void *, int, uint8_t, 
> int32_t);
>  #define HUD_TOUCHSCREEN  0x0004
>  #define HUD_TOUCHPAD 0x0005
>  #define HUD_CONFIG   0x000e
> +#define HUD_STYLUS   0x0020
>  #define HUD_FINGER   0x0022
>  #define HUD_TIP_PRESSURE 0x0030
>  #define HUD_BARREL_PRESSURE  0x0031
> @@ -387,6 +390,12 @@ int  hid_is_collection(const void *, int, uint8_t, 
> int32_t);
>  #define HUD_CONTACT_MAX  0x0055
>  #define HUD_SCAN_TIME0x0056
>  #define HUD_BUTTON_TYPE  0x0059
> +#define HUD_SECONDARY_BARREL_SWITCH  0x005A
> +#define HUD_WACOM_X  0x0130
> +#define HUD_WACOM_Y  0x0131
> +#define HUD_WACOM_DISTANCE   0x0132
> +#define HUD_WACOM_PAD_BUTTONS00  0x0910
> +#define HUD_WACOM_BATTERY0x1013
>  
>  /* Usages, LED */
>  #define HUL_NUM_LOCK 0x0001
> diff --git a/sys/dev/hid/hidms.c b/sys/dev/hid/hidms.c
> index 

Diff for evaluation (WACOM tablet driver)

2023-06-18 Thread Vladimir Meshcheriakov
Good day,

I am currently trying to work on an implementation
of a driver for the WACOM tablet on openBSD
I am therefore submitting this diff so that it could potentially be evaluated.
Please if you have a moment, could you have a look at this diff?
I have tested it with my Wacom tablet
and it seems to work correctly,
the coding style is normally respected,
but I apologize in advance if my keen eyes have missed out something.

diff --git a/sys/dev/hid/hid.c b/sys/dev/hid/hid.c
index c758764f17a..20c0c501e91 100644
--- a/sys/dev/hid/hid.c
+++ b/sys/dev/hid/hid.c
@@ -657,3 +657,49 @@ hid_is_collection(const void *desc, int size, uint8_t id, 
int32_t usage)
hid_end_parse(hd);
return (0);
 }
+
+struct hid_data *
+hid_get_collection_data(const void *desc, int size, int32_t usage, uint32_t 
collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: usage=0x%x\n", __func__, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage){
+   DPRINTF("%s: found\n", __func__);
+   return hd;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return NULL;
+}
+
+int
+hid_get_id_of_collection(const void *desc, int size, int32_t usage, uint32_t 
collection)
+{
+   struct hid_data *hd;
+   struct hid_item hi;
+
+   hd = hid_start_parse(desc, size, hid_all);
+
+   DPRINTF("%s: id=%d usage=0x%x\n", __func__, id, usage);
+   while (hid_get_item(hd, )) {
+   DPRINTF("%s: kind=%d id=%d usage=0x%x(0x%x)\n", __func__,
+   hi.kind, hi.report_ID, hi.usage, usage);
+   if (hi.kind == hid_collection &&
+   hi.collection == collection && hi.usage == usage){
+   DPRINTF("%s: found\n", __func__);
+   return hi.report_ID;
+   }
+   }
+   DPRINTF("%s: not found\n", __func__);
+   hid_end_parse(hd);
+   return 0;
+}
diff --git a/sys/dev/hid/hid.h b/sys/dev/hid/hid.h
index 7400e920bc2..78bc4c403c5 100644
--- a/sys/dev/hid/hid.h
+++ b/sys/dev/hid/hid.h
@@ -93,6 +93,8 @@ int   hid_locate(const void *, int, int32_t, uint8_t, enum 
hid_kind,
 int32_thid_get_data(const uint8_t *buf, int, struct hid_location *);
 uint32_t hid_get_udata(const uint8_t *buf, int, struct hid_location *);
 inthid_is_collection(const void *, int, uint8_t, int32_t);
+struct hid_data *  hid_get_collection_data(const void *, int, int32_t, 
uint32_t);
+int hid_get_id_of_collection(const void *desc, int size, int32_t usage, 
uint32_t collection);
 
 #endif /* _KERNEL */
 
@@ -353,6 +355,7 @@ int hid_is_collection(const void *, int, uint8_t, int32_t);
 #define HUD_TOUCHSCREEN0x0004
 #define HUD_TOUCHPAD   0x0005
 #define HUD_CONFIG 0x000e
+#define HUD_STYLUS 0x0020
 #define HUD_FINGER 0x0022
 #define HUD_TIP_PRESSURE   0x0030
 #define HUD_BARREL_PRESSURE0x0031
@@ -387,6 +390,12 @@ inthid_is_collection(const void *, int, uint8_t, 
int32_t);
 #define HUD_CONTACT_MAX0x0055
 #define HUD_SCAN_TIME  0x0056
 #define HUD_BUTTON_TYPE0x0059
+#define HUD_SECONDARY_BARREL_SWITCH0x005A
+#define HUD_WACOM_X0x0130
+#define HUD_WACOM_Y0x0131
+#define HUD_WACOM_DISTANCE 0x0132
+#define HUD_WACOM_PAD_BUTTONS000x0910
+#define HUD_WACOM_BATTERY  0x1013
 
 /* Usages, LED */
 #define HUL_NUM_LOCK   0x0001
diff --git a/sys/dev/hid/hidms.c b/sys/dev/hid/hidms.c
index 622d5d9bc33..ec5c8d34d1b 100644
--- a/sys/dev/hid/hidms.c
+++ b/sys/dev/hid/hidms.c
@@ -37,6 +37,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -61,6 +62,219 @@ int hidmsdebug = 0;
 #define MOUSE_FLAGS_MASK   (HIO_CONST | HIO_RELATIVE)
 #define NOTMOUSE(f)(((f) & MOUSE_FLAGS_MASK) != HIO_RELATIVE)
 
+
+int
+stylus_hid_parse(struct hidms *ms, struct hid_data *d, uint32_t *flags) {
+   /* Define stylus reported usages: (maybe macros?) */
+   const uint32_t stylus_usage_tip
+   = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_TIP_SWITCH);
+   const uint32_t stylus_usage_barrel
+   = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_BARREL_SWITCH);
+   const uint32_t stylus_usage_sec_barrel = HID_USAGE2(
+   HUP_WACOM | HUP_DIGITIZERS, HUD_SECONDARY_BARREL_SWITCH);
+   const uint32_t stylus_usage_in_range
+   = HID_USAGE2(HUP_WACOM | HUP_DIGITIZERS, HUD_IN_RANGE);
+   const uint32_t stylus_usage_quality
+   =