From 61515c5ae47a0d54fdb18853e5d1c09579bd2135 Mon Sep 17 00:00:00 2001 From: shepherd Date: Sat, 2 Dec 2023 10:20:52 +0800 Subject: [PATCH 1/2] support BusPlatform --- workload/hwcodec/src/exec/vendorconfig.ini | 2 +- workload/hwcodec/src/source/device.c | 40 +++++++++++++++++++--- workload/hwcodec/src/source/device.h | 7 ++-- workload/hwcodec/src/source/utils.c | 26 +++++++------- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/workload/hwcodec/src/exec/vendorconfig.ini b/workload/hwcodec/src/exec/vendorconfig.ini index db8f844..5cc3bec 100755 --- a/workload/hwcodec/src/exec/vendorconfig.ini +++ b/workload/hwcodec/src/exec/vendorconfig.ini @@ -19,4 +19,4 @@ card_num:19 0x1eed xdxgpu x86_64 /usr/lib/x86_64-linux-gnu/dri /usr/lib/x86_64-linux-gnu/vdpau 0x1ec8 innogpu x86_64 /usr/lib/x86_64-linux-gnu/dri /usr/lib/x86_64-linux-gnu/vdpau 0x1ec8 innogpu aarch64 /usr/lib/aarch64-linux-gnu/dri /usr/lib/aarch64-linux-gnu/vdpau -0xcad0 huawei aarch64 /usr/lib/aarch64-linux-gnu/dri /usr/lib/aarch64-linux-gnu/vdpau +huanglong hisilicon aarch64 /usr/lib/aarch64-linux-gnu/dri /usr/lib/aarch64-linux-gnu/vdpau diff --git a/workload/hwcodec/src/source/device.c b/workload/hwcodec/src/source/device.c index 9275a5e..e62a212 100755 --- a/workload/hwcodec/src/source/device.c +++ b/workload/hwcodec/src/source/device.c @@ -72,7 +72,10 @@ int get_device_info(device_info_t *device_info) drmGetDevice(fd, &device); card_info->device_id = device->deviceinfo.pci->device_id; card_info->vendor_id = device->deviceinfo.pci->vendor_id; - //0 for discrete card, 1 for intergated card + if (device->bustype==2) { + sscanf(device->deviceinfo.platform->compatible[0], "%s", card_info->card_compatible); + } + //0 for discrete card, 1 for intergated card if (device->businfo.pci->bus > 0) { card_info->card_type = DISCRETE_CARD_TYPE; } else @@ -82,9 +85,9 @@ int get_device_info(device_info_t *device_info) } return 0; } -const char *get_vendor_name(int vendor_id) +const char *get_vendor_name(card_info_t* card_info) { - int index = get_cardinfoindex_byid(vendor_id); + int index = get_cardinfoindex_by_info(card_info); if (index > -1) return card_config_info[index].card_name; @@ -154,10 +157,11 @@ int load_card_config(const char* configFilePath) else { char strplatform[32] = {0}; - if (5 == sscanf(buf, "%x %s %s %s %s", - &card_config_info[line].card_id, card_config_info[line].card_name, strplatform, + if (5 == sscanf(buf, "%s %s %s %s %s", + card_config_info[line].card_compatible, card_config_info[line].card_name, strplatform, card_config_info[line].vaapi_path, card_config_info[line].vdpau_path)) { + sscanf(card_config_info[line].card_compatible, "%x", &card_config_info[line].card_id); printf("vendor_id:0x%x, vendor_name:%s, vaapi_path:%s, vdpau_path:%s, strplatform:%s.\n", card_config_info[line].card_id, card_config_info[line].card_name, card_config_info[line].vaapi_path, card_config_info[line].vdpau_path, @@ -209,3 +213,29 @@ int get_cardinfoindex_byid(int venderid) printf("get_cardinfoindex_byid failed, venderid=0x%x!\n", venderid); return index; } + +static int get_cardinfoindex_by_compatible(char *compatible) +{ + if (compatible == NULL) + return -1; + + for (int i = 0; i < card_info_nums; i++) + { + if (card_config_info[i].card_compatible == NULL) + continue; + if (strstr(card_config_info[i].card_compatible, compatible) != NULL) + return i; + } + + printf("cannot find matched compatible, compatible=%s!\n", compatible); + return -1; +} + +int get_cardinfoindex_by_info(card_info_t* card_info) +{ + int index = get_cardinfoindex_byid(card_info->vendor_id); + if (index > -1) + return index; + + return get_cardinfoindex_by_compatible(card_info->card_compatible); +} diff --git a/workload/hwcodec/src/source/device.h b/workload/hwcodec/src/source/device.h index 5b9abba..e77411a 100644 --- a/workload/hwcodec/src/source/device.h +++ b/workload/hwcodec/src/source/device.h @@ -7,6 +7,7 @@ typedef struct _card_info_t int device_id; int vendor_id; int card_type; + char card_compatible[32]; }card_info_t; #define DISCRETE_CARD_TYPE 0xef #define INTERGRATED_CARD_TYPE 0xfe @@ -20,7 +21,8 @@ typedef struct _device_info typedef struct _CARD_CONFIG_INFO { - int card_id; + int card_id; + char card_compatible[32]; char card_name[32]; char vaapi_path[256]; char vdpau_path[256]; @@ -28,10 +30,11 @@ typedef struct _CARD_CONFIG_INFO extern int get_device_info(device_info_t* device_info); -extern const char* get_vendor_name(int vendor_id); +extern const char* get_vendor_name(card_info_t* card_info); int load_card_config(const char* configFilePath); int get_cardinfoindex_byid(int venderid); +int get_cardinfoindex_by_info(card_info_t* card_info); extern CARD_CONFIG_INFO* card_config_info; diff --git a/workload/hwcodec/src/source/utils.c b/workload/hwcodec/src/source/utils.c index 38586a8..8800d8c 100755 --- a/workload/hwcodec/src/source/utils.c +++ b/workload/hwcodec/src/source/utils.c @@ -218,12 +218,12 @@ static int test_vaapi_driver(const char* driver_name) } return 0; } -static int setup_env(int vendor_id,char* hw_type) +static int setup_env(card_info_t* card_info,char* hw_type) { int is_vaapi = 0; int is_vdpau = 0; - int index = get_cardinfoindex_byid(vendor_id); + int index = get_cardinfoindex_by_info(card_info); setenv("LIBVA_MESSAGING_LEVEL", "1", 1); if (!strncasecmp(hw_type, "vaapi",5)) @@ -245,7 +245,7 @@ static int setup_env(int vendor_id,char* hw_type) is_vdpau = 1; } #if 1 - switch (vendor_id) { + switch (card_info->vendor_id) { case 0x1002: { const char* amd_driver[]={"radeonsi"}; @@ -254,13 +254,13 @@ static int setup_env(int vendor_id,char* hw_type) { if (!test_vaapi_driver(amd_driver[i])) break; - printf("vaapi is not supported in %s using driver %s \n", get_vendor_name(vendor_id),amd_driver[i]); + printf("vaapi is not supported in %s using driver %s \n", get_vendor_name(card_info),amd_driver[i]); } for(int i=0;icard_type==DISCRETE_CARD_TYPE?"Discrete Card":"Intergrated Cards"); printf("device id : 0x%x\n", card_info->device_id); printf("vendor id : 0x%x(%s)\n", card_info->vendor_id, - get_vendor_name(card_info->vendor_id)); + get_vendor_name(card_info)); } int card_idx=0; for(int i=0;i Date: Sat, 2 Dec 2023 06:31:18 +0000 Subject: [PATCH 2/2] update workload/hwcodec/src/source/device.c. Signed-off-by: shepherd <12437770+shepherd_2059@user.noreply.gitee.com> --- workload/hwcodec/src/source/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workload/hwcodec/src/source/device.c b/workload/hwcodec/src/source/device.c index e62a212..94f0c83 100755 --- a/workload/hwcodec/src/source/device.c +++ b/workload/hwcodec/src/source/device.c @@ -223,7 +223,7 @@ static int get_cardinfoindex_by_compatible(char *compatible) { if (card_config_info[i].card_compatible == NULL) continue; - if (strstr(card_config_info[i].card_compatible, compatible) != NULL) + if (strstr(compatible, card_config_info[i].card_compatible) != NULL) return i; } -- Gitee