Files
daedalus-v4l2/kernel/daedalus_v4l2_chardev.h
T
marfrit 895f57c63a Phase 8.2: kernel ↔ daemon chardev bridge with round-trip test
Adds /dev/daedalus-v4l2 misc chardev to the kernel module. The
chardev is the IPC channel for the future userspace decoder
daemon: kernel enqueues REQ_* messages, daemon read()s them,
processes, write()s RESP_* back.

Wire protocol (pre-1.0, header in include/daedalus_v4l2_proto.h):
- struct daedalus_msg_hdr: magic (D04V) + version + type +
  cookie + payload_len + reserved
- Request/response separated by high bit of type field
- Max 64 KiB payload per message
- Cookie correlates request with matching response

Kernel implementation (kernel/daedalus_v4l2_chardev.{c,h}):
- Single-instance chardev (-EBUSY on second open)
- In-kernel FIFO bounded at 64 messages
- Blocking + non-blocking read; poll() with EPOLLIN on queued
- write() parses + validates header, logs response at pr_debug
- Bad magic → -EBADMSG, bad version → -EPROTO, oversize → -EMSGSIZE
- All error paths free resources

Phase 8.2 test trigger via debugfs:
- /sys/kernel/debug/daedalus_v4l2/test_ping — any byte
  enqueues a PING with a fixed 24-byte payload. Removed in
  Phase 8.4 when real REQ_DECODE from V4L2 path takes over.

Userspace verification tool (tools/test_chardev_pingpong.c):
- Real C program, proper error reporting via strerror
- Validates the 6-step round-trip: open → empty-queue EAGAIN →
  trigger ping → read PING → verify all fields → write PONG → close
- Builds with -Wall -Wextra clean

Verification on hertz (Pi 5, 6.12.75+rpt-rpi-2712):
  $ sudo insmod daedalus_v4l2.ko
  $ sudo tools/test_chardev_pingpong
  opening /dev/daedalus-v4l2...
    non-blocking read on empty queue: EAGAIN ✓
    injected PING via debugfs ✓
    read PING: magic ✓ version ✓ type=PING ✓ cookie=0x1234 ✓ payload=24 bytes
      payload: "DAEDALUS-V4L2-PING-PL"
    wrote PONG (cookie=0x1234) ✓
  ALL TESTS PASSED.
  $ sudo rmmod daedalus_v4l2      # clean

Per correctness-before-speed: full kerneldoc on structs, 8-tab
kernel style, SPDX headers, proper error paths, real test
program (not "I ran it once"), failure-mode coverage documented.

Phase 8.3 next: userspace daemon with dlopen'd FFmpeg parse path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 15:05:54 +00:00

30 lines
1.0 KiB
C

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* daedalus-v4l2 — chardev bridge interface (kernel-internal).
*/
#ifndef DAEDALUS_V4L2_CHARDEV_H
#define DAEDALUS_V4L2_CHARDEV_H
#include <linux/types.h>
int daedalus_chardev_init(void);
void daedalus_chardev_exit(void);
/**
* daedalus_chardev_enqueue_req() - queue a request for the daemon
* @type: request type (must have high bit clear; see enum
* daedalus_msg_type in include/daedalus_v4l2_proto.h)
* @cookie: caller-supplied identifier; echoed in matching response
* @payload: pointer to payload bytes (may be NULL if @payload_len = 0)
* @payload_len: payload size in bytes (0..DAEDALUS_PROTO_MAX_PAYLOAD)
*
* Return: 0 on success, -ENODEV if chardev not registered,
* -ENOSPC if the queue is full, -EMSGSIZE if @payload_len is
* too large, -EINVAL if @type has the response bit set,
* -ENOMEM on allocation failure.
*/
int daedalus_chardev_enqueue_req(__u32 type, __u32 cookie,
const void *payload, size_t payload_len);
#endif /* DAEDALUS_V4L2_CHARDEV_H */