summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom St Denis <tom.stdenis@amd.com>2019-03-08 10:21:09 -0500
committerTom St Denis <tom.stdenis@amd.com>2019-03-08 10:21:09 -0500
commit0319b0ce62509c89d36db31c1911bb64b992a4a5 (patch)
tree926b0d661a5935cf29d818464985b466db95b247
parentfc51f662cbc3d221f5aa7e49f92858075910fb4f (diff)
re-factor umr_update() to create umr_update_string()
Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
-rw-r--r--src/lib/update.c60
-rw-r--r--src/umr.h1
2 files changed, 37 insertions, 24 deletions
diff --git a/src/lib/update.c b/src/lib/update.c
index dbb0b9b..ffda925 100644
--- a/src/lib/update.c
+++ b/src/lib/update.c
@@ -391,6 +391,38 @@ static int do_del(char **ptr, struct umr_asic *asic)
return 0;
}
+int umr_update_string(struct umr_asic *asic, char *sdata)
+{
+ int r;
+
+ // parse script
+ while (*sdata) {
+ consume_whitespace(&sdata);
+
+ // should be pointing to "add/edit/del" now
+ if (!memcmp(sdata, "add", 3)) {
+ sdata += 3;
+ if ((r = do_add(&sdata, asic)))
+ return r;
+ } else if (!memcmp(sdata, "edit", 4)) {
+ sdata += 4;
+ r = do_edit(&sdata, asic);
+ if (r)
+ return r;
+ } else if (!memcmp(sdata, "del", 3)) {
+ sdata += 3;
+ r = do_del(&sdata, asic);
+ if (r)
+ return r;
+ } else if (*sdata) {
+ fprintf(stderr, "[ERROR]: Unknown update command [%s]\n", sdata);
+ *sdata = 0;
+ return -1;
+ }
+ }
+ return 0;
+}
+
/**
* umr_update - Update an ASIC device from script
*
@@ -400,9 +432,8 @@ static int do_del(char **ptr, struct umr_asic *asic)
*/
int umr_update(struct umr_asic *asic, char *script)
{
- int fd;
+ int fd, s;
void *smem;
- char *sdata;
unsigned len, r;
fd = open(script, O_RDWR);
@@ -411,7 +442,7 @@ int umr_update(struct umr_asic *asic, char *script)
return -1;
}
len = lseek(fd, 0, SEEK_END) + 1;
- sdata = smem = calloc(1, len);
+ smem = calloc(1, len);
lseek(fd, 0, SEEK_SET);
if (!smem) {
close(fd);
@@ -425,26 +456,7 @@ int umr_update(struct umr_asic *asic, char *script)
return 0;
}
- // parse script
- while (*sdata) {
- consume_whitespace(&sdata);
-
- // should be pointing to "add/edit/del" now
- if (!memcmp(sdata, "add", 3)) {
- sdata += 3;
- if (do_add(&sdata, asic))
- *sdata = 0;
- } else if (!memcmp(sdata, "edit", 4)) {
- sdata += 4;
- do_edit(&sdata, asic);
- } else if (!memcmp(sdata, "del", 3)) {
- sdata += 3;
- do_del(&sdata, asic);
- } else if (*sdata) {
- fprintf(stderr, "[ERROR]: Unknown update command [%s]\n", sdata);
- *sdata = 0;
- }
- }
+ s = umr_update_string(asic, smem);
free(smem);
- return 0;
+ return s;
}
diff --git a/src/umr.h b/src/umr.h
index 218b95b..febd390 100644
--- a/src/umr.h
+++ b/src/umr.h
@@ -672,6 +672,7 @@ void umr_close_asic(struct umr_asic *asic); // call this to close a fully open a
int umr_query_drm(struct umr_asic *asic, int field, void *ret, int size);
void umr_enumerate_devices(void);
int umr_update(struct umr_asic *asic, char *script);
+int umr_update_string(struct umr_asic *asic, char *sdata);
/* lib helpers */
int umr_get_wave_status(struct umr_asic *asic, unsigned se, unsigned sh, unsigned cu, unsigned simd, unsigned wave, struct umr_wave_status *ws);