FreeBSD/sys/powerpc/powerpc/cpu.c
/* Get current clock frequency for the given cpu id. */
Get current clock frequency for the given cpu id.
Get current clock frequency for the given cpu id .
int
cpu_est_clockrate(int cpu_id, uint64_t *cps)
{
	uint16_t	vers;
	register_t	msr;
	phandle_t	cpu, dev, root;
	int		res  = 0;
	char		buf[8];
	vers = mfpvr() >> 16;
	msr = mfmsr();
	mtmsr(msr & ~PSL_EE);
	switch (vers) {
		case MPC7450:
		case MPC7455:
		case MPC7457:
		case MPC750:
		case IBM750FX:
		case MPC7400:
		case MPC7410:
		case MPC7447A:
		case MPC7448:
			mtspr(SPR_MMCR0, SPR_MMCR0_FC);
			mtspr(SPR_PMC1, 0);
			mtspr(SPR_MMCR0, SPR_MMCR0_PMC1SEL(PMCN_CYCLES));
			DELAY(1000);
			*cps = (mfspr(SPR_PMC1) * 1000) + 4999;
			mtspr(SPR_MMCR0, SPR_MMCR0_FC);
			mtmsr(msr);
			return (0);
		case IBM970:
		case IBM970FX:
		case IBM970MP:
			isync();
			mtspr(SPR_970MMCR0, SPR_MMCR0_FC);
			isync();
			mtspr(SPR_970MMCR1, 0);
			mtspr(SPR_970MMCRA, 0);
			mtspr(SPR_970PMC1, 0);
			mtspr(SPR_970MMCR0,
			    SPR_970MMCR0_PMC1SEL(PMC970N_CYCLES));
			isync();
			DELAY(1000);
			powerpc_sync();
			mtspr(SPR_970MMCR0, SPR_MMCR0_FC);
			*cps = (mfspr(SPR_970PMC1) * 1000) + 4999;
			mtmsr(msr);
			return (0);
		default:
			root = OF_peer(0);
			if (root == 0)
				return (ENXIO);
			dev = OF_child(root);
			while (dev != 0) {
				res = OF_getprop(dev, "name", buf, sizeof(buf));
				if (res > 0 && strcmp(buf, "cpus") == 0)
					break;
				dev = OF_peer(dev);
			}
			cpu = OF_child(dev);
			while (cpu != 0) {
				res = OF_getprop(cpu, "device_type", buf,
						sizeof(buf));
				if (res > 0 && strcmp(buf, "cpu") == 0)
					break;
				cpu = OF_peer(cpu);
			}
			if (cpu == 0)
				return (ENOENT);
			if (OF_getprop(cpu, "ibm,extended-clock-frequency",
			    cps, sizeof(*cps)) >= 0) {
				return (0);
			} else if (OF_getprop(cpu, "clock-frequency", cps, 
			    sizeof(cell_t)) >= 0) {
				*cps >>= 32;
				return (0);
			} else {
				return (ENOENT);
			}
	}
}
int cpu_est_clockrate ( int cpu_id , uint64_t * cps ) { uint16_t vers ; register_t msr ; phandle_t cpu , dev , root ; int res = 0 ; char buf [ 8 ] ; vers = mfpvr ( ) >> 16 ; msr = mfmsr ( ) ; mtmsr ( msr & ~ PSL_EE ) ; switch ( vers ) { case MPC7450 : case MPC7455 : case MPC7457 : case MPC750 : case IBM750FX : case MPC7400 : case MPC7410 : case MPC7447A : case MPC7448 : mtspr ( SPR_MMCR0 , SPR_MMCR0_FC ) ; mtspr ( SPR_PMC1 , 0 ) ; mtspr ( SPR_MMCR0 , SPR_MMCR0_PMC1SEL ( PMCN_CYCLES ) ) ; DELAY ( 1000 ) ; * cps = ( mfspr ( SPR_PMC1 ) * 1000 ) + 4999 ; mtspr ( SPR_MMCR0 , SPR_MMCR0_FC ) ; mtmsr ( msr ) ; return ( 0 ) ; case IBM970 : case IBM970FX : case IBM970MP : isync ( ) ; mtspr ( SPR_970MMCR0 , SPR_MMCR0_FC ) ; isync ( ) ; mtspr ( SPR_970MMCR1 , 0 ) ; mtspr ( SPR_970MMCRA , 0 ) ; mtspr ( SPR_970PMC1 , 0 ) ; mtspr ( SPR_970MMCR0 , SPR_970MMCR0_PMC1SEL ( PMC970N_CYCLES ) ) ; isync ( ) ; DELAY ( 1000 ) ; powerpc_sync ( ) ; mtspr ( SPR_970MMCR0 , SPR_MMCR0_FC ) ; * cps = ( mfspr ( SPR_970PMC1 ) * 1000 ) + 4999 ; mtmsr ( msr ) ; return ( 0 ) ; default : root = OF_peer ( 0 ) ; if ( root == 0 ) return ( ENXIO ) ; dev = OF_child ( root ) ; while ( dev != 0 ) { res = OF_getprop ( dev , " " , buf , sizeof ( buf ) ) ; if ( res > 0 && strcmp ( buf , " " ) == 0 ) break ; dev = OF_peer ( dev ) ; } cpu = OF_child ( dev ) ; while ( cpu != 0 ) { res = OF_getprop ( cpu , " " , buf , sizeof ( buf ) ) ; if ( res > 0 && strcmp ( buf , " " ) == 0 ) break ; cpu = OF_peer ( cpu ) ; } if ( cpu == 0 ) return ( ENOENT ) ; if ( OF_getprop ( cpu , " " , cps , sizeof ( * cps ) ) >= 0 ) { return ( 0 ) ; } else if ( OF_getprop ( cpu , " " , cps , sizeof ( cell_t ) ) >= 0 ) { * cps >>= 32 ; return ( 0 ) ; } else { return ( ENOENT ) ; } } }
Get current clock frequency for the given cpu id.
Get current clock frequency for the given cpu id .