drivers/hid/bpf/progs/hid_bpf_async.h
Source file repositories/reference/linux-study-clean/drivers/hid/bpf/progs/hid_bpf_async.h
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/bpf/progs/hid_bpf_async.h- Extension
.h- Size
- 5314 bytes
- Lines
- 220
- 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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct hid_bpf_async_map_elemenum hid_bpf_async_statefunction __start_wq_timer_cbfunction hid_bpf_async_find_empty_keyfunction bpf_forfunction hid_bpf_async_get_ctxfunction ms_to_nsfunction hid_bpf_async_delayed_callfunction hid_bpf_async_call
Annotated Snippet
struct hid_bpf_async_map_elem {
struct bpf_spin_lock lock;
enum hid_bpf_async_state state;
struct bpf_timer t;
struct bpf_wq wq;
u32 hid;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, HID_BPF_ASYNC_MAX_CTX);
__type(key, u32);
__type(value, struct hid_bpf_async_map_elem);
} hid_bpf_async_ctx_map SEC(".maps");
/**
* HID_BPF_ASYNC_CB: macro to define an async callback used in a bpf_wq
*
* The caller is responsible for allocating a key in the async map
* with hid_bpf_async_get_ctx().
*/
#define HID_BPF_ASYNC_CB(cb) \
cb(void *map, int *key, void *value); \
static __always_inline int \
____##cb(struct hid_bpf_ctx *ctx); \
typeof(cb(0, 0, 0)) cb(void *map, int *key, void *value) \
{ \
struct hid_bpf_async_map_elem *e; \
struct hid_bpf_ctx *ctx; \
\
e = (struct hid_bpf_async_map_elem *)value; \
ctx = hid_bpf_allocate_context(e->hid); \
if (!ctx) \
return 0; /* EPERM check */ \
\
e->state = HID_BPF_ASYNC_STATE_RUNNING; \
\
____##cb(ctx); \
\
e->state = HID_BPF_ASYNC_STATE_INITIALIZED; \
hid_bpf_release_context(ctx); \
return 0; \
} \
static __always_inline int \
____##cb
/**
* ASYNC: macro to automatically handle async callbacks contexts
*
* Needs to be used in conjunction with HID_BPF_ASYNC_INIT and HID_BPF_ASYNC_DELAYED_CALL
*/
#define HID_BPF_ASYNC_FUN(fun) \
fun(struct hid_bpf_ctx *ctx); \
int ____key__##fun; \
static int ____async_init_##fun(void) \
{ \
____key__##fun = hid_bpf_async_get_ctx(); \
if (____key__##fun < 0) \
return ____key__##fun; \
return 0; \
} \
static int HID_BPF_ASYNC_CB(____##fun##_cb)(struct hid_bpf_ctx *hctx) \
{ \
return fun(hctx); \
} \
typeof(fun(0)) fun
#define HID_BPF_ASYNC_INIT(fun) ____async_init_##fun()
#define HID_BPF_ASYNC_DELAYED_CALL(fun, ctx, delay) \
hid_bpf_async_delayed_call(ctx, delay, ____key__##fun, ____##fun##_cb)
/*
* internal cb for starting the delayed work callback in a workqueue.
*/
static int __start_wq_timer_cb(void *map, int *key, void *value)
{
struct hid_bpf_async_map_elem *e = (struct hid_bpf_async_map_elem *)value;
bpf_wq_start(&e->wq, 0);
return 0;
}
static int hid_bpf_async_find_empty_key(void)
{
int i;
bpf_for(i, 0, HID_BPF_ASYNC_MAX_CTX) {
struct hid_bpf_async_map_elem *elem;
int key = i;
Annotation
- Detected declarations: `struct hid_bpf_async_map_elem`, `enum hid_bpf_async_state`, `function __start_wq_timer_cb`, `function hid_bpf_async_find_empty_key`, `function bpf_for`, `function hid_bpf_async_get_ctx`, `function ms_to_ns`, `function hid_bpf_async_delayed_call`, `function hid_bpf_async_call`.
- Atlas domain: Driver Families / drivers/hid.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.