xref: /linux/drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.h (revision 42874e4eb35bdfc54f8514685e50434098ba4f6c)
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  * return: allocated bw else return 0
63  */
64 int link_dp_dpia_allocate_usb4_bandwidth_for_stream(struct dc_link *link, int req_bw);
65 
66 /*
67  * Handle the USB4 BW Allocation related functionality here:
68  * Plug => Try to allocate max bw from timing parameters supported by the sink
69  * Unplug => de-allocate bw
70  *
71  * @link: pointer to the dc_link struct instance
72  * @peak_bw: Peak bw used by the link/sink
73  *
74  * return: allocated bw else return 0
75  */
76 int dpia_handle_usb4_bandwidth_allocation_for_link(struct dc_link *link, int peak_bw);
77 
78 /*
79  * Handle function for when the status of the Request above is complete.
80  * We will find out the result of allocating on CM and update structs.
81  *
82  * @link: pointer to the dc_link struct instance
83  * @bw: Allocated or Estimated BW depending on the result
84  * @result: Response type
85  *
86  * return: none
87  */
88 void dpia_handle_bw_alloc_response(struct dc_link *link, uint8_t bw, uint8_t result);
89 
90 /*
91  * Handle the validation of total BW here and confirm that the bw used by each
92  * DPIA doesn't exceed available BW for each host router (HR)
93  *
94  * @link[]: array of link pointer to all possible DPIA links
95  * @bw_needed[]: bw needed for each DPIA link based on timing
96  * @num_dpias: Number of DPIAs for the above 2 arrays. Should always be <= MAX_DPIA_NUM
97  *
98  * return: TRUE if bw used by DPIAs doesn't exceed available BW else return FALSE
99  */
100 bool dpia_validate_usb4_bw(struct dc_link **link, int *bw_needed, const unsigned int num_dpias);
101 
102 #endif /* DC_INC_LINK_DP_DPIA_BW_H_ */
103