Per Åstrand | ec3f2b0 | 2021-06-09 10:43:38 +0200 | [diff] [blame] | 1 | /* |
Kshitij Sisodia | f9efe0d | 2022-09-30 16:42:50 +0100 | [diff] [blame^] | 2 | * SPDX-FileCopyrightText: Copyright 2020-2022 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Per Åstrand | ec3f2b0 | 2021-06-09 10:43:38 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| 7 | * not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #include <uapi/ethosu.h> |
| 20 | |
| 21 | #include <ethosu.hpp> |
| 22 | #include <exception> |
| 23 | #include <iostream> |
| 24 | |
| 25 | #include <fcntl.h> |
| 26 | #include <poll.h> |
| 27 | #include <sys/ioctl.h> |
| 28 | #include <sys/mman.h> |
| 29 | #include <unistd.h> |
| 30 | |
| 31 | namespace EthosU { |
| 32 | int eopen(const char *p, int) { |
| 33 | std::cout << "Opened filedescriptor for " << p; |
| 34 | return 1; |
| 35 | } |
| 36 | |
| 37 | int eclose(int) { |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | void *emmap(void *, size_t length, int, int, int, off_t) { |
| 42 | void *d = malloc(length); |
| 43 | return d; |
| 44 | } |
| 45 | |
| 46 | int emunmap(void *addr, size_t) { |
| 47 | free(addr); |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | int eioctl(int, unsigned long cmd, void *) { |
| 52 | int result = 0; |
| 53 | using namespace EthosU; |
| 54 | |
| 55 | switch (cmd) { |
| 56 | case ETHOSU_IOCTL_PING: |
| 57 | return result; |
| 58 | case ETHOSU_IOCTL_VERSION_REQ: |
| 59 | return result; |
| 60 | case ETHOSU_IOCTL_CAPABILITIES_REQ: |
| 61 | return result; |
| 62 | case ETHOSU_IOCTL_BUFFER_CREATE: |
| 63 | return result; |
| 64 | case ETHOSU_IOCTL_BUFFER_SET: |
| 65 | return result; |
| 66 | case ETHOSU_IOCTL_BUFFER_GET: |
| 67 | return result; |
| 68 | case ETHOSU_IOCTL_NETWORK_CREATE: |
| 69 | return result; |
| 70 | case ETHOSU_IOCTL_INFERENCE_CREATE: |
| 71 | return result; |
| 72 | case ETHOSU_IOCTL_INFERENCE_STATUS: |
| 73 | return result; |
| 74 | default: |
| 75 | throw EthosU::Exception("Unknown IOCTL"); |
| 76 | } |
| 77 | } |
| 78 | |
Davide Grohmann | e446b42 | 2021-10-19 15:33:23 +0200 | [diff] [blame] | 79 | int eppoll(struct pollfd *, nfds_t, const struct timespec *tmo_p, const sigset_t *) { |
| 80 | if (tmo_p == NULL) { |
| 81 | // sleep one second |
| 82 | usleep(1000000ul); |
| 83 | } else { |
| 84 | unsigned long t = tmo_p->tv_sec / 2; // sleep half of the time |
| 85 | t = t * 1000ul * 1000ul; // sec to microsec |
| 86 | usleep(t); |
| 87 | } |
Per Åstrand | ec3f2b0 | 2021-06-09 10:43:38 +0200 | [diff] [blame] | 88 | return 1; |
| 89 | } |
| 90 | } // namespace EthosU |