moved controller specific functionality into it's own class

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22069 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen 2007-08-26 19:06:14 +00:00
parent 2210148f94
commit 21255d1fc7
4 changed files with 128 additions and 13 deletions

View File

@ -2,5 +2,6 @@ SubDir HAIKU_TOP src add-ons kernel busses scsi ahci ;
KernelAddon ahci :
ahci.c
ahci_controller.cpp
ahci_sim.cpp
;

View File

@ -0,0 +1,73 @@
/*
* Copyright 2007, Marcus Overhagen. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "ahci_controller.h"
#include <KernelExport.h>
#define TRACE(a...) dprintf("\33[34mahci:\33[30m " a)
#define FLOW(a...) dprintf("ahci: " a)
AHCIController::AHCIController(device_node_handle node, pci_device_module_info *pci, scsi_for_sim_interface * scsi)
: fNode(node)
, fPCI(pci)
, fSCSI(scsi)
, fDevicePresentMask(0)
{
fDevicePresentMask = (1 << 7) | (1 << 19);
}
AHCIController::~AHCIController()
{
}
void
AHCIController::ExecuteRequest(scsi_ccb *request)
{
if (request->target_lun || !IsDevicePresent(request->target_id)) {
request->subsys_status = SCSI_DEV_NOT_THERE;
fSCSI->finished(request, 1);
return;
}
TRACE("AHCIController::ExecuteRequest opcode %u, length %u\n", request->cdb[0], request->cdb_length);
request->subsys_status = SCSI_REQ_CMP;
fSCSI->finished(request, 1);
}
uchar
AHCIController::AbortRequest(scsi_ccb *request)
{
if (request->target_lun || !IsDevicePresent(request->target_id))
return SCSI_DEV_NOT_THERE;
return SCSI_REQ_CMP;
}
uchar
AHCIController::TerminateRequest(scsi_ccb *request)
{
if (request->target_lun || !IsDevicePresent(request->target_id))
return SCSI_DEV_NOT_THERE;
return SCSI_REQ_CMP;
}
uchar
AHCIController::ResetDevice(uchar targetID, uchar targetLUN)
{
if (targetLUN || !IsDevicePresent(targetID))
return SCSI_DEV_NOT_THERE;
return SCSI_REQ_CMP;
}

View File

@ -0,0 +1,43 @@
/*
* Copyright 2007, Marcus Overhagen. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _AHCI_CONTROLLER_H
#define _AHCI_CONTROLLER_H
#include "ahci_defs.h"
class AHCIController
{
public:
AHCIController(device_node_handle node, pci_device_module_info *pci, scsi_for_sim_interface * scsi);
~AHCIController();
void ExecuteRequest(scsi_ccb *request);
uchar AbortRequest(scsi_ccb *request);
uchar TerminateRequest(scsi_ccb *request);
uchar ResetDevice(uchar targetID, uchar targetLUN);
private:
bool IsDevicePresent(uint device);
private:
device_node_handle fNode;
pci_device_module_info * fPCI;
scsi_for_sim_interface * fSCSI;
uint32 fDevicePresentMask;
};
inline bool
AHCIController::IsDevicePresent(uint device)
{
return fDevicePresentMask & (1 << device);
}
#endif

View File

@ -3,10 +3,11 @@
* Distributed under the terms of the MIT License.
*/
#include "ahci_defs.h"
#include "ahci_controller.h"
#include <KernelExport.h>
#include <string.h>
#include <new>
#define TRACE(a...) dprintf("\33[34mahci:\33[30m " a)
#define FLOW(a...) dprintf("ahci: " a)
@ -25,11 +26,7 @@ ahci_scsi_io(scsi_sim_cookie cookie, scsi_ccb *request)
{
TRACE("ahci_scsi_io, cookie %p, path_id %u, target_id %u, target_lun %u\n",
cookie, request->path_id, request->target_id, request->target_lun);
TRACE("ahci_scsi_io, opcode %u, length %u\n", request->cdb[0], request->cdb_length);
request->subsys_status = SCSI_REQ_CMP;
gSCSI->finished(request, 1);
static_cast<AHCIController *>(cookie)->ExecuteRequest(request);
}
@ -38,8 +35,7 @@ static uchar
ahci_abort_io(scsi_sim_cookie cookie, scsi_ccb *request)
{
TRACE("ahci_abort_io, cookie %p\n", cookie);
return SCSI_REQ_CMP;
return static_cast<AHCIController *>(cookie)->AbortRequest(request);
}
@ -47,8 +43,7 @@ static uchar
ahci_reset_device(scsi_sim_cookie cookie, uchar targetID, uchar targetLUN)
{
TRACE("ahci_reset_device, cookie %p\n", cookie);
return SCSI_REQ_CMP;
return static_cast<AHCIController *>(cookie)->ResetDevice(targetID, targetLUN);
}
@ -57,8 +52,7 @@ static uchar
ahci_terminate_io(scsi_sim_cookie cookie, scsi_ccb *request)
{
TRACE("ahci_terminate_io, cookie %p\n", cookie);
return SCSI_REQ_CMP;
return static_cast<AHCIController *>(cookie)->TerminateRequest(request);
}
@ -131,7 +125,10 @@ static status_t
ahci_sim_init_bus(device_node_handle node, void *user_cookie, void **_cookie)
{
TRACE("ahci_sim_init_bus, user_cookie %p\n", user_cookie);
*_cookie = (void *)0x1234;
// *_cookie = (void *)0x1234;
*_cookie = new(std::nothrow) AHCIController(node, gPCI, gSCSI);
if (!*_cookie)
return B_NO_MEMORY;
TRACE("cookie = %p\n", *_cookie);
return B_OK;
}
@ -141,6 +138,7 @@ static status_t
ahci_sim_uninit_bus(void *cookie)
{
TRACE("ahci_sim_uninit_bus, cookie %p\n", cookie);
delete static_cast<AHCIController *>(cookie);
return B_OK;
}