<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:15pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
It is for unique identification of the GPU in system management applications, the 64 bit asic number is only available in Vega10 and later and not compliant with RFC4122.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
David</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Sunday, May 16, 2021 11:52 PM<br>
<b>To:</b> Gu, JiaWei (Will) <JiaWei.Gu@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Deng, Emily <Emily.Deng@amd.com>; Nieto, David M <David.Nieto@amd.com><br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu: Expose rfc4122 compliant UUID</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Am 17.05.21 um 07:54 schrieb Jiawei Gu:<br>
> Introduce an RFC 4122 compliant UUID for the GPUs derived<br>
> from the unique GPU serial number (from Vega10) on gpus.<br>
> Where this serial number is not available, use a compliant<br>
> random UUID.<br>
><br>
> For virtualization, the unique ID is passed by the host driver<br>
> in the PF2VF structure.<br>
<br>
The question is why this is useful.<br>
<br>
><br>
> Signed-off-by: Jiawei Gu <Jiawei.Gu@amd.com><br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu.h | 36 ++++++++<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 96 +++++++++++++++++++++<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 +<br>
> drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h | 4 +-<br>
> drivers/gpu/drm/amd/amdgpu/nv.c | 5 ++<br>
> drivers/gpu/drm/amd/amdgpu/nv.h | 3 +<br>
> 6 files changed, 146 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> index 3147c1c935c8..ad6d4b55be6c 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> @@ -802,6 +802,40 @@ struct amd_powerplay {<br>
> (rid == 0x01) || \<br>
> (rid == 0x10))))<br>
> <br>
> +union amdgpu_uuid_info {<br>
> + struct {<br>
> + union {<br>
> + struct {<br>
> + uint32_t did : 16;<br>
> + uint32_t fcn : 8;<br>
> + uint32_t asic_7 : 8;<br>
> + };<br>
<br>
Bitfields are not allowed in structures used for communication with <br>
hardware or uAPI.<br>
<br>
Regards,<br>
Christian.<br>
<br>
> + uint32_t time_low;<br>
> + };<br>
> +<br>
> + struct {<br>
> + uint32_t time_mid : 16;<br>
> + uint32_t time_high : 12;<br>
> + uint32_t version : 4;<br>
> + };<br>
> +<br>
> + struct {<br>
> + struct {<br>
> + uint8_t clk_seq_hi : 6;<br>
> + uint8_t variant : 2;<br>
> + };<br>
> + union {<br>
> + uint8_t clk_seq_low;<br>
> + uint8_t asic_6;<br>
> + };<br>
> + uint16_t asic_4;<br>
> + };<br>
> +<br>
> + uint32_t asic_0;<br>
> + };<br>
> + char as_char[16];<br>
> +};<br>
> +<br>
> #define AMDGPU_RESET_MAGIC_NUM 64<br>
> #define AMDGPU_MAX_DF_PERFMONS 4<br>
> struct amdgpu_device {<br>
> @@ -1074,6 +1108,8 @@ struct amdgpu_device {<br>
> char product_name[32];<br>
> char serial[20];<br>
> <br>
> + union amdgpu_uuid_info uuid_info;<br>
> +<br>
> struct amdgpu_autodump autodump;<br>
> <br>
> atomic_t throttling_logging_enabled;<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> index 7c6c435e5d02..079841e1cb52 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> @@ -37,6 +37,7 @@<br>
> #include <linux/vgaarb.h><br>
> #include <linux/vga_switcheroo.h><br>
> #include <linux/efi.h><br>
> +#include <linux/uuid.h><br>
> #include "amdgpu.h"<br>
> #include "amdgpu_trace.h"<br>
> #include "amdgpu_i2c.h"<br>
> @@ -3239,11 +3240,104 @@ static int amdgpu_device_get_job_timeout_settings(struct amdgpu_device *adev)<br>
> return ret;<br>
> }<br>
> <br>
> +static bool amdgpu_is_uuid_info_empty(union amdgpu_uuid_info *uuid_info)<br>
> +{<br>
> + return (uuid_info->time_low == 0 &&<br>
> + uuid_info->time_mid == 0 &&<br>
> + uuid_info->time_high == 0 &&<br>
> + uuid_info->version == 0 &&<br>
> + uuid_info->clk_seq_hi == 0 &&<br>
> + uuid_info->variant == 0 &&<br>
> + uuid_info->clk_seq_low == 0 &&<br>
> + uuid_info->asic_4 == 0 &&<br>
> + uuid_info->asic_0 == 0);<br>
> +}<br>
> +<br>
> +static void amdgpu_gen_uuid_info(union amdgpu_uuid_info *uuid_info,<br>
> + uint64_t serial, uint16_t did, uint8_t idx)<br>
> +{<br>
> + uint16_t clk_seq = 0;<br>
> +<br>
> + /* Step1: insert clk_seq */<br>
> + uuid_info->clk_seq_low = (uint8_t)clk_seq;<br>
> + uuid_info->clk_seq_hi = (uint8_t)(clk_seq >> 8) & 0x3F;<br>
> +<br>
> + /* Step2: insert did */<br>
> + uuid_info->did = did;<br>
> +<br>
> + /* Step3: insert vf idx */<br>
> + uuid_info->fcn = idx;<br>
> +<br>
> + /* Step4: insert serial */<br>
> + uuid_info->asic_0 = (uint32_t)serial;<br>
> + uuid_info->asic_4 = (uint16_t)(serial >> 4 * 8) & 0xFFFF;<br>
> + uuid_info->asic_6 = (uint8_t)(serial >> 6 * 8) & 0xFF;<br>
> + uuid_info->asic_7 = (uint8_t)(serial >> 7 * 8) & 0xFF;<br>
> +<br>
> + /* Step5: insert version */<br>
> + uuid_info->version = 1;<br>
> + /* Step6: insert variant */<br>
> + uuid_info->variant = 2;<br>
> +}<br>
> +<br>
> +/* byte reverse random uuid */<br>
> +static void amdgpu_gen_uuid_random(union amdgpu_uuid_info *uuid_info)<br>
> +{<br>
> + char b0, b1;<br>
> + int i;<br>
> +<br>
> + generate_random_uuid(uuid_info->as_char);<br>
> + for (i = 0; i < 8; i++) {<br>
> + b0 = uuid_info->as_char[i];<br>
> + b1 = uuid_info->as_char[16-i];<br>
> + uuid_info->as_char[16-i] = b0;<br>
> + uuid_info->as_char[i] = b1;<br>
> + }<br>
> +}<br>
> +<br>
> +/**<br>
> + *<br>
> + * The amdgpu driver provides a sysfs API for providing uuid data.<br>
> + * The file uuid_info is used for this, and returns string of amdgpu uuid.<br>
> + */<br>
> +static ssize_t amdgpu_get_uuid_info(struct device *dev,<br>
> + struct device_attribute *attr,<br>
> + char *buf)<br>
> +{<br>
> + struct drm_device *ddev = dev_get_drvdata(dev);<br>
> + struct amdgpu_device *adev = drm_to_adev(ddev);//ddev->dev_private;<br>
> + union amdgpu_uuid_info *uuid = &adev->uuid_info;<br>
> +<br>
> + return sysfs_emit(buf,<br>
> + "%08x-%04x-%x%03x-%02x%02x-%04x%08x\n",<br>
> + uuid->time_low,<br>
> + uuid->time_mid,<br>
> + uuid->version,<br>
> + uuid->time_high,<br>
> + uuid->clk_seq_hi |<br>
> + uuid->variant << 6,<br>
> + uuid->clk_seq_low,<br>
> + uuid->asic_4,<br>
> + uuid->asic_0);<br>
> +}<br>
> +static DEVICE_ATTR(uuid_info, S_IRUGO, amdgpu_get_uuid_info, NULL);<br>
> +<br>
> +static void amdgpu_uuid_init(struct amdgpu_device *adev)<br>
> +{<br>
> + if (amdgpu_is_uuid_info_empty(&adev->uuid_info)) {<br>
> + if (adev->unique_id)<br>
> + amdgpu_gen_uuid_info(&adev->uuid_info, adev->unique_id, adev->pdev->device, 31);<br>
> + else<br>
> + amdgpu_gen_uuid_random(&adev->uuid_info);<br>
> + }<br>
> +}<br>
> +<br>
> static const struct attribute *amdgpu_dev_attributes[] = {<br>
> &dev_attr_product_name.attr,<br>
> &dev_attr_product_number.attr,<br>
> &dev_attr_serial_number.attr,<br>
> &dev_attr_pcie_replay_count.attr,<br>
> + &dev_attr_uuid_info.attr,<br>
> NULL<br>
> };<br>
> <br>
> @@ -3551,6 +3645,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,<br>
> <br>
> amdgpu_fbdev_init(adev);<br>
> <br>
> + amdgpu_uuid_init(adev);<br>
> +<br>
> r = amdgpu_pm_sysfs_init(adev);<br>
> if (r) {<br>
> adev->pm_sysfs_en = false;<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c<br>
> index b71dd1deeb2d..2dfebfe38079 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c<br>
> @@ -429,6 +429,7 @@ static void amdgpu_virt_add_bad_page(struct amdgpu_device *adev,<br>
> static int amdgpu_virt_read_pf2vf_data(struct amdgpu_device *adev)<br>
> {<br>
> struct amd_sriov_msg_pf2vf_info_header *pf2vf_info = adev->virt.fw_reserve.p_pf2vf;<br>
> + union amdgpu_uuid_info *uuid = &adev->uuid_info;<br>
> uint32_t checksum;<br>
> uint32_t checkval;<br>
> <br>
> @@ -498,6 +499,9 @@ static int amdgpu_virt_read_pf2vf_data(struct amdgpu_device *adev)<br>
> <br>
> adev->unique_id =<br>
> ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->uuid;<br>
> +<br>
> + memcpy(uuid, &((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->uuid_info_reserved,<br>
> + sizeof(union amdgpu_uuid_info));<br>
> break;<br>
> default:<br>
> DRM_ERROR("invalid pf2vf version\n");<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h b/drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h<br>
> index a434c71fde8e..0d1d36e82aeb 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h<br>
> @@ -203,9 +203,9 @@ struct amd_sriov_msg_pf2vf_info {<br>
> uint32_t encode_max_frame_pixels;<br>
> } mm_bw_management[AMD_SRIOV_MSG_RESERVE_VCN_INST];<br>
> /* UUID info */<br>
> - struct amd_sriov_msg_uuid_info uuid_info;<br>
> + uint32_t uuid_info_reserved[4];<br>
> /* reserved */<br>
> - uint32_t reserved[256 - 47];<br>
> + uint32_t reserved[256-47];<br>
> };<br>
> <br>
> struct amd_sriov_msg_vf2pf_info_header {<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c<br>
> index 32c34470404c..16d4a480f4c0 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/nv.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/nv.c<br>
> @@ -1167,6 +1167,11 @@ static int nv_common_early_init(void *handle)<br>
> if (amdgpu_sriov_vf(adev))<br>
> adev->rev_id = 0;<br>
> adev->external_rev_id = adev->rev_id + 0xa;<br>
> + if (!amdgpu_sriov_vf(adev)) {<br>
> + adev->unique_id = RREG32(mmFUSE_DATA_730);<br>
> + adev->unique_id <<= 32;<br>
> + adev->unique_id |= RREG32(mmFUSE_DATA_729);<br>
> + }<br>
> break;<br>
> case CHIP_SIENNA_CICHLID:<br>
> adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/nv.h b/drivers/gpu/drm/amd/amdgpu/nv.h<br>
> index 515d67bf249f..520ac2b98744 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/nv.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/nv.h<br>
> @@ -26,6 +26,9 @@<br>
> <br>
> #include "nbio_v2_3.h"<br>
> <br>
> +#define mmFUSE_DATA_729 (0x176D9)<br>
> +#define mmFUSE_DATA_730 (0x176DA)<br>
> +<br>
> void nv_grbm_select(struct amdgpu_device *adev,<br>
> u32 me, u32 pipe, u32 queue, u32 vmid);<br>
> void nv_set_virt_ops(struct amdgpu_device *adev);<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>