All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@qumranet.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 1/6] Use IO port for qemu<->guest BIOS communication.
Date: Tue, 26 Aug 2008 11:24:53 +0300	[thread overview]
Message-ID: <20080826082453.GV6192@minantech.com> (raw)
In-Reply-To: <f43fc5580808251127m36cec30du40858fb0e731832c@mail.gmail.com>

On Mon, Aug 25, 2008 at 09:27:18PM +0300, Blue Swirl wrote:
> >  Blue Swirl: What do you think of switching sparc to use a structure more
> > like this?  I do prefer a key-value mechanism verses a blob.  Even with pure
> > MMIO, the same results could be achieved by treating the MMIO region as
> > registers and using a selector.
> 
> I could switch Sparc to something like this, if the goal is that it
> will be used by all targets.
> 
> There should be a .h file which lists the keys and which can be
> included from C and asm, like current firmware_abi.h. I'd define an
> offset (0x8000?) for architecture-specific keys which need not be in
> the same .h file.

Is the patch below what you mean? (not tested, but compiles)


---

    Use IO port for qemu<->guest BIOS communication.
    
    Use PIO to get configuration info between qemu process and guest BIOS.
    
    Signed-off-by: Gleb Natapov <gleb@qumranet.com>

diff --git a/hw/fw_channel.h b/hw/fw_channel.h
new file mode 100644
index 0000000..3d44af1
--- /dev/null
+++ b/hw/fw_channel.h
@@ -0,0 +1,68 @@
+#ifndef FW_CHANNEL_H
+#define FW_CHANNEL_H
+
+#define FW_CFG_SIGNATURE        0x00
+#define FW_CFG_ID               0x01
+#define FW_CFG_MAX_ENTRY        0x10
+
+#define FW_CFG_ARCH_LOCAL       0x8000
+
+#ifndef __ASSEMBLY__
+
+typedef struct _FWCfgEntry {
+    uint16_t len;
+    uint8_t *data;
+} FWCfgEntry;
+
+typedef struct _FWCfgState {
+    FWCfgEntry entries[2][FW_CFG_MAX_ENTRY];
+    FWCfgEntry *cur_entry;
+    uint16_t cur_offset;
+} FWCfgState;
+
+static inline int firmware_cfg_add(FWCfgState *s, uint16_t key,
+        uint8_t *data, uint16_t len)
+{
+    int arch = key & FW_CFG_ARCH_LOCAL;
+
+    key &= (~FW_CFG_ARCH_LOCAL);
+
+    if (key >= FW_CFG_MAX_ENTRY)
+        return 0;
+
+    s->entries[arch][key].data = data;
+    s->entries[arch][key].len = len;
+
+    return 1;
+}
+
+static inline int firmware_cfg_select(FWCfgState *s, uint16_t key)
+{
+    int arch = key & FW_CFG_ARCH_LOCAL;
+
+    key &= (~FW_CFG_ARCH_LOCAL);
+
+    s->cur_offset = 0;
+    if (key >= FW_CFG_MAX_ENTRY) {
+        s->cur_entry = NULL;
+        return 0;
+    }
+
+    s->cur_entry = &s->entries[arch][key];
+
+    return 1;
+}
+
+static inline uint8_t firmware_cfg_read(FWCfgState *s)
+{
+    FWCfgEntry *e = s->cur_entry;
+
+    if (!e || !e->data || s->cur_offset >= e->len)
+        return 0;
+
+    return e->data[s->cur_offset++];
+}
+
+#endif /* __ASSEMBLY__ */
+
+#endif
diff --git a/hw/pc.c b/hw/pc.c
index 213ead8..db5089b 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -32,6 +32,7 @@
 #include "smbus.h"
 #include "boards.h"
 #include "console.h"
+#include "hw/fw_channel.h"
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -44,6 +45,7 @@
 
 /* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables.  */
 #define ACPI_DATA_SIZE       0x10000
+#define BIOS_CFG_IOPORT 0x510
 
 #define MAX_IDE_BUS 2
 
@@ -53,6 +55,9 @@ static PITState *pit;
 static IOAPICState *ioapic;
 static PCIDevice *i440fx_state;
 
+static uint32_t bios_cfg_id = 1;
+static FWCfgState *bios_params;
+
 static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
 {
 }
@@ -367,6 +372,21 @@ static uint32_t ioport92_read(void *opaque, uint32_t addr)
     return ioport_get_a20() << 1;
 }
 
+static uint32_t bios_cfg_read(void *opaque, uint32_t addr)
+{
+    FWCfgState *s = opaque;
+
+    return firmware_cfg_read(s);
+}
+
+static void bios_cfg_write(void *opaque, uint32_t addr, uint32_t value)
+{
+    FWCfgState *s = opaque;
+
+    firmware_cfg_select(s, (uint16_t)value);
+}
+
+
 /***********************************************************/
 /* Bochs BIOS debug ports */
 
@@ -426,6 +446,14 @@ static void bochs_bios_init(void)
     register_ioport_write(0x502, 1, 2, bochs_bios_write, NULL);
     register_ioport_write(0x500, 1, 1, bochs_bios_write, NULL);
     register_ioport_write(0x503, 1, 1, bochs_bios_write, NULL);
+
+    bios_params = qemu_mallocz(sizeof(FWCfgState));
+
+    register_ioport_read(BIOS_CFG_IOPORT, 1, 1, bios_cfg_read, bios_params);
+    register_ioport_write(BIOS_CFG_IOPORT, 1, 1, bios_cfg_write, bios_params);
+
+    firmware_cfg_add(bios_params, FW_CFG_SIGNATURE, "QEMU", 4);
+    firmware_cfg_add(bios_params, FW_CFG_ID, (uint8_t*)&bios_cfg_id, 4);
 }
 
 /* Generate an initial boot sector which sets state and jump to
--
			Gleb.

  reply	other threads:[~2008-08-26  8:24 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-25  9:58 [Qemu-devel] [PATCH v2 0/6] Add UUID command-line option Gleb Natapov
2008-08-25  9:58 ` [Qemu-devel] [PATCH v2 1/6] Use IO port for qemu<->guest BIOS communication Gleb Natapov
2008-08-25 14:24   ` Anthony Liguori
2008-08-25 14:40     ` Gleb Natapov
2008-08-25 15:01       ` Blue Swirl
2008-08-25 18:01         ` Anthony Liguori
2008-08-25 18:27           ` Blue Swirl
2008-08-26  8:24             ` Gleb Natapov [this message]
2008-08-26 16:46               ` Blue Swirl
2008-08-26 19:30                 ` Avi Kivity
2008-08-26 19:43                   ` Blue Swirl
2008-08-27  8:18                     ` Avi Kivity
2008-08-27 11:05                 ` Gleb Natapov
2008-08-27 17:10                   ` Blue Swirl
2008-08-28  5:29                     ` Gleb Natapov
2008-09-07  2:33                       ` Anthony Liguori
2008-09-07  9:32                         ` Blue Swirl
2008-09-08  5:39                         ` Gleb Natapov
2008-08-25 14:25   ` Anthony Liguori
2008-08-25 14:46     ` Gleb Natapov
2008-08-25 15:37       ` Jamie Lokier
2008-08-25 18:53         ` [Qemu-devel] Re: [PATCH v2 1/6] Use IO port for qemu<->guest BIOScommunication Sebastian Herbszt
2008-08-26  8:17           ` Gleb Natapov
2008-08-25  9:58 ` [Qemu-devel] [PATCH v2 2/6] Add -uuid command line option Gleb Natapov
2008-08-25  9:58 ` [Qemu-devel] [PATCH v2 3/6] Add "info uuid" command to monitor Gleb Natapov
2008-08-25  9:58 ` [Qemu-devel] [PATCH v2 4/6] Use libuuid if available Gleb Natapov
2008-08-25 11:08   ` Andreas Färber
2008-08-25 11:26     ` Gleb Natapov
2008-08-25 11:35       ` Jamie Lokier
2008-08-25 11:45       ` Andreas Färber
2008-08-25 14:03         ` Gleb Natapov
2008-08-25 18:57         ` [Qemu-devel] " Sebastian Herbszt
2008-08-25  9:58 ` [Qemu-devel] [PATCH v2 5/6] Add UUID to BIOS configuration info Gleb Natapov
2008-08-25  9:58 ` [Qemu-devel] [PATCH v2 6/6] Pass cpu speed into SM BIOS Gleb Natapov
2008-08-25 14:17   ` Anthony Liguori
2008-08-25 14:26     ` Gleb Natapov
2008-08-25 19:26       ` [Qemu-devel] " Sebastian Herbszt
2008-08-26  6:23         ` Gleb Natapov
2008-08-27 23:42           ` [Qemu-devel] " Sebastian Herbszt
2008-08-28  5:28             ` Gleb Natapov
2008-08-25 19:15   ` [Qemu-devel] " Sebastian Herbszt
2008-08-26  6:34     ` Gleb Natapov

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=20080826082453.GV6192@minantech.com \
    --to=gleb@qumranet.com \
    --cc=blauwirbel@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.