usb_drv: Add hrtimer support (ref #758)

This commit is contained in:
Sebastian Sumpf 2014-06-12 14:14:12 +02:00 committed by Norman Feske
parent 6f58cdffb6
commit 3961a3e2a1
4 changed files with 102 additions and 54 deletions

View File

@ -175,12 +175,10 @@ void add_device_randomness(const void *buf, unsigned int size) { TRACE; }
#define KTIME_RET ({TRACE; ktime_t t = { 0 }; return t;})
ktime_t ktime_add(const ktime_t lhs, const ktime_t rhs) { KTIME_RET; }
ktime_t ktime_add_ns(const ktime_t kt, u64 nsec) { KTIME_RET; }
ktime_t ktime_get(void) { KTIME_RET; }
ktime_t ktime_get_monotonic_offset(void) { KTIME_RET; }
ktime_t ktime_set(const long secs, const unsigned long nsecs) { KTIME_RET; }
ktime_t ktime_sub(const ktime_t lhs, const ktime_t rhs) { KTIME_RET; }
ktime_t ktime_get_real(void) { TRACE; ktime_t ret; return ret; }
struct timeval ktime_to_timeval(const ktime_t kt) { TRACE; struct timeval ret; return ret; }
@ -194,16 +192,6 @@ s64 ktime_us_delta(const ktime_t later, const ktime_t earlier) { TRACE; return 0
unsigned long round_jiffies(unsigned long j) { TRACE; return 1; }
void set_timer_slack(struct timer_list *time, int slack_hz) { TRACE; }
/*********************
** linux/hrtimer.h **
*********************/
ktime_t ktime_get_real(void) { TRACE; ktime_t ret; return ret; }
int hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
unsigned long delta_ns, const enum hrtimer_mode mode) { TRACE; return 0; }
void hrtimer_init(struct hrtimer *timer, clockid_t clock_id, enum hrtimer_mode mode) { TRACE; }
int hrtimer_cancel(struct hrtimer *timer) { TRACE; return 0; }
/***********************
** linux/workquque.h **

View File

@ -712,7 +712,19 @@ long find_next_zero_bit_le(const void *addr,
int ffs(int x);
int fls(int x);
#define for_each_set_bit(bit, addr, size) for ((bit) = 0; !bit; bit++, dev_err(0, "for_each_set_bit should not be called\n"))
static inline unsigned find_next_bit(unsigned long where, unsigned size, unsigned bit)
{
for (; bit < size; bit++)
if ((1 << bit) & where)
return bit;
return size;
}
#define for_each_set_bit(bit, addr, size) \
for ((e) = find_next_bit((*addr), (size), 0); \
(e) < (size); \
(e) = find_next_bit((*addr),(size), (e) + 1))
/*****************************************
@ -945,6 +957,32 @@ long time_after_eq(long a, long b);
long time_before(long a, long b);
/******************
** linux/time.h **
******************/
struct timespec {
__kernel_time_t tv_sec;
long tv_nsec;
};
struct timeval { };
struct timespec current_kernel_time(void);
void do_gettimeofday(struct timeval *tv);
#define CURRENT_TIME (current_kernel_time())
enum {
CLOCK_REALTIME = 0,
CLOCK_MONOTONIC = 1,
NSEC_PER_USEC = 1000L,
NSEC_PER_MSEC = 1000000L,
NSEC_PER_SEC = 1000 * NSEC_PER_MSEC,
};
/*******************
** linux/ktime.h **
*******************/
@ -959,16 +997,30 @@ static inline ktime_t ktime_add_us(const ktime_t kt, const u64 usec)
{
return ktime_add_ns(kt, usec * 1000);
}
static inline ktime_t ktime_get(void)
{
return (ktime_t){ .tv64 = (s64)jiffies * HZ * NSEC_PER_MSEC /* ns */ };
}
static inline ktime_t ktime_set(const long sec, const unsigned long nsec)
{
return (ktime_t){ .tv64 = (s64)sec * NSEC_PER_SEC + nsec /* ns */ };
}
static inline ktime_t ktime_add(const ktime_t a, const ktime_t b)
{
return (ktime_t){ .tv64 = a.tv64 + b.tv64 /* ns */ };
}
s64 ktime_us_delta(const ktime_t later, const ktime_t earlier);
struct timeval ktime_to_timeval(const ktime_t);
ktime_t ktime_get_real(void);
ktime_t ktime_get(void);
ktime_t ktime_sub(const ktime_t, const ktime_t);
ktime_t ktime_get_monotonic_offset(void);
ktime_t ktime_add(const ktime_t, const ktime_t);
ktime_t ktime_set(const long, const unsigned long);
/*******************
** linux/timer.h **
@ -1010,6 +1062,8 @@ enum hrtimer_restart { HRTIMER_NORESTART = 0 };
struct hrtimer
{
enum hrtimer_restart (*function)(struct hrtimer *);
struct hrtimer *data;
void *timer;
};
int hrtimer_start_range_ns(struct hrtimer *, ktime_t,
@ -1177,31 +1231,6 @@ void __wait_event(void);
})
/******************
** linux/time.h **
******************/
struct timespec {
__kernel_time_t tv_sec;
long tv_nsec;
};
struct timeval { };
struct timespec current_kernel_time(void);
void do_gettimeofday(struct timeval *tv);
#define CURRENT_TIME (current_kernel_time())
enum {
CLOCK_REALTIME = 0,
CLOCK_MONOTONIC = 1,
NSEC_PER_USEC = 1000L,
NSEC_PER_MSEC = 1000000L,
};
/*******************
** linux/sched.h **
*******************/

View File

@ -950,13 +950,17 @@ unsigned long msecs_to_jiffies(const unsigned int m) { return m / JIFFIES_TICK_M
long time_after_eq(long a, long b) { return (a - b) >= 0; }
long time_after(long a, long b) { return (b - a) < 0; }
/*********
** DMA **
*********/
struct dma_pool
{
size_t size;
int align;
};
struct dma_pool *dma_pool_create(const char *name, struct device *d, size_t size,
size_t align, size_t alloc)
{

View File

@ -27,11 +27,12 @@ static Signal_helper *_signal = 0;
/**
* Signal context for time-outs
*/
template<typename CLASS>
class Timer_context
{
private:
timer_list *_timer; /* Linux timer */
CLASS *_timer; /* Linux timer */
dde_kit_timer *_dde_timer; /* DDE kit timer */
Genode::Signal_rpc_member<Timer_context> _dispatcher;
@ -40,7 +41,7 @@ class Timer_context
public:
Timer_context(timer_list *timer)
Timer_context(CLASS *timer)
: _timer(timer), _dde_timer(0),
_dispatcher(_signal->ep(), *this, &Timer_context::_handle) {}
@ -54,6 +55,7 @@ class Timer_context
}
char const *debug() { return "Timer_context"; }
/**
* Return true if timer is pending
*/
@ -70,8 +72,8 @@ class Timer_context
/**
* Convert 'timer_list' to 'Timer_conext'
*/
static Timer_context *to_ctx(timer_list const *timer) {
return static_cast<Timer_context *>(timer->timer); }
static Timer_context *to_ctx(CLASS const *timer) {
return static_cast<Timer_context<CLASS> *>(timer->timer); }
void remove()
{
@ -80,8 +82,6 @@ class Timer_context
_dde_timer = 0;
}
timer_list *l() { return _timer; }
};
@ -90,7 +90,7 @@ class Timer_context
*/
static void handler(void *timer)
{
Timer_context *t = static_cast<Timer_context *>(timer);
Timer_context<timer_list> *t = static_cast<Timer_context<timer_list> *>(timer);
/* set context and submit */
_signal->sender().context(t->cap());
@ -107,14 +107,14 @@ void Timer::init(Server::Entrypoint &ep) {
*******************/
void init_timer(struct timer_list *timer) {
timer->timer = (void *) new (Genode::env()->heap()) Timer_context(timer); }
timer->timer = (void *) new (Genode::env()->heap()) Timer_context<timer_list>(timer); }
int mod_timer(struct timer_list *timer, unsigned long expires)
{
dde_kit_log(DEBUG_TIMER, "Timer: %p j: %lu ex: %lu func %p",
timer, jiffies, expires, timer->function);
Timer_context::to_ctx(timer)->schedule(expires);
Timer_context<timer_list>::to_ctx(timer)->schedule(expires);
return 0;
}
@ -130,7 +130,7 @@ void setup_timer(struct timer_list *timer,void (*function)(unsigned long),
int timer_pending(const struct timer_list * timer)
{
bool pending = Timer_context::to_ctx(timer)->pending();
bool pending = Timer_context<timer_list>::to_ctx(timer)->pending();
dde_kit_log(DEBUG_TIMER, "Pending %p %u", timer, pending);
return pending;
}
@ -139,7 +139,34 @@ int timer_pending(const struct timer_list * timer)
int del_timer(struct timer_list *timer)
{
dde_kit_log(DEBUG_TIMER, "Delete timer %p", timer);
Timer_context::to_ctx(timer)->remove();
Timer_context<timer_list>::to_ctx(timer)->remove();
return 0;
}
/*********************
** linux/hrtimer.h **
*********************/
void hrtimer_init(struct hrtimer *timer, clockid_t clock_id, enum hrtimer_mode mode)
{
timer->timer = (void *) new (Genode::env()->heap()) Timer_context<hrtimer>(timer);
timer->data = timer;
}
int hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
unsigned long delta_ns, const enum hrtimer_mode mode)
{
unsigned long expires = tim.tv64 / (NSEC_PER_MSEC * DDE_KIT_HZ);
dde_kit_log(DEBUG_TIMER, "HR: e: %lu j %lu", jiffies, expires);
Timer_context<hrtimer>::to_ctx(timer)->schedule(expires);
return 0;
}
int hrtimer_cancel(struct hrtimer *timer)
{
Timer_context<hrtimer>::to_ctx(timer)->remove();
return 0;
}