Merge drm/drm-next into drm-intel-next
[linux-2.6-block.git] / drivers / gpu / drm / i915 / display / intel_display_core.h
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5
6 #ifndef __INTEL_DISPLAY_CORE_H__
7 #define __INTEL_DISPLAY_CORE_H__
8
9 #include <linux/list.h>
10 #include <linux/llist.h>
11 #include <linux/mutex.h>
12 #include <linux/types.h>
13 #include <linux/wait.h>
14 #include <linux/workqueue.h>
15
16 #include <drm/drm_connector.h>
17 #include <drm/drm_modeset_lock.h>
18
19 #include "intel_cdclk.h"
20 #include "intel_display_device.h"
21 #include "intel_display_limits.h"
22 #include "intel_display_params.h"
23 #include "intel_display_power.h"
24 #include "intel_dpll_mgr.h"
25 #include "intel_fbc.h"
26 #include "intel_global_state.h"
27 #include "intel_gmbus.h"
28 #include "intel_opregion.h"
29 #include "intel_wm_types.h"
30
31 struct task_struct;
32
33 struct drm_i915_private;
34 struct drm_property;
35 struct drm_property_blob;
36 struct i915_audio_component;
37 struct i915_hdcp_arbiter;
38 struct intel_atomic_state;
39 struct intel_audio_funcs;
40 struct intel_cdclk_funcs;
41 struct intel_cdclk_vals;
42 struct intel_color_funcs;
43 struct intel_crtc;
44 struct intel_crtc_state;
45 struct intel_dmc;
46 struct intel_dpll_funcs;
47 struct intel_dpll_mgr;
48 struct intel_fbdev;
49 struct intel_fdi_funcs;
50 struct intel_hotplug_funcs;
51 struct intel_initial_plane_config;
52 struct intel_overlay;
53
54 /* Amount of SAGV/QGV points, BSpec precisely defines this */
55 #define I915_NUM_QGV_POINTS 8
56
57 /* Amount of PSF GV points, BSpec precisely defines this */
58 #define I915_NUM_PSF_GV_POINTS 3
59
60 struct intel_display_funcs {
61         /*
62          * Returns the active state of the crtc, and if the crtc is active,
63          * fills out the pipe-config with the hw state.
64          */
65         bool (*get_pipe_config)(struct intel_crtc *,
66                                 struct intel_crtc_state *);
67         void (*get_initial_plane_config)(struct intel_crtc *,
68                                          struct intel_initial_plane_config *);
69         void (*crtc_enable)(struct intel_atomic_state *state,
70                             struct intel_crtc *crtc);
71         void (*crtc_disable)(struct intel_atomic_state *state,
72                              struct intel_crtc *crtc);
73         void (*commit_modeset_enables)(struct intel_atomic_state *state);
74 };
75
76 /* functions used for watermark calcs for display. */
77 struct intel_wm_funcs {
78         /* update_wm is for legacy wm management */
79         void (*update_wm)(struct drm_i915_private *dev_priv);
80         int (*compute_pipe_wm)(struct intel_atomic_state *state,
81                                struct intel_crtc *crtc);
82         int (*compute_intermediate_wm)(struct intel_atomic_state *state,
83                                        struct intel_crtc *crtc);
84         void (*initial_watermarks)(struct intel_atomic_state *state,
85                                    struct intel_crtc *crtc);
86         void (*atomic_update_watermarks)(struct intel_atomic_state *state,
87                                          struct intel_crtc *crtc);
88         void (*optimize_watermarks)(struct intel_atomic_state *state,
89                                     struct intel_crtc *crtc);
90         int (*compute_global_watermarks)(struct intel_atomic_state *state);
91         void (*get_hw_state)(struct drm_i915_private *i915);
92 };
93
94 struct intel_audio_state {
95         struct intel_encoder *encoder;
96         u8 eld[MAX_ELD_BYTES];
97 };
98
99 struct intel_audio {
100         /* hda/i915 audio component */
101         struct i915_audio_component *component;
102         bool component_registered;
103         /* mutex for audio/video sync */
104         struct mutex mutex;
105         int power_refcount;
106         u32 freq_cntrl;
107
108         /* current audio state for the audio component hooks */
109         struct intel_audio_state state[I915_MAX_TRANSCODERS];
110
111         /* necessary resource sharing with HDMI LPE audio driver. */
112         struct {
113                 struct platform_device *platdev;
114                 int irq;
115         } lpe;
116 };
117
118 /*
119  * dpll and cdclk state is protected by connection_mutex dpll.lock serializes
120  * intel_{prepare,enable,disable}_shared_dpll.  Must be global rather than per
121  * dpll, because on some platforms plls share registers.
122  */
123 struct intel_dpll {
124         struct mutex lock;
125
126         int num_shared_dpll;
127         struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
128         const struct intel_dpll_mgr *mgr;
129
130         struct {
131                 int nssc;
132                 int ssc;
133         } ref_clks;
134
135         /*
136          * Bitmask of PLLs using the PCH SSC, indexed using enum intel_dpll_id.
137          */
138         u8 pch_ssc_use;
139 };
140
141 struct intel_frontbuffer_tracking {
142         spinlock_t lock;
143
144         /*
145          * Tracking bits for delayed frontbuffer flushing du to gpu activity or
146          * scheduled flips.
147          */
148         unsigned busy_bits;
149         unsigned flip_bits;
150 };
151
152 struct intel_hotplug {
153         struct delayed_work hotplug_work;
154
155         const u32 *hpd, *pch_hpd;
156
157         struct {
158                 unsigned long last_jiffies;
159                 int count;
160                 enum {
161                         HPD_ENABLED = 0,
162                         HPD_DISABLED = 1,
163                         HPD_MARK_DISABLED = 2
164                 } state;
165         } stats[HPD_NUM_PINS];
166         u32 event_bits;
167         u32 retry_bits;
168         struct delayed_work reenable_work;
169
170         u32 long_port_mask;
171         u32 short_port_mask;
172         struct work_struct dig_port_work;
173
174         struct work_struct poll_init_work;
175         bool poll_enabled;
176
177         /*
178          * Queuing of hotplug_work, reenable_work and poll_init_work is
179          * enabled. Protected by drm_i915_private::irq_lock.
180          */
181         bool detection_work_enabled;
182
183         unsigned int hpd_storm_threshold;
184         /* Whether or not to count short HPD IRQs in HPD storms */
185         u8 hpd_short_storm_enabled;
186
187         /* Last state reported by oob_hotplug_event for each encoder */
188         unsigned long oob_hotplug_last_state;
189
190         /*
191          * if we get a HPD irq from DP and a HPD irq from non-DP
192          * the non-DP HPD could block the workqueue on a mode config
193          * mutex getting, that userspace may have taken. However
194          * userspace is waiting on the DP workqueue to run which is
195          * blocked behind the non-DP one.
196          */
197         struct workqueue_struct *dp_wq;
198
199         /*
200          * Flag to track if long HPDs need not to be processed
201          *
202          * Some panels generate long HPDs while keep connected to the port.
203          * This can cause issues with CI tests results. In CI systems we
204          * don't expect to disconnect the panels and could ignore the long
205          * HPDs generated from the faulty panels. This flag can be used as
206          * cue to ignore the long HPDs and can be set / unset using debugfs.
207          */
208         bool ignore_long_hpd;
209 };
210
211 struct intel_vbt_data {
212         /* bdb version */
213         u16 version;
214
215         /* Feature bits */
216         unsigned int int_tv_support:1;
217         unsigned int int_crt_support:1;
218         unsigned int lvds_use_ssc:1;
219         unsigned int int_lvds_support:1;
220         unsigned int display_clock_mode:1;
221         unsigned int fdi_rx_polarity_inverted:1;
222         int lvds_ssc_freq;
223         enum drm_panel_orientation orientation;
224
225         bool override_afc_startup;
226         u8 override_afc_startup_val;
227
228         int crt_ddc_pin;
229
230         struct list_head display_devices;
231         struct list_head bdb_blocks;
232
233         struct sdvo_device_mapping {
234                 u8 initialized;
235                 u8 dvo_port;
236                 u8 slave_addr;
237                 u8 dvo_wiring;
238                 u8 i2c_pin;
239                 u8 ddc_pin;
240         } sdvo_mappings[2];
241 };
242
243 struct intel_wm {
244         /*
245          * Raw watermark latency values:
246          * in 0.1us units for WM0,
247          * in 0.5us units for WM1+.
248          */
249         /* primary */
250         u16 pri_latency[5];
251         /* sprite */
252         u16 spr_latency[5];
253         /* cursor */
254         u16 cur_latency[5];
255         /*
256          * Raw watermark memory latency values
257          * for SKL for all 8 levels
258          * in 1us units.
259          */
260         u16 skl_latency[8];
261
262         /* current hardware state */
263         union {
264                 struct ilk_wm_values hw;
265                 struct vlv_wm_values vlv;
266                 struct g4x_wm_values g4x;
267         };
268
269         u8 num_levels;
270
271         /*
272          * Should be held around atomic WM register writing; also
273          * protects * intel_crtc->wm.active and
274          * crtc_state->wm.need_postvbl_update.
275          */
276         struct mutex wm_mutex;
277
278         bool ipc_enabled;
279 };
280
281 struct intel_display {
282         /* Display functions */
283         struct {
284                 /* Top level crtc-ish functions */
285                 const struct intel_display_funcs *display;
286
287                 /* Display CDCLK functions */
288                 const struct intel_cdclk_funcs *cdclk;
289
290                 /* Display pll funcs */
291                 const struct intel_dpll_funcs *dpll;
292
293                 /* irq display functions */
294                 const struct intel_hotplug_funcs *hotplug;
295
296                 /* pm display functions */
297                 const struct intel_wm_funcs *wm;
298
299                 /* fdi display functions */
300                 const struct intel_fdi_funcs *fdi;
301
302                 /* Display internal color functions */
303                 const struct intel_color_funcs *color;
304
305                 /* Display internal audio functions */
306                 const struct intel_audio_funcs *audio;
307         } funcs;
308
309         struct {
310                 bool any_task_allowed;
311                 struct task_struct *allowed_task;
312         } access;
313
314         struct {
315                 /* backlight registers and fields in struct intel_panel */
316                 struct mutex lock;
317         } backlight;
318
319         struct {
320                 struct intel_global_obj obj;
321
322                 struct intel_bw_info {
323                         /* for each QGV point */
324                         unsigned int deratedbw[I915_NUM_QGV_POINTS];
325                         /* for each PSF GV point */
326                         unsigned int psf_bw[I915_NUM_PSF_GV_POINTS];
327                         /* Peak BW for each QGV point */
328                         unsigned int peakbw[I915_NUM_QGV_POINTS];
329                         u8 num_qgv_points;
330                         u8 num_psf_gv_points;
331                         u8 num_planes;
332                 } max[6];
333         } bw;
334
335         struct {
336                 /* The current hardware cdclk configuration */
337                 struct intel_cdclk_config hw;
338
339                 /* cdclk, divider, and ratio table from bspec */
340                 const struct intel_cdclk_vals *table;
341
342                 struct intel_global_obj obj;
343
344                 unsigned int max_cdclk_freq;
345         } cdclk;
346
347         struct {
348                 struct drm_property_blob *glk_linear_degamma_lut;
349         } color;
350
351         struct {
352                 /* The current hardware dbuf configuration */
353                 u8 enabled_slices;
354
355                 struct intel_global_obj obj;
356         } dbuf;
357
358         struct {
359                 /*
360                  * dkl.phy_lock protects against concurrent access of the
361                  * Dekel TypeC PHYs.
362                  */
363                 spinlock_t phy_lock;
364         } dkl;
365
366         struct {
367                 struct intel_dmc *dmc;
368                 intel_wakeref_t wakeref;
369         } dmc;
370
371         struct {
372                 /* VLV/CHV/BXT/GLK DSI MMIO register base address */
373                 u32 mmio_base;
374         } dsi;
375
376         struct {
377                 /* list of fbdev register on this device */
378                 struct intel_fbdev *fbdev;
379                 struct work_struct suspend_work;
380         } fbdev;
381
382         struct {
383                 unsigned int pll_freq;
384                 u32 rx_config;
385         } fdi;
386
387         struct {
388                 struct list_head obj_list;
389         } global;
390
391         struct {
392                 /*
393                  * Base address of where the gmbus and gpio blocks are located
394                  * (either on PCH or on SoC for platforms without PCH).
395                  */
396                 u32 mmio_base;
397
398                 /*
399                  * gmbus.mutex protects against concurrent usage of the single
400                  * hw gmbus controller on different i2c buses.
401                  */
402                 struct mutex mutex;
403
404                 struct intel_gmbus *bus[GMBUS_NUM_PINS];
405
406                 wait_queue_head_t wait_queue;
407         } gmbus;
408
409         struct {
410                 struct i915_hdcp_arbiter *arbiter;
411                 bool comp_added;
412
413                 /*
414                  * HDCP message struct for allocation of memory which can be
415                  * reused when sending message to gsc cs.
416                  * this is only populated post Meteorlake
417                  */
418                 struct intel_hdcp_gsc_message *hdcp_message;
419                 /* Mutex to protect the above hdcp related values. */
420                 struct mutex hdcp_mutex;
421         } hdcp;
422
423         struct {
424                 /*
425                  * HTI (aka HDPORT) state read during initial hw readout. Most
426                  * platforms don't have HTI, so this will just stay 0. Those
427                  * that do will use this later to figure out which PLLs and PHYs
428                  * are unavailable for driver usage.
429                  */
430                 u32 state;
431         } hti;
432
433         struct {
434                 /* Access with DISPLAY_INFO() */
435                 const struct intel_display_device_info *__device_info;
436
437                 /* Access with DISPLAY_RUNTIME_INFO() */
438                 struct intel_display_runtime_info __runtime_info;
439         } info;
440
441         struct {
442                 bool false_color;
443         } ips;
444
445         struct {
446                 wait_queue_head_t waitqueue;
447
448                 /* mutex to protect pmdemand programming sequence */
449                 struct mutex lock;
450
451                 struct intel_global_obj obj;
452         } pmdemand;
453
454         struct {
455                 struct i915_power_domains domains;
456
457                 /* Shadow for DISPLAY_PHY_CONTROL which can't be safely read */
458                 u32 chv_phy_control;
459
460                 /* perform PHY state sanity checks? */
461                 bool chv_phy_assert[2];
462         } power;
463
464         struct {
465                 u32 mmio_base;
466
467                 /* protects panel power sequencer state */
468                 struct mutex mutex;
469         } pps;
470
471         struct {
472                 struct drm_property *broadcast_rgb;
473                 struct drm_property *force_audio;
474         } properties;
475
476         struct {
477                 unsigned long mask;
478         } quirks;
479
480         struct {
481                 /* restore state for suspend/resume and display reset */
482                 struct drm_atomic_state *modeset_state;
483                 struct drm_modeset_acquire_ctx reset_ctx;
484         } restore;
485
486         struct {
487                 enum {
488                         I915_SAGV_UNKNOWN = 0,
489                         I915_SAGV_DISABLED,
490                         I915_SAGV_ENABLED,
491                         I915_SAGV_NOT_CONTROLLED
492                 } status;
493
494                 u32 block_time_us;
495         } sagv;
496
497         struct {
498                 /*
499                  * DG2: Mask of PHYs that were not calibrated by the firmware
500                  * and should not be used.
501                  */
502                 u8 phy_failed_calibration;
503         } snps;
504
505         struct {
506                 /*
507                  * Shadows for CHV DPLL_MD regs to keep the state
508                  * checker somewhat working in the presence hardware
509                  * crappiness (can't read out DPLL_MD for pipes B & C).
510                  */
511                 u32 chv_dpll_md[I915_MAX_PIPES];
512                 u32 bxt_phy_grc;
513         } state;
514
515         struct {
516                 /* ordered wq for modesets */
517                 struct workqueue_struct *modeset;
518
519                 /* unbound hipri wq for page flips/plane updates */
520                 struct workqueue_struct *flip;
521         } wq;
522
523         /* Grouping using named structs. Keep sorted. */
524         struct intel_audio audio;
525         struct intel_dpll dpll;
526         struct intel_fbc *fbc[I915_MAX_FBCS];
527         struct intel_frontbuffer_tracking fb_tracking;
528         struct intel_hotplug hotplug;
529         struct intel_opregion opregion;
530         struct intel_overlay *overlay;
531         struct intel_display_params params;
532         struct intel_vbt_data vbt;
533         struct intel_wm wm;
534 };
535
536 #endif /* __INTEL_DISPLAY_CORE_H__ */