Skip to content

Commit abd5d1d

Browse files
committed
TPMI: Minor improvements
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
1 parent c53a897 commit abd5d1d

1 file changed

Lines changed: 32 additions & 13 deletions

File tree

pepclibs/TPMI.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
import yaml
8585
from pepclibs import CPUModels
8686
from pepclibs.helperlibs import Logging, YAML, ClassHelpers, FSHelpers, ProjectFiles, Trivial, Human
87-
from pepclibs.helperlibs.Exceptions import Error, ErrorNotFound, ErrorNotSupported
87+
from pepclibs.helperlibs.Exceptions import Error, ErrorNotSupported
8888
from pepclibs.helperlibs.Exceptions import ErrorPermissionDenied
8989
from pepclibs.TPMIVars import DEFAULT_VFM, DEFAULT_PLATFORM_NAME, UFS_HEADER_REGNAMES
9090

@@ -380,6 +380,10 @@ def _parse_index_file(specpath: Path, vfm: int) -> SDDTypedDict:
380380
Returns:
381381
Path to a sub-directory within the spec directory containing spec files for the current
382382
platform.
383+
384+
Raises:
385+
ErrorNotSupported: If the index format version is not supported or if the platform (VFM)
386+
is not supported.
383387
"""
384388

385389
def _raise_exc(msg: str) -> NoReturn:
@@ -410,8 +414,8 @@ def _raise_exc(msg: str) -> NoReturn:
410414

411415
version: str = idxdict["version"]
412416
if version != "1.0":
413-
_raise_exc(f"Unsupported index format version '{version}': only version '1.0' is "
414-
f"supported")
417+
raise ErrorNotSupported(f"Unsupported index format version '{version}' in "
418+
f"'{idxpath}': only version '1.0' is supported")
415419

416420
vfms: dict[int, IdxDictVFMEntryTypedDict] = idxdict["vfms"]
417421

@@ -427,8 +431,8 @@ def _raise_exc(msg: str) -> NoReturn:
427431
return sdd
428432

429433
available_vfms = ", ".join(str(vfm) for vfm in vfms)
430-
raise ErrorNotFound(f"No matching platform for VFM {vfm} found in {idxpath}, available VFMs "
431-
f"are: {available_vfms}")
434+
raise ErrorNotSupported(f"Platform with VFM {vfm} is not supported, no spec files found in "
435+
f"{idxpath}. Available VFMs: {available_vfms}")
432436

433437
def get_features(specdirs: Iterable[Path] = (),
434438
vfm: int = -1) -> tuple[dict[str, SDictTypedDict], dict[Path, SDDTypedDict]]:
@@ -451,6 +455,11 @@ def get_features(specdirs: Iterable[Path] = (),
451455
* A dictionary of spec dictionaries for all found TPMI features. Keys are feature names.
452456
* A dictionary of scanned spec directories. Keys are spec directory paths.
453457
458+
Raises:
459+
ErrorNotSupported: If no TPMI spec files are found in the specified directories, if the
460+
index format version is not supported, or if the platform (VFM) is not
461+
supported.
462+
454463
Notes:
455464
1. During the scanning process, only the headers of spec files are read. The entire YAML
456465
file is not parsed, to avoid the overhead of loading complete spec files.
@@ -609,6 +618,11 @@ def __init__(self,
609618
pman: The Process manager object that defines the host to access TPMI registers on. If
610619
not provided, a local process manager will be used.
611620
621+
Raises:
622+
ErrorNotSupported: If the CPU vendor is not Intel, if no TPMI spec files are found,
623+
if no TPMI-related sub-directories are found in debugfs, or if no
624+
TPMI features are found on the system.
625+
612626
Notes:
613627
1. TPMI is designed to be forward-compatible. If VFM is not provided, a default VFM
614628
from an early TPMI-capable platform generation is used (Granite Rapids Xeon),
@@ -773,6 +787,9 @@ def _drop_unimplemented_instances(self,
773787
addr: PCI address of the TPMI device.
774788
mdmap: The memory dump map (mdmap) for the feature.
775789
vals: Register values for all instances and offsets.
790+
791+
Raises:
792+
ErrorNotSupported: If the TPMI interface version is not supported.
776793
"""
777794

778795
expected_major_version = -1
@@ -954,7 +971,12 @@ def get_dummy_tpmi_info(self, addr: str, addrs: set[str]) -> tuple[_MDMapType, i
954971
return mdmap, package
955972

956973
def _build_fmaps(self):
957-
"""Build fmap for all TPMI features and save them in 'self._fmap'."""
974+
"""
975+
Build fmap for all TPMI features and save them in 'self._fmap'.
976+
977+
Raises:
978+
ErrorNotSupported: If no TPMI features are found on the system or in the debugfs dump.
979+
"""
958980

959981
# A dictionary mapping feature names to the list of TPMI device addresses that provide this
960982
# feature.
@@ -1227,7 +1249,9 @@ def _get_regdict(self, fname: str, regname: str) -> RegDictTypedDict:
12271249

12281250
fdict = self._get_fdict(fname)
12291251
if regname not in fdict:
1230-
raise Error(f"BUG: Bad register '{regname}' for feature {fname}")
1252+
available = ", ".join(fdict)
1253+
raise Error(f"Register '{regname}' does not exist for feature '{fname}', "
1254+
f"available registers: {available}")
12311255

12321256
return fdict[regname]
12331257

@@ -1794,12 +1818,7 @@ def iter_feature(self,
17941818
if addr not in fmap:
17951819
continue
17961820

1797-
try:
1798-
mdmap = self._get_mdmap(fname, addr)
1799-
except ErrorNotFound as err:
1800-
# No instances found for this feature on this device, skip it.
1801-
_LOG.debug(err)
1802-
continue
1821+
mdmap = self._get_mdmap(fname, addr)
18031822

18041823
for package in packages:
18051824
if fmap[addr]["package"] != package:

0 commit comments

Comments
 (0)