lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright lowRISC contributors. |
| 3 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 5 | r"""Command-line tool to generate boilerplate DV testbench. |
| 6 | |
| 7 | The generated objects are extended from dv_lib / cip_lib. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 8 | """ |
| 9 | import argparse |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 10 | import logging as log |
| 11 | import re |
| 12 | import sys |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 13 | |
Udi Jonnalagadda | 2c9d0f4 | 2020-03-17 17:25:33 -0700 | [diff] [blame] | 14 | import gen_agent |
| 15 | import gen_env |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 16 | |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 17 | VENDOR_DEFAULT = "lowrisc" |
| 18 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 19 | |
| 20 | def main(): |
| 21 | parser = argparse.ArgumentParser( |
| 22 | description=__doc__, |
| 23 | formatter_class=argparse.RawDescriptionHelpFormatter) |
| 24 | parser.add_argument( |
| 25 | "name", |
| 26 | metavar="[ip/block name]", |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 27 | help="""Name of the ip/block for which the UVM TB is being generated. |
| 28 | This should just name the block, not the path to it.""") |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 29 | |
| 30 | parser.add_argument( |
| 31 | "-a", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 32 | "--gen-agent", |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 33 | action='store_true', |
| 34 | help="Generate UVM agent code extended from DV library") |
| 35 | |
| 36 | parser.add_argument( |
| 37 | "-s", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 38 | "--has-separate-host-device-driver", |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 39 | action='store_true', |
| 40 | help= |
| 41 | """IP / block agent creates a separate driver for host and device modes. |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 42 | (Ignored if -a switch is not passed.)""") |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 43 | |
Srikrishna Iyer | 607c404 | 2019-10-23 17:48:05 -0700 | [diff] [blame] | 44 | parser.add_argument("-e", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 45 | "--gen-env", |
Srikrishna Iyer | 607c404 | 2019-10-23 17:48:05 -0700 | [diff] [blame] | 46 | action='store_true', |
| 47 | help="Generate testbench UVM env code") |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 48 | |
| 49 | parser.add_argument( |
| 50 | "-c", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 51 | "--is-cip", |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 52 | action='store_true', |
| 53 | help= |
| 54 | """Is comportable IP - this will result in code being extended from CIP |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 55 | library. If switch is not passed, the code will be extended from DV |
| 56 | library instead. (Ignored if -e switch is not passed.)""") |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 57 | |
| 58 | parser.add_argument( |
Udi Jonnalagadda | 3e460cc | 2020-02-11 15:46:24 -0800 | [diff] [blame] | 59 | "-hr", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 60 | "--has-ral", |
Udi Jonnalagadda | 3e460cc | 2020-02-11 15:46:24 -0800 | [diff] [blame] | 61 | default=False, |
| 62 | action='store_true', |
| 63 | help="""Specify whether the DUT has CSRs and thus needs a UVM RAL model. |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 64 | This option is required if either --is_cip or --has_interrupts |
| 65 | are enabled.""") |
Udi Jonnalagadda | 3e460cc | 2020-02-11 15:46:24 -0800 | [diff] [blame] | 66 | |
| 67 | parser.add_argument( |
Srikrishna Iyer | a8255fd | 2019-10-11 11:58:17 -0700 | [diff] [blame] | 68 | "-hi", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 69 | "--has-interrupts", |
Srikrishna Iyer | a8255fd | 2019-10-11 11:58:17 -0700 | [diff] [blame] | 70 | default=False, |
| 71 | action='store_true', |
| 72 | help="""CIP has interrupts. Create interrupts interface in tb""") |
| 73 | |
| 74 | parser.add_argument( |
| 75 | "-ha", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 76 | "--has-alerts", |
Srikrishna Iyer | a8255fd | 2019-10-11 11:58:17 -0700 | [diff] [blame] | 77 | default=False, |
| 78 | action='store_true', |
| 79 | help="""CIP has alerts. Create alerts interface in tb""") |
| 80 | |
| 81 | parser.add_argument( |
Cindy Chen | 936ebfa | 2020-12-09 13:15:47 -0800 | [diff] [blame] | 82 | "-he", |
| 83 | "--has-edn", |
| 84 | default=False, |
| 85 | action='store_true', |
| 86 | help="""CIP has EDN connection. Create edn pull interface in tb""") |
| 87 | |
| 88 | parser.add_argument( |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 89 | "-ea", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 90 | "--env-agents", |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 91 | nargs="+", |
| 92 | metavar="agt1 agt2", |
| 93 | help="""Env creates an interface agent specified here. They are |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 94 | assumed to already exist. Note that the list is space-separated, |
| 95 | and not comma-separated. (ignored if -e switch is not passed)""" |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 96 | ) |
| 97 | |
| 98 | parser.add_argument( |
| 99 | "-ao", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 100 | "--agent-outdir", |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 101 | metavar="[hw/dv/sv]", |
| 102 | help="""Path to place the agent code. A directory called <name>_agent is |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 103 | created at this location. (default set to './<name>')""") |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 104 | |
| 105 | parser.add_argument( |
| 106 | "-eo", |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 107 | "--env-outdir", |
Srikrishna Iyer | 607c404 | 2019-10-23 17:48:05 -0700 | [diff] [blame] | 108 | metavar="[hw/ip/<ip>]", |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 109 | help="""Path to place the full testbench code. It creates 3 directories |
Srikrishna Iyer | 01c56b4 | 2021-08-02 12:50:11 -0700 | [diff] [blame] | 110 | - dv, data, and doc. The DV doc and the testplan Hjson files are placed |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 111 | in the doc and data directories respectively. These are to be merged |
| 112 | into the IP's root directory (with the existing data and doc |
| 113 | directories). Under dv, it creates 3 sub-directories - env, tb, and |
| 114 | tests - to place all of the testbench sources. (default set to |
| 115 | './<name>'.)""") |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 116 | |
Srikrishna Iyer | 48a6d98 | 2020-01-15 01:26:43 -0800 | [diff] [blame] | 117 | parser.add_argument( |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 118 | "-v", |
| 119 | "--vendor", |
| 120 | default=VENDOR_DEFAULT, |
| 121 | help= |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 122 | """Name of the vendor / entity developing the testbench. This is used |
| 123 | to set the VLNV of the FuseSoC core files.""") |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 124 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 125 | args = parser.parse_args() |
Guillermo Maturana | f61d25d | 2021-05-05 22:29:32 -0700 | [diff] [blame] | 126 | |
| 127 | # The name should be alphanumeric. |
| 128 | if re.search(r"\W", args.name): |
| 129 | log.error("The block name '%s' contains non-alphanumeric characters.", |
| 130 | args.name) |
| 131 | sys.exit(1) |
| 132 | |
Cindy Chen | 5aa4342 | 2020-09-15 11:29:58 -0700 | [diff] [blame] | 133 | if not args.agent_outdir: |
| 134 | args.agent_outdir = args.name |
| 135 | if not args.env_outdir: |
| 136 | args.env_outdir = args.name |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 137 | |
Srikrishna Iyer | 30ed4b0 | 2020-04-01 23:41:50 -0700 | [diff] [blame] | 138 | # The has_ral option must be set if either is_cip or has_interrupts is set, |
| 139 | # as both require use of a RAL model. As such, it is disallowed to not have |
| 140 | # has_ral set if one of these options is set. |
| 141 | if not args.has_ral and (args.is_cip or args.has_interrupts): |
| 142 | args.has_ral = True |
| 143 | print("NOTE: --has_ral switch is enabled since either " |
| 144 | "--is_cip or --has_interrupts is set.") |
Udi Jonnalagadda | 3e460cc | 2020-02-11 15:46:24 -0800 | [diff] [blame] | 145 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 146 | if args.gen_agent: |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 147 | gen_agent.gen_agent(args.name, args.has_separate_host_device_driver, |
| 148 | args.agent_outdir, args.vendor) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 149 | |
| 150 | if args.gen_env: |
Cindy Chen | 5aa4342 | 2020-09-15 11:29:58 -0700 | [diff] [blame] | 151 | if not args.env_agents: |
| 152 | args.env_agents = [] |
Srikrishna Iyer | e9aa88f | 2020-07-21 20:19:33 -0700 | [diff] [blame] | 153 | gen_env.gen_env(args.name, args.is_cip, args.has_ral, |
Canberk Topal | 40e87bc | 2021-10-25 13:07:00 +0100 | [diff] [blame] | 154 | args.has_interrupts, args.has_alerts, args.num_edn, |
Cindy Chen | 936ebfa | 2020-12-09 13:15:47 -0800 | [diff] [blame] | 155 | args.env_agents, args.env_outdir, args.vendor) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 156 | |
| 157 | |
| 158 | if __name__ == '__main__': |
| 159 | main() |