cpu_x86.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <cpu.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <asm/cpu.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. int cpu_x86_bind(struct udevice *dev)
  13. {
  14. struct cpu_platdata *plat = dev_get_parent_platdata(dev);
  15. plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
  16. "intel,apic-id", -1);
  17. return 0;
  18. }
  19. int cpu_x86_get_desc(struct udevice *dev, char *buf, int size)
  20. {
  21. if (size < CPU_MAX_NAME_LEN)
  22. return -ENOSPC;
  23. cpu_get_name(buf);
  24. return 0;
  25. }
  26. static int cpu_x86_get_count(struct udevice *dev)
  27. {
  28. int node, cpu;
  29. int num = 0;
  30. node = fdt_path_offset(gd->fdt_blob, "/cpus");
  31. if (node < 0)
  32. return -ENOENT;
  33. for (cpu = fdt_first_subnode(gd->fdt_blob, node);
  34. cpu >= 0;
  35. cpu = fdt_next_subnode(gd->fdt_blob, cpu)) {
  36. const char *device_type;
  37. device_type = fdt_getprop(gd->fdt_blob, cpu,
  38. "device_type", NULL);
  39. if (!device_type)
  40. continue;
  41. if (strcmp(device_type, "cpu") == 0)
  42. num++;
  43. }
  44. return num;
  45. }
  46. static const struct cpu_ops cpu_x86_ops = {
  47. .get_desc = cpu_x86_get_desc,
  48. .get_count = cpu_x86_get_count,
  49. };
  50. static const struct udevice_id cpu_x86_ids[] = {
  51. { .compatible = "cpu-x86" },
  52. { }
  53. };
  54. U_BOOT_DRIVER(cpu_x86_drv) = {
  55. .name = "cpu_x86",
  56. .id = UCLASS_CPU,
  57. .of_match = cpu_x86_ids,
  58. .bind = cpu_x86_bind,
  59. .ops = &cpu_x86_ops,
  60. };