<div dir="auto">Mesa doesn't have any use for this. It should be ok to expose just the ioctl without userspace because it's just vbios info.<div dir="auto"><br></div><div dir="auto">Marek</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue., May 18, 2021, 22:41 Gu, JiaWei (Will), <<a href="mailto:JiaWei.Gu@amd.com">JiaWei.Gu@amd.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[AMD Official Use Only - Internal Distribution Only]<br>
<br>
Thanks Tom's suggestion.<br>
I'm fine to replace ioctl with sysfs.<br>
<br>
Hi all, how about this sysfs alternative?<br>
<br>
And if it's a must to insist on ioctl, is there any Mesa expert to help provide the patch?<br>
<br>
Best regards,<br>
Jiawei<br>
<br>
<br>
-----Original Message-----<br>
From: StDenis, Tom <<a href="mailto:Tom.StDenis@amd.com" target="_blank" rel="noreferrer">Tom.StDenis@amd.com</a>> <br>
Sent: Tuesday, May 18, 2021 9:26 PM<br>
To: Koenig, Christian <<a href="mailto:Christian.Koenig@amd.com" target="_blank" rel="noreferrer">Christian.Koenig@amd.com</a>>; Gu, JiaWei (Will) <<a href="mailto:JiaWei.Gu@amd.com" target="_blank" rel="noreferrer">JiaWei.Gu@amd.com</a>>; <a href="mailto:amd-gfx@lists.freedesktop.org" target="_blank" rel="noreferrer">amd-gfx@lists.freedesktop.org</a>; Nieto, David M <<a href="mailto:David.Nieto@amd.com" target="_blank" rel="noreferrer">David.Nieto@amd.com</a>>; <a href="mailto:maraeo@gmail.com" target="_blank" rel="noreferrer">maraeo@gmail.com</a>; Deucher, Alexander <<a href="mailto:Alexander.Deucher@amd.com" target="_blank" rel="noreferrer">Alexander.Deucher@amd.com</a>><br>
Cc: Deng, Emily <<a href="mailto:Emily.Deng@amd.com" target="_blank" rel="noreferrer">Emily.Deng@amd.com</a>><br>
Subject: Re: [PATCH] drm/amdgpu: Add vbios info ioctl interface<br>
<br>
[AMD Official Use Only - Internal Distribution Only]<br>
<br>
If changing the ioctl is an issue why not just use sysfs? umr already makes uses of all three for it's purposes so it's fine by me for either.<br>
<br>
Tom<br>
<br>
________________________________________<br>
From: amd-gfx <<a href="mailto:amd-gfx-bounces@lists.freedesktop.org" target="_blank" rel="noreferrer">amd-gfx-bounces@lists.freedesktop.org</a>> on behalf of Christian König <<a href="mailto:christian.koenig@amd.com" target="_blank" rel="noreferrer">christian.koenig@amd.com</a>><br>
Sent: Tuesday, May 18, 2021 09:17<br>
To: Gu, JiaWei (Will); <a href="mailto:amd-gfx@lists.freedesktop.org" target="_blank" rel="noreferrer">amd-gfx@lists.freedesktop.org</a>; Nieto, David M; <a href="mailto:maraeo@gmail.com" target="_blank" rel="noreferrer">maraeo@gmail.com</a>; Deucher, Alexander<br>
Cc: Deng, Emily<br>
Subject: Re: [PATCH] drm/amdgpu: Add vbios info ioctl interface<br>
<br>
Well not an expert on that stuff, but looks like that should work for me.<br>
<br>
Question is can you provide a patch to use that information in Mesa as well? Umr might be sufficient as well as justification for upstreaming, but I want to be better save than sorry.<br>
<br>
Unless Marek has a better idea maybe add the vbios version to the string returned by GLX_MESA_query_renderer or something like that.<br>
<br>
Thanks,<br>
Christian.<br>
<br>
Am 18.05.21 um 14:19 schrieb Gu, JiaWei (Will):<br>
> [AMD Official Use Only - Internal Distribution Only]<br>
><br>
> Hi all,<br>
><br>
> Please help confirm that we're all fine with this new struct in uapi in this V3 patch:<br>
><br>
> +struct drm_amdgpu_info_vbios {<br>
> + __u8 name[64];<br>
> + __u8 vbios_pn[64];<br>
> + __u32 version;<br>
> + __u8 vbios_ver_str[32];<br>
> + __u8 date[32];<br>
> +};<br>
><br>
> Best regards,<br>
> Jiawei<br>
><br>
> -----Original Message-----<br>
> From: Jiawei Gu <<a href="mailto:Jiawei.Gu@amd.com" target="_blank" rel="noreferrer">Jiawei.Gu@amd.com</a>><br>
> Sent: Tuesday, May 18, 2021 8:16 PM<br>
> To: <a href="mailto:amd-gfx@lists.freedesktop.org" target="_blank" rel="noreferrer">amd-gfx@lists.freedesktop.org</a>; Koenig, Christian <br>
> <<a href="mailto:Christian.Koenig@amd.com" target="_blank" rel="noreferrer">Christian.Koenig@amd.com</a>>; Nieto, David M <<a href="mailto:David.Nieto@amd.com" target="_blank" rel="noreferrer">David.Nieto@amd.com</a>>; <br>
> <a href="mailto:maraeo@gmail.com" target="_blank" rel="noreferrer">maraeo@gmail.com</a>; Deucher, Alexander <<a href="mailto:Alexander.Deucher@amd.com" target="_blank" rel="noreferrer">Alexander.Deucher@amd.com</a>><br>
> Cc: Deng, Emily <<a href="mailto:Emily.Deng@amd.com" target="_blank" rel="noreferrer">Emily.Deng@amd.com</a>>; Gu, JiaWei (Will) <br>
> <<a href="mailto:JiaWei.Gu@amd.com" target="_blank" rel="noreferrer">JiaWei.Gu@amd.com</a>><br>
> Subject: [PATCH] drm/amdgpu: Add vbios info ioctl interface<br>
><br>
> Add AMDGPU_INFO_VBIOS_INFO subquery id for detailed vbios info.<br>
><br>
> Provides a way for the user application to get the VBIOS information without having to parse the binary.<br>
> It is useful for the user to be able to display in a simple way the VBIOS version in their system if they happen to encounter an issue.<br>
><br>
> V2:<br>
> Use numeric serial.<br>
> Parse and expose vbios version string.<br>
><br>
> V3:<br>
> Remove redundant data in drm_amdgpu_info_vbios struct.<br>
><br>
> Signed-off-by: Jiawei Gu <<a href="mailto:Jiawei.Gu@amd.com" target="_blank" rel="noreferrer">Jiawei.Gu@amd.com</a>><br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 15 ++<br>
> drivers/gpu/drm/amd/amdgpu/atom.c | 172 +++++++++++++++++++++<br>
> drivers/gpu/drm/amd/amdgpu/atom.h | 10 ++<br>
> drivers/gpu/drm/amd/include/atomfirmware.h | 5 +<br>
> include/uapi/drm/amdgpu_drm.h | 10 ++<br>
> 5 files changed, 212 insertions(+)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c <br>
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c<br>
> index 8d12e474745a..524e4fe5efe8 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c<br>
> @@ -861,6 +861,21 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)<br>
> min((size_t)size, (size_t)(bios_size - bios_offset)))<br>
> ? -EFAULT : 0;<br>
> }<br>
> + case AMDGPU_INFO_VBIOS_INFO: {<br>
> + struct drm_amdgpu_info_vbios vbios_info = {};<br>
> + struct atom_context *atom_context;<br>
> +<br>
> + atom_context = adev->mode_info.atom_context;<br>
> + memcpy(<a href="http://vbios_info.name" rel="noreferrer noreferrer" target="_blank">vbios_info.name</a>, atom_context->name, sizeof(atom_context->name));<br>
> + memcpy(vbios_info.vbios_pn, atom_context->vbios_pn, sizeof(atom_context->vbios_pn));<br>
> + vbios_info.version = atom_context->version;<br>
> + memcpy(vbios_info.vbios_ver_str, atom_context->vbios_ver_str,<br>
> + sizeof(atom_context->vbios_ver_str));<br>
> + memcpy(vbios_info.date, atom_context->date, <br>
> +sizeof(atom_context->date));<br>
> +<br>
> + return copy_to_user(out, &vbios_info,<br>
> + min((size_t)size, sizeof(vbios_info))) ? -EFAULT : 0;<br>
> + }<br>
> default:<br>
> DRM_DEBUG_KMS("Invalid request %d\n",<br>
> info->vbios_info.type); diff <br>
> --git a/drivers/gpu/drm/amd/amdgpu/atom.c <br>
> b/drivers/gpu/drm/amd/amdgpu/atom.c<br>
> index 3dcb8b32f48b..6fa2229b7229 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/atom.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/atom.c<br>
> @@ -31,6 +31,7 @@<br>
><br>
> #define ATOM_DEBUG<br>
><br>
> +#include "atomfirmware.h"<br>
> #include "atom.h"<br>
> #include "atom-names.h"<br>
> #include "atom-bits.h"<br>
> @@ -1299,12 +1300,168 @@ static void atom_index_iio(struct atom_context *ctx, int base)<br>
> }<br>
> }<br>
><br>
> +static void atom_get_vbios_name(struct atom_context *ctx) {<br>
> + unsigned char *p_rom;<br>
> + unsigned char str_num;<br>
> + unsigned short off_to_vbios_str;<br>
> + unsigned char *c_ptr;<br>
> + int name_size;<br>
> + int i;<br>
> +<br>
> + const char *na = "--N/A--";<br>
> + char *back;<br>
> +<br>
> + p_rom = ctx->bios;<br>
> +<br>
> + str_num = *(p_rom + OFFSET_TO_GET_ATOMBIOS_NUMBER_OF_STRINGS);<br>
> + if (str_num != 0) {<br>
> + off_to_vbios_str =<br>
> + *(unsigned short *)(p_rom + <br>
> + OFFSET_TO_GET_ATOMBIOS_STRING_START);<br>
> +<br>
> + c_ptr = (unsigned char *)(p_rom + off_to_vbios_str);<br>
> + } else {<br>
> + /* do not know where to find name */<br>
> + memcpy(ctx->name, na, 7);<br>
> + ctx->name[7] = 0;<br>
> + return;<br>
> + }<br>
> +<br>
> + /*<br>
> + * skip the atombios strings, usually 4<br>
> + * 1st is P/N, 2nd is ASIC, 3rd is PCI type, 4th is Memory type<br>
> + */<br>
> + for (i = 0; i < str_num; i++) {<br>
> + while (*c_ptr != 0)<br>
> + c_ptr++;<br>
> + c_ptr++;<br>
> + }<br>
> +<br>
> + /* skip the following 2 chars: 0x0D 0x0A */<br>
> + c_ptr += 2;<br>
> +<br>
> + name_size = strnlen(c_ptr, STRLEN_LONG - 1);<br>
> + memcpy(ctx->name, c_ptr, name_size);<br>
> + back = ctx->name + name_size;<br>
> + while ((*--back) == ' ')<br>
> + ;<br>
> + *(back + 1) = '\0';<br>
> +}<br>
> +<br>
> +static void atom_get_vbios_date(struct atom_context *ctx) {<br>
> + unsigned char *p_rom;<br>
> + unsigned char *date_in_rom;<br>
> +<br>
> + p_rom = ctx->bios;<br>
> +<br>
> + date_in_rom = p_rom + OFFSET_TO_VBIOS_DATE;<br>
> +<br>
> + ctx->date[0] = '2';<br>
> + ctx->date[1] = '0';<br>
> + ctx->date[2] = date_in_rom[6];<br>
> + ctx->date[3] = date_in_rom[7];<br>
> + ctx->date[4] = '/';<br>
> + ctx->date[5] = date_in_rom[0];<br>
> + ctx->date[6] = date_in_rom[1];<br>
> + ctx->date[7] = '/';<br>
> + ctx->date[8] = date_in_rom[3];<br>
> + ctx->date[9] = date_in_rom[4];<br>
> + ctx->date[10] = ' ';<br>
> + ctx->date[11] = date_in_rom[9];<br>
> + ctx->date[12] = date_in_rom[10];<br>
> + ctx->date[13] = date_in_rom[11];<br>
> + ctx->date[14] = date_in_rom[12];<br>
> + ctx->date[15] = date_in_rom[13];<br>
> + ctx->date[16] = '\0';<br>
> +}<br>
> +<br>
> +static unsigned char *atom_find_str_in_rom(struct atom_context *ctx, char *str, int start,<br>
> + int end, int maxlen) {<br>
> + unsigned long str_off;<br>
> + unsigned char *p_rom;<br>
> + unsigned short str_len;<br>
> +<br>
> + str_off = 0;<br>
> + str_len = strnlen(str, maxlen);<br>
> + p_rom = ctx->bios;<br>
> +<br>
> + for (; start <= end; ++start) {<br>
> + for (str_off = 0; str_off < str_len; ++str_off) {<br>
> + if (str[str_off] != *(p_rom + start + str_off))<br>
> + break;<br>
> + }<br>
> +<br>
> + if (str_off == str_len || str[str_off] == 0)<br>
> + return p_rom + start;<br>
> + }<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +static void atom_get_vbios_pn(struct atom_context *ctx) {<br>
> + unsigned char *p_rom;<br>
> + unsigned short off_to_vbios_str;<br>
> + unsigned char *vbios_str;<br>
> + int count;<br>
> +<br>
> + off_to_vbios_str = 0;<br>
> + p_rom = ctx->bios;<br>
> +<br>
> + if (*(p_rom + OFFSET_TO_GET_ATOMBIOS_NUMBER_OF_STRINGS) != 0) {<br>
> + off_to_vbios_str =<br>
> + *(unsigned short *)(p_rom + <br>
> + OFFSET_TO_GET_ATOMBIOS_STRING_START);<br>
> +<br>
> + vbios_str = (unsigned char *)(p_rom + off_to_vbios_str);<br>
> + } else {<br>
> + vbios_str = p_rom + OFFSET_TO_VBIOS_PART_NUMBER;<br>
> + }<br>
> +<br>
> + if (*vbios_str == 0) {<br>
> + vbios_str = atom_find_str_in_rom(ctx, BIOS_ATOM_PREFIX, 3, 1024, 64);<br>
> + if (vbios_str == NULL)<br>
> + vbios_str += sizeof(BIOS_ATOM_PREFIX) - 1;<br>
> + }<br>
> + if (vbios_str != NULL && *vbios_str == 0)<br>
> + vbios_str++;<br>
> +<br>
> + if (vbios_str != NULL) {<br>
> + count = 0;<br>
> + while ((count < BIOS_STRING_LENGTH) && vbios_str[count] >= ' ' &&<br>
> + vbios_str[count] <= 'z') {<br>
> + ctx->vbios_pn[count] = vbios_str[count];<br>
> + count++;<br>
> + }<br>
> +<br>
> + ctx->vbios_pn[count] = 0;<br>
> + }<br>
> +}<br>
> +<br>
> +static void atom_get_vbios_version(struct atom_context *ctx) {<br>
> + unsigned char *vbios_ver;<br>
> +<br>
> + /* find anchor ATOMBIOSBK-AMD */<br>
> + vbios_ver = atom_find_str_in_rom(ctx, BIOS_VERSION_PREFIX, 3, 1024, 64);<br>
> + if (vbios_ver != NULL) {<br>
> + /* skip ATOMBIOSBK-AMD VER */<br>
> + vbios_ver += 18;<br>
> + memcpy(ctx->vbios_ver_str, vbios_ver, STRLEN_NORMAL);<br>
> + } else {<br>
> + ctx->vbios_ver_str[0] = '\0';<br>
> + }<br>
> +}<br>
> +<br>
> struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios) {<br>
> int base;<br>
> struct atom_context *ctx =<br>
> kzalloc(sizeof(struct atom_context), GFP_KERNEL);<br>
> char *str;<br>
> + struct _ATOM_ROM_HEADER *atom_rom_header;<br>
> + struct _ATOM_MASTER_DATA_TABLE *master_table;<br>
> + struct _ATOM_FIRMWARE_INFO *atom_fw_info;<br>
> u16 idx;<br>
><br>
> if (!ctx)<br>
> @@ -1353,6 +1510,21 @@ struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)<br>
> strlcpy(ctx->vbios_version, str, sizeof(ctx->vbios_version));<br>
> }<br>
><br>
> + atom_rom_header = (struct _ATOM_ROM_HEADER *)CSTR(base);<br>
> + if (atom_rom_header->usMasterDataTableOffset != 0) {<br>
> + master_table = (struct _ATOM_MASTER_DATA_TABLE *)<br>
> + CSTR(atom_rom_header->usMasterDataTableOffset);<br>
> + if (master_table->ListOfDataTables.FirmwareInfo != 0) {<br>
> + atom_fw_info = (struct _ATOM_FIRMWARE_INFO *)<br>
> + CSTR(master_table->ListOfDataTables.FirmwareInfo);<br>
> + ctx->version = atom_fw_info->ulFirmwareRevision;<br>
> + }<br>
> + }<br>
> +<br>
> + atom_get_vbios_name(ctx);<br>
> + atom_get_vbios_pn(ctx);<br>
> + atom_get_vbios_date(ctx);<br>
> + atom_get_vbios_version(ctx);<br>
><br>
> return ctx;<br>
> }<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/atom.h <br>
> b/drivers/gpu/drm/amd/amdgpu/atom.h<br>
> index d279759cab47..0c1839824520 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/atom.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/atom.h<br>
> @@ -112,6 +112,10 @@ struct drm_device;<br>
> #define ATOM_IO_SYSIO 2<br>
> #define ATOM_IO_IIO 0x80<br>
><br>
> +#define STRLEN_NORMAL 32<br>
> +#define STRLEN_LONG 64<br>
> +#define STRLEN_VERYLONG 254<br>
> +<br>
> struct card_info {<br>
> struct drm_device *dev;<br>
> void (* reg_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */<br>
> @@ -140,6 +144,12 @@ struct atom_context {<br>
> uint32_t *scratch;<br>
> int scratch_size_bytes;<br>
> char vbios_version[20];<br>
> +<br>
> + uint8_t name[STRLEN_LONG];<br>
> + uint8_t vbios_pn[STRLEN_LONG];<br>
> + uint32_t version;<br>
> + uint8_t vbios_ver_str[STRLEN_NORMAL];<br>
> + uint8_t date[STRLEN_NORMAL];<br>
> };<br>
><br>
> extern int amdgpu_atom_debug;<br>
> diff --git a/drivers/gpu/drm/amd/include/atomfirmware.h <br>
> b/drivers/gpu/drm/amd/include/atomfirmware.h<br>
> index 275468e4be60..28deecc2f990 100644<br>
> --- a/drivers/gpu/drm/amd/include/atomfirmware.h<br>
> +++ b/drivers/gpu/drm/amd/include/atomfirmware.h<br>
> @@ -197,6 +197,9 @@ enum atom_dp_vs_preemph_def{<br>
> DP_VS_LEVEL0_PREEMPH_LEVEL3 = 0x18,<br>
> };<br>
><br>
> +#define BIOS_ATOM_PREFIX "ATOMBIOS"<br>
> +#define BIOS_VERSION_PREFIX "ATOMBIOSBK-AMD"<br>
> +#define BIOS_STRING_LENGTH 43<br>
><br>
> /*<br>
> enum atom_string_def{<br>
> @@ -215,6 +218,8 @@ enum atombios_image_offset{<br>
> MAXSIZE_OF_ATOMBIOS_ASIC_BUS_MEM_TYPE = 20, /*including the terminator 0x0!*/<br>
> OFFSET_TO_GET_ATOMBIOS_NUMBER_OF_STRINGS = 0x2f,<br>
> OFFSET_TO_GET_ATOMBIOS_STRING_START = 0x6e,<br>
> + OFFSET_TO_VBIOS_PART_NUMBER = 0x80,<br>
> + OFFSET_TO_VBIOS_DATE = 0x50,<br>
> };<br>
><br>
> <br>
> /*********************************************************************<br>
> ******* diff --git a/include/uapi/drm/amdgpu_drm.h <br>
> b/include/uapi/drm/amdgpu_drm.h index 9169df7fadee..155fd9918b4d <br>
> 100644<br>
> --- a/include/uapi/drm/amdgpu_drm.h<br>
> +++ b/include/uapi/drm/amdgpu_drm.h<br>
> @@ -756,6 +756,8 @@ struct drm_amdgpu_cs_chunk_data {<br>
> #define AMDGPU_INFO_VBIOS_SIZE 0x1<br>
> /* Subquery id: Query vbios image */<br>
> #define AMDGPU_INFO_VBIOS_IMAGE 0x2<br>
> + /* Subquery id: Query vbios info */<br>
> + #define AMDGPU_INFO_VBIOS_INFO 0x3<br>
> /* Query UVD handles */<br>
> #define AMDGPU_INFO_NUM_HANDLES 0x1C<br>
> /* Query sensor related information */ @@ -949,6 +951,14 @@ struct <br>
> drm_amdgpu_info_firmware {<br>
> __u32 feature;<br>
> };<br>
><br>
> +struct drm_amdgpu_info_vbios {<br>
> + __u8 name[64];<br>
> + __u8 vbios_pn[64];<br>
> + __u32 version;<br>
> + __u8 vbios_ver_str[32];<br>
> + __u8 date[32];<br>
> +};<br>
> +<br>
> #define AMDGPU_VRAM_TYPE_UNKNOWN 0<br>
> #define AMDGPU_VRAM_TYPE_GDDR1 1<br>
> #define AMDGPU_VRAM_TYPE_DDR2 2<br>
> --<br>
> 2.17.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
<a href="mailto:amd-gfx@lists.freedesktop.org" target="_blank" rel="noreferrer">amd-gfx@lists.freedesktop.org</a><br>
<a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Ctom.stdenis%40amd.com%7C332524597a5e42ad491908d919ff414f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637569406377960645%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=ZFBUbqu1VjvQkpnQ4Wy6Q4XE9CB2IcFltOq3Iv12F7U%3D&reserved=0" rel="noreferrer noreferrer" target="_blank">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Ctom.stdenis%40amd.com%7C332524597a5e42ad491908d919ff414f%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637569406377960645%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=ZFBUbqu1VjvQkpnQ4Wy6Q4XE9CB2IcFltOq3Iv12F7U%3D&reserved=0</a><br>
</blockquote></div>