Skip to content

Commit

Permalink
Import feature-vepci.
Browse files Browse the repository at this point in the history
  • Loading branch information
veos-sxarr committed Nov 29, 2018
1 parent cd43779 commit 4cedbbb
Show file tree
Hide file tree
Showing 15 changed files with 564 additions and 64 deletions.
12 changes: 12 additions & 0 deletions include/comm_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ struct userdma {
uint64_t dmactl;
};

/**
* @brief Structure to store to store information for PCI operation.
*/
struct pcicmd {
uint64_t addr;
size_t size;
};

/**
* @brief command ID's used to communicate b/w VEOS and PSEUDO side
*/
Expand Down Expand Up @@ -618,6 +626,10 @@ enum pseudo_veos_msg_id {
CMD_VHSHM,
MAP_DMADES,
UNMAP_DMADES,
REGIS_PCIATB,
UNREG_PCIATB,
REGIS_DMAATB,
UNREG_DMAATB,
PSEUDO_VEOS_MAX_MSG_NUM,
CMD_INVALID = -1,
};
Expand Down
6 changes: 5 additions & 1 deletion include/sysve.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ enum sysve_command {
VE_SYSVE_UNMAP_DMADES,
VE_SYSVE_AIO_READ = 0x60,
VE_SYSVE_AIO_WRITE,
VE_SYSVE_AIO_WAIT
VE_SYSVE_AIO_WAIT,
VE_SYSVE_REGISTER_VEMVA_TO_PCIATB = 0x70,
VE_SYSVE_UNREGISTER_VHSAA_FROM_PCIATB,
VE_SYSVE_REGISTER_VHSAA_TO_DMAATB,
VE_SYSVE_UNREGISTER_VEHVA_FROM_DMAATB
};

#endif
4 changes: 3 additions & 1 deletion lib/libvepseudo/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ libpseudocommon_la_SOURCES = \
sysve_os.h \
list.h \
sys_veaio.c \
sys_veaio.h
sys_veaio.h \
sys_pci.c \
sys_pci.h

BUILT_SOURCES = \
ve_syscall_no.h \
Expand Down
17 changes: 17 additions & 0 deletions lib/libvepseudo/common/sys_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "pseudo_veshm.h"
#include "pseudo_vhshm.h"
#include "sys_veaio.h"
#include "sys_pci.h"

/**
* @brief This function will be invoked to handle the MONC interrupt
Expand Down Expand Up @@ -1457,6 +1458,22 @@ ret_t ve_sysve(int syscall_num, char *syscall_name, veos_handle *handle)
case VE_SYSVE_AIO_WAIT:
retval = sys_ve_aio_wait(handle, (void *)args[1]);
break;
case VE_SYSVE_REGISTER_VEMVA_TO_PCIATB:
retval = ve_sys_pcireq(handle,(uint64_t)args[1],
(size_t)args[2], REGIS_PCIATB);
break;
case VE_SYSVE_UNREGISTER_VHSAA_FROM_PCIATB:
retval = ve_sys_pcireq(handle,(uint64_t)args[1],
(size_t)args[2], UNREG_PCIATB);
break;
case VE_SYSVE_REGISTER_VHSAA_TO_DMAATB:
retval = ve_sys_pcireq(handle,(uint64_t)args[1],
(size_t)args[2], REGIS_DMAATB);
break;
case VE_SYSVE_UNREGISTER_VEHVA_FROM_DMAATB:
retval = ve_sys_pcireq(handle,(uint64_t)args[1],
(size_t)args[2], UNREG_DMAATB);
break;
default:
/* write return value */
retval = -EINVAL;
Expand Down
94 changes: 94 additions & 0 deletions lib/libvepseudo/common/sys_pci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Copyright (C) 2018 by NEC Corporation
* This file is part of the VEOS.]
*
*
* The VEOS 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
* 2.1 of the License, or (at your option) any later version.
* The VEOS 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 the VEOS; if not, see * <http://www.gnu.org/licenses/>.
*/
/**
* @file sys_vepci.c
* @brief Handle PCI operation system call on VE
*
* @internal
* @author VEPCI
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "handle.h"
#include "libvepseudo.h"
#include "sysve_os.h"

/**
* @brief This function is handler of ve_register/unregister_mem_to/from_pci
* and ve_register/unregister_pci_to/from_vehva
* @param[in] handle Handle for VE driver interface
* @param[in] addr Address to register or unregister
* @param[in] size Size of address
* @param[in] msg_id Identifier of request operation
*
* @return Return Address or 0 on success. Negative value on failure.
*/
int64_t ve_sys_pcireq(veos_handle *handle, uint64_t addr, size_t size,
enum pseudo_veos_msg_id msg_id)
{
int64_t ret = 0;
PseudoVeosMessage *reply_msg = NULL;
struct pcicmd *cmd = NULL;
ProtobufCBinaryData request_msg = {0};

PSEUDO_TRACE("invoked");

cmd = (struct pcicmd *)calloc(1, sizeof(struct pcicmd));
if (NULL == cmd) {
PSEUDO_DEBUG("Fail to allocate memory for "
"amm request block\n");
return -ENOMEM;
}

/* Populating struct ve_mmap_cmd buffer to Generate IPC Command */
cmd->addr = addr;
cmd->size = size;

PSEUDO_DEBUG("Sending request for PCI operation to VEOS for addr(0x%lx) "
"size(0x%lx)",
cmd->addr, cmd->size);

/* Populate parameters for ve_mmap req */
request_msg.len = sizeof(struct pcicmd);
request_msg.data = (uint8_t *)cmd;
ret = ve_request_veos(handle, msg_id, &request_msg, &reply_msg);
if (ret < 0) {
PSEUDO_ERROR("Failed to request PCI operation to VEOS: %s",
strerror(-ret));
goto hndl_return;
}

ret = (int64_t)reply_msg->syscall_retval;
if (reply_msg->syscall_retval < 0) {
PSEUDO_DEBUG("Error(%s) occurred on VE OS while PCI operation for addr(0x%lx)",
strerror(-ret), addr);
} else {
PSEUDO_DEBUG("retval:0x%lx PCI operation successfully done on VE",
reply_msg->syscall_retval);
}
pseudo_veos_message__free_unpacked(reply_msg, NULL);
hndl_return:
if (cmd)
free(cmd);
PSEUDO_TRACE("returned(%ld)", ret);
return ret;
}
39 changes: 39 additions & 0 deletions lib/libvepseudo/common/sys_pci.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (C) 2018 NEC Corporation
* This file is part of the VEOS.
*
* The VEOS 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
* 2.1 of the License, or (at your option) any later version.
*
* The VEOS 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 the VEOS; if not, see
* <http://www.gnu.org/licenses/>.
*/

/**
* @file pseudo_vepci.h
* @brief Header for VEPCI in psedo process
*
* @internal
* @author VEPCI
*/

#ifndef __PSEUDO_VEPCI_H
#define __PSEUDO_VEPCI_H

#include <sys/types.h>
#include "sys_common.h"
#include "comm_request.h"

int64_t ve_sys_pcireq(veos_handle *, uint64_t, size_t, enum pseudo_veos_msg_id);
int ve_sys_pciunmap(veos_handle *, uint64_t, size_t);
int64_t ve_sys_map_pciatb(veos_handle *, uint64_t, size_t);
int ve_sys_unmap_pciatb(veos_handle *, uint64_t, size_t);

#endif
7 changes: 4 additions & 3 deletions lib/libvepseudo/common/sysve_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,12 @@ static int ve_sys_map_reg(uint64_t reg)
*
* @author libsysve
*/
int ve_request_veos(veos_handle *handle,
int64_t ve_request_veos(veos_handle *handle,
enum pseudo_veos_msg_id id,
ProtobufCBinaryData *data,
PseudoVeosMessage **reply_msg)
{
int ret;
int64_t ret;
PseudoVeosMessage msg = PSEUDO_VEOS_MESSAGE__INIT;
PseudoVeosMessage *recv_msg;
size_t msg_len;
Expand Down Expand Up @@ -674,12 +674,13 @@ int ve_request_veos(veos_handle *handle,
} else {
pseudo_veos_message__free_unpacked(recv_msg, NULL);
}

ret = recv_msg->syscall_retval;

free(msg_buf);
err_ret_nofree:
PSEUDO_TRACE("Exiting");

return ret;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/libvepseudo/common/sysve_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@

#include "sys_common.h"
#include <veos_defs.h>
#include "proto_buff_schema.pb-c.h"
#include "comm_request.h"

int ve_sys_get_pci_sync(veos_handle *, uint8_t, uint64_t *, uint64_t *);
int ve_sys_get_fixed_vehva(veos_handle *, uint64_t, uint64_t *);
int ve_sys_set_user_reg(veos_handle *, uint64_t, uint64_t);
ssize_t ve_sys_get_ve_info(veos_handle *, char *, char *, size_t);
int ve_sys_map_dmades(veos_handle *, uint64_t * ,uint64_t *);
int ve_sys_unmap_dmades(veos_handle *, uint64_t );
int64_t ve_request_veos(veos_handle *, enum pseudo_veos_msg_id, ProtobufCBinaryData *, PseudoVeosMessage **reply_msg);

#endif
4 changes: 3 additions & 1 deletion src/veos/main/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ libvemain_a_SOURCES = \
veos.h \
veos_init.c \
veos_ipc.c \
veos_ipc.h \
veos_handler.c \
veos_handler.h \
veos_main.c \
sysve.c \
userdma.c
userdma.c \
pci.c

libvemain_a_CFLAGS = \
-g -Wall -Werror -D_GNU_SOURCE -std=gnu99 \
Expand Down
Loading

0 comments on commit 4cedbbb

Please sign in to comment.