xref: /openbmc/linux/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.h (revision 09c434b8)
1 /*
2  * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
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 
15 #ifndef __DPU_RM_H__
16 #define __DPU_RM_H__
17 
18 #include <linux/list.h>
19 
20 #include "msm_kms.h"
21 #include "dpu_hw_top.h"
22 
23 /**
24  * struct dpu_rm - DPU dynamic hardware resource manager
25  * @hw_blks: array of lists of hardware resources present in the system, one
26  *	list per type of hardware block
27  * @lm_max_width: cached layer mixer maximum width
28  * @rm_lock: resource manager mutex
29  */
30 struct dpu_rm {
31 	struct list_head hw_blks[DPU_HW_BLK_MAX];
32 	uint32_t lm_max_width;
33 	struct mutex rm_lock;
34 };
35 
36 /**
37  *  struct dpu_rm_hw_blk - resource manager internal structure
38  *	forward declaration for single iterator definition without void pointer
39  */
40 struct dpu_rm_hw_blk;
41 
42 /**
43  * struct dpu_rm_hw_iter - iterator for use with dpu_rm
44  * @hw: dpu_hw object requested, or NULL on failure
45  * @blk: dpu_rm internal block representation. Clients ignore. Used as iterator.
46  * @enc_id: DRM ID of Encoder client wishes to search for, or 0 for Any Encoder
47  * @type: Hardware Block Type client wishes to search for.
48  */
49 struct dpu_rm_hw_iter {
50 	void *hw;
51 	struct dpu_rm_hw_blk *blk;
52 	uint32_t enc_id;
53 	enum dpu_hw_blk_type type;
54 };
55 
56 /**
57  * dpu_rm_init - Read hardware catalog and create reservation tracking objects
58  *	for all HW blocks.
59  * @rm: DPU Resource Manager handle
60  * @cat: Pointer to hardware catalog
61  * @mmio: mapped register io address of MDP
62  * @Return: 0 on Success otherwise -ERROR
63  */
64 int dpu_rm_init(struct dpu_rm *rm,
65 		struct dpu_mdss_cfg *cat,
66 		void __iomem *mmio);
67 
68 /**
69  * dpu_rm_destroy - Free all memory allocated by dpu_rm_init
70  * @rm: DPU Resource Manager handle
71  * @Return: 0 on Success otherwise -ERROR
72  */
73 int dpu_rm_destroy(struct dpu_rm *rm);
74 
75 /**
76  * dpu_rm_reserve - Given a CRTC->Encoder->Connector display chain, analyze
77  *	the use connections and user requirements, specified through related
78  *	topology control properties, and reserve hardware blocks to that
79  *	display chain.
80  *	HW blocks can then be accessed through dpu_rm_get_* functions.
81  *	HW Reservations should be released via dpu_rm_release_hw.
82  * @rm: DPU Resource Manager handle
83  * @drm_enc: DRM Encoder handle
84  * @crtc_state: Proposed Atomic DRM CRTC State handle
85  * @topology: Pointer to topology info for the display
86  * @test_only: Atomic-Test phase, discard results (unless property overrides)
87  * @Return: 0 on Success otherwise -ERROR
88  */
89 int dpu_rm_reserve(struct dpu_rm *rm,
90 		struct drm_encoder *drm_enc,
91 		struct drm_crtc_state *crtc_state,
92 		struct msm_display_topology topology,
93 		bool test_only);
94 
95 /**
96  * dpu_rm_reserve - Given the encoder for the display chain, release any
97  *	HW blocks previously reserved for that use case.
98  * @rm: DPU Resource Manager handle
99  * @enc: DRM Encoder handle
100  * @Return: 0 on Success otherwise -ERROR
101  */
102 void dpu_rm_release(struct dpu_rm *rm, struct drm_encoder *enc);
103 
104 /**
105  * dpu_rm_init_hw_iter - setup given iterator for new iteration over hw list
106  *	using dpu_rm_get_hw
107  * @iter: iter object to initialize
108  * @enc_id: DRM ID of Encoder client wishes to search for, or 0 for Any Encoder
109  * @type: Hardware Block Type client wishes to search for.
110  */
111 void dpu_rm_init_hw_iter(
112 		struct dpu_rm_hw_iter *iter,
113 		uint32_t enc_id,
114 		enum dpu_hw_blk_type type);
115 /**
116  * dpu_rm_get_hw - retrieve reserved hw object given encoder and hw type
117  *	Meant to do a single pass through the hardware list to iteratively
118  *	retrieve hardware blocks of a given type for a given encoder.
119  *	Initialize an iterator object.
120  *	Set hw block type of interest. Set encoder id of interest, 0 for any.
121  *	Function returns first hw of type for that encoder.
122  *	Subsequent calls will return the next reserved hw of that type in-order.
123  *	Iterator HW pointer will be null on failure to find hw.
124  * @rm: DPU Resource Manager handle
125  * @iter: iterator object
126  * @Return: true on match found, false on no match found
127  */
128 bool dpu_rm_get_hw(struct dpu_rm *rm, struct dpu_rm_hw_iter *iter);
129 #endif /* __DPU_RM_H__ */
130