1.增加动态回收mem

This commit is contained in:
payton 2023-12-20 16:25:17 +08:00
parent 27f5c29b33
commit e8f2ea7d8f
5 changed files with 95 additions and 1 deletions

View File

@ -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 \

View File

@ -14,6 +14,7 @@
#include "comm/timer.h"
#include <io/gpio.h>
#include <IOCfg.h>
#include "mem_hotplug.h"
#if HUNTING_CAMERA_MCU == ENABLE
#include <sf_inc.h>
#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);

View File

@ -0,0 +1,82 @@
#include <stdio.h>
#include <vendor_common.h>
#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;
}

View File

@ -0,0 +1,7 @@
#ifndef _MEM_HOTPLUG_H
#define _MEM_HOTPLUG_H
#include <hd_type.h>
extern HD_RESULT memory_hotplug(void);
#endif

View File

@ -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 {