blob: 1e5a79321129fd84d1b762f2a8222e19f00a597a [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2019 MediaTek Inc.
4 */
5#ifndef __EMI_H__
6#define __EMI_H__
7
8#include <linux/irqreturn.h>
9#define MTK_EMIMPU_NO_PROTECTION 0
10#define MTK_EMIMPU_SEC_RW 1
11#define MTK_EMIMPU_SEC_RW_NSEC_R 2
12#define MTK_EMIMPU_SEC_RW_NSEC_W 3
13#define MTK_EMIMPU_SEC_R_NSEC_R 4
14#define MTK_EMIMPU_FORBIDDEN 5
15#define MTK_EMIMPU_SEC_R_NSEC_RW 6
16
17#define MTK_EMIMPU_UNLOCK false
18#define MTK_EMIMPU_LOCK true
19
20#define MTK_EMIMPU_SET 0
21#define MTK_EMIMPU_CLEAR 1
22#define MTK_EMIMPU_READ 2
23#define MTK_EMIMPU_SLVERR 3
24#define MTK_EMIDBG_DUMP 4
25#define MTK_EMIDBG_MSG 5
26
27#define MTK_EMIMPU_READ_SA 0
28#define MTK_EMIMPU_READ_EA 1
29#define MTK_EMIMPU_READ_APC 2
30#define MTK_EMI_MAX_TOKEN 4
31
32#define MTK_EMI_MAX_CMD_LEN 4096
33
34struct emi_addr_map {
35 int emi;
36 int channel;
37 int rank;
38 int bank;
39 int row;
40 int column;
41};
42
43struct reg_info_t {
44 unsigned int offset;
45 unsigned int value;
46 unsigned int leng;
47};
48
49struct emimpu_region_t {
50 unsigned long long start;
51 unsigned long long end;
52 unsigned int rg_num;
53 bool lock;
54 unsigned int *apc;
55};
56
57typedef irqreturn_t (*emimpu_pre_handler)(
58 unsigned int emi_id, struct reg_info_t *dump, unsigned int leng);
59typedef void (*emimpu_post_clear)(unsigned int emi_id);
60typedef void (*emimpu_md_handler)(
61 unsigned int emi_id, struct reg_info_t *dump, unsigned int leng);
62typedef void (*emimpu_debug_dump)(void);
63
64struct emimpu_dbg_cb {
65 emimpu_debug_dump func;
66 struct emimpu_dbg_cb *next_dbg_cb;
67};
68
69/* mtk emicen api */
70unsigned int mtk_emicen_get_ch_cnt(void);
71unsigned int mtk_emicen_get_rk_cnt(void);
72unsigned int mtk_emicen_get_rk_size(unsigned int rk_id);
73int mtk_emicen_addr2dram(unsigned long addr, struct emi_addr_map *map);
74
75/* mtk emidbg api */
76void mtk_emidbg_dump(void);
77
78/* mtk emimpu api */
79int emimpu_ap_region_init(void);
80int mtk_emimpu_init_region(
81 struct emimpu_region_t *rg_info, unsigned int rg_num);
82int mtk_emimpu_set_addr(struct emimpu_region_t *rg_info,
83 unsigned long long start, unsigned long long end);
84int mtk_emimpu_set_apc(struct emimpu_region_t *rg_info,
85 unsigned int d_num, unsigned int apc);
86int mtk_emimpu_lock_region(struct emimpu_region_t *rg_info, bool lock);
87int mtk_emimpu_set_protection(struct emimpu_region_t *rg_info);
88int mtk_emimpu_free_region(struct emimpu_region_t *rg_info);
89int mtk_emimpu_clear_protection(struct emimpu_region_t *rg_info);
90int mtk_emimpu_prehandle_register(emimpu_pre_handler bypass_func);
91int mtk_emimpu_postclear_register(emimpu_post_clear clear_func);
92int mtk_emimpu_md_handling_register(emimpu_md_handler md_handling_func);
93int mtk_emimpu_debugdump_register(emimpu_debug_dump debug_func);
94void mtk_clear_md_violation(void);
95
96#endif /* __EMI_H__ */