1da68386dSThomas Zimmermann /*
2da68386dSThomas Zimmermann  * Copyright © 2014 Red Hat.
3da68386dSThomas Zimmermann  *
4da68386dSThomas Zimmermann  * Permission to use, copy, modify, distribute, and sell this software and its
5da68386dSThomas Zimmermann  * documentation for any purpose is hereby granted without fee, provided that
6da68386dSThomas Zimmermann  * the above copyright notice appear in all copies and that both that copyright
7da68386dSThomas Zimmermann  * notice and this permission notice appear in supporting documentation, and
8da68386dSThomas Zimmermann  * that the name of the copyright holders not be used in advertising or
9da68386dSThomas Zimmermann  * publicity pertaining to distribution of the software without specific,
10da68386dSThomas Zimmermann  * written prior permission.  The copyright holders make no representations
11da68386dSThomas Zimmermann  * about the suitability of this software for any purpose.  It is provided "as
12da68386dSThomas Zimmermann  * is" without express or implied warranty.
13da68386dSThomas Zimmermann  *
14da68386dSThomas Zimmermann  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15da68386dSThomas Zimmermann  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16da68386dSThomas Zimmermann  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17da68386dSThomas Zimmermann  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18da68386dSThomas Zimmermann  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19da68386dSThomas Zimmermann  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20da68386dSThomas Zimmermann  * OF THIS SOFTWARE.
21da68386dSThomas Zimmermann  */
22da68386dSThomas Zimmermann #ifndef _DRM_DP_MST_HELPER_H_
23da68386dSThomas Zimmermann #define _DRM_DP_MST_HELPER_H_
24da68386dSThomas Zimmermann 
25da68386dSThomas Zimmermann #include <linux/types.h>
26da68386dSThomas Zimmermann #include <drm/display/drm_dp_helper.h>
27da68386dSThomas Zimmermann #include <drm/drm_atomic.h>
28da68386dSThomas Zimmermann 
29da68386dSThomas Zimmermann #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
30da68386dSThomas Zimmermann #include <linux/stackdepot.h>
31da68386dSThomas Zimmermann #include <linux/timekeeping.h>
32da68386dSThomas Zimmermann 
33da68386dSThomas Zimmermann enum drm_dp_mst_topology_ref_type {
34da68386dSThomas Zimmermann 	DRM_DP_MST_TOPOLOGY_REF_GET,
35da68386dSThomas Zimmermann 	DRM_DP_MST_TOPOLOGY_REF_PUT,
36da68386dSThomas Zimmermann };
37da68386dSThomas Zimmermann 
38da68386dSThomas Zimmermann struct drm_dp_mst_topology_ref_history {
39da68386dSThomas Zimmermann 	struct drm_dp_mst_topology_ref_entry {
40da68386dSThomas Zimmermann 		enum drm_dp_mst_topology_ref_type type;
41da68386dSThomas Zimmermann 		int count;
42da68386dSThomas Zimmermann 		ktime_t ts_nsec;
43da68386dSThomas Zimmermann 		depot_stack_handle_t backtrace;
44da68386dSThomas Zimmermann 	} *entries;
45da68386dSThomas Zimmermann 	int len;
46da68386dSThomas Zimmermann };
47da68386dSThomas Zimmermann #endif /* IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS) */
48da68386dSThomas Zimmermann 
49da68386dSThomas Zimmermann struct drm_dp_mst_branch;
50da68386dSThomas Zimmermann 
51da68386dSThomas Zimmermann /**
52da68386dSThomas Zimmermann  * struct drm_dp_mst_port - MST port
53da68386dSThomas Zimmermann  * @port_num: port number
54da68386dSThomas Zimmermann  * @input: if this port is an input port. Protected by
55da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
56da68386dSThomas Zimmermann  * @mcs: message capability status - DP 1.2 spec. Protected by
57da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
58da68386dSThomas Zimmermann  * @ddps: DisplayPort Device Plug Status - DP 1.2. Protected by
59da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
60da68386dSThomas Zimmermann  * @pdt: Peer Device Type. Protected by
61da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
62da68386dSThomas Zimmermann  * @ldps: Legacy Device Plug Status. Protected by
63da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
64da68386dSThomas Zimmermann  * @dpcd_rev: DPCD revision of device on this port. Protected by
65da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
66da68386dSThomas Zimmermann  * @num_sdp_streams: Number of simultaneous streams. Protected by
67da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
68da68386dSThomas Zimmermann  * @num_sdp_stream_sinks: Number of stream sinks. Protected by
69da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
70da68386dSThomas Zimmermann  * @full_pbn: Max possible bandwidth for this port. Protected by
71da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
72da68386dSThomas Zimmermann  * @next: link to next port on this branch device
73da68386dSThomas Zimmermann  * @aux: i2c aux transport to talk to device connected to this port, protected
74da68386dSThomas Zimmermann  * by &drm_dp_mst_topology_mgr.base.lock.
7534f66763SHamza Mahfooz  * @passthrough_aux: parent aux to which DSC pass-through requests should be
7634f66763SHamza Mahfooz  * sent, only set if DSC pass-through is possible.
77da68386dSThomas Zimmermann  * @parent: branch device parent of this port
78da68386dSThomas Zimmermann  * @vcpi: Virtual Channel Payload info for this port.
79da68386dSThomas Zimmermann  * @connector: DRM connector this port is connected to. Protected by
80da68386dSThomas Zimmermann  * &drm_dp_mst_topology_mgr.base.lock.
81da68386dSThomas Zimmermann  * @mgr: topology manager this port lives under.
82da68386dSThomas Zimmermann  *
83da68386dSThomas Zimmermann  * This structure represents an MST port endpoint on a device somewhere
84da68386dSThomas Zimmermann  * in the MST topology.
85da68386dSThomas Zimmermann  */
86da68386dSThomas Zimmermann struct drm_dp_mst_port {
87da68386dSThomas Zimmermann 	/**
88da68386dSThomas Zimmermann 	 * @topology_kref: refcount for this port's lifetime in the topology,
89da68386dSThomas Zimmermann 	 * only the DP MST helpers should need to touch this
90da68386dSThomas Zimmermann 	 */
91da68386dSThomas Zimmermann 	struct kref topology_kref;
92da68386dSThomas Zimmermann 
93da68386dSThomas Zimmermann 	/**
94da68386dSThomas Zimmermann 	 * @malloc_kref: refcount for the memory allocation containing this
95da68386dSThomas Zimmermann 	 * structure. See drm_dp_mst_get_port_malloc() and
96da68386dSThomas Zimmermann 	 * drm_dp_mst_put_port_malloc().
97da68386dSThomas Zimmermann 	 */
98da68386dSThomas Zimmermann 	struct kref malloc_kref;
99da68386dSThomas Zimmermann 
100da68386dSThomas Zimmermann #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
101da68386dSThomas Zimmermann 	/**
102da68386dSThomas Zimmermann 	 * @topology_ref_history: A history of each topology
103da68386dSThomas Zimmermann 	 * reference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.
104da68386dSThomas Zimmermann 	 */
105da68386dSThomas Zimmermann 	struct drm_dp_mst_topology_ref_history topology_ref_history;
106da68386dSThomas Zimmermann #endif
107da68386dSThomas Zimmermann 
108da68386dSThomas Zimmermann 	u8 port_num;
109da68386dSThomas Zimmermann 	bool input;
110da68386dSThomas Zimmermann 	bool mcs;
111da68386dSThomas Zimmermann 	bool ddps;
112da68386dSThomas Zimmermann 	u8 pdt;
113da68386dSThomas Zimmermann 	bool ldps;
114da68386dSThomas Zimmermann 	u8 dpcd_rev;
115da68386dSThomas Zimmermann 	u8 num_sdp_streams;
116da68386dSThomas Zimmermann 	u8 num_sdp_stream_sinks;
117da68386dSThomas Zimmermann 	uint16_t full_pbn;
118da68386dSThomas Zimmermann 	struct list_head next;
119da68386dSThomas Zimmermann 	/**
120da68386dSThomas Zimmermann 	 * @mstb: the branch device connected to this port, if there is one.
121da68386dSThomas Zimmermann 	 * This should be considered protected for reading by
122da68386dSThomas Zimmermann 	 * &drm_dp_mst_topology_mgr.lock. There are two exceptions to this:
123da68386dSThomas Zimmermann 	 * &drm_dp_mst_topology_mgr.up_req_work and
124da68386dSThomas Zimmermann 	 * &drm_dp_mst_topology_mgr.work, which do not grab
125da68386dSThomas Zimmermann 	 * &drm_dp_mst_topology_mgr.lock during reads but are the only
126da68386dSThomas Zimmermann 	 * updaters of this list and are protected from writing concurrently
127da68386dSThomas Zimmermann 	 * by &drm_dp_mst_topology_mgr.probe_lock.
128da68386dSThomas Zimmermann 	 */
129da68386dSThomas Zimmermann 	struct drm_dp_mst_branch *mstb;
130da68386dSThomas Zimmermann 	struct drm_dp_aux aux; /* i2c bus for this port? */
13134f66763SHamza Mahfooz 	struct drm_dp_aux *passthrough_aux;
132da68386dSThomas Zimmermann 	struct drm_dp_mst_branch *parent;
133da68386dSThomas Zimmermann 
134da68386dSThomas Zimmermann 	struct drm_connector *connector;
135da68386dSThomas Zimmermann 	struct drm_dp_mst_topology_mgr *mgr;
136da68386dSThomas Zimmermann 
137da68386dSThomas Zimmermann 	/**
138da68386dSThomas Zimmermann 	 * @cached_edid: for DP logical ports - make tiling work by ensuring
139da68386dSThomas Zimmermann 	 * that the EDID for all connectors is read immediately.
140da68386dSThomas Zimmermann 	 */
141c1c9042bSJani Nikula 	const struct drm_edid *cached_edid;
142da68386dSThomas Zimmermann 
143da68386dSThomas Zimmermann 	/**
144da68386dSThomas Zimmermann 	 * @fec_capable: bool indicating if FEC can be supported up to that
145da68386dSThomas Zimmermann 	 * point in the MST topology.
146da68386dSThomas Zimmermann 	 */
147da68386dSThomas Zimmermann 	bool fec_capable;
148da68386dSThomas Zimmermann };
149da68386dSThomas Zimmermann 
150da68386dSThomas Zimmermann /* sideband msg header - not bit struct */
151da68386dSThomas Zimmermann struct drm_dp_sideband_msg_hdr {
152da68386dSThomas Zimmermann 	u8 lct;
153da68386dSThomas Zimmermann 	u8 lcr;
154da68386dSThomas Zimmermann 	u8 rad[8];
155da68386dSThomas Zimmermann 	bool broadcast;
156da68386dSThomas Zimmermann 	bool path_msg;
157da68386dSThomas Zimmermann 	u8 msg_len;
158da68386dSThomas Zimmermann 	bool somt;
159da68386dSThomas Zimmermann 	bool eomt;
160da68386dSThomas Zimmermann 	bool seqno;
161da68386dSThomas Zimmermann };
162da68386dSThomas Zimmermann 
163da68386dSThomas Zimmermann struct drm_dp_sideband_msg_rx {
164da68386dSThomas Zimmermann 	u8 chunk[48];
165da68386dSThomas Zimmermann 	u8 msg[256];
166da68386dSThomas Zimmermann 	u8 curchunk_len;
167da68386dSThomas Zimmermann 	u8 curchunk_idx; /* chunk we are parsing now */
168da68386dSThomas Zimmermann 	u8 curchunk_hdrlen;
169da68386dSThomas Zimmermann 	u8 curlen; /* total length of the msg */
170da68386dSThomas Zimmermann 	bool have_somt;
171da68386dSThomas Zimmermann 	bool have_eomt;
172da68386dSThomas Zimmermann 	struct drm_dp_sideband_msg_hdr initial_hdr;
173da68386dSThomas Zimmermann };
174da68386dSThomas Zimmermann 
175da68386dSThomas Zimmermann /**
176da68386dSThomas Zimmermann  * struct drm_dp_mst_branch - MST branch device.
177da68386dSThomas Zimmermann  * @rad: Relative Address to talk to this branch device.
178da68386dSThomas Zimmermann  * @lct: Link count total to talk to this branch device.
179da68386dSThomas Zimmermann  * @num_ports: number of ports on the branch.
180da68386dSThomas Zimmermann  * @port_parent: pointer to the port parent, NULL if toplevel.
181da68386dSThomas Zimmermann  * @mgr: topology manager for this branch device.
182da68386dSThomas Zimmermann  * @link_address_sent: if a link address message has been sent to this device yet.
183da68386dSThomas Zimmermann  * @guid: guid for DP 1.2 branch device. port under this branch can be
184da68386dSThomas Zimmermann  * identified by port #.
185da68386dSThomas Zimmermann  *
186da68386dSThomas Zimmermann  * This structure represents an MST branch device, there is one
187da68386dSThomas Zimmermann  * primary branch device at the root, along with any other branches connected
188da68386dSThomas Zimmermann  * to downstream port of parent branches.
189da68386dSThomas Zimmermann  */
190da68386dSThomas Zimmermann struct drm_dp_mst_branch {
191da68386dSThomas Zimmermann 	/**
192da68386dSThomas Zimmermann 	 * @topology_kref: refcount for this branch device's lifetime in the
193da68386dSThomas Zimmermann 	 * topology, only the DP MST helpers should need to touch this
194da68386dSThomas Zimmermann 	 */
195da68386dSThomas Zimmermann 	struct kref topology_kref;
196da68386dSThomas Zimmermann 
197da68386dSThomas Zimmermann 	/**
198da68386dSThomas Zimmermann 	 * @malloc_kref: refcount for the memory allocation containing this
199da68386dSThomas Zimmermann 	 * structure. See drm_dp_mst_get_mstb_malloc() and
200da68386dSThomas Zimmermann 	 * drm_dp_mst_put_mstb_malloc().
201da68386dSThomas Zimmermann 	 */
202da68386dSThomas Zimmermann 	struct kref malloc_kref;
203da68386dSThomas Zimmermann 
204da68386dSThomas Zimmermann #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
205da68386dSThomas Zimmermann 	/**
206da68386dSThomas Zimmermann 	 * @topology_ref_history: A history of each topology
207da68386dSThomas Zimmermann 	 * reference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.
208da68386dSThomas Zimmermann 	 */
209da68386dSThomas Zimmermann 	struct drm_dp_mst_topology_ref_history topology_ref_history;
210da68386dSThomas Zimmermann #endif
211da68386dSThomas Zimmermann 
212da68386dSThomas Zimmermann 	/**
213da68386dSThomas Zimmermann 	 * @destroy_next: linked-list entry used by
214da68386dSThomas Zimmermann 	 * drm_dp_delayed_destroy_work()
215da68386dSThomas Zimmermann 	 */
216da68386dSThomas Zimmermann 	struct list_head destroy_next;
217da68386dSThomas Zimmermann 
218da68386dSThomas Zimmermann 	u8 rad[8];
219da68386dSThomas Zimmermann 	u8 lct;
220da68386dSThomas Zimmermann 	int num_ports;
221da68386dSThomas Zimmermann 
222da68386dSThomas Zimmermann 	/**
223da68386dSThomas Zimmermann 	 * @ports: the list of ports on this branch device. This should be
224da68386dSThomas Zimmermann 	 * considered protected for reading by &drm_dp_mst_topology_mgr.lock.
225da68386dSThomas Zimmermann 	 * There are two exceptions to this:
226da68386dSThomas Zimmermann 	 * &drm_dp_mst_topology_mgr.up_req_work and
227da68386dSThomas Zimmermann 	 * &drm_dp_mst_topology_mgr.work, which do not grab
228da68386dSThomas Zimmermann 	 * &drm_dp_mst_topology_mgr.lock during reads but are the only
229da68386dSThomas Zimmermann 	 * updaters of this list and are protected from updating the list
230da68386dSThomas Zimmermann 	 * concurrently by @drm_dp_mst_topology_mgr.probe_lock
231da68386dSThomas Zimmermann 	 */
232da68386dSThomas Zimmermann 	struct list_head ports;
233da68386dSThomas Zimmermann 
234da68386dSThomas Zimmermann 	struct drm_dp_mst_port *port_parent;
235da68386dSThomas Zimmermann 	struct drm_dp_mst_topology_mgr *mgr;
236da68386dSThomas Zimmermann 
237da68386dSThomas Zimmermann 	bool link_address_sent;
238da68386dSThomas Zimmermann 
239da68386dSThomas Zimmermann 	/* global unique identifier to identify branch devices */
240da68386dSThomas Zimmermann 	u8 guid[16];
241da68386dSThomas Zimmermann };
242da68386dSThomas Zimmermann 
243da68386dSThomas Zimmermann 
244da68386dSThomas Zimmermann struct drm_dp_nak_reply {
245da68386dSThomas Zimmermann 	u8 guid[16];
246da68386dSThomas Zimmermann 	u8 reason;
247da68386dSThomas Zimmermann 	u8 nak_data;
248da68386dSThomas Zimmermann };
249da68386dSThomas Zimmermann 
250da68386dSThomas Zimmermann struct drm_dp_link_address_ack_reply {
251da68386dSThomas Zimmermann 	u8 guid[16];
252da68386dSThomas Zimmermann 	u8 nports;
253da68386dSThomas Zimmermann 	struct drm_dp_link_addr_reply_port {
254da68386dSThomas Zimmermann 		bool input_port;
255da68386dSThomas Zimmermann 		u8 peer_device_type;
256da68386dSThomas Zimmermann 		u8 port_number;
257da68386dSThomas Zimmermann 		bool mcs;
258da68386dSThomas Zimmermann 		bool ddps;
259da68386dSThomas Zimmermann 		bool legacy_device_plug_status;
260da68386dSThomas Zimmermann 		u8 dpcd_revision;
261da68386dSThomas Zimmermann 		u8 peer_guid[16];
262da68386dSThomas Zimmermann 		u8 num_sdp_streams;
263da68386dSThomas Zimmermann 		u8 num_sdp_stream_sinks;
264da68386dSThomas Zimmermann 	} ports[16];
265da68386dSThomas Zimmermann };
266da68386dSThomas Zimmermann 
267da68386dSThomas Zimmermann struct drm_dp_remote_dpcd_read_ack_reply {
268da68386dSThomas Zimmermann 	u8 port_number;
269da68386dSThomas Zimmermann 	u8 num_bytes;
270da68386dSThomas Zimmermann 	u8 bytes[255];
271da68386dSThomas Zimmermann };
272da68386dSThomas Zimmermann 
273da68386dSThomas Zimmermann struct drm_dp_remote_dpcd_write_ack_reply {
274da68386dSThomas Zimmermann 	u8 port_number;
275da68386dSThomas Zimmermann };
276da68386dSThomas Zimmermann 
277da68386dSThomas Zimmermann struct drm_dp_remote_dpcd_write_nak_reply {
278da68386dSThomas Zimmermann 	u8 port_number;
279da68386dSThomas Zimmermann 	u8 reason;
280da68386dSThomas Zimmermann 	u8 bytes_written_before_failure;
281da68386dSThomas Zimmermann };
282da68386dSThomas Zimmermann 
283da68386dSThomas Zimmermann struct drm_dp_remote_i2c_read_ack_reply {
284da68386dSThomas Zimmermann 	u8 port_number;
285da68386dSThomas Zimmermann 	u8 num_bytes;
286da68386dSThomas Zimmermann 	u8 bytes[255];
287da68386dSThomas Zimmermann };
288da68386dSThomas Zimmermann 
289da68386dSThomas Zimmermann struct drm_dp_remote_i2c_read_nak_reply {
290da68386dSThomas Zimmermann 	u8 port_number;
291da68386dSThomas Zimmermann 	u8 nak_reason;
292da68386dSThomas Zimmermann 	u8 i2c_nak_transaction;
293da68386dSThomas Zimmermann };
294da68386dSThomas Zimmermann 
295da68386dSThomas Zimmermann struct drm_dp_remote_i2c_write_ack_reply {
296da68386dSThomas Zimmermann 	u8 port_number;
297da68386dSThomas Zimmermann };
298da68386dSThomas Zimmermann 
299da68386dSThomas Zimmermann struct drm_dp_query_stream_enc_status_ack_reply {
300da68386dSThomas Zimmermann 	/* Bit[23:16]- Stream Id */
301da68386dSThomas Zimmermann 	u8 stream_id;
302da68386dSThomas Zimmermann 
303da68386dSThomas Zimmermann 	/* Bit[15]- Signed */
304da68386dSThomas Zimmermann 	bool reply_signed;
305da68386dSThomas Zimmermann 
306da68386dSThomas Zimmermann 	/* Bit[10:8]- Stream Output Sink Type */
307da68386dSThomas Zimmermann 	bool unauthorizable_device_present;
308da68386dSThomas Zimmermann 	bool legacy_device_present;
309da68386dSThomas Zimmermann 	bool query_capable_device_present;
310da68386dSThomas Zimmermann 
311da68386dSThomas Zimmermann 	/* Bit[12:11]- Stream Output CP Type */
312da68386dSThomas Zimmermann 	bool hdcp_1x_device_present;
313da68386dSThomas Zimmermann 	bool hdcp_2x_device_present;
314da68386dSThomas Zimmermann 
315da68386dSThomas Zimmermann 	/* Bit[4]- Stream Authentication */
316da68386dSThomas Zimmermann 	bool auth_completed;
317da68386dSThomas Zimmermann 
318da68386dSThomas Zimmermann 	/* Bit[3]- Stream Encryption */
319da68386dSThomas Zimmermann 	bool encryption_enabled;
320da68386dSThomas Zimmermann 
321da68386dSThomas Zimmermann 	/* Bit[2]- Stream Repeater Function Present */
322da68386dSThomas Zimmermann 	bool repeater_present;
323da68386dSThomas Zimmermann 
324da68386dSThomas Zimmermann 	/* Bit[1:0]- Stream State */
325da68386dSThomas Zimmermann 	u8 state;
326da68386dSThomas Zimmermann };
327da68386dSThomas Zimmermann 
328da68386dSThomas Zimmermann #define DRM_DP_MAX_SDP_STREAMS 16
329da68386dSThomas Zimmermann struct drm_dp_allocate_payload {
330da68386dSThomas Zimmermann 	u8 port_number;
331da68386dSThomas Zimmermann 	u8 number_sdp_streams;
332da68386dSThomas Zimmermann 	u8 vcpi;
333da68386dSThomas Zimmermann 	u16 pbn;
334da68386dSThomas Zimmermann 	u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
335da68386dSThomas Zimmermann };
336da68386dSThomas Zimmermann 
337da68386dSThomas Zimmermann struct drm_dp_allocate_payload_ack_reply {
338da68386dSThomas Zimmermann 	u8 port_number;
339da68386dSThomas Zimmermann 	u8 vcpi;
340da68386dSThomas Zimmermann 	u16 allocated_pbn;
341da68386dSThomas Zimmermann };
342da68386dSThomas Zimmermann 
343da68386dSThomas Zimmermann struct drm_dp_connection_status_notify {
344da68386dSThomas Zimmermann 	u8 guid[16];
345da68386dSThomas Zimmermann 	u8 port_number;
346da68386dSThomas Zimmermann 	bool legacy_device_plug_status;
347da68386dSThomas Zimmermann 	bool displayport_device_plug_status;
348da68386dSThomas Zimmermann 	bool message_capability_status;
349da68386dSThomas Zimmermann 	bool input_port;
350da68386dSThomas Zimmermann 	u8 peer_device_type;
351da68386dSThomas Zimmermann };
352da68386dSThomas Zimmermann 
353da68386dSThomas Zimmermann struct drm_dp_remote_dpcd_read {
354da68386dSThomas Zimmermann 	u8 port_number;
355da68386dSThomas Zimmermann 	u32 dpcd_address;
356da68386dSThomas Zimmermann 	u8 num_bytes;
357da68386dSThomas Zimmermann };
358da68386dSThomas Zimmermann 
359da68386dSThomas Zimmermann struct drm_dp_remote_dpcd_write {
360da68386dSThomas Zimmermann 	u8 port_number;
361da68386dSThomas Zimmermann 	u32 dpcd_address;
362da68386dSThomas Zimmermann 	u8 num_bytes;
363da68386dSThomas Zimmermann 	u8 *bytes;
364da68386dSThomas Zimmermann };
365da68386dSThomas Zimmermann 
366da68386dSThomas Zimmermann #define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
367da68386dSThomas Zimmermann struct drm_dp_remote_i2c_read {
368da68386dSThomas Zimmermann 	u8 num_transactions;
369da68386dSThomas Zimmermann 	u8 port_number;
370da68386dSThomas Zimmermann 	struct drm_dp_remote_i2c_read_tx {
371da68386dSThomas Zimmermann 		u8 i2c_dev_id;
372da68386dSThomas Zimmermann 		u8 num_bytes;
373da68386dSThomas Zimmermann 		u8 *bytes;
374da68386dSThomas Zimmermann 		u8 no_stop_bit;
375da68386dSThomas Zimmermann 		u8 i2c_transaction_delay;
376da68386dSThomas Zimmermann 	} transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
377da68386dSThomas Zimmermann 	u8 read_i2c_device_id;
378da68386dSThomas Zimmermann 	u8 num_bytes_read;
379da68386dSThomas Zimmermann };
380da68386dSThomas Zimmermann 
381da68386dSThomas Zimmermann struct drm_dp_remote_i2c_write {
382da68386dSThomas Zimmermann 	u8 port_number;
383da68386dSThomas Zimmermann 	u8 write_i2c_device_id;
384da68386dSThomas Zimmermann 	u8 num_bytes;
385da68386dSThomas Zimmermann 	u8 *bytes;
386da68386dSThomas Zimmermann };
387da68386dSThomas Zimmermann 
388da68386dSThomas Zimmermann struct drm_dp_query_stream_enc_status {
389da68386dSThomas Zimmermann 	u8 stream_id;
390da68386dSThomas Zimmermann 	u8 client_id[7];	/* 56-bit nonce */
391da68386dSThomas Zimmermann 	u8 stream_event;
392da68386dSThomas Zimmermann 	bool valid_stream_event;
393da68386dSThomas Zimmermann 	u8 stream_behavior;
394da68386dSThomas Zimmermann 	u8 valid_stream_behavior;
395da68386dSThomas Zimmermann };
396da68386dSThomas Zimmermann 
397da68386dSThomas Zimmermann /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
398da68386dSThomas Zimmermann struct drm_dp_port_number_req {
399da68386dSThomas Zimmermann 	u8 port_number;
400da68386dSThomas Zimmermann };
401da68386dSThomas Zimmermann 
402da68386dSThomas Zimmermann struct drm_dp_enum_path_resources_ack_reply {
403da68386dSThomas Zimmermann 	u8 port_number;
404da68386dSThomas Zimmermann 	bool fec_capable;
405da68386dSThomas Zimmermann 	u16 full_payload_bw_number;
406da68386dSThomas Zimmermann 	u16 avail_payload_bw_number;
407da68386dSThomas Zimmermann };
408da68386dSThomas Zimmermann 
409da68386dSThomas Zimmermann /* covers POWER_DOWN_PHY, POWER_UP_PHY */
410da68386dSThomas Zimmermann struct drm_dp_port_number_rep {
411da68386dSThomas Zimmermann 	u8 port_number;
412da68386dSThomas Zimmermann };
413da68386dSThomas Zimmermann 
414da68386dSThomas Zimmermann struct drm_dp_query_payload {
415da68386dSThomas Zimmermann 	u8 port_number;
416da68386dSThomas Zimmermann 	u8 vcpi;
417da68386dSThomas Zimmermann };
418da68386dSThomas Zimmermann 
419da68386dSThomas Zimmermann struct drm_dp_resource_status_notify {
420da68386dSThomas Zimmermann 	u8 port_number;
421da68386dSThomas Zimmermann 	u8 guid[16];
422da68386dSThomas Zimmermann 	u16 available_pbn;
423da68386dSThomas Zimmermann };
424da68386dSThomas Zimmermann 
425da68386dSThomas Zimmermann struct drm_dp_query_payload_ack_reply {
426da68386dSThomas Zimmermann 	u8 port_number;
427da68386dSThomas Zimmermann 	u16 allocated_pbn;
428da68386dSThomas Zimmermann };
429da68386dSThomas Zimmermann 
430da68386dSThomas Zimmermann struct drm_dp_sideband_msg_req_body {
431da68386dSThomas Zimmermann 	u8 req_type;
432da68386dSThomas Zimmermann 	union ack_req {
433da68386dSThomas Zimmermann 		struct drm_dp_connection_status_notify conn_stat;
434da68386dSThomas Zimmermann 		struct drm_dp_port_number_req port_num;
435da68386dSThomas Zimmermann 		struct drm_dp_resource_status_notify resource_stat;
436da68386dSThomas Zimmermann 
437da68386dSThomas Zimmermann 		struct drm_dp_query_payload query_payload;
438da68386dSThomas Zimmermann 		struct drm_dp_allocate_payload allocate_payload;
439da68386dSThomas Zimmermann 
440da68386dSThomas Zimmermann 		struct drm_dp_remote_dpcd_read dpcd_read;
441da68386dSThomas Zimmermann 		struct drm_dp_remote_dpcd_write dpcd_write;
442da68386dSThomas Zimmermann 
443da68386dSThomas Zimmermann 		struct drm_dp_remote_i2c_read i2c_read;
444da68386dSThomas Zimmermann 		struct drm_dp_remote_i2c_write i2c_write;
445da68386dSThomas Zimmermann 
446da68386dSThomas Zimmermann 		struct drm_dp_query_stream_enc_status enc_status;
447da68386dSThomas Zimmermann 	} u;
448da68386dSThomas Zimmermann };
449da68386dSThomas Zimmermann 
450da68386dSThomas Zimmermann struct drm_dp_sideband_msg_reply_body {
451da68386dSThomas Zimmermann 	u8 reply_type;
452da68386dSThomas Zimmermann 	u8 req_type;
453da68386dSThomas Zimmermann 	union ack_replies {
454da68386dSThomas Zimmermann 		struct drm_dp_nak_reply nak;
455da68386dSThomas Zimmermann 		struct drm_dp_link_address_ack_reply link_addr;
456da68386dSThomas Zimmermann 		struct drm_dp_port_number_rep port_number;
457da68386dSThomas Zimmermann 
458da68386dSThomas Zimmermann 		struct drm_dp_enum_path_resources_ack_reply path_resources;
459da68386dSThomas Zimmermann 		struct drm_dp_allocate_payload_ack_reply allocate_payload;
460da68386dSThomas Zimmermann 		struct drm_dp_query_payload_ack_reply query_payload;
461da68386dSThomas Zimmermann 
462da68386dSThomas Zimmermann 		struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
463da68386dSThomas Zimmermann 		struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
464da68386dSThomas Zimmermann 		struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
465da68386dSThomas Zimmermann 
466da68386dSThomas Zimmermann 		struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
467da68386dSThomas Zimmermann 		struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
468da68386dSThomas Zimmermann 		struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
469da68386dSThomas Zimmermann 
470da68386dSThomas Zimmermann 		struct drm_dp_query_stream_enc_status_ack_reply enc_status;
471da68386dSThomas Zimmermann 	} u;
472da68386dSThomas Zimmermann };
473da68386dSThomas Zimmermann 
474da68386dSThomas Zimmermann /* msg is queued to be put into a slot */
475da68386dSThomas Zimmermann #define DRM_DP_SIDEBAND_TX_QUEUED 0
476da68386dSThomas Zimmermann /* msg has started transmitting on a slot - still on msgq */
477da68386dSThomas Zimmermann #define DRM_DP_SIDEBAND_TX_START_SEND 1
478da68386dSThomas Zimmermann /* msg has finished transmitting on a slot - removed from msgq only in slot */
479da68386dSThomas Zimmermann #define DRM_DP_SIDEBAND_TX_SENT 2
480da68386dSThomas Zimmermann /* msg has received a response - removed from slot */
481da68386dSThomas Zimmermann #define DRM_DP_SIDEBAND_TX_RX 3
482da68386dSThomas Zimmermann #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
483da68386dSThomas Zimmermann 
484da68386dSThomas Zimmermann struct drm_dp_sideband_msg_tx {
485da68386dSThomas Zimmermann 	u8 msg[256];
486da68386dSThomas Zimmermann 	u8 chunk[48];
487da68386dSThomas Zimmermann 	u8 cur_offset;
488da68386dSThomas Zimmermann 	u8 cur_len;
489da68386dSThomas Zimmermann 	struct drm_dp_mst_branch *dst;
490da68386dSThomas Zimmermann 	struct list_head next;
491da68386dSThomas Zimmermann 	int seqno;
492da68386dSThomas Zimmermann 	int state;
493da68386dSThomas Zimmermann 	bool path_msg;
494da68386dSThomas Zimmermann 	struct drm_dp_sideband_msg_reply_body reply;
495da68386dSThomas Zimmermann };
496da68386dSThomas Zimmermann 
497da68386dSThomas Zimmermann /* sideband msg handler */
498da68386dSThomas Zimmermann struct drm_dp_mst_topology_mgr;
499da68386dSThomas Zimmermann struct drm_dp_mst_topology_cbs {
500da68386dSThomas Zimmermann 	/* create a connector for a port */
501da68386dSThomas Zimmermann 	struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
502da68386dSThomas Zimmermann 	/*
503da68386dSThomas Zimmermann 	 * Checks for any pending MST interrupts, passing them to MST core for
504da68386dSThomas Zimmermann 	 * processing, the same way an HPD IRQ pulse handler would do this.
505da68386dSThomas Zimmermann 	 * If provided MST core calls this callback from a poll-waiting loop
506da68386dSThomas Zimmermann 	 * when waiting for MST down message replies. The driver is expected
507da68386dSThomas Zimmermann 	 * to guard against a race between this callback and the driver's HPD
508da68386dSThomas Zimmermann 	 * IRQ pulse handler.
509da68386dSThomas Zimmermann 	 */
510da68386dSThomas Zimmermann 	void (*poll_hpd_irq)(struct drm_dp_mst_topology_mgr *mgr);
511da68386dSThomas Zimmermann };
512da68386dSThomas Zimmermann 
513da68386dSThomas Zimmermann #define to_dp_mst_topology_state(x) container_of(x, struct drm_dp_mst_topology_state, base)
514da68386dSThomas Zimmermann 
5150bee2ae2SLyude Paul /**
5160bee2ae2SLyude Paul  * struct drm_dp_mst_atomic_payload - Atomic state struct for an MST payload
5170bee2ae2SLyude Paul  *
5180bee2ae2SLyude Paul  * The primary atomic state structure for a given MST payload. Stores information like current
5190bee2ae2SLyude Paul  * bandwidth allocation, intended action for this payload, etc.
5200bee2ae2SLyude Paul  */
52148b6b372SLyude Paul struct drm_dp_mst_atomic_payload {
5220bee2ae2SLyude Paul 	/** @port: The MST port assigned to this payload */
523da68386dSThomas Zimmermann 	struct drm_dp_mst_port *port;
524df78f7f6SLyude Paul 
525df78f7f6SLyude Paul 	/**
5264d07b0bcSLyude Paul 	 * @vc_start_slot: The time slot that this payload starts on. Because payload start slots
5274d07b0bcSLyude Paul 	 * can't be determined ahead of time, the contents of this value are UNDEFINED at atomic
5284d07b0bcSLyude Paul 	 * check time. This shouldn't usually matter, as the start slot should never be relevant for
5294d07b0bcSLyude Paul 	 * atomic state computations.
5304d07b0bcSLyude Paul 	 *
5314d07b0bcSLyude Paul 	 * Since this value is determined at commit time instead of check time, this value is
5324d07b0bcSLyude Paul 	 * protected by the MST helpers ensuring that async commits operating on the given topology
5334d07b0bcSLyude Paul 	 * never run in parallel. In the event that a driver does need to read this value (e.g. to
5344d07b0bcSLyude Paul 	 * inform hardware of the starting timeslot for a payload), the driver may either:
5354d07b0bcSLyude Paul 	 *
5364d07b0bcSLyude Paul 	 * * Read this field during the atomic commit after
5374d07b0bcSLyude Paul 	 *   drm_dp_mst_atomic_wait_for_dependencies() has been called, which will ensure the
5384d07b0bcSLyude Paul 	 *   previous MST states payload start slots have been copied over to the new state. Note
5394d07b0bcSLyude Paul 	 *   that a new start slot won't be assigned/removed from this payload until
5404d07b0bcSLyude Paul 	 *   drm_dp_add_payload_part1()/drm_dp_remove_payload() have been called.
5414d07b0bcSLyude Paul 	 * * Acquire the MST modesetting lock, and then wait for any pending MST-related commits to
5424d07b0bcSLyude Paul 	 *   get committed to hardware by calling drm_crtc_commit_wait() on each of the
5434d07b0bcSLyude Paul 	 *   &drm_crtc_commit structs in &drm_dp_mst_topology_state.commit_deps.
5444d07b0bcSLyude Paul 	 *
5454d07b0bcSLyude Paul 	 * If neither of the two above solutions suffice (e.g. the driver needs to read the start
5464d07b0bcSLyude Paul 	 * slot in the middle of an atomic commit without waiting for some reason), then drivers
5474d07b0bcSLyude Paul 	 * should cache this value themselves after changing payloads.
5484d07b0bcSLyude Paul 	 */
5494d07b0bcSLyude Paul 	s8 vc_start_slot;
5504d07b0bcSLyude Paul 
5514d07b0bcSLyude Paul 	/** @vcpi: The Virtual Channel Payload Identifier */
5524d07b0bcSLyude Paul 	u8 vcpi;
5534d07b0bcSLyude Paul 	/**
554df78f7f6SLyude Paul 	 * @time_slots:
555df78f7f6SLyude Paul 	 * The number of timeslots allocated to this payload from the source DP Tx to
556df78f7f6SLyude Paul 	 * the immediate downstream DP Rx
557df78f7f6SLyude Paul 	 */
558df78f7f6SLyude Paul 	int time_slots;
5590bee2ae2SLyude Paul 	/** @pbn: The payload bandwidth for this payload */
560da68386dSThomas Zimmermann 	int pbn;
5616366fc70SLyude Paul 
5626366fc70SLyude Paul 	/** @delete: Whether or not we intend to delete this payload during this atomic commit */
5636366fc70SLyude Paul 	bool delete : 1;
5640bee2ae2SLyude Paul 	/** @dsc_enabled: Whether or not this payload has DSC enabled */
5656366fc70SLyude Paul 	bool dsc_enabled : 1;
5660bee2ae2SLyude Paul 
5670bee2ae2SLyude Paul 	/** @next: The list node for this payload */
568da68386dSThomas Zimmermann 	struct list_head next;
569da68386dSThomas Zimmermann };
570da68386dSThomas Zimmermann 
5710bee2ae2SLyude Paul /**
5720bee2ae2SLyude Paul  * struct drm_dp_mst_topology_state - DisplayPort MST topology atomic state
5730bee2ae2SLyude Paul  *
5740bee2ae2SLyude Paul  * This struct represents the atomic state of the toplevel DisplayPort MST manager
5750bee2ae2SLyude Paul  */
576da68386dSThomas Zimmermann struct drm_dp_mst_topology_state {
5770bee2ae2SLyude Paul 	/** @base: Base private state for atomic */
578da68386dSThomas Zimmermann 	struct drm_private_state base;
5790bee2ae2SLyude Paul 
5800bee2ae2SLyude Paul 	/** @mgr: The topology manager */
581da68386dSThomas Zimmermann 	struct drm_dp_mst_topology_mgr *mgr;
5820bee2ae2SLyude Paul 
583a5c2c0d1SLyude Paul 	/**
584a5c2c0d1SLyude Paul 	 * @pending_crtc_mask: A bitmask of all CRTCs this topology state touches, drivers may
585a5c2c0d1SLyude Paul 	 * modify this to add additional dependencies if needed.
586a5c2c0d1SLyude Paul 	 */
587a5c2c0d1SLyude Paul 	u32 pending_crtc_mask;
588a5c2c0d1SLyude Paul 	/**
589a5c2c0d1SLyude Paul 	 * @commit_deps: A list of all CRTC commits affecting this topology, this field isn't
590a5c2c0d1SLyude Paul 	 * populated until drm_dp_mst_atomic_wait_for_dependencies() is called.
591a5c2c0d1SLyude Paul 	 */
592a5c2c0d1SLyude Paul 	struct drm_crtc_commit **commit_deps;
593a5c2c0d1SLyude Paul 	/** @num_commit_deps: The number of CRTC commits in @commit_deps */
594a5c2c0d1SLyude Paul 	size_t num_commit_deps;
595a5c2c0d1SLyude Paul 
5964d07b0bcSLyude Paul 	/** @payload_mask: A bitmask of allocated VCPIs, used for VCPI assignments */
5974d07b0bcSLyude Paul 	u32 payload_mask;
5984d07b0bcSLyude Paul 	/** @payloads: The list of payloads being created/destroyed in this state */
5994d07b0bcSLyude Paul 	struct list_head payloads;
6004d07b0bcSLyude Paul 
6010bee2ae2SLyude Paul 	/** @total_avail_slots: The total number of slots this topology can handle (63 or 64) */
602da68386dSThomas Zimmermann 	u8 total_avail_slots;
6030bee2ae2SLyude Paul 	/** @start_slot: The first usable time slot in this topology (1 or 0) */
604da68386dSThomas Zimmermann 	u8 start_slot;
6054d07b0bcSLyude Paul 
6064d07b0bcSLyude Paul 	/**
6074d07b0bcSLyude Paul 	 * @pbn_div: The current PBN divisor for this topology. The driver is expected to fill this
6084d07b0bcSLyude Paul 	 * out itself.
6094d07b0bcSLyude Paul 	 */
6104d07b0bcSLyude Paul 	int pbn_div;
611da68386dSThomas Zimmermann };
612da68386dSThomas Zimmermann 
613da68386dSThomas Zimmermann #define to_dp_mst_topology_mgr(x) container_of(x, struct drm_dp_mst_topology_mgr, base)
614da68386dSThomas Zimmermann 
615da68386dSThomas Zimmermann /**
616da68386dSThomas Zimmermann  * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
617da68386dSThomas Zimmermann  *
618da68386dSThomas Zimmermann  * This struct represents the toplevel displayport MST topology manager.
619da68386dSThomas Zimmermann  * There should be one instance of this for every MST capable DP connector
620da68386dSThomas Zimmermann  * on the GPU.
621da68386dSThomas Zimmermann  */
622da68386dSThomas Zimmermann struct drm_dp_mst_topology_mgr {
623da68386dSThomas Zimmermann 	/**
624da68386dSThomas Zimmermann 	 * @base: Base private object for atomic
625da68386dSThomas Zimmermann 	 */
626da68386dSThomas Zimmermann 	struct drm_private_obj base;
627da68386dSThomas Zimmermann 
628da68386dSThomas Zimmermann 	/**
629da68386dSThomas Zimmermann 	 * @dev: device pointer for adding i2c devices etc.
630da68386dSThomas Zimmermann 	 */
631da68386dSThomas Zimmermann 	struct drm_device *dev;
632da68386dSThomas Zimmermann 	/**
633da68386dSThomas Zimmermann 	 * @cbs: callbacks for connector addition and destruction.
634da68386dSThomas Zimmermann 	 */
635da68386dSThomas Zimmermann 	const struct drm_dp_mst_topology_cbs *cbs;
636da68386dSThomas Zimmermann 	/**
637da68386dSThomas Zimmermann 	 * @max_dpcd_transaction_bytes: maximum number of bytes to read/write
638da68386dSThomas Zimmermann 	 * in one go.
639da68386dSThomas Zimmermann 	 */
640da68386dSThomas Zimmermann 	int max_dpcd_transaction_bytes;
641da68386dSThomas Zimmermann 	/**
642da68386dSThomas Zimmermann 	 * @aux: AUX channel for the DP MST connector this topolgy mgr is
643da68386dSThomas Zimmermann 	 * controlling.
644da68386dSThomas Zimmermann 	 */
645da68386dSThomas Zimmermann 	struct drm_dp_aux *aux;
646da68386dSThomas Zimmermann 	/**
647da68386dSThomas Zimmermann 	 * @max_payloads: maximum number of payloads the GPU can generate.
648da68386dSThomas Zimmermann 	 */
649da68386dSThomas Zimmermann 	int max_payloads;
650da68386dSThomas Zimmermann 	/**
651da68386dSThomas Zimmermann 	 * @conn_base_id: DRM connector ID this mgr is connected to. Only used
652da68386dSThomas Zimmermann 	 * to build the MST connector path value.
653da68386dSThomas Zimmermann 	 */
654da68386dSThomas Zimmermann 	int conn_base_id;
655da68386dSThomas Zimmermann 
656da68386dSThomas Zimmermann 	/**
657da68386dSThomas Zimmermann 	 * @up_req_recv: Message receiver state for up requests.
658da68386dSThomas Zimmermann 	 */
659da68386dSThomas Zimmermann 	struct drm_dp_sideband_msg_rx up_req_recv;
660da68386dSThomas Zimmermann 
661da68386dSThomas Zimmermann 	/**
662da68386dSThomas Zimmermann 	 * @down_rep_recv: Message receiver state for replies to down
663da68386dSThomas Zimmermann 	 * requests.
664da68386dSThomas Zimmermann 	 */
665da68386dSThomas Zimmermann 	struct drm_dp_sideband_msg_rx down_rep_recv;
666da68386dSThomas Zimmermann 
667da68386dSThomas Zimmermann 	/**
668da68386dSThomas Zimmermann 	 * @lock: protects @mst_state, @mst_primary, @dpcd, and
669da68386dSThomas Zimmermann 	 * @payload_id_table_cleared.
670da68386dSThomas Zimmermann 	 */
671da68386dSThomas Zimmermann 	struct mutex lock;
672da68386dSThomas Zimmermann 
673da68386dSThomas Zimmermann 	/**
674da68386dSThomas Zimmermann 	 * @probe_lock: Prevents @work and @up_req_work, the only writers of
675da68386dSThomas Zimmermann 	 * &drm_dp_mst_port.mstb and &drm_dp_mst_branch.ports, from racing
676da68386dSThomas Zimmermann 	 * while they update the topology.
677da68386dSThomas Zimmermann 	 */
678da68386dSThomas Zimmermann 	struct mutex probe_lock;
679da68386dSThomas Zimmermann 
680da68386dSThomas Zimmermann 	/**
681da68386dSThomas Zimmermann 	 * @mst_state: If this manager is enabled for an MST capable port. False
682da68386dSThomas Zimmermann 	 * if no MST sink/branch devices is connected.
683da68386dSThomas Zimmermann 	 */
684da68386dSThomas Zimmermann 	bool mst_state : 1;
685da68386dSThomas Zimmermann 
686da68386dSThomas Zimmermann 	/**
687da68386dSThomas Zimmermann 	 * @payload_id_table_cleared: Whether or not we've cleared the payload
688da68386dSThomas Zimmermann 	 * ID table for @mst_primary. Protected by @lock.
689da68386dSThomas Zimmermann 	 */
690da68386dSThomas Zimmermann 	bool payload_id_table_cleared : 1;
691da68386dSThomas Zimmermann 
692da68386dSThomas Zimmermann 	/**
6934d07b0bcSLyude Paul 	 * @payload_count: The number of currently active payloads in hardware. This value is only
6944d07b0bcSLyude Paul 	 * intended to be used internally by MST helpers for payload tracking, and is only safe to
6954d07b0bcSLyude Paul 	 * read/write from the atomic commit (not check) context.
6964d07b0bcSLyude Paul 	 */
6974d07b0bcSLyude Paul 	u8 payload_count;
6984d07b0bcSLyude Paul 
6994d07b0bcSLyude Paul 	/**
7004d07b0bcSLyude Paul 	 * @next_start_slot: The starting timeslot to use for new VC payloads. This value is used
7014d07b0bcSLyude Paul 	 * internally by MST helpers for payload tracking, and is only safe to read/write from the
7024d07b0bcSLyude Paul 	 * atomic commit (not check) context.
7034d07b0bcSLyude Paul 	 */
7044d07b0bcSLyude Paul 	u8 next_start_slot;
7054d07b0bcSLyude Paul 
7064d07b0bcSLyude Paul 	/**
707da68386dSThomas Zimmermann 	 * @mst_primary: Pointer to the primary/first branch device.
708da68386dSThomas Zimmermann 	 */
709da68386dSThomas Zimmermann 	struct drm_dp_mst_branch *mst_primary;
710da68386dSThomas Zimmermann 
711da68386dSThomas Zimmermann 	/**
712da68386dSThomas Zimmermann 	 * @dpcd: Cache of DPCD for primary port.
713da68386dSThomas Zimmermann 	 */
714da68386dSThomas Zimmermann 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
715da68386dSThomas Zimmermann 	/**
716da68386dSThomas Zimmermann 	 * @sink_count: Sink count from DEVICE_SERVICE_IRQ_VECTOR_ESI0.
717da68386dSThomas Zimmermann 	 */
718da68386dSThomas Zimmermann 	u8 sink_count;
719da68386dSThomas Zimmermann 
720da68386dSThomas Zimmermann 	/**
721da68386dSThomas Zimmermann 	 * @funcs: Atomic helper callbacks
722da68386dSThomas Zimmermann 	 */
723da68386dSThomas Zimmermann 	const struct drm_private_state_funcs *funcs;
724da68386dSThomas Zimmermann 
725da68386dSThomas Zimmermann 	/**
726da68386dSThomas Zimmermann 	 * @qlock: protects @tx_msg_downq and &drm_dp_sideband_msg_tx.state
727da68386dSThomas Zimmermann 	 */
728da68386dSThomas Zimmermann 	struct mutex qlock;
729da68386dSThomas Zimmermann 
730da68386dSThomas Zimmermann 	/**
731da68386dSThomas Zimmermann 	 * @tx_msg_downq: List of pending down requests
732da68386dSThomas Zimmermann 	 */
733da68386dSThomas Zimmermann 	struct list_head tx_msg_downq;
734da68386dSThomas Zimmermann 
735da68386dSThomas Zimmermann 	/**
736da68386dSThomas Zimmermann 	 * @tx_waitq: Wait to queue stall for the tx worker.
737da68386dSThomas Zimmermann 	 */
738da68386dSThomas Zimmermann 	wait_queue_head_t tx_waitq;
739da68386dSThomas Zimmermann 	/**
740da68386dSThomas Zimmermann 	 * @work: Probe work.
741da68386dSThomas Zimmermann 	 */
742da68386dSThomas Zimmermann 	struct work_struct work;
743da68386dSThomas Zimmermann 	/**
744da68386dSThomas Zimmermann 	 * @tx_work: Sideband transmit worker. This can nest within the main
745da68386dSThomas Zimmermann 	 * @work worker for each transaction @work launches.
746da68386dSThomas Zimmermann 	 */
747da68386dSThomas Zimmermann 	struct work_struct tx_work;
748da68386dSThomas Zimmermann 
749da68386dSThomas Zimmermann 	/**
750da68386dSThomas Zimmermann 	 * @destroy_port_list: List of to be destroyed connectors.
751da68386dSThomas Zimmermann 	 */
752da68386dSThomas Zimmermann 	struct list_head destroy_port_list;
753da68386dSThomas Zimmermann 	/**
754da68386dSThomas Zimmermann 	 * @destroy_branch_device_list: List of to be destroyed branch
755da68386dSThomas Zimmermann 	 * devices.
756da68386dSThomas Zimmermann 	 */
757da68386dSThomas Zimmermann 	struct list_head destroy_branch_device_list;
758da68386dSThomas Zimmermann 	/**
759da68386dSThomas Zimmermann 	 * @delayed_destroy_lock: Protects @destroy_port_list and
760da68386dSThomas Zimmermann 	 * @destroy_branch_device_list.
761da68386dSThomas Zimmermann 	 */
762da68386dSThomas Zimmermann 	struct mutex delayed_destroy_lock;
763da68386dSThomas Zimmermann 
764da68386dSThomas Zimmermann 	/**
765da68386dSThomas Zimmermann 	 * @delayed_destroy_wq: Workqueue used for delayed_destroy_work items.
766da68386dSThomas Zimmermann 	 * A dedicated WQ makes it possible to drain any requeued work items
767da68386dSThomas Zimmermann 	 * on it.
768da68386dSThomas Zimmermann 	 */
769da68386dSThomas Zimmermann 	struct workqueue_struct *delayed_destroy_wq;
770da68386dSThomas Zimmermann 
771da68386dSThomas Zimmermann 	/**
772da68386dSThomas Zimmermann 	 * @delayed_destroy_work: Work item to destroy MST port and branch
773da68386dSThomas Zimmermann 	 * devices, needed to avoid locking inversion.
774da68386dSThomas Zimmermann 	 */
775da68386dSThomas Zimmermann 	struct work_struct delayed_destroy_work;
776da68386dSThomas Zimmermann 
777da68386dSThomas Zimmermann 	/**
778da68386dSThomas Zimmermann 	 * @up_req_list: List of pending up requests from the topology that
779da68386dSThomas Zimmermann 	 * need to be processed, in chronological order.
780da68386dSThomas Zimmermann 	 */
781da68386dSThomas Zimmermann 	struct list_head up_req_list;
782da68386dSThomas Zimmermann 	/**
783da68386dSThomas Zimmermann 	 * @up_req_lock: Protects @up_req_list
784da68386dSThomas Zimmermann 	 */
785da68386dSThomas Zimmermann 	struct mutex up_req_lock;
786da68386dSThomas Zimmermann 	/**
787da68386dSThomas Zimmermann 	 * @up_req_work: Work item to process up requests received from the
788da68386dSThomas Zimmermann 	 * topology. Needed to avoid blocking hotplug handling and sideband
789da68386dSThomas Zimmermann 	 * transmissions.
790da68386dSThomas Zimmermann 	 */
791da68386dSThomas Zimmermann 	struct work_struct up_req_work;
792da68386dSThomas Zimmermann 
793da68386dSThomas Zimmermann #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
794da68386dSThomas Zimmermann 	/**
795da68386dSThomas Zimmermann 	 * @topology_ref_history_lock: protects
796da68386dSThomas Zimmermann 	 * &drm_dp_mst_port.topology_ref_history and
797da68386dSThomas Zimmermann 	 * &drm_dp_mst_branch.topology_ref_history.
798da68386dSThomas Zimmermann 	 */
799da68386dSThomas Zimmermann 	struct mutex topology_ref_history_lock;
800da68386dSThomas Zimmermann #endif
801da68386dSThomas Zimmermann };
802da68386dSThomas Zimmermann 
803da68386dSThomas Zimmermann int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,
804da68386dSThomas Zimmermann 				 struct drm_device *dev, struct drm_dp_aux *aux,
805da68386dSThomas Zimmermann 				 int max_dpcd_transaction_bytes,
8064d07b0bcSLyude Paul 				 int max_payloads, int conn_base_id);
807da68386dSThomas Zimmermann 
808da68386dSThomas Zimmermann void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
809da68386dSThomas Zimmermann 
810da68386dSThomas Zimmermann bool drm_dp_read_mst_cap(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
811da68386dSThomas Zimmermann int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
812da68386dSThomas Zimmermann 
81372f1de49SWayne Lin int drm_dp_mst_hpd_irq_handle_event(struct drm_dp_mst_topology_mgr *mgr,
81472f1de49SWayne Lin 				    const u8 *esi,
81572f1de49SWayne Lin 				    u8 *ack,
81672f1de49SWayne Lin 				    bool *handled);
81772f1de49SWayne Lin void drm_dp_mst_hpd_irq_send_new_request(struct drm_dp_mst_topology_mgr *mgr);
818da68386dSThomas Zimmermann 
819da68386dSThomas Zimmermann int
820da68386dSThomas Zimmermann drm_dp_mst_detect_port(struct drm_connector *connector,
821da68386dSThomas Zimmermann 		       struct drm_modeset_acquire_ctx *ctx,
822da68386dSThomas Zimmermann 		       struct drm_dp_mst_topology_mgr *mgr,
823da68386dSThomas Zimmermann 		       struct drm_dp_mst_port *port);
824da68386dSThomas Zimmermann 
825c1c9042bSJani Nikula const struct drm_edid *drm_dp_mst_edid_read(struct drm_connector *connector,
826c1c9042bSJani Nikula 					    struct drm_dp_mst_topology_mgr *mgr,
827c1c9042bSJani Nikula 					    struct drm_dp_mst_port *port);
828c1c9042bSJani Nikula struct edid *drm_dp_mst_get_edid(struct drm_connector *connector,
829c1c9042bSJani Nikula 				 struct drm_dp_mst_topology_mgr *mgr,
830c1c9042bSJani Nikula 				 struct drm_dp_mst_port *port);
831da68386dSThomas Zimmermann 
832da68386dSThomas Zimmermann int drm_dp_get_vc_payload_bw(const struct drm_dp_mst_topology_mgr *mgr,
833da68386dSThomas Zimmermann 			     int link_rate, int link_lane_count);
834da68386dSThomas Zimmermann 
835*4e042f02SVille Syrjälä int drm_dp_calc_pbn_mode(int clock, int bpp);
836da68386dSThomas Zimmermann 
837da68386dSThomas Zimmermann void drm_dp_mst_update_slots(struct drm_dp_mst_topology_state *mst_state, uint8_t link_encoding_cap);
838da68386dSThomas Zimmermann 
8394d07b0bcSLyude Paul int drm_dp_add_payload_part1(struct drm_dp_mst_topology_mgr *mgr,
8404d07b0bcSLyude Paul 			     struct drm_dp_mst_topology_state *mst_state,
8414d07b0bcSLyude Paul 			     struct drm_dp_mst_atomic_payload *payload);
8424d07b0bcSLyude Paul int drm_dp_add_payload_part2(struct drm_dp_mst_topology_mgr *mgr,
8434d07b0bcSLyude Paul 			     struct drm_atomic_state *state,
8444d07b0bcSLyude Paul 			     struct drm_dp_mst_atomic_payload *payload);
8454d07b0bcSLyude Paul void drm_dp_remove_payload(struct drm_dp_mst_topology_mgr *mgr,
8464d07b0bcSLyude Paul 			   struct drm_dp_mst_topology_state *mst_state,
847e761cc20SImre Deak 			   const struct drm_dp_mst_atomic_payload *old_payload,
848e761cc20SImre Deak 			   struct drm_dp_mst_atomic_payload *new_payload);
849da68386dSThomas Zimmermann 
850da68386dSThomas Zimmermann int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
851da68386dSThomas Zimmermann 
852da68386dSThomas Zimmermann void drm_dp_mst_dump_topology(struct seq_file *m,
853da68386dSThomas Zimmermann 			      struct drm_dp_mst_topology_mgr *mgr);
854da68386dSThomas Zimmermann 
855da68386dSThomas Zimmermann void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
856da68386dSThomas Zimmermann int __must_check
857da68386dSThomas Zimmermann drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr,
858da68386dSThomas Zimmermann 			       bool sync);
859da68386dSThomas Zimmermann 
860da68386dSThomas Zimmermann ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
861da68386dSThomas Zimmermann 			     unsigned int offset, void *buffer, size_t size);
862da68386dSThomas Zimmermann ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
863da68386dSThomas Zimmermann 			      unsigned int offset, void *buffer, size_t size);
864da68386dSThomas Zimmermann 
865da68386dSThomas Zimmermann int drm_dp_mst_connector_late_register(struct drm_connector *connector,
866da68386dSThomas Zimmermann 				       struct drm_dp_mst_port *port);
867da68386dSThomas Zimmermann void drm_dp_mst_connector_early_unregister(struct drm_connector *connector,
868da68386dSThomas Zimmermann 					   struct drm_dp_mst_port *port);
869da68386dSThomas Zimmermann 
8704d07b0bcSLyude Paul struct drm_dp_mst_topology_state *
8714d07b0bcSLyude Paul drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
872da68386dSThomas Zimmermann 				  struct drm_dp_mst_topology_mgr *mgr);
8734d07b0bcSLyude Paul struct drm_dp_mst_topology_state *
8749ffdb67aSImre Deak drm_atomic_get_old_mst_topology_state(struct drm_atomic_state *state,
8759ffdb67aSImre Deak 				      struct drm_dp_mst_topology_mgr *mgr);
8769ffdb67aSImre Deak struct drm_dp_mst_topology_state *
8774d07b0bcSLyude Paul drm_atomic_get_new_mst_topology_state(struct drm_atomic_state *state,
8784d07b0bcSLyude Paul 				      struct drm_dp_mst_topology_mgr *mgr);
8794d07b0bcSLyude Paul struct drm_dp_mst_atomic_payload *
8804d07b0bcSLyude Paul drm_atomic_get_mst_payload_state(struct drm_dp_mst_topology_state *state,
8814d07b0bcSLyude Paul 				 struct drm_dp_mst_port *port);
882da68386dSThomas Zimmermann int __must_check
883df78f7f6SLyude Paul drm_dp_atomic_find_time_slots(struct drm_atomic_state *state,
884da68386dSThomas Zimmermann 			      struct drm_dp_mst_topology_mgr *mgr,
8854d07b0bcSLyude Paul 			      struct drm_dp_mst_port *port, int pbn);
886da68386dSThomas Zimmermann int drm_dp_mst_atomic_enable_dsc(struct drm_atomic_state *state,
887da68386dSThomas Zimmermann 				 struct drm_dp_mst_port *port,
8884d07b0bcSLyude Paul 				 int pbn, bool enable);
889da68386dSThomas Zimmermann int __must_check
890da68386dSThomas Zimmermann drm_dp_mst_add_affected_dsc_crtcs(struct drm_atomic_state *state,
891da68386dSThomas Zimmermann 				  struct drm_dp_mst_topology_mgr *mgr);
892da68386dSThomas Zimmermann int __must_check
893df78f7f6SLyude Paul drm_dp_atomic_release_time_slots(struct drm_atomic_state *state,
894da68386dSThomas Zimmermann 				 struct drm_dp_mst_topology_mgr *mgr,
895da68386dSThomas Zimmermann 				 struct drm_dp_mst_port *port);
896a5c2c0d1SLyude Paul void drm_dp_mst_atomic_wait_for_dependencies(struct drm_atomic_state *state);
897a5c2c0d1SLyude Paul int __must_check drm_dp_mst_atomic_setup_commit(struct drm_atomic_state *state);
898da68386dSThomas Zimmermann int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr,
899da68386dSThomas Zimmermann 				 struct drm_dp_mst_port *port, bool power_up);
900da68386dSThomas Zimmermann int drm_dp_send_query_stream_enc_status(struct drm_dp_mst_topology_mgr *mgr,
901da68386dSThomas Zimmermann 		struct drm_dp_mst_port *port,
902da68386dSThomas Zimmermann 		struct drm_dp_query_stream_enc_status_ack_reply *status);
903da68386dSThomas Zimmermann int __must_check drm_dp_mst_atomic_check(struct drm_atomic_state *state);
904a76eb429SLyude Paul int __must_check drm_dp_mst_root_conn_atomic_check(struct drm_connector_state *new_conn_state,
905a76eb429SLyude Paul 						   struct drm_dp_mst_topology_mgr *mgr);
906da68386dSThomas Zimmermann 
907da68386dSThomas Zimmermann void drm_dp_mst_get_port_malloc(struct drm_dp_mst_port *port);
908da68386dSThomas Zimmermann void drm_dp_mst_put_port_malloc(struct drm_dp_mst_port *port);
909da68386dSThomas Zimmermann 
910da68386dSThomas Zimmermann struct drm_dp_aux *drm_dp_mst_dsc_aux_for_port(struct drm_dp_mst_port *port);
911da68386dSThomas Zimmermann 
9124d07b0bcSLyude Paul static inline struct drm_dp_mst_topology_state *
to_drm_dp_mst_topology_state(struct drm_private_state * state)9134d07b0bcSLyude Paul to_drm_dp_mst_topology_state(struct drm_private_state *state)
9144d07b0bcSLyude Paul {
9154d07b0bcSLyude Paul 	return container_of(state, struct drm_dp_mst_topology_state, base);
9164d07b0bcSLyude Paul }
9174d07b0bcSLyude Paul 
918da68386dSThomas Zimmermann extern const struct drm_private_state_funcs drm_dp_mst_topology_state_funcs;
919da68386dSThomas Zimmermann 
920da68386dSThomas Zimmermann /**
921da68386dSThomas Zimmermann  * __drm_dp_mst_state_iter_get - private atomic state iterator function for
922da68386dSThomas Zimmermann  * macro-internal use
923da68386dSThomas Zimmermann  * @state: &struct drm_atomic_state pointer
924da68386dSThomas Zimmermann  * @mgr: pointer to the &struct drm_dp_mst_topology_mgr iteration cursor
925da68386dSThomas Zimmermann  * @old_state: optional pointer to the old &struct drm_dp_mst_topology_state
926da68386dSThomas Zimmermann  * iteration cursor
927da68386dSThomas Zimmermann  * @new_state: optional pointer to the new &struct drm_dp_mst_topology_state
928da68386dSThomas Zimmermann  * iteration cursor
929da68386dSThomas Zimmermann  * @i: int iteration cursor, for macro-internal use
930da68386dSThomas Zimmermann  *
931da68386dSThomas Zimmermann  * Used by for_each_oldnew_mst_mgr_in_state(),
932da68386dSThomas Zimmermann  * for_each_old_mst_mgr_in_state(), and for_each_new_mst_mgr_in_state(). Don't
933da68386dSThomas Zimmermann  * call this directly.
934da68386dSThomas Zimmermann  *
935da68386dSThomas Zimmermann  * Returns:
936da68386dSThomas Zimmermann  * True if the current &struct drm_private_obj is a &struct
937da68386dSThomas Zimmermann  * drm_dp_mst_topology_mgr, false otherwise.
938da68386dSThomas Zimmermann  */
939da68386dSThomas Zimmermann static inline bool
__drm_dp_mst_state_iter_get(struct drm_atomic_state * state,struct drm_dp_mst_topology_mgr ** mgr,struct drm_dp_mst_topology_state ** old_state,struct drm_dp_mst_topology_state ** new_state,int i)940da68386dSThomas Zimmermann __drm_dp_mst_state_iter_get(struct drm_atomic_state *state,
941da68386dSThomas Zimmermann 			    struct drm_dp_mst_topology_mgr **mgr,
942da68386dSThomas Zimmermann 			    struct drm_dp_mst_topology_state **old_state,
943da68386dSThomas Zimmermann 			    struct drm_dp_mst_topology_state **new_state,
944da68386dSThomas Zimmermann 			    int i)
945da68386dSThomas Zimmermann {
946da68386dSThomas Zimmermann 	struct __drm_private_objs_state *objs_state = &state->private_objs[i];
947da68386dSThomas Zimmermann 
948da68386dSThomas Zimmermann 	if (objs_state->ptr->funcs != &drm_dp_mst_topology_state_funcs)
949da68386dSThomas Zimmermann 		return false;
950da68386dSThomas Zimmermann 
951da68386dSThomas Zimmermann 	*mgr = to_dp_mst_topology_mgr(objs_state->ptr);
952da68386dSThomas Zimmermann 	if (old_state)
953da68386dSThomas Zimmermann 		*old_state = to_dp_mst_topology_state(objs_state->old_state);
954da68386dSThomas Zimmermann 	if (new_state)
955da68386dSThomas Zimmermann 		*new_state = to_dp_mst_topology_state(objs_state->new_state);
956da68386dSThomas Zimmermann 
957da68386dSThomas Zimmermann 	return true;
958da68386dSThomas Zimmermann }
959da68386dSThomas Zimmermann 
960da68386dSThomas Zimmermann /**
961da68386dSThomas Zimmermann  * for_each_oldnew_mst_mgr_in_state - iterate over all DP MST topology
962da68386dSThomas Zimmermann  * managers in an atomic update
963da68386dSThomas Zimmermann  * @__state: &struct drm_atomic_state pointer
964da68386dSThomas Zimmermann  * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
965da68386dSThomas Zimmermann  * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
966da68386dSThomas Zimmermann  * state
967da68386dSThomas Zimmermann  * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
968da68386dSThomas Zimmermann  * state
969da68386dSThomas Zimmermann  * @__i: int iteration cursor, for macro-internal use
970da68386dSThomas Zimmermann  *
971da68386dSThomas Zimmermann  * This iterates over all DRM DP MST topology managers in an atomic update,
972da68386dSThomas Zimmermann  * tracking both old and new state. This is useful in places where the state
973da68386dSThomas Zimmermann  * delta needs to be considered, for example in atomic check functions.
974da68386dSThomas Zimmermann  */
975da68386dSThomas Zimmermann #define for_each_oldnew_mst_mgr_in_state(__state, mgr, old_state, new_state, __i) \
976da68386dSThomas Zimmermann 	for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
977da68386dSThomas Zimmermann 		for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), &(new_state), (__i)))
978da68386dSThomas Zimmermann 
979da68386dSThomas Zimmermann /**
980da68386dSThomas Zimmermann  * for_each_old_mst_mgr_in_state - iterate over all DP MST topology managers
981da68386dSThomas Zimmermann  * in an atomic update
982da68386dSThomas Zimmermann  * @__state: &struct drm_atomic_state pointer
983da68386dSThomas Zimmermann  * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
984da68386dSThomas Zimmermann  * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
985da68386dSThomas Zimmermann  * state
986da68386dSThomas Zimmermann  * @__i: int iteration cursor, for macro-internal use
987da68386dSThomas Zimmermann  *
988da68386dSThomas Zimmermann  * This iterates over all DRM DP MST topology managers in an atomic update,
989da68386dSThomas Zimmermann  * tracking only the old state. This is useful in disable functions, where we
990da68386dSThomas Zimmermann  * need the old state the hardware is still in.
991da68386dSThomas Zimmermann  */
992da68386dSThomas Zimmermann #define for_each_old_mst_mgr_in_state(__state, mgr, old_state, __i) \
993da68386dSThomas Zimmermann 	for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
994da68386dSThomas Zimmermann 		for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), NULL, (__i)))
995da68386dSThomas Zimmermann 
996da68386dSThomas Zimmermann /**
997da68386dSThomas Zimmermann  * for_each_new_mst_mgr_in_state - iterate over all DP MST topology managers
998da68386dSThomas Zimmermann  * in an atomic update
999da68386dSThomas Zimmermann  * @__state: &struct drm_atomic_state pointer
1000da68386dSThomas Zimmermann  * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
1001da68386dSThomas Zimmermann  * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
1002da68386dSThomas Zimmermann  * state
1003da68386dSThomas Zimmermann  * @__i: int iteration cursor, for macro-internal use
1004da68386dSThomas Zimmermann  *
1005da68386dSThomas Zimmermann  * This iterates over all DRM DP MST topology managers in an atomic update,
1006da68386dSThomas Zimmermann  * tracking only the new state. This is useful in enable functions, where we
1007da68386dSThomas Zimmermann  * need the new state the hardware should be in when the atomic commit
1008da68386dSThomas Zimmermann  * operation has completed.
1009da68386dSThomas Zimmermann  */
1010da68386dSThomas Zimmermann #define for_each_new_mst_mgr_in_state(__state, mgr, new_state, __i) \
1011da68386dSThomas Zimmermann 	for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
1012da68386dSThomas Zimmermann 		for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), NULL, &(new_state), (__i)))
1013da68386dSThomas Zimmermann 
1014da68386dSThomas Zimmermann #endif
1015