Lines Matching +full:buffer +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0 OR MIT
4 * Copyright 2015-2023 VMware, Inc., Palo Alto, CA., USA
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
37 * Size of inline command buffers. Try to make sure that a page size is a
38 * multiple of the DMA pool allocation size.
42 (1024 - ALIGN(sizeof(SVGACBHeader), VMW_CMDBUF_INLINE_ALIGN))
45 * struct vmw_cmdbuf_context - Command buffer context queues
63 * struct vmw_cmdbuf_man - Command buffer manager
65 * @cur_mutex: Mutex protecting the command buffer used for incremental small
68 * main pool buffer space.
72 * @work: A struct work_struct implementeing command buffer error handling.
75 * @ctx: Array of command buffer context queues. The queues and the context
79 * @mm: Range manager for the command buffer space. Manager allocations and
81 * @cmd_space: Buffer object for the command buffer space, unless we were
83 * @map: Pointer to command buffer space. May be a mapped buffer object or
85 * @cur: Command buffer for small kernel command submissions. Protected by
88 * @default_size: Default size for the @cur command buffer. Immutable.
89 * @max_hw_submitted: Max number of in-flight command buffers the device can
92 * @headers: Pool of DMA memory for device command buffer headers.
94 * @dheaders: Pool of DMA memory for device command buffer headers with trailing
96 * @alloc_queue: Wait queue for processes waiting to allocate command buffer
98 * @idle_queue: Wait queue for processes waiting for command buffer idle.
101 * @using_mob: Whether the command buffer space is a MOB or a contigous DMA
105 * @handle: DMA address handle for the command buffer space if @using_mob is
107 * @size: The size of the command buffer space. Immutable.
134 size_t size; member
139 * struct vmw_cmdbuf_header - Command buffer metadata
141 * @man: The command buffer manager.
142 * @cb_header: Device command buffer header, allocated from a DMA pool.
143 * @cb_context: The device command buffer context.
147 * buffer submission.
148 * @cmd: Pointer to the command buffer space of this buffer.
149 * @size: Size of the command buffer space of this buffer.
150 * @reserved: Reserved space of this buffer.
151 * @inline_space: Whether inline command buffer space is used.
161 size_t size; member
167 * struct vmw_cmdbuf_dheader - Device command buffer header with inline
168 * command buffer space.
170 * @cb_header: Device command buffer header.
171 * @cmd: Inline command buffer space.
179 * struct vmw_cmdbuf_alloc_info - Command buffer space allocation metadata
181 * @page_size: Size of requested command buffer space in pages.
191 /* Loop over each context in the command buffer manager. */
193 for (_i = 0, _ctx = &(_man)->ctx[0]; (_i) < (_man)->num_contexts; \
201 * vmw_cmdbuf_cur_lock - Helper to lock the cur_mutex.
209 if (mutex_lock_interruptible(&man->cur_mutex)) in vmw_cmdbuf_cur_lock()
210 return -ERESTARTSYS; in vmw_cmdbuf_cur_lock()
212 mutex_lock(&man->cur_mutex); in vmw_cmdbuf_cur_lock()
219 * vmw_cmdbuf_cur_unlock - Helper to unlock the cur_mutex.
225 mutex_unlock(&man->cur_mutex); in vmw_cmdbuf_cur_unlock()
229 * vmw_cmdbuf_header_inline_free - Free a struct vmw_cmdbuf_header that has
239 if (WARN_ON_ONCE(!header->inline_space)) in vmw_cmdbuf_header_inline_free()
242 dheader = container_of(header->cb_header, struct vmw_cmdbuf_dheader, in vmw_cmdbuf_header_inline_free()
244 dma_pool_free(header->man->dheaders, dheader, header->handle); in vmw_cmdbuf_header_inline_free()
249 * __vmw_cmdbuf_header_free - Free a struct vmw_cmdbuf_header and its
258 struct vmw_cmdbuf_man *man = header->man; in __vmw_cmdbuf_header_free()
260 lockdep_assert_held_once(&man->lock); in __vmw_cmdbuf_header_free()
262 if (header->inline_space) { in __vmw_cmdbuf_header_free()
267 drm_mm_remove_node(&header->node); in __vmw_cmdbuf_header_free()
268 wake_up_all(&man->alloc_queue); in __vmw_cmdbuf_header_free()
269 if (header->cb_header) in __vmw_cmdbuf_header_free()
270 dma_pool_free(man->headers, header->cb_header, in __vmw_cmdbuf_header_free()
271 header->handle); in __vmw_cmdbuf_header_free()
276 * vmw_cmdbuf_header_free - Free a struct vmw_cmdbuf_header and its
283 struct vmw_cmdbuf_man *man = header->man; in vmw_cmdbuf_header_free()
286 if (header->inline_space) { in vmw_cmdbuf_header_free()
290 spin_lock(&man->lock); in vmw_cmdbuf_header_free()
292 spin_unlock(&man->lock); in vmw_cmdbuf_header_free()
297 * vmw_cmdbuf_header_submit: Submit a command buffer to hardware.
299 * @header: The header of the buffer to submit.
303 struct vmw_cmdbuf_man *man = header->man; in vmw_cmdbuf_header_submit()
306 val = upper_32_bits(header->handle); in vmw_cmdbuf_header_submit()
307 vmw_write(man->dev_priv, SVGA_REG_COMMAND_HIGH, val); in vmw_cmdbuf_header_submit()
309 val = lower_32_bits(header->handle); in vmw_cmdbuf_header_submit()
310 val |= header->cb_context & SVGA_CB_CONTEXT_MASK; in vmw_cmdbuf_header_submit()
311 vmw_write(man->dev_priv, SVGA_REG_COMMAND_LOW, val); in vmw_cmdbuf_header_submit()
313 return header->cb_header->status; in vmw_cmdbuf_header_submit()
317 * vmw_cmdbuf_ctx_init: Initialize a command buffer context.
319 * @ctx: The command buffer context to initialize
323 INIT_LIST_HEAD(&ctx->hw_submitted); in vmw_cmdbuf_ctx_init()
324 INIT_LIST_HEAD(&ctx->submitted); in vmw_cmdbuf_ctx_init()
325 INIT_LIST_HEAD(&ctx->preempted); in vmw_cmdbuf_ctx_init()
326 ctx->num_hw_submitted = 0; in vmw_cmdbuf_ctx_init()
330 * vmw_cmdbuf_ctx_submit: Submit command buffers from a command buffer
333 * @man: The command buffer manager.
334 * @ctx: The command buffer context.
342 while (ctx->num_hw_submitted < man->max_hw_submitted && in vmw_cmdbuf_ctx_submit()
343 !list_empty(&ctx->submitted) && in vmw_cmdbuf_ctx_submit()
344 !ctx->block_submission) { in vmw_cmdbuf_ctx_submit()
348 entry = list_first_entry(&ctx->submitted, in vmw_cmdbuf_ctx_submit()
356 entry->cb_header->status = SVGA_CB_STATUS_NONE; in vmw_cmdbuf_ctx_submit()
360 list_move_tail(&entry->list, &ctx->hw_submitted); in vmw_cmdbuf_ctx_submit()
361 ctx->num_hw_submitted++; in vmw_cmdbuf_ctx_submit()
367 * vmw_cmdbuf_ctx_process - Process a command buffer context.
369 * @man: The command buffer manager.
370 * @ctx: The command buffer context.
371 * @notempty: Pass back count of non-empty command submitted lists.
385 list_for_each_entry_safe(entry, next, &ctx->hw_submitted, list) { in vmw_cmdbuf_ctx_process()
386 SVGACBStatus status = entry->cb_header->status; in vmw_cmdbuf_ctx_process()
391 list_del(&entry->list); in vmw_cmdbuf_ctx_process()
392 wake_up_all(&man->idle_queue); in vmw_cmdbuf_ctx_process()
393 ctx->num_hw_submitted--; in vmw_cmdbuf_ctx_process()
399 WARN_ONCE(true, "Command buffer error.\n"); in vmw_cmdbuf_ctx_process()
400 entry->cb_header->status = SVGA_CB_STATUS_NONE; in vmw_cmdbuf_ctx_process()
401 list_add_tail(&entry->list, &man->error); in vmw_cmdbuf_ctx_process()
402 schedule_work(&man->work); in vmw_cmdbuf_ctx_process()
405 entry->cb_header->status = SVGA_CB_STATUS_NONE; in vmw_cmdbuf_ctx_process()
406 list_add_tail(&entry->list, &ctx->preempted); in vmw_cmdbuf_ctx_process()
409 WARN_ONCE(true, "Command buffer header error.\n"); in vmw_cmdbuf_ctx_process()
413 WARN_ONCE(true, "Undefined command buffer status.\n"); in vmw_cmdbuf_ctx_process()
420 if (!list_empty(&ctx->submitted)) in vmw_cmdbuf_ctx_process()
425 * vmw_cmdbuf_man_process - Process all command buffer contexts and
428 * @man: The command buffer manager.
445 if (man->irq_on && !notempty) { in vmw_cmdbuf_man_process()
446 vmw_generic_waiter_remove(man->dev_priv, in vmw_cmdbuf_man_process()
448 &man->dev_priv->cmdbuf_waiters); in vmw_cmdbuf_man_process()
449 man->irq_on = false; in vmw_cmdbuf_man_process()
450 } else if (!man->irq_on && notempty) { in vmw_cmdbuf_man_process()
451 vmw_generic_waiter_add(man->dev_priv, in vmw_cmdbuf_man_process()
453 &man->dev_priv->cmdbuf_waiters); in vmw_cmdbuf_man_process()
454 man->irq_on = true; in vmw_cmdbuf_man_process()
462 * vmw_cmdbuf_ctx_add - Schedule a command buffer for submission on a
463 * command buffer context
465 * @man: The command buffer manager.
466 * @header: The header of the buffer to submit.
467 * @cb_context: The command buffer context to use.
470 * buffer context identified by @cb_context. It then calls the command buffer
471 * manager processing to potentially submit the buffer to hardware.
472 * @man->lock needs to be held when calling this function.
478 if (!(header->cb_header->flags & SVGA_CB_FLAG_DX_CONTEXT)) in vmw_cmdbuf_ctx_add()
479 header->cb_header->dxContext = 0; in vmw_cmdbuf_ctx_add()
480 header->cb_context = cb_context; in vmw_cmdbuf_ctx_add()
481 list_add_tail(&header->list, &man->ctx[cb_context].submitted); in vmw_cmdbuf_ctx_add()
487 * vmw_cmdbuf_irqthread - The main part of the command buffer interrupt
490 * @man: Pointer to the command buffer manager.
493 * command buffer processor to free finished buffers and submit any
498 spin_lock(&man->lock); in vmw_cmdbuf_irqthread()
500 spin_unlock(&man->lock); in vmw_cmdbuf_irqthread()
504 * vmw_cmdbuf_work_func - The deferred work function that handles
505 * command buffer errors.
509 * Restarting the command buffer context after an error requires process
527 mutex_lock(&man->error_mutex); in vmw_cmdbuf_work_func()
528 spin_lock(&man->lock); in vmw_cmdbuf_work_func()
529 list_for_each_entry_safe(entry, next, &man->error, list) { in vmw_cmdbuf_work_func()
530 SVGACBHeader *cb_hdr = entry->cb_header; in vmw_cmdbuf_work_func()
532 (entry->cmd + cb_hdr->errorOffset); in vmw_cmdbuf_work_func()
536 list_del_init(&entry->list); in vmw_cmdbuf_work_func()
541 VMW_DEBUG_USER("Command buffer offset is %lu\n", in vmw_cmdbuf_work_func()
542 (unsigned long) cb_hdr->errorOffset); in vmw_cmdbuf_work_func()
550 VMW_DEBUG_USER("Command buffer offset is %lu\n", in vmw_cmdbuf_work_func()
551 (unsigned long) cb_hdr->errorOffset); in vmw_cmdbuf_work_func()
552 VMW_DEBUG_USER("Command size is %lu\n", in vmw_cmdbuf_work_func()
555 new_start_offset = cb_hdr->errorOffset + error_cmd_size; in vmw_cmdbuf_work_func()
557 if (new_start_offset >= cb_hdr->length) { in vmw_cmdbuf_work_func()
563 if (man->using_mob) in vmw_cmdbuf_work_func()
564 cb_hdr->ptr.mob.mobOffset += new_start_offset; in vmw_cmdbuf_work_func()
566 cb_hdr->ptr.pa += (u64) new_start_offset; in vmw_cmdbuf_work_func()
568 entry->cmd += new_start_offset; in vmw_cmdbuf_work_func()
569 cb_hdr->length -= new_start_offset; in vmw_cmdbuf_work_func()
570 cb_hdr->errorOffset = 0; in vmw_cmdbuf_work_func()
571 cb_hdr->offset = 0; in vmw_cmdbuf_work_func()
573 list_add_tail(&entry->list, &restart_head[entry->cb_context]); in vmw_cmdbuf_work_func()
577 man->ctx[i].block_submission = true; in vmw_cmdbuf_work_func()
579 spin_unlock(&man->lock); in vmw_cmdbuf_work_func()
583 DRM_ERROR("Failed preempting command buffer contexts\n"); in vmw_cmdbuf_work_func()
585 spin_lock(&man->lock); in vmw_cmdbuf_work_func()
591 * Add the preempted queue after the command buffer in vmw_cmdbuf_work_func()
594 list_splice_init(&ctx->preempted, restart_head[i].prev); in vmw_cmdbuf_work_func()
601 ctx->block_submission = false; in vmw_cmdbuf_work_func()
602 list_splice_init(&restart_head[i], &ctx->submitted); in vmw_cmdbuf_work_func()
606 spin_unlock(&man->lock); in vmw_cmdbuf_work_func()
609 DRM_ERROR("Failed restarting command buffer contexts\n"); in vmw_cmdbuf_work_func()
613 vmw_cmd_send_fence(man->dev_priv, &dummy); in vmw_cmdbuf_work_func()
614 wake_up_all(&man->idle_queue); in vmw_cmdbuf_work_func()
617 mutex_unlock(&man->error_mutex); in vmw_cmdbuf_work_func()
621 * vmw_cmdbuf_man_idle - Check whether the command buffer manager is idle.
623 * @man: The command buffer manager.
634 spin_lock(&man->lock); in vmw_cmdbuf_man_idle()
637 if (!list_empty(&ctx->submitted) || in vmw_cmdbuf_man_idle()
638 !list_empty(&ctx->hw_submitted) || in vmw_cmdbuf_man_idle()
639 (check_preempted && !list_empty(&ctx->preempted))) in vmw_cmdbuf_man_idle()
643 idle = list_empty(&man->error); in vmw_cmdbuf_man_idle()
646 spin_unlock(&man->lock); in vmw_cmdbuf_man_idle()
652 * __vmw_cmdbuf_cur_flush - Flush the current command buffer for small kernel
655 * @man: The command buffer manager.
657 * Flushes the current command buffer without allocating a new one. A new one
658 * is automatically allocated when needed. Call with @man->cur_mutex held.
662 struct vmw_cmdbuf_header *cur = man->cur; in __vmw_cmdbuf_cur_flush()
664 lockdep_assert_held_once(&man->cur_mutex); in __vmw_cmdbuf_cur_flush()
669 spin_lock(&man->lock); in __vmw_cmdbuf_cur_flush()
670 if (man->cur_pos == 0) { in __vmw_cmdbuf_cur_flush()
675 man->cur->cb_header->length = man->cur_pos; in __vmw_cmdbuf_cur_flush()
676 vmw_cmdbuf_ctx_add(man, man->cur, SVGA_CB_CONTEXT_0); in __vmw_cmdbuf_cur_flush()
678 spin_unlock(&man->lock); in __vmw_cmdbuf_cur_flush()
679 man->cur = NULL; in __vmw_cmdbuf_cur_flush()
680 man->cur_pos = 0; in __vmw_cmdbuf_cur_flush()
684 * vmw_cmdbuf_cur_flush - Flush the current command buffer for small kernel
687 * @man: The command buffer manager.
690 * Flushes the current command buffer without allocating a new one. A new one
708 * vmw_cmdbuf_idle - Wait for command buffer manager idle.
710 * @man: The command buffer manager.
714 * Wait until the command buffer manager has processed all command buffers,
716 * -EBUSY.
724 vmw_generic_waiter_add(man->dev_priv, in vmw_cmdbuf_idle()
726 &man->dev_priv->cmdbuf_waiters); in vmw_cmdbuf_idle()
730 (man->idle_queue, vmw_cmdbuf_man_idle(man, true), in vmw_cmdbuf_idle()
734 (man->idle_queue, vmw_cmdbuf_man_idle(man, true), in vmw_cmdbuf_idle()
737 vmw_generic_waiter_remove(man->dev_priv, in vmw_cmdbuf_idle()
739 &man->dev_priv->cmdbuf_waiters); in vmw_cmdbuf_idle()
742 ret = -EBUSY; in vmw_cmdbuf_idle()
753 * vmw_cmdbuf_try_alloc - Try to allocate buffer space from the main pool.
755 * @man: The command buffer manager.
756 * @info: Allocation info. Will hold the size on entry and allocated mm node
759 * Try to allocate buffer space from the main pool. Returns true if succeeded.
760 * If a fatal error was hit, the error code is returned in @info->ret.
767 if (info->done) in vmw_cmdbuf_try_alloc()
770 memset(info->node, 0, sizeof(*info->node)); in vmw_cmdbuf_try_alloc()
771 spin_lock(&man->lock); in vmw_cmdbuf_try_alloc()
772 ret = drm_mm_insert_node(&man->mm, info->node, info->page_size); in vmw_cmdbuf_try_alloc()
775 ret = drm_mm_insert_node(&man->mm, info->node, info->page_size); in vmw_cmdbuf_try_alloc()
778 spin_unlock(&man->lock); in vmw_cmdbuf_try_alloc()
779 info->done = !ret; in vmw_cmdbuf_try_alloc()
781 return info->done; in vmw_cmdbuf_try_alloc()
785 * vmw_cmdbuf_alloc_space - Allocate buffer space from the main pool.
787 * @man: The command buffer manager.
788 * @node: Pointer to pre-allocated range-manager node.
789 * @size: The size of the allocation.
792 * This function allocates buffer space from the main pool, and if there is
798 size_t size, in vmw_cmdbuf_alloc_space() argument
803 info.page_size = PFN_UP(size); in vmw_cmdbuf_alloc_space()
812 if (mutex_lock_interruptible(&man->space_mutex)) in vmw_cmdbuf_alloc_space()
813 return -ERESTARTSYS; in vmw_cmdbuf_alloc_space()
815 mutex_lock(&man->space_mutex); in vmw_cmdbuf_alloc_space()
822 vmw_generic_waiter_add(man->dev_priv, in vmw_cmdbuf_alloc_space()
824 &man->dev_priv->cmdbuf_waiters); in vmw_cmdbuf_alloc_space()
830 (man->alloc_queue, vmw_cmdbuf_try_alloc(man, &info)); in vmw_cmdbuf_alloc_space()
833 (man->dev_priv, SVGA_IRQFLAG_COMMAND_BUFFER, in vmw_cmdbuf_alloc_space()
834 &man->dev_priv->cmdbuf_waiters); in vmw_cmdbuf_alloc_space()
835 mutex_unlock(&man->space_mutex); in vmw_cmdbuf_alloc_space()
839 wait_event(man->alloc_queue, vmw_cmdbuf_try_alloc(man, &info)); in vmw_cmdbuf_alloc_space()
841 vmw_generic_waiter_remove(man->dev_priv, in vmw_cmdbuf_alloc_space()
843 &man->dev_priv->cmdbuf_waiters); in vmw_cmdbuf_alloc_space()
846 mutex_unlock(&man->space_mutex); in vmw_cmdbuf_alloc_space()
852 * vmw_cmdbuf_space_pool - Set up a command buffer header with command buffer
855 * @man: The command buffer manager.
857 * @size: The requested size of the buffer space.
862 size_t size, in vmw_cmdbuf_space_pool() argument
869 if (!man->has_pool) in vmw_cmdbuf_space_pool()
870 return -ENOMEM; in vmw_cmdbuf_space_pool()
872 ret = vmw_cmdbuf_alloc_space(man, &header->node, size, interruptible); in vmw_cmdbuf_space_pool()
877 header->cb_header = dma_pool_zalloc(man->headers, GFP_KERNEL, in vmw_cmdbuf_space_pool()
878 &header->handle); in vmw_cmdbuf_space_pool()
879 if (!header->cb_header) { in vmw_cmdbuf_space_pool()
880 ret = -ENOMEM; in vmw_cmdbuf_space_pool()
884 header->size = header->node.size << PAGE_SHIFT; in vmw_cmdbuf_space_pool()
885 cb_hdr = header->cb_header; in vmw_cmdbuf_space_pool()
886 offset = header->node.start << PAGE_SHIFT; in vmw_cmdbuf_space_pool()
887 header->cmd = man->map + offset; in vmw_cmdbuf_space_pool()
888 if (man->using_mob) { in vmw_cmdbuf_space_pool()
889 cb_hdr->flags = SVGA_CB_FLAG_MOB; in vmw_cmdbuf_space_pool()
890 cb_hdr->ptr.mob.mobid = man->cmd_space->tbo.resource->start; in vmw_cmdbuf_space_pool()
891 cb_hdr->ptr.mob.mobOffset = offset; in vmw_cmdbuf_space_pool()
893 cb_hdr->ptr.pa = (u64)man->handle + (u64)offset; in vmw_cmdbuf_space_pool()
899 spin_lock(&man->lock); in vmw_cmdbuf_space_pool()
900 drm_mm_remove_node(&header->node); in vmw_cmdbuf_space_pool()
901 spin_unlock(&man->lock); in vmw_cmdbuf_space_pool()
907 * vmw_cmdbuf_space_inline - Set up a command buffer header with
908 * inline command buffer space.
910 * @man: The command buffer manager.
912 * @size: The requested size of the buffer space.
916 int size) in vmw_cmdbuf_space_inline() argument
921 if (WARN_ON_ONCE(size > VMW_CMDBUF_INLINE_SIZE)) in vmw_cmdbuf_space_inline()
922 return -ENOMEM; in vmw_cmdbuf_space_inline()
924 dheader = dma_pool_zalloc(man->dheaders, GFP_KERNEL, in vmw_cmdbuf_space_inline()
925 &header->handle); in vmw_cmdbuf_space_inline()
927 return -ENOMEM; in vmw_cmdbuf_space_inline()
929 header->inline_space = true; in vmw_cmdbuf_space_inline()
930 header->size = VMW_CMDBUF_INLINE_SIZE; in vmw_cmdbuf_space_inline()
931 cb_hdr = &dheader->cb_header; in vmw_cmdbuf_space_inline()
932 header->cb_header = cb_hdr; in vmw_cmdbuf_space_inline()
933 header->cmd = dheader->cmd; in vmw_cmdbuf_space_inline()
934 cb_hdr->status = SVGA_CB_STATUS_NONE; in vmw_cmdbuf_space_inline()
935 cb_hdr->flags = SVGA_CB_FLAG_NONE; in vmw_cmdbuf_space_inline()
936 cb_hdr->ptr.pa = (u64)header->handle + in vmw_cmdbuf_space_inline()
943 * vmw_cmdbuf_alloc - Allocate a command buffer header complete with
944 * command buffer space.
946 * @man: The command buffer manager.
947 * @size: The requested size of the buffer space.
951 * Returns a pointer to command buffer space if successful. Otherwise
956 size_t size, bool interruptible, in vmw_cmdbuf_alloc() argument
966 return ERR_PTR(-ENOMEM); in vmw_cmdbuf_alloc()
968 if (size <= VMW_CMDBUF_INLINE_SIZE) in vmw_cmdbuf_alloc()
969 ret = vmw_cmdbuf_space_inline(man, header, size); in vmw_cmdbuf_alloc()
971 ret = vmw_cmdbuf_space_pool(man, header, size, interruptible); in vmw_cmdbuf_alloc()
978 header->man = man; in vmw_cmdbuf_alloc()
979 INIT_LIST_HEAD(&header->list); in vmw_cmdbuf_alloc()
980 header->cb_header->status = SVGA_CB_STATUS_NONE; in vmw_cmdbuf_alloc()
983 return header->cmd; in vmw_cmdbuf_alloc()
987 * vmw_cmdbuf_reserve_cur - Reserve space for commands in the current
988 * command buffer.
990 * @man: The command buffer manager.
991 * @size: The requested size of the commands.
995 * Returns a pointer to command buffer space if successful. Otherwise
999 size_t size, in vmw_cmdbuf_reserve_cur() argument
1007 return ERR_PTR(-ERESTARTSYS); in vmw_cmdbuf_reserve_cur()
1009 cur = man->cur; in vmw_cmdbuf_reserve_cur()
1010 if (cur && (size + man->cur_pos > cur->size || in vmw_cmdbuf_reserve_cur()
1011 ((cur->cb_header->flags & SVGA_CB_FLAG_DX_CONTEXT) && in vmw_cmdbuf_reserve_cur()
1012 ctx_id != cur->cb_header->dxContext))) in vmw_cmdbuf_reserve_cur()
1015 if (!man->cur) { in vmw_cmdbuf_reserve_cur()
1017 max_t(size_t, size, man->default_size), in vmw_cmdbuf_reserve_cur()
1018 interruptible, &man->cur); in vmw_cmdbuf_reserve_cur()
1024 cur = man->cur; in vmw_cmdbuf_reserve_cur()
1028 cur->cb_header->flags |= SVGA_CB_FLAG_DX_CONTEXT; in vmw_cmdbuf_reserve_cur()
1029 cur->cb_header->dxContext = ctx_id; in vmw_cmdbuf_reserve_cur()
1032 cur->reserved = size; in vmw_cmdbuf_reserve_cur()
1034 return (void *) (man->cur->cmd + man->cur_pos); in vmw_cmdbuf_reserve_cur()
1038 * vmw_cmdbuf_commit_cur - Commit commands in the current command buffer.
1040 * @man: The command buffer manager.
1041 * @size: The size of the commands actually written.
1042 * @flush: Whether to flush the command buffer immediately.
1045 size_t size, bool flush) in vmw_cmdbuf_commit_cur() argument
1047 struct vmw_cmdbuf_header *cur = man->cur; in vmw_cmdbuf_commit_cur()
1049 lockdep_assert_held_once(&man->cur_mutex); in vmw_cmdbuf_commit_cur()
1051 WARN_ON(size > cur->reserved); in vmw_cmdbuf_commit_cur()
1052 man->cur_pos += size; in vmw_cmdbuf_commit_cur()
1053 if (!size) in vmw_cmdbuf_commit_cur()
1054 cur->cb_header->flags &= ~SVGA_CB_FLAG_DX_CONTEXT; in vmw_cmdbuf_commit_cur()
1061 * vmw_cmdbuf_reserve - Reserve space for commands in a command buffer.
1063 * @man: The command buffer manager.
1064 * @size: The requested size of the commands.
1067 * @header: Header of the command buffer. NULL if the current command buffer
1070 * Returns a pointer to command buffer space if successful. Otherwise
1073 void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size, in vmw_cmdbuf_reserve() argument
1078 return vmw_cmdbuf_reserve_cur(man, size, ctx_id, interruptible); in vmw_cmdbuf_reserve()
1080 if (size > header->size) in vmw_cmdbuf_reserve()
1081 return ERR_PTR(-EINVAL); in vmw_cmdbuf_reserve()
1084 header->cb_header->flags |= SVGA_CB_FLAG_DX_CONTEXT; in vmw_cmdbuf_reserve()
1085 header->cb_header->dxContext = ctx_id; in vmw_cmdbuf_reserve()
1088 header->reserved = size; in vmw_cmdbuf_reserve()
1089 return header->cmd; in vmw_cmdbuf_reserve()
1093 * vmw_cmdbuf_commit - Commit commands in a command buffer.
1095 * @man: The command buffer manager.
1096 * @size: The size of the commands actually written.
1097 * @header: Header of the command buffer. NULL if the current command buffer
1099 * @flush: Whether to flush the command buffer immediately.
1101 void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size, in vmw_cmdbuf_commit() argument
1105 vmw_cmdbuf_commit_cur(man, size, flush); in vmw_cmdbuf_commit()
1111 WARN_ON(size > header->reserved); in vmw_cmdbuf_commit()
1112 man->cur = header; in vmw_cmdbuf_commit()
1113 man->cur_pos = size; in vmw_cmdbuf_commit()
1114 if (!size) in vmw_cmdbuf_commit()
1115 header->cb_header->flags &= ~SVGA_CB_FLAG_DX_CONTEXT; in vmw_cmdbuf_commit()
1123 * vmw_cmdbuf_send_device_command - Send a command through the device context.
1125 * @man: The command buffer manager.
1127 * @size: Size of the command.
1133 size_t size) in vmw_cmdbuf_send_device_command() argument
1137 void *cmd = vmw_cmdbuf_alloc(man, size, false, &header); in vmw_cmdbuf_send_device_command()
1142 memcpy(cmd, command, size); in vmw_cmdbuf_send_device_command()
1143 header->cb_header->length = size; in vmw_cmdbuf_send_device_command()
1144 header->cb_context = SVGA_CB_CONTEXT_DEVICE; in vmw_cmdbuf_send_device_command()
1145 spin_lock(&man->lock); in vmw_cmdbuf_send_device_command()
1147 spin_unlock(&man->lock); in vmw_cmdbuf_send_device_command()
1153 return -EINVAL; in vmw_cmdbuf_send_device_command()
1160 * vmw_cmdbuf_preempt - Send a preempt command through the device
1163 * @man: The command buffer manager.
1184 * vmw_cmdbuf_startstop - Send a start / stop command through the device
1187 * @man: The command buffer manager.
1209 * vmw_cmdbuf_set_pool_size - Set command buffer manager sizes
1211 * @man: The command buffer manager.
1212 * @size: The size of the main space pool.
1214 * Set the size and allocate the main command buffer space pool.
1220 int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size) in vmw_cmdbuf_set_pool_size() argument
1222 struct vmw_private *dev_priv = man->dev_priv; in vmw_cmdbuf_set_pool_size()
1225 if (man->has_pool) in vmw_cmdbuf_set_pool_size()
1226 return -EINVAL; in vmw_cmdbuf_set_pool_size()
1229 size = PAGE_ALIGN(size); in vmw_cmdbuf_set_pool_size()
1230 man->map = dma_alloc_coherent(dev_priv->drm.dev, size, in vmw_cmdbuf_set_pool_size()
1231 &man->handle, GFP_KERNEL); in vmw_cmdbuf_set_pool_size()
1232 if (man->map) { in vmw_cmdbuf_set_pool_size()
1233 man->using_mob = false; in vmw_cmdbuf_set_pool_size()
1239 .size = size, in vmw_cmdbuf_set_pool_size()
1248 if (!(dev_priv->capabilities & SVGA_CAP_DX) || in vmw_cmdbuf_set_pool_size()
1249 !dev_priv->has_mob) in vmw_cmdbuf_set_pool_size()
1250 return -ENOMEM; in vmw_cmdbuf_set_pool_size()
1252 ret = vmw_bo_create(dev_priv, &bo_params, &man->cmd_space); in vmw_cmdbuf_set_pool_size()
1256 man->map = vmw_bo_map_and_cache(man->cmd_space); in vmw_cmdbuf_set_pool_size()
1257 man->using_mob = man->map; in vmw_cmdbuf_set_pool_size()
1260 man->size = size; in vmw_cmdbuf_set_pool_size()
1261 drm_mm_init(&man->mm, 0, size >> PAGE_SHIFT); in vmw_cmdbuf_set_pool_size()
1263 man->has_pool = true; in vmw_cmdbuf_set_pool_size()
1266 * For now, set the default size to VMW_CMDBUF_INLINE_SIZE to in vmw_cmdbuf_set_pool_size()
1271 man->default_size = VMW_CMDBUF_INLINE_SIZE; in vmw_cmdbuf_set_pool_size()
1272 drm_info(&dev_priv->drm, in vmw_cmdbuf_set_pool_size()
1274 (man->using_mob) ? "MOB" : "DMA"); in vmw_cmdbuf_set_pool_size()
1280 * vmw_cmdbuf_man_create: Create a command buffer manager and enable it for
1281 * inline command buffer submissions only.
1285 * Returns a pointer to a cummand buffer manager to success or error pointer
1286 * on failure. The command buffer manager will be enabled for submissions of
1287 * size VMW_CMDBUF_INLINE_SIZE only.
1296 if (!(dev_priv->capabilities & SVGA_CAP_COMMAND_BUFFERS)) in vmw_cmdbuf_man_create()
1297 return ERR_PTR(-ENOSYS); in vmw_cmdbuf_man_create()
1301 return ERR_PTR(-ENOMEM); in vmw_cmdbuf_man_create()
1303 man->num_contexts = (dev_priv->capabilities & SVGA_CAP_HP_CMD_QUEUE) ? in vmw_cmdbuf_man_create()
1305 man->headers = dma_pool_create("vmwgfx cmdbuf", in vmw_cmdbuf_man_create()
1306 dev_priv->drm.dev, in vmw_cmdbuf_man_create()
1309 if (!man->headers) { in vmw_cmdbuf_man_create()
1310 ret = -ENOMEM; in vmw_cmdbuf_man_create()
1314 man->dheaders = dma_pool_create("vmwgfx inline cmdbuf", in vmw_cmdbuf_man_create()
1315 dev_priv->drm.dev, in vmw_cmdbuf_man_create()
1318 if (!man->dheaders) { in vmw_cmdbuf_man_create()
1319 ret = -ENOMEM; in vmw_cmdbuf_man_create()
1326 INIT_LIST_HEAD(&man->error); in vmw_cmdbuf_man_create()
1327 spin_lock_init(&man->lock); in vmw_cmdbuf_man_create()
1328 mutex_init(&man->cur_mutex); in vmw_cmdbuf_man_create()
1329 mutex_init(&man->space_mutex); in vmw_cmdbuf_man_create()
1330 mutex_init(&man->error_mutex); in vmw_cmdbuf_man_create()
1331 man->default_size = VMW_CMDBUF_INLINE_SIZE; in vmw_cmdbuf_man_create()
1332 init_waitqueue_head(&man->alloc_queue); in vmw_cmdbuf_man_create()
1333 init_waitqueue_head(&man->idle_queue); in vmw_cmdbuf_man_create()
1334 man->dev_priv = dev_priv; in vmw_cmdbuf_man_create()
1335 man->max_hw_submitted = SVGA_CB_MAX_QUEUED_PER_CONTEXT - 1; in vmw_cmdbuf_man_create()
1336 INIT_WORK(&man->work, &vmw_cmdbuf_work_func); in vmw_cmdbuf_man_create()
1338 &dev_priv->error_waiters); in vmw_cmdbuf_man_create()
1341 DRM_ERROR("Failed starting command buffer contexts\n"); in vmw_cmdbuf_man_create()
1349 dma_pool_destroy(man->headers); in vmw_cmdbuf_man_create()
1357 * vmw_cmdbuf_remove_pool - Take down the main buffer space pool.
1359 * @man: Pointer to a command buffer manager.
1361 * This function removes the main buffer space pool, and should be called
1363 * only small command buffer submissions of size VMW_CMDBUF_INLINE_SIZE or
1364 * less are allowed, and the default size of the command buffer for small kernel
1365 * submissions is also set to this size.
1369 if (!man->has_pool) in vmw_cmdbuf_remove_pool()
1372 man->has_pool = false; in vmw_cmdbuf_remove_pool()
1373 man->default_size = VMW_CMDBUF_INLINE_SIZE; in vmw_cmdbuf_remove_pool()
1375 if (man->using_mob) in vmw_cmdbuf_remove_pool()
1376 vmw_bo_unreference(&man->cmd_space); in vmw_cmdbuf_remove_pool()
1378 dma_free_coherent(man->dev_priv->drm.dev, in vmw_cmdbuf_remove_pool()
1379 man->size, man->map, man->handle); in vmw_cmdbuf_remove_pool()
1383 * vmw_cmdbuf_man_destroy - Take down a command buffer manager.
1385 * @man: Pointer to a command buffer manager.
1387 * This function idles and then destroys a command buffer manager.
1391 WARN_ON_ONCE(man->has_pool); in vmw_cmdbuf_man_destroy()
1395 DRM_ERROR("Failed stopping command buffer contexts.\n"); in vmw_cmdbuf_man_destroy()
1397 vmw_generic_waiter_remove(man->dev_priv, SVGA_IRQFLAG_ERROR, in vmw_cmdbuf_man_destroy()
1398 &man->dev_priv->error_waiters); in vmw_cmdbuf_man_destroy()
1399 (void) cancel_work_sync(&man->work); in vmw_cmdbuf_man_destroy()
1400 dma_pool_destroy(man->dheaders); in vmw_cmdbuf_man_destroy()
1401 dma_pool_destroy(man->headers); in vmw_cmdbuf_man_destroy()
1402 mutex_destroy(&man->cur_mutex); in vmw_cmdbuf_man_destroy()
1403 mutex_destroy(&man->space_mutex); in vmw_cmdbuf_man_destroy()
1404 mutex_destroy(&man->error_mutex); in vmw_cmdbuf_man_destroy()