All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liav Albani <liavalb@gmail.com>
To: qemu-devel@nongnu.org
Cc: ani@anisinha.ca, imammedo@redhat.com,
	Liav Albani <liavalb@gmail.com>,
	mst@redhat.com
Subject: [PATCH v3 1/4] hw/isa: add function to check for existence of device by its type
Date: Sat, 26 Feb 2022 08:30:16 +0200	[thread overview]
Message-ID: <20220226063019.1112654-2-liavalb@gmail.com> (raw)
In-Reply-To: <20220226063019.1112654-1-liavalb@gmail.com>

This function enumerates all attached ISA devices in the machine, and
tries to compare a given device type name to the enumerated devices.
For example, this can help other code to determine if a i8042 controller
exists in the machine.

Signed-off-by: Liav Albani <liavalb@gmail.com>
---
 hw/isa/isa-bus.c     | 23 +++++++++++++++++++++++
 include/hw/isa/isa.h |  1 +
 2 files changed, 24 insertions(+)

diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c
index 6c31398dda..663aa36d29 100644
--- a/hw/isa/isa-bus.c
+++ b/hw/isa/isa-bus.c
@@ -222,6 +222,29 @@ void isa_build_aml(ISABus *bus, Aml *scope)
     }
 }
 
+bool isa_check_device_existence(const char *typename)
+{
+    /*
+     * If there's no ISA bus, we know for sure that the checked ISA device type
+     * doesn't exist in the machine.
+     */
+    if (isabus == NULL) {
+        return false;
+    }
+
+    BusChild *kid;
+    ISADevice *dev;
+
+    QTAILQ_FOREACH(kid, &isabus->parent_obj.children, sibling) {
+        dev = ISA_DEVICE(kid->child);
+        const char *object_type = object_get_typename(OBJECT(dev));
+        if (object_type && strcmp(object_type, typename) == 0) {
+            return true;
+        }
+    }
+    return false;
+}
+
 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
 {
     ISADevice *d = ISA_DEVICE(dev);
diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h
index d4417b34b6..65f0c7e28c 100644
--- a/include/hw/isa/isa.h
+++ b/include/hw/isa/isa.h
@@ -99,6 +99,7 @@ IsaDma *isa_get_dma(ISABus *bus, int nchan);
 MemoryRegion *isa_address_space(ISADevice *dev);
 MemoryRegion *isa_address_space_io(ISADevice *dev);
 ISADevice *isa_new(const char *name);
+bool isa_check_device_existence(const char *typename);
 ISADevice *isa_try_new(const char *name);
 bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp);
 ISADevice *isa_create_simple(ISABus *bus, const char *name);
-- 
2.35.1



  reply	other threads:[~2022-02-26  6:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-26  6:30 [PATCH v3 0/4] hw/acpi: add indication for i8042 in IA-PC boot flags of the FADT table Liav Albani
2022-02-26  6:30 ` Liav Albani [this message]
2022-02-27  7:27   ` [PATCH v3 1/4] hw/isa: add function to check for existence of device by its type Ani Sinha
2022-02-27 19:03     ` Liav Albani
2022-02-26  6:30 ` [PATCH v3 2/4] tests/acpi: i386: allow FACP acpi table changes Liav Albani
2022-02-27  6:57   ` Ani Sinha
2022-02-26  6:30 ` [PATCH v3 3/4] hw/acpi: add indication for i8042 in IA-PC boot flags of the FADT table Liav Albani
2022-02-27  6:56   ` Ani Sinha
2022-02-27 18:59     ` Liav Albani
2022-02-27 10:48   ` Bernhard Beschow
2022-02-27 18:58     ` Liav Albani
2022-02-27 21:33       ` Bernhard Beschow
2022-02-28  5:01         ` Ani Sinha
2022-02-28  6:56           ` Ani Sinha
2022-02-28  8:47             ` Ani Sinha
2022-02-26  6:30 ` [PATCH v3 4/4] tests/acpi: i386: update FACP table differences Liav Albani
2022-02-27  7:05   ` Ani Sinha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220226063019.1112654-2-liavalb@gmail.com \
    --to=liavalb@gmail.com \
    --cc=ani@anisinha.ca \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.