config/arm: add platform config option
[dpdk.git] / config / arm / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2017 Intel Corporation.
3 # Copyright(c) 2017 Cavium, Inc
4 # Copyright(c) 2021 PANTHEON.tech s.r.o.
5
6 # common flags to all aarch64 builds, with lowest priority
7 flags_common = [
8         # Accelerate rte_memcpy. Be sure to run unit test (memcpy_perf_autotest)
9         # to determine the best threshold in code. Refer to notes in source file
10         # (lib/librte_eal/arm/include/rte_memcpy_64.h) for more info.
11         ['RTE_ARCH_ARM64_MEMCPY', false],
12         #       ['RTE_ARM64_MEMCPY_ALIGNED_THRESHOLD', 2048],
13         #       ['RTE_ARM64_MEMCPY_UNALIGNED_THRESHOLD', 512],
14         # Leave below RTE_ARM64_MEMCPY_xxx options commented out,
15         # unless there are strong reasons.
16         #       ['RTE_ARM64_MEMCPY_SKIP_GCC_VER_CHECK', false],
17         #       ['RTE_ARM64_MEMCPY_ALIGN_MASK', 0xF],
18         #       ['RTE_ARM64_MEMCPY_STRICT_ALIGN', false],
19
20         ['RTE_SCHED_VECTOR', false],
21         ['RTE_ARM_USE_WFE', false],
22         ['RTE_ARCH_ARM64', true],
23         ['RTE_CACHE_LINE_SIZE', 128]
24 ]
25
26 ## Part numbers are specific to Arm implementers
27 # implementer specific aarch64 flags have middle priority
28 #     (will overwrite common flags)
29 # part number specific aarch64 flags have higher priority
30 #     (will overwrite both common and implementer specific flags)
31 implementer_generic = {
32         'description': 'Generic armv8',
33         'flags': [
34                 ['RTE_MACHINE', '"armv8a"'],
35                 ['RTE_USE_C11_MEM_MODEL', true],
36                 ['RTE_MAX_LCORE', 256],
37                 ['RTE_MAX_NUMA_NODES', 4]
38         ],
39         'part_number_config': {
40                 'generic': {'machine_args': ['-march=armv8-a+crc',
41                                              '-moutline-atomics']}
42         }
43 }
44
45 part_number_config_arm = {
46         '0xd03': {'machine_args':  ['-mcpu=cortex-a53']},
47         '0xd04': {'machine_args':  ['-mcpu=cortex-a35']},
48         '0xd07': {'machine_args':  ['-mcpu=cortex-a57']},
49         '0xd08': {'machine_args':  ['-mcpu=cortex-a72']},
50         '0xd09': {'machine_args':  ['-mcpu=cortex-a73']},
51         '0xd0a': {'machine_args':  ['-mcpu=cortex-a75']},
52         '0xd0b': {'machine_args':  ['-mcpu=cortex-a76']},
53         '0xd0c': {
54                 'machine_args':  ['-march=armv8.2-a+crypto',
55                                   '-mcpu=neoverse-n1'],
56                 'flags': [
57                         ['RTE_MACHINE', '"neoverse-n1"'],
58                         ['RTE_ARM_FEATURE_ATOMICS', true],
59                         ['RTE_MAX_MEM_MB', 1048576],
60                         ['RTE_MAX_LCORE', 80]
61                 ]
62         },
63         '0xd49': {
64                 'machine_args':  ['-march=armv8.5-a+crypto+sve2'],
65                 'flags': [
66                         ['RTE_MACHINE', '"neoverse-n2"'],
67                         ['RTE_ARM_FEATURE_ATOMICS', true],
68                         ['RTE_MAX_LCORE', 64]
69                 ]
70         }
71 }
72 implementer_arm = {
73         'description': 'Arm',
74         'flags': [
75                 ['RTE_MACHINE', '"armv8a"'],
76                 ['RTE_USE_C11_MEM_MODEL', true],
77                 ['RTE_CACHE_LINE_SIZE', 64],
78                 ['RTE_MAX_LCORE', 16],
79                 ['RTE_MAX_NUMA_NODES', 1]
80         ],
81         'part_number_config': part_number_config_arm
82 }
83
84 flags_part_number_thunderx = [
85         ['RTE_MACHINE', '"thunderx"'],
86         ['RTE_USE_C11_MEM_MODEL', false]
87 ]
88 implementer_cavium = {
89         'description': 'Cavium',
90         'flags': [
91                 ['RTE_MAX_VFIO_GROUPS', 128],
92                 ['RTE_MAX_LCORE', 96],
93                 ['RTE_MAX_NUMA_NODES', 2]
94         ],
95         'part_number_config': {
96                 '0xa1': {
97                         'machine_args': ['-mcpu=thunderxt88'],
98                         'flags': flags_part_number_thunderx
99                 },
100                 '0xa2': {
101                         'machine_args': ['-mcpu=thunderxt81'],
102                         'flags': flags_part_number_thunderx
103                 },
104                 '0xa3': {
105                         'machine_args': ['-mcpu=thunderxt83'],
106                         'flags': flags_part_number_thunderx
107                 },
108                 '0xaf': {
109                         'machine_args': ['-march=armv8.1-a+crc+crypto',
110                                          '-mcpu=thunderx2t99'],
111                         'flags': [
112                                 ['RTE_MACHINE', '"thunderx2"'],
113                                 ['RTE_ARM_FEATURE_ATOMICS', true],
114                                 ['RTE_USE_C11_MEM_MODEL', true],
115                                 ['RTE_CACHE_LINE_SIZE', 64],
116                                 ['RTE_MAX_LCORE', 256]
117                         ]
118                 },
119                 '0xb2': {
120                         'machine_args': ['-march=armv8.2-a+crc+crypto+lse',
121                                          '-mcpu=octeontx2'],
122                         'flags': [
123                                 ['RTE_MACHINE', '"octeontx2"'],
124                                 ['RTE_ARM_FEATURE_ATOMICS', true],
125                                 ['RTE_USE_C11_MEM_MODEL', true],
126                                 ['RTE_MAX_LCORE', 36],
127                                 ['RTE_MAX_NUMA_NODES', 1]
128                         ]
129                 }
130         }
131 }
132
133 implementer_ampere = {
134         'description': 'Ampere Computing',
135         'flags': [
136                 ['RTE_MACHINE', '"emag"'],
137                 ['RTE_CACHE_LINE_SIZE', 64],
138                 ['RTE_MAX_LCORE', 32],
139                 ['RTE_MAX_NUMA_NODES', 1]
140         ],
141         'part_number_config': {
142                 '0x0': {'machine_args':  ['-march=armv8-a+crc+crypto',
143                                           '-mtune=emag']}
144         }
145 }
146
147 implementer_qualcomm = {
148         'description': 'Qualcomm',
149         'flags': [
150                 ['RTE_MACHINE', '"armv8a"'],
151                 ['RTE_USE_C11_MEM_MODEL', true],
152                 ['RTE_CACHE_LINE_SIZE', 64],
153                 ['RTE_MAX_LCORE', 64],
154                 ['RTE_MAX_NUMA_NODES', 1]
155         ],
156         'part_number_config': {
157                 '0xc00': {'machine_args':  ['-march=armv8-a+crc']}
158         }
159 }
160
161 implementer_marvell = {
162         'description': 'Marvell ARMADA',
163         'flags': [
164                 ['RTE_MACHINE', '"armv8a"'],
165                 ['RTE_CACHE_LINE_SIZE', 64],
166                 ['RTE_MAX_LCORE', 16],
167                 ['RTE_MAX_NUMA_NODES', 1]
168         ],
169         'part_number_config': part_number_config_arm
170 }
171
172 implementer_dpaa = {
173         'description': 'NXP DPAA',
174         'flags': [
175                 ['RTE_MACHINE', '"dpaa"'],
176                 ['RTE_LIBRTE_DPAA2_USE_PHYS_IOVA', false],
177                 ['RTE_USE_C11_MEM_MODEL', true],
178                 ['RTE_CACHE_LINE_SIZE', 64],
179                 ['RTE_MAX_LCORE', 16],
180                 ['RTE_MAX_NUMA_NODES', 1]
181         ],
182         'part_number_config': part_number_config_arm
183 }
184
185 ## Arm implementers (ID from MIDR in Arm Architecture Reference Manual)
186 implementers = {
187         'generic': implementer_generic,
188         '0x41': implementer_arm,
189         '0x43': implementer_cavium,
190         '0x50': implementer_ampere,
191         '0x51': implementer_qualcomm,
192         '0x56': implementer_marvell,
193         'dpaa': implementer_dpaa
194 }
195
196 # SoC specific aarch64 flags have the highest priority
197 #     (will overwrite all other flags)
198 soc_generic = {
199         'description': 'Generic un-optimized build for all aarch64 machines',
200         'implementer': 'generic',
201         'part_number': 'generic'
202 }
203
204 soc_armada = {
205         'description': 'Marvell ARMADA',
206         'implementer': '0x56',
207         'part_number': '0xd08',
208         'numa': false
209 }
210
211 soc_bluefield = {
212         'description': 'NVIDIA BlueField',
213         'implementer': '0x41',
214         'part_number': '0xd08',
215         'numa': false
216 }
217
218 soc_dpaa = {
219         'description': 'NXP DPAA',
220         'implementer': 'dpaa',
221         'part_number': '0xd08',
222         'numa': false
223 }
224
225 soc_emag = {
226         'description': 'Ampere eMAG',
227         'implementer': '0x50',
228         'part_number': '0x0'
229 }
230
231 soc_graviton2 = {
232         'description': 'AWS Graviton2',
233         'implementer': '0x41',
234         'part_number': '0xd0c',
235         'numa': false
236 }
237
238 soc_n1sdp = {
239         'description': 'Arm Neoverse N1SDP',
240         'implementer': '0x41',
241         'part_number': '0xd0c',
242         'flags': [
243                 ['RTE_MAX_LCORE', 4]
244         ],
245         'numa': false
246 }
247
248 soc_n2 = {
249         'description': 'Arm Neoverse N2',
250         'implementer': '0x41',
251         'part_number': '0xd49',
252         'numa': false
253 }
254
255 soc_octeontx2 = {
256         'description': 'Marvell OCTEON TX2',
257         'implementer': '0x43',
258         'part_number': '0xb2',
259         'numa': false
260 }
261
262 soc_stingray = {
263         'description': 'Broadcom Stingray',
264         'implementer': '0x41',
265         'part_number': '0xd08',
266         'numa': false
267 }
268
269 soc_thunderx2 = {
270         'description': 'Marvell ThunderX2 T99',
271         'implementer': '0x43',
272         'part_number': '0xaf'
273 }
274
275 soc_thunderxt88 = {
276         'description': 'Marvell ThunderX T88',
277         'implementer': '0x43',
278         'part_number': '0xa1'
279 }
280
281 socs = {
282         'generic': soc_generic,
283         'armada': soc_armada,
284         'bluefield': soc_bluefield,
285         'dpaa': soc_dpaa,
286         'emag': soc_emag,
287         'graviton2': soc_graviton2,
288         'n1sdp': soc_n1sdp,
289         'n2': soc_n2,
290         'octeontx2': soc_octeontx2,
291         'stingray': soc_stingray,
292         'thunderx2': soc_thunderx2,
293         'thunderxt88': soc_thunderxt88
294 }
295
296 dpdk_conf.set('RTE_ARCH_ARM', 1)
297 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
298
299 if dpdk_conf.get('RTE_ARCH_32')
300         # armv7 build
301         dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
302         dpdk_conf.set('RTE_ARCH_ARMv7', 1)
303         # the minimum architecture supported, armv7-a, needs the following,
304         machine_args += '-mfpu=neon'
305 else
306         # aarch64 build
307         soc = get_option('platform')
308         soc_config = {}
309         if not meson.is_cross_build()
310                 if machine == 'generic'
311                         # generic build
312                         if soc != ''
313                                 error('Building for a particular platform is ' +
314                                       'unsupported with generic build.')
315                         endif
316                         implementer_id = 'generic'
317                         part_number = 'generic'
318                 elif soc != ''
319                         soc_config = socs.get(soc, {'not_supported': true})
320                 else
321                         # native build
322                         # The script returns ['Implementer', 'Variant', 'Architecture',
323                         # 'Primary Part number', 'Revision']
324                         detect_vendor = find_program(join_paths(
325                                         meson.current_source_dir(), 'armv8_machine.py'))
326                         cmd = run_command(detect_vendor.path())
327                         if cmd.returncode() == 0
328                                 cmd_output = cmd.stdout().to_lower().strip().split(' ')
329                                 implementer_id = cmd_output[0]
330                                 part_number = cmd_output[3]
331                         else
332                                 error('Error when getting Arm Implementer ID and part number.')
333                         endif
334                 endif
335         else
336                 # cross build
337                 soc = meson.get_cross_property('platform', '')
338                 if soc == ''
339                         error('Arm SoC must be specified in the cross file.')
340                 endif
341                 soc_config = socs.get(soc, {'not_supported': true})
342         endif
343
344         soc_flags = []
345         if soc_config.has_key('not_supported')
346                 error('SoC @0@ not supported.'.format(soc))
347         elif soc_config != {}
348                 implementer_id = soc_config['implementer']
349                 implementer_config = implementers[implementer_id]
350                 part_number = soc_config['part_number']
351                 soc_flags = soc_config.get('flags', [])
352                 if not soc_config.get('numa', true)
353                         has_libnuma = 0
354                 endif
355
356                 disable_drivers += ',' + soc_config.get('disable_drivers', '')
357                 enable_drivers += ',' + soc_config.get('enable_drivers', '')
358         endif
359
360         if implementers.has_key(implementer_id)
361                 implementer_config = implementers[implementer_id]
362         else
363                 error('Unsupported Arm implementer: @0@. '.format(implementer_id) +
364                       'Please add support for it or use the generic ' +
365                       '(-Dmachine=generic) build.')
366         endif
367
368         message('Arm implementer: ' + implementer_config['description'])
369         message('Arm part number: ' + part_number)
370
371         part_number_config = implementer_config['part_number_config']
372         if part_number_config.has_key(part_number)
373                 # use the specified part_number machine args if found
374                 part_number_config = part_number_config[part_number]
375         else
376                 # unknown part number
377                 error('Unsupported part number @0@ of implementer @1@. '
378                       .format(part_number, implementer_id) +
379                       'Please add support for it or use the generic ' +
380                       '(-Dmachine=generic) build.')
381         endif
382
383         # add/overwrite flags in the proper order
384         dpdk_flags = flags_common + implementer_config['flags'] + part_number_config.get('flags', []) + soc_flags
385
386         # apply supported machine args
387         machine_args = [] # Clear previous machine args
388         foreach flag: part_number_config['machine_args']
389                 if cc.has_argument(flag)
390                         machine_args += flag
391                 endif
392         endforeach
393
394         # apply flags
395         foreach flag: dpdk_flags
396                 if flag.length() > 0
397                         dpdk_conf.set(flag[0], flag[1])
398                 endif
399         endforeach
400 endif
401 message('Using machine args: @0@'.format(machine_args))
402
403 if (cc.get_define('__ARM_NEON', args: machine_args) != '' or
404     cc.get_define('__aarch64__', args: machine_args) != '')
405         compile_time_cpuflags += ['RTE_CPUFLAG_NEON']
406 endif
407
408 if cc.get_define('__ARM_FEATURE_CRC32', args: machine_args) != ''
409         compile_time_cpuflags += ['RTE_CPUFLAG_CRC32']
410 endif
411
412 if cc.get_define('__ARM_FEATURE_CRYPTO', args: machine_args) != ''
413         compile_time_cpuflags += ['RTE_CPUFLAG_AES', 'RTE_CPUFLAG_PMULL',
414         'RTE_CPUFLAG_SHA1', 'RTE_CPUFLAG_SHA2']
415 endif