~ubuntu-branches/ubuntu/oneiric/oss4/oneiric-proposed

« back to all changes in this revision

Viewing changes to kernel/framework/midi/oss_default_timer.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-06-16 20:37:48 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110616203748-jbrxik6ql33z54co
Tags: 4.2-build2004-1ubuntu1
* Merge from Debian unstable.
  - Supports our current kernel (LP: #746048)
  Remaining changes:
  - debian/oss4-dkms.dkms.in: s/source/build/ in Kernel headers paths.
* ld-as-needed.patch: Re-order CC arguments to enable building with ld
  --as-needed (LP: #770972)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Purpose: Default MIDI timer (using system clock)
 
3
 */
 
4
/*
 
5
 *
 
6
 * This file is part of Open Sound System.
 
7
 *
 
8
 * Copyright (C) 4Front Technologies 1996-2008.
 
9
 *
 
10
 * This this source file is released under GPL v2 license (no other versions).
 
11
 * See the COPYING file included in the main directory of this source
 
12
 * distribution for the license terms and conditions.
 
13
 *
 
14
 */
 
15
 
 
16
#include "oss_config.h"
 
17
#include "midi_core.h"
 
18
 
 
19
typedef struct
 
20
{
 
21
  unsigned long long start_time;
 
22
  timeout_id_t timeout_id;
 
23
  oss_midi_wait_callback_t timer_callback;
 
24
  void *arg;
 
25
} deftmr_timerc_t;
 
26
 
 
27
static unsigned long long tick_scale = 1;
 
28
 
 
29
static int
 
30
deftmr_create_instance (int timer_dev, int driver_dev)
 
31
{
 
32
  deftmr_timerc_t *timerc;
 
33
 
 
34
  if ((timerc = KERNEL_MALLOC (sizeof (*timerc))) == NULL)
 
35
    return OSS_ENOMEM;
 
36
 
 
37
  memset (timerc, 0, sizeof (*timerc));
 
38
 
 
39
  oss_timer_devs[timer_dev]->timerc = timerc;
 
40
 
 
41
  return 0;
 
42
}
 
43
 
 
44
static void
 
45
deftmr_free_instance (int timer_dev, int driver_dev)
 
46
{
 
47
  deftmr_timerc_t *timerc;
 
48
 
 
49
  timerc = oss_timer_devs[timer_dev]->timerc;
 
50
  untimeout (timerc->timeout_id);
 
51
 
 
52
  if (timerc != NULL)
 
53
    KERNEL_FREE (timerc);
 
54
  oss_timer_devs[timer_dev]->timerc = NULL;
 
55
}
 
56
 
 
57
static int
 
58
deftmr_attach_client (int timer_dev, int mididev)
 
59
{
 
60
  return 0;
 
61
}
 
62
 
 
63
static void
 
64
deftmr_detach_client (int timer_dev, int mididev)
 
65
{
 
66
}
 
67
 
 
68
static int
 
69
deftmr_ioctl (int timer_dev, unsigned int cmd, ioctl_arg arg)
 
70
{
 
71
  return OSS_EINVAL;
 
72
}
 
73
 
 
74
static int
 
75
deftmr_set_source (int timer_dev, int source)
 
76
{
 
77
  return source;
 
78
}
 
79
 
 
80
static int
 
81
deftmr_set_tempo (int timer_dev, int tempo)
 
82
{
 
83
  return tempo;
 
84
}
 
85
 
 
86
static int
 
87
deftmr_set_timebase (int timer_dev, int timebase)
 
88
{
 
89
  return timebase;
 
90
}
 
91
static int
 
92
deftmr_start (int timer_dev, oss_uint64_t tick)
 
93
{
 
94
  deftmr_timerc_t *timerc;
 
95
 
 
96
  timerc = oss_timer_devs[timer_dev]->timerc;
 
97
 
 
98
  if (timerc == NULL)
 
99
    {
 
100
      cmn_err (CE_WARN, "deftmr_start: timerc==NULL\n");
 
101
      return OSS_EIO;
 
102
    }
 
103
 
 
104
  timerc->start_time = GET_JIFFIES ();
 
105
  return 0;
 
106
}
 
107
 
 
108
static int
 
109
deftmr_stop (int timer_dev)
 
110
{
 
111
  deftmr_timerc_t *timerc;
 
112
 
 
113
  timerc = oss_timer_devs[timer_dev]->timerc;
 
114
  untimeout (timerc->timeout_id);
 
115
 
 
116
  return 0;
 
117
}
 
118
 
 
119
static int
 
120
deftmr_cont (int timer_dev)
 
121
{
 
122
  return 0;
 
123
}
 
124
 
 
125
static int
 
126
deftmr_wait (int timer_dev, unsigned long long time,
 
127
             oss_midi_wait_callback_t callback, void *arg)
 
128
{
 
129
  deftmr_timerc_t *timerc;
 
130
  unsigned long long t;
 
131
 
 
132
  timerc = oss_timer_devs[timer_dev]->timerc;
 
133
  untimeout (timerc->timeout_id);
 
134
 
 
135
  t = ((oss_uint64_t) time + (tick_scale / 2)) / tick_scale;
 
136
 
 
137
  t += timerc->start_time;
 
138
 
 
139
  t -= GET_JIFFIES ();
 
140
 
 
141
  if (t < 0)
 
142
    {
 
143
      return 1;
 
144
    }
 
145
 
 
146
  timerc->timeout_id = timeout (callback, arg, t);
 
147
 
 
148
  return 0;
 
149
}
 
150
 
 
151
static unsigned long long
 
152
deftmr_get_current_time (int timer_dev)
 
153
{
 
154
  unsigned long long t;
 
155
  deftmr_timerc_t *timerc;
 
156
 
 
157
  timerc = oss_timer_devs[timer_dev]->timerc;
 
158
  /*
 
159
   * Compute time in system ticks since start of the timer
 
160
   */
 
161
  t = GET_JIFFIES ();
 
162
  if (t < timerc->start_time)
 
163
    return 0;
 
164
  t -= timerc->start_time;
 
165
 
 
166
  return t * tick_scale;        /* In microseconds */
 
167
}
 
168
 
 
169
oss_timer_driver_t default_midi_driver = {
 
170
  deftmr_create_instance,
 
171
  deftmr_free_instance,
 
172
  deftmr_attach_client,
 
173
  deftmr_detach_client,
 
174
  deftmr_ioctl,
 
175
  deftmr_wait,
 
176
  deftmr_get_current_time,
 
177
  deftmr_set_source,
 
178
  deftmr_set_tempo,
 
179
  deftmr_set_timebase,
 
180
  deftmr_start,
 
181
  deftmr_stop,
 
182
  deftmr_cont
 
183
};
 
184
 
 
185
void
 
186
attach_oss_default_timer (oss_device_t * osdev)
 
187
{
 
188
  int timer_dev;
 
189
 
 
190
  tick_scale = 1000000 / OSS_HZ;
 
191
  if ((timer_dev = oss_install_timer (OSS_TIMER_DRIVER_VERSION, "System timer", &default_midi_driver, sizeof (oss_timer_driver_t), 0,   /* Flags */
 
192
                                      16,       /* max_instances */
 
193
                                      1000000 / OSS_HZ, /* Resolution */
 
194
                                      NULL, osdev)) < 0)
 
195
    {
 
196
      cmn_err (CE_WARN, "Failed to install default MIDI timer\n");
 
197
      return;
 
198
    }
 
199
}
 
200
 
 
201
void
 
202
detach_oss_default_timer ()
 
203
{
 
204
}