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

Complete ioctl default operations

* read_mem and write_mem work now, too
* changed a few things, e.g., handing out DMA address now, instead of id
* works with platform-stress-alloc test (mode 1)
* default implementation should now be working
parent b8fce9f1
......@@ -42,7 +42,14 @@ platform_res_t default_read_mem(platform_devctx_t const *devctx,
void *data,
platform_mem_flags_t const flags)
{
DEVLOG(devctx->dev_id, LPLL_MM, "reading from device at 0x%08lx with flags 0x%08lx", addr, (ulong)flags);
struct tlkm_copy_cmd cmd = { .length = length, .dev_addr = addr, .user_addr = data };
long ret = ioctl(devctx->fd_ctrl, TLKM_DEV_IOCTL_COPYFROM, &cmd);
if (ret) {
DEVERR(devctx->dev_id, "error reading device memory: %s (%d)", strerror(errno), errno);
return PERR_TLKM_ERROR;
}
return PLATFORM_SUCCESS;
}
platform_res_t default_write_mem(platform_devctx_t const *devctx,
......@@ -51,7 +58,14 @@ platform_res_t default_write_mem(platform_devctx_t const *devctx,
void const *data,
platform_mem_flags_t const flags)
{
DEVLOG(devctx->dev_id, LPLL_MM, "writing to device at 0x%08lx with flags 0x%08lx", addr, (ulong)flags);
struct tlkm_copy_cmd cmd = { .length = length, .dev_addr = addr, .user_addr = (void *)data };
long ret = ioctl(devctx->fd_ctrl, TLKM_DEV_IOCTL_COPYTO, &cmd);
if (ret) {
DEVERR(devctx->dev_id, "error writing device memory: %s (%d)", strerror(errno), errno);
return PERR_TLKM_ERROR;
}
return PLATFORM_SUCCESS;
}
platform_res_t default_read_ctl(platform_devctx_t const *devctx,
......
......@@ -80,10 +80,10 @@ static inline
long zynq_ioctl_copyto(struct tlkm_device_inst *inst, struct tlkm_copy_cmd *cmd)
{
struct dma_buf_t *dmab;
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "copyto: len = %zu, id = %ld, p = 0x%08lx",
cmd->length, (long)cmd->dev_addr, (unsigned long) cmd->user_addr);
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "copyto: len = %zu, dma = 0x%08lx, p = 0x%08lx",
cmd->length, (ulong)cmd->dev_addr, (ulong) cmd->user_addr);
// allocate, if necessary
if (cmd->dev_addr < 0 || ! (dmab = zynq_dmamgmt_get(cmd->dev_addr))) {
if (cmd->dev_addr < 0 || ! (dmab = zynq_dmamgmt_get(zynq_dmamgmt_get_id(cmd->dev_addr)))) {
int ret;
struct tlkm_mm_cmd mm_cmd = { .sz = cmd->length, };
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "allocating %zu bytes for transfer", cmd->length);
......@@ -92,7 +92,7 @@ long zynq_ioctl_copyto(struct tlkm_device_inst *inst, struct tlkm_copy_cmd *cmd)
if (ret) return ret;
}
DEVLOG(inst->dev_id, TLKM_LF_IOCTL, "cmd->dev_addr = %ld", (long)cmd->dev_addr);
dmab = zynq_dmamgmt_get(cmd->dev_addr);
dmab = zynq_dmamgmt_get(zynq_dmamgmt_get_id(cmd->dev_addr));
if (! dmab || ! dmab->kvirt_addr) {
DEVERR(inst->dev_id, "something went wrong in the allocation");
return -ENOMEM;
......@@ -114,9 +114,9 @@ long zynq_ioctl_copyfrom(struct tlkm_device_inst *inst, struct tlkm_copy_cmd *cm
struct dma_buf_t *dmab;
DEVLOG(inst->dev_id, TLKM_LF_DEVICE, "copyfrom: len = %zu, id = %ld, p = 0x%08lx",
cmd->length, (long)cmd->dev_addr, (unsigned long) cmd->user_addr);
dmab = zynq_dmamgmt_get(cmd->dev_addr);
dmab = zynq_dmamgmt_get(zynq_dmamgmt_get_id(cmd->dev_addr));
if (! dmab || ! dmab->kvirt_addr) {
DEVERR(inst->dev_id, "could not get dma buffer with id = %ld", (long)cmd->dev_addr);
DEVERR(inst->dev_id, "could not get dma buffer with dma = 0x%08lx", (ulong)cmd->dev_addr);
return -EINVAL;
}
if (copy_to_user((void __user *) cmd->user_addr, dmab->kvirt_addr, cmd->length)) {
......
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