|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * The contents of this file constitute Original Code as defined in and ! 7: * are subject to the Apple Public Source License Version 1.1 (the ! 8: * "License"). You may not use this file except in compliance with the ! 9: * License. Please obtain a copy of the License at ! 10: * http://www.apple.com/publicsource and read it before using this file. ! 11: * ! 12: * This Original Code and all software distributed under the License are ! 13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 17: * License for the specific language governing rights and limitations ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: #include <pexpert/protos.h> ! 23: #include <pexpert/pexpert.h> ! 24: #include <pexpert/ppc/powermac.h> ! 25: #include <pexpert/ppc/powermac_pci.h> ! 26: #include <pexpert/device_tree.h> ! 27: ! 28: /* Local declarations */ ! 29: void pe_identify_machine(void); ! 30: int get_clock_frequency(void); ! 31: int init_powermac_machine_info(void); ! 32: ! 33: /* External declarations */ ! 34: ! 35: unsigned int LockTimeOut = 12500000; ! 36: ! 37: /* pe_identify_machine: ! 38: * ! 39: * Sets up platform parameters. ! 40: * Returns: nothing ! 41: */ ! 42: void pe_identify_machine(void) ! 43: { ! 44: unsigned int dec_rate; ! 45: union { ! 46: unsigned long fixed; ! 47: unsigned char top; ! 48: } tmp_fixed; ! 49: ! 50: /* Everything starts out zeroed... */ ! 51: bzero((void *)&powermac_info, sizeof(powermac_info_t)); ! 52: ! 53: powermac_info.struct_version = POWERMAC_INFO_VERSION; ! 54: ! 55: /* ! 56: * First, find out everything we can from the device tree. ! 57: * ! 58: */ ! 59: ! 60: powermac_info.bus_clock_rate_hz = get_clock_frequency(); ! 61: ! 62: LockTimeOut = powermac_info.bus_clock_rate_hz >> 4; /* XXX */ ! 63: ! 64: powermac_info.proc_clock_to_nsec_numerator = 100000 * 4; ! 65: powermac_info.proc_clock_to_nsec_denominator = powermac_info.bus_clock_rate_hz / 10000; ! 66: ! 67: dec_rate = powermac_info.bus_clock_rate_hz / 4; ! 68: // Do the lower 24 bits (ie the remainder * 1_Fixed / dec_rate) ! 69: tmp_fixed.fixed = ! 70: ((1000000000 % dec_rate) << 24) / dec_rate; ! 71: ! 72: // Do the top 8 bits (ie the whole part of the number) ! 73: tmp_fixed.top = 1000000000 / dec_rate; ! 74: ! 75: powermac_info.dec_clock_period = tmp_fixed.fixed; ! 76: ! 77: init_powermac_machine_info(); ! 78: ! 79: //powermac_info.io_coherent = powermac_is_coherent(); ! 80: powermac_info.io_coherent = 1; ! 81: } ! 82: ! 83: int pe_map_physical_range( vm_offset_t phys, unsigned int size, ! 84: int findSpace, int cache, vm_offset_t * virt) ! 85: { ! 86: ! 87: *virt = io_map( phys, size); ! 88: ! 89: return( 0); ! 90: } ! 91: ! 92: ! 93: /* get_io_base_addr(): ! 94: * ! 95: * Get the base address of the io controller. ! 96: */ ! 97: vm_offset_t get_io_base_addr(void) ! 98: { ! 99: DTEntry entryP; ! 100: vm_offset_t *address; ! 101: int size; ! 102: ! 103: if( (DTFindEntry("device_type", "dbdma", &entryP) == kSuccess) ! 104: || (DTFindEntry("device_type", "mac-io", &entryP) == kSuccess)) ! 105: { ! 106: if (DTGetProperty(entryP, "AAPL,address", (void **)&address, &size) == kSuccess) ! 107: return(*address); ! 108: ! 109: if (DTGetProperty(entryP, "assigned-addresses", (void **)&address, &size) == kSuccess) ! 110: // address calculation not correct ! 111: return(*(address+2)); ! 112: } ! 113: ! 114: panic("Uhmmm.. I can't get this machine's io base address\n"); ! 115: return( 0 ); ! 116: } ! 117: ! 118: boolean_t PE_init_ethernet_debugger( void ) ! 119: { ! 120: DTEntry entryP; ! 121: vm_offset_t * address; ! 122: unsigned char * netAddr; ! 123: int size; ! 124: vm_offset_t io; ! 125: boolean_t result; ! 126: ! 127: if( (io = get_io_base_addr()) ! 128: && (DTFindEntry("name", "mace", &entryP) == kSuccess) ! 129: && (DTGetProperty(entryP, "local-mac-address", (void **)&netAddr, &size) == kSuccess) ! 130: && (DTGetProperty(entryP, "reg", (void **)&address, &size) == kSuccess) ! 131: && (size == (2 * 3 * sizeof(vm_offset_t)) )) ! 132: { ! 133: extern boolean_t kdp_mace_init( void * baseAddresses[3], ! 134: unsigned char * netAddr ); ! 135: void * maceAddrs[3]; ! 136: ! 137: // address calculation not correct ! 138: maceAddrs[0] = (void *) io_map(io + address[0], address[1]); ! 139: maceAddrs[1] = (void *) io_map(io + address[2], 0x1000); ! 140: maceAddrs[2] = (void *) (((vm_offset_t)maceAddrs[1]) ! 141: + address[4] - address[2]); ! 142: result = kdp_mace_init( maceAddrs, netAddr ); ! 143: ! 144: } else ! 145: result = FALSE; ! 146: ! 147: return( result ); ! 148: } ! 149: ! 150: vm_offset_t PE_find_scc( void ) ! 151: { ! 152: vm_offset_t io; ! 153: DTEntry entryP; ! 154: ! 155: if( (io = get_io_base_addr()) ! 156: && (DTFindEntry("name", "escc", &entryP) == kSuccess)) ! 157: io += PCI_SCC_OFFSET_PHYS; ! 158: else ! 159: io = 0; ! 160: ! 161: return( io ); ! 162: } ! 163: ! 164: /* get_clock_frequency(): ! 165: * ! 166: * Get the clock freq ! 167: */ ! 168: int get_clock_frequency() ! 169: { ! 170: DTEntry entry; ! 171: int *freq; ! 172: int size; ! 173: ! 174: if (DTLookupEntry(0, "/", &entry) == kSuccess) ! 175: if (DTGetProperty(entry, "clock-frequency", (void **)&freq, &size) == kSuccess) ! 176: return(*freq); ! 177: ! 178: return(50000000); // 50 MHz default ! 179: } ! 180: ! 181: int ! 182: init_powermac_machine_info(void) ! 183: { ! 184: DTEntry entry; ! 185: int *value; ! 186: int size; ! 187: ! 188: value = (int *)0; ! 189: size = 0; ! 190: ! 191: if (DTFindEntry("device_type", "cpu", &entry) == kSuccess) { ! 192: if (DTGetProperty(entry, "d-cache-block-size", ! 193: (void **)&value, &size) == kSuccess) ! 194: powermac_info.dcache_block_size = *value; ! 195: ! 196: if (DTGetProperty(entry, "d-cache-size", ! 197: (void **)&value, &size) == kSuccess) ! 198: powermac_info.dcache_size = *value; ! 199: ! 200: if (DTGetProperty(entry, "i-cache-size", ! 201: (void **)&value, &size) == kSuccess) ! 202: powermac_info.icache_size = *value; ! 203: ! 204: if (DTGetProperty(entry, "cpu-version", ! 205: (void **)&value, &size) == kSuccess) ! 206: powermac_info.processor_version = *value; ! 207: ! 208: if (DTGetProperty(entry, "clock-frequency", ! 209: (void **)&value, &size) == kSuccess) ! 210: powermac_info.cpu_clock_rate_hz = *value; ! 211: else powermac_info.cpu_clock_rate_hz = 300000000; ! 212: ! 213: if (DTGetProperty(entry, "timebase-frequency", ! 214: (void **)&value, &size) == kSuccess) ! 215: powermac_info.dec_clock_rate_hz = *value; ! 216: else powermac_info.dec_clock_rate_hz = 25000000; ! 217: ! 218: if (DTGetProperty(entry, "bus-frequency", ! 219: (void **)&value, &size) == kSuccess) ! 220: powermac_info.bus_clock_rate_num = *value; ! 221: else powermac_info.bus_clock_rate_num = get_clock_frequency(); ! 222: ! 223: } else ! 224: return 1; ! 225: ! 226: powermac_info.bus_clock_rate_den = 1; ! 227: ! 228: powermac_info.bus_to_dec_rate_num = 1; ! 229: powermac_info.bus_to_dec_rate_den = powermac_info.bus_clock_rate_num / ! 230: powermac_info.dec_clock_rate_hz; ! 231: ! 232: powermac_info.bus_to_cpu_rate_num = ! 233: (2 * powermac_info.cpu_clock_rate_hz) / ! 234: powermac_info.bus_clock_rate_num; ! 235: powermac_info.bus_to_cpu_rate_den = 2; ! 236: ! 237: if (DTFindEntry("device_type", "cache", &entry) == kSuccess) { ! 238: if (DTGetProperty(entry, "cache-unified", ! 239: (void **)&value, &size) == kSuccess) ! 240: powermac_info.caches_unified = 1; ! 241: } else ! 242: return 1; ! 243: ! 244: return 0; ! 245: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.