All of lore.kernel.org
 help / color / mirror / Atom feed
From: BALATON Zoltan <balaton@eik.bme.hu>
To: Nicholas Piggin <npiggin@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Subject: Re: [PATCH 2/4] ppc/amigaone: Implement NVRAM emulation
Date: Thu, 27 Feb 2025 17:40:58 +0100 (CET)	[thread overview]
Message-ID: <bbcac143-83ab-330e-389c-e7eaafccbef9@eik.bme.hu> (raw)
In-Reply-To: <D832OVALUQAP.19HG8HTKN2EGJ@gmail.com>

On Thu, 27 Feb 2025, Nicholas Piggin wrote:
> On Thu Feb 27, 2025 at 11:48 AM AEST, BALATON Zoltan wrote:
>> On Thu, 27 Feb 2025, Nicholas Piggin wrote:
>>> On Sun Feb 23, 2025 at 3:52 AM AEST, BALATON Zoltan wrote:
>>>> The board has a battery backed NVRAM where U-Boot environment is
>>>> stored which is also accessed by AmigaOS and e.g. C:NVGetVar command
>>>> crashes without it having at least a valid checksum.
>>>>
>>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>>> ---
>>>>  hw/ppc/amigaone.c | 116 ++++++++++++++++++++++++++++++++++++++++++++--
>>>>  1 file changed, 113 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/hw/ppc/amigaone.c b/hw/ppc/amigaone.c
>>>> index 4290d58613..5273543460 100644
>>>> --- a/hw/ppc/amigaone.c
>>>> +++ b/hw/ppc/amigaone.c
>>>> @@ -21,10 +21,13 @@
>>>>  #include "hw/ide/pci.h"
>>>>  #include "hw/i2c/smbus_eeprom.h"
>>>>  #include "hw/ppc/ppc.h"
>>>> +#include "system/block-backend.h"
>>>>  #include "system/qtest.h"
>>>>  #include "system/reset.h"
>>>>  #include "kvm_ppc.h"
>>>>
>>>> +#include <zlib.h> /* for crc32 */
>>>> +
>>>>  #define BUS_FREQ_HZ 100000000
>>>>
>>>>  /*
>>>> @@ -46,6 +49,103 @@ static const char dummy_fw[] = {
>>>>      0x4e, 0x80, 0x00, 0x20, /* blr */
>>>>  };
>>>>
>>>> +#define NVRAM_ADDR 0xfd0e0000
>>>> +#define NVRAM_SIZE (4 * KiB)
>>>> +
>>>> +#define TYPE_A1_NVRAM "a1-nvram"
>>>> +OBJECT_DECLARE_SIMPLE_TYPE(A1NVRAMState, A1_NVRAM)
>>>> +
>>>> +struct A1NVRAMState {
>>>> +    SysBusDevice parent_obj;
>>>> +
>>>> +    MemoryRegion mr;
>>>> +    BlockBackend *blk;
>>>> +};
>>>> +
>>>> +/* read callback not used because of romd mode, only here just in case */
>>>
>>> Better make it g_assert_not_reached() then.
>>
>> There is a memory_region_rom_device_set_romd() function. It's not called
>> here so a read function should not be needed but it's also trivial and
>> would work if romd mode is turned off for some reason in the future so
>> adding it seems safer to me. The comment is just to note it's a romd
>> region so reads normally don't go through this function unless romd mode
>> is turned off.
>
> It's trivial to add back if you do turn it off. Adding dead code is no
> good. The memory API default won't get changed underneath you without
> proper code audit or deprecating the API so that's no problem.

OK, done in v2.

>>> Better make these addresses #defines at the top of the file with
>>> the NVRAM_ADDR?
>>
>> I don't have defines for these as these are single use constants to set up
>> memory map and with defines it's less obvious and has to be looked up
>> where these are while this way I can see it directly without having to
>> scroll up so I prefer this. I've added defines where the constant is used
>> more than once where it makes sense to keep consistency.
>
> But now you have to lok in two different places anyway because you have
> the NVRAM_ADDR etc defines at the top of the file. Seems like a good
> time to move all defines there so you can easily see the memory map in
> one place.

I don't think this makes it more readable at all but I've added a patch in 
v2 to add defines for these.

Regards,
BALATON Zoltan


  reply	other threads:[~2025-02-27 16:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-22 17:52 [PATCH 0/4] ppc/amigaone patches BALATON Zoltan
2025-02-22 17:52 ` [PATCH 1/4] ppc/amigaone: Simplify replacement dummy_fw BALATON Zoltan
2025-02-27  0:50   ` Nicholas Piggin
2025-02-22 17:52 ` [PATCH 2/4] ppc/amigaone: Implement NVRAM emulation BALATON Zoltan
2025-02-27  1:10   ` Nicholas Piggin
2025-02-27  1:48     ` BALATON Zoltan
2025-02-27  8:08       ` Nicholas Piggin
2025-02-27 16:40         ` BALATON Zoltan [this message]
2025-02-22 17:52 ` [PATCH 3/4] ppc/amigaone: Add default environment BALATON Zoltan
2025-02-27  1:21   ` Nicholas Piggin
2025-02-27  2:18     ` BALATON Zoltan
2025-02-27  8:31       ` Nicholas Piggin
2025-02-27 17:07         ` BALATON Zoltan
2025-02-22 17:52 ` [PATCH 4/4] ppc/amigaone: Add kernel and initrd support BALATON Zoltan
2025-02-27  1:24   ` Nicholas Piggin
2025-02-24 19:04 ` [PATCH 0/4] ppc/amigaone patches Bernhard Beschow
2025-02-24 20:48   ` 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=bbcac143-83ab-330e-389c-e7eaafccbef9@eik.bme.hu \
    --to=balaton@eik.bme.hu \
    --cc=npiggin@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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.