blob: c6ebf3356cbff6051664b901c669f988a2ab507c [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2019 MediaTek Inc.
4 * Author: Ming-Fan Chen <ming-fan.chen@mediatek.com>
5 */
6#ifndef MMQOS_MTK_H
7#define MMQOS_MTK_H
8
9#include <linux/interconnect-provider.h>
10#include <linux/notifier.h>
11#include <linux/platform_device.h>
12#include <linux/workqueue.h>
13#include <soc/mediatek/mmqos.h>
14
15#define MMQOS_NO_LINK (0xffffffff)
16#define MMQOS_MAX_COMM_PORT_NUM (15)
17
18struct mmqos_hrt {
19 u32 hrt_bw[HRT_TYPE_NUM];
20 u32 hrt_total_bw;
21 u32 cam_max_bw;
22 u32 cam_occu_bw;
23 bool blocking;
24 struct delayed_work work;
25 struct blocking_notifier_head hrt_bw_throttle_notifier;
26 atomic_t lock_count;
27 wait_queue_head_t hrt_wait;
28 struct mutex blocking_lock;
29};
30
31struct mmqos_base_node {
32 struct icc_node *icc_node;
33 u32 mix_bw;
34};
35
36struct common_node {
37 struct mmqos_base_node *base;
38 const char *clk_name;
39 struct clk *clk;
40 u64 freq;
41 struct list_head list;
42 struct icc_path *icc_path;
43 struct work_struct work;
44 struct list_head comm_port_list;
45};
46
47struct common_port_node {
48 struct mmqos_base_node *base;
49 struct common_node *common;
50 struct device *larb_dev;
51 struct mutex bw_lock;
52 u32 latest_mix_bw;
53 u32 latest_peak_bw;
54 u32 latest_avg_bw;
55 struct list_head list;
56};
57
58struct larb_node {
59 struct mmqos_base_node *base;
60 struct device *larb_dev;
61};
62
63struct larb_port_node {
64 struct mmqos_base_node *base;
65 u16 bw_ratio;
66};
67
68struct mtk_mmqos {
69 struct device *dev;
70 struct icc_provider prov;
71 struct notifier_block nb;
72 struct list_head comm_list;
73 struct workqueue_struct *wq;
74 u32 max_ratio;
75 bool qos_bound; /* Todo: Set qos_bound to true if necessary */
76};
77
78struct mtk_node_desc {
79 const char *name;
80 u32 id;
81 u32 link;
82 u16 bw_ratio;
83};
84
85struct mtk_mmqos_desc {
86 const struct mtk_node_desc *nodes;
87 const size_t num_nodes;
88 const char * const *comm_muxes;
89 const char * const *comm_icc_path_names;
90 const u32 max_ratio;
91 const struct mmqos_hrt hrt;
92};
93
94#define DEFINE_MNODE(_name, _id, _bw_ratio, _link) { \
95 .name = #_name, \
96 .id = _id, \
97 .bw_ratio = _bw_ratio, \
98 .link = _link, \
99 }
100
101int mtk_mmqos_probe(struct platform_device *pdev);
102int mtk_mmqos_remove(struct platform_device *pdev);
103
104/* For HRT */
105void mtk_mmqos_init_hrt(struct mmqos_hrt *hrt);
106int mtk_mmqos_register_hrt_sysfs(struct device *dev);
107void mtk_mmqos_unregister_hrt_sysfs(struct device *dev);
108#endif /* MMQOS_MTK_H */