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 //Uint gaFrameList[1024];
24 tUHCI_TD gaUHCI_TDPool[NUM_TDs];
25 tUHCI_Controller gUHCI_Controllers[MAX_CONTROLLERS];
29 * \fn int UHCI_Initialise()
30 * \brief Called to initialise the UHCI Driver
39 // Enumerate PCI Bus, getting a maximum of `MAX_CONTROLLERS` devices
40 while( (id = PCI_GetDeviceByClass(0x0C03, 0xFFFF, id)) >= 0 && i < MAX_CONTROLLERS )
42 // NOTE: Check "protocol" from PCI?
44 gUHCI_Controllers[i].PciId = id;
45 // Assign a port range (BAR4, Reserve 32 ports)
46 gUHCI_Controllers[i].IOBase = PCI_GetBAR(id, 4);
47 gUHCI_Controllers[i].IRQNum = PCI_GetIRQ(id);
49 Log("[USB ] Controller PCI #%i: IO Base = 0x%x, IRQ %i",
50 id, gUHCI_Controllers[i].IOBase, gUHCI_Controllers[i].IRQNum);
53 ret = UHCI_Int_InitHost(&gUHCI_Controllers[i]);
62 if(i == MAX_CONTROLLERS) {
63 Log_Warning("UHCI", "Over "EXPAND_STR(MAX_CONTROLLERS)" UHCI controllers detected, ignoring rest");
70 * \fn void UHCI_Cleanup()
71 * \brief Called just before module is unloaded
78 * \brief Sends a packet to a device endpoint
80 int UHCI_SendPacket(int ControllerId, int Length)
82 //tUHCI_TD *td = UHCI_AllocateTD();
86 // === INTERNAL FUNCTIONS ===
88 * \fn int UHCI_Int_InitHost(tUCHI_Controller *Host)
89 * \brief Initialises a UHCI host controller
90 * \param Host Pointer - Host to initialise
92 int UHCI_Int_InitHost(tUHCI_Controller *Host)
96 outw( Host->IOBase + USBCMD, 4 ); // GRESET
97 // TODO: Wait for at least 10ms
98 outw( Host->IOBase + USBCMD, 0 ); // GRESET
100 // Allocate Frame List
101 Host->FrameList = (void *) MM_AllocDMA(1, 32, &Host->PhysFrameList); // 1 Page, 32-bit
102 if( !Host->FrameList ) {
103 Log_Warning("UHCI", "Unable to allocate frame list, aborting");
107 LOG("Allocated frame list 0x%x (0x%x)", Host->FrameList, Host->PhysFrameList);
108 memsetd( Host->FrameList, 1, 1024 ); // Clear List (Disabling all entries)
110 //! \todo Properly fill frame list
112 // Set frame length to 1 ms
113 outb( Host->IOBase + SOFMOD, 64 );
115 // Set Frame List Address
116 outd( Host->IOBase + FLBASEADD, Host->PhysFrameList );
119 outw( Host->IOBase + FRNUM, 0 );
122 //PCI_WriteWord( Host->PciId, 0xC0, 0x2000 );