2 * Copyright 2004-2008, Haiku, Inc. All RightsReserved.
3 * Copyright 2002/03, Thomas Kurschel. All rights reserved.
5 * Distributed under the terms of the MIT License.
9 Controllers use this interface to interact with bus manager.
13 #include "scsi_internal.h"
21 /** new scsi controller added
22 * in return, we register a new scsi bus node and let its fixed
23 * consumer (the SCSI device layer) automatically scan it for devices
27 scsi_controller_added(device_node
*parent
)
29 const char *controller_name
;
34 if (pnp
->get_attr_string(parent
, SCSI_DESCRIPTION_CONTROLLER_NAME
,
35 &controller_name
, false) != B_OK
) {
36 dprintf("scsi: ignored controller - controller name missing\n");
40 pathID
= pnp
->create_id(SCSI_PATHID_GENERATOR
);
42 dprintf("scsi: Cannot register SCSI controller %s - out of path IDs\n",
48 device_attr attrs
[] = {
49 // remember who we are
50 // (could use the controller name, but probably some software would choke)
51 // TODO create_id() generates a 32 bit ranged integer but we need only 8 bits
52 { SCSI_BUS_PATH_ID_ITEM
, B_UINT8_TYPE
, { ui8
: (uint8
)pathID
}},
54 // tell PnP manager to clean up ID
55 // { PNP_MANAGER_ID_GENERATOR, B_STRING_TYPE, { string: SCSI_PATHID_GENERATOR }},
56 // { PNP_MANAGER_AUTO_ID, B_UINT32_TYPE, { ui32: path_id }},
60 return pnp
->register_node(parent
, SCSI_BUS_MODULE_NAME
, attrs
, NULL
,
67 scsi_controller_init(device_node
*node
, void **_cookie
)
75 scsi_controller_register_raw_device(void *_cookie
)
77 device_node
*node
= (device_node
*)_cookie
;
83 // TODO: this seems to cause a crash in some configurations, and needs to be investigated!
84 // see bug #389 and #393.
85 // TODO: check if the above is still true
86 if (pnp
->get_attr_uint32(node
, "ide/channel_id", &channel
, true) == B_OK
) {
87 // this is actually an IDE device, we don't need to publish
88 // a bus device for those
92 pnp
->get_attr_uint8(node
, SCSI_BUS_PATH_ID_ITEM
, &pathID
, false);
94 // put that on heap to not overflow the limited kernel stack
95 name
= (char*)malloc(PATH_MAX
+ 1);
99 snprintf(name
, PATH_MAX
+ 1, "bus/scsi/%d/bus_raw", pathID
);
101 return pnp
->publish_device(node
, name
, SCSI_BUS_RAW_MODULE_NAME
);
106 std_ops(int32 op
, ...)
110 case B_MODULE_UNINIT
:
119 scsi_for_sim_interface scsi_for_sim_module
=
123 SCSI_FOR_SIM_MODULE_NAME
,
128 NULL
, // supported devices
129 scsi_controller_added
,
130 scsi_controller_init
,
132 scsi_controller_register_raw_device
,
137 scsi_requeue_request
,
138 scsi_resubmit_request
,
139 scsi_request_finished
,
151 scsi_cont_send_device