LCOV - code coverage report
Current view: top level - dev/pci/drm/ttm - ttm_memory.h (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 18 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <sys/task.h>
      32             : 
      33             : /**
      34             :  * struct ttm_mem_shrink - callback to shrink TTM memory usage.
      35             :  *
      36             :  * @do_shrink: The callback function.
      37             :  *
      38             :  * Arguments to the do_shrink functions are intended to be passed using
      39             :  * inheritance. That is, the argument class derives from struct ttm_mem_shrink,
      40             :  * and can be accessed using container_of().
      41             :  */
      42             : 
      43             : struct ttm_mem_shrink {
      44             :         int (*do_shrink) (struct ttm_mem_shrink *);
      45             : };
      46             : 
      47             : /**
      48             :  * struct ttm_mem_global - Global memory accounting structure.
      49             :  *
      50             :  * @shrink: A single callback to shrink TTM memory usage. Extend this
      51             :  * to a linked list to be able to handle multiple callbacks when needed.
      52             :  * @swap_queue: A workqueue to handle shrinking in low memory situations. We
      53             :  * need a separate workqueue since it will spend a lot of time waiting
      54             :  * for the GPU, and this will otherwise block other workqueue tasks(?)
      55             :  * At this point we use only a single-threaded workqueue.
      56             :  * @work: The workqueue callback for the shrink queue.
      57             :  * @lock: Lock to protect the @shrink - and the memory accounting members,
      58             :  * that is, essentially the whole structure with some exceptions.
      59             :  * @zones: Array of pointers to accounting zones.
      60             :  * @num_zones: Number of populated entries in the @zones array.
      61             :  * @zone_kernel: Pointer to the kernel zone.
      62             :  * @zone_highmem: Pointer to the highmem zone if there is one.
      63             :  * @zone_dma32: Pointer to the dma32 zone if there is one.
      64             :  *
      65             :  * Note that this structure is not per device. It should be global for all
      66             :  * graphics devices.
      67             :  */
      68             : 
      69             : #define TTM_MEM_MAX_ZONES 2
      70             : struct ttm_mem_zone;
      71             : struct ttm_mem_global {
      72             :         struct kobject kobj;
      73             :         struct ttm_mem_shrink *shrink;
      74             :         struct workqueue_struct *swap_queue;
      75             :         struct work_struct work;
      76             :         spinlock_t lock;
      77             :         struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES];
      78             :         unsigned int num_zones;
      79             :         struct ttm_mem_zone *zone_kernel;
      80             : #ifdef CONFIG_HIGHMEM
      81             :         struct ttm_mem_zone *zone_highmem;
      82             : #else
      83             :         struct ttm_mem_zone *zone_dma32;
      84             : #endif
      85             : };
      86             : 
      87             : /**
      88             :  * ttm_mem_init_shrink - initialize a struct ttm_mem_shrink object
      89             :  *
      90             :  * @shrink: The object to initialize.
      91             :  * @func: The callback function.
      92             :  */
      93             : 
      94           0 : static inline void ttm_mem_init_shrink(struct ttm_mem_shrink *shrink,
      95             :                                        int (*func) (struct ttm_mem_shrink *))
      96             : {
      97           0 :         shrink->do_shrink = func;
      98           0 : }
      99             : 
     100             : /**
     101             :  * ttm_mem_register_shrink - register a struct ttm_mem_shrink object.
     102             :  *
     103             :  * @glob: The struct ttm_mem_global object to register with.
     104             :  * @shrink: An initialized struct ttm_mem_shrink object to register.
     105             :  *
     106             :  * Returns:
     107             :  * -EBUSY: There's already a callback registered. (May change).
     108             :  */
     109             : 
     110           0 : static inline int ttm_mem_register_shrink(struct ttm_mem_global *glob,
     111             :                                           struct ttm_mem_shrink *shrink)
     112             : {
     113           0 :         spin_lock(&glob->lock);
     114           0 :         if (glob->shrink != NULL) {
     115           0 :                 spin_unlock(&glob->lock);
     116           0 :                 return -EBUSY;
     117             :         }
     118           0 :         glob->shrink = shrink;
     119           0 :         spin_unlock(&glob->lock);
     120           0 :         return 0;
     121           0 : }
     122             : 
     123             : /**
     124             :  * ttm_mem_unregister_shrink - unregister a struct ttm_mem_shrink object.
     125             :  *
     126             :  * @glob: The struct ttm_mem_global object to unregister from.
     127             :  * @shrink: A previously registert struct ttm_mem_shrink object.
     128             :  *
     129             :  */
     130             : 
     131           0 : static inline void ttm_mem_unregister_shrink(struct ttm_mem_global *glob,
     132             :                                              struct ttm_mem_shrink *shrink)
     133             : {
     134           0 :         spin_lock(&glob->lock);
     135           0 :         BUG_ON(glob->shrink != shrink);
     136           0 :         glob->shrink = NULL;
     137           0 :         spin_unlock(&glob->lock);
     138           0 : }
     139             : 
     140             : extern int ttm_mem_global_init(struct ttm_mem_global *glob);
     141             : extern void ttm_mem_global_release(struct ttm_mem_global *glob);
     142             : extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
     143             :                                 bool no_wait, bool interruptible);
     144             : extern void ttm_mem_global_free(struct ttm_mem_global *glob,
     145             :                                 uint64_t amount);
     146             : extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
     147             :                                      struct vm_page *page,
     148             :                                      bool no_wait, bool interruptible);
     149             : extern void ttm_mem_global_free_page(struct ttm_mem_global *glob,
     150             :                                      struct vm_page *page);
     151             : extern size_t ttm_round_pot(size_t size);
     152             : #endif

Generated by: LCOV version 1.13