All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 1/2] Move malloc_cache_aligned() to its own header
@ 2015-09-02 23:24 Simon Glass
  2015-09-02 23:24 ` [U-Boot] [PATCH v2 2/2] Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h header Simon Glass
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Simon Glass @ 2015-09-02 23:24 UTC (permalink / raw)
  To: u-boot

At present malloc.h is included everywhere since it recently was added to
common.h in this commit:

   4519668 mtd/nand/ubi: assortment of alignment fixes

This seems wasteful and unnecessary. We have been trying to trim down
common.h and put separate functions into separate header files and that
change goes in the opposite direction.

Move malloc_cache_aligned() to a new header so that this can be avoided.
The header would perhaps be better named as alignmem.h but it needs to be
included after common.h and people might be confused by this. With the name
memalign.h it fits nicely after malloc() in most cases.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 common/cmd_ubi.c             |  2 +-
 drivers/mtd/nand/nand_util.c |  1 +
 fs/ubifs/super.c             |  3 +++
 fs/ubifs/ubifs.c             |  2 ++
 include/common.h             |  9 ---------
 include/memalign.h           | 25 +++++++++++++++++++++++++
 lib/gzip.c                   |  1 +
 lib/zlib/zutil.c             |  4 +++-
 8 files changed, 36 insertions(+), 11 deletions(-)
 create mode 100644 include/memalign.h

diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c
index 10eea65..0460b4c 100644
--- a/common/cmd_ubi.c
+++ b/common/cmd_ubi.c
@@ -14,7 +14,7 @@
 #include <common.h>
 #include <command.h>
 #include <exports.h>
-
+#include <memalign.h>
 #include <nand.h>
 #include <onenand_uboot.h>
 #include <linux/mtd/mtd.h>
diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
index 21b4a61..71285b6 100644
--- a/drivers/mtd/nand/nand_util.c
+++ b/drivers/mtd/nand/nand_util.c
@@ -23,6 +23,7 @@
 #include <command.h>
 #include <watchdog.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <div64.h>
 
 #include <asm/errno.h>
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 0bf52db..41763a1 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -28,6 +28,9 @@
 #include <linux/writeback.h>
 #else
 
+#include <common.h>
+#include <malloc.h>
+#include <memalign.h>
 #include <linux/compat.h>
 #include <linux/stat.h>
 #include <linux/err.h>
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 4daa7fa..f7a0847 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -23,6 +23,8 @@
  *          Adrian Hunter
  */
 
+#include <common.h>
+#include <memalign.h>
 #include "ubifs.h"
 #include <u-boot/zlib.h>
 
diff --git a/include/common.h b/include/common.h
index c12f402..c48e5bc 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1060,15 +1060,6 @@ int cpu_release(int nr, int argc, char * const argv[]);
 #define DEFINE_CACHE_ALIGN_BUFFER(type, name, size)			\
 	DEFINE_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
 
-#ifndef __ASSEMBLY__
-#include <malloc.h>
-
-static inline void *malloc_cache_aligned(size_t size)
-{
-	return memalign(ARCH_DMA_MINALIGN, ALIGN(size, ARCH_DMA_MINALIGN));
-}
-#endif
-
 /*
  * check_member() - Check the offset of a structure member
  *
diff --git a/include/memalign.h b/include/memalign.h
new file mode 100644
index 0000000..f78b9dd
--- /dev/null
+++ b/include/memalign.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __ALIGNMEM_H
+#define __ALIGNMEM_H
+
+/*
+ * ARCH_DMA_MINALIGN is defined in asm/cache.h for each architecture.  It
+ * is used to align DMA buffers.
+ */
+#ifndef __ASSEMBLY__
+#include <asm/cache.h>
+
+#include <malloc.h>
+
+static inline void *malloc_cache_aligned(size_t size)
+{
+	return memalign(ARCH_DMA_MINALIGN, ALIGN(size, ARCH_DMA_MINALIGN));
+}
+#endif
+
+#endif /* __ALIGNMEM_H */
diff --git a/lib/gzip.c b/lib/gzip.c
index cd8e9fe..2c49e4e 100644
--- a/lib/gzip.c
+++ b/lib/gzip.c
@@ -10,6 +10,7 @@
 #include <command.h>
 #include <image.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <u-boot/zlib.h>
 #include "zlib/zutil.h"
 
diff --git a/lib/zlib/zutil.c b/lib/zlib/zutil.c
index 173a81d..227343e 100644
--- a/lib/zlib/zutil.c
+++ b/lib/zlib/zutil.c
@@ -43,7 +43,9 @@ void z_error (m)
  */
 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
 
-#ifndef __UBOOT__
+#ifdef __UBOOT__
+#include <malloc.h>
+#else
 #ifndef STDC
 extern voidp    malloc OF((uInt size));
 extern voidp    calloc OF((uInt items, uInt size));
-- 
2.5.0.457.gab17608

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2 2/2] Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h header
  2015-09-02 23:24 [U-Boot] [PATCH v2 1/2] Move malloc_cache_aligned() to its own header Simon Glass
@ 2015-09-02 23:24 ` Simon Glass
  2015-09-12 12:50   ` [U-Boot] [U-Boot, v2, " Tom Rini
  2015-09-03 11:08 ` [U-Boot] [PATCH v2 1/2] Move malloc_cache_aligned() to its own header Marcel Ziswiler
  2015-09-12 12:50 ` [U-Boot] [U-Boot, v2, " Tom Rini
  2 siblings, 1 reply; 5+ messages in thread
From: Simon Glass @ 2015-09-02 23:24 UTC (permalink / raw)
  To: u-boot

Now that we have a new header file for cache-aligned allocation, we should
move the stack-based allocation macro there also.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Add a new patch to move ALLOC_CACHE_ALIGN_BUFFER() to the new header

 board/raspberrypi/rpi/rpi.c   |  1 +
 board/samsung/common/misc.c   |  1 +
 common/cmd_usb.c              |  1 +
 common/env_fat.c              |  1 +
 common/env_mmc.c              |  1 +
 common/env_nand.c             |  1 +
 common/env_ubi.c              |  1 +
 common/usb.c                  |  1 +
 common/usb_hub.c              |  1 +
 common/usb_kbd.c              |  1 +
 common/usb_storage.c          |  1 +
 disk/part_dos.c               |  1 +
 disk/part_efi.c               |  1 +
 disk/part_mac.c               |  1 +
 drivers/block/ahci.c          |  1 +
 drivers/mmc/dw_mmc.c          |  1 +
 drivers/mmc/mmc.c             |  1 +
 drivers/mmc/rpmb.c            |  1 +
 drivers/mtd/nand/tegra_nand.c |  1 +
 drivers/net/e1000.c           |  1 +
 drivers/net/fec_mxc.c         |  1 +
 drivers/net/rtl8169.c         |  1 +
 drivers/spi/mxs_spi.c         |  1 +
 drivers/usb/eth/asix.c        |  1 +
 drivers/usb/eth/asix88179.c   |  1 +
 drivers/usb/eth/mcs7830.c     |  1 +
 drivers/usb/eth/smsc95xx.c    |  1 +
 drivers/usb/gadget/ether.c    |  1 +
 drivers/usb/gadget/f_thor.c   |  1 +
 drivers/usb/host/dwc2.c       |  1 +
 drivers/usb/host/ehci-hcd.c   |  1 +
 drivers/usb/host/ohci-hcd.c   |  1 +
 drivers/usb/host/usb-uclass.c |  1 +
 drivers/video/bcm2835.c       |  1 +
 fs/ext4/dev.c                 |  1 +
 fs/ext4/ext4_common.c         |  1 +
 fs/ext4/ext4_write.c          |  1 +
 fs/fat/fat.c                  |  1 +
 include/common.h              | 87 ----------------------------------------
 include/memalign.h            | 93 ++++++++++++++++++++++++++++++++++++++++++-
 40 files changed, 130 insertions(+), 88 deletions(-)

diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index d21750e..6d7be11 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -10,6 +10,7 @@
 #include <fdt_support.h>
 #include <fdt_simplefb.h>
 #include <lcd.h>
+#include <memalign.h>
 #include <mmc.h>
 #include <asm/gpio.h>
 #include <asm/arch/mbox.h>
diff --git a/board/samsung/common/misc.c b/board/samsung/common/misc.c
index f0d69d4..e0e2c48 100644
--- a/board/samsung/common/misc.c
+++ b/board/samsung/common/misc.c
@@ -12,6 +12,7 @@
 #include <errno.h>
 #include <version.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <linux/sizes.h>
 #include <asm/arch/cpu.h>
 #include <asm/gpio.h>
diff --git a/common/cmd_usb.c b/common/cmd_usb.c
index 6874af7..6bdbbc5 100644
--- a/common/cmd_usb.c
+++ b/common/cmd_usb.c
@@ -14,6 +14,7 @@
 #include <common.h>
 #include <command.h>
 #include <dm.h>
+#include <memalign.h>
 #include <asm/byteorder.h>
 #include <asm/unaligned.h>
 #include <part.h>
diff --git a/common/env_fat.c b/common/env_fat.c
index e4c8489..d79d864 100644
--- a/common/env_fat.c
+++ b/common/env_fat.c
@@ -13,6 +13,7 @@
 #include <environment.h>
 #include <linux/stddef.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <search.h>
 #include <errno.h>
 #include <fat.h>
diff --git a/common/env_mmc.c b/common/env_mmc.c
index 51e7707..9639822 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -12,6 +12,7 @@
 #include <environment.h>
 #include <linux/stddef.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <mmc.h>
 #include <search.h>
 #include <errno.h>
diff --git a/common/env_nand.c b/common/env_nand.c
index 92e0e05..b32eeac 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -19,6 +19,7 @@
 #include <environment.h>
 #include <linux/stddef.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <nand.h>
 #include <search.h>
 #include <errno.h>
diff --git a/common/env_ubi.c b/common/env_ubi.c
index 77bbfa6..e0dc5af 100644
--- a/common/env_ubi.c
+++ b/common/env_ubi.c
@@ -11,6 +11,7 @@
 #include <environment.h>
 #include <errno.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <search.h>
 #include <ubi_uboot.h>
 #undef crc32
diff --git a/common/usb.c b/common/usb.c
index fbaf8ec..700bfc3 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -29,6 +29,7 @@
 #include <common.h>
 #include <command.h>
 #include <dm.h>
+#include <memalign.h>
 #include <asm/processor.h>
 #include <linux/compiler.h>
 #include <linux/ctype.h>
diff --git a/common/usb_hub.c b/common/usb_hub.c
index 652a104..415b45c 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -26,6 +26,7 @@
 #include <command.h>
 #include <dm.h>
 #include <errno.h>
+#include <memalign.h>
 #include <asm/processor.h>
 #include <asm/unaligned.h>
 #include <linux/ctype.h>
diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index 0227024..95912f9 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -11,6 +11,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <stdio_dev.h>
 #include <asm/byteorder.h>
 
diff --git a/common/usb_storage.c b/common/usb_storage.c
index b978430..b390310 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -39,6 +39,7 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <mapmem.h>
+#include <memalign.h>
 #include <asm/byteorder.h>
 #include <asm/processor.h>
 #include <dm/device-internal.h>
diff --git a/disk/part_dos.c b/disk/part_dos.c
index cf1a36e..89263d3 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -17,6 +17,7 @@
 #include <common.h>
 #include <command.h>
 #include <ide.h>
+#include <memalign.h>
 #include "part_dos.h"
 
 #ifdef HAVE_BLOCK_DEVICE
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 5856f93..15627f2 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -16,6 +16,7 @@
 #include <ide.h>
 #include <inttypes.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <part_efi.h>
 #include <linux/ctype.h>
 
diff --git a/disk/part_mac.c b/disk/part_mac.c
index cbcb995..099e0a0 100644
--- a/disk/part_mac.c
+++ b/disk/part_mac.c
@@ -15,6 +15,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <memalign.h>
 #include <ide.h>
 #include "part_mac.h"
 
diff --git a/drivers/block/ahci.c b/drivers/block/ahci.c
index 0d19dd2..82c6843 100644
--- a/drivers/block/ahci.c
+++ b/drivers/block/ahci.c
@@ -15,6 +15,7 @@
 #include <asm/errno.h>
 #include <asm/io.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <scsi.h>
 #include <libata.h>
 #include <linux/ctype.h>
diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c
index 77b87e0..b41bfad 100644
--- a/drivers/mmc/dw_mmc.c
+++ b/drivers/mmc/dw_mmc.c
@@ -10,6 +10,7 @@
 #include <common.h>
 #include <errno.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <mmc.h>
 #include <dwmmc.h>
 #include <asm-generic/errno.h>
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index f12546a..361154c 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -14,6 +14,7 @@
 #include <mmc.h>
 #include <part.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <linux/list.h>
 #include <div64.h>
 #include "mmc_private.h"
diff --git a/drivers/mmc/rpmb.c b/drivers/mmc/rpmb.c
index 9d0b8bc..1c6888f 100644
--- a/drivers/mmc/rpmb.c
+++ b/drivers/mmc/rpmb.c
@@ -10,6 +10,7 @@
 
 #include <config.h>
 #include <common.h>
+#include <memalign.h>
 #include <mmc.h>
 #include <u-boot/sha256.h>
 #include "mmc_private.h"
diff --git a/drivers/mtd/nand/tegra_nand.c b/drivers/mtd/nand/tegra_nand.c
index debad4f..a77db7b 100644
--- a/drivers/mtd/nand/tegra_nand.c
+++ b/drivers/mtd/nand/tegra_nand.c
@@ -9,6 +9,7 @@
 
 #include <common.h>
 #include <asm/io.h>
+#include <memalign.h>
 #include <nand.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/funcmux.h>
diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c
index 7b830ff..2ba03ed 100644
--- a/drivers/net/e1000.c
+++ b/drivers/net/e1000.c
@@ -32,6 +32,7 @@ tested on both gig copper and gig fiber boards
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
+#include <memalign.h>
 #include <pci.h>
 #include "e1000.h"
 
diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index c5dcbbb..b683413 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <net.h>
 #include <netdev.h>
 #include <miiphy.h>
diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index 7b6e20f..ebd46b2 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -44,6 +44,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <net.h>
 #ifndef CONFIG_DM_ETH
 #include <netdev.h>
diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
index 2b9f395..627644b 100644
--- a/drivers/spi/mxs_spi.c
+++ b/drivers/spi/mxs_spi.c
@@ -12,6 +12,7 @@
 
 #include <common.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <spi.h>
 #include <asm/errno.h>
 #include <asm/io.h>
diff --git a/drivers/usb/eth/asix.c b/drivers/usb/eth/asix.c
index 8a43e7c..ad083cf 100644
--- a/drivers/usb/eth/asix.c
+++ b/drivers/usb/eth/asix.c
@@ -10,6 +10,7 @@
 #include <dm.h>
 #include <usb.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <linux/mii.h>
 #include "usb_ether.h"
 
diff --git a/drivers/usb/eth/asix88179.c b/drivers/usb/eth/asix88179.c
index 94dfe85..cf4085d 100644
--- a/drivers/usb/eth/asix88179.c
+++ b/drivers/usb/eth/asix88179.c
@@ -12,6 +12,7 @@
 #include <linux/mii.h>
 #include "usb_ether.h"
 #include <malloc.h>
+#include <memalign.h>
 #include <errno.h>
 
 /* ASIX AX88179 based USB 3.0 Ethernet Devices */
diff --git a/drivers/usb/eth/mcs7830.c b/drivers/usb/eth/mcs7830.c
index c1b7086..bbdad8b 100644
--- a/drivers/usb/eth/mcs7830.c
+++ b/drivers/usb/eth/mcs7830.c
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <linux/mii.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <usb.h>
 
 #include "usb_ether.h"
diff --git a/drivers/usb/eth/smsc95xx.c b/drivers/usb/eth/smsc95xx.c
index 1dcd088..dc8fa88 100644
--- a/drivers/usb/eth/smsc95xx.c
+++ b/drivers/usb/eth/smsc95xx.c
@@ -11,6 +11,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <usb.h>
 #include <asm/unaligned.h>
 #include <linux/mii.h>
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 53f4672..c5e35ee 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -17,6 +17,7 @@
 #include <net.h>
 #include <usb.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <linux/ctype.h>
 
 #include "gadget_chips.h"
diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c
index 6346370..99c22c7 100644
--- a/drivers/usb/gadget/f_thor.c
+++ b/drivers/usb/gadget/f_thor.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <common.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <version.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index 85236ae..541c0f9 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -10,6 +10,7 @@
 #include <errno.h>
 #include <usb.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <phys2bus.h>
 #include <usbroothubdes.h>
 #include <asm/io.h>
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 3a0d32e..bc47e46 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -15,6 +15,7 @@
 #include <usb.h>
 #include <asm/io.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <watchdog.h>
 #include <linux/compiler.h>
 
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 0ffd838..9bde2b2 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -41,6 +41,7 @@
 #endif
 
 #include <malloc.h>
+#include <memalign.h>
 #include <usb.h>
 
 #include "ohci.h"
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
index b17a7d7..c66ebb6 100644
--- a/drivers/usb/host/usb-uclass.c
+++ b/drivers/usb/host/usb-uclass.c
@@ -10,6 +10,7 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
+#include <memalign.h>
 #include <usb.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
diff --git a/drivers/video/bcm2835.c b/drivers/video/bcm2835.c
index 61d054d..7867fe3 100644
--- a/drivers/video/bcm2835.c
+++ b/drivers/video/bcm2835.c
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <lcd.h>
+#include <memalign.h>
 #include <asm/arch/mbox.h>
 #include <asm/global_data.h>
 
diff --git a/fs/ext4/dev.c b/fs/ext4/dev.c
index c77c02c..20f5256 100644
--- a/fs/ext4/dev.c
+++ b/fs/ext4/dev.c
@@ -25,6 +25,7 @@
 
 #include <common.h>
 #include <config.h>
+#include <memalign.h>
 #include <ext4fs.h>
 #include <ext_common.h>
 #include "ext4_common.h"
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index cab5465..c77e22d 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -24,6 +24,7 @@
 #include <ext4fs.h>
 #include <inttypes.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <stddef.h>
 #include <linux/stat.h>
 #include <linux/time.h>
diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index fbc4c4b..d346c06 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -23,6 +23,7 @@
 
 
 #include <common.h>
+#include <memalign.h>
 #include <linux/stat.h>
 #include <div64.h>
 #include "ext4_common.h"
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index bccc3e3..48cf652 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -16,6 +16,7 @@
 #include <asm/byteorder.h>
 #include <part.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <linux/compiler.h>
 #include <linux/ctype.h>
 
diff --git a/include/common.h b/include/common.h
index c48e5bc..68b24d0 100644
--- a/include/common.h
+++ b/include/common.h
@@ -974,93 +974,6 @@ int cpu_release(int nr, int argc, char * const argv[]);
 #define ROUND(a,b)		(((a) + (b) - 1) & ~((b) - 1))
 
 /*
- * ARCH_DMA_MINALIGN is defined in asm/cache.h for each architecture.  It
- * is used to align DMA buffers.
- */
-#ifndef __ASSEMBLY__
-#include <asm/cache.h>
-#endif
-
-/*
- * The ALLOC_CACHE_ALIGN_BUFFER macro is used to allocate a buffer on the
- * stack that meets the minimum architecture alignment requirements for DMA.
- * Such a buffer is useful for DMA operations where flushing and invalidating
- * the cache before and after a read and/or write operation is required for
- * correct operations.
- *
- * When called the macro creates an array on the stack that is sized such
- * that:
- *
- * 1) The beginning of the array can be advanced enough to be aligned.
- *
- * 2) The size of the aligned portion of the array is a multiple of the minimum
- *    architecture alignment required for DMA.
- *
- * 3) The aligned portion contains enough space for the original number of
- *    elements requested.
- *
- * The macro then creates a pointer to the aligned portion of this array and
- * assigns to the pointer the address of the first element in the aligned
- * portion of the array.
- *
- * Calling the macro as:
- *
- *     ALLOC_CACHE_ALIGN_BUFFER(uint32_t, buffer, 1024);
- *
- * Will result in something similar to saying:
- *
- *     uint32_t    buffer[1024];
- *
- * The following differences exist:
- *
- * 1) The resulting buffer is guaranteed to be aligned to the value of
- *    ARCH_DMA_MINALIGN.
- *
- * 2) The buffer variable created by the macro is a pointer to the specified
- *    type, and NOT an array of the specified type.  This can be very important
- *    if you want the address of the buffer, which you probably do, to pass it
- *    to the DMA hardware.  The value of &buffer is different in the two cases.
- *    In the macro case it will be the address of the pointer, not the address
- *    of the space reserved for the buffer.  However, in the second case it
- *    would be the address of the buffer.  So if you are replacing hard coded
- *    stack buffers with this macro you need to make sure you remove the & from
- *    the locations where you are taking the address of the buffer.
- *
- * Note that the size parameter is the number of array elements to allocate,
- * not the number of bytes.
- *
- * This macro can not be used outside of function scope, or for the creation
- * of a function scoped static buffer.  It can not be used to create a cache
- * line aligned global buffer.
- */
-#define PAD_COUNT(s, pad) (((s) - 1) / (pad) + 1)
-#define PAD_SIZE(s, pad) (PAD_COUNT(s, pad) * pad)
-#define ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, pad)		\
-	char __##name[ROUND(PAD_SIZE((size) * sizeof(type), pad), align)  \
-		      + (align - 1)];					\
-									\
-	type *name = (type *) ALIGN((uintptr_t)__##name, align)
-#define ALLOC_ALIGN_BUFFER(type, name, size, align)		\
-	ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, 1)
-#define ALLOC_CACHE_ALIGN_BUFFER_PAD(type, name, size, pad)		\
-	ALLOC_ALIGN_BUFFER_PAD(type, name, size, ARCH_DMA_MINALIGN, pad)
-#define ALLOC_CACHE_ALIGN_BUFFER(type, name, size)			\
-	ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
-
-/*
- * DEFINE_CACHE_ALIGN_BUFFER() is similar to ALLOC_CACHE_ALIGN_BUFFER, but it's
- * purpose is to allow allocating aligned buffers outside of function scope.
- * Usage of this macro shall be avoided or used with extreme care!
- */
-#define DEFINE_ALIGN_BUFFER(type, name, size, align)			\
-	static char __##name[ALIGN(size * sizeof(type), align)]	\
-			__aligned(align);				\
-									\
-	static type *name = (type *)__##name
-#define DEFINE_CACHE_ALIGN_BUFFER(type, name, size)			\
-	DEFINE_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
-
-/*
  * check_member() - Check the offset of a structure member
  *
  * @structure:	Name of structure (e.g. global_data)
diff --git a/include/memalign.h b/include/memalign.h
index f78b9dd..a960039 100644
--- a/include/memalign.h
+++ b/include/memalign.h
@@ -13,9 +13,100 @@
  */
 #ifndef __ASSEMBLY__
 #include <asm/cache.h>
-
 #include <malloc.h>
 
+/*
+ * The ALLOC_CACHE_ALIGN_BUFFER macro is used to allocate a buffer on the
+ * stack that meets the minimum architecture alignment requirements for DMA.
+ * Such a buffer is useful for DMA operations where flushing and invalidating
+ * the cache before and after a read and/or write operation is required for
+ * correct operations.
+ *
+ * When called the macro creates an array on the stack that is sized such
+ * that:
+ *
+ * 1) The beginning of the array can be advanced enough to be aligned.
+ *
+ * 2) The size of the aligned portion of the array is a multiple of the minimum
+ *    architecture alignment required for DMA.
+ *
+ * 3) The aligned portion contains enough space for the original number of
+ *    elements requested.
+ *
+ * The macro then creates a pointer to the aligned portion of this array and
+ * assigns to the pointer the address of the first element in the aligned
+ * portion of the array.
+ *
+ * Calling the macro as:
+ *
+ *     ALLOC_CACHE_ALIGN_BUFFER(uint32_t, buffer, 1024);
+ *
+ * Will result in something similar to saying:
+ *
+ *     uint32_t    buffer[1024];
+ *
+ * The following differences exist:
+ *
+ * 1) The resulting buffer is guaranteed to be aligned to the value of
+ *    ARCH_DMA_MINALIGN.
+ *
+ * 2) The buffer variable created by the macro is a pointer to the specified
+ *    type, and NOT an array of the specified type.  This can be very important
+ *    if you want the address of the buffer, which you probably do, to pass it
+ *    to the DMA hardware.  The value of &buffer is different in the two cases.
+ *    In the macro case it will be the address of the pointer, not the address
+ *    of the space reserved for the buffer.  However, in the second case it
+ *    would be the address of the buffer.  So if you are replacing hard coded
+ *    stack buffers with this macro you need to make sure you remove the & from
+ *    the locations where you are taking the address of the buffer.
+ *
+ * Note that the size parameter is the number of array elements to allocate,
+ * not the number of bytes.
+ *
+ * This macro can not be used outside of function scope, or for the creation
+ * of a function scoped static buffer.  It can not be used to create a cache
+ * line aligned global buffer.
+ */
+#define PAD_COUNT(s, pad) (((s) - 1) / (pad) + 1)
+#define PAD_SIZE(s, pad) (PAD_COUNT(s, pad) * pad)
+#define ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, pad)		\
+	char __##name[ROUND(PAD_SIZE((size) * sizeof(type), pad), align)  \
+		      + (align - 1)];					\
+									\
+	type *name = (type *)ALIGN((uintptr_t)__##name, align)
+#define ALLOC_ALIGN_BUFFER(type, name, size, align)		\
+	ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, 1)
+#define ALLOC_CACHE_ALIGN_BUFFER_PAD(type, name, size, pad)		\
+	ALLOC_ALIGN_BUFFER_PAD(type, name, size, ARCH_DMA_MINALIGN, pad)
+#define ALLOC_CACHE_ALIGN_BUFFER(type, name, size)			\
+	ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
+
+/*
+ * DEFINE_CACHE_ALIGN_BUFFER() is similar to ALLOC_CACHE_ALIGN_BUFFER, but it's
+ * purpose is to allow allocating aligned buffers outside of function scope.
+ * Usage of this macro shall be avoided or used with extreme care!
+ */
+#define DEFINE_ALIGN_BUFFER(type, name, size, align)			\
+	static char __##name[ALIGN(size * sizeof(type), align)]	\
+			__aligned(align);				\
+									\
+	static type *name = (type *)__##name
+#define DEFINE_CACHE_ALIGN_BUFFER(type, name, size)			\
+	DEFINE_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
+
+/**
+ * malloc_cache_aligned() - allocate a memory region aligned to cache line size
+ *
+ * This allocates memory at a cache-line boundary. The amount allocated may
+ * be larger than requested as it is rounded up to the nearest multiple of the
+ * cache-line size. This ensured that subsequent cache operations on this
+ * memory (flush, invalidate) will not affect subsequently allocated regions.
+ *
+ * @size:	Minimum number of bytes to allocate
+ *
+ * @return pointer to new memory region, or NULL if there is no more memory
+ * available.
+ */
 static inline void *malloc_cache_aligned(size_t size)
 {
 	return memalign(ARCH_DMA_MINALIGN, ALIGN(size, ARCH_DMA_MINALIGN));
-- 
2.5.0.457.gab17608

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2 1/2] Move malloc_cache_aligned() to its own header
  2015-09-02 23:24 [U-Boot] [PATCH v2 1/2] Move malloc_cache_aligned() to its own header Simon Glass
  2015-09-02 23:24 ` [U-Boot] [PATCH v2 2/2] Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h header Simon Glass
@ 2015-09-03 11:08 ` Marcel Ziswiler
  2015-09-12 12:50 ` [U-Boot] [U-Boot, v2, " Tom Rini
  2 siblings, 0 replies; 5+ messages in thread
From: Marcel Ziswiler @ 2015-09-03 11:08 UTC (permalink / raw)
  To: u-boot

On Wed, 2015-09-02 at 17:24 -0600, Simon Glass wrote:
> At present malloc.h is included everywhere since it recently was
> added to
> common.h in this commit:
> 
>    4519668 mtd/nand/ubi: assortment of alignment fixes
> 
> This seems wasteful and unnecessary. We have been trying to trim down
> common.h and put separate functions into separate header files and
> that
> change goes in the opposite direction.
> 
> Move malloc_cache_aligned() to a new header so that this can be
> avoided.
> The header would perhaps be better named as alignmem.h but it needs
> to be
> included after common.h and people might be confused by this. With
> the name
> memalign.h it fits nicely after malloc() in most cases.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

The series successfully NAND boot tested on Colibri T20 512MB V1.2A
therefore

Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [U-Boot, v2, 1/2] Move malloc_cache_aligned() to its own header
  2015-09-02 23:24 [U-Boot] [PATCH v2 1/2] Move malloc_cache_aligned() to its own header Simon Glass
  2015-09-02 23:24 ` [U-Boot] [PATCH v2 2/2] Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h header Simon Glass
  2015-09-03 11:08 ` [U-Boot] [PATCH v2 1/2] Move malloc_cache_aligned() to its own header Marcel Ziswiler
@ 2015-09-12 12:50 ` Tom Rini
  2 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2015-09-12 12:50 UTC (permalink / raw)
  To: u-boot

On Wed, Sep 02, 2015 at 05:24:57PM -0600, Simon Glass wrote:

> At present malloc.h is included everywhere since it recently was added to
> common.h in this commit:
> 
>    4519668 mtd/nand/ubi: assortment of alignment fixes
> 
> This seems wasteful and unnecessary. We have been trying to trim down
> common.h and put separate functions into separate header files and that
> change goes in the opposite direction.
> 
> Move malloc_cache_aligned() to a new header so that this can be avoided.
> The header would perhaps be better named as alignmem.h but it needs to be
> included after common.h and people might be confused by this. With the name
> memalign.h it fits nicely after malloc() in most cases.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150912/c5191218/attachment.sig>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [U-Boot, v2, 2/2] Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h header
  2015-09-02 23:24 ` [U-Boot] [PATCH v2 2/2] Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h header Simon Glass
@ 2015-09-12 12:50   ` Tom Rini
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2015-09-12 12:50 UTC (permalink / raw)
  To: u-boot

On Wed, Sep 02, 2015 at 05:24:58PM -0600, Simon Glass wrote:

> Now that we have a new header file for cache-aligned allocation, we should
> move the stack-based allocation macro there also.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150912/0dfc1318/attachment.sig>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-12 12:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-02 23:24 [U-Boot] [PATCH v2 1/2] Move malloc_cache_aligned() to its own header Simon Glass
2015-09-02 23:24 ` [U-Boot] [PATCH v2 2/2] Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h header Simon Glass
2015-09-12 12:50   ` [U-Boot] [U-Boot, v2, " Tom Rini
2015-09-03 11:08 ` [U-Boot] [PATCH v2 1/2] Move malloc_cache_aligned() to its own header Marcel Ziswiler
2015-09-12 12:50 ` [U-Boot] [U-Boot, v2, " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.