blob: cd5bc8563681a50915207b381b90d3735be39e7e [file] [log] [blame]
/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* IPs Traffic Monitor(ITMON) Driver for Samsung Exynos8895 SOC
* By Hosung Kim (hosung0.kim@samsung.com)
*
* 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.
*/
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/bitops.h>
#include <linux/of_irq.h>
#include <soc/samsung/exynos-itmon.h>
#define OFFSET_TMOUT_REG (0x2000)
#define OFFSET_REQ_R (0x0)
#define OFFSET_REQ_W (0x20)
#define OFFSET_RESP_R (0x40)
#define OFFSET_RESP_W (0x60)
#define OFFSET_ERR_REPT (0x20)
#define OFFSET_NUM (0x4)
#define REG_INT_MASK (0x0)
#define REG_INT_CLR (0x4)
#define REG_INT_INFO (0x8)
#define REG_EXT_INFO_0 (0x10)
#define REG_EXT_INFO_1 (0x14)
#define REG_EXT_INFO_2 (0x18)
#define REG_DBG_CTL (0x10)
#define REG_TMOUT_INIT_VAL (0x14)
#define REG_TMOUT_FRZ_EN (0x18)
#define REG_TMOUT_BUF_WR_OFFSET (0x10)
#define REG_TMOUT_BUF_RD_ADDR (0x20)
#define REG_TMOUT_BUF_RD_ID (0x24)
#define REG_TMOUT_BUF_RD_PAYLOAD (0x28)
#define REG_TMOUT_BUF_WR_ADDR (0x30)
#define REG_TMOUT_BUF_WR_ID (0x34)
#define REG_TMOUT_BUF_WR_PAYLOAD (0x38)
#define BIT_ERR_CODE(x) (((x) & (0xF << 28)) >> 28)
#define BIT_ERR_OCCURRED(x) (((x) & (0x1 << 27)) >> 27)
#define BIT_ERR_VALID(x) (((x) & (0x1 << 26)) >> 26)
#define BIT_AXID(x) (((x) & (0xFFFF)))
#define BIT_AXUSER(x) (((x) & (0xFFFF << 16)) >> 16)
#define BIT_AXBURST(x) (((x) & (0x3)))
#define BIT_AXPROT(x) (((x) & (0x3 << 2)) >> 2)
#define BIT_AXLEN(x) (((x) & (0xF << 16)) >> 16)
#define BIT_AXSIZE(x) (((x) & (0x7 << 28)) >> 28)
#define M_NODE (0)
#define T_S_NODE (1)
#define T_M_NODE (2)
#define S_NODE (3)
#define NODE_TYPE (4)
#define ERRCODE_SLVERR (0)
#define ERRCODE_DECERR (1)
#define ERRCODE_UNSUPORTED (2)
#define ERRCODE_POWER_DOWN (3)
#define ERRCODE_UNKNOWN_4 (4)
#define ERRCODE_UNKNOWN_5 (5)
#define ERRCODE_TMOUT (6)
#define BUS_DATA (0)
#define BUS_PERI (1)
#define BUS_PATH_TYPE (2)
#define TRANS_TYPE_WRITE (0)
#define TRANS_TYPE_READ (1)
#define TRANS_TYPE_NUM (2)
#define FROM_CP (0)
#define FROM_CPU (1)
#define FROM_CPU_MAY (2)
#define FROM_M_NODE (3)
#define TMOUT (0xFFFFF)
#define TMOUT_TEST (0x1)
#define PANIC_ALLOWED_THRESHOLD (0x2)
#define INVALID_REMAPPING (0x08000000)
static bool initial_multi_irq_enable = false;
static struct itmon_dev *g_itmon = NULL;
struct itmon_rpathinfo {
unsigned int id;
char *port_name;
char *dest_name;
unsigned int bits;
unsigned int shift_bits;
};
struct itmon_masterinfo {
char *port_name;
unsigned int user;
char *master_name;
unsigned int bits;
};
struct itmon_nodegroup;
struct itmon_traceinfo {
char* port;
char* master;
char* dest;
unsigned long target_addr;
unsigned int errcode;
bool read;
bool path_dirty;
bool trans_dirty;
bool dirty;
unsigned long from;
char buf[SZ_32];
};
struct itmon_tracedata {
unsigned int int_info;
unsigned int ext_info_0;
unsigned int ext_info_1;
unsigned int ext_info_2;
unsigned int offset;
bool logging;
bool read;
};
struct itmon_nodeinfo {
unsigned int type;
char *name;
unsigned int phy_regs;
void __iomem *regs;
unsigned int time_val;
bool tmout_enabled;
bool tmout_frz_enabled;
bool err_enabled;
bool retention;
struct itmon_tracedata tracedata;
struct itmon_nodegroup *group;
struct list_head list;
};
const static char *itmon_pathtype[] = {
"DATA Path transaction (0x2000_0000 ~ 0xf_ffff_ffff)",
"PERI(SFR) Path transaction (0x0 ~ 0x1fff_ffff)",
};
/* Error Code Description */
const static char *itmon_errcode[] = {
"Error Detect by the Slave(SLVERR)",
"Decode error(DECERR)",
"Unsupported transaction error",
"Power Down access error",
"Unsupported transaction",
"Unsupported transaction",
"Timeout error - response timeout in timeout value",
"Invalid errorcode",
};
const static char *itmon_nodestring[] = {
"M_NODE",
"TAXI_S_NODE",
"TAXI_M_NODE",
"S_NODE",
};
struct itmon_nodegroup {
int irq;
char *name;
unsigned int phy_regs;
void __iomem *regs;
struct itmon_nodeinfo *nodeinfo;
unsigned int nodesize;
unsigned int bus_type;
};
struct itmon_platdata {
const struct itmon_rpathinfo *rpathinfo;
const struct itmon_masterinfo *masterinfo;
struct itmon_nodegroup *nodegroup;
struct itmon_traceinfo traceinfo[BUS_PATH_TYPE];
struct list_head tracelist[BUS_PATH_TYPE];
unsigned int err_cnt;
bool panic_allowed;
bool probed;
};
const static struct itmon_rpathinfo rpathinfo[] = {
/* Target Address = 0x2000_0000 ~ 0xf_ffff_ffff */
{0, "DPU0", "DREX", GENMASK(5, 0), 0},
{1, "DPU1", "DREX", GENMASK(5, 0), 0},
{2, "DPU2", "DREX", GENMASK(5, 0), 0},
{3, "CAM0", "DREX", GENMASK(5, 0), 0},
{4, "CAM1", "DREX", GENMASK(5, 0), 0},
{5, "ISPLP", "DREX", GENMASK(5, 0), 0},
{6, "SRDZ", "DREX", GENMASK(5, 0), 0},
{7, "IVA", "DREX", GENMASK(5, 0), 0},
{8, "DSP", "DREX", GENMASK(5, 0), 0},
{9, "VPU", "DREX", GENMASK(5, 0), 0},
{10, "MFC0", "DREX", GENMASK(5, 0), 0},
{11, "MFC1", "DREX", GENMASK(5, 0), 0},
{12, "G2D0", "DREX", GENMASK(5, 0), 0},
{13, "G2D1", "DREX", GENMASK(5, 0), 0},
{14, "G2D2", "DREX", GENMASK(5, 0), 0},
{15, "VTS", "DREX", GENMASK(5, 0), 0},
{16, "FSYS0", "DREX", GENMASK(5, 0), 0},
{17, "CORESIGHT", "DREX", GENMASK(5, 0), 0},
{18, "PDMA", "DREX", GENMASK(5, 0), 0},
{19, "SPDMA", "DREX", GENMASK(5, 0), 0},
{20, "FSYS1", "DREX", GENMASK(5, 0), 0},
{21, "GNSS", "DREX", GENMASK(5, 0), 0},
{22, "ALIVE", "DREX", GENMASK(5, 0), 0},
{23, "ABOX", "DREX", GENMASK(5, 0), 0},
{24, "DPU0", "DREX", GENMASK(5, 0), 0},
{25, "DPU1", "DREX", GENMASK(5, 0), 0},
{26, "DPU2", "DREX", GENMASK(5, 0), 0},
{27, "CAM0", "DREX", GENMASK(5, 0), 0},
{28, "CAM1", "DREX", GENMASK(5, 0), 0},
{29, "ISPLP", "DREX", GENMASK(5, 0), 0},
{30, "SRDZ", "DREX", GENMASK(5, 0), 0},
{31, "IVA", "DREX", GENMASK(5, 0), 0},
{32, "DSP", "DREX", GENMASK(5, 0), 0},
{33, "VPU", "DREX", GENMASK(5, 0), 0},
{34, "MFC0", "DREX", GENMASK(5, 0), 0},
{35, "MFC1", "DREX", GENMASK(5, 0), 0},
{36, "G2D0", "DREX", GENMASK(5, 0), 0},
{37, "G2D1", "DREX", GENMASK(5, 0), 0},
{38, "G2D2", "DREX", GENMASK(5, 0), 0},
{39, "VTS", "DREX", GENMASK(5, 0), 0},
{40, "FSYS0", "DREX", GENMASK(5, 0), 0},
{41, "CORESIGHT", "DREX", GENMASK(5, 0), 0},
{42, "PDMA", "DREX", GENMASK(5, 0), 0},
{43, "SPDMA", "DREX", GENMASK(5, 0), 0},
{44, "FSYS1", "DREX", GENMASK(5, 0), 0},
{45, "GNSS", "DREX", GENMASK(5, 0), 0},
{46, "ALIVE", "DREX", GENMASK(5, 0), 0},
{47, "ABOX", "DREX", GENMASK(5, 0), 0},
{48, "G3D0", "DREX", GENMASK(5, 0), 0},
{49, "G3D1", "DREX", GENMASK(5, 0), 0},
{50, "G3D2", "DREX", GENMASK(5, 0), 0},
{51, "G3D3", "DREX", GENMASK(5, 0), 0},
{52, "CP", "DREX", GENMASK(5, 0), 0},
/* Target Address = 0x1800_0000 ~ 0x1fff_ffff */
{0, "DPU0", "SP", GENMASK(4, 0), 0},
{1, "DPU1", "SP", GENMASK(4, 0), 0},
{2, "DPU2", "SP", GENMASK(4, 0), 0},
{3, "CAM0", "SP", GENMASK(4, 0), 0},
{4, "CAM1", "SP", GENMASK(4, 0), 0},
{5, "ISPLP", "SP", GENMASK(4, 0), 0},
{6, "SRDZ", "SP", GENMASK(4, 0), 0},
{7, "IVA", "SP", GENMASK(4, 0), 0},
{8, "DSP", "SP", GENMASK(4, 0), 0},
{9, "VPU", "SP", GENMASK(4, 0), 0},
{10, "MFC0", "SP", GENMASK(4, 0), 0},
{11, "MFC1", "SP", GENMASK(4, 0), 0},
{12, "G2D0", "SP", GENMASK(4, 0), 0},
{13, "G2D1", "SP", GENMASK(4, 0), 0},
{14, "G2D2", "SP", GENMASK(4, 0), 0},
{15, "VTS", "SP", GENMASK(4, 0), 0},
{16, "FSYS0", "SP", GENMASK(4, 0), 0},
{17, "CORESIGHT", "SP", GENMASK(4, 0), 0},
{18, "PDMA", "SP", GENMASK(4, 0), 0},
{19, "SPDMA", "SP", GENMASK(4, 0), 0},
{20, "FSYS1", "SP", GENMASK(4, 0), 0},
{21, "GNSS", "SP", GENMASK(4, 0), 0},
{22, "ALIVE", "SP", GENMASK(4, 0), 0},
{23, "ABOX", "SP", GENMASK(4, 0), 0},
/* Target Address = 0x0000_0000 ~ 0x17ff_ffff */
{0, "DPU0", "PERI", GENMASK(4, 0), 0},
{1, "DPU1", "PERI", GENMASK(4, 0), 0},
{2, "DPU2", "PERI", GENMASK(4, 0), 0},
{3, "CAM0", "PERI", GENMASK(4, 0), 0},
{4, "CAM1", "PERI", GENMASK(4, 0), 0},
{5, "ISPLP", "PERI", GENMASK(4, 0), 0},
{6, "SRDZ", "PERI", GENMASK(4, 0), 0},
{7, "IVA", "PERI", GENMASK(4, 0), 0},
{8, "DSP", "PERI", GENMASK(4, 0), 0},
{9, "VPU", "PERI", GENMASK(4, 0), 0},
{10, "MFC0", "PERI", GENMASK(4, 0), 0},
{11, "MFC1", "PERI", GENMASK(4, 0), 0},
{12, "G2D0", "PERI", GENMASK(4, 0), 0},
{13, "G2D1", "PERI", GENMASK(4, 0), 0},
{14, "G2D2", "PERI", GENMASK(4, 0), 0},
{15, "ABOX", "PERI", GENMASK(4, 0), 0},
{16, "VTS", "PERI", GENMASK(4, 0), 0},
{17, "FSYS0", "PERI", GENMASK(4, 0), 0},
{18, "CORESIGHT", "PERI", GENMASK(4, 0), 0},
{19, "PDMA", "PERI", GENMASK(4, 0), 0},
{20, "SPDMA", "PERI", GENMASK(4, 0), 0},
{21, "FSYS1", "PERI", GENMASK(4, 0), 0},
{22, "GNSS", "PERI", GENMASK(4, 0), 0},
{22, "ALIVE", "PERI", GENMASK(4, 0), 0},
};
const static struct itmon_masterinfo masterinfo[] = {
{"DPU0", 0, /* 0XXXX0 */ "DPP/WBMUX", BIT(5) | BIT(0)},
{"DPU0", BIT(0), /* 0XXXX1 */ "SYSMMU_DPU0", BIT(5) | BIT(0)},
{"DPU1", 0, /* 0XXXX0 */ "DPP/WBMUX", BIT(5) | BIT(0)},
{"DPU1", BIT(0), /* 0XXXX1 */ "SYSMMU_DPU1", BIT(5) | BIT(0)},
{"DPU2", 0, /* 0XXXX0 */ "DPP/WBMUX", BIT(5) | BIT(0)},
{"DPU2", BIT(0), /* 0XXXX1 */ "SYSMMU_DPU2", BIT(5) | BIT(0)},
{"CAM0", 0, /* 0XX000 */ "CSISx4", BIT(5) | GENMASK(2, 0)},
{"CAM0", BIT(1), /* 0XX010 */ "TPU0", BIT(5) | GENMASK(2, 0)},
{"CAM0", BIT(2), /* 0XX100 */ "VRA", BIT(5) | GENMASK(2, 0)},
{"CAM0", GENMASK(2, 1), /* 0XX110 */ "TPU1", BIT(5) | GENMASK(2, 0)},
{"CAM0", BIT(0), /* 0XXXX1 */ "SYSMMU_CAM0", BIT(5) | BIT(0)},
{"CAM1", 0, /* 0XXXX0 */ "MC_SCALER", BIT(5) | BIT(0)},
{"CAM1", BIT(0), /* 0XXXX1 */ "SYSMMU_CAM1", BIT(5) | BIT(0)},
{"ISPLP", 0, /* 0XX000 */ "3AAW", BIT(5) | GENMASK(2, 0)},
{"ISPLP", BIT(1), /* 0XX010 */ "ISPLP", BIT(5) | GENMASK(2, 0)},
{"ISPLP", BIT(2), /* 0XX100 */ "ISPHQ", BIT(5) | GENMASK(2, 0)},
{"ISPLP", BIT(0), /* 0XXXX1 */ "SYSMMU_ISPLP", BIT(5) | BIT(0)},
{"FSYS0", 0, /* 0XXX00 */ "ETR", BIT(5) | GENMASK(1, 0)},
{"FSYS0", BIT(1), /* 0XXX10 */ "USB", BIT(5) | GENMASK(1, 0)},
{"FSYS0", BIT(0), /* 0XXXX1 */ "UFS", BIT(5) | BIT(0)},
{"MFC0", 0, /* 0XXXX0 */ "MFC0", BIT(5) | BIT(0)},
{"MFC0", BIT(0), /* 0XXXX1 */ "SYSMMU_MFC0", BIT(5) | BIT(0)},
{"MFC1", 0, /* 0XXXX0 */ "MFC1", BIT(5) | BIT(0)},
{"MFC1", BIT(0), /* 0XXXX1 */ "SYSMMU_MFC1", BIT(5) | BIT(0)},
{"G2D0", 0, /* 0XXXX0 */ "G2D0", BIT(5) | BIT(0)},
{"G2D0", BIT(0), /* 0XXXX1 */ "SYSMMU_G2D0", BIT(5) | BIT(0)},
{"G2D1", 0, /* 0XXXX0 */ "G2D1", BIT(5) | BIT(0)},
{"G2D1", BIT(0), /* 0XXXX1 */ "SYSMMU_G2D1", BIT(5) | BIT(0)},
{"G2D2", 0, /* 0XXX00 */ "JPEG", BIT(5) | GENMASK(1, 0)},
{"G2D2", BIT(1), /* 0XXX10 */ "M2MSCALER", BIT(5) | GENMASK(1, 0)},
{"G2D2", BIT(0), /* 0XXXX1 */ "SYSMMU_G2D2", BIT(5) | BIT(0)},
{"IVA", 0, /* 0XXX00 */ "DSP0", BIT(5) | GENMASK(1, 0)},
{"IVA", BIT(1), /* 0XXX10 */ "DSP1", BIT(5) | GENMASK(1, 0)},
{"IVA", BIT(0), /* 0XXXX1 */ "SYSMMU_DSP", BIT(5) | BIT(0)},
{"VPU", 0, /* 0XXXX0 */ "VPU", BIT(5) | BIT(0)},
{"VPU", BIT(0), /* 0XXXX1 */ "SYSMMU_VPU", BIT(5) | BIT(0)},
{"FSYS1", 0, /* 0XX000 */ "MMC2", BIT(5) | GENMASK(2, 0)},
{"FSYS1", BIT(0), /* 0XX001 */ "PCIE0", BIT(5) | GENMASK(2, 0)},
{"FSYS1", BIT(1), /* 0XX010 */ "PCIE1", BIT(5) | GENMASK(2, 0)},
{"FSYS1", GENMASK(1, 0), /* 0XX011 */ "SSS", BIT(5) | GENMASK(2, 0)},
{"FSYS1", BIT(2), /* 0XX100 */ "RTIC", BIT(5) | GENMASK(2, 0)},
{"FSYS1", BIT(2) | BIT(0), /* 0XX101 */ "MCOMP", BIT(5) | GENMASK(2, 0)},
{"AUD", 0, /* 0XXXX0 */ "SPUS/SPUM/CA7", BIT(5) | BIT(0)},
{"AUD", BIT(0), /* 0XXXX1 */ "SYSMMU_AUC", BIT(5) | BIT(0)},
{"GNSS", 0, /* 0XXX00 */ "CM0+", BIT(5) | GENMASK(1, 0)},
{"GNSS", BIT(0), /* 0XXX01 */ "XDMA0", BIT(5) | GENMASK(1, 0)},
{"GNSS", BIT(1), /* 0XXX10 */ "XDMA1", BIT(5) | GENMASK(1, 0)},
{"ALIVE", 0, /* 0XXX00 */ "CM3", BIT(5) | GENMASK(1, 0)},
{"ALIVE", BIT(0), /* 0XXX01 */ "SCAN2AXI", BIT(5) | GENMASK(1, 0)},
{"ALIVE", BIT(1), /* 0XXX10 */ "CM4F/DMIC", BIT(5) | GENMASK(1, 0)},
{"CP", BIT(3), /* X01XXX */ "CR7M", GENMASK(4, 3)},
{"CP", BIT(2), /* X001XX */ "CR4MtoL2", GENMASK(4, 2)},
{"CP", GENMASK(4, 3), /* X1100X */ "DMA", GENMASK(4, 1)},
{"CP", GENMASK(4, 3) | BIT(1), /* X1101X */ "MDMtoL2", GENMASK(4, 1)},
{"CP", BIT(4), /* X1000X */ "LMACtoL2", GENMASK(4, 1)},
{"CP", BIT(1), /* X00010 */ "CSXAP", GENMASK(4, 1)},
{"CP", BIT(4) | GENMASK(1, 0), /* X10011 */ "HARQMOVERtoL2", GENMASK(4, 0)},
/* Others */
{"SRDZ", 0, "SRDZ", 0},
{"DSP", 0, "DSP", 0},
{"ABOX", 0, "ABOX", 0},
{"VTS", 0, "VTS", 0},
{"PDMA", 0, "PDMA", 0},
{"SPDMA",0, "SPDMA",0},
};
static struct itmon_nodeinfo data_bus_1[] = {
{M_NODE, "ALIVE", 0x15423000, NULL, 0, false, false, true, false},
{M_NODE, "FSYS1", 0x15403000, NULL, 0, false, false, true, false},
{M_NODE, "GNSS", 0x15413000, NULL, 0, false, false, true, false},
{T_S_NODE, "BUS1_B0", 0x15433000, NULL, TMOUT, true, false, true, false},
};
static struct itmon_nodeinfo data_bus_c[] = {
{M_NODE, "ABOX", 0x15143000, NULL, 0, false, false, true, false},
{T_M_NODE, "BUS1_B0", 0x15003000, NULL, 0, false, false, true, false},
{M_NODE, "CAM0", 0x15043000, NULL, 0, false, false, true, false},
{M_NODE, "CAM1", 0x15053000, NULL, 0, false, false, true, false},
{M_NODE, "CORESIGHT", 0x15113000, NULL, 0, false, false, true, false},
{M_NODE, "DPU0", 0x15013000, NULL, 0, false, false, true, false},
{M_NODE, "DPU1", 0x15023000, NULL, 0, false, false, true, false},
{M_NODE, "DPU2", 0x15033000, NULL, 0, false, false, true, false},
{M_NODE, "DSP", 0x15093000, NULL, 0, false, false, true, false},
{M_NODE, "FSYS0", 0x15103000, NULL, 0, false, false, true, false},
{M_NODE, "G2D0", 0x150D3000, NULL, 0, false, false, true, false},
{M_NODE, "G2D1", 0x150E3000, NULL, 0, false, false, true, false},
{M_NODE, "G2D2", 0x150F3000, NULL, 0, false, false, true, false},
{M_NODE, "ISPLP", 0x15063000, NULL, 0, false, false, true, false},
{M_NODE, "IVA", 0x15083000, NULL, 0, false, false, true, false},
{M_NODE, "MFC0", 0x150B3000, NULL, 0, false, false, true, false},
{M_NODE, "MFC1", 0x150C3000, NULL, 0, false, false, true, false},
{M_NODE, "PDMA", 0x15123000, NULL, 0, false, false, true, false},
{M_NODE, "SPDMA", 0x15133000, NULL, 0, false, false, true, false},
{M_NODE, "SRDZ", 0x15073000, NULL, 0, false, false, true, false},
{M_NODE, "VPU", 0x150A3000, NULL, 0, false, false, true, false},
{M_NODE, "VTS", 0x15153000, NULL, 0, false, false, true, false},
{T_S_NODE, "BUSC_M0", 0x15163000, NULL, 0, false, false, true, false},
{T_S_NODE, "BUSC_M1", 0x15173000, NULL, 0, false, false, true, false},
{T_S_NODE, "BUSC_M2", 0x15183000, NULL, 0, false, false, true, false},
{T_S_NODE, "BUSC_M3", 0x15193000, NULL, 0, false, false, true, false},
{S_NODE, "PERI", 0x151B3000, NULL, TMOUT, true, false, true, false},
{S_NODE, "SP", 0x151A3000, NULL, TMOUT, true, false, true, false},
};
static struct itmon_nodeinfo data_core[] = {
{T_M_NODE, "BUSC_M0", 0x14A03000, NULL, 0, false, false, true, false},
{T_M_NODE, "BUSC_M1", 0x14A13000, NULL, 0, false, false, true, false},
{T_M_NODE, "BUSC_M2", 0x14A23000, NULL, 0, false, false, true, false},
{T_M_NODE, "BUSC_M3", 0x14A33000, NULL, 0, false, false, true, false},
{M_NODE, "CP", 0x14A83000, NULL, 0, false, false, true, false},
{M_NODE, "G3D0", 0x14A43000, NULL, 0, false, false, true, false},
{M_NODE, "G3D1", 0x14A53000, NULL, 0, false, false, true, false},
{M_NODE, "G3D2", 0x14A63000, NULL, 0, false, false, true, false},
{M_NODE, "G3D3", 0x14A73000, NULL, 0, false, false, true, false},
{S_NODE, "DREX", 0x14A93000, NULL, TMOUT, true, true, true, false},
{S_NODE, "DREX", 0x14AA3000, NULL, TMOUT, true, true, true, false},
};
static struct itmon_nodeinfo peri_core_0[] = {
{M_NODE, "CP_PERI_M", 0x14C63000, NULL, 0, false, false, true, false},
{M_NODE, "SCI_CCM0", 0x14C33000, NULL, 0, false, false, true, false},
{M_NODE, "SCI_CCM1", 0x14C43000, NULL, 0, false, false, true, false},
{M_NODE, "SCI_IRPM", 0x14C53000, NULL, 0, false, false, true, false},
{T_S_NODE, "CORE0_CORE1", 0x14C03000, NULL, 0, true, false, true, false},
{T_S_NODE, "CORE_BUSC", 0x14C13000, NULL, 0, true, false, true, false},
};
static struct itmon_nodeinfo peri_core_1[] = {
{T_M_NODE, "BUSC_CORE", 0x14E13000, NULL, 0, false, false, true, false},
{T_M_NODE, "CORE0_CORE1", 0x14E03000, NULL, 0, false, false, true, false},
{S_NODE, "CORESIGHT", 0x14E83000, NULL, TMOUT, true, false, true, false},
{S_NODE, "CORE_SFR", 0x14E33000, NULL, TMOUT, true, false, true, false},
{S_NODE, "CPUCL0", 0x14E53000, NULL, TMOUT, true, false, true, false},
{S_NODE, "CPUCL1", 0x14E63000, NULL, TMOUT, true, false, true, false},
{S_NODE, "G3D", 0x14E73000, NULL, TMOUT, true, false, true, false},
{S_NODE, "IMEM", 0x14E43000, NULL, TMOUT, true, false, true, false},
{S_NODE, "TREX_CORE", 0x14E23000, NULL, TMOUT, true, false, true, false},
};
static struct itmon_nodeinfo peri_bus_c[] = {
{M_NODE, "BUSC_PERI_M", 0x153A3000, NULL, 0, false, false, true, false},
{T_M_NODE, "CORE_BUSC", 0x153B3000, NULL, 0, false, false, true, false},
{S_NODE, "ABOX", 0x15383000, NULL, TMOUT, true, false, true, false},
{T_S_NODE, "BUSC_BUS1", 0x15243000, NULL, 0, false, false, true, false},
{T_S_NODE, "BUSC_CORE", 0x15233000, NULL, 0, false, false, true, false},
{S_NODE, "BUSC_SFR0", 0x15213000, NULL, TMOUT, true, false, true, false},
{S_NODE, "BUSC_SFR1", 0x15223000, NULL, TMOUT, true, false, true, false},
{S_NODE, "CAM", 0x152E3000, NULL, TMOUT, true, false, true, false},
{S_NODE, "DPU0", 0x152C3000, NULL, TMOUT, true, false, true, false},
{S_NODE, "DPU1", 0x152D3000, NULL, TMOUT, true, false, true, false},
{S_NODE, "DSP", 0x15363000, NULL, TMOUT, true, false, true, false},
{S_NODE, "FSYS0", 0x15333000, NULL, TMOUT, true, false, true, false},
{S_NODE, "G2D", 0x15343000, NULL, TMOUT, true, false, true, false},
{S_NODE, "ISPHQ", 0x15313000, NULL, TMOUT, true, false, true, false},
{S_NODE, "ISPLP", 0x15303000, NULL, TMOUT, true, false, true, false},
{S_NODE, "IVA", 0x15353000, NULL, TMOUT, true, false, true, false},
{S_NODE, "MFC", 0x15323000, NULL, TMOUT, true, false, true, false},
{S_NODE, "MIF0", 0x15253000, NULL, TMOUT, true, false, true, false},
{S_NODE, "MIF1", 0x15263000, NULL, TMOUT, true, false, true, false},
{S_NODE, "MIF2", 0x15273000, NULL, TMOUT, true, false, true, false},
{S_NODE, "MIF3", 0x15283000, NULL, TMOUT, true, false, true, false},
{S_NODE, "PERIC0", 0x152A3000, NULL, TMOUT, true, false, true, false},
{S_NODE, "PERIC1", 0x152B3000, NULL, TMOUT, true, false, true, false},
{S_NODE, "PERIS", 0x15293000, NULL, TMOUT, true, false, true, false},
{S_NODE, "SRDZ", 0x152F3000, NULL, TMOUT, true, false, true, false},
{S_NODE, "TREX_BUSC", 0x15203000, NULL, TMOUT, true, false, true, false},
{S_NODE, "VPU", 0x15373000, NULL, TMOUT, true, false, true, false},
{S_NODE, "VTS", 0x15393000, NULL, TMOUT, true, false, true, false},
};
static struct itmon_nodeinfo peri_bus_1[] = {
{T_M_NODE, "BUSC_BUS1", 0x15643000, NULL, 0, false, false, true, false},
{S_NODE, "ALIVE", 0x15633000, NULL, TMOUT, true, false, true, false},
{S_NODE, "BUS1_SFR", 0x15613000, NULL, TMOUT, true, false, true, false},
{S_NODE, "FSYS1", 0x15623000, NULL, TMOUT, true, false, true, false},
{S_NODE, "TREX_BUS1", 0x15603000, NULL, TMOUT, true, false, true, false},
};
static struct itmon_nodegroup nodegroup[] = {
{72, "DATA_BUS_1", 0x155F3000, NULL, data_bus_1, ARRAY_SIZE(data_bus_1), BUS_DATA},
{311, "DATA_CORE", 0x14AF3000, NULL, data_core, ARRAY_SIZE(data_core), BUS_DATA},
{92, "DATA_BUS_C", 0, NULL, data_bus_c, ARRAY_SIZE(data_bus_c), BUS_DATA},
{315, "PERI_CORE_0", 0x14CF3000, NULL, peri_core_0, ARRAY_SIZE(peri_core_0),BUS_PERI},
{316, "PERI_CORE_1", 0x14EF3000, NULL, peri_core_1, ARRAY_SIZE(peri_core_1),BUS_PERI},
{93, "PERI_BUS_C", 0x153F3000, NULL, peri_bus_c, ARRAY_SIZE(peri_bus_c), BUS_PERI},
{77, "PERI_BUS_1", 0x156F3000, NULL, peri_bus_1, ARRAY_SIZE(peri_bus_1), BUS_PERI},
};
struct itmon_dev {
struct device *dev;
struct itmon_platdata *pdata;
struct of_device_id *match;
int irq;
int id;
void __iomem *regs;
spinlock_t ctrl_lock;
struct itmon_notifier notifier_info;
};
struct itmon_panic_block {
struct notifier_block nb_panic_block;
struct itmon_dev *pdev;
};
/* declare notifier_list */
static ATOMIC_NOTIFIER_HEAD(itmon_notifier_list);
static const struct of_device_id itmon_dt_match[] = {
{.compatible = "samsung,exynos-itmon",
.data = NULL,},
{},
};
MODULE_DEVICE_TABLE(of, itmon_dt_match);
static struct itmon_rpathinfo *itmon_get_rpathinfo(struct itmon_dev *itmon,
unsigned int id,
char *dest_name)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_rpathinfo *rpath = NULL;
int i;
for (i = 0; i < ARRAY_SIZE(rpathinfo); i++) {
if (pdata->rpathinfo[i].id == (id & pdata->rpathinfo[i].bits)) {
if (dest_name && !strncmp(pdata->rpathinfo[i].dest_name,
dest_name,
strlen(pdata->rpathinfo[i].dest_name))) {
rpath = (struct itmon_rpathinfo *)&pdata->rpathinfo[i];
break;
}
}
}
return rpath;
}
static struct itmon_masterinfo *itmon_get_masterinfo(struct itmon_dev *itmon,
char *port_name,
unsigned int user)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_masterinfo *master = NULL;
unsigned int val;
int i;
for (i = 0; i < ARRAY_SIZE(masterinfo); i++) {
if (!strncmp(pdata->masterinfo[i].port_name, port_name, strlen(port_name))) {
val = user & pdata->masterinfo[i].bits;
if (val == pdata->masterinfo[i].user) {
master = (struct itmon_masterinfo *)&pdata->masterinfo[i];
break;
}
}
}
return master;
}
static void itmon_init(struct itmon_dev *itmon, bool enabled)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_nodeinfo *node;
unsigned int offset;
int i, j;
for (i = 0; i < ARRAY_SIZE(nodegroup); i++) {
node = pdata->nodegroup[i].nodeinfo;
for (j = 0; j < pdata->nodegroup[i].nodesize; j++) {
if (node[j].type == S_NODE && node[j].tmout_enabled) {
offset = OFFSET_TMOUT_REG;
/* Enable Timeout setting */
__raw_writel(enabled, node[j].regs + offset + REG_DBG_CTL);
/* set tmout interval value */
__raw_writel(node[j].time_val,
node[j].regs + offset + REG_TMOUT_INIT_VAL);
pr_debug("Exynos IPM - %s timeout enabled\n", node[j].name);
if (node[j].tmout_frz_enabled) {
/* Enable freezing */
__raw_writel(enabled,
node[j].regs + offset + REG_TMOUT_FRZ_EN);
}
}
if (node[j].err_enabled) {
/* clear previous interrupt of req_read */
offset = OFFSET_REQ_R;
if (!pdata->probed || !node->retention)
__raw_writel(1, node[j].regs + offset + REG_INT_CLR);
/* enable interrupt */
__raw_writel(enabled, node[j].regs + offset + REG_INT_MASK);
/* clear previous interrupt of req_write */
offset = OFFSET_REQ_W;
if (pdata->probed || !node->retention)
__raw_writel(1, node[j].regs + offset + REG_INT_CLR);
/* enable interrupt */
__raw_writel(enabled, node[j].regs + offset + REG_INT_MASK);
/* clear previous interrupt of response_read */
offset = OFFSET_RESP_R;
if (!pdata->probed || !node->retention)
__raw_writel(1, node[j].regs + offset + REG_INT_CLR);
/* enable interrupt */
__raw_writel(enabled, node[j].regs + offset + REG_INT_MASK);
/* clear previous interrupt of response_write */
offset = OFFSET_RESP_W;
if (!pdata->probed || !node->retention)
__raw_writel(1, node[j].regs + offset + REG_INT_CLR);
/* enable interrupt */
__raw_writel(enabled, node[j].regs + offset + REG_INT_MASK);
pr_debug("Exynos IPM - %s error reporting enabled\n", node[j].name);
}
}
}
}
void itmon_enable(bool enabled)
{
if (g_itmon) {
itmon_init(g_itmon, enabled);
}
}
void itmon_set_errcnt(int cnt)
{
struct itmon_platdata *pdata;
if (g_itmon) {
pdata = g_itmon->pdata;
pdata->err_cnt = cnt;
}
}
static void itmon_post_handler_by_master(struct itmon_dev *itmon,
struct itmon_nodeinfo *node,
unsigned int trans_type)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_traceinfo *traceinfo = &pdata->traceinfo[trans_type];
/* After treatment by port */
if (!traceinfo->port || strlen(traceinfo->port) < 1)
return;
if (!strncmp(traceinfo->port, "CP", strlen(traceinfo->port))) {
/* if master is DSP and operation is read, we don't care this */
if (traceinfo->master && traceinfo->target_addr == INVALID_REMAPPING &&
!strncmp(traceinfo->master, "CR4MtoL2", strlen(traceinfo->master))) {
pdata->err_cnt = 0;
pr_info("ITMON skips CP's DSP(CR4MtoL2) detected\n");
} else {
/* Disable busmon all interrupts */
itmon_init(itmon, false);
}
} else if (!strncmp(traceinfo->port, "CPU", strlen("CPU"))) {
/* if master is CPU, then we expect any exception */
if (pdata->err_cnt > PANIC_ALLOWED_THRESHOLD) {
pdata->err_cnt = 0;
itmon_init(itmon, false);
pr_info("ITMON is turn-off when CPU transaction is detected repeatly\n");
} else {
pr_info("ITMON skips CPU transaction detected\n");
}
}
}
static void itmon_report_timeout(struct itmon_dev *itmon,
struct itmon_nodeinfo *node,
unsigned int trans_type)
{
unsigned int id, payload, axid, user, valid, timeout;
char *master_name, *port_name;
struct itmon_rpathinfo *port;
struct itmon_masterinfo *master;
int i, num = (trans_type == TRANS_TYPE_READ ? SZ_128 : SZ_64);
int fz_offset = (trans_type == TRANS_TYPE_READ ? 0 : REG_TMOUT_BUF_WR_OFFSET);
pr_info(" TIMEOUT_BUFFER Information\n\n");
pr_info(" > NUM| BLOCK| MASTER| VALID| TIMEOUT| ID| PAYLOAD|\n");
for (i = 0; i < num; i++) {
writel(i, node->regs + OFFSET_TMOUT_REG +
REG_TMOUT_BUF_RD_ADDR + fz_offset);
id = readl(node->regs + OFFSET_TMOUT_REG +
REG_TMOUT_BUF_RD_ID + fz_offset);
payload = readl(node->regs + OFFSET_TMOUT_REG +
REG_TMOUT_BUF_RD_PAYLOAD + fz_offset);
/* ID[5:0] 6bit : R-PATH */
axid = id & GENMASK(5, 0);
/* PAYLOAD[15:8] : USER */
user = payload & GENMASK(15, 8) >> 8;
/* PAYLOAD[0] : Valid or Not valid */
valid = payload & BIT(0);
/* PAYLOAD[19:16] : Timeout */
timeout = payload & GENMASK(19, 16) >> 16;
port = (struct itmon_rpathinfo *)
itmon_get_rpathinfo(itmon, axid, "DREX");
if (port) {
port_name = port->port_name;
master = (struct itmon_masterinfo *)
itmon_get_masterinfo(itmon, port_name, user);
if (master)
master_name = master->master_name;
else
master_name = "Unknown";
} else {
port_name = "Unknown";
master_name = "Unknown";
}
pr_info(" > %03d|%8s|%8s|%8u|%8x|%08x|%08x|\n",
i, port_name, master_name, valid, timeout, id, payload);
}
pr_info("--------------------------------------------------------------------------\n");
}
static unsigned int power(unsigned int param, unsigned int num)
{
if (num == 0)
return 1;
return param * (power(param, num - 1));
}
static void itmon_report_traceinfo(struct itmon_dev *itmon,
struct itmon_nodeinfo *node,
unsigned int trans_type)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_traceinfo *traceinfo = &pdata->traceinfo[trans_type];
struct itmon_nodegroup *group = NULL;
if (!traceinfo->dirty || traceinfo->trans_dirty)
return;
else
traceinfo->trans_dirty = true;
pr_info("--------------------------------------------------------------------------\n"
" Transaction Information\n\n"
" > Master : %s %s\n"
" > Target : %s\n"
" > Target Address : 0x%zx %s\n"
" > Type : %s\n"
" > Error code : %s\n",
traceinfo->port, traceinfo->master ? traceinfo->master : "",
traceinfo->dest ? traceinfo->dest : "Unknown",
traceinfo->target_addr,
traceinfo->target_addr == INVALID_REMAPPING ?
"(Violation Access by CP maybe)" : "",
trans_type == TRANS_TYPE_READ ? "READ" : "WRITE",
itmon_errcode[traceinfo->errcode]);
if (node) {
struct itmon_tracedata *tracedata = &node->tracedata;
pr_info(" > Size : %u bytes x %u burst => %u bytes\n"
" > Burst Type : %u (0:FIXED, 1:INCR, 2:WRAP)\n"
" > Level : %s\n"
" > Protection : %s\n",
power(BIT_AXSIZE(tracedata->ext_info_1), 2), BIT_AXLEN(tracedata->ext_info_1) + 1,
power(BIT_AXSIZE(tracedata->ext_info_1), 2) * (BIT_AXLEN(tracedata->ext_info_1) + 1),
BIT_AXBURST(tracedata->ext_info_2),
(BIT_AXPROT(tracedata->ext_info_2) & 0x1) ? "Privileged access" : "Unprivileged access",
(BIT_AXPROT(tracedata->ext_info_2) & 0x2) ? "Non-secure access" : "Secure access");
group = node->group;
pr_info(" > Path Type : %s\n"
"--------------------------------------------------------------------------\n",
itmon_pathtype[group->bus_type]);
/* timeout freezing result */
if (node->type == S_NODE && node->tmout_frz_enabled &&
traceinfo->errcode == ERRCODE_TMOUT)
itmon_report_timeout(itmon, node, trans_type);
} else {
pr_info("--------------------------------------------------------------------------\n");
}
}
static void itmon_report_pathinfo(struct itmon_dev *itmon,
struct itmon_nodeinfo *node,
unsigned int trans_type)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_tracedata *tracedata = &node->tracedata;
struct itmon_traceinfo *traceinfo = &pdata->traceinfo[trans_type];
if (!traceinfo->path_dirty) {
pr_info("--------------------------------------------------------------------------\n"
" ITMON Report (%s)\n"
"--------------------------------------------------------------------------\n"
" PATH Information\n",
trans_type == TRANS_TYPE_READ ? "READ" : "WRITE");
traceinfo->path_dirty = true;
}
switch (node->type) {
case M_NODE:
pr_info(" ||\n"
" > %14s, %8s(0x%08X)\n",
node->name, "M_NODE", node->phy_regs + tracedata->offset);
break;
case T_S_NODE:
pr_info(" ||\n"
" > %14s, %8s(0x%08X)\n",
node->name, "T_S_NODE", node->phy_regs + tracedata->offset);
break;
case T_M_NODE:
pr_info(" ||\n"
" > %14s, %8s(0x%08X)\n",
node->name, "T_M_NODE", node->phy_regs + tracedata->offset);
break;
case S_NODE:
pr_info(" ||\n"
" > %14s, %8s(0x%08X)\n",
node->name, "S_NODE", node->phy_regs + tracedata->offset);
break;
}
}
static void itmon_report_tracedata(struct itmon_dev *itmon,
struct itmon_nodeinfo *node,
unsigned int trans_type)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_tracedata *tracedata = &node->tracedata;
struct itmon_traceinfo *traceinfo = &pdata->traceinfo[trans_type];
struct itmon_nodegroup *group = node->group;
struct itmon_masterinfo *master;
struct itmon_rpathinfo *port;
unsigned int errcode, axid;
unsigned long userbit;
errcode = BIT_ERR_CODE(tracedata->int_info);
axid = BIT_AXID(tracedata->int_info);
userbit = BIT_AXUSER(tracedata->ext_info_2);
switch (node->type) {
case M_NODE:
/* In this case, we can get information from M_NODE
* Fill traceinfo->port / target_addr / read / master */
if (BIT_ERR_VALID(tracedata->int_info) && tracedata->ext_info_2) {
/* If only detecting M_NODE only */
if (!strncmp(node->name, "SCI_IRPM", strlen(node->name))) {
int cluster_num, core_num;
core_num = axid & GENMASK(1, 0);
cluster_num = (axid & BIT(2)) >> 2;
snprintf(traceinfo->buf, SZ_32 - 1, "CPU%d Cluster%d", core_num, cluster_num);
traceinfo->port = traceinfo->buf;
} else if (!strncmp(node->name, "CP_PERI_M", strlen(node->name))) {
snprintf(traceinfo->buf, SZ_32 - 1, "CP");
traceinfo->port = traceinfo->buf;
master = (struct itmon_masterinfo *)
itmon_get_masterinfo(itmon, traceinfo->port, userbit);
if (master)
traceinfo->master = master->master_name;
else
traceinfo->master = NULL;
} else {
traceinfo->port = node->name;
master = (struct itmon_masterinfo *)
itmon_get_masterinfo(itmon, node->name, userbit);
if (master)
traceinfo->master = master->master_name;
else
traceinfo->master = NULL;
}
traceinfo->target_addr =
(unsigned long)(node->tracedata.ext_info_2
& GENMASK(3, 0) << 32ULL);
traceinfo->target_addr |= node->tracedata.ext_info_0;
traceinfo->read = tracedata->read;
traceinfo->errcode = errcode;
traceinfo->dirty = true;
}
/* If we excepts following M_NODE with S_NODE */
if (!strncmp(node->name, "SCI_IRPM", strlen(node->name))) {
set_bit(FROM_CPU, &traceinfo->from);
} else if (!strncmp(node->name, "SCI_CCM0", strlen(node->name)) ||
!strncmp(node->name, "SCI_CCM1", strlen(node->name))) {
set_bit(FROM_CPU_MAY, &traceinfo->from);
} else if (!strncmp(node->name, "CP_PERI_M", strlen(node->name))) {
set_bit(FROM_CP, &traceinfo->from);
} else if (!strncmp(node->name, "BUSC_PERI_M", strlen(node->name))) {
set_bit(FROM_M_NODE, &traceinfo->from);
} else {
/* Pure M_NODE and it doesn't have any information */
if (!traceinfo->dirty) {
traceinfo->master = NULL;
traceinfo->target_addr = 0;
traceinfo->read = tracedata->read;
traceinfo->port = node->name;
traceinfo->errcode = errcode;
traceinfo->dirty = true;
}
}
itmon_report_pathinfo(itmon, node, trans_type);
break;
case S_NODE:
if (test_bit(FROM_CPU, &traceinfo->from)) {
/*
* This case is only for PERI Path
* Master is CPU cluster
* user & GENMASK(1, 0) = core number
*/
int cluster_num, core_num;
core_num = axid & GENMASK(1, 0);
cluster_num = (axid & BIT(2)) >> 2;
snprintf(traceinfo->buf, SZ_32 - 1, "CPU%d Cluster%d", core_num, cluster_num);
traceinfo->port = traceinfo->buf;
} else if (test_bit(FROM_CPU_MAY, &traceinfo->from)) {
snprintf(traceinfo->buf, SZ_32 - 1, "CPU maybe");
traceinfo->port = traceinfo->buf;
} else {
/*
* we expect traceinfo->port is always true in this case
* In DECERR case, the follow information was filled.
*/
if (test_bit(FROM_CP, &traceinfo->from)) {
snprintf(traceinfo->buf, SZ_32 - 1, "CP");
traceinfo->port = traceinfo->buf;
}
if (!traceinfo->port) {
port = (struct itmon_rpathinfo *)
itmon_get_rpathinfo(itmon, axid, node->name);
if (port)
traceinfo->port = port->port_name;
else
traceinfo->port = NULL;
}
if (!traceinfo->master) {
master = (struct itmon_masterinfo *)
itmon_get_masterinfo(itmon, traceinfo->port,
userbit & GENMASK(2, 0));
if (master)
traceinfo->master = master->master_name;
else
traceinfo->master = NULL;
}
}
traceinfo->target_addr =
(unsigned long)(node->tracedata.ext_info_2
& GENMASK(3, 0) << 32ULL);
traceinfo->target_addr |= node->tracedata.ext_info_0;
traceinfo->errcode = errcode;
traceinfo->dest = node->name;
traceinfo->dirty = true;
itmon_report_pathinfo(itmon, node, trans_type);
itmon_report_traceinfo(itmon, node, trans_type);
break;
case T_S_NODE:
case T_M_NODE:
/* Data Path */
if (!strncmp(group->name, "DATA_CORE", strlen("DATA_CORE"))
&& node->type == T_M_NODE) {
/* Exception Situation - DREX PATH */
traceinfo->dest = "DREX";
traceinfo->errcode = errcode;
traceinfo->dirty = true;
}
itmon_report_pathinfo(itmon, node, trans_type);
break;
default:
pr_info("Unknown Error - offset:%u\n", tracedata->offset);
break;
}
}
static void itmon_report_rawdata(struct itmon_dev *itmon, struct itmon_nodeinfo *node)
{
struct itmon_tracedata *tracedata = &node->tracedata;
pr_info(" > %s(%s, 0x%08X)\n"
" > REG(0x08~0x18) : 0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
node->name, itmon_nodestring[node->type],
node->phy_regs + tracedata->offset,
tracedata->int_info,
tracedata->ext_info_0,
tracedata->ext_info_1,
tracedata->ext_info_2);
}
static void itmon_route_tracedata(struct itmon_dev *itmon)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_nodeinfo *node, *next_node;
unsigned int trans_type;
int i;
/* To call function is sorted by declaration */
for (trans_type = 0; trans_type < TRANS_TYPE_NUM; trans_type++) {
for (i = M_NODE; i < NODE_TYPE; i++) {
list_for_each_entry(node, &pdata->tracelist[trans_type], list) {
if (i == node->type)
itmon_report_tracedata(itmon, node, trans_type);
}
}
/* If there is no S_NODE and T_S_NODE and T_M_NODE, check one more */
itmon_report_traceinfo(itmon, NULL, trans_type);
}
if (pdata->traceinfo[TRANS_TYPE_READ].dirty ||
pdata->traceinfo[TRANS_TYPE_WRITE].dirty)
pr_info(" Raw Register Information(ITMON Internal Information)\n\n");
for (trans_type = 0; trans_type < TRANS_TYPE_NUM; trans_type++) {
itmon_post_handler_by_master(itmon, node, trans_type);
for (i = M_NODE; i < NODE_TYPE; i++) {
list_for_each_entry_safe(node, next_node, &pdata->tracelist[trans_type], list) {
if (i == node->type) {
itmon_report_rawdata(itmon, node);
/* clean up */
list_del(&node->list);
kfree(node);
}
}
}
}
if (pdata->traceinfo[TRANS_TYPE_READ].dirty ||
pdata->traceinfo[TRANS_TYPE_WRITE].dirty)
pr_info("--------------------------------------------------------------------------\n");
}
static void itmon_trace_data(struct itmon_dev *itmon,
struct itmon_nodegroup *group,
struct itmon_nodeinfo *node,
unsigned int offset)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_nodeinfo *new_node = NULL;
unsigned int int_info, info0, info1, info2;
bool read = TRANS_TYPE_WRITE;
bool req = false;
int_info = __raw_readl(node->regs + offset + REG_INT_INFO);
info0 = __raw_readl(node->regs + offset + REG_EXT_INFO_0);
info1 = __raw_readl(node->regs + offset + REG_EXT_INFO_1);
info2 = __raw_readl(node->regs + offset + REG_EXT_INFO_2);
switch (offset) {
case OFFSET_REQ_R:
read = TRANS_TYPE_READ;
/* fall down */
case OFFSET_REQ_W:
req = true;
/* Only S-Node is able to make log to registers */
break;
case OFFSET_RESP_R:
read = TRANS_TYPE_READ;
/* fall down */
case OFFSET_RESP_W:
req = false;
/* Only NOT S-Node is able to make log to registers */
break;
default:
pr_info("Unknown Error - node:%s offset:%u\n", node->name, offset);
break;
}
new_node = kmalloc(sizeof(struct itmon_nodeinfo), GFP_ATOMIC);
if (new_node) {
/* Fill detected node information to tracedata's list */
memcpy(new_node, node, sizeof(struct itmon_nodeinfo));
new_node->tracedata.int_info = int_info;
new_node->tracedata.ext_info_0 = info0;
new_node->tracedata.ext_info_1 = info1;
new_node->tracedata.ext_info_2 = info2;
new_node->tracedata.offset = offset;
new_node->tracedata.read = read;
new_node->group = group;
if (BIT_ERR_VALID(int_info))
node->tracedata.logging = true;
else
node->tracedata.logging = false;
list_add(&new_node->list, &pdata->tracelist[read]);
} else {
pr_info("failed to kmalloc for %s node %x offset\n",
node->name, offset);
}
}
static int itmon_search_node(struct itmon_dev *itmon, struct itmon_nodegroup *group, bool clear)
{
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_nodeinfo *node = NULL;
unsigned int val, offset, vec;
unsigned long flags, bit = 0;
int i, j, ret = 0;
spin_lock_irqsave(&itmon->ctrl_lock, flags);
memset(pdata->traceinfo, 0, sizeof(struct itmon_traceinfo) * 2);
if (group) {
/* Processing only this group and select detected node */
vec = __raw_readl(group->regs);
node = group->nodeinfo;
if (!vec)
goto exit;
for_each_set_bit(bit, (unsigned long *)&vec, group->nodesize) {
/* exist array */
for (i = 0; i < OFFSET_NUM; i++) {
offset = i * OFFSET_ERR_REPT;
/* Check Request information */
val = __raw_readl(node[bit].regs + offset + REG_INT_INFO);
if (BIT_ERR_OCCURRED(val)) {
/* This node occurs the error */
itmon_trace_data(itmon, group, &node[bit], offset);
if (clear)
__raw_writel(1, node[bit].regs
+ offset + REG_INT_CLR);
ret = true;
}
}
}
} else {
/* Processing all group & nodes */
for (i = 0; i < ARRAY_SIZE(nodegroup); i++) {
group = &nodegroup[i];
if (group->phy_regs)
vec = __raw_readl(group->regs);
else
vec = GENMASK(group->nodesize, 0);
node = group->nodeinfo;
bit = 0;
for_each_set_bit(bit, (unsigned long *)&vec, group->nodesize) {
for (j = 0; j < OFFSET_NUM; j++) {
offset = j * OFFSET_ERR_REPT;
/* Check Request information */
val = __raw_readl(node[bit].regs + offset + REG_INT_INFO);
if (BIT_ERR_OCCURRED(val)) {
/* This node occurs the error */
itmon_trace_data(itmon, group, &node[bit], offset);
if (clear)
__raw_writel(1, node[bit].regs
+ offset + REG_INT_CLR);
ret = true;
}
}
}
}
}
itmon_route_tracedata(itmon);
exit:
spin_unlock_irqrestore(&itmon->ctrl_lock, flags);
return ret;
}
static irqreturn_t itmon_irq_handler(int irq, void *data)
{
struct itmon_dev *itmon = (struct itmon_dev *)data;
struct itmon_platdata *pdata = itmon->pdata;
struct itmon_nodegroup *group = NULL;
bool ret;
int i;
/* Search itmon group */
for (i = 0; i < ARRAY_SIZE(nodegroup); i++) {
if (irq == nodegroup[i].irq) {
group = &pdata->nodegroup[i];
if (group->phy_regs != 0) {
pr_info("\nITMON Detected: %d irq, %s group, 0x%x vec, err_cnt:%u\n",
irq, group->name, __raw_readl(group->regs), pdata->err_cnt);
} else {
pr_info("\nITMON Detected: %d irq, %s group, err_cnt:%u\n",
irq, group->name, pdata->err_cnt);
}
break;
}
}
ret = itmon_search_node(itmon, NULL, true);
if (!ret) {
pr_info("ITMON could not detect any error\n");
} else {
if (pdata->err_cnt++ > PANIC_ALLOWED_THRESHOLD)
pdata->panic_allowed = true;
}
if (pdata->panic_allowed)
panic("ITMON occurs panic to prevent endless log");
return IRQ_HANDLED;
}
void itmon_notifier_chain_register(struct notifier_block *block)
{
atomic_notifier_chain_register(&itmon_notifier_list, block);
}
static int itmon_logging_panic_handler(struct notifier_block *nb,
unsigned long l, void *buf)
{
struct itmon_panic_block *itmon_panic = (struct itmon_panic_block *)nb;
struct itmon_dev *itmon = itmon_panic->pdev;
int ret;
if (!IS_ERR_OR_NULL(itmon)) {
/* Check error has been logged */
ret = itmon_search_node(itmon, NULL, false);
if (!ret)
pr_info("No found error in %s\n", __func__);
else
pr_info("Found errors in %s\n", __func__);
}
return 0;
}
static int itmon_probe(struct platform_device *pdev)
{
struct itmon_dev *itmon;
struct itmon_panic_block *itmon_panic = NULL;
struct itmon_platdata *pdata;
struct itmon_nodeinfo *node;
unsigned int irq_option = 0, irq;
char *dev_name;
int ret, i, j;
itmon = devm_kzalloc(&pdev->dev, sizeof(struct itmon_dev), GFP_KERNEL);
if (!itmon) {
dev_err(&pdev->dev, "failed to allocate memory for driver's "
"private data\n");
return -ENOMEM;
}
itmon->dev = &pdev->dev;
spin_lock_init(&itmon->ctrl_lock);
pdata = devm_kzalloc(&pdev->dev, sizeof(struct itmon_platdata), GFP_KERNEL);
if (!pdata) {
dev_err(&pdev->dev, "failed to allocate memory for driver's "
"platform data\n");
return -ENOMEM;
}
itmon->pdata = pdata;
itmon->pdata->masterinfo = masterinfo;
itmon->pdata->rpathinfo = rpathinfo;
itmon->pdata->nodegroup = nodegroup;
for (i = 0; i < ARRAY_SIZE(nodegroup); i++) {
dev_name = nodegroup[i].name;
node = nodegroup[i].nodeinfo;
if (nodegroup[i].phy_regs) {
nodegroup[i].regs = devm_ioremap_nocache(&pdev->dev,
nodegroup[i].phy_regs, SZ_16K);
if (nodegroup[i].regs == NULL) {
dev_err(&pdev->dev, "failed to claim register region - %s\n",
dev_name);
return -ENOENT;
}
}
if (initial_multi_irq_enable)
irq_option = IRQF_GIC_MULTI_TARGET;
irq = irq_of_parse_and_map(pdev->dev.of_node, i);
nodegroup[i].irq = irq;
ret = devm_request_irq(&pdev->dev, irq,
itmon_irq_handler, irq_option, dev_name, itmon);
if (ret < 0) {
dev_err(&pdev->dev, "failed to request irq - %s\n", dev_name);
return -ENOENT;
} else {
dev_err(&pdev->dev, "success to register request irq%u - %s\n", irq, dev_name);
}
for (j = 0; j < nodegroup[i].nodesize; j++) {
node[j].regs = devm_ioremap_nocache(&pdev->dev, node[j].phy_regs, SZ_16K);
if (node[j].regs == NULL) {
dev_err(&pdev->dev, "failed to claim register region - %s\n",
dev_name);
return -ENOENT;
}
}
}
itmon_panic = devm_kzalloc(&pdev->dev, sizeof(struct itmon_panic_block),
GFP_KERNEL);
if (!itmon_panic) {
dev_err(&pdev->dev, "failed to allocate memory for driver's "
"panic handler data\n");
} else {
itmon_panic->nb_panic_block.notifier_call = itmon_logging_panic_handler;
itmon_panic->pdev = itmon;
atomic_notifier_chain_register(&panic_notifier_list,
&itmon_panic->nb_panic_block);
}
platform_set_drvdata(pdev, itmon);
INIT_LIST_HEAD(&pdata->tracelist[BUS_DATA]);
INIT_LIST_HEAD(&pdata->tracelist[BUS_PERI]);
itmon_init(itmon, true);
g_itmon = itmon;
pdata->probed = true;
dev_info(&pdev->dev, "success to probe Exynos ITMON driver\n");
return 0;
}
static int itmon_remove(struct platform_device *pdev)
{
platform_set_drvdata(pdev, NULL);
return 0;
}
#ifdef CONFIG_PM_SLEEP
static int itmon_suspend(struct device *dev)
{
return 0;
}
static int itmon_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct itmon_dev *itmon = platform_get_drvdata(pdev);
itmon_init(itmon, true);
return 0;
}
static SIMPLE_DEV_PM_OPS(itmon_pm_ops, itmon_suspend, itmon_resume);
#define ITMON_PM (itmon_pm_ops)
#else
#define ITM_ONPM NULL
#endif
static struct platform_driver exynos_itmon_driver = {
.probe = itmon_probe,
.remove = itmon_remove,
.driver = {
.name = "exynos-itmon",
.of_match_table = itmon_dt_match,
.pm = &itmon_pm_ops,
},
};
module_platform_driver(exynos_itmon_driver);
MODULE_DESCRIPTION("Samsung Exynos ITMON DRIVER");
MODULE_AUTHOR("Hosung Kim <hosung0.kim@samsung.com");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:exynos-itmon");