1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25/*
26 * Copyright (c) 2010, Intel Corporation.
27 * All rights reserved.
28 * Copyright 2018 Joyent, Inc.
29 */
30
31#ifndef _SYS_MACHSYSTM_H
32#define	_SYS_MACHSYSTM_H
33
34/*
35 * Numerous platform-dependent interfaces that don't seem to belong
36 * in any other header file.
37 *
38 * This file should not be included by code that purports to be
39 * platform-independent.
40 *
41 */
42
43#include <sys/machparam.h>
44#include <sys/varargs.h>
45#include <sys/thread.h>
46#include <sys/cpuvar.h>
47#include <sys/privregs.h>
48#include <sys/systm.h>
49#include <sys/traptrace.h>
50#include <vm/page.h>
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56#ifdef _KERNEL
57
58typedef enum mach_cpu_add_arg_type {
59	MACH_CPU_ARG_LOCAL_APIC,
60	MACH_CPU_ARG_LOCAL_X2APIC,
61} mach_cpu_add_arg_type_t;
62
63typedef struct mach_cpu_add_arg {
64	mach_cpu_add_arg_type_t		type;
65	union {
66		struct {
67			uint32_t	apic_id;
68			uint32_t	proc_id;
69		} apic;
70	} arg;
71} mach_cpu_add_arg_t;
72
73extern void mach_cpu_idle(void);
74extern int mach_cpu_halt(xc_arg_t, xc_arg_t, xc_arg_t);
75extern int mach_cpu_start(cpu_t *, void *);
76extern int mach_cpuid_start(processorid_t, void *);
77extern int mach_cpu_stop(cpu_t *, void *);
78extern int mach_cpu_add(mach_cpu_add_arg_t *, processorid_t *);
79extern int mach_cpu_remove(processorid_t);
80extern int mach_cpu_create_device_node(cpu_t *, dev_info_t **);
81extern int mach_cpu_get_device_node(cpu_t *, dev_info_t **);
82
83extern int Cpudelay;
84extern void setcpudelay(void);
85
86extern void send_dirint(int, int);
87extern void siron(void);
88extern void sir_on(int);
89
90extern void return_instr(void);
91
92extern int kcpc_hw_load_pcbe(void);
93extern void kcpc_hw_init(cpu_t *cp);
94extern void kcpc_hw_fini(cpu_t *cp);
95extern int kcpc_hw_overflow_intr_installed;
96
97struct panic_trap_info {
98	struct regs *trap_regs;
99	uint_t trap_type;
100	caddr_t trap_addr;
101};
102
103struct memconf {
104	pfn_t	mcf_spfn;	/* begin page frame number */
105	pfn_t	mcf_epfn;	/* end page frame number */
106};
107
108struct system_hardware {
109	int		hd_nodes;		/* number of nodes */
110	int		hd_cpus_per_node;	/* max cpus in a node */
111	struct memconf	hd_mem[MAXNODES];
112						/*
113						 * memory layout for each
114						 * node.
115						 */
116};
117extern struct system_hardware system_hardware;
118extern void get_system_configuration(void);
119extern void mmu_init(void);
120extern int cpuid2nodeid(int);
121extern void map_kaddr(caddr_t, pfn_t, int, int);
122
123extern void memscrub_init(void);
124extern void trap(struct regs *, caddr_t, processorid_t);
125
126extern void do_interrupt(struct regs *, trap_trace_rec_t *);
127extern void memscrub_disable(void);
128
129/*
130 * Interrupt handling hooks
131 */
132extern void (*do_interrupt_common)(struct regs *, trap_trace_rec_t *);
133extern uintptr_t (*get_intr_handler)(int, short);
134
135/*
136 * Dispatcher hooks.
137 */
138void    (*idle_cpu)();
139void    (*non_deep_idle_cpu)();
140void    (*disp_enq_thread)(cpu_t *, int);
141void    (*non_deep_idle_disp_enq_thread)(cpu_t *, int);
142
143#ifndef __xpv
144extern unsigned int microdata;
145#endif
146
147extern int use_mp;
148
149extern struct cpu	cpus[];		/* pointer to other cpus */
150extern struct cpu	*cpu[];		/* pointer to all cpus */
151
152/* Operation types for extended mach_cpucontext interfaces */
153#define	MACH_CPUCONTEXT_OP_START	0
154#define	MACH_CPUCONTEXT_OP_STOP		1
155
156extern int mach_cpucontext_init(void);
157extern void mach_cpucontext_fini(void);
158extern void *mach_cpucontext_alloc(struct cpu *);
159extern void mach_cpucontext_free(struct cpu *, void *, int);
160extern void *mach_cpucontext_xalloc(struct cpu *, int);
161extern void mach_cpucontext_xfree(struct cpu *, void *, int, int);
162extern void rmp_gdt_init(rm_platter_t *);
163
164extern uintptr_t hole_start, hole_end;
165
166#define	INVALID_VADDR(a)	\
167	(((a) >= (caddr_t)hole_start && (a) < (caddr_t)hole_end))
168
169/* kpm mapping window */
170extern size_t   kpm_size;
171extern uchar_t  kpm_size_shift;
172extern caddr_t  kpm_vbase;
173
174struct memlist;
175extern void memlist_add(uint64_t, uint64_t, struct memlist *,
176    struct memlist **);
177extern page_t *page_get_physical(uintptr_t seed);
178extern int linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp);
179extern int dtrace_linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp);
180
181extern int force_shutdown_method;
182
183/* Dynamic Reconfiguration capability interface. */
184#define	PLAT_DR_OPTIONS_NAME		"plat-dr-options"
185#define	PLAT_DR_PHYSMAX_NAME		"plat-dr-physmax"
186#define	PLAT_MAX_NCPUS_NAME		"plat-max-ncpus"
187#define	BOOT_MAX_NCPUS_NAME		"boot-max-ncpus"
188#define	BOOT_NCPUS_NAME			"boot-ncpus"
189
190#define	PLAT_DR_FEATURE_CPU		0x1
191#define	PLAT_DR_FEATURE_MEMORY		0x2
192#define	PLAT_DR_FEATURE_ENABLED		0x1000000
193
194#define	plat_dr_enabled()		\
195	plat_dr_check_capability(PLAT_DR_FEATURE_ENABLED)
196
197#define	plat_dr_enable()		\
198	plat_dr_enable_capability(PLAT_DR_FEATURE_ENABLED)
199
200#define	plat_dr_disable_cpu()		\
201	plat_dr_disable_capability(PLAT_DR_FEATURE_CPU)
202#define	plat_dr_disable_memory()	\
203	plat_dr_disable_capability(PLAT_DR_FEATURE_MEMORY)
204
205extern boolean_t plat_dr_support_cpu(void);
206extern boolean_t plat_dr_support_memory(void);
207extern boolean_t plat_dr_check_capability(uint64_t features);
208extern void plat_dr_enable_capability(uint64_t features);
209extern void plat_dr_disable_capability(uint64_t features);
210
211#pragma	weak plat_dr_support_cpu
212#pragma	weak plat_dr_support_memory
213
214/*
215 * Used to communicate DR updates to platform lgroup framework
216 */
217typedef struct {
218	uint64_t	u_base;
219	uint64_t	u_length;
220	uint32_t	u_domain;
221	uint32_t	u_device_id;
222	uint32_t	u_sli_cnt;
223	uchar_t		*u_sli_ptr;
224} update_membounds_t;
225
226/* Maximum physical page number (PFN) for memory DR operations. */
227extern uint64_t plat_dr_physmax;
228
229#ifdef __xpv
230#include <sys/xen_mmu.h>
231extern page_t *page_get_high_mfn(mfn_t);
232#endif
233
234extern hrtime_t tsc_gethrtime_tick_delta(void);
235extern hrtime_t tsc_gethrtime_params(uint64_t *, uint32_t *, uint8_t *);
236
237#endif /* _KERNEL */
238
239#ifdef __cplusplus
240}
241#endif
242
243#endif	/* _SYS_MACHSYSTM_H */
244