xref: /openbmc/u-boot/include/cpu.h (revision 23ff8633)
1 /*
2  * Copyright (c) 2015 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #ifndef __CPU_H
9 #define __CPU_H
10 
11 /**
12  * struct cpu_platdata - platform data for a CPU
13  *
14  * This can be accessed with dev_get_parent_platdata() for any UCLASS_CPU
15  * device.
16  *
17  * @cpu_id:	Platform-specific way of identifying the CPU.
18  */
19 struct cpu_platdata {
20 	int cpu_id;
21 };
22 
23 /* CPU features - mostly just a placeholder for now */
24 enum {
25 	CPU_FEAT_L1_CACHE	= 0,	/* Supports level 1 cache */
26 	CPU_FEAT_MMU		= 1,	/* Supports virtual memory */
27 
28 	CPU_FEAT_COUNT,
29 };
30 
31 /**
32  * struct cpu_info - Information about a CPU
33  *
34  * @cpu_freq:	Current CPU frequency in Hz
35  * @features:	Flags for supported CPU features
36  */
37 struct cpu_info {
38 	ulong cpu_freq;
39 	ulong features;
40 };
41 
42 struct cpu_ops {
43 	/**
44 	 * get_desc() - Get a description string for a CPU
45 	 *
46 	 * @dev:	Device to check (UCLASS_CPU)
47 	 * @buf:	Buffer to place string
48 	 * @size:	Size of string space
49 	 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
50 	 */
51 	int (*get_desc)(struct udevice *dev, char *buf, int size);
52 
53 	/**
54 	 * get_info() - Get information about a CPU
55 	 *
56 	 * @dev:	Device to check (UCLASS_CPU)
57 	 * @info:	Returns CPU info
58 	 * @return 0 if OK, -ve on error
59 	 */
60 	int (*get_info)(struct udevice *dev, struct cpu_info *info);
61 
62 	/**
63 	 * get_count() - Get number of CPUs
64 	 *
65 	 * @dev:	Device to check (UCLASS_CPU)
66 	 * @return CPU count if OK, -ve on error
67 	 */
68 	int (*get_count)(struct udevice *dev);
69 };
70 
71 #define cpu_get_ops(dev)        ((struct cpu_ops *)(dev)->driver->ops)
72 
73 /**
74  * cpu_get_desc() - Get a description string for a CPU
75  *
76  * @dev:	Device to check (UCLASS_CPU)
77  * @buf:	Buffer to place string
78  * @size:	Size of string space
79  * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
80  */
81 int cpu_get_desc(struct udevice *dev, char *buf, int size);
82 
83 /**
84  * cpu_get_info() - Get information about a CPU
85  *
86  * @dev:	Device to check (UCLASS_CPU)
87  * @info:	Returns CPU info
88  * @return 0 if OK, -ve on error
89  */
90 int cpu_get_info(struct udevice *dev, struct cpu_info *info);
91 
92 /**
93  * cpu_get_count() - Get number of CPUs
94  *
95  * @dev:	Device to check (UCLASS_CPU)
96  * @return CPU count if OK, -ve on error
97  */
98 int cpu_get_count(struct udevice *dev);
99 
100 #endif
101