*/
void
malloc_elem_init(struct malloc_elem *elem,
- struct malloc_heap *heap, size_t size)
+ struct malloc_heap *heap, const struct rte_memzone *mz, size_t size)
{
elem->heap = heap;
+ elem->mz = mz;
elem->prev = elem->next_free = NULL;
elem->state = ELEM_FREE;
elem->size = size;
void
malloc_elem_mkend(struct malloc_elem *elem, struct malloc_elem *prev)
{
- malloc_elem_init(elem, prev->heap, 0);
+ malloc_elem_init(elem, prev->heap, prev->mz, 0);
elem->prev = prev;
elem->state = ELEM_BUSY; /* mark busy so its never merged */
}
const unsigned old_elem_size = (uintptr_t)split_pt - (uintptr_t)elem;
const unsigned new_elem_size = elem->size - old_elem_size;
- malloc_elem_init(split_pt, elem->heap, new_elem_size);
+ malloc_elem_init(split_pt, elem->heap, elem->mz, new_elem_size);
split_pt->prev = elem;
next_elem->prev = split_pt;
elem->size = old_elem_size;
struct malloc_heap *heap;
struct malloc_elem *volatile prev; /* points to prev elem in memzone */
struct malloc_elem *volatile next_free; /* to make list of free elements */
+ const struct rte_memzone *mz;
volatile enum elem_state state;
uint32_t pad;
size_t size;
void
malloc_elem_init(struct malloc_elem *elem,
struct malloc_heap *heap,
+ const struct rte_memzone *mz,
size_t size);
/*
end_elem = RTE_PTR_ALIGN_FLOOR(end_elem, CACHE_LINE_SIZE);
const unsigned elem_size = (uintptr_t)end_elem - (uintptr_t)start_elem;
- malloc_elem_init(start_elem, heap, elem_size);
+ malloc_elem_init(start_elem, heap, mz, elem_size);
malloc_elem_mkend(end_elem, start_elem);
start_elem->next_free = heap->free_head;
{
return 0;
}
+
+/*
+ * Return the physical address of a virtual address obtained through rte_malloc
+ */
+phys_addr_t
+rte_malloc_virt2phy(const void *addr)
+{
+ const struct malloc_elem *elem = malloc_elem_from_data(addr);
+ if (elem == NULL)
+ return 0;
+ return elem->mz->phys_addr + ((uintptr_t)addr - (uintptr_t)elem->mz->addr);
+}
*/
#include <stddef.h>
+#include <rte_memory.h>
#ifdef __cplusplus
extern "C" {
int
rte_malloc_set_limit(const char *type, size_t max);
+/**
+ * Return the physical address of a virtual address obtained through
+ * rte_malloc
+ *
+ * @param addr
+ * Adress obtained from a previous rte_malloc call
+ * @return
+ * NULL on error
+ * otherwise return physical address of the buffer
+ */
+phys_addr_t
+rte_malloc_virt2phy(const void *addr);
+
#ifdef __cplusplus
}
#endif