[PATCH libdrm 2/2] radeon: use asic id table to get chipset name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change-Id: I24b6624789d1a9dc0fd3a446b0e6f21ed5183ff2
Signed-off-by: Samuel Li <Samuel.Li at amd.com>
---
 radeon/Makefile.am      |   6 +++
 radeon/Makefile.sources |   6 ++-
 radeon/radeon_asic_id.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++
 radeon/radeon_asic_id.h |  37 +++++++++++++++++
 4 files changed, 153 insertions(+), 2 deletions(-)
 create mode 100644 radeon/radeon_asic_id.c
 create mode 100644 radeon/radeon_asic_id.h

diff --git a/radeon/Makefile.am b/radeon/Makefile.am
index e241531..69407bc 100644
--- a/radeon/Makefile.am
+++ b/radeon/Makefile.am
@@ -30,6 +30,12 @@ AM_CFLAGS = \
 	$(PTHREADSTUBS_CFLAGS) \
 	-I$(top_srcdir)/include/drm
 
+libdrmdatadir = @libdrmdatadir@
+ASIC_ID_TABLE_NUM_ENTRIES := $(shell egrep -ci '^[0-9a-f]{4},.*[0-9a-f]+,' \
+	$(top_srcdir)/data/amdgpu.ids)
+AM_CPPFLAGS = -DRADEON_ASIC_ID_TABLE=\"${libdrmdatadir}/amdgpu.ids\" \
+	-DRADEON_ASIC_ID_TABLE_NUM_ENTRIES=$(ASIC_ID_TABLE_NUM_ENTRIES)
+
 libdrm_radeon_la_LTLIBRARIES = libdrm_radeon.la
 libdrm_radeon_ladir = $(libdir)
 libdrm_radeon_la_LDFLAGS = -version-number 1:0:1 -no-undefined
diff --git a/radeon/Makefile.sources b/radeon/Makefile.sources
index 1cf482a..8eaf1c6 100644
--- a/radeon/Makefile.sources
+++ b/radeon/Makefile.sources
@@ -4,7 +4,8 @@ LIBDRM_RADEON_FILES := \
 	radeon_cs_space.c \
 	radeon_bo.c \
 	radeon_cs.c \
-	radeon_surface.c
+	radeon_surface.c \
+	radeon_asic_id.c
 
 LIBDRM_RADEON_H_FILES := \
 	radeon_bo.h \
@@ -14,7 +15,8 @@ LIBDRM_RADEON_H_FILES := \
 	radeon_cs_gem.h \
 	radeon_bo_int.h \
 	radeon_cs_int.h \
-	r600_pci_ids.h
+	r600_pci_ids.h \
+	radeon_asic_id.h
 
 LIBDRM_RADEON_BOF_FILES := \
 	bof.c \
diff --git a/radeon/radeon_asic_id.c b/radeon/radeon_asic_id.c
new file mode 100644
index 0000000..b03502b
--- /dev/null
+++ b/radeon/radeon_asic_id.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2017 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.
+ *
+ */
+
+/**
+ * \file radeon_asic_id.c
+ *
+ *  Implementation of chipset name lookup functions for radeon device
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+//#include <errno.h>
+//#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <assert.h>
+
+#include "xf86atomic.h"
+#include "util/util_asic_id.h"
+#include "radeon_asic_id.h"
+
+
+static pthread_mutex_t asic_id_mutex = PTHREAD_MUTEX_INITIALIZER;
+static struct util_asic_id *radeon_asic_ids;
+static atomic_t refcount;
+
+int radeon_asic_id_initialize(void)
+{
+	int r = 0;
+	pthread_mutex_lock(&asic_id_mutex);
+	if (radeon_asic_ids) {
+		atomic_inc(&refcount);
+		pthread_mutex_unlock(&asic_id_mutex);
+		return r;
+	}
+
+	r = util_parse_asic_ids(&radeon_asic_ids, RADEON_ASIC_ID_TABLE,
+				RADEON_ASIC_ID_TABLE_NUM_ENTRIES);
+	if (r) {
+		fprintf(stderr, "%s: Cannot parse ASIC IDs, 0x%x.",
+			__func__, r);
+	} else
+		atomic_inc(&refcount);
+
+	pthread_mutex_unlock(&asic_id_mutex);
+	return r;
+}
+
+void radeon_asic_id_deinitialize(void)
+{
+	const struct util_asic_id *id;
+
+	assert(atomic_read(&refcount) > 0);
+	pthread_mutex_lock(&asic_id_mutex);
+	if (atomic_dec_and_test(&refcount)) {
+		if (radeon_asic_ids) {
+			for (id = radeon_asic_ids; id->did; id++)
+				free(id->marketing_name);
+			free(radeon_asic_ids);
+			radeon_asic_ids = NULL;
+		}
+	}
+	pthread_mutex_unlock(&asic_id_mutex);
+}
+
+const char *radeon_get_marketing_name(uint32_t device_id, uint32_t pci_rev_id)
+{
+	const struct util_asic_id *id;
+
+	if (!radeon_asic_ids)
+		return NULL;
+
+	for (id = radeon_asic_ids; id->did; id++) {
+		if ((id->did == device_id) &&
+		    (id->rid == pci_rev_id))
+			return id->marketing_name;
+	}
+
+	return NULL;
+}
diff --git a/radeon/radeon_asic_id.h b/radeon/radeon_asic_id.h
new file mode 100644
index 0000000..00bc110
--- /dev/null
+++ b/radeon/radeon_asic_id.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017 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.
+ *
+ */
+
+/**
+ * \file radeon_asic_id.h
+ *
+ * Declare public API for chipset name lookup
+ *
+ */
+#ifndef _RADEON_ASIC_ID_H_
+#define _RADEON_ASIC_ID_H_
+
+int radeon_asic_id_initialize(void);
+void radeon_asic_id_deinitialize(void);
+const char *radeon_get_marketing_name(uint32_t device_id, uint32_t pci_rev_id);
+
+#endif
-- 
2.7.4



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux