Lines Matching refs:buffer
50 static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer) in binder_buffer_next() argument
52 return list_entry(buffer->entry.next, struct binder_buffer, entry); in binder_buffer_next()
55 static struct binder_buffer *binder_buffer_prev(struct binder_buffer *buffer) in binder_buffer_prev() argument
57 return list_entry(buffer->entry.prev, struct binder_buffer, entry); in binder_buffer_prev()
61 struct binder_buffer *buffer) in binder_alloc_buffer_size() argument
63 if (list_is_last(&buffer->entry, &alloc->buffers)) in binder_alloc_buffer_size()
64 return alloc->buffer + alloc->buffer_size - buffer->user_data; in binder_alloc_buffer_size()
65 return binder_buffer_next(buffer)->user_data - buffer->user_data; in binder_alloc_buffer_size()
73 struct binder_buffer *buffer; in binder_insert_free_buffer() local
87 buffer = rb_entry(parent, struct binder_buffer, rb_node); in binder_insert_free_buffer()
88 BUG_ON(!buffer->free); in binder_insert_free_buffer()
90 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_insert_free_buffer()
106 struct binder_buffer *buffer; in binder_insert_allocated_buffer_locked() local
112 buffer = rb_entry(parent, struct binder_buffer, rb_node); in binder_insert_allocated_buffer_locked()
113 BUG_ON(buffer->free); in binder_insert_allocated_buffer_locked()
115 if (new_buffer->user_data < buffer->user_data) in binder_insert_allocated_buffer_locked()
117 else if (new_buffer->user_data > buffer->user_data) in binder_insert_allocated_buffer_locked()
131 struct binder_buffer *buffer; in binder_alloc_prepare_to_free_locked() local
134 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_prepare_to_free_locked()
135 BUG_ON(buffer->free); in binder_alloc_prepare_to_free_locked()
137 if (user_ptr < buffer->user_data) { in binder_alloc_prepare_to_free_locked()
139 } else if (user_ptr > buffer->user_data) { in binder_alloc_prepare_to_free_locked()
147 if (!buffer->allow_user_free) in binder_alloc_prepare_to_free_locked()
149 buffer->allow_user_free = 0; in binder_alloc_prepare_to_free_locked()
150 return buffer; in binder_alloc_prepare_to_free_locked()
170 struct binder_buffer *buffer; in binder_alloc_prepare_to_free() local
173 buffer = binder_alloc_prepare_to_free_locked(alloc, user_ptr); in binder_alloc_prepare_to_free()
175 return buffer; in binder_alloc_prepare_to_free()
205 index = (page_addr - alloc->buffer) / PAGE_SIZE; in binder_lru_freelist_add()
254 alloc->pid, __func__, addr - alloc->buffer, ret); in binder_install_single_page()
269 struct binder_buffer *buffer, in binder_install_buffer_pages() argument
276 start = buffer->user_data & PAGE_MASK; in binder_install_buffer_pages()
277 final = PAGE_ALIGN(buffer->user_data + size); in binder_install_buffer_pages()
283 index = (page_addr - alloc->buffer) / PAGE_SIZE; in binder_install_buffer_pages()
314 index = (page_addr - alloc->buffer) / PAGE_SIZE; in binder_lru_freelist_del()
349 struct binder_buffer *buffer; in debug_no_space_locked() local
359 buffer = rb_entry(n, struct binder_buffer, rb_node); in debug_no_space_locked()
360 buffer_size = binder_alloc_buffer_size(alloc, buffer); in debug_no_space_locked()
368 buffer = rb_entry(n, struct binder_buffer, rb_node); in debug_no_space_locked()
369 buffer_size = binder_alloc_buffer_size(alloc, buffer); in debug_no_space_locked()
392 struct binder_buffer *buffer; in debug_low_async_space_locked() local
409 buffer = rb_entry(n, struct binder_buffer, rb_node); in debug_low_async_space_locked()
410 if (buffer->pid != pid) in debug_low_async_space_locked()
412 if (!buffer->async_transaction) in debug_low_async_space_locked()
414 total_alloc_size += binder_alloc_buffer_size(alloc, buffer); in debug_low_async_space_locked()
444 struct binder_buffer *buffer; in binder_alloc_new_buf_locked() local
453 buffer = ERR_PTR(-ENOSPC); in binder_alloc_new_buf_locked()
458 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_new_buf_locked()
459 BUG_ON(!buffer->free); in binder_alloc_new_buf_locked()
460 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_new_buf_locked()
478 buffer = ERR_PTR(-ENOSPC); in binder_alloc_new_buf_locked()
484 buffer = rb_entry(best_fit, struct binder_buffer, rb_node); in binder_alloc_new_buf_locked()
485 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_new_buf_locked()
488 new_buffer->user_data = buffer->user_data + size; in binder_alloc_new_buf_locked()
489 list_add(&new_buffer->entry, &buffer->entry); in binder_alloc_new_buf_locked()
497 alloc->pid, size, buffer, buffer_size); in binder_alloc_new_buf_locked()
505 next_used_page = (buffer->user_data + buffer_size) & PAGE_MASK; in binder_alloc_new_buf_locked()
506 curr_last_page = PAGE_ALIGN(buffer->user_data + size); in binder_alloc_new_buf_locked()
507 binder_lru_freelist_del(alloc, PAGE_ALIGN(buffer->user_data), in binder_alloc_new_buf_locked()
510 rb_erase(&buffer->rb_node, &alloc->free_buffers); in binder_alloc_new_buf_locked()
511 buffer->free = 0; in binder_alloc_new_buf_locked()
512 buffer->allow_user_free = 0; in binder_alloc_new_buf_locked()
513 binder_insert_allocated_buffer_locked(alloc, buffer); in binder_alloc_new_buf_locked()
514 buffer->async_transaction = is_async; in binder_alloc_new_buf_locked()
515 buffer->oneway_spam_suspect = false; in binder_alloc_new_buf_locked()
522 buffer->oneway_spam_suspect = true; in binder_alloc_new_buf_locked()
528 return buffer; in binder_alloc_new_buf_locked()
574 struct binder_buffer *buffer, *next; in binder_alloc_new_buf() local
601 buffer = binder_alloc_new_buf_locked(alloc, next, size, is_async); in binder_alloc_new_buf()
602 if (IS_ERR(buffer)) { in binder_alloc_new_buf()
607 buffer->data_size = data_size; in binder_alloc_new_buf()
608 buffer->offsets_size = offsets_size; in binder_alloc_new_buf()
609 buffer->extra_buffers_size = extra_buffers_size; in binder_alloc_new_buf()
610 buffer->pid = current->tgid; in binder_alloc_new_buf()
613 ret = binder_install_buffer_pages(alloc, buffer, size); in binder_alloc_new_buf()
615 binder_alloc_free_buf(alloc, buffer); in binder_alloc_new_buf()
616 buffer = ERR_PTR(ret); in binder_alloc_new_buf()
619 return buffer; in binder_alloc_new_buf()
622 static unsigned long buffer_start_page(struct binder_buffer *buffer) in buffer_start_page() argument
624 return buffer->user_data & PAGE_MASK; in buffer_start_page()
627 static unsigned long prev_buffer_end_page(struct binder_buffer *buffer) in prev_buffer_end_page() argument
629 return (buffer->user_data - 1) & PAGE_MASK; in prev_buffer_end_page()
633 struct binder_buffer *buffer) in binder_delete_free_buffer() argument
637 if (PAGE_ALIGNED(buffer->user_data)) in binder_delete_free_buffer()
640 BUG_ON(alloc->buffers.next == &buffer->entry); in binder_delete_free_buffer()
641 prev = binder_buffer_prev(buffer); in binder_delete_free_buffer()
643 if (prev_buffer_end_page(prev) == buffer_start_page(buffer)) in binder_delete_free_buffer()
646 if (!list_is_last(&buffer->entry, &alloc->buffers)) { in binder_delete_free_buffer()
647 next = binder_buffer_next(buffer); in binder_delete_free_buffer()
648 if (buffer_start_page(next) == buffer_start_page(buffer)) in binder_delete_free_buffer()
652 binder_lru_freelist_add(alloc, buffer_start_page(buffer), in binder_delete_free_buffer()
653 buffer_start_page(buffer) + PAGE_SIZE); in binder_delete_free_buffer()
655 list_del(&buffer->entry); in binder_delete_free_buffer()
656 kfree(buffer); in binder_delete_free_buffer()
660 struct binder_buffer *buffer) in binder_free_buf_locked() argument
664 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_free_buf_locked()
666 size = ALIGN(buffer->data_size, sizeof(void *)) + in binder_free_buf_locked()
667 ALIGN(buffer->offsets_size, sizeof(void *)) + in binder_free_buf_locked()
668 ALIGN(buffer->extra_buffers_size, sizeof(void *)); in binder_free_buf_locked()
672 alloc->pid, buffer, size, buffer_size); in binder_free_buf_locked()
674 BUG_ON(buffer->free); in binder_free_buf_locked()
676 BUG_ON(buffer->transaction != NULL); in binder_free_buf_locked()
677 BUG_ON(buffer->user_data < alloc->buffer); in binder_free_buf_locked()
678 BUG_ON(buffer->user_data > alloc->buffer + alloc->buffer_size); in binder_free_buf_locked()
680 if (buffer->async_transaction) { in binder_free_buf_locked()
687 binder_lru_freelist_add(alloc, PAGE_ALIGN(buffer->user_data), in binder_free_buf_locked()
688 (buffer->user_data + buffer_size) & PAGE_MASK); in binder_free_buf_locked()
690 rb_erase(&buffer->rb_node, &alloc->allocated_buffers); in binder_free_buf_locked()
691 buffer->free = 1; in binder_free_buf_locked()
692 if (!list_is_last(&buffer->entry, &alloc->buffers)) { in binder_free_buf_locked()
693 struct binder_buffer *next = binder_buffer_next(buffer); in binder_free_buf_locked()
700 if (alloc->buffers.next != &buffer->entry) { in binder_free_buf_locked()
701 struct binder_buffer *prev = binder_buffer_prev(buffer); in binder_free_buf_locked()
704 binder_delete_free_buffer(alloc, buffer); in binder_free_buf_locked()
706 buffer = prev; in binder_free_buf_locked()
709 binder_insert_free_buffer(alloc, buffer); in binder_free_buf_locked()
732 struct binder_buffer *buffer, in binder_alloc_get_page() argument
737 (buffer->user_data - alloc->buffer); in binder_alloc_get_page()
755 struct binder_buffer *buffer) in binder_alloc_clear_buf() argument
757 size_t bytes = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_clear_buf()
765 page = binder_alloc_get_page(alloc, buffer, in binder_alloc_clear_buf()
782 struct binder_buffer *buffer) in binder_alloc_free_buf() argument
792 if (buffer->clear_on_free) { in binder_alloc_free_buf()
793 binder_alloc_clear_buf(alloc, buffer); in binder_alloc_free_buf()
794 buffer->clear_on_free = false; in binder_alloc_free_buf()
797 binder_free_buf_locked(alloc, buffer); in binder_alloc_free_buf()
817 struct binder_buffer *buffer; in binder_alloc_mmap_handler() local
837 alloc->buffer = vma->vm_start; in binder_alloc_mmap_handler()
853 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); in binder_alloc_mmap_handler()
854 if (!buffer) { in binder_alloc_mmap_handler()
860 buffer->user_data = alloc->buffer; in binder_alloc_mmap_handler()
861 list_add(&buffer->entry, &alloc->buffers); in binder_alloc_mmap_handler()
862 buffer->free = 1; in binder_alloc_mmap_handler()
863 binder_insert_free_buffer(alloc, buffer); in binder_alloc_mmap_handler()
875 alloc->buffer = 0; in binder_alloc_mmap_handler()
893 struct binder_buffer *buffer; in binder_alloc_deferred_release() local
900 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_deferred_release()
903 BUG_ON(buffer->transaction); in binder_alloc_deferred_release()
905 if (buffer->clear_on_free) { in binder_alloc_deferred_release()
906 binder_alloc_clear_buf(alloc, buffer); in binder_alloc_deferred_release()
907 buffer->clear_on_free = false; in binder_alloc_deferred_release()
909 binder_free_buf_locked(alloc, buffer); in binder_alloc_deferred_release()
914 buffer = list_first_entry(&alloc->buffers, in binder_alloc_deferred_release()
916 WARN_ON(!buffer->free); in binder_alloc_deferred_release()
918 list_del(&buffer->entry); in binder_alloc_deferred_release()
920 kfree(buffer); in binder_alloc_deferred_release()
964 struct binder_buffer *buffer; in binder_alloc_print_allocated() local
969 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_print_allocated()
971 buffer->debug_id, in binder_alloc_print_allocated()
972 buffer->user_data - alloc->buffer, in binder_alloc_print_allocated()
973 buffer->data_size, buffer->offsets_size, in binder_alloc_print_allocated()
974 buffer->extra_buffers_size, in binder_alloc_print_allocated()
975 buffer->transaction ? "active" : "delivered"); in binder_alloc_print_allocated()
1080 page_addr = alloc->buffer + index * PAGE_SIZE; in binder_alloc_free_page()
1202 struct binder_buffer *buffer, in check_buffer() argument
1205 size_t buffer_size = binder_alloc_buffer_size(alloc, buffer); in check_buffer()
1210 !buffer->free && in check_buffer()
1211 (!buffer->allow_user_free || !buffer->transaction); in check_buffer()
1228 struct binder_buffer *buffer, in binder_alloc_copy_user_to_buffer() argument
1233 if (!check_buffer(alloc, buffer, buffer_offset, bytes)) in binder_alloc_copy_user_to_buffer()
1243 page = binder_alloc_get_page(alloc, buffer, in binder_alloc_copy_user_to_buffer()
1260 struct binder_buffer *buffer, in binder_alloc_do_buffer_copy() argument
1266 if (!check_buffer(alloc, buffer, buffer_offset, bytes)) in binder_alloc_do_buffer_copy()
1274 page = binder_alloc_get_page(alloc, buffer, in binder_alloc_do_buffer_copy()
1290 struct binder_buffer *buffer, in binder_alloc_copy_to_buffer() argument
1295 return binder_alloc_do_buffer_copy(alloc, true, buffer, buffer_offset, in binder_alloc_copy_to_buffer()
1301 struct binder_buffer *buffer, in binder_alloc_copy_from_buffer() argument
1305 return binder_alloc_do_buffer_copy(alloc, false, buffer, buffer_offset, in binder_alloc_copy_from_buffer()