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.
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.
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/>.
18 #include "qemu/osdep.h"
20 #include "hw/fw-path-provider.h"
22 const char *qdev_fw_name(DeviceState
*dev
)
24 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
30 return object_get_typename(OBJECT(dev
));
33 static char *bus_get_fw_dev_path(BusState
*bus
, DeviceState
*dev
)
35 BusClass
*bc
= BUS_GET_CLASS(bus
);
37 if (bc
->get_fw_dev_path
) {
38 return bc
->get_fw_dev_path(dev
);
44 static char *qdev_get_fw_dev_path_from_handler(BusState
*bus
, DeviceState
*dev
)
46 Object
*obj
= OBJECT(dev
);
49 while (!d
&& obj
->parent
) {
51 d
= fw_path_provider_try_get_dev_path(obj
, bus
, dev
);
56 char *qdev_get_own_fw_dev_path_from_handler(BusState
*bus
, DeviceState
*dev
)
58 Object
*obj
= OBJECT(dev
);
60 return fw_path_provider_try_get_dev_path(obj
, bus
, dev
);
63 static int qdev_get_fw_dev_path_helper(DeviceState
*dev
, char *p
, int size
)
67 if (dev
&& dev
->parent_bus
) {
69 l
= qdev_get_fw_dev_path_helper(dev
->parent_bus
->parent
, p
, size
);
70 d
= qdev_get_fw_dev_path_from_handler(dev
->parent_bus
, dev
);
72 d
= bus_get_fw_dev_path(dev
->parent_bus
, dev
);
75 l
+= snprintf(p
+ l
, size
- l
, "%s", d
);
81 l
+= snprintf(p
+ l
, size
- l
, "/");
86 char *qdev_get_fw_dev_path(DeviceState
*dev
)
91 l
= qdev_get_fw_dev_path_helper(dev
, path
, 128);
95 return g_strdup(path
);