drm_dp_mst_helper.h 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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(int link_rate, int link_lane_count);
  766. int drm_dp_calc_pbn_mode(int clock, int bpp);
  767. void drm_dp_mst_update_slots(struct drm_dp_mst_topology_state *mst_state, uint8_t link_encoding_cap);
  768. int drm_dp_add_payload_part1(struct drm_dp_mst_topology_mgr *mgr,
  769. struct drm_dp_mst_topology_state *mst_state,
  770. struct drm_dp_mst_atomic_payload *payload);
  771. int drm_dp_add_payload_part2(struct drm_dp_mst_topology_mgr *mgr,
  772. struct drm_dp_mst_atomic_payload *payload);
  773. void drm_dp_remove_payload_part1(struct drm_dp_mst_topology_mgr *mgr,
  774. struct drm_dp_mst_topology_state *mst_state,
  775. struct drm_dp_mst_atomic_payload *payload);
  776. void drm_dp_remove_payload_part2(struct drm_dp_mst_topology_mgr *mgr,
  777. struct drm_dp_mst_topology_state *mst_state,
  778. const struct drm_dp_mst_atomic_payload *old_payload,
  779. struct drm_dp_mst_atomic_payload *new_payload);
  780. int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr);
  781. void drm_dp_mst_dump_topology(struct seq_file *m,
  782. struct drm_dp_mst_topology_mgr *mgr);
  783. void drm_dp_mst_topology_queue_probe(struct drm_dp_mst_topology_mgr *mgr);
  784. void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr);
  785. int __must_check
  786. drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr,
  787. bool sync);
  788. ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux,
  789. unsigned int offset, void *buffer, size_t size);
  790. ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux,
  791. unsigned int offset, void *buffer, size_t size);
  792. int drm_dp_mst_connector_late_register(struct drm_connector *connector,
  793. struct drm_dp_mst_port *port);
  794. void drm_dp_mst_connector_early_unregister(struct drm_connector *connector,
  795. struct drm_dp_mst_port *port);
  796. struct drm_dp_mst_topology_state *
  797. drm_atomic_get_mst_topology_state(struct drm_atomic_state *state,
  798. struct drm_dp_mst_topology_mgr *mgr);
  799. struct drm_dp_mst_topology_state *
  800. drm_atomic_get_old_mst_topology_state(struct drm_atomic_state *state,
  801. struct drm_dp_mst_topology_mgr *mgr);
  802. struct drm_dp_mst_topology_state *
  803. drm_atomic_get_new_mst_topology_state(struct drm_atomic_state *state,
  804. struct drm_dp_mst_topology_mgr *mgr);
  805. struct drm_dp_mst_atomic_payload *
  806. drm_atomic_get_mst_payload_state(struct drm_dp_mst_topology_state *state,
  807. struct drm_dp_mst_port *port);
  808. bool drm_dp_mst_port_downstream_of_parent(struct drm_dp_mst_topology_mgr *mgr,
  809. struct drm_dp_mst_port *port,
  810. struct drm_dp_mst_port *parent);
  811. int __must_check
  812. drm_dp_atomic_find_time_slots(struct drm_atomic_state *state,
  813. struct drm_dp_mst_topology_mgr *mgr,
  814. struct drm_dp_mst_port *port, int pbn);
  815. int drm_dp_mst_atomic_enable_dsc(struct drm_atomic_state *state,
  816. struct drm_dp_mst_port *port,
  817. int pbn, bool enable);
  818. int __must_check
  819. drm_dp_mst_add_affected_dsc_crtcs(struct drm_atomic_state *state,
  820. struct drm_dp_mst_topology_mgr *mgr);
  821. int __must_check
  822. drm_dp_atomic_release_time_slots(struct drm_atomic_state *state,
  823. struct drm_dp_mst_topology_mgr *mgr,
  824. struct drm_dp_mst_port *port);
  825. void drm_dp_mst_atomic_wait_for_dependencies(struct drm_atomic_state *state);
  826. int __must_check drm_dp_mst_atomic_setup_commit(struct drm_atomic_state *state);
  827. int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr,
  828. struct drm_dp_mst_port *port, bool power_up);
  829. int drm_dp_send_query_stream_enc_status(struct drm_dp_mst_topology_mgr *mgr,
  830. struct drm_dp_mst_port *port,
  831. struct drm_dp_query_stream_enc_status_ack_reply *status);
  832. int __must_check drm_dp_mst_atomic_check_mgr(struct drm_atomic_state *state,
  833. struct drm_dp_mst_topology_mgr *mgr,
  834. struct drm_dp_mst_topology_state *mst_state,
  835. struct drm_dp_mst_port **failing_port);
  836. int __must_check drm_dp_mst_atomic_check(struct drm_atomic_state *state);
  837. int __must_check drm_dp_mst_root_conn_atomic_check(struct drm_connector_state *new_conn_state,
  838. struct drm_dp_mst_topology_mgr *mgr);
  839. void drm_dp_mst_get_port_malloc(struct drm_dp_mst_port *port);
  840. void drm_dp_mst_put_port_malloc(struct drm_dp_mst_port *port);
  841. static inline
  842. bool drm_dp_mst_port_is_logical(struct drm_dp_mst_port *port)
  843. {
  844. return port->port_num >= DP_MST_LOGICAL_PORT_0;
  845. }
  846. struct drm_dp_aux *drm_dp_mst_aux_for_parent(struct drm_dp_mst_port *port);
  847. struct drm_dp_aux *drm_dp_mst_dsc_aux_for_port(struct drm_dp_mst_port *port);
  848. static inline struct drm_dp_mst_topology_state *
  849. to_drm_dp_mst_topology_state(struct drm_private_state *state)
  850. {
  851. return container_of(state, struct drm_dp_mst_topology_state, base);
  852. }
  853. extern const struct drm_private_state_funcs drm_dp_mst_topology_state_funcs;
  854. /**
  855. * __drm_dp_mst_state_iter_get - private atomic state iterator function for
  856. * macro-internal use
  857. * @state: &struct drm_atomic_state pointer
  858. * @mgr: pointer to the &struct drm_dp_mst_topology_mgr iteration cursor
  859. * @old_state: optional pointer to the old &struct drm_dp_mst_topology_state
  860. * iteration cursor
  861. * @new_state: optional pointer to the new &struct drm_dp_mst_topology_state
  862. * iteration cursor
  863. * @i: int iteration cursor, for macro-internal use
  864. *
  865. * Used by for_each_oldnew_mst_mgr_in_state(),
  866. * for_each_old_mst_mgr_in_state(), and for_each_new_mst_mgr_in_state(). Don't
  867. * call this directly.
  868. *
  869. * Returns:
  870. * True if the current &struct drm_private_obj is a &struct
  871. * drm_dp_mst_topology_mgr, false otherwise.
  872. */
  873. static inline bool
  874. __drm_dp_mst_state_iter_get(struct drm_atomic_state *state,
  875. struct drm_dp_mst_topology_mgr **mgr,
  876. struct drm_dp_mst_topology_state **old_state,
  877. struct drm_dp_mst_topology_state **new_state,
  878. int i)
  879. {
  880. struct __drm_private_objs_state *objs_state = &state->private_objs[i];
  881. if (objs_state->ptr->funcs != &drm_dp_mst_topology_state_funcs)
  882. return false;
  883. *mgr = to_dp_mst_topology_mgr(objs_state->ptr);
  884. if (old_state)
  885. *old_state = to_dp_mst_topology_state(objs_state->old_state);
  886. if (new_state)
  887. *new_state = to_dp_mst_topology_state(objs_state->new_state);
  888. return true;
  889. }
  890. /**
  891. * for_each_oldnew_mst_mgr_in_state - iterate over all DP MST topology
  892. * managers in an atomic update
  893. * @__state: &struct drm_atomic_state pointer
  894. * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
  895. * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
  896. * state
  897. * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
  898. * state
  899. * @__i: int iteration cursor, for macro-internal use
  900. *
  901. * This iterates over all DRM DP MST topology managers in an atomic update,
  902. * tracking both old and new state. This is useful in places where the state
  903. * delta needs to be considered, for example in atomic check functions.
  904. */
  905. #define for_each_oldnew_mst_mgr_in_state(__state, mgr, old_state, new_state, __i) \
  906. for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
  907. for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), &(new_state), (__i)))
  908. /**
  909. * for_each_old_mst_mgr_in_state - iterate over all DP MST topology managers
  910. * in an atomic update
  911. * @__state: &struct drm_atomic_state pointer
  912. * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
  913. * @old_state: &struct drm_dp_mst_topology_state iteration cursor for the old
  914. * state
  915. * @__i: int iteration cursor, for macro-internal use
  916. *
  917. * This iterates over all DRM DP MST topology managers in an atomic update,
  918. * tracking only the old state. This is useful in disable functions, where we
  919. * need the old state the hardware is still in.
  920. */
  921. #define for_each_old_mst_mgr_in_state(__state, mgr, old_state, __i) \
  922. for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
  923. for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), &(old_state), NULL, (__i)))
  924. /**
  925. * for_each_new_mst_mgr_in_state - iterate over all DP MST topology managers
  926. * in an atomic update
  927. * @__state: &struct drm_atomic_state pointer
  928. * @mgr: &struct drm_dp_mst_topology_mgr iteration cursor
  929. * @new_state: &struct drm_dp_mst_topology_state iteration cursor for the new
  930. * state
  931. * @__i: int iteration cursor, for macro-internal use
  932. *
  933. * This iterates over all DRM DP MST topology managers in an atomic update,
  934. * tracking only the new state. This is useful in enable functions, where we
  935. * need the new state the hardware should be in when the atomic commit
  936. * operation has completed.
  937. */
  938. #define for_each_new_mst_mgr_in_state(__state, mgr, new_state, __i) \
  939. for ((__i) = 0; (__i) < (__state)->num_private_objs; (__i)++) \
  940. for_each_if(__drm_dp_mst_state_iter_get((__state), &(mgr), NULL, &(new_state), (__i)))
  941. #endif