18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * IBM ASM Service Processor Device Driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) IBM Corporation, 2004
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Max Asböck <amax@us.ibm.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* Condor service processor specific hardware definitions */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef __IBMASM_CONDOR_H__
138c2ecf20Sopenharmony_ci#define __IBMASM_CONDOR_H__
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <asm/io.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define VENDORID_IBM	0x1014
188c2ecf20Sopenharmony_ci#define DEVICEID_RSA	0x010F
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define GET_MFA_ADDR(x)  (x & 0xFFFFFF00)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define MAILBOX_FULL(x)  (x & 0x00000001)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define NO_MFAS_AVAILABLE     0xFFFFFFFF
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define INBOUND_QUEUE_PORT   0x40  /* contains address of next free MFA */
288c2ecf20Sopenharmony_ci#define OUTBOUND_QUEUE_PORT  0x44  /* contains address of posted MFA    */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define SP_INTR_MASK	0x00000008
318c2ecf20Sopenharmony_ci#define UART_INTR_MASK	0x00000010
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define INTR_STATUS_REGISTER   0x13A0
348c2ecf20Sopenharmony_ci#define INTR_CONTROL_REGISTER  0x13A4
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define SCOUT_COM_A_BASE         0x0000
378c2ecf20Sopenharmony_ci#define SCOUT_COM_B_BASE         0x0100
388c2ecf20Sopenharmony_ci#define SCOUT_COM_C_BASE         0x0200
398c2ecf20Sopenharmony_ci#define SCOUT_COM_D_BASE         0x0300
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic inline int sp_interrupt_pending(void __iomem *base_address)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	return SP_INTR_MASK & readl(base_address + INTR_STATUS_REGISTER);
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic inline int uart_interrupt_pending(void __iomem *base_address)
478c2ecf20Sopenharmony_ci{
488c2ecf20Sopenharmony_ci	return UART_INTR_MASK & readl(base_address + INTR_STATUS_REGISTER);
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic inline void ibmasm_enable_interrupts(void __iomem *base_address, int mask)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	void __iomem *ctrl_reg = base_address + INTR_CONTROL_REGISTER;
548c2ecf20Sopenharmony_ci	writel( readl(ctrl_reg) & ~mask, ctrl_reg);
558c2ecf20Sopenharmony_ci}
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistatic inline void ibmasm_disable_interrupts(void __iomem *base_address, int mask)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	void __iomem *ctrl_reg = base_address + INTR_CONTROL_REGISTER;
608c2ecf20Sopenharmony_ci	writel( readl(ctrl_reg) | mask, ctrl_reg);
618c2ecf20Sopenharmony_ci}
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic inline void enable_sp_interrupts(void __iomem *base_address)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	ibmasm_enable_interrupts(base_address, SP_INTR_MASK);
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic inline void disable_sp_interrupts(void __iomem *base_address)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	ibmasm_disable_interrupts(base_address, SP_INTR_MASK);
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic inline void enable_uart_interrupts(void __iomem *base_address)
748c2ecf20Sopenharmony_ci{
758c2ecf20Sopenharmony_ci	ibmasm_enable_interrupts(base_address, UART_INTR_MASK);
768c2ecf20Sopenharmony_ci}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cistatic inline void disable_uart_interrupts(void __iomem *base_address)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	ibmasm_disable_interrupts(base_address, UART_INTR_MASK);
818c2ecf20Sopenharmony_ci}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define valid_mfa(mfa)	( (mfa) != NO_MFAS_AVAILABLE )
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline u32 get_mfa_outbound(void __iomem *base_address)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	int retry;
888c2ecf20Sopenharmony_ci	u32 mfa;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	for (retry=0; retry<=10; retry++) {
918c2ecf20Sopenharmony_ci		mfa = readl(base_address + OUTBOUND_QUEUE_PORT);
928c2ecf20Sopenharmony_ci		if (valid_mfa(mfa))
938c2ecf20Sopenharmony_ci			break;
948c2ecf20Sopenharmony_ci	}
958c2ecf20Sopenharmony_ci	return mfa;
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic inline void set_mfa_outbound(void __iomem *base_address, u32 mfa)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	writel(mfa, base_address + OUTBOUND_QUEUE_PORT);
1018c2ecf20Sopenharmony_ci}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistatic inline u32 get_mfa_inbound(void __iomem *base_address)
1048c2ecf20Sopenharmony_ci{
1058c2ecf20Sopenharmony_ci	u32 mfa = readl(base_address + INBOUND_QUEUE_PORT);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	if (MAILBOX_FULL(mfa))
1088c2ecf20Sopenharmony_ci		return 0;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	return mfa;
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistatic inline void set_mfa_inbound(void __iomem *base_address, u32 mfa)
1148c2ecf20Sopenharmony_ci{
1158c2ecf20Sopenharmony_ci	writel(mfa, base_address + INBOUND_QUEUE_PORT);
1168c2ecf20Sopenharmony_ci}
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistatic inline struct i2o_message *get_i2o_message(void __iomem *base_address, u32 mfa)
1198c2ecf20Sopenharmony_ci{
1208c2ecf20Sopenharmony_ci	return (struct i2o_message *)(GET_MFA_ADDR(mfa) + base_address);
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#endif /* __IBMASM_CONDOR_H__ */
124