GNU Linux-libre 4.19.263-gnu1
[releases.git] / include / drm / ttm / ttm_set_memory.h
1 /**************************************************************************
2  *
3  * Copyright (c) 2018 Advanced Micro Devices, Inc.
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  * Authors: Huang Rui <ray.huang@amd.com>
29  */
30
31 #ifndef TTM_SET_MEMORY
32 #define TTM_SET_MEMORY
33
34 #include <linux/mm.h>
35
36 #ifdef CONFIG_X86
37
38 #include <asm/set_memory.h>
39
40 static inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray)
41 {
42         return set_pages_array_wb(pages, addrinarray);
43 }
44
45 static inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray)
46 {
47         return set_pages_array_wc(pages, addrinarray);
48 }
49
50 static inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray)
51 {
52         return set_pages_array_uc(pages, addrinarray);
53 }
54
55 static inline int ttm_set_pages_wb(struct page *page, int numpages)
56 {
57         return set_pages_wb(page, numpages);
58 }
59
60 static inline int ttm_set_pages_wc(struct page *page, int numpages)
61 {
62         unsigned long addr = (unsigned long)page_address(page);
63
64         return set_memory_wc(addr, numpages);
65 }
66
67 static inline int ttm_set_pages_uc(struct page *page, int numpages)
68 {
69         return set_pages_uc(page, numpages);
70 }
71
72 #else /* for CONFIG_X86 */
73
74 #if IS_ENABLED(CONFIG_AGP)
75
76 #include <asm/agp.h>
77
78 static inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray)
79 {
80         int i;
81
82         for (i = 0; i < addrinarray; i++)
83                 unmap_page_from_agp(pages[i]);
84         return 0;
85 }
86
87 static inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray)
88 {
89         int i;
90
91         for (i = 0; i < addrinarray; i++)
92                 map_page_into_agp(pages[i]);
93         return 0;
94 }
95
96 static inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray)
97 {
98         int i;
99
100         for (i = 0; i < addrinarray; i++)
101                 map_page_into_agp(pages[i]);
102         return 0;
103 }
104
105 static inline int ttm_set_pages_wb(struct page *page, int numpages)
106 {
107         int i;
108
109         for (i = 0; i < numpages; i++)
110                 unmap_page_from_agp(page++);
111         return 0;
112 }
113
114 #else /* for CONFIG_AGP */
115
116 static inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray)
117 {
118         return 0;
119 }
120
121 static inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray)
122 {
123         return 0;
124 }
125
126 static inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray)
127 {
128         return 0;
129 }
130
131 static inline int ttm_set_pages_wb(struct page *page, int numpages)
132 {
133         return 0;
134 }
135
136 #endif /* for CONFIG_AGP */
137
138 static inline int ttm_set_pages_wc(struct page *page, int numpages)
139 {
140         return 0;
141 }
142
143 static inline int ttm_set_pages_uc(struct page *page, int numpages)
144 {
145         return 0;
146 }
147
148 #endif /* for CONFIG_X86 */
149
150 #endif