Skip to content

Commit b4a8fcc

Browse files
Ellen Panalexdeucher
authored andcommitted
drm/amdgpu: Add logic for VF ipd and VF bios to init from dynamic crit_region offsets
1. Added VF logic in amdgpu_virt to init IP discovery using the offsets from dynamic(v2) critical regions; 2. Added VF logic in amdgpu_virt to init bios image using the offsets from dynamic(v2) critical regions; Signed-off-by: Ellen Pan <yunru.pan@amd.com> Reviewed-by: Lijo Lazar <lijo.lazar@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 13ccaa8 commit b4a8fcc

4 files changed

Lines changed: 85 additions & 14 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ void amdgpu_bios_release(struct amdgpu_device *adev)
9696
* part of the system bios. On boot, the system bios puts a
9797
* copy of the igp rom at the start of vram if a discrete card is
9898
* present.
99-
* For SR-IOV, the vbios image is also put in VRAM in the VF.
99+
* For SR-IOV, if dynamic critical region is not enabled,
100+
* the vbios image is also put at the start of VRAM in the VF.
100101
*/
101102
static bool amdgpu_read_bios_from_vram(struct amdgpu_device *adev)
102103
{
103-
uint8_t __iomem *bios;
104+
uint8_t __iomem *bios = NULL;
104105
resource_size_t vram_base;
105106
resource_size_t size = 256 * 1024; /* ??? */
106107

@@ -114,18 +115,33 @@ static bool amdgpu_read_bios_from_vram(struct amdgpu_device *adev)
114115

115116
adev->bios = NULL;
116117
vram_base = pci_resource_start(adev->pdev, 0);
117-
bios = ioremap_wc(vram_base, size);
118-
if (!bios)
119-
return false;
120118

121119
adev->bios = kmalloc(size, GFP_KERNEL);
122-
if (!adev->bios) {
123-
iounmap(bios);
120+
if (!adev->bios)
124121
return false;
122+
123+
/* For SRIOV with dynamic critical region is enabled,
124+
* the vbios image is put at a dynamic offset of VRAM in the VF.
125+
* If dynamic critical region is disabled, follow the existing logic as on baremetal.
126+
*/
127+
if (amdgpu_sriov_vf(adev) && adev->virt.is_dynamic_crit_regn_enabled) {
128+
if (amdgpu_virt_get_dynamic_data_info(adev,
129+
AMD_SRIOV_MSG_VBIOS_IMG_TABLE_ID, adev->bios, (uint64_t *)&size)) {
130+
amdgpu_bios_release(adev);
131+
return false;
132+
}
133+
} else {
134+
bios = ioremap_wc(vram_base, size);
135+
if (!bios) {
136+
amdgpu_bios_release(adev);
137+
return false;
138+
}
139+
140+
memcpy_fromio(adev->bios, bios, size);
141+
iounmap(bios);
125142
}
143+
126144
adev->bios_size = size;
127-
memcpy_fromio(adev->bios, bios, size);
128-
iounmap(bios);
129145

130146
if (!check_atom_bios(adev, size)) {
131147
amdgpu_bios_release(adev);

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,26 @@ static int amdgpu_discovery_read_binary_from_mem(struct amdgpu_device *adev,
304304
* then it is not required to be reserved.
305305
*/
306306
if (sz_valid) {
307-
uint64_t pos = vram_size - DISCOVERY_TMR_OFFSET;
308-
amdgpu_device_vram_access(adev, pos, (uint32_t *)binary,
309-
adev->discovery.size, false);
310-
adev->discovery.reserve_tmr = true;
307+
if (amdgpu_sriov_vf(adev) && adev->virt.is_dynamic_crit_regn_enabled) {
308+
/* For SRIOV VFs with dynamic critical region enabled,
309+
* we will get the IPD binary via below call.
310+
* If dynamic critical is disabled, fall through to normal seq.
311+
*/
312+
if (amdgpu_virt_get_dynamic_data_info(adev,
313+
AMD_SRIOV_MSG_IPD_TABLE_ID, binary,
314+
(uint64_t *)&adev->discovery.size)) {
315+
dev_err(adev->dev,
316+
"failed to read discovery info from dynamic critical region.");
317+
ret = -EINVAL;
318+
goto exit;
319+
}
320+
} else {
321+
uint64_t pos = vram_size - DISCOVERY_TMR_OFFSET;
322+
323+
amdgpu_device_vram_access(adev, pos, (uint32_t *)binary,
324+
adev->discovery.size, false);
325+
adev->discovery.reserve_tmr = true;
326+
}
311327
} else {
312328
ret = amdgpu_discovery_read_binary_from_sysmem(adev, binary);
313329
}
@@ -316,7 +332,7 @@ static int amdgpu_discovery_read_binary_from_mem(struct amdgpu_device *adev,
316332
dev_err(adev->dev,
317333
"failed to read discovery info from memory, vram size read: %llx",
318334
vram_size);
319-
335+
exit:
320336
return ret;
321337
}
322338

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,14 @@ int amdgpu_virt_init_critical_region(struct amdgpu_device *adev)
10081008
init_data_hdr->bad_page_size_in_kb;
10091009
}
10101010

1011+
/* Validation for critical region info */
1012+
if (adev->virt.crit_regn_tbl[AMD_SRIOV_MSG_IPD_TABLE_ID].size_kb > DISCOVERY_TMR_SIZE) {
1013+
dev_err(adev->dev, "Invalid IP discovery size: 0x%x\n",
1014+
adev->virt.crit_regn_tbl[AMD_SRIOV_MSG_IPD_TABLE_ID].size_kb);
1015+
r = -EINVAL;
1016+
goto out;
1017+
}
1018+
10111019
/* reserved memory starts from crit region base offset with the size of 5MB */
10121020
adev->mman.fw_vram_usage_start_offset = adev->virt.crit_regn.offset;
10131021
adev->mman.fw_vram_usage_size = adev->virt.crit_regn.size_kb << 10;
@@ -1026,6 +1034,35 @@ int amdgpu_virt_init_critical_region(struct amdgpu_device *adev)
10261034
return r;
10271035
}
10281036

1037+
int amdgpu_virt_get_dynamic_data_info(struct amdgpu_device *adev,
1038+
int data_id, uint8_t *binary, uint64_t *size)
1039+
{
1040+
uint32_t data_offset = 0;
1041+
uint32_t data_size = 0;
1042+
enum amd_sriov_msg_table_id_enum data_table_id = data_id;
1043+
1044+
if (data_table_id >= AMD_SRIOV_MSG_MAX_TABLE_ID)
1045+
return -EINVAL;
1046+
1047+
data_offset = adev->virt.crit_regn_tbl[data_table_id].offset;
1048+
data_size = adev->virt.crit_regn_tbl[data_table_id].size_kb << 10;
1049+
1050+
/* Validate on input params */
1051+
if (!binary || !size || *size < (uint64_t)data_size)
1052+
return -EINVAL;
1053+
1054+
/* Proceed to copy the dynamic content */
1055+
amdgpu_device_vram_access(adev,
1056+
(uint64_t)data_offset, (uint32_t *)binary, data_size, false);
1057+
*size = (uint64_t)data_size;
1058+
1059+
dev_dbg(adev->dev,
1060+
"Got %s info from dynamic crit_region_table at offset 0x%x with size of 0x%x bytes.\n",
1061+
amdgpu_virt_dynamic_crit_table_name[data_id], data_offset, data_size);
1062+
1063+
return 0;
1064+
}
1065+
10291066
void amdgpu_virt_init(struct amdgpu_device *adev)
10301067
{
10311068
bool is_sriov = false;

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ void amdgpu_virt_fini_data_exchange(struct amdgpu_device *adev);
442442
void amdgpu_virt_init(struct amdgpu_device *adev);
443443

444444
int amdgpu_virt_init_critical_region(struct amdgpu_device *adev);
445+
int amdgpu_virt_get_dynamic_data_info(struct amdgpu_device *adev,
446+
int data_id, uint8_t *binary, uint64_t *size);
445447

446448
bool amdgpu_virt_can_access_debugfs(struct amdgpu_device *adev);
447449
int amdgpu_virt_enable_access_debugfs(struct amdgpu_device *adev);

0 commit comments

Comments
 (0)