drm/amdgpu: add amdgpu_discovery_log_bad_signature helper
Subsystems (2)
Alex Deucher
maintainerPATCH 1/14 drm/amdgpu: add amdgpu_discovery_log_bad_signature helper
From: Feifei Xu <[email protected]>
Add a helper that prints the actual vs expected signature for debugging purpose.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +13 -2
@@ -701,6 +701,18 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev,return 0 ; } +static void amdgpu_discovery_log_bad_signature (struct amdgpu_device *adev, +uint8_t *discovery_bin, +const char *fw_name) +{ +dev_err (adev->dev, +"get invalid ip discovery binary signature: got 0x%08x, expected 0x%08x (source=%s)\n" , +le32_to_cpu (((struct binary_header *)discovery_bin)->binary_signature), +BINARY_SIGNATURE , fw_name ?"file" :"mem" ); +print_hex_dump (KERN_ERR ,"ip_discovery head: " ,DUMP_PREFIX_OFFSET , +16 ,1 , discovery_bin,64 , false); +} +static int amdgpu_discovery_init (struct amdgpu_device *adev) {struct binary_header *bhdr;
@@ -736,8 +748,7 @@ static int amdgpu_discovery_init(struct amdgpu_device *adev)/* check the ip discovery binary signature */ if (!amdgpu_discovery_verify_binary_signature (discovery_bin)) { -dev_err (adev->dev, -"get invalid ip discovery binary signature\n" ); +amdgpu_discovery_log_bad_signature (adev, discovery_bin, fw_name); r = -EINVAL ; goto out; }
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 2/14 drm/amdgpu: add MEM_RESERVED_INFO to discovery table
From: Feifei Xu <[email protected]>
MEM_RESERVED_INFO holds the reserved info like size/offset for firmware usage.
On soc_v1_0, MASTER_DIE_UMF_REGION_ID is to query UMF reserved region info for master die MPASP. SPECIFIC_PURPOSE_REGION_ID is to query VRAM base.
v1->v2: convert // to /* */ and move comments ahead of declarations
(per Christian's review)
--- drivers/gpu/drm/amd/include/discovery.h | 54 ++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/include/discovery.h +53 -1
@@ -33,6 +33,11 @@#define MALL_INFO_TABLE_ID 0x4C4C414D#define NPS_INFO_TABLE_ID 0x0053504E +/* = ('I' << 16u | 'R' << 8u | 'M') */ +#define MEM_RSV_TABLE_SIGNATURE 0x0049524D +#define MEM_RSV_TABLE_VERSION 0x01 +#define MAX_MEM_REGION_NUM 16 + typedef enum { IP_DISCOVERY = 0, GC,
@@ -40,7 +45,8 @@ typedef enum {VCN_INFO ,MALL_INFO ,NPS_INFO , - TOTAL_TABLES = 6 +MEM_RESERVED_INFO , + TOTAL_TABLES = 7 } table;#pragma pack(1)
@@ -504,6 +510,52 @@ struct nps_info_v1_0 { instance_info[NPS_INFO_TABLE_MAX_NUM_INSTANCES]; }; +typedef enum { +NO_RESERVED_REGION_ID =0 , +/* reserved for UEFI GOP/DMUB FW */ +PRE_OS_DISP_FW_REGION_ID =1 , +/* UMF reserved region for master die MPASP */ +MASTER_DIE_UMF_REGION_ID =2 , +/* DCC meta data */ +DCC_META_DATA_REGION_ID =3 , +/* GPUVM page fault region */ +VM_PAGE_FAULT_REGION_ID =4 , +/* G7 Alternate Pstate Aperture 1 */ +G7_PSTATE_APERTURE1_ID =5 , +/* G7 Alternate Pstate Aperture 2 */ +G7_PSTATE_APERTURE2_ID =6 , +/* G7 Alternate Pstate Mirror Region */ +G7_PSTATE_MIRROR_REGION_ID =7 , +/* G7 Pstate Training Data */ +G7_TRAINING_DATA_REGION_ID =8 , +/* Specific purpose memory region */ +SPECIFIC_PURPOSE_REGION_ID =9 , +MEM_RESERVED_REGION_NUM , +}MEM_RESERVED_REGION_ID ; + +typedef struct mem_reserved_info_header { +/* Table Signature */ +uint32_t signature; +/* Table Version */ +uint32_t version; +uint32_t size; +}mem_reserved_info_header ; + +typedef struct mem_reserved_info { +/* enum of MEM_RESERVED_REGION_ID */ +uint32_t reserved_region_id; +/* Memory Reserved Region Size */ +uint64_t reserved_region_size; +/* Memory Reserved Region Start Address */ +uint64_t reserved_region_start; +}mem_reserved_info ; + +typedef struct mem_reserved_info_table_v1_0 { +mem_reserved_info_header header; +uint32_t list_num; +mem_reserved_info list[MAX_MEM_REGION_NUM ]; +}mem_reserved_info_table_v1_0 ; +#pragma pack()#endif
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 3/14 drm/amdgpu: Add NPS_INFO case to amdgpu_discovery_table_check
In reply to Alex DeucherFrom: Feifei Xu <[email protected]>
Add a NPS_INFO case with check_table=false to skip annoying "invalid ip discovery table id" error.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +5 -0
@@ -679,6 +679,11 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev, check_table = false;break ; } +case NPS_INFO : { + table_name ="nps table" ; + check_table = false; +break ; + }default :dev_err (adev->dev,"invalid ip discovery table id %d specified\n" , table_id); check_table = false;
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 4/14 drm/amdgpu: add amdgpu_discovery_get_mem_reserved_info_table
In reply to Alex DeucherFrom: Feifei Xu <[email protected]>
Add interface to query the optional MEM_RESERVED_INFO table:
- introduce amdgpu_discovery_get_mem_reserved_info_table() which
resolves the table from the discovery binary and caches the pointer
in adev->discovery.mem_reserved_table so subsequent lookups are
cheap;- invoke it once at init time. Missing/invalid table is non-fatal.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 55 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 4 ++ 2 files changed, 58 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +54 -1
@@ -684,6 +684,15 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev, check_table = false;break ; } +case MEM_RESERVED_INFO : { +struct mem_reserved_info_header *mrhdr = + (struct mem_reserved_info_header *)(discovery_bin + offset); + act_val =le32_to_cpu (mrhdr->signature); + exp_val =MEM_RSV_TABLE_SIGNATURE ; + table_size =le32_to_cpu (mrhdr->size); + table_name ="mem_reserved table" ; +break ; + }default :dev_err (adev->dev,"invalid ip discovery table id %d specified\n" , table_id); check_table = false;
@@ -772,12 +781,17 @@ static int amdgpu_discovery_init(struct amdgpu_device *adev) goto out; } -for (table_id =0 ; table_id <=MALL_INFO ; table_id++) { +for (table_id =0 ; table_id <TOTAL_TABLES ; table_id++) { r =amdgpu_discovery_table_check (adev, discovery_bin, table_id);if (r) goto out; } +/* +* Resolve the MEM_RESERVED_INFO table once at init time. The table +* is optional, so missing it is not a fatal error. +*/ +amdgpu_discovery_get_mem_reserved_info_table (adev);return 0 ; out:
@@ -796,6 +810,8 @@ void amdgpu_discovery_fini(struct amdgpu_device *adev)kfree (adev->discovery.bin); adev->discovery.bin =NULL ; +/* Cached pointer lives inside discovery.bin; drop it to avoid UAF. */ + adev->discovery.mem_reserved_table =NULL ; } static int amdgpu_discovery_validate_ip(struct amdgpu_device *adev,
@@ -2375,6 +2391,43 @@ int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev,return 0 ; } +/* +* Resolve the MEM_RESERVED_INFO table from the IP discovery binary and +* cache it in adev->discovery.mem_reserved_table. +* Return: 0 on success, -ENOENT/-EINVAL if the table unavailable. +*/ +int amdgpu_discovery_get_mem_reserved_info_table (struct amdgpu_device *adev) +{ +uint8_t *discovery_bin = adev->discovery.bin; +struct table_info *info; + +/* If already queried, do not query again. */ +if (adev->discovery.mem_reserved_table) +return 0 ; + +if (!discovery_bin) { +dev_err (adev->dev,"ip discovery uninitialized\n" ); +return -ENOENT ; + } + +if (amdgpu_discovery_get_table_info (adev, &info,MEM_RESERVED_INFO )) { +dev_dbg (adev->dev,"MEM_RESERVED_INFO table entry not present\n" ); +return -EINVAL ; + } + +if (!le16_to_cpu (info->offset)) { +dev_dbg (adev->dev,"MEM_RESERVED_INFO table offset is 0, invalid!\n" ); +return -EINVAL ; + } + +/* Cache for subsequent lookups. */ + adev->discovery.mem_reserved_table = + (struct mem_reserved_info_table_v1_0 *)(discovery_bin +le16_to_cpu (info->offset)); + +dev_dbg (adev->dev,"MEM_RESERVED_INFO table exist\n" ); +return 0 ; +} +static int amdgpu_discovery_set_common_ip_blocks (struct amdgpu_device *adev) {/* what IP to use for this? */
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h +4 -0
@@ -25,6 +25,7 @@#define __AMDGPU_DISCOVERY__#include <linux/debugfs.h> +#include "discovery.h" #define DISCOVERY_TMR_SIZE (10 << 10)#define DISCOVERY_TMR_OFFSET (64 << 10)
@@ -39,6 +40,7 @@ struct amdgpu_discovery_info {uint32_t size;uint8_t *bin;bool reserve_tmr; +struct mem_reserved_info_table_v1_0 *mem_reserved_table; };void amdgpu_discovery_sysfs_fini (struct amdgpu_device *adev);
@@ -59,4 +61,6 @@ int amdgpu_discovery_sysfs_early_init(struct amdgpu_device *adev, struct pci_dev *pdev);void amdgpu_discovery_sysfs_early_fini (struct pci_dev *pdev); +int amdgpu_discovery_get_mem_reserved_info_table (struct amdgpu_device *adev); +#endif /* __AMDGPU_DISCOVERY__ */
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 5/14 drm/amdgpu: add amdgpu_discovery_get_mem_reserved_region_by_id
In reply to Alex DeucherFrom: Feifei Xu <[email protected]>
Add a lookup helper to pass a MEM_RESERVED_REGION_ID and receive the region's start address and size.
A static amdgpu_discovery_mem_reserved_region_name() helper is also introduced so debug output can refer to regions by symbolic name rather than raw IDs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 55 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 4 ++ 2 files changed, 59 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +55 -0
@@ -2391,6 +2391,23 @@ int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev,return 0 ; } +static const char *amdgpu_discovery_mem_reserved_region_name (u32 id) +{ +switch (id) { +case NO_RESERVED_REGION_ID :return "NO_RESERVED_REGION" ; +case PRE_OS_DISP_FW_REGION_ID :return "PRE_OS_DISP_FW" ; +case MASTER_DIE_UMF_REGION_ID :return "MASTER_DIE_UMF" ; +case DCC_META_DATA_REGION_ID :return "DCC_META_DATA" ; +case VM_PAGE_FAULT_REGION_ID :return "VM_PAGE_FAULT" ; +case G7_PSTATE_APERTURE1_ID :return "G7_PSTATE_APERTURE1" ; +case G7_PSTATE_APERTURE2_ID :return "G7_PSTATE_APERTURE2" ; +case G7_PSTATE_MIRROR_REGION_ID :return "G7_PSTATE_MIRROR" ; +case G7_TRAINING_DATA_REGION_ID :return "G7_TRAINING_DATA" ; +case SPECIFIC_PURPOSE_REGION_ID :return "SPECIFIC_PURPOSE" ; +default :return "UNKNOWN" ; + } +} +/* * Resolve the MEM_RESERVED_INFO table from the IP discovery binary and * cache it in adev->discovery.mem_reserved_table.
@@ -2428,6 +2445,44 @@ int amdgpu_discovery_get_mem_reserved_info_table(struct amdgpu_device *adev)return 0 ; } +/** +* Query mem_reserved_info by region ID +* +* @reserved_region_id: MEM_RESERVED_REGION_ID to look up +* @info: pass NULL to skip +*/ +int amdgpu_discovery_get_mem_reserved_region_by_id (struct amdgpu_device *adev, +u32 reserved_region_id, +struct mem_reserved_info *info) +{ +struct mem_reserved_info_table_v1_0 *table; +u32 list_num, i; + +if (!adev->discovery.mem_reserved_table) +return -ENOENT ; + + table = adev->discovery.mem_reserved_table; + list_num =min_t (u32,le32_to_cpu (table->list_num),MAX_MEM_REGION_NUM ); + +for (i =0 ; i < list_num; i++) { +if (le32_to_cpu (table->list[i].reserved_region_id) != reserved_region_id) +continue ; + +if (info) { + info->reserved_region_id = reserved_region_id; + info->reserved_region_size = +le64_to_cpu (table->list[i].reserved_region_size); + info->reserved_region_start = +le64_to_cpu (table->list[i].reserved_region_start); + } +dev_dbg (adev->dev,"Found reserved region: %s (id=%u)\n" , +amdgpu_discovery_mem_reserved_region_name (reserved_region_id), + reserved_region_id); +return 0 ; + } +return -ENOENT ; +} +static int amdgpu_discovery_set_common_ip_blocks (struct amdgpu_device *adev) {/* what IP to use for this? */
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h +4 -0
@@ -63,4 +63,8 @@ void amdgpu_discovery_sysfs_early_fini(struct pci_dev *pdev);int amdgpu_discovery_get_mem_reserved_info_table (struct amdgpu_device *adev); +int amdgpu_discovery_get_mem_reserved_region_by_id (struct amdgpu_device *adev, +u32 reserved_region_id, +struct mem_reserved_info *info); +#endif /* __AMDGPU_DISCOVERY__ */
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 6/14 drm/amdgpu: add get_fw_reserved_info implementation
In reply to Alex DeucherFrom: Feifei Xu <[email protected]>
Add asic specific callback ->get_fw_reserved_info() that returns the firmware/UMF VRAM carveout as a (size, offset_within_VRAM) pair, and provide the soc v1.0 implementation.
Query MASTER_DIE_UMF_REGION_ID from the discovery MEM_RESERVED_INFO table for the carveout size/start. SPECIFIC_PURPOSE_REGION_ID is used to resolve the VRAM base in multi-die layouts where VRAM may not start at the default base.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/soc_v1_0.c | 50 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
@@ -482,6 +482,9 @@ struct amdgpu_asic_funcs {ssize_t (*get_reg_state)(struct amdgpu_device *adev,enum amdgpu_reg_state reg_state,void *buf,size_t max_size); +/* query FW reserved region (size/offset) from discovery */ +void (*get_fw_reserved_info)(struct amdgpu_device *adev, +u64 *reserve_size,u64 *offset); };/*
drivers/gpu/drm/amd/amdgpu/soc_v1_0.c +50 -0
68 lines not on this page · raw message
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 7/14 drm/amdgpu: set reserve_tmr in amdgpu_discovery_get_tmr_info
In reply to Alex DeucherFrom: Feifei Xu <[email protected]>
If reading mmDRIVER_SCRATCH_2 returns non-zero, discovery.reserve_tmr is set to true and driver need reserve tmr for firmware.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -0
@@ -357,6 +357,7 @@ static int amdgpu_discovery_get_tmr_info(struct amdgpu_device *adev, tmr_offset_hi =RREG32 (mmDRIVER_SCRATCH_1); adev->discovery.offset = ((u64 )le32_to_cpu (tmr_offset_hi) <<32 |le32_to_cpu (tmr_offset_lo)); + adev->discovery.reserve_tmr = true; }else if (!vram_size) {/* fall back to apci approach to query tmr offset if vram_size is 0 */ ret =amdgpu_acpi_get_tmr_info (adev, &tmr_offset, &tmr_size);
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 8/14 drm/amdgpu: query the reserved info with get_fw_reserved_info
In reply to Alex DeucherFrom: Feifei Xu <[email protected]>
Extend amdgpu_ttm_init_fw_resv_region() to honour the ->get_fw_reserved_info().
Previously the FW carveout was hardcoded and placed at the top of VRAM (real_vram_size - reserve_size):
- a hard-coded 144/256 MB for GC 12.1.0;
- or DISCOVERY_TMR_OFFSET fallback.
The hard-coded GC 12.1.0 path is replaced by ->get_fw_reserved_info(), which returns a (size, offset_within_VRAM) pair derived from the MASTER_DIE_UMF_REGION embedded in IP discovery, and falls back only when the discovery region is missing or invalid.
v1->v2: Remove !adev->bios check, and call the get_fw_reserved_info
interface when it is available. (suggested by Hawking)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 26 ++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +15 -11
@@ -1737,7 +1737,7 @@ void amdgpu_ttm_init_vram_resv(struct amdgpu_device *adev,static void amdgpu_ttm_init_fw_resv_region (struct amdgpu_device *adev) { -uint32_t reserve_size =0 ; +u64 reserve_size =0 , offset =0 ;if (!adev->discovery.reserve_tmr)return ;
@@ -1749,24 +1749,28 @@ static void amdgpu_ttm_init_fw_resv_region(struct amdgpu_device *adev)* Otherwise, fallback to legacy approach to check and reserve tmr block for ip * discovery data and G6 memory training data respectively */ -if (adev->bios) +if (adev->bios) { reserve_size =amdgpu_atomfirmware_get_fw_reserved_fb_size (adev); +if (reserve_size) + offset = adev->gmc.real_vram_size - reserve_size; + }if (!adev->bios && (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,3 ) ||amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,4 ) || -amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,5 ,0 ))) - reserve_size =max (reserve_size, (uint32_t )280 <<20 ); -else if (!adev->bios && -amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (12 ,1 ,0 )) { - reserve_size =max (reserve_size, (uint32_t )150 <<20 ); - }else if (!reserve_size) +amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,5 ,0 ))) { + reserve_size = (u64 )280 <<20 ; + offset = adev->gmc.real_vram_size - reserve_size; + }else if (adev->asic_funcs && adev->asic_funcs->get_fw_reserved_info) { +dev_dbg (adev->dev,"Querying FW reserved region info through get_fw_reserved_info\n" ); + adev->asic_funcs->get_fw_reserved_info (adev, &reserve_size, &offset); + }else if (!reserve_size) { reserve_size =DISCOVERY_TMR_OFFSET ; - + offset = adev->gmc.real_vram_size - reserve_size; + }amdgpu_ttm_init_vram_resv (adev,AMDGPU_RESV_FW , - adev->gmc.real_vram_size - reserve_size, - reserve_size, false); + offset, reserve_size, false); }static void amdgpu_ttm_init_mem_train_resv_region (struct amdgpu_device *adev)
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 9/14 drm/amdgpu: add amdgpu_discovery_dump_mem_reserved_info_table
In reply to Alex DeucherFrom: Feifei Xu <[email protected]>
Walk the cached MEM_RESERVED_INFO table once at discovery init time and log every entry (region id, symbolic name, size, start). Add for debugging purpose.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +27 -3
@@ -716,6 +716,9 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev,return 0 ; } +static void amdgpu_discovery_dump_mem_reserved_info_table (struct amdgpu_device *adev, +struct mem_reserved_info_table_v1_0 *table); +static void amdgpu_discovery_log_bad_signature (struct amdgpu_device *adev,uint8_t *discovery_bin,const char *fw_name)
@@ -789,10 +792,13 @@ static int amdgpu_discovery_init(struct amdgpu_device *adev) }/* -* Resolve the MEM_RESERVED_INFO table once at init time. The table -* is optional, so missing it is not a fatal error. +* Resolve and dump the MEM_RESERVED_INFO table once at init time. +* The table is optional, so missing it is not a fatal error. */ -amdgpu_discovery_get_mem_reserved_info_table (adev); +if (!amdgpu_discovery_get_mem_reserved_info_table (adev)) +amdgpu_discovery_dump_mem_reserved_info_table (adev, + adev->discovery.mem_reserved_table); +return 0 ; out:
@@ -2409,6 +2415,24 @@ static const char *amdgpu_discovery_mem_reserved_region_name(u32 id) } } +/* Dump all the mem_reserved_info table entries for debugging */ +static void amdgpu_discovery_dump_mem_reserved_info_table (struct amdgpu_device *adev, +struct mem_reserved_info_table_v1_0 *table) +{ +u32 list_num =min_t (u32,le32_to_cpu (table->list_num),MAX_MEM_REGION_NUM ); +u32 id, i; + +dev_info (adev->dev,"MEM_RESERVED_INFO: list_num=%u\n" , list_num); +for (i =0 ; i < list_num; i++) { + id =le32_to_cpu (table->list[i].reserved_region_id); +dev_info (adev->dev," [%u] id=%u (%s) size=0x%llx start=0x%llx\n" , + i, id, +amdgpu_discovery_mem_reserved_region_name (id), +le64_to_cpu (table->list[i].reserved_region_size), +le64_to_cpu (table->list[i].reserved_region_start)); + } +} +/* * Resolve the MEM_RESERVED_INFO table from the IP discovery binary and * cache it in adev->discovery.mem_reserved_table.
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 10/14 drm/amdgpu: add mem_reserved_info sysfs attribute
In reply to Alex DeucherFrom: Feifei Xu <[email protected]>
Expose the cached MEM_RESERVED_INFO discovery table via a per-device sysfs file:
/sys/class/drm/cardX/device/mem_reserved_info
The file is read-only and dumps every region as:
list_num=<N>
[<i>] id=<id> (<name>) size=0x<size> start=0x<start>Only created when the table was successfully resolved at discovery init time.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 56 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 3 + 3 files changed, 64 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
@@ -247,6 +247,9 @@ static int amdgpu_device_attr_sysfs_init(struct amdgpu_device *adev) ret =sysfs_create_file (&adev->dev->kobj, &dev_attr_pcie_replay_count.attr); +if (!ret) + ret =amdgpu_discovery_mem_reserved_info_sysfs_init (adev); +return ret; }
@@ -255,6 +258,8 @@ static void amdgpu_device_attr_sysfs_fini(struct amdgpu_device *adev)if (amdgpu_nbio_is_replay_cnt_supported (adev))sysfs_remove_file (&adev->dev->kobj, &dev_attr_pcie_replay_count.attr); + +amdgpu_discovery_mem_reserved_info_sysfs_fini (adev); } static ssize_t amdgpu_sysfs_reg_state_get(struct file *f, struct kobject *kobj,
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +56 -0
62 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h +3 -0
@@ -67,4 +67,7 @@ int amdgpu_discovery_get_mem_reserved_region_by_id(struct amdgpu_device *adev,u32 reserved_region_id, struct mem_reserved_info *info); +int amdgpu_discovery_mem_reserved_info_sysfs_init (struct amdgpu_device *adev); +void amdgpu_discovery_mem_reserved_info_sysfs_fini (struct amdgpu_device *adev); +#endif /* __AMDGPU_DISCOVERY__ */
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 11/14 drm/amdgpu/discovery: skip MEM_RESERVED_INFO on unsupported ASICs
In reply to Alex DeucherFrom: Feifei Xu <[email protected]>
Some ASICs' MEM_RESERVED_INFO table_entry may carry non-zero garbage, causing signature check failed thus probe fail.
Move signature check in amdgpu_discovery_get_mem_reserved_info_table(), returning -ENOENT when invalid so the table is skipped.
v1->v2: Add discovery binary header check before populate the
mem_reserved_info table. (Lijo)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +26 -9
@@ -685,15 +685,11 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev, check_table = false;break ; } -case MEM_RESERVED_INFO : { -struct mem_reserved_info_header *mrhdr = - (struct mem_reserved_info_header *)(discovery_bin + offset); - act_val =le32_to_cpu (mrhdr->signature); - exp_val =MEM_RSV_TABLE_SIGNATURE ; - table_size =le32_to_cpu (mrhdr->size); +case MEM_RESERVED_INFO : +/* Optional table; signature is validated in get_mem_reserved_info_table(). */ table_name ="mem_reserved table" ; + check_table = false;break ; - }default :dev_err (adev->dev,"invalid ip discovery table id %d specified\n" , table_id); check_table = false;
@@ -2497,7 +2493,10 @@ void amdgpu_discovery_mem_reserved_info_sysfs_fini(struct amdgpu_device *adev)int amdgpu_discovery_get_mem_reserved_info_table (struct amdgpu_device *adev) {uint8_t *discovery_bin = adev->discovery.bin; +struct mem_reserved_info_header *mrhdr; +struct binary_header *bhdr;struct table_info *info; +u16 offset;/* If already queried, do not query again. */ if (adev->discovery.mem_reserved_table)
@@ -2508,19 +2507,37 @@ int amdgpu_discovery_get_mem_reserved_info_table(struct amdgpu_device *adev)return -ENOENT ; } +/* MEM_RESERVED_INFO only exists in binary_header >= v2. Skip populating it on v1 */ + bhdr = (struct binary_header *)discovery_bin; +if (le16_to_cpu (bhdr->version_major) <2 ) { +dev_dbg (adev->dev,"header version = %d\n" ,le16_to_cpu (bhdr->version_major)); +return -ENOENT ; + } +if (amdgpu_discovery_get_table_info (adev, &info,MEM_RESERVED_INFO )) {dev_dbg (adev->dev,"MEM_RESERVED_INFO table entry not present\n" );return -EINVAL ; } -if (!le16_to_cpu (info->offset)) { + offset =le16_to_cpu (info->offset); +if (!offset) {dev_dbg (adev->dev,"MEM_RESERVED_INFO table offset is 0, invalid!\n" );return -EINVAL ; } +/* +* Only populated when the signature matches; skip ASICs whose +* slot points to unrelated data. +*/ + mrhdr = (struct mem_reserved_info_header *)(discovery_bin + offset); +if (le32_to_cpu (mrhdr->signature) !=MEM_RSV_TABLE_SIGNATURE ) { +dev_dbg (adev->dev,"MEM_RESERVED_INFO table signature mismatch, skipping\n" ); +return -ENOENT ; + } +/* Cache for subsequent lookups. */ adev->discovery.mem_reserved_table = - (struct mem_reserved_info_table_v1_0 *)(discovery_bin +le16_to_cpu (info->offset)); + (struct mem_reserved_info_table_v1_0 *)mrhdr;dev_dbg (adev->dev,"MEM_RESERVED_INFO table exist\n" );return 0 ;
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 12/14 drm/amdgpu: handle MMHUB harvest information from ip discovery
In reply to Alex DeucherFrom: Le Ma <[email protected]>
Clear harvested MMHUB instances from mmhub.inst_mask when processing the harvest table. Report the harvest state through IP discovery sysfs for MMHUB v4.2.0.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +6 -0
@@ -961,6 +961,9 @@ static void amdgpu_discovery_read_from_harvest_table(struct amdgpu_device *adev,case SDMA0_HWID : adev->sdma.sdma_mask &= ~BIT (inst);break ; +case MMHUB_HWID : + adev->mmhub.inst_mask &= ~BIT (inst); +break ;#if defined(CONFIG_DRM_AMD_ISP )case ISP_HWID : adev->isp.harvest_config |= ~BIT (inst);
@@ -1251,6 +1254,9 @@ static uint8_t amdgpu_discovery_get_harvest_info(struct amdgpu_device *adev,case SDMA0_HWID : harvest = ((1 << inst) & adev->sdma.sdma_mask) ==0 ;break ; +case MMHUB_HWID : + harvest = (BIT (inst) & adev->mmhub.inst_mask) ==0 ; +break ;default :break ; }
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 13/14 drm/amdgpu: handle LSDMA instance and harvest information from ip discovery
In reply to Alex DeucherFrom: Le Ma <[email protected]>
Track discovered LSDMA instances in inst_mask and clear harvested instances when processing the harvest table. Report the harvest state through IP discovery sysfs for LSDMA v7.1.0.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 16 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h | 3 +++ 2 files changed, 19 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +16 -0
@@ -964,6 +964,9 @@ static void amdgpu_discovery_read_from_harvest_table(struct amdgpu_device *adev,case MMHUB_HWID : adev->mmhub.inst_mask &= ~BIT (inst);break ; +case LSDMA_HWID : + adev->lsdma.inst_mask &= ~BIT (inst); +break ;#if defined(CONFIG_DRM_AMD_ISP )case ISP_HWID : adev->isp.harvest_config |= ~BIT (inst);
@@ -1257,6 +1260,9 @@ static uint8_t amdgpu_discovery_get_harvest_info(struct amdgpu_device *adev,case MMHUB_HWID : harvest = (BIT (inst) & adev->mmhub.inst_mask) ==0 ;break ; +case LSDMA_HWID : + harvest = (BIT (inst) & adev->lsdma.inst_mask) ==0 ; +break ;default :break ; }
@@ -1802,6 +1808,7 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev) adev->vcn.inst_mask =0 ; adev->jpeg.inst_mask =0 ; adev->mmhub.inst_mask =0 ; + adev->lsdma.inst_mask =0 ; r =amdgpu_discovery_get_table_info (adev, &info,IP_DISCOVERY );if (r)return r;
@@ -1877,6 +1884,15 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev) AMDGPU_MAX_MMHUB_INSTANCES); } +if (le16_to_cpu (ip->hw_id) ==LSDMA_HWID ) { +if (inst <AMDGPU_MAX_LSDMA_INSTANCES ) + adev->lsdma.inst_mask |=BIT (inst); +else +dev_err (adev->dev,"Too many LSDMA instances: %d vs %d\n" , + inst +1 , +AMDGPU_MAX_LSDMA_INSTANCES ); + } + if (le16_to_cpu(ip->hw_id) == SDMA0_HWID || le16_to_cpu(ip->hw_id) == SDMA1_HWID || le16_to_cpu(ip->hw_id) == SDMA2_HWID ||
drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h +3 -0
@@ -24,9 +24,12 @@#ifndef __AMDGPU_LSDMA_H__#define __AMDGPU_LSDMA_H__ +#define AMDGPU_MAX_LSDMA_INSTANCES 2 +struct amdgpu_lsdma {struct mutex lock;const struct amdgpu_lsdma_funcs *funcs; +uint32_t inst_mask; }; struct amdgpu_lsdma_funcs {
Signature · 1 line
2.55.0
Alex Deucher
maintainerPATCH 14/14 drm/amdgpu: Init soc_v1_0 rev_id from IP discovery die_id
In reply to Alex DeucherFrom: Horatio Zhang <[email protected]>
Software components need to detect die revisions in order to apply the correct software workarounds. During system boot, ASP firmware reads the IDCODE values from the MID, AID and XCD fuses and encodes the die revision into die_info[0].die_id in the IP discovery blob.
v2: Default die_rev_id to 0 and warn instead of failing probe when IP discovery does not provide a die rev id.
v3: Update names for external_rev_id enumerators.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 24 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 2 + drivers/gpu/drm/amd/amdgpu/soc_v1_0.c | 74 ++++++++++++++++++- 3 files changed, 97 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +24 -0
@@ -4038,3 +4038,27 @@ int amdgpu_discovery_get_gc_major_minor_version(struct amdgpu_device *adev, *minor =le16_to_cpu (gc_info->v1.header.version_minor);return 0 ; } + +int amdgpu_discovery_get_die_rev_id (struct amdgpu_device *adev, +uint16_t *die_rev_id) +{ +uint8_t *discovery_bin = adev->discovery.bin; +struct ip_discovery_header *ihdr; +struct table_info *info; +u16 offset; + +if (!discovery_bin) +return -EINVAL ; +if (amdgpu_discovery_get_table_info (adev, &info,IP_DISCOVERY )) +return -EINVAL ; + + offset =le16_to_cpu (info->offset); +if (!offset) +return -EINVAL ; + + ihdr = (struct ip_discovery_header *)(discovery_bin + offset); + +if (die_rev_id) + *die_rev_id =le16_to_cpu (ihdr->die_info[0 ].die_id); +return 0 ; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h +2 -0
@@ -53,6 +53,8 @@ int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev, int *range_cnt, bool refresh);int amdgpu_discovery_get_gc_major_minor_version (struct amdgpu_device *adev,uint16_t *major,uint16_t *minor); +int amdgpu_discovery_get_die_rev_id (struct amdgpu_device *adev, +uint16_t *die_rev_id);void amdgpu_discovery_dump (struct amdgpu_device *adev,struct drm_printer *p);
drivers/gpu/drm/amd/amdgpu/soc_v1_0.c +71 -3
100 lines not on this page · raw message
Signature · 1 line
2.55.0