3 * Universal Host Controller Interface
13 #define MAX_CONTROLLERS 4
17 int UHCI_Initialise();
19 int UHCI_IOCtl(tVFS_Node *node, int id, void *data);
20 int UHCI_Int_InitHost(tUHCI_Controller *Host);
23 tUHCI_TD gaUHCI_TDPool[NUM_TDs];
24 tUHCI_Controller gUHCI_Controllers[MAX_CONTROLLERS];
28 * \fn int UHCI_Initialise()
29 * \brief Called to initialise the UHCI Driver
31 int UHCI_Initialise(const char **Arguments)
38 // Enumerate PCI Bus, getting a maximum of `MAX_CONTROLLERS` devices
39 while( (id = PCI_GetDeviceByClass(0x0C03, 0xFFFF, id)) >= 0 && i < MAX_CONTROLLERS )
41 tUHCI_Controller *cinfo = &gUHCI_Controllers[i];
42 // NOTE: Check "protocol" from PCI?
45 // Assign a port range (BAR4, Reserve 32 ports)
46 cinfo->IOBase = PCI_GetBAR(id, 4);
47 if( !(cinfo->IOBase & 1) ) {
48 Log_Warning("UHCI", "MMIO is not supported");
51 cinfo->IRQNum = PCI_GetIRQ(id);
53 Log_Debug("UHCI", "Controller PCI #%i: IO Base = 0x%x, IRQ %i",
54 id, cinfo->IOBase, cinfo->IRQNum);
57 ret = UHCI_Int_InitHost(&gUHCI_Controllers[i]);
66 if(i == MAX_CONTROLLERS) {
67 Log_Warning("UHCI", "Over "EXPAND_STR(MAX_CONTROLLERS)" UHCI controllers detected, ignoring rest");
74 * \fn void UHCI_Cleanup()
75 * \brief Called just before module is unloaded
82 * \brief Sends a packet to the bus
84 int UHCI_SendPacket(int ControllerID, enum eUSB_TransferType Type, void *Data, size_t Length)
86 //tUHCI_TD *td = UHCI_AllocateTD();
90 // === INTERNAL FUNCTIONS ===
92 * \fn int UHCI_Int_InitHost(tUCHI_Controller *Host)
93 * \brief Initialises a UHCI host controller
94 * \param Host Pointer - Host to initialise
96 int UHCI_Int_InitHost(tUHCI_Controller *Host)
100 outw( Host->IOBase + USBCMD, 4 ); // GRESET
101 // TODO: Wait for at least 10ms
102 outw( Host->IOBase + USBCMD, 0 ); // GRESET
104 // Allocate Frame List
105 // - 1 Page, 32-bit address
106 // - 1 page = 1024 4 byte entries
107 Host->FrameList = (void *) MM_AllocDMA(1, 32, &Host->PhysFrameList);
108 if( !Host->FrameList ) {
109 Log_Warning("UHCI", "Unable to allocate frame list, aborting");
113 LOG("Allocated frame list 0x%x (0x%x)", Host->FrameList, Host->PhysFrameList);
114 memsetd( Host->FrameList, 1, 1024 ); // Clear List (Disabling all entries)
116 //! \todo Properly fill frame list
118 // Set frame length to 1 ms
119 outb( Host->IOBase + SOFMOD, 64 );
121 // Set Frame List Address
122 outd( Host->IOBase + FLBASEADD, Host->PhysFrameList );
125 outw( Host->IOBase + FRNUM, 0 );
128 //PCI_WriteWord( Host->PciId, 0xC0, 0x2000 );