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

+29
View File
@@ -0,0 +1,29 @@
#
# Copyright (C) 2018 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.
#
ccflags-y += -I$(srctree)/drivers/misc/mediatek/mdla/$(MTK_PLATFORM)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/mdla/1.0
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include
ccflags-y += -I$(srctree)/drivers/staging/android/mtk_ion/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/m4u/$(MTK_PLATFORM)/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include
ccflags-y += -I$(srctree)/drivers/devfreq
ccflags-y += -I$(srctree)/include
ccflags-y += -I$(srctree)/drivers/misc/mediatek/vpu/$(MTK_PLATFORM)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/qos/
obj-$(CONFIG_MTK_MDLA_SUPPORT) := mdla_main.o gsm.o mdla_dvfs.o \
mdla_debug.o mdla_trace.o mdla_decoder.o
obj-$(CONFIG_MTK_ION) += mdla_ion.o
+123
View File
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "mdla_debug.h"
#include "gsm.h"
#include "mdla.h"
#include <linux/bitmap.h>
#include <asm/page.h>
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/module.h>
#define GSM_BITMAP_SIZE (GSM_SIZE/PAGE_SIZE)
DECLARE_BITMAP(gsm_bitmap, GSM_BITMAP_SIZE);
DEFINE_SPINLOCK(gsm_lock);
void *gsm_alloc(size_t size)
{
unsigned long flags;
int pageno;
int order = get_order(size);
spin_lock_irqsave(&gsm_lock, flags);
pageno = bitmap_find_free_region(
gsm_bitmap, GSM_BITMAP_SIZE, order);
spin_unlock_irqrestore(&gsm_lock, flags);
if (unlikely(pageno < 0))
return NULL;
return apu_mdla_gsm_top + (pageno << PAGE_SHIFT);
}
void *gsm_mva_to_virt(u32 mva)
{
return (void *)(mva - GSM_MVA_BASE + apu_mdla_gsm_top);
}
#define is_gsm_virt(a) \
(likely(((a) >= apu_mdla_gsm_top) && \
((a) < (apu_mdla_gsm_top + SZ_1M))))
#define gsm_virt_offset(a) \
((a) - apu_mdla_gsm_top)
static u32 gsm_virt_to_mva(void *vaddr)
{
if (is_gsm_virt(vaddr))
return (u32)(gsm_virt_offset(vaddr) + GSM_MVA_BASE);
return GSM_MVA_INVALID;
}
static void *gsm_virt_to_pa(void *vaddr)
{
if (is_gsm_virt(vaddr))
return (apu_mdla_gsm_base + gsm_virt_offset(vaddr));
return NULL;
}
int gsm_release(void *vaddr, size_t size)
{
unsigned long flags;
int order = get_order(size);
int page = (vaddr - apu_mdla_gsm_top) >> PAGE_SHIFT;
if ((page >= GSM_BITMAP_SIZE) || (page < 0))
return -EINVAL;
spin_lock_irqsave(&gsm_lock, flags);
bitmap_release_region(gsm_bitmap, page, order);
spin_unlock_irqrestore(&gsm_lock, flags);
return 0;
}
int mdla_gsm_alloc(struct ioctl_malloc *malloc_data)
{
int ret = 0;
int ex = 0;
void *ptr;
u32 size = malloc_data->size;
if (size == GSM_MVA_INVALID) {
size = GSM_SIZE;
mdla_mem_debug("%s: <exclusive mode>\n", __func__);
ex = 1;
}
ptr = gsm_alloc(size);
if (ptr == NULL)
ret = -ENOMEM;
malloc_data->size = size;
malloc_data->kva = (ex) ? apu_mdla_gsm_top : ptr;
malloc_data->mva = gsm_virt_to_mva(malloc_data->kva);
malloc_data->pa = gsm_virt_to_pa(malloc_data->kva);
#ifdef CONFIG_FPGA_EARLY_PORTING
/* avoid bus hang in fpga stage */
malloc_data->pa = (void *)((long) malloc_data->mva);
#endif
mdla_mem_debug("%s: ret: %d, kva:%p, mva:%x, pa:%p, size:%x\n",
__func__, ret,
malloc_data->kva, malloc_data->mva,
malloc_data->pa, malloc_data->size);
return ret;
}
void mdla_gsm_free(struct ioctl_malloc *malloc_data)
{
if (malloc_data->size > GSM_SIZE)
return;
if (malloc_data->kva)
gsm_release(malloc_data->kva, malloc_data->size);
mdla_mem_debug("%s: kva:%p, mva:%x, pa:%p, size:%x\n", __func__,
malloc_data->kva, malloc_data->mva,
malloc_data->pa, malloc_data->size);
}
+27
View File
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef __GSM_H__
#define __GSM_H__
#include <linux/types.h>
#include <linux/sizes.h>
#include "mdla_ioctl.h"
#define GSM_SIZE (SZ_1M)
#define GSM_MVA_BASE (0x80000000)
#define GSM_MVA_INVALID (0xFFFFFFFF)
void *gsm_alloc(size_t size);
void *gsm_mva_to_virt(u32 mva);
int gsm_release(void *vaddr, size_t size);
int mdla_gsm_alloc(struct ioctl_malloc *malloc_data);
void mdla_gsm_free(struct ioctl_malloc *malloc_data);
#define is_gsm_mva(a) \
(likely(((a) >= GSM_MVA_BASE) && ((a) < (GSM_MVA_BASE + SZ_1M))))
#endif /* KMOD_GSM_H_ */
+93
View File
@@ -0,0 +1,93 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef __MDLA_H__
#define __MDLA_H__
#include <linux/types.h>
#include <linux/seq_file.h>
#include <mdla_ioctl.h>
#define MTK_MDLA_CORE 1
unsigned int mdla_cfg_read(u32 offset);
unsigned int mdla_reg_read(u32 offset);
void mdla_reg_write(u32 value, u32 offset);
#define mdla_reg_set(mask, offset) \
mdla_reg_write(mdla_reg_read(offset) | (mask), (offset))
#define mdla_reg_clear(mask, offset) \
mdla_reg_write(mdla_reg_read(offset) & ~(mask), (offset))
u32 mdla_max_cmd_id(void);
extern void *apu_mdla_gsm_top;
extern void *apu_mdla_gsm_base;
extern void *apu_mdla_biu_top;
extern u32 mdla_timeout;
extern u32 mdla_poweroff_time;
extern u32 mdla_e1_detect_timeout;
extern u32 mdla_e1_detect_count;
enum REASON_ENUM {
REASON_OTHERS = 0,
REASON_DRVINIT = 1,
REASON_TIMEOUT = 2,
REASON_POWERON = 3,
REASON_MAX
};
void mdla_reset_lock(int ret);
enum command_entry_state {
CE_NONE = 0,
CE_QUEUE = 1,
CE_RUN = 2,
CE_DONE = 3,
CE_FIN = 4,
};
enum command_entry_flags {
CE_NOP = 0x00,
CE_SYNC = 0x01,
CE_POLLING = 0x02,
};
struct wait_entry {
u32 async_id;
struct list_head list;
struct ioctl_wait_cmd wt;
};
struct command_entry {
struct list_head list;
int flags;
int state;
int sync;
void *kva; /* Virtual Address for Kernel */
u32 mva; /* Physical Address for Device */
u32 count;
u32 id;
u64 khandle; /* ion kernel handle */
u8 type; /* allocate memory type */
u8 priority; /* dvfs priority */
u8 boost_value; /* dvfs boost value */
uint32_t bandwidth;
int result;
u64 receive_t; /* time of receive the request (ns) */
u64 queue_t; /* time queued in list (ns) */
u64 poweron_t; /* dvfs start time */
u64 req_start_t; /* request stant time (ns) */
u64 req_end_t; /* request end time (ns) */
u64 wait_t; /* time waited by user */
};
#endif
+577
View File
@@ -0,0 +1,577 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "mdla_debug.h"
#include "mdla.h"
#include "mdla_hw_reg.h"
#include "mdla_trace.h"
#include "mdla_dvfs.h"
#include "mdla_pmu.h"
#include <linux/vmalloc.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/mman.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/debugfs.h>
#include <linux/dcache.h>
#include <linux/delay.h>
#include <linux/kthread.h>
#include <linux/uaccess.h>
#include <linux/string.h>
#include <linux/io.h>
#define ALGO_OF_MAX_POWER (3)
/* global variables */
int g_mdla_log_level = 1;
unsigned int g_mdla_func_mask;
static int mdla_log_level_set(void *data, u64 val)
{
g_mdla_log_level = val & 0xf;
LOG_INF("g_mdla_log_level: %d\n", g_mdla_log_level);
return 0;
}
static int mdla_log_level_get(void *data, u64 *val)
{
*val = g_mdla_log_level;
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(mdla_debug_log_level_fops, mdla_log_level_get,
mdla_log_level_set, "%llu\n");
static int mdla_func_mask_set(void *data, u64 val)
{
g_mdla_func_mask = val & 0xffffffff;
LOG_INF("g_func_mask: 0x%x\n", g_mdla_func_mask);
return 0;
}
static int mdla_func_mask_get(void *data, u64 *val)
{
*val = g_mdla_func_mask;
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(mdla_debug_func_mask_fops, mdla_func_mask_get,
mdla_func_mask_set, "%llu\n");
#define IMPLEMENT_MDLA_DEBUGFS(name) \
static int mdla_debug_## name ##_show(struct seq_file *s, void *unused)\
{ \
mdla_dump_## name(s); \
return 0; \
} \
static int mdla_debug_## name ##_open(struct inode *inode, struct file *file) \
{ \
return single_open(file, mdla_debug_ ## name ## _show, \
inode->i_private); \
} \
static const struct file_operations mdla_debug_ ## name ## _fops = { \
.open = mdla_debug_ ## name ## _open, \
.read = seq_read, \
.llseek = seq_lseek, \
.release = seq_release, \
}
IMPLEMENT_MDLA_DEBUGFS(register);
IMPLEMENT_MDLA_DEBUGFS(opp_table);
#undef IMPLEMENT_MDLA_DEBUGFS
static int mdla_debug_power_show(struct seq_file *s, void *unused)
{
mdla_dump_power(s);
return 0;
}
static int mdla_debug_power_open(struct inode *inode, struct file *file)
{
return single_open(file, mdla_debug_power_show, inode->i_private);
}
static ssize_t mdla_debug_power_write(struct file *flip,
const char __user *buffer,
size_t count, loff_t *f_pos)
{
char *tmp, *token, *cursor;
int ret, i, param;
const int max_arg = 5;
unsigned int args[max_arg];
tmp = kzalloc(count + 1, GFP_KERNEL);
if (!tmp)
return -ENOMEM;
ret = copy_from_user(tmp, buffer, count);
if (ret) {
LOG_ERR("copy_from_user failed, ret=%d\n", ret);
goto out;
}
tmp[count] = '\0';
cursor = tmp;
/* parse a command */
token = strsep(&cursor, " ");
if (strcmp(token, "fix_opp") == 0)
param = MDLA_POWER_PARAM_FIX_OPP;
else if (strcmp(token, "dvfs_debug") == 0)
param = MDLA_POWER_PARAM_DVFS_DEBUG;
else if (strcmp(token, "jtag") == 0)
param = MDLA_POWER_PARAM_JTAG;
else if (strcmp(token, "lock") == 0)
param = MDLA_POWER_PARAM_LOCK;
else if (strcmp(token, "volt_step") == 0)
param = MDLA_POWER_PARAM_VOLT_STEP;
else if (strcmp(token, "power_hal") == 0)
param = MDLA_POWER_HAL_CTL;
else if (strcmp(token, "eara") == 0)
param = MDLA_EARA_CTL;
else {
ret = -EINVAL;
LOG_ERR("no power param[%s]!\n", token);
goto out;
}
/* parse arguments */
for (i = 0; i < max_arg && (token = strsep(&cursor, " ")); i++) {
ret = kstrtouint(token, 10, &args[i]);
if (ret) {
LOG_ERR("fail to parse args[%d]\n", i);
goto out;
}
}
mdla_set_power_parameter(param, i, args);
ret = count;
out:
kfree(tmp);
return ret;
}
static const struct file_operations mdla_debug_power_fops = {
.open = mdla_debug_power_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
.write = mdla_debug_power_write,
};
static int mdla_debug_prof_show(struct seq_file *s, void *unused)
{
mdla_dump_prof(s);
return 0;
}
static int mdla_debug_prof_open(struct inode *inode, struct file *file)
{
return single_open(file, mdla_debug_prof_show, inode->i_private);
}
static ssize_t mdla_debug_prof_write(struct file *flip,
const char __user *buffer,
size_t count, loff_t *f_pos)
{
pmu_reset_saved_counter();
return count;
}
static const struct file_operations mdla_debug_prof_fops = {
.open = mdla_debug_prof_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
.write = mdla_debug_prof_write,
};
#define DEFINE_MDLA_DEBUGFS(name) \
struct dentry *mdla_d##name
DEFINE_MDLA_DEBUGFS(root);
DEFINE_MDLA_DEBUGFS(timeout);
DEFINE_MDLA_DEBUGFS(e1_detect_timeout);
DEFINE_MDLA_DEBUGFS(e1_detect_count);
DEFINE_MDLA_DEBUGFS(poweroff_time);
DEFINE_MDLA_DEBUGFS(klog);
DEFINE_MDLA_DEBUGFS(register);
DEFINE_MDLA_DEBUGFS(opp_table);
DEFINE_MDLA_DEBUGFS(power);
DEFINE_MDLA_DEBUGFS(eng0);
DEFINE_MDLA_DEBUGFS(eng1);
DEFINE_MDLA_DEBUGFS(eng2);
DEFINE_MDLA_DEBUGFS(eng11);
DEFINE_MDLA_DEBUGFS(power);
DEFINE_MDLA_DEBUGFS(prof_start);
DEFINE_MDLA_DEBUGFS(prof);
DEFINE_MDLA_DEBUGFS(period);
DEFINE_MDLA_DEBUGFS(cmd_trace);
DEFINE_MDLA_DEBUGFS(op_trace);
DEFINE_MDLA_DEBUGFS(c1);
DEFINE_MDLA_DEBUGFS(c2);
DEFINE_MDLA_DEBUGFS(c3);
DEFINE_MDLA_DEBUGFS(c4);
DEFINE_MDLA_DEBUGFS(c5);
DEFINE_MDLA_DEBUGFS(c6);
DEFINE_MDLA_DEBUGFS(c7);
DEFINE_MDLA_DEBUGFS(c8);
DEFINE_MDLA_DEBUGFS(c9);
DEFINE_MDLA_DEBUGFS(c10);
DEFINE_MDLA_DEBUGFS(c11);
DEFINE_MDLA_DEBUGFS(c12);
DEFINE_MDLA_DEBUGFS(c13);
DEFINE_MDLA_DEBUGFS(c14);
DEFINE_MDLA_DEBUGFS(c15);
u32 mdla_klog;
void mdla_debugfs_init(void)
{
int ret;
mdla_klog = 0x40; /* print timeout info by default */
mdla_droot = debugfs_create_dir("mdla", NULL);
ret = IS_ERR_OR_NULL(mdla_droot);
if (ret) {
LOG_ERR("failed to create debug dir.\n");
return;
}
mdla_dtimeout = debugfs_create_u32("timeout", 0660, mdla_droot,
&mdla_timeout);
mdla_de1_detect_timeout = debugfs_create_u32("e1_detect_timeout",
0660, mdla_droot, &mdla_e1_detect_timeout);
mdla_de1_detect_timeout = debugfs_create_u32("e1_detect_count",
0440, mdla_droot, &mdla_e1_detect_count);
mdla_dpoweroff_time = debugfs_create_u32("poweroff_time",
0660, mdla_droot, &mdla_poweroff_time);
mdla_dklog = debugfs_create_u32("klog", 0660, mdla_droot,
&mdla_klog);
mdla_deng0 = debugfs_create_u32("eng0",
0660, mdla_droot, &cfg_eng0);
mdla_deng1 = debugfs_create_u32("eng1",
0660, mdla_droot, &cfg_eng1);
mdla_deng2 = debugfs_create_u32("eng2",
0660, mdla_droot, &cfg_eng2);
mdla_deng11 = debugfs_create_u32("eng11",
0660, mdla_droot, &cfg_eng11);
/* Prof */
mdla_dprof_start = debugfs_create_u32("prof_start",
0660, mdla_droot, &cfg_timer_en);
mdla_dc1 = debugfs_create_u32("c1", 0660,
mdla_droot, &cfg_pmu_event[0]);
mdla_dc2 = debugfs_create_u32("c2", 0660,
mdla_droot, &cfg_pmu_event[1]);
mdla_dc3 = debugfs_create_u32("c3", 0660,
mdla_droot, &cfg_pmu_event[2]);
mdla_dc4 = debugfs_create_u32("c4", 0660,
mdla_droot, &cfg_pmu_event[3]);
mdla_dc5 = debugfs_create_u32("c5", 0660,
mdla_droot, &cfg_pmu_event[4]);
mdla_dc6 = debugfs_create_u32("c6", 0660,
mdla_droot, &cfg_pmu_event[5]);
mdla_dc7 = debugfs_create_u32("c7", 0660,
mdla_droot, &cfg_pmu_event[6]);
mdla_dc8 = debugfs_create_u32("c8", 0660,
mdla_droot, &cfg_pmu_event[7]);
mdla_dc9 = debugfs_create_u32("c9", 0660,
mdla_droot, &cfg_pmu_event[8]);
mdla_dc10 = debugfs_create_u32("c10", 0660,
mdla_droot, &cfg_pmu_event[9]);
mdla_dc11 = debugfs_create_u32("c11",
0660, mdla_droot, &cfg_pmu_event[10]);
mdla_dc12 = debugfs_create_u32("c12",
0660, mdla_droot, &cfg_pmu_event[11]);
mdla_dc13 = debugfs_create_u32("c13",
0660, mdla_droot, &cfg_pmu_event[12]);
mdla_dc14 = debugfs_create_u32("c14",
0660, mdla_droot, &cfg_pmu_event[13]);
mdla_dc15 = debugfs_create_u32("c15",
0660, mdla_droot, &cfg_pmu_event[14]);
mdla_dperiod = debugfs_create_u64("period",
0660, mdla_droot, &cfg_period);
mdla_dcmd_trace = debugfs_create_u32("cmd_trace",
0660, mdla_droot, &cfg_cmd_trace);
mdla_dop_trace = debugfs_create_u32("op_trace",
0660, mdla_droot, &cfg_op_trace);
#define CREATE_MDLA_DEBUGFS(name) \
{ \
mdla_d##name = debugfs_create_file(#name, 0644, \
mdla_droot, \
NULL, &mdla_debug_ ## name ## _fops); \
if (IS_ERR_OR_NULL(mdla_d##name)) \
LOG_ERR("failed to create debug file[" #name "].\n"); \
}
CREATE_MDLA_DEBUGFS(register);
CREATE_MDLA_DEBUGFS(opp_table);
CREATE_MDLA_DEBUGFS(power);
CREATE_MDLA_DEBUGFS(prof);
#undef CREATE_MDLA_DEBUGFS
cfg_eng0 = 0x0;
cfg_eng1 = 0x0;
cfg_eng2 = 0x0;
cfg_eng11 = 0x600;
}
void mdla_debugfs_exit(void)
{
#define REMOVE_MDLA_DEBUGFS(name) \
debugfs_remove(mdla_d##name)
REMOVE_MDLA_DEBUGFS(timeout);
REMOVE_MDLA_DEBUGFS(poweroff_time);
REMOVE_MDLA_DEBUGFS(klog);
REMOVE_MDLA_DEBUGFS(register);
REMOVE_MDLA_DEBUGFS(opp_table);
REMOVE_MDLA_DEBUGFS(power);
REMOVE_MDLA_DEBUGFS(prof_start);
REMOVE_MDLA_DEBUGFS(prof);
REMOVE_MDLA_DEBUGFS(period);
REMOVE_MDLA_DEBUGFS(cmd_trace);
REMOVE_MDLA_DEBUGFS(op_trace);
REMOVE_MDLA_DEBUGFS(eng0);
REMOVE_MDLA_DEBUGFS(eng1);
REMOVE_MDLA_DEBUGFS(eng2);
REMOVE_MDLA_DEBUGFS(eng11);
REMOVE_MDLA_DEBUGFS(c1);
REMOVE_MDLA_DEBUGFS(c2);
REMOVE_MDLA_DEBUGFS(c3);
REMOVE_MDLA_DEBUGFS(c4);
REMOVE_MDLA_DEBUGFS(c5);
REMOVE_MDLA_DEBUGFS(c6);
REMOVE_MDLA_DEBUGFS(c7);
REMOVE_MDLA_DEBUGFS(c8);
REMOVE_MDLA_DEBUGFS(c9);
REMOVE_MDLA_DEBUGFS(c10);
REMOVE_MDLA_DEBUGFS(c11);
REMOVE_MDLA_DEBUGFS(c12);
REMOVE_MDLA_DEBUGFS(c13);
REMOVE_MDLA_DEBUGFS(c14);
REMOVE_MDLA_DEBUGFS(c15);
REMOVE_MDLA_DEBUGFS(root);
}
#define dump_reg_top(name) \
mdla_timeout_debug("%s: %.8x\n", #name, mdla_reg_read(name))
#define dump_reg_cfg(name) \
mdla_timeout_debug("%s: %.8x\n", #name, mdla_cfg_read(name))
void dump_timeout_debug_info(void)
{
u32 mreg_top_g_idle, c2r_exe_st, ste_debug_if_1;
int i;
mreg_top_g_idle = mdla_reg_read(MREG_TOP_G_IDLE);
c2r_exe_st = mdla_reg_read(0x0000);
ste_debug_if_1 = mdla_reg_read(0x0EA8);
if (((ste_debug_if_1&0x1C0) != 0x0 && (ste_debug_if_1&0x3) == 0x3)) {
mdla_timeout_debug(
"Matched, %s, mdla_timeout:%d, mreg_top_g_idle: %08x, c2r_exe_st: %08x, ste_debug_if_1: %08x\n",
__func__, mdla_timeout,
mreg_top_g_idle, c2r_exe_st, ste_debug_if_1);
} else {
mdla_timeout_debug(
"Not match, %s, mdla_timeout:%d, mreg_top_g_idle: %08x, c2r_exe_st: %08x, ste_debug_if_1: %08x\n",
__func__, mdla_timeout,
mreg_top_g_idle, c2r_exe_st, ste_debug_if_1);
}
mdla_timeout_debug("0x19000148: %08X\n",
ioread32(apu_conn_top + 0x148));
mdla_timeout_debug("0x19000150: %08X\n",
ioread32(apu_conn_top + 0x150));
mdla_timeout_debug("0x1902006C: %08X\n",
ioread32(apu_conn_top + 0x2006C));
mdla_timeout_debug("0x19020070: %08X\n",
ioread32(apu_conn_top + 0x20070));
for (i = 0x0000; i < 0x1000; i += 4)
mdla_timeout_debug("0x1938%04X: %08X\n", i, mdla_cfg_read(i));
for (i = 0x0000; i < 0x1000; i += 4)
mdla_timeout_debug("0x1939%04X: %08X\n", i, mdla_reg_read(i));
}
void mdla_dump_reg(void)
{
mdla_timeout_debug("mdla_timeout\n");
// TODO: too many registers, dump only debug required ones.
dump_reg_cfg(MDLA_CG_CON);
dump_reg_cfg(MDLA_SW_RST);
dump_reg_cfg(MDLA_MBIST_MODE0);
dump_reg_cfg(MDLA_MBIST_MODE1);
dump_reg_cfg(MDLA_MBIST_CTL);
dump_reg_cfg(MDLA_RP_OK0);
dump_reg_cfg(MDLA_RP_OK1);
dump_reg_cfg(MDLA_RP_OK2);
dump_reg_cfg(MDLA_RP_OK3);
dump_reg_cfg(MDLA_RP_FAIL0);
dump_reg_cfg(MDLA_RP_FAIL1);
dump_reg_cfg(MDLA_RP_FAIL2);
dump_reg_cfg(MDLA_RP_FAIL3);
dump_reg_cfg(MDLA_MBIST_FAIL0);
dump_reg_cfg(MDLA_MBIST_FAIL1);
dump_reg_cfg(MDLA_MBIST_FAIL2);
dump_reg_cfg(MDLA_MBIST_FAIL3);
dump_reg_cfg(MDLA_MBIST_FAIL4);
dump_reg_cfg(MDLA_MBIST_FAIL5);
dump_reg_cfg(MDLA_MBIST_DONE0);
dump_reg_cfg(MDLA_MBIST_DONE1);
dump_reg_cfg(MDLA_MBIST_DEFAULT_DELSEL);
dump_reg_cfg(MDLA_SRAM_DELSEL0);
dump_reg_cfg(MDLA_SRAM_DELSEL1);
dump_reg_cfg(MDLA_RP_RST);
dump_reg_cfg(MDLA_RP_CON);
dump_reg_cfg(MDLA_RP_PRE_FUSE);
dump_reg_cfg(MDLA_AXI_CTRL);
dump_reg_cfg(MDLA_AXI1_CTRL);
dump_reg_top(MREG_TOP_G_REV);
dump_reg_top(MREG_TOP_G_INTP0);
dump_reg_top(MREG_TOP_G_INTP1);
dump_reg_top(MREG_TOP_G_INTP2);
dump_reg_top(MREG_TOP_G_CDMA0);
dump_reg_top(MREG_TOP_G_CDMA1);
dump_reg_top(MREG_TOP_G_CDMA2);
dump_reg_top(MREG_TOP_G_CDMA3);
dump_reg_top(MREG_TOP_G_CDMA4);
dump_reg_top(MREG_TOP_G_CDMA5);
dump_reg_top(MREG_TOP_G_CDMA6);
dump_reg_top(MREG_TOP_G_CUR0);
dump_reg_top(MREG_TOP_G_CUR1);
dump_reg_top(MREG_TOP_G_FIN0);
dump_reg_top(MREG_TOP_G_FIN1);
dump_reg_top(MREG_TOP_G_IDLE);
/* for DCM and CG */
dump_reg_top(MREG_TOP_ENG0);
dump_reg_top(MREG_TOP_ENG1);
dump_reg_top(MREG_TOP_ENG2);
dump_reg_top(MREG_TOP_ENG11);
dump_timeout_debug_info();
}
void mdla_dump_buf(int mask, void *kva, int group, u32 size)
{
if (mdla_klog & mask) {
print_hex_dump_debug("mdla-buf: ",
DUMP_PREFIX_OFFSET, 32, group, kva, size, 0);
}
}
void mdla_dump_ce(struct command_entry *ce)
{
int i;
char *ptr;
if (ce == NULL)
return;
if (!(mdla_klog & MDLA_DBG_TIMEOUT))
return;
if (ce->kva == NULL)
return;
ptr = (char *)ce->kva;
for (i = 0; i < ce->count; i++) {
mdla_timeout_debug("mdla-buf: %s: cmd_id: %u, cmd[%d/%d], kva=%p\n",
__func__, ce->id, i, ce->count, ptr);
mdla_dump_buf(MDLA_DBG_TIMEOUT, ptr, 4, MREG_CMD_SIZE);
ptr += MREG_CMD_SIZE;
}
}
int mdla_dump_register(struct seq_file *s)
{
#define seq_reg_top(name) \
seq_printf(s, "%s: %.8x\n", #name, mdla_reg_read(name))
#define seq_reg_cfg(name) \
seq_printf(s, "%s: %.8x\n", #name, mdla_cfg_read(name))
seq_reg_cfg(MDLA_CG_CON);
seq_reg_cfg(MDLA_SW_RST);
seq_reg_cfg(MDLA_MBIST_MODE0);
seq_reg_cfg(MDLA_MBIST_MODE1);
seq_reg_cfg(MDLA_MBIST_CTL);
seq_reg_cfg(MDLA_RP_OK0);
seq_reg_cfg(MDLA_RP_OK1);
seq_reg_cfg(MDLA_RP_OK2);
seq_reg_cfg(MDLA_RP_OK3);
seq_reg_cfg(MDLA_RP_FAIL0);
seq_reg_cfg(MDLA_RP_FAIL1);
seq_reg_cfg(MDLA_RP_FAIL2);
seq_reg_cfg(MDLA_RP_FAIL3);
seq_reg_cfg(MDLA_MBIST_FAIL0);
seq_reg_cfg(MDLA_MBIST_FAIL1);
seq_reg_cfg(MDLA_MBIST_FAIL2);
seq_reg_cfg(MDLA_MBIST_FAIL3);
seq_reg_cfg(MDLA_MBIST_FAIL4);
seq_reg_cfg(MDLA_MBIST_FAIL5);
seq_reg_cfg(MDLA_MBIST_DONE0);
seq_reg_cfg(MDLA_MBIST_DONE1);
seq_reg_cfg(MDLA_MBIST_DEFAULT_DELSEL);
seq_reg_cfg(MDLA_SRAM_DELSEL0);
seq_reg_cfg(MDLA_SRAM_DELSEL1);
seq_reg_cfg(MDLA_RP_RST);
seq_reg_cfg(MDLA_RP_CON);
seq_reg_cfg(MDLA_RP_PRE_FUSE);
seq_reg_cfg(MDLA_AXI_CTRL);
seq_reg_cfg(MDLA_AXI1_CTRL);
seq_reg_top(MREG_TOP_G_REV);
seq_reg_top(MREG_TOP_G_INTP0);
seq_reg_top(MREG_TOP_G_INTP1);
seq_reg_top(MREG_TOP_G_INTP2);
seq_reg_top(MREG_TOP_G_CDMA0);
seq_reg_top(MREG_TOP_G_CDMA1);
seq_reg_top(MREG_TOP_G_CDMA2);
seq_reg_top(MREG_TOP_G_CDMA3);
seq_reg_top(MREG_TOP_G_CDMA4);
seq_reg_top(MREG_TOP_G_CDMA5);
seq_reg_top(MREG_TOP_G_CDMA6);
seq_reg_top(MREG_TOP_G_CUR0);
seq_reg_top(MREG_TOP_G_CUR1);
seq_reg_top(MREG_TOP_G_FIN0);
seq_reg_top(MREG_TOP_G_FIN1);
return 0;
}
+130
View File
@@ -0,0 +1,130 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef __MDLA_DEBUG_H__
#define __MDLA_DEBUG_H__
#define DEBUG 1
#include "mdla.h"
#include <linux/types.h>
#include <linux/printk.h>
#include <linux/seq_file.h>
extern int g_vpu_log_level;
extern unsigned int g_mdla_func_mask;
extern void *apu_mdla_cmde_mreg_top;
extern void *apu_mdla_config_top;
extern void *apu_conn_top;
/* LOG & AEE */
#define MDLA_TAG "[mdla]"
/*#define VPU_DEBUG*/
#ifdef VPU_DEBUG
#define LOG_DBG(format, args...) pr_debug(MDLA_TAG " " format, ##args)
#else
#define LOG_DBG(format, args...)
#endif
#define LOG_INF(format, args...) pr_info(MDLA_TAG " " format, ##args)
#define LOG_WRN(format, args...) pr_info(MDLA_TAG "[warn] " format, ##args)
#define LOG_ERR(format, args...) pr_info(MDLA_TAG "[error] " format, ##args)
enum MdlaFuncMask {
VFM_NEED_WAIT_VCORE = 0x1,
VFM_ROUTINE_PRT_SYSLOG = 0x2
};
enum MdlaLogThre {
/* >1, performance break down check */
MdlaLogThre_PERFORMANCE = 1,
/* >2, algo info, opp info check */
Log_ALGO_OPP_INFO = 2,
/* >3, state machine check, while wait vcore/do running */
Log_STATE_MACHINE = 3,
/* >4, dump buffer mva */
MdlaLogThre_DUMP_BUF_MVA = 4
};
enum MDLA_power_param {
MDLA_POWER_PARAM_FIX_OPP,
MDLA_POWER_PARAM_DVFS_DEBUG,
MDLA_POWER_PARAM_JTAG,
MDLA_POWER_PARAM_LOCK,
MDLA_POWER_PARAM_VOLT_STEP,
MDLA_POWER_HAL_CTL,
MDLA_EARA_CTL,
};
#define mdla_print_seq(seq_file, format, args...) \
{ \
if (seq_file) \
seq_printf(seq_file, format, ##args); \
else \
LOG_ERR(format, ##args); \
}
/**
* mdla_dump_register - dump the register table, and show the content
* of all fields.
* @s: the pointer to seq_file.
*/
int mdla_dump_register(struct seq_file *s);
/**
* mdla_dump_image_file - dump the binary information stored in flash storage.
* @s: the pointer to seq_file.
*/
int mdla_dump_image_file(struct seq_file *s);
/**
* mdla_dump_mesg - dump the log buffer, which is wroted by VPU
* @s: the pointer to seq_file.
*/
int mdla_dump_mesg(struct seq_file *s);
/**
* mdla_dump_mdla - dump the mdla status
* @s: the pointer to seq_file.
*/
int mdla_dump_mdla(struct seq_file *s);
/**
* mdla_dump_device_dbg - dump the remaining user information to debug fd leak
* @s: the pointer to seq_file.
*/
int mdla_dump_device_dbg(struct seq_file *s);
enum MDLA_DEBUG_MASK {
MDLA_DBG_DRV = 0x01,
MDLA_DBG_MEM = 0x02,
MDLA_DBG_CMD = 0x04,
MDLA_DBG_PMU = 0x08,
MDLA_DBG_PERF = 0x10,
MDLA_DBG_QOS = 0x20,
MDLA_DBG_TIMEOUT = 0x40,
MDLA_DBG_DVFS = 0x80,
};
extern u32 mdla_klog;
#define mdla_debug(mask, ...) do { if (mdla_klog & mask) \
pr_debug(__VA_ARGS__); \
} while (0)
void mdla_dump_reg(void);
void mdla_dump_ce(struct command_entry *ce);
void mdla_dump_buf(int mask, void *kva, int group, u32 size);
void mdla_debugfs_init(void);
void mdla_debugfs_exit(void);
#define mdla_drv_debug(...) mdla_debug(MDLA_DBG_DRV, __VA_ARGS__)
#define mdla_mem_debug(...) mdla_debug(MDLA_DBG_MEM, __VA_ARGS__)
#define mdla_cmd_debug(...) mdla_debug(MDLA_DBG_CMD, __VA_ARGS__)
#define mdla_pmu_debug(...) mdla_debug(MDLA_DBG_PMU, __VA_ARGS__)
#define mdla_perf_debug(...) mdla_debug(MDLA_DBG_PERF, __VA_ARGS__)
#define mdla_qos_debug(...) mdla_debug(MDLA_DBG_QOS, __VA_ARGS__)
#define mdla_timeout_debug(...) mdla_debug(MDLA_DBG_TIMEOUT, __VA_ARGS__)
#define mdla_dvfs_debug(...) mdla_debug(MDLA_DBG_DVFS, __VA_ARGS__)
#endif
@@ -0,0 +1,262 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "mdla_debug.h"
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include "mdla_hw_reg.h"
#include "mdla_decoder.h"
static const char *mreg_str_exe[16] = {
"none",
"CNVL",
"SBL",
"CONV",
"ELW_BN",
"ELW_ACTI",
"POOL",
"STORE",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
};
// CNVL(1): 0 None, 1: conv_preload, 2: Used in fused
static const char *mreg_str_cbl[16] = {
"none",
"conv_preload",
"fused",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
};
// SBL(2): 0: None, 1: Load 1-tensor or DMA, 2: Load 2-tensor
static const char *mreg_str_sbl[16] = {
"none",
"load 1-tensor/DMA",
"load 2-tensor",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
};
// CONV(3): 0: None, 1: conv2D, 2:DW, 3 FC, 4: dilated; 5:De-convolution
static const char *mreg_str_conv[16] = {
"none",
"conv2D",
"DW",
"FC",
"dilated",
"De-convolution",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
};
// ELW_BN(4): 0: None, 1: BN_Add, 2: BN_Mul, 3: BN_Mul+Add,
// 4: EW_Abs, 5: EW_Add, 6: EW_Sub12, 7: EW_Sub21,
// 8: EW_Mul, 9: EW_Max, 10: EW_Min
static const char *mreg_str_elw[16] = {
"none",
"BN_Add",
"BN_Mul",
"BN_Mul+Add",
"EW_Abs",
"EW_Add",
"EW_Sub12",
"EW_Sub21",
"EW_Mul",
"EW_Max",
"EW_Min",
"-",
"-",
"-",
"-",
"-"
};
// ELW_ACTI(5): 0: None, 1: sigmoid, 2: tanh, 4: Relu1,
// 5: Relu6, 6: Relu, 7: Prelu, 8: Elu
static const char *mreg_str_atci[16] = {
"none",
"sigmoid",
"tanh",
"Relu1",
"Relu6",
"Relu",
"Prelu",
"Elu",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
};
// POOL(6): 0: None, 1: AVG, 2: L2, 3: MAX, 4:MIN, 5: Bilinear
static const char *mreg_str_pool[16] = {
"none",
"AVG",
"L2",
"MAX",
"MIN",
"Bilinear",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
};
// STORE(7): 0:None, 1: store to external memory
static const char *mreg_str_ste[16] = {
"none",
"external",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
};
static const char **cmd_map[8] = {
mreg_str_exe, // used as dummy
mreg_str_cbl,
mreg_str_sbl,
mreg_str_conv,
mreg_str_elw,
mreg_str_atci,
mreg_str_pool,
mreg_str_ste
};
static void
mdla_cmd_parse(u32 swid, u32 exec, int func_map[8], char *str, int size)
{
int i;
u8 cmd;
char *ptr = str;
int remain = size;
int out;
mdla_cmd_debug("%s: %xh: cbl=%d sbl=%d conv=%d elw=%d acti=%d pool=%d ste=%d\n",
__func__,
exec,
func_map[1],
func_map[2],
func_map[3],
func_map[4],
func_map[5],
func_map[6],
func_map[7]);
out = snprintf(ptr, remain, "mdla_cmd_id:%u,", swid);
if (out <= 0)
return;
remain -= out;
ptr += out;
for (i = 0; i < 8; i++) {
cmd = (exec & 0xF);
if (!cmd)
break;
out = snprintf(ptr, remain, "%s%d:%s(%d:%s)",
(i) ? "->" : "",
cmd,
mreg_str_exe[cmd],
func_map[cmd],
cmd_map[cmd][func_map[cmd]]);
if (!out)
break;
remain -= out;
ptr += out;
exec = exec >> 4;
}
}
void mdla_decode(const char *cmd, char *str, int size)
{
#define _VAL32(offset) (*((const u32 *)(cmd+offset)))
#define _VAL4(offset) (_VAL32(offset) & 0xF)
int func_map[8] = { 0,
_VAL4(MREG_CMD_CBL_FUNC),
_VAL4(MREG_CMD_SBL_FUNC),
_VAL4(MREG_CMD_CONV_FUNC),
_VAL4(MREG_CMD_ELW_FUNC),
_VAL4(MREG_CMD_ACTI_FUNC),
_VAL4(MREG_CMD_POOL_FUNC_0),
_VAL4(MREG_CMD_STE_FUNC)};
mdla_cmd_parse(
_VAL32(MREG_CMD_SWCMD_ID),
_VAL32(MREG_CMD_EXE_FLOW),
func_map,
str,
size);
#undef _VAL
}
@@ -0,0 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef __MDLA_DECODER_H__
#define __MDLA_DECODER_H__
void mdla_decode(const char *cmd, char *str, int size);
#endif
File diff suppressed because it is too large. Load diff
+197
View File
@@ -0,0 +1,197 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef _MDLA_DVFS_H_
#define _MDLA_DVFS_H_
#include "mdla.h"
#include "mdla_ioctl.h"
#include <linux/of_platform.h>
#include <linux/seq_file.h>
#include <linux/arm-smccc.h>
#include <linux/soc/mediatek/mtk_sip_svc.h>
/* ++++++++++++++++++++++++++++++++++*/
/* |opp_index | mdla frequency | power */
/* ------------------------------------------*/
/* | 0 | 788 MHz | 336 mA */
/* ------------------------------------------*/
/* | 1 | 700 MHz | 250 mA */
/* ------------------------------------------*/
/* | 2 | 624 MHz | 221 mA */
/* ------------------------------------------*/
/* | 3 | 606 MHz | 208 mA */
/* ------------------------------------------*/
/* | 4 | 594 MHz | 140 mA */
/* ------------------------------------------*/
/* | 5 | 546 MHz | 120 mA */
/* ------------------------------------------*/
/* | 6 | 525 MHz | 114 mA */
/* ------------------------------------------*/
/* | 7 | 450 MHz | 84 mA */
/* ------------------------------------------*/
/* | 8 | 416 MHz | 336 mA */
/* ------------------------------------------*/
/* | 9 | 364 MHz | 250 mA */
/* ------------------------------------------*/
/* | 10 | 312 MHz | 221 mA */
/* ------------------------------------------*/
/* | 11 | 273 MHz | 208 mA */
/* ------------------------------------------*/
/* | 12 | 208 MHz | 140 mA */
/* ------------------------------------------*/
/* | 13 | 137 MHz | 120 mA */
/* ------------------------------------------*/
/* | 14 | 52 MHz | 114 mA */
/* ------------------------------------------*/
/* | 15 | 26 MHz | 114 mA */
/* ------------------------------------------*/
/* ++++++++++++++++++++++++++++++++++*/
enum MDLA_OPP_INDEX {
MDLA_OPP_0 = 0,
MDLA_OPP_1 = 1,
MDLA_OPP_2 = 2,
MDLA_OPP_3 = 3,
MDLA_OPP_4 = 4,
MDLA_OPP_5 = 5,
MDLA_OPP_6 = 6,
MDLA_OPP_7 = 7,
MDLA_OPP_8 = 8,
MDLA_OPP_9 = 9,
MDLA_OPP_10 = 10,
MDLA_OPP_11 = 11,
MDLA_OPP_12 = 12,
MDLA_OPP_NUM
};
struct MDLA_OPP_INFO {
enum MDLA_OPP_INDEX opp_index;
int power; /*mW*/
};
#define MDLA_MAX_NUM_STEPS (16)
#define MDLA_MAX_NUM_OPPS (16)
//#define MTK_MDLA_CORE (1)
#define MTK_MDLA_USER (2)
#define MTK_VPU_CORE_NUM (2)
struct mdla_dvfs_steps {
uint32_t values[MDLA_MAX_NUM_STEPS];
uint8_t count;
uint8_t index;
uint8_t opp_map[MDLA_MAX_NUM_OPPS];
};
struct mdla_dvfs_opps {
struct mdla_dvfs_steps vcore;
struct mdla_dvfs_steps vvpu;
struct mdla_dvfs_steps vmdla;
struct mdla_dvfs_steps dsp; /* ipu_conn */
struct mdla_dvfs_steps dspcore[MTK_VPU_CORE_NUM]; /* ipu_core# */
struct mdla_dvfs_steps mdlacore; /* ipu_core# */
struct mdla_dvfs_steps ipu_if; /* ipusys_vcore, interface */
uint8_t index;
uint8_t count;
};
enum mdlaPowerOnType {
/* power on previously by setPower */
MDLA_PRE_ON = 1,
/* power on by enque */
MDLA_ENQUE_ON = 2,
/* power on by enque, but want to immediately off(when exception) */
MDLA_IMT_OFF = 3,
};
/*3 prioritys of cmd*/
#define MDLA_REQ_MAX_NUM_PRIORITY 3
extern struct MDLA_OPP_INFO mdla_power_table[MDLA_OPP_NUM];
int32_t mdla_thermal_en_throttle_cb(uint8_t vmdla_opp, uint8_t mdla_opp);
int32_t mdla_thermal_dis_throttle_cb(void);
int mdla_quick_suspend(int core);
int mdla_get_opp(void);
int get_mdlacore_opp(void);
int get_mdla_platform_floor_opp(void);
int get_mdla_ceiling_opp(void);
int get_mdla_opp_to_freq(uint8_t step);
void mdla_put_power(int core);
int mdla_get_power(int core);
void mdla_opp_check(int core, uint8_t vmdla_index, uint8_t freq_index);
#ifndef MTK_MDLA_FPGA_PORTING
int mdla_init_hw(int core, struct platform_device *pdev);
int mdla_uninit_hw(void);
int mdla_set_power_parameter(uint8_t param, int argc, int *args);
int mdla_dump_power(struct seq_file *s);
int mdla_dump_opp_table(struct seq_file *s);
long mdla_dvfs_ioctl(struct file *filp, unsigned int command,
unsigned long arg);
int mdla_dvfs_cmd_start(struct command_entry *ce);
int mdla_dvfs_cmd_end_info(struct command_entry *ce);
int mdla_dvfs_cmd_end_shutdown(void);
#else
static inline
int mdla_init_hw(int core, struct platform_device *pdev)
{
return 0;
}
static inline
int mdla_uninit_hw(void)
{
return 0;
}
static inline
int mdla_set_power_parameter(uint8_t param, int argc, int *args)
{
return 0;
}
static inline
int mdla_dump_power(struct seq_file *s)
{
return 0;
}
static inline
int mdla_dump_opp_table(struct seq_file *s)
{
return 0;
}
static inline
long mdla_dvfs_ioctl(struct file *filp, unsigned int command,
unsigned long arg)
{
return 0;
}
static inline
int mdla_dvfs_cmd_start(struct command_entry *ce)
{
return 0;
}
static inline
int mdla_dvfs_cmd_end_info(struct command_entry *ce)
{
return 0;
}
static inline
int mdla_dvfs_cmd_end_shutdown(void)
{
return 0;
}
#endif
#endif
+207
View File
@@ -0,0 +1,207 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef _MDLAIOCTL_
#define _MDLAIOCTL_
#include <stdbool.h>
#include <linux/ioctl.h>
#include <linux/types.h>
/* Memory type for mdla_buf_alloc */
enum mem_type {
MEM_DRAM,
MEM_IOMMU,
MEM_GSM
};
enum MDLA_PMU_INTERFACE {
MDLA_PMU_IF_WDEC0 = 0xe,
MDLA_PMU_IF_WDEC1 = 0xf,
MDLA_PMU_IF_CBLD0 = 0x10,
MDLA_PMU_IF_CBLD1 = 0x11,
MDLA_PMU_IF_SBLD0 = 0x12,
MDLA_PMU_IF_SBLD1 = 0x13,
MDLA_PMU_IF_STE0 = 0x14,
MDLA_PMU_IF_STE1 = 0x15,
MDLA_PMU_IF_CMDE = 0x16,
MDLA_PMU_IF_DDE = 0x17,
MDLA_PMU_IF_CONV = 0x18,
MDLA_PMU_IF_RQU = 0x19,
MDLA_PMU_IF_POOLING = 0x1a,
MDLA_PMU_IF_EWE = 0x1b,
MDLA_PMU_IF_CFLD = 0x1c
};
enum MDLA_PMU_DDE_EVENT {
MDLA_PMU_DDE_WORK_CYC = 0x0,
MDLA_PMU_DDE_TILE_DONE_CNT,
MDLA_PMU_DDE_EFF_WORK_CYC,
MDLA_PMU_DDE_BLOCK_CNT,
MDLA_PMU_DDE_READ_CB_WT_CNT,
MDLA_PMU_DDE_READ_CB_ACT_CNT,
MDLA_PMU_DDE_WAIT_CB_TOKEN_CNT,
MDLA_PMU_DDE_WAIT_CONV_RDY_CNT,
MDLA_PMU_DDE_WAIT_CB_FCWT_CNT,
};
enum MDLA_PMU_MODE {
MDLA_PMU_ACC_MODE = 0x0,
MDLA_PMU_INTERVAL_MODE = 0x1,
};
#define MDLA_IOC_MAGIC (0x3d1a632fULL)
struct ioctl_malloc {
__u32 size; /* [in] allocate size */
__u32 mva; /* [out] modified virtual address */
void *pa; /* [out] physical address */
void *kva; /* [out] kernel virtual address */
__u8 type; /* [in] allocate memory type */
void *data; /* [out] userspace virtual address */
};
struct ioctl_run_cmd {
struct {
uint32_t size;
uint32_t mva;
void *pa;
void *kva;
uint32_t id;
uint8_t type;
void *data;
int ion_share_fd;
int ion_handle; /* user space handle */
uint64_t ion_khandle; /* kernel space handle */
} buf;
__u32 offset; /* [in] command byte offset in buf */
__u32 count; /* [in] # of commands */
__u32 id; /* [out] command id */
__u8 priority; /* [in] dvfs priority */
__u8 boost_value; /* [in] dvfs boost value */
};
enum MDLA_CMD_RESULT {
MDLA_CMD_SUCCESS = 0,
MDLA_CMD_TIMEOUT = 1,
};
#define MDLA_IOC_SET_ARRAY_CNT(n) \
((MDLA_IOC_MAGIC << 32) | ((n) & 0xFFFFFFFF))
#define MDLA_IOC_GET_ARRAY_CNT(n) \
(((n >> 32) == MDLA_IOC_MAGIC) ? ((n) & 0xFFFFFFFF) : 0)
#define MDLA_IOC_SET_ARRAY_PTR(a) \
((unsigned long)(a))
#define MDLA_IOC_GET_ARRAY_PTR(a) \
((void *)((unsigned long)(a)))
#define MDLA_WAIT_CMD_ARRAY_SIZE 6
struct ioctl_wait_cmd {
__u32 id; /* [in] command id */
int result; /* [out] success(0), timeout(1) */
uint64_t queue_time; /* [out] time queued in driver (ns) */
uint64_t busy_time; /* [out] mdla execution time (ns) */
uint32_t bandwidth; /* [out] mdla bandwidth */
};
struct ioctl_run_cmd_sync {
struct ioctl_run_cmd req;
struct ioctl_wait_cmd res;
};
struct ioctl_perf {
int handle;
__u32 interface;
__u32 event;
__u32 counter;
__u32 start;
__u32 end;
__u32 mode;
};
struct ioctl_ion {
int fd; /* [in] user handle, eq. ion_user_handle_t */
__u64 mva; /* [in] phyiscal address */
__u64 kva; /* [in(unmap)/out(map)] kernel virtual address */
__u64 khandle; /* [in(unmap)/out(map)] kernel handle */
size_t len; /* [in] memory size */
};
enum MDLA_CONFIG {
MDLA_CFG_NONE = 0,
MDLA_CFG_TIMEOUT_GET = 1,
MDLA_CFG_TIMEOUT_SET = 2,
MDLA_CFG_FIFO_SZ_GET = 3,
MDLA_CFG_FIFO_SZ_SET = 4,
MDLA_CFG_GSM_INFO = 5,
};
struct ioctl_config {
__u32 op;
__u32 arg_count;
__u64 arg[8];
};
struct mdla_power {
uint8_t boost_value;
/* align with core index defined in user space header file */
unsigned int core;
};
enum MDLA_OPP_PRIORIYY {
MDLA_OPP_DEBUG = 0,
MDLA_OPP_THERMAL = 1,
MDLA_OPP_POWER_HAL = 2,
MDLA_OPP_EARA_QOS = 3,
MDLA_OPP_NORMAL = 4,
MDLA_OPP_PRIORIYY_NUM
};
struct mdla_lock_power {
unsigned int core;
uint8_t max_boost_value;
uint8_t min_boost_value;
bool lock;
enum MDLA_OPP_PRIORIYY priority;
};
#define IOC_MDLA ('\x1d')
#define IOCTL_MALLOC _IOWR(IOC_MDLA, 0, struct ioctl_malloc)
#define IOCTL_FREE _IOWR(IOC_MDLA, 1, struct ioctl_malloc)
#define IOCTL_RUN_CMD_SYNC _IOWR(IOC_MDLA, 2, struct ioctl_run_cmd)
#define IOCTL_RUN_CMD_ASYNC _IOWR(IOC_MDLA, 3, struct ioctl_run_cmd_sync)
#define IOCTL_WAIT_CMD _IOWR(IOC_MDLA, 4, struct ioctl_wait_cmd)
#define IOCTL_PERF_SET_EVENT _IOWR(IOC_MDLA, 5, struct ioctl_perf)
#define IOCTL_PERF_GET_EVENT _IOWR(IOC_MDLA, 6, struct ioctl_perf)
#define IOCTL_PERF_GET_CNT _IOWR(IOC_MDLA, 7, struct ioctl_perf)
#define IOCTL_PERF_UNSET_EVENT _IOWR(IOC_MDLA, 8, struct ioctl_perf)
#define IOCTL_PERF_GET_START _IOWR(IOC_MDLA, 9, struct ioctl_perf)
#define IOCTL_PERF_GET_END _IOWR(IOC_MDLA, 10, struct ioctl_perf)
#define IOCTL_PERF_GET_CYCLE _IOWR(IOC_MDLA, 11, struct ioctl_perf)
#define IOCTL_PERF_RESET_CNT _IOWR(IOC_MDLA, 12, struct ioctl_perf)
#define IOCTL_PERF_RESET_CYCLE _IOWR(IOC_MDLA, 13, struct ioctl_perf)
#define IOCTL_PERF_SET_MODE _IOWR(IOC_MDLA, 14, struct ioctl_perf)
#define IOCTL_ION_KMAP _IOWR(IOC_MDLA, 15, struct ioctl_ion)
#define IOCTL_ION_KUNMAP _IOWR(IOC_MDLA, 16, struct ioctl_ion)
/* 17 ~ 63: reserved for DVFS */
#define IOCTL_SET_POWER _IOW(IOC_MDLA, 17, struct mdla_power)
#define IOCTL_EARA_LOCK_POWER _IOW(IOC_MDLA, 18, struct mdla_lock_power)
#define IOCTL_POWER_HAL_LOCK_POWER _IOW(IOC_MDLA, 19, struct mdla_lock_power)
#define IOCTL_EARA_UNLOCK_POWER _IOW(IOC_MDLA, 20, struct mdla_lock_power)
#define IOCTL_POWER_HAL_UNLOCK_POWER _IOW(IOC_MDLA, 21, struct mdla_lock_power)
#define MDLA_DVFS_IOCTL_START IOCTL_SET_POWER
#define MDLA_DVFS_IOCTL_END IOCTL_POWER_HAL_UNLOCK_POWER
#define IOCTL_CONFIG _IOWR(IOC_MDLA, 64, struct ioctl_config)
#endif
+163
View File
@@ -0,0 +1,163 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "mdla_debug.h"
#include <linux/types.h>
#include <ion.h>
#include <mtk/ion_drv.h>
#include <mtk/mtk_ion.h>
#include <linux/uaccess.h>
#include <linux/err.h>
#include <m4u.h>
#include "mdla_ioctl.h"
#include "mdla_ion.h"
static struct ion_client *ion_client;
void mdla_ion_init(void)
{
ion_client = ion_client_create(g_ion_device, "mdla");
mdla_drv_debug("%s: ion_client_create(): %p\n", __func__, ion_client);
}
void mdla_ion_exit(void)
{
if (ion_client) {
mdla_drv_debug("%s: %p\n", __func__, ion_client);
ion_client_destroy(ion_client);
ion_client = NULL;
}
}
int mdla_ion_kmap(unsigned long arg)
{
struct ioctl_ion ion_data;
struct ion_mm_data mm_data;
struct ion_handle *hndl;
ion_phys_addr_t mva;
void *kva;
int ret;
if (!ion_client)
return -ENOENT;
if (copy_from_user(&ion_data, (void * __user) arg, sizeof(ion_data)))
return -EFAULT;
mdla_mem_debug("%s: share fd: %d\n", __func__, ion_data.fd);
hndl = ion_import_dma_buf_fd(ion_client, ion_data.fd);
if (IS_ERR_OR_NULL(hndl)) {
mdla_mem_debug("%s: ion_import_dma_buf_fd(): failed: %ld\n",
__func__, PTR_ERR(hndl));
return -EINVAL;
}
mdla_mem_debug("%s: ion_import_dma_buf_fd(): %p\n", __func__, hndl);
/* set memory port */
mm_data.mm_cmd = ION_MM_CONFIG_BUFFER;
mm_data.config_buffer_param.kernel_handle = hndl;
mm_data.config_buffer_param.module_id = M4U_PORT_VPU;
ret = ion_kernel_ioctl(ion_client, ION_CMD_MULTIMEDIA,
(unsigned long) &mm_data);
if (ret < 0) {
mdla_mem_debug("%s: ion_kernel_ioctl(%p, %p): %d\n",
__func__, ion_client, hndl, ret);
return -EINVAL;
}
/* map to to kernel virtual address */
kva = ion_map_kernel(ion_client, hndl);
if (IS_ERR_OR_NULL(kva)) {
mdla_mem_debug("%s: ion_map_kernel(%p, %p): %d\n",
__func__, ion_client, hndl, ret);
return -EINVAL;
}
/* Get the phyiscal address (mva) to the buffer */
ret = ion_phys(ion_client, hndl, &mva, &ion_data.len);
if (ret < 0) {
mdla_mem_debug("%s: ion_phys(%p, %p): %d\n",
__func__, ion_client, hndl, ret);
return -EINVAL;
}
ion_data.kva = (__u64) kva;
ion_data.mva = mva;
ion_data.khandle = (__u64) hndl;
if (copy_to_user((void * __user) arg, &ion_data, sizeof(ion_data)))
return -EFAULT;
mdla_mem_debug("%s: mva=%llxh, kva=%llxh, kernel_handle=%llxh\n",
__func__, ion_data.mva, ion_data.kva, ion_data.khandle);
return 0;
}
int mdla_ion_kunmap(unsigned long arg)
{
struct ioctl_ion ion_data;
struct ion_handle *hndl;
if (!ion_client)
return -ENOENT;
if (copy_from_user(&ion_data, (void * __user) arg, sizeof(ion_data)))
return -EFAULT;
mdla_mem_debug("%s: mva=%llxh, kva=%llxh, kernel_handle=%llxh\n",
__func__, ion_data.mva, ion_data.kva, ion_data.khandle);
hndl = ion_drv_get_handle(ion_client, ion_data.fd, NULL, false);
if (IS_ERR_OR_NULL(hndl))
return -EINVAL;
if (hndl != (struct ion_handle *)ion_data.khandle) {
mdla_mem_debug("%s: user_handle=%d, get khandle=%llxh\n",
__func__, ion_data.fd, hndl);
LOG_ERR("%s: invalid ion kernel handle\n", __func__);
return -EINVAL;
}
ion_unmap_kernel(ion_client, hndl);
ion_free(ion_client, hndl);
return 0;
}
void mdla_ion_sync(u64 hndl, void *kva, u32 size)
{
struct ion_sys_data sys_data;
int ret;
sys_data.sys_cmd = ION_SYS_CACHE_SYNC;
sys_data.cache_sync_param.kernel_handle =
(struct ion_handle *)hndl;
sys_data.cache_sync_param.sync_type = ION_CACHE_FLUSH_BY_RANGE;
sys_data.cache_sync_param.va = kva;
sys_data.cache_sync_param.size = size;
ret = ion_kernel_ioctl(ion_client, ION_CMD_SYSTEM,
(unsigned long)&sys_data);
mdla_mem_debug("%s: ion_kernel_ioctl kernel_handle=%llx\n",
__func__, (unsigned long long)hndl);
if (ret) {
mdla_mem_debug("%s: ion_kernel_ioctl(hndl=%llx): %d failed\n",
__func__, (unsigned long long)hndl, ret);
}
}
+38
View File
@@ -0,0 +1,38 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include <linux/types.h>
#ifdef CONFIG_MTK_ION
void mdla_ion_init(void);
void mdla_ion_exit(void);
int mdla_ion_kmap(unsigned long arg);
int mdla_ion_kunmap(unsigned long arg);
void mdla_ion_sync(u64 hndl, void *kva, u32 size);
#else
static inline
void mdla_ion_init(void)
{
}
static inline
void mdla_ion_exit(void)
{
}
static inline
int mdla_ion_kmap(unsigned long arg)
{
return -EINVAL;
}
static inline
int mdla_ion_kunmap(unsigned long arg)
{
return -EINVAL;
}
static inline
void mdla_ion_sync(u64 hndl, void *kva, u32 size)
{
}
#endif
File diff suppressed because it is too large. Load diff
+310
View File
@@ -0,0 +1,310 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "mdla_debug.h"
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include "mdla.h"
#include "mdla_hw_reg.h"
#include "mdla_trace.h"
#include "mdla_decoder.h"
#include "met_mdlasys_events.h"
#include <linux/kallsyms.h>
#include <linux/preempt.h>
#define TRACE_LEN 128
#define PERIOD_DEFAULT 1000 // in micro-seconds (us)
static struct hrtimer hr_timer;
u64 cfg_period;
int cfg_op_trace;
int cfg_cmd_trace;
static int cfg_pmu_int;
int cfg_timer_en;
u32 cfg_eng0;
u32 cfg_eng1;
u32 cfg_eng2;
u32 cfg_eng11;
static int timer_started;
static noinline int tracing_mark_write(const char *buf)
{
trace_printk(buf);
return 0;
}
void mdla_trace_custom(const char *fmt, ...)
{
char buf[TRACE_LEN];
va_list args;
int len;
va_start(args, fmt);
len = vsnprintf(buf, TRACE_LEN, fmt, args);
va_end(args);
if (len > 0)
tracing_mark_write(buf);
}
void mdla_trace_begin(struct command_entry *ce)
{
char buf[TRACE_LEN];
char *p;
int len;
u32 cmd_num;
void *cmd;
if (!ce)
return;
if (!cfg_cmd_trace)
return;
p = cmd = ce->kva;
cmd_num = ce->count;
len = snprintf(buf, sizeof(buf),
"I|%d|MDLA|B|mdla_cmd_id:%d,mdla_cmd_num:%d",
task_pid_nr(current),
1,
cmd_num);
if (len <= 0)
return;
else if (len >= TRACE_LEN)
buf[TRACE_LEN - 1] = '\0';
mdla_perf_debug("%s\n", __func__);
tracing_mark_write(buf);
}
void mdla_trace_end(struct command_entry *ce)
{
u64 end = ce->req_end_t;
u32 cmd_id = ce->count;
/* EARA Qos*/
ce->bandwidth = mdla_cmd_qos_end(0);
if ((!cfg_cmd_trace) || (!end))
return;
mdla_perf_debug("%s\n", __func__);
mdla_trace_custom(
"I|%d|MDLA|E|mdla_cmd_id:%d,cycle:%u,sched_clock_result:%llu",
task_pid_nr(current),
cmd_id,
pmu_get_perf_cycle(),
(unsigned long long) end);
}
/* MET: define to enable MET */
#if defined(MDLA_MET_READY)
#define CREATE_TRACE_POINTS
#include "met_mdlasys_events.h"
#endif
void mdla_dump_prof(struct seq_file *s)
{
int i;
u32 c[MDLA_PMU_COUNTERS] = {0};
#define _SHOW_VAL(t) \
mdla_print_seq(s, "%s=%lu\n", #t, (unsigned long)cfg_##t)
_SHOW_VAL(period);
_SHOW_VAL(cmd_trace);
_SHOW_VAL(op_trace);
_SHOW_VAL(pmu_int);
pmu_counter_event_get_all(c);
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
mdla_print_seq(s, "c%d=0x%x\n", (i+1), c[i]);
}
/*
* MDLA PMU counter reader
*/
static void mdla_profile_pmu_counter(int core)
{
u32 c[MDLA_PMU_COUNTERS] = {0};
pmu_counter_read_all(c);
mdla_perf_debug("_id=c%d, c1=%u, c2=%u, c3=%u, c4=%u, c5=%u, c6=%u, c7=%u, c8=%u, c9=%u, c10=%u, c11=%u, c12=%u, c13=%u, c14=%u, c15=%u\n",
core,
c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7],
c[8], c[9], c[10], c[11], c[12], c[13], c[14]);
trace_mdla_polling(core, c);
}
static void mdla_profile_register_read(void)
{
int i = 0;
if (!get_power_on_status())
return;
for (i = 0 ; i < MTK_MDLA_CORE; i++)
mdla_profile_pmu_counter(i);
}
void mdla_trace_iter(void)
{
mutex_lock(&power_lock);
if (cfg_timer_en)
mdla_profile_register_read();
mutex_unlock(&power_lock);
}
/* restore trace settings after reset */
int mdla_profile_reset(const char *str)
{
if (cfg_cmd_trace)
mdla_trace_custom("I|%d|MDLA|C|reset:%s",
task_pid_nr(current), str);
return 0;
}
int mdla_profile_init(void)
{
cfg_period = PERIOD_DEFAULT;
cfg_op_trace = 0;
cfg_cmd_trace = 0;
cfg_pmu_int = MDLA_TRACE_MODE_CMD;
cfg_timer_en = 0;
timer_started = 0;
return 0;
}
#define MDLA_TRACE_TAG_EN 0
void mdla_trace_tag_begin(const char *format, ...)
{
#if MDLA_TRACE_TAG_EN
char buf[TRACE_LEN];
int len = snprintf(buf, sizeof(buf),
"B|%d|%s", format, task_pid_nr(current));
if (len >= TRACE_LEN)
len = TRACE_LEN - 1;
tracing_mark_write(buf);
#endif
}
void mdla_trace_tag_end(void)
{
#if MDLA_TRACE_TAG_EN
char buf[TRACE_LEN];
int len = snprintf(buf, sizeof(buf), "E\n");
if (len >= TRACE_LEN)
len = TRACE_LEN - 1;
tracing_mark_write(buf);
#endif
}
/*
* MDLA event based MET funcs
*/
void mdla_met_event_enter(int core, int vmdla_opp,
int dsp_freq, int ipu_if_freq, int mdla_freq)
{
#if defined(MDLA_MET_READY)
trace_mdla_cmd_enter(core, vmdla_opp, dsp_freq,
ipu_if_freq, mdla_freq);
#endif
}
void mdla_met_event_leave(int core)
{
#if defined(MDLA_MET_READY)
trace_mdla_cmd_leave(core, 0);
#endif
}
/*
* MDLA Polling Function
*/
static enum hrtimer_restart mdla_profile_polling(struct hrtimer *timer)
{
if (!cfg_period || !cfg_timer_en)
return HRTIMER_NORESTART;
/*call functions need to be called periodically*/
mdla_profile_register_read();
hrtimer_forward_now(&hr_timer, ns_to_ktime(cfg_period * 1000));
return HRTIMER_RESTART;
}
static int mdla_profile_timer_start(void)
{
hrtimer_init(&hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
hr_timer.function = mdla_profile_polling;
hrtimer_start(&hr_timer, ns_to_ktime(cfg_period * 1000),
HRTIMER_MODE_REL);
mdla_perf_debug("%s: hrtimer_start()\n", __func__);
return 0;
}
static int mdla_profile_timer_stop(int wait)
{
int ret = 0;
if (wait) {
hrtimer_cancel(&hr_timer);
mdla_perf_debug("%s: hrtimer_cancel()\n", __func__);
} else {
ret = hrtimer_try_to_cancel(&hr_timer);
mdla_perf_debug("%s: hrtimer_try_to_cancel(): %d\n",
__func__, ret);
}
return ret;
}
/* protected by cmd_list_lock @ mdla_main.c */
int mdla_profile_start(void)
{
pmu_reset();
if (!cfg_timer_en)
return 0;
if (!timer_started) {
mdla_profile_timer_start();
timer_started = 1;
}
return 0;
}
int mdla_profile_stop(int wait)
{
if (timer_started) {
mdla_profile_timer_stop(wait);
timer_started = 0;
}
return 0;
}
int mdla_profile_exit(void)
{
cfg_period = 0;
mdla_profile_stop(1);
return 0;
}
@@ -0,0 +1,48 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef __MDLA_TRACE_H__
#define __MDLA_TRACE_H__
#include "mdla_qos.h"
#include "mdla_pmu.h"
extern u64 cfg_period;
extern int cfg_op_trace;
extern int cfg_cmd_trace;
extern int cfg_timer_en;
extern u32 cfg_eng0;
extern u32 cfg_eng1;
extern u32 cfg_eng2;
extern u32 cfg_eng11;
extern int get_power_on_status(void);
extern struct mutex power_lock;
enum {
MDLA_TRACE_MODE_CMD = 0,
MDLA_TRACE_MODE_INT = 1
};
extern u32 cfg_pmu_event[MDLA_PMU_COUNTERS];
#define MDLA_MET_READY 1
#include <linux/sched.h>
int mdla_profile_init(void);
int mdla_profile_exit(void);
int mdla_profile_reset(const char *str);
int mdla_profile(const char *str);
int mdla_profile_power_mode(u32 *stat);
void mdla_dump_prof(struct seq_file *s);
void mdla_trace_begin(struct command_entry *ce);
void mdla_trace_iter(void);
int mdla_profile_start(void);
int mdla_profile_stop(int type);
void mdla_trace_end(struct command_entry *ce);
void mdla_trace_tag_begin(const char *format, ...);
void mdla_trace_tag_end(void);
void mdla_met_event_enter(int core, int vmdla_opp,
int dsp_freq, int ipu_if_freq, int mdla_freq);
void mdla_met_event_leave(int core);
#endif
@@ -0,0 +1,94 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#undef TRACE_SYSTEM
#define TRACE_SYSTEM met_mdlasys_events
#if !defined(_TRACE_MET_MDLASYS_EVENTS_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_MET_MDLASYS_EVENTS_H
#include <linux/tracepoint.h>
#include "mdla_pmu.h"
TRACE_EVENT(mdla_polling,
TP_PROTO(int core,
u32 *c),
TP_ARGS(core, c),
TP_STRUCT__entry(
__field(int, core)
__array(u32, c, MDLA_PMU_COUNTERS)
),
TP_fast_assign(
__entry->core = core;
memcpy(__entry->c, c, MDLA_PMU_COUNTERS * sizeof(u32));
),
TP_printk("_id=c%d, c1=%u, c2=%u, c3=%u, c4=%u, c5=%u, c6=%u, c7=%u, c8=%u, c9=%u, c10=%u, c11=%u, c12=%u, c13=%u, c14=%u, c15=%u",
__entry->core,
__entry->c[0],
__entry->c[1],
__entry->c[2],
__entry->c[3],
__entry->c[4],
__entry->c[5],
__entry->c[6],
__entry->c[7],
__entry->c[8],
__entry->c[9],
__entry->c[10],
__entry->c[11],
__entry->c[12],
__entry->c[13],
__entry->c[14])
);
TRACE_EVENT(mdla_cmd_enter,
TP_PROTO(int core, int vmdla_opp, int dsp_freq,
int ipu_if_freq, int mdla_freq),
TP_ARGS(core, vmdla_opp, dsp_freq, ipu_if_freq,
mdla_freq),
TP_STRUCT__entry(
__field(int, core)
__field(int, vmdla_opp)
__field(int, dsp_freq)
__field(int, ipu_if_freq)
__field(int, mdla_freq)
),
TP_fast_assign(
__entry->core = core;
__entry->vmdla_opp = vmdla_opp;
__entry->dsp_freq = dsp_freq;
__entry->ipu_if_freq = ipu_if_freq;
__entry->mdla_freq = mdla_freq;
),
TP_printk("_id=c%d, %s=%d, %s=%d, %s=%d, %s=%d",
__entry->core,
"vmdla_opp", __entry->vmdla_opp,
"dsp_freq", __entry->dsp_freq,
"ipu_if_freq", __entry->ipu_if_freq,
"mdla_freq", __entry->mdla_freq)
);
TRACE_EVENT(mdla_cmd_leave,
TP_PROTO(int core, int dummy),
TP_ARGS(core, dummy),
TP_STRUCT__entry(
__field(int, core)
__field(int, dummy)
),
TP_fast_assign(
__entry->core = core;
__entry->dummy = dummy;
),
TP_printk("_id=c%d", __entry->core)
);
#endif /* _TRACE_MET_MDLASYS_EVENTS_H */
/* This part must be outside protection */
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH .
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE met_mdlasys_events
#include <trace/define_trace.h>
+7
View File
@@ -0,0 +1,7 @@
config MTK_MDLA_SUPPORT
bool "MDLA (Mediatek Deep Learning Accelerator) Driver"
help
Support deep neural network calculation using
hardware accelerator. Customers and third party
could use MDLA to develop feature and algorithm
by themselves.
+57
View File
@@ -0,0 +1,57 @@
#
# Copyright (C) 2018 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.
#
MTK_MDLA_CORE := 1
ifneq (,$(filter $(strip $(MTK_PLATFORM)), mt6779))
MTK_MDLA_CORE := 1
obj-y += 1.0/
else
endif
obj-y += $(MTK_PLATFORM)/
subdir-ccflags-y += -DMTK_MDLA_CORE=$(MTK_MDLA_CORE)
subdir-ccflags-y += -DMTK_MDLA_DVT
# FPGA environment
ifeq ($(CONFIG_MTK_FPGA),y)
subdir-ccflags-y += -DMTK_MDLA_FPGA_PORTING
else ifeq ($(CONFIG_FPGA_EARLY_PORTING),y)
subdir-ccflags-y += -DMTK_MDLA_FPGA_PORTING
endif
# VPU support
ifeq ($(CONFIG_MTK_VPU_SUPPORT),y)
subdir-ccflags-y += -DMTK_VPU_SUPPORT
endif
# SWPM support
ifeq ($(CONFIG_MTK_SWPM),y)
subdir-ccflags-y += -DMTK_SWPM
endif
# PER_OBSERVER support
ifeq ($(CONFIG_MTK_PERF_OBSERVER),y)
subdir-ccflags-y += -DMTK_PERF_OBSERVER
endif
# HQA load
ifeq ($(PROJECT_DTB_NAMES),"mediatek/evb6779_64_hqact")
subdir-ccflags-y += -DHQA_LOAD
endif
# HQA load
ifeq ($(PROJECT_DTB_NAMES),"mediatek/k79v1_64_ctighten")
subdir-ccflags-y += -DHQA_LOAD
endif
@@ -0,0 +1,18 @@
#
# Copyright (C) 2018 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.
#
ccflags-y += -I$(srctree)/drivers/misc/mediatek/mdla/$(MTK_PLATFORM)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/mdla/1.0
ccflags-y += -I$(srctree)/drivers/misc/mediatek/qos/
obj-$(CONFIG_MTK_MDLA_SUPPORT) := mdla_pmu.o mdla_qos.o
@@ -0,0 +1,127 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef _MDLA_HW_REG_H_
#define _MDLA_HW_REG_H_
#define APU2_IRQ_ID (321+32)
#define MDLA_IRQ_SWCMD_TILECNT_INT (1 << 1)
#define MDLA_IRQ_TILECNT_DONE (1 << 1)
#define MDLA_IRQ_SWCMD_DONE (1 << 2)
#define MDLA_IRQ_PMU_INTE (1 << 9)
#define MDLA_IRQ_MASK (0x1FFFFF)
#define MDLA_AXI_CTRL_MASK ((1 << 7) | (1 << 16))
/* Infra TOPAXI */
#define INFRA_TOPAXI_PROTECTEN_MCU_SET (0x2C4)
#define INFRA_TOPAXI_PROTECTEN_MCU_CLR (0x2C8)
#define INFRA_TOPAXI_PROTECTEN_MCU_STA0 (0x2E0)
#define INFRA_TOPAXI_PROTECTEN_MCU_STA1 (0x2E4)
#define VPU_CORE2_PROT_STEP1_0_MASK \
((0x1 << 8) | (0x1 << 9) | (0x1 << 10))
#define VPU_CORE2_PROT_STEP1_0_ACK_MASK \
((0x1 << 8) | (0x1 << 9) | (0x1 << 10))
/* APU CONN */
#define APU_CONN_SW_RST (0x00C)
#define APU_CORE2_RSTB (1 << 15)
/* MDLA config */
#define MDLA_CG_CON (0x000)
#define MDLA_CG_SET (0x004)
#define MDLA_CG_CLR (0x008)
#define MDLA_SW_RST (0x00C)
#define MDLA_MBIST_MODE0 (0x010)
#define MDLA_MBIST_MODE1 (0x014)
#define MDLA_MBIST_CTL (0x018)
#define MDLA_RP_OK0 (0x01C)
#define MDLA_RP_OK1 (0x020)
#define MDLA_RP_OK2 (0x024)
#define MDLA_RP_OK3 (0x028)
#define MDLA_RP_FAIL0 (0x02C)
#define MDLA_RP_FAIL1 (0x030)
#define MDLA_RP_FAIL2 (0x034)
#define MDLA_RP_FAIL3 (0x038)
#define MDLA_MBIST_FAIL0 (0x03C)
#define MDLA_MBIST_FAIL1 (0x040)
#define MDLA_MBIST_FAIL2 (0x044)
#define MDLA_MBIST_FAIL3 (0x048)
#define MDLA_MBIST_FAIL4 (0x04C)
#define MDLA_MBIST_FAIL5 (0x050)
#define MDLA_MBIST_DONE0 (0x054)
#define MDLA_MBIST_DONE1 (0x058)
#define MDLA_MBIST_DEFAULT_DELSEL (0x05C)
#define MDLA_SRAM_DELSEL0 (0x060)
#define MDLA_SRAM_DELSEL1 (0x064)
#define MDLA_RP_RST (0x068)
#define MDLA_RP_CON (0x06C)
#define MDLA_RP_PRE_FUSE (0x070)
#define MDLA_SPARE_0 (0x074)
#define MDLA_SPARE_1 (0x078)
#define MDLA_SPARE_2 (0x07C)
#define MDLA_SPARE_3 (0x080)
#define MDLA_SPARE_4 (0x084)
#define MDLA_SPARE_5 (0x088)
#define MDLA_SPARE_6 (0x08C)
#define MDLA_SPARE_7 (0x090)
#define MDLA_AXI_CTRL (0x120)
#define MDLA_AXI1_CTRL (0x124)
/* MDLA command */
#define MREG_TOP_G_REV (0x0500)
#define MREG_TOP_G_INTP0 (0x0504)
#define MREG_TOP_G_INTP1 (0x0508)
#define MREG_TOP_G_INTP2 (0x050C)
#define MREG_TOP_G_CDMA0 (0x0510)
#define MREG_TOP_G_CDMA1 (0x0514)
#define MREG_TOP_G_CDMA2 (0x0518)
#define MREG_TOP_G_CDMA3 (0x051C)
#define MREG_TOP_G_CDMA4 (0x0520)
#define MREG_TOP_G_CDMA5 (0x0524)
#define MREG_TOP_G_CDMA6 (0x0528)
#define MREG_TOP_G_CUR0 (0x052C)
#define MREG_TOP_G_CUR1 (0x0530)
#define MREG_TOP_G_FIN0 (0x0534)
#define MREG_TOP_G_FIN1 (0x0538)
#define MREG_TOP_G_STREAM0 (0x053C)
#define MREG_TOP_G_STREAM1 (0x0540)
#define MREG_TOP_G_IDLE (0x0544)
#define MREG_TOP_ENG0 (0x0550)
#define MREG_TOP_ENG1 (0x0554)
#define MREG_TOP_ENG2 (0x0558)
#define MREG_TOP_ENG11 (0x057C)
#define MREG_CMD_SIZE (0x180)
#define MREG_CMD_SWCMD_ID (0x150)
#define MREG_CMD_EXE_FLOW (0x158)
#define MREG_CMD_CBL_FUNC (0x0AC)
#define MREG_CMD_SBL_FUNC (0x11C)
#define MREG_CMD_CONV_FUNC (0x0BC)
#define MREG_CMD_ELW_FUNC (0x0CC)
#define MREG_CMD_ACTI_FUNC (0x0E0)
#define MREG_CMD_POOL_FUNC_0 (0x0F8)
#define MREG_CMD_STE_FUNC (0x118)
/* MDLA PMU */
#define CFG_PMCR_DEFAULT (0x1F021)
#define PMU_CNT_SHIFT (0x0010)
#define PMU_CLR_CMDE_SHIFT (0x5)
#define PMU_PMCR_CCNT_EN (0x10000)
#define PMU_PMCR_CCNT_RST (0x4)
#define PMU_PMCR_CNT_RST (0x2)
#define PMU_CFG_PMCR (0x0E00)
#define PMU_CYCLE (0x0E04)
#define PMU_START_TSTAMP (0x0E08)
#define PMU_END_TSTAMP (0x0E0C)
#define PMU_EVENT_OFFSET (0x0E10)
#define PMU_CNT_OFFSET (0x0E14)
#endif
@@ -0,0 +1,301 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "mdla_debug.h"
#include <linux/io.h>
#include <linux/spinlock.h>
#include <linux/types.h>
#include <linux/bitmap.h>
#include "mdla_hw_reg.h"
#include "mdla_pmu.h"
#include "mdla.h"
#define COUNTER_CLEAR 0xFFFFFFFF
DECLARE_BITMAP(pmu_bitmap, MDLA_PMU_COUNTERS);
DEFINE_SPINLOCK(pmu_lock);
/* saved registers, used to restore config after pmu reset */
u32 cfg_pmu_event[MDLA_PMU_COUNTERS];
static u32 cfg_pmu_clr_mode;
/* lastest register values, since last command end */
static u32 l_counters[MDLA_PMU_COUNTERS];
static u32 l_start_t;
static u32 l_end_t;
static u32 l_cycle;
unsigned int pmu_reg_read(u32 offset)
{
return ioread32(apu_mdla_biu_top + offset);
}
static void pmu_reg_write(u32 value, u32 offset)
{
iowrite32(value, apu_mdla_biu_top + offset);
}
#define pmu_reg_set(mask, offset) \
pmu_reg_write(pmu_reg_read(offset) | (mask), (offset))
#define pmu_reg_clear(mask, offset) \
pmu_reg_write(pmu_reg_read(offset) & ~(mask), (offset))
/*
* API naming rules
* pmu_xxx_save(): save registers to variables
* pmu_xxx_get(): load values from saved variables.
* pmu_xxx_read(): read values from registers.
* pmu_xxx_write(): write values to registers.
*/
static int pmu_event_write(u32 handle, u32 val)
{
u32 mask;
if (handle >= MDLA_PMU_COUNTERS)
return -EINVAL;
mask = 1 << (handle+17);
if (val == COUNTER_CLEAR) {
mdla_pmu_debug("%s: clear pmu counter[%d]\n",
__func__, handle);
pmu_reg_write(0, PMU_EVENT_OFFSET +
(handle) * PMU_CNT_SHIFT);
pmu_reg_clear(mask, PMU_CFG_PMCR);
} else {
mdla_pmu_debug("%s: set pmu counter[%d] = 0x%x\n",
__func__, handle, val);
pmu_reg_write(val, PMU_EVENT_OFFSET +
(handle) * PMU_CNT_SHIFT);
pmu_reg_set(mask, PMU_CFG_PMCR);
}
return 0;
}
int pmu_counter_alloc(u32 interface, u32 event)
{
unsigned long flags;
int handle;
mutex_lock(&cmd_lock);
mutex_lock(&power_lock);
spin_lock_irqsave(&pmu_lock, flags);
handle = bitmap_find_free_region(pmu_bitmap, MDLA_PMU_COUNTERS, 0);
spin_unlock_irqrestore(&pmu_lock, flags);
if (unlikely(handle < 0))
goto out;
pmu_counter_event_save(handle, ((interface << 16) | event));
out:
mutex_unlock(&power_lock);
mutex_unlock(&cmd_lock);
return handle;
}
EXPORT_SYMBOL(pmu_counter_alloc);
int pmu_counter_free(int handle)
{
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
mutex_lock(&cmd_lock);
mutex_lock(&power_lock);
bitmap_release_region(pmu_bitmap, handle, 0);
if (get_power_on_status())
pmu_event_write(handle, COUNTER_CLEAR);
mutex_unlock(&power_lock);
mutex_unlock(&cmd_lock);
return 0;
}
EXPORT_SYMBOL(pmu_counter_free);
int pmu_counter_event_save(u32 handle, u32 val)
{
if (handle >= MDLA_PMU_COUNTERS)
return -EINVAL;
cfg_pmu_event[handle] = val;
if (!get_power_on_status())
return 0;
return pmu_event_write(handle, val);
}
int pmu_counter_event_get(int handle)
{
u32 event;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
event = cfg_pmu_event[handle];
return (event == COUNTER_CLEAR) ? -ENOENT : event;
}
int pmu_counter_event_get_all(u32 out[MDLA_PMU_COUNTERS])
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
out[i] = cfg_pmu_event[i];
return 0;
}
void pmu_counter_read_all(u32 out[MDLA_PMU_COUNTERS])
{
int i;
u32 offset;
u32 reg;
offset = PMU_CNT_OFFSET;
reg = pmu_reg_read(PMU_CFG_PMCR);
if ((1<<PMU_CLR_CMDE_SHIFT) & reg)
offset = offset + 4;
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
out[i] = pmu_reg_read(offset + (i * PMU_CNT_SHIFT));
}
u32 pmu_counter_get(int handle)
{
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
return l_counters[handle];
}
void pmu_counter_get_all(u32 out[MDLA_PMU_COUNTERS])
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
out[i] = l_counters[i];
}
u32 pmu_get_perf_start(void)
{
return l_start_t;
}
u32 pmu_get_perf_end(void)
{
return l_end_t;
}
u32 pmu_get_perf_cycle(void)
{
return l_cycle;
}
static void pmu_reset_counter(void)
{
mdla_pmu_debug("mdla: %s\n", __func__);
if (!get_power_on_status())
return;
pmu_reg_set(PMU_PMCR_CNT_RST, PMU_CFG_PMCR);
while (pmu_reg_read(PMU_CFG_PMCR) &
PMU_PMCR_CNT_RST) {
}
}
static void pmu_reset_cycle(void)
{
mdla_pmu_debug("mdla: %s\n", __func__);
if (!get_power_on_status())
return;
pmu_reg_set((PMU_PMCR_CCNT_EN | PMU_PMCR_CCNT_RST), PMU_CFG_PMCR);
while (pmu_reg_read(PMU_CFG_PMCR) &
PMU_PMCR_CCNT_RST) {
}
}
void pmu_reset_saved_counter(void)
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
l_counters[i] = 0;
pmu_reset_counter();
}
void pmu_reset_saved_cycle(void)
{
l_cycle = 0;
pmu_reset_cycle();
}
/* 1: PMU cleary by each command end */
static void pmu_clr_mode_write(u32 mode)
{
u32 mask = (1 << PMU_CLR_CMDE_SHIFT);
if (!get_power_on_status())
return;
if (mode)
pmu_reg_set(mask, PMU_CFG_PMCR);
else
pmu_reg_clear(mask, PMU_CFG_PMCR);
}
void pmu_clr_mode_save(u32 mode)
{
cfg_pmu_clr_mode = mode;
pmu_clr_mode_write(mode);
}
/* save pmu registers for query after power off */
void pmu_reg_save(void)
{
l_cycle = pmu_reg_read(PMU_CYCLE);
l_end_t = pmu_reg_read(PMU_END_TSTAMP);
l_start_t = pmu_reg_read(PMU_START_TSTAMP);
pmu_counter_read_all(l_counters);
}
void pmu_reset(void)
{
int i;
pmu_reg_write((CFG_PMCR_DEFAULT|
PMU_PMCR_CCNT_RST|PMU_PMCR_CNT_RST), PMU_CFG_PMCR);
while (pmu_reg_read(PMU_CFG_PMCR) &
(PMU_PMCR_CCNT_RST|PMU_PMCR_CNT_RST)) {
}
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
pmu_event_write(i, cfg_pmu_event[i]);
pmu_clr_mode_write(cfg_pmu_clr_mode);
}
void pmu_init(void)
{
cfg_pmu_clr_mode = 0;
memset(cfg_pmu_event, 0xFF, sizeof(cfg_pmu_event));
}
@@ -0,0 +1,41 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef __MDLA_PMU_H__
#define __MDLA_PMU_H__
#include <linux/types.h>
extern int get_power_on_status(void);
extern struct mutex power_lock;
extern struct mutex cmd_lock;
#define MDLA_PMU_COUNTERS 15
unsigned int pmu_reg_read(u32 offset);
int pmu_counter_alloc(u32 interface, u32 event);
int pmu_counter_free(int handle);
int pmu_counter_event_save(u32 handle, u32 val);
int pmu_counter_event_get(int handle);
int pmu_counter_event_get_all(u32 out[MDLA_PMU_COUNTERS]);
u32 pmu_counter_get(int handle);
void pmu_counter_get_all(u32 out[MDLA_PMU_COUNTERS]);
void pmu_counter_read_all(u32 out[MDLA_PMU_COUNTERS]);
void pmu_reg_save(void);
void pmu_clr_mode_save(u32 mode);
u32 pmu_get_perf_start(void);
u32 pmu_get_perf_end(void);
u32 pmu_get_perf_cycle(void);
void pmu_reset_saved_counter(void);
void pmu_reset_saved_cycle(void);
void pmu_init(void);
void pmu_reset(void);
#endif
@@ -0,0 +1,511 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include <linux/timer.h>
#include <linux/module.h>
#include <linux/soc/mediatek/mtk-pm-qos.h>
#include <linux/pm_qos.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/workqueue.h>
#include <mtk_qos_bound.h>
#include "mdla_qos.h"
#include "mdla_debug.h"
#define LINE_TAG mdla_qos_debug("[mdla][qos] %s %d\n", __func__, __LINE__)
/* polling interval 16 ms */
//#define MDLA_SELF_WORKQUEUE
#define DEFAUTL_QOS_POLLING_TIME 16
#define MTK_QOS_BUF_SIZE QOS_BOUND_BUF_SIZE //define in mtk_qos_bound.h
#define MTK_MDLA_CORE 1
#define get_qosbound_enum(x) (QOS_SMIBM_MDLA)
struct qos_counter {
struct timer_list qos_timer;
struct mtk_pm_qos_request qos_req;
struct list_head list;
struct mutex list_mtx;
int32_t last_peak_val;
unsigned int last_idx;
int core;
int wait_ms;
};
struct cmd_qos {
int32_t total_bw;
unsigned int last_idx;
unsigned int count;
struct list_head list;
struct mutex mtx;
};
/* workqueue */
#ifdef MDLA_SELF_WORKQUEUE
DEFINE_MUTEX(wq_mtx);
struct qos_workqueue {
struct workqueue_struct *qos_queue;
unsigned int ref_cnt;
};
static struct qos_workqueue qos_wq;
#endif
static struct qos_counter qos_counter[MTK_MDLA_CORE];
static struct work_struct qos_work[MTK_MDLA_CORE];
//-----
static inline void enque_qos_wq(struct work_struct *work)
{
#ifdef MDLA_SELF_WORKQUEUE
if (qos_wq.qos_queue == NULL || work == NULL) {
LOG_ERR("[mdla][qos] enque qos wq fail\n");
return;
}
queue_work(qos_wq.qos_queue, work);
#else
schedule_work(work);
#endif
}
static inline struct qos_counter *get_qos_counter(unsigned int core)
{
return &qos_counter[core];
}
//-----
static int add_qos_request(struct mtk_pm_qos_request *req)
{
mtk_pm_qos_add_request(req, MTK_PM_QOS_MEMORY_EXT_BANDWIDTH,
PM_QOS_DEFAULT_VALUE);
return 0;
}
static void update_qos_request(struct mtk_pm_qos_request *req, int32_t val)
{
mdla_qos_debug("[mdla][qos] %s, bw=%d -\n", __func__, val);
mtk_pm_qos_update_request(req, val);
}
static int destroy_qos_request(struct mtk_pm_qos_request *req)
{
mtk_pm_qos_update_request(req,
MTK_PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE);
mtk_pm_qos_remove_request(req);
return 0;
}
//-----
/* called by timer up, update average bw according idx/last_idx */
static int update_cmd_qos(struct qos_counter *counter,
struct qos_bound *qos_info)
{
struct cmd_qos *cmd_qos = NULL;
unsigned int idx = 0;
int qos_smi_idx = 0;
mdla_qos_debug("[mdla][qos] %s +\n", __func__);
mutex_lock(&counter->list_mtx);
/* get first entry */
if (!list_empty(&counter->list)) {
cmd_qos = list_first_entry(&counter->list,
struct cmd_qos, list);
if (cmd_qos != NULL) {
/* sum current bw value to cmd_qos */
mutex_lock(&cmd_qos->mtx);
idx = cmd_qos->last_idx;
do {
cmd_qos->total_bw +=
qos_info->stats[idx].smibw_mon[qos_smi_idx];
cmd_qos->count++;
idx = (idx + 1) % MTK_QOS_BUF_SIZE;
} while (idx != qos_info->idx);
mdla_qos_debug("[mdla][qos] %s, idx(%d ~ %d)\n",
__func__, cmd_qos->last_idx, idx);
/* update last idx */
cmd_qos->last_idx = idx;
mutex_unlock(&cmd_qos->mtx);
}
} else {
mutex_unlock(&counter->list_mtx);
return 0;
}
mutex_unlock(&counter->list_mtx);
mdla_qos_debug("[mdla][qos] %s -, total bw(%d)\n",
__func__, cmd_qos->total_bw);
return 0;
}
static int enque_cmd_qos(struct qos_counter *counter)
{
struct qos_bound *qos_info = NULL;
struct cmd_qos *cmd_qos = NULL;
mdla_qos_debug("[mdla][qos] %s +\n", __func__);
/* alloc cmd_qos */
cmd_qos = kzalloc(sizeof(struct cmd_qos), GFP_KERNEL);
if (cmd_qos == NULL) {
LOG_ERR("[mdla][qos] %s alloc cmd_qos fail\n", __func__);
return -1;
};
/* get qos information */
qos_info = get_qos_bound();
if (qos_info == NULL) {
LOG_ERR("[mdla][qos] %s get info fail\n", __func__);
kfree(cmd_qos);
return -1;
}
/* init cmd_qos */
mutex_init(&cmd_qos->mtx);
/* critical session, modify cmd_qos's idx */
mutex_lock(&cmd_qos->mtx);
cmd_qos->last_idx = qos_info->idx;
mutex_unlock(&cmd_qos->mtx);
/* add to counter's list */
mutex_lock(&counter->list_mtx);
list_add_tail(&cmd_qos->list, &counter->list);
mutex_unlock(&counter->list_mtx);
mdla_qos_debug("[mdla][qos] %s -\n", __func__);
return 0;
}
static int deque_cmd_qos(struct qos_counter *counter)
{
struct cmd_qos *cmd_qos = NULL;
struct qos_bound *qos_info = NULL;
int qos_smi_idx = 0;
int avg_bw = 0;
unsigned int idx = 0;
mdla_qos_debug("[mdla][qos] %s +\n", __func__);
/* pop out cmd_qos from the head of list */
mutex_lock(&counter->list_mtx);
if (!list_empty(&counter->list)) {
cmd_qos = list_first_entry(&counter->list,
struct cmd_qos, list);
if (cmd_qos == NULL) {
LOG_ERR("[mdla][qos] %s get first entry fail\n",
__func__);
mutex_unlock(&counter->list_mtx);
return 0;
}
} else {
LOG_ERR("[mdla][qos] %s empty list\n", __func__);
mutex_unlock(&counter->list_mtx);
return 0;
}
list_del(&cmd_qos->list);
mutex_unlock(&counter->list_mtx);
mdla_qos_debug("[mdla][qos] %s cmd_qos = %p\n", __func__, cmd_qos);
/* get qos information */
qos_info = get_qos_bound();
if (qos_info == NULL) {
LOG_ERR("[mdla][qos] %s get info fail\n", __func__);
return 0;
}
/* get qos smibm enum */
qos_smi_idx = get_qosbound_enum(counter->core);
/* sum the last bw */
mutex_lock(&cmd_qos->mtx);
idx = cmd_qos->last_idx;
do {
cmd_qos->total_bw +=
qos_info->stats[idx].smibw_mon[qos_smi_idx];
cmd_qos->count++;
idx = (idx + 1) % MTK_QOS_BUF_SIZE;
} while (idx != qos_info->idx);
mdla_qos_debug("[mdla][qos] %s, idx(%d ~ %d)\n", __func__,
cmd_qos->last_idx, idx);
cmd_qos->last_idx = idx;
mutex_unlock(&cmd_qos->mtx);
/* average bw */
if (cmd_qos->count != 0) {
avg_bw = cmd_qos->total_bw / cmd_qos->count;
} else {
avg_bw = cmd_qos->total_bw;
};
mdla_qos_debug("[mdla][qos] cmd:bw(%d/%d)\n",
avg_bw, cmd_qos->total_bw);
/* free cmd_qos */
kfree(cmd_qos);
mdla_qos_debug("[mdla][qos] %s -\n", __func__);
return avg_bw;
}
static void qos_work_func(struct work_struct *work)
{
struct qos_bound *qos_info = NULL;
struct qos_counter *counter = NULL;
int qos_smi_idx = 0;
int idx = 0;
unsigned int peak_bw = 0;
int i = 0;
mdla_qos_debug("[mdla][qos] %s +\n", __func__);
/* get qos smibm enum */
for (i = 0; i < MTK_MDLA_CORE; i++) {
if (work == &qos_work[i]) {
counter = get_qos_counter(i);
break;
}
}
if (counter == NULL) {
LOG_ERR("[mdla][qos] %s get counter fail(%p)\n",
__func__, work);
return;
}
mdla_qos_debug("[mdla][qos] %s core(%d)\n", __func__, counter->core);
/* get qos smibm enum */
qos_smi_idx = get_qosbound_enum(counter->core);
/* get qos bound */
qos_info = get_qos_bound();
if (qos_info == NULL) {
LOG_ERR("[mdla][qos] %s get info fail\n", __func__);
return;
}
/* find peak bandwidth consumption */
idx = counter->last_idx;
do {
idx = (idx + 1) % MTK_QOS_BUF_SIZE;
peak_bw = peak_bw >
qos_info->stats[idx].smibw_mon[qos_smi_idx] ?
peak_bw : qos_info->stats[idx].smibw_mon[qos_smi_idx];
} while (idx != qos_info->idx);
mdla_qos_debug("[mdla][qos] %s, idx(%d ~ %d)\n",
__func__, counter->last_idx, idx);
counter->last_idx = idx;
/* update peak bw */
if (counter->last_peak_val != peak_bw) {
counter->last_peak_val = peak_bw;
update_qos_request(&counter->qos_req, peak_bw);
}
update_cmd_qos(counter, qos_info);
mdla_qos_debug("[mdla][qos] %s, peakbw=%d -\n", __func__, peak_bw);
}
static void qos_timer_func(struct timer_list *t)
{
struct qos_counter *counter = NULL;
counter = container_of(t, struct qos_counter, qos_timer);
mdla_qos_debug("[mdla][qos] %s(%d) +\n", __func__, counter->core);
if (counter == NULL) {
LOG_ERR("[mdla][qos] %s get counter fail\n", __func__);
return;
}
/* queue work because mutex sleep must be happened */
enque_qos_wq(&qos_work[counter->core]);
mod_timer(&counter->qos_timer,
jiffies + msecs_to_jiffies(DEFAUTL_QOS_POLLING_TIME));
mdla_qos_debug("[mdla][qos] %s -\n", __func__);
}
//-----
int mdla_cmd_qos_start(int core)
{
struct qos_counter *counter = NULL;
mdla_qos_debug("[mdla][qos] %s(%d)+\n", __func__, core);
/* get qos counter */
counter = get_qos_counter(core);
if (counter == NULL) {
LOG_ERR("[mdla][qos] %s get counter fail\n", __func__);
return -1;
}
/* enque cmd to counter's list */
if (enque_cmd_qos(counter)) {
LOG_ERR("[mdla][qos] %s enque cmd qos fail\n", __func__);
return -1;
}
mdla_qos_debug("[mdla][qos] %s -\n", __func__);
return 0;
}
int mdla_cmd_qos_end(int core)
{
struct qos_counter *counter = NULL;
int bw = 0;
mdla_qos_debug("[mdla][qos] %s(%d) +\n", __func__, core);
/* get counter */
counter = get_qos_counter(core);
if (counter == NULL) {
LOG_ERR("[mdla][qos] %s get counter fail\n", __func__);
return -1;
}
/* deque cmd to counter's list */
bw = deque_cmd_qos(counter);
mdla_qos_debug("[mdla][qos] %s -\n", __func__);
/* return 1 if bw = 0 (eara requirement) */
return bw == 0 ? 1 : bw;
}
int mdla_qos_counter_start(unsigned int core)
{
struct qos_counter *counter = NULL;
mdla_qos_debug("[mdla][qos]%s(%d) +\n", __func__, core);
#ifdef MDLA_SELF_WORKQUEUE
/* init qos_queue */
if (qos_wq.qos_queue == NULL) {
qos_wq.qos_queue = create_workqueue("mdla_qos");
if (qos_wq.qos_queue == NULL) {
LOG_ERR("[mdla][qos] create workqueue fail\n");
return -1;
}
}
#endif
/* get counter */
counter = get_qos_counter(core);
if (counter == NULL) {
LOG_ERR("[mdla][qos] get counter fail\n");
return -1;
}
/* init counter's list */
INIT_LIST_HEAD(&counter->list);
mutex_init(&counter->list_mtx);
/* setup timer */
timer_setup(&counter->qos_timer, qos_timer_func, 0);
counter->qos_timer.expires =
jiffies + msecs_to_jiffies(DEFAUTL_QOS_POLLING_TIME);
/* record wait time in counter */
counter->wait_ms = DEFAUTL_QOS_POLLING_TIME;
counter->core = core;
counter->last_idx = 0;
counter->last_peak_val = 0;
add_timer(&counter->qos_timer);
mdla_qos_debug("[mdla][qos] %s -\n", __func__);
return 0;
}
int mdla_qos_counter_end(unsigned int core)
{
struct qos_counter *counter = NULL;
mdla_qos_debug("[mdla][qos]%s +\n", __func__);
/* get qos smibm enum */
counter = get_qos_counter(core);
/* delete timer */
del_timer_sync(&counter->qos_timer);
mdla_qos_debug("[mdla][qos] %s -\n", __func__);
return 0;
}
int mdla_qos_counter_init(void)
{
int i = 0;
struct qos_counter *counter = NULL;
mdla_qos_debug("[mdla][qos] %s +\n", __func__);
#ifdef MDLA_SELF_WORKQUEUE
mutex_lock(&wq_mtx);
/* init qos_queue */
if (qos_wq.qos_queue == NULL) {
qos_wq.qos_queue = create_workqueue("mdla_qos");
if (qos_wq.qos_queue == NULL) {
LOG_ERR("[mdla][qos] create workqueue fail\n");
mutex_unlock(&wq_mtx);
return -1;
}
qos_wq.ref_cnt++;
}
mutex_unlock(&wq_mtx);
#endif
/* init work and pm_qos_request */
for (i = 0; i < MTK_MDLA_CORE; i++) {
INIT_WORK(&qos_work[i], &qos_work_func);
/* get counter */
counter = get_qos_counter(i);
if (counter == NULL) {
LOG_ERR("[mdla][qos] %s get counter(%d) fail\n",
__func__, i);
continue;
}
add_qos_request(&counter->qos_req);
}
return 0;
}
void mdla_qos_counter_destroy(void)
{
int i = 0;
struct qos_counter *counter = NULL;
mdla_qos_debug("[mdla][qos] %s +\n", __func__);
#ifdef MDLA_SELF_WORKQUEUE
mutex_lock(&wq_mtx);
qos_wq.ref_cnt--;
if (qos_wq.ref_cnt == 0) {
flush_workqueue(qos_wq.qos_queue);
destroy_workqueue(qos_wq.qos_queue);
}
mutex_unlock(&wq_mtx);
#endif
/* remove pm_qos_request */
for (i = 0; i < MTK_MDLA_CORE; i++) {
counter = get_qos_counter(i);
if (counter == NULL) {
LOG_ERR("[mdla][qos] %s get counter(%d) fail\n",
__func__, i);
continue;
}
destroy_qos_request(&counter->qos_req);
}
}
@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
/*
* usage:
* mdla_qos_counter_init():
* create qos workqueue for count bandwidth
* @call at init hardware
*
* mdla_qos_counter_start():
* create timer to count current bandwidth of VPU each 16ms
* timer will schedule work to wq when time's up
* @call at bootup hardware
*
* mdla_cmd_qos_start():
* enque one cmd to counter's linked list and count bw of cmd
* @call at issue cmd
*
* mdla_cmd_qos_end():
* deque current cmd from counter's linked list
* @call at cmd return
*
* mdla_qos_counter_end():
* delete timer
* @call at shutdown hardware
*
* mdla_qos_counter_destroy():
* delete qos workqueue
* @call at destroy hardware
*/
#ifndef __MDLA_QOS_H__
#define __MDLA_QOS_H__
int mdla_cmd_qos_start(int core);
int mdla_cmd_qos_end(int core);
int mdla_qos_counter_start(unsigned int core);
int mdla_qos_counter_end(unsigned int core);
int mdla_qos_counter_init(void);
void mdla_qos_counter_destroy(void);
#endif