Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Miao Yan | 4336af6 | 2016-01-07 01:32:01 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Miao Yan <yanmiaobest@gmail.com> |
Miao Yan | 4336af6 | 2016-01-07 01:32:01 -0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <cpu.h> |
| 8 | #include <dm.h> |
| 9 | #include <errno.h> |
Miao Yan | 9210627 | 2016-05-22 19:37:17 -0700 | [diff] [blame] | 10 | #include <qfw.h> |
Miao Yan | 4336af6 | 2016-01-07 01:32:01 -0800 | [diff] [blame] | 11 | #include <asm/cpu.h> |
Miao Yan | 4336af6 | 2016-01-07 01:32:01 -0800 | [diff] [blame] | 12 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 13 | int cpu_qemu_get_desc(const struct udevice *dev, char *buf, int size) |
Miao Yan | 4336af6 | 2016-01-07 01:32:01 -0800 | [diff] [blame] | 14 | { |
| 15 | if (size < CPU_MAX_NAME_LEN) |
| 16 | return -ENOSPC; |
| 17 | |
| 18 | cpu_get_name(buf); |
| 19 | |
| 20 | return 0; |
| 21 | } |
| 22 | |
Simon Glass | 791fa45 | 2020-01-26 22:06:27 -0700 | [diff] [blame] | 23 | static int cpu_qemu_get_count(const struct udevice *dev) |
Miao Yan | 4336af6 | 2016-01-07 01:32:01 -0800 | [diff] [blame] | 24 | { |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 25 | int ret; |
| 26 | struct udevice *qfw_dev; |
| 27 | |
| 28 | ret = qfw_get_dev(&qfw_dev); |
| 29 | if (ret) |
| 30 | return ret; |
| 31 | |
| 32 | return qfw_online_cpus(qfw_dev); |
Miao Yan | 4336af6 | 2016-01-07 01:32:01 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static const struct cpu_ops cpu_qemu_ops = { |
| 36 | .get_desc = cpu_qemu_get_desc, |
| 37 | .get_count = cpu_qemu_get_count, |
| 38 | }; |
| 39 | |
| 40 | static const struct udevice_id cpu_qemu_ids[] = { |
| 41 | { .compatible = "cpu-qemu" }, |
| 42 | { } |
| 43 | }; |
| 44 | |
| 45 | U_BOOT_DRIVER(cpu_qemu_drv) = { |
| 46 | .name = "cpu_qemu", |
| 47 | .id = UCLASS_CPU, |
| 48 | .of_match = cpu_qemu_ids, |
Miao Yan | 4336af6 | 2016-01-07 01:32:01 -0800 | [diff] [blame] | 49 | .ops = &cpu_qemu_ops, |
| 50 | }; |