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