├── .gitignore ├── .gitmodules ├── .vimrc ├── .ycm_extra_conf.py ├── CMakeLists.txt ├── LICENSE ├── README.md ├── doc ├── Comments.txt ├── Languages.txt └── Project.txt ├── rtl ├── CMakeLists.txt └── virtio │ ├── CMakeLists.txt │ ├── available_ring │ ├── CMakeLists.txt │ ├── handler │ │ ├── CMakeLists.txt │ │ ├── virtio_available_ring_handler.sv │ │ └── virtio_available_ring_handler_top.sv │ └── monitor │ │ ├── CMakeLists.txt │ │ ├── virtio_available_ring_monitor.sv │ │ └── virtio_available_ring_monitor_top.sv │ └── packages │ ├── CMakeLists.txt │ └── virtio_available_ring_pkg.sv └── tests ├── CMakeLists.txt └── virtio ├── CMakeLists.txt └── available_ring ├── CMakeLists.txt └── handler ├── CMakeLists.txt └── virtio_available_ring_handler_unit_test.sv /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Vim 35 | *.swp 36 | 37 | # Build directories 38 | build/** 39 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "logic"] 2 | path = logic 3 | url = https://github.com/tymonx/logic 4 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | " Copyright 2018 Tymoteusz Blazejczyk 2 | " 3 | " Licensed under the Apache License, Version 2.0 (the "License"); 4 | " you may not use this file except in compliance with the License. 5 | " You may obtain a copy of the License at 6 | " 7 | " http://www.apache.org/licenses/LICENSE-2.0 8 | " 9 | " Unless required by applicable law or agreed to in writing, software 10 | " distributed under the License is distributed on an "AS IS" BASIS, 11 | " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | " See the License for the specific language governing permissions and 13 | " limitations under the License. 14 | 15 | let current_dir = expand(':p:h') 16 | 17 | let verilog_includes = split(globpath(current_dir, '**/rtl/**/*.vh'), '\n') 18 | let verilog_files = split(globpath(current_dir, '**/rtl/**/*.v'), '\n') 19 | 20 | let systemverilog_includes = split(globpath(current_dir, '**/rtl/**/*.svh'), '\n') 21 | let systemverilog_packages = split(globpath(current_dir, '**/rtl/**/*_pkg.sv'), '\n') 22 | let systemverilog_files = split(globpath(current_dir, '**/rtl/**/*.sv'), '\n') 23 | 24 | let verilator_sources = [] 25 | for systemverilog_package in systemverilog_packages 26 | call add(verilator_sources, fnamemodify(systemverilog_package, ":p")) 27 | endfor 28 | 29 | let verilator_includes = [] 30 | for verilog_include in verilog_includes 31 | call add(verilator_includes, fnamemodify(verilog_include, ":p:h")) 32 | endfor 33 | 34 | for verilog_file in verilog_files 35 | call add(verilator_includes, fnamemodify(verilog_file, ":p:h")) 36 | endfor 37 | 38 | for systemverilog_include in systemverilog_includes 39 | call add(verilator_includes, fnamemodify(systemverilog_include, ":p:h")) 40 | endfor 41 | 42 | for systemverilog_file in systemverilog_files 43 | call add(verilator_includes, fnamemodify(systemverilog_file, ":p:h")) 44 | endfor 45 | 46 | let dict = {} 47 | for verilator_include in verilator_includes 48 | let dict[verilator_include] = '' 49 | endfor 50 | 51 | let verilator_includes = keys(dict) 52 | 53 | let verilator_options = [] 54 | 55 | call add(verilator_options, '-Wall --top-module logic_dummy') 56 | 57 | for verilator_include in verilator_includes 58 | call add(verilator_options, '-I' . verilator_include) 59 | endfor 60 | 61 | for verilator_source in verilator_sources 62 | call add(verilator_options, verilator_source) 63 | endfor 64 | 65 | let g:syntastic_systemverilog_compiler_options = join(verilator_options, ' ') 66 | -------------------------------------------------------------------------------- /.ycm_extra_conf.py: -------------------------------------------------------------------------------- 1 | # This file is NOT licensed under the GPLv3, which is the license for the rest 2 | # of YouCompleteMe. 3 | # 4 | # Here's the license text for this file: 5 | # 6 | # This is free and unencumbered software released into the public domain. 7 | # 8 | # Anyone is free to copy, modify, publish, use, compile, sell, or 9 | # distribute this software, either in source code form or as a compiled 10 | # binary, for any purpose, commercial or non-commercial, and by any 11 | # means. 12 | # 13 | # In jurisdictions that recognize copyright laws, the author or authors 14 | # of this software dedicate any and all copyright interest in the 15 | # software to the public domain. We make this dedication for the benefit 16 | # of the public at large and to the detriment of our heirs and 17 | # successors. We intend this dedication to be an overt act of 18 | # relinquishment in perpetuity of all present and future rights to this 19 | # software under copyright law. 20 | # 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24 | # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 | # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | # OTHER DEALINGS IN THE SOFTWARE. 28 | # 29 | # For more information, please refer to 30 | 31 | import os 32 | import ycm_core 33 | 34 | # These are the compilation flags that will be used in case there's no 35 | # compilation database set (by default, one is not set). 36 | # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. 37 | flags = [ 38 | '-Weverything', 39 | '-Werror', 40 | '-Wno-padded', 41 | '-Wno-c++98-compat', 42 | '-Wno-c++98-compat-pedantic', 43 | '-Wno-global-constructors', 44 | '-Wno-exit-time-destructors', 45 | '-Wno-covered-switch-default', 46 | '-fexceptions', 47 | '-std=c++11', 48 | '-xc++', 49 | '-Iinclude', 50 | '-Ilogic/include', 51 | '-isystem/usr/local/systemc/2.3.1/include', 52 | '-isystem/usr/local/share/verilator/include', 53 | ] 54 | 55 | 56 | # Set this to the absolute path to the folder (NOT the file!) containing the 57 | # compile_commands.json file to use that instead of 'flags'. See here for 58 | # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html 59 | # 60 | # You can get CMake to generate this file for you by adding: 61 | # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) 62 | # to your CMakeLists.txt file. 63 | # 64 | # Most projects will NOT need to set this to anything; you can just change the 65 | # 'flags' list of compilation flags. Notice that YCM itself uses that approach. 66 | compilation_database_folder = '' 67 | 68 | if os.path.exists( compilation_database_folder ): 69 | database = ycm_core.CompilationDatabase( compilation_database_folder ) 70 | else: 71 | database = None 72 | 73 | SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] 74 | 75 | def DirectoryOfThisScript(): 76 | return os.path.dirname( os.path.abspath( __file__ ) ) 77 | 78 | 79 | def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): 80 | if not working_directory: 81 | return list( flags ) 82 | new_flags = [] 83 | make_next_absolute = False 84 | path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] 85 | for flag in flags: 86 | new_flag = flag 87 | 88 | if make_next_absolute: 89 | make_next_absolute = False 90 | if not flag.startswith( '/' ): 91 | new_flag = os.path.join( working_directory, flag ) 92 | 93 | for path_flag in path_flags: 94 | if flag == path_flag: 95 | make_next_absolute = True 96 | break 97 | 98 | if flag.startswith( path_flag ): 99 | path = flag[ len( path_flag ): ] 100 | new_flag = path_flag + os.path.join( working_directory, path ) 101 | break 102 | 103 | if new_flag: 104 | new_flags.append( new_flag ) 105 | return new_flags 106 | 107 | 108 | def IsHeaderFile( filename ): 109 | extension = os.path.splitext( filename )[ 1 ] 110 | return extension in [ '.h', '.hxx', '.hpp', '.hh' ] 111 | 112 | 113 | def GetCompilationInfoForFile( filename ): 114 | # The compilation_commands.json file generated by CMake does not have entries 115 | # for header files. So we do our best by asking the db for flags for a 116 | # corresponding source file, if any. If one exists, the flags for that file 117 | # should be good enough. 118 | if IsHeaderFile( filename ): 119 | basename = os.path.splitext( filename )[ 0 ] 120 | for extension in SOURCE_EXTENSIONS: 121 | replacement_file = basename + extension 122 | if os.path.exists( replacement_file ): 123 | compilation_info = database.GetCompilationInfoForFile( 124 | replacement_file ) 125 | if compilation_info.compiler_flags_: 126 | return compilation_info 127 | return None 128 | return database.GetCompilationInfoForFile( filename ) 129 | 130 | 131 | def FlagsForFile( filename, **kwargs ): 132 | if database: 133 | # Bear in mind that compilation_info.compiler_flags_ does NOT return a 134 | # python list, but a "list-like" StringVec object 135 | compilation_info = GetCompilationInfoForFile( filename ) 136 | if not compilation_info: 137 | return None 138 | 139 | final_flags = MakeRelativePathsInFlagsAbsolute( 140 | compilation_info.compiler_flags_, 141 | compilation_info.compiler_working_dir_ ) 142 | 143 | # NOTE: This is just for YouCompleteMe; it's highly likely that your project 144 | # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR 145 | # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT. 146 | try: 147 | final_flags.remove( '-stdlib=libc++' ) 148 | except ValueError: 149 | pass 150 | else: 151 | relative_to = DirectoryOfThisScript() 152 | final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) 153 | 154 | return { 'flags': final_flags } 155 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.1) 16 | project(Virtio CXX) 17 | 18 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} 19 | ${CMAKE_CURRENT_LIST_DIR}/logic/cmake 20 | ) 21 | 22 | include(AddLogic) 23 | 24 | enable_testing() 25 | 26 | add_subdirectory(logic) 27 | add_subdirectory(rtl) 28 | add_subdirectory(tests) 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Virtio 2 | ====== 3 | 4 | Virtio implementation in SystemVerilog. 5 | 6 | Requirements 7 | ------------ 8 | 9 | These 3rd party tools and libraries must be installed to build and run tests: 10 | 11 | * [CMake](https://cmake.org/) - build, test and package project 12 | * [IntelFPGA Quartus](https://www.altera.com/downloads/download-center.html) - synthesis tool for Intel FPGAs 13 | * [Verilator](https://www.veripool.org/wiki/verilator/) - simulator, lint and coverage tool 14 | * [SystemC 2.3.1](http://accellera.org/downloads/standards/systemc) - SystemC C++ library 15 | * [SystemC Verification 2.0](http://accellera.org/downloads/standards/systemc) - SystemC data randomization 16 | * [UVM-SystemC 1.0](http://www.eda.org/activities/working-groups/systemc-verification) - UVM for SystemC 17 | * [Natural Docs](http://www.naturaldocs.org/) - code documentation generator 18 | * [GoogleTest](https://github.com/google/googletest) - C++ unit test framework 19 | * [SVUnit](http://agilesoc.com/open-source-projects/svunit/) - SystemVerilog unit test framework 20 | * [GTKWave](http://gtkwave.sourceforge.net/) - waveform viewer 21 | * [WaveDrom](http://wavedrom.com/) - digital timing diagram 22 | 23 | Workspace 24 | --------- 25 | 26 | * README.md - this read me file in MarkDown format 27 | * LICENSE - license file 28 | * CMakeLists.txt - CMake root script for building and testing project 29 | * doc - configuration files for code documentation generator 30 | * rtl - RTL source files 31 | * src - C++ source files 32 | * include - C++ include headers 33 | * tests - unit tests and verification tests in SystemC using 34 | Google Test or UVM and SystemVerilog using SVUnit 35 | * cmake - additional CMake scripts for building project 36 | * scripts - additional scripts in TCL or Python for building project 37 | 38 | Build 39 | ----- 40 | 41 | Clone repository: 42 | 43 | git clone git@github.com:tymonx/virtio.git 44 | 45 | Change current location to repository directory: 46 | 47 | cd virtio 48 | 49 | Clone git submodules: 50 | 51 | git submodule init 52 | git submodule update 53 | 54 | Create build directory: 55 | 56 | mkdir build 57 | 58 | Change current location to build directory: 59 | 60 | cd build 61 | 62 | Create build scripts using CMake: 63 | 64 | cmake .. 65 | 66 | Build project using CMake: 67 | 68 | cmake --build . --target all 69 | 70 | Or build project using make: 71 | 72 | make -j`nproc` 73 | 74 | To build documentation: 75 | 76 | cmake --build . target doc 77 | 78 | Built HTML documentation can be found in: 79 | 80 | doc/html 81 | 82 | To view HTML documentation, open it using web browser: 83 | 84 | doc/html/index.html 85 | 86 | Tests 87 | ----- 88 | 89 | Run all unit tests: 90 | 91 | ctest 92 | 93 | Run only unit tests for AXI4-Stream: 94 | 95 | ctest -R axi4_stream 96 | 97 | All waveforms generated from unit tests are located in: 98 | 99 | output 100 | 101 | All unit tests logs are stored in: 102 | 103 | Testing/Temporary/LastTest.log 104 | 105 | Verilator Coverage 106 | ------------------ 107 | 108 | Run Verilator coverage after running all tests: 109 | 110 | cmake --build . --target verilator-coverage 111 | -------------------------------------------------------------------------------- /doc/Comments.txt: -------------------------------------------------------------------------------- 1 | Format: 2.0.1 2 | 3 | # This is the Natural Docs comments file for this project. If you change 4 | # anything here, it will apply to THIS PROJECT ONLY. You can edit the version 5 | # in Natural Docs' Config folder to make the changes apply to all projects, 6 | # but it's recommended that you edit this version instead. 7 | 8 | 9 | # Ignored Keywords 10 | # ------------------------------------------------------------------------ 11 | 12 | # If you'd like to prevent keywords from being recognized by Natural Docs, 13 | # you can do it like this: 14 | # 15 | # Ignore Keywords: 16 | # [keyword] 17 | # [keyword] 18 | # ... 19 | 20 | 21 | # Comment Types 22 | # ------------------------------------------------------------------------ 23 | # The syntax reference is after the definitions. 24 | 25 | Alter Comment Type: Class 26 | 27 | Keywords: 28 | module, Modules 29 | package, Packages 30 | interface, Interfaces 31 | 32 | 33 | Comment Type: Logic 34 | 35 | Display Name: Logics 36 | Plural Display Name: Logics 37 | 38 | Scope: Normal 39 | Flags: Code, Variable Type 40 | 41 | Keywords: 42 | logic 43 | 44 | 45 | Comment Type: Structure 46 | 47 | Display Name: Structs 48 | Plural Display Name: Structs 49 | 50 | Scope: Normal 51 | Flags: Code, Variable Type 52 | 53 | Keywords: 54 | struct 55 | 56 | 57 | Comment Type: Enum 58 | 59 | Display Name: Enums 60 | Plural Display Name: Enums 61 | 62 | Scope: Normal 63 | Flags: Code, Variable Type 64 | 65 | Keywords: 66 | enum 67 | 68 | 69 | # Each Natural Docs comment has a corresponding type which determine its 70 | # behavior. You can define your own here or override the settings of the 71 | # existing ones. 72 | # 73 | # Comment Type: [name] 74 | # Alter Comment Type: [name] 75 | # Creates a new comment type or changes an existing one. 76 | # 77 | # Display Name: [name] 78 | # Plural Display Name: [name] 79 | # The singular and plural name of the comment type as it should appear in 80 | # the output. 81 | # 82 | # Simple Identifier: [name] 83 | # The name of the comment type using only the letters A to Z. No spaces, 84 | # numbers, symbols, or Unicode allowed. Defaults to the comment type name 85 | # minus any unacceptable characters. This is used to generate things like 86 | # CSS class names. 87 | # 88 | # Scope: [normal|start|end|always global] 89 | # How the comment affects scope. Defaults to normal. 90 | # normal - The comment stays within the current scope. 91 | # start - The comment starts a new scope for all the comments 92 | # beneath it, like class comments. 93 | # end - The comment resets the scope back to global for all the 94 | # comments beneath it, like section comments. 95 | # always global - The comment is defined as a global symbol, but does not 96 | # change the scope for any other comments. 97 | # 98 | # Flags: [flag], [flag], ... 99 | # A combination of settings that apply to the comment type. 100 | # Code, File, or Documentation 101 | # Whether it's used to describe a code element, a file, or is a 102 | # standalone documentation comment. Defaults to Code. 103 | # Variable Type 104 | # Whether it describes a code element that can be used as a variable's 105 | # type. 106 | # Class Hierarchy or Database Hierarchy 107 | # Whether it describes a code element that should be included in the 108 | # class or database hierarchy. Requires Scope: Start. 109 | # Enum 110 | # Whether it describes an enum. 111 | # 112 | # Keywords: 113 | # [keyword] 114 | # [keyword], [plural keyword] 115 | # ... 116 | # A list of the comment type's keywords. Each line after the heading is 117 | # the keyword and optionally its plural form for list comments. You can 118 | # reuse existing keywords to change their definition. When using 119 | # "Alter Comment Type", these keywords are added to the existing ones 120 | # rather than replacing them. 121 | -------------------------------------------------------------------------------- /doc/Languages.txt: -------------------------------------------------------------------------------- 1 | Format: 2.0.1 2 | 3 | # This is the Natural Docs languages file for this project. If you change 4 | # anything here, it will apply to THIS PROJECT ONLY. You can edit the version 5 | # in Natural Docs' Config folder to make the changes apply to all projects, 6 | # but it's recommended that you edit this version instead. 7 | 8 | 9 | # Ignored Extensions 10 | # ------------------------------------------------------------------------ 11 | 12 | # If you'd like to prevent certain file extensions from being scanned by 13 | # Natural Docs, you can do it like this: 14 | # 15 | # Ignore Extensions: [extension] [extension] ... 16 | 17 | 18 | # Languages 19 | # ------------------------------------------------------------------------ 20 | 21 | Language: SystemVerilog 22 | 23 | Extensions: v vh sv svh 24 | 25 | Line Comment: // 26 | Block Comment: /* */ 27 | Member Operator: . 28 | Enum Values: Global 29 | Case Sensitive: Yes 30 | 31 | Function Prototype Enders: ; begin 32 | Class Prototype Ender: ; 33 | Interface Prototype Ender: ; 34 | Macro Prototype Enders: \ \n 35 | 36 | 37 | # These settings define the languages Natural Docs knows how to parse. You 38 | # can define your own here or override the settings of the existing ones. 39 | # Note that all lists are space separated so that commas can be used as 40 | # values. 41 | # 42 | # Language: [name] 43 | # Alter Language: [name] 44 | # Defines a new language or alters an existing one. Its name can use any 45 | # characters. If any of the properties below have an add/replace form, you 46 | # must use that when using Alter Language. 47 | # 48 | # The language Shebang Script is special. It's entry is only used for 49 | # extensions, and files with those extensions have their shebang (#!) lines 50 | # read to determine the real language of the file. Extensionless files are 51 | # always treated this way. 52 | # 53 | # The language Text File is also special. It's treated as one big comment 54 | # so you can put Natural Docs content in them without special symbols. 55 | # 56 | # Extensions: [extension] [extension] ... 57 | # [Add/Replace] Extensions: [extension] [extension] ... 58 | # Defines the file extensions of the language's source files. 59 | # 60 | # Shebang Strings: [string] [string] ... 61 | # [Add/Replace] Shebang Strings: [string] [string] ... 62 | # Defines a list of strings that can appear in the shebang (#!) line to 63 | # designate that it's part of the language. 64 | # 65 | # Simple Identifier: [name] 66 | # The name of the language using only the letters A to Z. No spaces, 67 | # numbers, symbols, or Unicode allowed. Defaults to the language name 68 | # minus any unacceptable characters. This is used to generate things like 69 | # CSS class names. 70 | # 71 | # Aliases: [alias] [alias] ... 72 | # [Add/Replace] Aliases: [alias] [alias] ... 73 | # Defines alternate names for the language that can be used to start a code 74 | # block. 75 | # 76 | # 77 | # Properties for Basic Language Support Only 78 | # ------------------------------------------------------------------------ 79 | # If you're adding your own language to Natural Docs you must define these. 80 | # 81 | # Line Comments: [symbol] [symbol] ... 82 | # Defines a space-separated list of symbols that are used for line comments, 83 | # if any. 84 | # 85 | # Block Comments: [opening sym] [closing sym] [opening sym] [closing sym] ... 86 | # Defines a space-separated list of symbol pairs that are used for block 87 | # comments, if any. 88 | # 89 | # Member Operator: [symbol] 90 | # Defines the default member operator symbol. The default is a dot. 91 | # 92 | # Line Extender: [symbol] 93 | # Defines the symbol that allows a prototype to span multiple lines if 94 | # normally a line break would end it. 95 | # 96 | # Enum Values: [global|under type|under parent] 97 | # Defines how enum values are referenced. The default is global. 98 | # global - Values are always global, referenced as 'value'. 99 | # under type - Values are under the enum type, referenced as 100 | # 'class.enum.value'. 101 | # under parent - Values are under the enum's parent, referenced as 102 | # 'class.value'. 103 | # 104 | # Case Sensitive: [yes|no] 105 | # Defines whether the language's identifiers are case sensitive. The 106 | # default is yes. 107 | # 108 | # [Comment Type] Prototype Enders: [symbol] [symbol] ... 109 | # When defined, Natural Docs will attempt to get a prototype from the code 110 | # immediately following the comment type. It stops when it reaches one of 111 | # these symbols. Use \n for line breaks. 112 | -------------------------------------------------------------------------------- /doc/Project.txt: -------------------------------------------------------------------------------- 1 | Format: 2.0.1 2 | 3 | # This is the file you use to provide information about your project. It can 4 | # also be used to specify input and output settings so you don't have to 5 | # include them on the command line. 6 | 7 | 8 | # Project Information 9 | # ------------------------------------------------------------------------ 10 | 11 | Title: Virtio 12 | 13 | Copyright: Copyright 2018 Tymoteusz Blazejczyk 14 | 15 | Timestamp: d month year 16 | # m - Single digit month, when possible. January is "1". 17 | # mm - Always double digit month. January is "01". 18 | # mon - Short month word. January is "Jan". 19 | # month - Long month word. January is "January". 20 | # d - Single digit day, when possible. 1 is "1". 21 | # dd - Always double digit day. 1 is "01". 22 | # day - Day with text extension. 1 is "1st". 23 | # yy - Double digit year. 2018 is "17". 24 | # yyyy - Four digit year. 2018 is "2018". 25 | # year - Four digit year. 2018 is "2018". 26 | 27 | 28 | # This is where you specify general information about your project. 29 | # 30 | # Subtitle: [text] 31 | # A subtitle for your project. 32 | # 33 | # Style: [style] 34 | # The style to apply to the generated documentation. It can be the name of 35 | # a CSS file in the project configuration folder or a subfolder that 36 | # contains Style.txt. Do not include ".css" if using a CSS file. 37 | 38 | 39 | # Source Code 40 | # ------------------------------------------------------------------------ 41 | 42 | Source Folder: ../logic/rtl/logic 43 | Name: logic 44 | 45 | Source Folder 2: ../rtl/virtio 46 | Name: virtio 47 | 48 | 49 | 50 | 51 | # This is where you specify what files and folders Natural Docs should be 52 | # scanning. If you use any of these options on the command line, this entire 53 | # section is ignored except for names and numbers. 54 | # 55 | # All paths are relative to the project configuration folder, which lets this 56 | # file remain portable across computers and not cause problems in version 57 | # control systems. You can enter absolute paths and they will be converted 58 | # automatically. 59 | # 60 | # Source Folder: [path] 61 | # Name: [name] 62 | # 63 | # Specifies a folder which will be searched for source files. If you have 64 | # more than one, add the Name property to set how it will show up in the 65 | # menu. 66 | 67 | 68 | # Source Filtering 69 | # ------------------------------------------------------------------------ 70 | 71 | # If there are any subfolders in the source code that you would like Natural 72 | # Docs to ignore, they can be specified here. If you use any of these options 73 | # on the command line, this entire section is ignored. 74 | # 75 | # Ignore Source Folder: [path] 76 | # Tells Natural Docs to skip this folder when scanning files. 77 | # 78 | # Ignore Source Folder Pattern: [pattern] 79 | # Tells Natural Docs to skip all folder names which match this pattern when 80 | # scanning files. ? matches a single character, * matches zero or more 81 | # characters. It applies to the entire folder name, so "cli" will not 82 | # match "client", although "cli*" will. 83 | # 84 | # The data folders of common version control systems (.git, .svn, .cvs, .hg) 85 | # are ignored automatically. You do not have to specify them here. 86 | 87 | 88 | # Generated Documentation 89 | # ------------------------------------------------------------------------ 90 | 91 | HTML Output Folder: ../build/doc/html 92 | 93 | 94 | # This is where you specify what kind of documentation you want Natural Docs 95 | # to build and where it should be put. If you use any of these options on the 96 | # command line, this entire section is ignored except for secondary settings. 97 | # 98 | # All paths are relative to the project configuration folder, which lets this 99 | # file remain portable across computers and not cause problems in version 100 | # control systems. You can enter absolute paths and they will be converted 101 | # automatically. 102 | # 103 | # You can override any of the project information settings under each entry, 104 | # so if you have multiple output folders you can give them each different 105 | # styles or subtitles. 106 | # 107 | # HTML Output Folder: [path] 108 | # [Project Information] 109 | # 110 | # Generates HTML documentation in the specified folder. 111 | 112 | 113 | # Global Settings 114 | # ------------------------------------------------------------------------ 115 | 116 | # Other settings that apply to your entire project. Settings specified on the 117 | # command line override the settings here. 118 | # 119 | # Tab Width: [width] 120 | # The number of spaces tabs should be expanded to. 121 | # 122 | # Documented Only: [yes|no] 123 | # Whether only documented code elements should appear in the output. 124 | # Defaults to no. 125 | # 126 | # Auto Group: [yes|no] 127 | # Whether groups should automatically apply to you code. Defaults to yes. 128 | 129 | 130 | -------------------------------------------------------------------------------- /rtl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_subdirectory(virtio) 16 | -------------------------------------------------------------------------------- /rtl/virtio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set(HDL_LIBRARY virtio) 16 | set(HDL_SYNTHESIZABLE TRUE) 17 | 18 | set(HDL_INCLUDES 19 | "${STD_OVL_DIR}" 20 | "${CMAKE_CURRENT_SOURCE_DIR}/../../logic/rtl/logic/include" 21 | ) 22 | 23 | add_subdirectory(packages) 24 | add_subdirectory(available_ring) 25 | -------------------------------------------------------------------------------- /rtl/virtio/available_ring/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_subdirectory(handler) 16 | add_subdirectory(monitor) 17 | -------------------------------------------------------------------------------- /rtl/virtio/available_ring/handler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_hdl_source(virtio_available_ring_handler.sv 16 | DEPENDS 17 | logic_axi4_stream_if 18 | logic_reset_synchronizer 19 | virtio_available_ring_pkg 20 | ) 21 | 22 | add_hdl_source(virtio_available_ring_handler_top.sv 23 | DEPENDS 24 | virtio_available_ring_handler 25 | ANALYSIS 26 | TRUE 27 | ) 28 | -------------------------------------------------------------------------------- /rtl/virtio/available_ring/handler/virtio_available_ring_handler.sv: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Tymoteusz Blazejczyk 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | `include "logic.svh" 17 | 18 | /* Module: virtio_available_ring_handler 19 | * 20 | * Virtio available ring handler. 21 | * 22 | * Parameters: 23 | * MAX_BURST_TRANSACTIONS - Maximum number of burst transactions. 24 | * NOTIFICATION_THRESHOLD_HIGH - Notification suppression threshold high bound. 25 | * NOTIFICATION_THRESHOLD_LOW - Notification suppression threshold low bound. 26 | * 27 | * Ports: 28 | * aclk - Clock. 29 | * areset_n - Asynchronous active-low reset. 30 | * configure - AXI4-Stream interface for virtqueue configuration. 31 | * notify - AXI4-Stream interface for virtqueue notification. 32 | * rx - AXI4-Stream interface for virtqueue responses. 33 | * tx - AXI4-Stream interface for virtqueue requests. 34 | */ 35 | module virtio_available_ring_handler #( 36 | int MAX_BURST_TRANSACTIONS = 16, 37 | int NOTIFICATION_THRESHOLD_HIGH = 1024, 38 | int NOTIFICATION_THRESHOLD_LOW = 16 39 | ) ( 40 | input aclk, 41 | input areset_n, 42 | `LOGIC_MODPORT(logic_axi4_stream_if, rx) configure, 43 | `LOGIC_MODPORT(logic_axi4_stream_if, rx) notify, 44 | `LOGIC_MODPORT(logic_axi4_stream_if, rx) rx, 45 | `LOGIC_MODPORT(logic_axi4_stream_if, tx) tx 46 | ); 47 | import virtio_available_ring_pkg::*; 48 | 49 | initial begin: design_rule_checks 50 | `LOGIC_DRC_EQUAL_OR_GREATER_THAN(MAX_BURST_TRANSACTIONS, 1) 51 | `LOGIC_DRC_LESS_THAN(NOTIFICATION_THRESHOLD_LOW, 52 | NOTIFICATION_THRESHOLD_HIGH) 53 | end 54 | 55 | enum logic [1:0] { 56 | FSM_IDLE, 57 | FSM_EVENT_IDX, 58 | FSM_READ_POINTER, 59 | FSM_DIFFERENCE 60 | } fsm_state; 61 | 62 | logic read; 63 | logic write; 64 | logic [15:0] write_pointer; 65 | logic [15:0] read_pointer; 66 | logic [15:0] difference; 67 | logic [15:0] ids; 68 | logic not_empty; 69 | 70 | logic threshold_low; 71 | logic threshold_high; 72 | 73 | logic notification; 74 | logic notification_set; 75 | logic notification_clear; 76 | 77 | logic suppression; 78 | logic suppression_set; 79 | logic suppression_clear; 80 | 81 | configuration_t configuration; 82 | 83 | request_type_t request_type; 84 | request_t request; 85 | response_t response; 86 | 87 | always_comb notification_set = notify.tvalid; 88 | always_comb notification_clear = (FSM_IDLE == fsm_state) && 89 | notification && !suppression && tx.tready; 90 | 91 | always_comb response = response_t'(rx.tdata); 92 | 93 | always_ff @(posedge aclk or negedge areset_n) begin 94 | if (!areset_n) begin 95 | rx.tready <= '0; 96 | end 97 | else begin 98 | rx.tready <= '1; 99 | end 100 | end 101 | 102 | always_ff @(posedge aclk or negedge areset_n) begin 103 | if (!areset_n) begin 104 | notify.tready <= '0; 105 | end 106 | else begin 107 | notify.tready <= '1; 108 | end 109 | end 110 | 111 | always_ff @(posedge aclk or negedge areset_n) begin 112 | if (!areset_n) begin 113 | configure.tready <= '0; 114 | end 115 | else begin 116 | configure.tready <= '1; 117 | end 118 | end 119 | 120 | always_ff @(posedge aclk or negedge areset_n) begin 121 | if (!areset_n) begin 122 | configuration <= '0; 123 | end 124 | else if (configure.tvalid) begin 125 | configuration <= configuration_t'(configure.tdata); 126 | end 127 | end 128 | 129 | always_ff @(posedge aclk or negedge areset_n) begin 130 | if (!areset_n) begin 131 | notification <= '0; 132 | end 133 | else if (notification_set) begin 134 | notification <= '1; 135 | end 136 | else if (notification_clear) begin 137 | notification <= '0; 138 | end 139 | end 140 | 141 | always_comb write = rx.tvalid; 142 | 143 | always_ff @(posedge aclk or negedge areset_n) begin 144 | if (!areset_n) begin 145 | write_pointer <= '0; 146 | end 147 | else if (write) begin 148 | write_pointer <= response.offset; 149 | end 150 | end 151 | 152 | always_comb read = (FSM_IDLE == fsm_state) && tx.tready && 153 | !(notification && !suppression) && not_empty; 154 | 155 | always_ff @(posedge aclk or negedge areset_n) begin 156 | if (!areset_n) begin 157 | read_pointer <= '0; 158 | end 159 | else if (read) begin 160 | read_pointer <= read_pointer + ids; 161 | end 162 | end 163 | 164 | always_ff @(posedge aclk or negedge areset_n) begin 165 | if (!areset_n) begin 166 | difference <= '0; 167 | end 168 | else begin 169 | difference <= write_pointer - read_pointer; 170 | end 171 | end 172 | 173 | always_ff @(posedge aclk or negedge areset_n) begin 174 | if (!areset_n) begin 175 | ids <= '0; 176 | end 177 | else begin 178 | ids <= (difference < MAX_BURST_TRANSACTIONS[15:0]) 179 | ? difference : MAX_BURST_TRANSACTIONS[15:0]; 180 | end 181 | end 182 | 183 | always_ff @(posedge aclk or negedge areset_n) begin 184 | if (!areset_n) begin 185 | not_empty <= '0; 186 | end 187 | else begin 188 | not_empty <= (0 != difference); 189 | end 190 | end 191 | 192 | always_ff @(posedge aclk or negedge areset_n) begin 193 | if (!areset_n) begin 194 | threshold_low <= '0; 195 | end 196 | else begin 197 | threshold_low <= (difference <= NOTIFICATION_THRESHOLD_LOW[15:0]); 198 | end 199 | end 200 | 201 | always_ff @(posedge aclk or negedge areset_n) begin 202 | if (!areset_n) begin 203 | threshold_high <= '0; 204 | end 205 | else begin 206 | threshold_high <= (difference >= NOTIFICATION_THRESHOLD_HIGH[15:0]); 207 | end 208 | end 209 | 210 | always_comb suppression_set = !suppression && threshold_high; 211 | always_comb suppression_clear = suppression && threshold_low; 212 | 213 | always_ff @(posedge aclk or negedge areset_n) begin 214 | if (!areset_n) begin 215 | suppression <= '0; 216 | end 217 | else if (suppression_set) begin 218 | suppression <= '1; 219 | end 220 | else if (suppression_clear) begin 221 | suppression <= '0; 222 | end 223 | end 224 | 225 | always_ff @(posedge aclk or negedge areset_n) begin 226 | if (!areset_n) begin 227 | fsm_state <= FSM_IDLE; 228 | end 229 | else if (tx.tready) begin 230 | unique case (fsm_state) 231 | FSM_IDLE: begin 232 | if (notification && !suppression) begin 233 | if (configuration.event_idx) begin 234 | fsm_state <= FSM_EVENT_IDX; 235 | end 236 | end 237 | else if (not_empty) begin 238 | fsm_state <= FSM_READ_POINTER; 239 | end 240 | end 241 | FSM_EVENT_IDX: begin 242 | fsm_state <= FSM_IDLE; 243 | end 244 | FSM_READ_POINTER: begin 245 | fsm_state <= FSM_DIFFERENCE; 246 | end 247 | default: begin 248 | fsm_state <= FSM_IDLE; 249 | end 250 | endcase 251 | end 252 | end 253 | 254 | always_comb begin 255 | unique case (fsm_state) 256 | FSM_IDLE: begin 257 | request_type = (notification && !suppression) ? 258 | REQUEST_READ_IDX : REQUEST_READ_RING; 259 | end 260 | FSM_EVENT_IDX: begin 261 | request_type = REQUEST_READ_USED_EVENT; 262 | end 263 | default: begin 264 | request_type = REQUEST_READ_RING; 265 | end 266 | endcase 267 | end 268 | 269 | always_comb request = '{ 270 | length: ids, 271 | offset: read_pointer 272 | }; 273 | 274 | always_ff @(posedge aclk or negedge areset_n) begin 275 | if (!areset_n) begin 276 | tx.tvalid <= 1'b0; 277 | end 278 | else if (tx.tready) begin 279 | unique case (fsm_state) 280 | FSM_IDLE: begin 281 | tx.tvalid <= (notification && !suppression) || not_empty; 282 | end 283 | FSM_EVENT_IDX: begin 284 | tx.tvalid <= 1'b1; 285 | end 286 | default: begin 287 | tx.tvalid <= 1'b0; 288 | end 289 | endcase 290 | end 291 | end 292 | 293 | always_ff @(posedge aclk) begin 294 | if (tx.tready) begin 295 | tx.tid <= request_type; 296 | tx.tdata <= request; 297 | end 298 | end 299 | 300 | always_comb tx.tdest = '0; 301 | always_comb tx.tuser = '0; 302 | always_comb tx.tlast = '1; 303 | always_comb tx.tkeep = '1; 304 | always_comb tx.tstrb = '1; 305 | endmodule 306 | -------------------------------------------------------------------------------- /rtl/virtio/available_ring/handler/virtio_available_ring_handler_top.sv: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Tymoteusz Blazejczyk 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | `include "logic.svh" 17 | 18 | module virtio_available_ring_handler_top #( 19 | int MAX_BURST_TRANSACTIONS = 16, 20 | int NOTIFICATION_THRESHOLD_HIGH = 1024, 21 | int NOTIFICATION_THRESHOLD_LOW = 16 22 | ) ( 23 | input aclk, 24 | input areset_n, 25 | /* Configure */ 26 | input configure_tlast, 27 | input configure_tvalid, 28 | input [0:0][7:0] configure_tdata, 29 | input [0:0] configure_tstrb, 30 | input [0:0] configure_tkeep, 31 | input [0:0] configure_tdest, 32 | input [0:0] configure_tuser, 33 | input [0:0] configure_tid, 34 | output logic configure_tready, 35 | /* Notify */ 36 | input notify_tlast, 37 | input notify_tvalid, 38 | input [0:0][7:0] notify_tdata, 39 | input [0:0] notify_tstrb, 40 | input [0:0] notify_tkeep, 41 | input [0:0] notify_tdest, 42 | input [0:0] notify_tuser, 43 | input [0:0] notify_tid, 44 | output logic notify_tready, 45 | /* Rx */ 46 | input rx_tlast, 47 | input rx_tvalid, 48 | input [1:0][7:0] rx_tdata, 49 | input [1:0] rx_tstrb, 50 | input [1:0] rx_tkeep, 51 | input [0:0] rx_tdest, 52 | input [0:0] rx_tuser, 53 | input [0:0] rx_tid, 54 | output logic rx_tready, 55 | /* Tx */ 56 | output logic tx_tlast, 57 | output logic tx_tvalid, 58 | output logic [3:0][7:0] tx_tdata, 59 | output logic [3:0] tx_tstrb, 60 | output logic [3:0] tx_tkeep, 61 | output logic [0:0] tx_tdest, 62 | output logic [0:0] tx_tuser, 63 | output logic [1:0] tx_tid, 64 | input tx_tready 65 | ); 66 | logic_axi4_stream_if 67 | configure (.*); 68 | 69 | logic_axi4_stream_if 70 | notify (.*); 71 | 72 | logic_axi4_stream_if #( 73 | .TDATA_BYTES(2) 74 | ) rx (.*); 75 | 76 | logic_axi4_stream_if #( 77 | .TDATA_BYTES(4), 78 | .TID_WIDTH(2) 79 | ) tx (.*); 80 | 81 | `LOGIC_AXI4_STREAM_IF_RX_ASSIGN(configure, configure); 82 | `LOGIC_AXI4_STREAM_IF_RX_ASSIGN(notify, notify); 83 | `LOGIC_AXI4_STREAM_IF_RX_ASSIGN(rx, rx); 84 | 85 | virtio_available_ring_handler #( 86 | .MAX_BURST_TRANSACTIONS(MAX_BURST_TRANSACTIONS), 87 | .NOTIFICATION_THRESHOLD_HIGH(NOTIFICATION_THRESHOLD_HIGH), 88 | .NOTIFICATION_THRESHOLD_LOW(NOTIFICATION_THRESHOLD_LOW) 89 | ) 90 | unit ( 91 | .* 92 | ); 93 | 94 | `LOGIC_AXI4_STREAM_IF_TX_ASSIGN(tx, tx); 95 | endmodule 96 | -------------------------------------------------------------------------------- /rtl/virtio/available_ring/monitor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_hdl_source(virtio_available_ring_monitor.sv 16 | DEPENDS 17 | logic_axi4_stream_if 18 | logic_reset_synchronizer 19 | virtio_available_ring_pkg 20 | ) 21 | 22 | add_hdl_source(virtio_available_ring_monitor_top.sv 23 | DEPENDS 24 | virtio_available_ring_monitor 25 | ANALYSIS 26 | TRUE 27 | ) 28 | -------------------------------------------------------------------------------- /rtl/virtio/available_ring/monitor/virtio_available_ring_monitor.sv: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Tymoteusz Blazejczyk 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | `include "logic.svh" 17 | 18 | /* Module: virtio_available_ring_monitor 19 | * 20 | * Virtio available ring monitor. 21 | * 22 | * Parameters: 23 | * CAPACITY - Maximum number of descriptor indexes transactions 24 | * that can be stored in buffer. 25 | * MAX_DESCRIPTOR_INDEXES - Maximum number of descriptor indexes per single 26 | * transaction. 27 | * 28 | * Ports: 29 | * aclk - Clock. 30 | * areset_n - Asynchronous active-low reset. 31 | * monitor - AXI4-Stream to monitor buffer for descriptor indexes. 32 | * rx - AXI4-Stream Rx interface for virtqueue requests. 33 | * tx - AXI4-Stream Tx interface for virtqueue requests. 34 | */ 35 | module virtio_available_ring_monitor #( 36 | int CAPACITY = 16, 37 | int MAX_DESCRIPTOR_INDEXES = 4, 38 | int ADDRESS_WIDTH = (CAPACITY >= 2) ? $clog2(CAPACITY) : 1, 39 | int OFFSET_WIDTH = (MAX_DESCRIPTOR_INDEXES >= 2) ? 40 | $clog2(MAX_DESCRIPTOR_INDEXES) : 1 41 | ) ( 42 | input aclk, 43 | input areset_n, 44 | `LOGIC_MODPORT(logic_axi4_stream_if, monitor) monitor, 45 | `LOGIC_MODPORT(logic_axi4_stream_if, rx) rx, 46 | `LOGIC_MODPORT(logic_axi4_stream_if, tx) tx 47 | ); 48 | import virtio_available_ring_pkg::*; 49 | 50 | localparam int OFFSET = MAX_DESCRIPTOR_INDEXES - 1; 51 | localparam int CAPACITY_WIDTH = ADDRESS_WIDTH + 1; 52 | localparam int ALMOST_FULL = CAPACITY - 1; 53 | 54 | initial begin: design_rule_checks 55 | `LOGIC_DRC_POWER_OF_2(CAPACITY) 56 | `LOGIC_DRC_POWER_OF_2(MAX_DESCRIPTOR_INDEXES) 57 | end 58 | 59 | request_t request; 60 | 61 | logic read; 62 | logic write; 63 | logic [15:0] capacity_add_pre; 64 | logic [CAPACITY_WIDTH-1:0] capacity_add; 65 | logic [CAPACITY_WIDTH-1:0] capacity; 66 | logic almost_full; 67 | 68 | always_comb request = request_t'(rx.tdata); 69 | always_comb capacity_add_pre = request.offset + OFFSET[15:0]; 70 | always_comb capacity_add = capacity_add_pre[OFFSET_WIDTH+:CAPACITY_WIDTH]; 71 | 72 | always_comb write = rx.tvalid && tx.tready && !almost_full && 73 | (REQUEST_READ_RING == request_type_t'(rx.tid)); 74 | 75 | always_comb begin 76 | if (rx.tvalid) begin 77 | unique case (request_type_t'(rx.tid)) 78 | REQUEST_READ_RING: begin 79 | rx.tready = tx.tready && !almost_full; 80 | end 81 | default: begin 82 | rx.tready = tx.tready; 83 | end 84 | endcase 85 | end 86 | else begin 87 | rx.tready = tx.tready; 88 | end 89 | end 90 | 91 | always_ff @(posedge aclk or negedge areset_n) begin 92 | if (!areset_n) begin 93 | almost_full <= '0; 94 | end 95 | else begin 96 | almost_full <= (capacity >= ALMOST_FULL[CAPACITY_WIDTH-1:0]); 97 | end 98 | end 99 | 100 | always_ff @(posedge aclk or negedge areset_n) begin 101 | if (!areset_n) begin 102 | read <= '0; 103 | end 104 | else begin 105 | read <= monitor.tvalid && monitor.tready; 106 | end 107 | end 108 | 109 | always_ff @(posedge aclk or negedge areset_n) begin 110 | if (!areset_n) begin 111 | capacity <= '0; 112 | end 113 | else if (write && !read) begin 114 | capacity <= capacity + capacity_add; 115 | end 116 | else if (!write && read) begin 117 | capacity <= capacity - 1'b1; 118 | end 119 | end 120 | 121 | always_ff @(posedge aclk or negedge areset_n) begin 122 | if (!areset_n) begin 123 | tx.tvalid <= '0; 124 | end 125 | else if (tx.tready) begin 126 | if (rx.tvalid) begin 127 | unique case (request_type_t'(rx.tid)) 128 | REQUEST_READ_RING: begin 129 | tx.tvalid <= !almost_full; 130 | end 131 | default: begin 132 | tx.tvalid <= '1; 133 | end 134 | endcase 135 | end 136 | else begin 137 | tx.tvalid <= '0; 138 | end 139 | end 140 | end 141 | 142 | always_ff @(posedge aclk) begin 143 | if (tx.tready) begin 144 | tx.write(rx.read()); 145 | end 146 | end 147 | 148 | `ifdef VERILATOR 149 | logic _unused_signals = &{1'b0, request.length, 1'b0}; 150 | `endif 151 | endmodule 152 | -------------------------------------------------------------------------------- /rtl/virtio/available_ring/monitor/virtio_available_ring_monitor_top.sv: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Tymoteusz Blazejczyk 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | `include "logic.svh" 17 | 18 | module virtio_available_ring_monitor_top #( 19 | int CAPACITY = 16, 20 | int MAX_DESCRIPTOR_INDEXES = 4 21 | ) ( 22 | input aclk, 23 | input areset_n, 24 | /* Monitor */ 25 | input monitor_tlast, 26 | input monitor_tvalid, 27 | input [0:0][7:0] monitor_tdata, 28 | input [0:0] monitor_tstrb, 29 | input [0:0] monitor_tkeep, 30 | input [0:0] monitor_tdest, 31 | input [0:0] monitor_tuser, 32 | input [0:0] monitor_tid, 33 | input monitor_tready, 34 | /* Rx */ 35 | input rx_tlast, 36 | input rx_tvalid, 37 | input [3:0][7:0] rx_tdata, 38 | input [3:0] rx_tstrb, 39 | input [3:0] rx_tkeep, 40 | input [0:0] rx_tdest, 41 | input [0:0] rx_tuser, 42 | input [1:0] rx_tid, 43 | output logic rx_tready, 44 | /* Tx */ 45 | output logic tx_tlast, 46 | output logic tx_tvalid, 47 | output logic [3:0][7:0] tx_tdata, 48 | output logic [3:0] tx_tstrb, 49 | output logic [3:0] tx_tkeep, 50 | output logic [0:0] tx_tdest, 51 | output logic [0:0] tx_tuser, 52 | output logic [1:0] tx_tid, 53 | input tx_tready 54 | ); 55 | logic_axi4_stream_if 56 | monitor (.*); 57 | 58 | logic_axi4_stream_if #( 59 | .TDATA_BYTES(4), 60 | .TID_WIDTH(2) 61 | ) rx (.*); 62 | 63 | logic_axi4_stream_if #( 64 | .TDATA_BYTES(4), 65 | .TID_WIDTH(2) 66 | ) tx (.*); 67 | 68 | always_comb monitor.tvalid = monitor_tvalid; 69 | always_comb monitor.tready = monitor_tready; 70 | always_comb monitor.tlast = monitor_tlast; 71 | always_comb monitor.tdest = monitor_tdest; 72 | always_comb monitor.tuser = monitor_tuser; 73 | always_comb monitor.tstrb = monitor_tstrb; 74 | always_comb monitor.tkeep = monitor_tkeep; 75 | always_comb monitor.tdata = monitor_tdata; 76 | always_comb monitor.tid = monitor_tid; 77 | 78 | `LOGIC_AXI4_STREAM_IF_RX_ASSIGN(rx, rx); 79 | 80 | virtio_available_ring_monitor #( 81 | .CAPACITY(CAPACITY), 82 | .MAX_DESCRIPTOR_INDEXES(MAX_DESCRIPTOR_INDEXES) 83 | ) 84 | unit ( 85 | .* 86 | ); 87 | 88 | `LOGIC_AXI4_STREAM_IF_TX_ASSIGN(tx, tx); 89 | endmodule 90 | -------------------------------------------------------------------------------- /rtl/virtio/packages/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_hdl_source(virtio_available_ring_pkg.sv) 16 | -------------------------------------------------------------------------------- /rtl/virtio/packages/virtio_available_ring_pkg.sv: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Tymoteusz Blazejczyk 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | /* Package: virtio_available_ring_pkg 17 | * 18 | * Virtio available ring package 19 | */ 20 | package virtio_available_ring_pkg; 21 | /* Struct: configuration_t 22 | * 23 | * Configuration. 24 | * 25 | * event_idx - VIRTIO_F_EVENT_IDX was negotiated. 26 | */ 27 | typedef struct packed { 28 | logic event_idx; 29 | } configuration_t; 30 | 31 | /* Struct: request_type_t 32 | * 33 | * Request type. 34 | * 35 | * REQUEST_READ_RING - Request type to read descriptor indexes from 36 | * available ring. 37 | * REQUEST_READ_IDX - Request type to read idx field from 38 | * available ring. 39 | * REQUEST_READ_USED_EVENT - Request type to read used_event field from 40 | * available ring. 41 | */ 42 | typedef enum logic [1:0] { 43 | REQUEST_READ_RING, 44 | REQUEST_READ_IDX, 45 | REQUEST_READ_USED_EVENT 46 | } request_type_t; 47 | 48 | /* Struct: request_t 49 | * 50 | * Request data. 51 | * 52 | * length - Number of descriptor indexes to read from available ring. 53 | * offset - Index offset from available ring base address. 54 | */ 55 | typedef struct packed { 56 | logic [15:0] length; 57 | logic [15:0] offset; 58 | } request_t; 59 | 60 | /* Struct: response_type_t 61 | * 62 | * Response type. See request_type_t. 63 | */ 64 | typedef request_type_t response_type_t; 65 | 66 | /* Struct: response_t 67 | * 68 | * Response data. 69 | * 70 | * offset - Index offset from available ring base address. 71 | */ 72 | typedef struct packed { 73 | logic [15:0] offset; 74 | } response_t; 75 | endpackage 76 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_subdirectory(virtio) 16 | -------------------------------------------------------------------------------- /tests/virtio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_subdirectory(available_ring) 16 | -------------------------------------------------------------------------------- /tests/virtio/available_ring/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_subdirectory(handler) 16 | -------------------------------------------------------------------------------- /tests/virtio/available_ring/handler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Tymoteusz Blazejczyk 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_hdl_unit_test(virtio_available_ring_handler_unit_test.sv 16 | DEPENDS 17 | virtio_available_ring_pkg 18 | virtio_available_ring_handler 19 | ) 20 | -------------------------------------------------------------------------------- /tests/virtio/available_ring/handler/virtio_available_ring_handler_unit_test.sv: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Tymoteusz Blazejczyk 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | `include "svunit_defines.svh" 17 | 18 | module virtio_available_ring_handler_unit_test; 19 | import svunit_pkg::svunit_testcase; 20 | import virtio_available_ring_pkg::*; 21 | 22 | string name = "virtio_available_ring_handler_unit_test"; 23 | svunit_testcase svunit_ut; 24 | 25 | localparam int MAX_BURST_TRANSACTIONS = 16; 26 | localparam int NOTIFICATION_THRESHOLD_HIGH = 1024; 27 | localparam int NOTIFICATION_THRESHOLD_LOW = 16; 28 | 29 | logic aclk = 0; 30 | logic areset_n = 0; 31 | 32 | initial forever #1 aclk = ~aclk; 33 | 34 | logic_axi4_stream_if 35 | notify (.*); 36 | 37 | logic_axi4_stream_if 38 | configure (.*); 39 | 40 | logic_axi4_stream_if #( 41 | .TID_WIDTH($bits(response_t)), 42 | .TDATA_BYTES(2) 43 | ) rx (.*); 44 | 45 | logic_axi4_stream_if #( 46 | .TID_WIDTH($bits(request_t)), 47 | .TDATA_BYTES(4) 48 | ) tx (.*); 49 | 50 | virtio_available_ring_handler #( 51 | .MAX_BURST_TRANSACTIONS(MAX_BURST_TRANSACTIONS), 52 | .NOTIFICATION_THRESHOLD_HIGH(NOTIFICATION_THRESHOLD_HIGH), 53 | .NOTIFICATION_THRESHOLD_LOW(NOTIFICATION_THRESHOLD_LOW) 54 | ) 55 | dut ( 56 | .* 57 | ); 58 | 59 | function void build(); 60 | svunit_ut = new (name); 61 | endfunction 62 | 63 | task setup(); 64 | svunit_ut.setup(); 65 | 66 | areset_n = 0; 67 | @(posedge aclk); 68 | 69 | areset_n = 1; 70 | tx.cb_tx.tready <= 1; 71 | @(posedge aclk); 72 | endtask 73 | 74 | task teardown(); 75 | svunit_ut.teardown(); 76 | 77 | areset_n = 0; 78 | tx.cb_tx.tready <= 0; 79 | endtask 80 | 81 | `SVUNIT_TESTS_BEGIN 82 | 83 | `SVTEST(basic) 84 | fork 85 | begin 86 | byte data[] = new [1]; 87 | 88 | @(notify.cb_rx); 89 | notify.cb_write(data); 90 | end 91 | begin 92 | byte data[]; 93 | request_t request; 94 | 95 | tx.cb_read(data, REQUEST_READ_IDX); 96 | `FAIL_UNLESS_EQUAL(data.size(), 4) 97 | 98 | data = new [2] ('{16'd63}); 99 | rx.cb_write(data); 100 | 101 | tx.cb_read(data, REQUEST_READ_RING); 102 | `FAIL_UNLESS_EQUAL(data.size(), 4) 103 | request = {<<8{data}}; 104 | `FAIL_UNLESS_EQUAL(request.offset, 0) 105 | `FAIL_UNLESS_EQUAL(request.length, 16) 106 | 107 | tx.cb_read(data, REQUEST_READ_RING); 108 | `FAIL_UNLESS_EQUAL(data.size(), 4) 109 | request = {<<8{data}}; 110 | `FAIL_UNLESS_EQUAL(request.offset, 16) 111 | `FAIL_UNLESS_EQUAL(request.length, 16) 112 | 113 | data = new [1]; 114 | notify.cb_write(data); 115 | 116 | tx.cb_read(data, REQUEST_READ_RING); 117 | `FAIL_UNLESS_EQUAL(data.size(), 4) 118 | request = {<<8{data}}; 119 | `FAIL_UNLESS_EQUAL(request.offset, 32) 120 | `FAIL_UNLESS_EQUAL(request.length, 16) 121 | 122 | tx.cb_read(data, REQUEST_READ_RING); 123 | `FAIL_UNLESS_EQUAL(data.size(), 4) 124 | request = {<<8{data}}; 125 | `FAIL_UNLESS_EQUAL(request.offset, 48) 126 | `FAIL_UNLESS_EQUAL(request.length, 15) 127 | end 128 | join 129 | `SVTEST_END 130 | 131 | `SVUNIT_TESTS_END 132 | 133 | endmodule 134 | --------------------------------------------------------------------------------