v4l2: built-in auto-boot via initcall ordering (sem service/self-init)

Faz o hi_v4l2 subir sozinho no boot quando built-in (CFG_HI_MSP_BUILDIN=y),
sem serviço de userspace nem self-init do VDEC. A causa-raiz de o decoder
falhar no boot (HI_DRV_VDEC_Open -> 0xffffffff) era ORDEM DE INITCALL: o
hi_init.c (HI_DRV_LoadModules, init master do stack msp) roda em late_initcall
(nivel 7) e faz VFMW/VDEC/VPSS *_DRV_ModInit; o nosso driver tambem usava
late_initcall, mesmo nivel -> ordem por link -> corria antes -> VDEC_DRV_Open
nao achava as funcoes de VFMW/VPSS (HI_DRV_MODULE_GetFunction) e caia no err.

Correcoes (padrao dvb-hisi):
- hi_v4l2_core.c: late_initcall_sync(hi_v4l2_init) INCONDICIONAL + module_exit
  (sob CONFIG MODULE os *_initcall viram module_init; built-in vira nivel 7s,
  que roda DEPOIS do nivel 7 do HI_DRV_LoadModules). Identico ao dvb-hisi.
- hi_vdec_hal.c: global_init so faz HI_DRV_VDEC_Open (NAO HI_DRV_VDEC_Init -- o
  hi_init.c ja faz VDEC_DRV_ModInit); global_exit so HI_DRV_VDEC_Close (NAO
  DeInit -- nao destruir o modulo VDEC que o hi_init e dono). Open/Close sao
  refcontados (atmOpenCnt) -> coexiste com AVServer/AVPLAY.
- Makefile: obj-$(HI_DRV_BUILDTYPE) (built-in quando CFG_HI_MSP_BUILDIN=y).

Validado em HW (Hi3798Cv200, kernel #18): no boot, /dev/video0=decoder (8 coded
formats) + /dev/video1=encoder (H264) automaticos; decode VP8 1080p 291 frames;
encode NV12->H264 720p valido; coexistencia com AVServer ativo (dec+enc OK, sem
derrubar o stack do AVServer, sem oops).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Leandro Tavares de MeloandClaude Opus 4.8 committed 2026-06-14 17:09:10 -03:00
1 parent 18e9f296e4
commit 0fa85ec72b
4 files changed
+42 -10

No files matched your search

+9 -9
View File
@@ -59,15 +59,15 @@ KBUILD_EXTRA_SYMBOLS += $(MSP_DIR)/drv/Module.symvers
#===============================================================================
MOD_NAME := hi_v4l2
# NOTE: unlike dvb-hisi (obj-$(HI_DRV_BUILDTYPE), built-in when CFG_HI_MSP_BUILDIN=y),
# hi_v4l2 is ALWAYS a loadable module (obj-m). It depends on the V4L2 mem2mem +
# videobuf2 framework (v4l2-mem2mem.ko, videobuf2-*.ko) which ship as kernel
# modules (=m) in this defconfig, so a built-in hi_v4l2 would fail to link
# (unresolved v4l2_m2m_*/vb2_* symbols). The HI_DRV_VDEC_*/HI_DRV_VENC_* symbols
# it also uses ARE in vmlinux (msp built-in), resolved via the kernel
# Module.symvers during `make modules`. The parent Makefile still reaches this
# dir through `obj-y += v4l2-hisi/`; this obj-m just makes the unit a module.
obj-m += $(MOD_NAME).o
# Built-in when CFG_HI_MSP_BUILDIN=y (HI_DRV_BUILDTYPE=y), like dvb-hisi.
# Works at boot via initcall ordering: hi_v4l2_core.c registers with
# late_initcall_sync (level 7s), which runs AFTER the msp boot init
# (hi_init.c HI_DRV_LoadModules @ late_initcall, level 7) that does the
# VFMW/VDEC/VPSS *_DRV_ModInit. So when our decoder probe opens the VDEC, the
# VFMW/VPSS functions it needs are already registered. We only HI_DRV_VDEC_Open
# (not Init/DeInit -- hi_init owns those), so we coexist with AVServer/AVPLAY.
# Deps built-in via the VIDEO_HISI_V4L2_DEPS Kconfig stub. Build w/ CONFIG_MSP=y.
obj-$(HI_DRV_BUILDTYPE) += $(MOD_NAME).o
$(MOD_NAME)-y := hi_v4l2_core.o \
hi_v4l2_dec.o \