Ejemplo n.º 1
0
void __devinit
ia64_init_itm (void)
{
    unsigned long platform_base_freq, itc_freq;
    struct pal_freq_ratio itc_ratio, proc_ratio;
    long status, platform_base_drift, itc_drift;

    /*
     * According to SAL v2.6, we need to use a SAL call to determine the platform base
     * frequency and then a PAL call to determine the frequency ratio between the ITC
     * and the base frequency.
     */
    status = ia64_sal_freq_base(SAL_FREQ_BASE_PLATFORM,
                                &platform_base_freq, &platform_base_drift);
    if (status != 0) {
        printk(KERN_ERR "SAL_FREQ_BASE_PLATFORM failed: %s\n", ia64_sal_strerror(status));
    } else {
        status = ia64_pal_freq_ratios(&proc_ratio, NULL, &itc_ratio);
        if (status != 0)
            printk(KERN_ERR "PAL_FREQ_RATIOS failed with status=%ld\n", status);
    }
    if (status != 0) {
        /* invent "random" values */
        printk(KERN_ERR
               "SAL/PAL failed to obtain frequency info---inventing reasonable values\n");
        platform_base_freq = 100000000;
        platform_base_drift = -1;	/* no drift info */
        itc_ratio.num = 3;
        itc_ratio.den = 1;
    }
    if (platform_base_freq < 40000000) {
        printk(KERN_ERR "Platform base frequency %lu bogus---resetting to 75MHz!\n",
               platform_base_freq);
        platform_base_freq = 75000000;
        platform_base_drift = -1;
    }
    if (!proc_ratio.den)
        proc_ratio.den = 1;	/* avoid division by zero */
    if (!itc_ratio.den)
        itc_ratio.den = 1;	/* avoid division by zero */

    itc_freq = (platform_base_freq*itc_ratio.num)/itc_ratio.den;

    local_cpu_data->itm_delta = (itc_freq + HZ/2) / HZ;
    printk(KERN_DEBUG "CPU %d: base freq=%lu.%03luMHz, ITC ratio=%u/%u, "
           "ITC freq=%lu.%03luMHz", smp_processor_id(),
           platform_base_freq / 1000000, (platform_base_freq / 1000) % 1000,
           itc_ratio.num, itc_ratio.den, itc_freq / 1000000, (itc_freq / 1000) % 1000);

    if (platform_base_drift != -1) {
        itc_drift = platform_base_drift*itc_ratio.num/itc_ratio.den;
        printk("+/-%ldppm\n", itc_drift);
    } else {
        itc_drift = -1;
        printk("\n");
    }

    local_cpu_data->proc_freq = (platform_base_freq*proc_ratio.num)/proc_ratio.den;
    local_cpu_data->itc_freq = itc_freq;
    local_cpu_data->cyc_per_usec = (itc_freq + USEC_PER_SEC/2) / USEC_PER_SEC;
    local_cpu_data->nsec_per_cyc = ((NSEC_PER_SEC<<IA64_NSEC_PER_CYC_SHIFT)
                                    + itc_freq/2)/itc_freq;

    if (!(sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)) {
        itc_interpolator.frequency = local_cpu_data->itc_freq;
        itc_interpolator.drift = itc_drift;
#ifdef CONFIG_SMP
        /* On IA64 in an SMP configuration ITCs are never accurately synchronized.
         * Jitter compensation requires a cmpxchg which may limit
         * the scalability of the syscalls for retrieving time.
         * The ITC synchronization is usually successful to within a few
         * ITC ticks but this is not a sure thing. If you need to improve
         * timer performance in SMP situations then boot the kernel with the
         * "nojitter" option. However, doing so may result in time fluctuating (maybe
         * even going backward) if the ITC offsets between the individual CPUs
         * are too large.
         */
        if (!nojitter) itc_interpolator.jitter = 1;
#endif
        register_time_interpolator(&itc_interpolator);
    }

    /* Setup the CPU local timer tick */
    ia64_cpu_local_tick();
}
Ejemplo n.º 2
0
int __init init_cyclone_clock(void)
{
	u64* reg;
	u64 base;	/* saved cyclone base address */
	u64 offset;	/* offset from pageaddr to cyclone_timer register */
	int i;
	u32* volatile cyclone_timer;	/* Cyclone MPMC0 register */

	if (!use_cyclone)
		return -ENODEV;

	printk(KERN_INFO "Summit chipset: Starting Cyclone Counter.\n");

	/* find base address */
	offset = (CYCLONE_CBAR_ADDR);
	reg = (u64*)ioremap_nocache(offset, sizeof(u64));
	if(!reg){
		printk(KERN_ERR "Summit chipset: Could not find valid CBAR register.\n");
		use_cyclone = 0;
		return -ENODEV;
	}
	base = readq(reg);
	if(!base){
		printk(KERN_ERR "Summit chipset: Could not find valid CBAR value.\n");
		use_cyclone = 0;
		return -ENODEV;
	}
	iounmap(reg);

	/* setup PMCC */
	offset = (base + CYCLONE_PMCC_OFFSET);
	reg = (u64*)ioremap_nocache(offset, sizeof(u64));
	if(!reg){
		printk(KERN_ERR "Summit chipset: Could not find valid PMCC register.\n");
		use_cyclone = 0;
		return -ENODEV;
	}
	writel(0x00000001,reg);
	iounmap(reg);

	/* setup MPCS */
	offset = (base + CYCLONE_MPCS_OFFSET);
	reg = (u64*)ioremap_nocache(offset, sizeof(u64));
	if(!reg){
		printk(KERN_ERR "Summit chipset: Could not find valid MPCS register.\n");
		use_cyclone = 0;
		return -ENODEV;
	}
	writel(0x00000001,reg);
	iounmap(reg);

	/* map in cyclone_timer */
	offset = (base + CYCLONE_MPMC_OFFSET);
	cyclone_timer = (u32*)ioremap_nocache(offset, sizeof(u32));
	if(!cyclone_timer){
		printk(KERN_ERR "Summit chipset: Could not find valid MPMC register.\n");
		use_cyclone = 0;
		return -ENODEV;
	}

	/*quick test to make sure its ticking*/
	for(i=0; i<3; i++){
		u32 old = readl(cyclone_timer);
		int stall = 100;
		while(stall--) barrier();
		if(readl(cyclone_timer) == old){
			printk(KERN_ERR "Summit chipset: Counter not counting! DISABLED\n");
			iounmap(cyclone_timer);
			cyclone_timer = 0;
			use_cyclone = 0;
			return -ENODEV;
		}
	}
	/* initialize last tick */
	cyclone_interpolator.addr = cyclone_timer;
	register_time_interpolator(&cyclone_interpolator);

	return 0;
}