2 * Copyright 2007-2009, Marcus Overhagen. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 #include "ahci_controller.h"
8 #include <KernelExport.h>
12 #define TRACE(a...) dprintf("ahci: " a)
13 //#define FLOW(a...) dprintf("ahci: " a)
17 // #pragma mark - SIM module interface
21 ahci_set_scsi_bus(scsi_sim_cookie cookie
, scsi_bus bus
)
28 ahci_scsi_io(scsi_sim_cookie cookie
, scsi_ccb
*request
)
30 FLOW("ahci_scsi_io, cookie %p, path_id %u, target_id %u, target_lun %u\n",
31 cookie
, request
->path_id
, request
->target_id
, request
->target_lun
);
32 static_cast<AHCIController
*>(cookie
)->ExecuteRequest(request
);
38 ahci_abort_io(scsi_sim_cookie cookie
, scsi_ccb
*request
)
40 TRACE("ahci_abort_io, cookie %p\n", cookie
);
41 return static_cast<AHCIController
*>(cookie
)->AbortRequest(request
);
46 ahci_reset_device(scsi_sim_cookie cookie
, uchar targetID
, uchar targetLUN
)
48 TRACE("ahci_reset_device, cookie %p\n", cookie
);
49 return static_cast<AHCIController
*>(cookie
)->ResetDevice(targetID
, targetLUN
);
55 ahci_terminate_io(scsi_sim_cookie cookie
, scsi_ccb
*request
)
57 TRACE("ahci_terminate_io, cookie %p\n", cookie
);
58 return static_cast<AHCIController
*>(cookie
)->TerminateRequest(request
);
62 //! get information about bus
64 ahci_path_inquiry(scsi_sim_cookie cookie
, scsi_path_inquiry
*info
)
66 TRACE("ahci_path_inquiry, cookie %p\n", cookie
);
68 memset(info
, 0, sizeof(*info
));
69 info
->version_num
= 1;
70 // supports tagged requests and soft reset
71 info
->hba_inquiry
= 0; // SCSI_PI_TAG_ABLE | SCSI_PI_SOFT_RST;
72 // controller is 32, devices are 0 to 31
73 info
->initiator_id
= 32;
74 // adapter command queue size
75 info
->hba_queue_size
= 1;
81 //! this is called immediately before the SCSI bus manager scans the bus
83 ahci_scan_bus(scsi_sim_cookie cookie
)
85 TRACE("ahci_scan_bus, cookie %p\n", cookie
);
92 ahci_reset_bus(scsi_sim_cookie cookie
)
94 TRACE("ahci_reset_bus, cookie %p\n", cookie
);
100 /*! Get restrictions of one device
101 (used for non-SCSI transport protocols and bug fixes)
104 ahci_get_restrictions(scsi_sim_cookie cookie
, uchar targetID
, bool *isATAPI
,
105 bool *noAutoSense
, uint32
*maxBlocks
)
107 TRACE("ahci_get_restrictions, cookie %p\n", cookie
);
109 static_cast<AHCIController
*>(cookie
)->GetRestrictions(targetID
, isATAPI
, noAutoSense
, maxBlocks
);
114 ahci_ioctl(scsi_sim_cookie cookie
, uint8 targetID
, uint32 op
, void *buffer
,
117 TRACE("ahci_ioctl, cookie %p\n", cookie
);
118 return B_DEV_INVALID_IOCTL
;
126 ahci_sim_init_bus(device_node
*node
, void **_cookie
)
128 TRACE("ahci_sim_init_bus\n");
130 // get the PCI device from our parent's parent
131 device_node
*parent
= gDeviceManager
->get_parent_node(node
);
132 device_node
*pciParent
= gDeviceManager
->get_parent_node(parent
);
133 gDeviceManager
->put_node(parent
);
135 pci_device_module_info
*pci
;
136 pci_device
*pciDevice
;
137 gDeviceManager
->get_driver(pciParent
, (driver_module_info
**)&pci
,
138 (void **)&pciDevice
);
139 gDeviceManager
->put_node(pciParent
);
141 TRACE("ahci_sim_init_bus: pciDevice %p\n", pciDevice
);
143 AHCIController
*controller
= new(std::nothrow
) AHCIController(node
, pci
,
147 status_t status
= controller
->Init();
153 *_cookie
= controller
;
154 TRACE("cookie = %p\n", *_cookie
);
160 ahci_sim_uninit_bus(void *cookie
)
162 TRACE("ahci_sim_uninit_bus, cookie %p\n", cookie
);
163 AHCIController
*controller
= static_cast<AHCIController
*>(cookie
);
165 controller
->Uninit();
171 ahci_sim_bus_removed(void *cookie
)
173 TRACE("ahci_sim_bus_removed, cookie %p\n", cookie
);
178 std_ops(int32 op
, ...)
182 case B_MODULE_UNINIT
:
191 scsi_sim_interface gAHCISimInterface
= {
194 AHCI_SIM_MODULE_NAME
,
198 NULL
, // supported devices
199 NULL
, // register node
202 NULL
, // register child devices
214 ahci_get_restrictions
,