Skip to contentSkip to conversation

drm/amdgpu: Reserve shared memory on VRAM for SR-IOV

PATCH In review Horace Chen 3 participants 3 messages Sep 29, 2017 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Reserve shared memory on VRAM for SR-IOV

SR-IOV need to reserve a piece of shared VRAM at the exact place to exchange data betweem PF and VF. The start address and size of the shared mem are passed to guest through VBIOS structure VRAM_UsageByFirmware.

VRAM_UsageByFirmware is a general feature in VBIOS, it indicates that VBIOS need to reserve a piece of memory on the VRAM.

Because the mem address is specified. Reserve it early in amdgpu_ttm_init to make sure that it can monoplize the space.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h          | 14 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 18 +++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c   | 88 ++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c      |  9 +++
 4 files changed, 128 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +14 -0
index a5b0b67..b802858 100644
@@ -1380,6 +1380,18 @@ struct amdgpu_atcs {
 };
 
 /*
+ * Firmware VRAM reservation
+ */
+struct amdgpu_fw_vram_usage {
+	u64 start_offset;
+	u64 size;
+	struct amdgpu_bo *reserved_bo;
+	volatile uint32_t *va;
+};
+
+int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev);
+
+/*
  * CGS
  */
 struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
@@ -1588,6 +1600,8 @@ struct amdgpu_device {
 	struct delayed_work     late_init_work;
 
 	struct amdgpu_virt	virt;
+	/* firmware VRAM reservation */
+	struct amdgpu_fw_vram_usage fw_vram_usage;
 
 	/* link all shadow bo */
 	struct list_head                shadow_list;
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +17 -1
index ce44358..f66d33e 100644
@@ -1807,6 +1807,8 @@ int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev)
 	uint16_t data_offset;
 	int usage_bytes = 0;
 	struct _ATOM_VRAM_USAGE_BY_FIRMWARE *firmware_usage;
+	u64 start_addr;
+	u64 size;
 
 	if (amdgpu_atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) {
 		firmware_usage = (struct _ATOM_VRAM_USAGE_BY_FIRMWARE *)(ctx->bios + data_offset);
@@ -1815,7 +1817,21 @@ int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev)
 			  le32_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware),
 			  le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb));
 
-		usage_bytes = le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024;
+		start_addr = firmware_usage->asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware;
+		size = firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb;
+
+		if ((uint32_t)(start_addr & ATOM_VRAM_OPERATION_FLAGS_MASK) ==
+			(uint32_t)(ATOM_VRAM_BLOCK_SRIOV_MSG_SHARE_RESERVATION <<
+			ATOM_VRAM_OPERATION_FLAGS_SHIFT)) {
+			/* Firmware request VRAM reservation for SR-IOV */
+			adev->fw_vram_usage.start_offset = (start_addr &
+				(~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
+			adev->fw_vram_usage.size = size << 10;
+			/* Use the default scratch size */
+			usage_bytes = 0;
+		} else {
+			usage_bytes = le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024;
+		}
 	}
 	ctx->scratch_size_bytes = 0;
 	if (usage_bytes == 0)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +88 -0

100 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +9 -0
index 1086f03..a5253cf 100644
@@ -1256,6 +1256,15 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 	/* Change the size here instead of the init above so only lpfn is affected */
 	amdgpu_ttm_set_active_vram_size(adev, adev->mc.visible_vram_size);
 
+	/*
+	 *The reserved vram for firmware must be pinned to the specified
+	 *place on the VRAM, so reserve it early.
+	 */
+	r = amdgpu_fw_reserve_vram_init(adev);
+	if (r) {
+		return r;
+	}
+
 	r = amdgpu_bo_create_kernel(adev, adev->mc.stolen_size, PAGE_SIZE,
 				    AMDGPU_GEM_DOMAIN_VRAM,
 				    &adev->stolen_vga_memory,
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by Alex Deucher
#2 lore raw
In reply to a message not in the archive
Quoted 13 lines

-----Original Message-----
From: Horace Chen [mailto:[email protected]]
Sent: Friday, September 29, 2017 3:21 AM
To: [email protected]
Cc: Deucher, Alexander; Chen, Horace
Subject: [PATCH] drm/amdgpu: Reserve shared memory on VRAM for SR- IOV

SR-IOV need to reserve a piece of shared VRAM at the exact place to exchange data betweem PF and VF. The start address and size of the shared mem are passed to guest through VBIOS structure VRAM_UsageByFirmware.

Quoted 7 lines

VRAM_UsageByFirmware is a general feature in VBIOS, it indicates that VBIOS need to reserve a piece of memory on the VRAM.

Because the mem address is specified. Reserve it early in amdgpu_ttm_init to make sure that it can monoplize the space.

Quoted 233 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h          | 14 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 18 +++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c   | 88
++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c      |  9 +++
 4 files changed, 128 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +12 -0
index a5b0b67..b802858 100644
@@ -1380,6 +1380,18 @@ struct amdgpu_atcs {
 };
 
 /*
+ * Firmware VRAM reservation
+ */
+struct amdgpu_fw_vram_usage {
+	u64 start_offset;
+	u64 size;
+	struct amdgpu_bo *reserved_bo;
+	volatile uint32_t *va;
+};
+
+int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev);
+
+/*
  * CGS
  */
 struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device

*adev);

drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -1588,6 +1600,8 @@ struct amdgpu_device {
 	struct delayed_work     late_init_work;
 
 	struct amdgpu_virt	virt;
+	/* firmware VRAM reservation */
+	struct amdgpu_fw_vram_usage fw_vram_usage;
 
 	/* link all shadow bo */
 	struct list_head                shadow_list;
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +2 -0
index ce44358..f66d33e 100644
@@ -1807,6 +1807,8 @@ int amdgpu_atombios_allocate_fb_scratch(struct
 amdgpu_device *adev)
 	uint16_t data_offset;
 	int usage_bytes = 0;
 	struct _ATOM_VRAM_USAGE_BY_FIRMWARE *firmware_usage;
+	u64 start_addr;
+	u64 size;
 
 	if (amdgpu_atom_parse_data_header(ctx, index, NULL, NULL, NULL,

&data_offset)) {
firmware_usage = (struct
_ATOM_VRAM_USAGE_BY_FIRMWARE *)(ctx->bios + data_offset);

drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +0 -1
@@ -1815,7 +1817,21 @@ int amdgpu_atombios_allocate_fb_scratch(struct
 amdgpu_device *adev)
 			  le32_to_cpu(firmware_usage-
 >asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware),
 			  le16_to_cpu(firmware_usage-
 >asFirmwareVramReserveInfo[0].usFirmwareUseInKb));
 
-		usage_bytes = le16_to_cpu(firmware_usage-
Quoted 1 line

asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024;

drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +1 -0
+		start_addr = firmware_usage-
Quoted 1 line

asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware;

drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +1 -0
+		size = firmware_usage-
Quoted 1 line

asFirmwareVramReserveInfo[0].usFirmwareUseInKb;

drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +2 -0
+
+		if ((uint32_t)(start_addr &

ATOM_VRAM_OPERATION_FLAGS_MASK) ==
+
(uint32_t)(ATOM_VRAM_BLOCK_SRIOV_MSG_SHARE_RESERVATIO
N <<

drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +4 -0
+			ATOM_VRAM_OPERATION_FLAGS_SHIFT)) {
+			/* Firmware request VRAM reservation for SR-IOV */
+			adev->fw_vram_usage.start_offset = (start_addr &
+
	(~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +5 -0
+			adev->fw_vram_usage.size = size << 10;
+			/* Use the default scratch size */
+			usage_bytes = 0;
+		} else {
+			usage_bytes = le16_to_cpu(firmware_usage-
Quoted 1 line

asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024;

drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +1 -0
+		}
 	}
 	ctx->scratch_size_bytes = 0;
 	if (usage_bytes == 0)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +55 -0
index a86d856..02e07a1 100644
@@ -658,6 +658,93 @@ void amdgpu_gart_location(struct amdgpu_device
 *adev, struct amdgpu_mc *mc)
 }
 
 /*
+ * Firmware Reservation function
+ */
+/**
+ * amdgpu_fw_reserve_vram_fini - free fw reserved vram
+ *
+ * @adev: amdgpu_device pointer
+ *
+ * free fw reserved vram if it has been reserved.
+ */
+void amdgpu_fw_reserve_vram_fini(struct amdgpu_device *adev)
+{
+
+	if (adev->fw_vram_usage.reserved_bo == NULL)
+		return;
+
+	if (likely(amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo,
+		true) == 0)) {
+		amdgpu_bo_kunmap(adev->fw_vram_usage.reserved_bo);
+		amdgpu_bo_unpin(adev->fw_vram_usage.reserved_bo);
+		amdgpu_bo_unreserve(adev-
 >fw_vram_usage.reserved_bo);
+	}
+	amdgpu_bo_unref(&adev->fw_vram_usage.reserved_bo);
+
+	adev->fw_vram_usage.va = NULL;
+	adev->fw_vram_usage.reserved_bo = NULL;
+}
+
+/**
+ * amdgpu_fw_reserve_vram_init - create bo vram reservation from fw
+ *
+ * @adev: amdgpu_device pointer
+ *
+ * create bo vram reservation from fw.
+ */
+int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev)
+{
+	int r = 0;
+	u64 gpu_addr;
+	u64 vram_size = adev->mc.visible_vram_size;
+
+	adev->fw_vram_usage.va = NULL;
+	adev->fw_vram_usage.reserved_bo = NULL;
+
+	if (adev->fw_vram_usage.size > 0 &&
+		adev->fw_vram_usage.size <= vram_size) {
+
+		r = amdgpu_bo_create(adev, adev->fw_vram_usage.size,
+			PAGE_SIZE, true, 0,
+			AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
 NULL, NULL, 0,
+			&adev->fw_vram_usage.reserved_bo);
+		if (r)
+			goto error_create;
+
+		r = amdgpu_bo_reserve(adev-
Quoted 1 line

fw_vram_usage.reserved_bo, false);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+		if (r)
+			goto error_reserve;
+		r = amdgpu_bo_pin_restricted(adev-
Quoted 1 line

fw_vram_usage.reserved_bo,

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +12 -0
+			AMDGPU_GEM_DOMAIN_VRAM,
+			adev->fw_vram_usage.start_offset,
+			(adev->fw_vram_usage.start_offset +
+			adev->fw_vram_usage.size), &gpu_addr);
+		if (r)
+			goto error_pin;
+		r = amdgpu_bo_kmap(adev->fw_vram_usage.reserved_bo,
+			(void **)&adev->fw_vram_usage.va);
+		if (r)
+			goto error_kmap;
+
+		amdgpu_bo_unreserve(adev-
Quoted 1 line

fw_vram_usage.reserved_bo);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +18 -0
+	}
+	return r;
+
+error_kmap:
+	amdgpu_bo_unpin(adev->fw_vram_usage.reserved_bo);
+error_pin:
+	amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);
+error_reserve:
+	amdgpu_bo_unref(&adev->fw_vram_usage.reserved_bo);
+error_create:
+	adev->fw_vram_usage.va = NULL;
+	adev->fw_vram_usage.reserved_bo = NULL;
+	return r;
+}
+
+
+/*
  * GPU helpers function.
  */
 /**
@@ -2331,6 +2418,7 @@ void amdgpu_device_fini(struct amdgpu_device
 *adev)
 	/* evict vram memory */
 	amdgpu_bo_evict_vram(adev);
 	amdgpu_ib_pool_fini(adev);
+	amdgpu_fw_reserve_vram_fini(adev);
 	amdgpu_fence_driver_fini(adev);
 	amdgpu_fbdev_fini(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
 	r = amdgpu_fini(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index 1086f03..a5253cf 100644
@@ -1256,6 +1256,15 @@ int amdgpu_ttm_init(struct amdgpu_device
 *adev)
 	/* Change the size here instead of the init above so only lpfn is

affected */
amdgpu_ttm_set_active_vram_size(adev, adev-

Quoted 1 line

mc.visible_vram_size);

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +9 -0
+	/*
+	 *The reserved vram for firmware must be pinned to the specified
+	 *place on the VRAM, so reserve it early.
+	 */
+	r = amdgpu_fw_reserve_vram_init(adev);
+	if (r) {
+		return r;
+	}
+
 	r = amdgpu_bo_create_kernel(adev, adev->mc.stolen_size,

PAGE_SIZE,

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -1
 				    AMDGPU_GEM_DOMAIN_VRAM,
 				    &adev->stolen_vga_memory,
--
Quoted 1 line

2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw
In reply to a message not in the archive

Am 29.09.2017 um 09:21 schrieb Horace Chen:

Quoted 24 lines

SR-IOV need to reserve a piece of shared VRAM at the exact place to exchange data betweem PF and VF. The start address and size of the shared mem are passed to guest through VBIOS structure VRAM_UsageByFirmware.

VRAM_UsageByFirmware is a general feature in VBIOS, it indicates that VBIOS need to reserve a piece of memory on the VRAM.

Because the mem address is specified. Reserve it early in amdgpu_ttm_init to make sure that it can monoplize the space.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h          | 14 +++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 18 +++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c   | 88 ++++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c      |  9 +++
  4 files changed, 128 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index a5b0b67..b802858 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_atcs { · line 1389

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +7 -0
@@ -1380,6 +1380,18 @@ struct amdgpu_atcs {
  };
 
  /*
+ * Firmware VRAM reservation
+ */
+struct amdgpu_fw_vram_usage {
+	u64 start_offset;
+	u64 size;
+	struct amdgpu_bo *reserved_bo;
+	volatile uint32_t *va;

Use something like cpu_address for the variable name here instead. That is usually not a virtual address at all, but a direct mapping.

Quoted 73 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +7 -0
+};
+
+int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev);
+
+/*
   * CGS
   */
  struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
@@ -1588,6 +1600,8 @@ struct amdgpu_device {
  	struct delayed_work     late_init_work;
 
  	struct amdgpu_virt	virt;
+	/* firmware VRAM reservation */
+	struct amdgpu_fw_vram_usage fw_vram_usage;
 
  	/* link all shadow bo */
  	struct list_head                shadow_list;
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +17 -1
index ce44358..f66d33e 100644
@@ -1807,6 +1807,8 @@ int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev)
  	uint16_t data_offset;
  	int usage_bytes = 0;
  	struct _ATOM_VRAM_USAGE_BY_FIRMWARE *firmware_usage;
+	u64 start_addr;
+	u64 size;
 
  	if (amdgpu_atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) {
  		firmware_usage = (struct _ATOM_VRAM_USAGE_BY_FIRMWARE *)(ctx->bios + data_offset);
@@ -1815,7 +1817,21 @@ int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev)
  			  le32_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware),
  			  le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb));
 
-		usage_bytes = le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024;
+		start_addr = firmware_usage->asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware;
+		size = firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb;
+
+		if ((uint32_t)(start_addr & ATOM_VRAM_OPERATION_FLAGS_MASK) ==
+			(uint32_t)(ATOM_VRAM_BLOCK_SRIOV_MSG_SHARE_RESERVATION <<
+			ATOM_VRAM_OPERATION_FLAGS_SHIFT)) {
+			/* Firmware request VRAM reservation for SR-IOV */
+			adev->fw_vram_usage.start_offset = (start_addr &
+				(~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
+			adev->fw_vram_usage.size = size << 10;
+			/* Use the default scratch size */
+			usage_bytes = 0;
+		} else {
+			usage_bytes = le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024;
+		}
  	}
  	ctx->scratch_size_bytes = 0;
  	if (usage_bytes == 0)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +12 -0
index a86d856..02e07a1 100644
@@ -658,6 +658,93 @@ void amdgpu_gart_location(struct amdgpu_device *adev, struct amdgpu_mc *mc)
  }
 
  /*
+ * Firmware Reservation function
+ */
+/**
+ * amdgpu_fw_reserve_vram_fini - free fw reserved vram
+ *
+ * @adev: amdgpu_device pointer
+ *
+ * free fw reserved vram if it has been reserved.
+ */
+void amdgpu_fw_reserve_vram_fini(struct amdgpu_device *adev)
+{
+

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_gart_location(struct amdgpu_device *adev, struct amdgpu_mc *mc) · line 682

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+	if (adev->fw_vram_usage.reserved_bo == NULL)
+		return;
+
+	if (likely(amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo,
+		true) == 0)) {
+		amdgpu_bo_kunmap(adev->fw_vram_usage.reserved_bo);
+		amdgpu_bo_unpin(adev->fw_vram_usage.reserved_bo);
+		amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);
+	}
+	amdgpu_bo_unref(&adev->fw_vram_usage.reserved_bo);

Please use amdgpu_bo_free_kernel() for this.

Apart from that looks good to me,
Christian.

Quoted 86 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +66 -0
+
+	adev->fw_vram_usage.va = NULL;
+	adev->fw_vram_usage.reserved_bo = NULL;
+}
+
+/**
+ * amdgpu_fw_reserve_vram_init - create bo vram reservation from fw
+ *
+ * @adev: amdgpu_device pointer
+ *
+ * create bo vram reservation from fw.
+ */
+int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev)
+{
+	int r = 0;
+	u64 gpu_addr;
+	u64 vram_size = adev->mc.visible_vram_size;
+
+	adev->fw_vram_usage.va = NULL;
+	adev->fw_vram_usage.reserved_bo = NULL;
+
+	if (adev->fw_vram_usage.size > 0 &&
+		adev->fw_vram_usage.size <= vram_size) {
+
+		r = amdgpu_bo_create(adev, adev->fw_vram_usage.size,
+			PAGE_SIZE, true, 0,
+			AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL, 0,
+			&adev->fw_vram_usage.reserved_bo);
+		if (r)
+			goto error_create;
+
+		r = amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo, false);
+		if (r)
+			goto error_reserve;
+		r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo,
+			AMDGPU_GEM_DOMAIN_VRAM,
+			adev->fw_vram_usage.start_offset,
+			(adev->fw_vram_usage.start_offset +
+			adev->fw_vram_usage.size), &gpu_addr);
+		if (r)
+			goto error_pin;
+		r = amdgpu_bo_kmap(adev->fw_vram_usage.reserved_bo,
+			(void **)&adev->fw_vram_usage.va);
+		if (r)
+			goto error_kmap;
+
+		amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);
+	}
+	return r;
+
+error_kmap:
+	amdgpu_bo_unpin(adev->fw_vram_usage.reserved_bo);
+error_pin:
+	amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);
+error_reserve:
+	amdgpu_bo_unref(&adev->fw_vram_usage.reserved_bo);
+error_create:
+	adev->fw_vram_usage.va = NULL;
+	adev->fw_vram_usage.reserved_bo = NULL;
+	return r;
+}
+
+
+/*
   * GPU helpers function.
   */
  /**
@@ -2331,6 +2418,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
  	/* evict vram memory */
  	amdgpu_bo_evict_vram(adev);
  	amdgpu_ib_pool_fini(adev);
+	amdgpu_fw_reserve_vram_fini(adev);
  	amdgpu_fence_driver_fini(adev);
  	amdgpu_fbdev_fini(adev);
  	r = amdgpu_fini(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
index 1086f03..a5253cf 100644
@@ -1256,6 +1256,15 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
  	/* Change the size here instead of the init above so only lpfn is affected */
  	amdgpu_ttm_set_active_vram_size(adev, adev->mc.visible_vram_size);
 
+	/*
+	 *The reserved vram for firmware must be pinned to the specified

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1270

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +7 -0
+	 *place on the VRAM, so reserve it early.
+	 */
+	r = amdgpu_fw_reserve_vram_init(adev);
+	if (r) {
+		return r;
+	}
+
  	r = amdgpu_bo_create_kernel(adev, adev->mc.stolen_size, PAGE_SIZE,
  				    AMDGPU_GEM_DOMAIN_VRAM,
  				    &adev->stolen_vga_memory,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx