cpu.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (C) 2015, Miao Yan <yanmiaobest@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. #include <asm/fw_cfg.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. int cpu_qemu_bind(struct udevice *dev)
  14. {
  15. struct cpu_platdata *plat = dev_get_parent_platdata(dev);
  16. plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
  17. "intel,apic-id", -1);
  18. return 0;
  19. }
  20. int cpu_qemu_get_desc(struct udevice *dev, char *buf, int size)
  21. {
  22. if (size < CPU_MAX_NAME_LEN)
  23. return -ENOSPC;
  24. cpu_get_name(buf);
  25. return 0;
  26. }
  27. static int cpu_qemu_get_count(struct udevice *dev)
  28. {
  29. return qemu_fwcfg_online_cpus();
  30. }
  31. static const struct cpu_ops cpu_qemu_ops = {
  32. .get_desc = cpu_qemu_get_desc,
  33. .get_count = cpu_qemu_get_count,
  34. };
  35. static const struct udevice_id cpu_qemu_ids[] = {
  36. { .compatible = "cpu-qemu" },
  37. { }
  38. };
  39. U_BOOT_DRIVER(cpu_qemu_drv) = {
  40. .name = "cpu_qemu",
  41. .id = UCLASS_CPU,
  42. .of_match = cpu_qemu_ids,
  43. .bind = cpu_qemu_bind,
  44. .ops = &cpu_qemu_ops,
  45. };