@@ -208,6 +208,11 @@ class SDDTypedDict(TypedDict, total=False):
208208# Size of the UFS header in bytes.
209209_UFS_HEADER_SIZE : Final [int ] = 16
210210
211+ # TPMI interface version constants.
212+ _TPMI_UNIMPLEMENTED_VERSION : Final [int ] = 0xFF
213+ _TPMI_MAX_MAJOR_VERSION : Final [int ] = 0
214+ _TPMI_MAX_MINOR_VERSION : Final [int ] = 3
215+
211216# Users can define this environment variable to extend the default spec files.
212217_SPECS_PATH_ENVVAR : Final [str ] = "PEPC_TPMI_DATA_PATH"
213218
@@ -816,7 +821,7 @@ def _drop_unimplemented_instances(self,
816821
817822 bfdict = bfdicts ["INTERFACE_VERSION" ]
818823 version = (regval & bfdict ["bitmask" ]) >> bfdict ["bitshift" ]
819- if version == 0xFF :
824+ if version == _TPMI_UNIMPLEMENTED_VERSION :
820825 # Version 0xFF indicates that the instance of the feature is not
821826 # implemented.
822827 _LOG .debug ("TPMI feature '%s', address %s, instance %d%s is not "
@@ -831,7 +836,8 @@ def _drop_unimplemented_instances(self,
831836 minor_version = version & 0b11111
832837
833838 # TPMI interface versions up to version 0.3 are supported.
834- if major_version != 0 or minor_version > 3 :
839+ if major_version != _TPMI_MAX_MAJOR_VERSION or \
840+ minor_version > _TPMI_MAX_MINOR_VERSION :
835841 raise ErrorNotSupported (f"Unsupported TPMI interface version "
836842 f"{ major_version } .{ minor_version } for feature "
837843 f"'{ fname } ', address { addr } { self ._pman .hostmsg } : "
@@ -1277,7 +1283,7 @@ def _validate_instance_offset(self,
12771283 if instance not in mdmap :
12781284 available = Trivial .rangify (mdmap )
12791285 raise Error (f"Bad instance number '{ instance } ' for TPMI feature '{ fname } ' and "
1280- f"device '{ addr } ', available instances: { available } " )
1286+ f"device '{ addr } '{ self . _pman . hostmsg } , available instances: { available } " )
12811287
12821288 if not mdmap [instance ]:
12831289 raise Error (f"TPMI feature '{ fname } ', device '{ addr } ', instance '{ instance } ' is not "
@@ -1286,8 +1292,8 @@ def _validate_instance_offset(self,
12861292 if offset < 0 or offset % 4 != 0 or offset not in mdmap [instance ]:
12871293 max_offset = max (mdmap [instance ])
12881294 raise Error (f"Bad offset '{ offset :#x} ' for register '{ regname } ' of TPMI feature "
1289- f"'{ fname } ': Should be a positive integer aligned to 4 and not "
1290- f"exceeding '{ max_offset } '" )
1295+ f"'{ fname } '{ self . _pman . hostmsg } : Should be a positive integer aligned to 4 "
1296+ f"and not exceeding '{ max_offset } '" )
12911297
12921298 def _adjust_ufs_offset (self , addr : str , instance : int , cluster : int , offset : int ) -> int :
12931299 """
@@ -1664,8 +1670,9 @@ def _validate_regname(self, fname: str, regname: str, bfname: str = ""):
16641670
16651671 regdict = fdict [regname ]
16661672 if bfname and bfname not in regdict ["fields" ]:
1673+ available = ", " .join (regdict ["fields" ])
16671674 raise Error (f"Bit field '{ bfname } ' does not exist in register '{ regname } ' of feature "
1668- f"'{ fname } '" )
1675+ f"'{ fname } ', available bit fields: { available } " )
16691676
16701677 def _validate_instance (self , fname : str , addr : str , instance : int ):
16711678 """
@@ -1722,13 +1729,13 @@ def get_known_features(self) -> dict[str, SDictTypedDict]:
17221729
17231730 Note:
17241731 The returned dictionaries should be treated as read-only and must not be modified.
1732+ For performance reasons, references to internal dictionaries are returned rather than
1733+ deep copies.
17251734
17261735 """
17271736
17281737 sdicts : dict [str , SDictTypedDict ] = {}
17291738 for fname in self ._fmaps :
1730- # It would be safer to return deep copy of the dictionary, but for optimization
1731- # purposes, avoid the copying.
17321739 sdicts [fname ] = self .sdicts [fname ]
17331740 return sdicts
17341741
@@ -1755,11 +1762,10 @@ def get_sdict(self, fname: str) -> SDictTypedDict:
17551762
17561763 Note:
17571764 The returned dictionary should be treated as read-only and must not be modified. For
1758- performance reasons, a deep copy is not returned.
1765+ performance reasons, a reference to the internal dictionary is returned rather than
1766+ a deep copy.
17591767 """
17601768
1761- # It would be safer to return deep copy of the dictionary, but for optimization purposes,
1762- # avoid the copying.
17631769 return self ._get_sdict (fname )
17641770
17651771 def get_fdict (self , fname : str ) -> dict [str , RegDictTypedDict ]:
@@ -1774,11 +1780,10 @@ def get_fdict(self, fname: str) -> dict[str, RegDictTypedDict]:
17741780
17751781 Note:
17761782 The returned dictionary should be treated as read-only and must not be modified. For
1777- performance reasons, a deep copy is not returned.
1783+ performance reasons, a reference to the internal dictionary is returned rather than
1784+ a deep copy.
17781785 """
17791786
1780- # It would be safer to return deep copy of the dictionary, but for optimization purposes,
1781- # avoid the copying.
17821787 return self ._get_fdict (fname )
17831788
17841789 def iter_feature (self ,
0 commit comments