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 |
| 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 Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 17 | * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 18 | */ |
| 19 | struct cpu_platdata { |
| 20 | int cpu_id; |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 21 | int ucode_version; |
| 22 | ulong device_id; |
Alexander Graf | 00b4fc2 | 2016-08-19 01:23:26 +0200 | [diff] [blame] | 23 | u16 family; /* DMTF CPU Family */ |
| 24 | u32 id[2]; /* DMTF CPU Processor IDs */ |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | /* CPU features - mostly just a placeholder for now */ |
| 28 | enum { |
| 29 | CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */ |
| 30 | CPU_FEAT_MMU = 1, /* Supports virtual memory */ |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 31 | CPU_FEAT_UCODE = 2, /* Requires/uses microcode */ |
| 32 | CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */ |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 33 | |
| 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 | */ |
| 43 | struct cpu_info { |
| 44 | ulong cpu_freq; |
| 45 | ulong features; |
| 46 | }; |
| 47 | |
| 48 | struct 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 Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 67 | |
| 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 Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 75 | |
| 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 Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 85 | }; |
| 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 | */ |
| 97 | int 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 | */ |
| 106 | int cpu_get_info(struct udevice *dev, struct cpu_info *info); |
| 107 | |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 108 | /** |
| 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 | */ |
| 114 | int cpu_get_count(struct udevice *dev); |
| 115 | |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 116 | /** |
| 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 | */ |
| 124 | int cpu_get_vendor(struct udevice *dev, char *buf, int size); |
| 125 | |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 126 | #endif |