Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 131a645 | 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 | 131a645 | 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 | 60ce6dd | 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 |
Bin Meng | b2aa495 | 2018-12-12 06:12:24 -0800 | [diff] [blame] | 17 | * @timebase_freq: the current frequency at which the cpu timer timebase |
| 18 | * registers are updated (in Hz) |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 19 | * |
| 20 | * This can be accessed with dev_get_parent_platdata() for any UCLASS_CPU |
| 21 | * device. |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 22 | */ |
| 23 | struct cpu_platdata { |
| 24 | int cpu_id; |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 25 | int ucode_version; |
| 26 | ulong device_id; |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 27 | u16 family; |
| 28 | u32 id[2]; |
Bin Meng | b2aa495 | 2018-12-12 06:12:24 -0800 | [diff] [blame] | 29 | u32 timebase_freq; |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | /* CPU features - mostly just a placeholder for now */ |
| 33 | enum { |
| 34 | CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */ |
| 35 | CPU_FEAT_MMU = 1, /* Supports virtual memory */ |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 36 | CPU_FEAT_UCODE = 2, /* Requires/uses microcode */ |
| 37 | CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */ |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 38 | |
| 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 |
Simon Glass | c35854a | 2020-04-08 16:57:20 -0600 | [diff] [blame] | 47 | * @address_width: Width of the CPU address space in bits (e.g. 32) |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 48 | */ |
| 49 | struct cpu_info { |
| 50 | ulong cpu_freq; |
| 51 | ulong features; |
Simon Glass | c35854a | 2020-04-08 16:57:20 -0600 | [diff] [blame] | 52 | uint address_width; |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct cpu_ops { |
| 56 | /** |
| 57 | * get_desc() - Get a description string for a CPU |
| 58 | * |
| 59 | * @dev: Device to check (UCLASS_CPU) |
| 60 | * @buf: Buffer to place string |
| 61 | * @size: Size of string space |
| 62 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
| 63 | */ |
| 64 | int (*get_desc)(struct udevice *dev, char *buf, int size); |
| 65 | |
| 66 | /** |
| 67 | * get_info() - Get information about a CPU |
| 68 | * |
| 69 | * @dev: Device to check (UCLASS_CPU) |
| 70 | * @info: Returns CPU info |
| 71 | * @return 0 if OK, -ve on error |
| 72 | */ |
| 73 | int (*get_info)(struct udevice *dev, struct cpu_info *info); |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * get_count() - Get number of CPUs |
| 77 | * |
| 78 | * @dev: Device to check (UCLASS_CPU) |
| 79 | * @return CPU count if OK, -ve on error |
| 80 | */ |
| 81 | int (*get_count)(struct udevice *dev); |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * get_vendor() - Get vendor name of a CPU |
| 85 | * |
| 86 | * @dev: Device to check (UCLASS_CPU) |
| 87 | * @buf: Buffer to place string |
| 88 | * @size: Size of string space |
| 89 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
| 90 | */ |
| 91 | int (*get_vendor)(struct udevice *dev, char *buf, int size); |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | #define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops) |
| 95 | |
| 96 | /** |
| 97 | * cpu_get_desc() - Get a description string for a CPU |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 98 | * @dev: Device to check (UCLASS_CPU) |
| 99 | * @buf: Buffer to place string |
| 100 | * @size: Size of string space |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 101 | * |
| 102 | * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 103 | */ |
| 104 | int cpu_get_desc(struct udevice *dev, char *buf, int size); |
| 105 | |
| 106 | /** |
| 107 | * cpu_get_info() - Get information about a CPU |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 108 | * @dev: Device to check (UCLASS_CPU) |
| 109 | * @info: Returns CPU info |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 110 | * |
| 111 | * Return: 0 if OK, -ve on error |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 112 | */ |
| 113 | int cpu_get_info(struct udevice *dev, struct cpu_info *info); |
| 114 | |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 115 | /** |
| 116 | * cpu_get_count() - Get number of CPUs |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 117 | * @dev: Device to check (UCLASS_CPU) |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 118 | * |
| 119 | * Return: CPU count if OK, -ve on error |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 120 | */ |
| 121 | int cpu_get_count(struct udevice *dev); |
| 122 | |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 123 | /** |
| 124 | * cpu_get_vendor() - Get vendor name of a CPU |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 125 | * @dev: Device to check (UCLASS_CPU) |
| 126 | * @buf: Buffer to place string |
| 127 | * @size: Size of string space |
Mario Six | 60ce6dd | 2018-08-06 10:23:42 +0200 | [diff] [blame] | 128 | * |
| 129 | * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 130 | */ |
| 131 | int cpu_get_vendor(struct udevice *dev, char *buf, int size); |
| 132 | |
Mario Six | 0263b43 | 2018-08-06 10:23:43 +0200 | [diff] [blame] | 133 | /** |
| 134 | * cpu_probe_all() - Probe all available CPUs |
| 135 | * |
| 136 | * Return: 0 if OK, -ve on error |
| 137 | */ |
| 138 | int cpu_probe_all(void); |
| 139 | |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 140 | #endif |