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  */
  29 
  30 #ifndef _SYS_MACHSYSTM_H
  31 #define _SYS_MACHSYSTM_H
  32 
  33 /*
  34  * Numerous platform-dependent interfaces that don't seem to belong
  35  * in any other header file.
  36  *
  37  * This file should not be included by code that purports to be
  38  * platform-independent.
  39  */
  40 
  41 #include <sys/machparam.h>
  42 #include <sys/varargs.h>
  43 #include <sys/thread.h>
  44 #include <sys/cpuvar.h>
  45 #include <sys/privregs.h>
  46 #include <sys/systm.h>
  47 #include <sys/traptrace.h>
  48 #include <vm/page.h>
  49 
  50 #ifdef __cplusplus
  51 extern "C" {
  52 #endif
  53 
  54 #ifdef _KERNEL
  55 
  56 typedef enum mach_cpu_add_arg_type {
  57         MACH_CPU_ARG_LOCAL_APIC,
  58         MACH_CPU_ARG_LOCAL_X2APIC,
  59 } mach_cpu_add_arg_type_t;
  60 
  61 typedef struct mach_cpu_add_arg {
  62         mach_cpu_add_arg_type_t         type;
  63         union {
  64                 struct {
  65                         uint32_t        apic_id;
  66                         uint32_t        proc_id;
  67                 } apic;
  68         } arg;
  69 } mach_cpu_add_arg_t;
  70 
  71 extern void mach_cpu_idle(void);
  72 extern void mach_cpu_halt(char *);
  73 extern int mach_cpu_start(cpu_t *, void *);
  74 extern int mach_cpuid_start(processorid_t, void *);
  75 extern int mach_cpu_stop(cpu_t *, void *);
  76 extern int mach_cpu_add(mach_cpu_add_arg_t *, processorid_t *);
  77 extern int mach_cpu_remove(processorid_t);
  78 extern int mach_cpu_create_device_node(cpu_t *, dev_info_t **);
  79 extern int mach_cpu_get_device_node(cpu_t *, dev_info_t **);
  80 
  81 extern int Cpudelay;
  82 extern void setcpudelay(void);
  83 
  84 extern void send_dirint(int, int);
  85 extern void siron(void);
  86 extern void sir_on(int);
  87 
  88 extern void return_instr(void);
  89 
  90 extern int kcpc_hw_load_pcbe(void);
  91 extern void kcpc_hw_init(cpu_t *cp);
  92 extern void kcpc_hw_fini(cpu_t *cp);
  93 extern int kcpc_hw_overflow_intr_installed;
  94 
  95 struct panic_trap_info {
  96         struct regs *trap_regs;
  97         uint_t trap_type;
  98         caddr_t trap_addr;
  99 };
 100 
 101 struct memconf {
 102         pfn_t   mcf_spfn;       /* begin page frame number */
 103         pfn_t   mcf_epfn;       /* end page frame number */
 104 };
 105 
 106 struct system_hardware {
 107         int             hd_nodes;               /* number of nodes */
 108         int             hd_cpus_per_node;       /* max cpus in a node */
 109         struct memconf  hd_mem[MAXNODES];
 110                                                 /*
 111                                                  * memory layout for each
 112                                                  * node.
 113                                                  */
 114 };
 115 extern struct system_hardware system_hardware;
 116 extern void get_system_configuration(void);
 117 extern void mmu_init(void);
 118 extern int cpuid2nodeid(int);
 119 extern void map_kaddr(caddr_t, pfn_t, int, int);
 120 
 121 extern void memscrub_init(void);
 122 extern void trap(struct regs *, caddr_t, processorid_t);
 123 
 124 extern void do_interrupt(struct regs *, trap_trace_rec_t *);
 125 extern void memscrub_disable(void);
 126 
 127 /*
 128  * Interrupt handling hooks
 129  */
 130 extern void (*do_interrupt_common)(struct regs *, trap_trace_rec_t *);
 131 extern uintptr_t (*get_intr_handler)(int, short);
 132 
 133 /*
 134  * Dispatcher hooks.
 135  */
 136 void    (*idle_cpu)();
 137 void    (*non_deep_idle_cpu)();
 138 void    (*disp_enq_thread)(cpu_t *, int);
 139 void    (*non_deep_idle_disp_enq_thread)(cpu_t *, int);
 140 
 141 #ifndef __xpv
 142 extern unsigned int microdata;
 143 #endif
 144 
 145 extern int use_mp;
 146 
 147 extern struct cpu       cpus[];         /* pointer to other cpus */
 148 extern struct cpu       *cpu[];         /* pointer to all cpus */
 149 
 150 /* Operation types for extended mach_cpucontext interfaces */
 151 #define MACH_CPUCONTEXT_OP_START        0
 152 #define MACH_CPUCONTEXT_OP_STOP         1
 153 
 154 extern int mach_cpucontext_init(void);
 155 extern void mach_cpucontext_fini(void);
 156 extern void *mach_cpucontext_alloc(struct cpu *);
 157 extern void mach_cpucontext_free(struct cpu *, void *, int);
 158 extern void *mach_cpucontext_xalloc(struct cpu *, int);
 159 extern void mach_cpucontext_xfree(struct cpu *, void *, int, int);
 160 extern void rmp_gdt_init(rm_platter_t *);
 161 
 162 extern uintptr_t hole_start, hole_end;
 163 
 164 #define INVALID_VADDR(a)        \
 165         (((a) >= (caddr_t)hole_start && (a) < (caddr_t)hole_end))
 166 
 167 /* kpm mapping window */
 168 extern size_t   kpm_size;
 169 extern uchar_t  kpm_size_shift;
 170 extern caddr_t  kpm_vbase;
 171 
 172 struct memlist;
 173 extern void memlist_add(uint64_t, uint64_t, struct memlist *,
 174     struct memlist **);
 175 extern page_t *page_get_physical(uintptr_t seed);
 176 extern int linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp);
 177 extern int dtrace_linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp);
 178 
 179 extern int force_shutdown_method;
 180 
 181 /* Dynamic Reconfiguration capability interface. */
 182 #define PLAT_DR_OPTIONS_NAME            "plat-dr-options"
 183 #define PLAT_DR_PHYSMAX_NAME            "plat-dr-physmax"
 184 #define PLAT_MAX_NCPUS_NAME             "plat-max-ncpus"
 185 #define BOOT_MAX_NCPUS_NAME             "boot-max-ncpus"
 186 #define BOOT_NCPUS_NAME                 "boot-ncpus"
 187 
 188 #define PLAT_DR_FEATURE_CPU             0x1
 189 #define PLAT_DR_FEATURE_MEMORY          0x2
 190 #define PLAT_DR_FEATURE_ENABLED         0x1000000
 191 
 192 #define plat_dr_enabled()               \
 193         plat_dr_check_capability(PLAT_DR_FEATURE_ENABLED)
 194 
 195 #define plat_dr_enable()                \
 196         plat_dr_enable_capability(PLAT_DR_FEATURE_ENABLED)
 197 
 198 #define plat_dr_disable_cpu()           \
 199         plat_dr_disable_capability(PLAT_DR_FEATURE_CPU)
 200 #define plat_dr_disable_memory()        \
 201         plat_dr_disable_capability(PLAT_DR_FEATURE_MEMORY)
 202 
 203 extern boolean_t plat_dr_support_cpu(void);
 204 extern boolean_t plat_dr_support_memory(void);
 205 extern boolean_t plat_dr_check_capability(uint64_t features);
 206 extern void plat_dr_enable_capability(uint64_t features);
 207 extern void plat_dr_disable_capability(uint64_t features);
 208 
 209 #pragma weak plat_dr_support_cpu
 210 #pragma weak plat_dr_support_memory
 211 
 212 /*
 213  * Used to communicate DR updates to platform lgroup framework
 214  */
 215 typedef struct {
 216         uint64_t        u_base;
 217         uint64_t        u_length;
 218         uint32_t        u_domain;
 219         uint32_t        u_device_id;
 220         uint32_t        u_sli_cnt;
 221         uchar_t         *u_sli_ptr;
 222 } update_membounds_t;
 223 
 224 /* Maximum physical page number (PFN) for memory DR operations. */
 225 extern uint64_t plat_dr_physmax;
 226 
 227 #ifdef __xpv
 228 #include <sys/xen_mmu.h>
 229 extern page_t *page_get_high_mfn(mfn_t);
 230 #endif
 231 
 232 extern hrtime_t tsc_gethrtime_tick_delta(void);
 233 
 234 extern boolean_t bios_calls_available;
 235 
 236 #endif /* _KERNEL */
 237 
 238 #ifdef __cplusplus
 239 }
 240 #endif
 241 
 242 #endif  /* _SYS_MACHSYSTM_H */