On 02/18/17 07:21, ben@skyportsystems.com wrote:
From: Ben Warren ben@skyportsystems.com
When resuming from S3, only fw_cfg file keys are known.
Signed-off-by: Ben Warren ben@skyportsystems.com
src/fw/paravirt.c | 23 +++++++++++++++++++++++ src/fw/paravirt.h | 2 ++ 2 files changed, 25 insertions(+)
diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 4618647..e513dd5 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -352,6 +352,17 @@ qemu_cfg_write_file(void *src, struct romfile_s *file, u32 offset, u32 len) return len; }
+// Bare-bones function for writing a file knowing only its unique +// identifying key (select) +int +qemu_cfg_write_file_simple(void *src, u16 key, u32 offset, u32 len) +{
- qemu_cfg_select(key);
- qemu_cfg_skip(offset);
- qemu_cfg_write(src, len);
- return len;
+}
Does anything counter-indicate the customization seen in qemu_cfg_write_file() as well, that is, call qemu_cfg_write_entry() if offset is zero?
If not, then I think you could even split out that part of qemu_cfg_write_file() as qemu_cfg_write_file_simple(), and call it from qemu_cfg_write_file().
static void qemu_romfile_add(char *name, int select, int skip, int size) { @@ -370,6 +381,18 @@ qemu_romfile_add(char *name, int select, int skip, int size) }
u16 +qemu_get_romfile_key(struct romfile_s *file) +{
- struct qemu_romfile_s *qfile;
- qfile = container_of(file, struct qemu_romfile_s, file);
If the input pointer "file" was valid, then container_of() cannot produce a NULL pointer. So I suggest to drop the code that depends on that.
- if (!qfile) {
warn_internalerror();
return 0;
- }
- return qfile->select;
+}
This could be reused in qemu_cfg_write_file() too, so that that function would remain: - initial checks - qemu_cfg_write_file_simple( ..., qemu_get_romfile_key(), ...)
I think patch #1 is fine as is, so I'd keep this refactoring in patch #4.
Thanks Laszlo
+u16 qemu_get_present_cpus_count(void) { u16 smp_count = 0; diff --git a/src/fw/paravirt.h b/src/fw/paravirt.h index fb220d8..16f3d9a 100644 --- a/src/fw/paravirt.h +++ b/src/fw/paravirt.h @@ -56,5 +56,7 @@ void qemu_cfg_init(void);
u16 qemu_get_present_cpus_count(void); int qemu_cfg_write_file(void *src, struct romfile_s *file, u32 offset, u32 len); +int qemu_cfg_write_file_simple(void *src, u16 key, u32 offset, u32 len); +u16 qemu_get_romfile_key(struct romfile_s *file);
#endif