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
29#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
48
49struct drm_dp_mst_branch;
50
51
52
53
54
55
56
57
58struct drm_dp_vcpi {
59 int vcpi;
60 int pbn;
61 int aligned_pbn;
62 int num_slots;
63};
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98struct drm_dp_mst_port {
99
100
101
102
103 struct kref topology_kref;
104
105
106
107
108
109
110 struct kref malloc_kref;
111
112#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
113
114
115
116
117 struct drm_dp_mst_topology_ref_history topology_ref_history;
118#endif
119
120 u8 port_num;
121 bool input;
122 bool mcs;
123 bool ddps;
124 u8 pdt;
125 bool ldps;
126 u8 dpcd_rev;
127 u8 num_sdp_streams;
128 u8 num_sdp_stream_sinks;
129 uint16_t full_pbn;
130 struct list_head next;
131
132
133
134
135
136
137
138
139
140
141 struct drm_dp_mst_branch *mstb;
142 struct drm_dp_aux aux;
143 struct drm_dp_mst_branch *parent;
144
145 struct drm_dp_vcpi vcpi;
146 struct drm_connector *connector;
147 struct drm_dp_mst_topology_mgr *mgr;
148
149
150
151
152
153 struct edid *cached_edid;
154
155
156
157
158 bool has_audio;
159
160
161
162
163
164 bool fec_capable;
165};
166
167
168struct drm_dp_sideband_msg_hdr {
169 u8 lct;
170 u8 lcr;
171 u8 rad[8];
172 bool broadcast;
173 bool path_msg;
174 u8 msg_len;
175 bool somt;
176 bool eomt;
177 bool seqno;
178};
179
180struct drm_dp_sideband_msg_rx {
181 u8 chunk[48];
182 u8 msg[256];
183 u8 curchunk_len;
184 u8 curchunk_idx;
185 u8 curchunk_hdrlen;
186 u8 curlen;
187 bool have_somt;
188 bool have_eomt;
189 struct drm_dp_sideband_msg_hdr initial_hdr;
190};
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207struct drm_dp_mst_branch {
208
209
210
211
212 struct kref topology_kref;
213
214
215
216
217
218
219 struct kref malloc_kref;
220
221#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
222
223
224
225
226 struct drm_dp_mst_topology_ref_history topology_ref_history;
227#endif
228
229
230
231
232
233 struct list_head destroy_next;
234
235 u8 rad[8];
236 u8 lct;
237 int num_ports;
238
239
240
241
242
243
244
245
246
247
248
249 struct list_head ports;
250
251 struct drm_dp_mst_port *port_parent;
252 struct drm_dp_mst_topology_mgr *mgr;
253
254 bool link_address_sent;
255
256
257 u8 guid[16];
258};
259
260
261struct drm_dp_nak_reply {
262 u8 guid[16];
263 u8 reason;
264 u8 nak_data;
265};
266
267struct drm_dp_link_address_ack_reply {
268 u8 guid[16];
269 u8 nports;
270 struct drm_dp_link_addr_reply_port {
271 bool input_port;
272 u8 peer_device_type;
273 u8 port_number;
274 bool mcs;
275 bool ddps;
276 bool legacy_device_plug_status;
277 u8 dpcd_revision;
278 u8 peer_guid[16];
279 u8 num_sdp_streams;
280 u8 num_sdp_stream_sinks;
281 } ports[16];
282};
283
284struct drm_dp_remote_dpcd_read_ack_reply {
285 u8 port_number;
286 u8 num_bytes;
287 u8 bytes[255];
288};
289
290struct drm_dp_remote_dpcd_write_ack_reply {
291 u8 port_number;
292};
293
294struct drm_dp_remote_dpcd_write_nak_reply {
295 u8 port_number;
296 u8 reason;
297 u8 bytes_written_before_failure;
298};
299
300struct drm_dp_remote_i2c_read_ack_reply {
301 u8 port_number;
302 u8 num_bytes;
303 u8 bytes[255];
304};
305
306struct drm_dp_remote_i2c_read_nak_reply {
307 u8 port_number;
308 u8 nak_reason;
309 u8 i2c_nak_transaction;
310};
311
312struct drm_dp_remote_i2c_write_ack_reply {
313 u8 port_number;
314};
315
316struct drm_dp_query_stream_enc_status_ack_reply {
317
318 u8 stream_id;
319
320
321 bool reply_signed;
322
323
324 bool unauthorizable_device_present;
325 bool legacy_device_present;
326 bool query_capable_device_present;
327
328
329 bool hdcp_1x_device_present;
330 bool hdcp_2x_device_present;
331
332
333 bool auth_completed;
334
335
336 bool encryption_enabled;
337
338
339 bool repeater_present;
340
341
342 u8 state;
343};
344
345#define DRM_DP_MAX_SDP_STREAMS 16
346struct drm_dp_allocate_payload {
347 u8 port_number;
348 u8 number_sdp_streams;
349 u8 vcpi;
350 u16 pbn;
351 u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
352};
353
354struct drm_dp_allocate_payload_ack_reply {
355 u8 port_number;
356 u8 vcpi;
357 u16 allocated_pbn;
358};
359
360struct drm_dp_connection_status_notify {
361 u8 guid[16];
362 u8 port_number;
363 bool legacy_device_plug_status;
364 bool displayport_device_plug_status;
365 bool message_capability_status;
366 bool input_port;
367 u8 peer_device_type;
368};
369
370struct drm_dp_remote_dpcd_read {
371 u8 port_number;
372 u32 dpcd_address;
373 u8 num_bytes;
374};
375
376struct drm_dp_remote_dpcd_write {
377 u8 port_number;
378 u32 dpcd_address;
379 u8 num_bytes;
380 u8 *bytes;
381};
382
383#define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
384struct drm_dp_remote_i2c_read {
385 u8 num_transactions;
386 u8 port_number;
387 struct drm_dp_remote_i2c_read_tx {
388 u8 i2c_dev_id;
389 u8 num_bytes;
390 u8 *bytes;
391 u8 no_stop_bit;
392 u8 i2c_transaction_delay;
393 } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
394 u8 read_i2c_device_id;
395 u8 num_bytes_read;
396};
397
398struct drm_dp_remote_i2c_write {
399 u8 port_number;
400 u8 write_i2c_device_id;
401 u8 num_bytes;
402 u8 *bytes;
403};
404
405struct drm_dp_query_stream_enc_status {
406 u8 stream_id;
407 u8 client_id[7];
408 u8 stream_event;
409 bool valid_stream_event;
410 u8 stream_behavior;
411 u8 valid_stream_behavior;
412};
413
414
415struct drm_dp_port_number_req {
416 u8 port_number;
417};
418
419struct drm_dp_enum_path_resources_ack_reply {
420 u8 port_number;
421 bool fec_capable;
422 u16 full_payload_bw_number;
423 u16 avail_payload_bw_number;
424};
425
426
427struct drm_dp_port_number_rep {
428 u8 port_number;
429};
430
431struct drm_dp_query_payload {
432 u8 port_number;
433 u8 vcpi;
434};
435
436struct drm_dp_resource_status_notify {
437 u8 port_number;
438 u8 guid[16];
439 u16 available_pbn;
440};
441
442struct drm_dp_query_payload_ack_reply {
443 u8 port_number;
444 u16 allocated_pbn;
445};
446
447struct drm_dp_sideband_msg_req_body {
448 u8 req_type;
449 union ack_req {
450 struct drm_dp_connection_status_notify conn_stat;
451 struct drm_dp_port_number_req port_num;
452 struct drm_dp_resource_status_notify resource_stat;
453
454 struct drm_dp_query_payload query_payload;
455 struct drm_dp_allocate_payload allocate_payload;
456
457 struct drm_dp_remote_dpcd_read dpcd_read;
458 struct drm_dp_remote_dpcd_write dpcd_write;
459
460 struct drm_dp_remote_i2c_read i2c_read;
461 struct drm_dp_remote_i2c_write i2c_write;
462
463 struct drm_dp_query_stream_enc_status enc_status;
464 } u;
465};
466
467struct drm_dp_sideband_msg_reply_body {
468 u8 reply_type;
469 u8 req_type;
470 union ack_replies {
471 struct drm_dp_nak_reply nak;
472 struct drm_dp_link_address_ack_reply link_addr;
473 struct drm_dp_port_number_rep port_number;
474
475 struct drm_dp_enum_path_resources_ack_reply path_resources;
476 struct drm_dp_allocate_payload_ack_reply allocate_payload;
477 struct drm_dp_query_payload_ack_reply query_payload;
478
479 struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
480 struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
481 struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
482
483 struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
484 struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
485 struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
486
487 struct drm_dp_query_stream_enc_status_ack_reply enc_status;
488 } u;
489};
490
491
492#define DRM_DP_SIDEBAND_TX_QUEUED 0
493
494#define DRM_DP_SIDEBAND_TX_START_SEND 1
495
496#define DRM_DP_SIDEBAND_TX_SENT 2
497
498#define DRM_DP_SIDEBAND_TX_RX 3
499#define DRM_DP_SIDEBAND_TX_TIMEOUT 4
500
501struct drm_dp_sideband_msg_tx {
502 u8 msg[256];
503 u8 chunk[48];
504 u8 cur_offset;
505 u8 cur_len;
506 struct drm_dp_mst_branch *dst;
507 struct list_head next;
508 int seqno;
509 int state;
510 bool path_msg;
511 struct drm_dp_sideband_msg_reply_body reply;
512};
513
514
515struct drm_dp_mst_topology_mgr;
516struct drm_dp_mst_topology_cbs {
517
518 struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
519
520
521
522
523
524
525
526
527 void (*poll_hpd_irq)(struct drm_dp_mst_topology_mgr *mgr);
528};
529
530#define DP_MAX_PAYLOAD (sizeof(unsigned long) * 8)
531
532#define DP_PAYLOAD_LOCAL 1
533#define DP_PAYLOAD_REMOTE 2
534#define DP_PAYLOAD_DELETE_LOCAL 3
535
536struct drm_dp_payload {
537 int payload_state;
538 int start_slot;
539 int num_slots;
540 int vcpi;
541};
542
543#define to_dp_mst_topology_state(x) container_of(x, struct drm_dp_mst_topology_state, base)
544
545struct drm_dp_vcpi_allocation {
546 struct drm_dp_mst_port *port;
547 int vcpi;
548 int pbn;
549 bool dsc_enabled;
550 struct list_head next;
551};
552
553struct drm_dp_mst_topology_state {
554 struct drm_private_state base;
555 struct list_head vcpis;
556 struct drm_dp_mst_topology_mgr *mgr;
557};
558
559#define to_dp_mst_topology_mgr(x) container_of(x, struct drm_dp_mst_topology_mgr, base)
560
561
562
563
564
565
566
567
568struct drm_dp_mst_topology_mgr {
569
570
571
572 struct drm_private_obj base;
573
574
575
576
577 struct drm_device *dev;
578
579
580
581 const struct drm_dp_mst_topology_cbs *cbs;
582
583
584
585
586 int max_dpcd_transaction_bytes;
587
588
589
590
591 struct drm_dp_aux *aux;
592
593
594
595 int max_payloads;
596
597
598
599 u8 max_lane_count;
600
601
602
603 u8 max_link_rate;
604
605
606
607
608 int conn_base_id;
609
610
611
612
613 struct drm_dp_sideband_msg_rx up_req_recv;
614
615
616
617
618
619 struct drm_dp_sideband_msg_rx down_rep_recv;
620
621
622
623
624
625 struct mutex lock;
626
627
628
629
630
631
632 struct mutex probe_lock;
633
634
635
636
637
638 bool mst_state : 1;
639
640
641
642
643
644 bool payload_id_table_cleared : 1;
645
646
647
648
649 struct drm_dp_mst_branch *mst_primary;
650
651
652
653
654 u8 dpcd[DP_RECEIVER_CAP_SIZE];
655
656
657
658 u8 sink_count;
659
660
661
662 int pbn_div;
663
664
665
666
667 const struct drm_private_state_funcs *funcs;
668
669
670
671
672 struct mutex qlock;
673
674
675
676
677 struct list_head tx_msg_downq;
678
679
680
681
682 struct mutex payload_lock;
683
684
685
686
687
688 struct drm_dp_vcpi **proposed_vcpis;
689
690
691
692
693 struct drm_dp_payload *payloads;
694
695
696
697
698
699 unsigned long payload_mask;
700
701
702
703 unsigned long vcpi_mask;
704
705
706
707
708 wait_queue_head_t tx_waitq;
709
710
711
712 struct work_struct work;
713
714
715
716
717 struct work_struct tx_work;
718
719
720
721
722 struct list_head destroy_port_list;
723
724
725
726
727 struct list_head destroy_branch_device_list;
728
729
730
731
732 struct mutex delayed_destroy_lock;
733
734
735
736
737
738
739 struct workqueue_struct *delayed_destroy_wq;
740
741
742
743
744
745 struct work_struct delayed_destroy_work;
746
747
748
749
750
751 struct list_head up_req_list;
752
753
754
755 struct mutex up_req_lock;
756
757
758
759
760
761 struct work_struct up_req_work;
762
763#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
764
765
766
767
768
769 struct mutex topology_ref_history_lock;
770#endif
771};
772
773int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,
774 struct drm_device *dev, struct drm_dp_aux *aux,
775 int max_dpcd_transaction_bytes,
776 int max_payloads,
777 u8 max_lane_count, u8 max_link_rate,
778 int conn_base_id);
779
780void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
781
782bool drm_dp_read_mst_cap(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
783int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
784
785int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
786
787
788int
789drm_dp_mst_detect_port(struct drm_connector *connector,
790 struct drm_modeset_acquire_ctx *ctx,
791 struct drm_dp_mst_topology_mgr *mgr,
792 struct drm_dp_mst_port *port);
793
794struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
795
796int drm_dp_get_vc_payload_bw(int link_rate, int link_lane_count);
797
798int drm_dp_calc_pbn_mode(int clock, int bpp, bool dsc);
799
800bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
801 struct drm_dp_mst_port *port, int pbn, int slots);
802
803int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
804
805
806void drm_dp_mst_reset_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);
807
808
809void drm_dp_mst_deallocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
810 struct drm_dp_mst_port *port);
811
812
813int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
814 int pbn);
815
816
817int drm_dp_update_payload_part1(struct drm_dp_mst_topology_mgr *mgr);
818
819
820int drm_dp_update_payload_part2(struct drm_dp_mst_topology_mgr *mgr);
821
822int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
823
824void drm_dp_mst_dump_topology(struct seq_file *m,
825 struct drm_dp_mst_topology_mgr *mgr);
826
827void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
828int __must_check
829drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr,
830 bool sync);
831
832ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
833 unsigned int offset, void *buffer, size_t size);
834ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
835 unsigned int offset, void *buffer, size_t size);
836
837int drm_dp_mst_connector_late_register(struct drm_connector *connector,
838 struct drm_dp_mst_port *port);
839void drm_dp_mst_connector_early_unregister(struct drm_connector *connector,
840 struct drm_dp_mst_port *port);
841
842struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
843 struct drm_dp_mst_topology_mgr *mgr);
844int __must_check
845drm_dp_atomic_find_vcpi_slots(struct drm_atomic_state *state,
846 struct drm_dp_mst_topology_mgr *mgr,
847 struct drm_dp_mst_port *port, int pbn,
848 int pbn_div);
849int drm_dp_mst_atomic_enable_dsc(struct drm_atomic_state *state,
850 struct drm_dp_mst_port *port,
851 int pbn, int pbn_div,
852 bool enable);
853int __must_check
854drm_dp_mst_add_affected_dsc_crtcs(struct drm_atomic_state *state,
855 struct drm_dp_mst_topology_mgr *mgr);
856int __must_check
857drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state,
858 struct drm_dp_mst_topology_mgr *mgr,
859 struct drm_dp_mst_port *port);
860int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr,
861 struct drm_dp_mst_port *port, bool power_up);
862int drm_dp_send_query_stream_enc_status(struct drm_dp_mst_topology_mgr *mgr,
863 struct drm_dp_mst_port *port,
864 struct drm_dp_query_stream_enc_status_ack_reply *status);
865int __must_check drm_dp_mst_atomic_check(struct drm_atomic_state *state);
866
867void drm_dp_mst_get_port_malloc(struct drm_dp_mst_port *port);
868void drm_dp_mst_put_port_malloc(struct drm_dp_mst_port *port);
869
870struct drm_dp_aux *drm_dp_mst_dsc_aux_for_port(struct drm_dp_mst_port *port);
871
872extern const struct drm_private_state_funcs drm_dp_mst_topology_state_funcs;
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893static inline bool
894__drm_dp_mst_state_iter_get(struct drm_atomic_state *state,
895 struct drm_dp_mst_topology_mgr **mgr,
896 struct drm_dp_mst_topology_state **old_state,
897 struct drm_dp_mst_topology_state **new_state,
898 int i)
899{
900 struct __drm_private_objs_state *objs_state = &state->private_objs[i];
901
902 if (objs_state->ptr->funcs != &drm_dp_mst_topology_state_funcs)
903 return false;
904
905 *mgr = to_dp_mst_topology_mgr(objs_state->ptr);
906 if (old_state)
907 *old_state = to_dp_mst_topology_state(objs_state->old_state);
908 if (new_state)
909 *new_state = to_dp_mst_topology_state(objs_state->new_state);
910
911 return true;
912}
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929#define for_each_oldnew_mst_mgr_in_state(__state, mgr, old_state, new_state, __i) \
930 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
931 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), &(new_state), (__i)))
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946#define for_each_old_mst_mgr_in_state(__state, mgr, old_state, __i) \
947 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
948 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), NULL, (__i)))
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964#define for_each_new_mst_mgr_in_state(__state, mgr, new_state, __i) \
965 for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
966 for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), NULL, &(new_state), (__i)))
967
968#endif
969