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

+37
View File
@@ -0,0 +1,37 @@
config MTK_TINYSYS_SCP_SUPPORT
tristate "Specify Interface Support SCP"
default n
select MFD_SYSCON
help
SCP is a MediaTek in-house DSP which can receive
command from IPI interface.
Set Y to enable this feature.
If unsure,
Set N to stay with legacy feature.
config MTK_TINYSYS_SCP_CM4_SUPPORT
tristate "Specify micro processor CM4 supported by SCP"
depends on MTK_TINYSYS_SCP_SUPPORT
default n
help
CM4 is one uP supported by SCP which designed by ARM corp.
Set Y to enable this feature.
If unsure,
Set N to stay with legacy feature.
config MTK_TINYSYS_SCP_LOGGER_SUPPORT
bool "SCP Logger support"
depends on MTK_TINYSYS_SCP_SUPPORT
default y
help
This is debug feature: SCP logger on/off option.
Set Y to enable this feature.
Set N to disable this feature.
If unsure, Set Y to have debug log.
config MTK_TINYSYS_SCP_RV_SUPPORT
tristate "Specify micro processor RV supported by SCP"
depends on MTK_TINYSYS_SCP_SUPPORT
default n
help
MTK_TINYSYS_SCP_VERSION define which scp version will be used
+19
View File
@@ -0,0 +1,19 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
obj-$(CONFIG_MTK_TINYSYS_SCP_CM4_SUPPORT) += cm4/
obj-$(CONFIG_MTK_TINYSYS_SCP_RV_SUPPORT) += rv/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/
+44
View File
@@ -0,0 +1,44 @@
SCP_VERSION := v01
SCP_VERSION_PATH := ./$(SCP_VERSION)
obj-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_feature_table.o scp_awake.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += scp_dvfs.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += $(SCP_VERSION_PATH)/scp_helper.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += $(SCP_VERSION_PATH)/scp_excep.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += $(SCP_VERSION_PATH)/scp_ipi.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += $(SCP_VERSION_PATH)/scp_irq.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += $(SCP_VERSION_PATH)/scp_logger.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += $(SCP_VERSION_PATH)/scp_l1c.o
scp-$(CONFIG_MTK_TINYSYS_SCP_SUPPORT) += $(SCP_VERSION_PATH)/scp_scpctl.o
# include mtk_spm_resource_req
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/scp/include
# include emi_mpu.h
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/emi/submodule
ccflags-$(CONFIG_MTK_EMI_LEGACY) += -I$(srctree)/drivers/misc/mediatek/emi/$(CONFIG_MTK_PLATFORM)
ccflags-y += -I$(srctree)/drivers/devfreq/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/
#ifeq ($(CONFIG_MTK_ENG_BUILD),y)
CFLAGS_scp_logger.o += -DDEBUG
CFLAGS_scp_helper.o += -DDEBUG
CFLAGS_scp_excep.o += -DDEBUG
CFLAGS_scp_ipi.o += -DDEBUG
CFLAGS_scp_irq.o += -DDEBUG
CFLAGS_scp_dvfs.o += -DDEBUG
CFLAGS_scp_scpctl.o += -DDEBUG
#endif
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_MT6357)+= -I$(srctree)/drivers/misc/mediatek/pmic/include/mt6357
ccflags-$(CONFIG_MTK_PMIC_CHIP_MT6358)+= -I$(srctree)/drivers/misc/mediatek/pmic/include/mt6358
ccflags-$(CONFIG_MTK_PMIC_CHIP_MT6359)+= -I$(srctree)/drivers/misc/mediatek/pmic/include/mt6359
+306
View File
@@ -0,0 +1,306 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 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/aee.h>
#include <linux/delay.h>
#include "scp_feature_define.h"
#include "scp_ipi.h"
#include "scp_helper.h"
#include "scp_excep.h"
#include "scp_dvfs.h"
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(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 (atomic_read(&scp_reset_status) == RESET_STATUS_START) {
pr_notice("%s: resetting scp, break\n", __func__);
break;
}
tmp = readl(INFRA_IRQ_SET);
if ((tmp & 0xf0) != 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(readl(INFRA_IRQ_SET), 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);
WARN_ON(1);
#if SCP_RECOVERY_SUPPORT
if (scp_set_reset_status() == RESET_STATUS_STOP) {
pr_notice("%s: start to reset scp...\n", __func__);
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(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) {
tmp = readl(INFRA_IRQ_SET);
if ((tmp & 0xf0) != 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(readl(INFRA_IRQ_SET), INFRA_IRQ_CLEAR);
/* scp unlock awake success*/
if (ret != -1) {
if (*scp_awake_count <= 0)
pr_notice("%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;
}
/* 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_SRAM_PDN);
}
/*
* l1c sram, 64K / tail sram, +32k
* L1_SRAM_PD / d_l1c_SRAM_PD / d_l1c_tag_SRAM_PD
* / p_l1c_SRAM_PD / p_l1c_tag_SRAM_PD
*/
writel(0, SCP_CLK_CTRL_L1_SRAM_PD);
/* TCM_TAIL_SRAM_PD */
writel(0, SCP_CLK_CTRL_TCM_TAIL_SRAM_PD);
}
/*
* scp_sys_reset, reset scp
*/
#if SCP_RECOVERY_SUPPORT
int scp_sys_full_reset(void)
{
#if SCP_SYSTEM_RESET_SUPPORT
#define INFRA_SLP_PROT_BITS (SCP_TO_INFRA_BIT | SCP_TO_AUDIO_BIT)
#define SUBSYS_RESET_BITS (SCP_RESET_BIT | SCP_SEC_RESET_BIT)
unsigned int reset_timeout;
u32 tmp;
pr_notice("[SCP]full reset start\n");
pr_notice("[SCP]enable sleep protection\n");
/*enable sleep protection*/
reset_timeout = SCP_SYS_RESET_TIMEOUT;
tmp = readl(INFRA_SLP_PROT_SET);
writel(INFRA_SLP_PROT_BITS | tmp, INFRA_SLP_PROT_SET);
dsb(SY);
if ((readl(INFRA_SLP_PROT_STAT) & INFRA_SLP_PROT_BITS)
!= INFRA_SLP_PROT_BITS) {
pr_notice("[SCP]waiting sleep protection\n");
reset_timeout = SCP_SYS_RESET_TIMEOUT;
while ((reset_timeout > 0) &&
((readl(INFRA_SLP_PROT_STAT) & INFRA_SLP_PROT_BITS)
!= INFRA_SLP_PROT_BITS)) {
mdelay(1);
reset_timeout--;
}
if (reset_timeout == 0)
pr_notice("[SCP]sleep protection timeout\n");
}
pr_notice("[SCP]set subsys reset\n");
/*shut down scp subsys*/
reset_timeout = SCP_SYS_RESET_TIMEOUT;
tmp = readl(MODULE_RESET_STATUS);
writel(SUBSYS_RESET_BITS | tmp, MODULE_RESET_SET);
if ((readl(MODULE_RESET_STATUS) & SUBSYS_RESET_BITS)
!= SUBSYS_RESET_BITS) {
pr_notice("[SCP] sys reset waiting status...\n");
while ((reset_timeout > 0) &&
((readl(MODULE_RESET_STATUS) & SUBSYS_RESET_BITS)
!= SUBSYS_RESET_BITS)) {
mdelay(1);
reset_timeout--;
}
if (reset_timeout)
pr_notice("[SCP]full reset timeout\n");
}
/*finish the shutdown process by clearing reset bit*/
pr_notice("[SCP]clear subsys reset\n");
tmp = readl(MODULE_RESET_CLR);
writel(SUBSYS_RESET_BITS | tmp, MODULE_RESET_CLR);
/*enable scp sram*/
pr_notice("[SCP]enable sram\n");
scp_enable_sram();
#endif
pr_notice("[SCP]copy scp to sram\n");
/*copy loader to scp sram*/
memcpy_to_scp(SCP_TCM, (const void *)(size_t)scp_loader_base_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_SYSTEM_RESET_SUPPORT
pr_notice("[SCP]disable sleep protection\n");
/*disable sleep protection*/
tmp = readl(INFRA_SLP_PROT_SET);
writel(~INFRA_SLP_PROT_BITS & tmp,
INFRA_SLP_PROT_SET);
#endif
pr_notice("[SCP]full reset done\n");
return 0;
}
#else
int scp_sys_full_reset(void) { return 0; }
#endif
MODULE_LICENSE("GPL");
File diff suppressed because it is too large. Load diff
+188
View File
@@ -0,0 +1,188 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __SCP_DVFS_H__
#define __SCP_DVFS_H__
#define PLL_ENABLE (1)
#define PLL_DISABLE (0)
#define DVFS_STATUS_OK (0)
#define DVFS_STATUS_BUSY (-1)
#define DVFS_REQUEST_SAME_CLOCK (-2)
#define DVFS_STATUS_ERR (-3)
#define DVFS_STATUS_TIMEOUT (-4)
#define DVFS_CLK_ERROR (-5)
#define DVFS_STATUS_CMD_FIX (-6)
#define DVFS_STATUS_CMD_LIMITED (-7)
#define DVFS_STATUS_CMD_DISABLE (-8)
#define CLK_26M (26)
#if defined(CONFIG_MACH_MT6785)
#define MAINPLL_273M (218)
#else
#define MAINPLL_273M (273)
#endif
#define UNIVPLL_416M (416)
enum scp_state_enum {
IN_DEBUG_IDLE = 1,
ENTERING_SLEEP = 2,
IN_SLEEP = 4,
ENTERING_ACTIVE = 8,
IN_ACTIVE = 16,
};
enum {
CLK_SYS_EN_BIT = 0,
CLK_HIGH_EN_BIT = 1,
CLK_HIGH_CG_BIT = 2,
CLK_SYS_IRQ_EN_BIT = 16,
CLK_HIGH_IRQ_EN_BIT = 17,
};
#if defined(CONFIG_MACH_MT6781)
#include <linux/arm-smccc.h>
enum scp_req_r {
SCP_REQ_RELEASE = 0,
SCP_REQ_26M = 1 << 0,
SCP_REQ_IFR = 1 << 1,
SCP_REQ_SYSPLL1 = 1 << 2,
SCP_REQ_MAX = 1 << 3,
};
extern int scp_resource_req(unsigned int req_type);
#endif
enum clk_opp_enum {
#if defined(CONFIG_MACH_MT6781)
CLK_OPP0 = 125,
CLK_OPP1 = 250,
CLK_OPP2 = 273,
CLK_OPP3 = 330,
CLK_OPP4 = 416,
CLK_MAX_OPP = CLK_OPP4,
CLK_MAINPLL = CLK_OPP2,
CLK_UNIVPLL = CLK_OPP4,
#else
CLK_OPP0 = 110,
CLK_OPP1 = 130,
CLK_OPP2 = 165,
CLK_OPP3 = 218,
CLK_OPP4 = 330,
CLK_OPP5 = 416,
CLK_MAX_OPP = CLK_OPP5,
CLK_MAINPLL = CLK_OPP3,
CLK_UNIVPLL = CLK_OPP5,
#endif
CLK_UNINIT = 0xffff,
};
enum clk_div_enum {
CLK_DIV_1 = 0,
CLK_DIV_2 = 1,
CLK_DIV_4 = 2,
CLK_DIV_3 = 3,
};
enum subsys_enum {
SYS_GPIO = 0,
SYS_PMIC,
SYS_NUM,
};
enum sub_feature_enum {
GPIO_MODE = 0,
PMIC_VOW_LP,
PMIC_PMRC,
SUB_FEATURE_NUM,
};
enum scp_dvfs_smc_cmd {
SCP_DVFS_SMC_RESOURCE_REQ = 1,
SCP_DVFS_SMC_RESOURCE_REL,
SCP_DVFS_SMC_WRITE_SPM,
SCP_DVFS_SMC_READ_SPM,
};
enum scp_request_resources {
SCP_REQ_RESOURCE_26M = (1 << 1L),
SCP_REQ_RESOURCE_INFRA = (1 << 2L),
SCP_REQ_RESOURCE_SYSPLL = (1 << 3L),
SCP_REQ_RESOURCE_DRAM = (1 << 4L),
SCP_REQ_RESOURCE_ALL = (0xFFFFFFFF),
};
struct mt_scp_pll_t {
struct clk *clk_mux;
struct clk *clk_pll[8];
unsigned int pll_num;
};
struct reg_info {
unsigned int ofs;
unsigned int msk;
unsigned int bit;
unsigned int setclr;
};
struct reg_cfg {
unsigned int on;
unsigned int off;
};
struct sub_feature_data {
const char *name;
struct reg_info *reg;
struct reg_cfg *cfg;
unsigned int onoff;
int num;
};
struct subsys_data {
struct regmap *regmap;
struct sub_feature_data *fd;
int num;
};
struct dvfs_opp {
unsigned int vcore;
unsigned int vsram;
unsigned int uv_idx;
unsigned int dvfsrc_opp;
unsigned int spm_opp;
unsigned int freq;
unsigned int clk_mux;
};
struct dvfs_data {
struct dvfs_opp *opp;
int scp_opp_num;
int dvfsrc_opp_num;
};
extern int scp_pll_ctrl_set(unsigned int pll_ctrl_flag, unsigned int pll_sel);
extern int scp_set_pmic_vcore(unsigned int cur_freq);
extern unsigned int scp_get_dvfs_opp(void);
extern uint32_t scp_get_freq(void);
extern int scp_request_freq(void);
extern void scp_pll_mux_set(unsigned int pll_ctrl_flag);
extern void wait_scp_dvfs_init_done(void);
extern int __init scp_dvfs_init(void);
extern void __exit scp_dvfs_exit(void);
/* scp dvfs variable*/
extern unsigned int scp_expected_freq;
extern unsigned int scp_current_freq;
extern spinlock_t scp_awake_spinlock;
#endif /* __SCP_DVFS_H__ */
+197
View File
@@ -0,0 +1,197 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __SCP_EXCEP_H__
#define __SCP_EXCEP_H__
#include <linux/sizes.h>
#define AED_LOG_PRINT_SIZE SZ_16K
#define SCP_LOCK_OFS 0xE0
#define SCP_TCM_LOCK_BIT (1 << 20)
enum scp_excep_id {
EXCEP_LOAD_FIRMWARE = 0,
EXCEP_RESET,
EXCEP_BOOTUP,
EXCEP_RUNTIME,
SCP_NR_EXCEP,
};
extern void scp_aed(enum scp_excep_id 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_get_last_log(enum scp_core_id id);
extern void scp_A_dump_regs(void);
extern uint32_t scp_dump_pc(void);
extern uint32_t scp_dump_lr(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);
enum { r0, r1, r2, r3, r12, lr, pc, psr};
extern int scp_ee_enable;
struct TaskContextType {
unsigned int r0;
unsigned int r1;
unsigned int r2;
unsigned int r3;
unsigned int r4;
unsigned int r5;
unsigned int r6;
unsigned int r7;
unsigned int r8;
unsigned int r9;
unsigned int r10;
unsigned int r11;
unsigned int r12;
unsigned int sp; /* after pop r0-r3, lr, pc, xpsr */
unsigned int lr; /* lr before exception */
unsigned int pc; /* pc before exception */
unsigned int psr; /* xpsr before exeption */
unsigned int control;/*nPRIV bit & FPCA bit, SPSEL bit = 0*/
unsigned int exc_return; /* current lr */
unsigned int msp; /* msp */
};
#define CRASH_SUMMARY_LENGTH 12
#define CRASH_MEMORY_HEADER_SIZE (8 * 1024)
#define CRASH_MEMORY_OFFSET (0x800)
#define CRASH_MEMORY_LENGTH (SCP_A_TCM_SIZE - CRASH_MEMORY_OFFSET)
#define CRASH_REG_SIZE (9 * 32)
#include <linux/elf.h>
#define ELF_NGREGS 18
#define CORE_STR "CORE"
#define ELF_PRARGSZ 80
#define ELF_CORE_EFLAGS 0
#define EM_ARM 40
static inline void elf_setup_eident(unsigned char e_ident[EI_NIDENT],
unsigned char elfclasz)
{
memcpy(e_ident, ELFMAG, SELFMAG);
e_ident[EI_CLASS] = elfclasz;
e_ident[EI_DATA] = ELFDATA2LSB;
e_ident[EI_VERSION] = EV_CURRENT;
e_ident[EI_OSABI] = ELFOSABI_NONE;
memset(e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
}
struct elf_siginfo {
int si_signo;
int si_code;
int si_errno;
};
struct elf32_note_t {
Elf32_Word n_namesz; /* Name size */
Elf32_Word n_descsz; /* Content size */
Elf32_Word n_type; /* Content type */
};
struct elf32_timeval {
int32_t tv_sec;
int32_t tv_usec;
};
struct elf32_prstatus {
struct elf_siginfo pr_info;
short pr_cursig;
uint32_t pr_sigpend;
uint32_t pr_sighold;
int32_t pr_pid;
int32_t pr_ppid;
int32_t pr_pgrp;
int32_t pr_sid;
struct elf32_timeval pr_utime;
struct elf32_timeval pr_stime;
struct elf32_timeval pr_cutime;
struct elf32_timeval pr_cstime;
uint32_t pr_reg[ELF_NGREGS];
int32_t pr_fpvalid;
};
struct elf32_prpsinfo {
char pr_state;
char pr_sname;
char pr_zomb;
char pr_nice;
uint32_t pr_flag;
uint16_t pr_uid;
uint16_t pr_gid;
int32_t pr_pid;
int32_t pr_ppid;
int32_t pr_pgrp;
int32_t pr_sid;
char pr_fname[16];
char pr_psargs[ELF_PRARGSZ];
};
/* scp reg dump*/
struct scp_reg_dump_list {
uint32_t scp_reg_magic;
uint32_t ap_resource;
uint32_t bus_resource;
uint32_t slp_protect;
uint32_t cpu_sleep_status;
uint32_t clk_sw_sel;
uint32_t clk_enable;
uint32_t clk_high_core;
uint32_t debug_wdt_sp;
uint32_t debug_wdt_lr;
uint32_t debug_wdt_psp;
uint32_t debug_wdt_pc;
uint32_t debug_addr_s2r;
uint32_t debug_addr_dma;
uint32_t debug_addr_spi0;
uint32_t debug_addr_spi1;
uint32_t debug_addr_spi2;
uint32_t debug_bus_status;
uint32_t debug_infra_mon;
uint32_t infra_addr_latch;
uint32_t ddebug_latch;
uint32_t pdebug_latch;
uint32_t pc_value;
uint32_t scp_reg_magic_end;
};
struct scp_dump_header_list {
uint32_t scp_head_magic;
struct scp_region_info_st scp_region_info;
uint32_t scp_head_magic_end;
};
struct MemoryDump {
struct elf32_hdr elf;
struct elf32_phdr nhdr;
struct elf32_phdr phdr;
char notes[CRASH_MEMORY_HEADER_SIZE-sizeof(struct elf32_hdr)
-sizeof(struct elf32_phdr)-sizeof(struct elf32_phdr)
-sizeof(struct scp_dump_header_list)];
/* ram dump total header size(elf+nhdr+phdr+header)
* must be fixed at CRASH_MEMORY_HEADER_SIZE
*/
struct scp_dump_header_list scp_dump_header;
/*scp reg*/
struct scp_reg_dump_list scp_reg_dump;
/* scp sram, don't move it, variable array,
* size is CRASH_MEMORY_LENGTH.
*/
char memory[0];
};
#endif
@@ -0,0 +1,115 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 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)
#ifdef CONFIG_MTK_TINYSYS_SCP_LOGGER_SUPPORT
#define SCP_LOGGER_ENABLE (1)
#else
#define SCP_LOGGER_ENABLE (0)
#endif
#define SCP_DVFS_INIT_ENABLE (1)
#define SCP_RESERVED_MEM (1)
/* scp rescovery feature option*/
#define SCP_RECOVERY_SUPPORT (1)
/* scp recovery timeout value (ms)*/
/* #define SCP_PARAMS_TO_SCP_SUPPORT */
#define SCP_SYSTEM_RESET_SUPPORT (0)
#define SCP_SYS_RESET_TIMEOUT 1000
/* scp aed definition*/
#define SCP_AED_STR_LEN (512)
/* scp sub feature register API marco*/
#define SCP_REGISTER_SUB_SENSOR (1)
/* emi mpu define, depends on legacy emi config option */
#define ENABLE_SCP_EMI_PROTECTION (1)
#define MPU_DOMAIN_D0 0
#define MPU_DOMAIN_D3 3
/* 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;
uint32_t freq;
uint32_t enable;
uint32_t sub_feature;
};
struct scp_sub_feature_tb {
uint32_t feature;
uint32_t freq;
uint32_t enable;
};
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,198 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/module.h> /* needed by all modules */
#include "scp_feature_define.h"
#include "scp_ipi.h"
/*scp feature list*/
struct scp_feature_tb feature_table[NUM_FEATURE_ID] = {
{
.feature = VOW_FEATURE_ID,
.freq = 47,
.enable = 0,
.sub_feature = 0,
},
{
.feature = OPEN_DSP_FEATURE_ID,
.freq = 356,
.enable = 0,
.sub_feature = 0,
},
{
.feature = SENS_FEATURE_ID,
.freq = 62,
.enable = 0,
.sub_feature = 0,
},
{
.feature = MP3_FEATURE_ID,
.freq = 47,
.enable = 0,
.sub_feature = 0,
},
{
.feature = FLP_FEATURE_ID,
.freq = 26,
.enable = 0,
.sub_feature = 0,
},
{
.feature = RTOS_FEATURE_ID,
.freq = 0,
.enable = 0,
.sub_feature = 0,
},
{
.feature = SPEAKER_PROTECT_FEATURE_ID,
.freq = 200,
.enable = 0,
.sub_feature = 0,
},
{
.feature = VCORE_TEST_FEATURE_ID,
.freq = 0,
.enable = 0,
.sub_feature = 0,
},
{
.feature = VOW_BARGEIN_FEATURE_ID,
.freq = 100,
.enable = 0,
.sub_feature = 0,
},
{
.feature = VOW_DUMP_FEATURE_ID,
.freq = 10,
.enable = 0,
.sub_feature = 0,
},
{
.feature = VOW_VENDOR_M_FEATURE_ID,
.freq = 43,
.enable = 0,
.sub_feature = 0,
},
{
.feature = VOW_VENDOR_A_FEATURE_ID,
.freq = 43,
.enable = 0,
.sub_feature = 0,
},
{
.feature = VOW_VENDOR_G_FEATURE_ID,
.freq = 22,
.enable = 0,
.sub_feature = 0,
},
{
.feature = ULTRA_FEATURE_ID,
.freq = 200,
.enable = 0,
.sub_feature = 0,
},
};
/*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,
},
};
MODULE_LICENSE("GPL");
+174
View File
@@ -0,0 +1,174 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __SCP_HELPER_H__
#define __SCP_HELPER_H__
#include <linux/notifier.h>
#include <linux/interrupt.h>
#include "scp_reg.h"
#include "scp_feature_define.h"
/* scp config reg. definition*/
#define SCP_TCM_SIZE (scpreg.total_tcmsize)
#define SCP_A_TCM_SIZE (scpreg.scp_tcmsize)
#define SCP_TCM (scpreg.sram) /* virtual address */
#define SCP_REGION_INFO_OFFSET 0x400
#define SCP_RTOS_START 0x800
#define SCP_A_SHARE_BUFFER (scpreg.sram + \
SCP_RTOS_START - SHARE_BUF_SIZE * 2)
#define SCP_TCM_PHY_ADDR (0x10500000) /* AP view: physical address */
/* scp dvfs return status flag */
#define SET_PLL_FAIL (1)
#define SET_PMIC_VOLT_FAIL (2)
/* 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
#define SCP_A_ENABLE 0x10
#define SCP_A_REBOOT 0x11
/* scp reset status */
enum SCP_RESET_STATUS {
RESET_STATUS_STOP = 0,
RESET_STATUS_START = 1,
};
/* scp reset status */
enum SCP_RESET_TYPE {
RESET_TYPE_WDT = 0,
RESET_TYPE_AWAKE = 1,
RESET_TYPE_CMD = 2,
};
struct scp_regs {
void __iomem *scpsys;
void __iomem *sram;
void __iomem *cfg;
void __iomem *clkctrl;
void __iomem *l1cctrl;
int irq;
unsigned int total_tcmsize;
unsigned int cfgregsize;
unsigned int scp_tcmsize;
};
/* 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 Il1c_con;
uint32_t Dl1c_con;
uint32_t scpctl;
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 bin_attribute bin_attr_scp_dump;
/* scp loggger */
int scp_logger_init(phys_addr_t start, phys_addr_t limit);
void scp_logger_uninit(void);
/* scp exception */
extern int scp_excep_init(void);
extern void scp_ram_dump_init(void);
extern void scp_excep_cleanup(void);
extern void scp_aee_last_reg(void);
/* scp irq */
extern irqreturn_t scp_A_irq_handler(int irq, void *dev_id);
extern void scp_A_irq_init(void);
extern void scp_A_ipi_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 void __iomem *scp_mem_base_virt;
extern phys_addr_t scp_mem_size;
extern atomic_t scp_reset_status;
/*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 struct completion scp_sys_reset_cp;
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);
#if SCP_RECOVERY_SUPPORT
extern phys_addr_t scp_loader_base_virt;
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_l1c_start_virt;
#endif
__attribute__((weak))
int sensor_params_to_scp(void *addr_vir, size_t size);
#endif
+53
View File
@@ -0,0 +1,53 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __SCP_IPI_H
#define __SCP_IPI_H
#include "scp_reg.h"
#include "scp.h"
#define SHARE_BUF_SIZE 288
/* scp awake timeout count definition*/
#define SCP_AWAKE_TIMEOUT 100000
#define SCP_IPI_STAMP_SUPPORT 0
struct scp_ipi_desc {
void (*handler)(int id, void *data, unsigned int len);
#if SCP_IPI_STAMP_SUPPORT
#define SCP_IPI_ID_STAMP_SIZE 5
unsigned long long recv_timestamp[SCP_IPI_ID_STAMP_SIZE];
unsigned long long handler_timestamp[SCP_IPI_ID_STAMP_SIZE];
unsigned long long send_timestamp[SCP_IPI_ID_STAMP_SIZE];
unsigned int recv_flag[SCP_IPI_ID_STAMP_SIZE];
unsigned int send_flag[SCP_IPI_ID_STAMP_SIZE];
#endif
unsigned int recv_count;
unsigned int success_count;
unsigned int busy_count;
unsigned int error_count;
const char *name;
};
struct share_obj {
enum ipi_id id;
unsigned int len;
unsigned char reserve[8];
unsigned char share_buf[SHARE_BUF_SIZE - 16];
};
extern void scp_A_ipi_handler(void);
extern int wake_up_scp(void);
extern unsigned char *scp_send_buff[SCP_CORE_TOTAL];
extern unsigned char *scp_recv_buff[SCP_CORE_TOTAL];
extern char *core_ids[SCP_CORE_TOTAL];
extern void scp_reset_awake_counts(void);
extern int scp_awake_counts[];
extern void scp_ipi_status_dump(void);
extern void scp_ipi_status_dump_id(enum ipi_id id);
#endif
+57
View File
@@ -0,0 +1,57 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 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
+123
View File
@@ -0,0 +1,123 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __SCP_REG_H
#define __SCP_REG_H
/*#define SCP_BASE (scpreg.cfg)*/
#define SCP_AP_RESOURCE (scpreg.cfg + 0x0004)
#define SCP_BUS_RESOURCE (scpreg.cfg + 0x0008)
#define SCP_A_TO_HOST_REG (scpreg.cfg + 0x001C)
#define SCP_IRQ_SCP2HOST (1 << 0)
#define SCP_IRQ_WDT (1 << 8)
#define SCP_TO_SPM_REG (scpreg.cfg + 0x0020)
#define SCP_GIPC_IN_REG (scpreg.cfg + 0x0028)
#define HOST_TO_SCP_A (1 << 0)
#define HOST_TO_SCP_B (1 << 1)
/* scp awake lock definition*/
#define SCP_A_IPI_AWAKE_NUM (2)
#define SCP_B_IPI_AWAKE_NUM (3)
#define SCP_A_DEBUG_PC_REG (scpreg.cfg + 0x00B4)
#define SCP_A_DEBUG_PSP_REG (scpreg.cfg + 0x00B0)
#define SCP_A_DEBUG_LR_REG (scpreg.cfg + 0x00AC)
#define SCP_A_DEBUG_SP_REG (scpreg.cfg + 0x00A8)
#define SCP_A_WDT_REG (scpreg.cfg + 0x0084)
#define SCP_A_GENERAL_REG0 (scpreg.cfg + 0x0050)
#define SCP_A_GENERAL_REG1 (scpreg.cfg + 0x0054)
#define SCP_A_GENERAL_REG2 (scpreg.cfg + 0x0058)
/*EXPECTED_FREQ_REG*/
#define SCP_A_GENERAL_REG3 (scpreg.cfg + 0x005C)
#define EXPECTED_FREQ_REG (scpreg.cfg + 0x5C)
/*CURRENT_FREQ_REG*/
#define SCP_A_GENERAL_REG4 (scpreg.cfg + 0x0060)
#define CURRENT_FREQ_REG (scpreg.cfg + 0x60)
/*SCP_GPR_CM4_A_REBOOT*/
#define SCP_A_GENERAL_REG5 (scpreg.cfg + 0x0064)
#define SCP_GPR_CM4_A_REBOOT (scpreg.cfg + 0x64)
#define CM4_A_READY_TO_REBOOT 0x34
#define CM4_A_REBOOT_OK 0x1
#define SCP_A_GENERAL_REG6 (scpreg.cfg + 0x0068)
#define SCP_A_GENERAL_REG7 (scpreg.cfg + 0x006C)
#define SCP_SEMAPHORE (scpreg.cfg + 0x90)
#define SCP_SCP2SPM_VOL_LV (scpreg.cfg + 0x0094)
#define SCP_SLP_PROTECT_CFG (scpreg.cfg + 0x00C8)
#define SCP_WDT_SP (scpreg.cfg + 0x00B8)
#define SCP_WDT_LR (scpreg.cfg + 0x00BC)
#define SCP_WDT_PSP (scpreg.cfg + 0x00C0)
#define SCP_WDT_PC (scpreg.cfg + 0x00C4)
#define SCP_BUS_CTRL (scpreg.cfg + 0x00F0)
#define dbg_irq_info_sel_shift 26
#define dbg_irq_info_sel_mask (0x3 << 26)
#define SCP_DEBUG_ADDR_S2R (scpreg.cfg + 0x00F4)
#define SCP_DEBUG_ADDR_DMA (scpreg.cfg + 0x00F8)
#define SCP_DEBUG_ADDR_SPI0 (scpreg.cfg + 0x00FC)
#define SCP_DEBUG_ADDR_SPI1 (scpreg.cfg + 0x0100)
#define SCP_DEBUG_ADDR_SPI2 (scpreg.cfg + 0x0104)
#define SCP_DEBUG_BUS_STATUS (scpreg.cfg + 0x0110)
#define SCP_CPU_SLEEP_STATUS (scpreg.cfg + 0x0114)
#define SCP_A_DEEP_SLEEP_BIT (1)
#define SCP_B_DEEP_SLEEP_BIT (3)
#define SCP_SLEEP_STATUS_REG (scpreg.cfg + 0x0114)
#define SCP_A_IS_SLEEP (1<<0)
#define SCP_A_IS_DEEPSLEEP (1<<1)
#define SCP_B_IS_SLEEP (1<<2)
#define SCP_B_IS_DEEPSLEEP (1<<3)
#define INFRA_CTRL_STATUS (scpreg.cfg + 0x011C)
#define SCP_DEBUG_IRQ_INFO (scpreg.cfg + 0x0160)
/* clk reg*/
#define SCP_CLK_CTRL_BASE (scpreg.clkctrl)
#define SCP_CLK_SW_SEL (scpreg.clkctrl)
#define SCP_CLK_ENABLE (scpreg.clkctrl + 0x0004)
#define SCP_A_SLEEP_DEBUG_REG (scpreg.clkctrl + 0x0028)
#define SCP_SRAM_PDN (scpreg.clkctrl + 0x002C)
#define SCP_CLK_HIGH_CORE_CG (scpreg.clkctrl + 0x005C)
#define SCP_CLK_CTRL_L1_SRAM_PD (scpreg.clkctrl + 0x0080)
#define SCP_CLK_CTRL_TCM_TAIL_SRAM_PD (scpreg.clkctrl + 0x0094)
/* SCP INTC register*/
#define SCP_INTC_IRQ_STATUS (scpreg.cfg + 0x2000)
#define SCP_INTC_IRQ_ENABLE (scpreg.cfg + 0x2004)
#define SCP_INTC_IRQ_SLEEP (scpreg.cfg + 0x200C)
#define SCP_INTC_IRQ_STATUS_MSB (scpreg.cfg + 0x2080)
#define SCP_INTC_IRQ_ENABLE_MSB (scpreg.cfg + 0x2084)
#define SCP_INTC_IRQ_SLEEP_MSB (scpreg.cfg + 0x208C)
/* SCP System Reset */
#define MODULE_RESET_SET (scpreg.scpsys + 0x0140)
#define MODULE_RESET_CLR (scpreg.scpsys + 0x0144)
#define MODULE_RESET_STATUS (scpreg.scpsys + 0x0148)
#define SCP_RESET_BIT (1 << 3)
#define SCP_SEC_RESET_BIT (1 << 10)
/* INFRA Sleep Protect */
#define INFRA_SLP_PROT_SET (scpreg.scpsys + 0x220)
#define INFRA_SLP_PROT_STAT (scpreg.scpsys + 0x224)
#define SCP_TO_INFRA_BIT (1 << 30)
#define SCP_TO_AUDIO_BIT (1 << 31)
/* INFRA_IRQ */
#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,79 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __SCP_RESERVEDMEM_DEFINE_H__
#define __SCP_RESERVEDMEM_DEFINE_H__
static struct scp_reserve_mblock scp_reserve_mblock[] = {
{
.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 = MP3_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = FLP_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 = SPK_PROTECT_MEM_ID,
.start_phys = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
{
.num = SPK_PROTECT_DUMP_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 = 0x0,
.start_virt = 0x0,
.size = 0x0,
},
};
#endif
@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __SCP_SCPCTL_H__
#define __SCP_SCPCTL_H__
#include <linux/types.h>
enum SCPCTL_TYPE_E {
SCPCTL_TYPE_TMON,
};
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,34 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 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];
};
__attribute__((weak)) void report_hub_dmd(uint32_t case_id, uint32_t sensor_id,
char *context);
#endif // SCP_ERR_INFO_H
@@ -0,0 +1,802 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 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>
#if IS_ENABLED(CONFIG_MTK_AEE_FEATURE)
#include <mt-plat/aee.h>
#endif
#include <linux/sched_clock.h>
#include <linux/ratelimit.h>
#include <linux/delay.h>
#include "scp_ipi.h"
#include "scp_helper.h"
#include "scp_excep.h"
#include "scp_feature_define.h"
#include "scp_l1c.h"
struct scp_aed_cfg {
int *log;
int log_size;
int *phy;
int phy_size;
char *detail;
struct MemoryDump *pMemoryDump;
int memory_dump_size;
};
struct scp_status_reg {
unsigned int pc;
unsigned int lr;
unsigned int psp;
unsigned int sp;
unsigned int m2h;
unsigned int h2m;
};
static unsigned char *scp_A_detail_buffer;
static unsigned char *scp_A_dump_buffer;
static unsigned char *scp_A_dump_buffer_last;
static unsigned int scp_A_dump_length;
static unsigned int scp_A_task_context_addr;
static struct scp_work_struct scp_aed_work;
static struct scp_status_reg scp_A_aee_status;
static struct mutex scp_excep_mutex;
static struct mutex scp_A_excep_dump_mutex;
int scp_ee_enable;
/* An ELF note in memory */
struct memelfnote {
const char *name;
int type;
unsigned int datasz;
void *data;
};
static int notesize(struct memelfnote *en)
{
int sz;
sz = sizeof(struct elf32_note);
sz += roundup((strlen(en->name) + 1), 4);
sz += roundup(en->datasz, 4);
return sz;
}
static uint8_t *storenote(struct memelfnote *men, uint8_t *bufp)
{
struct elf32_note en;
en.n_namesz = strlen(men->name) + 1;
en.n_descsz = men->datasz;
en.n_type = men->type;
memcpy(bufp, &en, sizeof(en));
bufp += sizeof(en);
memcpy(bufp, men->name, en.n_namesz);
bufp += en.n_namesz;
bufp = (uint8_t *) roundup((unsigned long)bufp, 4);
memcpy(bufp, men->data, men->datasz);
bufp += men->datasz;
bufp = (uint8_t *) roundup((unsigned long)bufp, 4);
return bufp;
}
static uint8_t *core_write_cpu_note(int cpu, struct elf32_phdr *nhdr,
uint8_t *bufp, enum scp_core_id id)
{
struct memelfnote notes;
struct elf32_prstatus prstatus;
char cpustr[16];
memset(&prstatus, 0, sizeof(struct elf32_prstatus));
snprintf(cpustr, sizeof(cpustr), "CPU%d", cpu);
/* set up the process status */
notes.name = cpustr;
notes.type = NT_PRSTATUS;
notes.datasz = sizeof(struct elf32_prstatus);
notes.data = &prstatus;
prstatus.pr_pid = cpu + 1;
if (scp_A_task_context_addr && (id == SCP_A_ID)) {
memcpy_from_scp((void *)&(prstatus.pr_reg),
(void *)(SCP_TCM + scp_A_task_context_addr),
sizeof(prstatus.pr_reg));
}
if (prstatus.pr_reg[15] == 0x0 && (id == SCP_A_ID))
prstatus.pr_reg[15] = readl(SCP_A_DEBUG_PC_REG);
if (prstatus.pr_reg[14] == 0x0 && (id == SCP_A_ID))
prstatus.pr_reg[14] = readl(SCP_A_DEBUG_LR_REG);
if (prstatus.pr_reg[13] == 0x0 && (id == SCP_A_ID))
prstatus.pr_reg[13] = readl(SCP_A_DEBUG_PSP_REG);
nhdr->p_filesz += notesize(&notes);
return storenote(&notes, bufp);
}
void exception_header_init(void *oldbufp, enum scp_core_id id)
{
struct elf32_phdr *nhdr, *phdr;
struct elf32_hdr *elf;
off_t offset = 0;
uint8_t *bufp = oldbufp;
uint32_t cpu;
uint32_t dram_size = 0;
/* NT_PRPSINFO */
struct elf32_prpsinfo prpsinfo;
struct memelfnote notes;
elf = (struct elf32_hdr *) bufp;
bufp += sizeof(struct elf32_hdr);
offset += sizeof(struct elf32_hdr);
elf_setup_eident(elf->e_ident, ELFCLASS32);
/*setup elf header*/
elf->e_type = ET_CORE;
elf->e_machine = EM_ARM;
elf->e_version = EV_CURRENT;
elf->e_entry = 0;
elf->e_phoff = sizeof(struct elf32_hdr);
elf->e_shoff = 0;
elf->e_flags = ELF_CORE_EFLAGS;
elf->e_ehsize = sizeof(struct elf32_hdr);
elf->e_phentsize = sizeof(struct elf32_phdr);
elf->e_phnum = 2;
elf->e_shentsize = 0;
elf->e_shnum = 0;
elf->e_shstrndx = 0;
nhdr = (struct elf32_phdr *) bufp;
bufp += sizeof(struct elf32_phdr);
offset += sizeof(struct elf32_phdr);
memset(nhdr, 0, sizeof(struct elf32_phdr));
nhdr->p_type = PT_NOTE;
phdr = (struct elf32_phdr *) bufp;
bufp += sizeof(struct elf32_phdr);
offset += sizeof(struct elf32_phdr);
phdr->p_flags = PF_R|PF_W|PF_X;
phdr->p_offset = CRASH_MEMORY_HEADER_SIZE;
phdr->p_vaddr = CRASH_MEMORY_OFFSET;
phdr->p_paddr = CRASH_MEMORY_OFFSET;
#if SCP_RECOVERY_SUPPORT
if ((int)scp_region_info_copy.ap_dram_size > 0)
dram_size = scp_region_info_copy.ap_dram_size;
#endif
phdr->p_filesz = CRASH_MEMORY_LENGTH + roundup(dram_size, 4);
phdr->p_memsz = CRASH_MEMORY_LENGTH + roundup(dram_size, 4);
phdr->p_align = 0;
phdr->p_type = PT_LOAD;
nhdr->p_offset = offset;
/* set up the process info */
notes.name = CORE_STR;
notes.type = NT_PRPSINFO;
notes.datasz = sizeof(struct elf32_prpsinfo);
notes.data = &prpsinfo;
memset(&prpsinfo, 0, sizeof(struct elf32_prpsinfo));
prpsinfo.pr_state = 0;
prpsinfo.pr_sname = 'R';
prpsinfo.pr_zomb = 0;
prpsinfo.pr_gid = prpsinfo.pr_uid = 0x0;
strlcpy(prpsinfo.pr_fname, "freertos8",
sizeof(prpsinfo.pr_fname));
strlcpy(prpsinfo.pr_psargs, "freertos8", ELF_PRARGSZ);
nhdr->p_filesz += notesize(&notes);
bufp = storenote(&notes, bufp);
/* Store pre-cpu backtrace */
for (cpu = 0; cpu < 1; cpu++)
bufp = core_write_cpu_note(cpu, nhdr, bufp, id);
}
/*dump scp reg*/
void scp_reg_copy(void *bufp)
{
struct scp_reg_dump_list *scp_reg;
uint32_t tmp;
scp_reg = (struct scp_reg_dump_list *) bufp;
/*setup scp reg*/
scp_reg->scp_reg_magic = 0xDEADBEEF;
scp_reg->ap_resource = readl(SCP_AP_RESOURCE);
scp_reg->bus_resource = readl(SCP_BUS_RESOURCE);
scp_reg->slp_protect = readl(SCP_SLP_PROTECT_CFG);
scp_reg->cpu_sleep_status = readl(SCP_CPU_SLEEP_STATUS);
scp_reg->clk_sw_sel = readl(SCP_CLK_SW_SEL);
scp_reg->clk_enable = readl(SCP_CLK_ENABLE);
scp_reg->clk_high_core = readl(SCP_CLK_HIGH_CORE_CG);
scp_reg->debug_wdt_sp = readl(SCP_WDT_SP);
scp_reg->debug_wdt_lr = readl(SCP_WDT_LR);
scp_reg->debug_wdt_psp = readl(SCP_WDT_PSP);
scp_reg->debug_wdt_pc = readl(SCP_WDT_PC);
scp_reg->debug_addr_s2r = readl(SCP_DEBUG_ADDR_S2R);
scp_reg->debug_addr_dma = readl(SCP_DEBUG_ADDR_DMA);
scp_reg->debug_addr_spi0 = readl(SCP_DEBUG_ADDR_SPI0);
scp_reg->debug_addr_spi1 = readl(SCP_DEBUG_ADDR_SPI1);
scp_reg->debug_addr_spi2 = readl(SCP_DEBUG_ADDR_SPI2);
scp_reg->debug_bus_status = readl(SCP_DEBUG_BUS_STATUS);
/* scp_reg->debug_infra_mon = readl(SCP_SYS_INFRA_MON); */
tmp = readl(SCP_BUS_CTRL)&(~dbg_irq_info_sel_mask);
writel(tmp | (0 << dbg_irq_info_sel_shift), SCP_BUS_CTRL);
scp_reg->infra_addr_latch = readl(SCP_DEBUG_IRQ_INFO);
writel(tmp | (1 << dbg_irq_info_sel_shift), SCP_BUS_CTRL);
scp_reg->ddebug_latch = readl(SCP_DEBUG_IRQ_INFO);
writel(tmp | (2 << dbg_irq_info_sel_shift), SCP_BUS_CTRL);
scp_reg->pdebug_latch = readl(SCP_DEBUG_IRQ_INFO);
writel(tmp | (3 << dbg_irq_info_sel_shift), SCP_BUS_CTRL);
scp_reg->pc_value = readl(SCP_DEBUG_IRQ_INFO);
scp_reg->scp_reg_magic_end = 0xDEADBEEF;
}
/*dump scp l1c header*/
void scp_sub_header_init(void *bufp)
{
struct scp_dump_header_list *scp_sub_head;
scp_sub_head = (struct scp_dump_header_list *) bufp;
/*setup scp reg*/
scp_sub_head->scp_head_magic = 0xDEADBEEF;
#if SCP_RECOVERY_SUPPORT
memcpy(&scp_sub_head->scp_region_info,
&scp_region_info_copy, sizeof(scp_region_info_copy));
#endif
scp_sub_head->scp_head_magic_end = 0xDEADBEEF;
}
/*
* return last lr for debugging
*/
uint32_t scp_dump_lr(void)
{
if (is_scp_ready(SCP_A_ID))
return readl(SCP_A_DEBUG_LR_REG);
else
return 0xFFFFFFFF;
}
/*
* return last pc for debugging
*/
uint32_t scp_dump_pc(void)
{
if (is_scp_ready(SCP_A_ID))
return readl(SCP_A_DEBUG_PC_REG);
else
return 0xFFFFFFFF;
}
/*
* dump scp register for debugging
*/
void scp_A_dump_regs(void)
{
uint32_t tmp;
if (is_scp_ready(SCP_A_ID)) {
pr_debug("[SCP]ready PC:0x%x,LR:0x%x,PSP:0x%x,SP:0x%x\n"
, readl(SCP_A_DEBUG_PC_REG), readl(SCP_A_DEBUG_LR_REG)
, readl(SCP_A_DEBUG_PSP_REG), readl(SCP_A_DEBUG_SP_REG));
} else {
pr_debug("[SCP]not ready PC:0x%x,LR:0x%x,PSP:0x%x,SP:0x%x\n"
, readl(SCP_A_DEBUG_PC_REG), readl(SCP_A_DEBUG_LR_REG)
, readl(SCP_A_DEBUG_PSP_REG), readl(SCP_A_DEBUG_SP_REG));
}
pr_debug("[SCP]GIPC 0x%x\n", readl(SCP_GIPC_IN_REG));
pr_debug("[SCP]BUS_CTRL 0x%x\n", readl(SCP_BUS_CTRL));
pr_debug("[SCP]SLEEP_STATUS 0x%x\n", readl(SCP_CPU_SLEEP_STATUS));
pr_debug("[SCP]INFRA_STATUS 0x%x\n", readl(INFRA_CTRL_STATUS));
pr_debug("[SCP]IRQ_STATUS 0x%x\n", readl(SCP_INTC_IRQ_STATUS));
pr_debug("[SCP]IRQ_ENABLE 0x%x\n", readl(SCP_INTC_IRQ_ENABLE));
pr_debug("[SCP]IRQ_SLEEP 0x%x\n", readl(SCP_INTC_IRQ_SLEEP));
pr_debug("[SCP]IRQ_STATUS_MSB 0x%x\n", readl(SCP_INTC_IRQ_STATUS_MSB));
pr_debug("[SCP]IRQ_ENABLE_MSB 0x%x\n", readl(SCP_INTC_IRQ_ENABLE_MSB));
pr_debug("[SCP]IRQ_SLEEP_MSB 0x%x\n", readl(SCP_INTC_IRQ_SLEEP_MSB));
pr_debug("[SCP]CLK_CTRL_SEL 0x%x\n", readl(SCP_CLK_SW_SEL));
pr_debug("[SCP]CLK_ENABLE 0x%x\n", readl(SCP_CLK_ENABLE));
pr_debug("[SCP]SLEEP_DEBUG 0x%x\n", readl(SCP_A_SLEEP_DEBUG_REG));
tmp = readl(SCP_BUS_CTRL)&(~dbg_irq_info_sel_mask);
writel(tmp | (0 << dbg_irq_info_sel_shift), SCP_BUS_CTRL);
pr_debug("[SCP]BUS:INFRA LATCH, 0x%x\n", readl(SCP_DEBUG_IRQ_INFO));
writel(tmp | (1 << dbg_irq_info_sel_shift), SCP_BUS_CTRL);
pr_debug("[SCP]BUS:DCACHE LATCH, 0x%x\n", readl(SCP_DEBUG_IRQ_INFO));
writel(tmp | (2 << dbg_irq_info_sel_shift), SCP_BUS_CTRL);
pr_debug("[SCP]BUS:ICACHE LATCH, 0x%x\n", readl(SCP_DEBUG_IRQ_INFO));
writel(tmp | (3 << dbg_irq_info_sel_shift), SCP_BUS_CTRL);
pr_debug("[SCP]BUS:PC LATCH, 0x%x\n", readl(SCP_DEBUG_IRQ_INFO));
}
/*
* save scp register when scp crash
* these data will be used to generate EE
*/
void scp_aee_last_reg(void)
{
pr_debug("[SCP] %s begins\n", __func__);
scp_A_aee_status.pc = readl(SCP_A_DEBUG_PC_REG);
scp_A_aee_status.lr = readl(SCP_A_DEBUG_LR_REG);
scp_A_aee_status.psp = readl(SCP_A_DEBUG_PSP_REG);
scp_A_aee_status.sp = readl(SCP_A_DEBUG_SP_REG);
scp_A_aee_status.m2h = readl(SCP_A_TO_HOST_REG);
scp_A_aee_status.h2m = readl(SCP_GIPC_IN_REG);
pr_debug("[SCP] %s ends\n", __func__);
}
/*
* this function need SCP to keeping awaken
* scp_crash_dump: dump scp tcm info.
* @param MemoryDump: scp dump struct
* @param scp_core_id: core id
* @return: scp dump size
*/
static unsigned int scp_crash_dump(struct MemoryDump *pMemoryDump,
enum scp_core_id id)
{
unsigned int lock;
unsigned int *reg;
unsigned int scp_dump_size;
unsigned int scp_awake_fail_flag;
#if SCP_RECOVERY_SUPPORT
uint32_t dram_start = 0;
#endif
uint32_t dram_size = 0;
/*flag use to indicate scp awake success or not*/
scp_awake_fail_flag = 0;
/*check SRAM lock ,awake scp*/
if (scp_awake_lock(id) == -1) {
pr_err("[SCP] %s: awake scp fail, scp id=%u\n", __func__, id);
scp_awake_fail_flag = 1;
}
reg = (unsigned int *) (scpreg.cfg + SCP_LOCK_OFS);
lock = *reg;
*reg &= ~SCP_TCM_LOCK_BIT;
dsb(SY);
if ((*reg & SCP_TCM_LOCK_BIT)) {
pr_debug("[SCP]unlock failed, skip dump\n");
return 0;
}
#if SCP_RECOVERY_SUPPORT
/* L1C support? */
if ((int)(scp_region_info_copy.ap_dram_size) <= 0) {
scp_dump_size = sizeof(struct MemoryDump) + CRASH_MEMORY_LENGTH;
} else {
dram_start = scp_region_info_copy.ap_dram_start;
dram_size = scp_region_info_copy.ap_dram_size;
scp_dump_size = sizeof(struct MemoryDump) + CRASH_MEMORY_LENGTH +
roundup(dram_size, 4);
}
#else
scp_dump_size = 0;
#endif
exception_header_init(pMemoryDump, id);
/* init sub header*/
scp_sub_header_init(&(pMemoryDump->scp_dump_header));
memcpy_from_scp((void *)&(pMemoryDump->memory),
(void *)(SCP_TCM + CRASH_MEMORY_OFFSET),
(SCP_A_TCM_SIZE - CRASH_MEMORY_OFFSET));
/* L1C support? */
if (dram_size) {
/* l1c enable,flua l1c */
scp_l1c_flua(SCP_DL1C);
scp_l1c_flua(SCP_IL1C);
udelay(10);
#if SCP_RECOVERY_SUPPORT
pr_debug("scp:scp_l1c_start_virt %p\n",
scp_l1c_start_virt);
/* copy dram data*/
memcpy((void *)&(pMemoryDump->scp_reg_dump),
scp_l1c_start_virt, dram_size);
/* dump scp reg */
#endif
scp_reg_copy((void *)(&pMemoryDump->scp_reg_dump) +
roundup(dram_size, 4));
} else {
/* dump scp reg */
scp_reg_copy(&(pMemoryDump->scp_reg_dump));
}
*reg = lock;
dsb(SY);
/*check SRAM unlock*/
if (scp_awake_fail_flag != 1) {
if (scp_awake_unlock(id) == -1)
pr_debug("[SCP]%s awake unlock fail, scp id=%u\n",
__func__, id);
}
return scp_dump_size;
}
/*
* generate aee argument without dump scp register
* @param aed_str: exception description
* @param aed: struct to store argument for aee api
*/
static void scp_prepare_aed(char *aed_str, struct scp_aed_cfg *aed)
{
char *detail, *log;
u8 *phy;
u32 log_size, phy_size;
int ret = 0;
pr_debug("[SCP] %s begins\n", __func__);
aed->detail = NULL;
detail = scp_A_detail_buffer;
if (!detail)
return;
memset(detail, 0, SCP_AED_STR_LEN);
ret = snprintf(detail, SCP_AED_STR_LEN, "%s\n", aed_str);
if (ret < 0)
pr_err("[SCP] detail msg is truncated\n");
detail[SCP_AED_STR_LEN - 1] = '\0';
log_size = 0;
log = NULL;
phy_size = 0;
phy = NULL;
aed->log = (int *)log;
aed->log_size = log_size;
aed->phy = (int *)phy;
aed->phy_size = phy_size;
aed->detail = detail;
pr_debug("[SCP] %s ends\n", __func__);
}
/*
* generate aee argument with scp register dump
* @param aed_str: exception description
* @param aed: struct to store argument for aee api
* @param id: identify scp core id
*/
static void scp_prepare_aed_dump(char *aed_str,
struct scp_aed_cfg *aed,
enum scp_core_id id)
{
u8 *scp_detail;
u8 *scp_dump_ptr;
int ret = 0;
u32 memory_dump_size;
struct MemoryDump *pMemoryDump = NULL;
char *scp_A_log = NULL;
pr_debug("[SCP] %s begins:%s\n", __func__, aed_str);
scp_aee_last_reg();
scp_A_log = scp_get_last_log(SCP_A_ID);
/* prepare scp aee detail information */
scp_detail = scp_A_detail_buffer;
if (!scp_detail) {
pr_err("[SCP AEE]detail buf is null\n");
} else {
/* prepare scp aee detail information*/
memset(scp_detail, 0, SCP_AED_STR_LEN);
ret = snprintf(scp_detail, SCP_AED_STR_LEN,
"%s\nscp_A pc=0x%08x, lr=0x%08x, psp=0x%08x, sp=0x%08x\n"
"last log:\n%s",
aed_str, scp_A_aee_status.pc,
scp_A_aee_status.lr,
scp_A_aee_status.psp,
scp_A_aee_status.sp,
scp_A_log);
if (ret < 0)
pr_err("[SCP AEE] detail buf msg is truncated\n");
scp_detail[SCP_AED_STR_LEN - 1] = '\0';
}
/*prepare scp A db file*/
memory_dump_size = 0;
scp_dump_ptr = scp_A_dump_buffer_last;
if (!scp_dump_ptr) {
pr_err("[SCP AEE]MemoryDump buf is null, size=0x%x\n",
memory_dump_size);
memory_dump_size = 0;
} else {
pr_debug("[SCP AEE]scp A dump ptr:%p\n", scp_dump_ptr);
pMemoryDump = (struct MemoryDump *) scp_dump_ptr;
memset(pMemoryDump, 0x0, sizeof(*pMemoryDump) + CRASH_MEMORY_LENGTH);
memory_dump_size = scp_crash_dump(pMemoryDump, SCP_A_ID);
}
/* scp_dump_buffer_set */
mutex_lock(&scp_A_excep_dump_mutex);
scp_A_dump_buffer_last = scp_A_dump_buffer;
scp_A_dump_buffer = scp_dump_ptr;
scp_A_dump_length = memory_dump_size;
mutex_unlock(&scp_A_excep_dump_mutex);
aed->log = NULL;
aed->log_size = 0;
aed->phy = NULL;
aed->phy_size = 0;
aed->detail = scp_detail;
aed->pMemoryDump = NULL;
aed->memory_dump_size = 0;
pr_debug("[SCP] %s ends\n", __func__);
}
/*
* generate an exception according to exception type
* @param type: exception type
*/
void scp_aed(enum scp_excep_id type, enum scp_core_id id)
{
struct scp_aed_cfg aed;
char *scp_aed_title;
mutex_lock(&scp_excep_mutex);
/* get scp title and exception type*/
switch (type) {
case EXCEP_LOAD_FIRMWARE:
scp_prepare_aed("scp firmware load exception", &aed);
if (id == SCP_A_ID)
scp_aed_title = "SCP_A load firmware exception";
else
scp_aed_title = "SCP load firmware exception";
break;
case EXCEP_RESET:
if (id == SCP_A_ID)
scp_aed_title = "SCP_A reset exception";
else
scp_aed_title = "SCP reset exception";
break;
case EXCEP_BOOTUP:
if (id == SCP_A_ID)
scp_aed_title = "SCP_A boot exception";
else
scp_aed_title = "SCP boot exception";
scp_get_log(id);
break;
case EXCEP_RUNTIME:
if (id == SCP_A_ID)
scp_aed_title = "SCP_A runtime exception";
else
scp_aed_title = "SCP runtime exception";
scp_get_log(id);
break;
default:
scp_prepare_aed("scp unknown exception", &aed);
if (id == SCP_A_ID)
scp_aed_title = "SCP_A unknown exception";
else
scp_aed_title = "SCP unknown exception";
break;
}
/*print scp message*/
pr_debug("scp_aed_title=%s", scp_aed_title);
if (type != EXCEP_LOAD_FIRMWARE)
scp_prepare_aed_dump(scp_aed_title, &aed, id);
/*print detail info. in kernel*/
pr_debug("%s", aed.detail);
#if IS_ENABLED(CONFIG_MTK_AEE_FEATURE)
/* scp aed api, only detail information available*/
aed_common_exception_api("scp", NULL, 0, NULL, 0,
aed.detail, DB_OPT_DEFAULT);
#endif
pr_debug("[SCP] scp exception dump is done\n");
mutex_unlock(&scp_excep_mutex);
}
/*
* generate an exception and reset scp right now
* NOTE: this function may be blocked and
* should not be called in interrupt context
* @param type: exception type
*/
void scp_aed_reset_inplace(enum scp_excep_id type, enum scp_core_id id)
{
pr_debug("[SCP] %s begins\n", __func__);
if (scp_ee_enable)
scp_aed(type, id);
else
pr_debug("[SCP]ee disable value=%d\n", scp_ee_enable);
#if (SCP_RECOVERY_SUPPORT == 0)
/* workaround for QA, not reset SCP in WDT */
if (type == EXCEP_RUNTIME)
return;
#endif
#if SCP_RECOVERY_SUPPORT
if (atomic_read(&scp_reset_status) == RESET_STATUS_START) {
/*complete scp ee, if scp reset by wdt or awake fail*/
pr_debug("[SCP]aed finished, complete it\n");
complete(&scp_sys_reset_cp);
}
#endif
}
/*
* callback function for work struct
* generate an exception and reset scp
* NOTE: this function may be blocked
* and should not be called in interrupt context
* @param ws: work struct
*/
static void scp_aed_reset_ws(struct work_struct *ws)
{
struct scp_work_struct *sws = container_of(ws,
struct scp_work_struct, work);
enum scp_excep_id type = (enum scp_excep_id) sws->flags;
enum scp_core_id id = (enum scp_core_id) sws->id;
pr_debug("[SCP] %s begins: scp_excep_id=%u scp_core_id=%u\n",
__func__, type, id);
scp_aed_reset_inplace(type, id);
}
/*
* schedule a work to generate an exception and reset scp
* @param type: exception type
*/
void scp_aed_reset(enum scp_excep_id type, enum scp_core_id id)
{
scp_aed_work.flags = (unsigned int) type;
scp_aed_work.id = (unsigned int) id;
scp_schedule_work(&scp_aed_work);
}
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;
mutex_lock(&scp_A_excep_dump_mutex);
if (offset >= 0 && offset < scp_A_dump_length) {
if ((offset + size) > scp_A_dump_length)
size = scp_A_dump_length - offset;
memcpy(buf, scp_A_dump_buffer + offset, size);
length = size;
}
mutex_unlock(&scp_A_excep_dump_mutex);
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;
mutex_init(&scp_excep_mutex);
mutex_init(&scp_A_excep_dump_mutex);
INIT_WORK(&scp_aed_work.work, scp_aed_reset_ws);
#if SCP_RECOVERY_SUPPORT
/* support L1C or not? */
if ((int)(scp_region_info->ap_dram_size) > 0)
dram_size = scp_region_info->ap_dram_size;
#else
dram_size = 0;
#endif
/* alloc dump memory */
scp_A_detail_buffer = vmalloc(SCP_AED_STR_LEN);
if (!scp_A_detail_buffer)
return -1;
scp_A_dump_buffer = vmalloc(sizeof(struct MemoryDump) +
CRASH_MEMORY_LENGTH + roundup(dram_size, 4));
if (!scp_A_dump_buffer)
goto _err;
scp_A_dump_buffer_last = vmalloc(sizeof(struct MemoryDump) +
CRASH_MEMORY_LENGTH + roundup(dram_size, 4));
if (!scp_A_dump_buffer_last)
goto _err1;
/* init global values */
scp_A_dump_length = 0;
/* 1: ee on, 0: ee disable */
scp_ee_enable = 1;
return 0;
_err1:
vfree(scp_A_dump_buffer);
_err:
vfree(scp_A_detail_buffer);
return -1;
}
/******************************************************************************
* 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)
{
#if SCP_RECOVERY_SUPPORT
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);
#endif
}
/*
* cleanup scp exception
*/
void scp_excep_cleanup(void)
{
vfree(scp_A_detail_buffer);
vfree(scp_A_dump_buffer_last);
vfree(scp_A_dump_buffer);
scp_A_task_context_addr = 0;
pr_debug("[SCP] %s ends\n", __func__);
}
File diff suppressed because it is too large. Load diff
+380
View File
@@ -0,0 +1,380 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/mutex.h>
#include <linux/io.h>
#include "scp_ipi.h"
#include "scp_helper.h"
#include "scp_excep.h"
#define PRINT_THRESHOLD 10000
enum ipi_id scp_ipi_id_record;
enum ipi_id scp_ipi_mutex_owner[SCP_CORE_TOTAL];
enum ipi_id scp_ipi_owner[SCP_CORE_TOTAL];
unsigned int scp_ipi_id_record_count;
unsigned int scp_to_ap_ipi_count;
unsigned int ap_to_scp_ipi_count;
struct scp_ipi_desc scp_ipi_desc[SCP_NR_IPI];
struct share_obj *scp_send_obj[SCP_CORE_TOTAL];
struct share_obj *scp_rcv_obj[SCP_CORE_TOTAL];
struct mutex scp_ipi_mutex[SCP_CORE_TOTAL];
/*
* find an ipi handler and invoke it
*/
void scp_A_ipi_handler(void)
{
#if SCP_IPI_STAMP_SUPPORT
unsigned int flag = 0;
#endif
enum ipi_id scp_id;
scp_id = scp_rcv_obj[SCP_A_ID]->id;
/*pr_debug("scp A ipi handler %d\n", scp_id);*/
if (scp_id >= SCP_NR_IPI || scp_id <= 0) {
/* ipi id abnormal*/
pr_debug("[SCP] A ipi handler id abnormal, id=%d\n", scp_id);
} else if (scp_ipi_desc[scp_id].handler) {
memcpy_from_scp(scp_recv_buff[SCP_A_ID],
(void *)scp_rcv_obj[SCP_A_ID]->share_buf,
scp_rcv_obj[SCP_A_ID]->len);
scp_ipi_desc[scp_id].recv_count++;
scp_to_ap_ipi_count++;
#if SCP_IPI_STAMP_SUPPORT
flag = scp_ipi_desc[scp_id].recv_count % SCP_IPI_ID_STAMP_SIZE;
if (flag < SCP_IPI_ID_STAMP_SIZE) {
scp_ipi_desc[scp_id].recv_flag[flag] =
scp_ipi_desc[scp_id].recv_count;
scp_ipi_desc[scp_id].handler_timestamp[flag] = 0;
scp_ipi_desc[scp_id].recv_timestamp[flag] =
arch_counter_get_cntvct();
}
#endif
scp_ipi_desc[scp_id].handler(scp_id, scp_recv_buff[SCP_A_ID],
scp_rcv_obj[SCP_A_ID]->len);
#if SCP_IPI_STAMP_SUPPORT
if (flag < SCP_IPI_ID_STAMP_SIZE)
scp_ipi_desc[scp_id].handler_timestamp[flag] =
arch_counter_get_cntvct();
#endif
/* After SCP IPI handler,
* send a awake ipi to avoid
* SCP keeping in ipi busy idle state
*/
/* set a direct IPI to awake SCP */
writel((1 << SCP_A_IPI_AWAKE_NUM), SCP_GIPC_IN_REG);
} else {
/* scp_ipi_handler is null or ipi id abnormal */
pr_debug("[SCP] A ipi handler is null or abnormal, id=%d\n"
, scp_id);
}
/* AP side write 1 to clear SCP to SPM reg.
* scp side write 1 to set SCP to SPM reg.
* scp set bit[0]
*/
writel(0x1, SCP_TO_SPM_REG);
/*pr_debug("scp_ipi_handler done\n");*/
}
/*
* ipi initialize
*/
void scp_A_ipi_init(void)
{
#if SCP_IPI_STAMP_SUPPORT
int j = 0;
#endif
mutex_init(&scp_ipi_mutex[SCP_A_ID]);
scp_rcv_obj[SCP_A_ID] = SCP_A_SHARE_BUFFER;
scp_send_obj[SCP_A_ID] = scp_rcv_obj[SCP_A_ID] + 1;
pr_debug("[SCP] scp_rcv_obj[A] = 0x%p\n", scp_rcv_obj[SCP_A_ID]);
pr_debug("[SCP] scp_send_obj[A] = 0x%p\n", scp_send_obj[SCP_A_ID]);
memset_io(scp_send_obj[SCP_A_ID], 0, SHARE_BUF_SIZE);
scp_to_ap_ipi_count = 0;
ap_to_scp_ipi_count = 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)
{
if (id < SCP_NR_IPI) {
scp_ipi_desc[id].name = name;
if (ipi_handler == NULL)
return SCP_IPI_ERROR;
scp_ipi_desc[id].handler = ipi_handler;
return SCP_IPI_DONE;
} else {
return SCP_IPI_ERROR;
}
}
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)
{
if (id < SCP_NR_IPI) {
scp_ipi_desc[id].name = "";
scp_ipi_desc[id].handler = NULL;
return SCP_IPI_DONE;
} else {
return SCP_IPI_ERROR;
}
}
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)
{
#if SCP_IPI_STAMP_SUPPORT
unsigned long flag = 0;
#endif
/* the variable is for reading back the id from sram
* to check the if the sram is ready for accesses.
*/
enum ipi_id rb_id;
/*avoid scp log print too much*/
if (scp_ipi_id_record == id)
scp_ipi_id_record_count++;
else
scp_ipi_id_record_count = 0;
scp_ipi_id_record = id;
if (scp_id >= SCP_CORE_TOTAL) {
pr_err("[SCP] %s: scp_id:%d wrong\n", __func__, scp_id);
scp_ipi_desc[id].error_count++;
return SCP_IPI_ERROR;
}
if (in_interrupt()) {
if (wait) {
pr_err("[SCP] %s: cannot use in isr\n", __func__);
scp_ipi_desc[id].error_count++;
return SCP_IPI_ERROR;
}
}
if (id >= SCP_NR_IPI) {
pr_err("[SCP] %s: ipi id %d wrong\n", __func__, id);
return SCP_IPI_ERROR;
}
if (is_scp_ready(scp_id) == 0) {
/* pr_err("[SCP] %s: %s not enabled, id=%d\n", __func__
* , core_ids[scp_id], id);
*/
pr_notice("[SCP] %s: %s not ready\n", __func__,
core_ids[scp_id]);
scp_ipi_desc[id].error_count++;
return SCP_IPI_ERROR;
}
if (len > sizeof(scp_send_obj[scp_id]->share_buf) || buf == NULL) {
pr_err("[SCP] %s: %s buffer error\n", __func__,
core_ids[scp_id]);
scp_ipi_desc[id].error_count++;
return SCP_IPI_ERROR;
}
#if SCP_RECOVERY_SUPPORT
if (atomic_read(&scp_reset_status) == RESET_STATUS_START) {
pr_notice("[SCP] %s: %s reset start\n", __func__,
core_ids[scp_id]);
scp_ipi_desc[id].error_count++;
return SCP_IPI_ERROR;
}
#endif
if (mutex_trylock(&scp_ipi_mutex[scp_id]) == 0) {
/*avoid scp ipi send log print too much*/
if ((scp_ipi_id_record_count % PRINT_THRESHOLD == 0) ||
(scp_ipi_id_record_count % PRINT_THRESHOLD == 1)) {
pr_err("[SCP] %s:%s %d mutex busy, owner=%d\n",
__func__, core_ids[scp_id], id,
scp_ipi_mutex_owner[scp_id]);
}
scp_ipi_desc[id].busy_count++;
return SCP_IPI_BUSY;
}
/* keep scp awake for sram copy*/
if (scp_awake_lock(scp_id) == -1) {
mutex_unlock(&scp_ipi_mutex[scp_id]);
pr_err("[SCP] %s: %s ipi error, awake scp fail\n", __func__,
core_ids[scp_id]);
scp_ipi_desc[id].error_count++;
return SCP_IPI_ERROR;
}
/*get scp ipi mutex owner*/
scp_ipi_mutex_owner[scp_id] = id;
if ((readl(SCP_GIPC_IN_REG) & (1<<scp_id)) > 0) {
/*avoid scp ipi send log print too much*/
if ((scp_ipi_id_record_count % PRINT_THRESHOLD == 0) ||
(scp_ipi_id_record_count % PRINT_THRESHOLD == 1)) {
pr_err("[SCP] %s:%s %d ap->scp busy,last time=%d\n",
__func__, core_ids[scp_id], id,
scp_ipi_owner[scp_id]);
scp_A_dump_regs();
}
if (scp_awake_unlock(scp_id) == -1)
pr_debug("[SCP] %s: ap->scp busy awake unlock -1\n",
__func__);
scp_ipi_desc[id].busy_count++;
mutex_unlock(&scp_ipi_mutex[scp_id]);
return SCP_IPI_BUSY;
}
/*get scp ipi send owner*/
scp_ipi_owner[scp_id] = id;
memcpy(scp_send_buff[scp_id], buf, len);
memcpy_to_scp((void *)scp_send_obj[scp_id]->share_buf,
scp_send_buff[scp_id], len);
scp_send_obj[scp_id]->len = len;
scp_send_obj[scp_id]->id = id;
/*
* read the value back to guarantee that scp's sram is ready.
*/
rb_id = readl(&(scp_send_obj[scp_id]->id));
if (rb_id != id) {
pr_debug("[SCP]ERR: write/read id failed, %d, %d\n", id, rb_id);
WARN_ON(1);
}
dsb(SY);
/*record timestamp*/
scp_ipi_desc[id].success_count++;
ap_to_scp_ipi_count++;
#if SCP_IPI_STAMP_SUPPORT
flag = scp_ipi_desc[id].success_count % SCP_IPI_ID_STAMP_SIZE;
if (flag < SCP_IPI_ID_STAMP_SIZE) {
scp_ipi_desc[id].send_flag[flag] =
scp_ipi_desc[id].success_count;
scp_ipi_desc[id].send_timestamp[flag] =
arch_counter_get_cntvct();
}
#endif
/* toggle the related bit to trigger an interrupt to scp */
writel((1<<scp_id), SCP_GIPC_IN_REG);
if (wait)
while ((readl(SCP_GIPC_IN_REG) & (1<<scp_id)) > 0)
;
if (scp_awake_unlock(scp_id) == -1)
pr_debug("[SCP] %s: awake unlock fail\n", __func__);
/* scp is interrupted, so unlock mutex to let other users in */
mutex_unlock(&scp_ipi_mutex[scp_id]);
return SCP_IPI_DONE;
}
EXPORT_SYMBOL_GPL(scp_ipi_send);
void scp_ipi_info_dump(enum ipi_id id)
{
pr_debug("%u\t%u\t%u\t%u\t%u\t%s\n\r",
id,
scp_ipi_desc[id].recv_count,
scp_ipi_desc[id].success_count,
scp_ipi_desc[id].busy_count,
scp_ipi_desc[id].error_count,
scp_ipi_desc[id].name);
#if SCP_IPI_STAMP_SUPPORT
/*time stamp*/
for (i = 0; i < SCP_IPI_ID_STAMP_SIZE; i++) {
if (scp_ipi_desc[id].recv_timestamp[i] != 0) {
pr_debug("[SCP]scp->ap recv count:%u, ap recv:%llu, handler fin:%llu\n",
scp_ipi_desc[id].recv_flag[i],
scp_ipi_desc[id].recv_timestamp[i],
scp_ipi_desc[id].handler_timestamp[i]);
}
}
for (i = 0; i < SCP_IPI_ID_STAMP_SIZE; i++) {
if (scp_ipi_desc[id].send_timestamp[i] != 0) {
pr_debug("ap->scp send count:%u send time:%llu\n",
scp_ipi_desc[id].send_flag[i],
scp_ipi_desc[id].send_timestamp[i]);
}
}
#endif
}
void scp_ipi_status_dump_id(enum ipi_id id)
{
#if SCP_IPI_STAMP_SUPPORT
/*time stamp*/
unsigned int i;
#endif
pr_debug("[SCP]id\trecv\tsuccess\tbusy\terror\tname\n\r");
scp_ipi_info_dump(id);
}
void scp_ipi_status_dump(void)
{
enum ipi_id id;
#if SCP_IPI_STAMP_SUPPORT
/*time stamp*/
unsigned int i;
#endif
pr_debug("[SCP]id\trecv\tsuccess\tbusy\terror\tname\n\r");
for (id = 0; id < SCP_NR_IPI; id++) {
if (scp_ipi_desc[id].recv_count > 0 ||
scp_ipi_desc[id].success_count > 0 ||
scp_ipi_desc[id].busy_count > 0 ||
scp_ipi_desc[id].error_count > 0)
scp_ipi_info_dump(id);
}
pr_debug("ap->scp total=%u scp->ap total=%u\n\r",
ap_to_scp_ipi_count,
scp_to_ap_ipi_count);
}
void mt_print_scp_ipi_id(void)
{
enum ipi_id id = scp_rcv_obj[0]->id;
unsigned char *buf = scp_rcv_obj[0]->share_buf;
uint16_t *ipi_count = (uint16_t *)scp_rcv_obj[0]->reserve;
switch (id) {
case IPI_SENSOR:
pr_info("[SCP] ipi(%d) id/type/action/event/reserve = %d/%d/%d/%d/%d\n",
*ipi_count, id, buf[0], buf[1], buf[2], buf[3]);
break;
default:
pr_info("[SCP] ipi id = %d\n", id);
break;
}
}
+102
View File
@@ -0,0 +1,102 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include "scp_ipi.h"
#include "scp_helper.h"
#include "scp_excep.h"
#include "scp_dvfs.h"
#include "scp_feature_define.h"
#if IS_ENABLED(CONFIG_MTK_AEE_FEATURE)
#include <mt-plat/aee.h>
#endif
/*
* handler for wdt irq for scp
* dump scp register
*/
static void scp_A_wdt_handler(void)
{
pr_debug("[SCP] CM4 A WDT exception\n");
scp_A_dump_regs();
}
/*
* 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)
{
unsigned int reg = readl(SCP_A_TO_HOST_REG);
#if SCP_RECOVERY_SUPPORT
/* if WDT and IPI triggered on the same time, ignore the IPI */
if (reg & SCP_IRQ_WDT) {
int retry;
unsigned long tmp;
scp_A_wdt_handler();
if (scp_set_reset_status() == RESET_STATUS_STOP) {
pr_debug("[SCP] CM4 WDT handler start to reset scp...\n");
scp_send_reset_wq(RESET_TYPE_WDT);
} else
pr_notice("scp_A_wdt_handler: scp resetting\n");
/* clr after SCP side INT trigger,
* or SCP may lost INT max wait 5000*40u = 200ms
*/
for (retry = SCP_AWAKE_TIMEOUT; retry > 0; retry--) {
tmp = readl(SCP_GPR_CM4_A_REBOOT);
if (tmp == CM4_A_READY_TO_REBOOT)
break;
udelay(40);
}
if (retry == 0)
pr_debug("[SCP] SCP_A wakeup timeout\n");
udelay(10);
writel(SCP_IRQ_WDT, SCP_A_TO_HOST_REG);
} else if (reg & SCP_IRQ_SCP2HOST) {
/* if WDT and IPI triggered on the same time, ignore the IPI */
scp_A_ipi_handler();
writel(SCP_IRQ_SCP2HOST, SCP_A_TO_HOST_REG);
}
#else
int reboot = 0;
if (reg & SCP_IRQ_WDT) {
scp_A_wdt_handler();
reboot = 1;
reg &= SCP_IRQ_WDT;
}
if (reg & SCP_IRQ_SCP2HOST) {
/* if WDT and IPI triggered on the same time, ignore the IPI */
if (!reboot)
scp_A_ipi_handler();
reg &= SCP_IRQ_SCP2HOST;
}
writel(reg, SCP_A_TO_HOST_REG);
if (reboot)
scp_aed_reset(EXCEP_RUNTIME, SCP_A_ID);
#endif // SCP_RECOVERY_SUPPORT
return IRQ_HANDLED;
}
/*
* scp irq initialize
*/
void scp_A_irq_init(void)
{
writel(SCP_IRQ_SCP2HOST, SCP_A_TO_HOST_REG); /* clear scp irq */
}
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/device.h> /* needed by device_* */
#include <linux/io.h>
#include <linux/mutex.h>
#include <linux/ratelimit.h>
#include <linux/sched_clock.h>
#include <linux/sysfs.h>
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/workqueue.h>
#include "scp_ipi.h"
#include "scp_helper.h"
#include "scp_excep.h"
#include "scp_feature_define.h"
#include "scp_l1c.h"
#if IS_ENABLED(CONFIG_MTK_AEE_FEATURE)
#include <mt-plat/aee.h>
#endif
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;
}
@@ -0,0 +1,847 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/miscdevice.h> /* needed by miscdevice* */
#include <linux/device.h> /* needed by device_* */
#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/vmalloc.h> /* needed by vmalloc */
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/delay.h>
#include <linux/io.h>
#include "scp_ipi.h"
#include "scp_helper.h"
#define DRAM_BUF_LEN (1 * 1024 * 1024)
#define SCP_TIMER_TIMEOUT (1 * HZ) /* 1 seconds*/
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
#define PLT_LOG_ENABLE 0x504C5402 /*magic*/
#define SCP_IPI_RETRY_TIMES (5000)
/* bit0 = 1, logger is on, else off*/
#define SCP_LOGGER_ON_BIT (1<<0)
/* bit1 = 1, logger_dram_use is on, else off*/
#define SCP_LOGGER_DRAM_ON_BIT (1<<1)
/* bit8 = 1, enable function (logger/logger dram use) */
#define SCP_LOGGER_ON_CTRL_BIT (1<<8)
/* bit8 = 0, disable function */
#define SCP_LOGGER_OFF_CTRL_BIT (0<<8)
/* let logger on */
#define SCP_LOGGER_ON (SCP_LOGGER_ON_CTRL_BIT | SCP_LOGGER_ON_BIT)
/* let logger off */
#define SCP_LOGGER_OFF (SCP_LOGGER_OFF_CTRL_BIT | SCP_LOGGER_ON_BIT)
/* let logger dram use on */
#define SCP_LOGGER_DRAM_ON (SCP_LOGGER_ON_CTRL_BIT | SCP_LOGGER_DRAM_ON_BIT)
/* let logger dram use off */
#define SCP_LOGGER_DRAM_OFF (SCP_LOGGER_OFF_CTRL_BIT | SCP_LOGGER_DRAM_ON_BIT)
#define SCP_LOGGER_UT (1)
struct log_ctrl_s {
unsigned int base;
unsigned int size;
unsigned int enable;
unsigned int info_ofs;
unsigned int buff_ofs;
unsigned int buff_size;
};
struct buffer_info_s {
unsigned int r_pos;
unsigned int w_pos;
};
struct SCP_LOG_INFO {
unsigned int scp_log_dram_addr;
unsigned int scp_log_buf_addr;
unsigned int scp_log_start_addr;
unsigned int scp_log_end_addr;
unsigned int scp_log_buf_maxlen;
};
static unsigned int scp_A_logger_inited;
static unsigned int scp_A_logger_wakeup_ap;
static struct log_ctrl_s *SCP_A_log_ctl;
static struct buffer_info_s *SCP_A_buf_info;
/*static struct timer_list scp_log_timer;*/
static DEFINE_MUTEX(scp_A_log_mutex);
static DEFINE_SPINLOCK(scp_A_log_buf_spinlock);
static struct scp_work_struct scp_logger_notify_work[SCP_CORE_TOTAL];
/*scp last log info*/
#define LAST_LOG_BUF_SIZE 4095
static struct SCP_LOG_INFO last_log_info;
static char *scp_A_last_log;
static wait_queue_head_t scp_A_logwait;
static DEFINE_MUTEX(scp_logger_mutex);
static char *scp_last_logger;
/*global value*/
unsigned int r_pos_debug;
unsigned int log_ctl_debug;
static struct mutex scp_logger_mutex;
/*
* get log from scp when received a buf full notify
* @param id: IPI id
* @param data: IPI data
* @param len: IPI data length
*/
static void scp_logger_wakeup_handler(int id, void *data, unsigned int len)
{
pr_debug("[SCP]wakeup by SCP logger\n");
}
/*
* get log from scp to last_log_buf
* @param len: data length
* @return: length of log
*/
static size_t scp_A_get_last_log(size_t b_len)
{
size_t ret = 0;
int scp_awake_flag;
unsigned int log_start_idx;
unsigned int log_end_idx;
unsigned int update_start_idx;
unsigned char *scp_last_log_buf =
(unsigned char *)(SCP_TCM + last_log_info.scp_log_buf_addr);
/*pr_debug("[SCP] %s\n", __func__);*/
if (!scp_A_logger_inited) {
pr_err("[SCP] %s(): logger has not been init\n", __func__);
return 0;
}
mutex_lock(&scp_logger_mutex);
/*SCP keep awake */
scp_awake_flag = 0;
if (scp_awake_lock(SCP_A_ID) == -1) {
scp_awake_flag = -1;
pr_debug("[SCP] %s: awake scp fail\n", __func__);
}
log_start_idx = readl((void __iomem *)(SCP_TCM +
last_log_info.scp_log_start_addr));
log_end_idx = readl((void __iomem *)(SCP_TCM +
last_log_info.scp_log_end_addr));
if (b_len > last_log_info.scp_log_buf_maxlen) {
pr_debug("[SCP] b_len %zu > scp_log_buf_maxlen %d\n",
b_len, last_log_info.scp_log_buf_maxlen);
b_len = last_log_info.scp_log_buf_maxlen;
}
/* handle sram error */
if (log_end_idx >= last_log_info.scp_log_buf_maxlen)
log_end_idx = 0;
if (log_end_idx >= b_len)
update_start_idx = log_end_idx - b_len;
else
update_start_idx = last_log_info.scp_log_buf_maxlen -
(b_len - log_end_idx) + 1;
/* read log from scp buffer */
ret = 0;
if (scp_A_last_log) {
while ((update_start_idx != log_end_idx) && ret < b_len) {
scp_A_last_log[ret] =
scp_last_log_buf[update_start_idx];
update_start_idx++;
ret++;
if (update_start_idx >=
last_log_info.scp_log_buf_maxlen)
update_start_idx = update_start_idx -
last_log_info.scp_log_buf_maxlen;
scp_A_last_log[ret] = '\0';
}
} else {
/* no buffer, just skip logs*/
update_start_idx = log_end_idx;
}
/*SCP release awake */
if (scp_awake_flag == 0) {
if (scp_awake_unlock(SCP_A_ID) == -1)
pr_debug("[SCP] %s: awake unlock fail\n", __func__);
}
mutex_unlock(&scp_logger_mutex);
return ret;
}
ssize_t scp_A_log_read(char __user *data, size_t len)
{
unsigned int w_pos, r_pos, datalen;
char *buf;
if (!scp_A_logger_inited)
return 0;
datalen = 0;
mutex_lock(&scp_A_log_mutex);
r_pos = SCP_A_buf_info->r_pos;
w_pos = SCP_A_buf_info->w_pos;
if (r_pos == w_pos)
goto error;
if (r_pos > w_pos)
datalen = DRAM_BUF_LEN - r_pos; /* not wrap */
else
datalen = w_pos - r_pos;
if (datalen > len)
datalen = len;
/*debug for logger pos fail*/
r_pos_debug = r_pos;
log_ctl_debug = SCP_A_log_ctl->buff_ofs;
if (r_pos >= DRAM_BUF_LEN) {
pr_err("[SCP] %s(): r_pos >= DRAM_BUF_LEN,%x,%x\n",
__func__, r_pos_debug, log_ctl_debug);
datalen = 0;
goto error;
}
buf = ((char *) SCP_A_log_ctl) + SCP_A_log_ctl->buff_ofs + r_pos;
len = datalen;
/*memory copy from log buf*/
if (copy_to_user(data, buf, len))
pr_debug("[SCP]copy to user buf failed..\n");
r_pos += datalen;
if (r_pos >= DRAM_BUF_LEN)
r_pos -= DRAM_BUF_LEN;
SCP_A_buf_info->r_pos = r_pos;
error:
mutex_unlock(&scp_A_log_mutex);
return datalen;
}
unsigned int scp_A_log_poll(void)
{
if (!scp_A_logger_inited)
return 0;
if (SCP_A_buf_info->r_pos != SCP_A_buf_info->w_pos)
return POLLIN | POLLRDNORM;
/*scp_log_timer_add();*/
return 0;
}
static ssize_t scp_A_log_if_read(struct file *file,
char __user *data, size_t len, loff_t *ppos)
{
ssize_t ret = 0;
/*if (access_ok(VERIFY_WRITE, data, len))*/
ret = scp_A_log_read(data, len);
return ret;
}
static int scp_A_log_if_open(struct inode *inode, struct file *file)
{
/*pr_debug("[SCP A] scp_A_log_if_open\n");*/
return nonseekable_open(inode, file);
}
static unsigned int scp_A_log_if_poll(struct file *file, poll_table *wait)
{
unsigned int ret = 0;
/* pr_debug("[SCP A] scp_A_log_if_poll\n"); */
if (!scp_A_logger_inited)
return 0;
if (!(file->f_mode & FMODE_READ))
return ret;
/*poll_wait(file, &scp_A_logwait, wait);*/
ret = scp_A_log_poll();
return ret;
}
/*
* ipi send to enable scp logger flag
*/
static unsigned int scp_A_log_enable_set(unsigned int enable)
{
int ret;
unsigned int retrytimes;
if (scp_A_logger_inited) {
/*
*send ipi to invoke scp logger
*/
ret = 0;
enable = (enable) ? SCP_LOGGER_ON : SCP_LOGGER_OFF;
retrytimes = SCP_IPI_RETRY_TIMES;
do {
ret = scp_ipi_send(IPI_LOGGER_ENABLE,
&enable, sizeof(enable), 0, SCP_A_ID);
if (ret == SCP_IPI_DONE)
break;
retrytimes--;
udelay(100);
} while (retrytimes > 0);
/*
*disable/enable logger flag
*/
if ((ret == SCP_IPI_DONE) && (enable == 1))
SCP_A_log_ctl->enable = 1;
else if ((ret == SCP_IPI_DONE) && (enable == 0))
SCP_A_log_ctl->enable = 0;
if (ret != SCP_IPI_DONE) {
pr_err("[SCP] %s: fail ret=%d\n", __func__, ret);
goto error;
}
}
error:
return 0;
}
/*
*ipi send enable scp logger wake up flag
*/
static unsigned int scp_A_log_wakeup_set(unsigned int enable)
{
int ret;
unsigned int retrytimes;
if (scp_A_logger_inited) {
/*
*send ipi to invoke scp logger
*/
ret = 0;
enable = (enable) ? 1 : 0;
retrytimes = SCP_IPI_RETRY_TIMES;
do {
ret = scp_ipi_send(IPI_LOGGER_WAKEUP, &enable,
sizeof(enable), 0, SCP_A_ID);
if (ret == SCP_IPI_DONE)
break;
retrytimes--;
udelay(100);
} while (retrytimes > 0);
/*
*disable/enable logger flag
*/
if ((ret == SCP_IPI_DONE) && (enable == 1))
scp_A_logger_wakeup_ap = 1;
else if ((ret == SCP_IPI_DONE) && (enable == 0))
scp_A_logger_wakeup_ap = 0;
if (ret != SCP_IPI_DONE) {
pr_err("[SCP] %s: fail ret=%d\n", __func__, ret);
goto error;
}
}
error:
return 0;
}
/*
* create device sysfs, scp logger status
*/
static ssize_t scp_mobile_log_show(struct device *kobj,
struct device_attribute *attr, char *buf)
{
unsigned int stat;
stat = (scp_A_logger_inited && SCP_A_log_ctl->enable) ? 1 : 0;
return scnprintf(buf, PAGE_SIZE, "[SCP A] mobile log is %s\n",
(stat == 0x1) ? "enabled" : "disabled");
}
static ssize_t scp_mobile_log_store(struct device *kobj,
struct device_attribute *attr, const char *buf, size_t n)
{
unsigned int enable;
if (kstrtouint(buf, 0, &enable) != 0)
return -EINVAL;
mutex_lock(&scp_A_log_mutex);
scp_A_log_enable_set(enable);
mutex_unlock(&scp_A_log_mutex);
return n;
}
DEVICE_ATTR_RW(scp_mobile_log);
/*
* create device sysfs, scp ADB cmd to set SCP wakeup AP flag
*/
static ssize_t scp_A_logger_wakeup_AP_show(struct device *kobj,
struct device_attribute *attr, char *buf)
{
unsigned int stat;
stat = (scp_A_logger_inited && scp_A_logger_wakeup_ap) ? 1 : 0;
return scnprintf(buf, PAGE_SIZE, "[SCP A] logger wakeup AP is %s\n",
(stat == 0x1) ? "enabled" : "disabled");
}
static ssize_t scp_A_logger_wakeup_AP_store(struct device *kobj,
struct device_attribute *attr, const char *buf, size_t n)
{
unsigned int enable;
if (kstrtouint(buf, 0, &enable) != 0)
return -EINVAL;
mutex_lock(&scp_A_log_mutex);
scp_A_log_wakeup_set(enable);
mutex_unlock(&scp_A_log_mutex);
return n;
}
DEVICE_ATTR_RW(scp_A_logger_wakeup_AP);
/*
* create device sysfs, scp last log show
*/
static ssize_t scp_A_get_last_log_show(struct device *kobj,
struct device_attribute *attr, char *buf)
{
scp_A_get_last_log(last_log_info.scp_log_buf_maxlen);
return scnprintf(buf, PAGE_SIZE, "scp_log_buf_maxlen=%u, log=%s\n",
last_log_info.scp_log_buf_maxlen,
scp_A_last_log ? scp_A_last_log : "");
}
DEVICE_ATTR_RO(scp_A_get_last_log);
/*
* logger UT test
*
*/
#if SCP_LOGGER_UT
static ssize_t scp_A_mobile_log_UT_show(struct device *kobj,
struct device_attribute *attr, char *buf)
{
unsigned int w_pos, r_pos, datalen;
char *logger_buf;
size_t len = 1024;
if (!scp_A_logger_inited)
return 0;
datalen = 0;
mutex_lock(&scp_A_log_mutex);
r_pos = SCP_A_buf_info->r_pos;
w_pos = SCP_A_buf_info->w_pos;
if (r_pos == w_pos)
goto error;
if (r_pos > w_pos)
datalen = DRAM_BUF_LEN - r_pos; /* not wrap */
else
datalen = w_pos - r_pos;
if (datalen > len)
datalen = len;
logger_buf = ((char *) SCP_A_log_ctl) +
SCP_A_log_ctl->buff_ofs + r_pos;
len = datalen;
/*memory copy from log buf*/
memcpy_fromio(buf, logger_buf, len);
r_pos += datalen;
if (r_pos >= DRAM_BUF_LEN)
r_pos -= DRAM_BUF_LEN;
SCP_A_buf_info->r_pos = r_pos;
error:
mutex_unlock(&scp_A_log_mutex);
return len;
}
static ssize_t scp_A_mobile_log_UT_store(struct device *kobj,
struct device_attribute *attr, const char *buf, size_t n)
{
unsigned int enable;
if (kstrtouint(buf, 0, &enable) != 0)
return -EINVAL;
mutex_lock(&scp_A_log_mutex);
scp_A_log_enable_set(enable);
mutex_unlock(&scp_A_log_mutex);
return n;
}
DEVICE_ATTR_RW(scp_A_mobile_log_UT);
#endif
/*
* IPI for logger init
* @param id: IPI id
* @param data: IPI data
* @param len: IPI data length
*/
static void scp_A_logger_init_handler(int id, void *data, unsigned int len)
{
unsigned long flags;
struct SCP_LOG_INFO *log_info = (struct SCP_LOG_INFO *)data;
pr_debug("[SCP]scp_get_reserve_mem_phys=%llx\n",
(uint64_t)scp_get_reserve_mem_phys(SCP_A_LOGGER_MEM_ID));
spin_lock_irqsave(&scp_A_log_buf_spinlock, flags);
/* sync scp last log information*/
last_log_info.scp_log_dram_addr = log_info->scp_log_dram_addr;
last_log_info.scp_log_buf_addr = log_info->scp_log_buf_addr;
last_log_info.scp_log_start_addr = log_info->scp_log_start_addr;
last_log_info.scp_log_end_addr = log_info->scp_log_end_addr;
last_log_info.scp_log_buf_maxlen = log_info->scp_log_buf_maxlen;
/* setting dram ctrl config to scp*/
/* scp side get wakelock, AP to write info to scp sram*/
writel(scp_get_reserve_mem_phys(SCP_A_LOGGER_MEM_ID),
(SCP_TCM + last_log_info.scp_log_dram_addr));
/* set init flag here*/
scp_A_logger_inited = 1;
spin_unlock_irqrestore(&scp_A_log_buf_spinlock, flags);
/*set a wq to enable scp logger*/
scp_logger_notify_work[SCP_A_ID].id = SCP_A_ID;
#if SCP_LOGGER_ENABLE
scp_schedule_logger_work(&scp_logger_notify_work[SCP_A_ID]);
#endif
}
/*
* callback function for work struct
* notify apps to start their tasks or generate an exception according to flag
* NOTE: this function may be blocked and should not be called in interrupt
* context
* @param ws: work struct
*/
static void scp_logger_notify_ws(struct work_struct *ws)
{
struct scp_work_struct *sws =
container_of(ws, struct scp_work_struct, work);
unsigned int magic = 0x5A5A5A5A;
unsigned int retrytimes;
unsigned int scp_core_id = sws->id;
enum scp_ipi_status ret;
enum ipi_id scp_ipi_id;
scp_ipi_id = IPI_LOGGER_INIT_A;
pr_notice("[SCP] %s: id=%u\n", __func__, scp_ipi_id);
/*
*send ipi to invoke scp logger
*/
retrytimes = SCP_IPI_RETRY_TIMES;
do {
ret = scp_ipi_send(scp_ipi_id,
&magic, sizeof(magic), 0, scp_core_id);
if ((retrytimes % 500) == 0)
pr_debug("[SCP] %s: ipi ret=%d\n", __func__, ret);
if ((ret == SCP_IPI_DONE) || (ret == SCP_IPI_ERROR))
break;
retrytimes--;
udelay(2000);
} while (retrytimes > 0);
/*enable logger flag*/
if (ret == SCP_IPI_DONE)
SCP_A_log_ctl->enable = 1;
else {
/* initialization of scp logger fails, but still raise
* the flag to dump scp's previous log for debugging.
*/
SCP_A_log_ctl->enable = 1;
pr_err("[SCP]logger initial fail, ipi ret=%d\n", ret);
}
}
/******************************************************************************
* init scp logger dram ctrl structure
* @return: -1: fail, otherwise: end of buffer
*****************************************************************************/
int scp_logger_init(phys_addr_t start, phys_addr_t limit)
{
int last_ofs;
/*init wait queue*/
init_waitqueue_head(&scp_A_logwait);
scp_A_logger_wakeup_ap = 0;
mutex_init(&scp_logger_mutex);
/*init work queue*/
INIT_WORK(&scp_logger_notify_work[SCP_A_ID].work, scp_logger_notify_ws);
/*init dram ctrl table*/
last_ofs = 0;
#ifdef CONFIG_ARM64
SCP_A_log_ctl = (struct log_ctrl_s *) start;
#else
/* plz fix origial ptr to phys_addr flow */
SCP_A_log_ctl = (struct log_ctrl_s *) (u32) start;
#endif
SCP_A_log_ctl->base = PLT_LOG_ENABLE; /* magic */
SCP_A_log_ctl->enable = 0;
SCP_A_log_ctl->size = sizeof(*SCP_A_log_ctl);
last_ofs += SCP_A_log_ctl->size;
SCP_A_log_ctl->info_ofs = last_ofs;
last_ofs += sizeof(*SCP_A_buf_info);
last_ofs = ROUNDUP(last_ofs, 4);
SCP_A_log_ctl->buff_ofs = last_ofs;
SCP_A_log_ctl->buff_size = DRAM_BUF_LEN;
SCP_A_buf_info = (struct buffer_info_s *)
(((unsigned char *) SCP_A_log_ctl) + SCP_A_log_ctl->info_ofs);
SCP_A_buf_info->r_pos = 0;
SCP_A_buf_info->w_pos = 0;
last_ofs += SCP_A_log_ctl->buff_size;
if (last_ofs >= limit) {
pr_err("[SCP]:%s() initial fail, last_ofs=%u, limit=%u\n",
__func__, last_ofs, (unsigned int) limit);
goto error;
}
/* init last log buffer*/
last_log_info.scp_log_buf_maxlen = LAST_LOG_BUF_SIZE;
if (!scp_A_last_log) {
/* Allocate one more byte for the NULL character. */
scp_A_last_log = vmalloc(last_log_info.scp_log_buf_maxlen + 1);
if (scp_A_last_log == NULL)
goto error;
}
/* register logger ini IPI */
scp_ipi_registration(IPI_LOGGER_INIT_A, scp_A_logger_init_handler,
"loggerA");
/* register log wakeup IPI */
scp_ipi_registration(IPI_LOGGER_WAKEUP, scp_logger_wakeup_handler,
"log wakeup");
scp_A_logger_inited = 1;
return last_ofs;
error:
scp_A_logger_inited = 0;
SCP_A_log_ctl = NULL;
SCP_A_buf_info = NULL;
return -1;
}
void scp_logger_uninit(void)
{
char *tmp = scp_A_last_log;
scp_A_logger_inited = 0;
scp_A_last_log = NULL;
vfree(tmp);
}
const struct file_operations scp_A_log_file_ops = {
.owner = THIS_MODULE,
.read = scp_A_log_if_read,
.open = scp_A_log_if_open,
.poll = scp_A_log_if_poll,
};
/*
* move scp last log from sram to dram
* NOTE: this function may be blocked
* @param scp_core_id: fill scp id to get last log
*/
void scp_crash_log_move_to_buf(enum scp_core_id scp_id)
{
int pos;
unsigned int ret;
unsigned int length;
unsigned int log_start_idx; /* SCP log start pointer */
unsigned int log_end_idx; /* SCP log end pointer */
unsigned int w_pos; /* buf write pointer */
char *pre_scp_logger_buf;
char *dram_logger_buf; /* dram buffer */
char *crash_message = "****SCP EE LOG DUMP****\n";
unsigned char *scp_logger_buf = (unsigned char *)(SCP_TCM +
last_log_info.scp_log_buf_addr);
if (!scp_A_logger_inited && scp_id == SCP_A_ID) {
pr_err("[SCP] %s(): logger has not been init\n", __func__);
return;
}
/* SCP keep awake */
mutex_lock(&scp_logger_mutex);
if (scp_awake_lock(scp_id) == -1) {
pr_debug("[SCP] %s: awake scp fail\n", __func__);
mutex_unlock(&scp_logger_mutex);
return;
}
log_start_idx = readl((void __iomem *)(SCP_TCM +
last_log_info.scp_log_start_addr));
log_end_idx = readl((void __iomem *)(SCP_TCM +
last_log_info.scp_log_end_addr));
if (log_end_idx >= log_start_idx)
length = log_end_idx - log_start_idx;
else
length = last_log_info.scp_log_buf_maxlen -
(log_start_idx - log_end_idx);
if (length >= last_log_info.scp_log_buf_maxlen) {
pr_err("[SCP] %s: length >= max\n", __func__);
length = last_log_info.scp_log_buf_maxlen;
}
pre_scp_logger_buf = scp_last_logger;
scp_last_logger = vmalloc(length + strlen(crash_message) + 1);
/* read log from scp buffer */
ret = 0;
if (scp_last_logger) {
ret += snprintf(scp_last_logger, strlen(crash_message),
crash_message);
ret--;
while ((log_start_idx != log_end_idx) &&
ret <= (length + strlen(crash_message))) {
scp_last_logger[ret] = scp_logger_buf[log_start_idx];
log_start_idx++;
ret++;
if (log_start_idx >= last_log_info.scp_log_buf_maxlen)
log_start_idx = log_start_idx -
last_log_info.scp_log_buf_maxlen;
scp_last_logger[ret] = '\0';
}
} else {
/* no buffer, just skip logs */
log_start_idx = log_end_idx;
}
if (ret != 0) {
/* get buffer w pos */
w_pos = SCP_A_buf_info->w_pos;
if (w_pos >= DRAM_BUF_LEN) {
pr_err("[SCP] %s(): w_pos >= DRAM_BUF_LEN, w_pos=%u",
__func__, w_pos);
return;
}
/* copy to dram buffer */
dram_logger_buf = ((char *) SCP_A_log_ctl) +
SCP_A_log_ctl->buff_ofs + w_pos;
/* memory copy from log buf */
pos = 0;
while ((pos != ret) && pos <= ret) {
*dram_logger_buf = scp_last_logger[pos];
pos++;
w_pos++;
dram_logger_buf++;
if (w_pos >= DRAM_BUF_LEN) {
/* warp */
pr_err("[SCP] %s: dram warp\n", __func__);
w_pos = 0;
dram_logger_buf = ((char *) SCP_A_log_ctl) +
SCP_A_log_ctl->buff_ofs;
}
}
/* update write pointer */
SCP_A_buf_info->w_pos = w_pos;
}
/* SCP release awake */
if (scp_awake_unlock(scp_id) == -1)
pr_debug("[SCP] %s: awake unlock fail\n", __func__);
mutex_unlock(&scp_logger_mutex);
vfree(pre_scp_logger_buf);
}
/*
* get log from scp and optionally save it
* NOTE: this function may be blocked
* @param scp_core_id: fill scp id to get last log
*/
void scp_get_log(enum scp_core_id scp_id)
{
pr_debug("[SCP] %s\n", __func__);
#if SCP_LOGGER_ENABLE
scp_A_get_last_log(SCP_AED_STR_LEN - 200);
/*move last log to dram*/
scp_crash_log_move_to_buf(scp_id);
#endif
}
/*
* return scp last log
*/
char *scp_get_last_log(enum scp_core_id id)
{
char *last_log;
last_log = scp_A_last_log;
return last_log;
}
/*
* set scp_A_logger_inited
*/
void scp_logger_init_set(unsigned int value)
{
/*scp_A_logger_inited
* 0: logger not init
* 1: logger inited
*/
scp_A_logger_inited = value;
}
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/device.h> /* needed by device_* */
#include "scp_ipi.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;
switch (type) {
case SCPCTL_TYPE_TMON:
ret = scp_ipi_send(IPI_SCPCTL, &cmd, sizeof(cmd), 0, SCP_A_ID);
if (ret != SCP_IPI_DONE)
goto _err;
break;
default:
return -EINVAL;
}
return n;
_err:
pr_notice("%s failed, %d\n", prompt, ret);
return -EIO;
}
DEVICE_ATTR_WO(scpctl);
+16
View File
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_H
#define __SCP_H
#if IS_ENABLED(CONFIG_MTK_TINYSYS_SCP_CM4_SUPPORT)
#include "scp_cm4.h"
#elif IS_ENABLED(CONFIG_MTK_TINYSYS_SCP_RV_SUPPORT)
#include "scp_rv.h"
#endif
#endif
+156
View File
@@ -0,0 +1,156 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __SCP_CM4_H
#define __SCP_CM4_H
/* scp Core ID definition*/
enum scp_core_id {
SCP_A_ID = 0,
SCP_CORE_TOTAL = 1,
};
/* scp ipi ID definition
* need to sync with SCP-side
*/
enum ipi_id {
IPI_WDT = 0,
IPI_TEST1,
IPI_LOGGER_ENABLE,
IPI_LOGGER_WAKEUP,
IPI_LOGGER_INIT_A,
IPI_VOW, /* 5 */
IPI_AUDIO,
IPI_DVT_TEST,
IPI_SENSOR,
IPI_TIME_SYNC,
IPI_SHF, /* 10 */
IPI_CONSYS,
IPI_SCP_A_READY,
IPI_APCCCI,
IPI_SCP_A_RAM_DUMP,
IPI_DVFS_DEBUG, /* 15 */
IPI_DVFS_FIX_OPP_SET,
IPI_DVFS_FIX_OPP_EN,
IPI_DVFS_LIMIT_OPP_SET,
IPI_DVFS_LIMIT_OPP_EN,
IPI_DVFS_DISABLE, /* 20 */
IPI_DVFS_SLEEP,
IPI_PMICW_MODE_DEBUG,
IPI_DVFS_SET_FREQ,
IPI_CHRE,
IPI_CHREX, /* 25 */
IPI_SCP_PLL_CTRL,
IPI_DO_AP_MSG,
IPI_DO_SCP_MSG,
IPI_MET_SCP,
IPI_SCP_TIMER, /* 30 */
IPI_SCP_ERROR_INFO,
IPI_SCPCTL,
IPI_SCP_LOG_FILTER = 33,
IPI_SENSOR_INIT_START = 34,
SCP_NR_IPI,
};
enum scp_ipi_status {
SCP_IPI_ERROR = -1,
SCP_IPI_DONE,
SCP_IPI_BUSY,
};
/* scp notify event */
enum SCP_NOTIFY_EVENT {
SCP_EVENT_READY = 0,
SCP_EVENT_STOP,
};
/* 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 reserve memory ID definition*/
enum scp_reserve_mem_id_t {
VOW_MEM_ID,
SENS_MEM_ID,
MP3_MEM_ID,
FLP_MEM_ID,
SCP_A_LOGGER_MEM_ID,
AUDIO_IPI_MEM_ID,
SPK_PROTECT_MEM_ID,
SPK_PROTECT_DUMP_MEM_ID,
VOW_BARGEIN_MEM_ID,
SCP_DRV_PARAMS_MEM_ID,
ULTRA_MEM_ID,
NUMS_MEM_ID,
};
/* scp feature ID list */
enum feature_id {
VOW_FEATURE_ID,
OPEN_DSP_FEATURE_ID,
SENS_FEATURE_ID,
MP3_FEATURE_ID,
FLP_FEATURE_ID,
RTOS_FEATURE_ID,
SPEAKER_PROTECT_FEATURE_ID,
VCORE_TEST_FEATURE_ID,
VOW_BARGEIN_FEATURE_ID,
VOW_DUMP_FEATURE_ID,
VOW_VENDOR_M_FEATURE_ID,
VOW_VENDOR_A_FEATURE_ID,
VOW_VENDOR_G_FEATURE_ID,
ULTRA_FEATURE_ID,
NUM_FEATURE_ID,
};
/* An API to get scp status */
extern unsigned int is_scp_ready(enum scp_core_id scp_id);
/* APIs to register new IPI handlers */
extern enum scp_ipi_status scp_ipi_registration(enum ipi_id id,
void (*ipi_handler)(int id, void *data, unsigned int len),
const char *name);
extern enum scp_ipi_status scp_ipi_unregistration(enum ipi_id id);
/* A common API to send message to SCP */
extern 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);
/* APIs to lock scp and make scp awaken */
extern int scp_awake_lock(enum scp_core_id scp_id);
extern int scp_awake_unlock(enum scp_core_id scp_id);
/* APIs for register notification */
extern void scp_A_register_notify(struct notifier_block *nb);
extern void scp_A_unregister_notify(struct notifier_block *nb);
/* APIs for hardware semaphore */
extern int get_scp_semaphore(int flag);
extern int release_scp_semaphore(int flag);
extern int scp_get_semaphore_3way(int flag);
extern int scp_release_semaphore_3way(int flag);
/* APIs for reserved memory */
extern phys_addr_t scp_get_reserve_mem_phys(enum scp_reserve_mem_id_t id);
extern phys_addr_t scp_get_reserve_mem_virt(enum scp_reserve_mem_id_t id);
extern phys_addr_t scp_get_reserve_mem_size(enum scp_reserve_mem_id_t id);
/* APIs for registering function of features */
extern void scp_register_feature(enum feature_id id);
extern void scp_deregister_feature(enum feature_id id);
#endif
+205
View File
@@ -0,0 +1,205 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __SCP_RV_H__
#define __SCP_RV_H__
#include <linux/soc/mediatek/mtk_tinysys_ipi.h>
#define SCP_MBOX_TOTAL 5
#define PIN_OUT_SIZE_AUDIO_VOW_1 9
#define PIN_IN_SIZE_AUDIO_VOW_ACK_1 2
#define PIN_IN_SIZE_AUDIO_VOW_1 26
#define PIN_IN_SIZE_AUDIO_ACCDET_1 1
#define PIN_OUT_SIZE_APCCCI_0 2
#define PIN_OUT_SIZE_DVFS_SET_FREQ_0 1
#define PIN_OUT_C_SIZE_SLEEP_0 2
#define PIN_OUT_R_SIZE_SLEEP_0 1
#define PIN_OUT_SIZE_TEST_0 1
#define PIN_OUT_SIZE_AUDIO_ULTRA_SND_0 9
#define PIN_IN_SIZE_APCCCI_0 2
#define PIN_IN_SIZE_SCP_ERROR_INFO_0 10
#define PIN_IN_SIZE_SCP_READY_0 1
#define PIN_IN_SIZE_SCP_RAM_DUMP_0 2
#define PIN_IN_SIZE_AUDIO_ULTRA_SND_0 5
#define PIN_IN_SIZE_AUDIO_ULTRA_SND_ACK_0 2
#define PIN_OUT_SIZE_DVFS_SET_FREQ_1 1
#define PIN_OUT_C_SIZE_SLEEP_1 2
#define PIN_OUT_R_SIZE_SLEEP_1 1
#define PIN_OUT_SIZE_TEST_1 1
#define PIN_OUT_SIZE_LOGGER_CTRL 6
#define PIN_OUT_SIZE_SCPCTL_1 2
#define PIN_IN_SIZE_SCP_ERROR_INFO_1 10
#define PIN_IN_SIZE_LOGGER_CTRL 6
#define PIN_IN_SIZE_SCP_READY_1 1
#define PIN_IN_SIZE_SCP_RAM_DUMP_1 2
#define PIN_OUT_SIZE_SCP_MPOOL 4
#define PIN_IN_SIZE_SCP_MPOOL 4
#define PIN_OUT_SIZE_SENSOR_CTRL 16
#define PIN_IN_SIZE_SENSOR_CTRL 2
#define PIN_OUT_SIZE_SENSOR_NOTIFY 7
#define PIN_IN_SIZE_SENSOR_NOTIFY 7
#define PIN_OUT_SIZE_SCP_CONNSYS 3
#define PIN_OUT_SIZE_SCP_HWVOTER_DEBUG 2
/* scp Core ID definition */
enum scp_core_id {
SCP_A_ID = 0,
SCP_CORE_TOTAL = 1,
};
enum {
/* for mbox mapping, please refer to tinysys side */
IPI_OUT_AUDIO_VOW_1 = 0,
IPI_IN_AUDIO_VOW_ACK_1 = 1,
IPI_IN_AUDIO_VOW_1 = 2,
IPI_OUT_APCCCI_0 = 3,
IPI_OUT_DVFS_SET_FREQ_0 = 4,
IPI_OUT_C_SLEEP_0 = 5,
IPI_OUT_TEST_0 = 6,
IPI_IN_APCCCI_0 = 7,
IPI_IN_SCP_ERROR_INFO_0 = 8,
IPI_IN_SCP_READY_0 = 9,
IPI_IN_SCP_RAM_DUMP_0 = 10,
IPI_OUT_SCP_MPOOL_0 = 11,
IPI_IN_SCP_MPOOL_0 = 12,
IPI_OUT_AUDIO_ULTRA_SND_1 = 13,
IPI_OUT_DVFS_SET_FREQ_1 = 14,
IPI_OUT_C_SLEEP_1 = 15,
IPI_OUT_TEST_1 = 16,
IPI_OUT_LOGGER_CTRL = 17,
IPI_OUT_SCPCTL_1 = 18,
IPI_IN_AUDIO_ULTRA_SND_1 = 19,
IPI_IN_SCP_ERROR_INFO_1 = 20,
IPI_IN_LOGGER_CTRL = 21,
IPI_IN_SCP_READY_1 = 22,
IPI_IN_SCP_RAM_DUMP_1 = 23,
IPI_OUT_SCP_MPOOL_1 = 24,
IPI_IN_SCP_MPOOL_1 = 25,
IPI_OUT_AUDIO_ULTRA_SND_0 = 26,
IPI_IN_AUDIO_ULTRA_SND_ACK_0 = 27,
IPI_IN_AUDIO_ULTRA_SND_0 = 28,
IPI_OUT_SENSOR_CTRL = 29,
IPI_IN_SENSOR_CTRL = 30,
IPI_OUT_SENSOR_NOTIFY = 31,
IPI_IN_SENSOR_NOTIFY = 32,
IPI_OUT_SCP_CONNSYS = 33,
IPI_IN_SCP_CONNSYS = 34,
IPI_OUT_SCP_HWVOTER_DEBUG = 35,
IPI_IN_AUDIO_ACCDET_1 = 36,
IPI_OUT_SCP_AOD = 37,
IPI_IN_SCP_AOD = 38,
SCP_IPI_COUNT
};
enum scp_ipi_status {
SCP_IPI_NOT_READY = -2,
SCP_IPI_ERROR = -1,
SCP_IPI_DONE,
SCP_IPI_BUSY,
};
/* scp notify event */
enum SCP_NOTIFY_EVENT {
SCP_EVENT_READY = 0,
SCP_EVENT_STOP,
SCP_EVENT_NOTIFYING,
};
/* the order of ipi_id should be consistent with IPI_LEGACY_GROUP */
enum ipi_id {
IPI_MPOOL,
IPI_CHRE,
IPI_CHREX,
IPI_SENSOR,
IPI_SENSOR_INIT_START,
SCP_NR_IPI,
};
/* scp reserve memory ID definition*/
enum scp_reserve_mem_id_t {
SCP_A_SECDUMP_MEM_ID = 0, /* please keep SCP_A_SECDUMP_MEM_ID=0 */
VOW_MEM_ID,
SENS_MEM_ID,
SCP_A_LOGGER_MEM_ID,
AUDIO_IPI_MEM_ID,
VOW_BARGEIN_MEM_ID,
SCP_DRV_PARAMS_MEM_ID,
ULTRA_MEM_ID,
SENS_SUPER_MEM_ID,
SENS_LIST_MEM_ID,
SENS_DEBUG_MEM_ID,
SENS_CUSTOM_W_MEM_ID,
SENS_CUSTOM_R_MEM_ID,
NUMS_MEM_ID,
};
/* scp feature ID list */
enum feature_id {
VOW_FEATURE_ID = 0,
SENS_FEATURE_ID = 1,
FLP_FEATURE_ID = 2,
RTOS_FEATURE_ID = 3,
SPEAKER_PROTECT_FEATURE_ID = 4,
VCORE_TEST_FEATURE_ID = 5,
VOW_BARGEIN_FEATURE_ID = 6,
VOW_DUMP_FEATURE_ID = 7,
VOW_VENDOR_M_FEATURE_ID = 8,
VOW_VENDOR_A_FEATURE_ID = 9,
VOW_VENDOR_G_FEATURE_ID = 10,
VOW_DUAL_MIC_FEATURE_ID = 11,
VOW_DUAL_MIC_BARGE_IN_FEATURE_ID = 12,
ULTRA_FEATURE_ID = 13,
NUM_FEATURE_ID = 14,
};
extern struct mtk_mbox_device scp_mboxdev;
extern struct mtk_ipi_device scp_ipidev;
extern struct mtk_mbox_pin_send *scp_mbox_pin_send;
extern struct mtk_mbox_pin_recv *scp_mbox_pin_recv;
/* An API to get scp status */
extern unsigned int is_scp_ready(enum scp_core_id scp_id);
/* APIs to register new IPI handlers */
extern enum scp_ipi_status scp_ipi_registration(enum ipi_id id,
void (*ipi_handler)(int id, void *data, unsigned int len),
const char *name);
extern enum scp_ipi_status scp_ipi_unregistration(enum ipi_id id);
/* A common API to send message to SCP */
extern 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);
/* APIs to lock scp and make scp awaken */
extern int scp_awake_lock(void *_scp_id);
extern int scp_awake_unlock(void *_scp_id);
/* APIs for register notification */
extern void scp_A_register_notify(struct notifier_block *nb);
extern void scp_A_unregister_notify(struct notifier_block *nb);
/* APIs for hardware semaphore */
extern int get_scp_semaphore(int flag);
extern int release_scp_semaphore(int flag);
extern int scp_get_semaphore_3way(int flag);
extern int scp_release_semaphore_3way(int flag);
/* APIs for reserved memory */
extern phys_addr_t scp_get_reserve_mem_phys(enum scp_reserve_mem_id_t id);
extern phys_addr_t scp_get_reserve_mem_virt(enum scp_reserve_mem_id_t id);
extern phys_addr_t scp_get_reserve_mem_size(enum scp_reserve_mem_id_t id);
/* APIs for registering function of features */
extern void scp_register_feature(enum feature_id id);
extern void scp_deregister_feature(enum feature_id id);
/* APIs for reset scp */
extern void scp_wdt_reset(int cpu_id);
#endif
+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);
}
}
}
}
}