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