Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Stephen Boyd and committed by
Andy Gross
ed3cafa7 84fa36eb

+30 -79
+19 -35
drivers/gpu/drm/msm/adreno/a6xx_gmu.c
··· 902 902 return ret; 903 903 } 904 904 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 - 925 905 /* Return the 'arc-level' for the given frequency */ 926 906 static u32 a6xx_gmu_get_arc_level(struct device *dev, unsigned long freq) 927 907 { ··· 929 949 } 930 950 931 951 static int a6xx_gmu_rpmh_arc_votes_init(struct device *dev, u32 *votes, 932 - unsigned long *freqs, int freqs_count, 933 - u16 *pri, int pri_count, 934 - u16 *sec, int sec_count) 952 + unsigned long *freqs, int freqs_count, const char *id) 935 953 { 936 954 int i, j; 955 + const u16 *pri, *sec; 956 + size_t pri_count, sec_count; 957 + 958 + pri = cmd_db_read_aux_data(id, &pri_count); 959 + /* 960 + * The data comes back as an array of unsigned shorts so adjust the 961 + * count accordingly 962 + */ 963 + pri_count >>= 1; 964 + if (!pri_count) 965 + return -EINVAL; 966 + 967 + sec = cmd_db_read_aux_data("mx.lvl", &sec_count); 968 + sec_count >>= 1; 969 + if (!sec_count) 970 + return -EINVAL; 937 971 938 972 /* Construct a vote for each frequency */ 939 973 for (i = 0; i < freqs_count; i++) { ··· 1006 1012 struct a6xx_gpu *a6xx_gpu = container_of(gmu, struct a6xx_gpu, gmu); 1007 1013 struct adreno_gpu *adreno_gpu = &a6xx_gpu->base; 1008 1014 struct msm_gpu *gpu = &adreno_gpu->base; 1009 - 1010 - u16 gx[16], cx[16], mx[16]; 1011 - u32 gxcount, cxcount, mxcount; 1012 1015 int ret; 1013 - 1014 - /* Get the list of available voltage levels for each component */ 1015 - gxcount = a6xx_gmu_rpmh_arc_cmds("gfx.lvl", gx, sizeof(gx)); 1016 - cxcount = a6xx_gmu_rpmh_arc_cmds("cx.lvl", cx, sizeof(cx)); 1017 - mxcount = a6xx_gmu_rpmh_arc_cmds("mx.lvl", mx, sizeof(mx)); 1018 1016 1019 1017 /* Build the GX votes */ 1020 1018 ret = a6xx_gmu_rpmh_arc_votes_init(&gpu->pdev->dev, gmu->gx_arc_votes, 1021 - gmu->gpu_freqs, gmu->nr_gpu_freqs, 1022 - gx, gxcount, mx, mxcount); 1019 + gmu->gpu_freqs, gmu->nr_gpu_freqs, "gfx.lvl"); 1023 1020 1024 1021 /* Build the CX votes */ 1025 1022 ret |= a6xx_gmu_rpmh_arc_votes_init(gmu->dev, gmu->cx_arc_votes, 1026 - gmu->gmu_freqs, gmu->nr_gmu_freqs, 1027 - cx, cxcount, mx, mxcount); 1023 + gmu->gmu_freqs, gmu->nr_gmu_freqs, "cx.lvl"); 1028 1024 1029 1025 return ret; 1030 1026 }
+8 -35
drivers/soc/qcom/cmd-db.c
··· 192 192 /** 193 193 * cmd_db_read_aux_data() - Query command db for aux data. 194 194 * 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 198 197 * 199 - * Return: size of data on success, errno otherwise 198 + * Return: pointer to data on success, error pointer otherwise 200 199 */ 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) 202 201 { 203 202 int ret; 204 203 const struct entry_header *ent; 205 204 const struct rsc_hdr *rsc_hdr; 206 - u16 ent_len; 207 - 208 - if (!data) 209 - return -EINVAL; 210 205 211 206 ret = cmd_db_get_header(id, &ent, &rsc_hdr); 212 207 if (ret) 213 - return ret; 208 + return ERR_PTR(ret); 214 209 215 - ent_len = le16_to_cpu(ent->len); 216 - if (len < ent_len) 217 - return -EINVAL; 210 + if (len) 211 + *len = le16_to_cpu(ent->len); 218 212 219 - len = min_t(u16, ent_len, len); 220 - memcpy(data, rsc_offset(rsc_hdr, ent), len); 221 - 222 - return len; 213 + return rsc_offset(rsc_hdr, ent); 223 214 } 224 215 EXPORT_SYMBOL(cmd_db_read_aux_data); 225 - 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 216 244 217 /** 245 218 * cmd_db_read_slave_id - Get the slave ID for a given resource address
+3 -9
include/soc/qcom/cmd-db.h
··· 18 18 #if IS_ENABLED(CONFIG_QCOM_COMMAND_DB) 19 19 u32 cmd_db_read_addr(const char *resource_id); 20 20 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); 24 22 25 23 enum cmd_db_hw_type cmd_db_read_slave_id(const char *resource_id); 26 24 ··· 27 29 static inline u32 cmd_db_read_addr(const char *resource_id) 28 30 { return 0; } 29 31 30 - static inline int cmd_db_read_aux_data(const char *resource_id, u8 *data, 31 - size_t len) 32 - { return -ENODEV; } 33 - 34 - static inline size_t cmd_db_read_aux_data_len(const char *resource_id) 35 - { return -ENODEV; } 32 + static inline const void *cmd_db_read_aux_data(const char *resource_id, size_t *len) 33 + { return ERR_PTR(-ENODEV); } 36 34 37 35 static inline enum cmd_db_hw_type cmd_db_read_slave_id(const char *resource_id) 38 36 { return -ENODEV; }