/* * Copyright © 2014 Red Hat * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that copyright * notice and this permission notice appear in supporting documentation, and * that the name of the copyright holders not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. The copyright holders make no representations * about the suitability of this software for any purpose. It is provided "as * is" without express or implied warranty. * * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. */ #include <linux/bitfield.h> #include <linux/delay.h> #include <linux/errno.h> #include <linux/i2c.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/random.h> #include <linux/sched.h> #include <linux/seq_file.h> #include <linux/iopoll.h> #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS) #include <linux/stacktrace.h> #include <linux/sort.h> #include <linux/timekeeping.h> #include <linux/math64.h> #endif #include <drm/display/drm_dp_mst_helper.h> #include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> #include <drm/drm_drv.h> #include <drm/drm_edid.h> #include <drm/drm_fixed.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h> #include "drm_dp_helper_internal.h" #include "drm_dp_mst_topology_internal.h" /** * DOC: dp mst helper * * These functions contain parts of the DisplayPort 1.2a MultiStream Transport * protocol. The helpers contain a topology manager and bandwidth manager. * The helpers encapsulate the sending and received of sideband msgs. */ struct drm_dp_pending_up_req { … }; static bool dump_dp_payload_table(struct drm_dp_mst_topology_mgr *mgr, char *buf); static void drm_dp_mst_topology_put_port(struct drm_dp_mst_port *port); static int drm_dp_dpcd_write_payload(struct drm_dp_mst_topology_mgr *mgr, int id, u8 start_slot, u8 num_slots); static int drm_dp_send_dpcd_read(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int offset, int size, u8 *bytes); static int drm_dp_send_dpcd_write(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int offset, int size, u8 *bytes); static int drm_dp_send_link_address(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb); static void drm_dp_send_clear_payload_id_table(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb); static int drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb, struct drm_dp_mst_port *port); static bool drm_dp_validate_guid(struct drm_dp_mst_topology_mgr *mgr, u8 *guid); static int drm_dp_mst_register_i2c_bus(struct drm_dp_mst_port *port); static void drm_dp_mst_unregister_i2c_bus(struct drm_dp_mst_port *port); static void drm_dp_mst_kick_tx(struct drm_dp_mst_topology_mgr *mgr); static bool drm_dp_mst_port_downstream_of_branch(struct drm_dp_mst_port *port, struct drm_dp_mst_branch *branch); #define DBG_PREFIX … #define DP_STR(x) … static const char *drm_dp_mst_req_type_str(u8 req_type) { … } #undef DP_STR #define DP_STR(x) … static const char *drm_dp_mst_nak_reason_str(u8 nak_reason) { … } #undef DP_STR #define DP_STR(x) … static const char *drm_dp_mst_sideband_tx_state_str(int state) { … } static int drm_dp_mst_rad_to_str(const u8 rad[8], u8 lct, char *out, size_t len) { … } /* sideband msg handling */ static u8 drm_dp_msg_header_crc4(const uint8_t *data, size_t num_nibbles) { … } static u8 drm_dp_msg_data_crc4(const uint8_t *data, u8 number_of_bytes) { … } static inline u8 drm_dp_calc_sb_hdr_size(struct drm_dp_sideband_msg_hdr *hdr) { … } static void drm_dp_encode_sideband_msg_hdr(struct drm_dp_sideband_msg_hdr *hdr, u8 *buf, int *len) { … } static bool drm_dp_decode_sideband_msg_hdr(const struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_sideband_msg_hdr *hdr, u8 *buf, int buflen, u8 *hdrlen) { … } void drm_dp_encode_sideband_req(const struct drm_dp_sideband_msg_req_body *req, struct drm_dp_sideband_msg_tx *raw) { … } EXPORT_SYMBOL_FOR_TESTS_ONLY(…); /* Decode a sideband request we've encoded, mainly used for debugging */ int drm_dp_decode_sideband_req(const struct drm_dp_sideband_msg_tx *raw, struct drm_dp_sideband_msg_req_body *req) { … } EXPORT_SYMBOL_FOR_TESTS_ONLY(…); void drm_dp_dump_sideband_msg_req_body(const struct drm_dp_sideband_msg_req_body *req, int indent, struct drm_printer *printer) { … } EXPORT_SYMBOL_FOR_TESTS_ONLY(…); static inline void drm_dp_mst_dump_sideband_msg_tx(struct drm_printer *p, const struct drm_dp_sideband_msg_tx *txmsg) { … } static void drm_dp_crc_sideband_chunk_req(u8 *msg, u8 len) { … } static void drm_dp_encode_sideband_reply(struct drm_dp_sideband_msg_reply_body *rep, struct drm_dp_sideband_msg_tx *raw) { … } static int drm_dp_sideband_msg_set_header(struct drm_dp_sideband_msg_rx *msg, struct drm_dp_sideband_msg_hdr *hdr, u8 hdrlen) { … } /* this adds a chunk of msg to the builder to get the final msg */ static bool drm_dp_sideband_append_payload(struct drm_dp_sideband_msg_rx *msg, u8 *replybuf, u8 replybuflen) { … } static bool drm_dp_sideband_parse_link_address(const struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *repmsg) { … } static bool drm_dp_sideband_parse_remote_dpcd_read(struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *repmsg) { … } static bool drm_dp_sideband_parse_remote_dpcd_write(struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *repmsg) { … } static bool drm_dp_sideband_parse_remote_i2c_read_ack(struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *repmsg) { … } static bool drm_dp_sideband_parse_enum_path_resources_ack(struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *repmsg) { … } static bool drm_dp_sideband_parse_allocate_payload_ack(struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *repmsg) { … } static bool drm_dp_sideband_parse_query_payload_ack(struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *repmsg) { … } static bool drm_dp_sideband_parse_power_updown_phy_ack(struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *repmsg) { … } static bool drm_dp_sideband_parse_query_stream_enc_status( struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *repmsg) { … } static bool drm_dp_sideband_parse_reply(const struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_reply_body *msg) { … } static bool drm_dp_sideband_parse_connection_status_notify(const struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_req_body *msg) { … } static bool drm_dp_sideband_parse_resource_status_notify(const struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_req_body *msg) { … } static bool drm_dp_sideband_parse_req(const struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_sideband_msg_rx *raw, struct drm_dp_sideband_msg_req_body *msg) { … } static void build_dpcd_write(struct drm_dp_sideband_msg_tx *msg, u8 port_num, u32 offset, u8 num_bytes, u8 *bytes) { … } static void build_link_address(struct drm_dp_sideband_msg_tx *msg) { … } static void build_clear_payload_id_table(struct drm_dp_sideband_msg_tx *msg) { … } static int build_enum_path_resources(struct drm_dp_sideband_msg_tx *msg, int port_num) { … } static void build_allocate_payload(struct drm_dp_sideband_msg_tx *msg, int port_num, u8 vcpi, uint16_t pbn, u8 number_sdp_streams, u8 *sdp_stream_sink) { … } static void build_power_updown_phy(struct drm_dp_sideband_msg_tx *msg, int port_num, bool power_up) { … } static int build_query_stream_enc_status(struct drm_dp_sideband_msg_tx *msg, u8 stream_id, u8 *q_id) { … } static bool check_txmsg_state(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_sideband_msg_tx *txmsg) { … } static int drm_dp_mst_wait_tx_reply(struct drm_dp_mst_branch *mstb, struct drm_dp_sideband_msg_tx *txmsg) { … } static struct drm_dp_mst_branch *drm_dp_add_mst_branch_device(u8 lct, u8 *rad) { … } static void drm_dp_free_mst_branch_device(struct kref *kref) { … } /** * DOC: Branch device and port refcounting * * Topology refcount overview * ~~~~~~~~~~~~~~~~~~~~~~~~~~ * * The refcounting schemes for &struct drm_dp_mst_branch and &struct * drm_dp_mst_port are somewhat unusual. Both ports and branch devices have * two different kinds of refcounts: topology refcounts, and malloc refcounts. * * Topology refcounts are not exposed to drivers, and are handled internally * by the DP MST helpers. The helpers use them in order to prevent the * in-memory topology state from being changed in the middle of critical * operations like changing the internal state of payload allocations. This * means each branch and port will be considered to be connected to the rest * of the topology until its topology refcount reaches zero. Additionally, * for ports this means that their associated &struct drm_connector will stay * registered with userspace until the port's refcount reaches 0. * * Malloc refcount overview * ~~~~~~~~~~~~~~~~~~~~~~~~ * * Malloc references are used to keep a &struct drm_dp_mst_port or &struct * drm_dp_mst_branch allocated even after all of its topology references have * been dropped, so that the driver or MST helpers can safely access each * branch's last known state before it was disconnected from the topology. * When the malloc refcount of a port or branch reaches 0, the memory * allocation containing the &struct drm_dp_mst_branch or &struct * drm_dp_mst_port respectively will be freed. * * For &struct drm_dp_mst_branch, malloc refcounts are not currently exposed * to drivers. As of writing this documentation, there are no drivers that * have a usecase for accessing &struct drm_dp_mst_branch outside of the MST * helpers. Exposing this API to drivers in a race-free manner would take more * tweaking of the refcounting scheme, however patches are welcome provided * there is a legitimate driver usecase for this. * * Refcount relationships in a topology * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Let's take a look at why the relationship between topology and malloc * refcounts is designed the way it is. * * .. kernel-figure:: dp-mst/topology-figure-1.dot * * An example of topology and malloc refs in a DP MST topology with two * active payloads. Topology refcount increments are indicated by solid * lines, and malloc refcount increments are indicated by dashed lines. * Each starts from the branch which incremented the refcount, and ends at * the branch to which the refcount belongs to, i.e. the arrow points the * same way as the C pointers used to reference a structure. * * As you can see in the above figure, every branch increments the topology * refcount of its children, and increments the malloc refcount of its * parent. Additionally, every payload increments the malloc refcount of its * assigned port by 1. * * So, what would happen if MSTB #3 from the above figure was unplugged from * the system, but the driver hadn't yet removed payload #2 from port #3? The * topology would start to look like the figure below. * * .. kernel-figure:: dp-mst/topology-figure-2.dot * * Ports and branch devices which have been released from memory are * colored grey, and references which have been removed are colored red. * * Whenever a port or branch device's topology refcount reaches zero, it will * decrement the topology refcounts of all its children, the malloc refcount * of its parent, and finally its own malloc refcount. For MSTB #4 and port * #4, this means they both have been disconnected from the topology and freed * from memory. But, because payload #2 is still holding a reference to port * #3, port #3 is removed from the topology but its &struct drm_dp_mst_port * is still accessible from memory. This also means port #3 has not yet * decremented the malloc refcount of MSTB #3, so its &struct * drm_dp_mst_branch will also stay allocated in memory until port #3's * malloc refcount reaches 0. * * This relationship is necessary because in order to release payload #2, we * need to be able to figure out the last relative of port #3 that's still * connected to the topology. In this case, we would travel up the topology as * shown below. * * .. kernel-figure:: dp-mst/topology-figure-3.dot * * And finally, remove payload #2 by communicating with port #2 through * sideband transactions. */ /** * drm_dp_mst_get_mstb_malloc() - Increment the malloc refcount of a branch * device * @mstb: The &struct drm_dp_mst_branch to increment the malloc refcount of * * Increments &drm_dp_mst_branch.malloc_kref. When * &drm_dp_mst_branch.malloc_kref reaches 0, the memory allocation for @mstb * will be released and @mstb may no longer be used. * * See also: drm_dp_mst_put_mstb_malloc() */ static void drm_dp_mst_get_mstb_malloc(struct drm_dp_mst_branch *mstb) { … } /** * drm_dp_mst_put_mstb_malloc() - Decrement the malloc refcount of a branch * device * @mstb: The &struct drm_dp_mst_branch to decrement the malloc refcount of * * Decrements &drm_dp_mst_branch.malloc_kref. When * &drm_dp_mst_branch.malloc_kref reaches 0, the memory allocation for @mstb * will be released and @mstb may no longer be used. * * See also: drm_dp_mst_get_mstb_malloc() */ static void drm_dp_mst_put_mstb_malloc(struct drm_dp_mst_branch *mstb) { … } static void drm_dp_free_mst_port(struct kref *kref) { … } /** * drm_dp_mst_get_port_malloc() - Increment the malloc refcount of an MST port * @port: The &struct drm_dp_mst_port to increment the malloc refcount of * * Increments &drm_dp_mst_port.malloc_kref. When &drm_dp_mst_port.malloc_kref * reaches 0, the memory allocation for @port will be released and @port may * no longer be used. * * Because @port could potentially be freed at any time by the DP MST helpers * if &drm_dp_mst_port.malloc_kref reaches 0, including during a call to this * function, drivers that which to make use of &struct drm_dp_mst_port should * ensure that they grab at least one main malloc reference to their MST ports * in &drm_dp_mst_topology_cbs.add_connector. This callback is called before * there is any chance for &drm_dp_mst_port.malloc_kref to reach 0. * * See also: drm_dp_mst_put_port_malloc() */ void drm_dp_mst_get_port_malloc(struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_put_port_malloc() - Decrement the malloc refcount of an MST port * @port: The &struct drm_dp_mst_port to decrement the malloc refcount of * * Decrements &drm_dp_mst_port.malloc_kref. When &drm_dp_mst_port.malloc_kref * reaches 0, the memory allocation for @port will be released and @port may * no longer be used. * * See also: drm_dp_mst_get_port_malloc() */ void drm_dp_mst_put_port_malloc(struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); #if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS) #define STACK_DEPTH … static noinline void __topology_ref_save(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_topology_ref_history *history, enum drm_dp_mst_topology_ref_type type) { … } static int topology_ref_history_cmp(const void *a, const void *b) { … } static inline const char * topology_ref_type_to_str(enum drm_dp_mst_topology_ref_type type) { … } static void __dump_topology_ref_history(struct drm_device *drm, struct drm_dp_mst_topology_ref_history *history, void *ptr, const char *type_str) { … } static __always_inline void drm_dp_mst_dump_mstb_topology_history(struct drm_dp_mst_branch *mstb) { … } static __always_inline void drm_dp_mst_dump_port_topology_history(struct drm_dp_mst_port *port) { … } static __always_inline void save_mstb_topology_ref(struct drm_dp_mst_branch *mstb, enum drm_dp_mst_topology_ref_type type) { … } static __always_inline void save_port_topology_ref(struct drm_dp_mst_port *port, enum drm_dp_mst_topology_ref_type type) { … } static inline void topology_ref_history_lock(struct drm_dp_mst_topology_mgr *mgr) { … } static inline void topology_ref_history_unlock(struct drm_dp_mst_topology_mgr *mgr) { … } #else static inline void topology_ref_history_lock(struct drm_dp_mst_topology_mgr *mgr) {} static inline void topology_ref_history_unlock(struct drm_dp_mst_topology_mgr *mgr) {} static inline void drm_dp_mst_dump_mstb_topology_history(struct drm_dp_mst_branch *mstb) {} static inline void drm_dp_mst_dump_port_topology_history(struct drm_dp_mst_port *port) {} #define save_mstb_topology_ref … #define save_port_topology_ref … #endif struct drm_dp_mst_atomic_payload * drm_atomic_get_mst_payload_state(struct drm_dp_mst_topology_state *state, struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); static void drm_dp_destroy_mst_branch_device(struct kref *kref) { … } /** * drm_dp_mst_topology_try_get_mstb() - Increment the topology refcount of a * branch device unless it's zero * @mstb: &struct drm_dp_mst_branch to increment the topology refcount of * * Attempts to grab a topology reference to @mstb, if it hasn't yet been * removed from the topology (e.g. &drm_dp_mst_branch.topology_kref has * reached 0). Holding a topology reference implies that a malloc reference * will be held to @mstb as long as the user holds the topology reference. * * Care should be taken to ensure that the user has at least one malloc * reference to @mstb. If you already have a topology reference to @mstb, you * should use drm_dp_mst_topology_get_mstb() instead. * * See also: * drm_dp_mst_topology_get_mstb() * drm_dp_mst_topology_put_mstb() * * Returns: * * 1: A topology reference was grabbed successfully * * 0: @port is no longer in the topology, no reference was grabbed */ static int __must_check drm_dp_mst_topology_try_get_mstb(struct drm_dp_mst_branch *mstb) { … } /** * drm_dp_mst_topology_get_mstb() - Increment the topology refcount of a * branch device * @mstb: The &struct drm_dp_mst_branch to increment the topology refcount of * * Increments &drm_dp_mst_branch.topology_refcount without checking whether or * not it's already reached 0. This is only valid to use in scenarios where * you are already guaranteed to have at least one active topology reference * to @mstb. Otherwise, drm_dp_mst_topology_try_get_mstb() must be used. * * See also: * drm_dp_mst_topology_try_get_mstb() * drm_dp_mst_topology_put_mstb() */ static void drm_dp_mst_topology_get_mstb(struct drm_dp_mst_branch *mstb) { … } /** * drm_dp_mst_topology_put_mstb() - release a topology reference to a branch * device * @mstb: The &struct drm_dp_mst_branch to release the topology reference from * * Releases a topology reference from @mstb by decrementing * &drm_dp_mst_branch.topology_kref. * * See also: * drm_dp_mst_topology_try_get_mstb() * drm_dp_mst_topology_get_mstb() */ static void drm_dp_mst_topology_put_mstb(struct drm_dp_mst_branch *mstb) { … } static void drm_dp_destroy_port(struct kref *kref) { … } /** * drm_dp_mst_topology_try_get_port() - Increment the topology refcount of a * port unless it's zero * @port: &struct drm_dp_mst_port to increment the topology refcount of * * Attempts to grab a topology reference to @port, if it hasn't yet been * removed from the topology (e.g. &drm_dp_mst_port.topology_kref has reached * 0). Holding a topology reference implies that a malloc reference will be * held to @port as long as the user holds the topology reference. * * Care should be taken to ensure that the user has at least one malloc * reference to @port. If you already have a topology reference to @port, you * should use drm_dp_mst_topology_get_port() instead. * * See also: * drm_dp_mst_topology_get_port() * drm_dp_mst_topology_put_port() * * Returns: * * 1: A topology reference was grabbed successfully * * 0: @port is no longer in the topology, no reference was grabbed */ static int __must_check drm_dp_mst_topology_try_get_port(struct drm_dp_mst_port *port) { … } /** * drm_dp_mst_topology_get_port() - Increment the topology refcount of a port * @port: The &struct drm_dp_mst_port to increment the topology refcount of * * Increments &drm_dp_mst_port.topology_refcount without checking whether or * not it's already reached 0. This is only valid to use in scenarios where * you are already guaranteed to have at least one active topology reference * to @port. Otherwise, drm_dp_mst_topology_try_get_port() must be used. * * See also: * drm_dp_mst_topology_try_get_port() * drm_dp_mst_topology_put_port() */ static void drm_dp_mst_topology_get_port(struct drm_dp_mst_port *port) { … } /** * drm_dp_mst_topology_put_port() - release a topology reference to a port * @port: The &struct drm_dp_mst_port to release the topology reference from * * Releases a topology reference from @port by decrementing * &drm_dp_mst_port.topology_kref. * * See also: * drm_dp_mst_topology_try_get_port() * drm_dp_mst_topology_get_port() */ static void drm_dp_mst_topology_put_port(struct drm_dp_mst_port *port) { … } static struct drm_dp_mst_branch * drm_dp_mst_topology_get_mstb_validated_locked(struct drm_dp_mst_branch *mstb, struct drm_dp_mst_branch *to_find) { … } static struct drm_dp_mst_branch * drm_dp_mst_topology_get_mstb_validated(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb) { … } static struct drm_dp_mst_port * drm_dp_mst_topology_get_port_validated_locked(struct drm_dp_mst_branch *mstb, struct drm_dp_mst_port *to_find) { … } static struct drm_dp_mst_port * drm_dp_mst_topology_get_port_validated(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port) { … } static struct drm_dp_mst_port *drm_dp_get_port(struct drm_dp_mst_branch *mstb, u8 port_num) { … } /* * calculate a new RAD for this MST branch device * if parent has an LCT of 2 then it has 1 nibble of RAD, * if parent has an LCT of 3 then it has 2 nibbles of RAD, */ static u8 drm_dp_calculate_rad(struct drm_dp_mst_port *port, u8 *rad) { … } static bool drm_dp_mst_is_end_device(u8 pdt, bool mcs) { … } static int drm_dp_port_set_pdt(struct drm_dp_mst_port *port, u8 new_pdt, bool new_mcs) { … } /** * drm_dp_mst_dpcd_read() - read a series of bytes from the DPCD via sideband * @aux: Fake sideband AUX CH * @offset: address of the (first) register to read * @buffer: buffer to store the register values * @size: number of bytes in @buffer * * Performs the same functionality for remote devices via * sideband messaging as drm_dp_dpcd_read() does for local * devices via actual AUX CH. * * Return: Number of bytes read, or negative error code on failure. */ ssize_t drm_dp_mst_dpcd_read(struct drm_dp_aux *aux, unsigned int offset, void *buffer, size_t size) { … } /** * drm_dp_mst_dpcd_write() - write a series of bytes to the DPCD via sideband * @aux: Fake sideband AUX CH * @offset: address of the (first) register to write * @buffer: buffer containing the values to write * @size: number of bytes in @buffer * * Performs the same functionality for remote devices via * sideband messaging as drm_dp_dpcd_write() does for local * devices via actual AUX CH. * * Return: number of bytes written on success, negative error code on failure. */ ssize_t drm_dp_mst_dpcd_write(struct drm_dp_aux *aux, unsigned int offset, void *buffer, size_t size) { … } static int drm_dp_check_mstb_guid(struct drm_dp_mst_branch *mstb, u8 *guid) { … } static void build_mst_prop_path(const struct drm_dp_mst_branch *mstb, int pnum, char *proppath, size_t proppath_size) { … } /** * drm_dp_mst_connector_late_register() - Late MST connector registration * @connector: The MST connector * @port: The MST port for this connector * * Helper to register the remote aux device for this MST port. Drivers should * call this from their mst connector's late_register hook to enable MST aux * devices. * * Return: 0 on success, negative error code on failure. */ int drm_dp_mst_connector_late_register(struct drm_connector *connector, struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_connector_early_unregister() - Early MST connector unregistration * @connector: The MST connector * @port: The MST port for this connector * * Helper to unregister the remote aux device for this MST port, registered by * drm_dp_mst_connector_late_register(). Drivers should call this from their mst * connector's early_unregister hook. */ void drm_dp_mst_connector_early_unregister(struct drm_connector *connector, struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); static void drm_dp_mst_port_add_connector(struct drm_dp_mst_branch *mstb, struct drm_dp_mst_port *port) { … } /* * Drop a topology reference, and unlink the port from the in-memory topology * layout */ static void drm_dp_mst_topology_unlink_port(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port) { … } static struct drm_dp_mst_port * drm_dp_mst_add_port(struct drm_device *dev, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb, u8 port_number) { … } static int drm_dp_mst_handle_link_address_port(struct drm_dp_mst_branch *mstb, struct drm_device *dev, struct drm_dp_link_addr_reply_port *port_msg) { … } static int drm_dp_mst_handle_conn_stat(struct drm_dp_mst_branch *mstb, struct drm_dp_connection_status_notify *conn_stat) { … } static struct drm_dp_mst_branch *drm_dp_get_mst_branch_device(struct drm_dp_mst_topology_mgr *mgr, u8 lct, u8 *rad) { … } static struct drm_dp_mst_branch *get_mst_branch_device_by_guid_helper( struct drm_dp_mst_branch *mstb, const uint8_t *guid) { … } static struct drm_dp_mst_branch * drm_dp_get_mst_branch_device_by_guid(struct drm_dp_mst_topology_mgr *mgr, const uint8_t *guid) { … } static int drm_dp_check_and_send_link_address(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb) { … } static void drm_dp_mst_link_probe_work(struct work_struct *work) { … } static bool drm_dp_validate_guid(struct drm_dp_mst_topology_mgr *mgr, u8 *guid) { … } static void build_dpcd_read(struct drm_dp_sideband_msg_tx *msg, u8 port_num, u32 offset, u8 num_bytes) { … } static int drm_dp_send_sideband_msg(struct drm_dp_mst_topology_mgr *mgr, bool up, u8 *msg, int len) { … } static int set_hdr_from_dst_qlock(struct drm_dp_sideband_msg_hdr *hdr, struct drm_dp_sideband_msg_tx *txmsg) { … } /* * process a single block of the next message in the sideband queue */ static int process_single_tx_qlock(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_sideband_msg_tx *txmsg, bool up) { … } static void process_single_down_tx_qlock(struct drm_dp_mst_topology_mgr *mgr) { … } static void drm_dp_queue_down_tx(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_sideband_msg_tx *txmsg) { … } static void drm_dp_dump_link_address(const struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_link_address_ack_reply *reply) { … } static int drm_dp_send_link_address(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb) { … } static void drm_dp_send_clear_payload_id_table(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb) { … } static int drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb, struct drm_dp_mst_port *port) { … } static struct drm_dp_mst_port *drm_dp_get_last_connected_port_to_mstb(struct drm_dp_mst_branch *mstb) { … } /* * Searches upwards in the topology starting from mstb to try to find the * closest available parent of mstb that's still connected to the rest of the * topology. This can be used in order to perform operations like releasing * payloads, where the branch device which owned the payload may no longer be * around and thus would require that the payload on the last living relative * be freed instead. */ static struct drm_dp_mst_branch * drm_dp_get_last_connected_port_and_mstb(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb, int *port_num) { … } static int drm_dp_payload_send_msg(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int id, int pbn) { … } int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, bool power_up) { … } EXPORT_SYMBOL(…); int drm_dp_send_query_stream_enc_status(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, struct drm_dp_query_stream_enc_status_ack_reply *status) { … } EXPORT_SYMBOL(…); static int drm_dp_create_payload_at_dfp(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_atomic_payload *payload) { … } static int drm_dp_create_payload_to_remote(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_atomic_payload *payload) { … } static void drm_dp_destroy_payload_at_remote_and_dfp(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_topology_state *mst_state, struct drm_dp_mst_atomic_payload *payload) { … } /** * drm_dp_add_payload_part1() - Execute payload update part 1 * @mgr: Manager to use. * @mst_state: The MST atomic state * @payload: The payload to write * * Determines the starting time slot for the given payload, and programs the VCPI for this payload * into the DPCD of DPRX. After calling this, the driver should generate ACT and payload packets. * * Returns: 0 on success, error code on failure. */ int drm_dp_add_payload_part1(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_topology_state *mst_state, struct drm_dp_mst_atomic_payload *payload) { … } EXPORT_SYMBOL(…); /** * drm_dp_remove_payload_part1() - Remove an MST payload along the virtual channel * @mgr: Manager to use. * @mst_state: The MST atomic state * @payload: The payload to remove * * Removes a payload along the virtual channel if it was successfully allocated. * After calling this, the driver should set HW to generate ACT and then switch to new * payload allocation state. */ void drm_dp_remove_payload_part1(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_topology_state *mst_state, struct drm_dp_mst_atomic_payload *payload) { … } EXPORT_SYMBOL(…); /** * drm_dp_remove_payload_part2() - Remove an MST payload locally * @mgr: Manager to use. * @mst_state: The MST atomic state * @old_payload: The payload with its old state * @new_payload: The payload with its latest state * * Updates the starting time slots of all other payloads which would have been shifted towards * the start of the payload ID table as a result of removing a payload. Driver should call this * function whenever it removes a payload in its HW. It's independent to the result of payload * allocation/deallocation at branch devices along the virtual channel. */ void drm_dp_remove_payload_part2(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_topology_state *mst_state, const struct drm_dp_mst_atomic_payload *old_payload, struct drm_dp_mst_atomic_payload *new_payload) { … } EXPORT_SYMBOL(…); /** * drm_dp_add_payload_part2() - Execute payload update part 2 * @mgr: Manager to use. * @payload: The payload to update * * If @payload was successfully assigned a starting time slot by drm_dp_add_payload_part1(), this * function will send the sideband messages to finish allocating this payload. * * Returns: 0 on success, negative error code on failure. */ int drm_dp_add_payload_part2(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_atomic_payload *payload) { … } EXPORT_SYMBOL(…); static int drm_dp_send_dpcd_read(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int offset, int size, u8 *bytes) { … } static int drm_dp_send_dpcd_write(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int offset, int size, u8 *bytes) { … } static int drm_dp_encode_up_ack_reply(struct drm_dp_sideband_msg_tx *msg, u8 req_type) { … } static int drm_dp_send_up_ack_reply(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_branch *mstb, int req_type, bool broadcast) { … } /** * drm_dp_get_vc_payload_bw - get the VC payload BW for an MST link * @mgr: The &drm_dp_mst_topology_mgr to use * @link_rate: link rate in 10kbits/s units * @link_lane_count: lane count * * Calculate the total bandwidth of a MultiStream Transport link. The returned * value is in units of PBNs/(timeslots/1 MTP). This value can be used to * convert the number of PBNs required for a given stream to the number of * timeslots this stream requires in each MTP. * * Returns the BW / timeslot value in 20.12 fixed point format. */ fixed20_12 drm_dp_get_vc_payload_bw(const struct drm_dp_mst_topology_mgr *mgr, int link_rate, int link_lane_count) { … } EXPORT_SYMBOL(…); /** * drm_dp_read_mst_cap() - Read the sink's MST mode capability * @aux: The DP AUX channel to use * @dpcd: A cached copy of the DPCD capabilities for this sink * * Returns: enum drm_dp_mst_mode to indicate MST mode capability */ enum drm_dp_mst_mode drm_dp_read_mst_cap(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_topology_mgr_set_mst() - Set the MST state for a topology manager * @mgr: manager to set state for * @mst_state: true to enable MST on this connector - false to disable. * * This is called by the driver when it detects an MST capable device plugged * into a DP MST capable port, or when a DP MST capable device is unplugged. */ int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state) { … } EXPORT_SYMBOL(…); static void drm_dp_mst_topology_mgr_invalidate_mstb(struct drm_dp_mst_branch *mstb) { … } /** * drm_dp_mst_topology_mgr_suspend() - suspend the MST manager * @mgr: manager to suspend * * This function tells the MST device that we can't handle UP messages * anymore. This should stop it from sending any since we are suspended. */ void drm_dp_mst_topology_mgr_suspend(struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_topology_mgr_resume() - resume the MST manager * @mgr: manager to resume * @sync: whether or not to perform topology reprobing synchronously * * This will fetch DPCD and see if the device is still there, * if it is, it will rewrite the MSTM control bits, and return. * * If the device fails this returns -1, and the driver should do * a full MST reprobe, in case we were undocked. * * During system resume (where it is assumed that the driver will be calling * drm_atomic_helper_resume()) this function should be called beforehand with * @sync set to true. In contexts like runtime resume where the driver is not * expected to be calling drm_atomic_helper_resume(), this function should be * called with @sync set to false in order to avoid deadlocking. * * Returns: -1 if the MST topology was removed while we were suspended, 0 * otherwise. */ int drm_dp_mst_topology_mgr_resume(struct drm_dp_mst_topology_mgr *mgr, bool sync) { … } EXPORT_SYMBOL(…); static bool drm_dp_get_one_sb_msg(struct drm_dp_mst_topology_mgr *mgr, bool up, struct drm_dp_mst_branch **mstb) { … } static int drm_dp_mst_handle_down_rep(struct drm_dp_mst_topology_mgr *mgr) { … } static inline bool drm_dp_mst_process_up_req(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_pending_up_req *up_req) { … } static void drm_dp_mst_up_req_work(struct work_struct *work) { … } static int drm_dp_mst_handle_up_req(struct drm_dp_mst_topology_mgr *mgr) { … } /** * drm_dp_mst_hpd_irq_handle_event() - MST hotplug IRQ handle MST event * @mgr: manager to notify irq for. * @esi: 4 bytes from SINK_COUNT_ESI * @ack: 4 bytes used to ack events starting from SINK_COUNT_ESI * @handled: whether the hpd interrupt was consumed or not * * This should be called from the driver when it detects a HPD IRQ, * along with the value of the DEVICE_SERVICE_IRQ_VECTOR_ESI0. The * topology manager will process the sideband messages received * as indicated in the DEVICE_SERVICE_IRQ_VECTOR_ESI0 and set the * corresponding flags that Driver has to ack the DP receiver later. * * Note that driver shall also call * drm_dp_mst_hpd_irq_send_new_request() if the 'handled' is set * after calling this function, to try to kick off a new request in * the queue if the previous message transaction is completed. * * See also: * drm_dp_mst_hpd_irq_send_new_request() */ int drm_dp_mst_hpd_irq_handle_event(struct drm_dp_mst_topology_mgr *mgr, const u8 *esi, u8 *ack, bool *handled) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_hpd_irq_send_new_request() - MST hotplug IRQ kick off new request * @mgr: manager to notify irq for. * * This should be called from the driver when mst irq event is handled * and acked. Note that new down request should only be sent when * previous message transaction is completed. Source is not supposed to generate * interleaved message transactions. */ void drm_dp_mst_hpd_irq_send_new_request(struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_detect_port() - get connection status for an MST port * @connector: DRM connector for this port * @ctx: The acquisition context to use for grabbing locks * @mgr: manager for this port * @port: pointer to a port * * This returns the current connection state for a port. */ int drm_dp_mst_detect_port(struct drm_connector *connector, struct drm_modeset_acquire_ctx *ctx, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_edid_read() - get EDID for an MST port * @connector: toplevel connector to get EDID for * @mgr: manager for this port * @port: unverified pointer to a port. * * This returns an EDID for the port connected to a connector, * It validates the pointer still exists so the caller doesn't require a * reference. */ const struct drm_edid *drm_dp_mst_edid_read(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_get_edid() - get EDID for an MST port * @connector: toplevel connector to get EDID for * @mgr: manager for this port * @port: unverified pointer to a port. * * This function is deprecated; please use drm_dp_mst_edid_read() instead. * * This returns an EDID for the port connected to a connector, * It validates the pointer still exists so the caller doesn't require a * reference. */ struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); /** * drm_dp_atomic_find_time_slots() - Find and add time slots to the state * @state: global atomic state * @mgr: MST topology manager for the port * @port: port to find time slots for * @pbn: bandwidth required for the mode in PBN * * Allocates time slots to @port, replacing any previous time slot allocations it may * have had. Any atomic drivers which support MST must call this function in * their &drm_encoder_helper_funcs.atomic_check() callback unconditionally to * change the current time slot allocation for the new state, and ensure the MST * atomic state is added whenever the state of payloads in the topology changes. * * Allocations set by this function are not checked against the bandwidth * restraints of @mgr until the driver calls drm_dp_mst_atomic_check(). * * Additionally, it is OK to call this function multiple times on the same * @port as needed. It is not OK however, to call this function and * drm_dp_atomic_release_time_slots() in the same atomic check phase. * * See also: * drm_dp_atomic_release_time_slots() * drm_dp_mst_atomic_check() * * Returns: * Total slots in the atomic state assigned for this port, or a negative error * code if the port no longer exists */ int drm_dp_atomic_find_time_slots(struct drm_atomic_state *state, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int pbn) { … } EXPORT_SYMBOL(…); /** * drm_dp_atomic_release_time_slots() - Release allocated time slots * @state: global atomic state * @mgr: MST topology manager for the port * @port: The port to release the time slots from * * Releases any time slots that have been allocated to a port in the atomic * state. Any atomic drivers which support MST must call this function * unconditionally in their &drm_connector_helper_funcs.atomic_check() callback. * This helper will check whether time slots would be released by the new state and * respond accordingly, along with ensuring the MST state is always added to the * atomic state whenever a new state would modify the state of payloads on the * topology. * * It is OK to call this even if @port has been removed from the system. * Additionally, it is OK to call this function multiple times on the same * @port as needed. It is not OK however, to call this function and * drm_dp_atomic_find_time_slots() on the same @port in a single atomic check * phase. * * See also: * drm_dp_atomic_find_time_slots() * drm_dp_mst_atomic_check() * * Returns: * 0 on success, negative error code otherwise */ int drm_dp_atomic_release_time_slots(struct drm_atomic_state *state, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_atomic_setup_commit() - setup_commit hook for MST helpers * @state: global atomic state * * This function saves all of the &drm_crtc_commit structs in an atomic state that touch any CRTCs * currently assigned to an MST topology. Drivers must call this hook from their * &drm_mode_config_helper_funcs.atomic_commit_setup hook. * * Returns: * 0 if all CRTC commits were retrieved successfully, negative error code otherwise */ int drm_dp_mst_atomic_setup_commit(struct drm_atomic_state *state) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_atomic_wait_for_dependencies() - Wait for all pending commits on MST topologies, * prepare new MST state for commit * @state: global atomic state * * Goes through any MST topologies in this atomic state, and waits for any pending commits which * touched CRTCs that were/are on an MST topology to be programmed to hardware and flipped to before * returning. This is to prevent multiple non-blocking commits affecting an MST topology from racing * with eachother by forcing them to be executed sequentially in situations where the only resources * the modeset objects in these commits share are an MST topology. * * This function also prepares the new MST state for commit by performing some state preparation * which can't be done until this point, such as reading back the final VC start slots (which are * determined at commit-time) from the previous state. * * All MST drivers must call this function after calling drm_atomic_helper_wait_for_dependencies(), * or whatever their equivalent of that is. */ void drm_dp_mst_atomic_wait_for_dependencies(struct drm_atomic_state *state) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_root_conn_atomic_check() - Serialize CRTC commits on MST-capable connectors operating * in SST mode * @new_conn_state: The new connector state of the &drm_connector * @mgr: The MST topology manager for the &drm_connector * * Since MST uses fake &drm_encoder structs, the generic atomic modesetting code isn't able to * serialize non-blocking commits happening on the real DP connector of an MST topology switching * into/away from MST mode - as the CRTC on the real DP connector and the CRTCs on the connector's * MST topology will never share the same &drm_encoder. * * This function takes care of this serialization issue, by checking a root MST connector's atomic * state to determine if it is about to have a modeset - and then pulling in the MST topology state * if so, along with adding any relevant CRTCs to &drm_dp_mst_topology_state.pending_crtc_mask. * * Drivers implementing MST must call this function from the * &drm_connector_helper_funcs.atomic_check hook of any physical DP &drm_connector capable of * driving MST sinks. * * Returns: * 0 on success, negative error code otherwise */ int drm_dp_mst_root_conn_atomic_check(struct drm_connector_state *new_conn_state, struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_update_slots() - updates the slot info depending on the DP ecoding format * @mst_state: mst_state to update * @link_encoding_cap: the ecoding format on the link */ void drm_dp_mst_update_slots(struct drm_dp_mst_topology_state *mst_state, uint8_t link_encoding_cap) { … } EXPORT_SYMBOL(…); static int drm_dp_dpcd_write_payload(struct drm_dp_mst_topology_mgr *mgr, int id, u8 start_slot, u8 num_slots) { … } static int do_get_act_status(struct drm_dp_aux *aux) { … } /** * drm_dp_check_act_status() - Polls for ACT handled status. * @mgr: manager to use * * Tries waiting for the MST hub to finish updating it's payload table by * polling for the ACT handled bit for up to 3 seconds (yes-some hubs really * take that long). * * Returns: * 0 if the ACT was handled in time, negative error code on failure. */ int drm_dp_check_act_status(struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); /** * drm_dp_calc_pbn_mode() - Calculate the PBN for a mode. * @clock: dot clock * @bpp: bpp as .4 binary fixed point * * This uses the formula in the spec to calculate the PBN value for a mode. */ int drm_dp_calc_pbn_mode(int clock, int bpp) { … } EXPORT_SYMBOL(…); /* we want to kick the TX after we've ack the up/down IRQs. */ static void drm_dp_mst_kick_tx(struct drm_dp_mst_topology_mgr *mgr) { … } /* * Helper function for parsing DP device types into convenient strings * for use with dp_mst_topology */ static const char *pdt_to_string(u8 pdt) { … } static void drm_dp_mst_dump_mstb(struct seq_file *m, struct drm_dp_mst_branch *mstb) { … } #define DP_PAYLOAD_TABLE_SIZE … static bool dump_dp_payload_table(struct drm_dp_mst_topology_mgr *mgr, char *buf) { … } static void fetch_monitor_name(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, char *name, int namelen) { … } /** * drm_dp_mst_dump_topology(): dump topology to seq file. * @m: seq_file to dump output to * @mgr: manager to dump current topology for. * * helper to dump MST topology to a seq file for debugfs. */ void drm_dp_mst_dump_topology(struct seq_file *m, struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); static void drm_dp_tx_work(struct work_struct *work) { … } static inline void drm_dp_delayed_destroy_port(struct drm_dp_mst_port *port) { … } static inline void drm_dp_delayed_destroy_mstb(struct drm_dp_mst_branch *mstb) { … } static void drm_dp_delayed_destroy_work(struct work_struct *work) { … } static struct drm_private_state * drm_dp_mst_duplicate_state(struct drm_private_obj *obj) { … } static void drm_dp_mst_destroy_state(struct drm_private_obj *obj, struct drm_private_state *state) { … } static bool drm_dp_mst_port_downstream_of_branch(struct drm_dp_mst_port *port, struct drm_dp_mst_branch *branch) { … } static bool drm_dp_mst_port_downstream_of_parent_locked(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, struct drm_dp_mst_port *parent) { … } /** * drm_dp_mst_port_downstream_of_parent - check if a port is downstream of a parent port * @mgr: MST topology manager * @port: the port being looked up * @parent: the parent port * * The function returns %true if @port is downstream of @parent. If @parent is * %NULL - denoting the root port - the function returns %true if @port is in * @mgr's topology. */ bool drm_dp_mst_port_downstream_of_parent(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, struct drm_dp_mst_port *parent) { … } EXPORT_SYMBOL(…); static int drm_dp_mst_atomic_check_port_bw_limit(struct drm_dp_mst_port *port, struct drm_dp_mst_topology_state *state, struct drm_dp_mst_port **failing_port); static int drm_dp_mst_atomic_check_mstb_bw_limit(struct drm_dp_mst_branch *mstb, struct drm_dp_mst_topology_state *state, struct drm_dp_mst_port **failing_port) { … } static int drm_dp_mst_atomic_check_port_bw_limit(struct drm_dp_mst_port *port, struct drm_dp_mst_topology_state *state, struct drm_dp_mst_port **failing_port) { … } static inline int drm_dp_mst_atomic_check_payload_alloc_limits(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_topology_state *mst_state) { … } /** * drm_dp_mst_add_affected_dsc_crtcs * @state: Pointer to the new struct drm_dp_mst_topology_state * @mgr: MST topology manager * * Whenever there is a change in mst topology * DSC configuration would have to be recalculated * therefore we need to trigger modeset on all affected * CRTCs in that topology * * See also: * drm_dp_mst_atomic_enable_dsc() */ int drm_dp_mst_add_affected_dsc_crtcs(struct drm_atomic_state *state, struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_atomic_enable_dsc - Set DSC Enable Flag to On/Off * @state: Pointer to the new drm_atomic_state * @port: Pointer to the affected MST Port * @pbn: Newly recalculated bw required for link with DSC enabled * @enable: Boolean flag to enable or disable DSC on the port * * This function enables DSC on the given Port * by recalculating its vcpi from pbn provided * and sets dsc_enable flag to keep track of which * ports have DSC enabled * */ int drm_dp_mst_atomic_enable_dsc(struct drm_atomic_state *state, struct drm_dp_mst_port *port, int pbn, bool enable) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_atomic_check_mgr - Check the atomic state of an MST topology manager * @state: The global atomic state * @mgr: Manager to check * @mst_state: The MST atomic state for @mgr * @failing_port: Returns the port with a BW limitation * * Checks the given MST manager's topology state for an atomic update to ensure * that it's valid. This includes checking whether there's enough bandwidth to * support the new timeslot allocations in the atomic update. * * Any atomic drivers supporting DP MST must make sure to call this or * the drm_dp_mst_atomic_check() function after checking the rest of their state * in their &drm_mode_config_funcs.atomic_check() callback. * * See also: * drm_dp_mst_atomic_check() * drm_dp_atomic_find_time_slots() * drm_dp_atomic_release_time_slots() * * Returns: * - 0 if the new state is valid * - %-ENOSPC, if the new state is invalid, because of BW limitation * @failing_port is set to: * * - The non-root port where a BW limit check failed * with all the ports downstream of @failing_port passing * the BW limit check. * The returned port pointer is valid until at least * one payload downstream of it exists. * - %NULL if the BW limit check failed at the root port * with all the ports downstream of the root port passing * the BW limit check. * * - %-EINVAL, if the new state is invalid, because the root port has * too many payloads. */ int drm_dp_mst_atomic_check_mgr(struct drm_atomic_state *state, struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_topology_state *mst_state, struct drm_dp_mst_port **failing_port) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_atomic_check - Check that the new state of an MST topology in an * atomic update is valid * @state: Pointer to the new &struct drm_dp_mst_topology_state * * Checks the given topology state for an atomic update to ensure that it's * valid, calling drm_dp_mst_atomic_check_mgr() for all MST manager in the * atomic state. This includes checking whether there's enough bandwidth to * support the new timeslot allocations in the atomic update. * * Any atomic drivers supporting DP MST must make sure to call this after * checking the rest of their state in their * &drm_mode_config_funcs.atomic_check() callback. * * See also: * drm_dp_mst_atomic_check_mgr() * drm_dp_atomic_find_time_slots() * drm_dp_atomic_release_time_slots() * * Returns: * * 0 if the new state is valid, negative error code otherwise. */ int drm_dp_mst_atomic_check(struct drm_atomic_state *state) { … } EXPORT_SYMBOL(…); const struct drm_private_state_funcs drm_dp_mst_topology_state_funcs = …; EXPORT_SYMBOL(…); /** * drm_atomic_get_mst_topology_state: get MST topology state * @state: global atomic state * @mgr: MST topology manager, also the private object in this case * * This function wraps drm_atomic_get_priv_obj_state() passing in the MST atomic * state vtable so that the private object state returned is that of a MST * topology object. * * RETURNS: * * The MST topology state or error pointer. */ struct drm_dp_mst_topology_state *drm_atomic_get_mst_topology_state(struct drm_atomic_state *state, struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); /** * drm_atomic_get_old_mst_topology_state: get old MST topology state in atomic state, if any * @state: global atomic state * @mgr: MST topology manager, also the private object in this case * * This function wraps drm_atomic_get_old_private_obj_state() passing in the MST atomic * state vtable so that the private object state returned is that of a MST * topology object. * * Returns: * * The old MST topology state, or NULL if there's no topology state for this MST mgr * in the global atomic state */ struct drm_dp_mst_topology_state * drm_atomic_get_old_mst_topology_state(struct drm_atomic_state *state, struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); /** * drm_atomic_get_new_mst_topology_state: get new MST topology state in atomic state, if any * @state: global atomic state * @mgr: MST topology manager, also the private object in this case * * This function wraps drm_atomic_get_new_private_obj_state() passing in the MST atomic * state vtable so that the private object state returned is that of a MST * topology object. * * Returns: * * The new MST topology state, or NULL if there's no topology state for this MST mgr * in the global atomic state */ struct drm_dp_mst_topology_state * drm_atomic_get_new_mst_topology_state(struct drm_atomic_state *state, struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_topology_mgr_init - initialise a topology manager * @mgr: manager struct to initialise * @dev: device providing this structure - for i2c addition. * @aux: DP helper aux channel to talk to this device * @max_dpcd_transaction_bytes: hw specific DPCD transaction limit * @max_payloads: maximum number of payloads this GPU can source * @conn_base_id: the connector object ID the MST device is connected to. * * Return 0 for success, or negative error code on failure */ int drm_dp_mst_topology_mgr_init(struct drm_dp_mst_topology_mgr *mgr, struct drm_device *dev, struct drm_dp_aux *aux, int max_dpcd_transaction_bytes, int max_payloads, int conn_base_id) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_topology_mgr_destroy() - destroy topology manager. * @mgr: manager to destroy */ void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr) { … } EXPORT_SYMBOL(…); static bool remote_i2c_read_ok(const struct i2c_msg msgs[], int num) { … } static bool remote_i2c_write_ok(const struct i2c_msg msgs[], int num) { … } static int drm_dp_mst_i2c_read(struct drm_dp_mst_branch *mstb, struct drm_dp_mst_port *port, struct i2c_msg *msgs, int num) { … } static int drm_dp_mst_i2c_write(struct drm_dp_mst_branch *mstb, struct drm_dp_mst_port *port, struct i2c_msg *msgs, int num) { … } /* I2C device */ static int drm_dp_mst_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num) { … } static u32 drm_dp_mst_i2c_functionality(struct i2c_adapter *adapter) { … } static const struct i2c_algorithm drm_dp_mst_i2c_algo = …; /** * drm_dp_mst_register_i2c_bus() - register an I2C adapter for I2C-over-AUX * @port: The port to add the I2C bus on * * Returns 0 on success or a negative error code on failure. */ static int drm_dp_mst_register_i2c_bus(struct drm_dp_mst_port *port) { … } /** * drm_dp_mst_unregister_i2c_bus() - unregister an I2C-over-AUX adapter * @port: The port to remove the I2C bus from */ static void drm_dp_mst_unregister_i2c_bus(struct drm_dp_mst_port *port) { … } /** * drm_dp_mst_is_virtual_dpcd() - Is the given port a virtual DP Peer Device * @port: The port to check * * A single physical MST hub object can be represented in the topology * by multiple branches, with virtual ports between those branches. * * As of DP1.4, An MST hub with internal (virtual) ports must expose * certain DPCD registers over those ports. See sections 2.6.1.1.1 * and 2.6.1.1.2 of Display Port specification v1.4 for details. * * May acquire mgr->lock * * Returns: * true if the port is a virtual DP peer device, false otherwise */ static bool drm_dp_mst_is_virtual_dpcd(struct drm_dp_mst_port *port) { … } /** * drm_dp_mst_aux_for_parent() - Get the AUX device for an MST port's parent * @port: MST port whose parent's AUX device is returned * * Return the AUX device for @port's parent or NULL if port's parent is the * root port. */ struct drm_dp_aux *drm_dp_mst_aux_for_parent(struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…); /** * drm_dp_mst_dsc_aux_for_port() - Find the correct aux for DSC * @port: The port to check. A leaf of the MST tree with an attached display. * * Depending on the situation, DSC may be enabled via the endpoint aux, * the immediately upstream aux, or the connector's physical aux. * * This is both the correct aux to read DSC_CAPABILITY and the * correct aux to write DSC_ENABLED. * * This operation can be expensive (up to four aux reads), so * the caller should cache the return. * * Returns: * NULL if DSC cannot be enabled on this port, otherwise the aux device */ struct drm_dp_aux *drm_dp_mst_dsc_aux_for_port(struct drm_dp_mst_port *port) { … } EXPORT_SYMBOL(…);