Skip to contentSkip to conversation

use sizes.h macros for power-of-two sizes

RFC Superseded Antony Pavlov 5 participants 8 messages Sep 4, 2013 – Sep 9, 2013

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

RFC 1/2 include/: import sizes.h from barebox

In reply to Antony Pavlov

The header file sizes.h is used in linux kernel, barebox bootloader and u-boot bootloader. It provides the short and easy-to-read names for power-of-two numbers. The numbers like this are othen used for memory range sizes.

This commits imports the sizes.h from barebox bootloader source code (see
http://git.pengutronix.de/?p=barebox.git;a=blob;f=include/sizes.h)
but not his twin from linux as the barebox header file is more neutral and has neither barebox mention nor linux mention.

---
 include/sizes.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 include/sizes.h
include/sizes.h new file +48 -0
new file mode 100644
index 0000000..aa0fbdc
@@ -0,0 +1,48 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307	 USA
+ */
+/*  Size defintions
+ *  Copyright (C) ARM Limited 1998. All rights reserved.
+ */
+
+#ifndef __sizes_h
+#define __sizes_h			1
+
+/* handy sizes */
+#define SZ_1K				0x00000400
+#define SZ_4K				0x00001000
+#define SZ_8K				0x00002000
+#define SZ_16K				0x00004000
+#define SZ_32K				0x00008000
+#define SZ_64K				0x00010000
+#define SZ_128K				0x00020000
+#define SZ_256K				0x00040000
+#define SZ_512K				0x00080000
+
+#define SZ_1M				0x00100000
+#define SZ_2M				0x00200000
+#define SZ_4M				0x00400000
+#define SZ_8M				0x00800000
+#define SZ_16M				0x01000000
+#define SZ_32M				0x02000000
+#define SZ_64M				0x04000000
+#define SZ_128M				0x08000000
+#define SZ_256M				0x10000000
+#define SZ_512M				0x20000000
+
+#define SZ_1G				0x40000000
+#define SZ_2G				0x80000000
+
+#endif	/* __sizes_h */
Signature · 1 line
1.8.4.rc3
#0 lore raw

cover use sizes.h macros for power-of-two sizes

[RFC 1/2] include/: import sizes.h from barebox [RFC 2/2] hw/mips: use sizes.h macros

The sizes.h macros is a easy-to-read method of power-of-two memory sizes representation. The sizes.h macros are actively used in linux kernel and other projects, so let's use them in QEMU too.

#6 lore raw

RFC 2/2 hw/mips: use sizes.h macros

---
 hw/mips/mips_malta.c   | 3 ++-
 include/hw/mips/bios.h | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/mips/mips_malta.c +2 -1
index ae0921c..7e8978b 100644
@@ -51,6 +51,7 @@
 #include "sysemu/qtest.h"
 #include "qemu/error-report.h"
 #include "hw/empty_slot.h"
+#include "sizes.h"
 
 //#define DEBUG_BOARD_INIT
 
@@ -63,7 +64,7 @@
 #define FPGA_ADDRESS  0x1f000000ULL
 #define RESET_ADDRESS 0x1fc00000ULL
 
-#define FLASH_SIZE    0x400000
+#define FLASH_SIZE    SZ_4M
 
 #define MAX_IDE_BUS 2
 
include/hw/mips/bios.h +2 -1
index b4b88ac..e744425 100644
@@ -1,6 +1,7 @@
 #include "cpu.h"
+#include "sizes.h"
 
-#define BIOS_SIZE (4 * 1024 * 1024)
+#define BIOS_SIZE SZ_4M
 #ifdef TARGET_WORDS_BIGENDIAN
 #define BIOS_FILENAME "mips_bios.bin"
 #else
Signature · 1 line
1.8.4.rc3
#2 lore raw

Re: [Qemu-devel] [RFC 1/2] include/: import sizes.h from barebox

In reply to Antony Pavlov

include/sizes.h

Quoted 24 lines · Antony Pavlov

The header file sizes.h is used in linux kernel, barebox bootloader and u-boot bootloader. It provides the short and easy-to-read names for power-of-two numbers. The numbers like this are othen used for memory range sizes.

This commits imports the sizes.h from barebox bootloader source code (see
http://git.pengutronix.de/?p=barebox.git;a=blob;f=include/sizes.h)
but not his twin from linux as the barebox header file is more neutral and has neither barebox mention nor linux mention.

---
 include/sizes.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 include/sizes.h
include/sizes.h new file +0 -0
new file mode 100644
index 0000000..aa0fbdc

I am not sure it is the correct location. Paolo, can you please look at that?

Quoted 12 lines
include/sizes.h new file +11 -0
@@ -0,0 +1,48 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
+ * GNU General Public License for more details.
+ *

include/sizes.h line 21

Quoted 10 lines
include/sizes.h new file +10 -0
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307	 USA
+ */
+/*  Size defintions
+ *  Copyright (C) ARM Limited 1998. All rights reserved.
+ */
+
+#ifndef __sizes_h
+#define __sizes_h			1

I think this should be in upper case, prefixed with QEMU_ or _QEMU.

Quoted 27 lines
include/sizes.h new file +27 -0
+
+/* handy sizes */
+#define SZ_1K				0x00000400
+#define SZ_4K				0x00001000
+#define SZ_8K				0x00002000
+#define SZ_16K				0x00004000
+#define SZ_32K				0x00008000
+#define SZ_64K				0x00010000
+#define SZ_128K				0x00020000
+#define SZ_256K				0x00040000
+#define SZ_512K				0x00080000
+
+#define SZ_1M				0x00100000
+#define SZ_2M				0x00200000
+#define SZ_4M				0x00400000
+#define SZ_8M				0x00800000
+#define SZ_16M				0x01000000
+#define SZ_32M				0x02000000
+#define SZ_64M				0x04000000
+#define SZ_128M				0x08000000
+#define SZ_256M				0x10000000
+#define SZ_512M				0x20000000
+
+#define SZ_1G				0x40000000
+#define SZ_2G				0x80000000
+
+#endif	/* __sizes_h */
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
Reviewed-by on v1 2/2
#7 lore raw

Re: [Qemu-devel] [RFC 2/2] hw/mips: use sizes.h macros

In reply to Antony Pavlov
Quoted 32 lines · Antony Pavlov
---
 hw/mips/mips_malta.c   | 3 ++-
 include/hw/mips/bios.h | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/mips/mips_malta.c +2 -1
index ae0921c..7e8978b 100644
@@ -51,6 +51,7 @@
 #include "sysemu/qtest.h"
 #include "qemu/error-report.h"
 #include "hw/empty_slot.h"
+#include "sizes.h"
 
 //#define DEBUG_BOARD_INIT
 
@@ -63,7 +64,7 @@
 #define FPGA_ADDRESS  0x1f000000ULL
 #define RESET_ADDRESS 0x1fc00000ULL
 
-#define FLASH_SIZE    0x400000
+#define FLASH_SIZE    SZ_4M
 
 #define MAX_IDE_BUS 2
 
include/hw/mips/bios.h +0 -0
index b4b88ac..e744425 100644

include/hw/mips/bios.h line 7

Quoted 8 lines
include/hw/mips/bios.h +2 -1
@@ -1,6 +1,7 @@
 #include "cpu.h"
+#include "sizes.h"
 
-#define BIOS_SIZE (4 * 1024 * 1024)
+#define BIOS_SIZE SZ_4M
 #ifdef TARGET_WORDS_BIGENDIAN
 #define BIOS_FILENAME "mips_bios.bin"
 #else

Besides the comments from the previous patch:

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#3 lore raw

Re: [Qemu-devel] [RFC 1/2] include/: import sizes.h from barebox

In reply to Aurelien Jarno

Il 09/09/2013 19:32, Aurelien Jarno ha scritto:

Quoted 20 lines · Antony Pavlov
Quoted 19 lines

The header file sizes.h is used in linux kernel, barebox bootloader and u-boot bootloader. It provides the short and easy-to-read names for power-of-two numbers. The numbers like this are othen used for memory range sizes.

This commits imports the sizes.h from barebox bootloader source code (see
http://git.pengutronix.de/?p=barebox.git;a=blob;f=include/sizes.h)
but not his twin from linux as the barebox header file is more neutral and has neither barebox mention nor linux mention.

---
 include/sizes.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 include/sizes.h
Quoted 7 lines

include/sizes.h

Quoted 5 lines
include/sizes.h new file +0 -0
new file mode 100644
index 0000000..aa0fbdc

I am not sure it is the correct location. Paolo, can you please look at that?

Yeah, probably should be include/qemu. (For a good reason---to not conflict with /usr/include/sizes.h that anyone might have installed).

Paolo

Quoted 55 lines
Quoted 12 lines
include/sizes.h new file +11 -0
@@ -0,0 +1,48 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
+ * GNU General Public License for more details.
+ *

include/sizes.h line 21

Quoted 10 lines
include/sizes.h new file +10 -0
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307	 USA
+ */
+/*  Size defintions
+ *  Copyright (C) ARM Limited 1998. All rights reserved.
+ */
+
+#ifndef __sizes_h
+#define __sizes_h			1

I think this should be in upper case, prefixed with QEMU_ or _QEMU.

Quoted 27 lines
include/sizes.h new file +27 -0
+
+/* handy sizes */
+#define SZ_1K				0x00000400
+#define SZ_4K				0x00001000
+#define SZ_8K				0x00002000
+#define SZ_16K				0x00004000
+#define SZ_32K				0x00008000
+#define SZ_64K				0x00010000
+#define SZ_128K				0x00020000
+#define SZ_256K				0x00040000
+#define SZ_512K				0x00080000
+
+#define SZ_1M				0x00100000
+#define SZ_2M				0x00200000
+#define SZ_4M				0x00400000
+#define SZ_8M				0x00800000
+#define SZ_16M				0x01000000
+#define SZ_32M				0x02000000
+#define SZ_64M				0x04000000
+#define SZ_128M				0x08000000
+#define SZ_256M				0x10000000
+#define SZ_512M				0x20000000
+
+#define SZ_1G				0x40000000
+#define SZ_2G				0x80000000
+
+#endif	/* __sizes_h */
#4 lore raw

Re: [Qemu-devel] [RFC 1/2] include/: import sizes.h from barebox

In reply to Aurelien Jarno

Am 09.09.2013 19:32, schrieb Aurelien Jarno:

Quoted 10 lines · Antony Pavlov
Quoted 9 lines
include/sizes.h new file +8 -0
@@ -0,0 +1,48 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
Quoted 8 lines

include/sizes.h line 16

Quoted 8 lines
include/sizes.h new file +8 -0
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307	 USA
+ */
+/*  Size defintions

Is this the original comment? Then someone should send them a fix :-)

Quoted 7 lines

include/sizes.h line 21

Quoted 5 lines
include/sizes.h new file +5 -0
+ *  Copyright (C) ARM Limited 1998. All rights reserved.
+ */
+
+#ifndef __sizes_h
+#define __sizes_h			1

I think this should be in upper case, prefixed with QEMU_ or _QEMU.

Quoted 5 lines

include/sizes.h line 26

Quoted 5 lines
include/sizes.h new file +5 -0
+
+/* handy sizes */
+#define SZ_1K				0x00000400
+#define SZ_4K				0x00001000
+#define SZ_8K				0x00002000

What about replacing all tabs to spaces before importing code to QEMU? This improves QEMU compatibility without requiring too much additional efforts during initial import and later updates.

I'd really appreciate that.

Stefan

#5 lore raw

Re: [Qemu-devel] [RFC 1/2] include/: import sizes.h from barebox

In reply to Aurelien Jarno
Quoted 1 line · Aurelien Jarno
Quoted 1 line

+#define SZ_2G 0x80000000

At minimum this must have a U or LL suffix.

And if this one has the suffix, then for consistency the rest ought as well.

r~