From patchwork Thu Dec 31 02:55:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Yan X-Patchwork-Id: 561830 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id D0646140BA3 for ; Thu, 31 Dec 2015 13:56:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=PF9/NxtF; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 377894BAA8; Thu, 31 Dec 2015 03:55:54 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WNTzDoArGySF; Thu, 31 Dec 2015 03:55:54 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B47594BAAC; Thu, 31 Dec 2015 03:55:42 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BFF094BA2C for ; Thu, 31 Dec 2015 03:55:37 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s9I_S0QQdDdl for ; Thu, 31 Dec 2015 03:55:37 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by theia.denx.de (Postfix) with ESMTPS id 3322D4BA1E for ; Thu, 31 Dec 2015 03:55:32 +0100 (CET) Received: by mail-pa0-f43.google.com with SMTP id yy13so53631154pab.3 for ; Wed, 30 Dec 2015 18:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1GYG6cp0tlRGu+MKGDTm6WnvAAW+LkcQsjIM4jXufR4=; b=PF9/NxtFgM0SlGWfQ+QtwOV3XEYQe1Yo714aByqYIDlj/zYmfK8TAanBoLvJITfAIr RbzIhqOuHH3eDl2kTmCWFEwXbhdBLZMP/oNGMdT8ZcUPoxW/mjZ3Yve161jhJAePfRHh bweiU7f90/zi9GpT4IJBmvrr8qY4fY1mc18FdQeu69Ee9aHYcEpfNxJMTO1EDRb1CilN yRNnPFhsy9Kjt1kO41lsaOGxaw9e3dSHiNEU6EpXbIcDiW0aHDEDcPp8p25wZXShtSUK IPJxfSehAePix1VNrWkWhIEbCAjKXU5pmn7fUFldgjC2aZhKYBn1j81/REqjF9bcvxFJ 4WBw== X-Received: by 10.66.102.8 with SMTP id fk8mr30212563pab.24.1451530531467; Wed, 30 Dec 2015 18:55:31 -0800 (PST) Received: from pa-dbc1131.eng.vmware.com ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id 7sm92818872pfb.62.2015.12.30.18.55.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Dec 2015 18:55:30 -0800 (PST) From: Miao Yan To: u-boot@lists.denx.de, bmeng.cn@gmail.com, sjg@chromium.org Date: Wed, 30 Dec 2015 18:55:19 -0800 Message-Id: <1451530525-30913-3-git-send-email-yanmiaobest@gmail.com> X-Mailer: git-send-email 2.6.3.444.gfd13a2e In-Reply-To: <1451530525-30913-1-git-send-email-yanmiaobest@gmail.com> References: <1451530525-30913-1-git-send-email-yanmiaobest@gmail.com> Subject: [U-Boot] [PATCH v4 2/8] x86: qemu: add a cpu uclass driver for qemu target X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add a cpu uclass driver for qemu. Previously, the qemu target gets cpu number from board dts files, which are manually created at compile time. This does not scale when more cpus are assigned to guest as the dts files must be modified as well. This patch adds a cpu uclass driver for qemu targets to directly read online cpu number from firmware. Signed-off-by: Reviewed-by: Simon Glass Reviewed-by: Bin Meng --- arch/x86/cpu/qemu/Makefile | 2 +- arch/x86/cpu/qemu/cpu.c | 57 ++++++++++++++++++++++++++++++++++++++++ arch/x86/dts/qemu-x86_i440fx.dts | 4 +-- arch/x86/dts/qemu-x86_q35.dts | 4 +-- 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 arch/x86/cpu/qemu/cpu.c diff --git a/arch/x86/cpu/qemu/Makefile b/arch/x86/cpu/qemu/Makefile index ad424ec..027a12f 100644 --- a/arch/x86/cpu/qemu/Makefile +++ b/arch/x86/cpu/qemu/Makefile @@ -7,5 +7,5 @@ ifndef CONFIG_EFI_STUB obj-y += car.o dram.o endif -obj-y += qemu.o fw_cfg.o +obj-y += qemu.o fw_cfg.o cpu.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o dsdt.o diff --git a/arch/x86/cpu/qemu/cpu.c b/arch/x86/cpu/qemu/cpu.c new file mode 100644 index 0000000..9bf9a7c --- /dev/null +++ b/arch/x86/cpu/qemu/cpu.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2015, Miao Yan + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include "fw_cfg.h" + +DECLARE_GLOBAL_DATA_PTR; + +int cpu_qemu_bind(struct udevice *dev) +{ + struct cpu_platdata *plat = dev_get_parent_platdata(dev); + + plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev->of_offset, + "intel,apic-id", -1); + + return 0; +} + +int cpu_qemu_get_desc(struct udevice *dev, char *buf, int size) +{ + if (size < CPU_MAX_NAME_LEN) + return -ENOSPC; + + cpu_get_name(buf); + + return 0; +} + +static int cpu_qemu_get_count(struct udevice *dev) +{ + return qemu_fwcfg_online_cpus(); +} + +static const struct cpu_ops cpu_qemu_ops = { + .get_desc = cpu_qemu_get_desc, + .get_count = cpu_qemu_get_count, +}; + +static const struct udevice_id cpu_qemu_ids[] = { + { .compatible = "cpu-qemu" }, + { } +}; + +U_BOOT_DRIVER(cpu_qemu_drv) = { + .name = "cpu_qemu", + .id = UCLASS_CPU, + .of_match = cpu_qemu_ids, + .bind = cpu_qemu_bind, + .ops = &cpu_qemu_ops, +}; diff --git a/arch/x86/dts/qemu-x86_i440fx.dts b/arch/x86/dts/qemu-x86_i440fx.dts index 8a06229..4332204 100644 --- a/arch/x86/dts/qemu-x86_i440fx.dts +++ b/arch/x86/dts/qemu-x86_i440fx.dts @@ -32,14 +32,14 @@ cpu@0 { device_type = "cpu"; - compatible = "cpu-x86"; + compatible = "cpu-qemu"; reg = <0>; intel,apic-id = <0>; }; cpu@1 { device_type = "cpu"; - compatible = "cpu-x86"; + compatible = "cpu-qemu"; reg = <1>; intel,apic-id = <1>; }; diff --git a/arch/x86/dts/qemu-x86_q35.dts b/arch/x86/dts/qemu-x86_q35.dts index 0b685c8..3e2cfac 100644 --- a/arch/x86/dts/qemu-x86_q35.dts +++ b/arch/x86/dts/qemu-x86_q35.dts @@ -43,14 +43,14 @@ cpu@0 { device_type = "cpu"; - compatible = "cpu-x86"; + compatible = "cpu-qemu"; reg = <0>; intel,apic-id = <0>; }; cpu@1 { device_type = "cpu"; - compatible = "cpu-x86"; + compatible = "cpu-qemu"; reg = <1>; intel,apic-id = <1>; };