Initial commit: Linux kernel 4.19 for Unplugged OS

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

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
#
# 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 */