Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | /* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 1.1 (the * "License"). You may not use this file except in compliance with the * License. Please obtain a copy of the License at * http://www.apple.com/publicsource and read it before using this file. * * This Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. * * @APPLE_LICENSE_HEADER_END@ */ #include <mach/std_types.h> #include <ppc/proc_reg.h> #include <ppc/boot.h> #include <ppc/mem.h> // The sophisticated BAT manager unsigned int mappedSegments = 0; unsigned int availableBATs = 0xE; // BAT0 used, 1-3 available vm_offset_t PEResidentAddress( vm_offset_t address, vm_size_t length ) { if( mappedSegments & (1 << (15 & (address >> 28)))) return( address); else return( 0); } vm_offset_t PEMapSegment( vm_offset_t address, vm_size_t length ) { vm_offset_t retAddress; bat_t bat; int batNum; retAddress = PEResidentAddress( address, length ); if( retAddress) return( retAddress); if( length < (256 * 1024)) return( 0); if( availableBATs == 0) return( 0); for( batNum = 0; (0 == (availableBATs & (1 << batNum))); batNum++); bat.upper.word = address & 0xf0000000; bat.lower.word = bat.upper.word; bat.upper.bits.bl = 0x7ff; /* size = 256M */ bat.upper.bits.vs = 1; bat.upper.bits.vp = 0; /* user disabled */ bat.lower.bits.wimg = PTE_WIMG_IO; bat.lower.bits.pp = 2; /* read/write access */ // Update the shadow bats. shadow_BAT.DBATs[batNum].upper = bat.upper.word; shadow_BAT.DBATs[batNum].lower = bat.lower.word; sync();isync(); switch( batNum) { // !%$@!! mtdbat needs literal case 0: mtdbatu( 0, BAT_INVALID); /* invalidate old mapping */ mtdbatl( 0, bat.lower.word); mtdbatu( 0, bat.upper.word); break; case 1: mtdbatu( 1, BAT_INVALID); mtdbatl( 1, bat.lower.word); mtdbatu( 1, bat.upper.word); break; case 2: mtdbatu( 2, BAT_INVALID); mtdbatl( 2, bat.lower.word); mtdbatu( 2, bat.upper.word); break; case 3: mtdbatu( 3, BAT_INVALID); mtdbatl( 3, bat.lower.word); mtdbatu( 3, bat.upper.word); break; } sync();isync(); availableBATs &= ~(1 << batNum); mappedSegments |= (1 << (15 & (address >> 28))); return( address); } void initialize_bats(boot_args *args) { int i; /* Give ourselves the virtual map that we would like */ bat_t bat; /* Make sure that the BATs map what we expect. Note * that we assume BAT0 maps kernel text & data. * * Except, oops, none of the BATs have ever been set. * Developer worked only by fluke. */ bat.upper.word = 0; bat.upper.bits.bepi = 0x0; /* start at logical addr 0M */ /* * We should be smarter here about picking an * amount to map */ bat.upper.bits.bl = 0x7ff; /* size = 256M */ bat.upper.bits.vs = 1; bat.upper.bits.vp = 0; bat.lower.word = 0; bat.lower.bits.brpn = 0x0; /* start at physical addr 0 */ bat.lower.bits.wimg = PTE_WIMG_DEFAULT; bat.lower.bits.pp = 2; /* read/write access */ /* Mustn't cause any data traffic here, * we're modifying our data BAT register! */ sync(); mtdbatu(0, BAT_INVALID); /* invalidate old mapping */ isync(); mtdbatl(0, bat.lower.word); isync(); mtdbatu(0, bat.upper.word); /* update with new mapping */ isync(); mtibatl(0, bat.lower.word); isync(); mtibatu(0, bat.upper.word); /* update with new mapping */ isync(); sync();isync(); mtdbatu(1,BAT_INVALID); mtdbatl(1,BAT_INVALID); mtibatu(1,BAT_INVALID); mtibatl(1,BAT_INVALID); mtdbatu(2,BAT_INVALID); mtdbatl(2,BAT_INVALID); mtibatu(2,BAT_INVALID); mtibatl(2,BAT_INVALID); mtdbatu(3,BAT_INVALID); mtdbatl(3,BAT_INVALID); mtibatu(3,BAT_INVALID); mtibatl(3,BAT_INVALID); sync();isync(); PEMapSegment( 0xf0000000, 0x10000000); if( args->Video.v_baseAddr) PEMapSegment( args->Video.v_baseAddr, 0x10000000); /* Set up segment registers as VM through space 0 */ isync(); for (i=0; i<=15; i++) { mtsrin(KERNEL_SEG_REG0_VALUE | i, i * 0x10000000); } isync(); } /* * Adjust the size of the region mapped by a BAT * to to be just large enough to include the specified * offset, and return the offset of the new end of the region. * Note that both 'offsets' are really *lengths*, i.e. the * offset of the end of the mapped region from the beginning. * Either the instruction or data BATs (or both) can be specified. * If the new length is greater than the size mappable by a BAT, * then that value is just returned and no changes are made. */ vm_offset_t adjust_bat_limit( vm_offset_t new_minimum, int batn, boolean_t ibat, boolean_t dbat ) { vm_offset_t new_limit; if (new_minimum <= 256*1024*1024) { unsigned int bl = 0; new_limit = 128*1024; while (new_limit < new_minimum) { new_limit *= 2; bl = (bl << 1) | 1; } { batu_t batu; if (dbat) switch (batn) { case 0: mfdbatu(batu, 0 ); batu.bits.bl = bl; sync(); isync(); mtdbatu( 0, batu); sync(); isync(); break; case 1: mfdbatu(batu, 1 ); batu.bits.bl = bl; sync(); isync(); mtdbatu( 1, batu); sync(); isync(); break; case 2: mfdbatu(batu, 2 ); batu.bits.bl = bl; sync(); isync(); mtdbatu( 2, batu); sync(); isync(); break; case 3: mfdbatu(batu, 3 ); batu.bits.bl = bl; sync(); isync(); mtdbatu( 3, batu); sync(); isync(); break; } if (ibat) switch (batn) { case 0: mfibatu(batu, 0 ); batu.bits.bl = bl; sync(); isync(); mtibatu( 0, batu); sync(); isync(); break; case 1: mfibatu(batu, 1 ); batu.bits.bl = bl; sync(); isync(); mtibatu( 1, batu); sync(); isync(); break; case 2: mfibatu(batu, 2 ); batu.bits.bl = bl; sync(); isync(); mtibatu( 2, batu); sync(); isync(); break; case 3: mfibatu(batu, 3 ); batu.bits.bl = bl; sync(); isync(); mtibatu( 3, batu); sync(); isync(); break; } } } else new_limit = new_minimum; return (new_limit); } |