1 /*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2016 Matt Macy (mmacy@nextbsd.org)
4 * Copyright (c) 2017 Mellanox Technologies, Ltd.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
12 * disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef _LINUXKPI_ASM_SET_MEMORY_H_
30 #define _LINUXKPI_ASM_SET_MEMORY_H_
31
32 #include <linux/page.h>
33
34 static inline int
set_memory_uc(unsigned long addr,int numpages)35 set_memory_uc(unsigned long addr, int numpages)
36 {
37 vm_size_t len;
38
39 len = (vm_size_t)numpages << PAGE_SHIFT;
40 return (-pmap_change_attr((void *)addr, len, VM_MEMATTR_UNCACHEABLE));
41 }
42
43 static inline int
set_memory_wc(unsigned long addr,int numpages)44 set_memory_wc(unsigned long addr, int numpages)
45 {
46 #ifdef VM_MEMATTR_WRITE_COMBINING
47 vm_size_t len;
48
49 len = (vm_size_t)numpages << PAGE_SHIFT;
50 return (-pmap_change_attr((void *)addr, len, VM_MEMATTR_WRITE_COMBINING));
51 #else
52 return (set_memory_uc(addr, numpages));
53 #endif
54 }
55
56 static inline int
set_memory_wb(unsigned long addr,int numpages)57 set_memory_wb(unsigned long addr, int numpages)
58 {
59 vm_size_t len;
60
61 len = (vm_size_t)numpages << PAGE_SHIFT;
62 return (-pmap_change_attr((void *)addr, len, VM_MEMATTR_WRITE_BACK));
63 }
64
65 static inline int
set_pages_uc(struct page * page,int numpages)66 set_pages_uc(struct page *page, int numpages)
67 {
68 return (lkpi_set_pages_attr(page, numpages, VM_MEMATTR_UNCACHEABLE));
69 }
70
71 static inline int
set_pages_wc(struct page * page,int numpages)72 set_pages_wc(struct page *page, int numpages)
73 {
74 #ifdef VM_MEMATTR_WRITE_COMBINING
75 return (lkpi_set_pages_attr(page, numpages, VM_MEMATTR_WRITE_COMBINING));
76 #else
77 return (set_pages_uc(page, numpages));
78 #endif
79 }
80
81 static inline int
set_pages_wb(struct page * page,int numpages)82 set_pages_wb(struct page *page, int numpages)
83 {
84 return (lkpi_set_pages_attr(page, numpages, VM_MEMATTR_WRITE_BACK));
85 }
86
87 static inline int
set_pages_array_wb(struct page ** pages,int addrinarray)88 set_pages_array_wb(struct page **pages, int addrinarray)
89 {
90 int i;
91
92 for (i = 0; i < addrinarray; i++)
93 set_pages_wb(pages[i], 1);
94 return (0);
95 }
96
97 static inline int
set_pages_array_wc(struct page ** pages,int addrinarray)98 set_pages_array_wc(struct page **pages, int addrinarray)
99 {
100 int i;
101
102 for (i = 0; i < addrinarray; i++)
103 set_pages_wc(pages[i], 1);
104 return (0);
105 }
106
107 static inline int
set_pages_array_uc(struct page ** pages,int addrinarray)108 set_pages_array_uc(struct page **pages, int addrinarray)
109 {
110 int i;
111
112 for (i = 0; i < addrinarray; i++)
113 set_pages_uc(pages[i], 1);
114 return (0);
115 }
116
117 #endif /* _LINUXKPI_ASM_SET_MEMORY_H_ */
118