xref: /openbmc/u-boot/include/cpu.h (revision e04f9d0c)
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  * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set
19  */
20 struct cpu_platdata {
21 	int cpu_id;
22 	int ucode_version;
23 	ulong device_id;
24 };
25 
26 /* CPU features - mostly just a placeholder for now */
27 enum {
28 	CPU_FEAT_L1_CACHE	= 0,	/* Supports level 1 cache */
29 	CPU_FEAT_MMU		= 1,	/* Supports virtual memory */
30 	CPU_FEAT_UCODE		= 2,	/* Requires/uses microcode */
31 	CPU_FEAT_DEVICE_ID	= 3,	/* Provides a device ID */
32 
33 	CPU_FEAT_COUNT,
34 };
35 
36 /**
37  * struct cpu_info - Information about a CPU
38  *
39  * @cpu_freq:	Current CPU frequency in Hz
40  * @features:	Flags for supported CPU features
41  */
42 struct cpu_info {
43 	ulong cpu_freq;
44 	ulong features;
45 };
46 
47 struct cpu_ops {
48 	/**
49 	 * get_desc() - Get a description string for a CPU
50 	 *
51 	 * @dev:	Device to check (UCLASS_CPU)
52 	 * @buf:	Buffer to place string
53 	 * @size:	Size of string space
54 	 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
55 	 */
56 	int (*get_desc)(struct udevice *dev, char *buf, int size);
57 
58 	/**
59 	 * get_info() - Get information about a CPU
60 	 *
61 	 * @dev:	Device to check (UCLASS_CPU)
62 	 * @info:	Returns CPU info
63 	 * @return 0 if OK, -ve on error
64 	 */
65 	int (*get_info)(struct udevice *dev, struct cpu_info *info);
66 
67 	/**
68 	 * get_count() - Get number of CPUs
69 	 *
70 	 * @dev:	Device to check (UCLASS_CPU)
71 	 * @return CPU count if OK, -ve on error
72 	 */
73 	int (*get_count)(struct udevice *dev);
74 };
75 
76 #define cpu_get_ops(dev)        ((struct cpu_ops *)(dev)->driver->ops)
77 
78 /**
79  * cpu_get_desc() - Get a description string for 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 cpu_get_desc(struct udevice *dev, char *buf, int size);
87 
88 /**
89  * cpu_get_info() - Get information about a CPU
90  *
91  * @dev:	Device to check (UCLASS_CPU)
92  * @info:	Returns CPU info
93  * @return 0 if OK, -ve on error
94  */
95 int cpu_get_info(struct udevice *dev, struct cpu_info *info);
96 
97 /**
98  * cpu_get_count() - Get number of CPUs
99  *
100  * @dev:	Device to check (UCLASS_CPU)
101  * @return CPU count if OK, -ve on error
102  */
103 int cpu_get_count(struct udevice *dev);
104 
105 #endif
106