Raja Mallik | ff6c75b | 2019-01-29 16:52:37 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. |
Raja Mallik | c7e256f | 2018-12-06 17:36:28 +0530 | [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 _CAM_HW_MGR_INTF_H_ |
| 14 | #define _CAM_HW_MGR_INTF_H_ |
| 15 | |
| 16 | #include <linux/time.h> |
| 17 | #include <linux/types.h> |
| 18 | |
| 19 | /* |
| 20 | * This file declares Constants, Enums, Structures and APIs to be used as |
| 21 | * Interface between HW Manager and Context. |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | /* maximum context numbers */ |
| 26 | #define CAM_CTX_MAX 8 |
| 27 | |
| 28 | /* maximum buf done irqs */ |
| 29 | #define CAM_NUM_OUT_PER_COMP_IRQ_MAX 12 |
| 30 | |
| 31 | /* hardware event callback function type */ |
| 32 | typedef int (*cam_hw_event_cb_func)(void *context, uint32_t evt_id, |
| 33 | void *evt_data); |
| 34 | |
| 35 | /* hardware page fault callback function type */ |
| 36 | typedef int (*cam_hw_pagefault_cb_func)(void *context, unsigned long iova, |
| 37 | uint32_t buf_info); |
| 38 | |
| 39 | /** |
| 40 | * struct cam_hw_update_entry - Entry for hardware config |
| 41 | * |
| 42 | * @handle: Memory handle for the configuration |
| 43 | * @offset: Memory offset |
| 44 | * @len: Size of the configuration |
| 45 | * @flags: Flags for the config entry(eg. DMI) |
| 46 | * @addr: Address of hardware update entry |
| 47 | * |
| 48 | */ |
| 49 | struct cam_hw_update_entry { |
| 50 | int handle; |
| 51 | uint32_t offset; |
| 52 | uint32_t len; |
| 53 | uint32_t flags; |
| 54 | uintptr_t addr; |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * struct cam_hw_fence_map_entry - Entry for the resource to sync id map |
| 59 | * |
| 60 | * @resrouce_handle: Resource port id for the buffer |
| 61 | * @sync_id: Sync id |
| 62 | * |
| 63 | */ |
| 64 | struct cam_hw_fence_map_entry { |
| 65 | uint32_t resource_handle; |
| 66 | int32_t sync_id; |
| 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * struct cam_hw_done_event_data - Payload for hw done event |
| 71 | * |
| 72 | * @num_handles: number of handles in the event |
| 73 | * @resrouce_handle: list of the resource handle |
| 74 | * @timestamp: time stamp |
| 75 | * @request_id: request identifier |
| 76 | * |
| 77 | */ |
| 78 | struct cam_hw_done_event_data { |
| 79 | uint32_t num_handles; |
| 80 | uint32_t resource_handle[CAM_NUM_OUT_PER_COMP_IRQ_MAX]; |
| 81 | struct timeval timestamp; |
| 82 | uint64_t request_id; |
| 83 | }; |
| 84 | |
| 85 | /** |
| 86 | * struct cam_hw_acquire_args - Payload for acquire command |
| 87 | * |
| 88 | * @context_data: Context data pointer for the callback function |
| 89 | * @event_cb: Callback function array |
| 90 | * @num_acq: Total number of acquire in the payload |
| 91 | * @acquire_info: Acquired resource array pointer |
| 92 | * @ctxt_to_hw_map: HW context (returned) |
| 93 | * |
| 94 | */ |
| 95 | struct cam_hw_acquire_args { |
| 96 | void *context_data; |
| 97 | cam_hw_event_cb_func event_cb; |
| 98 | uint32_t num_acq; |
| 99 | uint32_t acquire_info_size; |
| 100 | uintptr_t acquire_info; |
| 101 | void *ctxt_to_hw_map; |
| 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * struct cam_hw_release_args - Payload for release command |
| 106 | * |
| 107 | * @ctxt_to_hw_map: HW context from the acquire |
| 108 | * @active_req: Active request flag |
| 109 | * |
| 110 | */ |
| 111 | struct cam_hw_release_args { |
| 112 | void *ctxt_to_hw_map; |
| 113 | bool active_req; |
| 114 | }; |
| 115 | |
| 116 | /** |
| 117 | * struct cam_hw_start_args - Payload for start command |
| 118 | * |
| 119 | * @ctxt_to_hw_map: HW context from the acquire |
| 120 | * @num_hw_update_entries: Number of Hardware configuration |
| 121 | * @hw_update_entries: Hardware configuration list |
| 122 | * |
| 123 | */ |
| 124 | struct cam_hw_start_args { |
| 125 | void *ctxt_to_hw_map; |
| 126 | uint32_t num_hw_update_entries; |
| 127 | struct cam_hw_update_entry *hw_update_entries; |
| 128 | }; |
| 129 | |
| 130 | /** |
| 131 | * struct cam_hw_stop_args - Payload for stop command |
| 132 | * |
| 133 | * @ctxt_to_hw_map: HW context from the acquire |
| 134 | * @args: Arguments to pass for stop |
| 135 | * |
| 136 | */ |
| 137 | struct cam_hw_stop_args { |
| 138 | void *ctxt_to_hw_map; |
| 139 | void *args; |
| 140 | }; |
| 141 | |
| 142 | |
| 143 | /** |
| 144 | * struct cam_hw_mgr_dump_pf_data - page fault debug data |
| 145 | * |
| 146 | * packet: pointer to packet |
Raja Mallik | 311ee71 | 2019-05-02 15:51:11 +0530 | [diff] [blame] | 147 | * ctx_id: context id |
Raja Mallik | c7e256f | 2018-12-06 17:36:28 +0530 | [diff] [blame] | 148 | */ |
| 149 | struct cam_hw_mgr_dump_pf_data { |
| 150 | void *packet; |
Raja Mallik | 311ee71 | 2019-05-02 15:51:11 +0530 | [diff] [blame] | 151 | uint32_t ctx_id; |
Raja Mallik | c7e256f | 2018-12-06 17:36:28 +0530 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | /** |
| 155 | * struct cam_hw_prepare_update_args - Payload for prepare command |
| 156 | * |
| 157 | * @packet: CSL packet from user mode driver |
Raja Mallik | ff6c75b | 2019-01-29 16:52:37 +0530 | [diff] [blame] | 158 | * @remain_len Remaining length of CPU buffer after config offset |
Raja Mallik | c7e256f | 2018-12-06 17:36:28 +0530 | [diff] [blame] | 159 | * @ctxt_to_hw_map: HW context from the acquire |
| 160 | * @max_hw_update_entries: Maximum hardware update entries supported |
| 161 | * @hw_update_entries: Actual hardware update configuration (returned) |
| 162 | * @num_hw_update_entries: Number of actual hardware update entries (returned) |
| 163 | * @max_out_map_entries: Maximum output fence mapping supported |
| 164 | * @out_map_entries: Actual output fence mapping list (returned) |
| 165 | * @num_out_map_entries: Number of actual output fence mapping (returned) |
| 166 | * @max_in_map_entries: Maximum input fence mapping supported |
| 167 | * @in_map_entries: Actual input fence mapping list (returned) |
| 168 | * @num_in_map_entries: Number of acutal input fence mapping (returned) |
| 169 | * @priv: Private pointer of hw update |
| 170 | * @pf_data: Debug data for page fault |
| 171 | * |
| 172 | */ |
| 173 | struct cam_hw_prepare_update_args { |
| 174 | struct cam_packet *packet; |
Raja Mallik | ff6c75b | 2019-01-29 16:52:37 +0530 | [diff] [blame] | 175 | size_t remain_len; |
Raja Mallik | c7e256f | 2018-12-06 17:36:28 +0530 | [diff] [blame] | 176 | void *ctxt_to_hw_map; |
| 177 | uint32_t max_hw_update_entries; |
| 178 | struct cam_hw_update_entry *hw_update_entries; |
| 179 | uint32_t num_hw_update_entries; |
| 180 | uint32_t max_out_map_entries; |
| 181 | struct cam_hw_fence_map_entry *out_map_entries; |
| 182 | uint32_t num_out_map_entries; |
| 183 | uint32_t max_in_map_entries; |
| 184 | struct cam_hw_fence_map_entry *in_map_entries; |
| 185 | uint32_t num_in_map_entries; |
| 186 | void *priv; |
| 187 | struct cam_hw_mgr_dump_pf_data *pf_data; |
| 188 | }; |
| 189 | |
| 190 | /** |
| 191 | * struct cam_hw_stream_setttings - Payload for config stream command |
| 192 | * |
| 193 | * @packet: CSL packet from user mode driver |
| 194 | * @ctxt_to_hw_map: HW context from the acquire |
| 195 | * @priv: Private pointer of hw update |
| 196 | * |
| 197 | */ |
| 198 | struct cam_hw_stream_setttings { |
| 199 | struct cam_packet *packet; |
| 200 | void *ctxt_to_hw_map; |
| 201 | void *priv; |
| 202 | }; |
| 203 | |
| 204 | /** |
| 205 | * struct cam_hw_config_args - Payload for config command |
| 206 | * |
| 207 | * @ctxt_to_hw_map: HW context from the acquire |
| 208 | * @num_hw_update_entries: Number of hardware update entries |
| 209 | * @hw_update_entries: Hardware update list |
| 210 | * @out_map_entries: Out map info |
| 211 | * @num_out_map_entries: Number of out map entries |
| 212 | * @priv: Private pointer |
| 213 | * @request_id: Request ID |
| 214 | * |
| 215 | */ |
| 216 | struct cam_hw_config_args { |
| 217 | void *ctxt_to_hw_map; |
| 218 | uint32_t num_hw_update_entries; |
| 219 | struct cam_hw_update_entry *hw_update_entries; |
| 220 | struct cam_hw_fence_map_entry *out_map_entries; |
| 221 | uint32_t num_out_map_entries; |
| 222 | void *priv; |
| 223 | uint64_t request_id; |
| 224 | bool init_packet; |
| 225 | }; |
| 226 | |
| 227 | /** |
| 228 | * struct cam_hw_flush_args - Flush arguments |
| 229 | * |
| 230 | * @ctxt_to_hw_map: HW context from the acquire |
| 231 | * @num_req_pending: Num request to flush, valid when flush type is REQ |
| 232 | * @flush_req_pending: Request pending pointers to flush |
| 233 | * @num_req_active: Num request to flush, valid when flush type is REQ |
| 234 | * @flush_req_active: Request active pointers to flush |
| 235 | * @flush_type: The flush type |
| 236 | * |
| 237 | */ |
| 238 | struct cam_hw_flush_args { |
| 239 | void *ctxt_to_hw_map; |
| 240 | uint32_t num_req_pending; |
| 241 | void *flush_req_pending[20]; |
| 242 | uint32_t num_req_active; |
| 243 | void *flush_req_active[20]; |
| 244 | enum flush_type_t flush_type; |
| 245 | }; |
| 246 | |
| 247 | /** |
| 248 | * struct cam_hw_dump_pf_args - Payload for dump pf info command |
| 249 | * |
| 250 | * @pf_data: Debug data for page fault |
| 251 | * @iova: Page fault address |
| 252 | * @buf_info: Info about memory buffer where page |
| 253 | * fault occurred |
| 254 | * @mem_found: If fault memory found in current |
| 255 | * request |
| 256 | * |
| 257 | */ |
| 258 | struct cam_hw_dump_pf_args { |
| 259 | struct cam_hw_mgr_dump_pf_data pf_data; |
| 260 | unsigned long iova; |
| 261 | uint32_t buf_info; |
| 262 | bool *mem_found; |
| 263 | }; |
| 264 | |
Raja Mallik | e3ed1a3 | 2019-08-22 17:12:32 +0530 | [diff] [blame] | 265 | /** |
| 266 | * struct cam_hw_reset_args -hw reset arguments |
| 267 | * |
| 268 | * @ctxt_to_hw_map: HW context from the acquire |
| 269 | * |
| 270 | */ |
| 271 | struct cam_hw_reset_args { |
| 272 | void *ctxt_to_hw_map; |
| 273 | }; |
| 274 | |
Raja Mallik | 971acc6 | 2019-08-29 14:36:19 +0530 | [diff] [blame^] | 275 | /** |
| 276 | * struct cam_hw_dump_args - Dump arguments |
| 277 | * |
| 278 | * @request_id: request_id |
| 279 | * @buf_handle: Buffer handle |
| 280 | * @offset: Buffer offset. This is updated by the drivers. |
| 281 | * @ctxt_to_hw_map: HW context from the acquire |
| 282 | */ |
| 283 | struct cam_hw_dump_args { |
| 284 | uint64_t request_id; |
| 285 | uint32_t buf_handle; |
| 286 | int32_t offset; |
| 287 | void *ctxt_to_hw_map; |
| 288 | }; |
| 289 | |
Raja Mallik | c7e256f | 2018-12-06 17:36:28 +0530 | [diff] [blame] | 290 | /* enum cam_hw_mgr_command - Hardware manager command type */ |
| 291 | enum cam_hw_mgr_command { |
| 292 | CAM_HW_MGR_CMD_INTERNAL, |
| 293 | CAM_HW_MGR_CMD_DUMP_PF_INFO, |
| 294 | }; |
| 295 | |
| 296 | /** |
| 297 | * struct cam_hw_cmd_args - Payload for hw manager command |
| 298 | * |
| 299 | * @ctxt_to_hw_map: HW context from the acquire |
| 300 | * @cmd_type HW command type |
| 301 | * @internal_args Arguments for internal command |
| 302 | * @pf_args Arguments for Dump PF info command |
| 303 | * |
| 304 | */ |
| 305 | struct cam_hw_cmd_args { |
| 306 | void *ctxt_to_hw_map; |
| 307 | uint32_t cmd_type; |
| 308 | union { |
| 309 | void *internal_args; |
| 310 | struct cam_hw_dump_pf_args pf_args; |
| 311 | } u; |
| 312 | }; |
| 313 | |
| 314 | /** |
| 315 | * cam_hw_mgr_intf - HW manager interface |
| 316 | * |
| 317 | * @hw_mgr_priv: HW manager object |
| 318 | * @hw_get_caps: Function pointer for get hw caps |
| 319 | * args = cam_query_cap_cmd |
| 320 | * @hw_acquire: Function poniter for acquire hw resources |
| 321 | * args = cam_hw_acquire_args |
| 322 | * @hw_release: Function pointer for release hw device resource |
| 323 | * args = cam_hw_release_args |
| 324 | * @hw_start: Function pointer for start hw devices |
| 325 | * args = cam_hw_start_args |
| 326 | * @hw_stop: Function pointer for stop hw devices |
| 327 | * args = cam_hw_stop_args |
| 328 | * @hw_prepare_update: Function pointer for prepare hw update for hw |
| 329 | * devices args = cam_hw_prepare_update_args |
| 330 | * @hw_config_stream_settings: Function pointer for configure stream for hw |
| 331 | * devices args = cam_hw_stream_setttings |
| 332 | * @hw_config: Function pointer for configure hw devices |
| 333 | * args = cam_hw_config_args |
| 334 | * @hw_read: Function pointer for read hardware registers |
| 335 | * @hw_write: Function pointer for Write hardware registers |
| 336 | * @hw_cmd: Function pointer for any customized commands for |
| 337 | * the hardware manager |
| 338 | * @hw_open: Function pointer for HW init |
| 339 | * @hw_close: Function pointer for HW deinit |
| 340 | * @hw_flush: Function pointer for HW flush |
Raja Mallik | e3ed1a3 | 2019-08-22 17:12:32 +0530 | [diff] [blame] | 341 | * @hw_reset: Function pointer for HW reset |
Raja Mallik | 971acc6 | 2019-08-29 14:36:19 +0530 | [diff] [blame^] | 342 | * @hw_dump: Function pointer for HW dump |
Raja Mallik | c7e256f | 2018-12-06 17:36:28 +0530 | [diff] [blame] | 343 | * |
| 344 | */ |
| 345 | struct cam_hw_mgr_intf { |
| 346 | void *hw_mgr_priv; |
| 347 | |
| 348 | int (*hw_get_caps)(void *hw_priv, void *hw_caps_args); |
| 349 | int (*hw_acquire)(void *hw_priv, void *hw_acquire_args); |
| 350 | int (*hw_release)(void *hw_priv, void *hw_release_args); |
| 351 | int (*hw_start)(void *hw_priv, void *hw_start_args); |
| 352 | int (*hw_stop)(void *hw_priv, void *hw_stop_args); |
| 353 | int (*hw_prepare_update)(void *hw_priv, void *hw_prepare_update_args); |
| 354 | int (*hw_config_stream_settings)(void *hw_priv, |
| 355 | void *hw_stream_settings); |
| 356 | int (*hw_config)(void *hw_priv, void *hw_config_args); |
| 357 | int (*hw_read)(void *hw_priv, void *read_args); |
| 358 | int (*hw_write)(void *hw_priv, void *write_args); |
| 359 | int (*hw_cmd)(void *hw_priv, void *write_args); |
| 360 | int (*hw_open)(void *hw_priv, void *fw_download_args); |
| 361 | int (*hw_close)(void *hw_priv, void *hw_close_args); |
| 362 | int (*hw_flush)(void *hw_priv, void *hw_flush_args); |
Raja Mallik | e3ed1a3 | 2019-08-22 17:12:32 +0530 | [diff] [blame] | 363 | int (*hw_reset)(void *hw_priv, void *hw_reset_args); |
Raja Mallik | 971acc6 | 2019-08-29 14:36:19 +0530 | [diff] [blame^] | 364 | int (*hw_dump)(void *hw_priv, void *hw_dump_args); |
Raja Mallik | c7e256f | 2018-12-06 17:36:28 +0530 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | #endif /* _CAM_HW_MGR_INTF_H_ */ |