lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | # Copyright lowRISC contributors. |
| 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 4 | import logging as log |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 5 | from enum import Enum |
Eunchan Kim | 6a4b49e | 2020-02-18 10:33:39 -0800 | [diff] [blame] | 6 | from collections import OrderedDict |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 7 | |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 8 | from reggen.validate import check_keys |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 9 | |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 10 | # For the reference |
| 11 | # val_types = { |
| 12 | # 'd': ["int", "integer (binary 0b, octal 0o, decimal, hex 0x)"], |
| 13 | # 'x': ["xint", "x for undefined otherwise int"], |
| 14 | # 'b': [ |
| 15 | # "bitrange", "bit number as decimal integer, \ |
| 16 | # or bit-range as decimal integers msb:lsb" |
| 17 | # ], |
| 18 | # 'l': ["list", "comma separated list enclosed in `[]`"], |
| 19 | # 'ln': ["name list", 'comma separated list enclosed in `[]` of '\ |
| 20 | # 'one or more groups that have just name and dscr keys.'\ |
| 21 | # ' e.g. `{ name: "name", desc: "description"}`'], |
| 22 | # 'lnw': ["name list+", 'name list that optionally contains a width'], |
| 23 | # 'lp': ["parameter list", 'parameter list having default value optionally'], |
| 24 | # 'g': ["group", "comma separated group of key:value enclosed in `{}`"], |
| 25 | # 's': ["string", "string, typically short"], |
| 26 | # 't': ["text", "string, may be multi-line enclosed in `'''` "\ |
| 27 | # "may use `**bold**`, `*italic*` or `!!Reg` markup"], |
| 28 | # 'T': ["tuple", "tuple enclosed in ()"], |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 29 | # 'pi': ["python int", "Native Python type int (generated)"], |
| 30 | # 'pb': ["python Bool", "Native Python type Bool (generated)"], |
| 31 | # 'pl': ["python list", "Native Python type list (generated)"], |
| 32 | # 'pe': ["python enum", "Native Python type enum (generated)"] |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 33 | # } |
| 34 | |
| 35 | # Required/optional field in top hjson |
| 36 | top_required = { |
| 37 | 'name': ['s', 'Top name'], |
| 38 | 'type': ['s', 'type of hjson. Shall be "top" always'], |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 39 | 'clocks': ['g', 'group of clock properties'], |
| 40 | 'resets': ['l', 'list of resets'], |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 41 | 'module': ['l', 'list of modules to instantiate'], |
| 42 | 'memory': [ |
| 43 | 'l', 'list of memories. At least one memory is needed to run \ |
| 44 | the software' |
| 45 | ], |
| 46 | 'debug_mem_base_addr': |
| 47 | ['d', 'Base address of RV_DM. Planned to move to \ |
| 48 | module'], |
| 49 | 'xbar': ['l', 'List of the xbar used in the top'], |
| 50 | } |
| 51 | |
| 52 | top_optional = { |
Eunchan Kim | 1cf66af | 2020-04-30 11:31:53 -0700 | [diff] [blame] | 53 | 'interrupt_module': ['l', 'list of the modules that connects to rv_plic'], |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 54 | 'interrupt': ['lnw', 'interrupts (generated)'], |
Eunchan Kim | 1cf66af | 2020-04-30 11:31:53 -0700 | [diff] [blame] | 55 | 'alert_module': |
Eunchan Kim | 6a4b49e | 2020-02-18 10:33:39 -0800 | [diff] [blame] | 56 | ['l', 'list of the modules that connects to alert_handler'], |
Michael Schaffner | 666dde1 | 2019-10-25 11:57:54 -0700 | [diff] [blame] | 57 | 'alert': ['lnw', 'alerts (generated)'], |
| 58 | 'alert_async': ['l', 'async alerts (generated)'], |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 59 | 'pinmux': ['g', 'pinmux definition if doesn\'t exist, tool uses defaults'], |
| 60 | 'padctrl': |
| 61 | ['g', 'PADS instantiation, if doesn\'t exist, tool creates direct output'], |
Eunchan Kim | 91b58ba | 2020-04-07 08:19:54 -0700 | [diff] [blame] | 62 | 'inter_module': ['g', 'define the signal connections between the modules'], |
Eunchan Kim | 1cf66af | 2020-04-30 11:31:53 -0700 | [diff] [blame] | 63 | 'num_cores': ['pn', "number of computing units"], |
| 64 | 'datawidth': ['pn', "default data width"], |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | top_added = {} |
| 68 | |
| 69 | pinmux_required = {} |
| 70 | pinmux_optional = { |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 71 | 'num_mio': [ |
| 72 | 'd', 'Number of Multiplexed IOs' |
| 73 | ' If padctrl is used, this value will be replaced with #pads' |
| 74 | ' - #DIO' |
| 75 | ], |
Eunchan Kim | 436d224 | 2019-10-29 17:25:51 -0700 | [diff] [blame] | 76 | 'dio_modules': ['l', 'List of Dedicated IOs.'], |
| 77 | 'mio_modules': ['l', 'List of Multiplexed IPs/IOs'], |
| 78 | 'nc_modules': ['l', 'List of NotConnected IOs'], |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 79 | } |
| 80 | pinmux_added = { |
| 81 | 'inputs': ['l', 'Full list of SoC inputs, `module_name.sig_name`'], |
| 82 | 'outputs': ['l', 'Full list of SoC outputs, `module_name.sig_name`'], |
| 83 | } |
| 84 | |
| 85 | padctrl_required = {} |
| 86 | padctrl_optional = { |
| 87 | 'pads': ['l', 'List of pads'], |
| 88 | 'attr_default': ['l', 'List of the attribute'] |
| 89 | } |
| 90 | padctrl_added = {} |
| 91 | |
Timothy Chen | 33b3b9d | 2020-05-08 10:14:17 -0700 | [diff] [blame] | 92 | clock_srcs_required = { |
| 93 | 'name': ['s', 'name of clock group'], |
Timothy Chen | a4cc10d | 2020-05-08 16:06:20 -0700 | [diff] [blame] | 94 | 'aon': ['s', 'yes, no. aon attribute of a clock'], |
Timothy Chen | 33b3b9d | 2020-05-08 10:14:17 -0700 | [diff] [blame] | 95 | 'freq': ['s', 'frequency of clock in Hz'], |
| 96 | } |
| 97 | |
Timothy Chen | fa851de | 2020-08-27 17:10:37 -0700 | [diff] [blame] | 98 | clock_srcs_optional = { |
| 99 | 'derived': ['s', 'whether clock is derived'], |
| 100 | 'params': ['s', 'extra clock parameters'] |
| 101 | } |
| 102 | |
Timothy Chen | b63f3b8 | 2020-06-30 17:10:57 -0700 | [diff] [blame] | 103 | derived_clock_srcs_required = { |
| 104 | 'name': ['s', 'name of clock group'], |
| 105 | 'aon': ['s', 'yes, no. aon attribute of a clock'], |
| 106 | 'freq': ['s', 'frequency of clock in Hz'], |
| 107 | 'src': ['s', 'source clock'], |
| 108 | 'div': ['d', 'ratio between source clock and derived clock'], |
| 109 | } |
| 110 | |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 111 | clock_groups_required = { |
| 112 | 'name': ['s', 'name of clock group'], |
Timothy Chen | f56c1b5 | 2020-04-28 17:00:43 -0700 | [diff] [blame] | 113 | 'src': ['s', 'yes, no. This clock group is directly from source'], |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 114 | 'sw_cg': ['s', 'yes, no, hint. Software clock gate attributes'], |
| 115 | } |
| 116 | clock_groups_optional = { |
| 117 | 'unique': ['s', 'whether clocks in the group are unique'], |
| 118 | 'clocks': ['g', 'groups of clock name to source'], |
| 119 | } |
| 120 | clock_groups_added = {} |
| 121 | |
Timothy Chen | 1daf582 | 2020-10-26 17:28:15 -0700 | [diff] [blame^] | 122 | eflash_required = { |
| 123 | 'banks': ['d', 'number of flash banks'], |
| 124 | 'pages_per_bank': ['d', 'number of data pages per flash bank'], |
| 125 | 'clock_srcs': ['g', 'clock connections'], |
| 126 | 'clock_group': ['s', 'associated clock attribute group'], |
| 127 | 'reset_connections': ['g', 'reset connections'], |
| 128 | 'type': ['s', 'type of memory'], |
| 129 | 'base_addr': ['s', 'strarting hex address of memory'], |
| 130 | 'swaccess': ['s', 'software accessibility'], |
| 131 | 'inter_signal_list': ['lg', 'intersignal list'] |
| 132 | } |
| 133 | |
| 134 | eflash_optional = {} |
| 135 | |
| 136 | eflash_added = {} |
| 137 | |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 138 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 139 | class TargetType(Enum): |
| 140 | MODULE = "module" |
| 141 | XBAR = "xbar" |
| 142 | |
| 143 | |
| 144 | class Target: |
| 145 | """Target class informs the checkers if we are validating a module or xbar |
| 146 | """ |
| 147 | |
| 148 | # The type of this target |
| 149 | target_type = "" |
| 150 | |
| 151 | # The key to search against |
| 152 | key = "" |
| 153 | |
| 154 | def __init__(self, target_type): |
| 155 | self.target_type = target_type |
| 156 | if target_type == TargetType.MODULE: |
| 157 | self.key = "type" |
| 158 | else: |
| 159 | self.key = "name" |
| 160 | |
| 161 | |
Timothy Chen | 1daf582 | 2020-10-26 17:28:15 -0700 | [diff] [blame^] | 162 | class Flash: |
| 163 | """Flash class contains information regarding parameter defaults. |
| 164 | For now, only expose banks / pages_per_bank for user configuration. |
| 165 | For now, also enforce power of 2 requiremnt. |
| 166 | """ |
| 167 | max_banks = 4 |
| 168 | max_pages_per_bank = 1024 |
| 169 | |
| 170 | def __init__(self, banks, pages_per_bank): |
| 171 | self.banks = banks |
| 172 | self.pages_per_bank = pages_per_bank |
| 173 | self.words_per_page = 128 |
| 174 | self.data_width = 64 |
| 175 | self.metadata_width = 12 |
| 176 | self.info_types = 2 |
| 177 | self.infos_per_bank = [4, 4] |
| 178 | |
| 179 | def is_pow2(self, n): |
| 180 | return (n != 0) and (n & (n - 1) == 0) |
| 181 | |
| 182 | def check_values(self): |
| 183 | pow2_check = self.is_pow2(self.banks) and self.is_pow2(self.pages_per_bank) |
| 184 | limit_check = (self.banks <= Flash.max_banks) \ |
| 185 | and (self.pages_per_bank <= Flash.max_pages_per_bank) |
| 186 | |
| 187 | return pow2_check and limit_check |
| 188 | |
| 189 | def calc_size(self): |
| 190 | word_bytes = self.data_width / 8 |
| 191 | bytes_per_page = word_bytes * self.words_per_page |
| 192 | bytes_per_bank = bytes_per_page * self.pages_per_bank |
| 193 | return bytes_per_bank * self.banks |
| 194 | |
| 195 | def populate(self, mem): |
| 196 | mem['words_per_page'] = self.words_per_page |
| 197 | mem['data_width'] = self.data_width |
| 198 | mem['metadata_width'] = self.metadata_width |
| 199 | mem['info_types'] = self.info_types |
| 200 | mem['infos_per_bank'] = self.infos_per_bank |
| 201 | mem['size'] = hex(int(self.calc_size())) |
| 202 | |
| 203 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 204 | # Check to see if each module/xbar defined in top.hjson exists as ip/xbar.hjson |
| 205 | # Also check to make sure there are not multiple definitions of ip/xbar.hjson for each |
| 206 | # top level definition |
| 207 | # If it does, return a dictionary of instance names to index in ip/xbarobjs |
| 208 | def check_target(top, objs, tgtobj): |
| 209 | error = 0 |
Eunchan Kim | 6a4b49e | 2020-02-18 10:33:39 -0800 | [diff] [blame] | 210 | idxs = OrderedDict() |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 211 | |
| 212 | for i in range(len(objs)): |
| 213 | log.info("%d Order is %s" % (i, objs[i]['name'].lower())) |
| 214 | |
| 215 | tgt_type = tgtobj.target_type.value |
| 216 | inst_key = tgtobj.key |
| 217 | |
| 218 | for cfg in top[tgt_type]: |
| 219 | cfg_name = cfg['name'].lower() |
| 220 | log.info("Checking target %s %s" % (tgt_type, cfg_name)) |
| 221 | tgt_def = [o for o in objs if cfg[inst_key] == o['name'].lower()] |
| 222 | error += check_def(tgt_def, cfg_name) |
| 223 | if error: |
| 224 | log.error("Target existence check failed") |
| 225 | break |
| 226 | else: |
| 227 | idxs[cfg_name] = objs.index(tgt_def[0]) |
| 228 | |
| 229 | log.info("Current state %s" % idxs) |
| 230 | return error, idxs |
| 231 | |
| 232 | |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 233 | def check_padctrl(top, prefix): |
| 234 | error = check_keys(top["padctrl"], padctrl_required, padctrl_optional, |
| 235 | padctrl_added, prefix + " PadControl") |
| 236 | return error |
| 237 | |
| 238 | |
| 239 | def check_pinmux(top, prefix): |
| 240 | return 0 |
| 241 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 242 | |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 243 | # check for inconsistent clock group definitions |
| 244 | def check_clock_groups(top): |
| 245 | |
| 246 | # default empty assignment |
| 247 | if "groups" not in top['clocks']: |
| 248 | top['clocks']['groups'] = [] |
| 249 | |
| 250 | error = 0 |
| 251 | for group in top['clocks']['groups']: |
| 252 | error = check_keys(group, clock_groups_required, clock_groups_optional, |
| 253 | clock_groups_added, "Clock Groups") |
| 254 | |
| 255 | # Check sw_cg values are valid |
| 256 | if group['sw_cg'] not in ['yes', 'no', 'hint']: |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 257 | log.error("Incorrect attribute for sw_cg: {}".format( |
| 258 | group['sw_cg'])) |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 259 | error += 1 |
| 260 | |
Timothy Chen | f56c1b5 | 2020-04-28 17:00:43 -0700 | [diff] [blame] | 261 | # Check combination of src and sw are valid |
Timothy Chen | a4cc10d | 2020-05-08 16:06:20 -0700 | [diff] [blame] | 262 | if group['src'] == 'yes' and group['sw_cg'] != 'no': |
Timothy Chen | f56c1b5 | 2020-04-28 17:00:43 -0700 | [diff] [blame] | 263 | log.error("Invalid combination of src and sw_cg: {} and {}".format( |
| 264 | group['src'], group['sw_cg'])) |
| 265 | error += 1 |
| 266 | |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 267 | # Check combination of sw_cg and unique are valid |
| 268 | unique = group['unique'] if 'unique' in group else 'no' |
| 269 | if group['sw_cg'] == 'no' and unique != 'no': |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 270 | log.error( |
| 271 | "Incorrect attribute combination. When sw_cg is no, unique must be no" |
| 272 | ) |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 273 | error += 1 |
| 274 | |
| 275 | if error: |
| 276 | break |
| 277 | |
| 278 | return error |
| 279 | |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 280 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 281 | def check_clocks_resets(top, ipobjs, ip_idxs, xbarobjs, xbar_idxs): |
Timothy Chen | 33b3b9d | 2020-05-08 10:14:17 -0700 | [diff] [blame] | 282 | |
Timothy Chen | b63f3b8 | 2020-06-30 17:10:57 -0700 | [diff] [blame] | 283 | error = 0 |
| 284 | |
Timothy Chen | 33b3b9d | 2020-05-08 10:14:17 -0700 | [diff] [blame] | 285 | # check clock fields are all there |
Timothy Chen | b63f3b8 | 2020-06-30 17:10:57 -0700 | [diff] [blame] | 286 | ext_srcs = [] |
Timothy Chen | 33b3b9d | 2020-05-08 10:14:17 -0700 | [diff] [blame] | 287 | for src in top['clocks']['srcs']: |
Timothy Chen | fa851de | 2020-08-27 17:10:37 -0700 | [diff] [blame] | 288 | check_keys(src, clock_srcs_required, clock_srcs_optional, {}, "Clock source") |
Timothy Chen | b63f3b8 | 2020-06-30 17:10:57 -0700 | [diff] [blame] | 289 | ext_srcs.append(src['name']) |
| 290 | |
| 291 | # check derived clock sources |
| 292 | log.info("Collected clocks are {}".format(ext_srcs)) |
| 293 | for src in top['clocks']['derived_srcs']: |
| 294 | check_keys(src, derived_clock_srcs_required, {}, {}, "Derived clocks") |
| 295 | try: |
| 296 | ext_srcs.index(src['src']) |
| 297 | except Exception: |
| 298 | error += 1 |
| 299 | log.error("{} is not a valid src for {}".format(src['src'], src['name'])) |
Timothy Chen | 33b3b9d | 2020-05-08 10:14:17 -0700 | [diff] [blame] | 300 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 301 | # all defined clock/reset nets |
Timothy Chen | c623393 | 2020-08-19 15:34:07 -0700 | [diff] [blame] | 302 | reset_nets = [reset['name'] for reset in top['resets']['nodes']] |
Timothy Chen | b63f3b8 | 2020-06-30 17:10:57 -0700 | [diff] [blame] | 303 | clock_srcs = [clock['name'] for clock in top['clocks']['srcs'] + |
| 304 | top['clocks']['derived_srcs']] |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 305 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 306 | # Check clock/reset port connection for all IPs |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 307 | for ipcfg in top['module']: |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 308 | ipcfg_name = ipcfg['name'].lower() |
| 309 | log.info("Checking clock/resets for %s" % ipcfg_name) |
| 310 | error += validate_reset(ipcfg, ipobjs[ip_idxs[ipcfg_name]], reset_nets) |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 311 | error += validate_clock(ipcfg, ipobjs[ip_idxs[ipcfg_name]], clock_srcs) |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 312 | |
| 313 | if error: |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 314 | log.error("module clock/reset checking failed") |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 315 | break |
| 316 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 317 | # Check clock/reset port connection for all xbars |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 318 | for xbarcfg in top['xbar']: |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 319 | xbarcfg_name = xbarcfg['name'].lower() |
| 320 | log.info("Checking clock/resets for xbar %s" % xbarcfg_name) |
| 321 | error += validate_reset(xbarcfg, xbarobjs[xbar_idxs[xbarcfg_name]], |
| 322 | reset_nets, "xbar") |
| 323 | error += validate_clock(xbarcfg, xbarobjs[xbar_idxs[xbarcfg_name]], |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 324 | clock_srcs, "xbar") |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 325 | |
| 326 | if error: |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 327 | log.error("xbar clock/reset checking failed") |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 328 | break |
| 329 | |
| 330 | return error |
| 331 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 332 | |
| 333 | def check_def(inst_def, name): |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 334 | error = 0 |
| 335 | if not inst_def: |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 336 | log.error("Could not find %s.hjson" % name) |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 337 | error += 1 |
| 338 | |
| 339 | if len(inst_def) > 1: |
| 340 | log.error("Duplicate %s.hjson" % name) |
| 341 | error += 1 |
| 342 | |
| 343 | return error |
| 344 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 345 | |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 346 | # Checks the following |
| 347 | # For each defined reset connection in top*.hjson, there exists a defined port at the destination |
| 348 | # and defined reset net |
| 349 | # There are the same number of defined connections as there are ports |
| 350 | def validate_reset(top, inst, reset_nets, prefix=""): |
| 351 | # Gather inst port list |
| 352 | error = 0 |
| 353 | inst_port_list = [] |
| 354 | if 'reset_primary' not in inst.keys(): |
| 355 | log.info("%s %s does not have a reset_primary defined, default used" % |
| 356 | (prefix, inst['name'])) |
| 357 | inst_port_list.append("rst_ni") |
| 358 | else: |
| 359 | inst_port_list.append(inst['reset_primary']) |
| 360 | |
| 361 | if 'other_reset_list' in inst.keys(): |
| 362 | inst_port_list.extend(inst['other_reset_list']) |
| 363 | log.info("%s %s resets are %s" % |
| 364 | (prefix, inst['name'].lower(), inst_port_list)) |
| 365 | |
| 366 | if len(top['reset_connections'].keys()) != len(inst_port_list): |
| 367 | error += 1 |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 368 | log.error("%s %s mismatched number of reset ports and nets" % |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 369 | (prefix, inst['name'])) |
| 370 | |
| 371 | missing_port = [ |
| 372 | port for port in top['reset_connections'].keys() |
| 373 | if port not in inst_port_list |
| 374 | ] |
| 375 | |
| 376 | if missing_port: |
| 377 | error += 1 |
| 378 | log.error("%s %s Following reset ports do not exist:" % |
| 379 | (prefix, inst['name'])) |
| 380 | [log.error("%s" % port) for port in missing_port] |
| 381 | |
| 382 | missing_net = [ |
| 383 | net for port, net in top['reset_connections'].items() |
| 384 | if net not in reset_nets |
| 385 | ] |
| 386 | |
| 387 | if missing_net: |
| 388 | error += 1 |
| 389 | log.error("%s %s Following reset nets do not exist:" % |
| 390 | (prefix, inst['name'])) |
| 391 | [log.error("%s" % net) for net in missing_net] |
| 392 | |
| 393 | return error |
| 394 | |
| 395 | |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 396 | # Checks the following |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 397 | # For each defined clock_src in top*.hjson, there exists a defined port at the destination |
| 398 | # and defined clock source |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 399 | # There are the same number of defined connections as there are ports |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 400 | def validate_clock(top, inst, clock_srcs, prefix=""): |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 401 | # Gather inst port list |
| 402 | error = 0 |
| 403 | inst_port_list = [] |
| 404 | if 'clock_primary' not in inst.keys(): |
| 405 | log.info("%s %s does not have a clock_primary defined, default used" % |
| 406 | (prefix, inst['name'])) |
| 407 | inst_port_list.append("clk_i") |
| 408 | else: |
| 409 | inst_port_list.append(inst['clock_primary']) |
| 410 | |
| 411 | if 'other_clock_list' in inst.keys(): |
| 412 | inst_port_list.extend(inst['other_clock_list']) |
| 413 | log.info("%s %s clocks are %s" % |
| 414 | (prefix, inst['name'].lower(), inst_port_list)) |
| 415 | |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 416 | if len(top['clock_srcs'].keys()) != len(inst_port_list): |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 417 | error += 1 |
| 418 | log.error("%s %s mismatched number of clock ports and nets" % |
| 419 | (prefix, inst['name'])) |
| 420 | |
| 421 | missing_port = [ |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 422 | port for port in top['clock_srcs'].keys() if port not in inst_port_list |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 423 | ] |
| 424 | |
| 425 | if missing_port: |
| 426 | error += 1 |
| 427 | log.error("%s %s Following clock ports do not exist:" % |
| 428 | (prefix, inst['name'])) |
| 429 | [log.error("%s" % port) for port in missing_port] |
| 430 | |
| 431 | missing_net = [ |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 432 | net for port, net in top['clock_srcs'].items() if net not in clock_srcs |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 433 | ] |
| 434 | |
| 435 | if missing_net: |
| 436 | error += 1 |
| 437 | log.error("%s %s Following clock nets do not exist:" % |
| 438 | (prefix, inst['name'])) |
| 439 | [log.error("%s" % net) for net in missing_net] |
| 440 | |
| 441 | return error |
| 442 | |
| 443 | |
Timothy Chen | 1daf582 | 2020-10-26 17:28:15 -0700 | [diff] [blame^] | 444 | def check_flash(top): |
| 445 | error = 0 |
| 446 | |
| 447 | for mem in top['memory']: |
| 448 | if mem['type'] == "eflash": |
| 449 | error = check_keys(mem, eflash_required, eflash_optional, |
| 450 | eflash_added, "Eflash") |
| 451 | |
| 452 | flash = Flash(mem['banks'], mem['pages_per_bank']) |
| 453 | error += 1 if not flash.check_values() else 0 |
| 454 | |
| 455 | if error: |
| 456 | log.error("Flash check failed") |
| 457 | else: |
| 458 | flash.populate(mem) |
| 459 | |
| 460 | return error |
| 461 | |
| 462 | |
Timothy Chen | 3193b00 | 2019-10-04 16:56:05 -0700 | [diff] [blame] | 463 | def validate_top(top, ipobjs, xbarobjs): |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 464 | # return as it is for now |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 465 | error = check_keys(top, top_required, top_optional, top_added, "top") |
| 466 | |
| 467 | if error != 0: |
| 468 | log.error("Top HJSON has top level errors. Aborting") |
| 469 | return top, error |
| 470 | |
| 471 | component = top['name'] |
| 472 | |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 473 | # MODULE check |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 474 | err, ip_idxs = check_target(top, ipobjs, Target(TargetType.MODULE)) |
| 475 | error += err |
| 476 | |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 477 | # XBAR check |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 478 | err, xbar_idxs = check_target(top, xbarobjs, Target(TargetType.XBAR)) |
| 479 | error += err |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 480 | |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 481 | # MEMORY check |
Timothy Chen | 1daf582 | 2020-10-26 17:28:15 -0700 | [diff] [blame^] | 482 | error += check_flash(top) |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 483 | |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 484 | # Clock / Reset check |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 485 | error += check_clocks_resets(top, ipobjs, ip_idxs, xbarobjs, xbar_idxs) |
| 486 | |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 487 | # Clock group check |
Timothy Chen | 0550d69 | 2020-04-20 17:19:35 -0700 | [diff] [blame] | 488 | error += check_clock_groups(top) |
| 489 | |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 490 | # RV_PLIC check |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 491 | |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 492 | # PINMUX & PADS check |
| 493 | if "padctrl" not in top: |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 494 | log.warning("padsctrl field doesn't exist in top. Skipping pads \ |
| 495 | generation. Top input/output are directly connected from \ |
| 496 | peripherals.") |
| 497 | # Pads configuration check |
| 498 | else: |
Timothy Chen | 80bd8aa | 2019-10-04 15:57:11 -0700 | [diff] [blame] | 499 | error += check_padctrl(top, component) |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 500 | |
Eunchan Kim | 529134b | 2020-04-24 09:51:06 -0700 | [diff] [blame] | 501 | if "pinmux" not in top: |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 502 | log.warning("Top {} has no 'pinmux' field. Please consider specifying \ |
| 503 | pinmux and pads configuration") |
Eunchan Kim | 6a4b49e | 2020-02-18 10:33:39 -0800 | [diff] [blame] | 504 | top["pinmux"] = OrderedDict() |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 505 | # checking pinmux after pads as dio connects to PAD |
| 506 | |
| 507 | error += check_pinmux(top, component) |
| 508 | |
Eunchan Kim | 632c6f7 | 2019-09-30 11:11:51 -0700 | [diff] [blame] | 509 | return top, error |