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 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 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 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 int lkpi_set_pages_attr(struct page *page, int numpages, vm_memattr_t ma); 66 67 static inline int 68 set_pages_uc(struct page *page, int numpages) 69 { 70 return (lkpi_set_pages_attr(page, numpages, VM_MEMATTR_UNCACHEABLE)); 71 } 72 73 static inline int 74 set_pages_wc(struct page *page, int numpages) 75 { 76 #ifdef VM_MEMATTR_WRITE_COMBINING 77 return (lkpi_set_pages_attr(page, numpages, VM_MEMATTR_WRITE_COMBINING)); 78 #else 79 return (set_pages_uc(page, numpages)); 80 #endif 81 } 82 83 static inline int 84 set_pages_wb(struct page *page, int numpages) 85 { 86 return (lkpi_set_pages_attr(page, numpages, VM_MEMATTR_WRITE_BACK)); 87 } 88 89 static inline int 90 set_pages_array_wb(struct page **pages, int addrinarray) 91 { 92 int i; 93 94 for (i = 0; i < addrinarray; i++) 95 set_pages_wb(pages[i], 1); 96 return (0); 97 } 98 99 static inline int 100 set_pages_array_wc(struct page **pages, int addrinarray) 101 { 102 int i; 103 104 for (i = 0; i < addrinarray; i++) 105 set_pages_wc(pages[i], 1); 106 return (0); 107 } 108 109 static inline int 110 set_pages_array_uc(struct page **pages, int addrinarray) 111 { 112 int i; 113 114 for (i = 0; i < addrinarray; i++) 115 set_pages_uc(pages[i], 1); 116 return (0); 117 } 118 119 #endif /* _LINUXKPI_ASM_SET_MEMORY_H_ */ 120