From patchwork Sat Dec 7 04:42:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1205416 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="DnIr8yYY"; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47VHPM3y1cz9sPL for ; Sat, 7 Dec 2019 16:01:59 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9E8318173A; Sat, 7 Dec 2019 05:54:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="DnIr8yYY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 87A6F81730; Sat, 7 Dec 2019 05:54:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 983A1816F7 for ; Sat, 7 Dec 2019 05:54:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd42.google.com with SMTP id z193so9511810iof.1 for ; Fri, 06 Dec 2019 20:54:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3sHR9w+/fd8+Ux26o9dbxID1Ji73iOYAJ9OMSn0qzp0=; b=DnIr8yYY6rdPOx1rRrZIrEWxa0I2asCf1E654S95BgcRT5FJ6+7WRdVKfFZYe08wZD 1EClF2Oed75H+R4ICF7t/MSFnCBdI538hCVjfZAg54ItnUgBtC5FV2oYl+EJaPRgdtMO MSWq1ljUHvuxIfcDXaZC/pDEQBgofOyWqXlYM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3sHR9w+/fd8+Ux26o9dbxID1Ji73iOYAJ9OMSn0qzp0=; b=Yf9ljtB8F42goXRxBaed3DLSoj0cNZ6RCW/XJPKoPdOMbRnwTzCUaYJrcifGXu37/E nH4Kg/FNmccUlTRdB5nUAPebb+rmfCBMdeMFKFLWjPg+d/IW6kbDqA83osJYp4oESy/0 Z5ViV4l3xnJj2OIERGuipp0u0z60J10tmzrkys66kOHczLOPn9ZPE/+XS2SC35WxRZp7 DrlAwp4C0yAtqCyiO2CMzMzddmGEP5i445csmyTMnz3CqfDBdW7X3vnAXIRtEm/hGgy6 /DCCB1MeUjLQFdC+4vfn7QzAKgZz+nqWOUKoCeWS5+0dS44JNopHjvRU9S11TAA8PYN3 9NJQ== X-Gm-Message-State: APjAAAV/k6gTraKMMNf6zpSUQLSWjxmX2uBYwD9MPDAMaXMSIWLW8aLO lmb9RRH/Go2aUwZ2bzmQWrt146ajagc= X-Google-Smtp-Source: APXvYqxIvV+/CrvzYbcoGs5Iu9f6yltl96c01S7VD50EgxAq38hmFzULV38/ix7yYAgbjCgsBDp5Jg== X-Received: by 2002:a6b:7119:: with SMTP id q25mr12758705iog.148.1575694466347; Fri, 06 Dec 2019 20:54:26 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id o7sm4549410ilo.58.2019.12.06.20.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2019 20:54:26 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH v6 082/102] x86: Move qemu CPU fixup function into its own file Date: Fri, 6 Dec 2019 21:42:55 -0700 Message-Id: <20191206213936.v6.82.Iddc5d65bde090e51864b37fae2900582ef215301@changeid> X-Mailer: git-send-email 2.24.0.393.g34dc348eaf-goog In-Reply-To: <20191207044315.51770-1-sjg@chromium.org> References: <20191207044315.51770-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean This function is specific to qemu so it seems best to keep it separate from the generic code. Move it out to a new file and update the condition to use if() instead of #ifdef Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- Changes in v6: - Add back '#ifdef' line to commit message - Drop incorrect mention of coreboot in qfw_cpu.c Changes in v5: - Add a new patch to move qemu CPU fixup function into its own file Changes in v4: None Changes in v3: None Changes in v2: None arch/x86/cpu/Makefile | 1 + arch/x86/cpu/mp_init.c | 73 +++--------------------------------------- arch/x86/cpu/qfw_cpu.c | 73 ++++++++++++++++++++++++++++++++++++++++++ include/qfw.h | 8 +++++ 4 files changed, 87 insertions(+), 68 deletions(-) create mode 100644 arch/x86/cpu/qfw_cpu.c diff --git a/arch/x86/cpu/Makefile b/arch/x86/cpu/Makefile index b6a010ea32..0e90a38dc5 100644 --- a/arch/x86/cpu/Makefile +++ b/arch/x86/cpu/Makefile @@ -54,6 +54,7 @@ obj-$(CONFIG_INTEL_QUEENSBAY) += queensbay/ obj-$(CONFIG_INTEL_TANGIER) += tangier/ obj-$(CONFIG_APIC) += lapic.o ioapic.o obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += irq.o +obj-$(CONFIG_QFW) += qfw_cpu.o ifndef CONFIG_$(SPL_)X86_64 obj-$(CONFIG_SMP) += mp_init.o endif diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c index fefbf8f728..7b09f90cd5 100644 --- a/arch/x86/cpu/mp_init.c +++ b/arch/x86/cpu/mp_init.c @@ -418,69 +418,6 @@ static int init_bsp(struct udevice **devp) return 0; } -#ifdef CONFIG_QFW -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; @@ -494,11 +431,11 @@ int mp_init(struct mp_params *p) if (ret) return ret; -#ifdef CONFIG_QFW - ret = qemu_cpu_fixup(); - if (ret) - return ret; -#endif + if (IS_ENABLED(CONFIG_QFW)) { + ret = qemu_cpu_fixup(); + if (ret) + return ret; + } ret = init_bsp(&cpu); if (ret) { diff --git a/arch/x86/cpu/qfw_cpu.c b/arch/x86/cpu/qfw_cpu.c new file mode 100644 index 0000000000..49e9dfcf69 --- /dev/null +++ b/arch/x86/cpu/qfw_cpu.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2015 Google, Inc + */ + +#include +#include +#include +#include +#include +#include +#include + +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; +} diff --git a/include/qfw.h b/include/qfw.h index 2f1a20416f..cea8e11d44 100644 --- a/include/qfw.h +++ b/include/qfw.h @@ -172,4 +172,12 @@ bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter); bool qemu_fwcfg_present(void); bool qemu_fwcfg_dma_present(void); +/** + * qemu_cpu_fixup() - Fix up the CPUs for QEMU + * + * @return 0 if OK, -ENODEV if no CPUs, -ENOMEM if out of memory, other -ve on + * on other error + */ +int qemu_cpu_fixup(void); + #endif