cpu.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #ifndef __CPU_H
  7. #define __CPU_H
  8. struct udevice;
  9. /**
  10. * struct cpu_plat - platform data for a CPU
  11. * @cpu_id: Platform-specific way of identifying the CPU.
  12. * @ucode_version: Microcode version, if CPU_FEAT_UCODE is set
  13. * @device_id: Driver-defined device identifier
  14. * @family: DMTF CPU Family identifier
  15. * @id: DMTF CPU Processor identifier
  16. * @timebase_freq: the current frequency at which the cpu timer timebase
  17. * registers are updated (in Hz)
  18. *
  19. * This can be accessed with dev_get_parent_plat() for any UCLASS_CPU
  20. * device.
  21. */
  22. struct cpu_plat {
  23. int cpu_id;
  24. int ucode_version;
  25. ulong device_id;
  26. u16 family;
  27. u32 id[2];
  28. u32 timebase_freq;
  29. };
  30. /* CPU features - mostly just a placeholder for now */
  31. enum {
  32. CPU_FEAT_L1_CACHE = 0, /* Supports level 1 cache */
  33. CPU_FEAT_MMU = 1, /* Supports virtual memory */
  34. CPU_FEAT_UCODE = 2, /* Requires/uses microcode */
  35. CPU_FEAT_DEVICE_ID = 3, /* Provides a device ID */
  36. CPU_FEAT_COUNT,
  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. * @address_width: Width of the CPU address space in bits (e.g. 32)
  44. */
  45. struct cpu_info {
  46. ulong cpu_freq;
  47. ulong features;
  48. uint address_width;
  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)(const struct udevice *dev, char *buf, int size);
  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)(const struct udevice *dev, struct cpu_info *info);
  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)(const struct udevice *dev);
  75. /**
  76. * get_vendor() - Get vendor name of a CPU
  77. *
  78. * @dev: Device to check (UCLASS_CPU)
  79. * @buf: Buffer to place string
  80. * @size: Size of string space
  81. * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  82. */
  83. int (*get_vendor)(const struct udevice *dev, char *buf, int size);
  84. /**
  85. * is_current() - Check if the CPU that U-Boot is currently running from
  86. *
  87. * @dev: Device to check (UCLASS_CPU)
  88. * @return 1 if the CPU that U-Boot is currently running from, 0
  89. * if not.
  90. */
  91. int (*is_current)(struct udevice *dev);
  92. };
  93. #define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops)
  94. /**
  95. * cpu_get_desc() - Get a description string for a CPU
  96. * @dev: Device to check (UCLASS_CPU)
  97. * @buf: Buffer to place string
  98. * @size: Size of string space
  99. *
  100. * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  101. */
  102. int cpu_get_desc(const struct udevice *dev, char *buf, int size);
  103. /**
  104. * cpu_get_info() - Get information about a CPU
  105. * @dev: Device to check (UCLASS_CPU)
  106. * @info: Returns CPU info
  107. *
  108. * Return: 0 if OK, -ve on error
  109. */
  110. int cpu_get_info(const struct udevice *dev, struct cpu_info *info);
  111. /**
  112. * cpu_get_count() - Get number of CPUs
  113. * @dev: Device to check (UCLASS_CPU)
  114. *
  115. * Return: CPU count if OK, -ve on error
  116. */
  117. int cpu_get_count(const struct udevice *dev);
  118. /**
  119. * cpu_get_vendor() - Get vendor name of a CPU
  120. * @dev: Device to check (UCLASS_CPU)
  121. * @buf: Buffer to place string
  122. * @size: Size of string space
  123. *
  124. * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  125. */
  126. int cpu_get_vendor(const struct udevice *dev, char *buf, int size);
  127. /**
  128. * cpu_probe_all() - Probe all available CPUs
  129. *
  130. * Return: 0 if OK, -ve on error
  131. */
  132. int cpu_probe_all(void);
  133. /**
  134. * cpu_is_current() - Check if the CPU that U-Boot is currently running from
  135. *
  136. * Return: 1 if yes, - 0 if not
  137. */
  138. int cpu_is_current(struct udevice *cpu);
  139. /**
  140. * cpu_get_current_dev() - Get CPU udevice for current CPU
  141. *
  142. * Return: udevice if OK, - NULL on error
  143. */
  144. struct udevice *cpu_get_current_dev(void);
  145. #endif