XHCI: Reorder some functions and tweak class definition.
No functional change intended (some methods are now private, but nothing outside this class used them, so no change.)
This commit is contained in:
@@ -105,6 +105,79 @@ module_info *modules[] = {
|
||||
};
|
||||
|
||||
|
||||
status_t
|
||||
XHCI::AddTo(Stack *stack)
|
||||
{
|
||||
if (!sPCIModule) {
|
||||
status_t status = get_module(B_PCI_MODULE_NAME,
|
||||
(module_info **)&sPCIModule);
|
||||
if (status < B_OK) {
|
||||
TRACE_MODULE_ERROR("getting pci module failed! 0x%08" B_PRIx32
|
||||
"\n", status);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
TRACE_MODULE("searching devices\n");
|
||||
bool found = false;
|
||||
pci_info *item = new(std::nothrow) pci_info;
|
||||
if (!item) {
|
||||
sPCIModule = NULL;
|
||||
put_module(B_PCI_MODULE_NAME);
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
// Try to get the PCI x86 module as well so we can enable possible MSIs.
|
||||
if (sPCIx86Module == NULL && get_module(B_PCI_X86_MODULE_NAME,
|
||||
(module_info **)&sPCIx86Module) != B_OK) {
|
||||
// If it isn't there, that's not critical though.
|
||||
TRACE_MODULE_ERROR("failed to get pci x86 module\n");
|
||||
sPCIx86Module = NULL;
|
||||
}
|
||||
|
||||
for (int32 i = 0; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) {
|
||||
if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb
|
||||
&& item->class_api == PCI_usb_xhci) {
|
||||
TRACE_MODULE("found device at PCI:%d:%d:%d\n",
|
||||
item->bus, item->device, item->function);
|
||||
XHCI *bus = new(std::nothrow) XHCI(item, stack);
|
||||
if (!bus) {
|
||||
delete item;
|
||||
sPCIModule = NULL;
|
||||
put_module(B_PCI_MODULE_NAME);
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
if (bus->InitCheck() < B_OK) {
|
||||
TRACE_MODULE_ERROR("bus failed init check\n");
|
||||
delete bus;
|
||||
continue;
|
||||
}
|
||||
|
||||
// the bus took it away
|
||||
item = new(std::nothrow) pci_info;
|
||||
|
||||
if (bus->Start() != B_OK) {
|
||||
delete bus;
|
||||
continue;
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
TRACE_MODULE_ERROR("no devices found\n");
|
||||
delete item;
|
||||
sPCIModule = NULL;
|
||||
put_module(B_PCI_MODULE_NAME);
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
delete item;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
XHCI::XHCI(pci_info *info, Stack *stack)
|
||||
: BusManager(stack),
|
||||
fRegisterArea(-1),
|
||||
@@ -822,76 +895,42 @@ XHCI::NotifyPipeChange(Pipe *pipe, usb_change change)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
XHCI::AddTo(Stack *stack)
|
||||
xhci_td *
|
||||
XHCI::CreateDescriptor(size_t bufferSize)
|
||||
{
|
||||
if (!sPCIModule) {
|
||||
status_t status = get_module(B_PCI_MODULE_NAME,
|
||||
(module_info **)&sPCIModule);
|
||||
if (status < B_OK) {
|
||||
TRACE_MODULE_ERROR("getting pci module failed! 0x%08" B_PRIx32
|
||||
"\n", status);
|
||||
return status;
|
||||
}
|
||||
xhci_td *result;
|
||||
phys_addr_t physicalAddress;
|
||||
|
||||
if (fStack->AllocateChunk((void **)&result, &physicalAddress,
|
||||
sizeof(xhci_td)) < B_OK) {
|
||||
TRACE_ERROR("failed to allocate a transfer descriptor\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TRACE_MODULE("searching devices\n");
|
||||
bool found = false;
|
||||
pci_info *item = new(std::nothrow) pci_info;
|
||||
if (!item) {
|
||||
sPCIModule = NULL;
|
||||
put_module(B_PCI_MODULE_NAME);
|
||||
return B_NO_MEMORY;
|
||||
result->this_phy = physicalAddress;
|
||||
result->buffer_size[0] = bufferSize;
|
||||
result->trb_count = 0;
|
||||
result->buffer_count = 1;
|
||||
result->next = NULL;
|
||||
result->next_chain = NULL;
|
||||
if (bufferSize <= 0) {
|
||||
result->buffer_log[0] = NULL;
|
||||
result->buffer_phy[0] = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Try to get the PCI x86 module as well so we can enable possible MSIs.
|
||||
if (sPCIx86Module == NULL && get_module(B_PCI_X86_MODULE_NAME,
|
||||
(module_info **)&sPCIx86Module) != B_OK) {
|
||||
// If it isn't there, that's not critical though.
|
||||
TRACE_MODULE_ERROR("failed to get pci x86 module\n");
|
||||
sPCIx86Module = NULL;
|
||||
if (fStack->AllocateChunk(&result->buffer_log[0],
|
||||
&result->buffer_phy[0], bufferSize) < B_OK) {
|
||||
TRACE_ERROR("unable to allocate space for the buffer (size %ld)\n",
|
||||
bufferSize);
|
||||
fStack->FreeChunk(result, result->this_phy, sizeof(xhci_td));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int32 i = 0; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) {
|
||||
if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb
|
||||
&& item->class_api == PCI_usb_xhci) {
|
||||
TRACE_MODULE("found device at PCI:%d:%d:%d\n",
|
||||
item->bus, item->device, item->function);
|
||||
XHCI *bus = new(std::nothrow) XHCI(item, stack);
|
||||
if (!bus) {
|
||||
delete item;
|
||||
sPCIModule = NULL;
|
||||
put_module(B_PCI_MODULE_NAME);
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
TRACE("CreateDescriptor allocated buffer_size %ld %p\n",
|
||||
result->buffer_size[0], result->buffer_log[0]);
|
||||
|
||||
if (bus->InitCheck() < B_OK) {
|
||||
TRACE_MODULE_ERROR("bus failed init check\n");
|
||||
delete bus;
|
||||
continue;
|
||||
}
|
||||
|
||||
// the bus took it away
|
||||
item = new(std::nothrow) pci_info;
|
||||
|
||||
if (bus->Start() != B_OK) {
|
||||
delete bus;
|
||||
continue;
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
TRACE_MODULE_ERROR("no devices found\n");
|
||||
delete item;
|
||||
sPCIModule = NULL;
|
||||
put_module(B_PCI_MODULE_NAME);
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
delete item;
|
||||
return B_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -946,45 +985,6 @@ XHCI::CreateDescriptorChain(size_t bufferSize, int32 &trbCount)
|
||||
}
|
||||
|
||||
|
||||
xhci_td *
|
||||
XHCI::CreateDescriptor(size_t bufferSize)
|
||||
{
|
||||
xhci_td *result;
|
||||
phys_addr_t physicalAddress;
|
||||
|
||||
if (fStack->AllocateChunk((void **)&result, &physicalAddress,
|
||||
sizeof(xhci_td)) < B_OK) {
|
||||
TRACE_ERROR("failed to allocate a transfer descriptor\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result->this_phy = physicalAddress;
|
||||
result->buffer_size[0] = bufferSize;
|
||||
result->trb_count = 0;
|
||||
result->buffer_count = 1;
|
||||
result->next = NULL;
|
||||
result->next_chain = NULL;
|
||||
if (bufferSize <= 0) {
|
||||
result->buffer_log[0] = NULL;
|
||||
result->buffer_phy[0] = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (fStack->AllocateChunk(&result->buffer_log[0],
|
||||
&result->buffer_phy[0], bufferSize) < B_OK) {
|
||||
TRACE_ERROR("unable to allocate space for the buffer (size %ld)\n",
|
||||
bufferSize);
|
||||
fStack->FreeChunk(result, result->this_phy, sizeof(xhci_td));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TRACE("CreateDescriptor allocated buffer_size %ld %p\n",
|
||||
result->buffer_size[0], result->buffer_log[0]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XHCI::FreeDescriptor(xhci_td *descriptor)
|
||||
{
|
||||
|
||||
@@ -84,9 +84,13 @@ typedef struct xhci_device {
|
||||
|
||||
class XHCI : public BusManager {
|
||||
public:
|
||||
static status_t AddTo(Stack *stack);
|
||||
|
||||
XHCI(pci_info *info, Stack *stack);
|
||||
~XHCI();
|
||||
|
||||
virtual const char * TypeName() const { return "xhci"; }
|
||||
|
||||
status_t Start();
|
||||
virtual status_t SubmitTransfer(Transfer *transfer);
|
||||
status_t SubmitControlRequest(Transfer *transfer);
|
||||
@@ -96,20 +100,11 @@ public:
|
||||
virtual status_t NotifyPipeChange(Pipe *pipe,
|
||||
usb_change change);
|
||||
|
||||
static status_t AddTo(Stack *stack);
|
||||
|
||||
virtual Device * AllocateDevice(Hub *parent,
|
||||
int8 hubAddress, uint8 hubPort,
|
||||
usb_speed speed);
|
||||
status_t ConfigureEndpoint(uint8 slot, uint8 number,
|
||||
uint8 type, uint64 ringAddr,
|
||||
uint16 interval, uint16 maxPacketSize,
|
||||
uint16 maxFrameSize, usb_speed speed);
|
||||
virtual void FreeDevice(Device *device);
|
||||
|
||||
status_t _InsertEndpointForPipe(Pipe *pipe);
|
||||
status_t _RemoveEndpointForPipe(Pipe *pipe);
|
||||
|
||||
// Port operations for root hub
|
||||
uint8 PortCount() const { return fPortCount; }
|
||||
status_t GetPortStatus(uint8 index,
|
||||
@@ -119,8 +114,6 @@ public:
|
||||
|
||||
status_t GetPortSpeed(uint8 index, usb_speed *speed);
|
||||
|
||||
virtual const char * TypeName() const { return "xhci"; }
|
||||
|
||||
private:
|
||||
// Controller resets
|
||||
status_t ControllerReset();
|
||||
@@ -130,6 +123,14 @@ private:
|
||||
static int32 InterruptHandler(void *data);
|
||||
int32 Interrupt();
|
||||
|
||||
// Endpoint management
|
||||
status_t ConfigureEndpoint(uint8 slot, uint8 number,
|
||||
uint8 type, uint64 ringAddr,
|
||||
uint16 interval, uint16 maxPacketSize,
|
||||
uint16 maxFrameSize, usb_speed speed);
|
||||
status_t _InsertEndpointForPipe(Pipe *pipe);
|
||||
status_t _RemoveEndpointForPipe(Pipe *pipe);
|
||||
|
||||
// Event management
|
||||
static int32 EventThread(void *data);
|
||||
void CompleteEvents();
|
||||
@@ -160,7 +161,8 @@ private:
|
||||
void HandleCmdComplete(xhci_trb *trb);
|
||||
void HandleTransferComplete(xhci_trb *trb);
|
||||
status_t DoCommand(xhci_trb *trb);
|
||||
//Doorbell
|
||||
|
||||
// Doorbell
|
||||
void Ring(uint8 slot, uint8 endpoint);
|
||||
|
||||
// Commands
|
||||
@@ -207,6 +209,7 @@ private:
|
||||
|
||||
void _SwitchIntelPorts();
|
||||
|
||||
private:
|
||||
static pci_module_info * sPCIModule;
|
||||
static pci_x86_module_info *sPCIx86Module;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user