blob: 135e00652fd6b0e5398b3cd57364d204595b0447 [file] [log] [blame]
Pavan Kumar Chilamkurthi5719f212017-07-20 15:02:21 -07001/* Copyright (c) 2017, 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 _CAM_FD_HW_MGR_H_
14#define _CAM_FD_HW_MGR_H_
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18
19#include <media/cam_fd.h>
20#include "cam_hw.h"
21#include "cam_hw_intf.h"
22#include "cam_cpas_api.h"
23#include "cam_debug_util.h"
24#include "cam_hw_mgr_intf.h"
25#include "cam_req_mgr_workq.h"
26#include "cam_fd_hw_intf.h"
27
28#define CAM_FD_HW_MAX 1
29#define CAM_FD_WORKQ_NUM_TASK 10
30
31struct cam_fd_hw_mgr;
32
33/**
34 * enum cam_fd_mgr_work_type - Type of worker task
35 *
36 * @CAM_FD_WORK_FRAME : Work type indicating frame task
37 * @CAM_FD_WORK_IRQ : Work type indicating irq task
38 */
39enum cam_fd_mgr_work_type {
40 CAM_FD_WORK_FRAME,
41 CAM_FD_WORK_IRQ,
42};
43
44/**
45 * struct cam_fd_hw_mgr_ctx : FD HW Mgr context
46 *
47 * @list : List pointer used to maintain this context
48 * in free, used list
49 * @ctx_index : Index of this context
50 * @ctx_in_use : Whether this context is in use
51 * @event_cb : Event callback pointer to notify cam core context
52 * @cb_priv : Event callback private pointer
53 * @hw_mgr : Pointer to hw manager
54 * @get_raw_results : Whether this context needs raw results
55 * @mode : Mode in which this context runs
56 * @device_index : HW Device used by this context
57 * @ctx_hw_private : HW layer's private context pointer for this context
58 * @priority : Priority of this context
59 */
60struct cam_fd_hw_mgr_ctx {
61 struct list_head list;
62 uint32_t ctx_index;
63 bool ctx_in_use;
64 cam_hw_event_cb_func event_cb;
65 void *cb_priv;
66 struct cam_fd_hw_mgr *hw_mgr;
67 bool get_raw_results;
68 enum cam_fd_hw_mode mode;
69 int32_t device_index;
70 void *ctx_hw_private;
71 uint32_t priority;
72};
73
74/**
75 * struct cam_fd_device : FD HW Device
76 *
77 * @hw_caps : This FD device's capabilities
78 * @hw_intf : FD device's interface information
79 * @ready_to_process : Whether this device is ready to process next frame
80 * @num_ctxts : Number of context currently running on this device
81 * @valid : Whether this device is valid
82 * @lock : Lock used for protectin
83 */
84struct cam_fd_device {
85 struct cam_fd_hw_caps hw_caps;
86 struct cam_hw_intf *hw_intf;
87 bool ready_to_process;
88 uint32_t num_ctxts;
89 bool valid;
90 struct mutex lock;
91};
92
93/**
94 * struct cam_fd_mgr_frame_request : Frame request information maintained
95 * in HW Mgr layer
96 *
97 * @list : List pointer used to maintain this request in
98 * free, pending, processing request lists
99 * @request_id : Request ID corresponding to this request
100 * @hw_ctx : HW context from which this request is coming
101 * @hw_req_private : HW layer's private information specific to
102 * this request
103 * @hw_update_entries : HW update entries corresponding to this request
104 * which needs to be submitted to HW through CDM
105 * @num_hw_update_entries : Number of HW update entries
106 */
107struct cam_fd_mgr_frame_request {
108 struct list_head list;
109 uint64_t request_id;
110 struct cam_fd_hw_mgr_ctx *hw_ctx;
111 struct cam_fd_hw_req_private hw_req_private;
112 struct cam_hw_update_entry hw_update_entries[CAM_FD_MAX_HW_ENTRIES];
113 uint32_t num_hw_update_entries;
114};
115
116/**
117 * struct cam_fd_mgr_work_data : HW Mgr work data information
118 *
119 * @type : Type of work
120 * @irq_type : IRQ type when this work is queued because of irq callback
121 */
122struct cam_fd_mgr_work_data {
123 enum cam_fd_mgr_work_type type;
124 enum cam_fd_hw_irq_type irq_type;
125};
126
127/**
128 * struct cam_fd_hw_mgr : FD HW Mgr information
129 *
130 * @free_ctx_list : List of free contexts available for acquire
131 * @used_ctx_list : List of contexts that are acquired
132 * @frame_free_list : List of free frame requests available
133 * @frame_pending_list_high : List of high priority frame requests pending
134 * for processing
135 * @frame_pending_list_normal : List of normal priority frame requests pending
136 * for processing
137 * @frame_processing_list : List of frame requests currently being
138 * processed currently. Generally maximum one
139 * request would be present in this list
140 * @hw_mgr_mutex : Mutex to protect hw mgr data when accessed
141 * from multiple threads
142 * @hw_mgr_slock : Spin lock to protect hw mgr data when accessed
143 * from multiple threads
144 * @ctx_mutex : Mutex to protect context list
145 * @frame_req_mutex : Mutex to protect frame request list
146 * @device_iommu : Device IOMMU information
147 * @cdm_iommu : CDM IOMMU information
148 * @hw_device : Underlying HW device information
149 * @num_devices : Number of HW devices available
150 * @raw_results_available : Whether raw results available in this driver
151 * @supported_modes : Supported modes by this driver
152 * @ctx_pool : List of context
153 * @frame_req : List of frame requests
154 * @work : Worker handle
155 * @work_data : Worker data
156 * @fd_caps : FD driver capabilities
157 */
158struct cam_fd_hw_mgr {
159 struct list_head free_ctx_list;
160 struct list_head used_ctx_list;
161 struct list_head frame_free_list;
162 struct list_head frame_pending_list_high;
163 struct list_head frame_pending_list_normal;
164 struct list_head frame_processing_list;
165 struct mutex hw_mgr_mutex;
166 spinlock_t hw_mgr_slock;
167 struct mutex ctx_mutex;
168 struct mutex frame_req_mutex;
169 struct cam_iommu_handle device_iommu;
170 struct cam_iommu_handle cdm_iommu;
171 struct cam_fd_device hw_device[CAM_FD_HW_MAX];
172 uint32_t num_devices;
173 bool raw_results_available;
174 uint32_t supported_modes;
175 struct cam_fd_hw_mgr_ctx ctx_pool[CAM_CTX_MAX];
176 struct cam_fd_mgr_frame_request frame_req[CAM_CTX_REQ_MAX];
177 struct cam_req_mgr_core_workq *work;
178 struct cam_fd_mgr_work_data work_data[CAM_FD_WORKQ_NUM_TASK];
179 struct cam_fd_query_cap_cmd fd_caps;
180};
181
182#endif /* _CAM_FD_HW_MGR_H_ */