18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * ross.h: Ross module specific definitions and defines.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _SPARC_ROSS_H
98c2ecf20Sopenharmony_ci#define _SPARC_ROSS_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <asm/asi.h>
128c2ecf20Sopenharmony_ci#include <asm/page.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* Ross made Hypersparcs have a %psr 'impl' field of '0001'.  The 'vers'
158c2ecf20Sopenharmony_ci * field has '1111'.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* The MMU control register fields on the HyperSparc.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * -----------------------------------------------------------------
218c2ecf20Sopenharmony_ci * |implvers| RSV |CWR|SE|WBE| MID |BM| C|CS|MR|CM|RSV|CE|RSV|NF|ME|
228c2ecf20Sopenharmony_ci * -----------------------------------------------------------------
238c2ecf20Sopenharmony_ci *  31    24 23-22 21  20  19 18-15 14 13 12 11 10  9   8 7-2  1  0
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * Phew, lots of fields there ;-)
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * CWR: Cache Wrapping Enabled, if one cache wrapping is on.
288c2ecf20Sopenharmony_ci * SE: Snoop Enable, turns on bus snooping for cache activity if one.
298c2ecf20Sopenharmony_ci * WBE: Write Buffer Enable, one turns it on.
308c2ecf20Sopenharmony_ci * MID: The ModuleID of the chip for MBus transactions.
318c2ecf20Sopenharmony_ci * BM: Boot-Mode. One indicates the MMU is in boot mode.
328c2ecf20Sopenharmony_ci * C: Indicates whether accesses are cachable while the MMU is
338c2ecf20Sopenharmony_ci *    disabled.
348c2ecf20Sopenharmony_ci * CS: Cache Size -- 0 = 128k, 1 = 256k
358c2ecf20Sopenharmony_ci * MR: Memory Reflection, one indicates that the memory bus connected
368c2ecf20Sopenharmony_ci *     to the MBus supports memory reflection.
378c2ecf20Sopenharmony_ci * CM: Cache Mode -- 0 = write-through, 1 = copy-back
388c2ecf20Sopenharmony_ci * CE: Cache Enable -- 0 = no caching, 1 = cache is on
398c2ecf20Sopenharmony_ci * NF: No Fault -- 0 = faults trap the CPU from supervisor mode
408c2ecf20Sopenharmony_ci *                 1 = faults from supervisor mode do not generate traps
418c2ecf20Sopenharmony_ci * ME: MMU Enable -- 0 = MMU is off, 1 = MMU is on
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define HYPERSPARC_CWENABLE   0x00200000
458c2ecf20Sopenharmony_ci#define HYPERSPARC_SBENABLE   0x00100000
468c2ecf20Sopenharmony_ci#define HYPERSPARC_WBENABLE   0x00080000
478c2ecf20Sopenharmony_ci#define HYPERSPARC_MIDMASK    0x00078000
488c2ecf20Sopenharmony_ci#define HYPERSPARC_BMODE      0x00004000
498c2ecf20Sopenharmony_ci#define HYPERSPARC_ACENABLE   0x00002000
508c2ecf20Sopenharmony_ci#define HYPERSPARC_CSIZE      0x00001000
518c2ecf20Sopenharmony_ci#define HYPERSPARC_MRFLCT     0x00000800
528c2ecf20Sopenharmony_ci#define HYPERSPARC_CMODE      0x00000400
538c2ecf20Sopenharmony_ci#define HYPERSPARC_CENABLE    0x00000100
548c2ecf20Sopenharmony_ci#define HYPERSPARC_NFAULT     0x00000002
558c2ecf20Sopenharmony_ci#define HYPERSPARC_MENABLE    0x00000001
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* The ICCR instruction cache register on the HyperSparc.
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci * -----------------------------------------------
618c2ecf20Sopenharmony_ci * |                                 | FTD | ICE |
628c2ecf20Sopenharmony_ci * -----------------------------------------------
638c2ecf20Sopenharmony_ci *  31                                  1     0
648c2ecf20Sopenharmony_ci *
658c2ecf20Sopenharmony_ci * This register is accessed using the V8 'wrasr' and 'rdasr'
668c2ecf20Sopenharmony_ci * opcodes, since not all assemblers understand them and those
678c2ecf20Sopenharmony_ci * that do use different semantics I will just hard code the
688c2ecf20Sopenharmony_ci * instruction with a '.word' statement.
698c2ecf20Sopenharmony_ci *
708c2ecf20Sopenharmony_ci * FTD:  If set to one flush instructions executed during an
718c2ecf20Sopenharmony_ci *       instruction cache hit occurs, the corresponding line
728c2ecf20Sopenharmony_ci *       for said cache-hit is invalidated.  If FTD is zero,
738c2ecf20Sopenharmony_ci *       an unimplemented 'flush' trap will occur when any
748c2ecf20Sopenharmony_ci *       flush is executed by the processor.
758c2ecf20Sopenharmony_ci *
768c2ecf20Sopenharmony_ci * ICE:  If set to one, the instruction cache is enabled.  If
778c2ecf20Sopenharmony_ci *       zero, the cache will not be used for instruction fetches.
788c2ecf20Sopenharmony_ci *
798c2ecf20Sopenharmony_ci * All other bits are read as zeros, and writes to them have no
808c2ecf20Sopenharmony_ci * effect.
818c2ecf20Sopenharmony_ci *
828c2ecf20Sopenharmony_ci * Wheee, not many assemblers understand the %iccr register nor
838c2ecf20Sopenharmony_ci * the generic asr r/w instructions.
848c2ecf20Sopenharmony_ci *
858c2ecf20Sopenharmony_ci *  1000 0011 0100 0111 1100 0000 0000 0000   ! rd %iccr, %g1
868c2ecf20Sopenharmony_ci *
878c2ecf20Sopenharmony_ci * 0x  8    3    4    7    c    0    0    0   ! 0x8347c000
888c2ecf20Sopenharmony_ci *
898c2ecf20Sopenharmony_ci *  1011 1111 1000 0000 0110 0000 0000 0000   ! wr %g1, 0x0, %iccr
908c2ecf20Sopenharmony_ci *
918c2ecf20Sopenharmony_ci * 0x  b    f    8    0    6    0    0    0   ! 0xbf806000
928c2ecf20Sopenharmony_ci *
938c2ecf20Sopenharmony_ci */
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define HYPERSPARC_ICCR_FTD     0x00000002
968c2ecf20Sopenharmony_ci#define HYPERSPARC_ICCR_ICE     0x00000001
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistatic inline unsigned int get_ross_icr(void)
1018c2ecf20Sopenharmony_ci{
1028c2ecf20Sopenharmony_ci	unsigned int icreg;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	__asm__ __volatile__(".word 0x8347c000\n\t" /* rd %iccr, %g1 */
1058c2ecf20Sopenharmony_ci			     "mov %%g1, %0\n\t"
1068c2ecf20Sopenharmony_ci			     : "=r" (icreg)
1078c2ecf20Sopenharmony_ci			     : /* no inputs */
1088c2ecf20Sopenharmony_ci			     : "g1", "memory");
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	return icreg;
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistatic inline void put_ross_icr(unsigned int icreg)
1148c2ecf20Sopenharmony_ci{
1158c2ecf20Sopenharmony_ci	__asm__ __volatile__("or %%g0, %0, %%g1\n\t"
1168c2ecf20Sopenharmony_ci			     ".word 0xbf806000\n\t" /* wr %g1, 0x0, %iccr */
1178c2ecf20Sopenharmony_ci			     "nop\n\t"
1188c2ecf20Sopenharmony_ci			     "nop\n\t"
1198c2ecf20Sopenharmony_ci			     "nop\n\t"
1208c2ecf20Sopenharmony_ci			     : /* no outputs */
1218c2ecf20Sopenharmony_ci			     : "r" (icreg)
1228c2ecf20Sopenharmony_ci			     : "g1", "memory");
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	return;
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/* HyperSparc specific cache flushing. */
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/* This is for the on-chip instruction cache. */
1308c2ecf20Sopenharmony_cistatic inline void hyper_flush_whole_icache(void)
1318c2ecf20Sopenharmony_ci{
1328c2ecf20Sopenharmony_ci	__asm__ __volatile__("sta %%g0, [%%g0] %0\n\t"
1338c2ecf20Sopenharmony_ci			     : /* no outputs */
1348c2ecf20Sopenharmony_ci			     : "i" (ASI_M_FLUSH_IWHOLE)
1358c2ecf20Sopenharmony_ci			     : "memory");
1368c2ecf20Sopenharmony_ci	return;
1378c2ecf20Sopenharmony_ci}
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ciextern int vac_cache_size;
1408c2ecf20Sopenharmony_ciextern int vac_line_size;
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistatic inline void hyper_clear_all_tags(void)
1438c2ecf20Sopenharmony_ci{
1448c2ecf20Sopenharmony_ci	unsigned long addr;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	for(addr = 0; addr < vac_cache_size; addr += vac_line_size)
1478c2ecf20Sopenharmony_ci		__asm__ __volatile__("sta %%g0, [%0] %1\n\t"
1488c2ecf20Sopenharmony_ci				     : /* no outputs */
1498c2ecf20Sopenharmony_ci				     : "r" (addr), "i" (ASI_M_DATAC_TAG)
1508c2ecf20Sopenharmony_ci				     : "memory");
1518c2ecf20Sopenharmony_ci}
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cistatic inline void hyper_flush_unconditional_combined(void)
1548c2ecf20Sopenharmony_ci{
1558c2ecf20Sopenharmony_ci	unsigned long addr;
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	for (addr = 0; addr < vac_cache_size; addr += vac_line_size)
1588c2ecf20Sopenharmony_ci		__asm__ __volatile__("sta %%g0, [%0] %1\n\t"
1598c2ecf20Sopenharmony_ci				     : /* no outputs */
1608c2ecf20Sopenharmony_ci				     : "r" (addr), "i" (ASI_M_FLUSH_CTX)
1618c2ecf20Sopenharmony_ci				     : "memory");
1628c2ecf20Sopenharmony_ci}
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cistatic inline void hyper_flush_cache_user(void)
1658c2ecf20Sopenharmony_ci{
1668c2ecf20Sopenharmony_ci	unsigned long addr;
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	for (addr = 0; addr < vac_cache_size; addr += vac_line_size)
1698c2ecf20Sopenharmony_ci		__asm__ __volatile__("sta %%g0, [%0] %1\n\t"
1708c2ecf20Sopenharmony_ci				     : /* no outputs */
1718c2ecf20Sopenharmony_ci				     : "r" (addr), "i" (ASI_M_FLUSH_USER)
1728c2ecf20Sopenharmony_ci				     : "memory");
1738c2ecf20Sopenharmony_ci}
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic inline void hyper_flush_cache_page(unsigned long page)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	unsigned long end;
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	page &= PAGE_MASK;
1808c2ecf20Sopenharmony_ci	end = page + PAGE_SIZE;
1818c2ecf20Sopenharmony_ci	while (page < end) {
1828c2ecf20Sopenharmony_ci		__asm__ __volatile__("sta %%g0, [%0] %1\n\t"
1838c2ecf20Sopenharmony_ci				     : /* no outputs */
1848c2ecf20Sopenharmony_ci				     : "r" (page), "i" (ASI_M_FLUSH_PAGE)
1858c2ecf20Sopenharmony_ci				     : "memory");
1868c2ecf20Sopenharmony_ci		page += vac_line_size;
1878c2ecf20Sopenharmony_ci	}
1888c2ecf20Sopenharmony_ci}
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci#endif /* !(__ASSEMBLY__) */
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci#endif /* !(_SPARC_ROSS_H) */
193