[AMD Official Use Only - Internal Distribution Only] Hi Tom, Can you help review & merge this patch to bring vbios IOCTL usage in UMR back? The patch is also attached. Thanks in advance, Jiawei -----Original Message----- From: Jiawei Gu Sent: Wednesday, May 12, 2021 11:35 AM To: StDenis, Tom ; amd-gfx@lists.freedesktop.org Cc: Deucher, Alexander ; Gu, JiaWei (Will) Subject: [PATCH] add vbios info query Signed-off-by: Jiawei Gu --- src/app/CMakeLists.txt | 1 + src/app/main.c | 8 +++++ src/app/vbios.c | 58 ++++++++++++++++++++++++++++++ src/lib/lowlevel/linux/query_drm.c | 11 ++++++ src/umr.h | 15 ++++++++ src/umrapp.h | 1 + 6 files changed, 94 insertions(+) create mode 100644 src/app/vbios.c diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index ca7d46b..462e4fc 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -35,6 +35,7 @@ add_library(umrapp STATIC pp_table.c navi10_ppt.c read_metrics.c + vbios.c ${GUI_SOURCE} ) diff --git a/src/app/main.c b/src/app/main.c index 47ddb38..b484cf3 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -825,6 +825,11 @@ int main(int argc, char **argv) asic = get_asic(); ih_self_test(asic); #endif + } else if (!strcmp(argv[i], "--vbios_info") || !strcmp(argv[i], "-vi")) { + if (!asic) + asic = get_asic(); + if (umr_print_vbios_info(asic) != 0) + fprintf(stderr, "[ERROR]: Cannot print vbios info.\n"); } else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { printf("User Mode Register debugger v%s for AMDGPU devices (build: %s [%s]), Copyright (c) 2021, AMD Inc.\n" "\n*** Device Selection ***\n" @@ -951,6 +956,9 @@ printf( "\n\t\tPrint the GPU metrics table for the device." "\n\t--power, -p \n\t\tRead the conetent of clocks, temperature, gpu loading at runtime" "\n\t\toptions 'use_colour' to colourize output \n"); +printf( +"\n*** Video BIOS Information ***\n" +"\n\t--vbios_info, -vi \n\t\tPrint Video BIOS information\n"); #if UMR_GUI printf( diff --git a/src/app/vbios.c b/src/app/vbios.c new file mode 100644 index 0000000..98e0f87 --- /dev/null +++ b/src/app/vbios.c @@ -0,0 +1,58 @@ +/* + * Copyright 2021 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. + * + * Authors: Tom St Denis + * + */ +#include "umrapp.h" + +#define AMDGPU_INFO_VBIOS 0x1B +#define AMDGPU_INFO_VBIOS_INFO 0x3 +int umr_print_vbios_info(struct umr_asic *asic) { + char fname[64]; + int r; + struct umr_vbios_info vbios_info; + + if (asic->fd.drm < 0) { + snprintf(fname, sizeof(fname)-1, "/dev/dri/card%d", asic->instance); + asic->fd.drm = open(fname, O_RDWR); + } + + r = umr_query_drm_vbios(asic, AMDGPU_INFO_VBIOS, AMDGPU_INFO_VBIOS_INFO, + &vbios_info, sizeof(vbios_info)); + if (r) + return r; + + printf("vbios name : %s\n", vbios_info.name); + printf("vbios dbdf : 0x%x\n", vbios_info.dbdf); + printf("vbios pn : %s\n", vbios_info.vbios_pn); + printf("vbios version : %d\n", vbios_info.version); + printf("vbios date : %s\n", vbios_info.date); + printf("vbios serial : %lld\n", vbios_info.serial); + printf("vbios dev_id : 0x%x\n", vbios_info.dev_id); + printf("vbios rev_id : 0x%x\n", vbios_info.rev_id); + printf("vbios sub_dev_id : 0x%x\n", vbios_info.sub_dev_id); + printf("vbios sub_ved_id : 0x%x\n", vbios_info.sub_ved_id); + + close(asic->fd.drm); + return 0; +} \ No newline at end of file diff --git a/src/lib/lowlevel/linux/query_drm.c b/src/lib/lowlevel/linux/query_drm.c index d0c82d4..f4ab709 100644 --- a/src/lib/lowlevel/linux/query_drm.c +++ b/src/lib/lowlevel/linux/query_drm.c @@ -49,7 +49,18 @@ int umr_query_drm(struct umr_asic *asic, int field, void *ret, int size) inf.return_size = size; inf.query = field; return ioctl(asic->fd.drm, DRM_IOC(DRM_IOC_WRITE, DRM_IOCTL_BASE, DRM_COMMAND_BASE + DRM_AMDGPU_INFO, sizeof(inf)), &inf); +} +int umr_query_drm_vbios(struct umr_asic *asic, int field, int type, +void *ret, int size) { + struct drm_amdgpu_info inf; + + memset(&inf, 0, sizeof inf); + inf.return_pointer = (uintptr_t)ret; + inf.return_size = size; + inf.query = field; + inf.vbios_info.type = type; + return ioctl(asic->fd.drm, DRM_IOC(DRM_IOC_WRITE, DRM_IOCTL_BASE, +DRM_COMMAND_BASE + DRM_AMDGPU_INFO, sizeof(inf)), &inf); } #else diff --git a/src/umr.h b/src/umr.h index 4e730e5..41266e2 100644 --- a/src/umr.h +++ b/src/umr.h @@ -973,6 +973,7 @@ void umr_free_asic(struct umr_asic *asic); void umr_free_maps(struct umr_asic *asic); void umr_close_asic(struct umr_asic *asic); // call this to close a fully open asic int umr_query_drm(struct umr_asic *asic, int field, void *ret, int size); +int umr_query_drm_vbios(struct umr_asic *asic, int field, int type, +void *ret, int size); void umr_enumerate_devices(void); int umr_update(struct umr_asic *asic, char *script); int umr_update_string(struct umr_asic *asic, char *sdata); @@ -1349,6 +1350,20 @@ struct umr_soc15_database { struct umr_soc15_database *next; }; +// vbios +struct umr_vbios_info { + uint8_t name[64]; + uint32_t dbdf; + uint8_t vbios_pn[64]; + uint32_t version; + uint8_t date[32]; + uint64_t serial; + uint32_t dev_id; + uint32_t rev_id; + uint32_t sub_dev_id; + uint32_t sub_ved_id; +}; + FILE *umr_database_open(char *path, char *filename); struct umr_soc15_database *umr_database_read_soc15(char *path, char *filename); void umr_database_free_soc15(struct umr_soc15_database *soc15); diff --git a/src/umrapp.h b/src/umrapp.h index 14457fe..1336e07 100644 --- a/src/umrapp.h +++ b/src/umrapp.h @@ -57,5 +57,6 @@ void umr_clock_scan(struct umr_asic *asic, const char* clock_name); void umr_clock_manual(struct umr_asic *asic, const char* clock_name, void* value); int umr_print_pp_table(struct umr_asic *asic, const char* param); int umr_print_gpu_metrics(struct umr_asic *asic); +int umr_print_vbios_info(struct umr_asic *asic); void run_server_loop(const char *url, struct umr_asic * asic); -- 2.17.1