public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Zhizhou Zhang <etou.zh@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [[Patch V2] mips:  04/16] add cpu/mips64/cpu.c
Date: Fri, 17 Aug 2012 23:30:47 +0800	[thread overview]
Message-ID: <1345217476-32034-5-git-send-email-etou.zh@gmail.com> (raw)
In-Reply-To: <1345217476-32034-1-git-send-email-etou.zh@gmail.com>

add icache and dcache probe here. but scache was not probed. For
I don't know how to determine it implemented or not.
Signed-off-by: Zhizhou Zhang <etou.zh@gmail.com>
---
 arch/mips/cpu/mips64/cpu.c |  133 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)
 create mode 100644 arch/mips/cpu/mips64/cpu.c

diff --git a/arch/mips/cpu/mips64/cpu.c b/arch/mips/cpu/mips64/cpu.c
new file mode 100644
index 0000000..ea9c28a
--- /dev/null
+++ b/arch/mips/cpu/mips64/cpu.c
@@ -0,0 +1,133 @@
+/*
+ * (C) Copyright 2003
+ * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
+ * Zhi-zhou Zhang <etou.zh@gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <command.h>
+#include <netdev.h>
+#include <asm/mipsregs.h>
+#include <asm/cacheops.h>
+#include <asm/reboot.h>
+
+#define cache_op(op,addr)						\
+	__asm__ __volatile__(						\
+	"	.set	push					\n"	\
+	"	.set	noreorder				\n"	\
+	"	.set	mips64\n\t				\n"	\
+	"	cache	%0, %1					\n"	\
+	"	.set	pop					\n"	\
+	:								\
+	: "i" (op), "R" (*(unsigned char *)(addr)))
+
+void __attribute__((weak)) _machine_restart(void)
+{
+}
+
+int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	_machine_restart();
+
+	fprintf(stderr, "*** reset failed ***\n");
+	return 0;
+}
+
+static struct cache_desc icache, dcache;
+
+void cache_probe()
+{
+	int config, lsize;
+
+	config = read_c0_config1();
+	lsize = (config >> 19) & 7;
+	if (lsize) { /* icache present */
+		icache.linesz = 2 << lsize;
+		icache.sets = 32 << (((config >> 22) + 1) & 7);
+		icache.ways = 1 + ((config >> 16) & 7);
+		icache.size = icache.sets *
+		icache.ways *
+		icache.linesz;
+	}
+
+	lsize = (config >> 10) & 7;
+	if (lsize) { /* dcache present */
+		dcache.linesz = 2 << lsize;
+		dcache.sets = 32 << (((config >> 13) + 1) & 7);
+		dcache.ways = 1 + ((config >> 7) & 7);
+		dcache.size = dcache.sets *
+		dcache.ways *
+		dcache.linesz;
+	}
+} 
+
+void flush_cache(ulong start_addr, ulong size)
+{
+	unsigned long addr, aend;
+
+	/* aend will be miscalculated when size is zero, so we return here */
+	if (size == 0)
+		return;
+
+	addr = start_addr & ~(icache.linesz - 1);
+	aend = (start_addr + size - 1) & ~(icache.linesz - 1);
+	while (1) {
+		cache_op(Hit_Invalidate_I, addr);
+		if (addr == aend)
+			break;
+		addr += icache.linesz;
+	}
+
+	addr = start_addr & ~(dcache.linesz - 1);
+	aend = (start_addr + size - 1) & ~(dcache.linesz - 1);
+	while (1) {
+		cache_op(Hit_Writeback_Inv_D, addr);
+		if (addr == aend)
+			break;
+		addr += dcache.linesz;
+	}
+}
+
+void flush_dcache_range(ulong start_addr, ulong stop)
+{
+	unsigned long addr = start_addr & ~(dcache.linesz - 1);
+	unsigned long aend = (stop - 1) & ~(dcache.linesz - 1);
+
+	while (1) {
+		cache_op(Hit_Writeback_Inv_D, addr);
+		if (addr == aend)
+			break;
+		addr += dcache.linesz;
+	}
+}
+
+void invalidate_dcache_range(ulong start_addr, ulong stop)
+{
+	unsigned long addr = start_addr & ~(dcache.linesz - 1);
+	unsigned long aend = (stop - 1) & ~(dcache.linesz - 1);
+
+	while (1) {
+		cache_op(Hit_Invalidate_D, addr);
+		if (addr == aend)
+			break;
+		addr += dcache.linesz;
+	}
+}
-- 
1.7.9.5

  parent reply	other threads:[~2012-08-17 15:30 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-17 15:30 [U-Boot] [[Patch V2] mips: 00/16] add mips64 support to U-Boot Zhizhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 01/16] add mips64 standalone support Zhizhou Zhang
2012-08-17 19:31   ` Mike Frysinger
2012-08-18 12:22     ` Zhi-zhou Zhang
2012-08-18 15:38       ` Mike Frysinger
2012-08-19  2:25         ` Zhi-zhou Zhang
2012-08-23  3:12           ` Mike Frysinger
2012-08-19  6:17         ` Zhi-zhou Zhang
2012-09-01 12:29   ` Wolfgang Denk
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 02/16] add cpu/mips64/Makefile Zhizhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 03/16] add cpu/mips64/config.mk Zhizhou Zhang
2012-08-17 19:32   ` Mike Frysinger
2012-08-17 15:30 ` Zhizhou Zhang [this message]
2012-08-17 19:34   ` [U-Boot] [[Patch V2] mips: 04/16] add cpu/mips64/cpu.c Mike Frysinger
2012-08-18  3:17     ` Zhi-zhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 05/16] add cpu/mips64/interrupts.c Zhizhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 06/16] add cpu/mips64/start.S Zhizhou Zhang
2012-08-17 19:38   ` Mike Frysinger
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 07/16] add cpu/mips64/time.c Zhizhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 08/16] Let UNCACHED_SDRAM be available to mips64 Zhizhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 09/16] add cache description struct Zhizhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 10/16] modify io operation for mips64 Zhizhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 11/16] Make size_t equaled to unsigned long Zhizhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 12/16] modify u-boot.lds for mips64 Zhizhou Zhang
2012-08-17 17:09   ` Andrew Dyer
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 13/16] add board define in boards.cfg Zhizhou Zhang
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 14/16] add mips64 standalone link script Zhizhou Zhang
2012-08-17 17:08   ` Andrew Dyer
2012-08-18  3:04     ` Zhi-zhou Zhang
2012-08-19 13:31       ` Daniel Schwierzeck
2012-08-19 13:25   ` Daniel Schwierzeck
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 15/16] add configs/qemu-mips64.h Zhizhou Zhang
2012-08-19 13:41   ` Daniel Schwierzeck
2012-08-17 15:30 ` [U-Boot] [[Patch V2] mips: 16/16] modify qemu-mips/config.mk Zhizhou Zhang
2012-08-19 13:38   ` Daniel Schwierzeck
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 00/16] add mips64 support to U-Boot Zhizhou Zhang
2012-08-19 13:00   ` Daniel Schwierzeck
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 01/16] add mips64 standalone support Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 02/16] add cpu/mips64/Makefile Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 03/16] add cpu/mips64/config.mk Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 04/16] add cpu/mips64/cpu.c Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 05/16] add cpu/mips64/interrupts.c Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 06/16] add cpu/mips64/start.S Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 07/16] add cpu/mips64/time.c Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 08/16] Let UNCACHED_SDRAM be available to mips64 Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 09/16] add cache description struct Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 10/16] modify io operation for mips64 Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 11/16] Make size_t equaled to unsigned long Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 12/16] modify u-boot.lds for mips64 Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 13/16] add board define in boards.cfg Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 14/16] add mips64 standalone link script Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 15/16] add configs/qemu-mips64.h Zhizhou Zhang
2012-08-17 15:31 ` [U-Boot] [[Patch V2] mips: 16/16] modify qemu-mips/config.mk Zhizhou Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1345217476-32034-5-git-send-email-etou.zh@gmail.com \
    --to=etou.zh@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox