63ff660b9479440812f4bdc7ffc7ce153333464d
[sfrench/cifs-2.6.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/mutex.h>
10 #include <linux/types.h>
11 #include <linux/wait.h>
12 #include <linux/workqueue.h>
13
14 #include "intel_cdclk.h"
15 #include "intel_display.h"
16 #include "intel_dmc.h"
17 #include "intel_dpll_mgr.h"
18 #include "intel_global_state.h"
19 #include "intel_gmbus.h"
20 #include "intel_opregion.h"
21 #include "intel_pm_types.h"
22
23 struct drm_i915_private;
24 struct i915_audio_component;
25 struct i915_hdcp_comp_master;
26 struct intel_atomic_state;
27 struct intel_audio_funcs;
28 struct intel_cdclk_funcs;
29 struct intel_cdclk_vals;
30 struct intel_color_funcs;
31 struct intel_crtc;
32 struct intel_crtc_state;
33 struct intel_dpll_funcs;
34 struct intel_dpll_mgr;
35 struct intel_fbdev;
36 struct intel_fdi_funcs;
37 struct intel_hotplug_funcs;
38 struct intel_initial_plane_config;
39 struct intel_overlay;
40
41 /* Amount of SAGV/QGV points, BSpec precisely defines this */
42 #define I915_NUM_QGV_POINTS 8
43
44 /* Amount of PSF GV points, BSpec precisely defines this */
45 #define I915_NUM_PSF_GV_POINTS 3
46
47 struct intel_display_funcs {
48         /*
49          * Returns the active state of the crtc, and if the crtc is active,
50          * fills out the pipe-config with the hw state.
51          */
52         bool (*get_pipe_config)(struct intel_crtc *,
53                                 struct intel_crtc_state *);
54         void (*get_initial_plane_config)(struct intel_crtc *,
55                                          struct intel_initial_plane_config *);
56         void (*crtc_enable)(struct intel_atomic_state *state,
57                             struct intel_crtc *crtc);
58         void (*crtc_disable)(struct intel_atomic_state *state,
59                              struct intel_crtc *crtc);
60         void (*commit_modeset_enables)(struct intel_atomic_state *state);
61 };
62
63 /* functions used for watermark calcs for display. */
64 struct intel_wm_funcs {
65         /* update_wm is for legacy wm management */
66         void (*update_wm)(struct drm_i915_private *dev_priv);
67         int (*compute_pipe_wm)(struct intel_atomic_state *state,
68                                struct intel_crtc *crtc);
69         int (*compute_intermediate_wm)(struct intel_atomic_state *state,
70                                        struct intel_crtc *crtc);
71         void (*initial_watermarks)(struct intel_atomic_state *state,
72                                    struct intel_crtc *crtc);
73         void (*atomic_update_watermarks)(struct intel_atomic_state *state,
74                                          struct intel_crtc *crtc);
75         void (*optimize_watermarks)(struct intel_atomic_state *state,
76                                     struct intel_crtc *crtc);
77         int (*compute_global_watermarks)(struct intel_atomic_state *state);
78 };
79
80 struct intel_audio {
81         /* hda/i915 audio component */
82         struct i915_audio_component *component;
83         bool component_registered;
84         /* mutex for audio/video sync */
85         struct mutex mutex;
86         int power_refcount;
87         u32 freq_cntrl;
88
89         /* Used to save the pipe-to-encoder mapping for audio */
90         struct intel_encoder *encoder_map[I915_MAX_PIPES];
91
92         /* necessary resource sharing with HDMI LPE audio driver. */
93         struct {
94                 struct platform_device *platdev;
95                 int irq;
96         } lpe;
97 };
98
99 /*
100  * dpll and cdclk state is protected by connection_mutex dpll.lock serializes
101  * intel_{prepare,enable,disable}_shared_dpll.  Must be global rather than per
102  * dpll, because on some platforms plls share registers.
103  */
104 struct intel_dpll {
105         struct mutex lock;
106
107         int num_shared_dpll;
108         struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
109         const struct intel_dpll_mgr *mgr;
110
111         struct {
112                 int nssc;
113                 int ssc;
114         } ref_clks;
115 };
116
117 struct intel_hotplug {
118         struct delayed_work hotplug_work;
119
120         const u32 *hpd, *pch_hpd;
121
122         struct {
123                 unsigned long last_jiffies;
124                 int count;
125                 enum {
126                         HPD_ENABLED = 0,
127                         HPD_DISABLED = 1,
128                         HPD_MARK_DISABLED = 2
129                 } state;
130         } stats[HPD_NUM_PINS];
131         u32 event_bits;
132         u32 retry_bits;
133         struct delayed_work reenable_work;
134
135         u32 long_port_mask;
136         u32 short_port_mask;
137         struct work_struct dig_port_work;
138
139         struct work_struct poll_init_work;
140         bool poll_enabled;
141
142         unsigned int hpd_storm_threshold;
143         /* Whether or not to count short HPD IRQs in HPD storms */
144         u8 hpd_short_storm_enabled;
145
146         /*
147          * if we get a HPD irq from DP and a HPD irq from non-DP
148          * the non-DP HPD could block the workqueue on a mode config
149          * mutex getting, that userspace may have taken. However
150          * userspace is waiting on the DP workqueue to run which is
151          * blocked behind the non-DP one.
152          */
153         struct workqueue_struct *dp_wq;
154 };
155
156 struct intel_wm {
157         /*
158          * Raw watermark latency values:
159          * in 0.1us units for WM0,
160          * in 0.5us units for WM1+.
161          */
162         /* primary */
163         u16 pri_latency[5];
164         /* sprite */
165         u16 spr_latency[5];
166         /* cursor */
167         u16 cur_latency[5];
168         /*
169          * Raw watermark memory latency values
170          * for SKL for all 8 levels
171          * in 1us units.
172          */
173         u16 skl_latency[8];
174
175         /* current hardware state */
176         union {
177                 struct ilk_wm_values hw;
178                 struct vlv_wm_values vlv;
179                 struct g4x_wm_values g4x;
180         };
181
182         u8 max_level;
183
184         /*
185          * Should be held around atomic WM register writing; also
186          * protects * intel_crtc->wm.active and
187          * crtc_state->wm.need_postvbl_update.
188          */
189         struct mutex wm_mutex;
190 };
191
192 struct intel_display {
193         /* Display functions */
194         struct {
195                 /* Top level crtc-ish functions */
196                 const struct intel_display_funcs *display;
197
198                 /* Display CDCLK functions */
199                 const struct intel_cdclk_funcs *cdclk;
200
201                 /* Display pll funcs */
202                 const struct intel_dpll_funcs *dpll;
203
204                 /* irq display functions */
205                 const struct intel_hotplug_funcs *hotplug;
206
207                 /* pm display functions */
208                 const struct intel_wm_funcs *wm;
209
210                 /* fdi display functions */
211                 const struct intel_fdi_funcs *fdi;
212
213                 /* Display internal color functions */
214                 const struct intel_color_funcs *color;
215
216                 /* Display internal audio functions */
217                 const struct intel_audio_funcs *audio;
218         } funcs;
219
220         /* Grouping using anonymous structs. Keep sorted. */
221         struct {
222                 /* backlight registers and fields in struct intel_panel */
223                 struct mutex lock;
224         } backlight;
225
226         struct {
227                 struct intel_global_obj obj;
228
229                 struct intel_bw_info {
230                         /* for each QGV point */
231                         unsigned int deratedbw[I915_NUM_QGV_POINTS];
232                         /* for each PSF GV point */
233                         unsigned int psf_bw[I915_NUM_PSF_GV_POINTS];
234                         u8 num_qgv_points;
235                         u8 num_psf_gv_points;
236                         u8 num_planes;
237                 } max[6];
238         } bw;
239
240         struct {
241                 /* The current hardware cdclk configuration */
242                 struct intel_cdclk_config hw;
243
244                 /* cdclk, divider, and ratio table from bspec */
245                 const struct intel_cdclk_vals *table;
246
247                 struct intel_global_obj obj;
248
249                 unsigned int max_cdclk_freq;
250         } cdclk;
251
252         struct {
253                 /* VLV/CHV/BXT/GLK DSI MMIO register base address */
254                 u32 mmio_base;
255         } dsi;
256
257         struct {
258                 /* list of fbdev register on this device */
259                 struct intel_fbdev *fbdev;
260                 struct work_struct suspend_work;
261         } fbdev;
262
263         struct {
264                 /*
265                  * Base address of where the gmbus and gpio blocks are located
266                  * (either on PCH or on SoC for platforms without PCH).
267                  */
268                 u32 mmio_base;
269
270                 /*
271                  * gmbus.mutex protects against concurrent usage of the single
272                  * hw gmbus controller on different i2c buses.
273                  */
274                 struct mutex mutex;
275
276                 struct intel_gmbus *bus[GMBUS_NUM_PINS];
277
278                 wait_queue_head_t wait_queue;
279         } gmbus;
280
281         struct {
282                 struct i915_hdcp_comp_master *master;
283                 bool comp_added;
284
285                 /* Mutex to protect the above hdcp component related values. */
286                 struct mutex comp_mutex;
287         } hdcp;
288
289         struct {
290                 u32 mmio_base;
291
292                 /* protects panel power sequencer state */
293                 struct mutex mutex;
294         } pps;
295
296         struct {
297                 enum {
298                         I915_SAGV_UNKNOWN = 0,
299                         I915_SAGV_DISABLED,
300                         I915_SAGV_ENABLED,
301                         I915_SAGV_NOT_CONTROLLED
302                 } status;
303
304                 u32 block_time_us;
305         } sagv;
306
307         /* Grouping using named structs. Keep sorted. */
308         struct intel_audio audio;
309         struct intel_dmc dmc;
310         struct intel_dpll dpll;
311         struct intel_hotplug hotplug;
312         struct intel_opregion opregion;
313         struct intel_overlay *overlay;
314         struct intel_wm wm;
315 };
316
317 #endif /* __INTEL_DISPLAY_CORE_H__ */