···1313libdrm is a low-level library, typically used by graphics drivers such as
1414the Mesa drivers, the X drivers, libva and similar projects.
15151616+Syncing with the Linux kernel headers
1717+-------------------------------------
1818+1919+The library should be regularly updated to match the recent changes in the
2020+`include/uapi/drm/`.
2121+2222+libdrm maintains a human-readable version for the token format modifier, with
2323+the simpler ones being extracted automatically from `drm_fourcc.h` header file
2424+with the help of a python script. This might not always possible, as some of
2525+the vendors require decoding/extracting them programmatically. For that
2626+reason one can enhance the current vendor functions to include/provide the
2727+newly added token formats, or, in case there's no such decoding
2828+function, to add one that performs the tasks of extracting them.
2929+3030+For simpler format modifier tokens there's a script (gen_table_fourcc.py) that
3131+creates a static table, by going over `drm_fourcc.h` header file. The script
3232+could be further modified if it can't handle new (simpler) token format
3333+modifiers instead of the generated static table.
16341735Compiling
1836---------
···1818# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919# SOFTWARE.
20202121-libdrm_exynos = shared_library(
2121+libdrm_exynos = library(
2222 'drm_exynos',
2323 [files('exynos_drm.c', 'exynos_fimg2d.c'), config_file],
2424 c_args : libdrm_c_args,
···11+#!/usr/bin/env python3
22+33+# Copyright 2021 Collabora, Ltd.
44+#
55+# Permission is hereby granted, free of charge, to any person obtaining
66+# a copy of this software and associated documentation files (the
77+# "Software"), to deal in the Software without restriction, including
88+# without limitation the rights to use, copy, modify, merge, publish,
99+# distribute, sublicense, and/or sell copies of the Software, and to
1010+# permit persons to whom the Software is furnished to do so, subject to
1111+# the following conditions:
1212+#
1313+# The above copyright notice and this permission notice (including the
1414+# next paragraph) shall be included in all copies or substantial
1515+# portions of the Software.
1616+#
1717+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1818+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1919+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2020+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2121+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2222+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2323+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424+# SOFTWARE.
2525+2626+# Helper script that reads drm_fourcc.h and writes a static table with the
2727+# simpler format token modifiers
2828+2929+import sys
3030+import re
3131+3232+filename = sys.argv[1]
3333+towrite = sys.argv[2]
3434+3535+fm_re = {
3636+ 'intel': r'^#define I915_FORMAT_MOD_(\w+)',
3737+ 'others': r'^#define DRM_FORMAT_MOD_((?:ARM|SAMSUNG|QCOM|VIVANTE|NVIDIA|BROADCOM|ALLWINNER)\w+)\s',
3838+ 'vendors': r'^#define DRM_FORMAT_MOD_VENDOR_(\w+)'
3939+}
4040+4141+def print_fm_intel(f, f_mod):
4242+ f.write(' {{ DRM_MODIFIER_INTEL({}, {}) }},\n'.format(f_mod, f_mod))
4343+4444+# generic write func
4545+def print_fm(f, vendor, mod, f_name):
4646+ f.write(' {{ DRM_MODIFIER({}, {}, {}) }},\n'.format(vendor, mod, f_name))
4747+4848+with open(filename, "r") as f:
4949+ data = f.read()
5050+ for k, v in fm_re.items():
5151+ fm_re[k] = re.findall(v, data, flags=re.M)
5252+5353+with open(towrite, "w") as f:
5454+ f.write('''\
5555+/* AUTOMATICALLY GENERATED by gen_table_fourcc.py. You should modify
5656+ that script instead of adding here entries manually! */
5757+static const struct drmFormatModifierInfo drm_format_modifier_table[] = {
5858+''')
5959+ f.write(' { DRM_MODIFIER_INVALID(NONE, INVALID_MODIFIER) },\n')
6060+ f.write(' { DRM_MODIFIER_LINEAR(NONE, LINEAR) },\n')
6161+6262+ for entry in fm_re['intel']:
6363+ print_fm_intel(f, entry)
6464+6565+ for entry in fm_re['others']:
6666+ (vendor, mod) = entry.split('_', 1)
6767+ if vendor == 'ARM' and (mod == 'TYPE_AFBC' or mod == 'TYPE_MISC'):
6868+ continue
6969+ print_fm(f, vendor, mod, mod)
7070+7171+ f.write('''\
7272+};
7373+''')
7474+7575+ f.write('''\
7676+static const struct drmFormatModifierVendorInfo drm_format_modifier_vendor_table[] = {
7777+''')
7878+7979+ for entry in fm_re['vendors']:
8080+ f.write(" {{ DRM_FORMAT_MOD_VENDOR_{}, \"{}\" }},\n".format(entry, entry))
8181+8282+ f.write('''\
8383+};
8484+''')
+45-6
lib/libdrm/include/drm/amdgpu_drm.h
···502502#define AMDGPU_VM_MTYPE_MASK (0xf << 5)
503503/* Default MTYPE. Pre-AI must use this. Recommended for newer ASICs. */
504504#define AMDGPU_VM_MTYPE_DEFAULT (0 << 5)
505505-/* Use NC MTYPE instead of default MTYPE */
505505+/* Use Non Coherent MTYPE instead of default MTYPE */
506506#define AMDGPU_VM_MTYPE_NC (1 << 5)
507507-/* Use WC MTYPE instead of default MTYPE */
507507+/* Use Write Combine MTYPE instead of default MTYPE */
508508#define AMDGPU_VM_MTYPE_WC (2 << 5)
509509-/* Use CC MTYPE instead of default MTYPE */
509509+/* Use Cache Coherent MTYPE instead of default MTYPE */
510510#define AMDGPU_VM_MTYPE_CC (3 << 5)
511511-/* Use UC MTYPE instead of default MTYPE */
511511+/* Use UnCached MTYPE instead of default MTYPE */
512512#define AMDGPU_VM_MTYPE_UC (4 << 5)
513513-/* Use RW MTYPE instead of default MTYPE */
513513+/* Use Read Write MTYPE instead of default MTYPE */
514514#define AMDGPU_VM_MTYPE_RW (5 << 5)
515515516516struct drm_amdgpu_gem_va {
···667667 };
668668};
669669670670-/**
670670+/*
671671 * Query h/w info: Flag that this is integrated (a.h.a. fusion) GPU
672672 *
673673 */
674674#define AMDGPU_IDS_FLAGS_FUSION 0x1
675675#define AMDGPU_IDS_FLAGS_PREEMPTION 0x2
676676+#define AMDGPU_IDS_FLAGS_TMZ 0x4
676677677678/* indicate if acceleration can be working */
678679#define AMDGPU_INFO_ACCEL_WORKING 0x00
···723724 #define AMDGPU_INFO_FW_TA 0x13
724725 /* Subquery id: Query DMCUB firmware version */
725726 #define AMDGPU_INFO_FW_DMCUB 0x14
727727+ /* Subquery id: Query TOC firmware version */
728728+ #define AMDGPU_INFO_FW_TOC 0x15
726729727730/* number of bytes moved for TTM migration */
728731#define AMDGPU_INFO_NUM_BYTES_MOVED 0x0f
···779782#define AMDGPU_INFO_VRAM_LOST_COUNTER 0x1F
780783/* query ras mask of enabled features*/
781784#define AMDGPU_INFO_RAS_ENABLED_FEATURES 0x20
785785+/* query video encode/decode caps */
786786+#define AMDGPU_INFO_VIDEO_CAPS 0x21
787787+ /* Subquery id: Decode */
788788+ #define AMDGPU_INFO_VIDEO_CAPS_DECODE 0
789789+ /* Subquery id: Encode */
790790+ #define AMDGPU_INFO_VIDEO_CAPS_ENCODE 1
782791783792/* RAS MASK: UMC (VRAM) */
784793#define AMDGPU_INFO_RAS_ENABLED_UMC (1 << 0)
···875884 struct {
876885 __u32 type;
877886 } sensor_info;
887887+888888+ struct {
889889+ __u32 type;
890890+ } video_cap;
878891 };
879892};
880893···945958#define AMDGPU_VRAM_TYPE_DDR3 7
946959#define AMDGPU_VRAM_TYPE_DDR4 8
947960#define AMDGPU_VRAM_TYPE_GDDR6 9
961961+#define AMDGPU_VRAM_TYPE_DDR5 10
948962949963struct drm_amdgpu_info_device {
950964 /** PCI Device ID */
···10701084 __u32 pad;
10711085};
1072108610871087+/* query video encode/decode caps */
10881088+#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2 0
10891089+#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4 1
10901090+#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1 2
10911091+#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC 3
10921092+#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC 4
10931093+#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG 5
10941094+#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9 6
10951095+#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1 7
10961096+#define AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT 8
10971097+10981098+struct drm_amdgpu_info_video_codec_info {
10991099+ __u32 valid;
11001100+ __u32 max_width;
11011101+ __u32 max_height;
11021102+ __u32 max_pixels_per_frame;
11031103+ __u32 max_level;
11041104+ __u32 pad;
11051105+};
11061106+11071107+struct drm_amdgpu_info_video_caps {
11081108+ struct drm_amdgpu_info_video_codec_info codec_info[AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT];
11091109+};
11101110+10731111/*
10741112 * Supported GPU families
10751113 */
···10821120#define AMDGPU_FAMILY_AI 141 /* Vega10 */
10831121#define AMDGPU_FAMILY_RV 142 /* Raven */
10841122#define AMDGPU_FAMILY_NV 143 /* Navi10 */
11231123+#define AMDGPU_FAMILY_VGH 144 /* Van Gogh */
1085112410861125#if defined(__cplusplus)
10871126}
···1818# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919# SOFTWARE.
20202121-libdrm_intel = shared_library(
2121+libdrm_intel = library(
2222 'drm_intel',
2323 [
2424 files(
···1818# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919# SOFTWARE.
20202121-libdrm_omap = shared_library(
2121+libdrm_omap = library(
2222 'drm_omap',
2323 [files('omap_drm.c'), config_file],
2424 include_directories : [inc_root, inc_drm],
···1818# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919# SOFTWARE.
20202121-libdrm_tegra = shared_library(
2121+libdrm_tegra = library(
2222 'drm_tegra',
2323 [files('tegra.c'), config_file],
2424 include_directories : [inc_root, inc_drm],
+108-7
lib/libdrm/tests/amdgpu/amdgpu_test.c
···3737#include <sys/time.h>
3838#include <stdarg.h>
3939#include <stdint.h>
4040+#ifdef __linux__
4141+#include <linux/limits.h>
4242+#elif __FreeBSD__
4343+/* SPECNAMELEN in FreeBSD is defined here: */
4444+#include <sys/param.h>
4545+#endif
4646+#ifdef MAJOR_IN_MKDEV
4747+#include <sys/mkdev.h>
4848+#endif
4949+#ifdef MAJOR_IN_SYSMACROS
5050+#include <sys/sysmacros.h>
5151+#endif
40524153#include "drm.h"
4254#include "xf86drmMode.h"
···5971#define RAS_TESTS_STR "RAS Tests"
6072#define SYNCOBJ_TIMELINE_TESTS_STR "SYNCOBJ TIMELINE Tests"
6173#define SECURITY_TESTS_STR "Security Tests"
7474+#define HOTUNPLUG_TESTS_STR "Hotunplug Tests"
62756376/**
6477 * Open handles for amdgpu devices
···137150 .pCleanupFunc = suite_security_tests_clean,
138151 .pTests = security_tests,
139152 },
153153+ {
154154+ .pName = HOTUNPLUG_TESTS_STR,
155155+ .pInitFunc = suite_hotunplug_tests_init,
156156+ .pCleanupFunc = suite_hotunplug_tests_clean,
157157+ .pTests = hotunplug_tests,
158158+ },
140159141160 CU_SUITE_INFO_NULL,
142161};
···198217 .pName = SECURITY_TESTS_STR,
199218 .pActive = suite_security_tests_enable,
200219 },
220220+ {
221221+ .pName = HOTUNPLUG_TESTS_STR,
222222+ .pActive = suite_hotunplug_tests_enable,
223223+ },
201224};
202225203226···339362340363/* Close AMD devices.
341364 */
342342-static void amdgpu_close_devices()
365365+void amdgpu_close_devices()
343366{
344367 int i;
345368 for (i = 0; i < MAX_CARDS_SUPPORTED; i++)
346346- if (drm_amdgpu[i] >=0)
369369+ if (drm_amdgpu[i] >=0) {
347370 close(drm_amdgpu[i]);
371371+ }
348372}
349373350374/* Print AMD devices information */
···430454{
431455 amdgpu_device_handle device_handle;
432456 uint32_t major_version, minor_version, family_id;
433433- int i;
457457+ drmDevicePtr devices[MAX_CARDS_SUPPORTED];
458458+ int i, drm_count;
434459 int size = sizeof(suites_active_stat) / sizeof(suites_active_stat[0]);
435460436461 if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
···441466442467 if (amdgpu_device_deinitialize(device_handle))
443468 return;
469469+470470+ drm_count = drmGetDevices2(0, devices, MAX_CARDS_SUPPORTED);
444471445472 /* Set active status for suites based on their policies */
446473 for (i = 0; i < size; ++i)
···496523 "gfx ring slow bad draw test (set amdgpu.lockup_timeout=50)", CU_FALSE))
497524 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
498525499499- if (amdgpu_set_test_active(BO_TESTS_STR, "Metadata", CU_FALSE))
500500- fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
501501-502526 if (amdgpu_set_test_active(BASIC_TESTS_STR, "bo eviction Test", CU_FALSE))
503527 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
504528···524548 //if (family_id < AMDGPU_FAMILY_AI || family_id > AMDGPU_FAMILY_RV)
525549 if (amdgpu_set_test_active(BASIC_TESTS_STR, "GPU reset Test", CU_FALSE))
526550 fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
551551+552552+ /* You need at least 2 devices for this */
553553+ if (drm_count < 2)
554554+ if (amdgpu_set_test_active(HOTUNPLUG_TESTS_STR, "Unplug with exported fence", CU_FALSE))
555555+ fprintf(stderr, "test deactivation failed - %s\n", CU_get_error_msg());
556556+}
557557+558558+int test_device_index;
559559+560560+int amdgpu_open_device_on_test_index(int render_node)
561561+{
562562+ int i;
563563+564564+ if (amdgpu_open_devices(open_render_node) <= 0) {
565565+ perror("Cannot open AMDGPU device");
566566+ return -1;
567567+ }
568568+569569+ if (test_device_index >= 0) {
570570+ /* Most tests run on device of drm_amdgpu[0].
571571+ * Swap the chosen device to drm_amdgpu[0].
572572+ */
573573+ i = drm_amdgpu[0];
574574+ drm_amdgpu[0] = drm_amdgpu[test_device_index];
575575+ drm_amdgpu[test_device_index] = i;
576576+ }
577577+578578+ return 0;
579579+580580+581581+}
582582+583583+584584+static bool amdgpu_node_is_drm(int maj, int min)
585585+{
586586+#ifdef __linux__
587587+ char path[64];
588588+ struct stat sbuf;
589589+590590+ snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device/drm",
591591+ maj, min);
592592+ return stat(path, &sbuf) == 0;
593593+#elif defined(__FreeBSD__)
594594+ char name[SPECNAMELEN];
595595+596596+ if (!devname_r(makedev(maj, min), S_IFCHR, name, sizeof(name)))
597597+ return 0;
598598+ /* Handle drm/ and dri/ as both are present in different FreeBSD version
599599+ * FreeBSD on amd64/i386/powerpc external kernel modules create node in
600600+ * in /dev/drm/ and links in /dev/dri while a WIP in kernel driver creates
601601+ * only device nodes in /dev/dri/ */
602602+ return (!strncmp(name, "drm/", 4) || !strncmp(name, "dri/", 4));
603603+#else
604604+ return maj == DRM_MAJOR;
605605+#endif
606606+}
607607+608608+char *amdgpu_get_device_from_fd(int fd)
609609+{
610610+#ifdef __linux__
611611+ struct stat sbuf;
612612+ char path[PATH_MAX + 1];
613613+ unsigned int maj, min;
614614+615615+ if (fstat(fd, &sbuf))
616616+ return NULL;
617617+618618+ maj = major(sbuf.st_rdev);
619619+ min = minor(sbuf.st_rdev);
620620+621621+ if (!amdgpu_node_is_drm(maj, min) || !S_ISCHR(sbuf.st_mode))
622622+ return NULL;
623623+624624+ snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device", maj, min);
625625+ return strdup(path);
626626+#else
627627+ return NULL;
628628+#endif
527629}
528630529631/* The main() function for setting up and running the tests.
···541643 int display_devices = 0;/* By default not to display devices' info */
542644 CU_pSuite pSuite = NULL;
543645 CU_pTest pTest = NULL;
544544- int test_device_index;
545646 int display_list = 0;
546647 int force_run = 0;
547648
+38-6
lib/libdrm/tests/amdgpu/amdgpu_test.h
···273273 unsigned ip_type,
274274 bool secure);
275275276276+277277+278278+/**
279279+ * Initialize hotunplug test suite
280280+ */
281281+int suite_hotunplug_tests_init();
282282+283283+/**
284284+ * Deinitialize hotunplug test suite
285285+ */
286286+int suite_hotunplug_tests_clean();
287287+288288+/**
289289+ * Decide if the suite is enabled by default or not.
290290+ */
291291+CU_BOOL suite_hotunplug_tests_enable(void);
292292+293293+/**
294294+ * Tests in uvd enc test suite
295295+ */
296296+extern CU_TestInfo hotunplug_tests[];
297297+298298+276299/**
277300 * Helper functions
278301 */
···449472 return r;
450473}
451474452452-static inline bool asic_is_arcturus(uint32_t asic_id)
475475+476476+static inline bool asic_is_gfx_pipe_removed(uint32_t family_id, uint32_t chip_id, uint32_t chip_rev)
453477{
454454- switch(asic_id) {
455455- /* Arcturus asic DID */
456456- case 0x738C:
457457- case 0x7388:
458458- case 0x738E:
478478+479479+ if (family_id != AMDGPU_FAMILY_AI)
480480+ return false;
481481+482482+ switch (chip_id - chip_rev) {
483483+ /* Arcturus */
484484+ case 0x32:
485485+ /* Aldebaran */
486486+ case 0x3c:
459487 return true;
460488 default:
461489 return false;
···470498 struct amdgpu_cs_ib_info *ib_info,
471499 struct amdgpu_cs_request *ibs_request,
472500 bool secure);
501501+502502+void amdgpu_close_devices();
503503+int amdgpu_open_device_on_test_index(int render_node);
504504+char *amdgpu_get_device_from_fd(int fd);
473505474506#endif /* #ifdef _AMDGPU_TEST_H_ */
···985985 unsigned int stride)
986986{
987987 const struct util_rgb_info *rgb = &info->rgb;
988988- void *mem_base = mem;
989988 unsigned int x, y;
990989991990 /* TODO: Give this actual fp16 precision */
···11131112 unsigned int width, unsigned int height,
11141113 unsigned int stride)
11151114{
11161116- int i, j;
11151115+ unsigned int i, j;
1117111611181117 for (i = 0; i < height / 2; i++) {
11191118 uint32_t *row = mem;
···11411140 unsigned int width, unsigned int height,
11421141 unsigned int stride)
11431142{
11441144- int i, j;
11431143+ unsigned int i, j;
1145114411461145 for (i = 0; i < height / 2; i++) {
11471146 uint64_t *row = mem;