Commit 617d5b34 authored by xinhui pan's avatar xinhui pan Committed by Christian König

drm/ttm: Try to check if new ttm man out of bounds during compile

Allow TTM know if vendor set new ttm mananger out of bounds by adding
build_bug_on.
Signed-off-by: default avatarxinhui pan <xinhui.pan@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210913080950.180752-1-xinhui.pan@amd.comSigned-off-by: default avatarChristian König <christian.koenig@amd.com>
parent d4cb82aa
...@@ -138,7 +138,7 @@ static const struct ttm_resource_manager_func ttm_range_manager_func = { ...@@ -138,7 +138,7 @@ static const struct ttm_resource_manager_func ttm_range_manager_func = {
* Initialise a generic range manager for the selected memory type. * Initialise a generic range manager for the selected memory type.
* The range manager is installed for this device in the type slot. * The range manager is installed for this device in the type slot.
*/ */
int ttm_range_man_init(struct ttm_device *bdev, int ttm_range_man_init_nocheck(struct ttm_device *bdev,
unsigned type, bool use_tt, unsigned type, bool use_tt,
unsigned long p_size) unsigned long p_size)
{ {
...@@ -163,7 +163,7 @@ int ttm_range_man_init(struct ttm_device *bdev, ...@@ -163,7 +163,7 @@ int ttm_range_man_init(struct ttm_device *bdev,
ttm_resource_manager_set_used(man, true); ttm_resource_manager_set_used(man, true);
return 0; return 0;
} }
EXPORT_SYMBOL(ttm_range_man_init); EXPORT_SYMBOL(ttm_range_man_init_nocheck);
/** /**
* ttm_range_man_fini * ttm_range_man_fini
...@@ -173,7 +173,7 @@ EXPORT_SYMBOL(ttm_range_man_init); ...@@ -173,7 +173,7 @@ EXPORT_SYMBOL(ttm_range_man_init);
* *
* Remove the generic range manager from a slot and tear it down. * Remove the generic range manager from a slot and tear it down.
*/ */
int ttm_range_man_fini(struct ttm_device *bdev, int ttm_range_man_fini_nocheck(struct ttm_device *bdev,
unsigned type) unsigned type)
{ {
struct ttm_resource_manager *man = ttm_manager_type(bdev, type); struct ttm_resource_manager *man = ttm_manager_type(bdev, type);
...@@ -200,4 +200,4 @@ int ttm_range_man_fini(struct ttm_device *bdev, ...@@ -200,4 +200,4 @@ int ttm_range_man_fini(struct ttm_device *bdev,
kfree(rman); kfree(rman);
return 0; return 0;
} }
EXPORT_SYMBOL(ttm_range_man_fini); EXPORT_SYMBOL(ttm_range_man_fini_nocheck);
...@@ -291,12 +291,15 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx, ...@@ -291,12 +291,15 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
static inline struct ttm_resource_manager * static inline struct ttm_resource_manager *
ttm_manager_type(struct ttm_device *bdev, int mem_type) ttm_manager_type(struct ttm_device *bdev, int mem_type)
{ {
BUILD_BUG_ON(__builtin_constant_p(mem_type)
&& mem_type >= TTM_NUM_MEM_TYPES);
return bdev->man_drv[mem_type]; return bdev->man_drv[mem_type];
} }
static inline void ttm_set_driver_manager(struct ttm_device *bdev, int type, static inline void ttm_set_driver_manager(struct ttm_device *bdev, int type,
struct ttm_resource_manager *manager) struct ttm_resource_manager *manager)
{ {
BUILD_BUG_ON(__builtin_constant_p(type) && type >= TTM_NUM_MEM_TYPES);
bdev->man_drv[type] = manager; bdev->man_drv[type] = manager;
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#define _TTM_RANGE_MANAGER_H_ #define _TTM_RANGE_MANAGER_H_
#include <drm/ttm/ttm_resource.h> #include <drm/ttm/ttm_resource.h>
#include <drm/ttm/ttm_device.h>
#include <drm/drm_mm.h> #include <drm/drm_mm.h>
/** /**
...@@ -33,10 +34,23 @@ to_ttm_range_mgr_node(struct ttm_resource *res) ...@@ -33,10 +34,23 @@ to_ttm_range_mgr_node(struct ttm_resource *res)
return container_of(res, struct ttm_range_mgr_node, base); return container_of(res, struct ttm_range_mgr_node, base);
} }
int ttm_range_man_init(struct ttm_device *bdev, int ttm_range_man_init_nocheck(struct ttm_device *bdev,
unsigned type, bool use_tt, unsigned type, bool use_tt,
unsigned long p_size); unsigned long p_size);
int ttm_range_man_fini(struct ttm_device *bdev, int ttm_range_man_fini_nocheck(struct ttm_device *bdev,
unsigned type); unsigned type);
static __always_inline int ttm_range_man_init(struct ttm_device *bdev,
unsigned int type, bool use_tt,
unsigned long p_size)
{
BUILD_BUG_ON(__builtin_constant_p(type) && type >= TTM_NUM_MEM_TYPES);
return ttm_range_man_init_nocheck(bdev, type, use_tt, p_size);
}
static __always_inline int ttm_range_man_fini(struct ttm_device *bdev,
unsigned int type)
{
BUILD_BUG_ON(__builtin_constant_p(type) && type >= TTM_NUM_MEM_TYPES);
return ttm_range_man_fini_nocheck(bdev, type);
}
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment