blob: 1e5ab0359be69444d5b4c59a897d255a2cd0f925 [file] [log] [blame]
Odelu Kukatla73820752017-10-30 13:27:16 +05301/*
2 *Copyright (c) 2014-2015, 2017, The Linux Foundation. All rights reserved.
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 and
6 *only version 2 as 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. See the
11 *GNU General Public License for more details.
12 */
13
14#ifndef DEVFREQ_SPDM_H
15#define DEVFREQ_SPDM_H
16
17#include <linux/list.h>
18#ifdef CONFIG_MSM_HVC
19#include <soc/qcom/hvc.h>
20#endif
21#include <soc/qcom/scm.h>
22
23enum pl_levels { SPDM_PL1, SPDM_PL2, SPDM_PL3, SPDM_PL_COUNT };
24enum actions { SPDM_UP, SPDM_DOWN };
25enum spdm_client { SPDM_CLIENT_CPU, SPDM_CLIENT_GPU, SPDM_CLIENT_COUNT };
26
27struct spdm_config_data {
28 /* in MB/s */
29 u32 upstep;
30 u32 downstep;
31 u32 up_step_multp;
32
33 u32 num_ports;
34 u32 *ports;
35 u32 aup;
36 u32 adown;
37 u32 bucket_size;
38
39 /*
40 * If We define n PL levels we need n-1 frequencies to tell
41 * where to change from one pl to another
42 */
43 /* hz */
44 u32 pl_freqs[SPDM_PL_COUNT - 1];
45 /*
46 * We have a low threshold and a high threhold for each pl to support
47 * the two port solution so we need twice as many entries as
48 * performance levels
49 */
50 /* in 100th's of a percent */
51 u32 reject_rate[SPDM_PL_COUNT * 2];
52 u32 response_time_us[SPDM_PL_COUNT * 2];
53 u32 cci_response_time_us[SPDM_PL_COUNT * 2];
54 /* hz */
55 u32 max_cci_freq;
56 /* in MB/s */
57 u32 max_vote;
58
59};
60
61struct spdm_data {
62 /* bus scaling data */
63 int cur_idx;
64 struct msm_bus_scale_pdata *pdata;
65 u32 bus_scale_client_id;
66 /* in mb/s */
67 u32 new_bw;
68
69 /* devfreq data */
70 struct devfreq *devfreq;
71 struct devfreq_dev_profile *profile;
72 unsigned long action;
73 int window;
74 struct clk *cci_clk;
75
76 /* spdm hw/gov data */
77 struct spdm_config_data config_data;
78
79 enum spdm_client spdm_client;
80 /* list used by governor to keep track of spdm devices */
81 struct list_head list;
82
83 struct dentry *debugfs_dir;
84
85 bool enabled;
86};
87
88extern void spdm_init_debugfs(struct device *dev);
89extern void spdm_remove_debugfs(struct spdm_data *data);
90
91#define SPDM_HYP_FNID 5
92#define SPDM_SCM_SVC_ID 0x9
93#define SPDM_SCM_CMD_ID 0x4
94#define SPDM_TZ_VERSION 0x20000 /* TZ SPDM driver version */
95/* SPDM CMD ID's for hypervisor/SCM */
96#define SPDM_CMD_GET_VERSION 0
97#define SPDM_CMD_GET_BW_ALL 1
98#define SPDM_CMD_GET_BW_SPECIFIC 2
99#define SPDM_CMD_ENABLE 3
100#define SPDM_CMD_DISABLE 4
101#define SPDM_CMD_CFG_PORTS 5
102#define SPDM_CMD_CFG_FLTR 6
103#define SPDM_CMD_CFG_PL 7
104#define SPDM_CMD_CFG_REJRATE_LOW 8
105#define SPDM_CMD_CFG_REJRATE_MED 9
106#define SPDM_CMD_CFG_REJRATE_HIGH 10
107#define SPDM_CMD_CFG_RESPTIME_LOW 11
108#define SPDM_CMD_CFG_RESPTIME_MED 12
109#define SPDM_CMD_CFG_RESPTIME_HIGH 13
110#define SPDM_CMD_CFG_CCIRESPTIME_LOW 14
111#define SPDM_CMD_CFG_CCIRESPTIME_MED 15
112#define SPDM_CMD_CFG_CCIRESPTIME_HIGH 16
113#define SPDM_CMD_CFG_MAXCCI 17
114#define SPDM_CMD_CFG_VOTES 18
115
116#define SPDM_MAX_ARGS 6
117#define SPDM_MAX_RETS 3
118
119struct spdm_args {
120 u64 arg[SPDM_MAX_ARGS];
121 u64 ret[SPDM_MAX_RETS];
122};
123
124#ifdef CONFIG_SPDM_SCM
125extern int __spdm_scm_call(struct spdm_args *args, int num_args);
126#define spdm_ext_call __spdm_scm_call
127#else
128extern int __spdm_hyp_call(struct spdm_args *args, int num_args);
129#define spdm_ext_call __spdm_hyp_call
130#endif
131#endif