xref: /linux/drivers/gpu/drm/ttm/ttm_module.c (revision 5b0764a53235d3c77e1ed674e836e1b3fe1a4b1f)
1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /**************************************************************************
3  *
4  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
23  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25  * USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *
27  **************************************************************************/
28 /*
29  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
30  * 	    Jerome Glisse
31  */
32 #include <linux/module.h>
33 #include <linux/device.h>
34 #include <linux/pgtable.h>
35 #include <linux/sched.h>
36 #include <linux/debugfs.h>
37 #include <drm/ttm/ttm_caching.h>
38 
39 #include "ttm_module.h"
40 
41 /**
42  * DOC: TTM
43  *
44  * TTM is a memory manager for accelerator devices with dedicated memory.
45  *
46  * The basic idea is that resources are grouped together in buffer objects of
47  * certain size and TTM handles lifetime, movement and CPU mappings of those
48  * objects.
49  *
50  * TODO: Add more design background and information here.
51  */
52 
53 /**
54  * ttm_prot_from_caching - Modify the page protection according to the
55  * ttm cacing mode
56  * @caching: The ttm caching mode
57  * @tmp: The original page protection
58  *
59  * Return: The modified page protection
60  */
61 pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
62 {
63 	/* Cached mappings need no adjustment */
64 	if (caching == ttm_cached)
65 		return tmp;
66 
67 #if defined(__i386__) || defined(__x86_64__)
68 	if (caching == ttm_write_combined)
69 		tmp = pgprot_writecombine(tmp);
70 #ifndef CONFIG_UML
71 	else if (boot_cpu_data.x86 > 3)
72 		tmp = pgprot_noncached(tmp);
73 #endif /* CONFIG_UML */
74 #endif /* __i386__ || __x86_64__ */
75 #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
76 	defined(__powerpc__) || defined(__mips__) || defined(__loongarch__) || \
77 	defined(__riscv)
78 	if (caching == ttm_write_combined)
79 		tmp = pgprot_writecombine(tmp);
80 	else
81 		tmp = pgprot_noncached(tmp);
82 #endif
83 #if defined(__sparc__)
84 	tmp = pgprot_noncached(tmp);
85 #endif
86 	return tmp;
87 }
88 
89 MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse");
90 MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)");
91 MODULE_LICENSE("GPL and additional rights");
92