qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: BALATON Zoltan <balaton@eik.bme.hu>
To: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	 Nicholas Piggin <npiggin@gmail.com>,
	 Daniel Henrique Barboza <danielhb413@gmail.com>,
	clg@kaod.org,  philmd@linaro.org,
	Bernhard Beschow <shentey@gmail.com>,
	 Rene Engel <ReneEngel80@emailn.de>,
	vr_qemu@t-online.de
Subject: Re: [PATCH 2/3] hw/pci-host: Add emulation of Mai Logic Articia S
Date: Tue, 10 Oct 2023 00:53:18 +0200 (CEST)	[thread overview]
Message-ID: <e9d17d6c-125b-0c1f-47e6-a23f193d7958@eik.bme.hu> (raw)
In-Reply-To: <c4223720-129a-42ee-a8c7-7bccc30002bd@ilande.co.uk>

[-- Attachment #1: Type: text/plain, Size: 8046 bytes --]

On Mon, 9 Oct 2023, Mark Cave-Ayland wrote:
> On 09/10/2023 22:57, BALATON Zoltan wrote:
>> On Mon, 9 Oct 2023, Mark Cave-Ayland wrote:
>>> On 08/10/2023 19:08, BALATON Zoltan wrote:
>>>> On Sun, 8 Oct 2023, Mark Cave-Ayland wrote:
>>>>> On 05/10/2023 23:13, BALATON Zoltan wrote:
>>>>> 
>>>>>> The Articia S is a generic chipset supporting several different CPUs
>>>>>> that were used on some PPC boards. This is a minimal emulation of the
>>>>>> parts needed for emulating the AmigaOne board.
>>>>>> 
>>>>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>>>>> ---
>>>>>>   hw/pci-host/Kconfig           |   5 +
>>>>>>   hw/pci-host/articia.c         | 266 
>>>>>> ++++++++++++++++++++++++++++++++++
>>>>>>   hw/pci-host/meson.build       |   2 +
>>>>>>   include/hw/pci-host/articia.h |  17 +++
>>>>>>   4 files changed, 290 insertions(+)
>>>>>>   create mode 100644 hw/pci-host/articia.c
>>>>>>   create mode 100644 include/hw/pci-host/articia.h
>>>>>> 
>>>>>> diff --git a/hw/pci-host/Kconfig b/hw/pci-host/Kconfig
>>>>>> index a07070eddf..33014c80a4 100644
>>>>>> --- a/hw/pci-host/Kconfig
>>>>>> +++ b/hw/pci-host/Kconfig
>>>>>> @@ -73,6 +73,11 @@ config SH_PCI
>>>>>>       bool
>>>>>>       select PCI
>>>>>>   +config ARTICIA
>>>>>> +    bool
>>>>>> +    select PCI
>>>>>> +    select I8259
>>>>>> +
>>>>>>   config MV64361
>>>>>>       bool
>>>>>>       select PCI
>>>>>> diff --git a/hw/pci-host/articia.c b/hw/pci-host/articia.c
>>>>>> new file mode 100644
>>>>>> index 0000000000..80558e1c47
>>>>>> --- /dev/null
>>>>>> +++ b/hw/pci-host/articia.c
>>>>>> @@ -0,0 +1,266 @@
>>>>>> +/*
>>>>>> + * Mai Logic Articia S emulation
>>>>>> + *
>>>>>> + * Copyright (c) 2023 BALATON Zoltan
>>>>>> + *
>>>>>> + * This work is licensed under the GNU GPL license version 2 or later.
>>>>>> + *
>>>>>> + */
>>>>>> +
>>>>>> +#include "qemu/osdep.h"
>>>>>> +#include "qemu/log.h"
>>>>>> +#include "qapi/error.h"
>>>>>> +#include "hw/pci/pci_device.h"
>>>>>> +#include "hw/pci/pci_host.h"
>>>>>> +#include "hw/irq.h"
>>>>>> +#include "hw/i2c/bitbang_i2c.h"
>>>>>> +#include "hw/intc/i8259.h"
>>>>>> +#include "hw/pci-host/articia.h"
>>>>>> +
>>>>>> +OBJECT_DECLARE_SIMPLE_TYPE(ArticiaState, ARTICIA)
>>>>>> +
>>>>>> +OBJECT_DECLARE_SIMPLE_TYPE(ArticiaHostState, ARTICIA_PCI_HOST)
>>>>>> +struct ArticiaHostState {
>>>>>> +    PCIDevice parent_obj;
>>>>>> +
>>>>>> +    ArticiaState *as;
>>>>>> +};
>>>>>> +
>>>>>> +/* TYPE_ARTICIA */
>>>>>> +
>>>>>> +struct ArticiaState {
>>>>>> +    PCIHostState parent_obj;
>>>>>> +
>>>>>> +    qemu_irq irq[PCI_NUM_PINS];
>>>>>> +    MemoryRegion io;
>>>>>> +    MemoryRegion mem;
>>>>>> +    MemoryRegion reg;
>>>>>> +
>>>>>> +    bitbang_i2c_interface smbus;
>>>>>> +    uint32_t gpio; /* bits 0-7 in, 8-15 out, 16-23 direction (0 in, 1 
>>>>>> out) */
>>>>>> +    hwaddr gpio_base;
>>>>>> +    MemoryRegion gpio_reg;
>>>>>> +};
>>>>> 
>>>>> These types above should be in the header file and not in the C file, as 
>>>>> per our current QOM guidelines.
>>>> 
>>>> I don't think there's such a guideline, at least I did not find any 
>>>> mention of it in style and qom docs. It was necessary to move some type 
>>>> declarations to headers for types that are embedded in other objects 
>>>> because C needs the struct size for that, but I don't think that should 
>>>> be a general thing when it's not needed.
>>>> 
>>>> The reason for that is that moving these to the header exposes internal 
>>>> object structure to users that should not need to know that so it breaks 
>>>> object encapsulation and also needs moving a bunch of includes to the 
>>>> header which then makes the users of this type also include those headers 
>>>> when they don't really need them but only need the type defines to 
>>>> instantiate the object and that's all they should have access to. So I 
>>>> think declaring types in the header should only be done for types that 
>>>> aren't full devices and are meant to be embedded as part of another 
>>>> device or a SoC but otherwise it's better to keep implementation closed 
>>>> and local to the object and not expose it unless really needed, that's 
>>>> why these are here.
>>>> 
>>>> If you insist I can move these but I don't think there's really such 
>>>> recommendation and I don't think that's a good idea because of the above.
>>> 
>>> Maybe it was something that was missed out of the recent documentation 
>>> updates, but you can clearly see this has been the standard pattern for 
>>> some time, including for recent devices such as the xlnx-versal. If there 
>>> are any devices that don't follow this pattern then it is likely because 
>>> they are based on older code.
>>> 
>>> If you disagree with this, then start a new thread on qemu-devel with a 
>>> new proposal and if everyone is agreement then that will be become the new 
>>> standard.
>> 
>> I think you should start a thread with a patch to style or qom docs about 
>> this to document this standard and if that's accepted then I also accept it 
>> as a real recommendation as my understanding of it was as above that it was 
>> needed for some deviecs to allow embedding them but not a general 
>> recommendation for all devices and I don't think it should be beacuse of 
>> braeaking encapsulation and introduces a lot of unneded includes so I'd 
>> keep it to those devices where it'e really needed which is what the docs 
>> currently say.
>
> Oh is there already a mention of this somewhere in the docs? Can you provide 
> a link so we can check the wording? Certainly that's the way my own patches 
> (and other people's patches) have been reviewed historically over the years.

The only mention I could find is in docs/devel/qom.rst, section "Standard 
type declaration and definition macros" which says: "In types which do not 
require any virtual functions in the class, the OBJECT_DECLARE_SIMPLE_TYPE 
macro is suitable, and is commonly placed in the header file" and then 
continues as "The 'struct MyDevice' needs to be declared separately." so 
it does not say the type should be in the header file, only the 
declaration macro and even that is not a requirement just a common 
pattern.

As I said above I think the convention of putting typedefs in the header 
came as a result of Peter's invention of embedding devices into their 
parents that is to avoid tools warning about not freing them which is 
reall working around a defficiency in the memory management of QEMU but 
this requires the parents to know the size of the objects to embed them as 
members so their declaration had to be moved to their public header for 
this. But this then breaks object encapsulation, locality and goes against 
another effort to reduce the number of unneded includes so I think this 
practice should be limited only to cases where it's needed. I've used that 
in PPC440 cleanup series before where the SoC object embeds the devices it 
contains so these were moved to a public header but here we model a 
complete device that isn't meant to be embedded anywhere so the board code 
should not need its internal structure. Therefore that's best declared in 
the implementation. Moving the OBJECT_DECLARE macros to the header could 
be done but also not necessary as per current docs so I wote for keeping 
scope of these to only where they are really needed and not expose them 
unnecessarily.

Regards,
BALATON Zoltan

>> But I also said I can change this if you insist as for just this devices 
>> only used once it does not matter much so I take that as you still want 
>> this chnage so I can send another version but wait for the opinion of the 
>> maintainers if they want anything else changed so I cah do all remaining 
>> changes in next version.
>
> Having a separate header would certainly be part of my review criteria as 
> I've been asked to make such changes in the past. But yeah, maybe wait for a 
> bit and see what other review comments arrive.
>
>
> ATB,
>
> Mark.
>
>
>

  reply	other threads:[~2023-10-09 22:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-05 22:12 [PATCH 0/3] Add emulation of AmigaOne XE board BALATON Zoltan
2023-10-05 22:13 ` [PATCH 1/3] via-ide: Fix legacy mode emulation BALATON Zoltan
2023-10-08  6:13   ` Mark Cave-Ayland
2023-10-08 11:08     ` BALATON Zoltan
2023-10-09  9:06       ` Bernhard Beschow
2023-10-09 11:22         ` BALATON Zoltan
2023-10-09 10:03       ` Bernhard Beschow
2023-10-09 13:02         ` BALATON Zoltan
2023-10-09 21:29       ` Mark Cave-Ayland
2023-10-09 22:23         ` BALATON Zoltan
2023-10-09 22:59           ` Mark Cave-Ayland
2023-10-10  0:00             ` BALATON Zoltan
2023-10-05 22:13 ` [PATCH 2/3] hw/pci-host: Add emulation of Mai Logic Articia S BALATON Zoltan
2023-10-06 21:13   ` Volker Rümelin
2023-10-07 10:21     ` BALATON Zoltan
2023-10-08  6:14   ` Mark Cave-Ayland
2023-10-08 18:08     ` BALATON Zoltan
2023-10-09 21:48       ` Mark Cave-Ayland
2023-10-09 21:57         ` BALATON Zoltan
2023-10-09 22:30           ` Mark Cave-Ayland
2023-10-09 22:53             ` BALATON Zoltan [this message]
2023-10-05 22:13 ` [PATCH 3/3] hw/ppc: Add emulation of AmigaOne XE board BALATON Zoltan
2023-10-09  6:24   ` Philippe Mathieu-Daudé
2023-10-09 11:56     ` 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=e9d17d6c-125b-0c1f-47e6-a23f193d7958@eik.bme.hu \
    --to=balaton@eik.bme.hu \
    --cc=ReneEngel80@emailn.de \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=npiggin@gmail.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=shentey@gmail.com \
    --cc=vr_qemu@t-online.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).