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