HID: bpf: Add a HID report composition helper macros
authorBenjamin Tissoires <bentiss@kernel.org>
Thu, 27 Jun 2024 09:54:17 +0000 (11:54 +0200)
committerBenjamin Tissoires <bentiss@kernel.org>
Mon, 1 Jul 2024 12:48:18 +0000 (14:48 +0200)
commit8a89db51873ca574de45b25fce68103f34266459
tree950d448761d56272fceb7d76bd76ddcf87d9f6a4
parentc79de517a226b86419a5baa867e65e3f8118829f
HID: bpf: Add a HID report composition helper macros

These macros make it slightly easier and more modular to create
a HID report descriptor from scratch. Since they carry the annotation
we don't need to comment it and they cannot get stale.

For comparison, before we had this:

        0x15, 0x00,                    //   Logical Minimum (0)
        0x25, 0x01,                    //   Logical Maximum (1)
        0x95, 0x04,                    //   Report Count (4)
        0x75, 0x01,                    //   Report Size (1)

Now we can write this as:
        LogicalRange_i8(0, 1)
        ReportCount(4)
        ReportSize(1)

Because these macros are for creating new report descriptors,
some bits aren't directly exposed. e.g in the example above:
there is a logical range as one macro that sets both min and max.
There is seldom a good use case for skipping either anyway.

These macros will need to be expanded over time.

For Usage Pages and Usage IDs, we use a tool to parse the HUT JSON
(attached to the HUT 1.5 PDF [1]) and generate all #defines for all
usage pages and usages in the form:

 #define UsagePage_Foo_Bar
 #define Usage_FB_SomeOrOther

Where the FB is simply the acronym based on the capital letters in the
Usage Page name or the first three letters, whichever makes slightly
more sense.

[1] https://usb.org/document-library/hid-usage-tables-15

Link: https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/-/merge_requests/92
Link: https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/-/merge_requests/96
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Link: https://patch.msgid.link/20240627-import-bpf-v1-1-0dbcda4a5b1f@kernel.org
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
drivers/hid/bpf/progs/hid_report_helpers.h [new file with mode: 0644]