Re: [Qemu-devel] [PATCH v3] chardev/char-i2c: Implement Linux I2C character device

2019-05-16 Thread Ernest Esene
On Wed, May 15, 2019 at 03:17:12PM +0100, Stefan Hajnoczi wrote:
> On Fri, May 10, 2019 at 07:04:10PM +0100, Ernest Esene wrote:
> > Add support for Linux I2C character device for I2C device passthrough
> > For example:
> > -chardev i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev
> > 
> > QEMU supports emulation of I2C devices in software but currently can't
> > passthrough to real I2C devices. This feature is needed by developers
> > using QEMU for writing and testing software for I2C devices.
> > 
> > Signed-off-by: Ernest Esene 
> 
> How is -chardev i2c meant to be used?  Do you have code to connect this
> new chardev type to an emulated I2C bus?
It is meant to be connected to emulated I2C bus as you've stated, but I
don't have the code yet.
> 
> Stefan




signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v3] chardev/char-i2c: Implement Linux I2C character device

2019-05-10 Thread Ernest Esene
Add support for Linux I2C character device for I2C device passthrough
For example:
-chardev i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev

QEMU supports emulation of I2C devices in software but currently can't
passthrough to real I2C devices. This feature is needed by developers
using QEMU for writing and testing software for I2C devices.

Signed-off-by: Ernest Esene 
---
v3:
  * change licence to GPLv2+
  * use non blocking IO for the chardev
  * change "address" to QEMU_OPT_NUMBER
  * update qemu-options.hx
---
v2:
  * Fixed errors
  * update "MAINTAINERS" file.
---
 MAINTAINERS  |   5 ++
 chardev/Makefile.objs|   1 +
 chardev/char-linux-i2c.c | 126 +++
 chardev/char.c   |   3 ++
 include/chardev/char.h   |   1 +
 qapi/char.json   |  17 +++
 qemu-options.hx  |  14 +-
 7 files changed, 166 insertions(+), 1 deletion(-)
 create mode 100644 chardev/char-linux-i2c.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 66ddbda9c9..d834a12241 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1801,6 +1801,11 @@ M: Samuel Thibault 
 S: Maintained
 F: chardev/baum.c
 
+Character Devices (I2C)
+M: Ernest Esene 
+S: Maintained
+F: chardev/char-linux-i2c.c
+
 Command line option argument parsing
 M: Markus Armbruster 
 S: Supported
diff --git a/chardev/Makefile.objs b/chardev/Makefile.objs
index d68e1347f9..7b64009aa6 100644
--- a/chardev/Makefile.objs
+++ b/chardev/Makefile.objs
@@ -16,6 +16,7 @@ chardev-obj-y += char-stdio.o
 chardev-obj-y += char-udp.o
 chardev-obj-$(CONFIG_WIN32) += char-win.o
 chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
+chardev-obj-$(CONFIG_LINUX) +=char-linux-i2c.o
 
 common-obj-y += msmouse.o wctablet.o testdev.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
diff --git a/chardev/char-linux-i2c.c b/chardev/char-linux-i2c.c
new file mode 100644
index 00..847a18f611
--- /dev/null
+++ b/chardev/char-linux-i2c.c
@@ -0,0 +1,126 @@
+/*
+ * QEMU System Emulator
+ * Linux I2C device support as a character device.
+ *
+ * Copyright (c) 2019 Ernest Esene 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/option.h"
+#include "qemu-common.h"
+#include "io/channel-file.h"
+#include "qemu/cutils.h"
+#include "qemu/sockets.h"
+
+#include "chardev/char-fd.h"
+#include "chardev/char.h"
+
+#include 
+#include 
+#include 
+
+#define CHR_IOCTL_I2C_SET_ADDR 1
+
+#define CHR_I2C_ADDR_10BIT_MAX 1023
+#define CHR_I2C_ADDR_7BIT_MAX 127
+
+static int i2c_ioctl(Chardev *chr, int cmd, void *arg)
+{
+FDChardev *fd_chr = FD_CHARDEV(chr);
+QIOChannelFile *floc = QIO_CHANNEL_FILE(fd_chr->ioc_in);
+int fd = floc->fd;
+int addr;
+unsigned long funcs;
+
+switch (cmd) {
+case CHR_IOCTL_I2C_SET_ADDR:
+addr = (intptr_t)arg;
+
+if (addr > CHR_I2C_ADDR_7BIT_MAX) {
+if (ioctl(fd, I2C_FUNCS, ) < 0) {
+goto err;
+}
+if (!(funcs & I2C_FUNC_10BIT_ADDR)) {
+goto err;
+}
+if (ioctl(fd, I2C_TENBIT, addr) < 0) {
+goto err;
+}
+} else {
+if (ioctl(fd, I2C_SLAVE, addr) < 0) {
+goto err;
+}
+}
+break;
+
+default:
+return -ENOTSUP;
+}
+return 0;
+err:
+return -ENOTSUP;
+}
+
+static void qmp_chardev_open_i2c(Chardev *chr, ChardevBackend *backend,
+ bool *be_opened, Error **errp)
+{
+ChardevI2c *i2c = backend->u.i2c.data;
+void *addr;
+int fd;
+
+fd = qmp_chardev_open_file_source(i2c->device, O_RDWR | O_NONBLOCK, errp);
+if (fd < 0) {
+return;
+}
+qemu_set_nonblock(fd);
+qemu_chr_open_fd(chr, fd, fd);
+addr = (void *)(intptr_t)i2c->address;
+i2c_ioctl(chr, CHR_IOCTL_I2C_SET_ADDR, addr);
+}
+
+static void qemu_chr_parse_i2c(QemuOpts *opts, ChardevBackend *backend,
+   Error **errp)
+{
+const char *device = qemu_opt_get(opts, "path");
+long address = qemu_opt_get_number(opts, "address", LONG_MAX);
+ChardevI2c *i2c;
+
+if (device == NULL) {
+error_setg(errp, "chardev: i2c: no device path given");
+return;
+}
+if (address < 0 || address > CHR_I2C_ADDR_10BIT_MAX) {
+error_setg(errp, "chardev: i2c: device address out of range");
+return;
+}
+backend->type = CHARDEV_BACKEND_KIND_I2C;
+i2c = backend->u.i2c.data = g_new0(ChardevI2c, 1);
+qemu_chr_parse_common(opts, qapi_ChardevI2c_base(i2c));
+i2c->device = g_strdup(device);
+i2c->address = (int16_t)address;
+}
+
+static void 

Re: [Qemu-devel] [PATCH v2] chardev/char-i2c: Implement Linux I2C character device

2019-05-10 Thread Ernest Esene
On Thu, May 09, 2019 at 02:00:56PM +0100, Stefan Hajnoczi wrote:
> On Sat, May 04, 2019 at 07:11:19PM +0100, Ernest Esene wrote:
> > Add support for Linux I2C character device for I2C device passthrough
> > For example:
> > -chardev linux-i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev
> 
> There is a mixture of "linux-i2c" and "char-i2c" names in this patch,
> which I find confusing.  Maybe you changed your mind while writing this
> code.  There are two options:
> 
> 1. Call it "linux-i2c".  Other host operating systems will need their
>own equivalent objects.
> 
> 2. Call it "char-i2c" and make all the parameters optional since they
>are likely to work differently on other host operating systems.
> 
> I tend towards the second approach because I think I2C is simple enough
> that a single user-visible object can work on all host operating
> systems.
> 
> Please make the naming consistent in the next revision of this patch.

My coding skills is limited to only Linux, I prefer the first approach
as is makes it easy.


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v2] chardev/char-i2c: Implement Linux I2C character device

2019-05-10 Thread Ernest Esene
On Tue, May 07, 2019 at 07:33:09PM +0200, Markus Armbruster wrote:
> Ernest Esene  writes:
> 
> > Add support for Linux I2C character device for I2C device passthrough
> > For example:
> > -chardev linux-i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev
> >
> > Signed-off-by: Ernest Esene 
> 
> Could you explain briefly how passing through a host's I2C device can be
> useful?
QEMU supports emulation of I2C devices in software but currently can't
passthrough to real I2C devices. This feature is needed by developers
using QEMU for writing and testing software for I2C devices.

> 
> Any particular reason not to use GPLv2+?
No, I used the wrong script. I'll update the licence.

> > +
> > +if (addr > CHR_I2C_ADDR_7BIT_MAX) {
> > +/*
> > + * TODO: check if adapter support 10-bit addr
> > + * I2C_FUNC_10BIT_ADDR
> > + */
> 
> What's the impact of not having done this TODO?
Not all I2C adapters supports 10-bit address.
> Should it be mentioned in the commit message?
I have handled it already.

> > +return;
> > +}
> > +qemu_set_block(fd);
> 
> Sure we want *blocking* I/O?  No other character device does.
No, it is a mistake.
> 
> > +qemu_chr_open_fd(chr, fd, fd);
> > +addr = (void *) (long) i2c->address;
> 
> 
> Why not make option "addr" QEMU_OPT_NUMBER and use
> qemu_opt_get_number()?
I never knew QEMU_OPT_NUMBER can handle inputs such: "0x08 and 8",
appropriately.
> 
> Missing: documentation update for qemu-options.hx.
I don't know much about this format (.hx), I'll be happy to have any
useful documentation on this.

Thank you.
-Ernest Esene


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v2] chardev/char-i2c: Implement Linux I2C character device

2019-05-04 Thread Ernest Esene
Add support for Linux I2C character device for I2C device passthrough
For example:
-chardev linux-i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev

Signed-off-by: Ernest Esene 

---
v2:
  * Fix errors
  * update "MAINTAINERS" file.
---
 MAINTAINERS|   6 ++
 chardev/Makefile.objs  |   1 +
 chardev/char-i2c.c | 140 +
 chardev/char.c |   3 +
 include/chardev/char-i2c.h |  35 
 include/chardev/char.h |   1 +
 qapi/char.json |  18 ++
 7 files changed, 204 insertions(+)
 create mode 100644 chardev/char-i2c.c
 create mode 100644 include/chardev/char-i2c.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 7dd71e0a2d..b79d9b8edf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1801,6 +1801,12 @@ M: Samuel Thibault 
 S: Maintained
 F: chardev/baum.c
 
+Character Devices (Linux I2C)
+M: Ernest Esene 
+S: Maintained
+F: chardev/char-i2c.c
+F: include/chardev/char-i2c.h
+
 Command line option argument parsing
 M: Markus Armbruster 
 S: Supported
diff --git a/chardev/Makefile.objs b/chardev/Makefile.objs
index d68e1347f9..6c96b9a353 100644
--- a/chardev/Makefile.objs
+++ b/chardev/Makefile.objs
@@ -16,6 +16,7 @@ chardev-obj-y += char-stdio.o
 chardev-obj-y += char-udp.o
 chardev-obj-$(CONFIG_WIN32) += char-win.o
 chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
+chardev-obj-$(CONFIG_POSIX) +=char-i2c.o
 
 common-obj-y += msmouse.o wctablet.o testdev.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
diff --git a/chardev/char-i2c.c b/chardev/char-i2c.c
new file mode 100644
index 00..4b068b0124
--- /dev/null
+++ b/chardev/char-i2c.c
@@ -0,0 +1,140 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2019 Ernest Esene 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/option.h"
+#include "qemu-common.h"
+#include "io/channel-file.h"
+#include "qemu/cutils.h"
+
+#include "chardev/char-fd.h"
+#include "chardev/char-i2c.h"
+#include "chardev/char.h"
+
+#include 
+#include 
+
+static int i2c_ioctl(Chardev *chr, int cmd, void *arg)
+{
+FDChardev *fd_chr = FD_CHARDEV(chr);
+QIOChannelFile *floc = QIO_CHANNEL_FILE(fd_chr->ioc_in);
+int fd = floc->fd;
+int addr;
+
+switch (cmd) {
+case CHR_IOCTL_I2C_SET_ADDR:
+addr = (int) (long) arg;
+
+if (addr > CHR_I2C_ADDR_7BIT_MAX) {
+/*
+ * TODO: check if adapter support 10-bit addr
+ * I2C_FUNC_10BIT_ADDR
+ */
+if (ioctl(fd, I2C_TENBIT, addr) < 0) {
+goto err;
+}
+} else {
+if (ioctl(fd, I2C_SLAVE, addr) < 0) {
+goto err;
+}
+}
+break;
+
+default:
+return -ENOTSUP;
+}
+return 0;
+err:
+return -ENOTSUP;
+}
+
+static void qmp_chardev_open_i2c(Chardev *chr, ChardevBackend *backend,
+ bool *be_opened, Error **errp)
+{
+ChardevI2c *i2c = backend->u.i2c.data;
+void *addr;
+int fd;
+
+fd = qmp_chardev_open_file_source(i2c->device, O_RDWR | O_NONBLOCK,
+  errp);
+if (fd < 0) {
+return;
+}
+qemu_set_block(fd);
+qemu_chr_open_fd(chr, fd, fd);
+addr = (void *) (long) i2c->address;
+i2c_ioctl(chr, CHR_IOCTL_I2C_SET_ADDR, addr);
+}
+
+static void qemu_chr_parse_i2c(QemuOpts *opts, ChardevBackend *backend,
+   Error **errp)
+{
+const char *device = qemu_opt_get(opts, "path");
+const char *addr = qemu_opt_get(opts, "address");
+long address;
+ChardevI2c *i2c;
+if (device == NULL) {
+error_setg(errp, "chardev: linux-i2c: no device path given");
+   

Re: [Qemu-devel] [PATCH] chardev/char-i2c: Implement Linux I2C character device

2019-05-03 Thread Ernest Esene
On Fri, May 03, 2019 at 03:24:06PM -0500, Eric Blake wrote:
> On 5/3/19 2:31 PM, Ernest Esene wrote:
> > Add support for Linux I2C character device for I2C device passthrough
> > For example:
> > -chardev linux-i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev
> > 
> > Signed-off-by: Ernest Esene 
> > ---
> 
> Just an interface review:
> 
> > +++ b/qapi/char.json
> > @@ -240,6 +240,21 @@
> >'data': { 'device': 'str' },
> >'base': 'ChardevCommon' }
> >  
> Missing a 'Since: 4.1' line.
4.1? Oh! I couldn't guess this number, I had to deliberately omit it.
> 
> > +{ 'struct': 'ChardevI2c',
> > +  'data': { 'device': 'str',
> > +'address': 'int16'},
> > +  'base': 'ChardevCommon'}
> 
> 'if': 'defined(CONFIG_LINUX)'
> 
> as part of the usage of this struct, so that introspection will only see
> the struct where it can be used.
> 
> > +
> >  ##
> >  # @ChardevSocket:
> >  #
> > @@ -398,6 +413,7 @@
> >'data': { 'file': 'ChardevFile',
> >  'serial': 'ChardevHostdev',
> >  'parallel': 'ChardevHostdev',
> > +'i2c': 'ChardevI2c',
> >  'pipe': 'ChardevHostdev',
> >  'socket': 'ChardevSocket',
> >  'udp': 'ChardevUdp',
> > 
> 
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3226
> Virtualization:  qemu.org | libvirt.org
> 
Thanks so much for the useful review. I have applied the changes and
will soon send v2 of the patch.

I hope it is OK to update the "MAINTAINERS" file this

Character Devices (Linux I2C)
M: Ernest Esene 
S: Maintained
F: chardev/char-i2c.c


-Ernest Esene


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH] chardev/char-i2c: Implement Linux I2C character device

2019-05-03 Thread Ernest Esene
Add support for Linux I2C character device for I2C device passthrough
For example:
-chardev linux-i2c,address=0x46,path=/dev/i2c-N,id=i2c-chardev

Signed-off-by: Ernest Esene 
---
 chardev/Makefile.objs  |   1 +
 chardev/char-i2c.c | 142 +
 chardev/char.c |   3 ++
 include/chardev/char.h |   1 +
 qapi/char.json |  16 ++
 5 files changed, 163 insertions(+)
 create mode 100644 chardev/char-i2c.c

diff --git a/chardev/Makefile.objs b/chardev/Makefile.objs
index d68e1347f9..6c96b9a353 100644
--- a/chardev/Makefile.objs
+++ b/chardev/Makefile.objs
@@ -16,6 +16,7 @@ chardev-obj-y += char-stdio.o
 chardev-obj-y += char-udp.o
 chardev-obj-$(CONFIG_WIN32) += char-win.o
 chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
+chardev-obj-$(CONFIG_POSIX) +=char-i2c.o
 
 common-obj-y += msmouse.o wctablet.o testdev.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
diff --git a/chardev/char-i2c.c b/chardev/char-i2c.c
new file mode 100644
index 00..78cf973bd7
--- /dev/null
+++ b/chardev/char-i2c.c
@@ -0,0 +1,142 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2019 Ernest Esene 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/option.h"
+#include "qemu-common.h"
+#include "io/channel-file.h"
+
+#include "chardev/char-fd.h"
+#include "chardev/char.h"
+
+#include 
+#include 
+
+#define CHR_IOCTL_I2C_SET_ADDR 1
+
+#define CHR_I2C_ADDR_10BIT_MAX 1023
+#define CHR_I2C_ADDR_7BIT_MAX 127
+
+void qemu_set_block(int fd);
+
+static int i2c_ioctl(Chardev *chr, int cmd, void *arg)
+{
+FDChardev *fd_chr = FD_CHARDEV(chr);
+QIOChannelFile *floc = QIO_CHANNEL_FILE(fd_chr->ioc_in);
+int fd = floc->fd;
+int addr;
+
+switch (cmd) {
+case CHR_IOCTL_I2C_SET_ADDR:
+addr = (int) (long) arg;
+
+if (addr > CHR_I2C_ADDR_7BIT_MAX) {
+/*TODO: check if adapter support 10-bit addr
+I2C_FUNC_10BIT_ADDR */
+if (ioctl(fd, I2C_TENBIT, addr) < 0) {
+goto err;
+}
+}
+else {
+if (ioctl(fd, I2C_SLAVE, addr) < 0) {
+goto err;
+}
+}
+break;
+
+default:
+return -ENOTSUP;
+
+}
+return 0;
+err:
+return -ENOTSUP;
+}
+
+static void qmp_chardev_open_i2c(Chardev *chr, ChardevBackend *backend,
+ bool *be_opened, Error **errp)
+{
+ChardevI2c *i2c = backend->u.i2c.data;
+void *addr;
+int fd;
+
+fd = qmp_chardev_open_file_source(i2c->device, O_RDWR | O_NONBLOCK,
+  errp);
+if (fd < 0) {
+   return;
+}
+qemu_set_block(fd);
+qemu_chr_open_fd(chr, fd, fd);
+addr = (void *) (long) i2c->address;
+i2c_ioctl(chr, CHR_IOCTL_I2C_SET_ADDR, addr);
+}
+
+static void qemu_chr_parse_i2c(QemuOpts *opts, ChardevBackend *backend, Error 
**errp)
+{
+const char *device = qemu_opt_get(opts, "path");
+const char *addr = qemu_opt_get(opts, "address");
+long address;
+ChardevI2c *i2c;
+
+if (device == NULL) {
+error_setg(errp, "chardev: linux-i2c: no device path given");
+return;
+}
+if (addr == NULL) {
+error_setg(errp, "chardev: linux-i2c: no device address given");
+return;
+}
+address = strtol(addr, NULL, 0);
+if (address < 0 || address > CHR_I2C_ADDR_10BIT_MAX) {
+error_setg(errp, "chardev: linux-i2c: invalid device address given");
+return;
+}
+backend->type = CHARDEV_BACKEND_KIND_I2C;
+i2c = backend->u.i2c.data = g_new0(ChardevI2c, 1);
+qemu_chr_parse_com

[Qemu-devel] [PATCH v3 3/3] Categorize devices: iommu

2019-04-01 Thread Ernest Esene
Set category and description for iommu devices.

Signed-off-by: Ernest Esene 

---
v3:
  * set category and describe smmuv3 as suggested by Eric
v2:
  * split into separate patches
---
 hw/arm/smmuv3.c   | 2 ++
 hw/i386/amd_iommu.c   | 2 ++
 hw/i386/intel_iommu.c | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index 8c4e99fecc..d5a3df047d 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -1463,6 +1463,8 @@ static void smmuv3_class_init(ObjectClass *klass, void 
*data)
 device_class_set_parent_reset(dc, smmu_reset, >parent_reset);
 c->parent_realize = dc->realize;
 dc->realize = smmu_realize;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "ARM IOMMU (SMMUv3) DMA Remapping device"
 }
 
 static void smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,
diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 6eabdf9917..4a4e2c7fd4 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -1601,6 +1601,8 @@ static void amdvi_class_init(ObjectClass *klass, void* 
data)
 dc_class->int_remap = amdvi_int_remap;
 /* Supported by the pc-q35-* machine types */
 dc->user_creatable = true;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "AMD IOMMU (AMD-Vi) DMA Remapping device";
 }
 
 static const TypeInfo amdvi = {
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 055a1e865d..f9781a5d20 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3727,6 +3727,8 @@ static void vtd_class_init(ObjectClass *klass, void *data)
 x86_class->int_remap = vtd_int_remap;
 /* Supported by the pc-q35-* machine types */
 dc->user_creatable = true;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "Intel IOMMU (VT-d) DMA Remapping device";
 }
 
 static const TypeInfo vtd_info = {
-- 
2.14.2



signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v3 2/3] Categorize devices: i82374

2019-04-01 Thread Ernest Esene
Set category and description for iommu devices

Signed-off-by: Ernest Esene 

---
v3:
  * remove user_creatable
v2:
  * split into separate patches
---
 hw/dma/i82374.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
index 892f655a7e..aeb3da8ba6 100644
--- a/hw/dma/i82374.c
+++ b/hw/dma/i82374.c
@@ -147,6 +147,9 @@ static void i82374_class_init(ObjectClass *klass, void 
*data)
 dc->realize = i82374_realize;
 dc->vmsd = _i82374;
 dc->props = i82374_properties;
+dc->desc = "Intel Enhanced DMA controller";
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+dc->user_creatable = false;
 }
 
 static const TypeInfo i82374_info = {
-- 
2.14.2



signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v3 1/3] Categorize devices: DIMM

2019-04-01 Thread Ernest Esene
Set category and describe DIMM devices

Signed-off-by: Ernest Esene 

---
v3:
  * add MEMORY device category
  * set category to MEMORY
v2:
  * split into separate patches
---
 hw/mem/nvdimm.c| 1 +
 hw/mem/pc-dimm.c   | 1 +
 include/hw/qdev-core.h | 1 +
 qdev-monitor.c | 1 +
 4 files changed, 4 insertions(+)

diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index bf2adf5e16..a334dbe1f5 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -200,6 +200,7 @@ static void nvdimm_class_init(ObjectClass *oc, void *data)
 ddc->realize = nvdimm_realize;
 mdc->get_memory_region = nvdimm_md_get_memory_region;
 dc->props = nvdimm_properties;
+dc->desc = "NVDIMM memory module";
 
 nvc->read_label_data = nvdimm_read_label_data;
 nvc->write_label_data = nvdimm_write_label_data;
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 152400b1fc..3ace8077b5 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -259,6 +259,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
 dc->unrealize = pc_dimm_unrealize;
 dc->props = pc_dimm_properties;
 dc->desc = "DIMM memory module";
+set_bit(DEVICE_CATEGORY_MEMORY, dc->categories);
 
 ddc->get_vmstate_memory_region = pc_dimm_get_memory_region;
 
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 33ed3b8dde..a7d9ea1fbe 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -26,6 +26,7 @@ typedef enum DeviceCategory {
 DEVICE_CATEGORY_SOUND,
 DEVICE_CATEGORY_MISC,
 DEVICE_CATEGORY_CPU,
+DEVICE_CATEGORY_MEMORY,
 DEVICE_CATEGORY_MAX
 } DeviceCategory;
 
diff --git a/qdev-monitor.c b/qdev-monitor.c
index d4320986a2..5318df205b 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -143,6 +143,7 @@ static void qdev_print_devinfos(bool show_no_user)
 [DEVICE_CATEGORY_SOUND]   = "Sound",
 [DEVICE_CATEGORY_MISC]= "Misc",
 [DEVICE_CATEGORY_CPU] = "CPU",
+[DEVICE_CATEGORY_MEMORY]  = "Memory",
 [DEVICE_CATEGORY_MAX] = "Uncategorized",
 };
 GSList *list, *elt;
-- 
2.14.2



signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v2] Replace calls to object_child_foreach() with object_child_foreach_recursive()

2019-04-01 Thread Ernest Esene
Replace calls to object_child_foreach() with object_child_foreach_recursive()
when applicable: nvdimm_device_list, nmi_monitor_handle,
find_sysbus_device,
pc_dimm_slot2bitmap, build_dimm_list.

Signed-off-by: Ernest Esene 

---
v2:
  * applied changes suggested by Paolo
---
 hw/acpi/nvdimm.c   |  4 +---
 hw/core/sysbus.c   | 11 ---
 hw/mem/pc-dimm.c   |  3 +--
 hw/virtio/virtio-balloon.c |  3 +--
 4 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index 9fdad6dc3f..36ff075a42 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -40,8 +40,6 @@ static int nvdimm_device_list(Object *obj, void *opaque)
 if (object_dynamic_cast(obj, TYPE_NVDIMM)) {
 *list = g_slist_append(*list, DEVICE(obj));
 }
-
-object_child_foreach(obj, nvdimm_device_list, opaque);
 return 0;
 }
 
@@ -56,7 +54,7 @@ static GSList *nvdimm_get_device_list(void)
 {
 GSList *list = NULL;
 
-object_child_foreach(qdev_get_machine(), nvdimm_device_list, );
+object_child_foreach_recursive(qdev_get_machine(), nvdimm_device_list, 
);
 return list;
 }
 
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 307cf90a51..3d0bf47a04 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -41,13 +41,10 @@ static int find_sysbus_device(Object *obj, void *opaque)
 dev = object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE);
 sbdev = (SysBusDevice *)dev;
 
-if (!sbdev) {
-/* Container, traverse it for children */
-return object_child_foreach(obj, find_sysbus_device, opaque);
+if (sbdev) {
+find->func(sbdev, find->opaque);
 }
 
-find->func(sbdev, find->opaque);
-
 return 0;
 }
 
@@ -65,9 +62,9 @@ void foreach_dynamic_sysbus_device(FindSysbusDeviceFunc 
*func, void *opaque)
 
 /* Loop through all sysbus devices that were spawened outside the machine 
*/
 container = container_get(qdev_get_machine(), "/peripheral");
-find_sysbus_device(container, );
+object_child_foreach_recursive(container, find_sysbus_device, );
 container = container_get(qdev_get_machine(), "/peripheral-anon");
-find_sysbus_device(container, );
+object_child_foreach_recursive(container, find_sysbus_device, );
 }
 
 
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 19b9c0f406..6eaac49a22 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -84,7 +84,6 @@ static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
 }
 }
 
-object_child_foreach(obj, pc_dimm_slot2bitmap, opaque);
 return 0;
 }
 
@@ -100,7 +99,7 @@ static int pc_dimm_get_free_slot(const int *hint, int 
max_slots, Error **errp)
 }
 
 bitmap = bitmap_new(max_slots);
-object_child_foreach(qdev_get_machine(), pc_dimm_slot2bitmap, bitmap);
+object_child_foreach_recursive(qdev_get_machine(), pc_dimm_slot2bitmap, 
bitmap);
 
 /* check if requested slot is not occupied */
 if (hint) {
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 2112874055..7945637077 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -649,7 +649,6 @@ static int build_dimm_list(Object *obj, void *opaque)
 }
 }
 
-object_child_foreach(obj, build_dimm_list, opaque);
 return 0;
 }
 
@@ -658,7 +657,7 @@ static ram_addr_t get_current_ram_size(void)
 GSList *list = NULL, *item;
 ram_addr_t size = ram_size;
 
-build_dimm_list(qdev_get_machine(), );
+object_child_foreach_recursive(qdev_get_machine(), build_dimm_list, );
 for (item = list; item; item = g_slist_next(item)) {
 Object *obj = OBJECT(item->data);
 if (!strcmp(object_get_typename(obj), TYPE_PC_DIMM)) {
-- 
2.14.2



signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH] Replace calls to object_child_foreach() with object_child_foreach_recursive()

2019-03-31 Thread Ernest Esene
On Fri, Mar 29, 2019 at 10:47:22AM +, Stefan Hajnoczi wrote:
> On Tue, Mar 26, 2019 at 10:12:56AM +0100, Paolo Bonzini wrote:
> > On 26/03/19 08:43, Stefan Hajnoczi wrote:
> > > On Sun, Mar 10, 2019 at 02:39:13AM +0100, Ernest Esene wrote:
> > >> Replace calls to object_child_foreach() with 
> > >> object_child_foreach_recursive()
> > >> when applicable: nvdimm_device_list, nmi_monitor_handle, 
> > >> find_sysbus_device,
> > >> pc_dimm_slot2bitmap, build_dimm_list.
> > > 
> > > Ernest or Paolo: What is the rationale for this change?
> > 
> > The change could have been described better probably...  The idea is
> > that for example nvdimm_device_list could just stop invoking
> > object_child_foreach, because recursion is handled by
> > nvdimm_get_device_list:
> > 
> > >> @@ -41,7 +41,7 @@ static int nvdimm_device_list(Object *obj, void 
> > >> *opaque)
> > >>  *list = g_slist_append(*list, DEVICE(obj));
> > >>  }
> > >>  
> > >> -object_child_foreach(obj, nvdimm_device_list, opaque);
> > >> +object_child_foreach_recursive(obj, nvdimm_device_list, opaque);
> > >>  return 0;
> > >>  }
> > >>  
> > >> @@ -56,7 +56,8 @@ static GSList *nvdimm_get_device_list(void)
> > >>  {
> > >>  GSList *list = NULL;
> > >>  
> > >> -object_child_foreach(qdev_get_machine(), nvdimm_device_list, );
> > >> +object_child_foreach_recursive(qdev_get_machine(),
> > >> +   nvdimm_device_list, );
> > >>  return list;
> > >>  }
> 
> Thanks, that makes sense!
> 
> Ernest: If you want to continue with this task, please make the changes
> Paolo has suggested and update the commit description to say that
> manually calling object_child_foreach() is unnecessary for children
> since a single object_child_foreach_recursive() call can be used
> instead.
> 
> Thanks,
> Stefan

Thank you Stefan and Paolo, I shall do it.

-Ernest




signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v2 3/6] Categorize devices: DIMM

2019-03-27 Thread Ernest Esene
On Wed, Mar 27, 2019 at 01:47:48PM +0100, Philippe Mathieu-Daudé wrote:
> Le mer. 27 mars 2019 13:32, Ernest Esene  a écrit :
> 
> > Set category and describe DIMM devices
> >
> > Signed-off-by: Ernest Esene 
> >
> > ---
> > v2:
> >   * split into separate patches
> > ---
> >  hw/mem/nvdimm.c  | 1 +
> >  hw/mem/pc-dimm.c | 1 +
> >  2 files changed, 2 insertions(+)
> >
> > diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
> > index bf2adf5e16..a334dbe1f5 100644
> > --- a/hw/mem/nvdimm.c
> > +++ b/hw/mem/nvdimm.c
> > @@ -200,6 +200,7 @@ static void nvdimm_class_init(ObjectClass *oc, void
> > *data)
> >  ddc->realize = nvdimm_realize;
> >  mdc->get_memory_region = nvdimm_md_get_memory_region;
> >  dc->props = nvdimm_properties;
> > +dc->desc = "NVDIMM memory module";
> >
> >  nvc->read_label_data = nvdimm_read_label_data;
> >  nvc->write_label_data = nvdimm_write_label_data;
> > diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> > index 152400b1fc..19b9c0f406 100644
> > --- a/hw/mem/pc-dimm.c
> > +++ b/hw/mem/pc-dimm.c
> > @@ -259,6 +259,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void
> > *data)
> >  dc->unrealize = pc_dimm_unrealize;
> >  dc->props = pc_dimm_properties;
> >  dc->desc = "DIMM memory module";
> > +set_bit(DEVICE_CATEGORY_MISC, dc->categories);
> >
> 
> Hmm should we add a MEMORY category?
Exactly what I was thinking. I shall send an update for the MEMORY
category.
> 
> 
> >  ddc->get_vmstate_memory_region = pc_dimm_get_memory_region;
> >
> > --
> > 2.14.2
> >
> >


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v2 6/6] Categorize devices: iommu

2019-03-27 Thread Ernest Esene
Set category and description for iommu devices
Signed-off-by: Ernest Esene 

---
v2:
  * split into separate patches
---
 hw/i386/amd_iommu.c   | 2 ++
 hw/i386/intel_iommu.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 6eabdf9917..4a4e2c7fd4 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -1601,6 +1601,8 @@ static void amdvi_class_init(ObjectClass *klass, void* 
data)
 dc_class->int_remap = amdvi_int_remap;
 /* Supported by the pc-q35-* machine types */
 dc->user_creatable = true;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "AMD IOMMU (AMD-Vi) DMA Remapping device";
 }
 
 static const TypeInfo amdvi = {
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index b90de6c664..4d0e60423c 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3702,6 +3702,8 @@ static void vtd_class_init(ObjectClass *klass, void *data)
 x86_class->int_remap = vtd_int_remap;
 /* Supported by the pc-q35-* machine types */
 dc->user_creatable = true;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "Intel IOMMU (VT-d) DMA Remapping device";
 }
 
 static const TypeInfo vtd_info = {
-- 
2.14.2



signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v2 5/6] Categorize devices: IGD passthrough ISA bridge

2019-03-27 Thread Ernest Esene
Set category for the device
Signed-off-by: Ernest Esene 

---
v2:
  * split into separate patches
---
 hw/i386/pc_piix.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 8ad8e885c6..03a9cb8af3 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -911,6 +911,7 @@ static void isa_bridge_class_init(ObjectClass *klass, void 
*data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
 dc->desc= "ISA bridge faked to support IGD PT";
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 k->vendor_id= PCI_VENDOR_ID_INTEL;
 k->class_id = PCI_CLASS_BRIDGE_ISA;
 };
-- 
2.14.2



signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v2 4/6] Categorize devices: i82374

2019-03-27 Thread Ernest Esene
Set category and describe the i82374 device

Signed-off-by: Ernest Esene 

---
v2:
  * split into separate patches
---
 hw/dma/i82374.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
index 892f655a7e..5b42dd1bd4 100644
--- a/hw/dma/i82374.c
+++ b/hw/dma/i82374.c
@@ -147,6 +147,8 @@ static void i82374_class_init(ObjectClass *klass, void 
*data)
 dc->realize = i82374_realize;
 dc->vmsd = _i82374;
 dc->props = i82374_properties;
+dc->desc = "Intel Enhanced DMA controller";
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 }
 
 static const TypeInfo i82374_info = {
-- 
2.14.2



signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v2 3/6] Categorize devices: DIMM

2019-03-27 Thread Ernest Esene
Set category and describe DIMM devices

Signed-off-by: Ernest Esene 

---
v2:
  * split into separate patches
---
 hw/mem/nvdimm.c  | 1 +
 hw/mem/pc-dimm.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index bf2adf5e16..a334dbe1f5 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -200,6 +200,7 @@ static void nvdimm_class_init(ObjectClass *oc, void *data)
 ddc->realize = nvdimm_realize;
 mdc->get_memory_region = nvdimm_md_get_memory_region;
 dc->props = nvdimm_properties;
+dc->desc = "NVDIMM memory module";
 
 nvc->read_label_data = nvdimm_read_label_data;
 nvc->write_label_data = nvdimm_write_label_data;
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 152400b1fc..19b9c0f406 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -259,6 +259,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
 dc->unrealize = pc_dimm_unrealize;
 dc->props = pc_dimm_properties;
 dc->desc = "DIMM memory module";
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
 
 ddc->get_vmstate_memory_region = pc_dimm_get_memory_region;
 
-- 
2.14.2



signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v2 2/6] Categorize devices: TPM

2019-03-27 Thread Ernest Esene
Set category and describe TPM device
Signed-off-by: Ernest Esene 

---
v2:
  * split into separate patch
---

 hw/tpm/tpm_tis.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index fd183e8deb..368242 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -1020,6 +1020,9 @@ static void tpm_tis_class_init(ObjectClass *klass, void 
*data)
 dc->props = tpm_tis_properties;
 dc->reset = tpm_tis_reset;
 dc->vmsd  = _tpm_tis;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "Trusted Platform Module (TPM) TIS Interface";
+
 tc->model = TPM_MODEL_TPM_TIS;
 tc->get_version = tpm_tis_get_tpm_version;
 tc->request_completed = tpm_tis_request_completed;
-- 
2.14.2



signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v2 1/6] Categorize devices: IPMI

2019-03-27 Thread Ernest Esene
Set category and describe IPMI devices

Signed-off-by: Ernest Esene 

---
v2:
  * split into different patches
  * change category and description for management controllers
---
 hw/ipmi/ipmi_bmc_extern.c | 2 ++
 hw/ipmi/ipmi_bmc_sim.c| 2 ++
 hw/ipmi/isa_ipmi_bt.c | 2 ++
 hw/ipmi/isa_ipmi_kcs.c| 2 ++
 4 files changed, 8 insertions(+)

diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c
index bf0b7ee0f5..6d0c1f0734 100644
--- a/hw/ipmi/ipmi_bmc_extern.c
+++ b/hw/ipmi/ipmi_bmc_extern.c
@@ -526,6 +526,8 @@ static void ipmi_bmc_extern_class_init(ObjectClass *oc, 
void *data)
 dc->hotpluggable = false;
 dc->realize = ipmi_bmc_extern_realize;
 dc->props = ipmi_bmc_extern_properties;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "IPMI External Baseboard management controller";
 }
 
 static const TypeInfo ipmi_bmc_extern_type = {
diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index 9b509f829b..5d2438234b 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -2016,6 +2016,8 @@ static void ipmi_sim_class_init(ObjectClass *oc, void 
*data)
 dc->realize = ipmi_sim_realize;
 dc->props = ipmi_sim_properties;
 bk->handle_command = ipmi_sim_handle_command;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "IPMI Simulated Baseboard management controller";
 }
 
 static const TypeInfo ipmi_sim_type = {
diff --git a/hw/ipmi/isa_ipmi_bt.c b/hw/ipmi/isa_ipmi_bt.c
index 8bbb1fa785..9ca3402e98 100644
--- a/hw/ipmi/isa_ipmi_bt.c
+++ b/hw/ipmi/isa_ipmi_bt.c
@@ -541,6 +541,8 @@ static void isa_ipmi_bt_class_init(ObjectClass *oc, void 
*data)
 
 dc->realize = isa_ipmi_bt_realize;
 dc->props = ipmi_isa_properties;
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+dc->desc = "ISA IPMI BT System Interface";
 
 iic->get_backend_data = isa_ipmi_bt_get_backend_data;
 ipmi_bt_class_init(iic);
diff --git a/hw/ipmi/isa_ipmi_kcs.c b/hw/ipmi/isa_ipmi_kcs.c
index a79431554a..818d59d17b 100644
--- a/hw/ipmi/isa_ipmi_kcs.c
+++ b/hw/ipmi/isa_ipmi_kcs.c
@@ -524,6 +524,8 @@ static void isa_ipmi_kcs_class_init(ObjectClass *oc, void 
*data)
 
 dc->realize = ipmi_isa_realize;
 dc->props = ipmi_isa_properties;
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+dc->desc = "ISA IPMI KCS System Interface";
 
 iic->get_backend_data = isa_ipmi_kcs_get_backend_data;
 ipmi_kcs_class_init(iic);
-- 
2.14.2



signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH] Categorize devices

2019-03-27 Thread Ernest Esene
On Tue, Mar 26, 2019 at 03:49:04PM -0300, Eduardo Habkost wrote:
> On Tue, Mar 26, 2019 at 07:43:51PM +0100, Hervé Poussineau wrote:
> > Le 24/03/2019 à 19:05, Ernest Esene a écrit :
> > > Categorize devices in "uncategorised devices" section
> > > This patch is based on BiteSizedTask.
> > > 
> > > Signed-off-by: Ernest Esene 
> > > ---
> > >   hw/dma/i82374.c   | 2 ++
> > >   hw/i386/amd_iommu.c   | 2 ++
> > >   hw/i386/intel_iommu.c | 2 ++
> > >   hw/i386/pc_piix.c | 1 +
> > >   hw/ipmi/ipmi_bmc_extern.c | 2 ++
> > >   hw/ipmi/ipmi_bmc_sim.c| 2 ++
> > >   hw/ipmi/isa_ipmi_bt.c | 2 ++
> > >   hw/ipmi/isa_ipmi_kcs.c| 2 ++
> > >   hw/mem/nvdimm.c   | 1 +
> > >   hw/mem/pc-dimm.c  | 1 +
> > >   hw/tpm/tpm_tis.c  | 3 +++
> > >   11 files changed, 20 insertions(+)
> > 
> > 
> > i82374 part:
> > 
> > Reviewed-by: Hervé Poussineau 
> 
> Thanks!  I wonder if it would be useful to resubmit this as
> separate patches, so the parts that are already reviewed aren't
> blocked by missing reviews for the other devices.
> 
> -- 
> Eduardo
Thanks for the suggestion. I am going to resubmit as separate patches.

--
Ernest


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH] Categorize devices

2019-03-27 Thread Ernest Esene
On Mon, Mar 25, 2019 at 07:42:27PM -0500, Corey Minyard wrote:
> On Sun, Mar 24, 2019 at 07:05:23PM +0100, Ernest Esene wrote:
> > Categorize devices in "uncategorised devices" section
> > This patch is based on BiteSizedTask.
> > 
> > Signed-off-by: Ernest Esene 
> 
> I'm not 100% sure the use of this field.  A couple
> of comments on the IPMI one inline.
> 
> > ---
> >  hw/dma/i82374.c   | 2 ++
> >  hw/i386/amd_iommu.c   | 2 ++
> >  hw/i386/intel_iommu.c | 2 ++
> >  hw/i386/pc_piix.c | 1 +
> >  hw/ipmi/ipmi_bmc_extern.c | 2 ++
> >  hw/ipmi/ipmi_bmc_sim.c| 2 ++
> >  hw/ipmi/isa_ipmi_bt.c | 2 ++
> >  hw/ipmi/isa_ipmi_kcs.c| 2 ++
> >  hw/mem/nvdimm.c   | 1 +
> >  hw/mem/pc-dimm.c  | 1 +
> >  hw/tpm/tpm_tis.c  | 3 +++
> >  11 files changed, 20 insertions(+)
> > 
> > diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c
> > index bf0b7ee0..39049c4d 100644
> > --- a/hw/ipmi/ipmi_bmc_extern.c
> > +++ b/hw/ipmi/ipmi_bmc_extern.c
> > @@ -526,6 +526,8 @@ static void ipmi_bmc_extern_class_init(ObjectClass *oc, 
> > void *data)
> >  dc->hotpluggable = false;
> >  dc->realize = ipmi_bmc_extern_realize;
> >  dc->props = ipmi_bmc_extern_properties;
> > +set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
> > +dc->desc = "IPMI Baseboard management controller";
> 
> This is not exactly a bridge.  None of the categories seem
> to fit, though, a management device would be the best
> category, but that's not available.  misc is probably the
> best.
> 
> Also, the description might be betters a: "IPMI external
> baseboard management controller" to distinguish it from
> the next one...
> 
> >  }
> >  
> >  static const TypeInfo ipmi_bmc_extern_type = {
> > diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
> > index 9b509f82..95a096fa 100644
> > --- a/hw/ipmi/ipmi_bmc_sim.c
> > +++ b/hw/ipmi/ipmi_bmc_sim.c
> > @@ -2016,6 +2016,8 @@ static void ipmi_sim_class_init(ObjectClass *oc, void 
> > *data)
> >  dc->realize = ipmi_sim_realize;
> >  dc->props = ipmi_sim_properties;
> >  bk->handle_command = ipmi_sim_handle_command;
> > +set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
> > +dc->desc = "IPMI Baseboard management controller";
> 
> This is definitely not a bridge, same basic comment as above,
> but this is an internal simulator of the device.  For the
> description, perhaps: "IPMI simulated baseboard management
> controller"
> 
> >  }
> >  
> >  static const TypeInfo ipmi_sim_type = {
> > diff --git a/hw/ipmi/isa_ipmi_bt.c b/hw/ipmi/isa_ipmi_bt.c
> > index 8bbb1fa7..9ca3402e 100644
> > --- a/hw/ipmi/isa_ipmi_bt.c
> > +++ b/hw/ipmi/isa_ipmi_bt.c
> > @@ -541,6 +541,8 @@ static void isa_ipmi_bt_class_init(ObjectClass *oc, 
> > void *data)
> >  
> >  dc->realize = isa_ipmi_bt_realize;
> >  dc->props = ipmi_isa_properties;
> > +set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
> > +dc->desc = "ISA IPMI BT System Interface";
> 
> I'm ok with these being bridges, that seem accurate, and the
> description looks good.  Same for KCS below.
> 
> Thanks,
> 
> -corey
> 
Thank you corey.

Ernest


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH] Categorize devices

2019-03-24 Thread Ernest Esene
Categorize devices in "uncategorised devices" section
This patch is based on BiteSizedTask.

Signed-off-by: Ernest Esene 
---
 hw/dma/i82374.c   | 2 ++
 hw/i386/amd_iommu.c   | 2 ++
 hw/i386/intel_iommu.c | 2 ++
 hw/i386/pc_piix.c | 1 +
 hw/ipmi/ipmi_bmc_extern.c | 2 ++
 hw/ipmi/ipmi_bmc_sim.c| 2 ++
 hw/ipmi/isa_ipmi_bt.c | 2 ++
 hw/ipmi/isa_ipmi_kcs.c| 2 ++
 hw/mem/nvdimm.c   | 1 +
 hw/mem/pc-dimm.c  | 1 +
 hw/tpm/tpm_tis.c  | 3 +++
 11 files changed, 20 insertions(+)

diff --git a/hw/dma/i82374.c b/hw/dma/i82374.c
index 892f655a..5b42dd1b 100644
--- a/hw/dma/i82374.c
+++ b/hw/dma/i82374.c
@@ -147,6 +147,8 @@ static void i82374_class_init(ObjectClass *klass, void 
*data)
 dc->realize = i82374_realize;
 dc->vmsd = _i82374;
 dc->props = i82374_properties;
+dc->desc = "Intel Enhanced DMA controller";
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 }
 
 static const TypeInfo i82374_info = {
diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 6eabdf99..4a4e2c7f 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -1601,6 +1601,8 @@ static void amdvi_class_init(ObjectClass *klass, void* 
data)
 dc_class->int_remap = amdvi_int_remap;
 /* Supported by the pc-q35-* machine types */
 dc->user_creatable = true;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "AMD IOMMU (AMD-Vi) DMA Remapping device";
 }
 
 static const TypeInfo amdvi = {
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index b90de6c6..4d0e6042 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3702,6 +3702,8 @@ static void vtd_class_init(ObjectClass *klass, void *data)
 x86_class->int_remap = vtd_int_remap;
 /* Supported by the pc-q35-* machine types */
 dc->user_creatable = true;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->desc = "Intel IOMMU (VT-d) DMA Remapping device";
 }
 
 static const TypeInfo vtd_info = {
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 8ad8e885..03a9cb8a 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -911,6 +911,7 @@ static void isa_bridge_class_init(ObjectClass *klass, void 
*data)
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
 dc->desc= "ISA bridge faked to support IGD PT";
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 k->vendor_id= PCI_VENDOR_ID_INTEL;
 k->class_id = PCI_CLASS_BRIDGE_ISA;
 };
diff --git a/hw/ipmi/ipmi_bmc_extern.c b/hw/ipmi/ipmi_bmc_extern.c
index bf0b7ee0..39049c4d 100644
--- a/hw/ipmi/ipmi_bmc_extern.c
+++ b/hw/ipmi/ipmi_bmc_extern.c
@@ -526,6 +526,8 @@ static void ipmi_bmc_extern_class_init(ObjectClass *oc, 
void *data)
 dc->hotpluggable = false;
 dc->realize = ipmi_bmc_extern_realize;
 dc->props = ipmi_bmc_extern_properties;
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+dc->desc = "IPMI Baseboard management controller";
 }
 
 static const TypeInfo ipmi_bmc_extern_type = {
diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index 9b509f82..95a096fa 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -2016,6 +2016,8 @@ static void ipmi_sim_class_init(ObjectClass *oc, void 
*data)
 dc->realize = ipmi_sim_realize;
 dc->props = ipmi_sim_properties;
 bk->handle_command = ipmi_sim_handle_command;
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+dc->desc = "IPMI Baseboard management controller";
 }
 
 static const TypeInfo ipmi_sim_type = {
diff --git a/hw/ipmi/isa_ipmi_bt.c b/hw/ipmi/isa_ipmi_bt.c
index 8bbb1fa7..9ca3402e 100644
--- a/hw/ipmi/isa_ipmi_bt.c
+++ b/hw/ipmi/isa_ipmi_bt.c
@@ -541,6 +541,8 @@ static void isa_ipmi_bt_class_init(ObjectClass *oc, void 
*data)
 
 dc->realize = isa_ipmi_bt_realize;
 dc->props = ipmi_isa_properties;
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+dc->desc = "ISA IPMI BT System Interface";
 
 iic->get_backend_data = isa_ipmi_bt_get_backend_data;
 ipmi_bt_class_init(iic);
diff --git a/hw/ipmi/isa_ipmi_kcs.c b/hw/ipmi/isa_ipmi_kcs.c
index a7943155..818d59d1 100644
--- a/hw/ipmi/isa_ipmi_kcs.c
+++ b/hw/ipmi/isa_ipmi_kcs.c
@@ -524,6 +524,8 @@ static void isa_ipmi_kcs_class_init(ObjectClass *oc, void 
*data)
 
 dc->realize = ipmi_isa_realize;
 dc->props = ipmi_isa_properties;
+set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+dc->desc = "ISA IPMI KCS System Interface";
 
 iic->get_backend_data = isa_ipmi_kcs_get_backend_data;
 ipmi_kcs_class_init(iic);
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index bf2adf5e..a334dbe1 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -200,6 +200,7 @@ static void nvdimm_class_init(ObjectClass *oc, void *data)
 ddc->realize = nvdimm_realize;
 mdc-&g

[Qemu-devel] [PATCH] Replace calls to object_child_foreach() with object_child_foreach_recursive()

2019-03-09 Thread Ernest Esene
Replace calls to object_child_foreach() with object_child_foreach_recursive()
when applicable: nvdimm_device_list, nmi_monitor_handle, find_sysbus_device,
pc_dimm_slot2bitmap, build_dimm_list.

Signed-off-by: Ernest Esene 
---
 hw/acpi/nvdimm.c   | 5 +++--
 hw/core/sysbus.c   | 2 +-
 hw/mem/pc-dimm.c   | 5 +++--
 hw/virtio/virtio-balloon.c | 2 +-
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c
index e53b2cb..846f44b 100644
--- a/hw/acpi/nvdimm.c
+++ b/hw/acpi/nvdimm.c
@@ -41,7 +41,7 @@ static int nvdimm_device_list(Object *obj, void *opaque)
 *list = g_slist_append(*list, DEVICE(obj));
 }
 
-object_child_foreach(obj, nvdimm_device_list, opaque);
+object_child_foreach_recursive(obj, nvdimm_device_list, opaque);
 return 0;
 }
 
@@ -56,7 +56,8 @@ static GSList *nvdimm_get_device_list(void)
 {
 GSList *list = NULL;
 
-object_child_foreach(qdev_get_machine(), nvdimm_device_list, );
+object_child_foreach_recursive(qdev_get_machine(),
+   nvdimm_device_list, );
 return list;
 }
 
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 9f9edbc..c16d57c 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -43,7 +43,7 @@ static int find_sysbus_device(Object *obj, void *opaque)
 
 if (!sbdev) {
 /* Container, traverse it for children */
-return object_child_foreach(obj, find_sysbus_device, opaque);
+return object_child_foreach_recursive(obj, find_sysbus_device, opaque);
 }
 
 find->func(sbdev, find->opaque);
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 152400b..844c8ac 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -84,7 +84,7 @@ static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
 }
 }
 
-object_child_foreach(obj, pc_dimm_slot2bitmap, opaque);
+object_child_foreach_recursive(obj, pc_dimm_slot2bitmap, opaque);
 return 0;
 }
 
@@ -100,7 +100,8 @@ static int pc_dimm_get_free_slot(const int *hint, int 
max_slots, Error **errp)
 }
 
 bitmap = bitmap_new(max_slots);
-object_child_foreach(qdev_get_machine(), pc_dimm_slot2bitmap, bitmap);
+object_child_foreach_recursive(qdev_get_machine(),
+   pc_dimm_slot2bitmap, bitmap);
 
 /* check if requested slot is not occupied */
 if (hint) {
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index e3a6594..ce4b8a5 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -591,7 +591,7 @@ static int build_dimm_list(Object *obj, void *opaque)
 }
 }
 
-object_child_foreach(obj, build_dimm_list, opaque);
+object_child_foreach_recursive(obj, build_dimm_list, opaque);
 return 0;
 }
 
-- 
2.14.2