[{"id":1775131,"web_url":"http://patchwork.ozlabs.org/comment/1775131/","msgid":"<20170926034706.GG12504@umbus>","list_archive_url":null,"date":"2017-09-26T03:47:06","subject":"Re: [Qemu-devel] [PATCH 6/7] mac_dbdma: change\n\tDBDMA_register_channel to a MAC_DBDMA type method","submitter":{"id":47,"url":"http://patchwork.ozlabs.org/api/people/47/","name":"David Gibson","email":"david@gibson.dropbear.id.au"},"content":"On Sun, Sep 24, 2017 at 03:47:45PM +0100, Mark Cave-Ayland wrote:\n> Using this we can change the MACIO_IDE instance to register the channel\n> itself via a type method instead of requiring a separate\n> DBDMA_register_channel() function.\n> \n> As a consequence of this it is now possible to remove the old external\n> macio_ide_register_dma() function.\n> \n> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>\n\nOk, two concerns about this.\n\nFirst, you've added the function pointer to the instance, not to the\nclass, which is not how a QOM method would normally be done.\n\nMore generally, though, why is a method preferable to a plain\nfunction?  AFAICT it's not plausible that there will ever be more than\none implementation of the method.\n\nSame comments apply to patch 7/7.\n\n> ---\n>  hw/ide/macio.c             |   12 ++++++------\n>  hw/misc/macio/mac_dbdma.c  |    9 +++++----\n>  hw/misc/macio/macio.c      |    1 -\n>  include/hw/ppc/mac_dbdma.h |    9 ++++-----\n>  4 files changed, 15 insertions(+), 16 deletions(-)\n> \n> diff --git a/hw/ide/macio.c b/hw/ide/macio.c\n> index ce194c6..b296017 100644\n> --- a/hw/ide/macio.c\n> +++ b/hw/ide/macio.c\n> @@ -411,12 +411,18 @@ static const IDEDMAOps dbdma_ops = {\n>  static void macio_ide_realizefn(DeviceState *dev, Error **errp)\n>  {\n>      MACIOIDEState *s = MACIO_IDE(dev);\n> +    DBDMAState *dbdma;\n>  \n>      ide_init2(&s->bus, s->ide_irq);\n>  \n>      /* Register DMA callbacks */\n>      s->dma.ops = &dbdma_ops;\n>      s->bus.dma = &s->dma;\n> +\n> +    /* Register DBDMA channel */\n> +    dbdma = MAC_DBDMA(object_property_get_link(OBJECT(dev), \"dbdma\", errp));\n> +    dbdma->register_channel(dbdma, s->channel, s->dma_irq,\n> +                            pmac_ide_transfer, pmac_ide_flush, s);\n>  }\n>  \n>  static void pmac_ide_irq(void *opaque, int n, int level)\n> @@ -497,10 +503,4 @@ void macio_ide_init_drives(MACIOIDEState *s, DriveInfo **hd_table)\n>      }\n>  }\n>  \n> -void macio_ide_register_dma(MACIOIDEState *s)\n> -{\n> -    DBDMA_register_channel(s->dbdma, s->channel, s->dma_irq,\n> -                           pmac_ide_transfer, pmac_ide_flush, s);\n> -}\n> -\n>  type_init(macio_ide_register_types)\n> diff --git a/hw/misc/macio/mac_dbdma.c b/hw/misc/macio/mac_dbdma.c\n> index 0eddf2e..addb97d 100644\n> --- a/hw/misc/macio/mac_dbdma.c\n> +++ b/hw/misc/macio/mac_dbdma.c\n> @@ -557,11 +557,10 @@ void DBDMA_kick(DBDMAState *dbdma)\n>      qemu_bh_schedule(dbdma->bh);\n>  }\n>  \n> -void DBDMA_register_channel(void *dbdma, int nchan, qemu_irq irq,\n> -                            DBDMA_rw rw, DBDMA_flush flush,\n> -                            void *opaque)\n> +static void\n> +dbdma_register_channel(DBDMAState *s, int nchan, qemu_irq irq,\n> +                       DBDMA_rw rw, DBDMA_flush flush, void *opaque)\n>  {\n> -    DBDMAState *s = dbdma;\n>      DBDMA_channel *ch = &s->channels[nchan];\n>  \n>      DBDMA_DPRINTFCH(ch, \"DBDMA_register_channel 0x%x\\n\", nchan);\n> @@ -903,6 +902,8 @@ static void mac_dbdma_init(Object *obj)\n>  \n>      memory_region_init_io(&s->mem, obj, &dbdma_ops, s, \"dbdma\", 0x1000);\n>      sysbus_init_mmio(sbd, &s->mem);\n> +\n> +    s->register_channel = dbdma_register_channel;\n>  }\n>  \n>  static void mac_dbdma_realize(DeviceState *dev, Error **errp)\n> diff --git a/hw/misc/macio/macio.c b/hw/misc/macio/macio.c\n> index 9aa7e75..533331a 100644\n> --- a/hw/misc/macio/macio.c\n> +++ b/hw/misc/macio/macio.c\n> @@ -161,7 +161,6 @@ static void macio_realize_ide(MacIOState *s, MACIOIDEState *ide,\n>      sysbus_connect_irq(sysbus_dev, 1, irq1);\n>      qdev_prop_set_uint32(DEVICE(ide), \"channel\", dmaid);\n>      object_property_set_link(OBJECT(ide), OBJECT(s->dbdma), \"dbdma\", errp);\n> -    macio_ide_register_dma(ide);\n>  \n>      object_property_set_bool(OBJECT(ide), true, \"realized\", errp);\n>  }\n> diff --git a/include/hw/ppc/mac_dbdma.h b/include/hw/ppc/mac_dbdma.h\n> index 26cc469..d6a38c5 100644\n> --- a/include/hw/ppc/mac_dbdma.h\n> +++ b/include/hw/ppc/mac_dbdma.h\n> @@ -160,19 +160,18 @@ typedef struct DBDMA_channel {\n>      dbdma_cmd current;\n>  } DBDMA_channel;\n>  \n> -typedef struct {\n> +typedef struct DBDMAState {\n>      SysBusDevice parent_obj;\n>  \n>      MemoryRegion mem;\n>      DBDMA_channel channels[DBDMA_CHANNELS];\n>      QEMUBH *bh;\n> +\n> +    void (*register_channel)(struct DBDMAState *s, int nchan, qemu_irq irq,\n> +                             DBDMA_rw rw, DBDMA_flush flush, void *opaque);\n>  } DBDMAState;\n>  \n>  /* Externally callable functions */\n> -\n> -void DBDMA_register_channel(void *dbdma, int nchan, qemu_irq irq,\n> -                            DBDMA_rw rw, DBDMA_flush flush,\n> -                            void *opaque);\n>  void DBDMA_kick(DBDMAState *dbdma);\n>  \n>  #define TYPE_MAC_DBDMA \"mac-dbdma\"","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=gibson.dropbear.id.au\n\theader.i=@gibson.dropbear.id.au header.b=\"ijUjJyC2\"; \n\tdkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y1Rrv6Y9Yz9t49\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 26 Sep 2017 13:53:51 +1000 (AEST)","from localhost ([::1]:45471 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dwgwQ-0004Ld-3n\n\tfor incoming@patchwork.ozlabs.org; Mon, 25 Sep 2017 23:53:50 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:38572)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1dwgv3-0003nB-2t\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 23:52:26 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1dwgv1-0001fc-MX\n\tfor qemu-devel@nongnu.org; Mon, 25 Sep 2017 23:52:25 -0400","from ozlabs.org ([2401:3900:2:1::2]:47787)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <dgibson@ozlabs.org>)\n\tid 1dwgv1-0001em-As; Mon, 25 Sep 2017 23:52:23 -0400","by ozlabs.org (Postfix, from userid 1007)\n\tid 3y1Rq84lj6z9t49; Tue, 26 Sep 2017 13:52:20 +1000 (AEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n\td=gibson.dropbear.id.au; s=201602; t=1506397940;\n\tbh=+QrCapbVZfPJcWSlb6gBmzfTeHWr9w3xD8IYWrmJoWo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ijUjJyC2/x68shx+KKTI3roVCYWs8yhR/PMfeZhyrxSWvrpHx/IDixnR352CCyeAu\n\tnT51oi8qlhStt7wtLsfUwQJgitxZ75xGxvH1rrMb/CjLdqmYDM2rK0MsEtfviCzEnp\n\t96l1npt4ZxzQzWwNlwDcUd/n+YvFhmOr3oWWldeA=","Date":"Tue, 26 Sep 2017 13:47:06 +1000","From":"David Gibson <david@gibson.dropbear.id.au>","To":"Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>","Message-ID":"<20170926034706.GG12504@umbus>","References":"<1506264466-28252-1-git-send-email-mark.cave-ayland@ilande.co.uk>\n\t<1506264466-28252-7-git-send-email-mark.cave-ayland@ilande.co.uk>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"9/eUdp+dLtKXvemk\"","Content-Disposition":"inline","In-Reply-To":"<1506264466-28252-7-git-send-email-mark.cave-ayland@ilande.co.uk>","User-Agent":"Mutt/1.9.0 (2017-09-02)","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2401:3900:2:1::2","Subject":"Re: [Qemu-devel] [PATCH 6/7] mac_dbdma: change\n\tDBDMA_register_channel to a MAC_DBDMA type method","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"qemu-ppc@nongnu.org, qemu-devel@nongnu.org","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1776793,"web_url":"http://patchwork.ozlabs.org/comment/1776793/","msgid":"<aaa2b280-4028-b593-e92a-5125d96fcbb6@ilande.co.uk>","list_archive_url":null,"date":"2017-09-28T06:40:18","subject":"Re: [Qemu-devel] [PATCH 6/7] mac_dbdma: change\n\tDBDMA_register_channel to a MAC_DBDMA type method","submitter":{"id":12451,"url":"http://patchwork.ozlabs.org/api/people/12451/","name":"Mark Cave-Ayland","email":"mark.cave-ayland@ilande.co.uk"},"content":"On 26/09/17 04:47, David Gibson wrote:\n\n> On Sun, Sep 24, 2017 at 03:47:45PM +0100, Mark Cave-Ayland wrote:\n>> Using this we can change the MACIO_IDE instance to register the channel\n>> itself via a type method instead of requiring a separate\n>> DBDMA_register_channel() function.\n>>\n>> As a consequence of this it is now possible to remove the old external\n>> macio_ide_register_dma() function.\n>>\n>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>\n> \n> Ok, two concerns about this.\n> \n> First, you've added the function pointer to the instance, not to the\n> class, which is not how a QOM method would normally be done.\n\nYeah I did think about whether I needed to create a full class but was\ntorn since as you say there is only one implementation.\n\n> More generally, though, why is a method preferable to a plain\n> function?  AFAICT it's not plausible that there will ever be more than\n> one implementation of the method.\n> \n> Same comments apply to patch 7/7.\n\nFor me it's really for encapsulation. It seems a little odd requiring a\nglobal function to configure a QOM object to which I already have a\nreference.\n\nIf I were to redo the last 2 patches using a proper class, would you\naccept them?\n\n\nATB,\n\nMark.","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y2lSz00wwz9t43\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 28 Sep 2017 16:41:05 +1000 (AEST)","from localhost ([::1]:57630 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dxSVI-000797-88\n\tfor incoming@patchwork.ozlabs.org; Thu, 28 Sep 2017 02:41:00 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:53429)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <mark.cave-ayland@ilande.co.uk>) id 1dxSUz-000792-5L\n\tfor qemu-devel@nongnu.org; Thu, 28 Sep 2017 02:40:42 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <mark.cave-ayland@ilande.co.uk>) id 1dxSUw-00072k-0v\n\tfor qemu-devel@nongnu.org; Thu, 28 Sep 2017 02:40:41 -0400","from chuckie.co.uk ([82.165.15.123]:44375\n\thelo=s16892447.onlinehome-server.info)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <mark.cave-ayland@ilande.co.uk>)\n\tid 1dxSUv-00072P-Ly; Thu, 28 Sep 2017 02:40:37 -0400","from host109-146-207-213.range109-146.btcentralplus.com\n\t([109.146.207.213] helo=[192.168.1.183])\n\tby s16892447.onlinehome-server.info with esmtpsa\n\t(TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76)\n\t(envelope-from <mark.cave-ayland@ilande.co.uk>)\n\tid 1dxSUu-0005V9-Vl; Thu, 28 Sep 2017 07:40:38 +0100"],"To":"David Gibson <david@gibson.dropbear.id.au>","References":"<1506264466-28252-1-git-send-email-mark.cave-ayland@ilande.co.uk>\n\t<1506264466-28252-7-git-send-email-mark.cave-ayland@ilande.co.uk>\n\t<20170926034706.GG12504@umbus>","From":"Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>","Message-ID":"<aaa2b280-4028-b593-e92a-5125d96fcbb6@ilande.co.uk>","Date":"Thu, 28 Sep 2017 07:40:18 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170926034706.GG12504@umbus>","Content-Type":"text/plain; charset=windows-1252","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","X-SA-Exim-Connect-IP":"109.146.207.213","X-SA-Exim-Mail-From":"mark.cave-ayland@ilande.co.uk","X-SA-Exim-Version":"4.2.1 (built Sun, 08 Jan 2012 02:45:44 +0000)","X-SA-Exim-Scanned":"Yes (on s16892447.onlinehome-server.info)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 3.x [fuzzy]","X-Received-From":"82.165.15.123","Subject":"Re: [Qemu-devel] [PATCH 6/7] mac_dbdma: change\n\tDBDMA_register_channel to a MAC_DBDMA type method","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"qemu-ppc@nongnu.org, qemu-devel@nongnu.org","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]