Merge tag 'nfs-for-5.7-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
[linux-2.6-block.git] / include / drm / drm_dp_mst_helper.h
CommitLineData
ad7f8a1f
DA
1/*
2 * Copyright © 2014 Red Hat.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22#ifndef _DRM_DP_MST_HELPER_H_
23#define _DRM_DP_MST_HELPER_H_
24
25#include <linux/types.h>
26#include <drm/drm_dp_helper.h>
3f3353b7 27#include <drm/drm_atomic.h>
ad7f8a1f 28
12a280c7
LP
29#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
30#include <linux/stackdepot.h>
31#include <linux/timekeeping.h>
32
33enum drm_dp_mst_topology_ref_type {
34 DRM_DP_MST_TOPOLOGY_REF_GET,
35 DRM_DP_MST_TOPOLOGY_REF_PUT,
36};
37
38struct drm_dp_mst_topology_ref_history {
39 struct drm_dp_mst_topology_ref_entry {
40 enum drm_dp_mst_topology_ref_type type;
41 int count;
42 ktime_t ts_nsec;
43 depot_stack_handle_t backtrace;
44 } *entries;
45 int len;
46};
47#endif /* IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS) */
48
ad7f8a1f
DA
49struct drm_dp_mst_branch;
50
51/**
32197aab 52 * struct drm_dp_vcpi - Virtual Channel Payload Identifier
ad7f8a1f
DA
53 * @vcpi: Virtual channel ID.
54 * @pbn: Payload Bandwidth Number for this channel
55 * @aligned_pbn: PBN aligned with slot size
56 * @num_slots: number of slots for this PBN
57 */
58struct drm_dp_vcpi {
59 int vcpi;
60 int pbn;
61 int aligned_pbn;
62 int num_slots;
63};
64
65/**
66 * struct drm_dp_mst_port - MST port
ad7f8a1f 67 * @port_num: port number
3f9b3f02
LP
68 * @input: if this port is an input port. Protected by
69 * &drm_dp_mst_topology_mgr.base.lock.
70 * @mcs: message capability status - DP 1.2 spec. Protected by
71 * &drm_dp_mst_topology_mgr.base.lock.
72 * @ddps: DisplayPort Device Plug Status - DP 1.2. Protected by
73 * &drm_dp_mst_topology_mgr.base.lock.
74 * @pdt: Peer Device Type. Protected by
75 * &drm_dp_mst_topology_mgr.base.lock.
76 * @ldps: Legacy Device Plug Status. Protected by
77 * &drm_dp_mst_topology_mgr.base.lock.
78 * @dpcd_rev: DPCD revision of device on this port. Protected by
79 * &drm_dp_mst_topology_mgr.base.lock.
80 * @num_sdp_streams: Number of simultaneous streams. Protected by
81 * &drm_dp_mst_topology_mgr.base.lock.
82 * @num_sdp_stream_sinks: Number of stream sinks. Protected by
83 * &drm_dp_mst_topology_mgr.base.lock.
fcf46380 84 * @full_pbn: Max possible bandwidth for this port. Protected by
3f9b3f02 85 * &drm_dp_mst_topology_mgr.base.lock.
ad7f8a1f 86 * @next: link to next port on this branch device
c485e2c9 87 * @aux: i2c aux transport to talk to device connected to this port, protected
3f9b3f02 88 * by &drm_dp_mst_topology_mgr.base.lock.
ad7f8a1f
DA
89 * @parent: branch device parent of this port
90 * @vcpi: Virtual Channel Payload info for this port.
3f9b3f02
LP
91 * @connector: DRM connector this port is connected to. Protected by
92 * &drm_dp_mst_topology_mgr.base.lock.
ad7f8a1f
DA
93 * @mgr: topology manager this port lives under.
94 *
95 * This structure represents an MST port endpoint on a device somewhere
96 * in the MST topology.
97 */
98struct drm_dp_mst_port {
ebcc0e6b
LP
99 /**
100 * @topology_kref: refcount for this port's lifetime in the topology,
101 * only the DP MST helpers should need to touch this
102 */
103 struct kref topology_kref;
104
105 /**
106 * @malloc_kref: refcount for the memory allocation containing this
107 * structure. See drm_dp_mst_get_port_malloc() and
108 * drm_dp_mst_put_port_malloc().
109 */
110 struct kref malloc_kref;
ad7f8a1f 111
12a280c7
LP
112#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
113 /**
114 * @topology_ref_history: A history of each topology
115 * reference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.
116 */
117 struct drm_dp_mst_topology_ref_history topology_ref_history;
118#endif
119
ad7f8a1f
DA
120 u8 port_num;
121 bool input;
122 bool mcs;
123 bool ddps;
124 u8 pdt;
125 bool ldps;
126 u8 dpcd_rev;
127 u8 num_sdp_streams;
128 u8 num_sdp_stream_sinks;
fcf46380 129 uint16_t full_pbn;
ad7f8a1f 130 struct list_head next;
14692a36
LP
131 /**
132 * @mstb: the branch device connected to this port, if there is one.
133 * This should be considered protected for reading by
134 * &drm_dp_mst_topology_mgr.lock. There are two exceptions to this:
135 * &drm_dp_mst_topology_mgr.up_req_work and
136 * &drm_dp_mst_topology_mgr.work, which do not grab
137 * &drm_dp_mst_topology_mgr.lock during reads but are the only
138 * updaters of this list and are protected from writing concurrently
139 * by &drm_dp_mst_topology_mgr.probe_lock.
140 */
141 struct drm_dp_mst_branch *mstb;
ad7f8a1f
DA
142 struct drm_dp_aux aux; /* i2c bus for this port? */
143 struct drm_dp_mst_branch *parent;
144
145 struct drm_dp_vcpi vcpi;
146 struct drm_connector *connector;
147 struct drm_dp_mst_topology_mgr *mgr;
c6a0aed4 148
132d49d7
DV
149 /**
150 * @cached_edid: for DP logical ports - make tiling work by ensuring
151 * that the EDID for all connectors is read immediately.
152 */
153 struct edid *cached_edid;
154 /**
155 * @has_audio: Tracks whether the sink connector to this port is
156 * audio-capable.
157 */
ef8f9bea 158 bool has_audio;
a3c2b0ff
DF
159
160 bool fec_capable;
ad7f8a1f
DA
161};
162
163/**
164 * struct drm_dp_mst_branch - MST branch device.
ad7f8a1f
DA
165 * @rad: Relative Address to talk to this branch device.
166 * @lct: Link count total to talk to this branch device.
167 * @num_ports: number of ports on the branch.
168 * @msg_slots: one bit per transmitted msg slot.
ad7f8a1f
DA
169 * @port_parent: pointer to the port parent, NULL if toplevel.
170 * @mgr: topology manager for this branch device.
171 * @tx_slots: transmission slots for this device.
172 * @last_seqno: last sequence number used to talk to this.
173 * @link_address_sent: if a link address message has been sent to this device yet.
5e93b820
HW
174 * @guid: guid for DP 1.2 branch device. port under this branch can be
175 * identified by port #.
ad7f8a1f
DA
176 *
177 * This structure represents an MST branch device, there is one
5e93b820
HW
178 * primary branch device at the root, along with any other branches connected
179 * to downstream port of parent branches.
ad7f8a1f
DA
180 */
181struct drm_dp_mst_branch {
ebcc0e6b
LP
182 /**
183 * @topology_kref: refcount for this branch device's lifetime in the
184 * topology, only the DP MST helpers should need to touch this
185 */
186 struct kref topology_kref;
187
188 /**
189 * @malloc_kref: refcount for the memory allocation containing this
190 * structure. See drm_dp_mst_get_mstb_malloc() and
191 * drm_dp_mst_put_mstb_malloc().
192 */
193 struct kref malloc_kref;
194
12a280c7
LP
195#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
196 /**
197 * @topology_ref_history: A history of each topology
198 * reference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.
199 */
200 struct drm_dp_mst_topology_ref_history topology_ref_history;
201#endif
202
7cb12d48
LP
203 /**
204 * @destroy_next: linked-list entry used by
205 * drm_dp_delayed_destroy_work()
206 */
207 struct list_head destroy_next;
208
ad7f8a1f
DA
209 u8 rad[8];
210 u8 lct;
211 int num_ports;
212
213 int msg_slots;
14692a36
LP
214 /**
215 * @ports: the list of ports on this branch device. This should be
216 * considered protected for reading by &drm_dp_mst_topology_mgr.lock.
217 * There are two exceptions to this:
218 * &drm_dp_mst_topology_mgr.up_req_work and
219 * &drm_dp_mst_topology_mgr.work, which do not grab
220 * &drm_dp_mst_topology_mgr.lock during reads but are the only
221 * updaters of this list and are protected from updating the list
222 * concurrently by @drm_dp_mst_topology_mgr.probe_lock
223 */
ad7f8a1f
DA
224 struct list_head ports;
225
226 /* list of tx ops queue for this port */
227 struct drm_dp_mst_port *port_parent;
228 struct drm_dp_mst_topology_mgr *mgr;
229
230 /* slots are protected by mstb->mgr->qlock */
231 struct drm_dp_sideband_msg_tx *tx_slots[2];
232 int last_seqno;
233 bool link_address_sent;
5e93b820
HW
234
235 /* global unique identifier to identify branch devices */
236 u8 guid[16];
ad7f8a1f
DA
237};
238
239
240/* sideband msg header - not bit struct */
241struct drm_dp_sideband_msg_hdr {
242 u8 lct;
243 u8 lcr;
244 u8 rad[8];
245 bool broadcast;
246 bool path_msg;
247 u8 msg_len;
248 bool somt;
249 bool eomt;
250 bool seqno;
251};
252
253struct drm_dp_nak_reply {
254 u8 guid[16];
255 u8 reason;
256 u8 nak_data;
257};
258
259struct drm_dp_link_address_ack_reply {
260 u8 guid[16];
261 u8 nports;
262 struct drm_dp_link_addr_reply_port {
263 bool input_port;
264 u8 peer_device_type;
265 u8 port_number;
266 bool mcs;
267 bool ddps;
268 bool legacy_device_plug_status;
269 u8 dpcd_revision;
270 u8 peer_guid[16];
271 u8 num_sdp_streams;
272 u8 num_sdp_stream_sinks;
273 } ports[16];
274};
275
276struct drm_dp_remote_dpcd_read_ack_reply {
277 u8 port_number;
278 u8 num_bytes;
279 u8 bytes[255];
280};
281
282struct drm_dp_remote_dpcd_write_ack_reply {
283 u8 port_number;
284};
285
286struct drm_dp_remote_dpcd_write_nak_reply {
287 u8 port_number;
288 u8 reason;
289 u8 bytes_written_before_failure;
290};
291
292struct drm_dp_remote_i2c_read_ack_reply {
293 u8 port_number;
294 u8 num_bytes;
295 u8 bytes[255];
296};
297
298struct drm_dp_remote_i2c_read_nak_reply {
299 u8 port_number;
300 u8 nak_reason;
301 u8 i2c_nak_transaction;
302};
303
304struct drm_dp_remote_i2c_write_ack_reply {
305 u8 port_number;
306};
307
308
309struct drm_dp_sideband_msg_rx {
310 u8 chunk[48];
311 u8 msg[256];
312 u8 curchunk_len;
313 u8 curchunk_idx; /* chunk we are parsing now */
314 u8 curchunk_hdrlen;
315 u8 curlen; /* total length of the msg */
316 bool have_somt;
317 bool have_eomt;
318 struct drm_dp_sideband_msg_hdr initial_hdr;
319};
320
ef8f9bea 321#define DRM_DP_MAX_SDP_STREAMS 16
ad7f8a1f
DA
322struct drm_dp_allocate_payload {
323 u8 port_number;
324 u8 number_sdp_streams;
325 u8 vcpi;
326 u16 pbn;
ef8f9bea 327 u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
ad7f8a1f
DA
328};
329
330struct drm_dp_allocate_payload_ack_reply {
331 u8 port_number;
332 u8 vcpi;
333 u16 allocated_pbn;
334};
335
336struct drm_dp_connection_status_notify {
337 u8 guid[16];
338 u8 port_number;
339 bool legacy_device_plug_status;
340 bool displayport_device_plug_status;
341 bool message_capability_status;
342 bool input_port;
343 u8 peer_device_type;
344};
345
346struct drm_dp_remote_dpcd_read {
347 u8 port_number;
348 u32 dpcd_address;
349 u8 num_bytes;
350};
351
352struct drm_dp_remote_dpcd_write {
353 u8 port_number;
354 u32 dpcd_address;
355 u8 num_bytes;
356 u8 *bytes;
357};
358
ae491542 359#define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
ad7f8a1f
DA
360struct drm_dp_remote_i2c_read {
361 u8 num_transactions;
362 u8 port_number;
2f015ec6 363 struct drm_dp_remote_i2c_read_tx {
ad7f8a1f
DA
364 u8 i2c_dev_id;
365 u8 num_bytes;
366 u8 *bytes;
367 u8 no_stop_bit;
368 u8 i2c_transaction_delay;
ae491542 369 } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
ad7f8a1f
DA
370 u8 read_i2c_device_id;
371 u8 num_bytes_read;
372};
373
374struct drm_dp_remote_i2c_write {
375 u8 port_number;
376 u8 write_i2c_device_id;
377 u8 num_bytes;
378 u8 *bytes;
379};
380
381/* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
382struct drm_dp_port_number_req {
383 u8 port_number;
384};
385
386struct drm_dp_enum_path_resources_ack_reply {
387 u8 port_number;
a3c2b0ff 388 bool fec_capable;
ad7f8a1f
DA
389 u16 full_payload_bw_number;
390 u16 avail_payload_bw_number;
391};
392
393/* covers POWER_DOWN_PHY, POWER_UP_PHY */
394struct drm_dp_port_number_rep {
395 u8 port_number;
396};
397
398struct drm_dp_query_payload {
399 u8 port_number;
400 u8 vcpi;
401};
402
403struct drm_dp_resource_status_notify {
404 u8 port_number;
405 u8 guid[16];
406 u16 available_pbn;
407};
408
409struct drm_dp_query_payload_ack_reply {
410 u8 port_number;
268de653 411 u16 allocated_pbn;
ad7f8a1f
DA
412};
413
414struct drm_dp_sideband_msg_req_body {
415 u8 req_type;
416 union ack_req {
417 struct drm_dp_connection_status_notify conn_stat;
418 struct drm_dp_port_number_req port_num;
419 struct drm_dp_resource_status_notify resource_stat;
420
421 struct drm_dp_query_payload query_payload;
422 struct drm_dp_allocate_payload allocate_payload;
423
424 struct drm_dp_remote_dpcd_read dpcd_read;
425 struct drm_dp_remote_dpcd_write dpcd_write;
426
427 struct drm_dp_remote_i2c_read i2c_read;
428 struct drm_dp_remote_i2c_write i2c_write;
429 } u;
430};
431
432struct drm_dp_sideband_msg_reply_body {
433 u8 reply_type;
434 u8 req_type;
435 union ack_replies {
436 struct drm_dp_nak_reply nak;
437 struct drm_dp_link_address_ack_reply link_addr;
438 struct drm_dp_port_number_rep port_number;
439
440 struct drm_dp_enum_path_resources_ack_reply path_resources;
441 struct drm_dp_allocate_payload_ack_reply allocate_payload;
442 struct drm_dp_query_payload_ack_reply query_payload;
443
444 struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
445 struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
446 struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
447
448 struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
449 struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
450 struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
451 } u;
452};
453
454/* msg is queued to be put into a slot */
455#define DRM_DP_SIDEBAND_TX_QUEUED 0
456/* msg has started transmitting on a slot - still on msgq */
457#define DRM_DP_SIDEBAND_TX_START_SEND 1
458/* msg has finished transmitting on a slot - removed from msgq only in slot */
459#define DRM_DP_SIDEBAND_TX_SENT 2
460/* msg has received a response - removed from slot */
461#define DRM_DP_SIDEBAND_TX_RX 3
462#define DRM_DP_SIDEBAND_TX_TIMEOUT 4
463
464struct drm_dp_sideband_msg_tx {
465 u8 msg[256];
466 u8 chunk[48];
467 u8 cur_offset;
468 u8 cur_len;
469 struct drm_dp_mst_branch *dst;
470 struct list_head next;
471 int seqno;
472 int state;
473 bool path_msg;
474 struct drm_dp_sideband_msg_reply_body reply;
475};
476
477/* sideband msg handler */
478struct drm_dp_mst_topology_mgr;
479struct drm_dp_mst_topology_cbs {
480 /* create a connector for a port */
12e6cecd 481 struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
ad7f8a1f
DA
482 void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
483 struct drm_connector *connector);
ad7f8a1f
DA
484};
485
486#define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
487
488#define DP_PAYLOAD_LOCAL 1
489#define DP_PAYLOAD_REMOTE 2
490#define DP_PAYLOAD_DELETE_LOCAL 3
491
492struct drm_dp_payload {
493 int payload_state;
494 int start_slot;
495 int num_slots;
dfda0df3 496 int vcpi;
ad7f8a1f
DA
497};
498
a4370c77
VS
499#define to_dp_mst_topology_state(x) container_of(x, struct drm_dp_mst_topology_state, base)
500
eceae147
LP
501struct drm_dp_vcpi_allocation {
502 struct drm_dp_mst_port *port;
503 int vcpi;
cd82d82c 504 int pbn;
8afb7e6a 505 bool dsc_enabled;
eceae147
LP
506 struct list_head next;
507};
508
3f3353b7 509struct drm_dp_mst_topology_state {
a4370c77 510 struct drm_private_state base;
eceae147 511 struct list_head vcpis;
3f3353b7
PD
512 struct drm_dp_mst_topology_mgr *mgr;
513};
514
a4370c77
VS
515#define to_dp_mst_topology_mgr(x) container_of(x, struct drm_dp_mst_topology_mgr, base)
516
ad7f8a1f
DA
517/**
518 * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
ad7f8a1f
DA
519 *
520 * This struct represents the toplevel displayport MST topology manager.
521 * There should be one instance of this for every MST capable DP connector
522 * on the GPU.
523 */
524struct drm_dp_mst_topology_mgr {
a4370c77
VS
525 /**
526 * @base: Base private object for atomic
527 */
528 struct drm_private_obj base;
529
132d49d7
DV
530 /**
531 * @dev: device pointer for adding i2c devices etc.
532 */
7b0a89a6 533 struct drm_device *dev;
132d49d7
DV
534 /**
535 * @cbs: callbacks for connector addition and destruction.
536 */
69a0f89c 537 const struct drm_dp_mst_topology_cbs *cbs;
132d49d7
DV
538 /**
539 * @max_dpcd_transaction_bytes: maximum number of bytes to read/write
540 * in one go.
541 */
ad7f8a1f 542 int max_dpcd_transaction_bytes;
132d49d7
DV
543 /**
544 * @aux: AUX channel for the DP MST connector this topolgy mgr is
545 * controlling.
546 */
547 struct drm_dp_aux *aux;
548 /**
549 * @max_payloads: maximum number of payloads the GPU can generate.
550 */
ad7f8a1f 551 int max_payloads;
132d49d7
DV
552 /**
553 * @conn_base_id: DRM connector ID this mgr is connected to. Only used
554 * to build the MST connector path value.
555 */
ad7f8a1f
DA
556 int conn_base_id;
557
132d49d7 558 /**
85783369 559 * @down_rep_recv: Message receiver state for down replies.
132d49d7 560 */
ad7f8a1f 561 struct drm_dp_sideband_msg_rx down_rep_recv;
132d49d7 562 /**
85783369 563 * @up_req_recv: Message receiver state for up requests.
132d49d7 564 */
ad7f8a1f
DA
565 struct drm_dp_sideband_msg_rx up_req_recv;
566
132d49d7 567 /**
f7948907
SP
568 * @lock: protects @mst_state, @mst_primary, @dpcd, and
569 * @payload_id_table_cleared.
132d49d7
DV
570 */
571 struct mutex lock;
ad7f8a1f 572
14692a36
LP
573 /**
574 * @probe_lock: Prevents @work and @up_req_work, the only writers of
575 * &drm_dp_mst_port.mstb and &drm_dp_mst_branch.ports, from racing
576 * while they update the topology.
577 */
578 struct mutex probe_lock;
579
132d49d7
DV
580 /**
581 * @mst_state: If this manager is enabled for an MST capable port. False
582 * if no MST sink/branch devices is connected.
583 */
f7948907
SP
584 bool mst_state : 1;
585
586 /**
587 * @payload_id_table_cleared: Whether or not we've cleared the payload
588 * ID table for @mst_primary. Protected by @lock.
589 */
590 bool payload_id_table_cleared : 1;
591
1cfff5f0
LP
592 /**
593 * @is_waiting_for_dwn_reply: whether we're waiting for a down reply.
594 */
595 bool is_waiting_for_dwn_reply : 1;
596
132d49d7
DV
597 /**
598 * @mst_primary: Pointer to the primary/first branch device.
599 */
ad7f8a1f 600 struct drm_dp_mst_branch *mst_primary;
5e93b820 601
132d49d7
DV
602 /**
603 * @dpcd: Cache of DPCD for primary port.
604 */
ad7f8a1f 605 u8 dpcd[DP_RECEIVER_CAP_SIZE];
132d49d7
DV
606 /**
607 * @sink_count: Sink count from DEVICE_SERVICE_IRQ_VECTOR_ESI0.
608 */
ad7f8a1f 609 u8 sink_count;
132d49d7
DV
610 /**
611 * @pbn_div: PBN to slots divisor.
612 */
ad7f8a1f 613 int pbn_div;
a538d613 614
3f3353b7
PD
615 /**
616 * @funcs: Atomic helper callbacks
617 */
618 const struct drm_private_state_funcs *funcs;
619
132d49d7 620 /**
6806cdf9
DV
621 * @qlock: protects @tx_msg_downq, the &drm_dp_mst_branch.txslost and
622 * &drm_dp_sideband_msg_tx.state once they are queued
132d49d7 623 */
ad7f8a1f 624 struct mutex qlock;
5a64967a 625
132d49d7
DV
626 /**
627 * @tx_msg_downq: List of pending down replies.
628 */
ad7f8a1f 629 struct list_head tx_msg_downq;
ad7f8a1f 630
132d49d7
DV
631 /**
632 * @payload_lock: Protect payload information.
633 */
ad7f8a1f 634 struct mutex payload_lock;
132d49d7
DV
635 /**
636 * @proposed_vcpis: Array of pointers for the new VCPI allocation. The
a727fe8f
LP
637 * VCPI structure itself is &drm_dp_mst_port.vcpi, and the size of
638 * this array is determined by @max_payloads.
132d49d7 639 */
ad7f8a1f 640 struct drm_dp_vcpi **proposed_vcpis;
132d49d7 641 /**
a727fe8f
LP
642 * @payloads: Array of payloads. The size of this array is determined
643 * by @max_payloads.
132d49d7 644 */
ad7f8a1f 645 struct drm_dp_payload *payloads;
132d49d7
DV
646 /**
647 * @payload_mask: Elements of @payloads actually in use. Since
648 * reallocation of active outputs isn't possible gaps can be created by
649 * disabling outputs out of order compared to how they've been enabled.
650 */
ad7f8a1f 651 unsigned long payload_mask;
132d49d7
DV
652 /**
653 * @vcpi_mask: Similar to @payload_mask, but for @proposed_vcpis.
654 */
dfda0df3 655 unsigned long vcpi_mask;
ad7f8a1f 656
132d49d7
DV
657 /**
658 * @tx_waitq: Wait to queue stall for the tx worker.
659 */
ad7f8a1f 660 wait_queue_head_t tx_waitq;
132d49d7
DV
661 /**
662 * @work: Probe work.
663 */
ad7f8a1f 664 struct work_struct work;
132d49d7
DV
665 /**
666 * @tx_work: Sideband transmit worker. This can nest within the main
667 * @work worker for each transaction @work launches.
668 */
ad7f8a1f 669 struct work_struct tx_work;
6b8eeca6 670
132d49d7 671 /**
7cb12d48
LP
672 * @destroy_port_list: List of to be destroyed connectors.
673 */
674 struct list_head destroy_port_list;
675 /**
676 * @destroy_branch_device_list: List of to be destroyed branch
677 * devices.
132d49d7 678 */
7cb12d48 679 struct list_head destroy_branch_device_list;
132d49d7 680 /**
7cb12d48
LP
681 * @delayed_destroy_lock: Protects @destroy_port_list and
682 * @destroy_branch_device_list.
132d49d7 683 */
7cb12d48 684 struct mutex delayed_destroy_lock;
132d49d7 685 /**
7cb12d48
LP
686 * @delayed_destroy_work: Work item to destroy MST port and branch
687 * devices, needed to avoid locking inversion.
132d49d7 688 */
7cb12d48 689 struct work_struct delayed_destroy_work;
9408cc94
LP
690
691 /**
692 * @up_req_list: List of pending up requests from the topology that
693 * need to be processed, in chronological order.
694 */
695 struct list_head up_req_list;
696 /**
697 * @up_req_lock: Protects @up_req_list
698 */
699 struct mutex up_req_lock;
700 /**
701 * @up_req_work: Work item to process up requests received from the
702 * topology. Needed to avoid blocking hotplug handling and sideband
703 * transmissions.
704 */
705 struct work_struct up_req_work;
12a280c7
LP
706
707#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
708 /**
709 * @topology_ref_history_lock: protects
710 * &drm_dp_mst_port.topology_ref_history and
711 * &drm_dp_mst_branch.topology_ref_history.
712 */
713 struct mutex topology_ref_history_lock;
714#endif
ad7f8a1f
DA
715};
716
7b0a89a6
DP
717int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,
718 struct drm_device *dev, struct drm_dp_aux *aux,
719 int max_dpcd_transaction_bytes,
720 int max_payloads, int conn_base_id);
ad7f8a1f
DA
721
722void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
723
724
725int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
726
727
728int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
729
730
3f9b3f02
LP
731int
732drm_dp_mst_detect_port(struct drm_connector *connector,
733 struct drm_modeset_acquire_ctx *ctx,
734 struct drm_dp_mst_topology_mgr *mgr,
735 struct drm_dp_mst_port *port);
ad7f8a1f 736
ef8f9bea
LY
737bool drm_dp_mst_port_has_audio(struct drm_dp_mst_topology_mgr *mgr,
738 struct drm_dp_mst_port *port);
ad7f8a1f
DA
739struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
740
741
dc48529f 742int drm_dp_calc_pbn_mode(int clock, int bpp, bool dsc);
ad7f8a1f 743
1e797f55
PD
744bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
745 struct drm_dp_mst_port *port, int pbn, int slots);
ad7f8a1f 746
87f5942d
DA
747int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
748
ad7f8a1f
DA
749
750void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
751
752
753void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
754 struct drm_dp_mst_port *port);
755
756
757int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
758 int pbn);
759
760
761int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
762
763
764int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
765
766int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
767
768void drm_dp_mst_dump_topology(struct seq_file *m,
769 struct drm_dp_mst_topology_mgr *mgr);
770
771void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
c235316d 772int __must_check
6f85f738
LP
773drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr,
774 bool sync);
562836a2
VS
775
776ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
777 unsigned int offset, void *buffer, size_t size);
778ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
779 unsigned int offset, void *buffer, size_t size);
780
781int drm_dp_mst_connector_late_register(struct drm_connector *connector,
782 struct drm_dp_mst_port *port);
783void drm_dp_mst_connector_early_unregister(struct drm_connector *connector,
784 struct drm_dp_mst_port *port);
785
3f3353b7
PD
786struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
787 struct drm_dp_mst_topology_mgr *mgr);
eceae147
LP
788int __must_check
789drm_dp_atomic_find_vcpi_slots(struct drm_atomic_state *state,
790 struct drm_dp_mst_topology_mgr *mgr,
1c6c1cb5
ML
791 struct drm_dp_mst_port *port, int pbn,
792 int pbn_div);
8afb7e6a
ML
793int drm_dp_mst_atomic_enable_dsc(struct drm_atomic_state *state,
794 struct drm_dp_mst_port *port,
795 int pbn, int pbn_div,
796 bool enable);
eceae147 797int __must_check
8ec04671
ML
798drm_dp_mst_add_affected_dsc_crtcs(struct drm_atomic_state *state,
799 struct drm_dp_mst_topology_mgr *mgr);
eceae147
LP
800int __must_check
801drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state,
802 struct drm_dp_mst_topology_mgr *mgr,
803 struct drm_dp_mst_port *port);
0bb9c2b2
DP
804int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr,
805 struct drm_dp_mst_port *port, bool power_up);
eceae147 806int __must_check drm_dp_mst_atomic_check(struct drm_atomic_state *state);
3f3353b7 807
ebcc0e6b
LP
808void drm_dp_mst_get_port_malloc(struct drm_dp_mst_port *port);
809void drm_dp_mst_put_port_malloc(struct drm_dp_mst_port *port);
810
c2bc1b6e
DF
811struct drm_dp_aux *drm_dp_mst_dsc_aux_for_port(struct drm_dp_mst_port *port);
812
bea5c38f
LP
813extern const struct drm_private_state_funcs drm_dp_mst_topology_state_funcs;
814
815/**
816 * __drm_dp_mst_state_iter_get - private atomic state iterator function for
817 * macro-internal use
818 * @state: &struct drm_atomic_state pointer
819 * @mgr: pointer to the &struct drm_dp_mst_topology_mgr iteration cursor
820 * @old_state: optional pointer to the old &struct drm_dp_mst_topology_state
821 * iteration cursor
822 * @new_state: optional pointer to the new &struct drm_dp_mst_topology_state
823 * iteration cursor
824 * @i: int iteration cursor, for macro-internal use
825 *
826 * Used by for_each_oldnew_mst_mgr_in_state(),
827 * for_each_old_mst_mgr_in_state(), and for_each_new_mst_mgr_in_state(). Don't
828 * call this directly.
829 *
830 * Returns:
831 * True if the current &struct drm_private_obj is a &struct
832 * drm_dp_mst_topology_mgr, false otherwise.
833 */
834static inline bool
835__drm_dp_mst_state_iter_get(struct drm_atomic_state *state,
836 struct drm_dp_mst_topology_mgr **mgr,
837 struct drm_dp_mst_topology_state **old_state,
838 struct drm_dp_mst_topology_state **new_state,
839 int i)
840{
841 struct __drm_private_objs_state *objs_state = &state->private_objs[i];
842
843 if (objs_state->ptr->funcs != &drm_dp_mst_topology_state_funcs)
844 return false;
845
846 *mgr = to_dp_mst_topology_mgr(objs_state->ptr);
847 if (old_state)
848 *old_state = to_dp_mst_topology_state(objs_state->old_state);
849 if (new_state)
850 *new_state = to_dp_mst_topology_state(objs_state->new_state);
851
852 return true;
853}
854
855/**
856 * for_each_oldnew_mst_mgr_in_state - iterate over all DP MST topology
857 * managers in an atomic update
858 * @__state: &struct drm_atomic_state pointer
859 * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
860 * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
861 * state
862 * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
863 * state
864 * @__i: int iteration cursor, for macro-internal use
865 *
866 * This iterates over all DRM DP MST topology managers in an atomic update,
867 * tracking both old and new state. This is useful in places where the state
868 * delta needs to be considered, for example in atomic check functions.
869 */
870#define for_each_oldnew_mst_mgr_in_state(__state, mgr, old_state, new_state, __i) \
871 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
872 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), &(new_state), (__i)))
873
874/**
875 * for_each_old_mst_mgr_in_state - iterate over all DP MST topology managers
876 * in an atomic update
877 * @__state: &struct drm_atomic_state pointer
878 * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
879 * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
880 * state
881 * @__i: int iteration cursor, for macro-internal use
882 *
883 * This iterates over all DRM DP MST topology managers in an atomic update,
884 * tracking only the old state. This is useful in disable functions, where we
885 * need the old state the hardware is still in.
886 */
887#define for_each_old_mst_mgr_in_state(__state, mgr, old_state, __i) \
888 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
889 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), NULL, (__i)))
890
891/**
892 * for_each_new_mst_mgr_in_state - iterate over all DP MST topology managers
893 * in an atomic update
894 * @__state: &struct drm_atomic_state pointer
895 * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
896 * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
897 * state
898 * @__i: int iteration cursor, for macro-internal use
899 *
900 * This iterates over all DRM DP MST topology managers in an atomic update,
901 * tracking only the new state. This is useful in enable functions, where we
902 * need the new state the hardware should be in when the atomic commit
903 * operation has completed.
904 */
905#define for_each_new_mst_mgr_in_state(__state, mgr, new_state, __i) \
906 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
907 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), NULL, &(new_state), (__i)))
908
ad7f8a1f 909#endif