<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;" dir="ltr">
<p>Hi Edward,</p>
<p><br>
</p>
<p>I don't think 'f' could be NULL there nor could the private data be NULL because it's initialized to point to the amdgpu_device when the entry is added to the vfs.</p>
<p><br>
</p>
<p>I can sort out the whitespace though.</p>
<p><br>
</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> Edward O'Callaghan <funfunctor@folklore1984.net><br>
<b>Sent:</b> Monday, December 5, 2016 14:59<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 debugfs support for reading GPRs</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Hi Tom,<br>
<br>
On 12/06/2016 05:36 AM, Tom St Denis wrote:<br>
> Implemented for SGPRs for GFX v8 initially.<br>
> <br>
> Signed-off-by: Tom St Denis <tom.stdenis@amd.com><br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 72 ++++++++++++++++++++++++++++++<br>
> drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 25 +++++++++++<br>
> 3 files changed, 99 insertions(+)<br>
> <br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> index 4f64bb16a8d3..2834451eef8a 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> @@ -844,6 +844,8 @@ struct amdgpu_gfx_funcs {<br>
> uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);<br>
> void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);<br>
> void (*read_wave_data)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields);<br>
> + void (*read_wave_vgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t thread, uint32_t start, uint32_t size, uint32_t *dst);<br>
> + void (*read_wave_sgprs)(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t start, uint32_t size, uint32_t *dst);<br>
> };<br>
> <br>
> struct amdgpu_gfx {<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> index 25ad736b5ca5..7f9cb1c85d75 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
> @@ -3055,6 +3055,71 @@ static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,<br>
> return result;<br>
> }<br>
> <br>
> +static ssize_t amdgpu_debugfs_gpr_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>
<br>
Could f potentially be null here?<br>
<br>
> + int r;<br>
> + ssize_t result=0;<br>
<br>
result = 0<br>
<br>
> + uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;<br>
> +<br>
> + if (size & 3 || *pos & 3)<br>
> + return -EINVAL;<br>
> +<br>
> + /* decode offset */<br>
> + offset = (*pos & 0xFFF);<br>
> + se = ((*pos >> 12) & 0xFF);<br>
> + sh = ((*pos >> 20) & 0xFF);<br>
> + cu = ((*pos >> 28) & 0xFF);<br>
> + wave = ((*pos >> 36) & 0xFF);<br>
> + simd = ((*pos >> 44) & 0xFF);<br>
> + thread = ((*pos >> 52) & 0xFF);<br>
> + bank = ((*pos >> 60) & 1);<br>
> +<br>
> + /* sanity check offset/size */<br>
> + if (offset + size > (adev->gfx.config.max_gprs << 2))<br>
> + return -EINVAL;<br>
> +<br>
> + data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);<br>
> + if (!data)<br>
> + return -ENOMEM;<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>
> + if (bank == 0) {<br>
> + if (adev->gfx.funcs->read_wave_vgprs)<br>
> + adev->gfx.funcs->read_wave_vgprs(adev, simd, wave, thread, offset>>2, size>>2, data);<br>
> + } else {<br>
> + if (adev->gfx.funcs->read_wave_sgprs)<br>
> + adev->gfx.funcs->read_wave_sgprs(adev, simd, wave, offset>>2, size>>2, data);<br>
> + }<br>
> +<br>
> + amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);<br>
> + mutex_unlock(&adev->grbm_idx_mutex);<br>
> +<br>
> + while (size) {<br>
> + uint32_t value;<br>
> +<br>
> + value = data[offset >> 2];<br>
> + r = put_user(value, (uint32_t *)buf);<br>
> + if (r) {<br>
> + result = r;<br>
> + goto err;<br>
> + }<br>
> +<br>
> + result += 4;<br>
> + buf += 4;<br>
> + offset += 4;<br>
> + size -= 4;<br>
> + }<br>
> +<br>
> +err:<br>
> + kfree(data);<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>
> @@ -3097,6 +3162,11 @@ static const struct file_operations amdgpu_debugfs_wave_fops = {<br>
> .read = amdgpu_debugfs_wave_read,<br>
> .llseek = default_llseek<br>
> };<br>
> +static const struct file_operations amdgpu_debugfs_gpr_fops = {<br>
> + .owner = THIS_MODULE,<br>
> + .read = amdgpu_debugfs_gpr_read,<br>
> + .llseek = default_llseek<br>
> +};<br>
> <br>
> static const struct file_operations *debugfs_regs[] = {<br>
> &amdgpu_debugfs_regs_fops,<br>
> @@ -3106,6 +3176,7 @@ static const struct file_operations *debugfs_regs[] = {<br>
> &amdgpu_debugfs_gca_config_fops,<br>
> &amdgpu_debugfs_sensors_fops,<br>
> &amdgpu_debugfs_wave_fops,<br>
> + &amdgpu_debugfs_gpr_fops,<br>
> };<br>
> <br>
> static const char *debugfs_regs_names[] = {<br>
> @@ -3116,6 +3187,7 @@ static const char *debugfs_regs_names[] = {<br>
> "amdgpu_gca_config",<br>
> "amdgpu_sensors",<br>
> "amdgpu_wave",<br>
> + "amdgpu_gpr",<br>
> };<br>
> <br>
> static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
> index 9b8d3fe67adb..180309f5784c 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
> @@ -5184,6 +5184,21 @@ static uint32_t wave_read_ind(struct amdgpu_device *adev, uint32_t simd, uint32_<br>
> return RREG32(mmSQ_IND_DATA);<br>
> }<br>
> <br>
> +static void wave_read_regs(struct amdgpu_device *adev, uint32_t simd,<br>
> + uint32_t wave, uint32_t thread,<br>
> + uint32_t regno, uint32_t num, uint32_t *out)<br>
> +{<br>
> + WREG32(mmSQ_IND_INDEX,<br>
> + (wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |<br>
> + (simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |<br>
> + (regno << SQ_IND_INDEX__INDEX__SHIFT) |<br>
> + (thread << SQ_IND_INDEX__THREAD_ID__SHIFT) |<br>
> + (SQ_IND_INDEX__FORCE_READ_MASK) |<br>
> + (SQ_IND_INDEX__AUTO_INCR_MASK));<br>
> + while (num--)<br>
> + *(out++) = RREG32(mmSQ_IND_DATA);<br>
> +}<br>
> +<br>
> static void gfx_v8_0_read_wave_data(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields)<br>
> {<br>
> /* type 0 wave data */<br>
> @@ -5208,11 +5223,21 @@ static void gfx_v8_0_read_wave_data(struct amdgpu_device *adev, uint32_t simd, u<br>
> dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_M0);<br>
> }<br>
> <br>
> +static void gfx_v8_0_read_wave_sgprs(struct amdgpu_device *adev, uint32_t simd,<br>
> + uint32_t wave, uint32_t start,<br>
> + uint32_t size, uint32_t *dst)<br>
> +{<br>
> + wave_read_regs(<br>
> + adev, simd, wave, 0,<br>
> + start + SQIND_WAVE_SGPRS_OFFSET, size, dst);<br>
> +}<br>
> +<br>
> <br>
> static const struct amdgpu_gfx_funcs gfx_v8_0_gfx_funcs = {<br>
> .get_gpu_clock_counter = &gfx_v8_0_get_gpu_clock_counter,<br>
> .select_se_sh = &gfx_v8_0_select_se_sh,<br>
> .read_wave_data = &gfx_v8_0_read_wave_data,<br>
> + .read_wave_sgprs = &gfx_v8_0_read_wave_sgprs,<br>
<br>
Just fyi, these & are actually redundant when it comes to func ptr's.<br>
<br>
> };<br>
> <br>
> static int gfx_v8_0_early_init(void *handle)<br>
> <br>
<br>
Kind Regards,<br>
Edward.<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>