From: ville.syrjala@linux.intel.com
To: intel-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Subject: [PATCH 08/22] drm: Add drm_dynarray
Date: Thu, 6 Jul 2017 23:24:28 +0300 [thread overview]
Message-ID: <20170706202442.5394-9-ville.syrjala@linux.intel.com> (raw)
In-Reply-To: <20170706202442.5394-1-ville.syrjala@linux.intel.com>
From: Ville Syrjälä <ville.syrjala@linux.intel.com>
Add a small helper that gives us dynamically growing arrays. We have a
couple hand rolled implementations of this in the atomic code, which we
can unify to use a common implementation.
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
Documentation/gpu/drm-utils.rst | 15 +++++++
Documentation/gpu/index.rst | 1 +
drivers/gpu/drm/Makefile | 2 +-
drivers/gpu/drm/drm_dynarray.c | 97 +++++++++++++++++++++++++++++++++++++++++
include/drm/drm_dynarray.h | 54 +++++++++++++++++++++++
5 files changed, 168 insertions(+), 1 deletion(-)
create mode 100644 Documentation/gpu/drm-utils.rst
create mode 100644 drivers/gpu/drm/drm_dynarray.c
create mode 100644 include/drm/drm_dynarray.h
diff --git a/Documentation/gpu/drm-utils.rst b/Documentation/gpu/drm-utils.rst
new file mode 100644
index 000000000000..bff8c899d7cd
--- /dev/null
+++ b/Documentation/gpu/drm-utils.rst
@@ -0,0 +1,15 @@
+=============
+DRM Utilities
+=============
+
+Dynamic arrays
+--------------
+
+.. kernel-doc:: drivers/gpu/drm/drm_dynarray.c
+ :doc: Dynamic arrays
+
+.. kernel-doc:: drivers/gpu/drm/drm_dynarray.c
+ :export:
+
+.. kernel-doc:: include/drm/drm_dynarray.h
+ :internal:
diff --git a/Documentation/gpu/index.rst b/Documentation/gpu/index.rst
index 35d673bf9b56..b7d196e5c70d 100644
--- a/Documentation/gpu/index.rst
+++ b/Documentation/gpu/index.rst
@@ -10,6 +10,7 @@ Linux GPU Driver Developer's Guide
drm-kms
drm-kms-helpers
drm-uapi
+ drm-utils
i915
meson
pl111
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 24a066e1841c..b637a34df388 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -3,7 +3,7 @@
# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
drm-y := drm_auth.o drm_bufs.o drm_cache.o \
- drm_context.o drm_dma.o \
+ drm_context.o drm_dma.o drm_dynarray.o \
drm_file.o drm_gem.o drm_ioctl.o drm_irq.o \
drm_lock.o drm_memory.o drm_drv.o \
drm_scatter.o drm_pci.o \
diff --git a/drivers/gpu/drm/drm_dynarray.c b/drivers/gpu/drm/drm_dynarray.c
new file mode 100644
index 000000000000..69a8819ecb62
--- /dev/null
+++ b/drivers/gpu/drm/drm_dynarray.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2017 Intel Corp.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <drm/drm_dynarray.h>
+
+/**
+ * DOC: Dynamic arrays
+ *
+ * Helper that provides dynamically growing arrays. The array
+ * must be initilaized to specify the size of each element, and
+ * space can be reserved in the array by specifying the element
+ * index to be used.
+ */
+
+/**
+ * drm_dynarray_init - Initialize the dynamic array
+ * @dynarr: the dynamic array
+ * @elem_size: size of each element in bytes
+ *
+ * Initialize the dynamic array and specify the size of
+ * each element of the array.
+ */
+void drm_dynarray_init(struct drm_dynarray *dynarr,
+ unsigned int elem_size)
+{
+ memset(dynarr, 0, sizeof(*dynarr));
+ dynarr->elem_size = elem_size;
+}
+EXPORT_SYMBOL(drm_dynarray_init);
+
+/**
+ * drm_dynarray_fini - Finalize the dynamic array
+ * @dynarr: the dynamic array
+ *
+ * Finalize the dynamic array, ie. free the memory
+ * used by the array.
+ */
+void drm_dynarray_fini(struct drm_dynarray *dynarr)
+{
+ kfree(dynarr->elems);
+ memset(dynarr, 0, sizeof(*dynarr));
+}
+EXPORT_SYMBOL(drm_dynarray_fini);
+
+/**
+ * drm_dynarray_reserve - Reserve space in the dynamic array
+ * @dynarr: the dynamic array
+ * @index: the index of the element to reserve
+ *
+ * Grow the array sufficiently to make sure @index points
+ * to a valid memory location within the array.
+ */
+int drm_dynarray_reserve(struct drm_dynarray *dynarr,
+ unsigned int index)
+{
+ unsigned int num_elems = index + 1;
+ unsigned int old_num_elems = dynarr->num_elems;
+ void *elems;
+
+ if (num_elems <= old_num_elems)
+ return 0;
+
+ elems = krealloc(dynarr->elems,
+ num_elems * dynarr->elem_size, GFP_KERNEL);
+ if (!elems)
+ return -ENOMEM;
+
+ dynarr->elems = elems;
+ dynarr->num_elems = num_elems;
+
+ memset(drm_dynarray_elem(dynarr, old_num_elems), 0,
+ (num_elems - old_num_elems) * dynarr->elem_size);
+
+ return 0;
+}
+EXPORT_SYMBOL(drm_dynarray_reserve);
diff --git a/include/drm/drm_dynarray.h b/include/drm/drm_dynarray.h
new file mode 100644
index 000000000000..c8cd088a3a3b
--- /dev/null
+++ b/include/drm/drm_dynarray.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 Intel Corp.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef DRM_DYNARRAY_H
+#define DRM_DYNARRAY_H
+
+struct drm_dynarray {
+ void *elems;
+ unsigned int elem_size, num_elems;
+};
+
+/**
+ * drm_dynarray_elem - Return a pointer to an element
+ * @dynarr: the dynamic array
+ * @index: the index of the element
+ *
+ * Returns:
+ * A pointer to the element at @index in the array.
+ */
+static inline void *drm_dynarray_elem(const struct drm_dynarray *dynarr,
+ unsigned int index)
+{
+ if (index >= dynarr->num_elems)
+ return NULL;
+ return dynarr->elems + index * dynarr->elem_size;
+}
+
+int drm_dynarray_reserve(struct drm_dynarray *dynarr,
+ unsigned int index);
+
+void drm_dynarray_init(struct drm_dynarray *dynarr,
+ unsigned int elem_size);
+void drm_dynarray_fini(struct drm_dynarray *dynarr);
+
+#endif
--
2.13.0
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2017-07-06 20:24 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-06 20:24 [PATCH v2 00/22] drm/i915: Fix pre-g4x GPU reset, again (v2) ville.syrjala
2017-07-06 20:24 ` [PATCH 01/22] drm/i915: Pass the new crtc state to color management code ville.syrjala
2017-07-06 20:24 ` [PATCH 02/22] drm/i915: Pass the crtc state explicitly to intel_pipe_update_start/end() ville.syrjala
2017-07-06 20:24 ` [PATCH 03/22] drm/i915: Eliminate obj->state usage in g4x/vlv/chv wm computation ville.syrjala
2017-07-06 20:24 ` [PATCH 04/22] drm/i915: Pass proper old/new states to intel_plane_atomic_check_with_state() ville.syrjala
2017-07-10 9:04 ` Maarten Lankhorst
2017-07-10 13:30 ` Ville Syrjälä
2017-07-10 14:59 ` [PATCH v2 " ville.syrjala
2017-07-06 20:24 ` [PATCH 05/22] drm/i915: Eliminate obj->state usage from pre/post plane update ville.syrjala
2017-07-06 20:24 ` [PATCH 06/22] drm/i915: Eliminate crtc->state usage from intel_update_pipe_config() ville.syrjala
2017-07-06 20:24 ` [PATCH 07/22] drm/i915: Eliminate crtc->state usage from intel_atomic_commit_tail and .crtc_update() ville.syrjala
2017-07-10 9:20 ` [Intel-gfx] " Maarten Lankhorst
2017-07-06 20:24 ` ville.syrjala [this message]
2017-07-06 20:24 ` [PATCH 09/22] drm/atomic: Convert state->connectors to drm_dynarray ville.syrjala
2017-07-06 20:24 ` [PATCH 10/22] drm/atomic: Remove pointless private object NULL state check ville.syrjala
2017-07-06 20:24 ` [PATCH 11/22] drm/atomic: Convert private_objs to drm_dynarray ville.syrjala
2017-07-06 20:24 ` [PATCH 12/22] drm/atomic: Make private objs proper objects ville.syrjala
2017-07-06 20:24 ` [PATCH 13/22] drm/atomic: Pass old state to __drm_atomic_helper_crtc_duplicate_state() & co. explicitly ville.syrjala
2017-07-06 20:24 ` [PATCH 14/22] drm/arm: s/old_state/old_mali_state/ ville.syrjala
2017-07-06 20:24 ` [PATCH 15/22] drm/mediatek: s/old_state/old_mtk_state/ ville.syrjala
2017-07-06 20:24 ` [PATCH 16/22] drm/atomic: Pass old state explicitly to .atomic_duplicate_state() ville.syrjala
2017-07-06 20:24 ` [PATCH 17/22] drm/atomic: Fix up the kernel docs for the state duplication functions ville.syrjala
2017-07-06 20:24 ` [PATCH 18/22] drm: Return the connector from drm_connector_get() ville.syrjala
2017-07-10 9:21 ` [Intel-gfx] " Maarten Lankhorst
2017-07-06 20:24 ` [PATCH 19/22] drm/i915% Store vma gtt offset in plane state ville.syrjala
2017-07-06 20:24 ` [PATCH 20/22] drm/i915: Refactor __intel_atomic_commit_tail() ville.syrjala
2017-07-06 20:24 ` [PATCH v3 21/22] drm/atomic: Introduce drm_atomic_helper_duplicate_commited_state() ville.syrjala
2017-07-07 12:03 ` [Intel-gfx] " Daniel Vetter
2017-07-07 13:21 ` Ville Syrjälä
2017-07-07 14:05 ` Daniel Vetter
2017-07-07 15:18 ` Ville Syrjälä
2017-07-10 6:43 ` Daniel Vetter
2017-07-10 9:31 ` Maarten Lankhorst
2017-07-10 12:18 ` Ville Syrjälä
2017-07-10 13:26 ` [Intel-gfx] " Maarten Lankhorst
2017-07-10 13:56 ` Ville Syrjälä
2017-07-10 14:47 ` Daniel Vetter
2017-07-06 20:24 ` [PATCH v5 22/22] drm/i915: Solve the GPU reset vs. modeset deadlocks with an rw_semaphore ville.syrjala
2017-07-10 6:48 ` Daniel Vetter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170706202442.5394-9-ville.syrjala@linux.intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox