xref: /dpdk/lib/eal/ppc/rte_mmu.c (revision e168b18986a7ce39da3ba986d91c43cd5bbd6c1b)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) IBM Corporation 2024
3  */
4 
5 #include <stdio.h>
6 #include <string.h>
7 
8 #include "eal_private.h"
9 
10 bool
eal_mmu_supported(void)11 eal_mmu_supported(void)
12 {
13 #ifdef RTE_EXEC_ENV_LINUX
14 	static const char proc_cpuinfo[] = "/proc/cpuinfo";
15 	static const char str_mmu[] = "MMU";
16 	static const char str_radix[] = "Radix";
17 	char buf[512];
18 	char *ret = NULL;
19 	FILE *f = fopen(proc_cpuinfo, "r");
20 
21 	if (f == NULL) {
22 		EAL_LOG(ERR, "Cannot open %s", proc_cpuinfo);
23 		return false;
24 	}
25 
26 	/*
27 	 * Example "MMU" in /proc/cpuinfo:
28 	 * ...
29 	 * model	: 8335-GTW
30 	 * machine	: PowerNV 8335-GTW
31 	 * firmware	: OPAL
32 	 * MMU		: Radix
33 	 * ... or ...
34 	 * model        : IBM,9009-22A
35 	 * machine      : CHRP IBM,9009-22A
36 	 * MMU          : Hash
37 	 */
38 	while (fgets(buf, sizeof(buf), f) != NULL) {
39 		ret = strstr(buf, str_mmu);
40 		if (ret == NULL)
41 			continue;
42 		ret += sizeof(str_mmu) - 1;
43 		ret = strchr(ret, ':');
44 		if (ret == NULL)
45 			continue;
46 		ret = strstr(ret, str_radix);
47 		break;
48 	}
49 	fclose(f);
50 
51 	if (ret == NULL)
52 		EAL_LOG(ERR, "DPDK on PPC64 requires radix-mmu");
53 
54 	return (ret != NULL);
55 #elif RTE_EXEC_ENV_FREEBSD
56 	/*
57 	 * Method to detect MMU type in FreeBSD not known at the moment.
58 	 * Return true for now to emulate previous behavior and
59 	 * avoid unnecessary failures.
60 	 */
61 	return true;
62 #else
63 	/* Force false for other execution environments. */
64 	return false;
65 #endif
66 }
67