blob: da149c51c96cc2d0ba79ed1c7bb4ad2236619890 [file] [log] [blame]
Amir Levy9659e592016-10-27 18:08:27 +03001/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _IPA_RM_RESOURCE_H_
14#define _IPA_RM_RESOURCE_H_
15
16#include <linux/list.h>
17#include <linux/ipa.h>
18#include "ipa_rm_peers_list.h"
19
20/**
21 * enum ipa_rm_resource_state - resource state
22 */
23enum ipa_rm_resource_state {
24 IPA_RM_RELEASED,
25 IPA_RM_REQUEST_IN_PROGRESS,
26 IPA_RM_GRANTED,
27 IPA_RM_RELEASE_IN_PROGRESS
28};
29
30/**
31 * enum ipa_rm_resource_type - IPA resource manager resource type
32 */
33enum ipa_rm_resource_type {
34 IPA_RM_PRODUCER,
35 IPA_RM_CONSUMER
36};
37
38/**
39 * struct ipa_rm_notification_info - notification information
40 * of IPA RM client
41 * @reg_params: registration parameters
42 * @explicit: registered explicitly by ipa_rm_register()
43 * @link: link to the list of all registered clients information
44 */
45struct ipa_rm_notification_info {
46 struct ipa_rm_register_params reg_params;
47 bool explicit;
48 struct list_head link;
49};
50
51/**
52 * struct ipa_rm_resource - IPA RM resource
53 * @name: name identifying resource
54 * @type: type of resource (PRODUCER or CONSUMER)
55 * @floor_voltage: minimum voltage level for operation
56 * @max_bw: maximum bandwidth required for resource in Mbps
57 * @state: state of the resource
58 * @peers_list: list of the peers of the resource
59 */
60struct ipa_rm_resource {
61 enum ipa_rm_resource_name name;
62 enum ipa_rm_resource_type type;
63 enum ipa_voltage_level floor_voltage;
64 u32 max_bw;
65 u32 needed_bw;
66 enum ipa_rm_resource_state state;
67 struct ipa_rm_peers_list *peers_list;
68};
69
70/**
71 * struct ipa_rm_resource_cons - IPA RM consumer
72 * @resource: resource
73 * @usage_count: number of producers in GRANTED / REQUESTED state
74 * using this consumer
75 * @request_consumer_in_progress: when set, the consumer is during its request
76 * phase
77 * @request_resource: function which should be called to request resource
78 * from resource manager
79 * @release_resource: function which should be called to release resource
80 * from resource manager
81 * Add new fields after @resource only.
82 */
83struct ipa_rm_resource_cons {
84 struct ipa_rm_resource resource;
85 int usage_count;
86 struct completion request_consumer_in_progress;
87 int (*request_resource)(void);
88 int (*release_resource)(void);
89};
90
91/**
92 * struct ipa_rm_resource_prod - IPA RM producer
93 * @resource: resource
94 * @event_listeners: clients registered with this producer
95 * for notifications in resource state
96 * list Add new fields after @resource only.
97 */
98struct ipa_rm_resource_prod {
99 struct ipa_rm_resource resource;
100 struct list_head event_listeners;
101 int pending_request;
102 int pending_release;
103};
104
105int ipa_rm_resource_create(
106 struct ipa_rm_create_params *create_params,
107 struct ipa_rm_resource **resource);
108
109int ipa_rm_resource_delete(struct ipa_rm_resource *resource);
110
111int ipa_rm_resource_producer_register(struct ipa_rm_resource_prod *producer,
112 struct ipa_rm_register_params *reg_params,
113 bool explicit);
114
115int ipa_rm_resource_producer_deregister(struct ipa_rm_resource_prod *producer,
116 struct ipa_rm_register_params *reg_params);
117
118int ipa_rm_resource_add_dependency(struct ipa_rm_resource *resource,
119 struct ipa_rm_resource *depends_on,
120 bool userspace_dep);
121
122int ipa_rm_resource_delete_dependency(struct ipa_rm_resource *resource,
123 struct ipa_rm_resource *depends_on,
124 bool userspace_dep);
125
126int ipa_rm_resource_producer_request(struct ipa_rm_resource_prod *producer);
127
128int ipa_rm_resource_producer_release(struct ipa_rm_resource_prod *producer);
129
130int ipa_rm_resource_consumer_request(struct ipa_rm_resource_cons *consumer,
131 u32 needed_bw,
132 bool inc_usage_count,
133 bool wake_client);
134
135int ipa_rm_resource_consumer_release(struct ipa_rm_resource_cons *consumer,
136 u32 needed_bw,
137 bool dec_usage_count);
138
139int ipa_rm_resource_set_perf_profile(struct ipa_rm_resource *resource,
140 struct ipa_rm_perf_profile *profile);
141
142void ipa_rm_resource_consumer_handle_cb(struct ipa_rm_resource_cons *consumer,
143 enum ipa_rm_event event);
144
145void ipa_rm_resource_producer_notify_clients(
146 struct ipa_rm_resource_prod *producer,
147 enum ipa_rm_event event,
148 bool notify_registered_only);
149
150int ipa_rm_resource_producer_print_stat(
151 struct ipa_rm_resource *resource,
152 char *buf,
153 int size);
154
155int ipa_rm_resource_consumer_request_work(struct ipa_rm_resource_cons *consumer,
156 enum ipa_rm_resource_state prev_state,
157 u32 needed_bw,
Gidon Studinski3021a6f2016-11-10 12:48:48 +0200158 bool notify_completion,
159 bool dec_client_on_err);
Amir Levy9659e592016-10-27 18:08:27 +0300160
161int ipa_rm_resource_consumer_release_work(
162 struct ipa_rm_resource_cons *consumer,
163 enum ipa_rm_resource_state prev_state,
164 bool notify_completion);
165
166#endif /* _IPA_RM_RESOURCE_H_ */