forked from minoca/os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spbhost.h
358 lines (226 loc) · 6.95 KB
/
spbhost.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*++
Copyright (c) 2015 Minoca Corp.
This file is licensed under the terms of the GNU General Public License
version 3. Alternative licensing terms are available. Contact
[email protected] for details. See the LICENSE file at the root of this
project for complete licensing information.
Module Name:
spbhost.h
Abstract:
This header contains definitions for creating and managing Simple
Peripheral Bus controllers.
Author:
Evan Green 14-Aug-2015
--*/
//
// ------------------------------------------------------------------- Includes
//
#include <minoca/spb/spb.h>
//
// ---------------------------------------------------------------- Definitions
//
#ifndef SPB_API
#define SPB_API __DLLIMPORT
#endif
#define SPB_CONTROLLER_INFORMATION_VERSION 1
//
// ------------------------------------------------------ Data Type Definitions
//
typedef struct _SPB_CONTROLLER SPB_CONTROLLER, *PSPB_CONTROLLER;
typedef
KSTATUS
(*PSPB_HOST_CONFIGURE) (
PVOID Context,
PRESOURCE_SPB_DATA Configuration
);
/*++
Routine Description:
This routine configures the given Simple Peripheral Bus controller.
Arguments:
Context - Supplies the host controller context.
Configuration - Supplies a pointer to the new configuration to set.
Return Value:
Status code.
--*/
typedef
KSTATUS
(*PSPB_HOST_SUBMIT_TRANSFER) (
PVOID Context,
PSPB_TRANSFER Transfer
);
/*++
Routine Description:
This routine is called to execute a single transfer on the Simple
Peripheral Bus. The host controller is responsible for implementing the
delay set in the transfer.
Arguments:
Context - Supplies the host controller context.
Transfer - Supplies a pointer to the transfer to begin executing. The
controller can return immediately, and should call
SpbProcessCompletedTransfer when the transfer completes.
Return Value:
Status code indicating whether or not the transfer was successfully
started.
--*/
typedef
VOID
(*PSPB_HOST_LOCK_BUS) (
PVOID Context,
PRESOURCE_SPB_DATA Configuration
);
/*++
Routine Description:
This routine is called when the bus is being locked for a particular
transfer set or directly via the interface. The software synchronization
portion of locking the bus is handled by the SPB library, this routine
only needs to do hardware-specific actions (like selecting or deselecting
device lines).
Arguments:
Context - Supplies the host controller context.
Configuration - Supplies a pointer to the configuration of the handle that
locked this bus. The configure bus function will still be called, this
is only passed for reference if bus-specific actions need to be
performed (like selecting or deselecting the device).
Return Value:
None.
--*/
typedef
VOID
(*PSPB_HOST_UNLOCK_BUS) (
PVOID Context
);
/*++
Routine Description:
This routine is called when the bus is being unlocked.
Arguments:
Context - Supplies the host controller context.
Return Value:
None.
--*/
/*++
Structure Description:
This structure stores the set of Simple Peripheral Bus controller functions
called by the SPB library.
Members:
Configure - Stores a pointer to a function used to set the current bus
parameters.
SubmitTransfer - Stores a pointer to a function used to begin a new
transfer.
LockBus - Stores an optional pointer to a function that is called when the
bus is being locked.
UnlockBus - Stores an optional pointer to a function that is called when
the bus is being unlocked.
--*/
typedef struct _SPB_FUNCTION_TABLE {
PSPB_HOST_CONFIGURE Configure;
PSPB_HOST_SUBMIT_TRANSFER SubmitTransfer;
PSPB_HOST_LOCK_BUS LockBus;
PSPB_HOST_UNLOCK_BUS UnlockBus;
} SPB_FUNCTION_TABLE, *PSPB_FUNCTION_TABLE;
/*++
Structure Description:
This structure defines the information provided to the SPB library by a
Simple Peripheral Bus controller.
Members:
Version - Stores the value SPB_CONTROLLER_INFORMATION_VERSION, used to
enable future expansion of this structure.
Context - Stores an opaque context pointer that is passed to the SPB
controller functions.
Device - Stores a pointer to the OS device associated with this controller.
MaxFrequency - Stores the maximum bus clock frequency.
BusType - Stores the bus type for this controller.
Features - Stores a bitfield of features about this controller. See
SPB_FEATURE_* definitions.
FunctionTable - Stores the table of functions the library uses to call back
into the controller.
--*/
typedef struct _SPB_CONTROLLER_INFORMATION {
ULONG Version;
PVOID Context;
PDEVICE Device;
ULONG MaxFrequency;
RESOURCE_SPB_BUS_TYPE BusType;
ULONG Features;
SPB_FUNCTION_TABLE FunctionTable;
} SPB_CONTROLLER_INFORMATION, *PSPB_CONTROLLER_INFORMATION;
//
// -------------------------------------------------------------------- Globals
//
//
// -------------------------------------------------------- Function Prototypes
//
SPB_API
KSTATUS
SpbCreateController (
PSPB_CONTROLLER_INFORMATION Registration,
PSPB_CONTROLLER *Controller
);
/*++
Routine Description:
This routine creates a new Simple Peripheral Bus controller.
Arguments:
Registration - Supplies a pointer to the host registration information.
Controller - Supplies a pointer where a pointer to the new controller will
be returned on success.
Return Value:
Status code.
--*/
SPB_API
VOID
SpbDestroyController (
PSPB_CONTROLLER Controller
);
/*++
Routine Description:
This routine destroys a Simple Peripheral Bus controller.
Arguments:
Controller - Supplies a pointer to the controller to tear down.
Return Value:
None.
--*/
SPB_API
KSTATUS
SpbStartController (
PSPB_CONTROLLER Controller
);
/*++
Routine Description:
This routine starts a Simple Peripheral Bus controller.
Arguments:
Controller - Supplies a pointer to the controller.
Return Value:
Status code.
--*/
SPB_API
VOID
SpbStopController (
PSPB_CONTROLLER Controller
);
/*++
Routine Description:
This routine stops a Simple Peripheral Bus controller.
Arguments:
Controller - Supplies a pointer to the controller.
Return Value:
None.
--*/
SPB_API
PSPB_TRANSFER
SpbTransferCompletion (
PSPB_CONTROLLER Controller,
PSPB_TRANSFER Transfer,
KSTATUS Status
);
/*++
Routine Description:
This routine is called by an SPB host controller when a transfer has
completed.
Arguments:
Controller - Supplies a pointer to the controller.
Transfer - Supplies a pointer to the transfer that completed.
Status - Supplies the status code the transfer completed with.
Return Value:
Returns a new transfer to begin executing if there are additional transfers
in this set and the previous transfer completed successfully.
NULL if no new transfers should be started at this time.
--*/