blob: 28dd48feb8f0a6c1ce8aceaa2d8d15b8d49c39aa [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass11f4dc12015-04-28 20:25:09 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass11f4dc12015-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 Six50d188b2018-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
Bin Mengb8596942018-12-12 06:12:24 -080017 * @timebase_freq: the current frequency at which the cpu timer timebase
18 * registers are updated (in Hz)
Simon Glass11f4dc12015-04-28 20:25:09 -060019 *
20 * This can be accessed with dev_get_parent_platdata() for any UCLASS_CPU
21 * device.
Simon Glass11f4dc12015-04-28 20:25:09 -060022 */
23struct cpu_platdata {
24 int cpu_id;
Simon Glass740d5d32016-03-06 19:27:49 -070025 int ucode_version;
26 ulong device_id;
Mario Six50d188b2018-08-06 10:23:42 +020027 u16 family;
28 u32 id[2];
Bin Mengb8596942018-12-12 06:12:24 -080029 u32 timebase_freq;
Simon Glass11f4dc12015-04-28 20:25:09 -060030};
31
32/* CPU features - mostly just a placeholder for now */
33enum {
34 CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */
35 CPU_FEAT_MMU = 1, /* Supports virtual memory */
Simon Glass740d5d32016-03-06 19:27:49 -070036 CPU_FEAT_UCODE = 2, /* Requires/uses microcode */
37 CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */
Simon Glass11f4dc12015-04-28 20:25:09 -060038
39 CPU_FEAT_COUNT,
40};
41
42/**
43 * struct cpu_info - Information about a CPU
44 *
45 * @cpu_freq: Current CPU frequency in Hz
46 * @features: Flags for supported CPU features
47 */
48struct cpu_info {
49 ulong cpu_freq;
50 ulong features;
51};
52
53struct cpu_ops {
54 /**
55 * get_desc() - Get a description string for a CPU
56 *
57 * @dev: Device to check (UCLASS_CPU)
58 * @buf: Buffer to place string
59 * @size: Size of string space
60 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
61 */
62 int (*get_desc)(struct udevice *dev, char *buf, int size);
63
64 /**
65 * get_info() - Get information about a CPU
66 *
67 * @dev: Device to check (UCLASS_CPU)
68 * @info: Returns CPU info
69 * @return 0 if OK, -ve on error
70 */
71 int (*get_info)(struct udevice *dev, struct cpu_info *info);
Bin Meng780bfdd2015-06-17 11:15:34 +080072
73 /**
74 * get_count() - Get number of CPUs
75 *
76 * @dev: Device to check (UCLASS_CPU)
77 * @return CPU count if OK, -ve on error
78 */
79 int (*get_count)(struct udevice *dev);
Alexander Graf94eaa792016-08-19 01:23:27 +020080
81 /**
82 * get_vendor() - Get vendor name of a CPU
83 *
84 * @dev: Device to check (UCLASS_CPU)
85 * @buf: Buffer to place string
86 * @size: Size of string space
87 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
88 */
89 int (*get_vendor)(struct udevice *dev, char *buf, int size);
Simon Glass11f4dc12015-04-28 20:25:09 -060090};
91
92#define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops)
93
94/**
95 * cpu_get_desc() - Get a description string for a CPU
Simon Glass11f4dc12015-04-28 20:25:09 -060096 * @dev: Device to check (UCLASS_CPU)
97 * @buf: Buffer to place string
98 * @size: Size of string space
Mario Six50d188b2018-08-06 10:23:42 +020099 *
100 * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
Simon Glass11f4dc12015-04-28 20:25:09 -0600101 */
102int cpu_get_desc(struct udevice *dev, char *buf, int size);
103
104/**
105 * cpu_get_info() - Get information about a CPU
Simon Glass11f4dc12015-04-28 20:25:09 -0600106 * @dev: Device to check (UCLASS_CPU)
107 * @info: Returns CPU info
Mario Six50d188b2018-08-06 10:23:42 +0200108 *
109 * Return: 0 if OK, -ve on error
Simon Glass11f4dc12015-04-28 20:25:09 -0600110 */
111int cpu_get_info(struct udevice *dev, struct cpu_info *info);
112
Bin Meng780bfdd2015-06-17 11:15:34 +0800113/**
114 * cpu_get_count() - Get number of CPUs
Bin Meng780bfdd2015-06-17 11:15:34 +0800115 * @dev: Device to check (UCLASS_CPU)
Mario Six50d188b2018-08-06 10:23:42 +0200116 *
117 * Return: CPU count if OK, -ve on error
Bin Meng780bfdd2015-06-17 11:15:34 +0800118 */
119int cpu_get_count(struct udevice *dev);
120
Alexander Graf94eaa792016-08-19 01:23:27 +0200121/**
122 * cpu_get_vendor() - Get vendor name of a CPU
Alexander Graf94eaa792016-08-19 01:23:27 +0200123 * @dev: Device to check (UCLASS_CPU)
124 * @buf: Buffer to place string
125 * @size: Size of string space
Mario Six50d188b2018-08-06 10:23:42 +0200126 *
127 * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
Alexander Graf94eaa792016-08-19 01:23:27 +0200128 */
129int cpu_get_vendor(struct udevice *dev, char *buf, int size);
130
Mario Six57370de2018-08-06 10:23:43 +0200131/**
132 * cpu_probe_all() - Probe all available CPUs
133 *
134 * Return: 0 if OK, -ve on error
135 */
136int cpu_probe_all(void);
137
Simon Glass11f4dc12015-04-28 20:25:09 -0600138#endif