Refactor ip mapping, compute and memory partition callbacks
Subsystems (2)
cover Refactor ip mapping, compute and memory partition callbacks
Convert IP mapping, compute, and memory partition-related callbacks into common helper functions to enable sharing across multiple products
Hawking Zhang (8):
drm/amdgpu: Convert select_sched into a common helper v3 drm/amdgpu: Convert update_partition_sched_list into a common helper
v3
drm/amdgpu: Convert update_supported_modes into a common helper drm/amdgpu: Convert pre|post_partition_switch into common helpers drm/amdgpu: Move MAX_MEM_RANGES to amdgpu_gmc.h drm/amdgpu: Convert query_memory_partition into common helpers drm/amdgpu: Generalize is_multi_chiplet with a common helper v2 drm/amdgpu: Convert init_mem_ranges into common helpers
Likun Gao (2):
drm/amdgpu: make ip map init to common function drm/amdgpu: use common function to map ip for aqua_vanjaram
drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 5 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 228 +++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 12 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 96 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h | 29 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 213 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h | 25 +- drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 308 +-------------------- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 255 +---------------- drivers/gpu/drm/amd/amdgpu/soc15.h | 1 - 12 files changed, 614 insertions(+), 563 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h
Signature · 1 line
2.17.1
PATCH 1/10 drm/amdgpu: make ip map init to common function
From: Likun Gao <[email protected]>
IP instance map init function can be an common function instead of operation on different ASIC.
V2: Create amdgpu_ip.[ch] file for ip related functions.
--- drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 96 ++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h | 29 ++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h
drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
@@ -66,7 +66,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \ amdgpu_fw_attestation.o amdgpu_securedisplay.o \ amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \ amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_dev_coredump.o \ - amdgpu_cper.o amdgpu_userq_fence.o amdgpu_eviction_fence.o + amdgpu_cper.o amdgpu_userq_fence.o amdgpu_eviction_fence.o amdgpu_ip.o amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c new file +96 -0
96 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright 2025 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +*/ + +#ifndef __AMDGPU_IP_H__ +#define __AMDGPU_IP_H__ + +void amdgpu_ip_map_init (struct amdgpu_device *adev); + +#endif /* __AMDGPU_IP_H__ */
Signature · 1 line
2.17.1
PATCH 2/10 drm/amdgpu: use common function to map ip for aqua_vanjaram
In reply to Hawking ZhangFrom: Likun Gao <[email protected]>
Transfer to use function amdgpu_ip_map_init to map ip instance for aqua_vanjaram instead of operation on different ASIC.
--- drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 74 +--------------------- drivers/gpu/drm/amd/amdgpu/soc15.h | 1 - 2 files changed, 2 insertions(+), 73 deletions(-)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +2 -72
@@ -29,6 +29,7 @@#include "gfx_v9_4_3.h" #include "gfxhub_v1_2.h" #include "sdma_v4_4_2.h" +#include "amdgpu_ip.h" #define XCP_INST_MASK (num_inst, xcp_id) \ (num_inst ? GENMASK(num_inst - 1, 0) << (xcp_id * num_inst) : 0)
@@ -219,77 +220,6 @@ static int aqua_vanjaram_select_scheds(return 0 ; } -static int8_t aqua_vanjaram_logical_to_dev_inst (struct amdgpu_device *adev, -enum amd_hw_ip_block_type block, -int8_t inst) -{ -int8_t dev_inst; - -switch (block) { -case GC_HWIP : -case SDMA0_HWIP : -/* Both JPEG and VCN as JPEG is only alias of VCN */ -case VCN_HWIP : - dev_inst = adev->ip_map.dev_inst[block][inst]; -break ; -default : -/* For rest of the IPs, no look up required. -* Assume 'logical instance == physical instance' for all configs. */ - dev_inst = inst; -break ; - } - -return dev_inst; -} - -static uint32_t aqua_vanjaram_logical_to_dev_mask (struct amdgpu_device *adev, -enum amd_hw_ip_block_type block, -uint32_t mask) -{ -uint32_t dev_mask =0 ; -int8_t log_inst, dev_inst; - -while (mask) { - log_inst =ffs (mask) -1 ; - dev_inst =aqua_vanjaram_logical_to_dev_inst (adev, block, log_inst); - dev_mask |= (1 << dev_inst); - mask &= ~(1 << log_inst); - } - -return dev_mask; -} - -static void aqua_vanjaram_populate_ip_map (struct amdgpu_device *adev, -enum amd_hw_ip_block_type ip_block, -uint32_t inst_mask) -{ -int l =0 , i; - -while (inst_mask) { - i =ffs (inst_mask) -1 ; - adev->ip_map.dev_inst[ip_block][l++] = i; - inst_mask &= ~(1 << i); - } -for (; l <HWIP_MAX_INSTANCE ; l++) - adev->ip_map.dev_inst[ip_block][l] =-1 ; -} - -void aqua_vanjaram_ip_map_init (struct amdgpu_device *adev) -{ -u32 ip_map[][2 ] = { - {GC_HWIP , adev->gfx.xcc_mask }, - {SDMA0_HWIP , adev->sdma.sdma_mask }, - {VCN_HWIP , adev->vcn.inst_mask }, - }; -int i; - -for (i =0 ; i <ARRAY_SIZE (ip_map); ++i) -aqua_vanjaram_populate_ip_map (adev, ip_map[i][0 ], ip_map[i][1 ]); - - adev->ip_map.logical_to_dev_inst = aqua_vanjaram_logical_to_dev_inst; - adev->ip_map.logical_to_dev_mask = aqua_vanjaram_logical_to_dev_mask; -} -/* Fixed pattern for smn addressing on different AIDs: * bit[34]: indicate cross AID access * bit[33:32]: indicate target AID id
@@ -858,7 +788,7 @@ int aqua_vanjaram_init_soc_config(struct amdgpu_device *adev)if (ret)return ret; -aqua_vanjaram_ip_map_init (adev); +amdgpu_ip_map_init (adev);return 0 ; }
drivers/gpu/drm/amd/amdgpu/soc15.h +0 -1
@@ -118,7 +118,6 @@ int vega10_reg_base_init(struct amdgpu_device *adev);int vega20_reg_base_init (struct amdgpu_device *adev);int arct_reg_base_init (struct amdgpu_device *adev);int aldebaran_reg_base_init (struct amdgpu_device *adev); -void aqua_vanjaram_ip_map_init (struct amdgpu_device *adev);u64 aqua_vanjaram_encode_ext_smn_addressing (int ext_id);int aqua_vanjaram_init_soc_config (struct amdgpu_device *adev); ssize_t aqua_vanjaram_get_reg_state(struct amdgpu_device *adev,
Signature · 1 line
2.17.1
PATCH 3/10 drm/amdgpu: Convert select_sched into a common helper v3
In reply to Hawking ZhangThe xcp select_sched function does not need to remain as a soc specific callback. It can be reused for future products
v2: bypass the function if xcp_mgr is not available (Likun)
v3: Let caller check the availability of xcp mgr (Lijo)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 38 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h | 13 +++---- drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 41 ---------------------- 3 files changed, 43 insertions(+), 49 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +38 -0
@@ -445,6 +445,44 @@ void amdgpu_xcp_release_sched(struct amdgpu_device *adev, } } +int amdgpu_xcp_select_scheds (struct amdgpu_device *adev, +u32 hw_ip,u32 hw_prio, +struct amdgpu_fpriv *fpriv, +unsigned int *num_scheds, +struct drm_gpu_scheduler ***scheds) +{ +u32 sel_xcp_id; +int i; + +if (fpriv->xcp_id ==AMDGPU_XCP_NO_PARTITION ) { +u32 least_ref_cnt = ~0 ; + + fpriv->xcp_id =0 ; +for (i =0 ; i < adev->xcp_mgr->num_xcps; i++) { +u32 total_ref_cnt; + + total_ref_cnt =atomic_read (&adev->xcp_mgr->xcp[i].ref_cnt); +if (total_ref_cnt < least_ref_cnt) { + fpriv->xcp_id = i; + least_ref_cnt = total_ref_cnt; + } + } + } + sel_xcp_id = fpriv->xcp_id; + +if (adev->xcp_mgr->xcp[sel_xcp_id].gpu_sched[hw_ip][hw_prio].num_scheds) { + *num_scheds = adev->xcp_mgr->xcp[fpriv->xcp_id].gpu_sched[hw_ip][hw_prio].num_scheds; + *scheds = adev->xcp_mgr->xcp[fpriv->xcp_id].gpu_sched[hw_ip][hw_prio].sched; +atomic_inc (&adev->xcp_mgr->xcp[sel_xcp_id].ref_cnt); +dev_dbg (adev->dev,"Selected partition #%d" , sel_xcp_id); + }else { +dev_err (adev->dev,"Failed to schedule partition #%d." , sel_xcp_id); +return -ENOENT ; + } + +return 0 ; +} +/*====================== xcp sysfs - configuration ======================*/ #define XCP_CFG_SYSFS_RES_ATTR_SHOW (_name) \ static ssize_t amdgpu_xcp_res_sysfs_##_name##_show( \
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h +5 -8
@@ -144,9 +144,6 @@ struct amdgpu_xcp_mgr_funcs {int (*suspend)(struct amdgpu_xcp_mgr *xcp_mgr,int xcp_id);int (*prepare_resume)(struct amdgpu_xcp_mgr *xcp_mgr,int xcp_id);int (*resume)(struct amdgpu_xcp_mgr *xcp_mgr,int xcp_id); -int (*select_scheds)(struct amdgpu_device *adev, -u32 hw_ip,u32 hw_prio,struct amdgpu_fpriv *fpriv, -unsigned int *num_scheds,struct drm_gpu_scheduler ***scheds);int (*update_partition_sched_list)(struct amdgpu_device *adev); };
@@ -176,14 +173,14 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev, struct drm_file *file_priv);void amdgpu_xcp_release_sched (struct amdgpu_device *adev,struct amdgpu_ctx_entity *entity); - +int amdgpu_xcp_select_scheds (struct amdgpu_device *adev, +u32 hw_ip,u32 hw_prio, +struct amdgpu_fpriv *fpriv, +unsigned int *num_scheds, +struct drm_gpu_scheduler ***scheds);void amdgpu_xcp_sysfs_init (struct amdgpu_device *adev);void amdgpu_xcp_sysfs_fini (struct amdgpu_device *adev); -#define amdgpu_xcp_select_scheds (adev, e, c, d, x, y) \ - ((adev)->xcp_mgr && (adev)->xcp_mgr->funcs && \ - (adev)->xcp_mgr->funcs->select_scheds ? \ - (adev)->xcp_mgr->funcs->select_scheds((adev), (e), (c), (d), (x), (y)) : -ENOENT)#define amdgpu_xcp_update_partition_sched_list (adev) \ ((adev)->xcp_mgr && (adev)->xcp_mgr->funcs && \ (adev)->xcp_mgr->funcs->update_partition_sched_list ? \
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +0 -41
53 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 4/10 drm/amdgpu: Convert update_partition_sched_list into a common helper v3
In reply to Hawking ZhangThe update_partition_sched_list function does not need to remain as a soc specific callback. It can be reused for future products.
v2: bypass the function if xcp_mgr is not available (Likun)
v3: Let caller check the availability of xcp_mgr (Lijo)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 111 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h | 7 +- drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 119 --------------------- 4 files changed, 114 insertions(+), 126 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -1
@@ -3012,7 +3012,8 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev) } } -amdgpu_xcp_update_partition_sched_list (adev); +if (adev->xcp_mgr) +amdgpu_xcp_update_partition_sched_list (adev);return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +111 -0
117 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h +1 -6
@@ -144,7 +144,6 @@ struct amdgpu_xcp_mgr_funcs {int (*suspend)(struct amdgpu_xcp_mgr *xcp_mgr,int xcp_id);int (*prepare_resume)(struct amdgpu_xcp_mgr *xcp_mgr,int xcp_id);int (*resume)(struct amdgpu_xcp_mgr *xcp_mgr,int xcp_id); -int (*update_partition_sched_list)(struct amdgpu_device *adev); };int amdgpu_xcp_prepare_suspend (struct amdgpu_xcp_mgr *xcp_mgr,int xcp_id);
@@ -178,14 +177,10 @@ int amdgpu_xcp_select_scheds(struct amdgpu_device *adev,struct amdgpu_fpriv *fpriv, unsigned int *num_scheds, struct drm_gpu_scheduler ***scheds); +int amdgpu_xcp_update_partition_sched_list (struct amdgpu_device *adev);void amdgpu_xcp_sysfs_init (struct amdgpu_device *adev);void amdgpu_xcp_sysfs_fini (struct amdgpu_device *adev); -#define amdgpu_xcp_update_partition_sched_list (adev) \ - ((adev)->xcp_mgr && (adev)->xcp_mgr->funcs && \ - (adev)->xcp_mgr->funcs->update_partition_sched_list ? \ - (adev)->xcp_mgr->funcs->update_partition_sched_list(adev) : 0) -static inline int amdgpu_xcp_get_num_xcp (struct amdgpu_xcp_mgr *xcp_mgr) {if (!xcp_mgr)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +0 -119
131 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 5/10 drm/amdgpu: Convert update_supported_modes into a common helper
In reply to Hawking ZhangSo it can be used for future products
--- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 37 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h | 1 + drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 41 +--------------------- 3 files changed, 39 insertions(+), 40 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +37 -0
@@ -594,6 +594,43 @@ int amdgpu_xcp_update_partition_sched_list(struct amdgpu_device *adev)return amdgpu_xcp_sched_list_update (adev); } +void amdgpu_xcp_update_supported_modes (struct amdgpu_xcp_mgr *xcp_mgr) +{ +struct amdgpu_device *adev = xcp_mgr->adev; + + xcp_mgr->supp_xcp_modes =0 ; + +switch (NUM_XCC (adev->gfx.xcc_mask)) { +case 8 : + xcp_mgr->supp_xcp_modes =BIT (AMDGPU_SPX_PARTITION_MODE ) | +BIT (AMDGPU_DPX_PARTITION_MODE ) | +BIT (AMDGPU_QPX_PARTITION_MODE ) | +BIT (AMDGPU_CPX_PARTITION_MODE ); +break ; +case 6 : + xcp_mgr->supp_xcp_modes =BIT (AMDGPU_SPX_PARTITION_MODE ) | +BIT (AMDGPU_TPX_PARTITION_MODE ) | +BIT (AMDGPU_CPX_PARTITION_MODE ); +break ; +case 4 : + xcp_mgr->supp_xcp_modes =BIT (AMDGPU_SPX_PARTITION_MODE ) | +BIT (AMDGPU_DPX_PARTITION_MODE ) | +BIT (AMDGPU_CPX_PARTITION_MODE ); +break ; +case 2 : + xcp_mgr->supp_xcp_modes =BIT (AMDGPU_SPX_PARTITION_MODE ) | +BIT (AMDGPU_CPX_PARTITION_MODE ); +break ; +case 1 : + xcp_mgr->supp_xcp_modes =BIT (AMDGPU_SPX_PARTITION_MODE ) | +BIT (AMDGPU_CPX_PARTITION_MODE ); +break ; + +default : +break ; + } +} +/*====================== xcp sysfs - configuration ======================*/ #define XCP_CFG_SYSFS_RES_ATTR_SHOW (_name) \ static ssize_t amdgpu_xcp_res_sysfs_##_name##_show( \
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h +1 -0
@@ -177,6 +177,7 @@ int amdgpu_xcp_select_scheds(struct amdgpu_device *adev,struct amdgpu_fpriv *fpriv, unsigned int *num_scheds, struct drm_gpu_scheduler ***scheds); +void amdgpu_xcp_update_supported_modes (struct amdgpu_xcp_mgr *xcp_mgr);int amdgpu_xcp_update_partition_sched_list (struct amdgpu_device *adev);void amdgpu_xcp_sysfs_init (struct amdgpu_device *adev);void amdgpu_xcp_sysfs_fini (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +1 -40
53 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 6/10 drm/amdgpu: Convert pre|post_partition_switch into common helpers
In reply to Hawking ZhangSo they can be reused for future products
--- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 27 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h | 4 +++ drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 33 ++-------------------- 3 files changed, 33 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +27 -0
@@ -631,6 +631,33 @@ void amdgpu_xcp_update_supported_modes(struct amdgpu_xcp_mgr *xcp_mgr) } } +int amdgpu_xcp_pre_partition_switch (struct amdgpu_xcp_mgr *xcp_mgr,u32 flags) +{ +/* TODO: +* Stop user queues and threads, and make sure GPU is empty of work. +*/ + +if (flags &AMDGPU_XCP_OPS_KFD ) +amdgpu_amdkfd_device_fini_sw (xcp_mgr->adev); + +return 0 ; +} + +int amdgpu_xcp_post_partition_switch (struct amdgpu_xcp_mgr *xcp_mgr,u32 flags) +{ +int ret =0 ; + +if (flags &AMDGPU_XCP_OPS_KFD ) { +amdgpu_amdkfd_device_probe (xcp_mgr->adev); +amdgpu_amdkfd_device_init (xcp_mgr->adev); +/* If KFD init failed, return failure */ +if (!xcp_mgr->adev->kfd.init_complete) + ret = -EIO ; + } + +return ret; +} +/*====================== xcp sysfs - configuration ======================*/ #define XCP_CFG_SYSFS_RES_ATTR_SHOW (_name) \ static ssize_t amdgpu_xcp_res_sysfs_##_name##_show( \
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h +4 -0
@@ -39,6 +39,8 @@#define AMDGPU_XCP_NO_PARTITION (~0) +#define AMDGPU_XCP_OPS_KFD (1 << 0) +struct amdgpu_fpriv ;enum AMDGPU_XCP_IP_BLOCK {
@@ -179,6 +181,8 @@ int amdgpu_xcp_select_scheds(struct amdgpu_device *adev, struct drm_gpu_scheduler ***scheds);void amdgpu_xcp_update_supported_modes (struct amdgpu_xcp_mgr *xcp_mgr);int amdgpu_xcp_update_partition_sched_list (struct amdgpu_device *adev); +int amdgpu_xcp_pre_partition_switch (struct amdgpu_xcp_mgr *xcp_mgr,u32 flags); +int amdgpu_xcp_post_partition_switch (struct amdgpu_xcp_mgr *xcp_mgr,u32 flags);void amdgpu_xcp_sysfs_init (struct amdgpu_device *adev);void amdgpu_xcp_sysfs_fini (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +2 -31
@@ -34,8 +34,6 @@#define XCP_INST_MASK (num_inst, xcp_id) \ (num_inst ? GENMASK(num_inst - 1, 0) << (xcp_id * num_inst) : 0) -#define AMDGPU_XCP_OPS_KFD (1 << 0) -void aqua_vanjaram_doorbell_index_init (struct amdgpu_device *adev) {int i;
@@ -366,33 +364,6 @@ static bool __aqua_vanjaram_is_valid_mode(struct amdgpu_xcp_mgr *xcp_mgr,return false; } -static int __aqua_vanjaram_pre_partition_switch (struct amdgpu_xcp_mgr *xcp_mgr,u32 flags) -{ -/* TODO: -* Stop user queues and threads, and make sure GPU is empty of work. -*/ - -if (flags &AMDGPU_XCP_OPS_KFD ) -amdgpu_amdkfd_device_fini_sw (xcp_mgr->adev); - -return 0 ; -} - -static int __aqua_vanjaram_post_partition_switch (struct amdgpu_xcp_mgr *xcp_mgr,u32 flags) -{ -int ret =0 ; - -if (flags &AMDGPU_XCP_OPS_KFD ) { -amdgpu_amdkfd_device_probe (xcp_mgr->adev); -amdgpu_amdkfd_device_init (xcp_mgr->adev); -/* If KFD init failed, return failure */ -if (!xcp_mgr->adev->kfd.init_complete) - ret = -EIO ; - } - -return ret; -} -static void __aqua_vanjaram_update_available_partition_mode (struct amdgpu_xcp_mgr *xcp_mgr) {int mode;
@@ -439,7 +410,7 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, goto out; } - ret =__aqua_vanjaram_pre_partition_switch (xcp_mgr, flags); + ret =amdgpu_xcp_pre_partition_switch (xcp_mgr, flags);if (ret) goto unlock;
@@ -452,7 +423,7 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, *num_xcps = num_xcc / num_xcc_per_xcp;amdgpu_xcp_init (xcp_mgr, *num_xcps, mode); - ret =__aqua_vanjaram_post_partition_switch (xcp_mgr, flags); + ret =amdgpu_xcp_post_partition_switch (xcp_mgr, flags);if (!ret)__aqua_vanjaram_update_available_partition_mode (xcp_mgr); unlock:
Signature · 1 line
2.17.1
PATCH 7/10 drm/amdgpu: Move MAX_MEM_RANGES to amdgpu_gmc.h
In reply to Hawking ZhangThis relocation allows MAX_MEM_RANGES to be shared across multiple products
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 2 ++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +2 -0
@@ -84,6 +84,8 @@ enum amdgpu_memory_partition {#define AMDGPU_GMC_INIT_RESET_NPS BIT(0) +#define AMDGPU_MAX_MEM_RANGES 8 +/* * GMC page fault information */
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -4
@@ -78,8 +78,6 @@#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_DCN2 0x05ea#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_DCN2_BASE_IDX 2 -#define MAX_MEM_RANGES 8 -static const char *const gfxhub_client_ids[] = {"CB" ,"DB" ,
@@ -1934,7 +1932,7 @@ gmc_v9_0_init_acpi_mem_ranges(struct amdgpu_device *adev, struct amdgpu_mem_partition_info *mem_ranges) {struct amdgpu_numa_info numa_info; -int node_ids[MAX_MEM_RANGES ]; +int node_ids[AMDGPU_MAX_MEM_RANGES ];int num_ranges =0 , ret;int num_xcc, xcc_id;uint32_t xcc_mask;
@@ -2042,7 +2040,7 @@ static int gmc_v9_0_init_mem_ranges(struct amdgpu_device *adev) {bool valid; - adev->gmc.mem_partitions =kcalloc (MAX_MEM_RANGES , + adev->gmc.mem_partitions =kcalloc (AMDGPU_MAX_MEM_RANGES ,sizeof (struct amdgpu_mem_partition_info ),GFP_KERNEL );if (!adev->gmc.mem_partitions)
Signature · 1 line
2.17.1
PATCH 8/10 drm/amdgpu: Convert query_memory_partition into common helpers
In reply to Hawking ZhangThe query_memory_partition does not need to remain as soc specific callbacks. They can be shared across multiple products
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 43 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 7 +++- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 48 +++---------------------- 3 files changed, 53 insertions(+), 45 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +43 -0
@@ -1448,3 +1448,46 @@ bool amdgpu_gmc_need_reset_on_init(struct amdgpu_device *adev)return false; } + +enum amdgpu_memory_partition +amdgpu_gmc_get_vf_memory_partition (struct amdgpu_device *adev) +{ +switch (adev->gmc.num_mem_partitions) { +case 0 : +return UNKNOWN_MEMORY_PARTITION_MODE ; +case 1 : +return AMDGPU_NPS1_PARTITION_MODE ; +case 2 : +return AMDGPU_NPS2_PARTITION_MODE ; +case 4 : +return AMDGPU_NPS4_PARTITION_MODE ; +case 8 : +return AMDGPU_NPS8_PARTITION_MODE ; +default : +return AMDGPU_NPS1_PARTITION_MODE ; + } +} + +enum amdgpu_memory_partition +amdgpu_gmc_get_memory_partition (struct amdgpu_device *adev,u32 *supp_modes) +{ +enum amdgpu_memory_partition mode =UNKNOWN_MEMORY_PARTITION_MODE ; + +if (adev->nbio.funcs && + adev->nbio.funcs->get_memory_partition_mode) + mode = adev->nbio.funcs->get_memory_partition_mode (adev, + supp_modes); +else +dev_warn (adev->dev,"memory partition mode query is not supported\n" ); + +return mode; +} + +enum amdgpu_memory_partition +amdgpu_gmc_query_memory_partition (struct amdgpu_device *adev) +{ +if (amdgpu_sriov_vf (adev)) +return amdgpu_gmc_get_vf_memory_partition (adev); +else +return amdgpu_gmc_get_memory_partition (adev,NULL ); +}
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +6 -1
@@ -458,5 +458,10 @@ int amdgpu_gmc_request_memory_partition(struct amdgpu_device *adev, int nps_mode);void amdgpu_gmc_prepare_nps_mode_change (struct amdgpu_device *adev);bool amdgpu_gmc_need_reset_on_init (struct amdgpu_device *adev); - +enum amdgpu_memory_partition +amdgpu_gmc_get_vf_memory_partition (struct amdgpu_device *adev); +enum amdgpu_memory_partition +amdgpu_gmc_get_memory_partition (struct amdgpu_device *adev,u32 *supp_modes); +enum amdgpu_memory_partition +amdgpu_gmc_query_memory_partition (struct amdgpu_device *adev);#endif
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -44
78 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 9/10 drm/amdgpu: Generalize is_multi_chiplet with a common helper v2
In reply to Hawking ZhangIt is not necessary to be ip generation specific
v2: rename the helper to is_multi_aid (Lijo)
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 5 +++++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 23 +++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +5 -0
@@ -1337,6 +1337,11 @@ static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_device *bdev) return container_of(bdev, struct amdgpu_device, mman.bdev); } +static inline bool amdgpu_is_multi_aid (struct amdgpu_device *adev) +{ +return !!adev->aid_mask; +} +int amdgpu_device_init (struct amdgpu_device *adev,uint32_t flags);void amdgpu_device_fini_hw (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +9 -14
@@ -409,11 +409,6 @@ static const uint32_t ecc_umc_mcumc_ctrl_mask_addrs[] = { (0x001d43e0 + 0x00001800), }; -static inline bool gmc_v9_0_is_multi_chiplet (struct amdgpu_device *adev) -{ -return !!adev->aid_mask; -} - static int gmc_v9_0_ecc_interrupt_state(struct amdgpu_device *adev, struct amdgpu_irq_src *src, unsigned int type,
@@ -650,7 +645,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, addr, entry->client_id, soc15_ih_clientid_name[entry->client_id]); -if (gmc_v9_0_is_multi_chiplet (adev)) +if (amdgpu_is_multi_aid (adev))dev_err (adev->dev," cookie node_id %d fault from die %s%d%s\n" , node_id, node_id %4 ==3 ?"RSV" :"AID" , node_id /4 , node_id %4 ==1 ?".XCD0" : node_id %4 ==2 ?".XCD1" :"" );
@@ -799,7 +794,7 @@ static bool gmc_v9_0_use_invalidate_semaphore(struct amdgpu_device *adev, uint32_t vmhub) {if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,2 ) || -gmc_v9_0_is_multi_chiplet (adev)) +amdgpu_is_multi_aid (adev))return false; return ((vmhub == AMDGPU_MMHUB0(0) ||
@@ -1511,7 +1506,7 @@ static void gmc_v9_0_set_mmhub_ras_funcs(struct amdgpu_device *adev)static void gmc_v9_0_set_gfxhub_funcs (struct amdgpu_device *adev) { -if (gmc_v9_0_is_multi_chiplet (adev)) +if (amdgpu_is_multi_aid (adev)) adev->gfxhub.funcs = &gfxhub_v1_2_funcs;else adev->gfxhub.funcs = &gfxhub_v1_0_funcs;
@@ -1593,7 +1588,7 @@ static int gmc_v9_0_early_init(struct amdgpu_ip_block *ip_block)*/ if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,0 ) ||amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,1 ) || -gmc_v9_0_is_multi_chiplet (adev)) +amdgpu_is_multi_aid (adev)) adev->gmc.xgmi.supported = true;if (amdgpu_ip_version (adev,XGMI_HWIP ,0 ) ==IP_VERSION (6 ,1 ,0 )) {
@@ -2046,7 +2041,7 @@ static int gmc_v9_0_sw_init(struct amdgpu_ip_block *ip_block)spin_lock_init (&adev->gmc.invalidate_lock); -if (gmc_v9_0_is_multi_chiplet (adev)) { +if (amdgpu_is_multi_aid (adev)) {gmc_v9_4_3_init_vram_info (adev); }else if (!adev->bios) {if (adev->flags &AMD_IS_APU ) {
@@ -2196,7 +2191,7 @@ static int gmc_v9_0_sw_init(struct amdgpu_ip_block *ip_block)amdgpu_gmc_get_vbios_allocations (adev); -if (gmc_v9_0_is_multi_chiplet (adev)) { +if (amdgpu_is_multi_aid (adev)) { r =gmc_v9_0_init_mem_ranges (adev);if (r)return r;
@@ -2225,7 +2220,7 @@ static int gmc_v9_0_sw_init(struct amdgpu_ip_block *ip_block) adev->vm_manager.first_kfd_vmid = (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,1 ) ||amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,2 ) || -gmc_v9_0_is_multi_chiplet (adev)) ? +amdgpu_is_multi_aid (adev)) ?3 :8 ;
@@ -2237,7 +2232,7 @@ static int gmc_v9_0_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; -if (gmc_v9_0_is_multi_chiplet (adev)) +if (amdgpu_is_multi_aid (adev))amdgpu_gmc_sysfs_init (adev);return 0 ;
@@ -2247,7 +2242,7 @@ static int gmc_v9_0_sw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -if (gmc_v9_0_is_multi_chiplet (adev)) +if (amdgpu_is_multi_aid (adev))amdgpu_gmc_sysfs_fini (adev);amdgpu_gmc_ras_fini (adev);
Signature · 1 line
2.17.1
PATCH 10/10 drm/amdgpu: Convert init_mem_ranges into common helpers
In reply to Hawking ZhangThey can be shared across multiple products
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 185 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 3 + drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 186 +----------------------- 3 files changed, 190 insertions(+), 184 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +185 -0
@@ -1491,3 +1491,188 @@ amdgpu_gmc_query_memory_partition(struct amdgpu_device *adev)else return amdgpu_gmc_get_memory_partition (adev,NULL ); } + +static bool amdgpu_gmc_validate_partition_info (struct amdgpu_device *adev) +{ +enum amdgpu_memory_partition mode; +u32 supp_modes; +bool valid; + + mode =amdgpu_gmc_get_memory_partition (adev, &supp_modes); + +/* Mode detected by hardware not present in supported modes */ +if ((mode !=UNKNOWN_MEMORY_PARTITION_MODE ) && + !(BIT (mode -1 ) & supp_modes)) +return false; + +switch (mode) { +case UNKNOWN_MEMORY_PARTITION_MODE : +case AMDGPU_NPS1_PARTITION_MODE : + valid = (adev->gmc.num_mem_partitions ==1 ); +break ; +case AMDGPU_NPS2_PARTITION_MODE : + valid = (adev->gmc.num_mem_partitions ==2 ); +break ; +case AMDGPU_NPS4_PARTITION_MODE : + valid = (adev->gmc.num_mem_partitions ==3 || + adev->gmc.num_mem_partitions ==4 ); +break ; +case AMDGPU_NPS8_PARTITION_MODE : + valid = (adev->gmc.num_mem_partitions ==8 ); +break ; +default : + valid = false; + } + +return valid; +} + +static bool amdgpu_gmc_is_node_present (int *node_ids,int num_ids,int nid) +{ +int i; + +/* Check if node with id 'nid' is present in 'node_ids' array */ +for (i =0 ; i < num_ids; ++i) +if (node_ids[i] == nid) +return true; + +return false; +} + +static void amdgpu_gmc_init_acpi_mem_ranges (struct amdgpu_device *adev, +struct amdgpu_mem_partition_info *mem_ranges) +{ +struct amdgpu_numa_info numa_info; +int node_ids[AMDGPU_MAX_MEM_RANGES ]; +int num_ranges =0 , ret; +int num_xcc, xcc_id; +uint32_t xcc_mask; + + num_xcc =NUM_XCC (adev->gfx.xcc_mask); + xcc_mask = (1U << num_xcc) -1 ; + +for_each_inst (xcc_id, xcc_mask) { + ret =amdgpu_acpi_get_mem_info (adev, xcc_id, &numa_info); +if (ret) +continue ; + +if (numa_info.nid ==NUMA_NO_NODE ) { + mem_ranges[0 ].size = numa_info.size; + mem_ranges[0 ].numa.node = numa_info.nid; + num_ranges =1 ; +break ; + } + +if (amdgpu_gmc_is_node_present (node_ids, num_ranges, + numa_info.nid)) +continue ; + + node_ids[num_ranges] = numa_info.nid; + mem_ranges[num_ranges].numa.node = numa_info.nid; + mem_ranges[num_ranges].size = numa_info.size; + ++num_ranges; + } + + adev->gmc.num_mem_partitions = num_ranges; +} + +void amdgpu_gmc_init_sw_mem_ranges (struct amdgpu_device *adev, +struct amdgpu_mem_partition_info *mem_ranges) +{ +enum amdgpu_memory_partition mode; +u32 start_addr =0 , size; +int i, r, l; + + mode =amdgpu_gmc_query_memory_partition (adev); + +switch (mode) { +case UNKNOWN_MEMORY_PARTITION_MODE : + adev->gmc.num_mem_partitions =0 ; +break ; +case AMDGPU_NPS1_PARTITION_MODE : + adev->gmc.num_mem_partitions =1 ; +break ; +case AMDGPU_NPS2_PARTITION_MODE : + adev->gmc.num_mem_partitions =2 ; +break ; +case AMDGPU_NPS4_PARTITION_MODE : +if (adev->flags &AMD_IS_APU ) + adev->gmc.num_mem_partitions =3 ; +else + adev->gmc.num_mem_partitions =4 ; +break ; +case AMDGPU_NPS8_PARTITION_MODE : + adev->gmc.num_mem_partitions =8 ; +break ; +default : + adev->gmc.num_mem_partitions =1 ; +break ; + } + +/* Use NPS range info, if populated */ + r =amdgpu_gmc_get_nps_memranges (adev, mem_ranges, + &adev->gmc.num_mem_partitions); +if (!r) { + l =0 ; +for (i =1 ; i < adev->gmc.num_mem_partitions; ++i) { +if (mem_ranges[i].range.lpfn > + mem_ranges[i -1 ].range.lpfn) + l = i; + } + + }else { +if (!adev->gmc.num_mem_partitions) { +dev_warn (adev->dev, +"Not able to detect NPS mode, fall back to NPS1\n" ); + adev->gmc.num_mem_partitions =1 ; + } +/* Fallback to sw based calculation */ + size = (adev->gmc.real_vram_size +SZ_16M ) >>AMDGPU_GPU_PAGE_SHIFT ; + size /= adev->gmc.num_mem_partitions; + +for (i =0 ; i < adev->gmc.num_mem_partitions; ++i) { + mem_ranges[i].range.fpfn = start_addr; + mem_ranges[i].size = + ((u64 )size <<AMDGPU_GPU_PAGE_SHIFT ); + mem_ranges[i].range.lpfn = start_addr + size -1 ; + start_addr += size; + } + + l = adev->gmc.num_mem_partitions -1 ; + } + +/* Adjust the last one */ + mem_ranges[l].range.lpfn = + (adev->gmc.real_vram_size >>AMDGPU_GPU_PAGE_SHIFT ) -1 ; + mem_ranges[l].size = + adev->gmc.real_vram_size - + ((u64 )mem_ranges[l].range.fpfn <<AMDGPU_GPU_PAGE_SHIFT ); +} + +int amdgpu_gmc_init_mem_ranges (struct amdgpu_device *adev) +{ +bool valid; + + adev->gmc.mem_partitions =kcalloc (AMDGPU_MAX_MEM_RANGES , +sizeof (struct amdgpu_mem_partition_info ), +GFP_KERNEL ); +if (!adev->gmc.mem_partitions) +return -ENOMEM ; + +if (adev->gmc.is_app_apu) +amdgpu_gmc_init_acpi_mem_ranges (adev, adev->gmc.mem_partitions); +else +amdgpu_gmc_init_sw_mem_ranges (adev, adev->gmc.mem_partitions); + +if (amdgpu_sriov_vf (adev)) + valid = true; +else + valid =amdgpu_gmc_validate_partition_info (adev); +if (!valid) { +/* TODO: handle invalid case */ +dev_warn (adev->dev, +"Mem ranges not matching with hardware config\n" ); + } + +return 0 ; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +3 -0
@@ -464,4 +464,7 @@ enum amdgpu_memory_partition amdgpu_gmc_get_memory_partition(struct amdgpu_device *adev, u32 *supp_modes);enum amdgpu_memory_partition amdgpu_gmc_query_memory_partition (struct amdgpu_device *adev); +int amdgpu_gmc_init_mem_ranges (struct amdgpu_device *adev); +void amdgpu_gmc_init_sw_mem_ranges (struct amdgpu_device *adev, +struct amdgpu_mem_partition_info *mem_ranges);#endif
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -184
204 lines not on this page · raw message
Signature · 1 line
2.17.1