// SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * * Copyright 2019-2023 VMware, Inc., Palo Alto, CA., USA * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. * **************************************************************************/ #include "vmwgfx_bo.h" #include "vmwgfx_drv.h" /* * Different methods for tracking dirty: * VMW_BO_DIRTY_PAGETABLE - Scan the pagetable for hardware dirty bits * VMW_BO_DIRTY_MKWRITE - Write-protect page table entries and record write- * accesses in the VM mkwrite() callback */ enum vmw_bo_dirty_method { … }; /* * No dirtied pages at scan trigger a transition to the _MKWRITE method, * similarly a certain percentage of dirty pages trigger a transition to * the _PAGETABLE method. How many triggers should we wait for before * changing method? */ #define VMW_DIRTY_NUM_CHANGE_TRIGGERS … /* Percentage to trigger a transition to the _PAGETABLE method */ #define VMW_DIRTY_PERCENTAGE … /** * struct vmw_bo_dirty - Dirty information for buffer objects * @start: First currently dirty bit * @end: Last currently dirty bit + 1 * @method: The currently used dirty method * @change_count: Number of consecutive method change triggers * @ref_count: Reference count for this structure * @bitmap_size: The size of the bitmap in bits. Typically equal to the * nuber of pages in the bo. * @bitmap: A bitmap where each bit represents a page. A set bit means a * dirty page. */ struct vmw_bo_dirty { … }; /** * vmw_bo_dirty_scan_pagetable - Perform a pagetable scan for dirty bits * @vbo: The buffer object to scan * * Scans the pagetable for dirty bits. Clear those bits and modify the * dirty structure with the results. This function may change the * dirty-tracking method. */ static void vmw_bo_dirty_scan_pagetable(struct vmw_bo *vbo) { … } /** * vmw_bo_dirty_scan_mkwrite - Reset the mkwrite dirty-tracking method * @vbo: The buffer object to scan * * Write-protect pages written to so that consecutive write accesses will * trigger a call to mkwrite. * * This function may change the dirty-tracking method. */ static void vmw_bo_dirty_scan_mkwrite(struct vmw_bo *vbo) { … } /** * vmw_bo_dirty_scan - Scan for dirty pages and add them to the dirty * tracking structure * @vbo: The buffer object to scan * * This function may change the dirty tracking method. */ void vmw_bo_dirty_scan(struct vmw_bo *vbo) { … } /** * vmw_bo_dirty_pre_unmap - write-protect and pick up dirty pages before * an unmap_mapping_range operation. * @vbo: The buffer object, * @start: First page of the range within the buffer object. * @end: Last page of the range within the buffer object + 1. * * If we're using the _PAGETABLE scan method, we may leak dirty pages * when calling unmap_mapping_range(). This function makes sure we pick * up all dirty pages. */ static void vmw_bo_dirty_pre_unmap(struct vmw_bo *vbo, pgoff_t start, pgoff_t end) { … } /** * vmw_bo_dirty_unmap - Clear all ptes pointing to a range within a bo * @vbo: The buffer object, * @start: First page of the range within the buffer object. * @end: Last page of the range within the buffer object + 1. * * This is similar to ttm_bo_unmap_virtual() except it takes a subrange. */ void vmw_bo_dirty_unmap(struct vmw_bo *vbo, pgoff_t start, pgoff_t end) { … } /** * vmw_bo_dirty_add - Add a dirty-tracking user to a buffer object * @vbo: The buffer object * * This function registers a dirty-tracking user to a buffer object. * A user can be for example a resource or a vma in a special user-space * mapping. * * Return: Zero on success, -ENOMEM on memory allocation failure. */ int vmw_bo_dirty_add(struct vmw_bo *vbo) { … } /** * vmw_bo_dirty_release - Release a dirty-tracking user from a buffer object * @vbo: The buffer object * * This function releases a dirty-tracking user from a buffer object. * If the reference count reaches zero, then the dirty-tracking object is * freed and the pointer to it cleared. * * Return: Zero on success, -ENOMEM on memory allocation failure. */ void vmw_bo_dirty_release(struct vmw_bo *vbo) { … } /** * vmw_bo_dirty_transfer_to_res - Pick up a resource's dirty region from * its backing mob. * @res: The resource * * This function will pick up all dirty ranges affecting the resource from * it's backup mob, and call vmw_resource_dirty_update() once for each * range. The transferred ranges will be cleared from the backing mob's * dirty tracking. */ void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res) { … } /** * vmw_bo_dirty_clear_res - Clear a resource's dirty region from * its backing mob. * @res: The resource * * This function will clear all dirty ranges affecting the resource from * it's backup mob's dirty tracking. */ void vmw_bo_dirty_clear_res(struct vmw_resource *res) { … } vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf) { … } vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf) { … }