xref: /xnu-8792.81.2/osfmk/kern/ecc.h (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
1 /*
2  * Copyright (c) 2013 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 #pragma once
30 
31 #include <mach/kern_return.h>
32 #include <stdint.h>
33 #include <sys/cdefs.h>
34 
35 __BEGIN_DECLS
36 
37 /* Old ECC logging mechanism */
38 
39 #define ECC_EVENT_INFO_DATA_ENTRIES     8
40 struct ecc_event {
41 	uint8_t         id;     // ID of memory (e.g. L2C), platform-specific
42 	uint8_t         count;  // Of uint64_t's used, starting at index 0
43 	uint64_t        data[ECC_EVENT_INFO_DATA_ENTRIES] __attribute__((aligned(8))); // Event-specific data
44 };
45 
46 #ifdef KERNEL_PRIVATE
47 extern kern_return_t    ecc_log_record_event(const struct ecc_event *ev);
48 #endif
49 
50 #ifdef XNU_KERNEL_PRIVATE
51 extern kern_return_t    ecc_log_get_next_event(struct ecc_event *ev);
52 extern uint32_t         ecc_log_get_correction_count(void);
53 #endif
54 
55 /* New CoreAnalytics ECC logging mechanism */
56 
57 /* Flags to describe ECC memory errors */
58 __options_decl(ecc_flags_t, uint32_t, {
59 	ECC_NONE                        = 0x00000000,
60 	ECC_IS_CORRECTABLE              = 0x00000001,
61 	ECC_IS_RETIRED                  = 0x00000002,
62 	ECC_IS_PANIC_PATH               = 0x00000004,
63 	ECC_IS_CPU_REPORTED             = 0x00000008,
64 	ECC_DB_CORRUPTED                = 0x00000010,
65 	ECC_IS_TEST_ERROR               = 0x00000020,
66 });
67 
68 /* Flags to describe MCC memory errors */
69 __options_decl(mcc_flags_t, uint32_t, {
70 	MCC_NONE                        = 0x00000000,
71 	MCC_IS_SINGLE_BIT               = 0x00000001,
72 	MCC_IS_MULTI_BIT                = 0x00000002,
73 });
74 
75 /**
76  * MCC ECC versions.
77  */
78 typedef enum {
79 	MCC_ECC_V1,
80 
81 	// Metadata
82 	MCC_ECC_NUM_VERSIONS
83 } mcc_ecc_version_t;
84 
85 /**
86  * MCC ECC event descriptor.
87  *
88  * @note If a new MCC ECC version has been added, because i.e. future hardware must log new or different data,
89  * new fields should be appended to this struct to represent the new data.  No fields should be
90  * deleted from this struct unless the field corresponds only to hardware that has been deprecated.
91  */
92 typedef struct {
93 	/* Version of this struct. */
94 	mcc_ecc_version_t version;
95 	/* Flags used to describe the error. */
96 	mcc_flags_t flags;
97 	/* Interrupt status at the time of the MCC error. */
98 	uint32_t status;
99 	/* AMCC on which the error occurred. */
100 	uint32_t amcc;
101 	/* Plane of the AMCC on which the error occurred. */
102 	uint32_t plane;
103 	/* MemCache error Bank of first one bit error. */
104 	uint32_t bank;
105 	/* MemCache error Way of first one bit error. */
106 	uint32_t way;
107 	/* MemCache error Index of first one bit error. */
108 	uint32_t index;
109 	/* Indicates whether the error is in upper half cache line or lower half cache line. */
110 	uint32_t bit_off_cl;
111 	/* MemCache one bit error bit offset of first one bit error with in half cache line. */
112 	uint32_t bit_off_within_hcl;
113 } mcc_ecc_event_t;
114 
115 #if KERNEL_PRIVATE
116 
117 /**
118  * Logs any memory error.
119  *
120  * This will notify mmaintenanced of the error. The error
121  * will get added to a database of errors and sent to
122  * CoreAnalytics. If ECC_IS_RETIRED flag is used,
123  * the address will be added to dramecc.db and will
124  * be retired for the lifetime of the device.
125  *
126  * If it is too early in boot to send a notification directly
127  * to the deamon, the error will be added to an array to be serviced
128  * later by an mpsc_daemon_queue.
129  *
130  * If ECC_IS_CORRECTABLE flag is set with this function, it
131  * assumes one error. If caller wishes to report the CE count
132  * reported by hardware, use ecc_log_memory_error_ce().
133  *
134  * @param physical_address address that the error occured on
135  * @param ecc_flags flags used to describe the error
136  *
137  * @returns KERN_SUCCESS if logging supported by hw, KERN_FAILURE if not
138  */
139 kern_return_t ecc_log_memory_error(uint64_t physical_address, ecc_flags_t ecc_flags);
140 kern_return_t ecc_log_memory_error_internal(uint64_t physical_address, ecc_flags_t ecc_flags);
141 
142 /**
143  * Logs a correctable memory error.
144  *
145  * ECC_IS_CORRECTABLE is implied. Including this flag or not
146  * makes no difference for this function.
147  *
148  * @param physical_address address that the error occured on
149  * @param ecc_flags flags used to describe the error
150  * @param ce_count number of CEs occured on this page reported by HW
151  *
152  * @returns KERN_SUCCESS if logging supported by hw, KERN_FAILURE if not
153  */
154 kern_return_t ecc_log_memory_error_ce(uint64_t physical_address, ecc_flags_t ecc_flags, uint32_t ce_count);
155 
156 /**
157  * Logs an MCC error.
158  *
159  * @param event Event to be logged
160  * @returns KERN_SUCCESS on success, KERN_FAILURE otherwise
161  */
162 kern_return_t
163 mcc_log_memory_error(mcc_ecc_event_t event);
164 
165 #endif /* KERNEL_PRIVATE */
166 
167 __END_DECLS
168