Skip to contentSkip to conversation

qemu-kvm: Remove the dependency for phys_ram_base for ipf.c

PATCH Applied Zhang, Xiantao 3 participants 24 messages Apr 28, 2009 – May 4, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 3/4 qemu-kvm: Remove the dependency for phys_ram_base for ipf.c

From aaf97331da3d6cd34522441218c8c9ab3c1067f6 Mon Sep 17 00:00:00 2001
From: Xiantao Zhang <[email protected]>
Date: Tue, 28 Apr 2009 16:55:47 +0800
Subject: [PATCH] qemu-kvm: Remove the dependency for phys_ram_base for ipf.c

Upstream has dropped phys_ram_base, so ia64 also remove the dependency for that.

---
 hw/ipf.c               |   42 +++++++++++++++++++-----------------------
 target-ia64/firmware.c |   25 +++++++++++++++++--------
 target-ia64/firmware.h |    6 +++---
 3 files changed, 39 insertions(+), 34 deletions(-)
hw/ipf.c +19 -23
index 5ed2667..ccd7665 100644
@@ -54,7 +54,8 @@ static fdctrl_t *floppy_controller;
 static RTCState *rtc_state;
 static PCIDevice *i440fx_state;
 
-uint8_t *g_fw_start;
+ram_addr_t gfw_start;
+
 static uint32_t ipf_to_legacy_io(target_phys_addr_t addr)
 {
     return (uint32_t)(((addr&0x3ffffff) >> 12 << 2)|((addr) & 0x3));
@@ -454,15 +455,15 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
     if (kvm_enabled()) {
         unsigned long  image_size;
         char *image = NULL;
-        uint8_t *fw_image_start;
+        ram_addr_t fw_image_start;
         unsigned long nvram_addr = 0;
         unsigned long nvram_fd = 0;
         unsigned long type = READ_FROM_NVRAM;
         unsigned long i = 0;
-        ram_addr_t fw_offset = qemu_ram_alloc(GFW_SIZE);
-        uint8_t *fw_start = phys_ram_base + fw_offset;
 
-        g_fw_start = fw_start;
+        ram_addr  = qemu_ram_alloc(GFW_SIZE);
+        gfw_start = (ram_addr_t)qemu_get_ram_ptr(ram_addr);
+
         snprintf(buf, sizeof(buf), "%s/%s", bios_dir, FW_FILENAME);
         image = read_image(buf, &image_size );
         if (NULL == image || !image_size) {
@@ -470,20 +471,20 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
             fprintf(stderr, "Please check Guest firmware at %s\n", buf);
             exit(1);
         }
-        fw_image_start = fw_start + GFW_SIZE - image_size;
-
-        cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_offset);
-        memcpy(fw_image_start, image, image_size);
-
-        free(image);
+ /* Load Guest Firmware to the proper postion. */
+        fw_image_start = gfw_start + GFW_SIZE - image_size;
+        memcpy((void *)fw_image_start, image, image_size);
         flush_icache_range((unsigned long)fw_image_start,
                            (unsigned long)fw_image_start + image_size);
+        free(image);
+
+        cpu_register_physical_memory(GFW_START, GFW_SIZE, ram_addr);
 
-        nvram_addr = NVRAM_START;
         if (nvram) {
+            nvram_addr = NVRAM_START;
             nvram_fd = kvm_ia64_nvram_init(type);
             if (nvram_fd != -1) {
-                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd, g_fw_start);
+                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd, gfw_start);
                 close(nvram_fd);
             }
             i = atexit((void *)kvm_ia64_copy_from_GFW_to_nvram);
@@ -491,7 +492,7 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
                 fprintf(stderr, "cannot set exit function\n");
         }
         kvm_ia64_build_hob(ram_size + above_4g_mem_size, smp_cpus,
-                           fw_start, nvram_addr);
+                           gfw_start, nvram_addr);
     }
 
     /*Register legacy io address space, size:64M*/
@@ -513,19 +514,15 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
 
     if (cirrus_vga_enabled) {
         if (pci_enabled) {
-            pci_cirrus_vga_init(pci_bus, phys_ram_base + vga_ram_addr,
-                                vga_ram_addr, vga_ram_size);
+            pci_cirrus_vga_init(pci_bus, vga_ram_size);
         } else {
-            isa_cirrus_vga_init(phys_ram_base + vga_ram_addr,
-                                vga_ram_addr, vga_ram_size);
+            isa_cirrus_vga_init(vga_ram_size);
         }
     } else {
         if (pci_enabled) {
-            pci_vga_init(pci_bus, phys_ram_base + vga_ram_addr,
-                         vga_ram_addr, vga_ram_size, 0, 0);
+            pci_vga_init(pci_bus, vga_ram_size, 0, 0);
         } else {
-            isa_vga_init(phys_ram_base + vga_ram_addr,
-                         vga_ram_addr, vga_ram_size);
+            isa_vga_init(vga_ram_size);
         }
     }
 
@@ -671,7 +668,6 @@ QEMUMachine ipf_machine = {
     .name = "itanium",
     .desc = "Itanium Platform",
     .init = (QEMUMachineInitFunc *)ipf_init_pci,
-    .ram_require = (ram_addr_t)(VGA_RAM_SIZE + GFW_SIZE),
     .max_cpus = 255,
 };
 
target-ia64/firmware.c +17 -8
index 87a8178..2ed2e0d 100644
@@ -92,11 +92,11 @@ static int build_hob(void *hob_buf, unsigned long hob_buf_size,
                      unsigned long dom_mem_size, unsigned long vcpus,
                      unsigned long nvram_addr);
 static int load_hob(void *hob_buf,
-                    unsigned long dom_mem_size, void* hob_start);
+                    unsigned long dom_mem_size, ram_addr_t hob_start);
 
 int
 kvm_ia64_build_hob(unsigned long memsize, unsigned long vcpus,
-                   uint8_t *fw_start, unsigned long nvram_addr)
+                   ram_addr_t fw_start, unsigned long nvram_addr)
 {
     char   *hob_buf;
 
@@ -249,7 +249,7 @@ err_out:
     return -1;
 }
 static int
-load_hob(void *hob_buf, unsigned long dom_mem_size, void* hob_start)
+load_hob(void *hob_buf, unsigned long dom_mem_size, ram_addr_t hob_start)
 {
     int hob_size;
 
@@ -263,7 +263,7 @@ load_hob(void *hob_buf, unsigned long dom_mem_size, void* hob_start)
         Hob_Output("No enough memory for hob data");
         return -1;
     }
-    memcpy (hob_start, hob_buf, hob_size);
+    memcpy ((void *)hob_start, hob_buf, hob_size);
     return 0;
 }
 
@@ -644,7 +644,7 @@ out:
 
 int
 kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd,
-                                const uint8_t *fw_start)
+                                const ram_addr_t fw_start)
 {
     struct stat file_stat;
     if ((fstat(nvram_fd, &file_stat) < 0) ||
@@ -659,8 +659,13 @@ int
 kvm_ia64_copy_from_GFW_to_nvram()
 {
     unsigned long nvram_fd;
+    void* real_nvram_start;
+    target_phys_addr_t nvram_size = NVRAM_SIZE;
     unsigned long type = WRITE_TO_NVRAM;
-    unsigned long *nvram_addr = (unsigned long *)(g_fw_start + NVRAM_OFFSET);
+    unsigned long *nvram_addr = (unsigned long *)(gfw_start + NVRAM_OFFSET);
+
+
+
     nvram_fd = kvm_ia64_nvram_init(type);
     if (nvram_fd  == -1)
         goto out;
@@ -669,11 +674,15 @@ kvm_ia64_copy_from_GFW_to_nvram()
         goto out;
     }
     lseek(nvram_fd, 0, SEEK_SET);
-    if (write(nvram_fd, ((void *)(((struct nvram_save_addr *)nvram_addr)->addr +
-        (char *)phys_ram_base)), NVRAM_SIZE) != NVRAM_SIZE) {
+
+    real_nvram_start = cpu_physical_memory_map(((struct nvram_save_addr*)nvram_addr)->addr,
+ &nvram_size, 1);
+    if (write(nvram_fd, real_nvram_start, NVRAM_SIZE) != NVRAM_SIZE) {
         close(nvram_fd);
         goto out;
     }
+    cpu_physical_memory_unmap(real_nvram_start, NVRAM_SIZE, 1, NVRAM_SIZE);
+
     close(nvram_fd);
     return 0;
 out:
target-ia64/firmware.h +3 -3
index c1707ac..548352c 100644
@@ -52,13 +52,13 @@ struct nvram_save_addr {
 };
 
 extern const char *nvram;
-extern uint8_t *g_fw_start;
+extern ram_addr_t gfw_start;
 extern int kvm_ia64_build_hob(unsigned long memsize, unsigned long vcpus,
-                              uint8_t *fw_start, unsigned long nvram_addr);
+                              ram_addr_t fw_start, unsigned long nvram_addr);
 extern char *read_image(const char *filename, unsigned long *size);
 
 extern int kvm_ia64_copy_from_GFW_to_nvram(void);
 extern int kvm_ia64_nvram_init(unsigned long type);
 extern int kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd,
-                                           const uint8_t *fw_start);
+                                           const ram_addr_t fw_start);
 #endif //__FIRM_WARE_
Signature · 1 line
1.6.0

From aaf97331da3d6cd34522441218c8c9ab3c1067f6 Mon Sep 17 00:00:00 2001
From: Xiantao Zhang <[email protected]>
Date: Tue, 28 Apr 2009 16:55:47 +0800
Subject: [PATCH] qemu-kvm: Remove the dependency for phys_ram_base for ipf.c

Upstream has dropped phys_ram_base, so ia64 also remove the dependency for that.

---
 hw/ipf.c               |   42 +++++++++++++++++++-----------------------
 target-ia64/firmware.c |   25 +++++++++++++++++--------
 target-ia64/firmware.h |    6 +++---
 3 files changed, 39 insertions(+), 34 deletions(-)
hw/ipf.c +19 -23

94 lines not on this page · raw message

target-ia64/firmware.c +17 -8
index 87a8178..2ed2e0d 100644
@@ -92,11 +92,11 @@ static int build_hob(void *hob_buf, unsigned long hob_buf_size,
                      unsigned long dom_mem_size, unsigned long vcpus,
                      unsigned long nvram_addr);
 static int load_hob(void *hob_buf,
-                    unsigned long dom_mem_size, void* hob_start);
+                    unsigned long dom_mem_size, ram_addr_t hob_start);
 
 int
 kvm_ia64_build_hob(unsigned long memsize, unsigned long vcpus,
-                   uint8_t *fw_start, unsigned long nvram_addr)
+                   ram_addr_t fw_start, unsigned long nvram_addr)
 {
     char   *hob_buf;
 
@@ -249,7 +249,7 @@ err_out:
     return -1;
 }
 static int
-load_hob(void *hob_buf, unsigned long dom_mem_size, void* hob_start)
+load_hob(void *hob_buf, unsigned long dom_mem_size, ram_addr_t hob_start)
 {
     int hob_size;
 
@@ -263,7 +263,7 @@ load_hob(void *hob_buf, unsigned long dom_mem_size, void* hob_start)
         Hob_Output("No enough memory for hob data");
         return -1;
     }
-    memcpy (hob_start, hob_buf, hob_size);
+    memcpy ((void *)hob_start, hob_buf, hob_size);
     return 0;
 }
 
@@ -644,7 +644,7 @@ out:
 
 int
 kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd,
-                                const uint8_t *fw_start)
+                                const ram_addr_t fw_start)
 {
     struct stat file_stat;
     if ((fstat(nvram_fd, &file_stat) < 0) ||
@@ -659,8 +659,13 @@ int
 kvm_ia64_copy_from_GFW_to_nvram()
 {
     unsigned long nvram_fd;
+    void* real_nvram_start;
+    target_phys_addr_t nvram_size = NVRAM_SIZE;
     unsigned long type = WRITE_TO_NVRAM;
-    unsigned long *nvram_addr = (unsigned long *)(g_fw_start + NVRAM_OFFSET);
+    unsigned long *nvram_addr = (unsigned long *)(gfw_start + NVRAM_OFFSET);
+
+
+
     nvram_fd = kvm_ia64_nvram_init(type);
     if (nvram_fd  == -1)
         goto out;
@@ -669,11 +674,15 @@ kvm_ia64_copy_from_GFW_to_nvram()
         goto out;
     }
     lseek(nvram_fd, 0, SEEK_SET);
-    if (write(nvram_fd, ((void *)(((struct nvram_save_addr *)nvram_addr)->addr +
-        (char *)phys_ram_base)), NVRAM_SIZE) != NVRAM_SIZE) {
+
+    real_nvram_start = cpu_physical_memory_map(((struct nvram_save_addr*)nvram_addr)->addr,
+	&nvram_size, 1);
+    if (write(nvram_fd, real_nvram_start, NVRAM_SIZE) != NVRAM_SIZE) {
         close(nvram_fd);
         goto out;
     }
+    cpu_physical_memory_unmap(real_nvram_start, NVRAM_SIZE, 1, NVRAM_SIZE);
+
     close(nvram_fd);
     return 0;
 out:
target-ia64/firmware.h +3 -3
index c1707ac..548352c 100644
@@ -52,13 +52,13 @@ struct nvram_save_addr {
 };
 
 extern const char *nvram;
-extern uint8_t *g_fw_start;
+extern ram_addr_t gfw_start;
 extern int kvm_ia64_build_hob(unsigned long memsize, unsigned long vcpus,
-                              uint8_t *fw_start, unsigned long nvram_addr);
+                              ram_addr_t fw_start, unsigned long nvram_addr);
 extern char *read_image(const char *filename, unsigned long *size);
 
 extern int kvm_ia64_copy_from_GFW_to_nvram(void);
 extern int kvm_ia64_nvram_init(unsigned long type);
 extern int kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd,
-                                           const uint8_t *fw_start);
+                                           const ram_addr_t fw_start);
 #endif //__FIRM_WARE_
Signature · 1 line
1.6.0
#1 lore raw
Quoted 26 lines · Xiantao

From aaf97331da3d6cd34522441218c8c9ab3c1067f6 Mon Sep 17 00:00:00 2001
From: Xiantao Zhang <[email protected]>
Date: Tue, 28 Apr 2009 16:55:47 +0800
Subject: [PATCH] qemu-kvm: Remove the dependency for phys_ram_base for ipf.c

Upstream has dropped phys_ram_base, so ia64 also remove the dependency for that.

+++ b/hw/ipf.c

hw/ipf.c +3 -2
@@ -54,7 +54,8 @@ static fdctrl_t *floppy_controller;
 static RTCState *rtc_state;
 static PCIDevice *i440fx_state;
 
-uint8_t *g_fw_start;
+ram_addr_t gfw_start;
+
 static uint32_t ipf_to_legacy_io(target_phys_addr_t addr)
 {
     return (uint32_t)(((addr&0x3ffffff) >> 12 << 2)|((addr) & 0x3));
@@ -454,15 +455,15 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
     if (kvm_enabled()) {
         unsigned long  image_size;
         char *image = NULL;
-        uint8_t *fw_image_start;
+        ram_addr_t fw_image_start;
         unsigned long nvram_addr = 0;

hw/ipf.c static void ipf_init1(ram_addr_t ram_size, int vga_ram_size, · line 466

Quoted 10 lines
hw/ipf.c +2 -3
         unsigned long nvram_fd = 0;
         unsigned long type = READ_FROM_NVRAM;
         unsigned long i = 0;
-        ram_addr_t fw_offset = qemu_ram_alloc(GFW_SIZE);
-        uint8_t *fw_start = phys_ram_base + fw_offset;
 
-        g_fw_start = fw_start;
+        ram_addr  = qemu_ram_alloc(GFW_SIZE);
+        gfw_start = (ram_addr_t)qemu_get_ram_ptr(ram_addr);
 

qemu_get_ram_ptr() returns a pointer. Don't cast it to a ram_addr_t, leave it a pointer.

But why not use cpu_physical_memory_write() (or cpu_physical_memory_write_rom())? It's much simpler and cleaner.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#2 lore raw
Quoted 40 lines · Avi Kivity
Quoted 25 lines · Xiantao

From aaf97331da3d6cd34522441218c8c9ab3c1067f6 Mon Sep 17 00:00:00 2001
From: Xiantao Zhang <[email protected]>
Date: Tue, 28 Apr 2009 16:55:47 +0800
Subject: [PATCH] qemu-kvm: Remove the dependency for phys_ram_base for ipf.c

Upstream has dropped phys_ram_base, so ia64 also remove the dependency for that.

+++ b/hw/ipf.c

(quoted diff) +3 -2
@@ -54,7 +54,8 @@ static fdctrl_t *floppy_controller;  static
 RTCState *rtc_state; static PCIDevice *i440fx_state;
 
-uint8_t *g_fw_start;
+ram_addr_t gfw_start;
+
 static uint32_t ipf_to_legacy_io(target_phys_addr_t addr)  {
     return (uint32_t)(((addr&0x3ffffff) >> 12 << 2)|((addr) & 0x3));
@@ -454,15 +455,15 @@ static void ipf_init1(ram_addr_t ram_size, int
         vga_ram_size,      if (kvm_enabled()) { unsigned long 
         image_size; char *image = NULL;
-        uint8_t *fw_image_start;
+        ram_addr_t fw_image_start;
         unsigned long nvram_addr = 0;

Review static void ipf_init1(ram_addr_t ram_size, int · line 465

Quoted 10 lines
(quoted diff) +2 -3
         unsigned long nvram_fd = 0;
         unsigned long type = READ_FROM_NVRAM;
         unsigned long i = 0;
-        ram_addr_t fw_offset = qemu_ram_alloc(GFW_SIZE);
-        uint8_t *fw_start = phys_ram_base + fw_offset;
 
-        g_fw_start = fw_start;
+        ram_addr  = qemu_ram_alloc(GFW_SIZE);
+        gfw_start = (ram_addr_t)qemu_get_ram_ptr(ram_addr);
 

qemu_get_ram_ptr() returns a pointer. Don't cast it to a ram_addr_t, leave it a pointer.

Quoted 2 lines

But why not use cpu_physical_memory_write() (or cpu_physical_memory_write_rom())? It's much simpler and cleaner.

Good suggestion! I just followed the original logic. Updated the patch. Xiantao

From ed2542566e800bbd20eeba13d030cafc940e5f39 Mon Sep 17 00:00:00 2001
From: Xiantao Zhang <[email protected]>
Date: Tue, 28 Apr 2009 18:25:54 +0800
Subject: [PATCH] qemu-kvm: Remove the dependency for phys_ram_base for ipf.c

Upstream has dropped phys_ram_base, so ia64 also remove the dependency for that.

---
 hw/ipf.c               |   43 +++++++++++++++++++------------------------
 target-ia64/firmware.c |   29 +++++++++++++++++++----------
 target-ia64/firmware.h |    8 ++++----
 3 files changed, 42 insertions(+), 38 deletions(-)
hw/ipf.c +19 -24
index 5ed2667..7aa9839 100644
@@ -54,7 +54,8 @@ static fdctrl_t *floppy_controller;
 static RTCState *rtc_state;
 static PCIDevice *i440fx_state;
 
-uint8_t *g_fw_start;
+void *gfw_start;
+
 static uint32_t ipf_to_legacy_io(target_phys_addr_t addr)
 {
     return (uint32_t)(((addr&0x3ffffff) >> 12 << 2)|((addr) & 0x3));
@@ -453,16 +454,17 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
     /*Load firware to its proper position.*/
     if (kvm_enabled()) {
         unsigned long  image_size;
-        char *image = NULL;
-        uint8_t *fw_image_start;
+        uint8_t *image = NULL;
+        target_phys_addr_t fw_image_start;
         unsigned long nvram_addr = 0;
         unsigned long nvram_fd = 0;
         unsigned long type = READ_FROM_NVRAM;
         unsigned long i = 0;
-        ram_addr_t fw_offset = qemu_ram_alloc(GFW_SIZE);
-        uint8_t *fw_start = phys_ram_base + fw_offset;
 
-        g_fw_start = fw_start;
+        ram_addr  = qemu_ram_alloc(GFW_SIZE);
+        gfw_start = qemu_get_ram_ptr(ram_addr);
+        cpu_register_physical_memory(GFW_START, GFW_SIZE, ram_addr);
+
         snprintf(buf, sizeof(buf), "%s/%s", bios_dir, FW_FILENAME);
         image = read_image(buf, &image_size );
         if (NULL == image || !image_size) {
@@ -470,20 +472,18 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
             fprintf(stderr, "Please check Guest firmware at %s\n", buf);
             exit(1);
         }
-        fw_image_start = fw_start + GFW_SIZE - image_size;
-
-        cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_offset);
-        memcpy(fw_image_start, image, image_size);
 
+        /* Load Guest Firmware to the proper postion. */
+        fw_image_start = GFW_START + GFW_SIZE - image_size;
+        cpu_physical_memory_write(fw_image_start, image, image_size);
         free(image);
-        flush_icache_range((unsigned long)fw_image_start,
-                           (unsigned long)fw_image_start + image_size);
 
-        nvram_addr = NVRAM_START;
+
         if (nvram) {
+            nvram_addr = NVRAM_START;
             nvram_fd = kvm_ia64_nvram_init(type);
             if (nvram_fd != -1) {
-                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd, g_fw_start);
+                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd, gfw_start);
                 close(nvram_fd);
             }
             i = atexit((void *)kvm_ia64_copy_from_GFW_to_nvram);
@@ -491,7 +491,7 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
                 fprintf(stderr, "cannot set exit function\n");
         }
         kvm_ia64_build_hob(ram_size + above_4g_mem_size, smp_cpus,
-                           fw_start, nvram_addr);
+					gfw_start, nvram_addr);
     }
 
     /*Register legacy io address space, size:64M*/
@@ -513,19 +513,15 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
 
     if (cirrus_vga_enabled) {
         if (pci_enabled) {
-            pci_cirrus_vga_init(pci_bus, phys_ram_base + vga_ram_addr,
-                                vga_ram_addr, vga_ram_size);
+            pci_cirrus_vga_init(pci_bus, vga_ram_size);
         } else {
-            isa_cirrus_vga_init(phys_ram_base + vga_ram_addr,
-                                vga_ram_addr, vga_ram_size);
+            isa_cirrus_vga_init(vga_ram_size);
         }
     } else {
         if (pci_enabled) {
-            pci_vga_init(pci_bus, phys_ram_base + vga_ram_addr,
-                         vga_ram_addr, vga_ram_size, 0, 0);
+            pci_vga_init(pci_bus, vga_ram_size, 0, 0);
         } else {
-            isa_vga_init(phys_ram_base + vga_ram_addr,
-                         vga_ram_addr, vga_ram_size);
+            isa_vga_init(vga_ram_size);
         }
     }
 
@@ -671,7 +667,6 @@ QEMUMachine ipf_machine = {
     .name = "itanium",
     .desc = "Itanium Platform",
     .init = (QEMUMachineInitFunc *)ipf_init_pci,
-    .ram_require = (ram_addr_t)(VGA_RAM_SIZE + GFW_SIZE),
     .max_cpus = 255,
 };
 
target-ia64/firmware.c +19 -10
index 87a8178..ba16bd8 100644
@@ -92,11 +92,11 @@ static int build_hob(void *hob_buf, unsigned long hob_buf_size,
                      unsigned long dom_mem_size, unsigned long vcpus,
                      unsigned long nvram_addr);
 static int load_hob(void *hob_buf,
-                    unsigned long dom_mem_size, void* hob_start);
+                    unsigned long dom_mem_size, void *hob_start);
 
 int
 kvm_ia64_build_hob(unsigned long memsize, unsigned long vcpus,
-                   uint8_t *fw_start, unsigned long nvram_addr)
+                   void* fw_start, unsigned long nvram_addr)
 {
     char   *hob_buf;
 
@@ -249,7 +249,7 @@ err_out:
     return -1;
 }
 static int
-load_hob(void *hob_buf, unsigned long dom_mem_size, void* hob_start)
+load_hob(void *hob_buf, unsigned long dom_mem_size, void *hob_start)
 {
     int hob_size;
 
@@ -263,7 +263,7 @@ load_hob(void *hob_buf, unsigned long dom_mem_size, void* hob_start)
         Hob_Output("No enough memory for hob data");
         return -1;
     }
-    memcpy (hob_start, hob_buf, hob_size);
+    memcpy ((void *)hob_start, hob_buf, hob_size);
     return 0;
 }
 
@@ -526,11 +526,11 @@ add_pal_hob(void* hob_buf)
     return 0;
 }
 
-char *read_image(const char *filename, unsigned long *size)
+uint8_t *read_image(const char *filename, unsigned long *size)
 {
     int kernel_fd = -1;
     gzFile kernel_gfd = NULL;
-    char *image = NULL, *tmp;
+    uint8_t *image = NULL, *tmp;
     unsigned int bytes;
 
     if ((filename == NULL) || (size == NULL))
@@ -644,7 +644,7 @@ out:
 
 int
 kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd,
-                                const uint8_t *fw_start)
+                                const void* fw_start)
 {
     struct stat file_stat;
     if ((fstat(nvram_fd, &file_stat) < 0) ||
@@ -659,8 +659,13 @@ int
 kvm_ia64_copy_from_GFW_to_nvram()
 {
     unsigned long nvram_fd;
+    void* real_nvram_start;
+    target_phys_addr_t nvram_size = NVRAM_SIZE;
     unsigned long type = WRITE_TO_NVRAM;
-    unsigned long *nvram_addr = (unsigned long *)(g_fw_start + NVRAM_OFFSET);
+    unsigned long *nvram_addr = (unsigned long *)(gfw_start + NVRAM_OFFSET);
+
+
+
     nvram_fd = kvm_ia64_nvram_init(type);
     if (nvram_fd  == -1)
         goto out;
@@ -669,11 +674,15 @@ kvm_ia64_copy_from_GFW_to_nvram()
         goto out;
     }
     lseek(nvram_fd, 0, SEEK_SET);
-    if (write(nvram_fd, ((void *)(((struct nvram_save_addr *)nvram_addr)->addr +
-        (char *)phys_ram_base)), NVRAM_SIZE) != NVRAM_SIZE) {
+
+    real_nvram_start = cpu_physical_memory_map(((struct nvram_save_addr*)nvram_addr)->addr,
+	&nvram_size, 1);
+    if (write(nvram_fd, real_nvram_start, NVRAM_SIZE) != NVRAM_SIZE) {
         close(nvram_fd);
         goto out;
     }
+    cpu_physical_memory_unmap(real_nvram_start, NVRAM_SIZE, 1, NVRAM_SIZE);
+
     close(nvram_fd);
     return 0;
 out:
target-ia64/firmware.h +4 -4
index c1707ac..132c119 100644
@@ -52,13 +52,13 @@ struct nvram_save_addr {
 };
 
 extern const char *nvram;
-extern uint8_t *g_fw_start;
+extern void *gfw_start;
 extern int kvm_ia64_build_hob(unsigned long memsize, unsigned long vcpus,
-                              uint8_t *fw_start, unsigned long nvram_addr);
-extern char *read_image(const char *filename, unsigned long *size);
+                              void* fw_start, unsigned long nvram_addr);
+extern uint8_t *read_image(const char *filename, unsigned long *size);
 
 extern int kvm_ia64_copy_from_GFW_to_nvram(void);
 extern int kvm_ia64_nvram_init(unsigned long type);
 extern int kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd,
-                                           const uint8_t *fw_start);
+                                           const void* fw_start);
 #endif //__FIRM_WARE_
Signature · 1 line
1.6.0
Applied
#3 lore raw
Quoted 10 lines · Xiantao
Quoted 7 lines

qemu_get_ram_ptr() returns a pointer. Don't cast it to a ram_addr_t, leave it a pointer.

But why not use cpu_physical_memory_write() (or cpu_physical_memory_write_rom())? It's much simpler and cleaner.

Good suggestion! I just followed the original logic. Updated the patch. Xiantao

Thanks, applied.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#4 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Avi" = Avi Kivity <[email protected]> writes:

Quoted 8 lines · Xiantao
Quoted 8 lines
Quoted 6 lines

qemu_get_ram_ptr() returns a pointer. Don't cast it to a
ram_addr_t, leave it a pointer.

But why not use cpu_physical_memory_write() (or cpu_physical_memory_write_rom())? It's much simpler and cleaner.

Good suggestion! I just followed the original logic. Updated the
patch. Xiantao

Avi> Thanks, applied.

Hi,

I am not crazy about this patch. You need to use cpy_physical_memory_rw() in the hob and nvram code too, not just in the ipf.c code.

What about the flush_icache_range() call you removed - is it safe to just discard that?

I was in the process of working through this myself, but I am not quite finished. If you don't mind waiting a couple hours, I should have something a fair bit simpler to solve the same problem.

Biggest issue is the flush_icache_range() one.

Cheers,
Jes

#5 lore raw
Quoted 23 lines · Jes Sorensen
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Avi" = Avi Kivity <[email protected]> writes:

Quoted 10 lines · Xiantao
Quoted 10 lines
Quoted 7 lines

qemu_get_ram_ptr() returns a pointer. Don't cast it to a
ram_addr_t, leave it a pointer.

But why not use cpu_physical_memory_write() (or cpu_physical_memory_write_rom())? It's much simpler and cleaner.

Good suggestion! I just followed the original logic. Updated the
patch. Xiantao

Avi> Thanks, applied.

Hi,

I am not crazy about this patch. You need to use cpy_physical_memory_rw() in the hob and nvram code too, not just in the ipf.c code.

Quoted 10 lines

What about the flush_icache_range() call you removed - is it safe to just discard that?

I was in the process of working through this myself, but I am not quite finished. If you don't mind waiting a couple hours, I should have something a fair bit simpler to solve the same problem.

Biggest issue is the flush_icache_range() one.

I haven't pushed this out yet, so I can apply a replacement patch.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#6 lore raw
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Jes Sorensen

Hi,

I am not crazy about this patch. You need to use cpy_physical_memory_rw() in the hob and nvram code too, not just in the ipf.c code.

What about the flush_icache_range() call you removed - is it safe to just discard that?

Quoted 7 lines
Quoted 6 lines

I was in the process of working through this myself, but I am not quite finished. If you don't mind waiting a couple hours, I should have something a fair bit simpler to solve the same problem.

Biggest issue is the flush_icache_range() one.

I haven't pushed this out yet, so I can apply a replacement patch.

Hi,

As promised here is my proposal for how to implement this patch. I have made the hob and nvram code use cpu_physical_memory_{read,write} as well, handled the cache flushing address pointer issue in the flush function, which needs some improvement to be done later.

By doing this I have been able to remove a bunch of globals and a number of variables being passed around which we really don't need.

Xiantao, what do you think of this solution?

Cheers,
Jes

Remove ia64 dependency on phys_ram_base and assumption that phys_ram_base + qemu_alloc_ram() is always valid. Use cpu_physical_memory_{read,write} instead of memcpy.

The behavior of the NVRAM code is questionable, but this code should behave the same as the old code ... it still needs to be fixed.

flush_icache_range() should also be improved to reget the host pointer on every page boundary, but at least this is no worse than what we had before.

---
 hw/ipf.c                |   48 ++++++++++++------------------
 target-ia64/fake-exec.c |   16 ++++++++--
 target-ia64/firmware.c  |   76 +++++++++++++++++++++++++++++++-----------------
 target-ia64/firmware.h  |    8 +----
 4 files changed, 85 insertions(+), 63 deletions(-)
hw/ipf.c +19 -29
Index: qemu-kvm/hw/ipf.c
===================================================================
@@ -54,7 +54,6 @@
 static RTCState *rtc_state;
 static PCIDevice *i440fx_state;
 
-uint8_t *g_fw_start;
 static uint32_t ipf_to_legacy_io(target_phys_addr_t addr)
 {
     return (uint32_t)(((addr&0x3ffffff) >> 12 << 2)|((addr) & 0x3));
@@ -453,16 +452,14 @@
     /*Load firware to its proper position.*/
     if (kvm_enabled()) {
         unsigned long  image_size;
-        char *image = NULL;
-        uint8_t *fw_image_start;
+        uint8_t *image = NULL;
         unsigned long nvram_addr = 0;
         unsigned long nvram_fd = 0;
         unsigned long type = READ_FROM_NVRAM;
         unsigned long i = 0;
-        ram_addr_t fw_offset = qemu_ram_alloc(GFW_SIZE);
-        uint8_t *fw_start = phys_ram_base + fw_offset;
+        unsigned long fw_offset;
+        ram_addr_t fw_mem = qemu_ram_alloc(GFW_SIZE);
 
-        g_fw_start = fw_start;
         snprintf(buf, sizeof(buf), "%s/%s", bios_dir, FW_FILENAME);
         image = read_image(buf, &image_size );
         if (NULL == image || !image_size) {
@@ -470,28 +467,28 @@
             fprintf(stderr, "Please check Guest firmware at %s\n", buf);
             exit(1);
         }
-        fw_image_start = fw_start + GFW_SIZE - image_size;
+        fw_offset = GFW_START + GFW_SIZE - image_size;
 
-        cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_offset);
-        memcpy(fw_image_start, image, image_size);
+        cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_mem);
+        cpu_physical_memory_write(fw_offset, image, image_size);
 
         free(image);
-        flush_icache_range((unsigned long)fw_image_start,
-                           (unsigned long)fw_image_start + image_size);
+
+        flush_icache_range(fw_offset, fw_offset + image_size);
 
         nvram_addr = NVRAM_START;
         if (nvram) {
             nvram_fd = kvm_ia64_nvram_init(type);
             if (nvram_fd != -1) {
-                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd, g_fw_start);
+                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd);
                 close(nvram_fd);
             }
             i = atexit((void *)kvm_ia64_copy_from_GFW_to_nvram);
             if (i != 0)
                 fprintf(stderr, "cannot set exit function\n");
         }
-        kvm_ia64_build_hob(ram_size + above_4g_mem_size, smp_cpus,
-                           fw_start, nvram_addr);
+
+        kvm_ia64_build_hob(ram_size + above_4g_mem_size, smp_cpus, nvram_addr);
     }
 
     /*Register legacy io address space, size:64M*/
@@ -512,21 +509,15 @@
     }
 
     if (cirrus_vga_enabled) {
-        if (pci_enabled) {
-            pci_cirrus_vga_init(pci_bus, phys_ram_base + vga_ram_addr,
-                                vga_ram_addr, vga_ram_size);
-        } else {
-            isa_cirrus_vga_init(phys_ram_base + vga_ram_addr,
-                                vga_ram_addr, vga_ram_size);
-        }
+        if (pci_enabled)
+            pci_cirrus_vga_init(pci_bus, vga_ram_size);
+        else
+            isa_cirrus_vga_init(vga_ram_size);
     } else {
-        if (pci_enabled) {
-            pci_vga_init(pci_bus, phys_ram_base + vga_ram_addr,
-                         vga_ram_addr, vga_ram_size, 0, 0);
-        } else {
-            isa_vga_init(phys_ram_base + vga_ram_addr,
-                         vga_ram_addr, vga_ram_size);
-        }
+        if (pci_enabled)
+            pci_vga_init(pci_bus, vga_ram_size, 0, 0);
+        else
+            isa_vga_init(vga_ram_size);
     }
 
     rtc_state = rtc_init(0x70, i8259[8], 2000);
@@ -671,7 +662,6 @@
     .name = "itanium",
     .desc = "Itanium Platform",
     .init = (QEMUMachineInitFunc *)ipf_init_pci,
-    .ram_require = (ram_addr_t)(VGA_RAM_SIZE + GFW_SIZE),
     .max_cpus = 255,
 };
 
target-ia64/fake-exec.c +13 -3
Index: qemu-kvm/target-ia64/fake-exec.c
===================================================================
@@ -43,9 +43,19 @@
 
 void flush_icache_range(unsigned long start, unsigned long stop)
 {
-    while (start < stop) {
-	asm volatile ("fc %0" :: "r"(start));
-	start += 32;
+    unsigned long size = stop - start;
+    unsigned long host_start, host_stop;
+
+    /*
+     * This probably should be made more advanced and regrab the pointer
+     * on every page boundary.
+     */
+    host_start = qemu_get_ram_ptr(start);
+    host_end = host_start + size;
+
+    while (host_start < host_stop) {
+	asm volatile ("fc %0" :: "r"(host_start));
+	host_start += 32;
     }
     asm volatile (";;sync.i;;srlz.i;;");
 }
target-ia64/firmware.c +50 -26

135 lines not on this page · raw message

target-ia64/firmware.h +3 -5
Index: qemu-kvm/target-ia64/firmware.h
===================================================================
@@ -52,13 +52,11 @@
 };
 
 extern const char *nvram;
-extern uint8_t *g_fw_start;
 extern int kvm_ia64_build_hob(unsigned long memsize, unsigned long vcpus,
-                              uint8_t *fw_start, unsigned long nvram_addr);
-extern char *read_image(const char *filename, unsigned long *size);
+                              unsigned long nvram_addr);
+extern uint8_t *read_image(const char *filename, unsigned long *size);
 
 extern int kvm_ia64_copy_from_GFW_to_nvram(void);
 extern int kvm_ia64_nvram_init(unsigned long type);
-extern int kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd,
-                                           const uint8_t *fw_start);
+extern int kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd);
 #endif //__FIRM_WARE_
#7 lore raw
In reply to Avi Kivity
Quoted 32 lines · Avi Kivity
Quoted 31 lines · Jes Sorensen
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Avi" = Avi Kivity <[email protected]> writes:

Quoted 10 lines · Xiantao
Quoted 10 lines
Quoted 7 lines

qemu_get_ram_ptr() returns a pointer. Don't cast it to a
ram_addr_t, leave it a pointer.

But why not use cpu_physical_memory_write() (or cpu_physical_memory_write_rom())? It's much simpler and cleaner.

Good suggestion! I just followed the original logic. Updated the
patch. Xiantao

Avi> Thanks, applied.

Hi,

I am not crazy about this patch. You need to use cpy_physical_memory_rw() in the hob and nvram code too, not just in the ipf.c code.

What about the flush_icache_range() call you removed - is it safe to just discard that?

I was in the process of working through this myself, but I am not quite finished. If you don't mind waiting a couple hours, I should have something a fair bit simpler to solve the same problem.

Quoted 5 lines
Quoted 3 lines

Biggest issue is the flush_icache_range() one.

I haven't pushed this out yet, so I can apply a replacement patch.

We don't need flush_icache_range here, because I believe it is called in cpu_physical_memory_write. Xiantao

#8 lore raw
Quoted 4 lines · Xiantao
Quoted 1 line · Avi Kivity

I haven't pushed this out yet, so I can apply a replacement patch.

We don't need flush_icache_range here, because I believe it is called in cpu_physical_memory_write. Xiantao

Hi Xiantao,

Good point, I hadn't spotted that, and worse I mangled flush_icache_range() in the process, trying to be smart :-(

Here's a version without cache flush changes, it should do the right thing<tm>. We still need to look at the nvram stuff, but that is broken in all setups currently.

What do you think of this one?

Cheers,
Jes

Remove ia64 dependency on phys_ram_base and assumption that phys_ram_base + qemu_alloc_ram() is always valid. Use cpu_physical_memory_{read,write} instead of memcpy.

The behavior of the NVRAM code is questionable, but this code should behave the same as the old code ... it still needs to be fixed.

---
 hw/ipf.c               |   46 ++++++++++-------------------
 target-ia64/firmware.c |   76 ++++++++++++++++++++++++++++++++-----------------
 target-ia64/firmware.h |    8 +----
 3 files changed, 70 insertions(+), 60 deletions(-)
hw/ipf.c +17 -29
Index: qemu-kvm/hw/ipf.c
===================================================================
@@ -54,7 +54,6 @@
 static RTCState *rtc_state;
 static PCIDevice *i440fx_state;
 
-uint8_t *g_fw_start;
 static uint32_t ipf_to_legacy_io(target_phys_addr_t addr)
 {
     return (uint32_t)(((addr&0x3ffffff) >> 12 << 2)|((addr) & 0x3));
@@ -453,16 +452,14 @@
     /*Load firware to its proper position.*/
     if (kvm_enabled()) {
         unsigned long  image_size;
-        char *image = NULL;
-        uint8_t *fw_image_start;
+        uint8_t *image = NULL;
         unsigned long nvram_addr = 0;
         unsigned long nvram_fd = 0;
         unsigned long type = READ_FROM_NVRAM;
         unsigned long i = 0;
-        ram_addr_t fw_offset = qemu_ram_alloc(GFW_SIZE);
-        uint8_t *fw_start = phys_ram_base + fw_offset;
+        unsigned long fw_offset;
+        ram_addr_t fw_mem = qemu_ram_alloc(GFW_SIZE);
 
-        g_fw_start = fw_start;
         snprintf(buf, sizeof(buf), "%s/%s", bios_dir, FW_FILENAME);
         image = read_image(buf, &image_size );
         if (NULL == image || !image_size) {
@@ -470,28 +467,26 @@
             fprintf(stderr, "Please check Guest firmware at %s\n", buf);
             exit(1);
         }
-        fw_image_start = fw_start + GFW_SIZE - image_size;
+        fw_offset = GFW_START + GFW_SIZE - image_size;
 
-        cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_offset);
-        memcpy(fw_image_start, image, image_size);
+        cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_mem);
+        cpu_physical_memory_write(fw_offset, image, image_size);
 
         free(image);
-        flush_icache_range((unsigned long)fw_image_start,
-                           (unsigned long)fw_image_start + image_size);
 
         nvram_addr = NVRAM_START;
         if (nvram) {
             nvram_fd = kvm_ia64_nvram_init(type);
             if (nvram_fd != -1) {
-                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd, g_fw_start);
+                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd);
                 close(nvram_fd);
             }
             i = atexit((void *)kvm_ia64_copy_from_GFW_to_nvram);
             if (i != 0)
                 fprintf(stderr, "cannot set exit function\n");
         }
-        kvm_ia64_build_hob(ram_size + above_4g_mem_size, smp_cpus,
-                           fw_start, nvram_addr);
+
+        kvm_ia64_build_hob(ram_size + above_4g_mem_size, smp_cpus, nvram_addr);
     }
 
     /*Register legacy io address space, size:64M*/
@@ -512,21 +507,15 @@
     }
 
     if (cirrus_vga_enabled) {
-        if (pci_enabled) {
-            pci_cirrus_vga_init(pci_bus, phys_ram_base + vga_ram_addr,
-                                vga_ram_addr, vga_ram_size);
-        } else {
-            isa_cirrus_vga_init(phys_ram_base + vga_ram_addr,
-                                vga_ram_addr, vga_ram_size);
-        }
+        if (pci_enabled)
+            pci_cirrus_vga_init(pci_bus, vga_ram_size);
+        else
+            isa_cirrus_vga_init(vga_ram_size);
     } else {
-        if (pci_enabled) {
-            pci_vga_init(pci_bus, phys_ram_base + vga_ram_addr,
-                         vga_ram_addr, vga_ram_size, 0, 0);
-        } else {
-            isa_vga_init(phys_ram_base + vga_ram_addr,
-                         vga_ram_addr, vga_ram_size);
-        }
+        if (pci_enabled)
+            pci_vga_init(pci_bus, vga_ram_size, 0, 0);
+        else
+            isa_vga_init(vga_ram_size);
     }
 
     rtc_state = rtc_init(0x70, i8259[8], 2000);
@@ -671,7 +660,6 @@
     .name = "itanium",
     .desc = "Itanium Platform",
     .init = (QEMUMachineInitFunc *)ipf_init_pci,
-    .ram_require = (ram_addr_t)(VGA_RAM_SIZE + GFW_SIZE),
     .max_cpus = 255,
 };
 
target-ia64/firmware.c +50 -26

135 lines not on this page · raw message

target-ia64/firmware.h +3 -5
Index: qemu-kvm/target-ia64/firmware.h
===================================================================
@@ -52,13 +52,11 @@
 };
 
 extern const char *nvram;
-extern uint8_t *g_fw_start;
 extern int kvm_ia64_build_hob(unsigned long memsize, unsigned long vcpus,
-                              uint8_t *fw_start, unsigned long nvram_addr);
-extern char *read_image(const char *filename, unsigned long *size);
+                              unsigned long nvram_addr);
+extern uint8_t *read_image(const char *filename, unsigned long *size);
 
 extern int kvm_ia64_copy_from_GFW_to_nvram(void);
 extern int kvm_ia64_nvram_init(unsigned long type);
-extern int kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd,
-                                           const uint8_t *fw_start);
+extern int kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd);
 #endif //__FIRM_WARE_
#9 lore raw
Quoted 9 lines · Jes Sorensen
Quoted 5 lines · Xiantao
Quoted 1 line · Avi Kivity

I haven't pushed this out yet, so I can apply a replacement patch.

We don't need flush_icache_range here, because I believe it is called in cpu_physical_memory_write. Xiantao

Hi Xiantao,

Quoted 8 lines

Good point, I hadn't spotted that, and worse I mangled flush_icache_range() in the process, trying to be smart :-(

Here's a version without cache flush changes, it should do the right thing<tm>. We still need to look at the nvram stuff, but that is broken in all setups currently.

What do you think of this one?

Hi, Jes
Except nvram stuff, I don't see the difference with my patch. Could you provide an incremental patch to fix nvram stuff ? :)
Xiantao

#10 lore raw
Quoted 6 lines · Xiantao
Quoted 1 line · Jes Sorensen

What do you think of this one?

Hi, Jes
Except nvram stuff, I don't see the difference with my patch. Could you provide an incremental patch to fix nvram stuff ? :)
Xiantao

Hi Xiantao,

The main difference is that my patch cleans up the interfaces and calls to the various functions, and removes a bunch of global variables as well.

The problem with the NVRAM stuff is that I don't know how it is supposed to work. Do you have any specification or documentation for it?

Cheers,
Jes

#11 lore raw
Quoted 9 lines · Jes Sorensen
Quoted 7 lines · Xiantao
Quoted 1 line · Jes Sorensen

What do you think of this one?

Hi, Jes
Except nvram stuff, I don't see the difference with my patch.
Could you provide an incremental patch to fix nvram stuff ? :) Xiantao

Quoted 5 lines

Hi Xiantao,

The main difference is that my patch cleans up the interfaces and calls to the various functions, and removes a bunch of global variables as well.

I still can't see the difference with the patch in Avi's tree except nvram stuff. And I believe the global variable you mentioned should be only used for nvram. So I propose an incremental patch for that. :)

Quoted 3 lines

The problem with the NVRAM stuff is that I don't know how it is supposed to work. Do you have any specification or documentation for it?

No specification, and we just followed the guest's firmware logic for that. The link for guest firmware: http://xenbits.xensource.com/ext/efi-vfirmware.hg

#12 lore raw
Quoted 6 lines · Xiantao
Quoted 3 lines · Jes Sorensen

The main difference is that my patch cleans up the interfaces and calls to the various functions, and removes a bunch of global variables as well.

I still can't see the difference with the patch in Avi's tree except nvram stuff. And I believe the global variable you mentioned should be only used for nvram. So I propose an incremental patch for that. :)

Let me try and take a look - last I pulled from Avi, those patches didn't show up in git.

Been trying to get the mapping and alias stuff done, so probably won't get to this until tomorrow.

Cheers,
jes

#13 lore raw
In reply to Zhang, Xiantao
Quoted 6 lines · Xiantao
Quoted 3 lines · Jes Sorensen

The main difference is that my patch cleans up the interfaces and calls to the various functions, and removes a bunch of global variables as well.

I still can't see the difference with the patch in Avi's tree except nvram stuff. And I believe the global variable you mentioned should be only used for nvram. So I propose an incremental patch for that. :)

Hi Xiantao,

I cannot see your patch in Avi's tree, would you mind sending me the latest version by email, so I can look into this?

Thanks,
Jes

#14 lore raw
Quoted 6 lines · Jes Sorensen
Quoted 5 lines · Xiantao
Quoted 3 lines · Jes Sorensen

The main difference is that my patch cleans up the interfaces and calls to the various functions, and removes a bunch of global variables as well.

Quoted 9 lines
Quoted 3 lines

I still can't see the difference with the patch in Avi's tree except nvram stuff. And I believe the global variable you mentioned should be only used for nvram. So I propose an incremental patch for that. :)

Hi Xiantao,

I cannot see your patch in Avi's tree, would you mind sending me the latest version by email, so I can look into this?

I pushed my queue into a branch (named 'queue'). Will merge once I resolve the regressions here.

Signature · 1 line
error compiling committee.c: too many arguments to function
#15 lore raw
Quoted 4 lines · Avi Kivity

Jes Sorensen wrote:
I pushed my queue into a branch (named 'queue'). Will merge once I resolve the regressions here.

Hi Avi,

I don't see that branch - it's in the qemu-kvm repo?

Cheers,
Jes

[jes@leavenworth qemu-kvm]$ git branch -a
* master
origin/HEAD
origin/bios-merge
origin/bios-patchqueue
origin/bochs-bios-cvs
origin/bochs-bios-vendor-drops
origin/build
origin/for-glommer
origin/ia64-vtd
origin/irq-routing-2
origin/kvm-updates-2.6.25
origin/kvm-updates-2.6.26
origin/kvm-updates-2.6.27
origin/kvm-updates/2.6.26
origin/kvm-updates/2.6.27
origin/kvm-updates/2.6.28
origin/kvm-updates/2.6.29
origin/kvm-updates/2.6.30
origin/maint/2.6.25
origin/maint/2.6.26
origin/maint/2.6.26-test
origin/maint/2.6.28
origin/maint/2.6.29
origin/maint/2.6.30
origin/master
origin/merge-tmp
origin/origin
origin/pending
origin/qemu-cvs
origin/qemu-vendor-drops
origin/realmode
origin/release
[jes@leavenworth qemu-kvm]$

#16 lore raw
Quoted 10 lines · Jes Sorensen
Quoted 4 lines · Avi Kivity

Jes Sorensen wrote:
I pushed my queue into a branch (named 'queue'). Will merge once I resolve the regressions here.

Hi Avi,

I don't see that branch - it's in the qemu-kvm repo?

Did you run 'git fetch origin'?

Signature · 1 line
error compiling committee.c: too many arguments to function
#17 lore raw
In reply to Zhang, Xiantao
Quoted 2 lines · Xiantao

Jes Sorensen wrote:
I still can't see the difference with the patch in Avi's tree except nvram stuff. And I believe the global variable you mentioned should be only used for nvram. So I propose an incremental patch for that. :)

Hi,

Here is an incremental version of the patch. I think the differences should be pretty obvious now :-)

It fixes the memcpy issues in the hob and nvram code and also cleans up the interfaces a lot.

Avi, please add.

Cheers,
Jes

Fix ia64 code to use copy_physical_memory_{read,write} in hob and nvram code, removing dependencies of qemu_get_ram_ptr() usage.

This results in cleaned up APIs and removal of unnecessary global variables.

This is an incremental patch on top of previous patch posted by Xiantao.

---
 hw/ipf.c               |   38 ++++++++++---------------
 target-ia64/firmware.c |   73 +++++++++++++++++++++++++++++--------------------
 target-ia64/firmware.h |    6 +---
 3 files changed, 62 insertions(+), 55 deletions(-)
hw/ipf.c +16 -22
Index: qemu-kvm/hw/ipf.c
===================================================================
@@ -54,8 +54,6 @@
 static RTCState *rtc_state;
 static PCIDevice *i440fx_state;
 
-void *gfw_start;
-
 static uint32_t ipf_to_legacy_io(target_phys_addr_t addr)
 {
     return (uint32_t)(((addr&0x3ffffff) >> 12 << 2)|((addr) & 0x3));
@@ -455,15 +453,12 @@
     if (kvm_enabled()) {
         unsigned long  image_size;
         uint8_t *image = NULL;
-        target_phys_addr_t fw_image_start;
-        unsigned long nvram_addr = 0;
+        unsigned long nvram_addr;
         unsigned long nvram_fd = 0;
         unsigned long type = READ_FROM_NVRAM;
         unsigned long i = 0;
-
-        ram_addr  = qemu_ram_alloc(GFW_SIZE);
-        gfw_start = qemu_get_ram_ptr(ram_addr);
-        cpu_register_physical_memory(GFW_START, GFW_SIZE, ram_addr);
+        unsigned long fw_offset;
+        ram_addr_t fw_mem = qemu_ram_alloc(GFW_SIZE);
 
         snprintf(buf, sizeof(buf), "%s/%s", bios_dir, FW_FILENAME);
         image = read_image(buf, &image_size );
@@ -472,26 +467,27 @@
             fprintf(stderr, "Please check Guest firmware at %s\n", buf);
             exit(1);
         }
+        fw_offset = GFW_START + GFW_SIZE - image_size;
 
-        /* Load Guest Firmware to the proper postion. */
-        fw_image_start = GFW_START + GFW_SIZE - image_size;
-        cpu_physical_memory_write(fw_image_start, image, image_size);
-        free(image);
+        cpu_register_physical_memory(GFW_START, GFW_SIZE, fw_mem);
+        cpu_physical_memory_write(fw_offset, image, image_size);
 
+        free(image);
 
         if (nvram) {
             nvram_addr = NVRAM_START;
             nvram_fd = kvm_ia64_nvram_init(type);
             if (nvram_fd != -1) {
-                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd, gfw_start);
+                kvm_ia64_copy_from_nvram_to_GFW(nvram_fd);
                 close(nvram_fd);
             }
             i = atexit((void *)kvm_ia64_copy_from_GFW_to_nvram);
             if (i != 0)
                 fprintf(stderr, "cannot set exit function\n");
-        }
-        kvm_ia64_build_hob(ram_size + above_4g_mem_size, smp_cpus,
-					gfw_start, nvram_addr);
+        } else
+            nvram_addr = 0;
+
+        kvm_ia64_build_hob(ram_size + above_4g_mem_size, smp_cpus, nvram_addr);
     }
 
     /*Register legacy io address space, size:64M*/
@@ -512,17 +508,15 @@
     }
 
     if (cirrus_vga_enabled) {
-        if (pci_enabled) {
+        if (pci_enabled)
             pci_cirrus_vga_init(pci_bus, vga_ram_size);
-        } else {
+        else
             isa_cirrus_vga_init(vga_ram_size);
-        }
     } else {
-        if (pci_enabled) {
+        if (pci_enabled)
             pci_vga_init(pci_bus, vga_ram_size, 0, 0);
-        } else {
+        else
             isa_vga_init(vga_ram_size);
-        }
     }
 
     rtc_state = rtc_init(0x70, i8259[8], 2000);
target-ia64/firmware.c +44 -29

127 lines not on this page · raw message

target-ia64/firmware.h +2 -4
Index: qemu-kvm/target-ia64/firmware.h
===================================================================
@@ -52,13 +52,11 @@
 };
 
 extern const char *nvram;
-extern void *gfw_start;
 extern int kvm_ia64_build_hob(unsigned long memsize, unsigned long vcpus,
-                              void* fw_start, unsigned long nvram_addr);
+                              unsigned long nvram_addr);
 extern uint8_t *read_image(const char *filename, unsigned long *size);
 
 extern int kvm_ia64_copy_from_GFW_to_nvram(void);
 extern int kvm_ia64_nvram_init(unsigned long type);
-extern int kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd,
-                                           const void* fw_start);
+extern int kvm_ia64_copy_from_nvram_to_GFW(unsigned long nvram_fd);
 #endif //__FIRM_WARE_
#18 lore raw
Quoted 8 lines · Jes Sorensen
Quoted 4 lines · Xiantao

Jes Sorensen wrote:
I still can't see the difference with the patch in Avi's tree except nvram stuff. And I believe the global variable you mentioned should be only used for nvram. So I propose an incremental patch for that. :)

Hi,

Quoted 7 lines

Here is an incremental version of the patch. I think the differences should be pretty obvious now :-)

It fixes the memcpy issues in the hob and nvram code and also cleans up the interfaces a lot.

Avi, please add.

Looks good to me. Xiantao?

Signature · 1 line
error compiling committee.c: too many arguments to function
#19 lore raw
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Jes Sorensen
Quoted 5 lines · Xiantao

Jes Sorensen wrote:
I still can't see the difference with the patch in Avi's tree except nvram stuff. And I believe the global variable you mentioned should be only used for nvram. So I propose an incremental patch for that. :)

Hi,

Here is an incremental version of the patch. I think the differences should be pretty obvious now :-)

Quoted 6 lines
Quoted 4 lines

It fixes the memcpy issues in the hob and nvram code and also cleans up the interfaces a lot.

Avi, please add.

Looks good to me. Xiantao?

Hi, Jes
Have you tested nvram support with this patch? I
Xiantao

#20 lore raw
Quoted 6 lines · Xiantao

Avi Kivity wrote:
Looks good to me. Xiantao?

Hi, Jes
Have you tested nvram support with this patch? I
Xiantao

No,

But it is behaving exactly like the old code, so it is no more broken than the old code was.

Lets apply this and then look at the nvram issues afterwards.

Jes

#21 lore raw
Quoted 8 lines · Jes Sorensen
Quoted 6 lines · Xiantao

Avi Kivity wrote:
Looks good to me. Xiantao?

Hi, Jes
Have you tested nvram support with this patch? I
Xiantao

Quoted 6 lines

No,

But it is behaving exactly like the old code, so it is no more broken than the old code was.

Lets apply this and then look at the nvram issues afterwards.

Okay. :)
Xiantao

#22 lore raw
In reply to Jes Sorensen
Quoted 8 lines · Jes Sorensen
Quoted 4 lines · Xiantao

Jes Sorensen wrote:
I still can't see the difference with the patch in Avi's tree except nvram stuff. And I believe the global variable you mentioned should be only used for nvram. So I propose an incremental patch for that. :)

Hi,

Quoted 7 lines

Here is an incremental version of the patch. I think the differences should be pretty obvious now :-)

It fixes the memcpy issues in the hob and nvram code and also cleans up the interfaces a lot.

Avi, please add.

Added, thanks.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#23 lore raw
In reply to Jes Sorensen
Quoted 9 lines · Jes Sorensen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Avi" = Avi Kivity <[email protected]> writes:

Quoted 6 lines · Xiantao
Quoted 6 lines
Quoted 6 lines

qemu_get_ram_ptr() returns a pointer. Don't cast it to a
ram_addr_t, leave it a pointer.

But why not use cpu_physical_memory_write() (or cpu_physical_memory_write_rom())? It's much simpler and cleaner.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

Good suggestion! I just followed the original logic. Updated the
patch. Xiantao

Avi> Thanks, applied.

Hi,

Hi, Jes

Quoted 3 lines

I am not crazy about this patch. You need to use cpy_physical_memory_rw() in the hob and nvram code too, not just in the ipf.c code.

Agree, maybe you can make an increment patch for that.

Quoted 2 lines

What about the flush_icache_range() call you removed - is it safe to just discard that?"

Yes, I think cpu_physical_memory_write also called the flush_icache_range, so don't need to duplicate it.

Quoted 8 lines

I was in the process of working through this myself, but I am not quite finished. If you don't mind waiting a couple hours, I should have something a fair bit simpler to solve the same problem.

Biggest issue is the flush_icache_range() one.

Cheers,
Jes