3
3
# SPDX-License-Identifier: BSD-3-Clause
4
4
#
5
5
6
+ import sys
6
7
import ctypes
8
+ import parser_lib
7
9
8
10
ACPI_DMAR_TYPE = {
9
11
'ACPI_DMAR_TYPE_HARDWARE_UNIT' :0 ,
@@ -167,6 +169,7 @@ def style_check_2(self):
167
169
# config from the other part of tools, so hard code the GPU_SBDF to gernerate DRHDx_IGNORE macro
168
170
CONFIG_GPU_SBDF = 0x10
169
171
172
+ PCI_BRIDGE_HEADER = 1
170
173
171
174
class PathDevFun :
172
175
"""Path Device Function meta data"""
@@ -184,6 +187,56 @@ def style_check_2(self):
184
187
self .path = 0
185
188
186
189
190
+ def get_secondary_bus (dmar_tbl , tmp_dev , tmp_fun ):
191
+
192
+ cmd = "lspci -xxx"
193
+ secondary_bus_str = ''
194
+ found_pci_bdf = False
195
+ pci_bridge_header_type = False
196
+ res = parser_lib .cmd_execute (cmd )
197
+
198
+ while True :
199
+ line = res .stdout .readline ().decode ("ascii" )
200
+
201
+ if not line :
202
+ break
203
+
204
+ if ':' not in line or len (line .strip ().split (":" )) < 1 :
205
+ continue
206
+
207
+ if not found_pci_bdf :
208
+ if '.' not in line .strip ():
209
+ continue
210
+
211
+ bus = int (line .strip ().split (":" )[0 ], 16 )
212
+ dev = int (line .strip ().split ()[0 ].split (":" )[1 ].split ("." )[0 ], 16 )
213
+ fun = int (line .strip ().split ()[0 ].split (":" )[1 ].split ("." )[1 ].strip (), 16 )
214
+ if bus == dmar_tbl .dmar_dev_scope .bus and dev == tmp_dev and fun == tmp_fun :
215
+ found_pci_bdf = True
216
+ continue
217
+ else :
218
+ if "00:" == line .strip ().split ()[0 ]:
219
+ # PCI Header type stores in 0xE
220
+ if len (line .split ()) >= 16 and int (line .strip ().split ()[15 ], 16 ) & 0x7 == PCI_BRIDGE_HEADER :
221
+ pci_bridge_header_type = True
222
+ continue
223
+
224
+ if not pci_bridge_header_type :
225
+ continue
226
+
227
+ # found the pci device, parse the secondary bus
228
+ if "10:" == line .strip ().split ()[0 ]:
229
+ # Secondary PCI BUS number stores in 0x18
230
+ secondary_bus_str = line .split ()[9 ]
231
+ found_pci_bdf = False
232
+ pci_bridge_header_type = False
233
+ break
234
+
235
+ # the pci device has secondary bus
236
+ if secondary_bus_str :
237
+ dmar_tbl .dmar_dev_scope .bus = int (secondary_bus_str , 16 )
238
+
239
+
187
240
def walk_pci_bus (tmp_pdf , dmar_tbl , dmar_hw_list , drhd_cnt ):
188
241
"""Walk Pci bus
189
242
:param tmp_pdf: it is a class what contains path,device,function in dmar device scope region
@@ -200,6 +253,9 @@ def walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, drhd_cnt):
200
253
tmp_pdf .function = scope_path .function
201
254
tmp_pdf .path = (((tmp_pdf .device & 0x1F ) << 3 ) | ((tmp_pdf .function & 0x7 )))
202
255
256
+ # walk the secondary pci bus
257
+ get_secondary_bus (dmar_tbl , tmp_pdf .device , tmp_pdf .function )
258
+
203
259
if ((dmar_tbl .dmar_drhd .segment << 16 ) | (
204
260
dmar_tbl .dmar_dev_scope .bus << 8 ) | tmp_pdf .path ) == CONFIG_GPU_SBDF :
205
261
dmar_hw_list .hw_ignore [drhd_cnt ] = 'true'
0 commit comments