| .. | .. |
|---|
| 37 | 37 | #include <linux/kernel.h> |
|---|
| 38 | 38 | |
|---|
| 39 | 39 | struct vmwgfx_gmrid_man { |
|---|
| 40 | + struct ttm_resource_manager manager; |
|---|
| 40 | 41 | spinlock_t lock; |
|---|
| 41 | 42 | struct ida gmr_ida; |
|---|
| 42 | 43 | uint32_t max_gmr_ids; |
|---|
| .. | .. |
|---|
| 44 | 45 | uint32_t used_gmr_pages; |
|---|
| 45 | 46 | }; |
|---|
| 46 | 47 | |
|---|
| 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, |
|---|
| 48 | 54 | struct ttm_buffer_object *bo, |
|---|
| 49 | 55 | const struct ttm_place *place, |
|---|
| 50 | | - struct ttm_mem_reg *mem) |
|---|
| 56 | + struct ttm_resource *mem) |
|---|
| 51 | 57 | { |
|---|
| 52 | | - struct vmwgfx_gmrid_man *gman = |
|---|
| 53 | | - (struct vmwgfx_gmrid_man *)man->priv; |
|---|
| 58 | + struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man); |
|---|
| 54 | 59 | int id; |
|---|
| 55 | | - |
|---|
| 56 | | - mem->mm_node = NULL; |
|---|
| 57 | 60 | |
|---|
| 58 | 61 | id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL); |
|---|
| 59 | 62 | if (id < 0) |
|---|
| 60 | | - return (id != -ENOMEM ? 0 : id); |
|---|
| 63 | + return id; |
|---|
| 61 | 64 | |
|---|
| 62 | 65 | spin_lock(&gman->lock); |
|---|
| 63 | 66 | |
|---|
| .. | .. |
|---|
| 78 | 81 | gman->used_gmr_pages -= bo->num_pages; |
|---|
| 79 | 82 | spin_unlock(&gman->lock); |
|---|
| 80 | 83 | ida_free(&gman->gmr_ida, id); |
|---|
| 81 | | - return 0; |
|---|
| 84 | + return -ENOSPC; |
|---|
| 82 | 85 | } |
|---|
| 83 | 86 | |
|---|
| 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) |
|---|
| 86 | 89 | { |
|---|
| 87 | | - struct vmwgfx_gmrid_man *gman = |
|---|
| 88 | | - (struct vmwgfx_gmrid_man *)man->priv; |
|---|
| 90 | + struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man); |
|---|
| 89 | 91 | |
|---|
| 90 | 92 | if (mem->mm_node) { |
|---|
| 91 | 93 | ida_free(&gman->gmr_ida, mem->start); |
|---|
| .. | .. |
|---|
| 96 | 98 | } |
|---|
| 97 | 99 | } |
|---|
| 98 | 100 | |
|---|
| 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) |
|---|
| 101 | 104 | { |
|---|
| 102 | | - struct vmw_private *dev_priv = |
|---|
| 103 | | - container_of(man->bdev, struct vmw_private, bdev); |
|---|
| 105 | + struct ttm_resource_manager *man; |
|---|
| 104 | 106 | struct vmwgfx_gmrid_man *gman = |
|---|
| 105 | 107 | kzalloc(sizeof(*gman), GFP_KERNEL); |
|---|
| 106 | 108 | |
|---|
| 107 | 109 | if (unlikely(!gman)) |
|---|
| 108 | 110 | return -ENOMEM; |
|---|
| 109 | 111 | |
|---|
| 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); |
|---|
| 110 | 118 | spin_lock_init(&gman->lock); |
|---|
| 111 | 119 | gman->used_gmr_pages = 0; |
|---|
| 112 | 120 | ida_init(&gman->gmr_ida); |
|---|
| 113 | 121 | |
|---|
| 114 | | - switch (p_size) { |
|---|
| 122 | + switch (type) { |
|---|
| 115 | 123 | case VMW_PL_GMR: |
|---|
| 116 | 124 | gman->max_gmr_ids = dev_priv->max_gmr_ids; |
|---|
| 117 | 125 | gman->max_gmr_pages = dev_priv->max_gmr_pages; |
|---|
| .. | .. |
|---|
| 123 | 131 | default: |
|---|
| 124 | 132 | BUG(); |
|---|
| 125 | 133 | } |
|---|
| 126 | | - man->priv = (void *) gman; |
|---|
| 134 | + ttm_set_driver_manager(&dev_priv->bdev, type, &gman->manager); |
|---|
| 135 | + ttm_resource_manager_set_used(man, true); |
|---|
| 127 | 136 | return 0; |
|---|
| 128 | 137 | } |
|---|
| 129 | 138 | |
|---|
| 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) |
|---|
| 131 | 140 | { |
|---|
| 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); |
|---|
| 134 | 143 | |
|---|
| 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 | + |
|---|
| 140 | 154 | } |
|---|
| 141 | 155 | |
|---|
| 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, |
|---|
| 154 | 159 | }; |
|---|