From e8f2ea7d8ffa28cde75299c60952b5a0c8b6ff80 Mon Sep 17 00:00:00 2001 From: payton Date: Wed, 20 Dec 2023 16:25:17 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E5=8A=A8=E6=80=81=E5=9B=9E?= =?UTF-8?q?=E6=94=B6mem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/application/source/cardv/Makefile | 1 + .../source/cardv/SrcCode/System/main.c | 4 + .../source/cardv/SrcCode/System/mem_hotplug.c | 82 +++++++++++++++++++ .../source/cardv/SrcCode/System/mem_hotplug.h | 7 ++ .../nvt-mem-tbl.dtsi | 2 +- 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 code/application/source/cardv/SrcCode/System/mem_hotplug.c create mode 100755 code/application/source/cardv/SrcCode/System/mem_hotplug.h diff --git a/code/application/source/cardv/Makefile b/code/application/source/cardv/Makefile index 91affbc5a..b7ad8541b 100755 --- a/code/application/source/cardv/Makefile +++ b/code/application/source/cardv/Makefile @@ -122,6 +122,7 @@ SRC = \ ./SrcCode/System/SysFW_Upgrade_Strg_Obj.c \ ./SrcCode/System/SysFW_Upgrade.c \ ./SrcCode/System/sys_usrmem.c \ + ./SrcCode/System/mem_hotplug.c \ ./SrcCode/UIApp/UIAppObj.c \ ./SrcCode/UIApp/ExifVendor.c \ ./SrcCode/UIApp/Setup/UISetup_Exe.c \ diff --git a/code/application/source/cardv/SrcCode/System/main.c b/code/application/source/cardv/SrcCode/System/main.c index 60e735c39..3af208301 100755 --- a/code/application/source/cardv/SrcCode/System/main.c +++ b/code/application/source/cardv/SrcCode/System/main.c @@ -14,6 +14,7 @@ #include "comm/timer.h" #include #include +#include "mem_hotplug.h" #if HUNTING_CAMERA_MCU == ENABLE #include #include "sf_log.h" @@ -250,6 +251,9 @@ UINT32 nvt_hdal_init(void) DBG_ERR("mem init fail=%d\n", ret); return -1; } + + memory_hotplug(); + ret = hd_gfx_init(); if(ret != HD_OK) { DBG_ERR("gfx init fail=%d\n", ret); diff --git a/code/application/source/cardv/SrcCode/System/mem_hotplug.c b/code/application/source/cardv/SrcCode/System/mem_hotplug.c new file mode 100755 index 000000000..90fc2a0c5 --- /dev/null +++ b/code/application/source/cardv/SrcCode/System/mem_hotplug.c @@ -0,0 +1,82 @@ +#include +#include +#include "mem_hotplug.h" +#include "kwrap/debug.h" + +#define SWAP4(x) ((((x) & 0xFF) << 24) | (((x) & 0xFF00) << 8) | (((x) & 0xFF0000) >> 8) | (((x) & 0xFF000000) >> 24)) + +static int read_fdt(const char *path, unsigned int *p_addr, unsigned int *p_size) +{ + int fd; + unsigned int reg[2] = {0}; + + if ((fd = open(path, O_RDONLY)) < 0) { + printf("unable to open %s\n", path); + return -1; + } + + if (read(fd, reg, sizeof(reg)) != sizeof(reg)) { + printf("unable to read reg on %s\n", path); + close(fd); + return -1; + } + + *p_addr = SWAP4(reg[0]); + *p_size = SWAP4(reg[1]); + close(fd); + return 0; +} + +static int get_mem_range(unsigned int *p_addr, unsigned int *p_size) +{ + unsigned int fdt_addr, fdt_size; + unsigned int rtos_addr, rtos_size; +// unsigned int bridge_addr, bridge_size; + //get fdt addr and size in nvt_memory_cfg + if (read_fdt("/sys/firmware/devicetree/base/nvt_memory_cfg/fdt/reg", &fdt_addr, &fdt_size) != 0) { + return -1; + } + if (read_fdt("/sys/firmware/devicetree/base/nvt_memory_cfg/rtos/reg", &rtos_addr, &rtos_size) != 0) { + return -1; + } + +#if 0 /* bridge is not used */ + if (read_fdt("/sys/firmware/devicetree/base/nvt_memory_cfg/bridge/reg", &bridge_addr, &bridge_size) != 0) { + return -1; + } +#endif + + *p_addr = fdt_addr; + *p_size = fdt_size + rtos_size; +// *p_size = fdt_size + rtos_size + bridge_size; + return 0; +} + +static int do_hotplug(unsigned int mem_begin, unsigned mem_size) +{ + HD_RESULT ret=0; + VENDOR_LINUX_MEM_HOT_PLUG desc = {0}; + desc.start_addr = mem_begin; + desc.size = mem_size; + ret = vendor_common_mem_set(VENDOR_COMMON_MEM_ITEM_LINUX_HOT_PLUG, &desc); + if(ret != 0){ + printf("nvtmem_hotplug_set fail ret:%d\n", (int)ret); + } + return 0; +} + +HD_RESULT memory_hotplug(void) +{ + unsigned int mem_begin, mem_size; + + // read memory space from bridge memory + if (get_mem_range(&mem_begin, &mem_size) != 0) { + return HD_ERR_INIT; + } + // do hotplug + if (do_hotplug(mem_begin, mem_size) != 0) { + return HD_ERR_SYS; + } + + return 0; +} diff --git a/code/application/source/cardv/SrcCode/System/mem_hotplug.h b/code/application/source/cardv/SrcCode/System/mem_hotplug.h new file mode 100755 index 000000000..71a2f281c --- /dev/null +++ b/code/application/source/cardv/SrcCode/System/mem_hotplug.h @@ -0,0 +1,7 @@ +#ifndef _MEM_HOTPLUG_H +#define _MEM_HOTPLUG_H +#include + +extern HD_RESULT memory_hotplug(void); + +#endif \ No newline at end of file diff --git a/configs/Linux/cfg_565_HUNTING_EVB_LINUX_4G_S550/nvt-mem-tbl.dtsi b/configs/Linux/cfg_565_HUNTING_EVB_LINUX_4G_S550/nvt-mem-tbl.dtsi index ea25fb642..d87aa1741 100755 --- a/configs/Linux/cfg_565_HUNTING_EVB_LINUX_4G_S550/nvt-mem-tbl.dtsi +++ b/configs/Linux/cfg_565_HUNTING_EVB_LINUX_4G_S550/nvt-mem-tbl.dtsi @@ -21,7 +21,7 @@ }; /* Linux system memory region*/ - memory { device_type = "memory"; reg = <0x00000000 0x01800000 0x02000000 0x01600000>; }; + memory { device_type = "memory"; reg = <0x00000000 0x01800000 0x02800000 0x00E00000>; }; /* Linux setup reserved memory */ reserved-memory {