libpayload: Add dma_allocator_range()
Some sensitive data may remain DMA buffer, we will want to zero out everything on the DMA buffer before we jump into the kernel to prevent leaking sensitive data into the kernel. To accomplish that, we will need this function to get the range of memory that can be allocated by the dma allocator. BUG=b:248610274 TEST=emerge-cherry libpayload BRANCH=none Signed-off-by: Yi Chou <yich@google.com> Change-Id: I8f3058dfd861ed44f716623967201b8cabe8d166 Reviewed-on: https://review.coreboot.org/c/coreboot/+/78407 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
This commit is contained in:
parent
cbbfd68481
commit
582c2a7980
|
@ -137,6 +137,7 @@ void print_malloc_map(void);
|
||||||
void init_dma_memory(void *start, u32 size);
|
void init_dma_memory(void *start, u32 size);
|
||||||
int dma_initialized(void);
|
int dma_initialized(void);
|
||||||
int dma_coherent(const void *ptr);
|
int dma_coherent(const void *ptr);
|
||||||
|
void dma_allocator_range(void **start_out, size_t *size_out);
|
||||||
|
|
||||||
static inline void *xmalloc_work(size_t size, const char *file,
|
static inline void *xmalloc_work(size_t size, const char *file,
|
||||||
const char *func, int line)
|
const char *func, int line)
|
||||||
|
|
|
@ -123,6 +123,18 @@ int dma_coherent(const void *ptr)
|
||||||
return !dma_initialized() || (dma->start <= ptr && dma->end > ptr);
|
return !dma_initialized() || (dma->start <= ptr && dma->end > ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the range of memory that can be allocated by the dma allocator. */
|
||||||
|
void dma_allocator_range(void **start_out, size_t *size_out)
|
||||||
|
{
|
||||||
|
if (dma_initialized()) {
|
||||||
|
*start_out = dma->start;
|
||||||
|
*size_out = dma->end - dma->start;
|
||||||
|
} else {
|
||||||
|
*start_out = NULL;
|
||||||
|
*size_out = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Find free block of size >= len */
|
/* Find free block of size >= len */
|
||||||
static hdrtype_t volatile *find_free_block(int len, struct memory_type *type)
|
static hdrtype_t volatile *find_free_block(int len, struct memory_type *type)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue