xref: /openbmc/u-boot/include/cpu.h (revision 5c8fd32b)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 2015 Google, Inc
4  * Written by Simon Glass <sjg@chromium.org>
5  */
6 
7 #ifndef __CPU_H
8 #define __CPU_H
9 
10 /**
11  * struct cpu_platdata - platform data for a CPU
12  * @cpu_id:	   Platform-specific way of identifying the CPU.
13  * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set
14  * @device_id:     Driver-defined device identifier
15  * @family:        DMTF CPU Family identifier
16  * @id:            DMTF CPU Processor identifier
17  *
18  * This can be accessed with dev_get_parent_platdata() for any UCLASS_CPU
19  * device.
20  */
21 struct cpu_platdata {
22 	int cpu_id;
23 	int ucode_version;
24 	ulong device_id;
25 	u16 family;
26 	u32 id[2];
27 };
28 
29 /* CPU features - mostly just a placeholder for now */
30 enum {
31 	CPU_FEAT_L1_CACHE	= 0,	/* Supports level 1 cache */
32 	CPU_FEAT_MMU		= 1,	/* Supports virtual memory */
33 	CPU_FEAT_UCODE		= 2,	/* Requires/uses microcode */
34 	CPU_FEAT_DEVICE_ID	= 3,	/* Provides a device ID */
35 
36 	CPU_FEAT_COUNT,
37 };
38 
39 /**
40  * struct cpu_info - Information about a CPU
41  *
42  * @cpu_freq:	Current CPU frequency in Hz
43  * @features:	Flags for supported CPU features
44  */
45 struct cpu_info {
46 	ulong cpu_freq;
47 	ulong features;
48 };
49 
50 struct cpu_ops {
51 	/**
52 	 * get_desc() - Get a description string for a CPU
53 	 *
54 	 * @dev:	Device to check (UCLASS_CPU)
55 	 * @buf:	Buffer to place string
56 	 * @size:	Size of string space
57 	 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
58 	 */
59 	int (*get_desc)(struct udevice *dev, char *buf, int size);
60 
61 	/**
62 	 * get_info() - Get information about a CPU
63 	 *
64 	 * @dev:	Device to check (UCLASS_CPU)
65 	 * @info:	Returns CPU info
66 	 * @return 0 if OK, -ve on error
67 	 */
68 	int (*get_info)(struct udevice *dev, struct cpu_info *info);
69 
70 	/**
71 	 * get_count() - Get number of CPUs
72 	 *
73 	 * @dev:	Device to check (UCLASS_CPU)
74 	 * @return CPU count if OK, -ve on error
75 	 */
76 	int (*get_count)(struct udevice *dev);
77 
78 	/**
79 	 * get_vendor() - Get vendor name of a CPU
80 	 *
81 	 * @dev:	Device to check (UCLASS_CPU)
82 	 * @buf:	Buffer to place string
83 	 * @size:	Size of string space
84 	 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
85 	 */
86 	int (*get_vendor)(struct udevice *dev, char *buf, int size);
87 };
88 
89 #define cpu_get_ops(dev)        ((struct cpu_ops *)(dev)->driver->ops)
90 
91 /**
92  * cpu_get_desc() - Get a description string for a CPU
93  * @dev:	Device to check (UCLASS_CPU)
94  * @buf:	Buffer to place string
95  * @size:	Size of string space
96  *
97  * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
98  */
99 int cpu_get_desc(struct udevice *dev, char *buf, int size);
100 
101 /**
102  * cpu_get_info() - Get information about a CPU
103  * @dev:	Device to check (UCLASS_CPU)
104  * @info:	Returns CPU info
105  *
106  * Return: 0 if OK, -ve on error
107  */
108 int cpu_get_info(struct udevice *dev, struct cpu_info *info);
109 
110 /**
111  * cpu_get_count() - Get number of CPUs
112  * @dev:	Device to check (UCLASS_CPU)
113  *
114  * Return: CPU count if OK, -ve on error
115  */
116 int cpu_get_count(struct udevice *dev);
117 
118 /**
119  * cpu_get_vendor() - Get vendor name of a CPU
120  * @dev:	Device to check (UCLASS_CPU)
121  * @buf:	Buffer to place string
122  * @size:	Size of string space
123  *
124  * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
125  */
126 int cpu_get_vendor(struct udevice *dev, char *buf, int size);
127 
128 /**
129  * cpu_probe_all() - Probe all available CPUs
130  *
131  * Return: 0 if OK, -ve on error
132  */
133 int cpu_probe_all(void);
134 
135 #endif
136