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

+60
View File
@@ -0,0 +1,60 @@
config MTK_APUSYS_SUPPORT
bool "APUSYS driver"
help
For Mediatek APUSYS features, such as APUSYS driver
APUSYS power, APUSYS QoS,
CONFIG_MTK_APUSYS defines
if the APUSYS driver should be
built in or not
config MTK_APUSYS_DEBUG
bool "APUSYS debug"
depends on MTK_APUSYS_SUPPORT
help
Enable debug facilities of APUSYS, including
trace points and trace tags. Recommended for
analysis resource issues, such as starvation.
Disable, if you don't need them.
config MTK_APUSYS_RT_SUPPORT
bool "APUSYS Preemption"
help
For Mediatek APUSYS preemption features.
This config will enable MDLA/VPU preemption feature.
It will increase performance for high priority task.
MDLA/VPU should be enable/disable at the same time.
config MTK_APUSYS_MDLA_SUPPORT
bool "MDLA driver"
help
Support deep neural network calculation using
hardware accelerator. Customers and third party
could use MDLA to develop feature and algorithm
by themselves.
config MTK_APUSYS_VPU
bool "VPU driver"
select REMOTEPROC
help
Support image processing using VPU hardware.
Customers and third party could use VPU to develop
feature and algorithm by themselves. There is better
performance and power if image process algorithm
land on VPU instead of CPU/GPU.
config MTK_APUSYS_VPU_DEBUG
bool "VPU Debug"
depends on MTK_APUSYS_VPU
help
Enable debug facilities of VPU, such as
kernel logs, register dumps, device logs,
VPU jtag functions, and MET trace.
Disable, if you don't need them.
config MTK_APUSYS_EDMA_SUPPORT
bool "EDMA (External DMA) Driver"
help
The purpose of Mediatek eDMA is performing
data transfer between external memory such as
DRAM/TCM, It will cooperate with MDLA. eDMA
support different modes for image process.
+23
View File
@@ -0,0 +1,23 @@
#
# Copyright (C) 2016 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
obj-$(CONFIG_MTK_APUSYS_SUPPORT) += power/
obj-$(CONFIG_MTK_APUSYS_SUPPORT) += reviser/
obj-$(CONFIG_MTK_APUSYS_SUPPORT) += mnoc/
obj-$(CONFIG_MTK_APUSYS_SUPPORT) += midware/
obj-$(CONFIG_MTK_APUSYS_SUPPORT) += sample/
obj-$(CONFIG_MTK_APUSYS_SUPPORT) += debug/
obj-$(CONFIG_MTK_APUSYS_MDLA_SUPPORT) += mdla/
obj-$(CONFIG_MTK_APUSYS_VPU) += vpu/
obj-$(CONFIG_MTK_APUSYS_SUPPORT) += edma/
obj-$(CONFIG_MTK_APUSYS_SUPPORT) += devapc/
@@ -0,0 +1,35 @@
#
# Copyright (C) 2019 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_MACH_MT6893),y)
PDIR = mt6885
else ifeq ($(CONFIG_MACH_MT6877),y)
PDIR = mt6877
else
PDIR = $(MTK_PLATFORM)
endif
ccflags-y += -I$(srctree)/drivers/misc/mediatek/apusys/include
ccflags-y += -I$(srctree)/drivers/misc/mediatek/apusys/power/2.0
ccflags-y += -I$(srctree)/drivers/misc/mediatek/apusys/power/2.0/$(PDIR)
ccflags-y += -I$(obj)/$(PDIR)/
obj-y += debug.o
debug-$(CONFIG_MTK_APUSYS_DEBUG) += apu_tp.o apu_tags.o
debug-objs += debug_driver.o
debug-objs += dump_core.o
debug-objs += secure_perf.o
@@ -0,0 +1,405 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/seq_file.h>
#include <linux/sched/clock.h>
#include "apu_tags.h"
#define APU_TAGS_PROC_FS_NAME "aputag"
static struct proc_dir_entry *proot;
static DEFINE_MUTEX(apu_tags_list_lock);
static LIST_HEAD(apu_tags_list);
static int apu_tags_alloc_procfs(struct apu_tags *at);
static void apu_tags_free_procfs(struct apu_tags *at);
static int apu_tags_init_procfs(void);
static void apu_tags_exit_procfs(void);
struct apu_tag_info_t {
uint64_t time;
unsigned short pid;
};
static struct apu_tags *apu_tags_find(const char *name)
{
struct apu_tags *a, *n;
struct apu_tags *ret = NULL;
mutex_lock(&apu_tags_list_lock);
list_for_each_entry_safe(a, n, &apu_tags_list, list) {
if (!strncmp(a->name, name, APU_TAG_NAME_SZ-1)) {
ret = a;
break;
}
}
mutex_unlock(&apu_tags_list_lock);
return ret;
}
static void apu_tags_free_tags(struct apu_tags *at)
{
unsigned long flags;
spin_lock_irqsave(&at->lock, flags);
kfree(at->tags);
at->tags = NULL;
at->cnt = 0;
at->used_mem = 0;
spin_unlock_irqrestore(&at->lock, flags);
}
/**
* apu_tags_alloc() - Allocate apu_tags
*
* @name: name of the tags
* @size: size of a tag data
* @cnt: number of tags
* @seq_tag: seq print function for each tag
* @seq_info: seq print funcction for private info
* @priv: private data (ex: device data)
*
* Returns allocated apu_tags, or NULL on fail.
* It also creates procfs entry at /proc/aputag/"name"
*/
struct apu_tags *apu_tags_alloc(const char *name, int size, int cnt,
apu_tags_seq_f seq_tag, apu_tags_seq_f seq_info, void *priv)
{
struct apu_tags *at;
if (!name || !cnt || !size || !seq_tag)
return NULL;
at = apu_tags_find(name);
if (at) {
pr_notice("%s: apu tags %s is already exist\n",
__func__, name);
return NULL;
}
at = kzalloc(sizeof(struct apu_tags), GFP_NOFS);
if (!at)
return NULL;
at->seq_tag = seq_tag;
at->seq_info = seq_info;
at->dat_sz = size;
at->ent_sz = size + sizeof(struct apu_tag_info_t);
at->used_mem = sizeof(struct apu_tags) + (at->ent_sz * cnt);
at->idx = 0;
at->cnt = cnt;
spin_lock_init(&at->lock);
at->tags = kmalloc_array(cnt, at->ent_sz, GFP_NOFS);
if (!at->tags) {
kfree(at);
return NULL;
}
memset(at->tags, 0, at->ent_sz * at->cnt);
strncpy(at->name, name, APU_TAG_NAME_SZ-1);
/* proc dentries */
if (apu_tags_alloc_procfs(at)) {
apu_tags_free(at);
return NULL;
}
return at;
}
/**
* apu_tags_free() - Free apu_tags, and removes its procfs entry
*
* @at: pointer to allocated apu_tags
*/
void apu_tags_free(struct apu_tags *at)
{
if (!at)
return;
apu_tags_free_procfs(at);
apu_tags_free_tags(at);
kfree(at);
}
static void apu_tags_clear(struct apu_tags *at)
{
unsigned long flags;
spin_lock_irqsave(&at->lock, flags);
memset(at->tags, 0, at->ent_sz * at->cnt);
at->idx = 0;
spin_unlock_irqrestore(&at->lock, flags);
}
static struct apu_tag_info_t *apu_tag_at(struct apu_tags *at, int idx)
{
if (!at->tags)
return NULL;
return (struct apu_tag_info_t *)(at->tags + (at->ent_sz * idx));
}
static struct apu_tag_info_t *apu_tag_curr(struct apu_tags *at)
{
return apu_tag_at(at, at->idx);
}
static void *apu_tag_data(struct apu_tag_info_t *ti)
{
if (!ti)
return NULL;
return ((char *)ti) + sizeof(struct apu_tag_info_t);
}
/**
* apu_tag_add() - Add an entry to the ring tag buffer of apu_tags
*
* @at: pointer to allocated apu_tags
* @tag: tag entry to be added
*
* Copyies the content of the given tag entry to apu_tags, and
* increments the index of apu_tags.
*/
void apu_tag_add(struct apu_tags *at, void *tag)
{
struct apu_tag_info_t *ti;
unsigned long flags;
if (!at->tags)
return;
spin_lock_irqsave(&at->lock, flags);
ti = apu_tag_curr(at);
if (ti) {
ti->time = sched_clock();
ti->pid = current->pid;
memcpy(apu_tag_data(ti), tag, at->dat_sz);
at->idx++;
if (at->idx >= at->cnt)
at->idx = 0;
}
spin_unlock_irqrestore(&at->lock, flags);
}
/**
* apu_tags_seq_time() - print time to seq_file
*
* @time: schedule clock time got from sched_clock()
*/
void apu_tags_seq_time(struct seq_file *s, uint64_t time)
{
uint32_t nsec;
nsec = do_div(time, 1000000000);
seq_printf(s, "%lu.%06lu", (unsigned long)time,
(unsigned long)nsec/1000);
}
static void
apu_tags_seq_prefix(struct seq_file *s, uint64_t t, unsigned short pid)
{
uint32_t nsec;
nsec = do_div(t, 1000000000);
seq_printf(s, "[%5lu.%06lu] %d:", (unsigned long)t,
(unsigned long)nsec/1000, pid);
}
/**
* apu_tags_seq() - print tags to seq_file
*
* @at: given apu_tags
* @s: target seq_file
*
* Note: The content of /proc/aputag/"name", you
* may call this function to show tags at other debug nodes
*/
int apu_tags_seq(struct apu_tags *at, struct seq_file *s)
{
unsigned long flags;
int i, end, ret;
if (!at || !at->seq_tag)
return 0;
if (at->idx >= at->cnt || at->idx < 0)
at->idx = 0;
spin_lock_irqsave(&at->lock, flags);
end = (at->idx > 0) ? at->idx - 1 : at->cnt - 1;
for (i = at->idx;; ) {
struct apu_tag_info_t *ti;
ti = apu_tag_at(at, i);
if (!ti)
break;
if (!ti->time)
goto next;
apu_tags_seq_prefix(s, ti->time, ti->pid);
ret = at->seq_tag(s, apu_tag_data(ti), at->priv);
if (ret) {
seq_puts(s, "\n");
break;
}
next:
if (i == end)
break;
i = (i >= at->cnt - 1) ? 0 : i + 1;
}
spin_unlock_irqrestore(&at->lock, flags);
if (at->seq_info)
at->seq_info(s, NULL, at->priv);
return 0;
}
#define APU_TAG_CMD_SZ 16
static ssize_t apu_tags_proc_write(struct file *file, const char *buf,
size_t count, loff_t *data)
{
struct apu_tags *at;
char b[APU_TAG_CMD_SZ];
char *cmd, *cur;
at = PDE_DATA(file->f_inode);
if (!at)
return -EINVAL;
if (count == 0 || count >= APU_TAG_CMD_SZ)
return -EINVAL;
if (copy_from_user(b, buf, count))
return -EINVAL;
b[APU_TAG_CMD_SZ - 1] = 0;
cur = &b[0];
cmd = strsep(&cur, " \t\n");
if (!strncmp(cmd, "clear", APU_TAG_CMD_SZ))
apu_tags_clear(at);
else if (!strncmp(cmd, "free", APU_TAG_CMD_SZ))
apu_tags_free_tags(at);
return count;
}
static int apu_tags_proc_show(struct seq_file *s, void *v)
{
return apu_tags_seq((struct apu_tags *)s->private, s);
}
static int apu_tags_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, apu_tags_proc_show, PDE_DATA(inode));
}
static const struct file_operations apu_tags_proc_fops = {
.open = apu_tags_proc_open,
.write = apu_tags_proc_write,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int apu_tags_info_show(struct seq_file *s, void *v)
{
struct apu_tags *a, *n;
unsigned long total_mem = 0;
seq_puts(s, "Name\tCount\tEntry Size\tUsed Memory\n");
mutex_lock(&apu_tags_list_lock);
list_for_each_entry_safe(a, n, &apu_tags_list, list) {
seq_printf(s, "%s\t%5d\t%10d\t%11ld\n",
a->name, a->cnt, a->ent_sz, a->used_mem);
total_mem += a->used_mem;
}
mutex_unlock(&apu_tags_list_lock);
seq_printf(s, "Total Used Memory: %ld bytes\n", total_mem);
return 0;
}
static int apu_tags_info_open(struct inode *inode, struct file *file)
{
return single_open(file, apu_tags_info_show, NULL);
}
static const struct file_operations apu_tags_info_fops = {
.open = apu_tags_info_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int apu_tags_init_procfs(void)
{
if (proot)
return 0;
proot = proc_mkdir(APU_TAGS_PROC_FS_NAME, NULL);
if (!proot) {
pr_info("%s: unable to create\n", __func__);
return -ENOMEM;
}
proc_create("info", 0440, proot, &apu_tags_info_fops);
return 0;
}
static void apu_tags_exit_procfs(void)
{
remove_proc_subtree(APU_TAGS_PROC_FS_NAME, NULL);
proot = NULL;
}
#if !defined(USER_BUILD_KERNEL) && defined(CONFIG_MTK_ENG_BUILD)
#define APU_TAG_PROC_MDOE 0660
#else
#define APU_TAG_PROC_MDOE 0440
#endif
static int apu_tags_alloc_procfs(struct apu_tags *at)
{
int ret = 0;
mutex_lock(&apu_tags_list_lock);
list_add(&at->list, &apu_tags_list);
ret = apu_tags_init_procfs();
if (ret)
goto out;
at->proc = proc_create_data(at->name, APU_TAG_PROC_MDOE,
proot, &apu_tags_proc_fops, at);
if (!at->proc) {
pr_info("%s: unable to create %s\n", __func__, at->name);
ret = -ENOMEM;
}
out:
mutex_unlock(&apu_tags_list_lock);
return ret;
}
static void apu_tags_free_procfs(struct apu_tags *at)
{
mutex_lock(&apu_tags_list_lock);
list_del(&at->list);
if (at->proc && proot) {
remove_proc_subtree(at->name, proot);
at->proc = NULL;
}
if (list_empty(&apu_tags_list))
apu_tags_exit_procfs();
mutex_unlock(&apu_tags_list_lock);
}
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APU_TAGS_H__
#define __APU_TAGS_H__
#include <linux/spinlock.h>
#include <linux/proc_fs.h>
#include <linux/types.h>
#define APU_TAG_NAME_SZ 32
typedef int (*apu_tags_seq_f)(struct seq_file *s, void *tag, void *priv);
struct apu_tags {
spinlock_t lock;
char name[APU_TAG_NAME_SZ];
int dat_sz; /* size of tag data */
int ent_sz; /* size of tag entry (including tag info) */
int cnt; /* total count of tags */
int idx; /* current tag index */
char *tags; /* container of tags, size = ent_sz * cnt */
apu_tags_seq_f seq_tag; /* seq print func. for each tag */
apu_tags_seq_f seq_info; /* seq print func. for private info */
void *priv; /* private data (ex: device data)*/
unsigned long used_mem; /* size of allocated memory */
struct list_head list; /* link to apu tags list*/
struct proc_dir_entry *proc; /* allocated procfs entry */
};
#ifdef CONFIG_MTK_APUSYS_DEBUG
struct apu_tags *apu_tags_alloc(const char *name, int size, int cnt,
apu_tags_seq_f seq_tag, apu_tags_seq_f seq_info, void *priv);
void apu_tag_add(struct apu_tags *at, void *tag);
void apu_tags_free(struct apu_tags *at);
void apu_tags_seq_time(struct seq_file *s, uint64_t time);
int apu_tags_seq(struct apu_tags *at, struct seq_file *s);
#else
static inline
struct apu_tags *apu_tags_alloc(const char *name, int size, int cnt,
apu_tags_seq_f seq_tag, apu_tags_seq_f seq_info, void *priv)
{
return NULL;
}
static inline
void apu_tags_free(struct apu_tags *at)
{
}
static inline
void apu_tag_add(struct apu_tags *at, void *tag)
{
}
static inline
void apu_tags_seq_time(struct seq_file *s, uint64_t time)
{
}
static inline
int apu_tags_seq(struct apu_tags *at, struct seq_file *s)
{
return 0;
}
#endif
#endif
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/types.h>
#include <linux/tracepoint.h>
#include <linux/tracepoint-defs.h>
#include <linux/string.h>
#include "apu_tp.h"
#define apu_tp_foreach(tbl, t) \
for ((t) = (tbl); (t)->name != NULL; (t)++)
static void apu_tp_lookup(struct tracepoint *tp, void *priv)
{
struct apu_tp_tbl *t, *tbl;
tbl = (struct apu_tp_tbl *)priv;
apu_tp_foreach(tbl, t) {
if (!strcmp(t->name, tp->name))
t->tp = tp;
}
}
/**
* apu_tp_exit() - Release trace point table
*
* @apu_tp_tbl: trace point table
*
* Unregister all trace points listed in the given table from kernel.
* Note: The last entry of the table must be "APU_TP_TBL_END".
*/
void apu_tp_exit(struct apu_tp_tbl *tbl)
{
struct apu_tp_tbl *t;
apu_tp_foreach(tbl, t) {
if (!t->tp)
continue;
tracepoint_probe_unregister(t->tp, t->func, NULL);
t->registered = false;
}
}
/**
* apu_tp_init() - Initialize trace point table
*
* @apu_tp_tbl: trace point table
*
* Register all trace points listed in the given table to kernel.
* Note: The last entry of the table must be "APU_TP_TBL_END".
*/
int apu_tp_init(struct apu_tp_tbl *tbl)
{
struct apu_tp_tbl *t;
/* install tracepoints */
for_each_kernel_tracepoint(apu_tp_lookup, tbl);
apu_tp_foreach(tbl, t) {
if (!t->tp) {
pr_info("%s: %s was not found\n", __func__, t->name);
apu_tp_exit(tbl); /* free registered entries */
return -EINVAL;
}
tracepoint_probe_register(t->tp, t->func, NULL);
t->registered = true;
}
return 0;
}
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APU_TP_H__
#define __APU_TP_H__
#include <linux/tracepoint-defs.h>
struct apu_tp_tbl {
const char *name; /* name of the trace point (TP) */
void *func; /* functional pointer to the TP hook */
struct tracepoint *tp; /* trace point looked-up from kernel */
bool registered; /* TP register status */
};
/* Last entry of the table must be APU_TP_TBL_END */
#define APU_TP_TBL_END {.name = NULL, .func = NULL},
#ifdef CONFIG_MTK_APUSYS_DEBUG
int apu_tp_init(struct apu_tp_tbl *tbl);
void apu_tp_exit(struct apu_tp_tbl *tbl);
#else
static inline
int apu_tp_init(struct apu_tp_tbl *tbl)
{
return 0;
}
static inline
void apu_tp_exit(struct apu_tp_tbl *tbl)
{
}
#endif
#endif
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/platform_device.h>
#include <linux/module.h>
#include "debug_driver.h"
#define APUDBG_DEV_NAME "apu_debug"
static int debug_probe(struct platform_device *pdev)
{
int ret = 0;
pr_notice("%s in", __func__);
ret = apusys_dump_init(&pdev->dev);
if (ret) {
DBG_LOG_ERR("failed to create debug dump attr node(devinfo).\n");
goto out;
}
return 0;
out:
pr_notice("debug probe error!!\n");
return ret;
}
static int debug_remove(struct platform_device *pdev)
{
apusys_dump_exit(&pdev->dev);
return 0;
}
static struct platform_driver debug_driver = {
.probe = debug_probe,
.remove = debug_remove,
.driver = {
.name = APUDBG_DEV_NAME,
.owner = THIS_MODULE,
}
};
static struct platform_device debug_device = {
.name = APUDBG_DEV_NAME,
.id = 0,
};
static int __init debug_INIT(void)
{
int ret = 0;
pr_notice("%s debug driver init", __func__);
ret = platform_driver_register(&debug_driver);
if (ret != 0)
pr_notice("failed to register debug driver");
if (platform_device_register(&debug_device)) {
DBG_LOG_ERR("failed to register debug_driver device");
platform_driver_unregister(&debug_driver);
return -ENODEV;
}
return ret;
}
static void __exit debug_EXIT(void)
{
platform_driver_unregister(&debug_driver);
}
module_init(debug_INIT);
module_exit(debug_EXIT);
MODULE_LICENSE("GPL");
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __DEBUG_DRIVER_H__
#define __DEBUG_DRIVER_H__
#define DEBUG_PREFIX "[apusys_dbg]"
#define DBG_LOG_ERR(x, args...) \
pr_info(DEBUG_PREFIX "[error] %s " x, __func__, ##args)
static inline void apu_dbg_print(const char *fmt, ...)
{
}
int apusys_dump_init(struct device *dev);
void apusys_dump_exit(struct device *dev);
#endif /* __DEBUG_DRIVER_H__ */
@@ -0,0 +1,231 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/sysfs.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/io.h>
#include <linux/sched/clock.h>
#include <apusys_secure.h>
#include <apusys_plat.h>
static void set_dbg_sel(int val, int offset, int shift, int mask)
{
void *target = apu_top + offset;
u32 tmp;
if (apu_top == NULL) /* Skip if apu_top is not valid */
return;
tmp = ioread32(target);
tmp = (tmp & ~(mask << shift)) | (val << shift);
iowrite32(tmp, target);
tmp = ioread32(target);
}
u32 dbg_read(struct dbg_mux_sel_value sel)
{
int i;
int offset;
int shift;
int length;
int mask;
void *addr = apu_top + sel.status_reg_offset;
struct dbg_mux_sel_info info;
if (apu_top == NULL) /* Skip if apu_top is not valid */
return 0;
for (i = 0; i < DBG_MUX_SEL_COUNT; ++i) {
if (sel.dbg_sel[i] >= 0) {
info = info_table[i];
offset = info.offset;
shift = info.end_bit;
length = info.start_bit - info.end_bit + 1;
mask = (1 << length) - 1;
set_dbg_sel(sel.dbg_sel[i], offset, shift, mask);
}
}
return ioread32(addr);
}
static u32 gals_reg[TOTAL_DBG_MUX_COUNT];
void dump_gals_reg(bool dump_vpu)
{
int i;
for (i = 0; i < TOTAL_DBG_MUX_COUNT; ++i)
gals_reg[i] = dbg_read(value_table[i]);
}
void apusys_reg_dump(void)
{
int i;
u32 offset, size;
char *tmp = reg_all_mem;
if (apu_top == NULL) /* Skip if apu_top is not valid */
return;
dump_gals_reg(false);
for (i = 0; i < SEGMENT_COUNT; ++i) {
offset = range_table[i].base - APUSYS_BASE;
size = range_table[i].size;
memcpy_fromio(tmp, apu_top + offset, size);
tmp += size;
}
}
static ssize_t gals_dump_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int i;
char *p = buf;
if (apusys_dump_force)
apusys_reg_dump();
for (i = 0; i < TOTAL_DBG_MUX_COUNT; ++i)
p += sprintf(p, "%s:0x%08x\n",
value_table[i].name, gals_reg[i]);
return p - buf;
}
static u32 find_next_offset(loff_t offset)
{
u32 start, end;
loff_t reg_mem_offset = 0;
int i;
offset += APUSYS_BASE;
for (i = 0; i < SEGMENT_COUNT; i++) {
start = range_table[i].base;
end = start + range_table[i].size;
if (offset < start)
return start - offset;
reg_mem_offset += range_table[i].size;
}
/* fail */
return 0;
}
static u32 find_offset(loff_t offset, u32 *reg_mem_offset)
{
u32 start, end;
int i;
*reg_mem_offset = 0;
offset += APUSYS_BASE;
for (i = 0; i < SEGMENT_COUNT; i++) {
start = range_table[i].base;
end = start + range_table[i].size;
if (offset >= start && offset < end) {
*reg_mem_offset += offset - start;
return end - offset;
}
*reg_mem_offset += range_table[i].size;
}
/* fail */
return 0;
}
static ssize_t
reg_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t offset, size_t count)
{
u32 resid;
u32 reg_mem_offset;
u32 copy_size;
resid = find_offset(offset, &reg_mem_offset);
if (resid == 0) {
resid = find_next_offset(offset);
copy_size = count <= resid ? count : resid;
memset(buf, 0, copy_size);
} else {
copy_size = count <= resid ? count : resid;
memcpy(buf, reg_all_mem + reg_mem_offset, copy_size);
}
return copy_size;
}
static struct bin_attribute reg_dump_attr = {
.attr = {.name = "reg_dump", .mode = (0400)},
.size = APUSYS_REG_SIZE,
.read = reg_read,
.write = NULL,
.mmap = NULL,
};
static DEVICE_ATTR_RO(gals_dump);
static DEVICE_BOOL_ATTR(force_dump, 0600, apusys_dump_force);
static struct attribute *reg_dump_attrs[] = {
&dev_attr_force_dump.attr.attr,
&dev_attr_gals_dump.attr,
NULL,
};
static struct bin_attribute *reg_dump_bin_attrs[] = {
&reg_dump_attr,
NULL,
};
static struct attribute_group mdw_reg_dump_attr_group = {
.name = "debug",
.attrs = reg_dump_attrs,
.bin_attrs = reg_dump_bin_attrs,
};
int apusys_dump_init(struct device *dev)
{
int ret;
int reg_mem_size = 0;
int i;
ret = sysfs_create_group(&dev->kobj, &mdw_reg_dump_attr_group);
apu_top = ioremap_nocache(APUSYS_BASE, APUSYS_REG_SIZE);
apu_to_infra_top = ioremap_nocache(INFRA_BASE, INFRA_SIZE);
if (apu_top == NULL || apu_to_infra_top == NULL)
return -EIO;
/*Pre-allocate dump buffer size*/
for (i = 0; i < SEGMENT_COUNT; i++)
reg_mem_size += range_table[i].size;
reg_all_mem = vzalloc(reg_mem_size);
apusys_dump_force = false;
return 0;
}
void apusys_dump_exit(struct device *dev)
{
vfree(reg_all_mem);
sysfs_remove_group(&dev->kobj, &mdw_reg_dump_attr_group);
iounmap(apu_top);
iounmap(apu_to_infra_top);
}
@@ -0,0 +1,150 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APUSYS_MIDWARE_PLATFORM_H__
#define __APUSYS_MIDWARE_PLATFORM_H__
extern struct dentry *mdw_dbg_root;
#define APUSYS_VLM_START 0x1D800000 // tcm tmp
#define APUSYS_VLM_SIZE 0x100000
#define APUSYS_REG_SIZE (0x100000)
#define APUSYS_BASE (0x19000000)
#define INFRA_BASE (0x10000000)
#define INFRA_SIZE (0x10000)
#define NA (-1)
char *reg_all_mem;
bool apusys_dump_force;
static void *apu_top;
static void *apu_to_infra_top;
struct dbg_mux_sel_info {
int offset;
int start_bit;
int end_bit;
};
struct dbg_mux_sel_info info_table[] = {
{0x29010, 1, 1 }, //vcore_dbg_sel
{0x29010, 4, 2 }, //vcore_dbg_sel0
{0x29010, 7, 5 }, //vcore_dbg_sel1
{0x20138, 2, 0 }, //conn_dbg0_sel
{0x20138, 11, 9 }, //conn_dbg3_sel
{0x20138, 14, 12}, //conn_dbg4_sel
{0x20138, 17, 15}, //conn_dbg5_sel
{0x20138, 20, 18}, //conn_dbg6_sel
{0x30a10, 10, 10}, //vpu0_apu_gals_m_ctl_sel
{0x31a10, 10, 10}, //vpu1_apu_gals_m_ctl_sel
{0x6E000, 29, 24}, //apu_noc_tip_cfg0
};
#define DBG_MUX_SEL_COUNT (sizeof(info_table)/sizeof(struct dbg_mux_sel_info))
struct dbg_mux_sel_value {
char name[128];
int status_reg_offset;
int dbg_sel[DBG_MUX_SEL_COUNT];
};
struct dbg_mux_sel_value value_table[] = {
{"VCORE2EMI_S0_GALS_TX", 0x2901C,
{ 0, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"VCORE2EMI_S1_GALS_TX", 0x2901C,
{ 0, 4, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S0_GALS_RX", 0x2901C,
{ 1, NA, 3, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S1_GALS_RX", 0x2901C,
{ 1, NA, 4, NA, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_VCORE_GALS_TX", 0x2901C,
{ 1, NA, 6, NA, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_VCORE_GALS_RX", 0x2901C,
{ 0, 6, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 0, NA, NA, NA, NA} },
{"VPU02CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 1, 1, NA, NA, NA, NA, NA, NA} },
{"VPU12CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 1, 2, NA, NA, NA, NA, NA, NA} },
{"CONN2VPU0_GALS_TX", 0x2901C,
{ 0, 7, NA, 1, 4, NA, NA, NA, NA, NA, NA} },
{"CONN2VPU1_GALS_TX", 0x2901C,
{ 0, 7, NA, 1, 5, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_N0_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 3, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_N1_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 4, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S0_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 1, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S1_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 2, NA, NA, NA, NA} },
{"VPU02CONN_GALS_TX", 0x30A28,
{NA, NA, NA, NA, NA, NA, NA, NA, 0, NA, NA} },
{"CONN2VPU0_GALS_RX", 0x30A28,
{NA, NA, NA, NA, NA, NA, NA, NA, 1, NA, NA} },
{"VPU12CONN_GALS_TX", 0x31A28,
{NA, NA, NA, NA, NA, NA, NA, NA, NA, 0, NA} },
{"CONN2VPU1_GALS_RX", 0x31A28,
{NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, NA} },
{"MNOC_TOP_DBG_BUS_OUT_MST0", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 0} },
{"MNOC_TOP_DBG_BUS_OUT_MST1", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 1} },
{"MNOC_TOP_DBG_BUS_OUT_MST2", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 2} },
{"MNOC_TOP_DBG_BUS_OUT_MST3", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 3} },
{"MNOC_TOP_DBG_BUS_OUT_SLV0", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 4} },
{"MNOC_TOP_DBG_BUS_OUT_SLV1", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 5} },
{"MNOC_TOP_DBG_BUS_OUT_SLV2", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 6} },
{"MNOC_TOP_DBG_BUS_OUT_SLV3", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 7} },
{"MNOC_TOP_DBG_BUS_OUT_SLV4", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 8} },
};
#define TOTAL_DBG_MUX_COUNT \
(sizeof(value_table)/sizeof(struct dbg_mux_sel_value))
struct reg_dump_info {
char name[128];
u32 base;
u32 size;
};
struct reg_dump_info range_table[] = {
{"md32_sysCtrl", 0x19001000, 0x800 },
{"md32_sysCtrl_PMU", 0x19001800, 0x800 },
{"md32_wdt", 0x19002000, 0x1000},
{"apu_iommu0_r0", 0x19010000, 0x1000},
{"apu_iommu0_r1", 0x19011000, 0x1000},
{"apu_iommu0_r2", 0x19012000, 0x1000},
{"apu_iommu0_r3", 0x19013000, 0x1000},
{"apu_iommu0_r4", 0x19014000, 0x1000},
{"apu_conn_config", 0x19020000, 0x1000},
{"apu_sema_stimer", 0x19022000, 0x1000},
{"emi_config", 0x19023000, 0x1000},
{"apb_dapc_wrapper", 0x19064000, 0x1000},
{"infra_bcrm", 0x19065000, 0x1000},
{"apb_debug_ctl", 0x19066000, 0x1000},
{"noc_dapc_wrapper", 0x1906C000, 0x1000},
{"apu_noc_bcrm", 0x1906D000, 0x1000},
{"apu_noc_config_0", 0x1906E000, 0x2000},
{"apu_noc_config_1", 0x19070000, 0x2000},
{"apu_noc_config_2", 0x19072000, 0x2000},
{"apu_noc_config_3", 0x19074000, 0x2000},
{"apu_noc_config_4", 0x19076000, 0x2000},
{"apu_rpc(CPC)", 0x190F0000, 0x1000},
{"apu_rpc(DVFS)", 0x190F1000, 0x1000},
{"apu_ao_ctrl", 0x190F2000, 0x1000},
{"apb_dapc_ap_wrapper", 0x190F8000, 0x4000},
{"noc_dapc_ap_wrapper", 0x190FC000, 0x4000},
};
#define SEGMENT_COUNT (sizeof(range_table)/sizeof(struct reg_dump_info))
#endif
@@ -0,0 +1,147 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APUSYS_MIDWARE_PLATFORM_H__
#define __APUSYS_MIDWARE_PLATFORM_H__
extern struct dentry *mdw_dbg_root;
#define APUSYS_VLM_START 0x1D800000 // tcm tmp
#define APUSYS_VLM_SIZE 0x100000
#define APUSYS_REG_SIZE (0x100000)
#define APUSYS_BASE (0x19000000)
#define INFRA_BASE (0x10000000)
#define INFRA_SIZE (0x10000)
#define NA (-1)
char *reg_all_mem;
bool apusys_dump_force;
static void *apu_top;
static void *apu_to_infra_top;
struct dbg_mux_sel_info {
int offset;
int start_bit;
int end_bit;
};
struct dbg_mux_sel_info info_table[] = {
{0x29010, 1, 1 }, //vcore_dbg_sel
{0x29010, 4, 2 }, //vcore_dbg_sel0
{0x29010, 7, 5 }, //vcore_dbg_sel1
{0x20138, 2, 0 }, //conn_dbg0_sel
{0x20138, 11, 9 }, //conn_dbg3_sel
{0x20138, 14, 12}, //conn_dbg4_sel
{0x20138, 17, 15}, //conn_dbg5_sel
{0x20138, 20, 18}, //conn_dbg6_sel
{0x30a10, 10, 10}, //vpu0_apu_gals_m_ctl_sel
{0x31a10, 10, 10}, //vpu1_apu_gals_m_ctl_sel
{0x6E000, 29, 24}, //apu_noc_tip_cfg0
};
#define DBG_MUX_SEL_COUNT (sizeof(info_table)/sizeof(struct dbg_mux_sel_info))
struct dbg_mux_sel_value {
char name[128];
int status_reg_offset;
int dbg_sel[DBG_MUX_SEL_COUNT];
};
struct dbg_mux_sel_value value_table[] = {
{"VCORE2EMI_S0_GALS_TX", 0x2901C,
{ 0, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"VCORE2EMI_S1_GALS_TX", 0x2901C,
{ 0, 4, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S0_GALS_RX", 0x2901C,
{ 1, NA, 3, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S1_GALS_RX", 0x2901C,
{ 1, NA, 4, NA, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_VCORE_GALS_TX", 0x2901C,
{ 1, NA, 6, NA, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_VCORE_GALS_RX", 0x2901C,
{ 0, 6, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 0, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_N0_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 3, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_N1_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 4, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S0_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 1, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S1_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 2, NA, NA, NA, NA} },
{"MNOC_TOP_DBG_BUS_OUT_MST0", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 0} },
{"MNOC_TOP_DBG_BUS_OUT_MST1", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 1} },
{"MNOC_TOP_DBG_BUS_OUT_MST2", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 2} },
{"MNOC_TOP_DBG_BUS_OUT_MST3", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 3} },
{"MNOC_TOP_DBG_BUS_OUT_SLV0", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 4} },
{"MNOC_TOP_DBG_BUS_OUT_SLV1", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 5} },
{"MNOC_TOP_DBG_BUS_OUT_SLV2", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 6} },
{"MNOC_TOP_DBG_BUS_OUT_SLV3", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 7} },
{"MNOC_TOP_DBG_BUS_OUT_SLV4", 0x2901C,
{ 0, 7, NA, 4, NA, NA, NA, 2, NA, NA, 8} },
};
#define TOTAL_DBG_MUX_COUNT \
(sizeof(value_table)/sizeof(struct dbg_mux_sel_value))
struct reg_dump_info {
char name[128];
u32 base;
u32 size;
};
struct reg_dump_info range_table[] = {
{"md32_sysCtrl", 0x19001000, 0x800 },
{"md32_sysCtrl_PMU", 0x19001800, 0x800 },
{"md32_wdt", 0x19002000, 0x1000},
{"apu_iommu0_r0", 0x19010000, 0x1000},
{"apu_iommu0_r1", 0x19011000, 0x1000},
{"apu_iommu0_r2", 0x19012000, 0x1000},
{"apu_iommu0_r3", 0x19013000, 0x1000},
{"apu_iommu0_r4", 0x19014000, 0x1000},
{"apu_iommu1_r0", 0x19015000, 0x1000},
{"apu_iommu1_r1", 0x19016000, 0x1000},
{"apu_iommu1_r2", 0x19017000, 0x1000},
{"apu_iommu1_r3", 0x19018000, 0x1000},
{"apu_iommu1_r4", 0x19019000, 0x1000},
{"apu_south_rsi_config", 0x1901A000, 0x1000},
{"apu_north_rsi_config", 0x1901B000, 0x1000},
{"apu_xpu_rsi_config", 0x1901C000, 0x1000},
{"apu_south_ssc_config", 0x1901D000, 0x1000},
{"apu_north_ssc_config", 0x1901E000, 0x1000},
{"apu_apcssc_config", 0x1901F000, 0x1000},
{"apu_conn_config", 0x19020000, 0x1000},
{"apu_sema_stimer", 0x19022000, 0x1000},
{"emi_config", 0x19023000, 0x1000},
{"apu_adl", 0x19024000, 0x1000},
{"apu_edma_lite0", 0x19025000, 0x1000},
{"apu_edma_lite1", 0x19026000, 0x1000},
{"apu_edma0", 0x19027000, 0x1000},
{"apu_edma1", 0x19028000, 0x1000},
{"apu_Vcore_config", 0x19029000, 0x1000},
{"apb_dapc_wrapper", 0x19064000, 0x1000},
{"infra_bcrm", 0x19065000, 0x1000},
{"apb_debug_ctl", 0x19066000, 0x1000},
{"noc_dapc_wrapper", 0x1906C000, 0x1000},
{"apu_noc_bcrm", 0x1906D000, 0x1000},
{"apu_noc_config_0", 0x1906E000, 0x2000},
{"apu_rpc(CPC)", 0x190F0000, 0x1000},
{"apu_rpc(DVFS)", 0x190F1000, 0x1000},
{"apb_dapc_ap_wrapper", 0x190F8000, 0x4000},
{"noc_dapc_ap_wrapper", 0x190FC000, 0x4000},
};
#define SEGMENT_COUNT (sizeof(range_table)/sizeof(struct reg_dump_info))
#endif
@@ -0,0 +1,122 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APUSYS_MIDWARE_PLATFORM_H__
#define __APUSYS_MIDWARE_PLATFORM_H__
extern struct dentry *mdw_dbg_root;
#define APUSYS_VLM_START 0x1D800000 // tcm tmp
#define APUSYS_VLM_SIZE 0x100000
#define APUSYS_REG_SIZE (0x100000)
#define APUSYS_BASE (0x19000000)
#define INFRA_BASE (0x10000000)
#define INFRA_SIZE (0x10000)
#define NA (-1)
char *reg_all_mem;
bool apusys_dump_force;
static void *apu_top;
static void *apu_to_infra_top;
struct dbg_mux_sel_info {
int offset;
int start_bit;
int end_bit;
};
struct dbg_mux_sel_info info_table[] = {
{0x29010, 1, 1 }, //vcore_dbg_sel
{0x29010, 4, 2 }, //vcore_dbg_sel0
{0x29010, 7, 5 }, //vcore_dbg_sel1
{0x20138, 2, 0 }, //conn_dbg0_sel
{0x20138, 11, 9 }, //conn_dbg3_sel
{0x20138, 20, 18}, //conn_dbg6_sel
{0x01098, 15, 8 }, //edma_up_dbg_bus_sel
{0x30a10, 10, 10}, //vpu0_apu_gals_m_ctl_sel
{0x31a10, 10, 10}, //vpu1_apu_gals_m_ctl_sel
};
#define DBG_MUX_SEL_COUNT (sizeof(info_table)/sizeof(struct dbg_mux_sel_info))
struct dbg_mux_sel_value {
char name[128];
int status_reg_offset;
int dbg_sel[DBG_MUX_SEL_COUNT];
};
struct dbg_mux_sel_value value_table[] = {
{"VCORE2EMI_S0_GALS_TX", 0x2901C,
{ 0, 3, NA, NA, NA, NA, NA, NA, NA} },
{"VCORE2EMI_S1_GALS_TX", 0x2901C,
{ 0, 4, NA, NA, NA, NA, NA, NA, NA} },
{"APUSYS2ACP_VCORE_GALS_TX", 0x2901C,
{ 0, 5, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_VCORE_GALS_RX", 0x2901C,
{ 0, 6, NA, NA, NA, NA, NA, NA, NA} },
{"MNOC_MISC_1/0_DBG_BUS", 0x2901C,
{ 0, 7, NA, 4, NA, 2, NA, NA, NA} },
{"MNOC_MISC_3/2_DBG_BUS", 0x2901C,
{ 0, 7, NA, 4, NA, 3, NA, NA, NA} },
{"MNOC_MISC_4_DBG_BUS", 0x2901C,
{ 0, 7, NA, 4, NA, 4, NA, NA, NA} },
{"APU_UP_SYS_DBG_BUS", 0x2901C,
{ 0, 7, NA, 4, NA, 5, 1, NA, NA} },
{"APU_EDMA_0_DBG_BUS_0", 0x2901C,
{ 0, 7, NA, 4, NA, 5, 2, NA, NA} },
{"APU_EDMA_0_DBG_BUS_1", 0x2901C,
{ 0, 7, NA, 4, NA, 5, 3, NA, NA} },
{"CONN2VCORE_EMI_S0_GALS_RX", 0x2901C,
{ 1, NA, 3, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S1_GALS_RX", 0x2901C,
{ 1, NA, 4, NA, NA, NA, NA, NA, NA} },
{"APUSYS2ACP_VCORE_GALS_RX", 0x2901C,
{ 1, NA, 5, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_VCORE_GALS_TX", 0x2901C,
{ 1, NA, 6, NA, NA, NA, NA, NA, NA} },
};
#define TOTAL_DBG_MUX_COUNT \
(sizeof(value_table)/sizeof(struct dbg_mux_sel_value))
struct reg_dump_info {
char name[128];
u32 base;
u32 size;
};
struct reg_dump_info range_table[] = {
{"md32_sysCtrl", 0x19001000, 0x800 },
{"md32_sysCtrl_PMU", 0x19001800, 0x800 },
{"md32_wdt", 0x19002000, 0x1000},
{"apu_iommu0_r0", 0x19010000, 0x1000},
{"apu_iommu0_r1", 0x19011000, 0x1000},
{"apu_iommu0_r2", 0x19012000, 0x1000},
{"apu_iommu0_r3", 0x19013000, 0x1000},
{"apu_iommu0_r4", 0x19014000, 0x1000},
{"apu_xpu_rsi_config", 0x1901C000, 0x1000},
{"apu_acp_ssc_config", 0x1901F000, 0x1000},
{"apu_conn_config", 0x19020000, 0x1000},
{"apu_sema_stimer", 0x19022000, 0x1000},
{"emi_config", 0x19023000, 0x1000},
{"apb_dapc_wrapper", 0x19064000, 0x1000},
{"infra_bcrm", 0x19065000, 0x1000},
{"apb_debug_ctl", 0x19066000, 0x1000},
{"noc_dapc_wrapper", 0x1906C000, 0x1000},
{"apu_noc_bcrm", 0x1906D000, 0x1000},
{"apu_noc_config_0", 0x1906E000, 0x2000},
{"apu_noc_config_1", 0x19070000, 0x2000},
{"apu_noc_config_2", 0x19072000, 0x2000},
{"apu_noc_config_3", 0x19074000, 0x2000},
{"apu_noc_config_4", 0x19076000, 0x2000},
{"apu_rpc(CPC)", 0x190F0000, 0x1000},
{"apu_rpc(DVFS)", 0x190F1000, 0x1000},
{"apu_ao_ctrl", 0x190F2000, 0x1000},
{"apb_dapc_ap_wrapper", 0x190F8000, 0x4000},
{"noc_dapc_ap_wrapper", 0x190FC000, 0x4000},
};
#define SEGMENT_COUNT (sizeof(range_table)/sizeof(struct reg_dump_info))
#endif
@@ -0,0 +1,121 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APUSYS_MIDWARE_PLATFORM_H__
#define __APUSYS_MIDWARE_PLATFORM_H__
extern struct dentry *mdw_dbg_root;
#define APUSYS_VLM_START 0x1D800000 // tcm tmp
#define APUSYS_VLM_SIZE 0x100000
#define APUSYS_REG_SIZE (0x100000)
#define APUSYS_BASE (0x19000000)
#define INFRA_BASE (0x10000000)
#define INFRA_SIZE (0x10000)
#define NA (-1)
char *reg_all_mem;
bool apusys_dump_force;
static void *apu_top;
static void *apu_to_infra_top;
struct dbg_mux_sel_info {
int offset;
int start_bit;
int end_bit;
};
struct dbg_mux_sel_info info_table[] = {
{0x29010, 1, 1 }, //vcore_dbg_sel
{0x29010, 4, 2 }, //vcore_dbg_sel0
{0x29010, 7, 5 }, //vcore_dbg_sel1
{0x20138, 2, 0 }, //conn_dbg0_sel
{0x20138, 11, 9 }, //conn_dbg3_sel
{0x20138, 14, 12}, //conn_dbg4_sel
{0x20138, 17, 15}, //conn_dbg5_sel
{0x20138, 20, 18}, //conn_dbg6_sel
{0x20138, 23, 21}, //conn_dbg7_sel
};
#define DBG_MUX_SEL_COUNT (sizeof(info_table)/sizeof(struct dbg_mux_sel_info))
struct dbg_mux_sel_value {
char name[128];
int status_reg_offset;
int dbg_sel[DBG_MUX_SEL_COUNT];
};
struct dbg_mux_sel_value value_table[] = {
{"VCORE2EMI_N0_GALS_TX", 0x2901C,
{ 0, 1, NA, NA, NA, NA, NA, NA, NA} },
{"VCORE2EMI_N1_GALS_TX", 0x2901C,
{ 0, 2, NA, NA, NA, NA, NA, NA, NA} },
{"DLA02CONN_M0_GALS_RX", 0x2901C,
{ 0, 6, NA, 2, NA, 1, NA, NA, NA} },
{"DLA02CONN_M1_GALS_RX", 0x2901C,
{ 0, 6, NA, 2, NA, 2, NA, NA, NA} },
{"MMU0_N0_GALS_TX", 0x2901C,
{ 0, 6, NA, 3, NA, NA, 1, NA, NA} },
{"MMU0_N1_GALS_TX", 0x2901C,
{ 0, 6, NA, 3, NA, NA, 2, NA, NA} },
{"EDMMA_NOC_0_RX", 0x2901C,
{ 0, 6, NA, 4, NA, NA, NA, 1, NA} },
{"MNOC_MISC_0_DBG_BUS", 0x2901C,
{ 0, 6, NA, 5, NA, NA, NA, NA, 1} },
{"APU_UP_SYS_DBG_BUS", 0x2901C,
{ 0, 6, NA, 5, NA, NA, NA, NA, 4} },
{"APUSYS_AO_DBG_PCU", 0x2901C,
{ 1, NA, 7, NA, NA, NA, NA, NA, NA} },
{"APUSYS_AO_DBG_RPC", 0x2901C,
{ 1, NA, 7, NA, NA, NA, NA, NA, NA} },
};
#define TOTAL_DBG_MUX_COUNT \
(sizeof(value_table)/sizeof(struct dbg_mux_sel_value))
struct reg_dump_info {
char name[128];
u32 base;
u32 size;
};
struct reg_dump_info range_table[] = {
{"apusys_ao-0", 0x190f0000, 0x1000},
{"apusys_ao-1", 0x190f1000, 0x1000},
{"apusys_ao-2", 0x190f2000, 0x1000},
{"apusys_ao-3", 0x190f3000, 0x1000},
{"apusys_ao-4", 0x190f4000, 0x800},
{"apusys_ao-5", 0x190f4800, 0x800},
{"apusys_ao-6", 0x19029000, 0x1000},
{"apusys_ao-8", 0x190f8000, 0x400},
{"apusys_ao-9", 0x190fc000, 0x400},
{"md32_apb_s-0", 0x19001000, 0x800},
{"md32_apb_s-1", 0x19002000, 0x1000},
{"noc_axi", 0x1d000000, 0x0},
{"apu_con2_config", 0x19020000, 0x1000},
{"apu_con1_config", 0x19024000, 0x1000},
{"apu_sema_stimer", 0x19022000, 0x1000},
{"apu_emi_config", 0x19023000, 0x1000},
{"apu_edma0", 0x19025000, 0x1000},
{"apu_dapc", 0x19064000, 0x1000},
{"infra_bcrm", 0x19065000, 0x1000},
{"infra_ao_bcrm", 0x19067000, 0x1000},
{"noc_dapc", 0x1906c000, 0x1000},
{"apu_noc_bcrm", 0x1906d000, 0x1000},
{"apu_noc_config_0", 0x1906e000, 0x2000},
{"vpu_core0_config-0", 0x19030000, 0x800},
{"vpu_core0_config-1", 0x19030800, 0x800},
{"vpu_core1_config-0", 0x19031000, 0x800},
{"vpu_core1_config-1", 0x19031800, 0x800},
{"mdla0_apb-0", 0x19034000, 0x1000},
{"mdla0_apb-1", 0x19035000, 0x800},
{"mdla0_apb-2", 0x19035800, 0x800},
{"mdla0_apb-3", 0x19036000, 0x2000},
{"apu_iommu0_r0", 0x19010000, 0x1000},
{"apu_n0_ssc_config", 0x1901e000, 0x1000},
};
#define SEGMENT_COUNT (sizeof(range_table)/sizeof(struct reg_dump_info))
#endif
@@ -0,0 +1,174 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APUSYS_MIDWARE_PLATFORM_H__
#define __APUSYS_MIDWARE_PLATFORM_H__
extern struct dentry *mdw_dbg_root;
#define APUSYS_VLM_START 0x1D800000 // tcm tmp
#define APUSYS_VLM_SIZE 0x100000
#define APUSYS_REG_SIZE (0x100000)
#define APUSYS_BASE (0x19000000)
#define INFRA_BASE (0x10000000)
#define INFRA_SIZE (0x10000)
#define NA (-1)
char *reg_all_mem;
bool apusys_dump_force;
static void *apu_top;
static void *apu_to_infra_top;
struct dbg_mux_sel_info {
int offset;
int start_bit;
int end_bit;
};
struct dbg_mux_sel_info info_table[] = {
{0x29010, 1, 1 }, //vcore_dbg_sel
{0x29010, 4, 2 }, //vcore_dbg_sel0
{0x29010, 7, 5 }, //vcore_dbg_sel1
{0x20138, 2, 0 }, //conn_dbg0_sel
{0x20138, 11, 9 }, //conn_dbg3_sel
{0x20138, 14, 12}, //conn_dbg4_sel
{0x20138, 17, 15}, //conn_dbg5_sel
{0x20138, 20, 18}, //conn_dbg6_sel
{0x34130, 10, 10}, //mdla0_axi_gals_dbg_sel
{0x38130, 10, 10}, //mdla1_axi_gals_dbg_sel
{0x30a10, 10, 10}, //vpu0_apu_gals_m_ctl_sel
{0x31a10, 10, 10}, //vpu1_apu_gals_m_ctl_sel
{0x32a10, 10, 10}, //vpu2_apu_gals_m_ctl_sel
};
#define DBG_MUX_SEL_COUNT (sizeof(info_table)/sizeof(struct dbg_mux_sel_info))
struct dbg_mux_sel_value {
char name[128];
int status_reg_offset;
int dbg_sel[DBG_MUX_SEL_COUNT];
};
struct dbg_mux_sel_value value_table[] = {
{"VCORE2EMI_N0_GALS_TX", 0x2901C,
{ 0, 1, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"VCORE2EMI_N1_GALS_TX", 0x2901C,
{ 0, 2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"VCORE2EMI_S0_GALS_TX", 0x2901C,
{ 0, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"VCORE2EMI_S1_GALS_TX", 0x2901C,
{ 0, 4, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_N0_GALS_RX", 0x2901C,
{ 1, NA, 1, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_N1_GALS_RX", 0x2901C,
{ 1, NA, 2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S0_GALS_RX", 0x2901C,
{ 1, NA, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S1_GALS_RX", 0x2901C,
{ 1, NA, 4, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_VCORE_GALS_TX", 0x2901C,
{ 1, NA, 6, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_VCORE_GALS_RX", 0x2901C,
{ 0, 6, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"XPU2APUSYS_CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 0, NA, NA, NA, NA, NA, NA} },
{"VPU02CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 1, 1, NA, NA, NA, NA, NA, NA, NA, NA} },
{"VPU12CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 1, 2, NA, NA, NA, NA, NA, NA, NA, NA} },
{"VPU22CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 1, 3, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VPU0_GALS_TX", 0x2901C,
{ 0, 7, NA, 1, 4, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VPU1_GALS_TX", 0x2901C,
{ 0, 7, NA, 1, 5, NA, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VPU2_GALS_TX", 0x2901C,
{ 0, 7, NA, 1, 0, NA, NA, NA, NA, NA, NA, NA, NA} },
{"MDLA0M02CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 2, NA, 1, NA, NA, NA, NA, NA, NA, NA} },
{"MDLA0M12CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 2, NA, 2, NA, NA, NA, NA, NA, NA, NA} },
{"MDLA1M02CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 2, NA, 3, NA, NA, NA, NA, NA, NA, NA} },
{"MDLA1M12CONN_GALS_RX", 0x2901C,
{ 0, 7, NA, 2, NA, 0, NA, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_N0_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 3, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_N1_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 4, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S0_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 1, NA, NA, NA, NA, NA, NA} },
{"CONN2VCORE_EMI_S1_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 2, NA, NA, NA, NA, NA, NA} },
{"MDLA0M02CONN_GALS_TX", 0x3413C,
{NA, NA, NA, NA, NA, NA, NA, NA, 0, NA, NA, NA, NA} },
{"MDLA0M12CONN_GALS_TX", 0x3413C,
{NA, NA, NA, NA, NA, NA, NA, NA, 1, NA, NA, NA, NA} },
{"MDLA1M02CONN_GALS_TX", 0x3813C,
{NA, NA, NA, NA, NA, NA, NA, NA, NA, 0, NA, NA, NA} },
{"MDLA1M12CONN_GALS_TX", 0x3813C,
{NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, NA, NA, NA} },
{"APUSYS2ACP_VCORE_GALS_TX", 0x2901C,
{ 0, 5, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"APUSYS2ACP_VCORE_GALS_RX", 0x2901C,
{ 1, NA, 5, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA} },
{"APUSYS2ACP_CONN_GALS_TX", 0x2901C,
{ 0, 7, NA, 3, NA, NA, 5, NA, NA, NA, NA, NA, NA} },
};
#define TOTAL_DBG_MUX_COUNT \
(sizeof(value_table)/sizeof(struct dbg_mux_sel_value))
struct reg_dump_info {
char name[128];
u32 base;
u32 size;
};
struct reg_dump_info range_table[] = {
{"md32_sysCtrl", 0x19001000, 0x800 },
{"md32_sysCtrl_PMU", 0x19001800, 0x800 },
{"md32_wdt", 0x19002000, 0x1000},
{"apu_iommu0_r0", 0x19010000, 0x1000},
{"apu_iommu0_r1", 0x19011000, 0x1000},
{"apu_iommu0_r2", 0x19012000, 0x1000},
{"apu_iommu0_r3", 0x19013000, 0x1000},
{"apu_iommu0_r4", 0x19014000, 0x1000},
{"apu_iommu1_r0", 0x19015000, 0x1000},
{"apu_iommu1_r1", 0x19016000, 0x1000},
{"apu_iommu1_r2", 0x19017000, 0x1000},
{"apu_iommu1_r3", 0x19018000, 0x1000},
{"apu_iommu1_r4", 0x19019000, 0x1000},
{"apu_south_rsi_config", 0x1901A000, 0x1000},
{"apu_north_rsi_config", 0x1901B000, 0x1000},
{"apu_xpu_rsi_config", 0x1901C000, 0x1000},
{"apu_south_ssc_config", 0x1901D000, 0x1000},
{"apu_north_ssc_config", 0x1901E000, 0x1000},
{"apu_apcssc_config", 0x1901F000, 0x1000},
{"apu_conn_config", 0x19020000, 0x1000},
{"apu_sema_stimer", 0x19022000, 0x1000},
{"emi_config", 0x19023000, 0x1000},
{"apu_adl", 0x19024000, 0x1000},
{"apu_edma_lite0", 0x19025000, 0x1000},
{"apu_edma_lite1", 0x19026000, 0x1000},
{"apu_edma0", 0x19027000, 0x1000},
{"apu_edma1", 0x19028000, 0x1000},
{"apu_Vcore_config", 0x19029000, 0x1000},
{"apb_dapc_wrapper", 0x19064000, 0x1000},
{"infra_bcrm", 0x19065000, 0x1000},
{"apb_debug_ctl", 0x19066000, 0x1000},
{"noc_dapc_wrapper", 0x1906C000, 0x1000},
{"apu_noc_bcrm", 0x1906D000, 0x1000},
{"apu_noc_config_0", 0x1906E000, 0x2000},
{"apu_rpc(CPC)", 0x190F0000, 0x1000},
{"apu_rpc(DVFS)", 0x190F1000, 0x1000},
{"apb_dapc_ap_wrapper", 0x190F8000, 0x4000},
{"noc_dapc_ap_wrapper", 0x190FC000, 0x4000},
};
#define SEGMENT_COUNT (sizeof(range_table)/sizeof(struct reg_dump_info))
#endif
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/pm_qos.h>
#include <linux/soc/mediatek/mtk-pm-qos.h>
static struct mtk_pm_qos_request ddr_opp_req;
void secure_perf_init(void)
{
mtk_pm_qos_add_request(&ddr_opp_req, MTK_PM_QOS_DDR_OPP,
MTK_PM_QOS_DDR_OPP_DEFAULT_VALUE);
}
void secure_perf_remove(void)
{
mtk_pm_qos_remove_request(&ddr_opp_req);
}
void secure_perf_raise(void)
{
/* Fix DDR to higher frequency (OPP 3) */
//pm_qos_update_request(&ddr_opp_req, 3);
}
void secure_perf_restore(void)
{
/* Reset DDR to default OPP */
//pm_qos_update_request(&ddr_opp_req, PM_QOS_DDR_OPP_DEFAULT_VALUE);
}
@@ -0,0 +1,17 @@
#
# Copyright (C) 2019 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/apusys/power/2.0/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/apusys/power/2.0/$(MTK_PLATFORM)
obj-y += dapc.o dapc_cfg.o
+646
View File
@@ -0,0 +1,646 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/debugfs.h>
#include <linux/random.h>
#include <linux/slab.h>
#if defined(CONFIG_MTK_AEE_FEATURE)
#include <mt-plat/aee.h>
#endif
#include "dapc.h"
#include "dapc_cfg.h"
#include "apusys_power.h"
struct dapc_driver *dapc_drv;
#ifdef CONFIG_MTK_ENG_BUILD
/* apusys devapc debug file operations */
static int apusys_devapc_open(struct inode *inode, struct file *file)
{
file->private_data = inode->i_private;
return nonseekable_open(inode, file);
}
static int apusys_devapc_release(struct inode *inode, struct file *file)
{
return 0;
}
static int trigger_vio_test(struct dapc_driver *drv, int round)
{
phys_addr_t test_base = drv->cfg->ut_base;
void __iomem *test_virt;
int i, num, flag_ke;
if (round <= 0) {
pr_info("invalid round %d\n", round);
return -EINVAL;
}
test_virt = ioremap(test_base, 4096);
if (!test_virt) {
pr_info("ioremap test base(0x%lx) virt failed\n",
(unsigned long)test_base);
return -ENOMEM;
}
/* do not trigger KE while testing */
flag_ke = drv->enable_ke;
drv->enable_ke = 0;
for (i = 0; i < round; i++) {
get_random_bytes(&num, sizeof(num));
num &= 0xF;
/* mdla_core0 0x8 */
iowrite32(num, (unsigned int *)(test_virt + 0x8));
pr_info("write 0x%x to (0x%lx), read: 0x%x\n",
num, (unsigned long)(test_base + 0x8),
readl((unsigned int *)(test_virt + 0x8)));
get_random_bytes(&num, sizeof(num));
num &= 0xF;
/* mdla_core1 0xC */
iowrite32(num, (unsigned int *)(test_virt + 0xC));
pr_info("write 0x%x to (0x%lx), read: 0x%x\n",
num, (unsigned long)(test_base + 0xC),
readl((unsigned int *)(test_virt + 0xC)));
}
iounmap(test_virt);
drv->enable_ke = flag_ke;
return 0;
}
static ssize_t apusys_devapc_read(struct file *file, char __user *buf,
size_t size, loff_t *offset)
{
struct dapc_driver *drv = (struct dapc_driver *)file->private_data;
char output[64] = {0};
int ret, len;
if (!buf)
return -EINVAL;
ret = snprintf(output, sizeof(output),
"%s enable_KE: %d, enable_AEE: %d, enable_IRQ: %d\n",
"[APUSYS_DEVAPC]", drv->enable_ke, drv->enable_aee,
drv->enable_irq);
if (ret <= 0)
return 0;
len = min((int)size, (int)(strlen(output) - *offset));
if (len <= 0)
return 0;
ret = copy_to_user(buf, output, len);
if (ret) {
pr_info("Fail to copy %s, ret %d\n", output, ret);
return -EFAULT;
}
*offset += len;
return len;
}
static void apusys_devapc_start(void *data);
static ssize_t apusys_devapc_write(struct file *file, const char __user *buf,
size_t size, loff_t *ppos)
{
struct dapc_driver *drv = (struct dapc_driver *)file->private_data;
char input[32] = {0};
char *cmd_str, *param_str, *tmp_str;
unsigned int param = 0;
size_t len;
int ret;
if (!buf)
return -EINVAL;
len = min(size, 31UL);
if (copy_from_user(input, buf, len)) {
pr_info("Fail to copy from user\n");
return -EFAULT;
}
input[len] = '\0';
tmp_str = input;
cmd_str = strsep(&tmp_str, " ");
if (!cmd_str) {
pr_info("Fail to get cmd\n");
return -EINVAL;
}
param_str = strsep(&tmp_str, " ");
if (!param_str) {
pr_info("Fail to get param\n");
return -EINVAL;
}
ret = kstrtouint(param_str, 10, &param);
if (ret)
return ret;
if (!strncmp(cmd_str, "enable_UT", sizeof("enable_UT"))) {
if (param & 0x1) {
drv->enable_ke = 0;
drv->enable_aee = 0;
drv->enable_irq = 1;
pr_info("APUSYS devapc debugging mode\n");
} else {
drv->enable_ke = 1;
drv->enable_aee = 1;
drv->enable_irq = 1;
pr_info("APUSYS devapc violation mode\n");
}
} else if (!strncmp(cmd_str, "enable_KE", sizeof("enable_KE"))) {
drv->enable_ke = param & 0x1;
pr_info("APUSYS devapc %s KE\n",
drv->enable_ke ? "enable" : "disable");
} else if (!strncmp(cmd_str, "enable_AEE", sizeof("enable_AEE"))) {
drv->enable_aee = param & 0x1;
pr_info("APUSYS devapc %s AEE\n",
drv->enable_aee ? "enable" : "disable");
} else if (!strncmp(cmd_str, "enable_IRQ", sizeof("enable_IRQ"))) {
drv->enable_irq = param & 0x1;
if (drv->enable_irq)
enable_irq(drv->irq);
else
disable_irq(drv->irq);
pr_info("APUSYS devapc %s IRQ\n",
drv->enable_irq ? "enable" : "disable");
} else if (!strncmp(cmd_str, "restart", sizeof("restart"))) {
apusys_devapc_start(NULL);
pr_info("APUSYS devapc restarted\n");
} else if (!strncmp(cmd_str, "trigger_vio", sizeof("trigger_vio"))) {
pr_info("APUSYS devapc trigger vio test %d +\n", param);
trigger_vio_test(drv, param);
pr_info("APUSYS devapc trigger vio test %d -\n", param);
} else {
pr_info("Unknown cmd %s\n", cmd_str);
return -EINVAL;
}
return len;
}
static const struct file_operations apusys_devapc_fops = {
.owner = THIS_MODULE,
.open = apusys_devapc_open,
.read = apusys_devapc_read,
.write = apusys_devapc_write,
.release = apusys_devapc_release,
};
/* apusys devapc debug file operations */
static int apusys_devapc_debug_init(struct dapc_driver *drv)
{
struct dentry *droot = NULL;
int ret = 0;
droot = debugfs_create_dir("apusys_devapc", NULL);
if (IS_ERR_OR_NULL(droot)) {
ret = PTR_ERR(droot);
pr_info("%s: unable to create debugfs folder: %d\n",
__func__, ret);
return ret;
}
debugfs_create_u32("debug",
0644, droot, &drv->debug_log);
debugfs_create_file("apusys_devapc", 0644,
droot, drv, &apusys_devapc_fops);
drv->droot = droot;
return ret;
}
static void apusys_devapc_debug_exit(struct dapc_driver *drv)
{
debugfs_remove_recursive(drv->droot);
drv->droot = NULL;
}
#else
static int apusys_devapc_debug_init(struct dapc_driver *drv)
{
return 0;
}
static void apusys_devapc_debug_exit(struct dapc_driver *drv)
{
}
#endif
static void slv_irq(unsigned int slv, bool enable)
{
uint32_t reg;
uint32_t mask;
struct dapc_driver *d = dapc_drv;
struct dapc_config *cfg = d->cfg;
if (slv > cfg->slv_cnt) {
pr_info("%s: slv: %d is out of index, max: %d\n",
slv, cfg->slv_cnt);
return;
}
reg = cfg->vio_mask(slv / cfg->slv_per_dapc);
mask = 1 << (slv % cfg->slv_per_dapc);
if (enable)
dapc_reg_clr(d, reg, mask);
else
dapc_reg_set(d, reg, mask);
}
static void do_kernel_exception(struct dapc_driver *drv, unsigned int i,
const char *slv_name,
struct dapc_exception *ex)
{
/* mask irq for slv "i" */
slv_irq(i, false);
if (drv->enable_ke) {
WARN_ON(1);
goto out;
}
#if defined(CONFIG_MTK_AEE_FEATURE)
if (drv->enable_aee) {
aee_kernel_exception("APUSYS_DEVAPC",
"Violation Slave: %s (%s%s): transaction ID:0x%x, Addr:0x%x, HighAddr: %x, Domain: 0x%x\n",
slv_name,
(ex->read_vio) ? "R" : "",
(ex->write_vio) ? " W" : "",
ex->trans_id,
ex->addr,
ex->addr_high,
ex->domain_id);
}
#endif
out:
/* unmask irq for slv "i" */
slv_irq(i, true);
}
static uint32_t check_vio_status(unsigned int slv)
{
uint32_t reg;
uint32_t mask;
struct dapc_driver *d = dapc_drv;
struct dapc_config *cfg = d->cfg;
if (slv > cfg->slv_cnt) {
pr_info("%s: slv: %d is out of index, max: %d\n",
slv, cfg->slv_cnt);
return -EINVAL;
}
reg = cfg->vio_sta(slv / cfg->slv_per_dapc);
mask = 0x1 << (slv % cfg->slv_per_dapc);
return dapc_reg_r(d, reg) & mask;
}
static void clear_vio_status(unsigned int slv)
{
uint32_t reg;
uint32_t mask;
struct dapc_driver *d = dapc_drv;
struct dapc_config *cfg = d->cfg;
if (slv > cfg->slv_cnt) {
pr_info("%s: slv: %d is out of index, max: %d\n",
slv, cfg->slv_cnt);
return;
}
reg = cfg->vio_sta(slv / cfg->slv_per_dapc);
mask = 0x1 << (slv % cfg->slv_per_dapc);
dapc_reg_w(d, reg, mask);
}
static int shift_vio_dbg(int shift_bit)
{
int count = 0;
struct dapc_driver *d = dapc_drv;
struct dapc_config *cfg = d->cfg;
uint32_t sel = cfg->vio_shift_sel;
uint32_t con = cfg->vio_shift_con;
uint32_t mask = cfg->vio_shift_con_mask;
/* start shift */
dapc_reg_w(d, sel, (0x1 << shift_bit));
dapc_reg_w(d, con, 0x1);
/* wait for shift done */
while (((dapc_reg_r(d, con) & mask) != mask) && (count < 100))
count++;
pr_debug("%s: shift done %d, %d, SHIFT_SEL: 0x%x, SHIFT_CON=0x%x\n",
__func__, shift_bit, count,
dapc_reg_r(d, sel), dapc_reg_r(d, con));
if ((dapc_reg_r(d, con) & mask) != mask) {
pr_info("%s: shift bit %d failed\n", shift_bit);
return -EFAULT;
}
/* disable shift mechanism */
dapc_reg_w(d, con, 0);
dapc_reg_w(d, sel, 0);
/* SHIFT_STA must be write-cleared before clear VIO_STA */
dapc_reg_w(d, cfg->vio_shift_sta, (0x1 << shift_bit));
return 0;
}
static void apusys_devapc_dbg(const char *prefix)
{
struct dapc_driver *d = dapc_drv;
struct dapc_config *cfg = d->cfg;
if (!dapc_drv->debug_log)
return;
pr_info("%s: %s: VIO_MASK0~3: 0x%x, 0x%x, 0x%x, 0x%x, VIO_STA0~3: 0x%x, 0x%x, 0x%x, 0x%x\n",
__func__,
prefix,
dapc_reg_r(d, cfg->vio_mask(0)),
dapc_reg_r(d, cfg->vio_mask(1)),
dapc_reg_r(d, cfg->vio_mask(2)),
dapc_reg_r(d, cfg->vio_mask(3)),
dapc_reg_r(d, cfg->vio_sta(0)),
dapc_reg_r(d, cfg->vio_sta(1)),
dapc_reg_r(d, cfg->vio_sta(2)),
dapc_reg_r(d, cfg->vio_sta(3)));
}
/* Return 1 means there are some violations */
static inline int is_violation_irq(void)
{
struct dapc_driver *d = dapc_drv;
struct dapc_config *cfg = d->cfg;
return (dapc_reg_r(d, cfg->vio_sta(0)) ||
dapc_reg_r(d, cfg->vio_sta(1)) ||
dapc_reg_r(d, cfg->vio_sta(2)) ||
dapc_reg_r(d, cfg->vio_sta(3)));
}
static irqreturn_t apusys_devapc_isr(int irq_number, void *data)
{
int i;
struct dapc_driver *d = (struct dapc_driver *)data;
struct dapc_config *cfg;
unsigned int shift_max;
struct dapc_slave *slv;
struct dapc_exception ex;
if (!is_violation_irq())
return IRQ_NONE;
if (!d || IS_ERR_OR_NULL(d->reg)) {
pr_info("%s: driver abort\n", __func__);
return IRQ_NONE;
}
cfg = d->cfg;
slv = cfg->slv;
shift_max = cfg->vio_shift_max_bit;
if (irq_number != d->irq) {
pr_info("%s: get unknown irq %d\n", __func__, irq_number);
return IRQ_NONE;
}
if (!d->irq) {
pr_info("%s: Disable vio irq handler\n", __func__);
return IRQ_NONE;
}
memset(&ex, 0, sizeof(struct dapc_exception));
disable_irq_nosync(irq_number);
apusys_devapc_dbg("ISR begin");
for (i = 0; i <= shift_max; ++i) {
if (!(dapc_reg_r(d, cfg->vio_shift_sta) & (0x1 << i)))
continue;
if (shift_vio_dbg(i))
continue;
pr_info("%s: VIO_SHIFT_STA=0x%x, VIO_SHIFT_SEL=0x%x, VIO_SHIFT_CON=0x%x,\n",
__func__,
dapc_reg_r(d, cfg->vio_shift_sta),
dapc_reg_r(d, cfg->vio_shift_sel),
dapc_reg_r(d, cfg->vio_shift_con));
cfg->excp_info(d, &ex);
/* violation information */
pr_info("%s: Violation(%s%s): transaction ID:0x%x, Addr:0x%x, HighAddr: %x, Domain: 0x%x\n",
__func__,
(ex.read_vio) ? "R" : "",
(ex.write_vio) ? " W" : "",
ex.trans_id,
ex.addr,
ex.addr_high,
ex.domain_id);
}
/* Clear VIO_STA */
for_each_dapc_slv(cfg, i) {
if (!(slv[i].vio_irq_en && check_vio_status(i)))
continue;
clear_vio_status(i);
pr_info("%s: vio_sta device: %d, slave: %s\n",
__func__, i, slv[i].name);
do_kernel_exception(d, i, slv[i].name, &ex);
}
apusys_devapc_dbg("ISR end");
enable_irq(irq_number);
return IRQ_HANDLED;
}
static void apusys_devapc_start(void *data)
{
int i = 0;
struct dapc_driver *d = dapc_drv;
struct dapc_config *cfg = d->cfg;
struct dapc_slave *slv = cfg->slv;
/* Clear APC violation status */
dapc_reg_w(d, cfg->apc_con, cfg->apc_con_vio);
apusys_devapc_dbg("Init begin");
/* Enable violation IRQ */
for_each_dapc_slv(cfg, i) {
if (!slv[i].vio_irq_en)
continue;
clear_vio_status(i);
slv_irq(i, true);
}
apusys_devapc_dbg("Init end");
}
static int apusys_devapc_probe(struct platform_device *pdev)
{
int ret = 0;
struct device_node *devapc_node;
struct dapc_driver *drv;
struct dapc_config *cfg;
dev_info(&pdev->dev, "%s +\n", __func__);
if (!apusys_power_check())
return 0;
devapc_node = pdev->dev.of_node;
if (!devapc_node) {
dev_info(&pdev->dev, "of_node required\n");
return -ENODEV;
}
if (dapc_drv) {
dev_info(&pdev->dev, "duplicated device node\n");
return -ENODEV;
}
cfg = (struct dapc_config *)of_device_get_match_data(&pdev->dev);
if (!cfg) {
dev_info(&pdev->dev, "unsupported device: %s\n", pdev->name);
return -ENODEV;
}
drv = kzalloc(sizeof(struct dapc_driver), GFP_KERNEL);
if (!drv) {
ret = -ENOMEM;
goto err_allocate;
}
dapc_drv = drv;
drv->cfg = cfg;
drv->reg = of_iomap(devapc_node, 0);
if (!drv->reg) {
ret = -ENOMEM;
goto err_iomap;
}
drv->irq = irq_of_parse_and_map(devapc_node, 0);
ret = request_irq(drv->irq, apusys_devapc_isr,
irq_get_trigger_type(drv->irq) | IRQF_SHARED,
"apusys-devapc", drv);
if (ret) {
ret = -EFAULT;
goto err_request_irq;
}
drv->enable_ke = drv->enable_aee = 1;
if (drv->cfg->irq_enable) {
drv->enable_irq = 1;
} else {
drv->enable_irq = 0;
disable_irq(drv->irq);
}
apusys_devapc_start(NULL);
ret = apu_power_callback_device_register(DEVAPC,
apusys_devapc_start, NULL);
if (ret)
dev_info(&pdev->dev,
"unable to register to apu power: %d\n", ret);
drv->debug_log = 0;
apusys_devapc_debug_init(drv);
platform_set_drvdata(pdev, drv);
dev_info(&pdev->dev, "%s -\n", __func__);
return 0;
err_request_irq:
iounmap(drv->reg);
err_iomap:
kfree(drv);
err_allocate:
dapc_drv = NULL;
return ret;
}
static int apusys_devapc_remove(struct platform_device *pdev)
{
struct dapc_driver *drv = platform_get_drvdata(pdev);
dev_dbg(&pdev->dev, "%s +\n", __func__);
free_irq(drv->irq, drv);
iounmap(drv->reg);
apusys_devapc_debug_exit(drv);
apu_power_callback_device_unregister(DEVAPC);
kfree(drv);
dev_dbg(&pdev->dev, "%s -\n", __func__);
dapc_drv = NULL;
return 0;
}
static const struct of_device_id apusys_devapc_of_match[] = {
{ .compatible = "mediatek,mt6885-apusys_devapc", &dapc_cfg_mt6885 },
{ .compatible = "mediatek,mt6873-apusys_devapc", &dapc_cfg_mt6873 },
{ .compatible = "mediatek,mt6853-apusys_devapc", &dapc_cfg_mt6853 },
{ .compatible = "mediatek,mt6893-apusys_devapc", &dapc_cfg_mt6885 },
{ .compatible = "mediatek,mt6877-apusys_devapc", &dapc_cfg_mt6877 },
{},
};
static struct platform_driver apusys_devapc_driver = {
.probe = apusys_devapc_probe,
.remove = apusys_devapc_remove,
.driver = {
.name = "apusys-devapc",
.owner = THIS_MODULE,
.of_match_table = apusys_devapc_of_match,
},
};
static int __init apusys_devapc_init(void)
{
dapc_drv = NULL;
return platform_driver_register(&apusys_devapc_driver);
}
static void __exit apusys_devapc_exit(void)
{
platform_driver_unregister(&apusys_devapc_driver);
}
late_initcall(apusys_devapc_init);
module_exit(apusys_devapc_exit);
MODULE_DESCRIPTION("Mediatek APUSYS DEVAPC Driver");
MODULE_AUTHOR("Mediatek");
MODULE_LICENSE("GPL");
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APUSYS_DAPC_H__
#define __APUSYS_DAPC_H__
#include <linux/types.h>
#include "dapc_cfg.h"
struct dapc_driver {
void __iomem *reg;
int irq;
unsigned int debug_log;
int enable_ke;
int enable_aee;
int enable_irq;
struct dentry *droot;
struct dentry *ddebug;
struct dentry *dfile;
struct dapc_config *cfg;
};
#endif
@@ -0,0 +1,393 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/types.h>
#include <linux/io.h>
#include "dapc.h"
#include "dapc_cfg.h"
#define __dbg(dbg, cfg, a) \
((dbg & cfg->vio_dbg_##a) >> cfg->vio_dbg_##a##_shift)
/*
* Platform devapc slaves
* {sys_idx, ctrl_idx, vio_idx, name, vio_irq_en}
* Note: "vio_idx" must be aligned with array index,
* add paddings to make them continuous.
*/
static struct dapc_slave dapc_slv_mt6885[] = {
{0, 0, 0, "apusys_ao-0", true},
{0, 1, 1, "apusys_ao-1", true},
{0, 2, 2, "apusys_ao-2", true},
{0, 3, 3, "apusys_ao-3", true},
{0, 4, 4, "apusys_ao-4", true},
{0, 5, 5, "apusys_ao-5", true},
{0, 6, 6, "md32_apb_s-0", true},
{0, 7, 7, "md32_apb_s-1", true},
{0, 8, 8, "md32_apb_s-2", true},
{0, 0, 9, "NULL_PADDING", false}, /* padding */
{0, 9, 10, "md32_debug_apb", true},
{0, 10, 11, "apu_conn_config", true},
{0, 11, 12, "apu_sctrl_reviser", true},
{0, 12, 13, "apu_sema_stimer", true},
{0, 13, 14, "apu_emi_config", true},
{0, 14, 15, "apu_adl", true},
{0, 15, 16, "apu_edma_lite0", true},
{0, 16, 17, "apu_edma_lite1", true},
{0, 17, 18, "apu_edma0", true},
{0, 18, 19, "apu_edma1", true},
{0, 19, 20, "apu_dapc_ao", true},
{0, 20, 21, "apu_dapc", true},
{0, 21, 22, "infra_bcrm", true},
{0, 22, 23, "apb_dbg_ctl", true},
{0, 23, 24, "noc_dapc", true},
{0, 24, 25, "apu_noc_bcrm", true},
{0, 25, 26, "apu_noc_config", true},
{0, 26, 27, "vpu_core0_config-0", true},
{0, 27, 28, "vpu_core0_config-1", true},
{0, 28, 29, "vpu_core1_config-0", true},
{0, 29, 30, "vpu_core1_config-1", true},
{0, 30, 31, "vpu_core2_config-0", true},
{0, 31, 32, "vpu_core2_config-1", true},
{0, 32, 33, "mdla0_apb-0", true},
{0, 33, 34, "mdla0_apb-1", true},
{0, 34, 35, "mdla0_apb-2", true},
{0, 35, 36, "mdla0_apb-3", true},
{0, 36, 37, "mdla1_apb-0", true},
{0, 37, 38, "mdla1_apb-1", true},
{0, 38, 39, "mdla1_apb-2", true},
{0, 39, 40, "mdla1_apb-3", true},
{0, 40, 41, "apu_iommu0_r0", true},
{0, 41, 42, "apu_iommu0_r1", true},
{0, 42, 43, "apu_iommu0_r2", true},
{0, 43, 44, "apu_iommu0_r3", true},
{0, 44, 45, "apu_iommu0_r4", true},
{0, 45, 46, "apu_iommu1_r0", true},
{0, 46, 47, "apu_iommu1_r1", true},
{0, 47, 48, "apu_iommu1_r2", true},
{0, 48, 49, "apu_iommu1_r3", true},
{0, 49, 50, "apu_iommu1_r4", true},
{0, 50, 51, "apu_rsi0_config", true},
{0, 51, 52, "apu_rsi1_config", true},
{0, 52, 53, "apu_rsi2_config", true},
{0, 53, 54, "apu_ssc0_config", true},
{0, 54, 55, "apu_ssc1_config", true},
{0, 55, 56, "apu_ssc2_config", true},
{0, 56, 57, "vp6_core0_debug_apb", true},
{0, 57, 58, "vp6_core1_debug_apb", true},
{0, 58, 59, "vp6_core2_debug_apb", true},
DAPC_SLAVE_END
};
static struct dapc_slave dapc_slv_mt6873[] = {
{0, 0, 0, "apusys_ao-0", true},
{0, 1, 1, "apusys_ao-1", true},
{0, 2, 2, "apusys_ao-2", true},
{0, 3, 3, "apusys_ao-3", true},
{0, 4, 4, "apusys_ao-4", true},
{0, 5, 5, "apusys_ao-5", true},
{0, 6, 6, "md32_apb_s-0", true},
{0, 7, 7, "md32_apb_s-1", true},
{0, 8, 8, "md32_apb_s-2", true},
{0, 0, 9, "NULL_PADDING", false}, /* padding */
{0, 9, 10, "md32_debug_apb", true},
{0, 10, 11, "apu_conn_config", true},
{0, 11, 12, "apu_sctrl_reviser", true},
{0, 12, 13, "apu_sema_stimer", true},
{0, 13, 14, "apu_emi_config", true},
{0, 14, 15, "apu_edma0", true},
{0, 15, 16, "apu_dapc_ao", true},
{0, 16, 17, "apu_dapc", true},
{0, 17, 18, "infra_bcrm", true},
{0, 18, 19, "apb_dbg_ctl", true},
{0, 19, 20, "noc_dapc", true},
{0, 20, 21, "apu_noc_bcrm", true},
{0, 21, 22, "apu_noc_config_0", true},
{0, 22, 23, "apu_noc_config_1", true},
{0, 23, 24, "apu_noc_config_2", true},
{0, 24, 25, "apu_noc_config_3", true},
{0, 25, 26, "apu_noc_config_4", true},
{0, 26, 27, "vpu_core0_config-0", true},
{0, 27, 28, "vpu_core0_config-1", true},
{0, 28, 29, "vpu_core1_config-0", true},
{0, 29, 30, "vpu_core1_config-1", true},
{0, 30, 31, "mdla0_apb-0", true},
{0, 31, 32, "mdla0_apb-1", true},
{0, 32, 33, "mdla0_apb-2", true},
{0, 33, 34, "mdla0_apb-3", true},
{0, 34, 35, "apu_iommu0_r0", true},
{0, 35, 36, "apu_iommu0_r1", true},
{0, 36, 37, "apu_iommu0_r2", true},
{0, 37, 38, "apu_iommu0_r3", true},
{0, 38, 39, "apu_iommu0_r4", true},
{0, 39, 40, "apu_rsi2_config", true},
{0, 40, 41, "apu_ssc2_config", true},
{0, 41, 42, "vp6_core0_debug_apb", true},
{0, 42, 43, "vp6_core1_debug_apb", true},
DAPC_SLAVE_END
};
static struct dapc_slave dapc_slv_mt6853[] = {
{0, 0, 0, "apusys_ao-0", true},
{0, 1, 1, "apusys_ao-1", true},
{0, 2, 2, "apusys_ao-2", true},
{0, 3, 3, "apusys_ao-3", true},
{0, 4, 4, "apusys_ao-4", true},
{0, 5, 5, "apusys_ao-5", true},
{0, 6, 6, "md32_apb_s-0", true},
{0, 7, 7, "md32_apb_s-1", true},
{0, 8, 8, "md32_apb_s-2", true},
{0, 0, 9, "NULL_PADDING", false}, /* padding */
{0, 9, 10, "md32_debug_apb", true},
{0, 10, 11, "apu_conn_config", true},
{0, 11, 12, "apu_sctrl_reviser", true},
{0, 12, 13, "apu_sema_stimer", true},
{0, 13, 14, "apu_emi_config", true},
{0, 14, 15, "apu_dapc_ao", true},
{0, 15, 16, "apu_dapc", true},
{0, 16, 17, "infra_bcrm", true},
{0, 17, 18, "apb_dbg_ctl", true},
{0, 18, 19, "noc_dapc", true},
{0, 19, 20, "apu_noc_bcrm", true},
{0, 20, 21, "apu_noc_config_0", true},
{0, 21, 22, "vpu_core0_config-0", true},
{0, 22, 23, "vpu_core0_config-1", true},
{0, 23, 24, "vpu_core1_config-0", true},
{0, 24, 25, "vpu_core1_config-1", true},
{0, 25, 26, "apu_iommu0_r0", true},
{0, 26, 27, "apu_iommu0_r1", true},
{0, 27, 28, "apu_iommu0_r2", true},
{0, 28, 29, "apu_iommu0_r3", true},
{0, 29, 30, "apu_iommu0_r4", true},
{0, 30, 31, "vp6_core0_debug_apb", true},
{0, 31, 32, "vp6_core1_debug_apb", true},
DAPC_SLAVE_END
};
static struct dapc_slave dapc_slv_mt6877[] = {
{0, 0, 0, "apusys_ao-0", true},
{0, 1, 1, "apusys_ao-1", true},
{0, 2, 2, "apusys_ao-2", true},
{0, 3, 3, "apusys_ao-3", true},
{0, 4, 4, "apusys_ao-4", true},
{0, 5, 5, "apusys_ao-5", true},
{0, 6, 6, "apusys_ao-6", true},
{0, 7, 7, "apusys_ao-8", true},
{0, 8, 8, "apusys_ao-9", true},
{0, 9, 9, "md32_apb_s-0", true},
{0, 10, 10, "md32_apb_s-1", true},
{0, 0, 11, "padding", false},
{0, 0, 12, "padding", false},
{0, 0, 13, "padding", false},
{0, 0, 14, "padding", false},
{0, 0, 15, "padding", false},
{0, 0, 16, "padding", false},
{0, 0, 17, "padding", false},
{0, 11, 18, "noc_axi", true},
{0, 12, 19, "apu_con2_config", true},
{0, 13, 20, "apu_con1_config", true},
{0, 14, 21, "apu_sctrl_reviser", true},
{0, 15, 22, "apu_sema_stimer", true},
{0, 16, 23, "apu_emi_config", true},
{0, 17, 24, "apu_edma0", true},
{0, 0, 25, "padding", false},
{0, 19, 26, "apu_dapc", true},
{0, 20, 27, "infra_bcrm", true},
{0, 21, 28, "infra_ao_bcrm", true},
{0, 22, 29, "noc_dapc", true},
{0, 23, 30, "apu_noc_bcrm", true},
{0, 24, 31, "apu_noc_config_0", true},
{0, 25, 32, "vpu_core0_config-0", true},
{0, 26, 33, "vpu_core0_config-1", true},
{0, 27, 34, "vpu_core1_config-0", true},
{0, 28, 35, "vpu_core1_config-1", true},
{0, 29, 36, "mdla0_apb-0", true},
{0, 30, 37, "mdla0_apb-1", true},
{0, 31, 38, "mdla0_apb-2", true},
{0, 32, 39, "mdla0_apb-3", true},
{0, 33, 40, "apu_iommu0_r0", true},
{0, 34, 41, "apu_iommu0_r1", true},
{0, 35, 42, "apu_iommu0_r2", true},
{0, 36, 43, "apu_iommu0_r3", true},
{0, 37, 44, "apu_iommu0_r4", true},
{0, 38, 45, "apu_n0_ssc_config", true},
{0, 39, 46, "apu_ao_dbgapb-0", true},
{0, 40, 47, "apu_ao_dbgapb-1", true},
{0, 41, 48, "apu_ao_dbgapb-2", true},
{0, 42, 49, "apu_ao_dbgapb-3", true},
{0, 43, 50, "apu_ao_dbgapb-4", true},
{0, 44, 51, "apu_ao_dbgapb-5", true},
{0, 45, 52, "vpu_core0_debug_apb", true},
{0, 46, 53, "vpu_core1_debug_apb", true},
{0, 47, 54, "apb_infra_dbg_ctl", true},
DAPC_SLAVE_END
};
static uint32_t vio_mask_v1(uint32_t idx)
{
return (0x4 * idx);
}
static uint32_t vio_sta_v1(uint32_t idx)
{
return 0x400 + (0x4 * idx);
}
/* read excetpion info to "excp" */
static int excp_info_v1(struct dapc_driver *d, struct dapc_exception *ex)
{
struct dapc_config *cfg;
uint32_t dbg0;
if (!ex || !d)
return -EINVAL;
cfg = d->cfg;
dbg0 = dapc_reg_r(d, cfg->vio_dbg0);
ex->trans_id = dapc_reg_r(d, cfg->vio_dbg1);
ex->addr = dapc_reg_r(d, cfg->vio_dbg2);
ex->domain_id = __dbg(dbg0, cfg, dmnid);
ex->write_vio = __dbg(dbg0, cfg, w_vio);
ex->read_vio = __dbg(dbg0, cfg, r_vio);
ex->addr_high = __dbg(dbg0, cfg, addr);
return 0;
}
struct dapc_config dapc_cfg_mt6885 = {
.irq_enable = 1,
.slv = dapc_slv_mt6885,
.slv_cnt = 60,
.vio_mask = vio_mask_v1,
.vio_sta = vio_sta_v1,
.excp_info = excp_info_v1,
.apc_con = 0xf00,
.apc_con_vio = 0x80000100, /* APC_VIO | VIO_AUTO_CLR_EN */
.vio_shift_sta = 0xf10,
.vio_shift_sel = 0xf14,
.vio_shift_con = 0xf20,
.vio_shift_con_mask = 0x3, /* SHFT_EN | SHFT_DONE */
.vio_dbg0 = 0x900,
.vio_dbg1 = 0x904,
.vio_dbg2 = 0x908,
.slv_per_dapc = 32,
.vio_shift_max_bit = 11,
.vio_dbg_dmnid = 0x3f,
.vio_dbg_dmnid_shift = 0,
.vio_dbg_w_vio = 0x40,
.vio_dbg_w_vio_shift = 6,
.vio_dbg_r_vio = 0x80,
.vio_dbg_r_vio_shift = 7,
.vio_dbg_addr = 0xf00,
.vio_dbg_addr_shift = 8,
.ut_base = 0x19021000, /* reviser sysctrl */
};
struct dapc_config dapc_cfg_mt6873 = {
.irq_enable = 1,
.slv = dapc_slv_mt6873,
.slv_cnt = 44,
.vio_mask = vio_mask_v1,
.vio_sta = vio_sta_v1,
.excp_info = excp_info_v1,
.apc_con = 0xf00,
.apc_con_vio = 0x80000100, /* APC_VIO | VIO_AUTO_CLR_EN */
.vio_shift_sta = 0xf10,
.vio_shift_sel = 0xf14,
.vio_shift_con = 0xf20,
.vio_shift_con_mask = 0x3, /* SHFT_EN | SHFT_DONE */
.vio_dbg0 = 0x900,
.vio_dbg1 = 0x904,
.vio_dbg2 = 0x908,
.slv_per_dapc = 32,
.vio_shift_max_bit = 9,
.vio_dbg_dmnid = 0x3f,
.vio_dbg_dmnid_shift = 0,
.vio_dbg_w_vio = 0x40,
.vio_dbg_w_vio_shift = 6,
.vio_dbg_r_vio = 0x80,
.vio_dbg_r_vio_shift = 7,
.vio_dbg_addr = 0xf00,
.vio_dbg_addr_shift = 8,
.ut_base = 0x19021000, /* reviser sysctrl */
};
struct dapc_config dapc_cfg_mt6853 = {
.irq_enable = 1,
.slv = dapc_slv_mt6853,
.slv_cnt = 33,
.vio_mask = vio_mask_v1,
.vio_sta = vio_sta_v1,
.excp_info = excp_info_v1,
.apc_con = 0xf00,
.apc_con_vio = 0x80000100, /* APC_VIO | VIO_AUTO_CLR_EN */
.vio_shift_sta = 0xf20,
.vio_shift_sel = 0xf30,
.vio_shift_con = 0xf10,
.vio_shift_con_mask = 0x3, /* SHFT_EN | SHFT_DONE */
.vio_dbg0 = 0x900,
.vio_dbg1 = 0x904,
.vio_dbg2 = 0x908,
.slv_per_dapc = 32,
.vio_shift_max_bit = 9,
.vio_dbg_dmnid = 0x3f,
.vio_dbg_dmnid_shift = 0,
.vio_dbg_w_vio = 0x40,
.vio_dbg_w_vio_shift = 6,
.vio_dbg_r_vio = 0x80,
.vio_dbg_r_vio_shift = 7,
.vio_dbg_addr = 0xf00,
.vio_dbg_addr_shift = 8,
.ut_base = 0x19021000, /* reviser sysctrl */
};
struct dapc_config dapc_cfg_mt6877 = {
.irq_enable = 1,
.slv = dapc_slv_mt6877,
.slv_cnt = 47,
.vio_mask = vio_mask_v1,
.vio_sta = vio_sta_v1,
.excp_info = excp_info_v1,
.apc_con = 0xf00,
.apc_con_vio = 0x80000100, /* APC_VIO | VIO_AUTO_CLR_EN */
.vio_shift_sta = 0xf20,
.vio_shift_sel = 0xf30,
.vio_shift_con = 0xf10,
.vio_shift_con_mask = 0x3, /* SHFT_EN | SHFT_DONE */
.vio_dbg0 = 0x900,
.vio_dbg1 = 0x904,
.vio_dbg2 = 0x908,
.slv_per_dapc = 32,
.vio_shift_max_bit = 9,
.vio_dbg_dmnid = 0x3f,
.vio_dbg_dmnid_shift = 0,
.vio_dbg_w_vio = 0x40,
.vio_dbg_w_vio_shift = 6,
.vio_dbg_r_vio = 0x80,
.vio_dbg_r_vio_shift = 7,
.vio_dbg_addr = 0xf00,
.vio_dbg_addr_shift = 8,
.ut_base = 0x19021000, /* reviser sysctrl */
};
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APUSYS_DAPC_CFG_H__
#define __APUSYS_DAPC_CFG_H__
#include <linux/types.h>
struct dapc_driver;
struct dapc_slave {
int sys_idx;
int ctrl_idx;
int vio_idx;
char *name;
bool vio_irq_en;
};
struct dapc_exception {
/* vio_dbg0 */
uint32_t read_vio;
uint32_t write_vio;
uint32_t addr_high;
uint32_t domain_id;
/* vio_dbg1 */
uint32_t trans_id;
/* vio_dbg2 */
uint32_t addr;
};
#define dapc_reg_base(d) ((unsigned long)d->reg)
#define dapc_reg_w(d, r, val) \
iowrite32(val, (void *) (dapc_reg_base(d) + (r)))
#define dapc_reg_r(d, r) \
ioread32((void *) (dapc_reg_base(d) + (r)))
#define dapc_reg_clr(d, r, mask) \
dapc_reg_w(d, r, dapc_reg_r(d, r) & ~(mask))
#define dapc_reg_set(d, r, mask) \
dapc_reg_w(d, r, dapc_reg_r(d, r) | (mask))
#define DAPC_SLAVE_END {-1, -1, -1, NULL, false}
struct dapc_config {
int irq_enable; /* enable interrupt */
struct dapc_slave *slv;
int slv_cnt;
uint32_t (*vio_mask)(uint32_t idx);
uint32_t (*vio_sta)(uint32_t idx);
int (*excp_info)(struct dapc_driver *d, struct dapc_exception *ex);
uint32_t apc_con;
uint32_t apc_con_vio;
uint32_t vio_shift_sta;
uint32_t vio_shift_sel;
uint32_t vio_shift_con;
uint32_t vio_shift_con_mask; /* shft_en | shft_done */
uint32_t vio_dbg0;
uint32_t vio_dbg1;
uint32_t vio_dbg2;
uint32_t slv_per_dapc;
uint32_t vio_shift_max_bit;
uint32_t vio_dbg_dmnid;
uint32_t vio_dbg_dmnid_shift;
uint32_t vio_dbg_w_vio;
uint32_t vio_dbg_w_vio_shift;
uint32_t vio_dbg_r_vio;
uint32_t vio_dbg_r_vio_shift;
uint32_t vio_dbg_addr;
uint32_t vio_dbg_addr_shift;
uint32_t ut_base;
};
extern struct dapc_config dapc_cfg_mt6885;
extern struct dapc_config dapc_cfg_mt6873;
extern struct dapc_config dapc_cfg_mt6853;
extern struct dapc_config dapc_cfg_mt6893;
extern struct dapc_config dapc_cfg_mt6877;
#define for_each_dapc_slv(cfg, i) \
for (i = 0; i < cfg->slv_cnt && cfg->slv[i].sys_idx >= 0; i++)
#endif
@@ -0,0 +1,24 @@
#
# Copyright (C) 2019 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.
#
PDIR = $(MTK_PLATFORM)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/apusys/include
ccflags-y += -I$(srctree)/drivers/misc/mediatek/apusys/power/2.0
ccflags-y += -I$(srctree)/drivers/misc/mediatek/apusys/power/2.0/$(PDIR)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/apusys/midware/1.1/
obj-y += edma.o
edma-objs += edma_driver.o edma_dbgfs.o edma_plat_device.o
edma-objs += edma_cmd_hnd.o edma_v20.o edma_v30.o
@@ -0,0 +1,176 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __EDMA3_REG_H__
#define __EDMA3_REG_H__
#include <linux/kernel.h>
#include <linux/io.h>
#define EDMA30_REG_SHOW_RANGE 0x200
/* APU_EDMA2_CFG_0 */
#define EXT_IOMMU_READ BIT(29)
#define EXT_IOMMU_WRITE BIT(31)
#define EXT_CMDQ_INT_ENABLE BIT(28)
#define APU_EDMA3_VERSION 0x000
#define APU_EDMA3_CTRL 0x004
#define APU_EDMA3_STATE 0x008
#define APU_EDMA3_ERR_STATUS 0x00C
#define APU_EDMA3_ERR_MASK 0x010
#define APU_EDMA3_ERR_DES_ID 0x014
#define APU_EDMA3_ERR_CH_INDEX 0x018
#define APU_EDMA3_DONE_STATUS 0x01C
#define APU_EDMA3_DONE_MASK 0x020
#define APU_EDMA3_HW_SYNC_A 0x024
#define APU_EDMA3_HW_SYNC_B 0x028
#define APU_EDMA3_PMU_CTRL 0x02C
#define APU_EDMA3_PMU_STATE 0x030
#define APU_EDMA3_UFBC_CTRL 0x080
#define APU_EDMA3_UFBC_GROUP_CTRL 0x084
#define APU_EDMA3_UFBC_DBG_STATE 0x088
#define APU_EDMA3_UFBC_MON_GMC 0x08C
#define APU_EDMA3_UFBC_CHECK_SUM 0x090
#define APU_EDMA3_UFBDC_CTRL 0x0C0
#define APU_EDMA3_UFBDC_GROUP_CTRL 0x0C4
#define APU_EDMA3_UFBDC_DBG_STATE 0x0C8
#define APU_EDMA3_UFBDC_MON_GMC 0x0CC
#define APU_EDMA3_UFBDC_VERSION_A 0x0D0
#define APU_EDMA3_UFBDC_VERSION_B 0x0D4
#define APU_EDMA3_UFBDC_VERSION_C 0x0D8
#define APU_EDMA3_UFBDC_VERSION_D 0x0DC
#define APU_EDMA3_CMDQ_CH0_LO_A 0x800
#define APU_EDMA3_CMDQ_CH0_LO_B 0x804
#define APU_EDMA3_CMDQ_CH0_LO_C 0x808
#define APU_EDMA3_CMDQ_CH0_LO_D 0x80C
#define APU_EDMA3_CMDQ_CH0_LO_E 0x810
#define APU_EDMA3_CMDQ_CH0_LO_F 0x814
#define APU_EDMA3_CMDQ_CH0_HI_A 0x880
#define APU_EDMA3_CMDQ_CH0_HI_B 0x884
#define APU_EDMA3_CMDQ_CH0_HI_C 0x888
#define APU_EDMA3_CMDQ_CH0_HI_D 0x88C
#define APU_EDMA3_CMDQ_CH0_HI_E 0x890
#define APU_EDMA3_CMDQ_CH0_HI_F 0x894
#define APU_EDMA3_CMDQ_CH1_LO_A 0x900
#define APU_EDMA3_CMDQ_CH1_LO_B 0x904
#define APU_EDMA3_CMDQ_CH1_LO_C 0x908
#define APU_EDMA3_CMDQ_CH1_LO_D 0x90C
#define APU_EDMA3_CMDQ_CH1_LO_E 0x910
#define APU_EDMA3_CMDQ_CH1_LO_F 0x914
#define APU_EDMA3_CMDQ_CH1_HI_A 0x980
#define APU_EDMA3_CMDQ_CH1_HI_B 0x984
#define APU_EDMA3_CMDQ_CH1_HI_C 0x988
#define APU_EDMA3_CMDQ_CH1_HI_D 0x98C
#define APU_EDMA3_CMDQ_CH1_HI_E 0x990
#define APU_EDMA3_CMDQ_CH1_HI_F 0x994
#define APU_EDMA3_CMDQ_CH2_LO_A 0xA00
#define APU_EDMA3_CMDQ_CH2_LO_B 0xA04
#define APU_EDMA3_CMDQ_CH2_LO_C 0xA08
#define APU_EDMA3_CMDQ_CH2_LO_D 0xA0C
#define APU_EDMA3_CMDQ_CH2_LO_E 0xA10
#define APU_EDMA3_CMDQ_CH2_LO_F 0xA14
#define APU_EDMA3_CMDQ_CH2_HI_A 0xA80
#define APU_EDMA3_CMDQ_CH2_HI_B 0xA84
#define APU_EDMA3_CMDQ_CH2_HI_C 0xA88
#define APU_EDMA3_CMDQ_CH2_HI_D 0xA8C
#define APU_EDMA3_CMDQ_CH2_HI_E 0xA90
#define APU_EDMA3_CMDQ_CH2_HI_F 0xA94
#define APU_EDMA3_CMDQ_CH3_LO_A 0xB00
#define APU_EDMA3_CMDQ_CH3_LO_B 0xB04
#define APU_EDMA3_CMDQ_CH3_LO_C 0xB08
#define APU_EDMA3_CMDQ_CH3_LO_D 0xB0C
#define APU_EDMA3_CMDQ_CH3_LO_E 0xB10
#define APU_EDMA3_CMDQ_CH3_LO_F 0xB14
#define APU_EDMA3_CMDQ_CH3_HI_A 0xB80
#define APU_EDMA3_CMDQ_CH3_HI_B 0xB84
#define APU_EDMA3_CMDQ_CH3_HI_C 0xB88
#define APU_EDMA3_CMDQ_CH3_HI_D 0xB8C
#define APU_EDMA3_CMDQ_CH3_HI_E 0xB90
#define APU_EDMA3_CMDQ_CH3_HI_F 0xB94
#define APU_EDMA3_CMDQ_CH4_LO_A 0xC00
#define APU_EDMA3_CMDQ_CH4_LO_B 0xC04
#define APU_EDMA3_CMDQ_CH4_LO_C 0xC08
#define APU_EDMA3_CMDQ_CH4_LO_D 0xC0C
#define APU_EDMA3_CMDQ_CH4_LO_E 0xC10
#define APU_EDMA3_CMDQ_CH4_LO_F 0xC14
#define APU_EDMA3_CMDQ_CH4_HI_A 0xC80
#define APU_EDMA3_CMDQ_CH4_HI_B 0xC84
#define APU_EDMA3_CMDQ_CH4_HI_C 0xC88
#define APU_EDMA3_CMDQ_CH4_HI_D 0xC8C
#define APU_EDMA3_CMDQ_CH4_HI_E 0xC90
#define APU_EDMA3_CMDQ_CH4_HI_F 0xC94
#define APU_EDMA3_CMDQ_CH5_LO_A 0xD00
#define APU_EDMA3_CMDQ_CH5_LO_B 0xD04
#define APU_EDMA3_CMDQ_CH5_LO_C 0xD08
#define APU_EDMA3_CMDQ_CH5_LO_D 0xD0C
#define APU_EDMA3_CMDQ_CH5_LO_E 0xD10
#define APU_EDMA3_CMDQ_CH5_LO_F 0xD14
#define APU_EDMA3_CMDQ_CH5_HI_A 0xD80
#define APU_EDMA3_CMDQ_CH5_HI_B 0xD84
#define APU_EDMA3_CMDQ_CH5_HI_C 0xD88
#define APU_EDMA3_CMDQ_CH5_HI_D 0xD8C
#define APU_EDMA3_CMDQ_CH5_HI_E 0xD90
#define APU_EDMA3_CMDQ_CH5_HI_F 0xD94
#define APU_EDMA3_CMDQ_CH6_LO_A 0xE00
#define APU_EDMA3_CMDQ_CH6_LO_B 0xE04
#define APU_EDMA3_CMDQ_CH6_LO_C 0xE08
#define APU_EDMA3_CMDQ_CH6_LO_D 0xE0C
#define APU_EDMA3_CMDQ_CH6_LO_E 0xE10
#define APU_EDMA3_CMDQ_CH6_LO_F 0xE14
#define APU_EDMA3_CMDQ_CH6_HI_A 0xE80
#define APU_EDMA3_CMDQ_CH6_HI_B 0xE84
#define APU_EDMA3_CMDQ_CH6_HI_C 0xE88
#define APU_EDMA3_CMDQ_CH6_HI_D 0xE8C
#define APU_EDMA3_CMDQ_CH6_HI_E 0xE90
#define APU_EDMA3_CMDQ_CH6_HI_F 0xE94
#define APU_EDMA3_CMDQ_CH7_LO_A 0xF00
#define APU_EDMA3_CMDQ_CH7_LO_B 0xF04
#define APU_EDMA3_CMDQ_CH7_LO_C 0xF08
#define APU_EDMA3_CMDQ_CH7_LO_D 0xF0C
#define APU_EDMA3_CMDQ_CH7_LO_E 0xF10
#define APU_EDMA3_CMDQ_CH7_LO_F 0xF14
#define APU_EDMA3_CMDQ_CH7_HI_A 0xF80
#define APU_EDMA3_CMDQ_CH7_HI_B 0xF84
#define APU_EDMA3_CMDQ_CH7_HI_C 0xF88
#define APU_EDMA3_CMDQ_CH7_HI_D 0xF8C
#define APU_EDMA3_CMDQ_CH7_HI_E 0xF90
#define APU_EDMA3_CMDQ_CH7_HI_F 0xF94
static inline unsigned int edma_read_reg32(void __iomem *edma_base,
unsigned int offset)
{
return readl(edma_base + offset);
}
static inline void edma_write_reg32(void __iomem *edma_base,
unsigned int offset,
unsigned int val)
{
writel(val, edma_base + offset);
}
static inline void edma_set_reg32(void __iomem *edma_base, unsigned int offset,
unsigned int bits)
{
edma_write_reg32(edma_base, offset,
(edma_read_reg32(edma_base, offset) | bits));
}
static inline void edma_clear_reg32(void __iomem *edma_base,
unsigned int offset,
unsigned int bits)
{
edma_write_reg32(edma_base, offset,
(edma_read_reg32(edma_base, offset) & ~bits));
}
#endif
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
* Author: JB Tsai <jb.tsai@mediatek.com>
*/
#ifndef __EDMA_API_H__
#define __EDMA_API_H__
#include "edma_ioctl.h"
int edma_set_external_with_normal(u8 *buf, u32 size,
struct edma_normal *edma_normal);
int edma_set_external_with_fill(u8 *buf, u32 size,
struct edma_fill *edma_fill);
int edma_set_external_with_numerical(u8 *buf, u32 size,
struct edma_numerical *edma_numerical);
int edma_set_external_with_format(u8 *buf, u32 size,
struct edma_format *edma_format);
int edma_set_external_with_compress(u8 *buf, u32 size,
struct edma_compress *edma_compress);
int edma_set_external_with_decompress(u8 *buf, u32 size,
struct edma_decompress *edma_decompress);
int edma_set_external_with_raw(u8 *buf, u32 size,
struct edma_raw *edma_raw);
#endif /* __EDMA_API_H__ */
@@ -0,0 +1,262 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/delay.h>
#include <linux/jiffies.h>
#include "edma_driver.h"
#include "edma_cmd_hnd.h"
#include "apusys_power.h"
#include "edma_dbgfs.h"
#include "edma_plat_internal.h"
#define NO_INTERRUPT 0
#define EDMA_POWEROFF_TIME_DEFAULT 2000
static inline void lock_command(struct edma_sub *edma_sub)
{
mutex_lock(&edma_sub->cmd_mutex);
edma_sub->is_cmd_done = false;
}
static inline int wait_command(struct edma_sub *edma_sub, u32 timeout)
{
return (wait_event_interruptible_timeout(edma_sub->cmd_wait,
edma_sub->is_cmd_done,
msecs_to_jiffies
(timeout)) > 0)
? 0 : -ETIMEDOUT;
}
static inline void unlock_command(struct edma_sub *edma_sub)
{
mutex_unlock(&edma_sub->cmd_mutex);
}
/**
* @brief excute request by each edma_sub
* parameters:
* edma_sub: include each edma base address
*/
int edma_ext_by_sub(struct edma_sub *edma_sub, struct edma_request *req)
{
int ret = 0;
unsigned long long get_port_time = 0;
struct edma_plat_drv *drv = (struct edma_plat_drv *)edma_sub->plat_drv;
ret = edma_power_on(edma_sub);
if (ret != 0)
return ret;
get_port_time = sched_clock();
lock_command(edma_sub);
if (drv)
ret = drv->exe_sub(edma_sub, req);
ret = wait_command(edma_sub, CMD_WAIT_TIME_MS);
if (ret) {
pr_notice
("%s:timeout\n", __func__);
if (drv)
drv->prt_error(edma_sub, req);
}
get_port_time = sched_clock() - get_port_time; //ns
edma_sub->ip_time = get_port_time/1000;
unlock_command(edma_sub);
edma_power_off(edma_sub, 0);
return ret;
}
bool edma_is_all_power_off(struct edma_device *edma_device)
{
int i;
for (i = 0; i < edma_device->edma_sub_num; i++)
if (edma_device->edma_sub[i]->power_state == EDMA_POWER_ON)
return false;
return true;
}
int edma_power_on(struct edma_sub *edma_sub)
{
struct edma_device *edma_device;
int ret = 0;
edma_device = edma_sub->edma_device;
mutex_lock(&edma_device->power_mutex);
if (edma_is_all_power_off(edma_device)) {
if (timer_pending(&edma_device->power_timer)) {
del_timer(&edma_device->power_timer);
LOG_DBG("%s deltimer no pwr on, state = %d\n",
__func__, edma_device->power_state);
} else if (edma_device->power_state ==
EDMA_POWER_ON) {
LOG_ERR("%s power on twice\n", __func__);
} else {
ret = apu_device_power_on(EDMA);
if (!ret) {
LOG_DBG("%s power on success\n", __func__);
edma_device->power_state = EDMA_POWER_ON;
} else {
LOG_ERR("%s power on fail\n",
__func__);
mutex_unlock(&edma_device->power_mutex);
return ret;
}
}
}
edma_sub->power_state = EDMA_POWER_ON;
mutex_unlock(&edma_device->power_mutex);
return ret;
}
void edma_start_power_off(struct work_struct *work)
{
int ret = 0;
struct edma_device *edmaDev = NULL;
edmaDev =
container_of(work, struct edma_device, power_off_work);
LOG_DBG("%s: contain power_state = %d!!\n", __func__,
edmaDev->power_state);
if (edmaDev->power_state == EDMA_POWER_OFF)
LOG_ERR("%s pwr off twice\n",
__func__);
mutex_lock(&edmaDev->power_mutex);
ret = apu_device_power_off(EDMA);
if (ret != 0) {
LOG_ERR("%s power off fail\n", __func__);
} else {
pr_notice("%s: power off done!!\n", __func__);
edmaDev->power_state = EDMA_POWER_OFF;
}
mutex_unlock(&edmaDev->power_mutex);
}
void edma_power_time_up(struct timer_list *tlist)
{
//struct edma_device *edma_device = (struct edma_device *)data;
struct edma_device *edma_device =
container_of(tlist, struct edma_device, power_timer);
pr_notice("%s: !!\n", __func__);
//use kwork job to prevent power off at irq
schedule_work(&edma_device->power_off_work);
}
int edma_power_off(struct edma_sub *edma_sub, u8 force)
{
struct edma_device *edma_device =
edma_sub->edma_device;
int ret = 0;
if (edma_device->dbg_cfg
& EDMA_DBG_DISABLE_PWR_OFF) {
pr_notice("%s:no power off!!\n", __func__);
return 0;
}
mutex_lock(&edma_device->power_mutex);
edma_sub->power_state = EDMA_POWER_OFF;
if (edma_is_all_power_off(edma_device)) {
if (timer_pending(&edma_device->power_timer))
del_timer(&edma_device->power_timer);
if (force == 1) {
if (edma_device->power_state != EDMA_POWER_OFF) {
ret = apu_device_power_suspend(EDMA, 1);
pr_notice("%s: force power off!!\n", __func__);
if (!ret) {
LOG_INF("%s power off success\n",
__func__);
edma_device->power_state =
EDMA_POWER_OFF;
} else {
LOG_ERR("%s power off fail\n",
__func__);
}
} else
LOG_INF("%s force power off skip\n",
__func__);
} else {
edma_device->power_timer.expires = jiffies +
msecs_to_jiffies(EDMA_POWEROFF_TIME_DEFAULT);
add_timer(&edma_device->power_timer);
}
}
mutex_unlock(&edma_device->power_mutex);
return ret;
}
void edma_setup_ext_mode_request(struct edma_request *req,
struct edma_ext *edma_ext,
unsigned int type)
{
req->handle = (u64) req;
req->cmd = type;
req->ext_reg_addr = edma_ext->reg_addr;
req->ext_count = edma_ext->count;
req->fill_value = edma_ext->fill_value;
req->desp_iommu_en = edma_ext->desp_iommu_en;
req->cmd_result = 0;
}
int edma_execute(struct edma_sub *edma_sub, struct edma_ext *edma_ext)
{
int ret = 0;
struct edma_request req = {0};
#ifdef DEBUG
uint32_t t1, t2;
uint32_t exe_time;
t1 = ktime_get_ns();
#endif
edma_setup_ext_mode_request(&req, edma_ext, EDMA_PROC_EXT_MODE);
ret = edma_ext_by_sub(edma_sub, &req);
#ifdef DEBUG
t2 = ktime_get_ns();
exe_time = (t2 - t1)/1000;
//pr_notice("%s:ip time = %d\n", __func__, edma_sub->ip_time);
LOG_DBG("%s:func done[%d], exe_time = %d, ip time = %d\n",
__func__, ret, exe_time, edma_sub->ip_time);
#endif
return ret;
}
@@ -0,0 +1,60 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __EDMA_CMD_HND_H__
#define __EDMA_CMD_HND_H__
#include <linux/interrupt.h>
#include "edma_dbgfs.h"
#include "edma_driver.h"
#define EDMA_TAG "[edma]"
#define EDMA_DEBUG
#ifdef EDMA_DEBUG
#define LOG_DBG(x, args...) \
{ \
if (g_edma_log_lv >= EDMA_LOG_DEBUG) \
pr_info(EDMA_TAG "[debug] %s/%d "\
x, __func__, __LINE__, ##args); \
}
#else
#define LOG_DBG(format, args...)
#endif
#define LOG_INF(format, args...) pr_info(EDMA_TAG " " format, ##args)
#define LOG_WRN(format, args...) pr_info(EDMA_TAG "[warn] " format, ##args)
#define LOG_ERR(format, args...) pr_info(EDMA_TAG "[error] " format, ##args)
irqreturn_t edma_isr_handler(int irq, void *edma_sub_info);
void edma_enable_sequence(struct edma_sub *edma_sub);
int edma_trigger_internal_mode(void __iomem *base_addr,
struct edma_request *req);
int edma_normal_mode(struct edma_sub *edma_sub, struct edma_request *req);
int edma_fill_mode(struct edma_sub *edma_sub, struct edma_request *req);
int edma_numerical_mode(struct edma_sub *edma_sub, struct edma_request *req);
int edma_format_mode(struct edma_sub *edma_sub, struct edma_request *req);
int edma_compress_mode(struct edma_sub *edma_sub, struct edma_request *req);
int edma_decompress_mode(struct edma_sub *edma_sub, struct edma_request *req);
int edma_raw_mode(struct edma_sub *edma_sub, struct edma_request *req);
int edma_ext_mode(struct edma_sub *edma_sub, struct edma_request *req);
int edma_power_on(struct edma_sub *edma_sub);
int edma_power_off(struct edma_sub *edma_sub, u8 force);
#ifdef DEBUG
int edma_sync_normal_mode(struct edma_device *edma_device,
struct edma_request *req);
int edma_sync_ext_mode(struct edma_device *edma_device,
struct edma_request *req);
#endif
int edma_execute(struct edma_sub *edma_sub, struct edma_ext *edma_ext);
void edma_power_time_up(struct timer_list *power_timer);
void edma_start_power_off(struct work_struct *work);
#endif /* __EDMA_CMD_HND_H__ */
@@ -0,0 +1,192 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/cdev.h>
#include "edma_driver.h"
#include "edma_dbgfs.h"
#include "edma_reg.h"
u8 g_edma_log_lv = EDMA_LOG_WARN;
static ssize_t edma_register_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int count = 0, i, desp;
struct edma_device *edma_device = dev_get_drvdata(dev);
unsigned int core = edma_device->dbgfs_reg_core;
struct edma_sub *edma_sub = edma_device->edma_sub[core];
if (core >= edma_device->edma_sub_num) {
count += scnprintf(buf + count, 2*PAGE_SIZE - count,
"not support core: %d\n", core);
return count;
}
count += scnprintf(buf + count, 2*PAGE_SIZE - count,
"core: %d\n", core);
for (i = 0; i < (EDMA_REG_SHOW_RANGE >> 2); i++) {
count += scnprintf(buf + count, 2*PAGE_SIZE - count,
"0x%03x: 0x%08x\n", i * 4,
edma_read_reg32(edma_sub->base_addr, i * 4));
}
for (desp = 0; desp < 4; desp++) {
u32 base;
count += scnprintf(buf + count, 2*PAGE_SIZE - count,
"descriptor %d\n", desp);
base = APU_EDMA2_DESP0_0 + desp * APU_EDMA2_DESP_OFFSET;
for (i = 0; i < (APU_EDMA2_EX_DESP_OFFSET >> 2); i++) {
count += scnprintf(buf + count, 2*PAGE_SIZE - count,
"0x%03x: 0x%08x\n", base + i * 4,
edma_read_reg32(edma_sub->base_addr,
base + i * 4));
}
}
return count;
}
static ssize_t edma_register_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct edma_device *edma_device = dev_get_drvdata(dev);
unsigned int core = 0;
int ret = 0;
ret = kstrtouint(buf, 10, &core);
if (ret || core >= EDMA_SUB_NUM) {
dev_notice(dev, "input parameter is worng\n");
return count;
}
edma_device->dbgfs_reg_core = core;
return count;
}
static ssize_t edma_power_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int count = 0, i;
struct edma_device *edma_device = dev_get_drvdata(dev);
struct edma_sub *edma_sub;
for (i = 0; i < edma_device->edma_sub_num; i++) {
edma_sub = edma_device->edma_sub[i];
count += scnprintf(buf + count, PAGE_SIZE - count,
"edma%d power:\n", i);
if (edma_sub->power_state == EDMA_POWER_ON)
count += scnprintf(buf + count, PAGE_SIZE - count,
"ON\n");
else
count += scnprintf(buf + count, PAGE_SIZE - count,
"OFF\n");
}
return count;
}
static ssize_t edma_power_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input = 0;
int ret = 0;
struct edma_device *edma_device = dev_get_drvdata(dev);
ret = kstrtouint(buf, 10, &input);
dev_notice(dev, "input parameter is %d\n", input);
if (input == 666)
edma_device->dbg_cfg |= EDMA_DBG_DISABLE_PWR_OFF;
else
edma_device->dbg_cfg &= ~EDMA_DBG_DISABLE_PWR_OFF;
dev_notice(dev, "edma_device->dbg_cfg = 0x%x\n",
edma_device->dbg_cfg);
return count;
}
static ssize_t edma_debuglv_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int count = 0;
count += scnprintf(buf + count, PAGE_SIZE - count,
"g_edma_log_lv =%d:\n", g_edma_log_lv);
return count;
}
static ssize_t edma_debuglv_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input = 0, portNum;
int ret, i;
struct edma_device *edma_device = dev_get_drvdata(dev);
struct edma_sub *edma_sub;
ret = kstrtouint(buf, 10, &input);
dev_notice(dev, "set debug lv = %d\n", input);
g_edma_log_lv = input;
if (input >= 10 && input < 18) {
portNum = input - 10;
for (i = 0; i < edma_device->edma_sub_num; i++) {
edma_sub = edma_device->edma_sub[i];
edma_sub->dbg_portID = input - 10;
}
dev_notice(dev, "set portNum = %d\n", portNum);
}
return count;
}
DEVICE_ATTR_RW(edma_register);
DEVICE_ATTR_RW(edma_power);
DEVICE_ATTR_RW(edma_debuglv);
static struct attribute *edma_sysfs_entries[] = {
&dev_attr_edma_register.attr,
&dev_attr_edma_power.attr,
&dev_attr_edma_debuglv.attr,
NULL,
};
static const struct attribute_group edma_attr_group = {
.attrs = edma_sysfs_entries,
};
int edma_create_sysfs(struct device *dev)
{
int ret;
ret = sysfs_create_group(&dev->kobj, &edma_attr_group);
if (ret)
dev_notice(dev, "create sysfs group error, %d\n", ret);
return ret;
}
void edma_remove_sysfs(struct device *dev)
{
sysfs_remove_group(&dev->kobj, &edma_attr_group);
}
@@ -0,0 +1,28 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __EDMA_DBGFS_H__
#define __EDMA_DBGFS_H__
int edma_create_sysfs(struct device *dev);
void edma_remove_sysfs(struct device *dev);
int edma_dbg_check_ststus(int check_status);
enum edma_dbg_cfg {
EDMA_DBG_DISABLE_PWR_OFF = 0x1,
EDMA_DBG_ALL = 0xFFFFFFF,
};
enum {
EDMA_LOG_WARN,
EDMA_LOG_INFO,
EDMA_LOG_DEBUG,
};
extern u8 g_edma_log_lv;
#endif /* __EDMA_DBGFS_H__ */
@@ -0,0 +1,420 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/of_irq.h>
#include <linux/of_platform.h>
#include <linux/interrupt.h>
#include <linux/syscalls.h>
#include <linux/cdev.h>
#include <linux/kthread.h>
#include <linux/timer.h>
#include "edma_dbgfs.h"
#include "edma_driver.h"
#include "edma_cmd_hnd.h"
#include "apusys_power.h"
#include "edma_plat_internal.h"
#define EDMA_DEV_NAME "edma"
static struct class *edma_class;
#define _EDMA_DEV
int edma_initialize(struct edma_device *edma_device)
{
int ret = 0;
int sub_id;
init_waitqueue_head(&edma_device->req_wait);
timer_setup(&edma_device->power_timer,
edma_power_time_up, TIMER_DEFERRABLE);
INIT_WORK(&edma_device->power_off_work,
edma_start_power_off);
edma_device->dbg_cfg = 0;
//real pwr state
edma_device->power_state = EDMA_POWER_OFF;
/* init hw and create task */
for (sub_id = 0; sub_id < edma_device->edma_sub_num; sub_id++) {
struct edma_sub *edma_sub = edma_device->edma_sub[sub_id];
if (!edma_sub)
continue;
edma_sub->edma_device = edma_device;
edma_sub->sub = sub_id;
edma_sub->power_state = EDMA_POWER_OFF;
mutex_init(&edma_sub->cmd_mutex);
init_waitqueue_head(&edma_sub->cmd_wait);
if (snprintf(edma_sub->sub_name, sizeof(edma_sub->sub_name),
"edma%d", edma_sub->sub) < 0)
pr_notice("edma_sub->sub_name cop fail!\n");
}
return ret;
}
#ifdef _EDMA_DEV
static inline void edma_unreg_chardev(struct edma_device *edma_device)
{
cdev_del(&edma_device->edma_chardev);
unregister_chrdev_region(edma_device->edma_devt, 1);
}
static inline int edma_reg_chardev(struct edma_device *edma_device)
{
int ret = 0;
ret = alloc_chrdev_region(&edma_device->edma_devt, 0, 1, EDMA_DEV_NAME);
if ((ret) < 0) {
pr_notice("alloc_chrdev_region failed, %d\n", ret);
return ret;
}
edma_device->edma_chardev.owner = THIS_MODULE;
cdev_init(&edma_device->edma_chardev, NULL);
/* Add to system */
ret = cdev_add(&edma_device->edma_chardev, edma_device->edma_devt, 1);
if ((ret) < 0) {
pr_notice("Attatch file operation failed, %d\n", ret);
goto out;
}
out:
if (ret < 0)
edma_unreg_chardev(edma_device);
return ret;
}
#endif
int edma_send_cmd(int cmd, void *hnd, struct apusys_device *adev)
{
struct edma_sub *edma_sub;
int result = 0;
if (adev == NULL)
return -EINVAL;
edma_sub = (struct edma_sub *)adev->private;
#ifdef DEBUG
LOG_DBG("%s:cmd = %d, name = %s\n", __func__,
cmd, edma_sub->sub_name);
#endif
switch (cmd) {
case APUSYS_CMD_POWERON:
/*pre-power on*/
return edma_power_on(edma_sub);
case APUSYS_CMD_POWERDOWN:
//return edma_power_off(edma_sub, 1);
break;
case APUSYS_CMD_RESUME:
return result;
case APUSYS_CMD_SUSPEND:
return edma_power_off(edma_sub, 1);
case APUSYS_CMD_EXECUTE:{
struct apusys_cmd_hnd *cmd_hnd;
struct edma_ext *edma_ext;
if (hnd == NULL)
break;
cmd_hnd = (struct apusys_cmd_hnd *)hnd;
if (cmd_hnd->kva == 0 ||
cmd_hnd->size != sizeof(struct edma_ext))
break;
edma_ext = (struct edma_ext *)cmd_hnd->kva;
result = edma_execute(edma_sub, edma_ext);
cmd_hnd->ip_time = edma_sub->ip_time;
return result;
}
case APUSYS_CMD_PREEMPT:
return result;
default:
break;
}
return -EINVAL;
}
static int mtk_edma_sub_probe(struct platform_device *pdev)
{
int irq, ret;
struct resource *mem;
struct edma_sub *edma_sub;
struct device *dev = &pdev->dev;
struct edma_plat_drv *drv;
edma_sub = devm_kzalloc(dev, sizeof(*edma_sub), GFP_KERNEL);
if (!edma_sub)
return -ENOMEM;
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
edma_sub->base_addr = devm_ioremap_resource(dev, mem);
if (IS_ERR((const void *)(edma_sub->base_addr))) {
dev_notice(dev, "cannot get ioremap\n");
return -ENOENT;
}
edma_sub->plat_drv = of_device_get_match_data(&pdev->dev);
spin_lock_init(&edma_sub->reg_lock);
edma_sub->dbg_portID = 5;
if (edma_sub->plat_drv == NULL) {
dev_notice(dev, "cannot get plat_drv\n");
return -ENOENT;
}
drv = (struct edma_plat_drv *)edma_sub->plat_drv;
/* interrupt resource */
irq = platform_get_irq(pdev, 0);
if (irq < 0)
return irq;
ret = devm_request_irq(dev, irq, drv->edma_isr,
IRQF_TRIGGER_NONE,
dev_name(dev),
edma_sub);
if (ret < 0) {
dev_notice(dev, "Failed to request irq %d: %d\n", irq, ret);
return ret;
}
edma_sub->dev = &pdev->dev;
platform_set_drvdata(pdev, edma_sub);
dev_set_drvdata(dev, edma_sub);
return 0;
}
static int mtk_edma_sub_remove(struct platform_device *pdev)
{
return 0;
}
static struct platform_driver mtk_edma_sub_driver = {
.probe = mtk_edma_sub_probe,
.remove = mtk_edma_sub_remove,
.driver = {
.name = "mtk,edma-sub",
.pm = NULL,
}
};
static int edma_setup_resource(struct platform_device *pdev,
struct edma_device *edma_device)
{
struct device *dev = &pdev->dev;
struct device_node *sub_node;
struct platform_device *sub_pdev;
int i, ret;
ret = of_property_read_u32(dev->of_node, "sub_nr",
&edma_device->edma_sub_num);
if (ret) {
dev_notice(dev, "parsing sub_nr error: %d\n", ret);
return -EINVAL;
}
if (edma_device->edma_sub_num > EDMA_SUB_NUM)
return -EINVAL;
for (i = 0; i < edma_device->edma_sub_num; i++) {
struct edma_sub *edma_sub = NULL;
sub_node = of_parse_phandle(dev->of_node,
"mediatek,edma-sub", i);
if (!sub_node) {
dev_notice(dev,
"Missing <mediatek,edma-sub> phandle\n");
return -EINVAL;
}
sub_pdev = of_find_device_by_node(sub_node);
if (sub_pdev)
edma_sub = platform_get_drvdata(sub_pdev);
if (!edma_sub) {
dev_notice(dev, "Waiting for edma sub %s\n",
sub_node->full_name);
of_node_put(sub_node);
return -EPROBE_DEFER;
}
of_node_put(sub_node);
/* attach edma_sub */
edma_device->edma_sub[i] = edma_sub;
/* register device to APUSYS */
edma_sub->adev.dev_type = APUSYS_DEVICE_EDMA;
edma_sub->adev.preempt_type = APUSYS_PREEMPT_NONE;
edma_sub->adev.preempt_level = 0;
edma_sub->adev.private = edma_sub;
edma_sub->adev.send_cmd = edma_send_cmd;
edma_sub->adev.idx = i;
ret = apusys_register_device(&edma_sub->adev);
if (ret) {
dev_notice(dev,
"Failed to register apusys (%d)\n", ret);
return -EPROBE_DEFER;
}
}
apu_power_device_register(EDMA, pdev);
return 0;
}
static int edma_probe(struct platform_device *pdev)
{
struct edma_device *edma_device;
struct device *dev = &pdev->dev;
int ret;
edma_device = devm_kzalloc(dev, sizeof(*edma_device), GFP_KERNEL);
if (!edma_device)
return -ENOMEM;
ret = edma_setup_resource(pdev, edma_device);
if (ret)
return ret;
mutex_init(&edma_device->power_mutex);
edma_device->dev = &pdev->dev;
edma_device->dbgfs_reg_core = 0;
#ifdef _EDMA_DEV
if (edma_reg_chardev(edma_device) == 0) {
/* Create class register */
edma_class = class_create(THIS_MODULE, EDMA_DEV_NAME);
if (IS_ERR(edma_class)) {
ret = PTR_ERR(edma_class);
dev_notice(dev, "Unable to create class, err = %d\n",
ret);
goto dev_out;
}
dev = device_create(edma_class, NULL, edma_device->edma_devt,
NULL, EDMA_DEV_NAME);
if (IS_ERR(dev)) {
ret = PTR_ERR(dev);
dev_notice(dev,
"Failed to create device: /dev/%s, err = %d",
EDMA_DEV_NAME, ret);
goto dev_out;
}
platform_set_drvdata(pdev, edma_device);
dev_set_drvdata(dev, edma_device);
edma_create_sysfs(dev);
}
#endif
edma_initialize(edma_device);
pr_notice("edma probe done\n");
return 0;
#ifdef _EDMA_DEV
dev_out:
edma_unreg_chardev(edma_device);
return ret;
#endif
}
static int edma_remove(struct platform_device *pdev)
{
struct edma_device *edma_device = platform_get_drvdata(pdev);
apu_power_device_unregister(EDMA);
#ifdef _EDMA_DEV
edma_unreg_chardev(edma_device);
#endif
device_destroy(edma_class, edma_device->edma_devt);
class_destroy(edma_class);
edma_remove_sysfs(&pdev->dev);
return 0;
}
static const struct of_device_id edma_of_ids[] = {
{.compatible = "mtk,edma",},
{}
};
MODULE_DEVICE_TABLE(of, edma_of_ids);
static struct platform_driver edma_driver = {
.probe = edma_probe,
.remove = edma_remove,
.driver = {
.name = EDMA_DEV_NAME,
.owner = THIS_MODULE,
.of_match_table = edma_of_ids,
}
};
static int __init edma_init(void)
{
int ret = 0;
pr_info("%s in\n", __func__);
if (!apusys_power_check()) {
pr_info("%s: edma is disabled by apusys\n", __func__);
return -ENODEV;
}
mtk_edma_sub_driver.driver.of_match_table = edma_plat_get_device();
ret = platform_driver_register(&mtk_edma_sub_driver);
if (ret != 0) {
pr_notice("Failed to register edma sub driver\n");
return -ENODEV;
}
ret = platform_driver_register(&edma_driver);
if (ret != 0) {
pr_notice("failed to register edma driver");
goto err_unreg_edma_sub;
}
return ret;
err_unreg_edma_sub:
platform_driver_unregister(&mtk_edma_sub_driver);
return ret;
}
static void __exit edma_exit(void)
{
platform_driver_unregister(&edma_driver);
platform_driver_unregister(&mtk_edma_sub_driver);
}
module_init(edma_init);
module_exit(edma_exit);
@@ -0,0 +1,177 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __EDMA_DRIVER_H__
#define __EDMA_DRIVER_H__
#include "apusys_device.h"
#include <linux/cdev.h>
#define DEBUG
#define EDMA_SUB_NUM 2
#define EDMA_SUB_NAME_SIZE 20
#define CMD_WAIT_TIME_MS (3 * 1000)
struct edma_device;
enum edma_sub_state {
EDMA_UNPREPARE,
EDMA_IDLE,
EDMA_ACTIVE,
EDMA_SLEEP,
};
enum edma_power_state {
EDMA_POWER_OFF,
EDMA_POWER_ON,
};
struct edma_sub {
struct device *dev;
struct apusys_device adev;
u32 sub;
struct edma_device *edma_device;
spinlock_t reg_lock;
void __iomem *base_addr;
/* edma irq operation info */
struct mutex cmd_mutex;
wait_queue_head_t cmd_wait;
bool is_cmd_done;
enum edma_sub_state state;
enum edma_power_state power_state;
struct task_struct *enque_task;
const void *plat_drv;
u8 sub_name[EDMA_SUB_NAME_SIZE];
uint32_t ip_time;
unsigned int dbg_portID;
};
struct edma_device {
struct device *dev;
struct edma_sub *edma_sub[EDMA_SUB_NUM];
struct timer_list power_timer;
unsigned int edma_sub_num;
/* notify enque thread */
wait_queue_head_t req_wait;
/* to check user list must have mutex protection */
struct mutex power_mutex;
enum edma_power_state power_state;
struct work_struct power_off_work;
dev_t edma_devt;
struct cdev edma_chardev;
struct dentry *debug_root;
unsigned int dbgfs_reg_core;
unsigned int dbg_cfg;
};
struct edma_user {
pid_t open_pid;
pid_t open_tgid;
u32 id;
struct device *dev;
struct mutex data_mutex;
bool running;
bool flush;
struct list_head enque_list;
struct list_head deque_list;
wait_queue_head_t deque_wait;
};
struct descriptor {
u32 src_tile_channel;
u32 src_tile_width;
u32 src_tile_height;
u32 src_channel_stride;
u32 src_uv_channel_stride;
u32 src_width_stride;
u32 src_uv_width_stride;
u32 dst_tile_channel;
u32 dst_tile_width;
u32 dst_channel_stride;
u32 dst_uv_channel_stride;
u32 dst_width_stride;
u32 dst_uv_width_stride;
u32 src_addr;
u32 src_uv_addr;
u32 dst_addr;
u32 dst_uv_addr;
u32 range_scale;
u32 min_fp32;
u32 param_a;
u32 param_m;
u32 cmprs_src_pxl;
u32 cmprs_dst_pxl;
u32 src_c_stride_pxl;
u32 src_w_stride_pxl;
u32 src_c_offset_m1;
u32 src_w_offset_m1;
u32 dst_c_stride_pxl;
u32 dst_w_stride_pxl;
u32 dst_c_offset_m1;
u32 dst_w_offset_m1;
u8 in_format;
u8 out_format;
u8 yuv2rgb_mat_bypass;
u8 rgb2yuv_mat_bypass;
u8 yuv2rgb_mat_select;
u8 rgb2yuv_mat_select;
u8 plane_num;
u8 unpack_shift;
u8 bit_num;
};
struct edma_request {
u64 handle;
u32 cmd;
u32 sub;
struct descriptor desp;
u32 fill_value;
u32 ext_reg_addr;
u32 ext_count;
u8 buf_iommu_en;
u8 desp_iommu_en;
s32 cmd_result;
u32 cmd_status;
};
#define EDMA_EXT_MODE_SIZE 0x60
enum edma_command_type {
EDMA_PROC_NORMAL,
EDMA_PROC_FILL,
EDMA_PROC_NUMERICAL,
EDMA_PROC_FORMAT,
EDMA_PROC_COMPRESS,
EDMA_PROC_DECOMPRESS,
EDMA_PROC_RAW,
EDMA_PROC_EXT_MODE,
EDMA_PROC_MAX,
};
struct edma_ext {
__u64 cmd_handle;
__u32 count;
__u32 reg_addr;
__u32 fill_value;
__u8 desp_iommu_en;
} __attribute__ ((__packed__));
//long edma_ioctl(struct file *flip, unsigned int cmd, unsigned long arg);
int edma_initialize(struct edma_device *edma_device);
#endif /* __EDMA_DRIVER_H__ */
@@ -0,0 +1,248 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
* Author: JB Tsai <jb.tsai@mediatek.com>
*/
#ifndef __EDMA_IOCTL_H__
#define __EDMA_IOCTL_H__
#define EDMA_EXT_MODE_SIZE 0x40
#define EDMA_MAGICNO 'v'
#define EDMA_IOCTL_ENQUE_NORMAL _IOWR(EDMA_MAGICNO, 0,\
struct edma_normal)
#define EDMA_IOCTL_ENQUE_FILL _IOWR(EDMA_MAGICNO, 1,\
struct edma_fill)
#define EDMA_IOCTL_ENQUE_NUMERICAL _IOWR(EDMA_MAGICNO, 2,\
struct edma_numerical)
#define EDMA_IOCTL_ENQUE_FORMAT _IOWR(EDMA_MAGICNO, 3,\
struct edma_format)
#define EDMA_IOCTL_ENQUE_COMPRESS _IOWR(EDMA_MAGICNO, 4,\
struct edma_compress)
#define EDMA_IOCTL_ENQUE_DECOMPRESS _IOWR(EDMA_MAGICNO, 5,\
struct edma_decompress)
#define EDMA_IOCTL_ENQUE_RAW _IOWR(EDMA_MAGICNO, 6,\
struct edma_raw)
#define EDMA_IOCTL_DEQUE _IOWR(EDMA_MAGICNO, 7,\
struct edma_cmd_deque)
#define EDMA_IOCTL_SYNC_NORMAL _IOWR(EDMA_MAGICNO, 8,\
struct edma_normal)
#define EDMA_IOCTL_ENQUE_EXT_MODE _IOWR(EDMA_MAGICNO, 9,\
struct edma_ext)
#define EDMA_IOCTL_SYNC_EXT_MODE _IOWR(EDMA_MAGICNO, 10,\
struct edma_ext)
enum edma_req_status {
/** 0: EDMA_REQ_STATUS_ENQUEUE */
EDMA_REQ_STATUS_ENQUEUE,
/** 1: EDMA_REQ_STATUS_RUN */
EDMA_REQ_STATUS_RUN,
/** 2: EDMA_REQ_STATUS_DEQUEUE */
EDMA_REQ_STATUS_DEQUEUE,
/** 3: EDMA_REQ_STATUS_TIMEOUT */
EDMA_REQ_STATUS_TIMEOUT,
/** 4: EDMA_REQ_STATUS_INVALID */
EDMA_REQ_STATUS_INVALID,
/** 5: EDMA_REQ_STATUS_FLUSH */
EDMA_REQ_STATUS_FLUSH,
};
enum edma_desp_format {
EDMA_FORMAT_FP32 = 1,
EDMA_FORMAT_FP16,
EDMA_FORMAT_I8,
EDMA_FORMAT_YUV420_2_PLANE_8B,
EDMA_FORMAT_YUV420_2_PLANE_16B,
EDMA_FORMAT_YUV420_2_PLANE_P010,
EDMA_FORMAT_YUV420_2_PLANE_MTK420_PACK_10B,
EDMA_FORMAT_RGB_8B,
EDMA_FORMAT_ARGB2SET_8B,
EDMA_FORMAT_ARGB2SET_16B,
EDMA_FORMAT_ARGB2SET_2101010,
EDMA_FORMAT_BITSTREAM_YUV420_8B,
EDMA_FORMAT_BITSTREAM_YUV420_10B,
EDMA_FORMAT_BITSTREAM_ARGB_8B,
EDMA_FORMAT_BITSTREAM_ARGB_10B,
};
struct edma_normal {
__u64 cmd_handle;
__u32 tile_channel;
__u32 tile_width;
__u32 tile_height;
__u32 src_channel_stride;
__u32 src_width_stride;
__u32 dst_channel_stride;
__u32 dst_width_stride;
__u32 src_addr;
__u32 dst_addr;
__u8 buf_iommu_en;
};
struct edma_fill {
__u64 cmd_handle;
__u32 tile_channel;
__u32 tile_width;
__u32 tile_height;
__u32 dst_channel_stride;
__u32 dst_width_stride;
__u32 dst_addr;
__u32 fill_value;
__u8 buf_iommu_en;
};
struct edma_numerical {
__u64 cmd_handle;
__u32 tile_channel;
__u32 tile_width;
__u32 tile_height;
__u32 src_channel_stride;
__u32 src_width_stride;
__u32 dst_channel_stride;
__u32 dst_width_stride;
__u32 src_addr;
__u32 dst_addr;
__u32 range_scale;
__u32 min_fp32;
__u8 in_format;
__u8 out_format;
};
struct edma_format {
__u64 cmd_handle;
__u32 src_tile_channel;
__u32 src_tile_width;
__u32 src_tile_height;
__u32 src_channel_stride;
__u32 src_uv_channel_stride;
__u32 src_width_stride;
__u32 src_uv_width_stride;
__u32 dst_tile_channel;
__u32 dst_tile_width;
__u32 dst_channel_stride;
__u32 dst_uv_channel_stride;
__u32 dst_width_stride;
__u32 dst_uv_width_stride;
__u32 src_addr;
__u32 src_uv_addr;
__u32 dst_addr;
__u32 dst_uv_addr;
__u32 param_a;
__u8 in_format;
__u8 out_format;
};
struct edma_compress {
__u64 cmd_handle;
__u32 src_tile_channel;
__u32 src_tile_width;
__u32 src_tile_height;
__u32 src_channel_stride;
__u32 src_uv_channel_stride;
__u32 src_width_stride;
__u32 src_uv_width_stride;
__u32 dst_tile_channel;
__u32 dst_tile_width;
__u32 dst_channel_stride;
__u32 dst_uv_channel_stride;
__u32 dst_width_stride;
__u32 dst_uv_width_stride;
__u32 src_addr;
__u32 src_uv_addr;
__u32 dst_addr;
__u32 dst_uv_addr;
__u32 param_a;
__u32 param_m;
__u32 cmprs_src_pxl;
__u32 cmprs_dst_pxl;
__u32 src_c_stride_pxl;
__u32 src_w_stride_pxl;
__u32 src_c_offset_m1;
__u32 src_w_offset_m1;
__u32 dst_c_stride_pxl;
__u32 dst_w_stride_pxl;
__u32 dst_c_offset_m1;
__u32 dst_w_offset_m1;
__u8 in_format;
__u8 out_format;
__u8 yuv2rgb_mat_bypass;
__u8 rgb2yuv_mat_bypass;
__u8 yuv2rgb_mat_select;
__u8 rgb2yuv_mat_select;
};
struct edma_decompress {
__u64 cmd_handle;
__u32 src_tile_channel;
__u32 src_tile_width;
__u32 src_tile_height;
__u32 src_channel_stride;
__u32 src_uv_channel_stride;
__u32 src_width_stride;
__u32 src_uv_width_stride;
__u32 dst_tile_channel;
__u32 dst_tile_width;
__u32 dst_channel_stride;
__u32 dst_uv_channel_stride;
__u32 dst_width_stride;
__u32 dst_uv_width_stride;
__u32 src_addr;
__u32 src_uv_addr;
__u32 dst_addr;
__u32 dst_uv_addr;
__u32 param_a;
__u32 param_m;
__u32 cmprs_src_pxl;
__u32 cmprs_dst_pxl;
__u32 src_c_stride_pxl;
__u32 src_w_stride_pxl;
__u32 src_c_offset_m1;
__u32 src_w_offset_m1;
__u32 dst_c_stride_pxl;
__u32 dst_w_stride_pxl;
__u32 dst_c_offset_m1;
__u32 dst_w_offset_m1;
__u8 in_format;
__u8 out_format;
__u8 yuv2rgb_mat_bypass;
__u8 rgb2yuv_mat_bypass;
__u8 yuv2rgb_mat_select;
__u8 rgb2yuv_mat_select;
};
struct edma_raw {
__u64 cmd_handle;
__u32 src_tile_channel;
__u32 src_tile_width;
__u32 src_tile_height;
__u32 src_channel_stride;
__u32 src_width_stride;
__u32 dst_tile_channel;
__u32 dst_tile_width;
__u32 dst_channel_stride;
__u32 dst_width_stride;
__u32 src_addr;
__u32 src_uv_addr;
__u32 dst_addr;
__u8 plane_num;
__u8 unpack_shift;
__u8 bit_num;
};
struct edma_ext {
__u64 cmd_handle;
__u32 count;
__u32 reg_addr;
__u32 fill_value;
__u8 desp_iommu_en;
} __attribute__ ((__packed__));
struct edma_cmd_deque {
__u64 cmd_handle;
__s32 cmd_result;
__u32 cmd_status;
};
#endif /* __EDMA_IOCTL_H__ */
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/module.h>
#include <linux/of_device.h>
#include "edma_cmd_hnd.h"
#include "edma_plat_internal.h"
static struct edma_plat_drv edma_v20_drv = {
.exe_sub = edma_exe_v20,
.prt_error = print_error_status,
.edma_isr = edma_isr_handler,
.cmd_timeout_ms = 3000,
.delay_power_off_ms = 2000,
};
static struct edma_plat_drv edma_v30_drv = {
.exe_sub = edma_exe_v30,
.prt_error = printV30_error_status,
.edma_isr = edmaV30_isr_handler,
.cmd_timeout_ms = 3000,
.delay_power_off_ms = 2000,
};
static const struct of_device_id mtk_edma_sub_of_ids[] = {
{.compatible = "mtk,edma-sub", .data = &edma_v20_drv},
{.compatible = "mtk,edma-sub-v20", .data = &edma_v20_drv},
{.compatible = "mtk,edma-sub-v30", .data = &edma_v30_drv},
{}
};
MODULE_DEVICE_TABLE(of, mtk_edma_sub_of_ids);
const struct of_device_id *edma_plat_get_device(void)
{
return mtk_edma_sub_of_ids;
}
@@ -0,0 +1,39 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __EDMA_PLAT_INTERNAL_H__
#define __EDMA_PLAT_INTERNAL_H__
#include <linux/platform_device.h>
#include <linux/interrupt.h>
#include "edma_driver.h"
struct edma_plat_drv {
int (*exe_sub)(struct edma_sub *edma_sub, struct edma_request *req);
void (*prt_error)(struct edma_sub *edma_sub, struct edma_request *req);
irqreturn_t (*edma_isr)(int irq, void *edma_sub_info);
unsigned int cmd_timeout_ms;
unsigned int delay_power_off_ms;
};
void print_error_status(struct edma_sub *edma_sub,
struct edma_request *req);
int edma_exe_v20(struct edma_sub *edma_sub, struct edma_request *req);
irqreturn_t edma_isr_handler(int irq, void *edma_sub_info);
void printV30_error_status(struct edma_sub *edma_sub,
struct edma_request *req);
int edma_exe_v30(struct edma_sub *edma_sub, struct edma_request *req);
irqreturn_t edmaV30_isr_handler(int irq, void *edma_sub_info);
const struct of_device_id *edma_plat_get_device(void);
#endif /* __EDMA_PLAT_INTERNAL_H__ */
@@ -0,0 +1,528 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
* Author: JB Tsai <jb.tsai@mediatek.com>
*/
#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include "edma_driver.h"
#include "edma_cmd_hnd.h"
#include "edma_ioctl.h"
#include "edma_queue.h"
DECLARE_VLIST(edma_user);
DECLARE_VLIST(edma_request);
int edma_alloc_request(struct edma_request **rreq)
{
struct edma_request *req;
req = kzalloc(sizeof(vlist_type(struct edma_request)), GFP_KERNEL);
if (!req)
return -ENOMEM;
*rreq = req;
return 0;
}
int edma_free_request(struct edma_request *req)
{
kfree(req);
return 0;
}
int edma_create_user(struct edma_user **user, struct edma_device *edma_device)
{
struct edma_user *u;
u = kzalloc(sizeof(vlist_type(struct edma_user)), GFP_KERNEL);
if (!u)
return -ENOMEM;
u->dev = edma_device->dev;
u->id = ++(edma_device->edma_num_users);
u->open_pid = current->pid;
u->open_tgid = current->tgid;
mutex_init(&u->data_mutex);
INIT_LIST_HEAD(&u->enque_list);
INIT_LIST_HEAD(&u->deque_list);
init_waitqueue_head(&u->deque_wait);
mutex_lock(&edma_device->user_mutex);
list_add_tail(vlist_link(u, struct edma_user), &edma_device->user_list);
mutex_unlock(&edma_device->user_mutex);
*user = u;
return 0;
}
int edma_delete_user(struct edma_user *user, struct edma_device *edma_device)
{
struct list_head *head, *temp;
struct edma_request *req;
edma_flush_requests_from_queue(user);
/* clear the list of deque */
mutex_lock(&user->data_mutex);
list_for_each_safe(head, temp, &user->deque_list) {
req = vlist_node_of(head, struct edma_request);
list_del(head);
edma_free_request(req);
}
mutex_unlock(&user->data_mutex);
mutex_lock(&edma_device->user_mutex);
list_del(vlist_link(user, struct edma_user));
mutex_unlock(&edma_device->user_mutex);
kfree(user);
return 0;
}
static int edma_enque_handler(struct edma_request *req,
struct edma_user *user, struct edma_sub *edma_sub)
{
int ret = 0;
edma_power_on(edma_sub);
edma_enable_sequence(edma_sub);
switch (req->cmd) {
case EDMA_PROC_NORMAL:
ret = edma_normal_mode(edma_sub, req);
break;
case EDMA_PROC_FILL:
ret = edma_fill_mode(edma_sub, req);
break;
case EDMA_PROC_NUMERICAL:
ret = edma_numerical_mode(edma_sub, req);
break;
case EDMA_PROC_FORMAT:
ret = edma_format_mode(edma_sub, req);
break;
case EDMA_PROC_COMPRESS:
ret = edma_compress_mode(edma_sub, req);
break;
case EDMA_PROC_DECOMPRESS:
ret = edma_decompress_mode(edma_sub, req);
break;
case EDMA_PROC_RAW:
ret = edma_raw_mode(edma_sub, req);
break;
case EDMA_PROC_EXT_MODE:
ret = edma_ext_mode(edma_sub, req);
break;
default:
pr_notice("%s: bad command!\n", __func__);
ret = -EINVAL;
}
edma_power_off(edma_sub, 0);
return ret;
}
void edma_setup_normal_request(struct edma_request *req,
struct edma_normal *edma_normal,
unsigned int type)
{
req->handle = (u64) req;
req->cmd = type;
req->desp.src_tile_channel = edma_normal->tile_channel;
req->desp.src_tile_width = edma_normal->tile_width;
req->desp.src_tile_height = edma_normal->tile_height;
req->desp.src_channel_stride = edma_normal->src_channel_stride;
req->desp.src_width_stride = edma_normal->src_width_stride;
req->desp.dst_tile_channel = edma_normal->tile_channel;
req->desp.dst_tile_width = edma_normal->tile_width;
req->desp.dst_channel_stride = edma_normal->dst_channel_stride;
req->desp.dst_width_stride = edma_normal->dst_width_stride;
req->desp.src_addr = edma_normal->src_addr;
req->desp.dst_addr = edma_normal->dst_addr;
req->buf_iommu_en = edma_normal->buf_iommu_en;
req->cmd_result = 0;
req->cmd_status = EDMA_REQ_STATUS_ENQUEUE;
}
void edma_setup_fill_request(struct edma_request *req,
struct edma_fill *edma_fill,
unsigned int type)
{
req->handle = (u64) req;
req->cmd = type;
req->desp.dst_tile_channel = edma_fill->tile_channel;
req->desp.dst_tile_width = edma_fill->tile_width;
req->desp.src_tile_height = edma_fill->tile_height;
req->desp.dst_channel_stride = edma_fill->dst_channel_stride;
req->desp.dst_width_stride = edma_fill->dst_width_stride;
req->desp.dst_addr = edma_fill->dst_addr;
req->fill_value = edma_fill->fill_value;
req->buf_iommu_en = edma_fill->buf_iommu_en;
req->cmd_result = 0;
req->cmd_status = EDMA_REQ_STATUS_ENQUEUE;
}
void edma_setup_numerical_request(struct edma_request *req,
struct edma_numerical *edma_numerical,
unsigned int type)
{
req->handle = (u64) req;
req->cmd = type;
req->desp.src_tile_channel = edma_numerical->tile_channel;
req->desp.src_tile_width = edma_numerical->tile_width;
req->desp.src_tile_height = edma_numerical->tile_height;
req->desp.src_channel_stride = edma_numerical->src_channel_stride;
req->desp.src_width_stride = edma_numerical->src_width_stride;
req->desp.dst_tile_channel = edma_numerical->tile_channel;
req->desp.dst_tile_width = edma_numerical->tile_width;
req->desp.dst_channel_stride = edma_numerical->dst_channel_stride;
req->desp.dst_width_stride = edma_numerical->dst_width_stride;
req->desp.src_addr = edma_numerical->src_addr;
req->desp.dst_addr = edma_numerical->dst_addr;
req->desp.range_scale = edma_numerical->range_scale;
req->desp.min_fp32 = edma_numerical->min_fp32;
req->desp.in_format = edma_numerical->in_format;
req->desp.out_format = edma_numerical->out_format;
req->cmd_result = 0;
req->cmd_status = EDMA_REQ_STATUS_ENQUEUE;
}
void edma_setup_format_request(struct edma_request *req,
struct edma_format *edma_format,
unsigned int type)
{
req->handle = (u64) req;
req->cmd = type;
req->desp.src_tile_channel = edma_format->src_tile_channel;
req->desp.src_tile_width = edma_format->src_tile_width;
req->desp.src_tile_height = edma_format->src_tile_height;
req->desp.src_channel_stride = edma_format->src_channel_stride;
req->desp.src_uv_channel_stride = edma_format->src_uv_channel_stride;
req->desp.src_width_stride = edma_format->src_width_stride;
req->desp.src_uv_width_stride = edma_format->src_uv_width_stride;
req->desp.dst_tile_channel = edma_format->dst_tile_channel;
req->desp.dst_tile_width = edma_format->dst_tile_width;
req->desp.dst_channel_stride = edma_format->dst_channel_stride;
req->desp.dst_uv_channel_stride = edma_format->dst_uv_channel_stride;
req->desp.dst_width_stride = edma_format->dst_width_stride;
req->desp.dst_uv_width_stride = edma_format->dst_uv_width_stride;
req->desp.src_addr = edma_format->src_addr;
req->desp.src_uv_addr = edma_format->src_uv_addr;
req->desp.dst_addr = edma_format->dst_addr;
req->desp.dst_uv_addr = edma_format->dst_uv_addr;
req->desp.param_a = edma_format->param_a;
req->desp.in_format = edma_format->in_format;
req->desp.out_format = edma_format->out_format;
req->cmd_result = 0;
req->cmd_status = EDMA_REQ_STATUS_ENQUEUE;
}
void edma_setup_compress_request(struct edma_request *req,
struct edma_compress *edma_compress,
unsigned int type)
{
req->handle = (u64) req;
req->cmd = type;
req->desp.src_tile_channel = edma_compress->src_tile_channel;
req->desp.src_tile_width = edma_compress->src_tile_width;
req->desp.src_tile_height = edma_compress->src_tile_height;
req->desp.src_channel_stride = edma_compress->src_channel_stride;
req->desp.src_uv_channel_stride = edma_compress->src_uv_channel_stride;
req->desp.src_width_stride = edma_compress->src_width_stride;
req->desp.src_uv_width_stride = edma_compress->src_uv_width_stride;
req->desp.dst_tile_channel = edma_compress->dst_tile_channel;
req->desp.dst_tile_width = edma_compress->dst_tile_width;
req->desp.dst_channel_stride = edma_compress->dst_channel_stride;
req->desp.dst_uv_channel_stride = edma_compress->dst_uv_channel_stride;
req->desp.dst_width_stride = edma_compress->dst_width_stride;
req->desp.dst_uv_width_stride = edma_compress->dst_uv_width_stride;
req->desp.src_addr = edma_compress->src_addr;
req->desp.src_uv_addr = edma_compress->src_uv_addr;
req->desp.dst_addr = edma_compress->dst_addr;
req->desp.dst_uv_addr = edma_compress->dst_uv_addr;
req->desp.param_a = edma_compress->param_a;
req->desp.param_m = edma_compress->param_m;
req->desp.cmprs_src_pxl = edma_compress->cmprs_src_pxl;
req->desp.cmprs_dst_pxl = edma_compress->cmprs_dst_pxl;
req->desp.src_c_stride_pxl = edma_compress->src_c_stride_pxl;
req->desp.src_w_stride_pxl = edma_compress->src_w_stride_pxl;
req->desp.src_c_offset_m1 = edma_compress->src_c_offset_m1;
req->desp.src_w_offset_m1 = edma_compress->src_w_offset_m1;
req->desp.dst_c_stride_pxl = edma_compress->dst_c_stride_pxl;
req->desp.dst_w_stride_pxl = edma_compress->dst_w_stride_pxl;
req->desp.dst_c_offset_m1 = edma_compress->dst_c_offset_m1;
req->desp.dst_w_offset_m1 = edma_compress->dst_w_offset_m1;
req->desp.in_format = edma_compress->in_format;
req->desp.out_format = edma_compress->out_format;
req->desp.rgb2yuv_mat_bypass = edma_compress->rgb2yuv_mat_bypass;
req->desp.rgb2yuv_mat_select = edma_compress->rgb2yuv_mat_select;
req->cmd_result = 0;
req->cmd_status = EDMA_REQ_STATUS_ENQUEUE;
}
void edma_setup_decompress_request(struct edma_request *req,
struct edma_decompress *edma_decompress,
unsigned int type)
{
req->handle = (u64) req;
req->cmd = type;
req->desp.src_tile_channel = edma_decompress->src_tile_channel;
req->desp.src_tile_width = edma_decompress->src_tile_width;
req->desp.src_tile_height = edma_decompress->src_tile_height;
req->desp.src_channel_stride = edma_decompress->src_channel_stride;
req->desp.src_uv_channel_stride =
edma_decompress->src_uv_channel_stride;
req->desp.src_width_stride = edma_decompress->src_width_stride;
req->desp.src_uv_width_stride = edma_decompress->src_uv_width_stride;
req->desp.dst_tile_channel = edma_decompress->dst_tile_channel;
req->desp.dst_tile_width = edma_decompress->dst_tile_width;
req->desp.dst_channel_stride = edma_decompress->dst_channel_stride;
req->desp.dst_uv_channel_stride =
edma_decompress->dst_uv_channel_stride;
req->desp.dst_width_stride = edma_decompress->dst_width_stride;
req->desp.dst_uv_width_stride = edma_decompress->dst_uv_width_stride;
req->desp.src_addr = edma_decompress->src_addr;
req->desp.src_uv_addr = edma_decompress->src_uv_addr;
req->desp.dst_addr = edma_decompress->dst_addr;
req->desp.dst_uv_addr = edma_decompress->dst_uv_addr;
req->desp.param_a = edma_decompress->param_a;
req->desp.param_m = edma_decompress->param_m;
req->desp.cmprs_src_pxl = edma_decompress->cmprs_src_pxl;
req->desp.cmprs_dst_pxl = edma_decompress->cmprs_dst_pxl;
req->desp.src_c_stride_pxl = edma_decompress->src_c_stride_pxl;
req->desp.src_w_stride_pxl = edma_decompress->src_w_stride_pxl;
req->desp.src_c_offset_m1 = edma_decompress->src_c_offset_m1;
req->desp.src_w_offset_m1 = edma_decompress->src_w_offset_m1;
req->desp.dst_c_stride_pxl = edma_decompress->dst_c_stride_pxl;
req->desp.dst_w_stride_pxl = edma_decompress->dst_w_stride_pxl;
req->desp.dst_c_offset_m1 = edma_decompress->dst_c_offset_m1;
req->desp.dst_w_offset_m1 = edma_decompress->dst_w_offset_m1;
req->desp.in_format = edma_decompress->in_format;
req->desp.out_format = edma_decompress->out_format;
req->desp.rgb2yuv_mat_bypass = edma_decompress->rgb2yuv_mat_bypass;
req->desp.rgb2yuv_mat_select = edma_decompress->rgb2yuv_mat_select;
req->cmd_result = 0;
req->cmd_status = EDMA_REQ_STATUS_ENQUEUE;
}
void edma_setup_raw_request(struct edma_request *req,
struct edma_raw *edma_raw,
unsigned int type)
{
req->handle = (u64) req;
req->cmd = type;
req->desp.src_tile_channel = edma_raw->src_tile_channel;
req->desp.src_tile_width = edma_raw->src_tile_width;
req->desp.src_tile_height = edma_raw->src_tile_height;
req->desp.src_channel_stride = edma_raw->src_channel_stride;
req->desp.src_width_stride = edma_raw->src_width_stride;
req->desp.dst_tile_channel = edma_raw->dst_tile_channel;
req->desp.dst_tile_width = edma_raw->dst_tile_width;
req->desp.dst_channel_stride = edma_raw->dst_channel_stride;
req->desp.dst_width_stride = edma_raw->dst_width_stride;
req->desp.src_addr = edma_raw->src_addr;
req->desp.src_uv_addr = edma_raw->src_uv_addr;
req->desp.dst_addr = edma_raw->dst_addr;
req->desp.plane_num = edma_raw->plane_num;
req->desp.unpack_shift = edma_raw->unpack_shift;
req->desp.bit_num = edma_raw->bit_num;
req->cmd_result = 0;
req->cmd_status = EDMA_REQ_STATUS_ENQUEUE;
}
void edma_setup_ext_mode_request(struct edma_request *req,
struct edma_ext *edma_ext,
unsigned int type)
{
req->handle = (u64) req;
req->cmd = type;
req->ext_reg_addr = edma_ext->reg_addr;
req->ext_count = edma_ext->count;
req->fill_value = edma_ext->fill_value;
req->desp_iommu_en = edma_ext->desp_iommu_en;
req->cmd_result = 0;
req->cmd_status = EDMA_REQ_STATUS_ENQUEUE;
}
int edma_push_request_to_queue(struct edma_user *user,
struct edma_request *req)
{
struct edma_device *edma_device;
int ret = 0;
if (!user) {
pr_notice("empty user");
return -EINVAL;
}
edma_device = dev_get_drvdata(user->dev);
mutex_lock(&user->data_mutex);
list_add_tail(vlist_link(req, struct edma_request),
&user->enque_list);
mutex_unlock(&user->data_mutex);
wake_up(&edma_device->req_wait);
return ret;
}
int edma_pop_request_from_queue(u64 handle,
struct edma_user *user,
struct edma_request **rreq)
{
struct list_head *head, *temp;
struct edma_request *req = NULL;
int status = EDMA_REQ_STATUS_RUN;
mutex_lock(&user->data_mutex);
/* This part should not be happened */
if (list_empty(&user->deque_list)) {
mutex_unlock(&user->data_mutex);
*rreq = NULL;
return status;
};
status = EDMA_REQ_STATUS_INVALID;
list_for_each_safe(head, temp, &user->deque_list) {
req = vlist_node_of(head, struct edma_request);
if (req->handle == handle) {
list_del_init(vlist_link(req, struct edma_request));
status = EDMA_REQ_STATUS_DEQUEUE;
req->cmd_status = EDMA_REQ_STATUS_DEQUEUE;
break;
}
}
mutex_unlock(&user->data_mutex);
*rreq = req;
return status;
}
static bool users_queue_are_empty(struct edma_device *edma_device)
{
struct list_head *head;
struct edma_user *user;
bool is_empty = true;
mutex_lock(&edma_device->user_mutex);
list_for_each(head, &edma_device->user_list) {
user = vlist_node_of(head, struct edma_user);
if (!list_empty(&user->enque_list)) {
is_empty = false;
break;
}
}
mutex_unlock(&edma_device->user_mutex);
return is_empty;
}
int edma_enque_routine_loop(void *arg)
{
struct edma_sub *edma_sub = (struct edma_sub *)arg;
struct list_head *head;
struct edma_user *user;
struct edma_request *req;
u32 sub = edma_sub->sub;
struct edma_device *edma_device = edma_sub->edma_device;
DEFINE_WAIT_FUNC(wait, woken_wake_function);
for (; !kthread_should_stop();) {
/* wait for requests if there is no one in user's queue */
add_wait_queue(&edma_device->req_wait, &wait);
while (1) {
if (!users_queue_are_empty(edma_device))
break;
wait_woken(&wait, TASK_INTERRUPTIBLE,
MAX_SCHEDULE_TIMEOUT);
}
remove_wait_queue(&edma_device->req_wait, &wait);
/* consume the user's queue */
mutex_lock(&edma_device->user_mutex);
list_for_each(head, &edma_device->user_list) {
user = vlist_node_of(head, struct edma_user);
mutex_lock(&user->data_mutex);
/* thread will handle the remaining queue if flush */
if (user->flush ||
list_empty(&user->enque_list)) {
mutex_unlock(&user->data_mutex);
continue;
}
/* get first node from enque list */
req =
vlist_node_of(user->enque_list.next,
struct edma_request);
list_del_init(vlist_link(req, struct edma_request));
req->sub = sub;
user->running = true;
mutex_unlock(&user->data_mutex);
/* unlock for avoiding long time locking */
mutex_unlock(&edma_device->user_mutex);
edma_enque_handler(req, user, edma_sub);
mutex_lock(&edma_device->user_mutex);
mutex_lock(&user->data_mutex);
list_add_tail(vlist_link(req, struct edma_request),
&user->deque_list);
user->running = false;
mutex_unlock(&user->data_mutex);
wake_up_interruptible_all(&user->deque_wait);
}
mutex_unlock(&edma_device->user_mutex);
/* release cpu for another operations */
usleep_range(1, 10);
}
return 0;
}
int edma_flush_requests_from_queue(struct edma_user *user)
{
struct list_head *head, *temp;
struct edma_request *req;
mutex_lock(&user->data_mutex);
if (!user->running && list_empty(&user->enque_list)) {
mutex_unlock(&user->data_mutex);
return 0;
}
user->flush = true;
mutex_unlock(&user->data_mutex);
/* the running request will add to the deque before interrupt */
wait_event_interruptible(user->deque_wait, !user->running);
mutex_lock(&user->data_mutex);
/* push the remaining enque to the deque */
list_for_each_safe(head, temp, &user->enque_list) {
req = vlist_node_of(head, struct edma_request);
req->cmd_status = EDMA_REQ_STATUS_FLUSH;
list_del_init(head);
list_add_tail(head, &user->deque_list);
}
user->flush = false;
mutex_unlock(&user->data_mutex);
return 0;
}
@@ -0,0 +1,100 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
* Author: JB Tsai <jb.tsai@mediatek.com>
*/
#ifndef __EDMA_QUEUE_H__
#define __EDMA_QUEUE_H__
#define DECLARE_VLIST(type) \
struct type ## _list { \
struct type node; \
struct list_head link; \
}
/*
* vlist_node_of - get the pointer to the node which has specific vlist
* @ptr: the pointer to struct list_head
* @type: the type of list node
*/
#define vlist_node_of(ptr, type) ({ \
const struct list_head *mptr = (ptr); \
(type *)((char *)mptr - offsetof(type ## _list, link)); })
/*
* vlist_link - get the pointer to struct list_head
* @ptr: the pointer to struct vlist
* @type: the type of list node
*/
#define vlist_link(ptr, type) \
((struct list_head *)((char *)ptr + offsetof(type ## _list, link)))
/*
* vlist_type - get the type of struct vlist
* @type: the type of list node
*/
#define vlist_type(type) type ## _list
/*
* vlist_node - get the pointer to the node of vlist
* @ptr: the pointer to struct vlist
* @type: the type of list node
*/
#define vlist_node(ptr, type) ((type *)ptr)
enum edma_command_type {
EDMA_PROC_NORMAL,
EDMA_PROC_FILL,
EDMA_PROC_NUMERICAL,
EDMA_PROC_FORMAT,
EDMA_PROC_COMPRESS,
EDMA_PROC_DECOMPRESS,
EDMA_PROC_RAW,
EDMA_PROC_EXT_MODE,
EDMA_PROC_MAX,
};
int edma_alloc_request(struct edma_request **rreq);
int edma_free_request(struct edma_request *req);
int edma_create_user(struct edma_user **user, struct edma_device *edma_device);
int edma_delete_user(struct edma_user *user, struct edma_device *edma_device);
int edma_enque_routine_loop(void *arg);
int edma_flush_requests_from_queue(struct edma_user *user);
int edma_free_request(struct edma_request *req);
void edma_setup_normal_request(struct edma_request *req,
struct edma_normal *edma_normal,
unsigned int type);
void edma_setup_fill_request(struct edma_request *req,
struct edma_fill *edma_fill,
unsigned int type);
void edma_setup_ext_mode_request(struct edma_request *req,
struct edma_ext *edma_ext,
unsigned int type);
void edma_setup_numerical_request(struct edma_request *req,
struct edma_numerical *edma_numerical,
unsigned int type);
void edma_setup_format_request(struct edma_request *req,
struct edma_format *edma_format,
unsigned int type);
void edma_setup_compress_request(struct edma_request *req,
struct edma_compress *edma_compress,
unsigned int type);
void edma_setup_decompress_request(struct edma_request *req,
struct edma_decompress *edma_decompress,
unsigned int type);
void edma_setup_raw_request(struct edma_request *req,
struct edma_raw *edma_raw,
unsigned int type);
int edma_push_request_to_queue(struct edma_user *user,
struct edma_request *req);
int edma_pop_request_from_queue(u64 handle,
struct edma_user *user,
struct edma_request **rreq);
#endif /* __EDMA_QUEUE_H__ */
@@ -0,0 +1,142 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
* Author: JB Tsai <jb.tsai@mediatek.com>
*/
#ifndef __EDMA_REG_H__
#define __EDMA_REG_H__
#include <linux/kernel.h>
#include <linux/io.h>
#define EDMA_REG_SHOW_RANGE 0x150
#define EDMA_REG_EX_R1 0xC00
#define EDMA_REG_EX_R2 0xC5C
#define DESP_WRITE_POINTER_MASK 0x00000030
#define NUM_DESP_MASK 0x00000007
#define DESP_NUM_INCR_MASK 0x00070000
#define DMA_IDLE_MASK 0x00000200
#define YUVRGB_MAT_MASK 0x7E000000
#define APU_EDMA2_DESP_OFFSET 0x100
#define APU_EDMA2_EX_DESP_OFFSET 0x60
/* APU_EDMA2_CTL_0 */
#define CLK_ENABLE BIT(0)
#define DMA_SW_RST BIT(4)
#define AXI_PROT_EN BIT(12)
#define RST_PROT_IDLE BIT(14)
#define EDMA_DESCRIPTOR_MODE BIT(16)
/* APU_EDMA2_CFG_0 */
#define EXT_DESP_START BIT(12)
#define DESP_NUM_INCR BIT(16)
/* APU_EDMA2_INT_STATUS */
#define DESP0_DONE_STATUS BIT(0)
#define DESP1_DONE_STATUS BIT(1)
#define DESP2_DONE_STATUS BIT(2)
#define DESP3_DONE_STATUS BIT(3)
#define EXT_DESP_DONE_STATUS BIT(4)
#define DESP0_DONE_INT_STATUS BIT(16)
#define DESP1_DONE_INT_STATUS BIT(17)
#define DESP2_DONE_INT_STATUS BIT(18)
#define DESP3_DONE_INT_STATUS BIT(19)
#define EXT_DESP_DONE_INT_STATUS BIT(20)
/* APU_EDMA2_EXT_DESP_CFG_0 */
#define EXT_DESP_INT_ENABLE BIT(16)
#define DESP0_OUT_FILL_MODE BIT(20)
#define DESP0_INT_ENABLE BIT(28)
#define EXT_DESP_USER_IOMMU BIT(12)
#define DESP0_DMA_AWUSER_IOMMU BIT(6)
#define DESP0_DMA_ARUSER_IOMMU BIT(1)
#define APU_EDMA2_CTL_0 0x000
#define APU_EDMA2_CFG_0 0x004
#define APU_EDMA2_INT_MASK 0x008
#define APU_EDMA2_ERR_INT_MASK 0x00C
#define APU_EDMA2_INT_STATUS 0x010
#define APU_EDMA2_ERR_STATUS 0x014
#define APU_EDMA2_FILL_VALUE 0x018
#define APU_EDMA2_UFBC_CFG_0 0x020
#define APU_EDMA2_UFBC_CFG_1 0x024
#define APU_EDMA2_UFBDC_CFG_0 0x030
#define APU_EDMA2_UFBDC_CFG_1 0x034
#define APU_EDMA2_UFBDC_INFO_0 0x038
#define APU_EDMA2_AFBC_DBG_SEL 0x080
#define APU_EDMA2_UFBC_DBG_INFO 0x084
#define APU_EDMA2_UFBDC_DBG_INFO 0x088
#define APU_EDMA2_UFBDC_VCODE_0 0x090
#define APU_EDMA2_UFBDC_VCODE_1 0x094
#define APU_EDMA2_UFBDC_VCODE_2 0x098
#define APU_EDMA2_UFBDC_VCODE_3 0x09C
#define APU_EDMA2_EXT_DESP_CFG_0 0x0A0
#define APU_EDMA2_EXT_DESP_CFG_1 0x0A4
#define APU_EDMA2_PMU_CTL 0x100
#define APU_EDMA2_DBG_PMU_SEL 0x104
#define APU_EDMA2_DBG_PMU_INFO 0x108
#define APU_EDMA2_DESP0_0 0x800
#define APU_EDMA2_DESP0_4 0x804
#define APU_EDMA2_DESP0_8 0x808
#define APU_EDMA2_DESP0_C 0x80C
#define APU_EDMA2_DESP0_10 0x810
#define APU_EDMA2_DESP0_14 0x814
#define APU_EDMA2_DESP0_18 0x818
#define APU_EDMA2_DESP0_1C 0x81C
#define APU_EDMA2_DESP0_20 0x820
#define APU_EDMA2_DESP0_24 0x824
#define APU_EDMA2_DESP0_28 0x828
#define APU_EDMA2_DESP0_2C 0x82C
#define APU_EDMA2_DESP0_30 0x830
#define APU_EDMA2_DESP0_34 0x834
#define APU_EDMA2_DESP0_38 0x838
#define APU_EDMA2_DESP0_3C 0x83C
#define APU_EDMA2_DESP0_40 0x840
#define APU_EDMA2_DESP0_44 0x844
#define APU_EDMA2_DESP0_48 0x848
#define APU_EDMA2_DESP0_4C 0x84C
#define APU_EDMA2_DESP0_50 0x850
#define APU_EDMA2_DESP0_54 0x854
#define APU_EDMA2_DESP0_58 0x858
#define APU_EDMA2_DESP0_5C 0x85C
static inline unsigned int edma_read_reg32(void __iomem *edma_base,
unsigned int offset)
{
return readl(edma_base + offset);
}
static inline void edma_write_reg32(void __iomem *edma_base,
unsigned int offset,
unsigned int val)
{
writel(val, edma_base + offset);
}
static inline void edma_set_reg32(void __iomem *edma_base, unsigned int offset,
unsigned int bits)
{
edma_write_reg32(edma_base, offset,
(edma_read_reg32(edma_base, offset) | bits));
}
static inline void edma_clear_reg32(void __iomem *edma_base,
unsigned int offset,
unsigned int bits)
{
edma_write_reg32(edma_base, offset,
(edma_read_reg32(edma_base, offset) & ~bits));
}
#endif /* __EDMA_REG_H__ */
@@ -0,0 +1,243 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/sched/clock.h>
#include "edma_driver.h"
#include "edma_cmd_hnd.h"
#include "edma_reg.h"
#include "apusys_power.h"
#include "edma_dbgfs.h"
#include "edma_plat_internal.h"
#include "apusys_dbg.h"
#define NO_INTERRUPT 0
#define EDMA_POWEROFF_TIME_DEFAULT 2000
static void edma_sw_reset(struct edma_sub *edma_sub);
void print_error_status(struct edma_sub *edma_sub,
struct edma_request *req)
{
u32 status, i, j;
unsigned int *ext_reg = NULL;
status = edma_read_reg32(edma_sub->base_addr, APU_EDMA2_ERR_STATUS);
pr_notice("%s error status %x\n", edma_sub->sub_name,
status);
for (i = 0; i < (EDMA_REG_SHOW_RANGE >> 2); i++) {
status = edma_read_reg32(edma_sub->base_addr, i*4);
pr_notice("edma error dump register[0x%x] = 0x%x\n",
i*4, status);
}
for (i = (0xC00/4); i < (0xD00/4); i++) {
status = edma_read_reg32(edma_sub->base_addr, i*4);
pr_notice("edma error dump register[0x%x] = 0x%x\n",
i*4, status);
}
if (req->ext_reg_addr != 0) {
ext_reg = (unsigned int *)
apusys_mem_query_kva(req->ext_reg_addr);
pr_notice("kva ext_reg = 0x%p, req->ext_count = %d\n",
ext_reg, req->ext_count);
if (ext_reg != 0)
for (i = 0; i < req->ext_count; i++) {
for (j = 0; j < EDMA_EXT_MODE_SIZE/4; j++)
pr_notice("descriptor%d [0x%x] = 0x%x\n",
i, j*4, *(ext_reg + j));
}
else
pr_notice("not support ext_reg dump!!\n");
}
edma_sw_reset(edma_sub);
}
irqreturn_t edma_isr_handler(int irq, void *edma_sub_info)
{
struct edma_sub *edma_sub = (struct edma_sub *)edma_sub_info;
u32 status;
u32 desp0_done;
u32 desp0_intr;
u32 desp1_done;
u32 desp1_intr;
u32 desp2_done;
u32 desp2_intr;
u32 desp3_done;
u32 desp3_intr;
u32 desp4_done;
u32 desp4_intr;
status = edma_read_reg32(edma_sub->base_addr, APU_EDMA2_INT_STATUS);
desp0_done = status & DESP0_DONE_STATUS;
desp1_done = status & DESP1_DONE_STATUS;
desp2_done = status & DESP2_DONE_STATUS;
desp3_done = status & DESP3_DONE_STATUS;
desp4_done = status & EXT_DESP_DONE_STATUS;
desp0_intr = status & DESP0_DONE_INT_STATUS;
desp1_intr = status & DESP1_DONE_INT_STATUS;
desp2_intr = status & DESP2_DONE_INT_STATUS;
desp3_intr = status & DESP3_DONE_INT_STATUS;
desp4_intr = status & EXT_DESP_DONE_INT_STATUS;
edma_sub->is_cmd_done = true;
if (desp0_done | desp1_done | desp2_done | desp3_done | desp4_done)
wake_up_interruptible(&edma_sub->cmd_wait);
if (desp0_intr)
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_INT_STATUS,
DESP0_DONE_INT_STATUS);
else if (desp1_intr)
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_INT_STATUS,
DESP1_DONE_INT_STATUS);
else if (desp2_intr)
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_INT_STATUS,
DESP2_DONE_INT_STATUS);
else if (desp3_intr)
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_INT_STATUS,
DESP3_DONE_INT_STATUS);
else if (desp4_intr)
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_INT_STATUS,
EXT_DESP_DONE_INT_STATUS);
return IRQ_HANDLED;
}
void edma_enable_sequence(struct edma_sub *edma_sub)
{
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_CTL_0, CLK_ENABLE);
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_CTL_0, DMA_SW_RST);
edma_clear_reg32(edma_sub->base_addr, APU_EDMA2_CTL_0, DMA_SW_RST);
}
static void edma_sw_reset(struct edma_sub *edma_sub)
{
u32 value = 0, count = 0;
unsigned long flags;
LOG_DBG("%s\n", __func__);
spin_lock_irqsave(&edma_sub->reg_lock, flags);
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_CTL_0, CLK_ENABLE);
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_CTL_0, AXI_PROT_EN);
while (!(value & RST_PROT_IDLE)) {
value = edma_read_reg32(edma_sub->base_addr, APU_EDMA2_CTL_0);
udelay(5);
count++;
if (count > 10000) {
u32 status, i;
spin_unlock_irqrestore(&edma_sub->reg_lock, flags);
/* dump error log */
pr_notice("hang on %s direct dump...\n", __func__);
for (i = 0; i < (EDMA_REG_SHOW_RANGE >> 2); i++) {
status = edma_read_reg32(edma_sub->base_addr,
i*4);
pr_notice("hang %s edma error dump [0x%x] = 0x%x\n",
__func__, i*4, status);
}
apusys_reg_dump();
/* continues do edma */
spin_lock_irqsave(&edma_sub->reg_lock, flags);
break;
}
}
LOG_DBG("value = 0x%x\n", value);
edma_set_reg32(edma_sub->base_addr, APU_EDMA2_CTL_0, DMA_SW_RST);
udelay(5);
edma_clear_reg32(edma_sub->base_addr, APU_EDMA2_CTL_0, DMA_SW_RST);
udelay(5);
edma_clear_reg32(edma_sub->base_addr, APU_EDMA2_CTL_0, AXI_PROT_EN);
spin_unlock_irqrestore(&edma_sub->reg_lock, flags);
}
/**
* @brief trigger edma external mode
* parameters:
* base_addr: each edma base address
* ext_addr: external descriptor mem addr
* num_desp: number of desc.
* desp_iommu_en: enable iommu or not
*/
void edma_trigger_external(void __iomem *base_addr, u32 ext_addr, u32 num_desp,
u8 desp_iommu_en)
{
edma_set_reg32(base_addr, APU_EDMA2_CTL_0, EDMA_DESCRIPTOR_MODE);
num_desp--;
if (desp_iommu_en)
edma_write_reg32(base_addr, APU_EDMA2_EXT_DESP_CFG_0,
EXT_DESP_INT_ENABLE | EXT_DESP_USER_IOMMU | num_desp);
else
edma_write_reg32(base_addr, APU_EDMA2_EXT_DESP_CFG_0,
EXT_DESP_INT_ENABLE | num_desp);
edma_write_reg32(base_addr, APU_EDMA2_EXT_DESP_CFG_1, ext_addr);
edma_set_reg32(base_addr, APU_EDMA2_CFG_0, EXT_DESP_START);
}
/**
* @brief excute request by each edma_sub
* parameters:
* edma_sub: include each edma base address
*/
int edma_exe_v20(struct edma_sub *edma_sub, struct edma_request *req)
{
int ret = 0;
void __iomem *base_addr;
unsigned long flags;
base_addr = edma_sub->base_addr;
//edma_enable_sequence(edma_sub);
edma_sw_reset(edma_sub); // no need in edma 3.0
spin_lock_irqsave(&edma_sub->reg_lock, flags);
edma_write_reg32(base_addr, APU_EDMA2_FILL_VALUE, req->fill_value);
edma_trigger_external(edma_sub->base_addr,
req->ext_reg_addr,
req->ext_count,
req->desp_iommu_en);
spin_unlock_irqrestore(&edma_sub->reg_lock, flags);
return ret;
}
@@ -0,0 +1,194 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/sched/clock.h>
#include "edma_driver.h"
#include "edma_cmd_hnd.h"
#include "edma3_reg.h"
#include "apusys_power.h"
#include "edma_dbgfs.h"
#include "edma_plat_internal.h"
#define NO_INTERRUPT 0
#define EDMA_POWEROFF_TIME_DEFAULT 2000
void printV30_error_status(struct edma_sub *edma_sub,
struct edma_request *req)
{
u32 status, i, j;
unsigned int *ext_reg = NULL;
u32 portID = edma_sub->dbg_portID;
status = edma_read_reg32(edma_sub->base_addr, APU_EDMA3_ERR_STATUS);
pr_notice("%s error status %x\n", edma_sub->sub_name,
status);
for (i = 0; i < (EDMA30_REG_SHOW_RANGE >> 2); i++) {
status = edma_read_reg32(edma_sub->base_addr, i*4);
pr_notice("edma error dump register[0x%x] = 0x%x\n",
i*4, status);
}
pr_notice("---------------- dump port [%d] registers ----------------\n"
, portID);
for (i = ((0x800+portID*0x100)/4); i < ((0x900+portID*0x100)/4); i++) {
status = edma_read_reg32(edma_sub->base_addr, i*4);
pr_notice("edma error dump register[0x%x] = 0x%x\n",
i*4, status);
}
if (req->ext_reg_addr != 0) {
ext_reg = (unsigned int *)
apusys_mem_query_kva(req->ext_reg_addr);
pr_notice("kva ext_reg = 0x%p, req->ext_count = %d\n",
ext_reg, req->ext_count);
if (ext_reg != 0)
for (i = 0; i < req->ext_count; i++) {
for (j = 0; j < EDMA_EXT_MODE_SIZE/4; j++)
pr_notice("descriptor%d [0x%x] = 0x%x\n",
i, j*4, *(ext_reg + j));
}
else
pr_notice("not support ext_reg dump!!\n");
}
}
irqreturn_t edmaV30_isr_handler(int irq, void *edma_sub_info)
{
struct edma_sub *edma_sub = (struct edma_sub *)edma_sub_info;
u32 status;
u32 portID = edma_sub->dbg_portID;
status = edma_read_reg32(edma_sub->base_addr, APU_EDMA3_DONE_STATUS);
//pr_notice("%s in, done status = 0x%x!!\r\n", __func__, status);
//status = edma_read_reg32(edma_sub->base_addr, 0x814+portID*0x100);
//pr_notice("status portID[%d][0x%x] = 0x%x!!\r\n", portID, 0x814+portID*0x100, status);
//status = edma_read_reg32(edma_sub->base_addr, APU_EDMA3_ERR_STATUS);
//pr_notice("APU_EDMA3_ERR_STATUS = 0x%x ", status);
/* if ((*(uint32_t*)((uint8_t*)edma_sub->base_addr + 0x01c)) & 0x1) { */
/* check port 5 low channel ==> lo5 = 0x20 */
/* {hi7, hi6, hi5, hi4, hi3, hi2, hi1, hi0, lo7, lo6, lo5, lo4, lo3, lo2, lo1, lo0} */
if (edma_read_reg32(edma_sub->base_addr, APU_EDMA3_DONE_STATUS) & (0x1 << portID)) {
edma_sub->is_cmd_done = true;
wake_up_interruptible(&edma_sub->cmd_wait);
} else if (edma_read_reg32(edma_sub->base_addr, APU_EDMA3_ERR_STATUS) != 0) {
status = edma_read_reg32(edma_sub->base_addr, APU_EDMA3_ERR_STATUS);
pr_notice("APU_EDMA3_ERR_STATUS = 0x%x, clear it... ", status);
edma_write_reg32(edma_sub->base_addr, APU_EDMA3_ERR_STATUS, status);
edma_sub->is_cmd_done = true;
wake_up_interruptible(&edma_sub->cmd_wait);
} else {
pr_notice("EDMA3_DONE_STATUS not done & not error...");
edma_sub->is_cmd_done = true;
wake_up_interruptible(&edma_sub->cmd_wait);
}
/* *(uint32_t*)((uint8_t*)edma_sub->base_addr + 0x814) |= 0x1; */
edma_set_reg32(edma_sub->base_addr, 0x814+portID*0x100, 0x1);
return IRQ_HANDLED;
}
static void edmaV30_sw_reset(struct edma_sub *edma_sub)
{
unsigned long flags;
//pr_notice("%s: new init for edma 3.0\n", __func__);
spin_lock_irqsave(&edma_sub->reg_lock, flags);
edma_set_reg32(edma_sub->base_addr, 0x004, (0x1 << 0));
udelay(5);
edma_set_reg32(edma_sub->base_addr, 0x004, (0x1 << 4));
udelay(5);
edma_clear_reg32(edma_sub->base_addr, 0x004, (0x1 << 4));
spin_unlock_irqrestore(&edma_sub->reg_lock, flags);
//LOG_DBG("%s edma 3.0 skip sw reset\n", __func__);
}
/**
* @brief trigger edma external mode
* parameters:
* base_addr: each edma base address
* ext_addr: external descriptor mem addr
* num_desp: number of desc.
* desp_iommu_en: enable iommu or not
*/
void edmaV30_trigger_external(struct edma_sub *edma_sub, u32 ext_addr, u32 num_desp,
u8 desp_iommu_en)
{
unsigned long flags;
u32 portID = edma_sub->dbg_portID;
pr_notice("%s:port id == %d\n", __func__, portID);
spin_lock_irqsave(&edma_sub->reg_lock, flags);
if (desp_iommu_en)
edma_set_reg32(edma_sub->base_addr, 0x004, ((0x2 << 30) | (0x2 << 28)));
udelay(5);
edma_write_reg32(edma_sub->base_addr, 0x800+portID*0x100, ext_addr);
/* [28] irq_en, [20] vc_sw_rst, [19:0] num */
edma_write_reg32(edma_sub->base_addr, 0x804+portID*0x100,
((0x1 << 28) | ((num_desp << 0) & 0xfffff)));
/* [16] stop, [0] fire */
edma_write_reg32(edma_sub->base_addr, 0x808+portID*0x100, (0x1 << 0));
spin_unlock_irqrestore(&edma_sub->reg_lock, flags);
}
/**
* @brief excute request by each edma_sub
* parameters:
* edma_sub: include each edma base address
*/
int edma_exe_v30(struct edma_sub *edma_sub, struct edma_request *req)
{
int ret = 0;
void __iomem *base_addr;
base_addr = edma_sub->base_addr;
//edma_enable_sequence(edma_sub);
edmaV30_sw_reset(edma_sub); // no need in edma 3.0
edmaV30_trigger_external(edma_sub,
req->ext_reg_addr,
req->ext_count,
req->desp_iommu_en);
return ret;
}
@@ -0,0 +1,207 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APUSYS_DEVICE_H__
#define __APUSYS_DEVICE_H__
/* device type */
enum {
APUSYS_DEVICE_NONE,
APUSYS_DEVICE_SAMPLE = 1,
APUSYS_DEVICE_MDLA = 2,
APUSYS_DEVICE_VPU = 3,
APUSYS_DEVICE_EDMA = 4,
APUSYS_DEVICE_EDMA_3_0 = 5,
APUSYS_DEVICE_RT = 32,
APUSYS_DEVICE_SAMPLE_RT = 33,
APUSYS_DEVICE_MDLA_RT = 34,
APUSYS_DEVICE_VPU_RT = 35,
APUSYS_DEVICE_LAST,
APUSYS_DEVICE_MAX = 64, //total support 64 different devices
};
/* device cmd type */
enum {
APUSYS_CMD_POWERON,
APUSYS_CMD_POWERDOWN,
APUSYS_CMD_RESUME,
APUSYS_CMD_SUSPEND,
APUSYS_CMD_EXECUTE,
APUSYS_CMD_PREEMPT,
APUSYS_CMD_FIRMWARE, // setup firmware
APUSYS_CMD_USER, //user defined
APUSYS_CMD_MAX,
};
/* device preempt type */
enum {
// device don't support preemption
APUSYS_PREEMPT_NONE,
// midware should resend preempted command after preemption call
APUSYS_PREEMPT_RESEND,
// midware don't need to resend cmd, and wait preempted cmd completed
APUSYS_PREEMPT_WAITCOMPLETED,
APUSYS_PREEMPT_MAX,
};
enum {
APUSYS_FIRMWARE_UNLOAD,
APUSYS_FIRMWARE_LOAD,
};
/* handle definition for send_cmd */
struct apusys_power_hnd {
uint32_t opp;
int boost_val;
uint32_t timeout;
};
struct apusys_kmem {
unsigned long long uva;
unsigned long long kva;
unsigned int iova;
unsigned int size;
unsigned int iova_size;
unsigned int align;
unsigned int cache;
int mem_type;
int fd;
unsigned long long khandle;
int uidr;
int property;
};
struct apusys_mdla_data {
uint64_t pmu_kva;
uint64_t cmd_entry;
};
/* cmd handle */
struct apusys_cmd_hnd {
/* cmd info */
uint64_t kva;
uint32_t iova;
uint32_t size;
struct apusys_kmem *cmdbuf;
uint64_t cmd_id;
uint32_t subcmd_idx;
uint8_t priority;
uint32_t ip_time;
int boost_val;
int cluster_size;
/* mdw priv*/
uint64_t m_kva;
/* multicore info */
uint32_t multicore_total; // how many cores to exec this subcmd
uint32_t multicore_idx; // which part of subcmd
/* mdla specific */
uint64_t pmu_kva;
uint64_t cmd_entry;
uint32_t cmd_size;
/* For preemption */
int (*context_callback)(int a, int b, uint8_t c);
int ctx_id;
};
struct apusys_firmware_hnd {
char name[32];
uint32_t magic; // for user checking byself
uint64_t kva;
uint32_t iova;
uint32_t size;
int idx;
int op;
};
struct apusys_usercmd_hnd {
uint64_t kva;
uint32_t iova;
uint32_t size;
};
struct apusys_preempt_hnd {
struct apusys_cmd_hnd *new_cmd;
struct apusys_cmd_hnd *old_cmd; //TODO
};
/* device definition */
struct apusys_device {
int dev_type;
int idx;
int preempt_type;
uint8_t preempt_level;
void *private; // for hw driver to record private structure
int (*send_cmd)(int type, void *hnd, struct apusys_device *dev);
};
/*
* export function for hardware driver
* @apusys_register_device
* Description:
* for drvier register device to resource management,
* caller should allocate struct apusys_device struct byself
* midware can schedule task and preempt by current requests status
* 1. user should implement 6 callback function for midware
* Parameters:
* <dev>
* dev_type: apusys device type, define as APUSYS_DEVICE_CMD_E
* private: midware don't touch this,
* it's for user record some private data,
* midware will pass to driver when send_cmd()
* preempt_type:
* preempt_level:
* send_cmd: 6 callback user should implement
* 1. poweron: poweron device with specific opp
* return:
* success: 0
* fail: error code
* 2. poweroff: poweroff device
* return:
* success: 0
* fail: error code
* 3. suspend: suspend device (TODO)
* 4. resume: resume device (TODO)
* 5. excute: execute command with device
* parameter:
* reutrn:
* success: cmd id
* fail: 0
* 6. preempt: preempt device and run new command
* return:
* success: 0
* fail: linux error code (negative value)
*/
extern int apusys_register_device(struct apusys_device *dev);
extern int apusys_unregister_device(struct apusys_device *dev);
extern uint64_t apusys_mem_query_kva(uint32_t iova);
extern uint32_t apusys_mem_query_iova(uint64_t kva);
extern int apusys_mem_flush(struct apusys_kmem *mem);
extern int apusys_mem_invalidate(struct apusys_kmem *mem);
#endif
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __APUSYS_SECURE_H__
#define __APUSYS_SECURE_H__
#include <mt-plat/mtk_secure_api.h>
enum MTK_APUSYS_KERNEL_OP {
MTK_APUSYS_KERNEL_OP_REVISER_SET_BOUNDARY = 0,
MTK_APUSYS_KERNEL_OP_SET_AO_DBG_SEL,
MTK_APUSYS_KERNEL_OP_NUM
};
#endif
@@ -0,0 +1,18 @@
#
# Copyright (C) 2020 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
ifeq (y, $(filter y, $(CONFIG_MACH_MT6877) ))
obj-y += new_arch/
else
obj-y += old_arch/
endif
@@ -0,0 +1,76 @@
#
# Copyright (C) 2019 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_MACH_MT6893),y)
PWR_PLAT=mt6885
else ifeq ($(CONFIG_MACH_MT6877),y)
PWR_PLAT=mt6877
else
PWR_PLAT=$(MTK_PLATFORM)
endif
# ------------------------------------------------------------------------------
# Initial flow
# ------------------------------------------------------------------------------
subdir-ccflags-y += -DINIT_MDLA_BY_SELF
#subdir-ccflags-y += -DBUILD_MODULE
# ------------------------------------------------------------------------------
# APUSYS ARCH : Legacy ARM version
# ------------------------------------------------------------------------------
subdir-ccflags-y += -DLEGACY_PROJ
ccflags-y += -I$(obj)/../../include/
ccflags-y += -I$(obj)/../../util/
ccflags-y += -I$(obj)/../../power/2.0/
ccflags-y += -I$(obj)/../../power/2.0/$(PWR_PLAT)/
ccflags-y += -I$(obj)/../../midware/1.1/
# ------------------------------------------------------------------------------
# APUSYS ARCH : uP version
# ------------------------------------------------------------------------------
#subdir-ccflags-y += -DRV_COMP
#
#ccflags-y += -I$(obj)/../util/
#ccflags-y += -I$(obj)/../power/3.0/
#ccflags-y += -I$(obj)/../power/3.0/$(PWR_PLAT)/
#
## Replace old apusys_device (Path : apusys/include -> apusys/mdla/dummy/)
#ccflags-y += -I$(obj)/dummy/
# ------------------------------------------------------------------------------
# GKI : MDLA only
# ------------------------------------------------------------------------------
src=$(srctree)/drivers/misc/mediatek/apusys/mdla
ccflags-y += -I$(src)/new_arch
obj-y += mdla.o
mdla-objs += $(shell cd $(src) && find new_arch -name "*.c" | sed 's/\.c/\.o/g')
# ------------------------------------------------------------------------------
# GKI : Copy following description to apusys/Makefile
# ------------------------------------------------------------------------------
# src=$(srctree)/drivers/misc/mediatek/apusys
# ccflags-y += -I$(src)/mdla/
# apusys-objs += $(shell cd $(src) && find mdla -name "*.c" | sed 's/\.c/\.o/g')
@@ -0,0 +1,111 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/types.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <utilities/mdla_debug.h>
static int mdla_cmd_dummy_run(struct mdla_run_cmd_sync *run_cmd,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd, uint32_t data)
{
mdla_cmd_debug("%s() !!!\n", __func__);
return 0;
}
static int mdla_cmd_dummy_ut_run_sync(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info)
{
mdla_cmd_debug("%s() !!!\n", __func__);
return 0;
}
static void mdla_cmd_dumy_lock_ops(struct mdla_dev *mdla_device) {}
static struct mdla_cmd_ops mdla_command = {
.run_sync = mdla_cmd_dummy_run,
.ut_run_sync = mdla_cmd_dummy_ut_run_sync,
.lock = mdla_cmd_dumy_lock_ops,
.unlock = mdla_cmd_dumy_lock_ops,
.list_lock = mdla_cmd_dumy_lock_ops,
.list_unlock = mdla_cmd_dumy_lock_ops,
};
static void mdla_cmd_lock(struct mdla_dev *mdla_device)
{
mutex_lock(&mdla_device->cmd_lock);
}
static void mdla_cmd_unlock(struct mdla_dev *mdla_device)
{
mutex_unlock(&mdla_device->cmd_lock);
}
static void mdla_cmd_list_lock(struct mdla_dev *mdla_device)
{
mutex_lock(&mdla_device->cmd_list_lock);
}
static void mdla_cmd_list_unlock(struct mdla_dev *mdla_device)
{
mutex_unlock(&mdla_device->cmd_list_lock);
}
void mdla_cmd_setup(run_sync_t sync, ut_run_sync_t ut_sync)
{
if (sync)
mdla_command.run_sync = sync;
if (ut_sync)
mdla_command.ut_run_sync = ut_sync;
mdla_command.lock = mdla_cmd_lock;
mdla_command.unlock = mdla_cmd_unlock;
mdla_command.list_lock = mdla_cmd_list_lock;
mdla_command.list_unlock = mdla_cmd_list_unlock;
}
const struct mdla_cmd_ops *mdla_cmd_ops_get(void)
{
return &mdla_command;
}
static bool mdla_cmd_check_dummp(uint64_t out_end,
struct command_entry *ce)
{
return false;
}
static int mdla_cmd_dummy_ops(u32 a0) { return 0; }
static unsigned long mdla_cmd_dummy_uint_int(u32 a0) { return 0; }
static void mdla_cmd_dummy_info(u32 a0) {}
static int mdla_cmd_dummy_ce_ops(u32 a0, struct command_entry *a1)
{
return 0;
}
static struct mdla_cmd_cb_func mdla_command_callback = {
.pre_cmd_handle = mdla_cmd_dummy_ce_ops,
.pre_cmd_info = mdla_cmd_dummy_info,
.check_cmd_valid = mdla_cmd_check_dummp,
.process_command = mdla_cmd_dummy_ce_ops,
.process_command_no_lock = mdla_cmd_dummy_ce_ops,
.post_cmd_handle = mdla_cmd_dummy_ce_ops,
.post_cmd_info = mdla_cmd_dummy_info,
.wait_cmd_handle = mdla_cmd_dummy_ce_ops,
.get_wait_time = mdla_cmd_dummy_uint_int,
.get_irq_num = mdla_cmd_dummy_ops,
.wait_cmd_hw_detect = mdla_cmd_dummy_ops,
.post_cmd_hw_detect = mdla_cmd_dummy_ops,
};
struct mdla_cmd_cb_func *mdla_cmd_plat_cb(void)
{
return &mdla_command_callback;
}
@@ -0,0 +1,60 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_CMD_PROC_H__
#define __MDLA_CMD_PROC_H__
#include <common/mdla_device.h>
struct apusys_cmd_hnd;
typedef int (*run_sync_t)(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority);
typedef int (*ut_run_sync_t)(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info);
/* command operations */
struct mdla_cmd_ops {
run_sync_t run_sync;
ut_run_sync_t ut_run_sync;
void (*lock)(struct mdla_dev *mdla_device);
void (*unlock)(struct mdla_dev *mdla_device);
void (*list_lock)(struct mdla_dev *mdla_device);
void (*list_unlock)(struct mdla_dev *mdla_device);
};
const struct mdla_cmd_ops *mdla_cmd_ops_get(void);
void mdla_cmd_setup(run_sync_t sync, ut_run_sync_t ut_sync);
/* platform callback functions */
struct mdla_cmd_cb_func {
int (*pre_cmd_handle)(u32 core_id, struct command_entry *ce);
void (*pre_cmd_info)(u32 core_id);
int (*process_command)(u32 core_id, struct command_entry *ce);
int (*process_command_no_lock)(u32 core_id, struct command_entry *ce);
int (*post_cmd_handle)(u32 core_id, struct command_entry *ce);
void (*post_cmd_info)(u32 core_id);
int (*wait_cmd_handle)(u32 core_id, struct command_entry *ce);
unsigned long (*get_wait_time)(u32 core_id);
int (*get_irq_num)(u32 core_id);
/* Check cmd is valid */
bool (*check_cmd_valid)(uint64_t out_end,
struct command_entry *ce);
/* HW error handing */
int (*wait_cmd_hw_detect)(u32 core_id);
int (*post_cmd_hw_detect)(u32 core_id);
};
struct mdla_cmd_cb_func *mdla_cmd_plat_cb(void);
#endif /* __MDLA_CMD_PROC_H__ */
@@ -0,0 +1,199 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_DEVICE_H__
#define __MDLA_DEVICE_H__
#include <linux/completion.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>
#include <linux/hrtimer.h>
#include <linux/list.h>
#include <linux/types.h>
#define MAX_CORE_NUM 16
struct device;
struct apusys_kmem;
struct mdla_run_cmd;
struct mdla_run_cmd_sync;
struct mdla_wait_cmd;
struct mdla_wait_entry;
struct mdla_pwr_ctrl;
struct mdla_prof_dev;
struct mdla_pmu_info;
struct mdla_scheduler;
enum REASON_ENUM {
REASON_MDLA_SUCCESS = 0,
REASON_MDLA_PREMPTED = 1,
REASON_MDLA_NULLPOINT = 2,
REASON_MDLA_TIMEOUT = 3,
REASON_MDLA_POWERON = 4,
REASON_MDLA_RETVAL_MAX,
};
enum MDLA_RESULT {
MDLA_SUCCESS = 0,
MDLA_TIMEOUT = 1,
};
enum command_entry_flags {
CE_NOP = 0x00,
CE_SYNC = 0x01,
CE_POLLING = 0x02,
};
enum command_entry_state {
CE_NONE = 0,
CE_QUEUE = 1,
CE_DEQUE = 2,
CE_RUN = 3,
CE_PREEMPTING = 4,
CE_SCHED = 5,
CE_PREEMPTED = 6,
CE_RESUMED = 7,
CE_DONE = 8,
CE_FIN = 9,
CE_TIMEOUT = 10,
CE_FAIL = 11,
CE_SKIP = 12,
CE_ISSUE_ERROR1 = 13,
CE_ISSUE_ERROR2 = 14,
CE_ISSUE_ERROR3 = 15,
CE_QUEUE_RESUME = 16,
};
enum interrupt_error {
IRQ_SUCCESS = 0,
IRQ_NO_SCHEDULER = 0x1,
IRQ_NO_PROCESSING_CE = 0x2,
IRQ_NO_WRONG_DEQUEUE_STATUS = 0x4,
IRQ_TWICE = 0x8,
IRQ_N_EMPTY_IN_ISSUE = 0x10,
IRQ_N_EMPTY_IN_SCHED = 0x20,
IRQ_NE_ISSUE_FIRST = 0x40,
IRQ_NE_SCHED_FIRST = 0x80,
IRQ_IN_IRQ = 0x100,
IRQ_NOT_IN_IRQ = 0x200,
IRQ_TIMEOUT = 0x400,
IRQ_RECORD_ERROR = 0x800,
};
enum REASON_QUEUE_STATE_ENUM {
REASON_QUEUE_NOCHANGE = 0,
REASON_QUEUE_NORMALEXE = 1,
REASON_QUEUE_PREEMPTION = 2,
REASON_QUEUE_NULLSCHEDULER = 3,
REASON_QUEUE_MAX,
};
enum MDLA_STATUS_TYPE {
MDLA_FREE = 0x0,
MDLA_GOTO_STOP = 0x1,
MDLA_STOP = 0x2,
MDLA_RUN = 0x3,
MDLA_SMP_PROP = 0x100,
};
/*mdla dev info, register to apusys callback*/
struct mdla_dev {
u32 mdla_id;
struct device *dev;
u32 max_cmd_id;
struct mutex cmd_lock;
struct list_head cmd_list;
struct mutex cmd_list_lock;
struct completion command_done;
spinlock_t hw_lock;
/* power */
struct mdla_pwr_ctrl *power;
u32 cmd_list_cnt;
bool power_is_on;
bool sw_power_is_on;
/* profile*/
struct mdla_prof_dev *prof;
/* pmu */
struct mdla_pmu_dev *pmu_dev;
struct mdla_pmu_info *pmu_info;
/* platform */
void *cmd_buf_dmp;
size_t cmd_buf_len;
struct mutex cmd_buf_dmp_lock;
/* SW preemption */
struct mdla_scheduler *sched;
/* SMP HW preemption*/
uint32_t status;
spinlock_t stat_lock;
u32 error_bit;
};
struct command_entry {
struct list_head node;
struct completion swcmd_done_wait; /* the completion for CE finish */
struct completion preempt_wait; /* the completion for normal CE */
int flags;
int state;
u32 irq_state;
u64 footprint;
int sync;
void *kva; /* Virtual Address for Kernel */
u32 mva; /* Physical Address for Device */
u32 count;
u32 csn;
int boost_val;
u32 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 start time (ns) */
u64 req_end_t; /* request end time (ns) */
u64 exec_time; /* HW execution time (ns) */
u64 wait_t; /* time waited by user */
u64 cmd_id;
u32 multicore_total;
u64 deadline_t;
u32 fin_cid; /* record the last finished command id */
u32 wish_fin_cid;
struct apusys_kmem *cmdbuf;
int ctx_id;
int (*context_callback)(int a, int b, unsigned char c);
/* SW preemption information */
u32 priority;
u32 cmd_batch_size; /* command batch size */
bool cmd_batch_en; /* enable command batch or not */
struct list_head *batch_list_head;/* list of command batch */
u32 *cmd_int_backup; /* backup MREG_CMD_TILE_CNT_INT */
u32 *cmd_ctrl_1_backup; /* backup MREG_CMD_GENERAL_CTRL_1 */
/* HW preemption information */
u32 hw_sync0;
u32 hw_sync1;
u32 hw_sync2;
u32 hw_sync3;
};
struct mdla_dev *mdla_get_device(int id);
void mdla_set_device(struct mdla_dev *dev, u32 num);
#endif /* __MDLA_DEVICE_H__ */
@@ -0,0 +1,410 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/cdev.h>
#include <linux/of_device.h>
#include <linux/types.h>
#include <apusys_device.h>
#include <common/mdla_driver.h>
#include <common/mdla_device.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_ioctl.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <linux/dma-mapping.h>
static struct apusys_device *apusys_dev_mdla;
static struct apusys_device *apusys_dev_mdla_rt;
static bool apusys_mdla_rt_support(void)
{
return DEVICE_MDLA != DEVICE_MDLA_RT;
}
static int apusys_mdla_handler(int type,
void *hnd, struct apusys_device *dev)
{
int ret = 0;
struct mdla_dev *mdla_info;
struct apusys_cmd_hnd *cmd_hnd;
struct mdla_run_cmd_sync *cmd_data;
if (unlikely(!dev || !(dev->private)))
return -EINVAL;
mdla_info = (struct mdla_dev *)dev->private;
if (dev->dev_type != DEVICE_MDLA)
return -EINVAL;
if (unlikely(mdla_info->mdla_id >= mdla_util_get_core_num()))
return -EINVAL;
switch (type) {
case APUSYS_CMD_POWERON:
ret = mdla_pwr_ops_get()->on(mdla_info->mdla_id, true);
break;
case APUSYS_CMD_POWERDOWN:
ret = mdla_pwr_ops_get()->off(mdla_info->mdla_id, 0, true);
break;
case APUSYS_CMD_RESUME:
break;
case APUSYS_CMD_SUSPEND:
ret = mdla_pwr_ops_get()->off(mdla_info->mdla_id, 1, true);
break;
case APUSYS_CMD_EXECUTE:
cmd_hnd = hnd;
cmd_data = (struct mdla_run_cmd_sync *)cmd_hnd->kva;
if (unlikely(!cmd_hnd || !cmd_data))
return -ENODEV;
ret = mdla_cmd_ops_get()->run_sync(
cmd_data,
mdla_info,
cmd_hnd,
MDLA_LOW_PRIORITY);
break;
case APUSYS_CMD_PREEMPT:
ret = -EINVAL;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static int apusys_mdla_rt_handler(int type,
void *hnd, struct apusys_device *dev)
{
int ret;
struct apusys_cmd_hnd *cmd_hnd;
struct mdla_dev *mdla_info;
struct mdla_run_cmd_sync *cmd_data;
if (type != APUSYS_CMD_EXECUTE)
return 0;
cmd_hnd = hnd;
if (unlikely(!cmd_hnd || !dev))
return -EINVAL;
cmd_data = (struct mdla_run_cmd_sync *)cmd_hnd->kva;
mdla_info = (struct mdla_dev *)dev->private;
if (unlikely(!mdla_info || !cmd_data))
return -ENODEV;
if (dev->dev_type != DEVICE_MDLA_RT)
return -EINVAL;
if (unlikely(mdla_info->mdla_id >= mdla_util_get_core_num()))
return -EINVAL;
ret = mdla_cmd_ops_get()->run_sync(
cmd_data,
mdla_info,
cmd_hnd,
MDLA_HIGH_PRIORITY);
return ret;
}
#define MDLA_DEVICE_NAME "mdlactl"
#define MDLA_CLASS_NAME "mdla"
static dev_t mdlactl_dev_num;
static struct cdev *mdlactl_cdev;
static struct class *mdlactl_class;
static struct device *mdlactl_device;
static void mdla_drv_unregister_char_dev(void)
{
cdev_del(mdlactl_cdev);
unregister_chrdev_region(mdlactl_dev_num, 1);
}
static int mdla_drv_register_char_dev(struct device *dev)
{
int ret = 0;
/* Register a range of char device numbers */
ret = alloc_chrdev_region(&mdlactl_dev_num, 0, 1, MDLA_DEVICE_NAME);
if (ret < 0) {
dev_info(dev, "alloc_chrdev_region failed, %d\n", ret);
goto out;
}
/* Allocate a char device structure */
mdlactl_cdev = cdev_alloc();
if (!mdlactl_cdev) {
dev_info(dev, "cdev_alloc failed\n");
ret = -ENOMEM;
goto err_cdev;
}
cdev_init(mdlactl_cdev, mdla_ioctl_get_fops());
mdlactl_cdev->owner = THIS_MODULE;
/* Add a char device to the system */
ret = cdev_add(mdlactl_cdev, mdlactl_dev_num, 1);
if (ret < 0) {
dev_info(dev, "Attatch file operation failed, %d\n", ret);
goto err_cdev_add;
}
dev_info(dev, "Registered cdev with major/minor number %d\n",
mdlactl_dev_num);
return 0;
err_cdev_add:
cdev_del(mdlactl_cdev);
err_cdev:
unregister_chrdev_region(mdlactl_dev_num, 1);
out:
return ret;
}
int mdla_drv_create_device_node(struct device *dev)
{
int ret = 0;
if (mdlactl_cdev) {
ret = -1;
dev_info(dev, "%s() Has registered character device!\n",
__func__);
goto out;
}
/* 1. Register character driver */
ret = mdla_drv_register_char_dev(dev);
if (ret < 0)
goto out;
/* 2. Create a class structure. It's used in calls to device_create() */
mdlactl_class = class_create(THIS_MODULE, MDLA_CLASS_NAME);
if (IS_ERR(mdlactl_class)) {
dev_info(dev, "Failed to register device class\n");
ret = PTR_ERR(mdlactl_class);
goto err_class;
}
/* 3. Creates a device and registers it with sysfs */
mdlactl_device = device_create(mdlactl_class, NULL,
mdlactl_dev_num, NULL, MDLA_DEVICE_NAME);
if (IS_ERR(mdlactl_device)) {
dev_info(dev, "Failed to create the device\n");
ret = PTR_ERR(mdlactl_device);
goto err_devive;
}
/* 4. Init DMA from of */
of_dma_configure(mdlactl_device, NULL, true);
/* 5. Set DMA mask */
ret = dma_get_mask(mdlactl_device);
if (ret < 0 || ret != DMA_BIT_MASK(32)) {
ret = dma_set_mask_and_coherent(mdlactl_device,
DMA_BIT_MASK(32));
if (ret)
dev_info(dev, "MDLA: set DMA mask failed: %d\n", ret);
}
return 0;
err_devive:
class_destroy(mdlactl_class);
err_class:
mdla_drv_unregister_char_dev();
out:
return ret;
}
void mdla_drv_destroy_device_node(void)
{
if (mdlactl_device) {
device_destroy(mdlactl_class, mdlactl_dev_num);
mdlactl_device = NULL;
}
if (mdlactl_class) {
class_destroy(mdlactl_class);
mdlactl_class = NULL;
}
if (mdlactl_cdev) {
mdla_drv_unregister_char_dev();
mdlactl_cdev = NULL;
}
}
static int mdla_probe(struct platform_device *pdev)
{
int i, ret = 0;
struct device *dev = &pdev->dev;
struct apusys_device *adev_mdla;
struct apusys_device *adev_mdla_rt;
struct mdla_dev *mdev;
if (mdla_pwr_apusys_disabled())
return -1;
/* Initialize platform to allocate mdla devices first. */
ret = mdla_util_plat_init(pdev);
if (ret < 0) {
dev_info(dev, "platform init failed\n");
return -EINVAL;
} else if (ret == 1) {
dev_info(dev, "%s: uP version done\n", __func__);
return 0;
}
apusys_dev_mdla = kcalloc(mdla_util_get_core_num(),
sizeof(struct apusys_device),
GFP_KERNEL);
if (!apusys_dev_mdla) {
ret = -ENOMEM;
goto err;
}
apusys_dev_mdla_rt = kcalloc(mdla_util_get_core_num(),
sizeof(struct apusys_device),
GFP_KERNEL);
if (!apusys_dev_mdla_rt) {
ret = -ENOMEM;
goto err_dev_mdla_rt;
}
for_each_mdla_core(i) {
mdev = mdla_get_device(i);
adev_mdla = &apusys_dev_mdla[i];
adev_mdla_rt = &apusys_dev_mdla_rt[i];
adev_mdla->dev_type = DEVICE_MDLA;
adev_mdla->preempt_type = APUSYS_PREEMPT_NONE;
adev_mdla->private = mdev;
adev_mdla->send_cmd = apusys_mdla_handler;
ret = apusys_register_device(adev_mdla);
if (ret) {
dev_info(dev, "register apusys mdla %d fail\n", i);
goto err_apusys;
}
if (!apusys_mdla_rt_support())
continue;
adev_mdla_rt->dev_type = DEVICE_MDLA_RT;
adev_mdla_rt->preempt_type = APUSYS_PREEMPT_NONE;
adev_mdla_rt->private = mdev;
adev_mdla_rt->send_cmd = apusys_mdla_rt_handler;
ret = apusys_register_device(adev_mdla_rt);
if (ret) {
dev_info(dev, "register apusys mdla RT %d fail\n", i);
apusys_unregister_device(adev_mdla);
goto err_apusys;
}
}
dev_info(dev, "%s: done\n", __func__);
return 0;
err_apusys:
for (i = i - 1; i >= 0; i--) {
apusys_unregister_device(&apusys_dev_mdla[i]);
if (apusys_mdla_rt_support())
apusys_unregister_device(&apusys_dev_mdla_rt[i]);
}
kfree(apusys_dev_mdla_rt);
err_dev_mdla_rt:
kfree(apusys_dev_mdla);
err:
mdla_util_plat_deinit(pdev);
return ret;
}
static int mdla_remove(struct platform_device *pdev)
{
int i;
if (mdla_pwr_apusys_disabled())
return 0;
dev_info(&pdev->dev, "%s start -\n", __func__);
for_each_mdla_core(i) {
apusys_unregister_device(&apusys_dev_mdla[i]);
if (apusys_mdla_rt_support())
apusys_unregister_device(&apusys_dev_mdla_rt[i]);
}
kfree(apusys_dev_mdla_rt);
kfree(apusys_dev_mdla);
mdla_util_plat_deinit(pdev);
platform_set_drvdata(pdev, NULL);
dev_info(&pdev->dev, "%s done -\n", __func__);
return 0;
}
static int mdla_resume(struct platform_device *pdev)
{
dev_info(&pdev->dev, "%s()\n", __func__);
return 0;
}
static int mdla_suspend(struct platform_device *pdev, pm_message_t mesg)
{
int i;
for_each_mdla_core(i)
mdla_pwr_ops_get()->off(i, 1, true);
dev_info(&pdev->dev, "%s()\n", __func__);
return 0;
}
static struct platform_driver mdla_driver = {
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
},
.probe = mdla_probe,
.remove = mdla_remove,
.suspend = mdla_suspend,
.resume = mdla_resume,
};
int mdla_drv_init(void)
{
mdla_driver.driver.of_match_table = mdla_util_get_device_id();
return platform_driver_register(&mdla_driver);
}
void mdla_drv_exit(void)
{
platform_driver_unregister(&mdla_driver);
}
@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_DRIVER_H__
#define __MDLA_DRIVER_H__
#include <linux/types.h>
#include <apusys_device.h>
#define DRIVER_NAME "mtk_mdla"
#if IS_ENABLED(CONFIG_MTK_APUSYS_RT_SUPPORT)
#define DEVICE_MDLA APUSYS_DEVICE_MDLA
#define DEVICE_MDLA_RT APUSYS_DEVICE_MDLA_RT
#else
#define DEVICE_MDLA APUSYS_DEVICE_MDLA
#define DEVICE_MDLA_RT APUSYS_DEVICE_MDLA
#endif
struct device;
int mdla_drv_create_device_node(struct device *dev);
void mdla_drv_destroy_device_node(void);
int mdla_drv_init(void);
void mdla_drv_exit(void);
#endif /* __MDLA_DRIVER_H__ */
@@ -0,0 +1,167 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/uaccess.h>
#include <common/mdla_device.h>
#include <common/mdla_ioctl.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_util.h>
static int (*mdla_ioctl_perf)(struct file *filp,
u32 command, unsigned long arg, bool need_pwr_on);
static long mdla_ioctl_config(unsigned long arg)
{
long retval = 0;
struct ioctl_config cfg;
if (copy_from_user(&cfg, (void *) arg, sizeof(cfg)))
return -EFAULT;
switch (cfg.op) {
case MDLA_CFG_NONE:
break;
case MDLA_CFG_TIMEOUT_GET:
cfg.arg[0] = mdla_dbg_read_u32(FS_TIMEOUT);
cfg.arg_count = 1;
break;
case MDLA_CFG_TIMEOUT_SET:
if (cfg.arg_count == 1)
mdla_dbg_write_u32(FS_TIMEOUT, cfg.arg[0]);
break;
case MDLA_CFG_FIFO_SZ_GET:
cfg.arg[0] = 1;
cfg.arg_count = 1;
break;
case MDLA_CFG_FIFO_SZ_SET:
return -EINVAL;
case MDLA_CFG_GSM_INFO:
break;
default:
return -EINVAL;
}
if (copy_to_user((void *) arg, &cfg, sizeof(cfg)))
return -EFAULT;
return retval;
}
static long mdla_ioctl(struct file *filp, unsigned int command,
unsigned long arg)
{
long retval = 0;
struct ioctl_run_cmd_sync cmd_data_sync;
switch (command) {
case IOCTL_MALLOC:
case IOCTL_FREE:
case IOCTL_ION_KMAP:
case IOCTL_ION_KUNMAP:
mdla_err("%s: Not support memory control\n", __func__);
break;
case IOCTL_RUN_CMD_SYNC:
if (copy_from_user(&cmd_data_sync, (void *) arg,
sizeof(cmd_data_sync))) {
return -EFAULT;
}
mdla_cmd_debug("%s: RUN_CMD_SYNC: core_id=%d, kva=%p, mva=0x%08x, phys_to_virt=%p\n",
__func__,
cmd_data_sync.mdla_id,
(void *)cmd_data_sync.req.buf.kva,
cmd_data_sync.req.buf.mva,
phys_to_virt(cmd_data_sync.req.buf.mva));
if (core_id_is_invalid(cmd_data_sync.mdla_id))
return -EFAULT;
retval = mdla_cmd_ops_get()->ut_run_sync(&cmd_data_sync.req,
&cmd_data_sync.res,
mdla_get_device(cmd_data_sync.mdla_id));
if (copy_to_user((void *) arg,
&cmd_data_sync, sizeof(cmd_data_sync)))
return -EFAULT;
break;
case IOCTL_RUN_CMD_ASYNC:
case IOCTL_WAIT_CMD:
/* Not support command type */
break;
case IOCTL_PERF_SET_EVENT:
case IOCTL_PERF_GET_EVENT:
case IOCTL_PERF_GET_CNT:
case IOCTL_PERF_UNSET_EVENT:
case IOCTL_PERF_RESET_CNT:
case IOCTL_PERF_RESET_CYCLE:
case IOCTL_PERF_SET_MODE:
if (mdla_ioctl_perf)
retval = mdla_ioctl_perf(filp, command, arg, true);
break;
case IOCTL_PERF_GET_START:
case IOCTL_PERF_GET_END:
case IOCTL_PERF_GET_CYCLE:
if (mdla_ioctl_perf)
retval = mdla_ioctl_perf(filp, command, arg, false);
break;
case IOCTL_CONFIG:
return mdla_ioctl_config(arg);
default:
return -EINVAL;
}
return retval;
}
static long mdla_compat_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
return mdla_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
}
static int mdla_open(struct inode *inodep, struct file *filep)
{
mdla_drv_debug("%s(): Device has been opened\n", __func__);
return 0;
}
static int mdla_release(struct inode *inodep, struct file *filep)
{
mdla_drv_debug("%s(): Device successfully closed\n", __func__);
return 0;
}
static const struct file_operations fops = {
.open = mdla_open,
.unlocked_ioctl = mdla_ioctl,
.compat_ioctl = mdla_compat_ioctl,
.release = mdla_release,
};
const struct file_operations *mdla_ioctl_get_fops(void)
{
return &fops;
}
void mdla_ioctl_register_perf_handle(int (*pmu_ioctl)(struct file *filp,
u32 command,
unsigned long arg,
bool need_pwr_on))
{
if (pmu_ioctl)
mdla_ioctl_perf = pmu_ioctl;
}
void mdla_ioctl_unregister_perf_handle(void)
{
mdla_ioctl_perf = NULL;
}
@@ -0,0 +1,218 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_IOCTL__
#define __MDLA_IOCTL__
#include <stdbool.h>
#include <linux/ioctl.h>
#include <linux/types.h>
#ifndef __KERNEL__
#include <stdint.h>
#endif
/* 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 {
uint32_t size; /* [in] allocate size */
uint32_t mva; /* [out] modified virtual address */
void *pa; /* [out] physical address */
void *kva; /* [out] kernel virtual address */
uint8_t 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;
int32_t ion_share_fd;
int32_t ion_handle; /* user space handle */
uint64_t ion_khandle; /* kernel space handle */
} buf;
uint32_t offset; /* [in] command byte offset in buf */
uint32_t count; /* [in] # of commands */
uint32_t id; /* [out] command id */
uint8_t priority; /* [in] dvfs priority */
uint8_t 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 {
uint32_t id; /* [in] command id */
int32_t 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;
uint32_t mdla_id;
};
struct ioctl_perf {
int32_t handle;
uint32_t interface;
uint32_t event;
uint32_t counter;
uint32_t start;
uint32_t end;
uint32_t mode;
uint32_t mdlaid;
};
struct ioctl_ion {
int32_t fd; /* [in] user handle, eq. ion_user_handle_t */
uint64_t mva; /* [in] phyiscal address */
uint64_t kva; /* [in(unmap)/out(map)] kernel virtual address */
uint64_t 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 {
uint32_t op;
uint32_t arg_count;
uint64_t arg[8];
};
struct mdla_power {
uint8_t boost_value;
/* align with core index defined in user space header file */
uint32_t core_id;
};
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 {
uint32_t 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)
const struct file_operations *mdla_ioctl_get_fops(void);
void mdla_ioctl_register_perf_handle(int (*pmu_ioctl)(struct file *filp,
unsigned int command,
unsigned long arg,
bool need_pwr_on));
void mdla_ioctl_unregister_perf_handle(void);
#endif /* __MDLA_IOCTL__ */
@@ -0,0 +1,94 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <common/mdla_driver.h>
#include <common/mdla_device.h>
#include <utilities/mdla_debug.h>
struct apusys_core_info;
static struct mdla_dev *mdla_devices;
static u32 mdla_device_num;
struct mdla_dev *mdla_get_device(int id)
{
if (unlikely(id >= mdla_device_num || !mdla_devices))
return NULL;
return &mdla_devices[id];
}
void mdla_set_device(struct mdla_dev *dev, u32 num)
{
mdla_devices = dev;
mdla_device_num = num;
}
int mdla_init(struct apusys_core_info *info)
{
mdla_dbg_fs_init(NULL);
/* Register platform driver after debugfs initialization */
if (mdla_drv_init()) {
mdla_dbg_fs_exit();
return -1;
}
pr_info("%s() done\n", __func__);
return 0;
}
void mdla_exit(void)
{
mdla_dbg_fs_exit();
mdla_drv_exit();
pr_info("%s()!!\n", __func__);
}
#ifdef RV_COMP
int mdla_post_init(void)
{
return mdla_init(NULL);
}
void mdla_post_exit(void)
{
mdla_exit();
}
#endif
#ifdef INIT_MDLA_BY_SELF
#ifdef BUILD_MODULE
static int mdla_mod_init(void)
{
return mdla_init(NULL);
}
static void mdla_mod_exit(void)
{
mdla_exit();
}
module_init(mdla_mod_init);
module_exit(mdla_mod_exit);
MODULE_DESCRIPTION("MDLA Driver");
MODULE_AUTHOR("SPT1/SS5");
MODULE_LICENSE("GPL");
#else
static int mdla_mod_init(void)
{
return mdla_init(NULL);
}
late_initcall(mdla_mod_init);
#endif
#endif
@@ -0,0 +1,418 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/kernel.h>
#include <linux/mutex.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/of_device.h>
#include <linux/pm_wakeup.h>
#include <linux/sched/clock.h>
#include <linux/slab.h>
#include <linux/random.h>
#include <linux/seq_file.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <apusys_power.h>
#include <common/mdla_device.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_profile.h>
#define get_pwr_id(core_id) (MDLA0 + core_id)
struct mdla_pwr_ctrl {
int mdla_id;
struct mutex lock;
struct wakeup_source *wakeup;
struct timer_list power_off_timer;
struct work_struct power_off_work;
void (*power_off_cb_func)(struct work_struct *work);
};
static int mdla_pwr_dummy_on(u32 core_id, bool force)
{
mdla_pwr_ops_get()->hw_reset(core_id,
mdla_dbg_get_reason_str(REASON_SIMULATOR));
return 0;
}
static int mdla_pwr_dummy_off(u32 core_id, int suspend, bool force)
{
return 0;
}
static void mdla_pwr_dummy_hw_reset(u32 core_id, const char *str) {}
static void mdla_pwr_dummy_opp(u32 a0, int a1) {}
static void mdla_pwr_dummy_lock(u32 a0) {}
static void mdla_pwr_dummy_ops(u32 a0) {}
static struct mdla_pwr_ops mdla_power = {
.on = mdla_pwr_dummy_on,
.off = mdla_pwr_dummy_off,
.off_timer_start = mdla_pwr_dummy_ops,
.off_timer_cancel = mdla_pwr_dummy_ops,
.set_opp = mdla_pwr_dummy_opp,
.set_opp_by_boost = mdla_pwr_dummy_opp,
.switch_off_on = mdla_pwr_dummy_ops,
.hw_reset = mdla_pwr_dummy_hw_reset,
.lock = mdla_pwr_dummy_lock,
.unlock = mdla_pwr_dummy_lock,
.wake_lock = mdla_pwr_dummy_lock,
.wake_unlock = mdla_pwr_dummy_lock,
};
static void mdla_pwr_timeup(struct timer_list *timer)
{
struct mdla_pwr_ctrl *pwr_ctrl;
pwr_ctrl = container_of(timer, struct mdla_pwr_ctrl, power_off_timer);
schedule_work(&pwr_ctrl->power_off_work);
}
static void mdla_pwr_off(struct work_struct *work)
{
struct mdla_pwr_ctrl *pwr_ctrl;
pwr_ctrl = container_of(work, struct mdla_pwr_ctrl, power_off_work);
mdla_power.off(pwr_ctrl->mdla_id, 0, false);
}
static void mdla_pwr_off_timer_start(u32 core_id)
{
u32 poweroff_time = mdla_dbg_read_u32(FS_POWEROFF_TIME);
struct mdla_dev *mdla_device = mdla_get_device(core_id);
struct mdla_pwr_ctrl *pwr_ctrl = mdla_device->power;
mutex_lock_nested(&pwr_ctrl->lock, core_id);
if (mdla_device->cmd_list_cnt > 0)
mdla_device->cmd_list_cnt--;
if (mdla_device->cmd_list_cnt == 0)
mdla_prof_stop(core_id, 1);
if (poweroff_time) {
mdla_pwr_debug("%s: MDLA %d start power_timer\n",
__func__, core_id);
mod_timer(&pwr_ctrl->power_off_timer,
jiffies + msecs_to_jiffies(poweroff_time));
}
mutex_unlock(&pwr_ctrl->lock);
}
static void mdla_pwr_off_timer_cancel(u32 core_id)
{
struct mdla_pwr_ctrl *pwr_ctrl = mdla_get_device(core_id)->power;
if (timer_pending(&pwr_ctrl->power_off_timer))
del_timer(&pwr_ctrl->power_off_timer);
}
static void mdla_pwr_set_opp(u32 core_id, int opp)
{
apu_device_set_opp(get_pwr_id(core_id), opp);
}
static void mdla_pwr_set_opp_by_boost(u32 core_id, int boost_val)
{
unsigned char mdla_opp = 0;
mdla_opp = apusys_boost_value_to_opp(get_pwr_id(core_id), (unsigned char)boost_val);
apu_device_set_opp(get_pwr_id(core_id), mdla_opp);
mdla_pwr_debug("core: %d, opp: %d\n", core_id, mdla_opp);
}
static void mdla_pwr_switch_off_on(u32 core_id)
{
struct mdla_pwr_ctrl *pwr_ctrl = mdla_get_device(core_id)->power;
mutex_lock_nested(&pwr_ctrl->lock, core_id);
if (apu_device_power_off(get_pwr_id(core_id))
|| apu_device_power_on(get_pwr_id(core_id)))
mdla_err("%s: fail\n", __func__);
mutex_unlock(&pwr_ctrl->lock);
}
static void mdla_pwr_lock(u32 core_id)
{
mutex_lock_nested(&mdla_get_device(core_id)->power->lock, core_id);
}
static void mdla_pwr_unlock(u32 core_id)
{
mutex_unlock(&mdla_get_device(core_id)->power->lock);
}
static void mdla_pwr_wake_lock(u32 core_id)
{
__pm_stay_awake(mdla_get_device(core_id)->power->wakeup);
}
static void mdla_pwr_wake_unlock(u32 core_id)
{
__pm_relax(mdla_get_device(core_id)->power->wakeup);
}
static int mdla_dbg_pwr_show(struct seq_file *s, void *data)
{
int i;
struct mdla_dev *mdla_device;
for_each_mdla_core(i) {
mdla_device = mdla_get_device(i);
seq_printf(s, "---- core %d ----\n", i);
seq_printf(s, "apu power status = %d\n", apu_get_power_on_status(get_pwr_id(i)));
seq_printf(s, "power_is_on = %d\n", mdla_device->power_is_on);
seq_printf(s, "sw_power_is_on = %d\n", mdla_device->sw_power_is_on);
seq_printf(s, "cmd_list_cnt = %d\n", mdla_device->cmd_list_cnt);
}
seq_printf(s, "\nRandom opp test: %u\n", mdla_dbg_read_u32(FS_DVFS_RAND));
seq_puts(s, "\n==== usage ====\n");
seq_printf(s, "echo [param] > /d/mdla/%s\n", DBGFS_PWR_NAME);
seq_puts(s, "\tparam:\n");
seq_puts(s, "\t 0: force all core power off\n");
seq_puts(s, "\t 1: force all core power on\n");
seq_printf(s, "echo [0|1] > /d/mdla/%s\n", mdla_dbg_get_u32_node_str(FS_DVFS_RAND));
seq_puts(s, "\tEnable/Disable random opp test\n");
return 0;
}
static int mdla_dbg_pwr_open(struct inode *inode, struct file *file)
{
return single_open(file, mdla_dbg_pwr_show, inode->i_private);
}
static ssize_t mdla_dbg_pwr_write(struct file *flip,
const char __user *buffer,
size_t count, loff_t *f_pos)
{
char *buf;
u32 param;
int i, ret;
buf = kzalloc(count + 1, GFP_KERNEL);
if (!buf)
return -ENOMEM;
ret = copy_from_user(buf, buffer, count);
if (ret)
goto out;
buf[count] = '\0';
if (kstrtouint(buf, 10, &param) != 0) {
ret = -EINVAL;
goto out;
}
for_each_mdla_core(i) {
if (param == 0)
mdla_pwr_ops_get()->off(i, 0, true);
else if (param == 1)
mdla_pwr_ops_get()->on(i, true);
}
out:
kfree(buf);
return count;
}
static const struct file_operations mdla_dbg_pwr_fops = {
.open = mdla_dbg_pwr_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = mdla_dbg_pwr_write,
};
static void mdla_pwr_fs_init(void)
{
struct dentry *d = mdla_dbg_get_fs_root();
if (d)
debugfs_create_file(DBGFS_PWR_NAME, 0644, d, NULL,
&mdla_dbg_pwr_fops);
}
const struct mdla_pwr_ops *mdla_pwr_ops_get(void)
{
return &mdla_power;
}
int mdla_pwr_get_random_boost_val(void)
{
int val;
/**
* Get opp 0 only when boost_val is 100
* Using division of 128 to increase probabiliy of getting opp 0
*/
val = (get_random_int() & 0x7F) + 1;
return val > 100 ? 100 : val;
}
bool mdla_pwr_apusys_disabled(void)
{
return !apusys_power_check();
}
void mdla_pwr_reset_setup(void (*hw_reset)(u32 core_id, const char *str))
{
if (hw_reset)
mdla_power.hw_reset = hw_reset;
}
#ifdef LEGACY_PROJ
struct apu_dev_power_data {
int dev_type;
int dev_core;
void *data;
};
#endif
int mdla_pwr_device_register(struct platform_device *pdev,
int (*on)(u32 core_id, bool force),
int (*off)(u32 core_id, int suspend, bool force))
{
int i, ret = 0;
enum DVFS_USER user_mdla;
struct mdla_dev *mdla_device;
struct mdla_pwr_ctrl *pwr_ctrl;
struct apu_dev_power_data *pwr_data;
mdla_drv_debug("probe 0, pdev id = %d name = %s, name = %s\n",
pdev->id, pdev->name,
pdev->dev.of_node->name);
pwr_data = kzalloc(sizeof(struct apu_dev_power_data), GFP_KERNEL);
if (!pwr_data)
return -1;
/* Only one platform_device */
pwr_data->dev_type = MDLA0;
pwr_data->dev_core = 0;
platform_set_drvdata(pdev, pwr_data);
for_each_mdla_core(i) {
user_mdla = get_pwr_id(i);
ret = apu_power_device_register(user_mdla, pdev);
if (!ret) {
mdla_drv_debug("%s register power device %d success\n",
__func__,
user_mdla);
} else {
mdla_err("%s register power device %d fail\n",
__func__,
user_mdla);
goto reg_pwr_err;
}
}
if ((on == NULL) && (off == NULL))
return 0;
for_each_mdla_core(i) {
pwr_ctrl = kzalloc(sizeof(struct mdla_pwr_ctrl), GFP_KERNEL);
if (!pwr_ctrl)
goto alloc_err;
pwr_ctrl->mdla_id = i;
mutex_init(&pwr_ctrl->lock);
#ifdef IS_KERNEL_4_14
pwr_ctrl->power_off_timer.data = i;
pwr_ctrl->power_off_timer.function = mdla_pwr_timeup;
init_timer(&pwr_ctrl->power_off_timer);
#else
timer_setup(&pwr_ctrl->power_off_timer, mdla_pwr_timeup, 0);
#endif
pwr_ctrl->power_off_cb_func = mdla_pwr_off;
INIT_WORK(&pwr_ctrl->power_off_work,
pwr_ctrl->power_off_cb_func);
#ifdef RV_COMP /* No backporting to kernel-4.14 */
pwr_ctrl->wakeup = wakeup_source_register("mdla");
#else
pwr_ctrl->wakeup = wakeup_source_register(NULL, "mdla");
#endif
if (!pwr_ctrl->wakeup)
mdla_err("mdla%d wakelock register fail!\n", i);
mdla_device = mdla_get_device(i);
mdla_device->power = pwr_ctrl;
mdla_device->power_is_on = false;
mdla_device->sw_power_is_on = false;
}
if (on)
mdla_power.on = on;
if (off)
mdla_power.off = off;
mdla_power.set_opp = mdla_pwr_set_opp;
mdla_power.set_opp_by_boost = mdla_pwr_set_opp_by_boost;
mdla_power.switch_off_on = mdla_pwr_switch_off_on;
mdla_power.off_timer_start = mdla_pwr_off_timer_start;
mdla_power.off_timer_cancel = mdla_pwr_off_timer_cancel;
mdla_power.lock = mdla_pwr_lock;
mdla_power.unlock = mdla_pwr_unlock;
mdla_power.wake_lock = mdla_pwr_wake_lock;
mdla_power.wake_unlock = mdla_pwr_wake_unlock;
mdla_pwr_fs_init();
return 0;
alloc_err:
for (i = i - 1; i >= 0; i--) {
pwr_ctrl = mdla_get_device(i)->power;
wakeup_source_unregister(pwr_ctrl->wakeup);
mutex_destroy(&pwr_ctrl->lock);
kfree(pwr_ctrl);
mdla_get_device(i)->power = NULL;
}
i = mdla_util_get_core_num();
reg_pwr_err:
for (i = i - 1; i >= 0; i--)
apu_power_device_unregister(get_pwr_id(i));
kfree(pwr_data);
return -1;
}
int mdla_pwr_device_unregister(struct platform_device *pdev)
{
struct mdla_pwr_ctrl *pwr_ctrl;
int i;
for_each_mdla_core(i)
mdla_power.off(i, 0, true);
for_each_mdla_core(i) {
apu_power_device_unregister(get_pwr_id(i));
pwr_ctrl = mdla_get_device(i)->power;
if (!pwr_ctrl)
continue;
wakeup_source_unregister(pwr_ctrl->wakeup);
mutex_destroy(&pwr_ctrl->lock);
kfree(pwr_ctrl);
}
kfree(platform_get_drvdata(pdev));
return 0;
}
@@ -0,0 +1,39 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_POWER_CTRL_H__
#define __MDLA_POWER_CTRL_H__
#include <linux/types.h>
#include <linux/platform_device.h>
#define DBGFS_PWR_NAME "pwr_dbg"
struct mdla_pwr_ops {
int (*on)(u32 core_id, bool force);
int (*off)(u32 core_id, int suspend, bool force);
void (*off_timer_start)(u32 core_id);
void (*off_timer_cancel)(u32 core_id);
void (*set_opp)(u32 core_id, int opp);
void (*set_opp_by_boost)(u32 core_id, int boost_val);
void (*switch_off_on)(u32 core_id);
void (*hw_reset)(u32 core_id, const char *str);
void (*lock)(u32 core_id);
void (*unlock)(u32 core_id);
void (*wake_lock)(u32 core_id);
void (*wake_unlock)(u32 core_id);
};
const struct mdla_pwr_ops *mdla_pwr_ops_get(void);
int mdla_pwr_get_random_boost_val(void);
bool mdla_pwr_apusys_disabled(void);
void mdla_pwr_reset_setup(void (*hw_reset)(u32 core_id, const char *str));
int mdla_pwr_device_register(struct platform_device *pdev,
int (*on)(u32 core_id, bool force),
int (*off)(u32 core_id, int suspend, bool force));
int mdla_pwr_device_unregister(struct platform_device *pdev);
#endif /* __MDLA_POWER_CTRL_H__ */
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <common/mdla_device.h>
#include <common/mdla_scheduler.h>
static int dev_handle_capability[MAX_CORE_NUM];
static int cmd_priority_max;
static void mdla_sched_dummy_cmd_batch(struct command_entry *c) {}
static struct mdla_sched_cb_func mdla_scheduler_callback = {
.split_alloc_cmd_batch = mdla_sched_dummy_cmd_batch,
.del_free_cmd_batch = mdla_sched_dummy_cmd_batch,
.backup_cmd_batch = mdla_sched_dummy_cmd_batch,
.restore_cmd_batch = mdla_sched_dummy_cmd_batch,
};
struct mdla_sched_cb_func *mdla_sched_plat_cb(void)
{
return &mdla_scheduler_callback;
}
void mdla_sched_set_dev_handle_cap(u32 core_id, int cmd_num)
{
if (core_id < MAX_CORE_NUM)
dev_handle_capability[core_id] = cmd_num;
}
int mdla_sched_get_dev_handle_cap(u32 core_id)
{
return (core_id < MAX_CORE_NUM) ? dev_handle_capability[core_id] : 0;
}
void mdla_sched_set_cmd_prio_lv(int max_lv)
{
cmd_priority_max = max_lv;
}
int mdla_sched_get_cmd_prio_lv(void)
{
return cmd_priority_max;
}
@@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_SCHEDULER_H__
#define __MDLA_SCHEDULER_H__
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/list.h>
struct command_entry;
/* platform callback functions */
struct mdla_sched_cb_func {
void (*split_alloc_cmd_batch)(struct command_entry *ce);
void (*del_free_cmd_batch)(struct command_entry *ce);
void (*backup_cmd_batch)(struct command_entry *ce);
void (*restore_cmd_batch)(struct command_entry *ce);
};
struct mdla_sched_cb_func *mdla_sched_plat_cb(void);
void mdla_sched_set_dev_handle_cap(u32 core_id, int cmd_num);
int mdla_sched_get_dev_handle_cap(u32 core_id);
void mdla_sched_set_cmd_prio_lv(int max_lv);
int mdla_sched_get_cmd_prio_lv(void);
#endif /* __MDLA_SCHEDULER_H__ */
@@ -0,0 +1,96 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_CMD_DATA_V1_0_H__
#define __MDLA_CMD_DATA_V1_0_H__
#include <linux/types.h>
#define USE_IOCTL_STRUCT 1
#if USE_IOCTL_STRUCT /* same as struct ioctl_xxx */
#define get_code_buf_kva(apusys_hd, run_cmd)\
((run_cmd)->kva + (run_cmd)->offset)
struct mdla_run_cmd {
struct {
uint32_t size;
uint32_t mva;
void *pa;
void *kva;
uint32_t u_id;
uint8_t type;
void *data;
int ion_share_fd;
int ion_handle; /* user space handle */
uint64_t ion_khandle; /* kernel space handle */
};
uint32_t offset; /* [in] command byte offset in buf */
uint32_t count; /* [in] # of commands */
uint32_t id; /* [out] command id */
uint8_t priority; /* [in] dvfs priority */
uint8_t boost_value; /* [in] dvfs boost value */
};
struct mdla_wait_cmd {
uint32_t id; /* [in] command id */
int32_t 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 mdla_run_cmd_sync {
struct mdla_run_cmd req;
struct mdla_wait_cmd res;
};
struct mdla_wait_entry {
uint32_t async_id;
struct list_head list;
struct mdla_wait_cmd wt;
};
#else /* use mt6885 struct definition */
#define get_code_buf_kva(apusys_hd, run_cmd)\
((apusys_hd)->cmd_entry + (run_cmd)->offset_code_buf)
struct mdla_wait_cmd {
uint32_t id; /* [in] command id */
int32_t 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 mdla_run_cmd {
uint32_t offset_code_buf;
uint32_t reserved;
uint32_t size;
uint32_t mva;
uint32_t offset; /* [in] command byte offset in buf */
uint32_t count; /* [in] # of commands */
uint32_t id; /* [out] command id */
};
struct mdla_run_cmd_sync {
struct mdla_run_cmd req;
struct mdla_wait_cmd res;
uint32_t mdla_id;
};
struct mdla_wait_entry {
uint32_t async_id;
struct list_head list;
struct mdla_wait_cmd wt;
};
#endif /* USE_IOCTL_STRUCT */
#endif /* __MDLA_CMD_DATA_V1_0_H__ */
@@ -0,0 +1,117 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_CMD_DATA_V1_X_H__
#define __MDLA_CMD_DATA_V1_X_H__
#include <linux/types.h>
#include <linux/list.h>
/* Get priority level */
#include <utilities/mdla_util.h>
struct command_entry;
struct mdla_wait_cmd {
uint32_t id; /* [in] command id */
int32_t 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 mdla_run_cmd {
uint32_t offset_code_buf;
uint32_t reserved;
uint32_t size;
uint32_t mva;
uint32_t offset; /* [in] command byte offset in buf */
uint32_t count; /* [in] # of commands */
uint32_t id; /* [out] command id */
};
struct mdla_run_cmd_sync {
struct mdla_run_cmd req;
struct mdla_wait_cmd res;
uint32_t mdla_id;
};
struct mdla_wait_entry {
uint32_t async_id;
struct list_head list;
struct mdla_wait_cmd wt;
};
/*
* struct mdla_scheduler
*
* @active_ce_queue: Queue for the active CEs, which would be issued when
* HW engine is available.
* @processing_ce: Pointer to the CE that is under processing.
* This pointer would be updated on:
* 1. dequeueing a CE from ce_queue
* 2. CE completed
* 3. CE timeout
* Pinter should be NULL if there is no incoming CEs.
*
* @lock: Lock to protect the scheduler elements.
*
* @enqueue_ce: Pointer to function for enqueueing a CE to ce_queue.
* The implementation should includes:
* 1. move the CE into its ce_queue
* 2. start the HW engine if processing_ce is NULL
* @dequeue_ce: Pointer to function for dequeueing a CE from ce_queue.
* The preemption of CE might be taken in this procedure.
* The implementation should includes:
* 1. search the next CE to be issued
* 2. if processing_ce is not NULL, callee must handle
* the preemption of CE
* 3. update processing_ce to the next CE, and move
* the previous processing one to ce_queue
* @issue_ce: Pointer to function for issuing a batch of the CE
* to HW engine.
* The implementation should include:
* 1. set the HW RGs for execution on the batch of
* commands.
* 2. not only handle the normal case, but also the
* preemption case.
* 3. callee could integrate power-on flow in this
* procedure, yet the reentrant issue should be taken
* into consideration.
* @process_ce: Pointer to function for processing the CE when
* the scheduler receives a interrupt from HW engine
* The implementation should includes:
* 1. read the engine status from HW RGs, and do proper
* operation based on the status
* 2. check whether this command batch completed or not
* The return value should be one of:
* 1. CE_DONE if all the batches in the CE completed
* 2. CE_RUN if a batch completed
* 3. CE_NONE if the batch is still under processing
* @complete_ce: Pointer to function for completing the CE.
* The implementation should includes:
* 1. set the status of processing_ce to CE_FIN
* 2. set processing_ce to NULL for the next CE
* 3. complete the processing_ce->done to notify
*/
struct mdla_scheduler {
struct list_head ce_list[PRIORITY_LEVEL];
struct command_entry *ce[PRIORITY_LEVEL];
struct command_entry *pro_ce;
spinlock_t lock;
void (*enqueue_ce)(u32 core_id, struct command_entry *ce, u32 resume);
struct command_entry* (*dequeue_ce)(u32 core_id);
void (*issue_ce)(u32 core_id);
void (*issue_dual_lowce)(u32 core_id, uint64_t dual_cmd_id);
int (*process_ce)(u32 core_id);
void (*complete_ce)(u32 core_id);
void (*preempt_ce)(u32 core_id, struct command_entry *high_ce);
u64 (*get_smp_deadline)(int priority);
void (*set_smp_deadline)(int priority, u64 deadline);
};
#endif /* __MDLA_CMD_DATA_V1_X_H__ */
@@ -0,0 +1,76 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_CMD_DATA_V2_0_H__
#define __MDLA_CMD_DATA_V2_0_H__
#include <linux/types.h>
#include <linux/list.h>
struct command_entry;
struct mdla_wait_cmd {
uint32_t id; /* [in] command id */
int32_t 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 mdla_run_cmd {
uint32_t offset_code_buf;
uint32_t reserved;
uint32_t size;
uint32_t mva;
uint32_t offset; /* [in] command byte offset in buf */
uint32_t count; /* [in] # of commands */
uint32_t id; /* [out] command id */
};
struct mdla_run_cmd_sync {
struct mdla_run_cmd req;
struct mdla_wait_cmd res;
uint32_t mdla_id;
};
struct mdla_wait_entry {
uint32_t async_id;
struct list_head list;
struct mdla_wait_cmd wt;
};
struct command_batch {
struct list_head node;
u32 index;
u32 size;
};
struct sched_smp_ce {
spinlock_t lock;
u64 deadline;
};
struct mdla_scheduler {
struct list_head ce_list[PRIORITY_LEVEL];
struct command_entry *ce[PRIORITY_LEVEL];
struct command_entry *pro_ce;
spinlock_t lock;
void (*sw_reset)(u32 core_id);
void (*enqueue_ce)(u32 core_id, struct command_entry *ce, u32 resume);
struct command_entry* (*dequeue_ce)(u32 core_id);
void (*issue_ce)(u32 core_id);
void (*issue_dual_lowce)(u32 core_id, uint64_t dual_cmd_id);
int (*process_ce)(u32 core_id);
void (*preempt_ce)(u32 core_id, struct command_entry *high_ce);
void (*stop_ce)(u32 core_id, struct command_entry *ce);
void (*complete_ce)(u32 core_id);
u64 (*get_smp_deadline)(int priority);
void (*set_smp_deadline)(int priority, u64 deadline);
};
#endif /* __MDLA_CMD_DATA_V2_0_H__ */
@@ -0,0 +1,59 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_CMD_PROC_INTF_H__
#define __MDLA_CMD_PROC_INTF_H__
#include <common/mdla_device.h>
/* MDLA HW v1.0 */
int mdla_cmd_run_sync_v1_0(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority);
int mdla_cmd_ut_run_sync_v1_0(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info);
/* MDLA HW v1.5 and v1.7 */
int mdla_cmd_run_sync_v1_x(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority);
int mdla_cmd_ut_run_sync_v1_x(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info);
/* MDLA HW v1.5 and v1.7 with SW preemption */
int mdla_cmd_run_sync_v1_x_sched(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority);
int mdla_cmd_ut_run_sync_v1_x_sched(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info);
/* MDLA HW v2.0 */
int mdla_cmd_run_sync_v2_0(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority);
int mdla_cmd_ut_run_sync_v2_0(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info);
/* MDLA HW v2.0 with HW preemption */
int mdla_cmd_run_sync_v2_0_hw_sched(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority);
int mdla_cmd_ut_run_sync_v2_0_hw_sched(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info);
/* MDLA HW v2.0 with SW preemption */
int mdla_cmd_run_sync_v2_0_sw_sched(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority);
int mdla_cmd_ut_run_sync_v2_0_sw_sched(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info);
#endif /* __MDLA_CMD_PROC_INTF_H__ */
@@ -0,0 +1,280 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/sched/clock.h>
#include <apusys_device.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_ioctl.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_trace.h>
#include <utilities/mdla_debug.h>
#include "mdla_cmd_data_v1_0.h"
static void mdla_cmd_cal_perf_index(struct ioctl_wait_cmd *wt,
struct command_entry *ce)
{
wt->queue_time = ce->poweron_t - ce->receive_t;
wt->busy_time = ce->wait_t - ce->poweron_t;
wt->bandwidth = ce->bandwidth;
}
static void mdla_cmd_prepare_v1_0(struct mdla_run_cmd *cd,
struct apusys_cmd_hnd *apusys_hd, struct command_entry *ce)
{
ce->mva = cd->mva + cd->offset;
mdla_cmd_debug("%s: mva=0x%08x, offset=0x%x, count: %u\n",
__func__,
cd->mva,
cd->offset,
cd->count);
ce->state = CE_NONE;
ce->flags = CE_NOP;
ce->bandwidth = 0;
ce->result = MDLA_SUCCESS;
ce->count = cd->count;
ce->receive_t = sched_clock();
ce->kva = NULL;
ce->kva = (void *)(get_code_buf_kva(apusys_hd, cd));
mdla_cmd_debug("%s: cmd_entry=0x%llx, ce->kva=%p, size=0x%x\n",
__func__,
apusys_hd->cmd_entry,
ce->kva,
cd->size);
}
static void mdla_cmd_ut_prepare_v1_0(struct ioctl_run_cmd *cd,
struct command_entry *ce)
{
if (!ce)
return;
ce->mva = cd->buf.mva + cd->offset;
mdla_cmd_debug("%s: mva=0x%08x, offset=0x%x, count: %u, priority: %u, boost: %u\n",
__func__,
cd->buf.mva,
cd->offset,
cd->count,
cd->priority,
cd->boost_value);
ce->state = CE_NONE;
ce->flags = CE_NOP;
ce->bandwidth = 0;
ce->result = MDLA_CMD_SUCCESS;
ce->count = cd->count;
ce->receive_t = sched_clock();
ce->kva = NULL;
}
int mdla_cmd_run_sync_v1_0(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority)
{
u64 deadline = 0;
struct mdla_run_cmd *cd = &cmd_data->req;
struct command_entry ce;
int ret = 0, boost_val;
u32 core_id = 0;
memset(&ce, 0, sizeof(struct command_entry));
core_id = mdla_info->mdla_id;
ce.queue_t = sched_clock();
/* The critical region of command enqueue */
mutex_lock(&mdla_info->cmd_lock);
mdla_pwr_ops_get()->wake_lock(core_id);
mdla_cmd_prepare_v1_0(cd, apusys_hd, &ce);
process_command:
deadline = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
mdla_info->max_cmd_id = 0;
mdla_verbose("%s: core: %d max_cmd_id: %d id: %d\n",
__func__, core_id, mdla_info->max_cmd_id, ce.count);
ret = mdla_pwr_ops_get()->on(core_id, false);
if (ret)
goto out;
boost_val = apusys_hd->boost_val;
if (unlikely(mdla_dbg_read_u32(FS_DVFS_RAND)))
boost_val = mdla_pwr_get_random_boost_val();
mdla_pwr_ops_get()->set_opp_by_boost(core_id, boost_val);
mdla_prof_start(core_id);
mdla_trace_begin(core_id, &ce);
mdla_util_apu_pmu_handle(mdla_info, apusys_hd, 0);
ce.poweron_t = sched_clock();
ce.req_start_t = sched_clock();
mdla_cmd_plat_cb()->pre_cmd_handle(core_id, &ce);
/* Fill HW reg */
mdla_cmd_plat_cb()->process_command(core_id, &ce);
/* Wait for timeout */
while (mdla_info->max_cmd_id < ce.count
&& time_before64(get_jiffies_64(), deadline)) {
wait_for_completion_interruptible_timeout(
&mdla_info->command_done,
mdla_cmd_plat_cb()->get_wait_time(core_id));
/* E1 HW timeout check here */
if (mdla_cmd_plat_cb()->wait_cmd_hw_detect(core_id) != 0) {
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
goto process_command;
}
}
mdla_cmd_plat_cb()->post_cmd_info(core_id);
ce.req_end_t = sched_clock();
mdla_prof_iter(core_id);
mdla_trace_end(core_id, 0, &ce);
cd->id = mdla_info->max_cmd_id;
if (mdla_info->max_cmd_id < ce.count) {
mdla_timeout_debug("command: %d, max_cmd_id: %d\n",
ce.count,
mdla_info->max_cmd_id);
mdla_dbg_dump(mdla_info, &ce);
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
ret = -1;
}
mdla_pwr_ops_get()->off_timer_start(core_id);
ce.wait_t = sched_clock();
mdla_util_apu_pmu_update(mdla_info, apusys_hd, 0);
apusys_hd->ip_time = (u32)((ce.wait_t - ce.poweron_t) / 1000);
out:
mdla_pwr_ops_get()->wake_unlock(core_id);
mutex_unlock(&mdla_info->cmd_lock);
return ret;
}
int mdla_cmd_ut_run_sync_v1_0(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info)
{
u64 deadline = 0;
int ret = 0;
struct ioctl_run_cmd *cd = (struct ioctl_run_cmd *)run_cmd;
struct ioctl_wait_cmd *wt = (struct ioctl_wait_cmd *)wait_cmd;
struct command_entry ce;
u32 core_id = mdla_info->mdla_id;
memset(&ce, 0, sizeof(struct command_entry));
ce.queue_t = sched_clock();
/* The critical region of command enqueue */
mutex_lock(&mdla_info->cmd_lock);
mdla_pwr_ops_get()->wake_lock(core_id);
mdla_cmd_ut_prepare_v1_0(cd, &ce);
mdla_trace_begin(0, &ce);
process_command:
/* Compute deadline */
deadline = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
mdla_info->max_cmd_id = 0;
mdla_timeout_debug("%s: max_cmd_id: %d id: %d\n",
__func__, mdla_info->max_cmd_id, ce.count);
ret = mdla_pwr_ops_get()->on(core_id, false);
if (ret)
goto out;
mdla_pwr_ops_get()->set_opp_by_boost(core_id, cd->boost_value);
mdla_prof_start(core_id);
ce.poweron_t = sched_clock();
ce.req_start_t = sched_clock();
/* Fill HW reg */
mdla_cmd_plat_cb()->process_command(core_id, &ce);
/* Wait for timeout */
while (mdla_info->max_cmd_id < ce.count
&& time_before64(get_jiffies_64(), deadline)) {
wait_for_completion_interruptible_timeout(
&mdla_info->command_done,
mdla_cmd_plat_cb()->get_wait_time(core_id));
/* E1 HW timeout check here */
if (mdla_cmd_plat_cb()->wait_cmd_hw_detect(core_id) != 0) {
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
goto process_command;
}
}
ce.req_end_t = sched_clock();
mdla_prof_iter(core_id);
mdla_trace_end(core_id, 0, &ce);
wt->id = ce.count;
if (mdla_info->max_cmd_id >= ce.count)
wt->result = 0;
else { // Command timeout
mdla_timeout_debug("%s: command: %u, max_cmd_id: %u deadline:%llu, jiffies: %lu\n",
__func__, ce.count,
mdla_info->max_cmd_id, deadline, jiffies);
mdla_dbg_dump(mdla_info, &ce);
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
wt->result = 1;
}
mdla_pwr_ops_get()->off_timer_start(core_id);
ce.wait_t = sched_clock();
/* Calculate all performance index */
mdla_cmd_cal_perf_index(wt, &ce);
out:
mdla_pwr_ops_get()->wake_unlock(core_id);
mutex_unlock(&mdla_info->cmd_lock);
return 0;
}
@@ -0,0 +1,275 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/sched/clock.h>
#include <apusys_device.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_ioctl.h>
#include <common/mdla_scheduler.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_trace.h>
#include <utilities/mdla_debug.h>
#include "mdla_cmd_data_v1_x.h"
static void mdla_cmd_prepare_v1_x(struct mdla_run_cmd *cd,
struct apusys_cmd_hnd *apusys_hd, struct command_entry *ce)
{
ce->mva = cd->mva + cd->offset;
ce->state = CE_NONE;
ce->flags = CE_NOP;
ce->bandwidth = 0;
ce->result = MDLA_SUCCESS;
ce->count = cd->count;
ce->receive_t = sched_clock();
ce->kva = (void *)apusys_mem_query_kva((u32)ce->mva);
mdla_cmd_debug("%s: kva=0x%llx, mva=0x%08x(0x%08x+0x%x), cnt=%u, sz=0x%x\n",
__func__,
(u64)ce->kva,
ce->mva,
cd->mva,
cd->offset,
ce->count,
cd->size);
}
static void mdla_cmd_ut_prepare_v1_x(struct ioctl_run_cmd *cd,
struct command_entry *ce)
{
ce->mva = cd->buf.mva + cd->offset;
mdla_cmd_debug("%s: mva=0x%08x, offset=0x%x, count: %u\n",
__func__,
cd->buf.mva,
cd->offset,
cd->count);
ce->state = CE_NONE;
ce->flags = CE_NOP;
ce->bandwidth = 0;
ce->result = MDLA_SUCCESS;
ce->count = cd->count;
ce->receive_t = sched_clock();
ce->kva = NULL;
ce->boost_val = cd->boost_value;
}
int mdla_cmd_run_sync_v1_x(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority)
{
u64 deadline = 0;
struct mdla_run_cmd *cd = &cmd_data->req;
struct command_entry ce;
int ret = 0, boost_val;
u32 core_id = 0;
uint64_t out_end;
memset(&ce, 0, sizeof(struct command_entry));
core_id = mdla_info->mdla_id;
ce.queue_t = sched_clock();
/* The critical region of command enqueue */
mutex_lock(&mdla_info->cmd_lock);
mdla_pwr_ops_get()->wake_lock(core_id);
mdla_cmd_prepare_v1_x(cd, apusys_hd, &ce);
out_end = apusys_hd->cmd_entry + apusys_hd->cmd_size;
if (mdla_cmd_plat_cb()->check_cmd_valid(out_end, &ce) == false)
return -EINVAL;
deadline = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
mdla_info->max_cmd_id = 0;
mdla_verbose("%s: core: %d max_cmd_id: %d id: %d\n",
__func__, core_id, mdla_info->max_cmd_id, ce.count);
ret = mdla_pwr_ops_get()->on(core_id, false);
if (ret)
goto out;
boost_val = apusys_hd->boost_val;
if (unlikely(mdla_dbg_read_u32(FS_DVFS_RAND)))
boost_val = mdla_pwr_get_random_boost_val();
mdla_pwr_ops_get()->set_opp_by_boost(core_id, boost_val);
mdla_util_apu_pmu_handle(mdla_info, apusys_hd, 0);
mdla_prof_start(core_id);
mdla_trace_begin(core_id, &ce);
ce.poweron_t = sched_clock();
mdla_info->sched->pro_ce = &ce;
mdla_cmd_plat_cb()->pre_cmd_handle(core_id, &ce);
/* Fill HW reg */
mdla_cmd_plat_cb()->process_command(core_id, &ce);
/* Wait for timeout */
while (mdla_info->max_cmd_id < ce.count
&& time_before64(get_jiffies_64(), deadline)) {
wait_for_completion_interruptible_timeout(
&mdla_info->command_done,
mdla_cmd_plat_cb()->get_wait_time(core_id));
}
mdla_cmd_plat_cb()->post_cmd_info(core_id);
mdla_info->sched->pro_ce = NULL;
mdla_trace_end(core_id, 0, &ce);
mdla_prof_iter(core_id);
mdla_util_apu_pmu_update(mdla_info, apusys_hd, 0);
cd->id = mdla_info->max_cmd_id;
if (mdla_info->max_cmd_id < ce.count) {
mdla_timeout_debug("command: %d, max_cmd_id: %d\n",
ce.count,
mdla_info->max_cmd_id);
mdla_cmd_plat_cb()->post_cmd_hw_detect(core_id);
mdla_dbg_dump(mdla_info, &ce);
/* Enable & Relase bus protect */
mdla_pwr_ops_get()->switch_off_on(core_id);
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
ret = -1;
}
mdla_pwr_ops_get()->off_timer_start(core_id);
apusys_hd->ip_time = (u32)ce.exec_time / 1000;
out:
mdla_pwr_ops_get()->wake_unlock(core_id);
mutex_unlock(&mdla_info->cmd_lock);
return ret;
}
int mdla_cmd_ut_run_sync_v1_x(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info)
{
u64 deadline = 0;
struct ioctl_run_cmd *cd = (struct ioctl_run_cmd *)run_cmd;
struct ioctl_wait_cmd *wt = (struct ioctl_wait_cmd *)wait_cmd;
struct command_entry ce;
int ret = 0, boost_val;
u32 core_id = 0;
memset(&ce, 0, sizeof(struct command_entry));
core_id = mdla_info->mdla_id;
ce.queue_t = sched_clock();
wt->result = 0;
/* The critical region of command enqueue */
mutex_lock(&mdla_info->cmd_lock);
mdla_pwr_ops_get()->wake_lock(core_id);
mdla_cmd_ut_prepare_v1_x(cd, &ce);
deadline = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
mdla_info->max_cmd_id = 0;
mdla_verbose("%s: core: %d max_cmd_id: %d id: %d\n",
__func__, core_id, mdla_info->max_cmd_id, ce.count);
ret = mdla_pwr_ops_get()->on(core_id, false);
if (ret)
goto out;
boost_val = ce.boost_val;
if (unlikely(mdla_dbg_read_u32(FS_DVFS_RAND)))
boost_val = mdla_pwr_get_random_boost_val();
mdla_pwr_ops_get()->set_opp_by_boost(core_id, boost_val);
mdla_prof_start(core_id);
mdla_trace_begin(core_id, &ce);
ce.poweron_t = sched_clock();
mdla_cmd_plat_cb()->pre_cmd_handle(core_id, &ce);
/* Fill HW reg */
mdla_cmd_plat_cb()->process_command(core_id, &ce);
/* Wait for timeout */
while (mdla_info->max_cmd_id < ce.count
&& time_before64(get_jiffies_64(), deadline)) {
wait_for_completion_interruptible_timeout(
&mdla_info->command_done,
mdla_cmd_plat_cb()->get_wait_time(core_id));
}
mdla_cmd_plat_cb()->post_cmd_info(core_id);
mdla_prof_iter(core_id);
mdla_trace_end(core_id, 0, &ce);
cd->id = mdla_info->max_cmd_id;
if (mdla_info->max_cmd_id < ce.count) {
mdla_timeout_debug("command: %d, max_cmd_id: %d\n",
ce.count,
mdla_info->max_cmd_id);
mdla_cmd_plat_cb()->post_cmd_hw_detect(core_id);
mdla_dbg_dump(mdla_info, &ce);
/* Enable & Relase bus protect */
mdla_pwr_ops_get()->switch_off_on(core_id);
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
ret = -1;
wt->result = 1;
}
mdla_pwr_ops_get()->off_timer_start(core_id);
ce.wait_t = sched_clock();
wt->queue_time = ce.poweron_t - ce.receive_t;
wt->busy_time = ce.wait_t - ce.poweron_t;
wt->bandwidth = ce.bandwidth;
out:
mdla_pwr_ops_get()->wake_unlock(core_id);
mutex_unlock(&mdla_info->cmd_lock);
return ret;
}
@@ -0,0 +1,329 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/sched/clock.h>
#if IS_ENABLED(CONFIG_MTK_GIC_V3_EXT)
#include <linux/irqchip/mtk-gic-extend.h>
#else
#define mt_irq_dump_status(n)
#endif
#include <apusys_device.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_ioctl.h>
#include <common/mdla_scheduler.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_trace.h>
#include <utilities/mdla_debug.h>
#include "mdla_cmd_data_v1_x.h"
static void mdla_cmd_prepare_v1_x_sched(struct mdla_run_cmd *cd,
struct apusys_cmd_hnd *apusys_hd,
struct command_entry *ce, uint32_t priority)
{
ce->mva = cd->mva + cd->offset;
ce->state = CE_NONE;
ce->flags = CE_NOP;
ce->bandwidth = 0;
ce->result = MDLA_SUCCESS;
ce->count = cd->count;
ce->receive_t = sched_clock();
ce->csn = priority + 1;
ce->deadline_t = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
/* It is new command list */
ce->fin_cid = 0;
ce->wish_fin_cid = ce->count;
ce->irq_state = IRQ_SUCCESS;
ce->req_start_t = 0;
ce->boost_val = apusys_hd->boost_val;
ce->ctx_id = apusys_hd->ctx_id;
ce->context_callback = apusys_hd->context_callback;
apusys_hd->ip_time = 0;
ce->cmdbuf = apusys_hd->cmdbuf;
ce->priority = priority;
ce->kva = (void *)apusys_mem_query_kva((u32)ce->mva);
if (apusys_hd->multicore_total == 2) {
ce->cmd_id = apusys_hd->cmd_id;
ce->multicore_total = apusys_hd->multicore_total;
ce->cmd_batch_size = cd->count + 1;
} else {
ce->cmd_batch_size = apusys_hd->cluster_size;
}
init_completion(&ce->swcmd_done_wait);
mdla_cmd_debug("%s: kva=0x%llx mva=0x%08x(0x%08x+0x%x) cnt=%u sz=0x%x\n",
__func__,
(u64)ce->kva,
ce->mva,
cd->mva,
cd->offset,
ce->count,
cd->size);
mdla_verbose("%s: ctx_id=%d apu_hd_core_num=%d prio=%d batch_sz=%d)\n",
__func__,
ce->ctx_id,
apusys_hd->multicore_total,
ce->priority,
ce->cmd_batch_size);
}
static void mdla_cmd_set_opp(u32 core_id, struct command_entry *ce, int boost_val)
{
if (ce->boost_val > boost_val)
boost_val = ce->boost_val;
else
boost_val = 0;
if (unlikely(mdla_dbg_read_u32(FS_DVFS_RAND)))
boost_val = mdla_pwr_get_random_boost_val();
if (boost_val)
mdla_pwr_ops_get()->set_opp_by_boost(core_id, boost_val);
}
static int mdla_cmd_wrong_count_handler(struct mdla_dev *mdla_info,
struct command_entry *ce)
{
struct command_entry *timeout_ce;
struct mdla_scheduler *sched = mdla_info->sched;
u32 core_id = mdla_info->mdla_id;
unsigned long flags;
int prio;
mdla_timeout_debug("Interrupt error status: %x\n",
mdla_info->error_bit);
mdla_info->error_bit = 0;
mdla_timeout_debug("Print current ce\n");
mdla_dbg_ce_info(core_id, ce);
mdla_timeout_debug("=====================\n");
if (sched->pro_ce != NULL) {
mdla_timeout_debug("Print process ce\n");
mdla_dbg_ce_info(core_id, sched->pro_ce);
mdla_timeout_debug("=====================\n");
}
for (prio = 0; prio < PRIORITY_LEVEL; prio++) {
if (!sched->ce[prio])
continue;
mdla_timeout_debug("Print ce in driver\n");
mdla_dbg_ce_info(core_id, sched->ce[prio]);
mdla_timeout_debug("=====================\n");
}
/* handle command timeout */
mdla_cmd_plat_cb()->post_cmd_hw_detect(core_id);
mt_irq_dump_status(mdla_cmd_plat_cb()->get_irq_num(core_id));
mdla_dbg_dump(mdla_info, ce);
/* Enable & Relase bus protect */
mdla_pwr_ops_get()->switch_off_on(core_id);
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
/* error handling for scheudler by removing processing CE */
spin_lock_irqsave(&sched->lock, flags);
sched->pro_ce = NULL;
do {
timeout_ce = sched->dequeue_ce(core_id);
if (timeout_ce != NULL) {
timeout_ce->state |= (1 << CE_FAIL);
complete(&timeout_ce->swcmd_done_wait);
}
} while (timeout_ce != NULL);
spin_unlock_irqrestore(&sched->lock, flags);
return -REASON_MDLA_TIMEOUT;
}
int mdla_cmd_run_sync_v1_x_sched(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority)
{
int ret = REASON_MDLA_SUCCESS;
unsigned long flags;
u64 pwron_t;
int pro_boost_val = 0;
struct mdla_run_cmd *cd = &cmd_data->req;
struct command_entry *ce;
struct mdla_scheduler *sched = mdla_info->sched;
uint64_t out_end;
u32 core_id = mdla_info->mdla_id;
if (!cd || (cd->count == 0) || (apusys_hd->cmdbuf == NULL)) {
mdla_err("%s: %d null check fail\n", __func__, __LINE__);
return -EINVAL;
}
/* need to define error code for scheduler is NULL */
if (!sched)
return -REASON_MDLA_NULLPOINT;
if (unlikely(priority >= PRIORITY_LEVEL)) {
mdla_err("%s: %d illegal priority level\n", __func__, __LINE__);
return -EINVAL;
}
ret = mdla_pwr_ops_get()->on(core_id, false);
if (ret)
return ret;
pwron_t = sched_clock();
/* initial global variable */
spin_lock_irqsave(&sched->lock, flags);
if (unlikely(sched->ce[priority])) {
spin_unlock_irqrestore(&sched->lock, flags);
mdla_err("%s: %d has ce with same priority\n", __func__, __LINE__);
return -EINVAL;
}
ce = kzalloc(sizeof(struct command_entry), GFP_ATOMIC);
sched->ce[priority] = ce;
if (sched->pro_ce)
pro_boost_val = sched->pro_ce->boost_val;
spin_unlock_irqrestore(&sched->lock, flags);
if (ce == NULL)
return -ENOMEM;
mdla_pwr_ops_get()->wake_lock(core_id);
/* prepare CE */
mdla_cmd_prepare_v1_x_sched(cd, apusys_hd, ce, priority);
out_end = apusys_hd->cmd_entry + apusys_hd->cmd_size;
if (mdla_cmd_plat_cb()->check_cmd_valid(out_end, ce) == false) {
spin_lock_irqsave(&sched->lock, flags);
kfree(sched->ce[priority]);
sched->ce[priority] = NULL;
spin_unlock_irqrestore(&sched->lock, flags);
return -EINVAL;
}
ce->poweron_t = pwron_t;
mdla_cmd_set_opp(core_id, ce, pro_boost_val);
ce->batch_list_head = NULL;
if (priority == MDLA_LOW_PRIORITY && ce->cmd_batch_size < ce->count) {
ce->cmd_int_backup = kcalloc(ce->count, sizeof(uint32_t), GFP_KERNEL);
if (ce->cmd_int_backup != NULL) {
ce->cmd_ctrl_1_backup = kcalloc(ce->count, sizeof(uint32_t), GFP_KERNEL);
if (ce->cmd_ctrl_1_backup != NULL) {
mdla_sched_plat_cb()->backup_cmd_batch(ce);
mdla_sched_plat_cb()->split_alloc_cmd_batch(ce);
if (ce->batch_list_head == NULL) {
kfree(ce->cmd_int_backup);
kfree(ce->cmd_ctrl_1_backup);
}
} else
kfree(ce->cmd_int_backup);
}
}
mdla_util_apu_pmu_handle(mdla_info, apusys_hd, (u16)priority);
mdla_prof_start(core_id);
mdla_trace_begin(core_id, ce);
mdla_cmd_plat_cb()->pre_cmd_handle(core_id, ce);
if (ce->multicore_total > 1 && ce->priority == MDLA_LOW_PRIORITY) {
spin_lock_irqsave(&sched->lock, flags);
sched->enqueue_ce(core_id, ce, 0);
spin_unlock_irqrestore(&sched->lock, flags);
sched->issue_dual_lowce(core_id, ce->cmd_id);
} else {
spin_lock_irqsave(&sched->lock, flags);
if (sched->pro_ce == NULL) {
sched->pro_ce = ce;
sched->issue_ce(core_id);
} else {
sched->enqueue_ce(core_id, ce, 0);
}
spin_unlock_irqrestore(&sched->lock, flags);
}
/* wait for deadline */
while (ce->fin_cid < ce->count
&& time_before64(get_jiffies_64(), ce->deadline_t)) {
wait_for_completion_interruptible_timeout(
&ce->swcmd_done_wait,
mdla_cmd_plat_cb()->get_wait_time(core_id));
mdla_cmd_plat_cb()->wait_cmd_handle(core_id, ce);
if (ce->state & BIT(CE_FAIL))
goto error_handle;
}
if (unlikely(ce->fin_cid < ce->count))
ret = mdla_cmd_wrong_count_handler(mdla_info, ce);
apusys_hd->ip_time = (u32)ce->exec_time / 1000;
/* update id to the last finished command id */
cd->id = ce->fin_cid;
error_handle:
mdla_trace_end(core_id, 0, ce);
mdla_prof_iter(core_id);
mdla_util_apu_pmu_update(mdla_info, apusys_hd, (u16)priority);
if (priority == MDLA_LOW_PRIORITY && ce->batch_list_head != NULL) {
mdla_sched_plat_cb()->restore_cmd_batch(ce);
kfree(ce->cmd_int_backup);
kfree(ce->cmd_ctrl_1_backup);
}
spin_lock_irqsave(&sched->lock, flags);
if (priority == MDLA_LOW_PRIORITY && ce->batch_list_head != NULL)
mdla_sched_plat_cb()->del_free_cmd_batch(ce);
kfree(sched->ce[priority]);
sched->ce[priority] = NULL;
spin_unlock_irqrestore(&sched->lock, flags);
mdla_pwr_ops_get()->off_timer_start(core_id);
mdla_pwr_ops_get()->wake_unlock(core_id);
return ret;
}
int mdla_cmd_ut_run_sync_v1_x_sched(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info)
{
return 0;
}
@@ -0,0 +1,294 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/sched/clock.h>
#include <apusys_device.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_ioctl.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_trace.h>
#include <utilities/mdla_debug.h>
#include "mdla_cmd_data_v2_0.h"
static void mdla_cmd_prepare_v2_0(struct mdla_run_cmd *cd,
struct apusys_cmd_hnd *apusys_hd, struct command_entry *ce)
{
ce->mva = cd->mva + cd->offset;
apusys_hd->ip_time = 0;
ce->state = CE_NONE;
ce->flags = CE_NOP;
ce->bandwidth = 0;
ce->result = MDLA_SUCCESS;
ce->count = cd->count;
ce->fin_cid = 0;
ce->csn = (ce->mva & 0xFFFFFFFE);
ce->footprint = 0;
ce->kva = (void *)apusys_mem_query_kva((u32)ce->mva);
/* Initialize timestamp*/
ce->exec_time = 0;
ce->poweron_t = 0;
ce->req_start_t = 0;
ce->req_end_t = 0;
ce->queue_t = 0;
mdla_cmd_debug("%s: kva=0x%llx mva=0x%08x(0x%08x+0x%x) cnt=%u sz=0x%x\n",
__func__,
(u64)ce->kva,
ce->mva,
cd->mva,
cd->offset,
ce->count,
cd->size);
}
static void mdla_cmd_ut_prepare_v2_0(struct ioctl_run_cmd *cd,
struct command_entry *ce)
{
ce->mva = cd->buf.mva + cd->offset;
mdla_cmd_debug("%s: mva=0x%08x, offset=0x%x, count: %u\n",
__func__,
cd->buf.mva,
cd->offset,
cd->count);
ce->state = CE_NONE;
ce->flags = CE_NOP;
ce->bandwidth = 0;
ce->result = MDLA_SUCCESS;
ce->count = cd->count;
ce->kva = NULL;
ce->boost_val = cd->boost_value;
/* Initialize timestamp */
ce->wait_t = 0;
ce->queue_t = 0;
}
int mdla_cmd_run_sync_v2_0(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority)
{
u64 deadline = 0, cmd_start_t;
struct mdla_run_cmd *cd = &cmd_data->req;
struct command_entry ce;
int ret = 0, boost_val;
u32 core_id = 0;
u16 prio = (u16)priority;
uint64_t out_end;
cmd_start_t = sched_clock();
memset(&ce, 0, sizeof(struct command_entry));
core_id = mdla_info->mdla_id;
ce.receive_t = cmd_start_t;
ce.queue_t = cmd_start_t;
mdla_prof_set_ts(core_id, TS_CMD_START, cmd_start_t);
/* The critical region of command enqueue */
mutex_lock(&mdla_info->cmd_lock);
mdla_pwr_ops_get()->wake_lock(core_id);
mdla_cmd_prepare_v2_0(cd, apusys_hd, &ce);
out_end = apusys_hd->cmd_entry + apusys_hd->cmd_size;
if (mdla_cmd_plat_cb()->check_cmd_valid(out_end, &ce) == false)
return -EINVAL;
deadline = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
mdla_info->max_cmd_id = 0;
mdla_verbose("%s: core: %d max_cmd_id: %d id: %d\n",
__func__, core_id, mdla_info->max_cmd_id, ce.count);
ret = mdla_pwr_ops_get()->on(core_id, false);
if (ret)
goto out;
boost_val = apusys_hd->boost_val;
if (unlikely(mdla_dbg_read_u32(FS_DVFS_RAND)))
boost_val = mdla_pwr_get_random_boost_val();
mdla_pwr_ops_get()->set_opp_by_boost(core_id, boost_val);
mdla_prof_start(core_id);
mdla_trace_begin(core_id, &ce);
ce.poweron_t = sched_clock();
mdla_cmd_plat_cb()->pre_cmd_handle(core_id, &ce);
if (mdla_util_apu_pmu_handle(mdla_info, apusys_hd, prio) == 0)
mdla_util_pmu_ops_get()->reset_write_evt_exec(core_id, prio);
/* Fill HW reg */
mdla_cmd_plat_cb()->process_command(core_id, &ce);
/* Wait for timeout */
while (mdla_info->max_cmd_id < ce.count
&& time_before64(get_jiffies_64(), deadline)) {
wait_for_completion_interruptible_timeout(
&mdla_info->command_done,
mdla_cmd_plat_cb()->get_wait_time(core_id));
}
mdla_cmd_plat_cb()->post_cmd_handle(core_id, &ce);
mdla_cmd_plat_cb()->post_cmd_info(core_id);
mdla_trace_end(core_id, 0, &ce);
mdla_util_apu_pmu_update(mdla_info, apusys_hd, 0);
cd->id = mdla_info->max_cmd_id;
if (mdla_info->max_cmd_id < ce.count) {
mdla_timeout_debug("command: %d, max_cmd_id: %d\n",
ce.count,
mdla_info->max_cmd_id);
mdla_cmd_plat_cb()->post_cmd_hw_detect(core_id);
mdla_dbg_dump(mdla_info, &ce);
/* Enable & Relase bus protect */
mdla_pwr_ops_get()->switch_off_on(core_id);
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
ret = -1;
}
mdla_pwr_ops_get()->off_timer_start(core_id);
apusys_hd->ip_time = (u32)ce.exec_time / 1000;
out:
mdla_pwr_ops_get()->wake_unlock(core_id);
mutex_unlock(&mdla_info->cmd_lock);
mdla_prof_set_ts(core_id, TS_CMD_FINISH, sched_clock());
mdla_prof_iter(core_id);
return ret;
}
int mdla_cmd_ut_run_sync_v2_0(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info)
{
u64 deadline = 0, cmd_start_t;
struct ioctl_run_cmd *cd = (struct ioctl_run_cmd *)run_cmd;
struct ioctl_wait_cmd *wt = (struct ioctl_wait_cmd *)wait_cmd;
struct command_entry ce;
int ret = 0, boost_val;
u32 core_id = 0;
cmd_start_t = sched_clock();
memset(&ce, 0, sizeof(struct command_entry));
core_id = mdla_info->mdla_id;
ce.receive_t = cmd_start_t;
ce.queue_t = cmd_start_t;
wt->result = 0;
/* The critical region of command enqueue */
mutex_lock(&mdla_info->cmd_lock);
mdla_pwr_ops_get()->wake_lock(core_id);
mdla_cmd_ut_prepare_v2_0(cd, &ce);
deadline = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
mdla_info->max_cmd_id = 0;
mdla_verbose("%s: core: %d max_cmd_id: %d id: %d\n",
__func__, core_id, mdla_info->max_cmd_id, ce.count);
ret = mdla_pwr_ops_get()->on(core_id, false);
if (ret)
goto out;
boost_val = ce.boost_val;
if (unlikely(mdla_dbg_read_u32(FS_DVFS_RAND)))
boost_val = mdla_pwr_get_random_boost_val();
mdla_pwr_ops_get()->set_opp_by_boost(core_id, boost_val);
mdla_prof_start(core_id);
mdla_trace_begin(core_id, &ce);
ce.poweron_t = sched_clock();
mdla_cmd_plat_cb()->pre_cmd_handle(core_id, &ce);
/* Fill HW reg */
mdla_cmd_plat_cb()->process_command(core_id, &ce);
/* Wait for timeout */
while (mdla_info->max_cmd_id < ce.count
&& time_before64(get_jiffies_64(), deadline)) {
wait_for_completion_interruptible_timeout(
&mdla_info->command_done,
mdla_cmd_plat_cb()->get_wait_time(core_id));
}
mdla_cmd_plat_cb()->post_cmd_info(core_id);
mdla_prof_iter(core_id);
mdla_trace_end(core_id, 0, &ce);
cd->id = mdla_info->max_cmd_id;
if (mdla_info->max_cmd_id < ce.count) {
mdla_timeout_debug("command: %d, max_cmd_id: %d\n",
ce.count,
mdla_info->max_cmd_id);
mdla_cmd_plat_cb()->post_cmd_hw_detect(core_id);
mdla_dbg_dump(mdla_info, &ce);
/* Enable & Relase bus protect */
mdla_pwr_ops_get()->switch_off_on(core_id);
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
ret = -1;
wt->result = 1;
}
mdla_pwr_ops_get()->off_timer_start(core_id);
ce.wait_t = sched_clock();
wt->queue_time = ce.poweron_t - ce.receive_t;
wt->busy_time = ce.wait_t - ce.poweron_t;
wt->bandwidth = ce.bandwidth;
out:
mdla_pwr_ops_get()->wake_unlock(core_id);
mutex_unlock(&mdla_info->cmd_lock);
return ret;
}
@@ -0,0 +1,329 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/sched/clock.h>
#if IS_ENABLED(CONFIG_MTK_GIC_V3_EXT)
#include <linux/irqchip/mtk-gic-extend.h>
#else
#define mt_irq_dump_status(n)
#endif
#include <apusys_device.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_ioctl.h>
#include <common/mdla_scheduler.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_trace.h>
#include <utilities/mdla_debug.h>
#include "mdla_cmd_data_v2_0.h"
static void mdla_cmd_prepare_v2_0_hw_sched(struct mdla_run_cmd *cd,
struct apusys_cmd_hnd *apusys_hd,
struct command_entry *ce, uint32_t priority)
{
ce->mva = cd->mva + cd->offset;
ce->state = CE_NONE;
ce->flags = CE_NOP;
ce->bandwidth = 0;
ce->result = MDLA_SUCCESS;
ce->count = cd->count;
ce->receive_t = sched_clock();
ce->csn = (ce->mva & 0xFFFFFFFE) | priority;
ce->deadline_t = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
/* It is new command list */
ce->fin_cid = 0;
ce->wish_fin_cid = ce->count;
ce->irq_state = IRQ_SUCCESS;
ce->req_start_t = 0;
ce->boost_val = apusys_hd->boost_val;
ce->ctx_id = apusys_hd->ctx_id;
ce->context_callback = apusys_hd->context_callback;
apusys_hd->ip_time = 0;
ce->cmdbuf = apusys_hd->cmdbuf;
ce->priority = priority;
ce->footprint = 0;
ce->kva = (void *)apusys_mem_query_kva((u32)ce->mva);
/* Initialize timestamp*/
ce->exec_time = 0;
ce->poweron_t = 0;
ce->req_start_t = 0;
ce->req_end_t = 0;
/* Initialize HW preemption information */
ce->hw_sync0 = 0;
ce->hw_sync1 = 0;
ce->hw_sync2 = 0;
ce->hw_sync3 = 0;
/* Initialize SMP cmd data */
ce->cmd_id = apusys_hd->cmd_id;
ce->multicore_total = apusys_hd->multicore_total;
//FIXME: porting multicore_id?
init_completion(&ce->swcmd_done_wait);
mdla_cmd_debug("%s: kva=0x%llx mva=0x%08x(0x%08x+0x%x) cnt=%u sz=0x%x\n",
__func__,
(u64)ce->kva,
ce->mva,
cd->mva,
cd->offset,
ce->count,
cd->size);
mdla_verbose("%s: ctx_id=%d apu_hd_core_num=%d prio=%d)\n",
__func__,
ce->ctx_id,
apusys_hd->multicore_total,
ce->priority);
}
static void mdla_cmd_set_opp(u32 core_id, struct command_entry *ce, int boost_val)
{
if (ce->boost_val > boost_val)
boost_val = ce->boost_val;
else
boost_val = 0;
if (unlikely(mdla_dbg_read_u32(FS_DVFS_RAND)))
boost_val = mdla_pwr_get_random_boost_val();
if (boost_val)
mdla_pwr_ops_get()->set_opp_by_boost(core_id, boost_val);
}
static int mdla_cmd_wrong_count_handler(struct mdla_dev *mdla_info,
struct command_entry *ce)
{
struct command_entry *timeout_ce;
struct mdla_scheduler *sched = mdla_info->sched;
u32 core_id = mdla_info->mdla_id;
unsigned long flags;
int prio;
mdla_timeout_debug("Interrupt error status: %x\n",
mdla_info->error_bit);
mdla_info->error_bit = 0;
mdla_timeout_debug("Print current ce\n");
mdla_dbg_ce_info(core_id, ce);
mdla_timeout_debug("=====================\n");
if (sched->pro_ce != NULL) {
mdla_timeout_debug("Print process ce\n");
mdla_dbg_ce_info(core_id, sched->pro_ce);
mdla_timeout_debug("=====================\n");
}
for (prio = 0; prio < PRIORITY_LEVEL; prio++) {
if (!sched->ce[prio])
continue;
mdla_timeout_debug("Print ce in driver\n");
mdla_dbg_ce_info(core_id, sched->ce[prio]);
mdla_timeout_debug("=====================\n");
}
mdla_timeout_debug("core_id: %x, TS_HW_TRIGGER=%llu",
core_id, mdla_prof_get_ts(core_id, TS_HW_TRIGGER));
mdla_timeout_debug("core_id: %x, TS_HW_FIRST_TRIGGER=%llu",
core_id, mdla_prof_get_ts(core_id, TS_HW_FIRST_TRIGGER));
mdla_timeout_debug("core_id: %x, TS_HW_INTR=%llu",
core_id, mdla_prof_get_ts(core_id, TS_HW_INTR));
mdla_timeout_debug("core_id: %x, TS_HW_LAST_INTR=%llu",
core_id, mdla_prof_get_ts(core_id, TS_HW_LAST_INTR));
mdla_timeout_debug("core_id: %x, TS_CMD_STOP_REQ=%llu",
core_id, mdla_prof_get_ts(core_id, TS_CMD_STOP_REQ));
mdla_timeout_debug("core_id: %x, TS_CMD_STOPPED=%llu",
core_id, mdla_prof_get_ts(core_id, TS_CMD_STOPPED));
mdla_timeout_debug("core_id: %x, TS_CMD_RESUME=%llu",
core_id, mdla_prof_get_ts(core_id, TS_CMD_RESUME));
/* handle command timeout */
mdla_cmd_plat_cb()->post_cmd_hw_detect(core_id);
mt_irq_dump_status(mdla_cmd_plat_cb()->get_irq_num(core_id));
mdla_dbg_dump(mdla_info, ce);
/* Enable & Relase bus protect */
mdla_pwr_ops_get()->switch_off_on(core_id);
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
/* error handling for scheudler by removing processing CE */
spin_lock_irqsave(&sched->lock, flags);
sched->pro_ce = NULL;
do {
timeout_ce = sched->dequeue_ce(core_id);
if (timeout_ce != NULL) {
timeout_ce->state |= (1 << CE_FAIL);
complete(&timeout_ce->swcmd_done_wait);
}
} while (timeout_ce != NULL);
spin_unlock_irqrestore(&sched->lock, flags);
return -REASON_MDLA_TIMEOUT;
}
int mdla_cmd_run_sync_v2_0_hw_sched(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority)
{
int ret = REASON_MDLA_SUCCESS;
unsigned long flags;
u64 pwron_t;
int pro_boost_val = 0;
struct mdla_run_cmd *cd = &cmd_data->req;
struct command_entry *ce;
struct mdla_scheduler *sched = mdla_info->sched;
uint64_t out_end;
u32 core_id = mdla_info->mdla_id;
if (!cd || (cd->count == 0) || (apusys_hd->cmdbuf == NULL)) {
mdla_err("%s: %d null check fail\n", __func__, __LINE__);
return -EINVAL;
}
/* need to define error code for scheduler is NULL */
if (!sched)
return -REASON_MDLA_NULLPOINT;
if (unlikely(priority >= PRIORITY_LEVEL)) {
mdla_err("%s: %d illegal priority level\n", __func__, __LINE__);
return -EINVAL;
}
ret = mdla_pwr_ops_get()->on(core_id, false);
if (ret)
return ret;
pwron_t = sched_clock();
/* initial global variable */
spin_lock_irqsave(&sched->lock, flags);
if (unlikely(sched->ce[priority])) {
spin_unlock_irqrestore(&sched->lock, flags);
mdla_err("%s: %d has ce with same priority\n", __func__, __LINE__);
return -EINVAL;
}
ce = kzalloc(sizeof(struct command_entry), GFP_ATOMIC);
sched->ce[priority] = ce;
if (sched->pro_ce)
pro_boost_val = sched->pro_ce->boost_val;
spin_unlock_irqrestore(&sched->lock, flags);
if (ce == NULL)
return -ENOMEM;
mdla_pwr_ops_get()->wake_lock(core_id);
/* prepare CE */
mdla_cmd_prepare_v2_0_hw_sched(cd, apusys_hd, ce, priority);
out_end = apusys_hd->cmd_entry + apusys_hd->cmd_size;
if (mdla_cmd_plat_cb()->check_cmd_valid(out_end, ce) == false) {
spin_lock_irqsave(&sched->lock, flags);
kfree(sched->ce[priority]);
sched->ce[priority] = NULL;
spin_unlock_irqrestore(&sched->lock, flags);
return -EINVAL;
}
ce->poweron_t = pwron_t;
mdla_cmd_set_opp(core_id, ce, pro_boost_val);
mdla_util_apu_pmu_handle(mdla_info, apusys_hd, (u16)priority);
mdla_prof_start(core_id);
mdla_trace_begin(core_id, ce);
mdla_cmd_plat_cb()->pre_cmd_handle(core_id, ce);
spin_lock_irqsave(&sched->lock, flags);
if (sched->pro_ce == NULL) {
sched->pro_ce = ce;
sched->issue_ce(core_id);
} else {
sched->enqueue_ce(core_id, ce, 0);
if (ce->priority > sched->pro_ce->priority) {
/* preemption occur */
sched->stop_ce(core_id, ce);
}
}
spin_unlock_irqrestore(&sched->lock, flags);
/* wait for deadline */
while (ce->fin_cid < ce->count
&& time_before64(get_jiffies_64(), ce->deadline_t)) {
wait_for_completion_interruptible_timeout(
&ce->swcmd_done_wait,
mdla_cmd_plat_cb()->get_wait_time(core_id));
mdla_cmd_plat_cb()->wait_cmd_handle(core_id, ce);
if (ce->state & BIT(CE_FAIL))
goto error_handle;
}
mdla_cmd_plat_cb()->post_cmd_handle(core_id, ce);
mdla_cmd_plat_cb()->post_cmd_info(core_id);
if (unlikely(ce->fin_cid < ce->count))
ret = mdla_cmd_wrong_count_handler(mdla_info, ce);
apusys_hd->ip_time = (u32)ce->exec_time / 1000;
/* update id to the last finished command id */
cd->id = ce->fin_cid;
error_handle:
mdla_trace_end(core_id, 0, ce);
mdla_prof_iter(core_id);
mdla_util_apu_pmu_update(mdla_info, apusys_hd, (u16)priority);
spin_lock_irqsave(&sched->lock, flags);
kfree(sched->ce[priority]);
sched->ce[priority] = NULL;
spin_unlock_irqrestore(&sched->lock, flags);
mdla_pwr_ops_get()->off_timer_start(core_id);
mdla_pwr_ops_get()->wake_unlock(core_id);
mdla_prof_set_ts(core_id, TS_CMD_FINISH, sched_clock());
return ret;
}
int mdla_cmd_ut_run_sync_v2_0_hw_sched(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info)
{
return 0;
}
@@ -0,0 +1,348 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/sched/clock.h>
#if IS_ENABLED(CONFIG_MTK_GIC_V3_EXT)
#include <linux/irqchip/mtk-gic-extend.h>
#else
#define mt_irq_dump_status(n)
#endif
#include <apusys_device.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_ioctl.h>
#include <common/mdla_scheduler.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_trace.h>
#include <utilities/mdla_debug.h>
#include "mdla_cmd_data_v2_0.h"
#include "platform/v2_0/mdla_hw_reg_v2_0.h"
static void mdla_cmd_prepare_v2_0_sw_sched(struct mdla_run_cmd *cd,
struct apusys_cmd_hnd *apusys_hd,
struct command_entry *ce, uint32_t priority)
{
ce->mva = cd->mva + cd->offset;
ce->state = CE_NONE;
ce->flags = CE_NOP;
ce->bandwidth = 0;
ce->result = MDLA_SUCCESS;
ce->count = cd->count;
ce->receive_t = sched_clock();
ce->csn = (ce->mva & 0xFFFFFFFE) | priority;
ce->deadline_t = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
/* It is new command list */
ce->fin_cid = 0;
ce->wish_fin_cid = ce->count;
ce->irq_state = IRQ_SUCCESS;
ce->boost_val = apusys_hd->boost_val;
ce->ctx_id = apusys_hd->ctx_id;
ce->context_callback = apusys_hd->context_callback;
apusys_hd->ip_time = 0;
ce->cmdbuf = apusys_hd->cmdbuf;
ce->priority = priority;
ce->kva = (void *)apusys_mem_query_kva((u32)ce->mva);
/* Initialize timestamp*/
ce->exec_time = 0;
ce->poweron_t = 0;
ce->req_start_t = 0;
ce->req_end_t = 0;
if (apusys_hd->multicore_total == 2) {
ce->cmd_id = apusys_hd->cmd_id;
ce->multicore_total = apusys_hd->multicore_total;
ce->cmd_batch_size = cd->count + 1;
} else {
ce->cmd_batch_size = apusys_hd->cluster_size;
}
init_completion(&ce->swcmd_done_wait);
mdla_cmd_debug("%s: kva=0x%llx mva=0x%08x(0x%08x+0x%x) cnt=%u sz=0x%x\n",
__func__,
(u64)ce->kva,
ce->mva,
cd->mva,
cd->offset,
ce->count,
cd->size);
mdla_verbose("%s: ctx_id=%d apu_hd_core_num=%d prio=%d batch_sz=%d)\n",
__func__,
ce->ctx_id,
apusys_hd->multicore_total,
ce->priority,
ce->cmd_batch_size);
}
static void mdla_cmd_set_opp(u32 core_id, struct command_entry *ce, int boost_val)
{
if (ce->boost_val > boost_val)
boost_val = ce->boost_val;
else
boost_val = 0;
if (unlikely(mdla_dbg_read_u32(FS_DVFS_RAND)))
boost_val = mdla_pwr_get_random_boost_val();
if (boost_val)
mdla_pwr_ops_get()->set_opp_by_boost(core_id, boost_val);
}
static int mdla_cmd_wrong_count_handler(struct mdla_dev *mdla_info,
struct command_entry *ce)
{
struct command_entry *timeout_ce;
struct mdla_scheduler *sched = mdla_info->sched;
u32 core_id = mdla_info->mdla_id;
unsigned long flags;
int prio;
mdla_timeout_debug("Interrupt error status: %x\n",
mdla_info->error_bit);
mdla_info->error_bit = 0;
mdla_timeout_debug("Print current ce\n");
mdla_dbg_ce_info(core_id, ce);
mdla_timeout_debug("=====================\n");
if (sched->pro_ce != NULL) {
mdla_timeout_debug("Print process ce\n");
mdla_dbg_ce_info(core_id, sched->pro_ce);
mdla_timeout_debug("=====================\n");
}
for (prio = 0; prio < PRIORITY_LEVEL; prio++) {
if (!sched->ce[prio])
continue;
mdla_timeout_debug("Print ce in driver\n");
mdla_dbg_ce_info(core_id, sched->ce[prio]);
mdla_timeout_debug("=====================\n");
}
mdla_timeout_debug("core_id: %x, TS_HW_TRIGGER=%llu",
core_id, mdla_prof_get_ts(core_id, TS_HW_TRIGGER));
mdla_timeout_debug("core_id: %x, TS_HW_FIRST_TRIGGER=%llu",
core_id, mdla_prof_get_ts(core_id, TS_HW_FIRST_TRIGGER));
mdla_timeout_debug("core_id: %x, TS_HW_INTR=%llu",
core_id, mdla_prof_get_ts(core_id, TS_HW_INTR));
mdla_timeout_debug("core_id: %x, TS_HW_LAST_INTR=%llu",
core_id, mdla_prof_get_ts(core_id, TS_HW_LAST_INTR));
mdla_timeout_debug("core_id: %x, TS_CMD_RESUME=%llu",
core_id, mdla_prof_get_ts(core_id, TS_CMD_RESUME));
/* handle command timeout */
mdla_cmd_plat_cb()->post_cmd_hw_detect(core_id);
mt_irq_dump_status(mdla_cmd_plat_cb()->get_irq_num(core_id));
mdla_dbg_dump(mdla_info, ce);
/* Enable & Relase bus protect */
mdla_pwr_ops_get()->switch_off_on(core_id);
mdla_pwr_ops_get()->hw_reset(mdla_info->mdla_id,
mdla_dbg_get_reason_str(REASON_TIMEOUT));
/* error handling for scheudler by removing processing CE */
spin_lock_irqsave(&sched->lock, flags);
sched->pro_ce = NULL;
do {
timeout_ce = sched->dequeue_ce(core_id);
if (timeout_ce != NULL) {
timeout_ce->state |= (1 << CE_FAIL);
complete(&timeout_ce->swcmd_done_wait);
}
} while (timeout_ce != NULL);
spin_unlock_irqrestore(&sched->lock, flags);
return -REASON_MDLA_TIMEOUT;
}
int mdla_cmd_run_sync_v2_0_sw_sched(struct mdla_run_cmd_sync *cmd_data,
struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd,
uint32_t priority)
{
int ret = REASON_MDLA_SUCCESS;
unsigned long flags;
u64 pwron_t;
int pro_boost_val = 0;
struct mdla_run_cmd *cd = &cmd_data->req;
struct command_entry *ce;
struct mdla_scheduler *sched = mdla_info->sched;
uint64_t out_end;
u32 core_id = mdla_info->mdla_id;
if (!cd || (cd->count == 0) || (apusys_hd->cmdbuf == NULL)) {
mdla_err("%s: %d null check fail\n", __func__, __LINE__);
return -EINVAL;
}
/* need to define error code for scheduler is NULL */
if (!sched)
return -REASON_MDLA_NULLPOINT;
if (unlikely(priority >= PRIORITY_LEVEL)) {
mdla_err("%s: %d illegal priority level\n", __func__, __LINE__);
return -EINVAL;
}
ret = mdla_pwr_ops_get()->on(core_id, false);
if (ret)
return ret;
pwron_t = sched_clock();
/* initial global variable */
spin_lock_irqsave(&sched->lock, flags);
if (unlikely(sched->ce[priority])) {
spin_unlock_irqrestore(&sched->lock, flags);
mdla_err("%s: %d has ce with same priority\n", __func__, __LINE__);
return -EINVAL;
}
ce = kzalloc(sizeof(struct command_entry), GFP_ATOMIC);
sched->ce[priority] = ce;
if (sched->pro_ce)
pro_boost_val = sched->pro_ce->boost_val;
spin_unlock_irqrestore(&sched->lock, flags);
if (ce == NULL)
return -ENOMEM;
mdla_pwr_ops_get()->wake_lock(core_id);
/* prepare CE */
mdla_cmd_prepare_v2_0_sw_sched(cd, apusys_hd, ce, priority);
out_end = apusys_hd->cmd_entry + apusys_hd->cmd_size;
if (mdla_cmd_plat_cb()->check_cmd_valid(out_end, ce) == false) {
spin_lock_irqsave(&sched->lock, flags);
kfree(sched->ce[priority]);
sched->ce[priority] = NULL;
spin_unlock_irqrestore(&sched->lock, flags);
return -EINVAL;
}
ce->poweron_t = pwron_t;
mdla_cmd_set_opp(core_id, ce, pro_boost_val);
ce->batch_list_head = NULL;
if (priority == MDLA_LOW_PRIORITY && ce->cmd_batch_size < ce->count) {
ce->cmd_int_backup = kcalloc(ce->count, sizeof(uint32_t), GFP_KERNEL);
if (ce->cmd_int_backup != NULL) {
ce->cmd_ctrl_1_backup = kcalloc(ce->count, sizeof(uint32_t), GFP_KERNEL);
if (ce->cmd_ctrl_1_backup != NULL) {
mdla_sched_plat_cb()->backup_cmd_batch(ce);
mdla_sched_plat_cb()->split_alloc_cmd_batch(ce);
if (ce->batch_list_head == NULL) {
kfree(ce->cmd_int_backup);
kfree(ce->cmd_ctrl_1_backup);
}
} else
kfree(ce->cmd_int_backup);
}
}
mdla_util_apu_pmu_handle(mdla_info, apusys_hd, (u16)priority);
mdla_prof_start(core_id);
mdla_trace_begin(core_id, ce);
mdla_cmd_plat_cb()->pre_cmd_handle(core_id, ce);
if (ce->multicore_total > 1 && ce->priority == MDLA_LOW_PRIORITY) {
spin_lock_irqsave(&sched->lock, flags);
sched->enqueue_ce(core_id, ce, 0);
spin_unlock_irqrestore(&sched->lock, flags);
sched->issue_dual_lowce(core_id, ce->cmd_id);
} else {
spin_lock_irqsave(&sched->lock, flags);
if (sched->pro_ce == NULL) {
sched->pro_ce = ce;
sched->issue_ce(core_id);
} else {
sched->enqueue_ce(core_id, ce, 0);
}
spin_unlock_irqrestore(&sched->lock, flags);
}
/* wait for deadline */
while (ce->fin_cid < ce->count
&& time_before64(get_jiffies_64(), ce->deadline_t)) {
wait_for_completion_interruptible_timeout(
&ce->swcmd_done_wait,
mdla_cmd_plat_cb()->get_wait_time(core_id));
mdla_cmd_plat_cb()->wait_cmd_handle(core_id, ce);
if (ce->state & BIT(CE_FAIL))
goto error_handle;
}
mdla_cmd_plat_cb()->post_cmd_handle(core_id, ce);
mdla_cmd_plat_cb()->post_cmd_info(core_id);
if (unlikely(ce->fin_cid < ce->count))
ret = mdla_cmd_wrong_count_handler(mdla_info, ce);
apusys_hd->ip_time = (u32)ce->exec_time / 1000;
/* update id to the last finished command id */
cd->id = ce->fin_cid;
error_handle:
mdla_trace_end(core_id, 0, ce);
mdla_prof_iter(core_id);
mdla_util_apu_pmu_update(mdla_info, apusys_hd, (u16)priority);
if (priority == MDLA_LOW_PRIORITY && ce->batch_list_head != NULL) {
mdla_sched_plat_cb()->restore_cmd_batch(ce);
kfree(ce->cmd_int_backup);
kfree(ce->cmd_ctrl_1_backup);
}
spin_lock_irqsave(&sched->lock, flags);
if (priority == MDLA_LOW_PRIORITY && ce->batch_list_head != NULL)
mdla_sched_plat_cb()->del_free_cmd_batch(ce);
kfree(sched->ce[priority]);
sched->ce[priority] = NULL;
spin_unlock_irqrestore(&sched->lock, flags);
mdla_pwr_ops_get()->off_timer_start(core_id);
mdla_pwr_ops_get()->wake_unlock(core_id);
return ret;
}
int mdla_cmd_ut_run_sync_v2_0_sw_sched(void *run_cmd, void *wait_cmd,
struct mdla_dev *mdla_info)
{
return 0;
}
@@ -0,0 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_INTERFACE_H__
#define __MDLA_INTERFACE_H__
#include "mdla_cmd_proc_intf.h"
#include "mdla_power_ctrl_intf.h"
#endif /* __MDLA_INTERFACE_H__ */
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_POWER_CTRL_INTF_H__
#define __MDLA_POWER_CTRL_INTF_H__
int mdla_pwr_on_v1_0(u32 core_id, bool force);
int mdla_pwr_off_v1_0(u32 core_id, int suspend, bool force);
bool mdla_pwr_is_on_v1_0(u32 core_id);
int mdla_pwr_on_v1_x(u32 core_id, bool force);
int mdla_pwr_off_v1_x(u32 core_id, int suspend, bool force);
bool mdla_pwr_is_on_v1_x(u32 core_id);
int mdla_pwr_on_v2_0(u32 core_id, bool force);
int mdla_pwr_off_v2_0(u32 core_id, int suspend, bool force);
bool mdla_pwr_is_on_v2_0(u32 core_id);
#endif
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/of_device.h>
#include <linux/pm_wakeup.h>
#include <linux/sched/clock.h>
#include <apusys_power.h>
#include <common/mdla_device.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_debug.h>
int mdla_pwr_on_v1_0(u32 core_id, bool force)
{
int ret = 0;
struct mdla_dev *mdla_device = mdla_get_device(core_id);
enum DVFS_USER user_mdla = MDLA0 + core_id;
mdla_pwr_ops_get()->lock(core_id);
mdla_pwr_ops_get()->off_timer_cancel(core_id);
if (mdla_device->power_is_on) {
mdla_pwr_debug("%s: already on.\n", __func__);
goto power_on_done;
}
ret = apu_device_power_on(user_mdla);
if (!ret) {
mdla_pwr_debug("%s power on device %d success\n",
__func__, user_mdla);
mdla_device->power_is_on = true;
} else {
mdla_err("%s power on device %d fail\n",
__func__, user_mdla);
}
mdla_pwr_ops_get()->hw_reset(core_id,
mdla_dbg_get_reason_str(REASON_POWERON));
power_on_done:
mdla_pwr_ops_get()->unlock(core_id);
return ret;
}
int mdla_pwr_off_v1_0(u32 core_id,
int suspend, bool force)
{
int ret = 0;
struct mdla_dev *mdla_device = mdla_get_device(core_id);
enum DVFS_USER user_mdla = MDLA0 + core_id;
if (unlikely(!mdla_device))
return -1;
mutex_lock(&mdla_device->cmd_lock);
mdla_pwr_ops_get()->lock(core_id);
if (mdla_device->power_is_on == false)
goto power_off_done;
ret = apu_device_power_off(user_mdla);
if (!ret) {
mdla_pwr_debug("%s power off device %d success\n",
__func__, user_mdla);
mdla_device->power_is_on = false;
} else {
mdla_err("%s power off device %d fail\n",
__func__, user_mdla);
}
power_off_done:
mdla_pwr_ops_get()->unlock(core_id);
mutex_unlock(&mdla_device->cmd_lock);
return ret;
}
@@ -0,0 +1,126 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/of_device.h>
#include <linux/pm_wakeup.h>
#include <linux/sched/clock.h>
#include <apusys_power.h>
#include <common/mdla_device.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_debug.h>
int mdla_pwr_on_v1_x(u32 core_id, bool force)
{
int ret = 0;
u64 poweron_t;
struct mdla_dev *mdla_device = mdla_get_device(core_id);
enum DVFS_USER user_mdla = MDLA0 + core_id;
if (unlikely(!mdla_device))
return -1;
mdla_pwr_ops_get()->lock(core_id);
if (force == false) {
mdla_device->cmd_list_cnt++;
if (mdla_device->cmd_list_cnt > 1)
goto power_on_done;
}
mdla_device->sw_power_is_on = true;
mdla_pwr_ops_get()->off_timer_cancel(core_id);
if (mdla_device->power_is_on)
goto power_on_done;
poweron_t = sched_clock();
ret = apu_device_power_on(user_mdla);
if (!ret) {
mdla_pwr_debug("%s power on device %d (mdla core %d) success\n",
__func__, user_mdla, core_id);
mdla_device->power_is_on = true;
} else {
mdla_err("%s power on device %d (mdla core %d) fail(%d)\n",
__func__, user_mdla, core_id, ret);
if (force == false)
mdla_device->cmd_list_cnt--;
goto power_on_done;
}
mdla_pwr_debug("mdla %d: power on info: apu_device_power_on_time: %llu\n",
core_id, sched_clock() - poweron_t);
mdla_pwr_ops_get()->hw_reset(core_id,
mdla_dbg_get_reason_str(REASON_POWERON));
power_on_done:
mdla_pwr_ops_get()->unlock(core_id);
return ret;
}
int mdla_pwr_off_v1_x(u32 core_id,
int suspend, bool force)
{
int ret = 0;
int i;
struct mdla_dev *mdla_device = mdla_get_device(core_id);
if (unlikely(!mdla_device))
return -1;
for_each_mdla_core(i)
mdla_pwr_ops_get()->lock(i);
if (force == true)
mdla_device->cmd_list_cnt = 0;
if (mdla_device->cmd_list_cnt == 0)
mdla_device->sw_power_is_on = false;
if (mdla_device->power_is_on == false)
goto power_off_done;
mdla_pwr_ops_get()->off_timer_cancel(core_id);
for_each_mdla_core(i) {
if (mdla_get_device(i)->cmd_list_cnt >= 1)
goto power_off_done;
}
/* avoid multi core power down pollute, pdn multi core simultaneously */
for_each_mdla_core(i) {
if (mdla_get_device(i)->sw_power_is_on)
goto power_off_done;
}
for_each_mdla_core(i) {
if (mdla_get_device(i)->power_is_on == false)
continue;
ret = apu_device_power_suspend(MDLA0 + i, suspend);
if (!ret) {
mdla_pwr_debug("%s power off device %d (mdla-%d) success\n",
__func__, MDLA0 + i, i);
mdla_get_device(i)->power_is_on = false;
} else {
mdla_err("%s power off device %d (mdla-%d) fail(%d)\n",
__func__, MDLA0 + i, i, ret);
}
}
power_off_done:
for_each_mdla_core(i)
mdla_pwr_ops_get()->unlock(i);
return ret;
}
@@ -0,0 +1,113 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/of_device.h>
#include <linux/pm_wakeup.h>
#include <linux/sched/clock.h>
#include <apusys_power.h>
#include <common/mdla_device.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_debug.h>
int mdla_pwr_on_v2_0(u32 core_id, bool force)
{
int ret = 0;
u64 poweron_t;
struct mdla_dev *mdla_device = mdla_get_device(core_id);
enum DVFS_USER user_mdla = MDLA0 + core_id;
if (unlikely(!mdla_device))
return -1;
mdla_pwr_ops_get()->lock(core_id);
if (force == false) {
mdla_device->cmd_list_cnt++;
if (mdla_device->cmd_list_cnt > 1)
goto power_on_done;
}
mdla_device->sw_power_is_on = true;
mdla_pwr_ops_get()->off_timer_cancel(core_id);
if (mdla_device->power_is_on)
goto power_on_done;
poweron_t = sched_clock();
ret = apu_device_power_on(user_mdla);
if (!ret) {
mdla_pwr_debug("%s power on device %d (mdla core %d) success\n",
__func__, user_mdla, core_id);
mdla_device->power_is_on = true;
} else {
mdla_err("%s power on device %d (mdla core %d) fail(%d)\n",
__func__, user_mdla, core_id, ret);
if (force == false)
mdla_device->cmd_list_cnt--;
goto power_on_done;
}
mdla_pwr_debug("mdla %d: power on info: apu_device_power_on_time: %llu\n",
core_id, sched_clock() - poweron_t);
mdla_pwr_ops_get()->hw_reset(core_id,
mdla_dbg_get_reason_str(REASON_POWERON));
power_on_done:
mdla_pwr_ops_get()->unlock(core_id);
return 0;
}
int mdla_pwr_off_v2_0(u32 core_id,
int suspend, bool force)
{
int ret = 0;
struct mdla_dev *mdla_device = mdla_get_device(core_id);
if (unlikely(!mdla_device))
return -1;
mdla_pwr_ops_get()->lock(core_id);
if (force == true)
mdla_device->cmd_list_cnt = 0;
if (mdla_device->cmd_list_cnt == 0)
mdla_device->sw_power_is_on = false;
if (mdla_device->power_is_on == false)
goto power_off_done;
mdla_pwr_ops_get()->off_timer_cancel(core_id);
if (mdla_get_device(core_id)->cmd_list_cnt >= 1)
goto power_off_done;
if (mdla_get_device(core_id)->sw_power_is_on)
goto power_off_done;
ret = apu_device_power_suspend(MDLA0 + core_id, suspend);
if (!ret) {
mdla_pwr_debug("%s power off device %d (mdla-%d) success\n",
__func__, MDLA0 + core_id, core_id);
mdla_get_device(core_id)->power_is_on = false;
} else {
mdla_err("%s power off device %d (mdla-%d) fail(%d)\n",
__func__, MDLA0 + core_id, core_id, ret);
}
power_off_done:
mdla_pwr_ops_get()->unlock(core_id);
return ret;
}
@@ -0,0 +1,54 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_PLAT_API_H__
#define __MDLA_PLAT_API_H__
#include <linux/types.h>
#include <linux/of_device.h>
u32 mdla_plat_get_core_num(void);
/**
* [0:7] : minor version number
* [8:15] : major version number
* [16:31] : project
*/
#define get_minor_num(v) ((v) & 0xFF)
#define get_major_num(v) (((v) >> 8) & 0xFF)
#define get_proj_code(v) (((v) >> 16) & 0xFFFF)
u32 mdla_plat_get_version(void);
/* sw configuration */
bool mdla_plat_pwr_drv_ready(void);
bool mdla_plat_iommu_enable(void);
bool mdla_plat_nn_pmu_support(void);
bool mdla_plat_sw_preemption_support(void);
bool mdla_plat_hw_preemption_support(void);
bool mdla_plat_micro_p_support(void);
int mdla_plat_get_prof_ver(void);
#if IS_ENABLED(CONFIG_OF)
const struct of_device_id *mdla_plat_get_device(void);
#else
#define mdla_plat_get_device() NULL
#endif
#if IS_ENABLED(CONFIG_FPGA_EARLY_PORTING)
#include <common/mdla_power_ctrl.h>
#define mdla_fpga_reset() \
do { \
int i; \
for_each_mdla_core(i) \
mdla_pwr_ops_get()->hw_reset(i, \
mdla_dbg_get_reason_str(REASON_DRVINIT));\
} while (0)
#else
#define mdla_fpga_reset()
#endif
int mdla_plat_init(struct platform_device *pdev);
void mdla_plat_deinit(struct platform_device *pdev);
#endif /* __MDLA_PLAT_API_H__ */
@@ -0,0 +1,100 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/module.h>
#include <linux/of_device.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_debug.h>
#include "mdla_plat_internal.h"
static struct mdla_plat_drv mt6779_drv = {
.init = mdla_v1_0_init,
.deinit = mdla_v1_0_deinit,
.sw_cfg = 0,
.klog = (MDLA_DBG_CMD | MDLA_DBG_TIMEOUT),
.timeout_ms = 6000,
.off_delay_ms = 2000,
.polling_cmd_ms = 5,
.pmu_period_us = 1000,
.profile_ver = PROF_V1,
};
static struct mdla_plat_drv mt6873_drv = {
.init = mdla_v1_x_init,
.deinit = mdla_v1_x_deinit,
.sw_cfg = BIT(CFG_NN_PMU_SUPPORT)
| BIT(CFG_SW_PREEMPTION_SUPPORT),
.klog = (MDLA_DBG_CMD | MDLA_DBG_TIMEOUT),
.timeout_ms = 6000,
.off_delay_ms = 2000,
.polling_cmd_ms = 5,
.pmu_period_us = 1000,
.profile_ver = PROF_V1,
};
static struct mdla_plat_drv mt6885_drv = {
.init = mdla_v1_x_init,
.deinit = mdla_v1_x_deinit,
.sw_cfg = BIT(CFG_NN_PMU_SUPPORT)
| BIT(CFG_SW_PREEMPTION_SUPPORT),
.klog = (MDLA_DBG_CMD | MDLA_DBG_TIMEOUT),
.timeout_ms = 6000,
.off_delay_ms = 2000,
.polling_cmd_ms = 5,
.pmu_period_us = 1000,
.profile_ver = PROF_V1,
};
static struct mdla_plat_drv mt6893_drv = {
.init = mdla_v1_x_init,
.deinit = mdla_v1_x_deinit,
.sw_cfg = BIT(CFG_NN_PMU_SUPPORT)
| BIT(CFG_SW_PREEMPTION_SUPPORT),
.klog = (MDLA_DBG_CMD | MDLA_DBG_TIMEOUT),
.timeout_ms = 6000,
.off_delay_ms = 2000,
.polling_cmd_ms = 5,
.pmu_period_us = 1000,
.profile_ver = PROF_V1,
};
static struct mdla_plat_drv mt6877_drv = {
.init = mdla_v2_0_init,
.deinit = mdla_v2_0_deinit,
.sw_cfg = BIT(CFG_NN_PMU_SUPPORT)
| BIT(CFG_SW_PREEMPTION_SUPPORT),
.klog = (MDLA_DBG_CMD | MDLA_DBG_TIMEOUT),
.timeout_ms = 6000,
.off_delay_ms = 2000,
.polling_cmd_ms = 5,
.pmu_period_us = 1000,
.profile_ver = PROF_V1,
};
static struct mdla_plat_drv rv_drv = {
.init = mdla_rv_init,
.deinit = mdla_rv_deinit,
.sw_cfg = BIT(CFG_MICRO_P_SUPPORT),
.profile_ver = PROF_NONE,
};
static const struct of_device_id mdla_of_match[] = {
{ .compatible = "mediatek, mt6779-mdla", .data = &mt6779_drv},
{ .compatible = "mediatek, mt6873-mdla", .data = &mt6873_drv},
{ .compatible = "mediatek, mt6885-mdla", .data = &mt6885_drv},
{ .compatible = "mediatek, mt6893-mdla", .data = &mt6893_drv},
{ .compatible = "mediatek, mt6877-mdla", .data = &mt6877_drv},
{ .compatible = "mediatek, mdla-rv", .data = &rv_drv},
{ /* end of list */},
};
MODULE_DEVICE_TABLE(of, mdla_of_match);
const struct of_device_id *mdla_plat_get_device(void)
{
return mdla_of_match;
}
@@ -0,0 +1,139 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/types.h>
#include <linux/of_device.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_util.h>
#include "mdla_plat_internal.h"
static u32 nr_core_ids = 1;
static u32 default_polling_cmd_done;
static u32 mdla_ver;
/* SW configuration */
static bool pwr_rdy;
static bool mmu_en;
static bool nn_pmu_en;
static bool sw_preemption_en;
static bool hw_preemption_en;
static bool micro_p_en;
static int prof_ver;
u32 mdla_plat_get_core_num(void)
{
return nr_core_ids;
}
u32 mdla_plat_get_polling_cmd_time(void)
{
return default_polling_cmd_done;
}
u32 mdla_plat_get_version(void)
{
return mdla_ver;
}
bool mdla_plat_pwr_drv_ready(void)
{
return pwr_rdy;
}
bool mdla_plat_iommu_enable(void)
{
return mmu_en;
}
bool mdla_plat_nn_pmu_support(void)
{
return nn_pmu_en;
}
bool mdla_plat_sw_preemption_support(void)
{
return sw_preemption_en;
}
bool mdla_plat_hw_preemption_support(void)
{
return hw_preemption_en;
}
bool mdla_plat_micro_p_support(void)
{
return micro_p_en;
}
int mdla_plat_get_prof_ver(void)
{
return prof_ver;
}
int mdla_plat_init(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct mdla_plat_drv *drv;
u32 major_ver = 0;
of_property_read_u32(dev->of_node, "core_num", &nr_core_ids);
if (nr_core_ids > MAX_CORE_NUM) {
dev_info(dev, "Invalid core number: %d\n", nr_core_ids);
nr_core_ids = 1;
}
if (of_property_read_u32(pdev->dev.of_node, "version", &mdla_ver) == 0) {
dev_info(&pdev->dev, "ver = %x\n", mdla_ver);
mdla_dbg_set_version(mdla_ver);
}
drv = (struct mdla_plat_drv *)of_device_get_match_data(dev);
if (!drv)
return -1;
pwr_rdy = !(drv->sw_cfg & BIT(CFG_DUMMY_PWR));
mmu_en = !(drv->sw_cfg & BIT(CFG_DUMMY_MMU));
nn_pmu_en = !!(drv->sw_cfg & BIT(CFG_NN_PMU_SUPPORT));
sw_preemption_en = !!(drv->sw_cfg & BIT(CFG_SW_PREEMPTION_SUPPORT));
hw_preemption_en = !!(drv->sw_cfg & BIT(CFG_HW_PREEMPTION_SUPPORT));
micro_p_en = !!(drv->sw_cfg & BIT(CFG_MICRO_P_SUPPORT));
if (sw_preemption_en && hw_preemption_en)
sw_preemption_en = false;
mdla_dbg_write_u64(FS_CFG_PMU_PERIOD, drv->pmu_period_us);
mdla_dbg_write_u32(FS_KLOG, drv->klog);
mdla_dbg_write_u32(FS_POWEROFF_TIME, drv->off_delay_ms);
mdla_dbg_write_u32(FS_POLLING_CMD_DONE, drv->polling_cmd_ms);
mdla_dbg_write_u32(FS_TIMEOUT, drv->timeout_ms);
major_ver = mdla_util_get_ip_version();
if ((major_ver == 1) || (major_ver == 2)) {
mdla_dbg_write_u32(FS_CFG_ENG0, 0x0);
mdla_dbg_write_u32(FS_CFG_ENG1, 0x0);
mdla_dbg_write_u32(FS_CFG_ENG2, 0x0);
mdla_dbg_write_u32(FS_CFG_ENG11, 0x600);
}
prof_ver = drv->profile_ver;
dev_info(dev, "core number = %d, sw_cfg = 0x%x\n",
nr_core_ids, drv->sw_cfg);
return drv->init(pdev);
}
void mdla_plat_deinit(struct platform_device *pdev)
{
struct mdla_plat_drv *drv;
drv = (struct mdla_plat_drv *)of_device_get_match_data(&pdev->dev);
if (drv)
drv->deinit(pdev);
}
@@ -0,0 +1,49 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_PLAT_INTERNAL_H__
#define __MDLA_PLAT_INTERNAL_H__
#include <linux/platform_device.h>
enum PLAT_SW_CONFIG {
CFG_DUMMY_PWR,
CFG_DUMMY_MMU,
CFG_DUMMY_MID,
CFG_NN_PMU_SUPPORT,
CFG_SW_PREEMPTION_SUPPORT,
CFG_HW_PREEMPTION_SUPPORT,
CFG_MICRO_P_SUPPORT,
SW_CFG_MAX
};
struct mdla_plat_drv {
int (*init)(struct platform_device *pdev);
void (*deinit)(struct platform_device *pdev);
unsigned int sw_cfg;
unsigned int klog;
unsigned int timeout_ms;
unsigned int off_delay_ms;
unsigned int polling_cmd_ms;
unsigned int pmu_period_us;
unsigned int rv_ver;
int profile_ver;
};
int mdla_v1_0_init(struct platform_device *pdev);
void mdla_v1_0_deinit(struct platform_device *pdev);
int mdla_v1_x_init(struct platform_device *pdev);
void mdla_v1_x_deinit(struct platform_device *pdev);
int mdla_v2_0_init(struct platform_device *pdev);
void mdla_v2_0_deinit(struct platform_device *pdev);
int mdla_rv_init(struct platform_device *pdev);
void mdla_rv_deinit(struct platform_device *pdev);
#endif /* __MDLA_PLAT_INTERNAL_H__ */
@@ -0,0 +1,138 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_device.h>
#include <linux/debugfs.h>
#include <linux/mutex.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_ipi.h>
#include <platform/mdla_plat_api.h>
#define DBGFS_PMU_NAME "pmu_reg"
#define DBGFS_USAGE_NAME "help"
static struct mdla_dev *mdla_plat_devices;
struct mdla_dbgfs_ipi_file {
char *str;
u64 val;
umode_t mode;
const struct file_operations *fops;
};
DEFINE_IPI_DBGFS_ATTRIBUTE(klog, MDLA_IPI_KLOG, 0, "0x%llx\n");
DEFINE_IPI_DBGFS_ATTRIBUTE(timeout, MDLA_IPI_TIMEOUT, 0, "%llu ms\n");
DEFINE_IPI_DBGFS_ATTRIBUTE(pwrtime, MDLA_IPI_PWR_TIME, 0, "%llu ms\n");
static struct mdla_dbgfs_ipi_file ipi_dbgfs_file[NF_MDLA_IPI_TYPE_0 + 1] = {
[MDLA_IPI_PWR_TIME] = { .str = "poweroff_time",
.mode = 0660, .fops = &pwrtime_fops},
[MDLA_IPI_TIMEOUT] = { .str = "timeout",
.mode = 0660, .fops = &timeout_fops},
[MDLA_IPI_KLOG] = { .str = "klog",
.mode = 0660, .fops = &klog_fops},
[NF_MDLA_IPI_TYPE_0] = { .str = "unknown"},
};
static int mdla_plat_init_fw(void)
{
/* TODO: Nofity uP of firmware address */
return 0;
}
#if 0
static int mdla_plat_register_show(struct seq_file *s, void *data)
{
return 0;
}
static int mdla_plat_dbgfs_usage(struct seq_file *s, void *data)
{
return 0;
}
static void mdla_plat_dbgfs_init(struct device *dev, struct dentry *parent)
{
struct mdla_dbgfs_ipi_file *file;
int i;
if (!dev || !parent)
return;
debugfs_create_devm_seqfile(dev, DBGFS_PMU_NAME, parent,
mdla_plat_register_show);
debugfs_create_devm_seqfile(dev, DBGFS_USAGE_NAME, parent,
mdla_plat_dbgfs_usage);
for (i = 0; i < NF_MDLA_IPI_TYPE_0; i++) {
file = &ipi_dbgfs_file[i];
debugfs_create_file(file->str, file->mode, parent, &file->val, file->fops);
}
}
#endif
/* platform public functions */
int mdla_rv_init(struct platform_device *pdev)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
dev_info(&pdev->dev, "%s()\n", __func__);
mdla_plat_devices = devm_kzalloc(&pdev->dev,
nr_core_ids * sizeof(struct mdla_dev),
GFP_KERNEL);
if (!mdla_plat_devices)
return -1;
mdla_set_device(mdla_plat_devices, nr_core_ids);
for (i = 0; i < nr_core_ids; i++) {
mdla_plat_devices[i].mdla_id = i;
mdla_plat_devices[i].dev = &pdev->dev;
}
if (mdla_plat_init_fw())
return -1;
if (mdla_plat_pwr_drv_ready()) {
if (mdla_pwr_device_register(pdev, NULL, NULL))
return -1;
}
mdla_ipi_init();
#if 0
mdla_dbg_plat_cb()->dbgfs_plat_init = mdla_plat_dbgfs_init;
ipi_dbgfs_file[MDLA_IPI_KLOG].val = mdla_dbg_read_u32(FS_KLOG);
ipi_dbgfs_file[MDLA_IPI_PWR_TIME].val = mdla_dbg_read_u32(FS_POWEROFF_TIME);
ipi_dbgfs_file[MDLA_IPI_TIMEOUT].val = mdla_dbg_read_u32(FS_TIMEOUT);
#endif
/* Initialize uP debug parameters */
for (i = 0; i < NF_MDLA_IPI_TYPE_0; i++)
mdla_ipi_send(i, 0, ipi_dbgfs_file[i].val);
return 0;
}
void mdla_rv_deinit(struct platform_device *pdev)
{
dev_info(&pdev->dev, "%s()\n", __func__);
mdla_ipi_deinit();
if (mdla_plat_pwr_drv_ready()
&& mdla_pwr_device_unregister(pdev))
dev_info(&pdev->dev, "unregister mdla power fail\n");
}
@@ -0,0 +1,139 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_V1_0_HW_REG_H__
#define __MDLA_V1_0_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 CFG_PMCR (0x0E00)
#define PMU_CLK_CNT (0x0E04)
#define PMU_START_TSTAMP (0x0E08)
#define PMU_END_TSTAMP (0x0E0C)
#define PMU1 (0x0E10)
#define PMU1_CNT (0x0E14)
#define PMU1_CNT_LATCH (0x0E18)
#define PMU_CMDID_LATCH (0x0F00)
/* id: 0 ~ 14 */
#define PMU(id) (0x10 * (id) + PMU1)
#define PMU_CNT(id) (0x10 * (id) + PMU1_CNT)
#define PMU_CNT_LATCH(id) (0x10 * (id) + PMU1_CNT_LATCH)
/* CFG_PMCR : 0xE00 */
#define PMU_CNT_EN(i) BIT(17 + (i))
#define PMU_CCNT_EN BIT(16)
#define PMU_PERCMD_MODE BIT(5)
#define PMU_EXPORT BIT(4)
#define PMU_CCNT_RESET BIT(2)
#define PMU_CNT_RESET BIT(1)
#define PMU_ENABLE BIT(0)
#endif /* __MDLA_V1_0_HW_REG_H__ */
@@ -0,0 +1,122 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_irq.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <common/mdla_driver.h>
#include <common/mdla_device.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_util.h>
#include "mdla_hw_reg_v1_0.h"
struct mdla_irq {
u32 irq;
struct mdla_dev *dev;
};
static int handle_num;
static struct mdla_irq *mdla_irq_desc;
/* platform static function */
static irqreturn_t mdla_irq_handler(int irq, void *dev_id)
{
u32 status_int, id;
unsigned long flags;
struct mdla_dev *mdla_device = (struct mdla_dev *)dev_id;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
struct mdla_pmu_info *pmu;
u32 core_id;
if (unlikely(!mdla_device))
return IRQ_HANDLED;
core_id = mdla_device->mdla_id;
spin_lock_irqsave(&mdla_device->hw_lock, flags);
status_int = io->cmde.read(core_id, MREG_TOP_G_INTP0);
id = io->cmde.read(core_id, MREG_TOP_G_FIN0);
//mdla_pmu_reg_save(mdla_device->mdla_id, &mdla_device->pmu_info[0]);
pmu = mdla_util_pmu_ops_get()->get_info(core_id, 0);
if (pmu)
mdla_util_pmu_ops_get()->reg_counter_save(core_id, pmu);
/* avoid max_cmd_id lost after timeout reset */
if (id > mdla_device->max_cmd_id)
mdla_device->max_cmd_id = id;
if (status_int & MDLA_IRQ_PMU_INTE)
io->cmde.write(core_id, MREG_TOP_G_INTP0, MDLA_IRQ_PMU_INTE);
spin_unlock_irqrestore(&mdla_device->hw_lock, flags);
complete(&mdla_device->command_done);
return IRQ_HANDLED;
}
/* platform public function */
int mdla_v1_0_irq_request(struct device *dev, int irqdesc_num)
{
int i;
struct mdla_irq *irq_desc;
struct device_node *node = dev->of_node;
if (!node) {
dev_info(dev, "get mdla device node err\n");
return -1;
}
mdla_irq_desc = kcalloc(irqdesc_num, sizeof(struct mdla_irq),
GFP_KERNEL);
if (!mdla_irq_desc)
return -1;
handle_num = irqdesc_num;
for (i = 0; i < irqdesc_num; i++) {
irq_desc = &mdla_irq_desc[i];
irq_desc->dev = mdla_get_device(i);
irq_desc->irq = irq_of_parse_and_map(node, i);
if (!irq_desc->irq) {
dev_info(dev, "get mdla irq: %d failed\n", i);
goto err;
}
if (request_irq(irq_desc->irq, mdla_irq_handler,
irq_get_trigger_type(irq_desc->irq),
DRIVER_NAME, irq_desc->dev)) {
dev_info(dev, "mtk_mdla[%d]: Could not allocate interrupt %d.\n",
i, irq_desc->irq);
}
dev_info(dev, "request_irq %d done\n", irq_desc->irq);
}
return 0;
err:
kfree(mdla_irq_desc);
return -1;
}
void mdla_v1_0_irq_release(struct device *dev)
{
int i;
for (i = 0; i < handle_num; i++)
free_irq(mdla_irq_desc[i].irq, mdla_irq_desc[i].dev);
kfree(mdla_irq_desc);
}
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_V1_0_IRQ_H__
#define __MDLA_V1_0_IRQ_H__
#include <linux/device.h>
int mdla_v1_0_irq_request(struct device *dev, int irqdesc_num);
int mdla_v1_0_irq_release(struct device *dev);
#endif /* __MDLA_V1_0_IRQ_H__ */
@@ -0,0 +1,665 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <apusys_device.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_ioctl.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_profile.h>
#include "mdla_hw_reg_v1_0.h"
#include <interface/mdla_cmd_data_v1_0.h>
#define biu_read(id, ofs) \
mdla_util_io_ops_get()->biu.read(id, ofs)
#define biu_write(id, ofs, val) \
mdla_util_io_ops_get()->biu.write(id, ofs, val)
#define biu_set_b(id, ofs, val) \
mdla_util_io_ops_get()->biu.set_b(id, ofs, val)
#define biu_clr_b(id, ofs, val) \
mdla_util_io_ops_get()->biu.clr_b(id, ofs, val)
struct mdla_pmu_dev {
spinlock_t lock;
DECLARE_BITMAP(pmu_bitmap, MDLA_PMU_COUNTERS);
u32 cfg_event[MDLA_PMU_COUNTERS];
};
struct mdla_pmu_data {
u8 cfg_percmd_mode;
u16 l_cmd_cnt;
u16 l_cmd_id;
u32 l_start_t;
u32 l_end_t;
u32 l_cycle;
u32 l_counters[MDLA_PMU_COUNTERS];
u32 event_handle[MDLA_PMU_COUNTERS];
};
/* pmu info handle (sync with NN)*/
struct mdla_pmu_hnd {
u32 graph_id;//need confirm apusys mid data type
u32 offset_to_PMU_res_buf0;//base addr: pmu_kva
u32 offset_to_PMU_res_buf1;
u8 mode;
u8 number_of_event;
u16 event[MDLA_PMU_COUNTERS];
};
struct mdla_pmu_info {
u64 cmd_id;
u64 PMU_res_buf_addr;
struct mdla_pmu_hnd *pmu_hnd;
struct mdla_pmu_data data;
spinlock_t lock;
u32 number_of_event;
u8 pmu_mode;
};
static u32 mdla_pmu_get_perf_end(struct mdla_pmu_info *pmu)
{
return pmu->data.l_end_t;
}
static u32 mdla_pmu_get_perf_cycle(struct mdla_pmu_info *pmu)
{
return pmu->data.l_cycle;
}
static u16 mdla_pmu_get_perf_cmdid(struct mdla_pmu_info *pmu)
{
return pmu->data.l_cmd_id;
}
static u16 mdla_pmu_get_perf_cmdcnt(struct mdla_pmu_info *pmu)
{
return pmu->data.l_cmd_cnt;
}
static u32 mdla_pmu_get_counter(struct mdla_pmu_info *pmu, u32 idx)
{
return pmu->data.l_counters[idx];
}
static int mdla_pmu_get_mode(struct mdla_pmu_info *pmu)
{
return (int)pmu->pmu_mode;
}
static u32 mdla_pmu_get_hnd_evt(struct mdla_pmu_info *pmu, u32 counter_idx)
{
return pmu->pmu_hnd->event[counter_idx];
}
static u32 mdla_pmu_get_hnd_evt_num(struct mdla_pmu_info *pmu)
{
return pmu->pmu_hnd->number_of_event;
}
static u32 mdla_pmu_get_hnd_mode(struct mdla_pmu_info *pmu)
{
return pmu->pmu_hnd->mode;
}
static u64 mdla_pmu_get_hnd_buf_addr(struct mdla_pmu_info *pmu)
{
return pmu->PMU_res_buf_addr;
}
static void mdla_pmu_set_evt_handle(struct mdla_pmu_info *pmu,
u32 counter_idx, u32 val)
{
pmu->data.event_handle[counter_idx] = val;
}
static struct mdla_pmu_info *mdla_pmu_get_info(u32 core_id, u16 priority)
{
return &mdla_get_device(core_id)->pmu_info[priority];
}
/* extract pmu_hnd form pmu_kva and set mdla_info->pmu */
static int mdla_pmu_cmd_prepare(struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd, u16 priority)
{
u64 ofs_buf_addr;
struct mdla_pmu_info *pmu;
pmu = &mdla_info->pmu_info[priority];
if (pmu->pmu_mode >= CMD_MODE_MAX)
return -1;
pmu->pmu_hnd =
(struct mdla_pmu_hnd *)apusys_hd->pmu_kva;
pmu->cmd_id = apusys_hd->cmd_id;
if (mdla_info->mdla_id == 0)
ofs_buf_addr = pmu->pmu_hnd->offset_to_PMU_res_buf0;
else if (mdla_info->mdla_id == 1)
ofs_buf_addr = pmu->pmu_hnd->offset_to_PMU_res_buf1;
else
return -1;
pmu->PMU_res_buf_addr = apusys_hd->cmd_entry + ofs_buf_addr;
if (pmu->pmu_mode == PER_CMD)
mdla_util_pmu_cmd_timer(true);
mdla_pmu_debug("pmu addr: %08llx\n", pmu->PMU_res_buf_addr);
return 0;
}
static bool mdla_pmu_apusys_valid(struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd, u16 priority)
{
struct mdla_pmu_info *pmu;
struct mdla_run_cmd_sync *cmd_data;
struct mdla_run_cmd *cd;
uint32_t count;
uint64_t out_size = 0;
uint64_t out_end = 0;
uint32_t out_length = 0;
uint32_t repeat_sz = 0;
uint32_t evt_num = 0;
uint32_t sz = 0;
cmd_data = (struct mdla_run_cmd_sync *)apusys_hd->kva;
cd = &cmd_data->req;
count = cd->count;
pmu = &mdla_info->pmu_info[priority];
evt_num = mdla_pmu_get_hnd_evt_num(pmu);
if (evt_num > MDLA_PMU_COUNTERS)
return false;
out_end = apusys_hd->cmd_entry + apusys_hd->cmd_size;
if (apusys_hd->cmd_entry > pmu->PMU_res_buf_addr)
return false;
if (out_end < pmu->PMU_res_buf_addr)
return false;
out_size = out_end - pmu->PMU_res_buf_addr;
if (pmu->pmu_mode == PER_CMD) {
if (out_size < sizeof(u16))
return false;
repeat_sz = sizeof(u16) + sizeof(u32) * (evt_num + 1);
out_length = (out_size - sizeof(u16)) / repeat_sz;
if (out_length < count)
return false;
} else if (pmu->pmu_mode == NORMAL) {
sz = sizeof(u16) * 2 + sizeof(u32) * (evt_num + 1);
if (out_size < sz)
return false;
}
return true;
}
static int mdla_pmu_event_write(u32 core_id, u32 handle, u32 val)
{
if (val == COUNTER_CLEAR) {
mdla_pmu_debug("%s: clear pmu counter[%d]\n",
__func__, handle);
biu_write(core_id, PMU(handle), 0);
biu_clr_b(core_id, CFG_PMCR, PMU_CNT_EN(handle));
} else {
mdla_pmu_debug("%s: set pmu counter[%d] = 0x%x\n",
__func__, handle, val);
biu_write(core_id, PMU(handle), val);
biu_set_b(core_id, CFG_PMCR, PMU_CNT_EN(handle));
}
return 0;
}
static void mdla_pmu_event_write_all(u32 core_id, u16 priority)
{
int i, cnt;
u32 val;
struct mdla_pmu_info *pmu;
pmu = &(mdla_get_device(core_id)->pmu_info[priority]);
cnt = mdla_prof_use_dbgfs_pmu_event(core_id)
? MDLA_PMU_COUNTERS : pmu->number_of_event;
for (i = 0; i < cnt; i++) {
val = i < MDLA_PMU_COUNTERS ?
pmu->data.event_handle[i] : COUNTER_CLEAR;
mdla_pmu_event_write(core_id, i, val);
}
}
static u32 mdla_pmu_get_num_evt(u32 core_id, u16 priority)
{
if (mdla_prof_use_dbgfs_pmu_event(core_id))
return MDLA_PMU_COUNTERS;
if (priority >= PRIORITY_LEVEL)
return 0;
return mdla_get_device(core_id)->pmu_info[priority].number_of_event;
}
static void mdla_pmu_set_num_evt(u32 core_id, u16 prio, u32 val)
{
if (prio < PRIORITY_LEVEL)
mdla_get_device(core_id)->pmu_info[prio].number_of_event = val;
}
#define pmu_is_percmd_mode(i)\
(biu_read(i, CFG_PMCR) & PMU_PERCMD_MODE)
/* for mdla_trace and apusys_hnd */
static void mdla_pmu_counter_read_all(u32 core_id, u32 out[MDLA_PMU_COUNTERS])
{
int i;
if (pmu_is_percmd_mode(core_id)) {
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
out[i] += biu_read(core_id, PMU_CNT_LATCH(i));
} else {
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
out[i] += biu_read(core_id, PMU_CNT(i));
}
}
static void mdla_pmu_counter_disable_all(u32 core_id)
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
biu_clr_b(core_id, CFG_PMCR, PMU_CNT_EN(i));
}
static void mdla_pmu_counter_enable_all(u32 core_id)
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++) {
if (biu_read(core_id, PMU(i)))
biu_set_b(core_id, CFG_PMCR, PMU_CNT_EN(i));
}
}
/* save pmu registers for query after power off */
static void mdla_pmu_counter_save(u32 core_id, struct mdla_pmu_info *pmu)
{
if (pmu->pmu_mode == NORMAL) {
pmu->data.l_cmd_cnt = 1;
pmu->data.l_cmd_id = 0;
} else {
u32 val = biu_read(core_id, PMU_CMDID_LATCH);
if (val != pmu->data.l_cmd_id) {
pmu->data.l_cmd_cnt++;
pmu->data.l_cmd_id = (u16)val;
}
}
pmu->data.l_cycle +=
biu_read(core_id, PMU_CLK_CNT);
pmu->data.l_end_t +=
biu_read(core_id, PMU_END_TSTAMP);
pmu->data.l_start_t =
biu_read(core_id, PMU_START_TSTAMP);
mdla_pmu_counter_read_all(core_id, pmu->data.l_counters);
}
/* it save mode setting to local variable */
static void mdla_pmu_percmd_mode_set(struct mdla_pmu_info *pmu, u32 mode)
{
pmu->data.cfg_percmd_mode = mode;
}
/* for ioctrl */
static void mdla_pmu_percmd_mode_write(u32 core_id, struct mdla_pmu_info *pmu)
{
if (pmu->data.cfg_percmd_mode)
biu_set_b(core_id, CFG_PMCR, PMU_PERCMD_MODE);
else
biu_clr_b(core_id, CFG_PMCR, PMU_PERCMD_MODE);
}
/* for ioctrl */
static int mdla_pmu_counter_event_set(u32 core_id, int handle, u32 val)
{
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
if (handle < MDLA_PMU_COUNTERS)
pmu_dev->cfg_event[handle] = val;
mdla_pmu_event_write(core_id, handle, val);
return 0;
}
/* for ioctrl */
static int mdla_pmu_counter_event_get(u32 core_id, int handle)
{
u32 event;
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
event = pmu_dev->cfg_event[handle];
return (event == COUNTER_CLEAR) ? -ENOENT : event;
}
static void mdla_pmu_reset_counter_variable(struct mdla_pmu_info *pmu)
{
int i;
unsigned long flags;
spin_lock_irqsave(&pmu->lock, flags);
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
pmu->data.l_counters[i] = 0;
pmu->data.l_cmd_id = 0;
pmu->data.l_cmd_cnt = 0;
spin_unlock_irqrestore(&pmu->lock, flags);
}
static void mdla_pmu_reset_cycle_variable(struct mdla_pmu_info *pmu)
{
unsigned long flags;
spin_lock_irqsave(&pmu->lock, flags);
pmu->data.l_cycle = 0;
pmu->data.l_end_t = 0;
pmu->data.l_start_t = 0;
spin_unlock_irqrestore(&pmu->lock, flags);
}
static void mdla_pmu_reset_counter_no_lock(u32 core_id)
{
mdla_pmu_debug("mdla: %s\n", __func__);
/*Reset Clock counter to zero. Return to zero when reset done.*/
biu_set_b(core_id, CFG_PMCR, PMU_CNT_RESET);
while ((biu_read(core_id, CFG_PMCR) & PMU_CNT_RESET)
!= 0) {
}
}
static void mdla_pmu_reset_counter(u32 core_id)
{
unsigned long flags;
struct mdla_pmu_dev *pmu_dev;
pmu_dev = mdla_get_device(core_id)->pmu_dev;
spin_lock_irqsave(&pmu_dev->lock, flags);
mdla_pmu_reset_counter_no_lock(core_id);
spin_unlock_irqrestore(&pmu_dev->lock, flags);
}
static void mdla_pmu_reset_cycle(u32 core_id)
{
mdla_pmu_debug("mdla: %s\n", __func__);
biu_set_b(core_id,
CFG_PMCR,
(PMU_CCNT_EN | PMU_CCNT_RESET));
while ((biu_read(core_id, CFG_PMCR) & PMU_CCNT_RESET)
!= 0) {
}
}
static void mdla_pmu_reset(u32 core_id)
{
int i;
biu_write(core_id, CFG_PMCR,
(CFG_PMCR_DEFAULT | PMU_CCNT_RESET | PMU_CNT_RESET));
while ((biu_read(core_id, CFG_PMCR) &
(PMU_CCNT_RESET | PMU_CNT_RESET)) != 0) {
}
/* reset to 0 */
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
mdla_pmu_event_write(core_id, i, COUNTER_CLEAR);
/* reset to normal */
biu_clr_b(core_id, CFG_PMCR, PMU_PERCMD_MODE);
mdla_pmu_debug("mdla: %s, CFG_PMCR: 0x%x\n",
__func__, biu_read(core_id, CFG_PMCR));
}
/* for ioctrl */
static int mdla_pmu_counter_alloc(u32 core_id)
{
unsigned long flags;
int handle;
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if (unlikely(!pmu_dev))
return -ENODEV;
spin_lock_irqsave(&pmu_dev->lock, flags);
handle = bitmap_find_free_region(pmu_dev->pmu_bitmap,
MDLA_PMU_COUNTERS, 0);
spin_unlock_irqrestore(&pmu_dev->lock, flags);
if (unlikely(handle < 0))
return -EINVAL;
return handle;
}
/* for ioctrl */
static int mdla_pmu_counter_free(u32 core_id, int handle)
{
unsigned long flags;
int ret = 0;
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
spin_lock_irqsave(&pmu_dev->lock, flags);
bitmap_release_region(pmu_dev->pmu_bitmap, handle, 0);
mdla_pmu_event_write(core_id, handle, COUNTER_CLEAR);
spin_unlock_irqrestore(&pmu_dev->lock, flags);
return ret;
}
static int mdla_pmu_ioctl(struct file *filp,
u32 command, unsigned long arg, bool need_pwr_on)
{
long retval = 0;
struct mdla_dev *mdla_device;
struct mdla_pmu_info *pmu_info;
struct ioctl_perf perf_data;
u32 core_id;
int cnt_idx = 0;
int i;
if (copy_from_user(&perf_data, (void *) arg, sizeof(perf_data)))
return -EFAULT;
core_id = perf_data.mdlaid;
if (core_id_is_invalid(core_id))
return -EINVAL;
mdla_device = mdla_get_device(core_id);
/* set priority level = 1 for ioctl */
pmu_info = &mdla_device->pmu_info[0];
if (need_pwr_on) {
mdla_pwr_ops_get()->lock(core_id);
if (mdla_device->power_is_on == false) {
mdla_err("mdla%d power off, pmu ioctl FAIL\n", core_id);
goto out;
}
}
switch (command) {
case IOCTL_PERF_SET_EVENT:
perf_data.handle = mdla_pmu_counter_alloc(core_id);
if (perf_data.handle >= 0)
mdla_pmu_counter_event_set(core_id,
perf_data.handle,
(perf_data.interface << 16) | perf_data.event);
break;
case IOCTL_PERF_UNSET_EVENT:
mdla_pmu_counter_free(core_id, perf_data.handle);
break;
case IOCTL_PERF_GET_EVENT:
perf_data.event = mdla_pmu_counter_event_get(
core_id, perf_data.handle);
break;
case IOCTL_PERF_GET_CNT:
cnt_idx = perf_data.handle;
if (cnt_idx < MDLA_PMU_COUNTERS && cnt_idx >= 0)
perf_data.counter = pmu_info->data.l_counters[cnt_idx];
break;
case IOCTL_PERF_GET_START:
perf_data.start = pmu_info->data.l_start_t;
break;
case IOCTL_PERF_GET_END:
perf_data.end = pmu_info->data.l_end_t;
break;
case IOCTL_PERF_GET_CYCLE:
perf_data.start = pmu_info->data.l_cycle;
break;
case IOCTL_PERF_RESET_CNT:
mdla_cmd_ops_get()->lock(mdla_device);
for (i = 0; i < PRIORITY_LEVEL; i++)
mdla_pmu_reset_counter_variable(
&mdla_device->pmu_info[i]);
mdla_pmu_reset_counter(core_id);
mdla_cmd_ops_get()->unlock(mdla_device);
break;
case IOCTL_PERF_RESET_CYCLE:
mdla_cmd_ops_get()->lock(mdla_device);
for (i = 0; i < PRIORITY_LEVEL; i++)
mdla_pmu_reset_cycle_variable(
&mdla_device->pmu_info[i]);
mdla_pmu_reset_cycle(core_id);
mdla_cmd_ops_get()->unlock(mdla_device);
break;
case IOCTL_PERF_SET_MODE:
mdla_cmd_ops_get()->lock(mdla_device);
mdla_pmu_percmd_mode_set(pmu_info, perf_data.mode);
mdla_pmu_percmd_mode_write(core_id, pmu_info);
mdla_cmd_ops_get()->unlock(mdla_device);
break;
default:
break;
}
if (copy_to_user((void *) arg, &perf_data, sizeof(perf_data)))
retval = -EFAULT;
out:
if (need_pwr_on)
mdla_pwr_ops_get()->unlock(core_id);
return retval;
}
void mdla_v1_0_pmu_init(struct mdla_dev *mdla_info)
{
int i;
struct mdla_pmu_info *info;
struct mdla_pmu_dev *dev;
struct mdla_util_pmu_ops *pmu_ops = mdla_util_pmu_ops_get();
info = kcalloc(PRIORITY_LEVEL, sizeof(struct mdla_pmu_info),
GFP_KERNEL);
if (!info)
return;
dev = kzalloc(sizeof(struct mdla_pmu_dev), GFP_KERNEL);
if (!dev) {
kfree(info);
return;
}
for (i = 0; i < PRIORITY_LEVEL; i++) {
info[i].data.cfg_percmd_mode = NORMAL;
spin_lock_init(&info[i].lock);
}
spin_lock_init(&dev->lock);
mdla_info->pmu_dev = dev;
mdla_info->pmu_info = info;
mdla_ioctl_register_perf_handle(mdla_pmu_ioctl);
pmu_ops->reg_counter_save = mdla_pmu_counter_save;
pmu_ops->reg_counter_read = mdla_pmu_counter_read_all;
pmu_ops->clr_counter_variable = mdla_pmu_reset_counter_variable;
pmu_ops->clr_cycle_variable = mdla_pmu_reset_cycle_variable;
pmu_ops->get_num_evt = mdla_pmu_get_num_evt;
pmu_ops->set_num_evt = mdla_pmu_set_num_evt;
pmu_ops->set_percmd_mode = mdla_pmu_percmd_mode_set;
pmu_ops->get_curr_mode = mdla_pmu_get_mode;
pmu_ops->get_perf_end = mdla_pmu_get_perf_end;
pmu_ops->get_perf_cycle = mdla_pmu_get_perf_cycle;
pmu_ops->get_perf_cmdid = mdla_pmu_get_perf_cmdid;
pmu_ops->get_perf_cmdcnt = mdla_pmu_get_perf_cmdcnt;
pmu_ops->get_counter = mdla_pmu_get_counter;
pmu_ops->reset_counter = mdla_pmu_reset_counter;
pmu_ops->disable_counter = mdla_pmu_counter_disable_all;
pmu_ops->enable_counter = mdla_pmu_counter_enable_all;
pmu_ops->reset = mdla_pmu_reset;
pmu_ops->write_evt_exec = mdla_pmu_event_write_all;
pmu_ops->get_hnd_evt = mdla_pmu_get_hnd_evt;
pmu_ops->get_hnd_evt_num = mdla_pmu_get_hnd_evt_num;
pmu_ops->get_hnd_mode = mdla_pmu_get_hnd_mode;
pmu_ops->get_hnd_buf_addr = mdla_pmu_get_hnd_buf_addr;
pmu_ops->set_evt_handle = mdla_pmu_set_evt_handle;
pmu_ops->get_info = mdla_pmu_get_info;
pmu_ops->apu_cmd_prepare = mdla_pmu_cmd_prepare;
pmu_ops->apu_pmu_valid = mdla_pmu_apusys_valid;
}
void mdla_v1_0_pmu_deinit(struct mdla_dev *mdla_info)
{
mdla_ioctl_unregister_perf_handle();
kfree(mdla_info->pmu_dev);
kfree(mdla_info->pmu_info);
}
@@ -0,0 +1,13 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_v1_0_PMU_H__
#define __MDLA_v1_0_PMU_H__
struct mdla_dev;
void mdla_v1_0_pmu_init(struct mdla_dev *mdla_info);
void mdla_v1_0_pmu_deinit(struct mdla_dev *mdla_info);
#endif /* __MDLA_v1_0_PMU_H__ */
@@ -0,0 +1,610 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_device.h>
#include <linux/io.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/interrupt.h>
#include <linux/completion.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_trace.h>
#include <interface/mdla_intf.h>
#include <interface/mdla_cmd_data_v1_0.h>
#include <platform/mdla_plat_api.h>
#include "mdla_hw_reg_v1_0.h"
#include "mdla_irq_v1_0.h"
#include "mdla_pmu_v1_0.h"
static struct mdla_reg_ctl *mdla_reg_control;
static void *apu_conn_top;
static void *apu_mdla_gsm_top;
static void *apu_mdla_gsm_base;
static void *infracfg_ao_top;
static struct mdla_dev *mdla_plat_devices;
static u32 fs_e1_detect_count;
static u32 fs_e1_detect_timeout_ms = 5;
static int mdla_dbgfs_u64_create[NF_MDLA_DEBUG_FS_U64] = {
[FS_CFG_PMU_PERIOD] = 1,
};
static int mdla_dbgfs_u32_create[NF_MDLA_DEBUG_FS_U32] = {
[FS_C1] = 1,
[FS_C2] = 1,
[FS_C3] = 1,
[FS_C4] = 1,
[FS_C5] = 1,
[FS_C6] = 1,
[FS_C7] = 1,
[FS_C8] = 1,
[FS_C9] = 1,
[FS_C10] = 1,
[FS_C11] = 1,
[FS_C12] = 1,
[FS_C13] = 1,
[FS_C14] = 1,
[FS_C15] = 1,
[FS_CFG_ENG0] = 1,
[FS_CFG_ENG1] = 1,
[FS_CFG_ENG2] = 1,
[FS_CFG_ENG11] = 1,
[FS_POLLING_CMD_DONE] = 0,
[FS_DUMP_CMDBUF] = 1,
[FS_DVFS_RAND] = 1,
[FS_PMU_EVT_BY_APU] = 0,
[FS_KLOG] = 1,
[FS_POWEROFF_TIME] = 1,
[FS_TIMEOUT] = 1,
[FS_TIMEOUT_DBG] = 0,
[FS_BATCH_NUM] = 0,
[FS_PREEMPTION_TIMES] = 0,
[FS_PREEMPTION_DBG] = 0,
};
static struct lock_class_key hw_lock_key[MAX_CORE_NUM];
/* platform static functions */
static int mdla_plat_hw_e1_timeout_detect(u32 core_id)
{
u32 debug_intf;
debug_intf = mdla_util_io_ops_get()->cmde.read(core_id, 0x0EA8);
if (((debug_intf & 0x1C0) != 0x0 &&
(debug_intf & 0x3) == 0x3)) {
mdla_timeout_debug("%s: match E1 timeout issue\n",
__func__);
fs_e1_detect_count++;
return -1;
}
return 0;
}
static void mdla_plat_print_post_cmd_info(u32 core_id)
{
mdla_verbose("dst addr:%.8x\n",
mdla_util_io_ops_get()->cmde.read(core_id, 0xE3C));
}
static unsigned long mdla_plat_get_wait_time(u32 core_id)
{
unsigned long time;
if (mdla_trace_get_cfg_pmu_tmr_en())
time = usecs_to_jiffies(
mdla_dbg_read_u64(FS_CFG_PMU_PERIOD));
else
time = msecs_to_jiffies(fs_e1_detect_timeout_ms);
return time;
}
static void mdla_plat_destroy_dump_cmdbuf(struct mdla_dev *mdla_device)
{
mutex_lock(&mdla_device->cmd_buf_dmp_lock);
if (mdla_device->cmd_buf_len) {
devm_kfree(mdla_device->dev, mdla_device->cmd_buf_dmp);
mdla_device->cmd_buf_len = 0;
}
mutex_unlock(&mdla_device->cmd_buf_dmp_lock);
}
static int mdla_plat_create_dump_cmdbuf(struct mdla_dev *mdla_device,
struct command_entry *ce)
{
int ret = 0;
if (ce->kva == NULL)
return ret;
mutex_lock(&mdla_device->cmd_buf_dmp_lock);
if (mdla_device->cmd_buf_len)
devm_kfree(mdla_device->dev, mdla_device->cmd_buf_dmp);
mdla_device->cmd_buf_dmp = devm_kzalloc(mdla_device->dev, ce->count * MREG_CMD_SIZE,
GFP_KERNEL);
if (!mdla_device->cmd_buf_dmp) {
ret = -ENOMEM;
mdla_err("%s: kvmalloc: failed\n", __func__);
goto out;
}
mdla_device->cmd_buf_len = ce->count * MREG_CMD_SIZE;
memcpy(mdla_device->cmd_buf_dmp, ce->kva, mdla_device->cmd_buf_len);
out:
mutex_unlock(&mdla_device->cmd_buf_dmp_lock);
return ret;
}
static void mdla_plat_raw_process_command(u32 core_id, u32 evt_id,
dma_addr_t addr, u32 count)
{
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
/* set command address */
io->cmde.write(core_id, MREG_TOP_G_CDMA1, addr);
/* set command number */
io->cmde.write(core_id, MREG_TOP_G_CDMA2, count);
/* trigger hw */
io->cmde.write(core_id, MREG_TOP_G_CDMA3, evt_id);
}
static int mdla_plat_process_command(u32 core_id, struct command_entry *ce)
{
dma_addr_t addr;
u32 evt_id, count;
unsigned long flags;
addr = ce->mva;
count = ce->count;
evt_id = ce->count;
mdla_verbose("%s: count: %d, addr: %lx\n",
__func__, ce->count,
(unsigned long)addr);
spin_lock_irqsave(&mdla_get_device(core_id)->hw_lock, flags);
mdla_util_pmu_ops_get()->reset(core_id);
mdla_util_pmu_ops_get()->write_evt_exec(core_id, 0);
ce->state = CE_RUN;
ce_func_trace(ce, F_ISSUE);
mdla_plat_raw_process_command(core_id, evt_id, addr, count);
spin_unlock_irqrestore(&mdla_get_device(core_id)->hw_lock, flags);
return 0;
}
static void mdla_plat_dump_reg(u32 core_id, struct seq_file *s)
{
dump_reg_cfg(core_id, MDLA_CG_CON);
dump_reg_cfg(core_id, MDLA_SW_RST);
dump_reg_cfg(core_id, MDLA_MBIST_MODE0);
dump_reg_cfg(core_id, MDLA_MBIST_MODE1);
dump_reg_cfg(core_id, MDLA_MBIST_CTL);
dump_reg_cfg(core_id, MDLA_RP_OK0);
dump_reg_cfg(core_id, MDLA_RP_OK1);
dump_reg_cfg(core_id, MDLA_RP_OK2);
dump_reg_cfg(core_id, MDLA_RP_OK3);
dump_reg_cfg(core_id, MDLA_RP_FAIL0);
dump_reg_cfg(core_id, MDLA_RP_FAIL1);
dump_reg_cfg(core_id, MDLA_RP_FAIL2);
dump_reg_cfg(core_id, MDLA_RP_FAIL3);
dump_reg_cfg(core_id, MDLA_MBIST_FAIL0);
dump_reg_cfg(core_id, MDLA_MBIST_FAIL1);
dump_reg_cfg(core_id, MDLA_MBIST_FAIL2);
dump_reg_cfg(core_id, MDLA_MBIST_FAIL3);
dump_reg_cfg(core_id, MDLA_MBIST_FAIL4);
dump_reg_cfg(core_id, MDLA_MBIST_FAIL5);
dump_reg_cfg(core_id, MDLA_MBIST_DONE0);
dump_reg_cfg(core_id, MDLA_MBIST_DONE1);
dump_reg_cfg(core_id, MDLA_MBIST_DEFAULT_DELSEL);
dump_reg_cfg(core_id, MDLA_SRAM_DELSEL0);
dump_reg_cfg(core_id, MDLA_SRAM_DELSEL1);
dump_reg_cfg(core_id, MDLA_RP_RST);
dump_reg_cfg(core_id, MDLA_RP_CON);
dump_reg_cfg(core_id, MDLA_RP_PRE_FUSE);
dump_reg_cfg(core_id, MDLA_AXI_CTRL);
dump_reg_cfg(core_id, MDLA_AXI1_CTRL);
dump_reg_top(core_id, MREG_TOP_G_REV);
dump_reg_top(core_id, MREG_TOP_G_INTP0);
dump_reg_top(core_id, MREG_TOP_G_INTP1);
dump_reg_top(core_id, MREG_TOP_G_INTP2);
dump_reg_top(core_id, MREG_TOP_G_CDMA0);
dump_reg_top(core_id, MREG_TOP_G_CDMA1);
dump_reg_top(core_id, MREG_TOP_G_CDMA2);
dump_reg_top(core_id, MREG_TOP_G_CDMA3);
dump_reg_top(core_id, MREG_TOP_G_CDMA4);
dump_reg_top(core_id, MREG_TOP_G_CDMA5);
dump_reg_top(core_id, MREG_TOP_G_CDMA6);
dump_reg_top(core_id, MREG_TOP_G_CUR0);
dump_reg_top(core_id, MREG_TOP_G_CUR1);
dump_reg_top(core_id, MREG_TOP_G_FIN0);
dump_reg_top(core_id, MREG_TOP_G_FIN1);
dump_reg_top(core_id, MREG_TOP_G_IDLE);
}
static void mdla_plat_memory_show(struct seq_file *s)
{
struct mdla_dev *mdla_device;
int i;
u32 core_id;
u32 *cmd_addr;
seq_puts(s, "------- dump MDLA code buf -------\n");
for_each_mdla_core(core_id) {
mdla_device = mdla_get_device(core_id);
if (mdla_device->cmd_buf_len == 0)
continue;
seq_printf(s, "mdla %d code buf:\n", mdla_device->mdla_id);
mutex_lock(&mdla_device->cmd_buf_dmp_lock);
cmd_addr = mdla_device->cmd_buf_dmp;
for (i = 0; i < (mdla_device->cmd_buf_len/4); i++)
seq_printf(s, "count: %d, offset: %.8x, val: %.8x\n",
(i * 4) / MREG_CMD_SIZE,
(i * 4) % MREG_CMD_SIZE,
cmd_addr[i]);
mutex_unlock(&mdla_device->cmd_buf_dmp_lock);
}
}
static bool mdla_plat_dbgfs_u64_enable(int node)
{
return node >= 0 && node < NF_MDLA_DEBUG_FS_U64
? mdla_dbgfs_u64_create[node] : false;
}
static bool mdla_plat_dbgfs_u32_enable(int node)
{
return node >= 0 && node < NF_MDLA_DEBUG_FS_U32
? mdla_dbgfs_u32_create[node] : false;
}
static void mdla_plat_dbgfs_init(struct device *dev, struct dentry *parent)
{
if (!dev || !parent)
return;
debugfs_create_u32("e1_detect_count", 0660,
parent, &fs_e1_detect_count);
debugfs_create_u32("e1_detect_timeout",
0660, parent, &fs_e1_detect_timeout_ms);
}
static int mdla_plat_get_base_addr(struct platform_device *pdev,
void **reg, int num)
{
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, num);
if (!res) {
dev_info(&pdev->dev, "invalid address (num = %d)\n", num);
return -ENODEV;
}
*reg = ioremap_nocache(res->start, res->end - res->start + 1);
if (*reg == 0) {
dev_info(&pdev->dev,
"could not allocate iomem (num = %d)\n", num);
return -EIO;
}
dev_info(&pdev->dev,
"MDLA IORESOURCE_MEM (num = %d) at 0x%08lx mapped to 0x%08lx\n",
num,
(unsigned long __force)res->start,
(unsigned long __force)res->end);
return 0;
}
static int mdla_dts_map(struct platform_device *pdev)
{
int i, mdla_idx, gsm_idx, apu_conn_idx, infra_ao_idx;
struct device *dev = &pdev->dev;
u32 nr_core_ids = mdla_util_get_core_num();
dev_info(dev, "Device Tree Probing\n");
mdla_reg_control = kcalloc(nr_core_ids, sizeof(struct mdla_reg_ctl),
GFP_KERNEL);
if (!mdla_reg_control)
return -1;
mdla_idx = 0;
gsm_idx = 3 * nr_core_ids;
apu_conn_idx = 3 * nr_core_ids + 1;
infra_ao_idx = 3 * nr_core_ids + 2;
for (i = mdla_idx; i < nr_core_ids; i++) {
if (mdla_plat_get_base_addr(pdev,
&mdla_reg_control[i].apu_mdla_config_top,
3 * i))
goto err;
if (mdla_plat_get_base_addr(pdev,
&mdla_reg_control[i].apu_mdla_cmde_mreg_top,
3 * i + 1)) {
iounmap(mdla_reg_control[i].apu_mdla_config_top);
goto err;
}
if (mdla_plat_get_base_addr(pdev,
&mdla_reg_control[i].apu_mdla_biu_top,
3 * i + 2)) {
iounmap(mdla_reg_control[i].apu_mdla_cmde_mreg_top);
iounmap(mdla_reg_control[i].apu_mdla_config_top);
goto err;
}
}
if (mdla_plat_get_base_addr(pdev, &apu_mdla_gsm_top, gsm_idx))
goto err;
else
apu_mdla_gsm_base = (void *)platform_get_resource(pdev,
IORESOURCE_MEM, gsm_idx)->start;
dev_info(dev, "apu_mdla_gsm_top: %p, apu_mdla_gsm_base: %p\n",
apu_mdla_gsm_top, apu_mdla_gsm_base);
if (mdla_plat_get_base_addr(pdev, &apu_conn_top, apu_conn_idx))
goto err_conn;
if (mdla_plat_get_base_addr(pdev, &infracfg_ao_top, infra_ao_idx))
goto err_infra_ao;
if (mdla_v1_0_irq_request(dev, nr_core_ids))
goto err_irq;
return 0;
err_irq:
iounmap(infracfg_ao_top);
err_infra_ao:
iounmap(apu_conn_top);
err_conn:
iounmap(apu_mdla_gsm_top);
err:
for (i = i - 1; i >= mdla_idx; i--) {
iounmap(mdla_reg_control[i].apu_mdla_config_top);
iounmap(mdla_reg_control[i].apu_mdla_cmde_mreg_top);
iounmap(mdla_reg_control[i].apu_mdla_biu_top);
}
kfree(mdla_reg_control);
return -1;
}
static void mdla_dts_unmap(struct platform_device *pdev)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
mdla_v1_0_irq_release(&pdev->dev);
iounmap(infracfg_ao_top);
iounmap(apu_conn_top);
iounmap(apu_mdla_gsm_top);
for (i = 0; i < nr_core_ids; i++) {
iounmap(mdla_reg_control[i].apu_mdla_config_top);
iounmap(mdla_reg_control[i].apu_mdla_cmde_mreg_top);
iounmap(mdla_reg_control[i].apu_mdla_biu_top);
}
kfree(mdla_reg_control);
}
static int mdla_sw_multi_devices_init(struct device *dev)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
mdla_plat_devices = devm_kzalloc(dev, nr_core_ids * sizeof(struct mdla_dev),
GFP_KERNEL);
if (!mdla_plat_devices)
return -1;
mdla_set_device(mdla_plat_devices, nr_core_ids);
for (i = 0; i < nr_core_ids; i++) {
mdla_plat_devices[i].mdla_id = i;
mdla_plat_devices[i].dev = dev;
mdla_plat_devices[i].cmd_buf_dmp = NULL;
mdla_plat_devices[i].cmd_buf_len = 0;
INIT_LIST_HEAD(&mdla_plat_devices[i].cmd_list);
init_completion(&mdla_plat_devices[i].command_done);
spin_lock_init(&mdla_plat_devices[i].hw_lock);
lockdep_set_class(&mdla_plat_devices[i].hw_lock,
&hw_lock_key[i]);
mutex_init(&mdla_plat_devices[i].cmd_lock);
mutex_init(&mdla_plat_devices[i].cmd_list_lock);
mutex_init(&mdla_plat_devices[i].cmd_buf_dmp_lock);
mdla_v1_0_pmu_init(&mdla_plat_devices[i]);
}
return 0;
}
static void mdla_sw_multi_devices_deinit(void)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
mdla_set_device(NULL, 0);
for (i = 0; i < nr_core_ids; i++) {
mdla_v1_0_pmu_deinit(&mdla_plat_devices[i]);
/* TODO: Need to kill completion and wait it finished ? */
mutex_destroy(&mdla_plat_devices[i].cmd_lock);
mutex_destroy(&mdla_plat_devices[i].cmd_list_lock);
mutex_destroy(&mdla_plat_devices[i].cmd_buf_dmp_lock);
}
}
/* platform public functions */
static void mdla_v1_0_reset(u32 core_id, const char *str)
{
unsigned long flags;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
struct mdla_dev *dev = mdla_get_device(core_id);
if (unlikely(!dev)) {
mdla_err("%s(): No mdla device (%d)\n", __func__, core_id);
return;
}
/* use power down==>power on apis insted bus protect init */
mdla_pwr_debug("%s(): MDLA RESET: %s\n", __func__, str);
spin_lock_irqsave(&dev->hw_lock, flags);
// Enable Bus prot, start to turn off, set bus protect - step 1:0
io->infra_cfg.write(INFRA_TOPAXI_PROTECTEN_MCU_SET,
VPU_CORE2_PROT_STEP1_0_MASK);
while ((io->infra_cfg.read(INFRA_TOPAXI_PROTECTEN_MCU_STA1) &
VPU_CORE2_PROT_STEP1_0_ACK_MASK) !=
VPU_CORE2_PROT_STEP1_0_ACK_MASK) {
}
// Reset
io->apu_conn.set_b(APU_CONN_SW_RST, APU_CORE2_RSTB);
io->apu_conn.clr_b(APU_CONN_SW_RST, APU_CORE2_RSTB);
// Release Bus Prot
io->infra_cfg.write(INFRA_TOPAXI_PROTECTEN_MCU_CLR,
VPU_CORE2_PROT_STEP1_0_MASK);
io->cfg.write(core_id, MDLA_CG_CLR, 0xffffffff);
io->cmde.write(core_id,
MREG_TOP_G_INTP2, MDLA_IRQ_MASK & ~(MDLA_IRQ_SWCMD_DONE));
/* for DCM and CG */
io->cmde.write(core_id,
MREG_TOP_ENG0, mdla_dbg_read_u32(FS_CFG_ENG0));
io->cmde.write(core_id,
MREG_TOP_ENG1, mdla_dbg_read_u32(FS_CFG_ENG1));
io->cmde.write(core_id,
MREG_TOP_ENG2, mdla_dbg_read_u32(FS_CFG_ENG2));
io->cmde.write(core_id,
MREG_TOP_ENG11, mdla_dbg_read_u32(FS_CFG_ENG11));
if (mdla_plat_iommu_enable()) {
io->cfg.set_b(core_id, MDLA_AXI_CTRL, MDLA_AXI_CTRL_MASK);
io->cfg.set_b(core_id, MDLA_AXI1_CTRL, MDLA_AXI_CTRL_MASK);
}
spin_unlock_irqrestore(&dev->hw_lock, flags);
mdla_trace_reset(core_id, str);
}
int mdla_v1_0_init(struct platform_device *pdev)
{
struct mdla_cmd_cb_func *cmd_cb = mdla_cmd_plat_cb();
struct mdla_dbg_cb_func *dbg_cb = mdla_dbg_plat_cb();
dev_info(&pdev->dev, "%s()\n", __func__);
if (mdla_sw_multi_devices_init(&pdev->dev))
return -1;
if (mdla_dts_map(pdev))
goto err;
if (mdla_plat_pwr_drv_ready()) {
if (mdla_pwr_device_register(pdev, mdla_pwr_on_v1_0,
mdla_pwr_off_v1_0))
goto err_pwr;
}
mdla_pwr_reset_setup(mdla_v1_0_reset);
/* set command strategy */
mdla_cmd_setup(mdla_cmd_run_sync_v1_0,
mdla_cmd_ut_run_sync_v1_0);
/* set callback function */
cmd_cb->wait_cmd_hw_detect = mdla_plat_hw_e1_timeout_detect;
cmd_cb->post_cmd_info = mdla_plat_print_post_cmd_info;
cmd_cb->get_wait_time = mdla_plat_get_wait_time;
cmd_cb->process_command = mdla_plat_process_command;
/* set debug callback */
dbg_cb->destroy_dump_cmdbuf = mdla_plat_destroy_dump_cmdbuf;
dbg_cb->create_dump_cmdbuf = mdla_plat_create_dump_cmdbuf;
dbg_cb->dump_reg = mdla_plat_dump_reg;
dbg_cb->memory_show = mdla_plat_memory_show;
dbg_cb->dbgfs_u64_enable = mdla_plat_dbgfs_u64_enable;
dbg_cb->dbgfs_u32_enable = mdla_plat_dbgfs_u32_enable;
dbg_cb->dbgfs_plat_init = mdla_plat_dbgfs_init;
/* set base address */
mdla_util_io_set_addr(mdla_reg_control);
mdla_util_io_set_extra_addr(EXTRA_ADDR_V1P0,
apu_conn_top, infracfg_ao_top, NULL);
return 0;
err_pwr:
dev_info(&pdev->dev, "register mdla power fail\n");
mdla_dts_unmap(pdev);
err:
mdla_sw_multi_devices_deinit();
return -1;
}
void mdla_v1_0_deinit(struct platform_device *pdev)
{
int i;
dev_info(&pdev->dev, "%s()\n", __func__);
for_each_mdla_core(i)
mdla_pwr_ops_get()->off(i, 0, true);
if (mdla_plat_pwr_drv_ready()
&& mdla_pwr_device_unregister(pdev))
dev_info(&pdev->dev, "unregister mdla power fail\n");
mdla_dts_unmap(pdev);
mdla_sw_multi_devices_deinit();
}
@@ -0,0 +1,132 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef _MDLA_V1_X_HW_REG_H__
#define _MDLA_V1_X_HW_REG_H__
#define MDLA_IRQ_SWCMD_TILECNT_INT BIT(1)
#define MDLA_IRQ_TILECNT_DONE BIT(1)
#define MDLA_IRQ_SWCMD_DONE BIT(2)
#define MDLA_IRQ_CDMA_FIFO_EMPTY BIT(5)
#define MDLA_IRQ_PMU_INTE BIT(9)
#define MDLA_IRQ_MASK (0x1FFFFF)
#define MDLA_AXI_CTRL_MASK (BIT(1) | BIT(10))
#define MDLA_SW_RST_SETETING (0x3F)
/* 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_AXI_BIST_CTL (0x01C)
#define MDLA_AXI_BIST_STA (0x020)
#define MDLA_MBIST_DEFAULT_DELSEL (0x024)
#define MDLA_RP_RST (0x060)
#define MDLA_RP_CON (0x064)
#define MDLA_RP_PRE_FUSE_0 (0x068)
#define MDLA_RP_PRE_FUSE_1 (0x06C)
#define MDLA_RP_PRE_FUSE_2 (0x070)
#define MDLA_RP_PRE_FUSE_3 (0x074)
#define MDLA_RP_PRE_FUSE_4 (0x078)
#define MDLA_SPARE_0 (0x07C)
#define MDLA_SPARE_1 (0x080)
#define MDLA_SPARE_2 (0x084)
#define MDLA_SPARE_3 (0x088)
#define MDLA_SPARE_4 (0x08C)
#define MDLA_SPARE_5 (0x090)
#define MDLA_SPARE_6 (0x094)
#define MDLA_SPARE_7 (0x098)
#define MDLA_CTRL (0x110)
#define MDLA_CSYSREQ (0x114)
#define MDLA_CSYSACK (0x118)
#define MDLA_AXI_CTRL (0x120)
#define MDLA_AXI1_CTRL (0x124)
#define MDLA_APB_CTRL (0x128)
#define MDLA_APB_STA (0x12C)
#define MDLA_GALS_M0_CTRL (0x130)
#define MDLA_GALS_M1_CTRL (0x134)
#define MDLA_GALS_STA (0x138)
#define MDLA_AXI_GALS_DBG (0x13C)
#define MDLA_SES_CTL0 (0x140)
#define MDLA_SES_CTL1 (0x144)
#define MDLA_SES_CTL2 (0x148)
/* MDLA command */
#define MREG_TOP_SWCMD_DONE_CNT (0x008C)
#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_TOP_G_FIN3 (0x0584)
#define MREG_TOP_G_COREINFO (0x0588)
#define MREG_CMD_GENERAL_CTRL_0 (0x70)
#define MREG_CMD_SIZE (0x1C0)
#define MREG_CMD_SWCMD_ID (0x150)
#define MREG_CMD_TILE_CNT_INT (0x154)
#define MREG_CMD_GENERAL_CTRL_1 (0x15C)
#define MSK_MREG_TOP_G_STREAM0_PROD_CMD_ID GENMASK(31, 0)
#define MSK_MREG_TOP_G_STREAM1_HALT_EN BIT(31)
#define MSK_MREG_TOP_G_STREAM1_PROD_TILE_ID GENMASK(23, 0)
#define MSK_MREG_CMD_SWCMD_FINISH_INT_EN GENMASK(24, 24)
#define MSK_MREG_CMD_LAYER_END GENMASK(12, 12)
#define MSK_MREG_CMD_SWCMD_WAIT_SWCMDDONE GENMASK(16, 16)
#define MSK_MREG_CMD_SWCMD_INT_SWCMDDONE GENMASK(15, 15)
/* MDLA PMU */
#define CFG_PMCR_DEFAULT (0x1F021)
#define CFG_PMCR (0x0E00)
#define PMU_CLK_CNT (0x0E04)
#define PMU_START_TSTAMP (0x0E08)
#define PMU_END_TSTAMP (0x0E0C)
#define PMU1 (0x0E10)
#define PMU1_CNT (0x0E14)
#define PMU1_CNT_LATCH (0x0E18)
#define PMU_CMDID_LATCH (0x0F00)
/* id: 0 ~ 14 */
#define PMU(id) (0x10 * (id) + PMU1)
#define PMU_CNT(id) (0x10 * (id) + PMU1_CNT)
#define PMU_CNT_LATCH(id) (0x10 * (id) + PMU1_CNT_LATCH)
/* CFG_PMCR : 0xE00 */
#define PMU_CNT_EN(i) BIT(17 + (i))
#define PMU_CCNT_EN BIT(16)
#define PMU_PERCMD_MODE BIT(5)
#define PMU_EXPORT BIT(4)
#define PMU_CCNT_RESET BIT(2)
#define PMU_CNT_RESET BIT(1)
#define PMU_ENABLE BIT(0)
#endif /* _MDLA_V1_X_HW_REG_H__ */
@@ -0,0 +1,277 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_irq.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/sched/clock.h>
#include <common/mdla_driver.h>
#include <common/mdla_device.h>
#include <common/mdla_scheduler.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_profile.h>
#include <interface/mdla_cmd_data_v1_x.h>
#include <platform/mdla_plat_api.h>
#include "mdla_hw_reg_v1_x.h"
#include "mdla_sched_v1_x.h"
struct mdla_irq {
u32 irq;
struct mdla_dev *dev;
};
static int handle_num;
static struct mdla_irq *mdla_irq_desc;
/* platform static function */
/*
* Return smp_cmd_id
* smp_cmd_id = 0 => single cmd, issue directly
* smp_cmd_id != 0 => SMP cmd, return and issue SMP later
*/
static uint64_t mdla_sw_issue_next(struct mdla_dev *mdla_device)
{
struct mdla_scheduler *sched = mdla_device->sched;
u32 core_id = mdla_device->mdla_id;
struct command_entry *new_ce;
uint64_t smp_cmd_id = 0;
/* get the next CE to be processed */
new_ce = sched->dequeue_ce(core_id);
if (new_ce) {
if (sched->pro_ce) {
sched->preempt_ce(core_id, new_ce);
sched->issue_ce(core_id);
} else if ((new_ce->multicore_total > 1)
&& (new_ce->priority == MDLA_LOW_PRIORITY)) {
sched->enqueue_ce(core_id, new_ce, 1);
smp_cmd_id = new_ce->cmd_id;
} else {
sched->pro_ce = new_ce;
sched->issue_ce(core_id);
}
} else if (sched->pro_ce) {
sched->issue_ce(core_id);
}
return smp_cmd_id;
}
static void mdla_irq_sched(struct mdla_dev *mdla_device)
{
struct mdla_scheduler *sched = mdla_device->sched;
unsigned long flags;
u32 status, core_id, cdma4 = 0, irq_status = 0;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
u64 smp_cmd_id = 0;
core_id = mdla_device->mdla_id;
/* clear intp0 to avoid irq fire twice */
spin_lock_irqsave(&mdla_device->hw_lock, flags);
irq_status = io->cmde.read(core_id, MREG_TOP_G_INTP0);
io->cmde.write(core_id, MREG_TOP_G_INTP0, MDLA_IRQ_SWCMD_DONE | MDLA_IRQ_PMU_INTE);
cdma4 = io->cmde.read(core_id, MREG_TOP_G_CDMA4);
spin_unlock_irqrestore(&mdla_device->hw_lock, flags);
if (unlikely(sched == NULL)) {
mdla_device->error_bit |= IRQ_NO_SCHEDULER;
return;
}
spin_lock_irqsave(&sched->lock, flags);
if (unlikely(sched->pro_ce == NULL)) {
mdla_device->error_bit |= IRQ_NO_PROCESSING_CE;
goto unlock;
}
if (unlikely(sched->pro_ce->state & (1 << CE_FAIL))) {
mdla_device->error_bit |= IRQ_TIMEOUT;
ce_func_trace(sched->pro_ce, F_TIMEOUT | 1);
goto unlock;
}
if (unlikely(time_after64(get_jiffies_64(),
sched->pro_ce->deadline_t))) {
sched->pro_ce->state |= (1 << CE_TIMEOUT);
ce_func_trace(sched->pro_ce, F_TIMEOUT);
goto unlock;
}
if (unlikely((irq_status & MDLA_IRQ_SWCMD_DONE) == 0)) {
ce_func_trace(sched->pro_ce, F_INIRQ_ERROR);
goto unlock;
}
if (unlikely(cdma4 != sched->pro_ce->csn)) {
sched->pro_ce->irq_state |= IRQ_RECORD_ERROR;
ce_func_trace(sched->pro_ce, F_INIRQ_CDMA4ERROR);
goto unlock;
}
sched->pro_ce->state |= (1 << CE_SCHED);
/* process the current CE */
status = sched->process_ce(core_id);
if (status == CE_DONE) {
sched->complete_ce(core_id);
} else if (status == CE_NONE) {
/* nothing to do but wait for the engine completed */
goto unlock;
}
/* get the next CE to be processed */
smp_cmd_id = mdla_sw_issue_next(mdla_device);
unlock:
spin_unlock_irqrestore(&sched->lock, flags);
if (smp_cmd_id)
sched->issue_dual_lowce(core_id, smp_cmd_id);
}
static void mdla_irq_intr(struct mdla_dev *mdla_device)
{
u32 status_int, core_id, id, mask;
unsigned long flags;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
struct mdla_pmu_info *pmu;
core_id = mdla_device->mdla_id;
spin_lock_irqsave(&mdla_device->hw_lock, flags);
status_int = io->cmde.read(core_id, MREG_TOP_G_INTP0);
mask = io->cmde.read(core_id, MREG_TOP_G_INTP2) | MDLA_IRQ_SWCMD_DONE;
io->cmde.write(core_id, MREG_TOP_G_INTP2, mask);
io->cmde.write(core_id, MREG_TOP_G_INTP0, mask);
/* Toggle for Latch Fin1 Tile ID */
io->cmde.read(core_id, MREG_TOP_G_FIN0);
id = io->cmde.read(core_id, MREG_TOP_G_FIN3);
pmu = mdla_util_pmu_ops_get()->get_info(core_id, 0);
if (pmu)
mdla_util_pmu_ops_get()->reg_counter_save(core_id, pmu);
mdla_device->max_cmd_id = id;
if (status_int & MDLA_IRQ_PMU_INTE)
io->cmde.write(core_id,
MREG_TOP_G_INTP0, MDLA_IRQ_PMU_INTE);
spin_unlock_irqrestore(&mdla_device->hw_lock, flags);
complete(&mdla_device->command_done);
}
static irqreturn_t mdla_irq_handler(int irq, void *dev_id)
{
struct mdla_dev *mdla_device = (struct mdla_dev *)dev_id;
struct command_entry *curr_ce;
u64 ts;
if (unlikely(!mdla_device))
return IRQ_HANDLED;
ts = sched_clock();
curr_ce = mdla_device->sched->pro_ce;
if (curr_ce && curr_ce->req_start_t) {
curr_ce->exec_time += ts - curr_ce->req_start_t;
curr_ce->req_start_t = 0;
/* for trace check */
curr_ce->req_end_t = ts;
}
if (mdla_plat_sw_preemption_support())
mdla_irq_sched(mdla_device);
else
mdla_irq_intr(mdla_device);
return IRQ_HANDLED;
}
/* platform public function */
int mdla_v1_x_get_irq_num(u32 core_id)
{
int i;
for (i = 0; i < handle_num; i++) {
if (mdla_irq_desc[i].dev == mdla_get_device(core_id))
return mdla_irq_desc[i].irq;
}
return 0;
}
int mdla_v1_x_irq_request(struct device *dev, int irqdesc_num)
{
int i;
struct mdla_irq *irq_desc;
struct device_node *node = dev->of_node;
if (!node) {
dev_info(dev, "get mdla device node err\n");
return -1;
}
mdla_irq_desc = kcalloc(irqdesc_num, sizeof(struct mdla_irq), GFP_KERNEL);
if (!mdla_irq_desc)
return -1;
handle_num = irqdesc_num;
for (i = 0; i < irqdesc_num; i++) {
irq_desc = &mdla_irq_desc[i];
irq_desc->dev = mdla_get_device(i);
irq_desc->irq = irq_of_parse_and_map(node, i);
if (!irq_desc->irq) {
dev_info(dev, "get mdla irq: %d failed\n", i);
goto err;
}
if (request_irq(irq_desc->irq, mdla_irq_handler,
irq_get_trigger_type(irq_desc->irq),
DRIVER_NAME, irq_desc->dev)) {
dev_info(dev, "mtk_mdla[%d]: Could not allocate interrupt %d.\n",
i, irq_desc->irq);
}
dev_info(dev, "request_irq %d done\n", irq_desc->irq);
}
return 0;
err:
kfree(mdla_irq_desc);
return -1;
}
void mdla_v1_x_irq_release(struct device *dev)
{
int i;
for (i = 0; i < handle_num; i++)
free_irq(mdla_irq_desc[i].irq, mdla_irq_desc[i].dev);
kfree(mdla_irq_desc);
}
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_V1_X_IRQ_H__
#define __MDLA_V1_X_IRQ_H__
#include <linux/types.h>
#include <linux/device.h>
int mdla_v1_x_get_irq_num(u32 core_id);
int mdla_v1_x_irq_request(struct device *dev, int irqdesc_num);
int mdla_v1_x_irq_release(struct device *dev);
#endif /* __MDLA_V1_X_IRQ_H__ */
@@ -0,0 +1,731 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
#include <apusys_device.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_profile.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_ioctl.h>
#include <platform/mdla_plat_api.h>
#include "mdla_pmu_v1_x.h"
#include "mdla_hw_reg_v1_x.h"
#include <interface/mdla_cmd_data_v1_x.h>
#define biu_read(id, ofs) \
mdla_util_io_ops_get()->biu.read(id, ofs)
#define biu_write(id, ofs, val) \
mdla_util_io_ops_get()->biu.write(id, ofs, val)
#define biu_set_b(id, ofs, val) \
mdla_util_io_ops_get()->biu.set_b(id, ofs, val)
#define biu_clr_b(id, ofs, val) \
mdla_util_io_ops_get()->biu.clr_b(id, ofs, val)
struct mdla_pmu_dev {
spinlock_t lock;
DECLARE_BITMAP(pmu_bitmap, MDLA_PMU_COUNTERS);
u32 cfg_event[MDLA_PMU_COUNTERS];
};
struct mdla_pmu_data {
u8 cfg_percmd_mode;
u16 l_cmd_cnt;
u16 l_cmd_id;
u32 l_start_t;
u32 l_end_t;
u32 l_cycle;
u32 l_counters[MDLA_PMU_COUNTERS];
u32 event_handle[MDLA_PMU_COUNTERS];
};
/* pmu info handle (sync with NN)*/
struct mdla_pmu_hnd {
u32 graph_id;//need confirm apusys mid data type
u32 offset_to_PMU_res_buf0;//base addr: pmu_kva
u32 offset_to_PMU_res_buf1;
u8 mode;
u8 number_of_event;
u16 event[MDLA_PMU_COUNTERS];
};
struct mdla_pmu_info {
u64 cmd_id;
u64 PMU_res_buf_addr;
struct mdla_pmu_hnd *pmu_hnd;
struct mdla_pmu_data data;
u32 number_of_event;
u8 pmu_mode;
};
static u32 mdla_pmu_get_perf_end(struct mdla_pmu_info *pmu)
{
return pmu->data.l_end_t;
}
static u32 mdla_pmu_get_perf_cycle(struct mdla_pmu_info *pmu)
{
return pmu->data.l_cycle;
}
static u16 mdla_pmu_get_perf_cmdid(struct mdla_pmu_info *pmu)
{
return pmu->data.l_cmd_id;
}
static u16 mdla_pmu_get_perf_cmdcnt(struct mdla_pmu_info *pmu)
{
return pmu->data.l_cmd_cnt;
}
static u32 mdla_pmu_get_counter(struct mdla_pmu_info *pmu, u32 idx)
{
return pmu->data.l_counters[idx];
}
static int mdla_pmu_get_mode(struct mdla_pmu_info *pmu)
{
return (int)pmu->pmu_mode;
}
static u32 mdla_pmu_get_hnd_evt(struct mdla_pmu_info *pmu, u32 counter_idx)
{
return pmu->pmu_hnd->event[counter_idx];
}
static u32 mdla_pmu_get_hnd_evt_num(struct mdla_pmu_info *pmu)
{
return pmu->pmu_hnd->number_of_event;
}
static u32 mdla_pmu_get_hnd_mode(struct mdla_pmu_info *pmu)
{
return pmu->pmu_hnd->mode;
}
static u64 mdla_pmu_get_hnd_buf_addr(struct mdla_pmu_info *pmu)
{
return pmu->PMU_res_buf_addr;
}
static void mdla_pmu_set_evt_handle(struct mdla_pmu_info *pmu,
u32 counter_idx, u32 val)
{
pmu->data.event_handle[counter_idx] = val;
}
static struct mdla_pmu_info *mdla_pmu_get_info(u32 core_id, u16 priority)
{
return &mdla_get_device(core_id)->pmu_info[priority];
}
/* extract pmu_hnd form pmu_kva and set mdla_info->pmu */
static int mdla_pmu_cmd_prepare(struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd, u16 priority)
{
u64 ofs_buf_addr;
struct mdla_pmu_info *pmu;
pmu = &mdla_info->pmu_info[priority];
if (pmu->pmu_mode >= CMD_MODE_MAX)
return -1;
pmu->pmu_hnd =
(struct mdla_pmu_hnd *)apusys_hd->pmu_kva;
pmu->cmd_id = apusys_hd->cmd_id;
if (mdla_info->mdla_id == 0)
ofs_buf_addr = pmu->pmu_hnd->offset_to_PMU_res_buf0;
else if (mdla_info->mdla_id == 1)
ofs_buf_addr = pmu->pmu_hnd->offset_to_PMU_res_buf1;
else
return -1;
pmu->PMU_res_buf_addr = apusys_hd->cmd_entry + ofs_buf_addr;
if (pmu->pmu_mode == PER_CMD)
mdla_util_pmu_cmd_timer(true);
mdla_pmu_debug("pmu addr: %08llx\n", pmu->PMU_res_buf_addr);
return 0;
}
static bool mdla_pmu_apusys_valid(struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd, u16 priority)
{
struct mdla_pmu_info *pmu;
struct mdla_run_cmd_sync *cmd_data;
struct mdla_run_cmd *cd;
uint32_t count;
uint64_t out_size = 0;
uint64_t out_end = 0;
uint32_t out_length = 0;
uint32_t repeat_sz = 0;
uint32_t evt_num = 0;
uint32_t sz = 0;
cmd_data = (struct mdla_run_cmd_sync *)apusys_hd->kva;
cd = &cmd_data->req;
count = cd->count;
pmu = &mdla_info->pmu_info[priority];
evt_num = mdla_pmu_get_hnd_evt_num(pmu);
if (evt_num > MDLA_PMU_COUNTERS)
return false;
out_end = apusys_hd->cmd_entry + apusys_hd->cmd_size;
if (apusys_hd->cmd_entry > pmu->PMU_res_buf_addr)
return false;
if (out_end < pmu->PMU_res_buf_addr)
return false;
out_size = out_end - pmu->PMU_res_buf_addr;
if (pmu->pmu_mode == PER_CMD) {
if (out_size < sizeof(u16))
return false;
repeat_sz = sizeof(u16) + sizeof(u32) * (evt_num + 1);
out_length = (out_size - sizeof(u16)) / repeat_sz;
if (out_length < count)
return false;
} else if (pmu->pmu_mode == NORMAL) {
sz = sizeof(u16) * 2 + sizeof(u32) * (evt_num + 1);
if (out_size < sz)
return false;
}
return true;
}
static int mdla_pmu_event_write(u32 core_id, u32 handle, u32 val)
{
if (val == COUNTER_CLEAR) {
mdla_pmu_debug("%s: clear pmu counter[%d]\n",
__func__, handle);
biu_write(core_id, PMU(handle), 0);
biu_clr_b(core_id, CFG_PMCR, PMU_CNT_EN(handle));
} else {
mdla_pmu_debug("%s: set pmu counter[%d] = 0x%x\n",
__func__, handle, val);
biu_write(core_id, PMU(handle), val);
biu_set_b(core_id, CFG_PMCR, PMU_CNT_EN(handle));
}
return 0;
}
static void mdla_pmu_event_write_all(u32 core_id, u16 priority)
{
int i, cnt;
u32 val;
struct mdla_pmu_info *pmu;
pmu = &(mdla_get_device(core_id)->pmu_info[priority]);
cnt = mdla_prof_use_dbgfs_pmu_event(core_id)
? MDLA_PMU_COUNTERS : pmu->number_of_event;
for (i = 0; i < cnt; i++) {
val = i < MDLA_PMU_COUNTERS ?
pmu->data.event_handle[i] : COUNTER_CLEAR;
mdla_pmu_event_write(core_id, i, val);
}
}
static u32 mdla_pmu_get_num_evt(u32 core_id, u16 priority)
{
if (mdla_prof_use_dbgfs_pmu_event(core_id))
return MDLA_PMU_COUNTERS;
if (priority >= PRIORITY_LEVEL)
return 0;
return mdla_get_device(core_id)->pmu_info[priority].number_of_event;
}
static void mdla_pmu_set_num_evt(u32 core_id, u16 prio, u32 val)
{
if (prio < PRIORITY_LEVEL)
mdla_get_device(core_id)->pmu_info[prio].number_of_event = val;
}
#define pmu_is_percmd_mode(i)\
(biu_read(i, CFG_PMCR) & PMU_PERCMD_MODE)
/* for mdla_trace and apusys_hnd */
static void mdla_pmu_counter_read_all(u32 core_id, u32 out[MDLA_PMU_COUNTERS])
{
int i;
if (pmu_is_percmd_mode(core_id)) {
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
out[i] += biu_read(core_id, PMU_CNT_LATCH(i));
} else {
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
out[i] += biu_read(core_id, PMU_CNT(i));
}
}
static void mdla_pmu_counter_disable_all(u32 core_id)
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
biu_clr_b(core_id, CFG_PMCR, PMU_CNT_EN(i));
}
static void mdla_pmu_counter_enable_all(u32 core_id)
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++) {
if (biu_read(core_id, PMU(i)))
biu_set_b(core_id, CFG_PMCR, PMU_CNT_EN(i));
}
}
/* save pmu registers for query after power off */
static void mdla_pmu_counter_save(u32 core_id, struct mdla_pmu_info *pmu)
{
if (pmu->pmu_mode == NORMAL) {
pmu->data.l_cmd_cnt = 1;
pmu->data.l_cmd_id = 0;
} else {
u32 val = biu_read(core_id, PMU_CMDID_LATCH);
if (val != pmu->data.l_cmd_id) {
pmu->data.l_cmd_cnt++;
pmu->data.l_cmd_id = (u16)val;
}
}
pmu->data.l_cycle +=
biu_read(core_id, PMU_CLK_CNT);
pmu->data.l_end_t +=
biu_read(core_id, PMU_END_TSTAMP);
pmu->data.l_start_t =
biu_read(core_id, PMU_START_TSTAMP);
mdla_pmu_counter_read_all(core_id, pmu->data.l_counters);
}
/* it save mode setting to local variable */
static void mdla_pmu_percmd_mode_set(struct mdla_pmu_info *pmu, u32 mode)
{
pmu->data.cfg_percmd_mode = mode;
}
/* for ioctrl */
static void mdla_pmu_percmd_mode_write(u32 core_id, struct mdla_pmu_info *pmu)
{
if (pmu->data.cfg_percmd_mode)
biu_set_b(core_id, CFG_PMCR, PMU_PERCMD_MODE);
else
biu_clr_b(core_id, CFG_PMCR, PMU_PERCMD_MODE);
}
/* for ioctrl */
static int mdla_pmu_counter_event_set(u32 core_id, int handle, u32 val)
{
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
if (handle < MDLA_PMU_COUNTERS)
pmu_dev->cfg_event[handle] = val;
mdla_pmu_event_write(core_id, handle, val);
return 0;
}
/* for ioctrl */
static int mdla_pmu_counter_event_get(u32 core_id, int handle)
{
u32 event;
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
event = pmu_dev->cfg_event[handle];
return (event == COUNTER_CLEAR) ? -ENOENT : event;
}
static void mdla_pmu_reset_and_write_event(u32 core_id, u16 priority)
{
biu_set_b(core_id,
CFG_PMCR,
(CFG_PMCR_DEFAULT | PMU_CNT_RESET
| PMU_CCNT_EN | PMU_CCNT_RESET));
while ((biu_read(core_id, CFG_PMCR) &
(PMU_CNT_RESET | PMU_CCNT_RESET)) != 0) {
}
mdla_pmu_percmd_mode_write(core_id,
&(mdla_get_device(core_id)->pmu_info[priority]));
mdla_pmu_event_write_all(core_id, priority);
}
static void mdla_pmu_reset_counter_variable(struct mdla_pmu_info *pmu)
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
pmu->data.l_counters[i] = 0;
pmu->data.l_cmd_id = 0;
pmu->data.l_cmd_cnt = 0;
}
static void mdla_pmu_reset_cycle_variable(struct mdla_pmu_info *pmu)
{
pmu->data.l_cycle = 0;
pmu->data.l_end_t = 0;
pmu->data.l_start_t = 0;
}
static void mdla_pmu_reset_counter_no_lock(u32 core_id)
{
mdla_pmu_debug("mdla: %s\n", __func__);
/*Reset Clock counter to zero. Return to zero when reset done.*/
biu_set_b(core_id, CFG_PMCR, PMU_CNT_RESET);
while ((biu_read(core_id, CFG_PMCR) & PMU_CNT_RESET)
!= 0) {
}
}
static void mdla_pmu_reset_counter(u32 core_id)
{
unsigned long flags;
struct mdla_pmu_dev *pmu_dev;
pmu_dev = mdla_get_device(core_id)->pmu_dev;
spin_lock_irqsave(&pmu_dev->lock, flags);
mdla_pmu_reset_counter_no_lock(core_id);
spin_unlock_irqrestore(&pmu_dev->lock, flags);
}
static void mdla_pmu_reset_cycle(u32 core_id)
{
mdla_pmu_debug("mdla: %s\n", __func__);
biu_set_b(core_id,
CFG_PMCR,
(PMU_CCNT_EN | PMU_CCNT_RESET));
while ((biu_read(core_id, CFG_PMCR) & PMU_CCNT_RESET)
!= 0) {
}
}
static void mdla_pmu_reset(u32 core_id)
{
int i;
biu_write(core_id, CFG_PMCR,
(CFG_PMCR_DEFAULT | PMU_CCNT_RESET | PMU_CNT_RESET));
while ((biu_read(core_id, CFG_PMCR) &
(PMU_CCNT_RESET | PMU_CNT_RESET)) != 0) {
}
/* reset to 0 */
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
mdla_pmu_event_write(core_id, i, COUNTER_CLEAR);
/* reset to normal */
biu_clr_b(core_id, CFG_PMCR, PMU_PERCMD_MODE);
mdla_pmu_debug("mdla: %s, CFG_PMCR: 0x%x\n",
__func__, biu_read(core_id, CFG_PMCR));
}
/* for ioctrl */
static int mdla_pmu_counter_alloc(u32 core_id)
{
unsigned long flags;
int handle;
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if (unlikely(!pmu_dev))
return -ENODEV;
spin_lock_irqsave(&pmu_dev->lock, flags);
handle = bitmap_find_free_region(pmu_dev->pmu_bitmap,
MDLA_PMU_COUNTERS, 0);
spin_unlock_irqrestore(&pmu_dev->lock, flags);
if (unlikely(handle < 0))
return -EINVAL;
return handle;
}
/* for ioctrl */
static int mdla_pmu_counter_free(u32 core_id, int handle)
{
unsigned long flags;
int ret = 0;
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
spin_lock_irqsave(&pmu_dev->lock, flags);
bitmap_release_region(pmu_dev->pmu_bitmap, handle, 0);
mdla_pmu_event_write(core_id, handle, COUNTER_CLEAR);
spin_unlock_irqrestore(&pmu_dev->lock, flags);
return ret;
}
static int mdla_pmu_ioctl(struct file *filp,
u32 command, unsigned long arg, bool need_pwr_on)
{
long retval = 0;
struct mdla_dev *mdla_device;
struct mdla_pmu_info *pmu_info;
struct ioctl_perf perf_data;
u32 core_id;
int cnt_idx = 0;
int i;
if (copy_from_user(&perf_data, (void *) arg, sizeof(perf_data)))
return -EFAULT;
core_id = perf_data.mdlaid;
if (core_id_is_invalid(core_id))
return -EINVAL;
mdla_device = mdla_get_device(core_id);
/* set priority level = 1 for ioctl */
pmu_info = &mdla_device->pmu_info[0];
if (need_pwr_on) {
mdla_pwr_ops_get()->lock(core_id);
if (mdla_device->power_is_on == false) {
mdla_err("mdla%d power off, pmu ioctl FAIL\n", core_id);
goto out;
}
}
switch (command) {
case IOCTL_PERF_SET_EVENT:
perf_data.handle = mdla_pmu_counter_alloc(core_id);
if (perf_data.handle >= 0)
mdla_pmu_counter_event_set(core_id,
perf_data.handle,
(perf_data.interface << 16) | perf_data.event);
break;
case IOCTL_PERF_UNSET_EVENT:
mdla_pmu_counter_free(core_id, perf_data.handle);
break;
case IOCTL_PERF_GET_EVENT:
perf_data.event = mdla_pmu_counter_event_get(
core_id, perf_data.handle);
break;
case IOCTL_PERF_GET_CNT:
cnt_idx = perf_data.handle;
if (cnt_idx < MDLA_PMU_COUNTERS && cnt_idx >= 0)
perf_data.counter = pmu_info->data.l_counters[cnt_idx];
break;
case IOCTL_PERF_GET_START:
perf_data.start = pmu_info->data.l_start_t;
break;
case IOCTL_PERF_GET_END:
perf_data.end = pmu_info->data.l_end_t;
break;
case IOCTL_PERF_GET_CYCLE:
perf_data.start = pmu_info->data.l_cycle;
break;
case IOCTL_PERF_RESET_CNT:
mdla_cmd_ops_get()->lock(mdla_device);
for (i = 0; i < PRIORITY_LEVEL; i++)
mdla_pmu_reset_counter_variable(
&mdla_device->pmu_info[i]);
mdla_pmu_reset_counter(core_id);
mdla_cmd_ops_get()->unlock(mdla_device);
break;
case IOCTL_PERF_RESET_CYCLE:
mdla_cmd_ops_get()->lock(mdla_device);
for (i = 0; i < PRIORITY_LEVEL; i++)
mdla_pmu_reset_cycle_variable(
&mdla_device->pmu_info[i]);
mdla_pmu_reset_cycle(core_id);
mdla_cmd_ops_get()->unlock(mdla_device);
break;
case IOCTL_PERF_SET_MODE:
mdla_cmd_ops_get()->lock(mdla_device);
mdla_pmu_percmd_mode_set(pmu_info, perf_data.mode);
mdla_pmu_percmd_mode_write(core_id, pmu_info);
mdla_cmd_ops_get()->unlock(mdla_device);
break;
default:
break;
}
if (copy_to_user((void *) arg, &perf_data, sizeof(perf_data)))
retval = -EFAULT;
out:
if (need_pwr_on)
mdla_pwr_ops_get()->unlock(core_id);
return retval;
}
void mdla_v1_x_pmu_info_show(struct seq_file *s)
{
int i, p, c;
struct mdla_pmu_info *pmu;
for_each_mdla_core(i) {
seq_printf(s, "%d: CFG_PMCR(0x%08x)=0x%x\n",
i, CFG_PMCR,
biu_read(i, CFG_PMCR));
seq_printf(s, "%d: PMU_CLK_CNT(0x%08x)=0x%x\n",
i, PMU_CLK_CNT,
biu_read(i, PMU_CLK_CNT));
seq_printf(s, "%d: PMU_START_TSTAMP(0x%08x)=0x%x\n",
i, PMU_START_TSTAMP,
biu_read(i, PMU_START_TSTAMP));
seq_printf(s, "%d: PMU_END_TSTAMP(0x%08x)=0x%x\n",
i, PMU_END_TSTAMP,
biu_read(i, PMU_END_TSTAMP));
seq_printf(s, "%d: PMU_CMDID_LATCH(0x%08x)=0x%x\n",
i, PMU_CMDID_LATCH,
biu_read(i, PMU_CMDID_LATCH));
for (c = 0; c < MDLA_PMU_COUNTERS; c++) {
seq_printf(s, "%d: counter %2d, 0x%04x=0x%-8x, 0x%04x=%d, 0x%04x=%d\n",
i, c,
PMU(c),
biu_read(c, PMU(c)),
PMU_CNT(c),
biu_read(c, PMU_CNT(c)),
PMU_CNT_LATCH(c),
biu_read(c, PMU_CNT_LATCH(c)));
}
for (p = 0; p < PRIORITY_LEVEL; p++) {
pmu = &mdla_get_device(i)->pmu_info[p];
seq_printf(s, "%d: priority = %d, number_of_event = %d\n",
i, p, pmu->number_of_event);
for (c = 0; c < MDLA_PMU_COUNTERS; c++)
seq_printf(s, "%d: priority=%d, counter %2d : event=0x%-8x, count=%d\n",
i, p, c,
pmu->data.event_handle[c],
pmu->data.l_counters[c]);
}
}
seq_printf(s, "set event by %s\n",
mdla_dbg_read_u32(FS_PMU_EVT_BY_APU) ? "apusys" : "debugfs");
}
void mdla_v1_x_pmu_init(struct mdla_dev *mdla_info)
{
int i;
struct mdla_pmu_info *info;
struct mdla_pmu_dev *dev;
struct mdla_util_pmu_ops *pmu_ops = mdla_util_pmu_ops_get();
info = kcalloc(PRIORITY_LEVEL, sizeof(struct mdla_pmu_info),
GFP_KERNEL);
if (!info)
return;
dev = kzalloc(sizeof(struct mdla_pmu_dev), GFP_KERNEL);
if (!dev) {
kfree(info);
return;
}
for (i = 0; i < PRIORITY_LEVEL; i++)
info[i].data.cfg_percmd_mode = NORMAL;
spin_lock_init(&dev->lock);
mdla_info->pmu_dev = dev;
mdla_info->pmu_info = info;
mdla_ioctl_register_perf_handle(mdla_pmu_ioctl);
pmu_ops->reg_counter_save = mdla_pmu_counter_save;
pmu_ops->reg_counter_read = mdla_pmu_counter_read_all;
pmu_ops->clr_counter_variable = mdla_pmu_reset_counter_variable;
pmu_ops->clr_cycle_variable = mdla_pmu_reset_cycle_variable;
pmu_ops->get_num_evt = mdla_pmu_get_num_evt;
pmu_ops->set_num_evt = mdla_pmu_set_num_evt;
pmu_ops->set_percmd_mode = mdla_pmu_percmd_mode_set;
pmu_ops->get_curr_mode = mdla_pmu_get_mode;
pmu_ops->get_perf_end = mdla_pmu_get_perf_end;
pmu_ops->get_perf_cycle = mdla_pmu_get_perf_cycle;
pmu_ops->get_perf_cmdid = mdla_pmu_get_perf_cmdid;
pmu_ops->get_perf_cmdcnt = mdla_pmu_get_perf_cmdcnt;
pmu_ops->get_counter = mdla_pmu_get_counter;
pmu_ops->reset_counter = mdla_pmu_reset_counter;
pmu_ops->disable_counter = mdla_pmu_counter_disable_all;
pmu_ops->enable_counter = mdla_pmu_counter_enable_all;
pmu_ops->reset = mdla_pmu_reset;
pmu_ops->write_evt_exec = mdla_pmu_event_write_all;
pmu_ops->reset_write_evt_exec = mdla_pmu_reset_and_write_event;
pmu_ops->get_hnd_evt = mdla_pmu_get_hnd_evt;
pmu_ops->get_hnd_evt_num = mdla_pmu_get_hnd_evt_num;
pmu_ops->get_hnd_mode = mdla_pmu_get_hnd_mode;
pmu_ops->get_hnd_buf_addr = mdla_pmu_get_hnd_buf_addr;
pmu_ops->set_evt_handle = mdla_pmu_set_evt_handle;
pmu_ops->get_info = mdla_pmu_get_info;
pmu_ops->apu_cmd_prepare = mdla_pmu_cmd_prepare;
pmu_ops->apu_pmu_valid = mdla_pmu_apusys_valid;
if (mdla_plat_nn_pmu_support())
mdla_util_apusys_pmu_support(true);
else
mdla_util_apusys_pmu_support(false);
}
void mdla_v1_x_pmu_deinit(struct mdla_dev *mdla_info)
{
mdla_util_apusys_pmu_support(false);
mdla_ioctl_unregister_perf_handle();
kfree(mdla_info->pmu_dev);
kfree(mdla_info->pmu_info);
}
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_V1_X_PMU_H__
#define __MDLA_V1_X_PMU_H__
struct seq_file;
struct mdla_dev;
void mdla_v1_x_pmu_info_show(struct seq_file *s);
void mdla_v1_x_pmu_init(struct mdla_dev *mdla_info);
void mdla_v1_x_pmu_deinit(struct mdla_dev *mdla_info);
#endif /* __MDLA_V1_X_PMU_H__ */
@@ -0,0 +1,581 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/list.h>
#include <linux/preempt.h>
#include <linux/sched/clock.h>
#include <apusys_device.h>
#include <common/mdla_device.h>
#include <common/mdla_scheduler.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_debug.h>
#include <interface/mdla_cmd_data_v1_x.h>
#include "mdla_hw_reg_v1_x.h"
struct command_batch {
struct list_head node;
u32 index;
u32 size;
};
struct sched_smp_ce {
spinlock_t lock;
u64 deadline;
};
static struct sched_smp_ce smp_ce[PRIORITY_LEVEL];
static struct lock_class_key smp_ce_lock_key[PRIORITY_LEVEL];
static struct lock_class_key sched_lock_key[MAX_CORE_NUM];
static void mdla_sched_set_smp_deadline(int priority, u64 deadline)
{
unsigned long flags;
if (unlikely(priority < 0 || priority >= PRIORITY_LEVEL))
return;
spin_lock_irqsave(&smp_ce[priority].lock, flags);
if (deadline > smp_ce[priority].deadline)
smp_ce[priority].deadline = deadline;
spin_unlock_irqrestore(&smp_ce[priority].lock, flags);
}
static u64 mdla_sched_get_smp_deadline(int priority)
{
if (unlikely(priority < 0 || priority >= PRIORITY_LEVEL))
return 0;
return smp_ce[priority].deadline;
}
static inline u32 mdla_get_swcmd(void *base_kva, u32 offset)
{
return (*(u32 *)(base_kva + offset));
}
static inline void mdla_set_swcmd(void *base_kva, u32 offset, u32 val)
{
(*(u32 *)(base_kva + offset)) = val;
}
//cid, which cmd id layer end bit do you want to get
static inline bool mdla_is_layer_end(void *base_kva, u32 cid)
{
return (mdla_get_swcmd(base_kva + (cid - 1) * MREG_CMD_SIZE,
MREG_CMD_GENERAL_CTRL_0)
& MSK_MREG_CMD_LAYER_END);
}
//cid, which cmd id wait bit do you want to clear
static inline void mdla_clear_swcmd_wait_bit(void *base_kva, u32 cid)
{
void *cmd_kva = base_kva + (cid - 1) * MREG_CMD_SIZE;
mdla_set_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1,
mdla_get_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1)
& ~MSK_MREG_CMD_SWCMD_WAIT_SWCMDDONE);
}
//cid, which cmd id issue bit do you want to clear
static inline void mdla_clear_swcmd_int_bit(void *base_kva, u32 cid)
{
void *cmd_kva = base_kva + (cid - 1) * MREG_CMD_SIZE;
mdla_set_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1,
mdla_get_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1)
& ~MSK_MREG_CMD_SWCMD_INT_SWCMDDONE);
}
static inline void mdla_set_swcmd_done_int(void *base_kva, u32 cid)
{
void *cmd_kva = base_kva + (cid - 1) * MREG_CMD_SIZE;
mdla_set_swcmd(cmd_kva, MREG_CMD_TILE_CNT_INT,
mdla_get_swcmd(cmd_kva, MREG_CMD_TILE_CNT_INT)
| MSK_MREG_CMD_SWCMD_FINISH_INT_EN);
}
/*
* Enqueue one CE and start scheduler
*
*/
static void mdla_sched_enqueue_ce(u32 core_id, struct command_entry *ce, u32 resume)
{
struct mdla_scheduler *sched = mdla_get_device(core_id)->sched;
if (!ce)
return;
if (resume) {
list_add(&ce->node, &sched->ce_list[ce->priority]);
ce->state |= BIT(CE_QUEUE_RESUME);
} else {
list_add_tail(&ce->node, &sched->ce_list[ce->priority]);
ce->state |= BIT(CE_QUEUE);
}
ce_func_trace(ce, F_ENQUEUE | resume);
}
/*
* Consume the processing_ce:
* 1. get the finished command id and tile id from HW RGs
* 2. check whether this batch completed
*
* Return value:
* 1. return CE_DONE if all the batches in the CE completed.
* 2. return CE_RUN if a batch completed, and we can go on to issue the next.
* 3. return CE_NONE if the batch is still under processing.
*
* NOTE: sched->lock should be acquired by caller
*/
static int mdla_sched_process_ce(u32 core_id)
{
unsigned long flags;
int ret = CE_NONE;
struct command_entry *ce;
struct command_batch *cb;
struct mdla_dev *dev = mdla_get_device(core_id);
struct mdla_scheduler *sched = dev->sched;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
struct mdla_pmu_info *pmu;
u32 fin_cid;
spin_lock_irqsave(&dev->hw_lock, flags);
/* Read current EVT_ID */
fin_cid = io->cmde.read(core_id, MREG_TOP_G_FIN3);
spin_unlock_irqrestore(&dev->hw_lock, flags);
ce = sched->pro_ce;
if (!ce)
return ret;
ce->fin_cid = fin_cid;
if (fin_cid < ce->wish_fin_cid) {
ce->irq_state |= IRQ_TWICE;
ce_func_trace(ce, F_CMDDONE_CE_FIN3ERROR);
return ret;
}
/* read after write make sure it will write back to register now */
spin_lock_irqsave(&dev->hw_lock, flags);
pmu = mdla_util_pmu_ops_get()->get_info(core_id, (u16)ce->priority);
if (pmu)
mdla_util_pmu_ops_get()->reg_counter_save(core_id, pmu);
io->cmde.write(core_id, MREG_TOP_G_CDMA4, 1);
spin_unlock_irqrestore(&dev->hw_lock, flags);
if (ce->batch_list_head != NULL) {
if (likely(!list_empty(ce->batch_list_head))) {
cb = list_first_entry(ce->batch_list_head,
struct command_batch, node);
list_del(&cb->node);
kfree(cb);
}
}
/* all command done for command-based scheduling */
if (fin_cid >= ce->count) {
ret = CE_DONE;
ce->state |= (1 << CE_DONE);
} else {
ret = CE_SCHED;
ce->state |= (1 << CE_SCHED);
}
return ret;
}
/*
* Issue the processing_ce to HW engine
* NOTE: sched->lock should be acquired by caller
*/
static void mdla_sched_issue_ce(u32 core_id)
{
dma_addr_t addr;
u32 nr_cmd_to_issue, irq_status;
struct mdla_dev *dev = mdla_get_device(core_id);
struct mdla_scheduler *sched = dev->sched;
struct command_entry *ce;
struct command_batch *cb;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
unsigned long flags;
ce = sched->pro_ce;
if (!ce) {
mdla_util_pmu_ops_get()->disable_counter(core_id);
return;
}
addr = ce->mva + ((dma_addr_t)ce->fin_cid) * MREG_CMD_SIZE;
nr_cmd_to_issue = ce->count - ce->fin_cid;
if ((ce->batch_list_head != NULL)
&& !list_empty(ce->batch_list_head)) {
cb = list_first_entry(ce->batch_list_head,
struct command_batch, node);
nr_cmd_to_issue = cb->size;
}
ce->wish_fin_cid = ce->fin_cid + nr_cmd_to_issue;
spin_lock_irqsave(&dev->hw_lock, flags);
irq_status = io->cmde.read(core_id, MREG_TOP_G_INTP0);
if (likely(irq_status & MDLA_IRQ_CDMA_FIFO_EMPTY)) {
u64 deadline = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
/* reset pmu and set register */
mdla_util_pmu_ops_get()->reset_write_evt_exec(core_id,
(u16)ce->cmd_batch_en);
ce->state |= (1 << CE_RUN);
if (likely(ce->context_callback != NULL))
ce->context_callback(
APUSYS_DEVICE_MDLA,
core_id, ce->ctx_id);
/* update smp deadline */
if (ce->multicore_total > 1)
mdla_sched_set_smp_deadline(ce->priority, deadline);
else
ce->deadline_t = deadline;
/* set command address */
io->cmde.write(core_id, MREG_TOP_G_CDMA1, addr);
/* set command number */
io->cmde.write(core_id, MREG_TOP_G_CDMA2, nr_cmd_to_issue);
ce->req_start_t = sched_clock();
/* trigger engine */
io->cmde.write(core_id, MREG_TOP_G_CDMA3, ce->csn);
ce_func_trace(ce, F_ISSUE);
} else {
if ((ce->irq_state & IRQ_N_EMPTY_IN_SCHED) == 0)
ce->irq_state |= IRQ_NE_ISSUE_FIRST;
ce->irq_state |= IRQ_N_EMPTY_IN_ISSUE;
ce->state |= (1 << CE_SKIP);
if (in_interrupt())
ce->irq_state |= IRQ_IN_IRQ;
else
ce->irq_state |= IRQ_NOT_IN_IRQ;
}
spin_unlock_irqrestore(&dev->hw_lock, flags);
}
/*
* Set the status of completed CE as CE_FIN
* NOTE: sched->lock should be acquired by caller
*/
static void mdla_sched_complete_ce(u32 core_id)
{
struct mdla_scheduler *sched = mdla_get_device(core_id)->sched;
sched->pro_ce->state |= (1 << CE_FIN);
complete(&sched->pro_ce->swcmd_done_wait);
sched->pro_ce = NULL;
}
/*
* Dequeue a prioritized CE from active CE queue, handle the context switch of
* the original processing_ce, and set the prioritized CE as processing_ce.
*
* NOTE: sched->lock should be acquired by caller
*/
static struct command_entry *mdla_sched_dequeue_ce(u32 core_id)
{
struct mdla_scheduler *sched = mdla_get_device(core_id)->sched;
struct command_entry *ce = NULL;
int prio;
for (prio = PRIORITY_LEVEL - 1; prio >= 0; prio--) {
ce = list_first_entry_or_null(&sched->ce_list[prio], struct command_entry, node);
if (ce) {
list_del(&ce->node);
ce_func_trace(ce, F_DEQUEUE);
break;
}
}
return ce;
}
static void mdla_sched_normal_smp_issue_ce(
uint32_t core_id,
uint64_t dual_cmd_id)
{
struct mdla_scheduler *sched;
unsigned long flags[MAX_CORE_NUM];
struct command_entry *ce;
int i;
for_each_mdla_core(i) {
sched = mdla_get_device(i)->sched;
if (sched->pro_ce != NULL)
goto unlock;
spin_lock_irqsave(&sched->lock, flags[i]);
}
/* check list status */
for_each_mdla_core(i) {
ce = mdla_sched_dequeue_ce(i);
if ((ce == NULL) || (ce->cmd_id != dual_cmd_id)
|| (ce->priority != MDLA_LOW_PRIORITY)) {
mdla_get_device(i)->sched->pro_ce = ce;
break;
}
mdla_get_device(i)->sched->pro_ce = ce;
}
if (i == mdla_util_get_core_num()) {
for_each_mdla_core(i)
mdla_sched_issue_ce(i);
} else {
for (; i >= 0; i--) {
sched = mdla_get_device(i)->sched;
mdla_sched_enqueue_ce(i, sched->pro_ce, 2);
sched->pro_ce = NULL;
}
}
i = mdla_util_get_core_num();
unlock:
/* free all cores spin lock */
for (i = i - 1; i >= 0; i--)
spin_unlock_irqrestore(&mdla_get_device(i)->sched->lock, flags[i]);
}
void mdla_preempt_ce(unsigned int core_id, struct command_entry *high_ce)
{
struct mdla_scheduler *sched = mdla_get_device(core_id)->sched;
struct command_entry *low_ce = sched->pro_ce;
low_ce->state |= (1 << CE_PREEMPTED);
low_ce->deadline_t = get_jiffies_64() + msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
sched->enqueue_ce(core_id, low_ce, 1);
mdla_dbg_add_u32(FS_PREEMPTION_TIMES, 1);
high_ce->state |= (1 << CE_PREEMPTING);
sched->pro_ce = high_ce;
}
static void mdla_del_free_command_batch(struct command_entry *ce)
{
struct command_batch *cb;
struct list_head *tmp, *next;
if (unlikely(ce->cmd_batch_size >= ce->count))
return;
list_for_each_safe(tmp, next, ce->batch_list_head) {
cb = list_entry(tmp, struct command_batch, node);
list_del(&cb->node);
kfree(cb);
}
kfree(ce->batch_list_head);
ce->batch_list_head = NULL;
}
static void mdla_split_alloc_command_batch(struct command_entry *ce)
{
size_t i, j;
u32 cur_batch_len = 0;
u32 batch_tail_id = 0;
u32 batch_size = ce->cmd_batch_size;
u32 cmd_count = ce->count;
struct command_batch *cb;
struct list_head *tmp, *next;
if (unlikely(ce->cmdbuf == NULL))
return;
ce->batch_list_head =
kzalloc(sizeof(struct list_head), GFP_KERNEL);
if (!ce->batch_list_head)
return;
INIT_LIST_HEAD(ce->batch_list_head);
apusys_mem_invalidate(ce->cmdbuf);
// TODO: add default policy when batch_size is zero
for (i = 1; i <= cmd_count; i += cur_batch_len) {
cur_batch_len = 0;
for (j = i; j <= cmd_count; ++j) {
cur_batch_len++;
if (cur_batch_len >= batch_size &&
mdla_is_layer_end(ce->kva, j))
break;
}
// allocate one command batch
cb = kzalloc(sizeof(*cb), GFP_KERNEL);
if (!cb) {
mdla_del_free_command_batch(ce);
return;
}
cb->index = i;// first cmd id
cb->size = cur_batch_len;
batch_tail_id = i + cur_batch_len - 1;// Last cmd id
list_add_tail(&cb->node, ce->batch_list_head);
// encode SWCMD DONE
mdla_set_swcmd_done_int(ce->kva, batch_tail_id);
// handle first cmd wait bit and check fuse cmd
mdla_clear_swcmd_wait_bit(ce->kva, cb->index);
if (batch_tail_id > cb->index &&
!mdla_is_layer_end(ce->kva, cb->index)) {
mdla_clear_swcmd_wait_bit(ce->kva, cb->index + 1);
}
// encode the previous layer if that is fused with tail
mdla_clear_swcmd_int_bit(ce->kva, batch_tail_id);
if (batch_tail_id > 1 &&
!mdla_is_layer_end(ce->kva, batch_tail_id - 1)) {
mdla_set_swcmd_done_int(ce->kva, batch_tail_id - 1);
mdla_clear_swcmd_int_bit(ce->kva, batch_tail_id - 1);
}
}
// buffer sync here
if (likely(ce->cmdbuf != NULL))
apusys_mem_flush(ce->cmdbuf);
if (mdla_dbg_read_u32(FS_PREEMPTION_DBG))
list_for_each_safe(tmp, next, ce->batch_list_head) {
cb = list_entry(tmp, struct command_batch, node);
mdla_cmd_debug("%s: id = %d, size = %d, tid = %d\n",
__func__, cb->index,
cb->size, cb->index + cb->size - 1);
}
}
static void mdla_backup_command_batch(struct command_entry *ce)
{
uint32_t i = 0;
void *cmd_kva = NULL;
if (unlikely(!ce->cmd_int_backup || !ce->cmd_ctrl_1_backup))
return;
apusys_mem_invalidate(ce->cmdbuf);
/* backup cmd buffer value */
for (i = 1; i <= ce->count; i++) {
cmd_kva = ce->kva + (i - 1) * MREG_CMD_SIZE;
ce->cmd_int_backup[i - 1] =
mdla_get_swcmd(cmd_kva, MREG_CMD_TILE_CNT_INT);
ce->cmd_ctrl_1_backup[i - 1] =
mdla_get_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1);
}
apusys_mem_flush(ce->cmdbuf);
}
static void mdla_restore_command_batch(struct command_entry *ce)
{
uint32_t i = 0;
void *cmd_kva = NULL;
if (unlikely(ce->cmdbuf == NULL))
return;
if (unlikely(!ce->cmd_int_backup || !ce->cmd_ctrl_1_backup))
return;
apusys_mem_invalidate(ce->cmdbuf);
for (i = 1; i <= ce->count; i++) {
cmd_kva = ce->kva + (i - 1) * MREG_CMD_SIZE;
mdla_set_swcmd(cmd_kva,
MREG_CMD_TILE_CNT_INT, ce->cmd_int_backup[i - 1]);
mdla_set_swcmd(cmd_kva,
MREG_CMD_GENERAL_CTRL_1, ce->cmd_ctrl_1_backup[i - 1]);
}
apusys_mem_flush(ce->cmdbuf);
}
int mdla_v1_x_sched_init(void)
{
struct mdla_scheduler *sched;
struct mdla_sched_cb_func *sched_cb = mdla_sched_plat_cb();
int i, j;
for_each_mdla_core(i) {
sched = kzalloc(sizeof(struct mdla_scheduler), GFP_KERNEL);
if (!sched)
goto err;
mdla_get_device(i)->sched = sched;
spin_lock_init(&sched->lock);
lockdep_set_class(&sched->lock, &sched_lock_key[i]);
for (j = 0; j < PRIORITY_LEVEL; j++)
INIT_LIST_HEAD(&sched->ce_list[j]);
sched->pro_ce = NULL;
sched->enqueue_ce = mdla_sched_enqueue_ce;
sched->dequeue_ce = mdla_sched_dequeue_ce;
sched->process_ce = mdla_sched_process_ce;
sched->issue_ce = mdla_sched_issue_ce;
sched->complete_ce = mdla_sched_complete_ce;
sched->issue_dual_lowce = mdla_sched_normal_smp_issue_ce;
sched->preempt_ce = mdla_preempt_ce;
sched->get_smp_deadline = mdla_sched_get_smp_deadline;
sched->set_smp_deadline = mdla_sched_set_smp_deadline;
}
for (i = 0; i < PRIORITY_LEVEL; i++) {
spin_lock_init(&smp_ce[i].lock);
lockdep_set_class(&smp_ce[i].lock, &smp_ce_lock_key[i]);
}
/* set scheduler callback */
sched_cb->split_alloc_cmd_batch = mdla_split_alloc_command_batch;
sched_cb->del_free_cmd_batch = mdla_del_free_command_batch;
sched_cb->backup_cmd_batch = mdla_backup_command_batch;
sched_cb->restore_cmd_batch = mdla_restore_command_batch;
return 0;
err:
for (i = i - 1; i >= 0; i--)
kfree(mdla_get_device(i)->sched);
return -ENOMEM;
}
void mdla_v1_x_sched_deinit(void)
{
int i;
for_each_mdla_core(i)
kfree(mdla_get_device(i)->sched);
}
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_V1_X_SCHED_H__
#define __MDLA_V1_X_SCHED_H__
int mdla_v1_x_sched_init(void);
void mdla_v1_x_sched_deinit(void);
#endif /* __MDLA_V1_X_SCHED_H__ */
@@ -0,0 +1,688 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_device.h>
#include <linux/io.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/interrupt.h>
#include <linux/completion.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/debugfs.h>
#include <linux/sched/clock.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_trace.h>
#include <interface/mdla_intf.h>
#include <interface/mdla_cmd_data_v1_x.h>
#include <platform/mdla_plat_api.h>
#include "mdla_hw_reg_v1_x.h"
#include "mdla_irq_v1_x.h"
#include "mdla_pmu_v1_x.h"
#include "mdla_sched_v1_x.h"
#define DBGFS_PMU_NAME "pmu_reg"
#define DBGFS_USAGE_NAME "help"
static struct mdla_reg_ctl *mdla_reg_control;
static void *apu_conn_top;
static void *apu_mdla_gsm_top;
static void *apu_mdla_gsm_base;
static struct mdla_dev *mdla_plat_devices;
static u32 fs_zero_skip_count;
static int mdla_dbgfs_u64_create[NF_MDLA_DEBUG_FS_U64] = {
[FS_CFG_PMU_PERIOD] = 1,
};
static bool mdla_dbgfs_u32_create[NF_MDLA_DEBUG_FS_U32] = {
[FS_C1] = 1,
[FS_C2] = 1,
[FS_C3] = 1,
[FS_C4] = 1,
[FS_C5] = 1,
[FS_C6] = 1,
[FS_C7] = 1,
[FS_C8] = 1,
[FS_C9] = 1,
[FS_C10] = 1,
[FS_C11] = 1,
[FS_C12] = 1,
[FS_C13] = 1,
[FS_C14] = 1,
[FS_C15] = 1,
[FS_CFG_ENG0] = 1,
[FS_CFG_ENG1] = 1,
[FS_CFG_ENG2] = 1,
[FS_CFG_ENG11] = 1,
[FS_POLLING_CMD_DONE] = 1,
[FS_DUMP_CMDBUF] = 1,
[FS_DVFS_RAND] = 1,
[FS_PMU_EVT_BY_APU] = 1,
[FS_KLOG] = 1,
[FS_POWEROFF_TIME] = 1,
[FS_TIMEOUT] = 1,
[FS_TIMEOUT_DBG] = 1,
[FS_BATCH_NUM] = 1,
[FS_PREEMPTION_TIMES] = 1,
[FS_PREEMPTION_DBG] = 1,
};
static struct lock_class_key hw_lock_key[MAX_CORE_NUM];
/* platform static functions */
static bool mdla_check_cmd_valid(
uint64_t out_end,
struct command_entry *ce)
{
uint64_t out_size;
if ((uint64_t)ce->kva == 0) {
mdla_err("%s:%d query kva = 0\n", __func__, __LINE__);
return false;
}
if (out_end < (uint64_t)ce->kva) {
mdla_err("%s:%d invalid cmd buffer addr\n", __func__, __LINE__);
return false;
}
out_size = out_end - (uint64_t)ce->kva;
if (out_size < (uint64_t)ce->count*MREG_CMD_SIZE) {
mdla_err("%s:%d invalid cmd buffer size\n", __func__, __LINE__);
return false;
}
return true;
}
static int mdla_plat_zero_skip_detect(u32 core_id)
{
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
u32 debug_intf, front_c_invalid;
unsigned long flags;
spin_lock_irqsave(&mdla_get_device(core_id)->hw_lock, flags);
if (io->cmde.read(core_id, 0x0DB0) != 0x6) {
spin_unlock_irqrestore(&mdla_get_device(core_id)->hw_lock, flags);
return 0;
}
debug_intf =
io->cmde.read(core_id, 0x0DB8);
front_c_invalid =
io->cmde.read(core_id, 0x0D74);
spin_unlock_irqrestore(&mdla_get_device(core_id)->hw_lock, flags);
if ((debug_intf == front_c_invalid) ||
(debug_intf == (front_c_invalid/2))) {
mdla_timeout_debug("core:%d, %s: match zero skip issue\n",
core_id,
__func__);
fs_zero_skip_count++;
return -1;
}
return 0;
}
static void mdla_plat_print_post_cmd_info(u32 core_id)
{
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
mdla_verbose("%s: C:%d,FIN1: %.8x\n",
__func__,
core_id,
io->cmde.read(core_id, MREG_TOP_G_FIN1));
mdla_verbose("dst addr:%.8x\n", io->cmde.read(core_id, 0xE3C));
mdla_pmu_debug("%s: CFG_PMCR: %8x, pmu_clk_cnt: %.8x\n",
__func__,
io->biu.read(core_id, CFG_PMCR),
io->biu.read(core_id, PMU_CLK_CNT));
}
static inline unsigned long mdla_plat_get_wait_time(u32 core_id)
{
unsigned long time;
if (mdla_trace_get_cfg_pmu_tmr_en())
time = usecs_to_jiffies(mdla_dbg_read_u64(FS_CFG_PMU_PERIOD));
else
time = msecs_to_jiffies(mdla_dbg_read_u32(FS_POLLING_CMD_DONE));
return time;
}
static void mdla_plat_destroy_dump_cmdbuf(struct mdla_dev *mdla_device)
{
mutex_lock(&mdla_device->cmd_buf_dmp_lock);
if (mdla_device->cmd_buf_len) {
kvfree(mdla_device->cmd_buf_dmp);
mdla_device->cmd_buf_len = 0;
}
mutex_unlock(&mdla_device->cmd_buf_dmp_lock);
}
static int mdla_plat_create_dump_cmdbuf(struct mdla_dev *mdla_device, struct command_entry *ce)
{
int ret = 0;
if (ce->kva == NULL)
return ret;
mutex_lock(&mdla_device->cmd_buf_dmp_lock);
if (mdla_device->cmd_buf_len)
kvfree(mdla_device->cmd_buf_dmp);
mdla_device->cmd_buf_dmp = kvmalloc(ce->count * MREG_CMD_SIZE, GFP_KERNEL);
if (!mdla_device->cmd_buf_dmp) {
ret = -ENOMEM;
mdla_err("%s: kvmalloc: failed\n", __func__);
goto out;
}
mdla_device->cmd_buf_len = ce->count * MREG_CMD_SIZE;
memcpy(mdla_device->cmd_buf_dmp, ce->kva, mdla_device->cmd_buf_len);
out:
mutex_unlock(&mdla_device->cmd_buf_dmp_lock);
return ret;
}
static int mdla_plat_pre_cmd_handle(u32 core_id, struct command_entry *ce)
{
if (ce->multicore_total > 1)
mdla_plat_devices[core_id].sched->set_smp_deadline(ce->priority, ce->deadline_t);
if (mdla_dbg_read_u32(FS_DUMP_CMDBUF))
mdla_plat_create_dump_cmdbuf(mdla_get_device(core_id), ce);
return 0;
}
static int mdla_plat_wait_cmd_handle(u32 core_id, struct command_entry *ce)
{
/* update SMP CMD deadline */
if (ce->multicore_total > 1) {
u64 deadline = mdla_plat_devices[core_id].sched->get_smp_deadline(ce->priority);
if (deadline > ce->deadline_t)
ce->deadline_t = deadline;
}
return 0;
}
/* NOTE: hw_lock should be acquired by caller */
static void mdla_plat_raw_process_command(u32 core_id, u32 evt_id, dma_addr_t addr, u32 count)
{
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
/* set command address */
io->cmde.write(core_id, MREG_TOP_G_CDMA1, addr);
/* set command number */
io->cmde.write(core_id, MREG_TOP_G_CDMA2, count);
mdla_plat_devices[core_id].sched->pro_ce->req_start_t = sched_clock();
/* trigger hw */
io->cmde.write(core_id, MREG_TOP_G_CDMA3, evt_id);
}
static int mdla_plat_process_command(u32 core_id, struct command_entry *ce)
{
dma_addr_t addr;
u32 evt_id, count;
unsigned long flags;
addr = ce->mva;
count = ce->count;
evt_id = ce->count;
mdla_verbose("%s: count: %d, addr: %lx\n",
__func__, ce->count,
(unsigned long)addr);
spin_lock_irqsave(&mdla_get_device(core_id)->hw_lock, flags);
mdla_util_pmu_ops_get()->reset(core_id);
mdla_util_pmu_ops_get()->write_evt_exec(core_id, 0);
ce->state = CE_RUN;
mdla_plat_raw_process_command(core_id, evt_id, addr, count);
spin_unlock_irqrestore(&mdla_get_device(core_id)->hw_lock, flags);
return 0;
}
static void mdla_plat_dump_reg(u32 core_id, struct seq_file *s)
{
dump_reg_cfg(core_id, MDLA_CG_CON);
dump_reg_cfg(core_id, MDLA_SW_RST);
dump_reg_cfg(core_id, MDLA_MBIST_MODE0);
dump_reg_cfg(core_id, MDLA_MBIST_MODE1);
dump_reg_cfg(core_id, MDLA_MBIST_CTL);
dump_reg_cfg(core_id, MDLA_MBIST_DEFAULT_DELSEL);
dump_reg_cfg(core_id, MDLA_RP_RST);
dump_reg_cfg(core_id, MDLA_RP_CON);
dump_reg_cfg(core_id, MDLA_AXI_CTRL);
dump_reg_cfg(core_id, MDLA_AXI1_CTRL);
dump_reg_top(core_id, MREG_TOP_G_REV);
dump_reg_top(core_id, MREG_TOP_G_INTP0);
dump_reg_top(core_id, MREG_TOP_G_INTP1);
dump_reg_top(core_id, MREG_TOP_G_INTP2);
dump_reg_top(core_id, MREG_TOP_G_CDMA0);
dump_reg_top(core_id, MREG_TOP_G_CDMA1);
dump_reg_top(core_id, MREG_TOP_G_CDMA2);
dump_reg_top(core_id, MREG_TOP_G_CDMA3);
dump_reg_top(core_id, MREG_TOP_G_CDMA4);
dump_reg_top(core_id, MREG_TOP_G_CDMA5);
dump_reg_top(core_id, MREG_TOP_G_CDMA6);
dump_reg_top(core_id, MREG_TOP_G_CUR0);
dump_reg_top(core_id, MREG_TOP_G_CUR1);
dump_reg_top(core_id, MREG_TOP_G_FIN0);
dump_reg_top(core_id, MREG_TOP_G_FIN1);
dump_reg_top(core_id, MREG_TOP_G_FIN3);
dump_reg_top(core_id, MREG_TOP_G_IDLE);
}
static void mdla_plat_memory_show(struct seq_file *s)
{
struct mdla_dev *mdla_device;
int i;
u32 core_id;
u32 *cmd_addr;
seq_puts(s, "------- dump MDLA code buf -------\n");
for_each_mdla_core(core_id) {
mdla_device = mdla_get_device(core_id);
if (mdla_device->cmd_buf_len == 0)
continue;
seq_printf(s, "mdla %d code buf:\n", mdla_device->mdla_id);
mutex_lock(&mdla_device->cmd_buf_dmp_lock);
cmd_addr = mdla_device->cmd_buf_dmp;
for (i = 0; i < (mdla_device->cmd_buf_len/4); i++)
seq_printf(s, "count: %d, offset: %.8x, val: %.8x\n",
(i * 4) / MREG_CMD_SIZE,
(i * 4) % MREG_CMD_SIZE,
cmd_addr[i]);
mutex_unlock(&mdla_device->cmd_buf_dmp_lock);
}
}
static bool mdla_plat_dbgfs_u64_enable(int node)
{
return node >= 0 && node < NF_MDLA_DEBUG_FS_U64
? mdla_dbgfs_u64_create[node] : false;
}
static bool mdla_plat_dbgfs_u32_enable(int node)
{
return node >= 0 && node < NF_MDLA_DEBUG_FS_U32
? mdla_dbgfs_u32_create[node] : false;
}
static int mdla_plat_register_show(struct seq_file *s, void *data)
{
mdla_v1_x_pmu_info_show(s);
return 0;
}
static int mdla_plat_dbgfs_usage(struct seq_file *s, void *data)
{
seq_printf(s, "---- Kernel debug log maks (current = 0x%x) ----\n",
mdla_dbg_read_u32(FS_KLOG));
seq_printf(s, "echo [mask(hex)] > /d/mdla/%s\n",
mdla_dbg_get_u32_node_str(FS_KLOG));
mdla_dbg_show_klog_info(s, "\t");
seq_puts(s, "\n---- Dump MDLA HW register ----\n");
seq_printf(s, "cat /d/mdla/%s\n", DBGFS_HW_REG_NAME);
seq_puts(s, "\n---- Dump the last code buffer ----\n");
seq_printf(s, "echo [1|0] > /d/mdla/%s\n",
mdla_dbg_get_u32_node_str(FS_DUMP_CMDBUF));
seq_printf(s, "cat /proc/mdla/%s\n", DBGFS_CMDBUF_NAME);
seq_puts(s, "\n---- Command timeout setting ----\n");
seq_printf(s, "echo [ms(dec)] > /d/mdla/%s\n",
mdla_dbg_get_u32_node_str(FS_TIMEOUT));
seq_puts(s, "\n---- Set delay time of power off (default = 2s) ----\n");
seq_printf(s, "echo [ms(dec)] > /d/mdla/%s\n",
mdla_dbg_get_u32_node_str(FS_POWEROFF_TIME));
seq_puts(s, "\n---- Show power usage ----\n");
seq_printf(s, "cat /d/mdla/%s\n", DBGFS_PWR_NAME);
seq_puts(s, "\n---- Dump PMU data ----\n");
seq_printf(s, "cat /d/mdla/%s\n", DBGFS_PMU_NAME);
seq_puts(s, "\n");
return 0;
}
static void mdla_plat_dbgfs_init(struct device *dev, struct dentry *parent)
{
if (!dev || !parent)
return;
debugfs_create_devm_seqfile(dev, DBGFS_PMU_NAME, parent,
mdla_plat_register_show);
debugfs_create_u32("zero_skip_count", 0660,
parent, &fs_zero_skip_count);
debugfs_create_devm_seqfile(dev, DBGFS_USAGE_NAME, parent,
mdla_plat_dbgfs_usage);
}
static int mdla_plat_get_base_addr(struct platform_device *pdev, void **reg, int num)
{
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, num);
if (!res) {
dev_info(&pdev->dev, "invalid address (num = %d)\n", num);
return -ENODEV;
}
*reg = ioremap_nocache(res->start, res->end - res->start + 1);
if (*reg == 0) {
dev_info(&pdev->dev,
"could not allocate iomem (num = %d)\n", num);
return -EIO;
}
dev_info(&pdev->dev,
"IORESOURCE_MEM (num = %d) at 0x%08lx mapped to 0x%08lx\n",
num,
(unsigned long __force)res->start,
(unsigned long __force)res->end);
return 0;
}
static int mdla_dts_map(struct platform_device *pdev)
{
int i, mdla_idx, gsm_idx, apu_conn_idx;
struct device *dev = &pdev->dev;
u32 nr_core_ids = mdla_util_get_core_num();
dev_info(dev, "Device Tree Probing\n");
mdla_reg_control = kcalloc(nr_core_ids, sizeof(struct mdla_reg_ctl), GFP_KERNEL);
if (!mdla_reg_control)
return -1;
mdla_idx = 0;
gsm_idx = 3 * nr_core_ids;
apu_conn_idx = 3 * nr_core_ids + 1;
for (i = mdla_idx; i < nr_core_ids; i++) {
if (mdla_plat_get_base_addr(pdev,
&mdla_reg_control[i].apu_mdla_config_top,
3 * i))
goto err;
if (mdla_plat_get_base_addr(pdev,
&mdla_reg_control[i].apu_mdla_cmde_mreg_top,
3 * i + 1)) {
iounmap(mdla_reg_control[i].apu_mdla_config_top);
goto err;
}
if (mdla_plat_get_base_addr(pdev,
&mdla_reg_control[i].apu_mdla_biu_top,
3 * i + 2)) {
iounmap(mdla_reg_control[i].apu_mdla_cmde_mreg_top);
iounmap(mdla_reg_control[i].apu_mdla_config_top);
goto err;
}
}
if (mdla_plat_get_base_addr(pdev, &apu_mdla_gsm_top, gsm_idx))
goto err;
else
apu_mdla_gsm_base = (void *)platform_get_resource(pdev,
IORESOURCE_MEM, gsm_idx)->start;
dev_info(dev, "apu_mdla_gsm_top: %p, apu_mdla_gsm_base: %p\n",
apu_mdla_gsm_top, apu_mdla_gsm_base);
if (mdla_plat_get_base_addr(pdev, &apu_conn_top, apu_conn_idx))
goto err_conn;
if (mdla_v1_x_irq_request(dev, nr_core_ids))
goto err_irq;
return 0;
err_irq:
iounmap(apu_conn_top);
err_conn:
iounmap(apu_mdla_gsm_top);
err:
for (i = i - 1; i >= mdla_idx; i--) {
iounmap(mdla_reg_control[i].apu_mdla_config_top);
iounmap(mdla_reg_control[i].apu_mdla_cmde_mreg_top);
iounmap(mdla_reg_control[i].apu_mdla_biu_top);
}
kfree(mdla_reg_control);
return -1;
}
static void mdla_dts_unmap(struct platform_device *pdev)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
mdla_v1_x_irq_release(&pdev->dev);
iounmap(apu_conn_top);
iounmap(apu_mdla_gsm_top);
for (i = 0; i < nr_core_ids; i++) {
iounmap(mdla_reg_control[i].apu_mdla_config_top);
iounmap(mdla_reg_control[i].apu_mdla_cmde_mreg_top);
iounmap(mdla_reg_control[i].apu_mdla_biu_top);
}
kfree(mdla_reg_control);
}
static int mdla_sw_multi_devices_init(struct device *dev)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
mdla_plat_devices = devm_kzalloc(dev, nr_core_ids * sizeof(struct mdla_dev), GFP_KERNEL);
if (!mdla_plat_devices)
return -1;
mdla_set_device(mdla_plat_devices, nr_core_ids);
for (i = 0; i < nr_core_ids; i++) {
mdla_plat_devices[i].mdla_id = i;
mdla_plat_devices[i].dev = dev;
mdla_plat_devices[i].cmd_buf_dmp = NULL;
mdla_plat_devices[i].cmd_buf_len = 0;
INIT_LIST_HEAD(&mdla_plat_devices[i].cmd_list);
init_completion(&mdla_plat_devices[i].command_done);
spin_lock_init(&mdla_plat_devices[i].hw_lock);
lockdep_set_class(&mdla_plat_devices[i].hw_lock,
&hw_lock_key[i]);
mutex_init(&mdla_plat_devices[i].cmd_lock);
mutex_init(&mdla_plat_devices[i].cmd_list_lock);
mutex_init(&mdla_plat_devices[i].cmd_buf_dmp_lock);
mdla_v1_x_pmu_init(&mdla_plat_devices[i]);
}
return 0;
}
static void mdla_sw_multi_devices_deinit(void)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
mdla_set_device(NULL, 0);
for (i = 0; i < nr_core_ids; i++) {
mdla_v1_x_pmu_deinit(&mdla_plat_devices[i]);
/* TODO: Need to kill completion and wait it finished ? */
mutex_destroy(&mdla_plat_devices[i].cmd_lock);
mutex_destroy(&mdla_plat_devices[i].cmd_list_lock);
mutex_destroy(&mdla_plat_devices[i].cmd_buf_dmp_lock);
}
}
static void mdla_v1_x_reset(u32 core_id, const char *str)
{
unsigned long flags;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
struct mdla_dev *dev = mdla_get_device(core_id);
if (unlikely(!dev)) {
mdla_err("%s(): No mdla device (%d)\n", __func__, core_id);
return;
}
/* use power down==>power on apis insted bus protect init */
mdla_pwr_debug("%s: MDLA RESET: %s\n", __func__,
str);
spin_lock_irqsave(&dev->hw_lock, flags);
io->cfg.write(core_id, MDLA_CG_CLR, 0xffffffff);
io->cmde.write(core_id, MREG_TOP_G_INTP2, MDLA_IRQ_MASK & ~(MDLA_IRQ_SWCMD_DONE));
/* for DCM and CG */
io->cmde.write(core_id, MREG_TOP_ENG0, mdla_dbg_read_u32(FS_CFG_ENG0));
io->cmde.write(core_id, MREG_TOP_ENG1, mdla_dbg_read_u32(FS_CFG_ENG1));
io->cmde.write(core_id, MREG_TOP_ENG2, mdla_dbg_read_u32(FS_CFG_ENG2));
io->cmde.write(core_id, MREG_TOP_ENG11, mdla_dbg_read_u32(FS_CFG_ENG11));
if (mdla_plat_iommu_enable()) {
io->cfg.set_b(core_id, MDLA_AXI_CTRL, MDLA_AXI_CTRL_MASK);
io->cfg.set_b(core_id, MDLA_AXI1_CTRL, MDLA_AXI_CTRL_MASK);
}
spin_unlock_irqrestore(&dev->hw_lock, flags);
mdla_trace_reset(core_id, str);
}
/* platform public functions */
int mdla_v1_x_init(struct platform_device *pdev)
{
struct mdla_cmd_cb_func *cmd_cb = mdla_cmd_plat_cb();
struct mdla_dbg_cb_func *dbg_cb = mdla_dbg_plat_cb();
dev_info(&pdev->dev, "%s()\n", __func__);
if (mdla_sw_multi_devices_init(&pdev->dev))
return -1;
if (mdla_dts_map(pdev))
goto err;
if (mdla_plat_pwr_drv_ready()) {
if (mdla_pwr_device_register(pdev, mdla_pwr_on_v1_x, mdla_pwr_off_v1_x))
goto err_pwr;
}
mdla_pwr_reset_setup(mdla_v1_x_reset);
if (mdla_v1_x_sched_init())
goto err_sched;
/* set command strategy */
if (mdla_plat_sw_preemption_support())
mdla_cmd_setup(mdla_cmd_run_sync_v1_x_sched, NULL);
else
mdla_cmd_setup(mdla_cmd_run_sync_v1_x, NULL);
/* set command callback */
cmd_cb->pre_cmd_handle = mdla_plat_pre_cmd_handle;
cmd_cb->post_cmd_hw_detect = mdla_plat_zero_skip_detect;
cmd_cb->post_cmd_info = mdla_plat_print_post_cmd_info;
cmd_cb->wait_cmd_handle = mdla_plat_wait_cmd_handle;
cmd_cb->get_irq_num = mdla_v1_x_get_irq_num;
cmd_cb->get_wait_time = mdla_plat_get_wait_time;
cmd_cb->process_command = mdla_plat_process_command;
cmd_cb->check_cmd_valid = mdla_check_cmd_valid;
/* set debug callback */
dbg_cb->destroy_dump_cmdbuf = mdla_plat_destroy_dump_cmdbuf;
dbg_cb->create_dump_cmdbuf = mdla_plat_create_dump_cmdbuf;
dbg_cb->dump_reg = mdla_plat_dump_reg;
dbg_cb->memory_show = mdla_plat_memory_show;
dbg_cb->dbgfs_u64_enable = mdla_plat_dbgfs_u64_enable;
dbg_cb->dbgfs_u32_enable = mdla_plat_dbgfs_u32_enable;
dbg_cb->dbgfs_plat_init = mdla_plat_dbgfs_init;
/* set base address */
mdla_util_io_set_addr(mdla_reg_control);
mdla_util_io_set_extra_addr(EXTRA_ADDR_V1PX, apu_conn_top, NULL, NULL);
return 0;
err_sched:
if (mdla_plat_pwr_drv_ready())
mdla_pwr_device_unregister(pdev);
err_pwr:
dev_info(&pdev->dev, "register mdla power fail\n");
mdla_dts_unmap(pdev);
err:
mdla_sw_multi_devices_deinit();
return -1;
}
void mdla_v1_x_deinit(struct platform_device *pdev)
{
int i;
dev_info(&pdev->dev, "%s()\n", __func__);
mdla_v1_x_sched_deinit();
for_each_mdla_core(i) {
mdla_pwr_ops_get()->off(i, 0, true);
mdla_plat_destroy_dump_cmdbuf(&mdla_plat_devices[i]);
}
if (mdla_plat_pwr_drv_ready()
&& mdla_pwr_device_unregister(pdev))
dev_info(&pdev->dev, "unregister mdla power fail\n");
mdla_dts_unmap(pdev);
mdla_sw_multi_devices_deinit();
}
@@ -0,0 +1,85 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_HW_APU_DLA_V2_0_H__
#define __MDLA_HW_APU_DLA_V2_0_H__
/**
* apu_dla_0_config
* apu_dla_1_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_AXI_BIST_CTL (0x01C)
#define MDLA_AXI_BIST_STA (0x020)
#define MDLA_MBIST_DEFAULT_DELSEL (0x024)
#define MDLA_SRAM_DELSEL_CMDE (0x028)
#define MDLA_SRAM_DELSEL_CONV (0x02C)
#define MDLA_SRAM_DELSEL_CBLD (0x030)
#define MDLA_SRAM_DELSEL_CB_0 (0x034)
#define MDLA_SRAM_DELSEL_CB_1 (0x038)
#define MDLA_SRAM_DELSEL_STE (0x03C)
#define MDLA_SRAM_DELSEL_SB_0 (0x040)
#define MDLA_SRAM_DELSEL_SB_1 (0x044)
#define MDLA_SRAM_DELSEL_EWE_0 (0x048)
#define MDLA_SRAM_DELSEL_EWE_1 (0x04C)
#define MDLA_SRAM_DELSEL_EWE_2 (0x050)
#define MDLA_SRAM_DELSEL_WDEC (0x054)
#define MDLA_SRAM_DELSEL_RQU_0 (0x058)
#define MDLA_SRAM_DELSEL_RQU_1 (0x05C)
#define MDLA_RP_RST (0x060)
#define MDLA_RP_CON (0x064)
#define MDLA_RP_PRE_FUSE_0 (0x068)
#define MDLA_RP_PRE_FUSE_1 (0x06C)
#define MDLA_RP_PRE_FUSE_2 (0x070)
#define MDLA_RP_PRE_FUSE_3 (0x074)
#define MDLA_RP_PRE_FUSE_4 (0x078)
#define MDLA_RP_PRE_FUSE_5 (0x07C)
#define MDLA_SPARE_0 (0x080)
#define MDLA_SPARE_1 (0x084)
#define MDLA_SPARE_2 (0x088)
#define MDLA_SPARE_3 (0x08C)
#define MDLA_SPARE_4 (0x090)
#define MDLA_SPARE_5 (0x094)
#define MDLA_SPARE_6 (0x098)
#define MDLA_SPARE_7 (0x09C)
#define MDLA_CTRL (0x110)
#define MDLA_CSYSREQ (0x114)
#define MDLA_CSYSACK (0x118)
#define MDLA_AXI_CTRL (0x120)
#define MDLA_AXI1_CTRL (0x124)
#define MDLA_APB_CTRL (0x128)
#define MDLA_APB_STA (0x12C)
#define MDLA_GALS_M0_CTRL (0x130)
#define MDLA_GALS_M1_CTRL (0x134)
#define MDLA_GALS_STA (0x138)
#define MDLA_AXI_GALS_DBG (0x13C)
#define MDLA_SES_CTL0 (0x140)
#define MDLA_SES_CTL1 (0x144)
#define MDLA_SES_CTL2 (0x148)
/* Register fields */
/* MDLA_SW_RST : 0x00C */
#define MDLA_SW_RST_SETETING (0x3F)
#define MDLA_SW_MDLA_RST_MASK BIT(0)
#define MDLA_SW_APB_RST_MASK BIT(6)
#define MDLA_SW_RST_MASK (MDLA_SW_MDLA_RST_MASK|MDLA_SW_APB_RST_MASK)
/* MDLA_AXI_CTRL, MDLA_AXI1_CTRL : 0x120, 0x124 */
#define AWUSER_M1_ACP_EN BIT(0)
#define AWUSER_M1_MMU_EN BIT(1)
#define ARUSER_M1_ACP_EN BIT(9)
#define ARUSER_M1_MMU_EN BIT(10)
#define MDLA_AXI_CTRL_MASK (AWUSER_M1_MMU_EN | ARUSER_M1_MMU_EN)
#endif /* __MDLA_HW_APU_DLA_V2_0_H__ */
@@ -0,0 +1,43 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_HW_BIU_V2_0_H__
#define __MDLA_HW_BIU_V2_0_H__
/**
* mdla0_biu_v1p5
* mdla1_biu_v1p5
*/
#define CFG_PMCR (0x0E00)
#define PMU_CLK_CNT (0x0E04)
#define PMU_START_TSTAMP (0x0E08)
#define PMU_END_TSTAMP (0x0E0C)
#define PMU1 (0x0E10)
#define PMU1_CNT (0x0E14)
#define PMU1_CNT_LATCH (0x0E18)
/* id = 0 ~ 14 (PMU counter 1 ~ 15): 0xE10 ~ 0xEF8 */
#define PMU(id) (0x10 * (id) + PMU1)
#define PMU_CNT(id) (0x10 * (id) + PMU1_CNT)
#define PMU_CNT_LATCH(id) (0x10 * (id) + PMU1_CNT_LATCH)
#define PMU_CMDID_LATCH (0x0F00)
/* Register fields */
/* CFG_PMCR : 0xE00 */
#define PMU_CNT_EN(i) BIT(17 + (i))
#define PMU_CCNT_EN BIT(16)
#define PMU_PERCMD_MODE BIT(5)
#define PMU_EXPORT BIT(4)
#define PMU_CCNT_RESET BIT(2)
#define PMU_CNT_RESET BIT(1)
#define PMU_ENABLE BIT(0)
/* FIXME: mt6885(0x1F021), need to confirm mt8198 value */
#define CFG_PMCR_DEFAULT (PMU_ENABLE | PMU_CCNT_EN)
#endif /* __MDLA_HW_BIU_V2_0_H__ */
@@ -0,0 +1,91 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_HW_CMDE_V2_0_H__
#define __MDLA_HW_CMDE_V2_0_H__
#define MREG_TOP_G_DBG_CMDE01 (0x0004)
#define MREG_TOP_G_DBG_CMDE28 (0x0088)
#define MREG_TOP_G_DBG_CMDE29 (0x008c)
#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_G_DBG_STREAM0 (0x0548)
#define MREG_TOP_G_DBG_STREAM1 (0x054C)
#define MREG_TOP_ENG0 (0x0550)
#define MREG_TOP_ENG1 (0x0554)
#define MREG_TOP_ENG2 (0x0558)
#define MREG_TOP_ENG3 (0x055C)
#define MREG_TOP_ENG4 (0x0560)
#define MREG_TOP_ENG5 (0x0564)
#define MREG_TOP_ENG6 (0x0568)
#define MREG_TOP_ENG7 (0x056C)
#define MREG_TOP_ENG8 (0x0570)
#define MREG_TOP_ENG9 (0x0574)
#define MREG_TOP_ENG10 (0x0578)
#define MREG_TOP_ENG11 (0x057C)
#define MREG_TOP_ENG12 (0x0580)
#define MREG_TOP_G_FIN3 (0x0584)
#define MREG_TOP_G_COREINFO (0x0588)
#define MREG_TOP_G_FIN4 (0x058C)
#define MREG_TOP_G_MDLA_HWSYNC0 (0x0590)
#define MREG_TOP_G_MDLA_HWSYNC1 (0x0594)
#define MREG_TOP_G_MDLA_HWSYNC2 (0x0598)
#define MREG_TOP_G_MDLA_HWSYNC3 (0x059C)
#define MREG_TOP_ENG13 (0x05A0)
/* Register fields */
/* MREG_TOP_G_DBG_CMDE01 : 0x0004 */
#define LCE_HWCMD_RDCNT BIT(0)
#define LCE_INT_SWCMD_DONE BIT(1)
#define LCE_WAIT_INT_SWCMD_DONE BIT(2)
#define LCE_MDLA_EXT_SWCMD_DONE(i) BIT((i + 3))
#define LCE_MDLA_WAIT_EXT_SWCMD_DONE(i) BIT((i + 11))
#define LCE_WAIT_LAST_ACTI BIT(19)
#define LCE_WAIT_LAST_CFG BIT(20)
#define LCE_LAYER_END BIT(21)
/* MREG_TOP_G_DBG_CMDE28/29 : 0x0088, 0x008c */
#define INT_SWCMD_DONE_CNT GENMASK(3, 0)
#define MDLA0_SWCMD_DONE_CNT GENMASK(7, 4)
#define MDLA1_SWCMD_DONE_CNT GENMASK(11, 8)
/* MREG_TOP_G_DBG_CMDE29 : 0x008c */
#define MREG_TOP_G_DBG_CMDE29 (0x008c)
/* MREG_TOP_G_INTPx : 0x0500, 0x0504, 0x0508 */
#define INTR_SWCMD_TILECNT_INT BIT(1)
#define INTR_SWCMD_DONE BIT(2)
#define INTR_CDMA_EVT_FAIL BIT(4)
#define INTR_CDMA_FIFO_EMPTY BIT(5)
#define INTR_CDMA_FIFO_FULL BIT(6)
#define INTR_PMU_INT BIT(9)
#define INTR_CONV_GCU_SAT_EXCEPTION_INT BIT(10)
#define INRQ_CONV_AQU_ACC_SAT_EXCEPTION_INT BIT(11)
#define INRQ_CONV_AQU_ADD_SAT_EXCEPTION_INT BIT(12)
#define INTR_FIN4_CMD_STOP_INT BIT(21)
#define MDLA_IRQ_MASK (0x3FFFFFFF)
#define INTR_SUPPORT_MASK \
(INTR_SWCMD_DONE | INTR_FIN4_CMD_STOP_INT)
#endif /* __MDLA_HW_CMDE_V2_0_H__ */
@@ -0,0 +1,39 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef _MDLA_V2_0_HW_REG_H__
#define _MDLA_V2_0_HW_REG_H__
#include "mdla_hw_apu_dla_v2_0.h"
#include "mdla_hw_cmde_v2_0.h"
#include "mdla_hw_biu_v2_0.h"
#define MREG_CMD_SIZE (0x1C0)
/**
* MDLA_HAVE_reg_v1.xx
* code buffer size = 0x1c0
*/
#define MREG_CMD_INPUT_ACTI_ADDR (0x0)
#define MREG_CMD_INPUT_WT_ACTI_ADDR (0x4)
#define MREG_CMD_OUTPUT_ACTI_ADDR (0x8)
#define MREG_CMD_GENERAL_CTRL_0 (0x70)
#define MREG_CMD_TILE_CNT_INT (0x154)
#define MREG_CMD_GENERAL_CTRL_1 (0x15C)
/* Register fields */
/* MREG_CMD_GENERAL_CTRL_0 : 0x70 */
#define MREG_CMD_LAYER_END BIT(12)
#define MREG_CMD_AXI_MAX_BURST_LEN BIT(25)
/* MREG_CMD_GENERAL_CTRL_1 : 0x15C */
#define MREG_CMD_INT_SWCMD_DONE BIT(15)
#define MREG_CMD_WAIT_SWCMD_DONE BIT(16)
/* MREG_CMD_TILE_CNT_INT : 0x154 */
#define MREG_CMD_SWCMD_FINISH_INT_EN BIT(24)
#endif /* _MDLA_V2_0_HW_REG_H__ */
@@ -0,0 +1,487 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_irq.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/sched/clock.h>
#include <common/mdla_driver.h>
#include <common/mdla_device.h>
#include <common/mdla_scheduler.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_profile.h>
#include <interface/mdla_cmd_data_v2_0.h>
#include <platform/mdla_plat_api.h>
#include "mdla_hw_reg_v2_0.h"
#include "mdla_sched_v2_0.h"
struct mdla_irq {
u32 irq;
struct mdla_dev *dev;
};
static int handle_num;
static struct mdla_irq *mdla_irq_desc;
/* platform static function */
static void mdla_backup_cmd(struct mdla_dev *mdla_device, struct command_entry *ce, u32 fin3)
{
u32 core_id = mdla_device->mdla_id;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
unsigned long flags;
spin_lock_irqsave(&mdla_device->hw_lock, flags);
ce->hw_sync1 = io->cmde.read(core_id, MREG_TOP_G_MDLA_HWSYNC1);
ce->hw_sync2 = io->cmde.read(core_id, MREG_TOP_G_MDLA_HWSYNC2);
ce->hw_sync3 = io->cmde.read(core_id, MREG_TOP_G_MDLA_HWSYNC3);
spin_unlock_irqrestore(&mdla_device->hw_lock, flags);
ce->fin_cid = fin3;
mdla_verbose("%s: core %x, hw_sync1: %.8x, hw_sync2: %.8x, hw_sync3: %.8x\n",
__func__, core_id, ce->hw_sync1, ce->hw_sync2, ce->hw_sync3);
}
static void mdla_sw_cmd_stop(struct mdla_dev *mdla_device, u32 fin3)
{
u32 core_id = mdla_device->mdla_id;
struct mdla_scheduler *sched = mdla_device->sched;
struct command_entry *ce = sched->pro_ce;
struct command_entry *new_ce;
unsigned long flags;
ce_func_trace(ce, F_INIRQ_STOP);
mdla_prof_set_ts(core_id, TS_CMD_STOPPED,
mdla_prof_get_ts(core_id, TS_HW_INTR));
ce->exec_time += mdla_prof_get_ts(core_id, TS_CMD_STOPPED)
- mdla_prof_get_ts(core_id, TS_HW_TRIGGER);
spin_lock_irqsave(&mdla_device->stat_lock, flags);
mdla_device->status = MDLA_STOP;
spin_unlock_irqrestore(&mdla_device->stat_lock, flags);
mdla_backup_cmd(mdla_device, ce, fin3);
sched->enqueue_ce(core_id, ce, 1);
new_ce = sched->dequeue_ce(core_id);
if (ce->csn != new_ce->csn) {
ce->state |= (1 << CE_PREEMPTED);
new_ce->state |= (1 << CE_PREEMPTING);
sched->pro_ce = new_ce;
}
//FIXME: unsafe reset flow
/* MDLA sw reset */
sched->sw_reset(core_id);
mdla_pwr_ops_get()->hw_reset(core_id,
mdla_dbg_get_reason_str(REASON_PREEMPTED));
/* Fire new cmd */
if (sched->pro_ce)
sched->issue_ce(core_id);
mdla_dbg_add_u32(FS_PREEMPTION_TIMES, 1);
}
static int mdla_sw_cmd_done(struct mdla_dev *mdla_device, u32 fin3)
{
u32 core_id = mdla_device->mdla_id;
struct mdla_scheduler *sched = mdla_device->sched;
struct command_entry *ce = sched->pro_ce;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
struct mdla_pmu_info *pmu;
struct command_entry *new_ce;
unsigned long flags;
ce->fin_cid = fin3;
if (ce->fin_cid < ce->count) {
ce_func_trace(ce, F_CMDDONE_CE_FIN3ERROR);
return -1;
}
ce_func_trace(ce, F_CMDDONE_CE_PASS);
mdla_prof_set_ts(core_id, TS_HW_LAST_INTR,
mdla_prof_get_ts(core_id, TS_HW_INTR));
ce->exec_time += mdla_prof_get_ts(core_id, TS_HW_LAST_INTR)
- mdla_prof_get_ts(core_id, TS_HW_TRIGGER);
sched->complete_ce(core_id);
sched->pro_ce = NULL;
/* out pmu data */
pmu = mdla_util_pmu_ops_get()->get_info(core_id, 0);
if (pmu)
mdla_util_pmu_ops_get()->reg_counter_save(core_id, pmu);
/* Clear STREAM0, FIN4 */
spin_lock_irqsave(&mdla_device->hw_lock, flags);
io->cmde.write(core_id, MREG_TOP_G_STREAM0, 0);
io->cmde.write(core_id, MREG_TOP_G_FIN4, 0);
spin_unlock_irqrestore(&mdla_device->hw_lock, flags);
new_ce = sched->dequeue_ce(core_id);
if (new_ce != NULL) {
sched->pro_ce = new_ce;
ce_func_trace(new_ce, F_CMDDONE_GO_TO_ISSUE);
sched->issue_ce(core_id);
} else {
spin_lock_irqsave(&mdla_device->stat_lock, flags);
mdla_device->status = MDLA_FREE;
spin_unlock_irqrestore(&mdla_device->stat_lock, flags);
}
return 0;
}
/* IRQ handler for hardware preemption */
static void mdla_irq_hw_sched(struct mdla_dev *mdla_device)
{
struct mdla_scheduler *sched = mdla_device->sched;
unsigned long flags, flags1;
u32 core_id, event_id = 0, irq_status = 0, fin3;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
core_id = mdla_device->mdla_id;
if (unlikely(sched == NULL)) {
mdla_device->error_bit |= IRQ_NO_SCHEDULER;
return;
}
spin_lock_irqsave(&sched->lock, flags1);
spin_lock_irqsave(&mdla_device->hw_lock, flags);
irq_status = io->cmde.read(core_id, MREG_TOP_G_INTP0);
if ((irq_status & INTR_SUPPORT_MASK) == 0) {
/* ignore unexpected interrupt */
spin_unlock_irqrestore(&mdla_device->hw_lock, flags);
ce_func_trace(sched->pro_ce, F_INIRQ_ERROR);
spin_unlock_irqrestore(&sched->lock, flags1);
mdla_cmd_debug("%s:Rcv unexpected IRQ: core %x, irq_status: %x\n",
__func__, core_id, irq_status);
return;
}
if (unlikely((irq_status & INTR_CONV_GCU_SAT_EXCEPTION_INT) ||
(irq_status & INRQ_CONV_AQU_ACC_SAT_EXCEPTION_INT) ||
(irq_status & INRQ_CONV_AQU_ADD_SAT_EXCEPTION_INT))) {
mdla_cmd_debug("%s:exception IRQ: core %x, irq_status: %x\n",
__func__, core_id, irq_status);
}
event_id = io->cmde.read(core_id, MREG_TOP_G_STREAM0);
fin3 = io->cmde.read(core_id, MREG_TOP_G_FIN3);
/* clear intp0 to avoid irq fire twice */
io->cmde.write(core_id, MREG_TOP_G_INTP0, INTR_SUPPORT_MASK);
spin_unlock_irqrestore(&mdla_device->hw_lock, flags);
if (unlikely(sched->pro_ce == NULL)) {
mdla_device->error_bit |= IRQ_NO_PROCESSING_CE;
goto unlock;
}
if (unlikely(sched->pro_ce->state & (1 << CE_FAIL))) {
mdla_device->error_bit |= IRQ_TIMEOUT;
ce_func_trace(sched->pro_ce, F_TIMEOUT | 1);
goto unlock;
}
if (unlikely(time_after64(get_jiffies_64(),
sched->pro_ce->deadline_t))) {
sched->pro_ce->state |= (1 << CE_TIMEOUT);
ce_func_trace(sched->pro_ce, F_TIMEOUT);
goto unlock;
}
if (unlikely(event_id != sched->pro_ce->csn)) {
sched->pro_ce->irq_state |= IRQ_RECORD_ERROR;
ce_func_trace(sched->pro_ce, F_INIRQ_CDMA4ERROR);
goto unlock;
}
sched->pro_ce->state |= (1 << CE_SCHED);
if (irq_status & INTR_SWCMD_DONE) {
mdla_sw_cmd_done(mdla_device, fin3);
goto unlock;
} else if (irq_status & INTR_FIN4_CMD_STOP_INT) {
mdla_sw_cmd_stop(mdla_device, fin3);
}
unlock:
spin_unlock_irqrestore(&sched->lock, flags1);
}
/* IRQ handler for SW pre-emption */
/*
* Return smp_cmd_id
* smp_cmd_id = 0 => single cmd, issue directly
* smp_cmd_id != 0 => SMP cmd, return and issue SMP later
*/
static uint64_t mdla_sw_issue_next(struct mdla_dev *mdla_device)
{
struct mdla_scheduler *sched = mdla_device->sched;
u32 core_id = mdla_device->mdla_id;
struct command_entry *new_ce;
uint64_t smp_cmd_id = 0;
/* get the next CE to be processed */
new_ce = sched->dequeue_ce(core_id);
if (new_ce) {
if (sched->pro_ce) {
sched->preempt_ce(core_id, new_ce);
sched->issue_ce(core_id);
} else if ((new_ce->multicore_total > 1)
&& (new_ce->priority == MDLA_LOW_PRIORITY)) {
sched->enqueue_ce(core_id, new_ce, 1);
smp_cmd_id = new_ce->cmd_id;
} else {
sched->pro_ce = new_ce;
sched->issue_ce(core_id);
}
} else if (sched->pro_ce) {
sched->issue_ce(core_id);
}
return smp_cmd_id;
}
static void mdla_irq_sw_sched(struct mdla_dev *mdla_device)
{
struct mdla_scheduler *sched = mdla_device->sched;
unsigned long flags;
u32 status, core_id, cdma4 = 0, irq_status = 0;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
u64 smp_cmd_id = 0;
u64 ts;
ts = sched_clock();
core_id = mdla_device->mdla_id;
/* clear intp0 to avoid irq fire twice */
spin_lock_irqsave(&mdla_device->hw_lock, flags);
irq_status = io->cmde.read(core_id, MREG_TOP_G_INTP0);
io->cmde.write(core_id, MREG_TOP_G_INTP0, INTR_SWCMD_DONE);
cdma4 = io->cmde.read(core_id, MREG_TOP_G_CDMA4);
spin_unlock_irqrestore(&mdla_device->hw_lock, flags);
if (unlikely(sched == NULL)) {
mdla_device->error_bit |= IRQ_NO_SCHEDULER;
return;
}
spin_lock_irqsave(&sched->lock, flags);
if (unlikely(sched->pro_ce == NULL)) {
mdla_device->error_bit |= IRQ_NO_PROCESSING_CE;
goto unlock;
}
if (unlikely(sched->pro_ce->state & (1 << CE_FAIL))) {
mdla_device->error_bit |= IRQ_TIMEOUT;
ce_func_trace(sched->pro_ce, F_TIMEOUT | 1);
goto unlock;
}
if (unlikely(time_after64(get_jiffies_64(),
sched->pro_ce->deadline_t))) {
sched->pro_ce->state |= (1 << CE_TIMEOUT);
ce_func_trace(sched->pro_ce, F_TIMEOUT);
goto unlock;
}
if (unlikely((irq_status & INTR_SWCMD_DONE) == 0)) {
ce_func_trace(sched->pro_ce, F_INIRQ_ERROR);
mdla_verbose("core %x: irq_status: %x\n", core_id, irq_status);
goto unlock;
}
if (unlikely((irq_status & INTR_CONV_GCU_SAT_EXCEPTION_INT) ||
(irq_status & INRQ_CONV_AQU_ACC_SAT_EXCEPTION_INT) ||
(irq_status & INRQ_CONV_AQU_ADD_SAT_EXCEPTION_INT))) {
pr_info("unexpected IRQ status: core %x, irq_status: %x\n",
core_id, irq_status);
}
if (unlikely(cdma4 != sched->pro_ce->csn)) {
sched->pro_ce->irq_state |= IRQ_RECORD_ERROR;
ce_func_trace(sched->pro_ce, F_INIRQ_CDMA4ERROR);
goto unlock;
}
sched->pro_ce->state |= (1 << CE_SCHED);
sched->pro_ce->exec_time += mdla_prof_get_ts(core_id, TS_HW_INTR)
- mdla_prof_get_ts(core_id, TS_HW_TRIGGER);
/* process the current CE */
status = sched->process_ce(core_id);
if (status == CE_DONE) {
mdla_prof_set_ts(core_id, TS_HW_LAST_INTR,
mdla_prof_get_ts(core_id, TS_HW_INTR));
sched->complete_ce(core_id);
} else if (status == CE_NONE) {
/* nothing to do but wait for the engine completed */
goto unlock;
}
/* get the next CE to be processed */
smp_cmd_id = mdla_sw_issue_next(mdla_device);
unlock:
spin_unlock_irqrestore(&sched->lock, flags);
if (smp_cmd_id)
sched->issue_dual_lowce(core_id, smp_cmd_id);
}
/* IRQ handler w/o preemption */
static void mdla_irq_intr(struct mdla_dev *mdla_device)
{
u32 core_id, id;
u32 irq_status;
unsigned long flags;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
struct mdla_pmu_info *pmu;
core_id = mdla_device->mdla_id;
spin_lock_irqsave(&mdla_device->hw_lock, flags);
irq_status = io->cmde.read(core_id, MREG_TOP_G_INTP0);
io->cmde.write(core_id, MREG_TOP_G_INTP0, INTR_SUPPORT_MASK);
/* Toggle for Latch Fin1 Tile ID */
io->cmde.read(core_id, MREG_TOP_G_FIN0);
id = io->cmde.read(core_id, MREG_TOP_G_FIN3);
pmu = mdla_util_pmu_ops_get()->get_info(core_id, 0);
if (pmu)
mdla_util_pmu_ops_get()->reg_counter_save(core_id, pmu);
mdla_device->max_cmd_id = id;
if (irq_status & INTR_PMU_INT)
io->cmde.write(core_id, MREG_TOP_G_INTP0, INTR_PMU_INT);
spin_unlock_irqrestore(&mdla_device->hw_lock, flags);
mdla_prof_set_ts(core_id, TS_HW_LAST_INTR,
mdla_prof_get_ts(core_id, TS_HW_INTR));
complete(&mdla_device->command_done);
}
static irqreturn_t mdla_irq_handler(int irq, void *dev_id)
{
struct mdla_dev *mdla_device = (struct mdla_dev *)dev_id;
if (unlikely(!mdla_device))
return IRQ_HANDLED;
mdla_prof_set_ts(mdla_device->mdla_id, TS_HW_INTR, sched_clock());
if (mdla_plat_hw_preemption_support())
mdla_irq_hw_sched(mdla_device);
else if (mdla_plat_sw_preemption_support())
mdla_irq_sw_sched(mdla_device);
else
mdla_irq_intr(mdla_device);
return IRQ_HANDLED;
}
/* platform public function */
int mdla_v2_0_get_irq_num(u32 core_id)
{
int i;
for (i = 0; i < handle_num; i++) {
if (mdla_irq_desc[i].dev == mdla_get_device(core_id))
return mdla_irq_desc[i].irq;
}
return 0;
}
int mdla_v2_0_irq_request(struct device *dev, int irqdesc_num)
{
int i;
struct mdla_irq *irq_desc;
struct device_node *node = dev->of_node;
if (!node) {
dev_info(dev, "get mdla device node err\n");
return -1;
}
mdla_irq_desc = kcalloc(irqdesc_num, sizeof(struct mdla_irq), GFP_KERNEL);
if (!mdla_irq_desc)
return -1;
handle_num = irqdesc_num;
for (i = 0; i < irqdesc_num; i++) {
irq_desc = &mdla_irq_desc[i];
irq_desc->dev = mdla_get_device(i);
irq_desc->irq = irq_of_parse_and_map(node, i);
if (!irq_desc->irq) {
dev_info(dev, "get mdla irq: %d failed\n", i);
goto err;
}
if (request_irq(irq_desc->irq, mdla_irq_handler,
irq_get_trigger_type(irq_desc->irq),
DRIVER_NAME, irq_desc->dev)) {
dev_info(dev, "mtk_mdla[%d]: Could not allocate interrupt %d.\n",
i, irq_desc->irq);
}
dev_info(dev, "request_irq %d done\n", irq_desc->irq);
}
return 0;
err:
kfree(mdla_irq_desc);
return -1;
}
void mdla_v2_0_irq_release(struct device *dev)
{
int i;
for (i = 0; i < handle_num; i++)
free_irq(mdla_irq_desc[i].irq, mdla_irq_desc[i].dev);
kfree(mdla_irq_desc);
}
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_V2_0_IRQ_H__
#define __MDLA_V2_0_IRQ_H__
#include <linux/types.h>
#include <linux/device.h>
int mdla_v2_0_get_irq_num(u32 core_id);
int mdla_v2_0_irq_request(struct device *dev, int irqdesc_num);
int mdla_v2_0_irq_release(struct device *dev);
#endif /* __MDLA_V2_0_IRQ_H__ */
@@ -0,0 +1,739 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
#include <apusys_device.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_profile.h>
#include <common/mdla_power_ctrl.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_ioctl.h>
#include <platform/mdla_plat_api.h>
#include "mdla_pmu_v2_0.h"
#include "mdla_hw_reg_v2_0.h"
#include <interface/mdla_cmd_data_v2_0.h>
#define biu_read(id, ofs) \
mdla_util_io_ops_get()->biu.read(id, ofs)
#define biu_write(id, ofs, val) \
mdla_util_io_ops_get()->biu.write(id, ofs, val)
#define biu_set_b(id, ofs, val) \
mdla_util_io_ops_get()->biu.set_b(id, ofs, val)
#define biu_clr_b(id, ofs, val) \
mdla_util_io_ops_get()->biu.clr_b(id, ofs, val)
struct mdla_pmu_dev {
spinlock_t lock;
DECLARE_BITMAP(pmu_bitmap, MDLA_PMU_COUNTERS);
u32 cfg_event[MDLA_PMU_COUNTERS];
};
struct mdla_pmu_data {
u8 cfg_percmd_mode;
u16 l_cmd_cnt;
u16 l_cmd_id;
u32 l_start_t;
u32 l_end_t;
u32 l_cycle;
u32 l_counters[MDLA_PMU_COUNTERS];
u32 event_handle[MDLA_PMU_COUNTERS];
};
/* pmu info handle (sync with NN)*/
struct mdla_pmu_hnd {
u32 graph_id;//need confirm apusys mid data type
u32 offset_to_PMU_res_buf0;//base addr: pmu_kva
u32 offset_to_PMU_res_buf1;
u8 mode;
u8 number_of_event;
u16 event[MDLA_PMU_COUNTERS];
};
struct mdla_pmu_info {
u64 cmd_id;
u64 PMU_res_buf_addr;
struct mdla_pmu_hnd *pmu_hnd;
struct mdla_pmu_data data;
u32 number_of_event;
u8 pmu_mode;
};
static u32 mdla_pmu_get_perf_end(struct mdla_pmu_info *pmu)
{
return pmu->data.l_end_t;
}
static u32 mdla_pmu_get_perf_cycle(struct mdla_pmu_info *pmu)
{
return pmu->data.l_cycle;
}
static u16 mdla_pmu_get_perf_cmdid(struct mdla_pmu_info *pmu)
{
return pmu->data.l_cmd_id;
}
static u16 mdla_pmu_get_perf_cmdcnt(struct mdla_pmu_info *pmu)
{
return pmu->data.l_cmd_cnt;
}
static u32 mdla_pmu_get_counter(struct mdla_pmu_info *pmu, u32 idx)
{
return pmu->data.l_counters[idx];
}
static int mdla_pmu_get_mode(struct mdla_pmu_info *pmu)
{
return (int)pmu->pmu_mode;
}
static u32 mdla_pmu_get_hnd_evt(struct mdla_pmu_info *pmu, u32 counter_idx)
{
return pmu->pmu_hnd->event[counter_idx];
}
static u32 mdla_pmu_get_hnd_evt_num(struct mdla_pmu_info *pmu)
{
return pmu->pmu_hnd->number_of_event;
}
static u32 mdla_pmu_get_hnd_mode(struct mdla_pmu_info *pmu)
{
return pmu->pmu_hnd->mode;
}
static u64 mdla_pmu_get_hnd_buf_addr(struct mdla_pmu_info *pmu)
{
return pmu->PMU_res_buf_addr;
}
static void mdla_pmu_set_evt_handle(struct mdla_pmu_info *pmu,
u32 counter_idx, u32 val)
{
pmu->data.event_handle[counter_idx] = val;
}
static struct mdla_pmu_info *mdla_pmu_get_info(u32 core_id, u16 priority)
{
return &mdla_get_device(core_id)->pmu_info[priority];
}
static bool mdla_pmu_apusys_valid(struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd, u16 priority)
{
struct mdla_pmu_info *pmu;
struct mdla_run_cmd_sync *cmd_data;
struct mdla_run_cmd *cd;
uint32_t count;
uint64_t out_size = 0;
uint64_t out_end = 0;
uint32_t out_length = 0;
uint32_t repeat_sz = 0;
uint32_t evt_num = 0;
uint32_t sz = 0;
cmd_data = (struct mdla_run_cmd_sync *)apusys_hd->kva;
cd = &cmd_data->req;
count = cd->count;
pmu = &mdla_info->pmu_info[priority];
evt_num = mdla_pmu_get_hnd_evt_num(pmu);
if (evt_num > MDLA_PMU_COUNTERS)
return false;
out_end = apusys_hd->cmd_entry + apusys_hd->cmd_size;
if (apusys_hd->cmd_entry > pmu->PMU_res_buf_addr)
return false;
if (out_end < pmu->PMU_res_buf_addr)
return false;
out_size = out_end - pmu->PMU_res_buf_addr;
if (pmu->pmu_mode == PER_CMD) {
if (out_size < sizeof(u16))
return false;
repeat_sz = sizeof(u16) + sizeof(u32) * (evt_num + 1);
out_length = (out_size - sizeof(u16)) / repeat_sz;
if (out_length < count)
return false;
} else if (pmu->pmu_mode == NORMAL) {
sz = sizeof(u16) * 2 + sizeof(u32) * (evt_num + 1);
if (out_size < sz)
return false;
}
return true;
}
/* extract pmu_hnd form pmu_kva and set mdla_info->pmu */
static int mdla_pmu_cmd_prepare(struct mdla_dev *mdla_info,
struct apusys_cmd_hnd *apusys_hd, u16 priority)
{
u64 ofs_buf_addr;
struct mdla_pmu_info *pmu;
pmu = &mdla_info->pmu_info[priority];
if (pmu->pmu_mode >= CMD_MODE_MAX)
return -1;
pmu->pmu_hnd =
(struct mdla_pmu_hnd *)apusys_hd->pmu_kva;
pmu->cmd_id = apusys_hd->cmd_id;
if (mdla_info->mdla_id == 0)
ofs_buf_addr = pmu->pmu_hnd->offset_to_PMU_res_buf0;
else if (mdla_info->mdla_id == 1)
ofs_buf_addr = pmu->pmu_hnd->offset_to_PMU_res_buf1;
else
return -1;
pmu->PMU_res_buf_addr = apusys_hd->cmd_entry + ofs_buf_addr;
if (pmu->pmu_mode == PER_CMD)
mdla_util_pmu_cmd_timer(true);
mdla_pmu_debug("pmu addr: %08llx\n", pmu->PMU_res_buf_addr);
return 0;
}
static int mdla_pmu_event_write(u32 core_id, u32 handle, u32 val)
{
if (val == COUNTER_CLEAR) {
mdla_pmu_debug("%s: clear pmu counter[%d]\n",
__func__, handle);
biu_write(core_id, PMU(handle), 0);
biu_clr_b(core_id, CFG_PMCR, PMU_CNT_EN(handle));
} else {
mdla_pmu_debug("%s: set pmu counter[%d] = 0x%x\n",
__func__, handle, val);
biu_write(core_id, PMU(handle), val);
biu_set_b(core_id, CFG_PMCR, PMU_CNT_EN(handle));
}
return 0;
}
static void mdla_pmu_event_write_all(u32 core_id, u16 priority)
{
int i, cnt;
u32 val;
struct mdla_pmu_info *pmu;
pmu = &(mdla_get_device(core_id)->pmu_info[priority]);
cnt = mdla_prof_use_dbgfs_pmu_event(core_id)
? MDLA_PMU_COUNTERS : pmu->number_of_event;
for (i = 0; i < cnt; i++) {
val = i < MDLA_PMU_COUNTERS ?
pmu->data.event_handle[i] : COUNTER_CLEAR;
mdla_pmu_event_write(core_id, i, val);
}
}
static u32 mdla_pmu_get_num_evt(u32 core_id, u16 priority)
{
if (mdla_prof_use_dbgfs_pmu_event(core_id))
return MDLA_PMU_COUNTERS;
if (priority >= PRIORITY_LEVEL)
return 0;
return mdla_get_device(core_id)->pmu_info[priority].number_of_event;
}
static void mdla_pmu_set_num_evt(u32 core_id, u16 prio, u32 val)
{
if (prio < PRIORITY_LEVEL)
mdla_get_device(core_id)->pmu_info[prio].number_of_event = val;
}
#define pmu_is_percmd_mode(i)\
(biu_read(i, CFG_PMCR) & PMU_PERCMD_MODE)
/* for mdla_trace and apusys_hnd */
static void mdla_pmu_counter_read_all(u32 core_id, u32 out[MDLA_PMU_COUNTERS])
{
int i;
if (pmu_is_percmd_mode(core_id)) {
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
out[i] += biu_read(core_id, PMU_CNT_LATCH(i));
} else {
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
out[i] += biu_read(core_id, PMU_CNT(i));
}
}
static void mdla_pmu_counter_disable_all(u32 core_id)
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
biu_clr_b(core_id, CFG_PMCR, PMU_CNT_EN(i));
}
static void mdla_pmu_counter_enable_all(u32 core_id)
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++) {
if (biu_read(core_id, PMU(i)))
biu_set_b(core_id, CFG_PMCR, PMU_CNT_EN(i));
}
}
/* save pmu registers for query after power off */
static void mdla_pmu_counter_save(u32 core_id, struct mdla_pmu_info *pmu)
{
if (pmu->pmu_mode == NORMAL) {
pmu->data.l_cmd_cnt = 1;
pmu->data.l_cmd_id = 0;
} else {
u32 val = biu_read(core_id, PMU_CMDID_LATCH);
if (val != pmu->data.l_cmd_id) {
pmu->data.l_cmd_cnt++;
pmu->data.l_cmd_id = (u16)val;
}
}
pmu->data.l_cycle +=
biu_read(core_id, PMU_CLK_CNT);
pmu->data.l_end_t +=
biu_read(core_id, PMU_END_TSTAMP);
pmu->data.l_start_t =
biu_read(core_id, PMU_START_TSTAMP);
mdla_pmu_counter_read_all(core_id, pmu->data.l_counters);
}
/* it save mode setting to local variable */
static void mdla_pmu_percmd_mode_set(struct mdla_pmu_info *pmu, u32 mode)
{
pmu->data.cfg_percmd_mode = mode;
}
/* for ioctrl */
static void mdla_pmu_percmd_mode_write(u32 core_id, struct mdla_pmu_info *pmu)
{
if (pmu->data.cfg_percmd_mode)
biu_set_b(core_id, CFG_PMCR, PMU_PERCMD_MODE);
else
biu_clr_b(core_id, CFG_PMCR, PMU_PERCMD_MODE);
}
/* for ioctrl */
static int mdla_pmu_counter_event_set(u32 core_id, int handle, u32 val)
{
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
if (handle < MDLA_PMU_COUNTERS)
pmu_dev->cfg_event[handle] = val;
mdla_pmu_event_write(core_id, handle, val);
return 0;
}
/* for ioctrl */
static int mdla_pmu_counter_event_get(u32 core_id, int handle)
{
u32 event;
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
event = pmu_dev->cfg_event[handle];
return (event == COUNTER_CLEAR) ? -ENOENT : event;
}
static void mdla_pmu_reset_and_write_event(u32 core_id, u16 priority)
{
biu_set_b(core_id,
CFG_PMCR,
(CFG_PMCR_DEFAULT | PMU_CNT_RESET
| PMU_CCNT_EN | PMU_CCNT_RESET));
while ((biu_read(core_id, CFG_PMCR) &
(PMU_CNT_RESET | PMU_CCNT_RESET)) != 0) {
}
mdla_pmu_percmd_mode_write(core_id,
&(mdla_get_device(core_id)->pmu_info[priority]));
mdla_pmu_event_write_all(core_id, priority);
}
static void mdla_pmu_reset_counter_variable(struct mdla_pmu_info *pmu)
{
int i;
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
pmu->data.l_counters[i] = 0;
pmu->data.l_cmd_id = 0;
pmu->data.l_cmd_cnt = 0;
}
static void mdla_pmu_reset_cycle_variable(struct mdla_pmu_info *pmu)
{
pmu->data.l_cycle = 0;
pmu->data.l_end_t = 0;
pmu->data.l_start_t = 0;
}
static void mdla_pmu_reset_counter_no_lock(u32 core_id)
{
mdla_pmu_debug("mdla: %s\n", __func__);
/*Reset Clock counter to zero. Return to zero when reset done.*/
biu_set_b(core_id, CFG_PMCR, PMU_CNT_RESET);
while ((biu_read(core_id, CFG_PMCR) & PMU_CNT_RESET)
!= 0) {
}
}
static void mdla_pmu_reset_counter(u32 core_id)
{
unsigned long flags;
struct mdla_pmu_dev *pmu_dev;
pmu_dev = mdla_get_device(core_id)->pmu_dev;
spin_lock_irqsave(&pmu_dev->lock, flags);
mdla_pmu_reset_counter_no_lock(core_id);
spin_unlock_irqrestore(&pmu_dev->lock, flags);
}
static void mdla_pmu_reset_cycle(u32 core_id)
{
mdla_pmu_debug("mdla: %s\n", __func__);
biu_set_b(core_id,
CFG_PMCR,
(PMU_CCNT_EN | PMU_CCNT_RESET));
while ((biu_read(core_id, CFG_PMCR) & PMU_CCNT_RESET)
!= 0) {
}
}
static void mdla_pmu_reset(u32 core_id)
{
int i;
biu_write(core_id, CFG_PMCR,
(CFG_PMCR_DEFAULT | PMU_CCNT_RESET | PMU_CNT_RESET));
while ((biu_read(core_id, CFG_PMCR) &
(PMU_CCNT_RESET | PMU_CNT_RESET)) != 0) {
}
/* reset to 0 */
for (i = 0; i < MDLA_PMU_COUNTERS; i++)
mdla_pmu_event_write(core_id, i, COUNTER_CLEAR);
/* FIXME: PMCR default is normal */
//biu_clr_b(core_id, CFG_PMCR, PMU_PERCMD_MODE);
mdla_pmu_debug("mdla: %s, CFG_PMCR: 0x%x\n",
__func__, biu_read(core_id, CFG_PMCR));
}
/* for ioctrl */
static int mdla_pmu_counter_alloc(u32 core_id)
{
unsigned long flags;
int handle;
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if (unlikely(!pmu_dev))
return -ENODEV;
spin_lock_irqsave(&pmu_dev->lock, flags);
handle = bitmap_find_free_region(pmu_dev->pmu_bitmap,
MDLA_PMU_COUNTERS, 0);
spin_unlock_irqrestore(&pmu_dev->lock, flags);
if (unlikely(handle < 0))
return -EINVAL;
return handle;
}
/* for ioctrl */
static int mdla_pmu_counter_free(u32 core_id, int handle)
{
unsigned long flags;
int ret = 0;
struct mdla_pmu_dev *pmu_dev = mdla_get_device(core_id)->pmu_dev;
if ((handle >= MDLA_PMU_COUNTERS) || (handle < 0))
return -EINVAL;
spin_lock_irqsave(&pmu_dev->lock, flags);
bitmap_release_region(pmu_dev->pmu_bitmap, handle, 0);
mdla_pmu_event_write(core_id, handle, COUNTER_CLEAR);
spin_unlock_irqrestore(&pmu_dev->lock, flags);
return ret;
}
static int mdla_pmu_ioctl(struct file *filp,
u32 command, unsigned long arg, bool need_pwr_on)
{
long retval = 0;
struct mdla_dev *mdla_device;
struct mdla_pmu_info *pmu_info;
struct ioctl_perf perf_data;
u32 core_id;
int cnt_idx = 0;
int i;
if (copy_from_user(&perf_data, (void *) arg, sizeof(perf_data)))
return -EFAULT;
core_id = perf_data.mdlaid;
if (core_id_is_invalid(core_id))
return -EINVAL;
mdla_device = mdla_get_device(core_id);
/* set priority level = 1 for ioctl */
pmu_info = &mdla_device->pmu_info[0];
if (need_pwr_on) {
mdla_pwr_ops_get()->lock(core_id);
if (mdla_device->power_is_on == false) {
mdla_err("mdla%d power off, pmu ioctl FAIL\n", core_id);
goto out;
}
}
switch (command) {
case IOCTL_PERF_SET_EVENT:
perf_data.handle = mdla_pmu_counter_alloc(core_id);
if (perf_data.handle >= 0)
mdla_pmu_counter_event_set(core_id,
perf_data.handle,
(perf_data.interface << 16) | perf_data.event);
break;
case IOCTL_PERF_UNSET_EVENT:
mdla_pmu_counter_free(core_id, perf_data.handle);
break;
case IOCTL_PERF_GET_EVENT:
perf_data.event = mdla_pmu_counter_event_get(
core_id, perf_data.handle);
break;
case IOCTL_PERF_GET_CNT:
cnt_idx = perf_data.handle;
if (cnt_idx < MDLA_PMU_COUNTERS && cnt_idx >= 0)
perf_data.counter = pmu_info->data.l_counters[cnt_idx];
break;
case IOCTL_PERF_GET_START:
perf_data.start = pmu_info->data.l_start_t;
break;
case IOCTL_PERF_GET_END:
perf_data.end = pmu_info->data.l_end_t;
break;
case IOCTL_PERF_GET_CYCLE:
perf_data.start = pmu_info->data.l_cycle;
break;
case IOCTL_PERF_RESET_CNT:
mdla_cmd_ops_get()->lock(mdla_device);
for (i = 0; i < PRIORITY_LEVEL; i++)
mdla_pmu_reset_counter_variable(
&mdla_device->pmu_info[i]);
mdla_pmu_reset_counter(core_id);
mdla_cmd_ops_get()->unlock(mdla_device);
break;
case IOCTL_PERF_RESET_CYCLE:
mdla_cmd_ops_get()->lock(mdla_device);
for (i = 0; i < PRIORITY_LEVEL; i++)
mdla_pmu_reset_cycle_variable(
&mdla_device->pmu_info[i]);
mdla_pmu_reset_cycle(core_id);
mdla_cmd_ops_get()->unlock(mdla_device);
break;
case IOCTL_PERF_SET_MODE:
mdla_cmd_ops_get()->lock(mdla_device);
mdla_pmu_percmd_mode_set(pmu_info, perf_data.mode);
mdla_pmu_percmd_mode_write(core_id, pmu_info);
mdla_cmd_ops_get()->unlock(mdla_device);
break;
default:
break;
}
if (copy_to_user((void *) arg, &perf_data, sizeof(perf_data)))
retval = -EFAULT;
out:
if (need_pwr_on)
mdla_pwr_ops_get()->unlock(core_id);
return retval;
}
void mdla_v2_0_pmu_info_show(struct seq_file *s)
{
int i, p, c;
struct mdla_pmu_info *pmu;
for_each_mdla_core(i) {
seq_printf(s, "%d: CFG_PMCR(0x%08x)=0x%x\n",
i, CFG_PMCR,
biu_read(i, CFG_PMCR));
seq_printf(s, "%d: PMU_CLK_CNT(0x%08x)=0x%x\n",
i, PMU_CLK_CNT,
biu_read(i, PMU_CLK_CNT));
seq_printf(s, "%d: PMU_START_TSTAMP(0x%08x)=0x%x\n",
i, PMU_START_TSTAMP,
biu_read(i, PMU_START_TSTAMP));
seq_printf(s, "%d: PMU_END_TSTAMP(0x%08x)=0x%x\n",
i, PMU_END_TSTAMP,
biu_read(i, PMU_END_TSTAMP));
seq_printf(s, "%d: PMU_CMDID_LATCH(0x%08x)=0x%x\n",
i, PMU_CMDID_LATCH,
biu_read(i, PMU_CMDID_LATCH));
for (c = 0; c < MDLA_PMU_COUNTERS; c++) {
seq_printf(s, "%d: counter %2d, 0x%04x=0x%-8x, 0x%04x=%d, 0x%04x=%d\n",
i, c,
PMU(c),
biu_read(c, PMU(c)),
PMU_CNT(c),
biu_read(c, PMU_CNT(c)),
PMU_CNT_LATCH(c),
biu_read(c, PMU_CNT_LATCH(c)));
}
for (p = 0; p < PRIORITY_LEVEL; p++) {
pmu = &mdla_get_device(i)->pmu_info[p];
seq_printf(s, "%d: priority = %d, number_of_event = %d\n",
i, p, pmu->number_of_event);
for (c = 0; c < MDLA_PMU_COUNTERS; c++)
seq_printf(s, "%d: priority=%d, counter %2d : event=0x%-8x, count=%d\n",
i, p, c,
pmu->data.event_handle[c],
pmu->data.l_counters[c]);
}
}
seq_printf(s, "\nset event by %s\n",
mdla_dbg_read_u32(FS_PMU_EVT_BY_APU) ? "apusys" : "debugfs");
seq_puts(s, "\n==== usage ====\n");
seq_printf(s, "%24s: echo [1|0] > /d/mdla/%s\n",
"set pmu event source",
mdla_dbg_get_u32_node_str(FS_PMU_EVT_BY_APU));
seq_printf(s, "%24s: echo [us(dec)] > /d/mdla/%s\n",
"set pmu timer period",
mdla_dbg_get_u64_node_str(FS_CFG_PMU_PERIOD));
}
void mdla_v2_0_pmu_init(struct mdla_dev *mdla_info)
{
int i;
struct mdla_pmu_info *info;
struct mdla_pmu_dev *dev;
struct mdla_util_pmu_ops *pmu_ops = mdla_util_pmu_ops_get();
info = kcalloc(PRIORITY_LEVEL, sizeof(struct mdla_pmu_info),
GFP_KERNEL);
if (!info)
return;
dev = kzalloc(sizeof(struct mdla_pmu_dev), GFP_KERNEL);
if (!dev) {
kfree(info);
return;
}
for (i = 0; i < PRIORITY_LEVEL; i++)
info[i].data.cfg_percmd_mode = NORMAL;
spin_lock_init(&dev->lock);
mdla_info->pmu_dev = dev;
mdla_info->pmu_info = info;
mdla_ioctl_register_perf_handle(mdla_pmu_ioctl);
pmu_ops->reg_counter_save = mdla_pmu_counter_save;
pmu_ops->reg_counter_read = mdla_pmu_counter_read_all;
pmu_ops->clr_counter_variable = mdla_pmu_reset_counter_variable;
pmu_ops->clr_cycle_variable = mdla_pmu_reset_cycle_variable;
pmu_ops->get_num_evt = mdla_pmu_get_num_evt;
pmu_ops->set_num_evt = mdla_pmu_set_num_evt;
pmu_ops->set_percmd_mode = mdla_pmu_percmd_mode_set;
pmu_ops->get_curr_mode = mdla_pmu_get_mode;
pmu_ops->get_perf_end = mdla_pmu_get_perf_end;
pmu_ops->get_perf_cycle = mdla_pmu_get_perf_cycle;
pmu_ops->get_perf_cmdid = mdla_pmu_get_perf_cmdid;
pmu_ops->get_perf_cmdcnt = mdla_pmu_get_perf_cmdcnt;
pmu_ops->get_counter = mdla_pmu_get_counter;
pmu_ops->reset_counter = mdla_pmu_reset_counter;
pmu_ops->disable_counter = mdla_pmu_counter_disable_all;
pmu_ops->enable_counter = mdla_pmu_counter_enable_all;
pmu_ops->reset = mdla_pmu_reset;
pmu_ops->write_evt_exec = mdla_pmu_event_write_all;
pmu_ops->reset_write_evt_exec = mdla_pmu_reset_and_write_event;
pmu_ops->get_hnd_evt = mdla_pmu_get_hnd_evt;
pmu_ops->get_hnd_evt_num = mdla_pmu_get_hnd_evt_num;
pmu_ops->get_hnd_mode = mdla_pmu_get_hnd_mode;
pmu_ops->get_hnd_buf_addr = mdla_pmu_get_hnd_buf_addr;
pmu_ops->set_evt_handle = mdla_pmu_set_evt_handle;
pmu_ops->get_info = mdla_pmu_get_info;
pmu_ops->apu_cmd_prepare = mdla_pmu_cmd_prepare;
pmu_ops->apu_pmu_valid = mdla_pmu_apusys_valid;
if (mdla_plat_nn_pmu_support())
mdla_util_apusys_pmu_support(true);
else
mdla_util_apusys_pmu_support(false);
}
void mdla_v2_0_pmu_deinit(struct mdla_dev *mdla_info)
{
mdla_util_apusys_pmu_support(false);
mdla_ioctl_unregister_perf_handle();
kfree(mdla_info->pmu_dev);
kfree(mdla_info->pmu_info);
}
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_V2_0_PMU_H__
#define __MDLA_V2_0_PMU_H__
struct seq_file;
struct mdla_dev;
void mdla_v2_0_pmu_info_show(struct seq_file *s);
void mdla_v2_0_pmu_init(struct mdla_dev *mdla_info);
void mdla_v2_0_pmu_deinit(struct mdla_dev *mdla_info);
#endif /* __MDLA_V2_0_PMU_H__ */
@@ -0,0 +1,731 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/list.h>
#include <linux/preempt.h>
#include <linux/sched/clock.h>
#include <apusys_device.h>
#include <common/mdla_device.h>
#include <common/mdla_scheduler.h>
#include <common/mdla_cmd_proc.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_profile.h>
#include <interface/mdla_cmd_data_v2_0.h>
#include <platform/mdla_plat_api.h>
#include "mdla_hw_reg_v2_0.h"
static void mdla_sched_enqueue_ce(u32 core_id, struct command_entry *ce, u32 resume);
static struct command_entry *mdla_sched_dequeue_ce(u32 core_id);
static void mdla_sched_hw_issue_ce(u32 core_id);
static void mdla_sched_sw_issue_ce(u32 core_id);
static struct lock_class_key sched_lock_key[MAX_CORE_NUM];
/*==========================================
* For SW preemption
*==========================================
*/
static struct sched_smp_ce smp_ce[PRIORITY_LEVEL];
static struct lock_class_key smp_ce_lock_key[PRIORITY_LEVEL];
/* callback functions */
static void mdla_sched_set_smp_deadline(int priority, u64 deadline)
{
unsigned long flags;
if (unlikely(priority < 0 || priority >= PRIORITY_LEVEL))
return;
spin_lock_irqsave(&smp_ce[priority].lock, flags);
if (deadline > smp_ce[priority].deadline)
smp_ce[priority].deadline = deadline;
spin_unlock_irqrestore(&smp_ce[priority].lock, flags);
}
static u64 mdla_sched_get_smp_deadline(int priority)
{
if (unlikely(priority < 0 || priority >= PRIORITY_LEVEL))
return 0;
return smp_ce[priority].deadline;
}
static inline u32 mdla_get_swcmd(void *base_kva, u32 offset)
{
return (*(u32 *)(base_kva + offset));
}
static inline void mdla_set_swcmd(void *base_kva, u32 offset, u32 val)
{
(*(u32 *)(base_kva + offset)) = val;
}
//cid, which cmd id layer end bit do you want to get
static inline bool mdla_is_layer_end(void *base_kva, u32 cid)
{
return (mdla_get_swcmd(base_kva + (cid - 1) * MREG_CMD_SIZE,
MREG_CMD_GENERAL_CTRL_0)
& MREG_CMD_LAYER_END);
}
//cid, which cmd id wait bit do you want to clear
static inline void mdla_clear_swcmd_wait_bit(void *base_kva, u32 cid)
{
void *cmd_kva = base_kva + (cid - 1) * MREG_CMD_SIZE;
mdla_set_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1,
mdla_get_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1)
& ~MREG_CMD_WAIT_SWCMD_DONE);
}
//cid, which cmd id issue bit do you want to clear
static inline void mdla_clear_swcmd_int_bit(void *base_kva, u32 cid)
{
void *cmd_kva = base_kva + (cid - 1) * MREG_CMD_SIZE;
mdla_set_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1,
mdla_get_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1)
& ~MREG_CMD_INT_SWCMD_DONE);
}
static inline void mdla_set_swcmd_done_int(void *base_kva, u32 cid)
{
void *cmd_kva = base_kva + (cid - 1) * MREG_CMD_SIZE;
mdla_set_swcmd(cmd_kva, MREG_CMD_TILE_CNT_INT,
mdla_get_swcmd(cmd_kva, MREG_CMD_TILE_CNT_INT)
| MREG_CMD_SWCMD_FINISH_INT_EN);
}
static void mdla_del_free_command_batch(struct command_entry *ce)
{
struct command_batch *cb;
struct list_head *tmp, *next;
if (unlikely(ce->cmd_batch_size >= ce->count))
return;
list_for_each_safe(tmp, next, ce->batch_list_head) {
cb = list_entry(tmp, struct command_batch, node);
list_del(&cb->node);
kfree(cb);
}
kfree(ce->batch_list_head);
ce->batch_list_head = NULL;
}
static void mdla_split_alloc_command_batch(struct command_entry *ce)
{
size_t i, j;
u32 cur_batch_len = 0;
u32 batch_tail_id = 0;
u32 batch_size = ce->cmd_batch_size;
u32 cmd_count = ce->count;
struct command_batch *cb;
struct list_head *tmp, *next;
if (unlikely(ce->cmdbuf == NULL))
return;
ce->batch_list_head =
kzalloc(sizeof(struct list_head), GFP_KERNEL);
if (!ce->batch_list_head)
return;
INIT_LIST_HEAD(ce->batch_list_head);
apusys_mem_invalidate(ce->cmdbuf);
// TODO: add default policy when batch_size is zero
for (i = 1; i <= cmd_count; i += cur_batch_len) {
cur_batch_len = 0;
for (j = i; j <= cmd_count; ++j) {
cur_batch_len++;
if (cur_batch_len >= batch_size &&
mdla_is_layer_end(ce->kva, j))
break;
}
// allocate one command batch
cb = kzalloc(sizeof(*cb), GFP_KERNEL);
if (!cb) {
mdla_del_free_command_batch(ce);
return;
}
cb->index = i;// first cmd id
cb->size = cur_batch_len;
batch_tail_id = i + cur_batch_len - 1;// Last cmd id
list_add_tail(&cb->node, ce->batch_list_head);
// encode SWCMD DONE
mdla_set_swcmd_done_int(ce->kva, batch_tail_id);
// handle first cmd wait bit and check fuse cmd
mdla_clear_swcmd_wait_bit(ce->kva, cb->index);
if (batch_tail_id > cb->index &&
!mdla_is_layer_end(ce->kva, cb->index)) {
mdla_clear_swcmd_wait_bit(ce->kva, cb->index + 1);
}
// encode the previous layer if that is fused with tail
mdla_clear_swcmd_int_bit(ce->kva, batch_tail_id);
if (batch_tail_id > 1 &&
!mdla_is_layer_end(ce->kva, batch_tail_id - 1)) {
mdla_set_swcmd_done_int(ce->kva, batch_tail_id - 1);
mdla_clear_swcmd_int_bit(ce->kva, batch_tail_id - 1);
}
}
// buffer sync here
if (likely(ce->cmdbuf != NULL))
apusys_mem_flush(ce->cmdbuf);
if (mdla_dbg_read_u32(FS_PREEMPTION_DBG))
list_for_each_safe(tmp, next, ce->batch_list_head) {
cb = list_entry(tmp, struct command_batch, node);
mdla_cmd_debug("%s: id = %d, size = %d, tid = %d\n",
__func__, cb->index,
cb->size, cb->index + cb->size - 1);
}
}
static void mdla_backup_command_batch(struct command_entry *ce)
{
uint32_t i = 0;
void *cmd_kva = NULL;
if (unlikely(!ce->cmd_int_backup || !ce->cmd_ctrl_1_backup))
return;
apusys_mem_invalidate(ce->cmdbuf);
/* backup cmd buffer value */
for (i = 1; i <= ce->count; i++) {
cmd_kva = ce->kva + (i - 1) * MREG_CMD_SIZE;
ce->cmd_int_backup[i - 1] =
mdla_get_swcmd(cmd_kva, MREG_CMD_TILE_CNT_INT);
ce->cmd_ctrl_1_backup[i - 1] =
mdla_get_swcmd(cmd_kva, MREG_CMD_GENERAL_CTRL_1);
}
apusys_mem_flush(ce->cmdbuf);
}
static void mdla_restore_command_batch(struct command_entry *ce)
{
uint32_t i = 0;
void *cmd_kva = NULL;
if (unlikely(ce->cmdbuf == NULL))
return;
if (unlikely(!ce->cmd_int_backup || !ce->cmd_ctrl_1_backup))
return;
apusys_mem_invalidate(ce->cmdbuf);
for (i = 1; i <= ce->count; i++) {
cmd_kva = ce->kva + (i - 1) * MREG_CMD_SIZE;
mdla_set_swcmd(cmd_kva,
MREG_CMD_TILE_CNT_INT, ce->cmd_int_backup[i - 1]);
mdla_set_swcmd(cmd_kva,
MREG_CMD_GENERAL_CTRL_1, ce->cmd_ctrl_1_backup[i - 1]);
}
apusys_mem_flush(ce->cmdbuf);
}
/*
* NOTE: sched->lock should be acquired by caller
*/
void mdla_sched_preempt_ce(unsigned int core_id, struct command_entry *high_ce)
{
struct mdla_scheduler *sched = mdla_get_device(core_id)->sched;
struct command_entry *low_ce = sched->pro_ce;
low_ce->state |= (1 << CE_PREEMPTED);
low_ce->deadline_t = get_jiffies_64() + msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
sched->enqueue_ce(core_id, low_ce, 1);
mdla_dbg_add_u32(FS_PREEMPTION_TIMES, 1);
high_ce->state |= (1 << CE_PREEMPTING);
sched->pro_ce = high_ce;
}
/*
* Issue the processing_ce to HW engine
* NOTE1: sched->lock should be acquired by caller
* NOTE2: sched->pro_ce should be assigned by caller
*/
static void mdla_sched_sw_issue_ce(u32 core_id)
{
u32 irq_status;
struct mdla_dev *dev = mdla_get_device(core_id);
struct mdla_scheduler *sched = dev->sched;
struct command_entry *ce;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
unsigned long flags;
ce = sched->pro_ce;
if (!ce) {
mdla_util_pmu_ops_get()->disable_counter(core_id);
return;
}
spin_lock_irqsave(&dev->stat_lock, flags);
dev->status = MDLA_RUN;
spin_unlock_irqrestore(&dev->stat_lock, flags);
spin_lock_irqsave(&dev->hw_lock, flags);
irq_status = io->cmde.read(core_id, MREG_TOP_G_INTP0);
if (likely(irq_status & INTR_CDMA_FIFO_EMPTY)) {
u64 deadline = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
/* reset pmu and set register */
mdla_util_pmu_ops_get()->reset_write_evt_exec(core_id,
(u16)ce->priority);
ce->state |= (1 << CE_RUN);
if (likely(ce->context_callback != NULL))
ce->context_callback(
APUSYS_DEVICE_MDLA,
core_id, ce->ctx_id);
/* update smp deadline */
if (ce->multicore_total > 1)
mdla_sched_set_smp_deadline(ce->priority, deadline);
else
ce->deadline_t = deadline;
mdla_cmd_plat_cb()->process_command_no_lock(core_id, ce);
if (ce->fin_cid == 0) {
mdla_prof_set_ts(core_id, TS_HW_FIRST_TRIGGER,
mdla_prof_get_ts(core_id, TS_HW_TRIGGER));
} else {
mdla_prof_set_ts(core_id, TS_CMD_RESUME,
mdla_prof_get_ts(core_id, TS_HW_TRIGGER));
}
} else {
if ((ce->irq_state & IRQ_N_EMPTY_IN_SCHED) == 0)
ce->irq_state |= IRQ_NE_ISSUE_FIRST;
ce->irq_state |= IRQ_N_EMPTY_IN_ISSUE;
ce->state |= (1 << CE_SKIP);
if (in_interrupt())
ce->irq_state |= IRQ_IN_IRQ;
else
ce->irq_state |= IRQ_NOT_IN_IRQ;
}
spin_unlock_irqrestore(&dev->hw_lock, flags);
}
static void mdla_sched_normal_smp_issue_ce(
uint32_t core_id,
uint64_t dual_cmd_id)
{
struct mdla_scheduler *sched;
unsigned long flags[MAX_CORE_NUM];
struct command_entry *ce;
int i;
for_each_mdla_core(i) {
sched = mdla_get_device(i)->sched;
if (sched->pro_ce != NULL)
goto unlock;
spin_lock_irqsave(&sched->lock, flags[i]);
}
/* check list status */
for_each_mdla_core(i) {
ce = mdla_sched_dequeue_ce(i);
if ((ce == NULL) || (ce->cmd_id != dual_cmd_id)
|| (ce->priority != MDLA_LOW_PRIORITY)) {
mdla_get_device(i)->sched->pro_ce = ce;
break;
}
mdla_get_device(i)->sched->pro_ce = ce;
}
if (i == mdla_util_get_core_num()) {
for_each_mdla_core(i)
mdla_sched_sw_issue_ce(i);
} else {
for (; i >= 0; i--) {
sched = mdla_get_device(i)->sched;
mdla_sched_enqueue_ce(i, sched->pro_ce, 2);
sched->pro_ce = NULL;
}
}
i = mdla_util_get_core_num();
unlock:
/* free all cores spin lock */
for (i = i - 1; i >= 0; i--)
spin_unlock_irqrestore(&mdla_get_device(i)->sched->lock, flags[i]);
}
/*
* Consume the processing_ce:
* 1. get the finished command id and tile id from HW RGs
* 2. check whether this batch completed
*
* Return value:
* 1. return CE_DONE if all the batches in the CE completed.
* 2. return CE_RUN if a batch completed, and we can go on to issue the next.
* 3. return CE_NONE if the batch is still under processing.
*
* NOTE: sched->lock should be acquired by caller
*/
static int mdla_sched_process_ce(u32 core_id)
{
unsigned long flags;
int ret = CE_NONE;
struct command_entry *ce;
struct command_batch *cb;
struct mdla_dev *dev = mdla_get_device(core_id);
struct mdla_scheduler *sched = dev->sched;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
struct mdla_pmu_info *pmu;
u32 fin_cid;
spin_lock_irqsave(&dev->hw_lock, flags);
/* Read current EVT_ID */
fin_cid = io->cmde.read(core_id, MREG_TOP_G_FIN3);
spin_unlock_irqrestore(&dev->hw_lock, flags);
ce = sched->pro_ce;
if (!ce)
return ret;
ce->fin_cid = fin_cid;
if (fin_cid < ce->wish_fin_cid) {
ce->irq_state |= IRQ_TWICE;
ce_func_trace(ce, F_CMDDONE_CE_FIN3ERROR);
return ret;
}
/* read after write make sure it will write back to register now */
spin_lock_irqsave(&dev->hw_lock, flags);
pmu = mdla_util_pmu_ops_get()->get_info(core_id, (u16)ce->priority);
if (pmu)
mdla_util_pmu_ops_get()->reg_counter_save(core_id, pmu);
io->cmde.write(core_id, MREG_TOP_G_CDMA4, 1);
spin_unlock_irqrestore(&dev->hw_lock, flags);
if (ce->batch_list_head != NULL) {
if (likely(!list_empty(ce->batch_list_head))) {
cb = list_first_entry(ce->batch_list_head,
struct command_batch, node);
list_del(&cb->node);
kfree(cb);
}
}
/* all command done for command-based scheduling */
if (fin_cid >= ce->count) {
ret = CE_DONE;
ce->state |= (1 << CE_DONE);
} else {
ret = CE_SCHED;
ce->state |= (1 << CE_SCHED);
}
return ret;
}
/*================================================
* For Hardware pre-emption
*================================================
*/
/* Note: hw_lock should be assigned by caller */
static void mdla_restore_cmd(u32 core_id, struct command_entry *ce)
{
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
io->cmde.write(core_id, MREG_TOP_G_MDLA_HWSYNC1, ce->hw_sync1);
io->cmde.write(core_id, MREG_TOP_G_MDLA_HWSYNC2, ce->hw_sync2);
io->cmde.write(core_id, MREG_TOP_G_MDLA_HWSYNC3, ce->hw_sync3);
}
/*
* Reset APB reg and MDLA reg
*/
//TODO: not dependent on sched, move to other file?
static void mdla_sched_sw_reset(u32 core_id)
{
unsigned long flags;
struct mdla_dev *dev = mdla_get_device(core_id);
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
u32 reg;
spin_lock_irqsave(&dev->hw_lock, flags);
io->cfg.write(core_id, MDLA_SW_RST, MDLA_SW_RST_MASK);
do {
reg = io->cfg.read(core_id, MDLA_SW_RST);
} while (reg != MDLA_SW_RST_MASK);
io->cfg.write(core_id, MDLA_SW_RST, 0);
spin_unlock_irqrestore(&dev->hw_lock, flags);
}
/*
* Issue the processing_ce to HW engine
* NOTE: sched->lock should be acquired by caller
* Note: sched->pro_ce should be assigned by caller
*/
static void mdla_sched_hw_issue_ce(u32 core_id)
{
u32 irq_status;
struct mdla_dev *dev = mdla_get_device(core_id);
struct mdla_scheduler *sched = dev->sched;
struct command_entry *ce;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
unsigned long flags, flags1;
ce = sched->pro_ce;
if (!ce) {
mdla_util_pmu_ops_get()->disable_counter(core_id);
return;
}
spin_lock_irqsave(&dev->stat_lock, flags);
dev->status = MDLA_RUN;
spin_unlock_irqrestore(&dev->stat_lock, flags);
spin_lock_irqsave(&dev->hw_lock, flags1);
irq_status = io->cmde.read(core_id, MREG_TOP_G_INTP0);
if (likely(irq_status & INTR_CDMA_FIFO_EMPTY)) {
u64 deadline = get_jiffies_64()
+ msecs_to_jiffies(mdla_dbg_read_u32(FS_TIMEOUT));
/* restore HW sync count to resume ce */
if (ce->fin_cid != 0)
mdla_restore_cmd(core_id, ce);
/* reset pmu and set register */
mdla_util_pmu_ops_get()->reset_write_evt_exec(core_id,
(u16)ce->priority);
ce->state |= (1 << CE_RUN);
if (likely(ce->context_callback != NULL))
ce->context_callback(
APUSYS_DEVICE_MDLA,
core_id, ce->ctx_id);
//FIXME: update SMP deadline for SMP cmd
ce->deadline_t = deadline;
mdla_cmd_plat_cb()->process_command_no_lock(core_id, ce);
if (ce->fin_cid == 0) {
mdla_prof_set_ts(core_id, TS_HW_FIRST_TRIGGER,
mdla_prof_get_ts(core_id, TS_HW_TRIGGER));
} else {
mdla_prof_set_ts(core_id, TS_CMD_RESUME,
mdla_prof_get_ts(core_id, TS_HW_TRIGGER));
}
} else {
if ((ce->irq_state & IRQ_N_EMPTY_IN_SCHED) == 0)
ce->irq_state |= IRQ_NE_ISSUE_FIRST;
ce->irq_state |= IRQ_N_EMPTY_IN_ISSUE;
ce->state |= (1 << CE_SKIP);
if (in_interrupt())
ce->irq_state |= IRQ_IN_IRQ;
else
ce->irq_state |= IRQ_NOT_IN_IRQ;
}
spin_unlock_irqrestore(&dev->hw_lock, flags1);
}
/*
* Set stop bit to the processing_ce in HW engine
* NOTE: Need to check sched->pro_ce != NULL before call it
* NOTE: sched->lock should be acquired by caller
*/
static void mdla_sched_stop_ce(u32 core_id, struct command_entry *ce)
{
struct mdla_dev *dev = mdla_get_device(core_id);
struct mdla_scheduler *sched = dev->sched;
struct command_entry *old_ce = (struct command_entry *)sched->pro_ce;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
unsigned long flags;
spin_lock_irqsave(&dev->stat_lock, flags);
dev->status = MDLA_GOTO_STOP;
spin_unlock_irqrestore(&dev->stat_lock, flags);
spin_lock_irqsave(&dev->hw_lock, flags);
io->cmde.write(core_id, MREG_TOP_G_FIN4, 1);
spin_unlock_irqrestore(&dev->hw_lock, flags);
ce_func_trace(old_ce, F_SET_STOP_SINGLE);
ce_func_trace(ce, F_SET_STOP_NEW_CE);
mdla_prof_set_ts(core_id, TS_CMD_STOP_REQ, sched_clock());
}
/*================================================
* For both SW and HW pre-emption
*================================================
*/
/*
* Enqueue one CE and start scheduler
* NOTE: sched->lock should be acquired by caller
*/
static void mdla_sched_enqueue_ce(u32 core_id, struct command_entry *ce, u32 resume)
{
struct mdla_scheduler *sched = mdla_get_device(core_id)->sched;
if (!ce)
return;
if (resume) {
list_add(&ce->node, &sched->ce_list[ce->priority]);
ce->state |= BIT(CE_QUEUE_RESUME);
} else {
list_add_tail(&ce->node, &sched->ce_list[ce->priority]);
ce->state |= BIT(CE_QUEUE);
}
ce_func_trace(ce, F_ENQUEUE | resume);
}
/*
* Dequeue a prioritized CE from CE queue.
* NOTE: sched->lock should be acquired by caller
*/
static struct command_entry *mdla_sched_dequeue_ce(u32 core_id)
{
struct mdla_scheduler *sched = mdla_get_device(core_id)->sched;
struct command_entry *ce = NULL;
int prio;
for (prio = PRIORITY_LEVEL - 1; prio >= 0; prio--) {
ce = list_first_entry_or_null(&sched->ce_list[prio], struct command_entry, node);
if (ce) {
list_del(&ce->node);
ce_func_trace(ce, F_DEQUEUE);
break;
}
}
return ce;
}
/*
* Set the status of completed CE as CE_FIN
* NOTE: sched->lock should be acquired by caller
*/
static void mdla_sched_complete_ce(u32 core_id)
{
struct mdla_scheduler *sched = mdla_get_device(core_id)->sched;
sched->pro_ce->state |= (1 << CE_FIN);
complete(&sched->pro_ce->swcmd_done_wait);
sched->pro_ce = NULL;
}
int mdla_v2_0_sched_init(void)
{
struct mdla_scheduler *sched;
struct mdla_sched_cb_func *sched_cb = mdla_sched_plat_cb();
int i, j;
for_each_mdla_core(i) {
sched = kzalloc(sizeof(struct mdla_scheduler), GFP_KERNEL);
if (!sched)
goto err;
mdla_get_device(i)->sched = sched;
spin_lock_init(&sched->lock);
lockdep_set_class(&sched->lock, &sched_lock_key[i]);
for (j = 0; j < PRIORITY_LEVEL; j++)
INIT_LIST_HEAD(&sched->ce_list[j]);
/* common */
sched->pro_ce = NULL;
sched->enqueue_ce = mdla_sched_enqueue_ce;
sched->dequeue_ce = mdla_sched_dequeue_ce;
sched->complete_ce = mdla_sched_complete_ce;
/* HW preemption only */
sched->sw_reset = mdla_sched_sw_reset;
sched->stop_ce = mdla_sched_stop_ce;
if (mdla_plat_hw_preemption_support())
sched->issue_ce = mdla_sched_hw_issue_ce;
/* SW preemption only */
sched->process_ce = mdla_sched_process_ce;
sched->issue_dual_lowce = mdla_sched_normal_smp_issue_ce;
sched->preempt_ce = mdla_sched_preempt_ce;
sched->get_smp_deadline = mdla_sched_get_smp_deadline;
sched->set_smp_deadline = mdla_sched_set_smp_deadline;
if (mdla_plat_sw_preemption_support())
sched->issue_ce = mdla_sched_sw_issue_ce;
}
for (i = 0; i < PRIORITY_LEVEL; i++) {
spin_lock_init(&smp_ce[i].lock);
lockdep_set_class(&smp_ce[i].lock, &smp_ce_lock_key[i]);
}
/* set scheduler callback, SW preemption only */
sched_cb->split_alloc_cmd_batch = mdla_split_alloc_command_batch;
sched_cb->del_free_cmd_batch = mdla_del_free_command_batch;
sched_cb->backup_cmd_batch = mdla_backup_command_batch;
sched_cb->restore_cmd_batch = mdla_restore_command_batch;
return 0;
err:
for (i = i - 1; i >= 0; i--)
kfree(mdla_get_device(i)->sched);
return -ENOMEM;
}
void mdla_v2_0_sched_deinit(void)
{
int i;
for_each_mdla_core(i)
kfree(mdla_get_device(i)->sched);
}
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MDLA_V2_0_SCHED_H__
#define __MDLA_V2_0_SCHED_H__
int mdla_v2_0_sched_init(void);
void mdla_v2_0_sched_deinit(void);
#endif /* __MDLA_V2_0_SCHED_H__ */
@@ -0,0 +1,802 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/of_device.h>
#include <linux/io.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/interrupt.h>
#include <linux/completion.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/debugfs.h>
#include <linux/sched/clock.h>
#include <common/mdla_device.h>
#include <common/mdla_cmd_proc.h>
#include <common/mdla_power_ctrl.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_profile.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_trace.h>
#include <interface/mdla_intf.h>
#include <interface/mdla_cmd_data_v2_0.h>
#include <platform/mdla_plat_api.h>
#include "mdla_hw_reg_v2_0.h"
#include "mdla_irq_v2_0.h"
#include "mdla_pmu_v2_0.h"
#include "mdla_sched_v2_0.h"
#define DBGFS_PMU_NAME "pmu_reg"
#define DBGFS_USAGE_NAME "help"
static struct mdla_reg_ctl *mdla_reg_control;
static struct mdla_dev *mdla_plat_devices;
static int mdla_dbgfs_u64_create[NF_MDLA_DEBUG_FS_U64] = {
[FS_CFG_PMU_PERIOD] = 1,
};
static bool mdla_dbgfs_u32_create[NF_MDLA_DEBUG_FS_U32] = {
[FS_C1] = 1,
[FS_C2] = 1,
[FS_C3] = 1,
[FS_C4] = 1,
[FS_C5] = 1,
[FS_C6] = 1,
[FS_C7] = 1,
[FS_C8] = 1,
[FS_C9] = 1,
[FS_C10] = 1,
[FS_C11] = 1,
[FS_C12] = 1,
[FS_C13] = 1,
[FS_C14] = 1,
[FS_C15] = 1,
[FS_CFG_ENG0] = 1,
[FS_CFG_ENG1] = 1,
[FS_CFG_ENG2] = 1,
[FS_CFG_ENG11] = 1,
[FS_POLLING_CMD_DONE] = 1,
[FS_DUMP_CMDBUF] = 1,
[FS_DVFS_RAND] = 1,
[FS_PMU_EVT_BY_APU] = 1,
[FS_KLOG] = 1,
[FS_POWEROFF_TIME] = 1,
[FS_TIMEOUT] = 1,
[FS_TIMEOUT_DBG] = 0,
[FS_BATCH_NUM] = 1,
[FS_PREEMPTION_TIMES] = 1,
[FS_PREEMPTION_DBG] = 1,
};
static struct lock_class_key hw_lock_key[MAX_CORE_NUM];
static struct lock_class_key stat_lock_key[MAX_CORE_NUM];
/* platform static functions */
static inline unsigned long mdla_plat_get_wait_time(u32 core_id)
{
unsigned long time;
if (mdla_trace_get_cfg_pmu_tmr_en())
time = usecs_to_jiffies(mdla_dbg_read_u64(FS_CFG_PMU_PERIOD));
else
time = msecs_to_jiffies(mdla_dbg_read_u32(FS_POLLING_CMD_DONE));
return time;
}
static void mdla_plat_destroy_dump_cmdbuf(struct mdla_dev *mdla_device)
{
mutex_lock(&mdla_device->cmd_buf_dmp_lock);
if (mdla_device->cmd_buf_len) {
kvfree(mdla_device->cmd_buf_dmp);
mdla_device->cmd_buf_len = 0;
}
mutex_unlock(&mdla_device->cmd_buf_dmp_lock);
}
static bool mdla_check_cmd_valid(
uint64_t out_end,
struct command_entry *ce)
{
uint64_t out_size;
if ((uint64_t)ce->kva == 0) {
mdla_err("%s:%d query kva = 0\n", __func__, __LINE__);
return false;
}
if (out_end < (uint64_t)ce->kva) {
mdla_err("%s:%d invalid cmd buffer addr\n", __func__, __LINE__);
return false;
}
out_size = out_end - (uint64_t)ce->kva;
if (out_size < (uint64_t)ce->count*MREG_CMD_SIZE) {
mdla_err("%s:%d invalid cmd buffer size\n", __func__, __LINE__);
return false;
}
return true;
}
/**
* Dump command buffer(code buffer) for debug
* [Condition]
* - command timeout
* - force to dump : echo 1 > /d/mdla/dump_cmdbuf_en
* [Show data]
* - debugfs node : cat /d/mdla/mdla_memory
* - db (only command timeout) : SYS_MDLA_MEMORY
*/
static int mdla_plat_create_dump_cmdbuf(struct mdla_dev *mdla_device, struct command_entry *ce)
{
int ret = 0;
if (ce->kva == NULL)
return ret;
mutex_lock(&mdla_device->cmd_buf_dmp_lock);
if (mdla_device->cmd_buf_len)
kvfree(mdla_device->cmd_buf_dmp);
mdla_device->cmd_buf_dmp = kvmalloc(ce->count * MREG_CMD_SIZE, GFP_KERNEL);
if (!mdla_device->cmd_buf_dmp) {
ret = -ENOMEM;
mdla_err("%s: allocate mem failed\n", __func__);
goto out;
}
mdla_device->cmd_buf_len = ce->count * MREG_CMD_SIZE;
memcpy(mdla_device->cmd_buf_dmp, ce->kva, mdla_device->cmd_buf_len);
out:
mutex_unlock(&mdla_device->cmd_buf_dmp_lock);
return ret;
}
static int mdla_plat_pre_cmd_handle(u32 core_id, struct command_entry *ce)
{
if (mdla_dbg_read_u32(FS_DUMP_CMDBUF))
mdla_plat_create_dump_cmdbuf(mdla_get_device(core_id), ce);
return 0;
}
static int mdla_plat_pre_cmd_handle_sw_sched(u32 core_id, struct command_entry *ce)
{
if (ce->multicore_total > 1)
mdla_plat_devices[core_id].sched->set_smp_deadline(ce->priority, ce->deadline_t);
if (mdla_dbg_read_u32(FS_DUMP_CMDBUF))
mdla_plat_create_dump_cmdbuf(mdla_get_device(core_id), ce);
return 0;
}
static int mdla_plat_post_cmd_handle(u32 core_id, struct command_entry *ce)
{
unsigned long flags;
spin_lock_irqsave(&mdla_get_device(core_id)->hw_lock, flags);
/* clear current event id */
mdla_util_io_ops_get()->cmde.write(core_id, MREG_TOP_G_CDMA4, 1);
spin_unlock_irqrestore(&mdla_get_device(core_id)->hw_lock, flags);
ce->req_start_t = mdla_prof_get_ts(core_id, TS_HW_FIRST_TRIGGER);
ce->req_end_t = mdla_prof_get_ts(core_id, TS_HW_LAST_INTR);
return 0;
}
static int mdla_plat_post_cmd_handle_sched(u32 core_id, struct command_entry *ce)
{
ce->req_start_t = mdla_prof_get_ts(core_id, TS_HW_FIRST_TRIGGER);
ce->req_end_t = mdla_prof_get_ts(core_id, TS_HW_LAST_INTR);
return 0;
}
static int mdla_plat_wait_cmd_handle(u32 core_id, struct command_entry *ce)
{
/* update SMP CMD deadline */
if (ce->multicore_total > 1) {
u64 deadline = mdla_plat_devices[core_id].sched->get_smp_deadline(ce->priority);
if (deadline > ce->deadline_t)
ce->deadline_t = deadline;
}
return 0;
}
static void mdla_plat_print_post_cmd_info(u32 core_id)
{
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
mdla_verbose("%s: C:%d,FIN1: %.8x\n",
__func__,
core_id,
io->cmde.read(core_id, MREG_TOP_G_FIN1));
mdla_pmu_debug("%s: CFG_PMCR: %8x, pmu_clk_cnt: %.8x\n",
__func__,
io->biu.read(core_id, CFG_PMCR),
io->biu.read(core_id, PMU_CLK_CNT));
}
/* NOTE: hw_lock should be acquired by caller */
static void mdla_plat_verbose_log(u32 core_id, const struct mdla_util_io_ops *io)
{
if (mdla_dbg_read_u32(FS_KLOG) != MDLA_DBG_ALL)
return;
io = mdla_util_io_ops_get();
pr_info("%d: CG_CON=0x%x\n", core_id, io->cfg.read(core_id, MDLA_CG_CON));
pr_info("%d: AXI_CTRL=0x%x\n", core_id, io->cfg.read(core_id, MDLA_AXI_CTRL));
pr_info("%d: AXI1_CTRL=0x%x\n", core_id, io->cfg.read(core_id, MDLA_AXI1_CTRL));
pr_info("%d: TOP_G_INTP0=0x%x\n", core_id, io->cmde.read(core_id, MREG_TOP_G_INTP0));
pr_info("%d: TOP_G_INTP1=0x%x\n", core_id, io->cmde.read(core_id, MREG_TOP_G_INTP1));
pr_info("%d: TOP_G_INTP2=0x%x\n", core_id, io->cmde.read(core_id, MREG_TOP_G_INTP2));
pr_info("%d: TOP_G_IDLE=0x%x\n", core_id, io->cmde.read(core_id, MREG_TOP_G_IDLE));
}
/* NOTE: hw_lock should be acquired by caller */
static void mdla_plat_raw_process_command(u32 core_id, u32 evt_id, dma_addr_t addr, u32 count)
{
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
mdla_plat_verbose_log(core_id, io);
/* set command address */
io->cmde.write(core_id, MREG_TOP_G_CDMA1, addr);
/* set command number */
io->cmde.write(core_id, MREG_TOP_G_CDMA2, count);
/* trigger hw */
io->cmde.write(core_id, MREG_TOP_G_CDMA3, evt_id);
/* write event id for SW debug */
io->cmde.write(core_id, MREG_TOP_G_STREAM0, evt_id);
mdla_prof_set_ts(core_id, TS_HW_TRIGGER, sched_clock());
mdla_verbose("%s:Fire to mdla-%x: addr: %lx, count: %d, evt_id: %x\n",
__func__, core_id, (unsigned long)addr, count, evt_id);
}
static int mdla_plat_process_command_in_batch(u32 core_id, struct command_entry *ce)
{
dma_addr_t addr;
u32 evt_id, count;
unsigned long flags;
struct command_batch *cb;
count = ce->count - ce->fin_cid;
if ((ce->batch_list_head != NULL)
&& !list_empty(ce->batch_list_head)) {
cb = list_first_entry(ce->batch_list_head,
struct command_batch, node);
count = cb->size;
}
ce->wish_fin_cid = ce->fin_cid + count;
addr = ce->mva + ((dma_addr_t)ce->fin_cid) * MREG_CMD_SIZE;
evt_id = ce->csn;
mdla_verbose("%s: mdla-%x: wish_fin_cid:%d\n", __func__, core_id, ce->wish_fin_cid);
spin_lock_irqsave(&mdla_get_device(core_id)->hw_lock, flags);
ce->state = CE_RUN;
mdla_plat_raw_process_command(core_id, evt_id, addr, count);
ce_func_trace(ce, F_ISSUE);
spin_unlock_irqrestore(&mdla_get_device(core_id)->hw_lock, flags);
return 0;
}
static int mdla_plat_process_command_in_batch_no_lock(u32 core_id, struct command_entry *ce)
{
dma_addr_t addr;
u32 evt_id, count;
struct command_batch *cb;
count = ce->count - ce->fin_cid;
if ((ce->batch_list_head != NULL)
&& !list_empty(ce->batch_list_head)) {
cb = list_first_entry(ce->batch_list_head,
struct command_batch, node);
count = cb->size;
}
ce->wish_fin_cid = ce->fin_cid + count;
addr = ce->mva + ((dma_addr_t)ce->fin_cid) * MREG_CMD_SIZE;
evt_id = ce->csn;
mdla_verbose("%s: mdla-%x: wish_fin_cid:%d\n", __func__, core_id, ce->wish_fin_cid);
ce->state = CE_RUN;
mdla_plat_raw_process_command(core_id, evt_id, addr, count);
ce_func_trace(ce, F_ISSUE);
return 0;
}
static int mdla_plat_process_command(u32 core_id, struct command_entry *ce)
{
dma_addr_t addr;
u32 evt_id, count;
unsigned long flags;
addr = ce->mva + ((dma_addr_t)ce->fin_cid) * MREG_CMD_SIZE;
count = ce->count - ce->fin_cid;
evt_id = ce->csn;
mdla_verbose("%s: mdla-%x: fin_cid:%d\n", __func__, core_id, ce->fin_cid);
spin_lock_irqsave(&mdla_get_device(core_id)->hw_lock, flags);
ce->state = CE_RUN;
mdla_plat_raw_process_command(core_id, evt_id, addr, count);
ce_func_trace(ce, F_ISSUE);
spin_unlock_irqrestore(&mdla_get_device(core_id)->hw_lock, flags);
return 0;
}
static int mdla_plat_process_command_no_lock(u32 core_id, struct command_entry *ce)
{
dma_addr_t addr;
u32 evt_id, count;
addr = ce->mva + ((dma_addr_t)ce->fin_cid) * MREG_CMD_SIZE;
count = ce->count - ce->fin_cid;
evt_id = ce->csn;
mdla_verbose("%s: mdla-%x: fin_cid:%d\n", __func__, core_id, ce->fin_cid);
ce->state = CE_RUN;
mdla_plat_raw_process_command(core_id, evt_id, addr, count);
ce_func_trace(ce, F_ISSUE);
return 0;
}
static void mdla_plat_dump_reg(u32 core_id, struct seq_file *s)
{
int i;
dump_reg_cfg(core_id, MDLA_CG_CON);
dump_reg_cfg(core_id, MDLA_SW_RST);
dump_reg_cfg(core_id, MDLA_MBIST_MODE0);
dump_reg_cfg(core_id, MDLA_MBIST_MODE1);
dump_reg_cfg(core_id, MDLA_MBIST_CTL);
dump_reg_cfg(core_id, MDLA_MBIST_DEFAULT_DELSEL);
dump_reg_cfg(core_id, MDLA_RP_RST);
dump_reg_cfg(core_id, MDLA_RP_CON);
dump_reg_cfg(core_id, MDLA_AXI_CTRL);
dump_reg_cfg(core_id, MDLA_AXI1_CTRL);
dump_reg_top(core_id, MREG_TOP_G_REV);
dump_reg_top(core_id, MREG_TOP_G_INTP0);
dump_reg_top(core_id, MREG_TOP_G_INTP1);
dump_reg_top(core_id, MREG_TOP_G_INTP2);
dump_reg_top(core_id, MREG_TOP_G_CDMA0);
dump_reg_top(core_id, MREG_TOP_G_CDMA1);
dump_reg_top(core_id, MREG_TOP_G_CDMA2);
dump_reg_top(core_id, MREG_TOP_G_CDMA3);
dump_reg_top(core_id, MREG_TOP_G_CDMA4);
dump_reg_top(core_id, MREG_TOP_G_CDMA5);
dump_reg_top(core_id, MREG_TOP_G_CDMA6);
dump_reg_top(core_id, MREG_TOP_G_CUR0);
dump_reg_top(core_id, MREG_TOP_G_CUR1);
dump_reg_top(core_id, MREG_TOP_G_FIN0);
dump_reg_top(core_id, MREG_TOP_G_FIN1);
dump_reg_top(core_id, MREG_TOP_G_FIN3);
dump_reg_top(core_id, MREG_TOP_G_IDLE);
dump_reg_top(core_id, MREG_TOP_G_MDLA_HWSYNC1);
dump_reg_top(core_id, MREG_TOP_G_MDLA_HWSYNC2);
dump_reg_top(core_id, MREG_TOP_G_MDLA_HWSYNC3);
dump_reg_top(core_id, MREG_TOP_G_DBG_CMDE28);
dump_reg_top(core_id, MREG_TOP_G_DBG_CMDE29);
for (i = 0x000; i < 0x1000; i = i + 0x004)
mdla_timeout_debug("apu_mdla_cmde_mreg_top+%.4x: %.8x\n",
i, mdla_util_io_ops_get()->cmde.read(core_id, i));
}
static void mdla_plat_memory_show(struct seq_file *s)
{
struct mdla_dev *mdla_device;
int i;
u32 core_id;
u32 *cmd_addr;
seq_puts(s, "------- dump MDLA code buf -------\n");
for_each_mdla_core(core_id) {
mdla_device = mdla_get_device(core_id);
if (mdla_device->cmd_buf_len == 0)
continue;
seq_printf(s, "mdla %d code buf:\n", mdla_device->mdla_id);
mutex_lock(&mdla_device->cmd_buf_dmp_lock);
cmd_addr = mdla_device->cmd_buf_dmp;
for (i = 0; i < (mdla_device->cmd_buf_len/4); i++)
seq_printf(s, "count: %d, offset: %.8x, val: %.8x\n",
(i * 4) / MREG_CMD_SIZE,
(i * 4) % MREG_CMD_SIZE,
cmd_addr[i]);
mutex_unlock(&mdla_device->cmd_buf_dmp_lock);
}
}
static bool mdla_plat_dbgfs_u64_enable(int node)
{
return node >= 0 && node < NF_MDLA_DEBUG_FS_U64
? mdla_dbgfs_u64_create[node] : false;
}
static bool mdla_plat_dbgfs_u32_enable(int node)
{
return node >= 0 && node < NF_MDLA_DEBUG_FS_U32
? mdla_dbgfs_u32_create[node] : false;
}
static int mdla_plat_register_show(struct seq_file *s, void *data)
{
mdla_v2_0_pmu_info_show(s);
return 0;
}
static int mdla_plat_dbgfs_usage(struct seq_file *s, void *data)
{
seq_printf(s, "---- Kernel debug log maks (current = 0x%x) ----\n",
mdla_dbg_read_u32(FS_KLOG));
seq_printf(s, "echo [mask(hex)] > /d/mdla/%s\n",
mdla_dbg_get_u32_node_str(FS_KLOG));
mdla_dbg_show_klog_info(s, "\t");
seq_puts(s, "\n---- Dump MDLA HW register ----\n");
seq_printf(s, "cat /d/mdla/%s\n", DBGFS_HW_REG_NAME);
seq_puts(s, "\n---- Dump the last code buffer ----\n");
seq_printf(s, "echo [1|0] > /d/mdla/%s\n",
mdla_dbg_get_u32_node_str(FS_DUMP_CMDBUF));
seq_printf(s, "cat /proc/mdla/%s\n", DBGFS_CMDBUF_NAME);
seq_puts(s, "\n---- Command timeout setting ----\n");
seq_printf(s, "echo [ms(dec)] > /d/mdla/%s\n",
mdla_dbg_get_u32_node_str(FS_TIMEOUT));
seq_puts(s, "\n---- Set delay time of power off (default = 2s) ----\n");
seq_printf(s, "echo [ms(dec)] > /d/mdla/%s\n",
mdla_dbg_get_u32_node_str(FS_POWEROFF_TIME));
seq_puts(s, "\n---- Show power usage ----\n");
seq_printf(s, "cat /d/mdla/%s\n", DBGFS_PWR_NAME);
seq_puts(s, "\n---- Show profile usage----\n");
seq_printf(s, "cat /d/mdla/%s\n", DBGFS_PROF_NAME_V2);
seq_puts(s, "\n---- Dump PMU data ----\n");
seq_printf(s, "cat /d/mdla/%s\n", DBGFS_PMU_NAME);
seq_puts(s, "\n");
return 0;
}
static void mdla_plat_dbgfs_init(struct device *dev, struct dentry *parent)
{
if (!dev || !parent)
return;
debugfs_create_devm_seqfile(dev, DBGFS_PMU_NAME, parent,
mdla_plat_register_show);
debugfs_create_devm_seqfile(dev, DBGFS_USAGE_NAME, parent,
mdla_plat_dbgfs_usage);
}
static int mdla_plat_get_base_addr(struct platform_device *pdev, void **reg, int num)
{
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, num);
if (!res) {
dev_info(&pdev->dev, "invalid address (num = %d)\n", num);
return -ENODEV;
}
*reg = ioremap_nocache(res->start, res->end - res->start + 1);
if (*reg == 0) {
dev_info(&pdev->dev,
"could not allocate iomem (num = %d)\n", num);
return -EIO;
}
dev_info(&pdev->dev,
"IORESOURCE_MEM (num = %d) at 0x%08lx mapped to 0x%08lx\n",
num,
(unsigned long __force)res->start,
(unsigned long __force)res->end);
return 0;
}
static int mdla_dts_map(struct platform_device *pdev)
{
int i, mdla_idx;
struct device *dev = &pdev->dev;
u32 nr_core_ids = mdla_util_get_core_num();
dev_info(dev, "Device Tree Probing\n");
mdla_reg_control = kcalloc(nr_core_ids, sizeof(struct mdla_reg_ctl), GFP_KERNEL);
if (!mdla_reg_control)
return -1;
mdla_idx = 0;
for (i = mdla_idx; i < nr_core_ids; i++) {
if (mdla_plat_get_base_addr(pdev,
&mdla_reg_control[i].apu_mdla_config_top,
3 * i))
goto err;
if (mdla_plat_get_base_addr(pdev,
&mdla_reg_control[i].apu_mdla_cmde_mreg_top,
3 * i + 1)) {
iounmap(mdla_reg_control[i].apu_mdla_config_top);
goto err;
}
if (mdla_plat_get_base_addr(pdev,
&mdla_reg_control[i].apu_mdla_biu_top,
3 * i + 2)) {
iounmap(mdla_reg_control[i].apu_mdla_cmde_mreg_top);
iounmap(mdla_reg_control[i].apu_mdla_config_top);
goto err;
}
}
if (mdla_v2_0_irq_request(dev, nr_core_ids))
goto err;
return 0;
err:
for (i = i - 1; i >= mdla_idx; i--) {
iounmap(mdla_reg_control[i].apu_mdla_config_top);
iounmap(mdla_reg_control[i].apu_mdla_cmde_mreg_top);
iounmap(mdla_reg_control[i].apu_mdla_biu_top);
}
kfree(mdla_reg_control);
return -1;
}
static void mdla_dts_unmap(struct platform_device *pdev)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
mdla_v2_0_irq_release(&pdev->dev);
for (i = 0; i < nr_core_ids; i++) {
iounmap(mdla_reg_control[i].apu_mdla_config_top);
iounmap(mdla_reg_control[i].apu_mdla_cmde_mreg_top);
iounmap(mdla_reg_control[i].apu_mdla_biu_top);
}
kfree(mdla_reg_control);
}
static int mdla_sw_multi_devices_init(struct device *dev)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
mdla_plat_devices = devm_kzalloc(dev, nr_core_ids * sizeof(struct mdla_dev), GFP_KERNEL);
if (!mdla_plat_devices)
return -1;
mdla_set_device(mdla_plat_devices, nr_core_ids);
for (i = 0; i < nr_core_ids; i++) {
mdla_plat_devices[i].mdla_id = i;
mdla_plat_devices[i].dev = dev;
mdla_plat_devices[i].cmd_buf_dmp = NULL;
mdla_plat_devices[i].cmd_buf_len = 0;
INIT_LIST_HEAD(&mdla_plat_devices[i].cmd_list);
init_completion(&mdla_plat_devices[i].command_done);
spin_lock_init(&mdla_plat_devices[i].hw_lock);
lockdep_set_class(&mdla_plat_devices[i].hw_lock,
&hw_lock_key[i]);
spin_lock_init(&mdla_plat_devices[i].stat_lock);
lockdep_set_class(&mdla_plat_devices[i].stat_lock,
&stat_lock_key[i]);
mutex_init(&mdla_plat_devices[i].cmd_lock);
mutex_init(&mdla_plat_devices[i].cmd_list_lock);
mutex_init(&mdla_plat_devices[i].cmd_buf_dmp_lock);
mdla_v2_0_pmu_init(&mdla_plat_devices[i]);
}
return 0;
}
static void mdla_sw_multi_devices_deinit(void)
{
int i;
u32 nr_core_ids = mdla_util_get_core_num();
mdla_set_device(NULL, 0);
for (i = 0; i < nr_core_ids; i++) {
mdla_v2_0_pmu_deinit(&mdla_plat_devices[i]);
/* TODO: Need to kill completion and wait it finished ? */
mutex_destroy(&mdla_plat_devices[i].cmd_lock);
mutex_destroy(&mdla_plat_devices[i].cmd_list_lock);
mutex_destroy(&mdla_plat_devices[i].cmd_buf_dmp_lock);
}
}
static void mdla_v2_0_reset(u32 core_id, const char *str)
{
unsigned long flags;
const struct mdla_util_io_ops *io = mdla_util_io_ops_get();
struct mdla_dev *dev = mdla_get_device(core_id);
if (unlikely(!dev)) {
mdla_err("%s(): No mdla device (%d)\n", __func__, core_id);
return;
}
/* use power down==>power on apis insted bus protect init */
mdla_pwr_debug("%s: MDLA RESET: %s\n", __func__,
str);
spin_lock_irqsave(&dev->hw_lock, flags);
io->cfg.write(core_id, MDLA_CG_CLR, 0xffffffff);
io->cmde.write(core_id, MREG_TOP_G_INTP2, MDLA_IRQ_MASK & ~(INTR_SUPPORT_MASK));
/* for DCM and CG */
io->cmde.write(core_id, MREG_TOP_ENG0, mdla_dbg_read_u32(FS_CFG_ENG0));
io->cmde.write(core_id, MREG_TOP_ENG1, mdla_dbg_read_u32(FS_CFG_ENG1));
io->cmde.write(core_id, MREG_TOP_ENG2, mdla_dbg_read_u32(FS_CFG_ENG2));
io->cmde.write(core_id, MREG_TOP_ENG11, mdla_dbg_read_u32(FS_CFG_ENG11));
if (mdla_plat_iommu_enable()) {
io->cfg.set_b(core_id, MDLA_AXI_CTRL, MDLA_AXI_CTRL_MASK);
io->cfg.set_b(core_id, MDLA_AXI1_CTRL, MDLA_AXI_CTRL_MASK);
}
spin_unlock_irqrestore(&dev->hw_lock, flags);
mdla_trace_reset(core_id, str);
}
/* platform public functions */
int mdla_v2_0_init(struct platform_device *pdev)
{
struct mdla_cmd_cb_func *cmd_cb = mdla_cmd_plat_cb();
struct mdla_dbg_cb_func *dbg_cb = mdla_dbg_plat_cb();
dev_info(&pdev->dev, "%s()\n", __func__);
if (mdla_sw_multi_devices_init(&pdev->dev))
return -1;
if (mdla_dts_map(pdev))
goto err;
if (mdla_plat_pwr_drv_ready()) {
if (mdla_pwr_device_register(pdev, mdla_pwr_on_v2_0, mdla_pwr_off_v2_0))
goto err_pwr;
}
mdla_pwr_reset_setup(mdla_v2_0_reset);
if (mdla_v2_0_sched_init())
goto err_sched;
/* set command strategy */
if (mdla_plat_hw_preemption_support())
mdla_cmd_setup(mdla_cmd_run_sync_v2_0_hw_sched, NULL);
else if (mdla_plat_sw_preemption_support())
mdla_cmd_setup(mdla_cmd_run_sync_v2_0_sw_sched, NULL);
else
mdla_cmd_setup(mdla_cmd_run_sync_v2_0, NULL);
/* set command callback */
cmd_cb->post_cmd_info = mdla_plat_print_post_cmd_info;
cmd_cb->get_irq_num = mdla_v2_0_get_irq_num;
cmd_cb->get_wait_time = mdla_plat_get_wait_time;
cmd_cb->check_cmd_valid = mdla_check_cmd_valid;
if (mdla_plat_sw_preemption_support()) {
cmd_cb->pre_cmd_handle = mdla_plat_pre_cmd_handle_sw_sched;
cmd_cb->post_cmd_handle = mdla_plat_post_cmd_handle_sched;
cmd_cb->wait_cmd_handle = mdla_plat_wait_cmd_handle;
cmd_cb->process_command = mdla_plat_process_command_in_batch;
cmd_cb->process_command_no_lock = mdla_plat_process_command_in_batch_no_lock;
} else if (mdla_plat_hw_preemption_support()) {
cmd_cb->pre_cmd_handle = mdla_plat_pre_cmd_handle;
cmd_cb->post_cmd_handle = mdla_plat_post_cmd_handle_sched;
cmd_cb->process_command = mdla_plat_process_command;
cmd_cb->process_command_no_lock = mdla_plat_process_command_no_lock;
} else {
cmd_cb->pre_cmd_handle = mdla_plat_pre_cmd_handle;
cmd_cb->post_cmd_handle = mdla_plat_post_cmd_handle;
cmd_cb->process_command = mdla_plat_process_command;
cmd_cb->process_command_no_lock = mdla_plat_process_command_no_lock;
}
/* set debug callback */
dbg_cb->destroy_dump_cmdbuf = mdla_plat_destroy_dump_cmdbuf;
dbg_cb->create_dump_cmdbuf = mdla_plat_create_dump_cmdbuf;
dbg_cb->dump_reg = mdla_plat_dump_reg;
dbg_cb->memory_show = mdla_plat_memory_show;
dbg_cb->dbgfs_u64_enable = mdla_plat_dbgfs_u64_enable;
dbg_cb->dbgfs_u32_enable = mdla_plat_dbgfs_u32_enable;
dbg_cb->dbgfs_plat_init = mdla_plat_dbgfs_init;
/* set base address */
mdla_util_io_set_addr(mdla_reg_control);
return 0;
err_sched:
if (mdla_plat_pwr_drv_ready())
mdla_pwr_device_unregister(pdev);
err_pwr:
dev_info(&pdev->dev, "register mdla power fail\n");
mdla_dts_unmap(pdev);
err:
mdla_sw_multi_devices_deinit();
return -1;
}
void mdla_v2_0_deinit(struct platform_device *pdev)
{
int i;
dev_info(&pdev->dev, "%s()\n", __func__);
mdla_v2_0_sched_deinit();
for_each_mdla_core(i) {
mdla_pwr_ops_get()->off(i, 0, true);
mdla_plat_destroy_dump_cmdbuf(&mdla_plat_devices[i]);
}
if (mdla_plat_pwr_drv_ready()
&& mdla_pwr_device_unregister(pdev))
dev_info(&pdev->dev, "unregister mdla power fail\n");
mdla_dts_unmap(pdev);
mdla_sw_multi_devices_deinit();
}
@@ -0,0 +1,339 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/fs.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <utilities/mdla_util.h>
#include <utilities/mdla_debug.h>
#include <utilities/mdla_profile.h>
#include "apusys_dbg.h"
static struct dentry *mdla_dbg_root;
static struct proc_dir_entry *mdla_procfs_dir;
static u32 ip_ver;
struct mdla_dbgfs_file {
union {
u64 u64_var;
u32 u32_var;
};
umode_t mode;
char hex;
char *str;
};
static struct mdla_dbgfs_file ull_dbgfs_file[NF_MDLA_DEBUG_FS_U64 + 1] = {
[FS_CFG_PMU_PERIOD] = { .mode = 0660, .str = "period"},
[NF_MDLA_DEBUG_FS_U64] = { .str = "unknown"},
};
static struct mdla_dbgfs_file u_dbgfs_file[NF_MDLA_DEBUG_FS_U32 + 1] = {
[FS_C1] = { .mode = 0660, .hex = 1, .str = "c1"},
[FS_C2] = { .mode = 0660, .hex = 1, .str = "c2"},
[FS_C3] = { .mode = 0660, .hex = 1, .str = "c3"},
[FS_C4] = { .mode = 0660, .hex = 1, .str = "c4"},
[FS_C5] = { .mode = 0660, .hex = 1, .str = "c5"},
[FS_C6] = { .mode = 0660, .hex = 1, .str = "c6"},
[FS_C7] = { .mode = 0660, .hex = 1, .str = "c7"},
[FS_C8] = { .mode = 0660, .hex = 1, .str = "c8"},
[FS_C9] = { .mode = 0660, .hex = 1, .str = "c9"},
[FS_C10] = { .mode = 0660, .hex = 1, .str = "c10"},
[FS_C11] = { .mode = 0660, .hex = 1, .str = "c11"},
[FS_C12] = { .mode = 0660, .hex = 1, .str = "c12"},
[FS_C13] = { .mode = 0660, .hex = 1, .str = "c13"},
[FS_C14] = { .mode = 0660, .hex = 1, .str = "c14"},
[FS_C15] = { .mode = 0660, .hex = 1, .str = "c15"},
[FS_CFG_ENG0] = { .mode = 0660, .hex = 1, .str = "eng0"},
[FS_CFG_ENG1] = { .mode = 0660, .hex = 1, .str = "eng1"},
[FS_CFG_ENG2] = { .mode = 0660, .hex = 1, .str = "eng2"},
[FS_CFG_ENG11] = { .mode = 0660, .hex = 1, .str = "eng11"},
[FS_POLLING_CMD_DONE] = { .mode = 0660, .str = "polling_cmd_period"},
[FS_DUMP_CMDBUF] = { .mode = 0660, .str = "dump_cmdbuf_en"},
[FS_DVFS_RAND] = { .mode = 0660, .str = "dvfs_rand"},
[FS_PMU_EVT_BY_APU] = { .mode = 0660, .str = "pmu_evt_by_apusys"},
[FS_KLOG] = { .mode = 0660, .hex = 1, .str = "klog"},
[FS_POWEROFF_TIME] = { .mode = 0660, .str = "poweroff_time"},
[FS_TIMEOUT] = { .mode = 0660, .str = "timeout"},
[FS_TIMEOUT_DBG] = { .mode = 0660, .str = "timeout_dbg"},
[FS_BATCH_NUM] = { .mode = 0660, .str = "batch_number"},
[FS_PREEMPTION_TIMES] = { .mode = 0660, .str = "preemption_times"},
[FS_PREEMPTION_DBG] = { .mode = 0660, .str = "preemption_debug"},
[NF_MDLA_DEBUG_FS_U32] = { .str = "unknown"},
};
static const char *reason_str[REASON_MAX+1] = {
"others",
"driver_init",
"command_timeout",
"power_on",
"preemption",
"simulator",
"-"
};
const char *mdla_dbg_get_reason_str(int res)
{
if ((res < 0) || (res > REASON_MAX))
res = REASON_MAX;
return reason_str[res];
}
const char *mdla_dbg_get_u64_node_str(int node)
{
if (unlikely(node < 0 || node > NF_MDLA_DEBUG_FS_U64))
node = NF_MDLA_DEBUG_FS_U64;
return ull_dbgfs_file[node].str;
}
const char *mdla_dbg_get_u32_node_str(int node)
{
if (unlikely(node < 0 || node > NF_MDLA_DEBUG_FS_U32))
node = NF_MDLA_DEBUG_FS_U32;
return u_dbgfs_file[node].str;
}
static void mdla_dbg_dummy_destroy(struct mdla_dev *a0) {}
static int mdla_dbg_dummy_create(struct mdla_dev *a0, struct command_entry *a1)
{
return -1;
}
static void mdla_dbg_dummy_dump(u32 core_id, struct seq_file *s) {}
static void mdla_dbg_dummy_mem_show(struct seq_file *s) {}
static bool mdla_dbg_dummy_enable(int node)
{
return false;
}
static void mdla_dbg_dummy_init(struct device *dev, struct dentry *parent) {}
static struct mdla_dbg_cb_func mdla_debug_callback = {
.destroy_dump_cmdbuf = mdla_dbg_dummy_destroy,
.create_dump_cmdbuf = mdla_dbg_dummy_create,
.dump_reg = mdla_dbg_dummy_dump,
.memory_show = mdla_dbg_dummy_mem_show,
.dbgfs_u64_enable = mdla_dbg_dummy_enable,
.dbgfs_u32_enable = mdla_dbg_dummy_enable,
.dbgfs_plat_init = mdla_dbg_dummy_init,
};
struct mdla_dbg_cb_func *mdla_dbg_plat_cb(void)
{
return &mdla_debug_callback;
}
void mdla_dbg_set_version(u32 ver)
{
ip_ver = ver;
}
void mdla_dbg_write_u64(int node, u64 val)
{
if (likely(node >= 0 && node < NF_MDLA_DEBUG_FS_U64))
ull_dbgfs_file[node].u64_var = val;
}
void mdla_dbg_write_u32(int node, u32 val)
{
if (likely(node >= 0 && node < NF_MDLA_DEBUG_FS_U32))
u_dbgfs_file[node].u32_var = val;
}
u64 mdla_dbg_read_u64(int node)
{
if (likely(node >= 0 && node < NF_MDLA_DEBUG_FS_U64))
return ull_dbgfs_file[node].u64_var;
return ~0;
}
u32 mdla_dbg_read_u32(int node)
{
if (likely(node >= 0 && node < NF_MDLA_DEBUG_FS_U32))
return u_dbgfs_file[node].u32_var;
return ~0;
}
void mdla_dbg_sub_u64(int node, u64 val)
{
if (likely(node >= 0 && node < NF_MDLA_DEBUG_FS_U64))
ull_dbgfs_file[node].u64_var -= val;
}
void mdla_dbg_sub_u32(int node, u32 val)
{
if (likely(node >= 0 && node < NF_MDLA_DEBUG_FS_U32))
u_dbgfs_file[node].u32_var -= val;
}
void mdla_dbg_add_u64(int node, u64 val)
{
if (likely(node >= 0 && node < NF_MDLA_DEBUG_FS_U64))
ull_dbgfs_file[node].u64_var += val;
}
void mdla_dbg_add_u32(int node, u32 val)
{
if (likely(node >= 0 && node < NF_MDLA_DEBUG_FS_U32))
u_dbgfs_file[node].u32_var += val;
}
void mdla_dbg_dump(struct mdla_dev *mdla_info, struct command_entry *ce)
{
mdla_debug_callback.dump_reg(mdla_info->mdla_id, NULL);
mdla_debug_callback.create_dump_cmdbuf(mdla_info, ce);
apusys_reg_dump();
mdla_aee_warn("MDLA", "MDLA timeout");
}
void mdla_dbg_ce_info(u32 core_id, struct command_entry *ce)
{
mdla_timeout_debug("core_id: %x, ce(%x) IRQ status: %x, footprint: %llx\n",
core_id,
ce->priority,
ce->irq_state,
ce->footprint);
mdla_timeout_debug("core_id: %x, ce(%x): total cmd count: %u, mva: %x",
core_id,
ce->priority,
ce->count,
ce->mva);
mdla_timeout_debug("core_id: %x, ce(%x): fin_cid: %u, ce state: %x\n",
core_id,
ce->priority,
ce->fin_cid, ce->state);
mdla_timeout_debug("core_id: %x, ce(%x): wish fin_cid: %u, dual: %d\n",
core_id,
ce->priority,
ce->wish_fin_cid,
ce->multicore_total);
mdla_timeout_debug("core_id: %x, ce(%x): batch size = %u\n",
core_id,
ce->priority,
ce->cmd_batch_size);
}
static int mdla_dbg_register_show(struct seq_file *s, void *data)
{
int i;
for_each_mdla_core(i)
mdla_debug_callback.dump_reg(i, s);
return 0;
}
static int mdla_dbg_mdla_memory_show(struct seq_file *s, void *data)
{
mdla_debug_callback.memory_show(s);
return 0;
}
PROC_FOPS_RO_MDLA(mdla_memory);
void mdla_dbg_show_klog_info(struct seq_file *s, char *prefix)
{
seq_printf(s, "%s bit0 = MDLA_DBG_DRV\n", prefix);
seq_printf(s, "%s bit1 = MDLA_DBG_MEM\n", prefix);
seq_printf(s, "%s bit2 = MDLA_DBG_CMD\n", prefix);
seq_printf(s, "%s bit3 = MDLA_DBG_PMU\n", prefix);
seq_printf(s, "%s bit4 = MDLA_DBG_PERF\n", prefix);
seq_printf(s, "%s bit5 = MDLA_DBG_PWR\n", prefix);
seq_printf(s, "%s bit6 = MDLA_DBG_TIMEOUT\n", prefix);
seq_printf(s, "%s bit7 = MDLA_DBG_RSV\n", prefix);
seq_printf(s, "%s set 0xff -> enable verbose log\n", prefix);
}
struct dentry *mdla_dbg_get_fs_root(void)
{
return mdla_dbg_root;
}
struct proc_dir_entry *mdla_dbg_get_procfs_dir(void)
{
return mdla_procfs_dir;
}
static void mdla_procfs_init(void)
{
mdla_procfs_dir = proc_mkdir("mdla", NULL);
if (IS_ERR_OR_NULL(mdla_procfs_dir)) {
mdla_err("fail to create /proc/mdla @ %s()\n", __func__);
return;
}
PROC_CREATE_RO_MDLA(mdla_procfs_dir, mdla_memory);
}
void mdla_dbg_fs_setup(struct device *dev)
{
struct mdla_dbgfs_file *file;
int i;
if (!dev) {
mdla_err("%s(): Fail. No device!\n", __func__);
return;
}
if (!mdla_dbg_root) {
mdla_err("%s(): dentry NOT ready\n", __func__);
return;
}
for (i = 0; i < NF_MDLA_DEBUG_FS_U64; i++) {
if (mdla_debug_callback.dbgfs_u64_enable(i)) {
file = &ull_dbgfs_file[i];
debugfs_create_u64(file->str, file->mode,
mdla_dbg_root, &file->u64_var);
}
}
for (i = 0; i < NF_MDLA_DEBUG_FS_U32; i++) {
if (mdla_debug_callback.dbgfs_u32_enable(i)) {
file = &u_dbgfs_file[i];
if (file->hex)
debugfs_create_x32(file->str, file->mode,
mdla_dbg_root, &file->u32_var);
else
debugfs_create_u32(file->str, file->mode,
mdla_dbg_root, &file->u32_var);
}
}
debugfs_create_devm_seqfile(dev, DBGFS_HW_REG_NAME,
mdla_dbg_root,
mdla_dbg_register_show);
mdla_procfs_init();
/* Platform debug node */
mdla_debug_callback.dbgfs_plat_init(dev, mdla_dbg_root);
}
void mdla_dbg_fs_init(struct dentry *droot)
{
mdla_dbg_root = debugfs_create_dir("mdla", droot);
if (IS_ERR_OR_NULL(mdla_dbg_root)) {
mdla_err("%s: failed to create mdla debugfs\n", __func__);
return;
}
/* AP&uP common node */
debugfs_create_x32("version", 0440, mdla_dbg_root, &ip_ver);
}
void mdla_dbg_fs_exit(void)
{
debugfs_remove_recursive(mdla_dbg_root);
if (mdla_procfs_dir)
proc_remove(mdla_procfs_dir);
}
Loaded 100 of 80519 files, more files were not shown because too many files have changed in this diff. Show more