config/arm: split -march into arch and features
[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/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 armv8 flags have middle priority
28 #     (will overwrite common flags)
29 # part number specific armv8 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': {
41             'march': 'armv8-a',
42             'march_features': ['crc'],
43             'compiler_options': ['-moutline-atomics']
44         },
45         'generic_aarch32': {
46             'machine_args': ['-march=armv8-a', '-mfpu=neon'],
47             'flags': [
48                 ['RTE_ARCH_ARM_NEON_MEMCPY', false],
49                 ['RTE_ARCH_STRICT_ALIGN', true],
50                 ['RTE_ARCH_ARMv8_AARCH32', true],
51                 ['RTE_CACHE_LINE_SIZE', 64]
52             ]
53         }
54     }
55 }
56
57 part_number_config_arm = {
58     '0xd03': {'compiler_options':  ['-mcpu=cortex-a53']},
59     '0xd04': {'compiler_options':  ['-mcpu=cortex-a35']},
60     '0xd07': {'compiler_options':  ['-mcpu=cortex-a57']},
61     '0xd08': {'compiler_options':  ['-mcpu=cortex-a72']},
62     '0xd09': {'compiler_options':  ['-mcpu=cortex-a73']},
63     '0xd0a': {'compiler_options':  ['-mcpu=cortex-a75']},
64     '0xd0b': {'compiler_options':  ['-mcpu=cortex-a76']},
65     '0xd0c': {
66         'march': 'armv8.2-a',
67         'march_features': ['crypto'],
68         'compiler_options':  ['-mcpu=neoverse-n1'],
69         'flags': [
70             ['RTE_MACHINE', '"neoverse-n1"'],
71             ['RTE_ARM_FEATURE_ATOMICS', true],
72             ['RTE_MAX_MEM_MB', 1048576],
73             ['RTE_MAX_LCORE', 160],
74             ['RTE_MAX_NUMA_NODES', 2]
75         ]
76     },
77     '0xd49': {
78         'march': 'armv8.5-a',
79         'march_features': ['crypto', 'sve2'],
80         'flags': [
81             ['RTE_MACHINE', '"neoverse-n2"'],
82             ['RTE_ARM_FEATURE_ATOMICS', true],
83             ['RTE_MAX_LCORE', 64],
84             ['RTE_MAX_NUMA_NODES', 1]
85         ]
86     }
87 }
88 implementer_arm = {
89     'description': 'Arm',
90     'flags': [
91         ['RTE_MACHINE', '"armv8a"'],
92         ['RTE_USE_C11_MEM_MODEL', true],
93         ['RTE_CACHE_LINE_SIZE', 64],
94         ['RTE_MAX_LCORE', 64],
95         ['RTE_MAX_NUMA_NODES', 4]
96     ],
97     'part_number_config': part_number_config_arm
98 }
99
100 flags_part_number_thunderx = [
101     ['RTE_MACHINE', '"thunderx"'],
102     ['RTE_USE_C11_MEM_MODEL', false]
103 ]
104 implementer_cavium = {
105     'description': 'Cavium',
106     'flags': [
107         ['RTE_MAX_VFIO_GROUPS', 128],
108         ['RTE_MAX_LCORE', 96],
109         ['RTE_MAX_NUMA_NODES', 2]
110     ],
111     'part_number_config': {
112         '0xa1': {
113             'compiler_options': ['-mcpu=thunderxt88'],
114             'flags': flags_part_number_thunderx
115         },
116         '0xa2': {
117             'compiler_options': ['-mcpu=thunderxt81'],
118             'flags': flags_part_number_thunderx
119         },
120         '0xa3': {
121             'compiler_options': ['-mcpu=thunderxt83'],
122             'flags': flags_part_number_thunderx
123         },
124         '0xaf': {
125             'march': 'armv8.1-a',
126             'march_features': ['crc', 'crypto'],
127             'compiler_options': ['-mcpu=thunderx2t99'],
128             'flags': [
129                 ['RTE_MACHINE', '"thunderx2"'],
130                 ['RTE_ARM_FEATURE_ATOMICS', true],
131                 ['RTE_USE_C11_MEM_MODEL', true],
132                 ['RTE_CACHE_LINE_SIZE', 64],
133                 ['RTE_MAX_LCORE', 256]
134             ]
135         },
136         '0xb2': {
137             'march': 'armv8.2-a',
138             'march_features': ['crc', 'crypto', 'lse'],
139             'compiler_options': ['-mcpu=octeontx2'],
140             'flags': [
141                 ['RTE_MACHINE', '"octeontx2"'],
142                 ['RTE_ARM_FEATURE_ATOMICS', true],
143                 ['RTE_USE_C11_MEM_MODEL', true],
144                 ['RTE_MAX_LCORE', 36],
145                 ['RTE_MAX_NUMA_NODES', 1]
146             ]
147         }
148     }
149 }
150
151 implementer_ampere = {
152     'description': 'Ampere Computing',
153     'flags': [
154         ['RTE_MACHINE', '"emag"'],
155         ['RTE_CACHE_LINE_SIZE', 64],
156         ['RTE_MAX_LCORE', 32],
157         ['RTE_MAX_NUMA_NODES', 1]
158     ],
159     'part_number_config': {
160         '0x0': {
161             'march': 'armv8-a',
162             'march_features': ['crc', 'crypto'],
163             'compiler_options':  ['-mtune=emag']
164         }
165     }
166 }
167
168 implementer_hisilicon = {
169     'description': 'HiSilicon',
170     'flags': [
171         ['RTE_USE_C11_MEM_MODEL', true],
172         ['RTE_CACHE_LINE_SIZE', 128]
173     ],
174     'part_number_config': {
175         '0xd01': {
176             'march': 'armv8.2-a',
177             'march_features': ['crypto'],
178             'compiler_options': ['-mtune=tsv110'],
179             'flags': [
180                 ['RTE_MACHINE', '"Kunpeng 920"'],
181                 ['RTE_ARM_FEATURE_ATOMICS', true],
182                 ['RTE_MAX_LCORE', 256],
183                 ['RTE_MAX_NUMA_NODES', 8]
184             ]
185         },
186         '0xd02': {
187             'march': 'armv8.2-a',
188             'march_features': ['crypto', 'sve'],
189             'flags': [
190                 ['RTE_MACHINE', '"Kunpeng 930"'],
191                 ['RTE_ARM_FEATURE_ATOMICS', true],
192                 ['RTE_MAX_LCORE', 1280],
193                 ['RTE_MAX_NUMA_NODES', 16]
194             ]
195         }
196     }
197 }
198
199 implementer_qualcomm = {
200     'description': 'Qualcomm',
201     'flags': [
202         ['RTE_MACHINE', '"armv8a"'],
203         ['RTE_USE_C11_MEM_MODEL', true],
204         ['RTE_CACHE_LINE_SIZE', 64],
205         ['RTE_MAX_LCORE', 64],
206         ['RTE_MAX_NUMA_NODES', 1]
207     ],
208     'part_number_config': {
209         '0x800': {
210             'march': 'armv8-a',
211             'march_features': ['crc']
212         },
213         '0xc00': {
214             'march': 'armv8-a',
215             'march_features': ['crc']
216         }
217     }
218 }
219
220 ## Arm implementers (ID from MIDR in Arm Architecture Reference Manual)
221 implementers = {
222     'generic': implementer_generic,
223     '0x41': implementer_arm,
224     '0x43': implementer_cavium,
225     '0x48': implementer_hisilicon,
226     '0x50': implementer_ampere,
227     '0x51': implementer_qualcomm
228 }
229
230 # SoC specific armv8 flags have the highest priority
231 #     (will overwrite all other flags)
232 soc_generic = {
233     'description': 'Generic un-optimized build for armv8 aarch64 exec mode',
234     'implementer': 'generic',
235     'part_number': 'generic'
236 }
237
238 soc_generic_aarch32 = {
239     'description': 'Generic un-optimized build for armv8 aarch32 exec mode',
240     'implementer': 'generic',
241     'part_number': 'generic_aarch32'
242 }
243
244 soc_armada = {
245     'description': 'Marvell ARMADA',
246     'implementer': '0x41',
247     'part_number': '0xd08',
248     'flags': [
249         ['RTE_MAX_LCORE', 16],
250         ['RTE_MAX_NUMA_NODES', 1]
251     ],
252     'numa': false
253 }
254
255 soc_bluefield = {
256     'description': 'NVIDIA BlueField',
257     'implementer': '0x41',
258     'part_number': '0xd08',
259     'flags': [
260         ['RTE_MAX_LCORE', 16],
261         ['RTE_MAX_NUMA_NODES', 1]
262     ],
263     'numa': false
264 }
265
266 soc_centriq2400 = {
267     'description': 'Qualcomm Centriq 2400',
268     'implementer': '0x51',
269     'part_number': '0xc00',
270     'numa': false
271 }
272
273 soc_cn10k = {
274     'description' : 'Marvell OCTEON 10',
275     'implementer' : '0x41',
276     'flags': [
277         ['RTE_MAX_LCORE', 24],
278         ['RTE_MAX_NUMA_NODES', 1]
279     ],
280     'part_number': '0xd49',
281     'numa': false
282 }
283
284 soc_dpaa = {
285     'description': 'NXP DPAA',
286     'implementer': '0x41',
287     'part_number': '0xd08',
288     'flags': [
289         ['RTE_MACHINE', '"dpaa"'],
290         ['RTE_LIBRTE_DPAA2_USE_PHYS_IOVA', false],
291         ['RTE_MAX_LCORE', 16],
292         ['RTE_MAX_NUMA_NODES', 1]
293     ],
294     'numa': false
295 }
296
297 soc_emag = {
298     'description': 'Ampere eMAG',
299     'implementer': '0x50',
300     'part_number': '0x0'
301 }
302
303 soc_graviton2 = {
304     'description': 'AWS Graviton2',
305     'implementer': '0x41',
306     'part_number': '0xd0c',
307     'numa': false
308 }
309
310 soc_kunpeng920 = {
311     'description': 'HiSilicon Kunpeng 920',
312     'implementer': '0x48',
313     'part_number': '0xd01',
314     'numa': true
315 }
316
317 soc_kunpeng930 = {
318     'description': 'HiSilicon Kunpeng 930',
319     'implementer': '0x48',
320     'part_number': '0xd02',
321     'numa': true
322 }
323
324 soc_n1sdp = {
325     'description': 'Arm Neoverse N1SDP',
326     'implementer': '0x41',
327     'part_number': '0xd0c',
328     'flags': [
329         ['RTE_MAX_LCORE', 4]
330     ],
331     'numa': false
332 }
333
334 soc_n2 = {
335     'description': 'Arm Neoverse N2',
336     'implementer': '0x41',
337     'part_number': '0xd49',
338     'numa': false
339 }
340
341 soc_octeontx2 = {
342     'description': 'Marvell OCTEON TX2',
343     'implementer': '0x43',
344     'part_number': '0xb2',
345     'numa': false
346 }
347
348 soc_stingray = {
349     'description': 'Broadcom Stingray',
350     'implementer': '0x41',
351     'flags': [
352         ['RTE_MAX_LCORE', 16],
353         ['RTE_MAX_NUMA_NODES', 1]
354     ],
355     'part_number': '0xd08',
356     'numa': false
357 }
358
359 soc_thunderx2 = {
360     'description': 'Marvell ThunderX2 T99',
361     'implementer': '0x43',
362     'part_number': '0xaf'
363 }
364
365 soc_thunderxt88 = {
366     'description': 'Marvell ThunderX T88',
367     'implementer': '0x43',
368     'part_number': '0xa1'
369 }
370
371 '''
372 Start of SoCs list
373 generic:         Generic un-optimized build for armv8 aarch64 execution mode.
374 generic_aarch32: Generic un-optimized build for armv8 aarch32 execution mode.
375 armada:          Marvell ARMADA
376 bluefield:       NVIDIA BlueField
377 centriq2400:     Qualcomm Centriq 2400
378 cn10k:           Marvell OCTEON 10
379 dpaa:            NXP DPAA
380 emag:            Ampere eMAG
381 graviton2:       AWS Graviton2
382 kunpeng920:      HiSilicon Kunpeng 920
383 kunpeng930:      HiSilicon Kunpeng 930
384 n1sdp:           Arm Neoverse N1SDP
385 n2:              Arm Neoverse N2
386 octeontx2:       Marvell OCTEON TX2
387 stingray:        Broadcom Stingray
388 thunderx2:       Marvell ThunderX2 T99
389 thunderxt88:     Marvell ThunderX T88
390 End of SoCs list
391 '''
392 # The string above is included in the documentation, keep it in sync with the
393 # SoCs list below.
394 socs = {
395     'generic': soc_generic,
396     'generic_aarch32': soc_generic_aarch32,
397     'armada': soc_armada,
398     'bluefield': soc_bluefield,
399     'centriq2400': soc_centriq2400,
400     'cn10k' : soc_cn10k,
401     'dpaa': soc_dpaa,
402     'emag': soc_emag,
403     'graviton2': soc_graviton2,
404     'kunpeng920': soc_kunpeng920,
405     'kunpeng930': soc_kunpeng930,
406     'n1sdp': soc_n1sdp,
407     'n2': soc_n2,
408     'octeontx2': soc_octeontx2,
409     'stingray': soc_stingray,
410     'thunderx2': soc_thunderx2,
411     'thunderxt88': soc_thunderxt88
412 }
413
414 dpdk_conf.set('RTE_ARCH_ARM', 1)
415 dpdk_conf.set('RTE_FORCE_INTRINSICS', 1)
416
417 update_flags = false
418 soc_flags = []
419 if dpdk_conf.get('RTE_ARCH_32')
420     # 32-bit build
421     dpdk_conf.set('RTE_CACHE_LINE_SIZE', 64)
422     if meson.is_cross_build()
423         update_flags = true
424         soc = meson.get_cross_property('platform', '')
425         if soc == ''
426             error('Arm SoC must be specified in the cross file.')
427         endif
428         soc_config = socs.get(soc, {'not_supported': true})
429         flags_common = []
430     else
431         # armv7 build
432         dpdk_conf.set('RTE_ARCH_ARMv7', true)
433         # the minimum architecture supported, armv7-a, needs the following,
434         machine_args += '-mfpu=neon'
435     endif
436 else
437     # armv8 build
438     update_flags = true
439     soc_config = {}
440     if not meson.is_cross_build()
441         # for backwards compatibility:
442         #   machine=native is the same behavior as soc=native
443         #   machine=generic/default is the same as soc=generic
444         # cpu_instruction_set holds the proper value - native, generic or cpu
445         # the old behavior only distinguished between generic and native build
446         if machine != 'auto'
447             if cpu_instruction_set == 'generic'
448                 soc = 'generic'
449             else
450                 soc = 'native'
451             endif
452         else
453             soc = platform
454         endif
455         if soc == 'native'
456             # native build
457             # The script returns ['Implementer', 'Variant', 'Architecture',
458             # 'Primary Part number', 'Revision']
459             detect_vendor = find_program(join_paths(meson.current_source_dir(),
460                                                     'armv8_machine.py'))
461             cmd = run_command(detect_vendor.path())
462             if cmd.returncode() == 0
463                 cmd_output = cmd.stdout().to_lower().strip().split(' ')
464                 implementer_id = cmd_output[0]
465                 part_number = cmd_output[3]
466             else
467                 error('Error when getting Arm Implementer ID and part number.')
468             endif
469         else
470             # SoC build
471             soc_config = socs.get(soc, {'not_supported': true})
472         endif
473     else
474         # cross build
475         soc = meson.get_cross_property('platform', '')
476         if soc == ''
477             error('Arm SoC must be specified in the cross file.')
478         endif
479         soc_config = socs.get(soc, {'not_supported': true})
480     endif
481 endif
482
483 if update_flags
484     if soc_config.has_key('not_supported')
485         error('SoC @0@ not supported.'.format(soc))
486     elif soc_config != {}
487         implementer_id = soc_config['implementer']
488         implementer_config = implementers[implementer_id]
489         part_number = soc_config['part_number']
490         soc_flags = soc_config.get('flags', [])
491         if not soc_config.get('numa', true)
492             has_libnuma = 0
493         endif
494
495         disable_drivers += ',' + soc_config.get('disable_drivers', '')
496         enable_drivers += ',' + soc_config.get('enable_drivers', '')
497     endif
498
499     if implementers.has_key(implementer_id)
500         implementer_config = implementers[implementer_id]
501     else
502         error('Unsupported Arm implementer: @0@. '.format(implementer_id) +
503               'Please add support for it or use the generic ' +
504               '(-Dplatform=generic) build.')
505     endif
506
507     message('Arm implementer: ' + implementer_config['description'])
508     message('Arm part number: ' + part_number)
509
510     part_number_config = implementer_config['part_number_config']
511     if part_number_config.has_key(part_number)
512         # use the specified part_number machine args if found
513         part_number_config = part_number_config[part_number]
514     else
515         # unknown part number
516         error('Unsupported part number @0@ of implementer @1@. '
517               .format(part_number, implementer_id) +
518               'Please add support for it or use the generic ' +
519               '(-Dplatform=generic) build.')
520     endif
521
522     # add/overwrite flags in the proper order
523     dpdk_flags = flags_common + implementer_config['flags'] + part_number_config.get('flags', []) + soc_flags
524
525     machine_args = [] # Clear previous machine args
526
527     # probe supported archs and their features
528     candidate_march = ''
529     if part_number_config.has_key('march')
530         supported_marchs = ['armv8.6-a', 'armv8.5-a', 'armv8.4-a', 'armv8.3-a',
531                             'armv8.2-a', 'armv8.1-a', 'armv8-a']
532         check_compiler_support = false
533         foreach supported_march: supported_marchs
534             if supported_march == part_number_config['march']
535                 # start checking from this version downwards
536                 check_compiler_support = true
537             endif
538             if (check_compiler_support and
539                 cc.has_argument('-march=' + supported_march))
540                 candidate_march = supported_march
541                 # highest supported march version found
542                 break
543             endif
544         endforeach
545         if candidate_march == ''
546             error('No suitable armv8 march version found.')
547         endif
548         if candidate_march != part_number_config['march']
549             warning('Configuration march version is ' +
550                     '@0@, but the compiler supports only @1@.'
551                     .format(part_number_config['march'], candidate_march))
552         endif
553         candidate_march = '-march=' + candidate_march
554
555         march_features = []
556         if part_number_config.has_key('march_features')
557             march_features += part_number_config['march_features']
558         endif
559         if soc_config.has_key('extra_march_features')
560             march_features += soc_config['extra_march_features']
561         endif
562         foreach feature: march_features
563             if cc.has_argument('+'.join([candidate_march, feature]))
564                 candidate_march = '+'.join([candidate_march, feature])
565             else
566                 warning('The compiler does not support feature @0@'
567                     .format(feature))
568             endif
569         endforeach
570         machine_args += candidate_march
571     endif
572
573     # apply supported compiler options
574     if part_number_config.has_key('compiler_options')
575         foreach flag: part_number_config['compiler_options']
576             if cc.has_argument(flag)
577                 machine_args += flag
578             else
579                 warning('Configuration compiler option ' +
580                         '@0@ isn\'t supported.'.format(flag))
581             endif
582         endforeach
583     endif
584
585     # apply flags
586     foreach flag: dpdk_flags
587         if flag.length() > 0
588             dpdk_conf.set(flag[0], flag[1])
589         endif
590     endforeach
591 endif
592 message('Using machine args: @0@'.format(machine_args))
593
594 if (cc.get_define('__ARM_NEON', args: machine_args) != '' or
595     cc.get_define('__aarch64__', args: machine_args) != '')
596     compile_time_cpuflags += ['RTE_CPUFLAG_NEON']
597 endif
598
599 if cc.get_define('__ARM_FEATURE_SVE', args: machine_args) != ''
600     compile_time_cpuflags += ['RTE_CPUFLAG_SVE']
601     if (cc.check_header('arm_sve.h'))
602         dpdk_conf.set('RTE_HAS_SVE_ACLE', 1)
603     endif
604 endif
605
606 if cc.get_define('__ARM_FEATURE_CRC32', args: machine_args) != ''
607     compile_time_cpuflags += ['RTE_CPUFLAG_CRC32']
608 endif
609
610 if cc.get_define('__ARM_FEATURE_CRYPTO', args: machine_args) != ''
611     compile_time_cpuflags += ['RTE_CPUFLAG_AES', 'RTE_CPUFLAG_PMULL',
612     'RTE_CPUFLAG_SHA1', 'RTE_CPUFLAG_SHA2']
613 endif