timeet.h revision 247463
1209371Smav/*- 2247463Smav * Copyright (c) 2010-2013 Alexander Motin <mav@FreeBSD.org> 3209371Smav * All rights reserved. 4209371Smav * 5209371Smav * Redistribution and use in source and binary forms, with or without 6209371Smav * modification, are permitted provided that the following conditions 7209371Smav * are met: 8209371Smav * 1. Redistributions of source code must retain the above copyright 9209371Smav * notice, this list of conditions and the following disclaimer, 10209371Smav * without modification, immediately at the beginning of the file. 11209371Smav * 2. Redistributions in binary form must reproduce the above copyright 12209371Smav * notice, this list of conditions and the following disclaimer in the 13209371Smav * documentation and/or other materials provided with the distribution. 14209371Smav * 15209371Smav * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16209371Smav * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17209371Smav * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18209371Smav * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19209371Smav * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20209371Smav * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21209371Smav * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22209371Smav * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23209371Smav * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24209371Smav * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25209371Smav * 26209371Smav * $FreeBSD: head/sys/sys/timeet.h 247463 2013-02-28 13:46:03Z mav $ 27209371Smav */ 28209371Smav 29209371Smav#ifndef _SYS_TIMEEC_H_ 30209371Smav#define _SYS_TIMEEC_H_ 31209371Smav 32209371Smav#ifndef _KERNEL 33209371Smav#error "no user-serviceable parts inside" 34209371Smav#endif 35209371Smav 36209371Smav#include <sys/lock.h> 37209371Smav#include <sys/mutex.h> 38209371Smav#include <sys/queue.h> 39209371Smav#include <sys/time.h> 40209371Smav 41209371Smav/* 42209371Smav * `struct eventtimer' is the interface between the hardware which implements 43209371Smav * a event timer and the MI code which uses this to receive time events. 44209371Smav */ 45209371Smav 46209371Smavstruct eventtimer; 47209371Smavtypedef int et_start_t(struct eventtimer *et, 48247463Smav sbintime_t first, sbintime_t period); 49209371Smavtypedef int et_stop_t(struct eventtimer *et); 50209371Smavtypedef void et_event_cb_t(struct eventtimer *et, void *arg); 51209371Smavtypedef int et_deregister_cb_t(struct eventtimer *et, void *arg); 52209371Smav 53209371Smavstruct eventtimer { 54209371Smav SLIST_ENTRY(eventtimer) et_all; 55209371Smav /* Pointer to the next event timer. */ 56209371Smav char *et_name; 57209371Smav /* Name of the event timer. */ 58209371Smav int et_flags; 59209371Smav /* Set of capabilities flags: */ 60209371Smav#define ET_FLAGS_PERIODIC 1 61209371Smav#define ET_FLAGS_ONESHOT 2 62209371Smav#define ET_FLAGS_PERCPU 4 63209371Smav#define ET_FLAGS_C3STOP 8 64210290Smav#define ET_FLAGS_POW2DIV 16 65209371Smav int et_quality; 66209371Smav /* 67209371Smav * Used to determine if this timecounter is better than 68209371Smav * another timecounter. Higher means better. 69209371Smav */ 70209371Smav int et_active; 71209371Smav u_int64_t et_frequency; 72209371Smav /* Base frequency in Hz. */ 73247463Smav sbintime_t et_min_period; 74247463Smav sbintime_t et_max_period; 75209371Smav et_start_t *et_start; 76209371Smav et_stop_t *et_stop; 77209371Smav et_event_cb_t *et_event_cb; 78209371Smav et_deregister_cb_t *et_deregister_cb; 79209371Smav void *et_arg; 80209371Smav void *et_priv; 81209371Smav struct sysctl_oid *et_sysctl; 82209371Smav /* Pointer to the event timer's private parts. */ 83209371Smav}; 84209371Smav 85209371Smavextern struct mtx et_eventtimers_mtx; 86212541Smav#define ET_LOCK() mtx_lock(&et_eventtimers_mtx) 87212541Smav#define ET_UNLOCK() mtx_unlock(&et_eventtimers_mtx) 88209371Smav 89209371Smav/* Driver API */ 90209371Smavint et_register(struct eventtimer *et); 91209371Smavint et_deregister(struct eventtimer *et); 92209371Smav/* Consumer API */ 93209371Smavstruct eventtimer *et_find(const char *name, int check, int want); 94209371Smavint et_init(struct eventtimer *et, et_event_cb_t *event, 95209371Smav et_deregister_cb_t *deregister, void *arg); 96247463Smavint et_start(struct eventtimer *et, sbintime_t first, sbintime_t period); 97209371Smavint et_stop(struct eventtimer *et); 98209371Smavint et_ban(struct eventtimer *et); 99209371Smavint et_free(struct eventtimer *et); 100209371Smav 101209371Smav#ifdef SYSCTL_DECL 102209371SmavSYSCTL_DECL(_kern_eventtimer); 103209371Smav#endif 104209371Smav#endif /* !_SYS_TIMETC_H_ */ 105209371Smav 106