blob: bda53150a6fb2bc1ebcb351f48ad4c175bcd8f3f [file] [log] [blame]
Simon Glass131a6452015-04-28 20:25:09 -06001/*
2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#ifndef __CPU_H
9#define __CPU_H
10
11/**
12 * struct cpu_platdata - platform data for a CPU
13 *
14 * This can be accessed with dev_get_parent_platdata() for any UCLASS_CPU
15 * device.
16 *
17 * @cpu_id: Platform-specific way of identifying the CPU.
Simon Glass8d374cd2016-03-06 19:27:49 -070018 * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set
Simon Glass131a6452015-04-28 20:25:09 -060019 */
20struct cpu_platdata {
21 int cpu_id;
Simon Glass8d374cd2016-03-06 19:27:49 -070022 int ucode_version;
23 ulong device_id;
Simon Glass131a6452015-04-28 20:25:09 -060024};
25
26/* CPU features - mostly just a placeholder for now */
27enum {
28 CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */
29 CPU_FEAT_MMU = 1, /* Supports virtual memory */
Simon Glass8d374cd2016-03-06 19:27:49 -070030 CPU_FEAT_UCODE = 2, /* Requires/uses microcode */
31 CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */
Simon Glass131a6452015-04-28 20:25:09 -060032
33 CPU_FEAT_COUNT,
34};
35
36/**
37 * struct cpu_info - Information about a CPU
38 *
39 * @cpu_freq: Current CPU frequency in Hz
40 * @features: Flags for supported CPU features
41 */
42struct cpu_info {
43 ulong cpu_freq;
44 ulong features;
45};
46
47struct cpu_ops {
48 /**
49 * get_desc() - Get a description string for a CPU
50 *
51 * @dev: Device to check (UCLASS_CPU)
52 * @buf: Buffer to place string
53 * @size: Size of string space
54 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
55 */
56 int (*get_desc)(struct udevice *dev, char *buf, int size);
57
58 /**
59 * get_info() - Get information about a CPU
60 *
61 * @dev: Device to check (UCLASS_CPU)
62 * @info: Returns CPU info
63 * @return 0 if OK, -ve on error
64 */
65 int (*get_info)(struct udevice *dev, struct cpu_info *info);
Bin Mengd13b0142015-06-17 11:15:34 +080066
67 /**
68 * get_count() - Get number of CPUs
69 *
70 * @dev: Device to check (UCLASS_CPU)
71 * @return CPU count if OK, -ve on error
72 */
73 int (*get_count)(struct udevice *dev);
Simon Glass131a6452015-04-28 20:25:09 -060074};
75
76#define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops)
77
78/**
79 * cpu_get_desc() - Get a description string for 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 */
86int cpu_get_desc(struct udevice *dev, char *buf, int size);
87
88/**
89 * cpu_get_info() - Get information about a CPU
90 *
91 * @dev: Device to check (UCLASS_CPU)
92 * @info: Returns CPU info
93 * @return 0 if OK, -ve on error
94 */
95int cpu_get_info(struct udevice *dev, struct cpu_info *info);
96
Bin Mengd13b0142015-06-17 11:15:34 +080097/**
98 * cpu_get_count() - Get number of CPUs
99 *
100 * @dev: Device to check (UCLASS_CPU)
101 * @return CPU count if OK, -ve on error
102 */
103int cpu_get_count(struct udevice *dev);
104
Simon Glass131a6452015-04-28 20:25:09 -0600105#endif