forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
....@@ -37,6 +37,7 @@
3737 #include <linux/kernel.h>
3838
3939 struct vmwgfx_gmrid_man {
40
+ struct ttm_resource_manager manager;
4041 spinlock_t lock;
4142 struct ida gmr_ida;
4243 uint32_t max_gmr_ids;
....@@ -44,20 +45,22 @@
4445 uint32_t used_gmr_pages;
4546 };
4647
47
-static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager *man,
48
+static struct vmwgfx_gmrid_man *to_gmrid_manager(struct ttm_resource_manager *man)
49
+{
50
+ return container_of(man, struct vmwgfx_gmrid_man, manager);
51
+}
52
+
53
+static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man,
4854 struct ttm_buffer_object *bo,
4955 const struct ttm_place *place,
50
- struct ttm_mem_reg *mem)
56
+ struct ttm_resource *mem)
5157 {
52
- struct vmwgfx_gmrid_man *gman =
53
- (struct vmwgfx_gmrid_man *)man->priv;
58
+ struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
5459 int id;
55
-
56
- mem->mm_node = NULL;
5760
5861 id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL);
5962 if (id < 0)
60
- return (id != -ENOMEM ? 0 : id);
63
+ return id;
6164
6265 spin_lock(&gman->lock);
6366
....@@ -78,14 +81,13 @@
7881 gman->used_gmr_pages -= bo->num_pages;
7982 spin_unlock(&gman->lock);
8083 ida_free(&gman->gmr_ida, id);
81
- return 0;
84
+ return -ENOSPC;
8285 }
8386
84
-static void vmw_gmrid_man_put_node(struct ttm_mem_type_manager *man,
85
- struct ttm_mem_reg *mem)
87
+static void vmw_gmrid_man_put_node(struct ttm_resource_manager *man,
88
+ struct ttm_resource *mem)
8689 {
87
- struct vmwgfx_gmrid_man *gman =
88
- (struct vmwgfx_gmrid_man *)man->priv;
90
+ struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
8991
9092 if (mem->mm_node) {
9193 ida_free(&gman->gmr_ida, mem->start);
....@@ -96,22 +98,28 @@
9698 }
9799 }
98100
99
-static int vmw_gmrid_man_init(struct ttm_mem_type_manager *man,
100
- unsigned long p_size)
101
+static const struct ttm_resource_manager_func vmw_gmrid_manager_func;
102
+
103
+int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
101104 {
102
- struct vmw_private *dev_priv =
103
- container_of(man->bdev, struct vmw_private, bdev);
105
+ struct ttm_resource_manager *man;
104106 struct vmwgfx_gmrid_man *gman =
105107 kzalloc(sizeof(*gman), GFP_KERNEL);
106108
107109 if (unlikely(!gman))
108110 return -ENOMEM;
109111
112
+ man = &gman->manager;
113
+
114
+ man->func = &vmw_gmrid_manager_func;
115
+ /* TODO: This is most likely not correct */
116
+ man->use_tt = true;
117
+ ttm_resource_manager_init(man, 0);
110118 spin_lock_init(&gman->lock);
111119 gman->used_gmr_pages = 0;
112120 ida_init(&gman->gmr_ida);
113121
114
- switch (p_size) {
122
+ switch (type) {
115123 case VMW_PL_GMR:
116124 gman->max_gmr_ids = dev_priv->max_gmr_ids;
117125 gman->max_gmr_pages = dev_priv->max_gmr_pages;
....@@ -123,32 +131,29 @@
123131 default:
124132 BUG();
125133 }
126
- man->priv = (void *) gman;
134
+ ttm_set_driver_manager(&dev_priv->bdev, type, &gman->manager);
135
+ ttm_resource_manager_set_used(man, true);
127136 return 0;
128137 }
129138
130
-static int vmw_gmrid_man_takedown(struct ttm_mem_type_manager *man)
139
+void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type)
131140 {
132
- struct vmwgfx_gmrid_man *gman =
133
- (struct vmwgfx_gmrid_man *)man->priv;
141
+ struct ttm_resource_manager *man = ttm_manager_type(&dev_priv->bdev, type);
142
+ struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
134143
135
- if (gman) {
136
- ida_destroy(&gman->gmr_ida);
137
- kfree(gman);
138
- }
139
- return 0;
144
+ ttm_resource_manager_set_used(man, false);
145
+
146
+ ttm_resource_manager_force_list_clean(&dev_priv->bdev, man);
147
+
148
+ ttm_resource_manager_cleanup(man);
149
+
150
+ ttm_set_driver_manager(&dev_priv->bdev, type, NULL);
151
+ ida_destroy(&gman->gmr_ida);
152
+ kfree(gman);
153
+
140154 }
141155
142
-static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
143
- struct drm_printer *printer)
144
-{
145
- drm_printf(printer, "No debug info available for the GMR id manager\n");
146
-}
147
-
148
-const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
149
- .init = vmw_gmrid_man_init,
150
- .takedown = vmw_gmrid_man_takedown,
151
- .get_node = vmw_gmrid_man_get_node,
152
- .put_node = vmw_gmrid_man_put_node,
153
- .debug = vmw_gmrid_man_debug
156
+static const struct ttm_resource_manager_func vmw_gmrid_manager_func = {
157
+ .alloc = vmw_gmrid_man_get_node,
158
+ .free = vmw_gmrid_man_put_node,
154159 };