18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
38c2ecf20Sopenharmony_ci * reserved.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
68c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
78c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
88c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the NetLogic
98c2ecf20Sopenharmony_ci * license below:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
128c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
138c2ecf20Sopenharmony_ci * are met:
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
168c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
178c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
188c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
198c2ecf20Sopenharmony_ci *    the documentation and/or other materials provided with the
208c2ecf20Sopenharmony_ci *    distribution.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
238c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
248c2ecf20Sopenharmony_ci * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
258c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
268c2ecf20Sopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
278c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
288c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
298c2ecf20Sopenharmony_ci * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
308c2ecf20Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
318c2ecf20Sopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
328c2ecf20Sopenharmony_ci * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef _NLM_HAL_PIC_H
368c2ecf20Sopenharmony_ci#define _NLM_HAL_PIC_H
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* PIC Specific registers */
398c2ecf20Sopenharmony_ci#define PIC_CTRL		0x00
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* PIC control register defines */
428c2ecf20Sopenharmony_ci#define PIC_CTRL_ITV		32 /* interrupt timeout value */
438c2ecf20Sopenharmony_ci#define PIC_CTRL_ICI		19 /* ICI interrupt timeout enable */
448c2ecf20Sopenharmony_ci#define PIC_CTRL_ITE		18 /* interrupt timeout enable */
458c2ecf20Sopenharmony_ci#define PIC_CTRL_STE		10 /* system timer interrupt enable */
468c2ecf20Sopenharmony_ci#define PIC_CTRL_WWR1		8  /* watchdog 1 wraparound count for reset */
478c2ecf20Sopenharmony_ci#define PIC_CTRL_WWR0		6  /* watchdog 0 wraparound count for reset */
488c2ecf20Sopenharmony_ci#define PIC_CTRL_WWN1		4  /* watchdog 1 wraparound count for NMI */
498c2ecf20Sopenharmony_ci#define PIC_CTRL_WWN0		2  /* watchdog 0 wraparound count for NMI */
508c2ecf20Sopenharmony_ci#define PIC_CTRL_WTE		0  /* watchdog timer enable */
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* PIC Status register defines */
538c2ecf20Sopenharmony_ci#define PIC_ICI_STATUS		33 /* ICI interrupt timeout status */
548c2ecf20Sopenharmony_ci#define PIC_ITE_STATUS		32 /* interrupt timeout status */
558c2ecf20Sopenharmony_ci#define PIC_STS_STATUS		4  /* System timer interrupt status */
568c2ecf20Sopenharmony_ci#define PIC_WNS_STATUS		2  /* NMI status for watchdog timers */
578c2ecf20Sopenharmony_ci#define PIC_WIS_STATUS		0  /* Interrupt status for watchdog timers */
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* PIC IPI control register offsets */
608c2ecf20Sopenharmony_ci#define PIC_IPICTRL_NMI		32
618c2ecf20Sopenharmony_ci#define PIC_IPICTRL_RIV		20 /* received interrupt vector */
628c2ecf20Sopenharmony_ci#define PIC_IPICTRL_IDB		16 /* interrupt destination base */
638c2ecf20Sopenharmony_ci#define PIC_IPICTRL_DTE		 0 /* interrupt destination thread enables */
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* PIC IRT register offsets */
668c2ecf20Sopenharmony_ci#define PIC_IRT_ENABLE		31
678c2ecf20Sopenharmony_ci#define PIC_IRT_NMI		29
688c2ecf20Sopenharmony_ci#define PIC_IRT_SCH		28 /* Scheduling scheme */
698c2ecf20Sopenharmony_ci#define PIC_IRT_RVEC		20 /* Interrupt receive vectors */
708c2ecf20Sopenharmony_ci#define PIC_IRT_DT		19 /* Destination type */
718c2ecf20Sopenharmony_ci#define PIC_IRT_DB		16 /* Destination base */
728c2ecf20Sopenharmony_ci#define PIC_IRT_DTE		0  /* Destination thread enables */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define PIC_BYTESWAP		0x02
758c2ecf20Sopenharmony_ci#define PIC_STATUS		0x04
768c2ecf20Sopenharmony_ci#define PIC_INTR_TIMEOUT	0x06
778c2ecf20Sopenharmony_ci#define PIC_ICI0_INTR_TIMEOUT	0x08
788c2ecf20Sopenharmony_ci#define PIC_ICI1_INTR_TIMEOUT	0x0a
798c2ecf20Sopenharmony_ci#define PIC_ICI2_INTR_TIMEOUT	0x0c
808c2ecf20Sopenharmony_ci#define PIC_IPI_CTL		0x0e
818c2ecf20Sopenharmony_ci#define PIC_INT_ACK		0x10
828c2ecf20Sopenharmony_ci#define PIC_INT_PENDING0	0x12
838c2ecf20Sopenharmony_ci#define PIC_INT_PENDING1	0x14
848c2ecf20Sopenharmony_ci#define PIC_INT_PENDING2	0x16
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define PIC_WDOG0_MAXVAL	0x18
878c2ecf20Sopenharmony_ci#define PIC_WDOG0_COUNT		0x1a
888c2ecf20Sopenharmony_ci#define PIC_WDOG0_ENABLE0	0x1c
898c2ecf20Sopenharmony_ci#define PIC_WDOG0_ENABLE1	0x1e
908c2ecf20Sopenharmony_ci#define PIC_WDOG0_BEATCMD	0x20
918c2ecf20Sopenharmony_ci#define PIC_WDOG0_BEAT0		0x22
928c2ecf20Sopenharmony_ci#define PIC_WDOG0_BEAT1		0x24
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define PIC_WDOG1_MAXVAL	0x26
958c2ecf20Sopenharmony_ci#define PIC_WDOG1_COUNT		0x28
968c2ecf20Sopenharmony_ci#define PIC_WDOG1_ENABLE0	0x2a
978c2ecf20Sopenharmony_ci#define PIC_WDOG1_ENABLE1	0x2c
988c2ecf20Sopenharmony_ci#define PIC_WDOG1_BEATCMD	0x2e
998c2ecf20Sopenharmony_ci#define PIC_WDOG1_BEAT0		0x30
1008c2ecf20Sopenharmony_ci#define PIC_WDOG1_BEAT1		0x32
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#define PIC_WDOG_MAXVAL(i)	(PIC_WDOG0_MAXVAL + ((i) ? 7 : 0))
1038c2ecf20Sopenharmony_ci#define PIC_WDOG_COUNT(i)	(PIC_WDOG0_COUNT + ((i) ? 7 : 0))
1048c2ecf20Sopenharmony_ci#define PIC_WDOG_ENABLE0(i)	(PIC_WDOG0_ENABLE0 + ((i) ? 7 : 0))
1058c2ecf20Sopenharmony_ci#define PIC_WDOG_ENABLE1(i)	(PIC_WDOG0_ENABLE1 + ((i) ? 7 : 0))
1068c2ecf20Sopenharmony_ci#define PIC_WDOG_BEATCMD(i)	(PIC_WDOG0_BEATCMD + ((i) ? 7 : 0))
1078c2ecf20Sopenharmony_ci#define PIC_WDOG_BEAT0(i)	(PIC_WDOG0_BEAT0 + ((i) ? 7 : 0))
1088c2ecf20Sopenharmony_ci#define PIC_WDOG_BEAT1(i)	(PIC_WDOG0_BEAT1 + ((i) ? 7 : 0))
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define PIC_TIMER0_MAXVAL    0x34
1118c2ecf20Sopenharmony_ci#define PIC_TIMER1_MAXVAL    0x36
1128c2ecf20Sopenharmony_ci#define PIC_TIMER2_MAXVAL    0x38
1138c2ecf20Sopenharmony_ci#define PIC_TIMER3_MAXVAL    0x3a
1148c2ecf20Sopenharmony_ci#define PIC_TIMER4_MAXVAL    0x3c
1158c2ecf20Sopenharmony_ci#define PIC_TIMER5_MAXVAL    0x3e
1168c2ecf20Sopenharmony_ci#define PIC_TIMER6_MAXVAL    0x40
1178c2ecf20Sopenharmony_ci#define PIC_TIMER7_MAXVAL    0x42
1188c2ecf20Sopenharmony_ci#define PIC_TIMER_MAXVAL(i)  (PIC_TIMER0_MAXVAL + ((i) * 2))
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#define PIC_TIMER0_COUNT     0x44
1218c2ecf20Sopenharmony_ci#define PIC_TIMER1_COUNT     0x46
1228c2ecf20Sopenharmony_ci#define PIC_TIMER2_COUNT     0x48
1238c2ecf20Sopenharmony_ci#define PIC_TIMER3_COUNT     0x4a
1248c2ecf20Sopenharmony_ci#define PIC_TIMER4_COUNT     0x4c
1258c2ecf20Sopenharmony_ci#define PIC_TIMER5_COUNT     0x4e
1268c2ecf20Sopenharmony_ci#define PIC_TIMER6_COUNT     0x50
1278c2ecf20Sopenharmony_ci#define PIC_TIMER7_COUNT     0x52
1288c2ecf20Sopenharmony_ci#define PIC_TIMER_COUNT(i)   (PIC_TIMER0_COUNT + ((i) * 2))
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define PIC_ITE0_N0_N1		0x54
1318c2ecf20Sopenharmony_ci#define PIC_ITE1_N0_N1		0x58
1328c2ecf20Sopenharmony_ci#define PIC_ITE2_N0_N1		0x5c
1338c2ecf20Sopenharmony_ci#define PIC_ITE3_N0_N1		0x60
1348c2ecf20Sopenharmony_ci#define PIC_ITE4_N0_N1		0x64
1358c2ecf20Sopenharmony_ci#define PIC_ITE5_N0_N1		0x68
1368c2ecf20Sopenharmony_ci#define PIC_ITE6_N0_N1		0x6c
1378c2ecf20Sopenharmony_ci#define PIC_ITE7_N0_N1		0x70
1388c2ecf20Sopenharmony_ci#define PIC_ITE_N0_N1(i)	(PIC_ITE0_N0_N1 + ((i) * 4))
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci#define PIC_ITE0_N2_N3		0x56
1418c2ecf20Sopenharmony_ci#define PIC_ITE1_N2_N3		0x5a
1428c2ecf20Sopenharmony_ci#define PIC_ITE2_N2_N3		0x5e
1438c2ecf20Sopenharmony_ci#define PIC_ITE3_N2_N3		0x62
1448c2ecf20Sopenharmony_ci#define PIC_ITE4_N2_N3		0x66
1458c2ecf20Sopenharmony_ci#define PIC_ITE5_N2_N3		0x6a
1468c2ecf20Sopenharmony_ci#define PIC_ITE6_N2_N3		0x6e
1478c2ecf20Sopenharmony_ci#define PIC_ITE7_N2_N3		0x72
1488c2ecf20Sopenharmony_ci#define PIC_ITE_N2_N3(i)	(PIC_ITE0_N2_N3 + ((i) * 4))
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#define PIC_IRT0		0x74
1518c2ecf20Sopenharmony_ci#define PIC_IRT(i)		(PIC_IRT0 + ((i) * 2))
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#define PIC_9XX_PENDING_0	0x6
1548c2ecf20Sopenharmony_ci#define PIC_9XX_PENDING_1	0x8
1558c2ecf20Sopenharmony_ci#define PIC_9XX_PENDING_2	0xa
1568c2ecf20Sopenharmony_ci#define PIC_9XX_PENDING_3	0xc
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#define PIC_9XX_IRT0		0x1c0
1598c2ecf20Sopenharmony_ci#define PIC_9XX_IRT(i)		(PIC_9XX_IRT0 + ((i) * 2))
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/*
1628c2ecf20Sopenharmony_ci *    IRT Map
1638c2ecf20Sopenharmony_ci */
1648c2ecf20Sopenharmony_ci#define PIC_NUM_IRTS		160
1658c2ecf20Sopenharmony_ci#define PIC_9XX_NUM_IRTS	256
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#define PIC_IRT_WD_0_INDEX	0
1688c2ecf20Sopenharmony_ci#define PIC_IRT_WD_1_INDEX	1
1698c2ecf20Sopenharmony_ci#define PIC_IRT_WD_NMI_0_INDEX	2
1708c2ecf20Sopenharmony_ci#define PIC_IRT_WD_NMI_1_INDEX	3
1718c2ecf20Sopenharmony_ci#define PIC_IRT_TIMER_0_INDEX	4
1728c2ecf20Sopenharmony_ci#define PIC_IRT_TIMER_1_INDEX	5
1738c2ecf20Sopenharmony_ci#define PIC_IRT_TIMER_2_INDEX	6
1748c2ecf20Sopenharmony_ci#define PIC_IRT_TIMER_3_INDEX	7
1758c2ecf20Sopenharmony_ci#define PIC_IRT_TIMER_4_INDEX	8
1768c2ecf20Sopenharmony_ci#define PIC_IRT_TIMER_5_INDEX	9
1778c2ecf20Sopenharmony_ci#define PIC_IRT_TIMER_6_INDEX	10
1788c2ecf20Sopenharmony_ci#define PIC_IRT_TIMER_7_INDEX	11
1798c2ecf20Sopenharmony_ci#define PIC_IRT_CLOCK_INDEX	PIC_IRT_TIMER_7_INDEX
1808c2ecf20Sopenharmony_ci#define PIC_IRT_TIMER_INDEX(num)	((num) + PIC_IRT_TIMER_0_INDEX)
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* 11 and 12 */
1848c2ecf20Sopenharmony_ci#define PIC_NUM_MSG_Q_IRTS	32
1858c2ecf20Sopenharmony_ci#define PIC_IRT_MSG_Q0_INDEX	12
1868c2ecf20Sopenharmony_ci#define PIC_IRT_MSG_Q_INDEX(qid)	((qid) + PIC_IRT_MSG_Q0_INDEX)
1878c2ecf20Sopenharmony_ci/* 12 to 43 */
1888c2ecf20Sopenharmony_ci#define PIC_IRT_MSG_0_INDEX	44
1898c2ecf20Sopenharmony_ci#define PIC_IRT_MSG_1_INDEX	45
1908c2ecf20Sopenharmony_ci/* 44 and 45 */
1918c2ecf20Sopenharmony_ci#define PIC_NUM_PCIE_MSIX_IRTS	32
1928c2ecf20Sopenharmony_ci#define PIC_IRT_PCIE_MSIX_0_INDEX	46
1938c2ecf20Sopenharmony_ci#define PIC_IRT_PCIE_MSIX_INDEX(num)	((num) + PIC_IRT_PCIE_MSIX_0_INDEX)
1948c2ecf20Sopenharmony_ci/* 46 to 77 */
1958c2ecf20Sopenharmony_ci#define PIC_NUM_PCIE_LINK_IRTS		4
1968c2ecf20Sopenharmony_ci#define PIC_IRT_PCIE_LINK_0_INDEX	78
1978c2ecf20Sopenharmony_ci#define PIC_IRT_PCIE_LINK_1_INDEX	79
1988c2ecf20Sopenharmony_ci#define PIC_IRT_PCIE_LINK_2_INDEX	80
1998c2ecf20Sopenharmony_ci#define PIC_IRT_PCIE_LINK_3_INDEX	81
2008c2ecf20Sopenharmony_ci#define PIC_IRT_PCIE_LINK_INDEX(num)	((num) + PIC_IRT_PCIE_LINK_0_INDEX)
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci#define PIC_9XX_IRT_PCIE_LINK_0_INDEX	191
2038c2ecf20Sopenharmony_ci#define PIC_9XX_IRT_PCIE_LINK_INDEX(num) \
2048c2ecf20Sopenharmony_ci				((num) + PIC_9XX_IRT_PCIE_LINK_0_INDEX)
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci#define PIC_CLOCK_TIMER			7
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci#if !defined(LOCORE) && !defined(__ASSEMBLY__)
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci/*
2118c2ecf20Sopenharmony_ci *   Misc
2128c2ecf20Sopenharmony_ci */
2138c2ecf20Sopenharmony_ci#define PIC_IRT_VALID			1
2148c2ecf20Sopenharmony_ci#define PIC_LOCAL_SCHEDULING		1
2158c2ecf20Sopenharmony_ci#define PIC_GLOBAL_SCHEDULING		0
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci#define nlm_read_pic_reg(b, r)	nlm_read_reg64(b, r)
2188c2ecf20Sopenharmony_ci#define nlm_write_pic_reg(b, r, v) nlm_write_reg64(b, r, v)
2198c2ecf20Sopenharmony_ci#define nlm_get_pic_pcibase(node)	nlm_pcicfg_base(cpu_is_xlp9xx() ? \
2208c2ecf20Sopenharmony_ci		XLP9XX_IO_PIC_OFFSET(node) : XLP_IO_PIC_OFFSET(node))
2218c2ecf20Sopenharmony_ci#define nlm_get_pic_regbase(node) (nlm_get_pic_pcibase(node) + XLP_IO_PCI_HDRSZ)
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci/* We use PIC on node 0 as a timer */
2248c2ecf20Sopenharmony_ci#define pic_timer_freq()		nlm_get_pic_frequency(0)
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci/* IRT and h/w interrupt routines */
2278c2ecf20Sopenharmony_cistatic inline void
2288c2ecf20Sopenharmony_cinlm_9xx_pic_write_irt(uint64_t base, int irt_num, int en, int nmi,
2298c2ecf20Sopenharmony_ci	int sch, int vec, int dt, int db, int cpu)
2308c2ecf20Sopenharmony_ci{
2318c2ecf20Sopenharmony_ci	uint64_t val;
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	val = (((uint64_t)en & 0x1) << 22) | ((nmi & 0x1) << 23) |
2348c2ecf20Sopenharmony_ci			((0 /*mc*/) << 20) | ((vec & 0x3f) << 24) |
2358c2ecf20Sopenharmony_ci			((dt & 0x1) << 21) | (0 /*ptr*/ << 16) |
2368c2ecf20Sopenharmony_ci			(cpu & 0x3ff);
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	nlm_write_pic_reg(base, PIC_9XX_IRT(irt_num), val);
2398c2ecf20Sopenharmony_ci}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistatic inline void
2428c2ecf20Sopenharmony_cinlm_pic_write_irt(uint64_t base, int irt_num, int en, int nmi,
2438c2ecf20Sopenharmony_ci	int sch, int vec, int dt, int db, int dte)
2448c2ecf20Sopenharmony_ci{
2458c2ecf20Sopenharmony_ci	uint64_t val;
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	val = (((uint64_t)en & 0x1) << 31) | ((nmi & 0x1) << 29) |
2488c2ecf20Sopenharmony_ci			((sch & 0x1) << 28) | ((vec & 0x3f) << 20) |
2498c2ecf20Sopenharmony_ci			((dt & 0x1) << 19) | ((db & 0x7) << 16) |
2508c2ecf20Sopenharmony_ci			(dte & 0xffff);
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	nlm_write_pic_reg(base, PIC_IRT(irt_num), val);
2538c2ecf20Sopenharmony_ci}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistatic inline void
2568c2ecf20Sopenharmony_cinlm_pic_write_irt_direct(uint64_t base, int irt_num, int en, int nmi,
2578c2ecf20Sopenharmony_ci	int sch, int vec, int cpu)
2588c2ecf20Sopenharmony_ci{
2598c2ecf20Sopenharmony_ci	if (cpu_is_xlp9xx())
2608c2ecf20Sopenharmony_ci		nlm_9xx_pic_write_irt(base, irt_num, en, nmi, sch, vec,
2618c2ecf20Sopenharmony_ci							1, 0, cpu);
2628c2ecf20Sopenharmony_ci	else
2638c2ecf20Sopenharmony_ci		nlm_pic_write_irt(base, irt_num, en, nmi, sch, vec, 1,
2648c2ecf20Sopenharmony_ci			(cpu >> 4),		/* thread group */
2658c2ecf20Sopenharmony_ci			1 << (cpu & 0xf));	/* thread mask */
2668c2ecf20Sopenharmony_ci}
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_cistatic inline uint64_t
2698c2ecf20Sopenharmony_cinlm_pic_read_timer(uint64_t base, int timer)
2708c2ecf20Sopenharmony_ci{
2718c2ecf20Sopenharmony_ci	return nlm_read_pic_reg(base, PIC_TIMER_COUNT(timer));
2728c2ecf20Sopenharmony_ci}
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_cistatic inline uint32_t
2758c2ecf20Sopenharmony_cinlm_pic_read_timer32(uint64_t base, int timer)
2768c2ecf20Sopenharmony_ci{
2778c2ecf20Sopenharmony_ci	return (uint32_t)nlm_read_pic_reg(base, PIC_TIMER_COUNT(timer));
2788c2ecf20Sopenharmony_ci}
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cistatic inline void
2818c2ecf20Sopenharmony_cinlm_pic_write_timer(uint64_t base, int timer, uint64_t value)
2828c2ecf20Sopenharmony_ci{
2838c2ecf20Sopenharmony_ci	nlm_write_pic_reg(base, PIC_TIMER_COUNT(timer), value);
2848c2ecf20Sopenharmony_ci}
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_cistatic inline void
2878c2ecf20Sopenharmony_cinlm_pic_set_timer(uint64_t base, int timer, uint64_t value, int irq, int cpu)
2888c2ecf20Sopenharmony_ci{
2898c2ecf20Sopenharmony_ci	uint64_t pic_ctrl = nlm_read_pic_reg(base, PIC_CTRL);
2908c2ecf20Sopenharmony_ci	int en;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	en = (irq > 0);
2938c2ecf20Sopenharmony_ci	nlm_write_pic_reg(base, PIC_TIMER_MAXVAL(timer), value);
2948c2ecf20Sopenharmony_ci	nlm_pic_write_irt_direct(base, PIC_IRT_TIMER_INDEX(timer),
2958c2ecf20Sopenharmony_ci		en, 0, 0, irq, cpu);
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	/* enable the timer */
2988c2ecf20Sopenharmony_ci	pic_ctrl |= (1 << (PIC_CTRL_STE + timer));
2998c2ecf20Sopenharmony_ci	nlm_write_pic_reg(base, PIC_CTRL, pic_ctrl);
3008c2ecf20Sopenharmony_ci}
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_cistatic inline void
3038c2ecf20Sopenharmony_cinlm_pic_enable_irt(uint64_t base, int irt)
3048c2ecf20Sopenharmony_ci{
3058c2ecf20Sopenharmony_ci	uint64_t reg;
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	if (cpu_is_xlp9xx()) {
3088c2ecf20Sopenharmony_ci		reg = nlm_read_pic_reg(base, PIC_9XX_IRT(irt));
3098c2ecf20Sopenharmony_ci		nlm_write_pic_reg(base, PIC_9XX_IRT(irt), reg | (1 << 22));
3108c2ecf20Sopenharmony_ci	} else {
3118c2ecf20Sopenharmony_ci		reg = nlm_read_pic_reg(base, PIC_IRT(irt));
3128c2ecf20Sopenharmony_ci		nlm_write_pic_reg(base, PIC_IRT(irt), reg | (1u << 31));
3138c2ecf20Sopenharmony_ci	}
3148c2ecf20Sopenharmony_ci}
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_cistatic inline void
3178c2ecf20Sopenharmony_cinlm_pic_disable_irt(uint64_t base, int irt)
3188c2ecf20Sopenharmony_ci{
3198c2ecf20Sopenharmony_ci	uint64_t reg;
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci	if (cpu_is_xlp9xx()) {
3228c2ecf20Sopenharmony_ci		reg = nlm_read_pic_reg(base, PIC_9XX_IRT(irt));
3238c2ecf20Sopenharmony_ci		reg &= ~((uint64_t)1 << 22);
3248c2ecf20Sopenharmony_ci		nlm_write_pic_reg(base, PIC_9XX_IRT(irt), reg);
3258c2ecf20Sopenharmony_ci	} else {
3268c2ecf20Sopenharmony_ci		reg = nlm_read_pic_reg(base, PIC_IRT(irt));
3278c2ecf20Sopenharmony_ci		reg &= ~((uint64_t)1 << 31);
3288c2ecf20Sopenharmony_ci		nlm_write_pic_reg(base, PIC_IRT(irt), reg);
3298c2ecf20Sopenharmony_ci	}
3308c2ecf20Sopenharmony_ci}
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_cistatic inline void
3338c2ecf20Sopenharmony_cinlm_pic_send_ipi(uint64_t base, int hwt, int irq, int nmi)
3348c2ecf20Sopenharmony_ci{
3358c2ecf20Sopenharmony_ci	uint64_t ipi;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	if (cpu_is_xlp9xx())
3388c2ecf20Sopenharmony_ci		ipi = (nmi << 23) | (irq << 24) |
3398c2ecf20Sopenharmony_ci			(0/*mcm*/ << 20) | (0/*ptr*/ << 16) | hwt;
3408c2ecf20Sopenharmony_ci	else
3418c2ecf20Sopenharmony_ci		ipi = ((uint64_t)nmi << 31) | (irq << 20) |
3428c2ecf20Sopenharmony_ci			((hwt >> 4) << 16) | (1 << (hwt & 0xf));
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	nlm_write_pic_reg(base, PIC_IPI_CTL, ipi);
3458c2ecf20Sopenharmony_ci}
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_cistatic inline void
3488c2ecf20Sopenharmony_cinlm_pic_ack(uint64_t base, int irt_num)
3498c2ecf20Sopenharmony_ci{
3508c2ecf20Sopenharmony_ci	nlm_write_pic_reg(base, PIC_INT_ACK, irt_num);
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	/* Ack the Status register for Watchdog & System timers */
3538c2ecf20Sopenharmony_ci	if (irt_num < 12)
3548c2ecf20Sopenharmony_ci		nlm_write_pic_reg(base, PIC_STATUS, (1 << irt_num));
3558c2ecf20Sopenharmony_ci}
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_cistatic inline void
3588c2ecf20Sopenharmony_cinlm_pic_init_irt(uint64_t base, int irt, int irq, int hwt, int en)
3598c2ecf20Sopenharmony_ci{
3608c2ecf20Sopenharmony_ci	nlm_pic_write_irt_direct(base, irt, en, 0, 0, irq, hwt);
3618c2ecf20Sopenharmony_ci}
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ciint nlm_irq_to_irt(int irq);
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */
3668c2ecf20Sopenharmony_ci#endif /* _NLM_HAL_PIC_H */
367