1 /* $OpenBSD: set_memory.h,v 1.5 2023/01/01 01:34:58 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/types.h> 22 #include <sys/systm.h> 23 #include <sys/atomic.h> 24 25 #include <sys/param.h> /* for PAGE_SIZE on i386 */ 26 #include <uvm/uvm_extern.h> 27 28 #include <machine/pmap.h> 29 30 #if defined(__amd64__) || defined(__i386__) 31 32 static inline int 33 set_pages_array_wb(struct vm_page **pages, int addrinarray) 34 { 35 int i; 36 37 for (i = 0; i < addrinarray; i++) 38 atomic_clearbits_int(&pages[i]->pg_flags, PG_PMAP_WC); 39 40 return 0; 41 } 42 43 static inline int 44 set_pages_array_wc(struct vm_page **pages, int addrinarray) 45 { 46 int i; 47 48 for (i = 0; i < addrinarray; i++) 49 atomic_setbits_int(&pages[i]->pg_flags, PG_PMAP_WC); 50 51 return 0; 52 } 53 54 static inline int 55 set_pages_array_uc(struct vm_page **pages, int addrinarray) 56 { 57 /* XXX */ 58 return 0; 59 } 60 61 static inline int 62 set_pages_wb(struct vm_page *page, int numpages) 63 { 64 struct vm_page *pg; 65 paddr_t start = VM_PAGE_TO_PHYS(page); 66 int i; 67 68 for (i = 0; i < numpages; i++) { 69 pg = PHYS_TO_VM_PAGE(start + (i * PAGE_SIZE)); 70 if (pg != NULL) 71 atomic_clearbits_int(&pg->pg_flags, PG_PMAP_WC); 72 } 73 74 return 0; 75 } 76 77 static inline int 78 set_pages_uc(struct vm_page *page, int numpages) 79 { 80 /* XXX */ 81 return 0; 82 } 83 84 #endif /* defined(__amd64__) || defined(__i386__) */ 85 86 #endif 87