From cf14b5699bd0350f0142c93a122b21f4e77fab65 Mon Sep 17 00:00:00 2001 From: Vasiliy Yakovlev Date: Thu, 7 May 2026 08:30:52 +0300 Subject: [PATCH] hi_cma: synthesize fallback zone from default CMA when no mmz= passed openhisilicon's V3.5 cma_allocator (in user-side open_osal.ko) calls hisi_get_cma_zone("anonymous") to look up a CMA region registered via the kernel cmdline `mmz=` early_param. On stock OpenIPC firmware where the U-Boot bootargs were never customised, no `mmz=` is present, hisi_get_cma_zone returns NULL, and the OSAL allocator fails to register any zone. After OpenIPC/openhisilicon#73 propagated -ENODEV from the empty-zone case, `insmod hi_osal.ko` started failing loud, and load_hisilicon's `|| report_error` aborts the whole module load chain. Existing hi3516av300 / hi3516cv500 / hi3516dv300 cameras that "worked for years" stopped loading any vendor module after a sysupgrade. Fix: when the named lookup misses, synthesize a single fallback zone that points to the kernel's default CMA pool (set by CONFIG_CMA_SIZE_MBYTES or `cma=` in cmdline). The fallback is one-shot (cached in a static struct) so subsequent get-by-name calls reuse it. Verified on hi3516av300_imx415 with default OpenIPC bootargs (no mmz=, no cma=) and CONFIG_CMA_SIZE_MBYTES=256: all 37 OSDRV modules load, IMX415 4K2K_30FPS init succuss, RTSP server on :554, HTTP /image.jpg returns a valid 3840x2160 baseline JPEG. No bootargs change required. Boards that DO put `mmz=anonymous,...` in bootargs keep their per-zone intent (named lookup is still tried first). Co-Authored-By: Claude Opus 4.7 (1M context) --- drivers/hisilicon/cma/hi_cma.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/hisilicon/cma/hi_cma.c b/drivers/hisilicon/cma/hi_cma.c index 8830558de7b..6c71f31e28e 100644 --- a/drivers/hisilicon/cma/hi_cma.c +++ b/drivers/hisilicon/cma/hi_cma.c @@ -134,7 +134,31 @@ struct cma_zone *hisi_get_cma_zone(const char *name) } if (i == num_zones) { - return NULL; + /* + * No zone with this name was registered via the cmdline mmz=. + * That's the case on stock OpenIPC firmware where the U-Boot + * bootargs were never customised — historically the vendor + * binary hi_osal.ko had its own raw allocator and didn't need + * a hisi_zone, but openhisilicon's cma_allocator.c expects one. + * + * Synthesize a single fallback zone backed by the kernel's + * default CMA pool (CONFIG_CMA_SIZE_MBYTES / cma=). This lets + * existing installs work after a sysupgrade without any + * U-Boot bootargs change. + */ + static struct cma_zone fallback_zone; + struct cma *def = dma_contiguous_default_area; + + if (def == NULL || fallback_zone.nbytes != 0) + return fallback_zone.nbytes ? &fallback_zone : NULL; + + fallback_zone.pdev.coherent_dma_mask = DMA_BIT_MASK(64); + dev_set_cma_area(&fallback_zone.pdev, def); + strlcpy(fallback_zone.name, name, NAME_LEN_MAX); + fallback_zone.gfp = 0; + fallback_zone.phys_start = cma_get_base(def); + fallback_zone.nbytes = cma_get_size(def); + return &fallback_zone; } return &hisi_zone[i];