14
14
PCI_END_HEADER = r"""
15
15
#endif /* PCI_DEVICES_H_ */"""
16
16
17
-
18
- HI_MMIO_OFFSET = 0
19
-
20
- class Bar_Mem :
21
- def __init__ (self ):
22
- self .addr = 0
23
- self .remapped = False
24
-
25
-
26
- class Bar_Attr :
27
- def __init__ (self ):
28
- self .name = 0
29
- self .remappable = True
30
-
31
-
32
- class Pci_Dev_Bar_Desc :
33
- def __init__ (self ):
34
- self .pci_dev_dic = {}
35
- self .pci_bar_dic = {}
36
-
37
- PCI_DEV_BAR_DESC = Pci_Dev_Bar_Desc ()
38
-
39
-
40
- def get_value_after_str (line , key ):
41
- """ Get the value after cstate string """
42
- idx = 0
43
- line_in_list = line .split ()
44
- for idx_key , val in enumerate (line_in_list ):
45
- if val == key :
46
- idx = idx_key
47
- break
48
-
49
- return line_in_list [idx + 1 ]
50
-
51
-
52
- def check_bar_remappable (line ):
53
- #TODO: check device BAR remappable per ACPI table
54
-
55
- return True
56
-
57
-
58
- def get_size (line ):
59
-
60
- # get size string from format, Region n: Memory at x ... [size=NK]
61
- size_str = line .split ()[- 1 ].strip (']' ).split ('=' )[1 ]
62
- if 'G' in size_str :
63
- size = int (size_str .strip ('G' )) * common .SIZE_G
64
- elif 'M' in size_str :
65
- size = int (size_str .strip ('M' )) * common .SIZE_M
66
- elif 'K' in size_str :
67
- size = int (size_str .strip ('K' )) * common .SIZE_K
68
- else :
69
- size = int (size_str )
70
-
71
- return size
72
-
73
- # round up the running bar_addr to the size of the incoming bar "line"
74
- def remap_bar_addr_to_high (bar_addr , line ):
75
- """Generate vbar address"""
76
- global HI_MMIO_OFFSET
77
- size = get_size (line )
78
- cur_addr = common .round_up (bar_addr , size )
79
- HI_MMIO_OFFSET = cur_addr + size
80
- return cur_addr
81
-
82
-
83
- def parser_pci ():
84
- """ Parse PCI lines """
85
- cur_bdf = 0
86
- prev_bdf = 0
87
- tmp_bar_dic = {}
88
- bar_addr = bar_num = '0'
89
- cal_sub_pci_name = []
90
-
91
- pci_lines = board_cfg_lib .get_info (
92
- common .BOARD_INFO_FILE , "<PCI_DEVICE>" , "</PCI_DEVICE>" )
93
-
94
- for line in pci_lines :
95
- tmp_bar_mem = Bar_Mem ()
96
- # get pci bar information into PCI_DEV_BAR_DESC
97
- if "Region" in line and "Memory at" in line :
98
- #ignore memory region from SR-IOV capabilities
99
- if "size=" not in line :
100
- continue
101
-
102
- bar_addr = int (get_value_after_str (line , "at" ), 16 )
103
- bar_num = line .split ()[1 ].strip (':' )
104
- if bar_addr >= common .SIZE_4G or bar_addr < common .SIZE_2G :
105
- if not tmp_bar_attr .remappable :
106
- continue
107
-
108
- bar_addr = remap_bar_addr_to_high (HI_MMIO_OFFSET , line )
109
- tmp_bar_mem .remapped = True
110
-
111
- tmp_bar_mem .addr = hex (bar_addr )
112
- tmp_bar_dic [int (bar_num )] = tmp_bar_mem
113
- else :
114
- tmp_bar_attr = Bar_Attr ()
115
- prev_bdf = cur_bdf
116
- pci_bdf = line .split ()[0 ]
117
- tmp_bar_attr .name = " " .join (line .split (':' )[1 ].split ()[1 :])
118
-
119
- # remove '[*]' in pci subname
120
- if '[' in tmp_bar_attr .name :
121
- tmp_bar_attr .name = tmp_bar_attr .name .rsplit ('[' , 1 )[0 ]
122
-
123
- cal_sub_pci_name .append (tmp_bar_attr .name )
124
- tmp_bar_attr .remappable = check_bar_remappable (line )
125
- PCI_DEV_BAR_DESC .pci_dev_dic [pci_bdf ] = tmp_bar_attr
126
- cur_bdf = pci_bdf
127
-
128
- if not prev_bdf :
129
- prev_bdf = cur_bdf
130
-
131
- if tmp_bar_dic and cur_bdf != prev_bdf :
132
- PCI_DEV_BAR_DESC .pci_bar_dic [prev_bdf ] = tmp_bar_dic
133
-
134
- # clear the tmp_bar_dic before store the next dic
135
- tmp_bar_dic = {}
136
-
137
- # output all the pci device list to pci_device.h
138
- sub_name_count = collections .Counter (cal_sub_pci_name )
139
-
140
- if tmp_bar_dic :
141
- PCI_DEV_BAR_DESC .pci_bar_dic [cur_bdf ] = tmp_bar_dic
142
-
143
- return sub_name_count
144
-
145
-
146
17
def write_pbdf (i_cnt , bdf , bar_attr , config ):
147
18
"""
148
19
Parser and generate pbdf
@@ -160,6 +31,8 @@ def write_pbdf(i_cnt, bdf, bar_attr, config):
160
31
else :
161
32
tmp_sub_name = "_" .join (bar_attr .name .split ()).upper () + "_" + str (i_cnt )
162
33
34
+ board_cfg_lib .PCI_DEV_BAR_DESC .pci_dev_dic [bdf ].name_w_i_cnt = tmp_sub_name
35
+
163
36
bus = int (bdf .split (':' )[0 ], 16 )
164
37
dev = int (bdf .split (':' )[1 ].split ('.' )[0 ], 16 )
165
38
fun = int (bdf .split ('.' )[1 ], 16 )
@@ -227,22 +100,22 @@ def generate_file(config):
227
100
# write the header into pci
228
101
print ("{0}" .format (PCI_HEADER ), file = config )
229
102
230
- sub_name_count = parser_pci ()
103
+ sub_name_count = board_cfg_lib . parser_pci ()
231
104
232
- print ("#define %-32s" % "PTDEV_HI_MMIO_SIZE" , " {}UL" .format (hex (HI_MMIO_OFFSET )), file = config )
105
+ print ("#define %-32s" % "PTDEV_HI_MMIO_SIZE" , " {}UL" .format (hex (board_cfg_lib . HI_MMIO_OFFSET )), file = config )
233
106
234
107
compared_bdf = []
235
108
for cnt_sub_name in sub_name_count .keys ():
236
109
i_cnt = 0
237
- for bdf , bar_attr in PCI_DEV_BAR_DESC .pci_dev_dic .items ():
110
+ for bdf , bar_attr in board_cfg_lib . PCI_DEV_BAR_DESC .pci_dev_dic .items ():
238
111
if cnt_sub_name == bar_attr .name and bdf not in compared_bdf :
239
112
compared_bdf .append (bdf )
240
113
else :
241
114
continue
242
115
243
116
print ("" ,file = config )
244
117
write_pbdf (i_cnt , bdf , bar_attr , config )
245
- write_vbar (i_cnt , bdf , PCI_DEV_BAR_DESC .pci_bar_dic , bar_attr , config )
118
+ write_vbar (i_cnt , bdf , board_cfg_lib . PCI_DEV_BAR_DESC .pci_bar_dic , bar_attr , config )
246
119
247
120
i_cnt += 1
248
121
0 commit comments