1b86cbe23SFrançois Tigeot /*
2*07f8725aSFrançois Tigeot * Copyright (c) 2015-2019 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
35*07f8725aSFrançois Tigeot static inline int
set_memory_uc(unsigned long addr,int numpages)36*07f8725aSFrançois Tigeot set_memory_uc(unsigned long addr, int numpages)
37*07f8725aSFrançois Tigeot {
38*07f8725aSFrançois Tigeot pmap_change_attr(addr, numpages, PAT_UNCACHED);
39*07f8725aSFrançois Tigeot return 0;
40*07f8725aSFrançois Tigeot }
41*07f8725aSFrançois Tigeot
set_memory_wc(unsigned long vaddr,int numpages)42c9fdb286SFrançois Tigeot static inline int set_memory_wc(unsigned long vaddr, int numpages)
43c9fdb286SFrançois Tigeot {
4496acd33eSMatthew Dillon pmap_change_attr(vaddr, numpages, PAT_WRITE_COMBINING);
45c9fdb286SFrançois Tigeot return 0;
46c9fdb286SFrançois Tigeot }
47c9fdb286SFrançois Tigeot
set_memory_wb(unsigned long vaddr,int numpages)48c9fdb286SFrançois Tigeot static inline int set_memory_wb(unsigned long vaddr, int numpages)
49c9fdb286SFrançois Tigeot {
5096acd33eSMatthew Dillon pmap_change_attr(vaddr, numpages, PAT_WRITE_BACK);
51c9fdb286SFrançois Tigeot return 0;
52c9fdb286SFrançois Tigeot }
53c9fdb286SFrançois Tigeot
set_pages_uc(struct page * page,int num_pages)54f0bba3d1SFrançois Tigeot static inline int set_pages_uc(struct page *page, int num_pages)
55b86cbe23SFrançois Tigeot {
56f0bba3d1SFrançois Tigeot struct vm_page *p = (struct vm_page *)page;
57f0bba3d1SFrançois Tigeot
58f0bba3d1SFrançois Tigeot pmap_change_attr(PHYS_TO_DMAP(VM_PAGE_TO_PHYS(p)),
5996acd33eSMatthew Dillon num_pages, PAT_UNCACHED);
60b86cbe23SFrançois Tigeot
61b86cbe23SFrançois Tigeot return 0;
62b86cbe23SFrançois Tigeot }
63b86cbe23SFrançois Tigeot
set_pages_wb(struct page * page,int num_pages)64f0bba3d1SFrançois Tigeot static inline int set_pages_wb(struct page *page, int num_pages)
65c441a1f1SFrançois Tigeot {
66f0bba3d1SFrançois Tigeot struct vm_page *p = (struct vm_page *)page;
67f0bba3d1SFrançois Tigeot
68f0bba3d1SFrançois Tigeot pmap_change_attr(PHYS_TO_DMAP(VM_PAGE_TO_PHYS(p)),
69c441a1f1SFrançois Tigeot num_pages, PAT_WRITE_BACK);
70c441a1f1SFrançois Tigeot
71c441a1f1SFrançois Tigeot return 0;
72c441a1f1SFrançois Tigeot }
73c441a1f1SFrançois Tigeot
7451933d89SFrançois Tigeot static inline int
set_pages_array_uc(struct page ** pages,int addrinarray)7551933d89SFrançois Tigeot set_pages_array_uc(struct page **pages, int addrinarray)
7651933d89SFrançois Tigeot {
7751933d89SFrançois Tigeot for (int i = 0; i < addrinarray; i++)
7851933d89SFrançois Tigeot pmap_page_set_memattr((struct vm_page *)pages[i], VM_MEMATTR_UNCACHEABLE);
7951933d89SFrançois Tigeot
8051933d89SFrançois Tigeot return 0;
8151933d89SFrançois Tigeot }
8251933d89SFrançois Tigeot
8351933d89SFrançois Tigeot static inline int
set_pages_array_wb(struct page ** pages,int addrinarray)8451933d89SFrançois Tigeot set_pages_array_wb(struct page **pages, int addrinarray)
8551933d89SFrançois Tigeot {
8651933d89SFrançois Tigeot for (int i = 0; i < addrinarray; i++)
8751933d89SFrançois Tigeot pmap_page_set_memattr((struct vm_page *)pages[i], VM_MEMATTR_WRITE_BACK);
8851933d89SFrançois Tigeot
8951933d89SFrançois Tigeot return 0;
9051933d89SFrançois Tigeot }
9151933d89SFrançois Tigeot
9251933d89SFrançois Tigeot static inline int
set_pages_array_wc(struct page ** pages,int addrinarray)9351933d89SFrançois Tigeot set_pages_array_wc(struct page **pages, int addrinarray)
9451933d89SFrançois Tigeot {
9551933d89SFrançois Tigeot for (int i = 0; i < addrinarray; i++)
9651933d89SFrançois Tigeot pmap_page_set_memattr((struct vm_page *)pages[i], VM_MEMATTR_WRITE_COMBINING);
9751933d89SFrançois Tigeot
9851933d89SFrançois Tigeot return 0;
9951933d89SFrançois Tigeot }
10051933d89SFrançois Tigeot
101b86cbe23SFrançois Tigeot #endif /* _ASM_CACHEFLUSH_H_ */
102