Skip to content

Commit b464e9a

Browse files
Rob Clarkairlied
authored andcommitted
drm/i915: use common functions for mmap offset creation
Signed-off-by: Rob Clark <rob@ti.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 75ef8b3 commit b464e9a

1 file changed

Lines changed: 2 additions & 83 deletions

File tree

‎drivers/gpu/drm/i915/i915_gem.c‎

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,74 +1264,6 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12641264
}
12651265
}
12661266

1267-
/**
1268-
* i915_gem_create_mmap_offset - create a fake mmap offset for an object
1269-
* @obj: obj in question
1270-
*
1271-
* GEM memory mapping works by handing back to userspace a fake mmap offset
1272-
* it can use in a subsequent mmap(2) call. The DRM core code then looks
1273-
* up the object based on the offset and sets up the various memory mapping
1274-
* structures.
1275-
*
1276-
* This routine allocates and attaches a fake offset for @obj.
1277-
*/
1278-
static int
1279-
i915_gem_create_mmap_offset(struct drm_i915_gem_object *obj)
1280-
{
1281-
struct drm_device *dev = obj->base.dev;
1282-
struct drm_gem_mm *mm = dev->mm_private;
1283-
struct drm_map_list *list;
1284-
struct drm_local_map *map;
1285-
int ret = 0;
1286-
1287-
/* Set the object up for mmap'ing */
1288-
list = &obj->base.map_list;
1289-
list->map = kzalloc(sizeof(struct drm_map_list), GFP_KERNEL);
1290-
if (!list->map)
1291-
return -ENOMEM;
1292-
1293-
map = list->map;
1294-
map->type = _DRM_GEM;
1295-
map->size = obj->base.size;
1296-
map->handle = obj;
1297-
1298-
/* Get a DRM GEM mmap offset allocated... */
1299-
list->file_offset_node = drm_mm_search_free(&mm->offset_manager,
1300-
obj->base.size / PAGE_SIZE,
1301-
0, 0);
1302-
if (!list->file_offset_node) {
1303-
DRM_ERROR("failed to allocate offset for bo %d\n",
1304-
obj->base.name);
1305-
ret = -ENOSPC;
1306-
goto out_free_list;
1307-
}
1308-
1309-
list->file_offset_node = drm_mm_get_block(list->file_offset_node,
1310-
obj->base.size / PAGE_SIZE,
1311-
0);
1312-
if (!list->file_offset_node) {
1313-
ret = -ENOMEM;
1314-
goto out_free_list;
1315-
}
1316-
1317-
list->hash.key = list->file_offset_node->start;
1318-
ret = drm_ht_insert_item(&mm->offset_hash, &list->hash);
1319-
if (ret) {
1320-
DRM_ERROR("failed to add to map hash\n");
1321-
goto out_free_mm;
1322-
}
1323-
1324-
return 0;
1325-
1326-
out_free_mm:
1327-
drm_mm_put_block(list->file_offset_node);
1328-
out_free_list:
1329-
kfree(list->map);
1330-
list->map = NULL;
1331-
1332-
return ret;
1333-
}
1334-
13351267
/**
13361268
* i915_gem_release_mmap - remove physical page mappings
13371269
* @obj: obj in question
@@ -1360,19 +1292,6 @@ i915_gem_release_mmap(struct drm_i915_gem_object *obj)
13601292
obj->fault_mappable = false;
13611293
}
13621294

1363-
static void
1364-
i915_gem_free_mmap_offset(struct drm_i915_gem_object *obj)
1365-
{
1366-
struct drm_device *dev = obj->base.dev;
1367-
struct drm_gem_mm *mm = dev->mm_private;
1368-
struct drm_map_list *list = &obj->base.map_list;
1369-
1370-
drm_ht_remove_item(&mm->offset_hash, &list->hash);
1371-
drm_mm_put_block(list->file_offset_node);
1372-
kfree(list->map);
1373-
list->map = NULL;
1374-
}
1375-
13761295
static uint32_t
13771296
i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, int tiling_mode)
13781297
{
@@ -1485,7 +1404,7 @@ i915_gem_mmap_gtt(struct drm_file *file,
14851404
}
14861405

14871406
if (!obj->base.map_list.map) {
1488-
ret = i915_gem_create_mmap_offset(obj);
1407+
ret = drm_gem_create_mmap_offset(&obj->base);
14891408
if (ret)
14901409
goto out;
14911410
}
@@ -3752,7 +3671,7 @@ static void i915_gem_free_object_tail(struct drm_i915_gem_object *obj)
37523671
trace_i915_gem_object_destroy(obj);
37533672

37543673
if (obj->base.map_list.map)
3755-
i915_gem_free_mmap_offset(obj);
3674+
drm_gem_free_mmap_offset(&obj->base);
37563675

37573676
drm_gem_object_release(&obj->base);
37583677
i915_gem_info_remove_obj(dev_priv, obj->base.size);

0 commit comments

Comments
 (0)