View | Details | Raw Unified | Return to bug 251390
Collapse All | Expand All

(-)drvGPIOIITK/BB-GPIOIITK.dts (+43 lines)
Line 0 Link Here
1
/dts-v1/;
2
/plugin/;
3
4
#include <dt-bindings/gpio/gpio.h>
5
#include <dt-bindings/pinctrl/am33xx.h>
6
#include <dt-bindings/board/am335x-bbw-bbb-base.h>
7
8
/ {
9
        compatible =  "ti,am335x-bone-black";
10
11
	/* identification */
12
	part-number = "BB-GPIOIITK";
13
	version = "00A0";
14
15
	fragment@0 {
16
		target = <&am33xx_pinmux>;
17
		__overlay__ {
18
			input_pins: pinmux-input-pins {
19
				pinctrl-single,pins = <
20
				/* P8_08 (T7) gpio2_3 */
21
				AM33XX_IOPAD(0x0894, PIN_INPUT | MUX_MODE7)
22
23
				/* P8_10 (U6) gpio2_4 */
24
				AM33XX_IOPAD(0x0898, PIN_INPUT | MUX_MODE7)
25
				>;
26
			};
27
		};
28
	};
29
30
	fragment@1 {
31
		target-path="/";
32
		__overlay__ {
33
			gpio_int_test {
34
				pinctrl-names = "default";
35
				pinctrl-0 = <&input_pins>;
36
				compatible = "gpioiitk";
37
38
				input-gpios =	<&gpio2 3 GPIO_ACTIVE_HIGH>,
39
						<&gpio2 4 GPIO_ACTIVE_HIGH>;
40
			};
41
		};
42
	};
43
};
(-)drvGPIOIITK/Makefile (+4 lines)
Line 0 Link Here
1
KMOD=	gpioiitk
2
SRCS=	gpioiitk.c
3
4
.include <bsd.kmod.mk>
(-)drvGPIOIITK/bus_if.h (+1255 lines)
Line 0 Link Here
1
/*
2
 * This file is @generated automatically.
3
 * Do not modify anything in here by hand.
4
 *
5
 * Created from source file
6
 *   /usr/src/sys/kern/bus_if.m
7
 * with
8
 *   makeobjops.awk
9
 *
10
 * See the source file for legal information
11
 */
12
13
/**
14
 * @defgroup BUS bus - KObj methods for drivers of devices with children
15
 * @brief A set of methods required device drivers that support
16
 * child devices.
17
 * @{
18
 */
19
20
#ifndef _bus_if_h_
21
#define _bus_if_h_
22
23
/** @brief Unique descriptor for the BUS_PRINT_CHILD() method */
24
extern struct kobjop_desc bus_print_child_desc;
25
/** @brief A function implementing the BUS_PRINT_CHILD() method */
26
typedef int bus_print_child_t(device_t _dev, device_t _child);
27
/**
28
 * @brief Print a description of a child device
29
 *
30
 * This is called from system code which prints out a description of a
31
 * device. It should describe the attachment that the child has with
32
 * the parent. For instance the TurboLaser bus prints which node the
33
 * device is attached to. See bus_generic_print_child() for more
34
 * information.
35
 *
36
 * @param _dev		the device whose child is being printed
37
 * @param _child	the child device to describe
38
 *
39
 * @returns		the number of characters output.
40
 */
41
42
static __inline int BUS_PRINT_CHILD(device_t _dev, device_t _child)
43
{
44
	kobjop_t _m;
45
	int rc;
46
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_print_child);
47
	rc = ((bus_print_child_t *) _m)(_dev, _child);
48
	return (rc);
49
}
50
51
/** @brief Unique descriptor for the BUS_PROBE_NOMATCH() method */
52
extern struct kobjop_desc bus_probe_nomatch_desc;
53
/** @brief A function implementing the BUS_PROBE_NOMATCH() method */
54
typedef void bus_probe_nomatch_t(device_t _dev, device_t _child);
55
/**
56
 * @brief Print a notification about an unprobed child device.
57
 *
58
 * Called for each child device that did not succeed in probing for a
59
 * driver.
60
 *
61
 * @param _dev		the device whose child was being probed
62
 * @param _child	the child device which failed to probe
63
 */
64
65
static __inline void BUS_PROBE_NOMATCH(device_t _dev, device_t _child)
66
{
67
	kobjop_t _m;
68
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_probe_nomatch);
69
	((bus_probe_nomatch_t *) _m)(_dev, _child);
70
}
71
72
/** @brief Unique descriptor for the BUS_READ_IVAR() method */
73
extern struct kobjop_desc bus_read_ivar_desc;
74
/** @brief A function implementing the BUS_READ_IVAR() method */
75
typedef int bus_read_ivar_t(device_t _dev, device_t _child, int _index,
76
                            uintptr_t *_result);
77
/**
78
 * @brief Read the value of a bus-specific attribute of a device
79
 *
80
 * This method, along with BUS_WRITE_IVAR() manages a bus-specific set
81
 * of instance variables of a child device.  The intention is that
82
 * each different type of bus defines a set of appropriate instance
83
 * variables (such as ports and irqs for ISA bus etc.)
84
 *
85
 * This information could be given to the child device as a struct but
86
 * that makes it hard for a bus to add or remove variables without
87
 * forcing an edit and recompile for all drivers which may not be
88
 * possible for vendor supplied binary drivers.
89
 *
90
 * This method copies the value of an instance variable to the
91
 * location specified by @p *_result.
92
 *
93
 * @param _dev		the device whose child was being examined
94
 * @param _child	the child device whose instance variable is
95
 *			being read
96
 * @param _index	the instance variable to read
97
 * @param _result	a location to receive the instance variable
98
 *			value
99
 *
100
 * @retval 0		success
101
 * @retval ENOENT	no such instance variable is supported by @p
102
 *			_dev
103
 */
104
105
static __inline int BUS_READ_IVAR(device_t _dev, device_t _child, int _index,
106
                                  uintptr_t *_result)
107
{
108
	kobjop_t _m;
109
	int rc;
110
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_read_ivar);
111
	rc = ((bus_read_ivar_t *) _m)(_dev, _child, _index, _result);
112
	return (rc);
113
}
114
115
/** @brief Unique descriptor for the BUS_WRITE_IVAR() method */
116
extern struct kobjop_desc bus_write_ivar_desc;
117
/** @brief A function implementing the BUS_WRITE_IVAR() method */
118
typedef int bus_write_ivar_t(device_t _dev, device_t _child, int _indx,
119
                             uintptr_t _value);
120
/**
121
 * @brief Write the value of a bus-specific attribute of a device
122
 *
123
 * This method sets the value of an instance variable to @p _value.
124
 *
125
 * @param _dev		the device whose child was being updated
126
 * @param _child	the child device whose instance variable is
127
 *			being written
128
 * @param _index	the instance variable to write
129
 * @param _value	the value to write to that instance variable
130
 *
131
 * @retval 0		success
132
 * @retval ENOENT	no such instance variable is supported by @p
133
 *			_dev
134
 * @retval EINVAL	the instance variable was recognised but
135
 *			contains a read-only value
136
 */
137
138
static __inline int BUS_WRITE_IVAR(device_t _dev, device_t _child, int _indx,
139
                                   uintptr_t _value)
140
{
141
	kobjop_t _m;
142
	int rc;
143
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_write_ivar);
144
	rc = ((bus_write_ivar_t *) _m)(_dev, _child, _indx, _value);
145
	return (rc);
146
}
147
148
/** @brief Unique descriptor for the BUS_CHILD_DELETED() method */
149
extern struct kobjop_desc bus_child_deleted_desc;
150
/** @brief A function implementing the BUS_CHILD_DELETED() method */
151
typedef void bus_child_deleted_t(device_t _dev, device_t _child);
152
/**
153
 * @brief Notify a bus that a child was deleted
154
 *
155
 * Called at the beginning of device_delete_child() to allow the parent
156
 * to teardown any bus-specific state for the child.
157
 *
158
 * @param _dev		the device whose child is being deleted
159
 * @param _child	the child device which is being deleted
160
 */
161
162
static __inline void BUS_CHILD_DELETED(device_t _dev, device_t _child)
163
{
164
	kobjop_t _m;
165
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_child_deleted);
166
	((bus_child_deleted_t *) _m)(_dev, _child);
167
}
168
169
/** @brief Unique descriptor for the BUS_CHILD_DETACHED() method */
170
extern struct kobjop_desc bus_child_detached_desc;
171
/** @brief A function implementing the BUS_CHILD_DETACHED() method */
172
typedef void bus_child_detached_t(device_t _dev, device_t _child);
173
/**
174
 * @brief Notify a bus that a child was detached
175
 *
176
 * Called after the child's DEVICE_DETACH() method to allow the parent
177
 * to reclaim any resources allocated on behalf of the child.
178
 *
179
 * @param _dev		the device whose child changed state
180
 * @param _child	the child device which changed state
181
 */
182
183
static __inline void BUS_CHILD_DETACHED(device_t _dev, device_t _child)
184
{
185
	kobjop_t _m;
186
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_child_detached);
187
	((bus_child_detached_t *) _m)(_dev, _child);
188
}
189
190
/** @brief Unique descriptor for the BUS_DRIVER_ADDED() method */
191
extern struct kobjop_desc bus_driver_added_desc;
192
/** @brief A function implementing the BUS_DRIVER_ADDED() method */
193
typedef void bus_driver_added_t(device_t _dev, driver_t *_driver);
194
/**
195
 * @brief Notify a bus that a new driver was added
196
 *
197
 * Called when a new driver is added to the devclass which owns this
198
 * bus. The generic implementation of this method attempts to probe and
199
 * attach any un-matched children of the bus.
200
 *
201
 * @param _dev		the device whose devclass had a new driver
202
 *			added to it
203
 * @param _driver	the new driver which was added
204
 */
205
206
static __inline void BUS_DRIVER_ADDED(device_t _dev, driver_t *_driver)
207
{
208
	kobjop_t _m;
209
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_driver_added);
210
	((bus_driver_added_t *) _m)(_dev, _driver);
211
}
212
213
/** @brief Unique descriptor for the BUS_ADD_CHILD() method */
214
extern struct kobjop_desc bus_add_child_desc;
215
/** @brief A function implementing the BUS_ADD_CHILD() method */
216
typedef device_t bus_add_child_t(device_t _dev, u_int _order, const char *_name,
217
                                 int _unit);
218
/**
219
 * @brief Create a new child device
220
 *
221
 * For buses which use use drivers supporting DEVICE_IDENTIFY() to
222
 * enumerate their devices, this method is used to create new
223
 * device instances. The new device will be added after the last
224
 * existing child with the same order. Implementations of bus_add_child
225
 * call device_add_child_ordered to add the child and often add
226
 * a suitable ivar to the device specific to that bus.
227
 *
228
 * @param _dev		the bus device which will be the parent of the
229
 *			new child device
230
 * @param _order	a value which is used to partially sort the
231
 *			children of @p _dev - devices created using
232
 *			lower values of @p _order appear first in @p
233
 *			_dev's list of children
234
 * @param _name		devclass name for new device or @c NULL if not
235
 *			specified
236
 * @param _unit		unit number for new device or @c -1 if not
237
 *			specified
238
 */
239
240
static __inline device_t BUS_ADD_CHILD(device_t _dev, u_int _order,
241
                                       const char *_name, int _unit)
242
{
243
	kobjop_t _m;
244
	device_t rc;
245
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_add_child);
246
	rc = ((bus_add_child_t *) _m)(_dev, _order, _name, _unit);
247
	return (rc);
248
}
249
250
/** @brief Unique descriptor for the BUS_RESCAN() method */
251
extern struct kobjop_desc bus_rescan_desc;
252
/** @brief A function implementing the BUS_RESCAN() method */
253
typedef int bus_rescan_t(device_t _dev);
254
/**
255
 * @brief Rescan the bus
256
 *
257
 * This method is called by a parent bridge or devctl to trigger a bus
258
 * rescan.  The rescan should delete devices no longer present and
259
 * enumerate devices that have newly arrived.
260
 *
261
 * @param _dev		the bus device
262
 */
263
264
static __inline int BUS_RESCAN(device_t _dev)
265
{
266
	kobjop_t _m;
267
	int rc;
268
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_rescan);
269
	rc = ((bus_rescan_t *) _m)(_dev);
270
	return (rc);
271
}
272
273
/** @brief Unique descriptor for the BUS_ALLOC_RESOURCE() method */
274
extern struct kobjop_desc bus_alloc_resource_desc;
275
/** @brief A function implementing the BUS_ALLOC_RESOURCE() method */
276
typedef struct resource * bus_alloc_resource_t(device_t _dev, device_t _child,
277
                                               int _type, int *_rid,
278
                                               rman_res_t _start,
279
                                               rman_res_t _end,
280
                                               rman_res_t _count, u_int _flags);
281
/**
282
 * @brief Allocate a system resource
283
 *
284
 * This method is called by child devices of a bus to allocate resources.
285
 * The types are defined in <machine/resource.h>; the meaning of the
286
 * resource-ID field varies from bus to bus (but @p *rid == 0 is always
287
 * valid if the resource type is). If a resource was allocated and the
288
 * caller did not use the RF_ACTIVE to specify that it should be
289
 * activated immediately, the caller is responsible for calling
290
 * BUS_ACTIVATE_RESOURCE() when it actually uses the resource.
291
 *
292
 * @param _dev		the parent device of @p _child
293
 * @param _child	the device which is requesting an allocation
294
 * @param _type		the type of resource to allocate
295
 * @param _rid		a pointer to the resource identifier
296
 * @param _start	hint at the start of the resource range - pass
297
 *			@c 0 for any start address
298
 * @param _end		hint at the end of the resource range - pass
299
 *			@c ~0 for any end address
300
 * @param _count	hint at the size of range required - pass @c 1
301
 *			for any size
302
 * @param _flags	any extra flags to control the resource
303
 *			allocation - see @c RF_XXX flags in
304
 *			<sys/rman.h> for details
305
 *
306
 * @returns		the resource which was allocated or @c NULL if no
307
 *			resource could be allocated
308
 */
309
310
static __inline struct resource * BUS_ALLOC_RESOURCE(device_t _dev,
311
                                                     device_t _child, int _type,
312
                                                     int *_rid,
313
                                                     rman_res_t _start,
314
                                                     rman_res_t _end,
315
                                                     rman_res_t _count,
316
                                                     u_int _flags)
317
{
318
	kobjop_t _m;
319
	struct resource * rc;
320
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_alloc_resource);
321
	rc = ((bus_alloc_resource_t *) _m)(_dev, _child, _type, _rid, _start, _end, _count, _flags);
322
	return (rc);
323
}
324
325
/** @brief Unique descriptor for the BUS_ACTIVATE_RESOURCE() method */
326
extern struct kobjop_desc bus_activate_resource_desc;
327
/** @brief A function implementing the BUS_ACTIVATE_RESOURCE() method */
328
typedef int bus_activate_resource_t(device_t _dev, device_t _child, int _type,
329
                                    int _rid, struct resource *_r);
330
/**
331
 * @brief Activate a resource
332
 *
333
 * Activate a resource previously allocated with
334
 * BUS_ALLOC_RESOURCE().  This may enable decoding of this resource in a
335
 * device for instance.  It will also establish a mapping for the resource
336
 * unless RF_UNMAPPED was set when allocating the resource.
337
 *
338
 * @param _dev		the parent device of @p _child
339
 * @param _child	the device which allocated the resource
340
 * @param _type		the type of resource
341
 * @param _rid		the resource identifier
342
 * @param _r		the resource to activate
343
 */
344
345
static __inline int BUS_ACTIVATE_RESOURCE(device_t _dev, device_t _child,
346
                                          int _type, int _rid,
347
                                          struct resource *_r)
348
{
349
	kobjop_t _m;
350
	int rc;
351
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_activate_resource);
352
	rc = ((bus_activate_resource_t *) _m)(_dev, _child, _type, _rid, _r);
353
	return (rc);
354
}
355
356
/** @brief Unique descriptor for the BUS_MAP_RESOURCE() method */
357
extern struct kobjop_desc bus_map_resource_desc;
358
/** @brief A function implementing the BUS_MAP_RESOURCE() method */
359
typedef int bus_map_resource_t(device_t _dev, device_t _child, int _type,
360
                               struct resource *_r,
361
                               struct resource_map_request *_args,
362
                               struct resource_map *_map);
363
/**
364
 * @brief Map a resource
365
 *
366
 * Allocate a mapping for a range of an active resource.  The mapping
367
 * is described by a struct resource_map object.  This may for instance
368
 * map a memory region into the kernel's virtual address space.
369
 *
370
 * @param _dev		the parent device of @p _child
371
 * @param _child	the device which allocated the resource
372
 * @param _type		the type of resource
373
 * @param _r		the resource to map
374
 * @param _args		optional attributes of the mapping
375
 * @param _map		the mapping
376
 */
377
378
static __inline int BUS_MAP_RESOURCE(device_t _dev, device_t _child, int _type,
379
                                     struct resource *_r,
380
                                     struct resource_map_request *_args,
381
                                     struct resource_map *_map)
382
{
383
	kobjop_t _m;
384
	int rc;
385
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_map_resource);
386
	rc = ((bus_map_resource_t *) _m)(_dev, _child, _type, _r, _args, _map);
387
	return (rc);
388
}
389
390
/** @brief Unique descriptor for the BUS_UNMAP_RESOURCE() method */
391
extern struct kobjop_desc bus_unmap_resource_desc;
392
/** @brief A function implementing the BUS_UNMAP_RESOURCE() method */
393
typedef int bus_unmap_resource_t(device_t _dev, device_t _child, int _type,
394
                                 struct resource *_r,
395
                                 struct resource_map *_map);
396
/**
397
 * @brief Unmap a resource
398
 *
399
 * Release a mapping previously allocated with
400
 * BUS_MAP_RESOURCE(). This may for instance unmap a memory region
401
 * from the kernel's virtual address space.
402
 *
403
 * @param _dev		the parent device of @p _child
404
 * @param _child	the device which allocated the resource
405
 * @param _type		the type of resource
406
 * @param _r		the resource
407
 * @param _map		the mapping to release
408
 */
409
410
static __inline int BUS_UNMAP_RESOURCE(device_t _dev, device_t _child,
411
                                       int _type, struct resource *_r,
412
                                       struct resource_map *_map)
413
{
414
	kobjop_t _m;
415
	int rc;
416
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_unmap_resource);
417
	rc = ((bus_unmap_resource_t *) _m)(_dev, _child, _type, _r, _map);
418
	return (rc);
419
}
420
421
/** @brief Unique descriptor for the BUS_DEACTIVATE_RESOURCE() method */
422
extern struct kobjop_desc bus_deactivate_resource_desc;
423
/** @brief A function implementing the BUS_DEACTIVATE_RESOURCE() method */
424
typedef int bus_deactivate_resource_t(device_t _dev, device_t _child, int _type,
425
                                      int _rid, struct resource *_r);
426
/**
427
 * @brief Deactivate a resource
428
 *
429
 * Deactivate a resource previously allocated with
430
 * BUS_ALLOC_RESOURCE().
431
 *
432
 * @param _dev		the parent device of @p _child
433
 * @param _child	the device which allocated the resource
434
 * @param _type		the type of resource
435
 * @param _rid		the resource identifier
436
 * @param _r		the resource to deactivate
437
 */
438
439
static __inline int BUS_DEACTIVATE_RESOURCE(device_t _dev, device_t _child,
440
                                            int _type, int _rid,
441
                                            struct resource *_r)
442
{
443
	kobjop_t _m;
444
	int rc;
445
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_deactivate_resource);
446
	rc = ((bus_deactivate_resource_t *) _m)(_dev, _child, _type, _rid, _r);
447
	return (rc);
448
}
449
450
/** @brief Unique descriptor for the BUS_ADJUST_RESOURCE() method */
451
extern struct kobjop_desc bus_adjust_resource_desc;
452
/** @brief A function implementing the BUS_ADJUST_RESOURCE() method */
453
typedef int bus_adjust_resource_t(device_t _dev, device_t _child, int _type,
454
                                  struct resource *_res, rman_res_t _start,
455
                                  rman_res_t _end);
456
/**
457
 * @brief Adjust a resource
458
 *
459
 * Adjust the start and/or end of a resource allocated by
460
 * BUS_ALLOC_RESOURCE.  At least part of the new address range must overlap
461
 * with the existing address range.  If the successful, the resource's range
462
 * will be adjusted to [start, end] on return.
463
 *
464
 * @param _dev		the parent device of @p _child
465
 * @param _child	the device which allocated the resource
466
 * @param _type		the type of resource
467
 * @param _res		the resource to adjust
468
 * @param _start	the new starting address of the resource range
469
 * @param _end		the new ending address of the resource range
470
 */
471
472
static __inline int BUS_ADJUST_RESOURCE(device_t _dev, device_t _child,
473
                                        int _type, struct resource *_res,
474
                                        rman_res_t _start, rman_res_t _end)
475
{
476
	kobjop_t _m;
477
	int rc;
478
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_adjust_resource);
479
	rc = ((bus_adjust_resource_t *) _m)(_dev, _child, _type, _res, _start, _end);
480
	return (rc);
481
}
482
483
/** @brief Unique descriptor for the BUS_TRANSLATE_RESOURCE() method */
484
extern struct kobjop_desc bus_translate_resource_desc;
485
/** @brief A function implementing the BUS_TRANSLATE_RESOURCE() method */
486
typedef int bus_translate_resource_t(device_t _dev, int _type,
487
                                     rman_res_t _start, rman_res_t *_newstart);
488
/**
489
 * @brief translate a resource value
490
 *
491
 *
492
 * @param _dev		the device associated with the resource
493
 * @param _type		the type of resource
494
 * @param _start	the starting address of the resource range
495
 * @param _newstart	the new starting address of the resource range
496
 */
497
498
static __inline int BUS_TRANSLATE_RESOURCE(device_t _dev, int _type,
499
                                           rman_res_t _start,
500
                                           rman_res_t *_newstart)
501
{
502
	kobjop_t _m;
503
	int rc;
504
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_translate_resource);
505
	rc = ((bus_translate_resource_t *) _m)(_dev, _type, _start, _newstart);
506
	return (rc);
507
}
508
509
/** @brief Unique descriptor for the BUS_RELEASE_RESOURCE() method */
510
extern struct kobjop_desc bus_release_resource_desc;
511
/** @brief A function implementing the BUS_RELEASE_RESOURCE() method */
512
typedef int bus_release_resource_t(device_t _dev, device_t _child, int _type,
513
                                   int _rid, struct resource *_res);
514
/**
515
 * @brief Release a resource
516
 *
517
 * Free a resource allocated by the BUS_ALLOC_RESOURCE.  The @p _rid
518
 * value must be the same as the one returned by BUS_ALLOC_RESOURCE()
519
 * (which is not necessarily the same as the one the client passed).
520
 *
521
 * @param _dev		the parent device of @p _child
522
 * @param _child	the device which allocated the resource
523
 * @param _type		the type of resource
524
 * @param _rid		the resource identifier
525
 * @param _r		the resource to release
526
 */
527
528
static __inline int BUS_RELEASE_RESOURCE(device_t _dev, device_t _child,
529
                                         int _type, int _rid,
530
                                         struct resource *_res)
531
{
532
	kobjop_t _m;
533
	int rc;
534
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_release_resource);
535
	rc = ((bus_release_resource_t *) _m)(_dev, _child, _type, _rid, _res);
536
	return (rc);
537
}
538
539
/** @brief Unique descriptor for the BUS_SETUP_INTR() method */
540
extern struct kobjop_desc bus_setup_intr_desc;
541
/** @brief A function implementing the BUS_SETUP_INTR() method */
542
typedef int bus_setup_intr_t(device_t _dev, device_t _child,
543
                             struct resource *_irq, int _flags,
544
                             driver_filter_t *_filter, driver_intr_t *_intr,
545
                             void *_arg, void **_cookiep);
546
/**
547
 * @brief Install an interrupt handler
548
 *
549
 * This method is used to associate an interrupt handler function with
550
 * an irq resource. When the interrupt triggers, the function @p _intr
551
 * will be called with the value of @p _arg as its single
552
 * argument. The value returned in @p *_cookiep is used to cancel the
553
 * interrupt handler - the caller should save this value to use in a
554
 * future call to BUS_TEARDOWN_INTR().
555
 *
556
 * @param _dev		the parent device of @p _child
557
 * @param _child	the device which allocated the resource
558
 * @param _irq		the resource representing the interrupt
559
 * @param _flags	a set of bits from enum intr_type specifying
560
 *			the class of interrupt
561
 * @param _intr		the function to call when the interrupt
562
 *			triggers
563
 * @param _arg		a value to use as the single argument in calls
564
 *			to @p _intr
565
 * @param _cookiep	a pointer to a location to receive a cookie
566
 *			value that may be used to remove the interrupt
567
 *			handler
568
 */
569
570
static __inline int BUS_SETUP_INTR(device_t _dev, device_t _child,
571
                                   struct resource *_irq, int _flags,
572
                                   driver_filter_t *_filter,
573
                                   driver_intr_t *_intr, void *_arg,
574
                                   void **_cookiep)
575
{
576
	kobjop_t _m;
577
	int rc;
578
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_setup_intr);
579
	rc = ((bus_setup_intr_t *) _m)(_dev, _child, _irq, _flags, _filter, _intr, _arg, _cookiep);
580
	return (rc);
581
}
582
583
/** @brief Unique descriptor for the BUS_TEARDOWN_INTR() method */
584
extern struct kobjop_desc bus_teardown_intr_desc;
585
/** @brief A function implementing the BUS_TEARDOWN_INTR() method */
586
typedef int bus_teardown_intr_t(device_t _dev, device_t _child,
587
                                struct resource *_irq, void *_cookie);
588
/**
589
 * @brief Uninstall an interrupt handler
590
 *
591
 * This method is used to disassociate an interrupt handler function
592
 * with an irq resource. The value of @p _cookie must be the value
593
 * returned from a previous call to BUS_SETUP_INTR().
594
 *
595
 * @param _dev		the parent device of @p _child
596
 * @param _child	the device which allocated the resource
597
 * @param _irq		the resource representing the interrupt
598
 * @param _cookie	the cookie value returned when the interrupt
599
 *			was originally registered
600
 */
601
602
static __inline int BUS_TEARDOWN_INTR(device_t _dev, device_t _child,
603
                                      struct resource *_irq, void *_cookie)
604
{
605
	kobjop_t _m;
606
	int rc;
607
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_teardown_intr);
608
	rc = ((bus_teardown_intr_t *) _m)(_dev, _child, _irq, _cookie);
609
	return (rc);
610
}
611
612
/** @brief Unique descriptor for the BUS_SUSPEND_INTR() method */
613
extern struct kobjop_desc bus_suspend_intr_desc;
614
/** @brief A function implementing the BUS_SUSPEND_INTR() method */
615
typedef int bus_suspend_intr_t(device_t _dev, device_t _child,
616
                               struct resource *_irq);
617
/**
618
 * @brief Suspend an interrupt handler
619
 *
620
 * This method is used to mark a handler as suspended in the case
621
 * that the associated device is powered down and cannot be a source
622
 * for the, typically shared, interrupt.
623
 * The value of @p _irq must be the interrupt resource passed
624
 * to a previous call to BUS_SETUP_INTR().
625
 *
626
 * @param _dev		the parent device of @p _child
627
 * @param _child	the device which allocated the resource
628
 * @param _irq		the resource representing the interrupt
629
 */
630
631
static __inline int BUS_SUSPEND_INTR(device_t _dev, device_t _child,
632
                                     struct resource *_irq)
633
{
634
	kobjop_t _m;
635
	int rc;
636
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_suspend_intr);
637
	rc = ((bus_suspend_intr_t *) _m)(_dev, _child, _irq);
638
	return (rc);
639
}
640
641
/** @brief Unique descriptor for the BUS_RESUME_INTR() method */
642
extern struct kobjop_desc bus_resume_intr_desc;
643
/** @brief A function implementing the BUS_RESUME_INTR() method */
644
typedef int bus_resume_intr_t(device_t _dev, device_t _child,
645
                              struct resource *_irq);
646
/**
647
 * @brief Resume an interrupt handler
648
 *
649
 * This method is used to clear suspended state of a handler when
650
 * the associated device is powered up and can be an interrupt source
651
 * again.
652
 * The value of @p _irq must be the interrupt resource passed
653
 * to a previous call to BUS_SETUP_INTR().
654
 *
655
 * @param _dev		the parent device of @p _child
656
 * @param _child	the device which allocated the resource
657
 * @param _irq		the resource representing the interrupt
658
 */
659
660
static __inline int BUS_RESUME_INTR(device_t _dev, device_t _child,
661
                                    struct resource *_irq)
662
{
663
	kobjop_t _m;
664
	int rc;
665
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_resume_intr);
666
	rc = ((bus_resume_intr_t *) _m)(_dev, _child, _irq);
667
	return (rc);
668
}
669
670
/** @brief Unique descriptor for the BUS_SET_RESOURCE() method */
671
extern struct kobjop_desc bus_set_resource_desc;
672
/** @brief A function implementing the BUS_SET_RESOURCE() method */
673
typedef int bus_set_resource_t(device_t _dev, device_t _child, int _type,
674
                               int _rid, rman_res_t _start, rman_res_t _count);
675
/**
676
 * @brief Define a resource which can be allocated with
677
 * BUS_ALLOC_RESOURCE().
678
 *
679
 * This method is used by some buses (typically ISA) to allow a
680
 * driver to describe a resource range that it would like to
681
 * allocate. The resource defined by @p _type and @p _rid is defined
682
 * to start at @p _start and to include @p _count indices in its
683
 * range.
684
 *
685
 * @param _dev		the parent device of @p _child
686
 * @param _child	the device which owns the resource
687
 * @param _type		the type of resource
688
 * @param _rid		the resource identifier
689
 * @param _start	the start of the resource range
690
 * @param _count	the size of the resource range
691
 */
692
693
static __inline int BUS_SET_RESOURCE(device_t _dev, device_t _child, int _type,
694
                                     int _rid, rman_res_t _start,
695
                                     rman_res_t _count)
696
{
697
	kobjop_t _m;
698
	int rc;
699
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_set_resource);
700
	rc = ((bus_set_resource_t *) _m)(_dev, _child, _type, _rid, _start, _count);
701
	return (rc);
702
}
703
704
/** @brief Unique descriptor for the BUS_GET_RESOURCE() method */
705
extern struct kobjop_desc bus_get_resource_desc;
706
/** @brief A function implementing the BUS_GET_RESOURCE() method */
707
typedef int bus_get_resource_t(device_t _dev, device_t _child, int _type,
708
                               int _rid, rman_res_t *_startp,
709
                               rman_res_t *_countp);
710
/**
711
 * @brief Describe a resource
712
 *
713
 * This method allows a driver to examine the range used for a given
714
 * resource without actually allocating it.
715
 *
716
 * @param _dev		the parent device of @p _child
717
 * @param _child	the device which owns the resource
718
 * @param _type		the type of resource
719
 * @param _rid		the resource identifier
720
 * @param _start	the address of a location to receive the start
721
 *			index of the resource range
722
 * @param _count	the address of a location to receive the size
723
 *			of the resource range
724
 */
725
726
static __inline int BUS_GET_RESOURCE(device_t _dev, device_t _child, int _type,
727
                                     int _rid, rman_res_t *_startp,
728
                                     rman_res_t *_countp)
729
{
730
	kobjop_t _m;
731
	int rc;
732
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_get_resource);
733
	rc = ((bus_get_resource_t *) _m)(_dev, _child, _type, _rid, _startp, _countp);
734
	return (rc);
735
}
736
737
/** @brief Unique descriptor for the BUS_DELETE_RESOURCE() method */
738
extern struct kobjop_desc bus_delete_resource_desc;
739
/** @brief A function implementing the BUS_DELETE_RESOURCE() method */
740
typedef void bus_delete_resource_t(device_t _dev, device_t _child, int _type,
741
                                   int _rid);
742
/**
743
 * @brief Delete a resource.
744
 *
745
 * Use this to delete a resource (possibly one previously added with
746
 * BUS_SET_RESOURCE()).
747
 *
748
 * @param _dev		the parent device of @p _child
749
 * @param _child	the device which owns the resource
750
 * @param _type		the type of resource
751
 * @param _rid		the resource identifier
752
 */
753
754
static __inline void BUS_DELETE_RESOURCE(device_t _dev, device_t _child,
755
                                         int _type, int _rid)
756
{
757
	kobjop_t _m;
758
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_delete_resource);
759
	((bus_delete_resource_t *) _m)(_dev, _child, _type, _rid);
760
}
761
762
/** @brief Unique descriptor for the BUS_GET_RESOURCE_LIST() method */
763
extern struct kobjop_desc bus_get_resource_list_desc;
764
/** @brief A function implementing the BUS_GET_RESOURCE_LIST() method */
765
typedef struct resource_list * bus_get_resource_list_t(device_t _dev,
766
                                                       device_t _child);
767
/**
768
 * @brief Return a struct resource_list.
769
 *
770
 * Used by drivers which use bus_generic_rl_alloc_resource() etc. to
771
 * implement their resource handling. It should return the resource
772
 * list of the given child device.
773
 *
774
 * @param _dev		the parent device of @p _child
775
 * @param _child	the device which owns the resource list
776
 */
777
778
static __inline struct resource_list * BUS_GET_RESOURCE_LIST(device_t _dev,
779
                                                             device_t _child)
780
{
781
	kobjop_t _m;
782
	struct resource_list * rc;
783
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_get_resource_list);
784
	rc = ((bus_get_resource_list_t *) _m)(_dev, _child);
785
	return (rc);
786
}
787
788
/** @brief Unique descriptor for the BUS_CHILD_PRESENT() method */
789
extern struct kobjop_desc bus_child_present_desc;
790
/** @brief A function implementing the BUS_CHILD_PRESENT() method */
791
typedef int bus_child_present_t(device_t _dev, device_t _child);
792
/**
793
 * @brief Is the hardware described by @p _child still attached to the
794
 * system?
795
 *
796
 * This method should return 0 if the device is not present.  It
797
 * should return -1 if it is present.  Any errors in determining
798
 * should be returned as a normal errno value.  Client drivers are to
799
 * assume that the device is present, even if there is an error
800
 * determining if it is there.  Buses are to try to avoid returning
801
 * errors, but newcard will return an error if the device fails to
802
 * implement this method.
803
 *
804
 * @param _dev		the parent device of @p _child
805
 * @param _child	the device which is being examined
806
 */
807
808
static __inline int BUS_CHILD_PRESENT(device_t _dev, device_t _child)
809
{
810
	kobjop_t _m;
811
	int rc;
812
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_child_present);
813
	rc = ((bus_child_present_t *) _m)(_dev, _child);
814
	return (rc);
815
}
816
817
/** @brief Unique descriptor for the BUS_CHILD_PNPINFO_STR() method */
818
extern struct kobjop_desc bus_child_pnpinfo_str_desc;
819
/** @brief A function implementing the BUS_CHILD_PNPINFO_STR() method */
820
typedef int bus_child_pnpinfo_str_t(device_t _dev, device_t _child, char *_buf,
821
                                    size_t _buflen);
822
/**
823
 * @brief Returns the pnp info for this device.
824
 *
825
 * Return it as a string.  If the storage is insufficient for the
826
 * string, then return EOVERFLOW.
827
 *
828
 * The string must be formatted as a space-separated list of
829
 * name=value pairs.  Names may only contain alphanumeric characters,
830
 * underscores ('_') and hyphens ('-').  Values can contain any
831
 * non-whitespace characters.  Values containing whitespace can be
832
 * quoted with double quotes ('"').  Double quotes and backslashes in
833
 * quoted values can be escaped with backslashes ('\').
834
 *
835
 * @param _dev		the parent device of @p _child
836
 * @param _child	the device which is being examined
837
 * @param _buf		the address of a buffer to receive the pnp
838
 *			string
839
 * @param _buflen	the size of the buffer pointed to by @p _buf
840
 */
841
842
static __inline int BUS_CHILD_PNPINFO_STR(device_t _dev, device_t _child,
843
                                          char *_buf, size_t _buflen)
844
{
845
	kobjop_t _m;
846
	int rc;
847
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_child_pnpinfo_str);
848
	rc = ((bus_child_pnpinfo_str_t *) _m)(_dev, _child, _buf, _buflen);
849
	return (rc);
850
}
851
852
/** @brief Unique descriptor for the BUS_CHILD_LOCATION_STR() method */
853
extern struct kobjop_desc bus_child_location_str_desc;
854
/** @brief A function implementing the BUS_CHILD_LOCATION_STR() method */
855
typedef int bus_child_location_str_t(device_t _dev, device_t _child, char *_buf,
856
                                     size_t _buflen);
857
/**
858
 * @brief Returns the location for this device.
859
 *
860
 * Return it as a string.  If the storage is insufficient for the
861
 * string, then return EOVERFLOW.
862
 *
863
 * The string must be formatted as a space-separated list of
864
 * name=value pairs.  Names may only contain alphanumeric characters,
865
 * underscores ('_') and hyphens ('-').  Values can contain any
866
 * non-whitespace characters.  Values containing whitespace can be
867
 * quoted with double quotes ('"').  Double quotes and backslashes in
868
 * quoted values can be escaped with backslashes ('\').
869
 *
870
 * @param _dev		the parent device of @p _child
871
 * @param _child	the device which is being examined
872
 * @param _buf		the address of a buffer to receive the location
873
 *			string
874
 * @param _buflen	the size of the buffer pointed to by @p _buf
875
 */
876
877
static __inline int BUS_CHILD_LOCATION_STR(device_t _dev, device_t _child,
878
                                           char *_buf, size_t _buflen)
879
{
880
	kobjop_t _m;
881
	int rc;
882
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_child_location_str);
883
	rc = ((bus_child_location_str_t *) _m)(_dev, _child, _buf, _buflen);
884
	return (rc);
885
}
886
887
/** @brief Unique descriptor for the BUS_BIND_INTR() method */
888
extern struct kobjop_desc bus_bind_intr_desc;
889
/** @brief A function implementing the BUS_BIND_INTR() method */
890
typedef int bus_bind_intr_t(device_t _dev, device_t _child,
891
                            struct resource *_irq, int _cpu);
892
/**
893
 * @brief Allow drivers to request that an interrupt be bound to a specific
894
 * CPU.
895
 *
896
 * @param _dev		the parent device of @p _child
897
 * @param _child	the device which allocated the resource
898
 * @param _irq		the resource representing the interrupt
899
 * @param _cpu		the CPU to bind the interrupt to
900
 */
901
902
static __inline int BUS_BIND_INTR(device_t _dev, device_t _child,
903
                                  struct resource *_irq, int _cpu)
904
{
905
	kobjop_t _m;
906
	int rc;
907
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_bind_intr);
908
	rc = ((bus_bind_intr_t *) _m)(_dev, _child, _irq, _cpu);
909
	return (rc);
910
}
911
912
/** @brief Unique descriptor for the BUS_CONFIG_INTR() method */
913
extern struct kobjop_desc bus_config_intr_desc;
914
/** @brief A function implementing the BUS_CONFIG_INTR() method */
915
typedef int bus_config_intr_t(device_t _dev, int _irq, enum intr_trigger _trig,
916
                              enum intr_polarity _pol);
917
/**
918
 * @brief Allow (bus) drivers to specify the trigger mode and polarity
919
 * of the specified interrupt.
920
 *
921
 * @param _dev		the bus device
922
 * @param _irq		the interrupt number to modify
923
 * @param _trig		the trigger mode required
924
 * @param _pol		the interrupt polarity required
925
 */
926
927
static __inline int BUS_CONFIG_INTR(device_t _dev, int _irq,
928
                                    enum intr_trigger _trig,
929
                                    enum intr_polarity _pol)
930
{
931
	kobjop_t _m;
932
	int rc;
933
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_config_intr);
934
	rc = ((bus_config_intr_t *) _m)(_dev, _irq, _trig, _pol);
935
	return (rc);
936
}
937
938
/** @brief Unique descriptor for the BUS_DESCRIBE_INTR() method */
939
extern struct kobjop_desc bus_describe_intr_desc;
940
/** @brief A function implementing the BUS_DESCRIBE_INTR() method */
941
typedef int bus_describe_intr_t(device_t _dev, device_t _child,
942
                                struct resource *_irq, void *_cookie,
943
                                const char *_descr);
944
/**
945
 * @brief Allow drivers to associate a description with an active
946
 * interrupt handler.
947
 *
948
 * @param _dev		the parent device of @p _child
949
 * @param _child	the device which allocated the resource
950
 * @param _irq		the resource representing the interrupt
951
 * @param _cookie	the cookie value returned when the interrupt
952
 *			was originally registered
953
 * @param _descr	the description to associate with the interrupt
954
 */
955
956
static __inline int BUS_DESCRIBE_INTR(device_t _dev, device_t _child,
957
                                      struct resource *_irq, void *_cookie,
958
                                      const char *_descr)
959
{
960
	kobjop_t _m;
961
	int rc;
962
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_describe_intr);
963
	rc = ((bus_describe_intr_t *) _m)(_dev, _child, _irq, _cookie, _descr);
964
	return (rc);
965
}
966
967
/** @brief Unique descriptor for the BUS_HINTED_CHILD() method */
968
extern struct kobjop_desc bus_hinted_child_desc;
969
/** @brief A function implementing the BUS_HINTED_CHILD() method */
970
typedef void bus_hinted_child_t(device_t _dev, const char *_dname, int _dunit);
971
/**
972
 * @brief Notify a (bus) driver about a child that the hints mechanism
973
 * believes it has discovered.
974
 *
975
 * The bus is responsible for then adding the child in the right order
976
 * and discovering other things about the child.  The bus driver is
977
 * free to ignore this hint, to do special things, etc.  It is all up
978
 * to the bus driver to interpret.
979
 *
980
 * This method is only called in response to the parent bus asking for
981
 * hinted devices to be enumerated.
982
 *
983
 * @param _dev		the bus device
984
 * @param _dname	the name of the device w/o unit numbers
985
 * @param _dunit	the unit number of the device
986
 */
987
988
static __inline void BUS_HINTED_CHILD(device_t _dev, const char *_dname,
989
                                      int _dunit)
990
{
991
	kobjop_t _m;
992
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_hinted_child);
993
	((bus_hinted_child_t *) _m)(_dev, _dname, _dunit);
994
}
995
996
/** @brief Unique descriptor for the BUS_GET_DMA_TAG() method */
997
extern struct kobjop_desc bus_get_dma_tag_desc;
998
/** @brief A function implementing the BUS_GET_DMA_TAG() method */
999
typedef bus_dma_tag_t bus_get_dma_tag_t(device_t _dev, device_t _child);
1000
/**
1001
 * @brief Returns bus_dma_tag_t for use w/ devices on the bus.
1002
 *
1003
 * @param _dev		the parent device of @p _child
1004
 * @param _child	the device to which the tag will belong
1005
 */
1006
1007
static __inline bus_dma_tag_t BUS_GET_DMA_TAG(device_t _dev, device_t _child)
1008
{
1009
	kobjop_t _m;
1010
	bus_dma_tag_t rc;
1011
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_get_dma_tag);
1012
	rc = ((bus_get_dma_tag_t *) _m)(_dev, _child);
1013
	return (rc);
1014
}
1015
1016
/** @brief Unique descriptor for the BUS_GET_BUS_TAG() method */
1017
extern struct kobjop_desc bus_get_bus_tag_desc;
1018
/** @brief A function implementing the BUS_GET_BUS_TAG() method */
1019
typedef bus_space_tag_t bus_get_bus_tag_t(device_t _dev, device_t _child);
1020
/**
1021
 * @brief Returns bus_space_tag_t for use w/ devices on the bus.
1022
 *
1023
 * @param _dev		the parent device of @p _child
1024
 * @param _child	the device to which the tag will belong
1025
 */
1026
1027
static __inline bus_space_tag_t BUS_GET_BUS_TAG(device_t _dev, device_t _child)
1028
{
1029
	kobjop_t _m;
1030
	bus_space_tag_t rc;
1031
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_get_bus_tag);
1032
	rc = ((bus_get_bus_tag_t *) _m)(_dev, _child);
1033
	return (rc);
1034
}
1035
1036
/** @brief Unique descriptor for the BUS_HINT_DEVICE_UNIT() method */
1037
extern struct kobjop_desc bus_hint_device_unit_desc;
1038
/** @brief A function implementing the BUS_HINT_DEVICE_UNIT() method */
1039
typedef void bus_hint_device_unit_t(device_t _dev, device_t _child,
1040
                                    const char *_name, int *_unitp);
1041
/**
1042
 * @brief Allow the bus to determine the unit number of a device.
1043
 *
1044
 * @param _dev		the parent device of @p _child
1045
 * @param _child	the device whose unit is to be wired
1046
 * @param _name		the name of the device's new devclass
1047
 * @param _unitp	a pointer to the device's new unit value
1048
 */
1049
1050
static __inline void BUS_HINT_DEVICE_UNIT(device_t _dev, device_t _child,
1051
                                          const char *_name, int *_unitp)
1052
{
1053
	kobjop_t _m;
1054
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_hint_device_unit);
1055
	((bus_hint_device_unit_t *) _m)(_dev, _child, _name, _unitp);
1056
}
1057
1058
/** @brief Unique descriptor for the BUS_NEW_PASS() method */
1059
extern struct kobjop_desc bus_new_pass_desc;
1060
/** @brief A function implementing the BUS_NEW_PASS() method */
1061
typedef void bus_new_pass_t(device_t _dev);
1062
/**
1063
 * @brief Notify a bus that the bus pass level has been changed
1064
 *
1065
 * @param _dev		the bus device
1066
 */
1067
1068
static __inline void BUS_NEW_PASS(device_t _dev)
1069
{
1070
	kobjop_t _m;
1071
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_new_pass);
1072
	((bus_new_pass_t *) _m)(_dev);
1073
}
1074
1075
/** @brief Unique descriptor for the BUS_REMAP_INTR() method */
1076
extern struct kobjop_desc bus_remap_intr_desc;
1077
/** @brief A function implementing the BUS_REMAP_INTR() method */
1078
typedef int bus_remap_intr_t(device_t _dev, device_t _child, u_int _irq);
1079
/**
1080
 * @brief Notify a bus that specified child's IRQ should be remapped.
1081
 *
1082
 * @param _dev		the bus device
1083
 * @param _child	the child device
1084
 * @param _irq		the irq number
1085
 */
1086
1087
static __inline int BUS_REMAP_INTR(device_t _dev, device_t _child, u_int _irq)
1088
{
1089
	kobjop_t _m;
1090
	int rc;
1091
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_remap_intr);
1092
	rc = ((bus_remap_intr_t *) _m)(_dev, _child, _irq);
1093
	return (rc);
1094
}
1095
1096
/** @brief Unique descriptor for the BUS_SUSPEND_CHILD() method */
1097
extern struct kobjop_desc bus_suspend_child_desc;
1098
/** @brief A function implementing the BUS_SUSPEND_CHILD() method */
1099
typedef int bus_suspend_child_t(device_t _dev, device_t _child);
1100
/**
1101
 * @brief Suspend a given child
1102
 *
1103
 * @param _dev		the parent device of @p _child
1104
 * @param _child	the device to suspend
1105
 */
1106
1107
static __inline int BUS_SUSPEND_CHILD(device_t _dev, device_t _child)
1108
{
1109
	kobjop_t _m;
1110
	int rc;
1111
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_suspend_child);
1112
	rc = ((bus_suspend_child_t *) _m)(_dev, _child);
1113
	return (rc);
1114
}
1115
1116
/** @brief Unique descriptor for the BUS_RESUME_CHILD() method */
1117
extern struct kobjop_desc bus_resume_child_desc;
1118
/** @brief A function implementing the BUS_RESUME_CHILD() method */
1119
typedef int bus_resume_child_t(device_t _dev, device_t _child);
1120
/**
1121
 * @brief Resume a given child
1122
 *
1123
 * @param _dev		the parent device of @p _child
1124
 * @param _child	the device to resume
1125
 */
1126
1127
static __inline int BUS_RESUME_CHILD(device_t _dev, device_t _child)
1128
{
1129
	kobjop_t _m;
1130
	int rc;
1131
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_resume_child);
1132
	rc = ((bus_resume_child_t *) _m)(_dev, _child);
1133
	return (rc);
1134
}
1135
1136
/** @brief Unique descriptor for the BUS_GET_DOMAIN() method */
1137
extern struct kobjop_desc bus_get_domain_desc;
1138
/** @brief A function implementing the BUS_GET_DOMAIN() method */
1139
typedef int bus_get_domain_t(device_t _dev, device_t _child, int *_domain);
1140
/**
1141
 * @brief Get the VM domain handle for the given bus and child.
1142
 *
1143
 * @param _dev		the bus device
1144
 * @param _child	the child device
1145
 * @param _domain	a pointer to the bus's domain handle identifier
1146
 */
1147
1148
static __inline int BUS_GET_DOMAIN(device_t _dev, device_t _child, int *_domain)
1149
{
1150
	kobjop_t _m;
1151
	int rc;
1152
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_get_domain);
1153
	rc = ((bus_get_domain_t *) _m)(_dev, _child, _domain);
1154
	return (rc);
1155
}
1156
1157
/** @brief Unique descriptor for the BUS_GET_CPUS() method */
1158
extern struct kobjop_desc bus_get_cpus_desc;
1159
/** @brief A function implementing the BUS_GET_CPUS() method */
1160
typedef int bus_get_cpus_t(device_t _dev, device_t _child, enum cpu_sets _op,
1161
                           size_t _setsize, struct _cpuset *_cpuset);
1162
/**
1163
 * @brief Request a set of CPUs
1164
 *
1165
 * @param _dev		the bus device
1166
 * @param _child	the child device
1167
 * @param _op		type of CPUs to request
1168
 * @param _setsize	the size of the set passed in _cpuset
1169
 * @param _cpuset	a pointer to a cpuset to receive the requested
1170
 *			set of CPUs
1171
 */
1172
1173
static __inline int BUS_GET_CPUS(device_t _dev, device_t _child,
1174
                                 enum cpu_sets _op, size_t _setsize,
1175
                                 struct _cpuset *_cpuset)
1176
{
1177
	kobjop_t _m;
1178
	int rc;
1179
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_get_cpus);
1180
	rc = ((bus_get_cpus_t *) _m)(_dev, _child, _op, _setsize, _cpuset);
1181
	return (rc);
1182
}
1183
1184
/** @brief Unique descriptor for the BUS_RESET_PREPARE() method */
1185
extern struct kobjop_desc bus_reset_prepare_desc;
1186
/** @brief A function implementing the BUS_RESET_PREPARE() method */
1187
typedef int bus_reset_prepare_t(device_t _dev, device_t _child);
1188
/**
1189
 * @brief Prepares the given child of the bus for reset
1190
 *
1191
 * Typically bus detaches or suspends children' drivers, and then
1192
 * calls this method to save bus-specific information, for instance,
1193
 * PCI config space, which is damaged by reset.
1194
 *
1195
 * The bus_helper_reset_prepare() helper is provided to ease
1196
 * implementing bus reset methods.
1197
 *
1198
 * @param _dev		the bus device
1199
 * @param _child	the child device
1200
 */
1201
1202
static __inline int BUS_RESET_PREPARE(device_t _dev, device_t _child)
1203
{
1204
	kobjop_t _m;
1205
	int rc;
1206
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_reset_prepare);
1207
	rc = ((bus_reset_prepare_t *) _m)(_dev, _child);
1208
	return (rc);
1209
}
1210
1211
/** @brief Unique descriptor for the BUS_RESET_POST() method */
1212
extern struct kobjop_desc bus_reset_post_desc;
1213
/** @brief A function implementing the BUS_RESET_POST() method */
1214
typedef int bus_reset_post_t(device_t _dev, device_t _child);
1215
/**
1216
 * @brief Restores the child operations after the reset
1217
 *
1218
 * The bus_helper_reset_post() helper is provided to ease
1219
 * implementing bus reset methods.
1220
 *
1221
 * @param _dev		the bus device
1222
 * @param _child	the child device
1223
 */
1224
1225
static __inline int BUS_RESET_POST(device_t _dev, device_t _child)
1226
{
1227
	kobjop_t _m;
1228
	int rc;
1229
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_reset_post);
1230
	rc = ((bus_reset_post_t *) _m)(_dev, _child);
1231
	return (rc);
1232
}
1233
1234
/** @brief Unique descriptor for the BUS_RESET_CHILD() method */
1235
extern struct kobjop_desc bus_reset_child_desc;
1236
/** @brief A function implementing the BUS_RESET_CHILD() method */
1237
typedef int bus_reset_child_t(device_t _dev, device_t _child, int _flags);
1238
/**
1239
 * @brief Performs reset of the child
1240
 *
1241
 * @param _dev		the bus device
1242
 * @param _child	the child device
1243
 * @param _flags	DEVF_RESET_ flags
1244
 */
1245
1246
static __inline int BUS_RESET_CHILD(device_t _dev, device_t _child, int _flags)
1247
{
1248
	kobjop_t _m;
1249
	int rc;
1250
	KOBJOPLOOKUP(((kobj_t)_dev)->ops,bus_reset_child);
1251
	rc = ((bus_reset_child_t *) _m)(_dev, _child, _flags);
1252
	return (rc);
1253
}
1254
1255
#endif /* _bus_if_h_ */
(-)drvGPIOIITK/device_if.h (+402 lines)
Line 0 Link Here
1
/*
2
 * This file is @generated automatically.
3
 * Do not modify anything in here by hand.
4
 *
5
 * Created from source file
6
 *   /usr/src/sys/kern/device_if.m
7
 * with
8
 *   makeobjops.awk
9
 *
10
 * See the source file for legal information
11
 */
12
13
/**
14
 * @defgroup DEVICE device - KObj methods for all device drivers
15
 * @brief A basic set of methods required for all device drivers.
16
 *
17
 * The device interface is used to match devices to drivers during
18
 * autoconfiguration and provides methods to allow drivers to handle
19
 * system-wide events such as suspend, resume or shutdown.
20
 * @{
21
 */
22
23
#ifndef _device_if_h_
24
#define _device_if_h_
25
26
27
#include <sys/tslog.h>
28
29
/** @brief Unique descriptor for the DEVICE_PROBE() method */
30
extern struct kobjop_desc device_probe_desc;
31
/** @brief A function implementing the DEVICE_PROBE() method */
32
typedef int device_probe_t(device_t dev);
33
/**
34
 * @brief Probe to see if a device matches a driver.
35
 *
36
 * Users should not call this method directly. Normally, this
37
 * is called via device_probe_and_attach() to select a driver
38
 * calling the DEVICE_PROBE() of all candidate drivers and attach
39
 * the winning driver (if any) to the device.
40
 *
41
 * This function is used to match devices to device drivers.
42
 * Typically, the driver will examine the device to see if
43
 * it is suitable for this driver. This might include checking
44
 * the values of various device instance variables or reading
45
 * hardware registers.
46
 *  
47
 * In some cases, there may be more than one driver available
48
 * which can be used for a device (for instance there might
49
 * be a generic driver which works for a set of many types of
50
 * device and a more specific driver which works for a subset
51
 * of devices). Because of this, a driver should not assume
52
 * that it will be the driver that attaches to the device even
53
 * if it returns a success status from DEVICE_PROBE(). In particular,
54
 * a driver must free any resources which it allocated during
55
 * the probe before returning. The return value of DEVICE_PROBE()
56
 * is used to elect which driver is used - the driver which returns
57
 * the largest non-error value wins the election and attaches to
58
 * the device. Common non-error values are described in the
59
 * DEVICE_PROBE(9) manual page.
60
 *
61
 * If a driver matches the hardware, it should set the device
62
 * description string using device_set_desc() or
63
 * device_set_desc_copy(). This string is used to generate an
64
 * informative message when DEVICE_ATTACH() is called.
65
 * 
66
 * As a special case, if a driver returns zero, the driver election
67
 * is cut short and that driver will attach to the device
68
 * immediately. This should rarely be used.
69
 *
70
 * For example, a probe method for a PCI device driver might look
71
 * like this:
72
 *
73
 * @code
74
 * int
75
 * foo_probe(device_t dev)
76
 * {
77
 *         if (pci_get_vendor(dev) == FOOVENDOR &&
78
 *             pci_get_device(dev) == FOODEVICE) {
79
 *                 device_set_desc(dev, "Foo device");
80
 *                 return (BUS_PROBE_DEFAULT);
81
 *         }
82
 *         return (ENXIO);
83
 * }
84
 * @endcode
85
 *
86
 * To include this method in a device driver, use a line like this
87
 * in the driver's method list:
88
 *
89
 * @code
90
 * 	KOBJMETHOD(device_probe, foo_probe)
91
 * @endcode
92
 *
93
 * @param dev		the device to probe
94
 *
95
 * @retval 0		if this is the only possible driver for this
96
 *			device
97
 * @retval negative	if the driver can match this device - the
98
 *			least negative value is used to select the
99
 *			driver
100
 * @retval ENXIO	if the driver does not match the device
101
 * @retval positive	if some kind of error was detected during
102
 *			the probe, a regular unix error code should
103
 *			be returned to indicate the type of error
104
 * @see DEVICE_ATTACH(), pci_get_vendor(), pci_get_device()
105
 */
106
107
static __inline int DEVICE_PROBE(device_t dev)
108
{
109
	kobjop_t _m;
110
	int rc;
111
112
TSENTER2(device_get_name(dev));
113
114
	KOBJOPLOOKUP(((kobj_t)dev)->ops,device_probe);
115
	rc = ((device_probe_t *) _m)(dev);
116
117
TSEXIT2(device_get_name(dev));
118
119
	return (rc);
120
}
121
122
/** @brief Unique descriptor for the DEVICE_IDENTIFY() method */
123
extern struct kobjop_desc device_identify_desc;
124
/** @brief A function implementing the DEVICE_IDENTIFY() method */
125
typedef void device_identify_t(driver_t *driver, device_t parent);
126
/**
127
 * @brief Allow a device driver to detect devices not otherwise enumerated.
128
 *
129
 * The DEVICE_IDENTIFY() method is used by some drivers (e.g. the ISA
130
 * bus driver) to help populate the bus device with a useful set of
131
 * child devices, normally by calling the BUS_ADD_CHILD() method of
132
 * the parent device. For instance, the ISA bus driver uses several
133
 * special drivers, including the isahint driver and the pnp driver to
134
 * create child devices based on configuration hints and PnP bus
135
 * probes respectively.
136
 *
137
 * Many bus drivers which support true plug-and-play do not need to
138
 * use this method at all since child devices can be discovered
139
 * automatically without help from child drivers.
140
 *
141
 * To include this method in a device driver, use a line like this
142
 * in the driver's method list:
143
 *
144
 * @code
145
 * 	KOBJMETHOD(device_identify, foo_identify)
146
 * @endcode
147
 *
148
 * @param driver	the driver whose identify method is being called
149
 * @param parent	the parent device to use when adding new children
150
 */
151
152
static __inline void DEVICE_IDENTIFY(driver_t *driver, device_t parent)
153
{
154
	kobjop_t _m;
155
	KOBJOPLOOKUP(driver->ops,device_identify);
156
	((device_identify_t *) _m)(driver, parent);
157
}
158
159
/** @brief Unique descriptor for the DEVICE_ATTACH() method */
160
extern struct kobjop_desc device_attach_desc;
161
/** @brief A function implementing the DEVICE_ATTACH() method */
162
typedef int device_attach_t(device_t dev);
163
/**
164
 * @brief Attach a device to a device driver
165
 *
166
 * Normally only called via device_probe_and_attach(), this is called
167
 * when a driver has succeeded in probing against a device.
168
 * This method should initialise the hardware and allocate other
169
 * system resources (e.g. devfs entries) as required.
170
 *
171
 * To include this method in a device driver, use a line like this
172
 * in the driver's method list:
173
 *
174
 * @code
175
 * 	KOBJMETHOD(device_attach, foo_attach)
176
 * @endcode
177
 *
178
 * @param dev		the device to probe
179
 *
180
 * @retval 0		success
181
 * @retval non-zero	if some kind of error was detected during
182
 *			the attach, a regular unix error code should
183
 *			be returned to indicate the type of error
184
 * @see DEVICE_PROBE()
185
 */
186
187
static __inline int DEVICE_ATTACH(device_t dev)
188
{
189
	kobjop_t _m;
190
	int rc;
191
192
TSENTER2(device_get_name(dev));
193
194
	KOBJOPLOOKUP(((kobj_t)dev)->ops,device_attach);
195
	rc = ((device_attach_t *) _m)(dev);
196
197
TSEXIT2(device_get_name(dev));
198
199
	return (rc);
200
}
201
202
/** @brief Unique descriptor for the DEVICE_DETACH() method */
203
extern struct kobjop_desc device_detach_desc;
204
/** @brief A function implementing the DEVICE_DETACH() method */
205
typedef int device_detach_t(device_t dev);
206
/**
207
 * @brief Detach a driver from a device.
208
 *
209
 * This can be called if the user is replacing the
210
 * driver software or if a device is about to be physically removed
211
 * from the system (e.g. for removable hardware such as USB or PCCARD).
212
 *
213
 * To include this method in a device driver, use a line like this
214
 * in the driver's method list:
215
 *
216
 * @code
217
 * 	KOBJMETHOD(device_detach, foo_detach)
218
 * @endcode
219
 *
220
 * @param dev		the device to detach
221
 *
222
 * @retval 0		success
223
 * @retval non-zero	the detach could not be performed, e.g. if the
224
 *			driver does not support detaching.
225
 *
226
 * @see DEVICE_ATTACH()
227
 */
228
229
static __inline int DEVICE_DETACH(device_t dev)
230
{
231
	kobjop_t _m;
232
	int rc;
233
	KOBJOPLOOKUP(((kobj_t)dev)->ops,device_detach);
234
	rc = ((device_detach_t *) _m)(dev);
235
	return (rc);
236
}
237
238
/** @brief Unique descriptor for the DEVICE_SHUTDOWN() method */
239
extern struct kobjop_desc device_shutdown_desc;
240
/** @brief A function implementing the DEVICE_SHUTDOWN() method */
241
typedef int device_shutdown_t(device_t dev);
242
/**
243
 * @brief Called during system shutdown.
244
 *
245
 * This method allows drivers to detect when the system is being shut down.
246
 * Some drivers need to use this to place their hardware in a consistent
247
 * state before rebooting the computer.
248
 *
249
 * To include this method in a device driver, use a line like this
250
 * in the driver's method list:
251
 *
252
 * @code
253
 * 	KOBJMETHOD(device_shutdown, foo_shutdown)
254
 * @endcode
255
 */
256
257
static __inline int DEVICE_SHUTDOWN(device_t dev)
258
{
259
	kobjop_t _m;
260
	int rc;
261
	KOBJOPLOOKUP(((kobj_t)dev)->ops,device_shutdown);
262
	rc = ((device_shutdown_t *) _m)(dev);
263
	return (rc);
264
}
265
266
/** @brief Unique descriptor for the DEVICE_SUSPEND() method */
267
extern struct kobjop_desc device_suspend_desc;
268
/** @brief A function implementing the DEVICE_SUSPEND() method */
269
typedef int device_suspend_t(device_t dev);
270
/**
271
 * @brief This is called by the power-management subsystem when a
272
 * suspend has been requested by the user or by some automatic
273
 * mechanism.
274
 *
275
 * This gives drivers a chance to veto the suspend or save their
276
 * configuration before power is removed.
277
 *
278
 * To include this method in a device driver, use a line like this in
279
 * the driver's method list:
280
 *
281
 * @code
282
 * 	KOBJMETHOD(device_suspend, foo_suspend)
283
 * @endcode
284
 *
285
 * @param dev		the device being suspended
286
 *
287
 * @retval 0		success
288
 * @retval non-zero	an error occurred while attempting to prepare the
289
 *                      device for suspension
290
 *
291
 * @see DEVICE_RESUME()
292
 */
293
294
static __inline int DEVICE_SUSPEND(device_t dev)
295
{
296
	kobjop_t _m;
297
	int rc;
298
	KOBJOPLOOKUP(((kobj_t)dev)->ops,device_suspend);
299
	rc = ((device_suspend_t *) _m)(dev);
300
	return (rc);
301
}
302
303
/** @brief Unique descriptor for the DEVICE_RESUME() method */
304
extern struct kobjop_desc device_resume_desc;
305
/** @brief A function implementing the DEVICE_RESUME() method */
306
typedef int device_resume_t(device_t dev);
307
/**
308
 * @brief This is called when the system resumes after a suspend.
309
 *
310
 * To include this method in a device driver, use a line like this
311
 * in the driver's method list:
312
 *
313
 * @code
314
 * 	KOBJMETHOD(device_resume, foo_resume)
315
 * @endcode
316
 *
317
 * @param dev		the device being resumed
318
 *
319
 * @retval 0		success
320
 * @retval non-zero	an error occurred while attempting to restore the
321
 *                      device from suspension
322
 *
323
 * @see DEVICE_SUSPEND()
324
 */
325
326
static __inline int DEVICE_RESUME(device_t dev)
327
{
328
	kobjop_t _m;
329
	int rc;
330
	KOBJOPLOOKUP(((kobj_t)dev)->ops,device_resume);
331
	rc = ((device_resume_t *) _m)(dev);
332
	return (rc);
333
}
334
335
/** @brief Unique descriptor for the DEVICE_QUIESCE() method */
336
extern struct kobjop_desc device_quiesce_desc;
337
/** @brief A function implementing the DEVICE_QUIESCE() method */
338
typedef int device_quiesce_t(device_t dev);
339
/**
340
 * @brief This is called when the driver is asked to quiesce itself.
341
 *
342
 * The driver should arrange for the orderly shutdown of this device.
343
 * All further access to the device should be curtailed.  Soon there
344
 * will be a request to detach, but there won't necessarily be one.
345
 *
346
 * To include this method in a device driver, use a line like this
347
 * in the driver's method list:
348
 *
349
 * @code
350
 * 	KOBJMETHOD(device_quiesce, foo_quiesce)
351
 * @endcode
352
 *
353
 * @param dev		the device being quiesced
354
 *
355
 * @retval 0		success
356
 * @retval non-zero	an error occurred while attempting to quiesce the
357
 *                      device
358
 *
359
 * @see DEVICE_DETACH()
360
 */
361
362
static __inline int DEVICE_QUIESCE(device_t dev)
363
{
364
	kobjop_t _m;
365
	int rc;
366
	KOBJOPLOOKUP(((kobj_t)dev)->ops,device_quiesce);
367
	rc = ((device_quiesce_t *) _m)(dev);
368
	return (rc);
369
}
370
371
/** @brief Unique descriptor for the DEVICE_REGISTER() method */
372
extern struct kobjop_desc device_register_desc;
373
/** @brief A function implementing the DEVICE_REGISTER() method */
374
typedef void * device_register_t(device_t dev);
375
/**
376
 * @brief This is called when the driver is asked to register handlers.
377
 *
378
 *
379
 * To include this method in a device driver, use a line like this
380
 * in the driver's method list:
381
 *
382
 * @code
383
 * 	KOBJMETHOD(device_register, foo_register)
384
 * @endcode
385
 *
386
 * @param dev		the device for which handlers are being registered
387
 *
388
 * @retval NULL     method not implemented
389
 * @retval non-NULL	a pointer to implementation specific static driver state
390
 *
391
 */
392
393
static __inline void * DEVICE_REGISTER(device_t dev)
394
{
395
	kobjop_t _m;
396
	void * rc;
397
	KOBJOPLOOKUP(((kobj_t)dev)->ops,device_register);
398
	rc = ((device_register_t *) _m)(dev);
399
	return (rc);
400
}
401
402
#endif /* _device_if_h_ */
(-)drvGPIOIITK/gpio_if.h (+206 lines)
Line 0 Link Here
1
/*
2
 * This file is @generated automatically.
3
 * Do not modify anything in here by hand.
4
 *
5
 * Created from source file
6
 *   /usr/src/sys/dev/gpio/gpio_if.m
7
 * with
8
 *   makeobjops.awk
9
 *
10
 * See the source file for legal information
11
 */
12
13
14
#ifndef _gpio_if_h_
15
#define _gpio_if_h_
16
17
18
#include <dev/ofw/openfirm.h>
19
20
/** @brief Unique descriptor for the GPIO_GET_BUS() method */
21
extern struct kobjop_desc gpio_get_bus_desc;
22
/** @brief A function implementing the GPIO_GET_BUS() method */
23
typedef device_t gpio_get_bus_t(device_t dev);
24
25
static __inline device_t GPIO_GET_BUS(device_t dev)
26
{
27
	kobjop_t _m;
28
	device_t rc;
29
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_get_bus);
30
	rc = ((gpio_get_bus_t *) _m)(dev);
31
	return (rc);
32
}
33
34
/** @brief Unique descriptor for the GPIO_PIN_MAX() method */
35
extern struct kobjop_desc gpio_pin_max_desc;
36
/** @brief A function implementing the GPIO_PIN_MAX() method */
37
typedef int gpio_pin_max_t(device_t dev, int *maxpin);
38
39
static __inline int GPIO_PIN_MAX(device_t dev, int *maxpin)
40
{
41
	kobjop_t _m;
42
	int rc;
43
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_max);
44
	rc = ((gpio_pin_max_t *) _m)(dev, maxpin);
45
	return (rc);
46
}
47
48
/** @brief Unique descriptor for the GPIO_PIN_SET() method */
49
extern struct kobjop_desc gpio_pin_set_desc;
50
/** @brief A function implementing the GPIO_PIN_SET() method */
51
typedef int gpio_pin_set_t(device_t dev, uint32_t pin_num, uint32_t pin_value);
52
53
static __inline int GPIO_PIN_SET(device_t dev, uint32_t pin_num,
54
                                 uint32_t pin_value)
55
{
56
	kobjop_t _m;
57
	int rc;
58
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_set);
59
	rc = ((gpio_pin_set_t *) _m)(dev, pin_num, pin_value);
60
	return (rc);
61
}
62
63
/** @brief Unique descriptor for the GPIO_PIN_GET() method */
64
extern struct kobjop_desc gpio_pin_get_desc;
65
/** @brief A function implementing the GPIO_PIN_GET() method */
66
typedef int gpio_pin_get_t(device_t dev, uint32_t pin_num, uint32_t *pin_value);
67
68
static __inline int GPIO_PIN_GET(device_t dev, uint32_t pin_num,
69
                                 uint32_t *pin_value)
70
{
71
	kobjop_t _m;
72
	int rc;
73
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_get);
74
	rc = ((gpio_pin_get_t *) _m)(dev, pin_num, pin_value);
75
	return (rc);
76
}
77
78
/** @brief Unique descriptor for the GPIO_PIN_TOGGLE() method */
79
extern struct kobjop_desc gpio_pin_toggle_desc;
80
/** @brief A function implementing the GPIO_PIN_TOGGLE() method */
81
typedef int gpio_pin_toggle_t(device_t dev, uint32_t pin_num);
82
83
static __inline int GPIO_PIN_TOGGLE(device_t dev, uint32_t pin_num)
84
{
85
	kobjop_t _m;
86
	int rc;
87
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_toggle);
88
	rc = ((gpio_pin_toggle_t *) _m)(dev, pin_num);
89
	return (rc);
90
}
91
92
/** @brief Unique descriptor for the GPIO_PIN_GETCAPS() method */
93
extern struct kobjop_desc gpio_pin_getcaps_desc;
94
/** @brief A function implementing the GPIO_PIN_GETCAPS() method */
95
typedef int gpio_pin_getcaps_t(device_t dev, uint32_t pin_num, uint32_t *caps);
96
97
static __inline int GPIO_PIN_GETCAPS(device_t dev, uint32_t pin_num,
98
                                     uint32_t *caps)
99
{
100
	kobjop_t _m;
101
	int rc;
102
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_getcaps);
103
	rc = ((gpio_pin_getcaps_t *) _m)(dev, pin_num, caps);
104
	return (rc);
105
}
106
107
/** @brief Unique descriptor for the GPIO_PIN_GETFLAGS() method */
108
extern struct kobjop_desc gpio_pin_getflags_desc;
109
/** @brief A function implementing the GPIO_PIN_GETFLAGS() method */
110
typedef int gpio_pin_getflags_t(device_t dev, uint32_t pin_num,
111
                                uint32_t *flags);
112
113
static __inline int GPIO_PIN_GETFLAGS(device_t dev, uint32_t pin_num,
114
                                      uint32_t *flags)
115
{
116
	kobjop_t _m;
117
	int rc;
118
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_getflags);
119
	rc = ((gpio_pin_getflags_t *) _m)(dev, pin_num, flags);
120
	return (rc);
121
}
122
123
/** @brief Unique descriptor for the GPIO_PIN_GETNAME() method */
124
extern struct kobjop_desc gpio_pin_getname_desc;
125
/** @brief A function implementing the GPIO_PIN_GETNAME() method */
126
typedef int gpio_pin_getname_t(device_t dev, uint32_t pin_num, char *name);
127
128
static __inline int GPIO_PIN_GETNAME(device_t dev, uint32_t pin_num, char *name)
129
{
130
	kobjop_t _m;
131
	int rc;
132
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_getname);
133
	rc = ((gpio_pin_getname_t *) _m)(dev, pin_num, name);
134
	return (rc);
135
}
136
137
/** @brief Unique descriptor for the GPIO_PIN_SETFLAGS() method */
138
extern struct kobjop_desc gpio_pin_setflags_desc;
139
/** @brief A function implementing the GPIO_PIN_SETFLAGS() method */
140
typedef int gpio_pin_setflags_t(device_t dev, uint32_t pin_num, uint32_t flags);
141
142
static __inline int GPIO_PIN_SETFLAGS(device_t dev, uint32_t pin_num,
143
                                      uint32_t flags)
144
{
145
	kobjop_t _m;
146
	int rc;
147
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_setflags);
148
	rc = ((gpio_pin_setflags_t *) _m)(dev, pin_num, flags);
149
	return (rc);
150
}
151
152
/** @brief Unique descriptor for the GPIO_MAP_GPIOS() method */
153
extern struct kobjop_desc gpio_map_gpios_desc;
154
/** @brief A function implementing the GPIO_MAP_GPIOS() method */
155
typedef int gpio_map_gpios_t(device_t bus, phandle_t dev, phandle_t gparent,
156
                             int gcells, pcell_t *gpios, uint32_t *pin,
157
                             uint32_t *flags);
158
159
static __inline int GPIO_MAP_GPIOS(device_t bus, phandle_t dev,
160
                                   phandle_t gparent, int gcells,
161
                                   pcell_t *gpios, uint32_t *pin,
162
                                   uint32_t *flags)
163
{
164
	kobjop_t _m;
165
	int rc;
166
	KOBJOPLOOKUP(((kobj_t)bus)->ops,gpio_map_gpios);
167
	rc = ((gpio_map_gpios_t *) _m)(bus, dev, gparent, gcells, gpios, pin, flags);
168
	return (rc);
169
}
170
171
/** @brief Unique descriptor for the GPIO_PIN_ACCESS_32() method */
172
extern struct kobjop_desc gpio_pin_access_32_desc;
173
/** @brief A function implementing the GPIO_PIN_ACCESS_32() method */
174
typedef int gpio_pin_access_32_t(device_t dev, uint32_t first_pin,
175
                                 uint32_t clear_pins, uint32_t change_pins,
176
                                 uint32_t *orig_pins);
177
178
static __inline int GPIO_PIN_ACCESS_32(device_t dev, uint32_t first_pin,
179
                                       uint32_t clear_pins,
180
                                       uint32_t change_pins,
181
                                       uint32_t *orig_pins)
182
{
183
	kobjop_t _m;
184
	int rc;
185
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_access_32);
186
	rc = ((gpio_pin_access_32_t *) _m)(dev, first_pin, clear_pins, change_pins, orig_pins);
187
	return (rc);
188
}
189
190
/** @brief Unique descriptor for the GPIO_PIN_CONFIG_32() method */
191
extern struct kobjop_desc gpio_pin_config_32_desc;
192
/** @brief A function implementing the GPIO_PIN_CONFIG_32() method */
193
typedef int gpio_pin_config_32_t(device_t dev, uint32_t first_pin,
194
                                 uint32_t num_pins, uint32_t *pin_flags);
195
196
static __inline int GPIO_PIN_CONFIG_32(device_t dev, uint32_t first_pin,
197
                                       uint32_t num_pins, uint32_t *pin_flags)
198
{
199
	kobjop_t _m;
200
	int rc;
201
	KOBJOPLOOKUP(((kobj_t)dev)->ops,gpio_pin_config_32);
202
	rc = ((gpio_pin_config_32_t *) _m)(dev, first_pin, num_pins, pin_flags);
203
	return (rc);
204
}
205
206
#endif /* _gpio_if_h_ */
(-)drvGPIOIITK/gpioiitk.c (+454 lines)
Line 0 Link Here
1
/*-
2
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3
 *
4
 * Copyright (c) 2019 Oskar Holmlund.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 
16
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 *
26
 * GPIO input interrupt to kevent.
27
 *
28
 * DTS example check out BB-GPIOIITK.dts
29
 *
30
 * Inspired by GSoC 2018 User space interface for GPIO interrupts
31
 * by Christian Krämer
32
 *
33
 * $FreeBSD$
34
 */
35
36
#include <sys/cdefs.h>
37
__FBSDID("$FreeBSD$");
38
39
#include <sys/param.h>
40
#include <sys/module.h>
41
#include <sys/kernel.h>
42
#include <sys/systm.h>
43
#include <sys/conf.h>
44
#include <sys/uio.h>
45
#include <sys/bus.h>
46
#include <sys/mutex.h>
47
#include <sys/gpio.h>
48
#include <sys/event.h>
49
50
#include <dev/gpio/gpiobusvar.h>
51
#include <dev/fdt/fdt_common.h>
52
#include <dev/ofw/ofw_bus_subr.h>
53
#include <dev/ofw/openfirm.h>
54
55
#include "gpio_if.h"
56
#include "gpioiitk_ioctl.h"
57
58
#define GPIOIITK_LOCK(_sc)               mtx_lock(&(_sc)->sc_mtx)
59
#define GPIOIITK_UNLOCK(_sc)             mtx_unlock(&(_sc)->sc_mtx)
60
#define GPIOIITK_LOCK_INIT(_sc) \
61
        mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->sc_device), \
62
            "gpio_mux", MTX_DEF)
63
#define GPIOIITK_LOCK_DESTROY(_sc)       mtx_destroy(&_sc->sc_mtx);
64
#define GPIOIITK_ASSERT_LOCKED(_sc)      mtx_assert(&_sc->sc_mtx, MA_OWNED);
65
#define GPIOIITK_ASSERT_UNLOCKED(_sc)    mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);
66
67
/* Defines for the ofw_compat_data table */                                     
68
#define GPIOIITK		0x01                                            
69
#define GPIOIITK_END		0x00
70
71
static d_open_t         gpioiitk_open;
72
static d_close_t        gpioiitk_close;
73
static d_ioctl_t        gpioiitk_ioctl;
74
static d_kqfilter_t	gpioiitk_kqfilter;
75
76
static int		gpioiitk_kqread(struct knote*, long);
77
static void		gpioiitk_kqdetach(struct knote*);
78
static void		input_intr(void *);
79
static int		gpioiitk_detach(device_t);
80
81
static struct cdevsw gpioiitk_cdevsw = {
82
        .d_version =    D_VERSION,
83
        .d_open =       gpioiitk_open,
84
        .d_close =      gpioiitk_close,
85
        .d_ioctl =      gpioiitk_ioctl,
86
	.d_kqfilter =	gpioiitk_kqfilter,
87
        .d_name =       GPIOIITK_NAME
88
};
89
90
static struct filterops gpioiitk_read_filterops = {
91
	.f_isfd =	true,
92
	.f_attach =	NULL,
93
	.f_detach =	gpioiitk_kqdetach,
94
	.f_event =	gpioiitk_kqread,
95
	.f_touch =	NULL
96
};
97
98
/* compatible */
99
static struct ofw_compat_data compat_data[] = {
100
	{ "gpioiitk",		GPIOIITK },
101
        { NULL,			GPIOIITK_END },
102
};
103
104
#define MAX_INPUTS	10
105
struct gpio_input_softc;
106
107
struct gpio_input_pin {
108
	struct gpio_input_softc	*sc_parent;
109
110
	gpio_pin_t		sc_pin;
111
	int			sc_irid;
112
	struct resource		*sc_ires;
113
	void 			*sc_ihandler;
114
115
	uint16_t		sc_counter;
116
	bool			sc_state;
117
};
118
119
struct gpio_input_softc {
120
	struct mtx		sc_mtx;
121
	device_t		sc_device;
122
123
	struct gpio_input_pin	sc_inputs[MAX_INPUTS];
124
	uint8_t			sc_num_inputs;
125
	bool			sc_changed;
126
127
	/* Character device interface */
128
	struct cdev		*sc_cdev;
129
130
	/* Kernel events */
131
	struct knlist           sc_note;
132
};
133
134
/* --- Device methods --- */
135
static int
136
gpioiitk_probe(device_t dev)
137
{
138
	const struct ofw_compat_data *compatible;
139
140
        if (!ofw_bus_status_okay(dev))
141
                return (ENXIO);
142
143
        compatible = ofw_bus_search_compatible(dev, compat_data);
144
145
	switch (compatible->ocd_data) {
146
	case GPIOIITK_END:
147
		return (ENXIO);
148
	case GPIOIITK:
149
		device_set_desc(dev, "GPIO Input Interrupt To Kevent");
150
		break;
151
	}
152
153
        return (BUS_PROBE_DEFAULT);
154
}
155
156
static int
157
gpioiitk_attach(device_t dev)
158
{
159
        struct gpio_input_softc *sc;
160
	const struct ofw_compat_data *compatible;
161
	int unit, err, pincaps, idx;
162
	phandle_t node;
163
164
	sc = device_get_softc(dev);
165
	sc->sc_device = dev;
166
        GPIOIITK_LOCK_INIT(sc);
167
168
	knlist_init_mtx(&sc->sc_note, &sc->sc_mtx);
169
170
	/* Look at the dts again and grab the type */
171
        compatible = ofw_bus_search_compatible(sc->sc_device, compat_data);
172
173
	node = ofw_bus_get_node(sc->sc_device);
174
175
	for (idx = 0; idx < MAX_INPUTS; idx++) {
176
177
		/* ------ Get the pin ------ */
178
		err = gpio_pin_get_by_ofw_propidx(sc->sc_device, node,
179
			"input-gpios", idx, &sc->sc_inputs[idx].sc_pin);
180
		if (err != 0 && idx == 0) {
181
			/* Error at the first pin */
182
			/* something are actually wrong */
183
			/* probably no pins in DTS */
184
			device_printf(sc->sc_device, "inputs[%d]: err %d\n",
185
				idx, err);
186
			break;
187
		} else if (err != 0) {
188
			/* Error later on indicates the last pin are found */
189
			err = 0;
190
191
			/* sc_num_inputs are total number of pins
192
			   (not 0-index based) */
193
			sc->sc_num_inputs = idx;
194
			break;
195
		}
196
197
198
		/* Check the state of the gpio pin */
199
		err = GPIO_PIN_GETFLAGS(sc->sc_inputs[idx].sc_pin->dev,
200
			sc->sc_inputs[idx].sc_pin->pin, &pincaps);
201
		if (err != 0) {
202
			device_printf(dev, "Failed to get pin flags gpio[%d]\n",
203
				idx);
204
			break;
205
		}
206
207
 		/* Ensure the pin are in INPUT mode */
208
		if (!(pincaps & GPIO_PIN_INPUT)) {
209
			device_printf(dev, "pin[%x] IS NOT in input mode\n",
210
				idx);
211
			err = 1;
212
			break;
213
		}
214
215
		/* Allocate interrupt resource */
216
		/* Available options are:
217
		 * GPIO_INTR_EDGE_BOTH
218
		 * GPIO_INTR_EDGE_FALLING
219
		 * GPIO_INTR_EDGE_RISING
220
		 *
221
		 * Set this in DTS?
222
		 */
223
		sc->sc_inputs[idx].sc_ires = gpio_alloc_intr_resource(
224
			sc->sc_device, &sc->sc_inputs[idx].sc_irid, RF_ACTIVE,
225
			sc->sc_inputs[idx].sc_pin, GPIO_INTR_EDGE_BOTH);
226
		if (sc->sc_inputs[idx].sc_ires == NULL) {
227
			device_printf(sc->sc_device, "Cannot allocate IRQ\n");
228
			err = 1;
229
			break;
230
		}
231
232
		/* Attach to interrupt handler function */
233
		err = bus_setup_intr(sc->sc_device, sc->sc_inputs[idx].sc_ires,
234
			 INTR_TYPE_BIO | INTR_MPSAFE, NULL, input_intr,
235
			&sc->sc_inputs[idx], &sc->sc_inputs[idx].sc_ihandler);
236
		if (err != 0) {
237
			device_printf(sc->sc_device, "Unable to setup IRQ\n");
238
			break;
239
		}
240
241
		sc->sc_inputs[idx].sc_counter = 0;
242
		sc->sc_inputs[idx].sc_parent = sc;
243
		gpio_pin_is_active(sc->sc_inputs[idx].sc_pin,
244
			&sc->sc_inputs[idx].sc_state);
245
	}
246
247
	if (err != 0) {
248
		/* -- Free allocated resource -- */
249
		gpioiitk_detach(sc->sc_device);	
250
		return (ENXIO);
251
	}
252
253
	 /* -- Create device -- */
254
        unit = device_get_unit(sc->sc_device);
255
	sc->sc_cdev = make_dev(&gpioiitk_cdevsw, unit,
256
		UID_ROOT, GID_WHEEL, 0666,
257
		"gpioiitk_%d", unit);
258
	sc->sc_cdev->si_drv1 = sc;
259
260
        return (0);
261
}
262
263
static int
264
gpioiitk_detach(device_t dev)
265
{
266
        struct gpio_input_softc *sc;
267
	int idx;
268
269
        sc = device_get_softc(dev);
270
271
	if (sc->sc_cdev)
272
		destroy_dev(sc->sc_cdev);
273
274
	/* Free input IRQ handler and pins */
275
	for (idx = 0; idx < MAX_INPUTS; idx++) {
276
		if (sc->sc_inputs[idx].sc_ihandler) {
277
			bus_teardown_intr(sc->sc_device,
278
				sc->sc_inputs[idx].sc_ires,
279
				sc->sc_inputs[idx].sc_ihandler);
280
		}
281
		if (sc->sc_inputs[idx].sc_pin) {
282
			gpio_pin_release(sc->sc_inputs[idx].sc_pin);
283
		}
284
		if (sc->sc_inputs[idx].sc_ires) {
285
			bus_release_resource(sc->sc_device, SYS_RES_IRQ, 0,
286
				sc->sc_inputs[idx].sc_ires);
287
		}
288
	}
289
290
        KASSERT(mtx_initialized(&sc->sc_mtx), ("gpioiitk mtx not initialized"));
291
292
        GPIOIITK_LOCK_DESTROY(sc);
293
294
        return (0);
295
}
296
297
static phandle_t
298
gpioiitk_get_node(device_t bus, device_t dev)
299
{
300
        struct gpio_input_softc *sc;
301
        sc = device_get_softc(dev);
302
        return (ofw_bus_get_node(bus));
303
}
304
305
/*
306
 * Character device interface 
307
 */
308
309
static int
310
gpioiitk_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
311
{
312
	return 0;
313
}
314
315
static int
316
gpioiitk_close(struct cdev *dev, int fflags, int devtype, struct thread *td)
317
{
318
	return 0;
319
}
320
321
static int
322
gpioiitk_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
323
        struct thread *td)
324
{
325
        struct gpio_input_softc *sc = dev->si_drv1;
326
	uint32_t *INx;
327
	uint16_t *counter;
328
	uint8_t idx;
329
330
	GPIOIITK_LOCK(sc);
331
	switch (cmd)
332
	{
333
	case GPIOIITK_GET_COUNTER:
334
		counter = (uint16_t *)data;
335
		for (idx = 0; idx < sc->sc_num_inputs; idx++) {
336
			counter[idx] = sc->sc_inputs[idx].sc_counter;
337
			sc->sc_inputs[idx].sc_counter=0;
338
		}
339
		break;
340
341
	/* Get the cached state on all input pins */
342
	case GPIOIITK_GET_CACHE:
343
		INx = (uint32_t *) data;
344
		*INx = 0;
345
		for (idx = 0; idx < sc->sc_num_inputs; idx++) {
346
			*INx |= (uint32_t)(sc->sc_inputs[idx].sc_state << idx);
347
		}
348
		break;
349
350
	/* Refetch the input state from HW */
351
	case GPIOIITK_GET:
352
		INx = (uint32_t *) data;
353
		*INx = 0;
354
		for (idx = 0; idx < sc->sc_num_inputs; idx++) {
355
			gpio_pin_is_active(sc->sc_inputs[idx].sc_pin,
356
				&sc->sc_inputs[idx].sc_state);
357
			*INx |= (uint32_t)(sc->sc_inputs[idx].sc_state << idx);
358
		}
359
		break;
360
	}
361
        GPIOIITK_UNLOCK(sc);
362
363
	return 0;
364
}
365
366
/* Interrupt handler for input pin */
367
static void
368
input_intr(void *arg)
369
{
370
	struct gpio_input_pin *input = (struct gpio_input_pin *)arg;
371
372
	GPIOIITK_LOCK(input->sc_parent);
373
	gpio_pin_is_active(input->sc_pin, &input->sc_state);
374
	input->sc_parent->sc_changed = true;
375
	input->sc_counter++;
376
377
	KNOTE_LOCKED(&input->sc_parent->sc_note, 1);
378
	GPIOIITK_UNLOCK(input->sc_parent);
379
}
380
381
static int
382
gpioiitk_kqfilter(struct cdev *dev, struct knote *kn)
383
{
384
	struct gpio_input_softc *sc = dev->si_drv1;
385
386
	switch(kn->kn_filter) {
387
	case EVFILT_READ:
388
		kn->kn_fop = &gpioiitk_read_filterops;
389
		kn->kn_hook = (void *)sc;
390
		break;
391
	default:
392
		return (EOPNOTSUPP);
393
	}
394
395
	knlist_add(&sc->sc_note, kn, 0);
396
397
	return (0);
398
}
399
400
static int
401
gpioiitk_kqread(struct knote *kn, long hint)
402
{
403
	struct gpio_input_softc *sc = kn->kn_hook;
404
	int ret;
405
406
	kn->kn_data =
407
		(sc->sc_inputs[0].sc_state) |
408
		(sc->sc_inputs[1].sc_state<<1) |
409
		(sc->sc_inputs[2].sc_state<<2) |
410
		(sc->sc_inputs[3].sc_state<<3) |
411
		(sc->sc_inputs[4].sc_state<<4) |
412
		(sc->sc_inputs[5].sc_state<<5) |
413
		(sc->sc_inputs[6].sc_state<<6) |
414
		(sc->sc_inputs[7].sc_state<<7) |
415
		(sc->sc_inputs[8].sc_state<<8) |
416
		(sc->sc_inputs[9].sc_state<<9);
417
418
	ret = sc->sc_changed;
419
	if (hint == 0)
420
		sc->sc_changed = false;
421
422
	return (ret);
423
}
424
425
static void
426
gpioiitk_kqdetach(struct knote *kn)
427
{
428
	struct gpio_input_softc *sc = kn->kn_hook;
429
430
	knlist_remove(&sc->sc_note, kn, 0);
431
}
432
433
static device_method_t gpioiitk_methods[] = {
434
        /* Device interface */
435
        DEVMETHOD(device_probe,         gpioiitk_probe),
436
        DEVMETHOD(device_attach,        gpioiitk_attach),
437
        DEVMETHOD(device_detach,        gpioiitk_detach),
438
439
	/* ofw_bus interface */
440
	DEVMETHOD(ofw_bus_get_node,	gpioiitk_get_node),
441
442
        DEVMETHOD_END
443
};
444
445
static devclass_t gpioiitk_devclass;
446
447
DEFINE_CLASS_0(gpioiitk, gpioiitk_driver, gpioiitk_methods,
448
	sizeof(struct gpio_input_softc));
449
450
DRIVER_MODULE(gpioiitk, ofwbus, gpioiitk_driver, gpioiitk_devclass, NULL, NULL);
451
DRIVER_MODULE(gpioiitk, simplebus, gpioiitk_driver, gpioiitk_devclass,
452
	NULL, NULL);
453
MODULE_DEPEND(gpioiitk, gpiobus, 1, 1, 1);
454
(-)drvGPIOIITK/gpioiitk_ioctl.h (+38 lines)
Line 0 Link Here
1
/*-
2
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3
 * 
4
 * Copyright (c) 2019 Oskar Holmlund.
5
 * 
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 * 
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
16
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#ifndef __GPIOIITK_IOCTL__
28
#define __GPIOIITK_IOCTL__
29
30
#include <sys/stdint.h>
31
32
#define GPIOIITK_NAME             "gpioiitk"
33
34
#define GPIOIITK_GET		_IOR('b', 1, uint32_t)
35
#define GPIOIITK_GET_CACHE	_IOR('b', 2, uint32_t)
36
#define GPIOIITK_GET_COUNTER	_IOR('b', 3, uint16_t[10])
37
38
#endif /* __GPIOIITK_IOCTL__ */
(-)drvGPIOIITK/ofw_bus_if.h (+130 lines)
Line 0 Link Here
1
/*
2
 * This file is @generated automatically.
3
 * Do not modify anything in here by hand.
4
 *
5
 * Created from source file
6
 *   /usr/src/sys/dev/ofw/ofw_bus_if.m
7
 * with
8
 *   makeobjops.awk
9
 *
10
 * See the source file for legal information
11
 */
12
13
14
#ifndef _ofw_bus_if_h_
15
#define _ofw_bus_if_h_
16
17
18
struct ofw_bus_devinfo {
19
	phandle_t	obd_node;
20
	char		*obd_compat;
21
	char		*obd_model;
22
	char		*obd_name;
23
	char		*obd_type;
24
	char		*obd_status;
25
};
26
27
/** @brief Unique descriptor for the OFW_BUS_GET_DEVINFO() method */
28
extern struct kobjop_desc ofw_bus_get_devinfo_desc;
29
/** @brief A function implementing the OFW_BUS_GET_DEVINFO() method */
30
typedef const struct ofw_bus_devinfo * ofw_bus_get_devinfo_t(device_t bus,
31
                                                             device_t dev);
32
33
static __inline const struct ofw_bus_devinfo * OFW_BUS_GET_DEVINFO(device_t bus,
34
                                                                   device_t dev)
35
{
36
	kobjop_t _m;
37
	const struct ofw_bus_devinfo * rc;
38
	KOBJOPLOOKUP(((kobj_t)bus)->ops,ofw_bus_get_devinfo);
39
	rc = ((ofw_bus_get_devinfo_t *) _m)(bus, dev);
40
	return (rc);
41
}
42
43
/** @brief Unique descriptor for the OFW_BUS_GET_COMPAT() method */
44
extern struct kobjop_desc ofw_bus_get_compat_desc;
45
/** @brief A function implementing the OFW_BUS_GET_COMPAT() method */
46
typedef const char * ofw_bus_get_compat_t(device_t bus, device_t dev);
47
48
static __inline const char * OFW_BUS_GET_COMPAT(device_t bus, device_t dev)
49
{
50
	kobjop_t _m;
51
	const char * rc;
52
	KOBJOPLOOKUP(((kobj_t)bus)->ops,ofw_bus_get_compat);
53
	rc = ((ofw_bus_get_compat_t *) _m)(bus, dev);
54
	return (rc);
55
}
56
57
/** @brief Unique descriptor for the OFW_BUS_GET_MODEL() method */
58
extern struct kobjop_desc ofw_bus_get_model_desc;
59
/** @brief A function implementing the OFW_BUS_GET_MODEL() method */
60
typedef const char * ofw_bus_get_model_t(device_t bus, device_t dev);
61
62
static __inline const char * OFW_BUS_GET_MODEL(device_t bus, device_t dev)
63
{
64
	kobjop_t _m;
65
	const char * rc;
66
	KOBJOPLOOKUP(((kobj_t)bus)->ops,ofw_bus_get_model);
67
	rc = ((ofw_bus_get_model_t *) _m)(bus, dev);
68
	return (rc);
69
}
70
71
/** @brief Unique descriptor for the OFW_BUS_GET_NAME() method */
72
extern struct kobjop_desc ofw_bus_get_name_desc;
73
/** @brief A function implementing the OFW_BUS_GET_NAME() method */
74
typedef const char * ofw_bus_get_name_t(device_t bus, device_t dev);
75
76
static __inline const char * OFW_BUS_GET_NAME(device_t bus, device_t dev)
77
{
78
	kobjop_t _m;
79
	const char * rc;
80
	KOBJOPLOOKUP(((kobj_t)bus)->ops,ofw_bus_get_name);
81
	rc = ((ofw_bus_get_name_t *) _m)(bus, dev);
82
	return (rc);
83
}
84
85
/** @brief Unique descriptor for the OFW_BUS_GET_NODE() method */
86
extern struct kobjop_desc ofw_bus_get_node_desc;
87
/** @brief A function implementing the OFW_BUS_GET_NODE() method */
88
typedef phandle_t ofw_bus_get_node_t(device_t bus, device_t dev);
89
90
static __inline phandle_t OFW_BUS_GET_NODE(device_t bus, device_t dev)
91
{
92
	kobjop_t _m;
93
	phandle_t rc;
94
	KOBJOPLOOKUP(((kobj_t)bus)->ops,ofw_bus_get_node);
95
	rc = ((ofw_bus_get_node_t *) _m)(bus, dev);
96
	return (rc);
97
}
98
99
/** @brief Unique descriptor for the OFW_BUS_GET_TYPE() method */
100
extern struct kobjop_desc ofw_bus_get_type_desc;
101
/** @brief A function implementing the OFW_BUS_GET_TYPE() method */
102
typedef const char * ofw_bus_get_type_t(device_t bus, device_t dev);
103
104
static __inline const char * OFW_BUS_GET_TYPE(device_t bus, device_t dev)
105
{
106
	kobjop_t _m;
107
	const char * rc;
108
	KOBJOPLOOKUP(((kobj_t)bus)->ops,ofw_bus_get_type);
109
	rc = ((ofw_bus_get_type_t *) _m)(bus, dev);
110
	return (rc);
111
}
112
113
/** @brief Unique descriptor for the OFW_BUS_MAP_INTR() method */
114
extern struct kobjop_desc ofw_bus_map_intr_desc;
115
/** @brief A function implementing the OFW_BUS_MAP_INTR() method */
116
typedef int ofw_bus_map_intr_t(device_t bus, device_t dev, phandle_t iparent,
117
                               int icells, pcell_t *interrupt);
118
119
static __inline int OFW_BUS_MAP_INTR(device_t bus, device_t dev,
120
                                     phandle_t iparent, int icells,
121
                                     pcell_t *interrupt)
122
{
123
	kobjop_t _m;
124
	int rc;
125
	KOBJOPLOOKUP(((kobj_t)bus)->ops,ofw_bus_map_intr);
126
	rc = ((ofw_bus_map_intr_t *) _m)(bus, dev, iparent, icells, interrupt);
127
	return (rc);
128
}
129
130
#endif /* _ofw_bus_if_h_ */
(-)drvGPIOIITK/opt_platform.h (+2 lines)
Line 0 Link Here
1
#define FDT 1
2
#define EFI 1
(-)drvGPIOIITK/test.c (+94 lines)
Line 0 Link Here
1
#include <stdio.h>
2
#include <fcntl.h>
3
#include <unistd.h>
4
#include <stdlib.h>
5
#include <string.h>
6
#include <errno.h>
7
#include <err.h>
8
#include <inttypes.h>
9
10
#include <sys/ioctl.h>
11
#include <sys/types.h>
12
#include <sys/select.h>
13
#include <sys/event.h>
14
15
#include "gpioiitk_ioctl.h"
16
17
int main(int argc, char **argv) {
18
19
	struct kevent event[1];
20
	struct kevent tevent[1];
21
	int kq = -1;
22
	int nev = -1;
23
	struct timespec tv;
24
	struct timespec *tv_ptr;
25
	int res;
26
27
	tv.tv_sec = 2;
28
	tv.tv_nsec = 0;
29
	tv_ptr = &tv;
30
31
	uint32_t status;
32
	uint16_t counters[10];
33
        int fd,ret, loop;
34
	char device[32];
35
	snprintf(device, sizeof(device), "/dev/gpioiitk_%d", 0);
36
37
        fd = open(device, O_RDONLY);
38
        if (fd < 0) {
39
		printf("Failed to open device\n");
40
                return (1);
41
	}
42
43
	ret = ioctl(fd, GPIOIITK_GET, &status);
44
	if (ret < 0) {
45
		close(fd);
46
		printf("ioctl(GPIOIITK_GET)\n");
47
		return (1);
48
	}
49
50
	printf("status: %x\n", status);
51
52
	ret = ioctl(fd, GPIOIITK_GET_COUNTER, counters);
53
	if (ret < 0) {
54
		close(fd);
55
		printf("ioctl(GPIOIITK_GET_COUNTER)\n");
56
		return (1);
57
	}
58
	printf("counters[0]: %d\n", counters[0]);
59
	printf("counters[1]: %d\n", counters[1]);
60
	printf("counters[2]: %d\n", counters[2]);
61
62
	kq = kqueue();
63
	if (kq == -1) {
64
		close(fd);
65
		printf("kqueue()");
66
		return (1);
67
	}
68
69
	EV_SET(&event[0], fd, EVFILT_READ, EV_ADD, 0, 0, NULL);
70
	nev = kevent(kq, event, 1, NULL, 0, NULL);
71
	if (nev == -1) {
72
		printf("kevent()");
73
		close(fd);
74
		return (1);
75
	}
76
77
	while (1) {
78
		nev = kevent(kq, NULL, 0, tevent, 1, tv_ptr);
79
		if (nev == -1) {
80
			printf("kevent()\n");
81
			break;
82
		} else if (nev > 0) {
83
			printf("keveturned %i events (flags: %d data %" PRIu64 ")\n",
84
				 nev, tevent[0].flags, tevent[0].data);
85
			if (tevent[0].flags & EV_EOF) {
86
				printf("Recieved EV_EOF\n");
87
				break;
88
			}
89
		}
90
	}
91
92
	close(fd);
93
	return (0);
94
}

Return to bug 251390