/* * Timer device implementation for SGI UV platform. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (c) 2009 Silicon Graphics, Inc. All rights reserved. *
*/
/* name of the device, usually in /dev */ #define UV_MMTIMER_NAME "mmtimer" #define UV_MMTIMER_DESC "SGI UV Memory Mapped RTC Timer" #define UV_MMTIMER_VERSION "1.0"
/** * uv_mmtimer_ioctl - ioctl interface for /dev/uv_mmtimer * @file: file structure for the device * @cmd: command to execute * @arg: optional argument to command * * Executes the command specified by @cmd. Returns 0 for success, < 0 for * failure. * * Valid commands: * * %MMTIMER_GETOFFSET - Should return the offset (relative to the start * of the page where the registers are mapped) for the counter in question. * * %MMTIMER_GETRES - Returns the resolution of the clock in femto (10^-15) * seconds * * %MMTIMER_GETFREQ - Copies the frequency of the clock in Hz to the address * specified by @arg * * %MMTIMER_GETBITS - Returns the number of bits in the clock's counter * * %MMTIMER_MMAPAVAIL - Returns 1 if registers can be mmap'd into userspace * * %MMTIMER_GETCOUNTER - Gets the current value in the counter and places it * in the address specified by @arg.
*/ staticlong uv_mmtimer_ioctl(struct file *file, unsignedint cmd, unsignedlong arg)
{ int ret = 0;
switch (cmd) { case MMTIMER_GETOFFSET: /* offset of the counter */ /* * Starting with HUB rev 2.0, the UV RTC register is * replicated across all cachelines of it's own page. * This allows faster simultaneous reads from a given socket. * * The offset returned is in 64 bit units.
*/ if (uv_get_min_hub_revision_id() == 1)
ret = 0; else
ret = ((uv_blade_processor_id() * L1_CACHE_BYTES) %
PAGE_SIZE) / 8; break;
case MMTIMER_GETRES: /* resolution of the clock in 10^-15 s */ if (copy_to_user((unsignedlong __user *)arg,
&uv_mmtimer_femtoperiod, sizeof(unsignedlong)))
ret = -EFAULT; break;
case MMTIMER_GETFREQ: /* frequency in Hz */ if (copy_to_user((unsignedlong __user *)arg,
&sn_rtc_cycles_per_second, sizeof(unsignedlong)))
ret = -EFAULT; break;
case MMTIMER_GETBITS: /* number of bits in the clock */
ret = hweight64(UVH_RTC_REAL_TIME_CLOCK_MASK); break;
case MMTIMER_MMAPAVAIL:
ret = 1; break;
case MMTIMER_GETCOUNTER: if (copy_to_user((unsignedlong __user *)arg,
(unsignedlong *)uv_local_mmr_address(UVH_RTC), sizeof(unsignedlong)))
ret = -EFAULT; break; default:
ret = -ENOTTY; break;
} return ret;
}
/** * uv_mmtimer_mmap - maps the clock's registers into userspace * @file: file structure for the device * @vma: VMA to map the registers into * * Calls remap_pfn_range() to map the clock's registers into * the calling process' address space.
*/ staticint uv_mmtimer_mmap(struct file *file, struct vm_area_struct *vma)
{ unsignedlong uv_mmtimer_addr;
if (vma->vm_end - vma->vm_start != PAGE_SIZE) return -EINVAL;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.