1237433Skib/*- 2237433Skib * Copyright 2012 Konstantin Belousov <kib@FreeBSD.ORG>. 3237433Skib * All rights reserved. 4237433Skib * 5237433Skib * Redistribution and use in source and binary forms, with or without 6237433Skib * modification, are permitted provided that the following conditions 7237433Skib * are met: 8237433Skib * 1. Redistributions of source code must retain the above copyright 9237433Skib * notice, this list of conditions and the following disclaimer. 10237433Skib * 2. Redistributions in binary form must reproduce the above copyright 11237433Skib * notice, this list of conditions and the following disclaimer in the 12237433Skib * documentation and/or other materials provided with the distribution. 13237433Skib * 14237433Skib * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15237433Skib * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16237433Skib * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17237433Skib * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18237433Skib * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19237433Skib * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20237433Skib * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21237433Skib * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22237433Skib * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23237433Skib * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24237433Skib * 25237433Skib * $FreeBSD$ 26237433Skib */ 27237433Skib 28237433Skib#ifndef _SYS_VDSO_H 29237433Skib#define _SYS_VDSO_H 30237433Skib 31237433Skib#include <sys/types.h> 32237433Skib#include <machine/vdso.h> 33237433Skib 34237433Skibstruct vdso_timehands { 35237433Skib uint32_t th_algo; 36237433Skib uint32_t th_gen; 37237433Skib uint64_t th_scale; 38237433Skib uint32_t th_offset_count; 39237433Skib uint32_t th_counter_mask; 40237433Skib struct bintime th_offset; 41237433Skib struct bintime th_boottime; 42237433Skib VDSO_TIMEHANDS_MD 43237433Skib}; 44237433Skib 45237433Skibstruct vdso_timekeep { 46237433Skib uint32_t tk_ver; 47237433Skib uint32_t tk_enabled; 48237433Skib uint32_t tk_current; 49237433Skib struct vdso_timehands tk_th[]; 50237433Skib}; 51237433Skib 52237433Skib#define VDSO_TK_CURRENT_BUSY 0xffffffff 53237433Skib#define VDSO_TK_VER_1 0x1 54237433Skib#define VDSO_TK_VER_CURR VDSO_TK_VER_1 55237433Skib#define VDSO_TH_ALGO_1 0x1 56237433Skib 57237433Skib#ifndef _KERNEL 58237433Skib 59237433Skibstruct timespec; 60237433Skibstruct timeval; 61237433Skibstruct timezone; 62237433Skib 63237433Skibint __vdso_clock_gettime(clockid_t clock_id, struct timespec *ts); 64237433Skibint __vdso_gettimeofday(struct timeval *tv, struct timezone *tz); 65237433Skibu_int __vdso_gettc(const struct vdso_timehands *vdso_th); 66246117Skibint __vdso_gettimekeep(struct vdso_timekeep **tk); 67237433Skib 68237433Skib#endif 69237433Skib 70237433Skib#ifdef _KERNEL 71237433Skib 72237474Skibvoid timekeep_push_vdso(void); 73237474Skib 74237433Skibuint32_t tc_fill_vdso_timehands(struct vdso_timehands *vdso_th); 75237433Skib 76237433Skib/* 77237433Skib * The cpu_fill_vdso_timehands() function should fill MD-part of the 78237433Skib * struct vdso_timehands, which is both machine- and 79237433Skib * timecounter-depended. The return value should be 1 if fast 80237433Skib * userspace timecounter is enabled by hardware, and 0 otherwise. The 81237433Skib * global sysctl enable override is handled by machine-independed code 82237433Skib * after cpu_fill_vdso_timehands() call is made. 83237433Skib */ 84237433Skibuint32_t cpu_fill_vdso_timehands(struct vdso_timehands *vdso_th); 85237433Skib 86237433Skib#define VDSO_TH_NUM 4 87237433Skib 88237433Skib#ifdef COMPAT_FREEBSD32 89237433Skibstruct bintime32 { 90237433Skib uint32_t sec; 91237433Skib uint32_t frac[2]; 92237433Skib}; 93237433Skib 94237433Skibstruct vdso_timehands32 { 95237433Skib uint32_t th_algo; 96237433Skib uint32_t th_gen; 97237433Skib uint32_t th_scale[2]; 98237433Skib uint32_t th_offset_count; 99237433Skib uint32_t th_counter_mask; 100237433Skib struct bintime32 th_offset; 101237433Skib struct bintime32 th_boottime; 102237433Skib VDSO_TIMEHANDS_MD32 103237433Skib}; 104237433Skib 105237433Skibstruct vdso_timekeep32 { 106237433Skib uint32_t tk_ver; 107237433Skib uint32_t tk_enabled; 108237433Skib uint32_t tk_current; 109237433Skib struct vdso_timehands32 tk_th[]; 110237433Skib}; 111237433Skib 112237433Skibuint32_t tc_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32); 113237433Skibuint32_t cpu_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32); 114237433Skib 115237433Skib#endif 116237433Skib#endif 117237433Skib 118237433Skib#endif 119