From patchwork Wed Aug 21 08:17:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andes X-Patchwork-Id: 1150686 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=andestech.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46D0zf1NSmz9sBp for ; Wed, 21 Aug 2019 18:23:26 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D2A0AC21C2C; Wed, 21 Aug 2019 08:23:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=RDNS_DYNAMIC autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0B446C21F77; Wed, 21 Aug 2019 08:23:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C2B0EC21C2C; Wed, 21 Aug 2019 08:23:18 +0000 (UTC) Received: from ATCSQR.andestech.com (59-120-53-16.HINET-IP.hinet.net [59.120.53.16]) by lists.denx.de (Postfix) with ESMTPS id 6FD64C21F77 for ; Wed, 21 Aug 2019 08:23:17 +0000 (UTC) Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id x7L8AmKO097548; Wed, 21 Aug 2019 16:10:48 +0800 (GMT-8) (envelope-from uboot@andestech.com) Received: from app09.andestech.com (10.0.15.117) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Wed, 21 Aug 2019 16:22:49 +0800 From: Andes To: Date: Wed, 21 Aug 2019 16:17:04 +0800 Message-ID: <20190821081704.13785-1-uboot@andestech.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-Originating-IP: [10.0.15.117] X-DNSRBL: X-MAIL: ATCSQR.andestech.com x7L8AmKO097548 Cc: rickchen36@gmail.com, kclin@andestech.com Subject: [U-Boot] [PATCH 1/3] riscv: andes_plic: init plic by scanning each cpu node X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" From: Rick Chen Initialize plic driver by ofnode_for_each_subnode() instead of cpu_get_count(). This way can support to skip some harts which maybe mark as unavailable, but the cpu node exist indeed. Signed-off-by: Rick Chen Cc: KC Lin --- arch/riscv/lib/andes_plic.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/arch/riscv/lib/andes_plic.c b/arch/riscv/lib/andes_plic.c index 2ffe49a..28568e4 100644 --- a/arch/riscv/lib/andes_plic.c +++ b/arch/riscv/lib/andes_plic.c @@ -44,15 +44,12 @@ static int init_plic(void); } \ } while (0) -static int enable_ipi(int harts) +static int enable_ipi(int hart) { - int i; - int en = ENABLE_HART_IPI; + int en; - for (i = 0; i < harts; i++) { - en = en >> i; - writel(en, (void __iomem *)ENABLE_REG(gd->arch.plic, i)); - } + en = ENABLE_HART_IPI >> hart; + writel(en, (void __iomem *)ENABLE_REG(gd->arch.plic, hart)); return 0; } @@ -60,18 +57,35 @@ static int enable_ipi(int harts) static int init_plic(void) { struct udevice *dev; + ofnode node; int ret; + u32 reg; ret = uclass_find_first_device(UCLASS_CPU, &dev); if (ret) return ret; if (ret == 0 && dev) { - ret = cpu_get_count(dev); - if (ret < 0) - return ret; + ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) { + const char *device_type; + + device_type = ofnode_read_string(node, "device_type"); + if (!device_type) + continue; + + if (strcmp(device_type, "cpu")) + continue; + + /* skip if hart is marked as not available */ + if (!ofnode_is_available(node)) + continue; + + /* read hart ID of CPU */ + ret = ofnode_read_u32(node, "reg", ®); + if (ret == 0) + enable_ipi(reg); + } - enable_ipi(ret); return 0; }