blob: 367c5f46a00f8499f93027653946c15bc75c4033 [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
10/**
11 * struct cpu_platdata - platform data for a CPU
Mario Six60ce6dd2018-08-06 10:23:42 +020012 * @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
Simon Glass131a6452015-04-28 20:25:09 -060017 *
18 * This can be accessed with dev_get_parent_platdata() for any UCLASS_CPU
19 * device.
Simon Glass131a6452015-04-28 20:25:09 -060020 */
21struct cpu_platdata {
22 int cpu_id;
Simon Glass8d374cd2016-03-06 19:27:49 -070023 int ucode_version;
24 ulong device_id;
Mario Six60ce6dd2018-08-06 10:23:42 +020025 u16 family;
26 u32 id[2];
Simon Glass131a6452015-04-28 20:25:09 -060027};
28
29/* CPU features - mostly just a placeholder for now */
30enum {
31 CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */
32 CPU_FEAT_MMU = 1, /* Supports virtual memory */
Simon Glass8d374cd2016-03-06 19:27:49 -070033 CPU_FEAT_UCODE = 2, /* Requires/uses microcode */
34 CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */
Simon Glass131a6452015-04-28 20:25:09 -060035
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 */
45struct cpu_info {
46 ulong cpu_freq;
47 ulong features;
48};
49
50struct 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);
Bin Mengd13b0142015-06-17 11:15:34 +080069
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);
Alexander Graf67f66bd2016-08-19 01:23:27 +020077
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);
Simon Glass131a6452015-04-28 20:25:09 -060087};
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
Simon Glass131a6452015-04-28 20:25:09 -060093 * @dev: Device to check (UCLASS_CPU)
94 * @buf: Buffer to place string
95 * @size: Size of string space
Mario Six60ce6dd2018-08-06 10:23:42 +020096 *
97 * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
Simon Glass131a6452015-04-28 20:25:09 -060098 */
99int cpu_get_desc(struct udevice *dev, char *buf, int size);
100
101/**
102 * cpu_get_info() - Get information about a CPU
Simon Glass131a6452015-04-28 20:25:09 -0600103 * @dev: Device to check (UCLASS_CPU)
104 * @info: Returns CPU info
Mario Six60ce6dd2018-08-06 10:23:42 +0200105 *
106 * Return: 0 if OK, -ve on error
Simon Glass131a6452015-04-28 20:25:09 -0600107 */
108int cpu_get_info(struct udevice *dev, struct cpu_info *info);
109
Bin Mengd13b0142015-06-17 11:15:34 +0800110/**
111 * cpu_get_count() - Get number of CPUs
Bin Mengd13b0142015-06-17 11:15:34 +0800112 * @dev: Device to check (UCLASS_CPU)
Mario Six60ce6dd2018-08-06 10:23:42 +0200113 *
114 * Return: CPU count if OK, -ve on error
Bin Mengd13b0142015-06-17 11:15:34 +0800115 */
116int cpu_get_count(struct udevice *dev);
117
Alexander Graf67f66bd2016-08-19 01:23:27 +0200118/**
119 * cpu_get_vendor() - Get vendor name of a CPU
Alexander Graf67f66bd2016-08-19 01:23:27 +0200120 * @dev: Device to check (UCLASS_CPU)
121 * @buf: Buffer to place string
122 * @size: Size of string space
Mario Six60ce6dd2018-08-06 10:23:42 +0200123 *
124 * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
Alexander Graf67f66bd2016-08-19 01:23:27 +0200125 */
126int cpu_get_vendor(struct udevice *dev, char *buf, int size);
127
Mario Six0263b432018-08-06 10:23:43 +0200128/**
129 * cpu_probe_all() - Probe all available CPUs
130 *
131 * Return: 0 if OK, -ve on error
132 */
133int cpu_probe_all(void);
134
Simon Glass131a6452015-04-28 20:25:09 -0600135#endif