Commit 9c3c788f authored by Jens Korinth's avatar Jens Korinth
Browse files

Move memory management to default implementation fragment

* memory allocation/deallocation and copy operations are no in
  tapasco_memory.h/c fragment in arch/common
* removed code from axi4mm Arch implementation and linking against
  default fragment instead
parent 86e05c0a
Pipeline #239 passed with stage
in 3 minutes and 27 seconds
......@@ -25,6 +25,7 @@ set(COMMON_SOURCES "${CMNDIR}/tapasco_logging.c"
"${CMNDIR}/tapasco_jobs.c"
"${CMNDIR}/tapasco_status.c"
"${CMNDIR}/tapasco_version.c"
"${CMNDIR}/tapasco_memory.c"
"${GCMNDIR}/src/gen_queue.c")
set(TAPASCO_LIBS_DIR "${TAPASCO_HOME}/arch/lib")
......
......@@ -108,54 +108,6 @@ tapasco_res_t tapasco_device_load_bitstream(tapasco_dev_ctx_t *dev_ctx, size_t c
return TAPASCO_ERR_NOT_IMPLEMENTED;
}
tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t *h,
size_t const len, tapasco_device_alloc_flag_t const flags)
{
platform_mem_addr_t addr;
platform_res_t r;
if ((r = platform_alloc(len, &addr, PLATFORM_ALLOC_FLAGS_NONE)) == PLATFORM_SUCCESS) {
LOG(LALL_MEM, "allocated %zd bytes at 0x%08x", len, addr);
*h = addr;
return TAPASCO_SUCCESS;
}
WRN("could not allocate %zd bytes of device memory: %s",
len, platform_strerror(r));
return TAPASCO_ERR_OUT_OF_MEMORY;
}
void tapasco_device_free(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t handle,
tapasco_device_alloc_flag_t const flags)
{
LOG(LALL_MEM, "freeing handle 0x%08x", (unsigned)handle);
platform_dealloc(handle, PLATFORM_ALLOC_FLAGS_NONE);
}
tapasco_res_t tapasco_device_copy_to(tapasco_dev_ctx_t *dev_ctx, void const *src,
tapasco_handle_t dst, size_t len,
tapasco_device_copy_flag_t const flags)
{
LOG(LALL_MEM, "dst = 0x%08x, len = %zd, flags = %d", (unsigned)dst, len, flags);
if (flags & TAPASCO_DEVICE_COPY_NONBLOCKING)
return TAPASCO_ERR_NONBLOCKING_MODE_NOT_SUPPORTED;
if (flags)
return TAPASCO_ERR_NOT_IMPLEMENTED;
return platform_write_mem(dst, len, src, PLATFORM_MEM_FLAGS_NONE) == PLATFORM_SUCCESS ?
TAPASCO_SUCCESS : TAPASCO_FAILURE;
}
tapasco_res_t tapasco_device_copy_from(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t src,
void *dst, size_t len,
tapasco_device_copy_flag_t const flags)
{
LOG(LALL_MEM, "src = 0x%08x, len = %zd, flags = %d", (unsigned)src, len, flags);
if (flags & TAPASCO_DEVICE_COPY_NONBLOCKING)
return TAPASCO_ERR_NONBLOCKING_MODE_NOT_SUPPORTED;
if (flags)
return TAPASCO_ERR_NOT_IMPLEMENTED;
return platform_read_mem(src, len, dst, PLATFORM_MEM_FLAGS_NONE) == PLATFORM_SUCCESS ?
TAPASCO_SUCCESS : TAPASCO_FAILURE;
}
tapasco_job_id_t tapasco_device_acquire_job_id(tapasco_dev_ctx_t *dev_ctx,
tapasco_func_id_t const func_id,
tapasco_device_acquire_job_id_flag_t flags)
......
//
// Copyright (C) 2017 Jens Korinth, TU Darmstadt
//
// This file is part of Tapasco (TPC).
//
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco. If not, see <http://www.gnu.org/licenses/>.
//
//! @file tapasco_memory.h
//! @brief Common TaPaSCo API implementation fragment:
//! Provides standard API to allocate and free memory.
//! @authors J. Korinth, TU Darmstadt (jk@esa.cs.tu-darmstadt.de)
//!
#ifndef TAPASCO_MEMORY_H__
#define TAPASCO_MEMORY_H__
#include <tapasco.h>
/**
* Allocates a chunk of len bytes on the device.
* @param dev_ctx device context
* @param h output parameter to write the handle to
* @param len size in bytes
* @param flags device memory allocation flags
* @return TAPASCO_SUCCESS if successful, error code otherwise
**/
tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t *handle,
size_t const len, tapasco_device_alloc_flag_t const flags);
/**
* Frees a previously allocated chunk of device memory.
* @param dev_ctx device context
* @param handle memory chunk handle returned by @see tapasco_alloc
* @param flags device memory allocation flags
**/
void tapasco_device_free(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t handle,
tapasco_device_alloc_flag_t const flags);
/**
* Copys memory from main memory to the FPGA device.
* @param dev_ctx device context
* @param src source address
* @param dst destination device handle (prev. alloc'ed with tapasco_alloc)
* @param len number of bytes to copy
* @param flags flags for copy operation, e.g., TAPASCO_COPY_NONBLOCKING
* @return TAPASCO_SUCCESS if copy was successful, TAPASCO_FAILURE otherwise
**/
tapasco_res_t tapasco_device_copy_to(tapasco_dev_ctx_t *dev_ctx, void const *src,
tapasco_handle_t dst, size_t len,
tapasco_device_copy_flag_t const flags);
/**
* Copys memory from FPGA device memory to main memory.
* @param dev_ctx device context
* @param src source device handle (prev. alloc'ed with tapasco_alloc)
* @param dst destination address
* @param len number of bytes to copy
* @param flags flags for copy operation, e.g., TAPASCO_COPY_NONBLOCKING
* @return TAPASCO_SUCCESS if copy was successful, TAPASCO_FAILURE otherwise
**/
tapasco_res_t tapasco_device_copy_from(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t src,
void *dst, size_t len, tapasco_device_copy_flag_t const flags);
#endif /* TAPASCO_MEMORY_H__ */
//
// Copyright (C) 2017 Jens Korinth, TU Darmstadt
//
// This file is part of Tapasco (TAPASCO).
//
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco. If not, see <http://www.gnu.org/licenses/>.
//
/**
* @file tapasco_memory.c
* @brief Default implementation of memory functions: Pass-through to
* Platform implementation.
* @author J. Korinth, TU Darmstadt (jk@esa.cs.tu-darmstadt.de)
**/
#ifdef __cplusplus
#include <cstdint>
#include <cstring>
#else
#include <stdint.h>
#include <string.h>
#endif
#include <platform.h>
#include <tapasco_memory.h>
#include <tapasco_logging.h>
#include <tapasco_errors.h>
tapasco_res_t tapasco_device_alloc(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t *h,
size_t const len, tapasco_device_alloc_flag_t const flags)
{
platform_mem_addr_t addr;
platform_res_t r;
if ((r = platform_alloc(len, &addr, PLATFORM_ALLOC_FLAGS_NONE)) == PLATFORM_SUCCESS) {
LOG(LALL_MEM, "allocated %zd bytes at 0x%08x", len, addr);
*h = addr;
return TAPASCO_SUCCESS;
}
WRN("could not allocate %zd bytes of device memory: %s",
len, platform_strerror(r));
return TAPASCO_ERR_OUT_OF_MEMORY;
}
void tapasco_device_free(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t handle,
tapasco_device_alloc_flag_t const flags)
{
LOG(LALL_MEM, "freeing handle 0x%08x", (unsigned)handle);
platform_dealloc(handle, PLATFORM_ALLOC_FLAGS_NONE);
}
tapasco_res_t tapasco_device_copy_to(tapasco_dev_ctx_t *dev_ctx, void const *src,
tapasco_handle_t dst, size_t len,
tapasco_device_copy_flag_t const flags)
{
LOG(LALL_MEM, "dst = 0x%08x, len = %zd, flags = %d", (unsigned)dst, len, flags);
if (flags & TAPASCO_DEVICE_COPY_NONBLOCKING)
return TAPASCO_ERR_NONBLOCKING_MODE_NOT_SUPPORTED;
if (flags)
return TAPASCO_ERR_NOT_IMPLEMENTED;
return platform_write_mem(dst, len, src, PLATFORM_MEM_FLAGS_NONE) == PLATFORM_SUCCESS ?
TAPASCO_SUCCESS : TAPASCO_FAILURE;
}
tapasco_res_t tapasco_device_copy_from(tapasco_dev_ctx_t *dev_ctx, tapasco_handle_t src,
void *dst, size_t len,
tapasco_device_copy_flag_t const flags)
{
LOG(LALL_MEM, "src = 0x%08x, len = %zd, flags = %d", (unsigned)src, len, flags);
if (flags & TAPASCO_DEVICE_COPY_NONBLOCKING)
return TAPASCO_ERR_NONBLOCKING_MODE_NOT_SUPPORTED;
if (flags)
return TAPASCO_ERR_NOT_IMPLEMENTED;
return platform_read_mem(src, len, dst, PLATFORM_MEM_FLAGS_NONE) == PLATFORM_SUCCESS ?
TAPASCO_SUCCESS : TAPASCO_FAILURE;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment