18c2ecf20Sopenharmony_ci/**************************************************************************
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright (c) 2018 Advanced Micro Devices, Inc.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
128c2ecf20Sopenharmony_ci * the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
168c2ecf20Sopenharmony_ci * of the Software.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
218c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
228c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
238c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
248c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci **************************************************************************/
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * Authors: Huang Rui <ray.huang@amd.com>
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#ifndef TTM_SET_MEMORY
328c2ecf20Sopenharmony_ci#define TTM_SET_MEMORY
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <linux/mm.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#ifdef CONFIG_X86
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <asm/set_memory.h>
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray)
418c2ecf20Sopenharmony_ci{
428c2ecf20Sopenharmony_ci	return set_pages_array_wb(pages, addrinarray);
438c2ecf20Sopenharmony_ci}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	return set_pages_array_wc(pages, addrinarray);
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci	return set_pages_array_uc(pages, addrinarray);
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_wb(struct page *page, int numpages)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	return set_pages_wb(page, numpages);
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_wc(struct page *page, int numpages)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	unsigned long addr = (unsigned long)page_address(page);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	return set_memory_wc(addr, numpages);
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_uc(struct page *page, int numpages)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	return set_pages_uc(page, numpages);
708c2ecf20Sopenharmony_ci}
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#else /* for CONFIG_X86 */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_AGP)
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#include <asm/agp.h>
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	int i;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	for (i = 0; i < addrinarray; i++)
838c2ecf20Sopenharmony_ci		unmap_page_from_agp(pages[i]);
848c2ecf20Sopenharmony_ci	return 0;
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray)
888c2ecf20Sopenharmony_ci{
898c2ecf20Sopenharmony_ci	int i;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	for (i = 0; i < addrinarray; i++)
928c2ecf20Sopenharmony_ci		map_page_into_agp(pages[i]);
938c2ecf20Sopenharmony_ci	return 0;
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	int i;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	for (i = 0; i < addrinarray; i++)
1018c2ecf20Sopenharmony_ci		map_page_into_agp(pages[i]);
1028c2ecf20Sopenharmony_ci	return 0;
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_wb(struct page *page, int numpages)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	int i;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	for (i = 0; i < numpages; i++)
1108c2ecf20Sopenharmony_ci		unmap_page_from_agp(page++);
1118c2ecf20Sopenharmony_ci	return 0;
1128c2ecf20Sopenharmony_ci}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#else /* for CONFIG_AGP */
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray)
1178c2ecf20Sopenharmony_ci{
1188c2ecf20Sopenharmony_ci	return 0;
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray)
1228c2ecf20Sopenharmony_ci{
1238c2ecf20Sopenharmony_ci	return 0;
1248c2ecf20Sopenharmony_ci}
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	return 0;
1298c2ecf20Sopenharmony_ci}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_wb(struct page *page, int numpages)
1328c2ecf20Sopenharmony_ci{
1338c2ecf20Sopenharmony_ci	return 0;
1348c2ecf20Sopenharmony_ci}
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#endif /* for CONFIG_AGP */
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_wc(struct page *page, int numpages)
1398c2ecf20Sopenharmony_ci{
1408c2ecf20Sopenharmony_ci	return 0;
1418c2ecf20Sopenharmony_ci}
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_cistatic inline int ttm_set_pages_uc(struct page *page, int numpages)
1448c2ecf20Sopenharmony_ci{
1458c2ecf20Sopenharmony_ci	return 0;
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#endif /* for CONFIG_X86 */
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#endif
151