1/*
2 * Copyright (c) 2007 Marcus Overhagen <marcus@overhagen.de>
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify,
8 * merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#include <KernelExport.h>
26#include <Drivers.h>
27#include <Errors.h>
28
29int32 			api_version = B_CUR_DRIVER_API_VERSION;
30static int32	sOpenMask;
31
32status_t
33init_hardware(void)
34{
35	dprintf("test: init_hardware\n");
36	return B_OK;
37}
38
39
40status_t
41init_driver(void)
42{
43	dprintf("test: init_driver\n");
44	return B_OK;
45}
46
47
48void
49uninit_driver(void)
50{
51	dprintf("test: uninit_driver\n");
52}
53
54
55static status_t
56driver_open(const char *name, uint32 flags, void** _cookie)
57{
58	dprintf("test: open\n");
59
60	if (atomic_or(&sOpenMask, 1)) {
61		dprintf("test: open, BUSY!\n");
62		return B_BUSY;
63	}
64
65	dprintf("test: open, success\n");
66	return B_OK;
67}
68
69
70static status_t
71driver_close(void* cookie)
72{
73	dprintf("test: close enter\n");
74	snooze(200000);
75	dprintf("test: close leave\n");
76	return B_OK;
77}
78
79
80static status_t
81driver_free(void* cookie)
82{
83	dprintf("test: free\n");
84	atomic_and(&sOpenMask, ~1);
85	return B_OK;
86}
87
88
89static status_t
90driver_read(void* cookie, off_t position, void *buf, size_t* num_bytes)
91{
92	dprintf("test: read\n");
93	*num_bytes = 0; // nothing to read
94	return B_ERROR;
95}
96
97
98static status_t
99driver_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes)
100{
101	dprintf("test: write\n");
102	snooze(1000000);	// 1s
103	*num_bytes = 1;		// pretend 1 byte was written
104	return B_OK;
105}
106
107
108static status_t
109driver_control(void *cookie, uint32 op, void *arg, size_t len)
110{
111	dprintf("test: control\n");
112	return B_ERROR;
113}
114
115
116const char**
117publish_devices(void)
118{
119	static const char *names[] = {"misc/test/1", NULL};
120	dprintf("test: publish_devices\n");
121	return names;
122}
123
124
125device_hooks*
126find_device(const char* name)
127{
128	static device_hooks hooks = {
129		driver_open,
130		driver_close,
131		driver_free,
132		driver_control,
133		driver_read,
134		driver_write,
135	};
136	dprintf("test: find_device\n");
137	return &hooks;
138}
139
140