From a83e0aa4876aaf5a2875381a3a55b5d62c0fc3b8 Mon Sep 17 00:00:00 2001 From: Valentin Charbonnier Date: Sun, 6 May 2018 04:31:15 +0200 Subject: [PATCH] NETWORK FIX. FINALLY. --- source/Cosmos.Core/PIC.cs | 4 +- .../Drivers/PCI/Network/AMDPCNetII.cs | 28 ++++++------ source/Cosmos.HAL2/PCIDevice.cs | 43 +++++++++++++++---- 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/source/Cosmos.Core/PIC.cs b/source/Cosmos.Core/PIC.cs index 2ecf7e515..8af544a2d 100644 --- a/source/Cosmos.Core/PIC.cs +++ b/source/Cosmos.Core/PIC.cs @@ -95,8 +95,8 @@ namespace Cosmos.Core // set masks: Master.Data.Byte = masterMask; IOPort.Wait(); - Slave.Data.Byte = slaveMask; - IOPort.Wait(); + //Slave.Data.Byte = slaveMask; + //IOPort.Wait(); } protected void Init(IOGroup.PIC aPIC, byte aBase, byte aIDunno, byte aMask) diff --git a/source/Cosmos.HAL2/Drivers/PCI/Network/AMDPCNetII.cs b/source/Cosmos.HAL2/Drivers/PCI/Network/AMDPCNetII.cs index 53e2b85ad..4a003c2b3 100644 --- a/source/Cosmos.HAL2/Drivers/PCI/Network/AMDPCNetII.cs +++ b/source/Cosmos.HAL2/Drivers/PCI/Network/AMDPCNetII.cs @@ -33,10 +33,10 @@ namespace Cosmos.HAL.Drivers.PCI.Network } this.pciCard = device; - // this.pciCard.Claimed = true; - //this.pciCard.EnableDevice(); + this.pciCard.Claimed = true; + this.pciCard.EnableDevice(); - //this.io = new AMDPCNetIIIOGroup((ushort) this.pciCard.BaseAddresses[0].BaseAddress()); + this.io = new AMDPCNetIIIOGroup((ushort) this.pciCard.BaseAddressBar[0].BaseAddress); this.io.RegisterData.DWord = 0; // Get the EEPROM MAC Address and set it as the devices MAC @@ -97,7 +97,7 @@ namespace Cosmos.HAL.Drivers.PCI.Network mTransmitBuffer = new Queue(); mRecvBuffer = new Queue(); - //INTs.SetIrqHandler(device.InterruptLine, HandleNetworkInterrupt); + INTs.SetIrqHandler(device.InterruptLine, HandleNetworkInterrupt); } protected void HandleNetworkInterrupt(ref INTs.IRQContext aContext) @@ -135,16 +135,16 @@ namespace Cosmos.HAL.Drivers.PCI.Network public static void FindAll() { Console.WriteLine("Scanning for AMD PCNetII cards..."); - // PCIDevice device = Cosmos.HAL.PCI.GetDevice(VendorID.AMD, DeviceID.PCNETII); - // if (device != null) - // { - // AMDPCNetII nic = new AMDPCNetII((PCIDevice) device); - // - // Console.WriteLine("Found AMD PCNetII NIC on PCI " + device.bus + ":" + device.slot + ":" + - // device.function); - // Console.WriteLine("NIC IRQ: " + device.InterruptLine); - // Console.WriteLine("NIC MAC Address: " + nic.MACAddress.ToString()); - // } + PCIDevice device = Cosmos.HAL.PCI.GetDevice(VendorID.AMD, DeviceID.PCNETII); + if (device != null) + { + AMDPCNetII nic = new AMDPCNetII((PCIDevice) device); + + Console.WriteLine("Found AMD PCNetII NIC on PCI " + device.bus + ":" + device.slot + ":" + + device.function); + Console.WriteLine("NIC IRQ: " + device.InterruptLine); + Console.WriteLine("NIC MAC Address: " + nic.MACAddress.ToString()); + } } #region Register Access Properties diff --git a/source/Cosmos.HAL2/PCIDevice.cs b/source/Cosmos.HAL2/PCIDevice.cs index 6c413746b..895e17a92 100644 --- a/source/Cosmos.HAL2/PCIDevice.cs +++ b/source/Cosmos.HAL2/PCIDevice.cs @@ -21,10 +21,10 @@ namespace Cosmos.HAL public enum PCIBist : byte { - CocdMask = 0x0f, - Start = 0x40, - Capable = 0x80 - }; + CocdMask = 0x0f, /* Return result */ + Start = 0x40, /* 1 to start BIST, 2 secs or less */ + Capable = 0x80 /* 1 if BIST capable */ + } public enum PCIInterruptPIN : byte { @@ -35,6 +35,20 @@ namespace Cosmos.HAL INTD = 0x04 }; + public enum PCICommand : short + { + IO = 0x1, /* Enable response in I/O space */ + Memory = 0x2, /* Enable response in Memory space */ + Master = 0x4, /* Enable bus mastering */ + Special = 0x8, /* Enable response to special cycles */ + Invalidate = 0x10, /* Use memory write and invalidate */ + VGA_Pallete = 0x20, /* Enable palette snooping */ + Parity = 0x40, /* Enable parity checking */ + Wait = 0x80, /* Enable address/data stepping */ + SERR = 0x100, /* Enable SERR */ + Fast_Back = 0x200, /* Enable back-to-back writes */ + } + public enum Config : byte { VendorID = 0, DeviceID = 2, @@ -63,7 +77,6 @@ namespace Cosmos.HAL public readonly ushort VendorID; public readonly ushort DeviceID; - public readonly ushort Command; public readonly ushort Status; public readonly byte RevisionID; @@ -85,6 +98,14 @@ namespace Cosmos.HAL protected static Core.IOGroup.PCI IO = new Core.IOGroup.PCI(); + public byte InterruptLine { get; private set; } + public PCICommand Command { get { return (PCICommand)ReadRegister16(0x04); } set { WriteRegister16(0x04, (ushort)value); } } + + /// + /// Has this device been claimed by a driver + /// + public bool Claimed { get; set; } + public PCIDevice(uint bus, uint slot, uint function) { this.bus = bus; @@ -94,9 +115,8 @@ namespace Cosmos.HAL VendorID = ReadRegister16((byte)Config.VendorID); DeviceID = ReadRegister16((byte)Config.DeviceID); - Command = ReadRegister16((byte)Config.Command); - Status = ReadRegister16((byte)Config.Status); - + //Command = ReadRegister16((byte)Config.Command); + //Status = ReadRegister16((byte)Config.Status); RevisionID = ReadRegister8((byte)Config.RevisionID); ProgIF = ReadRegister8((byte)Config.ProgIF); @@ -107,6 +127,8 @@ namespace Cosmos.HAL HeaderType = (PCIHeaderType)ReadRegister8((byte)Config.HeaderType); BIST = (PCIBist)ReadRegister8((byte)Config.BIST); InterruptPIN = (PCIInterruptPIN)ReadRegister8((byte)Config.InterruptPIN); + InterruptLine = ReadRegister8((byte)Config.InterruptLine); + if ((uint)VendorID == 0xFF && (uint)DeviceID == 0xFFFF) { DeviceExists = false; @@ -127,6 +149,11 @@ namespace Cosmos.HAL } } + public void EnableDevice() + { + Command |= PCICommand.Master | PCICommand.IO | PCICommand.Memory; + } + public static ushort GetHeaderType(ushort Bus, ushort Slot, ushort Function) { UInt32 xAddr = GetAddressBase(Bus, Slot, Function) | 0xE & 0xFC;