From: John Hodge Date: Thu, 1 Apr 2010 02:18:01 +0000 (+0800) Subject: Misc Changes X-Git-Tag: rel0.06~260 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=351dd3b194833c923bad0292e9019320fb2a41fa;p=tpg%2Facess2.git Misc Changes - Moved USB core to a new folder, - Slight changes to Ext2 driver - Slight changes in BochsGA driver - Added a cache field to the tVFS_Node that can be assumed to be a heap address or NULL > Allows easier cleanup of per-fs buffers when a node is freed - Added the start of a VM8086 driver for BIOS calls --- diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index f26427d5..dc7f7ff2 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1633 +BUILD_NUM = 1636 diff --git a/Kernel/arch/x86/include/vm8086.h b/Kernel/arch/x86/include/vm8086.h new file mode 100644 index 00000000..cb2834c2 --- /dev/null +++ b/Kernel/arch/x86/include/vm8086.h @@ -0,0 +1,29 @@ +/* + * Acess2 VM8086 BIOS Interface + * - By John Hodge (thePowersGang) + * + * vm8086.h + * - Core Header + */ +#ifndef _VM80806_H_ +#define _VM80806_H_ + +// === TYPES === +typedef struct sVM8086 +{ + Uint16 AX, CX, DX, BX; + Uint16 BP, SP, SI, DI; + + Uint16 CS, SS, DS, ES; + + Uint16 IP; +} tVM8086; + +// === FUNCTIONS === +extern tVM8086 *VM8086_Init(void); +extern void VM8086_Free(tVM8086 *State); +extern void *VM8086_Allocate(tVM8086 *State, int Size, Uint16 *Segment, Uint16 *Ofs); +extern void *VM8086_GetPointer(tVM8086 *State, Uint16 Segment, Uint16 Ofs); +extern void VM8086_Int(tVM8086 *State, Uint8 Interrupt); + +#endif diff --git a/Kernel/include/vfs.h b/Kernel/include/vfs.h index a7821048..e3a61d43 100644 --- a/Kernel/include/vfs.h +++ b/Kernel/include/vfs.h @@ -97,6 +97,12 @@ typedef struct sVFS_Node Uint64 Size; //!< File Size Uint32 Flags; //!< File Flags + + /** + * Pointer to cached data (FS Specific) + * \note Inode_* will free when the node is uncached this if needed + */ + void *Data; /** * \} */ diff --git a/Modules/Display/BochsGA/bochsvbe.c b/Modules/Display/BochsGA/bochsvbe.c index 7065709f..d1d78a5c 100644 --- a/Modules/Display/BochsGA/bochsvbe.c +++ b/Modules/Display/BochsGA/bochsvbe.c @@ -15,7 +15,7 @@ #define INT -// === TYPEDEFS === +// === TYPES === typedef struct { Uint16 width; Uint16 height; diff --git a/Modules/Filesystems/Ext2/dir.c b/Modules/Filesystems/Ext2/dir.c index 0ab3ed39..86092b0f 100644 --- a/Modules/Filesystems/Ext2/dir.c +++ b/Modules/Filesystems/Ext2/dir.c @@ -57,7 +57,7 @@ char *Ext2_ReadDir(tVFS_Node *Node, int Pos) if(ofs >= disk->BlockSize) { block ++; if( ofs > disk->BlockSize ) { - Warning("[EXT2] Directory Entry %i of inode %i extends over a block boundary, ignoring", + Log_Warning("EXT2", "Directory Entry %i of inode %i extends over a block boundary, ignoring", entNum-1, Node->Inode); } ofs = 0; @@ -135,7 +135,7 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *Filename) if(ofs >= disk->BlockSize) { block ++; if( ofs > disk->BlockSize ) { - Warning("[EXT2 ] Directory Entry %i of inode %i extends over a block boundary, ignoring", + Log_Warning("EXT2", "Directory Entry %i of inode %i extends over a block boundary, ignoring", entNum-1, Node->Inode); } ofs = 0; @@ -220,7 +220,7 @@ tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID, char *Name) //if(Name[0] == '.') retNode.Flags |= VFS_FFLAG_HIDDEN; // Set Timestamps - retNode.ATime = now(); + retNode.ATime = inode.i_atime * 1000; retNode.MTime = inode.i_mtime * 1000; retNode.CTime = inode.i_ctime * 1000; diff --git a/Modules/Filesystems/Ext2/ext2.c b/Modules/Filesystems/Ext2/ext2.c index c2c2df9c..ac3d7e5c 100644 --- a/Modules/Filesystems/Ext2/ext2.c +++ b/Modules/Filesystems/Ext2/ext2.c @@ -33,7 +33,6 @@ tVFS_Driver gExt2_FSInfo = { }; // === CODE === - /** * \fn int Ext2_Install(char **Arguments) * \brief Install the Ext2 Filesystem Driver @@ -64,7 +63,7 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options) // Open Disk fd = VFS_Open(Device, VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE); //Open Device if(fd == -1) { - Warning("[EXT2 ] Unable to open '%s'", Device); + Log_Warning("EXT2", "Unable to open '%s'", Device); LEAVE('n'); return NULL; } @@ -74,7 +73,7 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options) // Sanity Check Magic value if(sb.s_magic != 0xEF53) { - Warning("[EXT2 ] Volume '%s' is not an EXT2 volume", Device); + Log_Warning("EXT2", "Volume '%s' is not an EXT2 volume", Device); VFS_Close(fd); LEAVE('n'); return NULL; @@ -87,7 +86,7 @@ tVFS_Node *Ext2_InitDevice(char *Device, char **Options) // Allocate Disk Information disk = malloc(sizeof(tExt2_Disk) + sizeof(tExt2_Group)*groupCount); if(!disk) { - Warning("[EXT2 ] Unable to allocate disk structure"); + Log_Warning("EXT2", "Unable to allocate disk structure"); VFS_Close(fd); LEAVE('n'); return NULL; @@ -187,7 +186,7 @@ int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode) { int group, subId; - //ENTER("pDisk iInodeId pInode", Disk, InodeId, Inode); + ENTER("pDisk iInodeId pInode", Disk, InodeId, Inode); if(InodeId == 0) return 0; @@ -196,7 +195,7 @@ int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode) group = InodeId / Disk->SuperBlock.s_inodes_per_group; subId = InodeId % Disk->SuperBlock.s_inodes_per_group; - //LOG("group=%i, subId = %i", group, subId); + LOG("group=%i, subId = %i", group, subId); // Read Inode VFS_ReadAt(Disk->FD, @@ -204,7 +203,7 @@ int Ext2_int_ReadInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode) sizeof(tExt2_Inode), Inode); - //LEAVE('i', 1); + LEAVE('i', 1); return 1; } @@ -216,7 +215,10 @@ int Ext2_int_WriteInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode) int group, subId; ENTER("pDisk iInodeId pInode", Disk, InodeId, Inode); - if(InodeId == 0) return 0; + if(InodeId == 0) { + LEAVE('i', 0); + return 0; + } InodeId --; // Inodes are numbered starting at 1 @@ -229,7 +231,8 @@ int Ext2_int_WriteInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *Inode) VFS_WriteAt(Disk->FD, Disk->Groups[group].bg_inode_table * Disk->BlockSize + sizeof(tExt2_Inode)*subId, sizeof(tExt2_Inode), - Inode); + Inode + ); LEAVE('i', 1); return 1; @@ -293,6 +296,7 @@ Uint64 Ext2_int_GetBlockAddr(tExt2_Disk *Disk, Uint32 *Blocks, int BlockNum) Uint32 Ext2_int_AllocateInode(tExt2_Disk *Disk, Uint32 Parent) { // Uint block = (Parent - 1) / Disk->SuperBlock.s_inodes_per_group; + Log_Warning("EXT2", "Ext2_int_AllocateInode is unimplemented"); return 0; } diff --git a/Modules/Filesystems/Ext2/write.c b/Modules/Filesystems/Ext2/write.c index ba8b61ce..e52ebf75 100644 --- a/Modules/Filesystems/Ext2/write.c +++ b/Modules/Filesystems/Ext2/write.c @@ -90,7 +90,7 @@ Uint64 Ext2_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) base = Ext2_int_GetBlockAddr(disk, inode.i_block, allocSize/disk->BlockSize-1); addBlocks: - Warning("[EXT2 ] File extending is untested"); + Log_Notice("EXT2", "File extending is untested"); // Allocate blocks and copy data to them retLen = Length - (allocSize-Offset); @@ -201,7 +201,7 @@ Uint32 Ext2_int_AllocateBlock(tExt2_Disk *Disk, Uint32 PrevBlock) else { checkAll: - Warning("[EXT2 ] TODO - Implement using blocks outside the current block group"); + Log_Warning("EXT2", "TODO - Implement using blocks outside the current block group"); return 0; } diff --git a/Modules/USB/Core/Makefile b/Modules/USB/Core/Makefile new file mode 100644 index 00000000..b4f400a5 --- /dev/null +++ b/Modules/USB/Core/Makefile @@ -0,0 +1,7 @@ +# +# + +OBJ = main.o uhci.o +NAME = USB + +-include ../Makefile.tpl diff --git a/Modules/USB/Core/main.c b/Modules/USB/Core/main.c new file mode 100644 index 00000000..5744c29d --- /dev/null +++ b/Modules/USB/Core/main.c @@ -0,0 +1,82 @@ +/* + * Acess2 + * USB Stack + */ +#define VERSION ( (0<<8)| 5 ) +#define DEBUG 1 +#include +#include +#include +#include +#include "usb.h" + +// === IMPORTS === + int UHCI_Initialise(); + +// === PROTOTYPES === + int USB_Install(char **Arguments); +void USB_Cleanup(); +char *USB_ReadDir(tVFS_Node *Node, int Pos); +tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name); + int USB_IOCtl(tVFS_Node *Node, int Id, void *Data); + +// === GLOBALS === +MODULE_DEFINE(0, VERSION, USB, USB_Install, NULL, NULL); +tDevFS_Driver gUSB_DrvInfo = { + NULL, "usb", { + .NumACLs = 1, + .ACLs = &gVFS_ACL_EveryoneRX, + .Flags = VFS_FFLAG_DIRECTORY, + .ReadDir = USB_ReadDir, + .FindDir = USB_FindDir, + .IOCtl = USB_IOCtl + } +}; +tUSBDevice *gUSB_Devices = NULL; +tUSBHost *gUSB_Hosts = NULL; + +// === CODE === +/** + * \fn int ModuleLoad() + * \brief Called once module is loaded + */ +int USB_Install(char **Arguments) +{ + UHCI_Initialise(); + Warning("[USB ] Not Complete - Devel Only"); + return MODULE_ERR_OK; +} + +/** + * \fn void USB_Cleanup() + * \brief Called just before module is unloaded + */ +void USB_Cleanup() +{ +} + +/** + * \fn char *USB_ReadDir(tVFS_Node *Node, int Pos) + * \brief Read from the USB root + */ +char *USB_ReadDir(tVFS_Node *Node, int Pos) +{ + return NULL; +} + +/** + * \fn tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name) + * \brief Locate an entry in the USB root + */ +tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name) +{ + return NULL; +} + +/** + * \brief Handles IOCtl Calls to the USB driver + */ +int USB_IOCtl(tVFS_Node *Node, int Id, void *Data) +{ + return 0; +} diff --git a/Modules/USB/Core/uhci.c b/Modules/USB/Core/uhci.c new file mode 100644 index 00000000..e8cb7b71 --- /dev/null +++ b/Modules/USB/Core/uhci.c @@ -0,0 +1,120 @@ +/* + * Acess 2 USB Stack + * Universal Host Controller Interface + */ +#define DEBUG 1 +#include +#include +#include +#include "usb.h" +#include "uhci.h" + +// === CONSTANTS === +#define MAX_CONTROLLERS 4 +#define NUM_TDs 1024 + +// === PROTOTYPES === + int UHCI_Initialise(); +void UHCI_Cleanup(); + int UHCI_IOCtl(tVFS_Node *node, int id, void *data); + int UHCI_Int_InitHost(tUHCI_Controller *Host); + +// === GLOBALS === +//Uint gaFrameList[1024]; +tUHCI_TD gaUHCI_TDPool[NUM_TDs]; +tUHCI_Controller gUHCI_Controllers[MAX_CONTROLLERS]; + +// === CODE === +/** + * \fn int UHCI_Initialise() + * \brief Called to initialise the UHCI Driver + */ +int UHCI_Initialise() +{ + int i=0, id=-1; + int ret; + Uint16 base; + + ENTER(""); + + // Enumerate PCI Bus, getting a maximum of `MAX_CONTROLLERS` devices + while( (id = PCI_GetDeviceByClass(0x0C03, 0xFFFF, id)) >= 0 && i < MAX_CONTROLLERS ) + { + gUHCI_Controllers[i].PciId = id; + // Assign a port range (BAR4, Reserve 32 ports) + base = PCI_AssignPort( id, 4, 0x20 ); + gUHCI_Controllers[i].IOBase = base; + + Log("[USB ] Controller PCI #%i: IO Base = 0x%x", id, base); + + // Initialise Host + ret = UHCI_Int_InitHost(&gUHCI_Controllers[i]); + // Detect an error + if(ret != 0) { + LEAVE('i', ret); + return ret; + } + + i ++; + } + if(i == MAX_CONTROLLERS) { + Warning("[UHCI ] Over "EXPAND_STR(MAX_CONTROLLERS)" UHCI controllers detected, ignoring rest"); + } + LEAVE('i', i); + return i; +} + +/** + * \fn void UHCI_Cleanup() + * \brief Called just before module is unloaded + */ +void UHCI_Cleanup() +{ +} + +/** + * \brief Sends a packet to a device endpoint + */ +int UHCI_SendPacket(int ControllerId, int Length) +{ + //tUHCI_TD *td = UHCI_AllocateTD(); + return 0; +} + +// === INTERNAL FUNCTIONS === +/** + * \fn int UHCI_Int_InitHost(tUCHI_Controller *Host) + * \brief Initialises a UHCI host controller + * \param Host Pointer - Host to initialise + */ +int UHCI_Int_InitHost(tUHCI_Controller *Host) +{ + ENTER("pHost", Host); + + // Allocate Frame List + Host->FrameList = (void *) MM_AllocDMA(1, 32, &Host->PhysFrameList); // 1 Page, 32-bit + if( !Host->FrameList ) { + Warning("[UHCI ] Unable to allocate frame list, aborting"); + LEAVE('i', -1); + return -1; + } + LOG("Allocated frame list 0x%x (0x%x)", Host->FrameList, Host->PhysFrameList); + memsetd( Host->FrameList, 1, 1024 ); // Clear List (Disabling all entries) + + //! \todo Properly fill frame list + + // Set frame length to 1 ms + outb( Host->IOBase + SOFMOD, 64 ); + + // Set Frame List Address + outd( Host->IOBase + FLBASEADD, Host->PhysFrameList ); + + // Set Frame Number + outw( Host->IOBase + FRNUM, 0 ); + + // Enable Interrupts + //PCI_WriteWord( Host->PciId, 0xC0, 0x2000 ); + + LEAVE('i', 0); + return 0; +} diff --git a/Modules/USB/Core/uhci.h b/Modules/USB/Core/uhci.h new file mode 100644 index 00000000..df7854b8 --- /dev/null +++ b/Modules/USB/Core/uhci.h @@ -0,0 +1,207 @@ +/* + * AcessOS Version 1 + * USB Stack + * - Universal Host Controller Interface + */ +#ifndef _UHCI_H_ +#define _UHCI_H_ + +// === TYPES === +typedef struct sUHCI_Controller tUHCI_Controller; +typedef struct sUHCI_TD tUHCI_TD; +typedef struct sUHCI_QH tUHCI_QH; + +// === STRUCTURES === +struct sUHCI_Controller +{ + /** + * \brief PCI Device ID + */ + Uint16 PciId; + + /** + * \brief IO Base Address + */ + Uint16 IOBase; + + /** + * \brief Frame list + * + * 31:4 - Frame Pointer + * 3:2 - Reserved + * 1 - QH/TD Selector + * 0 - Terminate (Empty Pointer) + */ + Uint32 *FrameList; + + /** + * \brief Physical Address of the Frame List + */ + tPAddr PhysFrameList; +}; + +struct sUHCI_TD +{ + /** + * \brief Next Entry in list + * + * 31:4 - Address + * 3 - Reserved + * 2 - Depth/Breadth Select + * 1 - QH/TD Select + * 0 - Terminate (Last in List) + */ + Uint32 Link; + + /** + * \brief Control and Status Field + * + * 31:30 - Reserved + * 29 - Short Packet Detect (Input Only) + * 28:27 - Number of Errors Allowed + * 26 - Low Speed Device (Communicating with a low speed device) + * 25 - Isynchonious Select + * 24 - Interrupt on Completion (IOC) + * 23:16 - Status + * 23 - Active + * 22 - Stalled + * 21 - Data Buffer Error + * 20 - Babble Detected + * 19 - NAK Detected + * 18 - CRC/Timout Error + * 17 - Bitstuff Error + * 16 - Reserved + * 15:11 - Reserved + * 10:0 - Actual Length (Number of bytes transfered) + */ + Uint32 Control; + + /** + * \brief Packet Header + * + * 31:21 - Maximum Length (0=1, Max 0x4FF, 0x7FF=0) + * 20 - Reserved + * 19 - Data Toggle + * 18:15 - Endpoint + * 14:8 - Device Address + * 7:0 - PID (Packet Identifcation) - Only 96, E1, 2D allowed + */ + Uint32 Token; + + /** + * \brief Pointer to the data to send + */ + Uint32 BufferPointer; +}; + +struct sUHCI_QH +{ + /** + * \brief Next Entry in list + * + * 31:4 - Address + * 3:2 - Reserved + * 1 - QH/TD Select + * 0 - Terminate (Last in List) + */ + Uint32 Next; + + + /** + * \brief Next Entry in list + * + * 31:4 - Address + * 3:2 - Reserved + * 1 - QH/TD Select + * 0 - Terminate (Last in List) + */ + Uint32 Child; +}; + +// === ENUMERATIONS === +enum eUHCI_IOPorts { + /** + * \brief USB Command Register + * + * 15:8 - Reserved + * 7 - Maximum Packet Size selector (1: 64 bytes, 0: 32 bytes) + * 6 - Configure Flag (No Hardware Effect) + * 5 - Software Debug (Don't think it will be needed) + * 4 - Force Global Resume + * 3 - Enter Global Suspend Mode + * 2 - Global Reset (Resets all devices on the bus) + * 1 - Host Controller Reset (Reset just the controller) + * 0 - Run/Stop + */ + USBCMD = 0x00, + /** + * \brief USB Status Register + * + * 15:6 - Reserved + * 5 - HC Halted, set to 1 when USBCMD:RS is set to 0 + * 4 - Host Controller Process Error (Errors related to the bus) + * 3 - Host System Error (Errors related to the OS/PCI Bus) + * 2 - Resume Detect (Set if a RESUME command is sent to the Controller) + * 1 - USB Error Interrupt + * 0 - USB Interrupts (Set if a transaction with the IOC bit set is completed) + */ + USBSTS = 0x02, + /** + * \brief USB Interrupt Enable Register + * + * 15:4 - Reserved + * 3 - Short Packet Interrupt Enable + * 2 - Interrupt on Complete (IOC) Enable + * 1 - Resume Interrupt Enable + * 0 - Timout / CRC Error Interrupt Enable + */ + USBINTR = 0x04, + /** + * \brief Frame Number (Index into the Frame List) + * + * 15:11 - Reserved + * 10:0 - Index (Incremented each approx 1ms) + */ + FRNUM = 0x06, + /** + * \brief Frame List Base Address + * + * 31:12 - Pysical Address >> 12 + * 11:0 - Reserved (Set to Zero) + */ + FLBASEADD = 0x08, // 32-bit + /** + * \brief Start-of-frame Modify Register + * \note 8-bits only + * + * Sets the size of a frame + * Frequency = (11936+n)/12000 kHz + * + * 7 - Reserved + * 6:0 - + */ + SOFMOD = 0x0C, // 8bit + /** + * \brief Port Status and Controll Register (Port 1) + * + * 15:13 - Reserved + * 12 - Suspend + * 11:10 - Reserved + * 9 - Port Reset + * 8 - Low Speed Device Attached + * 5:4 - Line Status + * 3 - Port Enable/Disable Change - Used for detecting device removal + * 2 - Port Enable/Disable + * 1 - Connect Status Change + * 0 - Current Connect Status + */ + PORTSC1 = 0x10, + /** + * \brief Port Status and Controll Register (Port 2) + * + * See ::PORTSC1 + */ + PORTSC2 = 0x12 +}; + +#endif diff --git a/Modules/USB/Core/usb.c b/Modules/USB/Core/usb.c new file mode 100644 index 00000000..60bf3f23 --- /dev/null +++ b/Modules/USB/Core/usb.c @@ -0,0 +1,37 @@ +/* + * Acess 2 USB Stack + * USB Packet Control + */ +#define DEBUG 1 +#include +#include +#include +#include "usb.h" + + +// === CODE === +void USB_MakeToken(void *Buf, int PID, int Addr, int EndP) +{ + Uint8 *tok = Buf; + int crc = 0; + + tok[0] = PID & 0xFF; + tok[1] = (Addr & 0x7F) | ((EndP&1)<<7); + tok[2] = ((EndP >> 1) & 0x7) | crc; +} + +#if 0 +void USB_SendData(int Controller, int Dev, int Endpoint, void *Data, int Length) +{ + Uint8 buf[Length+3+2/*?*/]; + + USB_MakeToken(buf, PID_DATA0, Dev, Endpoint); + + switch(Controller & 0xF00) + { + case 1: // UHCI + UHCI_SendPacket(Controller & 0xFF); + break; + } +} +#endif diff --git a/Modules/USB/Core/usb.h b/Modules/USB/Core/usb.h new file mode 100644 index 00000000..397e4d70 --- /dev/null +++ b/Modules/USB/Core/usb.h @@ -0,0 +1,96 @@ +/* + * AcessOS Version 1 + * USB Stack + */ +#ifndef _USB_H_ +#define _USB_H_ + +// === TYPES === +typedef struct sUSBHost tUSBHost; +typedef struct sUSBDevice tUSBDevice; + +// === CONSTANTS === +enum eUSB_PIDs +{ + /** + * \name Token + * \{ + */ + PID_OUT = 0xE1, + PID_IN = 0x69, + PID_SOF = 0xA5, + PID_SETUP = 0x2D, + /** + * \} + */ + + /** + * \name Data + * \{ + */ + PID_DATA0 = 0xC3, + PID_DATA1 = 0x4B, + PID_DATA2 = 0x87, // USB2 only + PID_MDATA = 0x0F, // USB2 only + /** + * \} + */ + + /** + * \name Handshake + * \{ + */ + PID_ACK = 0xD2, + PID_NAK = 0x5A, + PID_STALL = 0x1E, + PID_NYET = 0x96, + /** + * \} + */ + + /** + * \name Special + * \{ + */ + PID_PRE = 0x3C, PID_ERR = 0x3C, + PID_SPLIT = 0x78, + PID_PING = 0xB4, + PID_RESVD = 0xF0, + /** + * \} + */ +}; + +// === FUNCTIONS === +/** + * \note 00101 - X^5+X^2+1 + */ +Uint8 USB_TokenCRC(void *Data, int len); +/** + * \note X^16 + X15 + X^2 + 1 + */ +Uint16 USB_DataCRC(void *Data, int len); + +// === STRUCTURES === +/** + * \brief Defines a USB Host Controller + */ +struct sUSBHost +{ + Uint16 IOBase; + + int (*SendPacket)(int ID, int Length, void *Data); +}; + +/** + * \brief Defines a single device on the USB Bus + */ +struct sUSBDevice +{ + tUSBHost *Host; + int MaxControl; + int MaxBulk; + int MaxISync; +}; + +#endif diff --git a/Modules/USB/Makefile b/Modules/USB/Makefile deleted file mode 100644 index b4f400a5..00000000 --- a/Modules/USB/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# -# - -OBJ = main.o uhci.o -NAME = USB - --include ../Makefile.tpl diff --git a/Modules/USB/main.c b/Modules/USB/main.c deleted file mode 100644 index 5744c29d..00000000 --- a/Modules/USB/main.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Acess2 - * USB Stack - */ -#define VERSION ( (0<<8)| 5 ) -#define DEBUG 1 -#include -#include -#include -#include -#include "usb.h" - -// === IMPORTS === - int UHCI_Initialise(); - -// === PROTOTYPES === - int USB_Install(char **Arguments); -void USB_Cleanup(); -char *USB_ReadDir(tVFS_Node *Node, int Pos); -tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name); - int USB_IOCtl(tVFS_Node *Node, int Id, void *Data); - -// === GLOBALS === -MODULE_DEFINE(0, VERSION, USB, USB_Install, NULL, NULL); -tDevFS_Driver gUSB_DrvInfo = { - NULL, "usb", { - .NumACLs = 1, - .ACLs = &gVFS_ACL_EveryoneRX, - .Flags = VFS_FFLAG_DIRECTORY, - .ReadDir = USB_ReadDir, - .FindDir = USB_FindDir, - .IOCtl = USB_IOCtl - } -}; -tUSBDevice *gUSB_Devices = NULL; -tUSBHost *gUSB_Hosts = NULL; - -// === CODE === -/** - * \fn int ModuleLoad() - * \brief Called once module is loaded - */ -int USB_Install(char **Arguments) -{ - UHCI_Initialise(); - Warning("[USB ] Not Complete - Devel Only"); - return MODULE_ERR_OK; -} - -/** - * \fn void USB_Cleanup() - * \brief Called just before module is unloaded - */ -void USB_Cleanup() -{ -} - -/** - * \fn char *USB_ReadDir(tVFS_Node *Node, int Pos) - * \brief Read from the USB root - */ -char *USB_ReadDir(tVFS_Node *Node, int Pos) -{ - return NULL; -} - -/** - * \fn tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name) - * \brief Locate an entry in the USB root - */ -tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name) -{ - return NULL; -} - -/** - * \brief Handles IOCtl Calls to the USB driver - */ -int USB_IOCtl(tVFS_Node *Node, int Id, void *Data) -{ - return 0; -} diff --git a/Modules/USB/uhci.c b/Modules/USB/uhci.c deleted file mode 100644 index e8cb7b71..00000000 --- a/Modules/USB/uhci.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Acess 2 USB Stack - * Universal Host Controller Interface - */ -#define DEBUG 1 -#include -#include -#include -#include "usb.h" -#include "uhci.h" - -// === CONSTANTS === -#define MAX_CONTROLLERS 4 -#define NUM_TDs 1024 - -// === PROTOTYPES === - int UHCI_Initialise(); -void UHCI_Cleanup(); - int UHCI_IOCtl(tVFS_Node *node, int id, void *data); - int UHCI_Int_InitHost(tUHCI_Controller *Host); - -// === GLOBALS === -//Uint gaFrameList[1024]; -tUHCI_TD gaUHCI_TDPool[NUM_TDs]; -tUHCI_Controller gUHCI_Controllers[MAX_CONTROLLERS]; - -// === CODE === -/** - * \fn int UHCI_Initialise() - * \brief Called to initialise the UHCI Driver - */ -int UHCI_Initialise() -{ - int i=0, id=-1; - int ret; - Uint16 base; - - ENTER(""); - - // Enumerate PCI Bus, getting a maximum of `MAX_CONTROLLERS` devices - while( (id = PCI_GetDeviceByClass(0x0C03, 0xFFFF, id)) >= 0 && i < MAX_CONTROLLERS ) - { - gUHCI_Controllers[i].PciId = id; - // Assign a port range (BAR4, Reserve 32 ports) - base = PCI_AssignPort( id, 4, 0x20 ); - gUHCI_Controllers[i].IOBase = base; - - Log("[USB ] Controller PCI #%i: IO Base = 0x%x", id, base); - - // Initialise Host - ret = UHCI_Int_InitHost(&gUHCI_Controllers[i]); - // Detect an error - if(ret != 0) { - LEAVE('i', ret); - return ret; - } - - i ++; - } - if(i == MAX_CONTROLLERS) { - Warning("[UHCI ] Over "EXPAND_STR(MAX_CONTROLLERS)" UHCI controllers detected, ignoring rest"); - } - LEAVE('i', i); - return i; -} - -/** - * \fn void UHCI_Cleanup() - * \brief Called just before module is unloaded - */ -void UHCI_Cleanup() -{ -} - -/** - * \brief Sends a packet to a device endpoint - */ -int UHCI_SendPacket(int ControllerId, int Length) -{ - //tUHCI_TD *td = UHCI_AllocateTD(); - return 0; -} - -// === INTERNAL FUNCTIONS === -/** - * \fn int UHCI_Int_InitHost(tUCHI_Controller *Host) - * \brief Initialises a UHCI host controller - * \param Host Pointer - Host to initialise - */ -int UHCI_Int_InitHost(tUHCI_Controller *Host) -{ - ENTER("pHost", Host); - - // Allocate Frame List - Host->FrameList = (void *) MM_AllocDMA(1, 32, &Host->PhysFrameList); // 1 Page, 32-bit - if( !Host->FrameList ) { - Warning("[UHCI ] Unable to allocate frame list, aborting"); - LEAVE('i', -1); - return -1; - } - LOG("Allocated frame list 0x%x (0x%x)", Host->FrameList, Host->PhysFrameList); - memsetd( Host->FrameList, 1, 1024 ); // Clear List (Disabling all entries) - - //! \todo Properly fill frame list - - // Set frame length to 1 ms - outb( Host->IOBase + SOFMOD, 64 ); - - // Set Frame List Address - outd( Host->IOBase + FLBASEADD, Host->PhysFrameList ); - - // Set Frame Number - outw( Host->IOBase + FRNUM, 0 ); - - // Enable Interrupts - //PCI_WriteWord( Host->PciId, 0xC0, 0x2000 ); - - LEAVE('i', 0); - return 0; -} diff --git a/Modules/USB/uhci.h b/Modules/USB/uhci.h deleted file mode 100644 index df7854b8..00000000 --- a/Modules/USB/uhci.h +++ /dev/null @@ -1,207 +0,0 @@ -/* - * AcessOS Version 1 - * USB Stack - * - Universal Host Controller Interface - */ -#ifndef _UHCI_H_ -#define _UHCI_H_ - -// === TYPES === -typedef struct sUHCI_Controller tUHCI_Controller; -typedef struct sUHCI_TD tUHCI_TD; -typedef struct sUHCI_QH tUHCI_QH; - -// === STRUCTURES === -struct sUHCI_Controller -{ - /** - * \brief PCI Device ID - */ - Uint16 PciId; - - /** - * \brief IO Base Address - */ - Uint16 IOBase; - - /** - * \brief Frame list - * - * 31:4 - Frame Pointer - * 3:2 - Reserved - * 1 - QH/TD Selector - * 0 - Terminate (Empty Pointer) - */ - Uint32 *FrameList; - - /** - * \brief Physical Address of the Frame List - */ - tPAddr PhysFrameList; -}; - -struct sUHCI_TD -{ - /** - * \brief Next Entry in list - * - * 31:4 - Address - * 3 - Reserved - * 2 - Depth/Breadth Select - * 1 - QH/TD Select - * 0 - Terminate (Last in List) - */ - Uint32 Link; - - /** - * \brief Control and Status Field - * - * 31:30 - Reserved - * 29 - Short Packet Detect (Input Only) - * 28:27 - Number of Errors Allowed - * 26 - Low Speed Device (Communicating with a low speed device) - * 25 - Isynchonious Select - * 24 - Interrupt on Completion (IOC) - * 23:16 - Status - * 23 - Active - * 22 - Stalled - * 21 - Data Buffer Error - * 20 - Babble Detected - * 19 - NAK Detected - * 18 - CRC/Timout Error - * 17 - Bitstuff Error - * 16 - Reserved - * 15:11 - Reserved - * 10:0 - Actual Length (Number of bytes transfered) - */ - Uint32 Control; - - /** - * \brief Packet Header - * - * 31:21 - Maximum Length (0=1, Max 0x4FF, 0x7FF=0) - * 20 - Reserved - * 19 - Data Toggle - * 18:15 - Endpoint - * 14:8 - Device Address - * 7:0 - PID (Packet Identifcation) - Only 96, E1, 2D allowed - */ - Uint32 Token; - - /** - * \brief Pointer to the data to send - */ - Uint32 BufferPointer; -}; - -struct sUHCI_QH -{ - /** - * \brief Next Entry in list - * - * 31:4 - Address - * 3:2 - Reserved - * 1 - QH/TD Select - * 0 - Terminate (Last in List) - */ - Uint32 Next; - - - /** - * \brief Next Entry in list - * - * 31:4 - Address - * 3:2 - Reserved - * 1 - QH/TD Select - * 0 - Terminate (Last in List) - */ - Uint32 Child; -}; - -// === ENUMERATIONS === -enum eUHCI_IOPorts { - /** - * \brief USB Command Register - * - * 15:8 - Reserved - * 7 - Maximum Packet Size selector (1: 64 bytes, 0: 32 bytes) - * 6 - Configure Flag (No Hardware Effect) - * 5 - Software Debug (Don't think it will be needed) - * 4 - Force Global Resume - * 3 - Enter Global Suspend Mode - * 2 - Global Reset (Resets all devices on the bus) - * 1 - Host Controller Reset (Reset just the controller) - * 0 - Run/Stop - */ - USBCMD = 0x00, - /** - * \brief USB Status Register - * - * 15:6 - Reserved - * 5 - HC Halted, set to 1 when USBCMD:RS is set to 0 - * 4 - Host Controller Process Error (Errors related to the bus) - * 3 - Host System Error (Errors related to the OS/PCI Bus) - * 2 - Resume Detect (Set if a RESUME command is sent to the Controller) - * 1 - USB Error Interrupt - * 0 - USB Interrupts (Set if a transaction with the IOC bit set is completed) - */ - USBSTS = 0x02, - /** - * \brief USB Interrupt Enable Register - * - * 15:4 - Reserved - * 3 - Short Packet Interrupt Enable - * 2 - Interrupt on Complete (IOC) Enable - * 1 - Resume Interrupt Enable - * 0 - Timout / CRC Error Interrupt Enable - */ - USBINTR = 0x04, - /** - * \brief Frame Number (Index into the Frame List) - * - * 15:11 - Reserved - * 10:0 - Index (Incremented each approx 1ms) - */ - FRNUM = 0x06, - /** - * \brief Frame List Base Address - * - * 31:12 - Pysical Address >> 12 - * 11:0 - Reserved (Set to Zero) - */ - FLBASEADD = 0x08, // 32-bit - /** - * \brief Start-of-frame Modify Register - * \note 8-bits only - * - * Sets the size of a frame - * Frequency = (11936+n)/12000 kHz - * - * 7 - Reserved - * 6:0 - - */ - SOFMOD = 0x0C, // 8bit - /** - * \brief Port Status and Controll Register (Port 1) - * - * 15:13 - Reserved - * 12 - Suspend - * 11:10 - Reserved - * 9 - Port Reset - * 8 - Low Speed Device Attached - * 5:4 - Line Status - * 3 - Port Enable/Disable Change - Used for detecting device removal - * 2 - Port Enable/Disable - * 1 - Connect Status Change - * 0 - Current Connect Status - */ - PORTSC1 = 0x10, - /** - * \brief Port Status and Controll Register (Port 2) - * - * See ::PORTSC1 - */ - PORTSC2 = 0x12 -}; - -#endif diff --git a/Modules/USB/usb.c b/Modules/USB/usb.c deleted file mode 100644 index 934136a1..00000000 --- a/Modules/USB/usb.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Acess 2 USB Stack - * USB Packet Control - */ -#define DEBUG 1 -#include -#include -#include -#include "usb.h" - - -// === CODE === -void USB_MakeToken(void *Buf, int PID, int Addr, int EndP) -{ - Uint8 *tok = Buf; - int crc = 0; //USB_TokenCRC(); - - tok[0] = PID & 0xFF; - tok[1] = (Addr & 0x7F) | ((EndP&1)<<7); - tok[2] = ((EndP >> 1) & 0x7) | crc; -} - -#if 0 -void USB_SendPacket(int Controller, int PID, int Dev, int Endpoint, void *Data, int Length) -{ - uint8_t buf[Length/*+??*/]; - switch(Controller & 0xF00) - { - case 1: - UHCI_SendPacket(Controller & 0xFF); - } -} -#endif diff --git a/Modules/USB/usb.h b/Modules/USB/usb.h deleted file mode 100644 index a867c112..00000000 --- a/Modules/USB/usb.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * AcessOS Version 1 - * USB Stack - */ -#ifndef _USB_H_ -#define _USB_H_ - -// === TYPES === -typedef struct sUSBHost tUSBHost; -typedef struct sUSBDevice tUSBDevice; - -// === CONSTANTS === -enum eUSB_PIDs -{ - /** - * \name Token - * \{ - */ - PID_OUT = 0xE1, - PID_IN = 0x69, - PID_SOF = 0xA5, - PID_SETUP = 0x2D, - /** - * \} - */ - - /** - * \name Data - * \{ - */ - PID_DATA0 = 0xC3, - PID_DATA1 = 0x4B, - PID_DATA2 = 0x87, // USB2 only - PID_MDATA = 0x0F, // USB2 only - /** - * \} - */ - - /** - * \name Handshake - * \{ - */ - PID_ACK = 0xD2, - PID_NAK = 0x5A, - PID_STALL = 0x1E, - PID_NYET = 0x96, - /** - * \} - */ - - /** - * \name Special - * \{ - */ - PID_PRE = 0x3C, PID_ERR = 0x3C, - PID_SPLIT = 0x78, - PID_PING = 0xB4, - PID_RESVD = 0xF0, - /** - * \} - */ -}; - -// === FUNCTIONS === -/** - * \note 00101 - X^5+X^2+1 - */ -Uint8 USB_TokenCRC(void *Data, int len); -/** - * \note X^16 + X15 + X^2 + 1 - */ -Uint16 USB_DataCRC(void *Data, int len); - -// === STRUCTURES === -/** - * \brief Defines a USB Host Controller - */ -struct sUSBHost -{ - Uint16 IOBase; - - int (*SendPacket)(int ID, int Length, void *Data); -}; - -/** - * \brief Defines a single device on the USB Bus - */ -struct sUSBDevice -{ - tUSBHost *Host; -}; - -#endif