/src/qemu/hw/core/qdev-fw.c
Line | Count | Source |
1 | | /* |
2 | | * qdev fw helpers |
3 | | * |
4 | | * This program is free software; you can redistribute it and/or modify |
5 | | * it under the terms of the GNU General Public License as published by |
6 | | * the Free Software Foundation; either version 2 of the License, |
7 | | * or (at your option) any later version. |
8 | | * |
9 | | * This program is distributed in the hope that it will be useful, |
10 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | * GNU General Public License for more details. |
13 | | * |
14 | | * You should have received a copy of the GNU General Public License |
15 | | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | |
18 | | #include "qemu/osdep.h" |
19 | | #include "hw/core/fw-path-provider.h" |
20 | | #include "hw/core/qdev.h" |
21 | | |
22 | | const char *qdev_fw_name(DeviceState *dev) |
23 | 0 | { |
24 | 0 | DeviceClass *dc = DEVICE_GET_CLASS(dev); |
25 | |
|
26 | 0 | if (dc->fw_name) { |
27 | 0 | return dc->fw_name; |
28 | 0 | } |
29 | | |
30 | 0 | return object_get_typename(OBJECT(dev)); |
31 | 0 | } |
32 | | |
33 | | static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev) |
34 | 0 | { |
35 | 0 | BusClass *bc = BUS_GET_CLASS(bus); |
36 | |
|
37 | 0 | if (bc->get_fw_dev_path) { |
38 | 0 | return bc->get_fw_dev_path(dev); |
39 | 0 | } |
40 | | |
41 | 0 | return NULL; |
42 | 0 | } |
43 | | |
44 | | static char *qdev_get_fw_dev_path_from_handler(BusState *bus, DeviceState *dev) |
45 | 0 | { |
46 | 0 | Object *obj = OBJECT(dev); |
47 | 0 | char *d = NULL; |
48 | |
|
49 | 0 | while (!d && obj->parent) { |
50 | 0 | obj = obj->parent; |
51 | 0 | d = fw_path_provider_try_get_dev_path(obj, bus, dev); |
52 | 0 | } |
53 | 0 | return d; |
54 | 0 | } |
55 | | |
56 | | char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev) |
57 | 0 | { |
58 | 0 | Object *obj = OBJECT(dev); |
59 | |
|
60 | 0 | return fw_path_provider_try_get_dev_path(obj, bus, dev); |
61 | 0 | } |
62 | | |
63 | | static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size) |
64 | 0 | { |
65 | 0 | int l = 0; |
66 | |
|
67 | 0 | if (dev && dev->parent_bus) { |
68 | 0 | char *d; |
69 | 0 | l = qdev_get_fw_dev_path_helper(dev->parent_bus->parent, p, size); |
70 | 0 | d = qdev_get_fw_dev_path_from_handler(dev->parent_bus, dev); |
71 | 0 | if (!d) { |
72 | 0 | d = bus_get_fw_dev_path(dev->parent_bus, dev); |
73 | 0 | } |
74 | 0 | if (d) { |
75 | 0 | l += snprintf(p + l, size - l, "%s", d); |
76 | 0 | g_free(d); |
77 | 0 | } else { |
78 | 0 | return l; |
79 | 0 | } |
80 | 0 | } |
81 | 0 | l += snprintf(p + l , size - l, "/"); |
82 | |
|
83 | 0 | return l; |
84 | 0 | } |
85 | | |
86 | | char *qdev_get_fw_dev_path(DeviceState *dev) |
87 | 0 | { |
88 | 0 | char path[128]; |
89 | 0 | int l; |
90 | |
|
91 | 0 | l = qdev_get_fw_dev_path_helper(dev, path, 128); |
92 | |
|
93 | 0 | path[l - 1] = '\0'; |
94 | |
|
95 | 0 | return g_strdup(path); |
96 | 0 | } |