Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __CPU_H |
| 8 | #define __CPU_H |
| 9 | |
| 10 | /** |
| 11 | * struct cpu_platdata - platform data for a CPU |
Mario Six | 50d188b | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 12 | * @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 Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 17 | * |
| 18 | * This can be accessed with dev_get_parent_platdata() for any UCLASS_CPU |
| 19 | * device. |
Simon Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 20 | */ |
| 21 | struct cpu_platdata { |
| 22 | int cpu_id; |
Simon Glass | 740d5d3 | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 23 | int ucode_version; |
| 24 | ulong device_id; |
Mario Six | 50d188b | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 25 | u16 family; |
| 26 | u32 id[2]; |
Simon Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | /* CPU features - mostly just a placeholder for now */ |
| 30 | enum { |
| 31 | CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */ |
| 32 | CPU_FEAT_MMU = 1, /* Supports virtual memory */ |
Simon Glass | 740d5d3 | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 33 | CPU_FEAT_UCODE = 2, /* Requires/uses microcode */ |
| 34 | CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */ |
Simon Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 35 | |
| 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 | */ |
| 45 | struct cpu_info { |
| 46 | ulong cpu_freq; |
| 47 | ulong features; |
| 48 | }; |
| 49 | |
| 50 | struct 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 Meng | 780bfdd | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 69 | |
| 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 Graf | 94eaa79 | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 77 | |
| 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 Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 87 | }; |
| 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 Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 93 | * @dev: Device to check (UCLASS_CPU) |
| 94 | * @buf: Buffer to place string |
| 95 | * @size: Size of string space |
Mario Six | 50d188b | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 96 | * |
| 97 | * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
Simon Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 98 | */ |
| 99 | int cpu_get_desc(struct udevice *dev, char *buf, int size); |
| 100 | |
| 101 | /** |
| 102 | * cpu_get_info() - Get information about a CPU |
Simon Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 103 | * @dev: Device to check (UCLASS_CPU) |
| 104 | * @info: Returns CPU info |
Mario Six | 50d188b | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 105 | * |
| 106 | * Return: 0 if OK, -ve on error |
Simon Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 107 | */ |
| 108 | int cpu_get_info(struct udevice *dev, struct cpu_info *info); |
| 109 | |
Bin Meng | 780bfdd | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 110 | /** |
| 111 | * cpu_get_count() - Get number of CPUs |
Bin Meng | 780bfdd | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 112 | * @dev: Device to check (UCLASS_CPU) |
Mario Six | 50d188b | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 113 | * |
| 114 | * Return: CPU count if OK, -ve on error |
Bin Meng | 780bfdd | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 115 | */ |
| 116 | int cpu_get_count(struct udevice *dev); |
| 117 | |
Alexander Graf | 94eaa79 | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 118 | /** |
| 119 | * cpu_get_vendor() - Get vendor name of a CPU |
Alexander Graf | 94eaa79 | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 120 | * @dev: Device to check (UCLASS_CPU) |
| 121 | * @buf: Buffer to place string |
| 122 | * @size: Size of string space |
Mario Six | 50d188b | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 123 | * |
| 124 | * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
Alexander Graf | 94eaa79 | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 125 | */ |
| 126 | int cpu_get_vendor(struct udevice *dev, char *buf, int size); |
| 127 | |
Mario Six | 57370de | 2018-08-06 10:23:43 +0200 | [diff] [blame] | 128 | /** |
| 129 | * cpu_probe_all() - Probe all available CPUs |
| 130 | * |
| 131 | * Return: 0 if OK, -ve on error |
| 132 | */ |
| 133 | int cpu_probe_all(void); |
| 134 | |
Simon Glass | 11f4dc1 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 135 | #endif |