XenevaOS
Loading...
Searching...
No Matches
drm_vma_manager.h
Go to the documentation of this file.
1#ifndef __DRM_VMA_MANAGER_H__
2#define __DRM_VMA_MANAGER_H__
3
4/*
5 * Copyright (c) 2013 David Herrmann <dh.herrmann@gmail.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#include <drm/drm_mm.h>
27#include <linux/mm.h>
28#include <linux/rbtree.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31
32/* We make up offsets for buffer objects so we can recognize them at
33 * mmap time. pgoff in mmap is an unsigned long, so we need to make sure
34 * that the faked up offset will fit
35 */
36#if BITS_PER_LONG == 64
37#define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
38#define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 256)
39#else
40#define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFUL >> PAGE_SHIFT) + 1)
41#define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFUL >> PAGE_SHIFT) * 16)
42#endif
43
44struct drm_file;
45
47 struct rb_node vm_rb;
49 unsigned long vm_count;
50};
51
58
63
65 unsigned long page_offset, unsigned long size);
67
69 unsigned long start,
70 unsigned long pages);
72 struct drm_vma_offset_node *node, unsigned long pages);
75
79 struct drm_file *tag);
81 struct drm_file *tag);
82
95static inline struct drm_vma_offset_node *
96drm_vma_offset_exact_lookup_locked(struct drm_vma_offset_manager *mgr,
97 unsigned long start,
98 unsigned long pages)
99{
101
103 return (node && node->vm_node.start == start) ? node : NULL;
104}
105
122static inline void drm_vma_offset_lock_lookup(struct drm_vma_offset_manager *mgr)
123{
124 read_lock(&mgr->vm_lock);
125}
126
133static inline void drm_vma_offset_unlock_lookup(struct drm_vma_offset_manager *mgr)
134{
135 read_unlock(&mgr->vm_lock);
136}
137
148static inline void drm_vma_node_reset(struct drm_vma_offset_node *node)
149{
150 memset(node, 0, sizeof(*node));
151 node->vm_files = RB_ROOT;
152 rwlock_init(&node->vm_lock);
153}
154
169static inline unsigned long drm_vma_node_start(const struct drm_vma_offset_node *node)
170{
171 return node->vm_node.start;
172}
173
186static inline unsigned long drm_vma_node_size(struct drm_vma_offset_node *node)
187{
188 return node->vm_node.size;
189}
190
203static inline __u64 drm_vma_node_offset_addr(struct drm_vma_offset_node *node)
204{
205 return ((__u64)node->vm_node.start) << PAGE_SHIFT;
206}
207
220static inline void drm_vma_node_unmap(struct drm_vma_offset_node *node,
221 struct address_space *file_mapping)
222{
223 if (drm_mm_node_allocated(&node->vm_node))
224 unmap_mapping_range(file_mapping,
225 drm_vma_node_offset_addr(node),
226 drm_vma_node_size(node) << PAGE_SHIFT, 1);
227}
228
241static inline int drm_vma_node_verify_access(struct drm_vma_offset_node *node,
242 struct drm_file *tag)
243{
244 return drm_vma_node_is_allowed(node, tag) ? 0 : -EACCES;
245}
246
247#endif /* __DRM_VMA_MANAGER_H__ */
#define PAGE_SHIFT
Definition vmmngr.h:80
#define EACCES
Definition acclib.h:193
#define NULL
Definition actypes.h:561
size_t pages
Definition audrv.c:83
uint64_t __u64
Definition drm.h:44
size_t size
Definition drm_bridge.h:1299
void drm_vma_offset_manager_destroy(struct drm_vma_offset_manager *mgr)
bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node, struct drm_file *tag)
int drm_vma_node_allow_once(struct drm_vma_offset_node *node, struct drm_file *tag)
void drm_vma_offset_manager_init(struct drm_vma_offset_manager *mgr, unsigned long page_offset, unsigned long size)
struct drm_vma_offset_node * drm_vma_offset_lookup_locked(struct drm_vma_offset_manager *mgr, unsigned long start, unsigned long pages)
void drm_vma_node_revoke(struct drm_vma_offset_node *node, struct drm_file *tag)
int drm_vma_offset_add(struct drm_vma_offset_manager *mgr, struct drm_vma_offset_node *node, unsigned long pages)
int drm_vma_node_allow(struct drm_vma_offset_node *node, struct drm_file *tag)
void drm_vma_offset_remove(struct drm_vma_offset_manager *mgr, struct drm_vma_offset_node *node)
void memset(void)
void int node
Definition kthread.h:31
spinlock_t rwlock_t
Definition spinlock.h:200
#define unmap_mapping_range(mapping, holebegin, holelen, even_cows)
Definition mount.h:93
#define RB_ROOT
Definition rbtree_types.h:62
Definition shmem_fs.h:25
Definition drm_file.h:165
Definition drm_mm.h:165
Definition drm_mm.h:198
Definition drm_vma_manager.h:46
struct drm_file * vm_tag
Definition drm_vma_manager.h:48
struct rb_node vm_rb
Definition drm_vma_manager.h:47
unsigned long vm_count
Definition drm_vma_manager.h:49
Definition drm_vma_manager.h:59
rwlock_t vm_lock
Definition drm_vma_manager.h:60
struct drm_mm vm_addr_space_mm
Definition drm_vma_manager.h:61
Definition drm_vma_manager.h:52
void * driver_private
Definition drm_vma_manager.h:56
rwlock_t vm_lock
Definition drm_vma_manager.h:53
struct drm_mm_node vm_node
Definition drm_vma_manager.h:54
struct rb_root vm_files
Definition drm_vma_manager.h:55
Definition rbtree_types.h:21
Definition rbtree_types.h:34