memutil.c (a20ad05beb32b120fab7f8cfaee81601d7851d92) | memutil.c (2fea6431120dc19a04430c68b2484524074b2e43) |
---|---|
1/*- 2 * Copyright (c) 2004 Mark R V Murray 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD$"); 29 30#include <sys/param.h> | 1/*- 2 * Copyright (c) 2004 Mark R V Murray 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD$"); 29 30#include <sys/param.h> |
31#include <sys/kernel.h> 32#include <sys/lock.h> |
|
31#include <sys/malloc.h> 32#include <sys/memrange.h> | 33#include <sys/malloc.h> 34#include <sys/memrange.h> |
35#include <sys/rwlock.h> |
|
33#include <sys/systm.h> 34 | 36#include <sys/systm.h> 37 |
38static struct rwlock mr_lock; 39 |
|
35/* 36 * Implementation-neutral, kernel-callable functions for manipulating 37 * memory range attributes. 38 */ | 40/* 41 * Implementation-neutral, kernel-callable functions for manipulating 42 * memory range attributes. 43 */ |
44void 45mem_range_init(void) 46{ 47 48 if (mem_range_softc.mr_op == NULL) 49 return; 50 rw_init(&mr_lock, "memrange"); 51 mem_range_softc.mr_op->init(&mem_range_softc); 52} 53 54void 55mem_range_destroy(void) 56{ 57 58 if (mem_range_softc.mr_op == NULL) 59 return; 60 rw_destroy(&mr_lock); 61} 62 |
|
39int 40mem_range_attr_get(struct mem_range_desc *mrd, int *arg) 41{ | 63int 64mem_range_attr_get(struct mem_range_desc *mrd, int *arg) 65{ |
42 /* can we handle this? */ | 66 int nd; 67 |
43 if (mem_range_softc.mr_op == NULL) 44 return (EOPNOTSUPP); | 68 if (mem_range_softc.mr_op == NULL) 69 return (EOPNOTSUPP); |
45 46 if (*arg == 0) | 70 nd = *arg; 71 rw_rlock(&mr_lock); 72 if (nd == 0) |
47 *arg = mem_range_softc.mr_ndesc; 48 else | 73 *arg = mem_range_softc.mr_ndesc; 74 else |
49 bcopy(mem_range_softc.mr_desc, mrd, 50 (*arg) * sizeof(struct mem_range_desc)); | 75 bcopy(mem_range_softc.mr_desc, mrd, nd * sizeof(*mrd)); 76 rw_runlock(&mr_lock); |
51 return (0); 52} 53 54int 55mem_range_attr_set(struct mem_range_desc *mrd, int *arg) 56{ | 77 return (0); 78} 79 80int 81mem_range_attr_set(struct mem_range_desc *mrd, int *arg) 82{ |
57 /* can we handle this? */ | 83 int ret; 84 |
58 if (mem_range_softc.mr_op == NULL) 59 return (EOPNOTSUPP); | 85 if (mem_range_softc.mr_op == NULL) 86 return (EOPNOTSUPP); |
60 61 return (mem_range_softc.mr_op->set(&mem_range_softc, mrd, arg)); | 87 rw_wlock(&mr_lock); 88 ret = mem_range_softc.mr_op->set(&mem_range_softc, mrd, arg); 89 rw_wunlock(&mr_lock); 90 return (ret); |
62} | 91} |