Subversion Repositories Kolibri OS

Rev

Rev 4110 | Rev 5056 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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 <drm/drm_vma_manager.h>
  36. #include <linux/kref.h>
  37. #include <linux/list.h>
  38. #include <linux/wait.h>
  39. #include <linux/mutex.h>
  40. #include <linux/mm.h>
  41. #include <linux/bitmap.h>
  42.  
  43. struct ttm_bo_device;
  44.  
  45. struct drm_mm_node;
  46.  
  47. struct reservation_object {
  48.         struct mutex lock;
  49. };
  50.  
  51.  
  52. /**
  53.  * struct ttm_placement
  54.  *
  55.  * @fpfn:               first valid page frame number to put the object
  56.  * @lpfn:               last valid page frame number to put the object
  57.  * @num_placement:      number of preferred placements
  58.  * @placement:          preferred placements
  59.  * @num_busy_placement: number of preferred placements when need to evict buffer
  60.  * @busy_placement:     preferred placements when need to evict buffer
  61.  *
  62.  * Structure indicating the placement you request for an object.
  63.  */
  64. struct ttm_placement {
  65.         unsigned        fpfn;
  66.         unsigned        lpfn;
  67.         unsigned        num_placement;
  68.         const uint32_t  *placement;
  69.         unsigned        num_busy_placement;
  70.         const uint32_t  *busy_placement;
  71. };
  72.  
  73. /**
  74.  * struct ttm_bus_placement
  75.  *
  76.  * @addr:               mapped virtual address
  77.  * @base:               bus base address
  78.  * @is_iomem:           is this io memory ?
  79.  * @size:               size in byte
  80.  * @offset:             offset from the base address
  81.  * @io_reserved_vm:     The VM system has a refcount in @io_reserved_count
  82.  * @io_reserved_count:  Refcounting the numbers of callers to ttm_mem_io_reserve
  83.  *
  84.  * Structure indicating the bus placement of an object.
  85.  */
  86. struct ttm_bus_placement {
  87.         void            *addr;
  88.         unsigned long   base;
  89.         unsigned long   size;
  90.         unsigned long   offset;
  91.         bool            is_iomem;
  92.         bool            io_reserved_vm;
  93.         uint64_t        io_reserved_count;
  94. };
  95.  
  96.  
  97. /**
  98.  * struct ttm_mem_reg
  99.  *
  100.  * @mm_node: Memory manager node.
  101.  * @size: Requested size of memory region.
  102.  * @num_pages: Actual size of memory region in pages.
  103.  * @page_alignment: Page alignment.
  104.  * @placement: Placement flags.
  105.  * @bus: Placement on io bus accessible to the CPU
  106.  *
  107.  * Structure indicating the placement and space resources used by a
  108.  * buffer object.
  109.  */
  110.  
  111. struct ttm_mem_reg {
  112.         void *mm_node;
  113.         unsigned long start;
  114.         unsigned long size;
  115.         unsigned long num_pages;
  116.         uint32_t page_alignment;
  117.         uint32_t mem_type;
  118.         uint32_t placement;
  119.         struct ttm_bus_placement bus;
  120. };
  121.  
  122. /**
  123.  * enum ttm_bo_type
  124.  *
  125.  * @ttm_bo_type_device: These are 'normal' buffers that can
  126.  * be mmapped by user space. Each of these bos occupy a slot in the
  127.  * device address space, that can be used for normal vm operations.
  128.  *
  129.  * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers,
  130.  * but they cannot be accessed from user-space. For kernel-only use.
  131.  *
  132.  * @ttm_bo_type_sg: Buffer made from dmabuf sg table shared with another
  133.  * driver.
  134.  */
  135.  
  136. enum ttm_bo_type {
  137.         ttm_bo_type_device,
  138.         ttm_bo_type_kernel,
  139.         ttm_bo_type_sg
  140. };
  141.  
  142. struct ttm_tt;
  143.  
  144. /**
  145.  * struct ttm_buffer_object
  146.  *
  147.  * @bdev: Pointer to the buffer object device structure.
  148.  * @type: The bo type.
  149.  * @destroy: Destruction function. If NULL, kfree is used.
  150.  * @num_pages: Actual number of pages.
  151.  * @acc_size: Accounted size for this object.
  152.  * @kref: Reference count of this buffer object. When this refcount reaches
  153.  * zero, the object is put on the delayed delete list.
  154.  * @list_kref: List reference count of this buffer object. This member is
  155.  * used to avoid destruction while the buffer object is still on a list.
  156.  * Lru lists may keep one refcount, the delayed delete list, and kref != 0
  157.  * keeps one refcount. When this refcount reaches zero,
  158.  * the object is destroyed.
  159.  * @mem: structure describing current placement.
  160.  * @persistent_swap_storage: Usually the swap storage is deleted for buffers
  161.  * pinned in physical memory. If this behaviour is not desired, this member
  162.  * holds a pointer to a persistent shmem object.
  163.  * @ttm: TTM structure holding system pages.
  164.  * @evicted: Whether the object was evicted without user-space knowing.
  165.  * @cpu_writes: For synchronization. Number of cpu writers.
  166.  * @lru: List head for the lru list.
  167.  * @ddestroy: List head for the delayed destroy list.
  168.  * @swap: List head for swap LRU list.
  169.  * @sync_obj: Pointer to a synchronization object.
  170.  * @priv_flags: Flags describing buffer object internal state.
  171.  * @vma_node: Address space manager node.
  172.  * @offset: The current GPU offset, which can have different meanings
  173.  * depending on the memory type. For SYSTEM type memory, it should be 0.
  174.  * @cur_placement: Hint of current placement.
  175.  * @wu_mutex: Wait unreserved mutex.
  176.  *
  177.  * Base class for TTM buffer object, that deals with data placement and CPU
  178.  * mappings. GPU mappings are really up to the driver, but for simpler GPUs
  179.  * the driver can usually use the placement offset @offset directly as the
  180.  * GPU virtual address. For drivers implementing multiple
  181.  * GPU memory manager contexts, the driver should manage the address space
  182.  * in these contexts separately and use these objects to get the correct
  183.  * placement and caching for these GPU maps. This makes it possible to use
  184.  * these objects for even quite elaborate memory management schemes.
  185.  * The destroy member, the API visibility of this object makes it possible
  186.  * to derive driver specific types.
  187.  */
  188.  
  189. struct ttm_buffer_object {
  190.         /**
  191.          * Members constant at init.
  192.          */
  193.  
  194.         struct ttm_bo_global *glob;
  195.         struct ttm_bo_device *bdev;
  196.         enum ttm_bo_type type;
  197.         void (*destroy) (struct ttm_buffer_object *);
  198.         unsigned long num_pages;
  199.         size_t acc_size;
  200.  
  201.         /**
  202.         * Members not needing protection.
  203.         */
  204.  
  205.         struct kref kref;
  206.         struct kref list_kref;
  207.  
  208.         /**
  209.          * Members protected by the bo::resv::reserved lock.
  210.          */
  211.  
  212.         struct ttm_mem_reg mem;
  213.         struct file *persistent_swap_storage;
  214.         struct ttm_tt *ttm;
  215.         bool evicted;
  216.  
  217.         /**
  218.          * Members protected by the bo::reserved lock only when written to.
  219.          */
  220.  
  221.         atomic_t cpu_writers;
  222.  
  223.         /**
  224.          * Members protected by the bdev::lru_lock.
  225.          */
  226.  
  227.         struct list_head lru;
  228.         struct list_head ddestroy;
  229.         struct list_head swap;
  230.         struct list_head io_reserve_lru;
  231.  
  232.         /**
  233.          * Members protected by struct buffer_object_device::fence_lock
  234.          * In addition, setting sync_obj to anything else
  235.          * than NULL requires bo::reserved to be held. This allows for
  236.          * checking NULL while reserved but not holding the mentioned lock.
  237.          */
  238.  
  239.         void *sync_obj;
  240.         unsigned long priv_flags;
  241.  
  242.         struct drm_vma_offset_node vma_node;
  243.  
  244.         /**
  245.          * Special members that are protected by the reserve lock
  246.          * and the bo::lock when written to. Can be read with
  247.          * either of these locks held.
  248.          */
  249.  
  250.         unsigned long offset;
  251.         uint32_t cur_placement;
  252.  
  253.         struct sg_table *sg;
  254.  
  255.         struct reservation_object *resv;
  256.         struct reservation_object ttm_resv;
  257.         struct mutex wu_mutex;
  258. };
  259.  
  260. /**
  261.  * struct ttm_bo_kmap_obj
  262.  *
  263.  * @virtual: The current kernel virtual address.
  264.  * @page: The page when kmap'ing a single page.
  265.  * @bo_kmap_type: Type of bo_kmap.
  266.  *
  267.  * Object describing a kernel mapping. Since a TTM bo may be located
  268.  * in various memory types with various caching policies, the
  269.  * mapping can either be an ioremap, a vmap, a kmap or part of a
  270.  * premapped region.
  271.  */
  272.  
  273. #define TTM_BO_MAP_IOMEM_MASK 0x80
  274. struct ttm_bo_kmap_obj {
  275.         void *virtual;
  276.         struct page *page;
  277.         enum {
  278.                 ttm_bo_map_iomap        = 1 | TTM_BO_MAP_IOMEM_MASK,
  279.                 ttm_bo_map_vmap         = 2,
  280.                 ttm_bo_map_kmap         = 3,
  281.                 ttm_bo_map_premapped    = 4 | TTM_BO_MAP_IOMEM_MASK,
  282.         } bo_kmap_type;
  283.         struct ttm_buffer_object *bo;
  284. };
  285.  
  286. /**
  287.  * ttm_bo_reference - reference a struct ttm_buffer_object
  288.  *
  289.  * @bo: The buffer object.
  290.  *
  291.  * Returns a refcounted pointer to a buffer object.
  292.  */
  293.  
  294. static inline struct ttm_buffer_object *
  295. ttm_bo_reference(struct ttm_buffer_object *bo)
  296. {
  297.         kref_get(&bo->kref);
  298.         return bo;
  299. }
  300.  
  301. /**
  302.  * ttm_bo_wait - wait for buffer idle.
  303.  *
  304.  * @bo:  The buffer object.
  305.  * @interruptible:  Use interruptible wait.
  306.  * @no_wait:  Return immediately if buffer is busy.
  307.  *
  308.  * This function must be called with the bo::mutex held, and makes
  309.  * sure any previous rendering to the buffer is completed.
  310.  * Note: It might be necessary to block validations before the
  311.  * wait by reserving the buffer.
  312.  * Returns -EBUSY if no_wait is true and the buffer is busy.
  313.  * Returns -ERESTARTSYS if interrupted by a signal.
  314.  */
  315. extern int ttm_bo_wait(struct ttm_buffer_object *bo, bool lazy,
  316.                        bool interruptible, bool no_wait);
  317. /**
  318.  * ttm_bo_validate
  319.  *
  320.  * @bo: The buffer object.
  321.  * @placement: Proposed placement for the buffer object.
  322.  * @interruptible: Sleep interruptible if sleeping.
  323.  * @no_wait_gpu: Return immediately if the GPU is busy.
  324.  *
  325.  * Changes placement and caching policy of the buffer object
  326.  * according proposed placement.
  327.  * Returns
  328.  * -EINVAL on invalid proposed placement.
  329.  * -ENOMEM on out-of-memory condition.
  330.  * -EBUSY if no_wait is true and buffer busy.
  331.  * -ERESTARTSYS if interrupted by a signal.
  332.  */
  333. extern int ttm_bo_validate(struct ttm_buffer_object *bo,
  334.                                 struct ttm_placement *placement,
  335.                                 bool interruptible,
  336.                                 bool no_wait_gpu);
  337.  
  338. /**
  339.  * ttm_bo_unref
  340.  *
  341.  * @bo: The buffer object.
  342.  *
  343.  * Unreference and clear a pointer to a buffer object.
  344.  */
  345. extern void ttm_bo_unref(struct ttm_buffer_object **bo);
  346.  
  347.  
  348. /**
  349.  * ttm_bo_list_ref_sub
  350.  *
  351.  * @bo: The buffer object.
  352.  * @count: The number of references with which to decrease @bo::list_kref;
  353.  * @never_free: The refcount should not reach zero with this operation.
  354.  *
  355.  * Release @count lru list references to this buffer object.
  356.  */
  357. extern void ttm_bo_list_ref_sub(struct ttm_buffer_object *bo, int count,
  358.                                 bool never_free);
  359.  
  360. /**
  361.  * ttm_bo_add_to_lru
  362.  *
  363.  * @bo: The buffer object.
  364.  *
  365.  * Add this bo to the relevant mem type lru and, if it's backed by
  366.  * system pages (ttms) to the swap list.
  367.  * This function must be called with struct ttm_bo_global::lru_lock held, and
  368.  * is typically called immediately prior to unreserving a bo.
  369.  */
  370. extern void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
  371.  
  372. /**
  373.  * ttm_bo_del_from_lru
  374.  *
  375.  * @bo: The buffer object.
  376.  *
  377.  * Remove this bo from all lru lists used to lookup and reserve an object.
  378.  * This function must be called with struct ttm_bo_global::lru_lock held,
  379.  * and is usually called just immediately after the bo has been reserved to
  380.  * avoid recursive reservation from lru lists.
  381.  */
  382. extern int ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
  383.  
  384.  
  385. /**
  386.  * ttm_bo_lock_delayed_workqueue
  387.  *
  388.  * Prevent the delayed workqueue from running.
  389.  * Returns
  390.  * True if the workqueue was queued at the time
  391.  */
  392. extern int ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev);
  393.  
  394. /**
  395.  * ttm_bo_unlock_delayed_workqueue
  396.  *
  397.  * Allows the delayed workqueue to run.
  398.  */
  399. extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev,
  400.                                             int resched);
  401.  
  402. /**
  403.  * ttm_bo_synccpu_write_grab
  404.  *
  405.  * @bo: The buffer object:
  406.  * @no_wait: Return immediately if buffer is busy.
  407.  *
  408.  * Synchronizes a buffer object for CPU RW access. This means
  409.  * command submission that affects the buffer will return -EBUSY
  410.  * until ttm_bo_synccpu_write_release is called.
  411.  *
  412.  * Returns
  413.  * -EBUSY if the buffer is busy and no_wait is true.
  414.  * -ERESTARTSYS if interrupted by a signal.
  415.  */
  416. extern int
  417. ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait);
  418.  
  419. /**
  420.  * ttm_bo_synccpu_write_release:
  421.  *
  422.  * @bo : The buffer object.
  423.  *
  424.  * Releases a synccpu lock.
  425.  */
  426. extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo);
  427.  
  428. /**
  429.  * ttm_bo_acc_size
  430.  *
  431.  * @bdev: Pointer to a ttm_bo_device struct.
  432.  * @bo_size: size of the buffer object in byte.
  433.  * @struct_size: size of the structure holding buffer object datas
  434.  *
  435.  * Returns size to account for a buffer object
  436.  */
  437. size_t ttm_bo_acc_size(struct ttm_bo_device *bdev,
  438.                        unsigned long bo_size,
  439.                        unsigned struct_size);
  440. size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
  441.                            unsigned long bo_size,
  442.                            unsigned struct_size);
  443.  
  444. /**
  445.  * ttm_bo_init
  446.  *
  447.  * @bdev: Pointer to a ttm_bo_device struct.
  448.  * @bo: Pointer to a ttm_buffer_object to be initialized.
  449.  * @size: Requested size of buffer object.
  450.  * @type: Requested type of buffer object.
  451.  * @flags: Initial placement flags.
  452.  * @page_alignment: Data alignment in pages.
  453.  * @interruptible: If needing to sleep to wait for GPU resources,
  454.  * sleep interruptible.
  455.  * @persistent_swap_storage: Usually the swap storage is deleted for buffers
  456.  * pinned in physical memory. If this behaviour is not desired, this member
  457.  * holds a pointer to a persistent shmem object. Typically, this would
  458.  * point to the shmem object backing a GEM object if TTM is used to back a
  459.  * GEM user interface.
  460.  * @acc_size: Accounted size for this object.
  461.  * @destroy: Destroy function. Use NULL for kfree().
  462.  *
  463.  * This function initializes a pre-allocated struct ttm_buffer_object.
  464.  * As this object may be part of a larger structure, this function,
  465.  * together with the @destroy function,
  466.  * enables driver-specific objects derived from a ttm_buffer_object.
  467.  * On successful return, the object kref and list_kref are set to 1.
  468.  * If a failure occurs, the function will call the @destroy function, or
  469.  * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
  470.  * illegal and will likely cause memory corruption.
  471.  *
  472.  * Returns
  473.  * -ENOMEM: Out of memory.
  474.  * -EINVAL: Invalid placement flags.
  475.  * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
  476.  */
  477.  
  478. extern int ttm_bo_init(struct ttm_bo_device *bdev,
  479.                         struct ttm_buffer_object *bo,
  480.                         unsigned long size,
  481.                         enum ttm_bo_type type,
  482.                         struct ttm_placement *placement,
  483.                         uint32_t page_alignment,
  484.                         bool interrubtible,
  485.                         struct file *persistent_swap_storage,
  486.                         size_t acc_size,
  487.                         struct sg_table *sg,
  488.                         void (*destroy) (struct ttm_buffer_object *));
  489.  
  490. /**
  491.  * ttm_bo_synccpu_object_init
  492.  *
  493.  * @bdev: Pointer to a ttm_bo_device struct.
  494.  * @bo: Pointer to a ttm_buffer_object to be initialized.
  495.  * @size: Requested size of buffer object.
  496.  * @type: Requested type of buffer object.
  497.  * @flags: Initial placement flags.
  498.  * @page_alignment: Data alignment in pages.
  499.  * @interruptible: If needing to sleep while waiting for GPU resources,
  500.  * sleep interruptible.
  501.  * @persistent_swap_storage: Usually the swap storage is deleted for buffers
  502.  * pinned in physical memory. If this behaviour is not desired, this member
  503.  * holds a pointer to a persistent shmem object. Typically, this would
  504.  * point to the shmem object backing a GEM object if TTM is used to back a
  505.  * GEM user interface.
  506.  * @p_bo: On successful completion *p_bo points to the created object.
  507.  *
  508.  * This function allocates a ttm_buffer_object, and then calls ttm_bo_init
  509.  * on that object. The destroy function is set to kfree().
  510.  * Returns
  511.  * -ENOMEM: Out of memory.
  512.  * -EINVAL: Invalid placement flags.
  513.  * -ERESTARTSYS: Interrupted by signal while waiting for resources.
  514.  */
  515.  
  516. extern int ttm_bo_create(struct ttm_bo_device *bdev,
  517.                                 unsigned long size,
  518.                                 enum ttm_bo_type type,
  519.                                 struct ttm_placement *placement,
  520.                                 uint32_t page_alignment,
  521.                                 bool interruptible,
  522.                                 struct file *persistent_swap_storage,
  523.                                 struct ttm_buffer_object **p_bo);
  524.  
  525. /**
  526.  * ttm_bo_check_placement
  527.  *
  528.  * @bo:         the buffer object.
  529.  * @placement:  placements
  530.  *
  531.  * Performs minimal validity checking on an intended change of
  532.  * placement flags.
  533.  * Returns
  534.  * -EINVAL: Intended change is invalid or not allowed.
  535.  */
  536. extern int ttm_bo_check_placement(struct ttm_buffer_object *bo,
  537.                                         struct ttm_placement *placement);
  538.  
  539. /**
  540.  * ttm_bo_init_mm
  541.  *
  542.  * @bdev: Pointer to a ttm_bo_device struct.
  543.  * @mem_type: The memory type.
  544.  * @p_size: size managed area in pages.
  545.  *
  546.  * Initialize a manager for a given memory type.
  547.  * Note: if part of driver firstopen, it must be protected from a
  548.  * potentially racing lastclose.
  549.  * Returns:
  550.  * -EINVAL: invalid size or memory type.
  551.  * -ENOMEM: Not enough memory.
  552.  * May also return driver-specified errors.
  553.  */
  554.  
  555. extern int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
  556.                                 unsigned long p_size);
  557. /**
  558.  * ttm_bo_clean_mm
  559.  *
  560.  * @bdev: Pointer to a ttm_bo_device struct.
  561.  * @mem_type: The memory type.
  562.  *
  563.  * Take down a manager for a given memory type after first walking
  564.  * the LRU list to evict any buffers left alive.
  565.  *
  566.  * Normally, this function is part of lastclose() or unload(), and at that
  567.  * point there shouldn't be any buffers left created by user-space, since
  568.  * there should've been removed by the file descriptor release() method.
  569.  * However, before this function is run, make sure to signal all sync objects,
  570.  * and verify that the delayed delete queue is empty. The driver must also
  571.  * make sure that there are no NO_EVICT buffers present in this memory type
  572.  * when the call is made.
  573.  *
  574.  * If this function is part of a VT switch, the caller must make sure that
  575.  * there are no appications currently validating buffers before this
  576.  * function is called. The caller can do that by first taking the
  577.  * struct ttm_bo_device::ttm_lock in write mode.
  578.  *
  579.  * Returns:
  580.  * -EINVAL: invalid or uninitialized memory type.
  581.  * -EBUSY: There are still buffers left in this memory type.
  582.  */
  583.  
  584. extern int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
  585.  
  586. /**
  587.  * ttm_bo_evict_mm
  588.  *
  589.  * @bdev: Pointer to a ttm_bo_device struct.
  590.  * @mem_type: The memory type.
  591.  *
  592.  * Evicts all buffers on the lru list of the memory type.
  593.  * This is normally part of a VT switch or an
  594.  * out-of-memory-space-due-to-fragmentation handler.
  595.  * The caller must make sure that there are no other processes
  596.  * currently validating buffers, and can do that by taking the
  597.  * struct ttm_bo_device::ttm_lock in write mode.
  598.  *
  599.  * Returns:
  600.  * -EINVAL: Invalid or uninitialized memory type.
  601.  * -ERESTARTSYS: The call was interrupted by a signal while waiting to
  602.  * evict a buffer.
  603.  */
  604.  
  605. extern int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
  606.  
  607. /**
  608.  * ttm_kmap_obj_virtual
  609.  *
  610.  * @map: A struct ttm_bo_kmap_obj returned from ttm_bo_kmap.
  611.  * @is_iomem: Pointer to an integer that on return indicates 1 if the
  612.  * virtual map is io memory, 0 if normal memory.
  613.  *
  614.  * Returns the virtual address of a buffer object area mapped by ttm_bo_kmap.
  615.  * If *is_iomem is 1 on return, the virtual address points to an io memory area,
  616.  * that should strictly be accessed by the iowriteXX() and similar functions.
  617.  */
  618.  
  619. static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map,
  620.                                          bool *is_iomem)
  621. {
  622.         *is_iomem = !!(map->bo_kmap_type & TTM_BO_MAP_IOMEM_MASK);
  623.         return map->virtual;
  624. }
  625.  
  626. /**
  627.  * ttm_bo_kmap
  628.  *
  629.  * @bo: The buffer object.
  630.  * @start_page: The first page to map.
  631.  * @num_pages: Number of pages to map.
  632.  * @map: pointer to a struct ttm_bo_kmap_obj representing the map.
  633.  *
  634.  * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the
  635.  * data in the buffer object. The ttm_kmap_obj_virtual function can then be
  636.  * used to obtain a virtual address to the data.
  637.  *
  638.  * Returns
  639.  * -ENOMEM: Out of memory.
  640.  * -EINVAL: Invalid range.
  641.  */
  642.  
  643. extern int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page,
  644.                        unsigned long num_pages, struct ttm_bo_kmap_obj *map);
  645.  
  646. /**
  647.  * ttm_bo_kunmap
  648.  *
  649.  * @map: Object describing the map to unmap.
  650.  *
  651.  * Unmaps a kernel map set up by ttm_bo_kmap.
  652.  */
  653.  
  654. extern void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
  655.  
  656. /**
  657.  * ttm_fbdev_mmap - mmap fbdev memory backed by a ttm buffer object.
  658.  *
  659.  * @vma:       vma as input from the fbdev mmap method.
  660.  * @bo:        The bo backing the address space. The address space will
  661.  * have the same size as the bo, and start at offset 0.
  662.  *
  663.  * This function is intended to be called by the fbdev mmap method
  664.  * if the fbdev address space is to be backed by a bo.
  665.  */
  666.  
  667. extern int ttm_fbdev_mmap(struct vm_area_struct *vma,
  668.                           struct ttm_buffer_object *bo);
  669.  
  670. /**
  671.  * ttm_bo_mmap - mmap out of the ttm device address space.
  672.  *
  673.  * @filp:      filp as input from the mmap method.
  674.  * @vma:       vma as input from the mmap method.
  675.  * @bdev:      Pointer to the ttm_bo_device with the address space manager.
  676.  *
  677.  * This function is intended to be called by the device mmap method.
  678.  * if the device address space is to be backed by the bo manager.
  679.  */
  680.  
  681. extern int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
  682.                        struct ttm_bo_device *bdev);
  683.  
  684. /**
  685.  * ttm_bo_io
  686.  *
  687.  * @bdev:      Pointer to the struct ttm_bo_device.
  688.  * @filp:      Pointer to the struct file attempting to read / write.
  689.  * @wbuf:      User-space pointer to address of buffer to write. NULL on read.
  690.  * @rbuf:      User-space pointer to address of buffer to read into.
  691.  * Null on write.
  692.  * @count:     Number of bytes to read / write.
  693.  * @f_pos:     Pointer to current file position.
  694.  * @write:     1 for read, 0 for write.
  695.  *
  696.  * This function implements read / write into ttm buffer objects, and is
  697.  * intended to
  698.  * be called from the fops::read and fops::write method.
  699.  * Returns:
  700.  * See man (2) write, man(2) read. In particular,
  701.  * the function may return -ERESTARTSYS if
  702.  * interrupted by a signal.
  703.  */
  704.  
  705. extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
  706.                          const char __user *wbuf, char __user *rbuf,
  707.                          size_t count, loff_t *f_pos, bool write);
  708.  
  709. extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
  710. extern int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo);
  711. #endif
  712.