Re: [PATCH] drm/amdgpu: implement TMZ accessor (v3)
On Wed, Nov 27, 2019 at 6:36 PM Luben Tuikov wrote: > > Implement an accessor of adev->tmz.enabled. Let not > code around access it as "if (adev->tmz.enabled)" > as the organization may change. Instead... > > Recruit "bool amdgpu_is_tmz(adev)" to return > exactly this Boolean value. That is, this function > is now an accessor of an already initialized and > set adev and adev->tmz. > > Add "void amdgpu_gmc_tmz_set(adev)" to check and > set adev->gmc.tmz_enabled at initialization > time. After which one uses "bool > amdgpu_is_tmz(adev)" to query whether adev > supports TMZ. > > Also, remove circular header file include. > > v2: Remove amdgpu_tmz.[ch] as requested. > v3: Move TMZ into GMC. > > Signed-off-by: Luben Tuikov > Acked-by: Christian König Reviewed-by: Alex Deucher > --- > drivers/gpu/drm/amd/amdgpu/Makefile| 2 +- > drivers/gpu/drm/amd/amdgpu/amdgpu.h| 10 ++--- > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +- > drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 4 +- > drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c| 25 +++ > drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h| 4 ++ > drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.c| 52 -- > drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h| 39 > drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +- > drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 +- > 10 files changed, 40 insertions(+), 103 deletions(-) > delete mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.c > delete mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h > > diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile > b/drivers/gpu/drm/amd/amdgpu/Makefile > index 83ee1c676e3a..7ae3b22c5628 100644 > --- a/drivers/gpu/drm/amd/amdgpu/Makefile > +++ b/drivers/gpu/drm/amd/amdgpu/Makefile > @@ -55,7 +55,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \ > amdgpu_vf_error.o amdgpu_sched.o amdgpu_debugfs.o amdgpu_ids.o \ > amdgpu_gmc.o amdgpu_mmhub.o amdgpu_xgmi.o amdgpu_csa.o amdgpu_ras.o > amdgpu_vm_cpu.o \ > amdgpu_vm_sdma.o amdgpu_discovery.o amdgpu_ras_eeprom.o amdgpu_nbio.o > \ > - amdgpu_umc.o smu_v11_0_i2c.o amdgpu_tmz.o > + amdgpu_umc.o smu_v11_0_i2c.o > > amdgpu-$(CONFIG_PERF_EVENTS) += amdgpu_pmu.o > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > index d120fe58ebea..cee37a4f8327 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > @@ -90,7 +90,6 @@ > #include "amdgpu_mes.h" > #include "amdgpu_umc.h" > #include "amdgpu_mmhub.h" > -#include "amdgpu_tmz.h" > > #define MAX_GPU_INSTANCE 16 > > @@ -937,9 +936,6 @@ struct amdgpu_device { > boolenable_mes; > struct amdgpu_mes mes; > > - /* tmz */ > - struct amdgpu_tmz tmz; > - > struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM]; > int num_ip_blocks; > struct mutexmn_lock; > @@ -1266,5 +1262,9 @@ _name##_show(struct device *dev, > \ > \ > static struct device_attribute pmu_attr_##_name = __ATTR_RO(_name) > > -#endif > +static inline bool amdgpu_is_tmz(struct amdgpu_device *adev) > +{ > + return adev->gmc.tmz_enabled; > +} > > +#endif > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > index b1408c5e4640..8dc96ae9f1c6 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > @@ -64,7 +64,6 @@ > #include "amdgpu_xgmi.h" > #include "amdgpu_ras.h" > #include "amdgpu_pmu.h" > -#include "amdgpu_tmz.h" > > #include > > @@ -1073,7 +1072,7 @@ static int amdgpu_device_check_arguments(struct > amdgpu_device *adev) > > adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, > amdgpu_fw_load_type); > > - adev->tmz.enabled = amdgpu_is_tmz(adev); > + amdgpu_gmc_tmz_set(adev); > > return ret; > } > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > index 716496a858e7..f41d41c2948f 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > @@ -235,8 +235,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void > *data, > if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK) > return -EINVAL; > > - if (!adev->tmz.enabled && (flags & AMDGPU_GEM_CREATE_ENCRYPTED)) { > - DRM_ERROR("Cannot allocate secure buffer while tmz is > disabled\n"); > + if (amdgpu_is_tmz(adev) && (flags & AMDGPU_GEM_CREATE_ENCRYPTED)) { > + DRM_ERROR("Cannot allocate secure buffer since TMZ is > disabled\n"); > return -EINVAL; > } > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c >
[PATCH] drm/amdgpu: implement TMZ accessor (v3)
Implement an accessor of adev->tmz.enabled. Let not code around access it as "if (adev->tmz.enabled)" as the organization may change. Instead... Recruit "bool amdgpu_is_tmz(adev)" to return exactly this Boolean value. That is, this function is now an accessor of an already initialized and set adev and adev->tmz. Add "void amdgpu_gmc_tmz_set(adev)" to check and set adev->gmc.tmz_enabled at initialization time. After which one uses "bool amdgpu_is_tmz(adev)" to query whether adev supports TMZ. Also, remove circular header file include. v2: Remove amdgpu_tmz.[ch] as requested. v3: Move TMZ into GMC. Signed-off-by: Luben Tuikov Acked-by: Christian König --- drivers/gpu/drm/amd/amdgpu/Makefile| 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h| 10 ++--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c| 25 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h| 4 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.c| 52 -- drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h| 39 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 +- 10 files changed, 40 insertions(+), 103 deletions(-) delete mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.c delete mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile index 83ee1c676e3a..7ae3b22c5628 100644 --- a/drivers/gpu/drm/amd/amdgpu/Makefile +++ b/drivers/gpu/drm/amd/amdgpu/Makefile @@ -55,7 +55,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \ amdgpu_vf_error.o amdgpu_sched.o amdgpu_debugfs.o amdgpu_ids.o \ amdgpu_gmc.o amdgpu_mmhub.o amdgpu_xgmi.o amdgpu_csa.o amdgpu_ras.o amdgpu_vm_cpu.o \ amdgpu_vm_sdma.o amdgpu_discovery.o amdgpu_ras_eeprom.o amdgpu_nbio.o \ - amdgpu_umc.o smu_v11_0_i2c.o amdgpu_tmz.o + amdgpu_umc.o smu_v11_0_i2c.o amdgpu-$(CONFIG_PERF_EVENTS) += amdgpu_pmu.o diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index d120fe58ebea..cee37a4f8327 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -90,7 +90,6 @@ #include "amdgpu_mes.h" #include "amdgpu_umc.h" #include "amdgpu_mmhub.h" -#include "amdgpu_tmz.h" #define MAX_GPU_INSTANCE 16 @@ -937,9 +936,6 @@ struct amdgpu_device { boolenable_mes; struct amdgpu_mes mes; - /* tmz */ - struct amdgpu_tmz tmz; - struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM]; int num_ip_blocks; struct mutexmn_lock; @@ -1266,5 +1262,9 @@ _name##_show(struct device *dev, \ \ static struct device_attribute pmu_attr_##_name = __ATTR_RO(_name) -#endif +static inline bool amdgpu_is_tmz(struct amdgpu_device *adev) +{ + return adev->gmc.tmz_enabled; +} +#endif diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index b1408c5e4640..8dc96ae9f1c6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -64,7 +64,6 @@ #include "amdgpu_xgmi.h" #include "amdgpu_ras.h" #include "amdgpu_pmu.h" -#include "amdgpu_tmz.h" #include @@ -1073,7 +1072,7 @@ static int amdgpu_device_check_arguments(struct amdgpu_device *adev) adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type); - adev->tmz.enabled = amdgpu_is_tmz(adev); + amdgpu_gmc_tmz_set(adev); return ret; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 716496a858e7..f41d41c2948f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -235,8 +235,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK) return -EINVAL; - if (!adev->tmz.enabled && (flags & AMDGPU_GEM_CREATE_ENCRYPTED)) { - DRM_ERROR("Cannot allocate secure buffer while tmz is disabled\n"); + if (amdgpu_is_tmz(adev) && (flags & AMDGPU_GEM_CREATE_ENCRYPTED)) { + DRM_ERROR("Cannot allocate secure buffer since TMZ is disabled\n"); return -EINVAL; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c index a12f33c0f5df..80db4b79af33 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c @@ -333,3 +333,28 @@ void amdgpu_gmc_ras_fini(struct amdgpu_device *adev) amdgpu_mmhub_ras_fini(adev); amdgpu_xgmi_ras_fini(adev); } + +/** + *