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