18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
58c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
118c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
128c2ecf20Sopenharmony_ci *     conditions are met:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
158c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
168c2ecf20Sopenharmony_ci *        disclaimer.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
198c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
208c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
218c2ecf20Sopenharmony_ci *        provided with the distribution.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
308c2ecf20Sopenharmony_ci * SOFTWARE.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#ifndef SOC_NPS_COMMON_H
348c2ecf20Sopenharmony_ci#define SOC_NPS_COMMON_H
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
378c2ecf20Sopenharmony_ci#define NPS_IPI_IRQ					5
388c2ecf20Sopenharmony_ci#endif
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define NPS_HOST_REG_BASE			0xF6000000
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define NPS_MSU_BLKID				0x018
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define CTOP_INST_RSPI_GIC_0_R12		0x3C56117E
458c2ecf20Sopenharmony_ci#define CTOP_INST_MOV2B_FLIP_R3_B1_B2_INST	0x5B60
468c2ecf20Sopenharmony_ci#define CTOP_INST_MOV2B_FLIP_R3_B1_B2_LIMM	0x00010422
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#ifndef AUX_IENABLE
498c2ecf20Sopenharmony_ci#define AUX_IENABLE				0x40c
508c2ecf20Sopenharmony_ci#endif
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define CTOP_AUX_IACK				(0xFFFFF800 + 0x088)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* In order to increase compilation test coverage */
578c2ecf20Sopenharmony_ci#ifdef CONFIG_ARC
588c2ecf20Sopenharmony_cistatic inline void nps_ack_gic(void)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	__asm__ __volatile__ (
618c2ecf20Sopenharmony_ci	"       .word %0\n"
628c2ecf20Sopenharmony_ci	:
638c2ecf20Sopenharmony_ci	: "i"(CTOP_INST_RSPI_GIC_0_R12)
648c2ecf20Sopenharmony_ci	: "memory");
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci#else
678c2ecf20Sopenharmony_cistatic inline void nps_ack_gic(void) { }
688c2ecf20Sopenharmony_ci#define write_aux_reg(r, v)
698c2ecf20Sopenharmony_ci#define read_aux_reg(r) 0
708c2ecf20Sopenharmony_ci#endif
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* CPU global ID */
738c2ecf20Sopenharmony_cistruct global_id {
748c2ecf20Sopenharmony_ci	union {
758c2ecf20Sopenharmony_ci		struct {
768c2ecf20Sopenharmony_ci#ifdef CONFIG_EZNPS_MTM_EXT
778c2ecf20Sopenharmony_ci			u32 __reserved:20, cluster:4, core:4, thread:4;
788c2ecf20Sopenharmony_ci#else
798c2ecf20Sopenharmony_ci			u32 __reserved:24, cluster:4, core:4;
808c2ecf20Sopenharmony_ci#endif
818c2ecf20Sopenharmony_ci		};
828c2ecf20Sopenharmony_ci		u32 value;
838c2ecf20Sopenharmony_ci	};
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/*
878c2ecf20Sopenharmony_ci * Convert logical to physical CPU IDs
888c2ecf20Sopenharmony_ci *
898c2ecf20Sopenharmony_ci * The conversion swap bits 1 and 2 of cluster id (out of 4 bits)
908c2ecf20Sopenharmony_ci * Now quad of logical clusters id's are adjacent physically,
918c2ecf20Sopenharmony_ci * and not like the id's physically came with each cluster.
928c2ecf20Sopenharmony_ci * Below table is 4x4 mesh of core clusters as it layout on chip.
938c2ecf20Sopenharmony_ci * Cluster ids are in format: logical (physical)
948c2ecf20Sopenharmony_ci *
958c2ecf20Sopenharmony_ci *    -----------------   ------------------
968c2ecf20Sopenharmony_ci * 3 |  5 (3)   7 (7)  | | 13 (11)   15 (15)|
978c2ecf20Sopenharmony_ci *
988c2ecf20Sopenharmony_ci * 2 |  4 (2)   6 (6)  | | 12 (10)   14 (14)|
998c2ecf20Sopenharmony_ci *    -----------------   ------------------
1008c2ecf20Sopenharmony_ci * 1 |  1 (1)   3 (5)  | |  9  (9)   11 (13)|
1018c2ecf20Sopenharmony_ci *
1028c2ecf20Sopenharmony_ci * 0 |  0 (0)   2 (4)  | |  8  (8)   10 (12)|
1038c2ecf20Sopenharmony_ci *    -----------------   ------------------
1048c2ecf20Sopenharmony_ci *       0       1            2        3
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_cistatic inline int nps_cluster_logic_to_phys(int cluster)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci#ifdef __arc__
1098c2ecf20Sopenharmony_ci	 __asm__ __volatile__(
1108c2ecf20Sopenharmony_ci	"       mov r3,%0\n"
1118c2ecf20Sopenharmony_ci	"       .short %1\n"
1128c2ecf20Sopenharmony_ci	"       .word %2\n"
1138c2ecf20Sopenharmony_ci	"       mov %0,r3\n"
1148c2ecf20Sopenharmony_ci	: "+r"(cluster)
1158c2ecf20Sopenharmony_ci	: "i"(CTOP_INST_MOV2B_FLIP_R3_B1_B2_INST),
1168c2ecf20Sopenharmony_ci	  "i"(CTOP_INST_MOV2B_FLIP_R3_B1_B2_LIMM)
1178c2ecf20Sopenharmony_ci	: "r3");
1188c2ecf20Sopenharmony_ci#endif
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	return cluster;
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define NPS_CPU_TO_CLUSTER_NUM(cpu) \
1248c2ecf20Sopenharmony_ci	({ struct global_id gid; gid.value = cpu; \
1258c2ecf20Sopenharmony_ci		nps_cluster_logic_to_phys(gid.cluster); })
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistruct nps_host_reg_address {
1288c2ecf20Sopenharmony_ci	union {
1298c2ecf20Sopenharmony_ci		struct {
1308c2ecf20Sopenharmony_ci			u32 base:8, cl_x:4, cl_y:4,
1318c2ecf20Sopenharmony_ci			blkid:6, reg:8, __reserved:2;
1328c2ecf20Sopenharmony_ci		};
1338c2ecf20Sopenharmony_ci		u32 value;
1348c2ecf20Sopenharmony_ci	};
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistruct nps_host_reg_address_non_cl {
1388c2ecf20Sopenharmony_ci	union {
1398c2ecf20Sopenharmony_ci		struct {
1408c2ecf20Sopenharmony_ci			u32 base:7, blkid:11, reg:12, __reserved:2;
1418c2ecf20Sopenharmony_ci		};
1428c2ecf20Sopenharmony_ci		u32 value;
1438c2ecf20Sopenharmony_ci	};
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cistatic inline void *nps_host_reg_non_cl(u32 blkid, u32 reg)
1478c2ecf20Sopenharmony_ci{
1488c2ecf20Sopenharmony_ci	struct nps_host_reg_address_non_cl reg_address;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	reg_address.value = NPS_HOST_REG_BASE;
1518c2ecf20Sopenharmony_ci	reg_address.blkid = blkid;
1528c2ecf20Sopenharmony_ci	reg_address.reg = reg;
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	return (void *)reg_address.value;
1558c2ecf20Sopenharmony_ci}
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistatic inline void *nps_host_reg(u32 cpu, u32 blkid, u32 reg)
1588c2ecf20Sopenharmony_ci{
1598c2ecf20Sopenharmony_ci	struct nps_host_reg_address reg_address;
1608c2ecf20Sopenharmony_ci	u32 cl = NPS_CPU_TO_CLUSTER_NUM(cpu);
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	reg_address.value = NPS_HOST_REG_BASE;
1638c2ecf20Sopenharmony_ci	reg_address.cl_x  = (cl >> 2) & 0x3;
1648c2ecf20Sopenharmony_ci	reg_address.cl_y  = cl & 0x3;
1658c2ecf20Sopenharmony_ci	reg_address.blkid = blkid;
1668c2ecf20Sopenharmony_ci	reg_address.reg   = reg;
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	return (void *)reg_address.value;
1698c2ecf20Sopenharmony_ci}
1708c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#endif /* SOC_NPS_COMMON_H */
173