blob: d5fc90b304876697740c7d994a78ea8692e9f85b [file] [log] [blame]
Dave Airliead7f8a12014-06-05 14:01:32 +10001/*
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>
Pandiyan, Dhinakaran3f3353b2017-04-20 22:51:31 -070027#include <drm/drm_atomic.h>
Dave Airliead7f8a12014-06-05 14:01:32 +100028
Lyude Paul12a280c2019-06-20 17:59:25 -040029#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
30#include <linux/stackdepot.h>
31#include <linux/timekeeping.h>
32
33enum drm_dp_mst_topology_ref_type {
34 DRM_DP_MST_TOPOLOGY_REF_GET,
35 DRM_DP_MST_TOPOLOGY_REF_PUT,
36};
37
38struct drm_dp_mst_topology_ref_history {
39 struct drm_dp_mst_topology_ref_entry {
40 enum drm_dp_mst_topology_ref_type type;
41 int count;
42 ktime_t ts_nsec;
43 depot_stack_handle_t backtrace;
44 } *entries;
45 int len;
46};
47#endif /* IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS) */
48
Dave Airliead7f8a12014-06-05 14:01:32 +100049struct drm_dp_mst_branch;
50
51/**
Masanari Iida32197aa2014-10-20 23:53:13 +090052 * struct drm_dp_vcpi - Virtual Channel Payload Identifier
Dave Airliead7f8a12014-06-05 14:01:32 +100053 * @vcpi: Virtual channel ID.
54 * @pbn: Payload Bandwidth Number for this channel
55 * @aligned_pbn: PBN aligned with slot size
56 * @num_slots: number of slots for this PBN
57 */
58struct drm_dp_vcpi {
59 int vcpi;
60 int pbn;
61 int aligned_pbn;
62 int num_slots;
63};
64
65/**
66 * struct drm_dp_mst_port - MST port
Dave Airliead7f8a12014-06-05 14:01:32 +100067 * @port_num: port number
Lyude Paul3f9b3f02019-06-17 17:59:29 -040068 * @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 * @available_pbn: Available bandwidth for this port. Protected by
85 * &drm_dp_mst_topology_mgr.base.lock.
Dave Airliead7f8a12014-06-05 14:01:32 +100086 * @next: link to next port on this branch device
Lyude Paulc485e2c2019-03-13 13:51:41 -040087 * @aux: i2c aux transport to talk to device connected to this port, protected
Lyude Paul3f9b3f02019-06-17 17:59:29 -040088 * by &drm_dp_mst_topology_mgr.base.lock.
Dave Airliead7f8a12014-06-05 14:01:32 +100089 * @parent: branch device parent of this port
90 * @vcpi: Virtual Channel Payload info for this port.
Lyude Paul3f9b3f02019-06-17 17:59:29 -040091 * @connector: DRM connector this port is connected to. Protected by
92 * &drm_dp_mst_topology_mgr.base.lock.
Dave Airliead7f8a12014-06-05 14:01:32 +100093 * @mgr: topology manager this port lives under.
94 *
95 * This structure represents an MST port endpoint on a device somewhere
96 * in the MST topology.
97 */
98struct drm_dp_mst_port {
Lyude Paulebcc0e62019-01-10 19:53:29 -050099 /**
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;
Dave Airliead7f8a12014-06-05 14:01:32 +1000111
Lyude Paul12a280c2019-06-20 17:59:25 -0400112#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
Dave Airliead7f8a12014-06-05 14:01:32 +1000120 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 available_pbn;
130 struct list_head next;
Lyude Paul14692a32019-10-16 16:02:59 -0400131 /**
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;
Dave Airliead7f8a12014-06-05 14:01:32 +1000142 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;
Dave Airliec6a0aed2014-10-20 16:28:02 +1000148
Daniel Vetter132d49d2016-07-15 21:48:04 +0200149 /**
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 */
Libin Yangef8f9be2015-12-02 14:09:43 +0800158 bool has_audio;
Dave Airliead7f8a12014-06-05 14:01:32 +1000159};
160
161/**
162 * struct drm_dp_mst_branch - MST branch device.
Dave Airliead7f8a12014-06-05 14:01:32 +1000163 * @rad: Relative Address to talk to this branch device.
164 * @lct: Link count total to talk to this branch device.
165 * @num_ports: number of ports on the branch.
166 * @msg_slots: one bit per transmitted msg slot.
Dave Airliead7f8a12014-06-05 14:01:32 +1000167 * @port_parent: pointer to the port parent, NULL if toplevel.
168 * @mgr: topology manager for this branch device.
169 * @tx_slots: transmission slots for this device.
170 * @last_seqno: last sequence number used to talk to this.
171 * @link_address_sent: if a link address message has been sent to this device yet.
Hersen Wu5e93b822016-01-22 17:07:28 -0500172 * @guid: guid for DP 1.2 branch device. port under this branch can be
173 * identified by port #.
Dave Airliead7f8a12014-06-05 14:01:32 +1000174 *
175 * This structure represents an MST branch device, there is one
Hersen Wu5e93b822016-01-22 17:07:28 -0500176 * primary branch device at the root, along with any other branches connected
177 * to downstream port of parent branches.
Dave Airliead7f8a12014-06-05 14:01:32 +1000178 */
179struct drm_dp_mst_branch {
Lyude Paulebcc0e62019-01-10 19:53:29 -0500180 /**
181 * @topology_kref: refcount for this branch device's lifetime in the
182 * topology, only the DP MST helpers should need to touch this
183 */
184 struct kref topology_kref;
185
186 /**
187 * @malloc_kref: refcount for the memory allocation containing this
188 * structure. See drm_dp_mst_get_mstb_malloc() and
189 * drm_dp_mst_put_mstb_malloc().
190 */
191 struct kref malloc_kref;
192
Lyude Paul12a280c2019-06-20 17:59:25 -0400193#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
194 /**
195 * @topology_ref_history: A history of each topology
196 * reference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.
197 */
198 struct drm_dp_mst_topology_ref_history topology_ref_history;
199#endif
200
Lyude Paul7cb12d42019-02-19 17:41:02 -0500201 /**
202 * @destroy_next: linked-list entry used by
203 * drm_dp_delayed_destroy_work()
204 */
205 struct list_head destroy_next;
206
Dave Airliead7f8a12014-06-05 14:01:32 +1000207 u8 rad[8];
208 u8 lct;
209 int num_ports;
210
211 int msg_slots;
Lyude Paul14692a32019-10-16 16:02:59 -0400212 /**
213 * @ports: the list of ports on this branch device. This should be
214 * considered protected for reading by &drm_dp_mst_topology_mgr.lock.
215 * There are two exceptions to this:
216 * &drm_dp_mst_topology_mgr.up_req_work and
217 * &drm_dp_mst_topology_mgr.work, which do not grab
218 * &drm_dp_mst_topology_mgr.lock during reads but are the only
219 * updaters of this list and are protected from updating the list
220 * concurrently by @drm_dp_mst_topology_mgr.probe_lock
221 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000222 struct list_head ports;
223
224 /* list of tx ops queue for this port */
225 struct drm_dp_mst_port *port_parent;
226 struct drm_dp_mst_topology_mgr *mgr;
227
228 /* slots are protected by mstb->mgr->qlock */
229 struct drm_dp_sideband_msg_tx *tx_slots[2];
230 int last_seqno;
231 bool link_address_sent;
Hersen Wu5e93b822016-01-22 17:07:28 -0500232
233 /* global unique identifier to identify branch devices */
234 u8 guid[16];
Dave Airliead7f8a12014-06-05 14:01:32 +1000235};
236
237
238/* sideband msg header - not bit struct */
239struct drm_dp_sideband_msg_hdr {
240 u8 lct;
241 u8 lcr;
242 u8 rad[8];
243 bool broadcast;
244 bool path_msg;
245 u8 msg_len;
246 bool somt;
247 bool eomt;
248 bool seqno;
249};
250
251struct drm_dp_nak_reply {
252 u8 guid[16];
253 u8 reason;
254 u8 nak_data;
255};
256
257struct drm_dp_link_address_ack_reply {
258 u8 guid[16];
259 u8 nports;
260 struct drm_dp_link_addr_reply_port {
261 bool input_port;
262 u8 peer_device_type;
263 u8 port_number;
264 bool mcs;
265 bool ddps;
266 bool legacy_device_plug_status;
267 u8 dpcd_revision;
268 u8 peer_guid[16];
269 u8 num_sdp_streams;
270 u8 num_sdp_stream_sinks;
271 } ports[16];
272};
273
274struct drm_dp_remote_dpcd_read_ack_reply {
275 u8 port_number;
276 u8 num_bytes;
277 u8 bytes[255];
278};
279
280struct drm_dp_remote_dpcd_write_ack_reply {
281 u8 port_number;
282};
283
284struct drm_dp_remote_dpcd_write_nak_reply {
285 u8 port_number;
286 u8 reason;
287 u8 bytes_written_before_failure;
288};
289
290struct drm_dp_remote_i2c_read_ack_reply {
291 u8 port_number;
292 u8 num_bytes;
293 u8 bytes[255];
294};
295
296struct drm_dp_remote_i2c_read_nak_reply {
297 u8 port_number;
298 u8 nak_reason;
299 u8 i2c_nak_transaction;
300};
301
302struct drm_dp_remote_i2c_write_ack_reply {
303 u8 port_number;
304};
305
306
307struct drm_dp_sideband_msg_rx {
308 u8 chunk[48];
309 u8 msg[256];
310 u8 curchunk_len;
311 u8 curchunk_idx; /* chunk we are parsing now */
312 u8 curchunk_hdrlen;
313 u8 curlen; /* total length of the msg */
314 bool have_somt;
315 bool have_eomt;
316 struct drm_dp_sideband_msg_hdr initial_hdr;
317};
318
Libin Yangef8f9be2015-12-02 14:09:43 +0800319#define DRM_DP_MAX_SDP_STREAMS 16
Dave Airliead7f8a12014-06-05 14:01:32 +1000320struct drm_dp_allocate_payload {
321 u8 port_number;
322 u8 number_sdp_streams;
323 u8 vcpi;
324 u16 pbn;
Libin Yangef8f9be2015-12-02 14:09:43 +0800325 u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
Dave Airliead7f8a12014-06-05 14:01:32 +1000326};
327
328struct drm_dp_allocate_payload_ack_reply {
329 u8 port_number;
330 u8 vcpi;
331 u16 allocated_pbn;
332};
333
334struct drm_dp_connection_status_notify {
335 u8 guid[16];
336 u8 port_number;
337 bool legacy_device_plug_status;
338 bool displayport_device_plug_status;
339 bool message_capability_status;
340 bool input_port;
341 u8 peer_device_type;
342};
343
344struct drm_dp_remote_dpcd_read {
345 u8 port_number;
346 u32 dpcd_address;
347 u8 num_bytes;
348};
349
350struct drm_dp_remote_dpcd_write {
351 u8 port_number;
352 u32 dpcd_address;
353 u8 num_bytes;
354 u8 *bytes;
355};
356
Dave Airlieae491542015-10-14 18:51:17 +1000357#define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
Dave Airliead7f8a12014-06-05 14:01:32 +1000358struct drm_dp_remote_i2c_read {
359 u8 num_transactions;
360 u8 port_number;
Lyude Paul2f015ec2019-09-03 16:45:45 -0400361 struct drm_dp_remote_i2c_read_tx {
Dave Airliead7f8a12014-06-05 14:01:32 +1000362 u8 i2c_dev_id;
363 u8 num_bytes;
364 u8 *bytes;
365 u8 no_stop_bit;
366 u8 i2c_transaction_delay;
Dave Airlieae491542015-10-14 18:51:17 +1000367 } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
Dave Airliead7f8a12014-06-05 14:01:32 +1000368 u8 read_i2c_device_id;
369 u8 num_bytes_read;
370};
371
372struct drm_dp_remote_i2c_write {
373 u8 port_number;
374 u8 write_i2c_device_id;
375 u8 num_bytes;
376 u8 *bytes;
377};
378
379/* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
380struct drm_dp_port_number_req {
381 u8 port_number;
382};
383
384struct drm_dp_enum_path_resources_ack_reply {
385 u8 port_number;
386 u16 full_payload_bw_number;
387 u16 avail_payload_bw_number;
388};
389
390/* covers POWER_DOWN_PHY, POWER_UP_PHY */
391struct drm_dp_port_number_rep {
392 u8 port_number;
393};
394
395struct drm_dp_query_payload {
396 u8 port_number;
397 u8 vcpi;
398};
399
400struct drm_dp_resource_status_notify {
401 u8 port_number;
402 u8 guid[16];
403 u16 available_pbn;
404};
405
406struct drm_dp_query_payload_ack_reply {
407 u8 port_number;
Sean Paul268de652019-08-29 12:52:19 -0400408 u16 allocated_pbn;
Dave Airliead7f8a12014-06-05 14:01:32 +1000409};
410
411struct drm_dp_sideband_msg_req_body {
412 u8 req_type;
413 union ack_req {
414 struct drm_dp_connection_status_notify conn_stat;
415 struct drm_dp_port_number_req port_num;
416 struct drm_dp_resource_status_notify resource_stat;
417
418 struct drm_dp_query_payload query_payload;
419 struct drm_dp_allocate_payload allocate_payload;
420
421 struct drm_dp_remote_dpcd_read dpcd_read;
422 struct drm_dp_remote_dpcd_write dpcd_write;
423
424 struct drm_dp_remote_i2c_read i2c_read;
425 struct drm_dp_remote_i2c_write i2c_write;
426 } u;
427};
428
429struct drm_dp_sideband_msg_reply_body {
430 u8 reply_type;
431 u8 req_type;
432 union ack_replies {
433 struct drm_dp_nak_reply nak;
434 struct drm_dp_link_address_ack_reply link_addr;
435 struct drm_dp_port_number_rep port_number;
436
437 struct drm_dp_enum_path_resources_ack_reply path_resources;
438 struct drm_dp_allocate_payload_ack_reply allocate_payload;
439 struct drm_dp_query_payload_ack_reply query_payload;
440
441 struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
442 struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
443 struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
444
445 struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
446 struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
447 struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
448 } u;
449};
450
451/* msg is queued to be put into a slot */
452#define DRM_DP_SIDEBAND_TX_QUEUED 0
453/* msg has started transmitting on a slot - still on msgq */
454#define DRM_DP_SIDEBAND_TX_START_SEND 1
455/* msg has finished transmitting on a slot - removed from msgq only in slot */
456#define DRM_DP_SIDEBAND_TX_SENT 2
457/* msg has received a response - removed from slot */
458#define DRM_DP_SIDEBAND_TX_RX 3
459#define DRM_DP_SIDEBAND_TX_TIMEOUT 4
460
461struct drm_dp_sideband_msg_tx {
462 u8 msg[256];
463 u8 chunk[48];
464 u8 cur_offset;
465 u8 cur_len;
466 struct drm_dp_mst_branch *dst;
467 struct list_head next;
468 int seqno;
469 int state;
470 bool path_msg;
471 struct drm_dp_sideband_msg_reply_body reply;
472};
473
474/* sideband msg handler */
475struct drm_dp_mst_topology_mgr;
476struct drm_dp_mst_topology_cbs {
477 /* create a connector for a port */
Thierry Reding12e6cec2014-05-13 11:38:36 +0200478 struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
Dave Airlied9515c52015-09-16 17:55:23 +1000479 void (*register_connector)(struct drm_connector *connector);
Dave Airliead7f8a12014-06-05 14:01:32 +1000480 void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
481 struct drm_connector *connector);
Dave Airliead7f8a12014-06-05 14:01:32 +1000482};
483
484#define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
485
486#define DP_PAYLOAD_LOCAL 1
487#define DP_PAYLOAD_REMOTE 2
488#define DP_PAYLOAD_DELETE_LOCAL 3
489
490struct drm_dp_payload {
491 int payload_state;
492 int start_slot;
493 int num_slots;
Dave Airliedfda0df2014-08-06 16:26:21 +1000494 int vcpi;
Dave Airliead7f8a12014-06-05 14:01:32 +1000495};
496
Ville Syrjäläa4370c72017-07-12 18:51:02 +0300497#define to_dp_mst_topology_state(x) container_of(x, struct drm_dp_mst_topology_state, base)
498
Lyude Pauleceae142019-01-10 19:53:41 -0500499struct drm_dp_vcpi_allocation {
500 struct drm_dp_mst_port *port;
501 int vcpi;
502 struct list_head next;
503};
504
Pandiyan, Dhinakaran3f3353b2017-04-20 22:51:31 -0700505struct drm_dp_mst_topology_state {
Ville Syrjäläa4370c72017-07-12 18:51:02 +0300506 struct drm_private_state base;
Lyude Pauleceae142019-01-10 19:53:41 -0500507 struct list_head vcpis;
Pandiyan, Dhinakaran3f3353b2017-04-20 22:51:31 -0700508 struct drm_dp_mst_topology_mgr *mgr;
509};
510
Ville Syrjäläa4370c72017-07-12 18:51:02 +0300511#define to_dp_mst_topology_mgr(x) container_of(x, struct drm_dp_mst_topology_mgr, base)
512
Dave Airliead7f8a12014-06-05 14:01:32 +1000513/**
514 * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
Dave Airliead7f8a12014-06-05 14:01:32 +1000515 *
516 * This struct represents the toplevel displayport MST topology manager.
517 * There should be one instance of this for every MST capable DP connector
518 * on the GPU.
519 */
520struct drm_dp_mst_topology_mgr {
Daniel Vetter132d49d2016-07-15 21:48:04 +0200521 /**
Ville Syrjäläa4370c72017-07-12 18:51:02 +0300522 * @base: Base private object for atomic
523 */
524 struct drm_private_obj base;
525
526 /**
Daniel Vetter132d49d2016-07-15 21:48:04 +0200527 * @dev: device pointer for adding i2c devices etc.
528 */
Dhinakaran Pandiyan7b0a89a2017-01-24 15:49:29 -0800529 struct drm_device *dev;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200530 /**
531 * @cbs: callbacks for connector addition and destruction.
532 */
Julia Lawall69a0f892015-12-30 22:20:30 +0100533 const struct drm_dp_mst_topology_cbs *cbs;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200534 /**
535 * @max_dpcd_transaction_bytes: maximum number of bytes to read/write
536 * in one go.
537 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000538 int max_dpcd_transaction_bytes;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200539 /**
540 * @aux: AUX channel for the DP MST connector this topolgy mgr is
541 * controlling.
542 */
543 struct drm_dp_aux *aux;
544 /**
545 * @max_payloads: maximum number of payloads the GPU can generate.
546 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000547 int max_payloads;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200548 /**
549 * @conn_base_id: DRM connector ID this mgr is connected to. Only used
550 * to build the MST connector path value.
551 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000552 int conn_base_id;
553
Daniel Vetter132d49d2016-07-15 21:48:04 +0200554 /**
Lyude Paul85783362019-09-03 16:45:56 -0400555 * @down_rep_recv: Message receiver state for down replies.
Daniel Vetter132d49d2016-07-15 21:48:04 +0200556 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000557 struct drm_dp_sideband_msg_rx down_rep_recv;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200558 /**
Lyude Paul85783362019-09-03 16:45:56 -0400559 * @up_req_recv: Message receiver state for up requests.
Daniel Vetter132d49d2016-07-15 21:48:04 +0200560 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000561 struct drm_dp_sideband_msg_rx up_req_recv;
562
Daniel Vetter132d49d2016-07-15 21:48:04 +0200563 /**
564 * @lock: protects mst state, primary, dpcd.
565 */
566 struct mutex lock;
Dave Airliead7f8a12014-06-05 14:01:32 +1000567
Daniel Vetter132d49d2016-07-15 21:48:04 +0200568 /**
Lyude Paul14692a32019-10-16 16:02:59 -0400569 * @probe_lock: Prevents @work and @up_req_work, the only writers of
570 * &drm_dp_mst_port.mstb and &drm_dp_mst_branch.ports, from racing
571 * while they update the topology.
572 */
573 struct mutex probe_lock;
574
575 /**
Daniel Vetter132d49d2016-07-15 21:48:04 +0200576 * @mst_state: If this manager is enabled for an MST capable port. False
577 * if no MST sink/branch devices is connected.
578 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000579 bool mst_state;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200580 /**
581 * @mst_primary: Pointer to the primary/first branch device.
582 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000583 struct drm_dp_mst_branch *mst_primary;
Hersen Wu5e93b822016-01-22 17:07:28 -0500584
Daniel Vetter132d49d2016-07-15 21:48:04 +0200585 /**
586 * @dpcd: Cache of DPCD for primary port.
587 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000588 u8 dpcd[DP_RECEIVER_CAP_SIZE];
Daniel Vetter132d49d2016-07-15 21:48:04 +0200589 /**
590 * @sink_count: Sink count from DEVICE_SERVICE_IRQ_VECTOR_ESI0.
591 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000592 u8 sink_count;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200593 /**
594 * @pbn_div: PBN to slots divisor.
595 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000596 int pbn_div;
Pandiyan, Dhinakarana538d612017-03-16 00:10:24 -0700597
Daniel Vetter132d49d2016-07-15 21:48:04 +0200598 /**
Pandiyan, Dhinakaran3f3353b2017-04-20 22:51:31 -0700599 * @funcs: Atomic helper callbacks
600 */
601 const struct drm_private_state_funcs *funcs;
602
603 /**
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100604 * @qlock: protects @tx_msg_downq, the &drm_dp_mst_branch.txslost and
605 * &drm_dp_sideband_msg_tx.state once they are queued
Daniel Vetter132d49d2016-07-15 21:48:04 +0200606 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000607 struct mutex qlock;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200608 /**
609 * @tx_msg_downq: List of pending down replies.
610 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000611 struct list_head tx_msg_downq;
Dave Airliead7f8a12014-06-05 14:01:32 +1000612
Daniel Vetter132d49d2016-07-15 21:48:04 +0200613 /**
614 * @payload_lock: Protect payload information.
615 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000616 struct mutex payload_lock;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200617 /**
618 * @proposed_vcpis: Array of pointers for the new VCPI allocation. The
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100619 * VCPI structure itself is &drm_dp_mst_port.vcpi.
Daniel Vetter132d49d2016-07-15 21:48:04 +0200620 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000621 struct drm_dp_vcpi **proposed_vcpis;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200622 /**
623 * @payloads: Array of payloads.
624 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000625 struct drm_dp_payload *payloads;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200626 /**
627 * @payload_mask: Elements of @payloads actually in use. Since
628 * reallocation of active outputs isn't possible gaps can be created by
629 * disabling outputs out of order compared to how they've been enabled.
630 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000631 unsigned long payload_mask;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200632 /**
633 * @vcpi_mask: Similar to @payload_mask, but for @proposed_vcpis.
634 */
Dave Airliedfda0df2014-08-06 16:26:21 +1000635 unsigned long vcpi_mask;
Dave Airliead7f8a12014-06-05 14:01:32 +1000636
Daniel Vetter132d49d2016-07-15 21:48:04 +0200637 /**
638 * @tx_waitq: Wait to queue stall for the tx worker.
639 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000640 wait_queue_head_t tx_waitq;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200641 /**
642 * @work: Probe work.
643 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000644 struct work_struct work;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200645 /**
646 * @tx_work: Sideband transmit worker. This can nest within the main
647 * @work worker for each transaction @work launches.
648 */
Dave Airliead7f8a12014-06-05 14:01:32 +1000649 struct work_struct tx_work;
Dave Airlie6b8eeca2015-06-15 10:34:28 +1000650
Daniel Vetter132d49d2016-07-15 21:48:04 +0200651 /**
Lyude Paul7cb12d42019-02-19 17:41:02 -0500652 * @destroy_port_list: List of to be destroyed connectors.
Daniel Vetter132d49d2016-07-15 21:48:04 +0200653 */
Lyude Paul7cb12d42019-02-19 17:41:02 -0500654 struct list_head destroy_port_list;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200655 /**
Lyude Paul7cb12d42019-02-19 17:41:02 -0500656 * @destroy_branch_device_list: List of to be destroyed branch
657 * devices.
Daniel Vetter132d49d2016-07-15 21:48:04 +0200658 */
Lyude Paul7cb12d42019-02-19 17:41:02 -0500659 struct list_head destroy_branch_device_list;
Daniel Vetter132d49d2016-07-15 21:48:04 +0200660 /**
Lyude Paul7cb12d42019-02-19 17:41:02 -0500661 * @delayed_destroy_lock: Protects @destroy_port_list and
662 * @destroy_branch_device_list.
Daniel Vetter132d49d2016-07-15 21:48:04 +0200663 */
Lyude Paul7cb12d42019-02-19 17:41:02 -0500664 struct mutex delayed_destroy_lock;
665 /**
666 * @delayed_destroy_work: Work item to destroy MST port and branch
667 * devices, needed to avoid locking inversion.
668 */
669 struct work_struct delayed_destroy_work;
Lyude Paul9408cc92019-06-17 16:37:18 -0400670
671 /**
672 * @up_req_list: List of pending up requests from the topology that
673 * need to be processed, in chronological order.
674 */
675 struct list_head up_req_list;
676 /**
677 * @up_req_lock: Protects @up_req_list
678 */
679 struct mutex up_req_lock;
680 /**
681 * @up_req_work: Work item to process up requests received from the
682 * topology. Needed to avoid blocking hotplug handling and sideband
683 * transmissions.
684 */
685 struct work_struct up_req_work;
Lyude Paul12a280c2019-06-20 17:59:25 -0400686
687#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
688 /**
689 * @topology_ref_history_lock: protects
690 * &drm_dp_mst_port.topology_ref_history and
691 * &drm_dp_mst_branch.topology_ref_history.
692 */
693 struct mutex topology_ref_history_lock;
694#endif
Dave Airliead7f8a12014-06-05 14:01:32 +1000695};
696
Dhinakaran Pandiyan7b0a89a2017-01-24 15:49:29 -0800697int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,
698 struct drm_device *dev, struct drm_dp_aux *aux,
699 int max_dpcd_transaction_bytes,
700 int max_payloads, int conn_base_id);
Dave Airliead7f8a12014-06-05 14:01:32 +1000701
702void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
703
704
705int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
706
707
708int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
709
710
Lyude Paul3f9b3f02019-06-17 17:59:29 -0400711int
712drm_dp_mst_detect_port(struct drm_connector *connector,
713 struct drm_modeset_acquire_ctx *ctx,
714 struct drm_dp_mst_topology_mgr *mgr,
715 struct drm_dp_mst_port *port);
Dave Airliead7f8a12014-06-05 14:01:32 +1000716
Libin Yangef8f9be2015-12-02 14:09:43 +0800717bool drm_dp_mst_port_has_audio(struct drm_dp_mst_topology_mgr *mgr,
718 struct drm_dp_mst_port *port);
Dave Airliead7f8a12014-06-05 14:01:32 +1000719struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
720
721
722int drm_dp_calc_pbn_mode(int clock, int bpp);
723
724
Pandiyan, Dhinakaran1e797f52017-03-16 00:10:26 -0700725bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
726 struct drm_dp_mst_port *port, int pbn, int slots);
Dave Airliead7f8a12014-06-05 14:01:32 +1000727
Dave Airlie87f59422015-02-24 09:23:55 +1000728int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
729
Dave Airliead7f8a12014-06-05 14:01:32 +1000730
731void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
732
733
734void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
735 struct drm_dp_mst_port *port);
736
737
738int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
739 int pbn);
740
741
742int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
743
744
745int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
746
747int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
748
749void drm_dp_mst_dump_topology(struct seq_file *m,
750 struct drm_dp_mst_topology_mgr *mgr);
751
752void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
Lyude Paulc2353162019-01-08 16:11:29 -0500753int __must_check
Lyude Paul6f85f732019-06-17 19:57:33 -0400754drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr,
755 bool sync);
Ville Syrjälä562836a22019-07-23 19:28:01 -0400756
757ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
758 unsigned int offset, void *buffer, size_t size);
759ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
760 unsigned int offset, void *buffer, size_t size);
761
762int drm_dp_mst_connector_late_register(struct drm_connector *connector,
763 struct drm_dp_mst_port *port);
764void drm_dp_mst_connector_early_unregister(struct drm_connector *connector,
765 struct drm_dp_mst_port *port);
766
Pandiyan, Dhinakaran3f3353b2017-04-20 22:51:31 -0700767struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
768 struct drm_dp_mst_topology_mgr *mgr);
Lyude Pauleceae142019-01-10 19:53:41 -0500769int __must_check
770drm_dp_atomic_find_vcpi_slots(struct drm_atomic_state *state,
771 struct drm_dp_mst_topology_mgr *mgr,
772 struct drm_dp_mst_port *port, int pbn);
773int __must_check
774drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state,
775 struct drm_dp_mst_topology_mgr *mgr,
776 struct drm_dp_mst_port *port);
Dhinakaran Pandiyan0bb9c2b2017-09-06 17:14:58 -0700777int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr,
778 struct drm_dp_mst_port *port, bool power_up);
Lyude Pauleceae142019-01-10 19:53:41 -0500779int __must_check drm_dp_mst_atomic_check(struct drm_atomic_state *state);
Pandiyan, Dhinakaran3f3353b2017-04-20 22:51:31 -0700780
Lyude Paulebcc0e62019-01-10 19:53:29 -0500781void drm_dp_mst_get_port_malloc(struct drm_dp_mst_port *port);
782void drm_dp_mst_put_port_malloc(struct drm_dp_mst_port *port);
783
Lyude Paulbea5c382019-01-10 19:53:40 -0500784extern const struct drm_private_state_funcs drm_dp_mst_topology_state_funcs;
785
786/**
787 * __drm_dp_mst_state_iter_get - private atomic state iterator function for
788 * macro-internal use
789 * @state: &struct drm_atomic_state pointer
790 * @mgr: pointer to the &struct drm_dp_mst_topology_mgr iteration cursor
791 * @old_state: optional pointer to the old &struct drm_dp_mst_topology_state
792 * iteration cursor
793 * @new_state: optional pointer to the new &struct drm_dp_mst_topology_state
794 * iteration cursor
795 * @i: int iteration cursor, for macro-internal use
796 *
797 * Used by for_each_oldnew_mst_mgr_in_state(),
798 * for_each_old_mst_mgr_in_state(), and for_each_new_mst_mgr_in_state(). Don't
799 * call this directly.
800 *
801 * Returns:
802 * True if the current &struct drm_private_obj is a &struct
803 * drm_dp_mst_topology_mgr, false otherwise.
804 */
805static inline bool
806__drm_dp_mst_state_iter_get(struct drm_atomic_state *state,
807 struct drm_dp_mst_topology_mgr **mgr,
808 struct drm_dp_mst_topology_state **old_state,
809 struct drm_dp_mst_topology_state **new_state,
810 int i)
811{
812 struct __drm_private_objs_state *objs_state = &state->private_objs[i];
813
814 if (objs_state->ptr->funcs != &drm_dp_mst_topology_state_funcs)
815 return false;
816
817 *mgr = to_dp_mst_topology_mgr(objs_state->ptr);
818 if (old_state)
819 *old_state = to_dp_mst_topology_state(objs_state->old_state);
820 if (new_state)
821 *new_state = to_dp_mst_topology_state(objs_state->new_state);
822
823 return true;
824}
825
826/**
827 * for_each_oldnew_mst_mgr_in_state - iterate over all DP MST topology
828 * managers in an atomic update
829 * @__state: &struct drm_atomic_state pointer
830 * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
831 * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
832 * state
833 * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
834 * state
835 * @__i: int iteration cursor, for macro-internal use
836 *
837 * This iterates over all DRM DP MST topology managers in an atomic update,
838 * tracking both old and new state. This is useful in places where the state
839 * delta needs to be considered, for example in atomic check functions.
840 */
841#define for_each_oldnew_mst_mgr_in_state(__state, mgr, old_state, new_state, __i) \
842 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
843 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), &(new_state), (__i)))
844
845/**
846 * for_each_old_mst_mgr_in_state - iterate over all DP MST topology managers
847 * in an atomic update
848 * @__state: &struct drm_atomic_state pointer
849 * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
850 * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
851 * state
852 * @__i: int iteration cursor, for macro-internal use
853 *
854 * This iterates over all DRM DP MST topology managers in an atomic update,
855 * tracking only the old state. This is useful in disable functions, where we
856 * need the old state the hardware is still in.
857 */
858#define for_each_old_mst_mgr_in_state(__state, mgr, old_state, __i) \
859 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
860 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), NULL, (__i)))
861
862/**
863 * for_each_new_mst_mgr_in_state - iterate over all DP MST topology managers
864 * in an atomic update
865 * @__state: &struct drm_atomic_state pointer
866 * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
867 * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
868 * state
869 * @__i: int iteration cursor, for macro-internal use
870 *
871 * This iterates over all DRM DP MST topology managers in an atomic update,
872 * tracking only the new state. This is useful in enable functions, where we
873 * need the new state the hardware should be in when the atomic commit
874 * operation has completed.
875 */
876#define for_each_new_mst_mgr_in_state(__state, mgr, new_state, __i) \
877 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
878 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), NULL, &(new_state), (__i)))
879
Dave Airliead7f8a12014-06-05 14:01:32 +1000880#endif