hw/audio/intel-hda: Restrict DMA engine to memories (not MMIO devices)
[qemu/rayw.git] / ui / util.c
blob7e8fc1ea537a49baf3bb31d84b41b0a74273c2dd
1 /*
2 * Copyright (C) 2021 Red Hat, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 or
7 * (at your option) version 3 of the License.
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/pci/pci.h"
21 #include "hw/pci/pci_bus.h"
22 #include "qapi/error.h"
23 #include "ui/console.h"
26 * Recursively (in reverse order) appends addresses of PCI devices as it moves
27 * up in the PCI hierarchy.
29 * @returns true on success, false when the buffer wasn't large enough
31 static bool append_pci_address(char *buf, size_t buf_size, const PCIDevice *pci)
33 PCIBus *bus = pci_get_bus(pci);
35 * equivalent to if (!pci_bus_is_root(bus)), but the function is not built
36 * with PCI_CONFIG=n, avoid using an #ifdef by checking directly
38 if (bus->parent_dev != NULL) {
39 append_pci_address(buf, buf_size, bus->parent_dev);
42 size_t len = strlen(buf);
43 ssize_t written = snprintf(buf + len, buf_size - len, "/%02x.%x",
44 PCI_SLOT(pci->devfn), PCI_FUNC(pci->devfn));
46 return written > 0 && written < buf_size - len;
49 bool qemu_console_fill_device_address(QemuConsole *con,
50 char *device_address,
51 size_t size,
52 Error **errp)
54 ERRP_GUARD();
55 DeviceState *dev = DEVICE(object_property_get_link(OBJECT(con),
56 "device",
57 &error_abort));
58 PCIDevice *pci = (PCIDevice *) object_dynamic_cast(OBJECT(dev),
59 TYPE_PCI_DEVICE);
61 if (pci == NULL) {
62 error_setg(errp, "Setting device address of a display device: "
63 "Not a PCI device.");
64 return false;
67 strncpy(device_address, "pci/0000", size);
68 if (!append_pci_address(device_address, size, pci)) {
69 error_setg(errp, "Setting device address of a display device: "
70 "Too many PCI devices in the chain.");
71 return false;
74 return true;