1/*
2 * Copyright 2002-04, Thomas Kurschel. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7//!	Devfs entry for raw bus access.
8
9
10#include "scsi_internal.h"
11
12#include <stdlib.h>
13#include <stdio.h>
14#include <string.h>
15
16#include <device/scsi_bus_raw_driver.h>
17
18
19// info about bus
20// (used both as bus cookie and file handle cookie)
21typedef struct bus_raw_info {
22	scsi_bus_interface *interface;
23	scsi_bus cookie;
24	device_node *node;
25} bus_raw_info;
26
27
28static status_t
29scsi_bus_raw_init(void *driverCookie, void **_cookie)
30{
31	device_node *node = (device_node *)driverCookie;
32	device_node *parent;
33	bus_raw_info *bus;
34
35	bus = (bus_raw_info*)malloc(sizeof(*bus));
36	if (bus == NULL)
37		return B_NO_MEMORY;
38
39	parent = pnp->get_parent_node(node);
40	pnp->get_driver(parent,
41		(driver_module_info **)&bus->interface, (void **)&bus->cookie);
42	pnp->put_node(parent);
43
44	bus->node = node;
45
46	*_cookie = bus;
47	return B_OK;
48}
49
50
51static void
52scsi_bus_raw_uninit(void *bus)
53{
54	free(bus);
55}
56
57
58static status_t
59scsi_bus_raw_open(void *bus, const char *path, int openMode,
60	void **handle_cookie)
61{
62	*handle_cookie = bus;
63	return B_OK;
64}
65
66
67static status_t
68scsi_bus_raw_close(void *cookie)
69{
70	return B_OK;
71}
72
73
74static status_t
75scsi_bus_raw_free(void *cookie)
76{
77	return B_OK;
78}
79
80
81static status_t
82scsi_bus_raw_control(void *_cookie, uint32 op, void *data, size_t length)
83{
84	bus_raw_info *bus = (bus_raw_info*)_cookie;
85
86	switch (op) {
87		case B_SCSI_BUS_RAW_RESET:
88			return bus->interface->reset_bus(bus->cookie);
89
90		case B_SCSI_BUS_RAW_PATH_INQUIRY:
91			return bus->interface->path_inquiry(bus->cookie,
92				(scsi_path_inquiry*)data);
93	}
94
95	return B_ERROR;
96}
97
98
99static status_t
100scsi_bus_raw_read(void *cookie, off_t position, void *data,
101	size_t *numBytes)
102{
103	*numBytes = 0;
104	return B_ERROR;
105}
106
107
108static status_t
109scsi_bus_raw_write(void *cookie, off_t position,
110	const void *data, size_t *numBytes)
111{
112	*numBytes = 0;
113	return B_ERROR;
114}
115
116
117struct device_module_info gSCSIBusRawModule = {
118	{
119		SCSI_BUS_RAW_MODULE_NAME,
120		0,
121		NULL
122	},
123
124	scsi_bus_raw_init,
125	scsi_bus_raw_uninit,
126	NULL,	// removed
127
128	scsi_bus_raw_open,
129	scsi_bus_raw_close,
130	scsi_bus_raw_free,
131	scsi_bus_raw_read,
132	scsi_bus_raw_write,
133	NULL,	// io
134	scsi_bus_raw_control,
135	NULL,	// select
136	NULL	// deselect
137};
138