diff options
author | Rob Clark <rob@ti.com> | 2011-08-10 09:09:08 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2011-08-30 06:07:00 -0400 |
commit | b464e9a25c27884eb8ee2c2bb904ec50bd3990ea (patch) | |
tree | 5db7dba2b387c41a31ac94c4cb98f17046650674 /drivers/gpu/drm/i915/i915_gem.c | |
parent | 75ef8b3b9c0b76eb5a16cd838cb99a7deecceb85 (diff) |
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>
Diffstat (limited to 'drivers/gpu/drm/i915/i915_gem.c')
-rw-r--r-- | drivers/gpu/drm/i915/i915_gem.c | 85 |
1 files changed, 2 insertions, 83 deletions
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index a546a71fb060..ee59f31316e0 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c | |||
@@ -1265,74 +1265,6 @@ out: | |||
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | /** | 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 | |||
1335 | /** | ||
1336 | * i915_gem_release_mmap - remove physical page mappings | 1268 | * i915_gem_release_mmap - remove physical page mappings |
1337 | * @obj: obj in question | 1269 | * @obj: obj in question |
1338 | * | 1270 | * |
@@ -1360,19 +1292,6 @@ i915_gem_release_mmap(struct drm_i915_gem_object *obj) | |||
1360 | obj->fault_mappable = false; | 1292 | obj->fault_mappable = false; |
1361 | } | 1293 | } |
1362 | 1294 | ||
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 | |||
1376 | static uint32_t | 1295 | static uint32_t |
1377 | i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, int tiling_mode) | 1296 | i915_gem_get_gtt_size(struct drm_device *dev, uint32_t size, int tiling_mode) |
1378 | { | 1297 | { |
@@ -1485,7 +1404,7 @@ i915_gem_mmap_gtt(struct drm_file *file, | |||
1485 | } | 1404 | } |
1486 | 1405 | ||
1487 | if (!obj->base.map_list.map) { | 1406 | if (!obj->base.map_list.map) { |
1488 | ret = i915_gem_create_mmap_offset(obj); | 1407 | ret = drm_gem_create_mmap_offset(&obj->base); |
1489 | if (ret) | 1408 | if (ret) |
1490 | goto out; | 1409 | goto out; |
1491 | } | 1410 | } |
@@ -3752,7 +3671,7 @@ static void i915_gem_free_object_tail(struct drm_i915_gem_object *obj) | |||
3752 | trace_i915_gem_object_destroy(obj); | 3671 | trace_i915_gem_object_destroy(obj); |
3753 | 3672 | ||
3754 | if (obj->base.map_list.map) | 3673 | if (obj->base.map_list.map) |
3755 | i915_gem_free_mmap_offset(obj); | 3674 | drm_gem_free_mmap_offset(&obj->base); |
3756 | 3675 | ||
3757 | drm_gem_object_release(&obj->base); | 3676 | drm_gem_object_release(&obj->base); |
3758 | i915_gem_info_remove_obj(dev_priv, obj->base.size); | 3677 | i915_gem_info_remove_obj(dev_priv, obj->base.size); |