Skip to content

Commit b954fa6

Browse files
ddavenport-chromiumrobclark
authored andcommitted
drm/msm/dpu: Refactor rm iterator
Make iterator implementation private, and add function to query resources assigned to an encoder. Signed-off-by: Drew Davenport <[email protected]> Signed-off-by: Rob Clark <[email protected]>
1 parent 8724d57 commit b954fa6

File tree

5 files changed

+76
-81
lines changed

5 files changed

+76
-81
lines changed

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -957,11 +957,11 @@ static void dpu_encoder_virt_mode_set(struct drm_encoder *drm_enc,
957957
struct drm_connector *conn = NULL, *conn_iter;
958958
struct drm_crtc *drm_crtc;
959959
struct dpu_crtc_state *cstate;
960-
struct dpu_rm_hw_iter hw_iter;
961960
struct msm_display_topology topology;
962-
struct dpu_hw_ctl *hw_ctl[MAX_CHANNELS_PER_ENC] = { NULL };
963-
struct dpu_hw_mixer *hw_lm[MAX_CHANNELS_PER_ENC] = { NULL };
964-
int num_lm = 0, num_ctl = 0;
961+
struct dpu_hw_blk *hw_pp[MAX_CHANNELS_PER_ENC];
962+
struct dpu_hw_blk *hw_ctl[MAX_CHANNELS_PER_ENC];
963+
struct dpu_hw_blk *hw_lm[MAX_CHANNELS_PER_ENC];
964+
int num_lm, num_ctl, num_pp;
965965
int i, j, ret;
966966

967967
if (!drm_enc) {
@@ -1005,42 +1005,31 @@ static void dpu_encoder_virt_mode_set(struct drm_encoder *drm_enc,
10051005
return;
10061006
}
10071007

1008-
dpu_rm_init_hw_iter(&hw_iter, drm_enc->base.id, DPU_HW_BLK_PINGPONG);
1009-
for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
1010-
dpu_enc->hw_pp[i] = NULL;
1011-
if (!dpu_rm_get_hw(&dpu_kms->rm, &hw_iter))
1012-
break;
1013-
dpu_enc->hw_pp[i] = (struct dpu_hw_pingpong *) hw_iter.hw;
1014-
}
1015-
1016-
dpu_rm_init_hw_iter(&hw_iter, drm_enc->base.id, DPU_HW_BLK_CTL);
1017-
for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
1018-
if (!dpu_rm_get_hw(&dpu_kms->rm, &hw_iter))
1019-
break;
1020-
hw_ctl[i] = (struct dpu_hw_ctl *)hw_iter.hw;
1021-
num_ctl++;
1022-
}
1008+
num_pp = dpu_rm_get_assigned_resources(&dpu_kms->rm, drm_enc->base.id,
1009+
DPU_HW_BLK_PINGPONG, hw_pp, ARRAY_SIZE(hw_pp));
1010+
num_ctl = dpu_rm_get_assigned_resources(&dpu_kms->rm, drm_enc->base.id,
1011+
DPU_HW_BLK_CTL, hw_ctl, ARRAY_SIZE(hw_ctl));
1012+
num_lm = dpu_rm_get_assigned_resources(&dpu_kms->rm, drm_enc->base.id,
1013+
DPU_HW_BLK_LM, hw_lm, ARRAY_SIZE(hw_lm));
10231014

1024-
dpu_rm_init_hw_iter(&hw_iter, drm_enc->base.id, DPU_HW_BLK_LM);
1025-
for (i = 0; i < MAX_CHANNELS_PER_ENC; i++) {
1026-
if (!dpu_rm_get_hw(&dpu_kms->rm, &hw_iter))
1027-
break;
1028-
hw_lm[i] = (struct dpu_hw_mixer *)hw_iter.hw;
1029-
num_lm++;
1030-
}
1015+
for (i = 0; i < MAX_CHANNELS_PER_ENC; i++)
1016+
dpu_enc->hw_pp[i] = i < num_pp ? to_dpu_hw_pingpong(hw_pp[i])
1017+
: NULL;
10311018

10321019
cstate = to_dpu_crtc_state(drm_crtc->state);
10331020

10341021
for (i = 0; i < num_lm; i++) {
10351022
int ctl_idx = (i < num_ctl) ? i : (num_ctl-1);
10361023

1037-
cstate->mixers[i].hw_lm = hw_lm[i];
1038-
cstate->mixers[i].lm_ctl = hw_ctl[ctl_idx];
1024+
cstate->mixers[i].hw_lm = to_dpu_hw_mixer(hw_lm[i]);
1025+
cstate->mixers[i].lm_ctl = to_dpu_hw_ctl(hw_ctl[ctl_idx]);
10391026
}
10401027

10411028
cstate->num_mixers = num_lm;
10421029

10431030
for (i = 0; i < dpu_enc->num_phys_encs; i++) {
1031+
int num_blk;
1032+
struct dpu_hw_blk *hw_blk[MAX_CHANNELS_PER_ENC];
10441033
struct dpu_encoder_phys *phys = dpu_enc->phys_encs[i];
10451034

10461035
if (!dpu_enc->hw_pp[i]) {
@@ -1056,17 +1045,15 @@ static void dpu_encoder_virt_mode_set(struct drm_encoder *drm_enc,
10561045
}
10571046

10581047
phys->hw_pp = dpu_enc->hw_pp[i];
1059-
phys->hw_ctl = hw_ctl[i];
1048+
phys->hw_ctl = to_dpu_hw_ctl(hw_ctl[i]);
10601049

1061-
dpu_rm_init_hw_iter(&hw_iter, drm_enc->base.id,
1062-
DPU_HW_BLK_INTF);
1063-
for (j = 0; j < MAX_CHANNELS_PER_ENC; j++) {
1050+
num_blk = dpu_rm_get_assigned_resources(&dpu_kms->rm,
1051+
drm_enc->base.id, DPU_HW_BLK_INTF, hw_blk,
1052+
ARRAY_SIZE(hw_blk));
1053+
for (j = 0; j < num_blk; j++) {
10641054
struct dpu_hw_intf *hw_intf;
10651055

1066-
if (!dpu_rm_get_hw(&dpu_kms->rm, &hw_iter))
1067-
break;
1068-
1069-
hw_intf = (struct dpu_hw_intf *)hw_iter.hw;
1056+
hw_intf = to_dpu_hw_intf(hw_blk[i]);
10701057
if (hw_intf->idx == phys->intf_idx)
10711058
phys->hw_intf = hw_intf;
10721059
}

drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ struct dpu_hw_intf {
8989
struct dpu_hw_intf_ops ops;
9090
};
9191

92+
/**
93+
* to_dpu_hw_intf - convert base object dpu_hw_base to container
94+
* @hw: Pointer to base hardware block
95+
* return: Pointer to hardware block container
96+
*/
97+
static inline struct dpu_hw_intf *to_dpu_hw_intf(struct dpu_hw_blk *hw)
98+
{
99+
return container_of(hw, struct dpu_hw_intf, base);
100+
}
101+
92102
/**
93103
* dpu_hw_intf_init(): Initializes the intf driver for the passed
94104
* interface idx.

drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ struct dpu_hw_pingpong {
9696
struct dpu_hw_pingpong_ops ops;
9797
};
9898

99+
/**
100+
* to_dpu_hw_pingpong - convert base object dpu_hw_base to container
101+
* @hw: Pointer to base hardware block
102+
* return: Pointer to hardware block container
103+
*/
104+
static inline struct dpu_hw_pingpong *to_dpu_hw_pingpong(struct dpu_hw_blk *hw)
105+
{
106+
return container_of(hw, struct dpu_hw_pingpong, base);
107+
}
108+
99109
/**
100110
* dpu_hw_pingpong_init - initializes the pingpong driver for the passed
101111
* pingpong idx.

drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,21 @@ struct dpu_rm_hw_blk {
4040
struct dpu_hw_blk *hw;
4141
};
4242

43-
void dpu_rm_init_hw_iter(
43+
/**
44+
* struct dpu_rm_hw_iter - iterator for use with dpu_rm
45+
* @hw: dpu_hw object requested, or NULL on failure
46+
* @blk: dpu_rm internal block representation. Clients ignore. Used as iterator.
47+
* @enc_id: DRM ID of Encoder client wishes to search for, or 0 for Any Encoder
48+
* @type: Hardware Block Type client wishes to search for.
49+
*/
50+
struct dpu_rm_hw_iter {
51+
void *hw;
52+
struct dpu_rm_hw_blk *blk;
53+
uint32_t enc_id;
54+
enum dpu_hw_blk_type type;
55+
};
56+
57+
static void dpu_rm_init_hw_iter(
4458
struct dpu_rm_hw_iter *iter,
4559
uint32_t enc_id,
4660
enum dpu_hw_blk_type type)
@@ -83,7 +97,7 @@ static bool _dpu_rm_get_hw_locked(struct dpu_rm *rm, struct dpu_rm_hw_iter *i)
8397
return false;
8498
}
8599

86-
bool dpu_rm_get_hw(struct dpu_rm *rm, struct dpu_rm_hw_iter *i)
100+
static bool dpu_rm_get_hw(struct dpu_rm *rm, struct dpu_rm_hw_iter *i)
87101
{
88102
bool ret;
89103

@@ -635,3 +649,16 @@ int dpu_rm_reserve(
635649

636650
return ret;
637651
}
652+
653+
int dpu_rm_get_assigned_resources(struct dpu_rm *rm, uint32_t enc_id,
654+
enum dpu_hw_blk_type type, struct dpu_hw_blk **blks, int blks_size)
655+
{
656+
struct dpu_rm_hw_iter hw_iter;
657+
int num_blks = 0;
658+
659+
dpu_rm_init_hw_iter(&hw_iter, enc_id, type);
660+
while (num_blks < blks_size && dpu_rm_get_hw(rm, &hw_iter))
661+
blks[num_blks++] = hw_iter.blk->hw;
662+
663+
return num_blks;
664+
}

drivers/gpu/drm/msm/disp/dpu1/dpu_rm.h

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,6 @@ struct dpu_rm {
2424
struct mutex rm_lock;
2525
};
2626

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-
4727
/**
4828
* dpu_rm_init - Read hardware catalog and create reservation tracking objects
4929
* for all HW blocks.
@@ -93,28 +73,9 @@ int dpu_rm_reserve(struct dpu_rm *rm,
9373
void dpu_rm_release(struct dpu_rm *rm, struct drm_encoder *enc);
9474

9575
/**
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.
76+
* Get hw resources of the given type that are assigned to this encoder.
10177
*/
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);
78+
int dpu_rm_get_assigned_resources(struct dpu_rm *rm, uint32_t enc_id,
79+
enum dpu_hw_blk_type type, struct dpu_hw_blk **blks, int blks_size);
12080
#endif /* __DPU_RM_H__ */
81+

0 commit comments

Comments
 (0)