blob: 462499685a748659d730efc7292fc023c3afc82d [file] [log] [blame]
Rob Clarkc8afe682013-06-26 12:44:06 -04001/*
2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __MSM_DRV_H__
19#define __MSM_DRV_H__
20
21#include <linux/kernel.h>
22#include <linux/clk.h>
23#include <linux/cpufreq.h>
24#include <linux/module.h>
Rob Clark060530f2014-03-03 14:19:12 -050025#include <linux/component.h>
Rob Clarkc8afe682013-06-26 12:44:06 -040026#include <linux/platform_device.h>
27#include <linux/pm.h>
28#include <linux/pm_runtime.h>
29#include <linux/slab.h>
30#include <linux/list.h>
31#include <linux/iommu.h>
32#include <linux/types.h>
Archit Taneja3d6df062015-06-09 14:17:22 +053033#include <linux/of_graph.h>
Archit Tanejae9fbdaf2015-11-18 12:15:14 +053034#include <linux/of_device.h>
Dhaval Patel3949f032016-06-20 16:24:33 -070035#include <linux/mdss_io_util.h>
Rob Clarkc8afe682013-06-26 12:44:06 -040036#include <asm/sizes.h>
37
Rob Clarkc8afe682013-06-26 12:44:06 -040038#include <drm/drmP.h>
Rob Clarkcf3a7e42014-11-08 13:21:06 -050039#include <drm/drm_atomic.h>
40#include <drm/drm_atomic_helper.h>
Rob Clarkc8afe682013-06-26 12:44:06 -040041#include <drm/drm_crtc_helper.h>
Rob Clarkcf3a7e42014-11-08 13:21:06 -050042#include <drm/drm_plane_helper.h>
Rob Clarkc8afe682013-06-26 12:44:06 -040043#include <drm/drm_fb_helper.h>
Rob Clark7198e6b2013-07-19 12:59:32 -040044#include <drm/msm_drm.h>
Daniel Vetterd9fc9412014-09-23 15:46:53 +020045#include <drm/drm_gem.h>
Rob Clarkc8afe682013-06-26 12:44:06 -040046
Lloyd Atkinson154b6aa2016-05-24 17:11:37 -040047#include "msm_evtlog.h"
Dhaval Patel3949f032016-06-20 16:24:33 -070048#include "sde_power_handle.h"
49
50#define GET_MAJOR_REV(rev) ((rev) >> 28)
51#define GET_MINOR_REV(rev) (((rev) >> 16) & 0xFFF)
52#define GET_STEP_REV(rev) ((rev) & 0xFFFF)
Lloyd Atkinson154b6aa2016-05-24 17:11:37 -040053
Rob Clarkc8afe682013-06-26 12:44:06 -040054struct msm_kms;
Rob Clark7198e6b2013-07-19 12:59:32 -040055struct msm_gpu;
Rob Clark871d8122013-11-16 12:56:06 -050056struct msm_mmu;
Archit Taneja990a4002016-05-07 23:11:25 +053057struct msm_mdss;
Rob Clarka7d3c952014-05-30 14:47:38 -040058struct msm_rd_state;
Rob Clark70c70f02014-05-30 14:49:43 -040059struct msm_perf_state;
Rob Clarka7d3c952014-05-30 14:47:38 -040060struct msm_gem_submit;
Rob Clarkca762a82016-03-15 17:22:13 -040061struct msm_fence_context;
Rob Clarkfde5de62016-03-15 15:35:08 -040062struct msm_fence_cb;
Rob Clarkc8afe682013-06-26 12:44:06 -040063
Alan Kwong112a84f2016-05-24 20:49:21 -040064#define NUM_DOMAINS 4 /* one for KMS, then one per gpu core (?) */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070065#define MAX_CRTCS 8
66#define MAX_PLANES 12
67#define MAX_ENCODERS 8
68#define MAX_BRIDGES 8
69#define MAX_CONNECTORS 8
Rob Clark7198e6b2013-07-19 12:59:32 -040070
71struct msm_file_private {
72 /* currently we don't do anything useful with this.. but when
73 * per-context address spaces are supported we'd keep track of
74 * the context's page-tables here.
75 */
76 int dummy;
77};
Rob Clarkc8afe682013-06-26 12:44:06 -040078
jilai wang12987782015-06-25 17:37:42 -040079enum msm_mdp_plane_property {
Clarence Ip5e2a9222016-06-26 22:38:24 -040080 /* blob properties, always put these first */
Clarence Ipb43d4592016-09-08 14:21:35 -040081 PLANE_PROP_SCALER_V1,
Clarence Ip5fc00c52016-09-23 15:03:34 -040082 PLANE_PROP_CSC_V1,
Dhaval Patel4e574842016-08-23 15:11:37 -070083 PLANE_PROP_INFO,
Clarence Ip5e2a9222016-06-26 22:38:24 -040084
85 /* # of blob properties */
86 PLANE_PROP_BLOBCOUNT,
87
Clarence Ipe78efb72016-06-24 18:35:21 -040088 /* range properties */
Clarence Ip5e2a9222016-06-26 22:38:24 -040089 PLANE_PROP_ZPOS = PLANE_PROP_BLOBCOUNT,
jilai wang12987782015-06-25 17:37:42 -040090 PLANE_PROP_ALPHA,
Clarence Ipcb410d42016-06-26 22:52:33 -040091 PLANE_PROP_COLOR_FILL,
Clarence Ipdedbba92016-09-27 17:43:10 -040092 PLANE_PROP_H_DECIMATE,
93 PLANE_PROP_V_DECIMATE,
Clarence Ipcae1bb62016-07-07 12:07:13 -040094 PLANE_PROP_INPUT_FENCE,
Clarence Ipe78efb72016-06-24 18:35:21 -040095
Clarence Ip5e2a9222016-06-26 22:38:24 -040096 /* enum/bitmask properties */
97 PLANE_PROP_ROTATION,
98 PLANE_PROP_BLEND_OP,
99 PLANE_PROP_SRC_CONFIG,
Clarence Ipe78efb72016-06-24 18:35:21 -0400100
Clarence Ip5e2a9222016-06-26 22:38:24 -0400101 /* total # of properties */
102 PLANE_PROP_COUNT
jilai wang12987782015-06-25 17:37:42 -0400103};
104
Clarence Ip7a753bb2016-07-07 11:47:44 -0400105enum msm_mdp_crtc_property {
Dhaval Patele4a5dda2016-10-13 19:29:30 -0700106 CRTC_PROP_INFO,
107
Clarence Ip7a753bb2016-07-07 11:47:44 -0400108 /* # of blob properties */
109 CRTC_PROP_BLOBCOUNT,
110
111 /* range properties */
Clarence Ipcae1bb62016-07-07 12:07:13 -0400112 CRTC_PROP_INPUT_FENCE_TIMEOUT = CRTC_PROP_BLOBCOUNT,
Clarence Ip24f80662016-06-13 19:05:32 -0400113 CRTC_PROP_OUTPUT_FENCE,
Clarence Ip1d9728b2016-09-01 11:10:54 -0400114 CRTC_PROP_OUTPUT_FENCE_OFFSET,
Clarence Ip7a753bb2016-07-07 11:47:44 -0400115
116 /* total # of properties */
117 CRTC_PROP_COUNT
118};
119
Clarence Ipdd8021c2016-07-20 16:39:47 -0400120enum msm_mdp_conn_property {
121 /* blob properties, always put these first */
122 CONNECTOR_PROP_SDE_INFO,
123
124 /* # of blob properties */
125 CONNECTOR_PROP_BLOBCOUNT,
126
127 /* range properties */
128 CONNECTOR_PROP_OUT_FB = CONNECTOR_PROP_BLOBCOUNT,
129 CONNECTOR_PROP_RETIRE_FENCE,
Alan Kwongbb27c092016-07-20 16:41:25 -0400130 CONNECTOR_PROP_DST_X,
131 CONNECTOR_PROP_DST_Y,
132 CONNECTOR_PROP_DST_W,
133 CONNECTOR_PROP_DST_H,
Clarence Ipdd8021c2016-07-20 16:39:47 -0400134
135 /* enum/bitmask properties */
Lloyd Atkinsonb6191972016-08-10 18:31:46 -0400136 CONNECTOR_PROP_TOPOLOGY_NAME,
137 CONNECTOR_PROP_TOPOLOGY_CONTROL,
Clarence Ipdd8021c2016-07-20 16:39:47 -0400138
139 /* total # of properties */
140 CONNECTOR_PROP_COUNT
141};
142
Hai Li78b1d472015-07-27 13:49:45 -0400143struct msm_vblank_ctrl {
144 struct work_struct work;
145 struct list_head event_list;
146 spinlock_t lock;
147};
148
Clarence Ipa4039322016-07-15 16:23:59 -0400149#define MAX_H_TILES_PER_DISPLAY 2
150
151/**
152 * enum msm_display_compression - compression method used for pixel stream
153 * @MSM_DISPLAY_COMPRESS_NONE: Pixel data is not compressed
154 * @MSM_DISPLAY_COMPRESS_DSC: DSC compresison is used
155 * @MSM_DISPLAY_COMPRESS_FBC: FBC compression is used
156 */
157enum msm_display_compression {
158 MSM_DISPLAY_COMPRESS_NONE,
159 MSM_DISPLAY_COMPRESS_DSC,
160 MSM_DISPLAY_COMPRESS_FBC,
161};
162
163/**
164 * enum msm_display_caps - features/capabilities supported by displays
165 * @MSM_DISPLAY_CAP_VID_MODE: Video or "active" mode supported
166 * @MSM_DISPLAY_CAP_CMD_MODE: Command mode supported
167 * @MSM_DISPLAY_CAP_HOT_PLUG: Hot plug detection supported
168 * @MSM_DISPLAY_CAP_EDID: EDID supported
169 */
170enum msm_display_caps {
171 MSM_DISPLAY_CAP_VID_MODE = BIT(0),
172 MSM_DISPLAY_CAP_CMD_MODE = BIT(1),
173 MSM_DISPLAY_CAP_HOT_PLUG = BIT(2),
174 MSM_DISPLAY_CAP_EDID = BIT(3),
175};
176
177/**
178 * struct msm_display_info - defines display properties
179 * @intf_type: DRM_MODE_CONNECTOR_ display type
180 * @capabilities: Bitmask of display flags
181 * @num_of_h_tiles: Number of horizontal tiles in case of split interface
182 * @h_tile_instance: Controller instance used per tile. Number of elements is
183 * based on num_of_h_tiles
184 * @is_connected: Set to true if display is connected
185 * @width_mm: Physical width
186 * @height_mm: Physical height
187 * @max_width: Max width of display. In case of hot pluggable display
188 * this is max width supported by controller
189 * @max_height: Max height of display. In case of hot pluggable display
190 * this is max height supported by controller
191 * @compression: Compression supported by the display
192 */
193struct msm_display_info {
194 int intf_type;
195 uint32_t capabilities;
196
197 uint32_t num_of_h_tiles;
198 uint32_t h_tile_instance[MAX_H_TILES_PER_DISPLAY];
199
200 bool is_connected;
201
202 unsigned int width_mm;
203 unsigned int height_mm;
204
205 uint32_t max_width;
206 uint32_t max_height;
207
208 enum msm_display_compression compression;
209};
210
Clarence Ip3649f8b2016-10-31 09:59:44 -0400211/**
212 * struct msm_drm_event - defines custom event notification struct
213 * @base: base object required for event notification by DRM framework.
214 * @event: event object required for event notification by DRM framework.
215 * @info: contains information of DRM object for which events has been
216 * requested.
217 * @data: memory location which contains response payload for event.
218 */
219struct msm_drm_event {
220 struct drm_pending_event base;
221 struct drm_event event;
222 struct drm_msm_event_req info;
223 u8 data[];
224};
Ajay Singh Parmar64c19192016-06-10 16:44:56 -0700225
Rob Clarkc8afe682013-06-26 12:44:06 -0400226struct msm_drm_private {
227
Rob Clark68209392016-05-17 16:19:32 -0400228 struct drm_device *dev;
229
Rob Clarkc8afe682013-06-26 12:44:06 -0400230 struct msm_kms *kms;
231
Dhaval Patel3949f032016-06-20 16:24:33 -0700232 struct sde_power_handle phandle;
233 struct sde_power_client *pclient;
234
Rob Clark060530f2014-03-03 14:19:12 -0500235 /* subordinate devices, if present: */
Rob Clark067fef32014-11-04 13:33:14 -0500236 struct platform_device *gpu_pdev;
237
Archit Taneja990a4002016-05-07 23:11:25 +0530238 /* top level MDSS wrapper device (for MDP5 only) */
239 struct msm_mdss *mdss;
240
Rob Clark067fef32014-11-04 13:33:14 -0500241 /* possibly this should be in the kms component, but it is
242 * shared by both mdp4 and mdp5..
243 */
244 struct hdmi *hdmi;
Rob Clark060530f2014-03-03 14:19:12 -0500245
Hai Liab5b0102015-01-07 18:47:44 -0500246 /* eDP is for mdp5 only, but kms has not been created
247 * when edp_bind() and edp_init() are called. Here is the only
248 * place to keep the edp instance.
249 */
250 struct msm_edp *edp;
251
Hai Lia6895542015-03-31 14:36:33 -0400252 /* DSI is shared by mdp4 and mdp5 */
253 struct msm_dsi *dsi[2];
254
Rob Clark7198e6b2013-07-19 12:59:32 -0400255 /* when we have more than one 'msm_gpu' these need to be an array: */
256 struct msm_gpu *gpu;
257 struct msm_file_private *lastctx;
258
Rob Clarkc8afe682013-06-26 12:44:06 -0400259 struct drm_fb_helper *fbdev;
260
Rob Clarka7d3c952014-05-30 14:47:38 -0400261 struct msm_rd_state *rd;
Rob Clark70c70f02014-05-30 14:49:43 -0400262 struct msm_perf_state *perf;
Rob Clarka7d3c952014-05-30 14:47:38 -0400263
Rob Clarkc8afe682013-06-26 12:44:06 -0400264 /* list of GEM objects: */
265 struct list_head inactive_list;
266
267 struct workqueue_struct *wq;
Rob Clarkba00c3f2016-03-16 18:18:17 -0400268 struct workqueue_struct *atomic_wq;
Rob Clarkc8afe682013-06-26 12:44:06 -0400269
Rob Clarkf86afec2014-11-25 12:41:18 -0500270 /* crtcs pending async atomic updates: */
271 uint32_t pending_crtcs;
272 wait_queue_head_t pending_crtcs_event;
273
Rob Clark871d8122013-11-16 12:56:06 -0500274 /* registered MMUs: */
275 unsigned int num_mmus;
276 struct msm_mmu *mmus[NUM_DOMAINS];
Rob Clarkc8afe682013-06-26 12:44:06 -0400277
Rob Clarka8623912013-10-08 12:57:48 -0400278 unsigned int num_planes;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700279 struct drm_plane *planes[MAX_PLANES];
Rob Clarka8623912013-10-08 12:57:48 -0400280
Rob Clarkc8afe682013-06-26 12:44:06 -0400281 unsigned int num_crtcs;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700282 struct drm_crtc *crtcs[MAX_CRTCS];
Rob Clarkc8afe682013-06-26 12:44:06 -0400283
284 unsigned int num_encoders;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700285 struct drm_encoder *encoders[MAX_ENCODERS];
Rob Clarkc8afe682013-06-26 12:44:06 -0400286
Rob Clarka3376e32013-08-30 13:02:15 -0400287 unsigned int num_bridges;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700288 struct drm_bridge *bridges[MAX_BRIDGES];
Rob Clarka3376e32013-08-30 13:02:15 -0400289
Rob Clarkc8afe682013-06-26 12:44:06 -0400290 unsigned int num_connectors;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700291 struct drm_connector *connectors[MAX_CONNECTORS];
Rob Clark871d8122013-11-16 12:56:06 -0500292
jilai wang12987782015-06-25 17:37:42 -0400293 /* Properties */
Clarence Ipe78efb72016-06-24 18:35:21 -0400294 struct drm_property *plane_property[PLANE_PROP_COUNT];
Clarence Ip7a753bb2016-07-07 11:47:44 -0400295 struct drm_property *crtc_property[CRTC_PROP_COUNT];
Clarence Ipdd8021c2016-07-20 16:39:47 -0400296 struct drm_property *conn_property[CONNECTOR_PROP_COUNT];
jilai wang12987782015-06-25 17:37:42 -0400297
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -0700298 /* Color processing properties for the crtc */
299 struct drm_property **cp_property;
300
Rob Clark871d8122013-11-16 12:56:06 -0500301 /* VRAM carveout, used when no IOMMU: */
302 struct {
303 unsigned long size;
304 dma_addr_t paddr;
305 /* NOTE: mm managed at the page level, size is in # of pages
306 * and position mm_node->start is in # of pages:
307 */
308 struct drm_mm mm;
309 } vram;
Hai Li78b1d472015-07-27 13:49:45 -0400310
Rob Clarke1e9db22016-05-27 11:16:28 -0400311 struct notifier_block vmap_notifier;
Rob Clark68209392016-05-17 16:19:32 -0400312 struct shrinker shrinker;
313
Hai Li78b1d472015-07-27 13:49:45 -0400314 struct msm_vblank_ctrl vblank_ctrl;
Rob Clarkd78d3832016-08-22 15:28:38 -0400315
316 /* task holding struct_mutex.. currently only used in submit path
317 * to detect and reject faults from copy_from_user() for submit
318 * ioctl.
319 */
320 struct task_struct *struct_mutex_task;
Lloyd Atkinson154b6aa2016-05-24 17:11:37 -0400321
322 struct msm_evtlog evtlog;
Rob Clarkc8afe682013-06-26 12:44:06 -0400323};
324
Clarence Ip7f23b892016-06-01 10:30:34 -0400325/* Helper macro for accessing msm_drm_private's event log */
326#define MSM_EVTMSG(dev, msg, x, y) do { \
327 if ((dev) && ((struct drm_device *)(dev))->dev_private) \
328 msm_evtlog_sample(&((struct msm_drm_private *) \
329 ((struct drm_device *) \
330 (dev))->dev_private)->evtlog, __func__,\
331 (msg), (uint64_t)(x), (uint64_t)(y), \
332 __LINE__); \
333 } while (0)
334
335/* Helper macro for accessing msm_drm_private's event log */
336#define MSM_EVT(dev, x, y) MSM_EVTMSG((dev), 0, (x), (y))
337
Rob Clarkc8afe682013-06-26 12:44:06 -0400338struct msm_format {
339 uint32_t pixel_format;
340};
341
Daniel Vetterb4274fb2014-11-26 17:02:18 +0100342int msm_atomic_check(struct drm_device *dev,
343 struct drm_atomic_state *state);
Dhaval Patel7a7d85d2016-08-26 16:35:34 -0700344/* callback from wq once fence has passed: */
345struct msm_fence_cb {
346 struct work_struct work;
347 uint32_t fence;
348 void (*func)(struct msm_fence_cb *cb);
349};
350
351void __msm_fence_worker(struct work_struct *work);
352
353#define INIT_FENCE_CB(_cb, _func) do { \
354 INIT_WORK(&(_cb)->work, __msm_fence_worker); \
355 (_cb)->func = _func; \
356 } while (0)
357
Rob Clarkcf3a7e42014-11-08 13:21:06 -0500358int msm_atomic_commit(struct drm_device *dev,
Maarten Lankhorsta3ccfb92016-04-26 16:11:38 +0200359 struct drm_atomic_state *state, bool nonblock);
Rob Clarkcf3a7e42014-11-08 13:21:06 -0500360
Rob Clark871d8122013-11-16 12:56:06 -0500361int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu);
Rob Clarkc8afe682013-06-26 12:44:06 -0400362
Rob Clark40e68152016-05-03 09:50:26 -0400363void msm_gem_submit_free(struct msm_gem_submit *submit);
Rob Clark7198e6b2013-07-19 12:59:32 -0400364int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
365 struct drm_file *file);
366
Rob Clark68209392016-05-17 16:19:32 -0400367void msm_gem_shrinker_init(struct drm_device *dev);
368void msm_gem_shrinker_cleanup(struct drm_device *dev);
369
Daniel Thompson77a147e2014-11-12 11:38:14 +0000370int msm_gem_mmap_obj(struct drm_gem_object *obj,
371 struct vm_area_struct *vma);
Rob Clarkc8afe682013-06-26 12:44:06 -0400372int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
373int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
374uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
375int msm_gem_get_iova_locked(struct drm_gem_object *obj, int id,
376 uint32_t *iova);
377int msm_gem_get_iova(struct drm_gem_object *obj, int id, uint32_t *iova);
Rob Clark2638d902014-11-08 09:13:37 -0500378uint32_t msm_gem_iova(struct drm_gem_object *obj, int id);
Rob Clark05b84912013-09-28 11:28:35 -0400379struct page **msm_gem_get_pages(struct drm_gem_object *obj);
380void msm_gem_put_pages(struct drm_gem_object *obj);
Rob Clarkc8afe682013-06-26 12:44:06 -0400381void msm_gem_put_iova(struct drm_gem_object *obj, int id);
382int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
383 struct drm_mode_create_dumb *args);
Rob Clarkc8afe682013-06-26 12:44:06 -0400384int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
385 uint32_t handle, uint64_t *offset);
Rob Clark05b84912013-09-28 11:28:35 -0400386struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj);
387void *msm_gem_prime_vmap(struct drm_gem_object *obj);
388void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
Daniel Thompson77a147e2014-11-12 11:38:14 +0000389int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
Rob Clark05b84912013-09-28 11:28:35 -0400390struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
Maarten Lankhorstb5e9c1a2014-01-09 11:03:14 +0100391 struct dma_buf_attachment *attach, struct sg_table *sg);
Rob Clark05b84912013-09-28 11:28:35 -0400392int msm_gem_prime_pin(struct drm_gem_object *obj);
393void msm_gem_prime_unpin(struct drm_gem_object *obj);
Rob Clark18f23042016-05-26 16:24:35 -0400394void *msm_gem_get_vaddr_locked(struct drm_gem_object *obj);
395void *msm_gem_get_vaddr(struct drm_gem_object *obj);
396void msm_gem_put_vaddr_locked(struct drm_gem_object *obj);
397void msm_gem_put_vaddr(struct drm_gem_object *obj);
Rob Clark4cd33c42016-05-17 15:44:49 -0400398int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv);
Rob Clark68209392016-05-17 16:19:32 -0400399void msm_gem_purge(struct drm_gem_object *obj);
Rob Clarke1e9db22016-05-27 11:16:28 -0400400void msm_gem_vunmap(struct drm_gem_object *obj);
Rob Clarkb6295f92016-03-15 18:26:28 -0400401int msm_gem_sync_object(struct drm_gem_object *obj,
402 struct msm_fence_context *fctx, bool exclusive);
Rob Clark7198e6b2013-07-19 12:59:32 -0400403void msm_gem_move_to_active(struct drm_gem_object *obj,
Rob Clarkb6295f92016-03-15 18:26:28 -0400404 struct msm_gpu *gpu, bool exclusive, struct fence *fence);
Rob Clark7198e6b2013-07-19 12:59:32 -0400405void msm_gem_move_to_inactive(struct drm_gem_object *obj);
Rob Clarkba00c3f2016-03-16 18:18:17 -0400406int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout);
Rob Clark7198e6b2013-07-19 12:59:32 -0400407int msm_gem_cpu_fini(struct drm_gem_object *obj);
Rob Clarkc8afe682013-06-26 12:44:06 -0400408void msm_gem_free_object(struct drm_gem_object *obj);
409int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
410 uint32_t size, uint32_t flags, uint32_t *handle);
411struct drm_gem_object *msm_gem_new(struct drm_device *dev,
412 uint32_t size, uint32_t flags);
Rob Clark05b84912013-09-28 11:28:35 -0400413struct drm_gem_object *msm_gem_import(struct drm_device *dev,
Rob Clark79f0e202016-03-16 12:40:35 -0400414 struct dma_buf *dmabuf, struct sg_table *sgt);
Rob Clarkc8afe682013-06-26 12:44:06 -0400415
Rob Clark2638d902014-11-08 09:13:37 -0500416int msm_framebuffer_prepare(struct drm_framebuffer *fb, int id);
417void msm_framebuffer_cleanup(struct drm_framebuffer *fb, int id);
418uint32_t msm_framebuffer_iova(struct drm_framebuffer *fb, int id, int plane);
Rob Clarkc8afe682013-06-26 12:44:06 -0400419struct drm_gem_object *msm_framebuffer_bo(struct drm_framebuffer *fb, int plane);
420const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb);
421struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
Ville Syrjälä1eb83452015-11-11 19:11:29 +0200422 const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos);
Rob Clarkc8afe682013-06-26 12:44:06 -0400423struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
Ville Syrjälä1eb83452015-11-11 19:11:29 +0200424 struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd);
Rob Clarkc8afe682013-06-26 12:44:06 -0400425
426struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev);
Archit Taneja1aaa57f2016-02-25 11:19:45 +0530427void msm_fbdev_free(struct drm_device *dev);
Rob Clarkc8afe682013-06-26 12:44:06 -0400428
Rob Clarkdada25b2013-12-01 12:12:54 -0500429struct hdmi;
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100430int msm_hdmi_modeset_init(struct hdmi *hdmi, struct drm_device *dev,
Rob Clark067fef32014-11-04 13:33:14 -0500431 struct drm_encoder *encoder);
Arnd Bergmannfcda50c2016-02-22 22:08:35 +0100432void __init msm_hdmi_register(void);
433void __exit msm_hdmi_unregister(void);
Rob Clarkc8afe682013-06-26 12:44:06 -0400434
Hai Li00453982014-12-12 14:41:17 -0500435struct msm_edp;
436void __init msm_edp_register(void);
437void __exit msm_edp_unregister(void);
438int msm_edp_modeset_init(struct msm_edp *edp, struct drm_device *dev,
439 struct drm_encoder *encoder);
440
Hai Lia6895542015-03-31 14:36:33 -0400441struct msm_dsi;
442enum msm_dsi_encoder_id {
443 MSM_DSI_VIDEO_ENCODER_ID = 0,
444 MSM_DSI_CMD_ENCODER_ID = 1,
445 MSM_DSI_ENCODER_NUM = 2
446};
447#ifdef CONFIG_DRM_MSM_DSI
448void __init msm_dsi_register(void);
449void __exit msm_dsi_unregister(void);
450int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,
451 struct drm_encoder *encoders[MSM_DSI_ENCODER_NUM]);
452#else
453static inline void __init msm_dsi_register(void)
454{
455}
456static inline void __exit msm_dsi_unregister(void)
457{
458}
459static inline int msm_dsi_modeset_init(struct msm_dsi *msm_dsi,
460 struct drm_device *dev,
461 struct drm_encoder *encoders[MSM_DSI_ENCODER_NUM])
462{
463 return -EINVAL;
464}
465#endif
466
Archit Taneja1dd0a0b2016-05-30 16:36:50 +0530467void __init msm_mdp_register(void);
468void __exit msm_mdp_unregister(void);
469
Rob Clarkc8afe682013-06-26 12:44:06 -0400470#ifdef CONFIG_DEBUG_FS
471void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m);
472void msm_gem_describe_objects(struct list_head *list, struct seq_file *m);
473void msm_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m);
Rob Clarka7d3c952014-05-30 14:47:38 -0400474int msm_debugfs_late_init(struct drm_device *dev);
475int msm_rd_debugfs_init(struct drm_minor *minor);
476void msm_rd_debugfs_cleanup(struct drm_minor *minor);
477void msm_rd_dump_submit(struct msm_gem_submit *submit);
Rob Clark70c70f02014-05-30 14:49:43 -0400478int msm_perf_debugfs_init(struct drm_minor *minor);
479void msm_perf_debugfs_cleanup(struct drm_minor *minor);
Rob Clarka7d3c952014-05-30 14:47:38 -0400480#else
481static inline int msm_debugfs_late_init(struct drm_device *dev) { return 0; }
482static inline void msm_rd_dump_submit(struct msm_gem_submit *submit) {}
Rob Clarkc8afe682013-06-26 12:44:06 -0400483#endif
484
485void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
486 const char *dbgname);
487void msm_writel(u32 data, void __iomem *addr);
488u32 msm_readl(const void __iomem *addr);
489
490#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
491#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
492
493static inline int align_pitch(int width, int bpp)
494{
495 int bytespp = (bpp + 7) / 8;
496 /* adreno needs pitch aligned to 32 pixels: */
497 return bytespp * ALIGN(width, 32);
498}
499
500/* for the generated headers: */
501#define INVALID_IDX(idx) ({BUG(); 0;})
Rob Clark7198e6b2013-07-19 12:59:32 -0400502#define fui(x) ({BUG(); 0;})
503#define util_float_to_half(x) ({BUG(); 0;})
504
Rob Clarkc8afe682013-06-26 12:44:06 -0400505
506#define FIELD(val, name) (((val) & name ## __MASK) >> name ## __SHIFT)
507
508/* for conditionally setting boolean flag(s): */
509#define COND(bool, val) ((bool) ? (val) : 0)
510
Rob Clark340ff412016-03-16 14:57:22 -0400511static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
512{
513 ktime_t now = ktime_get();
514 unsigned long remaining_jiffies;
515
516 if (ktime_compare(*timeout, now) < 0) {
517 remaining_jiffies = 0;
518 } else {
519 ktime_t rem = ktime_sub(*timeout, now);
520 struct timespec ts = ktime_to_timespec(rem);
521 remaining_jiffies = timespec_to_jiffies(&ts);
522 }
523
524 return remaining_jiffies;
525}
Rob Clarkc8afe682013-06-26 12:44:06 -0400526
527#endif /* __MSM_DRV_H__ */