2 * Copyright (C) 2011-2013 Apple Inc. All rights reserved.
4 * This document is the property of Apple Inc.
5 * It is considered confidential and proprietary.
7 * This document may not be reproduced or transmitted in any form,
8 * in whole or in part, without the express written permission of
12 #include <pexpert/pexpert.h>
13 #include <pexpert/arm/consistent_debug.h>
14 #include <pexpert/device_tree.h>
15 #include <libkern/OSAtomic.h>
16 #include <machine/machine_routines.h>
18 static dbg_registry_t
* consistent_debug_registry
= NULL
;
20 static dbg_record_header_t
* consistent_debug_allocate_entry(void) {
23 if (!consistent_debug_registry
)
25 for (i
= 0; i
< consistent_debug_registry
->top_level_header
.num_records
; i
++) {
26 dbg_record_header_t
*record
= &consistent_debug_registry
->records
[i
];
27 if (OSCompareAndSwap64(kDbgIdUnusedEntry
, kDbgIdReservedEntry
, &record
->record_id
)) {
28 // Reserved an entry at position i.
29 return (dbg_record_header_t
*)record
;
35 int PE_consistent_debug_inherit(void)
39 uintptr_t root_pointer
= 0;
42 if ((DTLookupEntry(NULL
, "/chosen", &entryP
) == kSuccess
))
43 if (DTGetProperty(entryP
, "consistent-debug-root", (void **)&prop_data
, &size
) == kSuccess
)
44 root_pointer
= prop_data
[0];
45 if (root_pointer
== 0)
47 consistent_debug_registry
= (dbg_registry_t
*)ml_map_high_window(root_pointer
, sizeof(dbg_registry_t
));
51 int PE_consistent_debug_register(uint64_t record_id
, uint64_t physaddr
, uint64_t length
)
53 dbg_record_header_t
*allocated_header
= consistent_debug_allocate_entry();
54 if (allocated_header
== NULL
)
56 allocated_header
->length
= length
;
57 allocated_header
->physaddr
= physaddr
;
58 // Make sure the hdr/length are visible before the record_id.
59 __asm__
volatile("dmb ish" : : : "memory");
60 allocated_header
->record_id
= record_id
;
64 int PE_consistent_debug_enabled(void)
66 return (consistent_debug_registry
!= NULL
);