xref: /haiku/src/tests/system/kernel/device_manager/playground/specific_video_driver.cpp (revision 079eccf655ba39812b421ae1b87a727d41b50354)
1 /*
2  * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "bus.h"
8 
9 #include <KernelExport.h>
10 #include <PCI.h>
11 
12 
13 #define DRIVER_MODULE_NAME "drivers/graphics/specific_driver/driver_v1"
14 #define DRIVER_DEVICE_MODULE_NAME "drivers/graphics/specific_driver/device_v1"
15 
16 
17 //	#pragma mark - driver
18 
19 
20 static float
21 supports_device(device_node *parent)
22 {
23 	bus_for_driver_module_info* module;
24 	void* data;
25 	gDeviceManager->get_driver(parent, (driver_module_info**)&module, &data);
26 
27 	if (strcmp(module->info.info.name, BUS_FOR_DRIVER_NAME))
28 		return -1;
29 
30 	bus_info info;
31 	if (module->get_bus_info(data, &info) == B_OK
32 		&& info.vendor_id == 0x1001
33 		&& info.device_id == 0x0002)
34 		return 0.8;
35 
36 	return 0.0;
37 }
38 
39 
40 static status_t
41 register_device(device_node *parent)
42 {
43 	return gDeviceManager->register_node(parent, DRIVER_MODULE_NAME, NULL,
44 		NULL, NULL);
45 }
46 
47 
48 static status_t
49 init_driver(device_node *node, void **_cookie)
50 {
51 	*_cookie = node;
52 	return B_OK;
53 }
54 
55 
56 static void
57 uninit_driver(void* cookie)
58 {
59 }
60 
61 
62 static status_t
63 register_child_devices(void* cookie)
64 {
65 	device_node* node = (device_node*)cookie;
66 
67 	gDeviceManager->publish_device(node, "graphics/specific/0",
68 		DRIVER_DEVICE_MODULE_NAME);
69 	return B_OK;
70 }
71 
72 
73 static void
74 device_removed(void* cookie)
75 {
76 }
77 
78 
79 //	#pragma mark - device
80 
81 
82 static status_t
83 init_device(void* driverCookie, void** _deviceCookie)
84 {
85 	// called once before one or several open() calls
86 	return B_OK;
87 }
88 
89 
90 static void
91 uninit_device(void* deviceCookie)
92 {
93 	// supposed to free deviceCookie, called when the last reference to
94 	// the device is closed
95 }
96 
97 
98 static status_t
99 device_open(void* deviceCookie, int openMode, void** _cookie)
100 {
101 	// deviceCookie is an object attached to the published device
102 	return B_ERROR;
103 }
104 
105 
106 static status_t
107 device_close(void* cookie)
108 {
109 	return B_ERROR;
110 }
111 
112 
113 static status_t
114 device_free(void* cookie)
115 {
116 	return B_ERROR;
117 }
118 
119 
120 static status_t
121 device_read(void* cookie, off_t pos, void* buffer, size_t* _length)
122 {
123 	return B_ERROR;
124 }
125 
126 
127 static status_t
128 device_write(void* cookie, off_t pos, const void* buffer, size_t* _length)
129 {
130 	return B_ERROR;
131 }
132 
133 
134 static status_t
135 device_ioctl(void* cookie, int32 op, void* buffer, size_t length)
136 {
137 	return B_ERROR;
138 }
139 
140 
141 static status_t
142 device_io(void* cookie, io_request* request)
143 {
144 	// new function to deal with I/O requests directly.
145 	return B_ERROR;
146 }
147 
148 
149 //	#pragma mark -
150 
151 
152 struct driver_module_info gSpecificVideoDriverModuleInfo = {
153 	{
154 		DRIVER_MODULE_NAME,
155 		0,
156 		NULL,
157 	},
158 
159 	supports_device,
160 	register_device,
161 	init_driver,
162 	uninit_driver,
163 	register_child_devices,
164 	NULL,
165 	device_removed,
166 };
167 
168 struct device_module_info gSpecificVideoDeviceModuleInfo = {
169 	{
170 		DRIVER_DEVICE_MODULE_NAME,
171 		0,
172 		NULL,
173 	},
174 
175 	init_device,
176 	uninit_device,
177 	NULL,	// device_removed
178 
179 	device_open,
180 	device_close,
181 	device_free,
182 	device_read,
183 	device_write,
184 	device_ioctl,
185 	device_io,
186 };
187