<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body>
    Well I don't think generating an UUID in the kernel makes sense in
    general.<br>
    <br>
    What we can do is to expose the serial number of the device, so that
    userspace can create an UUID if necessary.<br>
    <br>
    Christian.<br>
    <br>
    <div class="moz-cite-prefix">Am 18.05.21 um 22:37 schrieb Nieto,
      David M:<br>
    </div>
    <blockquote type="cite"
cite="mid:BYAPR12MB2840D36066EF94573527A8F4F42C9@BYAPR12MB2840.namprd12.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
      <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);">
          I think the sysfs node should be moved into amdgpu_pm instead
          of the amdgpu_device.c and generation of the unique_id should
          be moved to navi10_ppt.c, similarly to other chips.</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);">
          Thinking it better, generating a random UUID makes no sense in
          the driver level, any application can do the same thing on
          userspace if the UUID sysfs node is empty.</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);">
          So, I think we should do the same as with the unique_id node,
          if the unique_id is not present, just return.</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>
        <hr style="display:inline-block;width:98%" tabindex="-1">
        <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
            face="Calibri, sans-serif" color="#000000"><b>From:</b> Alex
            Deucher <a class="moz-txt-link-rfc2396E" href="mailto:alexdeucher@gmail.com"><alexdeucher@gmail.com></a><br>
            <b>Sent:</b> Tuesday, May 18, 2021 7:12 AM<br>
            <b>To:</b> Gu, JiaWei (Will) <a class="moz-txt-link-rfc2396E" href="mailto:JiaWei.Gu@amd.com"><JiaWei.Gu@amd.com></a><br>
            <b>Cc:</b> amd-gfx list
            <a class="moz-txt-link-rfc2396E" href="mailto:amd-gfx@lists.freedesktop.org"><amd-gfx@lists.freedesktop.org></a>; Deng, Emily
            <a class="moz-txt-link-rfc2396E" href="mailto:Emily.Deng@amd.com"><Emily.Deng@amd.com></a>; Nieto, David M
            <a class="moz-txt-link-rfc2396E" href="mailto:David.Nieto@amd.com"><David.Nieto@amd.com></a><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">On Mon, May 17, 2021 at 1:54 AM
                Jiawei Gu <a class="moz-txt-link-rfc2396E" href="mailto:Jiawei.Gu@amd.com"><Jiawei.Gu@amd.com></a> wrote:<br>
                ><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>
                > Signed-off-by: Jiawei Gu <a class="moz-txt-link-rfc2396E" href="mailto:Jiawei.Gu@amd.com"><Jiawei.Gu@amd.com></a><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>
                > +                       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>
                <br>
                I would suggest putting this in navi10_get_unique_id()
                in navi10_ppt.c<br>
                for consistency since we query this from the SMU on most
                other asics.<br>
                <br>
                Alex<br>
                <br>
                <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>
                > 2.17.1<br>
                ><br>
                > _______________________________________________<br>
                > amd-gfx mailing list<br>
                > <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">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&amp;data=04%7C01%7Cdavid.nieto%40amd.com%7Cb6a43b8c156c4a6964e208d91a070e84%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637569439877514988%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=7lpRnRgRwKASGUmfr3RChO0P6QfRbcpMFggQl6HO%2Bss%3D&amp;reserved=0"
                  moz-do-not-send="true">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Cdavid.nieto%40amd.com%7Cb6a43b8c156c4a6964e208d91a070e84%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637569439877514988%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=7lpRnRgRwKASGUmfr3RChO0P6QfRbcpMFggQl6HO%2Bss%3D&amp;reserved=0</a><br>
              </div>
            </span></font></div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
amd-gfx mailing list
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>