From: John Hodge Date: Wed, 17 Mar 2010 14:13:33 +0000 (+0800) Subject: Multiple fixes X-Git-Tag: rel0.06~273 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=1e25b20fd5d119d3b5673d6a31f60b2da676de98;p=tpg%2Facess2.git Multiple fixes - Fixed bug in FDD driver where motor was stopped during a read operation - Moved PCI and DMA to be loaded like any other module/driver - Added PCI as a dependency to BochsGA and ATA driver, Added DMA to FDD - Fixed PCI not scanning the full length of the bus (only scanned 10, not 32 devices per bus) --- diff --git a/Kernel/Makefile b/Kernel/Makefile index 9825a3d5..ccc47dd8 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -28,7 +28,7 @@ endif OBJ = $(addprefix arch/$(ARCHDIR)/,$(A_OBJ)) OBJ += heap.o messages.o debug.o modules.o lib.o syscalls.o system.o threads.o drvutil.o OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS))) -OBJ += drv/vterm.o drv/proc.o drv/fifo.o drv/dma.o drv/iocache.o drv/pci.o drv/kb.o drv/vga.o +OBJ += drv/vterm.o drv/proc.o drv/fifo.o drv/iocache.o drv/dma.o drv/pci.o drv/kb.o drv/vga.o OBJ += binary.o bin/elf.o bin/pe.o OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o OBJ += vfs/fs/root.o vfs/fs/devfs.o diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index db4b72be..61acd3c6 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1531 +BUILD_NUM = 1541 diff --git a/Kernel/arch/x86/include/arch.h b/Kernel/arch/x86/include/arch.h index 18267576..996f4185 100644 --- a/Kernel/arch/x86/include/arch.h +++ b/Kernel/arch/x86/include/arch.h @@ -44,6 +44,7 @@ // === MACROS === typedef volatile int tSpinlock; +#define IS_LOCKED(lockptr) (!!(*(tSpinlock*)lockptr)) #define LOCK(lockptr) do {int v=1;\ while(v)__asm__ __volatile__("lock xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(lockptr));}while(0) #define RELEASE(lockptr) __asm__ __volatile__("lock andl $0, (%%edi)"::"D"(lockptr)); diff --git a/Kernel/drv/dma.c b/Kernel/drv/dma.c index 9116703e..750b180d 100644 --- a/Kernel/drv/dma.c +++ b/Kernel/drv/dma.c @@ -3,6 +3,7 @@ * DMA Driver */ #include +#include #define DMA_SIZE (0x2400) #define DMA_ADDRESS(c) ((c)*DMA_SIZE+0x500) //Save Space for IDT and BDA @@ -11,11 +12,19 @@ #define HIB(x) (((x)>>8)&0xFF) #define HIW(x) (((x)>>16)&0xFFFF) -typedef struct { - int mode; +// === TYPES === +typedef struct +{ + int mode; char *address; } t_dmaChannel; +// === PROTOTYPES === + int DMA_Install(); +void DMA_SetChannel(int Channel, int length, int read); + int DMA_ReadData(int channel, int count, void *buffer); + +// === CONSTANTS === const Uint8 cMASKPORT [8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 }; const Uint8 cMODEPORT [8] = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 }; const Uint8 cCLEARPORT[8] = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 }; @@ -23,14 +32,17 @@ const Uint8 cPAGEPORT [8] = { 0x87, 0x83, 0x81, 0x82, 0x8F, 0x8B, 0x89, 0x8A }; const Uint8 cADDRPORT [8] = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC }; const Uint8 cCOUNTPORT[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE }; +// === GLOBALS === +MODULE_DEFINE(0, 0x0100, ISADMA, DMA_Install, NULL, NULL); char *dma_addresses[8]; t_dmaChannel dma_channels[8]; +// === CODE === /** - * \fn void DMA_Install() + * \fn int DMA_Install() * \brief Initialise DMA channels */ -void DMA_Install() +int DMA_Install() { Uint i; for(i=8;i--;) @@ -51,6 +63,7 @@ void DMA_Install() dma_addresses[i] = (char*)DMA_ADDRESS(i); dma_addresses[i] += KERNEL_BASE; } + return MODULE_ERR_OK; } /** diff --git a/Kernel/drv/pci.c b/Kernel/drv/pci.c index 9f1dd6ea..dfbc8ca2 100644 --- a/Kernel/drv/pci.c +++ b/Kernel/drv/pci.c @@ -56,7 +56,7 @@ Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); // === GLOBALS === -//MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL); +MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL, NULL); int giPCI_BusCount = 1; int giPCI_InodeHandle = -1; int giPCI_DeviceCount = 0; @@ -97,15 +97,13 @@ int PCI_Install(char **Arguments) // Scan Busses for( bus = 0; bus < giPCI_BusCount; bus++ ) { - for( dev = 0; dev < 10; dev++ ) // 10 Devices per bus + for( dev = 0; dev < 32; dev++ ) // 32 Devices per bus { - for( fcn = 0; fcn < 8; fcn++ ) // 8 functions per device + for( fcn = 0; fcn < 8; fcn++ ) // Max 8 functions per device { // Check if the device/function exists if(!PCI_EnumDevice(bus, dev, fcn, &devInfo)) - { continue; - } if(giPCI_DeviceCount == space) { @@ -118,20 +116,26 @@ int PCI_Install(char **Arguments) if(devInfo.oc == PCI_OC_PCIBRIDGE) { #if LIST_DEVICES - Log("[PCI ] Bridge @ %i,%i:%i (0x%x:0x%x)", + Log("[PCI ] Bridge @ %i,%i:%i (0x%x:0x%x)", bus, dev, fcn, devInfo.vendor, devInfo.device); #endif giPCI_BusCount++; } + else + { + #if LIST_DEVICES + Log("[PCI ] Device %i,%i:%i %04x => 0x%04x:0x%04x", + bus, dev, fcn, devInfo.oc, devInfo.vendor, devInfo.device); + #endif + } + devInfo.Node.Inode = giPCI_DeviceCount; memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(tPCIDevice)); giPCI_DeviceCount ++; - #if LIST_DEVICES - Log("[PCI ] Device %i,%i:%i => 0x%x:0x%x", - bus, dev, fcn, devInfo.vendor, devInfo.device); - #endif // WTF is this for? + // Maybe bit 23 must be set for the device to be valid? + // - Actually, maybe 23 means that there are sub-functions if(fcn == 0) { if( !(devInfo.ConfigCache[3] & 0x800000) ) break; @@ -290,8 +294,8 @@ int PCI_GetDeviceByClass(Uint16 class, Uint16 mask, int prev) for( ; i < giPCI_DeviceCount; i++ ) { - if((gPCI_Devices[i].oc & mask) != class) continue; - return i; + if((gPCI_Devices[i].oc & mask) == class) + return i; } return -1; } diff --git a/Kernel/system.c b/Kernel/system.c index 80af7d1c..b30f4d04 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -21,7 +21,7 @@ typedef struct // === IMPORTS === extern int Modules_LoadBuiltins(); -extern int PCI_Install(); +//extern int PCI_Install(); extern void DMA_Install(); extern void Debug_SetKTerminal(char *File); extern void StartupPrint(char *Str); @@ -41,8 +41,8 @@ char *gsConfigScript = "/Acess/Conf/BootConf.cfg"; void System_Init(char *ArgString) { // - Start Builtin Drivers & Filesystems - StartupPrint("Scanning PCI Bus..."); - PCI_Install(); + //StartupPrint("Scanning PCI Bus..."); + //PCI_Install(); StartupPrint("Loading DMA..."); DMA_Install(); StartupPrint("Loading staticly compiled modules..."); diff --git a/Makefile.cfg b/Makefile.cfg index a12ea151..5fc3af1d 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -26,11 +26,11 @@ endif FILESYSTEMS = DRIVERS = MODULES = Storage/ATA Storage/FDD -MODULES += Network/NE2000 -MODULES += Display/BochsGA +#MODULES += Network/NE2000 +#MODULES += Display/BochsGA MODULES += Filesystems/Ext2 MODULES += Filesystems/FAT -MODULES += IPStack +#MODULES += IPStack DYNMODS = USB Interfaces/UDI #DISTROOT = /mnt/AcessHDD/Acess2 diff --git a/Modules/Display/BochsGA/bochsvbe.c b/Modules/Display/BochsGA/bochsvbe.c index 4b76c223..7065709f 100644 --- a/Modules/Display/BochsGA/bochsvbe.c +++ b/Modules/Display/BochsGA/bochsvbe.c @@ -70,7 +70,7 @@ Uint64 BGA_Write(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer); int BGA_Ioctl(tVFS_Node *node, int id, void *data); // === GLOBALS === -MODULE_DEFINE(0, 0x0032, BochsGA, BGA_Install, NULL, NULL); +MODULE_DEFINE(0, 0x0032, BochsGA, BGA_Install, NULL, "PCI", NULL); tDevFS_Driver gBGA_DriverStruct = { NULL, "BochsGA", { diff --git a/Modules/Makefile.tpl b/Modules/Makefile.tpl index 8f548c59..4341bdae 100644 --- a/Modules/Makefile.tpl +++ b/Modules/Makefile.tpl @@ -15,7 +15,11 @@ CPPFLAGS = -I$(ACESSDIR)/Kernel/include -I$(ACESSDIR)/Kernel/arch/$(ARCHDIR)/inc CFLAGS = -Wall -Werror -fno-stack-protector $(CPPFLAGS) -O3 OBJ := $(addsuffix .$(ARCH),$(OBJ)) -BIN = ../$(CATEGORY)_$(NAME).kmd.$(ARCH) +ifeq ($(CATEGORY),) + BIN := ../$(CATEGORY)_$(NAME).kmd.$(ARCH) +else + BIN := ../$(NAME).kmd.$(ARCH) +endif KOBJ = ../$(NAME).xo.$(ARCH) DEPFILES = $(filter %.o.$(ARCH),$(OBJ)) diff --git a/Modules/Storage/ATA/main.c b/Modules/Storage/ATA/main.c index 2bb151da..9ad8898c 100644 --- a/Modules/Storage/ATA/main.c +++ b/Modules/Storage/ATA/main.c @@ -76,7 +76,7 @@ void ATA_int_BusMasterWriteByte(int Ofs, Uint8 Value); void ATA_int_BusMasterWriteDWord(int Ofs, Uint32 Value); // === GLOBALS === -MODULE_DEFINE(0, 0x0032, i386ATA, ATA_Install, NULL, NULL); +MODULE_DEFINE(0, 0x0032, i386ATA, ATA_Install, NULL, "PCI", NULL); tDevFS_Driver gATA_DriverInfo = { NULL, "ata", { diff --git a/Modules/Storage/FDD/fdd.c b/Modules/Storage/FDD/fdd.c index 86cef014..793e76c4 100644 --- a/Modules/Storage/FDD/fdd.c +++ b/Modules/Storage/FDD/fdd.c @@ -107,7 +107,7 @@ void FDD_int_StartMotor(int disk); int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt); // === GLOBALS === -MODULE_DEFINE(0, FDD_VERSION, FDD, FDD_Install, NULL, NULL); +MODULE_DEFINE(0, FDD_VERSION, FDD, FDD_Install, NULL, "ISADMA", NULL); t_floppyDevice gFDD_Devices[2]; tSpinlock glFDD; volatile int gbFDD_IrqFired = 0; @@ -143,6 +143,10 @@ int FDD_Install(char **Arguments) Log("[FDD ] Detected Disk 0: %s and Disk 1: %s", cFDD_TYPES[data>>4], cFDD_TYPES[data&0xF]); + if( data == 0 ) { + return MODULE_ERR_NOTNEEDED; + } + // Clear FDD IRQ Flag FDD_SensInt(0x3F0, NULL, NULL); // Install IRQ6 Handler @@ -347,32 +351,12 @@ int FDD_ReadSector(Uint32 Disk, Uint64 SectorAddr, void *Buffer) int i; int lba = SectorAddr; - ENTER("iDisk XSectorAddr pBuffer", disk, SectorAddr, Buffer); + ENTER("iDisk XSectorAddr pBuffer", Disk, SectorAddr, Buffer); - #if USE_CACHE - FDD_AquireCacheSpinlock(); - for( i = 0; i < siFDD_SectorCacheSize; i++ ) - { - if(sFDD_SectorCache[i].timestamp == 0) continue; - if( sFDD_SectorCache[i].disk == Disk - && sFDD_SectorCache[i].sector == lba) - { - LOG("Found %i in cache %i", lba, i); - memcpy(Buffer, sFDD_SectorCache[i].data, 512); - sFDD_SectorCache[i].timestamp = now(); - FDD_FreeCacheSpinlock(); - LEAVE('i', 1); - return 1; - } - } - LOG("Read %i from Disk", lba); - FDD_FreeCacheSpinlock(); - #else if( IOCache_Read( gFDD_Devices[Disk].CacheHandle, SectorAddr, Buffer ) == 1 ) { LEAVE('i', 1); return 1; } - #endif base = cPORTBASE[Disk >> 1]; @@ -383,20 +367,20 @@ int FDD_ReadSector(Uint32 Disk, Uint64 SectorAddr, void *Buffer) LEAVE('i', -1); return -1; } + LOG("Cyl=%i, Head=%i, Sector=%i", cyl, head, sec); - // Remove Old Timer - Time_RemoveTimer(gFDD_Devices[Disk].timer); - // Check if Motor is on - if(gFDD_Devices[Disk].motorState == 0) FDD_int_StartMotor(Disk); + LOCK(&glFDD); // Lock to stop the motor stopping on us + Time_RemoveTimer(gFDD_Devices[Disk].timer); // Remove Old Timer + // Start motor if needed + if(gFDD_Devices[Disk].motorState != 2) FDD_int_StartMotor(Disk); + RELEASE(&glFDD); LOG("Wait for the motor to spin up"); // Wait for spinup while(gFDD_Devices[Disk].motorState == 1) Threads_Yield(); - LOG("Cyl=%i, Head=%i, Sector=%i", cyl, head, sec); LOG("Acquire Spinlock"); - LOCK(&glFDD); // Seek to track @@ -717,8 +701,12 @@ void FDD_int_StartMotor(int disk) void FDD_int_StopMotor(int disk) { Uint8 state; + if( IS_LOCKED(&glFDD) ) return ; + ENTER("iDisk", disk); + state = inb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT ); state &= ~( 1 << (4+disk) ); outb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT, state ); gFDD_Devices[disk].motorState = 0; + LEAVE('-'); }