1b86cbe23SFrançois Tigeot /* 2f0bba3d1SFrançois Tigeot * Copyright (c) 2015-2018 François Tigeot <ftigeot@wolfpond.org> 3b86cbe23SFrançois Tigeot * All rights reserved. 4b86cbe23SFrançois Tigeot * 5b86cbe23SFrançois Tigeot * Redistribution and use in source and binary forms, with or without 6b86cbe23SFrançois Tigeot * modification, are permitted provided that the following conditions 7b86cbe23SFrançois Tigeot * are met: 8b86cbe23SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright 9b86cbe23SFrançois Tigeot * notice unmodified, this list of conditions, and the following 10b86cbe23SFrançois Tigeot * disclaimer. 11b86cbe23SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright 12b86cbe23SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the 13b86cbe23SFrançois Tigeot * documentation and/or other materials provided with the distribution. 14b86cbe23SFrançois Tigeot * 15b86cbe23SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16b86cbe23SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17b86cbe23SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18b86cbe23SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19b86cbe23SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20b86cbe23SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21b86cbe23SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22b86cbe23SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23b86cbe23SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24b86cbe23SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25b86cbe23SFrançois Tigeot */ 26b86cbe23SFrançois Tigeot 27b86cbe23SFrançois Tigeot #ifndef _ASM_CACHEFLUSH_H_ 28b86cbe23SFrançois Tigeot #define _ASM_CACHEFLUSH_H_ 29b86cbe23SFrançois Tigeot 30fc8df113SFrançois Tigeot #include <asm/special_insns.h> 31fc8df113SFrançois Tigeot 321b13d190SFrançois Tigeot #include <vm/pmap.h> 331b13d190SFrançois Tigeot #include <vm/vm_page.h> 341b13d190SFrançois Tigeot 35c9fdb286SFrançois Tigeot static inline int set_memory_wc(unsigned long vaddr, int numpages) 36c9fdb286SFrançois Tigeot { 3796acd33eSMatthew Dillon pmap_change_attr(vaddr, numpages, PAT_WRITE_COMBINING); 38c9fdb286SFrançois Tigeot return 0; 39c9fdb286SFrançois Tigeot } 40c9fdb286SFrançois Tigeot 41c9fdb286SFrançois Tigeot static inline int set_memory_wb(unsigned long vaddr, int numpages) 42c9fdb286SFrançois Tigeot { 4396acd33eSMatthew Dillon pmap_change_attr(vaddr, numpages, PAT_WRITE_BACK); 44c9fdb286SFrançois Tigeot return 0; 45c9fdb286SFrançois Tigeot } 46c9fdb286SFrançois Tigeot 47f0bba3d1SFrançois Tigeot static inline int set_pages_uc(struct page *page, int num_pages) 48b86cbe23SFrançois Tigeot { 49f0bba3d1SFrançois Tigeot struct vm_page *p = (struct vm_page *)page; 50f0bba3d1SFrançois Tigeot 51f0bba3d1SFrançois Tigeot pmap_change_attr(PHYS_TO_DMAP(VM_PAGE_TO_PHYS(p)), 5296acd33eSMatthew Dillon num_pages, PAT_UNCACHED); 53b86cbe23SFrançois Tigeot 54b86cbe23SFrançois Tigeot return 0; 55b86cbe23SFrançois Tigeot } 56b86cbe23SFrançois Tigeot 57f0bba3d1SFrançois Tigeot static inline int set_pages_wb(struct page *page, int num_pages) 58c441a1f1SFrançois Tigeot { 59f0bba3d1SFrançois Tigeot struct vm_page *p = (struct vm_page *)page; 60f0bba3d1SFrançois Tigeot 61f0bba3d1SFrançois Tigeot pmap_change_attr(PHYS_TO_DMAP(VM_PAGE_TO_PHYS(p)), 62c441a1f1SFrançois Tigeot num_pages, PAT_WRITE_BACK); 63c441a1f1SFrançois Tigeot 64c441a1f1SFrançois Tigeot return 0; 65c441a1f1SFrançois Tigeot } 66c441a1f1SFrançois Tigeot 67*51933d89SFrançois Tigeot static inline int 68*51933d89SFrançois Tigeot set_pages_array_uc(struct page **pages, int addrinarray) 69*51933d89SFrançois Tigeot { 70*51933d89SFrançois Tigeot for (int i = 0; i < addrinarray; i++) 71*51933d89SFrançois Tigeot pmap_page_set_memattr((struct vm_page *)pages[i], VM_MEMATTR_UNCACHEABLE); 72*51933d89SFrançois Tigeot 73*51933d89SFrançois Tigeot return 0; 74*51933d89SFrançois Tigeot } 75*51933d89SFrançois Tigeot 76*51933d89SFrançois Tigeot static inline int 77*51933d89SFrançois Tigeot set_pages_array_wb(struct page **pages, int addrinarray) 78*51933d89SFrançois Tigeot { 79*51933d89SFrançois Tigeot for (int i = 0; i < addrinarray; i++) 80*51933d89SFrançois Tigeot pmap_page_set_memattr((struct vm_page *)pages[i], VM_MEMATTR_WRITE_BACK); 81*51933d89SFrançois Tigeot 82*51933d89SFrançois Tigeot return 0; 83*51933d89SFrançois Tigeot } 84*51933d89SFrançois Tigeot 85*51933d89SFrançois Tigeot static inline int 86*51933d89SFrançois Tigeot set_pages_array_wc(struct page **pages, int addrinarray) 87*51933d89SFrançois Tigeot { 88*51933d89SFrançois Tigeot for (int i = 0; i < addrinarray; i++) 89*51933d89SFrançois Tigeot pmap_page_set_memattr((struct vm_page *)pages[i], VM_MEMATTR_WRITE_COMBINING); 90*51933d89SFrançois Tigeot 91*51933d89SFrançois Tigeot return 0; 92*51933d89SFrançois Tigeot } 93*51933d89SFrançois Tigeot 94b86cbe23SFrançois Tigeot #endif /* _ASM_CACHEFLUSH_H_ */ 95