Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 1 | /* |
| 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 Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 18 | * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 19 | */ |
| 20 | struct cpu_platdata { |
| 21 | int cpu_id; |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 22 | int ucode_version; |
| 23 | ulong device_id; |
Alexander Graf | 00b4fc2 | 2016-08-19 01:23:26 +0200 | [diff] [blame] | 24 | u16 family; /* DMTF CPU Family */ |
| 25 | u32 id[2]; /* DMTF CPU Processor IDs */ |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | /* CPU features - mostly just a placeholder for now */ |
| 29 | enum { |
| 30 | CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */ |
| 31 | CPU_FEAT_MMU = 1, /* Supports virtual memory */ |
Simon Glass | 8d374cd | 2016-03-06 19:27:49 -0700 | [diff] [blame] | 32 | CPU_FEAT_UCODE = 2, /* Requires/uses microcode */ |
| 33 | CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */ |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 34 | |
| 35 | CPU_FEAT_COUNT, |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * struct cpu_info - Information about a CPU |
| 40 | * |
| 41 | * @cpu_freq: Current CPU frequency in Hz |
| 42 | * @features: Flags for supported CPU features |
| 43 | */ |
| 44 | struct cpu_info { |
| 45 | ulong cpu_freq; |
| 46 | ulong features; |
| 47 | }; |
| 48 | |
| 49 | struct cpu_ops { |
| 50 | /** |
| 51 | * get_desc() - Get a description string for a CPU |
| 52 | * |
| 53 | * @dev: Device to check (UCLASS_CPU) |
| 54 | * @buf: Buffer to place string |
| 55 | * @size: Size of string space |
| 56 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
| 57 | */ |
| 58 | int (*get_desc)(struct udevice *dev, char *buf, int size); |
| 59 | |
| 60 | /** |
| 61 | * get_info() - Get information about a CPU |
| 62 | * |
| 63 | * @dev: Device to check (UCLASS_CPU) |
| 64 | * @info: Returns CPU info |
| 65 | * @return 0 if OK, -ve on error |
| 66 | */ |
| 67 | int (*get_info)(struct udevice *dev, struct cpu_info *info); |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * get_count() - Get number of CPUs |
| 71 | * |
| 72 | * @dev: Device to check (UCLASS_CPU) |
| 73 | * @return CPU count if OK, -ve on error |
| 74 | */ |
| 75 | int (*get_count)(struct udevice *dev); |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * get_vendor() - Get vendor name of a CPU |
| 79 | * |
| 80 | * @dev: Device to check (UCLASS_CPU) |
| 81 | * @buf: Buffer to place string |
| 82 | * @size: Size of string space |
| 83 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
| 84 | */ |
| 85 | int (*get_vendor)(struct udevice *dev, char *buf, int size); |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | #define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops) |
| 89 | |
| 90 | /** |
| 91 | * cpu_get_desc() - Get a description string for a CPU |
| 92 | * |
| 93 | * @dev: Device to check (UCLASS_CPU) |
| 94 | * @buf: Buffer to place string |
| 95 | * @size: Size of string space |
| 96 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
| 97 | */ |
| 98 | int cpu_get_desc(struct udevice *dev, char *buf, int size); |
| 99 | |
| 100 | /** |
| 101 | * cpu_get_info() - Get information about a CPU |
| 102 | * |
| 103 | * @dev: Device to check (UCLASS_CPU) |
| 104 | * @info: Returns CPU info |
| 105 | * @return 0 if OK, -ve on error |
| 106 | */ |
| 107 | int cpu_get_info(struct udevice *dev, struct cpu_info *info); |
| 108 | |
Bin Meng | d13b014 | 2015-06-17 11:15:34 +0800 | [diff] [blame] | 109 | /** |
| 110 | * cpu_get_count() - Get number of CPUs |
| 111 | * |
| 112 | * @dev: Device to check (UCLASS_CPU) |
| 113 | * @return CPU count if OK, -ve on error |
| 114 | */ |
| 115 | int cpu_get_count(struct udevice *dev); |
| 116 | |
Alexander Graf | 67f66bd | 2016-08-19 01:23:27 +0200 | [diff] [blame] | 117 | /** |
| 118 | * cpu_get_vendor() - Get vendor name of a CPU |
| 119 | * |
| 120 | * @dev: Device to check (UCLASS_CPU) |
| 121 | * @buf: Buffer to place string |
| 122 | * @size: Size of string space |
| 123 | * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error |
| 124 | */ |
| 125 | int cpu_get_vendor(struct udevice *dev, char *buf, int size); |
| 126 | |
Simon Glass | 131a645 | 2015-04-28 20:25:09 -0600 | [diff] [blame] | 127 | #endif |