History

media: rc: introduce BPF_PROG_LIRC_MODE2

Add support for BPF_PROG_LIRC_MODE2. This type of BPF program can call rc_keydown() to reported decoded IR scancodes, or rc_repeat() to report that the last key should be repeated. The bpf program can be attached to using the bpf(BPF_PROG_ATTACH) syscall; the target_fd must be the /dev/lircN device.

Sean Young committed 8 years ago

Commit f4364dc1 parent 170a7e310 files · +479 −3Browse files

Showing the changes to include/uapi/linux (1 of 10 files). Show all

Unified · Split

include/uapi/linux/bpf.h+52−1
@@ -143,6 +143,7 @@ enum bpf_prog_type { · 142 unmodified lines
143143 BPF_PROG_TYPE_RAW_TRACEPOINT,
144144 BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
145145 BPF_PROG_TYPE_LWT_SEG6LOCAL,
146+ BPF_PROG_TYPE_LIRC_MODE2,
146147 };
147148
148149 enum bpf_attach_type {
@@ -162,6 +163,7 @@ enum bpf_attach_type { · 13 unmodified lines
162163 BPF_CGROUP_INET6_POST_BIND,
163164 BPF_CGROUP_UDP4_SENDMSG,
164165 BPF_CGROUP_UDP6_SENDMSG,
166+ BPF_LIRC_MODE2,
165167 __MAX_BPF_ATTACH_TYPE
166168 };
167169
@@ -2005,6 +2007,53 @@ union bpf_attr { · 1837 unmodified lines
20052007 * direct packet access.
20062008 * Return
20072009 * 0 on success, or a negative error in case of failure.
2010+ *
2011+ * int bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
2012+ * Description
2013+ * This helper is used in programs implementing IR decoding, to
2014+ * report a successfully decoded key press with *scancode*,
2015+ * *toggle* value in the given *protocol*. The scancode will be
2016+ * translated to a keycode using the rc keymap, and reported as
2017+ * an input key down event. After a period a key up event is
2018+ * generated. This period can be extended by calling either
2019+ * **bpf_rc_keydown** () again with the same values, or calling
2020+ * **bpf_rc_repeat** ().
2021+ *
2022+ * Some protocols include a toggle bit, in case the button was
2023+ * released and pressed again between consecutive scancodes.
2024+ *
2025+ * The *ctx* should point to the lirc sample as passed into
2026+ * the program.
2027+ *
2028+ * The *protocol* is the decoded protocol number (see
2029+ * **enum rc_proto** for some predefined values).
2030+ *
2031+ * This helper is only available is the kernel was compiled with
2032+ * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
2033+ * "**y**".
2034+ *
2035+ * Return
2036+ * 0
2037+ *
2038+ * int bpf_rc_repeat(void *ctx)
2039+ * Description
2040+ * This helper is used in programs implementing IR decoding, to
2041+ * report a successfully decoded repeat key message. This delays
2042+ * the generation of a key up event for previously generated
2043+ * key down event.
2044+ *
2045+ * Some IR protocols like NEC have a special IR message for
2046+ * repeating last button, for when a button is held down.
2047+ *
2048+ * The *ctx* should point to the lirc sample as passed into
2049+ * the program.
2050+ *
2051+ * This helper is only available is the kernel was compiled with
2052+ * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
2053+ * "**y**".
2054+ *
2055+ * Return
2056+ * 0
20082057 */
20092058 #define __BPF_FUNC_MAPPER(FN) \
20102059 FN(unspec), \
@@ -2083,7 +2132,9 @@ union bpf_attr { · 72 unmodified lines
20832132 FN(lwt_push_encap), \
20842133 FN(lwt_seg6_store_bytes), \
20852134 FN(lwt_seg6_adjust_srh), \
2086− FN(lwt_seg6_action),
2135+ FN(lwt_seg6_action), \
2136+ FN(rc_repeat), \
2137+ FN(rc_keydown),
20872138
20882139 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
20892140 * function eBPF program intends to call