2011-07-16 19:35:44 +00:00
|
|
|
/*-
|
|
|
|
* Copyright 2003-2011 Netlogic Microsystems (Netlogic). All rights
|
|
|
|
* reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Netlogic Microsystems ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2011-09-05 10:45:29 +00:00
|
|
|
* NETLOGIC_BSD
|
2011-07-16 19:35:44 +00:00
|
|
|
* $FreeBSD$
|
2011-09-05 10:45:29 +00:00
|
|
|
*/
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
#ifndef _NLM_HAL_PIC_H
|
2011-11-21 08:12:36 +00:00
|
|
|
#define _NLM_HAL_PIC_H
|
2011-07-16 19:35:44 +00:00
|
|
|
|
|
|
|
/* PIC Specific registers */
|
2011-11-21 08:12:36 +00:00
|
|
|
#define PIC_CTRL 0x00
|
2011-09-05 10:45:29 +00:00
|
|
|
|
|
|
|
/* PIC control register defines */
|
2011-11-21 08:12:36 +00:00
|
|
|
#define PIC_CTRL_ITV 32 /* interrupt timeout value */
|
|
|
|
#define PIC_CTRL_ICI 19 /* ICI interrupt timeout enable */
|
|
|
|
#define PIC_CTRL_ITE 18 /* interrupt timeout enable */
|
|
|
|
#define PIC_CTRL_STE 10 /* system timer interrupt enable */
|
|
|
|
#define PIC_CTRL_WWR1 8 /* watchdog 1 wraparound count for reset */
|
|
|
|
#define PIC_CTRL_WWR0 6 /* watchdog 0 wraparound count for reset */
|
|
|
|
#define PIC_CTRL_WWN1 4 /* watchdog 1 wraparound count for NMI */
|
|
|
|
#define PIC_CTRL_WWN0 2 /* watchdog 0 wraparound count for NMI */
|
|
|
|
#define PIC_CTRL_WTE 0 /* watchdog timer enable */
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
/* PIC Status register defines */
|
2011-11-21 08:12:36 +00:00
|
|
|
#define PIC_ICI_STATUS 33 /* ICI interrupt timeout status */
|
|
|
|
#define PIC_ITE_STATUS 32 /* interrupt timeout status */
|
|
|
|
#define PIC_STS_STATUS 4 /* System timer interrupt status */
|
|
|
|
#define PIC_WNS_STATUS 2 /* NMI status for watchdog timers */
|
|
|
|
#define PIC_WIS_STATUS 0 /* Interrupt status for watchdog timers */
|
2011-09-05 10:45:29 +00:00
|
|
|
|
|
|
|
/* PIC IPI control register offsets */
|
2011-11-21 08:12:36 +00:00
|
|
|
#define PIC_IPICTRL_NMI 32
|
|
|
|
#define PIC_IPICTRL_RIV 20 /* received interrupt vector */
|
|
|
|
#define PIC_IPICTRL_IDB 16 /* interrupt destination base */
|
|
|
|
#define PIC_IPICTRL_DTE 0 /* interrupt destination thread enables */
|
2011-09-05 10:45:29 +00:00
|
|
|
|
|
|
|
/* PIC IRT register offsets */
|
2011-11-21 08:12:36 +00:00
|
|
|
#define PIC_IRT_ENABLE 31
|
|
|
|
#define PIC_IRT_NMI 29
|
|
|
|
#define PIC_IRT_SCH 28 /* Scheduling scheme */
|
|
|
|
#define PIC_IRT_RVEC 20 /* Interrupt receive vectors */
|
|
|
|
#define PIC_IRT_DT 19 /* Destination type */
|
|
|
|
#define PIC_IRT_DB 16 /* Destination base */
|
|
|
|
#define PIC_IRT_DTE 0 /* Destination thread enables */
|
|
|
|
|
|
|
|
#define PIC_BYTESWAP 0x02
|
|
|
|
#define PIC_STATUS 0x04
|
|
|
|
#define PIC_INTR_TIMEOUT 0x06
|
|
|
|
#define PIC_ICI0_INTR_TIMEOUT 0x08
|
|
|
|
#define PIC_ICI1_INTR_TIMEOUT 0x0a
|
|
|
|
#define PIC_ICI2_INTR_TIMEOUT 0x0c
|
|
|
|
#define PIC_IPI_CTL 0x0e
|
|
|
|
#define PIC_INT_ACK 0x10
|
|
|
|
#define PIC_INT_PENDING0 0x12
|
|
|
|
#define PIC_INT_PENDING1 0x14
|
|
|
|
#define PIC_INT_PENDING2 0x16
|
|
|
|
|
|
|
|
#define PIC_WDOG0_MAXVAL 0x18
|
|
|
|
#define PIC_WDOG0_COUNT 0x1a
|
|
|
|
#define PIC_WDOG0_ENABLE0 0x1c
|
|
|
|
#define PIC_WDOG0_ENABLE1 0x1e
|
|
|
|
#define PIC_WDOG0_BEATCMD 0x20
|
|
|
|
#define PIC_WDOG0_BEAT0 0x22
|
|
|
|
#define PIC_WDOG0_BEAT1 0x24
|
|
|
|
|
|
|
|
#define PIC_WDOG1_MAXVAL 0x26
|
|
|
|
#define PIC_WDOG1_COUNT 0x28
|
|
|
|
#define PIC_WDOG1_ENABLE0 0x2a
|
|
|
|
#define PIC_WDOG1_ENABLE1 0x2c
|
|
|
|
#define PIC_WDOG1_BEATCMD 0x2e
|
|
|
|
#define PIC_WDOG1_BEAT0 0x30
|
|
|
|
#define PIC_WDOG1_BEAT1 0x32
|
|
|
|
|
|
|
|
#define PIC_WDOG_MAXVAL(i) (PIC_WDOG0_MAXVAL + ((i) ? 7 : 0))
|
|
|
|
#define PIC_WDOG_COUNT(i) (PIC_WDOG0_COUNT + ((i) ? 7 : 0))
|
|
|
|
#define PIC_WDOG_ENABLE0(i) (PIC_WDOG0_ENABLE0 + ((i) ? 7 : 0))
|
|
|
|
#define PIC_WDOG_ENABLE1(i) (PIC_WDOG0_ENABLE1 + ((i) ? 7 : 0))
|
|
|
|
#define PIC_WDOG_BEATCMD(i) (PIC_WDOG0_BEATCMD + ((i) ? 7 : 0))
|
|
|
|
#define PIC_WDOG_BEAT0(i) (PIC_WDOG0_BEAT0 + ((i) ? 7 : 0))
|
|
|
|
#define PIC_WDOG_BEAT1(i) (PIC_WDOG0_BEAT1 + ((i) ? 7 : 0))
|
|
|
|
|
|
|
|
#define PIC_TIMER0_MAXVAL 0x34
|
|
|
|
#define PIC_TIMER1_MAXVAL 0x36
|
|
|
|
#define PIC_TIMER2_MAXVAL 0x38
|
|
|
|
#define PIC_TIMER3_MAXVAL 0x3a
|
|
|
|
#define PIC_TIMER4_MAXVAL 0x3c
|
|
|
|
#define PIC_TIMER5_MAXVAL 0x3e
|
|
|
|
#define PIC_TIMER6_MAXVAL 0x40
|
|
|
|
#define PIC_TIMER7_MAXVAL 0x42
|
|
|
|
#define PIC_TIMER_MAXVAL(i) (PIC_TIMER0_MAXVAL + ((i) * 2))
|
|
|
|
|
|
|
|
#define PIC_TIMER0_COUNT 0x44
|
|
|
|
#define PIC_TIMER1_COUNT 0x46
|
|
|
|
#define PIC_TIMER2_COUNT 0x48
|
|
|
|
#define PIC_TIMER3_COUNT 0x4a
|
|
|
|
#define PIC_TIMER4_COUNT 0x4c
|
|
|
|
#define PIC_TIMER5_COUNT 0x4e
|
|
|
|
#define PIC_TIMER6_COUNT 0x50
|
|
|
|
#define PIC_TIMER7_COUNT 0x52
|
|
|
|
#define PIC_TIMER_COUNT(i) (PIC_TIMER0_COUNT + ((i) * 2))
|
|
|
|
|
|
|
|
#define PIC_ITE0_N0_N1 0x54
|
|
|
|
#define PIC_ITE1_N0_N1 0x58
|
|
|
|
#define PIC_ITE2_N0_N1 0x5c
|
|
|
|
#define PIC_ITE3_N0_N1 0x60
|
|
|
|
#define PIC_ITE4_N0_N1 0x64
|
|
|
|
#define PIC_ITE5_N0_N1 0x68
|
|
|
|
#define PIC_ITE6_N0_N1 0x6c
|
|
|
|
#define PIC_ITE7_N0_N1 0x70
|
|
|
|
#define PIC_ITE_N0_N1(i) (PIC_ITE0_N0_N1 + ((i) * 4))
|
|
|
|
|
|
|
|
#define PIC_ITE0_N2_N3 0x56
|
|
|
|
#define PIC_ITE1_N2_N3 0x5a
|
|
|
|
#define PIC_ITE2_N2_N3 0x5e
|
|
|
|
#define PIC_ITE3_N2_N3 0x62
|
|
|
|
#define PIC_ITE4_N2_N3 0x66
|
|
|
|
#define PIC_ITE5_N2_N3 0x6a
|
|
|
|
#define PIC_ITE6_N2_N3 0x6e
|
|
|
|
#define PIC_ITE7_N2_N3 0x72
|
|
|
|
#define PIC_ITE_N2_N3(i) (PIC_ITE0_N2_N3 + ((i) * 4))
|
|
|
|
|
|
|
|
#define PIC_IRT0 0x74
|
|
|
|
#define PIC_IRT(i) (PIC_IRT0 + ((i) * 2))
|
|
|
|
|
|
|
|
#define TIMER_CYCLES_MAXVAL 0xffffffffffffffffULL
|
2011-09-05 10:45:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IRT Map
|
|
|
|
*/
|
2011-11-21 08:12:36 +00:00
|
|
|
#define PIC_IRT_WD_0_INDEX 0
|
|
|
|
#define PIC_IRT_WD_1_INDEX 1
|
|
|
|
#define PIC_IRT_WD_NMI_0_INDEX 2
|
|
|
|
#define PIC_IRT_WD_NMI_1_INDEX 3
|
|
|
|
#define PIC_IRT_TIMER_0_INDEX 4
|
|
|
|
#define PIC_IRT_TIMER_1_INDEX 5
|
|
|
|
#define PIC_IRT_TIMER_2_INDEX 6
|
|
|
|
#define PIC_IRT_TIMER_3_INDEX 7
|
|
|
|
#define PIC_IRT_TIMER_4_INDEX 8
|
|
|
|
#define PIC_IRT_TIMER_5_INDEX 9
|
|
|
|
#define PIC_IRT_TIMER_6_INDEX 10
|
|
|
|
#define PIC_IRT_TIMER_7_INDEX 11
|
|
|
|
#define PIC_IRT_CLOCK_INDEX PIC_IRT_TIMER_7_INDEX
|
|
|
|
#define PIC_IRT_TIMER_INDEX(num) ((num) + PIC_IRT_TIMER_0_INDEX)
|
|
|
|
|
|
|
|
#define PIC_CLOCK_TIMER 7
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
#if !defined(LOCORE) && !defined(__ASSEMBLY__)
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
/*
|
|
|
|
* Misc
|
|
|
|
*/
|
2011-11-21 08:12:36 +00:00
|
|
|
#define PIC_IRT_VALID 1
|
|
|
|
#define PIC_LOCAL_SCHEDULING 1
|
|
|
|
#define PIC_GLOBAL_SCHEDULING 0
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-11-21 08:12:36 +00:00
|
|
|
#define nlm_read_pic_reg(b, r) nlm_read_reg64(b, r)
|
|
|
|
#define nlm_write_pic_reg(b, r, v) nlm_write_reg64(b, r, v)
|
|
|
|
#define nlm_get_pic_pcibase(node) nlm_pcicfg_base(XLP_IO_PIC_OFFSET(node))
|
|
|
|
#define nlm_get_pic_regbase(node) (nlm_get_pic_pcibase(node) + XLP_IO_PCI_HDRSZ)
|
2011-07-16 19:35:44 +00:00
|
|
|
|
|
|
|
/* IRT and h/w interrupt routines */
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline int
|
|
|
|
nlm_pic_read_irt(uint64_t base, int irt_index)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
return nlm_read_pic_reg(base, PIC_IRT(irt_index));
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline void
|
|
|
|
nlm_pic_send_ipi(uint64_t base, int cpu, int vec, int nmi)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
uint64_t ipi;
|
|
|
|
int node, ncpu;
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
node = cpu / 32;
|
|
|
|
ncpu = cpu & 0x1f;
|
|
|
|
ipi = ((uint64_t)nmi << 31) | (vec << 20) | (node << 17) |
|
|
|
|
(1 << (cpu & 0xf));
|
|
|
|
if (ncpu > 15)
|
|
|
|
ipi |= 0x10000; /* Setting bit 16 to select cpus 16-31 */
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
nlm_write_pic_reg(base, PIC_IPI_CTL, ipi);
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline uint64_t
|
|
|
|
nlm_pic_read_control(uint64_t base)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
return nlm_read_pic_reg(base, PIC_CTRL);
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline void
|
|
|
|
nlm_pic_write_control(uint64_t base, uint64_t control)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
nlm_write_pic_reg(base, PIC_CTRL, control);
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline void
|
|
|
|
nlm_pic_update_control(uint64_t base, uint64_t control)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
uint64_t val;
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
val = nlm_read_pic_reg(base, PIC_CTRL);
|
|
|
|
nlm_write_pic_reg(base, PIC_CTRL, control | val);
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline void
|
|
|
|
nlm_pic_ack(uint64_t base, int irt_num)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
nlm_write_pic_reg(base, PIC_INT_ACK, irt_num);
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
/* Ack the Status register for Watchdog & System timers */
|
|
|
|
if (irt_num < 12)
|
|
|
|
nlm_write_pic_reg(base, PIC_STATUS, (1 << irt_num));
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline void
|
|
|
|
nlm_set_irt_to_cpu(uint64_t base, int irt, int cpu)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
uint64_t val;
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
val = nlm_read_pic_reg(base, PIC_IRT(irt));
|
|
|
|
val |= cpu & 0xf;
|
|
|
|
if (cpu > 15)
|
|
|
|
val |= 1 << 16;
|
|
|
|
nlm_write_pic_reg(base, PIC_IRT(irt), val);
|
|
|
|
}
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline void
|
|
|
|
nlm_pic_write_irt(uint64_t base, int irt_num, int en, int nmi,
|
|
|
|
int sch, int vec, int dt, int db, int dte)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
uint64_t val;
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
val = (((uint64_t)en & 0x1) << 31) | ((nmi & 0x1) << 29) |
|
|
|
|
((sch & 0x1) << 28) | ((vec & 0x3f) << 20) |
|
|
|
|
((dt & 0x1) << 19) | ((db & 0x7) << 16) |
|
|
|
|
(dte & 0xffff);
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
nlm_write_pic_reg(base, PIC_IRT(irt_num), val);
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline void
|
|
|
|
nlm_pic_write_irt_direct(uint64_t base, int irt_num, int en, int nmi,
|
|
|
|
int sch, int vec, int cpu)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
nlm_pic_write_irt(base, irt_num, en, nmi, sch, vec, 1,
|
|
|
|
(cpu >> 4), /* thread group */
|
|
|
|
1 << (cpu & 0xf)); /* thread mask */
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline uint64_t
|
|
|
|
nlm_pic_read_timer(uint64_t base, int timer)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-09-05 10:45:29 +00:00
|
|
|
return nlm_read_pic_reg(base, PIC_TIMER_COUNT(timer));
|
|
|
|
}
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline void
|
|
|
|
nlm_pic_write_timer(uint64_t base, int timer, uint64_t value)
|
|
|
|
{
|
|
|
|
nlm_write_pic_reg(base, PIC_TIMER_COUNT(timer), value);
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
static inline void
|
|
|
|
nlm_pic_set_timer(uint64_t base, int timer, uint64_t value, int irq, int cpu)
|
2011-07-16 19:35:44 +00:00
|
|
|
{
|
2011-11-21 08:12:36 +00:00
|
|
|
uint64_t pic_ctrl;
|
|
|
|
int en, nmi;
|
|
|
|
|
|
|
|
en = nmi = 0;
|
|
|
|
if (irq > 0)
|
|
|
|
en = 1;
|
|
|
|
else if (irq < 0) {
|
|
|
|
en = nmi = 1;
|
|
|
|
irq = -irq;
|
|
|
|
}
|
2011-09-05 10:45:29 +00:00
|
|
|
nlm_write_pic_reg(base, PIC_TIMER_MAXVAL(timer), value);
|
|
|
|
nlm_pic_write_irt_direct(base, PIC_IRT_TIMER_INDEX(timer),
|
2011-11-21 08:12:36 +00:00
|
|
|
en, nmi, 0, irq, cpu);
|
2011-07-16 19:35:44 +00:00
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
/* enable the timer */
|
2011-11-21 08:12:36 +00:00
|
|
|
pic_ctrl = nlm_read_pic_reg(base, PIC_CTRL);
|
2011-09-05 10:45:29 +00:00
|
|
|
pic_ctrl |= (1 << (PIC_CTRL_STE + timer));
|
|
|
|
nlm_write_pic_reg(base, PIC_CTRL, pic_ctrl);
|
2011-07-16 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:45:29 +00:00
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* _NLM_HAL_PIC_H */
|