18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ARConnect IP Support (Multi core enabler: Cross core IPI, RTC ...) 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com) 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef __SOC_ARC_MCIP_H 98c2ecf20Sopenharmony_ci#define __SOC_ARC_MCIP_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <soc/arc/aux.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define ARC_REG_MCIP_BCR 0x0d0 148c2ecf20Sopenharmony_ci#define ARC_REG_MCIP_IDU_BCR 0x0D5 158c2ecf20Sopenharmony_ci#define ARC_REG_GFRC_BUILD 0x0D6 168c2ecf20Sopenharmony_ci#define ARC_REG_MCIP_CMD 0x600 178c2ecf20Sopenharmony_ci#define ARC_REG_MCIP_WDATA 0x601 188c2ecf20Sopenharmony_ci#define ARC_REG_MCIP_READBACK 0x602 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct mcip_cmd { 218c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_BIG_ENDIAN 228c2ecf20Sopenharmony_ci unsigned int pad:8, param:16, cmd:8; 238c2ecf20Sopenharmony_ci#else 248c2ecf20Sopenharmony_ci unsigned int cmd:8, param:16, pad:8; 258c2ecf20Sopenharmony_ci#endif 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define CMD_INTRPT_GENERATE_IRQ 0x01 288c2ecf20Sopenharmony_ci#define CMD_INTRPT_GENERATE_ACK 0x02 298c2ecf20Sopenharmony_ci#define CMD_INTRPT_READ_STATUS 0x03 308c2ecf20Sopenharmony_ci#define CMD_INTRPT_CHECK_SOURCE 0x04 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* Semaphore Commands */ 338c2ecf20Sopenharmony_ci#define CMD_SEMA_CLAIM_AND_READ 0x11 348c2ecf20Sopenharmony_ci#define CMD_SEMA_RELEASE 0x12 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define CMD_DEBUG_SET_MASK 0x34 378c2ecf20Sopenharmony_ci#define CMD_DEBUG_READ_MASK 0x35 388c2ecf20Sopenharmony_ci#define CMD_DEBUG_SET_SELECT 0x36 398c2ecf20Sopenharmony_ci#define CMD_DEBUG_READ_SELECT 0x37 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define CMD_GFRC_READ_LO 0x42 428c2ecf20Sopenharmony_ci#define CMD_GFRC_READ_HI 0x43 438c2ecf20Sopenharmony_ci#define CMD_GFRC_SET_CORE 0x47 448c2ecf20Sopenharmony_ci#define CMD_GFRC_READ_CORE 0x48 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define CMD_IDU_ENABLE 0x71 478c2ecf20Sopenharmony_ci#define CMD_IDU_DISABLE 0x72 488c2ecf20Sopenharmony_ci#define CMD_IDU_SET_MODE 0x74 498c2ecf20Sopenharmony_ci#define CMD_IDU_READ_MODE 0x75 508c2ecf20Sopenharmony_ci#define CMD_IDU_SET_DEST 0x76 518c2ecf20Sopenharmony_ci#define CMD_IDU_ACK_CIRQ 0x79 528c2ecf20Sopenharmony_ci#define CMD_IDU_SET_MASK 0x7C 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define IDU_M_TRIG_LEVEL 0x0 558c2ecf20Sopenharmony_ci#define IDU_M_TRIG_EDGE 0x1 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define IDU_M_DISTRI_RR 0x0 588c2ecf20Sopenharmony_ci#define IDU_M_DISTRI_DEST 0x2 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct mcip_bcr { 628c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_BIG_ENDIAN 638c2ecf20Sopenharmony_ci unsigned int pad4:6, pw_dom:1, pad3:1, 648c2ecf20Sopenharmony_ci idu:1, pad2:1, num_cores:6, 658c2ecf20Sopenharmony_ci pad:1, gfrc:1, dbg:1, pw:1, 668c2ecf20Sopenharmony_ci msg:1, sem:1, ipi:1, slv:1, 678c2ecf20Sopenharmony_ci ver:8; 688c2ecf20Sopenharmony_ci#else 698c2ecf20Sopenharmony_ci unsigned int ver:8, 708c2ecf20Sopenharmony_ci slv:1, ipi:1, sem:1, msg:1, 718c2ecf20Sopenharmony_ci pw:1, dbg:1, gfrc:1, pad:1, 728c2ecf20Sopenharmony_ci num_cores:6, pad2:1, idu:1, 738c2ecf20Sopenharmony_ci pad3:1, pw_dom:1, pad4:6; 748c2ecf20Sopenharmony_ci#endif 758c2ecf20Sopenharmony_ci}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistruct mcip_idu_bcr { 788c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_BIG_ENDIAN 798c2ecf20Sopenharmony_ci unsigned int pad:21, cirqnum:3, ver:8; 808c2ecf20Sopenharmony_ci#else 818c2ecf20Sopenharmony_ci unsigned int ver:8, cirqnum:3, pad:21; 828c2ecf20Sopenharmony_ci#endif 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* 878c2ecf20Sopenharmony_ci * Build register for IDU contains not an actual number of supported common 888c2ecf20Sopenharmony_ci * interrupts but an exponent of 2 which must be multiplied by 4 to 898c2ecf20Sopenharmony_ci * get a number of supported common interrupts. 908c2ecf20Sopenharmony_ci */ 918c2ecf20Sopenharmony_ci#define mcip_idu_bcr_to_nr_irqs(bcr) (4 * (1 << (bcr).cirqnum)) 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* 948c2ecf20Sopenharmony_ci * MCIP programming model 958c2ecf20Sopenharmony_ci * 968c2ecf20Sopenharmony_ci * - Simple commands write {cmd:8,param:16} to MCIP_CMD aux reg 978c2ecf20Sopenharmony_ci * (param could be irq, common_irq, core_id ...) 988c2ecf20Sopenharmony_ci * - More involved commands setup MCIP_WDATA with cmd specific data 998c2ecf20Sopenharmony_ci * before invoking the simple command 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_cistatic inline void __mcip_cmd(unsigned int cmd, unsigned int param) 1028c2ecf20Sopenharmony_ci{ 1038c2ecf20Sopenharmony_ci struct mcip_cmd buf; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci buf.pad = 0; 1068c2ecf20Sopenharmony_ci buf.cmd = cmd; 1078c2ecf20Sopenharmony_ci buf.param = param; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci WRITE_AUX(ARC_REG_MCIP_CMD, buf); 1108c2ecf20Sopenharmony_ci} 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci/* 1138c2ecf20Sopenharmony_ci * Setup additional data for a cmd 1148c2ecf20Sopenharmony_ci * Callers need to lock to ensure atomicity 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_cistatic inline void __mcip_cmd_data(unsigned int cmd, unsigned int param, 1178c2ecf20Sopenharmony_ci unsigned int data) 1188c2ecf20Sopenharmony_ci{ 1198c2ecf20Sopenharmony_ci write_aux_reg(ARC_REG_MCIP_WDATA, data); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci __mcip_cmd(cmd, param); 1228c2ecf20Sopenharmony_ci} 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/* 1258c2ecf20Sopenharmony_ci * Read MCIP register 1268c2ecf20Sopenharmony_ci */ 1278c2ecf20Sopenharmony_cistatic inline unsigned int __mcip_cmd_read(unsigned int cmd, unsigned int param) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci __mcip_cmd(cmd, param); 1308c2ecf20Sopenharmony_ci return read_aux_reg(ARC_REG_MCIP_READBACK); 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#endif 134