Skip to content

Commit 40929ef

Browse files
Wei Liuwenlingz
authored andcommitted
acrn-config: walk secondary PCI Bus for target board
There may be more than one PCI segment in target board, and DRHD info should be parsed correctly base on secondary PCI bus. currently board_parser.py tool did not handle such case. Add this patch for walking secondary PCI Bus. Tracked-On: #4143 Signed-off-by: Wei Liu <weix.w.liu@intel.com> Acked-by: Victor Sun <victor.sun@intel.com>
1 parent 5e92342 commit 40929ef

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

misc/acrn-config/target/dmar.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# SPDX-License-Identifier: BSD-3-Clause
44
#
55

6+
import sys
67
import ctypes
8+
import parser_lib
79

810
ACPI_DMAR_TYPE = {
911
'ACPI_DMAR_TYPE_HARDWARE_UNIT':0,
@@ -167,6 +169,7 @@ def style_check_2(self):
167169
# config from the other part of tools, so hard code the GPU_SBDF to gernerate DRHDx_IGNORE macro
168170
CONFIG_GPU_SBDF = 0x10
169171

172+
PCI_BRIDGE_HEADER = 1
170173

171174
class PathDevFun:
172175
"""Path Device Function meta data"""
@@ -184,6 +187,56 @@ def style_check_2(self):
184187
self.path = 0
185188

186189

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+
187240
def walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, drhd_cnt):
188241
"""Walk Pci bus
189242
: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):
200253
tmp_pdf.function = scope_path.function
201254
tmp_pdf.path = (((tmp_pdf.device & 0x1F) << 3) | ((tmp_pdf.function & 0x7)))
202255

256+
# walk the secondary pci bus
257+
get_secondary_bus(dmar_tbl, tmp_pdf.device, tmp_pdf.function)
258+
203259
if ((dmar_tbl.dmar_drhd.segment << 16) | (
204260
dmar_tbl.dmar_dev_scope.bus << 8) | tmp_pdf.path) == CONFIG_GPU_SBDF:
205261
dmar_hw_list.hw_ignore[drhd_cnt] = 'true'

0 commit comments

Comments
 (0)