1 /* 2 * Copyright 2021 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 #ifndef DC_INC_LINK_DP_DPIA_BW_H_ 27 #define DC_INC_LINK_DP_DPIA_BW_H_ 28 29 #include "link.h" 30 31 /* Number of Host Routers per motherboard is 2 */ 32 #define MAX_HR_NUM 2 33 /* Number of DPIA per host router is 2 */ 34 #define MAX_DPIA_NUM (MAX_HR_NUM * 2) 35 36 /* 37 * Host Router BW type 38 */ 39 enum bw_type { 40 HOST_ROUTER_BW_ESTIMATED, 41 HOST_ROUTER_BW_ALLOCATED, 42 HOST_ROUTER_BW_INVALID, 43 }; 44 45 /* 46 * Enable BW Allocation Mode Support from the DP-Tx side 47 * 48 * @link: pointer to the dc_link struct instance 49 * 50 * return: SUCCESS or FAILURE 51 */ 52 bool link_dp_dpia_set_dptx_usb4_bw_alloc_support(struct dc_link *link); 53 54 /* 55 * Allocates only what the stream needs for bw, so if: 56 * If (stream_req_bw < or > already_allocated_bw_at_HPD) 57 * => Deallocate Max Bw & then allocate only what the stream needs 58 * 59 * @link: pointer to the dc_link struct instance 60 * @req_bw: Bw requested by the stream 61 * 62 */ 63 void link_dp_dpia_allocate_usb4_bandwidth_for_stream(struct dc_link *link, int req_bw); 64 65 /* 66 * Handle the USB4 BW Allocation related functionality here: 67 * Plug => Try to allocate max bw from timing parameters supported by the sink 68 * Unplug => de-allocate bw 69 * 70 * @link: pointer to the dc_link struct instance 71 * @peak_bw: Peak bw used by the link/sink 72 * 73 */ 74 void dpia_handle_usb4_bandwidth_allocation_for_link(struct dc_link *link, int peak_bw); 75 76 /* 77 * Handle the validation of total BW here and confirm that the bw used by each 78 * DPIA doesn't exceed available BW for each host router (HR) 79 * 80 * @link[]: array of link pointer to all possible DPIA links 81 * @bw_needed[]: bw needed for each DPIA link based on timing 82 * @num_dpias: Number of DPIAs for the above 2 arrays. Should always be <= MAX_DPIA_NUM 83 * 84 * return: TRUE if bw used by DPIAs doesn't exceed available BW else return FALSE 85 */ 86 bool dpia_validate_usb4_bw(struct dc_link **link, int *bw_needed, const unsigned int num_dpias); 87 88 /* 89 * Obtain all the DP overheads in dp tunneling for the dpia link 90 * 91 * @link: pointer to the dc_link struct instance 92 * 93 * return: DP overheads in DP tunneling 94 */ 95 int link_dp_dpia_get_dp_overhead_in_dp_tunneling(struct dc_link *link); 96 97 /* 98 * Handle DP BW allocation status register 99 * 100 * @link: pointer to the dc_link struct instance 101 * @status: content of DP tunneling status register 102 * 103 * return: none 104 */ 105 void link_dp_dpia_handle_bw_alloc_status(struct dc_link *link, uint8_t status); 106 107 #endif /* DC_INC_LINK_DP_DPIA_BW_H_ */ 108