]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/sun4v/mdesc/mdesc_bus_subr.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / sun4v / mdesc / mdesc_bus_subr.c
1 /*-
2  * Copyright (c) 2006 Kip Macy
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
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/systm.h>
35 #include <sys/bus.h>
36 #include <sys/errno.h>
37 #include <sys/malloc.h>
38
39 #include <machine/mdesc_bus_subr.h>
40 #include <machine/cddl/mdesc.h>
41 #include <machine/cddl/mdesc_impl.h>
42
43 #include "mdesc_bus_if.h"
44
45 MALLOC_DEFINE(M_MDPROP, "mdesc", "machine description");
46
47 int
48 mdesc_bus_gen_setup_devinfo(struct mdesc_bus_devinfo *mbd, mde_cookie_t node)
49 {
50         md_t *mdp;
51         
52         if (mbd == NULL)
53                 return (ENOMEM);
54         
55         mdp = md_get();
56         
57         /* The 'name' property is considered mandatory. */
58         if ((md_get_prop_alloc(mdp, node, "name", MDET_PROP_STR, (uint8_t **)&mbd->mbd_name)) == -1)
59                 return (EINVAL);
60         md_get_prop_alloc(mdp, node, "compatible", MDET_PROP_DAT, (uint8_t **)&mbd->mbd_compat);
61         md_get_prop_alloc(mdp, node, "device-type", MDET_PROP_STR, (uint8_t **)&mbd->mbd_type);
62         md_get_prop_val(mdp, node, "cfg-handle", &mbd->mbd_handle);
63
64         md_put(mdp);
65         return (0);
66 }
67
68 void
69 mdesc_bus_gen_destroy_devinfo(struct mdesc_bus_devinfo *mbd)
70 {
71
72         if (mbd == NULL)
73                 return;
74         if (mbd->mbd_compat != NULL)
75                 free(mbd->mbd_compat, M_MDPROP);
76         if (mbd->mbd_name != NULL)
77                 free(mbd->mbd_name, M_MDPROP);
78         if (mbd->mbd_type != NULL)
79                 free(mbd->mbd_type, M_MDPROP);
80 }
81
82 const char *
83 mdesc_bus_gen_get_compat(device_t bus, device_t dev)
84 {
85         const struct mdesc_bus_devinfo *mbd;
86
87         mbd = MDESC_BUS_GET_DEVINFO(bus, dev);
88         if (mbd == NULL)
89                 return (NULL);
90         return (mbd->mbd_compat);
91 }
92
93 const char *
94 mdesc_bus_gen_get_name(device_t bus, device_t dev)
95 {
96         const struct mdesc_bus_devinfo *mbd;
97
98         mbd = MDESC_BUS_GET_DEVINFO(bus, dev);
99         if (mbd == NULL)
100                 return (NULL);
101         return (mbd->mbd_name);
102 }
103
104 const char *
105 mdesc_bus_gen_get_type(device_t bus, device_t dev)
106 {
107         const struct mdesc_bus_devinfo *mbd;
108
109         mbd = MDESC_BUS_GET_DEVINFO(bus, dev);
110         if (mbd == NULL)
111                 return (NULL);
112         return (mbd->mbd_type);
113 }
114
115 uint64_t
116 mdesc_bus_gen_get_handle(device_t bus, device_t dev)
117 {
118         const struct mdesc_bus_devinfo *mbd;
119
120         mbd = MDESC_BUS_GET_DEVINFO(bus, dev);
121         if (mbd == NULL)
122                 return (0);
123         return (mbd->mbd_handle);
124 }
125
126
127
128
129
130
131
132
133