From b423230a0381ccfdf83573e516fc2843013e3069 Mon Sep 17 00:00:00 2001 From: Yizhi Liu Date: Sat, 23 Nov 2019 20:32:29 -0800 Subject: [PATCH 1/2] [License] move cma_api to 3rdparty. separate BSD 2-clause and 3-clause --- 3rdparty/cma/cma_api_impl.h | 179 +++++++++++++++++++++++++++++++++++ LICENSE | 8 +- vta/src/de10nano/cma_api.cc | 182 +++--------------------------------- 3 files changed, 200 insertions(+), 169 deletions(-) create mode 100644 3rdparty/cma/cma_api_impl.h diff --git a/3rdparty/cma/cma_api_impl.h b/3rdparty/cma/cma_api_impl.h new file mode 100644 index 000000000000..12c0e3b27efc --- /dev/null +++ b/3rdparty/cma/cma_api_impl.h @@ -0,0 +1,179 @@ +/* + * The MIT License (MIT) + * + * COPYRIGHT (C) 2017 Institute of Electronics and Computer Science (EDI), Latvia. + * AUTHOR: Rihards Novickis (rihards.novickis@edi.lv) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +/*! + * Copyright (c) 2018 by Contributors + * \file cma_api.cc + * \brief Application layer implementation for contigous memory allocation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cma_api.h" + +#ifndef CMA_IOCTL_MAGIC +#define CMA_IOCTL_MAGIC 0xf2 +#endif + +#define CMA_ALLOC_CACHED _IOC(_IOC_WRITE|_IOC_READ, CMA_IOCTL_MAGIC, 1, 4) +#define CMA_ALLOC_NONCACHED _IOC(_IOC_WRITE|_IOC_READ, CMA_IOCTL_MAGIC, 2, 4) +#define CMA_FREE _IOC(_IOC_WRITE, CMA_IOCTL_MAGIC, 3, 4) +#define CMA_GET_PHY_ADDR _IOC(_IOC_WRITE|_IOC_READ, CMA_IOCTL_MAGIC, 4, 4) +#define CMA_GET_SIZE _IOC(_IOC_WRITE|_IOC_READ, CMA_IOCTL_MAGIC, 5, 4) + +#define CMA_IOCTL_MAXNR 5 + +#ifndef CMA_DEBUG + #define CMA_DEBUG 0 +#endif +#ifndef DRIVER_NODE_NAME + #define DRIVER_NODE_NAME "cma" +#endif + +#if CMA_DEBUG == 1 + #define __DEBUG(fmt, args...) printf("CMA_API_DEBUG: " fmt, ##args) +#else + #define __DEBUG(fmt, args...) +#endif + +#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S)) + + +/* Private functions */ +void *cma_alloc(size_t size, unsigned ioctl_cmd); + +/* Global file descriptor */ +int cma_fd = 0; + +int cma_init(void) { + __DEBUG("Opening \"/dev/" DRIVER_NODE_NAME "\" file\n"); + + cma_fd = open("/dev/" DRIVER_NODE_NAME, O_RDWR); + if (cma_fd == -1) { + __DEBUG("Failed to initialize api - \"%s\"\n", strerror(errno)); + return -1; + } + + return 0; +} + +int cma_release(void) { + __DEBUG("Closing \"/dev/" DRIVER_NODE_NAME "\" file\n"); + + if (close(cma_fd) == -1) { + __DEBUG("Failed to finilize api - \"%s\"\n", strerror(errno)); + return -1; + } + + return 0; +} + +void *cma_alloc_cached(size_t size) { + return cma_alloc(size, CMA_ALLOC_CACHED); +} + +void *cma_alloc_noncached(size_t size) { + return cma_alloc(size, CMA_ALLOC_NONCACHED); +} + +int cma_free(void *mem) { + __DEBUG("Releasing contigous memory from 0x%x\n", (unsigned)mem); + unsigned data, v_addr; + + /* save user space pointer value */ + data = (unsigned)mem; + v_addr = (unsigned)mem; + + if ( ioctl(cma_fd, CMA_GET_SIZE, &data) == -1 ) { + __DEBUG("cma_free - ioctl command unsuccsessful - 0\n"); + return -1; + } + /* data now contains size */ + + /* unmap memory */ + munmap(mem, data); + + /* free cma entry */ + if ( ioctl(cma_fd, CMA_FREE, &v_addr) == -1 ) { + __DEBUG("cma_free - ioctl command unsuccsessful - 1\n"); + return -1; + } + + return 0; +} + +unsigned cma_get_phy_addr(void *mem) { + unsigned data; + __DEBUG("Getting physical address from 0x%x\n", (unsigned)mem); + + /* save user space pointer value */ + data = (unsigned)mem; + + /* get physical address */ + if ( ioctl(cma_fd, CMA_GET_PHY_ADDR, &data) == -1 ) { + __DEBUG("cma_free - ioctl command unsuccsessful\n"); + return 0; + } + /* data now contains physical address */ + + return data; +} + + +void *cma_alloc(size_t size, unsigned ioctl_cmd) { + unsigned data; + void *mem; + __DEBUG("Allocating 0x%x bytes of contigous memory\n", size); + + /* Page align size */ + size = ROUND_UP(size, getpagesize()); + + /* ioctl cmd to allocate contigous memory */ + data = (unsigned)size; + if ( ioctl(cma_fd, ioctl_cmd, &data) == -1 ) { + __DEBUG("cma_alloc - ioctl command unsuccsessful\n"); + return NULL; + } + + /* at this point phy_addr is written to data */ + + /* mmap memory */ + mem = mmap(NULL, size, PROT_WRITE | PROT_READ, MAP_SHARED, cma_fd, data); + if (mem == MAP_FAILED) { + __DEBUG("cma_alloc - mmap unsuccsessful\n"); + return NULL; + } + + return mem; +} diff --git a/LICENSE b/LICENSE index 45ee1f9baf56..eae08c553b9a 100644 --- a/LICENSE +++ b/LICENSE @@ -214,10 +214,15 @@ Apache Software Foundation License 2.0 3rdparty/dmlc-core -BSD License +BSD 2-clause License ----------- 3rdparty/picojson + + +BSD 3-clause License +----------- + 3rdparty/dmlc-core/include/dmlc/concurrentqueue.h @@ -225,7 +230,6 @@ MIT License ----------- 3rdparty/cma -vta/src/de10nano/cma_api.cc 3rdparty/compiler-rt/builtin_fp16.h diff --git a/vta/src/de10nano/cma_api.cc b/vta/src/de10nano/cma_api.cc index 12c0e3b27efc..10941cfae6ed 100644 --- a/vta/src/de10nano/cma_api.cc +++ b/vta/src/de10nano/cma_api.cc @@ -1,179 +1,27 @@ /* - * The MIT License (MIT) + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * COPYRIGHT (C) 2017 Institute of Electronics and Computer Science (EDI), Latvia. - * AUTHOR: Rihards Novickis (rihards.novickis@edi.lv) + * http://www.apache.org/licenses/LICENSE-2.0 * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. * */ /*! - * Copyright (c) 2018 by Contributors * \file cma_api.cc * \brief Application layer implementation for contigous memory allocation. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "cma_api.h" - -#ifndef CMA_IOCTL_MAGIC -#define CMA_IOCTL_MAGIC 0xf2 -#endif - -#define CMA_ALLOC_CACHED _IOC(_IOC_WRITE|_IOC_READ, CMA_IOCTL_MAGIC, 1, 4) -#define CMA_ALLOC_NONCACHED _IOC(_IOC_WRITE|_IOC_READ, CMA_IOCTL_MAGIC, 2, 4) -#define CMA_FREE _IOC(_IOC_WRITE, CMA_IOCTL_MAGIC, 3, 4) -#define CMA_GET_PHY_ADDR _IOC(_IOC_WRITE|_IOC_READ, CMA_IOCTL_MAGIC, 4, 4) -#define CMA_GET_SIZE _IOC(_IOC_WRITE|_IOC_READ, CMA_IOCTL_MAGIC, 5, 4) - -#define CMA_IOCTL_MAXNR 5 - -#ifndef CMA_DEBUG - #define CMA_DEBUG 0 -#endif -#ifndef DRIVER_NODE_NAME - #define DRIVER_NODE_NAME "cma" -#endif - -#if CMA_DEBUG == 1 - #define __DEBUG(fmt, args...) printf("CMA_API_DEBUG: " fmt, ##args) -#else - #define __DEBUG(fmt, args...) -#endif - -#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S)) - - -/* Private functions */ -void *cma_alloc(size_t size, unsigned ioctl_cmd); - -/* Global file descriptor */ -int cma_fd = 0; - -int cma_init(void) { - __DEBUG("Opening \"/dev/" DRIVER_NODE_NAME "\" file\n"); - - cma_fd = open("/dev/" DRIVER_NODE_NAME, O_RDWR); - if (cma_fd == -1) { - __DEBUG("Failed to initialize api - \"%s\"\n", strerror(errno)); - return -1; - } - - return 0; -} - -int cma_release(void) { - __DEBUG("Closing \"/dev/" DRIVER_NODE_NAME "\" file\n"); - - if (close(cma_fd) == -1) { - __DEBUG("Failed to finilize api - \"%s\"\n", strerror(errno)); - return -1; - } - - return 0; -} - -void *cma_alloc_cached(size_t size) { - return cma_alloc(size, CMA_ALLOC_CACHED); -} - -void *cma_alloc_noncached(size_t size) { - return cma_alloc(size, CMA_ALLOC_NONCACHED); -} - -int cma_free(void *mem) { - __DEBUG("Releasing contigous memory from 0x%x\n", (unsigned)mem); - unsigned data, v_addr; - - /* save user space pointer value */ - data = (unsigned)mem; - v_addr = (unsigned)mem; - - if ( ioctl(cma_fd, CMA_GET_SIZE, &data) == -1 ) { - __DEBUG("cma_free - ioctl command unsuccsessful - 0\n"); - return -1; - } - /* data now contains size */ - - /* unmap memory */ - munmap(mem, data); - - /* free cma entry */ - if ( ioctl(cma_fd, CMA_FREE, &v_addr) == -1 ) { - __DEBUG("cma_free - ioctl command unsuccsessful - 1\n"); - return -1; - } - - return 0; -} - -unsigned cma_get_phy_addr(void *mem) { - unsigned data; - __DEBUG("Getting physical address from 0x%x\n", (unsigned)mem); - - /* save user space pointer value */ - data = (unsigned)mem; - - /* get physical address */ - if ( ioctl(cma_fd, CMA_GET_PHY_ADDR, &data) == -1 ) { - __DEBUG("cma_free - ioctl command unsuccsessful\n"); - return 0; - } - /* data now contains physical address */ - - return data; -} - - -void *cma_alloc(size_t size, unsigned ioctl_cmd) { - unsigned data; - void *mem; - __DEBUG("Allocating 0x%x bytes of contigous memory\n", size); - - /* Page align size */ - size = ROUND_UP(size, getpagesize()); - - /* ioctl cmd to allocate contigous memory */ - data = (unsigned)size; - if ( ioctl(cma_fd, ioctl_cmd, &data) == -1 ) { - __DEBUG("cma_alloc - ioctl command unsuccsessful\n"); - return NULL; - } - - /* at this point phy_addr is written to data */ - - /* mmap memory */ - mem = mmap(NULL, size, PROT_WRITE | PROT_READ, MAP_SHARED, cma_fd, data); - if (mem == MAP_FAILED) { - __DEBUG("cma_alloc - mmap unsuccsessful\n"); - return NULL; - } - - return mem; -} +#include From 82e7513f3d333422b75c89a039edd6727455feb1 Mon Sep 17 00:00:00 2001 From: Yizhi Liu Date: Sun, 24 Nov 2019 00:09:32 -0800 Subject: [PATCH 2/2] add zlib license for blockingconcurrentqueue.h --- LICENSE | 7 ++++--- licenses/LICENSE.blockingconcurrentqueue.txt | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 licenses/LICENSE.blockingconcurrentqueue.txt diff --git a/LICENSE b/LICENSE index eae08c553b9a..4345a24d059b 100644 --- a/LICENSE +++ b/LICENSE @@ -215,13 +215,14 @@ Apache Software Foundation License 2.0 BSD 2-clause License ------------ +-------------------- 3rdparty/picojson +3rdparty/dmlc-core/include/dmlc/concurrentqueue.h -BSD 3-clause License ------------ +BSD 2-clause License + zlib License +----------------------------------- 3rdparty/dmlc-core/include/dmlc/concurrentqueue.h diff --git a/licenses/LICENSE.blockingconcurrentqueue.txt b/licenses/LICENSE.blockingconcurrentqueue.txt new file mode 100644 index 000000000000..1cc22c47f9d5 --- /dev/null +++ b/licenses/LICENSE.blockingconcurrentqueue.txt @@ -0,0 +1,17 @@ +Copyright (c) 2015 Jeff Preshing + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgement in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. \ No newline at end of file