From cf92e05c0135bc2b1a1b25a3218e31e6d79bad59 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 2 Sep 2015 17:24:58 -0600 Subject: Move ALLOC_CACHE_ALIGN_BUFFER() to the new memalign.h header 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 --- 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 d21750e2a0..6d7be11518 100644 --- a/board/raspberrypi/rpi/rpi.c +++ b/board/raspberrypi/rpi/rpi.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/board/samsung/common/misc.c b/board/samsung/common/misc.c index f0d69d4a48..e0e2c48632 100644 --- a/board/samsung/common/misc.c +++ b/board/samsung/common/misc.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/common/cmd_usb.c b/common/cmd_usb.c index 6874af7547..6bdbbc5c05 100644 --- a/common/cmd_usb.c +++ b/common/cmd_usb.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/common/env_fat.c b/common/env_fat.c index e4c848935a..d79d864a0c 100644 --- a/common/env_fat.c +++ b/common/env_fat.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/common/env_mmc.c b/common/env_mmc.c index 51e7707cb0..96398224cc 100644 --- a/common/env_mmc.c +++ b/common/env_mmc.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/common/env_nand.c b/common/env_nand.c index 92e0e053df..b32eeac9d7 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/common/env_ubi.c b/common/env_ubi.c index 77bbfa6ef4..e0dc5af851 100644 --- a/common/env_ubi.c +++ b/common/env_ubi.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #undef crc32 diff --git a/common/usb.c b/common/usb.c index fbaf8ecbe2..700bfc315b 100644 --- a/common/usb.c +++ b/common/usb.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/common/usb_hub.c b/common/usb_hub.c index 652a104361..415b45c1f1 100644 --- a/common/usb_hub.c +++ b/common/usb_hub.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/common/usb_kbd.c b/common/usb_kbd.c index 0227024441..95912f99c7 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include diff --git a/common/usb_storage.c b/common/usb_storage.c index b978430408..b390310ee3 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include diff --git a/disk/part_dos.c b/disk/part_dos.c index cf1a36ebb8..89263d38aa 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "part_dos.h" #ifdef HAVE_BLOCK_DEVICE diff --git a/disk/part_efi.c b/disk/part_efi.c index 5856f93211..15627f29e8 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/disk/part_mac.c b/disk/part_mac.c index cbcb995c48..099e0a0035 100644 --- a/disk/part_mac.c +++ b/disk/part_mac.c @@ -15,6 +15,7 @@ #include #include +#include #include #include "part_mac.h" diff --git a/drivers/block/ahci.c b/drivers/block/ahci.c index 0d19dd25a3..82c68439f8 100644 --- a/drivers/block/ahci.c +++ b/drivers/block/ahci.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index 1117fedefe..a84c1e16d8 100644 --- a/drivers/mmc/dw_mmc.c +++ b/drivers/mmc/dw_mmc.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 371c1ec212..2a58702848 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include "mmc_private.h" diff --git a/drivers/mmc/rpmb.c b/drivers/mmc/rpmb.c index 9d0b8bc0c8..1c6888fc48 100644 --- a/drivers/mmc/rpmb.c +++ b/drivers/mmc/rpmb.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include "mmc_private.h" diff --git a/drivers/mtd/nand/tegra_nand.c b/drivers/mtd/nand/tegra_nand.c index debad4f791..a77db7b65d 100644 --- a/drivers/mtd/nand/tegra_nand.c +++ b/drivers/mtd/nand/tegra_nand.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index 7b830ff8c0..2ba03ed73e 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 #include #include +#include #include #include "e1000.h" diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index bff5fd1119..79f6737e8e 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c index 7b6e20f30f..ebd46b27e5 100644 --- a/drivers/net/rtl8169.c +++ b/drivers/net/rtl8169.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #ifndef CONFIG_DM_ETH #include diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c index 2b9f395a97..627644b56b 100644 --- a/drivers/spi/mxs_spi.c +++ b/drivers/spi/mxs_spi.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include diff --git a/drivers/usb/eth/asix.c b/drivers/usb/eth/asix.c index 8a43e7c27d..ad083cf8ae 100644 --- a/drivers/usb/eth/asix.c +++ b/drivers/usb/eth/asix.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "usb_ether.h" diff --git a/drivers/usb/eth/asix88179.c b/drivers/usb/eth/asix88179.c index 94dfe85eff..cf4085d765 100644 --- a/drivers/usb/eth/asix88179.c +++ b/drivers/usb/eth/asix88179.c @@ -12,6 +12,7 @@ #include #include "usb_ether.h" #include +#include #include /* ASIX AX88179 based USB 3.0 Ethernet Devices */ diff --git a/drivers/usb/eth/mcs7830.c b/drivers/usb/eth/mcs7830.c index c1b708600e..bbdad8b79a 100644 --- a/drivers/usb/eth/mcs7830.c +++ b/drivers/usb/eth/mcs7830.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "usb_ether.h" diff --git a/drivers/usb/eth/smsc95xx.c b/drivers/usb/eth/smsc95xx.c index 1dcd088b8d..dc8fa8891b 100644 --- a/drivers/usb/eth/smsc95xx.c +++ b/drivers/usb/eth/smsc95xx.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 53f4672291..c5e35ee350 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "gadget_chips.h" diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c index 06139ee04d..ff1481ba37 100644 --- a/drivers/usb/gadget/f_thor.c +++ b/drivers/usb/gadget/f_thor.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c index 85236aeb2a..541c0f9687 100644 --- a/drivers/usb/host/dwc2.c +++ b/drivers/usb/host/dwc2.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 88b670b7f8..135ef72622 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 0ffd838db2..9bde2b252c 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c @@ -41,6 +41,7 @@ #endif #include +#include #include #include "ohci.h" diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index b17a7d762e..c66ebb6678 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/video/bcm2835.c b/drivers/video/bcm2835.c index 61d054dd89..7867fe3895 100644 --- a/drivers/video/bcm2835.c +++ b/drivers/video/bcm2835.c @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/fs/ext4/dev.c b/fs/ext4/dev.c index c77c02cdfc..20f52566f0 100644 --- a/fs/ext4/dev.c +++ b/fs/ext4/dev.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include "ext4_common.h" diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index cab5465b9d..c77e22d477 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c index fbc4c4b1cc..d346c065cd 100644 --- a/fs/ext4/ext4_write.c +++ b/fs/ext4/ext4_write.c @@ -23,6 +23,7 @@ #include +#include #include #include #include "ext4_common.h" diff --git a/fs/fat/fat.c b/fs/fat/fat.c index a863644d64..06dcbb7005 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/include/common.h b/include/common.h index c48e5bc11b..68b24d0778 100644 --- a/include/common.h +++ b/include/common.h @@ -973,93 +973,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 -#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 * diff --git a/include/memalign.h b/include/memalign.h index f78b9dd9dc..a960039083 100644 --- a/include/memalign.h +++ b/include/memalign.h @@ -13,9 +13,100 @@ */ #ifndef __ASSEMBLY__ #include - #include +/* + * 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)); -- cgit v1.2.1