esp-idf/components/esp_mm/include/esp_private/heap_align_hw.h
Jeroen Domburg a1ba660b4a change(system): heap_caps_alloc returns aligned memory if caps indicate a need for it
The implicit promise of heap_alloc_caps() and friends is that the memory it
returns is fit for the purpose as requested in the caps field. Before
this commit, that did not happen; e.g. DMA-capable memory wass returned
from a correct region, but not aligned/sized to something the DMA subsystem
can handle.

This commit adds an API to the esp_mm component that is then used by the
heap component to adjust allocation alignment, caps and size dependent on
the hardware requirement of the requested allocation caps.
2024-05-27 12:41:18 +08:00

40 lines
1.3 KiB
C

/*
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include "multi_heap.h"
#include "sdkconfig.h"
#include "esp_err.h"
#include "esp_attr.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Adjust size, alignment and caps of a memory allocation request to the specific
* hardware requirements, dependent on where the memory gets allocated.
*
* @note Note that heap_caps_base.c has its own definition for this function in order not to depend
* on this component.
*
* @param[in,out] p_alignment Pointer to alignment requirements. This may be modified upwards if the
* hardware has stricter alignment requirements.
* @param[in,out] p_size Pointer to size of memory to be allocated. This may be modified upwards
* if e.g. the memory needs to be aligned to a cache line.
* @param[in,out] p_caps Pointer to memory requirements. This may be adjusted if the memory
* requirements need modification for the heap caps allocator to work
* properly.
*/
void esp_heap_adjust_alignment_to_hw(size_t *p_alignment, size_t *p_size, uint32_t *p_caps);
#ifdef __cplusplus
}
#endif