xref: /freebsd/sys/dev/mem/memutil.c (revision a20ad05beb32b120fab7f8cfaee81601d7851d92)
1a20ad05bSMark Murray /*-
2a20ad05bSMark Murray  * Copyright (c) 2004 Mark R V Murray
3a20ad05bSMark Murray  * All rights reserved.
4a20ad05bSMark Murray  *
5a20ad05bSMark Murray  * Redistribution and use in source and binary forms, with or without
6a20ad05bSMark Murray  * modification, are permitted provided that the following conditions
7a20ad05bSMark Murray  * are met:
8a20ad05bSMark Murray  * 1. Redistributions of source code must retain the above copyright
9a20ad05bSMark Murray  *    notice, this list of conditions and the following disclaimer
10a20ad05bSMark Murray  *    in this position and unchanged.
11a20ad05bSMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
12a20ad05bSMark Murray  *    notice, this list of conditions and the following disclaimer in the
13a20ad05bSMark Murray  *    documentation and/or other materials provided with the distribution.
14a20ad05bSMark Murray  *
15a20ad05bSMark Murray  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16a20ad05bSMark Murray  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17a20ad05bSMark Murray  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18a20ad05bSMark Murray  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19a20ad05bSMark Murray  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20a20ad05bSMark Murray  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21a20ad05bSMark Murray  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22a20ad05bSMark Murray  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23a20ad05bSMark Murray  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24a20ad05bSMark Murray  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25a20ad05bSMark Murray  */
26a20ad05bSMark Murray 
27a20ad05bSMark Murray #include <sys/cdefs.h>
28a20ad05bSMark Murray __FBSDID("$FreeBSD$");
29a20ad05bSMark Murray 
30a20ad05bSMark Murray #include <sys/param.h>
31a20ad05bSMark Murray #include <sys/malloc.h>
32a20ad05bSMark Murray #include <sys/memrange.h>
33a20ad05bSMark Murray #include <sys/systm.h>
34a20ad05bSMark Murray 
35a20ad05bSMark Murray /*
36a20ad05bSMark Murray  * Implementation-neutral, kernel-callable functions for manipulating
37a20ad05bSMark Murray  * memory range attributes.
38a20ad05bSMark Murray  */
39a20ad05bSMark Murray int
40a20ad05bSMark Murray mem_range_attr_get(struct mem_range_desc *mrd, int *arg)
41a20ad05bSMark Murray {
42a20ad05bSMark Murray 	/* can we handle this? */
43a20ad05bSMark Murray 	if (mem_range_softc.mr_op == NULL)
44a20ad05bSMark Murray 		return (EOPNOTSUPP);
45a20ad05bSMark Murray 
46a20ad05bSMark Murray 	if (*arg == 0)
47a20ad05bSMark Murray 		*arg = mem_range_softc.mr_ndesc;
48a20ad05bSMark Murray 	else
49a20ad05bSMark Murray 		bcopy(mem_range_softc.mr_desc, mrd,
50a20ad05bSMark Murray 			(*arg) * sizeof(struct mem_range_desc));
51a20ad05bSMark Murray 	return (0);
52a20ad05bSMark Murray }
53a20ad05bSMark Murray 
54a20ad05bSMark Murray int
55a20ad05bSMark Murray mem_range_attr_set(struct mem_range_desc *mrd, int *arg)
56a20ad05bSMark Murray {
57a20ad05bSMark Murray 	/* can we handle this? */
58a20ad05bSMark Murray 	if (mem_range_softc.mr_op == NULL)
59a20ad05bSMark Murray 		return (EOPNOTSUPP);
60a20ad05bSMark Murray 
61a20ad05bSMark Murray 	return (mem_range_softc.mr_op->set(&mem_range_softc, mrd, arg));
62a20ad05bSMark Murray }
63