xref: /openbmc/linux/drivers/gpu/drm/ttm/ttm_module.c (revision 439057ec)
11297bf2eSDirk Hohndel /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2ba4e7d97SThomas Hellstrom /**************************************************************************
3ba4e7d97SThomas Hellstrom  *
4ba4e7d97SThomas Hellstrom  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
5ba4e7d97SThomas Hellstrom  * All Rights Reserved.
6ba4e7d97SThomas Hellstrom  *
7ba4e7d97SThomas Hellstrom  * Permission is hereby granted, free of charge, to any person obtaining a
8ba4e7d97SThomas Hellstrom  * copy of this software and associated documentation files (the
9ba4e7d97SThomas Hellstrom  * "Software"), to deal in the Software without restriction, including
10ba4e7d97SThomas Hellstrom  * without limitation the rights to use, copy, modify, merge, publish,
11ba4e7d97SThomas Hellstrom  * distribute, sub license, and/or sell copies of the Software, and to
12ba4e7d97SThomas Hellstrom  * permit persons to whom the Software is furnished to do so, subject to
13ba4e7d97SThomas Hellstrom  * the following conditions:
14ba4e7d97SThomas Hellstrom  *
15ba4e7d97SThomas Hellstrom  * The above copyright notice and this permission notice (including the
16ba4e7d97SThomas Hellstrom  * next paragraph) shall be included in all copies or substantial portions
17ba4e7d97SThomas Hellstrom  * of the Software.
18ba4e7d97SThomas Hellstrom  *
19ba4e7d97SThomas Hellstrom  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20ba4e7d97SThomas Hellstrom  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21ba4e7d97SThomas Hellstrom  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22ba4e7d97SThomas Hellstrom  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
23ba4e7d97SThomas Hellstrom  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24ba4e7d97SThomas Hellstrom  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25ba4e7d97SThomas Hellstrom  * USE OR OTHER DEALINGS IN THE SOFTWARE.
26ba4e7d97SThomas Hellstrom  *
27ba4e7d97SThomas Hellstrom  **************************************************************************/
28ba4e7d97SThomas Hellstrom /*
29ba4e7d97SThomas Hellstrom  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
30ba4e7d97SThomas Hellstrom  * 	    Jerome Glisse
31ba4e7d97SThomas Hellstrom  */
32ba4e7d97SThomas Hellstrom #include <linux/module.h>
33e9840be8SThomas Hellstrom #include <linux/device.h>
343bf3710eSThomas Hellström #include <linux/pgtable.h>
35e9840be8SThomas Hellstrom #include <linux/sched.h>
363763d635SChristian König #include <linux/debugfs.h>
37760285e7SDavid Howells #include <drm/drm_sysfs.h>
383bf3710eSThomas Hellström #include <drm/ttm/ttm_caching.h>
39e9840be8SThomas Hellstrom 
405cf82904SChristian König #include "ttm_module.h"
415cf82904SChristian König 
423bf3710eSThomas Hellström /**
43fcd0bbd6SChristian König  * DOC: TTM
44fcd0bbd6SChristian König  *
45fcd0bbd6SChristian König  * TTM is a memory manager for accelerator devices with dedicated memory.
46fcd0bbd6SChristian König  *
47fcd0bbd6SChristian König  * The basic idea is that resources are grouped together in buffer objects of
48fcd0bbd6SChristian König  * certain size and TTM handles lifetime, movement and CPU mappings of those
49fcd0bbd6SChristian König  * objects.
50fcd0bbd6SChristian König  *
51fcd0bbd6SChristian König  * TODO: Add more design background and information here.
52fcd0bbd6SChristian König  */
53fcd0bbd6SChristian König 
54fcd0bbd6SChristian König /**
553bf3710eSThomas Hellström  * ttm_prot_from_caching - Modify the page protection according to the
563bf3710eSThomas Hellström  * ttm cacing mode
573bf3710eSThomas Hellström  * @caching: The ttm caching mode
583bf3710eSThomas Hellström  * @tmp: The original page protection
593bf3710eSThomas Hellström  *
603bf3710eSThomas Hellström  * Return: The modified page protection
613bf3710eSThomas Hellström  */
ttm_prot_from_caching(enum ttm_caching caching,pgprot_t tmp)623bf3710eSThomas Hellström pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
633bf3710eSThomas Hellström {
643bf3710eSThomas Hellström 	/* Cached mappings need no adjustment */
653bf3710eSThomas Hellström 	if (caching == ttm_cached)
663bf3710eSThomas Hellström 		return tmp;
673bf3710eSThomas Hellström 
683bf3710eSThomas Hellström #if defined(__i386__) || defined(__x86_64__)
693bf3710eSThomas Hellström 	if (caching == ttm_write_combined)
703bf3710eSThomas Hellström 		tmp = pgprot_writecombine(tmp);
71016017a1SJohannes Berg #ifndef CONFIG_UML
723bf3710eSThomas Hellström 	else if (boot_cpu_data.x86 > 3)
733bf3710eSThomas Hellström 		tmp = pgprot_noncached(tmp);
74016017a1SJohannes Berg #endif /* CONFIG_UML */
75016017a1SJohannes Berg #endif /* __i386__ || __x86_64__ */
763bf3710eSThomas Hellström #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
77*439057ecSHuacai Chen 	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__)
783bf3710eSThomas Hellström 	if (caching == ttm_write_combined)
793bf3710eSThomas Hellström 		tmp = pgprot_writecombine(tmp);
803bf3710eSThomas Hellström 	else
813bf3710eSThomas Hellström 		tmp = pgprot_noncached(tmp);
823bf3710eSThomas Hellström #endif
833bf3710eSThomas Hellström #if defined(__sparc__)
843bf3710eSThomas Hellström 	tmp = pgprot_noncached(tmp);
853bf3710eSThomas Hellström #endif
863bf3710eSThomas Hellström 	return tmp;
873bf3710eSThomas Hellström }
883bf3710eSThomas Hellström 
89ba4e7d97SThomas Hellstrom MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse");
90ba4e7d97SThomas Hellstrom MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)");
91ba4e7d97SThomas Hellstrom MODULE_LICENSE("GPL and additional rights");
92