Skip to contentSkip to conversation

mips_malta: Clean up definition of flash memory size

PATCH In review Philippe Mathieu-Daudé 5 participants 20 messages Mar 5, 2019 – Mar 7, 2019

lore
Share & tools
lore
#0 lore raw

cover mips_malta: Clean up definition of flash memory size

Hi Markus,

this is a rework of your 'mips_malta: Clean up definition of flash memory size somewhat' patch:
https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07177.html

Regards,

Phil.

Based-on: <[email protected]>

Markus Armbruster (1):
mips_malta: Clean up definition of flash memory size somewhat

Philippe Mathieu-Daudé (4):
hw/mips/malta: Fix the DEBUG_BOARD_INIT code hw/mips/malta: Remove fl_sectors variable (used one single time) hw/mips/malta: Restrict 'bios_size' variable scope hw/mips/malta: Only accept 'monitor' pflash of 4MiB

 hw/mips/mips_malta.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/5 hw/mips/malta: Fix the DEBUG_BOARD_INIT code

Commit fa1d36df746 missed to convert this ifdef'ed out code. Introduce the pflash_blk variable.

This fixes:

hw/mips/mips_malta.c:1273:16: error: implicit declaration of function ‘blk_name’; did you mean ‘basename’? [-Werror=implicit-function-declaration]

                blk_name(dinfo->bdrv), fl_sectors);
                ^~~~~~~~
  hw/mips/mips_malta.c:1273:16: error: nested extern declaration of ‘blk_name’ [-Werror=nested-externs]
  hw/mips/mips_malta.c:1273:30: error: ‘DriveInfo’ {aka ‘struct DriveInfo’} has no member named ‘bdrv’
                blk_name(dinfo->bdrv), fl_sectors);
                                ^~
Fixes fa1d36df746
---
 hw/mips/mips_malta.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
hw/mips/mips_malta.c +9 -6
index 2827074e9b..b4cd8f02ad 100644
@@ -40,6 +40,7 @@
 #include "hw/pci/pci.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/arch_init.h"
+#include "sysemu/block-backend.h"
 #include "qemu/log.h"
 #include "hw/mips/bios.h"
 #include "hw/ide.h"
@@ -1205,6 +1206,7 @@ void mips_malta_init(MachineState *machine)
     qemu_irq cbus_irq, i8259_irq;
     int piix4_devfn;
     I2CBus *smbus;
+    BlockBackend *pflash_blk = NULL;
     DriveInfo *dinfo;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     int fl_idx = 0;
@@ -1265,17 +1267,18 @@ void mips_malta_init(MachineState *machine)
 
     /* Load firmware in flash / BIOS. */
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
-#ifdef DEBUG_BOARD_INIT
     if (dinfo) {
+        pflash_blk = blk_by_legacy_dinfo(dinfo);
+#ifdef DEBUG_BOARD_INIT
         printf("Register parallel flash %d size " TARGET_FMT_lx " at "
-               "addr %08llx '%s' %x\n",
-               fl_idx, bios_size, FLASH_ADDRESS,
-               blk_name(dinfo->bdrv), fl_sectors);
-    }
+               "addr %08llx '%s'\n",
+               fl_idx, blk_getlength(pflash_blk), FLASH_ADDRESS,
+               blk_name(pflash_blk));
 #endif
+    }
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
                                BIOS_SIZE,
-                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
+                               pflash_blk,
                                65536, fl_sectors,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
     bios = pflash_cfi01_get_memory(fl);
Signature · 1 line
2.20.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] hw/mips/malta: Fix the DEBUG_BOARD_INIT code

Quoted 1 line · Philippe Mathieu-Daudé

Commit fa1d36df746 missed to convert this ifdef'ed out code.

My fault...

Quoted 44 lines

Introduce the pflash_blk variable.

This fixes:

hw/mips/mips_malta.c:1273:16: error: implicit declaration of function ‘blk_name’; did you mean ‘basename’? [-Werror=implicit-function-declaration]

                blk_name(dinfo->bdrv), fl_sectors);
                ^~~~~~~~
  hw/mips/mips_malta.c:1273:16: error: nested extern declaration of ‘blk_name’ [-Werror=nested-externs]
  hw/mips/mips_malta.c:1273:30: error: ‘DriveInfo’ {aka ‘struct DriveInfo’} has no member named ‘bdrv’
                blk_name(dinfo->bdrv), fl_sectors);
                                ^~
Fixes fa1d36df746
---
 hw/mips/mips_malta.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
hw/mips/mips_malta.c +2 -1
index 2827074e9b..b4cd8f02ad 100644
@@ -40,6 +40,7 @@
 #include "hw/pci/pci.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/arch_init.h"
+#include "sysemu/block-backend.h"
 #include "qemu/log.h"
 #include "hw/mips/bios.h"
 #include "hw/ide.h"
@@ -1205,6 +1206,7 @@ void mips_malta_init(MachineState *machine)
     qemu_irq cbus_irq, i8259_irq;
     int piix4_devfn;
     I2CBus *smbus;
+    BlockBackend *pflash_blk = NULL;
     DriveInfo *dinfo;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     int fl_idx = 0;
@@ -1265,17 +1267,18 @@ void mips_malta_init(MachineState *machine)
 
     /* Load firmware in flash / BIOS. */
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
-#ifdef DEBUG_BOARD_INIT
     if (dinfo) {

hw/mips/mips_malta.c void mips_malta_init(MachineState *machine) · line 1276

Quoted 10 lines
hw/mips/mips_malta.c +5 -4
+        pflash_blk = blk_by_legacy_dinfo(dinfo);
+#ifdef DEBUG_BOARD_INIT
         printf("Register parallel flash %d size " TARGET_FMT_lx " at "
-               "addr %08llx '%s' %x\n",
-               fl_idx, bios_size, FLASH_ADDRESS,
-               blk_name(dinfo->bdrv), fl_sectors);
-    }
+               "addr %08llx '%s'\n",
+               fl_idx, blk_getlength(pflash_blk), FLASH_ADDRESS,
+               blk_name(pflash_blk));

You stop printing @fl_sectors. Intentional?

Would the next patch be a better fit?

hw/mips/mips_malta.c void mips_malta_init(MachineState *machine) · line 1284

Quoted 9 lines
hw/mips/mips_malta.c +2 -1
 #endif
+    }
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
                                BIOS_SIZE,
-                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
+                               pflash_blk,
                                65536, fl_sectors,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
     bios = pflash_cfi01_get_memory(fl);

We should probably join lines here.

#3 lore raw

Re: [Qemu-devel] [PATCH 1/5] hw/mips/malta: Fix the DEBUG_BOARD_INIT code

In reply to Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé

Commit fa1d36df746 missed to convert this ifdef'ed out code. Introduce the pflash_blk variable.

This fixes:

hw/mips/mips_malta.c:1273:16: error: implicit declaration of function ‘blk_name’; did you mean ‘basename’? [-Werror=implicit-function-declaration]

                blk_name(dinfo->bdrv), fl_sectors);
                ^~~~~~~~
  hw/mips/mips_malta.c:1273:16: error: nested extern declaration of ‘blk_name’ [-Werror=nested-externs]
  hw/mips/mips_malta.c:1273:30: error: ‘DriveInfo’ {aka ‘struct DriveInfo’} has no member named ‘bdrv’
                blk_name(dinfo->bdrv), fl_sectors);
                                ^~
Quoted 2 lines
Fixes fa1d36df746

Question for the maintainers: Aurelien, Aleksandar, fix the DEBUG_BOARD_INIT code or drop it? It looks rather stale...

#4 lore raw

Re: [Qemu-devel] [PATCH 1/5] hw/mips/malta: Fix the DEBUG_BOARD_INIT code

Quoted 18 lines

From: Markus Armbruster <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 1/5] hw/mips/malta: Fix the DEBUG_BOARD_INIT code

Quoted 13 lines · Philippe Mathieu-Daudé

Commit fa1d36df746 missed to convert this ifdef'ed out code. Introduce the pflash_blk variable.

This fixes:

   hw/mips/mips_malta.c:1273:16: error: implicit declaration of function ‘blk_name’; did you mean ‘basename’? [-Werror=implicit-function-declaration]
                blk_name(dinfo->bdrv), fl_sectors);
                ^~~~~~~~
  hw/mips/mips_malta.c:1273:16: error: nested extern declaration of ‘blk_name’ [-Werror=nested-externs]
  hw/mips/mips_malta.c:1273:30: error: ‘DriveInfo’ {aka ‘struct DriveInfo’} has no member named ‘bdrv’
                blk_name(dinfo->bdrv), fl_sectors);
                                ^~
Quoted 5 lines
Quoted 2 lines
Fixes fa1d36df746

Question for the maintainers: Aurelien, Aleksandar, fix the DEBUG_BOARD_INIT code or drop it? It looks rather stale...

Markus,

My vote is: drop it.

And, Markus, yes, if you agree with any patch from this series, please let them all go though your pull request.

Regards,
Aleksandar

#5 lore raw

Re: [Qemu-devel] [PATCH 1/5] hw/mips/malta: Fix the DEBUG_BOARD_INIT code

Quoted 28 lines
Quoted 14 lines

From: Markus Armbruster <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 1/5] hw/mips/malta: Fix the DEBUG_BOARD_INIT code

Quoted 9 lines · Philippe Mathieu-Daudé

Commit fa1d36df746 missed to convert this ifdef'ed out code. Introduce the pflash_blk variable.

This fixes:

   hw/mips/mips_malta.c:1273:16: error: implicit declaration of function ‘blk_name’; > did you mean ‘basename’? [-Werror=implicit-function-declaration]
                blk_name(dinfo->bdrv), fl_sectors);
                ^~~~~~~~

hw/mips/mips_malta.c:1273:16: error: nested extern declaration of ‘blk_name’

[-Werror=nested-externs]

Quoted 1 line
Quoted 1 line

hw/mips/mips_malta.c:1273:30: error: ‘DriveInfo’ {aka ‘struct DriveInfo’} has no

member named ‘bdrv’

Quoted 8 lines
Quoted 5 lines
                blk_name(dinfo->bdrv), fl_sectors);
                                ^~
Fixes fa1d36df746

Question for the maintainers: Aurelien, Aleksandar, fix the DEBUG_BOARD_INIT code or drop it? It looks rather stale...

Markus,

Quoted 7 lines

My vote is: drop it.

And, Markus, yes, if you agree with any patch from this series, please let them all go > though your pull request.

Regards,
Aleksandar

Markus, if you decide to drop the code segment, you have my

in advance.

I believe the whole patch series was also reviewed by Richard.

Sincerely,
Aleksandar

#6 lore raw

PATCH 2/5 hw/mips/malta: Remove fl_sectors variable (used one single time)

In reply to Philippe Mathieu-Daudé

fl_sectors is only used in one place, with bios_size = FLASH_SIZE. Use it directly and remove the variable.

---
 hw/mips/mips_malta.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/mips/mips_malta.c +1 -2
index b4cd8f02ad..00e5aac98b 100644
@@ -1210,7 +1210,6 @@ void mips_malta_init(MachineState *machine)
     DriveInfo *dinfo;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     int fl_idx = 0;
-    int fl_sectors = bios_size >> 16;
     int be;
 
     DeviceState *dev = qdev_create(NULL, TYPE_MIPS_MALTA);
@@ -1279,7 +1278,7 @@ void mips_malta_init(MachineState *machine)
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
                                BIOS_SIZE,
                                pflash_blk,
-                               65536, fl_sectors,
+                               65536, FLASH_SIZE >> 16,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
     bios = pflash_cfi01_get_memory(fl);
     fl_idx++;
Signature · 1 line
2.20.1
#7 lore raw

PATCH 3/5 hw/mips/malta: Restrict 'bios_size' variable scope

In reply to Philippe Mathieu-Daudé

The 'bios_size' variable is only used in the 'if (!kernel_filename && !dinfo)' clause. This is the case when we don't provide -pflash command line option, and also don't provide a -kernel option. In this case we will check for the -bios option, or use the default BIOS_FILENAME file.

The 'bios' term is valid in this if statement, but is confuse in the whole mips_malta_init() scope. Restrict his scope.

---
 hw/mips/mips_malta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/mips/mips_malta.c +1 -1
index 00e5aac98b..396645b1a9 100644
@@ -1196,7 +1196,6 @@ void mips_malta_init(MachineState *machine)
     MemoryRegion *ram_low_preio = g_new(MemoryRegion, 1);
     MemoryRegion *ram_low_postio;
     MemoryRegion *bios, *bios_copy = g_new(MemoryRegion, 1);
-    target_long bios_size = FLASH_SIZE;
     const size_t smbus_eeprom_size = 8 * 256;
     uint8_t *smbus_eeprom_buf = g_malloc0(smbus_eeprom_size);
     int64_t kernel_entry, bootloader_run_addr;
@@ -1314,6 +1313,7 @@ void mips_malta_init(MachineState *machine)
                              bootloader_run_addr, kernel_entry);
         }
     } else {
+        target_long bios_size = FLASH_SIZE;
         /* The flash region isn't executable from a KVM guest */
         if (kvm_enabled()) {
             error_report("KVM enabled but no -kernel argument was specified. "
Signature · 1 line
2.20.1
#8 lore raw

PATCH 4/5 hw/mips/malta: Only accept 'monitor' pflash of 4MiB

In reply to Philippe Mathieu-Daudé

The Malta 'mother' board can use various 'daughter' core cards [1]. QEMU only models the CoreLV card.

The CoreLV card provides [2] a Galileo GT64120 as North bridge, connecting the CPU via the 'CBUS'. The CBUS also connects a 'Monitor flash' memory and maps it to the CPU RESET vector.
The Monitor flash size is exactly 4 MiB.
Refuse Monitor pflash of different size.

[1] https://www.linux-mips.org/wiki/MIPS_Malta#Core_cards
[2] "Malta User's Manual" rev. 01.05 (MIPS Technologies doc number: MD00048)

---
 hw/mips/mips_malta.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/mips/mips_malta.c +5 -0
index 396645b1a9..04788ff50a 100644
@@ -1267,6 +1267,11 @@ void mips_malta_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
     if (dinfo) {
         pflash_blk = blk_by_legacy_dinfo(dinfo);
+
+        if (blk_getlength(pflash_blk) != FLASH_SIZE) {
+                error_report("Malta CoreLV card expects a bios of 4MB");
+                exit(1);
+        }
 #ifdef DEBUG_BOARD_INIT
         printf("Register parallel flash %d size " TARGET_FMT_lx " at "
                "addr %08llx '%s'\n",
Signature · 1 line
2.20.1
#9 lore raw

Re: [Qemu-devel] [PATCH 4/5] hw/mips/malta: Only accept 'monitor' pflash of 4MiB

hw/mips/mips_malta.c void mips_malta_init(MachineState *machine) · line 1274

Quoted 5 lines · Philippe Mathieu-Daudé
hw/mips/mips_malta.c +5 -0
+
+        if (blk_getlength(pflash_blk) != FLASH_SIZE) {
+                error_report("Malta CoreLV card expects a bios of 4MB");
+                exit(1);
+        }

Indentation is off, somehow. Tabs or extra spaces?

r~

#10 lore raw

Re: [Qemu-devel] [PATCH 4/5] hw/mips/malta: Only accept 'monitor' pflash of 4MiB

Quoted 8 lines · Richard Henderson

hw/mips/mips_malta.c void mips_malta_init(MachineState *machine) · line 1274

Quoted 5 lines · Philippe Mathieu-Daudé
hw/mips/mips_malta.c +5 -0
+
+        if (blk_getlength(pflash_blk) != FLASH_SIZE) {
+                error_report("Malta CoreLV card expects a bios of 4MB");
+                exit(1);
+        }

Indentation is off, somehow. Tabs or extra spaces?

Oops... Probably extra spaces, since checkpatch didn't complain.

I'll let Markus fix this if it takes this series ;)

Thanks!

Phil.

#11 lore raw

Re: [Qemu-devel] [PATCH 4/5] hw/mips/malta: Only accept 'monitor' pflash of 4MiB

In reply to Philippe Mathieu-Daudé
Quoted 23 lines · Philippe Mathieu-Daudé

The Malta 'mother' board can use various 'daughter' core cards [1]. QEMU only models the CoreLV card.

The CoreLV card provides [2] a Galileo GT64120 as North bridge, connecting the CPU via the 'CBUS'. The CBUS also connects a 'Monitor flash' memory and maps it to the CPU RESET vector.
The Monitor flash size is exactly 4 MiB.
Refuse Monitor pflash of different size.

[1] https://www.linux-mips.org/wiki/MIPS_Malta#Core_cards
[2] "Malta User's Manual" rev. 01.05 (MIPS Technologies doc number: MD00048)

---
 hw/mips/mips_malta.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/mips/mips_malta.c +0 -0
index 396645b1a9..04788ff50a 100644
@@ -1267,6 +1267,11 @@ void mips_malta_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);

hw/mips/mips_malta.c void mips_malta_init(MachineState *machine) · line 1277

Quoted 10 lines
hw/mips/mips_malta.c +5 -0
     if (dinfo) {
         pflash_blk = blk_by_legacy_dinfo(dinfo);
+
+        if (blk_getlength(pflash_blk) != FLASH_SIZE) {
+                error_report("Malta CoreLV card expects a bios of 4MB");
+                exit(1);
+        }
 #ifdef DEBUG_BOARD_INIT
         printf("Register parallel flash %d size " TARGET_FMT_lx " at "
                "addr %08llx '%s'\n",

I'm in favor of insisting on image size matching flash size, but I'd rather do it in generic code.

We're already rejecting undersized images, with a sub-optimal error message. We're silently ignoring the tail of oversized images. Alex proposed a patch to generic code that does three things:

* We reject an undersized image with a sub-optimal error message. Improve that message.

* We silently ignore an oversized image's tail. Warn instead.

* As a convenience feature, don't reject undersized read-only image, but pad it with 0xff instead, to simulate (1) above.

[v5] hw/block: better reporting on pflash backing file mismatch
Message-Id: <[email protected]>

I asked for the convenience feature split off into its own patch (and offered to do it).

If we accept Alex's work (split or not), your patch merely kills the convenience feature for this board. I like killing it --- I consider it a bad idea --- but if that's not in the cards, then I prefer all boards to implement the same set of bad ideas.

#12 lore raw

PATCH 5/5 mips_malta: Clean up definition of flash memory size somewhat

In reply to Philippe Mathieu-Daudé

From: Markus Armbruster <[email protected]>

pflash_cfi01_register() takes a size in bytes, a block size in bytes and a number of blocks. mips_malta_init() passes BIOS_SIZE, 65536, FLASH_SIZE >> 16. Actually consistent only because BIOS_SIZE (defined in include/hw/mips/bios.h as (4 * MiB)) matches FLASH_SIZE (defined locally as 0x400000). Confusing all the same.

Pass FLASH_SIZE instead of BIOS_SIZE.

Cc Aurelien Jarno <[email protected]>
Cc Aleksandar Rikalo <[email protected]>
[PMD: rebased]
---
 hw/mips/mips_malta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/mips/mips_malta.c +1 -1
index 04788ff50a..a5726edaa7 100644
@@ -1280,7 +1280,7 @@ void mips_malta_init(MachineState *machine)
 #endif
     }
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
-                               BIOS_SIZE,
+                               FLASH_SIZE,
                                pflash_blk,
                                65536, FLASH_SIZE >> 16,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
Signature · 1 line
2.20.1
author Reviewed-by Alex Bennée on v1 5/5
#13 lore raw

Re: [Qemu-devel] [PATCH 5/5] mips_malta: Clean up definition of flash memory size somewhat

Quoted 8 lines · Philippe Mathieu-Daudé

From: Markus Armbruster <[email protected]>

pflash_cfi01_register() takes a size in bytes, a block size in bytes and a number of blocks. mips_malta_init() passes BIOS_SIZE, 65536, FLASH_SIZE >> 16. Actually consistent only because BIOS_SIZE (defined in include/hw/mips/bios.h as (4 * MiB)) matches FLASH_SIZE (defined locally as 0x400000). Confusing all the same.

Quoted 5 lines

Pass FLASH_SIZE instead of BIOS_SIZE.

Cc Aurelien Jarno <[email protected]>
Cc Aleksandar Rikalo <[email protected]>

I forgot here:

Quoted 20 lines
---
 hw/mips/mips_malta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/mips/mips_malta.c +1 -1
index 04788ff50a..a5726edaa7 100644
@@ -1280,7 +1280,7 @@ void mips_malta_init(MachineState *machine)
 #endif
     }
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
-                               BIOS_SIZE,
+                               FLASH_SIZE,
                                pflash_blk,
                                65536, FLASH_SIZE >> 16,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
Reviewed-by on the v1 series
#14 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Markus Armbruster (1):
mips_malta: Clean up definition of flash memory size somewhat

Philippe Mathieu-Daudé (4):
hw/mips/malta: Fix the DEBUG_BOARD_INIT code hw/mips/malta: Remove fl_sectors variable (used one single time) hw/mips/malta: Restrict 'bios_size' variable scope hw/mips/malta: Only accept 'monitor' pflash of 4MiB

 hw/mips/mips_malta.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

r~

#15 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Hi Markus,

this is a rework of your 'mips_malta: Clean up definition of flash memory size somewhat' patch:
https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07177.html

Regards,

Phil.

Philippe,

Could you summarize end-user-visible changes resulting from this series?

Aleksandar

Quoted 19 lines

Based-on: <[email protected]>

Markus Armbruster (1):
mips_malta: Clean up definition of flash memory size somewhat

Philippe Mathieu-Daudé (4):
hw/mips/malta: Fix the DEBUG_BOARD_INIT code hw/mips/malta: Remove fl_sectors variable (used one single time) hw/mips/malta: Restrict 'bios_size' variable scope hw/mips/malta: Only accept 'monitor' pflash of 4MiB

 hw/mips/mips_malta.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

--
2.20.1

#16 lore raw

Hi Aleksandar,

Quoted 10 lines · Aleksandar Markovic

On Tuesday, March 5, 2019, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

Hi Markus,

this is a rework of your 'mips_malta: Clean up definition of flash memory size somewhat' patch:
https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07177.html
<https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07177.html>

Quoted 8 lines

Regards,

Phil.

Philippe,

Could you summarize end-user-visible changes resulting from this series?

Good maintainer reflex :)

There is an end-user visible change, if he provides a file that is not exactly 4MiB he will now get a "Malta CoreLV card expects a bios of 4MB" error message and QEMU will exit to his shell. This change is introduced by patch 4/5.

Now I rather expect this series to get integrated in Markus current work, because his subsequent patches change the PFlash API and it is easier he takes this (to avoid merge conflicts).

Note: Markus series is expected to include the following patch from Alex Bennée: "hw/block: better reporting on pflash backing file mismatch"
https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07341.html
which is a more important user visible change. I think the the changelog can be updated once, by Markus :)

Meanwhile, if this series is taken by Markus can I have your Ack-by?

Thanks,

Phil.

#17 lore raw
Quoted 24 lines · Philippe Mathieu-Daudé

Hi Aleksandar,

Quoted 10 lines · Aleksandar Markovic

On Tuesday, March 5, 2019, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

Hi Markus,

this is a rework of your 'mips_malta: Clean up definition of flash memory size somewhat' patch:
https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07177.html
<https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07177.html>

Quoted 8 lines

Regards,

Phil.

Philippe,

Could you summarize end-user-visible changes resulting from this series?

Good maintainer reflex :)

Quoted 8 lines

There is an end-user visible change, if he provides a file that is not exactly 4MiB he will now get a "Malta CoreLV card expects a bios of 4MB" error message and QEMU will exit to his shell. This change is introduced by patch 4/5.

Now I rather expect this series to get integrated in Markus current work, because his subsequent patches change the PFlash API and it is easier he takes this (to avoid merge conflicts).

Definitely.

Quoted 5 lines

Note: Markus series is expected to include the following patch from Alex Bennée: "hw/block: better reporting on pflash backing file mismatch"
https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07341.html
which is a more important user visible change. I think the the changelog can be updated once, by Markus :)

Yes.

Quoted 5 lines

Meanwhile, if this series is taken by Markus can I have your Ack-by?

Thanks,

Phil.

#18 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

Hi Markus,

this is a rework of your 'mips_malta: Clean up definition of flash memory size somewhat' patch:
https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07177.html

Diff between my patch and your series:

hw/mips/mips_malta.c +2 -2
index 9ade9b194c..2827074e9b 100644
@@ -1269,12 +1269,12 @@ void mips_malta_init(MachineState *machine)
     if (dinfo) {
         printf("Register parallel flash %d size " TARGET_FMT_lx " at "
                "addr %08llx '%s' %x\n",
-               fl_idx, FLASH_SIZE, FLASH_ADDRESS,
+               fl_idx, bios_size, FLASH_ADDRESS,
                blk_name(dinfo->bdrv), fl_sectors);
     }
 #endif
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
-                               FLASH_SIZE,
+                               BIOS_SIZE,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                65536, fl_sectors,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);

We have in include/hw/mips/bios.h

    #define BIOS_SIZE (4 * MiB)

and locally

    #define FLASH_SIZE    0x400000

    target_long bios_size = FLASH_SIZE;

Three names for the same value. Therefore, there's no functional difference, just more cleanup. Good to know.

#19 lore raw
Quoted 33 lines · Markus Armbruster
Quoted 4 lines · Philippe Mathieu-Daudé

Hi Markus,

this is a rework of your 'mips_malta: Clean up definition of flash memory size somewhat' patch:
https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg07177.html

Diff between my patch and your series:

hw/mips/mips_malta.c +2 -2
index 9ade9b194c..2827074e9b 100644
@@ -1269,12 +1269,12 @@ void mips_malta_init(MachineState *machine)
     if (dinfo) {
         printf("Register parallel flash %d size " TARGET_FMT_lx " at "
                "addr %08llx '%s' %x\n",
-               fl_idx, FLASH_SIZE, FLASH_ADDRESS,
+               fl_idx, bios_size, FLASH_ADDRESS,
                blk_name(dinfo->bdrv), fl_sectors);
     }
 #endif
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
-                               FLASH_SIZE,
+                               BIOS_SIZE,
                                dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
                                65536, fl_sectors,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);

We have in include/hw/mips/bios.h

    #define BIOS_SIZE (4 * MiB)
Quoted 8 lines

and locally

    #define FLASH_SIZE    0x400000

    target_long bios_size = FLASH_SIZE;

Three names for the same value. Therefore, there's no functional difference, just more cleanup. Good to know.

Wrong diff, sorry.

hw/mips/mips_malta.c +16 -9
index 9ade9b194c..a5726edaa7 100644
@@ -40,6 +40,7 @@
 #include "hw/pci/pci.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/arch_init.h"
+#include "sysemu/block-backend.h"
 #include "qemu/log.h"
 #include "hw/mips/bios.h"
 #include "hw/ide.h"
@@ -1195,7 +1196,6 @@ void mips_malta_init(MachineState *machine)
     MemoryRegion *ram_low_preio = g_new(MemoryRegion, 1);
     MemoryRegion *ram_low_postio;
     MemoryRegion *bios, *bios_copy = g_new(MemoryRegion, 1);
-    target_long bios_size = FLASH_SIZE;
     const size_t smbus_eeprom_size = 8 * 256;
     uint8_t *smbus_eeprom_buf = g_malloc0(smbus_eeprom_size);
     int64_t kernel_entry, bootloader_run_addr;
@@ -1205,10 +1205,10 @@ void mips_malta_init(MachineState *machine)
     qemu_irq cbus_irq, i8259_irq;
     int piix4_devfn;
     I2CBus *smbus;
+    BlockBackend *pflash_blk = NULL;
     DriveInfo *dinfo;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     int fl_idx = 0;
-    int fl_sectors = bios_size >> 16;
     int be;
 
     DeviceState *dev = qdev_create(NULL, TYPE_MIPS_MALTA);
@@ -1265,18 +1265,24 @@ void mips_malta_init(MachineState *machine)
 
     /* Load firmware in flash / BIOS. */
     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
-#ifdef DEBUG_BOARD_INIT
     if (dinfo) {
+        pflash_blk = blk_by_legacy_dinfo(dinfo);
+
+        if (blk_getlength(pflash_blk) != FLASH_SIZE) {
+                error_report("Malta CoreLV card expects a bios of 4MB");
+                exit(1);
+        }
+#ifdef DEBUG_BOARD_INIT
         printf("Register parallel flash %d size " TARGET_FMT_lx " at "
-               "addr %08llx '%s' %x\n",
-               fl_idx, FLASH_SIZE, FLASH_ADDRESS,
-               blk_name(dinfo->bdrv), fl_sectors);
-    }
+               "addr %08llx '%s'\n",
+               fl_idx, blk_getlength(pflash_blk), FLASH_ADDRESS,
+               blk_name(pflash_blk));
 #endif
+    }
     fl = pflash_cfi01_register(FLASH_ADDRESS, NULL, "mips_malta.bios",
                                FLASH_SIZE,
-                               dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-                               65536, fl_sectors,
+                               pflash_blk,
+                               65536, FLASH_SIZE >> 16,
                                4, 0x0000, 0x0000, 0x0000, 0x0000, be);
     bios = pflash_cfi01_get_memory(fl);
     fl_idx++;
@@ -1312,6 +1318,7 @@ void mips_malta_init(MachineState *machine)
                              bootloader_run_addr, kernel_entry);
         }
     } else {
+        target_long bios_size = FLASH_SIZE;
         /* The flash region isn't executable from a KVM guest */
         if (kvm_enabled()) {
             error_report("KVM enabled but no -kernel argument was specified. "