[PATCH] block/monitor: Consolidate hmp_handle_error calls to reduce redundant code

2021-08-02 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
---
 block/monitor/block-hmp-cmds.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
index 3e6670c963..2ac4aedfff 100644
--- a/block/monitor/block-hmp-cmds.c
+++ b/block/monitor/block-hmp-cmds.c
@@ -251,10 +251,10 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
 
 if (!filename) {
 error_setg(, QERR_MISSING_PARAMETER, "target");
-hmp_handle_error(mon, err);
-return;
+goto end;
 }
 qmp_drive_mirror(, );
+end:
 hmp_handle_error(mon, err);
 }
 
@@ -281,11 +281,11 @@ void hmp_drive_backup(Monitor *mon, const QDict *qdict)
 
 if (!filename) {
 error_setg(, QERR_MISSING_PARAMETER, "target");
-hmp_handle_error(mon, err);
-return;
+goto end;
 }
 
 qmp_drive_backup(, );
+end:
 hmp_handle_error(mon, err);
 }
 
@@ -356,8 +356,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
  * will be taken internally. Today it's actually required.
  */
 error_setg(, QERR_MISSING_PARAMETER, "snapshot-file");
-hmp_handle_error(mon, err);
-return;
+goto end;
 }
 
 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
@@ -365,6 +364,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
filename, false, NULL,
!!format, format,
true, mode, );
+end:
 hmp_handle_error(mon, err);
 }
 
-- 
2.31.1






[PATCH] docs: Update path that mentions deprecated.rst

2021-07-23 Thread Mao Zhongyi
Missed in commit f3478392 "docs: Move deprecation, build
and license info out of system/"

Signed-off-by: Mao Zhongyi 
---
 MAINTAINERS   | 2 +-
 configure | 2 +-
 target/i386/cpu.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4256ad1adb..701d071258 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3435,7 +3435,7 @@ F: contrib/gitdm/*
 
 Incompatible changes
 R: libvir-l...@redhat.com
-F: docs/system/deprecated.rst
+F: docs/about/deprecated.rst
 
 Build System
 
diff --git a/configure b/configure
index b5965b159f..dfbbfc5e94 100755
--- a/configure
+++ b/configure
@@ -5242,7 +5242,7 @@ fi
 
 if test -n "${deprecated_features}"; then
 echo "Warning, deprecated features enabled."
-echo "Please see docs/system/deprecated.rst"
+echo "Please see docs/about/deprecated.rst"
 echo "  features: ${deprecated_features}"
 fi
 
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 48b55ebd0a..129602fc97 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -4110,7 +4110,7 @@ static const X86CPUDefinition builtin_x86_defs[] = {
  * none", but this is just for compatibility while libvirt isn't
  * adapted to resolve CPU model versions before creating VMs.
  * See "Runnability guarantee of CPU models" at
- * docs/system/deprecated.rst.
+ * docs/about/deprecated.rst.
  */
 X86CPUVersion default_cpu_version = 1;
 
-- 
2.31.1






[PATCH 8/9] docs/xbzrle: update 'cache miss rate' and 'encoding rate' to docs

2020-06-03 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
---
 docs/xbzrle.txt | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/docs/xbzrle.txt b/docs/xbzrle.txt
index 385b4993f8..6bd1828f34 100644
--- a/docs/xbzrle.txt
+++ b/docs/xbzrle.txt
@@ -113,9 +113,11 @@ is recommended.
 xbzrle transferred: I kbytes
 xbzrle pages: J pages
 xbzrle cache miss: K pages
-xbzrle overflow: L
+xbzrle cache miss rate: L
+xbzrle encoding rate: M
+xbzrle overflow: N
 
-xbzrle cache-miss: the number of cache misses to date - high cache-miss rate
+xbzrle cache miss: the number of cache misses to date - high cache-miss rate
 indicates that the cache size is set too low.
 xbzrle overflow: the number of overflows in the decoding which where the delta
 could not be compressed. This can happen if the changes in the pages are too
-- 
2.17.1






[PATCH 3/9] monitor/hmp-cmds: add units for migrate_parameters

2020-06-03 Thread Mao Zhongyi
When running:
(qemu) info migrate_parameters
announce-initial: 50 ms
announce-max: 550 ms
announce-step: 100 ms
compress-wait-thread: on
...
max-bandwidth: 33554432 bytes/second
downtime-limit: 300 milliseconds
x-checkpoint-delay: 2
...
xbzrle-cache-size: 67108864

add units for the parameters 'x-checkpoint-delay' and
'xbzrle-cache-size', it's easier to read, also move
milliseconds to ms to keep the same style.

Signed-off-by: Mao Zhongyi 
Reviewed-by: Dr. David Alan Gilbert 
Reviewed-by: Stefano Garzarella 
---
 monitor/hmp-cmds.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 9c61e769ca..8c3e436b39 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -443,11 +443,11 @@ void hmp_info_migrate_parameters(Monitor *mon, const 
QDict *qdict)
 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
 params->max_bandwidth);
 assert(params->has_downtime_limit);
-monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
+monitor_printf(mon, "%s: %" PRIu64 " ms\n",
 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
 params->downtime_limit);
 assert(params->has_x_checkpoint_delay);
-monitor_printf(mon, "%s: %u\n",
+monitor_printf(mon, "%s: %u ms\n",
 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
 params->x_checkpoint_delay);
 assert(params->has_block_incremental);
@@ -460,7 +460,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict 
*qdict)
 monitor_printf(mon, "%s: %s\n",
 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
 MultiFDCompression_str(params->multifd_compression));
-monitor_printf(mon, "%s: %" PRIu64 "\n",
+monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
 params->xbzrle_cache_size);
 monitor_printf(mon, "%s: %" PRIu64 "\n",
-- 
2.17.1






[PATCH 1/9] tests/migration: mem leak fix

2020-06-03 Thread Mao Zhongyi
‘data’ has the possibility of memory leaks, so use the
glib macros g_autofree recommended by CODING_STYLE.rst
to automatically release the memory that returned from
g_malloc().

Signed-off-by: Mao Zhongyi 
Reviewed-by: Alex Bennée 
Reviewed-by: Laurent Vivier 
---
 tests/migration/stress.c | 21 ++---
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index 0c23964693..f9626d50ee 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -170,26 +170,14 @@ static unsigned long long now(void)
 static int stressone(unsigned long long ramsizeMB)
 {
 size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
-char *ram = malloc(ramsizeMB * 1024 * 1024);
+g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
 char *ramptr;
 size_t i, j, k;
-char *data = malloc(PAGE_SIZE);
+g_autofree char *data = g_malloc(PAGE_SIZE);
 char *dataptr;
 size_t nMB = 0;
 unsigned long long before, after;
 
-if (!ram) {
-fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM: 
%s\n",
-argv0, gettid(), ramsizeMB, strerror(errno));
-return -1;
-}
-if (!data) {
-fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM: 
%s\n",
-argv0, gettid(), PAGE_SIZE, strerror(errno));
-free(ram);
-return -1;
-}
-
 /* We don't care about initial state, but we do want
  * to fault it all into RAM, otherwise the first iter
  * of the loop below will be quite slow. We can't use
@@ -198,8 +186,6 @@ static int stressone(unsigned long long ramsizeMB)
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
 
 if (random_bytes(data, PAGE_SIZE) < 0) {
-free(ram);
-free(data);
 return -1;
 }
 
@@ -227,9 +213,6 @@ static int stressone(unsigned long long ramsizeMB)
 }
 }
 }
-
-free(data);
-free(ram);
 }
 
 
-- 
2.17.1






[PATCH 9/9] migration/ram: calculate un/encoded_size only when needed.

2020-06-03 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
---
 migration/ram.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index 41cc530d9d..ca20030b64 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -910,14 +910,15 @@ static void migration_update_rates(RAMState *rs, int64_t 
end_time)
 xbzrle_counters.cache_miss_rate = (double)(xbzrle_counters.cache_miss -
 rs->xbzrle_cache_miss_prev) / page_count;
 rs->xbzrle_cache_miss_prev = xbzrle_counters.cache_miss;
-unencoded_size = (xbzrle_counters.pages - rs->xbzrle_pages_prev) *
- TARGET_PAGE_SIZE;
-encoded_size = xbzrle_counters.bytes - rs->xbzrle_bytes_prev;
 if (xbzrle_counters.pages == rs->xbzrle_pages_prev) {
 xbzrle_counters.encoding_rate = 0;
-} else if (!encoded_size) {
+} else if (xbzrle_counters.bytes == rs->xbzrle_bytes_prev) {
 xbzrle_counters.encoding_rate = UINT64_MAX;
 } else {
+unencoded_size = (xbzrle_counters.pages - rs->xbzrle_pages_prev) *
+ TARGET_PAGE_SIZE;
+encoded_size = xbzrle_counters.bytes - rs->xbzrle_bytes_prev;
+
 xbzrle_counters.encoding_rate = unencoded_size / encoded_size;
 }
 rs->xbzrle_pages_prev = xbzrle_counters.pages;
-- 
2.17.1






[PATCH 0/9] monitor/hmp-cmds: small improvements for migration

2020-06-03 Thread Mao Zhongyi
patch1 ~ patch4 have been r-b, here rebase to HEAD.
patch5 ~ patch9 mainly decorate some statistics
and minor logic changes of migration, because they
all involve migration, so merged into a patchset.

Cc: dgilb...@redhat.com
Cc: quint...@redhat.com

Mao Zhongyi (9):
  tests/migration: mem leak fix
  tests/migration: fix unreachable path in stress test
  monitor/hmp-cmds: add units for migrate_parameters
  monitor/hmp-cmds: don't silently output when running
'migrate_set_downtime' fails
  monitor/hmp-cmds: delete redundant Error check before invoke
hmp_handle_error()
  monitor/hmp-cmds: add 'goto end' to reduce duplicate code.
  monitor/hmp-cmds: improvements for the 'info migrate'
  docs/xbzrle: update 'cache miss rate' and 'encoding rate' to docs
  migration/ram: calculate un/encoded_size only when needed.

 docs/xbzrle.txt  |  8 +---
 migration/ram.c  |  9 +
 monitor/hmp-cmds.c   | 30 --
 tests/migration/stress.c | 34 +++---
 4 files changed, 33 insertions(+), 48 deletions(-)

-- 
2.17.1






[PATCH 2/9] tests/migration: fix unreachable path in stress test

2020-06-03 Thread Mao Zhongyi
If stressone() or stress() exits it's because of a failure
because the test runs forever otherwise, so change stressone
and stress type to void to make the exit_failure() as the exit
function of main().

Signed-off-by: Mao Zhongyi 
Reviewed-by: Laurent Vivier 
---
 tests/migration/stress.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index f9626d50ee..a062ef6b55 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -167,7 +167,7 @@ static unsigned long long now(void)
 return (tv.tv_sec * 1000ull) + (tv.tv_usec / 1000ull);
 }
 
-static int stressone(unsigned long long ramsizeMB)
+static void stressone(unsigned long long ramsizeMB)
 {
 size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
 g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
@@ -186,7 +186,7 @@ static int stressone(unsigned long long ramsizeMB)
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
 
 if (random_bytes(data, PAGE_SIZE) < 0) {
-return -1;
+return;
 }
 
 before = now();
@@ -225,7 +225,7 @@ static void *stressthread(void *arg)
 return NULL;
 }
 
-static int stress(unsigned long long ramsizeGB, int ncpus)
+static void stress(unsigned long long ramsizeGB, int ncpus)
 {
 size_t i;
 unsigned long long ramsizeMB = ramsizeGB * 1024 / ncpus;
@@ -238,8 +238,6 @@ static int stress(unsigned long long ramsizeGB, int ncpus)
 }
 
 stressone(ramsizeMB);
-
-return 0;
 }
 
 
@@ -335,8 +333,7 @@ int main(int argc, char **argv)
 fprintf(stdout, "%s (%05d): INFO: RAM %llu GiB across %d CPUs\n",
 argv0, gettid(), ramsizeGB, ncpus);
 
-if (stress(ramsizeGB, ncpus) < 0)
-exit_failure();
+stress(ramsizeGB, ncpus);
 
-exit_success();
+exit_failure();
 }
-- 
2.17.1






[PATCH 4/9] monitor/hmp-cmds: don't silently output when running 'migrate_set_downtime' fails

2020-06-03 Thread Mao Zhongyi
Although 'migrate_set_downtime' has been deprecated and replaced
with 'migrate_set_parameter downtime_limit', it has not been
completely eliminated, possibly due to compatibility with older
versions. I think as long as this old parameter is running, we
should report appropriate message when something goes wrong, not
be silent.

before:
(qemu) migrate_set_downtime -1
(qemu)

after:
(qemu) migrate_set_downtime -1
Error: Parameter 'downtime_limit' expects an integer in the range of 0 to 2000 
seconds

Signed-off-by: Mao Zhongyi 
Reviewed-by: Dr. David Alan Gilbert 
---
 monitor/hmp-cmds.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 8c3e436b39..6938f1060e 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -1188,8 +1188,11 @@ void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
 /* Kept for backwards compatibility */
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
 {
+Error *err = NULL;
+
 double value = qdict_get_double(qdict, "value");
-qmp_migrate_set_downtime(value, NULL);
+qmp_migrate_set_downtime(value, );
+hmp_handle_error(mon, err);
 }
 
 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
-- 
2.17.1






[PATCH 6/9] monitor/hmp-cmds: add 'goto end' to reduce duplicate code.

2020-06-03 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
---
 monitor/hmp-cmds.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index acdd6baff3..e8cf72eb3a 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -1501,8 +1501,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
 read_only,
 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, );
 if (err) {
-hmp_handle_error(mon, err);
-return;
+goto end;
 }
 }
 
@@ -1511,6 +1510,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
);
 }
 
+end:
 hmp_handle_error(mon, err);
 }
 
@@ -1629,13 +1629,13 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
 
 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, );
 if (err) {
-hmp_handle_error(mon, err);
-return;
+goto end;
 }
 
 obj = user_creatable_add_opts(opts, );
 qemu_opts_del(opts);
 
+end:
 hmp_handle_error(mon, err);
 
 if (obj) {
-- 
2.17.1






[PATCH 5/9] monitor/hmp-cmds: delete redundant Error check before invoke hmp_handle_error()

2020-06-03 Thread Mao Zhongyi
hmp_handle_error() does Error check internally.

Signed-off-by: Mao Zhongyi 
---
 monitor/hmp-cmds.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 6938f1060e..acdd6baff3 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -1636,9 +1636,8 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
 obj = user_creatable_add_opts(opts, );
 qemu_opts_del(opts);
 
-if (err) {
-hmp_handle_error(mon, err);
-}
+hmp_handle_error(mon, err);
+
 if (obj) {
 object_unref(obj);
 }
-- 
2.17.1






[PATCH 7/9] monitor/hmp-cmds: improvements for the 'info migrate'

2020-06-03 Thread Mao Zhongyi
When running:

(qemu) info migrate
globals:
store-global-state: on
only-migratable: off
...
xbzrle transferred: 640892 kbytes
xbzrle pages: 16645936 pages
xbzrle cache miss: 1525426
xbzrle cache miss rate: 0.09
xbzrle encoding rate: 91.42
xbzrle overflow: 40896
...
compression pages: 377710 pages
compression busy: 0
compression busy rate: 0.00
compressed size: 463169457
compression rate: 3.33

Add units for 'xbzrle cache miss' and 'compressed size',
make it easier to read.

Suggested-by: Dr. David Alan Gilbert 
Signed-off-by: Mao Zhongyi 
---
 docs/xbzrle.txt| 2 +-
 monitor/hmp-cmds.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/xbzrle.txt b/docs/xbzrle.txt
index b431bdaf0f..385b4993f8 100644
--- a/docs/xbzrle.txt
+++ b/docs/xbzrle.txt
@@ -112,7 +112,7 @@ is recommended.
 cache size: H bytes
 xbzrle transferred: I kbytes
 xbzrle pages: J pages
-xbzrle cache miss: K
+xbzrle cache miss: K pages
 xbzrle overflow: L
 
 xbzrle cache-miss: the number of cache misses to date - high cache-miss rate
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index e8cf72eb3a..24f3e8e44d 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -299,7 +299,7 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
info->xbzrle_cache->bytes >> 10);
 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
info->xbzrle_cache->pages);
-monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
+monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n",
info->xbzrle_cache->cache_miss);
 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
info->xbzrle_cache->cache_miss_rate);
@@ -316,8 +316,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
info->compression->busy);
 monitor_printf(mon, "compression busy rate: %0.2f\n",
info->compression->busy_rate);
-monitor_printf(mon, "compressed size: %" PRIu64 "\n",
-   info->compression->compressed_size);
+monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n",
+   info->compression->compressed_size >> 10);
 monitor_printf(mon, "compression rate: %0.2f\n",
info->compression->compression_rate);
 }
-- 
2.17.1






[PATCH v2 2/3] monitor/hmp-cmds: add hmp_handle_error() for hmp_migrate_set_speed()

2020-03-31 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
Reviewed-by: Juan Quintela 
---
 monitor/hmp-cmds.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 790fad3afe..63097ddcc8 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -1203,8 +1203,11 @@ void hmp_migrate_set_cache_size(Monitor *mon, const 
QDict *qdict)
 /* Kept for backwards compatibility */
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
 {
+Error *err = NULL;
+
 int64_t value = qdict_get_int(qdict, "value");
-qmp_migrate_set_speed(value, NULL);
+qmp_migrate_set_speed(value, );
+hmp_handle_error(mon, err);
 }
 
 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
-- 
2.17.1






[PATCH v2 3/3] migration: move the units of migrate parameters from milliseconds to ms

2020-03-31 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
Reviewed-by: Juan Quintela 
---
 migration/migration.c | 2 +-
 monitor/hmp-cmds.c| 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index 5a6436d035..b3d36d1467 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1214,7 +1214,7 @@ static bool migrate_params_check(MigrationParameters 
*params, Error **errp)
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"downtime_limit",
"an integer in the range of 0 to "
-stringify(MAX_MIGRATE_DOWNTIME)" milliseconds");
+stringify(MAX_MIGRATE_DOWNTIME)" ms");
 return false;
 }
 
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 63097ddcc8..c5de8af1ee 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -231,18 +231,18 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
 monitor_printf(mon, "\n");
 }
 
-monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
+monitor_printf(mon, "total time: %" PRIu64 " ms\n",
info->total_time);
 if (info->has_expected_downtime) {
-monitor_printf(mon, "expected downtime: %" PRIu64 " 
milliseconds\n",
+monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n",
info->expected_downtime);
 }
 if (info->has_downtime) {
-monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
+monitor_printf(mon, "downtime: %" PRIu64 " ms\n",
info->downtime);
 }
 if (info->has_setup_time) {
-monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
+monitor_printf(mon, "setup: %" PRIu64 " ms\n",
info->setup_time);
 }
 }
-- 
2.17.1






[PATCH v2 1/3] migration/migration: improve error reporting for migrate parameters

2020-03-31 Thread Mao Zhongyi
use QERR_INVALID_PARAMETER_VALUE instead of
"Parameter '%s' expects" for consistency.

Signed-off-by: Mao Zhongyi 
---
 migration/migration.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index 2b7b5bccfa..5a6436d035 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1202,16 +1202,19 @@ static bool migrate_params_check(MigrationParameters 
*params, Error **errp)
 }
 
 if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
-error_setg(errp, "Parameter 'max_bandwidth' expects an integer in the"
- " range of 0 to %zu bytes/second", SIZE_MAX);
+error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+   "max_bandwidth",
+   "an integer in the range of 0 to "stringify(SIZE_MAX)
+   " bytes/second");
 return false;
 }
 
 if (params->has_downtime_limit &&
 (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
-error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
- "the range of 0 to %d milliseconds",
- MAX_MIGRATE_DOWNTIME);
+error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+   "downtime_limit",
+   "an integer in the range of 0 to "
+stringify(MAX_MIGRATE_DOWNTIME)" milliseconds");
 return false;
 }
 
@@ -2108,9 +2111,10 @@ void qmp_migrate_set_speed(int64_t value, Error **errp)
 void qmp_migrate_set_downtime(double value, Error **errp)
 {
 if (value < 0 || value > MAX_MIGRATE_DOWNTIME_SECONDS) {
-error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
- "the range of 0 to %d seconds",
- MAX_MIGRATE_DOWNTIME_SECONDS);
+error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+   "downtime_limit",
+   "an integer in the range of 0 to "
+stringify(MAX_MIGRATE_DOWNTIME_SECONDS)" seconds");
 return;
 }
 
-- 
2.17.1






[PATCH v2 0/3] Improved reporting for migrate parameters

2020-03-31 Thread Mao Zhongyi
This series mainly improve the report message of migrate parameters
to make it easier to read.

v2->v1
-p1: avoid using constants, replace it with stringify().

Cc: quint...@redhat.com
Cc: dgilb...@redhat.com

Mao Zhongyi (3):
  migration/migration: improve error reporting for migrate parameters
  monitor/hmp-cmds: add hmp_handle_error() for hmp_migrate_set_speed()
  migration: move the units of migrate parameters from milliseconds to
ms

 migration/migration.c | 20 
 monitor/hmp-cmds.c| 13 -
 2 files changed, 20 insertions(+), 13 deletions(-)

-- 
2.17.1






[PATCH 1/3] migration/migration: improve error reporting for migrate parameters

2020-03-28 Thread Mao Zhongyi
use QERR_INVALID_PARAMETER_VALUE instead of
"Parameter '%s' expects" for consistency.

Signed-off-by: Mao Zhongyi 
---
 migration/migration.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index 2b7b5bccfa..e0223f3b15 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1202,16 +1202,17 @@ static bool migrate_params_check(MigrationParameters 
*params, Error **errp)
 }
 
 if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
-error_setg(errp, "Parameter 'max_bandwidth' expects an integer in the"
- " range of 0 to %zu bytes/second", SIZE_MAX);
+error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+   "max_bandwidth",
+   "an integer in the range of 0 to '2^64 - 1' bytes/second");
 return false;
 }
 
 if (params->has_downtime_limit &&
 (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
-error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
- "the range of 0 to %d milliseconds",
- MAX_MIGRATE_DOWNTIME);
+error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+   "downtime_limit",
+   "an integer in the range of 0 to 200 milliseconds");
 return false;
 }
 
@@ -2108,9 +2109,9 @@ void qmp_migrate_set_speed(int64_t value, Error **errp)
 void qmp_migrate_set_downtime(double value, Error **errp)
 {
 if (value < 0 || value > MAX_MIGRATE_DOWNTIME_SECONDS) {
-error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
- "the range of 0 to %d seconds",
- MAX_MIGRATE_DOWNTIME_SECONDS);
+error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+   "downtime_limit",
+   "an integer in the range of 0 to 2000 seconds");
 return;
 }
 
-- 
2.17.1






[PATCH 2/3] monitor/hmp-cmds: add hmp_handle_error() for hmp_migrate_set_speed()

2020-03-28 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
---
 monitor/hmp-cmds.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 790fad3afe..63097ddcc8 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -1203,8 +1203,11 @@ void hmp_migrate_set_cache_size(Monitor *mon, const 
QDict *qdict)
 /* Kept for backwards compatibility */
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
 {
+Error *err = NULL;
+
 int64_t value = qdict_get_int(qdict, "value");
-qmp_migrate_set_speed(value, NULL);
+qmp_migrate_set_speed(value, );
+hmp_handle_error(mon, err);
 }
 
 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
-- 
2.17.1






[PATCH 0/3] Improved reporting for migrate parameters

2020-03-28 Thread Mao Zhongyi
This series mainly improve the report message of migrate parameters
to make it easier to read.

Cc: quint...@redhat.com
Cc: dgilb...@redhat.com

Mao Zhongyi (3):
  migration/migration: improve error reporting for migrate parameters
  monitor/hmp-cmds: add hmp_handle_error() for hmp_migrate_set_speed()
  migration: move the units of migrate parameters from milliseconds to
ms.

 migration/migration.c | 17 +
 monitor/hmp-cmds.c| 13 -
 2 files changed, 17 insertions(+), 13 deletions(-)

-- 
2.17.1






[PATCH 3/3] migration: move the units of migrate parameters from milliseconds to ms.

2020-03-28 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
Suggested-by: Dr. David Alan Gilbert 
---
 migration/migration.c | 2 +-
 monitor/hmp-cmds.c| 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index e0223f3b15..d014da388a 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1212,7 +1212,7 @@ static bool migrate_params_check(MigrationParameters 
*params, Error **errp)
 (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"downtime_limit",
-   "an integer in the range of 0 to 200 milliseconds");
+   "an integer in the range of 0 to 200 ms");
 return false;
 }
 
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 63097ddcc8..c5de8af1ee 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -231,18 +231,18 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
 monitor_printf(mon, "\n");
 }
 
-monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
+monitor_printf(mon, "total time: %" PRIu64 " ms\n",
info->total_time);
 if (info->has_expected_downtime) {
-monitor_printf(mon, "expected downtime: %" PRIu64 " 
milliseconds\n",
+monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n",
info->expected_downtime);
 }
 if (info->has_downtime) {
-monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
+monitor_printf(mon, "downtime: %" PRIu64 " ms\n",
info->downtime);
 }
 if (info->has_setup_time) {
-monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
+monitor_printf(mon, "setup: %" PRIu64 " ms\n",
info->setup_time);
 }
 }
-- 
2.17.1






[PATCH v2] migration: fix bad indentation in error_report()

2020-03-27 Thread Mao Zhongyi
bad indentation conflicts with CODING_STYLE doc.

Signed-off-by: Mao Zhongyi 
---
 migration/migration.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index c4c9aee15e..2b7b5bccfa 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2495,7 +2495,7 @@ retry:
 if (header_type >= MIG_RP_MSG_MAX ||
 header_type == MIG_RP_MSG_INVALID) {
 error_report("RP: Received invalid message 0x%04x length 0x%04x",
-header_type, header_len);
+ header_type, header_len);
 mark_source_rp_bad(ms);
 goto out;
 }
@@ -2504,9 +2504,9 @@ retry:
 header_len != rp_cmd_args[header_type].len) ||
 header_len > sizeof(buf)) {
 error_report("RP: Received '%s' message (0x%04x) with"
-"incorrect length %d expecting %zu",
-rp_cmd_args[header_type].name, header_type, header_len,
-(size_t)rp_cmd_args[header_type].len);
+ "incorrect length %d expecting %zu",
+ rp_cmd_args[header_type].name, header_type, 
header_len,
+ (size_t)rp_cmd_args[header_type].len);
 mark_source_rp_bad(ms);
 goto out;
 }
@@ -2561,7 +2561,7 @@ retry:
 }
 if (header_len != expected_len) {
 error_report("RP: Req_Page_id with length %d expecting %zd",
-header_len, expected_len);
+ header_len, expected_len);
 mark_source_rp_bad(ms);
 goto out;
 }
-- 
2.17.1






[PATCH v2] monitor/hmp-cmds: add units for migrate_parameters.

2020-03-27 Thread Mao Zhongyi
When running:
(qemu) info migrate_parameters
announce-initial: 50 ms
announce-max: 550 ms
announce-step: 100 ms
compress-wait-thread: on
...
max-bandwidth: 33554432 bytes/second
downtime-limit: 300 milliseconds
x-checkpoint-delay: 2
...
xbzrle-cache-size: 67108864

add units for the parameters 'x-checkpoint-delay' and
'xbzrle-cache-size', it's easier to read, also move
milliseconds to ms to keep the same style.

Signed-off-by: Mao Zhongyi 
---
 monitor/hmp-cmds.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 2a900a528a..790fad3afe 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -436,11 +436,11 @@ void hmp_info_migrate_parameters(Monitor *mon, const 
QDict *qdict)
 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
 params->max_bandwidth);
 assert(params->has_downtime_limit);
-monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
+monitor_printf(mon, "%s: %" PRIu64 " ms\n",
 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
 params->downtime_limit);
 assert(params->has_x_checkpoint_delay);
-monitor_printf(mon, "%s: %u\n",
+monitor_printf(mon, "%s: %u ms\n",
 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
 params->x_checkpoint_delay);
 assert(params->has_block_incremental);
@@ -453,7 +453,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict 
*qdict)
 monitor_printf(mon, "%s: %s\n",
 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
 MultiFDCompression_str(params->multifd_compression));
-monitor_printf(mon, "%s: %" PRIu64 "\n",
+monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
 params->xbzrle_cache_size);
 monitor_printf(mon, "%s: %" PRIu64 "\n",
-- 
2.17.1






[PATCH] migration: fix bad indentation in error_report()

2020-03-27 Thread Mao Zhongyi
bad indentation conflicts with CODING_STYLE doc.

Signed-off-by: Mao Zhongyi 
---
 migration/migration.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index c4c9aee15e..aa43137bd2 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1203,15 +1203,15 @@ static bool migrate_params_check(MigrationParameters 
*params, Error **errp)
 
 if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
 error_setg(errp, "Parameter 'max_bandwidth' expects an integer in the"
- " range of 0 to %zu bytes/second", SIZE_MAX);
+   " range of 0 to %zu bytes/second", SIZE_MAX);
 return false;
 }
 
 if (params->has_downtime_limit &&
 (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
 error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
- "the range of 0 to %d milliseconds",
- MAX_MIGRATE_DOWNTIME);
+   "the range of 0 to %d milliseconds",
+   MAX_MIGRATE_DOWNTIME);
 return false;
 }
 
@@ -2109,8 +2109,8 @@ void qmp_migrate_set_downtime(double value, Error **errp)
 {
 if (value < 0 || value > MAX_MIGRATE_DOWNTIME_SECONDS) {
 error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
- "the range of 0 to %d seconds",
- MAX_MIGRATE_DOWNTIME_SECONDS);
+   "the range of 0 to %d seconds",
+   MAX_MIGRATE_DOWNTIME_SECONDS);
 return;
 }
 
@@ -2495,7 +2495,7 @@ retry:
 if (header_type >= MIG_RP_MSG_MAX ||
 header_type == MIG_RP_MSG_INVALID) {
 error_report("RP: Received invalid message 0x%04x length 0x%04x",
-header_type, header_len);
+ header_type, header_len);
 mark_source_rp_bad(ms);
 goto out;
 }
@@ -2504,9 +2504,9 @@ retry:
 header_len != rp_cmd_args[header_type].len) ||
 header_len > sizeof(buf)) {
 error_report("RP: Received '%s' message (0x%04x) with"
-"incorrect length %d expecting %zu",
-rp_cmd_args[header_type].name, header_type, header_len,
-(size_t)rp_cmd_args[header_type].len);
+ "incorrect length %d expecting %zu",
+ rp_cmd_args[header_type].name, header_type, 
header_len,
+ (size_t)rp_cmd_args[header_type].len);
 mark_source_rp_bad(ms);
 goto out;
 }
@@ -2561,7 +2561,7 @@ retry:
 }
 if (header_len != expected_len) {
 error_report("RP: Req_Page_id with length %d expecting %zd",
-header_len, expected_len);
+ header_len, expected_len);
 mark_source_rp_bad(ms);
 goto out;
 }
-- 
2.17.1






[PATCH] monitor/hmp-cmds: add units for mirate_parameters.

2020-03-27 Thread Mao Zhongyi
When running:
(qemu) info migrate_parameters
announce-initial: 50 ms
announce-max: 550 ms
announce-step: 100 ms
compress-wait-thread: on
...
max-bandwidth: 33554432 bytes/second
downtime-limit: 300 milliseconds
x-checkpoint-delay: 2
...
xbzrle-cache-size: 67108864

add units for the parameters 'x-checkpoint-delay' and
'xbzrle-cache-size', it's easier to read.

Signed-off-by: Mao Zhongyi 
---
 monitor/hmp-cmds.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 2a900a528a..8d22f96e57 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -440,7 +440,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict 
*qdict)
 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
 params->downtime_limit);
 assert(params->has_x_checkpoint_delay);
-monitor_printf(mon, "%s: %u\n",
+monitor_printf(mon, "%s: %u" " milliseconds\n",
 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
 params->x_checkpoint_delay);
 assert(params->has_block_incremental);
@@ -453,7 +453,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict 
*qdict)
 monitor_printf(mon, "%s: %s\n",
 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
 MultiFDCompression_str(params->multifd_compression));
-monitor_printf(mon, "%s: %" PRIu64 "\n",
+monitor_printf(mon, "%s: %" PRIu64 " bytes\n",
 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
 params->xbzrle_cache_size);
 monitor_printf(mon, "%s: %" PRIu64 "\n",
-- 
2.17.1






[PATCH] monitor/hmp-cmds: don't silently output when running 'migrate_set_downtime' fails

2020-03-27 Thread Mao Zhongyi
Although 'migrate_set_downtime' has been deprecated and replaced
with 'migrate_set_parameter downtime_limit', it has not been
completely eliminated, possibly due to compatibility with older
versions. I think as long as this old parameter is running, we
should report appropriate message when something goes wrong, not
be silent.

before:
(qemu) migrate_set_downtime -1
(qemu)

after:
(qemu) migrate_set_downtime -1
Error: Parameter 'downtime_limit' expects an integer in the range of 0 to 2000 
seconds

Signed-off-by: Mao Zhongyi 
---
 monitor/hmp-cmds.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 9b94e67879..2a900a528a 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -1181,8 +1181,14 @@ void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
 /* Kept for backwards compatibility */
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
 {
+Error *err = NULL;
+
 double value = qdict_get_double(qdict, "value");
-qmp_migrate_set_downtime(value, NULL);
+qmp_migrate_set_downtime(value, );
+
+if (err) {
+hmp_handle_error(mon, err);
+}
 }
 
 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
-- 
2.17.1






[PATCH v3] migration: use "" instead of (null) for tls-authz

2020-03-24 Thread Mao Zhongyi
run:
(qemu) info migrate_parameters
announce-initial: 50 ms
...
announce-max: 550 ms
multifd-compression: none
xbzrle-cache-size: 4194304
max-postcopy-bandwidth: 0
 tls-authz: '(null)'

Migration parameter 'tls-authz' is used to provide the QOM ID
of a QAuthZ subclass instance that provides the access control
check, default is NULL. But the empty string is not a valid
object ID, so use "" instead of the default. Although it will
fail when lookup an object with ID "", it is harmless, just
consistent with tls_creds.

As a bonus, this patch also fixed the bad indentation on the
last line and removed 'has_tls_authz' redundant check in
'hmp_info_migrate_parameters'.

Signed-off-by: Mao Zhongyi 
---
 migration/migration.c | 3 ++-
 monitor/hmp-cmds.c| 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index 4b26110d57..c4c9aee15e 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -790,7 +790,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error 
**errp)
 params->has_tls_hostname = true;
 params->tls_hostname = g_strdup(s->parameters.tls_hostname);
 params->has_tls_authz = true;
-params->tls_authz = g_strdup(s->parameters.tls_authz);
+params->tls_authz = g_strdup(s->parameters.tls_authz ?
+ s->parameters.tls_authz : "");
 params->has_max_bandwidth = true;
 params->max_bandwidth = s->parameters.max_bandwidth;
 params->has_downtime_limit = true;
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index a71de0e60b..dc48e6986c 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -459,9 +459,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict 
*qdict)
 monitor_printf(mon, "%s: %" PRIu64 "\n",
 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
 params->max_postcopy_bandwidth);
-monitor_printf(mon, " %s: '%s'\n",
+monitor_printf(mon, "%s: '%s'\n",
 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-params->has_tls_authz ? params->tls_authz : "");
+params->tls_authz);
 }
 
 qapi_free_MigrationParameters(params);
-- 
2.17.1






[PATCH] monitor/hmp-cmds: remove redundant check for tls_authz in hmp_info_migrate_parameters

2020-03-21 Thread Mao Zhongyi
'params->has_tls_authz = true' has been hardcoded as true in
qmp_query_migrate_parameters, so remove the redundant check.

Signed-off-by: Mao Zhongyi 
---
 monitor/hmp-cmds.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index f8be6bbb16..d18826309b 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -461,7 +461,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict 
*qdict)
 params->max_postcopy_bandwidth);
 monitor_printf(mon, "%s: '%s'\n",
 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-params->has_tls_authz ? params->tls_authz : "");
+params->tls_authz);
 }
 
 qapi_free_MigrationParameters(params);
-- 
2.17.1






[PATCH v2] migration: use "" instead of (null) for tls-authz

2020-03-21 Thread Mao Zhongyi
run:
(qemu) info migrate_parameters
announce-initial: 50 ms
...
announce-max: 550 ms
multifd-compression: none
xbzrle-cache-size: 4194304
max-postcopy-bandwidth: 0
 tls-authz: '(null)'

Migration parameter 'tls-authz' is used to provide the QOM ID
of a QAuthZ subclass instance that provides the access control
check, default is NULL. But the empty string is not a valid
object ID, so use "" instead of the default. Although it will
fail when lookup an object with ID "", it is harmless, just
consistent with tls_creds.

Also fixed the bad indentation on the last line.

Signed-off-by: Mao Zhongyi 
---
 migration/migration.c | 3 ++-
 monitor/hmp-cmds.c| 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/migration/migration.c b/migration/migration.c
index c1d88ace7f..b060153ef7 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -790,7 +790,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error 
**errp)
 params->has_tls_hostname = true;
 params->tls_hostname = g_strdup(s->parameters.tls_hostname);
 params->has_tls_authz = true;
-params->tls_authz = g_strdup(s->parameters.tls_authz);
+params->tls_authz = s->parameters.tls_authz ? \
+g_strdup(s->parameters.tls_authz) : g_strdup("");
 params->has_max_bandwidth = true;
 params->max_bandwidth = s->parameters.max_bandwidth;
 params->has_downtime_limit = true;
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 58724031ea..f8be6bbb16 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -459,7 +459,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict 
*qdict)
 monitor_printf(mon, "%s: %" PRIu64 "\n",
 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
 params->max_postcopy_bandwidth);
-monitor_printf(mon, " %s: '%s'\n",
+monitor_printf(mon, "%s: '%s'\n",
 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
 params->has_tls_authz ? params->tls_authz : "");
 }
-- 
2.17.1






[PATCH] xbzrle: update xbzrle doc

2020-03-20 Thread Mao Zhongyi
Add new parameter description, also:
1. Remove unsociable space.
2. Nit picking: s/two/2 in report

Signed-off-by: Mao Zhongyi 
---
 docs/xbzrle.txt   | 7 ++-
 migration/migration.c | 2 +-
 monitor/hmp-cmds.c| 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/docs/xbzrle.txt b/docs/xbzrle.txt
index c0a7dfd44c..b431bdaf0f 100644
--- a/docs/xbzrle.txt
+++ b/docs/xbzrle.txt
@@ -92,6 +92,11 @@ Usage
 power of 2. The cache default value is 64MBytes. (on source only)
 {qemu} migrate_set_cache_size 256m
 
+Commit 73af8dd8d7 "migration: Make xbzrle_cache_size a migration parameter"
+(v2.11.0) deprecated migrate-set-cache-size, therefore, the new parameter
+is recommended.
+{qemu} migrate_set_parameter xbzrle-cache-size 256m
+
 4. Start outgoing migration
 {qemu} migrate -d tcp:destination.host:
 {qemu} info migrate
@@ -108,7 +113,7 @@ power of 2. The cache default value is 64MBytes. (on source 
only)
 xbzrle transferred: I kbytes
 xbzrle pages: J pages
 xbzrle cache miss: K
-xbzrle overflow : L
+xbzrle overflow: L
 
 xbzrle cache-miss: the number of cache misses to date - high cache-miss rate
 indicates that the cache size is set too low.
diff --git a/migration/migration.c b/migration/migration.c
index c1d88ace7f..4b26110d57 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1243,7 +1243,7 @@ static bool migrate_params_check(MigrationParameters 
*params, Error **errp)
 error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"xbzrle_cache_size",
"is invalid, it should be bigger than target page size"
-   " and a power of two");
+   " and a power of 2");
 return false;
 }
 
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index f8be6bbb16..dbfb121eb2 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -303,7 +303,7 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
info->xbzrle_cache->cache_miss);
 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
info->xbzrle_cache->cache_miss_rate);
-monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
+monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n",
info->xbzrle_cache->overflow);
 }
 
-- 
2.17.1






[PATCH] monitor/hmp-cmds: fix bad indentation in 'info migrate_parameters' cmd output

2020-03-20 Thread Mao Zhongyi
run:
(qemu) info migrate_parameters
announce-initial: 50 ms
...
announce-max: 550 ms
multifd-compression: none
xbzrle-cache-size: 4194304
max-postcopy-bandwidth: 0
 tls-authz: '(null)'

The last line seems a bit out of place, fix it.

Signed-off-by: Mao Zhongyi 
---
 monitor/hmp-cmds.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 58724031ea..f8be6bbb16 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -459,7 +459,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict 
*qdict)
 monitor_printf(mon, "%s: %" PRIu64 "\n",
 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
 params->max_postcopy_bandwidth);
-monitor_printf(mon, " %s: '%s'\n",
+monitor_printf(mon, "%s: '%s'\n",
 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
 params->has_tls_authz ? params->tls_authz : "");
 }
-- 
2.17.1






[PATCH 1/2] arm/smmuv3: use helper to be more easier to understand when using abstract QOM parent functions.

2019-10-12 Thread Mao Zhongyi
Philippe introduced a series of helpers to make the
device class_init() easier to understand when a
device class change the parent hooks, device smmuv3
missed helper, so convert it.

Cc: eric.au...@redhat.com
Cc: peter.mayd...@linaro.org
Cc: f4...@amsat.org
Signed-off-by: Mao Zhongyi 
---
 hw/arm/smmuv3.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index e2fbb8357e..65b6b158e5 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -1465,8 +1465,7 @@ static void smmuv3_class_init(ObjectClass *klass, void 
*data)
 
 dc->vmsd = _smmuv3;
 device_class_set_parent_reset(dc, smmu_reset, >parent_reset);
-c->parent_realize = dc->realize;
-dc->realize = smmu_realize;
+device_class_set_parent_realize(dc, smmu_realize, >parent_realize);
 }
 
 static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,
-- 
2.17.1






[PATCH 2/2] isa/pc87312: use helper to be more easier to understand when using abstract QOM parent functions.

2019-10-12 Thread Mao Zhongyi
Philippe introduced a series of helpers to make the
device class_init() easier to understand when a
device class change the parent hooks, device pc87312
missed helper, so convert it.

Cc: hpous...@reactos.org
Cc: f4...@amsat.org
Signed-off-by: Mao Zhongyi 
---
 hw/isa/pc87312.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/isa/pc87312.c b/hw/isa/pc87312.c
index b9bd57471e..13c1c43d2f 100644
--- a/hw/isa/pc87312.c
+++ b/hw/isa/pc87312.c
@@ -338,8 +338,7 @@ static void pc87312_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
 
-sc->parent_realize = dc->realize;
-dc->realize = pc87312_realize;
+device_class_set_parent_realize(dc, pc87312_realize, >parent_realize);
 dc->reset = pc87312_reset;
 dc->vmsd = _pc87312;
 dc->props = pc87312_properties;
-- 
2.17.1






[PATCH 0/2] use helper when using abstract QOM parent functions

2019-10-12 Thread Mao Zhongyi
Philippe introduced a series of helpers to make the
device class_init() easier to understand when a device
class change the parent hooks, some devices in the
source tree missed helper, so convert it.

Cc: eric.au...@redhat.com
Cc: peter.mayd...@linaro.org
Cc: hpous...@reactos.org
Cc: f4...@amsat.org

Mao Zhongyi (2):
  arm/smmuv3: use helpers to be more easier to understand when using
abstract QOM parent functions.
  isa/pc87312: use helpers to be more easier to understand when using
abstract QOM parent functions.

 hw/arm/smmuv3.c  | 3 +--
 hw/isa/pc87312.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

-- 
2.17.1






[PATCH v4 1/3] tests/migration: mem leak fix

2019-10-04 Thread Mao Zhongyi
‘data’ has the possibility of memory leaks, so use the
glib macros g_autofree recommended by CODING_STYLE.rst
to automatically release the memory that returned from
g_malloc().

Signed-off-by: Mao Zhongyi 
Reviewed-by: Alex Bennée 
---
 tests/migration/stress.c | 21 ++---
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index d9aa4afe92..d8a6f64af0 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -170,26 +170,14 @@ static unsigned long long now(void)
 static int stressone(unsigned long long ramsizeMB)
 {
 size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
-char *ram = malloc(ramsizeMB * 1024 * 1024);
+g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
 char *ramptr;
 size_t i, j, k;
-char *data = malloc(PAGE_SIZE);
+g_autofree char *data = g_malloc(PAGE_SIZE);
 char *dataptr;
 size_t nMB = 0;
 unsigned long long before, after;
 
-if (!ram) {
-fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM: 
%s\n",
-argv0, gettid(), ramsizeMB, strerror(errno));
-return -1;
-}
-if (!data) {
-fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM: 
%s\n",
-argv0, gettid(), PAGE_SIZE, strerror(errno));
-free(ram);
-return -1;
-}
-
 /* We don't care about initial state, but we do want
  * to fault it all into RAM, otherwise the first iter
  * of the loop below will be quite slow. We cna't use
@@ -198,8 +186,6 @@ static int stressone(unsigned long long ramsizeMB)
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
 
 if (random_bytes(data, PAGE_SIZE) < 0) {
-free(ram);
-free(data);
 return -1;
 }
 
@@ -227,9 +213,6 @@ static int stressone(unsigned long long ramsizeMB)
 }
 }
 }
-
-free(data);
-free(ram);
 }
 
 
-- 
2.17.1






[PATCH v4 3/3] tests/migration:fix unreachable path in stress test

2019-10-04 Thread Mao Zhongyi
If stressone() or stress() exits it's because of a failure
because the test runs forever otherwise, so change stressone
and stress type to void to make the exit_failure() as the exit
function of main().

Signed-off-by: Mao Zhongyi 
---
 tests/migration/stress.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index f9626d50ee..a062ef6b55 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -167,7 +167,7 @@ static unsigned long long now(void)
 return (tv.tv_sec * 1000ull) + (tv.tv_usec / 1000ull);
 }
 
-static int stressone(unsigned long long ramsizeMB)
+static void stressone(unsigned long long ramsizeMB)
 {
 size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
 g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
@@ -186,7 +186,7 @@ static int stressone(unsigned long long ramsizeMB)
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
 
 if (random_bytes(data, PAGE_SIZE) < 0) {
-return -1;
+return;
 }
 
 before = now();
@@ -225,7 +225,7 @@ static void *stressthread(void *arg)
 return NULL;
 }
 
-static int stress(unsigned long long ramsizeGB, int ncpus)
+static void stress(unsigned long long ramsizeGB, int ncpus)
 {
 size_t i;
 unsigned long long ramsizeMB = ramsizeGB * 1024 / ncpus;
@@ -238,8 +238,6 @@ static int stress(unsigned long long ramsizeGB, int ncpus)
 }
 
 stressone(ramsizeMB);
-
-return 0;
 }
 
 
@@ -335,8 +333,7 @@ int main(int argc, char **argv)
 fprintf(stdout, "%s (%05d): INFO: RAM %llu GiB across %d CPUs\n",
 argv0, gettid(), ramsizeGB, ncpus);
 
-if (stress(ramsizeGB, ncpus) < 0)
-exit_failure();
+stress(ramsizeGB, ncpus);
 
-exit_success();
+exit_failure();
 }
-- 
2.17.1






[PATCH v4 2/3] tests/migration: fix a typo in comment

2019-10-04 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
Reviewed-by: Alex Bennée 
Reviewed-by: Laurent Vivier 
Reviewed-by: Philippe Mathieu-Daudé 
---
 tests/migration/stress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index d8a6f64af0..f9626d50ee 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -180,7 +180,7 @@ static int stressone(unsigned long long ramsizeMB)
 
 /* We don't care about initial state, but we do want
  * to fault it all into RAM, otherwise the first iter
- * of the loop below will be quite slow. We cna't use
+ * of the loop below will be quite slow. We can't use
  * 0x0 as the byte as gcc optimizes that away into a
  * calloc instead :-) */
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
-- 
2.17.1






[PATCH v4 0/3] some fix in tests/migration

2019-10-04 Thread Mao Zhongyi
This patchset mainly fixes memory leak, typo and return
value of stress function in stress test.

v4-v3:
p1:
- remove redundant g_malloc return value judgment.
 [Laurent Vivier]
p3:
- always use exit_failure() as the exit function of main().
 [Laurent Vivier] 
- update the commit message.

v3->v2:
p1: 
- replace malloc with g_malloc   [Laurent Vivier]
p3:
- change stressone type to void and stree return value
  to -1 to make the path of 'if (stress(ramsizeGB, ncpus) < 0)'
  can be reached.[Laurent Vivier]
- update the commit message.

v2->v1:
- use g_autofree to release memory automatically instead
  of free(). [Alex Bennée]
  
Cc: arm...@redhat.com 
Cc: laur...@vivier.eu 
Cc: tony.ngu...@bt.com
Cc: alex.ben...@linaro.org

Mao Zhongyi (3):
  tests/migration: mem leak fix
  tests/migration: fix a typo in comment
  tests/migration:fix unreachable path in stress test

 tests/migration/stress.c | 36 
 1 file changed, 8 insertions(+), 28 deletions(-)

-- 
2.17.1






[PATCH v3 3/3] tests/migration:fix unreachable path in stress test

2019-10-03 Thread Mao Zhongyi
If stressone() or stress() exits it's because of a failure
because the test runs forever otherwise, so change stressone
type to void and stress should always return -1 to make the
path of 'if (stress(ramsizeGB, ncpus) < 0)' can be reached.

Signed-off-by: Mao Zhongyi 
---
 tests/migration/stress.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index debf34359f..b0df1323bb 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -167,7 +167,7 @@ static unsigned long long now(void)
 return (tv.tv_sec * 1000ull) + (tv.tv_usec / 1000ull);
 }
 
-static int stressone(unsigned long long ramsizeMB)
+static void stressone(unsigned long long ramsizeMB)
 {
 size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
 g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
@@ -181,12 +181,12 @@ static int stressone(unsigned long long ramsizeMB)
 if (!ram) {
 fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM: 
%s\n",
 argv0, gettid(), ramsizeMB, strerror(errno));
-return -1;
+return;
 }
 if (!data) {
 fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM: 
%s\n",
 argv0, gettid(), PAGE_SIZE, strerror(errno));
-return -1;
+return;
 }
 
 /* We don't care about initial state, but we do want
@@ -197,7 +197,7 @@ static int stressone(unsigned long long ramsizeMB)
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
 
 if (random_bytes(data, PAGE_SIZE) < 0) {
-return -1;
+return;
 }
 
 before = now();
@@ -250,7 +250,7 @@ static int stress(unsigned long long ramsizeGB, int ncpus)
 
 stressone(ramsizeMB);
 
-return 0;
+return -1;
 }
 
 
@@ -348,6 +348,4 @@ int main(int argc, char **argv)
 
 if (stress(ramsizeGB, ncpus) < 0)
 exit_failure();
-
-exit_success();
 }
-- 
2.17.1






[PATCH v3 2/3] tests/migration: fix a typo in comment

2019-10-03 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
Reviewed-by: Alex Bennée 
Reviewed-by: Laurent Vivier 
---
 tests/migration/stress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index 9e128eef50..debf34359f 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -191,7 +191,7 @@ static int stressone(unsigned long long ramsizeMB)
 
 /* We don't care about initial state, but we do want
  * to fault it all into RAM, otherwise the first iter
- * of the loop below will be quite slow. We cna't use
+ * of the loop below will be quite slow. We can't use
  * 0x0 as the byte as gcc optimizes that away into a
  * calloc instead :-) */
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
-- 
2.17.1






[PATCH v3 1/3] tests/migration: mem leak fix

2019-10-03 Thread Mao Zhongyi
‘data’ has the possibility of memory leaks, so use the
glib macros g_autofree recommended by CODING_STYLE.rst
to automatically release the memory that returned from
g_malloc().

Signed-off-by: Mao Zhongyi 
Reviewed-by: Alex Bennée 
---
 tests/migration/stress.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index d9aa4afe92..9e128eef50 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -170,10 +170,10 @@ static unsigned long long now(void)
 static int stressone(unsigned long long ramsizeMB)
 {
 size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
-char *ram = malloc(ramsizeMB * 1024 * 1024);
+g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
 char *ramptr;
 size_t i, j, k;
-char *data = malloc(PAGE_SIZE);
+g_autofree char *data = g_malloc(PAGE_SIZE);
 char *dataptr;
 size_t nMB = 0;
 unsigned long long before, after;
@@ -186,7 +186,6 @@ static int stressone(unsigned long long ramsizeMB)
 if (!data) {
 fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM: 
%s\n",
 argv0, gettid(), PAGE_SIZE, strerror(errno));
-free(ram);
 return -1;
 }
 
@@ -198,8 +197,6 @@ static int stressone(unsigned long long ramsizeMB)
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
 
 if (random_bytes(data, PAGE_SIZE) < 0) {
-free(ram);
-free(data);
 return -1;
 }
 
@@ -227,9 +224,6 @@ static int stressone(unsigned long long ramsizeMB)
 }
 }
 }
-
-free(data);
-free(ram);
 }
 
 
-- 
2.17.1






[PATCH v3 0/3] some fix in tests/migration

2019-10-03 Thread Mao Zhongyi
This patchset mainly fixes memory leak, typo and return
value of stress function in stress test.

v3->v2:
p1: 
- replace malloc with g_malloc   [Laurent Vivier]
p3:
- change stressone type to void and stree return value
  to -1 to make the path of 'if (stress(ramsizeGB, ncpus) < 0)'
  can be reached.[Laurent Vivier]
- update the commit message.

v2->v1:
- use g_autofree to release memory automatically instead
  of free(). [Alex Bennée]
  
Cc: arm...@redhat.com 
Cc: laur...@vivier.eu 
Cc: tony.ngu...@bt.com
Cc: alex.ben...@linaro.org

Mao Zhongyi (3):
  tests/migration: mem leak fix
  tests/migration: fix a typo in comment
  tests/migration:fix unreachable path in stress test

 tests/migration/stress.c | 24 
 1 file changed, 8 insertions(+), 16 deletions(-)

-- 
2.17.1






[Qemu-devel] [PATCH v2 3/3] tests/migration:fix unreachable path in stress test

2019-09-10 Thread Mao Zhongyi
if stress function always return 0, the path
'if (stress(ramsizeGB, ncpus) < 0)' is nerver unreachable,
so fix it to allow the test failed.

Cc: arm...@redhat.com
Cc: laur...@vivier.eu
Cc: tony.ngu...@bt.com

Signed-off-by: Mao Zhongyi 
---
 tests/migration/stress.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index 19a6eff5fd..35903d90c4 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -224,6 +224,7 @@ static int stressone(unsigned long long ramsizeMB)
 }
 }
 }
+return 0;
 }
 
 
@@ -248,9 +249,7 @@ static int stress(unsigned long long ramsizeGB, int ncpus)
stressthread,   );
 }
 
-stressone(ramsizeMB);
-
-return 0;
+return stressone(ramsizeMB);
 }
 
 
-- 
2.17.1






[Qemu-devel] [PATCH v2 0/3] some fix in tests/migration

2019-09-10 Thread Mao Zhongyi
This patchset mainly fixes memory leak, typo and return
value of stress function in stress test.

v2->v1:
- use g_autofree to release memory automatically instead
  of free(). [Alex Bennée]
  
Cc: arm...@redhat.com 
Cc: laur...@vivier.eu 
Cc: tony.ngu...@bt.com
Cc: alex.ben...@linaro.org

Mao Zhongyi (3):
  tests/migration: mem leak fix
  tests/migration: fix a typo in comment
  tests/migration:fix unreachable path in stress test

 tests/migration/stress.c | 17 +
 1 file changed, 5 insertions(+), 12 deletions(-)

-- 
2.17.1






[Qemu-devel] [PATCH v2 1/3] tests/migration: mem leak fix

2019-09-10 Thread Mao Zhongyi
‘data’ has the possibility of memory leaks, so use the
glic macros g_autofree recommended by CODING_STYLE.rst
to automatically release the memory that returned from
g_malloc().

Cc: arm...@redhat.com
Cc: laur...@vivier.eu
Cc: tony.ngu...@bt.com
Cc: alex.ben...@linaro.org

Signed-off-by: Mao Zhongyi 
---
 tests/migration/stress.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index d9aa4afe92..6cbb2d49d3 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -170,10 +170,10 @@ static unsigned long long now(void)
 static int stressone(unsigned long long ramsizeMB)
 {
 size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
-char *ram = malloc(ramsizeMB * 1024 * 1024);
+g_autofree char *ram = malloc(ramsizeMB * 1024 * 1024);
 char *ramptr;
 size_t i, j, k;
-char *data = malloc(PAGE_SIZE);
+g_autofree char *data = malloc(PAGE_SIZE);
 char *dataptr;
 size_t nMB = 0;
 unsigned long long before, after;
@@ -186,7 +186,6 @@ static int stressone(unsigned long long ramsizeMB)
 if (!data) {
 fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM: 
%s\n",
 argv0, gettid(), PAGE_SIZE, strerror(errno));
-free(ram);
 return -1;
 }
 
@@ -198,8 +197,6 @@ static int stressone(unsigned long long ramsizeMB)
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
 
 if (random_bytes(data, PAGE_SIZE) < 0) {
-free(ram);
-free(data);
 return -1;
 }
 
@@ -227,9 +224,6 @@ static int stressone(unsigned long long ramsizeMB)
 }
 }
 }
-
-free(data);
-free(ram);
 }
 
 
-- 
2.17.1






[Qemu-devel] [PATCH v2 2/3] tests/migration: fix a typo in comment

2019-09-10 Thread Mao Zhongyi
Cc: arm...@redhat.com
Cc: laur...@vivier.eu
Cc: tony.ngu...@bt.com

Signed-off-by: Mao Zhongyi 
Reviewed-by: Alex Bennée 
---
 tests/migration/stress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index 6cbb2d49d3..19a6eff5fd 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -191,7 +191,7 @@ static int stressone(unsigned long long ramsizeMB)
 
 /* We don't care about initial state, but we do want
  * to fault it all into RAM, otherwise the first iter
- * of the loop below will be quite slow. We cna't use
+ * of the loop below will be quite slow. We can't use
  * 0x0 as the byte as gcc optimizes that away into a
  * calloc instead :-) */
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
-- 
2.17.1






[Qemu-devel] [PATCH 2/3] tests/migration: fix a typo in comment

2019-09-10 Thread Mao Zhongyi
Cc: arm...@redhat.com
Cc: laur...@vivier.eu
Cc: tony.ngu...@bt.com

Signed-off-by: Mao Zhongyi 
---
 tests/migration/stress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index e6c9a6b243..4bc3a249e6 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -194,7 +194,7 @@ static int stressone(unsigned long long ramsizeMB)
 
 /* We don't care about initial state, but we do want
  * to fault it all into RAM, otherwise the first iter
- * of the loop below will be quite slow. We cna't use
+ * of the loop below will be quite slow. We can't use
  * 0x0 as the byte as gcc optimizes that away into a
  * calloc instead :-) */
 memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
-- 
2.17.1






[Qemu-devel] [PATCH 1/3] tests/migration: mem leak fix

2019-09-10 Thread Mao Zhongyi
Cc: arm...@redhat.com
Cc: laur...@vivier.eu
Cc: tony.ngu...@bt.com

Signed-off-by: Mao Zhongyi 
---
 tests/migration/stress.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index d9aa4afe92..e6c9a6b243 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -181,6 +181,8 @@ static int stressone(unsigned long long ramsizeMB)
 if (!ram) {
 fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM: 
%s\n",
 argv0, gettid(), ramsizeMB, strerror(errno));
+if (data)
+free(data);
 return -1;
 }
 if (!data) {
-- 
2.17.1






[Qemu-devel] [PATCH 0/3] some fix in tests/migration

2019-09-10 Thread Mao Zhongyi
This patchset mainly fixes memory leak, typo and return
value of stress function in stress test.

Cc: arm...@redhat.com
Cc: laur...@vivier.eu
Cc: tony.ngu...@bt.com

Mao Zhongyi (3):
  tests/migration: mem leak fix
  tests/migration: fix a typo in comment
  tests/migration:fix unreachable path in stress test

 tests/migration/stress.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

-- 
2.17.1






[Qemu-devel] [PATCH 3/3] tests/migration:fix unreachable path in stress test

2019-09-10 Thread Mao Zhongyi
if stress function always return 0, the path
'if (stress(ramsizeGB, ncpus) < 0)' is nerver unreachable,
so fix it to allow the test failed.

Cc: arm...@redhat.com
Cc: laur...@vivier.eu
Cc: tony.ngu...@bt.com

Signed-off-by: Mao Zhongyi 
---
 tests/migration/stress.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index 4bc3a249e6..36f7d71d37 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -232,6 +232,8 @@ static int stressone(unsigned long long ramsizeMB)
 
 free(data);
 free(ram);
+
+return 0;
 }
 
 
@@ -256,9 +258,7 @@ static int stress(unsigned long long ramsizeGB, int ncpus)
stressthread,   );
 }
 
-stressone(ramsizeMB);
-
-return 0;
+return stressone(ramsizeMB);
 }
 
 
-- 
2.17.1






[Qemu-devel] [PATCH] pci_bridge: fix a typo in comment

2019-09-08 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
---
 hw/pci/pci_bridge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
index 715b9a4fe6..97967d12eb 100644
--- a/hw/pci/pci_bridge.c
+++ b/hw/pci/pci_bridge.c
@@ -311,7 +311,7 @@ void pci_bridge_reset(DeviceState *qdev)
 
 /*
  * the default values for base/limit registers aren't specified
- * in the PCI-to-PCI-bridge spec. So we don't thouch them here.
+ * in the PCI-to-PCI-bridge spec. So we don't touch them here.
  * Each implementation can override it.
  * typical implementation does
  * zero base/limit registers or
-- 
2.17.1






[Qemu-devel] [PATCH] isa/pc87312: use device_class_set_parent_realize

2019-08-15 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
---
 hw/isa/pc87312.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/isa/pc87312.c b/hw/isa/pc87312.c
index 85dbc94439..e95176c148 100644
--- a/hw/isa/pc87312.c
+++ b/hw/isa/pc87312.c
@@ -336,8 +336,8 @@ static void pc87312_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
 
-sc->parent_realize = dc->realize;
-dc->realize = pc87312_realize;
+device_class_set_parent_realize(dc, pc87312_realize,
+>parent_realize);
 dc->reset = pc87312_reset;
 dc->vmsd = _pc87312;
 dc->props = pc87312_properties;
-- 
2.17.1






[Qemu-devel] [PATCH v3 21/21] core/sysbus: remove the SysBusDeviceClass::init path

2018-11-30 Thread Mao Zhongyi
Currently, all sysbus devices have been converted to realize(),
so remove this path.

Cc: ehabk...@redhat.com
Cc: th...@redhat.com
Cc: pbonz...@redhat.com
Cc: arm...@redhat.com
Cc: peter.mayd...@linaro.org
Cc: richard.hender...@linaro.org
Cc: alistair.fran...@wdc.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/core/sysbus.c| 15 +--
 include/hw/sysbus.h |  3 ---
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 7ac36ad3e7..9f9edbcab9 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -201,18 +201,13 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t 
ioport, uint32_t size)
 }
 }
 
-/* TODO remove once all sysbus devices have been converted to realize */
+/* The purpose of preserving this empty realize function
+ * is to prevent the parent_realize field of some subclasses
+ * from being set to NULL to break the normal init/realize
+ * of some devices.
+ */
 static void sysbus_realize(DeviceState *dev, Error **errp)
 {
-SysBusDevice *sd = SYS_BUS_DEVICE(dev);
-SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
-
-if (!sbc->init) {
-return;
-}
-if (sbc->init(sd) < 0) {
-error_setg(errp, "Device initialization failed");
-}
 }
 
 DeviceState *sysbus_create_varargs(const char *name,
diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
index 0b59a3b8d6..1aedcf05c9 100644
--- a/include/hw/sysbus.h
+++ b/include/hw/sysbus.h
@@ -38,9 +38,6 @@ typedef struct SysBusDevice SysBusDevice;
 typedef struct SysBusDeviceClass {
 /*< private >*/
 DeviceClass parent_class;
-/*< public >*/
-
-int (*init)(SysBusDevice *dev);
 
 /*
  * Let the sysbus device format its own non-PIO, non-MMIO unit address.
-- 
2.17.1






[Qemu-devel] [PATCH v3 20/21] xen_backend: remove xen_sysdev_init() function

2018-11-30 Thread Mao Zhongyi
The init function doesn't do anything at all, so we
just omit it.

Cc: sstabell...@kernel.org
Cc: anthony.per...@citrix.com
Cc: xen-de...@lists.xenproject.org
Cc: peter.mayd...@linaro.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Acked-by: Anthony PERARD 
---
 hw/xen/xen_backend.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index 9a8e8771ec..0bc6b1de60 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -809,11 +809,6 @@ static const TypeInfo xensysbus_info = {
 }
 };
 
-static int xen_sysdev_init(SysBusDevice *dev)
-{
-return 0;
-}
-
 static Property xen_sysdev_properties[] = {
 {/* end of property list */},
 };
@@ -821,9 +816,7 @@ static Property xen_sysdev_properties[] = {
 static void xen_sysdev_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = xen_sysdev_init;
 dc->props = xen_sysdev_properties;
 dc->bus_type = TYPE_XENSYSBUS;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v3 00/21] QOM'ify SysBusDeviceClass->init

2018-11-30 Thread Mao Zhongyi
v3 -> v2:

- rebase to the HEAD
- use SysBusDevice *sbd variable in patch15

v2 -> v1:

- SYS_BUS_DEVICE(dev) was used in a function several
  times, so use a variable 'sbd' to replace it, like:
  SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
- remove the xen_sysdev_init() function
- drop the patch21 in v1
- fix the broken in sysbus_realize of patch22

Cc: alistair.fran...@wdc.com
Cc: anthony.per...@citrix.com
Cc: arm...@redhat.com
Cc: borntrae...@de.ibm.com
Cc: chout...@adacore.com
Cc: coh...@redhat.com
Cc: da...@gibson.dropbear.id.au
Cc: da...@redhat.com
Cc: edgar.igles...@gmail.com
Cc: ehabk...@redhat.com
Cc: f4...@amsat.org
Cc: g...@mprc.pku.edu.cn
Cc: jan.kis...@web.de
Cc: kra...@redhat.com
Cc: kw...@redhat.com
Cc: marcandre.lur...@redhat.com
Cc: marcel.apfelb...@gmail.com
Cc: mich...@walle.cc
Cc: mre...@redhat.com
Cc: m...@redhat.com
Cc: pbonz...@redhat.com
Cc: peter.mayd...@linaro.org

  
Cc: qemu-...@nongnu.org
Cc: qemu-bl...@nongnu.org
Cc: qemu-...@nongnu.org
Cc: qemu-s3...@nongnu.org
Cc: richard.hender...@linaro.org
Cc: r...@twiddle.net
Cc: sstabell...@kernel.org
Cc: th...@redhat.com
Cc: xen-de...@lists.xenproject.org

Mao Zhongyi (21):
  musicpal: Convert sysbus init function to realize function
  block/noenand: Convert sysbus init function to realize function
  char/grlib_apbuart: Convert sysbus init function to realize function
  core/empty_slot: Convert sysbus init function to realize function
  display/g364fb: Convert sysbus init function to realize function
  dma/puv3_dma: Convert sysbus init function to realize function
  gpio/puv3_gpio: Convert sysbus init function to realize function
  milkymist-softusb: Convert sysbus init function to realize function
  input/pl050: Convert sysbus init function to realize function
  intc/puv3_intc: Convert sysbus init function to realize function
  milkymist-hpdmc: Convert sysbus init function to realize function
  milkymist-pfpu: Convert sysbus init function to realize function
  puv3_pm.c: Convert sysbus init function to realize function
  nvram/ds1225y: Convert sysbus init function to realize function
  pci-bridge/dec: Convert sysbus init function to realize function
  timer/etraxfs_timer: Convert sysbus init function to realize function
  timer/grlib_gptimer: Convert sysbus init function to realize function
  timer/puv3_ost: Convert sysbus init function to realize function
  usb/tusb6010: Convert sysbus init function to realize function
  xen_backend: remove xen_sysdev_init() function
  core/sysbus: remove the SysBusDeviceClass::init path

 hw/arm/musicpal.c|  9 -
 hw/block/onenand.c   | 16 +++-
 hw/char/grlib_apbuart.c  | 12 +---
 hw/core/empty_slot.c |  9 -
 hw/core/sysbus.c | 15 +--
 hw/display/g364fb.c  |  9 +++--
 hw/dma/puv3_dma.c| 10 --
 hw/gpio/puv3_gpio.c  | 29 ++---
 hw/input/milkymist-softusb.c | 16 +++-
 hw/input/pl050.c | 11 +--
 hw/intc/puv3_intc.c  | 11 ---
 hw/misc/milkymist-hpdmc.c|  9 +++--
 hw/misc/milkymist-pfpu.c | 12 +---
 hw/misc/puv3_pm.c| 10 --
 hw/nvram/ds1225y.c   | 12 +---
 hw/pci-bridge/dec.c  | 12 ++--
 hw/timer/etraxfs_timer.c | 14 +++---
 hw/timer/grlib_gptimer.c | 11 +--
 hw/timer/puv3_ost.c  | 13 ++---
 hw/usb/tusb6010.c|  8 +++-
 hw/xen/xen_backend.c |  7 ---
 include/hw/sysbus.h  |  3 ---
 22 files changed, 106 insertions(+), 152 deletions(-)

-- 
2.17.1






[Qemu-devel] [PATCH v3 18/21] timer/puv3_ost: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_ost_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/timer/puv3_ost.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/hw/timer/puv3_ost.c b/hw/timer/puv3_ost.c
index 0b3d717e60..3be58c7fdd 100644
--- a/hw/timer/puv3_ost.c
+++ b/hw/timer/puv3_ost.c
@@ -113,16 +113,17 @@ static void puv3_ost_tick(void *opaque)
 }
 }
 
-static int puv3_ost_init(SysBusDevice *dev)
+static void puv3_ost_realize(DeviceState *dev, Error **errp)
 {
 PUV3OSTState *s = PUV3_OST(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 s->reg_OIER = 0;
 s->reg_OSSR = 0;
 s->reg_OSMR0 = 0;
 s->reg_OSCR = 0;
 
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 s->bh = qemu_bh_new(puv3_ost_tick, s);
 s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT);
@@ -130,16 +131,14 @@ static int puv3_ost_init(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _ost_ops, s, "puv3_ost",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(sbd, >iomem);
 }
 
 static void puv3_ost_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_ost_init;
+dc->realize = puv3_ost_realize;
 }
 
 static const TypeInfo puv3_ost_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v3 15/21] pci-bridge/dec: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
pci_dec_21154_device_class_init().

Cc: da...@gibson.dropbear.id.au
Cc: m...@redhat.com
Cc: marcel.apfelb...@gmail.com
Cc: qemu-...@nongnu.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: David Gibson 
Acked-by: David Gibson 
---
 hw/pci-bridge/dec.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/pci-bridge/dec.c b/hw/pci-bridge/dec.c
index 84492d5e5f..8484bfd434 100644
--- a/hw/pci-bridge/dec.c
+++ b/hw/pci-bridge/dec.c
@@ -98,9 +98,10 @@ PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
 return pci_bridge_get_sec_bus(br);
 }
 
-static int pci_dec_21154_device_init(SysBusDevice *dev)
+static void pci_dec_21154_device_realize(DeviceState *dev, Error **errp)
 {
 PCIHostState *phb;
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 phb = PCI_HOST_BRIDGE(dev);
 
@@ -108,9 +109,8 @@ static int pci_dec_21154_device_init(SysBusDevice *dev)
   dev, "pci-conf-idx", 0x1000);
 memory_region_init_io(>data_mem, OBJECT(dev), _host_data_le_ops,
   dev, "pci-data-idx", 0x1000);
-sysbus_init_mmio(dev, >conf_mem);
-sysbus_init_mmio(dev, >data_mem);
-return 0;
+sysbus_init_mmio(sbd, >conf_mem);
+sysbus_init_mmio(sbd, >data_mem);
 }
 
 static void dec_21154_pci_host_realize(PCIDevice *d, Error **errp)
@@ -150,9 +150,9 @@ static const TypeInfo dec_21154_pci_host_info = {
 
 static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = pci_dec_21154_device_init;
+dc->realize = pci_dec_21154_device_realize;
 }
 
 static const TypeInfo pci_dec_21154_device_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v3 06/21] dma/puv3_dma: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_dma_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/dma/puv3_dma.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/dma/puv3_dma.c b/hw/dma/puv3_dma.c
index b97a6c1767..c89eade029 100644
--- a/hw/dma/puv3_dma.c
+++ b/hw/dma/puv3_dma.c
@@ -76,7 +76,7 @@ static const MemoryRegionOps puv3_dma_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int puv3_dma_init(SysBusDevice *dev)
+static void puv3_dma_realize(DeviceState *dev, Error **errp)
 {
 PUV3DMAState *s = PUV3_DMA(dev);
 int i;
@@ -87,16 +87,14 @@ static int puv3_dma_init(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _dma_ops, s, "puv3_dma",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 }
 
 static void puv3_dma_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_dma_init;
+dc->realize = puv3_dma_realize;
 }
 
 static const TypeInfo puv3_dma_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v3 13/21] puv3_pm.c: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_pm_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/misc/puv3_pm.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/misc/puv3_pm.c b/hw/misc/puv3_pm.c
index 577cebaac7..afe191fbe1 100644
--- a/hw/misc/puv3_pm.c
+++ b/hw/misc/puv3_pm.c
@@ -119,7 +119,7 @@ static const MemoryRegionOps puv3_pm_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int puv3_pm_init(SysBusDevice *dev)
+static void puv3_pm_realize(DeviceState *dev, Error **errp)
 {
 PUV3PMState *s = PUV3_PM(dev);
 
@@ -127,16 +127,14 @@ static int puv3_pm_init(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _pm_ops, s, "puv3_pm",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 }
 
 static void puv3_pm_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_pm_init;
+dc->realize = puv3_pm_realize;
 }
 
 static const TypeInfo puv3_pm_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v3 07/21] gpio/puv3_gpio: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_gpio_class_init().

Cc: g...@mprc.pku.edu.cn
Cc: peter.mayd...@linaro.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/gpio/puv3_gpio.c | 29 ++---
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/hw/gpio/puv3_gpio.c b/hw/gpio/puv3_gpio.c
index 445afccf9f..33241b8564 100644
--- a/hw/gpio/puv3_gpio.c
+++ b/hw/gpio/puv3_gpio.c
@@ -99,36 +99,35 @@ static const MemoryRegionOps puv3_gpio_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int puv3_gpio_init(SysBusDevice *dev)
+static void puv3_gpio_realize(DeviceState *dev, Error **errp)
 {
 PUV3GPIOState *s = PUV3_GPIO(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 s->reg_GPLR = 0;
 s->reg_GPDR = 0;
 
 /* FIXME: these irqs not handled yet */
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW0]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW1]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW2]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW3]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW4]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW5]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW6]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW7]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOHIGH]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW0]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW1]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW2]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW3]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW4]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW5]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW6]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW7]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOHIGH]);
 
 memory_region_init_io(>iomem, OBJECT(s), _gpio_ops, s, "puv3_gpio",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(sbd, >iomem);
 }
 
 static void puv3_gpio_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_gpio_init;
+dc->realize = puv3_gpio_realize;
 }
 
 static const TypeInfo puv3_gpio_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v3 19/21] usb/tusb6010: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
tusb6010_class_init().

Cc: kra...@redhat.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/usb/tusb6010.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/hw/usb/tusb6010.c b/hw/usb/tusb6010.c
index a2128024c1..501706e2b2 100644
--- a/hw/usb/tusb6010.c
+++ b/hw/usb/tusb6010.c
@@ -808,10 +808,10 @@ static void tusb6010_reset(DeviceState *dev)
 musb_reset(s->musb);
 }
 
-static int tusb6010_init(SysBusDevice *sbd)
+static void tusb6010_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
 TUSBState *s = TUSB(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 s->otg_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, tusb_otg_tick, s);
 s->pwr_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, tusb_power_tick, s);
@@ -822,15 +822,13 @@ static int tusb6010_init(SysBusDevice *sbd)
 sysbus_init_irq(sbd, >irq);
 qdev_init_gpio_in(dev, tusb6010_irq, musb_irq_max + 1);
 s->musb = musb_init(dev, 1);
-return 0;
 }
 
 static void tusb6010_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = tusb6010_init;
+dc->realize = tusb6010_realize;
 dc->reset = tusb6010_reset;
 }
 
-- 
2.17.1






[Qemu-devel] [PATCH v3 17/21] timer/grlib_gptimer: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
grlib_gptimer_class_init().

Cc: chout...@adacore.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/timer/grlib_gptimer.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/timer/grlib_gptimer.c b/hw/timer/grlib_gptimer.c
index 4ed96e970a..183eddc073 100644
--- a/hw/timer/grlib_gptimer.c
+++ b/hw/timer/grlib_gptimer.c
@@ -347,10 +347,11 @@ static void grlib_gptimer_reset(DeviceState *d)
 }
 }
 
-static int grlib_gptimer_init(SysBusDevice *dev)
+static void grlib_gptimer_realize(DeviceState *dev, Error **errp)
 {
 GPTimerUnit  *unit = GRLIB_GPTIMER(dev);
 unsigned int  i;
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 assert(unit->nr_timers > 0);
 assert(unit->nr_timers <= GPTIMER_MAX_TIMERS);
@@ -366,7 +367,7 @@ static int grlib_gptimer_init(SysBusDevice *dev)
 timer->id = i;
 
 /* One IRQ line for each timer */
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 ptimer_set_freq(timer->ptimer, unit->freq_hz);
 }
@@ -375,8 +376,7 @@ static int grlib_gptimer_init(SysBusDevice *dev)
   unit, "gptimer",
   UNIT_REG_SIZE + GPTIMER_REG_SIZE * unit->nr_timers);
 
-sysbus_init_mmio(dev, >iomem);
-return 0;
+sysbus_init_mmio(sbd, >iomem);
 }
 
 static Property grlib_gptimer_properties[] = {
@@ -389,9 +389,8 @@ static Property grlib_gptimer_properties[] = {
 static void grlib_gptimer_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = grlib_gptimer_init;
+dc->realize = grlib_gptimer_realize;
 dc->reset = grlib_gptimer_reset;
 dc->props = grlib_gptimer_properties;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v3 02/21] block/noenand: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
onenand_class_init().

Cc: kw...@redhat.com
Cc: mre...@redhat.com
Cc: qemu-bl...@nongnu.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/block/onenand.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/hw/block/onenand.c b/hw/block/onenand.c
index 2b48609776..f8a687 100644
--- a/hw/block/onenand.c
+++ b/hw/block/onenand.c
@@ -772,9 +772,9 @@ static const MemoryRegionOps onenand_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int onenand_initfn(SysBusDevice *sbd)
+static void onenand_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 OneNANDState *s = ONE_NAND(dev);
 uint32_t size = 1 << (24 + ((s->id.dev >> 4) & 7));
 void *ram;
@@ -794,14 +794,14 @@ static int onenand_initfn(SysBusDevice *sbd)
   0xff, size + (size >> 5));
 } else {
 if (blk_is_read_only(s->blk)) {
-error_report("Can't use a read-only drive");
-return -1;
+error_setg(errp, "Can't use a read-only drive");
+return;
 }
 blk_set_perm(s->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
  BLK_PERM_ALL, _err);
 if (local_err) {
-error_report_err(local_err);
-return -1;
+error_propagate(errp, local_err);
+return;
 }
 s->blk_cur = s->blk;
 }
@@ -826,7 +826,6 @@ static int onenand_initfn(SysBusDevice *sbd)
  | ((s->id.dev & 0xff) << 8)
  | (s->id.ver & 0xff),
  _onenand, s);
-return 0;
 }
 
 static Property onenand_properties[] = {
@@ -841,9 +840,8 @@ static Property onenand_properties[] = {
 static void onenand_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = onenand_initfn;
+dc->realize = onenand_realize;
 dc->reset = onenand_system_reset;
 dc->props = onenand_properties;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v3 01/21] musicpal: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
mv88w8618_wlan_class_init().

Cc: jan.kis...@web.de
Cc: peter.mayd...@linaro.org
Cc: qemu-...@nongnu.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/arm/musicpal.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index 9648b3af44..7ffcdbb097 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -1147,14 +1147,13 @@ static const MemoryRegionOps mv88w8618_wlan_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int mv88w8618_wlan_init(SysBusDevice *dev)
+static void mv88w8618_wlan_realize(DeviceState *dev, Error **errp)
 {
 MemoryRegion *iomem = g_new(MemoryRegion, 1);
 
 memory_region_init_io(iomem, OBJECT(dev), _wlan_ops, NULL,
   "musicpal-wlan", MP_WLAN_SIZE);
-sysbus_init_mmio(dev, iomem);
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), iomem);
 }
 
 /* GPIO register offsets */
@@ -1720,9 +1719,9 @@ DEFINE_MACHINE("musicpal", musicpal_machine_init)
 
 static void mv88w8618_wlan_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = mv88w8618_wlan_init;
+dc->realize = mv88w8618_wlan_realize;
 }
 
 static const TypeInfo mv88w8618_wlan_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v3 03/21] char/grlib_apbuart: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
grlib_apbuart_class_init().

Cc: chout...@adacore.com
Cc: marcandre.lur...@redhat.com
Cc: pbonz...@redhat.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/char/grlib_apbuart.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/hw/char/grlib_apbuart.c b/hw/char/grlib_apbuart.c
index bac11bec58..e1d258b611 100644
--- a/hw/char/grlib_apbuart.c
+++ b/hw/char/grlib_apbuart.c
@@ -239,9 +239,10 @@ static const MemoryRegionOps grlib_apbuart_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int grlib_apbuart_init(SysBusDevice *dev)
+static void grlib_apbuart_realize(DeviceState *dev, Error **errp)
 {
 UART *uart = GRLIB_APB_UART(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 qemu_chr_fe_set_handlers(>chr,
  grlib_apbuart_can_receive,
@@ -249,14 +250,12 @@ static int grlib_apbuart_init(SysBusDevice *dev)
  grlib_apbuart_event,
  NULL, uart, NULL, true);
 
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 memory_region_init_io(>iomem, OBJECT(uart), _apbuart_ops, uart,
   "uart", UART_REG_SIZE);
 
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(sbd, >iomem);
 }
 
 static void grlib_apbuart_reset(DeviceState *d)
@@ -280,9 +279,8 @@ static Property grlib_apbuart_properties[] = {
 static void grlib_apbuart_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = grlib_apbuart_init;
+dc->realize = grlib_apbuart_realize;
 dc->reset = grlib_apbuart_reset;
 dc->props = grlib_apbuart_properties;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v3 10/21] intc/puv3_intc: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_intc_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/intc/puv3_intc.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/hw/intc/puv3_intc.c b/hw/intc/puv3_intc.c
index ef8488aacc..69ddc8c19a 100644
--- a/hw/intc/puv3_intc.c
+++ b/hw/intc/puv3_intc.c
@@ -101,10 +101,10 @@ static const MemoryRegionOps puv3_intc_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int puv3_intc_init(SysBusDevice *sbd)
+static void puv3_intc_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
 PUV3INTCState *s = PUV3_INTC(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 qdev_init_gpio_in(dev, puv3_intc_handler, PUV3_IRQS_NR);
 sysbus_init_irq(sbd, >parent_irq);
@@ -115,15 +115,12 @@ static int puv3_intc_init(SysBusDevice *sbd)
 memory_region_init_io(>iomem, OBJECT(s), _intc_ops, s, "puv3_intc",
   PUV3_REGS_OFFSET);
 sysbus_init_mmio(sbd, >iomem);
-
-return 0;
 }
 
 static void puv3_intc_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
-
-sdc->init = puv3_intc_init;
+DeviceClass *dc = DEVICE_CLASS(klass);
+dc->realize = puv3_intc_realize;
 }
 
 static const TypeInfo puv3_intc_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v3 14/21] nvram/ds1225y: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
nvram_sysbus_class_init().

Cc: pbonz...@redhat.com
Cc: marcandre.lur...@redhat.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/nvram/ds1225y.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/hw/nvram/ds1225y.c b/hw/nvram/ds1225y.c
index ad7345f288..b6ef463db0 100644
--- a/hw/nvram/ds1225y.c
+++ b/hw/nvram/ds1225y.c
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "hw/sysbus.h"
 #include "trace.h"
+#include "qemu/error-report.h"
 
 typedef struct {
 MemoryRegion iomem;
@@ -113,7 +114,7 @@ typedef struct {
 NvRamState nvram;
 } SysBusNvRamState;
 
-static int nvram_sysbus_initfn(SysBusDevice *dev)
+static void nvram_sysbus_realize(DeviceState *dev, Error **errp)
 {
 SysBusNvRamState *sys = DS1225Y(dev);
 NvRamState *s = >nvram;
@@ -123,20 +124,18 @@ static int nvram_sysbus_initfn(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _ops, s,
   "nvram", s->chip_size);
-sysbus_init_mmio(dev, >iomem);
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 
 /* Read current file */
 file = s->filename ? fopen(s->filename, "rb") : NULL;
 if (file) {
 /* Read nvram contents */
 if (fread(s->contents, s->chip_size, 1, file) != 1) {
-printf("nvram_sysbus_initfn: short read\n");
+error_report("nvram_sysbus_realize: short read");
 }
 fclose(file);
 }
 nvram_post_load(s, 0);
-
-return 0;
 }
 
 static Property nvram_sysbus_properties[] = {
@@ -148,9 +147,8 @@ static Property nvram_sysbus_properties[] = {
 static void nvram_sysbus_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = nvram_sysbus_initfn;
+dc->realize = nvram_sysbus_realize;
 dc->vmsd = _nvram;
 dc->props = nvram_sysbus_properties;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v3 08/21] milkymist-softusb: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
milkymist_softusb_class_init().

Cc: mich...@walle.cc

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/input/milkymist-softusb.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/hw/input/milkymist-softusb.c b/hw/input/milkymist-softusb.c
index ef8f47cd83..8766a17d9e 100644
--- a/hw/input/milkymist-softusb.c
+++ b/hw/input/milkymist-softusb.c
@@ -245,32 +245,31 @@ static void milkymist_softusb_reset(DeviceState *d)
 s->regs[R_CTRL] = CTRL_RESET;
 }
 
-static int milkymist_softusb_init(SysBusDevice *dev)
+static void milkymist_softusb_realize(DeviceState *dev, Error **errp)
 {
 MilkymistSoftUsbState *s = MILKYMIST_SOFTUSB(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 memory_region_init_io(>regs_region, OBJECT(s), _mmio_ops, s,
   "milkymist-softusb", R_MAX * 4);
-sysbus_init_mmio(dev, >regs_region);
+sysbus_init_mmio(sbd, >regs_region);
 
 /* register pmem and dmem */
 memory_region_init_ram_nomigrate(>pmem, OBJECT(s), 
"milkymist-softusb.pmem",
s->pmem_size, _fatal);
 vmstate_register_ram_global(>pmem);
 s->pmem_ptr = memory_region_get_ram_ptr(>pmem);
-sysbus_init_mmio(dev, >pmem);
+sysbus_init_mmio(sbd, >pmem);
 memory_region_init_ram_nomigrate(>dmem, OBJECT(s), 
"milkymist-softusb.dmem",
s->dmem_size, _fatal);
 vmstate_register_ram_global(>dmem);
 s->dmem_ptr = memory_region_get_ram_ptr(>dmem);
-sysbus_init_mmio(dev, >dmem);
+sysbus_init_mmio(sbd, >dmem);
 
 hid_init(>hid_kbd, HID_KEYBOARD, softusb_kbd_hid_datain);
 hid_init(>hid_mouse, HID_MOUSE, softusb_mouse_hid_datain);
-
-return 0;
 }
 
 static const VMStateDescription vmstate_milkymist_softusb = {
@@ -296,9 +295,8 @@ static Property milkymist_softusb_properties[] = {
 static void milkymist_softusb_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = milkymist_softusb_init;
+dc->realize = milkymist_softusb_realize;
 dc->reset = milkymist_softusb_reset;
 dc->vmsd = _milkymist_softusb;
 dc->props = milkymist_softusb_properties;
-- 
2.17.1






[Qemu-devel] [PATCH v3 12/21] milkymist-pfpu: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
milkymist_pfpu_class_init().

Cc: mich...@walle.cc

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/misc/milkymist-pfpu.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/hw/misc/milkymist-pfpu.c b/hw/misc/milkymist-pfpu.c
index 86f5e383b0..4a03c7ee63 100644
--- a/hw/misc/milkymist-pfpu.c
+++ b/hw/misc/milkymist-pfpu.c
@@ -497,17 +497,16 @@ static void milkymist_pfpu_reset(DeviceState *d)
 }
 }
 
-static int milkymist_pfpu_init(SysBusDevice *dev)
+static void milkymist_pfpu_realize(DeviceState *dev, Error **errp)
 {
 MilkymistPFPUState *s = MILKYMIST_PFPU(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 memory_region_init_io(>regs_region, OBJECT(dev), _mmio_ops, s,
 "milkymist-pfpu", MICROCODE_END * 4);
-sysbus_init_mmio(dev, >regs_region);
-
-return 0;
+sysbus_init_mmio(sbd, >regs_region);
 }
 
 static const VMStateDescription vmstate_milkymist_pfpu = {
@@ -527,9 +526,8 @@ static const VMStateDescription vmstate_milkymist_pfpu = {
 static void milkymist_pfpu_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = milkymist_pfpu_init;
+dc->realize = milkymist_pfpu_realize;
 dc->reset = milkymist_pfpu_reset;
 dc->vmsd = _milkymist_pfpu;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v3 09/21] input/pl050: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
pl050_class_init().

Cc: peter.mayd...@linaro.org
Cc: qemu-...@nongnu.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/input/pl050.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/input/pl050.c b/hw/input/pl050.c
index be9cd57b17..15bffbfcad 100644
--- a/hw/input/pl050.c
+++ b/hw/input/pl050.c
@@ -139,19 +139,19 @@ static const MemoryRegionOps pl050_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int pl050_initfn(SysBusDevice *dev)
+static void pl050_realize(DeviceState *dev, Error **errp)
 {
 PL050State *s = PL050(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 memory_region_init_io(>iomem, OBJECT(s), _ops, s, "pl050", 
0x1000);
-sysbus_init_mmio(dev, >iomem);
-sysbus_init_irq(dev, >irq);
+sysbus_init_mmio(sbd, >iomem);
+sysbus_init_irq(sbd, >irq);
 if (s->is_mouse) {
 s->dev = ps2_mouse_init(pl050_update, s);
 } else {
 s->dev = ps2_kbd_init(pl050_update, s);
 }
-return 0;
 }
 
 static void pl050_keyboard_init(Object *obj)
@@ -183,9 +183,8 @@ static const TypeInfo pl050_mouse_info = {
 static void pl050_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(oc);
 
-sdc->init = pl050_initfn;
+dc->realize = pl050_realize;
 dc->vmsd = _pl050;
 }
 
-- 
2.17.1






[Qemu-devel] [PATCH v3 05/21] display/g364fb: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
g364fb_sysbus_class_init().

Cc: pbonz...@redhat.com
Cc: kra...@redhat.com
Cc: f4...@amsat.org
Cc: alistair.fran...@wdc.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Alistair Francis 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/display/g364fb.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c
index 8ad7e5d824..3407adf98d 100644
--- a/hw/display/g364fb.c
+++ b/hw/display/g364fb.c
@@ -489,18 +489,16 @@ typedef struct {
 G364State g364;
 } G364SysBusState;
 
-static int g364fb_sysbus_init(SysBusDevice *sbd)
+static void g364fb_sysbus_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
 G364SysBusState *sbs = G364(dev);
 G364State *s = >g364;
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 g364fb_init(dev, s);
 sysbus_init_irq(sbd, >irq);
 sysbus_init_mmio(sbd, >mem_ctrl);
 sysbus_init_mmio(sbd, >mem_vram);
-
-return 0;
 }
 
 static void g364fb_sysbus_reset(DeviceState *d)
@@ -518,9 +516,8 @@ static Property g364fb_sysbus_properties[] = {
 static void g364fb_sysbus_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = g364fb_sysbus_init;
+dc->realize = g364fb_sysbus_realize;
 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
 dc->desc = "G364 framebuffer";
 dc->reset = g364fb_sysbus_reset;
-- 
2.17.1






[Qemu-devel] [PATCH v3 11/21] milkymist-hpdmc: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
milkymist_hpdmc_class_init().

Cc: g...@mprc.pku.edu.cn
Cc: mich...@walle.cc

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/misc/milkymist-hpdmc.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/misc/milkymist-hpdmc.c b/hw/misc/milkymist-hpdmc.c
index e6140eec6b..44dc0698ec 100644
--- a/hw/misc/milkymist-hpdmc.c
+++ b/hw/misc/milkymist-hpdmc.c
@@ -129,15 +129,13 @@ static void milkymist_hpdmc_reset(DeviceState *d)
  | IODELAY_PLL2_LOCKED;
 }
 
-static int milkymist_hpdmc_init(SysBusDevice *dev)
+static void milkymist_hpdmc_realize(DeviceState *dev, Error **errp)
 {
 MilkymistHpdmcState *s = MILKYMIST_HPDMC(dev);
 
 memory_region_init_io(>regs_region, OBJECT(dev), _mmio_ops, s,
 "milkymist-hpdmc", R_MAX * 4);
-sysbus_init_mmio(dev, >regs_region);
-
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >regs_region);
 }
 
 static const VMStateDescription vmstate_milkymist_hpdmc = {
@@ -153,9 +151,8 @@ static const VMStateDescription vmstate_milkymist_hpdmc = {
 static void milkymist_hpdmc_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = milkymist_hpdmc_init;
+dc->realize = milkymist_hpdmc_realize;
 dc->reset = milkymist_hpdmc_reset;
 dc->vmsd = _milkymist_hpdmc;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v3 16/21] timer/etraxfs_timer: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
etraxfs_timer_class_init().

Cc: edgar.igles...@gmail.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Edgar E. Iglesias 
---
 hw/timer/etraxfs_timer.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/timer/etraxfs_timer.c b/hw/timer/etraxfs_timer.c
index d13bc30b2d..2280914b1d 100644
--- a/hw/timer/etraxfs_timer.c
+++ b/hw/timer/etraxfs_timer.c
@@ -315,9 +315,10 @@ static void etraxfs_timer_reset(void *opaque)
 qemu_irq_lower(t->irq);
 }
 
-static int etraxfs_timer_init(SysBusDevice *dev)
+static void etraxfs_timer_realize(DeviceState *dev, Error **errp)
 {
 ETRAXTimerState *t = ETRAX_TIMER(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 t->bh_t0 = qemu_bh_new(timer0_hit, t);
 t->bh_t1 = qemu_bh_new(timer1_hit, t);
@@ -326,21 +327,20 @@ static int etraxfs_timer_init(SysBusDevice *dev)
 t->ptimer_t1 = ptimer_init(t->bh_t1, PTIMER_POLICY_DEFAULT);
 t->ptimer_wd = ptimer_init(t->bh_wd, PTIMER_POLICY_DEFAULT);
 
-sysbus_init_irq(dev, >irq);
-sysbus_init_irq(dev, >nmi);
+sysbus_init_irq(sbd, >irq);
+sysbus_init_irq(sbd, >nmi);
 
 memory_region_init_io(>mmio, OBJECT(t), _ops, t,
   "etraxfs-timer", 0x5c);
-sysbus_init_mmio(dev, >mmio);
+sysbus_init_mmio(sbd, >mmio);
 qemu_register_reset(etraxfs_timer_reset, t);
-return 0;
 }
 
 static void etraxfs_timer_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = etraxfs_timer_init;
+dc->realize = etraxfs_timer_realize;
 }
 
 static const TypeInfo etraxfs_timer_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v3 04/21] core/empty_slot: Convert sysbus init function to realize function

2018-11-30 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
empty_slot_class_init().

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/core/empty_slot.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/core/empty_slot.c b/hw/core/empty_slot.c
index c1b9c2b104..239f78e2a7 100644
--- a/hw/core/empty_slot.c
+++ b/hw/core/empty_slot.c
@@ -71,21 +71,20 @@ void empty_slot_init(hwaddr addr, uint64_t slot_size)
 }
 }
 
-static int empty_slot_init1(SysBusDevice *dev)
+static void empty_slot_realize(DeviceState *dev, Error **errp)
 {
 EmptySlot *s = EMPTY_SLOT(dev);
 
 memory_region_init_io(>iomem, OBJECT(s), _slot_ops, s,
   "empty-slot", s->size);
-sysbus_init_mmio(dev, >iomem);
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 }
 
 static void empty_slot_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-k->init = empty_slot_init1;
+dc->realize = empty_slot_realize;
 }
 
 static const TypeInfo empty_slot_info = {
-- 
2.17.1






[Qemu-devel] [PATCH] riscv/cpu: use device_class_set_parent_realize

2018-11-25 Thread Mao Zhongyi
Signed-off-by: Mao Zhongyi 
---
 target/riscv/cpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index a025a0a3ba..5e8a2cb2ba 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -330,8 +330,8 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
 CPUClass *cc = CPU_CLASS(c);
 DeviceClass *dc = DEVICE_CLASS(c);
 
-mcc->parent_realize = dc->realize;
-dc->realize = riscv_cpu_realize;
+device_class_set_parent_realize(dc, riscv_cpu_realize,
+>parent_realize);
 
 mcc->parent_reset = cc->reset;
 cc->reset = riscv_cpu_reset;
-- 
2.17.1






[Qemu-devel] [PATCH v2 21/21] core/sysbus: remove the SysBusDeviceClass::init path

2018-11-23 Thread Mao Zhongyi
Currently, all sysbus devices have been converted to realize(),
so remove this path.

Cc: ehabk...@redhat.com
Cc: th...@redhat.com
Cc: pbonz...@redhat.com
Cc: arm...@redhat.com
Cc: peter.mayd...@linaro.org
Cc: richard.hender...@linaro.org
Cc: alistair.fran...@wdc.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/core/sysbus.c| 15 +--
 include/hw/sysbus.h |  3 ---
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 7ac36ad3e7..9f9edbcab9 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -201,18 +201,13 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t 
ioport, uint32_t size)
 }
 }
 
-/* TODO remove once all sysbus devices have been converted to realize */
+/* The purpose of preserving this empty realize function
+ * is to prevent the parent_realize field of some subclasses
+ * from being set to NULL to break the normal init/realize
+ * of some devices.
+ */
 static void sysbus_realize(DeviceState *dev, Error **errp)
 {
-SysBusDevice *sd = SYS_BUS_DEVICE(dev);
-SysBusDeviceClass *sbc = SYS_BUS_DEVICE_GET_CLASS(sd);
-
-if (!sbc->init) {
-return;
-}
-if (sbc->init(sd) < 0) {
-error_setg(errp, "Device initialization failed");
-}
 }
 
 DeviceState *sysbus_create_varargs(const char *name,
diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
index 0b59a3b8d6..1aedcf05c9 100644
--- a/include/hw/sysbus.h
+++ b/include/hw/sysbus.h
@@ -38,9 +38,6 @@ typedef struct SysBusDevice SysBusDevice;
 typedef struct SysBusDeviceClass {
 /*< private >*/
 DeviceClass parent_class;
-/*< public >*/
-
-int (*init)(SysBusDevice *dev);
 
 /*
  * Let the sysbus device format its own non-PIO, non-MMIO unit address.
-- 
2.17.1






[Qemu-devel] [PATCH v2 18/21] timer/puv3_ost: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_ost_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/timer/puv3_ost.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/hw/timer/puv3_ost.c b/hw/timer/puv3_ost.c
index 0b3d717e60..3be58c7fdd 100644
--- a/hw/timer/puv3_ost.c
+++ b/hw/timer/puv3_ost.c
@@ -113,16 +113,17 @@ static void puv3_ost_tick(void *opaque)
 }
 }
 
-static int puv3_ost_init(SysBusDevice *dev)
+static void puv3_ost_realize(DeviceState *dev, Error **errp)
 {
 PUV3OSTState *s = PUV3_OST(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 s->reg_OIER = 0;
 s->reg_OSSR = 0;
 s->reg_OSMR0 = 0;
 s->reg_OSCR = 0;
 
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 s->bh = qemu_bh_new(puv3_ost_tick, s);
 s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT);
@@ -130,16 +131,14 @@ static int puv3_ost_init(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _ost_ops, s, "puv3_ost",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(sbd, >iomem);
 }
 
 static void puv3_ost_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_ost_init;
+dc->realize = puv3_ost_realize;
 }
 
 static const TypeInfo puv3_ost_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v2 20/21] xen_backend: remove xen_sysdev_init() function

2018-11-23 Thread Mao Zhongyi
The init function doesn't do anything at all, so we
just omit it.

Cc: sstabell...@kernel.org
Cc: anthony.per...@citrix.com
Cc: xen-de...@lists.xenproject.org
Cc: peter.mayd...@linaro.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/xen/xen_backend.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index 9a8e8771ec..0bc6b1de60 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -809,11 +809,6 @@ static const TypeInfo xensysbus_info = {
 }
 };
 
-static int xen_sysdev_init(SysBusDevice *dev)
-{
-return 0;
-}
-
 static Property xen_sysdev_properties[] = {
 {/* end of property list */},
 };
@@ -821,9 +816,7 @@ static Property xen_sysdev_properties[] = {
 static void xen_sysdev_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = xen_sysdev_init;
 dc->props = xen_sysdev_properties;
 dc->bus_type = TYPE_XENSYSBUS;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v2 15/21] pci-bridge/dec: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
pci_dec_21154_device_class_init().

Cc: da...@gibson.dropbear.id.au
Cc: m...@redhat.com
Cc: marcel.apfelb...@gmail.com
Cc: qemu-...@nongnu.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: David Gibson 
Acked-by: David Gibson 
---
 hw/pci-bridge/dec.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/pci-bridge/dec.c b/hw/pci-bridge/dec.c
index 84492d5e5f..5b21c20e50 100644
--- a/hw/pci-bridge/dec.c
+++ b/hw/pci-bridge/dec.c
@@ -98,7 +98,7 @@ PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
 return pci_bridge_get_sec_bus(br);
 }
 
-static int pci_dec_21154_device_init(SysBusDevice *dev)
+static void pci_dec_21154_device_realize(DeviceState *dev, Error **errp)
 {
 PCIHostState *phb;
 
@@ -108,9 +108,8 @@ static int pci_dec_21154_device_init(SysBusDevice *dev)
   dev, "pci-conf-idx", 0x1000);
 memory_region_init_io(>data_mem, OBJECT(dev), _host_data_le_ops,
   dev, "pci-data-idx", 0x1000);
-sysbus_init_mmio(dev, >conf_mem);
-sysbus_init_mmio(dev, >data_mem);
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >conf_mem);
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >data_mem);
 }
 
 static void dec_21154_pci_host_realize(PCIDevice *d, Error **errp)
@@ -150,9 +149,9 @@ static const TypeInfo dec_21154_pci_host_info = {
 
 static void pci_dec_21154_device_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = pci_dec_21154_device_init;
+dc->realize = pci_dec_21154_device_realize;
 }
 
 static const TypeInfo pci_dec_21154_device_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v2 16/21] timer/etraxfs_timer: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
etraxfs_timer_class_init().

Cc: edgar.igles...@gmail.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/timer/etraxfs_timer.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/timer/etraxfs_timer.c b/hw/timer/etraxfs_timer.c
index d13bc30b2d..2280914b1d 100644
--- a/hw/timer/etraxfs_timer.c
+++ b/hw/timer/etraxfs_timer.c
@@ -315,9 +315,10 @@ static void etraxfs_timer_reset(void *opaque)
 qemu_irq_lower(t->irq);
 }
 
-static int etraxfs_timer_init(SysBusDevice *dev)
+static void etraxfs_timer_realize(DeviceState *dev, Error **errp)
 {
 ETRAXTimerState *t = ETRAX_TIMER(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 t->bh_t0 = qemu_bh_new(timer0_hit, t);
 t->bh_t1 = qemu_bh_new(timer1_hit, t);
@@ -326,21 +327,20 @@ static int etraxfs_timer_init(SysBusDevice *dev)
 t->ptimer_t1 = ptimer_init(t->bh_t1, PTIMER_POLICY_DEFAULT);
 t->ptimer_wd = ptimer_init(t->bh_wd, PTIMER_POLICY_DEFAULT);
 
-sysbus_init_irq(dev, >irq);
-sysbus_init_irq(dev, >nmi);
+sysbus_init_irq(sbd, >irq);
+sysbus_init_irq(sbd, >nmi);
 
 memory_region_init_io(>mmio, OBJECT(t), _ops, t,
   "etraxfs-timer", 0x5c);
-sysbus_init_mmio(dev, >mmio);
+sysbus_init_mmio(sbd, >mmio);
 qemu_register_reset(etraxfs_timer_reset, t);
-return 0;
 }
 
 static void etraxfs_timer_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = etraxfs_timer_init;
+dc->realize = etraxfs_timer_realize;
 }
 
 static const TypeInfo etraxfs_timer_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v2 02/21] block/noenand: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
onenand_class_init().

Cc: kw...@redhat.com
Cc: mre...@redhat.com
Cc: qemu-bl...@nongnu.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/block/onenand.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/hw/block/onenand.c b/hw/block/onenand.c
index 2b48609776..f8a687 100644
--- a/hw/block/onenand.c
+++ b/hw/block/onenand.c
@@ -772,9 +772,9 @@ static const MemoryRegionOps onenand_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int onenand_initfn(SysBusDevice *sbd)
+static void onenand_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 OneNANDState *s = ONE_NAND(dev);
 uint32_t size = 1 << (24 + ((s->id.dev >> 4) & 7));
 void *ram;
@@ -794,14 +794,14 @@ static int onenand_initfn(SysBusDevice *sbd)
   0xff, size + (size >> 5));
 } else {
 if (blk_is_read_only(s->blk)) {
-error_report("Can't use a read-only drive");
-return -1;
+error_setg(errp, "Can't use a read-only drive");
+return;
 }
 blk_set_perm(s->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
  BLK_PERM_ALL, _err);
 if (local_err) {
-error_report_err(local_err);
-return -1;
+error_propagate(errp, local_err);
+return;
 }
 s->blk_cur = s->blk;
 }
@@ -826,7 +826,6 @@ static int onenand_initfn(SysBusDevice *sbd)
  | ((s->id.dev & 0xff) << 8)
  | (s->id.ver & 0xff),
  _onenand, s);
-return 0;
 }
 
 static Property onenand_properties[] = {
@@ -841,9 +840,8 @@ static Property onenand_properties[] = {
 static void onenand_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = onenand_initfn;
+dc->realize = onenand_realize;
 dc->reset = onenand_system_reset;
 dc->props = onenand_properties;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v2 10/21] intc/puv3_intc: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_intc_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/intc/puv3_intc.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/hw/intc/puv3_intc.c b/hw/intc/puv3_intc.c
index ef8488aacc..69ddc8c19a 100644
--- a/hw/intc/puv3_intc.c
+++ b/hw/intc/puv3_intc.c
@@ -101,10 +101,10 @@ static const MemoryRegionOps puv3_intc_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int puv3_intc_init(SysBusDevice *sbd)
+static void puv3_intc_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
 PUV3INTCState *s = PUV3_INTC(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 qdev_init_gpio_in(dev, puv3_intc_handler, PUV3_IRQS_NR);
 sysbus_init_irq(sbd, >parent_irq);
@@ -115,15 +115,12 @@ static int puv3_intc_init(SysBusDevice *sbd)
 memory_region_init_io(>iomem, OBJECT(s), _intc_ops, s, "puv3_intc",
   PUV3_REGS_OFFSET);
 sysbus_init_mmio(sbd, >iomem);
-
-return 0;
 }
 
 static void puv3_intc_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
-
-sdc->init = puv3_intc_init;
+DeviceClass *dc = DEVICE_CLASS(klass);
+dc->realize = puv3_intc_realize;
 }
 
 static const TypeInfo puv3_intc_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v2 05/21] display/g364fb: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
g364fb_sysbus_class_init().

Cc: pbonz...@redhat.com
Cc: kra...@redhat.com
Cc: f4...@amsat.org
Cc: alistair.fran...@wdc.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Alistair Francis 
---
 hw/display/g364fb.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c
index 8ad7e5d824..3407adf98d 100644
--- a/hw/display/g364fb.c
+++ b/hw/display/g364fb.c
@@ -489,18 +489,16 @@ typedef struct {
 G364State g364;
 } G364SysBusState;
 
-static int g364fb_sysbus_init(SysBusDevice *sbd)
+static void g364fb_sysbus_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
 G364SysBusState *sbs = G364(dev);
 G364State *s = >g364;
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 g364fb_init(dev, s);
 sysbus_init_irq(sbd, >irq);
 sysbus_init_mmio(sbd, >mem_ctrl);
 sysbus_init_mmio(sbd, >mem_vram);
-
-return 0;
 }
 
 static void g364fb_sysbus_reset(DeviceState *d)
@@ -518,9 +516,8 @@ static Property g364fb_sysbus_properties[] = {
 static void g364fb_sysbus_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = g364fb_sysbus_init;
+dc->realize = g364fb_sysbus_realize;
 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
 dc->desc = "G364 framebuffer";
 dc->reset = g364fb_sysbus_reset;
-- 
2.17.1






[Qemu-devel] [PATCH v2 00/21] QOM'ify SysBusDeviceClass->init

2018-11-23 Thread Mao Zhongyi
The SysBusDeviceClass::init() interface is considered
as a legacy interface and there are currently some
efforts going on to get rid of it. Thus convert 
SysBusDeviceClass::init to DeviceClass::realize.

v2 -> v1:

- SYS_BUS_DEVICE(dev) was used in a function several
  times, so use a variable 'sbd' to replace it, like:
  SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
- remove the xen_sysdev_init() function
- drop the patch21 in v1
- fix the broken in sysbus_realize of patch22


Cc: alistair.fran...@wdc.com
Cc: anthony.per...@citrix.com
Cc: arm...@redhat.com
Cc: borntrae...@de.ibm.com
Cc: chout...@adacore.com
Cc: coh...@redhat.com
Cc: da...@gibson.dropbear.id.au
Cc: da...@redhat.com
Cc: edgar.igles...@gmail.com
Cc: ehabk...@redhat.com
Cc: f4...@amsat.org
Cc: g...@mprc.pku.edu.cn
Cc: jan.kis...@web.de
Cc: kra...@redhat.com
Cc: kw...@redhat.com
Cc: marcandre.lur...@redhat.com
Cc: marcel.apfelb...@gmail.com
Cc: mich...@walle.cc
Cc: mre...@redhat.com
Cc: m...@redhat.com
Cc: pbonz...@redhat.com
Cc: peter.mayd...@linaro.org
Cc: peter.mayd...@linaro.org

  
Cc: qemu-...@nongnu.org
Cc: qemu-bl...@nongnu.org
Cc: qemu-...@nongnu.org
Cc: qemu-s3...@nongnu.org
Cc: richard.hender...@linaro.org
Cc: r...@twiddle.net
Cc: sstabell...@kernel.org
Cc: th...@redhat.com
Cc: xen-de...@lists.xenproject.org

Mao Zhongyi (21):
  musicpal: Convert sysbus init function to realize function
  block/noenand: Convert sysbus init function to realize function
  char/grlib_apbuart: Convert sysbus init function to realize function
  core/empty_slot: Convert sysbus init function to realize function
  display/g364fb: Convert sysbus init function to realize function
  dma/puv3_dma: Convert sysbus init function to realize function
  gpio/puv3_gpio: Convert sysbus init function to realize function
  milkymist-softusb: Convert sysbus init function to realize function
  input/pl050: Convert sysbus init function to realize function
  intc/puv3_intc: Convert sysbus init function to realize function
  milkymist-hpdmc: Convert sysbus init function to realize function
  milkymist-pfpu: Convert sysbus init function to realize function
  puv3_pm.c: Convert sysbus init function to realize function
  nvram/ds1225y: Convert sysbus init function to realize function
  pci-bridge/dec: Convert sysbus init function to realize function
  timer/etraxfs_timer: Convert sysbus init function to realize function
  timer/grlib_gptimer: Convert sysbus init function to realize function
  timer/puv3_ost: Convert sysbus init function to realize function
  usb/tusb6010: Convert sysbus init function to realize function
  xen_backend: remove xen_sysdev_init() function
  core/sysbus: remove the SysBusDeviceClass::init path

 hw/arm/musicpal.c|  9 -
 hw/block/onenand.c   | 16 +++-
 hw/char/grlib_apbuart.c  | 12 +---
 hw/core/empty_slot.c |  9 -
 hw/core/sysbus.c | 15 +--
 hw/display/g364fb.c  |  9 +++--
 hw/dma/puv3_dma.c| 10 --
 hw/gpio/puv3_gpio.c  | 29 ++---
 hw/input/milkymist-softusb.c | 16 +++-
 hw/input/pl050.c | 11 +--
 hw/intc/puv3_intc.c  | 11 ---
 hw/misc/milkymist-hpdmc.c|  9 +++--
 hw/misc/milkymist-pfpu.c | 12 +---
 hw/misc/puv3_pm.c| 10 --
 hw/nvram/ds1225y.c   | 12 +---
 hw/pci-bridge/dec.c  | 11 +--
 hw/timer/etraxfs_timer.c | 14 +++---
 hw/timer/grlib_gptimer.c | 11 +--
 hw/timer/puv3_ost.c  | 13 ++---
 hw/usb/tusb6010.c|  8 +++-
 hw/xen/xen_backend.c |  7 ---
 include/hw/sysbus.h  |  3 ---
 22 files changed, 105 insertions(+), 152 deletions(-)

-- 
2.17.1






[Qemu-devel] [PATCH v2 13/21] puv3_pm.c: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_pm_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/misc/puv3_pm.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/misc/puv3_pm.c b/hw/misc/puv3_pm.c
index 577cebaac7..afe191fbe1 100644
--- a/hw/misc/puv3_pm.c
+++ b/hw/misc/puv3_pm.c
@@ -119,7 +119,7 @@ static const MemoryRegionOps puv3_pm_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int puv3_pm_init(SysBusDevice *dev)
+static void puv3_pm_realize(DeviceState *dev, Error **errp)
 {
 PUV3PMState *s = PUV3_PM(dev);
 
@@ -127,16 +127,14 @@ static int puv3_pm_init(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _pm_ops, s, "puv3_pm",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 }
 
 static void puv3_pm_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_pm_init;
+dc->realize = puv3_pm_realize;
 }
 
 static const TypeInfo puv3_pm_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v2 14/21] nvram/ds1225y: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
nvram_sysbus_class_init().

Cc: pbonz...@redhat.com
Cc: marcandre.lur...@redhat.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/nvram/ds1225y.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/hw/nvram/ds1225y.c b/hw/nvram/ds1225y.c
index ad7345f288..b6ef463db0 100644
--- a/hw/nvram/ds1225y.c
+++ b/hw/nvram/ds1225y.c
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "hw/sysbus.h"
 #include "trace.h"
+#include "qemu/error-report.h"
 
 typedef struct {
 MemoryRegion iomem;
@@ -113,7 +114,7 @@ typedef struct {
 NvRamState nvram;
 } SysBusNvRamState;
 
-static int nvram_sysbus_initfn(SysBusDevice *dev)
+static void nvram_sysbus_realize(DeviceState *dev, Error **errp)
 {
 SysBusNvRamState *sys = DS1225Y(dev);
 NvRamState *s = >nvram;
@@ -123,20 +124,18 @@ static int nvram_sysbus_initfn(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _ops, s,
   "nvram", s->chip_size);
-sysbus_init_mmio(dev, >iomem);
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 
 /* Read current file */
 file = s->filename ? fopen(s->filename, "rb") : NULL;
 if (file) {
 /* Read nvram contents */
 if (fread(s->contents, s->chip_size, 1, file) != 1) {
-printf("nvram_sysbus_initfn: short read\n");
+error_report("nvram_sysbus_realize: short read");
 }
 fclose(file);
 }
 nvram_post_load(s, 0);
-
-return 0;
 }
 
 static Property nvram_sysbus_properties[] = {
@@ -148,9 +147,8 @@ static Property nvram_sysbus_properties[] = {
 static void nvram_sysbus_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = nvram_sysbus_initfn;
+dc->realize = nvram_sysbus_realize;
 dc->vmsd = _nvram;
 dc->props = nvram_sysbus_properties;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v2 17/21] timer/grlib_gptimer: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
grlib_gptimer_class_init().

Cc: chout...@adacore.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/timer/grlib_gptimer.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/timer/grlib_gptimer.c b/hw/timer/grlib_gptimer.c
index 4ed96e970a..183eddc073 100644
--- a/hw/timer/grlib_gptimer.c
+++ b/hw/timer/grlib_gptimer.c
@@ -347,10 +347,11 @@ static void grlib_gptimer_reset(DeviceState *d)
 }
 }
 
-static int grlib_gptimer_init(SysBusDevice *dev)
+static void grlib_gptimer_realize(DeviceState *dev, Error **errp)
 {
 GPTimerUnit  *unit = GRLIB_GPTIMER(dev);
 unsigned int  i;
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 assert(unit->nr_timers > 0);
 assert(unit->nr_timers <= GPTIMER_MAX_TIMERS);
@@ -366,7 +367,7 @@ static int grlib_gptimer_init(SysBusDevice *dev)
 timer->id = i;
 
 /* One IRQ line for each timer */
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 ptimer_set_freq(timer->ptimer, unit->freq_hz);
 }
@@ -375,8 +376,7 @@ static int grlib_gptimer_init(SysBusDevice *dev)
   unit, "gptimer",
   UNIT_REG_SIZE + GPTIMER_REG_SIZE * unit->nr_timers);
 
-sysbus_init_mmio(dev, >iomem);
-return 0;
+sysbus_init_mmio(sbd, >iomem);
 }
 
 static Property grlib_gptimer_properties[] = {
@@ -389,9 +389,8 @@ static Property grlib_gptimer_properties[] = {
 static void grlib_gptimer_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = grlib_gptimer_init;
+dc->realize = grlib_gptimer_realize;
 dc->reset = grlib_gptimer_reset;
 dc->props = grlib_gptimer_properties;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v2 11/21] milkymist-hpdmc: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
milkymist_hpdmc_class_init().

Cc: g...@mprc.pku.edu.cn
Cc: mich...@walle.cc

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/misc/milkymist-hpdmc.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/misc/milkymist-hpdmc.c b/hw/misc/milkymist-hpdmc.c
index e6140eec6b..44dc0698ec 100644
--- a/hw/misc/milkymist-hpdmc.c
+++ b/hw/misc/milkymist-hpdmc.c
@@ -129,15 +129,13 @@ static void milkymist_hpdmc_reset(DeviceState *d)
  | IODELAY_PLL2_LOCKED;
 }
 
-static int milkymist_hpdmc_init(SysBusDevice *dev)
+static void milkymist_hpdmc_realize(DeviceState *dev, Error **errp)
 {
 MilkymistHpdmcState *s = MILKYMIST_HPDMC(dev);
 
 memory_region_init_io(>regs_region, OBJECT(dev), _mmio_ops, s,
 "milkymist-hpdmc", R_MAX * 4);
-sysbus_init_mmio(dev, >regs_region);
-
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >regs_region);
 }
 
 static const VMStateDescription vmstate_milkymist_hpdmc = {
@@ -153,9 +151,8 @@ static const VMStateDescription vmstate_milkymist_hpdmc = {
 static void milkymist_hpdmc_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = milkymist_hpdmc_init;
+dc->realize = milkymist_hpdmc_realize;
 dc->reset = milkymist_hpdmc_reset;
 dc->vmsd = _milkymist_hpdmc;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v2 19/21] usb/tusb6010: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
tusb6010_class_init().

Cc: kra...@redhat.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/usb/tusb6010.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/hw/usb/tusb6010.c b/hw/usb/tusb6010.c
index a2128024c1..501706e2b2 100644
--- a/hw/usb/tusb6010.c
+++ b/hw/usb/tusb6010.c
@@ -808,10 +808,10 @@ static void tusb6010_reset(DeviceState *dev)
 musb_reset(s->musb);
 }
 
-static int tusb6010_init(SysBusDevice *sbd)
+static void tusb6010_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
 TUSBState *s = TUSB(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 s->otg_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, tusb_otg_tick, s);
 s->pwr_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, tusb_power_tick, s);
@@ -822,15 +822,13 @@ static int tusb6010_init(SysBusDevice *sbd)
 sysbus_init_irq(sbd, >irq);
 qdev_init_gpio_in(dev, tusb6010_irq, musb_irq_max + 1);
 s->musb = musb_init(dev, 1);
-return 0;
 }
 
 static void tusb6010_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = tusb6010_init;
+dc->realize = tusb6010_realize;
 dc->reset = tusb6010_reset;
 }
 
-- 
2.17.1






[Qemu-devel] [PATCH v2 06/21] dma/puv3_dma: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_dma_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/dma/puv3_dma.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/dma/puv3_dma.c b/hw/dma/puv3_dma.c
index b97a6c1767..c89eade029 100644
--- a/hw/dma/puv3_dma.c
+++ b/hw/dma/puv3_dma.c
@@ -76,7 +76,7 @@ static const MemoryRegionOps puv3_dma_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int puv3_dma_init(SysBusDevice *dev)
+static void puv3_dma_realize(DeviceState *dev, Error **errp)
 {
 PUV3DMAState *s = PUV3_DMA(dev);
 int i;
@@ -87,16 +87,14 @@ static int puv3_dma_init(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _dma_ops, s, "puv3_dma",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 }
 
 static void puv3_dma_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_dma_init;
+dc->realize = puv3_dma_realize;
 }
 
 static const TypeInfo puv3_dma_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v2 12/21] milkymist-pfpu: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
milkymist_pfpu_class_init().

Cc: mich...@walle.cc

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/misc/milkymist-pfpu.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/hw/misc/milkymist-pfpu.c b/hw/misc/milkymist-pfpu.c
index 86f5e383b0..4a03c7ee63 100644
--- a/hw/misc/milkymist-pfpu.c
+++ b/hw/misc/milkymist-pfpu.c
@@ -497,17 +497,16 @@ static void milkymist_pfpu_reset(DeviceState *d)
 }
 }
 
-static int milkymist_pfpu_init(SysBusDevice *dev)
+static void milkymist_pfpu_realize(DeviceState *dev, Error **errp)
 {
 MilkymistPFPUState *s = MILKYMIST_PFPU(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 memory_region_init_io(>regs_region, OBJECT(dev), _mmio_ops, s,
 "milkymist-pfpu", MICROCODE_END * 4);
-sysbus_init_mmio(dev, >regs_region);
-
-return 0;
+sysbus_init_mmio(sbd, >regs_region);
 }
 
 static const VMStateDescription vmstate_milkymist_pfpu = {
@@ -527,9 +526,8 @@ static const VMStateDescription vmstate_milkymist_pfpu = {
 static void milkymist_pfpu_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = milkymist_pfpu_init;
+dc->realize = milkymist_pfpu_realize;
 dc->reset = milkymist_pfpu_reset;
 dc->vmsd = _milkymist_pfpu;
 }
-- 
2.17.1






[Qemu-devel] [PATCH v2 01/21] musicpal: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
mv88w8618_wlan_class_init().

Cc: jan.kis...@web.de
Cc: peter.mayd...@linaro.org
Cc: qemu-...@nongnu.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/arm/musicpal.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index 9648b3af44..7ffcdbb097 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -1147,14 +1147,13 @@ static const MemoryRegionOps mv88w8618_wlan_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int mv88w8618_wlan_init(SysBusDevice *dev)
+static void mv88w8618_wlan_realize(DeviceState *dev, Error **errp)
 {
 MemoryRegion *iomem = g_new(MemoryRegion, 1);
 
 memory_region_init_io(iomem, OBJECT(dev), _wlan_ops, NULL,
   "musicpal-wlan", MP_WLAN_SIZE);
-sysbus_init_mmio(dev, iomem);
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), iomem);
 }
 
 /* GPIO register offsets */
@@ -1720,9 +1719,9 @@ DEFINE_MACHINE("musicpal", musicpal_machine_init)
 
 static void mv88w8618_wlan_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = mv88w8618_wlan_init;
+dc->realize = mv88w8618_wlan_realize;
 }
 
 static const TypeInfo mv88w8618_wlan_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v2 04/21] core/empty_slot: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
empty_slot_class_init().

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/core/empty_slot.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/core/empty_slot.c b/hw/core/empty_slot.c
index c1b9c2b104..239f78e2a7 100644
--- a/hw/core/empty_slot.c
+++ b/hw/core/empty_slot.c
@@ -71,21 +71,20 @@ void empty_slot_init(hwaddr addr, uint64_t slot_size)
 }
 }
 
-static int empty_slot_init1(SysBusDevice *dev)
+static void empty_slot_realize(DeviceState *dev, Error **errp)
 {
 EmptySlot *s = EMPTY_SLOT(dev);
 
 memory_region_init_io(>iomem, OBJECT(s), _slot_ops, s,
   "empty-slot", s->size);
-sysbus_init_mmio(dev, >iomem);
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 }
 
 static void empty_slot_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-k->init = empty_slot_init1;
+dc->realize = empty_slot_realize;
 }
 
 static const TypeInfo empty_slot_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v2 08/21] milkymist-softusb: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
milkymist_softusb_class_init().

Cc: mich...@walle.cc

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/input/milkymist-softusb.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/hw/input/milkymist-softusb.c b/hw/input/milkymist-softusb.c
index ef8f47cd83..8766a17d9e 100644
--- a/hw/input/milkymist-softusb.c
+++ b/hw/input/milkymist-softusb.c
@@ -245,32 +245,31 @@ static void milkymist_softusb_reset(DeviceState *d)
 s->regs[R_CTRL] = CTRL_RESET;
 }
 
-static int milkymist_softusb_init(SysBusDevice *dev)
+static void milkymist_softusb_realize(DeviceState *dev, Error **errp)
 {
 MilkymistSoftUsbState *s = MILKYMIST_SOFTUSB(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 memory_region_init_io(>regs_region, OBJECT(s), _mmio_ops, s,
   "milkymist-softusb", R_MAX * 4);
-sysbus_init_mmio(dev, >regs_region);
+sysbus_init_mmio(sbd, >regs_region);
 
 /* register pmem and dmem */
 memory_region_init_ram_nomigrate(>pmem, OBJECT(s), 
"milkymist-softusb.pmem",
s->pmem_size, _fatal);
 vmstate_register_ram_global(>pmem);
 s->pmem_ptr = memory_region_get_ram_ptr(>pmem);
-sysbus_init_mmio(dev, >pmem);
+sysbus_init_mmio(sbd, >pmem);
 memory_region_init_ram_nomigrate(>dmem, OBJECT(s), 
"milkymist-softusb.dmem",
s->dmem_size, _fatal);
 vmstate_register_ram_global(>dmem);
 s->dmem_ptr = memory_region_get_ram_ptr(>dmem);
-sysbus_init_mmio(dev, >dmem);
+sysbus_init_mmio(sbd, >dmem);
 
 hid_init(>hid_kbd, HID_KEYBOARD, softusb_kbd_hid_datain);
 hid_init(>hid_mouse, HID_MOUSE, softusb_mouse_hid_datain);
-
-return 0;
 }
 
 static const VMStateDescription vmstate_milkymist_softusb = {
@@ -296,9 +295,8 @@ static Property milkymist_softusb_properties[] = {
 static void milkymist_softusb_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = milkymist_softusb_init;
+dc->realize = milkymist_softusb_realize;
 dc->reset = milkymist_softusb_reset;
 dc->vmsd = _milkymist_softusb;
 dc->props = milkymist_softusb_properties;
-- 
2.17.1






[Qemu-devel] [PATCH v2 07/21] gpio/puv3_gpio: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_gpio_class_init().

Cc: g...@mprc.pku.edu.cn
Cc: peter.mayd...@linaro.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/gpio/puv3_gpio.c | 29 ++---
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/hw/gpio/puv3_gpio.c b/hw/gpio/puv3_gpio.c
index 445afccf9f..33241b8564 100644
--- a/hw/gpio/puv3_gpio.c
+++ b/hw/gpio/puv3_gpio.c
@@ -99,36 +99,35 @@ static const MemoryRegionOps puv3_gpio_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int puv3_gpio_init(SysBusDevice *dev)
+static void puv3_gpio_realize(DeviceState *dev, Error **errp)
 {
 PUV3GPIOState *s = PUV3_GPIO(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 s->reg_GPLR = 0;
 s->reg_GPDR = 0;
 
 /* FIXME: these irqs not handled yet */
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW0]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW1]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW2]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW3]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW4]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW5]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW6]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOLOW7]);
-sysbus_init_irq(dev, >irq[PUV3_IRQS_GPIOHIGH]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW0]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW1]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW2]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW3]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW4]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW5]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW6]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOLOW7]);
+sysbus_init_irq(sbd, >irq[PUV3_IRQS_GPIOHIGH]);
 
 memory_region_init_io(>iomem, OBJECT(s), _gpio_ops, s, "puv3_gpio",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(sbd, >iomem);
 }
 
 static void puv3_gpio_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_gpio_init;
+dc->realize = puv3_gpio_realize;
 }
 
 static const TypeInfo puv3_gpio_info = {
-- 
2.17.1






[Qemu-devel] [PATCH v2 09/21] input/pl050: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
pl050_class_init().

Cc: peter.mayd...@linaro.org
Cc: qemu-...@nongnu.org

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/input/pl050.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/input/pl050.c b/hw/input/pl050.c
index be9cd57b17..15bffbfcad 100644
--- a/hw/input/pl050.c
+++ b/hw/input/pl050.c
@@ -139,19 +139,19 @@ static const MemoryRegionOps pl050_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int pl050_initfn(SysBusDevice *dev)
+static void pl050_realize(DeviceState *dev, Error **errp)
 {
 PL050State *s = PL050(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 memory_region_init_io(>iomem, OBJECT(s), _ops, s, "pl050", 
0x1000);
-sysbus_init_mmio(dev, >iomem);
-sysbus_init_irq(dev, >irq);
+sysbus_init_mmio(sbd, >iomem);
+sysbus_init_irq(sbd, >irq);
 if (s->is_mouse) {
 s->dev = ps2_mouse_init(pl050_update, s);
 } else {
 s->dev = ps2_kbd_init(pl050_update, s);
 }
-return 0;
 }
 
 static void pl050_keyboard_init(Object *obj)
@@ -183,9 +183,8 @@ static const TypeInfo pl050_mouse_info = {
 static void pl050_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(oc);
 
-sdc->init = pl050_initfn;
+dc->realize = pl050_realize;
 dc->vmsd = _pl050;
 }
 
-- 
2.17.1






[Qemu-devel] [PATCH v2 03/21] char/grlib_apbuart: Convert sysbus init function to realize function

2018-11-23 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
grlib_apbuart_class_init().

Cc: chout...@adacore.com
Cc: marcandre.lur...@redhat.com
Cc: pbonz...@redhat.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/char/grlib_apbuart.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/hw/char/grlib_apbuart.c b/hw/char/grlib_apbuart.c
index bac11bec58..e1d258b611 100644
--- a/hw/char/grlib_apbuart.c
+++ b/hw/char/grlib_apbuart.c
@@ -239,9 +239,10 @@ static const MemoryRegionOps grlib_apbuart_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int grlib_apbuart_init(SysBusDevice *dev)
+static void grlib_apbuart_realize(DeviceState *dev, Error **errp)
 {
 UART *uart = GRLIB_APB_UART(dev);
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
 qemu_chr_fe_set_handlers(>chr,
  grlib_apbuart_can_receive,
@@ -249,14 +250,12 @@ static int grlib_apbuart_init(SysBusDevice *dev)
  grlib_apbuart_event,
  NULL, uart, NULL, true);
 
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(sbd, >irq);
 
 memory_region_init_io(>iomem, OBJECT(uart), _apbuart_ops, uart,
   "uart", UART_REG_SIZE);
 
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(sbd, >iomem);
 }
 
 static void grlib_apbuart_reset(DeviceState *d)
@@ -280,9 +279,8 @@ static Property grlib_apbuart_properties[] = {
 static void grlib_apbuart_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = grlib_apbuart_init;
+dc->realize = grlib_apbuart_realize;
 dc->reset = grlib_apbuart_reset;
 dc->props = grlib_apbuart_properties;
 }
-- 
2.17.1






[Qemu-devel] [PATCH 18/22] timer/puv3_ost: Convert sysbus init function to realize function

2018-11-19 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_ost_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/timer/puv3_ost.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/hw/timer/puv3_ost.c b/hw/timer/puv3_ost.c
index 0b3d717e60..853b96dbde 100644
--- a/hw/timer/puv3_ost.c
+++ b/hw/timer/puv3_ost.c
@@ -113,7 +113,7 @@ static void puv3_ost_tick(void *opaque)
 }
 }
 
-static int puv3_ost_init(SysBusDevice *dev)
+static void puv3_ost_realize(DeviceState *dev, Error **errp)
 {
 PUV3OSTState *s = PUV3_OST(dev);
 
@@ -122,7 +122,7 @@ static int puv3_ost_init(SysBusDevice *dev)
 s->reg_OSMR0 = 0;
 s->reg_OSCR = 0;
 
-sysbus_init_irq(dev, >irq);
+sysbus_init_irq(SYS_BUS_DEVICE(dev), >irq);
 
 s->bh = qemu_bh_new(puv3_ost_tick, s);
 s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT);
@@ -130,16 +130,14 @@ static int puv3_ost_init(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _ost_ops, s, "puv3_ost",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 }
 
 static void puv3_ost_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_ost_init;
+dc->realize = puv3_ost_realize;
 }
 
 static const TypeInfo puv3_ost_info = {
-- 
2.17.1






[Qemu-devel] [PATCH 05/22] display/g364fb: Convert sysbus init function to realize function

2018-11-19 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
g364fb_sysbus_class_init().

Cc: pbonz...@redhat.com
Cc: kra...@redhat.com
Cc: f4...@amsat.org
Cc: alistair.fran...@wdc.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/display/g364fb.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c
index 8ad7e5d824..e7f67088b0 100644
--- a/hw/display/g364fb.c
+++ b/hw/display/g364fb.c
@@ -489,18 +489,15 @@ typedef struct {
 G364State g364;
 } G364SysBusState;
 
-static int g364fb_sysbus_init(SysBusDevice *sbd)
+static void g364fb_sysbus_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
 G364SysBusState *sbs = G364(dev);
 G364State *s = >g364;
 
 g364fb_init(dev, s);
-sysbus_init_irq(sbd, >irq);
-sysbus_init_mmio(sbd, >mem_ctrl);
-sysbus_init_mmio(sbd, >mem_vram);
-
-return 0;
+sysbus_init_irq(SYS_BUS_DEVICE(dev), >irq);
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >mem_ctrl);
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >mem_vram);
 }
 
 static void g364fb_sysbus_reset(DeviceState *d)
@@ -518,9 +515,8 @@ static Property g364fb_sysbus_properties[] = {
 static void g364fb_sysbus_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = g364fb_sysbus_init;
+dc->realize = g364fb_sysbus_realize;
 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
 dc->desc = "G364 framebuffer";
 dc->reset = g364fb_sysbus_reset;
-- 
2.17.1






[Qemu-devel] [PATCH 19/22] usb/tusb6010: Convert sysbus init function to realize function

2018-11-19 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
tusb6010_class_init().

Cc: kra...@redhat.com

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/usb/tusb6010.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/hw/usb/tusb6010.c b/hw/usb/tusb6010.c
index a2128024c1..0712281c42 100644
--- a/hw/usb/tusb6010.c
+++ b/hw/usb/tusb6010.c
@@ -808,29 +808,26 @@ static void tusb6010_reset(DeviceState *dev)
 musb_reset(s->musb);
 }
 
-static int tusb6010_init(SysBusDevice *sbd)
+static void tusb6010_realize(DeviceState *dev, Error **errp)
 {
-DeviceState *dev = DEVICE(sbd);
 TUSBState *s = TUSB(dev);
 
 s->otg_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, tusb_otg_tick, s);
 s->pwr_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, tusb_power_tick, s);
 memory_region_init_io(>iomem[1], OBJECT(s), _async_ops, s,
   "tusb-async", UINT32_MAX);
-sysbus_init_mmio(sbd, >iomem[0]);
-sysbus_init_mmio(sbd, >iomem[1]);
-sysbus_init_irq(sbd, >irq);
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem[0]);
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem[1]);
+sysbus_init_irq(SYS_BUS_DEVICE(dev), >irq);
 qdev_init_gpio_in(dev, tusb6010_irq, musb_irq_max + 1);
 s->musb = musb_init(dev, 1);
-return 0;
 }
 
 static void tusb6010_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
-SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-k->init = tusb6010_init;
+dc->realize = tusb6010_realize;
 dc->reset = tusb6010_reset;
 }
 
-- 
2.17.1






[Qemu-devel] [PATCH 13/22] puv3_pm.c: Convert sysbus init function to realize function

2018-11-19 Thread Mao Zhongyi
Use DeviceClass rather than SysBusDeviceClass in
puv3_pm_class_init().

Cc: g...@mprc.pku.edu.cn

Signed-off-by: Mao Zhongyi 
Signed-off-by: Zhang Shengju 
---
 hw/misc/puv3_pm.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/misc/puv3_pm.c b/hw/misc/puv3_pm.c
index 577cebaac7..afe191fbe1 100644
--- a/hw/misc/puv3_pm.c
+++ b/hw/misc/puv3_pm.c
@@ -119,7 +119,7 @@ static const MemoryRegionOps puv3_pm_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static int puv3_pm_init(SysBusDevice *dev)
+static void puv3_pm_realize(DeviceState *dev, Error **errp)
 {
 PUV3PMState *s = PUV3_PM(dev);
 
@@ -127,16 +127,14 @@ static int puv3_pm_init(SysBusDevice *dev)
 
 memory_region_init_io(>iomem, OBJECT(s), _pm_ops, s, "puv3_pm",
 PUV3_REGS_OFFSET);
-sysbus_init_mmio(dev, >iomem);
-
-return 0;
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), >iomem);
 }
 
 static void puv3_pm_class_init(ObjectClass *klass, void *data)
 {
-SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
-sdc->init = puv3_pm_init;
+dc->realize = puv3_pm_realize;
 }
 
 static const TypeInfo puv3_pm_info = {
-- 
2.17.1






  1   2   3   4   5   >