drivers/hid/bpf/progs/hid_report_helpers.h

Source file repositories/reference/linux-study-clean/drivers/hid/bpf/progs/hid_report_helpers.h

File Facts

System
Linux kernel
Corpus path
drivers/hid/bpf/progs/hid_report_helpers.h
Extension
.h
Size
203794 bytes
Lines
2983
Domain
Driver Families
Bucket
drivers/hid
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// THIS FILE IS GENERATED, DO NOT EDIT

#pragma once


/* Macros for composing HID reports.
 *
 * HID Fields are added manually to the template, please add to it as needed
 * for any individual device. The Usage Pages and Usages are generated.
 *
 * Some macros have a _i8, _i16, or _i32 suffix. Pick the
 * right suffix given the passed-in value.
 */

/*
 * This macro behaves like static_assert(), failing to
 * compile if its argument is not true.  However, it always
 * returns 0, which allows using it everywhere an expression
 * can be used.
 */
#define must_be(e, msg_)						\
(									\
	0 * (int) sizeof(						\
		struct {						\
			_Static_assert(e, msg_);			\
			int  ISO_C_forbids_a_struct_with_no_members;	\
		}							\
	)								\
)

/* Ensure the given value fits within 8/16/32 bits */
#define i4(v_)  (((__u8)(v_) & 0xf)  + must_be((v_) >= -0x8 && (v_) <= 0x7, "not a i4"))
#define i8(v_)  ((__u8)(v_)  + must_be((v_) >= -0x80 && (v_) <= 0xff, "not a i8/u8"))
#define i16(v_) ((__u16)(v_) + must_be((v_) >= -0x8000 && (v_) <= 0xffff, "not a i16/u16"))
#define i32(v_) ((__u32)(v_) + must_be((v_) >= -0x80000000L && (v_) <= 0xffffffffL, \
				       "not a i32/u16"))

/* Split a value across multiple bytes in LE order */
#define LE16(v_) i16(v_) & 0xff, ((v_) >> 8) & 0xff
#define LE32(v_) i32(v_) & 0xff, ((v_) >> 8) & 0xff, ((v_) >> 16) & 0xff, ((v_) >> 24) & 0xff

/* Collections require two items in the report descriptor, the start
 * of the collection (0xa?) and the EndCollection item (0xc?).
 * This macro provides both, use like this:
 *
 * static const __u8 fixed_rdesc[] = {
 *     UsagePage_Generic_Desktop
 *     Usage_GD_Keyboard
 *     CollectionApplication(     ← Open the collection
 *         ReportId(3)
 *         LogicalMinimum_i8(0)
 *         LogicalMaximum_i8(1)
 *         // other fields
 *     )                          ← End EndCollection
 *
 * Collections may be nested.
 */
#define Collection(col_, ...)		0xa1, i8(col_), __VA_ARGS__ 0xc0,
#define CollectionPhysical(...)		Collection(0x00, __VA_ARGS__)
#define CollectionApplication(...)	Collection(0x01, __VA_ARGS__)
#define CollectionLogical(...)		Collection(0x02, __VA_ARGS__)

/* See Collections, this macro provides Push and Pop with
 * elements in between
 */
#define PushPop(...)			0xa4, __VA_ARGS__ 0xb4,

/* Arguments to use in bitwise-or for Input, Output, Feature */
#define Const		0x1
#define Var		0x2
#define Arr		0x0
#define Abs		0x0
#define Rel		0x4
#define Null		0x40
#define Buff		0x0100

/* Use like this: Input(Var|Abs) */
#define Input(i_)			0x081, i8(i_),
#define Output(i_)			0x091, i8(i_),
#define Feature(i_)			0x0b1, i8(i_),

#define Input_i16(i_)			0x082, LE16(i_),
#define Output_i16(i_)			0x092, LE16(i_),
#define Feature_i16(i_)			0x0b2, LE16(i_),

#define ReportId(id_)			0x85, i8(id_),
#define ReportSize(sz_)		        0x75, i8(sz_),
#define ReportCount(cnt_)		0x95, i8(cnt_),

#define LogicalMinimum_i8(min_)		0x15, i8(min_),

Annotation

Implementation Notes