^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #ifndef __DRM_VMA_MANAGER_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #define __DRM_VMA_MANAGER_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2013 David Herrmann <dh.herrmann@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Permission is hereby granted, free of charge, to any person obtaining a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * copy of this software and associated documentation files (the "Software"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * to deal in the Software without restriction, including without limitation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * the rights to use, copy, modify, merge, publish, distribute, sublicense,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * and/or sell copies of the Software, and to permit persons to whom the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Software is furnished to do so, subject to the following conditions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * The above copyright notice and this permission notice shall be included in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * all copies or substantial portions of the Software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * OTHER DEALINGS IN THE SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <drm/drm_mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* We make up offsets for buffer objects so we can recognize them at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * mmap time. pgoff in mmap is an unsigned long, so we need to make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * that the faked up offset will fit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #if BITS_PER_LONG == 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFUL >> PAGE_SHIFT) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFUL >> PAGE_SHIFT) * 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct drm_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct drm_vma_offset_file {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct rb_node vm_rb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct drm_file *vm_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned long vm_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct drm_vma_offset_node {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) rwlock_t vm_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct drm_mm_node vm_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct rb_root vm_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) bool readonly:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct drm_vma_offset_manager {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) rwlock_t vm_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct drm_mm vm_addr_space_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) void drm_vma_offset_manager_init(struct drm_vma_offset_manager *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned long page_offset, unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) void drm_vma_offset_manager_destroy(struct drm_vma_offset_manager *mgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct drm_vma_offset_node *drm_vma_offset_lookup_locked(struct drm_vma_offset_manager *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) unsigned long start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned long pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int drm_vma_offset_add(struct drm_vma_offset_manager *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct drm_vma_offset_node *node, unsigned long pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) void drm_vma_offset_remove(struct drm_vma_offset_manager *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct drm_vma_offset_node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int drm_vma_node_allow(struct drm_vma_offset_node *node, struct drm_file *tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) void drm_vma_node_revoke(struct drm_vma_offset_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct drm_file *tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct drm_file *tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * drm_vma_offset_exact_lookup_locked() - Look up node by exact address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @mgr: Manager object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * @start: Start address (page-based, not byte-based)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * @pages: Size of object (page-based)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * Same as drm_vma_offset_lookup_locked() but does not allow any offset into the node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * It only returns the exact object with the given start address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * Node at exact start address @start.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static inline struct drm_vma_offset_node *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) drm_vma_offset_exact_lookup_locked(struct drm_vma_offset_manager *mgr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned long start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned long pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct drm_vma_offset_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) node = drm_vma_offset_lookup_locked(mgr, start, pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return (node && node->vm_node.start == start) ? node : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * drm_vma_offset_lock_lookup() - Lock lookup for extended private use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @mgr: Manager object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * Lock VMA manager for extended lookups. Only locked VMA function calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * are allowed while holding this lock. All other contexts are blocked from VMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * until the lock is released via drm_vma_offset_unlock_lookup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Use this if you need to take a reference to the objects returned by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * drm_vma_offset_lookup_locked() before releasing this lock again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * This lock must not be used for anything else than extended lookups. You must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * not call any other VMA helpers while holding this lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Note: You're in atomic-context while holding this lock!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static inline void drm_vma_offset_lock_lookup(struct drm_vma_offset_manager *mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) read_lock(&mgr->vm_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * drm_vma_offset_unlock_lookup() - Unlock lookup for extended private use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * @mgr: Manager object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * Release lookup-lock. See drm_vma_offset_lock_lookup() for more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static inline void drm_vma_offset_unlock_lookup(struct drm_vma_offset_manager *mgr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) read_unlock(&mgr->vm_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * drm_vma_node_reset() - Initialize or reset node object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * @node: Node to initialize or reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * Reset a node to its initial state. This must be called before using it with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * any VMA offset manager.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * This must not be called on an already allocated node, or you will leak
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static inline void drm_vma_node_reset(struct drm_vma_offset_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) memset(node, 0, sizeof(*node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) node->vm_files = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) rwlock_init(&node->vm_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * drm_vma_node_start() - Return start address for page-based addressing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @node: Node to inspect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * Return the start address of the given node. This can be used as offset into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * the linear VM space that is provided by the VMA offset manager. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * this can only be used for page-based addressing. If you need a proper offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * for user-space mappings, you must apply "<< PAGE_SHIFT" or use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * drm_vma_node_offset_addr() helper instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Start address of @node for page-based addressing. 0 if the node does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * have an offset allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static inline unsigned long drm_vma_node_start(const struct drm_vma_offset_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return node->vm_node.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * drm_vma_node_size() - Return size (page-based)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * @node: Node to inspect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Return the size as number of pages for the given node. This is the same size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * that was passed to drm_vma_offset_add(). If no offset is allocated for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * node, this is 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * Size of @node as number of pages. 0 if the node does not have an offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static inline unsigned long drm_vma_node_size(struct drm_vma_offset_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return node->vm_node.size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * drm_vma_node_offset_addr() - Return sanitized offset for user-space mmaps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * @node: Linked offset node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * Same as drm_vma_node_start() but returns the address as a valid offset that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * can be used for user-space mappings during mmap().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * This must not be called on unlinked nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * Offset of @node for byte-based addressing. 0 if the node does not have an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * object allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static inline __u64 drm_vma_node_offset_addr(struct drm_vma_offset_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return ((__u64)node->vm_node.start) << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * drm_vma_node_unmap() - Unmap offset node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * @node: Offset node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * @file_mapping: Address space to unmap @node from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * Unmap all userspace mappings for a given offset node. The mappings must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * associated with the @file_mapping address-space. If no offset exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * nothing is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * This call is unlocked. The caller must guarantee that drm_vma_offset_remove()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * is not called on this node concurrently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static inline void drm_vma_node_unmap(struct drm_vma_offset_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct address_space *file_mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (drm_mm_node_allocated(&node->vm_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unmap_mapping_range(file_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) drm_vma_node_offset_addr(node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) drm_vma_node_size(node) << PAGE_SHIFT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * drm_vma_node_verify_access() - Access verification helper for TTM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * @node: Offset node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * @tag: Tag of file to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * This checks whether @tag is granted access to @node. It is the same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * drm_vma_node_is_allowed() but suitable as drop-in helper for TTM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * verify_access() callbacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * 0 if access is granted, -EACCES otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static inline int drm_vma_node_verify_access(struct drm_vma_offset_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct drm_file *tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return drm_vma_node_is_allowed(node, tag) ? 0 : -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #endif /* __DRM_VMA_MANAGER_H__ */