Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ttm_bo_api.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  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29  */
30 
31 #ifndef _TTM_BO_API_H_
32 #define _TTM_BO_API_H_
33 
34 #include <drm/drm_hashtab.h>
35 #include <linux/kref.h>
36 #include <linux/list.h>
37 #include <linux/wait.h>
38 #include <linux/mutex.h>
39 #include <linux/mm.h>
40 #include <linux/rbtree.h>
41 #include <linux/bitmap.h>
42 
43 struct ttm_bo_device;
44 
45 struct drm_mm_node;
46 
47 
60 struct ttm_placement {
61  unsigned fpfn;
62  unsigned lpfn;
63  unsigned num_placement;
67 };
68 
83  void *addr;
84  unsigned long base;
85  unsigned long size;
86  unsigned long offset;
87  bool is_iomem;
90 };
91 
92 
107 struct ttm_mem_reg {
108  void *mm_node;
109  unsigned long start;
110  unsigned long size;
111  unsigned long num_pages;
116 };
117 
136 };
137 
138 struct ttm_tt;
139 
203  unsigned long buffer_start;
206  unsigned long num_pages;
208  size_t acc_size;
209 
214  struct kref kref;
215  struct kref list_kref;
217 
222  struct ttm_mem_reg mem;
224  struct ttm_tt *ttm;
225  bool evicted;
226 
232 
237  struct list_head lru;
239  struct list_head swap;
242  bool seq_valid;
243 
250 
259  void *sync_obj;
260  unsigned long priv_flags;
261 
266  struct rb_node vm_rb;
268 
269 
276  unsigned long offset;
278 
279  struct sg_table *sg;
280 };
281 
295 #define TTM_BO_MAP_IOMEM_MASK 0x80
297  void *virtual;
298  struct page *page;
299  enum {
304  } bo_kmap_type;
306 };
307 
316 static inline struct ttm_buffer_object *
317 ttm_bo_reference(struct ttm_buffer_object *bo)
318 {
319  kref_get(&bo->kref);
320  return bo;
321 }
322 
337 extern int ttm_bo_wait(struct ttm_buffer_object *bo, bool lazy,
338  bool interruptible, bool no_wait);
356 extern int ttm_bo_validate(struct ttm_buffer_object *bo,
357  struct ttm_placement *placement,
358  bool interruptible, bool no_wait_reserve,
359  bool no_wait_gpu);
360 
368 extern void ttm_bo_unref(struct ttm_buffer_object **bo);
369 
370 
380 extern void ttm_bo_list_ref_sub(struct ttm_buffer_object *bo, int count,
381  bool never_free);
382 
393 extern void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
394 
405 extern int ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
406 
407 
416 
423  int resched);
424 
438 extern int
439 ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait);
440 
448 extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo);
449 
459 size_t ttm_bo_acc_size(struct ttm_bo_device *bdev,
460  unsigned long bo_size,
461  unsigned struct_size);
462 size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
463  unsigned long bo_size,
464  unsigned struct_size);
465 
502 extern int ttm_bo_init(struct ttm_bo_device *bdev,
503  struct ttm_buffer_object *bo,
504  unsigned long size,
505  enum ttm_bo_type type,
506  struct ttm_placement *placement,
507  uint32_t page_alignment,
508  unsigned long buffer_start,
509  bool interrubtible,
511  size_t acc_size,
512  struct sg_table *sg,
513  void (*destroy) (struct ttm_buffer_object *));
514 
543 extern int ttm_bo_create(struct ttm_bo_device *bdev,
544  unsigned long size,
545  enum ttm_bo_type type,
546  struct ttm_placement *placement,
547  uint32_t page_alignment,
548  unsigned long buffer_start,
549  bool interruptible,
550  struct file *persistent_swap_storage,
551  struct ttm_buffer_object **p_bo);
552 
564 extern int ttm_bo_check_placement(struct ttm_buffer_object *bo,
565  struct ttm_placement *placement);
566 
583 extern int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
584  unsigned long p_size);
612 extern int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
613 
633 extern int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
634 
647 static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map,
648  bool *is_iomem)
649 {
650  *is_iomem = !!(map->bo_kmap_type & TTM_BO_MAP_IOMEM_MASK);
651  return map->virtual;
652 }
653 
671 extern int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page,
672  unsigned long num_pages, struct ttm_bo_kmap_obj *map);
673 
682 extern void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
683 
695 extern int ttm_fbdev_mmap(struct vm_area_struct *vma,
696  struct ttm_buffer_object *bo);
697 
709 extern int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
710  struct ttm_bo_device *bdev);
711 
733 extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
734  const char __user *wbuf, char __user *rbuf,
735  size_t count, loff_t *f_pos, bool write);
736 
737 extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
738 
739 #endif