1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2022, Ovidiu Panait <ovpanait@gmail.com>
4  */
5 
6 #ifndef __ASM_MICROBLAZE_CPUINFO_H
7 #define __ASM_MICROBLAZE_CPUINFO_H
8 
9 #include <linux/types.h>
10 
11 /**
12  * struct microblaze_cpuinfo - CPU info for microblaze processor core.
13  *
14  * @icache_size: Size of instruction cache memory in bytes.
15  * @icache_line_length: Instruction cache line length in bytes.
16  * @dcache_size: Size of data cache memory in bytes.
17  * @dcache_line_length: Data cache line length in bytes.
18  * @use_mmu: MMU support flag.
19  * @cpu_freq: Cpu clock frequency in Hz.
20  * @addr_size: Address bus width in bits.
21  * @ver_code: Cpu version code.
22  * @fpga_code: FPGA family version code.
23  */
24 struct microblaze_cpuinfo {
25 	u32 icache_size;
26 	u32 icache_line_length;
27 
28 	u32 dcache_size;
29 	u32 dcache_line_length;
30 
31 #if IS_ENABLED(CONFIG_CPU_MICROBLAZE)
32 	u32 use_mmu;
33 	u32 cpu_freq;
34 	u32 addr_size;
35 
36 	u32 ver_code;
37 	u32 fpga_code;
38 #endif /* CONFIG_CPU_MICROBLAZE */
39 };
40 
41 /**
42  * struct microblaze_version_data - Maps a hex version code to a cpu/fpga name.
43  */
44 struct microblaze_version_map {
45 	const char *string;
46 	const u32 code;
47 };
48 
49 /**
50  * microblaze_lookup_cpu_version_code() - Get hex version code for the
51  * specified cpu name string.
52  *
53  * This function searches the cpu_ver_lookup[] array for the hex version code
54  * associated with a specific CPU name. The version code is returned if a match
55  * is found, otherwise 0.
56  *
57  * @string: cpu name string
58  *
59  * Return: >0 if the entry is found, 0 otherwise.
60  */
61 const u32 microblaze_lookup_cpu_version_code(const char *string);
62 
63 /**
64  * microblaze_lookup_fpga_family_code() - Get hex version code for the
65  * specified fpga family name.
66  *
67  * This function searches the family_string_lookup[] array for the hex version
68  * code associated with a specific fpga family name. The version code is
69  * returned if a match is found, otherwise 0.
70  *
71  * @string: fpga family name string
72  *
73  * Return: >0 if the entry is found, 0 otherwise.
74  */
75 const u32 microblaze_lookup_fpga_family_code(const char *string);
76 
77 /**
78  * microblaze_lookup_cpu_version_string() - Get cpu name for the specified cpu
79  * version code.
80  *
81  * This function searches the cpu_ver_lookup[] array for the cpu name string
82  * associated with a specific version code. The cpu name is returned if a match
83  * is found, otherwise "(unknown)".
84  *
85  * @code: cpu version code
86  *
87  * Return: Pointer to the cpu name if the entry is found, otherwise "(unknown)".
88  */
89 const char *microblaze_lookup_cpu_version_string(const u32 code);
90 
91 /**
92  * microblaze_lookup_fpga_family_string() - Get fpga family name for the
93  * specified version code.
94  *
95  * This function searches the family_string_lookup[] array for the fpga family
96  * name string associated with a specific version code. The fpga family name is
97  * returned if a match is found, otherwise "(unknown)".
98  *
99  * @code: fpga family version code
100  *
101  * Return: Pointer to the fpga family name if the entry is found, otherwise
102  * "(unknown)".
103  */
104 const char *microblaze_lookup_fpga_family_string(const u32 code);
105 
106 /**
107  * microblaze_early_cpuinfo_init() - Initialize cpuinfo with default values.
108  *
109  * Initializes the global data cpuinfo structure with default values (cache
110  * size, cache line size, etc.). It is called very early in the boot process
111  * (start.S codepath right before the first cache flush call) to ensure that
112  * cache related operations are properly handled.
113  */
114 void microblaze_early_cpuinfo_init(void);
115 
116 #endif	/* __ASM_MICROBLAZE_CPUINFO_H */
117