blob: 8e4ca5e9432237c225ba62e424a8cf73a698f887 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (C) 2017 MediaTek Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 * See http://www.gnu.org/licenses/gpl-2.0.html for more details.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/tracepoint.h>
17#include <trace/events/sched.h>
18#include <trace/events/power.h>
19#include <linux/dma-mapping.h>
20
21#include <linux/kallsyms.h>
22#include <linux/printk.h>
23#include <linux/perf_event.h>
24#include <linux/kthread.h>
25#include <asm/arch_timer.h>
26#include <asm/cpu.h>
27#include <linux/smp.h> /* arch_send_call_function_single_ipi */
28
29/******************************************************************************
30 * Tracepoints
31 ******************************************************************************/
32#define MET_DEFINE_PROBE(probe_name, proto) \
33 static void probe_##probe_name(void *data, PARAMS(proto))
34#define MET_REGISTER_TRACE(probe_name) \
35 register_trace_##probe_name(probe_##probe_name, NULL)
36#define MET_UNREGISTER_TRACE(probe_name) \
37 unregister_trace_##probe_name(probe_##probe_name, NULL)
38
39struct met_api_tbl {
40 int (*met_tag_start)(unsigned int class_id,
41 const char *name);
42 int (*met_tag_end)(unsigned int class_id,
43 const char *name);
44 int (*met_tag_async_start)(unsigned int class_id,
45 const char *name,
46 unsigned int cookie);
47 int (*met_tag_async_end)(unsigned int class_id,
48 const char *name,
49 unsigned int cookie);
50 int (*met_tag_oneshot)(unsigned int class_id,
51 const char *name,
52 unsigned int value);
53 int (*met_tag_userdata)(char *pData);
54 int (*met_tag_dump)(unsigned int class_id,
55 const char *name,
56 void *data,
57 unsigned int length);
58 int (*met_tag_disable)(unsigned int class_id);
59 int (*met_tag_enable)(unsigned int class_id);
60 int (*met_set_dump_buffer)(int size);
61 int (*met_save_dump_buffer)(const char *pathname);
62 int (*met_save_log)(const char *pathname);
63 int (*met_show_bw_limiter)(void);
64 int (*met_reg_bw_limiter)(void *fp);
65 int (*met_show_clk_tree)(const char *name,
66 unsigned int addr,
67 unsigned int status);
68 int (*met_reg_clk_tree)(void *fp);
69 void (*met_sched_switch)(struct task_struct *prev,
70 struct task_struct *next);
71 int (*enable_met_backlight_tag)(void);
72 int (*output_met_backlight_tag)(int level);
73};
74
75struct met_api_tbl met_ext_api;
76EXPORT_SYMBOL(met_ext_api);
77
78#if 0
79int met_tag_init(void)
80{
81 return 0;
82}
83EXPORT_SYMBOL(met_tag_init);
84
85int met_tag_uninit(void)
86{
87 return 0;
88}
89EXPORT_SYMBOL(met_tag_uninit);
90#endif
91
92int met_tag_start(unsigned int class_id, const char *name)
93{
94 if (met_ext_api.met_tag_start)
95 return met_ext_api.met_tag_start(class_id, name);
96 return 0;
97}
98EXPORT_SYMBOL(met_tag_start);
99
100int met_tag_end(unsigned int class_id, const char *name)
101{
102 if (met_ext_api.met_tag_end)
103 return met_ext_api.met_tag_end(class_id, name);
104 return 0;
105}
106EXPORT_SYMBOL(met_tag_end);
107
108int met_tag_async_start(unsigned int class_id,
109 const char *name,
110 unsigned int cookie)
111{
112 if (met_ext_api.met_tag_async_start)
113 return met_ext_api.met_tag_async_start(class_id, name, cookie);
114 return 0;
115}
116EXPORT_SYMBOL(met_tag_async_start);
117
118int met_tag_async_end(unsigned int class_id,
119 const char *name,
120 unsigned int cookie)
121{
122 if (met_ext_api.met_tag_async_end)
123 return met_ext_api.met_tag_async_end(class_id, name, cookie);
124 return 0;
125}
126EXPORT_SYMBOL(met_tag_async_end);
127
128int met_tag_oneshot(unsigned int class_id, const char *name, unsigned int value)
129{
130 if (met_ext_api.met_tag_oneshot)
131 return met_ext_api.met_tag_oneshot(class_id, name, value);
132 return 0;
133}
134EXPORT_SYMBOL(met_tag_oneshot);
135
136int met_tag_userdata(char *pData)
137{
138 if (met_ext_api.met_tag_userdata)
139 return met_ext_api.met_tag_userdata(pData);
140 return 0;
141}
142EXPORT_SYMBOL(met_tag_userdata);
143
144int met_tag_dump(unsigned int class_id,
145 const char *name,
146 void *data,
147 unsigned int length)
148{
149 if (met_ext_api.met_tag_dump)
150 return met_ext_api.met_tag_dump(class_id, name, data, length);
151 return 0;
152}
153EXPORT_SYMBOL(met_tag_dump);
154
155int met_tag_disable(unsigned int class_id)
156{
157 if (met_ext_api.met_tag_disable)
158 return met_ext_api.met_tag_disable(class_id);
159 return 0;
160}
161EXPORT_SYMBOL(met_tag_disable);
162
163int met_tag_enable(unsigned int class_id)
164{
165 if (met_ext_api.met_tag_enable)
166 return met_ext_api.met_tag_enable(class_id);
167 return 0;
168}
169EXPORT_SYMBOL(met_tag_enable);
170
171int met_set_dump_buffer(int size)
172{
173 if (met_ext_api.met_set_dump_buffer)
174 return met_ext_api.met_set_dump_buffer(size);
175 return 0;
176}
177EXPORT_SYMBOL(met_set_dump_buffer);
178
179int met_save_dump_buffer(const char *pathname)
180{
181 if (met_ext_api.met_save_dump_buffer)
182 return met_ext_api.met_save_dump_buffer(pathname);
183 return 0;
184}
185EXPORT_SYMBOL(met_save_dump_buffer);
186
187int met_save_log(const char *pathname)
188{
189 if (met_ext_api.met_save_log)
190 return met_ext_api.met_save_log(pathname);
191 return 0;
192}
193EXPORT_SYMBOL(met_save_log);
194
195int met_show_bw_limiter(void)
196{
197 if (met_ext_api.met_show_bw_limiter)
198 return met_ext_api.met_show_bw_limiter();
199 return 0;
200}
201EXPORT_SYMBOL(met_show_bw_limiter);
202
203int met_reg_bw_limiter(void *fp)
204{
205 if (met_ext_api.met_reg_bw_limiter)
206 return met_ext_api.met_reg_bw_limiter(fp);
207 return 0;
208}
209EXPORT_SYMBOL(met_reg_bw_limiter);
210
211int met_show_clk_tree(const char *name,
212 unsigned int addr,
213 unsigned int status)
214{
215 if (met_ext_api.met_show_clk_tree)
216 return met_ext_api.met_show_clk_tree(name, addr, status);
217 return 0;
218}
219EXPORT_SYMBOL(met_show_clk_tree);
220
221int met_reg_clk_tree(void *fp)
222{
223 if (met_ext_api.met_reg_clk_tree)
224 return met_ext_api.met_reg_clk_tree(fp);
225 return 0;
226}
227EXPORT_SYMBOL(met_reg_clk_tree);
228
229MET_DEFINE_PROBE(sched_switch,
230 TP_PROTO(bool preempt,
231 struct task_struct *prev,
232 struct task_struct *next))
233{
234 if (met_ext_api.met_sched_switch)
235 met_ext_api.met_sched_switch(prev, next);
236}
237
238int met_reg_switch(void)
239{
240 if (MET_REGISTER_TRACE(sched_switch)) {
241 pr_debug("can not register callback of sched_switch\n");
242 return -ENODEV;
243 } else
244 return 0;
245}
246EXPORT_SYMBOL(met_reg_switch);
247
248void met_unreg_switch(void)
249{
250 MET_UNREGISTER_TRACE(sched_switch);
251}
252EXPORT_SYMBOL(met_unreg_switch);
253
254#if defined(CONFIG_MET_ARM_32BIT)
255void met_get_cpuinfo(int cpu, struct cpuinfo_arm **cpuinfo)
256{
257 *cpuinfo = &per_cpu(cpu_data, cpu);
258}
259#else
260void met_get_cpuinfo(int cpu, struct cpuinfo_arm64 **cpuinfo)
261{
262 *cpuinfo = &per_cpu(cpu_data, cpu);
263}
264#endif
265EXPORT_SYMBOL(met_get_cpuinfo);
266
267void met_cpu_frequency(unsigned int frequency, unsigned int cpu_id)
268{
269 trace_cpu_frequency(frequency, cpu_id);
270}
271EXPORT_SYMBOL(met_cpu_frequency);
272
273void met_tracing_record_cmdline(struct task_struct *tsk)
274{
275 tracing_record_cmdline(tsk);
276}
277EXPORT_SYMBOL(met_tracing_record_cmdline);
278
279void met_set_kptr_restrict(int value)
280{
281 kptr_restrict = value;
282}
283EXPORT_SYMBOL(met_set_kptr_restrict);
284
285int met_get_kptr_restrict(void)
286{
287 return kptr_restrict;
288}
289EXPORT_SYMBOL(met_get_kptr_restrict);
290
291void met_arch_setup_dma_ops(struct device *dev)
292{
293 arch_setup_dma_ops(dev, 0, 0, NULL, false);
294}
295EXPORT_SYMBOL(met_arch_setup_dma_ops);
296
297#if 1
298int enable_met_backlight_tag(void)
299{
300 if (met_ext_api.enable_met_backlight_tag)
301 return met_ext_api.enable_met_backlight_tag();
302 return 0;
303}
304EXPORT_SYMBOL(enable_met_backlight_tag);
305
306int output_met_backlight_tag(int level)
307{
308 if (met_ext_api.output_met_backlight_tag)
309 return met_ext_api.output_met_backlight_tag(level);
310 return 0;
311}
312EXPORT_SYMBOL(output_met_backlight_tag);
313#endif
314
315/* the following handle weak function in met_drv.h */
316void met_mmsys_event_gce_thread_begin(ulong thread_no, ulong task_handle,
317 ulong engineFlag, void *pCmd, ulong size)
318{
319}
320EXPORT_SYMBOL(met_mmsys_event_gce_thread_begin);
321
322void met_mmsys_event_gce_thread_end(ulong thread_no,
323 ulong task_handle,
324 ulong engineFlag)
325{
326}
327EXPORT_SYMBOL(met_mmsys_event_gce_thread_end);
328
329void met_mmsys_event_disp_sof(int mutex_id)
330{
331}
332EXPORT_SYMBOL(met_mmsys_event_disp_sof);
333
334void met_mmsys_event_disp_mutex_eof(int mutex_id)
335{
336}
337EXPORT_SYMBOL(met_mmsys_event_disp_mutex_eof);
338
339void met_mmsys_event_disp_ovl_eof(int ovl_id)
340{
341}
342EXPORT_SYMBOL(met_mmsys_event_disp_ovl_eof);
343
344void met_mmsys_config_isp_base_addr(unsigned long *isp_reg_list)
345{
346}
347EXPORT_SYMBOL(met_mmsys_config_isp_base_addr);
348
349void met_mmsys_event_isp_pass1_begin(int sensor_id)
350{
351}
352EXPORT_SYMBOL(met_mmsys_event_isp_pass1_begin);
353
354void met_mmsys_event_isp_pass1_end(int sensor_id)
355{
356}
357EXPORT_SYMBOL(met_mmsys_event_isp_pass1_end);
358
359void met_show_pmic_info(unsigned int RegNum, unsigned int pmic_reg)
360{
361}
362EXPORT_SYMBOL(met_show_pmic_info);
363
364u64 met_perf_event_read_local(struct perf_event *ev)
365{
366 return perf_event_read_local(ev);
367}
368EXPORT_SYMBOL(met_perf_event_read_local);
369
370struct task_struct *met_kthread_create_on_cpu(int (*threadfn)(void *data),
371 void *data, unsigned int cpu,
372 const char *namefmt)
373{
374 return kthread_create_on_cpu(threadfn, data, cpu, namefmt);
375}
376EXPORT_SYMBOL(met_kthread_create_on_cpu);
377
378int met_smp_call_function_single(
379 int cpu,
380 smp_call_func_t func,
381 void *info,
382 int wait)
383{
384 return smp_call_function_single(cpu, func, info, wait);
385}
386EXPORT_SYMBOL(met_smp_call_function_single);
387
388u64 met_arch_counter_get_cntvct(void)
389{
390 return arch_counter_get_cntvct();
391}
392EXPORT_SYMBOL(met_arch_counter_get_cntvct);
393
394void met_arch_send_call_function_single_ipi(int cpu)
395{
396 return arch_send_call_function_single_ipi(cpu);
397}
398EXPORT_SYMBOL(met_arch_send_call_function_single_ipi);