Set the malloc alignment to 64 bytes on platforms that use the U-Boot API
device drivers. Recent versions of u-boot run with the MMU enabled, and require DMA-based I/O to be aligned to cache line boundaries. These changes are based on a patch originally submitted by Juergen Weiss, but I reworked them and thus any problems are purely my fault. Submitted by: "Juergen Weiss" <weiss@uni-mainz.de> Reviewed by: imp, nwhitehorn, jhb
This commit is contained in:
parent
3b78c64b35
commit
b1526b43e8
@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "stand.h"
|
#include "stand.h"
|
||||||
|
#include "zalloc_defs.h"
|
||||||
|
|
||||||
static size_t maxheap, heapsize = 0;
|
static size_t maxheap, heapsize = 0;
|
||||||
static void *heapbase;
|
static void *heapbase;
|
||||||
@ -40,8 +41,9 @@ static void *heapbase;
|
|||||||
void
|
void
|
||||||
setheap(void *base, void *top)
|
setheap(void *base, void *top)
|
||||||
{
|
{
|
||||||
/* Align start address to 16 bytes for the malloc code. Sigh. */
|
/* Align start address for the malloc code. Sigh. */
|
||||||
heapbase = (void *)(((uintptr_t)base + 15) & ~15);
|
heapbase = (void *)(((uintptr_t)base + MALLOCALIGN_MASK) &
|
||||||
|
~MALLOCALIGN_MASK);
|
||||||
maxheap = (char *)top - (char *)heapbase;
|
maxheap = (char *)top - (char *)heapbase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,15 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include "zalloc_defs.h"
|
#include "zalloc_defs.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Objects in the pool must be aligned to at least the size of struct MemNode.
|
||||||
|
* They must also be aligned to MALLOCALIGN, which should normally be larger
|
||||||
|
* than the struct, so assert that to be so at compile time.
|
||||||
|
*/
|
||||||
|
typedef char assert_align[(sizeof(struct MemNode) <= MALLOCALIGN) ? 1 : -1];
|
||||||
|
|
||||||
|
#define MEMNODE_SIZE_MASK MALLOCALIGN_MASK
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* znalloc() - allocate memory (without zeroing) from pool. Call reclaim
|
* znalloc() - allocate memory (without zeroing) from pool. Call reclaim
|
||||||
* and retry if appropriate, return NULL if unable to allocate
|
* and retry if appropriate, return NULL if unable to allocate
|
||||||
|
@ -52,18 +52,26 @@
|
|||||||
#define BLKEXTENDMASK (BLKEXTEND - 1)
|
#define BLKEXTENDMASK (BLKEXTEND - 1)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* required malloc alignment. Just hardwire to 16.
|
* Required malloc alignment.
|
||||||
*
|
*
|
||||||
* Note: if we implement a more sophisticated realloc, we should ensure that
|
* Embedded platforms using the u-boot API drivers require that all I/O buffers
|
||||||
* MALLOCALIGN is at least as large as MemNode.
|
* be on a cache line sized boundary. The worst case size for that is 64 bytes.
|
||||||
|
* For other platforms, 16 bytes works fine. The alignment also must be at
|
||||||
|
* least sizeof(struct MemNode); this is asserted in zalloc.c.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined(__arm__) || defined(__mips__) || defined(__powerpc__)
|
||||||
|
#define MALLOCALIGN 64
|
||||||
|
#else
|
||||||
|
#define MALLOCALIGN 16
|
||||||
|
#endif
|
||||||
|
#define MALLOCALIGN_MASK (MALLOCALIGN - 1)
|
||||||
|
|
||||||
typedef struct Guard {
|
typedef struct Guard {
|
||||||
size_t ga_Bytes;
|
size_t ga_Bytes;
|
||||||
size_t ga_Magic; /* must be at least 32 bits */
|
size_t ga_Magic; /* must be at least 32 bits */
|
||||||
} Guard;
|
} Guard;
|
||||||
|
|
||||||
#define MALLOCALIGN 16
|
|
||||||
#define GAMAGIC 0x55FF44FD
|
#define GAMAGIC 0x55FF44FD
|
||||||
#define GAFREE 0x5F54F4DF
|
#define GAFREE 0x5F54F4DF
|
||||||
|
|
||||||
|
@ -48,8 +48,6 @@ typedef struct MemPool {
|
|||||||
uintptr_t mp_Used;
|
uintptr_t mp_Used;
|
||||||
} MemPool;
|
} MemPool;
|
||||||
|
|
||||||
#define MEMNODE_SIZE_MASK ((sizeof(MemNode) <= 8) ? 7 : 15)
|
|
||||||
|
|
||||||
#define ZNOTE_FREE 0
|
#define ZNOTE_FREE 0
|
||||||
#define ZNOTE_REUSE 1
|
#define ZNOTE_REUSE 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user