qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Jason A . Donenfeld" <Jason@zx2c4.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Laurent Vivier" <laurent@vivier.eu>
Subject: [PATCH 3/4] hw/i386: extract handling of setup data linked list
Date: Thu, 21 Jul 2022 14:29:36 +0200	[thread overview]
Message-ID: <20220721122937.729959-4-pbonzini@redhat.com> (raw)
In-Reply-To: <20220721122937.729959-1-pbonzini@redhat.com>

In preparation for the introduction of a second setup data block,
manage the linked list and the reallocation of data.kernel in
a separate function.  Unlike the code that's being moved, the
function can be called more than once.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/i386/x86.c | 47 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 253a6ff536..564bf3834b 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -828,6 +828,34 @@ typedef struct LinuxBootData {
     size_t setup_data_offset;
 } LinuxBootData;
 
+static void *add_setup_data(LinuxBootData *data, uint32_t size, uint32_t type)
+{
+    struct setup_data *setup_data;
+    size_t prev_setup_data_offset = data->setup_data_offset;
+
+    if (data->protocol < 0x209) {
+        fprintf(stderr, "qemu: Linux kernel too old to add setup data\n");
+        exit(1);
+    }
+
+    data->setup_data_offset = QEMU_ALIGN_UP(data->kernel_size, 16);
+    data->kernel_size = data->setup_data_offset + sizeof(struct setup_data) + size;
+    data->kernel = g_realloc(data->kernel, data->kernel_size);
+
+    if (prev_setup_data_offset) {
+        setup_data = (struct setup_data *)(data->kernel + prev_setup_data_offset);
+        setup_data->next = cpu_to_le64(data->prot_addr + data->setup_data_offset);
+    } else {
+        stq_p(data->header + 0x250, data->prot_addr + data->setup_data_offset);
+    }
+
+    setup_data = (struct setup_data *)(data->kernel + data->setup_data_offset);
+    setup_data->next = 0;
+    setup_data->type = cpu_to_le32(type);
+    setup_data->len = cpu_to_le32(size);
+    return setup_data->data;
+}
+
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
@@ -1062,11 +1090,6 @@ void x86_load_linux(X86MachineState *x86ms,
 
     /* append dtb to kernel */
     if (dtb_filename) {
-        if (data.protocol < 0x209) {
-            fprintf(stderr, "qemu: Linux kernel too old to load a dtb\n");
-            exit(1);
-        }
-
         dtb_size = get_image_size(dtb_filename);
         if (dtb_size <= 0) {
             fprintf(stderr, "qemu: error reading dtb %s: %s\n",
@@ -1074,18 +1097,8 @@ void x86_load_linux(X86MachineState *x86ms,
             exit(1);
         }
 
-        data.setup_data_offset = QEMU_ALIGN_UP(data.kernel_size, 16);
-        data.kernel_size = data.setup_data_offset + sizeof(struct setup_data) + dtb_size;
-        data.kernel = g_realloc(data.kernel, data.kernel_size);
-
-        stq_p(data.header + 0x250, data.prot_addr + data.setup_data_offset);
-
-        struct setup_data *setup_data = (struct setup_data *)(data.kernel + data.setup_data_offset);
-        setup_data->next = 0;
-        setup_data->type = cpu_to_le32(SETUP_DTB);
-        setup_data->len = cpu_to_le32(dtb_size);
-
-        load_image_size(dtb_filename, setup_data->data, dtb_size);
+        void *dtb = add_setup_data(&data, dtb_size, SETUP_DTB);
+        load_image_size(dtb_filename, dtb, dtb_size);
     }
 
     /*
-- 
2.36.1




  parent reply	other threads:[~2022-07-21 12:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 12:29 [PATCH 0/4] Refactor x86_load_linux and pass RNG seed via setup_data entry Paolo Bonzini
2022-07-21 12:29 ` [PATCH 1/4] hw/i386: extract PVH load to a separate function Paolo Bonzini
2022-07-21 12:29 ` [PATCH 2/4] hw/i386: define a struct for Linux boot protocol data Paolo Bonzini
2022-07-21 12:29 ` Paolo Bonzini [this message]
2022-07-21 12:29 ` [PATCH 4/4] hw/i386: pass RNG seed via setup_data entry Paolo Bonzini
2022-07-21 13:02   ` Jason A. Donenfeld
2022-07-21 14:47   ` Michael S. Tsirkin
2022-07-21 15:15     ` Jason A. Donenfeld
2022-07-21 14:52 ` [PATCH 0/4] Refactor x86_load_linux and " Michael S. Tsirkin
2022-07-21 15:11   ` Jason A. Donenfeld
2022-07-21 15:29     ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220721122937.729959-4-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=Jason@zx2c4.com \
    --cc=eduardo@habkost.net \
    --cc=f4bug@amsat.org \
    --cc=laurent@vivier.eu \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).