From 2932a03180b9224b9d44a83c2ee299f19107f92d Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 23 Jul 2018 09:42:22 -0400 Subject: [PATCH] freedreno: small cleanup Make cheezy growable array thing less open-coded before adding more. Signed-off-by: Rob Clark --- freedreno/msm/msm_priv.h | 26 ++++++++++++++++++++++++++ freedreno/msm/msm_ringbuffer.c | 32 +++++--------------------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/freedreno/msm/msm_priv.h b/freedreno/msm/msm_priv.h index 776859a..ee0eecb 100644 --- a/freedreno/msm/msm_priv.h +++ b/freedreno/msm/msm_priv.h @@ -101,4 +101,30 @@ static inline void get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns) tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000); } +/* + * Stupid/simple growable array implementation: + */ + +static inline void * +grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz) +{ + if ((nr + 1) > *max) { + if ((*max * 2) < (nr + 1)) + *max = nr + 5; + else + *max = *max * 2; + ptr = realloc(ptr, *max * sz); + } + return ptr; +} + +#define DECLARE_ARRAY(type, name) \ + unsigned nr_ ## name, max_ ## name; \ + type * name; + +#define APPEND(x, name) ({ \ + (x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \ + (x)->nr_ ## name ++; \ +}) + #endif /* MSM_PRIV_H_ */ diff --git a/freedreno/msm/msm_ringbuffer.c b/freedreno/msm/msm_ringbuffer.c index 9812d58..a5f9861 100644 --- a/freedreno/msm/msm_ringbuffer.c +++ b/freedreno/msm/msm_ringbuffer.c @@ -42,8 +42,7 @@ struct msm_cmd { struct fd_bo *ring_bo; /* reloc's table: */ - struct drm_msm_gem_submit_reloc *relocs; - uint32_t nr_relocs, max_relocs; + DECLARE_ARRAY(struct drm_msm_gem_submit_reloc, relocs); uint32_t size; }; @@ -58,22 +57,18 @@ struct msm_ringbuffer { */ struct { /* bo's table: */ - struct drm_msm_gem_submit_bo *bos; - uint32_t nr_bos, max_bos; + DECLARE_ARRAY(struct drm_msm_gem_submit_bo, bos); /* cmd's table: */ - struct drm_msm_gem_submit_cmd *cmds; - uint32_t nr_cmds, max_cmds; + DECLARE_ARRAY(struct drm_msm_gem_submit_cmd, cmds); } submit; /* should have matching entries in submit.bos: */ /* Note, only in parent ringbuffer */ - struct fd_bo **bos; - uint32_t nr_bos, max_bos; + DECLARE_ARRAY(struct fd_bo *, bos); /* should have matching entries in submit.cmds: */ - struct msm_cmd **cmds; - uint32_t nr_cmds, max_cmds; + DECLARE_ARRAY(struct msm_cmd *, cmds); /* List of physical cmdstream buffers (msm_cmd) assocated with this * logical fd_ringbuffer. @@ -170,23 +165,6 @@ fail: return NULL; } -static void *grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz) -{ - if ((nr + 1) > *max) { - if ((*max * 2) < (nr + 1)) - *max = nr + 5; - else - *max = *max * 2; - ptr = realloc(ptr, *max * sz); - } - return ptr; -} - -#define APPEND(x, name) ({ \ - (x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \ - (x)->nr_ ## name ++; \ -}) - static struct msm_cmd *current_cmd(struct fd_ringbuffer *ring) { struct msm_ringbuffer *msm_ring = to_msm_ringbuffer(ring); -- 2.7.4