Files
v4l2-hisi/hi_v4l2_core.c
T
Leandro Tavares de MeloandClaude Opus 4.8 0fa85ec72b 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>
2026-06-14 17:09:10 -03:00

64 lines
1.8 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Hisilicon V4L2 driver - module entry. Registers both the mem2mem video
* decoder (/dev/videoN) and encoder (/dev/videoM) over the proven HI_DRV_VDEC_*
* / HI_DRV_VENC_* kernel layer.
*/
#include <linux/module.h>
#include <linux/init.h>
#include "hi_v4l2_drv.h"
static int __init hi_v4l2_init(void)
{
int ret;
ret = hi_dec_register();
if (ret) {
pr_err("hi-v4l2: decoder register failed (%d)\n", ret);
return ret;
}
ret = hi_enc_register();
if (ret) {
pr_err("hi-v4l2: encoder register failed (%d)\n", ret);
hi_dec_unregister();
return ret;
}
#ifdef HI_V4L2_ZC_SELFTEST
hi_zc_test_register(); /* isolated zero-copy probe (KI-003) */
#endif
pr_info("hi-v4l2: decoder + encoder registered\n");
return 0;
}
static void __exit hi_v4l2_exit(void)
{
#ifdef HI_V4L2_ZC_SELFTEST
hi_zc_test_unregister();
#endif
hi_enc_unregister();
hi_dec_unregister();
}
/*
* Same idiom as dvb-hisi (drivers/msp/drv/dvb-hisi): late_initcall_sync works
* for both build kinds -- under CONFIG MODULE all *_initcall macros collapse to
* module_init (runs at insmod, stack already up); built-in it is initcall level
* 7s, which runs AFTER the msp boot init (hi_init.c HI_DRV_LoadModules @
* late_initcall, level 7) that does VFMW/VDEC/VPSS *_DRV_ModInit. We must run
* after it: the decoder probe opens the VDEC (HI_DRV_VDEC_Open -> GetFunction
* of VFMW/VPSS) and probes caps (HI_DRV_VDEC_GetCap), which need those
* subsystems already registered. Plain late_initcall (level 7) raced
* HI_DRV_LoadModules by link order and lost (VDEC_DRV_Open -> 0xffffffff).
*/
late_initcall_sync(hi_v4l2_init);
module_exit(hi_v4l2_exit);
MODULE_DESCRIPTION("Hisilicon V4L2 mem2mem video codec (decoder + encoder)");
MODULE_AUTHOR("HiSTBLinux V4L2 migration");
MODULE_LICENSE("GPL");
MODULE_VERSION("0.2.0");