Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp995577pxa; Fri, 28 Aug 2020 00:11:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzda1Ddkp68Rm4v+zol4RgDjLyNLIZoBD8MBaHKzvB+wbatTIJ4lB8mMgqk5NvZoHZOZB4 X-Received: by 2002:a05:6402:342:: with SMTP id r2mr446136edw.353.1598598663725; Fri, 28 Aug 2020 00:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598598663; cv=none; d=google.com; s=arc-20160816; b=oK5QB6rH4Nx3jCq4VBqQsmocE+BuqOKMApsXB/EEhnKCK2nhUD3F5MOpodtsNL/kTi YV067ssvUtsThztAUeKqBdOsSPBoj5BHKIAx6MYAtbzR6btMUp2H+RJt1SLSFIC6aI8F rh8CvB0kUNSHlReMAOPSoN3ps9R4xp9aS/EZLzkFBC5IZewGrrNmUNiPKGCy1pXISV4p /ww3I8jYMgXxG9lfDIkSm5H/vjaR1u0dus1Cl1kQKYbuD9rNZ9tZictr2na61YN0bzuW zeRp/AWASolMFw6wHS3erYXpOGJCoB0UU8YgDETi/omNEPzFzSjqhewgQiCuPGRh5OUs mqBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mKMjaK4PJ2ikiw6P6/95F1RDaOcuUp3p/mM1whWPxCo=; b=tf+giOjboGm9mj3Nzdfj/XgHs+jTCNlY0q+LhjIp+qlVGV/gLqW6qCURzfHSvVMa7x fAV4q99j+SM5xSiTzsE3kHgqMvC237Ctv3TPcKjq+5udTkQMwYBRWLkc7XyYwxljDSG2 39r7dBnFs9OPRMBCWgrJuHuemVAArNHgtOQk8tYAaC9AfJfoYVcy+yKtv2F6V1p/PJig MeTURq8YaSDB7EP9zy1p+u1i//ye8aX+jusnuf2bV8ExjEjfWNfwALTZVbyv9SpbPysI tAPwFlW8RnCjKHV3NtztuJoVW+Ow96OBYSixZHbf2u9ETICS7BZwRdTfBcwb3K2T+x9w sjTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=ghhlv7BF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a29si28836edj.418.2020.08.28.00.10.41; Fri, 28 Aug 2020 00:11:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=ghhlv7BF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728469AbgH1HJQ (ORCPT + 99 others); Fri, 28 Aug 2020 03:09:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728458AbgH1HJN (ORCPT ); Fri, 28 Aug 2020 03:09:13 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 562A2C061264 for ; Fri, 28 Aug 2020 00:09:13 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id i10so36254pgk.1 for ; Fri, 28 Aug 2020 00:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mKMjaK4PJ2ikiw6P6/95F1RDaOcuUp3p/mM1whWPxCo=; b=ghhlv7BFn+CoyJ/qpWLxPvcAdjBob84a1v1bEie4PmjELr4jDJpKD189uiP+PiSeUM dn4BkGa8PD6RZ5SMdrACxOlfdAE2inOoTptwUtEDwcgpMTd4c878Ef6yGb+UPioaUQHW V+YTVZ6b2FKID7CRLzrNaXrXzLAMmtJWFgU/r7AWLbRNpoKfwJgtBvy1QoGc/kE6bNfL EJhJfTNsUAezTtl3mQzj+8g8SiHkUKfmrYVwzp4HomPA6eoem+IxfOJufXvT05T/tBzG 6uRVhuBGmRWU4ju32MEPHWmakv5hIvz/r9S0YbJKLaxNkSWjmV1SljyJ8lNy6xNTcTQ6 LnVw== 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=mKMjaK4PJ2ikiw6P6/95F1RDaOcuUp3p/mM1whWPxCo=; b=tNjHUtRog9m1nbdTEXmIZXvfAjh0MvDwbbyLH/MdxncQl6spbAiol9hwe4VfMWWMld 82mvzK5i/JyvJOuVHEP0fGJFb4Y7qH0Y+0SXr8Jg1s/On8jn5Slkzo9uqqIjPPvUOUlj wDXF79dY/ghQ2SRShuGPO2GzxVyZ3fRwF2r+amcsMQSjVzgsUbyHT1W+qZuV5NS+JxcC bOOQYcHn25XGPKK7aG+z7rS53OSuIMnCQ28TSRLg966Q4CCJKSe6+u1zrow02xXRAQqn BtfdCgBis1pYE3XA80bZZBrWDK4GM7B/23cedE2zRsPvfxFuUIiqRGOIN+Kc3FSdg1nb A9ig== X-Gm-Message-State: AOAM532DDaD9f+1cFSGhGbNacTLkb2+iy4s7+NdYEn2wIcmEfzfdsk3v 1oaAlyRpKcDbF92L4z6kSl+aSsIxafUVlA== X-Received: by 2002:a63:c30b:: with SMTP id c11mr252351pgd.252.1598598552858; Fri, 28 Aug 2020 00:09:12 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id b8sm434158pfp.48.2020.08.28.00.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2020 00:09:12 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, david.abdurachmanov@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH v3 1/3] riscv: Set more data to cacheinfo Date: Fri, 28 Aug 2020 15:09:05 +0800 Message-Id: <3f1f693147f0b62f19f4a44b8e8ef3d5bde23352.1598598459.git.zong.li@sifive.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Set cacheinfo.{size,sets,line_size} for each cache node, then we can get these information from userland through auxiliary vector. Signed-off-by: Zong Li --- arch/riscv/kernel/cacheinfo.c | 59 ++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/arch/riscv/kernel/cacheinfo.c b/arch/riscv/kernel/cacheinfo.c index bd0f122965c3..8b85abfbd77a 100644 --- a/arch/riscv/kernel/cacheinfo.c +++ b/arch/riscv/kernel/cacheinfo.c @@ -25,12 +25,46 @@ cache_get_priv_group(struct cacheinfo *this_leaf) return NULL; } -static void ci_leaf_init(struct cacheinfo *this_leaf, - struct device_node *node, - enum cache_type type, unsigned int level) +static void ci_leaf_init(struct cacheinfo *this_leaf, enum cache_type type, + unsigned int level, unsigned int size, + unsigned int sets, unsigned int line_size) { this_leaf->level = level; this_leaf->type = type; + this_leaf->size = size; + this_leaf->number_of_sets = sets; + this_leaf->coherency_line_size = line_size; + + /* + * If the cache is fully associative, there is no need to + * check the other properties. + */ + if (!(sets == 1) && (sets > 0 && size > 0 && line_size > 0)) + this_leaf->ways_of_associativity = (size / sets) / line_size; +} + +static void fill_cacheinfo(struct cacheinfo **this_leaf, + struct device_node *node, unsigned int level) +{ + unsigned int size, sets, line_size; + + if (!of_property_read_u32(node, "cache-size", &size) && + !of_property_read_u32(node, "cache-block-size", &line_size) && + !of_property_read_u32(node, "cache-sets", &sets)) { + ci_leaf_init((*this_leaf)++, CACHE_TYPE_UNIFIED, level, size, sets, line_size); + } + + if (!of_property_read_u32(node, "i-cache-size", &size) && + !of_property_read_u32(node, "i-cache-sets", &sets) && + !of_property_read_u32(node, "i-cache-block-size", &line_size)) { + ci_leaf_init((*this_leaf)++, CACHE_TYPE_INST, level, size, sets, line_size); + } + + if (!of_property_read_u32(node, "d-cache-size", &size) && + !of_property_read_u32(node, "d-cache-sets", &sets) && + !of_property_read_u32(node, "d-cache-block-size", &line_size)) { + ci_leaf_init((*this_leaf)++, CACHE_TYPE_DATA, level, size, sets, line_size); + } } static int __init_cache_level(unsigned int cpu) @@ -83,29 +117,24 @@ static int __populate_cache_leaves(unsigned int cpu) struct device_node *prev = NULL; int levels = 1, level = 1; - if (of_property_read_bool(np, "cache-size")) - ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level); - if (of_property_read_bool(np, "i-cache-size")) - ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level); - if (of_property_read_bool(np, "d-cache-size")) - ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level); + /* Level 1 caches in cpu node */ + fill_cacheinfo(&this_leaf, np, level); + /* Next level caches in cache nodes */ prev = np; while ((np = of_find_next_cache_node(np))) { of_node_put(prev); prev = np; + if (!of_device_is_compatible(np, "cache")) break; if (of_property_read_u32(np, "cache-level", &level)) break; if (level <= levels) break; - if (of_property_read_bool(np, "cache-size")) - ci_leaf_init(this_leaf++, np, CACHE_TYPE_UNIFIED, level); - if (of_property_read_bool(np, "i-cache-size")) - ci_leaf_init(this_leaf++, np, CACHE_TYPE_INST, level); - if (of_property_read_bool(np, "d-cache-size")) - ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level); + + fill_cacheinfo(&this_leaf, np, level); + levels = level; } of_node_put(np); -- 2.28.0