Received: by 10.223.164.202 with SMTP id h10csp1599846wrb; Mon, 27 Nov 2017 05:04:33 -0800 (PST) X-Google-Smtp-Source: AGs4zMaeQkdqpkY1TeOkBk+mLASPZw44K7eQg2tkZaFnj79C0vn4uATpueWzTIJNOukAG6531F8R X-Received: by 10.84.174.131 with SMTP id r3mr29524988plb.358.1511787872658; Mon, 27 Nov 2017 05:04:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511787872; cv=none; d=google.com; s=arc-20160816; b=ZD+9LeXWguimrqdzaGy3dj1yNzCPCw5jaPbWBD5AampSHECU+sG/dnO5eAbSrIvNVa hmX4C7q1/FxW4GiPVVFXD9HonxteoQiQ5QDDi6P6s7TmPOf+HjIOBWN2GyZokPoYjWXs PDb54fm4YPdKnODp/go/guqIAxcDN0+88M5FhHvOOw5tyha4mimYX9zNAiuFSu8aWTxq euQpVVe3NL27D7xEzmReB91Yh8up/iwd4BLwSY8EWo8NiFnLv+e24BUUVppNE71nEUtr NjM6xe6RktwUspTm/LVWuJxbUr2SopMaIio8QMEFBV0SZ6i3OUDnXHnTCTq8evSpEAB2 /eLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=IeMQkgFdVEmScXguF/mauV7zZN41+R0GQmzRlyAOEf0=; b=Qt3olNAD5UwT6gVOMdl4PKdpWUJOtxg+qlNKPx6WTXKvsoz9WgE6BtIbIhhiOupGGB tP7F2txBX6usLZN58COMzO33jEaNUC0E0BOxhUCEOY1Nj0OTizRFeaAjDpMkAbA02Vjq ppRDHwW2utsSkUitIIiW0GKj0YWSHterWMEZV5sfj+FZhHt1BkOTZjUPqJT+Kwi/NqdL z+xYQAruauifg5Jc26VWMnc/PX5VI7NsOB9r1NvgnU9jrXYpKlwXKbArVfaPeNFe803o Vni+cz8STUdEYpm1/9R6Feuym53W6vsJfu21csiARXrIxgxncE1qwqTGzZS/DyLPqJV6 U6BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ig1tsK4x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t80si25364958pfg.139.2017.11.27.05.04.19; Mon, 27 Nov 2017 05:04:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ig1tsK4x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752552AbdK0NCf (ORCPT + 77 others); Mon, 27 Nov 2017 08:02:35 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35510 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752128AbdK0Mya (ORCPT ); Mon, 27 Nov 2017 07:54:30 -0500 Received: by mail-pg0-f67.google.com with SMTP id l19so18654477pgo.2; Mon, 27 Nov 2017 04:54:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=IeMQkgFdVEmScXguF/mauV7zZN41+R0GQmzRlyAOEf0=; b=Ig1tsK4xCAHXF3/aoRO6lmnYoRHlbqgBt/eNQ5eXcSc+nTAt35Si9eXHps0XEzHyQW mR9FcBFR7qbTraE7FpEIWRexa+XF2WIQ+JAqAlDv6cob0QzQCH7TQrO8BQA8WofripkX lgBBI/+aeFwTxwCbHBS/HfRTdOOH7VtmWZedKwwErXooX888Op2ptmhO64fUNWk7cF9A TlcNt1PeKwpkFWjwhE2pJhg+QQb0XfR9Yn0MgaB70fsHGBg/Tcb6Mylu0JyeXJxAKvT5 b+i03g2IansCRVJ68wybN+O+FlZ+sXnKBDTMnTCPDal2kZdRHlaQHXGCRn5Cj3sAMxnQ vnSg== 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:in-reply-to:references; bh=IeMQkgFdVEmScXguF/mauV7zZN41+R0GQmzRlyAOEf0=; b=VhI7ifolP6JNYSVGW6tHPDTenhkhKBrCVF4bFLm53cSoa2ZzrCOyV3WI9n1BJETgOk 5FnQjHtxgO8Ozi9+IgYEIZPjhovvGV08GR9v5gnGOOJt1nRKj3/GY9NNLKiFT77uBTqO aSn0VfhkPyMvtHLG0938Qvei/F9vHTL5oU1gXATK5d7JomNdmanE0hYO3eTZVoZAN5YM jzOIqHnbA689Eb5qMVZFcBk/meU5dShdoYBB6lopngeyNuk2wPLYeYIbI1bn9qAOhS31 NxWF7BiAB8ctM7xQnGZkBMzARgoVOtuiQI0Z+VVLWQHQ5wSejYYGvabsuBQ/8O6a2zqF 1xJg== X-Gm-Message-State: AJaThX6vtbbpEru1C3k5Tnlnm1sB3Sfm3UFnOWBl5Iz4C3O1DMvx5POv 9YOgaYhFiiEnaM8S2UwrcBU= X-Received: by 10.98.202.26 with SMTP id n26mr13063341pfg.202.1511787269508; Mon, 27 Nov 2017 04:54:29 -0800 (PST) Received: from app09.andestech.com ([118.163.51.199]) by smtp.gmail.com with ESMTPSA id w64sm55225459pfj.62.2017.11.27.04.54.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2017 04:54:28 -0800 (PST) From: Greentime Hu To: greentime@andestech.com, linux-kernel@vger.kernel.org, arnd@arndb.de, linux-arch@vger.kernel.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, robh+dt@kernel.org, netdev@vger.kernel.org, deanbo422@gmail.com, devicetree@vger.kernel.org, viro@zeniv.linux.org.uk, dhowells@redhat.com, will.deacon@arm.com, daniel.lezcano@linaro.org, linux-serial@vger.kernel.org Cc: green.hu@gmail.com, Vincent Chen Subject: [PATCH v2 19/35] nds32: L2 cache support Date: Mon, 27 Nov 2017 20:28:06 +0800 Message-Id: <380808fe9139e2c3800ae76dfa6aa5cbbbc4894f.1511785528.git.green.hu@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greentime Hu This patch adds L2 cache support. Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu --- arch/nds32/include/asm/l2_cache.h | 155 +++++++++++++++++++++++++++++++++++++ arch/nds32/kernel/atl2c.c | 77 ++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 arch/nds32/include/asm/l2_cache.h create mode 100644 arch/nds32/kernel/atl2c.c diff --git a/arch/nds32/include/asm/l2_cache.h b/arch/nds32/include/asm/l2_cache.h new file mode 100644 index 0000000..8f3ec79 --- /dev/null +++ b/arch/nds32/include/asm/l2_cache.h @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2005-2017 Andes Technology Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef L2_CACHE_H +#define L2_CACHE_H + +/* CCTL_CMD_OP */ +#define L2_CA_CONF_OFF 0x0 +#define L2_IF_CONF_OFF 0x4 +#define L2CC_SETUP_OFF 0x8 +#define L2CC_PROT_OFF 0xC +#define L2CC_CTRL_OFF 0x10 +#define L2_INT_EN_OFF 0x20 +#define L2_STA_OFF 0x24 +#define RDERR_ADDR_OFF 0x28 +#define WRERR_ADDR_OFF 0x2c +#define EVDPTERR_ADDR_OFF 0x30 +#define IMPL3ERR_ADDR_OFF 0x34 +#define L2_CNT0_CTRL_OFF 0x40 +#define L2_EVNT_CNT0_OFF 0x44 +#define L2_CNT1_CTRL_OFF 0x48 +#define L2_EVNT_CNT1_OFF 0x4c +#define L2_CCTL_CMD_OFF 0x60 +#define L2_CCTL_STATUS_OFF 0x64 +#define L2_LINE_TAG_OFF 0x68 +#define L2_LINE_DPT_OFF 0x70 + +#define CCTL_CMD_L2_IX_INVAL 0x0 +#define CCTL_CMD_L2_PA_INVAL 0x1 +#define CCTL_CMD_L2_IX_WB 0x2 +#define CCTL_CMD_L2_PA_WB 0x3 +#define CCTL_CMD_L2_PA_WBINVAL 0x5 +#define CCTL_CMD_L2_SYNC 0xa + +/* CCTL_CMD_TYPE */ +#define CCTL_SINGLE_CMD 0 +#define CCTL_BLOCK_CMD 0x10 +#define CCTL_ALL_CMD 0x10 + +/****************************************************************************** + * L2_CA_CONF (Cache architecture configuration) + *****************************************************************************/ +#define L2_CA_CONF_offL2SET 0 +#define L2_CA_CONF_offL2WAY 4 +#define L2_CA_CONF_offL2CLSZ 8 +#define L2_CA_CONF_offL2DW 11 +#define L2_CA_CONF_offL2PT 14 +#define L2_CA_CONF_offL2VER 16 + +#define L2_CA_CONF_mskL2SET (0xFUL << L2_CA_CONF_offL2SET) +#define L2_CA_CONF_mskL2WAY (0xFUL << L2_CA_CONF_offL2WAY) +#define L2_CA_CONF_mskL2CLSZ (0x7UL << L2_CA_CONF_offL2CLSZ) +#define L2_CA_CONF_mskL2DW (0x7UL << L2_CA_CONF_offL2DW) +#define L2_CA_CONF_mskL2PT (0x3UL << L2_CA_CONF_offL2PT) +#define L2_CA_CONF_mskL2VER (0xFFFFUL << L2_CA_CONF_offL2VER) + +/****************************************************************************** + * L2CC_SETUP (L2CC Setup register) + *****************************************************************************/ +#define L2CC_SETUP_offPART 0 +#define L2CC_SETUP_mskPART (0x3UL << L2CC_SETUP_offPART) +#define L2CC_SETUP_offDDLATC 4 +#define L2CC_SETUP_mskDDLATC (0x3UL << L2CC_SETUP_offDDLATC) +#define L2CC_SETUP_offTDLATC 8 +#define L2CC_SETUP_mskTDLATC (0x3UL << L2CC_SETUP_offTDLATC) + +/****************************************************************************** + * L2CC_PROT (L2CC Protect register) + *****************************************************************************/ +#define L2CC_PROT_offMRWEN 31 +#define L2CC_PROT_mskMRWEN (0x1UL << L2CC_PROT_offMRWEN) + +/****************************************************************************** + * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n) + *****************************************************************************/ +#define L2CC_CTRL_offEN 31 +#define L2CC_CTRL_mskEN (0x1UL << L2CC_CTRL_offEN) + +/****************************************************************************** + * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n) + *****************************************************************************/ +#define L2_CCTL_STATUS_offCMD_COMP 31 +#define L2_CCTL_STATUS_mskCMD_COMP (0x1 << L2_CCTL_STATUS_offCMD_COMP) + +#ifndef __ASSEMBLY__ +extern void __iomem *atl2c_base; + +#include +#include +#include + +#define L2C_R_REG(offset) __raw_readl(atl2c_base + offset) +#define L2C_W_REG(offset, value) __raw_writel(value, atl2c_base + offset) + +#define L2_CMD_RDY() \ + do{;}while((L2C_R_REG(L2_CCTL_STATUS_OFF) & L2_CCTL_STATUS_mskCMD_COMP) == 0) + +static inline unsigned long L2_CACHE_SET(void) +{ + return 64 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2SET) >> + L2_CA_CONF_offL2SET); +} + +static inline unsigned long L2_CACHE_WAY(void) +{ + return 1 + + ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2WAY) >> + L2_CA_CONF_offL2WAY); +} + +static inline unsigned long L2_CACHE_LINE_SIZE(void) +{ + + return 4 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2CLSZ) >> + L2_CA_CONF_offL2CLSZ); +} + +static inline unsigned long GET_L2CC_CTRL_CPU(unsigned long cpu) +{ + if (cpu == smp_processor_id()) + return L2C_R_REG(L2CC_CTRL_OFF); + return L2C_R_REG(L2CC_CTRL_OFF + (cpu << 8)); +} + +static inline void SET_L2CC_CTRL_CPU(unsigned long cpu, unsigned long val) +{ + if (cpu == smp_processor_id()) + L2C_W_REG(L2CC_CTRL_OFF, val); + else + L2C_W_REG(L2CC_CTRL_OFF + (cpu << 8), val); +} + +static inline unsigned long GET_L2CC_STATUS_CPU(unsigned long cpu) +{ + if (cpu == smp_processor_id()) + return L2C_R_REG(L2_CCTL_STATUS_OFF); + return L2C_R_REG(L2_CCTL_STATUS_OFF + (cpu << 8)); +} + +#endif + +#endif diff --git a/arch/nds32/kernel/atl2c.c b/arch/nds32/kernel/atl2c.c new file mode 100644 index 0000000..dd87fc9 --- /dev/null +++ b/arch/nds32/kernel/atl2c.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2005-2017 Andes Technology Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include + +void __iomem *atl2c_base; +static const struct of_device_id atl2c_ids[] __initconst = { + {.compatible = "andestech,atl2c",} +}; + +static int __init atl2c_of_init(void) +{ + struct device_node *np; + struct resource res; + unsigned long tmp = 0; + unsigned long l2set, l2way, l2clsz; + + if (!(__nds32__mfsr(NDS32_SR_MSC_CFG) & MSC_CFG_mskL2C)) + return -ENODEV; + + np = of_find_matching_node(NULL, atl2c_ids); + if (!np) + return -ENODEV; + + if (of_address_to_resource(np, 0, &res)) + return -ENODEV; + + atl2c_base = ioremap(res.start, resource_size(&res)); + if (!atl2c_base) + return -ENOMEM; + + l2set = + 64 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2SET) >> + L2_CA_CONF_offL2SET); + l2way = + 1 + + ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2WAY) >> + L2_CA_CONF_offL2WAY); + l2clsz = + 4 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2CLSZ) >> + L2_CA_CONF_offL2CLSZ); + pr_info("L2:%luKB/%luS/%luW/%luB\n", + l2set * l2way * l2clsz / 1024, l2set, l2way, l2clsz); + + tmp = L2C_R_REG(L2CC_PROT_OFF); + tmp &= ~L2CC_PROT_mskMRWEN; + L2C_W_REG(L2CC_PROT_OFF, tmp); + + tmp = L2C_R_REG(L2CC_SETUP_OFF); + tmp &= ~L2CC_SETUP_mskPART; + L2C_W_REG(L2CC_SETUP_OFF, tmp); + + tmp = L2C_R_REG(L2CC_CTRL_OFF); + tmp |= L2CC_CTRL_mskEN; + L2C_W_REG(L2CC_CTRL_OFF, tmp); + + return 0; +} + +subsys_initcall(atl2c_of_init); -- 1.7.9.5 From 1585322779663843633@xxx Tue Nov 28 15:06:58 +0000 2017 X-GM-THRID: 1585322779663843633 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread