Commit b4c05351 authored by Jens Korinth's avatar Jens Korinth
Browse files

WIP: Bugfixes in TLKM

parent 0615ad96
......@@ -27,10 +27,9 @@ set (CMAKE_SKIP_RPATH true)
set (TAPASCO_HOME "$ENV{TAPASCO_HOME}")
set (TAPASCO_TLKM_DIR "${TAPASCO_HOME}/tlkm")
set (TAPASCO_COMMON_DIR "${TAPASCO_HOME}/common")
set (TAPASCO_LIB_DIR "${TAPASCO_HOME}/lib")
set (TAPASCO_PLATFORM_DIR "${TAPASCO_HOME}/platform")
set (TAPASCO_PLATFORM_LIBS_DIR "${TAPASCO_PLATFORM_DIR}/lib")
set (TAPASCO_ARCH_DIR "${TAPASCO_HOME}/arch")
set (TAPASCO_ARCH_LIBS_DIR "${TAPASCO_ARCH_DIR}/lib")
# set target architecture
if (NOT EXISTS "$ENV{TAPASCO_TARGET}")
......@@ -41,8 +40,8 @@ else (NOT EXISTS "$ENV{TAPASCO_TARGET}")
endif (NOT EXISTS "$ENV{TAPASCO_TARGET}")
# static libraries
set (TAPASCO_PLATFORM_LIB "${TAPASCO_PLATFORM_LIBS_DIR}/${TAPASCO_TARGET}/static/libplatform.a")
set (TAPASCO_ARCH_LIB "${TAPASCO_ARCH_LIBS_DIR}/${TAPASCO_TARGET}/static/libtapasco.a")
set (TAPASCO_PLATFORM_LIB "${TAPASCO_LIB_DIR}/${TAPASCO_TARGET}/static/libplatform.a")
set (TAPASCO_ARCH_LIB "${TAPASCO_LIB_DIR}/${TAPASCO_TARGET}/static/libtapasco.a")
# basic include directories
set (TAPASCO_INCDIRS
......@@ -55,14 +54,12 @@ set (TAPASCO_INCDIRS
# directories for static libraries
set (TAPASCO_STATICLINKDIRS
"${TAPASCO_PLATFORM_DIR}/lib/${TAPASCO_TARGET}/static"
"${TAPASCO_ARCH_DIR}/lib/${TAPASCO_TARGET}/static"
"${TAPASCO_LIB_DIR}/${TAPASCO_TARGET}/static"
)
# directories for dynamic link libraries
set (TAPASCO_LINKDIRS
"${TAPASCO_PLATFORM_DIR}/lib/${TAPASCO_TARGET}"
"${TAPASCO_ARCH_DIR}/lib/${TAPASCO_TARGET}"
"${TAPASCO_LIB_DIR}/${TAPASCO_TARGET}"
)
# default C flags
......
......@@ -26,6 +26,9 @@ set(CMNSRCS "${CMNDIR}/src/platform_addr_map.c"
"${GCMNDIR}/src/gen_queue.c")
set(ZYNQSRCS "zynq/src/platform_zynq.c")
set(TAPASCO_CFLAGS "-Wall -Werror -std=gnu11 -g")
set(TAPASCO_LDFLAGS "-flto -fno-rtti -static")
link_directories(${TAPASCO_STATICLINKDIRS})
include_directories(
"include"
......
......@@ -70,4 +70,15 @@ platform_res_t default_write_ctl(platform_devctx_t const *devctx,
void const *data,
platform_ctl_flags_t const flags);
static inline
void default_dops(platform_device_operations_t *dops)
{
dops->alloc = default_alloc;
dops->dealloc = default_dealloc;
dops->read_mem = default_read_mem;
dops->write_mem = default_write_mem;
dops->read_ctl = default_read_ctl;
dops->write_ctl = default_write_ctl;
}
#endif /* PLATFORM_DEVICE_OPERATIONS_H__ */
......@@ -160,7 +160,7 @@ void platform_deinit(platform_ctx_t *ctx)
LOG(LPLL_INIT, "so long & thanks for all the fish, bye");
}
platform_res_t platform_enum_devs(platform_ctx_t *ctx,
platform_res_t platform_enum_devices(platform_ctx_t *ctx,
size_t *num_devs,
platform_device_info_t **devs)
{
......@@ -196,16 +196,17 @@ platform_res_t platform_create_device(platform_ctx_t *ctx,
}
LOG(LPLL_TLKM, "created device #%03u, initializing device context ...");
if ((res = platform_devctx_init(ctx, dev_id, mode, &ctx->devctx[dev_id])) != PLATFORM_SUCCESS) {
ERR("could not initialized device context for #%03u: %s (%d)",
ERR("could not initialize device context for #%03u: %s (%d)",
dev_id, platform_strerror(r), r);
platform_destroy_device(ctx, dev_id);
goto err_pdev;
}
if (pdctx) *pdctx = ctx->devctx[dev_id];
LOG(LPLL_DEVICE, "successfully initialized device #%03u", dev_id);
return PLATFORM_SUCCESS;
err_pdev:
return r;
return res;
}
void platform_destroy_device(platform_ctx_t *ctx, platform_dev_id_t const dev_id)
......
......@@ -8,6 +8,7 @@
#include <platform_devctx.h>
#include <platform_types.h>
#include <platform_logging.h>
#include <platform_info.h>
#include <platform_devfiles.h>
#include <platform_addr_map.h>
#include <platform_signaling.h>
......@@ -33,8 +34,9 @@ platform_res_t platform_devctx_init(platform_ctx_t *ctx,
LOG(LPLL_DEVICE, "preparing device #%03u ...", dev_id);
devctx->dev_id = dev_id;
devctx->mode = mode;
default_dops(&devctx->dops);
if ((res = platform_device_info(ctx, dev_id, &devctx->dev_info))) {
if ((res = platform_device_info(ctx, dev_id, &devctx->dev_info)) != PLATFORM_SUCCESS) {
ERR("device #%03u: could not get device information: %s (%d)",
dev_id, platform_strerror(res), res);
free (devctx);
......@@ -53,6 +55,7 @@ platform_res_t platform_devctx_init(platform_ctx_t *ctx,
dev_id, platform_strerror(res), res);
goto err_info;
}
log_device_info(&devctx->info);
res = platform_addr_map_init(devctx, &devctx->info, &devctx->addrmap);
if (res != PLATFORM_SUCCESS) {
......
......@@ -45,7 +45,20 @@ platform_res_t default_read_ctl(platform_devctx_t const *devctx,
void *data,
platform_ctl_flags_t const flags)
{
long ret = 0;
DEVLOG(devctx->dev_id, LPLL_TLKM, "reading %zu bytes from 0x%08llx with flags 0x%08llx",
length, (u64)addr, (u64)flags);
struct tlkm_copy_cmd cmd = {
.length = length,
.user_addr = (void *)data,
.dev_addr = addr,
};
if ((ret = ioctl(devctx->fd_ctrl, TLKM_DEV_IOCTL_READ, &cmd))) {
DEVERR(devctx->dev_id, "error writing to 0x%08llx: %s (%d)",
(u64)addr, strerror(errno), errno);
return PERR_TLKM_ERROR;
}
return PLATFORM_SUCCESS;
}
platform_res_t default_write_ctl(platform_devctx_t const *devctx,
......
......@@ -136,7 +136,7 @@ platform_res_t read_info_from_status_core(platform_devctx_t const *p,
return PLATFORM_SUCCESS;
}
static inline
inline
void log_device_info(platform_info_t const *info)
{
#ifndef NDEBUG
......
......@@ -57,4 +57,6 @@ size_t platform_info_pe_count(platform_info_t const *info,
return ret;
}
void log_device_info(platform_info_t const *info);
#endif /* PLATFORM_INFO_H__ */
......@@ -10,14 +10,15 @@ endif ("$ENV{TAPASCO_HOME}" STREQUAL "")
include ("$ENV{TAPASCO_HOME}/cmake/Tapasco.cmake")
include_directories(${TAPASCO_INCDIRS})
link_directories(${TAPASCO_LINKDIRS} ${TAPASCO_STATICLINKDIRS})
link_directories(${TAPASCO_STATICLINKDIRS})
add_executable(platform-stress-alloc platform_stress_alloc.c ${TAPASCO_PLATFORM_LIB})
set_target_properties(platform-stress-alloc PROPERTIES
LINK_SEARCH_START_STATIC 1
LINK_SEARCH_END_STATIC 1
LINKER_FLAGS ${TAPASCO_LDFLAGS})
target_link_libraries(platform-stress-alloc atomic m pthread platform)
set_target_properties(platform-stress-alloc PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
target_link_libraries(platform-stress-alloc m platform atomic pthread)
add_executable(platform-stress-ioctl platform_stress_ioctl.c ${TAPASCO_PLATFORM_LIB})
set_target_properties(platform-stress-ioctl PROPERTIES LINK_SEARCH_START_STATIC 1 LINK_SEARCH_END_STATIC 1)
target_link_libraries(platform-stress-ioctl m platform atomic pthread)
add_executable(platform-slots platform_slots.c ${TAPASCO_PLATFORM_LIB})
target_link_libraries(platform-slots pthread platform)
......@@ -25,6 +26,7 @@ target_link_libraries(platform-slots pthread platform)
add_executable(iplatform iplatform.c)
target_link_libraries(iplatform pthread platform ncurses ${TAPASCO_PLATFORM_LIB})
set_target_properties(platform-stress-alloc platform-slots iplatform PROPERTIES COMPILE_FLAGS ${TAPASCO_CFLAGS})
set_target_properties(platform-stress-alloc platform-stress-ioctl platform-slots iplatform PROPERTIES COMPILE_FLAGS ${TAPASCO_CFLAGS})
set_target_properties(platform-stress-alloc platform-stress-ioctl platform-slots iplatform PROPERTIES LINKER_FLAGS ${TAPASCO_LDFLAGS})
install(TARGETS platform-stress-alloc platform-slots
RUNTIME DESTINATION bin/${TAPASCO_TARGET})
//
// Copyright (C) 2014 Jens Korinth, TU Darmstadt
// Copyright (C) 2014-2018 Jens Korinth, TU Darmstadt
//
// This file is part of Tapasco (TPC).
// 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
......@@ -33,7 +33,7 @@ static inline int check(platform_res_t res)
if (res != PLATFORM_SUCCESS) {
fprintf(stderr, "platform-error: %s (%d)\n", platform_strerror(res), res);
}
return res;
return res == PLATFORM_SUCCESS;
}
static inline int clock_period(void)
......
......@@ -140,10 +140,12 @@ int main(int argc, char **argv)
pthread_t threads[thread_count];
srand(time(NULL));
if (!check(platform_init(&ctx)))
if (!check(platform_init(&ctx))) {
fprintf(stderr, "error during init, exiting");
exit(EXIT_FAILURE);
}
if (!check(platform_create_device(ctx, 0, PLATFORM_EXCLUSIVE_ACCESS, &devctx))) {
platform_destroy_device(ctx, 0);
fprintf(stderr, "error during init device, exiting");
platform_deinit(ctx);
exit(EXIT_FAILURE);
}
......
#include <stdio.h>
#include <platform.h>
#define NUM_RUNS 100
static
void stress(platform_ctx_t *ctx, platform_dev_id_t dev_id)
{
platform_res_t res = PLATFORM_SUCCESS;
for (size_t i = NUM_RUNS; i > 0 && res == PLATFORM_SUCCESS; --i) {
res = platform_create_device(ctx, dev_id, PLATFORM_EXCLUSIVE_ACCESS, NULL);
if (res == PLATFORM_SUCCESS)
platform_destroy_device(ctx, dev_id);
}
}
int main(int argc, char *argv[])
{
platform_ctx_t *ctx;
size_t num_devs = 0;
platform_device_info_t *devs;
platform_res_t res = platform_init(&ctx);
if (res != PLATFORM_SUCCESS) {
fprintf(stderr, "could not initialize platform: %s (%d)", platform_strerror(res), res);
exit(EXIT_FAILURE);
}
platform_enum_devices(ctx, &num_devs, &devs);
for (size_t i = 0; i < num_devs; ++i) {
printf("Stressing device #%03u ...\n", i);
stress(ctx, i);
}
platform_deinit(ctx);
}
KERNEL=="tlkm*" OWNER="xilinx" GROUP="xilinx"
......@@ -89,9 +89,8 @@ err_miscdev:
void tlkm_control_exit(struct tlkm_control *pctl)
{
if (pctl) {
dev_id_t dev_id = pctl->dev_id;
exit_miscdev(pctl);
LOG(TLKM_LF_CONTROL, "destroyed control for device #%03u", pctl->dev_id);
kfree(pctl);
LOG(TLKM_LF_CONTROL, "destroyed control for device #%03u", dev_id);
}
}
......@@ -58,6 +58,9 @@ long tlkm_device_ioctl(struct file *fp, unsigned int ioctl, unsigned long data)
{
if (ioctl == TLKM_DEV_IOCTL_INFO) {
return tlkm_device_ioctl_info(fp, ioctl, (struct tlkm_device_info __user *)data);
} else {
tlkm_device_ioctl_f ioctl_f = device_from_file(fp)->ioctl;
BUG_ON(!ioctl_f);
return ioctl_f(device_inst_from_file(fp), ioctl, data);
}
return device_from_file(fp)->ioctl(device_inst_from_file(fp), ioctl, data);
}
......@@ -13,27 +13,27 @@ static int init_iomapping(void)
int retval = 0;
_zynq_dev.gp_map[0] = ioremap_nocache(ZYNQ_PLATFORM_GP0_BASE, ZYNQ_PLATFORM_GP0_SIZE);
if (IS_ERR(_zynq_dev.gp_map[0])) {
ERR("could not ioremap the AXI register space at 0x%08lx-0x%08lx",
ZYNQ_PLATFORM_GP0_BASE,
ZYNQ_PLATFORM_GP0_BASE + ZYNQ_PLATFORM_GP0_SIZE - 1);
ERR("could not ioremap the AXI register space at 0x%08llx-0x%08llx",
(u64)ZYNQ_PLATFORM_GP0_BASE,
(u64)(ZYNQ_PLATFORM_GP0_BASE + ZYNQ_PLATFORM_GP0_SIZE - 1));
retval = PTR_ERR(_zynq_dev.gp_map[0]);
goto err_gp0;
}
_zynq_dev.gp_map[1] = ioremap_nocache(ZYNQ_PLATFORM_GP1_BASE, ZYNQ_PLATFORM_GP1_SIZE);
if (IS_ERR(_zynq_dev.gp_map[1])) {
ERR("could not ioremap the AXI register space at 0x%08lx-0x%08lx",
ZYNQ_PLATFORM_GP1_BASE,
ZYNQ_PLATFORM_GP1_BASE + ZYNQ_PLATFORM_GP1_SIZE - 1);
ERR("could not ioremap the AXI register space at 0x%08llx-0x%08llx",
(u64)ZYNQ_PLATFORM_GP1_BASE,
(u64)(ZYNQ_PLATFORM_GP1_BASE + ZYNQ_PLATFORM_GP1_SIZE - 1));
retval = PTR_ERR(_zynq_dev.gp_map[1]);
goto err_gp1;
}
_zynq_dev.tapasco_status = ioremap_nocache(ZYNQ_PLATFORM_STATUS_BASE, ZYNQ_PLATFORM_STATUS_SIZE);
if (IS_ERR(_zynq_dev.tapasco_status)) {
ERR("could not ioremap the AXI register space at 0x%08lx-0x%08lx",
ZYNQ_PLATFORM_STATUS_BASE,
ZYNQ_PLATFORM_STATUS_BASE + ZYNQ_PLATFORM_STATUS_SIZE);
ERR("could not ioremap the AXI register space at 0x%08llx-0x%08llx",
(u64)(ZYNQ_PLATFORM_STATUS_BASE),
(u64)(ZYNQ_PLATFORM_STATUS_BASE + ZYNQ_PLATFORM_STATUS_SIZE));
retval = PTR_ERR(_zynq_dev.tapasco_status);
goto err_tapasco_status;
}
......
Supports Markdown
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