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 #include <umem.h>
28 #include <strings.h>
29
30 #include <topo_alloc.h>
31
32 void *
topo_alloc(size_t size,int flags)33 topo_alloc(size_t size, int flags)
34 {
35 return (umem_alloc(size, flags));
36 }
37
38 /*ARGSUSED*/
39 void *
topo_zalloc(size_t size,int flags)40 topo_zalloc(size_t size, int flags)
41 {
42 void *data = topo_alloc(size, flags);
43 if (data != NULL)
44 bzero(data, size);
45
46 return (data);
47 }
48
49 void
topo_free(void * data,size_t size)50 topo_free(void *data, size_t size)
51 {
52 umem_free(data, size);
53 }
54
55 void *
topo_hdl_alloc(topo_hdl_t * thp,size_t size)56 topo_hdl_alloc(topo_hdl_t *thp, size_t size)
57 {
58 topo_alloc_t *ap = thp->th_alloc;
59
60 return (ap->ta_alloc(size, ap->ta_flags));
61 }
62
63 void *
topo_hdl_zalloc(topo_hdl_t * thp,size_t size)64 topo_hdl_zalloc(topo_hdl_t *thp, size_t size)
65 {
66 topo_alloc_t *ap = thp->th_alloc;
67
68 return (ap->ta_zalloc(size, ap->ta_flags));
69 }
70
71 void
topo_hdl_free(topo_hdl_t * thp,void * data,size_t size)72 topo_hdl_free(topo_hdl_t *thp, void *data, size_t size)
73 {
74 topo_alloc_t *ap = thp->th_alloc;
75
76 ap->ta_free(data, size);
77 }
78
79 void *
topo_mod_alloc(topo_mod_t * mod,size_t size)80 topo_mod_alloc(topo_mod_t *mod, size_t size)
81 {
82 return (topo_hdl_alloc(mod->tm_hdl, size));
83 }
84
85 void *
topo_mod_zalloc(topo_mod_t * mod,size_t size)86 topo_mod_zalloc(topo_mod_t *mod, size_t size)
87 {
88 return (topo_hdl_zalloc(mod->tm_hdl, size));
89 }
90
91 void
topo_mod_free(topo_mod_t * mod,void * data,size_t size)92 topo_mod_free(topo_mod_t *mod, void *data, size_t size)
93 {
94 topo_hdl_free(mod->tm_hdl, data, size);
95 }
96