xref: /openbmc/u-boot/include/cpu.h (revision 7e40d0a3)
183d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
211f4dc15SSimon Glass /*
311f4dc15SSimon Glass  * Copyright (c) 2015 Google, Inc
411f4dc15SSimon Glass  * Written by Simon Glass <sjg@chromium.org>
511f4dc15SSimon Glass  */
611f4dc15SSimon Glass 
711f4dc15SSimon Glass #ifndef __CPU_H
811f4dc15SSimon Glass #define __CPU_H
911f4dc15SSimon Glass 
1011f4dc15SSimon Glass /**
1111f4dc15SSimon Glass  * struct cpu_platdata - platform data for a CPU
1250d188b9SMario Six  * @cpu_id:	   Platform-specific way of identifying the CPU.
1350d188b9SMario Six  * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set
1450d188b9SMario Six  * @device_id:     Driver-defined device identifier
1550d188b9SMario Six  * @family:        DMTF CPU Family identifier
1650d188b9SMario Six  * @id:            DMTF CPU Processor identifier
17*b8596947SBin Meng  * @timebase_freq: the current frequency at which the cpu timer timebase
18*b8596947SBin Meng  *		   registers are updated (in Hz)
1911f4dc15SSimon Glass  *
2011f4dc15SSimon Glass  * This can be accessed with dev_get_parent_platdata() for any UCLASS_CPU
2111f4dc15SSimon Glass  * device.
2211f4dc15SSimon Glass  */
2311f4dc15SSimon Glass struct cpu_platdata {
2411f4dc15SSimon Glass 	int cpu_id;
25740d5d34SSimon Glass 	int ucode_version;
26740d5d34SSimon Glass 	ulong device_id;
2750d188b9SMario Six 	u16 family;
2850d188b9SMario Six 	u32 id[2];
29*b8596947SBin Meng 	u32 timebase_freq;
3011f4dc15SSimon Glass };
3111f4dc15SSimon Glass 
3211f4dc15SSimon Glass /* CPU features - mostly just a placeholder for now */
3311f4dc15SSimon Glass enum {
3411f4dc15SSimon Glass 	CPU_FEAT_L1_CACHE	= 0,	/* Supports level 1 cache */
3511f4dc15SSimon Glass 	CPU_FEAT_MMU		= 1,	/* Supports virtual memory */
36740d5d34SSimon Glass 	CPU_FEAT_UCODE		= 2,	/* Requires/uses microcode */
37740d5d34SSimon Glass 	CPU_FEAT_DEVICE_ID	= 3,	/* Provides a device ID */
3811f4dc15SSimon Glass 
3911f4dc15SSimon Glass 	CPU_FEAT_COUNT,
4011f4dc15SSimon Glass };
4111f4dc15SSimon Glass 
4211f4dc15SSimon Glass /**
4311f4dc15SSimon Glass  * struct cpu_info - Information about a CPU
4411f4dc15SSimon Glass  *
4511f4dc15SSimon Glass  * @cpu_freq:	Current CPU frequency in Hz
4611f4dc15SSimon Glass  * @features:	Flags for supported CPU features
4711f4dc15SSimon Glass  */
4811f4dc15SSimon Glass struct cpu_info {
4911f4dc15SSimon Glass 	ulong cpu_freq;
5011f4dc15SSimon Glass 	ulong features;
5111f4dc15SSimon Glass };
5211f4dc15SSimon Glass 
5311f4dc15SSimon Glass struct cpu_ops {
5411f4dc15SSimon Glass 	/**
5511f4dc15SSimon Glass 	 * get_desc() - Get a description string for a CPU
5611f4dc15SSimon Glass 	 *
5711f4dc15SSimon Glass 	 * @dev:	Device to check (UCLASS_CPU)
5811f4dc15SSimon Glass 	 * @buf:	Buffer to place string
5911f4dc15SSimon Glass 	 * @size:	Size of string space
6011f4dc15SSimon Glass 	 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
6111f4dc15SSimon Glass 	 */
6211f4dc15SSimon Glass 	int (*get_desc)(struct udevice *dev, char *buf, int size);
6311f4dc15SSimon Glass 
6411f4dc15SSimon Glass 	/**
6511f4dc15SSimon Glass 	 * get_info() - Get information about a CPU
6611f4dc15SSimon Glass 	 *
6711f4dc15SSimon Glass 	 * @dev:	Device to check (UCLASS_CPU)
6811f4dc15SSimon Glass 	 * @info:	Returns CPU info
6911f4dc15SSimon Glass 	 * @return 0 if OK, -ve on error
7011f4dc15SSimon Glass 	 */
7111f4dc15SSimon Glass 	int (*get_info)(struct udevice *dev, struct cpu_info *info);
72780bfdd3SBin Meng 
73780bfdd3SBin Meng 	/**
74780bfdd3SBin Meng 	 * get_count() - Get number of CPUs
75780bfdd3SBin Meng 	 *
76780bfdd3SBin Meng 	 * @dev:	Device to check (UCLASS_CPU)
77780bfdd3SBin Meng 	 * @return CPU count if OK, -ve on error
78780bfdd3SBin Meng 	 */
79780bfdd3SBin Meng 	int (*get_count)(struct udevice *dev);
8094eaa79cSAlexander Graf 
8194eaa79cSAlexander Graf 	/**
8294eaa79cSAlexander Graf 	 * get_vendor() - Get vendor name of a CPU
8394eaa79cSAlexander Graf 	 *
8494eaa79cSAlexander Graf 	 * @dev:	Device to check (UCLASS_CPU)
8594eaa79cSAlexander Graf 	 * @buf:	Buffer to place string
8694eaa79cSAlexander Graf 	 * @size:	Size of string space
8794eaa79cSAlexander Graf 	 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
8894eaa79cSAlexander Graf 	 */
8994eaa79cSAlexander Graf 	int (*get_vendor)(struct udevice *dev, char *buf, int size);
9011f4dc15SSimon Glass };
9111f4dc15SSimon Glass 
9211f4dc15SSimon Glass #define cpu_get_ops(dev)        ((struct cpu_ops *)(dev)->driver->ops)
9311f4dc15SSimon Glass 
9411f4dc15SSimon Glass /**
9511f4dc15SSimon Glass  * cpu_get_desc() - Get a description string for a CPU
9611f4dc15SSimon Glass  * @dev:	Device to check (UCLASS_CPU)
9711f4dc15SSimon Glass  * @buf:	Buffer to place string
9811f4dc15SSimon Glass  * @size:	Size of string space
9950d188b9SMario Six  *
10050d188b9SMario Six  * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
10111f4dc15SSimon Glass  */
10211f4dc15SSimon Glass int cpu_get_desc(struct udevice *dev, char *buf, int size);
10311f4dc15SSimon Glass 
10411f4dc15SSimon Glass /**
10511f4dc15SSimon Glass  * cpu_get_info() - Get information about a CPU
10611f4dc15SSimon Glass  * @dev:	Device to check (UCLASS_CPU)
10711f4dc15SSimon Glass  * @info:	Returns CPU info
10850d188b9SMario Six  *
10950d188b9SMario Six  * Return: 0 if OK, -ve on error
11011f4dc15SSimon Glass  */
11111f4dc15SSimon Glass int cpu_get_info(struct udevice *dev, struct cpu_info *info);
11211f4dc15SSimon Glass 
113780bfdd3SBin Meng /**
114780bfdd3SBin Meng  * cpu_get_count() - Get number of CPUs
115780bfdd3SBin Meng  * @dev:	Device to check (UCLASS_CPU)
11650d188b9SMario Six  *
11750d188b9SMario Six  * Return: CPU count if OK, -ve on error
118780bfdd3SBin Meng  */
119780bfdd3SBin Meng int cpu_get_count(struct udevice *dev);
120780bfdd3SBin Meng 
12194eaa79cSAlexander Graf /**
12294eaa79cSAlexander Graf  * cpu_get_vendor() - Get vendor name of a CPU
12394eaa79cSAlexander Graf  * @dev:	Device to check (UCLASS_CPU)
12494eaa79cSAlexander Graf  * @buf:	Buffer to place string
12594eaa79cSAlexander Graf  * @size:	Size of string space
12650d188b9SMario Six  *
12750d188b9SMario Six  * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
12894eaa79cSAlexander Graf  */
12994eaa79cSAlexander Graf int cpu_get_vendor(struct udevice *dev, char *buf, int size);
13094eaa79cSAlexander Graf 
13157370de3SMario Six /**
13257370de3SMario Six  * cpu_probe_all() - Probe all available CPUs
13357370de3SMario Six  *
13457370de3SMario Six  * Return: 0 if OK, -ve on error
13557370de3SMario Six  */
13657370de3SMario Six int cpu_probe_all(void);
13757370de3SMario Six 
13811f4dc15SSimon Glass #endif
139