|
| 1 | +/** |
| 2 | + * Copyright (C) 2018 by NEC Corporation |
| 3 | + * This file is part of the VEOS.] |
| 4 | + * |
| 5 | + * |
| 6 | + * The VEOS is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public |
| 8 | + * License as published by the Free Software Foundation; either version |
| 9 | + * 2.1 of the License, or (at your option) any later version. |
| 10 | + * The VEOS is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with the VEOS; if not, see * <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | +/** |
| 19 | + * @file sys_vepci.c |
| 20 | + * @brief Handle PCI operation system call on VE |
| 21 | + * |
| 22 | + * @internal |
| 23 | + * @author VEPCI |
| 24 | + */ |
| 25 | + |
| 26 | +#include <stdio.h> |
| 27 | +#include <stdlib.h> |
| 28 | +#include <sys/types.h> |
| 29 | +#include <unistd.h> |
| 30 | +#include <errno.h> |
| 31 | +#include "handle.h" |
| 32 | +#include "libvepseudo.h" |
| 33 | +#include "sysve_os.h" |
| 34 | + |
| 35 | +/** |
| 36 | + * @brief This function is handler of ve_register/unregister_mem_to/from_pci |
| 37 | + * and ve_register/unregister_pci_to/from_vehva |
| 38 | + * @param[in] handle Handle for VE driver interface |
| 39 | + * @param[in] addr Address to register or unregister |
| 40 | + * @param[in] size Size of address |
| 41 | + * @param[in] msg_id Identifier of request operation |
| 42 | + * |
| 43 | + * @return Return Address or 0 on success. Negative value on failure. |
| 44 | + */ |
| 45 | +int64_t ve_sys_pcireq(veos_handle *handle, uint64_t addr, size_t size, |
| 46 | + enum pseudo_veos_msg_id msg_id) |
| 47 | +{ |
| 48 | + int64_t ret = 0; |
| 49 | + PseudoVeosMessage *reply_msg = NULL; |
| 50 | + struct pcicmd *cmd = NULL; |
| 51 | + ProtobufCBinaryData request_msg = {0}; |
| 52 | + |
| 53 | + PSEUDO_TRACE("invoked"); |
| 54 | + |
| 55 | + cmd = (struct pcicmd *)calloc(1, sizeof(struct pcicmd)); |
| 56 | + if (NULL == cmd) { |
| 57 | + PSEUDO_DEBUG("Fail to allocate memory for " |
| 58 | + "amm request block\n"); |
| 59 | + return -ENOMEM; |
| 60 | + } |
| 61 | + |
| 62 | + /* Populating struct ve_mmap_cmd buffer to Generate IPC Command */ |
| 63 | + cmd->addr = addr; |
| 64 | + cmd->size = size; |
| 65 | + |
| 66 | + PSEUDO_DEBUG("Sending request for PCI operation to VEOS for addr(0x%lx) " |
| 67 | + "size(0x%lx)", |
| 68 | + cmd->addr, cmd->size); |
| 69 | + |
| 70 | + /* Populate parameters for ve_mmap req */ |
| 71 | + request_msg.len = sizeof(struct pcicmd); |
| 72 | + request_msg.data = (uint8_t *)cmd; |
| 73 | + ret = ve_request_veos(handle, msg_id, &request_msg, &reply_msg); |
| 74 | + if (ret < 0) { |
| 75 | + PSEUDO_ERROR("Failed to request PCI operation to VEOS: %s", |
| 76 | + strerror(-ret)); |
| 77 | + goto hndl_return; |
| 78 | + } |
| 79 | + |
| 80 | + ret = (int64_t)reply_msg->syscall_retval; |
| 81 | + if (reply_msg->syscall_retval < 0) { |
| 82 | + PSEUDO_DEBUG("Error(%s) occurred on VE OS while PCI operation for addr(0x%lx)", |
| 83 | + strerror(-ret), addr); |
| 84 | + } else { |
| 85 | + PSEUDO_DEBUG("retval:0x%lx PCI operation successfully done on VE", |
| 86 | + reply_msg->syscall_retval); |
| 87 | + } |
| 88 | + pseudo_veos_message__free_unpacked(reply_msg, NULL); |
| 89 | +hndl_return: |
| 90 | + if (cmd) |
| 91 | + free(cmd); |
| 92 | + PSEUDO_TRACE("returned(%ld)", ret); |
| 93 | + return ret; |
| 94 | +} |
0 commit comments