xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/topo_alloc.c (revision 76716eaced8d7659d4594350eb3f343c31fe2806)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <umem.h>
30 #include <strings.h>
31 
32 #include <topo_alloc.h>
33 
34 void *
35 topo_alloc(size_t size, int flags)
36 {
37 	return (umem_alloc(size, flags));
38 }
39 
40 /*ARGSUSED*/
41 void *
42 topo_zalloc(size_t size, int flags)
43 {
44 	void *data = topo_alloc(size, flags);
45 	if (data != NULL)
46 		bzero(data, size);
47 
48 	return (data);
49 }
50 
51 void
52 topo_free(void *data, size_t size)
53 {
54 	umem_free(data, size);
55 }
56 
57 void *
58 topo_hdl_alloc(topo_hdl_t *thp, size_t size)
59 {
60 	topo_alloc_t *ap = thp->th_alloc;
61 
62 	return (ap->ta_alloc(size, ap->ta_flags));
63 }
64 
65 void *
66 topo_hdl_zalloc(topo_hdl_t *thp, size_t size)
67 {
68 	topo_alloc_t *ap = thp->th_alloc;
69 
70 	return (ap->ta_zalloc(size, ap->ta_flags));
71 }
72 
73 void
74 topo_hdl_free(topo_hdl_t *thp, void *data, size_t size)
75 {
76 	topo_alloc_t *ap = thp->th_alloc;
77 
78 	ap->ta_free(data, size);
79 }
80 
81 void *
82 topo_mod_alloc(topo_mod_t *mod, size_t size)
83 {
84 	return (topo_hdl_alloc(mod->tm_hdl, size));
85 }
86 
87 void *
88 topo_mod_zalloc(topo_mod_t *mod, size_t size)
89 {
90 	return (topo_hdl_zalloc(mod->tm_hdl, size));
91 }
92 
93 void
94 topo_mod_free(topo_mod_t *mod, void *data, size_t size)
95 {
96 	topo_hdl_free(mod->tm_hdl, data, size);
97 }
98