2 * Copyright 2009, Michael Lotz, mmlr@mlotz.ch.
3 * Copyright 2008, Marcus Overhagen.
4 * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de.
5 * Copyright 2002-2003, Thomas Kurschel.
7 * Distributed under the terms of the MIT License.
10 #include "ATAPrivate.h"
13 scsi_for_sim_interface
*gSCSIModule
= NULL
;
14 device_manager_info
*gDeviceManager
= NULL
;
18 ata_sim_init_bus(device_node
*node
, void **cookie
)
20 ATAChannel
*channel
= new(std::nothrow
) ATAChannel(node
);
24 status_t result
= channel
->InitCheck();
26 TRACE_ERROR("failed to set up ata channel object\n");
36 ata_sim_uninit_bus(void *cookie
)
38 ATAChannel
*channel
= (ATAChannel
*)cookie
;
44 ata_sim_bus_removed(void *cookie
)
46 ATAChannel
*channel
= (ATAChannel
*)cookie
;
47 if (channel
->Bus() != NULL
) {
48 gSCSIModule
->block_bus(channel
->Bus());
49 channel
->SetBus(NULL
);
55 ata_sim_set_scsi_bus(scsi_sim_cookie cookie
, scsi_bus bus
)
57 ATAChannel
*channel
= (ATAChannel
*)cookie
;
64 ata_sim_scsi_io(scsi_sim_cookie cookie
, scsi_ccb
*ccb
)
66 ATAChannel
*channel
= (ATAChannel
*)cookie
;
67 if (channel
->Bus() == NULL
) {
68 ccb
->subsys_status
= SCSI_NO_HBA
;
69 gSCSIModule
->finished(ccb
, 1);
73 if (channel
->ExecuteIO(ccb
) == B_BUSY
)
74 gSCSIModule
->requeue(ccb
, true);
79 ata_sim_abort(scsi_sim_cookie cookie
, scsi_ccb
*ccb
)
81 ATAChannel
*channel
= (ATAChannel
*)cookie
;
82 if (channel
->Bus() == NULL
)
85 // aborting individual commands is not possible
91 ata_sim_reset_device(scsi_sim_cookie cookie
, uchar targetId
, uchar targetLun
)
93 ATAChannel
*channel
= (ATAChannel
*)cookie
;
94 if (channel
->Bus() == NULL
)
98 return SCSI_REQ_INVALID
;
103 ata_sim_term_io(scsi_sim_cookie cookie
, scsi_ccb
*ccb
)
105 ATAChannel
*channel
= (ATAChannel
*)cookie
;
106 if (channel
->Bus() == NULL
)
109 // we don't terminate commands, ignore
115 ata_sim_path_inquiry(scsi_sim_cookie cookie
, scsi_path_inquiry
*info
)
117 ATAChannel
*channel
= (ATAChannel
*)cookie
;
118 if (channel
->Bus() == NULL
)
121 channel
->PathInquiry(info
);
127 ata_sim_rescan_bus(scsi_sim_cookie cookie
)
135 ata_sim_reset_bus(scsi_sim_cookie cookie
)
137 ATAChannel
*channel
= (ATAChannel
*)cookie
;
138 if (channel
->Bus() == NULL
)
142 panic("asking for trouble");
148 ata_sim_get_restrictions(scsi_sim_cookie cookie
, uchar targetID
,
149 bool *isATAPI
, bool *noAutoSense
, uint32
*maxBlocks
)
151 ATAChannel
*channel
= (ATAChannel
*)cookie
;
152 channel
->GetRestrictions(targetID
, isATAPI
, noAutoSense
, maxBlocks
);
157 ata_sim_control(scsi_sim_cookie cookie
, uchar targetID
, uint32 op
, void *buffer
,
160 ATAChannel
*channel
= (ATAChannel
*)cookie
;
161 return channel
->Control(targetID
, op
, buffer
, length
);
166 ata_channel_added(device_node
*parent
)
168 const char *controllerName
;
169 if (gDeviceManager
->get_attr_string(parent
,
170 ATA_CONTROLLER_CONTROLLER_NAME_ITEM
, &controllerName
, true) != B_OK
) {
171 TRACE_ERROR("controller name missing\n");
175 int32 channelID
= gDeviceManager
->create_id(ATA_CHANNEL_ID_GENERATOR
);
177 TRACE_ERROR("out of channel ids\n");
181 device_attr attributes
[] = {
183 B_DEVICE_FIXED_CHILD
, B_STRING_TYPE
,
184 { string
: SCSI_FOR_SIM_MODULE_NAME
}
188 SCSI_DESCRIPTION_CONTROLLER_NAME
, B_STRING_TYPE
,
189 { string
: controllerName
}
192 // maximum number of blocks per transmission:
193 // - ATAPI uses packets, i.e. normal SCSI limits apply
194 // but I'm not sure about controller restrictions
195 // - ATA allows up to 256 blocks for LBA28 and 65535 for LBA48
196 // to fix specific drive bugs use ATAChannel::GetRestrictions()
197 { B_DMA_MAX_TRANSFER_BLOCKS
, B_UINT32_TYPE
, { ui32
: 0xffff } },
198 { ATA_CHANNEL_ID_ITEM
, B_UINT32_TYPE
, { ui32
: (uint32
)channelID
} },
202 return gDeviceManager
->register_node(parent
, ATA_SIM_MODULE_NAME
,
203 attributes
, NULL
, NULL
);
208 ata_interrupt_handler(void *cookie
, uint8 status
)
210 ATAChannel
*channel
= (ATAChannel
*)cookie
;
211 return channel
->Interrupt(status
);
216 std_ops(int32 op
, ...)
220 case B_MODULE_UNINIT
:
231 scsi_sim_interface ata_sim_module
= {
239 NULL
, // supported devices
240 NULL
, // register node
243 NULL
, // register child devices
250 ata_sim_set_scsi_bus
,
253 ata_sim_reset_device
,
255 ata_sim_path_inquiry
,
258 ata_sim_get_restrictions
,
262 ata_for_controller_interface ata_for_controller_module
= {
265 ATA_FOR_CONTROLLER_MODULE_NAME
,
270 NULL
, // supported devices
277 ata_interrupt_handler
281 module_dependency module_dependencies
[] = {
282 { SCSI_FOR_SIM_MODULE_NAME
, (module_info
**)&gSCSIModule
},
283 { B_DEVICE_MANAGER_MODULE_NAME
, (module_info
**)&gDeviceManager
},
287 module_info
*modules
[] = {
288 (module_info
*)&ata_for_controller_module
,
289 (module_info
*)&ata_sim_module
,