<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Yuan, Xiaojie <Xiaojie.Yuan@amd.com><br>
<b>Sent:</b> Friday, October 11, 2019 12:09 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> alexdeucher@gmail.com <alexdeucher@gmail.com>; Xiao, Jack <Jack.Xiao@amd.com>; Yuan, Xiaojie <Xiaojie.Yuan@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com><br>
<b>Subject:</b> [PATCH v2] drm/amdgpu/discovery: reserve discovery data at the top of VRAM</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">IP Discovery data is TMR fenced by the latest PSP BL,<br>
so we need to reserve this region.<br>
<br>
Tested on navi10/12/14 with VBIOS integrated with latest PSP BL.<br>
<br>
v2: use DISCOVERY_TMR_SIZE macro as bo size<br>
use amdgpu_bo_create_kernel_at() to allocate bo<br>
<br>
Signed-off-by: Xiaojie Yuan <xiaojie.yuan@amd.com><br>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 +<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 4 ++--<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 2 ++<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++++++++++++++++<br>
drivers/gpu/drm/amd/include/discovery.h | 1 -<br>
5 files changed, 22 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
index be0b2c69c223..6775647f0ba5 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
@@ -812,6 +812,7 @@ struct amdgpu_device {<br>
uint8_t *bios;<br>
uint32_t bios_size;<br>
struct amdgpu_bo *stolen_vga_memory;<br>
+ struct amdgpu_bo *discovery_memory;<br>
uint32_t bios_scratch_reg_offset;<br>
uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c<br>
index 1481899f86c1..71198c5318e1 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c<br>
@@ -136,7 +136,7 @@ static int amdgpu_discovery_read_binary(struct amdgpu_device *adev, uint8_t *bin<br>
{<br>
uint32_t *p = (uint32_t *)binary;<br>
uint64_t vram_size = (uint64_t)RREG32(mmRCC_CONFIG_MEMSIZE) << 20;<br>
- uint64_t pos = vram_size - BINARY_MAX_SIZE;<br>
+ uint64_t pos = vram_size - DISCOVERY_TMR_SIZE;<br>
unsigned long flags;<br>
<br>
while (pos < vram_size) {<br>
@@ -179,7 +179,7 @@ int amdgpu_discovery_init(struct amdgpu_device *adev)<br>
uint16_t checksum;<br>
int r;<br>
<br>
- adev->discovery = kzalloc(BINARY_MAX_SIZE, GFP_KERNEL);<br>
+ adev->discovery = kzalloc(DISCOVERY_TMR_SIZE, GFP_KERNEL);<br>
if (!adev->discovery)<br>
return -ENOMEM;<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h<br>
index 85b8c4d4d576..5a6693d7d269 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h<br>
@@ -24,6 +24,8 @@<br>
#ifndef __AMDGPU_DISCOVERY__<br>
#define __AMDGPU_DISCOVERY__<br>
<br>
+#define DISCOVERY_TMR_SIZE (64 << 10)<br>
+<br>
int amdgpu_discovery_init(struct amdgpu_device *adev);<br>
void amdgpu_discovery_fini(struct amdgpu_device *adev);<br>
int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
index edffc883549a..ed7b10e0848d 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
@@ -1955,6 +1955,20 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)<br>
NULL, &stolen_vga_buf);<br>
if (r)<br>
return r;<br>
+<br>
+ /*<br>
+ * reserve one TMR (64K) memory at the top of VRAM which holds<br>
+ * IP Discovery data and is protected by PSP.<br>
+ */<br>
+ r = amdgpu_bo_create_kernel_at(adev,<br>
+ adev->gmc.real_vram_size - DISCOVERY_TMR_SIZE,<br>
+ DISCOVERY_TMR_SIZE,<br>
+ AMDGPU_GEM_DOMAIN_VRAM,<br>
+ &adev->discovery_memory,<br>
+ NULL);<br>
+ if (r)<br>
+ return r;<br>
+<br>
DRM_INFO("amdgpu: %uM of VRAM memory ready\n",<br>
(unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));<br>
<br>
@@ -2024,6 +2038,9 @@ void amdgpu_ttm_late_init(struct amdgpu_device *adev)<br>
void *stolen_vga_buf;<br>
/* return the VGA stolen memory (if any) back to VRAM */<br>
amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, &stolen_vga_buf);<br>
+<br>
+ /* return the IP Discovery TMR memory back to VRAM */<br>
+ amdgpu_bo_free_kernel(&adev->discovery_memory, NULL, NULL);<br>
}<br>
<br>
/**<br>
diff --git a/drivers/gpu/drm/amd/include/discovery.h b/drivers/gpu/drm/amd/include/discovery.h<br>
index 5dcb776548d8..7ec4331e67f2 100644<br>
--- a/drivers/gpu/drm/amd/include/discovery.h<br>
+++ b/drivers/gpu/drm/amd/include/discovery.h<br>
@@ -25,7 +25,6 @@<br>
#define _DISCOVERY_H_<br>
<br>
#define PSP_HEADER_SIZE 256<br>
-#define BINARY_MAX_SIZE (64 << 10)<br>
#define BINARY_SIGNATURE 0x28211407<br>
#define DISCOVERY_TABLE_SIGNATURE 0x53445049<br>
<br>
-- <br>
2.20.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a></div>
</span></font></div>
</body>
</html>