@@ -30,68 +30,78 @@ def __init__(self, cs) -> None:
3030 self .cs = cs
3131
3232 def get_obj (self , device_name : str ) -> PCIConfig :
33- scope = self .cs .Cfg .get_scope (device_name )
34- vid , device , _ , _ = self .cs .Cfg .convert_internal_scope (scope , device_name )
35- if vid in self .cs .Cfg .CONFIG_PCI and device in self .cs .Cfg .CONFIG_PCI [vid ]:
36- return self .cs .Cfg .CONFIG_PCI [vid ][device ]
37- else :
38- return None
39-
40- def get_first_bus (self , device : dict ) -> int :
41- """Retrieves first value in bus list for PCI device"""
42- if 'bus' in device :
43- return self .get_first (device ['bus' ])
44- raise CSBusNotFoundError ()
45-
46- def get_first (self , a_list : Union [list , int ]) -> int :
47- """Returns received integer or first item from received list"""
48- if type (a_list ) is int :
49- return a_list
50- if type (a_list ) is list :
51- return a_list [0 ]
52- raise CSFirstNotFoundError ()
53-
54- def get_BDF (self , device_name : str ) -> Tuple [int , int , int ]:
55- """Retrieves bus, device, and function values from PCI device"""
56- scope = self .cs .Cfg .get_scope (device_name )
57- vid , device , _ , _ = self .cs .Cfg .convert_internal_scope (scope , device_name )
58- try :
59- device = self .cs .Cfg .CONFIG_PCI [vid ][device ]
60- except KeyError :
61- device = None
62- if device is None or device == {}:
63- raise DeviceNotFoundError (f'DeviceNotFound: { device_name } ' )
64- b = device ['bus' ]
65- d = device ['dev' ]
66- f = device ['fun' ]
67- return (b , d , f )
68-
69- def get_VendorID (self , device_name : str ) -> Tuple [int , int ]:
70- """Retrieves device ID and vendor ID from the PCI device"""
71- (b , d , f ) = self .get_BDF (device_name )
72- return self .cs .hals .Pci .get_DIDVID (b , d , f )
73-
74- def is_enabled (self , device_name : str ) -> bool :
75- """Checks if PCI device is enabled"""
76- if self .is_defined (device_name ):
77- (b , d , f ) = self .get_BDF (device_name )
78- return self .cs .hals .Pci .is_enabled (b , d , f )
79- return False
33+ devlist = self .get_objlist (device_name )
34+ if devlist :
35+ return devlist [0 ]
36+ return None
37+
38+ def get_objlist (self , device_name : str ):
39+ return self .cs .Cfg .get_objlist (self .cs .Cfg .CONFIG_PCI , device_name )
40+
41+ # def get_first_bus(self, device: dict) -> int:
42+ # """Retrieves first value in bus list for PCI device"""
43+ # if 'bus' in device:
44+ # return self.get_first(device['bus'])
45+ # raise CSBusNotFoundError()
46+
47+ # def get_first(self, a_list: Union[list, int]) -> int:
48+ # """Returns received integer or first item from received list"""
49+ # if type(a_list) is int:
50+ # return a_list
51+ # if type(a_list) is list:
52+ # return a_list[0]
53+ # raise CSFirstNotFoundError()
54+
55+ # def get_BDF(self, device_name: str) -> Tuple[int, int, int]:
56+ # """Retrieves bus, device, and function values from PCI device"""
57+ # scope = self.cs.Cfg.get_scope(device_name)
58+ # vid, device, _, _ = self.cs.Cfg.convert_internal_scope(scope, device_name)
59+ # try:
60+ # device = self.cs.Cfg.CONFIG_PCI[vid][device]
61+ # except KeyError:
62+ # device = None
63+ # if device is None or device == {}:
64+ # raise DeviceNotFoundError(f'DeviceNotFound: {device_name}')
65+ # b = device['bus']
66+ # d = device['dev']
67+ # f = device['fun']
68+ # return (b, d, f)
69+
70+ # def get_VendorID(self, device_name: str) -> Tuple[int, int]:
71+ # """Retrieves device ID and vendor ID from the PCI device"""
72+ # (b, d, f) = self.get_BDF(device_name)
73+ # return self.cs.hals.Pci.get_DIDVID(b, d, f)
74+
75+ # def is_enabled(self, device_name: str) -> bool:
76+ # """Checks if PCI device is enabled"""
77+ # if self.is_defined(device_name):
78+ # (b, d, f) = self.get_BDF(device_name)
79+ # return self.cs.hals.Pci.is_enabled(b, d, f)
80+ # return False
8081
8182 def is_defined (self , device_name : str ) -> bool :
8283 """Checks if device is defined in the XML config"""
83- scope = self .cs .Cfg .get_scope (device_name )
84- vid , device , _ , _ = self .cs .Cfg .convert_internal_scope (scope , device_name )
85- return self .cs .Cfg .CONFIG_PCI [vid ].get (device , None ) is not None
84+ return self .get_obj (device_name ) is not None
85+ # scope = self.cs.Cfg.get_scope(device_name)
86+ # vid, device, _, _ = self.cs.Cfg.convert_internal_scope(scope, device_name)
87+ # return self.cs.Cfg.CONFIG_PCI[vid].get(device, None) is not None
8688
8789 def get_bus (self , device_name : str ) -> List [int ]:
8890 """Retrieves bus value(s) from PCI device"""
89- scope = self .cs .Cfg .get_scope (device_name )
90- vid , device , _ , _ = self .cs .Cfg .convert_internal_scope (scope , device_name )
91- if vid in self .cs .Cfg .CONFIG_PCI and device in self .cs .Cfg .CONFIG_PCI [vid ]:
92- return self .cs .Cfg .CONFIG_PCI [vid ][device ].bus
93- else :
94- return []
91+ dev_list = self .get_objlist (device_name )
92+ buses = []
93+ breakpoint ()
94+ for dev in dev_list :
95+ for instance_key in dev .instances .keys ():
96+ buses .append (dev .instances [instance_key ].bus )
97+ return buses
98+
99+ # scope = self.cs.Cfg.get_scope(device_name)
100+ # vid, device, _, _ = self.cs.Cfg.convert_internal_scope(scope, device_name)
101+ # if vid in self.cs.Cfg.CONFIG_PCI and device in self.cs.Cfg.CONFIG_PCI[vid]:
102+ # return self.cs.Cfg.CONFIG_PCI[vid][device].bus
103+ # else:
104+ # return []
95105
96106 # buses = self.cs.Cfg.BUS.get(device_name, [])
97107 # if buses:
0 commit comments