<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">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi Nicolai,</p>
<p><br>
</p>
<p>I was trying to avoid having ASIC specific includes/etc in the amdgpu_device.c file. Agreed that de-numberifying it would be nice. Maybe we can add some /**/ comments to clear it up. I imagine in the future we'll add more fields (upto 32 in this design)
anyways.</p>
<p><br>
</p>
<p>Cheers,</p>
<p>Tom</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Nicolai Hähnle <nhaehnle@gmail.com><br>
<b>Sent:</b> Friday, October 14, 2016 03:25<br>
<b>To:</b> Tom St Denis; amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> StDenis, Tom<br>
<b>Subject:</b> Re: [PATCH 1/3] drm/amd/amdgpu: Add wave reader to debugfs</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">On 11.10.2016 21:18, Tom St Denis wrote:<br>
> Currently supports CZ/VI. Allows nearly atomic read<br>
> of wave data from GPU.<br>
><br>
> Signed-off-by: Tom St Denis <tom.stdenis@amd.com><br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 74 ++++++++++++++++++++++++++++++<br>
> 1 file changed, 74 insertions(+)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> index 89b353418195..b1ab6358fa0f 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> @@ -2914,6 +2914,72 @@ static ssize_t amdgpu_debugfs_sensor_read(struct file *f, char __user *buf,<br>
> return !r ? 4 : r;<br>
> }<br>
><br>
> +static uint32_t wave_read_ind(struct amdgpu_device *adev, uint32_t SQ_INDEX, uint32_t SQ_DATA, uint32_t simd, uint32_t wave, uint32_t address)<br>
> +{<br>
> + WREG32(SQ_INDEX, (wave & 0xF) | ((simd & 0x3) << 4) | (address << 16) | (1 << 13));<br>
> + return RREG32(SQ_DATA);<br>
> +}<br>
> +<br>
> +static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,<br>
> + size_t size, loff_t *pos)<br>
> +{<br>
> + struct amdgpu_device *adev = f->f_inode->i_private;<br>
> + int r, x;<br>
> + ssize_t result=0;<br>
> + uint32_t offset, se, sh, cu, wave, simd, data[16];<br>
> + <br>
> + if (size & 3 || *pos & 3)<br>
> + return -EINVAL;<br>
> +<br>
> + /* decode offset */<br>
> + offset = (*pos & 0x7F);<br>
> + se = ((*pos >> 7) & 0xFF);<br>
> + sh = ((*pos >> 15) & 0xFF);<br>
> + cu = ((*pos >> 23) & 0xFF);<br>
> + wave = ((*pos >> 31) & 0xFF);<br>
> + simd = ((*pos >> 37) & 0xFF);<br>
> + *pos &= 0x7F;<br>
> +<br>
> + /* switch to the specific se/sh/cu */<br>
> + mutex_lock(&adev->grbm_idx_mutex);<br>
> + amdgpu_gfx_select_se_sh(adev, se, sh, cu);<br>
> +<br>
> + x = 0;<br>
> + if (adev->family == AMDGPU_FAMILY_CZ || adev->family == AMDGPU_FAMILY_VI) {<br>
> + /* type 0 wave data */<br>
> + data[x++] = 0;<br>
> + data[x++] = wave_read_ind(adev, 0x2378, 0x2379, simd, wave, 0x12);<br>
> + data[x++] = wave_read_ind(adev, 0x2378, 0x2379, simd, wave, 0x18);<br>
> + data[x++] = wave_read_ind(adev, 0x2378, 0x2379, simd, wave, 0x19);<br>
> + data[x++] = wave_read_ind(adev, 0x2378, 0x2379, simd, wave, 0x27E);<br>
> + data[x++] = wave_read_ind(adev, 0x2378, 0x2379, simd, wave, 0x27F);<br>
> + data[x++] = wave_read_ind(adev, 0x2378, 0x2379, simd, wave, 0x14);<br>
> + data[x++] = wave_read_ind(adev, 0x2378, 0x2379, simd, wave, 0x1A);<br>
> + data[x++] = wave_read_ind(adev, 0x2378, 0x2379, simd, wave, 0x1B);<br>
<br>
I know this is just debug code, but it's still annoying to have all <br>
these magic constants here, when there are perfectly good ixSQ_WAVE_* <br>
etc. defines in the asic_reg headers.<br>
<br>
Nicolai<br>
<br>
> + } else {<br>
> + return -EINVAL;<br>
> + }<br>
> +<br>
> + amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);<br>
> + mutex_unlock(&adev->grbm_idx_mutex);<br>
> +<br>
> + while (size && (*pos < x * 4)) {<br>
> + uint32_t value;<br>
> +<br>
> + value = data[*pos >> 2];<br>
> + r = put_user(value, (uint32_t *)buf);<br>
> + if (r)<br>
> + return r;<br>
> +<br>
> + result += 4;<br>
> + buf += 4;<br>
> + *pos += 4;<br>
> + size -= 4;<br>
> + }<br>
> +<br>
> + return result;<br>
> +}<br>
> +<br>
> static const struct file_operations amdgpu_debugfs_regs_fops = {<br>
> .owner = THIS_MODULE,<br>
> .read = amdgpu_debugfs_regs_read,<br>
> @@ -2951,6 +3017,12 @@ static const struct file_operations amdgpu_debugfs_sensors_fops = {<br>
> .llseek = default_llseek<br>
> };<br>
><br>
> +static const struct file_operations amdgpu_debugfs_wave_fops = {<br>
> + .owner = THIS_MODULE,<br>
> + .read = amdgpu_debugfs_wave_read,<br>
> + .llseek = default_llseek<br>
> +};<br>
> +<br>
> static const struct file_operations *debugfs_regs[] = {<br>
> &amdgpu_debugfs_regs_fops,<br>
> &amdgpu_debugfs_regs_didt_fops,<br>
> @@ -2958,6 +3030,7 @@ static const struct file_operations *debugfs_regs[] = {<br>
> &amdgpu_debugfs_regs_smc_fops,<br>
> &amdgpu_debugfs_gca_config_fops,<br>
> &amdgpu_debugfs_sensors_fops,<br>
> + &amdgpu_debugfs_wave_fops,<br>
> };<br>
><br>
> static const char *debugfs_regs_names[] = {<br>
> @@ -2967,6 +3040,7 @@ static const char *debugfs_regs_names[] = {<br>
> "amdgpu_regs_smc",<br>
> "amdgpu_gca_config",<br>
> "amdgpu_sensors",<br>
> + "amdgpu_wave",<br>
> };<br>
><br>
> static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)<br>
><br>
</div>
</span></font></div>
</div>
</body>
</html>