1 /* $NetBSD: ttm_set_memory.h,v 1.4 2021/12/19 12:40:44 riastradh Exp $ */ 2 3 /************************************************************************** 4 * 5 * Copyright (c) 2018 Advanced Micro Devices, Inc. 6 * All Rights Reserved. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sub license, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice (including the 17 * next paragraph) shall be included in all copies or substantial portions 18 * of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 23 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 24 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 26 * USE OR OTHER DEALINGS IN THE SOFTWARE. 27 * 28 **************************************************************************/ 29 /* 30 * Authors: Huang Rui <ray.huang (at) amd.com> 31 */ 32 33 #ifndef TTM_SET_MEMORY 34 #define TTM_SET_MEMORY 35 36 #include <linux/mm.h> 37 38 #if defined(CONFIG_X86) && !defined(__NetBSD__) 39 40 #include <asm/set_memory.h> 41 42 static inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray) 43 { 44 return set_pages_array_wb(pages, addrinarray); 45 } 46 47 static inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray) 48 { 49 return set_pages_array_wc(pages, addrinarray); 50 } 51 52 static inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray) 53 { 54 return set_pages_array_uc(pages, addrinarray); 55 } 56 57 static inline int ttm_set_pages_wb(struct page *page, int numpages) 58 { 59 return set_pages_wb(page, numpages); 60 } 61 62 static inline int ttm_set_pages_wc(struct page *page, int numpages) 63 { 64 unsigned long addr = (unsigned long)page_address(page); 65 66 return set_memory_wc(addr, numpages); 67 } 68 69 static inline int ttm_set_pages_uc(struct page *page, int numpages) 70 { 71 return set_pages_uc(page, numpages); 72 } 73 74 #else /* for CONFIG_X86 */ 75 76 #if IS_ENABLED(CONFIG_AGP) 77 78 #include <asm/agp.h> 79 80 static inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray) 81 { 82 int i; 83 84 for (i = 0; i < addrinarray; i++) 85 unmap_page_from_agp(pages[i]); 86 return 0; 87 } 88 89 static inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray) 90 { 91 int i; 92 93 for (i = 0; i < addrinarray; i++) 94 map_page_into_agp(pages[i]); 95 return 0; 96 } 97 98 static inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray) 99 { 100 int i; 101 102 for (i = 0; i < addrinarray; i++) 103 map_page_into_agp(pages[i]); 104 return 0; 105 } 106 107 static inline int ttm_set_pages_wb(struct page *page, int numpages) 108 { 109 int i; 110 111 for (i = 0; i < numpages; i++) 112 unmap_page_from_agp(page++); 113 return 0; 114 } 115 116 #else /* for CONFIG_AGP */ 117 118 static inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray) 119 { 120 return 0; 121 } 122 123 static inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray) 124 { 125 return 0; 126 } 127 128 static inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray) 129 { 130 return 0; 131 } 132 133 static inline int ttm_set_pages_wb(struct page *page, int numpages) 134 { 135 return 0; 136 } 137 138 #endif /* for CONFIG_AGP */ 139 140 static inline int ttm_set_pages_wc(struct page *page, int numpages) 141 { 142 return 0; 143 } 144 145 static inline int ttm_set_pages_uc(struct page *page, int numpages) 146 { 147 return 0; 148 } 149 150 #endif /* for CONFIG_X86 */ 151 152 #endif 153