Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ttm_memory.h
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #ifndef TTM_MEMORY_H
29 #define TTM_MEMORY_H
30 
31 #include <linux/workqueue.h>
32 #include <linux/spinlock.h>
33 #include <linux/bug.h>
34 #include <linux/wait.h>
35 #include <linux/errno.h>
36 #include <linux/kobject.h>
37 #include <linux/mm.h>
38 
50  int (*do_shrink) (struct ttm_mem_shrink *);
51 };
52 
76 #define TTM_MEM_MAX_ZONES 2
77 struct ttm_mem_zone;
79  struct kobject kobj;
82  struct work_struct work;
86  unsigned int num_zones;
88 #ifdef CONFIG_HIGHMEM
89  struct ttm_mem_zone *zone_highmem;
90 #else
92 #endif
93 };
94 
102 static inline void ttm_mem_init_shrink(struct ttm_mem_shrink *shrink,
103  int (*func) (struct ttm_mem_shrink *))
104 {
105  shrink->do_shrink = func;
106 }
107 
118 static inline int ttm_mem_register_shrink(struct ttm_mem_global *glob,
119  struct ttm_mem_shrink *shrink)
120 {
121  spin_lock(&glob->lock);
122  if (glob->shrink != NULL) {
123  spin_unlock(&glob->lock);
124  return -EBUSY;
125  }
126  glob->shrink = shrink;
127  spin_unlock(&glob->lock);
128  return 0;
129 }
130 
139 static inline void ttm_mem_unregister_shrink(struct ttm_mem_global *glob,
140  struct ttm_mem_shrink *shrink)
141 {
142  spin_lock(&glob->lock);
143  BUG_ON(glob->shrink != shrink);
144  glob->shrink = NULL;
145  spin_unlock(&glob->lock);
146 }
147 
148 extern int ttm_mem_global_init(struct ttm_mem_global *glob);
149 extern void ttm_mem_global_release(struct ttm_mem_global *glob);
150 extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
151  bool no_wait, bool interruptible);
152 extern void ttm_mem_global_free(struct ttm_mem_global *glob,
153  uint64_t amount);
154 extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
155  struct page *page,
156  bool no_wait, bool interruptible);
157 extern void ttm_mem_global_free_page(struct ttm_mem_global *glob,
158  struct page *page);
159 extern size_t ttm_round_pot(size_t size);
160 #endif