Skylar Chang | a951658 | 2017-05-09 11:36:47 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved. |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 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_I_H_ |
| 14 | #define _IPA_RM_I_H_ |
| 15 | |
| 16 | #include <linux/workqueue.h> |
| 17 | #include <linux/ipa.h> |
| 18 | #include "ipa_rm_resource.h" |
| 19 | #include "ipa_common_i.h" |
| 20 | |
| 21 | #define IPA_RM_DRV_NAME "ipa_rm" |
| 22 | |
| 23 | #define IPA_RM_DBG_LOW(fmt, args...) \ |
| 24 | do { \ |
| 25 | pr_debug(IPA_RM_DRV_NAME " %s:%d " fmt, __func__, __LINE__, \ |
| 26 | ## args); \ |
| 27 | IPA_IPC_LOGGING(ipa_get_ipc_logbuf_low(), \ |
| 28 | IPA_RM_DRV_NAME " %s:%d " fmt, ## args); \ |
| 29 | } while (0) |
| 30 | #define IPA_RM_DBG(fmt, args...) \ |
| 31 | do { \ |
| 32 | pr_debug(IPA_RM_DRV_NAME " %s:%d " fmt, __func__, __LINE__, \ |
| 33 | ## args); \ |
| 34 | IPA_IPC_LOGGING(ipa_get_ipc_logbuf(), \ |
| 35 | IPA_RM_DRV_NAME " %s:%d " fmt, ## args); \ |
| 36 | IPA_IPC_LOGGING(ipa_get_ipc_logbuf_low(), \ |
| 37 | IPA_RM_DRV_NAME " %s:%d " fmt, ## args); \ |
| 38 | } while (0) |
| 39 | |
| 40 | #define IPA_RM_ERR(fmt, args...) \ |
| 41 | do { \ |
| 42 | pr_err(IPA_RM_DRV_NAME " %s:%d " fmt, __func__, __LINE__, \ |
| 43 | ## args); \ |
| 44 | IPA_IPC_LOGGING(ipa_get_ipc_logbuf(), \ |
| 45 | IPA_RM_DRV_NAME " %s:%d " fmt, ## args); \ |
| 46 | IPA_IPC_LOGGING(ipa_get_ipc_logbuf_low(), \ |
| 47 | IPA_RM_DRV_NAME " %s:%d " fmt, ## args); \ |
| 48 | } while (0) |
| 49 | |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 50 | #define IPA_RM_RESORCE_IS_PROD(x) \ |
Skylar Chang | a951658 | 2017-05-09 11:36:47 -0700 | [diff] [blame] | 51 | (x < IPA_RM_RESOURCE_MAX && (x & 0x1) == 0) |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 52 | #define IPA_RM_RESORCE_IS_CONS(x) \ |
Skylar Chang | a951658 | 2017-05-09 11:36:47 -0700 | [diff] [blame] | 53 | (x < IPA_RM_RESOURCE_MAX && (x & 0x1) == 1) |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 54 | #define IPA_RM_INDEX_INVALID (-1) |
| 55 | #define IPA_RM_RELEASE_DELAY_IN_MSEC 1000 |
| 56 | |
| 57 | int ipa_rm_prod_index(enum ipa_rm_resource_name resource_name); |
| 58 | int ipa_rm_cons_index(enum ipa_rm_resource_name resource_name); |
| 59 | |
| 60 | /** |
| 61 | * struct ipa_rm_delayed_release_work_type - IPA RM delayed resource release |
| 62 | * work type |
| 63 | * @delayed_work: work struct |
| 64 | * @ipa_rm_resource_name: name of the resource on which this work should be done |
| 65 | * @needed_bw: bandwidth required for resource in Mbps |
| 66 | * @dec_usage_count: decrease usage count on release ? |
| 67 | */ |
| 68 | struct ipa_rm_delayed_release_work_type { |
| 69 | struct delayed_work work; |
| 70 | enum ipa_rm_resource_name resource_name; |
| 71 | u32 needed_bw; |
| 72 | bool dec_usage_count; |
| 73 | |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * enum ipa_rm_wq_cmd - workqueue commands |
| 78 | */ |
| 79 | enum ipa_rm_wq_cmd { |
| 80 | IPA_RM_WQ_NOTIFY_PROD, |
| 81 | IPA_RM_WQ_NOTIFY_CONS, |
| 82 | IPA_RM_WQ_RESOURCE_CB |
| 83 | }; |
| 84 | |
| 85 | /** |
| 86 | * struct ipa_rm_wq_work_type - IPA RM worqueue specific |
| 87 | * work type |
| 88 | * @work: work struct |
| 89 | * @wq_cmd: command that should be processed in workqueue context |
| 90 | * @resource_name: name of the resource on which this work |
| 91 | * should be done |
| 92 | * @dep_graph: data structure to search for resource if exists |
| 93 | * @event: event to notify |
| 94 | * @notify_registered_only: notify only clients registered by |
| 95 | * ipa_rm_register() |
| 96 | */ |
| 97 | struct ipa_rm_wq_work_type { |
| 98 | struct work_struct work; |
| 99 | enum ipa_rm_wq_cmd wq_cmd; |
| 100 | enum ipa_rm_resource_name resource_name; |
| 101 | enum ipa_rm_event event; |
| 102 | bool notify_registered_only; |
| 103 | }; |
| 104 | |
| 105 | /** |
| 106 | * struct ipa_rm_wq_suspend_resume_work_type - IPA RM worqueue resume or |
| 107 | * suspend work type |
| 108 | * @work: work struct |
| 109 | * @resource_name: name of the resource on which this work |
| 110 | * should be done |
| 111 | * @prev_state: |
| 112 | * @needed_bw: |
| 113 | */ |
| 114 | struct ipa_rm_wq_suspend_resume_work_type { |
| 115 | struct work_struct work; |
| 116 | enum ipa_rm_resource_name resource_name; |
| 117 | enum ipa_rm_resource_state prev_state; |
| 118 | u32 needed_bw; |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 119 | bool inc_usage_count; |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 120 | |
| 121 | }; |
| 122 | |
| 123 | int ipa_rm_wq_send_cmd(enum ipa_rm_wq_cmd wq_cmd, |
| 124 | enum ipa_rm_resource_name resource_name, |
| 125 | enum ipa_rm_event event, |
| 126 | bool notify_registered_only); |
| 127 | |
| 128 | int ipa_rm_wq_send_resume_cmd(enum ipa_rm_resource_name resource_name, |
| 129 | enum ipa_rm_resource_state prev_state, |
Gidon Studinski | 3021a6f | 2016-11-10 12:48:48 +0200 | [diff] [blame] | 130 | u32 needed_bw, |
| 131 | bool inc_usage_count); |
Amir Levy | 9659e59 | 2016-10-27 18:08:27 +0300 | [diff] [blame] | 132 | |
| 133 | int ipa_rm_wq_send_suspend_cmd(enum ipa_rm_resource_name resource_name, |
| 134 | enum ipa_rm_resource_state prev_state, |
| 135 | u32 needed_bw); |
| 136 | |
| 137 | int ipa_rm_initialize(void); |
| 138 | |
| 139 | int ipa_rm_stat(char *buf, int size); |
| 140 | |
| 141 | const char *ipa_rm_resource_str(enum ipa_rm_resource_name resource_name); |
| 142 | |
| 143 | void ipa_rm_perf_profile_change(enum ipa_rm_resource_name resource_name); |
| 144 | |
| 145 | int ipa_rm_request_resource_with_timer(enum ipa_rm_resource_name resource_name); |
| 146 | |
| 147 | void delayed_release_work_func(struct work_struct *work); |
| 148 | |
| 149 | int ipa_rm_add_dependency_from_ioctl(enum ipa_rm_resource_name resource_name, |
| 150 | enum ipa_rm_resource_name depends_on_name); |
| 151 | |
| 152 | int ipa_rm_delete_dependency_from_ioctl(enum ipa_rm_resource_name resource_name, |
| 153 | enum ipa_rm_resource_name depends_on_name); |
| 154 | |
| 155 | void ipa_rm_exit(void); |
| 156 | |
| 157 | #endif /* _IPA_RM_I_H_ */ |