]>
Commit | Line | Data |
---|---|---|
5ba3f43e | 1 | /* |
a39ff7e2 | 2 | * Copyright (c) 2011-2018 Apple Inc. All rights reserved. |
5ba3f43e | 3 | * |
a39ff7e2 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5ba3f43e | 5 | * |
a39ff7e2 A |
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@ | |
5ba3f43e A |
27 | */ |
28 | ||
29 | #include <pexpert/pexpert.h> | |
30 | #include <pexpert/arm/consistent_debug.h> | |
31 | #include <pexpert/device_tree.h> | |
32 | #include <libkern/OSAtomic.h> | |
33 | #include <machine/machine_routines.h> | |
34 | ||
0a7de745 | 35 | static dbg_registry_t * consistent_debug_registry = NULL; |
5ba3f43e | 36 | |
0a7de745 A |
37 | static dbg_record_header_t* |
38 | consistent_debug_allocate_entry(void) | |
39 | { | |
5ba3f43e A |
40 | unsigned int i; |
41 | ||
0a7de745 | 42 | if (!consistent_debug_registry) { |
5ba3f43e | 43 | return NULL; |
0a7de745 | 44 | } |
5ba3f43e A |
45 | for (i = 0; i < consistent_debug_registry->top_level_header.num_records; i++) { |
46 | dbg_record_header_t *record = &consistent_debug_registry->records[i]; | |
47 | if (OSCompareAndSwap64(kDbgIdUnusedEntry, kDbgIdReservedEntry, &record->record_id)) { | |
48 | // Reserved an entry at position i. | |
49 | return (dbg_record_header_t*)record; | |
50 | } | |
51 | } | |
52 | return NULL; | |
53 | } | |
54 | ||
cb323159 A |
55 | boolean_t |
56 | PE_consistent_debug_lookup_entry(uint64_t record_id, uint64_t *phys_addr, uint64_t *length) | |
57 | { | |
58 | assert(phys_addr != NULL); | |
59 | assert(length != NULL); | |
60 | ||
61 | for (unsigned int i = 0; i < consistent_debug_registry->top_level_header.num_records; i++) { | |
62 | if (consistent_debug_registry->records[i].record_id == record_id) { | |
63 | *phys_addr = consistent_debug_registry->records[i].physaddr; | |
64 | *length = consistent_debug_registry->records[i].length; | |
65 | ||
66 | return true; | |
67 | } | |
68 | } | |
69 | ||
70 | return false; | |
71 | } | |
72 | ||
0a7de745 A |
73 | int |
74 | PE_consistent_debug_inherit(void) | |
5ba3f43e | 75 | { |
0a7de745 A |
76 | DTEntry entryP; |
77 | uintptr_t *prop_data; | |
78 | uintptr_t root_pointer = 0; | |
79 | uint32_t size; | |
5ba3f43e | 80 | |
0a7de745 A |
81 | if ((DTLookupEntry(NULL, "/chosen", &entryP) == kSuccess)) { |
82 | if (DTGetProperty(entryP, "consistent-debug-root", (void **)&prop_data, &size) == kSuccess) { | |
5ba3f43e | 83 | root_pointer = prop_data[0]; |
0a7de745 A |
84 | } |
85 | } | |
86 | if (root_pointer == 0) { | |
5ba3f43e | 87 | return -1; |
0a7de745 | 88 | } |
5ba3f43e A |
89 | consistent_debug_registry = (dbg_registry_t *)ml_map_high_window(root_pointer, sizeof(dbg_registry_t)); |
90 | return 0; | |
91 | } | |
92 | ||
0a7de745 A |
93 | int |
94 | PE_consistent_debug_register(uint64_t record_id, uint64_t physaddr, uint64_t length) | |
5ba3f43e A |
95 | { |
96 | dbg_record_header_t *allocated_header = consistent_debug_allocate_entry(); | |
0a7de745 | 97 | if (allocated_header == NULL) { |
5ba3f43e | 98 | return -1; |
0a7de745 | 99 | } |
5ba3f43e A |
100 | allocated_header->length = length; |
101 | allocated_header->physaddr = physaddr; | |
102 | // Make sure the hdr/length are visible before the record_id. | |
0a7de745 | 103 | __asm__ volatile ("dmb ish" : : : "memory"); |
5ba3f43e A |
104 | allocated_header->record_id = record_id; |
105 | return 0; | |
106 | } | |
107 | ||
0a7de745 A |
108 | int |
109 | PE_consistent_debug_enabled(void) | |
5ba3f43e | 110 | { |
0a7de745 | 111 | return consistent_debug_registry != NULL; |
5ba3f43e | 112 | } |