Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 1 | /* |
Lloyd Atkinson | b6b9917 | 2017-01-17 10:23:06 -0500 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
Lloyd Atkinson | 05ec907 | 2016-09-12 15:44:46 -0400 | [diff] [blame] | 15 | #ifndef __SDE_RM_H__ |
| 16 | #define __SDE_RM_H__ |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 17 | |
| 18 | #include <linux/list.h> |
| 19 | |
| 20 | #include "msm_kms.h" |
| 21 | #include "sde_hw_top.h" |
| 22 | |
| 23 | /** |
| 24 | * enum sde_rm_topology_name - HW resource use case in use by connector |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 25 | * @SDE_RM_TOPOLOGY_NONE: No topology in use currently |
| 26 | * @SDE_RM_TOPOLOGY_SINGLEPIPE: 1 LM, 1 PP, 1 INTF/WB |
| 27 | * @SDE_RM_TOPOLOGY_SINGLEPIPE_DSC: 1 LM, 1 DSC, 1 PP, 1 INTF/WB |
| 28 | * @SDE_RM_TOPOLOGY_DUALPIPE: 2 LM, 2 PP, 2 INTF/WB |
| 29 | * @SDE_RM_TOPOLOGY_DUALPIPE_DSC: 2 LM, 2 DSC, 2 PP, 2 INTF/WB |
| 30 | * @SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE: 2 LM, 2 PP, 3DMux, 1 INTF/WB |
| 31 | * @SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC: 2 LM, 2 PP, 3DMux, 1 DSC, 1 INTF/WB |
| 32 | * @SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE: 2 LM, 2 PP, 2 DSC Merge, 1 INTF/WB |
| 33 | * @SDE_RM_TOPOLOGY_PPSPLIT: 1 LM, 2 PPs, 2 INTF/WB |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 34 | */ |
| 35 | enum sde_rm_topology_name { |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 36 | SDE_RM_TOPOLOGY_NONE = 0, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 37 | SDE_RM_TOPOLOGY_SINGLEPIPE, |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 38 | SDE_RM_TOPOLOGY_SINGLEPIPE_DSC, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 39 | SDE_RM_TOPOLOGY_DUALPIPE, |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 40 | SDE_RM_TOPOLOGY_DUALPIPE_DSC, |
| 41 | SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE, |
| 42 | SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC, |
| 43 | SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 44 | SDE_RM_TOPOLOGY_PPSPLIT, |
Jeykumar Sankaran | 2b09807 | 2017-03-16 17:25:59 -0700 | [diff] [blame] | 45 | SDE_RM_TOPOLOGY_MAX, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * enum sde_rm_topology_control - HW resource use case in use by connector |
| 50 | * @SDE_RM_TOPCTL_RESERVE_LOCK: If set, in AtomicTest phase, after a successful |
| 51 | * test, reserve the resources for this display. |
| 52 | * Normal behavior would not impact the reservation |
| 53 | * list during the AtomicTest phase. |
| 54 | * @SDE_RM_TOPCTL_RESERVE_CLEAR: If set, in AtomicTest phase, before testing, |
| 55 | * release any reservation held by this display. |
| 56 | * Normal behavior would not impact the |
| 57 | * reservation list during the AtomicTest phase. |
| 58 | * @SDE_RM_TOPCTL_DSPP: Require layer mixers with DSPP capabilities |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 59 | * @SDE_RM_TOPCTL_DS : Require layer mixers with DS capabilities |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 60 | */ |
| 61 | enum sde_rm_topology_control { |
| 62 | SDE_RM_TOPCTL_RESERVE_LOCK, |
| 63 | SDE_RM_TOPCTL_RESERVE_CLEAR, |
| 64 | SDE_RM_TOPCTL_DSPP, |
Sravanthi Kollukuduru | c7bcde9 | 2017-06-16 12:44:39 +0530 | [diff] [blame] | 65 | SDE_RM_TOPCTL_DS, |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /** |
| 69 | * struct sde_rm - SDE dynamic hardware resource manager |
| 70 | * @dev: device handle for event logging purposes |
| 71 | * @rsvps: list of hardware reservations by each crtc->encoder->connector |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 72 | * @hw_blks: array of lists of hardware resources present in the system, one |
| 73 | * list per type of hardware block |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 74 | * @hw_mdp: hardware object for mdp_top |
| 75 | * @lm_max_width: cached layer mixer maximum width |
| 76 | * @rsvp_next_seq: sequence number for next reservation for debugging purposes |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 77 | * @rm_lock: resource manager mutex |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 78 | */ |
| 79 | struct sde_rm { |
| 80 | struct drm_device *dev; |
| 81 | struct list_head rsvps; |
Lloyd Atkinson | d170981 | 2016-08-31 10:04:02 -0400 | [diff] [blame] | 82 | struct list_head hw_blks[SDE_HW_BLK_MAX]; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 83 | struct sde_hw_mdp *hw_mdp; |
| 84 | uint32_t lm_max_width; |
| 85 | uint32_t rsvp_next_seq; |
Lloyd Atkinson | d3b1457 | 2017-04-26 08:33:55 -0700 | [diff] [blame] | 86 | struct mutex rm_lock; |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /** |
| 90 | * struct sde_rm_hw_blk - resource manager internal structure |
| 91 | * forward declaration for single iterator definition without void pointer |
| 92 | */ |
| 93 | struct sde_rm_hw_blk; |
| 94 | |
| 95 | /** |
| 96 | * struct sde_rm_hw_iter - iterator for use with sde_rm |
| 97 | * @hw: sde_hw object requested, or NULL on failure |
| 98 | * @blk: sde_rm internal block representation. Clients ignore. Used as iterator. |
| 99 | * @enc_id: DRM ID of Encoder client wishes to search for, or 0 for Any Encoder |
| 100 | * @type: Hardware Block Type client wishes to search for. |
| 101 | */ |
| 102 | struct sde_rm_hw_iter { |
| 103 | void *hw; |
| 104 | struct sde_rm_hw_blk *blk; |
| 105 | uint32_t enc_id; |
| 106 | enum sde_hw_blk_type type; |
| 107 | }; |
| 108 | |
| 109 | /** |
Jeykumar Sankaran | 83ddcb0 | 2017-10-27 11:34:50 -0700 | [diff] [blame] | 110 | * sde_rm_get_topology_name - get the name of the given topology config |
| 111 | * @topology: msm_display_topology topology config |
| 112 | * @Return: name of the given topology |
| 113 | */ |
| 114 | enum sde_rm_topology_name sde_rm_get_topology_name( |
| 115 | struct msm_display_topology topology); |
| 116 | |
| 117 | |
| 118 | /** |
Lloyd Atkinson | ccc11c5 | 2016-08-10 18:54:30 -0400 | [diff] [blame] | 119 | * sde_rm_init - Read hardware catalog and create reservation tracking objects |
| 120 | * for all HW blocks. |
| 121 | * @rm: SDE Resource Manager handle |
| 122 | * @cat: Pointer to hardware catalog |
| 123 | * @mmio: mapped register io address of MDP |
| 124 | * @dev: device handle for event logging purposes |
| 125 | * @Return: 0 on Success otherwise -ERROR |
| 126 | */ |
| 127 | int sde_rm_init(struct sde_rm *rm, |
| 128 | struct sde_mdss_cfg *cat, |
| 129 | void *mmio, |
| 130 | struct drm_device *dev); |
| 131 | |
| 132 | /** |
| 133 | * sde_rm_destroy - Free all memory allocated by sde_rm_init |
| 134 | * @rm: SDE Resource Manager handle |
| 135 | * @Return: 0 on Success otherwise -ERROR |
| 136 | */ |
| 137 | int sde_rm_destroy(struct sde_rm *rm); |
| 138 | |
| 139 | /** |
| 140 | * sde_rm_reserve - Given a CRTC->Encoder->Connector display chain, analyze |
| 141 | * the use connections and user requirements, specified through related |
| 142 | * topology control properties, and reserve hardware blocks to that |
| 143 | * display chain. |
| 144 | * HW blocks can then be accessed through sde_rm_get_* functions. |
| 145 | * HW Reservations should be released via sde_rm_release_hw. |
| 146 | * @rm: SDE Resource Manager handle |
| 147 | * @drm_enc: DRM Encoder handle |
| 148 | * @crtc_state: Proposed Atomic DRM CRTC State handle |
| 149 | * @conn_state: Proposed Atomic DRM Connector State handle |
| 150 | * @test_only: Atomic-Test phase, discard results (unless property overrides) |
| 151 | * @Return: 0 on Success otherwise -ERROR |
| 152 | */ |
| 153 | int sde_rm_reserve(struct sde_rm *rm, |
| 154 | struct drm_encoder *drm_enc, |
| 155 | struct drm_crtc_state *crtc_state, |
| 156 | struct drm_connector_state *conn_state, |
| 157 | bool test_only); |
| 158 | |
| 159 | /** |
| 160 | * sde_rm_reserve - Given the encoder for the display chain, release any |
| 161 | * HW blocks previously reserved for that use case. |
| 162 | * @rm: SDE Resource Manager handle |
| 163 | * @enc: DRM Encoder handle |
| 164 | * @Return: 0 on Success otherwise -ERROR |
| 165 | */ |
| 166 | void sde_rm_release(struct sde_rm *rm, struct drm_encoder *enc); |
| 167 | |
| 168 | /** |
| 169 | * sde_rm_get_mdp - Retrieve HW block for MDP TOP. |
| 170 | * This is never reserved, and is usable by any display. |
| 171 | * @rm: SDE Resource Manager handle |
| 172 | * @Return: Pointer to hw block or NULL |
| 173 | */ |
| 174 | struct sde_hw_mdp *sde_rm_get_mdp(struct sde_rm *rm); |
| 175 | |
| 176 | /** |
| 177 | * sde_rm_init_hw_iter - setup given iterator for new iteration over hw list |
| 178 | * using sde_rm_get_hw |
| 179 | * @iter: iter object to initialize |
| 180 | * @enc_id: DRM ID of Encoder client wishes to search for, or 0 for Any Encoder |
| 181 | * @type: Hardware Block Type client wishes to search for. |
| 182 | */ |
| 183 | void sde_rm_init_hw_iter( |
| 184 | struct sde_rm_hw_iter *iter, |
| 185 | uint32_t enc_id, |
| 186 | enum sde_hw_blk_type type); |
| 187 | /** |
| 188 | * sde_rm_get_hw - retrieve reserved hw object given encoder and hw type |
| 189 | * Meant to do a single pass through the hardware list to iteratively |
| 190 | * retrieve hardware blocks of a given type for a given encoder. |
| 191 | * Initialize an iterator object. |
| 192 | * Set hw block type of interest. Set encoder id of interest, 0 for any. |
| 193 | * Function returns first hw of type for that encoder. |
| 194 | * Subsequent calls will return the next reserved hw of that type in-order. |
| 195 | * Iterator HW pointer will be null on failure to find hw. |
| 196 | * @rm: SDE Resource Manager handle |
| 197 | * @iter: iterator object |
| 198 | * @Return: true on match found, false on no match found |
| 199 | */ |
| 200 | bool sde_rm_get_hw(struct sde_rm *rm, struct sde_rm_hw_iter *iter); |
| 201 | |
| 202 | /** |
| 203 | * sde_rm_check_property_topctl - validate property bitmask before it is set |
| 204 | * @val: user's proposed topology control bitmask |
| 205 | * @Return: 0 on success or error |
| 206 | */ |
| 207 | int sde_rm_check_property_topctl(uint64_t val); |
| 208 | |
Jeykumar Sankaran | 586d092 | 2017-09-18 15:01:33 -0700 | [diff] [blame] | 209 | /** |
| 210 | * sde_rm_update_topology - sets topology property of the connector |
| 211 | * @conn_state: drm state of the connector |
| 212 | * @topology: topology selected for the display |
| 213 | * @return: 0 on success or error |
| 214 | */ |
| 215 | int sde_rm_update_topology(struct drm_connector_state *conn_state, |
| 216 | struct msm_display_topology *topology); |
| 217 | |
Lloyd Atkinson | 05ec907 | 2016-09-12 15:44:46 -0400 | [diff] [blame] | 218 | #endif /* __SDE_RM_H__ */ |