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

@@ -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