xref: /dflybsd-src/sys/platform/pc64/apic/lapic.h (revision 8afc0c3d245781786d80df73e9bcc25b531a96b1)
12b6cd37eSSepherosa Ziehau /*
22b6cd37eSSepherosa Ziehau  * Copyright (c) 1996, by Steve Passe
32b6cd37eSSepherosa Ziehau  * Copyright (c) 2008 The DragonFly Project.
42b6cd37eSSepherosa Ziehau  * All rights reserved.
52b6cd37eSSepherosa Ziehau  *
62b6cd37eSSepherosa Ziehau  * Redistribution and use in source and binary forms, with or without
72b6cd37eSSepherosa Ziehau  * modification, are permitted provided that the following conditions
82b6cd37eSSepherosa Ziehau  * are met:
92b6cd37eSSepherosa Ziehau  * 1. Redistributions of source code must retain the above copyright
102b6cd37eSSepherosa Ziehau  *    notice, this list of conditions and the following disclaimer.
112b6cd37eSSepherosa Ziehau  * 2. The name of the developer may NOT be used to endorse or promote products
122b6cd37eSSepherosa Ziehau  *    derived from this software without specific prior written permission.
132b6cd37eSSepherosa Ziehau  *
142b6cd37eSSepherosa Ziehau  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
152b6cd37eSSepherosa Ziehau  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
162b6cd37eSSepherosa Ziehau  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
172b6cd37eSSepherosa Ziehau  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
182b6cd37eSSepherosa Ziehau  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
192b6cd37eSSepherosa Ziehau  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
202b6cd37eSSepherosa Ziehau  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
212b6cd37eSSepherosa Ziehau  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
222b6cd37eSSepherosa Ziehau  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
232b6cd37eSSepherosa Ziehau  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
242b6cd37eSSepherosa Ziehau  * SUCH DAMAGE.
252b6cd37eSSepherosa Ziehau  *
262b6cd37eSSepherosa Ziehau  * $FreeBSD: src/sys/i386/include/mpapic.h,v 1.14.2.2 2000/09/30 02:49:34 ps Exp $
272b6cd37eSSepherosa Ziehau  */
282b6cd37eSSepherosa Ziehau 
292b6cd37eSSepherosa Ziehau #ifndef _ARCH_APIC_LAPIC_H_
302b6cd37eSSepherosa Ziehau #define _ARCH_APIC_LAPIC_H_
312b6cd37eSSepherosa Ziehau 
3283c8d73eSSepherosa Ziehau #include <machine_base/apic/apicreg.h>
332b6cd37eSSepherosa Ziehau 
342b6cd37eSSepherosa Ziehau /*
35fbac0dc4SSepherosa Ziehau  * APIC ID <-> CPU ID mapping macros
362b6cd37eSSepherosa Ziehau  */
37fbac0dc4SSepherosa Ziehau #define CPUID_TO_APICID(cpu_id)		(cpu_id_to_apic_id[(cpu_id)])
38fbac0dc4SSepherosa Ziehau #define APICID_TO_CPUID(apic_id)	(apic_id_to_cpu_id[(apic_id)])
392b6cd37eSSepherosa Ziehau 
4083c8d73eSSepherosa Ziehau #ifndef _SYS_QUEUE_H_
4183c8d73eSSepherosa Ziehau #include <sys/queue.h>
4283c8d73eSSepherosa Ziehau #endif
4383c8d73eSSepherosa Ziehau 
4483c8d73eSSepherosa Ziehau struct lapic_enumerator {
4583c8d73eSSepherosa Ziehau 	int	lapic_prio;
4683c8d73eSSepherosa Ziehau 	TAILQ_ENTRY(lapic_enumerator) lapic_link;
4783c8d73eSSepherosa Ziehau 	int	(*lapic_probe)(struct lapic_enumerator *);
48f8ae0475SSepherosa Ziehau 	int	(*lapic_enumerate)(struct lapic_enumerator *);
4983c8d73eSSepherosa Ziehau };
5083c8d73eSSepherosa Ziehau 
5183c8d73eSSepherosa Ziehau #define LAPIC_ENUM_PRIO_MPTABLE		20
5283c8d73eSSepherosa Ziehau #define LAPIC_ENUM_PRIO_MADT		40
5383c8d73eSSepherosa Ziehau 
54*8afc0c3dSSepherosa Ziehau extern volatile lapic_t		*lapic_mem;
55fbac0dc4SSepherosa Ziehau extern int			cpu_id_to_apic_id[];
56fbac0dc4SSepherosa Ziehau extern int			apic_id_to_cpu_id[];
572e0ed166SSepherosa Ziehau extern int			lapic_enable;
58*8afc0c3dSSepherosa Ziehau extern int			lapic_usable;
593c38fc60SSepherosa Ziehau extern void			(*lapic_eoi)(void);
60*8afc0c3dSSepherosa Ziehau extern int			(*apic_ipi)(int, int, int);
61*8afc0c3dSSepherosa Ziehau extern void			(*single_apic_ipi)(int, int, int);
6283c8d73eSSepherosa Ziehau 
6383c8d73eSSepherosa Ziehau void	apic_dump(char*);
6483c8d73eSSepherosa Ziehau void	lapic_init(boolean_t);
650e44391aSSepherosa Ziehau void	lapic_set_cpuid(int, int);
663566408bSSepherosa Ziehau int	lapic_config(void);
6783c8d73eSSepherosa Ziehau void	lapic_enumerator_register(struct lapic_enumerator *);
6883c8d73eSSepherosa Ziehau void	set_apic_timer(int);
6983c8d73eSSepherosa Ziehau int	read_apic_timer(void);
7083c8d73eSSepherosa Ziehau void	u_sleep(int);
7183c8d73eSSepherosa Ziehau 
7213481c87SSepherosa Ziehau void	lapic_map(vm_paddr_t);
739a4bd8f3SSepherosa Ziehau int	lapic_unused_apic_id(int);
749a4bd8f3SSepherosa Ziehau void	lapic_fixup_noioapic(void);
75*8afc0c3dSSepherosa Ziehau void	lapic_seticr_sync(uint32_t, uint32_t);
769a4bd8f3SSepherosa Ziehau 
7749b0f72aSSepherosa Ziehau #ifndef _MACHINE_SMP_H_
7849b0f72aSSepherosa Ziehau #include <machine/smp.h>
7949b0f72aSSepherosa Ziehau #endif
8049b0f72aSSepherosa Ziehau 
819a4bd8f3SSepherosa Ziehau void	selected_apic_ipi(cpumask_t, int, int);
829a4bd8f3SSepherosa Ziehau 
832b6cd37eSSepherosa Ziehau /*
8483c8d73eSSepherosa Ziehau  * Send an IPI INTerrupt containing 'vector' to all CPUs EXCEPT myself
852b6cd37eSSepherosa Ziehau  */
86b976e2c2Szrj #ifndef _CPU_CPUMASK_H_
87b976e2c2Szrj #include <machine/cpumask.h>
88b976e2c2Szrj #endif
89b976e2c2Szrj 
902b6cd37eSSepherosa Ziehau static __inline int
912b6cd37eSSepherosa Ziehau all_but_self_ipi(int vector)
922b6cd37eSSepherosa Ziehau {
93c07315c4SMatthew Dillon 	if (CPUMASK_ISUP(smp_active_mask))
942b6cd37eSSepherosa Ziehau 		return 0;
952b6cd37eSSepherosa Ziehau 	return apic_ipi(APIC_DEST_ALLESELF, vector, APIC_DELMODE_FIXED);
962b6cd37eSSepherosa Ziehau }
972b6cd37eSSepherosa Ziehau 
98*8afc0c3dSSepherosa Ziehau #define LAPIC_MEM_READ(field)		(lapic_mem->field)
99*8afc0c3dSSepherosa Ziehau #define LAPIC_MEM_WRITE(field, val)	\
100*8afc0c3dSSepherosa Ziehau do {					\
101*8afc0c3dSSepherosa Ziehau 	lapic_mem->field = (val);	\
102*8afc0c3dSSepherosa Ziehau } while (0)
103*8afc0c3dSSepherosa Ziehau 
104*8afc0c3dSSepherosa Ziehau /* TODO: x2apic */
105*8afc0c3dSSepherosa Ziehau #define LAPIC_READ(field)		LAPIC_MEM_READ(field)
106*8afc0c3dSSepherosa Ziehau #define LAPIC_WRITE(field, val)		LAPIC_MEM_WRITE(field, (val))
107*8afc0c3dSSepherosa Ziehau 
108*8afc0c3dSSepherosa Ziehau /* TODO: x2apic */
109*8afc0c3dSSepherosa Ziehau #define LAPIC_READID			APIC_ID(LAPIC_MEM_READ(id))
110*8afc0c3dSSepherosa Ziehau 
1112b6cd37eSSepherosa Ziehau #endif /* _ARCH_APIC_LAPIC_H_ */
112