From b0bc5f1ae559c705565e516ebb289bf072559dec Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 14 Dec 2007 11:42:17 -0800 Subject: Make ttm create/destroy APIs consistent. Pass page_flags in create. Creating a ttm was done with drm_ttm_init while destruction was done with drm_destroy_ttm. Renaming these to drm_ttm_create and drm_ttm_destroy makes their use clearer. Passing page_flags to the create function will allow that to know whether user or kernel pages are needed, with the goal of allowing kernel ttms to be saved for later reuse. --- linux-core/drm_bo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'linux-core/drm_bo.c') diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index d308dcfd..4845f442 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -144,12 +144,12 @@ static int drm_bo_add_ttm(struct drm_buffer_object *bo) switch (bo->type) { case drm_bo_type_dc: case drm_bo_type_kernel: - bo->ttm = drm_ttm_init(dev, bo->num_pages << PAGE_SHIFT); + bo->ttm = drm_ttm_create(dev, bo->num_pages << PAGE_SHIFT, 0); if (!bo->ttm) ret = -ENOMEM; break; case drm_bo_type_user: - bo->ttm = drm_ttm_init(dev, bo->num_pages << PAGE_SHIFT); + bo->ttm = drm_ttm_create(dev, bo->num_pages << PAGE_SHIFT, DRM_TTM_PAGE_USER); if (!bo->ttm) ret = -ENOMEM; @@ -262,7 +262,7 @@ out_err: new_man = &bm->man[bo->mem.mem_type]; if ((new_man->flags & _DRM_FLAG_MEMTYPE_FIXED) && bo->ttm) { drm_ttm_unbind(bo->ttm); - drm_destroy_ttm(bo->ttm); + drm_ttm_destroy(bo->ttm); bo->ttm = NULL; } @@ -419,7 +419,7 @@ static void drm_bo_destroy_locked(struct drm_buffer_object *bo) if (bo->ttm) { drm_ttm_unbind(bo->ttm); - drm_destroy_ttm(bo->ttm); + drm_ttm_destroy(bo->ttm); bo->ttm = NULL; } -- cgit v1.2.3 From b5181d2506be332db8b07c02cdf37c6e25545c4d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 14 Dec 2007 12:33:35 -0800 Subject: Document drm_bo_do_validate. Remove spurious 'do_wait' parameter. Add comments about the parameters to drm_bo_do_validate, along with comments for the DRM_BO_HINT options. Remove the 'do_wait' parameter as it is duplicated by DRM_BO_HINT_DONT_BLOCK. --- linux-core/drm_bo.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'linux-core/drm_bo.c') diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index 4845f442..d7a507ab 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -1502,13 +1502,36 @@ static int drm_buffer_object_validate(struct drm_buffer_object *bo, return 0; } +/* + * drm_bo_do_validate + * + * 'validate' a buffer object. This changes where the buffer is + * located, along with changing access modes. + * + * flags access rights, mapping parameters and cacheability. See + * the DRM_BO_FLAG_* values in drm.h + * + * mask which flag values to change; this allows callers to modify + * things without knowing the current state of other flags. + * + * hint changes the proceedure for this operation, see the DRM_BO_HINT_* + * values in drm.h. + * + * fence_class a driver-specific way of doing fences. Presumably, this + * would be used if the driver had more than one submission and + * fencing mechanism. At this point, there isn't any use of this + * from the user mode code. + * + * rep will be stuffed with the reply from validation + */ + int drm_bo_do_validate(struct drm_buffer_object *bo, uint64_t flags, uint64_t mask, uint32_t hint, uint32_t fence_class, - int no_wait, struct drm_bo_info_rep *rep) { int ret; + int no_wait = (hint & DRM_BO_HINT_DONT_BLOCK) != 0; mutex_lock(&bo->mutex); ret = drm_bo_wait_unfenced(bo, no_wait, 0); @@ -1547,7 +1570,6 @@ int drm_bo_handle_validate(struct drm_file *file_priv, uint32_t handle, struct drm_device *dev = file_priv->head->dev; struct drm_buffer_object *bo; int ret; - int no_wait = hint & DRM_BO_HINT_DONT_BLOCK; mutex_lock(&dev->struct_mutex); bo = drm_lookup_buffer_object(file_priv, handle, 1); @@ -1567,8 +1589,7 @@ int drm_bo_handle_validate(struct drm_file *file_priv, uint32_t handle, mask &= ~(DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_NO_MOVE); - ret = drm_bo_do_validate(bo, flags, mask, hint, fence_class, - no_wait, rep); + ret = drm_bo_do_validate(bo, flags, mask, hint, fence_class, rep); if (!ret && bo_rep) *bo_rep = bo; -- cgit v1.2.3 From 5f23519b14e54823c94f5db5ad81e6bd5ffd3877 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 14 Dec 2007 12:45:55 -0800 Subject: Document drm_bo_handle_validate. Match drm_bo_do_validate parameter order. Document parameters and usage for drm_bo_handle_validate. Change parameter order to match drm_bo_do_validate (fence_class has been moved to after flags, hint and mask values). Existing users of this function have been changed, but out-of-tree users must be modified separately. --- linux-core/drm_bo.c | 67 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 17 deletions(-) (limited to 'linux-core/drm_bo.c') diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index d7a507ab..aa613d7a 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -1502,27 +1502,29 @@ static int drm_buffer_object_validate(struct drm_buffer_object *bo, return 0; } -/* +/** * drm_bo_do_validate * - * 'validate' a buffer object. This changes where the buffer is - * located, along with changing access modes. + * @bo: the buffer object * - * flags access rights, mapping parameters and cacheability. See - * the DRM_BO_FLAG_* values in drm.h + * @flags: access rights, mapping parameters and cacheability. See + * the DRM_BO_FLAG_* values in drm.h * - * mask which flag values to change; this allows callers to modify - * things without knowing the current state of other flags. + * @mask: Which flag values to change; this allows callers to modify + * things without knowing the current state of other flags. * - * hint changes the proceedure for this operation, see the DRM_BO_HINT_* - * values in drm.h. + * @hint: changes the proceedure for this operation, see the DRM_BO_HINT_* + * values in drm.h. * - * fence_class a driver-specific way of doing fences. Presumably, this - * would be used if the driver had more than one submission and - * fencing mechanism. At this point, there isn't any use of this - * from the user mode code. + * @fence_class: a driver-specific way of doing fences. Presumably, + * this would be used if the driver had more than one submission and + * fencing mechanism. At this point, there isn't any use of this + * from the user mode code. * - * rep will be stuffed with the reply from validation + * @rep: To be stuffed with the reply from validation + * + * 'validate' a buffer object. This changes where the buffer is + * located, along with changing access modes. */ int drm_bo_do_validate(struct drm_buffer_object *bo, @@ -1558,11 +1560,42 @@ out: } EXPORT_SYMBOL(drm_bo_do_validate); +/** + * drm_bo_handle_validate + * + * @file_priv: the drm file private, used to get a handle to the user context + * + * @handle: the buffer object handle + * + * @flags: access rights, mapping parameters and cacheability. See + * the DRM_BO_FLAG_* values in drm.h + * + * @mask: Which flag values to change; this allows callers to modify + * things without knowing the current state of other flags. + * + * @hint: changes the proceedure for this operation, see the DRM_BO_HINT_* + * values in drm.h. + * + * @fence_class: a driver-specific way of doing fences. Presumably, + * this would be used if the driver had more than one submission and + * fencing mechanism. At this point, there isn't any use of this + * from the user mode code. + * + * @use_old_fence_class: don't change fence class, pull it from the buffer object + * + * @rep: To be stuffed with the reply from validation + * + * @bp_rep: To be stuffed with the buffer object pointer + * + * Perform drm_bo_do_validate on a buffer referenced by a user-space handle. + * Some permissions checking is done on the parameters, otherwise this + * is a thin wrapper. + */ int drm_bo_handle_validate(struct drm_file *file_priv, uint32_t handle, - uint32_t fence_class, uint64_t flags, uint64_t mask, uint32_t hint, + uint32_t fence_class, int use_old_fence_class, struct drm_bo_info_rep *rep, struct drm_buffer_object **bo_rep) @@ -1818,11 +1851,11 @@ int drm_bo_setstatus_ioctl(struct drm_device *dev, if (ret) return ret; - ret = drm_bo_handle_validate(file_priv, req->handle, req->fence_class, + ret = drm_bo_handle_validate(file_priv, req->handle, req->flags, req->mask, req->hint | DRM_BO_HINT_DONT_FENCE, - 1, + req->fence_class, 1, rep, NULL); (void) drm_bo_read_unlock(&dev->bm.bm_lock); -- cgit v1.2.3 From 7461519fed25f6d63415a9dd4b915c6cc668a69c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 14 Dec 2007 12:49:22 -0800 Subject: Document fence_class mess in drm_bo_setstatus_ioctl drmBOSetStatus does not bother to set the fence_class parameter. Fortunately, drm_bo_setstatus_ioctl doesn't end up using it as it calls drm_bo_handle_validate with use_old_fence_class = 1. --- linux-core/drm_bo.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'linux-core/drm_bo.c') diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index aa613d7a..1ce86978 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -1851,6 +1851,12 @@ int drm_bo_setstatus_ioctl(struct drm_device *dev, if (ret) return ret; + /* + * validate the buffer. note that 'fence_class' will be unused + * as we pass use_old_fence_class=1 here. Note also that + * the libdrm API doesn't pass fence_class to the kernel, + * so it's a good thing it isn't used here. + */ ret = drm_bo_handle_validate(file_priv, req->handle, req->flags, req->mask, -- cgit v1.2.3 From 9d17373ffbba3cc4ee5f63ff02ff24d48ab99fe0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 14 Dec 2007 13:19:09 -0800 Subject: Document drm_buffer_object_validate function. Just add documentation for this function, no code changes. --- linux-core/drm_bo.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'linux-core/drm_bo.c') diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index 1ce86978..7033a8ba 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -1372,8 +1372,25 @@ static int drm_bo_mem_compat(struct drm_bo_mem_reg *mem) return 1; } -/* - * bo locked. +/** + * drm_buffer_object_validate: + * + * @bo: the buffer object to modify + * + * @fence_class: the new fence class covering this buffer + * + * @move_unfenced: a boolean indicating whether switching the + * memory space of this buffer should cause the buffer to + * be placed on the unfenced list. + * + * @no_wait: whether this function should return -EBUSY instead + * of waiting. + * + * Change buffer access parameters. This can involve moving + * the buffer to the correct memory type, pinning the buffer + * or changing the class/type of fence covering this buffer + * + * Must be called with bo locked. */ static int drm_buffer_object_validate(struct drm_buffer_object *bo, @@ -1503,7 +1520,7 @@ static int drm_buffer_object_validate(struct drm_buffer_object *bo, } /** - * drm_bo_do_validate + * drm_bo_do_validate: * * @bo: the buffer object * -- cgit v1.2.3 From 6d44f48002c19d67187adb660ef74dd1870d52c2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 16 Dec 2007 00:54:25 -0800 Subject: Clean up and document drm_ttm.c APIs. drm_bind_ttm -> drm_ttm_bind. Aside from changing drm_bind_ttm to drm_ttm_bind, this patch adds only documentation and fixes the functions inside drm_ttm.c to all be prefixed with drm_ttm_. --- linux-core/drm_bo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linux-core/drm_bo.c') diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index 7033a8ba..eced94ea 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -199,7 +199,7 @@ static int drm_bo_handle_move_mem(struct drm_buffer_object *bo, goto out_err; if (mem->mem_type != DRM_BO_MEM_LOCAL) { - ret = drm_bind_ttm(bo->ttm, mem); + ret = drm_ttm_bind(bo->ttm, mem); if (ret) goto out_err; } -- cgit v1.2.3 From 881ee70ab7bab5d6f6140dc9bf1e19c7b5844084 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 16 Dec 2007 01:12:07 -0800 Subject: Move dummy_read_page from drm_ttm_set_user to drm_ttm_create. I'm hoping to use the dummy_read_page for kernel allocated buffers to avoid allocating extra pages for read-only buffers (like vertex and batch buffers). This also eliminates the 'write' parameter to drm_ttm_set_user and just has DRM_TTM_PAGE_WRITE passed into drm_ttm_create. --- linux-core/drm_bo.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'linux-core/drm_bo.c') diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index eced94ea..e7b9c5b1 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -137,27 +137,32 @@ static int drm_bo_add_ttm(struct drm_buffer_object *bo) { struct drm_device *dev = bo->dev; int ret = 0; + uint32_t page_flags = 0; DRM_ASSERT_LOCKED(&bo->mutex); bo->ttm = NULL; + if (bo->mem.mask & DRM_BO_FLAG_WRITE) + page_flags |= DRM_TTM_PAGE_WRITE; + switch (bo->type) { case drm_bo_type_dc: case drm_bo_type_kernel: - bo->ttm = drm_ttm_create(dev, bo->num_pages << PAGE_SHIFT, 0); + bo->ttm = drm_ttm_create(dev, bo->num_pages << PAGE_SHIFT, + page_flags, dev->bm.dummy_read_page); if (!bo->ttm) ret = -ENOMEM; break; case drm_bo_type_user: - bo->ttm = drm_ttm_create(dev, bo->num_pages << PAGE_SHIFT, DRM_TTM_PAGE_USER); + bo->ttm = drm_ttm_create(dev, bo->num_pages << PAGE_SHIFT, + page_flags | DRM_TTM_PAGE_USER, + dev->bm.dummy_read_page); if (!bo->ttm) ret = -ENOMEM; ret = drm_ttm_set_user(bo->ttm, current, - bo->mem.mask & DRM_BO_FLAG_WRITE, bo->buffer_start, - bo->num_pages, - dev->bm.dummy_read_page); + bo->num_pages); if (ret) return ret; -- cgit v1.2.3 From d1187641d64f442968a3b9ea6a19de6cdd45acd4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 16 Dec 2007 20:16:50 -0800 Subject: Rename inappropriately named 'mask' fields to 'proposed_flags' instead. Flags pending validation were stored in a misleadingly named field, 'mask'. As 'mask' is already used to indicate pieces of a flags field which are changing, it seems better to use a name reflecting the actual purpose of this field. I chose 'proposed_flags' as they may not actually end up in 'flags', and in an case will be modified when they are moved over. This affects the API, but not ABI of the user-mode interface. --- linux-core/drm_bo.c | 111 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 44 deletions(-) (limited to 'linux-core/drm_bo.c') diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index e7b9c5b1..171c074a 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -80,7 +80,7 @@ void drm_bo_add_to_lru(struct drm_buffer_object *bo) DRM_ASSERT_LOCKED(&bo->dev->struct_mutex); - if (!(bo->mem.mask & (DRM_BO_FLAG_NO_MOVE | DRM_BO_FLAG_NO_EVICT)) + if (!(bo->mem.proposed_flags & (DRM_BO_FLAG_NO_MOVE | DRM_BO_FLAG_NO_EVICT)) || bo->mem.mem_type != bo->pinned_mem_type) { man = &bo->dev->bm.man[bo->mem.mem_type]; list_add_tail(&bo->lru, &man->lru); @@ -142,7 +142,7 @@ static int drm_bo_add_ttm(struct drm_buffer_object *bo) DRM_ASSERT_LOCKED(&bo->mutex); bo->ttm = NULL; - if (bo->mem.mask & DRM_BO_FLAG_WRITE) + if (bo->mem.proposed_flags & DRM_BO_FLAG_WRITE) page_flags |= DRM_TTM_PAGE_WRITE; switch (bo->type) { @@ -214,11 +214,11 @@ static int drm_bo_handle_move_mem(struct drm_buffer_object *bo, struct drm_bo_mem_reg *old_mem = &bo->mem; uint64_t save_flags = old_mem->flags; - uint64_t save_mask = old_mem->mask; + uint64_t save_proposed_flags = old_mem->proposed_flags; *old_mem = *mem; mem->mm_node = NULL; - old_mem->mask = save_mask; + old_mem->proposed_flags = save_proposed_flags; DRM_FLAG_MASKED(save_flags, mem->flags, DRM_BO_MASK_MEMTYPE); } else if (!(old_man->flags & _DRM_FLAG_MEMTYPE_FIXED) && @@ -708,7 +708,7 @@ static int drm_bo_evict(struct drm_buffer_object *bo, unsigned mem_type, evict_mem.mm_node = NULL; evict_mem = bo->mem; - evict_mem.mask = dev->driver->bo_driver->evict_mask(bo); + evict_mem.proposed_flags = dev->driver->bo_driver->evict_flags(bo); ret = drm_bo_mem_space(bo, &evict_mem, no_wait); if (ret) { @@ -872,7 +872,7 @@ int drm_bo_mem_space(struct drm_buffer_object *bo, type_ok = drm_bo_mt_compatible(man, bo->type == drm_bo_type_user, - mem_type, mem->mask, + mem_type, mem->proposed_flags, &cur_flags); if (!type_ok) @@ -924,7 +924,7 @@ int drm_bo_mem_space(struct drm_buffer_object *bo, if (!drm_bo_mt_compatible(man, bo->type == drm_bo_type_user, mem_type, - mem->mask, + mem->proposed_flags, &cur_flags)) continue; @@ -944,11 +944,25 @@ int drm_bo_mem_space(struct drm_buffer_object *bo, } EXPORT_SYMBOL(drm_bo_mem_space); -static int drm_bo_new_mask(struct drm_buffer_object *bo, - uint64_t new_flags, uint64_t used_mask) +/* + * drm_bo_propose_flags: + * + * @bo: the buffer object getting new flags + * + * @new_flags: the new set of proposed flag bits + * + * @new_mask: the mask of bits changed in new_flags + * + * Modify the proposed_flag bits in @bo + */ +static int drm_bo_modify_proposed_flags (struct drm_buffer_object *bo, + uint64_t new_flags, uint64_t new_mask) { - uint32_t new_props; + uint32_t new_access; + /* Copy unchanging bits from existing proposed_flags */ + DRM_FLAG_MASKED(new_flags, bo->mem.proposed_flags, ~new_mask); + if (bo->type == drm_bo_type_user && ((new_flags & (DRM_BO_FLAG_CACHED | DRM_BO_FLAG_FORCE_CACHING)) != (DRM_BO_FLAG_CACHED | DRM_BO_FLAG_FORCE_CACHING))) { @@ -956,7 +970,7 @@ static int drm_bo_new_mask(struct drm_buffer_object *bo, return -EINVAL; } - if ((used_mask & DRM_BO_FLAG_NO_EVICT) && !DRM_SUSER(DRM_CURPROC)) { + if ((new_mask & DRM_BO_FLAG_NO_EVICT) && !DRM_SUSER(DRM_CURPROC)) { DRM_ERROR("DRM_BO_FLAG_NO_EVICT is only available to priviliged processes.\n"); return -EPERM; } @@ -966,15 +980,15 @@ static int drm_bo_new_mask(struct drm_buffer_object *bo, return -EPERM; } - new_props = new_flags & (DRM_BO_FLAG_EXE | DRM_BO_FLAG_WRITE | - DRM_BO_FLAG_READ); + new_access = new_flags & (DRM_BO_FLAG_EXE | DRM_BO_FLAG_WRITE | + DRM_BO_FLAG_READ); - if (!new_props) { + if (new_access == 0) { DRM_ERROR("Invalid buffer object rwx properties\n"); return -EINVAL; } - bo->mem.mask = new_flags; + bo->mem.proposed_flags = new_flags; return 0; } @@ -1109,8 +1123,8 @@ static int drm_bo_wait_unfenced(struct drm_buffer_object *bo, int no_wait, ret = 0; mutex_unlock(&bo->mutex); - DRM_WAIT_ON(ret, bo->event_queue, 3 * DRM_HZ, - !drm_bo_check_unfenced(bo)); + DRM_WAIT_ON (ret, bo->event_queue, 3 * DRM_HZ, + !drm_bo_check_unfenced(bo)); mutex_lock(&bo->mutex); if (ret == -EINTR) return -EAGAIN; @@ -1146,7 +1160,7 @@ static void drm_bo_fill_rep_arg(struct drm_buffer_object *bo, else rep->arg_handle = 0; - rep->mask = bo->mem.mask; + rep->proposed_flags = bo->mem.proposed_flags; rep->buffer_start = bo->buffer_start; rep->fence_flags = bo->fence_type; rep->rep_flags = 0; @@ -1292,7 +1306,7 @@ static void drm_buffer_user_object_unmap(struct drm_file *file_priv, /* * bo->mutex locked. - * Note that new_mem_flags are NOT transferred to the bo->mem.mask. + * Note that new_mem_flags are NOT transferred to the bo->mem.proposed_flags. */ int drm_bo_move_buffer(struct drm_buffer_object *bo, uint64_t new_mem_flags, @@ -1318,7 +1332,7 @@ int drm_bo_move_buffer(struct drm_buffer_object *bo, uint64_t new_mem_flags, mem.num_pages = bo->num_pages; mem.size = mem.num_pages << PAGE_SHIFT; - mem.mask = new_mem_flags; + mem.proposed_flags = new_mem_flags; mem.page_alignment = bo->mem.page_alignment; mutex_lock(&bm->evict_mutex); @@ -1361,18 +1375,18 @@ out_unlock: static int drm_bo_mem_compat(struct drm_bo_mem_reg *mem) { - uint32_t flag_diff = (mem->mask ^ mem->flags); + uint32_t flag_diff = (mem->proposed_flags ^ mem->flags); - if ((mem->mask & mem->flags & DRM_BO_MASK_MEM) == 0) + if ((mem->proposed_flags & mem->flags & DRM_BO_MASK_MEM) == 0) return 0; if ((flag_diff & DRM_BO_FLAG_CACHED) && - (/* !(mem->mask & DRM_BO_FLAG_CACHED) ||*/ - (mem->mask & DRM_BO_FLAG_FORCE_CACHING))) + (/* !(mem->proposed_flags & DRM_BO_FLAG_CACHED) ||*/ + (mem->proposed_flags & DRM_BO_FLAG_FORCE_CACHING))) return 0; if ((flag_diff & DRM_BO_FLAG_MAPPABLE) && - ((mem->mask & DRM_BO_FLAG_MAPPABLE) || - (mem->mask & DRM_BO_FLAG_FORCE_MAPPABLE))) + ((mem->proposed_flags & DRM_BO_FLAG_MAPPABLE) || + (mem->proposed_flags & DRM_BO_FLAG_FORCE_MAPPABLE))) return 0; return 1; } @@ -1408,8 +1422,8 @@ static int drm_buffer_object_validate(struct drm_buffer_object *bo, uint32_t ftype; int ret; - DRM_DEBUG("New flags 0x%016llx, Old flags 0x%016llx\n", - (unsigned long long) bo->mem.mask, + DRM_DEBUG("Proposed flags 0x%016llx, Old flags 0x%016llx\n", + (unsigned long long) bo->mem.proposed_flags, (unsigned long long) bo->mem.flags); ret = driver->fence_type(bo, &fence_class, &ftype); @@ -1450,7 +1464,7 @@ static int drm_buffer_object_validate(struct drm_buffer_object *bo, */ if (!drm_bo_mem_compat(&bo->mem)) { - ret = drm_bo_move_buffer(bo, bo->mem.mask, no_wait, + ret = drm_bo_move_buffer(bo, bo->mem.proposed_flags, no_wait, move_unfenced); if (ret) { if (ret != -EAGAIN) @@ -1463,7 +1477,7 @@ static int drm_buffer_object_validate(struct drm_buffer_object *bo, * Pinned buffers. */ - if (bo->mem.mask & (DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_NO_MOVE)) { + if (bo->mem.proposed_flags & (DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_NO_MOVE)) { bo->pinned_mem_type = bo->mem.mem_type; mutex_lock(&dev->struct_mutex); list_del_init(&bo->pinned_lru); @@ -1499,7 +1513,13 @@ static int drm_buffer_object_validate(struct drm_buffer_object *bo, if (ret) return ret; } - DRM_FLAG_MASKED(bo->mem.flags, bo->mem.mask, ~DRM_BO_MASK_MEMTYPE); + /* + * Validation has succeeded, move the access and other + * non-mapping-related flag bits from the proposed flags to + * the active flags + */ + + DRM_FLAG_MASKED(bo->mem.flags, bo->mem.proposed_flags, ~DRM_BO_MASK_MEMTYPE); /* * Finally, adjust lru to be sure. @@ -1563,9 +1583,7 @@ int drm_bo_do_validate(struct drm_buffer_object *bo, if (ret) goto out; - - DRM_FLAG_MASKED(flags, bo->mem.mask, ~mask); - ret = drm_bo_new_mask(bo, flags, mask); + ret = drm_bo_modify_proposed_flags (bo, flags, mask); if (ret) goto out; @@ -1712,7 +1730,7 @@ out: int drm_buffer_object_create(struct drm_device *dev, unsigned long size, enum drm_bo_type type, - uint64_t mask, + uint64_t flags, uint32_t hint, uint32_t page_alignment, unsigned long buffer_start, @@ -1757,12 +1775,14 @@ int drm_buffer_object_create(struct drm_device *dev, bo->mem.page_alignment = page_alignment; bo->buffer_start = buffer_start & PAGE_MASK; bo->priv_flags = 0; - bo->mem.flags = DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_CACHED | - DRM_BO_FLAG_MAPPABLE; - bo->mem.mask = DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_CACHED | - DRM_BO_FLAG_MAPPABLE; + bo->mem.flags = (DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_CACHED | + DRM_BO_FLAG_MAPPABLE); + bo->mem.proposed_flags = 0; atomic_inc(&bm->count); - ret = drm_bo_new_mask(bo, mask, mask); + /* + * Use drm_bo_modify_proposed_flags to error-check the proposed flags + */ + ret = drm_bo_modify_proposed_flags (bo, flags, flags); if (ret) goto out_err; @@ -1831,18 +1851,21 @@ int drm_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *fil bo_type = (req->buffer_start) ? drm_bo_type_user : drm_bo_type_dc; + /* + * User buffers cannot be shared + */ if (bo_type == drm_bo_type_user) - req->mask &= ~DRM_BO_FLAG_SHAREABLE; + req->flags &= ~DRM_BO_FLAG_SHAREABLE; ret = drm_buffer_object_create(file_priv->head->dev, - req->size, bo_type, req->mask, + req->size, bo_type, req->flags, req->hint, req->page_alignment, req->buffer_start, &entry); if (ret) goto out; ret = drm_bo_add_user_object(file_priv, entry, - req->mask & DRM_BO_FLAG_SHAREABLE); + req->flags & DRM_BO_FLAG_SHAREABLE); if (ret) { drm_bo_usage_deref_unlocked(&entry); goto out; @@ -2034,7 +2057,7 @@ static int drm_bo_leave_list(struct drm_buffer_object *bo, DRM_ERROR("A DRM_BO_NO_EVICT buffer present at " "cleanup. Removing flag and evicting.\n"); bo->mem.flags &= ~DRM_BO_FLAG_NO_EVICT; - bo->mem.mask &= ~DRM_BO_FLAG_NO_EVICT; + bo->mem.proposed_flags &= ~DRM_BO_FLAG_NO_EVICT; } if (bo->mem.mem_type == mem_type) -- cgit v1.2.3 From da3601e43ae75695f3b080904b1e090c8eb1cd8e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 16 Dec 2007 22:00:45 -0800 Subject: Change drm_bo_type_dc to drm_bo_type_device and comment usage of this value. I couldn't figure out what drm_bo_type_dc was for; Dave Airlie finally clued me in that it was the 'normal' buffer objects with kernel allocated pages that could be mmapped from the drm device file. I thought that 'drm_bo_type_device' was a more descriptive name. I also added a bunch of comments describing the use of the type enum values and the functions that use them. --- linux-core/drm_bo.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'linux-core/drm_bo.c') diff --git a/linux-core/drm_bo.c b/linux-core/drm_bo.c index 171c074a..df10e12b 100644 --- a/linux-core/drm_bo.c +++ b/linux-core/drm_bo.c @@ -146,7 +146,7 @@ static int drm_bo_add_ttm(struct drm_buffer_object *bo) page_flags |= DRM_TTM_PAGE_WRITE; switch (bo->type) { - case drm_bo_type_dc: + case drm_bo_type_device: case drm_bo_type_kernel: bo->ttm = drm_ttm_create(dev, bo->num_pages << PAGE_SHIFT, page_flags, dev->bm.dummy_read_page); @@ -1155,7 +1155,12 @@ static void drm_bo_fill_rep_arg(struct drm_buffer_object *bo, rep->size = bo->num_pages * PAGE_SIZE; rep->offset = bo->offset; - if (bo->type == drm_bo_type_dc) + /* + * drm_bo_type_device buffers have user-visible + * handles which can be used to share across + * processes. Hand that back to the application + */ + if (bo->type == drm_bo_type_device) rep->arg_handle = bo->map_list.user_token; else rep->arg_handle = 0; @@ -1786,7 +1791,12 @@ int drm_buffer_object_create(struct drm_device *dev, if (ret) goto out_err; - if (bo->type == drm_bo_type_dc) { + /* + * For drm_bo_type_device buffers, allocate + * address space from the device so that applications + * can mmap the buffer from there + */ + if (bo->type == drm_bo_type_device) { mutex_lock(&dev->struct_mutex); ret = drm_bo_setup_vm_locked(bo); mutex_unlock(&dev->struct_mutex); @@ -1849,7 +1859,12 @@ int drm_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *fil return -EINVAL; } - bo_type = (req->buffer_start) ? drm_bo_type_user : drm_bo_type_dc; + /* + * If the buffer creation request comes in with a starting address, + * that points at the desired user pages to map. Otherwise, create + * a drm_bo_type_device buffer, which uses pages allocated from the kernel + */ + bo_type = (req->buffer_start) ? drm_bo_type_user : drm_bo_type_device; /* * User buffers cannot be shared @@ -2607,6 +2622,14 @@ void drm_bo_unmap_virtual(struct drm_buffer_object *bo) unmap_mapping_range(dev->dev_mapping, offset, holelen, 1); } +/** + * drm_bo_takedown_vm_locked: + * + * @bo: the buffer object to remove any drm device mapping + * + * Remove any associated vm mapping on the drm device node that + * would have been created for a drm_bo_type_device buffer + */ static void drm_bo_takedown_vm_locked(struct drm_buffer_object *bo) { struct drm_map_list *list; @@ -2614,7 +2637,7 @@ static void drm_bo_takedown_vm_locked(struct drm_buffer_object *bo) struct drm_device *dev = bo->dev; DRM_ASSERT_LOCKED(&dev->struct_mutex); - if (bo->type != drm_bo_type_dc) + if (bo->type != drm_bo_type_device) return; list = &bo->map_list; @@ -2637,6 +2660,16 @@ static void drm_bo_takedown_vm_locked(struct drm_buffer_object *bo) drm_bo_usage_deref_locked(&bo); } +/** + * drm_bo_setup_vm_locked: + * + * @bo: the buffer to allocate address space for + * + * Allocate address space in the drm device so that applications + * can mmap the buffer and access the contents. This only + * applies to drm_bo_type_device objects as others are not + * placed in the drm device address space. + */ static int drm_bo_setup_vm_locked(struct drm_buffer_object *bo) { struct drm_map_list *list = &bo->map_list; -- cgit v1.2.3