summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Clark <robclark@freedesktop.org>2018-07-23 09:42:22 -0400
committerRob Clark <robclark@freedesktop.org>2018-07-30 12:18:58 -0400
commit2932a03180b9224b9d44a83c2ee299f19107f92d (patch)
treeeffee72e34af4637a12adf9467886090aa975c02
parentfcbf206aa293af2d478e48dc45e4e8b3af0e7737 (diff)
downloadexternal_libdrm-2932a03180b9224b9d44a83c2ee299f19107f92d.tar.gz
external_libdrm-2932a03180b9224b9d44a83c2ee299f19107f92d.tar.bz2
external_libdrm-2932a03180b9224b9d44a83c2ee299f19107f92d.zip
freedreno: small cleanup
Make cheezy growable array thing less open-coded before adding more. Signed-off-by: Rob Clark <robclark@freedesktop.org>
-rw-r--r--freedreno/msm/msm_priv.h26
-rw-r--r--freedreno/msm/msm_ringbuffer.c32
2 files changed, 31 insertions, 27 deletions
diff --git a/freedreno/msm/msm_priv.h b/freedreno/msm/msm_priv.h
index 776859a4d..ee0eecb83 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 9812d58b9..a5f9861c7 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);