Skip to contentSkip to conversation

drm: add libdrm_amdgpu

PATCH In review Alex Deucher 2 participants 3 messages Apr 21, 2015 – Apr 23, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm: add libdrm_amdgpu

This is the new ioctl wrapper used by the new admgpu driver. It's primarily used by xf86-video-amdgpu and mesa.

---
 Makefile.am                |    5 +
 amdgpu/Makefile.am         |   55 ++
 amdgpu/amdgpu.h            | 1278 ++++++++++++++++++++++++++++++++++++++++++++
 amdgpu/amdgpu_bo.c         |  622 +++++++++++++++++++++
 amdgpu/amdgpu_cs.c         |  981 ++++++++++++++++++++++++++++++++++
 amdgpu/amdgpu_device.c     |  242 +++++++++
 amdgpu/amdgpu_gpu_info.c   |  275 ++++++++++
 amdgpu/amdgpu_internal.h   |  210 ++++++++
 amdgpu/amdgpu_vamgr.c      |  169 ++++++
 amdgpu/libdrm_amdgpu.pc.in |   10 +
 amdgpu/util_double_list.h  |  146 +++++
 amdgpu/util_hash.c         |  382 +++++++++++++
 amdgpu/util_hash.h         |   99 ++++
 amdgpu/util_hash_table.c   |  257 +++++++++
 amdgpu/util_hash_table.h   |   65 +++
 amdgpu/util_math.h         |   32 ++
 configure.ac               |   20 +
 include/drm/amdgpu_drm.h   |  600 +++++++++++++++++++++
 18 files changed, 5448 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_double_list.h
 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 amdgpu/util_math.h
 create mode 100644 include/drm/amdgpu_drm.h
Makefile.am +5 -0
index 42d3d7f..5defeb2 100644
@@ -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) \
amdgpu/Makefile.am new file +55 -0

55 lines not on this page · raw message

amdgpu/amdgpu.h new file +1278 -0

1,278 lines not on this page · raw message

amdgpu/amdgpu_bo.c new file +622 -0

622 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 +242 -0

47 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 +210 -0

210 lines not on this page · raw message

amdgpu/amdgpu_vamgr.c new file +169 -0

169 lines not on this page · raw message

amdgpu/libdrm_amdgpu.pc.in new file +10 -0
new file mode 100644
index 0000000..417865e

Lines of this file are not shown. View the raw message.

amdgpu/util_double_list.h new file +146 -0

146 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

amdgpu/util_math.h new file +32 -0
new file mode 100644
index 0000000..b8de0f8

Lines of this file are not shown. View the raw message.

configure.ac +20 -0
index 155d577..509f2d4 100644

Lines of this file are not shown. View the 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.

#1 lore raw

PATCH 2/2 drm: add tests/amdgpu

This adds some basic unit tests for the new amdgpu driver.

---
 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
index 509f2d4..0019f73 100644
@@ -351,6 +351,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])
@@ -467,6 +489,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
index 069285f..a980b3d 100644
@@ -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
new file mode 100644
index 0000000..ba7339d
@@ -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
index 7d50f5b..f39364f 100644
@@ -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
#2 lore raw
In reply to Alex Deucher

Hi Alex,

Quoted 3 lines · Alex Deucher

This is the new ioctl wrapper used by the new admgpu driver. It's primarily used by xf86-video-amdgpu and mesa.

Glad to see amdgpu finally out :-)

Can we annotate the private symbols with drm_private, in both declaration and definition ? It will hide the symbols, plus will make the leap towards Solaris support a bit smaller.

Quoted 41 lines
---
 Makefile.am                |    5 +
 amdgpu/Makefile.am         |   55 ++
 amdgpu/amdgpu.h            | 1278 ++++++++++++++++++++++++++++++++++++++++++++
 amdgpu/amdgpu_bo.c         |  622 +++++++++++++++++++++
 amdgpu/amdgpu_cs.c         |  981 ++++++++++++++++++++++++++++++++++
 amdgpu/amdgpu_device.c     |  242 +++++++++
 amdgpu/amdgpu_gpu_info.c   |  275 ++++++++++
 amdgpu/amdgpu_internal.h   |  210 ++++++++
 amdgpu/amdgpu_vamgr.c      |  169 ++++++
 amdgpu/libdrm_amdgpu.pc.in |   10 +
 amdgpu/util_double_list.h  |  146 +++++
 amdgpu/util_hash.c         |  382 +++++++++++++
 amdgpu/util_hash.h         |   99 ++++
 amdgpu/util_hash_table.c   |  257 +++++++++
 amdgpu/util_hash_table.h   |   65 +++
 amdgpu/util_math.h         |   32 ++
 configure.ac               |   20 +
 include/drm/amdgpu_drm.h   |  600 +++++++++++++++++++++
 18 files changed, 5448 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_double_list.h
 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 amdgpu/util_math.h
 create mode 100644 include/drm/amdgpu_drm.h

amdgpu/Makefile.am

Quoted 5 lines
amdgpu/Makefile.am new file +2 -1
 
+AM_CFLAGS = \
+	$(WARN_CFLAGS)
 
-Wno-switch-enum \

From a quick look you should be OK without this. If that's not the case, it might be worth looking into ?

amdgpu/Makefile.am line 28

Quoted 2 lines
amdgpu/Makefile.am new file +2 -0
+	-I$(top_srcdir) \
+	-I$(top_srcdir)/amdgpu \

You can drop this line.

amdgpu/Makefile.am line 34

Quoted 6 lines
amdgpu/Makefile.am new file +6 -0
+	$(PTHREADSTUBS_CFLAGS) \
+	-I$(top_srcdir)/include/drm
+
+libdrm_amdgpu_la_LTLIBRARIES = libdrm_amdgpu.la
+libdrm_amdgpu_ladir = $(libdir)
+libdrm_amdgpu_la_LDFLAGS = -version-number 1:0:1 -no-undefined

Considering that this is the first public version shouldn't this be 1:0:0 ?

amdgpu/Makefile.am line 45

Quoted 11 lines
amdgpu/Makefile.am new file +11 -0
+libdrm_amdgpu_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
+
+libdrm_amdgpu_la_SOURCES = \
+	amdgpu_gpu_info.c \
+	amdgpu_device.c \
+	amdgpu_bo.c \
+	util_hash.c \
+	util_hash_table.c \
+	amdgpu_vamgr.c \
+	amdgpu_cs.c
+

Please include all files, and sort them alphabetically, something like:

amdgpu_bo.c
amdgpu_cs.c
amdgpu_device.c
amdgpu_gpu_info.c
amdgpu_internal.h
amdgpu_vamgr.c
util_double_list.h
util_hash.c
util_hash.h
util_hash_table.c
util_hash_table.h
util_math.h

One might want to drop util_double_list.h if you go for my suggestion below.

amdgpu/Makefile.am

Quoted 2 lines
amdgpu/Makefile.am new file +2 -0
+nodist_EXTRA_libdrm_amdgpu_la_SOURCES = dummy.cxx
+

There are no C++ sources or static libs based on such so you can drop this.

Quoted 1 line

+EXTRA_DIST = libdrm_amdgpu.pc.in

You don't need this.

amdgpu/amdgpu.h line 36

Quoted 6 lines
amdgpu/amdgpu.h new file +3 -0
 
+#ifndef _amdgpu_h_
+#define _amdgpu_h_
+

Capitalise the header guard name ?

amdgpu/amdgpu.h line 39

Quoted 3 lines
amdgpu/amdgpu.h new file +3 -0
+#include <stdint.h>
+#include <stdbool.h>
+

Albeit not so common in libdrm, you can add make the header C++ safe.

#if defined(__cplusplus)
extern "C" {
#endif

Quoted 7 lines
amdgpu/amdgpu.h new file +7 -0
+struct amdgpu_bo_alloc_request {
+	/** Allocation request. It must be aligned correctly. */
+	uint64_t alloc_size;
+
+	/**
+	 * It may be required to have some specific alignment requirements
+	 * for physical back-up storage (e.g. for displayable surface).

amdgpu/amdgpu.h line 202

Quoted 10 lines
amdgpu/amdgpu.h new file +10 -0
+	 * If 0 there is no special alignment requirement
+	 */
+	uint64_t phys_alignment;
+
+	/**
+	 * UMD should specify where to allocate memory and how it
+	 * will be accessed by the CPU.
+	 */
+	uint32_t preferred_heap;
+

Worth adding a pad ?

Quoted 14 lines
amdgpu/amdgpu.h new file +13 -0
+	/** Additional flags passed on allocation */
+	uint64_t flags;
+};
 
+struct amdgpu_bo_info {
+	/** Allocated memory size */
+	uint64_t alloc_size;
+
+	/**
+	 * It may be required to have some specific alignment requirements
+	 * for physical back-up storage.
+	 */
+	uint64_t phys_alignment;
+

amdgpu/amdgpu.h line 274

Quoted 10 lines
amdgpu/amdgpu.h new file +10 -0
+	/**
+	 * Assigned virtual MC Base Address.
+	 * \note  This information will be returned only if this buffer was
+	 * allocated in the same process otherwise 0 will be returned.
+	*/
+	uint64_t virtual_mc_base_address;
+
+	/** Heap where to allocate memory. */
+	uint32_t preferred_heap;
+

Ditto.

Quoted 9 lines
amdgpu/amdgpu.h new file +8 -0
+	/** Additional allocation flags. */
+	uint64_t alloc_flags;
+
+	/** Metadata associated with buffer if any. */
+	struct amdgpu_bo_metadata metadata;
+};
 
+struct amdgpu_gds_alloc_info {
+	/** Handle assigned to gds allocation */

amdgpu/amdgpu.h line 337

Quoted 10 lines
amdgpu/amdgpu.h new file +10 -0
+	amdgpu_bo_handle resource_handle;
+
+	/** How much was really allocated */
+	uint32_t   gds_memory_size;
+
+	/** Number of GWS resources allocated */
+	uint32_t   gws;
+
+	/** Number of OA resources allocated */
+	uint32_t   oa;

Ditto.

Quoted 4 lines
amdgpu/amdgpu.h new file +4 -0
+struct amdgpu_cs_ib_info {
+	/** Special flags */
+	uint64_t      flags;
+

amdgpu/amdgpu.h line 376

Quoted 10 lines
amdgpu/amdgpu.h new file +10 -0
+	/** Handle of command buffer */
+	amdgpu_ib_handle ib_handle;
+
+	/**
+	 * Size of Command Buffer to be submitted.
+	 *   - The size is in units of dwords (4 bytes).
+	 *   - Must be less or equal to the size of allocated IB
+	 *   - Could be 0
+	 */
+	uint32_t       size;

Ditto.

Quoted 22 lines
amdgpu/amdgpu.h new file +22 -0
+struct amdgpu_cs_request {
+	/** Specify flags with additional information */
+	uint64_t	flags;
+
+	/** Specify HW IP block type to which to send the IB. */
+	unsigned	ip_type;
+
+	/** IP instance index if there are several IPs of the same type. */
+	unsigned	ip_instance;
+
+	/**
+	 * Specify ring index of the IP. We could have several rings
+	 * in the same IP. E.g. 0 for SDMA0 and 1 for SDMA1.
+	 */
+	uint32_t           ring;
+
+	/**
+	 * Specify number of resource handles passed.
+	 * Size of 'handles' array
+	 *
+	 */
+	uint32_t number_of_resources;

amdgpu/amdgpu.h line 417

Quoted 10 lines
amdgpu/amdgpu.h new file +10 -0
+
+	/** Array of resources used by submission. */
+	amdgpu_bo_handle   *resources;
+
+	/** Array of resources flags. This is optional and can be NULL. */
+	uint8_t *resource_flags;
+
+	/** Number of IBs to submit in the field ibs. */
+	uint32_t number_of_ibs;
+

Ditto.

Quoted 19 lines
amdgpu/amdgpu.h new file +19 -0
+	/**
+	 * IBs to submit. Those IBs will be submit together as single entity
+	 */
+	struct amdgpu_cs_ib_info *ibs;
+};
+
+/**
+ * Structure describing request to check submission state using fence
+ *
+ * \sa amdgpu_cs_query_fence_status()
+ *
+*/
+struct amdgpu_cs_query_fence {
+
+	/** In which context IB was sent to execution */
+	amdgpu_context_handle  context;
+
+	/** Timeout in nanoseconds. */
+	uint64_t  timeout_ns;

amdgpu/amdgpu.h line 446

Quoted 10 lines
amdgpu/amdgpu.h new file +10 -0
+
+	/** To which HW IP type the fence belongs */
+	unsigned  ip_type;
+
+	/** IP instance index if there are several IPs of the same type. */
+	unsigned ip_instance;
+
+	/** Ring index of the HW IP */
+	uint32_t      ring;
+

Ditto.

amdgpu/amdgpu_bo.c

Quoted 12 lines
amdgpu/amdgpu.h new file +6 -0
+	/** Flags */
+	uint64_t  flags;
+
+	/** Specify fence for which we need to check
+	 * submission status.*/
+	uint64_t	fence;
amdgpu/amdgpu_bo.c new file +1 -0
 
+#define _FILE_OFFSET_BITS 64

How about

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

If you feel against poluting all the C sources with it, you should ensure that amdgpu_internal.h is included before any other header in every source and header file.

Quoted 24 lines
amdgpu/amdgpu_bo.c new file +24 -0
+int amdgpu_bo_cpu_map(amdgpu_bo_handle bo, void **cpu)
+{
+	union drm_amdgpu_gem_mmap args;
+	void *ptr;
+	int r;
+
+	pthread_mutex_lock(&bo->cpu_access_mutex);
+
+	if (bo->cpu_ptr) {
+		/* already mapped */
+		assert(bo->cpu_map_count > 0);
+		bo->cpu_map_count++;
+		*cpu = bo->cpu_ptr;
+		pthread_mutex_unlock(&bo->cpu_access_mutex);
+		return 0;
+	}
+
+	assert(bo->cpu_map_count == 0);
+
+	memset(&args, 0, sizeof(args));
+
+	/* Query the buffer address (args.addr_ptr).
+	 * The kernel driver ignores the offset and size parameters. */
+	args.in.handle = bo->handle;

amdgpu/amdgpu_bo.c line 505

Quoted 10 lines
amdgpu/amdgpu_bo.c new file +10 -0
+
+	r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_MMAP, &args,
+				sizeof(args));
+	if (r) {
+		pthread_mutex_unlock(&bo->cpu_access_mutex);
+		return r;
+	}
+
+	/* Map the buffer. */
+	ptr = mmap(NULL, bo->alloc_size, PROT_READ | PROT_WRITE, MAP_SHARED,

Please use drm_mmap/drm_munmap.

amdgpu/amdgpu_cs.c line 95

Quoted 11 lines
amdgpu/amdgpu_cs.c new file +7 -0
 
+static int amdgpu_cs_create_ib(amdgpu_device_handle dev,
+			       amdgpu_context_handle context,
+			       enum amdgpu_cs_ib_size ib_size,
+			       amdgpu_ib_handle *ib)
+{
 
+	new_ib = malloc(sizeof(struct amdgpu_ib));
+	if (NULL == new_ib) {

Use new_ib == NULL or !new_ib ? There are a few other places that can do so.

amdgpu/amdgpu_device.c line 67

Quoted 11 lines
amdgpu/amdgpu_device.c new file +8 -0
 
+static unsigned fd_hash(void *key)
+{
+	int fd = PTR_TO_UINT(key);
+	struct stat stat;
+	fstat(fd, &stat);
+
+	if (!S_ISCHR(stat.st_mode))
+		return stat.st_dev ^ stat.st_ino;

I'm a bit puzzled, how is this possible ?

amdgpu/amdgpu_device.c line 69

Quoted 2 lines
amdgpu/amdgpu_device.c new file +2 -0
+	else
+		return stat.st_dev ^ (stat.st_rdev & RENDERNODE_MINOR_MASK);

I'm not 100% sure that there won't be any side-effects with the idea of using primary and render node interchangeably.

Plus one cannot mask out to get from the primary device to the render one, or vice-versa. The minor number is not reliable (rightfully so), thus one can use drmGet(Primary|Render)DeviceNameFromFd or introduce their fd counterpart.

Quoted 7 lines
amdgpu/amdgpu_device.c new file +7 -0
+}
+
+static int fd_compare(void *key1, void *key2)
+{
+	int fd1 = PTR_TO_UINT(key1);
+	int fd2 = PTR_TO_UINT(key2);
+	struct stat stat1, stat2;

amdgpu/amdgpu_device.c line 86

Quoted 10 lines
amdgpu/amdgpu_device.c new file +10 -0
+	fstat(fd1, &stat1);
+	fstat(fd2, &stat2);
+
+	if (!S_ISCHR(stat1.st_mode) || !S_ISCHR(stat2.st_mode))
+		return stat1.st_dev != stat2.st_dev ||
+			stat1.st_ino != stat2.st_ino;
+        else
+		return major(stat1.st_rdev) != major(stat2.st_rdev) ||
+			(minor(stat1.st_rdev) & RENDERNODE_MINOR_MASK) !=
+			(minor(stat2.st_rdev) & RENDERNODE_MINOR_MASK);

Same comments apply.

Quoted 11 lines
amdgpu/amdgpu_device.c new file +11 -0
+}
+
+/**
+* Get the authenticated form fd,
+*
+* \param   fd   - \c [in]  File descriptor for AMD GPU device
+* \param   auth - \c [out] Pointer to output the fd is authenticated or not
+*                          A render node fd, output auth = 0
+*                          A legacy fd, get the authenticated for compatibility root
+*
+* \return   0 on success\n

amdgpu/amdgpu_device.c line 107

Quoted 10 lines
amdgpu/amdgpu_device.c new file +10 -0
+*          >0 - AMD specific error code\n
+*          <0 - Negative POSIX Error code
+*/
+static int amdgpu_get_auth(int fd, int *auth)
+{
+	int r = 0;
+	drm_client_t client;
+	struct stat stat1;
+	fstat(fd,&stat1);
+	if (minor(stat1.st_rdev) & ~RENDERNODE_MINOR_MASK)/* find a render node fd */

Please use drmGetNodeTypeFromFd().

amdgpu/amdgpu_internal.h line 26

Quoted 7 lines
amdgpu/amdgpu_internal.h new file +3 -0
@@ -0,0 +1,210 @@
 
+#ifndef _amdgpu_internal_h_
+#define _amdgpu_internal_h_
+

Capital letters for the header guard ?

amdgpu/amdgpu_internal.h line 38

Quoted 12 lines
amdgpu/amdgpu_internal.h new file +12 -0
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
+#include <pthread.h>
+#include "xf86atomic.h"
+#include "amdgpu.h"
+#include "util_double_list.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+

Drop this and use util_math.h where needed ?

Quoted 7 lines
amdgpu/amdgpu_internal.h new file +7 -0
+/**
+ * Increment src and decrement dst as if we were updating references
+ * for an assignment between 2 pointers of some objects.
+ *
+ * \return  true if dst is 0
+ */
+static inline bool update_references(atomic_t *dst, atomic_t *src)

amdgpu/amdgpu_internal.h line 166

Quoted 10 lines
amdgpu/amdgpu_internal.h new file +10 -0
+{
+	if (dst != src) {
+		/* bump src first */
+		if (src) {
+			assert(atomic_read(src) > 0);
+			atomic_inc(src);
+		}
+		if (dst) {
+			assert(atomic_read(dst) > 0);
+			return atomic_dec_and_test(dst);

Am I imagining something or does the assert conditions look a bit strange ?

amdgpu/util_double_list.h

Quoted 5 lines
amdgpu/util_double_list.h new file +0 -0
new file mode 100644
index 0000000..3f48ae2

There are already two identical copies of this file - let's not add a third one.

freedreno/list.h
tests/radeon/list.h

How about we move it one level up, and update the current users (incl. Makefile.sources)

amdgpu/util_hash_table.c

Quoted 5 lines
amdgpu/util_hash.c new file +0 -0
amdgpu/util_hash_table.c new file +0 -0

Can one use the existing drmHash functions like omap and freedreno ? Would be nice to avoid going the mesa's route which iirc has four different implementations.

amdgpu/util_math.h

Quoted 2 lines
amdgpu/util_math.h new file +0 -0

FWIW we can move this a level up, so that others can use it. Obviously there is no reason to be part of this series.

configure.ac m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) · line 40

Quoted 10 lines
configure.ac +1 -0
index 155d577..509f2d4 100644
@@ -36,6 +36,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 # Check for programs
 AC_PROG_CC
+AC_PROG_CXX
 

There are no C++ sources, so you don't need a C++ compiler.

configure.ac if test "x$drm_cv_atomic_primitives" = "xnone"; then · line 247

Quoted 7 lines
configure.ac +3 -0
@@ -236,6 +242,9 @@ if test "x$drm_cv_atomic_primitives" = "xnone"; then
 	LIBDRM_ATOMICS_NOT_FOUND_MSG($RADEON, radeon, Radeon, radeon)
 	RADEON=no
 
+	LIBDRM_ATOMICS_NOT_FOUND_MSG($AMDGPU, amdgpu, AMD, amdgpu)
+	AMDGPU=no
+

Glad to see this, unlike the original copy/paste of an insanely long message previously :)

configure.ac if test "x$RADEON" = xyes; then · line 355

Quoted 4 lines
configure.ac +4 -0
+if test "x$AMDGPU" = xyes; then
+	AC_DEFINE(HAVE_AMDGPU, 1, [Have amdgpu support])
+fi
+

Unless you're planning to add support to libkms you can drop this.

Quoted 16 lines
include/drm/amdgpu_drm.h new file +10 -0
new file mode 100644
index 0000000..d248d77
 
+struct drm_amdgpu_cs_in {
+	/** Rendering context id */
+	uint32_t		ctx_id;
+	/**  Handle of resource list associated with CS */
+	uint32_t		bo_list_handle;
+	uint32_t		num_chunks;
+	uint32_t		pad;
+	/* this points to uint64_t * which point to cs chunks */
+	uint64_t		chunks;
+};

include/drm/amdgpu_drm.h line 360

Quoted 10 lines
include/drm/amdgpu_drm.h new file +10 -0
+
+struct drm_amdgpu_cs_out {
+	uint64_t handle;
+};
+
+union drm_amdgpu_cs {
+       struct drm_amdgpu_cs_in in;
+       struct drm_amdgpu_cs_out out;
+};
+

Don't think I've seen similar contruct in any of the other drm drivers. (Genuenly curious) What benefit does it bring ?

I think you want to add a trailing padding for the following structures. I'm thinking of a case where, old 64bit userspace feeds in the last u32 as rubbish, to the kernel while the latter uses an updated/expanded struct. In such case the driver will either reject the request, or worse use the rubbish data.

struct drm_amdgpu_gem_metadata
struct drm_amdgpu_wait_cs_in

struct drm_amdgpu_info_hw_ip
struct drm_amdgpu_info_device

Cheers
Emil

P.S. Based on the coding style seems like this is the combined work of 3+ developers. Anyway glad to see that it's out :-)

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel