cpu.h 4.1 KB

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