blob: 5cc7c5abd7234a9bd08c7beeb8e108f2a47f3d3b [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
12 *
13 * This can be accessed with dev_get_parent_platdata() for any UCLASS_CPU
14 * device.
15 *
16 * @cpu_id: Platform-specific way of identifying the CPU.
Simon Glass8d374cd2016-03-06 19:27:49 -070017 * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set
Simon Glass131a6452015-04-28 20:25:09 -060018 */
19struct cpu_platdata {
20 int cpu_id;
Simon Glass8d374cd2016-03-06 19:27:49 -070021 int ucode_version;
22 ulong device_id;
Alexander Graf00b4fc22016-08-19 01:23:26 +020023 u16 family; /* DMTF CPU Family */
24 u32 id[2]; /* DMTF CPU Processor IDs */
Simon Glass131a6452015-04-28 20:25:09 -060025};
26
27/* CPU features - mostly just a placeholder for now */
28enum {
29 CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */
30 CPU_FEAT_MMU = 1, /* Supports virtual memory */
Simon Glass8d374cd2016-03-06 19:27:49 -070031 CPU_FEAT_UCODE = 2, /* Requires/uses microcode */
32 CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */
Simon Glass131a6452015-04-28 20:25:09 -060033
34 CPU_FEAT_COUNT,
35};
36
37/**
38 * struct cpu_info - Information about a CPU
39 *
40 * @cpu_freq: Current CPU frequency in Hz
41 * @features: Flags for supported CPU features
42 */
43struct cpu_info {
44 ulong cpu_freq;
45 ulong features;
46};
47
48struct cpu_ops {
49 /**
50 * get_desc() - Get a description string for a CPU
51 *
52 * @dev: Device to check (UCLASS_CPU)
53 * @buf: Buffer to place string
54 * @size: Size of string space
55 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
56 */
57 int (*get_desc)(struct udevice *dev, char *buf, int size);
58
59 /**
60 * get_info() - Get information about a CPU
61 *
62 * @dev: Device to check (UCLASS_CPU)
63 * @info: Returns CPU info
64 * @return 0 if OK, -ve on error
65 */
66 int (*get_info)(struct udevice *dev, struct cpu_info *info);
Bin Mengd13b0142015-06-17 11:15:34 +080067
68 /**
69 * get_count() - Get number of CPUs
70 *
71 * @dev: Device to check (UCLASS_CPU)
72 * @return CPU count if OK, -ve on error
73 */
74 int (*get_count)(struct udevice *dev);
Alexander Graf67f66bd2016-08-19 01:23:27 +020075
76 /**
77 * get_vendor() - Get vendor name of a CPU
78 *
79 * @dev: Device to check (UCLASS_CPU)
80 * @buf: Buffer to place string
81 * @size: Size of string space
82 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
83 */
84 int (*get_vendor)(struct udevice *dev, char *buf, int size);
Simon Glass131a6452015-04-28 20:25:09 -060085};
86
87#define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops)
88
89/**
90 * cpu_get_desc() - Get a description string for a CPU
91 *
92 * @dev: Device to check (UCLASS_CPU)
93 * @buf: Buffer to place string
94 * @size: Size of string space
95 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
96 */
97int cpu_get_desc(struct udevice *dev, char *buf, int size);
98
99/**
100 * cpu_get_info() - Get information about a CPU
101 *
102 * @dev: Device to check (UCLASS_CPU)
103 * @info: Returns CPU info
104 * @return 0 if OK, -ve on error
105 */
106int cpu_get_info(struct udevice *dev, struct cpu_info *info);
107
Bin Mengd13b0142015-06-17 11:15:34 +0800108/**
109 * cpu_get_count() - Get number of CPUs
110 *
111 * @dev: Device to check (UCLASS_CPU)
112 * @return CPU count if OK, -ve on error
113 */
114int cpu_get_count(struct udevice *dev);
115
Alexander Graf67f66bd2016-08-19 01:23:27 +0200116/**
117 * cpu_get_vendor() - Get vendor name of a CPU
118 *
119 * @dev: Device to check (UCLASS_CPU)
120 * @buf: Buffer to place string
121 * @size: Size of string space
122 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
123 */
124int cpu_get_vendor(struct udevice *dev, char *buf, int size);
125
Simon Glass131a6452015-04-28 20:25:09 -0600126#endif