From bd091745844da6f7e510f9738e2027ae716f4052 Mon Sep 17 00:00:00 2001 From: Sumit Gaur Date: Wed, 19 Jun 2019 12:31:39 +0530 Subject: [PATCH] qcn3018: Set number of cores for QCN3018 QCN3018 has only 2 cores, the kernel has to bringup only 2 cores, hence if the SoC is identified as QCN3018 restrict the number of cores using "maxcpus" bootargs Change-Id: Idafc44c02de302b65f9c9dfc5f77783a91b2c018 Signed-off-by: Sumit Gaur --- .../include/asm/arch-qca-common/qca_common.h | 1 + board/qca/arm/common/board_init.c | 5 +++ board/qca/arm/common/cmd_bootqca.c | 36 +++++++++++++++++++ board/qca/arm/ipq40xx/ipq40xx.c | 12 +++++++ board/qca/arm/ipq40xx/ipq40xx.h | 5 +-- 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/arch-qca-common/qca_common.h b/arch/arm/include/asm/arch-qca-common/qca_common.h index b07e5bdac5..d556429ab5 100644 --- a/arch/arm/include/asm/arch-qca-common/qca_common.h +++ b/arch/arm/include/asm/arch-qca-common/qca_common.h @@ -82,6 +82,7 @@ void aquantia_phy_reset_init_done(void); void aquantia_phy_reset_init(void); int bring_sec_core_up(unsigned int cpuid, unsigned int entry, unsigned int arg); int is_secondary_core_off(unsigned int cpuid); +int smem_read_cpu_count(void); struct dumpinfo_t{ char name[16]; /* use only file name in 8.3 format */ diff --git a/board/qca/arm/common/board_init.c b/board/qca/arm/common/board_init.c index f9b25ae31a..fff4d27474 100644 --- a/board/qca/arm/common/board_init.c +++ b/board/qca/arm/common/board_init.c @@ -469,3 +469,8 @@ __weak void clear_l2cache_err(void) { return; } + +__weak int smem_read_cpu_count() +{ + return -1; +} diff --git a/board/qca/arm/common/cmd_bootqca.c b/board/qca/arm/common/cmd_bootqca.c index 0511197933..e35a0fb5ae 100644 --- a/board/qca/arm/common/cmd_bootqca.c +++ b/board/qca/arm/common/cmd_bootqca.c @@ -415,6 +415,36 @@ static int authenticate_rootfs_elf(unsigned int rootfs_hdr) #endif #endif +static int set_num_cpus(void) +{ + char *arg; + char *p; + char bootarg_buf[50]; + int numcpus; + + numcpus = smem_read_cpu_count(); + + if (numcpus != -1) { /* QCN3018 */ + /* check if nosmp is set in bootargs */ + arg = getenv("bootargs"); + if (arg) { + p = strstr(arg, "nosmp"); + if (p) { + if ((p[strlen("nosmp")] == ' ') + || (p[strlen("nosmp")] == '\0')) + if ((p == arg) || (*(p - 1) == ' ')) + return 0; + } + } + snprintf(bootarg_buf, sizeof(bootarg_buf), + "setenv bootargs ${booargs} maxcpus=%d\n", + numcpus); + + return run_command(bootarg_buf, 0); + } + return 0; +} + static int do_boot_signedimg(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { char runcmd[256]; @@ -435,6 +465,9 @@ static int do_boot_signedimg(cmd_tbl_t *cmdtp, int flag, int argc, char *const a if (argc == 2 && strncmp(argv[1], "debug", 5) == 0) debug = 1; + if ((ret = set_num_cpus())) + return ret; + if ((ret = set_fs_bootargs(&ipq_fs_on_nand))) return ret; @@ -682,6 +715,9 @@ static int do_boot_unsignedimg(cmd_tbl_t *cmdtp, int flag, int argc, char *const if (argc == 2 && strncmp(argv[1], "debug", 5) == 0) debug = 1; + if ((ret = set_num_cpus())) + return ret; + if ((ret = set_fs_bootargs(&ipq_fs_on_nand))) return ret; diff --git a/board/qca/arm/ipq40xx/ipq40xx.c b/board/qca/arm/ipq40xx/ipq40xx.c index cb7929f160..4a38de607a 100644 --- a/board/qca/arm/ipq40xx/ipq40xx.c +++ b/board/qca/arm/ipq40xx/ipq40xx.c @@ -696,3 +696,15 @@ int bring_sec_core_up(unsigned int cpuid, unsigned int entry, unsigned int arg) return 0; } + +int smem_read_cpu_count() +{ + uint32_t core_no; + + if (!smem_read_alloc_entry(SMEM_NUM_CPUINFO, &core_no, + sizeof(uint32_t))) { + if (core_no != 4) + return core_no; + } + return -1; +} diff --git a/board/qca/arm/ipq40xx/ipq40xx.h b/board/qca/arm/ipq40xx/ipq40xx.h index 613158dfcf..b7fe71b412 100644 --- a/board/qca/arm/ipq40xx/ipq40xx.h +++ b/board/qca/arm/ipq40xx/ipq40xx.h @@ -162,9 +162,10 @@ typedef enum { SMEM_BOOT_FLASH_DENSITY = 482, SMEM_PARTITION_TABLE_OFFSET = 483, SMEM_BOOT_DUALPARTINFO = 484, + SMEM_NUM_CPUINFO = 485, SMEM_FIRST_VALID_TYPE = SMEM_SPINLOCK_ARRAY, - SMEM_LAST_VALID_TYPE = SMEM_BOOT_DUALPARTINFO, - SMEM_MAX_SIZE = SMEM_BOOT_DUALPARTINFO + 1, + SMEM_LAST_VALID_TYPE = SMEM_NUM_CPUINFO, + SMEM_MAX_SIZE = SMEM_NUM_CPUINFO + 1, } smem_mem_type_t; unsigned smem_read_alloc_entry(smem_mem_type_t type, void *buf, int len);