1216f7a2cSFrançois Tigeot /************************************************************************** 2216f7a2cSFrançois Tigeot * 3216f7a2cSFrançois Tigeot * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA 4216f7a2cSFrançois Tigeot * All Rights Reserved. 5216f7a2cSFrançois Tigeot * 6216f7a2cSFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a 7216f7a2cSFrançois Tigeot * copy of this software and associated documentation files (the 8216f7a2cSFrançois Tigeot * "Software"), to deal in the Software without restriction, including 9216f7a2cSFrançois Tigeot * without limitation the rights to use, copy, modify, merge, publish, 10216f7a2cSFrançois Tigeot * distribute, sub license, and/or sell copies of the Software, and to 11216f7a2cSFrançois Tigeot * permit persons to whom the Software is furnished to do so, subject to 12216f7a2cSFrançois Tigeot * the following conditions: 13216f7a2cSFrançois Tigeot * 14216f7a2cSFrançois Tigeot * The above copyright notice and this permission notice (including the 15216f7a2cSFrançois Tigeot * next paragraph) shall be included in all copies or substantial portions 16216f7a2cSFrançois Tigeot * of the Software. 17216f7a2cSFrançois Tigeot * 18216f7a2cSFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19216f7a2cSFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20216f7a2cSFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21216f7a2cSFrançois Tigeot * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 22216f7a2cSFrançois Tigeot * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23216f7a2cSFrançois Tigeot * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24216f7a2cSFrançois Tigeot * USE OR OTHER DEALINGS IN THE SOFTWARE. 25216f7a2cSFrançois Tigeot * 26216f7a2cSFrançois Tigeot **************************************************************************/ 27216f7a2cSFrançois Tigeot 28216f7a2cSFrançois Tigeot #ifndef TTM_MEMORY_H 29216f7a2cSFrançois Tigeot #define TTM_MEMORY_H 30216f7a2cSFrançois Tigeot 313a2096e8SFrançois Tigeot #include <linux/workqueue.h> 323a2096e8SFrançois Tigeot #include <linux/spinlock.h> 333a2096e8SFrançois Tigeot #include <linux/bug.h> 343a2096e8SFrançois Tigeot #include <linux/wait.h> 353a2096e8SFrançois Tigeot #include <linux/errno.h> 363a2096e8SFrançois Tigeot #include <linux/kobject.h> 373a2096e8SFrançois Tigeot #include <linux/mm.h> 38*932d855eSSergey Zigachev #include "ttm_bo_api.h" 39216f7a2cSFrançois Tigeot 40216f7a2cSFrançois Tigeot /** 41216f7a2cSFrançois Tigeot * struct ttm_mem_global - Global memory accounting structure. 42216f7a2cSFrançois Tigeot * 43216f7a2cSFrançois Tigeot * @shrink: A single callback to shrink TTM memory usage. Extend this 44216f7a2cSFrançois Tigeot * to a linked list to be able to handle multiple callbacks when needed. 45216f7a2cSFrançois Tigeot * @swap_queue: A workqueue to handle shrinking in low memory situations. We 46216f7a2cSFrançois Tigeot * need a separate workqueue since it will spend a lot of time waiting 47216f7a2cSFrançois Tigeot * for the GPU, and this will otherwise block other workqueue tasks(?) 48216f7a2cSFrançois Tigeot * At this point we use only a single-threaded workqueue. 49216f7a2cSFrançois Tigeot * @work: The workqueue callback for the shrink queue. 50216f7a2cSFrançois Tigeot * @lock: Lock to protect the @shrink - and the memory accounting members, 51216f7a2cSFrançois Tigeot * that is, essentially the whole structure with some exceptions. 52*932d855eSSergey Zigachev * @lower_mem_limit: include lower limit of swap space and lower limit of 53*932d855eSSergey Zigachev * system memory. 54216f7a2cSFrançois Tigeot * @zones: Array of pointers to accounting zones. 55216f7a2cSFrançois Tigeot * @num_zones: Number of populated entries in the @zones array. 56216f7a2cSFrançois Tigeot * @zone_kernel: Pointer to the kernel zone. 57216f7a2cSFrançois Tigeot * @zone_highmem: Pointer to the highmem zone if there is one. 58216f7a2cSFrançois Tigeot * @zone_dma32: Pointer to the dma32 zone if there is one. 59216f7a2cSFrançois Tigeot * 60216f7a2cSFrançois Tigeot * Note that this structure is not per device. It should be global for all 61216f7a2cSFrançois Tigeot * graphics devices. 62216f7a2cSFrançois Tigeot */ 63216f7a2cSFrançois Tigeot 64216f7a2cSFrançois Tigeot #define TTM_MEM_MAX_ZONES 2 65216f7a2cSFrançois Tigeot struct ttm_mem_zone; 66216f7a2cSFrançois Tigeot struct ttm_mem_global { 673a2096e8SFrançois Tigeot struct kobject kobj; 68*932d855eSSergey Zigachev struct ttm_bo_global *bo_glob; 6960b00aa3SFrançois Tigeot struct workqueue_struct *swap_queue; 7060b00aa3SFrançois Tigeot struct work_struct work; 71ec5b6af4SFrançois Tigeot spinlock_t lock; 72*932d855eSSergey Zigachev uint64_t lower_mem_limit; 73216f7a2cSFrançois Tigeot struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES]; 74216f7a2cSFrançois Tigeot unsigned int num_zones; 75216f7a2cSFrançois Tigeot struct ttm_mem_zone *zone_kernel; 763a2096e8SFrançois Tigeot #ifdef CONFIG_HIGHMEM 773a2096e8SFrançois Tigeot struct ttm_mem_zone *zone_highmem; 783a2096e8SFrançois Tigeot #else 79216f7a2cSFrançois Tigeot struct ttm_mem_zone *zone_dma32; 803a2096e8SFrançois Tigeot #endif 81216f7a2cSFrançois Tigeot }; 82216f7a2cSFrançois Tigeot 83216f7a2cSFrançois Tigeot extern int ttm_mem_global_init(struct ttm_mem_global *glob); 84216f7a2cSFrançois Tigeot extern void ttm_mem_global_release(struct ttm_mem_global *glob); 85216f7a2cSFrançois Tigeot extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, 86*932d855eSSergey Zigachev struct ttm_operation_ctx *ctx); 87216f7a2cSFrançois Tigeot extern void ttm_mem_global_free(struct ttm_mem_global *glob, 88216f7a2cSFrançois Tigeot uint64_t amount); 89216f7a2cSFrançois Tigeot extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob, 90*932d855eSSergey Zigachev struct page *page, uint64_t size, 91*932d855eSSergey Zigachev struct ttm_operation_ctx *ctx); 92216f7a2cSFrançois Tigeot extern void ttm_mem_global_free_page(struct ttm_mem_global *glob, 933f2dd94aSFrançois Tigeot struct page *page, uint64_t size); 94216f7a2cSFrançois Tigeot extern size_t ttm_round_pot(size_t size); 951dedbd3bSFrançois Tigeot extern uint64_t ttm_get_kernel_zone_memory_size(struct ttm_mem_global *glob); 96*932d855eSSergey Zigachev extern bool ttm_check_under_lowerlimit(struct ttm_mem_global *glob, 97*932d855eSSergey Zigachev uint64_t num_pages, struct ttm_operation_ctx *ctx); 98216f7a2cSFrançois Tigeot #endif 99