drm: consolidate common list implementations
Subsystems (2)
PATCH 1/4 drm: consolidate common list implementations
This is used by radeon and freedreno and will be used by amdgpu. I looked at switching to libdrm_lists.h, but it's pretty horrible. E.g., DRMLISTFOREACHENTRYSAFE.
--- Makefile.sources | 3 +- freedreno/Makefile.sources | 3 +- freedreno/freedreno_priv.h | 2 +- freedreno/list.h | 137 --------------------------------------------- tests/radeon/list.h | 137 --------------------------------------------- tests/radeon/rbo.h | 2 +- util_double_list.h | 137 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 142 insertions(+), 279 deletions(-) delete mode 100644 freedreno/list.h delete mode 100644 tests/radeon/list.h create mode 100644 util_double_list.h
Makefile.sources +2 -1
@@ -8,7 +8,8 @@ LIBDRM_FILES := \ xf86drmMode.c \ xf86atomic.h \ libdrm.h \ - libdrm_lists.h + libdrm_lists.h \ + util_double_list.h LIBDRM_H_FILES := \ xf86drm.h \
freedreno/Makefile.sources +1 -2
@@ -9,8 +9,7 @@ LIBDRM_FREEDRENO_FILES := \ msm/msm_drm.h \ msm/msm_pipe.c \ msm/msm_priv.h \ - msm/msm_ringbuffer.c \ - list.h + msm/msm_ringbuffer.c LIBDRM_FREEDRENO_KGSL_FILES := \ kgsl/kgsl_bo.c \
freedreno/freedreno_priv.h +1 -1
@@ -48,7 +48,7 @@#include "xf86drm.h" #include "xf86atomic.h" -#include "list.h" +#include "util_double_list.h" #include "freedreno_drmif.h" #include "freedreno_ringbuffer.h"
freedreno/list.h deleted +0 -137
137 lines not on this page · raw message
tests/radeon/list.h deleted +0 -137
137 lines not on this page · raw message
tests/radeon/rbo.h +1 -1
@@ -26,7 +26,7 @@ #ifndef RBO_H #define RBO_H -#include "list.h" +#include "util_double_list.h" struct rbo { struct list_head list;
util_double_list.h new file +137 -0
137 lines not on this page · raw message
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/4 drm: add util_math.h
Used by amdgpu, could be used by other components.
--- Makefile.sources | 3 ++- util_math.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 util_math.h
Makefile.sources +2 -1
@@ -9,7 +9,8 @@ LIBDRM_FILES := \ xf86atomic.h \ libdrm.h \ libdrm_lists.h \ - util_double_list.h + util_double_list.h \ + util_math.h LIBDRM_H_FILES := \ xf86drm.h \
util_math.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright 2014 Advanced Micro Devices, Inc. +* +* 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 _UTIL_MATH_H_ +#define _UTIL_MATH_H_ + +#define MIN2 (A ,B ) ( (A)<(B) ? (A) : (B) ) +#define MAX2 (A ,B ) ( (A)>(B) ? (A) : (B) ) + +#define ALIGN ( value, alignment ) ( ((value) + (alignment) - 1) & ~((alignment) - 1) ) + +#endif /*_UTIL_MATH_H_*/
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/4 drm: add libdrm_amdgpu (v3)
In reply to Alex DeucherThis is the new ioctl wrapper used by the new admgpu driver. It's primarily used by xf86-video-amdgpu and mesa.
v2: fix amdgpu_drm.h install
v3: Integrate some of the sugestions from Emil:
clean up Makefile.am, configure.ac
capitalize header guards
fix _FILE_OFFSET_BITS with config.h
use drm_mmap/drm_munmap
Remove unused ARRAY_SIZE macro
use shared list implementation
use shared math implementation
use drmGetNodeTypeFromFd helper
--- Makefile.am | 5 + Makefile.sources | 1 + amdgpu/Makefile.am | 53 ++ amdgpu/amdgpu.h | 1276 ++++++++++++++++++++++++++++++++++++++++++++ amdgpu/amdgpu_bo.c | 626 ++++++++++++++++++++++ amdgpu/amdgpu_cs.c | 981 ++++++++++++++++++++++++++++++++++ amdgpu/amdgpu_device.c | 241 +++++++++ amdgpu/amdgpu_gpu_info.c | 275 ++++++++++ amdgpu/amdgpu_internal.h | 208 ++++++++ amdgpu/amdgpu_vamgr.c | 169 ++++++ amdgpu/libdrm_amdgpu.pc.in | 10 + amdgpu/util_hash.c | 382 +++++++++++++ amdgpu/util_hash.h | 99 ++++ amdgpu/util_hash_table.c | 257 +++++++++ amdgpu/util_hash_table.h | 65 +++ configure.ac | 19 + include/drm/amdgpu_drm.h | 600 +++++++++++++++++++++ 17 files changed, 5267 insertions(+) create mode 100644 amdgpu/Makefile.am create mode 100644 amdgpu/amdgpu.h create mode 100644 amdgpu/amdgpu_bo.c create mode 100644 amdgpu/amdgpu_cs.c create mode 100644 amdgpu/amdgpu_device.c create mode 100644 amdgpu/amdgpu_gpu_info.c create mode 100644 amdgpu/amdgpu_internal.h create mode 100644 amdgpu/amdgpu_vamgr.c create mode 100644 amdgpu/libdrm_amdgpu.pc.in create mode 100644 amdgpu/util_hash.c create mode 100644 amdgpu/util_hash.h create mode 100644 amdgpu/util_hash_table.c create mode 100644 amdgpu/util_hash_table.h create mode 100644 include/drm/amdgpu_drm.h
Makefile.am +5 -0
@@ -57,6 +57,10 @@ if HAVE_RADEON RADEON_SUBDIR = radeon endif +if HAVE_AMDGPU +AMDGPU_SUBDIR = amdgpu +endif + if HAVE_OMAP OMAP_SUBDIR = omap endif
@@ -79,6 +83,7 @@ SUBDIRS = \ $(INTEL_SUBDIR) \ $(NOUVEAU_SUBDIR) \ $(RADEON_SUBDIR) \ + $(AMDGPU_SUBDIR) \ $(OMAP_SUBDIR) \ $(EXYNOS_SUBDIR) \ $(FREEDRENO_SUBDIR) \
Makefile.sources +1 -0
@@ -28,6 +28,7 @@ LIBDRM_INCLUDE_H_FILES := \ include/drm/qxl_drm.h \ include/drm/r128_drm.h \ include/drm/radeon_drm.h \ + include/drm/amdgpu_drm.h \ include/drm/savage_drm.h \ include/drm/sis_drm.h \ include/drm/tegra_drm.h \
amdgpu/Makefile.am new file +53 -0
53 lines not on this page · raw message
amdgpu/amdgpu.h new file +1276 -0
1,276 lines not on this page · raw message
amdgpu/amdgpu_bo.c new file +626 -0
626 lines not on this page · raw message
amdgpu/amdgpu_cs.c new file +981 -0
981 lines not on this page · raw message
amdgpu/amdgpu_device.c new file +241 -0
40 lines not on this page · raw message
amdgpu/amdgpu_gpu_info.c new file +275 -0
275 lines not on this page · raw message
amdgpu/amdgpu_internal.h new file +208 -0
208 lines not on this page · raw message
amdgpu/amdgpu_vamgr.c new file +169 -0
169 lines not on this page · raw message
amdgpu/util_hash.c new file +382 -0
382 lines not on this page · raw message
amdgpu/util_hash.h new file +99 -0
99 lines not on this page · raw message
amdgpu/util_hash_table.c new file +257 -0
257 lines not on this page · raw message
amdgpu/util_hash_table.h new file +65 -0
65 lines not on this page · raw message
include/drm/amdgpu_drm.h new file +600 -0
600 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Part of the diff is not shown here. View the raw message.
PATCH 4/4 drm: add tests/amdgpu (v2)
In reply to Alex DeucherThis adds some basic unit tests for the new amdgpu driver.
v2: use common util_math.h
--- configure.ac | 23 ++ tests/Makefile.am | 6 + tests/amdgpu/Makefile.am | 24 ++ tests/amdgpu/amdgpu_test.c | 241 +++++++++++++ tests/amdgpu/amdgpu_test.h | 119 +++++++ tests/amdgpu/basic_tests.c | 676 ++++++++++++++++++++++++++++++++++++ tests/amdgpu/bo_tests.c | 151 ++++++++ tests/amdgpu/cs_tests.c | 319 +++++++++++++++++ tests/amdgpu/uvd_messages.h | 813 ++++++++++++++++++++++++++++++++++++++++++++ tests/kmstest/main.c | 1 + 10 files changed, 2373 insertions(+) create mode 100644 tests/amdgpu/Makefile.am create mode 100644 tests/amdgpu/amdgpu_test.c create mode 100644 tests/amdgpu/amdgpu_test.h create mode 100644 tests/amdgpu/basic_tests.c create mode 100644 tests/amdgpu/bo_tests.c create mode 100644 tests/amdgpu/cs_tests.c create mode 100644 tests/amdgpu/uvd_messages.h
configure.ac +23 -0
@@ -350,6 +350,28 @@ fi AM_CONDITIONAL(HAVE_AMDGPU, [test "x$AMDGPU" = xyes]) if test "x$AMDGPU" = xyes; then AC_DEFINE(HAVE_AMDGPU, 1, [Have amdgpu support]) + + # Detect cunit library + PKG_CHECK_MODULES([CUNIT], [cunit >= 2.1], [have_cunit=yes], [have_cunit=no]) + + # If pkg-config does not find cunit, check it using AC_CHECK_LIB. We + # do this because Debian (Ubuntu) lacks pkg-config file for cunit. + if test "x${have_cunit}" = "xno"; then + AC_CHECK_LIB([cunit], [CU_initialize_registry], [have_cunit=yes], [have_cunit=no]) + if test "x${have_cunit}" = "xyes"; then + CUNIT_LIBS="-lcunit" + CUNIT_CFLAGS="" + AC_SUBST([CUNIT_LIBS]) + AC_SUBST([CUNIT_CFLAGS]) + fi + fi + + AM_CONDITIONAL(HAVE_CUNIT, [test "x$have_cunit" != "xno"]) + AC_DEFINE(HAVE_CUNIT, [test "x$have_cunit" != "xno"], [Enable CUNIT Have amdgpu support]) + + if test "x$have_cunit" = "xno"; then + AC_MSG_WARN([Could not find cunit library. Disabling amdgpu tests]) + fi fi AM_CONDITIONAL(HAVE_TEGRA, [test "x$TEGRA" = xyes])
@@ -466,6 +488,7 @@ AC_CONFIG_FILES([ tests/kmstest/Makefile tests/proptest/Makefile tests/radeon/Makefile + tests/amdgpu/Makefile tests/vbltest/Makefile tests/exynos/Makefile tests/tegra/Makefile
tests/Makefile.am +6 -0
@@ -8,6 +8,12 @@ if HAVE_RADEON SUBDIRS += radeon endif +if HAVE_AMDGPU +if HAVE_CUNIT +SUBDIRS += amdgpu +endif +endif + if HAVE_EXYNOS SUBDIRS += exynos endif
tests/amdgpu/Makefile.am new file +24 -0
@@ -0,0 +1,24 @@ +AM_CFLAGS = \ + -I $(top_srcdir)/include/drm \ + -I $(top_srcdir)/amdgpu \ + -I $(top_srcdir) + +LDADD = $(top_builddir)/libdrm.la \ + $(top_builddir)/amdgpu/libdrm_amdgpu.la + +if HAVE_INSTALL_TESTS +bin_PROGRAMS = \ + amdgpu_test +else +noinst_PROGRAMS = \ + amdgpu_test +endif + +amdgpu_test_CPPFLAGS = $(CUNIT_CFLAGS) +amdgpu_test_LDFLAGS = $(CUNIT_LIBS) + +amdgpu_test_SOURCES = \ + amdgpu_test.c \ + basic_tests.c \ + bo_tests.c \ + cs_tests.c
tests/amdgpu/amdgpu_test.c new file +241 -0
241 lines not on this page · raw message
tests/amdgpu/amdgpu_test.h new file +119 -0
119 lines not on this page · raw message
tests/amdgpu/basic_tests.c new file +676 -0
676 lines not on this page · raw message
tests/amdgpu/bo_tests.c new file +151 -0
151 lines not on this page · raw message
tests/amdgpu/cs_tests.c new file +319 -0
319 lines not on this page · raw message
tests/amdgpu/uvd_messages.h new file +813 -0
813 lines not on this page · raw message
tests/kmstest/main.c +1 -0
@@ -62,6 +62,7 @@ static const char *drivers[] = {"nouveau" ,"vmwgfx" ,"exynos" , +"amdgpu" ,"imx-drm" ,"rockchip" ,NULL
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 4/4] drm: add tests/amdgpu (v2)
Hi Alex,
Quoted 4 lines · Alex Deucher
This adds some basic unit tests for the new amdgpu driver.
v2: use common
util_math.h
Can I put forward a few suggestions:
- Can we use calloc over malloc. It will likely save you/others some
headaches in the future.
- Use capital letters for header guards
- Annotate the CU_SuiteInfo/CU_TestInfo as static.
Quoted 32 lines
Signed-off-by Alex Deucher <[email protected]>--- configure.ac | 23 ++ tests/Makefile.am | 6 + tests/amdgpu/Makefile.am | 24 ++ tests/amdgpu/amdgpu_test.c | 241 +++++++++++++ tests/amdgpu/amdgpu_test.h | 119 +++++++ tests/amdgpu/basic_tests.c | 676 ++++++++++++++++++++++++++++++++++++ tests/amdgpu/bo_tests.c | 151 ++++++++ tests/amdgpu/cs_tests.c | 319 +++++++++++++++++ tests/amdgpu/uvd_messages.h | 813 ++++++++++++++++++++++++++++++++++++++++++++ tests/kmstest/main.c | 1 + 10 files changed, 2373 insertions(+) create mode 100644 tests/amdgpu/Makefile.am create mode 100644 tests/amdgpu/amdgpu_test.c create mode 100644 tests/amdgpu/amdgpu_test.h create mode 100644 tests/amdgpu/basic_tests.c create mode 100644 tests/amdgpu/bo_tests.c create mode 100644 tests/amdgpu/cs_tests.c create mode 100644 tests/amdgpu/uvd_messages.htests/amdgpu/Makefile.am new file +3
-0@@ -0,0 +1,24 @@ +LDADD = $(top_builddir)/libdrm.la \ + $(top_builddir)/amdgpu/libdrm_amdgpu.la +
...
Quoted 1 line
+amdgpu_test_LDFLAGS = $(CUNIT_LIBS)
LDFLAGS should not be used for LIBS (normally) - please fold it with LDADD above;
amdgpu_test_LDADD = \
$(top_builddir)/libdrm.la \
$(top_builddir)/amdgpu/libdrm_amdgpu.la \
$(CUNIT_LIBS)
tests/amdgpu/Makefile.am line 24
Quoted 5 lines
tests/amdgpu/Makefile.am new file +5
-0+amdgpu_test_SOURCES = \ + amdgpu_test.c \ + basic_tests.c \ + bo_tests.c \ + cs_tests.c
Please add the headers in the list.amdgpu_test.huvd_messages.h
tests/amdgpu/amdgpu_test.c
Quoted 8 lines
tests/amdgpu/amdgpu_test.c new file +1
-0@@ -0,0 +1,241 @@ +int drm_amdgpu[MAX_CARDS_SUPPORTED ];
We're using only a single one in the tests. Why the array ?
tests/amdgpu/amdgpu_test.c line 117
Quoted 5 lines
tests/amdgpu/amdgpu_test.c new file +4
-0+int main (int argc,char **argv) +{ +for (i =0 ; i <MAX_CARDS_SUPPORTED ; i++) + drm_amdgpu[i] =0 ;
0 is a valid fd number.
tests/amdgpu/amdgpu_test.c line 149
Quoted 7 lines
tests/amdgpu/amdgpu_test.c new file +7
-0+/* Try to open all possible radeon connections +* Right now: Open only the 0. +*/ +printf ("Try to open the card 0..\n" ); + drm_amdgpu[0 ] =open ("/dev/dri/card0" ,O_RDWR |O_CLOEXEC ); + +if (drm_amdgpu[0 ] ==1 ) {
1 is a valid fd number. Perhaps < 0 ?
Quoted 31 lines
tests/amdgpu/amdgpu_test.c new file +31
-0+/** Display version of DRM driver */ +drmVersionPtr retval; +drm_version_t *version =drmMalloc (sizeof (*version)); + + version->name_len =0 ; + version->name =NULL ; + version->date_len =0 ; + version->date =NULL ; + version->desc_len =0 ; + version->desc =NULL ; + +if (drmIoctl (drm_amdgpu[0 ],DRM_IOCTL_VERSION , version)) { +perror ("Could not get DRM driver version\n" ); +drmFree (version); +exit (EXIT_FAILURE ); + } + +if (version->name_len) + version->name =drmMalloc (version->name_len +1 ); +if (version->date_len) + version->date =drmMalloc (version->date_len +1 ); +if (version->desc_len) + version->desc =drmMalloc (version->desc_len +1 ); + +if (drmIoctl (drm_amdgpu[0 ],DRM_IOCTL_VERSION , version)) { +perror ("Could not get information about DRM driver" ); +drmFree (version); +exit (EXIT_FAILURE ); + } + +/* The results might not be null-terminated strings. Add zero */
tests/amdgpu/amdgpu_test.c line 194
Quoted 10 lines
tests/amdgpu/amdgpu_test.c new file +10
-0+if (version->name_len) + version->name[version->name_len] ='\0' ; +if (version->date_len) + version->date[version->date_len] ='\0' ; +if (version->desc_len) + version->desc[version->desc_len] ='\0' ; + +printf ("DRM Driver: Name: [%s] : Date [%s] : Description [%s]\n" , + version->name, version->date, version->desc); +
Please use drmGetVersion/drmFreeVersion rather than open coding it. This implementation leaks memory.
tests/amdgpu/amdgpu_test.c line 200
Quoted 6 lines
tests/amdgpu/amdgpu_test.c new file +6
-0+drmFree (version); + +/* Initialize test suites to run */ + +/* initialize the CUnit test registry */ +if (CUE_SUCCESS !=CU_initialize_registry ())
Swap CUE_SUCCESS and CU_initialize_registry() ?
Quoted 1 line
+ return
CU_get_error();
Close the fd before return/exit(). The rest of the could use it as well.
tests/amdgpu/amdgpu_test.c line 206
Quoted 5 lines
tests/amdgpu/amdgpu_test.c new file +5
-0+ +/* Register suites. */ +if (CU_register_suites (suites) !=CUE_SUCCESS ) { +fprintf (stderr,"suite registration failed - %s\n" , +CU_get_error_msg ());
Not familiar with CUnit, but looks like we should use CU_cleanup_registry() here. Same for the rest of the file ?
Quoted 9 lines
tests/amdgpu/amdgpu_test.c new file +2
-0+exit (EXIT_FAILURE ); + }tests/amdgpu/basic_tests.c new file +0
-0
tests/amdgpu/basic_tests.c line 56
Quoted 5 lines
tests/amdgpu/basic_tests.c new file +4
-0+#define SDMA_PKT_HEADER_op_offset 0 +#define SDMA_PKT_HEADER_op_mask 0x000000FF +#define SDMA_PKT_HEADER_op_shift 0 +#define SDMA_PKT_HEADER_OP (x) (((x) & SDMA_PKT_HEADER_op_mask) << SDMA_PKT_HEADER_op_shift)
Unused ?
tests/amdgpu/basic_tests.c line 433
Quoted 4 lines
tests/amdgpu/basic_tests.c new file +3
-0+static void amdgpu_command_submission_sdma_const_fill (void ) +{ + pm4 =malloc (pm4_dw *4 );
pm4 = calloc(pm4_dw, sizeof(*pm4));
tests/amdgpu/basic_tests.c
Quoted 2 lines
tests/amdgpu/basic_tests.c new file +2
-0+ loop =0 ; +while (loop <3 ) {
Bikeshed: Most of the patch uses for loops
tests/amdgpu/basic_tests.c line 501
Quoted 4 lines
tests/amdgpu/basic_tests.c new file +3
-0+} +static void amdgpu_command_submission_sdma_copy_linear (void ) +{
Same suggestions as amdgpu_command_submission_sdma_const_fill
Cheers
Emil
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 4 lines · Alex Deucher
This is used by radeon and freedreno and will be used by amdgpu. I looked at switching to
libdrm_lists.h, but it's pretty horrible. E.g., DRMLISTFOREACHENTRYSAFE.
It does have one advantage though - it's typeless. Thus it allows nouveau and intel to have their custom list implementations. For example
- struct nouveau_list (plain double list)
- struct {mem_,}block (double list with some extra bookkeeping)
This change might cause small issues with Jerome's bof replay tool (joujou), although I should have it merged with libdrm as this lands (or shortly after).
With the comments sent out earlier for 3/4 (v4) and 4/4(v2), feel free to add Reviewed-by: Emil Velikov <[email protected]>, fwiw.
Thanks
Emil
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel