Skip to content

Commit ed3cafa

Browse files
bebarinoAndy Gross
authored andcommitted
soc: qcom: cmd-db: Stop memcpy()ing in cmd_db_read_aux_data()
Let's change the function signature to return the pointer to memory or an error pointer on failure, and take an argument that lets us return the size of the aux data read. This way we can remove the cmd_db_read_aux_data_len() API entirely and also get rid of the memcpy operation from cmd_db to the caller. Updating the only user of this code shows that making this change allows us to remove a function and put the lookup where the user is. Cc: Mahesh Sivasubramanian <msivasub@codeaurora.org> Cc: Lina Iyer <ilina@codeaurora.org> Cc: Bjorn Andersson <bjorn.andersson@linaro.org> Cc: Evan Green <evgreen@chromium.org> Cc: Jordan Crouse <jcrouse@codeaurora.org> Cc: Rob Clark <robdclark@gmail.com> Signed-off-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Andy Gross <andy.gross@linaro.org>
1 parent 84fa36e commit ed3cafa

3 files changed

Lines changed: 30 additions & 79 deletions

File tree

‎drivers/gpu/drm/msm/adreno/a6xx_gmu.c‎

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -902,26 +902,6 @@ static int a6xx_gmu_memory_probe(struct a6xx_gmu *gmu)
902902
return ret;
903903
}
904904

905-
/* Get the list of RPMh voltage levels from cmd-db */
906-
static int a6xx_gmu_rpmh_arc_cmds(const char *id, void *vals, int size)
907-
{
908-
u32 len = cmd_db_read_aux_data_len(id);
909-
910-
if (!len)
911-
return 0;
912-
913-
if (WARN_ON(len > size))
914-
return -EINVAL;
915-
916-
cmd_db_read_aux_data(id, vals, len);
917-
918-
/*
919-
* The data comes back as an array of unsigned shorts so adjust the
920-
* count accordingly
921-
*/
922-
return len >> 1;
923-
}
924-
925905
/* Return the 'arc-level' for the given frequency */
926906
static u32 a6xx_gmu_get_arc_level(struct device *dev, unsigned long freq)
927907
{
@@ -949,11 +929,25 @@ static u32 a6xx_gmu_get_arc_level(struct device *dev, unsigned long freq)
949929
}
950930

951931
static int a6xx_gmu_rpmh_arc_votes_init(struct device *dev, u32 *votes,
952-
unsigned long *freqs, int freqs_count,
953-
u16 *pri, int pri_count,
954-
u16 *sec, int sec_count)
932+
unsigned long *freqs, int freqs_count, const char *id)
955933
{
956934
int i, j;
935+
const u16 *pri, *sec;
936+
size_t pri_count, sec_count;
937+
938+
pri = cmd_db_read_aux_data(id, &pri_count);
939+
/*
940+
* The data comes back as an array of unsigned shorts so adjust the
941+
* count accordingly
942+
*/
943+
pri_count >>= 1;
944+
if (!pri_count)
945+
return -EINVAL;
946+
947+
sec = cmd_db_read_aux_data("mx.lvl", &sec_count);
948+
sec_count >>= 1;
949+
if (!sec_count)
950+
return -EINVAL;
957951

958952
/* Construct a vote for each frequency */
959953
for (i = 0; i < freqs_count; i++) {
@@ -1012,25 +1006,15 @@ static int a6xx_gmu_rpmh_votes_init(struct a6xx_gmu *gmu)
10121006
struct a6xx_gpu *a6xx_gpu = container_of(gmu, struct a6xx_gpu, gmu);
10131007
struct adreno_gpu *adreno_gpu = &a6xx_gpu->base;
10141008
struct msm_gpu *gpu = &adreno_gpu->base;
1015-
1016-
u16 gx[16], cx[16], mx[16];
1017-
u32 gxcount, cxcount, mxcount;
10181009
int ret;
10191010

1020-
/* Get the list of available voltage levels for each component */
1021-
gxcount = a6xx_gmu_rpmh_arc_cmds("gfx.lvl", gx, sizeof(gx));
1022-
cxcount = a6xx_gmu_rpmh_arc_cmds("cx.lvl", cx, sizeof(cx));
1023-
mxcount = a6xx_gmu_rpmh_arc_cmds("mx.lvl", mx, sizeof(mx));
1024-
10251011
/* Build the GX votes */
10261012
ret = a6xx_gmu_rpmh_arc_votes_init(&gpu->pdev->dev, gmu->gx_arc_votes,
1027-
gmu->gpu_freqs, gmu->nr_gpu_freqs,
1028-
gx, gxcount, mx, mxcount);
1013+
gmu->gpu_freqs, gmu->nr_gpu_freqs, "gfx.lvl");
10291014

10301015
/* Build the CX votes */
10311016
ret |= a6xx_gmu_rpmh_arc_votes_init(gmu->dev, gmu->cx_arc_votes,
1032-
gmu->gmu_freqs, gmu->nr_gmu_freqs,
1033-
cx, cxcount, mx, mxcount);
1017+
gmu->gmu_freqs, gmu->nr_gmu_freqs, "cx.lvl");
10341018

10351019
return ret;
10361020
}

‎drivers/soc/qcom/cmd-db.c‎

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -192,55 +192,28 @@ EXPORT_SYMBOL(cmd_db_read_addr);
192192
/**
193193
* cmd_db_read_aux_data() - Query command db for aux data.
194194
*
195-
* @id: Resource to retrieve AUX Data on.
196-
* @data: Data buffer to copy returned aux data to. Returns size on NULL
197-
* @len: Caller provides size of data buffer passed in.
195+
* @id: Resource to retrieve AUX Data on
196+
* @len: size of data buffer returned
198197
*
199-
* Return: size of data on success, errno otherwise
198+
* Return: pointer to data on success, error pointer otherwise
200199
*/
201-
int cmd_db_read_aux_data(const char *id, u8 *data, size_t len)
200+
const void *cmd_db_read_aux_data(const char *id, size_t *len)
202201
{
203202
int ret;
204203
const struct entry_header *ent;
205204
const struct rsc_hdr *rsc_hdr;
206-
u16 ent_len;
207-
208-
if (!data)
209-
return -EINVAL;
210205

211206
ret = cmd_db_get_header(id, &ent, &rsc_hdr);
212207
if (ret)
213-
return ret;
214-
215-
ent_len = le16_to_cpu(ent->len);
216-
if (len < ent_len)
217-
return -EINVAL;
208+
return ERR_PTR(ret);
218209

219-
len = min_t(u16, ent_len, len);
220-
memcpy(data, rsc_offset(rsc_hdr, ent), len);
210+
if (len)
211+
*len = le16_to_cpu(ent->len);
221212

222-
return len;
213+
return rsc_offset(rsc_hdr, ent);
223214
}
224215
EXPORT_SYMBOL(cmd_db_read_aux_data);
225216

226-
/**
227-
* cmd_db_read_aux_data_len - Get the length of the auxiliary data stored in DB.
228-
*
229-
* @id: Resource to retrieve AUX Data.
230-
*
231-
* Return: size on success, 0 on error
232-
*/
233-
size_t cmd_db_read_aux_data_len(const char *id)
234-
{
235-
int ret;
236-
const struct entry_header *ent;
237-
238-
ret = cmd_db_get_header(id, &ent, NULL);
239-
240-
return ret < 0 ? 0 : le16_to_cpu(ent->len);
241-
}
242-
EXPORT_SYMBOL(cmd_db_read_aux_data_len);
243-
244217
/**
245218
* cmd_db_read_slave_id - Get the slave ID for a given resource address
246219
*

‎include/soc/qcom/cmd-db.h‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ enum cmd_db_hw_type {
1818
#if IS_ENABLED(CONFIG_QCOM_COMMAND_DB)
1919
u32 cmd_db_read_addr(const char *resource_id);
2020

21-
int cmd_db_read_aux_data(const char *resource_id, u8 *data, size_t len);
22-
23-
size_t cmd_db_read_aux_data_len(const char *resource_id);
21+
const void *cmd_db_read_aux_data(const char *resource_id, size_t *len);
2422

2523
enum cmd_db_hw_type cmd_db_read_slave_id(const char *resource_id);
2624

@@ -29,12 +27,8 @@ int cmd_db_ready(void);
2927
static inline u32 cmd_db_read_addr(const char *resource_id)
3028
{ return 0; }
3129

32-
static inline int cmd_db_read_aux_data(const char *resource_id, u8 *data,
33-
size_t len)
34-
{ return -ENODEV; }
35-
36-
static inline size_t cmd_db_read_aux_data_len(const char *resource_id)
37-
{ return -ENODEV; }
30+
static inline const void *cmd_db_read_aux_data(const char *resource_id, size_t *len)
31+
{ return ERR_PTR(-ENODEV); }
3832

3933
static inline enum cmd_db_hw_type cmd_db_read_slave_id(const char *resource_id)
4034
{ return -ENODEV; }

0 commit comments

Comments
 (0)