drm_dp_mst_helper.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. /*
  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. #include <linux/types.h>
  25. #include <drm/display/drm_dp_helper.h>
  26. #include <drm/drm_atomic.h>
  27. #include <drm/drm_fixed.h>
  28. #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
  29. #include <linux/stackdepot.h>
  30. #include <linux/timekeeping.h>
  31. enum drm_dp_mst_topology_ref_type {
  32. DRM_DP_MST_TOPOLOGY_REF_GET,
  33. DRM_DP_MST_TOPOLOGY_REF_PUT,
  34. };
  35. struct drm_dp_mst_topology_ref_history {
  36. struct drm_dp_mst_topology_ref_entry {
  37. enum drm_dp_mst_topology_ref_type type;
  38. int count;
  39. ktime_t ts_nsec;
  40. depot_stack_handle_t backtrace;
  41. } *entries;
  42. int len;
  43. };
  44. #endif /* IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS) */
  45. enum drm_dp_mst_payload_allocation {
  46. DRM_DP_MST_PAYLOAD_ALLOCATION_NONE,
  47. DRM_DP_MST_PAYLOAD_ALLOCATION_LOCAL,
  48. DRM_DP_MST_PAYLOAD_ALLOCATION_DFP,
  49. DRM_DP_MST_PAYLOAD_ALLOCATION_REMOTE,
  50. };
  51. struct drm_dp_mst_branch;
  52. /**
  53. * struct drm_dp_mst_port - MST port
  54. * @port_num: port number
  55. * @input: if this port is an input port. Protected by
  56. * &drm_dp_mst_topology_mgr.base.lock.
  57. * @mcs: message capability status - DP 1.2 spec. Protected by
  58. * &drm_dp_mst_topology_mgr.base.lock.
  59. * @ddps: DisplayPort Device Plug Status - DP 1.2. Protected by
  60. * &drm_dp_mst_topology_mgr.base.lock.
  61. * @pdt: Peer Device Type. Protected by
  62. * &drm_dp_mst_topology_mgr.base.lock.
  63. * @ldps: Legacy Device Plug Status. Protected by
  64. * &drm_dp_mst_topology_mgr.base.lock.
  65. * @dpcd_rev: DPCD revision of device on this port. Protected by
  66. * &drm_dp_mst_topology_mgr.base.lock.
  67. * @num_sdp_streams: Number of simultaneous streams. Protected by
  68. * &drm_dp_mst_topology_mgr.base.lock.
  69. * @num_sdp_stream_sinks: Number of stream sinks. Protected by
  70. * &drm_dp_mst_topology_mgr.base.lock.
  71. * @full_pbn: Max possible bandwidth for this port. Protected by
  72. * &drm_dp_mst_topology_mgr.base.lock.
  73. * @next: link to next port on this branch device
  74. * @aux: i2c aux transport to talk to device connected to this port, protected
  75. * by &drm_dp_mst_topology_mgr.base.lock.
  76. * @passthrough_aux: parent aux to which DSC pass-through requests should be
  77. * sent, only set if DSC pass-through is possible.
  78. * @parent: branch device parent of this port
  79. * @connector: DRM connector this port is connected to. Protected by
  80. * &drm_dp_mst_topology_mgr.base.lock.
  81. * @mgr: topology manager this port lives under.
  82. *
  83. * This structure represents an MST port endpoint on a device somewhere
  84. * in the MST topology.
  85. */
  86. struct drm_dp_mst_port {
  87. /**
  88. * @topology_kref: refcount for this port's lifetime in the topology,
  89. * only the DP MST helpers should need to touch this
  90. */
  91. struct kref topology_kref;
  92. /**
  93. * @malloc_kref: refcount for the memory allocation containing this
  94. * structure. See drm_dp_mst_get_port_malloc() and
  95. * drm_dp_mst_put_port_malloc().
  96. */
  97. struct kref malloc_kref;
  98. #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
  99. /**
  100. * @topology_ref_history: A history of each topology
  101. * reference/dereference. See CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS.
  102. */
  103. struct drm_dp_mst_topology_ref_history topology_ref_history;
  104. #endif
  105. u8 port_num;
  106. bool input;
  107. bool mcs;
  108. bool ddps;
  109. u8 pdt;
  110. bool ldps;
  111. u8 dpcd_rev;
  112. u8 num_sdp_streams;
  113. u8 num_sdp_stream_sinks;
  114. uint16_t full_pbn;
  115. struct list_head next;
  116. /**
  117. * @mstb: the branch device connected to this port, if there is one.
  118. * This should be considered protected for reading by
  119. * &drm_dp_mst_topology_mgr.lock. There are two exceptions to this:
  120. * &drm_dp_mst_topology_mgr.up_req_work and
  121. * &drm_dp_mst_topology_mgr.work, which do not grab
  122. * &drm_dp_mst_topology_mgr.lock during reads but are the only
  123. * updaters of this list and are protected from writing concurrently
  124. * by &drm_dp_mst_topology_mgr.probe_lock.
  125. */
  126. struct drm_dp_mst_branch *mstb;
  127. struct drm_dp_aux aux; /* i2c bus for this port? */
  128. struct drm_dp_aux *passthrough_aux;
  129. struct drm_dp_mst_branch *parent;
  130. struct drm_connector *connector;
  131. struct drm_dp_mst_topology_mgr *mgr;
  132. /**
  133. * @cached_edid: for DP logical ports - make tiling work by ensuring
  134. * that the EDID for all connectors is read immediately.
  135. */
  136. const struct drm_edid *cached_edid;
  137. /**
  138. * @fec_capable: bool indicating if FEC can be supported up to that
  139. * point in the MST topology.
  140. */
  141. bool fec_capable;
  142. };
  143. /* sideband msg header - not bit struct */
  144. struct drm_dp_sideband_msg_hdr {
  145. u8 lct;
  146. u8 lcr;
  147. u8 rad[8];
  148. bool broadcast;
  149. bool path_msg;
  150. u8 msg_len;
  151. bool somt;
  152. bool eomt;
  153. bool seqno;
  154. };
  155. struct drm_dp_sideband_msg_rx {
  156. u8 chunk[48];
  157. u8 msg[256];
  158. u8 curchunk_len;
  159. u8 curchunk_idx; /* chunk we are parsing now */
  160. u8 curchunk_hdrlen;
  161. u8 curlen; /* total length of the msg */
  162. bool have_somt;
  163. bool have_eomt;
  164. struct drm_dp_sideband_msg_hdr initial_hdr;
  165. };
  166. /**
  167. * struct drm_dp_mst_branch - MST branch device.
  168. * @rad: Relative Address to talk to this branch device.
  169. * @lct: Link count total to talk to this branch device.
  170. * @num_ports: number of ports on the branch.
  171. * @port_parent: pointer to the port parent, NULL if toplevel.
  172. * @mgr: topology manager for this branch device.
  173. * @link_address_sent: if a link address message has been sent to this device yet.
  174. * @guid: guid for DP 1.2 branch device. port under this branch can be
  175. * identified by port #.
  176. *
  177. * This structure represents an MST branch device, there is one
  178. * primary branch device at the root, along with any other branches connected
  179. * to downstream port of parent branches.
  180. */
  181. struct drm_dp_mst_branch {
  182. /**
  183. * @topology_kref: refcount for this branch device's lifetime in the
  184. * topology, only the DP MST helpers should need to touch this
  185. */
  186. struct kref topology_kref;
  187. /**
  188. * @malloc_kref: refcount for the memory allocation containing this
  189. * structure. See drm_dp_mst_get_mstb_malloc() and
  190. * drm_dp_mst_put_mstb_malloc().
  191. */
  192. struct kref malloc_kref;
  193. #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. /**
  201. * @destroy_next: linked-list entry used by
  202. * drm_dp_delayed_destroy_work()
  203. */
  204. struct list_head destroy_next;
  205. /**
  206. * @rad: Relative Address of the MST branch.
  207. * For &drm_dp_mst_topology_mgr.mst_primary, it's rad[8] are all 0,
  208. * unset and unused. For MST branches connected after mst_primary,
  209. * in each element of rad[] the nibbles are ordered by the most
  210. * signifcant 4 bits first and the least significant 4 bits second.
  211. */
  212. u8 rad[8];
  213. u8 lct;
  214. int num_ports;
  215. /**
  216. * @ports: the list of ports on this branch device. This should be
  217. * considered protected for reading by &drm_dp_mst_topology_mgr.lock.
  218. * There are two exceptions to this:
  219. * &drm_dp_mst_topology_mgr.up_req_work and
  220. * &drm_dp_mst_topology_mgr.work, which do not grab
  221. * &drm_dp_mst_topology_mgr.lock during reads but are the only
  222. * updaters of this list and are protected from updating the list
  223. * concurrently by @drm_dp_mst_topology_mgr.probe_lock
  224. */
  225. struct list_head ports;
  226. struct drm_dp_mst_port *port_parent;
  227. struct drm_dp_mst_topology_mgr *mgr;
  228. bool link_address_sent;
  229. /* global unique identifier to identify branch devices */
  230. guid_t guid;
  231. };
  232. struct drm_dp_nak_reply {
  233. guid_t guid;
  234. u8 reason;
  235. u8 nak_data;
  236. };
  237. struct drm_dp_link_address_ack_reply {
  238. guid_t guid;
  239. u8 nports;
  240. struct drm_dp_link_addr_reply_port {
  241. bool input_port;
  242. u8 peer_device_type;
  243. u8 port_number;
  244. bool mcs;
  245. bool ddps;
  246. bool legacy_device_plug_status;
  247. u8 dpcd_revision;
  248. guid_t peer_guid;
  249. u8 num_sdp_streams;
  250. u8 num_sdp_stream_sinks;
  251. } ports[16];
  252. };
  253. struct drm_dp_remote_dpcd_read_ack_reply {
  254. u8 port_number;
  255. u8 num_bytes;
  256. u8 bytes[255];
  257. };
  258. struct drm_dp_remote_dpcd_write_ack_reply {
  259. u8 port_number;
  260. };
  261. struct drm_dp_remote_dpcd_write_nak_reply {
  262. u8 port_number;
  263. u8 reason;
  264. u8 bytes_written_before_failure;
  265. };
  266. struct drm_dp_remote_i2c_read_ack_reply {
  267. u8 port_number;
  268. u8 num_bytes;
  269. u8 bytes[255];
  270. };
  271. struct drm_dp_remote_i2c_read_nak_reply {
  272. u8 port_number;
  273. u8 nak_reason;
  274. u8 i2c_nak_transaction;
  275. };
  276. struct drm_dp_remote_i2c_write_ack_reply {
  277. u8 port_number;
  278. };
  279. struct drm_dp_query_stream_enc_status_ack_reply {
  280. /* Bit[23:16]- Stream Id */
  281. u8 stream_id;
  282. /* Bit[15]- Signed */
  283. bool reply_signed;
  284. /* Bit[10:8]- Stream Output Sink Type */
  285. bool unauthorizable_device_present;
  286. bool legacy_device_present;
  287. bool query_capable_device_present;
  288. /* Bit[12:11]- Stream Output CP Type */
  289. bool hdcp_1x_device_present;
  290. bool hdcp_2x_device_present;
  291. /* Bit[4]- Stream Authentication */
  292. bool auth_completed;
  293. /* Bit[3]- Stream Encryption */
  294. bool encryption_enabled;
  295. /* Bit[2]- Stream Repeater Function Present */
  296. bool repeater_present;
  297. /* Bit[1:0]- Stream State */
  298. u8 state;
  299. };
  300. #define DRM_DP_MAX_SDP_STREAMS 16
  301. struct drm_dp_allocate_payload {
  302. u8 port_number;
  303. u8 number_sdp_streams;
  304. u8 vcpi;
  305. u16 pbn;
  306. u8 sdp_stream_sink[DRM_DP_MAX_SDP_STREAMS];
  307. };
  308. struct drm_dp_allocate_payload_ack_reply {
  309. u8 port_number;
  310. u8 vcpi;
  311. u16 allocated_pbn;
  312. };
  313. struct drm_dp_connection_status_notify {
  314. guid_t guid;
  315. u8 port_number;
  316. bool legacy_device_plug_status;
  317. bool displayport_device_plug_status;
  318. bool message_capability_status;
  319. bool input_port;
  320. u8 peer_device_type;
  321. };
  322. struct drm_dp_remote_dpcd_read {
  323. u8 port_number;
  324. u32 dpcd_address;
  325. u8 num_bytes;
  326. };
  327. struct drm_dp_remote_dpcd_write {
  328. u8 port_number;
  329. u32 dpcd_address;
  330. u8 num_bytes;
  331. u8 *bytes;
  332. };
  333. #define DP_REMOTE_I2C_READ_MAX_TRANSACTIONS 4
  334. struct drm_dp_remote_i2c_read {
  335. u8 num_transactions;
  336. u8 port_number;
  337. struct drm_dp_remote_i2c_read_tx {
  338. u8 i2c_dev_id;
  339. u8 num_bytes;
  340. u8 *bytes;
  341. u8 no_stop_bit;
  342. u8 i2c_transaction_delay;
  343. } transactions[DP_REMOTE_I2C_READ_MAX_TRANSACTIONS];
  344. u8 read_i2c_device_id;
  345. u8 num_bytes_read;
  346. };
  347. struct drm_dp_remote_i2c_write {
  348. u8 port_number;
  349. u8 write_i2c_device_id;
  350. u8 num_bytes;
  351. u8 *bytes;
  352. };
  353. struct drm_dp_query_stream_enc_status {
  354. u8 stream_id;
  355. u8 client_id[7]; /* 56-bit nonce */
  356. u8 stream_event;
  357. bool valid_stream_event;
  358. u8 stream_behavior;
  359. u8 valid_stream_behavior;
  360. };
  361. /* this covers ENUM_RESOURCES, POWER_DOWN_PHY, POWER_UP_PHY */
  362. struct drm_dp_port_number_req {
  363. u8 port_number;
  364. };
  365. struct drm_dp_enum_path_resources_ack_reply {
  366. u8 port_number;
  367. bool fec_capable;
  368. u16 full_payload_bw_number;
  369. u16 avail_payload_bw_number;
  370. };
  371. /* covers POWER_DOWN_PHY, POWER_UP_PHY */
  372. struct drm_dp_port_number_rep {
  373. u8 port_number;
  374. };
  375. struct drm_dp_query_payload {
  376. u8 port_number;
  377. u8 vcpi;
  378. };
  379. struct drm_dp_resource_status_notify {
  380. u8 port_number;
  381. guid_t guid;
  382. u16 available_pbn;
  383. };
  384. struct drm_dp_query_payload_ack_reply {
  385. u8 port_number;
  386. u16 allocated_pbn;
  387. };
  388. struct drm_dp_sideband_msg_req_body {
  389. u8 req_type;
  390. union ack_req {
  391. struct drm_dp_connection_status_notify conn_stat;
  392. struct drm_dp_port_number_req port_num;
  393. struct drm_dp_resource_status_notify resource_stat;
  394. struct drm_dp_query_payload query_payload;
  395. struct drm_dp_allocate_payload allocate_payload;
  396. struct drm_dp_remote_dpcd_read dpcd_read;
  397. struct drm_dp_remote_dpcd_write dpcd_write;
  398. struct drm_dp_remote_i2c_read i2c_read;
  399. struct drm_dp_remote_i2c_write i2c_write;
  400. struct drm_dp_query_stream_enc_status enc_status;
  401. } u;
  402. };
  403. struct drm_dp_sideband_msg_reply_body {
  404. u8 reply_type;
  405. u8 req_type;
  406. union ack_replies {
  407. struct drm_dp_nak_reply nak;
  408. struct drm_dp_link_address_ack_reply link_addr;
  409. struct drm_dp_port_number_rep port_number;
  410. struct drm_dp_enum_path_resources_ack_reply path_resources;
  411. struct drm_dp_allocate_payload_ack_reply allocate_payload;
  412. struct drm_dp_query_payload_ack_reply query_payload;
  413. struct drm_dp_remote_dpcd_read_ack_reply remote_dpcd_read_ack;
  414. struct drm_dp_remote_dpcd_write_ack_reply remote_dpcd_write_ack;
  415. struct drm_dp_remote_dpcd_write_nak_reply remote_dpcd_write_nack;
  416. struct drm_dp_remote_i2c_read_ack_reply remote_i2c_read_ack;
  417. struct drm_dp_remote_i2c_read_nak_reply remote_i2c_read_nack;
  418. struct drm_dp_remote_i2c_write_ack_reply remote_i2c_write_ack;
  419. struct drm_dp_query_stream_enc_status_ack_reply enc_status;
  420. } u;
  421. };
  422. /* msg is queued to be put into a slot */
  423. #define DRM_DP_SIDEBAND_TX_QUEUED 0
  424. /* msg has started transmitting on a slot - still on msgq */
  425. #define DRM_DP_SIDEBAND_TX_START_SEND 1
  426. /* msg has finished transmitting on a slot - removed from msgq only in slot */
  427. #define DRM_DP_SIDEBAND_TX_SENT 2
  428. /* msg has received a response - removed from slot */
  429. #define DRM_DP_SIDEBAND_TX_RX 3
  430. #define DRM_DP_SIDEBAND_TX_TIMEOUT 4
  431. struct drm_dp_sideband_msg_tx {
  432. u8 msg[256];
  433. u8 chunk[48];
  434. u8 cur_offset;
  435. u8 cur_len;
  436. struct drm_dp_mst_branch *dst;
  437. struct list_head next;
  438. int seqno;
  439. int state;
  440. bool path_msg;
  441. struct drm_dp_sideband_msg_reply_body reply;
  442. };
  443. /* sideband msg handler */
  444. struct drm_dp_mst_topology_mgr;
  445. struct drm_dp_mst_topology_cbs {
  446. /* create a connector for a port */
  447. struct drm_connector *(*add_connector)(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, const char *path);
  448. /*
  449. * Checks for any pending MST interrupts, passing them to MST core for
  450. * processing, the same way an HPD IRQ pulse handler would do this.
  451. * If provided MST core calls this callback from a poll-waiting loop
  452. * when waiting for MST down message replies. The driver is expected
  453. * to guard against a race between this callback and the driver's HPD
  454. * IRQ pulse handler.
  455. */
  456. void (*poll_hpd_irq)(struct drm_dp_mst_topology_mgr *mgr);
  457. };
  458. #define to_dp_mst_topology_state(x) container_of(x, struct drm_dp_mst_topology_state, base)
  459. /**
  460. * struct drm_dp_mst_atomic_payload - Atomic state struct for an MST payload
  461. *
  462. * The primary atomic state structure for a given MST payload. Stores information like current
  463. * bandwidth allocation, intended action for this payload, etc.
  464. */
  465. struct drm_dp_mst_atomic_payload {
  466. /** @port: The MST port assigned to this payload */
  467. struct drm_dp_mst_port *port;
  468. /**
  469. * @vc_start_slot: The time slot that this payload starts on. Because payload start slots
  470. * can't be determined ahead of time, the contents of this value are UNDEFINED at atomic
  471. * check time. This shouldn't usually matter, as the start slot should never be relevant for
  472. * atomic state computations.
  473. *
  474. * Since this value is determined at commit time instead of check time, this value is
  475. * protected by the MST helpers ensuring that async commits operating on the given topology
  476. * never run in parallel. In the event that a driver does need to read this value (e.g. to
  477. * inform hardware of the starting timeslot for a payload), the driver may either:
  478. *
  479. * * Read this field during the atomic commit after
  480. * drm_dp_mst_atomic_wait_for_dependencies() has been called, which will ensure the
  481. * previous MST states payload start slots have been copied over to the new state. Note
  482. * that a new start slot won't be assigned/removed from this payload until
  483. * drm_dp_add_payload_part1()/drm_dp_remove_payload_part2() have been called.
  484. * * Acquire the MST modesetting lock, and then wait for any pending MST-related commits to
  485. * get committed to hardware by calling drm_crtc_commit_wait() on each of the
  486. * &drm_crtc_commit structs in &drm_dp_mst_topology_state.commit_deps.
  487. *
  488. * If neither of the two above solutions suffice (e.g. the driver needs to read the start
  489. * slot in the middle of an atomic commit without waiting for some reason), then drivers
  490. * should cache this value themselves after changing payloads.
  491. */
  492. s8 vc_start_slot;
  493. /** @vcpi: The Virtual Channel Payload Identifier */
  494. u8 vcpi;
  495. /**
  496. * @time_slots:
  497. * The number of timeslots allocated to this payload from the source DP Tx to
  498. * the immediate downstream DP Rx
  499. */
  500. int time_slots;
  501. /** @pbn: The payload bandwidth for this payload */
  502. int pbn;
  503. /** @delete: Whether or not we intend to delete this payload during this atomic commit */
  504. bool delete : 1;
  505. /** @dsc_enabled: Whether or not this payload has DSC enabled */
  506. bool dsc_enabled : 1;
  507. /** @payload_allocation_status: The allocation status of this payload */
  508. enum drm_dp_mst_payload_allocation payload_allocation_status;
  509. /** @next: The list node for this payload */
  510. struct list_head next;
  511. };
  512. /**
  513. * struct drm_dp_mst_topology_state - DisplayPort MST topology atomic state
  514. *
  515. * This struct represents the atomic state of the toplevel DisplayPort MST manager
  516. */
  517. struct drm_dp_mst_topology_state {
  518. /** @base: Base private state for atomic */
  519. struct drm_private_state base;
  520. /** @mgr: The topology manager */
  521. struct drm_dp_mst_topology_mgr *mgr;
  522. /**
  523. * @pending_crtc_mask: A bitmask of all CRTCs this topology state touches, drivers may
  524. * modify this to add additional dependencies if needed.
  525. */
  526. u32 pending_crtc_mask;
  527. /**
  528. * @commit_deps: A list of all CRTC commits affecting this topology, this field isn't
  529. * populated until drm_dp_mst_atomic_wait_for_dependencies() is called.
  530. */
  531. struct drm_crtc_commit **commit_deps;
  532. /** @num_commit_deps: The number of CRTC commits in @commit_deps */
  533. size_t num_commit_deps;
  534. /** @payload_mask: A bitmask of allocated VCPIs, used for VCPI assignments */
  535. u32 payload_mask;
  536. /** @payloads: The list of payloads being created/destroyed in this state */
  537. struct list_head payloads;
  538. /** @total_avail_slots: The total number of slots this topology can handle (63 or 64) */
  539. u8 total_avail_slots;
  540. /** @start_slot: The first usable time slot in this topology (1 or 0) */
  541. u8 start_slot;
  542. /**
  543. * @pbn_div: The current PBN divisor for this topology. The driver is expected to fill this
  544. * out itself.
  545. */
  546. fixed20_12 pbn_div;
  547. };
  548. #define to_dp_mst_topology_mgr(x) container_of(x, struct drm_dp_mst_topology_mgr, base)
  549. /**
  550. * struct drm_dp_mst_topology_mgr - DisplayPort MST manager
  551. *
  552. * This struct represents the toplevel displayport MST topology manager.
  553. * There should be one instance of this for every MST capable DP connector
  554. * on the GPU.
  555. */
  556. struct drm_dp_mst_topology_mgr {
  557. /**
  558. * @base: Base private object for atomic
  559. */
  560. struct drm_private_obj base;
  561. /**
  562. * @dev: device pointer for adding i2c devices etc.
  563. */
  564. struct drm_device *dev;
  565. /**
  566. * @cbs: callbacks for connector addition and destruction.
  567. */
  568. const struct drm_dp_mst_topology_cbs *cbs;
  569. /**
  570. * @max_dpcd_transaction_bytes: maximum number of bytes to read/write
  571. * in one go.
  572. */
  573. int max_dpcd_transaction_bytes;
  574. /**
  575. * @aux: AUX channel for the DP MST connector this topolgy mgr is
  576. * controlling.
  577. */
  578. struct drm_dp_aux *aux;
  579. /**
  580. * @max_payloads: maximum number of payloads the GPU can generate.
  581. */
  582. int max_payloads;
  583. /**
  584. * @conn_base_id: DRM connector ID this mgr is connected to. Only used
  585. * to build the MST connector path value.
  586. */
  587. int conn_base_id;
  588. /**
  589. * @up_req_recv: Message receiver state for up requests.
  590. */
  591. struct drm_dp_sideband_msg_rx up_req_recv;
  592. /**
  593. * @down_rep_recv: Message receiver state for replies to down
  594. * requests.
  595. */
  596. struct drm_dp_sideband_msg_rx down_rep_recv;
  597. /**
  598. * @lock: protects @mst_state, @mst_primary, @dpcd, and
  599. * @payload_id_table_cleared.
  600. */
  601. struct mutex lock;
  602. /**
  603. * @probe_lock: Prevents @work and @up_req_work, the only writers of
  604. * &drm_dp_mst_port.mstb and &drm_dp_mst_branch.ports, from racing
  605. * while they update the topology.
  606. */
  607. struct mutex probe_lock;
  608. /**
  609. * @mst_state: If this manager is enabled for an MST capable port. False
  610. * if no MST sink/branch devices is connected.
  611. */
  612. bool mst_state : 1;
  613. /**
  614. * @payload_id_table_cleared: Whether or not we've cleared the payload
  615. * ID table for @mst_primary. Protected by @lock.
  616. */
  617. bool payload_id_table_cleared : 1;
  618. /**
  619. * @reset_rx_state: The down request's reply and up request message
  620. * receiver state must be reset, after the topology manager got
  621. * removed. Protected by @lock.
  622. */
  623. bool reset_rx_state : 1;
  624. /**
  625. * @payload_count: The number of currently active payloads in hardware. This value is only
  626. * intended to be used internally by MST helpers for payload tracking, and is only safe to
  627. * read/write from the atomic commit (not check) context.
  628. */
  629. u8 payload_count;
  630. /**
  631. * @next_start_slot: The starting timeslot to use for new VC payloads. This value is used
  632. * internally by MST helpers for payload tracking, and is only safe to read/write from the
  633. * atomic commit (not check) context.
  634. */
  635. u8 next_start_slot;
  636. /**
  637. * @mst_primary: Pointer to the primary/first branch device.
  638. */
  639. struct drm_dp_mst_branch *mst_primary;
  640. /**
  641. * @dpcd: Cache of DPCD for primary port.
  642. */
  643. u8 dpcd[DP_RECEIVER_CAP_SIZE];
  644. /**
  645. * @sink_count: Sink count from DEVICE_SERVICE_IRQ_VECTOR_ESI0.
  646. */
  647. u8 sink_count;
  648. /**
  649. * @funcs: Atomic helper callbacks
  650. */
  651. const struct drm_private_state_funcs *funcs;
  652. /**
  653. * @qlock: protects @tx_msg_downq and &drm_dp_sideband_msg_tx.state
  654. */
  655. struct mutex qlock;
  656. /**
  657. * @tx_msg_downq: List of pending down requests
  658. */
  659. struct list_head tx_msg_downq;
  660. /**
  661. * @tx_waitq: Wait to queue stall for the tx worker.
  662. */
  663. wait_queue_head_t tx_waitq;
  664. /**
  665. * @work: Probe work.
  666. */
  667. struct work_struct work;
  668. /**
  669. * @tx_work: Sideband transmit worker. This can nest within the main
  670. * @work worker for each transaction @work launches.
  671. */
  672. struct work_struct tx_work;
  673. /**
  674. * @destroy_port_list: List of to be destroyed connectors.
  675. */
  676. struct list_head destroy_port_list;
  677. /**
  678. * @destroy_branch_device_list: List of to be destroyed branch
  679. * devices.
  680. */
  681. struct list_head destroy_branch_device_list;
  682. /**
  683. * @delayed_destroy_lock: Protects @destroy_port_list and
  684. * @destroy_branch_device_list.
  685. */
  686. struct mutex delayed_destroy_lock;
  687. /**
  688. * @delayed_destroy_wq: Workqueue used for delayed_destroy_work items.
  689. * A dedicated WQ makes it possible to drain any requeued work items
  690. * on it.
  691. */
  692. struct workqueue_struct *delayed_destroy_wq;
  693. /**
  694. * @delayed_destroy_work: Work item to destroy MST port and branch
  695. * devices, needed to avoid locking inversion.
  696. */
  697. struct work_struct delayed_destroy_work;
  698. /**
  699. * @up_req_list: List of pending up requests from the topology that
  700. * need to be processed, in chronological order.
  701. */
  702. struct list_head up_req_list;
  703. /**
  704. * @up_req_lock: Protects @up_req_list
  705. */
  706. struct mutex up_req_lock;
  707. /**
  708. * @up_req_work: Work item to process up requests received from the
  709. * topology. Needed to avoid blocking hotplug handling and sideband
  710. * transmissions.
  711. */
  712. struct work_struct up_req_work;
  713. #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
  714. /**
  715. * @topology_ref_history_lock: protects
  716. * &drm_dp_mst_port.topology_ref_history and
  717. * &drm_dp_mst_branch.topology_ref_history.
  718. */
  719. struct mutex topology_ref_history_lock;
  720. #endif
  721. };
  722. int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr,
  723. struct drm_device *dev, struct drm_dp_aux *aux,
  724. int max_dpcd_transaction_bytes,
  725. int max_payloads, int conn_base_id);
  726. void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
  727. /**
  728. * enum drm_dp_mst_mode - sink's MST mode capability
  729. */
  730. enum drm_dp_mst_mode {
  731. /**
  732. * @DRM_DP_SST: The sink does not support MST nor single stream sideband
  733. * messaging.
  734. */
  735. DRM_DP_SST,
  736. /**
  737. * @DRM_DP_MST: Sink supports MST, more than one stream and single
  738. * stream sideband messaging.
  739. */
  740. DRM_DP_MST,
  741. /**
  742. * @DRM_DP_SST_SIDEBAND_MSG: Sink supports only one stream and single
  743. * stream sideband messaging.
  744. */
  745. DRM_DP_SST_SIDEBAND_MSG,
  746. };
  747. enum drm_dp_mst_mode drm_dp_read_mst_cap(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
  748. int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
  749. int drm_dp_mst_hpd_irq_handle_event(struct drm_dp_mst_topology_mgr *mgr,
  750. const u8 *esi,
  751. u8 *ack,
  752. bool *handled);
  753. void drm_dp_mst_hpd_irq_send_new_request(struct drm_dp_mst_topology_mgr *mgr);
  754. int
  755. drm_dp_mst_detect_port(struct drm_connector *connector,
  756. struct drm_modeset_acquire_ctx *ctx,
  757. struct drm_dp_mst_topology_mgr *mgr,
  758. struct drm_dp_mst_port *port);
  759. const struct drm_edid *drm_dp_mst_edid_read(struct drm_connector *connector,
  760. struct drm_dp_mst_topology_mgr *mgr,
  761. struct drm_dp_mst_port *port);
  762. struct edid *drm_dp_mst_get_edid(struct drm_connector *connector,
  763. struct drm_dp_mst_topology_mgr *mgr,
  764. struct drm_dp_mst_port *port);
  765. fixed20_12 drm_dp_get_vc_payload_bw(const struct drm_dp_mst_topology_mgr *mgr,
  766. int link_rate, int link_lane_count);
  767. int drm_dp_calc_pbn_mode(int clock, int bpp);
  768. void drm_dp_mst_update_slots(struct drm_dp_mst_topology_state *mst_state, uint8_t link_encoding_cap);
  769. int drm_dp_add_payload_part1(struct drm_dp_mst_topology_mgr *mgr,
  770. struct drm_dp_mst_topology_state *mst_state,
  771. struct drm_dp_mst_atomic_payload *payload);
  772. int drm_dp_add_payload_part2(struct drm_dp_mst_topology_mgr *mgr,
  773. struct drm_dp_mst_atomic_payload *payload);
  774. void drm_dp_remove_payload_part1(struct drm_dp_mst_topology_mgr *mgr,
  775. struct drm_dp_mst_topology_state *mst_state,
  776. struct drm_dp_mst_atomic_payload *payload);
  777. void drm_dp_remove_payload_part2(struct drm_dp_mst_topology_mgr *mgr,
  778. struct drm_dp_mst_topology_state *mst_state,
  779. const struct drm_dp_mst_atomic_payload *old_payload,
  780. struct drm_dp_mst_atomic_payload *new_payload);
  781. int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
  782. void drm_dp_mst_dump_topology(struct seq_file *m,
  783. struct drm_dp_mst_topology_mgr *mgr);
  784. void drm_dp_mst_topology_queue_probe(struct drm_dp_mst_topology_mgr *mgr);
  785. void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
  786. int __must_check
  787. drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr,
  788. bool sync);
  789. ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
  790. unsigned int offset, void *buffer, size_t size);
  791. ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
  792. unsigned int offset, void *buffer, size_t size);
  793. int drm_dp_mst_connector_late_register(struct drm_connector *connector,
  794. struct drm_dp_mst_port *port);
  795. void drm_dp_mst_connector_early_unregister(struct drm_connector *connector,
  796. struct drm_dp_mst_port *port);
  797. struct drm_dp_mst_topology_state *
  798. drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
  799. struct drm_dp_mst_topology_mgr *mgr);
  800. struct drm_dp_mst_topology_state *
  801. drm_atomic_get_old_mst_topology_state(struct drm_atomic_state *state,
  802. struct drm_dp_mst_topology_mgr *mgr);
  803. struct drm_dp_mst_topology_state *
  804. drm_atomic_get_new_mst_topology_state(struct drm_atomic_state *state,
  805. struct drm_dp_mst_topology_mgr *mgr);
  806. struct drm_dp_mst_atomic_payload *
  807. drm_atomic_get_mst_payload_state(struct drm_dp_mst_topology_state *state,
  808. struct drm_dp_mst_port *port);
  809. bool drm_dp_mst_port_downstream_of_parent(struct drm_dp_mst_topology_mgr *mgr,
  810. struct drm_dp_mst_port *port,
  811. struct drm_dp_mst_port *parent);
  812. int __must_check
  813. drm_dp_atomic_find_time_slots(struct drm_atomic_state *state,
  814. struct drm_dp_mst_topology_mgr *mgr,
  815. struct drm_dp_mst_port *port, int pbn);
  816. int drm_dp_mst_atomic_enable_dsc(struct drm_atomic_state *state,
  817. struct drm_dp_mst_port *port,
  818. int pbn, bool enable);
  819. int __must_check
  820. drm_dp_mst_add_affected_dsc_crtcs(struct drm_atomic_state *state,
  821. struct drm_dp_mst_topology_mgr *mgr);
  822. int __must_check
  823. drm_dp_atomic_release_time_slots(struct drm_atomic_state *state,
  824. struct drm_dp_mst_topology_mgr *mgr,
  825. struct drm_dp_mst_port *port);
  826. void drm_dp_mst_atomic_wait_for_dependencies(struct drm_atomic_state *state);
  827. int __must_check drm_dp_mst_atomic_setup_commit(struct drm_atomic_state *state);
  828. int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr,
  829. struct drm_dp_mst_port *port, bool power_up);
  830. int drm_dp_send_query_stream_enc_status(struct drm_dp_mst_topology_mgr *mgr,
  831. struct drm_dp_mst_port *port,
  832. struct drm_dp_query_stream_enc_status_ack_reply *status);
  833. int __must_check drm_dp_mst_atomic_check_mgr(struct drm_atomic_state *state,
  834. struct drm_dp_mst_topology_mgr *mgr,
  835. struct drm_dp_mst_topology_state *mst_state,
  836. struct drm_dp_mst_port **failing_port);
  837. int __must_check drm_dp_mst_atomic_check(struct drm_atomic_state *state);
  838. int __must_check drm_dp_mst_root_conn_atomic_check(struct drm_connector_state *new_conn_state,
  839. struct drm_dp_mst_topology_mgr *mgr);
  840. void drm_dp_mst_get_port_malloc(struct drm_dp_mst_port *port);
  841. void drm_dp_mst_put_port_malloc(struct drm_dp_mst_port *port);
  842. static inline
  843. bool drm_dp_mst_port_is_logical(struct drm_dp_mst_port *port)
  844. {
  845. return port->port_num >= DP_MST_LOGICAL_PORT_0;
  846. }
  847. struct drm_dp_aux *drm_dp_mst_aux_for_parent(struct drm_dp_mst_port *port);
  848. struct drm_dp_aux *drm_dp_mst_dsc_aux_for_port(struct drm_dp_mst_port *port);
  849. static inline struct drm_dp_mst_topology_state *
  850. to_drm_dp_mst_topology_state(struct drm_private_state *state)
  851. {
  852. return container_of(state, struct drm_dp_mst_topology_state, base);
  853. }
  854. extern const struct drm_private_state_funcs drm_dp_mst_topology_state_funcs;
  855. /**
  856. * __drm_dp_mst_state_iter_get - private atomic state iterator function for
  857. * macro-internal use
  858. * @state: &struct drm_atomic_state pointer
  859. * @mgr: pointer to the &struct drm_dp_mst_topology_mgr iteration cursor
  860. * @old_state: optional pointer to the old &struct drm_dp_mst_topology_state
  861. * iteration cursor
  862. * @new_state: optional pointer to the new &struct drm_dp_mst_topology_state
  863. * iteration cursor
  864. * @i: int iteration cursor, for macro-internal use
  865. *
  866. * Used by for_each_oldnew_mst_mgr_in_state(),
  867. * for_each_old_mst_mgr_in_state(), and for_each_new_mst_mgr_in_state(). Don't
  868. * call this directly.
  869. *
  870. * Returns:
  871. * True if the current &struct drm_private_obj is a &struct
  872. * drm_dp_mst_topology_mgr, false otherwise.
  873. */
  874. static inline bool
  875. __drm_dp_mst_state_iter_get(struct drm_atomic_state *state,
  876. struct drm_dp_mst_topology_mgr **mgr,
  877. struct drm_dp_mst_topology_state **old_state,
  878. struct drm_dp_mst_topology_state **new_state,
  879. int i)
  880. {
  881. struct __drm_private_objs_state *objs_state = &state->private_objs[i];
  882. if (objs_state->ptr->funcs != &drm_dp_mst_topology_state_funcs)
  883. return false;
  884. *mgr = to_dp_mst_topology_mgr(objs_state->ptr);
  885. if (old_state)
  886. *old_state = to_dp_mst_topology_state(objs_state->old_state);
  887. if (new_state)
  888. *new_state = to_dp_mst_topology_state(objs_state->new_state);
  889. return true;
  890. }
  891. /**
  892. * for_each_oldnew_mst_mgr_in_state - iterate over all DP MST topology
  893. * managers in an atomic update
  894. * @__state: &struct drm_atomic_state pointer
  895. * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
  896. * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
  897. * state
  898. * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
  899. * state
  900. * @__i: int iteration cursor, for macro-internal use
  901. *
  902. * This iterates over all DRM DP MST topology managers in an atomic update,
  903. * tracking both old and new state. This is useful in places where the state
  904. * delta needs to be considered, for example in atomic check functions.
  905. */
  906. #define for_each_oldnew_mst_mgr_in_state(__state, mgr, old_state, new_state, __i) \
  907. for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
  908. for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), &(new_state), (__i)))
  909. /**
  910. * for_each_old_mst_mgr_in_state - iterate over all DP MST topology managers
  911. * in an atomic update
  912. * @__state: &struct drm_atomic_state pointer
  913. * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
  914. * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
  915. * state
  916. * @__i: int iteration cursor, for macro-internal use
  917. *
  918. * This iterates over all DRM DP MST topology managers in an atomic update,
  919. * tracking only the old state. This is useful in disable functions, where we
  920. * need the old state the hardware is still in.
  921. */
  922. #define for_each_old_mst_mgr_in_state(__state, mgr, old_state, __i) \
  923. for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
  924. for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), NULL, (__i)))
  925. /**
  926. * for_each_new_mst_mgr_in_state - iterate over all DP MST topology managers
  927. * in an atomic update
  928. * @__state: &struct drm_atomic_state pointer
  929. * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
  930. * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
  931. * state
  932. * @__i: int iteration cursor, for macro-internal use
  933. *
  934. * This iterates over all DRM DP MST topology managers in an atomic update,
  935. * tracking only the new state. This is useful in enable functions, where we
  936. * need the new state the hardware should be in when the atomic commit
  937. * operation has completed.
  938. */
  939. #define for_each_new_mst_mgr_in_state(__state, mgr, new_state, __i) \
  940. for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
  941. for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), NULL, &(new_state), (__i)))
  942. #endif