1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
4  *
5  */
6 
7 #include <linux/platform_device.h>
8 #ifndef __LLCC_QCOM__
9 #define __LLCC_QCOM__
10 
11 #define LLCC_CPUSS       1
12 #define LLCC_VIDSC0      2
13 #define LLCC_VIDSC1      3
14 #define LLCC_ROTATOR     4
15 #define LLCC_VOICE       5
16 #define LLCC_AUDIO       6
17 #define LLCC_MDMHPGRW    7
18 #define LLCC_MDM         8
19 #define LLCC_MODHW       9
20 #define LLCC_CMPT        10
21 #define LLCC_GPUHTW      11
22 #define LLCC_GPU         12
23 #define LLCC_MMUHWT      13
24 #define LLCC_CMPTDMA     15
25 #define LLCC_DISP        16
26 #define LLCC_VIDFW       17
27 #define LLCC_MDMHPFX     20
28 #define LLCC_MDMPNG      21
29 #define LLCC_AUDHW       22
30 #define LLCC_NPU         23
31 #define LLCC_WLHW        24
32 #define LLCC_PIMEM       25
33 #define LLCC_DRE         26
34 #define LLCC_CVP         28
35 #define LLCC_MODPE       29
36 #define LLCC_APTCM       30
37 #define LLCC_WRCACHE     31
38 #define LLCC_CVPFW       32
39 #define LLCC_CPUSS1      33
40 #define LLCC_CAMEXP0     34
41 #define LLCC_CPUMTE      35
42 #define LLCC_CPUHWT      36
43 #define LLCC_MDMCLAD2    37
44 #define LLCC_CAMEXP1     38
45 #define LLCC_AENPU       45
46 
47 /**
48  * struct llcc_slice_desc - Cache slice descriptor
49  * @slice_id: llcc slice id
50  * @slice_size: Size allocated for the llcc slice
51  */
52 struct llcc_slice_desc {
53 	u32 slice_id;
54 	size_t slice_size;
55 };
56 
57 /**
58  * struct llcc_edac_reg_data - llcc edac registers data for each error type
59  * @name: Name of the error
60  * @synd_reg: Syndrome register address
61  * @count_status_reg: Status register address to read the error count
62  * @ways_status_reg: Status register address to read the error ways
63  * @reg_cnt: Number of registers
64  * @count_mask: Mask value to get the error count
65  * @ways_mask: Mask value to get the error ways
66  * @count_shift: Shift value to get the error count
67  * @ways_shift: Shift value to get the error ways
68  */
69 struct llcc_edac_reg_data {
70 	char *name;
71 	u64 synd_reg;
72 	u64 count_status_reg;
73 	u64 ways_status_reg;
74 	u32 reg_cnt;
75 	u32 count_mask;
76 	u32 ways_mask;
77 	u8  count_shift;
78 	u8  ways_shift;
79 };
80 
81 struct llcc_edac_reg_offset {
82 	/* LLCC TRP registers */
83 	u32 trp_ecc_error_status0;
84 	u32 trp_ecc_error_status1;
85 	u32 trp_ecc_sb_err_syn0;
86 	u32 trp_ecc_db_err_syn0;
87 	u32 trp_ecc_error_cntr_clear;
88 	u32 trp_interrupt_0_status;
89 	u32 trp_interrupt_0_clear;
90 	u32 trp_interrupt_0_enable;
91 
92 	/* LLCC Common registers */
93 	u32 cmn_status0;
94 	u32 cmn_interrupt_0_enable;
95 	u32 cmn_interrupt_2_enable;
96 
97 	/* LLCC DRP registers */
98 	u32 drp_ecc_error_cfg;
99 	u32 drp_ecc_error_cntr_clear;
100 	u32 drp_interrupt_status;
101 	u32 drp_interrupt_clear;
102 	u32 drp_interrupt_enable;
103 	u32 drp_ecc_error_status0;
104 	u32 drp_ecc_error_status1;
105 	u32 drp_ecc_sb_err_syn0;
106 	u32 drp_ecc_db_err_syn0;
107 };
108 
109 /**
110  * struct llcc_drv_data - Data associated with the llcc driver
111  * @regmap: regmap associated with the llcc device
112  * @bcast_regmap: regmap associated with llcc broadcast offset
113  * @cfg: pointer to the data structure for slice configuration
114  * @edac_reg_offset: Offset of the LLCC EDAC registers
115  * @lock: mutex associated with each slice
116  * @cfg_size: size of the config data table
117  * @max_slices: max slices as read from device tree
118  * @num_banks: Number of llcc banks
119  * @bitmap: Bit map to track the active slice ids
120  * @offsets: Pointer to the bank offsets array
121  * @ecc_irq: interrupt for llcc cache error detection and reporting
122  * @version: Indicates the LLCC version
123  */
124 struct llcc_drv_data {
125 	struct regmap *regmap;
126 	struct regmap *bcast_regmap;
127 	const struct llcc_slice_config *cfg;
128 	const struct llcc_edac_reg_offset *edac_reg_offset;
129 	struct mutex lock;
130 	u32 cfg_size;
131 	u32 max_slices;
132 	u32 num_banks;
133 	unsigned long *bitmap;
134 	u32 *offsets;
135 	int ecc_irq;
136 	u32 version;
137 };
138 
139 #if IS_ENABLED(CONFIG_QCOM_LLCC)
140 /**
141  * llcc_slice_getd - get llcc slice descriptor
142  * @uid: usecase_id of the client
143  */
144 struct llcc_slice_desc *llcc_slice_getd(u32 uid);
145 
146 /**
147  * llcc_slice_putd - llcc slice descritpor
148  * @desc: Pointer to llcc slice descriptor
149  */
150 void llcc_slice_putd(struct llcc_slice_desc *desc);
151 
152 /**
153  * llcc_get_slice_id - get slice id
154  * @desc: Pointer to llcc slice descriptor
155  */
156 int llcc_get_slice_id(struct llcc_slice_desc *desc);
157 
158 /**
159  * llcc_get_slice_size - llcc slice size
160  * @desc: Pointer to llcc slice descriptor
161  */
162 size_t llcc_get_slice_size(struct llcc_slice_desc *desc);
163 
164 /**
165  * llcc_slice_activate - Activate the llcc slice
166  * @desc: Pointer to llcc slice descriptor
167  */
168 int llcc_slice_activate(struct llcc_slice_desc *desc);
169 
170 /**
171  * llcc_slice_deactivate - Deactivate the llcc slice
172  * @desc: Pointer to llcc slice descriptor
173  */
174 int llcc_slice_deactivate(struct llcc_slice_desc *desc);
175 
176 #else
llcc_slice_getd(u32 uid)177 static inline struct llcc_slice_desc *llcc_slice_getd(u32 uid)
178 {
179 	return NULL;
180 }
181 
llcc_slice_putd(struct llcc_slice_desc * desc)182 static inline void llcc_slice_putd(struct llcc_slice_desc *desc)
183 {
184 
185 };
186 
llcc_get_slice_id(struct llcc_slice_desc * desc)187 static inline int llcc_get_slice_id(struct llcc_slice_desc *desc)
188 {
189 	return -EINVAL;
190 }
191 
llcc_get_slice_size(struct llcc_slice_desc * desc)192 static inline size_t llcc_get_slice_size(struct llcc_slice_desc *desc)
193 {
194 	return 0;
195 }
llcc_slice_activate(struct llcc_slice_desc * desc)196 static inline int llcc_slice_activate(struct llcc_slice_desc *desc)
197 {
198 	return -EINVAL;
199 }
200 
llcc_slice_deactivate(struct llcc_slice_desc * desc)201 static inline int llcc_slice_deactivate(struct llcc_slice_desc *desc)
202 {
203 	return -EINVAL;
204 }
205 #endif
206 
207 #endif
208