xref: /onnv-gate/usr/src/uts/common/xen/public/arch-x86/xen-mca.h (revision 11120:fe619717975a)
17532SSean.Ye@Sun.COM /******************************************************************************
210175SStuart.Maybee@Sun.COM  * arch-x86/mca.h
37532SSean.Ye@Sun.COM  *
47532SSean.Ye@Sun.COM  * Contributed by Advanced Micro Devices, Inc.
57532SSean.Ye@Sun.COM  * Author: Christoph Egger <Christoph.Egger@amd.com>
67532SSean.Ye@Sun.COM  *
77532SSean.Ye@Sun.COM  * Guest OS machine check interface to x86 Xen.
87532SSean.Ye@Sun.COM  *
97532SSean.Ye@Sun.COM  * Permission is hereby granted, free of charge, to any person obtaining a copy
107532SSean.Ye@Sun.COM  * of this software and associated documentation files (the "Software"), to
117532SSean.Ye@Sun.COM  * deal in the Software without restriction, including without limitation the
127532SSean.Ye@Sun.COM  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
137532SSean.Ye@Sun.COM  * sell copies of the Software, and to permit persons to whom the Software is
147532SSean.Ye@Sun.COM  * furnished to do so, subject to the following conditions:
157532SSean.Ye@Sun.COM  *
167532SSean.Ye@Sun.COM  * The above copyright notice and this permission notice shall be included in
177532SSean.Ye@Sun.COM  * all copies or substantial portions of the Software.
187532SSean.Ye@Sun.COM  *
197532SSean.Ye@Sun.COM  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
207532SSean.Ye@Sun.COM  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
217532SSean.Ye@Sun.COM  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
227532SSean.Ye@Sun.COM  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
237532SSean.Ye@Sun.COM  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
247532SSean.Ye@Sun.COM  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
257532SSean.Ye@Sun.COM  * DEALINGS IN THE SOFTWARE.
267532SSean.Ye@Sun.COM  */
277532SSean.Ye@Sun.COM 
287532SSean.Ye@Sun.COM /* Full MCA functionality has the following Usecases from the guest side:
297532SSean.Ye@Sun.COM  *
307532SSean.Ye@Sun.COM  * Must have's:
317532SSean.Ye@Sun.COM  * 1. Dom0 and DomU register machine check trap callback handlers
327532SSean.Ye@Sun.COM  *    (already done via "set_trap_table" hypercall)
337532SSean.Ye@Sun.COM  * 2. Dom0 registers machine check event callback handler
347532SSean.Ye@Sun.COM  *    (doable via EVTCHNOP_bind_virq)
357532SSean.Ye@Sun.COM  * 3. Dom0 and DomU fetches machine check data
367532SSean.Ye@Sun.COM  * 4. Dom0 wants Xen to notify a DomU
377532SSean.Ye@Sun.COM  * 5. Dom0 gets DomU ID from physical address
387532SSean.Ye@Sun.COM  * 6. Dom0 wants Xen to kill DomU (already done for "xm destroy")
397532SSean.Ye@Sun.COM  *
407532SSean.Ye@Sun.COM  * Nice to have's:
417532SSean.Ye@Sun.COM  * 7. Dom0 wants Xen to deactivate a physical CPU
427532SSean.Ye@Sun.COM  *    This is better done as separate task, physical CPU hotplugging,
437532SSean.Ye@Sun.COM  *    and hypercall(s) should be sysctl's
447532SSean.Ye@Sun.COM  * 8. Page migration proposed from Xen NUMA work, where Dom0 can tell Xen to
457532SSean.Ye@Sun.COM  *    move a DomU (or Dom0 itself) away from a malicious page
467532SSean.Ye@Sun.COM  *    producing correctable errors.
477532SSean.Ye@Sun.COM  * 9. offlining physical page:
487532SSean.Ye@Sun.COM  *    Xen free's and never re-uses a certain physical page.
497532SSean.Ye@Sun.COM  * 10. Testfacility: Allow Dom0 to write values into machine check MSR's
507532SSean.Ye@Sun.COM  *     and tell Xen to trigger a machine check
517532SSean.Ye@Sun.COM  */
527532SSean.Ye@Sun.COM 
537532SSean.Ye@Sun.COM #ifndef __XEN_PUBLIC_ARCH_X86_MCA_H__
547532SSean.Ye@Sun.COM #define __XEN_PUBLIC_ARCH_X86_MCA_H__
557532SSean.Ye@Sun.COM 
567532SSean.Ye@Sun.COM /* Hypercall */
577532SSean.Ye@Sun.COM #define __HYPERVISOR_mca __HYPERVISOR_arch_0
587532SSean.Ye@Sun.COM 
597532SSean.Ye@Sun.COM /*
607532SSean.Ye@Sun.COM  * The xen-unstable repo has interface version 0x03000001; out interface
617532SSean.Ye@Sun.COM  * is incompatible with that and any future minor revisions, so we
627532SSean.Ye@Sun.COM  * choose a different version number range that is numerically less
637532SSean.Ye@Sun.COM  * than that used in xen-unstable.
647532SSean.Ye@Sun.COM  */
65*11120SMark.Johnson@Sun.COM #define XEN_MCA_INTERFACE_VERSION 0x01ecc003
667532SSean.Ye@Sun.COM 
677532SSean.Ye@Sun.COM /* IN: Dom0 calls hypercall to retrieve nonurgent telemetry */
6810175SStuart.Maybee@Sun.COM #define XEN_MC_NONURGENT  0x0001
6910175SStuart.Maybee@Sun.COM /* IN: Dom0/DomU calls hypercall to retrieve urgent telemetry */
7010175SStuart.Maybee@Sun.COM #define XEN_MC_URGENT     0x0002
717532SSean.Ye@Sun.COM /* IN: Dom0 acknowledges previosly-fetched telemetry */
7210175SStuart.Maybee@Sun.COM #define XEN_MC_ACK        0x0004
737532SSean.Ye@Sun.COM 
7410175SStuart.Maybee@Sun.COM /* OUT: All is ok */
7510175SStuart.Maybee@Sun.COM #define XEN_MC_OK           0x0
767532SSean.Ye@Sun.COM /* OUT: Domain could not fetch data. */
7710175SStuart.Maybee@Sun.COM #define XEN_MC_FETCHFAILED  0x1
787532SSean.Ye@Sun.COM /* OUT: There was no machine check data to fetch. */
7910175SStuart.Maybee@Sun.COM #define XEN_MC_NODATA       0x2
807532SSean.Ye@Sun.COM /* OUT: Between notification time and this hypercall an other
817532SSean.Ye@Sun.COM  *  (most likely) correctable error happened. The fetched data,
827532SSean.Ye@Sun.COM  *  does not match the original machine check data. */
8310175SStuart.Maybee@Sun.COM #define XEN_MC_NOMATCH      0x4
847532SSean.Ye@Sun.COM 
857532SSean.Ye@Sun.COM /* OUT: DomU did not register MC NMI handler. Try something else. */
8610175SStuart.Maybee@Sun.COM #define XEN_MC_CANNOTHANDLE 0x8
877532SSean.Ye@Sun.COM /* OUT: Notifying DomU failed. Retry later or try something else. */
8810175SStuart.Maybee@Sun.COM #define XEN_MC_NOTDELIVERED 0x10
8910175SStuart.Maybee@Sun.COM /* Note, XEN_MC_CANNOTHANDLE and XEN_MC_NOTDELIVERED are mutually exclusive. */
9010175SStuart.Maybee@Sun.COM 
917532SSean.Ye@Sun.COM 
927532SSean.Ye@Sun.COM #ifndef __ASSEMBLY__
937532SSean.Ye@Sun.COM 
947532SSean.Ye@Sun.COM #define VIRQ_MCA VIRQ_ARCH_0 /* G. (DOM0) Machine Check Architecture */
957532SSean.Ye@Sun.COM 
967532SSean.Ye@Sun.COM /*
977532SSean.Ye@Sun.COM  * Machine Check Architecure:
987532SSean.Ye@Sun.COM  * structs are read-only and used to report all kinds of
997532SSean.Ye@Sun.COM  * correctable and uncorrectable errors detected by the HW.
1007532SSean.Ye@Sun.COM  * Dom0 and DomU: register a handler to get notified.
1017532SSean.Ye@Sun.COM  * Dom0 only: Correctable errors are reported via VIRQ_MCA
1027532SSean.Ye@Sun.COM  * Dom0 and DomU: Uncorrectable errors are reported via nmi handlers
1037532SSean.Ye@Sun.COM  */
1047532SSean.Ye@Sun.COM #define MC_TYPE_GLOBAL          0
1057532SSean.Ye@Sun.COM #define MC_TYPE_BANK            1
1067532SSean.Ye@Sun.COM #define MC_TYPE_EXTENDED        2
107*11120SMark.Johnson@Sun.COM #define MC_TYPE_RECOVERY        3
1087532SSean.Ye@Sun.COM 
1097532SSean.Ye@Sun.COM struct mcinfo_common {
11010175SStuart.Maybee@Sun.COM     uint16_t type;      /* structure type */
1117532SSean.Ye@Sun.COM     uint16_t size;      /* size of this struct in bytes */
1127532SSean.Ye@Sun.COM };
1137532SSean.Ye@Sun.COM 
1147532SSean.Ye@Sun.COM 
11510175SStuart.Maybee@Sun.COM #define MC_FLAG_CORRECTABLE     (1 << 0)
11610175SStuart.Maybee@Sun.COM #define MC_FLAG_UNCORRECTABLE   (1 << 1)
11710175SStuart.Maybee@Sun.COM #define MC_FLAG_RECOVERABLE	(1 << 2)
11810175SStuart.Maybee@Sun.COM #define MC_FLAG_POLLED		(1 << 3)
11910175SStuart.Maybee@Sun.COM #define MC_FLAG_RESET		(1 << 4)
12010175SStuart.Maybee@Sun.COM #define MC_FLAG_CMCI		(1 << 5)
12110175SStuart.Maybee@Sun.COM #define MC_FLAG_MCE		(1 << 6)
1227532SSean.Ye@Sun.COM /* contains global x86 mc information */
1237532SSean.Ye@Sun.COM struct mcinfo_global {
1247532SSean.Ye@Sun.COM     struct mcinfo_common common;
1257532SSean.Ye@Sun.COM 
1267532SSean.Ye@Sun.COM     /* running domain at the time in error (most likely the impacted one) */
1277532SSean.Ye@Sun.COM     uint16_t mc_domid;
128*11120SMark.Johnson@Sun.COM     uint16_t mc_vcpuid; /* virtual cpu scheduled for mc_domid */
1297532SSean.Ye@Sun.COM     uint32_t mc_socketid; /* physical socket of the physical core */
1307532SSean.Ye@Sun.COM     uint16_t mc_coreid; /* physical impacted core */
131*11120SMark.Johnson@Sun.COM     uint16_t mc_core_threadid; /* core thread of physical core */
13210175SStuart.Maybee@Sun.COM     uint32_t mc_apicid;
133*11120SMark.Johnson@Sun.COM     uint32_t mc_flags;
1347532SSean.Ye@Sun.COM     uint64_t mc_gstatus; /* global status */
1357532SSean.Ye@Sun.COM };
1367532SSean.Ye@Sun.COM 
1377532SSean.Ye@Sun.COM /* contains bank local x86 mc information */
1387532SSean.Ye@Sun.COM struct mcinfo_bank {
1397532SSean.Ye@Sun.COM     struct mcinfo_common common;
1407532SSean.Ye@Sun.COM 
1417532SSean.Ye@Sun.COM     uint16_t mc_bank; /* bank nr */
1427532SSean.Ye@Sun.COM     uint16_t mc_domid; /* Usecase 5: domain referenced by mc_addr on dom0
1437532SSean.Ye@Sun.COM                         * and if mc_addr is valid. Never valid on DomU. */
1447532SSean.Ye@Sun.COM     uint64_t mc_status; /* bank status */
1457532SSean.Ye@Sun.COM     uint64_t mc_addr;   /* bank address, only valid
1467532SSean.Ye@Sun.COM                          * if addr bit is set in mc_status */
1477532SSean.Ye@Sun.COM     uint64_t mc_misc;
14810175SStuart.Maybee@Sun.COM     uint64_t mc_ctrl2;
14910175SStuart.Maybee@Sun.COM     uint64_t mc_tsc;
1507532SSean.Ye@Sun.COM };
1517532SSean.Ye@Sun.COM 
1527532SSean.Ye@Sun.COM 
1537532SSean.Ye@Sun.COM struct mcinfo_msr {
1547532SSean.Ye@Sun.COM     uint64_t reg;   /* MSR */
1557532SSean.Ye@Sun.COM     uint64_t value; /* MSR value */
1567532SSean.Ye@Sun.COM };
1577532SSean.Ye@Sun.COM 
1587532SSean.Ye@Sun.COM /* contains mc information from other
1597532SSean.Ye@Sun.COM  * or additional mc MSRs */
1607532SSean.Ye@Sun.COM struct mcinfo_extended {
1617532SSean.Ye@Sun.COM     struct mcinfo_common common;
1627532SSean.Ye@Sun.COM 
1637532SSean.Ye@Sun.COM     /* You can fill up to five registers.
1647532SSean.Ye@Sun.COM      * If you need more, then use this structure
1657532SSean.Ye@Sun.COM      * multiple times. */
1667532SSean.Ye@Sun.COM 
1677532SSean.Ye@Sun.COM     uint32_t mc_msrs; /* Number of msr with valid values. */
16810175SStuart.Maybee@Sun.COM     /*
169*11120SMark.Johnson@Sun.COM      * Currently Intel extended MSR (32/64) include all gp registers
170*11120SMark.Johnson@Sun.COM      * and E(R)FLAGS, E(R)IP, E(R)MISC, up to 11/19 of them might be
171*11120SMark.Johnson@Sun.COM      * useful at present. So expand this array to 16/32 to leave room.
172*11120SMark.Johnson@Sun.COM      */
173*11120SMark.Johnson@Sun.COM     struct mcinfo_msr mc_msr[sizeof(void *) * 4];
1747532SSean.Ye@Sun.COM };
1757532SSean.Ye@Sun.COM 
176*11120SMark.Johnson@Sun.COM /* Recovery Action flags. Giving recovery result information to DOM0 */
177*11120SMark.Johnson@Sun.COM 
178*11120SMark.Johnson@Sun.COM /* Xen takes successful recovery action, the error is recovered */
179*11120SMark.Johnson@Sun.COM #define REC_ACTION_RECOVERED (0x1 << 0)
180*11120SMark.Johnson@Sun.COM /* No action is performed by XEN */
181*11120SMark.Johnson@Sun.COM #define REC_ACTION_NONE (0x1 << 1)
182*11120SMark.Johnson@Sun.COM /* It's possible DOM0 might take action ownership in some case */
183*11120SMark.Johnson@Sun.COM #define REC_ACTION_NEED_RESET (0x1 << 2)
184*11120SMark.Johnson@Sun.COM 
185*11120SMark.Johnson@Sun.COM /* Different Recovery Action types, if the action is performed successfully,
186*11120SMark.Johnson@Sun.COM  * REC_ACTION_RECOVERED flag will be returned.
187*11120SMark.Johnson@Sun.COM  */
188*11120SMark.Johnson@Sun.COM 
189*11120SMark.Johnson@Sun.COM /* Page Offline Action */
190*11120SMark.Johnson@Sun.COM #define MC_ACTION_PAGE_OFFLINE (0x1 << 0)
191*11120SMark.Johnson@Sun.COM /* CPU offline Action */
192*11120SMark.Johnson@Sun.COM #define MC_ACTION_CPU_OFFLINE (0x1 << 1)
193*11120SMark.Johnson@Sun.COM /* L3 cache disable Action */
194*11120SMark.Johnson@Sun.COM #define MC_ACTION_CACHE_SHRINK (0x1 << 2)
195*11120SMark.Johnson@Sun.COM 
196*11120SMark.Johnson@Sun.COM /* Below interface used between XEN/DOM0 for passing XEN's recovery action
197*11120SMark.Johnson@Sun.COM  * information to DOM0.
198*11120SMark.Johnson@Sun.COM  * usage Senario: After offlining broken page, XEN might pass its page offline
199*11120SMark.Johnson@Sun.COM  * recovery action result to DOM0. DOM0 will save the information in
200*11120SMark.Johnson@Sun.COM  * non-volatile memory for further proactive actions, such as offlining the
201*11120SMark.Johnson@Sun.COM  * easy broken page earlier when doing next reboot.
202*11120SMark.Johnson@Sun.COM */
203*11120SMark.Johnson@Sun.COM struct page_offline_action
204*11120SMark.Johnson@Sun.COM {
205*11120SMark.Johnson@Sun.COM     /* Params for passing the offlined page number to DOM0 */
206*11120SMark.Johnson@Sun.COM     uint64_t mfn;
207*11120SMark.Johnson@Sun.COM     uint64_t status;
208*11120SMark.Johnson@Sun.COM };
209*11120SMark.Johnson@Sun.COM 
210*11120SMark.Johnson@Sun.COM struct cpu_offline_action
211*11120SMark.Johnson@Sun.COM {
212*11120SMark.Johnson@Sun.COM     /* Params for passing the identity of the offlined CPU to DOM0 */
213*11120SMark.Johnson@Sun.COM     uint32_t mc_socketid;
214*11120SMark.Johnson@Sun.COM     uint16_t mc_coreid;
215*11120SMark.Johnson@Sun.COM     uint16_t mc_core_threadid;
216*11120SMark.Johnson@Sun.COM };
217*11120SMark.Johnson@Sun.COM 
218*11120SMark.Johnson@Sun.COM #define MAX_UNION_SIZE 16
219*11120SMark.Johnson@Sun.COM struct mcinfo_recovery
220*11120SMark.Johnson@Sun.COM {
221*11120SMark.Johnson@Sun.COM     struct mcinfo_common common;
222*11120SMark.Johnson@Sun.COM     uint16_t mc_bank; /* bank nr */
223*11120SMark.Johnson@Sun.COM     uint8_t action_flags;
224*11120SMark.Johnson@Sun.COM     uint8_t action_types;
225*11120SMark.Johnson@Sun.COM     union {
226*11120SMark.Johnson@Sun.COM         struct page_offline_action page_retire;
227*11120SMark.Johnson@Sun.COM         struct cpu_offline_action cpu_offline;
228*11120SMark.Johnson@Sun.COM         uint8_t pad[MAX_UNION_SIZE];
229*11120SMark.Johnson@Sun.COM     } action_info;
230*11120SMark.Johnson@Sun.COM };
231*11120SMark.Johnson@Sun.COM 
232*11120SMark.Johnson@Sun.COM 
23310175SStuart.Maybee@Sun.COM #define MCINFO_HYPERCALLSIZE	1024
2347532SSean.Ye@Sun.COM #define MCINFO_MAXSIZE		768
2357532SSean.Ye@Sun.COM 
23610175SStuart.Maybee@Sun.COM struct mc_info {
2377532SSean.Ye@Sun.COM     /* Number of mcinfo_* entries in mi_data */
2387532SSean.Ye@Sun.COM     uint32_t mi_nentries;
239*11120SMark.Johnson@Sun.COM     uint32_t _pad0;
240*11120SMark.Johnson@Sun.COM     uint64_t mi_data[(MCINFO_MAXSIZE - 1) / 8];
24110175SStuart.Maybee@Sun.COM };
24210175SStuart.Maybee@Sun.COM typedef struct mc_info mc_info_t;
2437532SSean.Ye@Sun.COM DEFINE_XEN_GUEST_HANDLE(mc_info_t);
2447532SSean.Ye@Sun.COM 
2457532SSean.Ye@Sun.COM #define __MC_MSR_ARRAYSIZE 8
2467532SSean.Ye@Sun.COM #define __MC_NMSRS 1
2477532SSean.Ye@Sun.COM #define MC_NCAPS	7	/* 7 CPU feature flag words */
2487532SSean.Ye@Sun.COM #define MC_CAPS_STD_EDX	0	/* cpuid level 0x00000001 (%edx) */
2497532SSean.Ye@Sun.COM #define MC_CAPS_AMD_EDX	1	/* cpuid level 0x80000001 (%edx) */
2507532SSean.Ye@Sun.COM #define MC_CAPS_TM	2	/* cpuid level 0x80860001 (TransMeta) */
2517532SSean.Ye@Sun.COM #define MC_CAPS_LINUX	3	/* Linux-defined */
2527532SSean.Ye@Sun.COM #define MC_CAPS_STD_ECX	4	/* cpuid level 0x00000001 (%ecx) */
2537532SSean.Ye@Sun.COM #define MC_CAPS_VIA	5	/* cpuid level 0xc0000001 */
2547532SSean.Ye@Sun.COM #define MC_CAPS_AMD_ECX	6	/* cpuid level 0x80000001 (%ecx) */
2557532SSean.Ye@Sun.COM 
256*11120SMark.Johnson@Sun.COM struct mcinfo_logical_cpu {
25710175SStuart.Maybee@Sun.COM     uint32_t mc_cpunr;
2587532SSean.Ye@Sun.COM     uint32_t mc_chipid;
2597532SSean.Ye@Sun.COM     uint16_t mc_coreid;
2607532SSean.Ye@Sun.COM     uint16_t mc_threadid;
26110175SStuart.Maybee@Sun.COM     uint32_t mc_apicid;
26210175SStuart.Maybee@Sun.COM     uint32_t mc_clusterid;
26310175SStuart.Maybee@Sun.COM     uint32_t mc_ncores;
26410175SStuart.Maybee@Sun.COM     uint32_t mc_ncores_active;
26510175SStuart.Maybee@Sun.COM     uint32_t mc_nthreads;
26610175SStuart.Maybee@Sun.COM     int32_t mc_cpuid_level;
26710175SStuart.Maybee@Sun.COM     uint32_t mc_family;
26810175SStuart.Maybee@Sun.COM     uint32_t mc_vendor;
26910175SStuart.Maybee@Sun.COM     uint32_t mc_model;
27010175SStuart.Maybee@Sun.COM     uint32_t mc_step;
2717532SSean.Ye@Sun.COM     char mc_vendorid[16];
2727532SSean.Ye@Sun.COM     char mc_brandid[64];
2737532SSean.Ye@Sun.COM     uint32_t mc_cpu_caps[MC_NCAPS];
27410175SStuart.Maybee@Sun.COM     uint32_t mc_cache_size;
27510175SStuart.Maybee@Sun.COM     uint32_t mc_cache_alignment;
27610175SStuart.Maybee@Sun.COM     int32_t mc_nmsrvals;
2777532SSean.Ye@Sun.COM     struct mcinfo_msr mc_msrvalues[__MC_MSR_ARRAYSIZE];
278*11120SMark.Johnson@Sun.COM };
279*11120SMark.Johnson@Sun.COM typedef struct mcinfo_logical_cpu xen_mc_logical_cpu_t;
2807532SSean.Ye@Sun.COM DEFINE_XEN_GUEST_HANDLE(xen_mc_logical_cpu_t);
2817532SSean.Ye@Sun.COM 
28210175SStuart.Maybee@Sun.COM 
2837532SSean.Ye@Sun.COM /*
2847532SSean.Ye@Sun.COM  * OS's should use these instead of writing their own lookup function
2857532SSean.Ye@Sun.COM  * each with its own bugs and drawbacks.
2867532SSean.Ye@Sun.COM  * We use macros instead of static inline functions to allow guests
2877532SSean.Ye@Sun.COM  * to include this header in assembly files (*.S).
2887532SSean.Ye@Sun.COM  */
2897532SSean.Ye@Sun.COM /* Prototype:
2907532SSean.Ye@Sun.COM  *    uint32_t x86_mcinfo_nentries(struct mc_info *mi);
2917532SSean.Ye@Sun.COM  */
2927532SSean.Ye@Sun.COM #define x86_mcinfo_nentries(_mi)    \
2937532SSean.Ye@Sun.COM     (_mi)->mi_nentries
2947532SSean.Ye@Sun.COM /* Prototype:
2957532SSean.Ye@Sun.COM  *    struct mcinfo_common *x86_mcinfo_first(struct mc_info *mi);
2967532SSean.Ye@Sun.COM  */
2977532SSean.Ye@Sun.COM #define x86_mcinfo_first(_mi)       \
298*11120SMark.Johnson@Sun.COM     ((struct mcinfo_common *)(_mi)->mi_data)
2997532SSean.Ye@Sun.COM /* Prototype:
3007532SSean.Ye@Sun.COM  *    struct mcinfo_common *x86_mcinfo_next(struct mcinfo_common *mic);
3017532SSean.Ye@Sun.COM  */
3027532SSean.Ye@Sun.COM #define x86_mcinfo_next(_mic)       \
303*11120SMark.Johnson@Sun.COM     ((struct mcinfo_common *)((uint8_t *)(_mic) + (_mic)->size))
3047532SSean.Ye@Sun.COM 
3057532SSean.Ye@Sun.COM /* Prototype:
3067532SSean.Ye@Sun.COM  *    void x86_mcinfo_lookup(void *ret, struct mc_info *mi, uint16_t type);
3077532SSean.Ye@Sun.COM  */
3087532SSean.Ye@Sun.COM #define x86_mcinfo_lookup(_ret, _mi, _type)    \
3097532SSean.Ye@Sun.COM     do {                                                        \
3107532SSean.Ye@Sun.COM         uint32_t found, i;                                      \
3117532SSean.Ye@Sun.COM         struct mcinfo_common *_mic;                             \
3127532SSean.Ye@Sun.COM                                                                 \
3137532SSean.Ye@Sun.COM         found = 0;                                              \
3147532SSean.Ye@Sun.COM 	(_ret) = NULL;						\
3157532SSean.Ye@Sun.COM 	if (_mi == NULL) break;					\
3167532SSean.Ye@Sun.COM         _mic = x86_mcinfo_first(_mi);                           \
3177532SSean.Ye@Sun.COM         for (i = 0; i < x86_mcinfo_nentries(_mi); i++) {        \
3187532SSean.Ye@Sun.COM             if (_mic->type == (_type)) {                        \
3197532SSean.Ye@Sun.COM                 found = 1;                                      \
3207532SSean.Ye@Sun.COM                 break;                                          \
3217532SSean.Ye@Sun.COM             }                                                   \
3227532SSean.Ye@Sun.COM             _mic = x86_mcinfo_next(_mic);                       \
3237532SSean.Ye@Sun.COM         }                                                       \
3247532SSean.Ye@Sun.COM         (_ret) = found ? _mic : NULL;                           \
3257532SSean.Ye@Sun.COM     } while (0)
3267532SSean.Ye@Sun.COM 
3277532SSean.Ye@Sun.COM 
3287532SSean.Ye@Sun.COM /* Usecase 1
3297532SSean.Ye@Sun.COM  * Register machine check trap callback handler
3307532SSean.Ye@Sun.COM  *    (already done via "set_trap_table" hypercall)
3317532SSean.Ye@Sun.COM  */
3327532SSean.Ye@Sun.COM 
3337532SSean.Ye@Sun.COM /* Usecase 2
3347532SSean.Ye@Sun.COM  * Dom0 registers machine check event callback handler
3357532SSean.Ye@Sun.COM  * done by EVTCHNOP_bind_virq
3367532SSean.Ye@Sun.COM  */
3377532SSean.Ye@Sun.COM 
3387532SSean.Ye@Sun.COM /* Usecase 3
3397532SSean.Ye@Sun.COM  * Fetch machine check data from hypervisor.
3407532SSean.Ye@Sun.COM  * Note, this hypercall is special, because both Dom0 and DomU must use this.
3417532SSean.Ye@Sun.COM  */
34210175SStuart.Maybee@Sun.COM #define XEN_MC_fetch            1
3437532SSean.Ye@Sun.COM struct xen_mc_fetch {
34410175SStuart.Maybee@Sun.COM     /* IN/OUT variables. */
34510175SStuart.Maybee@Sun.COM     uint32_t flags;	/* IN: XEN_MC_NONURGENT, XEN_MC_URGENT,
34610175SStuart.Maybee@Sun.COM                            XEN_MC_ACK if ack'ing an earlier fetch */
34710175SStuart.Maybee@Sun.COM 			/* OUT: XEN_MC_OK, XEN_MC_FETCHFAILED,
34810175SStuart.Maybee@Sun.COM 			   XEN_MC_NODATA, XEN_MC_NOMATCH */
349*11120SMark.Johnson@Sun.COM     uint32_t _pad0;
35010175SStuart.Maybee@Sun.COM     uint64_t fetch_id;	/* OUT: id for ack, IN: id we are ack'ing */
3517532SSean.Ye@Sun.COM 
35210175SStuart.Maybee@Sun.COM     /* OUT variables. */
3537532SSean.Ye@Sun.COM     XEN_GUEST_HANDLE(mc_info_t) data;
3547532SSean.Ye@Sun.COM };
3557532SSean.Ye@Sun.COM typedef struct xen_mc_fetch xen_mc_fetch_t;
3567532SSean.Ye@Sun.COM DEFINE_XEN_GUEST_HANDLE(xen_mc_fetch_t);
3577532SSean.Ye@Sun.COM 
3587532SSean.Ye@Sun.COM 
3597532SSean.Ye@Sun.COM /* Usecase 4
3607532SSean.Ye@Sun.COM  * This tells the hypervisor to notify a DomU about the machine check error
3617532SSean.Ye@Sun.COM  */
36210175SStuart.Maybee@Sun.COM #define XEN_MC_notifydomain     2
3637532SSean.Ye@Sun.COM struct xen_mc_notifydomain {
3647532SSean.Ye@Sun.COM     /* IN variables. */
36510175SStuart.Maybee@Sun.COM     uint16_t mc_domid;    /* The unprivileged domain to notify. */
36610175SStuart.Maybee@Sun.COM     uint16_t mc_vcpuid;   /* The vcpu in mc_domid to notify.
36710175SStuart.Maybee@Sun.COM                            * Usually echo'd value from the fetch hypercall. */
3687532SSean.Ye@Sun.COM 
3697532SSean.Ye@Sun.COM     /* IN/OUT variables. */
37010175SStuart.Maybee@Sun.COM     uint32_t flags;
37110175SStuart.Maybee@Sun.COM 
37210175SStuart.Maybee@Sun.COM /* IN: XEN_MC_CORRECTABLE, XEN_MC_TRAP */
37310175SStuart.Maybee@Sun.COM /* OUT: XEN_MC_OK, XEN_MC_CANNOTHANDLE, XEN_MC_NOTDELIVERED, XEN_MC_NOMATCH */
3747532SSean.Ye@Sun.COM };
3757532SSean.Ye@Sun.COM typedef struct xen_mc_notifydomain xen_mc_notifydomain_t;
3767532SSean.Ye@Sun.COM DEFINE_XEN_GUEST_HANDLE(xen_mc_notifydomain_t);
3777532SSean.Ye@Sun.COM 
37810175SStuart.Maybee@Sun.COM #define XEN_MC_physcpuinfo 3
3797532SSean.Ye@Sun.COM struct xen_mc_physcpuinfo {
3807532SSean.Ye@Sun.COM 	/* IN/OUT */
3817532SSean.Ye@Sun.COM 	uint32_t ncpus;
382*11120SMark.Johnson@Sun.COM 	uint32_t _pad0;
3837532SSean.Ye@Sun.COM 	/* OUT */
3847532SSean.Ye@Sun.COM 	XEN_GUEST_HANDLE(xen_mc_logical_cpu_t) info;
3857532SSean.Ye@Sun.COM };
3867532SSean.Ye@Sun.COM 
38710175SStuart.Maybee@Sun.COM #define XEN_MC_msrinject    4
38810175SStuart.Maybee@Sun.COM #define MC_MSRINJ_MAXMSRS       8
3897532SSean.Ye@Sun.COM struct xen_mc_msrinject {
39010175SStuart.Maybee@Sun.COM        /* IN */
391*11120SMark.Johnson@Sun.COM 	uint32_t mcinj_cpunr;           /* target processor id */
39210175SStuart.Maybee@Sun.COM 	uint32_t mcinj_flags;           /* see MC_MSRINJ_F_* below */
39310175SStuart.Maybee@Sun.COM 	uint32_t mcinj_count;           /* 0 .. count-1 in array are valid */
394*11120SMark.Johnson@Sun.COM 	uint32_t _pad0;
3957532SSean.Ye@Sun.COM 	struct mcinfo_msr mcinj_msr[MC_MSRINJ_MAXMSRS];
3967532SSean.Ye@Sun.COM };
3977532SSean.Ye@Sun.COM 
3987532SSean.Ye@Sun.COM /* Flags for mcinj_flags above; bits 16-31 are reserved */
39910175SStuart.Maybee@Sun.COM #define MC_MSRINJ_F_INTERPOSE   0x1
4007532SSean.Ye@Sun.COM 
40110175SStuart.Maybee@Sun.COM #define XEN_MC_mceinject    5
40210175SStuart.Maybee@Sun.COM struct xen_mc_mceinject {
40310175SStuart.Maybee@Sun.COM 	unsigned int mceinj_cpunr;      /* target processor id */
4047532SSean.Ye@Sun.COM };
4057532SSean.Ye@Sun.COM 
4067532SSean.Ye@Sun.COM struct xen_mc {
4077532SSean.Ye@Sun.COM     uint32_t cmd;
4087532SSean.Ye@Sun.COM     uint32_t interface_version; /* XEN_MCA_INTERFACE_VERSION */
409*11120SMark.Johnson@Sun.COM     union {
410*11120SMark.Johnson@Sun.COM         struct xen_mc_fetch        mc_fetch;
411*11120SMark.Johnson@Sun.COM         struct xen_mc_notifydomain mc_notifydomain;
412*11120SMark.Johnson@Sun.COM         struct xen_mc_physcpuinfo  mc_physcpuinfo;
413*11120SMark.Johnson@Sun.COM         struct xen_mc_msrinject    mc_msrinject;
414*11120SMark.Johnson@Sun.COM         struct xen_mc_mceinject    mc_mceinject;
415*11120SMark.Johnson@Sun.COM     } u;
4167532SSean.Ye@Sun.COM };
4177532SSean.Ye@Sun.COM typedef struct xen_mc xen_mc_t;
4187532SSean.Ye@Sun.COM DEFINE_XEN_GUEST_HANDLE(xen_mc_t);
4197532SSean.Ye@Sun.COM 
4207532SSean.Ye@Sun.COM #endif /* __ASSEMBLY__ */
4217532SSean.Ye@Sun.COM 
4227532SSean.Ye@Sun.COM #endif /* __XEN_PUBLIC_ARCH_X86_MCA_H__ */
423