2019-07-30 09:20:40 +08:00
|
|
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
#
|
|
|
|
|
|
|
|
import collections
|
|
|
|
import board_cfg_lib
|
2020-03-26 17:07:49 +08:00
|
|
|
import common
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
PCI_HEADER = r"""
|
|
|
|
#ifndef PCI_DEVICES_H_
|
|
|
|
#define PCI_DEVICES_H_
|
|
|
|
"""
|
|
|
|
PCI_END_HEADER = r"""
|
|
|
|
#endif /* PCI_DEVICES_H_ */"""
|
|
|
|
|
2020-03-06 11:04:46 +08:00
|
|
|
def write_pbdf(i_cnt, bdf, bar_attr, config):
|
2019-09-05 13:31:11 +08:00
|
|
|
"""
|
|
|
|
Parser and generate pbdf
|
2020-03-06 11:04:46 +08:00
|
|
|
:param i_cnt: the number of pci devices have the same PCI sub class name
|
2019-08-02 19:17:58 +08:00
|
|
|
:param bdf: it is a string what contains BDF
|
2020-03-06 11:04:46 +08:00
|
|
|
:param bar_attr: it is a class, contains PIC bar attribute
|
2019-08-02 19:17:58 +08:00
|
|
|
:param config: it is a file pointer of pci information for writing to
|
|
|
|
"""
|
2019-07-30 09:20:40 +08:00
|
|
|
# if there is only one host bridge, then will discard the index of suffix
|
2020-03-06 11:04:46 +08:00
|
|
|
if i_cnt == 0 and bar_attr.name.upper() == "HOST BRIDGE":
|
|
|
|
tmp_sub_name = "_".join(bar_attr.name.split()).upper()
|
2019-07-30 09:20:40 +08:00
|
|
|
else:
|
2020-03-06 11:04:46 +08:00
|
|
|
if '-' in bar_attr.name:
|
2020-03-26 17:07:49 +08:00
|
|
|
tmp_sub_name = common.undline_name(bar_attr.name) + "_" + str(i_cnt)
|
2019-09-05 13:31:11 +08:00
|
|
|
else:
|
2020-03-06 11:04:46 +08:00
|
|
|
tmp_sub_name = "_".join(bar_attr.name.split()).upper() + "_" + str(i_cnt)
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-04-20 05:56:10 +08:00
|
|
|
board_cfg_lib.PCI_DEV_BAR_DESC.pci_dev_dic[bdf].name_w_i_cnt = tmp_sub_name
|
|
|
|
|
2019-07-30 09:20:40 +08:00
|
|
|
bus = int(bdf.split(':')[0], 16)
|
|
|
|
dev = int(bdf.split(':')[1].split('.')[0], 16)
|
|
|
|
fun = int(bdf.split('.')[1], 16)
|
|
|
|
print("#define %-32s" % tmp_sub_name, end="", file=config)
|
|
|
|
print(" .pbdf.bits = {{.b = 0x{:02X}U, .d = 0x{:02X}U, .f = 0x{:02X}U}}".format(
|
|
|
|
bus, dev, fun), end="", file=config)
|
|
|
|
|
2020-03-06 11:04:46 +08:00
|
|
|
if not bar_attr.remappable:
|
|
|
|
align = ' ' * 48
|
|
|
|
print("\n{}/* TODO: add {} 64bit BAR support */".format(align, tmp_sub_name), file=config)
|
|
|
|
return
|
|
|
|
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-03-06 11:04:46 +08:00
|
|
|
def write_vbar(i_cnt, bdf, pci_bar_dic, bar_attr, config):
|
2019-09-05 13:31:11 +08:00
|
|
|
"""
|
|
|
|
Parser and generate vbar
|
2020-03-06 11:04:46 +08:00
|
|
|
:param i_cnt: the number of pci devices have the same PCI sub class name
|
2019-08-02 19:17:58 +08:00
|
|
|
:param bdf: it is a string what contains BDF
|
|
|
|
:param pci_bar_dic: it is a dictionary of pci vbar for those BDF
|
2020-03-06 11:04:46 +08:00
|
|
|
:param bar_attr: it is a class, contains PIC bar attribute
|
2019-08-02 19:17:58 +08:00
|
|
|
:param config: it is a file pointer of pci information for writing to
|
|
|
|
"""
|
2019-07-30 09:20:40 +08:00
|
|
|
tail = 0
|
|
|
|
align = ' ' * 48
|
2020-03-06 11:04:46 +08:00
|
|
|
ptdev_mmio_str = ''
|
|
|
|
|
2020-03-26 17:07:49 +08:00
|
|
|
tmp_sub_name = common.undline_name(bar_attr.name) + "_" + str(i_cnt)
|
2019-07-30 09:20:40 +08:00
|
|
|
if bdf in pci_bar_dic.keys():
|
|
|
|
bar_list = list(pci_bar_dic[bdf].keys())
|
|
|
|
bar_len = len(bar_list)
|
|
|
|
bar_num = 0
|
|
|
|
for bar_i in bar_list:
|
2020-03-06 11:04:46 +08:00
|
|
|
if not bar_attr.remappable:
|
|
|
|
return
|
|
|
|
|
2019-07-30 09:20:40 +08:00
|
|
|
if tail == 0:
|
|
|
|
print(", \\", file=config)
|
|
|
|
tail += 1
|
|
|
|
bar_num += 1
|
2020-03-06 11:04:46 +08:00
|
|
|
bar_val = pci_bar_dic[bdf][bar_i].addr
|
|
|
|
if pci_bar_dic[bdf][bar_i].remapped:
|
|
|
|
ptdev_mmio_str = 'PTDEV_HI_MMIO_START + '
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
if bar_num == bar_len:
|
2020-03-06 11:04:46 +08:00
|
|
|
print("{}.vbar_base[{}] = {}{}UL".format(align, bar_i, ptdev_mmio_str, bar_val), file=config)
|
2019-07-30 09:20:40 +08:00
|
|
|
else:
|
2020-03-06 11:04:46 +08:00
|
|
|
print("{}.vbar_base[{}] = {}{}UL, \\".format(
|
|
|
|
align, bar_i, ptdev_mmio_str, bar_val), file=config)
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
else:
|
|
|
|
print("", file=config)
|
|
|
|
|
|
|
|
|
|
|
|
def generate_file(config):
|
2019-09-05 13:31:11 +08:00
|
|
|
"""
|
|
|
|
Get PCI device and generate pci_devices.h
|
2019-08-02 19:17:58 +08:00
|
|
|
:param config: it is a file pointer of pci information for writing to
|
|
|
|
"""
|
2019-07-30 09:20:40 +08:00
|
|
|
# write the license into pci
|
|
|
|
print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
|
|
|
|
|
|
|
|
# add bios and base board info
|
|
|
|
board_cfg_lib.handle_bios_info(config)
|
|
|
|
|
|
|
|
# write the header into pci
|
|
|
|
print("{0}".format(PCI_HEADER), file=config)
|
|
|
|
|
2020-04-20 05:56:10 +08:00
|
|
|
sub_name_count = board_cfg_lib.parser_pci()
|
2019-07-30 09:20:40 +08:00
|
|
|
|
2020-04-20 05:56:10 +08:00
|
|
|
print("#define %-32s" % "PTDEV_HI_MMIO_SIZE", " {}UL".format(hex(board_cfg_lib.HI_MMIO_OFFSET)), file=config)
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
compared_bdf = []
|
|
|
|
for cnt_sub_name in sub_name_count.keys():
|
|
|
|
i_cnt = 0
|
2020-04-20 05:56:10 +08:00
|
|
|
for bdf, bar_attr in board_cfg_lib.PCI_DEV_BAR_DESC.pci_dev_dic.items():
|
2020-03-06 11:04:46 +08:00
|
|
|
if cnt_sub_name == bar_attr.name and bdf not in compared_bdf:
|
2019-07-30 09:20:40 +08:00
|
|
|
compared_bdf.append(bdf)
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
|
2020-03-06 11:04:46 +08:00
|
|
|
print("",file=config)
|
|
|
|
write_pbdf(i_cnt, bdf, bar_attr, config)
|
2020-04-20 05:56:10 +08:00
|
|
|
write_vbar(i_cnt, bdf, board_cfg_lib.PCI_DEV_BAR_DESC.pci_bar_dic, bar_attr, config)
|
2019-07-30 09:20:40 +08:00
|
|
|
|
|
|
|
i_cnt += 1
|
|
|
|
|
|
|
|
# write the end to the pci devices
|
|
|
|
print("{0}".format(PCI_END_HEADER), file=config)
|