vdso.h revision 305866
111406Sbde/*- 211406Sbde * Copyright 2012 Konstantin Belousov <kib@FreeBSD.ORG>. 311406Sbde * All rights reserved. 411406Sbde * 511406Sbde * Redistribution and use in source and binary forms, with or without 611406Sbde * modification, are permitted provided that the following conditions 711406Sbde * are met: 811406Sbde * 1. Redistributions of source code must retain the above copyright 911406Sbde * notice, this list of conditions and the following disclaimer. 1011406Sbde * 2. Redistributions in binary form must reproduce the above copyright 1111406Sbde * notice, this list of conditions and the following disclaimer in the 1211406Sbde * documentation and/or other materials provided with the distribution. 1311406Sbde * 1411406Sbde * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1511406Sbde * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1611406Sbde * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1711406Sbde * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1811406Sbde * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1911406Sbde * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2011406Sbde * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2111406Sbde * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2211406Sbde * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2311406Sbde * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2411406Sbde * 2511406Sbde * $FreeBSD: stable/11/sys/sys/vdso.h 305866 2016-09-16 10:04:28Z kib $ 2611406Sbde */ 2711406Sbde 2811406Sbde#ifndef _SYS_VDSO_H 2911406Sbde#define _SYS_VDSO_H 3011406Sbde 3111406Sbde#include <sys/types.h> 3211406Sbde#include <machine/vdso.h> 3311406Sbde 3411406Sbdestruct vdso_timehands { 3511406Sbde uint32_t th_algo; 3611406Sbde uint32_t th_gen; 3711406Sbde uint64_t th_scale; 3850476Speter uint32_t th_offset_count; 3911406Sbde uint32_t th_counter_mask; 40129614Sbde struct bintime th_offset; 41129619Sbde struct bintime th_boottime; 4279538Sru VDSO_TIMEHANDS_MD 4311406Sbde}; 4411406Sbde 4523354Sbdestruct vdso_timekeep { 4611406Sbde uint32_t tk_ver; 4799810Sbde uint32_t tk_enabled; 48129614Sbde uint32_t tk_current; 49101908Sru struct vdso_timehands tk_th[]; 50129614Sbde}; 51101908Sru 52129614Sbde#define VDSO_TK_CURRENT_BUSY 0xffffffff 5384877Syokota#define VDSO_TK_VER_1 0x1 5484877Syokota#define VDSO_TK_VER_CURR VDSO_TK_VER_1 5584877Syokota#define VDSO_TH_ALGO_1 0x1 5684877Syokota#define VDSO_TH_ALGO_2 0x2 5784877Syokota 58101908Sru#ifndef _KERNEL 5984877Syokota 60129614Sbdestruct timespec; 61101908Srustruct timeval; 62129614Sbdestruct timezone; 63101908Sru 64129614Sbdeint __vdso_clock_gettime(clockid_t clock_id, struct timespec *ts); 6599810Sbdeint __vdso_gettimeofday(struct timeval *tv, struct timezone *tz); 6684877Syokotaint __vdso_gettc(const struct vdso_timehands *vdso_th, u_int *tc); 6784877Syokotaint __vdso_gettimekeep(struct vdso_timekeep **tk); 6884877Syokota 6984877Syokota#endif 7084877Syokota 7184877Syokota#ifdef _KERNEL 7284877Syokota 7384877Syokotastruct timecounter; 74101908Sru 7584877Syokotastruct vdso_sv_tk { 76129614Sbde int sv_timekeep_off; 77129614Sbde int sv_timekeep_curr; 78129617Sbde uint32_t sv_timekeep_gen; 79129614Sbde}; 80129614Sbde 81129614Sbdevoid timekeep_push_vdso(void); 82129614Sbde 83129614Sbdeuint32_t tc_fill_vdso_timehands(struct vdso_timehands *vdso_th); 84129614Sbde 85129614Sbde/* 8611406Sbde * The cpu_fill_vdso_timehands() function should fill MD-part of the 87101908Sru * struct vdso_timehands, which is both machine- and 8823354Sbde * timecounter-depended. The return value should be 1 if fast 8923354Sbde * userspace timecounter is enabled by hardware, and 0 otherwise. The 9023354Sbde * global sysctl enable override is handled by machine-independed code 9123354Sbde * after cpu_fill_vdso_timehands() call is made. 9223354Sbde */ 9322148Smppuint32_t cpu_fill_vdso_timehands(struct vdso_timehands *vdso_th, 9411406Sbde struct timecounter *tc); 9511406Sbde 9668962Srustruct vdso_sv_tk *alloc_sv_tk(void); 9723354Sbde 9811406Sbde#define VDSO_TH_NUM 4 9911406Sbde 10011406Sbde#ifdef COMPAT_FREEBSD32 10111406Sbdestruct bintime32 { 10211406Sbde uint32_t sec; 10311406Sbde uint32_t frac[2]; 10423354Sbde}; 10523354Sbde 10611406Sbdestruct vdso_timehands32 { 10711406Sbde uint32_t th_algo; 10811406Sbde uint32_t th_gen; 10911406Sbde uint32_t th_scale[2]; 11011406Sbde uint32_t th_offset_count; 11111406Sbde uint32_t th_counter_mask; 11211406Sbde struct bintime32 th_offset; 11311406Sbde struct bintime32 th_boottime; 11411406Sbde VDSO_TIMEHANDS_MD32 11511406Sbde}; 11611406Sbde 11711406Sbdestruct vdso_timekeep32 { 11811406Sbde uint32_t tk_ver; 11911406Sbde uint32_t tk_enabled; 12011406Sbde uint32_t tk_current; 12111406Sbde struct vdso_timehands32 tk_th[]; 12211406Sbde}; 12368962Sru 12411406Sbdeuint32_t tc_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32); 12511406Sbdeuint32_t cpu_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32, 12611406Sbde struct timecounter *tc); 12711406Sbdestruct vdso_sv_tk *alloc_sv_tk_compat32(void); 12811406Sbde 12911406Sbde#endif 13011406Sbde#endif 13111406Sbde 13211406Sbde#endif 13311406Sbde