blob: be02a1671298950867c4366ec4bd4a98027c3fd2 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass131a6452015-04-28 20:25:09 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass131a6452015-04-28 20:25:09 -06005 */
6
7#ifndef __CPU_H
8#define __CPU_H
9
Simon Glass3ba929a2020-10-30 21:38:53 -060010struct udevice;
11
Simon Glass131a6452015-04-28 20:25:09 -060012/**
Simon Glassb75b15b2020-12-03 16:55:23 -070013 * struct cpu_plat - platform data for a CPU
Mario Six60ce6dd2018-08-06 10:23:42 +020014 * @cpu_id: Platform-specific way of identifying the CPU.
15 * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set
16 * @device_id: Driver-defined device identifier
17 * @family: DMTF CPU Family identifier
18 * @id: DMTF CPU Processor identifier
Bin Mengb2aa4952018-12-12 06:12:24 -080019 * @timebase_freq: the current frequency at which the cpu timer timebase
20 * registers are updated (in Hz)
Simon Glass131a6452015-04-28 20:25:09 -060021 *
Simon Glass71fa5b42020-12-03 16:55:18 -070022 * This can be accessed with dev_get_parent_plat() for any UCLASS_CPU
Simon Glass131a6452015-04-28 20:25:09 -060023 * device.
Simon Glass131a6452015-04-28 20:25:09 -060024 */
Simon Glassb75b15b2020-12-03 16:55:23 -070025struct cpu_plat {
Simon Glass131a6452015-04-28 20:25:09 -060026 int cpu_id;
Simon Glass8d374cd2016-03-06 19:27:49 -070027 int ucode_version;
28 ulong device_id;
Mario Six60ce6dd2018-08-06 10:23:42 +020029 u16 family;
30 u32 id[2];
Bin Mengb2aa4952018-12-12 06:12:24 -080031 u32 timebase_freq;
Simon Glass131a6452015-04-28 20:25:09 -060032};
33
34/* CPU features - mostly just a placeholder for now */
35enum {
36 CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */
37 CPU_FEAT_MMU = 1, /* Supports virtual memory */
Simon Glass8d374cd2016-03-06 19:27:49 -070038 CPU_FEAT_UCODE = 2, /* Requires/uses microcode */
39 CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */
Simon Glass131a6452015-04-28 20:25:09 -060040
41 CPU_FEAT_COUNT,
42};
43
44/**
45 * struct cpu_info - Information about a CPU
46 *
47 * @cpu_freq: Current CPU frequency in Hz
48 * @features: Flags for supported CPU features
Simon Glassc35854a2020-04-08 16:57:20 -060049 * @address_width: Width of the CPU address space in bits (e.g. 32)
Simon Glass131a6452015-04-28 20:25:09 -060050 */
51struct cpu_info {
52 ulong cpu_freq;
53 ulong features;
Simon Glassc35854a2020-04-08 16:57:20 -060054 uint address_width;
Simon Glass131a6452015-04-28 20:25:09 -060055};
56
57struct cpu_ops {
58 /**
59 * get_desc() - Get a description string for a CPU
60 *
61 * @dev: Device to check (UCLASS_CPU)
62 * @buf: Buffer to place string
63 * @size: Size of string space
64 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
65 */
Simon Glass791fa452020-01-26 22:06:27 -070066 int (*get_desc)(const struct udevice *dev, char *buf, int size);
Simon Glass131a6452015-04-28 20:25:09 -060067
68 /**
69 * get_info() - Get information about a CPU
70 *
71 * @dev: Device to check (UCLASS_CPU)
72 * @info: Returns CPU info
73 * @return 0 if OK, -ve on error
74 */
Simon Glass791fa452020-01-26 22:06:27 -070075 int (*get_info)(const struct udevice *dev, struct cpu_info *info);
Bin Mengd13b0142015-06-17 11:15:34 +080076
77 /**
78 * get_count() - Get number of CPUs
79 *
80 * @dev: Device to check (UCLASS_CPU)
81 * @return CPU count if OK, -ve on error
82 */
Simon Glass791fa452020-01-26 22:06:27 -070083 int (*get_count)(const struct udevice *dev);
Alexander Graf67f66bd2016-08-19 01:23:27 +020084
85 /**
86 * get_vendor() - Get vendor name of a CPU
87 *
88 * @dev: Device to check (UCLASS_CPU)
89 * @buf: Buffer to place string
90 * @size: Size of string space
91 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
92 */
Simon Glass791fa452020-01-26 22:06:27 -070093 int (*get_vendor)(const struct udevice *dev, char *buf, int size);
Peng Fan221763a2020-05-03 21:58:47 +080094
95 /**
96 * is_current() - Check if the CPU that U-Boot is currently running from
97 *
98 * @dev: Device to check (UCLASS_CPU)
99 * @return 1 if the CPU that U-Boot is currently running from, 0
100 * if not.
101 */
102 int (*is_current)(struct udevice *dev);
Simon Glass131a6452015-04-28 20:25:09 -0600103};
104
105#define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops)
106
107/**
108 * cpu_get_desc() - Get a description string for a CPU
Simon Glass131a6452015-04-28 20:25:09 -0600109 * @dev: Device to check (UCLASS_CPU)
110 * @buf: Buffer to place string
111 * @size: Size of string space
Mario Six60ce6dd2018-08-06 10:23:42 +0200112 *
113 * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
Simon Glass131a6452015-04-28 20:25:09 -0600114 */
Simon Glass791fa452020-01-26 22:06:27 -0700115int cpu_get_desc(const struct udevice *dev, char *buf, int size);
Simon Glass131a6452015-04-28 20:25:09 -0600116
117/**
118 * cpu_get_info() - Get information about a CPU
Simon Glass131a6452015-04-28 20:25:09 -0600119 * @dev: Device to check (UCLASS_CPU)
120 * @info: Returns CPU info
Mario Six60ce6dd2018-08-06 10:23:42 +0200121 *
122 * Return: 0 if OK, -ve on error
Simon Glass131a6452015-04-28 20:25:09 -0600123 */
Simon Glass791fa452020-01-26 22:06:27 -0700124int cpu_get_info(const struct udevice *dev, struct cpu_info *info);
Simon Glass131a6452015-04-28 20:25:09 -0600125
Bin Mengd13b0142015-06-17 11:15:34 +0800126/**
127 * cpu_get_count() - Get number of CPUs
Bin Mengd13b0142015-06-17 11:15:34 +0800128 * @dev: Device to check (UCLASS_CPU)
Mario Six60ce6dd2018-08-06 10:23:42 +0200129 *
130 * Return: CPU count if OK, -ve on error
Bin Mengd13b0142015-06-17 11:15:34 +0800131 */
Simon Glass791fa452020-01-26 22:06:27 -0700132int cpu_get_count(const struct udevice *dev);
Bin Mengd13b0142015-06-17 11:15:34 +0800133
Alexander Graf67f66bd2016-08-19 01:23:27 +0200134/**
135 * cpu_get_vendor() - Get vendor name of a CPU
Alexander Graf67f66bd2016-08-19 01:23:27 +0200136 * @dev: Device to check (UCLASS_CPU)
137 * @buf: Buffer to place string
138 * @size: Size of string space
Mario Six60ce6dd2018-08-06 10:23:42 +0200139 *
140 * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
Alexander Graf67f66bd2016-08-19 01:23:27 +0200141 */
Simon Glass791fa452020-01-26 22:06:27 -0700142int cpu_get_vendor(const struct udevice *dev, char *buf, int size);
Alexander Graf67f66bd2016-08-19 01:23:27 +0200143
Mario Six0263b432018-08-06 10:23:43 +0200144/**
145 * cpu_probe_all() - Probe all available CPUs
146 *
147 * Return: 0 if OK, -ve on error
148 */
149int cpu_probe_all(void);
150
Peng Fan221763a2020-05-03 21:58:47 +0800151/**
152 * cpu_is_current() - Check if the CPU that U-Boot is currently running from
153 *
154 * Return: 1 if yes, - 0 if not
155 */
156int cpu_is_current(struct udevice *cpu);
157
158/**
159 * cpu_get_current_dev() - Get CPU udevice for current CPU
160 *
161 * Return: udevice if OK, - NULL on error
162 */
163struct udevice *cpu_get_current_dev(void);
164
Simon Glass131a6452015-04-28 20:25:09 -0600165#endif