1/*
2 * Copyright (c) 2012-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#include <mach_kdp.h>
30#include <mach/vm_param.h>
31#include <arm64/lowglobals.h>
32#include <vm/vm_object.h>
33#include <vm/vm_page.h>
34
35/*
36 * On arm64, the low globals get mapped low via machine_init() during kernel
37 * bootstrap.
38 */
39
40extern vm_offset_t vm_kernel_stext;
41extern void *version;
42extern void *kmod;
43extern void *kdp_trans_off;
44extern void *osversion;
45extern void *flag_kdp_trigger_reboot;
46extern void *manual_pkt;
47extern struct vm_object pmap_object_store; /* store pt pages */
48extern vm_offset_t c_buffers;
49extern vm_size_t c_buffers_size;
50
51lowglo lowGlo __attribute__ ((aligned(PAGE_MAX_SIZE))) = {
52 // Increment the major version for changes that break the current Astris
53 // usage of lowGlo values
54 // Increment the minor version for changes that provide additonal info/function
55 // but does not break current usage
56 .lgLayoutMajorVersion = 3,
57 .lgLayoutMinorVersion = 3,
58 .lgLayoutMagic = LOWGLO_LAYOUT_MAGIC,
59 .lgVerCode = { 'K', 'r', 'a', 'k', 'e', 'n', ' ', ' ' },
60 .lgZero = 0,
61 .lgStext = 0, // To be filled in below
62 .lgVersion = (uint64_t) &version,
63 .lgOSVersion = (uint64_t) &osversion,
64 .lgKmodptr = (uint64_t) &kmod,
65#if MACH_KDP && CONFIG_KDP_INTERACTIVE_DEBUGGING
66 .lgTransOff = (uint64_t) &kdp_trans_off,
67 .lgRebootFlag = (uint64_t) &flag_kdp_trigger_reboot,
68 .lgManualPktAddr = (uint64_t) &manual_pkt,
69#endif
70 .lgPmapMemQ = (uint64_t)&(pmap_object_store.memq),
71 .lgPmapMemPageOffset = offsetof(struct vm_page_with_ppnum, vmp_phys_page),
72 .lgPmapMemChainOffset = offsetof(struct vm_page, vmp_listq),
73 .lgPmapMemPagesize = (uint64_t)sizeof(struct vm_page),
74 .lgPmapMemFromArrayMask = VM_PAGE_PACKED_FROM_ARRAY,
75 .lgPmapMemPackedShift = VM_PAGE_PACKED_PTR_SHIFT,
76 .lgPmapMemPackedBaseAddr = VM_PAGE_PACKED_PTR_BASE,
77 .lgPmapMemStartAddr = -1,
78 .lgPmapMemEndAddr = -1,
79 .lgPmapMemFirstppnum = -1,
80 .lgPageShift = ARM_PGSHIFT,
81 .lgVmFirstPhys = -1,
82 .lgVmLastPhys = -1,
83 .lgPhysMapBase = -1,
84 .lgPhysMapEnd = -1,
85 .lgPmapIoRangePtr = -1,
86 .lgNumPmapIoRanges = -1,
87 .lgCompressorBufferAddr = (uint64_t) &c_buffers, // added in 3.3
88 .lgCompressorSizeAddr = (uint64_t) &c_buffers_size // added in 3.3
89};
90
91void
92patch_low_glo(void)
93{
94 lowGlo.lgStext = (uint64_t)vm_kernel_stext;
95}
96
97void
98patch_low_glo_static_region(uint64_t address, uint64_t size)
99{
100 lowGlo.lgStaticAddr = address;
101 lowGlo.lgStaticSize = size;
102
103 /**
104 * These values are set in pmap_bootstrap() and represent the range of
105 * kernel managed memory.
106 */
107 extern const pmap_paddr_t vm_first_phys;
108 extern const pmap_paddr_t vm_last_phys;
109 assertf((vm_first_phys != 0) && (vm_last_phys != 0),
110 "Tried setting the Low Globals before pmap_bootstrap()");
111 lowGlo.lgVmFirstPhys = vm_first_phys;
112 lowGlo.lgVmLastPhys = vm_last_phys;
113
114 /**
115 * These values are set in pmap_bootstrap() and represent an array of all
116 * kernel-managed I/O regions (pmap-io-ranges in the device tree). Some of
117 * these regions may include DRAM carved out for usage by other agents on
118 * the system.
119 *
120 * Need to forward-declare pmap_io_range_t since that only exists in the
121 * PMAP code.
122 */
123 typedef struct pmap_io_range pmap_io_range_t;
124 extern const pmap_io_range_t* io_attr_table;
125 extern const unsigned int num_io_rgns;
126 lowGlo.lgPmapIoRangePtr = (uint64_t)io_attr_table;
127 lowGlo.lgNumPmapIoRanges = (uint64_t)num_io_rgns;
128
129 /**
130 * These values are set in arm_vm_init() and represent the virtual address
131 * space used by the physical aperture.
132 */
133 extern const vm_map_address_t physmap_base;
134 extern const vm_map_address_t physmap_end;
135 assertf((physmap_base != 0) && (physmap_end != 0),
136 "Tried setting the Low Globals before arm_vm_init()");
137 lowGlo.lgPhysMapBase = physmap_base;
138 lowGlo.lgPhysMapEnd = physmap_end;
139}
140
141void
142patch_low_glo_vm_page_info(void * start_addr, void * end_addr, uint32_t first_ppnum)
143{
144 lowGlo.lgPmapMemStartAddr = (uint64_t)start_addr;
145 lowGlo.lgPmapMemEndAddr = (uint64_t)end_addr;
146 lowGlo.lgPmapMemFirstppnum = first_ppnum;
147 lowGlo.lgPageShift = PAGE_SHIFT;
148}
149