cpu.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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)(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)(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)(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)(struct udevice *dev, char *buf, int size);
  83. };
  84. #define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops)
  85. /**
  86. * cpu_get_desc() - Get a description string for a CPU
  87. * @dev: Device to check (UCLASS_CPU)
  88. * @buf: Buffer to place string
  89. * @size: Size of string space
  90. *
  91. * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  92. */
  93. int cpu_get_desc(struct udevice *dev, char *buf, int size);
  94. /**
  95. * cpu_get_info() - Get information about a CPU
  96. * @dev: Device to check (UCLASS_CPU)
  97. * @info: Returns CPU info
  98. *
  99. * Return: 0 if OK, -ve on error
  100. */
  101. int cpu_get_info(struct udevice *dev, struct cpu_info *info);
  102. /**
  103. * cpu_get_count() - Get number of CPUs
  104. * @dev: Device to check (UCLASS_CPU)
  105. *
  106. * Return: CPU count if OK, -ve on error
  107. */
  108. int cpu_get_count(struct udevice *dev);
  109. /**
  110. * cpu_get_vendor() - Get vendor name of a CPU
  111. * @dev: Device to check (UCLASS_CPU)
  112. * @buf: Buffer to place string
  113. * @size: Size of string space
  114. *
  115. * Return: 0 if OK, -ENOSPC if buffer is too small, other -ve on error
  116. */
  117. int cpu_get_vendor(struct udevice *dev, char *buf, int size);
  118. /**
  119. * cpu_probe_all() - Probe all available CPUs
  120. *
  121. * Return: 0 if OK, -ve on error
  122. */
  123. int cpu_probe_all(void);
  124. #endif