1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef _DRM_DP_MST_HELPER_H_
23#define _DRM_DP_MST_HELPER_H_
24
25#include <linux/types.h>
26#include <drm/drm_dp_helper.h>
27#include <drm/drm_atomic.h>
28
29struct drm_dp_mst_branch;
30
31
32
33
34
35
36
37
38struct drm_dp_vcpi {
39 int vcpi;
40 int pbn;
41 int aligned_pbn;
42 int num_slots;
43};
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69struct drm_dp_mst_port {
70 struct kref kref;
71
72 u8 port_num;
73 bool input;
74 bool mcs;
75 bool ddps;
76 u8 pdt;
77 bool ldps;
78 u8 dpcd_rev;
79 u8 num_sdp_streams;
80 u8 num_sdp_stream_sinks;
81 uint16_t available_pbn;
82 struct list_head next;
83 struct drm_dp_mst_branch *mstb;
84 struct drm_dp_aux aux;
85 struct drm_dp_mst_branch *parent;
86
87 struct drm_dp_vcpi vcpi;
88 struct drm_connector *connector;
89 struct drm_dp_mst_topology_mgr *mgr;
90
91
92
93
94
95 struct edid *cached_edid;
96
97
98
99
100 bool has_audio;
101};
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123struct drm_dp_mst_branch {
124 struct kref kref;
125 u8 rad[8];
126 u8 lct;
127 int num_ports;
128
129 int msg_slots;
130 struct list_head ports;
131
132
133 struct drm_dp_mst_port *port_parent;
134 struct drm_dp_mst_topology_mgr *mgr;
135
136
137 struct drm_dp_sideband_msg_tx *tx_slots[2];
138 int last_seqno;
139 bool link_address_sent;
140
141
142 u8 guid[16];
143};
144
145
146
147struct drm_dp_sideband_msg_hdr {
148 u8 lct;
149 u8 lcr;
150 u8 rad[8];
151 bool broadcast;
152 bool path_msg;
153 u8 msg_len;
154 bool somt;
155 bool eomt;
156 bool seqno;
157};
158
159struct drm_dp_nak_reply {
160 u8 guid[16];
161 u8 reason;
162 u8 nak_data;
163};
164
165struct drm_dp_link_address_ack_reply {
166 u8 guid[16];
167 u8 nports;
168 struct drm_dp_link_addr_reply_port {
169 bool input_port;
170 u8 peer_device_type;
171 u8 port_number;
172 bool mcs;
173 bool ddps;
174 bool legacy_device_plug_status;
175 u8 dpcd_revision;
176 u8 peer_guid[16];
177 u8 num_sdp_streams;
178 u8 num_sdp_stream_sinks;
179 } ports[16];
180};
181
182struct drm_dp_remote_dpcd_read_ack_reply {
183 u8 port_number;
184 u8 num_bytes;
185 u8 bytes[255];
186};
187
188struct drm_dp_remote_dpcd_write_ack_reply {
189 u8 port_number;
190};
191
192struct drm_dp_remote_dpcd_write_nak_reply {
193 u8 port_number;
194 u8 reason;
195 u8 bytes_written_before_failure;
196};
197
198struct drm_dp_remote_i2c_read_ack_reply {
199 u8 port_number;
200 u8 num_bytes;
201 u8 bytes[255];
202};
203
204struct drm_dp_remote_i2c_read_nak_reply {
205 u8 port_number;
206 u8 nak_reason;
207 u8 i2c_nak_transaction;
208};
209
210struct drm_dp_remote_i2c_write_ack_reply {
211 u8 port_number;
212};
213
214
215struct drm_dp_sideband_msg_rx {
216 u8 chunk[48];
217 u8 msg[256];
218 u8 curchunk_len;
219 u8 curchunk_idx;
220 u8 curchunk_hdrlen;
221 u8 curlen;
222 bool have_somt;
223 bool have_eomt;
224 struct drm_dp_sideband_msg_hdr initial_hdr;
225};
226
227#define DRM_DP_MAX_SDP_STREAMS 16
228struct drm_dp_allocate_payload {
229 u8 port_number;
230 u8 number_sdp_streams;
231 u8 vcpi;
232 u16 pbn;
233 u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
234};
235
236struct drm_dp_allocate_payload_ack_reply {
237 u8 port_number;
238 u8 vcpi;
239 u16 allocated_pbn;
240};
241
242struct drm_dp_connection_status_notify {
243 u8 guid[16];
244 u8 port_number;
245 bool legacy_device_plug_status;
246 bool displayport_device_plug_status;
247 bool message_capability_status;
248 bool input_port;
249 u8 peer_device_type;
250};
251
252struct drm_dp_remote_dpcd_read {
253 u8 port_number;
254 u32 dpcd_address;
255 u8 num_bytes;
256};
257
258struct drm_dp_remote_dpcd_write {
259 u8 port_number;
260 u32 dpcd_address;
261 u8 num_bytes;
262 u8 *bytes;
263};
264
265#define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
266struct drm_dp_remote_i2c_read {
267 u8 num_transactions;
268 u8 port_number;
269 struct {
270 u8 i2c_dev_id;
271 u8 num_bytes;
272 u8 *bytes;
273 u8 no_stop_bit;
274 u8 i2c_transaction_delay;
275 } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
276 u8 read_i2c_device_id;
277 u8 num_bytes_read;
278};
279
280struct drm_dp_remote_i2c_write {
281 u8 port_number;
282 u8 write_i2c_device_id;
283 u8 num_bytes;
284 u8 *bytes;
285};
286
287
288struct drm_dp_port_number_req {
289 u8 port_number;
290};
291
292struct drm_dp_enum_path_resources_ack_reply {
293 u8 port_number;
294 u16 full_payload_bw_number;
295 u16 avail_payload_bw_number;
296};
297
298
299struct drm_dp_port_number_rep {
300 u8 port_number;
301};
302
303struct drm_dp_query_payload {
304 u8 port_number;
305 u8 vcpi;
306};
307
308struct drm_dp_resource_status_notify {
309 u8 port_number;
310 u8 guid[16];
311 u16 available_pbn;
312};
313
314struct drm_dp_query_payload_ack_reply {
315 u8 port_number;
316 u8 allocated_pbn;
317};
318
319struct drm_dp_sideband_msg_req_body {
320 u8 req_type;
321 union ack_req {
322 struct drm_dp_connection_status_notify conn_stat;
323 struct drm_dp_port_number_req port_num;
324 struct drm_dp_resource_status_notify resource_stat;
325
326 struct drm_dp_query_payload query_payload;
327 struct drm_dp_allocate_payload allocate_payload;
328
329 struct drm_dp_remote_dpcd_read dpcd_read;
330 struct drm_dp_remote_dpcd_write dpcd_write;
331
332 struct drm_dp_remote_i2c_read i2c_read;
333 struct drm_dp_remote_i2c_write i2c_write;
334 } u;
335};
336
337struct drm_dp_sideband_msg_reply_body {
338 u8 reply_type;
339 u8 req_type;
340 union ack_replies {
341 struct drm_dp_nak_reply nak;
342 struct drm_dp_link_address_ack_reply link_addr;
343 struct drm_dp_port_number_rep port_number;
344
345 struct drm_dp_enum_path_resources_ack_reply path_resources;
346 struct drm_dp_allocate_payload_ack_reply allocate_payload;
347 struct drm_dp_query_payload_ack_reply query_payload;
348
349 struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
350 struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
351 struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
352
353 struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
354 struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
355 struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
356 } u;
357};
358
359
360#define DRM_DP_SIDEBAND_TX_QUEUED 0
361
362#define DRM_DP_SIDEBAND_TX_START_SEND 1
363
364#define DRM_DP_SIDEBAND_TX_SENT 2
365
366#define DRM_DP_SIDEBAND_TX_RX 3
367#define DRM_DP_SIDEBAND_TX_TIMEOUT 4
368
369struct drm_dp_sideband_msg_tx {
370 u8 msg[256];
371 u8 chunk[48];
372 u8 cur_offset;
373 u8 cur_len;
374 struct drm_dp_mst_branch *dst;
375 struct list_head next;
376 int seqno;
377 int state;
378 bool path_msg;
379 struct drm_dp_sideband_msg_reply_body reply;
380};
381
382
383struct drm_dp_mst_topology_mgr;
384struct drm_dp_mst_topology_cbs {
385
386 struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
387 void (*register_connector)(struct drm_connector *connector);
388 void (*destroy_connector)(struct drm_dp_mst_topology_mgr *mgr,
389 struct drm_connector *connector);
390 void (*hotplug)(struct drm_dp_mst_topology_mgr *mgr);
391
392};
393
394#define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
395
396#define DP_PAYLOAD_LOCAL 1
397#define DP_PAYLOAD_REMOTE 2
398#define DP_PAYLOAD_DELETE_LOCAL 3
399
400struct drm_dp_payload {
401 int payload_state;
402 int start_slot;
403 int num_slots;
404 int vcpi;
405};
406
407struct drm_dp_mst_topology_state {
408 int avail_slots;
409 struct drm_atomic_state *state;
410 struct drm_dp_mst_topology_mgr *mgr;
411};
412
413
414
415
416
417
418
419
420struct drm_dp_mst_topology_mgr {
421
422
423
424 struct drm_device *dev;
425
426
427
428 const struct drm_dp_mst_topology_cbs *cbs;
429
430
431
432
433 int max_dpcd_transaction_bytes;
434
435
436
437
438 struct drm_dp_aux *aux;
439
440
441
442 int max_payloads;
443
444
445
446
447 int conn_base_id;
448
449
450
451
452
453
454 struct drm_dp_sideband_msg_rx down_rep_recv;
455
456
457
458
459
460 struct drm_dp_sideband_msg_rx up_req_recv;
461
462
463
464
465 struct mutex lock;
466
467
468
469
470
471 bool mst_state;
472
473
474
475 struct drm_dp_mst_branch *mst_primary;
476
477
478
479
480 u8 dpcd[DP_RECEIVER_CAP_SIZE];
481
482
483
484 u8 sink_count;
485
486
487
488 int pbn_div;
489
490
491
492
493 struct drm_dp_mst_topology_state *state;
494
495
496
497
498 const struct drm_private_state_funcs *funcs;
499
500
501
502
503
504 struct mutex qlock;
505
506
507
508 struct list_head tx_msg_downq;
509
510
511
512
513 struct mutex payload_lock;
514
515
516
517
518 struct drm_dp_vcpi **proposed_vcpis;
519
520
521
522 struct drm_dp_payload *payloads;
523
524
525
526
527
528 unsigned long payload_mask;
529
530
531
532 unsigned long vcpi_mask;
533
534
535
536
537 wait_queue_head_t tx_waitq;
538
539
540
541 struct work_struct work;
542
543
544
545
546 struct work_struct tx_work;
547
548
549
550
551 struct list_head destroy_connector_list;
552
553
554
555 struct mutex destroy_connector_lock;
556
557
558
559
560 struct work_struct destroy_connector_work;
561};
562
563int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,
564 struct drm_device *dev, struct drm_dp_aux *aux,
565 int max_dpcd_transaction_bytes,
566 int max_payloads, int conn_base_id);
567
568void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
569
570
571int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
572
573
574int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
575
576
577enum drm_connector_status drm_dp_mst_detect_port(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
578
579bool drm_dp_mst_port_has_audio(struct drm_dp_mst_topology_mgr *mgr,
580 struct drm_dp_mst_port *port);
581struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
582
583
584int drm_dp_calc_pbn_mode(int clock, int bpp);
585
586
587bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
588 struct drm_dp_mst_port *port, int pbn, int slots);
589
590int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
591
592
593void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
594
595
596void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
597 struct drm_dp_mst_port *port);
598
599
600int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
601 int pbn);
602
603
604int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
605
606
607int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
608
609int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
610
611void drm_dp_mst_dump_topology(struct seq_file *m,
612 struct drm_dp_mst_topology_mgr *mgr);
613
614void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
615int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr);
616struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
617 struct drm_dp_mst_topology_mgr *mgr);
618int drm_dp_atomic_find_vcpi_slots(struct drm_atomic_state *state,
619 struct drm_dp_mst_topology_mgr *mgr,
620 struct drm_dp_mst_port *port, int pbn);
621int drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state,
622 struct drm_dp_mst_topology_mgr *mgr,
623 int slots);
624
625#endif
626