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

+46
View File
@@ -0,0 +1,46 @@
config MTK_AEE_FEATURE
tristate "Enable Android Exception Enhancement"
select FIQ_GLUE if !TRUSTONIC_TEE_SUPPORT && !ARM_PSCI && !TRUSTY
select TRACER_SNAPSHOT
select FTRACE
help
AEE (Android Exception Engine) that designed by Mediatek is an
exception catching and debugging information generation mechanism.
It can collect and dump information to filesystem
(/sdcard/mtklog/aee_exp) when exceptions occur(E.g. kernel
panic/android system server crash and ..)
config MTK_AEE_AED
tristate "Enable AEE Kernel Exception Report Daemon"
depends on MTK_AEE_FEATURE
help
MTK_AEE_AED is the kernel config of aed, which is the base support for
aee features. Such as:
aed debug: some test case for aee driver itself
aed main: aed main function and ioctl for user space aee
monitor hang: detect hang feature...
config MTK_AEE_IPANIC
tristate "Enable AEE Kernel Panic Dump"
depends on MTK_AEE_FEATURE
help
MTK_AEE_IPANIC is the kernel config of ipanic feature designed by
MTK, which is the enhancement of kernel defaut panic flow, and
combined with aee. It will do some hook function and get some
kernel panic information for debug.
config MTK_AEE_UT
tristate "control AED debug file"
help
MTK_AEE_UT is the kernel config of aed-debug.c
aed-debug.c is AEE UT test case file, just for generate some vendor
exception to test AEE dump flow, include in KE, HWT, HW_reboot, EE,
and kernelAPI exception
config MTK_AEE_HANGDET
tristate "Enable AEE Kernel Hang Detector"
depends on MTK_AEE_FEATURE
help
MTK_AEE_HANGDET is the kernel config of hang detector feature
designed by MTK, which is the mechanism to check if each cpu
is alived. When cpu hang is detected, raise excetpion.
+40
View File
@@ -0,0 +1,40 @@
#
# 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.
#
ifeq ($(CONFIG_MTK_PLATFORM), "mt6761")
MTK_PLATFORM := mt6765
else ifneq ($(CONFIG_MTK_PLATFORM), "")
MTK_PLATFORM := $(subst ",,$(CONFIG_MTK_PLATFORM))
else
MTK_PLATFORM := $(subst ",,$(CONFIG_MTK_DISP_PLATFORM))
endif
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/$(MTK_PLATFORM)
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/video/$(MTK_PLATFORM)/videox/
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/aee/mrdump
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/aee/aed
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/aee
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/mmp/
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/log_store/
ifdef CONFIG_MTK_ION
subdir-ccflags-y += -I$(srctree)/drivers/staging/android/ion
endif
ifdef CONFIG_DRM_MEDIATEK
subdir-ccflags-y += -I$(srctree)/drivers/gpu/drm/mediatek/
endif
obj-$(CONFIG_MTK_AEE_FEATURE) += aed/
obj-$(CONFIG_MTK_AEE_FEATURE) += mrdump/
obj-$(CONFIG_MTK_AEE_HANGDET) += hangdet/
+24
View File
@@ -0,0 +1,24 @@
#
# 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.
#
ifeq ($(CONFIG_MTK_GCOV_KERNEL),y)
GCOV_PROFILE := y
endif
obj-$(CONFIG_MTK_AEE_AED) += aee_aed.o
obj-$(CONFIG_MTK_AEE_UT) += aed-debug.o
aee_aed-y += \
aed-main.o \
aee-common.o \
reboot-reason.o
+794
View File
@@ -0,0 +1,794 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#include <linux/arm-smccc.h>
#include <linux/cpumask.h>
#include <linux/delay.h>
#include <linux/kallsyms.h>
#include <linux/kdebug.h>
#include <linux/kprobes.h>
#include <linux/kthread.h>
#include <linux/notifier.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/sched/rt.h>
#include <linux/sched/task.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/soc/mediatek/mtk_sip_svc.h> /* for SMC ID table */
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
#include <uapi/linux/sched/types.h>
#include <mt-plat/mrdump.h>
#include "aed.h"
#include "mrdump_helper.h"
#define BUFSIZE 128
static int test_case;
static int test_cpu;
static struct task_struct *wk_tsk[AEE_MTK_CPU_NUMS];
static int force_panic_hang(struct notifier_block *this, unsigned long event,
void *ptr)
{
pr_notice("\n ==> force panic flow hang\n");
while (1)
;
return 0;
}
static struct notifier_block panic_test = {
.notifier_call = force_panic_hang,
.priority = INT_MAX,
};
void notrace wdt_atf_hang(void)
{
int cpu = get_HW_cpuid();
pr_notice(" CPU %d : %s\n", cpu, __func__);
preempt_disable();
local_irq_disable();
while (1)
;
}
static int kwdt_thread_test(void *arg)
{
struct sched_param param = {.sched_priority = 99 };
int cpu = get_HW_cpuid();
sched_setscheduler(current, SCHED_FIFO, &param);
set_current_state(TASK_INTERRUPTIBLE);
pr_notice("\n ==> %s on CPU %d, test_case = %d\n",
__func__, cpu, test_case);
msleep(1000);
if (test_case == 1) {
if (cpu == test_cpu) {
pr_notice("\n CPU %d : disable preemption and local IRQ forever"
, cpu);
preempt_disable();
local_irq_disable();
while (1)
;
} else {
pr_notice("\n CPU %d : Do nothing and exit\n ", cpu);
}
} else if (test_case == 2) {
if (cpu == test_cpu) {
msleep(1000);
pr_notice("\n CPU %d : disable preemption and local IRQ forever"
, cpu);
preempt_disable();
local_irq_disable();
while (1)
;
} else {
pr_notice("\n CPU %d : disable irq\n ", cpu);
local_irq_disable();
while (1)
;
}
} else if (test_case == 3) {
if (cpu == test_cpu) {
pr_notice("\n CPU %d : register panic notifier and force hang\n"
, cpu);
atomic_notifier_chain_register(&panic_notifier_list,
&panic_test);
preempt_disable();
local_irq_disable();
while (1)
;
} else {
pr_notice("\n CPU %d : Do nothing and exit\n ", cpu);
}
} else if (test_case == 4) {
pr_notice("\n CPU %d : disable preemption and local IRQ forever\n "
, cpu);
preempt_disable();
local_irq_disable();
while (1)
;
} else if (test_case == 5) {
pr_notice("\n CPU %d : disable preemption and local IRQ/FIQ forever\n "
, cpu);
preempt_disable();
local_irq_disable();
while (1)
;
} else if (test_case == 6) {
pr_notice("\n CPU %d : disable preemption and local IRQ/FIQ forever\n "
, cpu);
preempt_disable();
local_irq_disable();
while (1)
;
}
return 0;
}
static ssize_t proc_generate_wdt_write(struct file *file,
const char __user *buf, size_t size, loff_t *ppos)
{
unsigned int i;
char msg[4];
unsigned char name[20] = { 0 };
struct arm_smccc_res res;
if ((size < 2) || (size > sizeof(msg))) {
pr_notice("\n size = %zx\n", size);
return -EINVAL;
}
if (!buf) {
pr_notice("\n buf = NULL\n");
return -EINVAL;
}
if (copy_from_user(msg, buf, size)) {
pr_notice("copy_from_user error");
return -EFAULT;
}
test_case = (unsigned int)msg[0] - '0';
test_cpu = (unsigned int)msg[2] - '0';
pr_notice("test_case = %d, test_cpu = %d", test_case, test_cpu);
if ((msg[1] != ':') || (test_case < 1) || (test_case > 6)
|| (test_cpu < 0) || (test_cpu > nr_cpu_ids)) {
pr_notice("WDT test - Usage: [test case number(1~6):test cpu(0~%d)]\n"
, nr_cpu_ids);
return -EINVAL;
}
if (test_case == 1) {
pr_notice("Test 1 : One CPU WDT timeout (smp_send_stop succeed)\n");
} else if (test_case == 2) {
pr_notice("Test 2 : One CPU WDT timeout, other CPU disable irq (smp_send_stop fail in old design)\n");
} else if (test_case == 3) {
pr_notice("Test 3 : WDT timeout and loop in panic flow\n");
} else if (test_case == 4) {
pr_notice("Test 4 : All CPU WDT timeout (other CPU stop in the loop)\n");
} else if (test_case == 5) {
pr_notice("Test 5 : Disable ALL CPU IRQ/FIQ (FIQ : HW_reboot, ATF : HWT\n");
} else if (test_case == 6) {
pr_notice("Test 6 : (For ATF) HW_REBOOT : change SMC call back function and while loop\n");
#ifdef CONFIG_ARM64
arm_smccc_smc(MTK_SIP_KERNEL_WDT, (u64) &wdt_atf_hang, 0, 0, 0,
0, 0, 0, &res);
#endif
#ifdef CONFIG_ARM_PSCI
arm_smccc_smc(MTK_SIP_KERNEL_WDT, (u32) &wdt_atf_hang, 0, 0, 0,
0, 0, 0, &res);
#endif
} else {
pr_notice("\n Unknown test_case %d\n", test_case);
return -EINVAL;
}
/* create kernel threads and bind on every cpu */
for (i = 0; i < nr_cpu_ids; i++) {
sprintf(name, "wd-test-%d", i);
pr_notice("[WDK]thread name: %s\n", name);
wk_tsk[i] = kthread_create(kwdt_thread_test, NULL, name);
if (IS_ERR(wk_tsk[i])) {
int ret = PTR_ERR(wk_tsk[i]);
wk_tsk[i] = NULL;
return ret;
}
kthread_bind(wk_tsk[i], i);
}
for (i = 0; i < nr_cpu_ids; i++) {
pr_notice(" wake_up_process(wk_tsk[%d])\n", i);
wake_up_process(wk_tsk[i]);
}
return size;
}
static ssize_t proc_generate_wdt_read(struct file *file,
char __user *buf, size_t size, loff_t *ppos)
{
char buffer[BUFSIZE];
int len = snprintf(buffer, BUFSIZE,
"WDT test - Usage: [test case number:test cpu]\n");
if (len < 0)
pr_notice("%s: snprintf failed\n", __func__);
if (*ppos)
return 0;
if (copy_to_user(buf, buffer, len)) {
pr_notice("%s fail to output info.\n", __func__);
return -EFAULT;
}
*ppos += len;
return len;
}
/*****************************BEGIN OOPS***************************/
/**********BEGIN ISR trigger HWT**********/
/* kprobe pre_handler: called just before the probed instruction is executed */
static int handler_pre(struct kprobe *p, struct pt_regs *regs)
{
pr_info("process_name:[%s], pid = %d.\n", current->comm, current->pid);
return 0;
}
/* kprobe post_handler: called after the probed instruction is executed */
int flag = 1;
void handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long flags)
{
if (flag) {
flag = 0;
mdelay(30 * 1000);
}
}
static int handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr);
static struct kprobe kp_kpd_irq_handler = {
.symbol_name = "kpd_irq_handler",
.pre_handler = handler_pre,
.post_handler = handler_post,
.fault_handler = handler_fault,
};
/*
* fault_handler: this is called if an exception is generated for any
* instruction within the pre- or post-handler, or when Kprobes
* single-steps the probed instruction.
*/
static int handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr)
{
pr_notice("fault_handler: p->addr = 0x%p, trap #%dn", p->addr, trapnr);
unregister_kprobe(&kp_kpd_irq_handler);
pr_notice("kprobe at %p unregistered\n", kp_kpd_irq_handler.addr);
/* Return 0 because we don't handle the fault. */
return 0;
}
static int register_kprobe_kpd_irq_handler(void)
{
int ret;
/* All set to register with Kprobes */
ret = register_kprobe(&kp_kpd_irq_handler);
if (ret < 0)
pr_info("register_kprobe failed, returned %d\n", ret);
else
pr_info("Planted kprobe at %p, press Vol+/- to trigger.\n",
kp_kpd_irq_handler.addr);
return ret;
}
/**********END ISR trigger HWT**********/
/**********BEGIN panic case**********/
static noinline int stack_overflow_routine(int x, int y, int z)
{
char a[4];
char *p = a;
int i;
for (i = 0; i < (x + y + z) * 2; i++)
*(p + i) = i;
/* stack overflow */
return a[0] + a[3];
}
static noinline void buffer_over_flow(void)
{
int n;
pr_info("test case : buffer overflow\n");
n = stack_overflow_routine(10, 1, 22);
pr_info("%s: %d\n", __func__, n);
}
static noinline void access_null_pointer(void)
{
void *p = NULL;
pr_info("test case : derefence Null pointer\n");
*((unsigned int *)p) = 0xDEAD;
}
static noinline void double_free(void)
{
char *p = kmalloc(32, GFP_KERNEL);
int i;
if (p == NULL)
return;
pr_info("test case : double free\n");
for (i = 0; i < 32; i++)
p[i] = (char)i;
pr_info("aee_ut_ke: call free\n");
kfree(p);
pr_info("aee_ut_ke: call free again\n");
kfree(p);
}
static noinline void devide_by_0(void)
{
int ZERO = 0;
int number;
pr_info("test case: division by %d\n", ZERO);
number = 100 / ZERO;
pr_info("%s: %d\n", __func__, number);
}
/**********END panic case**********/
static ssize_t proc_generate_oops_read(struct file *file,
char __user *buf, size_t size, loff_t *ppos)
{
int len;
char buffer[BUFSIZE];
len = snprintf(buffer, BUFSIZE, "Oops Generated!\n");
if (len <= 0)
pr_debug("%s: snprintf error\n", __func__);
if (copy_to_user(buf, buffer, len))
pr_notice("%s fail to output info.\n", __func__);
BUG();
return len;
}
static ssize_t proc_generate_oops_write(struct file *file,
const char __user *buf, size_t size, loff_t *ppos)
{
char msg[6];
int test_case, test_subcase, test_cpu;
if ((size < 2) || (size > sizeof(msg))) {
pr_notice("%s: count = %zx\n", __func__, size);
return -EINVAL;
}
if (!buf) {
pr_notice("%s: buf = NULL\n", __func__);
return -EINVAL;
}
if (copy_from_user(msg, buf, size)) {
pr_notice("%s: error\n", __func__);
return -EFAULT;
}
test_case = (unsigned int)msg[0] - '0';
test_subcase = (unsigned int)msg[2] - '0';
test_cpu = (unsigned int)msg[4] - '0';
pr_notice("test_case = %d-%d, test_cpu = %d\n", test_case,
test_subcase, test_cpu);
switch (test_case) {
case 1:
switch (test_subcase) {
case 1:
buffer_over_flow();
break;
case 2:
access_null_pointer();
break;
case 3:
double_free();
break;
case 4:
devide_by_0();
break;
default:
break;
}
break;
case 2:
register_kprobe_kpd_irq_handler();
break;
case 3:
panic("aee test");
break;
default:
break;
}
return size;
}
static int nested_panic(struct notifier_block *this, unsigned long event,
void *ptr)
{
pr_notice("\n => force nested panic\n");
BUG();
return 0;
}
static struct notifier_block panic_blk = {
.notifier_call = nested_panic,
.priority = INT_MAX - 100,
};
static ssize_t proc_generate_nested_ke_read(struct file *file, char __user *buf,
size_t size, loff_t *ppos)
{
atomic_notifier_chain_register(&panic_notifier_list, &panic_blk);
pr_notice("\n => panic_notifier_list registered\n");
BUG();
return 0;
}
static ssize_t proc_generate_nested_ke_write(struct file *file,
const char __user *buf, size_t size, loff_t *ppos)
{
char msg[6];
int test_case, test_subcase, test_cpu;
if ((size < 2) || (size > sizeof(msg))) {
pr_notice("%s: count = %zx\n", __func__, size);
return -EINVAL;
}
if (!buf) {
pr_notice("%s: buf = NULL\n", __func__);
return -EINVAL;
}
if (copy_from_user(msg, buf, size)) {
pr_notice("%s: error\n", __func__);
return -EFAULT;
}
test_case = (unsigned int)msg[0] - '0';
test_subcase = (unsigned int)msg[2] - '0';
test_cpu = (unsigned int)msg[4] - '0';
pr_notice("test_case = %d-%d, test_cpu = %d\n", test_case,
test_subcase, test_cpu);
switch (test_case) {
case 1:
register_die_notifier(&panic_blk);
break;
}
//BUG();
return 0;
}
static ssize_t proc_generate_ee_read(struct file *file, char __user *buf,
size_t size, loff_t *ppos)
{
#define TEST_EE_LOG_SIZE 2048
#define TEST_EE_PHY_SIZE 65536
char buffer[BUFSIZE];
char *ptr, *log;
int i, len;
if ((*ppos)++)
return 0;
ptr = vmalloc(TEST_EE_PHY_SIZE);
if (!ptr)
return 0;
log = kmalloc(TEST_EE_LOG_SIZE, GFP_KERNEL);
if (!log) {
vfree(ptr);
return 0;
}
for (i = 0; i < TEST_EE_PHY_SIZE; i++)
ptr[i] = (i % 26) + 'A';
for (i = 0; i < TEST_EE_LOG_SIZE; i++)
log[i] = i % 255;
aed_md_exception_api((int *)log, TEST_EE_LOG_SIZE, (int *)ptr,
TEST_EE_PHY_SIZE, __FILE__, DB_OPT_FTRACE);
vfree(ptr);
kfree(log);
len = snprintf(buffer, BUFSIZE, "Modem EE Generated\n");
if (len <= 0)
pr_debug("%s: snprintf error\n", __func__);
if (copy_to_user(buf, buffer, len)) {
pr_notice("%s fail to output info.\n", __func__);
return -EFAULT;
}
*ppos += len;
return len;
}
static ssize_t proc_generate_ee_write(struct file *file,
const char __user *buf, size_t size, loff_t *ppos)
{
return 0;
}
static ssize_t proc_generate_combo_read(struct file *file, char __user *buf,
size_t size, loff_t *ppos)
{
#define TEST_COMBO_PHY_SIZE 65536
char buffer[BUFSIZE];
int i, len;
char *ptr;
if ((*ppos)++)
return 0;
ptr = vmalloc(TEST_COMBO_PHY_SIZE);
if (!ptr)
return sprintf(buffer, "kmalloc fail\n");
for (i = 0; i < TEST_COMBO_PHY_SIZE; i++)
ptr[i] = (i % 26) + 'A';
aed_combo_exception(NULL, 0, (int *)ptr, TEST_COMBO_PHY_SIZE, __FILE__);
vfree(ptr);
len = snprintf(buffer, BUFSIZE, "Combo EE Generated\n");
if (len <= 0)
pr_debug("%s: snprintf error\n", __func__);
if (copy_to_user(buf, buffer, len)) {
pr_notice("%s fail to output info.\n", __func__);
return -EFAULT;
}
*ppos += len;
return len;
}
static ssize_t proc_generate_combo_write(struct file *file,
const char __user *buf, size_t size, loff_t *ppos)
{
return 0;
}
static ssize_t proc_generate_md32_read(struct file *file, char __user *buf,
size_t size, loff_t *ppos)
{
#define TEST_MD32_PHY_SIZE 65536
char buffer[BUFSIZE];
int i, len;
char *ptr;
if ((*ppos)++)
return 0;
ptr = vmalloc(TEST_MD32_PHY_SIZE);
if (!ptr)
return 0;
for (i = 0; i < TEST_MD32_PHY_SIZE; i++)
ptr[i] = (i % 26) + 'a';
if (sprintf(buffer, "MD32 EE log here\n") < 0)
pr_info("%s: sprintf failed\n", __func__);
aed_md32_exception((int *)buffer, (int)sizeof(buffer), (int *)ptr,
TEST_MD32_PHY_SIZE, __FILE__);
vfree(ptr);
len = snprintf(buffer, BUFSIZE, "MD32 EE Generated\n");
if (len < 0)
pr_info("%s: snprintf failed\n", __func__);
if (copy_to_user(buf, buffer, len)) {
pr_notice("%s fail to output info.\n", __func__);
return -EFAULT;
}
*ppos += len;
return len;
}
static ssize_t proc_generate_md32_write(struct file *file,
const char __user *buf, size_t size,
loff_t *ppos)
{
return 0;
}
static ssize_t proc_generate_scp_read(struct file *file,
char __user *buf, size_t size,
loff_t *ppos)
{
#define TEST_SCP_PHY_SIZE 65536
char buffer[BUFSIZE];
int i, len;
char *ptr;
if ((*ppos)++)
return 0;
ptr = vmalloc(TEST_SCP_PHY_SIZE);
if (!ptr)
return 0;
for (i = 0; i < TEST_SCP_PHY_SIZE; i++)
ptr[i] = (i % 26) + 'a';
if (sprintf(buffer, "SCP EE log here\n") < 0)
pr_info("%s: sprintf failed\n", __func__);
aed_scp_exception((int *)buffer, (int)sizeof(buffer), (int *)ptr,
TEST_SCP_PHY_SIZE, __FILE__);
vfree(ptr);
len = snprintf(buffer, BUFSIZE, "SCP EE Generated\n");
if (len < 0)
pr_info("%s: snprintf failed\n", __func__);
if (copy_to_user(buf, buffer, len)) {
pr_notice("%s fail to output info.\n", __func__);
return -EFAULT;
}
*ppos += len;
return len;
}
static ssize_t proc_generate_scp_write(struct file *file,
const char __user *buf, size_t size,
loff_t *ppos)
{
return 0;
}
static ssize_t proc_generate_adsp_read(struct file *file,
char __user *buf, size_t size,
loff_t *ppos)
{
#define TEST_ADSP_PHY_SIZE 65536
char buffer[BUFSIZE];
int i;
char *ptr;
int n;
if ((*ppos)++)
return 0;
ptr = kmalloc(TEST_ADSP_PHY_SIZE, GFP_KERNEL);
if (ptr == NULL)
return sprintf(buffer, "kmalloc fail\n");
for (i = 0; i < TEST_ADSP_PHY_SIZE; i++)
ptr[i] = (i % 26) + 'a';
n = sprintf(buffer, "ADSP EE log here\n");
if (n < 0 || n >= sizeof(buffer))
strncpy(buffer, "unknown error", sizeof(buffer));
aed_common_exception("adsp", (int *)buffer, (int)sizeof(buffer),
(int *)ptr, TEST_ADSP_PHY_SIZE, __FILE__);
kfree(ptr);
return sprintf(buffer, "ADSP EE Generated\n");
}
static ssize_t proc_generate_adsp_write(struct file *file,
const char __user *buf, size_t size,
loff_t *ppos)
{
return 0;
}
static ssize_t proc_generate_kernel_notify_read(struct file *file,
char __user *buf, size_t size,
loff_t *ppos)
{
char buffer[BUFSIZE];
int len = snprintf(buffer, BUFSIZE,
"Usage: write message with format \"R|W|E:Tag:You Message\" into this file to generate kernel warning\n");
if (len <= 0)
pr_debug("%s: snprintf error\n", __func__);
if (*ppos)
return 0;
if (copy_to_user(buf, buffer, len)) {
pr_notice("%s fail to output info.\n", __func__);
return -EFAULT;
}
*ppos += len;
return len;
}
static ssize_t proc_generate_kernel_notify_write(struct file *file,
const char __user *buf,
size_t size,
loff_t *ppos)
{
char msg[164], *colon_ptr;
if (size == 0)
return -EINVAL;
if ((size < 5) || (size >= sizeof(msg))) {
pr_notice("aed: %s size sould be >= 5 and <= %zx bytes.\n",
__func__, sizeof(msg));
return -EINVAL;
}
if (!buf) {
pr_notice("aed: %s buf = NULL\n", __func__);
return -EINVAL;
}
if (copy_from_user(msg, buf, size)) {
pr_notice("aed: %s unable to read message\n", __func__);
return -EFAULT;
}
/* Be safe */
msg[size] = 0;
if (msg[1] != ':')
return -EINVAL;
colon_ptr = strchr(&msg[2], ':');
if (!colon_ptr || ((colon_ptr - msg) > 32)) {
pr_notice("aed: %s cannot find valid module name\n", __func__);
return -EINVAL;
}
*colon_ptr = 0;
switch (msg[0]) {
case 'R':
aee_kernel_reminding_api(__FILE__, __LINE__,
DB_OPT_DEFAULT | DB_OPT_NATIVE_BACKTRACE, &msg[2], colon_ptr + 1);
break;
case 'W':
aee_kernel_warning_api(__FILE__, __LINE__,
DB_OPT_DEFAULT | DB_OPT_NATIVE_BACKTRACE, &msg[2], colon_ptr + 1);
break;
case 'E':
aee_kernel_exception_api(__FILE__, __LINE__,
DB_OPT_DEFAULT | DB_OPT_NATIVE_BACKTRACE, &msg[2], colon_ptr + 1);
break;
default:
return -EINVAL;
}
return size;
}
AED_FILE_OPS(generate_oops);
AED_FILE_OPS(generate_nested_ke);
AED_FILE_OPS(generate_kernel_notify);
AED_FILE_OPS(generate_wdt);
AED_FILE_OPS(generate_ee);
AED_FILE_OPS(generate_combo);
AED_FILE_OPS(generate_md32);
AED_FILE_OPS(generate_scp);
AED_FILE_OPS(generate_adsp);
int aed_proc_debug_init(struct proc_dir_entry *aed_proc_dir)
{
/* 0600: S_IRUSR | S_IWUSR */
AED_PROC_ENTRY(generate-oops, generate_oops, 0600);
/* 0400: S_IRUSR */
AED_PROC_ENTRY(generate-nested-ke, generate_nested_ke, 0400);
/* 0600: S_IRUSR | S_IWUSR */
AED_PROC_ENTRY(generate-kernel-notify, generate_kernel_notify, 0600);
AED_PROC_ENTRY(generate-wdt, generate_wdt, 0600);
/* 0400: S_IRUSR */
AED_PROC_ENTRY(generate-ee, generate_ee, 0400);
AED_PROC_ENTRY(generate-combo, generate_combo, 0400);
AED_PROC_ENTRY(generate-md32, generate_md32, 0400);
AED_PROC_ENTRY(generate-scp, generate_scp, 0400);
AED_PROC_ENTRY(generate-adsp, generate_adsp, 0400);
return 0;
}
int aed_proc_debug_done(struct proc_dir_entry *aed_proc_dir)
{
remove_proc_entry("generate-oops", aed_proc_dir);
remove_proc_entry("generate-nested-ke", aed_proc_dir);
remove_proc_entry("generate-kernel-notify", aed_proc_dir);
remove_proc_entry("generate-ee", aed_proc_dir);
remove_proc_entry("generate-combo", aed_proc_dir);
remove_proc_entry("generate-md32", aed_proc_dir);
remove_proc_entry("generate-scp", aed_proc_dir);
remove_proc_entry("generate-wdt", aed_proc_dir);
remove_proc_entry("generate-adsp", aed_proc_dir);
return 0;
}
File diff suppressed because it is too large. Load diff
+296
View File
@@ -0,0 +1,296 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef __aed_h
#define __aed_h
#include <generated/autoconf.h>
#include <linux/bug.h>
#include <linux/kallsyms.h>
#include <linux/notifier.h>
#include <linux/ptrace.h>
#include <linux/types.h>
#include <mt-plat/aee.h>
#define AE_INVALID 0xAEEFF000
#define AE_NOT_AVAILABLE 0xAEE00000
#define AE_DEFAULT 0xAEE00001
enum AE_DEFECT_ATTR {
AE_DEFECT_FATAL,
AE_DEFECT_EXCEPTION,
AE_DEFECT_WARNING,
AE_DEFECT_REMINDING,
AE_DEFECT_ATTR_END
};
enum AEE_MODE {
AEE_MODE_MTK_ENG = 1,
AEE_MODE_MTK_USER,
AEE_MODE_CUSTOMER_ENG,
AEE_MODE_CUSTOMER_USER,
AEE_MODE_NOT_INIT
};
enum AE_EXP_CLASS {
AE_KE = 0, /* Fatal Exception */
AE_HWT,
AE_REBOOT,
AE_NE,
AE_JE,
AE_SWT,
AE_EE,
AE_EXP_ERR_END,
AE_ANR, /* Error or Warning or Defect */
AE_RESMON,
AE_MODEM_WARNING,
AE_WTF,
AE_WRN_ERR_END,
AE_MANUAL, /* Manual Raise */
AE_EXP_CLASS_END,
AE_KERNEL_PROBLEM_REPORT = 1000,
AE_SYSTEM_JAVA_DEFECT,
AE_SYSTEM_NATIVE_DEFECT,
AE_MANUAL_MRDUMP_KEY,
}; /* General Program Exception Class */
enum AEE_FORCE_RED_SCREEN_VALUE {
AEE_FORCE_DISABLE_RED_SCREEN = 0,
AEE_FORCE_RED_SCREEN,
AEE_FORCE_NOT_SET
};
enum AEE_FORCE_EXP {
AEE_FORCE_EXP_DISABLE = 0,
AEE_FORCE_EXP_ENABLE,
AEE_FORCE_EXP_NOT_SET
};
enum AE_ERR {
AE_SUCC,
AE_FAIL
};
enum AE_PASS_METHOD {
AE_PASS_BY_MEM,
AE_PASS_BY_FILE,
AE_PASS_METHOD_END
};
enum AE_CMD_TYPE { AE_REQ, AE_RSP, AE_IND, AE_CMD_TYPE_END };
enum AE_CMD_ID {
AE_REQ_IDX,
AE_REQ_CLASS,
AE_REQ_TYPE,
AE_REQ_PROCESS, /* deprecated */
AE_REQ_MODULE,
AE_REQ_BACKTRACE,
/* Content of response message rule:
* if msg.arg1==AE_PASS_BY_FILE => msg->data=file path
*/
AE_REQ_DETAIL,
AE_REQ_ROOT_LOG_DIR,
AE_REQ_CURR_LOG_DIR,
AE_REQ_DFLT_LOG_DIR,
AE_REQ_MAIN_LOG_FILE_PATH,
/* fatal event raised, indicate AED to notify users */
AE_IND_FATAL_RAISED,
/* exception event raised, indicate AED to notify users */
AE_IND_EXP_RAISED,
/* warning event raised, indicate AED to notify users */
AE_IND_WRN_RAISED,
/* reminding event raised, indicate AED to notify users */
AE_IND_REM_RAISED,
/* arg = AE_ERR */
AE_IND_LOG_STATUS,
/* arg = AE_ERR */
AE_IND_LOG_CLOSE,
/* arg: dal on|off, seq: beep on|off */
AE_REQ_SWITCH_DAL_BEEP,
/* arg: db count */
AE_REQ_DB_COUNT,
/* arg: force db path yes\no */
AE_REQ_DB_FORCE_PATH,
AE_REQ_SWITCH_EXP_LEVEL,
/* query if AED is ready for service */
AE_REQ_IS_AED_READY,
/* msg->data=file path */
AE_REQ_COREDUMP,
/* set read flag msg */
AE_REQ_SET_READFLAG,
/* Init notification of client side(application layer) of Exp2Server */
AE_REQ_E2S_INIT,
AE_REQ_USERSPACEBACKTRACE = 40,
AE_REQ_USER_REG,
AE_REQ_USER_MAPS,
AE_CMD_ID_END
};
struct aee_kernel_api {
void (*kernel_reportAPI)(const enum AE_DEFECT_ATTR attr,
const int db_opt, const char *module, const char *msg);
void (*md_exception)(const char *assert_type, const int *log,
int log_size, const int *phy, int phy_size,
const char *detail, const int db_opt);
void (*md32_exception)(const char *assert_type, const int *log,
int log_size, const int *phy, int phy_size,
const char *detail, const int db_opt);
void (*combo_exception)(const char *assert_type, const int *log,
int log_size, const int *phy, int phy_size,
const char *detail, const int db_opt);
void (*scp_exception)(const char *assert_type, const int *log,
int log_size, const int *phy, int phy_size,
const char *detail, const int db_opt);
void (*common_exception)(const char *assert_type, const int *log,
int log_size, const int *phy, int phy_size,
const char *detail, const int db_opt);
};
struct aee_oops {
struct list_head list;
enum AE_DEFECT_ATTR attr;
enum AE_EXP_CLASS clazz;
char module[AEE_MODULE_NAME_LENGTH];
/* consist with struct aee_process_info */
char backtrace[AEE_BACKTRACE_LENGTH];
char *detail;
int detail_len;
struct aee_user_thread_stack userthread_stack;
struct aee_thread_reg userthread_reg;
struct aee_user_thread_maps userthread_maps;
int dump_option;
};
struct AE_Msg {
enum AE_CMD_TYPE cmdType; /* command type */
enum AE_CMD_ID cmdId; /* command Id */
union {
unsigned int seq; /* sequence number for error checking */
int pid; /* process id */
};
union {
unsigned int arg; /* simple argument */
enum AE_EXP_CLASS cls; /* exception/error/defect class */
};
union {
unsigned int len; /* dynamic length argument */
int id; /* desired id */
};
unsigned int dbOption; /* DB dump option */
};
/* Kernel IOCTL interface */
struct aee_dal_show {
char msg[1024];
};
struct aee_dal_setcolor {
unsigned int foreground;
unsigned int background;
unsigned int screencolor;
};
/* we use MAX_NR_FRAME to control max unwind layer */
#define MAX_AEE_KERNEL_BT 16
#define AEE_NR_FRAME 32
struct aee_ioctl {
__u32 pid;
__u32 detail;
__u32 size;
__u32 pad;
__u64 in;
__u64 out;
};
struct aee_thread_user_stack {
pid_t tid;
int StackLength;
/* 8k stack ,define to char only for match 64bit/32bit */
unsigned char Userspace_Stack[8192];
};
struct aee_siginfo {
pid_t tid;
int si_signo;
int si_errno;
int si_code;
uintptr_t fault_addr;
};
/* Show string on DAL layer */
#define AEEIOCTL_DAL_SHOW _IOW('p', 0x01, struct aee_dal_show)
#define AEEIOCTL_DAL_CLEAN _IO('p', 0x02) /* Clear DAL layer */
/* RGB color 0x00RRGGBB */
#define AEEIOCTL_SETCOLOR _IOW('p', 0x03, struct aee_dal_setcolor)
#define AEEIOCTL_GET_PROCESS_BT _IOW('p', 0x04, struct aee_ioctl)
#define AEEIOCTL_GET_SMP_INFO _IOR('p', 0x05, int)
#define AEEIOCTL_SET_AEE_MODE _IOR('p', 0x06, int)
#define AEEIOCTL_GET_THREAD_REG _IOW('p', 0x07, struct aee_thread_reg)
#define AEEIOCTL_CHECK_SUID_DUMPABLE _IOR('p', 0x08, int)
/* AED debug support */
#define AEEIOCTL_WDT_KICK_POWERKEY _IOR('p', 0x09, int)
#define AEEIOCTL_RT_MON_Kick _IOR('p', 0x0A, int)
#define AEEIOCTL_SET_FORECE_RED_SCREEN _IOR('p', 0x0B, int)
#define AEEIOCTL_SET_SF_STATE _IOR('p', 0x0C, long long)
#define AEEIOCTL_GET_SF_STATE _IOW('p', 0x0D, long long)
#define AEEIOCTL_USER_IOCTL_TO_KERNEL_WANING _IOR('p', 0x0E, int)
#define AEEIOCTL_SET_AEE_FORCE_EXP _IOR('p', 0x0F, int)
#define AEEIOCTL_GET_AEE_SIGINFO _IOW('p', 0x10, struct aee_siginfo)
#define AEEIOCTL_SET_HANG_FLAG _IOW('p', 0x11, int)
#define AEEIOCTL_SET_HANG_REBOOT _IO('p', 0x12)
#define AEEIOCTL_GET_THREAD_RMS _IOW('p', 0x13, struct unwind_info_rms)
#define AEEIOCTL_GET_THREAD_STACK_RAW _IOW('p', 0x14, struct unwind_info_stack)
#define AED_FILE_OPS(entry) \
static const struct file_operations proc_##entry##_fops = { \
.read = proc_##entry##_read, \
.write = proc_##entry##_write, \
}
#define AED_FILE_OPS_RO(entry) \
static const struct file_operations proc_##entry##_fops = { \
.read = proc_##entry##_read, \
}
#define AED_PROC_ENTRY(name, entry, mode)\
({if (!proc_create(#name, S_IFREG | mode, aed_proc_dir, \
&proc_##entry##_fops)) \
pr_info("proc_create %s failed\n", #name); })
struct proc_dir_entry;
int aed_proc_debug_init(struct proc_dir_entry *aed_proc_dir);
int aed_proc_debug_done(struct proc_dir_entry *aed_proc_dir);
void aee_rr_proc_init(struct proc_dir_entry *aed_proc_dir);
void aee_rr_proc_done(struct proc_dir_entry *aed_proc_dir);
extern struct atomic_notifier_head panic_notifier_list;
extern int ksysfs_bootinfo_init(void);
extern void ksysfs_bootinfo_exit(void);
extern int aee_dump_ccci_debug_info(int md_id, void **addr, int *size);
extern int aee_get_mode(void);
extern void aee_kernel_RT_Monitor_api(int lParam);
extern void show_task_mem(void);
void show_native_bt_by_pid(int task_pid);
void aee_register_api(struct aee_kernel_api *aee_api);
#endif
+211
View File
@@ -0,0 +1,211 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#include "aed.h"
static struct aee_kernel_api *g_aee_api;
#define KERNEL_REPORT_LENGTH 344
void aee_register_api(struct aee_kernel_api *aee_api)
{
g_aee_api = aee_api;
}
EXPORT_SYMBOL(aee_register_api);
void aee_disable_api(void)
{
if (g_aee_api) {
pr_info("disable aee kernel api");
g_aee_api = NULL;
}
}
EXPORT_SYMBOL(aee_disable_api);
void aee_kernel_exception_api_func(const char *file, const int line,
const int db_opt, const char *module, const char *msg, ...)
{
char msgbuf[KERNEL_REPORT_LENGTH];
int offset = 0;
va_list args;
va_start(args, msg);
offset += snprintf(msgbuf, KERNEL_REPORT_LENGTH, "<%s:%d> ", file,
line);
offset += vsnprintf(msgbuf + offset, KERNEL_REPORT_LENGTH - offset, msg,
args);
if (g_aee_api && g_aee_api->kernel_reportAPI)
g_aee_api->kernel_reportAPI(AE_DEFECT_EXCEPTION, db_opt, module,
msgbuf);
else
pr_notice("AEE kernel exception: %s", msgbuf);
va_end(args);
}
EXPORT_SYMBOL(aee_kernel_exception_api_func);
void aee_kernel_warning_api_func(const char *file, const int line,
const int db_opt, const char *module, const char *msg, ...)
{
char msgbuf[KERNEL_REPORT_LENGTH];
int offset = 0;
va_list args;
va_start(args, msg);
offset += snprintf(msgbuf, KERNEL_REPORT_LENGTH, "<%s:%d> ", file,
line);
offset += vsnprintf(msgbuf + offset, KERNEL_REPORT_LENGTH - offset,
msg, args);
if (g_aee_api && g_aee_api->kernel_reportAPI) {
if (module && strstr(module,
"maybe have other hang_detect KE DB"))
g_aee_api->kernel_reportAPI(AE_DEFECT_FATAL, db_opt,
module, msgbuf);
else
g_aee_api->kernel_reportAPI(AE_DEFECT_WARNING, db_opt,
module, msgbuf);
} else {
pr_notice("AEE kernel warning: %s", msgbuf);
}
va_end(args);
}
EXPORT_SYMBOL(aee_kernel_warning_api_func);
int aee_is_printk_too_much(const char *module)
{
if (strstr(module, "intk too much"))
return 1;
return 0;
}
EXPORT_SYMBOL(aee_is_printk_too_much);
void aee_kernel_reminding_api(const char *file, const int line,
const int db_opt, const char *module, const char *msg, ...)
{
char msgbuf[KERNEL_REPORT_LENGTH];
int offset = 0;
va_list args;
va_start(args, msg);
offset += snprintf(msgbuf, KERNEL_REPORT_LENGTH, "<%s:%d> ",
file, line);
offset += vsnprintf(msgbuf + offset, KERNEL_REPORT_LENGTH - offset,
msg, args);
if (g_aee_api && g_aee_api->kernel_reportAPI)
g_aee_api->kernel_reportAPI(AE_DEFECT_REMINDING, db_opt,
module, msgbuf);
else
pr_notice("AEE kernel reminding: %s", msgbuf);
va_end(args);
}
EXPORT_SYMBOL(aee_kernel_reminding_api);
void aed_md_exception_api(const int *log, int log_size, const int *phy,
int phy_size, const char *detail, const int db_opt)
{
pr_debug("%s\n", __func__);
if (g_aee_api) {
if (g_aee_api->md_exception) {
g_aee_api->md_exception("modem", log, log_size, phy,
phy_size, detail, db_opt);
} else {
pr_debug("g_aee_api->md_exception = 0x%p\n",
g_aee_api->md_exception);
}
} else {
pr_debug("g_aee_api is null\n");
}
pr_debug("%s out\n", __func__);
}
EXPORT_SYMBOL(aed_md_exception_api);
void aed_md32_exception_api(const int *log, int log_size, const int *phy,
int phy_size, const char *detail, const int db_opt)
{
pr_debug("%s\n", __func__);
if (g_aee_api) {
if (g_aee_api->md_exception) {
g_aee_api->md_exception("md32", log, log_size, phy,
phy_size, detail, db_opt);
} else {
pr_debug("g_aee_api->md32_exception = 0x%p\n",
g_aee_api->md32_exception);
}
} else {
pr_debug("g_aee_api is null\n");
}
pr_debug("%s out\n", __func__);
}
EXPORT_SYMBOL(aed_md32_exception_api);
void aed_scp_exception_api(const int *log, int log_size, const int *phy,
int phy_size, const char *detail, const int db_opt)
{
pr_debug("%s\n", __func__);
if (g_aee_api) {
if (g_aee_api->md_exception) {
g_aee_api->md_exception("scp", log, log_size, phy,
phy_size, detail, db_opt);
} else {
pr_debug("g_aee_api->scp_exception = 0x%p\n",
g_aee_api->scp_exception);
}
} else {
pr_debug("g_aee_api is null\n");
}
pr_debug("%s out\n", __func__);
}
EXPORT_SYMBOL(aed_scp_exception_api);
void aed_combo_exception_api(const int *log, int log_size, const int *phy,
int phy_size, const char *detail, const int db_opt)
{
pr_debug("aed_combo_exception\n");
if (g_aee_api) {
if (g_aee_api->combo_exception) {
g_aee_api->combo_exception("combo", log, log_size, phy,
phy_size, detail, db_opt);
} else {
pr_debug("g_aee_api->combo_exception = 0x%p\n",
g_aee_api->combo_exception);
}
} else {
pr_debug("g_aee_api is null\n");
}
pr_debug("aed_combo_exception out\n");
}
EXPORT_SYMBOL(aed_combo_exception_api);
void aed_common_exception_api(const char *assert_type, const int *log,
int log_size, const int *phy, int phy_size,
const char *detail, const int db_opt)
{
pr_debug("%s\n", __func__);
if (g_aee_api) {
if (g_aee_api->common_exception) {
g_aee_api->common_exception(assert_type, log, log_size,
phy, phy_size, detail, db_opt);
} else {
pr_debug("g_aee_api->common_exception = 0x%p\n",
g_aee_api->common_exception);
}
} else {
pr_debug("g_aee_api is null\n");
}
pr_debug("%s out\n", __func__);
}
EXPORT_SYMBOL(aed_common_exception_api);
int aed_get_status(void)
{
int mode;
mode = aee_get_mode();
if ((mode >= AEE_MODE_MTK_ENG) && (mode <= AEE_MODE_CUSTOMER_USER))
return 1;
return 0;
}
EXPORT_SYMBOL(aed_get_status);
@@ -0,0 +1,158 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#include <asm/memory.h>
#include <asm/setup.h>
#include <linux/init.h>
#include <linux/kobject.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include <linux/uaccess.h>
#if IS_ENABLED(CONFIG_MTK_WATCHDOG)
#include <mtk_wd_api.h>
#endif
#include <mt-plat/aee.h>
#include <mt-plat/mboot_params.h>
#include <mt-plat/mrdump.h>
#include "aed.h"
#define RR_PROC_NAME "reboot-reason"
static struct proc_dir_entry *aee_rr_file;
static char aee_cmdline[COMMAND_LINE_SIZE];
static const char *mrdump_get_cmd(void)
{
struct file *fd;
mm_segment_t fs;
loff_t pos = 0;
if (aee_cmdline[0] != 0)
return aee_cmdline;
fs = get_fs();
set_fs(KERNEL_DS);
fd = filp_open("/proc/cmdline", O_RDONLY, 0);
if (IS_ERR(fd)) {
pr_info("kedump: Unable to open /proc/cmdline (%ld)",
PTR_ERR(fd));
set_fs(fs);
return aee_cmdline;
}
vfs_read(fd, (void *)aee_cmdline, COMMAND_LINE_SIZE, &pos);
filp_close(fd, NULL);
fd = NULL;
set_fs(fs);
return aee_cmdline;
}
static int aee_rr_reboot_reason_proc_open(struct inode *inode,
struct file *file)
{
return single_open(file, aee_rr_reboot_reason_show, NULL);
}
static const struct file_operations aee_rr_reboot_reason_proc_fops = {
.open = aee_rr_reboot_reason_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
void aee_rr_proc_init(struct proc_dir_entry *aed_proc_dir)
{
aee_rr_file = proc_create(RR_PROC_NAME, 0440, aed_proc_dir,
&aee_rr_reboot_reason_proc_fops);
if (!aee_rr_file)
pr_notice("%s: Can't create rr proc entry\n", __func__);
}
EXPORT_SYMBOL(aee_rr_proc_init);
void aee_rr_proc_done(struct proc_dir_entry *aed_proc_dir)
{
remove_proc_entry(RR_PROC_NAME, aed_proc_dir);
}
EXPORT_SYMBOL(aee_rr_proc_done);
/* define /sys/bootinfo/powerup_reason */
static ssize_t powerup_reason_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
char boot_reason[64];
char *br_ptr;
char *br_ptr_e;
memset(boot_reason, 0x0, 64);
br_ptr = strstr(mrdump_get_cmd(), "androidboot.bootreason=");
if (br_ptr) {
br_ptr_e = strstr(br_ptr, " ");
/* get boot reason */
if (br_ptr_e) {
strncpy(boot_reason, br_ptr + 23,
br_ptr_e - br_ptr - 23);
boot_reason[br_ptr_e - br_ptr - 23] = '\0';
}
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
if (aee_rr_last_fiq_step())
strncpy(boot_reason, "kpanic", 7);
#endif
if (!strncmp(boot_reason, "2sec_reboot",
strlen("2sec_reboot"))) {
br_ptr = strstr(mrdump_get_cmd(),
"has_battery_removed=1");
if (!br_ptr)
return snprintf(buf, sizeof(boot_reason),
"%s_abnormal\n", boot_reason);
}
return snprintf(buf, sizeof(boot_reason), "%s\n", boot_reason);
} else {
return 0;
}
}
static struct kobj_attribute powerup_reason_attr = __ATTR_RO(powerup_reason);
struct kobject *bootinfo_kobj;
EXPORT_SYMBOL(bootinfo_kobj);
static struct attribute *bootinfo_attrs[] = {
&powerup_reason_attr.attr,
NULL
};
static struct attribute_group bootinfo_attr_group = {
.attrs = bootinfo_attrs,
};
int ksysfs_bootinfo_init(void)
{
int error;
bootinfo_kobj = kobject_create_and_add("bootinfo", NULL);
if (!bootinfo_kobj)
return -ENOMEM;
error = sysfs_create_group(bootinfo_kobj, &bootinfo_attr_group);
if (error)
kobject_put(bootinfo_kobj);
return error;
}
void ksysfs_bootinfo_exit(void)
{
kobject_put(bootinfo_kobj);
}
/* end sysfs bootinfo */
@@ -0,0 +1,22 @@
#
# Copyright (C) 2020 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 http://www.gnu.org/licenses/gpl-2.0.html for more details.
#
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/aee/mrdump
subdir-ccflags-y += -I$(srctree)/include/
subdir-ccflags-y += -I$(srctree)/kernel/
ifeq ($(CONFIG_MTK_GCOV_KERNEL),y)
GCOV_PROFILE := y
endif
obj-$(CONFIG_MTK_AEE_HANGDET) += aee_hangdet.o
@@ -0,0 +1,883 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 MediaTek Inc.
*/
#include <asm/cacheflush.h>
#include <asm/kexec.h>
#include <asm/memory.h>
#include <asm/stacktrace.h>
#include <linux/cpu.h>
#include <linux/delay.h>
#if IS_ENABLED(CONFIG_MTK_TICK_BROADCAST_DEBUG)
#include <linux/hrtimer.h>
#endif
#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/rtc.h>
#include <linux/sched/clock.h>
#include <linux/sched/signal.h>
#include <linux/spinlock.h>
#include <linux/suspend.h>
#include <linux/sysrq.h>
#include <sched/sched.h>
#include <uapi/linux/sched/types.h>
#if IS_ENABLED(CONFIG_MTK_TICK_BROADCAST_DEBUG)
#include "../../../../../kernel/time/tick-internal.h"
#include <linux/of_irq.h>
#endif
#include <mt-plat/mboot_params.h>
#include <mt-plat/mrdump.h>
#include "mrdump_helper.h"
#include "mrdump_private.h"
#if IS_ENABLED(CONFIG_MTK_TICK_BROADCAST_DEBUG)
extern void mt_irq_dump_status(unsigned int irq);
#endif
/*************************************************************************
* Feature configure region
*************************************************************************/
#define WK_MAX_MSG_SIZE (128)
#define SOFT_KICK_RANGE (100*1000) // 100ms
#define WDT_MODE 0x0
#define WDT_MODE_EN 0x1
#define WDT_STATUS 0xc
#define WDT_STATUS_IRQ (1 << 29)
#define WDT_LENGTH_TIMEOUT(n) ((n) << 5)
#define WDT_LENGTH 0x04
#define WDT_LENGTH_KEY 0x8
#define WDT_RST 0x08
#define WDT_RST_RELOAD 0x1971
#define WDT_NONRST_REG2 0x24
#define WDT_STAGE_OFS 29
#define WDT_STAGE_MASK 0x07
#define WDT_STAGE_KERNEL 0x03
#define CPU_NR (nr_cpu_ids)
#define DEFAULT_INTERVAL 15
#define WDT_COUNTER 0x514
#define SYST0_CON 0x40
#define SYST0_VAL 0x44
#define SYSTIMER_CNTCV_L (0x8)
#define SYSTIMER_CNTCV_H (0xC)
/* Delay to change RGU timeout in ms */
#define CHG_TMO_DLY_SEC 8L
#define CHG_TMO_EN 0
static int start_kicker(void);
static int g_kicker_init;
static DEFINE_SPINLOCK(lock);
struct task_struct *wk_tsk[16] = { 0 }; /* max cpu 16 */
static unsigned int wk_tsk_bind[16] = { 0 }; /* max cpu 16 */
static unsigned long long wk_tsk_bind_time[16] = { 0 }; /* max cpu 16 */
static unsigned long long wk_tsk_kick_time[16] = { 0 }; /* max cpu 16 */
static char wk_tsk_buf[128] = { 0 };
static unsigned long kick_bit;
static int g_kinterval = -1;
static struct work_struct wdk_work;
static struct workqueue_struct *wdk_workqueue;
static unsigned int lasthpg_act;
static unsigned int lasthpg_cpu;
static unsigned long long lasthpg_t;
static unsigned long long wk_lasthpg_t[16] = { 0 }; /* max cpu 16 */
static unsigned int cpuid_t[16] = { 0 }; /* max cpu 16 */
static unsigned long long lastsuspend_t;
static unsigned long long lastresume_t;
static unsigned long long lastsuspend_syst;
static unsigned long long lastresume_syst;
static struct notifier_block wdt_pm_nb;
static unsigned long g_nxtKickTime;
static int g_hang_detected;
static int g_change_tmo;
static void __iomem *toprgu_base;
static void __iomem *systimer_base;
#if IS_ENABLED(CONFIG_MTK_TICK_BROADCAST_DEBUG)
static unsigned int systimer_irq;
#endif
static unsigned int cpus_kick_bit;
static atomic_t plug_mask = ATOMIC_INIT(0x0);
static struct pt_regs saved_regs;
struct timer_list aee_dump_timer;
static unsigned long long aee_dump_timer_t;
static unsigned long long all_k_timer_t;
static unsigned int aee_dump_timer_c;
static unsigned int cpus_skip_bit;
__weak void mt_irq_dump_status(unsigned int irq)
{
pr_info("empty gic dump\n");
};
static unsigned int get_check_bit(void)
{
return cpus_kick_bit;
}
static unsigned int get_kick_bit(void)
{
return kick_bit;
}
static int start_kicker_thread_with_default_setting(void)
{
g_kinterval = DEFAULT_INTERVAL;
start_kicker();
pr_debug("[wdk] %s done\n", __func__);
return 0;
}
void wk_start_kick_cpu(int cpu)
{
if (IS_ERR(wk_tsk[cpu])) {
pr_debug("[wdk] wk_task[%d] is NULL\n", cpu);
} else {
kthread_bind(wk_tsk[cpu], cpu);
pr_info("[wdk] bind thread %d to cpu %d\n",
wk_tsk[cpu]->pid, cpu);
wake_up_process(wk_tsk[cpu]);
}
}
#if IS_ENABLED(CONFIG_MTK_TICK_BROADCAST_DEBUG)
static char tick_broadcast_mtk_aee_dump_buf[128];
void tick_broadcast_mtk_aee_dump(void)
{
int i, ret = -1;
pr_info("[name:bc&]%s\n", bc_dump_buf.buf);
/* tick_broadcast_oneshot_mask */
memset(tick_broadcast_mtk_aee_dump_buf, 0,
sizeof(tick_broadcast_mtk_aee_dump_buf));
ret = snprintf(tick_broadcast_mtk_aee_dump_buf,
sizeof(tick_broadcast_mtk_aee_dump_buf),
"[TICK] oneshot_mask: %*pbl\n",
cpumask_pr_args(bc_tick_get_broadcast_oneshot_mask()));
if (ret >= 0)
aee_sram_fiq_log(tick_broadcast_mtk_aee_dump_buf);
/* tick_broadcast_pending_mask */
memset(tick_broadcast_mtk_aee_dump_buf, 0,
sizeof(tick_broadcast_mtk_aee_dump_buf));
ret = snprintf(tick_broadcast_mtk_aee_dump_buf,
sizeof(tick_broadcast_mtk_aee_dump_buf),
"[TICK] pending_mask: %*pbl\n",
cpumask_pr_args(bc_tick_get_broadcast_pending_mask()));
if (ret >= 0)
aee_sram_fiq_log(tick_broadcast_mtk_aee_dump_buf);
/* tick_broadcast_force_mask */
memset(tick_broadcast_mtk_aee_dump_buf, 0,
sizeof(tick_broadcast_mtk_aee_dump_buf));
ret = snprintf(tick_broadcast_mtk_aee_dump_buf,
sizeof(tick_broadcast_mtk_aee_dump_buf),
"[TICK] force_mask: %*pbl\n",
cpumask_pr_args(bc_tick_get_broadcast_force_mask()));
if (ret >= 0)
aee_sram_fiq_log(tick_broadcast_mtk_aee_dump_buf);
memset(tick_broadcast_mtk_aee_dump_buf, 0,
sizeof(tick_broadcast_mtk_aee_dump_buf));
ret = snprintf(tick_broadcast_mtk_aee_dump_buf,
sizeof(tick_broadcast_mtk_aee_dump_buf),
"[TICK] affin_e cpu: %d affin_h cpu: %d last_handle %lld\n",
tick_broadcast_history[0].affin_enter_cpu,
tick_broadcast_history[0].affin_handle_cpu,
tick_broadcast_history[0].handle_time);
if (ret >= 0)
aee_sram_fiq_log(tick_broadcast_mtk_aee_dump_buf);
for_each_possible_cpu(i) {
/* to avoid unexpected overrun */
if (i >= num_possible_cpus())
break;
memset(tick_broadcast_mtk_aee_dump_buf, 0,
sizeof(tick_broadcast_mtk_aee_dump_buf));
ret = snprintf(tick_broadcast_mtk_aee_dump_buf,
sizeof(tick_broadcast_mtk_aee_dump_buf),
"[TICK] cpu %d, %llu, %d, %llu\n",
i, tick_broadcast_history[i].time_enter,
tick_broadcast_history[i].ret_enter,
tick_broadcast_history[i].time_exit);
if (ret >= 0)
aee_sram_fiq_log(tick_broadcast_mtk_aee_dump_buf);
}
}
#endif
void dump_wdk_bind_info(bool to_aee_sram)
{
int i = 0;
snprintf(wk_tsk_buf, sizeof(wk_tsk_buf),
"kick=0x%x,check=0x%x\n",
get_kick_bit(), get_check_bit());
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
aee_rr_rec_kick(('D' << 24) | get_kick_bit());
aee_rr_rec_check(('B' << 24) | get_check_bit());
#endif
pr_info("%s", wk_tsk_buf);
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
if (to_aee_sram) {
aee_sram_fiq_log("\n");
aee_sram_fiq_log(wk_tsk_buf);
}
#endif
for (i = 0; i < CPU_NR; i++) {
if (wk_tsk[i] != NULL) {
memset(wk_tsk_buf, 0, sizeof(wk_tsk_buf));
snprintf(wk_tsk_buf, sizeof(wk_tsk_buf),
"[wdk]CPU %d, %d, %lld, %d, %ld, %lld\n",
i, wk_tsk_bind[i], wk_tsk_bind_time[i],
wk_tsk[i]->on_rq, wk_tsk[i]->state,
wk_tsk_kick_time[i]);
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
if (to_aee_sram)
aee_sram_fiq_log(wk_tsk_buf);
#endif
if (!to_aee_sram)
pr_info("%s", wk_tsk_buf);
}
}
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
if (to_aee_sram)
aee_sram_fiq_log("\n");
#endif
}
void kicker_cpu_bind(int cpu)
{
if (IS_ERR(wk_tsk[cpu]))
pr_debug("[wdk]wk_task[%d] is NULL\n", cpu);
else {
/* kthread_bind(wk_tsk[cpu], cpu); */
WARN_ON_ONCE(set_cpus_allowed_ptr(wk_tsk[cpu],
cpumask_of(cpu)) < 0);
wake_up_process(wk_tsk[cpu]);
wk_tsk_bind[cpu] = 1;
wk_tsk_bind_time[cpu] = sched_clock();
}
}
void wk_cpu_update_bit_flag(int cpu, int plug_status, int set_check)
{
if (plug_status == 1) { /* plug on */
spin_lock_bh(&lock);
if (set_check)
cpus_kick_bit |= (1 << cpu);
lasthpg_cpu = cpu;
lasthpg_act = plug_status;
lasthpg_t = sched_clock();
spin_unlock_bh(&lock);
}
if (plug_status == 0) { /* plug off */
spin_lock_bh(&lock);
cpus_kick_bit &= (~(1 << cpu));
lasthpg_cpu = cpu;
lasthpg_act = plug_status;
lasthpg_t = sched_clock();
wk_tsk_bind[cpu] = 0;
spin_unlock_bh(&lock);
}
}
static void (*p_mt_aee_dump_irq_info)(void);
void kwdt_regist_irq_info(void (*fn)(void))
{
p_mt_aee_dump_irq_info = fn;
}
EXPORT_SYMBOL_GPL(kwdt_regist_irq_info);
static void kwdt_time_sync(void)
{
struct rtc_time tm;
struct timespec64 tv = { 0 };
/* android time */
struct rtc_time tm_android;
struct timespec64 tv_android = { 0 };
ktime_get_real_ts64(&tv);
tv_android = tv;
rtc_time64_to_tm(tv.tv_sec, &tm);
tv_android.tv_sec -= (uint64_t)sys_tz.tz_minuteswest * 60;
rtc_time64_to_tm(tv_android.tv_sec, &tm_android);
pr_info("[thread:%d] %d-%02d-%02d %02d:%02d:%02d.%u UTC;"
"android time %d-%02d-%02d %02d:%02d:%02d.%03d\n",
current->pid, tm.tm_year + 1900, tm.tm_mon + 1,
tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
(unsigned int)(tv.tv_nsec / 1000), tm_android.tm_year + 1900,
tm_android.tm_mon + 1, tm_android.tm_mday, tm_android.tm_hour,
tm_android.tm_min, tm_android.tm_sec,
(unsigned int)(tv_android.tv_nsec / 1000));
}
static void kwdt_dump_func(void)
{
struct task_struct *g, *t;
int i = 0;
for_each_process_thread(g, t) {
if (!strcmp(t->comm, "watchdogd")) {
#ifdef CONFIG_ARM64
pr_info("watchdogd on CPU %d\n", t->cpu);
#endif
sched_show_task(t);
break;
}
}
for (i = 0; i < CPU_NR; i++) {
struct rq *rq;
pr_info("task on CPU%d\n", i);
rq = cpu_rq(i);
if (cpu_rq(i))
sched_show_task(rq->curr);
}
dump_wdk_bind_info(true);
#if IS_ENABLED(CONFIG_MTK_IRQ_MONITOR)
if (p_mt_aee_dump_irq_info)
p_mt_aee_dump_irq_info();
#endif
#ifdef CONFIG_MTK_SCHED_EXTENSION
sysrq_sched_debug_show_at_AEE();
#endif
if (toprgu_base)
iowrite32(WDT_RST_RELOAD, toprgu_base + WDT_RST);
/* trigger HWT */
aee_rr_rec_exp_type(AEE_EXP_TYPE_HWT);
crash_setup_regs(&saved_regs, NULL);
mrdump_common_die(0, AEE_REBOOT_MODE_WDT, "HWT", &saved_regs);
}
static void aee_dump_timer_func(struct timer_list *t)
{
spin_lock(&lock);
if (sched_clock() - aee_dump_timer_t < CHG_TMO_DLY_SEC * 1000000000ULL) {
g_change_tmo = 0;
aee_dump_timer_t = 0;
g_hang_detected = 0;
spin_unlock(&lock);
return;
}
if ((sched_clock() > all_k_timer_t) &&
(sched_clock() - all_k_timer_t) < (CHG_TMO_DLY_SEC + 1) * 1000000000ULL) {
g_change_tmo = 0;
aee_dump_timer_t = 0;
g_hang_detected = 0;
spin_unlock(&lock);
return;
} else if ((all_k_timer_t > sched_clock()) &&
(ULLONG_MAX - all_k_timer_t + sched_clock()) < (CHG_TMO_DLY_SEC + 1) * 1000000000ULL) {
g_change_tmo = 0;
aee_dump_timer_t = 0;
g_hang_detected = 0;
spin_unlock(&lock);
return;
}
if (!g_hang_detected ||
(get_kick_bit() & get_check_bit()) == get_check_bit()) {
g_change_tmo = 0;
aee_dump_timer_t = 0;
spin_unlock(&lock);
if (toprgu_base) {
unsigned int tmo_len = 0;
tmo_len = ioread32(toprgu_base + WDT_LENGTH);
iowrite32(tmo_len | WDT_LENGTH_KEY, toprgu_base + WDT_LENGTH);
iowrite32(WDT_RST_RELOAD, toprgu_base + WDT_RST);
}
} else {
spin_unlock(&lock);
kwdt_dump_func();
}
}
static void kwdt_process_kick(int local_bit, int cpu,
unsigned long curInterval, char msg_buf[],
unsigned int original_kicker)
{
unsigned int dump_timeout = 0, r_counter = DEFAULT_INTERVAL;
int i = 0;
bool rgu_fiq = false;
if (toprgu_base && (ioread32(toprgu_base + WDT_MODE) & WDT_MODE_EN))
r_counter = ioread32(toprgu_base + WDT_COUNTER) / (32 * 1024);
if (toprgu_base && (ioread32(toprgu_base + WDT_STATUS) & WDT_STATUS_IRQ))
rgu_fiq = true;
if (aee_dump_timer_t && ((sched_clock() - aee_dump_timer_t) >
(CHG_TMO_DLY_SEC + 5) * 1000000000ULL)) {
if (!aee_dump_timer_c) {
aee_dump_timer_c = 1;
snprintf(msg_buf, WK_MAX_MSG_SIZE, "wdtk-et %s %d cpu=%d o_k=%d\n",
__func__, __LINE__, cpu, original_kicker);
spin_unlock_bh(&lock);
pr_info("%s", msg_buf);
kwdt_dump_func();
return;
}
snprintf(msg_buf, WK_MAX_MSG_SIZE,
"all wdtk was already stopped cpu=%d o_k=%d\n",
cpu, original_kicker);
spin_unlock_bh(&lock);
pr_info("%s", msg_buf);
return;
}
local_bit = kick_bit;
if (cpu != original_kicker) {
/* wdtk-(original_kicker) is migrated to (cpu) */
local_bit |= (1 << original_kicker);
} else if ((local_bit & (1 << cpu)) == 0) {
/* pr_debug("[wdk] set kick_bit\n"); */
local_bit |= (1 << cpu);
/* aee_rr_rec_wdk_kick_jiffies(jiffies); */
} else if ((g_hang_detected == 0) &&
((local_bit & get_check_bit()) != get_check_bit()) &&
(sched_clock() - wk_lasthpg_t[cpu] >
curInterval * 1000ULL)) {
g_hang_detected = 1;
dump_timeout = 1;
}
if ((g_hang_detected == 0) &&
(r_counter < DEFAULT_INTERVAL - 10) && !g_change_tmo) {
g_hang_detected = 1;
dump_timeout = 2;
}
wk_tsk_kick_time[cpu] = sched_clock();
#ifdef CONFIG_ARM64
snprintf(msg_buf, WK_MAX_MSG_SIZE,
"[wdk-c] cpu=%d o_k=%d lbit=0x%x cbit=0x%x,%x,%d,%d,%lld,%x,%ld,%ld,%ld,%ld,[%lld,%ld] %d\n",
cpu, original_kicker, local_bit, get_check_bit(),
(local_bit ^ get_check_bit()) & get_check_bit(), lasthpg_cpu,
lasthpg_act, lasthpg_t, atomic_read(&plug_mask), lastsuspend_t / 1000000,
lastsuspend_syst / 1000000, lastresume_t / 1000000, lastresume_syst / 1000000,
wk_tsk_kick_time[cpu], curInterval, r_counter);
#else
snprintf(msg_buf, WK_MAX_MSG_SIZE,
"[wdk-c] cpu=%d o_k=%d lbit=0x%x cbit=0x%x,%x,%d,%d,%lld,%x,[%lld,%ld] %d\n",
cpu, original_kicker, local_bit, get_check_bit(),
(local_bit ^ get_check_bit()) & get_check_bit(), lasthpg_cpu,
lasthpg_act, lasthpg_t, atomic_read(&plug_mask),
wk_tsk_kick_time[cpu], curInterval, r_counter);
#endif
if ((local_bit & get_check_bit()) == get_check_bit()) {
all_k_timer_t = sched_clock();
del_timer(&aee_dump_timer);
aee_dump_timer_t = 0;
cpus_skip_bit = 0;
msg_buf[5] = 'k';
g_hang_detected = 0;
dump_timeout = 0;
local_bit = 0;
kwdt_time_sync();
}
kick_bit = local_bit;
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
if (!dump_timeout) {
aee_rr_rec_kick(('D' << 24) | local_bit);
aee_rr_rec_check(('B' << 24) | get_check_bit());
}
#endif
for (i = 0; i < CPU_NR; i++) {
if ((atomic_read(&plug_mask) & (1 << i)) || (i == cpu)) {
cpus_kick_bit |= (1 << i);
if (cpus_skip_bit & (1 << i))
cpus_kick_bit &= ~(1 << i);
}
}
if (cpu != original_kicker) {
cpus_kick_bit &= ~(1 << cpu);
cpus_skip_bit |= (1 << cpu);
}
spin_unlock_bh(&lock);
pr_info("%s", msg_buf);
if (dump_timeout) {
#if IS_ENABLED(CONFIG_MTK_TICK_BROADCAST_DEBUG)
tick_broadcast_mtk_aee_dump();
if (systimer_irq)
mt_irq_dump_status(systimer_irq);
#endif
dump_wdk_bind_info(false);
if (systimer_base)
pr_info("SYST0 CON%x VAL%x\n",
ioread32(systimer_base + SYST0_CON),
ioread32(systimer_base + SYST0_VAL));
#if CHG_TMO_EN
if (toprgu_base) {
spin_lock_bh(&lock);
g_change_tmo = 1;
spin_unlock_bh(&lock);
iowrite32((WDT_LENGTH_TIMEOUT(6) << 6) | WDT_LENGTH_KEY,
toprgu_base + WDT_LENGTH);
iowrite32(WDT_RST_RELOAD, toprgu_base + WDT_RST);
}
#endif
/* abort suspend when wdt kick */
if (dump_timeout == 2)
pm_system_wakeup();
else {
spin_lock_bh(&lock);
if (g_hang_detected && !aee_dump_timer_t) {
pm_system_wakeup();
aee_dump_timer_t = sched_clock();
g_change_tmo = 1;
spin_unlock_bh(&lock);
aee_dump_timer.expires = jiffies + CHG_TMO_DLY_SEC * HZ;
add_timer(&aee_dump_timer);
return;
}
spin_unlock_bh(&lock);
}
}
if (rgu_fiq)
pr_info("RGU IRQ triggered, but not raise FIQ\n");
}
static int kwdt_thread(void *arg)
{
struct sched_param param = {.sched_priority = 99 };
int cpu = 0;
int local_bit = 0;
unsigned long curInterval = 0;
char msg_buf[WK_MAX_MSG_SIZE];
sched_setscheduler(current, SCHED_FIFO, &param);
set_current_state(TASK_INTERRUPTIBLE);
for (;;) {
if (kthread_should_stop()) {
pr_info("[wdk] kthread_should_stop do !!\n");
break;
}
msg_buf[0] = '\0';
/*
* pr_debug("[wdk] loc_wk_wdt(%x),loc_wk_wdt->ready(%d)\n",
* loc_wk_wdt ,loc_wk_wdt->ready);
*/
curInterval = g_kinterval*1000*1000;
spin_lock_bh(&lock);
/* smp_processor_id does not
* allowed preemptible context
*/
cpu = smp_processor_id();
/* to avoid wk_tsk[cpu] had not created out */
if (wk_tsk[cpu] != 0) {
if ((kick_bit & get_check_bit()) == 0) {
g_nxtKickTime = ktime_to_us(ktime_get())
+ g_kinterval*1000*1000;
curInterval = g_kinterval*1000*1000;
} else {
curInterval = g_nxtKickTime
- ktime_to_us(ktime_get());
}
/* to avoid interval too long */
if (curInterval > g_kinterval*1000*1000)
curInterval = g_kinterval*1000*1000;
kwdt_process_kick(local_bit, cpu, curInterval,
msg_buf, *((unsigned int *)arg));
} else {
spin_unlock_bh(&lock);
}
usleep_range(curInterval, curInterval + SOFT_KICK_RANGE);
}
pr_debug("[wdk] wdk thread stop, cpu:%d, pid:%d\n", cpu, current->pid);
return 0;
}
static int start_kicker(void)
{
int i;
for (i = 0; i < CPU_NR; i++) {
if (cpu_online(i)) {
cpuid_t[i] = i;
wk_tsk[i] = kthread_create(kwdt_thread,
(void *) &cpuid_t[i], "wdtk-%d", i);
if (IS_ERR(wk_tsk[i])) {
int ret = PTR_ERR(wk_tsk[i]);
wk_tsk[i] = NULL;
pr_info("[wdk]kthread_create failed, wdtk-%d\n", i);
return ret;
}
/* wk_cpu_update_bit_flag(i,1); */
wk_start_kick_cpu(i);
atomic_or(1 << i, &plug_mask);
} else
atomic_andnot(1 << i, &plug_mask);
}
g_kicker_init = 1;
pr_info("[wdk] WDT start kicker done CPU_NR=%d online cpu NR%d\n",
CPU_NR, num_online_cpus());
return 0;
}
static int wk_cpu_callback_online(unsigned int cpu)
{
wk_cpu_update_bit_flag(cpu, 1, 0);
wk_lasthpg_t[cpu] = sched_clock();
atomic_or(1 << cpu, &plug_mask);
/*
* Bind WDK thread to this CPU.
* NOTE: Thread binding must be executed after CPU is ready
* (online).
*/
if (g_kicker_init == 1)
kicker_cpu_bind(cpu);
else
pr_info("kicker was not bound to CPU%d\n", cpu);
return 0;
}
static int wk_cpu_callback_offline(unsigned int cpu)
{
wk_cpu_update_bit_flag(cpu, 0, 1);
atomic_andnot(1 << cpu, &plug_mask);
return 0;
}
static void wdk_work_callback(struct work_struct *work)
{
int res = 0;
int i = 0;
cpu_hotplug_disable();
res = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
"watchdog:wdkctrl:online", wk_cpu_callback_online, NULL);
if (res < 0)
pr_info("[wdk]setup CPUHP_AP_ONLINE_DYN fail %d\n", res);
res = cpuhp_setup_state_nocalls(CPUHP_BP_PREPARE_DYN,
"watchdog:wdkctrl:offline", NULL, wk_cpu_callback_offline);
if (res < 0)
pr_info("[wdk]setup CPUHP_BP_PREPARE_DYN fail %d\n", res);
for (i = 0; i < CPU_NR; i++) {
if (cpu_online(i)) {
wk_cpu_update_bit_flag(i, 1, 1);
pr_debug("[wdk]init cpu online %d\n", i);
} else {
wk_cpu_update_bit_flag(i, 0, 1);
pr_debug("[wdk]init cpu offline %d\n", i);
}
}
start_kicker_thread_with_default_setting();
cpu_hotplug_enable();
pr_info("[wdk]init_wk done late_initcall cpus_kick_bit=0x%x -----\n",
cpus_kick_bit);
}
static int wdt_pm_notify(struct notifier_block *notify_block,
unsigned long mode, void *unused)
{
uint64_t cnt = 0;
if (systimer_base) {
uint32_t low = 0;
cnt = sched_clock();
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
aee_rr_rec_wdk_ktime(cnt);
#endif
low = readl(systimer_base + SYSTIMER_CNTCV_L);
cnt = readl(systimer_base + SYSTIMER_CNTCV_H);
cnt = cnt << 32 | low;
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
aee_rr_rec_wdk_systimer_cnt(cnt);
#endif
}
switch (mode) {
case PM_HIBERNATION_PREPARE:
case PM_SUSPEND_PREPARE:
case PM_RESTORE_PREPARE:
lastsuspend_t = sched_clock();
lastsuspend_syst = cnt;
spin_lock_bh(&lock);
del_timer_sync(&aee_dump_timer);
aee_dump_timer_t = 0;
g_hang_detected = 0;
spin_unlock_bh(&lock);
break;
case PM_POST_SUSPEND:
case PM_POST_HIBERNATION:
case PM_POST_RESTORE:
lastresume_t = sched_clock();
lastresume_syst = cnt;
break;
}
if (toprgu_base)
iowrite32(WDT_RST_RELOAD, toprgu_base + WDT_RST);
return 0;
}
static int __init init_wk_check_bit(void)
{
int i = 0;
pr_debug("[wdk]arch init check_bit=0x%x+++++\n", cpus_kick_bit);
for (i = 0; i < CPU_NR; i++) {
if (cpu_online(i))
wk_cpu_update_bit_flag(i, 1, 1);
}
pr_debug("[wdk]arch init check_bit=0x%x-----\n", cpus_kick_bit);
return 0;
}
static void wdt_mark_stage(unsigned int stage)
{
unsigned int reg = ioread32(toprgu_base + WDT_NONRST_REG2);
reg = (reg & ~(WDT_STAGE_MASK << WDT_STAGE_OFS))
| (stage << WDT_STAGE_OFS);
iowrite32(reg, toprgu_base + WDT_NONRST_REG2);
}
static const struct of_device_id toprgu_of_match[] = {
{ .compatible = "mediatek,mt6589-wdt" },
{},
};
static const struct of_device_id systimer_of_match[] = {
{ .compatible = "mediatek,mt6765-timer" },
{},
};
static int __init hangdet_init(void)
{
int res = 0;
#if IS_ENABLED(CONFIG_MTK_TICK_BROADCAST_DEBUG)
unsigned int systirq = 0;
#endif
struct device_node *np_toprgu, *np_systimer;
for_each_matching_node(np_toprgu, toprgu_of_match) {
pr_info("%s: compatible node found: %s\n",
__func__, np_toprgu->name);
break;
}
toprgu_base = of_iomap(np_toprgu, 0);
if (!toprgu_base)
pr_debug("toprgu iomap failed\n");
else
wdt_mark_stage(WDT_STAGE_KERNEL);
for_each_matching_node(np_systimer, systimer_of_match) {
pr_info("%s: compatible node found: %s\n",
__func__, np_systimer->name);
break;
}
systimer_base = of_iomap(np_systimer, 0);
if (!systimer_base)
pr_debug("systimer iomap failed\n");
#if IS_ENABLED(CONFIG_MTK_TICK_BROADCAST_DEBUG)
systirq = irq_of_parse_and_map(np_systimer, 0);
if (systirq <= 0)
systimer_irq = 0;
else
systimer_irq = systirq;
#endif
init_wk_check_bit();
wdk_workqueue = create_singlethread_workqueue("mt-wdk");
INIT_WORK(&wdk_work, wdk_work_callback);
res = queue_work(wdk_workqueue, &wdk_work);
if (!res)
pr_info("[wdk]wdk_work start return:%d!\n", res);
wdt_pm_nb.notifier_call = wdt_pm_notify;
register_pm_notifier(&wdt_pm_nb);
if (systimer_base) {
uint64_t cnt;
uint32_t low;
low = readl(systimer_base + SYSTIMER_CNTCV_L);
cnt = readl(systimer_base + SYSTIMER_CNTCV_H);
cnt = cnt << 32 | low;
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
aee_rr_rec_wdk_systimer_cnt(cnt);
#endif
pr_info("%s systimer_cnt %lld\n", __func__, cnt);
cnt = sched_clock();
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
aee_rr_rec_wdk_ktime(cnt);
#endif
pr_info("%s set wdk_ktime %lld\n", __func__, cnt);
}
timer_setup(&aee_dump_timer, aee_dump_timer_func, 0);
return 0;
}
static void __exit hangdet_exit(void)
{
unregister_pm_notifier(&wdt_pm_nb);
kthread_stop((struct task_struct *)wk_tsk);
}
module_init(hangdet_init);
module_exit(hangdet_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mediatek inc.");
MODULE_DESCRIPTION("The cpu hang detector");
+37
View File
@@ -0,0 +1,37 @@
#
# Copyright (C) 2016 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 http://www.gnu.org/licenses/gpl-2.0.html for more details.
#
ifeq ($(CONFIG_MTK_GCOV_KERNEL),y)
GCOV_PROFILE := y
endif
subdir-ccflags-y += -Idrivers/misc/mediatek/mtprof/
subdir-ccflags-y += -Idrivers/misc/mediatek/
subdir-ccflags-y += -Idrivers/misc/mediatek/dbgtop/
ccflags-y += -DTEXT_OFFSET=$(TEXT_OFFSET)
obj-$(CONFIG_MTK_AEE_IPANIC) += mrdump.o
mrdump-y := \
mboot_params.o \
mrdump_control.o \
mrdump_hw.o \
mrdump_full.o \
mrdump_mini.o \
mrdump_panic.o \
mrdump_helper.o
mrdump-$(CONFIG_ARM) += mrdump_arm.o
mrdump-$(CONFIG_ARM64) += mrdump_arm64.o
KASAN_SANITIZE := n
@@ -0,0 +1,147 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
/*
* DF: for single variable
* DF_A: for array variable
* DF_S: for segmented single byte
* NOTE: fmt string must be less than FMT_MAX_LEN
*/
DF(fiq_step, " fiq step: %u "),
DF(exp_type, " exception type: %u\n"),
DF(kaslr_offset, "Kernel Offset: 0x%llx\n"),
DF(oops_in_progress_addr, "&oops_in_progress: 0x%llx\n"),
DF(kick, "kick=0x%x,"),
DF(check, "check=0x%x\n"),
DF(wdk_ktime, "wdk_ktime=%lld\n"),
DF(wdk_systimer_cnt, "wdk_systimer_cnt=%lld\n"),
/* ensure info related to HWT always be bottom and keep their order*/
DF(mcdi_wfi, "mcdi_wfi: 0x%x\n"),
DF(mcdi_r15, "mcdi_r15: 0x%x\n"),
DF(deepidle_data, "deepidle: 0x%x\n"),
DF(sodi3_data, "sodi3: 0x%x\n"),
DF(sodi_data, "sodi: 0x%x\n"),
DF(mcsodi_data, "mcsodi: 0x%x\n"),
DF(spm_suspend_data, "spm_suspend: 0x%x\n"),
DF(spm_common_scenario_data, "spm_common_scenario: 0x%x\n"),
DF_A(clk_data, "clk_data: 0x%x\n", 8),
DF(suspend_debug_flag, NULL/* not enabled */),
DF(fiq_cache_step, "fiq_cache_step: %d\n"),
DF(vcore_dvfs_opp, "vcore_dvfs_opp: 0x%x\n"),
DF(vcore_dvfs_status, "vcore_dvfs_status: 0x%x\n"),
DF_A(ppm_cluster_limit, "ppm_cluster_limit: 0x%08x\n", 8),
DF(ppm_step, "ppm_step: 0x%x\n"),
DF(ppm_cur_state, "ppm_cur_state: 0x%x\n"),
DF(ppm_min_pwr_bgt, "ppm_min_pwr_bgt: %d\n"),
DF(ppm_policy_mask, "ppm_policy_mask: 0x%x\n"),
DF(ppm_waiting_for_pbm, "ppm_waiting_for_pbm: 0x%x\n"),
DF(cpu_dvfs_vproc_big, "cpu_dvfs_vproc_big: 0x%x\n"),
DF(cpu_dvfs_vproc_little, "cpu_dvfs_vproc_little: 0x%x\n"),
DF(cpu_dvfs_oppidx, "cpu_dvfs_oppidx: 0x%x\n"),
DF(cpu_dvfs_cci_oppidx, "cpu_dvfs_oppidx: cci = 0x%x\n"),
DF(cpu_dvfs_status, "cpu_dvfs_status: 0x%x\n"),
DF(cpu_dvfs_step, "cpu_dvfs_step: 0x%x\n"),
DF(cpu_dvfs_pbm_step, "cpu_dvfs_pbm_step: 0x%x\n"),
DF(cpu_dvfs_cb, "cpu_dvfs_cb: 0x%x\n"),
DF(cpufreq_cb, "cpufreq_cb: 0x%x\n"),
DF(gpu_dvfs_vgpu, "gpu_dvfs_vgpu: 0x%x\n"),
DF(gpu_dvfs_oppidx, "gpu_dvfs_oppidx: 0x%x\n"),
DF(gpu_dvfs_status, "gpu_dvfs_status: 0x%x\n"),
DF(drcc_0, "drcc_0 = 0x%X\n"),
DF(drcc_1, "drcc_1 = 0x%X\n"),
DF(drcc_2, "drcc_2 = 0x%X\n"),
DF(drcc_3, "drcc_3 = 0x%X\n"),
DF(drcc_dbg_ret, "DRCC dbg info result: 0x%x\n"),
DF(drcc_dbg_off, "DRCC dbg info offset: 0x%x\n"),
DF(drcc_dbg_ts, "DRCC dbg info timestamp: 0x%llx\n"),
DF(ptp_devinfo_0, "EEM devinfo0 = 0x%X\n"),
DF(ptp_devinfo_1, "EEM devinfo1 = 0x%X\n"),
DF(ptp_devinfo_2, "EEM devinfo2 = 0x%X\n"),
DF(ptp_devinfo_3, "EEM devinfo3 = 0x%X\n"),
DF(ptp_devinfo_4, "EEM devinfo4 = 0x%X\n"),
DF(ptp_devinfo_5, "EEM devinfo5 = 0x%X\n"),
DF(ptp_devinfo_6, "EEM devinfo6 = 0x%X\n"),
DF(ptp_devinfo_7, "EEM devinfo7 = 0x%X\n"),
DF(ptp_e0, "M_HW_RES0 = 0x%X\n"),
DF(ptp_e1, "M_HW_RES1 = 0x%X\n"),
DF(ptp_e2, "M_HW_RES2 = 0x%X\n"),
DF(ptp_e3, "M_HW_RES3 = 0x%X\n"),
DF(ptp_e4, "M_HW_RES4 = 0x%X\n"),
DF(ptp_e5, "M_HW_RES5 = 0x%X\n"),
DF(ptp_e6, "M_HW_RES6 = 0x%X\n"),
DF(ptp_e7, "M_HW_RES7 = 0x%X\n"),
DF(ptp_e8, "M_HW_RES8 = 0x%X\n"),
DF(ptp_e9, "M_HW_RES9 = 0x%X\n"),
DF(ptp_e10, "M_HW_RESA = 0x%X\n"),
DF(ptp_e11, "M_HW_RESB = 0x%X\n"),
DF_S(ptp_vboot, "ptp_bank_[%d]_vboot = 0x%llx\n"),
DF_S(ptp_cpu_big_volt, "ptp_cpu_big_volt[%d] = %llx\n"),
DF_S(ptp_cpu_big_volt_1, "ptp_cpu_big_volt_1[%d] = %llx\n"),
DF_S(ptp_cpu_big_volt_2, "ptp_cpu_big_volt_2[%d] = %llx\n"),
DF_S(ptp_cpu_big_volt_3, "ptp_cpu_big_volt_3[%d] = %llx\n"),
DF_S(ptp_cpu_2_little_volt, "ptp_cpu_2_little_volt[%d] = %llx\n"),
DF_S(ptp_cpu_2_little_volt_1, "ptp_cpu_2_little_volt_1[%d] = %llx\n"),
DF_S(ptp_cpu_2_little_volt_2, "ptp_cpu_2_little_volt_2[%d] = %llx\n"),
DF_S(ptp_cpu_2_little_volt_3, "ptp_cpu_2_little_volt_3[%d] = %llx\n"),
DF_S(ptp_cpu_little_volt, "ptp_cpu_little_volt[%d] = %llx\n"),
DF_S(ptp_cpu_little_volt_1, "ptp_cpu_little_volt_1[%d] = %llx\n"),
DF_S(ptp_cpu_little_volt_2, "ptp_cpu_little_volt_2[%d] = %llx\n"),
DF_S(ptp_cpu_little_volt_3, "ptp_cpu_little_volt_3[%d] = %llx\n"),
DF_S(ptp_cpu_cci_volt, "ptp_cpu_cci_volt[%d] = %llx\n"),
DF_S(ptp_cpu_cci_volt_1, "ptp_cpu_cci_volt_1[%d] = %llx\n"),
DF_S(ptp_cpu_cci_volt_2, "ptp_cpu_cci_volt_2[%d] = %llx\n"),
DF_S(ptp_cpu_cci_volt_3, "ptp_cpu_cci_volt_3[%d] = %llx\n"),
DF_S(ptp_gpu_volt, "ptp_gpu_volt[%d] = %llx\n"),
DF_S(ptp_gpu_volt_1, "ptp_gpu_volt_1[%d] = %llx\n"),
DF_S(ptp_gpu_volt_2, "ptp_gpu_volt_2[%d] = %llx\n"),
DF_S(ptp_gpu_volt_3, "ptp_gpu_volt_3[%d] = %llx\n"),
DF_S(ptp_temp, "ptp_temp[%d] = %llx\n"),
DF(ptp_status, "ptp_status: 0x%x\n"),
DF(eem_pi_offset, "eem_pi_offset : 0x%x\n"),
DF(etc_status, "etc_status : 0x%x\n"),
DF(etc_mode, "etc_mode : 0x%x\n"),
DF_A(thermal_temp, "thermal_temp = %d\n", THERMAL_RESERVED_TZS),
DF(thermal_status, "thermal_status: %d\n"),
DF(thermal_ATM_status, "thermal_ATM_status: %d\n"),
DF(thermal_ktime, "thermal_ktime: %lld\n"),
DF(idvfs_ctrl_reg, "idvfs_ctrl_reg = 0x%x\n"),
DF(idvfs_enable_cnt, "idvfs_enable_cnt = %u\n"),
DF(idvfs_swreq_cnt, "idvfs_swreq_cnt = %u\n"),
DF(idvfs_curr_volt, "idvfs_curr_volt(raw) = 0x%x\n"),
DF(idvfs_sram_ldo, "idvfs_sram_ldo = %umv\n"),
DF(idvfs_swavg_curr_pct_x100, "idvfs_swavg_curr_pct_x100 = %u\n"),
DF(idvfs_swreq_curr_pct_x100, "idvfs_swreq_curr_pct_x100 = %u\n"),
DF(idvfs_swreq_next_pct_x100, "idvfs_swreq_next_pct_x100 = %u\n"),
DF(idvfs_state_manchine, "idvfs_state_manchine = 0x%x\n"),
DF_A(ocp_target_limit, "ocp_target_limit: %d\n", 4),
DF(ocp_enable, "ocp_enable = 0x%x\n"),
DF(scp_pc, "scp_pc: 0x%x\n"),
DF(scp_lr, "scp_lr: 0x%x\n"),
DF(hang_detect_timeout_count, "hang detect time out: 0x%x\n"),
DF(last_sync_func, "last sync function: 0x%lx\n"),
DF(last_async_func, "last async function: 0x%lx\n"),
DF(gz_irq, "GZ IRQ: 0x%x\n"),
/* kparams (unused) */
/* ensure info related to HWT always be bottom and keep their order*/
DF(last_init_func, "last init function: 0x%lx\n"),
DF(pmic_ext_buck, "pmic & external buck: 0x%x\n"),
DF(hps_cb_enter_times, "CPU HPS footprint: %llu, "),
DF(hps_cb_cpu_bitmask, "0x%x, "),
DF(hps_cb_footprint, "%d, "),
DF(hps_cb_fp_times, "%llu\n"),
DF(hotplug_cpu_event, "CPU notifier status: %d, "),
DF(hotplug_cb_index, "%d, "),
DF(hotplug_cb_fp, "0x%llx, "),
DF(hotplug_cb_times, "%llu\n"),
DF(cpu_caller, "CPU Hotplug: caller CPU%d, "),
DF(cpu_callee, "callee CPU%d\n"),
DF(cpu_up_prepare_ktime, "CPU_UP_PREPARE: %lld\n"),
DF(cpu_starting_ktime, "CPU_STARTING: %lld\n"),
DF(cpu_online_ktime, "CPU_ONLINE: %lld\n"),
DF(cpu_down_prepare_ktime, "CPU_DOWN_PREPARE: %lld\n"),
DF(cpu_dying_ktime, "CPU_DYING: %lld\n"),
DF(cpu_dead_ktime, "CPU_DEAD: %lld\n"),
DF(cpu_post_dead_ktime, "CPU_POST_DEAD: %lld\n"),
@@ -0,0 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
DF_PER_CPU(last_irq_enter, " irq: enter(%d, "),
DF_PER_CPU(jiffies_last_irq_enter, "%llu) "),
DF_PER_CPU(last_irq_exit, "quit(%d, "),
DF_PER_CPU(jiffies_last_irq_exit, "%llu)\n"),
DF_PER_CPU(hotplug_footprint, " hotplug: %d\n"),
DF_PER_CPU(mtk_cpuidle_footprint, " mtk_cpuidle_footprint: 0x%x\n"),
DF_PER_CPU(mcdi_footprint, " mcdi footprint: 0x%x\n"),
@@ -0,0 +1,178 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#define E_EX(member) e_rrr_##member
#define E_PER_CPU_EX(member) e_rrr_per_cpu_##member
#define DF(member, fmt) E_EX(member)
#define DF_A(member, fmt, total) E_EX(member)
#define DF_S(member, fmt) E_EX(member)
#define DF_PER_CPU(member, fmt) E_PER_CPU_EX(member)
enum {
#include "desc_def.h"
E_EX(num_total),
};
enum {
#include "desc_def_per_cpu.h"
E_PER_CPU_EX(num_total),
};
enum DESC_DATA_TYPE_SPECIAL {
D_SEG_SINGLE_BYTE = 0xabe,
D_SINGLE_VALUE = 0xaee,
D_PER_CPU_VALUE = 0xaed,
};
#define FMT_MAX_LEN 128
struct rrr_desc_data {
/* D_SINGLE_VARIABLE : single;
* D_PER_CPU_VALUE : per cpu;
* D_SEG_SINGLE_BYTE : segmented into single byte;
* > 0 : array
* == 0 : invalid
*/
uint32_t type;
/* offset in structure of last_reboot_reason */
uint32_t off;
/* varaible type e.g. char size=1; uint32_t size=4; uint64_t size=8; */
uint32_t size;
/* real size of fmt string for seq_printf */
uint32_t fmtsize;
char fmt[FMT_MAX_LEN];
};
struct rrr_desc {
uint32_t magic;
uint32_t version;
uint32_t off_pl;
uint32_t off_linux;
uint32_t off_desc_data;
uint32_t total;
uint32_t per_cpu_total;
uint32_t cpu_num;
uint32_t fmt_max_len;
uint32_t reserve[6];
uint32_t magic_end;
struct rrr_desc_data desc[E_EX(num_total)];
struct rrr_desc_data per_cpu_desc[E_PER_CPU_EX(num_total)];
};
#undef DF
#define DF(member, fmt) \
[E_EX(member)] = fmt
#undef DF_A
#define DF_A(member, fmt, total) \
[E_EX(member)] = fmt
#undef DF_S
#define DF_S(member, fmt) \
[E_EX(member)] = fmt
#undef DF_PER_CPU
#define DF_PER_CPU(member, fmt) \
[E_PER_CPU_EX(member)] = fmt
static char *buf[] = {
#include "desc_def.h"
};
static char *per_cpu_buf[] = {
#include "desc_def_per_cpu.h"
};
static struct last_reboot_reason dummy_var;
#define DF_C(type, member) { \
type, \
offsetof(struct last_reboot_reason, member), \
sizeof(typeof(dummy_var.member)) \
}
#undef DF
#define DF(member, fmt) \
[E_EX(member)] = DF_C(D_SINGLE_VALUE, member)
#undef DF_A
#define DF_A(member, fmt, total) \
[E_EX(member)] = DF_C(total, member[0])
#undef DF_S
#define DF_S(member, fmt) \
[E_EX(member)] = DF_C(D_SEG_SINGLE_BYTE, member)
#undef DF_PER_CPU
#define DF_PER_CPU(member, fmt) \
[E_PER_CPU_EX(member)] = DF_C(D_PER_CPU_VALUE, member[0])
static struct rrr_desc /*__maybe_unused*/ idesc_init = {
REBOOT_REASON_SIG,
0x100,
sizeof(struct mboot_params_buffer),
0x0,
(offsetof(struct rrr_desc, desc)),
E_EX(num_total),
E_PER_CPU_EX(num_total),
AEE_MTK_CPU_NUMS,
FMT_MAX_LEN,
{0},
REBOOT_REASON_SIG,
{
#include "desc_def.h"
},
/* per cpu */
{
#include "desc_def_per_cpu.h"
}
};
static struct rrr_desc *idesc;
#define IDESC_ADDR ((unsigned long)idesc)
#define IDESC_SIZE (sizeof(struct rrr_desc))
static uint32_t start_pos;
#define IDESC_START_POS ((unsigned long)&start_pos)
static int mboot_params_init_desc(uint32_t off_linux)
{
int i;
size_t len;
idesc = kzalloc(IDESC_SIZE, GFP_KERNEL);
if (!idesc)
return -1;
memcpy(idesc, &idesc_init, IDESC_SIZE);
idesc->off_linux = off_linux;
idesc->cpu_num = nr_cpu_ids;
for (i = 0; i < E_EX(num_total); i++) {
if (buf[i]) {
len = strlen(buf[i]);
if (len < FMT_MAX_LEN) {
strncpy(idesc->desc[i].fmt,
buf[i], FMT_MAX_LEN);
idesc->desc[i].fmt[FMT_MAX_LEN - 1] = '\0';
idesc->desc[i].fmtsize = len;
} else {
/* idesc->desc[i].size = i; */
idesc->desc[i].type = 0x0;
}
} else {
/* idesc->desc[i].size = i; */
idesc->desc[i].type = 0x0;
}
}
for (i = 0; i < E_PER_CPU_EX(num_total); i++) {
if (per_cpu_buf[i]) {
len = strlen(per_cpu_buf[i]);
if (len < FMT_MAX_LEN) {
strncpy(idesc->per_cpu_desc[i].fmt,
per_cpu_buf[i], FMT_MAX_LEN);
idesc->per_cpu_desc[i].fmt[FMT_MAX_LEN - 1] =
'\0';
idesc->per_cpu_desc[i].fmtsize =
strlen(idesc->per_cpu_desc[i].fmt);
} else {
/* idesc->per_cpu_desc[i].size = i; */
idesc->per_cpu_desc[i].type = 0x0;
}
} else {
/* idesc->per_cpu_desc[i].size = i; */
idesc->per_cpu_desc[i].type = 0x0;
}
}
return 0;
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef __MBOOT_PARAMS_INTERNAL_H__
#define __MBOOT_PARAMS_INTERNAL_H__
#define MBOOT_PARAMS_EXP_TYPE_MAGIC 0xaeedead0
#define MBOOT_PARAMS_EXP_TYPE_DEC(exp_type) \
((exp_type ^ MBOOT_PARAMS_EXP_TYPE_MAGIC) < 16 ? \
exp_type ^ MBOOT_PARAMS_EXP_TYPE_MAGIC : exp_type)
extern u32 scp_dump_pc(void);
extern u32 scp_dump_lr(void);
#endif
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#include <linux/bug.h>
#include <linux/compiler.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/ptrace.h>
#include <mt-plat/mrdump.h>
#include "mrdump_private.h"
void mrdump_save_control_register(void *creg)
{
struct arm32_ctrl_regs *cregs = (struct arm32_ctrl_regs *)creg;
asm volatile ("mrc p15, 0, %0, c1, c0, 0\n\t"
"mrc p15, 0, %1, c2, c0, 2\n\t"
"mrc p15, 0, %2, c2, c0, 0\n\t"
"mrc p15, 0, %3, c2, c0, 1\n\t"
: "=r"(cregs->sctlr), "=r"(cregs->ttbcr),
"=r"(cregs->ttbr0), "=r"(cregs->ttbr1) : : "memory");
}
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#include <linux/ptrace.h>
#include <asm/stacktrace.h>
#include <asm/system_misc.h>
#include <mt-plat/mrdump.h>
#include "mrdump_private.h"
void mrdump_save_control_register(void *creg)
{
struct aarch64_ctrl_regs *cregs = (struct aarch64_ctrl_regs *)creg;
u64 tmp;
asm volatile ("mrs %0, sctlr_el1\n\t"
"mrs %1, tcr_el1\n\t"
"mrs %2, ttbr0_el1\n\t"
"mrs %3, ttbr1_el1\n\t"
"mrs %4, sp_el0\n\t"
"mov %5, sp\n\t"
: "=&r"(tmp), "=r"(cregs->tcr_el1),
"=r"(cregs->ttbr0_el1), "=r"(cregs->ttbr1_el1),
"=r"(cregs->sp_el[0]), "=r"(cregs->sp_el[1])
: : "memory");
cregs->sctlr_el1 = (uint64_t) tmp;
}
@@ -0,0 +1,136 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#include <linux/bug.h>
#include <linux/crc32.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/memblock.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <asm/memory.h>
#include <asm/sections.h>
#include <mt-plat/mrdump.h>
#include "mrdump_private.h"
struct mrdump_control_block *mrdump_cblock;
#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_KALLSYMS_BASE_RELATIVE)
static void mrdump_cblock_kallsyms_init(struct mrdump_ksyms_param *kparam)
{
unsigned long start_addr = (unsigned long) &kallsyms_addresses;
kparam->tag[0] = 'K';
kparam->tag[1] = 'S';
kparam->tag[2] = 'Y';
kparam->tag[3] = 'M';
switch (sizeof(unsigned long)) {
case 4:
kparam->flag = KSYM_32;
break;
case 8:
kparam->flag = KSYM_64;
break;
default:
BUILD_BUG();
}
kparam->start_addr = __pa_symbol(start_addr);
kparam->size = (unsigned long)&kallsyms_token_index - start_addr + 512;
kparam->crc = crc32(0, (unsigned char *)start_addr, kparam->size);
kparam->addresses_off = (unsigned long)&kallsyms_addresses - start_addr;
kparam->num_syms_off = (unsigned long)&kallsyms_num_syms - start_addr;
kparam->names_off = (unsigned long)&kallsyms_names - start_addr;
kparam->markers_off = (unsigned long)&kallsyms_markers - start_addr;
kparam->token_table_off =
(unsigned long)&kallsyms_token_table - start_addr;
kparam->token_index_off =
(unsigned long)&kallsyms_token_index - start_addr;
}
#else
static void mrdump_cblock_kallsyms_init(struct mrdump_ksyms_param *unused)
{
}
#endif
__init void mrdump_cblock_init(phys_addr_t cb_addr, phys_addr_t cb_size)
{
struct mrdump_machdesc *machdesc_p;
if (cb_addr == 0) {
pr_notice("%s: mrdump control address cannot be 0\n",
__func__);
return;
}
if (cb_size < sizeof(struct mrdump_control_block)) {
pr_notice("%s: not enough space for mrdump control block\n",
__func__);
return;
}
mrdump_cblock = ioremap_wc(cb_addr, cb_size);
if (!mrdump_cblock) {
pr_notice("%s: mrdump_cb not mapped\n", __func__);
return;
}
memset_io(mrdump_cblock, 0, sizeof(struct mrdump_control_block));
memcpy_toio(mrdump_cblock->sig, MRDUMP_GO_DUMP,
sizeof(mrdump_cblock->sig));
machdesc_p = &mrdump_cblock->machdesc;
machdesc_p->nr_cpus = nr_cpu_ids;
machdesc_p->page_offset = (uint64_t)PAGE_OFFSET;
machdesc_p->high_memory = (uintptr_t)high_memory;
#if defined(KIMAGE_VADDR)
machdesc_p->kimage_vaddr = KIMAGE_VADDR;
#endif
#if defined(TEXT_OFFSET)
machdesc_p->kimage_vaddr += TEXT_OFFSET;
#endif
machdesc_p->dram_start = (uint64_t)aee_memblock_start_of_DRAM();
machdesc_p->dram_end = (uint64_t)aee_memblock_end_of_DRAM();
machdesc_p->kimage_stext = (uint64_t)aee_get_text();
machdesc_p->kimage_etext = (uint64_t)aee_get_etext();
machdesc_p->kimage_stext_real = (uint64_t)aee_get_stext();
#if defined(CONFIG_ARM64)
machdesc_p->kimage_voffset = kimage_voffset;
#endif
machdesc_p->vmalloc_start = (uint64_t)VMALLOC_START;
machdesc_p->vmalloc_end = (uint64_t)VMALLOC_END;
machdesc_p->modules_start = (uint64_t)MODULES_VADDR;
machdesc_p->modules_end = (uint64_t)MODULES_END;
machdesc_p->phys_offset = (uint64_t)(phys_addr_t)PHYS_OFFSET;
if (virt_addr_valid(aee_get_swapper_pg_dir())) {
machdesc_p->master_page_table =
(uintptr_t)__pa(aee_get_swapper_pg_dir());
} else {
machdesc_p->master_page_table =
(uintptr_t)__pa_symbol(aee_get_swapper_pg_dir());
}
#if defined(CONFIG_SPARSEMEM_VMEMMAP)
machdesc_p->memmap = (uintptr_t)vmemmap;
#endif
machdesc_p->pageflags = (1UL << PG_uptodate) + (1UL << PG_dirty) +
(1UL << PG_lru) + (1UL << PG_writeback);
machdesc_p->struct_page_size = (uint32_t)sizeof(struct page);
mrdump_cblock_kallsyms_init(&machdesc_p->kallsyms);
mrdump_cblock->machdesc_crc = crc32(0, machdesc_p,
sizeof(struct mrdump_machdesc));
pr_notice("%s: done.\n", __func__);
/* TODO: remove flush APIs after full ramdump support HW_Reboot*/
aee__flush_dcache_area(mrdump_cblock,
sizeof(struct mrdump_control_block));
}
@@ -0,0 +1,136 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#include <stdarg.h>
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/processor.h>
#include <mt-plat/mboot_params.h>
#include <mrdump.h>
#include "mrdump_private.h"
static unsigned long mrdump_output_lbaooo;
void __mrdump_create_oops_dump(enum AEE_REBOOT_MODE reboot_mode,
struct pt_regs *regs, const char *msg, ...)
{
va_list ap;
struct mrdump_crash_record *crash_record;
void *creg;
int cpu;
elf_gregset_t *reg;
if (mrdump_cblock) {
crash_record = &mrdump_cblock->crash_record;
local_irq_disable();
cpu = get_HW_cpuid();
if (cpu < 0 || cpu >= nr_cpu_ids)
return;
switch (sizeof(unsigned long)) {
case 4:
reg = (elf_gregset_t *)&crash_record->cpu_reg[cpu].arm32_reg.arm32_regs;
creg = (void *)&crash_record->cpu_reg[cpu].arm32_reg.arm32_creg;
break;
case 8:
reg = (elf_gregset_t *)&crash_record->cpu_reg[cpu].arm64_reg.arm64_regs;
creg = (void *)&crash_record->cpu_reg[cpu].arm64_reg.arm64_creg;
break;
default:
BUILD_BUG();
}
if (cpu >= 0 && cpu < nr_cpu_ids) {
/* null regs, no register dump */
if (regs)
elf_core_copy_kernel_regs(reg, regs);
mrdump_save_control_register(creg);
}
va_start(ap, msg);
vsnprintf(crash_record->msg, sizeof(crash_record->msg), msg,
ap);
va_end(ap);
crash_record->fault_cpu = cpu;
/* FIXME: Check reboot_mode is valid */
crash_record->reboot_mode = reboot_mode;
}
}
#if IS_ENABLED(CONFIG_SYSFS)
static ssize_t mrdump_version_show(struct kobject *kobj,
struct kobj_attribute *kattr, char *buf)
{
return snprintf(buf, PAGE_SIZE, "%s", MRDUMP_GO_DUMP);
}
static struct kobj_attribute mrdump_version_attribute =
__ATTR(mrdump_version, 0400, mrdump_version_show, NULL);
static struct attribute *attrs[] = {
&mrdump_version_attribute.attr,
NULL,
};
static struct attribute_group attr_group = {
.attrs = attrs,
};
#endif
int __init mrdump_full_init(void)
{
mrdump_cblock->enabled = MRDUMP_ENABLE_COOKIE;
/* TODO: remove flush APIs after full ramdump support HW_Reboot*/
aee__flush_dcache_area(mrdump_cblock,
sizeof(struct mrdump_control_block));
pr_info("%s: MT-RAMDUMP enabled done\n", __func__);
#if IS_ENABLED(CONFIG_SYSFS)
if (sysfs_create_group(kernel_kobj, &attr_group)) {
pr_notice("MT-RAMDUMP: sysfs create sysfs failed\n");
return -ENOMEM;
}
#endif
return 0;
}
static int param_set_mrdump_lbaooo(const char *val,
const struct kernel_param *kp)
{
int retval = 0;
if (mrdump_cblock) {
retval = param_set_ulong(val, kp);
if (!retval) {
mrdump_cblock->output_fs_lbaooo = mrdump_output_lbaooo;
/* TODO: remove flush APIs after full ramdump support HW_Reboot*/
aee__flush_dcache_area(mrdump_cblock,
sizeof(struct mrdump_control_block));
}
}
return retval;
}
/* sys/modules/mrdump/parameter/lbaooo */
struct kernel_param_ops param_ops_mrdump_lbaooo = {
.set = param_set_mrdump_lbaooo,
.get = param_get_ulong,
};
param_check_ulong(lbaooo, &mrdump_output_lbaooo);
/* 0644: S_IRUGO | S_IWUSR */
module_param_cb(lbaooo, &param_ops_mrdump_lbaooo, &mrdump_output_lbaooo,
0644);
__MODULE_PARM_TYPE(lbaooo, "ulong");
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("MediaTek MRDUMP module");
MODULE_AUTHOR("MediaTek Inc.");
@@ -0,0 +1,720 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#include <linux/init.h>
#include <linux/memblock.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/of_fdt.h>
#include <linux/percpu.h>
#include "../../../../kernel/sched/sched.h"
#include <asm/memory.h>
#include <asm/pgtable.h>
#include <asm/sections.h>
#include <asm/smp_plat.h>
#include <asm/stacktrace.h>
#include <asm/system_misc.h>
#include <mt-plat/aee.h>
struct module_sect_attr {
struct module_attribute mattr;
char *name;
unsigned long address;
};
struct module_sect_attrs {
struct attribute_group grp;
unsigned int nsections;
struct module_sect_attr attrs[0];
};
#ifdef MODULE
struct aee_sym {
char name[KSYM_NAME_LEN];
unsigned long addr;
};
static int (*aee_koes)(int (*fn)(void *, const char *,
struct module *,
unsigned long),
void *data);
static int addr_ok(void *data, const char *namebuf,
struct module *mod, unsigned long addr)
{
struct aee_sym *aee_sym = (struct aee_sym *)data;
if (strcmp(namebuf, aee_sym->name) == 0) {
aee_sym->addr = addr;
return 1;
}
return 0;
}
#define SYM_PT "kallsyms_on_each_symbol+0x%X/0x%X"
#define FIX_OFF 0x72C
static void find_koes(void)
{
char namebuf[KSYM_NAME_LEN] = {0};
unsigned long addr_tmp = (unsigned long)sprint_symbol;
int off;
int fsize;
int ret;
if (aee_koes)
return;
addr_tmp -= FIX_OFF;
sprint_symbol(namebuf, addr_tmp);
ret = sscanf(namebuf, SYM_PT, &off, &fsize);
if (ret == 2) {
if (off > 0 && off <= fsize)
addr_tmp -= off;
aee_koes = (void *)addr_tmp;
return;
}
}
static int need_init = 1;
unsigned long aee_addr_find(const char *name)
{
struct aee_sym sym;
if (need_init) {
need_init = 0;
find_koes();
}
if (!aee_koes)
return 0;
memset(&sym, 0x0, sizeof(sym));
if (snprintf(sym.name, sizeof(sym.name), "%s", name) < 0)
return 0;
if (aee_koes(addr_ok, (void *)(&sym)))
return sym.addr;
return 0;
}
EXPORT_SYMBOL(aee_addr_find);
/* for mrdump.ko */
static void (*p_show_regs)(struct pt_regs *);
void aee_show_regs(struct pt_regs *regs)
{
if (p_show_regs) {
p_show_regs(regs);
return;
}
p_show_regs = (void *)aee_addr_find("__show_regs");
if (!p_show_regs)
pr_info("%s failed", __func__);
else
p_show_regs(regs);
}
#ifdef CONFIG_ARM64
static int (*p_unwind_frame)(struct task_struct *tsk,
struct stackframe *frame);
int aee_unwind_frame(struct task_struct *tsk, struct stackframe *frame)
{
if (p_unwind_frame)
return p_unwind_frame(tsk, frame);
p_unwind_frame = (void *)aee_addr_find("unwind_frame");
if (p_unwind_frame)
return p_unwind_frame(tsk, frame);
pr_info("%s failed", __func__);
return -1;
}
#else
static int (*p_unwind_frame)(struct stackframe *frame);
int aee_unwind_frame(struct stackframe *frame)
{
if (p_unwind_frame)
return p_unwind_frame(frame);
p_unwind_frame = (void *)aee_addr_find("unwind_frame");
if (p_unwind_frame)
return p_unwind_frame(frame);
pr_info("%s failed", __func__);
return -1;
}
#endif
static unsigned long p_stext;
unsigned long aee_get_stext(void)
{
if (p_stext != 0)
return p_stext;
p_stext = aee_addr_find("_stext");
if (p_stext == 0)
pr_info("%s failed", __func__);
return p_stext;
}
static unsigned long p_etext;
unsigned long aee_get_etext(void)
{
if (p_etext != 0)
return p_etext;
p_etext = aee_addr_find("_etext");
if (p_etext == 0)
pr_info("%s failed", __func__);
return p_etext;
}
static unsigned long p_text;
unsigned long aee_get_text(void)
{
if (p_text != 0)
return p_text;
p_text = aee_addr_find("_text");
if (p_text == 0)
pr_info("%s failed", __func__);
return p_text;
}
#if defined(CONFIG_ARM64)
static unsigned long *p_kimage_vaddr;
unsigned long aee_get_kimage_vaddr(void)
{
if (p_kimage_vaddr)
return *p_kimage_vaddr;
p_kimage_vaddr = (void *)aee_addr_find("kimage_vaddr");
if (!p_kimage_vaddr) {
pr_info("%s failed", __func__);
return 0;
}
return *p_kimage_vaddr;
}
#endif
static phys_addr_t (*p_memblock_start_of_DRAM)(void);
phys_addr_t aee_memblock_start_of_DRAM(void)
{
if (p_memblock_start_of_DRAM)
return p_memblock_start_of_DRAM();
p_memblock_start_of_DRAM =
(void *)aee_addr_find("memblock_start_of_DRAM");
if (p_memblock_start_of_DRAM)
return p_memblock_start_of_DRAM();
pr_info("%s failed", __func__);
return 0;
}
static phys_addr_t (*p_memblock_end_of_DRAM)(void);
phys_addr_t aee_memblock_end_of_DRAM(void)
{
if (p_memblock_end_of_DRAM)
return p_memblock_end_of_DRAM();
p_memblock_end_of_DRAM = (void *)aee_addr_find("memblock_end_of_DRAM");
if (p_memblock_end_of_DRAM)
return p_memblock_end_of_DRAM();
pr_info("%s failed", __func__);
return 0;
}
static void (*p_print_modules)(void);
void aee_print_modules(void)
{
if (p_print_modules) {
p_print_modules();
return;
}
p_print_modules = (void *)aee_addr_find("print_modules");
if (!p_print_modules) {
pr_info("%s failed", __func__);
return;
}
p_print_modules();
}
static struct list_head *p_modules;
/* MUST ensure called when preempt disabled already */
int aee_save_modules(char *mbuf, int mbufsize)
{
struct module *mod;
int sz = 0;
unsigned long text_addr = 0;
unsigned long init_addr = 0;
int i, search_nm;
if (!mbuf || mbufsize <= 0) {
pr_info("mrdump: module info buffer wrong(sz:%d)\n", mbufsize);
return sz;
}
if (!p_modules)
p_modules = (void *)aee_addr_find("modules");
if (!p_modules) {
pr_info("%s failed", __func__);
return sz;
}
memset(mbuf, '\0', mbufsize);
sz += snprintf(mbuf + sz, mbufsize - sz, "Modules linked in:");
list_for_each_entry_rcu(mod, p_modules, list) {
if (mod->state == MODULE_STATE_UNFORMED)
continue;
if (sz >= mbufsize) {
pr_info("mrdump: module info buffer full(sz:%d)\n",
mbufsize);
break;
}
text_addr = (unsigned long)mod->core_layout.base;
init_addr = (unsigned long)mod->init_layout.base;
search_nm = 2;
for (i = 0; i < mod->sect_attrs->nsections; i++) {
if (!strcmp(mod->sect_attrs->attrs[i].name, ".text")) {
text_addr = mod->sect_attrs->attrs[i].address;
search_nm--;
} else if (!strcmp(mod->sect_attrs->attrs[i].name,
".init.text")) {
init_addr = mod->sect_attrs->attrs[i].address;
search_nm--;
}
if (!search_nm)
break;
}
sz += snprintf(mbuf + sz, mbufsize - sz,
" %s %lx %lx %d %d",
mod->name,
text_addr,
init_addr,
mod->core_layout.size,
mod->init_layout.size);
}
if (sz < mbufsize)
sz += snprintf(mbuf + sz, mbufsize - sz, "\n");
return sz;
}
#ifdef __aarch64__
static u64 *p__cpu_logical_map;
static u64 *aee_cpu_logical_map(void)
#else
static u32 *p__cpu_logical_map;
static u32 *aee_cpu_logical_map(void)
#endif
{
if (p__cpu_logical_map)
return p__cpu_logical_map;
p__cpu_logical_map = (void *)aee_addr_find("__cpu_logical_map");
if (p__cpu_logical_map)
return p__cpu_logical_map;
return NULL;
}
int get_HW_cpuid(void)
{
u64 mpidr;
int cpu;
if (!aee_cpu_logical_map())
return -EINVAL;
mpidr = read_cpuid_mpidr();
/*
* NOTICE: the logic of following code sould be the same with
* get_logical_index() of linux kenrel
*/
mpidr &= MPIDR_HWID_BITMASK;
for (cpu = 0; cpu < nr_cpu_ids; cpu++)
if (p__cpu_logical_map[cpu] == mpidr)
return cpu;
return -EINVAL;
}
EXPORT_SYMBOL(get_HW_cpuid);
u32 aee_log_buf_len_get(void)
{
u32 log_buf_len = 1 << CONFIG_LOG_BUF_SHIFT;
if (log_buf_len > 0 && log_buf_len <= (1 << 25))
return log_buf_len;
return 0;
}
static char *p__log_buf;
char *aee_log_buf_addr_get(void)
{
if (p__log_buf)
return p__log_buf;
p__log_buf = (void *)(aee_addr_find("__log_buf"));
if (p__log_buf)
return p__log_buf;
pr_info("%s failed", __func__);
return NULL;
}
EXPORT_SYMBOL(aee_log_buf_addr_get);
#ifdef __aarch64__
static unsigned long *p_irq_stack_ptr;
static unsigned long *aee_irq_stack_ptr(void)
{
if (p_irq_stack_ptr)
return p_irq_stack_ptr;
p_irq_stack_ptr = (void *)aee_addr_find("irq_stack_ptr");
if (!p_irq_stack_ptr) {
pr_info("%s failed", __func__);
return NULL;
}
return p_irq_stack_ptr;
}
/* NOTICE: this function should be the same with on_irq_stack() */
bool aee_on_irq_stack(unsigned long sp, struct stack_info *info)
{
unsigned long *isp = aee_irq_stack_ptr();
unsigned long low, high;
if (!isp)
return false;
low = (unsigned long)raw_cpu_read(*isp);
high = low + IRQ_STACK_SIZE;
if (!low)
return false;
if (sp < low || sp >= high)
return false;
if (info) {
info->low = low;
info->high = high;
info->type = STACK_TYPE_IRQ;
}
return true;
}
#endif
static struct mm_struct *p_init_mm;
static struct mm_struct *aee_init_mm(void)
{
if (p_init_mm)
return p_init_mm;
p_init_mm = (void *)aee_addr_find("init_mm");
if (!p_init_mm) {
pr_info("%s failed", __func__);
return NULL;
}
return p_init_mm;
}
pgd_t *aee_pgd_offset_k(unsigned long addr)
{
struct mm_struct *pim = aee_init_mm();
if (!pim)
return NULL;
return (pgd_t *)pgd_offset(pim, addr);
}
static struct rq *p_runqueues;
static struct rq *aee_runqueues(void)
{
if (p_runqueues)
return p_runqueues;
p_runqueues = (void *)aee_addr_find("runqueues");
if (!p_runqueues) {
pr_info("%s failed", __func__);
return NULL;
}
return p_runqueues;
}
unsigned long aee_cpu_rq(int cpu)
{
struct rq *p_runqueues = aee_runqueues();
if (p_runqueues)
return (unsigned long)(&per_cpu(*p_runqueues, (cpu)));
return 0;
}
struct task_struct *aee_cpu_curr(int cpu)
{
struct rq *rq = (struct rq *)aee_cpu_rq(cpu);
if (rq)
return (struct task_struct *)(rq->curr);
return NULL;
}
unsigned long aee_get_swapper_pg_dir(void)
{
/* FIX ME: symbol in *ABS* section */
return 0;
}
unsigned long aee_get_kallsyms_addresses(void)
{
/* FIX ME: symbol in *UND* section */
return 0;
}
static void (*p__flush_dcache_area)(void *addr, size_t len);
void aee__flush_dcache_area(void *addr, size_t len)
{
if (p__flush_dcache_area) {
p__flush_dcache_area(addr, len);
return;
}
p__flush_dcache_area = (void *)aee_addr_find("__flush_dcache_area");
if (!p__flush_dcache_area) {
pr_info("%s failed", __func__);
return;
}
p__flush_dcache_area(addr, len);
}
raw_spinlock_t *p_logbuf_lock;
struct semaphore *p_console_sem;
void aee_zap_locks(void)
{
if (!p_logbuf_lock) {
p_logbuf_lock = (void *)aee_addr_find("logbuf_lock");
if (!p_logbuf_lock) {
aee_sram_printk("%s failed to get logbuf lock\n",
__func__);
return;
}
}
if (!p_console_sem) {
p_console_sem = (void *)aee_addr_find("console_sem");
if (!p_console_sem) {
aee_sram_printk("%s failed to get console_sem\n",
__func__);
return;
}
}
debug_locks_off();
/* If a crash is occurring, make sure we can't deadlock */
raw_spin_lock_init(p_logbuf_lock);
/* And make sure that we print immediately */
sema_init(p_console_sem, 1);
}
static raw_spinlock_t *p_die_lock;
void aee_reinit_die_lock(void)
{
if (!p_die_lock) {
p_die_lock = (void *)aee_addr_find("die_lock");
if (!p_die_lock) {
aee_sram_printk("%s failed to get die_lock\n",
__func__);
return;
}
}
/* If a crash is occurring, make sure we not deadlock */
raw_spin_lock_init(p_die_lock);
}
/* for aee_aed.ko */
static const char *(*p_arch_vma_name)(struct vm_area_struct *vma);
const char *aee_arch_vma_name(struct vm_area_struct *vma)
{
if (p_arch_vma_name)
return p_arch_vma_name(vma);
p_arch_vma_name = (void *)aee_addr_find("arch_vma_name");
if (p_arch_vma_name)
return p_arch_vma_name(vma);
pr_info("%s failed", __func__);
return NULL;
}
EXPORT_SYMBOL(aee_arch_vma_name);
#else /* #ifdef MODULE*/
/* for mrdump.ko */
void aee_show_regs(struct pt_regs *regs)
{
__show_regs(regs);
}
#ifdef CONFIG_ARM64
int aee_unwind_frame(struct task_struct *tsk, struct stackframe *frame)
{
return unwind_frame(tsk, frame);
}
#else
int aee_unwind_frame(struct stackframe *frame)
{
return unwind_frame(frame);
}
#endif
unsigned long aee_get_stext(void)
{
return (unsigned long)_stext;
}
unsigned long aee_get_etext(void)
{
return (unsigned long)_etext;
}
unsigned long aee_get_text(void)
{
return (unsigned long)_text;
}
#if defined(CONFIG_ARM64)
unsigned long aee_get_kimage_vaddr(void)
{
return (unsigned long)kimage_vaddr;
}
#endif
phys_addr_t aee_memblock_start_of_DRAM(void)
{
return memblock_start_of_DRAM();
}
phys_addr_t aee_memblock_end_of_DRAM(void)
{
return memblock_end_of_DRAM();
}
void aee_print_modules(void)
{
print_modules();
}
extern int save_modules(char *mbuf, int mbufsize);
/* MUST ensure called when preempt disabled already */
int aee_save_modules(char *mbuf, int mbufsize)
{
return save_modules(mbuf, mbufsize);
}
int get_HW_cpuid(void)
{
u64 mpidr;
mpidr = read_cpuid_mpidr();
return get_logical_index(mpidr & MPIDR_HWID_BITMASK);
}
u32 aee_log_buf_len_get(void)
{
return log_buf_len_get();
}
char *aee_log_buf_addr_get(void)
{
return log_buf_addr_get();
}
#ifdef __aarch64__
bool aee_on_irq_stack(unsigned long sp, struct stack_info *info)
{
return on_irq_stack(sp, info);
}
#endif
pgd_t *aee_pgd_offset_k(unsigned long addr)
{
return (pgd_t *)pgd_offset_k(addr);
}
unsigned long aee_cpu_rq(int cpu)
{
return (unsigned long)cpu_rq(cpu);
}
struct task_struct *aee_cpu_curr(int cpu)
{
return (struct task_struct *)cpu_curr(cpu);
}
unsigned long aee_get_swapper_pg_dir(void)
{
return (unsigned long)(&swapper_pg_dir);
}
extern const unsigned long kallsyms_addresses[] __weak;
unsigned long aee_get_kallsyms_addresses(void)
{
return (unsigned long)&kallsyms_addresses;
}
/* workaround for 32bit kernel, waiting for cache implement */
__weak void __flush_dcache_area(void *addr, size_t len)
{
pr_info("%s weak function", __func__);
}
extern void __flush_dcache_area(void *addr, size_t len);
void aee__flush_dcache_area(void *addr, size_t len)
{
__flush_dcache_area(addr, len);
}
void aee_zap_locks(void)
{
aee_wdt_zap_locks();
}
static raw_spinlock_t *p_die_lock;
void aee_reinit_die_lock(void)
{
if (!p_die_lock) {
p_die_lock = (void *)kallsyms_lookup_name("die_lock");
if (!p_die_lock) {
aee_sram_printk("%s failed to get die_lock\n",
__func__);
return;
}
}
/* If a crash is occurring, make sure we not deadlock */
raw_spin_lock_init(p_die_lock);
}
/* for aee_aed.ko */
const char *aee_arch_vma_name(struct vm_area_struct *vma)
{
return arch_vma_name(vma);
}
EXPORT_SYMBOL(aee_arch_vma_name);
#endif
@@ -0,0 +1,46 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#ifndef __aee_helper_h
#define __aee_helper_h
#include <asm/stacktrace.h>
/* for aee_aed.ko */
extern const char *aee_arch_vma_name(struct vm_area_struct *vma);
/* for mrdump.ko */
extern unsigned long aee_get_stext(void);
extern unsigned long aee_get_etext(void);
extern unsigned long aee_get_text(void);
#if defined(CONFIG_ARM64)
extern unsigned long aee_get_kimage_vaddr(void);
#endif
#ifdef CONFIG_ARM64
extern int aee_unwind_frame(struct task_struct *tsk, struct stackframe *frame);
#else
extern int aee_unwind_frame(struct stackframe *frame);
#endif
extern u32 aee_log_buf_len_get(void);
extern char *aee_log_buf_addr_get(void);
extern phys_addr_t aee_memblock_start_of_DRAM(void);
extern phys_addr_t aee_memblock_end_of_DRAM(void);
extern unsigned long aee_get_swapper_pg_dir(void);
#ifdef __aarch64__
extern bool aee_on_irq_stack(unsigned long sp, struct stack_info *info);
#endif
extern void aee_print_modules(void);
extern int aee_save_modules(char *mbuf, int mbufsize);
extern void aee_show_regs(struct pt_regs *regs);
extern pgd_t *aee_pgd_offset_k(unsigned long addr);
extern unsigned long aee_cpu_rq(int cpu);
extern struct task_struct *aee_cpu_curr(int cpu);
extern int get_HW_cpuid(void);
extern unsigned long aee_get_kallsyms_addresses(void);
extern void aee__flush_dcache_area(void *addr, size_t len);
extern void aee_zap_locks(void);
extern void aee_reinit_die_lock(void);
#endif
@@ -0,0 +1,95 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#include <linux/kconfig.h>
#include <linux/module.h>
#include <linux/string.h>
#include "mrdump_private.h"
#include <mrdump.h>
#if IS_ENABLED(CONFIG_MTK_DFD_INTERNAL_DUMP)
#include <mtk_platform_debug.h>
#endif
#if IS_ENABLED(CONFIG_MTK_DBGTOP)
#include <dbgtop.h>
#else
#if IS_ENABLED(CONFIG_MTK_WATCHDOG)
#include <mtk_wd_api.h>
#endif
#endif
#if IS_ENABLED(CONFIG_MTK_DBGTOP)
static void mrdump_dbgtop_dram_reserved(bool drm_ready)
{
int res;
if (drm_ready == true) {
pr_notice("%s: Trying to enable DDR Reserve Mode(%d)\n",
__func__, drm_ready);
res = mtk_dbgtop_dram_reserved(drm_ready);
if (res == 0) {
pr_notice("%s: DDR reserved mode enable ok\n",
__func__);
} else {
pr_notice("%s: mtk_dbgtop_dram_reserved error(%d)\n",
__func__, res);
}
} else {
pr_notice("%s: DDR Reserve Mode disabled.(%d)\n",
__func__, drm_ready);
}
}
#else
#if IS_ENABLED(CONFIG_MTK_WATCHDOG)
static void mrdump_wd_dram_reserved_mode(bool drm_ready)
{
int res;
struct wd_api *wd_api;
res = get_wd_api(&wd_api);
if (res < 0) {
pr_notice("%s: get wd api error (%d)\n", __func__, res);
} else {
if (drm_ready) {
res = wd_api->wd_dram_reserved_mode(drm_ready);
pr_notice("%s: DDR reserved mode enabled\n",
__func__);
} else {
pr_notice("%s: DDR reserved mode not ready, disabled\n",
__func__);
}
pr_notice("%s: config is not enabled yet\n", __func__);
}
}
#endif
#endif
int __init mrdump_hw_init(bool drm_ready)
{
#if IS_ENABLED(CONFIG_MTK_DBGTOP)
mrdump_dbgtop_dram_reserved(drm_ready);
#else
#if IS_ENABLED(CONFIG_MTK_WATCHDOG)
mrdump_wd_dram_reserved_mode(drm_ready);
#endif
#endif
pr_info("%s: init_done.\n", __func__);
#if IS_ENABLED(CONFIG_MTK_DFD_INTERNAL_DUMP)
if (dfd_setup(DFD_BASIC_DUMP) == -1)
pr_notice("%s: DFD disabled\n", __func__);
else
pr_notice("%s: DFD enabled\n", __func__);
#endif
return 0;
}
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("MediaTek AEE module");
MODULE_AUTHOR("MediaTek Inc.");
@@ -0,0 +1,762 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#include <linux/bug.h>
#include <linux/compiler.h>
#include <linux/elf.h>
#include <linux/fs.h>
#include <linux/highmem.h>
#include <linux/init.h>
#include <linux/kdebug.h>
#include <linux/memblock.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_fdt.h>
#include <linux/of_reserved_mem.h>
#include <linux/printk.h>
#include <linux/sizes.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/stacktrace.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
#include "../../../../kernel/sched/sched.h"
#include <asm/irq.h>
#include <asm/kexec.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/setup.h>
#include <asm/stacktrace.h>
#include <asm-generic/percpu.h>
#include <asm-generic/sections.h>
#include <mrdump.h>
#include <mt-plat/aee.h>
#include "mrdump_mini.h"
#include "mrdump_private.h"
static struct mrdump_mini_elf_header *mrdump_mini_ehdr;
#ifdef CONFIG_MODULES
static char *modules_info_buf;
#endif
__weak void get_gz_log_buffer(unsigned long *addr, unsigned long *paddr,
unsigned long *size, unsigned long *start)
{
*addr = *paddr = *size = *start = 0;
}
__weak void get_disp_err_buffer(unsigned long *addr, unsigned long *size,
unsigned long *start)
{
}
__weak void get_disp_fence_buffer(unsigned long *addr, unsigned long *size,
unsigned long *start)
{
}
__weak void get_disp_dbg_buffer(unsigned long *addr, unsigned long *size,
unsigned long *start)
{
}
__weak void get_disp_dump_buffer(unsigned long *addr, unsigned long *size,
unsigned long *start)
{
}
__weak void get_pidmap_aee_buffer(unsigned long *addr, unsigned long *size)
{
}
#ifdef __aarch64__
#define MIN_MARGIN VA_START
#else
#define MIN_MARGIN MODULES_VADDR
#endif
#ifdef __aarch64__
static unsigned long virt_2_pfn(unsigned long addr)
{
pgd_t *pgd = aee_pgd_offset_k(addr), _pgd_val = {0};
pud_t *pud, _pud_val = {0};
pmd_t *pmd, _pmd_val = {0};
pte_t *ptep, _pte_val = {0};
unsigned long pfn = ~0UL;
if (addr < VA_START)
goto OUT;
if (probe_kernel_address(pgd, _pgd_val) || pgd_none(_pgd_val))
goto OUT;
pud = pud_offset(pgd, addr);
if (probe_kernel_address(pud, _pud_val) || pud_none(_pud_val))
goto OUT;
if (pud_sect(_pud_val)) {
pfn = pud_pfn(_pud_val) + ((addr&~PUD_MASK) >> PAGE_SHIFT);
} else if (pud_table(_pud_val)) {
pmd = pmd_offset(pud, addr);
if (probe_kernel_address(pmd, _pmd_val) || pmd_none(_pmd_val))
goto OUT;
if (pmd_sect(_pmd_val)) {
pfn = pmd_pfn(_pmd_val) +
((addr&~PMD_MASK) >> PAGE_SHIFT);
} else if (pmd_table(_pmd_val)) {
ptep = pte_offset_map(pmd, addr);
if (probe_kernel_address(ptep, _pte_val)
|| !pte_present(_pte_val)) {
pte_unmap(ptep);
goto OUT;
}
pfn = pte_pfn(_pte_val);
pte_unmap(ptep);
}
}
OUT:
return pfn;
}
#else
#ifndef pmd_sect
#define pmd_sect(pmd) (pmd & PMD_TYPE_SECT)
#endif
#ifndef pmd_table
#define pmd_table(pmd) (pmd & PMD_TYPE_TABLE)
#endif
#ifndef pmd_pfn
#define pmd_pfn(pmd) (((pmd_val(pmd) & PMD_MASK) & PHYS_MASK) >> PAGE_SHIFT)
#endif
static unsigned long virt_2_pfn(unsigned long addr)
{
pgd_t *pgd = aee_pgd_offset_k(addr), _pgd_val = {0};
#ifdef CONFIG_ARM_LPAE
pud_t *pud, _pud_val = {0};
#else
pud_t *pud, _pud_val = {{0} };
#endif
pmd_t *pmd, _pmd_val = 0;
pte_t *ptep, _pte_val = 0;
unsigned long pfn = ~0UL;
if (probe_kernel_address(pgd, _pgd_val) || pgd_none(_pgd_val))
goto OUT;
pud = pud_offset(pgd, addr);
if (probe_kernel_address(pud, _pud_val) || pud_none(_pud_val))
goto OUT;
pmd = pmd_offset(pud, addr);
if (probe_kernel_address(pmd, _pmd_val) || pmd_none(_pmd_val))
goto OUT;
if (pmd_sect(_pmd_val)) {
pfn = pmd_pfn(_pmd_val) + ((addr&~PMD_MASK) >> PAGE_SHIFT);
} else if (pmd_table(_pmd_val)) {
ptep = pte_offset_map(pmd, addr);
if (probe_kernel_address(ptep, _pte_val)
|| !pte_present(_pte_val)) {
pte_unmap(ptep);
goto OUT;
}
pfn = pte_pfn(_pte_val);
pte_unmap(ptep);
}
OUT:
return pfn;
}
#endif
/* copy from fs/binfmt_elf.c */
static void fill_elf_header(struct elfhdr *elf, int segs)
{
memcpy(elf->e_ident, ELFMAG, SELFMAG);
elf->e_ident[EI_CLASS] = ELF_CLASS;
elf->e_ident[EI_DATA] = ELF_DATA;
elf->e_ident[EI_VERSION] = EV_CURRENT;
elf->e_ident[EI_OSABI] = ELF_OSABI;
elf->e_type = ET_CORE;
elf->e_machine = ELF_ARCH;
elf->e_version = EV_CURRENT;
elf->e_phoff = sizeof(struct elfhdr);
#ifndef ELF_CORE_EFLAGS
#define ELF_CORE_EFLAGS 0
#endif
elf->e_flags = ELF_CORE_EFLAGS;
elf->e_ehsize = sizeof(struct elfhdr);
elf->e_phentsize = sizeof(struct elf_phdr);
elf->e_phnum = segs;
}
static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offset)
{
phdr->p_type = PT_NOTE;
phdr->p_offset = offset;
phdr->p_vaddr = 0;
phdr->p_paddr = 0;
phdr->p_filesz = sz;
phdr->p_memsz = 0;
phdr->p_flags = 0;
phdr->p_align = 0;
}
static noinline void fill_note(struct elf_note *note, const char *name,
int type, unsigned int sz, unsigned int namesz)
{
char *n_name = (char *)note + sizeof(struct elf_note);
note->n_namesz = namesz;
note->n_type = type;
note->n_descsz = sz;
strncpy(n_name, name, note->n_namesz);
}
static void fill_note_L(struct elf_note *note, const char *name, int type,
unsigned int sz)
{
fill_note(note, name, type, sz, NOTE_NAME_LONG);
}
static void fill_note_S(struct elf_note *note, const char *name, int type,
unsigned int sz)
{
fill_note(note, name, type, sz, NOTE_NAME_SHORT);
}
/*
* fill up all the fields in prstatus from the given task struct, except
* registers which need to be filled up separately.
*/
static void fill_prstatus(struct elf_prstatus *prstatus, struct pt_regs *regs,
struct task_struct *p, unsigned long pid)
{
elf_core_copy_regs(&prstatus->pr_reg, regs);
prstatus->pr_pid = pid;
prstatus->pr_ppid = nr_cpu_ids;
prstatus->pr_sigpend = (uintptr_t)p;
}
static int fill_psinfo(struct elf_prpsinfo *psinfo)
{
unsigned int i;
strncpy(psinfo->pr_psargs, "vmlinux", ELF_PRARGSZ - 1);
for (i = 0; i < ELF_PRARGSZ - 1; i++)
if (psinfo->pr_psargs[i] == 0)
psinfo->pr_psargs[i] = ' ';
psinfo->pr_psargs[ELF_PRARGSZ - 1] = 0;
strncpy(psinfo->pr_fname, "vmlinux", sizeof(psinfo->pr_fname));
return 0;
}
#ifndef __pa_nodebug
#ifdef __pa_symbol_nodebug
#define __pa_nodebug __pa_symbol_nodebug
#else
#define __pa_nodebug __pa
#endif
#endif
static void mrdump_mini_add_misc_pa(unsigned long va, unsigned long pa,
unsigned long size, unsigned long start, char *name)
{
int i;
struct elf_note *note;
if (!mrdump_mini_ehdr)
return;
for (i = 0; i < MRDUMP_MINI_NR_MISC; i++) {
note = &mrdump_mini_ehdr->misc[i].note;
if (note->n_type == NT_IPANIC_MISC) {
if (strncmp(name, MRDUMP_MINI_MISC_LOAD, 4) == 0)
continue;
if (strncmp(mrdump_mini_ehdr->misc[i].name, name, 16)
!= 0)
continue;
}
mrdump_mini_ehdr->misc[i].data.vaddr = va;
mrdump_mini_ehdr->misc[i].data.paddr = pa;
mrdump_mini_ehdr->misc[i].data.size = size;
mrdump_mini_ehdr->misc[i].data.start =
mrdump_virt_addr_valid((void *)start) ?
__pa_nodebug(start) : 0;
fill_note_L(note, name, NT_IPANIC_MISC,
sizeof(struct mrdump_mini_elf_misc));
break;
}
}
void mrdump_mini_add_misc(unsigned long addr, unsigned long size,
unsigned long start, char *name)
{
if (!mrdump_virt_addr_valid((void *)addr))
return;
mrdump_mini_add_misc_pa(addr, __pa_nodebug(addr), size, start, name);
}
int kernel_addr_valid(unsigned long addr)
{
if (addr < MIN_MARGIN)
return 0;
return pfn_valid(virt_2_pfn(addr));
}
static void mrdump_mini_build_task_info(struct pt_regs *regs)
{
#define MAX_STACK_TRACE_DEPTH 64
unsigned long ipanic_stack_entries[MAX_STACK_TRACE_DEPTH];
char symbol[96] = {'\0'};
int sz;
#ifdef CONFIG_STACKTRACE
int off, plen;
struct stack_trace trace;
int i;
#endif
struct task_struct *tsk, *cur;
struct task_struct *previous;
struct aee_process_info *cur_proc;
if (!mrdump_mini_ehdr) {
pr_notice("mrdump: ehder invalid\n");
return;
}
if (!mrdump_virt_addr_valid(current_thread_info())) {
pr_notice("current thread info invalid\n");
return;
}
cur = current;
tsk = cur;
if (!mrdump_virt_addr_valid(tsk)) {
pr_notice("tsk invalid\n");
return;
}
cur_proc = (struct aee_process_info *)((void *)mrdump_mini_ehdr +
MRDUMP_MINI_HEADER_SIZE);
/* Current panic user tasks */
sz = 0;
do {
if (!tsk) {
pr_notice("No tsk info\n");
memset_io(cur_proc, 0x0,
sizeof(struct aee_process_info));
break;
}
/* FIXME: Check overflow ? */
sz += snprintf(symbol + sz, 96 - sz, "[%s, %d]", tsk->comm,
tsk->pid);
previous = tsk;
tsk = tsk->real_parent;
if (!mrdump_virt_addr_valid(tsk)) {
pr_notice("tsk(%p) invalid (previous: [%s, %d])\n", tsk,
previous->comm, previous->pid);
break;
}
} while (tsk && (tsk->pid != 0) && (tsk->pid != 1));
if (!strncmp(cur_proc->process_path, symbol, sz)) {
pr_notice("same process path\n");
return;
}
memset_io(cur_proc, 0, sizeof(struct aee_process_info));
memcpy(cur_proc->process_path, symbol, sz);
if (regs) {
cur_proc->ke_frame.pc = (__u64) regs->reg_pc;
cur_proc->ke_frame.lr = (__u64) regs->reg_lr;
}
#ifdef CONFIG_STACKTRACE
/* Grab kernel task stack trace */
trace.nr_entries = 0;
trace.max_entries = MAX_STACK_TRACE_DEPTH;
trace.entries = ipanic_stack_entries;
/* the value is only from experience and without strict rules
* need to pay attention to the value
*/
trace.skip = 4;
save_stack_trace_tsk(cur, &trace);
if (!regs) {
/* in case panic() is called without die */
/* Todo: a UT for this */
cur_proc->ke_frame.pc = ipanic_stack_entries[0];
cur_proc->ke_frame.lr = ipanic_stack_entries[1];
}
/* Skip the entries -
* ipanic_save_current_tsk_info/save_stack_trace_tsk
*/
for (i = 0; i < trace.nr_entries; i++) {
off = strlen(cur_proc->backtrace);
plen = AEE_BACKTRACE_LENGTH - ALIGN(off, 8);
if (plen > 16) {
if (ipanic_stack_entries[i] != cur_proc->ke_frame.pc)
ipanic_stack_entries[i] -= 4;
sz = snprintf(symbol, 96, "[<%px>] %pS\n",
(void *)ipanic_stack_entries[i],
(void *)ipanic_stack_entries[i]);
if (ALIGN(sz, 8) - sz) {
memset_io(symbol + sz - 1, ' ',
ALIGN(sz, 8) - sz);
memset_io(symbol + ALIGN(sz, 8) - 1, '\n', 1);
}
if (ALIGN(sz, 8) <= plen)
memcpy(cur_proc->backtrace + ALIGN(off, 8),
symbol, ALIGN(sz, 8));
}
}
#endif
if (mrdump_virt_addr_valid(cur_proc->ke_frame.pc))
snprintf(cur_proc->ke_frame.pc_symbol, AEE_SZ_SYMBOL_S,
"[<%px>] %pS",
(void *)(unsigned long)cur_proc->ke_frame.pc,
(void *)(unsigned long)cur_proc->ke_frame.pc);
else
pr_info("[<%llu>] invalid pc", cur_proc->ke_frame.pc);
if (mrdump_virt_addr_valid(cur_proc->ke_frame.lr))
snprintf(cur_proc->ke_frame.lr_symbol, AEE_SZ_SYMBOL_L,
"[<%px>] %pS",
(void *)(unsigned long)cur_proc->ke_frame.lr,
(void *)(unsigned long)cur_proc->ke_frame.lr);
else
pr_info("[<%llu>] invalid lr", cur_proc->ke_frame.lr);
}
int mrdump_modules_info(unsigned char *buffer, size_t sz_buf)
{
#ifdef CONFIG_MODULES
int sz;
sz = aee_save_modules(modules_info_buf, MODULES_INFO_BUF_SIZE);
if (sz <= 0 || sz_buf < sz || !buffer)
return -1;
memcpy(buffer, modules_info_buf, sz);
return sz;
#else
return -1;
#endif
}
#define EXTRA_MISC(func, name, max_size) \
__weak void func(unsigned long *vaddr, unsigned long *size) \
{ \
if (size) \
*size = 0; \
}
#include "mrdump_mini_extra_misc.h"
#undef EXTRA_MISC
#define EXTRA_MISC(func, name, max_size) \
{func, name, max_size},
static struct mrdump_mini_extra_misc extra_members[] = {
#include "mrdump_mini_extra_misc.h"
};
#define EXTRA_TOTAL_NUM ((sizeof(extra_members)) / (sizeof(extra_members[0])))
static size_t __maybe_unused dummy_check(void)
{
size_t dummy;
dummy = BUILD_BUG_ON_ZERO(EXTRA_TOTAL_NUM > 10);
return dummy;
}
static int _mrdump_mini_add_extra_misc(unsigned long vaddr, unsigned long size,
const char *name)
{
char name_buf[SZ_128];
if (!mrdump_mini_ehdr ||
!size ||
size > SZ_512K ||
!name)
return -1;
snprintf(name_buf, SZ_128, "_EXTRA_%s_", name);
mrdump_mini_add_misc(vaddr, size, 0, name_buf);
return 0;
}
void mrdump_mini_add_extra_misc(void)
{
static int once;
int i;
unsigned long vaddr = 0;
unsigned long size = 0;
int ret;
if (!once) {
once = 1;
for (i = 0; i < EXTRA_TOTAL_NUM; i++) {
extra_members[i].dump_func(&vaddr, &size);
if (size > extra_members[i].max_size)
continue;
ret = _mrdump_mini_add_extra_misc(vaddr, size,
extra_members[i].dump_name);
if (ret < 0)
pr_notice("mrdump: add %s:0x%lx sz:0x%lx failed\n",
extra_members[i].dump_name,
vaddr, size);
}
}
}
EXPORT_SYMBOL(mrdump_mini_add_extra_misc);
static void mrdump_mini_fatal(const char *str)
{
pr_notice("minirdump: FATAL:%s\n", str);
}
static unsigned int mrdump_mini_addr;
static unsigned int mrdump_mini_size;
void mrdump_mini_set_addr_size(unsigned int addr, unsigned int size)
{
mrdump_mini_addr = addr;
mrdump_mini_size = size;
}
EXPORT_SYMBOL(mrdump_mini_set_addr_size);
static void mrdump_mini_build_elf_misc(void)
{
struct mrdump_mini_elf_misc misc;
unsigned long task_info_va =
(unsigned long)((void *)mrdump_mini_ehdr + MRDUMP_MINI_HEADER_SIZE);
unsigned long task_info_pa = 0;
if (mrdump_mini_addr
&& mrdump_mini_size
&& MRDUMP_MINI_HEADER_SIZE < mrdump_mini_size) {
task_info_pa = (unsigned long)(mrdump_mini_addr +
MRDUMP_MINI_HEADER_SIZE);
} else {
pr_notice("minirdump: unexpected addr:0x%x, size:0x%x(0x%x)\n",
mrdump_mini_addr, mrdump_mini_size,
(unsigned int)MRDUMP_MINI_HEADER_SIZE);
mrdump_mini_fatal("illegal addr size");
}
mrdump_mini_add_misc_pa(task_info_va, task_info_pa,
sizeof(struct aee_process_info), 0, "PROC_CUR_TSK");
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
/* could also use the kernel log in pstore for LKM case */
misc.vaddr = (unsigned long)aee_log_buf_addr_get();
misc.size = (unsigned long)aee_log_buf_len_get();
mrdump_mini_add_misc(misc.vaddr, misc.size, misc.start, "_KERNEL_LOG_");
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
get_mbootlog_buffer(&misc.vaddr, &misc.size, &misc.start);
mrdump_mini_add_misc(misc.vaddr, misc.size, misc.start, "_LAST_KMSG");
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
aee_rr_get_desc_info(&misc.vaddr, &misc.size, &misc.start);
mrdump_mini_add_misc(misc.vaddr, misc.size, misc.start, "_RR_DESC_");
#if IS_ENABLED(CONFIG_HAVE_MTK_GZ_LOG)
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
get_gz_log_buffer(&misc.vaddr, &misc.paddr, &misc.size, &misc.start);
if (misc.paddr)
mrdump_mini_add_misc_pa(misc.vaddr, misc.paddr, misc.size,
misc.start, "_GZ_LOG_");
#endif
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
get_disp_err_buffer(&misc.vaddr, &misc.size, &misc.start);
mrdump_mini_add_misc(misc.vaddr, misc.size, misc.start, "_DISP_ERR_");
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
get_disp_dump_buffer(&misc.vaddr, &misc.size, &misc.start);
mrdump_mini_add_misc(misc.vaddr, misc.size, misc.start, "_DISP_DUMP_");
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
get_disp_fence_buffer(&misc.vaddr, &misc.size, &misc.start);
mrdump_mini_add_misc(misc.vaddr, misc.size, misc.start, "_DISP_FENCE_");
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
get_disp_dbg_buffer(&misc.vaddr, &misc.size, &misc.start);
mrdump_mini_add_misc(misc.vaddr, misc.size, misc.start, "_DISP_DBG_");
#ifdef CONFIG_MODULES
modules_info_buf = kzalloc(MODULES_INFO_BUF_SIZE, GFP_KERNEL);
if (modules_info_buf)
mrdump_mini_add_misc_pa((unsigned long)modules_info_buf,
(unsigned long)__pa_nodebug(
(unsigned long)modules_info_buf),
MODULES_INFO_BUF_SIZE, 0, "SYS_MODULES_INFO");
#endif
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
get_pidmap_aee_buffer(&misc.vaddr, &misc.size);
misc.start = 0;
mrdump_mini_add_misc(misc.vaddr, misc.size, misc.start, "_PIDMAP_");
#ifndef MODULE
memset_io(&misc, 0, sizeof(struct mrdump_mini_elf_misc));
misc.vaddr = (unsigned long)(void *)linux_banner;
misc.size = strlen(linux_banner);
misc.start = 0;
mrdump_mini_add_misc(misc.vaddr, misc.size, misc.start, "_VERSION_BR");
#endif
}
static void mrdump_mini_clear_loads(void)
{
struct elf_phdr *phdr;
int i;
for (i = 0; i < MRDUMP_MINI_NR_SECTION; i++) {
phdr = &mrdump_mini_ehdr->phdrs[i];
if (phdr->p_type == PT_NULL)
continue;
if (phdr->p_type == PT_LOAD)
phdr->p_type = PT_NULL;
}
}
void mrdump_mini_add_hang_raw(unsigned long vaddr, unsigned long size)
{
pr_notice("mrdump: hang data 0x%lx size:0x%lx\n", vaddr, size);
if (!mrdump_mini_ehdr) {
pr_notice("mrdump: ehdr invalid");
return;
}
mrdump_mini_add_misc(vaddr, size, 0, "_HANG_DETECT_");
/* hang only remove mini rdump loads info to save storage space */
mrdump_mini_clear_loads();
}
EXPORT_SYMBOL(mrdump_mini_add_hang_raw);
void mrdump_mini_ke_cpu_regs(struct pt_regs *regs)
{
mrdump_mini_build_task_info(regs);
}
static void *remap_lowmem(phys_addr_t start, phys_addr_t size)
{
struct page **pages;
phys_addr_t page_start;
unsigned int page_count;
unsigned int i;
void *vaddr;
page_start = start - offset_in_page(start);
page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE);
pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL);
if (!pages)
return NULL;
for (i = 0; i < page_count; i++) {
phys_addr_t addr = page_start + i * PAGE_SIZE;
pages[i] = pfn_to_page(addr >> PAGE_SHIFT);
}
vaddr = vmap(pages, page_count, VM_MAP, PAGE_KERNEL);
kfree(pages);
if (!vaddr) {
pr_notice("%s: Failed to map %u pages\n", __func__, page_count);
return NULL;
}
return vaddr + offset_in_page(start);
}
static void __init mrdump_mini_elf_header_init(void)
{
if (mrdump_mini_addr && mrdump_mini_size) {
mrdump_mini_ehdr =
remap_lowmem(mrdump_mini_addr,
mrdump_mini_size);
pr_notice("minirdump: [DT] reserved 0x%x+0x%lx->%p\n",
mrdump_mini_addr,
(unsigned long)mrdump_mini_size,
mrdump_mini_ehdr);
} else {
pr_notice("minirdump: [DT] illegal value 0x%x(0x%x)\n",
mrdump_mini_addr,
mrdump_mini_size);
mrdump_mini_fatal("illegal addr size");
return;
}
if (!mrdump_mini_ehdr) {
pr_notice("mrdump mini reserve buffer fail");
mrdump_mini_fatal("header null pointer");
return;
}
memset_io(mrdump_mini_ehdr, 0, MRDUMP_MINI_HEADER_SIZE +
sizeof(struct aee_process_info));
fill_elf_header(&mrdump_mini_ehdr->ehdr, MRDUMP_MINI_NR_SECTION);
}
int __init mrdump_mini_init(const struct mrdump_params *mparams)
{
int i, cpu;
unsigned long size, offset, vaddr;
struct pt_regs regs;
mrdump_mini_elf_header_init();
if (!mrdump_mini_ehdr) {
pr_notice("mrdump: mini init fail\n");
return -1;
}
fill_psinfo(&mrdump_mini_ehdr->psinfo.data);
fill_note_S(&mrdump_mini_ehdr->psinfo.note, "vmlinux", NT_PRPSINFO,
sizeof(struct elf_prpsinfo));
memset_io(&regs, 0, sizeof(struct pt_regs));
for (i = 0; i < AEE_MTK_CPU_NUMS; i++) {
fill_prstatus(&mrdump_mini_ehdr->prstatus[i].data, &regs,
NULL, i);
fill_note_S(&mrdump_mini_ehdr->prstatus[i].note, "NA",
NT_PRSTATUS, sizeof(struct elf_prstatus));
}
offset = offsetof(struct mrdump_mini_elf_header, psinfo);
size = sizeof(mrdump_mini_ehdr->psinfo) +
sizeof(mrdump_mini_ehdr->prstatus);
fill_elf_note_phdr(&mrdump_mini_ehdr->phdrs[0], size, offset);
for (i = 0; i < MRDUMP_MINI_NR_MISC; i++)
fill_note_L(&mrdump_mini_ehdr->misc[i].note, "NA", 0,
sizeof(struct mrdump_mini_elf_misc));
mrdump_mini_build_elf_misc();
fill_elf_note_phdr(&mrdump_mini_ehdr->phdrs[1],
sizeof(mrdump_mini_ehdr->misc),
offsetof(struct mrdump_mini_elf_header, misc));
if (mrdump_cblock) {
mrdump_mini_add_misc_pa((unsigned long)mrdump_cblock,
mparams->cb_addr, mparams->cb_size,
0, MRDUMP_MINI_MISC_LOAD);
vaddr = aee_get_kallsyms_addresses();
vaddr = round_down(vaddr, PAGE_SIZE);
size = mrdump_cblock->machdesc.kallsyms.size;
size = round_up(size, PAGE_SIZE);
if (vaddr)
mrdump_mini_add_misc_pa(vaddr, __pa_nodebug(vaddr),
size, 0, MRDUMP_MINI_MISC_LOAD);
}
vaddr = round_down((unsigned long)__per_cpu_offset, PAGE_SIZE);
mrdump_mini_add_misc_pa(vaddr, __pa_nodebug(vaddr),
PAGE_SIZE * 2, 0, MRDUMP_MINI_MISC_LOAD);
for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
vaddr = (unsigned long)aee_cpu_rq(cpu);
vaddr = round_down(vaddr, PAGE_SIZE);
mrdump_mini_add_misc(vaddr, MRDUMP_MINI_SECTION_SIZE,
0, MRDUMP_MINI_MISC_LOAD);
}
return 0;
}
int mini_rdump_reserve_memory(struct reserved_mem *rmem)
{
pr_info("[memblock]%s: 0x%llx - 0x%llx (0x%llx)\n",
"mediatek,minirdump",
(unsigned long long)rmem->base,
(unsigned long long)rmem->base +
(unsigned long long)rmem->size,
(unsigned long long)rmem->size);
return 0;
}
RESERVEDMEM_OF_DECLARE(reserve_memory_minirdump, "mediatek,minirdump",
mini_rdump_reserve_memory);
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#if !defined(__MRDUMP_MINI_H__)
struct mrdump_mini_extra_misc {
void (*dump_func)(unsigned long *vaddr, unsigned long *size);
const char *dump_name;
unsigned long max_size;
};
#ifdef CONFIG_STACKTRACE
extern unsigned long *stack_trace;
#endif
extern void get_hang_detect_buffer(unsigned long *addr, unsigned long *size,
unsigned long *start);
#if IS_ENABLED(CONFIG_HAVE_MTK_GZ_LOG)
extern void get_gz_log_buffer(unsigned long *addr, unsigned long *paddr,
unsigned long *size, unsigned long *start);
#endif
extern void get_mbootlog_buffer(unsigned long *addr, unsigned long *size,
unsigned long *start);
extern struct mboot_params_buffer *mboot_params_buffer;
extern void aee_rr_get_desc_info(unsigned long *addr, unsigned long *size,
unsigned long *start);
#endif
@@ -0,0 +1,26 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 MediaTek Inc.
*/
/*
* implement your own function "function_name" for the type:
* void function_name(unsigned long *vaddr, unsigned long *size)
* then add one line here just like the sample code below
* EXTRA_MISC(function_name, "DBFILENAME", MAX_SIZE)
* a file "SYS_EXTRA_DBFILENAME_RAW" will be generated
* ensure size return by the function is <= MAX_SIZE
* otherwise this file will not be generated i.e. ignored
* MAX_SIZE should be as less as possible and dozens of kb is preferred
* NOTE: end-of-line DON'T add comma
*/
/* e.g. */
/* EXTRA_MISC(test_func, "TESTNAME", (4 * 1024)) */
EXTRA_MISC(get_msdc_aee_buffer, "MSDC", (512 * 1024))
EXTRA_MISC(get_ufs_aee_buffer, "UFS", (100 * 1024))
EXTRA_MISC(get_blockio_aee_buffer, "BLOCKIO", (300 * 1024))
EXTRA_MISC(get_ccci_aee_buffer, "CCCI", (300 * 1024))
EXTRA_MISC(get_md_aee_buffer, "MD", (512 * 1024))
#ifdef CONFIG_MTK_AUDIODSP_SUPPORT
EXTRA_MISC(get_adsp_misc_buffer, "ADSP", (512 * 1024))
#endif
@@ -0,0 +1,308 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 MediaTek Inc.
*/
#include <linux/delay.h>
#include <linux/of.h>
#include <linux/kdebug.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/reboot.h>
#include <linux/sched/clock.h>
#include <linux/slab.h>
#include <asm/cacheflush.h>
#include <asm/kexec.h>
#include <asm/memory.h>
#include <asm/stacktrace.h>
#include <asm/system_misc.h>
#include <mrdump.h>
#include <mt-plat/mboot_params.h>
#include "mrdump_mini.h"
#include "mrdump_private.h"
/* for arm_smccc_smc */
#include <linux/arm-smccc.h>
#include <uapi/linux/psci.h>
static inline unsigned long get_linear_memory_size(void)
{
return (unsigned long)high_memory - PAGE_OFFSET;
}
/* no export symbol to aee_exception_reboot, only used in exception flow */
/* PSCI v1.1 extended power state encoding for SYSTEM_RESET2 function */
#define PSCI_1_1_FN_SYSTEM_RESET2 0x84000012
#define PSCI_1_1_RESET2_TYPE_VENDOR_SHIFT 31
#define PSCI_1_1_RESET2_TYPE_VENDOR \
(1 << PSCI_1_1_RESET2_TYPE_VENDOR_SHIFT)
static void aee_exception_reboot(void)
{
struct arm_smccc_res res;
int opt1 = 1, opt2 = 0;
arm_smccc_smc(PSCI_1_1_FN_SYSTEM_RESET2,
PSCI_1_1_RESET2_TYPE_VENDOR | opt1,
opt2, 0, 0, 0, 0, 0, &res);
}
#if defined(CONFIG_RANDOMIZE_BASE) && defined(CONFIG_ARM64)
static inline void show_kaslr(void)
{
u64 const kaslr_offset = aee_get_kimage_vaddr() - KIMAGE_VADDR;
pr_notice("Kernel Offset: 0x%llx from 0x%lx\n",
kaslr_offset, KIMAGE_VADDR);
pr_notice("PHYS_OFFSET: 0x%llx\n", PHYS_OFFSET);
aee_rr_rec_kaslr_offset(kaslr_offset);
}
#else
static inline void show_kaslr(void)
{
pr_notice("Kernel Offset: disabled\n");
aee_rr_rec_kaslr_offset(0xd15ab1e);
}
#endif
static char nested_panic_buf[1024];
int aee_nested_printf(const char *fmt, ...)
{
va_list args;
static int total_len;
va_start(args, fmt);
total_len += vsnprintf(nested_panic_buf, sizeof(nested_panic_buf),
fmt, args);
va_end(args);
aee_sram_fiq_log(nested_panic_buf);
return total_len;
}
static int num_die;
int mrdump_common_die(u8 fiq_step, int reboot_reason, const char *msg,
struct pt_regs *regs)
{
int last_step;
int next_step;
num_die++;
last_step = aee_rr_curr_fiq_step();
if (num_die > 1) {
/* NESTED KE */
#if IS_ENABLED(CONFIG_ARM64)
aee_reinit_die_lock();
#endif
}
aee_nested_printf("num_die-%d, fiq_step-%d last_step-%d\n",
num_die, fiq_step, last_step);
/* if we were in nested ke now, then the if condition would be false */
if (last_step < AEE_FIQ_STEP_COMMON_DIE_START)
last_step = AEE_FIQ_STEP_COMMON_DIE_START - 1;
/* skip the works of last_step */
next_step = last_step + 1;
switch (next_step) {
case AEE_FIQ_STEP_COMMON_DIE_START:
aee_rr_rec_fiq_step(AEE_FIQ_STEP_COMMON_DIE_START);
__mrdump_create_oops_dump(reboot_reason, regs, msg);
mrdump_mini_ke_cpu_regs(regs);
/* FALLTHRU */
case AEE_FIQ_STEP_COMMON_DIE_LOCK:
aee_rr_rec_fiq_step(AEE_FIQ_STEP_COMMON_DIE_LOCK);
#if IS_ENABLED(CONFIG_ARM64)
aee_reinit_die_lock();
#endif
aee_zap_locks();
/* FALLTHRU */
case AEE_FIQ_STEP_COMMON_DIE_KASLR:
aee_rr_rec_fiq_step(AEE_FIQ_STEP_COMMON_DIE_KASLR);
show_kaslr();
aee_print_modules();
/* FALLTHRU */
case AEE_FIQ_STEP_COMMON_DIE_SCP:
aee_rr_rec_fiq_step(AEE_FIQ_STEP_COMMON_DIE_SCP);
aee_rr_rec_scp();
/* FALLTHRU */
case AEE_FIQ_STEP_COMMON_DIE_EMISC:
aee_rr_rec_fiq_step(AEE_FIQ_STEP_COMMON_DIE_EMISC);
mrdump_mini_add_extra_misc();
/* FALLTHRU */
case AEE_FIQ_STEP_COMMON_DIE_TRACE:
aee_rr_rec_fiq_step(AEE_FIQ_STEP_COMMON_DIE_TRACE);
switch (reboot_reason) {
case AEE_REBOOT_MODE_KERNEL_OOPS:
aee_show_regs(regs);
dump_stack();
break;
case AEE_REBOOT_MODE_KERNEL_PANIC:
#ifndef CONFIG_DEBUG_BUGVERBOSE
dump_stack();
#endif
break;
case AEE_REBOOT_MODE_HANG_DETECT:
aee_rr_rec_exp_type(AEE_EXP_TYPE_HANG_DETECT);
break;
default:
/* Don't print anything */
break;
}
/* FALLTHRU */
case AEE_FIQ_STEP_COMMON_DIE_CS:
aee_rr_rec_fiq_step(AEE_FIQ_STEP_COMMON_DIE_CS);
console_unlock();
/* FALLTHRU */
case AEE_FIQ_STEP_COMMON_DIE_DONE:
aee_rr_rec_fiq_step(AEE_FIQ_STEP_COMMON_DIE_DONE);
/* FALLTHRU */
default:
aee_nested_printf("num_die-%d, fiq_step-%d, last_step-%d, next_step-%d\n",
num_die, fiq_step,
last_step, next_step);
aee_exception_reboot();
break;
}
return NOTIFY_DONE;
}
EXPORT_SYMBOL(mrdump_common_die);
int ipanic(struct notifier_block *this, unsigned long event, void *ptr)
{
struct pt_regs saved_regs;
aee_rr_rec_exp_type(AEE_EXP_TYPE_KE);
crash_setup_regs(&saved_regs, NULL);
return mrdump_common_die(AEE_FIQ_STEP_KE_IPANIC_START,
AEE_REBOOT_MODE_KERNEL_PANIC,
"Kernel Panic", &saved_regs);
}
static int ipanic_die(struct notifier_block *self, unsigned long cmd, void *ptr)
{
struct die_args *dargs = (struct die_args *)ptr;
aee_rr_rec_exp_type(AEE_EXP_TYPE_KE);
return mrdump_common_die(AEE_FIQ_STEP_KE_IPANIC_DIE,
AEE_REBOOT_MODE_KERNEL_OOPS,
"Kernel Oops", dargs->regs);
}
static struct notifier_block panic_blk = {
.notifier_call = ipanic,
};
static struct notifier_block die_blk = {
.notifier_call = ipanic_die,
};
static __init int mrdump_parse_chosen(struct mrdump_params *mparams)
{
struct device_node *node;
u32 reg[2];
const char *lkver, *ddr_rsv;
memset(mparams, 0, sizeof(struct mrdump_params));
node = of_find_node_by_path("/chosen");
if (node) {
if (of_property_read_u32_array(node, "mrdump,cblock",
reg, ARRAY_SIZE(reg)) == 0) {
mparams->cb_addr = reg[0];
mparams->cb_size = reg[1];
pr_notice("%s: mrdump_cbaddr=%pa, mrdump_cbsize=%pa\n",
__func__, &mparams->cb_addr, &mparams->cb_size);
}
if (of_property_read_string(node, "mrdump,lk", &lkver) == 0) {
strlcpy(mparams->lk_version, lkver,
sizeof(mparams->lk_version));
pr_notice("%s: lk version %s\n", __func__, lkver);
}
if (of_property_read_string(node, "mrdump,ddr_rsv",
&ddr_rsv) == 0) {
if (strcmp(ddr_rsv, "yes") == 0)
mparams->drm_ready = true;
pr_notice("%s: ddr reserve mode %s\n", __func__,
ddr_rsv);
}
return 0;
}
of_node_put(node);
pr_notice("%s: Can't find chosen node\n", __func__);
return -1;
}
#ifdef CONFIG_MODULES
/* Module notifier call back, update module info list */
static int mrdump_module_callback(struct notifier_block *nb,
unsigned long val, void *data)
{
if (val == MODULE_STATE_LIVE)
mrdump_modules_info(NULL, -1);
return NOTIFY_DONE;
}
static struct notifier_block mrdump_module_nb = {
.notifier_call = mrdump_module_callback,
};
#endif
static int __init mrdump_panic_init(void)
{
struct mrdump_params mparams = {};
if (!aee_is_enable()) {
pr_notice("%s: ipanic: mrdump is disable\n", __func__);
return 0;
}
mrdump_parse_chosen(&mparams);
#ifdef MODULE
mrdump_module_init_mboot_params();
#endif
mrdump_hw_init(mparams.drm_ready);
mrdump_cblock_init(mparams.cb_addr, mparams.cb_size);
if (mrdump_cblock == NULL) {
pr_notice("%s: MT-RAMDUMP no control block\n", __func__);
return -EINVAL;
}
mrdump_mini_init(&mparams);
if (strcmp(mparams.lk_version, MRDUMP_GO_DUMP) == 0) {
mrdump_full_init();
} else {
pr_notice("%s: Full ramdump disabled, version %s not matched.\n",
__func__, mparams.lk_version);
}
atomic_notifier_chain_register(&panic_notifier_list, &panic_blk);
register_die_notifier(&die_blk);
#ifdef CONFIG_MODULES
register_module_notifier(&mrdump_module_nb);
#endif
pr_debug("ipanic: startup\n");
return 0;
}
arch_initcall(mrdump_panic_init);
#ifdef MODULE
static void __exit mrdump_panic_exit(void)
{
atomic_notifier_chain_unregister(&panic_notifier_list, &panic_blk);
unregister_die_notifier(&die_blk);
unregister_module_notifier(&mrdump_module_nb);
pr_debug("ipanic: exit\n");
}
module_exit(mrdump_panic_exit);
#endif
@@ -0,0 +1,92 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#if !defined(__MRDUMP_PRIVATE_H__)
#define __MRDUMP_PRIVATE_H__
#include <asm/cputype.h>
#include <asm/memory.h>
#include <asm/smp_plat.h>
#include <asm-generic/sections.h>
#if IS_ENABLED(CONFIG_MTK_AEE_IPANIC)
#include <mt-plat/mboot_params.h>
#endif
#include "mrdump_helper.h"
extern int kernel_addr_valid(unsigned long addr);
#define mrdump_virt_addr_valid(kaddr) \
kernel_addr_valid((unsigned long)kaddr)
struct pt_regs;
struct mrdump_params {
char lk_version[12];
bool drm_ready;
phys_addr_t cb_addr;
phys_addr_t cb_size;
};
extern struct mrdump_control_block *mrdump_cblock;
extern const unsigned long kallsyms_addresses[] __weak;
extern const u8 kallsyms_names[] __weak;
extern const u8 kallsyms_token_table[] __weak;
extern const u16 kallsyms_token_index[] __weak;
extern const unsigned long kallsyms_markers[] __weak;
extern const unsigned long kallsyms_num_syms
__attribute__((weak, section(".rodata")));
#ifdef MODULE
int mrdump_module_init_mboot_params(void);
#endif
int mrdump_hw_init(bool drm_enabled);
void mrdump_cblock_init(phys_addr_t cb_addr, phys_addr_t cb_size);
int mrdump_full_init(void);
int mrdump_mini_init(const struct mrdump_params *mparams);
void mrdump_save_control_register(void *creg);
extern void mrdump_mini_ke_cpu_regs(struct pt_regs *regs);
extern int mrdump_modules_info(unsigned char *buffer, size_t sz_buf);
/* for WDT timeout case : dump timer/schedule/irq/softirq etc...
* debug information
*/
#ifdef CONFIG_MTK_SCHED_EXTENSION
extern void sysrq_sched_debug_show_at_AEE(void);
#endif
#if IS_ENABLED(CONFIG_MTK_WQ_DEBUG)
extern void wq_debug_dump(void);
#endif
#if defined(__arm__)
static inline void crash_setup_regs(struct pt_regs *newregs,
struct pt_regs *oldregs)
{
if (oldregs) {
memcpy(newregs, oldregs, sizeof(*newregs));
} else {
__asm__ __volatile__ (
"stmia %[regs_base], {r0-r12}\n\t"
"mov %[_ARM_sp], sp\n\t"
"str lr, %[_ARM_lr]\n\t"
"adr %[_ARM_pc], 1f\n\t"
"mrs %[_ARM_cpsr], cpsr\n\t"
"1:"
: [_ARM_pc] "=r" (newregs->ARM_pc),
[_ARM_cpsr] "=r" (newregs->ARM_cpsr),
[_ARM_sp] "=r" (newregs->ARM_sp),
[_ARM_lr] "=o" (newregs->ARM_lr)
: [regs_base] "r" (&newregs->ARM_r0)
: "memory"
);
}
}
#endif
#endif /* __MRDUMP_PRIVATE_H__ */