2 * Copyright © 2014 Red Hat.
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.
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
22 #ifndef _DRM_DP_MST_HELPER_H_
23 #define _DRM_DP_MST_HELPER_H_
25 #include <linux/types.h>
26 #include <drm/display/drm_dp_helper.h>
27 #include <drm/drm_atomic.h>
29 #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
30 #include <linux/stackdepot.h>
31 #include <linux/timekeeping.h>
33 enum drm_dp_mst_topology_ref_type {
34 DRM_DP_MST_TOPOLOGY_REF_GET,
35 DRM_DP_MST_TOPOLOGY_REF_PUT,
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;
43 depot_stack_handle_t backtrace;
47 #endif /* IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS) */
49 struct drm_dp_mst_branch;
52 * struct drm_dp_mst_port - MST port
53 * @port_num: port number
54 * @input: if this port is an input port. Protected by
55 * &drm_dp_mst_topology_mgr.base.lock.
56 * @mcs: message capability status - DP 1.2 spec. Protected by
57 * &drm_dp_mst_topology_mgr.base.lock.
58 * @ddps: DisplayPort Device Plug Status - DP 1.2. Protected by
59 * &drm_dp_mst_topology_mgr.base.lock.
60 * @pdt: Peer Device Type. Protected by
61 * &drm_dp_mst_topology_mgr.base.lock.
62 * @ldps: Legacy Device Plug Status. Protected by
63 * &drm_dp_mst_topology_mgr.base.lock.
64 * @dpcd_rev: DPCD revision of device on this port. Protected by
65 * &drm_dp_mst_topology_mgr.base.lock.
66 * @num_sdp_streams: Number of simultaneous streams. Protected by
67 * &drm_dp_mst_topology_mgr.base.lock.
68 * @num_sdp_stream_sinks: Number of stream sinks. Protected by
69 * &drm_dp_mst_topology_mgr.base.lock.
70 * @full_pbn: Max possible bandwidth for this port. Protected by
71 * &drm_dp_mst_topology_mgr.base.lock.
72 * @next: link to next port on this branch device
73 * @aux: i2c aux transport to talk to device connected to this port, protected
74 * by &drm_dp_mst_topology_mgr.base.lock.
75 * @passthrough_aux: parent aux to which DSC pass-through requests should be
76 * sent, only set if DSC pass-through is possible.
77 * @parent: branch device parent of this port
78 * @vcpi: Virtual Channel Payload info for this port.
79 * @connector: DRM connector this port is connected to. Protected by
80 * &drm_dp_mst_topology_mgr.base.lock.
81 * @mgr: topology manager this port lives under.
83 * This structure represents an MST port endpoint on a device somewhere
84 * in the MST topology.
86 struct drm_dp_mst_port {
88 * @topology_kref: refcount for this port's lifetime in the topology,
89 * only the DP MST helpers should need to touch this
91 struct kref topology_kref;
94 * @malloc_kref: refcount for the memory allocation containing this
95 * structure. See drm_dp_mst_get_port_malloc() and
96 * drm_dp_mst_put_port_malloc().
98 struct kref malloc_kref;
100 #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
102 * @topology_ref_history: A history of each topology
103 * reference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.
105 struct drm_dp_mst_topology_ref_history topology_ref_history;
116 u8 num_sdp_stream_sinks;
118 struct list_head next;
120 * @mstb: the branch device connected to this port, if there is one.
121 * This should be considered protected for reading by
122 * &drm_dp_mst_topology_mgr.lock. There are two exceptions to this:
123 * &drm_dp_mst_topology_mgr.up_req_work and
124 * &drm_dp_mst_topology_mgr.work, which do not grab
125 * &drm_dp_mst_topology_mgr.lock during reads but are the only
126 * updaters of this list and are protected from writing concurrently
127 * by &drm_dp_mst_topology_mgr.probe_lock.
129 struct drm_dp_mst_branch *mstb;
130 struct drm_dp_aux aux; /* i2c bus for this port? */
131 struct drm_dp_aux *passthrough_aux;
132 struct drm_dp_mst_branch *parent;
134 struct drm_connector *connector;
135 struct drm_dp_mst_topology_mgr *mgr;
138 * @cached_edid: for DP logical ports - make tiling work by ensuring
139 * that the EDID for all connectors is read immediately.
141 struct edid *cached_edid;
143 * @has_audio: Tracks whether the sink connector to this port is
149 * @fec_capable: bool indicating if FEC can be supported up to that
150 * point in the MST topology.
155 /* sideband msg header - not bit struct */
156 struct drm_dp_sideband_msg_hdr {
168 struct drm_dp_sideband_msg_rx {
172 u8 curchunk_idx; /* chunk we are parsing now */
174 u8 curlen; /* total length of the msg */
177 struct drm_dp_sideband_msg_hdr initial_hdr;
181 * struct drm_dp_mst_branch - MST branch device.
182 * @rad: Relative Address to talk to this branch device.
183 * @lct: Link count total to talk to this branch device.
184 * @num_ports: number of ports on the branch.
185 * @port_parent: pointer to the port parent, NULL if toplevel.
186 * @mgr: topology manager for this branch device.
187 * @link_address_sent: if a link address message has been sent to this device yet.
188 * @guid: guid for DP 1.2 branch device. port under this branch can be
189 * identified by port #.
191 * This structure represents an MST branch device, there is one
192 * primary branch device at the root, along with any other branches connected
193 * to downstream port of parent branches.
195 struct drm_dp_mst_branch {
197 * @topology_kref: refcount for this branch device's lifetime in the
198 * topology, only the DP MST helpers should need to touch this
200 struct kref topology_kref;
203 * @malloc_kref: refcount for the memory allocation containing this
204 * structure. See drm_dp_mst_get_mstb_malloc() and
205 * drm_dp_mst_put_mstb_malloc().
207 struct kref malloc_kref;
209 #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
211 * @topology_ref_history: A history of each topology
212 * reference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.
214 struct drm_dp_mst_topology_ref_history topology_ref_history;
218 * @destroy_next: linked-list entry used by
219 * drm_dp_delayed_destroy_work()
221 struct list_head destroy_next;
228 * @ports: the list of ports on this branch device. This should be
229 * considered protected for reading by &drm_dp_mst_topology_mgr.lock.
230 * There are two exceptions to this:
231 * &drm_dp_mst_topology_mgr.up_req_work and
232 * &drm_dp_mst_topology_mgr.work, which do not grab
233 * &drm_dp_mst_topology_mgr.lock during reads but are the only
234 * updaters of this list and are protected from updating the list
235 * concurrently by @drm_dp_mst_topology_mgr.probe_lock
237 struct list_head ports;
239 struct drm_dp_mst_port *port_parent;
240 struct drm_dp_mst_topology_mgr *mgr;
242 bool link_address_sent;
244 /* global unique identifier to identify branch devices */
249 struct drm_dp_nak_reply {
255 struct drm_dp_link_address_ack_reply {
258 struct drm_dp_link_addr_reply_port {
264 bool legacy_device_plug_status;
268 u8 num_sdp_stream_sinks;
272 struct drm_dp_remote_dpcd_read_ack_reply {
278 struct drm_dp_remote_dpcd_write_ack_reply {
282 struct drm_dp_remote_dpcd_write_nak_reply {
285 u8 bytes_written_before_failure;
288 struct drm_dp_remote_i2c_read_ack_reply {
294 struct drm_dp_remote_i2c_read_nak_reply {
297 u8 i2c_nak_transaction;
300 struct drm_dp_remote_i2c_write_ack_reply {
304 struct drm_dp_query_stream_enc_status_ack_reply {
305 /* Bit[23:16]- Stream Id */
308 /* Bit[15]- Signed */
311 /* Bit[10:8]- Stream Output Sink Type */
312 bool unauthorizable_device_present;
313 bool legacy_device_present;
314 bool query_capable_device_present;
316 /* Bit[12:11]- Stream Output CP Type */
317 bool hdcp_1x_device_present;
318 bool hdcp_2x_device_present;
320 /* Bit[4]- Stream Authentication */
323 /* Bit[3]- Stream Encryption */
324 bool encryption_enabled;
326 /* Bit[2]- Stream Repeater Function Present */
327 bool repeater_present;
329 /* Bit[1:0]- Stream State */
333 #define DRM_DP_MAX_SDP_STREAMS 16
334 struct drm_dp_allocate_payload {
336 u8 number_sdp_streams;
339 u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
342 struct drm_dp_allocate_payload_ack_reply {
348 struct drm_dp_connection_status_notify {
351 bool legacy_device_plug_status;
352 bool displayport_device_plug_status;
353 bool message_capability_status;
358 struct drm_dp_remote_dpcd_read {
364 struct drm_dp_remote_dpcd_write {
371 #define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
372 struct drm_dp_remote_i2c_read {
375 struct drm_dp_remote_i2c_read_tx {
380 u8 i2c_transaction_delay;
381 } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
382 u8 read_i2c_device_id;
386 struct drm_dp_remote_i2c_write {
388 u8 write_i2c_device_id;
393 struct drm_dp_query_stream_enc_status {
395 u8 client_id[7]; /* 56-bit nonce */
397 bool valid_stream_event;
399 u8 valid_stream_behavior;
402 /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
403 struct drm_dp_port_number_req {
407 struct drm_dp_enum_path_resources_ack_reply {
410 u16 full_payload_bw_number;
411 u16 avail_payload_bw_number;
414 /* covers POWER_DOWN_PHY, POWER_UP_PHY */
415 struct drm_dp_port_number_rep {
419 struct drm_dp_query_payload {
424 struct drm_dp_resource_status_notify {
430 struct drm_dp_query_payload_ack_reply {
435 struct drm_dp_sideband_msg_req_body {
438 struct drm_dp_connection_status_notify conn_stat;
439 struct drm_dp_port_number_req port_num;
440 struct drm_dp_resource_status_notify resource_stat;
442 struct drm_dp_query_payload query_payload;
443 struct drm_dp_allocate_payload allocate_payload;
445 struct drm_dp_remote_dpcd_read dpcd_read;
446 struct drm_dp_remote_dpcd_write dpcd_write;
448 struct drm_dp_remote_i2c_read i2c_read;
449 struct drm_dp_remote_i2c_write i2c_write;
451 struct drm_dp_query_stream_enc_status enc_status;
455 struct drm_dp_sideband_msg_reply_body {
459 struct drm_dp_nak_reply nak;
460 struct drm_dp_link_address_ack_reply link_addr;
461 struct drm_dp_port_number_rep port_number;
463 struct drm_dp_enum_path_resources_ack_reply path_resources;
464 struct drm_dp_allocate_payload_ack_reply allocate_payload;
465 struct drm_dp_query_payload_ack_reply query_payload;
467 struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
468 struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
469 struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
471 struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
472 struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
473 struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
475 struct drm_dp_query_stream_enc_status_ack_reply enc_status;
479 /* msg is queued to be put into a slot */
480 #define DRM_DP_SIDEBAND_TX_QUEUED 0
481 /* msg has started transmitting on a slot - still on msgq */
482 #define DRM_DP_SIDEBAND_TX_START_SEND 1
483 /* msg has finished transmitting on a slot - removed from msgq only in slot */
484 #define DRM_DP_SIDEBAND_TX_SENT 2
485 /* msg has received a response - removed from slot */
486 #define DRM_DP_SIDEBAND_TX_RX 3
487 #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
489 struct drm_dp_sideband_msg_tx {
494 struct drm_dp_mst_branch *dst;
495 struct list_head next;
499 struct drm_dp_sideband_msg_reply_body reply;
502 /* sideband msg handler */
503 struct drm_dp_mst_topology_mgr;
504 struct drm_dp_mst_topology_cbs {
505 /* create a connector for a port */
506 struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
508 * Checks for any pending MST interrupts, passing them to MST core for
509 * processing, the same way an HPD IRQ pulse handler would do this.
510 * If provided MST core calls this callback from a poll-waiting loop
511 * when waiting for MST down message replies. The driver is expected
512 * to guard against a race between this callback and the driver's HPD
515 void (*poll_hpd_irq)(struct drm_dp_mst_topology_mgr *mgr);
518 #define to_dp_mst_topology_state(x) container_of(x, struct drm_dp_mst_topology_state, base)
521 * struct drm_dp_mst_atomic_payload - Atomic state struct for an MST payload
523 * The primary atomic state structure for a given MST payload. Stores information like current
524 * bandwidth allocation, intended action for this payload, etc.
526 struct drm_dp_mst_atomic_payload {
527 /** @port: The MST port assigned to this payload */
528 struct drm_dp_mst_port *port;
531 * @vc_start_slot: The time slot that this payload starts on. Because payload start slots
532 * can't be determined ahead of time, the contents of this value are UNDEFINED at atomic
533 * check time. This shouldn't usually matter, as the start slot should never be relevant for
534 * atomic state computations.
536 * Since this value is determined at commit time instead of check time, this value is
537 * protected by the MST helpers ensuring that async commits operating on the given topology
538 * never run in parallel. In the event that a driver does need to read this value (e.g. to
539 * inform hardware of the starting timeslot for a payload), the driver may either:
541 * * Read this field during the atomic commit after
542 * drm_dp_mst_atomic_wait_for_dependencies() has been called, which will ensure the
543 * previous MST states payload start slots have been copied over to the new state. Note
544 * that a new start slot won't be assigned/removed from this payload until
545 * drm_dp_add_payload_part1()/drm_dp_remove_payload() have been called.
546 * * Acquire the MST modesetting lock, and then wait for any pending MST-related commits to
547 * get committed to hardware by calling drm_crtc_commit_wait() on each of the
548 * &drm_crtc_commit structs in &drm_dp_mst_topology_state.commit_deps.
550 * If neither of the two above solutions suffice (e.g. the driver needs to read the start
551 * slot in the middle of an atomic commit without waiting for some reason), then drivers
552 * should cache this value themselves after changing payloads.
556 /** @vcpi: The Virtual Channel Payload Identifier */
560 * The number of timeslots allocated to this payload from the source DP Tx to
561 * the immediate downstream DP Rx
564 /** @pbn: The payload bandwidth for this payload */
567 /** @delete: Whether or not we intend to delete this payload during this atomic commit */
569 /** @dsc_enabled: Whether or not this payload has DSC enabled */
570 bool dsc_enabled : 1;
572 /** @next: The list node for this payload */
573 struct list_head next;
577 * struct drm_dp_mst_topology_state - DisplayPort MST topology atomic state
579 * This struct represents the atomic state of the toplevel DisplayPort MST manager
581 struct drm_dp_mst_topology_state {
582 /** @base: Base private state for atomic */
583 struct drm_private_state base;
585 /** @mgr: The topology manager */
586 struct drm_dp_mst_topology_mgr *mgr;
589 * @pending_crtc_mask: A bitmask of all CRTCs this topology state touches, drivers may
590 * modify this to add additional dependencies if needed.
592 u32 pending_crtc_mask;
594 * @commit_deps: A list of all CRTC commits affecting this topology, this field isn't
595 * populated until drm_dp_mst_atomic_wait_for_dependencies() is called.
597 struct drm_crtc_commit **commit_deps;
598 /** @num_commit_deps: The number of CRTC commits in @commit_deps */
599 size_t num_commit_deps;
601 /** @payload_mask: A bitmask of allocated VCPIs, used for VCPI assignments */
603 /** @payloads: The list of payloads being created/destroyed in this state */
604 struct list_head payloads;
606 /** @total_avail_slots: The total number of slots this topology can handle (63 or 64) */
607 u8 total_avail_slots;
608 /** @start_slot: The first usable time slot in this topology (1 or 0) */
612 * @pbn_div: The current PBN divisor for this topology. The driver is expected to fill this
618 #define to_dp_mst_topology_mgr(x) container_of(x, struct drm_dp_mst_topology_mgr, base)
621 * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
623 * This struct represents the toplevel displayport MST topology manager.
624 * There should be one instance of this for every MST capable DP connector
627 struct drm_dp_mst_topology_mgr {
629 * @base: Base private object for atomic
631 struct drm_private_obj base;
634 * @dev: device pointer for adding i2c devices etc.
636 struct drm_device *dev;
638 * @cbs: callbacks for connector addition and destruction.
640 const struct drm_dp_mst_topology_cbs *cbs;
642 * @max_dpcd_transaction_bytes: maximum number of bytes to read/write
645 int max_dpcd_transaction_bytes;
647 * @aux: AUX channel for the DP MST connector this topolgy mgr is
650 struct drm_dp_aux *aux;
652 * @max_payloads: maximum number of payloads the GPU can generate.
656 * @conn_base_id: DRM connector ID this mgr is connected to. Only used
657 * to build the MST connector path value.
662 * @up_req_recv: Message receiver state for up requests.
664 struct drm_dp_sideband_msg_rx up_req_recv;
667 * @down_rep_recv: Message receiver state for replies to down
670 struct drm_dp_sideband_msg_rx down_rep_recv;
673 * @lock: protects @mst_state, @mst_primary, @dpcd, and
674 * @payload_id_table_cleared.
679 * @probe_lock: Prevents @work and @up_req_work, the only writers of
680 * &drm_dp_mst_port.mstb and &drm_dp_mst_branch.ports, from racing
681 * while they update the topology.
683 struct mutex probe_lock;
686 * @mst_state: If this manager is enabled for an MST capable port. False
687 * if no MST sink/branch devices is connected.
692 * @payload_id_table_cleared: Whether or not we've cleared the payload
693 * ID table for @mst_primary. Protected by @lock.
695 bool payload_id_table_cleared : 1;
698 * @payload_count: The number of currently active payloads in hardware. This value is only
699 * intended to be used internally by MST helpers for payload tracking, and is only safe to
700 * read/write from the atomic commit (not check) context.
705 * @next_start_slot: The starting timeslot to use for new VC payloads. This value is used
706 * internally by MST helpers for payload tracking, and is only safe to read/write from the
707 * atomic commit (not check) context.
712 * @mst_primary: Pointer to the primary/first branch device.
714 struct drm_dp_mst_branch *mst_primary;
717 * @dpcd: Cache of DPCD for primary port.
719 u8 dpcd[DP_RECEIVER_CAP_SIZE];
721 * @sink_count: Sink count from DEVICE_SERVICE_IRQ_VECTOR_ESI0.
726 * @funcs: Atomic helper callbacks
728 const struct drm_private_state_funcs *funcs;
731 * @qlock: protects @tx_msg_downq and &drm_dp_sideband_msg_tx.state
736 * @tx_msg_downq: List of pending down requests
738 struct list_head tx_msg_downq;
741 * @tx_waitq: Wait to queue stall for the tx worker.
743 wait_queue_head_t tx_waitq;
747 struct work_struct work;
749 * @tx_work: Sideband transmit worker. This can nest within the main
750 * @work worker for each transaction @work launches.
752 struct work_struct tx_work;
755 * @destroy_port_list: List of to be destroyed connectors.
757 struct list_head destroy_port_list;
759 * @destroy_branch_device_list: List of to be destroyed branch
762 struct list_head destroy_branch_device_list;
764 * @delayed_destroy_lock: Protects @destroy_port_list and
765 * @destroy_branch_device_list.
767 struct mutex delayed_destroy_lock;
770 * @delayed_destroy_wq: Workqueue used for delayed_destroy_work items.
771 * A dedicated WQ makes it possible to drain any requeued work items
774 struct workqueue_struct *delayed_destroy_wq;
777 * @delayed_destroy_work: Work item to destroy MST port and branch
778 * devices, needed to avoid locking inversion.
780 struct work_struct delayed_destroy_work;
783 * @up_req_list: List of pending up requests from the topology that
784 * need to be processed, in chronological order.
786 struct list_head up_req_list;
788 * @up_req_lock: Protects @up_req_list
790 struct mutex up_req_lock;
792 * @up_req_work: Work item to process up requests received from the
793 * topology. Needed to avoid blocking hotplug handling and sideband
796 struct work_struct up_req_work;
798 #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
800 * @topology_ref_history_lock: protects
801 * &drm_dp_mst_port.topology_ref_history and
802 * &drm_dp_mst_branch.topology_ref_history.
804 struct mutex topology_ref_history_lock;
808 int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,
809 struct drm_device *dev, struct drm_dp_aux *aux,
810 int max_dpcd_transaction_bytes,
811 int max_payloads, int conn_base_id);
813 void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
815 bool drm_dp_read_mst_cap(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
816 int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
818 int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
822 drm_dp_mst_detect_port(struct drm_connector *connector,
823 struct drm_modeset_acquire_ctx *ctx,
824 struct drm_dp_mst_topology_mgr *mgr,
825 struct drm_dp_mst_port *port);
827 struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
829 int drm_dp_get_vc_payload_bw(const struct drm_dp_mst_topology_mgr *mgr,
830 int link_rate, int link_lane_count);
832 int drm_dp_calc_pbn_mode(int clock, int bpp, bool dsc);
834 void drm_dp_mst_update_slots(struct drm_dp_mst_topology_state *mst_state, uint8_t link_encoding_cap);
836 int drm_dp_add_payload_part1(struct drm_dp_mst_topology_mgr *mgr,
837 struct drm_dp_mst_topology_state *mst_state,
838 struct drm_dp_mst_atomic_payload *payload);
839 int drm_dp_add_payload_part2(struct drm_dp_mst_topology_mgr *mgr,
840 struct drm_atomic_state *state,
841 struct drm_dp_mst_atomic_payload *payload);
842 void drm_dp_remove_payload(struct drm_dp_mst_topology_mgr *mgr,
843 struct drm_dp_mst_topology_state *mst_state,
844 struct drm_dp_mst_atomic_payload *payload);
846 int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
848 void drm_dp_mst_dump_topology(struct seq_file *m,
849 struct drm_dp_mst_topology_mgr *mgr);
851 void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
853 drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr,
856 ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
857 unsigned int offset, void *buffer, size_t size);
858 ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
859 unsigned int offset, void *buffer, size_t size);
861 int drm_dp_mst_connector_late_register(struct drm_connector *connector,
862 struct drm_dp_mst_port *port);
863 void drm_dp_mst_connector_early_unregister(struct drm_connector *connector,
864 struct drm_dp_mst_port *port);
866 struct drm_dp_mst_topology_state *
867 drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
868 struct drm_dp_mst_topology_mgr *mgr);
869 struct drm_dp_mst_topology_state *
870 drm_atomic_get_new_mst_topology_state(struct drm_atomic_state *state,
871 struct drm_dp_mst_topology_mgr *mgr);
872 struct drm_dp_mst_atomic_payload *
873 drm_atomic_get_mst_payload_state(struct drm_dp_mst_topology_state *state,
874 struct drm_dp_mst_port *port);
876 drm_dp_atomic_find_time_slots(struct drm_atomic_state *state,
877 struct drm_dp_mst_topology_mgr *mgr,
878 struct drm_dp_mst_port *port, int pbn);
879 int drm_dp_mst_atomic_enable_dsc(struct drm_atomic_state *state,
880 struct drm_dp_mst_port *port,
881 int pbn, bool enable);
883 drm_dp_mst_add_affected_dsc_crtcs(struct drm_atomic_state *state,
884 struct drm_dp_mst_topology_mgr *mgr);
886 drm_dp_atomic_release_time_slots(struct drm_atomic_state *state,
887 struct drm_dp_mst_topology_mgr *mgr,
888 struct drm_dp_mst_port *port);
889 void drm_dp_mst_atomic_wait_for_dependencies(struct drm_atomic_state *state);
890 int __must_check drm_dp_mst_atomic_setup_commit(struct drm_atomic_state *state);
891 int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr,
892 struct drm_dp_mst_port *port, bool power_up);
893 int drm_dp_send_query_stream_enc_status(struct drm_dp_mst_topology_mgr *mgr,
894 struct drm_dp_mst_port *port,
895 struct drm_dp_query_stream_enc_status_ack_reply *status);
896 int __must_check drm_dp_mst_atomic_check(struct drm_atomic_state *state);
897 int __must_check drm_dp_mst_root_conn_atomic_check(struct drm_connector_state *new_conn_state,
898 struct drm_dp_mst_topology_mgr *mgr);
900 void drm_dp_mst_get_port_malloc(struct drm_dp_mst_port *port);
901 void drm_dp_mst_put_port_malloc(struct drm_dp_mst_port *port);
903 struct drm_dp_aux *drm_dp_mst_dsc_aux_for_port(struct drm_dp_mst_port *port);
905 static inline struct drm_dp_mst_topology_state *
906 to_drm_dp_mst_topology_state(struct drm_private_state *state)
908 return container_of(state, struct drm_dp_mst_topology_state, base);
911 extern const struct drm_private_state_funcs drm_dp_mst_topology_state_funcs;
914 * __drm_dp_mst_state_iter_get - private atomic state iterator function for
916 * @state: &struct drm_atomic_state pointer
917 * @mgr: pointer to the &struct drm_dp_mst_topology_mgr iteration cursor
918 * @old_state: optional pointer to the old &struct drm_dp_mst_topology_state
920 * @new_state: optional pointer to the new &struct drm_dp_mst_topology_state
922 * @i: int iteration cursor, for macro-internal use
924 * Used by for_each_oldnew_mst_mgr_in_state(),
925 * for_each_old_mst_mgr_in_state(), and for_each_new_mst_mgr_in_state(). Don't
926 * call this directly.
929 * True if the current &struct drm_private_obj is a &struct
930 * drm_dp_mst_topology_mgr, false otherwise.
933 __drm_dp_mst_state_iter_get(struct drm_atomic_state *state,
934 struct drm_dp_mst_topology_mgr **mgr,
935 struct drm_dp_mst_topology_state **old_state,
936 struct drm_dp_mst_topology_state **new_state,
939 struct __drm_private_objs_state *objs_state = &state->private_objs[i];
941 if (objs_state->ptr->funcs != &drm_dp_mst_topology_state_funcs)
944 *mgr = to_dp_mst_topology_mgr(objs_state->ptr);
946 *old_state = to_dp_mst_topology_state(objs_state->old_state);
948 *new_state = to_dp_mst_topology_state(objs_state->new_state);
954 * for_each_oldnew_mst_mgr_in_state - iterate over all DP MST topology
955 * managers in an atomic update
956 * @__state: &struct drm_atomic_state pointer
957 * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
958 * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
960 * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
962 * @__i: int iteration cursor, for macro-internal use
964 * This iterates over all DRM DP MST topology managers in an atomic update,
965 * tracking both old and new state. This is useful in places where the state
966 * delta needs to be considered, for example in atomic check functions.
968 #define for_each_oldnew_mst_mgr_in_state(__state, mgr, old_state, new_state, __i) \
969 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
970 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), &(new_state), (__i)))
973 * for_each_old_mst_mgr_in_state - iterate over all DP MST topology managers
974 * in an atomic update
975 * @__state: &struct drm_atomic_state pointer
976 * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
977 * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
979 * @__i: int iteration cursor, for macro-internal use
981 * This iterates over all DRM DP MST topology managers in an atomic update,
982 * tracking only the old state. This is useful in disable functions, where we
983 * need the old state the hardware is still in.
985 #define for_each_old_mst_mgr_in_state(__state, mgr, old_state, __i) \
986 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
987 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), NULL, (__i)))
990 * for_each_new_mst_mgr_in_state - iterate over all DP MST topology managers
991 * in an atomic update
992 * @__state: &struct drm_atomic_state pointer
993 * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
994 * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
996 * @__i: int iteration cursor, for macro-internal use
998 * This iterates over all DRM DP MST topology managers in an atomic update,
999 * tracking only the new state. This is useful in enable functions, where we
1000 * need the new state the hardware should be in when the atomic commit
1001 * operation has completed.
1003 #define for_each_new_mst_mgr_in_state(__state, mgr, new_state, __i) \
1004 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
1005 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), NULL, &(new_state), (__i)))