1 /* $OpenBSD: set_memory.h,v 1.4 2022/01/14 06:53:14 jsg Exp $ */ 2 /* 3 * Copyright (c) 2013, 2014, 2015 Mark Kettenis 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef _ASM_SET_MEMORY_H 19 #define _ASM_SET_MEMORY_H 20 21 #include <sys/systm.h> 22 #include <sys/atomic.h> 23 24 #include <sys/param.h> /* for PAGE_SIZE on i386 */ 25 #include <uvm/uvm_extern.h> 26 27 #include <machine/pmap.h> 28 29 #if defined(__amd64__) || defined(__i386__) 30 31 static inline int 32 set_pages_array_wb(struct vm_page **pages, int addrinarray) 33 { 34 int i; 35 36 for (i = 0; i < addrinarray; i++) 37 atomic_clearbits_int(&pages[i]->pg_flags, PG_PMAP_WC); 38 39 return 0; 40 } 41 42 static inline int 43 set_pages_array_wc(struct vm_page **pages, int addrinarray) 44 { 45 int i; 46 47 for (i = 0; i < addrinarray; i++) 48 atomic_setbits_int(&pages[i]->pg_flags, PG_PMAP_WC); 49 50 return 0; 51 } 52 53 static inline int 54 set_pages_array_uc(struct vm_page **pages, int addrinarray) 55 { 56 /* XXX */ 57 return 0; 58 } 59 60 static inline int 61 set_pages_wb(struct vm_page *page, int numpages) 62 { 63 struct vm_page *pg; 64 paddr_t start = VM_PAGE_TO_PHYS(page); 65 int i; 66 67 for (i = 0; i < numpages; i++) { 68 pg = PHYS_TO_VM_PAGE(start + (i * PAGE_SIZE)); 69 if (pg != NULL) 70 atomic_clearbits_int(&pg->pg_flags, PG_PMAP_WC); 71 } 72 73 return 0; 74 } 75 76 static inline int 77 set_pages_uc(struct vm_page *page, int numpages) 78 { 79 /* XXX */ 80 return 0; 81 } 82 83 #endif /* defined(__amd64__) || defined(__i386__) */ 84 85 #endif 86