diff --git a/Makefile b/Makefile index 11eaf53..2eb4221 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/hi_v4l2_core.c b/hi_v4l2_core.c index cddbcb2..1dfc02c 100644 --- a/hi_v4l2_core.c +++ b/hi_v4l2_core.c @@ -43,7 +43,18 @@ static void __exit hi_v4l2_exit(void) hi_dec_unregister(); } -module_init(hi_v4l2_init); +/* + * 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)"); diff --git a/hi_v4l2_dec.c b/hi_v4l2_dec.c index 7ce35fd..c6ca5bc 100644 --- a/hi_v4l2_dec.c +++ b/hi_v4l2_dec.c @@ -1459,6 +1459,12 @@ static int hi_dec_probe(struct platform_device *pdev) mutex_init(&dev->dev_mutex); atomic_set(&dev->num_inst, 0); + /* + * Open the VDEC subsystem here (refcounted; coexists with AVServer). The + * msp boot init (hi_init.c) already did VDEC_DRV_ModInit, and our + * late_initcall_sync (hi_v4l2_core.c) runs after it, so the VFMW/VPSS + * functions the open needs are already registered. + */ ret = hi_vdec_hal_global_init(); if (ret) return ret; diff --git a/hi_vdec_hal.c b/hi_vdec_hal.c index e9b3cf6..60c1db0 100644 --- a/hi_vdec_hal.c +++ b/hi_vdec_hal.c @@ -161,6 +161,15 @@ int hi_vdec_hal_global_init(void) mutex_lock(&g_lock); if (g_open_refcnt == 0) { + /* + * Only OPEN the VDEC -- do NOT call HI_DRV_VDEC_Init. The msp boot + * init (hi_init.c HI_DRV_LoadModules) already does VDEC_DRV_ModInit + * (-> HI_DRV_VDEC_Init: module-register + bufmng + task); calling it + * again fights that single owner. We behave like the userspace MPI: + * just HI_DRV_VDEC_Open, which is refcounted (atmOpenCnt) and so + * coexists with AVServer/AVPLAY. This needs VFMW/VPSS already + * registered, hence late_initcall_sync ordering in hi_v4l2_core.c. + */ ret = HI_DRV_VDEC_Open(); if (ret != HI_SUCCESS) { pr_err("hi-v4l2: HI_DRV_VDEC_Open failed (0x%x)\n", ret); @@ -177,6 +186,12 @@ out: void hi_vdec_hal_global_exit(void) { mutex_lock(&g_lock); + /* + * Close only -- never HI_DRV_VDEC_DeInit: the VDEC subsystem is owned by + * the msp boot init (hi_init.c), not by us. DeInit would tear down the + * whole VDEC module out from under AVServer/AVPLAY and the rest of the + * stack. Close is the refcounted (atmOpenCnt) counterpart of our Open. + */ if (--g_open_refcnt == 0) HI_DRV_VDEC_Close(); if (g_open_refcnt < 0)