162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * mxcc.h:  Definitions of the Viking MXCC registers
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _SPARC_MXCC_H
962306a36Sopenharmony_ci#define _SPARC_MXCC_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/* These registers are accessed through ASI 0x2. */
1262306a36Sopenharmony_ci#define MXCC_DATSTREAM       0x1C00000  /* Data stream register */
1362306a36Sopenharmony_ci#define MXCC_SRCSTREAM       0x1C00100  /* Source stream register */
1462306a36Sopenharmony_ci#define MXCC_DESSTREAM       0x1C00200  /* Destination stream register */
1562306a36Sopenharmony_ci#define MXCC_RMCOUNT         0x1C00300  /* Count of references and misses */
1662306a36Sopenharmony_ci#define MXCC_STEST           0x1C00804  /* Internal self-test */
1762306a36Sopenharmony_ci#define MXCC_CREG            0x1C00A04  /* Control register */
1862306a36Sopenharmony_ci#define MXCC_SREG            0x1C00B00  /* Status register */
1962306a36Sopenharmony_ci#define MXCC_RREG            0x1C00C04  /* Reset register */
2062306a36Sopenharmony_ci#define MXCC_EREG            0x1C00E00  /* Error code register */
2162306a36Sopenharmony_ci#define MXCC_PREG            0x1C00F04  /* Address port register */
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/* Some MXCC constants. */
2462306a36Sopenharmony_ci#define MXCC_STREAM_SIZE     0x20       /* Size in bytes of one stream r/w */
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/* The MXCC Control Register:
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * ----------------------------------------------------------------------
2962306a36Sopenharmony_ci * |                                   | RRC | RSV |PRE|MCE|PARE|ECE|RSV|
3062306a36Sopenharmony_ci * ----------------------------------------------------------------------
3162306a36Sopenharmony_ci *  31                              10    9    8-6   5   4    3   2  1-0
3262306a36Sopenharmony_ci *
3362306a36Sopenharmony_ci * RRC: Controls what you read from MXCC_RMCOUNT reg.
3462306a36Sopenharmony_ci *      0=Misses 1=References
3562306a36Sopenharmony_ci * PRE: Prefetch enable
3662306a36Sopenharmony_ci * MCE: Multiple Command Enable
3762306a36Sopenharmony_ci * PARE: Parity enable
3862306a36Sopenharmony_ci * ECE: External cache enable
3962306a36Sopenharmony_ci */
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define MXCC_CTL_RRC   0x00000200
4262306a36Sopenharmony_ci#define MXCC_CTL_PRE   0x00000020
4362306a36Sopenharmony_ci#define MXCC_CTL_MCE   0x00000010
4462306a36Sopenharmony_ci#define MXCC_CTL_PARE  0x00000008
4562306a36Sopenharmony_ci#define MXCC_CTL_ECE   0x00000004
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci/* The MXCC Error Register:
4862306a36Sopenharmony_ci *
4962306a36Sopenharmony_ci * --------------------------------------------------------
5062306a36Sopenharmony_ci * |ME| RSV|CE|PEW|PEE|ASE|EIV| MOPC|ECODE|PRIV|RSV|HPADDR|
5162306a36Sopenharmony_ci * --------------------------------------------------------
5262306a36Sopenharmony_ci *  31   30 29  28  27  26  25 24-15  14-7   6  5-3   2-0
5362306a36Sopenharmony_ci *
5462306a36Sopenharmony_ci * ME: Multiple Errors have occurred
5562306a36Sopenharmony_ci * CE: Cache consistency Error
5662306a36Sopenharmony_ci * PEW: Parity Error during a Write operation
5762306a36Sopenharmony_ci * PEE: Parity Error involving the External cache
5862306a36Sopenharmony_ci * ASE: ASynchronous Error
5962306a36Sopenharmony_ci * EIV: This register is toast
6062306a36Sopenharmony_ci * MOPC: MXCC Operation Code for instance causing error
6162306a36Sopenharmony_ci * ECODE: The Error CODE
6262306a36Sopenharmony_ci * PRIV: A privileged mode error? 0=no 1=yes
6362306a36Sopenharmony_ci * HPADDR: High PhysicalADDRess bits (35-32)
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define MXCC_ERR_ME     0x80000000
6762306a36Sopenharmony_ci#define MXCC_ERR_CE     0x20000000
6862306a36Sopenharmony_ci#define MXCC_ERR_PEW    0x10000000
6962306a36Sopenharmony_ci#define MXCC_ERR_PEE    0x08000000
7062306a36Sopenharmony_ci#define MXCC_ERR_ASE    0x04000000
7162306a36Sopenharmony_ci#define MXCC_ERR_EIV    0x02000000
7262306a36Sopenharmony_ci#define MXCC_ERR_MOPC   0x01FF8000
7362306a36Sopenharmony_ci#define MXCC_ERR_ECODE  0x00007F80
7462306a36Sopenharmony_ci#define MXCC_ERR_PRIV   0x00000040
7562306a36Sopenharmony_ci#define MXCC_ERR_HPADDR 0x0000000f
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/* The MXCC Port register:
7862306a36Sopenharmony_ci *
7962306a36Sopenharmony_ci * -----------------------------------------------------
8062306a36Sopenharmony_ci * |                | MID |                            |
8162306a36Sopenharmony_ci * -----------------------------------------------------
8262306a36Sopenharmony_ci *  31            21 20-18 17                         0
8362306a36Sopenharmony_ci *
8462306a36Sopenharmony_ci * MID: The moduleID of the cpu your read this from.
8562306a36Sopenharmony_ci */
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#ifndef __ASSEMBLY__
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cistatic inline void mxcc_set_stream_src(unsigned long *paddr)
9062306a36Sopenharmony_ci{
9162306a36Sopenharmony_ci	unsigned long data0 = paddr[0];
9262306a36Sopenharmony_ci	unsigned long data1 = paddr[1];
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci	__asm__ __volatile__ ("or %%g0, %0, %%g2\n\t"
9562306a36Sopenharmony_ci			      "or %%g0, %1, %%g3\n\t"
9662306a36Sopenharmony_ci			      "stda %%g2, [%2] %3\n\t" : :
9762306a36Sopenharmony_ci			      "r" (data0), "r" (data1),
9862306a36Sopenharmony_ci			      "r" (MXCC_SRCSTREAM),
9962306a36Sopenharmony_ci			      "i" (ASI_M_MXCC) : "g2", "g3");
10062306a36Sopenharmony_ci}
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cistatic inline void mxcc_set_stream_dst(unsigned long *paddr)
10362306a36Sopenharmony_ci{
10462306a36Sopenharmony_ci	unsigned long data0 = paddr[0];
10562306a36Sopenharmony_ci	unsigned long data1 = paddr[1];
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci	__asm__ __volatile__ ("or %%g0, %0, %%g2\n\t"
10862306a36Sopenharmony_ci			      "or %%g0, %1, %%g3\n\t"
10962306a36Sopenharmony_ci			      "stda %%g2, [%2] %3\n\t" : :
11062306a36Sopenharmony_ci			      "r" (data0), "r" (data1),
11162306a36Sopenharmony_ci			      "r" (MXCC_DESSTREAM),
11262306a36Sopenharmony_ci			      "i" (ASI_M_MXCC) : "g2", "g3");
11362306a36Sopenharmony_ci}
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_cistatic inline unsigned long mxcc_get_creg(void)
11662306a36Sopenharmony_ci{
11762306a36Sopenharmony_ci	unsigned long mxcc_control;
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci	__asm__ __volatile__("set 0xffffffff, %%g2\n\t"
12062306a36Sopenharmony_ci			     "set 0xffffffff, %%g3\n\t"
12162306a36Sopenharmony_ci			     "stda %%g2, [%1] %2\n\t"
12262306a36Sopenharmony_ci			     "lda [%3] %2, %0\n\t" :
12362306a36Sopenharmony_ci			     "=r" (mxcc_control) :
12462306a36Sopenharmony_ci			     "r" (MXCC_EREG), "i" (ASI_M_MXCC),
12562306a36Sopenharmony_ci			     "r" (MXCC_CREG) : "g2", "g3");
12662306a36Sopenharmony_ci	return mxcc_control;
12762306a36Sopenharmony_ci}
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_cistatic inline void mxcc_set_creg(unsigned long mxcc_control)
13062306a36Sopenharmony_ci{
13162306a36Sopenharmony_ci	__asm__ __volatile__("sta %0, [%1] %2\n\t" : :
13262306a36Sopenharmony_ci			     "r" (mxcc_control), "r" (MXCC_CREG),
13362306a36Sopenharmony_ci			     "i" (ASI_M_MXCC));
13462306a36Sopenharmony_ci}
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#endif /* !__ASSEMBLY__ */
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci#endif /* !(_SPARC_MXCC_H) */
139