2009-06-10 21:20:19 +08:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TTM_MEMORY_H
|
|
|
|
#define TTM_MEMORY_H
|
|
|
|
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/spinlock.h>
|
2011-11-24 09:12:59 +08:00
|
|
|
#include <linux/bug.h>
|
2009-06-10 21:20:19 +08:00
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/errno.h>
|
2009-08-17 22:28:39 +08:00
|
|
|
#include <linux/kobject.h>
|
2009-11-20 00:29:45 +08:00
|
|
|
#include <linux/mm.h>
|
2017-12-08 15:09:50 +08:00
|
|
|
#include "ttm_bo_api.h"
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct ttm_mem_global - Global memory accounting structure.
|
|
|
|
*
|
|
|
|
* @shrink: A single callback to shrink TTM memory usage. Extend this
|
|
|
|
* to a linked list to be able to handle multiple callbacks when needed.
|
|
|
|
* @swap_queue: A workqueue to handle shrinking in low memory situations. We
|
|
|
|
* need a separate workqueue since it will spend a lot of time waiting
|
|
|
|
* for the GPU, and this will otherwise block other workqueue tasks(?)
|
|
|
|
* At this point we use only a single-threaded workqueue.
|
|
|
|
* @work: The workqueue callback for the shrink queue.
|
|
|
|
* @lock: Lock to protect the @shrink - and the memory accounting members,
|
|
|
|
* that is, essentially the whole structure with some exceptions.
|
2018-02-05 17:57:07 +08:00
|
|
|
* @lower_mem_limit: include lower limit of swap space and lower limit of
|
|
|
|
* system memory.
|
2009-08-17 22:28:39 +08:00
|
|
|
* @zones: Array of pointers to accounting zones.
|
|
|
|
* @num_zones: Number of populated entries in the @zones array.
|
|
|
|
* @zone_kernel: Pointer to the kernel zone.
|
|
|
|
* @zone_highmem: Pointer to the highmem zone if there is one.
|
|
|
|
* @zone_dma32: Pointer to the dma32 zone if there is one.
|
2009-06-10 21:20:19 +08:00
|
|
|
*
|
|
|
|
* Note that this structure is not per device. It should be global for all
|
|
|
|
* graphics devices.
|
|
|
|
*/
|
|
|
|
|
2009-08-17 22:28:39 +08:00
|
|
|
#define TTM_MEM_MAX_ZONES 2
|
|
|
|
struct ttm_mem_zone;
|
2018-10-19 19:49:05 +08:00
|
|
|
extern struct ttm_mem_global {
|
2009-08-17 22:28:39 +08:00
|
|
|
struct kobject kobj;
|
2009-06-10 21:20:19 +08:00
|
|
|
struct workqueue_struct *swap_queue;
|
|
|
|
struct work_struct work;
|
|
|
|
spinlock_t lock;
|
2018-02-05 17:57:07 +08:00
|
|
|
uint64_t lower_mem_limit;
|
2009-08-17 22:28:39 +08:00
|
|
|
struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES];
|
|
|
|
unsigned int num_zones;
|
|
|
|
struct ttm_mem_zone *zone_kernel;
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
struct ttm_mem_zone *zone_highmem;
|
|
|
|
#else
|
|
|
|
struct ttm_mem_zone *zone_dma32;
|
|
|
|
#endif
|
2018-10-19 19:49:05 +08:00
|
|
|
} ttm_mem_glob;
|
2009-06-10 21:20:19 +08:00
|
|
|
|
|
|
|
extern int ttm_mem_global_init(struct ttm_mem_global *glob);
|
|
|
|
extern void ttm_mem_global_release(struct ttm_mem_global *glob);
|
|
|
|
extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
|
2017-12-08 15:09:50 +08:00
|
|
|
struct ttm_operation_ctx *ctx);
|
2009-06-10 21:20:19 +08:00
|
|
|
extern void ttm_mem_global_free(struct ttm_mem_global *glob,
|
2009-08-17 22:28:39 +08:00
|
|
|
uint64_t amount);
|
|
|
|
extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
|
2017-12-08 15:21:18 +08:00
|
|
|
struct page *page, uint64_t size,
|
|
|
|
struct ttm_operation_ctx *ctx);
|
2009-08-17 22:28:39 +08:00
|
|
|
extern void ttm_mem_global_free_page(struct ttm_mem_global *glob,
|
2017-07-04 22:56:24 +08:00
|
|
|
struct page *page, uint64_t size);
|
2009-06-10 21:20:19 +08:00
|
|
|
extern size_t ttm_round_pot(size_t size);
|
2016-07-27 19:12:15 +08:00
|
|
|
extern uint64_t ttm_get_kernel_zone_memory_size(struct ttm_mem_global *glob);
|
2018-02-05 17:57:07 +08:00
|
|
|
extern bool ttm_check_under_lowerlimit(struct ttm_mem_global *glob,
|
|
|
|
uint64_t num_pages, struct ttm_operation_ctx *ctx);
|
2009-06-10 21:20:19 +08:00
|
|
|
#endif
|