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/generic_driver/driver_v1"
14#define DRIVER_DEVICE_MODULE_NAME "drivers/graphics/generic_driver/device_v1"
15
16
17//	#pragma mark - driver
18
19
20static float
21supports_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	uint16 type;
31	if (gDeviceManager->get_attr_uint16(parent, B_DEVICE_TYPE, &type, false)
32			!= B_OK)
33		return -1;
34
35	if (type == PCI_display)
36		return 0.1;
37
38	return 0.0;
39}
40
41
42static status_t
43register_device(device_node* parent)
44{
45	return gDeviceManager->register_node(parent, DRIVER_MODULE_NAME, NULL,
46		NULL, NULL);
47}
48
49
50static status_t
51init_driver(device_node* node, void** _cookie)
52{
53	*_cookie = node;
54	return B_OK;
55}
56
57
58static void
59uninit_driver(void* cookie)
60{
61}
62
63
64static status_t
65register_child_devices(void* cookie)
66{
67	device_node* node = (device_node*)cookie;
68
69	gDeviceManager->publish_device(node, "graphics/generic/0",
70		DRIVER_DEVICE_MODULE_NAME);
71	return B_OK;
72}
73
74
75static void
76device_removed(device_node* node)
77{
78}
79
80
81//	#pragma mark - device
82
83
84static status_t
85init_device(void* driverCookie, void** _deviceCookie)
86{
87	// called once before one or several open() calls
88	return B_OK;
89}
90
91
92static void
93uninit_device(void* deviceCookie)
94{
95	// supposed to free deviceCookie, called when the last reference to
96	// the device is closed
97}
98
99
100static status_t
101device_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
108static status_t
109device_close(void* cookie)
110{
111	return B_ERROR;
112}
113
114
115static status_t
116device_free(void* cookie)
117{
118	return B_ERROR;
119}
120
121
122static status_t
123device_read(void* cookie, off_t pos, void* buffer, size_t* _length)
124{
125	return B_ERROR;
126}
127
128
129static status_t
130device_write(void* cookie, off_t pos, const void* buffer, size_t* _length)
131{
132	return B_ERROR;
133}
134
135
136static status_t
137device_ioctl(void* cookie, int32 op, void* buffer, size_t length)
138{
139	return B_ERROR;
140}
141
142
143static status_t
144device_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
154struct driver_module_info gGenericVideoDriverModuleInfo = {
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
170struct device_module_info gGenericVideoDeviceModuleInfo = {
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