2017-07-16 17:02:48 +03:00
|
|
|
/* $NetBSD: intr.h,v 1.51 2017/07/16 14:02:48 cherry Exp $ */
|
2003-02-27 00:26:09 +03:00
|
|
|
|
|
|
|
/*-
|
2008-04-29 02:47:37 +04:00
|
|
|
* Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
2003-02-27 00:26:09 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum, and by Jason R. Thorpe.
|
|
|
|
*
|
|
|
|
* 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 THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 THE FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _X86_INTR_H_
|
|
|
|
#define _X86_INTR_H_
|
|
|
|
|
2017-07-16 17:02:48 +03:00
|
|
|
#if !defined(XEN)
|
2007-12-03 18:33:00 +03:00
|
|
|
#define __HAVE_FAST_SOFTINTS
|
2008-04-29 02:47:37 +04:00
|
|
|
#define __HAVE_PREEMPTION
|
2017-07-16 17:02:48 +03:00
|
|
|
#endif /* !defined(XEN) */
|
2007-12-03 18:33:00 +03:00
|
|
|
|
2009-03-27 19:09:24 +03:00
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <sys/types.h>
|
|
|
|
#else
|
|
|
|
#include <stdbool.h>
|
|
|
|
#endif
|
|
|
|
|
2009-03-26 01:54:56 +03:00
|
|
|
#include <sys/evcnt.h>
|
2015-04-27 09:42:52 +03:00
|
|
|
#include <sys/queue.h>
|
2003-02-27 00:26:09 +03:00
|
|
|
#include <machine/intrdefs.h>
|
|
|
|
|
|
|
|
#ifndef _LOCORE
|
|
|
|
#include <machine/pic.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Struct describing an interrupt source for a CPU. struct cpu_info
|
|
|
|
* has an array of MAX_INTR_SOURCES of these. The index in the array
|
|
|
|
* is equal to the stub number of the stubcode as present in vector.s
|
|
|
|
*
|
|
|
|
* The primary CPU's array of interrupt sources has its first 16
|
|
|
|
* entries reserved for legacy ISA irq handlers. This means that
|
|
|
|
* they have a 1:1 mapping for arrayindex:irq_num. This is not
|
|
|
|
* true for interrupts that come in through IO APICs, to find
|
|
|
|
* their source, go through ci->ci_isources[index].is_pic
|
|
|
|
*
|
|
|
|
* It's possible to always maintain a 1:1 mapping, but that means
|
|
|
|
* limiting the total number of interrupt sources to MAX_INTR_SOURCES
|
|
|
|
* (32), instead of 32 per CPU. It also would mean that having multiple
|
|
|
|
* IO APICs which deliver interrupts from an equal pin number would
|
|
|
|
* overlap if they were to be sent to the same CPU.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct intrstub {
|
2017-07-16 17:02:48 +03:00
|
|
|
#if !defined(XEN)
|
2003-02-27 00:26:09 +03:00
|
|
|
void *ist_entry;
|
2017-07-16 17:02:48 +03:00
|
|
|
#endif
|
2016-07-07 09:55:38 +03:00
|
|
|
void *ist_recurse;
|
2003-02-27 00:26:09 +03:00
|
|
|
void *ist_resume;
|
|
|
|
};
|
|
|
|
|
2015-04-27 09:42:52 +03:00
|
|
|
struct percpu_evcnt {
|
|
|
|
cpuid_t cpuid;
|
|
|
|
uint64_t count;
|
|
|
|
};
|
|
|
|
|
2003-02-27 00:26:09 +03:00
|
|
|
struct intrsource {
|
|
|
|
int is_maxlevel; /* max. IPL for this source */
|
2011-08-01 14:42:23 +04:00
|
|
|
int is_pin; /* IRQ for legacy; pin for IO APIC,
|
|
|
|
-1 for MSI */
|
2003-02-27 00:26:09 +03:00
|
|
|
struct intrhand *is_handlers; /* handler chain */
|
|
|
|
struct pic *is_pic; /* originating PIC */
|
|
|
|
void *is_recurse; /* entry for spllower */
|
|
|
|
void *is_resume; /* entry for doreti */
|
2007-12-03 18:33:00 +03:00
|
|
|
lwp_t *is_lwp; /* for soft interrupts */
|
2017-07-16 17:02:48 +03:00
|
|
|
#if defined(XEN)
|
|
|
|
u_long ipl_evt_mask1; /* pending events for this IPL */
|
|
|
|
u_long ipl_evt_mask2[NR_EVENT_CHANNELS];
|
|
|
|
#endif
|
2015-08-17 09:16:02 +03:00
|
|
|
struct evcnt is_evcnt; /* interrupt counter per cpu */
|
2003-02-27 00:26:09 +03:00
|
|
|
int is_flags; /* see below */
|
|
|
|
int is_type; /* level, edge */
|
|
|
|
int is_idtvec;
|
|
|
|
int is_minlevel;
|
2007-12-03 18:33:00 +03:00
|
|
|
char is_evname[32]; /* event counter name */
|
2015-04-27 09:42:52 +03:00
|
|
|
char is_intrid[INTRIDBUF]; /* intrid created by create_intrid() */
|
2015-08-17 09:16:02 +03:00
|
|
|
char is_xname[INTRDEVNAMEBUF]; /* device names */
|
2015-04-27 09:42:52 +03:00
|
|
|
cpuid_t is_active_cpu; /* active cpuid */
|
|
|
|
struct percpu_evcnt *is_saved_evcnt; /* interrupt count of deactivated cpus */
|
|
|
|
SIMPLEQ_ENTRY(intrsource) is_list; /* link of intrsources */
|
2003-02-27 00:26:09 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define IS_LEGACY 0x0001 /* legacy ISA irq source */
|
|
|
|
#define IS_IPI 0x0002
|
|
|
|
#define IS_LOG 0x0004
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt handler chains. *_intr_establish() insert a handler into
|
|
|
|
* the list. The handler is called with its (single) argument.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct intrhand {
|
|
|
|
int (*ih_fun)(void *);
|
|
|
|
void *ih_arg;
|
|
|
|
int ih_level;
|
2004-10-24 01:24:05 +04:00
|
|
|
int (*ih_realfun)(void *);
|
|
|
|
void *ih_realarg;
|
2003-02-27 00:26:09 +03:00
|
|
|
struct intrhand *ih_next;
|
2009-04-19 18:11:36 +04:00
|
|
|
struct intrhand **ih_prevp;
|
2017-07-16 17:02:48 +03:00
|
|
|
#if !defined(XEN)
|
2003-02-27 00:26:09 +03:00
|
|
|
int ih_pin;
|
|
|
|
int ih_slot;
|
2017-07-16 17:02:48 +03:00
|
|
|
#else
|
|
|
|
struct intrhand *ih_evt_next;
|
|
|
|
#endif
|
2003-02-27 00:26:09 +03:00
|
|
|
struct cpu_info *ih_cpu;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define IMASK(ci,level) (ci)->ci_imask[(level)]
|
|
|
|
#define IUNMASK(ci,level) (ci)->ci_iunmask[(level)]
|
|
|
|
|
2010-05-02 22:03:31 +04:00
|
|
|
#ifdef _KERNEL
|
|
|
|
|
2007-05-17 18:51:11 +04:00
|
|
|
void Xspllower(int);
|
|
|
|
void spllower(int);
|
|
|
|
int splraise(int);
|
|
|
|
void softintr(int);
|
2003-02-27 00:26:09 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert spl level to local APIC level
|
|
|
|
*/
|
2007-05-17 18:51:11 +04:00
|
|
|
|
2003-02-27 00:26:09 +03:00
|
|
|
#define APIC_LEVEL(l) ((l) << 4)
|
|
|
|
|
|
|
|
/*
|
2007-05-17 18:51:11 +04:00
|
|
|
* Miscellaneous
|
2003-02-27 00:26:09 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define SPL_ASSERT_BELOW(x) KDASSERT(curcpu()->ci_ilevel < (x))
|
|
|
|
#define spl0() spllower(IPL_NONE)
|
|
|
|
#define splx(x) spllower(x)
|
|
|
|
|
2006-12-26 18:22:44 +03:00
|
|
|
typedef uint8_t ipl_t;
|
2006-12-21 18:55:21 +03:00
|
|
|
typedef struct {
|
|
|
|
ipl_t _ipl;
|
|
|
|
} ipl_cookie_t;
|
|
|
|
|
|
|
|
static inline ipl_cookie_t
|
|
|
|
makeiplcookie(ipl_t ipl)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ipl_cookie_t){._ipl = ipl};
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
splraiseipl(ipl_cookie_t icookie)
|
|
|
|
{
|
|
|
|
|
|
|
|
return splraise(icookie._ipl);
|
|
|
|
}
|
|
|
|
|
2005-11-03 16:06:06 +03:00
|
|
|
#include <sys/spl.h>
|
|
|
|
|
2003-02-27 00:26:09 +03:00
|
|
|
/*
|
|
|
|
* Stub declarations.
|
|
|
|
*/
|
|
|
|
|
2007-12-03 18:33:00 +03:00
|
|
|
void Xsoftintr(void);
|
2008-04-29 02:47:37 +04:00
|
|
|
void Xpreemptrecurse(void);
|
|
|
|
void Xpreemptresume(void);
|
2003-02-27 00:26:09 +03:00
|
|
|
|
|
|
|
extern struct intrstub i8259_stubs[];
|
2003-05-05 02:01:56 +04:00
|
|
|
extern struct intrstub ioapic_edge_stubs[];
|
|
|
|
extern struct intrstub ioapic_level_stubs[];
|
2017-05-23 11:54:38 +03:00
|
|
|
extern struct intrstub x2apic_edge_stubs[];
|
|
|
|
extern struct intrstub x2apic_level_stubs[];
|
2003-02-27 00:26:09 +03:00
|
|
|
|
|
|
|
struct cpu_info;
|
|
|
|
|
2003-10-31 00:19:54 +03:00
|
|
|
struct pcibus_attach_args;
|
|
|
|
|
2015-04-27 09:51:40 +03:00
|
|
|
typedef uint64_t intr_handle_t;
|
|
|
|
|
2003-02-27 00:26:09 +03:00
|
|
|
void intr_default_setup(void);
|
2011-04-04 02:29:25 +04:00
|
|
|
void x86_nmi(void);
|
2015-08-17 09:16:02 +03:00
|
|
|
void *intr_establish_xname(int, struct pic *, int, int, int, int (*)(void *),
|
|
|
|
void *, bool, const char *);
|
2008-05-30 23:03:10 +04:00
|
|
|
void *intr_establish(int, struct pic *, int, int, int, int (*)(void *), void *, bool);
|
2003-02-27 00:26:09 +03:00
|
|
|
void intr_disestablish(struct intrhand *);
|
2003-10-31 00:19:54 +03:00
|
|
|
void intr_add_pcibus(struct pcibus_attach_args *);
|
2015-04-27 09:51:40 +03:00
|
|
|
const char *intr_string(intr_handle_t, char *, size_t);
|
2003-02-27 00:26:09 +03:00
|
|
|
void cpu_intr_init(struct cpu_info *);
|
2015-04-27 09:51:40 +03:00
|
|
|
int intr_find_mpmapping(int, int, intr_handle_t *);
|
2006-07-04 04:30:21 +04:00
|
|
|
struct pic *intr_findpic(int);
|
2003-02-27 00:26:09 +03:00
|
|
|
void intr_printconfig(void);
|
|
|
|
|
2015-04-27 09:42:52 +03:00
|
|
|
struct intrsource *intr_allocate_io_intrsource(const char *);
|
|
|
|
void intr_free_io_intrsource(const char *);
|
|
|
|
|
2003-02-27 00:26:09 +03:00
|
|
|
int x86_send_ipi(struct cpu_info *, int);
|
|
|
|
void x86_broadcast_ipi(int);
|
|
|
|
void x86_ipi_handler(void);
|
|
|
|
|
2017-07-16 17:02:48 +03:00
|
|
|
#ifndef XEN
|
2014-07-20 19:46:34 +04:00
|
|
|
extern void (* const ipifunc[X86_NIPI])(struct cpu_info *);
|
2017-07-16 17:02:48 +03:00
|
|
|
#endif
|
2003-02-27 00:26:09 +03:00
|
|
|
|
2010-05-02 22:03:31 +04:00
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
2003-02-27 00:26:09 +03:00
|
|
|
#endif /* !_LOCORE */
|
|
|
|
|
|
|
|
#endif /* !_X86_INTR_H_ */
|