From patchwork Thu Jan 7 09:32:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Yan X-Patchwork-Id: 564221 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 55BB81402B4 for ; Thu, 7 Jan 2016 20:34:02 +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=rZs+qhxw; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8CEC74B9BD; Thu, 7 Jan 2016 10:33:25 +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 eMSC08FjSNjl; Thu, 7 Jan 2016 10:33:25 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5F70E4B98F; Thu, 7 Jan 2016 10:33:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EE7244B976 for ; Thu, 7 Jan 2016 10:33:06 +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 Wu_nqwkjEetN for ; Thu, 7 Jan 2016 10:33:06 +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-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by theia.denx.de (Postfix) with ESMTPS id 202B94B873 for ; Thu, 7 Jan 2016 10:32:58 +0100 (CET) Received: by mail-pa0-f52.google.com with SMTP id cy9so254512394pac.0 for ; Thu, 07 Jan 2016 01:32:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=otanpazalxROLIcUPpshJuyoOJ3sJ3f69OlHcy7tBJA=; b=rZs+qhxwDkz80beUo8539nm0ChSGCnUBUd/g85LIx8Tn6WupVtJEYoBerZb7KIYURK 8CxJBydx5+4ro4I2iMaKLpptH7pSxREdVA7YPnmp32M5Co4ZMIYcsil1y6WjIo8nd/QI AcKVh4AU4PUx1qkGnAm+xCVyro9QIUlP3nKKDre0Yd+ojmiI2yfiHLLnOpwixlUfuNsU BdU4j69tUa4yoCnLZz38DoRVDdvhbSVQdeM8EnwAx9u/igICIowaP5ryMmJcq/fAFktB 7n0v2pGVT2o74jlMdCjhPFrKRga113IKvl7XYzYThlgoSBiAzKTSeCt3D+pqTz/hhuLD iZ6Q== X-Received: by 10.66.197.131 with SMTP id iu3mr129179066pac.57.1452159177175; Thu, 07 Jan 2016 01:32:57 -0800 (PST) Received: from pa-dbc1131.eng.vmware.com ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id qy3sm15919642pab.39.2016.01.07.01.32.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Jan 2016 01:32:55 -0800 (PST) From: Miao Yan To: u-boot@lists.denx.de, sjg@chromium.org, bmeng.cn@gmail.com Date: Thu, 7 Jan 2016 01:32:04 -0800 Message-Id: <1452159126-22877-7-git-send-email-yanmiaobest@gmail.com> X-Mailer: git-send-email 2.6.3.444.gfd13a2e In-Reply-To: <1452159126-22877-1-git-send-email-yanmiaobest@gmail.com> References: <1452159126-22877-1-git-send-email-yanmiaobest@gmail.com> Subject: [U-Boot] [PATCH v6 6/8] x86: qemu: fix cpu device in smp boot 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" Currently, when booting with more that one CPU enabled, U-Boot scans 'cpu' node in device tree and calculates CPU number. This does not scale well as changing CPU number also requires modifying .dts and re-compiling U-Boot. This patch uses fw_cfg interface provided by QEMU to detect online CPU number at runtime, and dynamically adds 'cpu' device to U-Boot's driver model. Signed-off-by: Miao Yan Reviewed-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- Changes in v6: - remove cpu_qemu_bind arch/x86/cpu/mp_init.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/cpu/qemu/cpu.c | 11 -------- 2 files changed, 72 insertions(+), 11 deletions(-) diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c index 2a3ce48..7917350 100644 --- a/arch/x86/cpu/mp_init.c +++ b/arch/x86/cpu/mp_init.c @@ -20,8 +20,11 @@ #include #include #include +#include #include #include +#include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -441,6 +444,69 @@ static int init_bsp(struct udevice **devp) return 0; } +#ifdef CONFIG_QEMU +static int qemu_cpu_fixup(void) +{ + int ret; + int cpu_num; + int cpu_online; + struct udevice *dev, *pdev; + struct cpu_platdata *plat; + char *cpu; + + /* first we need to find '/cpus' */ + for (device_find_first_child(dm_root(), &pdev); + pdev; + device_find_next_child(&pdev)) { + if (!strcmp(pdev->name, "cpus")) + break; + } + if (!pdev) { + printf("unable to find cpus device\n"); + return -ENODEV; + } + + /* calculate cpus that are already bound */ + cpu_num = 0; + for (uclass_find_first_device(UCLASS_CPU, &dev); + dev; + uclass_find_next_device(&dev)) { + cpu_num++; + } + + /* get actual cpu number */ + cpu_online = qemu_fwcfg_online_cpus(); + if (cpu_online < 0) { + printf("unable to get online cpu number: %d\n", cpu_online); + return cpu_online; + } + + /* bind addtional cpus */ + dev = NULL; + for (; cpu_num < cpu_online; cpu_num++) { + /* + * allocate device name here as device_bind_driver() does + * not copy device name, 8 bytes are enough for + * sizeof("cpu@") + 3 digits cpu number + '\0' + */ + cpu = malloc(8); + if (!cpu) { + printf("unable to allocate device name\n"); + return -ENOMEM; + } + sprintf(cpu, "cpu@%d", cpu_num); + ret = device_bind_driver(pdev, "cpu_qemu", cpu, &dev); + if (ret) { + printf("binding cpu@%d failed: %d\n", cpu_num, ret); + return ret; + } + plat = dev_get_parent_platdata(dev); + plat->cpu_id = cpu_num; + } + return 0; +} +#endif + int mp_init(struct mp_params *p) { int num_aps; @@ -454,6 +520,12 @@ int mp_init(struct mp_params *p) if (ret) return ret; +#ifdef CONFIG_QEMU + ret = qemu_cpu_fixup(); + if (ret) + return ret; +#endif + ret = init_bsp(&cpu); if (ret) { debug("Cannot init boot CPU: err=%d\n", ret); diff --git a/arch/x86/cpu/qemu/cpu.c b/arch/x86/cpu/qemu/cpu.c index a4bf53d..a1b70c6 100644 --- a/arch/x86/cpu/qemu/cpu.c +++ b/arch/x86/cpu/qemu/cpu.c @@ -13,16 +13,6 @@ 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) @@ -52,6 +42,5 @@ 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, };