X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/1c79356b52d46aa6b508fb032f5ae709b1f2897b..ab86ba338a07a58a89f50cf7066a0f0e487ac0cc:/pexpert/ppc/pe_identify_machine.c diff --git a/pexpert/ppc/pe_identify_machine.c b/pexpert/ppc/pe_identify_machine.c index 092d1926f..16f0cd59d 100644 --- a/pexpert/ppc/pe_identify_machine.c +++ b/pexpert/ppc/pe_identify_machine.c @@ -3,19 +3,22 @@ * * @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. + * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The 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. + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -24,10 +27,6 @@ #include #include -/* External declarations */ - -unsigned int LockTimeOut = 12500000; - /* pe_identify_machine: * * Sets up platform parameters. @@ -43,32 +42,61 @@ void pe_identify_machine(void) bzero((void *)&gPEClockFrequencyInfo, sizeof(clock_frequency_info_t)); // Start with default values. - gPEClockFrequencyInfo.bus_clock_rate_hz = 100000000; - gPEClockFrequencyInfo.cpu_clock_rate_hz = 300000000; - gPEClockFrequencyInfo.dec_clock_rate_hz = 25000000; - + gPEClockFrequencyInfo.timebase_frequency_hz = 25000000; + gPEClockFrequencyInfo.bus_clock_rate_hz = 100000000; + gPEClockFrequencyInfo.cpu_clock_rate_hz = 300000000; + // Try to get the values from the device tree. if (DTFindEntry("device_type", "cpu", &cpu) == kSuccess) { - if (DTGetProperty(cpu, "bus-frequency", - (void **)&value, &size) == kSuccess) - gPEClockFrequencyInfo.bus_clock_rate_hz = *value; - else { - if (DTLookupEntry(0, "/", &root) == kSuccess) - if (DTGetProperty(root, "clock-frequency", - (void **)&value, &size) == kSuccess) - gPEClockFrequencyInfo.bus_clock_rate_hz = *value; + // Find the time base frequency first. + if (DTGetProperty(cpu, "timebase-frequency", (void **)&value, &size) == kSuccess) { + // timebase_frequency_hz is only 32 bits, and the device tree should never provide 64 bits + // so this if should never be taken. + if (size == 8) gPEClockFrequencyInfo.timebase_frequency_hz = *(unsigned long long *)value; + else gPEClockFrequencyInfo.timebase_frequency_hz = *value; + } + gPEClockFrequencyInfo.dec_clock_rate_hz = gPEClockFrequencyInfo.timebase_frequency_hz; + + // Find the bus frequency next. Try the cpu node, then the root. + if (DTGetProperty(cpu, "bus-frequency", (void **)&value, &size) == kSuccess) { + if (size == 8) gPEClockFrequencyInfo.bus_frequency_hz = *(unsigned long long *)value; + else gPEClockFrequencyInfo.bus_frequency_hz = *value; + } else { + if (DTLookupEntry(0, "/", &root) == kSuccess) { + if (DTGetProperty(root, "clock-frequency", (void **)&value, &size) == kSuccess) { + if (size == 8) gPEClockFrequencyInfo.bus_frequency_hz = *(unsigned long long *)value; + else gPEClockFrequencyInfo.bus_frequency_hz = *value; + } + } } - if (DTGetProperty(cpu, "clock-frequency", - (void **)&value, &size) == kSuccess) - gPEClockFrequencyInfo.cpu_clock_rate_hz = *value; + gPEClockFrequencyInfo.bus_frequency_min_hz = gPEClockFrequencyInfo.bus_frequency_hz; + gPEClockFrequencyInfo.bus_frequency_max_hz = gPEClockFrequencyInfo.bus_frequency_hz; + + if (gPEClockFrequencyInfo.bus_frequency_hz < 0x100000000ULL) + gPEClockFrequencyInfo.bus_clock_rate_hz = gPEClockFrequencyInfo.bus_frequency_hz; + else + gPEClockFrequencyInfo.bus_clock_rate_hz = 0xFFFFFFFF; - if (DTGetProperty(cpu, "timebase-frequency", - (void **)&value, &size) == kSuccess) - gPEClockFrequencyInfo.dec_clock_rate_hz = *value; + // Find the cpu frequency last. + if (DTGetProperty(cpu, "clock-frequency", (void **)&value, &size) == kSuccess) { + if (size == 8) gPEClockFrequencyInfo.cpu_frequency_hz = *(unsigned long long *)value; + else gPEClockFrequencyInfo.cpu_frequency_hz = *value; + } + + gPEClockFrequencyInfo.cpu_frequency_min_hz = gPEClockFrequencyInfo.cpu_frequency_hz; + gPEClockFrequencyInfo.cpu_frequency_max_hz = gPEClockFrequencyInfo.cpu_frequency_hz; + + if (gPEClockFrequencyInfo.cpu_frequency_hz < 0x100000000ULL) + gPEClockFrequencyInfo.cpu_clock_rate_hz = gPEClockFrequencyInfo.cpu_frequency_hz; + else + gPEClockFrequencyInfo.cpu_clock_rate_hz = 0xFFFFFFFF; } // Set the num / den pairs form the hz values. + gPEClockFrequencyInfo.timebase_frequency_num = gPEClockFrequencyInfo.timebase_frequency_hz; + gPEClockFrequencyInfo.timebase_frequency_den = 1; + gPEClockFrequencyInfo.bus_clock_rate_num = gPEClockFrequencyInfo.bus_clock_rate_hz; gPEClockFrequencyInfo.bus_clock_rate_den = 1; @@ -106,50 +134,51 @@ vm_offset_t get_io_base_addr(void) return 0; } -boolean_t PE_init_ethernet_debugger(void) +vm_offset_t PE_find_scc(void) { - boolean_t result; -#if 0 - DTEntry entryP; - vm_offset_t *address; - unsigned char *netAddr; - int size; - vm_offset_t io; - - if ((io = get_io_base_addr()) - && (DTFindEntry("name", "mace", &entryP) == kSuccess) - && (DTGetProperty(entryP, "local-mac-address", (void **)&netAddr, &size) == kSuccess) - && (DTGetProperty(entryP, "reg", (void **)&address, &size) == kSuccess) - && (size == (2 * 3 * sizeof(vm_offset_t)) )) - { - extern boolean_t kdp_mace_init(void *baseAddresses[3], - unsigned char *netAddr); - void *maceAddrs[3]; - - // address calculation not correct - maceAddrs[0] = (void *) io_map(io + address[0], address[1]); - maceAddrs[1] = (void *) io_map(io + address[2], 0x1000); - maceAddrs[2] = (void *) (((vm_offset_t)maceAddrs[1]) - + address[4] - address[2]); - result = kdp_mace_init( maceAddrs, netAddr ); - - } else -#endif - result = FALSE; - - return result; + vm_offset_t io, sccadd; + DTEntry entryP; + vm_offset_t *sccregs; + unsigned int sccrsize; + + if(!(io = get_io_base_addr())) { /* Get the I/O controller base address */ + return (vm_offset_t)0; /* Hmmm, no I/O??? What gives??? How'd we even boot? */ + } + + +/* Note: if we find a escc-legacy, we need to kind of hack because it can be either an offset + into the iobase or the actual address itself. ORint the two should provide the correct + for either */ + + sccadd = 0; /* Assume none for now */ + + if(DTFindEntry("name", "escc-legacy", &entryP) == kSuccess) { /* Find the old fashioned serial port */ + if (DTGetProperty(entryP, "reg", (void **)&sccregs, &sccrsize) == kSuccess) { /* Do we have some registers? */ + sccadd = ((vm_offset_t)*sccregs | io); /* Get the address */ + } + } + + if(DTFindEntry("name", "escc", &entryP) == kSuccess) { /* Well, see if we just have the new fangled one */ + sccadd = io + 0x12000; /* Yeah, but still return the oldie goldie... */ + } + + return sccadd; /* Return it if you found it */ } -vm_offset_t PE_find_scc(void) +unsigned int PE_init_taproot(vm_offset_t *taddr) { - vm_offset_t io; - DTEntry entryP; - - if ((io = get_io_base_addr()) - && (DTFindEntry("name", "escc", &entryP) == kSuccess)) - io += 0x12000; /* Offset to legacy SCC Registers */ - else - io = 0; - - return io; + DTEntry entryP; + vm_offset_t *tappdata; + unsigned int tappsize; + + + if(DTFindEntry("name", "memory-map", &entryP) != kSuccess) return 0; /* no memory map */ + + if (DTGetProperty(entryP, "TapRoot", (void **)&tappdata, &tappsize) != kSuccess) return 0; /* No TapRoot */ + + tappdata[1] = (tappdata[1] + 4095 ) & -4096; /* Make sure this is a whole page */ + + *taddr = io_map_spec(tappdata[0], tappdata[1]); /* Map it in and return the address */ + tappdata[0] = *taddr; /* Also change property */ + return tappdata[1]; /* And the size */ }