All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: BALATON Zoltan <balaton@eik.bme.hu>
Cc: qemu-block@nongnu.org, philmd@redhat.com,
	Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
	qemu-devel@nongnu.org,
	Aleksandar Markovic <amarkovic@wavecomp.com>,
	John Snow <jsnow@redhat.com>,
	Artyom Tarasenko <atar4qemu@gmail.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [PATCH 1/2] ide: Make room for flags in PCIIDEState and add one for legacy IRQ routing
Date: Mon, 02 Mar 2020 09:10:14 +0100	[thread overview]
Message-ID: <87pndvch3t.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <alpine.BSF.2.22.395.2003011619100.95594@zero.eik.bme.hu> (BALATON Zoltan's message of "Sun, 1 Mar 2020 16:27:50 +0100 (CET)")

BALATON Zoltan <balaton@eik.bme.hu> writes:

> On Sun, 1 Mar 2020, Mark Cave-Ayland wrote:
>> On 29/02/2020 23:02, BALATON Zoltan wrote:
>>> We'll need a flag for implementing some device specific behaviour in
>>> via-ide but we already have a currently CMD646 specific field that can
>>> be repurposed for this and leave room for furhter flags if needed in
>>> the future. This patch changes the "secondary" field to "flags" and
>>> define the flags for CMD646 and via-ide and change CMD646 and its
>>> users accordingly.
>>>
>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>> ---
>>>  hw/alpha/dp264.c     |  2 +-
>>>  hw/ide/cmd646.c      | 12 ++++++------
>>>  hw/sparc64/sun4u.c   |  9 ++-------
>>>  include/hw/ide.h     |  4 ++--
>>>  include/hw/ide/pci.h |  7 ++++++-
>>>  5 files changed, 17 insertions(+), 17 deletions(-)
>>>
>>> diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
[...]
>>> @@ -317,20 +317,20 @@ static void pci_cmd646_ide_exitfn(PCIDevice *dev)
>>>      }
>>>  }
>>>
>>> -void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table,
>>> -                         int secondary_ide_enabled)
>>> +void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn,
>>> +                         bool secondary_ide_enabled)
>>>  {
>>>      PCIDevice *dev;
>>>
>>> -    dev = pci_create(bus, -1, "cmd646-ide");
>>> -    qdev_prop_set_uint32(&dev->qdev, "secondary", secondary_ide_enabled);
>>> +    dev = pci_create(bus, devfn, "cmd646-ide");
>>> +    qdev_prop_set_bit(&dev->qdev, "secondary", secondary_ide_enabled);
>>>      qdev_init_nofail(&dev->qdev);
>>>
>>>      pci_ide_create_devs(dev, hd_table);
>>>  }
>>
>> Note that legacy init functions such as pci_cmd646_ide_init() should be removed where
>> possible, and in fact I posted a patch last week to completely remove it. This is
>> because using qdev directly allows each board to wire up the device as required,
>> rather than pushing it down into a set of init functions with different defaults.
>>
>> Given that you're working in this area, I'd highly recommend doing the same for
>> via_ide_init() too.
>
> I could do that, however these ide init functions seem to exist for
> piix, cmd646 and via-ide so that pci_ide_create_devs function is kept
> local to hw/ide. Nothing else called that func apart from sun4u so
> I've chosen this way to keep consistency (also keeps property type at
> one place instead of needing to change each board that sets
> property). If the consensus is that getting rid of these init funcs
> even if that means pci_ide_create_devs will not be local to ide any
> more I can go that way but would like to hear opinion of ide
> maintainer as well.

I think Mark's point is that modelling a device and wiring up a device
model are separate things, and the latter belongs to the board.

pci_cmd646_ide_init() is a helper for boards.  Similar helpers exist
elsewhere.

In the oldest stratum of qdev code, such helpers were static inline
functions in the device model's .h.  That way, they're kind of separate
from the device model proper, in the .c, and kind of in the board code
where they belong, via inlining.  I've always considered that a terrible
idea; it's "kind of" as in "not really".  Over time, practice moved
first to putting the helpers into .c, then to open-coding the wiring
where it belongs: in the boards.

A few helper functions have survived, e.g. in hw/lm32/milkymist-hw.h,
and the IDE helpers we're discussing here.

Of course, when the code to wire up certain devices gets overly
repetitive, factoring out common code into helpers can make sense.  But
where to put them?  I can't see an obvious home for common board
helpers.  We tend to put these wiring helpers into a device model's .c
code for want of a better place.  Tolerable, I think.



  reply	other threads:[~2020-03-02  8:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-29 23:02 [PATCH 0/2] Implement "non 100% native mode" in via-ide BALATON Zoltan
2020-02-29 23:02 ` [PATCH 1/2] ide: Make room for flags in PCIIDEState and add one for legacy IRQ routing BALATON Zoltan
2020-03-01 11:32   ` Mark Cave-Ayland
2020-03-01 15:27     ` BALATON Zoltan
2020-03-02  8:10       ` Markus Armbruster [this message]
2020-03-02 19:13         ` Mark Cave-Ayland
2020-03-02 23:26           ` BALATON Zoltan
2020-02-29 23:02 ` [PATCH 2/2] via-ide: Also emulate non 100% native mode BALATON Zoltan
2020-03-01 11:35   ` Mark Cave-Ayland
2020-03-01 11:41     ` Mark Cave-Ayland
2020-03-01 16:42       ` BALATON Zoltan
2020-03-01 17:54         ` Mark Cave-Ayland
2020-03-01 18:32           ` BALATON Zoltan
2020-03-01 18:53             ` BALATON Zoltan
2020-03-01 19:40               ` Mark Cave-Ayland
2020-03-01 21:30                 ` BALATON Zoltan
2020-03-02 19:00                   ` Mark Cave-Ayland
2020-03-02 21:40                     ` BALATON Zoltan
2020-03-03 20:40                       ` Mark Cave-Ayland
2020-03-04  0:22                         ` BALATON Zoltan
2020-03-04 21:04                           ` Mark Cave-Ayland
2020-03-04 22:33                             ` BALATON Zoltan
2020-03-05 18:40                               ` Mark Cave-Ayland
2020-03-05 23:35                                 ` BALATON Zoltan
2020-03-06  0:21                                   ` BALATON Zoltan
2020-03-06  7:25                                     ` Mark Cave-Ayland
2020-03-06 12:40                                       ` BALATON Zoltan
2020-03-06 18:44                                         ` Mark Cave-Ayland
2020-03-06  7:03                                   ` Mark Cave-Ayland
2020-03-06 12:06                                     ` BALATON Zoltan
2020-03-06 18:42                                       ` Mark Cave-Ayland
2020-03-06 19:38                                         ` BALATON Zoltan
2020-03-06 20:36                                           ` Mark Cave-Ayland
2020-03-06 22:59                                             ` BALATON Zoltan
2020-03-07 11:09                                               ` Mark Cave-Ayland
2020-03-07 15:56                                                 ` BALATON Zoltan
2020-03-06 12:36           ` Artyom Tarasenko
2020-03-01 16:31     ` BALATON Zoltan

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=87pndvch3t.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=amarkovic@wavecomp.com \
    --cc=atar4qemu@gmail.com \
    --cc=balaton@eik.bme.hu \
    --cc=jsnow@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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.