Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
obj-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_helper.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_excep.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_wrapper_ipi.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_irq.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_logger.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_l1c.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_scpctl.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_feature_table.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_awake.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_dvfs.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_hwvoter_dbg.o
ccflags-y += -I$(srctree)/drivers/misc/mediatek/scp/include
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include
ccflags-y += -I$(srctree)/drivers/clk/mediatek/
ccflags-y += -I$(srctree)/drivers/devfreq/
ccflags-$(CONFIG_MTK_PMIC_CHIP_MT6335)+= -I$(srctree)/drivers/misc/mediatek/pmic/include/mt6335
ccflags-$(CONFIG_MTK_PMIC_CHIP_MT6353)+= -I$(srctree)/drivers/misc/mediatek/pmic/include/mt6353
ccflags-$(CONFIG_MTK_PMIC_CHIP_MT6355)+= -I$(srctree)/drivers/misc/mediatek/pmic/include/mt6355
ccflags-$(CONFIG_MTK_PMIC_CHIP_MT6358)+= -I$(srctree)/drivers/misc/mediatek/pmic/include/mt6358
ccflags-$(CONFIG_MTK_PMIC_CHIP_MT6359P)+= -I$(srctree)/drivers/misc/mediatek/pmic/include/mt6359p
+360
View File
@@ -0,0 +1,360 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#include <linux/module.h> /* needed by all modules */
#include <linux/init.h> /* needed by module macros */
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/miscdevice.h> /* needed by miscdevice* */
#include <linux/sysfs.h>
#include <linux/platform_device.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/uaccess.h> /* needed by copy_to_user */
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/slab.h> /* needed by kmalloc */
#include <linux/poll.h> /* needed by poll */
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/suspend.h>
#include <linux/timer.h>
#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/of_fdt.h>
#include <linux/ioport.h>
#include <linux/io.h>
//#include <mt-plat/sync_write.h>
#include <mt-plat/aee.h>
#include <linux/delay.h>
#include "scp_feature_define.h"
#include "scp_ipi_pin.h"
#include "scp_helper.h"
#include "scp_excep.h"
#include "scp_dvfs.h"
#include "scp.h"
#define SCP_SECURE_DUMP_MEASURE 0
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM) && SCP_SECURE_DUMP_MEASURE
static struct cal {
uint64_t start, end;
} scpdump_cal[3];
#endif
struct mutex scp_awake_mutexs[SCP_CORE_TOTAL];
/*
* acquire scp lock flag, keep scp awake
* @param scp_core_id: scp core id
* return 0 :get lock success
* -1 :get lock timeout
*/
int scp_awake_lock(void *_scp_id)
{
enum scp_core_id scp_id = (enum scp_core_id) _scp_id;
unsigned long spin_flags;
char *core_id;
int *scp_awake_count;
int count = 0;
int ret = -1;
unsigned int tmp;
if (scp_id >= SCP_CORE_TOTAL) {
pr_notice("%s: SCP ID >= SCP_CORE_TOTAL\n", __func__);
return ret;
}
scp_awake_count = (int *)&scp_awake_counts[scp_id];
core_id = core_ids[scp_id];
if (is_scp_ready(scp_id) == 0) {
pr_notice("%s: %s not enabled\n", __func__, core_id);
return ret;
}
/* scp unlock awake */
spin_lock_irqsave(&scp_awake_spinlock, spin_flags);
if (*scp_awake_count > 0) {
*scp_awake_count = *scp_awake_count + 1;
spin_unlock_irqrestore(&scp_awake_spinlock, spin_flags);
return 0;
}
/*set a direct IPI to awake SCP */
/*pr_debug("scp_awake_lock: try to awake %s\n", core_id);*/
writel(0xA0 | (1 << AP_AWAKE_LOCK), INFRA_IRQ_SET);
count = 0;
while (++count != SCP_AWAKE_TIMEOUT) {
#if SCP_RECOVERY_SUPPORT
if (atomic_read(&scp_reset_status) == RESET_STATUS_START) {
pr_notice("%s: resetting scp, break\n", __func__);
break;
}
#endif // SCP_RECOVERY_SUPPORT
tmp = readl(INFRA_IRQ_SET);
if ((tmp & 0xA0) != 0xA0) {
pr_notice("%s: INFRA_IRQ_SET %x\n", __func__, tmp);
break;
}
if (!((tmp & 0x0f) & (1 << AP_AWAKE_LOCK))) {
ret = 0;
break;
}
udelay(10);
}
/* clear status */
writel(0xA0 | (1 << AP_AWAKE_LOCK), INFRA_IRQ_CLEAR);
/* scp lock awake success*/
if (ret != -1)
*scp_awake_count = *scp_awake_count + 1;
if (ret == -1) {
pr_notice("%s: awake %s fail..\n", __func__, core_id);
#if SCP_RECOVERY_SUPPORT
if (atomic_read(&scp_reset_status) == RESET_STATUS_STOP) {
scp_set_reset_status();
pr_notice("%s: start to reset scp...\n", __func__);
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
if (scpreg.secure_dump) {
scp_do_halt_set();
} else {
#else
{
#endif
/* trigger halt isr, force scp enter wfi */
writel(B_GIPC4_SETCLR_0, R_GIPC_IN_SET);
}
scp_send_reset_wq(RESET_TYPE_AWAKE);
} else
pr_notice("%s: scp resetting\n", __func__);
#endif
}
spin_unlock_irqrestore(&scp_awake_spinlock, spin_flags);
return ret;
}
EXPORT_SYMBOL_GPL(scp_awake_lock);
/*
* release scp awake lock flag
* @param scp_core_id: scp core id
* return 0 :release lock success
* -1 :release lock fail
*/
int scp_awake_unlock(void *_scp_id)
{
enum scp_core_id scp_id = (enum scp_core_id) _scp_id;
unsigned long spin_flags;
int *scp_awake_count;
char *core_id;
int count = 0;
int ret = -1;
unsigned int tmp;
if (scp_id >= SCP_CORE_TOTAL) {
pr_notice("%s: SCP ID >= SCP_CORE_TOTAL\n", __func__);
return -1;
}
scp_awake_count = (int *)&scp_awake_counts[scp_id];
core_id = core_ids[scp_id];
if (is_scp_ready(scp_id) == 0) {
pr_notice("%s: %s not enabled\n", __func__, core_id);
return -1;
}
/* scp unlock awake */
spin_lock_irqsave(&scp_awake_spinlock, spin_flags);
if (*scp_awake_count > 1) {
*scp_awake_count = *scp_awake_count - 1;
spin_unlock_irqrestore(&scp_awake_spinlock, spin_flags);
return 0;
}
/* WE1: set a direct IPI to release awake SCP */
/*pr_debug("scp_awake_lock: try to awake %s\n", core_id);*/
writel(0xA0 | (1 << AP_AWAKE_UNLOCK), INFRA_IRQ_SET);
count = 0;
while (++count != SCP_AWAKE_TIMEOUT) {
#if SCP_RECOVERY_SUPPORT
if (atomic_read(&scp_reset_status) == RESET_STATUS_START) {
pr_notice("%s: scp is being reset, break\n", __func__);
break;
}
#endif // SCP_RECOVERY_SUPPORT
tmp = readl(INFRA_IRQ_SET);
if ((tmp & 0xA0) != 0xA0) {
pr_notice("%s: INFRA7_IRQ_SET %x\n", __func__, tmp);
break;
}
if (!((tmp & 0x0f) & (1 << AP_AWAKE_UNLOCK))) {
ret = 0;
break;
}
udelay(10);
}
/* clear status */
writel(0xA0 | (1 << AP_AWAKE_UNLOCK), INFRA_IRQ_CLEAR);
/* scp unlock awake success*/
if (ret != -1) {
if (*scp_awake_count <= 0)
pr_err("%s:%s awake_count=%d NOT SYNC!\n", __func__,
core_id, *scp_awake_count);
if (*scp_awake_count > 0)
*scp_awake_count = *scp_awake_count - 1;
}
if (ret == -1) {
pr_notice("%s: awake %s fail..\n", __func__, core_id);
#if SCP_RECOVERY_SUPPORT
if (atomic_read(&scp_reset_status) == RESET_STATUS_STOP) {
scp_set_reset_status();
pr_notice("%s: start to reset scp...\n", __func__);
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
if (scpreg.secure_dump) {
scp_do_halt_set();
} else {
#else
{
#endif
/* trigger halt isr, force scp enter wfi */
writel(B_GIPC4_SETCLR_0, R_GIPC_IN_SET);
}
scp_send_reset_wq(RESET_TYPE_AWAKE);
} else
pr_notice("%s: scp resetting\n", __func__);
#endif
}
/* spinlock context safe */
spin_unlock_irqrestore(&scp_awake_spinlock, spin_flags);
return ret;
}
EXPORT_SYMBOL_GPL(scp_awake_unlock);
void scp_enable_sram(void)
{
uint32_t reg_temp;
/*enable sram, enable 1 block per time*/
for (reg_temp = 0xffffffff; reg_temp != 0;) {
reg_temp = reg_temp >> 1;
writel(reg_temp, SCP_CPU0_SRAM_PD);
writel(reg_temp, SCP_CPU1_SRAM_PD);
}
/*enable scp all TCM*/
writel(0, SCP_CLK_CTRL_L1_SRAM_PD);
writel(0, SCP_CLK_CTRL_TCM_TAIL_SRAM_PD);
}
/*
* scp_sys_reset, reset scp
*/
int scp_sys_full_reset(void)
{
void *tmp;
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM) && SCP_SECURE_DUMP_MEASURE
int idx;
#endif
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
uint64_t restore_start, restore_end;
#endif
pr_notice("[SCP] %s\n", __func__);
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
restore_start = ktime_get_boot_ns();
if (scpreg.secure_dump) {
#if SCP_SECURE_DUMP_MEASURE
memset(scpdump_cal, 0x0, sizeof(scpdump_cal));
scpdump_cal[0].start = ktime_get_boot_ns();
scpdump_cal[1].start = ktime_get_boot_ns();
#endif
scp_restore_l2tcm();
#if SCP_SECURE_DUMP_MEASURE
scpdump_cal[1].end = ktime_get_boot_ns();
#endif
} else {
#else
{
#endif
/* clear whole TCM */
memset_io(SCP_TCM, 0, SCP_TCM_SIZE);
/*copy loader to scp sram*/
memcpy_to_scp(SCP_TCM, (const void *)(size_t)scp_loader_virt
, scp_region_info_copy.ap_loader_size);
/*set info to sram*/
memcpy_to_scp(scp_region_info, (const void *)&scp_region_info_copy
, sizeof(scp_region_info_copy));
}
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
if (scpreg.secure_dump) {
#if SCP_SECURE_DUMP_MEASURE
scpdump_cal[2].start = ktime_get_boot_ns();
#endif
tmp = (void *)(scp_ap_dram_virt +
ROUNDUP(scp_region_info_copy.ap_dram_size, 1024)
* scpreg.core_nums);
scp_restore_dram();
#if SCP_SECURE_DUMP_MEASURE
scpdump_cal[2].end = ktime_get_boot_ns();
scpdump_cal[0].end = ktime_get_boot_ns();
for (idx = 0; idx < 3; idx++) {
pr_notice("MDebug SCP Cal:%d %lldns\n", idx,
(scpdump_cal[idx].end - scpdump_cal[idx].start));
}
#endif
restore_end = ktime_get_boot_ns();
pr_notice("[SCP] Restore: %lld ns\n", (restore_end - restore_start));
} else {
#else
{
#endif
/* reset dram from dram back */
if ((int)(scp_region_info_copy.ap_dram_size) > 0) {
tmp = (void *)(scp_ap_dram_virt +
ROUNDUP(scp_region_info_copy.ap_dram_size, 1024)
* scpreg.core_nums);
memset(scp_ap_dram_virt, 0,
ROUNDUP(scp_region_info_copy.ap_dram_size, 1024)
* scpreg.core_nums);
memcpy(scp_ap_dram_virt, tmp,
scp_region_info_copy.ap_dram_size);
}
}
return 0;
}
int scp_clr_spm_reg(void *unused)
{
/* AP side write 0x1 to SCP2SPM_IPC_CLR to clear
* scp side write 0x1 to SCP2SPM_IPC_SET to set SPM reg
* scp set bit[0]
*/
writel(0x1, SCP_TO_SPM_REG);
return 0;
}
EXPORT_SYMBOL_GPL(scp_clr_spm_reg);
File diff suppressed because it is too large. Load diff
+268
View File
@@ -0,0 +1,268 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_DVFS_H__
#define __SCP_DVFS_H__
#define PLL_ENABLE (1)
#define PLL_DISABLE (0)
#define CLK_26M (26)
#define CALI_CONFIG_ELEM_CNT (3)
#define OPP_ELEM_CNT (8)
#define REG_MAX_MASK (0xFFFFFFFF)
#define SCP_ULPOSC_SEL_CORE (0x4)
#define SCP_ULPOSC_SEL_PERI (0x8)
#define CAL_EXT_BITS (2)
#define CAL_MIN_VAL_EXT (0)
#define CAL_MAX_VAL_EXT (0x2)
#define CAL_BITS (7)
#define CAL_MIN_VAL (0)
#define CAL_MAX_VAL (0x7F)
#define CALI_MIS_RATE (40)
#define CALI_DIV_VAL (512)
#define MAX_SUPPORTED_PLL_NUM 9
#define REG_DEFINE_WITH_INIT(reg, offset, mask, shift, init, set_clr) \
._##reg = { \
.ofs = offset, \
.msk = mask, \
.bit = shift, \
.setclr = set_clr, \
.init_config = init \
},
#define REG_DEFINE(reg, ofs, msk, bit) \
REG_DEFINE_WITH_INIT(reg, ofs, msk, bit, 0, 0)
enum {
SCP_CORE_0,
SCP_CORE_1,
SCP_MAX_CORE_NUM,
};
enum scp_dvfs_err_enum {
ESCP_REG_NOT_SUPPORTED = 1000,
ESCP_DVFS_OPP_OUT_OF_BOUND,
ESCP_DVFS_PMIC_REGULATOR_FAILED,
ESCP_DVFS_IPI_FAILED,
ESCP_DVFS_CALI_FAILED,
ESCP_DVFS_NO_CALI_CONFIG_FOUND,
ESCP_DVFS_NO_CALI_HW_FOUND,
ESCP_DVFS_DATA_RE_INIT,
ESCP_DVFS_NO_PMIC_REG_FOUND,
ESCP_DVFS_REGMAP_INIT_FAILED,
ESCP_DVFS_INIT_FAILED,
ESCP_DVFS_DBG_INVALID_CMD,
ESCP_DVFS_DVS_SHOULD_BE_BYPASSED,
};
enum scp_cmd_type {
VCORE_ACQUIRE,
RESOURCE_REQ,
ULPOSC2_TURN_ON,
ULPOSC2_TURN_OFF,
};
enum scp_req_r {
SCP_REQ_RELEASE = 0,
SCP_REQ_26M = 1 << 0,
SCP_REQ_INFRA = 1 << 1,
SCP_REQ_SYSPLL = 1 << 2,
SCP_REQ_MAX = 1 << 3,
};
enum scp_state_enum {
IN_DEBUG_IDLE = 1 << 0,
ENTERING_SLEEP = 1 << 1,
IN_SLEEP = 1 << 2,
ENTERING_ACTIVE = 1 << 3,
IN_ACTIVE = 1 << 4,
};
enum scp_sleep_config {
R_CPU_OFF = 1 << 1, /* cpu-off config: 1:enable, 0: disable */
};
enum scp_power_status {
POW_ON = 1 << 1, /* 1: cpu-on, 0: cpu-off */
};
enum {
SCP_SLEEP_OFF,
SCP_SLEEP_ON,
SCP_SLEEP_NO_WAKEUP,
SCP_SLEEP_NO_CONDITION,
SCP_SLEEP_GET_DBG_FLAG,
SCP_SLEEP_GET_COUNT,
SCP_SLEEP_RESET,
SCP_SYNC_ULPOSC_CALI,
SCP_SLEEP_BLOCK_BY_TIMER_CNI,
SCP_SLEEP_BLOCK_BY_COMPILER_CNT,
SCP_SLEEP_BLOCK_BY_SEMAPHORE_CNT,
SCP_SLEEP_BLOCK_BY_WAKELOCK_CNT,
SCP_SLEEP_BLOCK_BY_IPI_BUSY_CNT,
SCP_SLEEP_BLOCK_BY_PENDING_IRQ_CNT,
SCP_SLEEP_BLOCK_BY_SLP_DISABLED_CNT,
SCP_SLEEP_BLOCK_BY_SLP_BUSY_CNT,
SCP_SLEEP_BLOCK_BY_HARD1_BUSY_CNT,
SCP_SLEEP_CMD_MAX,
};
enum ulposc_ver_enum {
ULPOSC_VER_1, /* APMIXED_SYS */
MAX_ULPOSC_VERSION,
};
enum clk_dbg_ver_enum {
CLK_DBG_VER_1,
MAX_CLK_DBG_VERSION,
};
enum scp_clk_ver_enum {
SCP_CLK_VER_1,
MAX_SCP_CLK_VERSION,
};
enum ulposc_onoff_enum {
ULPOSC_OFF,
ULPOSC_ON,
};
struct mt_scp_pll_t {
struct clk *clk_mux;
struct clk *clk_pll[MAX_SUPPORTED_PLL_NUM];
unsigned int pll_num;
};
struct reg_info {
unsigned int ofs;
unsigned int msk;
unsigned int bit;
unsigned int setclr;
unsigned int init_config;
};
struct ulposc_cali_regs {
struct reg_info _con0;
struct reg_info _cali_ext; /* turning factor 1, maybe unused, */
struct reg_info _cali; /* turning factor 2 */
struct reg_info _con1;
struct reg_info _con2;
};
struct ulposc_cali_config {
unsigned int con0_val;
unsigned int con1_val;
unsigned int con2_val;
};
struct clk_cali_regs {
struct reg_info _clk_misc_cfg0;
struct reg_info _meter_div;
struct reg_info _clk_dbg_cfg;
struct reg_info _fmeter_ck_sel;
struct reg_info _abist_clk;
struct reg_info _clk26cali_0;
struct reg_info _fmeter_rst; /* using carefully, if set to 0, fmeter will reset */
struct reg_info _fmeter_en;
struct reg_info _trigger_cal;
struct reg_info _clk26cali_1;
struct reg_info _cal_cnt;
struct reg_info _load_cnt;
};
struct ulposc_cali_hw {
struct regmap *fmeter_regmap;
struct regmap *ulposc_regmap;
struct ulposc_cali_regs *ulposc_regs;
struct ulposc_cali_config *cali_configs;
struct clk_cali_regs *clkdbg_regs;
unsigned int cali_nums;
unsigned short *cali_val_ext;
unsigned short *cali_val;
unsigned short *cali_freq;
bool do_ulposc_cali;
bool cali_failed;
unsigned int fmeter_id_ulposc2;
};
struct scp_clk_hw {
struct regmap *scp_clk_regmap;
struct reg_info _clk_high_en;
struct reg_info _ulposc2_en;
struct reg_info _ulposc2_cg;
struct reg_info _sel_clk;
};
struct scp_pmic_regs {
struct reg_info _sshub_op_mode;
struct reg_info _sshub_op_en;
struct reg_info _sshub_op_cfg;
struct reg_info _sshub_buck_en;
struct reg_info _sshub_ldo_en;
struct reg_info _pmrc_en;
};
struct dvfs_opp {
unsigned int vcore;
unsigned int vsram;
unsigned int tuned_vcore;
unsigned int dvfsrc_opp;
unsigned int spm_opp;
unsigned int freq;
unsigned int clk_mux;
unsigned int resource_req;
unsigned int uv_idx;
};
struct scp_dvfs_hw {
struct dvfs_opp *opp;
struct regmap *pmic_regmap;
struct scp_pmic_regs *pmic_regs;
struct ulposc_cali_hw ulposc_hw;
struct scp_clk_hw *clk_hw;
bool ccf_fmeter_support; /* Has CCF provided fmeter api to use? */
int ccf_fmeter_id;
int ccf_fmeter_type;
bool vlpck_support; /* Using 2-phase calibration if vlpck_bypass_phase1 not set */
bool vlpck_bypass_phase1;
bool vlp_support; /* Moving regulator & PMIC setting into SCP side */
bool pmic_sshub_en;
bool ipi_init_done;
bool pre_mux_en;
u32 scp_opp_nums;
int vow_lp_en_gear;
int cur_dbg_core;
u32 core_nums;
};
extern int scp_pll_ctrl_set(unsigned int pll_ctrl_flag, unsigned int pll_sel);
extern int scp_request_freq(void);
extern int scp_resource_req(unsigned int req);
extern uint32_t scp_get_freq(void);
extern unsigned int scp_get_dvfs_opp(void);
extern void scp_init_vcore_request(void);
extern void scp_pll_mux_set(unsigned int pll_ctrl_flag);
extern void wait_scp_dvfs_init_done(void);
extern void sync_ulposc_cali_data_to_scp(void);
extern int __init scp_dvfs_init(void);
extern void __exit scp_dvfs_exit(void);
extern int scp_dvfs_feature_enable(void);
/* scp dvfs variable*/
extern unsigned int last_scp_expected_freq;
extern unsigned int scp_expected_freq;
extern unsigned int scp_current_freq;
extern spinlock_t scp_awake_spinlock;
#endif /* __SCP_DVFS_H__ */
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef SCP_ERR_INFO_H
#define SCP_ERR_INFO_H
#include <linux/types.h> /* for uint32_t */
/******************************************************************************
******************************************************************************/
#define ERR_MAX_CONTEXT_LEN 32
/******************************************************************************
* SCP side uses the data types err_case_id_t and err_sensor_id_t which can be
* regarded as uint32_t.
******************************************************************************/
struct error_info {
uint32_t case_id;
uint32_t sensor_id;
char context[ERR_MAX_CONTEXT_LEN];
};
#endif // SCP_ERR_INFO_H
+909
View File
@@ -0,0 +1,909 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/sysfs.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/workqueue.h>
#include <linux/io.h>
#include <linux/mutex.h>
#include <mt-plat/aee.h>
//#include <mt-plat/sync_write.h>
#include <linux/sched_clock.h>
#include <linux/ratelimit.h>
#include <linux/delay.h>
#include <linux/of.h> /* probe dts */
#include "scp.h"
#include "scp_ipi_pin.h"
#include "scp_helper.h"
#include "scp_excep.h"
#include "scp_feature_define.h"
#include "scp_l1c.h"
#if IS_ENABLED(CONFIG_OF_RESERVED_MEM)
#include <linux/of_reserved_mem.h>
#include "scp_reservedmem_define.h"
#endif
#define SCP_SECURE_DUMP_MEASURE 0
#define POLLING_RETRY 200
#define SCP_SECURE_DUMP_DEBUG 1
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM) && SCP_SECURE_DUMP_MEASURE
struct cal {
uint64_t start, end;
int type; //1:all 2:dump 3:polling
} scpdump_cal[POLLING_RETRY+1];
#endif
struct scp_dump_st {
uint8_t *detail_buff;
uint8_t *ramdump;
uint32_t ramdump_length;
/* use prefix to get size or offset in O(1) to save memory */
uint32_t prefix[MDUMP_TOTAL];
};
uint32_t scp_reg_base_phy;
struct reg_save_st {
uint32_t addr;
uint32_t size;
};
struct reg_save_st reg_save_list[] = {
/* size must 16 byte alignment */
{0x00021000, 0x120},
{0x00024000, 0x170},
{0x00030000, 0x180},
{0x00032000, 0x260},
{0x00033000, 0x120},
{0x00040000, 0x180},
{0x00042000, 0x260},
{0x00043000, 0x120},
{0x00050000, 0x330},
{0x00051000, 0x10},
{0x00051400, 0x70},
{0x00052000, 0x400},
{0x000A5000, 0x110},
{0x10001B14, 0x10},
};
//static unsigned char *scp_A_dump_buffer;
struct scp_dump_st scp_dump;
//static unsigned int scp_A_dump_length;
static unsigned int scp_A_task_context_addr;
struct scp_status_reg *c0_m = NULL;
struct scp_status_reg *c0_t1_m = NULL;
struct scp_status_reg *c1_m = NULL;
struct scp_status_reg *c1_t1_m = NULL;
void (*scp_do_tbufdump)(uint32_t*, uint32_t*) = NULL;
int scp_ee_enable;
int scp_reset_counts = 100000;
static atomic_t coredumping = ATOMIC_INIT(0);
static DECLARE_COMPLETION(scp_coredump_comp);
static uint32_t get_MDUMP_size(MDUMP_t type)
{
return scp_dump.prefix[type] - scp_dump.prefix[type - 1];
}
static uint32_t get_MDUMP_size_accumulate(MDUMP_t type)
{
return scp_dump.prefix[type];
}
static uint8_t* get_MDUMP_addr(MDUMP_t type)
{
return (uint8_t*)(scp_dump.ramdump + scp_dump.prefix[type - 1]);
}
uint32_t memorydump_size_probe(struct platform_device *pdev)
{
uint32_t i, ret;
for (i = MDUMP_L2TCM; i < MDUMP_TOTAL; ++i) {
ret = of_property_read_u32_index(pdev->dev.of_node,
"memorydump", i - 1, &scp_dump.prefix[i]);
if (ret) {
pr_notice("[SCP] %s:Cannot get memorydump size(%d)\n", __func__, i - 1);
return -1;
}
scp_dump.prefix[i] += scp_dump.prefix[i - 1];
}
return 0;
}
void scp_dump_last_regs(void)
{
c0_m->status = readl(R_CORE0_STATUS);
c0_m->pc = readl(R_CORE0_MON_PC);
c0_m->lr = readl(R_CORE0_MON_LR);
c0_m->sp = readl(R_CORE0_MON_SP);
c0_m->pc_latch = readl(R_CORE0_MON_PC_LATCH);
c0_m->lr_latch = readl(R_CORE0_MON_LR_LATCH);
c0_m->sp_latch = readl(R_CORE0_MON_SP_LATCH);
if (scpreg.twohart) {
c0_t1_m->pc = readl(R_CORE0_T1_MON_PC);
c0_t1_m->lr = readl(R_CORE0_T1_MON_LR);
c0_t1_m->sp = readl(R_CORE0_T1_MON_SP);
c0_t1_m->pc_latch = readl(R_CORE0_T1_MON_PC_LATCH);
c0_t1_m->lr_latch = readl(R_CORE0_T1_MON_LR_LATCH);
c0_t1_m->sp_latch = readl(R_CORE0_T1_MON_SP_LATCH);
}
if (scpreg.core_nums == 2) {
c1_m->status = readl(R_CORE1_STATUS);
c1_m->pc = readl(R_CORE1_MON_PC);
c1_m->lr = readl(R_CORE1_MON_LR);
c1_m->sp = readl(R_CORE1_MON_SP);
c1_m->pc_latch = readl(R_CORE1_MON_PC_LATCH);
c1_m->lr_latch = readl(R_CORE1_MON_LR_LATCH);
c1_m->sp_latch = readl(R_CORE1_MON_SP_LATCH);
}
if (scpreg.core_nums == 2 && scpreg.twohart) {
c1_t1_m->pc = readl(R_CORE1_T1_MON_PC);
c1_t1_m->lr = readl(R_CORE1_T1_MON_LR);
c1_t1_m->sp = readl(R_CORE1_T1_MON_SP);
c1_t1_m->pc_latch = readl(R_CORE1_T1_MON_PC_LATCH);
c1_t1_m->lr_latch = readl(R_CORE1_T1_MON_LR_LATCH);
c1_t1_m->sp_latch = readl(R_CORE1_T1_MON_SP_LATCH);
}
scp_dump_bus_tracker_status();
}
void scp_show_last_regs(void)
{
pr_notice("[SCP] c0h0_status = %08x\n", c0_m->status);
pr_notice("[SCP] c0h0_pc = %08x\n", c0_m->pc);
pr_notice("[SCP] c0h0_lr = %08x\n", c0_m->lr);
pr_notice("[SCP] c0h0_sp = %08x\n", c0_m->sp);
pr_notice("[SCP] c0h0_pc_latch = %08x\n", c0_m->pc_latch);
pr_notice("[SCP] c0h0_lr_latch = %08x\n", c0_m->lr_latch);
pr_notice("[SCP] c0h0_sp_latch = %08x\n", c0_m->sp_latch);
if (scpreg.twohart) {
pr_notice("[SCP] c0h1_pc = %08x\n", c0_t1_m->pc);
pr_notice("[SCP] c0h1_lr = %08x\n", c0_t1_m->lr);
pr_notice("[SCP] c0h1_sp = %08x\n", c0_t1_m->sp);
pr_notice("[SCP] c0h1_pc_latch = %08x\n", c0_t1_m->pc_latch);
pr_notice("[SCP] c0h1_lr_latch = %08x\n", c0_t1_m->lr_latch);
pr_notice("[SCP] c0h1_sp_latch = %08x\n", c0_t1_m->sp_latch);
}
if (scpreg.core_nums == 2) {
pr_notice("[SCP] c1h0_status = %08x\n", c1_m->status);
pr_notice("[SCP] c1h0_pc = %08x\n", c1_m->pc);
pr_notice("[SCP] c1h0_lr = %08x\n", c1_m->lr);
pr_notice("[SCP] c1h0_sp = %08x\n", c1_m->sp);
pr_notice("[SCP] c1h0_pc_latch = %08x\n", c1_m->pc_latch);
pr_notice("[SCP] c1h0_lr_latch = %08x\n", c1_m->lr_latch);
pr_notice("[SCP] c1h0_sp_latch = %08x\n", c1_m->sp_latch);
}
if (scpreg.core_nums == 2 && scpreg.twohart) {
pr_notice("[SCP] c1h1_pc = %08x\n", c1_t1_m->pc);
pr_notice("[SCP] c1h1_lr = %08x\n", c1_t1_m->lr);
pr_notice("[SCP] c1h1_sp = %08x\n", c1_t1_m->sp);
pr_notice("[SCP] c1h1_pc_latch = %08x\n", c1_t1_m->pc_latch);
pr_notice("[SCP] c1h1_lr_latch = %08x\n", c1_t1_m->lr_latch);
pr_notice("[SCP] c1h1_sp_latch = %08x\n", c1_t1_m->sp_latch);
}
scp_show_bus_tracker_status();
}
void scp_dump_bus_tracker_status(void)
{
uint32_t offset;
uint64_t __iomem *bus_dbg_read_l;
uint64_t __iomem *bus_dbg_write_l;
int i, j;
struct scp_bus_tracker_status *bus_tracker;
bus_tracker = &scpreg.tracker_status;
bus_tracker->dbg_con = readl(SCP_BUS_DBG_CON);
for (i = 3; i >= 0; --i) {
offset = i << 3;
bus_dbg_read_l = ((uint64_t *)SCP_BUS_DBG_AR_TRACK0_L) + offset;
bus_dbg_write_l = ((uint64_t *)SCP_BUS_DBG_AW_TRACK0_L) + offset;
if (!readl(bus_dbg_read_l + 7) && !readl(bus_dbg_write_l + 7))
continue;
for (j = 7; j >= 0; --j) {
bus_tracker->dbg_r[offset + j] =
readl(bus_dbg_read_l + j);
bus_tracker->dbg_w[offset + j] =
readl(bus_dbg_write_l + j);
}
}
}
void scp_show_bus_tracker_status(void)
{
uint32_t offset;
int i;
struct scp_bus_tracker_status *bus_tracker;
bus_tracker = &scpreg.tracker_status;
pr_notice("BUS DBG CON: %x\n", bus_tracker->dbg_con);
for (i = 3; i >= 0; --i) {
offset = i << 3;
if (!bus_tracker->dbg_r[offset + 7])
continue;
pr_notice("R[%u-%u] %08x %08x %08x %08x %08x %08x %08x %08x\n",
offset, offset + 7,
bus_tracker->dbg_r[offset],
bus_tracker->dbg_r[offset + 1],
bus_tracker->dbg_r[offset + 2],
bus_tracker->dbg_r[offset + 3],
bus_tracker->dbg_r[offset + 4],
bus_tracker->dbg_r[offset + 5],
bus_tracker->dbg_r[offset + 6],
bus_tracker->dbg_r[offset + 7]);
pr_notice("W[%u-%u] %08x %08x %08x %08x %08x %08x %08x %08x\n",
offset, offset + 7,
bus_tracker->dbg_w[offset],
bus_tracker->dbg_w[offset + 1],
bus_tracker->dbg_w[offset + 2],
bus_tracker->dbg_w[offset + 3],
bus_tracker->dbg_w[offset + 4],
bus_tracker->dbg_w[offset + 5],
bus_tracker->dbg_w[offset + 6],
bus_tracker->dbg_w[offset + 7]);
}
}
void scp_do_regdump(uint32_t *out, uint32_t *out_end)
{
int i = 0;
void *from;
uint32_t *buf = out;
int size_limit = sizeof(reg_save_list) / sizeof(struct reg_save_st);
for (i = 0; i < size_limit; i++) {
if (((void *)buf + reg_save_list[i].size
+ sizeof(struct reg_save_st)) > (void *)out_end) {
pr_notice("[SCP] %s overflow\n", __func__);
break;
}
*buf = reg_save_list[i].addr;
buf++;
*buf = reg_save_list[i].size;
buf++;
from = scp_regdump_virt + (reg_save_list[i].addr & 0xfffff);
if ((reg_save_list[i].addr & 0xfff00000) < 0x10700000)
from = scpreg.scpsys + (reg_save_list[i].addr & 0xfff);
memcpy_from_scp(buf, from, reg_save_list[i].size);
buf += (reg_save_list[i].size / sizeof(uint32_t));
}
}
void scp_do_l1cdump(uint32_t *out, uint32_t *out_end)
{
uint32_t *buf = out;
uint32_t tmp;
uint32_t l1c_size = get_MDUMP_size(MDUMP_L1C);
tmp = readl(R_SEC_CTRL);
/* enable cache debug */
writel(tmp | B_CORE0_CACHE_DBG_EN | B_CORE1_CACHE_DBG_EN, R_SEC_CTRL);
if ((void *)buf + l1c_size > (void *)out_end) {
pr_notice("[SCP] %s overflow\n", __func__);
return;
}
memcpy_from_scp(buf, R_CORE0_CACHE_RAM, l1c_size);
/* disable cache debug */
writel(tmp, R_SEC_CTRL);
}
void scp_do_tbufdump_RV33(uint32_t *out, uint32_t *out_end)
{
uint32_t *buf = out;
uint32_t tmp, index, offset, wbuf_ptr;
int i;
wbuf_ptr = readl(R_CORE0_TBUF_WPTR);
tmp = readl(R_CORE0_DBG_CTRL) & (~M_CORE_TBUF_DBG_SEL);
for (i = 0; i < 16; i++) {
index = (wbuf_ptr + i) / 2;
offset = ((wbuf_ptr + i) % 2) * 0x8;
writel(tmp | (index << S_CORE_TBUF_DBG_SEL), R_CORE0_DBG_CTRL);
*(buf) = readl(R_CORE0_TBUF_DATA31_0 + offset);
*(buf + 1) = readl(R_CORE0_TBUF_DATA63_32 + offset);
buf += 2;
}
wbuf_ptr = readl(R_CORE1_TBUF_WPTR);
tmp = readl(R_CORE1_DBG_CTRL) & (~M_CORE_TBUF_DBG_SEL);
for (i = 0; i < 16; i++) {
index = (wbuf_ptr + i) / 2;
offset = ((wbuf_ptr + i) % 2) * 0x8;
writel(tmp | (index << S_CORE_TBUF_DBG_SEL), R_CORE1_DBG_CTRL);
*(buf) = readl(R_CORE1_TBUF_DATA31_0 + offset);
*(buf + 1) = readl(R_CORE1_TBUF_DATA63_32 + offset);
buf += 2;
}
for (i = 0; i < 16; i++) {
pr_notice("[SCP] C0:%02d:0x%08x::0x%08x\n",
i, *(out + i * 2), *(out + i * 2 + 1));
}
for (i = 0; i < 16; i++) {
pr_notice("[SCP] C1:%02d:0x%08x::0x%08x\n",
i, *(out + i * 2 + 16), *(out + i * 2 + 17));
}
}
void scp_do_tbufdump_RV55(uint32_t *out, uint32_t *out_end)
{
uint32_t *buf = out;
uint32_t tmp, tmp1, index, offset, wbuf_ptr, wbuf1_ptr;
int i;
wbuf1_ptr = readl(R_CORE0_TBUF_WPTR);
wbuf_ptr = wbuf1_ptr & 0x1f;
wbuf1_ptr = wbuf1_ptr >> 8;
tmp = readl(R_CORE0_DBG_CTRL) & M_CORE_TBUF_DBG_SEL_RV55;
for (i = 0; i < 32; i++) {
index = ((wbuf_ptr + i) / 4) & 0x7;
offset = ((wbuf_ptr + i) % 4) * 0x8;
tmp1 = (index << S_CORE_TBUF_S) | (index << S_CORE_TBUF1_S);
writel(tmp | tmp1, R_CORE0_DBG_CTRL);
*(buf) = readl(R_CORE0_TBUF_DATA31_0 + offset);
*(buf + 1) = readl(R_CORE0_TBUF_DATA63_32 + offset);
buf += 2;
}
for (i = 0; i < 32; i++) {
pr_notice("[SCP] C0:H0:%02d:0x%08x::0x%08x\n",
i, *(out + i * 2), *(out + i * 2 + 1));
}
for (i = 0; i < 32; i++) {
index = (((wbuf1_ptr + i) / 4) & 0x7) | 0x8;
offset = ((wbuf1_ptr + i) % 4) * 0x8;
tmp1 = (index << S_CORE_TBUF_S) | (index << S_CORE_TBUF1_S);
writel(tmp | tmp1, R_CORE0_DBG_CTRL);
*(buf) = readl(R_CORE0_TBUF_DATA31_0 + offset);
*(buf + 1) = readl(R_CORE0_TBUF_DATA63_32 + offset);
buf += 2;
}
for (i = 0; i < 32; i++) {
pr_notice("[SCP] C0:H1:%02d:0x%08x::0x%08x\n",
i, *(out + 64 + i * 2), *(out + 64 + i * 2 + 1));
}
if (scpreg.core_nums == 1)
return;
wbuf1_ptr = readl(R_CORE1_TBUF_WPTR);
wbuf_ptr = wbuf1_ptr & 0x1f;
wbuf1_ptr = wbuf1_ptr >> 8;
tmp = readl(R_CORE1_DBG_CTRL) & M_CORE_TBUF_DBG_SEL_RV55;
for (i = 0; i < 32; i++) {
index = ((wbuf_ptr + i) / 4) & 0x7;
offset = ((wbuf_ptr + i) % 4) * 0x8;
tmp1 = (index << S_CORE_TBUF_S) | (index << S_CORE_TBUF1_S);
writel(tmp | tmp1, R_CORE1_DBG_CTRL);
*(buf) = readl(R_CORE1_TBUF_DATA31_0 + offset);
*(buf + 1) = readl(R_CORE1_TBUF_DATA63_32 + offset);
buf += 2;
}
for (i = 0; i < 32; i++) {
pr_notice("[SCP] C1:H0:%02d:0x%08x::0x%08x\n",
i, *(out + i * 2), *(out + i * 2 + 1));
}
for (i = 0; i < 32; i++) {
index = (((wbuf1_ptr + i) / 4) & 0x7) | 0x8;
offset = ((wbuf1_ptr + i) % 4) * 0x8;
tmp1 = (index << S_CORE_TBUF_S) | (index << S_CORE_TBUF1_S);
writel(tmp | tmp1, R_CORE1_DBG_CTRL);
*(buf) = readl(R_CORE1_TBUF_DATA31_0 + offset);
*(buf + 1) = readl(R_CORE1_TBUF_DATA63_32 + offset);
buf += 2;
}
for (i = 0; i < 32; i++) {
pr_notice("[SCP] C1:H1:%02d:0x%08x::0x%08x\n",
i, *(out + 64 + i * 2), *(out + 64 + i * 2 + 1));
}
}
/*
* this function need SCP to keeping awaken
* scp_crash_dump: dump scp tcm info.
* @param scp_core_id: core id
* @return: scp dump size
*/
static unsigned int scp_crash_dump(enum scp_core_id id)
{
unsigned int scp_dump_size;
unsigned int scp_awake_fail_flag;
uint32_t dram_start = 0;
uint32_t dram_size = 0;
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM) && SCP_SECURE_DUMP_MEASURE
int idx;
#endif
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
uint64_t dump_start, dump_end;
#endif
/*flag use to indicate scp awake success or not*/
scp_awake_fail_flag = 0;
/*check SRAM lock ,awake scp*/
if (scp_awake_lock((void *)id) == -1) {
pr_notice("[SCP] %s: awake scp fail, scp id=%u\n", __func__, id);
scp_awake_fail_flag = 1;
}
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
if (scpreg.secure_dump) {
#if SCP_SECURE_DUMP_MEASURE
memset(scpdump_cal, 0x0, sizeof(scpdump_cal));
idx = 0;
scpdump_cal[0].type = 1;
scpdump_cal[0].start = ktime_get_boot_ns();
#endif
dump_start = ktime_get_boot_ns();
{
int polling = 1;
int retry = POLLING_RETRY;
#if SCP_SECURE_DUMP_MEASURE
idx++;
scpdump_cal[idx].type = 2;
scpdump_cal[idx].start = ktime_get_boot_ns();
#endif
scp_do_dump();
#if SCP_SECURE_DUMP_MEASURE
scpdump_cal[idx].end = ktime_get_boot_ns();
#endif
while (polling != 0 && retry > 0) {
#if SCP_SECURE_DUMP_MEASURE
if (idx >= POLLING_RETRY)
break;
idx++;
scpdump_cal[idx].type = 3;
scpdump_cal[idx].start = ktime_get_boot_ns();
#endif
polling = scp_do_polling();
#if SCP_SECURE_DUMP_MEASURE
scpdump_cal[idx].end = ktime_get_boot_ns();
#endif
if (!polling)
break;
mdelay(polling);
retry--;
}
if (retry == 0) {
pr_notice("[SCP] Dump timed out:%d\n", POLLING_RETRY);
#if SCP_SECURE_DUMP_DEBUG
pr_notice("[SCP] Dump timeout dump once again.\n");
print_clk_registers();
#endif
}
}
dump_end = ktime_get_boot_ns();
pr_notice("[SCP] Dump: %lld ns\n", (dump_end - dump_start));
#if SCP_SECURE_DUMP_MEASURE
scpdump_cal[0].end = ktime_get_boot_ns();
for (idx = 0; idx < POLLING_RETRY; idx++) {
if (scpdump_cal[idx].type == 0)
break;
pr_notice("[SCP] scpdump:%d Type:%d %lldns\n", idx, scpdump_cal[idx].type,
(scpdump_cal[idx].end - scpdump_cal[idx].start));
}
#endif
/* tbuf is different between rv33/rv55 */
if (scpreg.twohart) {
/* RV55 */
uint32_t *out = (uint32_t *)get_MDUMP_addr(MDUMP_TBUF);
int i;
for (i = 0; i < 32; i++) {
pr_notice("[SCP] C0:H0:%02d:0x%08x::0x%08x\n",
i, *(out + i * 2), *(out + i * 2 + 1));
}
for (i = 0; i < 32; i++) {
pr_notice("[SCP] C0:H1:%02d:0x%08x::0x%08x\n",
i, *(out + 64 + i * 2), *(out + 64 + i * 2 + 1));
}
if (scpreg.core_nums > 1) {
for (i = 0; i < 32; i++) {
pr_notice("[SCP] C1:H0:%02d:0x%08x::0x%08x\n",
i, *(out + 128 + i * 2), *(out + 128 + i * 2 + 1));
}
for (i = 0; i < 32; i++) {
pr_notice("[SCP] C1:H1:%02d:0x%08x::0x%08x\n",
i, *(out + 192 + i * 2), *(out + 192 + i * 2 + 1));
}
}
} else {
/* RV33 */
uint32_t *out = (uint32_t *)get_MDUMP_addr(MDUMP_TBUF);
int i;
for (i = 0; i < 16; i++) {
pr_notice("[SCP] C0:%02d:0x%08x::0x%08x\n",
i, *(out + i * 2), *(out + i * 2 + 1));
}
for (i = 0; i < 16; i++) {
pr_notice("[SCP] C1:%02d:0x%08x::0x%08x\n",
i, *(out + i * 2 + 16), *(out + i * 2 + 17));
}
}
scp_dump_size = get_MDUMP_size_accumulate(MDUMP_TBUF);
/* dram support? */
if ((int)(scp_region_info_copy.ap_dram_size) <= 0) {
pr_notice("[scp] ap_dram_size <=0\n");
} else {
dram_start = scp_region_info_copy.ap_dram_start;
dram_size = scp_region_info_copy.ap_dram_size;
scp_dump_size += roundup(dram_size, 4);
}
} else {
#else
{
#endif
memcpy_from_scp((void *)get_MDUMP_addr(MDUMP_L2TCM),
(void *)(SCP_TCM),
(SCP_A_TCM_SIZE));
scp_do_l1cdump((void *)get_MDUMP_addr(MDUMP_L1C),
(void *)get_MDUMP_addr(MDUMP_REGDUMP));
/* dump sys registers */
scp_do_regdump((void *)get_MDUMP_addr(MDUMP_REGDUMP),
(void *)get_MDUMP_addr(MDUMP_TBUF));
scp_do_tbufdump((void *)get_MDUMP_addr(MDUMP_TBUF),
(void *)get_MDUMP_addr(MDUMP_DRAM));
scp_dump_size = get_MDUMP_size_accumulate(MDUMP_TBUF);
/* dram support? */
if ((int)(scp_region_info_copy.ap_dram_size) <= 0) {
pr_notice("[scp] ap_dram_size <=0\n");
} else {
dram_start = scp_region_info_copy.ap_dram_start;
dram_size = scp_region_info_copy.ap_dram_size;
/* copy dram data*/
memcpy((void *)get_MDUMP_addr(MDUMP_DRAM),
scp_ap_dram_virt, dram_size);
scp_dump_size += roundup(dram_size, 4);
}
}
dsb(SY); /* may take lot of time */
/*check SRAM unlock*/
if (scp_awake_fail_flag != 1) {
if (scp_awake_unlock((void *)id) == -1)
pr_debug("[SCP]%s awake unlock fail, scp id=%u\n",
__func__, id);
}
return scp_dump_size;
}
/*
* generate aee argument with scp register dump
* @param aed_str: exception description
* @param id: identify scp core id
*/
static void scp_prepare_aed_dump(char *aed_str,
enum scp_core_id id)
{
char *scp_A_log = NULL;
size_t offset = 0;
pr_debug("[SCP] %s begins:%s\n", __func__, aed_str);
scp_dump_last_regs();
scp_show_last_regs();
scp_A_log = scp_pickup_log_for_aee();
if (scp_dump.detail_buff == NULL) {
pr_notice("[SCP AEE]detail buf is null\n");
} else {
/* prepare scp aee detail information*/
memset(scp_dump.detail_buff, 0, SCP_AED_STR_LEN);
offset += SCP_CHECK_AED_STR_LEN(snprintf(scp_dump.detail_buff + offset,
SCP_AED_STR_LEN - offset, "%s\n", aed_str), offset);
offset += SCP_CHECK_AED_STR_LEN(snprintf(scp_dump.detail_buff + offset,
SCP_AED_STR_LEN - offset,
"core0 pc=0x%08x, lr=0x%08x, sp=0x%08x\n",
c0_m->pc, c0_m->lr, c0_m->sp), offset);
if (!scpreg.twohart)
goto core1;
offset += SCP_CHECK_AED_STR_LEN(snprintf(scp_dump.detail_buff + offset,
SCP_AED_STR_LEN - offset,
"hart1 pc=0x%08x, lr=0x%08x, sp=0x%08x\n",
c0_t1_m->pc, c0_t1_m->lr, c0_t1_m->sp), offset);
core1:
if (scpreg.core_nums == 1)
goto end;
offset += SCP_CHECK_AED_STR_LEN(snprintf(scp_dump.detail_buff + offset,
SCP_AED_STR_LEN - offset,
"core1 pc=0x%08x, lr=0x%08x, sp=0x%08x\n",
c1_m->pc, c1_m->lr, c1_m->sp), offset);
if (!scpreg.twohart)
goto end;
offset += SCP_CHECK_AED_STR_LEN(snprintf(scp_dump.detail_buff + offset,
SCP_AED_STR_LEN - offset,
"hart1 pc=0x%08x, lr=0x%08x, sp=0x%08x\n",
c1_t1_m->pc, c1_t1_m->lr, c1_t1_m->sp), offset);
end:
offset += SCP_CHECK_AED_STR_LEN(snprintf(scp_dump.detail_buff + offset,
SCP_AED_STR_LEN - offset, "last log:\n%s", scp_A_log), offset);
scp_dump.detail_buff[SCP_AED_STR_LEN - 1] = '\0';
}
/*prepare scp A db file*/
scp_dump.ramdump_length = 0;
scp_dump.ramdump_length = scp_crash_dump(SCP_A_ID);
pr_notice("[SCP] %s ends, @%p, size = %x\n", __func__,
scp_dump.ramdump, scp_dump.ramdump_length);
}
/*
* generate an exception according to exception type
* NOTE: this function may be blocked and
* should not be called in interrupt context
* @param type: exception type
*/
void scp_aed(enum SCP_RESET_TYPE type, enum scp_core_id id)
{
char *scp_aed_title = NULL;
size_t timeout = msecs_to_jiffies(SCP_COREDUMP_TIMEOUT_MS);
size_t expire = jiffies + timeout;
int ret;
if (!scp_ee_enable) {
pr_debug("[SCP]ee disable value=%d\n", scp_ee_enable);
return;
}
/* wait for previous coredump complete */
while (1) {
ret = wait_for_completion_interruptible_timeout(
&scp_coredump_comp, timeout);
if (ret == 0) {
pr_notice("[SCP] %s:TIMEOUT, skip\n",
__func__);
break;
}
if (ret > 0)
break;
if ((ret == -ERESTARTSYS) && time_before(jiffies, expire)) {
pr_debug("[SCP] %s: continue waiting for completion\n",
__func__);
timeout = expire - jiffies;
continue;
}
}
if (atomic_read(&coredumping) == true)
pr_notice("[SCP] coredump overwrite happen\n");
atomic_set(&coredumping, true);
/* get scp title and exception type*/
switch (type) {
case RESET_TYPE_WDT:
if (id == SCP_A_ID)
scp_aed_title = "SCP_A wdt reset";
else
scp_aed_title = "SCP_B wdt reset";
break;
case RESET_TYPE_AWAKE:
if (id == SCP_A_ID)
scp_aed_title = "SCP_A awake reset";
else
scp_aed_title = "SCP_B awake reset";
break;
case RESET_TYPE_CMD:
if (id == SCP_A_ID)
scp_aed_title = "SCP_A cmd reset";
else
scp_aed_title = "SCP_B cmd reset";
break;
case RESET_TYPE_TIMEOUT:
if (id == SCP_A_ID)
scp_aed_title = "SCP_A timeout reset";
else
scp_aed_title = "SCP_B timeout reset";
break;
}
scp_get_log(id);
/*print scp message*/
pr_debug("scp_aed_title=%s\n", scp_aed_title);
scp_prepare_aed_dump(scp_aed_title, id);
#if IS_ENABLED(CONFIG_MTK_AEE_AED)
/* scp aed api, only detail information available*/
aed_common_exception_api("scp", NULL, 0, NULL, 0,
scp_dump.detail_buff, DB_OPT_DEFAULT);
#endif
pr_debug("[SCP] scp exception dump is done\n");
}
static ssize_t scp_A_dump_show(struct file *filep,
struct kobject *kobj, struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
unsigned int length = 0;
if (offset >= 0 && offset < scp_dump.ramdump_length) {
if ((offset + size) >= scp_dump.ramdump_length)
size = scp_dump.ramdump_length - offset;
memcpy(buf, scp_dump.ramdump + offset, size);
length = size;
/* clean the buff after readed */
memset(scp_dump.ramdump + offset, 0x0, size);
/* log for the first and latest cleanup */
if (offset == 0 || size == (scp_dump.ramdump_length - offset))
pr_notice("[SCP] %s ramdump cleaned of:0x%llx sz:0x%lx\n", __func__,
offset, size);
/* the last time read scp_dump buffer has done
* so the next coredump flow can be continued
*/
if (size == scp_dump.ramdump_length - offset) {
atomic_set(&coredumping, false);
pr_notice("[SCP] coredumping:%d, coredump complete\n",
atomic_read(&coredumping));
complete(&scp_coredump_comp);
}
}
return length;
}
struct bin_attribute bin_attr_scp_dump = {
.attr = {
.name = "scp_dump",
.mode = 0444,
},
.size = 0,
.read = scp_A_dump_show,
};
/*
* init a work struct
*/
int scp_excep_init(void)
{
int dram_size = 0;
int i;
int size_limit = sizeof(reg_save_list) / sizeof(struct reg_save_st);
/* last addr is infra */
for (i = 0; i < size_limit - 1; i++)
reg_save_list[i].addr |= scp_reg_base_phy;
/* alloc dump memory */
scp_dump.detail_buff = vmalloc(SCP_AED_STR_LEN);
if (!scp_dump.detail_buff)
return -1;
/* support L1C or not? */
if ((int)(scp_region_info->ap_dram_size) > 0)
dram_size = scp_region_info->ap_dram_size;
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
if (scpreg.secure_dump) {
scp_dump.ramdump =
(uint8_t *)(void *)scp_get_reserve_mem_virt(SCP_A_SECDUMP_MEM_ID);
if (!scp_dump.ramdump)
return -1;
} else {
#else
{
#endif
scp_dump.ramdump = vmalloc(get_MDUMP_size_accumulate(MDUMP_DRAM));
if (!scp_dump.ramdump)
return -1;
}
memset(scp_dump.ramdump, 0x0, get_MDUMP_size_accumulate(MDUMP_DRAM));
pr_notice("[SCP] %s cleaned ramdump\n", __func__);
/* scp_status_reg init */
c0_m = vmalloc(sizeof(struct scp_status_reg));
if (!c0_m)
return -1;
if (scpreg.twohart) {
c0_t1_m = vmalloc(sizeof(struct scp_status_reg));
if (!c0_t1_m)
return -1;
}
if (scpreg.core_nums == 2) {
c1_m = vmalloc(sizeof(struct scp_status_reg));
if (!c1_m)
return -1;
}
if (scpreg.core_nums == 2 && scpreg.twohart) {
c1_t1_m = vmalloc(sizeof(struct scp_status_reg));
if (!c1_t1_m)
return -1;
}
/* scp_do_tbufdump init, because tbuf is different between rv33/rv55 */
if (scpreg.twohart)
scp_do_tbufdump = scp_do_tbufdump_RV55;
else
scp_do_tbufdump = scp_do_tbufdump_RV33;
/* init global values */
scp_dump.ramdump_length = 0;
/* 1: ee on, 0: ee disable */
scp_ee_enable = 1;
/* all coredump need element is prepare done */
complete(&scp_coredump_comp);
return 0;
}
/******************************************************************************
* This function is called in the interrupt context. Note that scp_region_info
* was initialized in scp_region_info_init() which must be called before this
* function is called.
*****************************************************************************/
void scp_ram_dump_init(void)
{
scp_A_task_context_addr = scp_region_info->TaskContext_ptr;
pr_debug("[SCP] get scp_A_task_context_addr: 0x%x\n",
scp_A_task_context_addr);
}
/*
* cleanup scp exception
*/
void scp_excep_cleanup(void)
{
vfree(scp_dump.detail_buff);
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
if (scpreg.secure_dump) {
scp_dump.ramdump = NULL;
} else {
#else
{
#endif
vfree(scp_dump.ramdump);
}
scp_A_task_context_addr = 0;
pr_debug("[SCP] %s ends\n", __func__);
}
+71
View File
@@ -0,0 +1,71 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_EXCEP_H__
#define __SCP_EXCEP_H__
#include <linux/sizes.h>
#include "scp_helper.h"
#include "scp_ipi_pin.h"
#define AED_LOG_PRINT_SIZE SZ_16K
#define SCP_LOCK_OFS 0xE0
#define SCP_TCM_LOCK_BIT (1 << 20)
#define SCP_COREDUMP_TIMEOUT_MS (3 * 60 * 1000) /* 3min */
enum scp_excep_id {
EXCEP_RESET,
EXCEP_BOOTUP,
EXCEP_RUNTIME,
SCP_NR_EXCEP,
};
struct scp_status_reg {
uint32_t status;
uint32_t pc;
uint32_t lr;
uint32_t sp;
uint32_t pc_latch;
uint32_t lr_latch;
uint32_t sp_latch;
};
extern void scp_dump_last_regs(void);
extern void scp_dump_bus_tracker_status(void);
extern void scp_show_last_regs(void);
extern void scp_show_bus_tracker_status(void);
extern void scp_aed(enum SCP_RESET_TYPE type, enum scp_core_id id);
extern void scp_aed_reset(enum scp_excep_id type, enum scp_core_id id);
extern void scp_aed_reset_inplace(enum scp_excep_id type,
enum scp_core_id id);
extern void scp_get_log(enum scp_core_id id);
extern char *scp_pickup_log_for_aee(void);
extern void aed_scp_exception_api(const int *log, int log_size,
const int *phy, int phy_size, const char *detail,
const int db_opt);
extern void scp_excep_cleanup(void);
extern void print_clk_registers(void);
extern uint32_t memorydump_size_probe(struct platform_device *pdev);
enum { r0, r1, r2, r3, r12, lr, pc, psr};
extern int scp_ee_enable;
extern int scp_reset_counts;
extern struct scp_status_reg *c0_m;
extern struct scp_status_reg *c0_t1_m;
extern struct scp_status_reg *c1_m;
extern struct scp_status_reg *c1_t1_m;
extern uint32_t scp_reg_base_phy;
typedef enum MDUMP {
MDUMP_DUMMY,
MDUMP_L2TCM,
MDUMP_L1C,
MDUMP_REGDUMP,
MDUMP_TBUF,
MDUMP_DRAM,
MDUMP_TOTAL
} MDUMP_t;
#endif
@@ -0,0 +1,125 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_FEATURE_DEFINE_H__
#define __SCP_FEATURE_DEFINE_H__
#include "scp.h"
/* scp platform configs*/
#define SCP_BOOT_TIME_OUT_MONITOR (1)
#define SCP_RESERVED_MEM (1)
#ifdef CONFIG_MTK_TINYSYS_SCP_LOGGER_SUPPORT
#define SCP_LOGGER_ENABLE (1)
#else
#define SCP_LOGGER_ENABLE (0)
#endif
#define SCP_VOW_LOW_POWER_MODE (1)
#define SCP_DEBUG_NODE_ENABLE (0)
/* scp rescovery feature option*/
#define SCP_RECOVERY_SUPPORT (1)
/* scp recovery timeout value (ms)*/
#define SCP_SYS_RESET_TIMEOUT 1000
#define SCP_PARAMS_TO_SCP_SUPPORT
/* scp aed definition*/
#define SCP_AED_STR_LEN (512)
#define SCP_CHECK_AED_STR_LEN(func, offset) ({\
int ret; ret = func; ((ret > 0) && ((ret + offset) < (SCP_AED_STR_LEN - 1))) ? ret : 0; })
/* scp sub feature register API marco*/
#define SCP_REGISTER_SUB_SENSOR (1)
/* emi mpu define*/
#define ENABLE_SCP_EMI_PROTECTION (1)
#define MPU_REGION_ID_SCP_SMEM 7
#define MPU_DOMAIN_D0 0
#define MPU_DOMAIN_D3 3
#define SCPSYS_CORE0 0
#define SCPSYS_CORE1 1
/* scp sensor type ID list */
enum scp_sensor_id {
ACCELEROMETER_FEATURE_ID = 0,
MAGNETIC_FEATURE_ID,
ORIENTATION_FEATURE_ID,
GYROSCOPE_FEATURE_ID,
LIGHT_FEATURE_ID,
PRESSURE_FEATURE_ID,
TEMPRERATURE_FEATURE_ID,
PROXIMITY_FEATURE_ID,
GRAVITY_FEATURE_ID,
LINEAR_ACCELERATION_FEATURE_ID,
ROTATION_VECTOR_FEATURE_ID,
RELATIVE_HUMIDITY_FEATURE_ID,
AMBIENT_TEMPERATURE_FEATURE_ID,
MAGNETIC_UNCALIBRATED_FEATURE_ID,
GAME_ROTATION_VECTOR_FEATURE_ID,
GYROSCOPE_UNCALIBRATED_FEATURE_ID,
SIGNIFICANT_MOTION_FEATURE_ID,
STEP_DETECTOR_FEATURE_ID,
STEP_COUNTER_FEATURE_ID,
GEOMAGNETIC_ROTATION_VECTOR_FEATURE_ID,
HEART_RATE_FEATURE_ID,
TILT_DETECTOR_FEATURE_ID,
WAKE_GESTURE_FEATURE_ID,
GLANCE_GESTURE_FEATURE_ID,
PICK_UP_GESTURE_FEATURE_ID,
WRIST_TITL_GESTURE_FEATURE_ID,
DEVICE_ORIENTATION_FEATURE_ID,
POSE_6DOF_FEATURE_ID,
STATIONARY_DETECT_FEATURE_ID,
MOTION_DETECT_FEATURE_ID,
HEART_BEAT_FEATURE_ID,
DYNAMIC_SENSOR_META_FEATURE_ID,
ADDITIONAL_INFO_FEATURE_ID,
PEDOMETER_FEATURE_ID = 34,
IN_POCKET_FEATURE_ID,
ACTIVITY_FEATURE_ID,
PDR_FEATURE_ID,
FREEFALL_FEATURE_ID,
ACCELEROMETER_UNCALIBRATED_FEATURE_ID,
FACE_DOWN_FEATURE_ID,
SHAKE_FEATURE_ID,
BRINGTOSEE_FEATURE_ID,
ANSWER_CALL_FEATURE_ID,
GEOFENCE_FEATURE_ID,
FLOOR_COUNTER_FEATURE_ID,
EKG_FEATURE_ID,
PPG1_FEATURE_ID,
PPG2_FEATURE_ID,
NUM_SENSOR_TYPE,
};
struct scp_feature_tb {
uint32_t feature:5, /* max = 31 */
freq:10, /* max = 1023 */
enable:1, /* max = 1 */
sys_id:1; /* max = 1, run at which subsys? */
};
struct scp_sub_feature_tb {
uint32_t feature:6, /* max = 63 */
freq:9, /* max = 511 */
enable:1; /* max = 1 */
};
extern struct scp_feature_tb feature_table[NUM_FEATURE_ID];
extern struct scp_sub_feature_tb sensor_type_table[NUM_SENSOR_TYPE];
extern void scp_register_sensor(enum feature_id id,
enum scp_sensor_id sensor_id);
extern void scp_deregister_sensor(enum feature_id id,
enum scp_sensor_id sensor_id);
#endif
@@ -0,0 +1,156 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#include <linux/module.h> /* needed by all modules */
#include "scp_feature_define.h"
#include "scp_ipi_pin.h"
#include "scp.h"
/*scp feature list*/
struct scp_feature_tb feature_table[NUM_FEATURE_ID] = {
/* VFFP:20 + default:5 */
{
.feature = VOW_FEATURE_ID,
},
{
.feature = SENS_FEATURE_ID,
},
{
.feature = FLP_FEATURE_ID,
},
{
.feature = RTOS_FEATURE_ID,
},
{
.feature = SPEAKER_PROTECT_FEATURE_ID,
},
{
.feature = VCORE_TEST_FEATURE_ID,
},
{
.feature = VOW_BARGEIN_FEATURE_ID,
},
{
.feature = VOW_DUMP_FEATURE_ID,
},
{
.feature = VOW_VENDOR_M_FEATURE_ID,
},
{
.feature = VOW_VENDOR_A_FEATURE_ID,
},
{
.feature = VOW_VENDOR_G_FEATURE_ID,
},
{
.feature = VOW_DUAL_MIC_FEATURE_ID,
},
{
.feature = VOW_DUAL_MIC_BARGE_IN_FEATURE_ID,
},
{
.feature = ULTRA_FEATURE_ID,
},
};
/*scp sensor type list*/
struct scp_sub_feature_tb sensor_type_table[NUM_SENSOR_TYPE] = {
{
.feature = ACCELEROMETER_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = MAGNETIC_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = ORIENTATION_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = GYROSCOPE_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = LIGHT_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = PROXIMITY_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = PRESSURE_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = STEP_COUNTER_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = SIGNIFICANT_MOTION_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = STEP_DETECTOR_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = GLANCE_GESTURE_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = ANSWER_CALL_FEATURE_ID,
.freq = 3,
.enable = 0,
},
{
.feature = SHAKE_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = STATIONARY_DETECT_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = MOTION_DETECT_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = IN_POCKET_FEATURE_ID,
.freq = 3,
.enable = 0,
},
{
.feature = SHAKE_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = DEVICE_ORIENTATION_FEATURE_ID,
.freq = 2,
.enable = 0,
},
{
.feature = ACTIVITY_FEATURE_ID,
.freq = 3,
.enable = 0,
},
};
File diff suppressed because it is too large. Load diff
+307
View File
@@ -0,0 +1,307 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#ifndef __SCP_HELPER_H__
#define __SCP_HELPER_H__
#include <linux/arm-smccc.h>
#include <linux/notifier.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/soc/mediatek/mtk_sip_svc.h>
#include "scp_reg.h"
#include "scp_feature_define.h"
#include "scp.h"
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
/* scp config reg. definition*/
#define SCP_TCM_SIZE (scpreg.total_tcmsize)
#define SCP_A_TCM_SIZE (scpreg.scp_tcmsize)
#define SCP_TCM (scpreg.sram)
#define SCP_REGION_INFO_OFFSET 0x4
#define SCP_RTOS_START (0x800)
#define SCP_DRAM_MAPSIZE (0x100000)
/* scp dvfs return status flag */
#define SET_PLL_FAIL (1)
#define SET_PMIC_VOLT_FAIL (2)
#define mt_reg_sync_writel(v, a) \
do { \
__raw_writel((v), (void __force __iomem *)((a))); \
mb(); /*make sure register access in order */ \
} while (0)
/* This structre need to sync with SCP-side */
struct SCP_IRQ_AST_INFO {
unsigned int scp_irq_ast_time;
unsigned int scp_irq_ast_pc_s;
unsigned int scp_irq_ast_pc_e;
unsigned int scp_irq_ast_lr_s;
unsigned int scp_irq_ast_lr_e;
unsigned int scp_irq_ast_irqd;
};
/* reset ID */
#define SCP_ALL_ENABLE 0x00
#define SCP_ALL_REBOOT 0x01
/* scp semaphore definition*/
enum SEMAPHORE_FLAG {
SEMAPHORE_CLK_CFG_5 = 0,
SEMAPHORE_PTP,
SEMAPHORE_I2C0,
SEMAPHORE_I2C1,
SEMAPHORE_TOUCH,
SEMAPHORE_APDMA,
SEMAPHORE_SENSOR,
SEMAPHORE_SCP_A_AWAKE,
SEMAPHORE_SCP_B_AWAKE,
NR_FLAG = 9,
};
/* scp semaphore 3way definition */
enum SEMAPHORE_3WAY_FLAG {
SEMA_SCP_3WAY_UART = 0,
SEMA_SCP_3WAY_C2C_A = 1,
SEMA_SCP_3WAY_C2C_B = 2,
SEMA_SCP_3WAY_DVFS = 3,
SEMA_SCP_3WAY_AUDIO = 4,
SEMA_SCP_3WAY_AUDIOREG = 5,
SEMA_SCP_3WAY_NUM = 6,
};
/* scp semaphore status */
enum SEMAPHORE_STATUS {
SEMAPHORE_NOT_INIT = -1,
SEMAPHORE_FAIL = 0,
SEMAPHORE_SUCCESS = 1,
};
/* scp reset status */
enum SCP_RESET_STATUS {
RESET_STATUS_STOP = 0,
RESET_STATUS_START = 1,
/* this state mean scp already kick reboot, if wdt trigger before
* recovery finish mean recovery fail, should retry again
*/
RESET_STATUS_START_KICK = 2,
RESET_STATUS_START_WDT = 3,
};
/* scp reset status */
enum SCP_RESET_TYPE {
RESET_TYPE_WDT = 0,
RESET_TYPE_AWAKE = 1,
RESET_TYPE_CMD = 2,
RESET_TYPE_TIMEOUT = 3,
};
struct scp_bus_tracker_status {
u32 dbg_con;
u32 dbg_r[32];
u32 dbg_w[32];
};
struct scp_regs {
void __iomem *scpsys;
void __iomem *sram;
void __iomem *cfg;
void __iomem *clkctrl;
void __iomem *l1cctrl;
void __iomem *cfg_core0;
void __iomem *cfg_core1;
void __iomem *cfg_sec;
void __iomem *bus_tracker;
int irq0;
int irq1;
unsigned int total_tcmsize;
unsigned int cfgregsize;
unsigned int scp_tcmsize;
unsigned int core_nums;
unsigned int twohart;
unsigned int secure_dump;
struct scp_bus_tracker_status tracker_status;
};
/* scp work struct definition*/
struct scp_work_struct {
struct work_struct work;
unsigned int flags;
unsigned int id;
};
struct scp_reserve_mblock {
enum scp_reserve_mem_id_t num;
u64 start_phys;
u64 start_virt;
u64 size;
};
struct scp_region_info_st {
uint32_t ap_loader_start;
uint32_t ap_loader_size;
uint32_t ap_firmware_start;
uint32_t ap_firmware_size;
uint32_t ap_dram_start;
uint32_t ap_dram_size;
uint32_t ap_dram_backup_start;
/* This is the size of the structure.
* It can act as a version number if entries can only be
* added to (not deleted from) the structure.
* It should be the first entry of the structure, but for
* compatibility reason, it is appended here.
*/
uint32_t struct_size;
uint32_t scp_log_thru_ap_uart;
uint32_t TaskContext_ptr;
uint32_t scpctl;
uint32_t regdump_start;
uint32_t regdump_size;
uint32_t ap_params_start;
};
/* scp device attribute */
extern struct device_attribute dev_attr_scp_A_mobile_log_UT;
extern struct device_attribute dev_attr_scp_A_logger_wakeup_AP;
extern const struct file_operations scp_A_log_file_ops;
extern struct scp_regs scpreg;
extern struct device_attribute dev_attr_scp_mobile_log;
extern struct device_attribute dev_attr_scp_A_get_last_log;
extern struct device_attribute dev_attr_scp_A_status;
extern struct device_attribute dev_attr_log_filter;
extern struct bin_attribute bin_attr_scp_dump;
/* scp loggger */
extern int scp_logger_init(phys_addr_t start, phys_addr_t limit);
extern void scp_logger_uninit(void);
extern void scp_logger_stop(void);
extern void scp_logger_cleanup(void);
/* scp exception */
int scp_excep_init(void);
void scp_ram_dump_init(void);
void scp_excep_cleanup(void);
void scp_reset_wait_timeout(void);
/* scp irq */
extern irqreturn_t scp_A_irq_handler(int irq, void *dev_id);
extern void scp_A_irq_init(void);
/* scp helper */
extern void scp_schedule_work(struct scp_work_struct *scp_ws);
extern void scp_schedule_logger_work(struct scp_work_struct *scp_ws);
extern void memcpy_to_scp(void __iomem *trg,
const void *src, int size);
extern void memcpy_from_scp(void *trg, const void __iomem *src,
int size);
extern int reset_scp(int reset);
extern int scp_check_resource(void);
void set_scp_mpu(void);
extern phys_addr_t scp_mem_base_phys;
extern phys_addr_t scp_mem_base_virt;
extern phys_addr_t scp_mem_size;
extern atomic_t scp_reset_status;
extern bool mbox_check_send_table(unsigned int id);
extern bool mbox_check_recv_table(unsigned int id);
extern void mbox_setup_pin_table(int mbox);
extern void mt_print_scp_ipi_id(unsigned int irq_no);
#ifdef CONFIG_MTK_GIC_V3_EXT
extern u32 mt_irq_get_pending(unsigned int irq);
#endif
/*extern scp notify*/
extern void scp_send_reset_wq(enum SCP_RESET_TYPE type);
extern void scp_extern_notify(enum SCP_NOTIFY_EVENT notify_status);
extern void scp_status_set(unsigned int value);
extern void scp_logger_init_set(unsigned int value);
extern unsigned int scp_set_reset_status(void);
extern void scp_enable_sram(void);
extern int scp_sys_full_reset(void);
extern void scp_reset_awake_counts(void);
extern void scp_awake_init(void);
extern unsigned int mt_get_abist_freq(unsigned int ID);
#if SCP_RECOVERY_SUPPORT
extern unsigned int scp_reset_by_cmd;
extern struct scp_region_info_st scp_region_info_copy;
extern struct scp_region_info_st *scp_region_info;
extern void __iomem *scp_ap_dram_virt;
extern void __iomem *scp_loader_virt;
extern void __iomem *scp_regdump_virt;
extern struct tasklet_struct scp_A_irq0_tasklet;
extern struct tasklet_struct scp_A_irq1_tasklet;
#endif
enum MTK_TINYSYS_SCP_KERNEL_OP {
MTK_TINYSYS_SCP_KERNEL_OP_DUMP_START = 0,
MTK_TINYSYS_SCP_KERNEL_OP_DUMP_POLLING,
MTK_TINYSYS_SCP_KERNEL_OP_RESET_SET,
MTK_TINYSYS_SCP_KERNEL_OP_RESET_RELEASE,
MTK_TINYSYS_SCP_KERNEL_OP_RESTORE_L2TCM,
MTK_TINYSYS_SCP_KERNEL_OP_RESTORE_DRAM,
MTK_TINYSYS_SCP_KERNEL_OP_WDT_SET,
MTK_TINYSYS_SCP_KERNEL_OP_HALT_SET,
MTK_TINYSYS_SCP_KERNEL_OP_WDT_CLEAR,
MTK_TINYSYS_SCP_KERNEL_OP_NUM,
};
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
static inline unsigned long scp_do_dump(void)
{
return 0;
}
static inline unsigned long scp_do_polling(void)
{
return 0;
}
static inline uint64_t scp_do_rstn_set(uint64_t boot_ok)
{
return 0;
}
static inline uint64_t scp_do_rstn_clr(void)
{
return 0;
}
static inline unsigned long scp_restore_l2tcm(void)
{
return 0;
}
static inline unsigned long scp_restore_dram(void)
{
return 0;
}
static inline uint64_t scp_do_wdt_set(uint64_t coreid)
{
return 0;
}
static inline uint64_t scp_do_halt_set(void)
{
return 0;
}
static inline uint64_t scp_do_wdt_clear(uint64_t coreid)
{
return 0;
}
#endif
#endif
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/arm-smccc.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/io.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/ktime.h>
#include <linux/mfd/syscon.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm_wakeup.h>
#include <linux/printk.h>
#include <linux/proc_fs.h>
#include <linux/regmap.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/suspend.h>
#include <linux/uaccess.h>
#include <linux/bits.h>
#include <linux/build_bug.h>
#include <clk-fmeter.h>
#if IS_ENABLED(CONFIG_OF)
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_platform.h>
#endif
#include "scp_ipi.h"
#include "scp_helper.h"
#include "scp_excep.h"
#include "scp.h"
#include "scp_hwvoter_dbg.h"
#if IS_ENABLED(CONFIG_PROC_FS)
/**********************************
* hw_voter debug
***********************************/
int scp_hw_voter_create_procfs(void)
{
return 0;
}
#endif /* CONFIG_PROC_FS */
int scp_hw_voter_dbg_init(void)
{
return 0;
}
@@ -0,0 +1,24 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_HW_VOTER_DBG_H__
#define __SCP_HW_VOTER_DBG_H__
enum {
HW_VOTER_DBG_CMD_TEST,
};
struct hwvoter_ipi_test_t {
unsigned char cmd;
unsigned char type;
unsigned char op;
unsigned char clk_category;
unsigned short clk_id;
unsigned short val;
};
extern int scp_hw_voter_dbg_init(void);
#endif /* __SCP_HW_VOTER_DBG_H__ */
+30
View File
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef _SCP_IPI_H_
#define _SCP_IPI_H_
#include "scp_ipi_wrapper.h"
#include "scp.h"
struct scp_ipi_wrapper {
uint32_t out_id_0;
uint32_t out_id_1;
uint32_t in_id_0;
uint32_t in_id_1;
uint32_t out_size;
uint32_t in_size;
void *msg_0;
void *msg_1;
};
extern struct mtk_mbox_device scp_mboxdev;
extern struct mtk_ipi_device scp_ipidev;
extern struct mtk_mbox_info *scp_mbox_info;
extern struct scp_ipi_wrapper scp_ipi_legacy_id[1];
extern enum scp_ipi_status scp_legacy_ipi_init(void);
#endif
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef _SCP_IPI_PIN_H_
#define _SCP_IPI_PIN_H_
#include <linux/soc/mediatek/mtk_tinysys_ipi.h>
#include "scp.h"
/* scp awake timeout count definition */
#define SCP_AWAKE_TIMEOUT 100000
/* this is only for ipi to distinguish core0 and core1 */
enum {
SCP_CORE0_ID = 0,
SCP_CORE1_ID = 1,
};
extern char *core_ids[SCP_CORE_TOTAL];
extern void scp_reset_awake_counts(void);
extern int scp_clr_spm_reg(void *unused);
extern int scp_awake_counts[];
#endif
@@ -0,0 +1,89 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef _SCP_IPI_TABLE_H_
#define _SCP_IPI_TABLE_H_
#include "scp_mbox_layout.h"
#include "scp_ipi_pin.h"
/*
* mbox information
*
* mbdev :mbox device
* irq_num:identity of mbox irq
* id :mbox id
* slot :how many slots that mbox used, up to 1GB
* opt :option for mbox or share memory, 0:mbox, 1:share memory
* enable :mbox status, 0:disable, 1: enable
* is64d :mbox is64d status, 0:32d, 1: 64d
* base :mbox base address
* set_irq_reg : mbox set irq register
* clr_irq_reg : mbox clear irq register
* init_base_reg: mbox initialize register
* mbox lock : lock of mbox
*/
struct mtk_mbox_info *scp_mbox_info;
/*
* mbox pin structure, this is for receive defination,
* ipi=endpoint=pin
* mbox : (mbox number)mbox number of the pin, up to 16(plt)
* offset : (slot)msg offset in share memory, up to 1024*4 KB(plt)
* recv_opt : (opt)recv option, 0:receive ,1: response(plt)
* lock : (lock)polling lock 0:unuse,1:used
* buf_full_opt : (opt)buffer option 0:drop, 1:assert, 2:overwrite(plt)
* cb_ctx_opt : (opt)callback option 0:isr context, 1:process context(plt)
* msg_size : (slot)msg used slots in the mbox, 4 bytes alignment(plt)
* pin_index : (bit offset)pin index in the mbox(plt)
* chan_id : (u32) ipc channel id(plt)
* notify : (completion)notify process
* mbox_pin_cb: (cb)cb function
* pin_buf : (void*)buffer point
* prdata : (void*)private data
* pin_lock: (spinlock_t)lock of the pin
*/
struct mtk_mbox_pin_recv *scp_mbox_pin_recv;
/*
* mbox pin structure, this is for send defination,
* ipi=endpoint=pin
* mbox : (mbox number)mbox number of the pin, up to 16(plt)
* offset : (slot)msg offset in share memory, up to 1024*4 KB(plt)
* send_opt : (opt)send opt, 0:send ,1: send for response(plt)
* lock : (lock)polling lock 0:unuse,1:used
* msg_size : (slot)message size in words, 4 bytes alignment(plt)
* pin_index : (bit offset)pin index in the mbox(plt)
* chan_id : (u32) ipc channel id(plt)
* mutex : (mutex)mutex for remote response
* completion : (completion)completion for remote response
* pin_lock : (spinlock_t)lock of the pin
*/
struct mtk_mbox_pin_send *scp_mbox_pin_send;
struct mtk_mbox_device scp_mboxdev = {
.name = "scp_mboxdev",
.pin_recv_table = 0,
.pin_send_table = 0,
.info_table = 0,
.count = 0,
.recv_count = 0,
.send_count = 0,
.post_cb = (mbox_rx_cb_t)scp_clr_spm_reg,
};
struct mtk_ipi_device scp_ipidev = {
.name = "scp_ipidev",
.id = IPI_DEV_SCP,
.mbdev = &scp_mboxdev,
.pre_cb = (ipi_tx_cb_t)scp_awake_lock,
.post_cb = (ipi_tx_cb_t)scp_awake_unlock,
.prdata = 0,
};
EXPORT_SYMBOL(scp_ipidev);
#endif
@@ -0,0 +1,19 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef _SCP_IPI_WRAPPER_H_
#define _SCP_IPI_WRAPPER_H_
#include "scp_ipi_pin.h"
#include "scp_mbox_layout.h"
/* retry times * 1000 = 0x7FFF_FFFF, mbox wait maximum */
#define SCP_IPI_LEGACY_WAIT 0x20C49B
struct scp_ipi_desc {
void (*handler)(int id, void *data, unsigned int len);
};
#endif
+77
View File
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#include <linux/spinlock.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <mt-plat/aee.h>
#include <linux/interrupt.h>
#include <linux/io.h>
//#include <mt-plat/sync_write.h>
#include "scp_ipi_pin.h"
#include "scp_helper.h"
#include "scp_excep.h"
#include "scp_dvfs.h"
static inline void scp_wdt_clear(uint32_t coreid)
{
coreid == 0 ? writel(B_WDT_IRQ, R_CORE0_WDT_IRQ) :
writel(B_WDT_IRQ, R_CORE1_WDT_IRQ);
}
/*
* handler for wdt irq for scp
* dump scp register
*/
static void scp_A_wdt_handler(unsigned long data)
{
unsigned int reg0 = readl(R_CORE0_WDT_IRQ);
unsigned int reg1 = scpreg.core_nums == 2 ?
readl(R_CORE1_WDT_IRQ) : 0;
#if SCP_RECOVERY_SUPPORT
if (scp_set_reset_status() == RESET_STATUS_STOP) {
pr_notice("[SCP] start to reset scp...\n");
mdelay(2);
scp_dump_last_regs();
scp_send_reset_wq(RESET_TYPE_WDT);
} else
pr_notice("%s: scp resetting\n", __func__);
#endif
#if SCP_RESERVED_MEM && IS_ENABLED(CONFIG_OF_RESERVED_MEM)
if (scpreg.secure_dump) {
if (reg0)
scp_do_wdt_clear(0);
if (reg1)
scp_do_wdt_clear(1);
} else
#endif
{
if (reg0)
scp_wdt_clear(0);
if (reg1)
scp_wdt_clear(1);
}
enable_irq(data);
}
DECLARE_TASKLET(scp_A_irq0_tasklet, scp_A_wdt_handler, 0);
DECLARE_TASKLET(scp_A_irq1_tasklet, scp_A_wdt_handler, 0);
/*
* dispatch scp irq
* reset scp and generate exception if needed
* @param irq: irq id
* @param dev_id: should be NULL
*/
irqreturn_t scp_A_irq_handler(int irq, void *dev_id)
{
disable_irq_nosync(irq);
if (likely(irq == scpreg.irq0))
tasklet_schedule(&scp_A_irq0_tasklet);
else
tasklet_schedule(&scp_A_irq1_tasklet);
return IRQ_HANDLED;
}
+28
View File
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/sysfs.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/workqueue.h>
#include <linux/io.h>
#include <linux/mutex.h>
#include <linux/sched_clock.h>
#include <linux/ratelimit.h>
#include "scp_helper.h"
#include "scp_excep.h"
#include "scp_feature_define.h"
#include "scp_l1c.h"
#include <mt-plat/aee.h>
enum scp_l1c_status_t scp_l1c_flua(uint32_t L1C_type)
{
L1C_SEL(L1C_type)->L1C_OP &= ~L1C_OP_OP_MASK;
L1C_SEL(L1C_type)->L1C_OP |=
((L1C_FLUA << L1C_OP_OP_OFFSET) |
L1C_OP_EN_MASK);
return SCP_L1C_STATUS_OK;
}
+57
View File
@@ -0,0 +1,57 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_L1C_H
#define __SCP_L1C_H
#define SCP_IL1C 0
#define SCP_DL1C 1
#define L1C_BASE (scpreg.l1cctrl)
#define L1C_SEL(x) ((struct L1C_REGISTER_T *)(L1C_BASE+x*0x3000))
/* L1C_OP register definitions
*/
#define L1C_OP_EN_OFFSET (0)
#define L1C_OP_EN_MASK (1<<L1C_OP_EN_OFFSET)
#define L1C_OP_OP_OFFSET (1)
#define L1C_OP_OP_MASK (15<<L1C_OP_OP_OFFSET)
enum scp_l1c_status_t {
SCP_L1C_STATUS_OK = 0
};
/* structure type to access the L1C register
*/
struct L1C_REGISTER_T {
uint32_t L1C_CON;
uint32_t L1C_OP;
uint32_t L1C_HCNT0L;
uint32_t L1C_HCNT0U;
uint32_t L1C_CCNT0L;
uint32_t L1C_CCNT0U;
uint32_t L1C_HCNT1L;
uint32_t L1C_HCNT1U;
uint32_t L1C_CCNT1L;
uint32_t L1C_CCNT1U;
uint32_t RESERVED0[1];
uint32_t L1C_REGION_EN;
uint32_t RESERVED1[2036];/**< (0x2000-12*4)/4 */
uint32_t L1C_ENTRY_N[16];
uint32_t L1C_END_ENTRY_N[16];
};
enum L1C_line_command_t {
L1C_INVA = 1,
L1C_INVL = 2,
L1C_INVW = 4,
L1C_FLUA = 9,
L1C_FLUD = 10,
L1C_FLUS = 12
};
enum scp_l1c_status_t scp_l1c_flua(uint32_t L1C_type);
#endif
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef _SCP_MBOX_LAYOUT_H_
#define _SCP_MBOX_LAYOUT_H_
#endif
+258
View File
@@ -0,0 +1,258 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_REG_H
#define __SCP_REG_H
#define SCP_SEMAPHORE (scpreg.cfg + 0x0018)
#define SCP_3WAY_SEMAPHORE (scpreg.cfg + 0x001c)
#define SCP_SCP2SPM_VOL_LV (scpreg.cfg + 0x0020)
/* SCP to SPM IPC clear */
#define SCP_TO_SPM_REG (scpreg.cfg + 0x0094)
#define R_GIPC_IN_SET (scpreg.cfg + 0x0098)
#define R_GIPC_IN_CLR (scpreg.cfg + 0x009c)
#define B_GIPC0_SETCLR_0 (1 << 0)
#define B_GIPC0_SETCLR_1 (1 << 1)
#define B_GIPC0_SETCLR_2 (1 << 2)
#define B_GIPC0_SETCLR_3 (1 << 3)
#define B_GIPC1_SETCLR_0 (1 << 4)
#define B_GIPC1_SETCLR_1 (1 << 5)
#define B_GIPC1_SETCLR_2 (1 << 6)
#define B_GIPC1_SETCLR_3 (1 << 7)
#define B_GIPC2_SETCLR_0 (1 << 8)
#define B_GIPC2_SETCLR_1 (1 << 9)
#define B_GIPC2_SETCLR_2 (1 << 10)
#define B_GIPC2_SETCLR_3 (1 << 11)
#define B_GIPC3_SETCLR_0 (1 << 12)
#define B_GIPC3_SETCLR_1 (1 << 13)
#define B_GIPC3_SETCLR_2 (1 << 14)
#define B_GIPC3_SETCLR_3 (1 << 15)
#define B_GIPC4_SETCLR_0 (1 << 16)
#define B_GIPC4_SETCLR_1 (1 << 17)
#define B_GIPC4_SETCLR_2 (1 << 18)
#define B_GIPC4_SETCLR_3 (1 << 19)
#define R_CORE0_SW_RSTN_CLR (scpreg.cfg_core0 + 0x0000)
#define R_CORE1_SW_RSTN_CLR (scpreg.cfg_core1 + 0x0000)
#define R_CORE0_SW_RSTN_SET (scpreg.cfg_core0 + 0x0004)
#define R_CORE1_SW_RSTN_SET (scpreg.cfg_core1 + 0x0004)
#define R_CORE0_DBG_CTRL (scpreg.cfg_core0 + 0x0010)
#define R_CORE1_DBG_CTRL (scpreg.cfg_core1 + 0x0010)
#define M_CORE_TBUF_DBG_SEL (7 << 4)
#define S_CORE_TBUF_DBG_SEL (4)
#define M_CORE_TBUF_DBG_SEL_RV55 (0xfff0ff0f)
#define S_CORE_TBUF_S (4)
#define S_CORE_TBUF1_S (16)
#define R_CORE0_WDT_IRQ (scpreg.cfg_core0 + 0x0030)
#define R_CORE1_WDT_IRQ (scpreg.cfg_core1 + 0x0030)
#define B_WDT_IRQ (1 << 0)
#define R_CORE0_WDT_CFG (scpreg.cfg_core0 + 0x0034)
#define R_CORE1_WDT_CFG (scpreg.cfg_core1 + 0x0034)
#define V_INSTANT_WDT 0x80000000
#define R_CORE0_STATUS (scpreg.cfg_core0 + 0x0070)
#define B_CORE_GATED (1 << 0)
#define B_CORE_HALT (1 << 1)
#define R_CORE0_MON_PC (scpreg.cfg_core0 + 0x0080)
#define R_CORE0_MON_LR (scpreg.cfg_core0 + 0x0084)
#define R_CORE0_MON_SP (scpreg.cfg_core0 + 0x0088)
#define R_CORE0_TBUF_WPTR (scpreg.cfg_core0 + 0x008c)
#define R_CORE0_MON_PC_LATCH (scpreg.cfg_core0 + 0x00d0)
#define R_CORE0_MON_LR_LATCH (scpreg.cfg_core0 + 0x00d4)
#define R_CORE0_MON_SP_LATCH (scpreg.cfg_core0 + 0x00d8)
#define R_CORE0_T1_MON_PC (scpreg.cfg_core0 + 0x0160)
#define R_CORE0_T1_MON_LR (scpreg.cfg_core0 + 0x0164)
#define R_CORE0_T1_MON_SP (scpreg.cfg_core0 + 0x0168)
#define R_CORE0_T1_MON_PC_LATCH (scpreg.cfg_core0 + 0x0170)
#define R_CORE0_T1_MON_LR_LATCH (scpreg.cfg_core0 + 0x0174)
#define R_CORE0_T1_MON_SP_LATCH (scpreg.cfg_core0 + 0x0178)
#define R_CORE1_STATUS (scpreg.cfg_core1 + 0x0070)
#define R_CORE1_MON_PC (scpreg.cfg_core1 + 0x0080)
#define R_CORE1_MON_LR (scpreg.cfg_core1 + 0x0084)
#define R_CORE1_MON_SP (scpreg.cfg_core1 + 0x0088)
#define R_CORE1_TBUF_WPTR (scpreg.cfg_core1 + 0x008c)
#define R_CORE1_MON_PC_LATCH (scpreg.cfg_core1 + 0x00d0)
#define R_CORE1_MON_LR_LATCH (scpreg.cfg_core1 + 0x00d4)
#define R_CORE1_MON_SP_LATCH (scpreg.cfg_core1 + 0x00d8)
#define R_CORE1_T1_MON_PC (scpreg.cfg_core1 + 0x0160)
#define R_CORE1_T1_MON_LR (scpreg.cfg_core1 + 0x0164)
#define R_CORE1_T1_MON_SP (scpreg.cfg_core1 + 0x0168)
#define R_CORE1_T1_MON_PC_LATCH (scpreg.cfg_core1 + 0x0170)
#define R_CORE1_T1_MON_LR_LATCH (scpreg.cfg_core1 + 0x0174)
#define R_CORE1_T1_MON_SP_LATCH (scpreg.cfg_core1 + 0x0178)
#define R_CORE0_TBUF_DATA31_0 (scpreg.cfg_core0 + 0x00e0)
#define R_CORE0_TBUF_DATA63_32 (scpreg.cfg_core0 + 0x00e4)
#define R_CORE0_TBUF_DATA95_64 (scpreg.cfg_core0 + 0x00e8)
#define R_CORE0_TBUF_DATA127_96 (scpreg.cfg_core0 + 0x00ec)
#define R_CORE0_TBUF1_DATA31_0 (scpreg.cfg_core0 + 0x00f0)
#define R_CORE0_TBUF1_DATA63_32 (scpreg.cfg_core0 + 0x00f4)
#define R_CORE0_TBUF1_DATA95_64 (scpreg.cfg_core0 + 0x00f8)
#define R_CORE0_TBUF1_DATA127_96 (scpreg.cfg_core0 + 0x00fc)
#define R_CORE1_TBUF_DATA31_0 (scpreg.cfg_core1 + 0x00e0)
#define R_CORE1_TBUF_DATA63_32 (scpreg.cfg_core1 + 0x00e4)
#define R_CORE1_TBUF_DATA95_64 (scpreg.cfg_core1 + 0x00e8)
#define R_CORE1_TBUF_DATA127_96 (scpreg.cfg_core1 + 0x00ec)
#define R_CORE1_TBUF1_DATA31_0 (scpreg.cfg_core1 + 0x00f0)
#define R_CORE1_TBUF1_DATA63_32 (scpreg.cfg_core1 + 0x00f4)
#define R_CORE1_TBUF1_DATA95_64 (scpreg.cfg_core1 + 0x00f8)
#define R_CORE1_TBUF1_DATA127_96 (scpreg.cfg_core1 + 0x00fc)
#define SCP_A_GENERAL_REG0 (scpreg.cfg_core0 + 0x0040)
/* DRAM reserved address and size */
#define SCP_A_GENERAL_REG1 (scpreg.cfg_core0 + 0x0044)
#define DRAM_RESV_ADDR_REG SCP_A_GENERAL_REG1
#define SCP_A_GENERAL_REG2 (scpreg.cfg_core0 + 0x0048)
#define DRAM_RESV_SIZE_REG SCP_A_GENERAL_REG2
/*EXPECTED_FREQ_REG*/
#define SCP_A_GENERAL_REG3 (scpreg.cfg_core0 + 0x004C)
#define EXPECTED_FREQ_REG SCP_A_GENERAL_REG3
/*CURRENT_FREQ_REG*/
#define SCP_A_GENERAL_REG4 (scpreg.cfg_core0 + 0x0050)
#define CURRENT_FREQ_REG SCP_A_GENERAL_REG4
/*SCP_GPR_CM4_A_REBOOT*/
#define SCP_A_GENERAL_REG5 (scpreg.cfg_core0 + 0x0054)
#define SCP_GPR_CORE0_REBOOT SCP_A_GENERAL_REG5
#define CORE_RDY_TO_REBOOT 0x34
#define CORE_REBOOT_OK 0x1
#define SCP_GPR_CORE1_REBOOT (scpreg.cfg_core1 + 0x0054)
#define SCP_A_GENERAL_REG6 (scpreg.cfg_core0 + 0x0058)
#define SCP_A_GENERAL_REG7 (scpreg.cfg_core0 + 0x005C)
/* bus tracker reg */
#define SCP_BUS_DBG_CON (scpreg.bus_tracker)
#define SCP_BUS_DBG_AR_TRACK0_L (scpreg.bus_tracker + 0x100)
#define SCP_BUS_DBG_AR_TRACK1_L (scpreg.bus_tracker + 0x108)
#define SCP_BUS_DBG_AR_TRACK2_L (scpreg.bus_tracker + 0x110)
#define SCP_BUS_DBG_AR_TRACK3_L (scpreg.bus_tracker + 0x118)
#define SCP_BUS_DBG_AR_TRACK4_L (scpreg.bus_tracker + 0x120)
#define SCP_BUS_DBG_AR_TRACK5_L (scpreg.bus_tracker + 0x128)
#define SCP_BUS_DBG_AR_TRACK6_L (scpreg.bus_tracker + 0x130)
#define SCP_BUS_DBG_AR_TRACK7_L (scpreg.bus_tracker + 0x138)
#define SCP_BUS_DBG_AR_TRACK8_L (scpreg.bus_tracker + 0x140)
#define SCP_BUS_DBG_AR_TRACK9_L (scpreg.bus_tracker + 0x148)
#define SCP_BUS_DBG_AR_TRACK10_L (scpreg.bus_tracker + 0x150)
#define SCP_BUS_DBG_AR_TRACK11_L (scpreg.bus_tracker + 0x158)
#define SCP_BUS_DBG_AR_TRACK12_L (scpreg.bus_tracker + 0x160)
#define SCP_BUS_DBG_AR_TRACK13_L (scpreg.bus_tracker + 0x168)
#define SCP_BUS_DBG_AR_TRACK14_L (scpreg.bus_tracker + 0x170)
#define SCP_BUS_DBG_AR_TRACK15_L (scpreg.bus_tracker + 0x178)
#define SCP_BUS_DBG_AR_TRACK16_L (scpreg.bus_tracker + 0x180)
#define SCP_BUS_DBG_AR_TRACK17_L (scpreg.bus_tracker + 0x188)
#define SCP_BUS_DBG_AR_TRACK18_L (scpreg.bus_tracker + 0x190)
#define SCP_BUS_DBG_AR_TRACK19_L (scpreg.bus_tracker + 0x198)
#define SCP_BUS_DBG_AR_TRACK20_L (scpreg.bus_tracker + 0x1a0)
#define SCP_BUS_DBG_AR_TRACK21_L (scpreg.bus_tracker + 0x1a8)
#define SCP_BUS_DBG_AR_TRACK22_L (scpreg.bus_tracker + 0x1b0)
#define SCP_BUS_DBG_AR_TRACK23_L (scpreg.bus_tracker + 0x1b8)
#define SCP_BUS_DBG_AR_TRACK24_L (scpreg.bus_tracker + 0x1c0)
#define SCP_BUS_DBG_AR_TRACK25_L (scpreg.bus_tracker + 0x1c8)
#define SCP_BUS_DBG_AR_TRACK26_L (scpreg.bus_tracker + 0x1d0)
#define SCP_BUS_DBG_AR_TRACK27_L (scpreg.bus_tracker + 0x1d8)
#define SCP_BUS_DBG_AR_TRACK28_L (scpreg.bus_tracker + 0x1e0)
#define SCP_BUS_DBG_AR_TRACK29_L (scpreg.bus_tracker + 0x1e8)
#define SCP_BUS_DBG_AR_TRACK30_L (scpreg.bus_tracker + 0x1f0)
#define SCP_BUS_DBG_AR_TRACK31_L (scpreg.bus_tracker + 0x1f8)
#define SCP_BUS_DBG_AW_TRACK0_L (scpreg.bus_tracker + 0x300)
#define SCP_BUS_DBG_AW_TRACK1_L (scpreg.bus_tracker + 0x308)
#define SCP_BUS_DBG_AW_TRACK2_L (scpreg.bus_tracker + 0x310)
#define SCP_BUS_DBG_AW_TRACK3_L (scpreg.bus_tracker + 0x318)
#define SCP_BUS_DBG_AW_TRACK4_L (scpreg.bus_tracker + 0x320)
#define SCP_BUS_DBG_AW_TRACK5_L (scpreg.bus_tracker + 0x328)
#define SCP_BUS_DBG_AW_TRACK6_L (scpreg.bus_tracker + 0x330)
#define SCP_BUS_DBG_AW_TRACK7_L (scpreg.bus_tracker + 0x338)
#define SCP_BUS_DBG_AW_TRACK8_L (scpreg.bus_tracker + 0x340)
#define SCP_BUS_DBG_AW_TRACK9_L (scpreg.bus_tracker + 0x348)
#define SCP_BUS_DBG_AW_TRACK10_L (scpreg.bus_tracker + 0x350)
#define SCP_BUS_DBG_AW_TRACK11_L (scpreg.bus_tracker + 0x358)
#define SCP_BUS_DBG_AW_TRACK12_L (scpreg.bus_tracker + 0x360)
#define SCP_BUS_DBG_AW_TRACK13_L (scpreg.bus_tracker + 0x368)
#define SCP_BUS_DBG_AW_TRACK14_L (scpreg.bus_tracker + 0x370)
#define SCP_BUS_DBG_AW_TRACK15_L (scpreg.bus_tracker + 0x378)
#define SCP_BUS_DBG_AW_TRACK16_L (scpreg.bus_tracker + 0x380)
#define SCP_BUS_DBG_AW_TRACK17_L (scpreg.bus_tracker + 0x388)
#define SCP_BUS_DBG_AW_TRACK18_L (scpreg.bus_tracker + 0x390)
#define SCP_BUS_DBG_AW_TRACK19_L (scpreg.bus_tracker + 0x398)
#define SCP_BUS_DBG_AW_TRACK20_L (scpreg.bus_tracker + 0x3a0)
#define SCP_BUS_DBG_AW_TRACK21_L (scpreg.bus_tracker + 0x3a8)
#define SCP_BUS_DBG_AW_TRACK22_L (scpreg.bus_tracker + 0x3b0)
#define SCP_BUS_DBG_AW_TRACK23_L (scpreg.bus_tracker + 0x3b8)
#define SCP_BUS_DBG_AW_TRACK24_L (scpreg.bus_tracker + 0x3c0)
#define SCP_BUS_DBG_AW_TRACK25_L (scpreg.bus_tracker + 0x3c8)
#define SCP_BUS_DBG_AW_TRACK26_L (scpreg.bus_tracker + 0x3d0)
#define SCP_BUS_DBG_AW_TRACK27_L (scpreg.bus_tracker + 0x3d8)
#define SCP_BUS_DBG_AW_TRACK28_L (scpreg.bus_tracker + 0x3e0)
#define SCP_BUS_DBG_AW_TRACK29_L (scpreg.bus_tracker + 0x3e8)
#define SCP_BUS_DBG_AW_TRACK30_L (scpreg.bus_tracker + 0x3f0)
#define SCP_BUS_DBG_AW_TRACK31_L (scpreg.bus_tracker + 0x3f8)
/* clk reg*/
#define SCP_A_SLEEP_DEBUG_REG (scpreg.clkctrl + 0x0028)
#define SCP_CLK_CTRL_L1_SRAM_PD (scpreg.clkctrl + 0x002C)
#define SCP_CLK_HIGH_CORE_CG (scpreg.clkctrl + 0x005C)
#define SCP_CPU0_SRAM_PD (scpreg.clkctrl + 0x0080)
#define SCP_CPU1_SRAM_PD (scpreg.clkctrl + 0x0084)
#define SCP_CLK_CTRL_TCM_TAIL_SRAM_PD (scpreg.clkctrl + 0x0094)
#define SCP_POWER_STATUS (scpreg.clkctrl + 0x0124)
#define SCP_SLP_PWR_CTRL (scpreg.clkctrl + 0x0128)
#define CLK_SW_SEL (scpreg.clkctrl + 0x0)
#define CLK_SW_SEL_O_BIT 8
#define CLK_SW_SEL_O_MASK 0xf
#define CLK_SW_SEL_O_ULPOSC_CORE 0x4
#define CLK_SW_SEL_O_ULPOSC_PERI 0x8
#define CLK_ENABLE (scpreg.clkctrl + 0x0004)
#define CLK_SAFE_ACK (scpreg.clkctrl + 0x0008)
#define CLK_SYS_SAFE_ACK_BIT 0
#define CLK_HIGH_SAFE_ACK_BIT 1
#define CLK_HIGH_CORE (scpreg.clkctrl + 0x005C)
#define HIGH_CORE_CG_BIT 1
#define CLK_ON_CTRL (scpreg.clkctrl + 0x006C)
#define HIGH_AO_BIT 0
#define HIGH_CG_AO_BIT 2
#define HIGH_CORE_AO_BIT 4
#define HIGH_CORE_DIS_SUB_BIT 5
#define HIGH_CORE_CG_AO_BIT 6
#define HIGH_FINAL_VAL_BIT 8
#define HIGH_FINAL_VAL_MASK 0x1f
#define R_SEC_CTRL (scpreg.cfg_sec + 0x0000)
#define B_CORE0_CACHE_DBG_EN (1 << 28)
#define B_CORE1_CACHE_DBG_EN (1 << 29)
#define R_CORE0_CACHE_RAM (scpreg.l1cctrl + 0x00000)
#define R_CORE1_CACHE_RAM (scpreg.l1cctrl + 0x20000)
/* INFRA_IRQ (always on register) */
#define INFRA_IRQ_SET (scpreg.scpsys + 0x0B14)
#define AP_AWAKE_LOCK (0)
#define AP_AWAKE_UNLOCK (1)
#define CONNSYS_AWAKE_LOCK (2)
#define CONNSYS_AWAKE_UNLOCK (3)
#define INFRA_IRQ_CLEAR (scpreg.scpsys + 0x0B18)
#define SCP_SYS_INFRA_MON (scpreg.scpsys + 0x0D50)
#endif
@@ -0,0 +1,92 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_RESERVEDMEM_DEFINE_H__
#define __SCP_RESERVEDMEM_DEFINE_H__
static struct scp_reserve_mblock scp_reserve_mblock[] = {
{
.num = SCP_A_SECDUMP_MEM_ID,
.start_phys = 0,
.start_virt = 0,
.size = 0, /* could be 3.5 MB */
},
{
.num = VOW_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = SENS_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = SCP_A_LOGGER_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = AUDIO_IPI_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = VOW_BARGEIN_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = SCP_DRV_PARAMS_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = ULTRA_MEM_ID,
.start_phys = 0,
.start_virt = 0,
.size = 0x0,
},
{
.num = SENS_SUPER_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = SENS_LIST_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = SENS_DEBUG_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = SENS_CUSTOM_W_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = SENS_CUSTOM_R_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
};
#endif
+50
View File
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#include <linux/device.h> /* needed by device_* */
#include "scp_ipi_pin.h"
#include "scp_mbox_layout.h"
#include "scp_scpctl.h"
/*
* A device node to send commands to scp wit unified interface
* @magic: should be 666
* @type: a class for different types of commands
* @op: the operation specified in a command type
* @return: 0 if success, -EINVAL if wrong value of number
* of parameters
*/
static ssize_t scpctl_store(struct device *kobj
, struct device_attribute *attr, const char *buf, size_t n)
{
int ret;
int magic, type, op;
struct scpctl_cmd_s cmd;
char *prompt = "[SCPCTL]:";
if (sscanf(buf, "%d %d %d", &magic, &type, &op) != 3)
return -EINVAL;
pr_notice("%s %d %d %d\n", prompt, magic, type, op);
if (magic != 666)
return -EINVAL;
cmd.type = type;
cmd.op = op;
ret = mtk_ipi_send(&scp_ipidev, IPI_OUT_SCPCTL_1, 0, &cmd,
PIN_OUT_SIZE_SCPCTL_1, 0);
if (ret != IPI_ACTION_DONE)
goto _err;
return n;
_err:
pr_notice("%s failed, %d\n", prompt, ret);
return -EIO;
}
DEVICE_ATTR_WO(scpctl);
+30
View File
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_SCPCTL_H__
#define __SCP_SCPCTL_H__
#include <linux/types.h>
enum SCPCTL_TYPE_E {
SCPCTL_TYPE_TMON,
SCPCTL_STRESS_TEST,
};
enum SCPCTL_OP_E {
SCPCTL_OP_INACTIVE = 0,
SCPCTL_OP_ACTIVE,
};
struct scpctl_cmd_s {
uint32_t type;
uint32_t op;
};
extern struct device_attribute dev_attr_scpctl;
#endif /* __SCP_SCPCTL_H__ */
@@ -0,0 +1,342 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include "scp_ipi.h"
#include "scp_ipi_table.h"
#include "scp.h"
#define IPI_NO_USE 0xFF
struct scp_ipi_desc mpool[SCP_NR_IPI - IPI_MPOOL - 1];
struct scp_ipi_wrapper scp_ipi_legacy_id[1];
struct scp_ipi_legacy_pkt {
unsigned int id;
unsigned int len;
void *data;
};
/*
* This is a handler for handling legacy ipi callback function
*/
static int scp_legacy_handler(unsigned int id, void *prdata, void *data,
unsigned int len)
{
void (*handler)(int id, void *data, unsigned int len);
struct scp_ipi_legacy_pkt pkt;
/* variation length will only support chre, chrex and sensor for
* reducing slot and cpu time cost by memcpy.
*/
pkt.id = *(unsigned int *)data;
pkt.len = *(unsigned int *)(data + 4);
pkt.data = (void *)(data + 8);
if (pkt.id > IPI_MPOOL)
handler = mpool[pkt.id - IPI_MPOOL - 1].handler;
else
handler = prdata;
if (handler)
handler(pkt.id, pkt.data, pkt.len);
return 0;
}
/*
* API let apps can register an ipi handler to receive IPI
* @param id: IPI ID
* @param handler: IPI handler
* @param name: IPI name
*/
enum scp_ipi_status scp_ipi_registration(enum ipi_id id,
void (*ipi_handler)(int id, void *data, unsigned int len),
const char *name)
{
int ret = SCP_IPI_ERROR;
if (id >= SCP_NR_IPI || id == IPI_MPOOL)
return SCP_IPI_ERROR;
if (ipi_handler == NULL)
return SCP_IPI_ERROR;
if (id > IPI_MPOOL) {
mpool[id - IPI_MPOOL - 1].handler = ipi_handler;
return SCP_IPI_DONE;
}
if (scp_ipi_legacy_id[id].in_id_0 != IPI_NO_USE) {
ret =
mtk_ipi_register(&scp_ipidev, scp_ipi_legacy_id[id].in_id_0,
(void *)scp_legacy_handler, ipi_handler,
scp_ipi_legacy_id[id].msg_0);
if (ret != IPI_ACTION_DONE)
return SCP_IPI_ERROR;
}
if (scp_ipi_legacy_id[id].in_id_1 != IPI_NO_USE) {
ret =
mtk_ipi_register(&scp_ipidev, scp_ipi_legacy_id[id].in_id_1,
(void *)scp_legacy_handler, ipi_handler,
scp_ipi_legacy_id[id].msg_1);
if (ret != IPI_ACTION_DONE)
return SCP_IPI_ERROR;
}
return SCP_IPI_DONE;
}
EXPORT_SYMBOL_GPL(scp_ipi_registration);
/*
* API let apps unregister an ipi handler
* @param id: IPI ID
*/
enum scp_ipi_status scp_ipi_unregistration(enum ipi_id id)
{
int ret;
if (id >= SCP_NR_IPI || id == IPI_MPOOL)
return SCP_IPI_ERROR;
if (id > IPI_MPOOL) {
/* if ipi id belongs to mbox pool, remove handler only */
mpool[id - IPI_MPOOL - 1].handler = NULL;
return SCP_IPI_DONE;
}
if (scp_ipi_legacy_id[id].in_id_0 != IPI_NO_USE) {
ret = mtk_ipi_unregister(&scp_ipidev,
scp_ipi_legacy_id[id].in_id_0);
if (ret != IPI_ACTION_DONE)
return SCP_IPI_ERROR;
}
if (scp_ipi_legacy_id[id].in_id_1 != IPI_NO_USE) {
ret = mtk_ipi_unregister(&scp_ipidev,
scp_ipi_legacy_id[id].in_id_1);
if (ret != IPI_ACTION_DONE)
return SCP_IPI_ERROR;
}
return SCP_IPI_DONE;
}
EXPORT_SYMBOL_GPL(scp_ipi_unregistration);
/*
* API for apps to send an IPI to scp
* @param id: IPI ID
* @param buf: the pointer of data
* @param len: data length
* @param wait: If true, wait (atomically) until data have been gotten by Host
* @param len: data length
*/
enum scp_ipi_status scp_ipi_send(enum ipi_id id, void *buf,
unsigned int len, unsigned int wait, enum scp_core_id scp_id)
{
/* declare pkt with a mbox maximum size for re-structing data */
char pkt[256];
int ret = SCP_IPI_ERROR, tmp_id;
void *ptr;
if (id >= SCP_NR_IPI || id == IPI_MPOOL)
return SCP_IPI_ERROR;
if (id > IPI_MPOOL)
tmp_id = IPI_MPOOL;
else
tmp_id = id;
if (is_scp_ready(scp_id) == 0) {
pr_notice("[SCP] %s: %s not ready\n", __func__, core_ids[scp_id]);
return SCP_IPI_NOT_READY;
}
if (len > (scp_ipi_legacy_id[tmp_id].out_size - 2) * MBOX_SLOT_SIZE) {
pr_notice("%s: len overflow\n", __func__);
return SCP_IPI_ERROR;
}
/* variation length will only support chre and sensor for reducing slot
* and cpu time cost by memcpy.
*/
memcpy((void *)pkt, (void *)&id, sizeof(uint32_t));
memcpy((void *)(pkt + 4), (void *)&len, sizeof(uint32_t));
memcpy((void *)(pkt + 8), buf, len);
ptr = pkt;
if (scp_ipi_legacy_id[tmp_id].out_id_0 != IPI_NO_USE
&& scp_id == (enum scp_core_id)SCP_CORE0_ID) {
ret =
mtk_ipi_send(&scp_ipidev, scp_ipi_legacy_id[tmp_id].out_id_0,
0, ptr, scp_ipi_legacy_id[tmp_id].out_size,
wait * SCP_IPI_LEGACY_WAIT);
if (ret == IPI_ACTION_DONE)
return SCP_IPI_DONE;
if (ret == IPI_PIN_BUSY)
return SCP_IPI_BUSY;
}
if (scp_ipi_legacy_id[tmp_id].out_id_1 != IPI_NO_USE
&& scp_id == (enum scp_core_id)SCP_CORE1_ID) {
ret =
mtk_ipi_send(&scp_ipidev, scp_ipi_legacy_id[tmp_id].out_id_1,
0, ptr, scp_ipi_legacy_id[tmp_id].out_size,
wait * SCP_IPI_LEGACY_WAIT);
if (ret == IPI_ACTION_DONE)
return SCP_IPI_DONE;
if (ret == IPI_PIN_BUSY)
return SCP_IPI_BUSY;
}
return SCP_IPI_ERROR;
}
EXPORT_SYMBOL_GPL(scp_ipi_send);
enum scp_ipi_status scp_legacy_ipi_init(void)
{
int ret = 0;
ret = mtk_ipi_register(&scp_ipidev, IPI_IN_SCP_MPOOL_0,
(void *)scp_legacy_handler, 0,
scp_ipi_legacy_id[0].msg_0);
if (ret != IPI_ACTION_DONE)
return SCP_IPI_ERROR;
ret = mtk_ipi_register(&scp_ipidev, IPI_IN_SCP_MPOOL_1,
(void *)scp_legacy_handler, 0,
scp_ipi_legacy_id[0].msg_1);
if (ret != IPI_ACTION_DONE)
return SCP_IPI_ERROR;
return SCP_IPI_DONE;
}
bool mbox_check_send_table(unsigned int id)
{
unsigned int i = 0;
for (i = 0; i < scp_mboxdev.send_count; i++)
if (scp_mbox_pin_send[i].chan_id == id)
return true;
return false;
}
bool mbox_check_recv_table(unsigned int id)
{
unsigned int i = 0;
for (i = 0; i < scp_mboxdev.recv_count; i++)
if (scp_mbox_pin_recv[i].chan_id == id)
return true;
return false;
}
void mbox_setup_pin_table(unsigned int mbox)
{
int i, last_ofs = 0, last_idx = 0, last_slot = 0, last_sz = 0;
for (i = 0; i < scp_mboxdev.send_count; i++) {
if (mbox == scp_mbox_pin_send[i].mbox) {
scp_mbox_pin_send[i].offset = last_ofs + last_slot;
scp_mbox_pin_send[i].pin_index = last_idx + last_sz;
last_idx = scp_mbox_pin_send[i].pin_index;
if (scp_mbox_info[mbox].is64d == 1) {
last_sz = DIV_ROUND_UP(
scp_mbox_pin_send[i].msg_size, 2);
last_ofs = last_sz * 2;
last_slot = last_idx * 2;
} else {
last_sz = scp_mbox_pin_send[i].msg_size;
last_ofs = last_sz;
last_slot = last_idx;
}
} else if (mbox < scp_mbox_pin_send[i].mbox)
break; /* no need to search the rest ipi */
}
for (i = 0; i < scp_mboxdev.recv_count; i++) {
if (mbox == scp_mbox_pin_recv[i].mbox) {
scp_mbox_pin_recv[i].offset = last_ofs + last_slot;
scp_mbox_pin_recv[i].pin_index = last_idx + last_sz;
last_idx = scp_mbox_pin_recv[i].pin_index;
if (scp_mbox_info[mbox].is64d == 1) {
last_sz = DIV_ROUND_UP(
scp_mbox_pin_recv[i].msg_size, 2);
last_ofs = last_sz * 2;
last_slot = last_idx * 2;
} else {
last_sz = scp_mbox_pin_recv[i].msg_size;
last_ofs = last_sz;
last_slot = last_idx;
}
} else if (mbox < scp_mbox_pin_recv[i].mbox)
break; /* no need to search the rest ipi */
}
if (last_idx > 32 ||
(last_ofs + last_slot) > (scp_mbox_info[mbox].is64d + 1) * 32) {
pr_notice("mbox%d ofs(%d)/slot(%d) exceed the maximum\n",
mbox, last_idx, last_ofs + last_slot);
WARN_ON(1);
}
}
/*
* API to dump wakeup reason for sensor ipi in detailed
*/
void mt_print_scp_ipi_id(unsigned int mbox)
{
unsigned int irq_status, i;
struct scp_ipi_info {
unsigned int id;
unsigned int len;
uint8_t info[4];
} buf;
irq_status = mtk_mbox_read_recv_irq(&scp_mboxdev, mbox);
for (i = 0; i < scp_mboxdev.recv_count; i++) {
if (scp_mbox_pin_recv[i].mbox == mbox) {
if (irq_status & 1 << scp_mbox_pin_recv[i].pin_index) {
if (scp_mbox_pin_recv[i].chan_id
== IPI_IN_SCP_MPOOL_0) {
/* only read 1st, 2nd, 3rd slot for
* sensor id, len, and header info
*/
mtk_mbox_read(&scp_mboxdev, mbox,
scp_mbox_pin_recv[i].offset,
&buf, MBOX_SLOT_SIZE * 3);
pr_info("[SCP] ipi id/type/action/event/reserve = %u/%u/%u/%u/%u\n",
buf.id, buf.info[0],
buf.info[1], buf.info[2],
buf.info[3]);
} else if (scp_mbox_pin_recv[i].chan_id
== IPI_IN_SENSOR_NOTIFY){
mtk_mbox_read(&scp_mboxdev, mbox,
scp_mbox_pin_recv[i].offset,
&buf.info, sizeof(buf.info));
pr_info("[SCP] sensor notify seq %u type %u cmd %u len %u\n",
buf.info[0], buf.info[1], buf.info[2], buf.info[3]);
} else {
pr_info("[SCP] mbox%u, ipi id %u\n",
mbox,
scp_mbox_pin_recv[i].chan_id);
}
}
}
}
}