162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * sbi.h:  SBI (Sbus Interface on sun4d) definitions
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 1997 Jakub Jelinek <jj@sunsite.mff.cuni.cz>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _SPARC_SBI_H
962306a36Sopenharmony_ci#define _SPARC_SBI_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <asm/obio.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* SBI */
1462306a36Sopenharmony_cistruct sbi_regs {
1562306a36Sopenharmony_ci/* 0x0000 */	u32		cid;		/* Component ID */
1662306a36Sopenharmony_ci/* 0x0004 */	u32		ctl;		/* Control */
1762306a36Sopenharmony_ci/* 0x0008 */	u32		status;		/* Status */
1862306a36Sopenharmony_ci		u32		_unused1;
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* 0x0010 */	u32		cfg0;		/* Slot0 config reg */
2162306a36Sopenharmony_ci/* 0x0014 */	u32		cfg1;		/* Slot1 config reg */
2262306a36Sopenharmony_ci/* 0x0018 */	u32		cfg2;		/* Slot2 config reg */
2362306a36Sopenharmony_ci/* 0x001c */	u32		cfg3;		/* Slot3 config reg */
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/* 0x0020 */	u32		stb0;		/* Streaming buf control for slot 0 */
2662306a36Sopenharmony_ci/* 0x0024 */	u32		stb1;		/* Streaming buf control for slot 1 */
2762306a36Sopenharmony_ci/* 0x0028 */	u32		stb2;		/* Streaming buf control for slot 2 */
2862306a36Sopenharmony_ci/* 0x002c */	u32		stb3;		/* Streaming buf control for slot 3 */
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci/* 0x0030 */	u32		intr_state;	/* Interrupt state */
3162306a36Sopenharmony_ci/* 0x0034 */	u32		intr_tid;	/* Interrupt target ID */
3262306a36Sopenharmony_ci/* 0x0038 */	u32		intr_diag;	/* Interrupt diagnostics */
3362306a36Sopenharmony_ci};
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define SBI_CID			0x02800000
3662306a36Sopenharmony_ci#define SBI_CTL			0x02800004
3762306a36Sopenharmony_ci#define SBI_STATUS		0x02800008
3862306a36Sopenharmony_ci#define SBI_CFG0		0x02800010
3962306a36Sopenharmony_ci#define SBI_CFG1		0x02800014
4062306a36Sopenharmony_ci#define SBI_CFG2		0x02800018
4162306a36Sopenharmony_ci#define SBI_CFG3		0x0280001c
4262306a36Sopenharmony_ci#define SBI_STB0		0x02800020
4362306a36Sopenharmony_ci#define SBI_STB1		0x02800024
4462306a36Sopenharmony_ci#define SBI_STB2		0x02800028
4562306a36Sopenharmony_ci#define SBI_STB3		0x0280002c
4662306a36Sopenharmony_ci#define SBI_INTR_STATE		0x02800030
4762306a36Sopenharmony_ci#define SBI_INTR_TID		0x02800034
4862306a36Sopenharmony_ci#define SBI_INTR_DIAG		0x02800038
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/* Burst bits for 8, 16, 32, 64 are in cfgX registers at bits 2, 3, 4, 5 respectively */
5162306a36Sopenharmony_ci#define SBI_CFG_BURST_MASK	0x0000001e
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/* How to make devid from sbi no */
5462306a36Sopenharmony_ci#define SBI2DEVID(sbino) ((sbino<<4)|2)
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/* intr_state has 4 bits for slots 0 .. 3 and these bits are repeated for each sbus irq level
5762306a36Sopenharmony_ci *
5862306a36Sopenharmony_ci *		   +-------+-------+-------+-------+-------+-------+-------+-------+
5962306a36Sopenharmony_ci *  SBUS IRQ LEVEL |   7   |   6   |   5   |   4   |   3   |   2   |   1   |       |
6062306a36Sopenharmony_ci *		   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Reser |
6162306a36Sopenharmony_ci *  SLOT #         |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|  ved  |
6262306a36Sopenharmony_ci *                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------+
6362306a36Sopenharmony_ci *  Bits           31      27      23      19      15      11      7       3      0
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#ifndef __ASSEMBLY__
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistatic inline int acquire_sbi(int devid, int mask)
7062306a36Sopenharmony_ci{
7162306a36Sopenharmony_ci	__asm__ __volatile__ ("swapa [%2] %3, %0" :
7262306a36Sopenharmony_ci			      "=r" (mask) :
7362306a36Sopenharmony_ci			      "0" (mask),
7462306a36Sopenharmony_ci			      "r" (ECSR_DEV_BASE(devid) | SBI_INTR_STATE),
7562306a36Sopenharmony_ci			      "i" (ASI_M_CTL));
7662306a36Sopenharmony_ci	return mask;
7762306a36Sopenharmony_ci}
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_cistatic inline void release_sbi(int devid, int mask)
8062306a36Sopenharmony_ci{
8162306a36Sopenharmony_ci	__asm__ __volatile__ ("sta %0, [%1] %2" : :
8262306a36Sopenharmony_ci			      "r" (mask),
8362306a36Sopenharmony_ci			      "r" (ECSR_DEV_BASE(devid) | SBI_INTR_STATE),
8462306a36Sopenharmony_ci			      "i" (ASI_M_CTL));
8562306a36Sopenharmony_ci}
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_cistatic inline void set_sbi_tid(int devid, int targetid)
8862306a36Sopenharmony_ci{
8962306a36Sopenharmony_ci	__asm__ __volatile__ ("sta %0, [%1] %2" : :
9062306a36Sopenharmony_ci			      "r" (targetid),
9162306a36Sopenharmony_ci			      "r" (ECSR_DEV_BASE(devid) | SBI_INTR_TID),
9262306a36Sopenharmony_ci			      "i" (ASI_M_CTL));
9362306a36Sopenharmony_ci}
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_cistatic inline int get_sbi_ctl(int devid, int cfgno)
9662306a36Sopenharmony_ci{
9762306a36Sopenharmony_ci	int cfg;
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci	__asm__ __volatile__ ("lda [%1] %2, %0" :
10062306a36Sopenharmony_ci			      "=r" (cfg) :
10162306a36Sopenharmony_ci			      "r" ((ECSR_DEV_BASE(devid) | SBI_CFG0) + (cfgno<<2)),
10262306a36Sopenharmony_ci			      "i" (ASI_M_CTL));
10362306a36Sopenharmony_ci	return cfg;
10462306a36Sopenharmony_ci}
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_cistatic inline void set_sbi_ctl(int devid, int cfgno, int cfg)
10762306a36Sopenharmony_ci{
10862306a36Sopenharmony_ci	__asm__ __volatile__ ("sta %0, [%1] %2" : :
10962306a36Sopenharmony_ci			      "r" (cfg),
11062306a36Sopenharmony_ci			      "r" ((ECSR_DEV_BASE(devid) | SBI_CFG0) + (cfgno<<2)),
11162306a36Sopenharmony_ci			      "i" (ASI_M_CTL));
11262306a36Sopenharmony_ci}
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci#endif /* !__ASSEMBLY__ */
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci#endif /* !(_SPARC_SBI_H) */
117