Re: [PATCH] block: use the request length for iov alignment

2022-09-15 Thread Keith Busch
On Wed, Sep 14, 2022 at 11:36:14AM +0100, Kevin Wolf wrote:
> Am 13.09.2022 um 15:12 hat Keith Busch geschrieben:
> > On Thu, Sep 08, 2022 at 09:45:26AM -0700, Keith Busch wrote:
> > > From: Keith Busch 
> > > 
> > > An iov length needs to be aligned to the logical block size, which may
> > > be larger than the memory alignment.
> > 
> > [cc'ing some other interested folks]
> > 
> > Any thoughts on this patch? It is fixing an observed IO error  when running
> > virtio-blk with the default 512b logical block size backed by a drive 
> > formatted
> > with 4k logical block.
> 
> I need to take a real look after KVM Forum, but my first thought was
> that we might be overloading request_alignment with multiple meanings
> now (file offset alignment and memory address alignment), and the values
> just happen to be the same for files on Linux.
> 
> Did you consider a separate iov_alignment or similar and intentionally
> decided against it, or is it something you just didn't think about?

I thought the request_alignment was indicating the minimum block length, so I
did not consider an additional separate value. If it can be overloaded, then
yes, I can certainly take on that idea.



Re: [PATCH v9 1/7] include: add zoned device structs

2022-09-15 Thread Eric Blake
On Sat, Sep 10, 2022 at 01:27:53PM +0800, Sam Li wrote:
> Signed-off-by: Sam Li 
> Reviewed-by: Stefan Hajnoczi 
> Reviewed-by: Damien Le Moal 
> ---
>  include/block/block-common.h | 43 
>  1 file changed, 43 insertions(+)
> 
> diff --git a/include/block/block-common.h b/include/block/block-common.h
> index fdb7306e78..36bd0e480e 100644
> --- a/include/block/block-common.h
> +++ b/include/block/block-common.h
> @@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver;
>  typedef struct BdrvChild BdrvChild;
>  typedef struct BdrvChildClass BdrvChildClass;
>  
> +typedef enum BlockZoneOp {
> +BLK_ZO_OPEN,
> +BLK_ZO_CLOSE,
> +BLK_ZO_FINISH,
> +BLK_ZO_RESET,
> +} BlockZoneOp;
> +
> +typedef enum BlockZoneModel {
> +BLK_Z_NONE = 0x0, /* Regular block device */
> +BLK_Z_HM = 0x1, /* Host-managed zoned block device */
> +BLK_Z_HA = 0x2, /* Host-aware zoned block device */
> +} BlockZoneModel;
> +
> +typedef enum BlockZoneCondition {
> +BLK_ZS_NOT_WP = 0x0,
> +BLK_ZS_EMPTY = 0x1,
> +BLK_ZS_IOPEN = 0x2,
> +BLK_ZS_EOPEN = 0x3,
> +BLK_ZS_CLOSED = 0x4,
> +BLK_ZS_RDONLY = 0xD,
> +BLK_ZS_FULL = 0xE,
> +BLK_ZS_OFFLINE = 0xF,
> +} BlockZoneCondition;
> +
> +typedef enum BlockZoneType {
> +BLK_ZT_CONV = 0x1, /* Conventional random writes supported */
> +BLK_ZT_SWR = 0x2, /* Sequential writes required */
> +BLK_ZT_SWP = 0x3, /* Sequential writes preferred */
> +} BlockZoneType;
> +
> +/*
> + * Zone descriptor data structure.
> + * Provides information on a zone with all position and size values in bytes.

I'm glad that you chose bytes here for use in qemu.  But since the
kernel struct blk_zone uses sectors instead of bytes, is it worth
adding a sentence that we intentionally use bytes here, different from
Linux, to make it easier for reviewers to realize that scaling when
translating between qemu and kernel is necessary?

> + */
> +typedef struct BlockZoneDescriptor {
> +uint64_t start;
> +uint64_t length;
> +uint64_t cap;
> +uint64_t wp;
> +BlockZoneType type;
> +BlockZoneCondition cond;
> +} BlockZoneDescriptor;
> +
>  typedef struct BlockDriverInfo {
>  /* in bytes, 0 if irrelevant */
>  int cluster_size;
> -- 
> 2.37.3
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v9 1/7] include: add zoned device structs

2022-09-15 Thread Sam Li
Eric Blake  于2022年9月15日周四 16:05写道:
>
> On Sat, Sep 10, 2022 at 01:27:53PM +0800, Sam Li wrote:
> > Signed-off-by: Sam Li 
> > Reviewed-by: Stefan Hajnoczi 
> > Reviewed-by: Damien Le Moal 
> > ---
> >  include/block/block-common.h | 43 
> >  1 file changed, 43 insertions(+)
> >
> > diff --git a/include/block/block-common.h b/include/block/block-common.h
> > index fdb7306e78..36bd0e480e 100644
> > --- a/include/block/block-common.h
> > +++ b/include/block/block-common.h
> > @@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver;
> >  typedef struct BdrvChild BdrvChild;
> >  typedef struct BdrvChildClass BdrvChildClass;
> >
> > +typedef enum BlockZoneOp {
> > +BLK_ZO_OPEN,
> > +BLK_ZO_CLOSE,
> > +BLK_ZO_FINISH,
> > +BLK_ZO_RESET,
> > +} BlockZoneOp;
> > +
> > +typedef enum BlockZoneModel {
> > +BLK_Z_NONE = 0x0, /* Regular block device */
> > +BLK_Z_HM = 0x1, /* Host-managed zoned block device */
> > +BLK_Z_HA = 0x2, /* Host-aware zoned block device */
> > +} BlockZoneModel;
> > +
> > +typedef enum BlockZoneCondition {
> > +BLK_ZS_NOT_WP = 0x0,
> > +BLK_ZS_EMPTY = 0x1,
> > +BLK_ZS_IOPEN = 0x2,
> > +BLK_ZS_EOPEN = 0x3,
> > +BLK_ZS_CLOSED = 0x4,
> > +BLK_ZS_RDONLY = 0xD,
> > +BLK_ZS_FULL = 0xE,
> > +BLK_ZS_OFFLINE = 0xF,
> > +} BlockZoneCondition;
> > +
> > +typedef enum BlockZoneType {
> > +BLK_ZT_CONV = 0x1, /* Conventional random writes supported */
> > +BLK_ZT_SWR = 0x2, /* Sequential writes required */
> > +BLK_ZT_SWP = 0x3, /* Sequential writes preferred */
> > +} BlockZoneType;
> > +
> > +/*
> > + * Zone descriptor data structure.
> > + * Provides information on a zone with all position and size values in 
> > bytes.
>
> I'm glad that you chose bytes here for use in qemu.  But since the
> kernel struct blk_zone uses sectors instead of bytes, is it worth
> adding a sentence that we intentionally use bytes here, different from
> Linux, to make it easier for reviewers to realize that scaling when
> translating between qemu and kernel is necessary?

Sorry about the unit mistake. The zone information is in sectors which
is the same as kernel struct blk_zone. I think adding a sentence to
inform the sector unit makes it clear what the zone descriptor is.

>
> > + */
> > +typedef struct BlockZoneDescriptor {
> > +uint64_t start;
> > +uint64_t length;
> > +uint64_t cap;
> > +uint64_t wp;
> > +BlockZoneType type;
> > +BlockZoneCondition cond;
> > +} BlockZoneDescriptor;
> > +
> >  typedef struct BlockDriverInfo {
> >  /* in bytes, 0 if irrelevant */
> >  int cluster_size;
> > --
> > 2.37.3
> >
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org
>



Re: [PATCH] bugfix:migrate with block-dirty-bitmap (disk size is big enough) can't be finished

2022-09-15 Thread Vladimir Sementsov-Ogievskiy

Post-copy migration of dirty-bitmaps doesn't mean post-copy migration of RAM.

To turn on post-copy migration of RAM, you should enable postcopy-ram 
capability. If you don't enable it, RAM is migrated in pre-copy (i.e. before 
starting VM on target).

migrate-start-postcopy command doesn't enable postcopy-ram capability 
automatically, so don't be afraid of it.

On 9/15/22 04:28, liuhaiwei9699 wrote:

Hi ,Vladimir
sometimes ,post-copy mode is not the best choice. For instance, Supposing 
migrate process will take ten minutes,but network may be interruptted In this 
process .
If it does happenthe , memory data of VM will be splitted into two parts, and 
will not be rollback.This is a bad situation


If you don't enable postcopy-ram capability, memory data is already migrated 
_before_ starting VM on destination. So, the only thing that we may lose in 
worst case is dirty bitmap itself, not RAM.



so  migrate-start-postcopy will not be setted in conservative scenario. In this 
case, the migration with block dirty bitmap may not be finished.


Again, migrate-start-postcopy command don't enable postcopy of RAM. It only 
allow to enter generic postcopy mode. If dirty-bitmaps capability is enabled 
and postcopy-ram is not, the only thing that can be migrated in postcopy is 
dirty bitmap.




I think  migration of block dirty bitmap should not dependent on post-copy or 
pre-copy mode.



But dirty bitmaps migration is realized as postcopy in Qemu.

We can't migrate bitmaps during downtime in general, as bitmaps may be large 
and connection slow (your case). So, we have to migrate them either in pre-copy 
or in post-copy mode. Historically, the second method was chosen.



At 2022-09-10 18:18:04, "Vladimir Sementsov-Ogievskiy" 
 wrote:

On 9/10/22 09:35, liuhaiwei wrote:

From: liuhaiwei 

bug description as  https://gitlab.com/qemu-project/qemu/-/issues/1203
Usually,we use the precopy or postcopy mode to migrate block dirty bitmap.
but if block-dirty-bitmap size more than threshold size,we cannot entry the 
migration_completion in migration_iteration_run function
To solve this problem, we can setting  the pending size to a fake 
value(threshold-1 or 0) to tell  migration_iteration_run function to entry the 
migration_completion,if pending size > threshold size




Actually, bitmaps migrate in postcopy. So, you should start postcopy for it to work (qmp 
command migrate-start-postcopy). This command simply set the boolean variable, so that in 
migration_iteration_run() we'll move to postcopy when needed. So, you can start this 
command immediately after migrate command, or even before it, but after setting the 
"dirty-bitmaps" capability.

Fake pending is a wrong thing to do, it means that you will make downtime to be 
larger than expected.

--
Best regards,
Vladimir



--
Best regards,
Vladimir



Re: [PATCH] hw/virtio/vhost-user: support obtain vdpa device's mac address automatically

2022-09-15 Thread ho...@yusur.tech
On Tue, Sep 13, 2022 at 17:08 PM Hao Chen  wrote:


>From: Hao Chen



>Date: 2022-09-13 17:08



>To: mst; raphael.norwitz



>CC: kwolf; hreitz; jasowang; qemu-block; qemu-devel; houyl; zy; Hao Chen



>Subject: [PATCH] hw/virtio/vhost-user: support obtain vdpa device's mac 
>address automatically



>When use dpdk-vdpa tests vdpa device. You need to specify the mac address to



>start the virtual machine through libvirt or qemu, but now, the libvirt or



>qemu can call dpdk vdpa vendor driver's ops .get_config through 
>vhost_net_get_config



>to get the mac address of the vdpa hardware without manual configuration.



 



>Signed-off-by: Hao Chen 



>---



>hw/block/vhost-user-blk.c |  1 -



>hw/net/virtio-net.c   |  3 ++-



>hw/virtio/vhost-user.c    | 19 ---



>3 files changed, 2 insertions(+), 21 deletions(-)



 



>diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c



>index 9117222456..5dca4eab09 100644



>--- a/hw/block/vhost-user-blk.c



>+++ b/hw/block/vhost-user-blk.c



>@@ -337,7 +337,6 @@ static int vhost_user_blk_connect(DeviceState *dev, Error 
>**errp)



> vhost_dev_set_config_notifier(&s->dev, &blk_ops);



>-    s->vhost_user.supports_config = true;



>    ret = vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USER, 0,



> errp);



>    if (ret < 0) {



>diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c



>index dd0d056fde..274ea84644 100644



>--- a/hw/net/virtio-net.c



>+++ b/hw/net/virtio-net.c



>@@ -149,7 +149,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, 
>uint8_t *config)



> * Is this VDPA? No peer means not VDPA: there's no way to

>

>  * disconnect/reconnect a VDPA peer.



>  */



>-    if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {



>+    if ((nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) ||



>+    (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_USER)) {



> ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t 
>*)&netcfg,



    n->config_size);



> if (ret != -1) {



>diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c



>index bd24741be8..8b01078249 100644



>--- a/hw/virtio/vhost-user.c



>+++ b/hw/virtio/vhost-user.c



>@@ -2013,8 +2013,6 @@ static int vhost_user_backend_init(struct vhost_dev 
>*dev, void *opaque,



>    }



>    if (virtio_has_feature(features, VHOST_USER_F_PROTOCOL_FEATURES)) {



>-    bool supports_f_config = vus->supports_config ||



>-    (dev->config_ops && dev->config_ops->vhost_dev_config_notifier);



> uint64_t protocol_features;



> dev->backend_features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES;



>@@ -2033,23 +2031,6 @@ static int vhost_user_backend_init(struct vhost_dev 
>*dev, void *opaque,



>  */



> protocol_features &= VHOST_USER_PROTOCOL_FEATURE_MASK;



>-    if (supports_f_config) {



>-    if (!virtio_has_feature(protocol_features,



>-    VHOST_USER_PROTOCOL_F_CONFIG)) {



>-    error_setg(errp, "vhost-user device expecting "



>-   "VHOST_USER_PROTOCOL_F_CONFIG but the vhost-user 
>backend does "



>-   "not support it.");



>-    return -EPROTO;



>-    }



>-    } else {



>-    if (virtio_has_feature(protocol_features,



>-   VHOST_USER_PROTOCOL_F_CONFIG)) {



>-    warn_reportf_err(*errp, "vhost-user backend supports "



>- "VHOST_USER_PROTOCOL_F_CONFIG but QEMU does 
>not.");



>-    protocol_features &= ~(1ULL << VHOST_USER_PROTOCOL_F_CONFIG);



>-    }



>-    }



>-



> /* final set of protocol features */



>    dev->protocol_features = protocol_features;



> err = vhost_user_set_protocol_features(dev, dev->protocol_features);



>--


Yusur (YUSUR Technology Co., Ltd.) focuses on the research and development of 
special data processors. 
The independently developed international leading DPU series products can be 
widely used in ultra-low 
latency network, big data processing, 5G edge computing, high-speed storage and 
other scenarios, 
helping computing power become the new productivity of the digital era.

The company put forward innovative Software Defined Accelerator technology and 
independently 
developed the chip architecture KPU(Kernel Processing Unit) and agile 
heterogeneous Software stack 
(HADOS) for domain-specific computing (DSA). 


Now, adding the feature of obtain vdpa device's mac address automatically for 
DPDK vDPA  path.



 




Re: [PATCH v11 18/21] job.c: enable job lock/unlock and remove Aiocontext locks

2022-09-15 Thread Vladimir Sementsov-Ogievskiy

On 8/26/22 16:21, Emanuele Giuseppe Esposito wrote:

Change the job_{lock/unlock} and macros to use job_mutex.

Now that they are not nop anymore, remove the aiocontext
to avoid deadlocks.

Therefore:
- when possible, remove completely the aiocontext lock/unlock pair
- if it is used by some other function too, reduce the locking
   section as much as possible, leaving the job API outside.
- change AIO_WAIT_WHILE in AIO_WAIT_WHILE_UNLOCKED, since we
   are not using the aiocontext lock anymore

The only functions that still need the aiocontext lock are the JobDriver
callbacks, already documented in job.h. Reduce the locking section to
only cover the callback invocation and document the functions that
take the AioContext lock, to avoid taking it twice.

Also remove real_job_{lock/unlock}, as they are replaced by the
public functions.

Signed-off-by: Emanuele Giuseppe Esposito 
Reviewed-by: Stefan Hajnoczi 
---


[..]


--- a/qemu-img.c
+++ b/qemu-img.c
@@ -911,7 +911,6 @@ static void run_block_job(BlockJob *job, Error **errp)
  AioContext *aio_context = block_job_get_aio_context(job);
  int ret = 0;
  
-aio_context_acquire(aio_context);

  job_lock();
  job_ref_locked(&job->job);
  do {


aio_poll() call here, doesn't require aio_context to be acquired?


@@ -936,7 +935,6 @@ static void run_block_job(BlockJob *job, Error **errp)
  }
  job_unref_locked(&job->job);
  job_unlock();
-aio_context_release(aio_context);
  
  /* publish completion progress only when success */

  if (!ret) {


[..]

In replication_stop, we call job_cancel_sync() inside aio_context_acquire - 
aio_context_release section. Should it be fixed?

Another question, sometimes you move job_start out of aio-context-acquire 
critical section, sometimes not. As I understand, it's of for job_start to be 
called both with acquired aio-context or not acquired?


Otherwise looks good to me!

--
Best regards,
Vladimir



Re: [PATCH v11 05/21] job.c: add job_lock/unlock while keeping job.h intact

2022-09-15 Thread Vladimir Sementsov-Ogievskiy

On 8/26/22 16:20, Emanuele Giuseppe Esposito wrote:

With "intact" we mean that all job.h functions implicitly
take the lock. Therefore API callers are unmodified.

This means that:
- many static functions that will be always called with job lock held
   become _locked, and call _locked functions
- all public functions take the lock internally if needed, and call _locked
   functions
- all public functions called internally by other functions in job.c will have a
   _locked counterpart (sometimes public), to avoid deadlocks (job lock already 
taken).
   These functions are not used for now.
- some public functions called only from exernal files (not job.c) do not
   have _locked() counterpart and take the lock inside. Others won't need
   the lock at all because use fields only set at initialization and
   never modified.

job_{lock/unlock} is independent from real_job_{lock/unlock}.

Note: at this stage, job_{lock/unlock} and job lock guard macros
are*nop*

Signed-off-by: Emanuele Giuseppe Esposito
Reviewed-by: Kevin Wolf
Reviewed-by: Stefan Hajnoczi


Reviewed-by: Vladimir Sementsov-Ogievskiy 

--
Best regards,
Vladimir



[PATCH 00/11] ppc/e500: Add support for two types of flash, cleanup

2022-09-15 Thread Bernhard Beschow
This series adds support for -pflash and direct SD card access to the
PPC e500 boards. The idea is to increase compatibility with "real" firmware
images where only the bare minimum of drivers is compiled in.

The series is structured as follows:

Patches 1-3 perform some general cleanup which paves the way for the rest of
the series.

Patches 4-7 add -pflash handling where memory-mapped flash can be added on
user's behalf. That is, the flash memory region is only added if the -pflash
argument is supplied. Note that the cfi01 device model becomes stricter in
checking the size of the emulated flash space.

Patches 8-11 add a new device model - the Freescale eSDHC - to the e500
boards which was missing so far.

User documentation is also added as the new features become available.

Tesing done:
* `qemu-system-ppc -M ppce500 -cpu e500mc -m 256 -kernel uImage -append
"console=ttyS0 rootwait root=/dev/mtdblock0 nokaslr" -drive
if=pflash,file=rootfs.ext2,format=raw`
* `qemu-system-ppc -M ppce500 -cpu e500mc -m 256 -kernel uImage -append
"console=ttyS0 rootwait root=/dev/mmcblk0" -device sd-card,drive=mydrive -drive
id=mydrive,if=none,file=rootfs.ext2,format=raw`

The load was created using latest Buildroot with `make
qemu_ppc_e500mc_defconfig` where the rootfs was configured to be of ext2 type.
In both cases it was possible to log in and explore the root file system.

Bernhard Beschow (11):
  hw/ppc/meson: Allow e500 boards to be enabled separately
  hw/gpio/meson: Introduce dedicated config switch for hw/gpio/mpc8xxx
  docs/system/ppc/ppce500: Add heading for networking chapter
  hw/ppc/mpc8544ds: Add platform bus
  hw/ppc/e500: Remove if statement which is now always true
  hw/block/pflash_cfi01: Error out if device length isn't a power of two
  hw/ppc/e500: Implement pflash handling
  hw/sd/sdhci-internal: Unexport ESDHC defines
  hw/sd/sdhci: Rename ESDHC_* defines to USDHC_*
  hw/sd/sdhci: Implement Freescale eSDHC device model
  hw/ppc/e500: Add Freescale eSDHC to e500 boards

 configs/devices/ppc-softmmu/default.mak |   3 +-
 docs/system/ppc/ppce500.rst |  28 
 hw/block/pflash_cfi01.c |   8 +-
 hw/gpio/Kconfig |   3 +
 hw/gpio/meson.build |   2 +-
 hw/ppc/Kconfig  |  11 ++
 hw/ppc/e500.c   | 116 +++--
 hw/ppc/e500.h   |   1 -
 hw/ppc/e500plat.c   |   1 -
 hw/ppc/meson.build  |   6 +-
 hw/ppc/mpc8544ds.c  |   5 +
 hw/sd/sdhci-internal.h  |  20 ---
 hw/sd/sdhci.c   | 212 +---
 include/hw/sd/sdhci.h   |   3 +
 14 files changed, 349 insertions(+), 70 deletions(-)

-- 
2.37.3




[PATCH 02/11] hw/gpio/meson: Introduce dedicated config switch for hw/gpio/mpc8xxx

2022-09-15 Thread Bernhard Beschow
Having a dedicated config switch makes dependency handling cleaner.

Signed-off-by: Bernhard Beschow 
---
 hw/gpio/Kconfig | 3 +++
 hw/gpio/meson.build | 2 +-
 hw/ppc/Kconfig  | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig
index f0e7405f6e..d2cf3accc8 100644
--- a/hw/gpio/Kconfig
+++ b/hw/gpio/Kconfig
@@ -8,6 +8,9 @@ config PL061
 config GPIO_KEY
 bool
 
+config GPIO_MPC8XXX
+bool
+
 config GPIO_PWR
 bool
 
diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build
index 7bd6a57264..b726e6d27a 100644
--- a/hw/gpio/meson.build
+++ b/hw/gpio/meson.build
@@ -1,5 +1,5 @@
-softmmu_ss.add(when: 'CONFIG_E500', if_true: files('mpc8xxx.c'))
 softmmu_ss.add(when: 'CONFIG_GPIO_KEY', if_true: files('gpio_key.c'))
+softmmu_ss.add(when: 'CONFIG_GPIO_MPC8XXX', if_true: files('mpc8xxx.c'))
 softmmu_ss.add(when: 'CONFIG_GPIO_PWR', if_true: files('gpio_pwr.c'))
 softmmu_ss.add(when: 'CONFIG_MAX7310', if_true: files('max7310.c'))
 softmmu_ss.add(when: 'CONFIG_PL061', if_true: files('pl061.c'))
diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
index 22a64745d4..791fe78a50 100644
--- a/hw/ppc/Kconfig
+++ b/hw/ppc/Kconfig
@@ -124,6 +124,7 @@ config E500
 imply AT24C
 imply VIRTIO_PCI
 select ETSEC
+select GPIO_MPC8XXX
 select OPENPIC
 select PLATFORM_BUS
 select PPCE500_PCI
-- 
2.37.3




[PATCH 01/11] hw/ppc/meson: Allow e500 boards to be enabled separately

2022-09-15 Thread Bernhard Beschow
Gives users more fine-grained control over what should be compiled into
QEMU.

Signed-off-by: Bernhard Beschow 
---
 configs/devices/ppc-softmmu/default.mak | 3 ++-
 hw/ppc/Kconfig  | 8 
 hw/ppc/meson.build  | 6 ++
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/configs/devices/ppc-softmmu/default.mak 
b/configs/devices/ppc-softmmu/default.mak
index 658a454426..a887f5438b 100644
--- a/configs/devices/ppc-softmmu/default.mak
+++ b/configs/devices/ppc-softmmu/default.mak
@@ -1,7 +1,8 @@
 # Default configuration for ppc-softmmu
 
 # For embedded PPCs:
-CONFIG_E500=y
+CONFIG_E500PLAT=y
+CONFIG_MPC8544DS=y
 CONFIG_PPC405=y
 CONFIG_PPC440=y
 CONFIG_VIRTEX=y
diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
index 3a4418a69e..22a64745d4 100644
--- a/hw/ppc/Kconfig
+++ b/hw/ppc/Kconfig
@@ -132,6 +132,14 @@ config E500
 select FDT_PPC
 select DS1338
 
+config E500PLAT
+bool
+select E500
+
+config MPC8544DS
+bool
+select E500
+
 config VIRTEX
 bool
 select PPC4XX
diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
index 62801923f3..32babc9b48 100644
--- a/hw/ppc/meson.build
+++ b/hw/ppc/meson.build
@@ -71,12 +71,10 @@ ppc_ss.add(when: 'CONFIG_MAC_OLDWORLD', if_true: 
files('mac_oldworld.c'))
 # NewWorld PowerMac
 ppc_ss.add(when: 'CONFIG_MAC_NEWWORLD', if_true: files('mac_newworld.c'))
 # e500
+ppc_ss.add(when: 'CONFIG_E500PLAT', if_true: files('e500plat.c'))
+ppc_ss.add(when: 'CONFIG_MPC8544DS', if_true: files('mpc8544ds.c'))
 ppc_ss.add(when: 'CONFIG_E500', if_true: files(
   'e500.c',
-  'mpc8544ds.c',
-  'e500plat.c'
-))
-ppc_ss.add(when: 'CONFIG_E500', if_true: files(
   'mpc8544_guts.c',
   'ppce500_spin.c'
 ))
-- 
2.37.3




[PATCH 05/11] hw/ppc/e500: Remove if statement which is now always true

2022-09-15 Thread Bernhard Beschow
Now that the MPC8544DS board also has a platform bus, the if statement
was always true.

Signed-off-by: Bernhard Beschow 
---
 hw/ppc/e500.c  | 30 ++
 hw/ppc/e500.h  |  1 -
 hw/ppc/e500plat.c  |  1 -
 hw/ppc/mpc8544ds.c |  1 -
 4 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 32495d0123..864b6f3d92 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -1007,25 +1007,23 @@ void ppce500_init(MachineState *machine)
 }
 
 /* Platform Bus Device */
-if (pmc->has_platform_bus) {
-dev = qdev_new(TYPE_PLATFORM_BUS_DEVICE);
-dev->id = g_strdup(TYPE_PLATFORM_BUS_DEVICE);
-qdev_prop_set_uint32(dev, "num_irqs", pmc->platform_bus_num_irqs);
-qdev_prop_set_uint32(dev, "mmio_size", pmc->platform_bus_size);
-sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
-pms->pbus_dev = PLATFORM_BUS_DEVICE(dev);
-
-s = SYS_BUS_DEVICE(pms->pbus_dev);
-for (i = 0; i < pmc->platform_bus_num_irqs; i++) {
-int irqn = pmc->platform_bus_first_irq + i;
-sysbus_connect_irq(s, i, qdev_get_gpio_in(mpicdev, irqn));
-}
+dev = qdev_new(TYPE_PLATFORM_BUS_DEVICE);
+dev->id = g_strdup(TYPE_PLATFORM_BUS_DEVICE);
+qdev_prop_set_uint32(dev, "num_irqs", pmc->platform_bus_num_irqs);
+qdev_prop_set_uint32(dev, "mmio_size", pmc->platform_bus_size);
+sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+pms->pbus_dev = PLATFORM_BUS_DEVICE(dev);
 
-memory_region_add_subregion(address_space_mem,
-pmc->platform_bus_base,
-sysbus_mmio_get_region(s, 0));
+s = SYS_BUS_DEVICE(pms->pbus_dev);
+for (i = 0; i < pmc->platform_bus_num_irqs; i++) {
+int irqn = pmc->platform_bus_first_irq + i;
+sysbus_connect_irq(s, i, qdev_get_gpio_in(mpicdev, irqn));
 }
 
+memory_region_add_subregion(address_space_mem,
+pmc->platform_bus_base,
+sysbus_mmio_get_region(s, 0));
+
 /*
  * Smart firmware defaults ahead!
  *
diff --git a/hw/ppc/e500.h b/hw/ppc/e500.h
index 1e5853b032..68f754ce50 100644
--- a/hw/ppc/e500.h
+++ b/hw/ppc/e500.h
@@ -27,7 +27,6 @@ struct PPCE500MachineClass {
 
 int mpic_version;
 bool has_mpc8xxx_gpio;
-bool has_platform_bus;
 hwaddr platform_bus_base;
 hwaddr platform_bus_size;
 int platform_bus_first_irq;
diff --git a/hw/ppc/e500plat.c b/hw/ppc/e500plat.c
index fc911bbb7b..5bb1c603da 100644
--- a/hw/ppc/e500plat.c
+++ b/hw/ppc/e500plat.c
@@ -86,7 +86,6 @@ static void e500plat_machine_class_init(ObjectClass *oc, void 
*data)
 pmc->fixup_devtree = e500plat_fixup_devtree;
 pmc->mpic_version = OPENPIC_MODEL_FSL_MPIC_42;
 pmc->has_mpc8xxx_gpio = true;
-pmc->has_platform_bus = true;
 pmc->platform_bus_base = 0xfULL;
 pmc->platform_bus_size = 128 * MiB;
 pmc->platform_bus_first_irq = 5;
diff --git a/hw/ppc/mpc8544ds.c b/hw/ppc/mpc8544ds.c
index cd6cd04bef..4ca696b56a 100644
--- a/hw/ppc/mpc8544ds.c
+++ b/hw/ppc/mpc8544ds.c
@@ -46,7 +46,6 @@ static void e500plat_machine_class_init(ObjectClass *oc, void 
*data)
 pmc->pci_nr_slots = 2;
 pmc->fixup_devtree = mpc8544ds_fixup_devtree;
 pmc->mpic_version = OPENPIC_MODEL_FSL_MPIC_20;
-pmc->has_platform_bus = true;
 pmc->platform_bus_base = 0xEC00ULL;
 pmc->platform_bus_size = 128 * MiB;
 pmc->platform_bus_first_irq = 5;
-- 
2.37.3




[PATCH 06/11] hw/block/pflash_cfi01: Error out if device length isn't a power of two

2022-09-15 Thread Bernhard Beschow
According to the JEDEC standard the device length is communicated to an
OS as an exponent (power of two).

Signed-off-by: Bernhard Beschow 
---
 hw/block/pflash_cfi01.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 0cbc2fb4cb..8c9b3f518a 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -690,7 +690,7 @@ static const MemoryRegionOps pflash_cfi01_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl)
+static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl, Error **errp)
 {
 uint64_t blocks_per_device, sector_len_per_device, device_len;
 int num_devices;
@@ -708,6 +708,10 @@ static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl)
 sector_len_per_device = pfl->sector_len / num_devices;
 }
 device_len = sector_len_per_device * blocks_per_device;
+if (ctpop64(device_len) != 1) {
+error_setg(errp, "Device size must be a power of two.");
+return;
+}
 
 /* Hardcoded CFI table */
 /* Standard "QRY" string */
@@ -865,7 +869,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error 
**errp)
  */
 pfl->cmd = 0x00;
 pfl->status = 0x80; /* WSM ready */
-pflash_cfi01_fill_cfi_table(pfl);
+pflash_cfi01_fill_cfi_table(pfl, errp);
 }
 
 static void pflash_cfi01_system_reset(DeviceState *dev)
-- 
2.37.3




[PATCH 09/11] hw/sd/sdhci: Rename ESDHC_* defines to USDHC_*

2022-09-15 Thread Bernhard Beschow
The device model's functions start with "usdhc_", so rename the defines
accordingly for consistency.

Signed-off-by: Bernhard Beschow 
---
 hw/sd/sdhci.c | 68 +--
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 6da5e2c781..7a5996caad 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1577,24 +1577,24 @@ static const TypeInfo sdhci_bus_info = {
 
 /* --- qdev i.MX eSDHC --- */
 
-#define ESDHC_MIX_CTRL  0x48
+#define USDHC_MIX_CTRL  0x48
 
-#define ESDHC_VENDOR_SPEC   0xc0
-#define ESDHC_IMX_FRC_SDCLK_ON  (1 << 8)
+#define USDHC_VENDOR_SPEC   0xc0
+#define USDHC_IMX_FRC_SDCLK_ON  (1 << 8)
 
-#define ESDHC_DLL_CTRL  0x60
+#define USDHC_DLL_CTRL  0x60
 
-#define ESDHC_TUNING_CTRL   0xcc
-#define ESDHC_TUNE_CTRL_STATUS  0x68
-#define ESDHC_WTMK_LVL  0x44
+#define USDHC_TUNING_CTRL   0xcc
+#define USDHC_TUNE_CTRL_STATUS  0x68
+#define USDHC_WTMK_LVL  0x44
 
 /* Undocumented register used by guests working around erratum ERR004536 */
-#define ESDHC_UNDOCUMENTED_REG270x6c
+#define USDHC_UNDOCUMENTED_REG270x6c
 
-#define ESDHC_CTRL_4BITBUS  (0x1 << 1)
-#define ESDHC_CTRL_8BITBUS  (0x2 << 1)
+#define USDHC_CTRL_4BITBUS  (0x1 << 1)
+#define USDHC_CTRL_8BITBUS  (0x2 << 1)
 
-#define ESDHC_PRNSTS_SDSTB  (1 << 3)
+#define USDHC_PRNSTS_SDSTB  (1 << 3)
 
 static uint64_t usdhc_read(void *opaque, hwaddr offset, unsigned size)
 {
@@ -1615,11 +1615,11 @@ static uint64_t usdhc_read(void *opaque, hwaddr offset, 
unsigned size)
 hostctl1 = SDHC_DMA_TYPE(s->hostctl1) << (8 - 3);
 
 if (s->hostctl1 & SDHC_CTRL_8BITBUS) {
-hostctl1 |= ESDHC_CTRL_8BITBUS;
+hostctl1 |= USDHC_CTRL_8BITBUS;
 }
 
 if (s->hostctl1 & SDHC_CTRL_4BITBUS) {
-hostctl1 |= ESDHC_CTRL_4BITBUS;
+hostctl1 |= USDHC_CTRL_4BITBUS;
 }
 
 ret  = hostctl1;
@@ -1630,21 +1630,21 @@ static uint64_t usdhc_read(void *opaque, hwaddr offset, 
unsigned size)
 
 case SDHC_PRNSTS:
 /* Add SDSTB (SD Clock Stable) bit to PRNSTS */
-ret = sdhci_read(opaque, offset, size) & ~ESDHC_PRNSTS_SDSTB;
+ret = sdhci_read(opaque, offset, size) & ~USDHC_PRNSTS_SDSTB;
 if (s->clkcon & SDHC_CLOCK_INT_STABLE) {
-ret |= ESDHC_PRNSTS_SDSTB;
+ret |= USDHC_PRNSTS_SDSTB;
 }
 break;
 
-case ESDHC_VENDOR_SPEC:
+case USDHC_VENDOR_SPEC:
 ret = s->vendor_spec;
 break;
-case ESDHC_DLL_CTRL:
-case ESDHC_TUNE_CTRL_STATUS:
-case ESDHC_UNDOCUMENTED_REG27:
-case ESDHC_TUNING_CTRL:
-case ESDHC_MIX_CTRL:
-case ESDHC_WTMK_LVL:
+case USDHC_DLL_CTRL:
+case USDHC_TUNE_CTRL_STATUS:
+case USDHC_UNDOCUMENTED_REG27:
+case USDHC_TUNING_CTRL:
+case USDHC_MIX_CTRL:
+case USDHC_WTMK_LVL:
 ret = 0;
 break;
 }
@@ -1660,18 +1660,18 @@ usdhc_write(void *opaque, hwaddr offset, uint64_t val, 
unsigned size)
 uint32_t value = (uint32_t)val;
 
 switch (offset) {
-case ESDHC_DLL_CTRL:
-case ESDHC_TUNE_CTRL_STATUS:
-case ESDHC_UNDOCUMENTED_REG27:
-case ESDHC_TUNING_CTRL:
-case ESDHC_WTMK_LVL:
+case USDHC_DLL_CTRL:
+case USDHC_TUNE_CTRL_STATUS:
+case USDHC_UNDOCUMENTED_REG27:
+case USDHC_TUNING_CTRL:
+case USDHC_WTMK_LVL:
 break;
 
-case ESDHC_VENDOR_SPEC:
+case USDHC_VENDOR_SPEC:
 s->vendor_spec = value;
 switch (s->vendor) {
 case SDHCI_VENDOR_IMX:
-if (value & ESDHC_IMX_FRC_SDCLK_ON) {
+if (value & USDHC_IMX_FRC_SDCLK_ON) {
 s->prnsts &= ~SDHC_IMX_CLOCK_GATE_OFF;
 } else {
 s->prnsts |= SDHC_IMX_CLOCK_GATE_OFF;
@@ -1740,12 +1740,12 @@ usdhc_write(void *opaque, hwaddr offset, uint64_t val, 
unsigned size)
  * Second, split "Data Transfer Width" from bits 2 and 1 in to
  * bits 5 and 1
  */
-if (value & ESDHC_CTRL_8BITBUS) {
+if (value & USDHC_CTRL_8BITBUS) {
 hostctl1 |= SDHC_CTRL_8BITBUS;
 }
 
-if (value & ESDHC_CTRL_4BITBUS) {
-hostctl1 |= ESDHC_CTRL_4BITBUS;
+if (value & USDHC_CTRL_4BITBUS) {
+hostctl1 |= USDHC_CTRL_4BITBUS;
 }
 
 /*
@@ -1768,11 +1768,11 @@ usdhc_write(void *opaque, hwaddr offset, uint64_t val, 
unsigned size)
 sdhci_write(opaque, offset, value, size);
 break;
 
-case ESDHC_MIX_CTRL:
+case USDHC_MIX_CTRL:
 /*
  * So, when SD/MMC stack in Linux tries to write to "Transfer
  * Mode Register", ESDHC i.MX quirk code will translate it
- * into a write to ESDHC_MIX_CTRL, so we do t

[PATCH 08/11] hw/sd/sdhci-internal: Unexport ESDHC defines

2022-09-15 Thread Bernhard Beschow
These defines aren't used outside of sdhci.c, so can be defined there.

Signed-off-by: Bernhard Beschow 
---
 hw/sd/sdhci-internal.h | 20 
 hw/sd/sdhci.c  | 19 +++
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/hw/sd/sdhci-internal.h b/hw/sd/sdhci-internal.h
index e8c753d6d1..964570f8e8 100644
--- a/hw/sd/sdhci-internal.h
+++ b/hw/sd/sdhci-internal.h
@@ -288,26 +288,6 @@ enum {
 
 extern const VMStateDescription sdhci_vmstate;
 
-
-#define ESDHC_MIX_CTRL  0x48
-
-#define ESDHC_VENDOR_SPEC   0xc0
-#define ESDHC_IMX_FRC_SDCLK_ON  (1 << 8)
-
-#define ESDHC_DLL_CTRL  0x60
-
-#define ESDHC_TUNING_CTRL   0xcc
-#define ESDHC_TUNE_CTRL_STATUS  0x68
-#define ESDHC_WTMK_LVL  0x44
-
-/* Undocumented register used by guests working around erratum ERR004536 */
-#define ESDHC_UNDOCUMENTED_REG270x6c
-
-#define ESDHC_CTRL_4BITBUS  (0x1 << 1)
-#define ESDHC_CTRL_8BITBUS  (0x2 << 1)
-
-#define ESDHC_PRNSTS_SDSTB  (1 << 3)
-
 /*
  * Default SD/MMC host controller features information, which will be
  * presented in CAPABILITIES register of generic SD host controller at reset.
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 0e5e988927..6da5e2c781 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1577,6 +1577,25 @@ static const TypeInfo sdhci_bus_info = {
 
 /* --- qdev i.MX eSDHC --- */
 
+#define ESDHC_MIX_CTRL  0x48
+
+#define ESDHC_VENDOR_SPEC   0xc0
+#define ESDHC_IMX_FRC_SDCLK_ON  (1 << 8)
+
+#define ESDHC_DLL_CTRL  0x60
+
+#define ESDHC_TUNING_CTRL   0xcc
+#define ESDHC_TUNE_CTRL_STATUS  0x68
+#define ESDHC_WTMK_LVL  0x44
+
+/* Undocumented register used by guests working around erratum ERR004536 */
+#define ESDHC_UNDOCUMENTED_REG270x6c
+
+#define ESDHC_CTRL_4BITBUS  (0x1 << 1)
+#define ESDHC_CTRL_8BITBUS  (0x2 << 1)
+
+#define ESDHC_PRNSTS_SDSTB  (1 << 3)
+
 static uint64_t usdhc_read(void *opaque, hwaddr offset, unsigned size)
 {
 SDHCIState *s = SYSBUS_SDHCI(opaque);
-- 
2.37.3




[PATCH 03/11] docs/system/ppc/ppce500: Add heading for networking chapter

2022-09-15 Thread Bernhard Beschow
The sudden change of topics is slightly confusing and makes the
networking information less visible. So separate the networking chapter
to improve comprehensibility.

Signed-off-by: Bernhard Beschow 
---
 docs/system/ppc/ppce500.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/docs/system/ppc/ppce500.rst b/docs/system/ppc/ppce500.rst
index 9beef39171..ba6bcb7314 100644
--- a/docs/system/ppc/ppce500.rst
+++ b/docs/system/ppc/ppce500.rst
@@ -146,6 +146,9 @@ You can specify a real world SoC device that QEMU has 
built-in support but all
 these SoCs are e500v2 based MPC85xx series, hence you cannot test anything
 built for P4080 (e500mc), P5020 (e5500) and T2080 (e6500).
 
+Networking
+--
+
 By default a VirtIO standard PCI networking device is connected as an ethernet
 interface at PCI address 0.1.0, but we can switch that to an e1000 NIC by:
 
-- 
2.37.3




[PATCH 04/11] hw/ppc/mpc8544ds: Add platform bus

2022-09-15 Thread Bernhard Beschow
Models the real device more closely.

Signed-off-by: Bernhard Beschow 
---
 hw/ppc/mpc8544ds.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/hw/ppc/mpc8544ds.c b/hw/ppc/mpc8544ds.c
index 81177505f0..cd6cd04bef 100644
--- a/hw/ppc/mpc8544ds.c
+++ b/hw/ppc/mpc8544ds.c
@@ -14,6 +14,7 @@
 #include "sysemu/device_tree.h"
 #include "hw/ppc/openpic.h"
 #include "qemu/error-report.h"
+#include "qemu/units.h"
 #include "cpu.h"
 
 static void mpc8544ds_fixup_devtree(void *fdt)
@@ -45,6 +46,11 @@ static void e500plat_machine_class_init(ObjectClass *oc, 
void *data)
 pmc->pci_nr_slots = 2;
 pmc->fixup_devtree = mpc8544ds_fixup_devtree;
 pmc->mpic_version = OPENPIC_MODEL_FSL_MPIC_20;
+pmc->has_platform_bus = true;
+pmc->platform_bus_base = 0xEC00ULL;
+pmc->platform_bus_size = 128 * MiB;
+pmc->platform_bus_first_irq = 5;
+pmc->platform_bus_num_irqs = 10;
 pmc->ccsrbar_base = 0xE000ULL;
 pmc->pci_mmio_base = 0xC000ULL;
 pmc->pci_mmio_bus_base = 0xC000ULL;
-- 
2.37.3




[PATCH 11/11] hw/ppc/e500: Add Freescale eSDHC to e500 boards

2022-09-15 Thread Bernhard Beschow
Adds missing functionality to emulated e500 SOCs which increases the
chance of given "real" firmware images to access SD cards.

Signed-off-by: Bernhard Beschow 
---
 docs/system/ppc/ppce500.rst | 13 +
 hw/ppc/Kconfig  |  1 +
 hw/ppc/e500.c   | 32 
 3 files changed, 46 insertions(+)

diff --git a/docs/system/ppc/ppce500.rst b/docs/system/ppc/ppce500.rst
index c3f55c6f3d..50b199c8f3 100644
--- a/docs/system/ppc/ppce500.rst
+++ b/docs/system/ppc/ppce500.rst
@@ -19,6 +19,7 @@ The ``ppce500`` machine supports the following devices:
 * Power-off functionality via one GPIO pin
 * 1 Freescale MPC8xxx PCI host controller
 * VirtIO devices via PCI bus
+* 1 Freescale Enhanced Secure Digital Host controller (eSDHC)
 * 1 Freescale Enhanced Triple Speed Ethernet controller (eTSEC)
 
 Hardware configuration information
@@ -131,6 +132,18 @@ be used as follows:
   -drive if=pflash,file=/path/to/rootfs.ext2,format=raw \
   -append "rootwait root=/dev/mtdblock0"
 
+Alternatively, the root file system can also reside on an emulated SD card
+whose size must again be a power of two:
+
+.. code-block:: bash
+
+  $ qemu-system-ppc64 -M ppce500 -cpu e500mc -smp 4 -m 2G \
+  -display none -serial stdio \
+  -kernel vmlinux \
+  -device sd-card,drive=mydrive \
+  -drive id=mydrive,if=none,file=/path/to/rootfs.ext2,format=raw \
+  -append "rootwait root=/dev/mmcblk0"
+
 Running U-Boot
 --
 
diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
index 769a1ead1c..6e31f568ba 100644
--- a/hw/ppc/Kconfig
+++ b/hw/ppc/Kconfig
@@ -129,6 +129,7 @@ config E500
 select PFLASH_CFI01
 select PLATFORM_BUS
 select PPCE500_PCI
+select SDHCI
 select SERIAL
 select MPC_I2C
 select FDT_PPC
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 7843a4e04b..87a03fd4a9 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -48,6 +48,7 @@
 #include "hw/net/fsl_etsec/etsec.h"
 #include "hw/i2c/i2c.h"
 #include "hw/irq.h"
+#include "hw/sd/sdhci.h"
 
 #define EPAPR_MAGIC(0x45504150)
 #define DTC_LOAD_PAD   0x180
@@ -66,11 +67,14 @@
 #define MPC8544_SERIAL1_REGS_OFFSET 0x4600ULL
 #define MPC8544_PCI_REGS_OFFSET0x8000ULL
 #define MPC8544_PCI_REGS_SIZE  0x1000ULL
+#define MPC85XX_ESDHC_REGS_OFFSET  0x2e000ULL
+#define MPC85XX_ESDHC_REGS_SIZE0x1000ULL
 #define MPC8544_UTIL_OFFSET0xeULL
 #define MPC8XXX_GPIO_OFFSET0x000FF000ULL
 #define MPC8544_I2C_REGS_OFFSET0x3000ULL
 #define MPC8XXX_GPIO_IRQ   47
 #define MPC8544_I2C_IRQ43
+#define MPC85XX_ESDHC_IRQ  72
 #define RTC_REGS_OFFSET0x68
 
 #define PLATFORM_CLK_FREQ_HZ   (400 * 1000 * 1000)
@@ -203,6 +207,25 @@ static void dt_i2c_create(void *fdt, const char *soc, 
const char *mpic,
 g_free(i2c);
 }
 
+static void dt_sdhc_create(void *fdt, const char *parent, const char *mpic)
+{
+hwaddr mmio = MPC85XX_ESDHC_REGS_OFFSET;
+hwaddr size = MPC85XX_ESDHC_REGS_SIZE;
+int irq = MPC85XX_ESDHC_IRQ;
+char *name;
+
+name = g_strdup_printf("%s/sdhc@%" PRIx64, parent, mmio);
+qemu_fdt_add_subnode(fdt, name);
+/* qemu_fdt_setprop_cells(fdt, name, "voltage-ranges", 3300, 3300); */
+qemu_fdt_setprop_cells(fdt, name, "clock-frequency", 16700);
+qemu_fdt_setprop(fdt, name, "sdhci,auto-cmd12", NULL, 0);
+qemu_fdt_setprop_phandle(fdt, name, "interrupt-parent", mpic);
+qemu_fdt_setprop_cells(fdt, name, "bus-width", 4);
+qemu_fdt_setprop_cells(fdt, name, "interrupts", irq, 0x2);
+qemu_fdt_setprop_cells(fdt, name, "reg", mmio, size);
+qemu_fdt_setprop_string(fdt, name, "compatible", "fsl,esdhc");
+g_free(name);
+}
 
 typedef struct PlatformDevtreeData {
 void *fdt;
@@ -556,6 +579,8 @@ static int ppce500_load_device_tree(PPCE500MachineState 
*pms,
 
 dt_rtc_create(fdt, "i2c", "rtc");
 
+/* sdhc */
+dt_sdhc_create(fdt, soc, mpic);
 
 gutil = g_strdup_printf("%s/global-utilities@%llx", soc,
 MPC8544_UTIL_OFFSET);
@@ -996,6 +1021,13 @@ void ppce500_init(MachineState *machine)
 i2c_slave_create_simple(i2c, "ds1338", RTC_REGS_OFFSET);
 
 
+/* eSDHC */
+dev = qdev_new(TYPE_FSL_ESDHC);
+s = SYS_BUS_DEVICE(dev);
+sysbus_realize_and_unref(s, &error_fatal);
+sysbus_mmio_map(s, 0, pmc->ccsrbar_base + MPC85XX_ESDHC_REGS_OFFSET);
+sysbus_connect_irq(s, 0, qdev_get_gpio_in(mpicdev, MPC85XX_ESDHC_IRQ));
+
 /* General Utility device */
 dev = qdev_new("mpc8544-guts");
 s = SYS_BUS_DEVICE(dev);
-- 
2.37.3




[PATCH 07/11] hw/ppc/e500: Implement pflash handling

2022-09-15 Thread Bernhard Beschow
Allows e500 boards to have their root file system reside on flash using
only builtin devices.

Note that the flash memory area is only created when a -pflash argument is
given, and that the size is determined by the given file. The idea is to
put users into control.

Signed-off-by: Bernhard Beschow 
---
 docs/system/ppc/ppce500.rst | 12 +
 hw/ppc/Kconfig  |  1 +
 hw/ppc/e500.c   | 54 +
 3 files changed, 67 insertions(+)

diff --git a/docs/system/ppc/ppce500.rst b/docs/system/ppc/ppce500.rst
index ba6bcb7314..c3f55c6f3d 100644
--- a/docs/system/ppc/ppce500.rst
+++ b/docs/system/ppc/ppce500.rst
@@ -119,6 +119,18 @@ To boot the 32-bit Linux kernel:
   -initrd /path/to/rootfs.cpio \
   -append "root=/dev/ram"
 
+Rather than using a root file system on ram disk, it is possible to have it on
+emulated flash. Given an ext2 image whose size must be a power of two, it can
+be used as follows:
+
+.. code-block:: bash
+
+  $ qemu-system-ppc64 -M ppce500 -cpu e500mc -smp 4 -m 2G \
+  -display none -serial stdio \
+  -kernel vmlinux \
+  -drive if=pflash,file=/path/to/rootfs.ext2,format=raw \
+  -append "rootwait root=/dev/mtdblock0"
+
 Running U-Boot
 --
 
diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
index 791fe78a50..769a1ead1c 100644
--- a/hw/ppc/Kconfig
+++ b/hw/ppc/Kconfig
@@ -126,6 +126,7 @@ config E500
 select ETSEC
 select GPIO_MPC8XXX
 select OPENPIC
+select PFLASH_CFI01
 select PLATFORM_BUS
 select PPCE500_PCI
 select SERIAL
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 864b6f3d92..7843a4e04b 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -23,8 +23,10 @@
 #include "e500-ccsr.h"
 #include "net/net.h"
 #include "qemu/config-file.h"
+#include "hw/block/flash.h"
 #include "hw/char/serial.h"
 #include "hw/pci/pci.h"
+#include "sysemu/block-backend-io.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/kvm.h"
 #include "sysemu/reset.h"
@@ -267,6 +269,34 @@ static void sysbus_device_create_devtree(SysBusDevice 
*sbdev, void *opaque)
 }
 }
 
+static void create_devtree_flash(SysBusDevice *sbdev,
+ PlatformDevtreeData *data)
+{
+char *name;
+uint64_t num_blocks = object_property_get_uint(OBJECT(sbdev),
+   "num-blocks",
+   &error_fatal);
+uint64_t sector_length = object_property_get_uint(OBJECT(sbdev),
+  "sector-length",
+  &error_fatal);
+uint64_t bank_width = object_property_get_uint(OBJECT(sbdev),
+   "width",
+   &error_fatal);
+hwaddr flashbase = 0;
+hwaddr flashsize = num_blocks * sector_length;
+void *fdt = data->fdt;
+
+name = g_strdup_printf("%s/nor@%" PRIx64, data->node, flashbase);
+qemu_fdt_add_subnode(fdt, name);
+qemu_fdt_setprop_cell(fdt, name, "#address-cells", 1);
+qemu_fdt_setprop_cell(fdt, name, "#size-cells", 1);
+qemu_fdt_setprop_string(fdt, name, "compatible", "cfi-flash");
+qemu_fdt_setprop_sized_cells(fdt, name, "reg",
+ 1, flashbase, 1, flashsize);
+qemu_fdt_setprop_cell(fdt, name, "bank-width", bank_width);
+g_free(name);
+}
+
 static void platform_bus_create_devtree(PPCE500MachineState *pms,
 void *fdt, const char *mpic)
 {
@@ -276,6 +306,8 @@ static void platform_bus_create_devtree(PPCE500MachineState 
*pms,
 uint64_t addr = pmc->platform_bus_base;
 uint64_t size = pmc->platform_bus_size;
 int irq_start = pmc->platform_bus_first_irq;
+SysBusDevice *sbdev;
+bool ambiguous;
 
 /* Create a /platform node that we can put all devices into */
 
@@ -302,6 +334,13 @@ static void 
platform_bus_create_devtree(PPCE500MachineState *pms,
 /* Loop through all dynamic sysbus devices and create nodes for them */
 foreach_dynamic_sysbus_device(sysbus_device_create_devtree, &data);
 
+sbdev = SYS_BUS_DEVICE(object_resolve_path_type("", TYPE_PFLASH_CFI01,
+&ambiguous));
+if (sbdev) {
+assert(!ambiguous);
+create_devtree_flash(sbdev, &data);
+}
+
 g_free(node);
 }
 
@@ -856,6 +895,7 @@ void ppce500_init(MachineState *machine)
 unsigned int pci_irq_nrs[PCI_NUM_PINS] = {1, 2, 3, 4};
 IrqLines *irqs;
 DeviceState *dev, *mpicdev;
+DriveInfo *dinfo;
 CPUPPCState *firstenv = NULL;
 MemoryRegion *ccsr_addr_space;
 SysBusDevice *s;
@@ -1024,6 +1064,20 @@ void ppce500_init(MachineState *machine)
 pmc->platform_bus_base,
 sysbus_mmio_get_region(s, 0));
 
+dinfo = drive_get(IF_PFLASH, 0, 0);
+if (dinfo) {
+Block

[PATCH 10/11] hw/sd/sdhci: Implement Freescale eSDHC device model

2022-09-15 Thread Bernhard Beschow
Will allow e500 boards to access SD cards using just their own devices.

Signed-off-by: Bernhard Beschow 
---
 hw/sd/sdhci.c | 147 +-
 include/hw/sd/sdhci.h |   3 +
 2 files changed, 149 insertions(+), 1 deletion(-)

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 7a5996caad..09285ccfa1 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1369,6 +1369,7 @@ void sdhci_initfn(SDHCIState *s)
 s->transfer_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sdhci_data_transfer, 
s);
 
 s->io_ops = &sdhci_mmio_ops;
+s->io_registers_map_size = SDHC_REGISTERS_MAP_SIZE;
 }
 
 void sdhci_uninitfn(SDHCIState *s)
@@ -1392,7 +1393,7 @@ void sdhci_common_realize(SDHCIState *s, Error **errp)
 s->fifo_buffer = g_malloc0(s->buf_maxsz);
 
 memory_region_init_io(&s->iomem, OBJECT(s), s->io_ops, s, "sdhci",
-  SDHC_REGISTERS_MAP_SIZE);
+  s->io_registers_map_size);
 }
 
 void sdhci_common_unrealize(SDHCIState *s)
@@ -1575,6 +1576,149 @@ static const TypeInfo sdhci_bus_info = {
 .class_init = sdhci_bus_class_init,
 };
 
+/* --- qdev Freescale eSDHC --- */
+
+/* Host Controller Capabilities Register 2 */
+#define ESDHC_CAPABILITIES_10x114
+
+/* Control Register for DMA transfer */
+#define ESDHC_DMA_SYSCTL0x40c
+#define ESDHC_PERIPHERAL_CLK_SEL0x0008
+#define ESDHC_FLUSH_ASYNC_FIFO  0x0004
+#define ESDHC_DMA_SNOOP 0x0040
+
+#define ESDHC_REGISTERS_MAP_SIZE0x410
+
+static uint64_t esdhci_read(void *opaque, hwaddr offset, unsigned size)
+{
+uint64_t ret;
+
+if (size != 4) {
+qemu_log_mask(LOG_GUEST_ERROR, "ESDHC rd_%ub @0x%02" HWADDR_PRIx
+  " wrong size\n", size, offset);
+return 0;
+}
+
+if (offset & 0x3) {
+qemu_log_mask(LOG_GUEST_ERROR, "ESDHC rd_%ub @0x%02" HWADDR_PRIx
+  " unaligned\n", size, offset);
+return 0;
+}
+
+switch (offset) {
+case SDHC_SYSAD:
+case SDHC_BLKSIZE:
+case SDHC_ARGUMENT:
+case SDHC_TRNMOD:
+case SDHC_RSPREG0:
+case SDHC_RSPREG1:
+case SDHC_RSPREG2:
+case SDHC_RSPREG3:
+case SDHC_BDATA:
+case SDHC_PRNSTS:
+case SDHC_HOSTCTL:
+case SDHC_CLKCON:
+case SDHC_NORINTSTS:
+case SDHC_NORINTSTSEN:
+case SDHC_NORINTSIGEN:
+case SDHC_ACMD12ERRSTS:
+case SDHC_CAPAB:
+case SDHC_SLOT_INT_STATUS:
+ret = sdhci_read(opaque, offset, size);
+break;
+
+case ESDHC_DMA_SYSCTL:
+case 0x44:
+ret = 0;
+qemu_log_mask(LOG_UNIMP, "ESDHC rd_%ub @0x%02" HWADDR_PRIx
+  " not implemented\n", size, offset);
+break;
+
+default:
+ret = 0;
+qemu_log_mask(LOG_GUEST_ERROR, "ESDHC rd_%ub @0x%02" HWADDR_PRIx
+  " unknown offset\n", size, offset);
+break;
+}
+
+return ret;
+}
+
+static void esdhci_write(void *opaque, hwaddr offset, uint64_t val,
+ unsigned size)
+{
+if (size != 4) {
+qemu_log_mask(LOG_GUEST_ERROR, "ESDHC wr_%ub @0x%02" HWADDR_PRIx
+  " <- 0x%08lx wrong size\n", size, offset, val);
+return;
+}
+
+if (offset & 0x3) {
+qemu_log_mask(LOG_GUEST_ERROR, "ESDHC wr_%ub @0x%02" HWADDR_PRIx
+  " <- 0x%08lx unaligned\n", size, offset, val);
+return;
+}
+
+switch (offset) {
+case SDHC_SYSAD:
+case SDHC_BLKSIZE:
+case SDHC_ARGUMENT:
+case SDHC_TRNMOD:
+case SDHC_BDATA:
+case SDHC_HOSTCTL:
+case SDHC_CLKCON:
+case SDHC_NORINTSTS:
+case SDHC_NORINTSTSEN:
+case SDHC_NORINTSIGEN:
+case SDHC_FEAER:
+sdhci_write(opaque, offset, val, size);
+break;
+
+case ESDHC_DMA_SYSCTL:
+case 0x44:
+qemu_log_mask(LOG_UNIMP, "ESDHC wr_%ub @0x%02" HWADDR_PRIx " <- 
0x%08lx "
+  "not implemented\n", size, offset, val);
+break;
+
+default:
+qemu_log_mask(LOG_GUEST_ERROR, "ESDHC wr_%ub @0x%02" HWADDR_PRIx
+  " <- 0x%08lx unknown offset\n", size, offset, val);
+break;
+}
+}
+
+static const MemoryRegionOps esdhc_mmio_ops = {
+.read = esdhci_read,
+.write = esdhci_write,
+.valid = {
+.min_access_size = 1,
+.max_access_size = 4,
+.unaligned = false
+},
+.endianness = DEVICE_BIG_ENDIAN,
+};
+
+static void esdhci_init(Object *obj)
+{
+DeviceState *dev = DEVICE(obj);
+SDHCIState *s = SYSBUS_SDHCI(obj);
+
+s->io_ops = &esdhc_mmio_ops;
+s->io_registers_map_size = ESDHC_REGISTERS_MAP_SIZE;
+
+/*
+ * Compatible with:
+ * - SD Host Controller Specification Version 2.0 Part A2
+ */
+qdev_prop_set_uint8(dev, "sd-spec-version", 2);
+}
+
+static const TypeInfo esdhc_info = {
+.name = TYPE_FSL_ESDHC,
+.parent = TYPE_SYSBUS_SDHCI,
+.instance_init = esdhci_init,
+};
+
 /* --- qdev i.MX 

[PATCH 12/27] qapi job: Elide redundant has_FOO in generated C

2022-09-15 Thread Markus Armbruster
The has_FOO for pointer-valued FOO are redundant, except for arrays.
They are also a nuisance to work with.  Recent commit "qapi: Start to
elide redundant has_FOO in generated C" provided the means to elide
them step by step.  This is the step for qapi/job.json.

Said commit explains the transformation in more detail.  The invariant
violations mentioned there do not occur here.

Cc: John Snow 
Cc: Vladimir Sementsov-Ogievskiy 
Cc: qemu-block@nongnu.org
Signed-off-by: Markus Armbruster 
---
 job-qmp.c  | 3 +--
 scripts/qapi/schema.py | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/job-qmp.c b/job-qmp.c
index 829a28aa70..f3c89c6db7 100644
--- a/job-qmp.c
+++ b/job-qmp.c
@@ -158,8 +158,7 @@ static JobInfo *job_query_single(Job *job, Error **errp)
 .status = job->status,
 .current_progress   = progress_current,
 .total_progress = progress_total,
-.has_error  = !!job->err,
-.error  = job->err ? \
+.error  = job->err ?
   g_strdup(error_get_pretty(job->err)) : NULL,
 };
 
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 2cdea9b3b6..765636a1a5 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -759,7 +759,6 @@ def need_has(self):
 assert self.type
 # Temporary hack to support dropping the has_FOO in reviewable chunks
 opt_out = [
-'qapi/job.json',
 'qapi/machine.json',
 'qapi/machine-target.json',
 'qapi/migration.json',
-- 
2.37.2




[PATCH 08/27] qapi block: Elide redundant has_FOO in generated C

2022-09-15 Thread Markus Armbruster
The has_FOO for pointer-valued FOO are redundant, except for arrays.
They are also a nuisance to work with.  Recent commit "qapi: Start to
elide redundant has_FOO in generated C" provided the means to elide
them step by step.  This is the step for qapi/block*.json.

Said commit explains the transformation in more detail.

There is one instance of the Invariant violation mentioned there:
qcow2_signal_corruption() passes false, "" when node_name is an empty
string.  Take care to pass NULL then.

Additionally, helper bdrv_latency_histogram_stats() loses its output
parameters and returns a value instead.

Cc: Kevin Wolf 
Cc: Hanna Reitz 
Cc: qemu-block@nongnu.org
Signed-off-by: Markus Armbruster 
---
 block/block-backend.c  |   2 +-
 block/copy-before-write.c  |   2 +-
 block/dirty-bitmap.c   |   1 -
 block/export/export.c  |   2 +-
 block/export/vduse-blk.c   |   3 +-
 block/gluster.c|   3 -
 block/monitor/block-hmp-cmds.c |  48 --
 block/qapi-sysemu.c|  73 +-
 block/qapi.c   |  62 +---
 block/qcow.c   |  10 +-
 block/qcow2.c  |  18 ++--
 block/qed.c|   2 +-
 block/quorum.c |   2 +-
 block/rbd.c|  15 +--
 block/ssh.c|   2 +-
 blockdev-nbd.c |   9 +-
 blockdev.c | 170 +
 blockjob.c |   2 -
 monitor/hmp-cmds.c |   3 +-
 nbd/server.c   |   2 +-
 qemu-img.c |  13 ++-
 qemu-nbd.c |   2 -
 scripts/qapi/schema.py |   3 -
 23 files changed, 170 insertions(+), 279 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index d4a5df2ac2..0433a1b0ba 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1861,7 +1861,7 @@ static void send_qmp_error_event(BlockBackend *blk,
 BlockDriverState *bs = blk_bs(blk);
 
 optype = is_read ? IO_OPERATION_TYPE_READ : IO_OPERATION_TYPE_WRITE;
-qapi_event_send_block_io_error(blk_name(blk), !!bs,
+qapi_event_send_block_io_error(blk_name(blk),
bs ? bdrv_get_node_name(bs) : NULL, optype,
action, blk_iostatus_is_enabled(blk),
error == ENOSPC, strerror(error));
diff --git a/block/copy-before-write.c b/block/copy-before-write.c
index c24b8dd117..6315651c7d 100644
--- a/block/copy-before-write.c
+++ b/block/copy-before-write.c
@@ -432,7 +432,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, 
int flags,
 return -EINVAL;
 }
 
-if (opts->has_bitmap) {
+if (opts->bitmap) {
 bitmap = block_dirty_bitmap_lookup(opts->bitmap->node,
opts->bitmap->name, NULL, errp);
 if (!bitmap) {
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index bf3dc0512a..9c39550698 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -541,7 +541,6 @@ BlockDirtyInfoList 
*bdrv_query_dirty_bitmaps(BlockDriverState *bs)
 
 info->count = bdrv_get_dirty_count(bm);
 info->granularity = bdrv_dirty_bitmap_granularity(bm);
-info->has_name = !!bm->name;
 info->name = g_strdup(bm->name);
 info->recording = bdrv_dirty_bitmap_recording(bm);
 info->busy = bdrv_dirty_bitmap_busy(bm);
diff --git a/block/export/export.c b/block/export/export.c
index 4744862915..da7480372c 100644
--- a/block/export/export.c
+++ b/block/export/export.c
@@ -114,7 +114,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error 
**errp)
 ctx = bdrv_get_aio_context(bs);
 aio_context_acquire(ctx);
 
-if (export->has_iothread) {
+if (export->iothread) {
 IOThread *iothread;
 AioContext *new_ctx;
 Error **set_context_errp;
diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c
index f101c24c3f..350d6fdaf0 100644
--- a/block/export/vduse-blk.c
+++ b/block/export/vduse-blk.c
@@ -265,8 +265,7 @@ static int vduse_blk_exp_create(BlockExport *exp, 
BlockExportOptions *opts,
 }
 vblk_exp->num_queues = num_queues;
 vblk_exp->handler.blk = exp->blk;
-vblk_exp->handler.serial = g_strdup(vblk_opts->has_serial ?
-vblk_opts->serial : "");
+vblk_exp->handler.serial = g_strdup(vblk_opts->serial ?: "");
 vblk_exp->handler.logical_block_size = logical_block_size;
 vblk_exp->handler.writable = opts->writable;
 
diff --git a/block/gluster.c b/block/gluster.c
index b60213ab80..e70f1c488a 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -830,7 +830,6 @@ static int qemu_gluster_open(BlockDriverState *bs,  QDict 
*options,
 s->logfile = g_strdup(logfile ? logfile : GLUSTER_LOGFILE_DEFAULT);
 
 gconf->logfile = g_strdup(s->logfile);
-gconf->has_logfile = true;
 
 s->glfs = 

[PATCH 00/27] qapi: Elide redundant has_FOO in generated C

2022-09-15 Thread Markus Armbruster
In QAPI, absent optional members are distinct from any present value.
We thus represent an optional schema member FOO as two C members: a
FOO with the member's type, and a bool has_FOO.  Likewise for function
arguments.

However, the has_FOO is actually redundant for a pointer-valued FOO,
which can be null only when has_FOO is false, i.e. has_FOO == !!FOO.
Except for arrays, where we a null FOO can also be a present empty
array.

The redundant has_FOO are a nuisance to work with.  Improve the
generator to elide them.

PATCH 01+02 are trivial documentation cleanups.

PATCH 03 tweaks an example in documentation so it'll show the change.

PATCH 04 improves the code generator, but nerfs the change for the
schema modules where handwritten code needs to be updated.

PATCH 05-26 un-nerfs in reviewable chunks.  Their commit messages
refer back to PATCH 04 for an explanation of the transformation.
Please read that first.  Note that these patches combine the
mechanical transformation with obvious, local follow-up
simplifications.  If you want them separate for easier review, let me
know.

PATCH 27 drops the nerfing code.

Cc: Ani Sinha 
Cc: Daniel P. Berrangé 
Cc: Daniel P. Berrangé" 
Cc: Dr. David Alan Gilbert 
Cc: Eduardo Habkost 
Cc: Gerd Hoffmann 
Cc: Hanna Reitz 
Cc: Igor Mammedov 
Cc: Jason Wang 
Cc: Jiri Pirko 
Cc: John Snow 
Cc: Juan Quintela 
Cc: Kevin Wolf 
Cc: Konstantin Kostiuk 
Cc: Marc-André Lureau 
Cc: Marcel Apfelbaum 
Cc: Mark Kanda 
Cc: Michael Roth 
Cc: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Pavel Dovgalyuk 
Cc: Philippe Mathieu-Daudé 
Cc: Stefan Berger 
Cc: Vladimir Sementsov-Ogievskiy 
Cc: Yanan Wang 
Cc: qemu-block@nongnu.org

Markus Armbruster (27):
  docs/devel/qapi-code-gen: Update example to match current code
  qapi: Tidy up whitespace in generated code
  docs/devel/qapi-code-gen: Extend example for next commit's change
  qapi: Start to elide redundant has_FOO in generated C
  qapi tests: Elide redundant has_FOO in generated C
  qapi acpi: Elide redundant has_FOO in generated C
  qapi audio: Elide redundant has_FOO in generated C
  qapi block: Elide redundant has_FOO in generated C
  qapi char: Elide redundant has_FOO in generated C
  qapi crypto: Elide redundant has_FOO in generated C
  qapi dump: Elide redundant has_FOO in generated C
  qapi job: Elide redundant has_FOO in generated C
  qapi machine: Elide redundant has_FOO in generated C
  qapi migration: Elide redundant has_FOO in generated C
  qapi misc: Elide redundant has_FOO in generated C
  qapi net: Elide redundant has_FOO in generated C
  qapi pci: Elide redundant has_FOO in generated C
  qapi qdev qom: Elide redundant has_FOO in generated C
  qapi replay: Elide redundant has_FOO in generated C
  qapi rocker: Elide redundant has_FOO in generated C
  qapi run-state: Elide redundant has_FOO in generated C
  qapi stats: Elide redundant has_FOO in generated C
  qapi tpm: Elide redundant has_FOO in generated C
  qapi transaction: Elide redundant has_FOO in generated C
  qapi ui: Elide redundant has_FOO in generated C
  qapi qga: Elide redundant has_FOO in generated C
  qapi: Drop temporary logic to support conversion step by step

 docs/devel/qapi-code-gen.rst |  29 +++-
 docs/devel/writing-monitor-commands.rst  |  14 +-
 include/monitor/monitor.h|   3 +-
 audio/alsaaudio.c|   2 +-
 audio/audio.c|   6 +-
 audio/audio_legacy.c |  17 +--
 audio/ossaudio.c |   8 +-
 audio/paaudio.c  |  12 +-
 audio/wavaudio.c |   2 +-
 backends/tpm/tpm_passthrough.c   |   2 -
 block/block-backend.c|   2 +-
 block/copy-before-write.c|   2 +-
 block/dirty-bitmap.c |   1 -
 block/export/export.c|   2 +-
 block/export/vduse-blk.c |   3 +-
 block/gluster.c  |   3 -
 block/monitor/block-hmp-cmds.c   |  48 +++
 block/qapi-sysemu.c  |  73 --
 block/qapi.c |  62 +++-
 block/qcow.c |  10 +-
 block/qcow2.c|  18 ++-
 block/qed.c  |   2 +-
 block/quorum.c   |   2 +-
 block/rbd.c  |  15 +-
 block/ssh.c  |   2 +-
 blockdev-nbd.c   |   9 +-
 blockdev.c   | 173 +--
 blockjob.c   |   2 -
 chardev/char-file.c  |   2 +-
 chardev/char-socket.c|  10 +-
 chardev/char-udp.c   |   1 -
 chardev/char.c   |   6 +-
 crypto/block-luks.c  |  16 +--
 dump/dump.c  |   4 +-
 hw/acpi/core.c   |  14 +-
 hw/acpi/

[PATCH 24/27] qapi transaction: Elide redundant has_FOO in generated C

2022-09-15 Thread Markus Armbruster
The has_FOO for pointer-valued FOO are redundant, except for arrays.
They are also a nuisance to work with.  Recent commit "qapi: Start to
elide redundant has_FOO in generated C" provided the means to elide
them step by step.  This is the step for qapi/transaction.json.

Said commit explains the transformation in more detail.  The invariant
violations mentioned there do not occur here.

Cc: Kevin Wolf 
Cc: Hanna Reitz 
Cc: qemu-block@nongnu.org
Signed-off-by: Markus Armbruster 
---
 blockdev.c | 3 +--
 scripts/qapi/schema.py | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index c1259f6bf1..9aac4e057c 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1039,7 +1039,7 @@ static void blockdev_do_action(TransactionAction *action, 
Error **errp)
 
 list.value = action;
 list.next = NULL;
-qmp_transaction(&list, false, NULL, errp);
+qmp_transaction(&list, NULL, errp);
 }
 
 void qmp_blockdev_snapshot_sync(const char *device, const char *node_name,
@@ -2293,7 +2293,6 @@ static TransactionProperties *get_transaction_properties(
  * Always run under BQL.
  */
 void qmp_transaction(TransactionActionList *dev_list,
- bool has_props,
  struct TransactionProperties *props,
  Error **errp)
 {
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 2bec0588c8..7fb24c2e5b 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -759,7 +759,6 @@ def need_has(self):
 assert self.type
 # Temporary hack to support dropping the has_FOO in reviewable chunks
 opt_out = [
-'qapi/transaction.json',
 'qapi/ui.json',
 'qga/qapi-schema.json']
 if self.info and any(self.info.fname.endswith(mod)
-- 
2.37.2




Re: [PATCH 0/7] nsis: gitlab-ci: Improve QEMU Windows installer packaging

2022-09-15 Thread Bin Meng
On Thu, Sep 8, 2022 at 9:28 PM Bin Meng  wrote:
>
> At present packaging the required DLLs of QEMU executables is a
> manual process, and error prone.
>
> Improve scripts/nsis.py by adding a logic to automatically package
> required DLLs of QEMU executables.
>
> 'make installer' is tested in the cross-build on Linux in CI, but
> not in the Windows native build. Update CI to test the installer
> generation on Windows too.
>
> During testing a 32-bit build issue was exposed in block/nfs.c and
> the fix is included in this series.
>
>
> Bin Meng (7):
>   scripts/nsis.py: Drop the unnecessary path separator
>   scripts/nsis.py: Fix destination directory name when invoked on
> Windows
>   scripts/nsis.py: Automatically package required DLLs of QEMU
> executables
>   .gitlab-ci.d/windows.yml: Drop the sed processing in the 64-bit build
>   block/nfs: Fix 32-bit Windows build
>   .gitlab-ci.d/windows.yml: Unify the prerequisite packages
>   .gitlab-ci.d/windows.yml: Test 'make installer' in the CI
>
>  meson.build  |  1 +
>  block/nfs.c  |  8 ++
>  .gitlab-ci.d/windows.yml | 40 ---
>  scripts/nsis.py  | 60 +---
>  4 files changed, 89 insertions(+), 20 deletions(-)
>

Ping for this series?



Re: [PATCH 01/11] hw/ppc/meson: Allow e500 boards to be enabled separately

2022-09-15 Thread Bin Meng
On Thu, Sep 15, 2022 at 11:25 PM Bernhard Beschow  wrote:
>
> Gives users more fine-grained control over what should be compiled into
> QEMU.
>
> Signed-off-by: Bernhard Beschow 
> ---
>  configs/devices/ppc-softmmu/default.mak | 3 ++-
>  hw/ppc/Kconfig  | 8 
>  hw/ppc/meson.build  | 6 ++
>  3 files changed, 12 insertions(+), 5 deletions(-)
>

Reviewed-by: Bin Meng 



Re: [PATCH 02/11] hw/gpio/meson: Introduce dedicated config switch for hw/gpio/mpc8xxx

2022-09-15 Thread Bin Meng
On Thu, Sep 15, 2022 at 11:26 PM Bernhard Beschow  wrote:
>
> Having a dedicated config switch makes dependency handling cleaner.
>
> Signed-off-by: Bernhard Beschow 
> ---
>  hw/gpio/Kconfig | 3 +++
>  hw/gpio/meson.build | 2 +-
>  hw/ppc/Kconfig  | 1 +
>  3 files changed, 5 insertions(+), 1 deletion(-)
>

Reviewed-by: Bin Meng 



Re: [PATCH 03/11] docs/system/ppc/ppce500: Add heading for networking chapter

2022-09-15 Thread Bin Meng
On Thu, Sep 15, 2022 at 11:29 PM Bernhard Beschow  wrote:
>
> The sudden change of topics is slightly confusing and makes the
> networking information less visible. So separate the networking chapter
> to improve comprehensibility.
>
> Signed-off-by: Bernhard Beschow 
> ---
>  docs/system/ppc/ppce500.rst | 3 +++
>  1 file changed, 3 insertions(+)
>

Reviewed-by: Bin Meng 



Re: [PATCH 05/11] hw/ppc/e500: Remove if statement which is now always true

2022-09-15 Thread Bin Meng
On Thu, Sep 15, 2022 at 11:34 PM Bernhard Beschow  wrote:
>
> Now that the MPC8544DS board also has a platform bus, the if statement
> was always true.
>
> Signed-off-by: Bernhard Beschow 
> ---
>  hw/ppc/e500.c  | 30 ++
>  hw/ppc/e500.h  |  1 -
>  hw/ppc/e500plat.c  |  1 -
>  hw/ppc/mpc8544ds.c |  1 -
>  4 files changed, 14 insertions(+), 19 deletions(-)
>

Reviewed-by: Bin Meng 



Re: [PATCH 04/11] hw/ppc/mpc8544ds: Add platform bus

2022-09-15 Thread Bin Meng
On Thu, Sep 15, 2022 at 11:29 PM Bernhard Beschow  wrote:
>
> Models the real device more closely.

Please describe the source (e.g.: I assume it's MPC8544DS board manual
or something like that?) that describe such memory map for the
platform bus.

Is this the eLBC bus range that includes the NOR flash device?

>
> Signed-off-by: Bernhard Beschow 
> ---
>  hw/ppc/mpc8544ds.c | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/hw/ppc/mpc8544ds.c b/hw/ppc/mpc8544ds.c
> index 81177505f0..cd6cd04bef 100644
> --- a/hw/ppc/mpc8544ds.c
> +++ b/hw/ppc/mpc8544ds.c
> @@ -14,6 +14,7 @@
>  #include "sysemu/device_tree.h"
>  #include "hw/ppc/openpic.h"
>  #include "qemu/error-report.h"
> +#include "qemu/units.h"
>  #include "cpu.h"
>
>  static void mpc8544ds_fixup_devtree(void *fdt)
> @@ -45,6 +46,11 @@ static void e500plat_machine_class_init(ObjectClass *oc, 
> void *data)
>  pmc->pci_nr_slots = 2;
>  pmc->fixup_devtree = mpc8544ds_fixup_devtree;
>  pmc->mpic_version = OPENPIC_MODEL_FSL_MPIC_20;
> +pmc->has_platform_bus = true;
> +pmc->platform_bus_base = 0xEC00ULL;
> +pmc->platform_bus_size = 128 * MiB;
> +pmc->platform_bus_first_irq = 5;
> +pmc->platform_bus_num_irqs = 10;
>  pmc->ccsrbar_base = 0xE000ULL;
>  pmc->pci_mmio_base = 0xC000ULL;
>  pmc->pci_mmio_bus_base = 0xC000ULL;
> --

Regards,
Bin



Re: [PATCH 06/11] hw/block/pflash_cfi01: Error out if device length isn't a power of two

2022-09-15 Thread Bin Meng
On Thu, Sep 15, 2022 at 11:26 PM Bernhard Beschow  wrote:
>
> According to the JEDEC standard the device length is communicated to an
> OS as an exponent (power of two).
>
> Signed-off-by: Bernhard Beschow 
> ---
>  hw/block/pflash_cfi01.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>

Reviewed-by: Bin Meng