Esempio n. 1
0
File: PCI.cs Progetto: iSalva/Cosmos
 private static void EnumerateBus(uint xBus, uint step)
 {
     for (uint xDevice = 0; xDevice < 32; xDevice++)
     {
         PCIDevice xPCIDevice = new PCIDevice(xBus, xDevice, 0x00);
         if (xPCIDevice.DeviceExists)
         {
             if (xPCIDevice.HeaderType == PCIDevice.PCIHeaderType.Bridge)
             {
                 for (uint xFunction = 0; xFunction < 8; xFunction++)
                 {
                     xPCIDevice = new PCIDevice(xBus, xDevice, xFunction);
                     if (xPCIDevice.DeviceExists)
                         AddDevice(new PCIDeviceBridge(xBus, xDevice, xFunction), step);
                 }
             }
             else if (xPCIDevice.HeaderType == PCIDevice.PCIHeaderType.Cardbus)
             {
                 AddDevice(new PCIDeviceCardbus(xBus, xDevice, 0x00), step);
             }
             else
             {
                 AddDevice(new PCIDeviceNormal(xBus, xDevice, 0x00), step);
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary> Returns all GPUs in system </summary>
        public static List <string> GetGPUInfo()
        {
            List <string> cards = new List <string>();

            foreach (GPU gpu in GPUs)
            {
                try
                {
                    PCISubSystem card = PCIIdentificationDatabase.GetSubSystem(gpu.VendorID, gpu.DeviceID, gpu.SubsystemVendorID, gpu.SubsystemDeviceID);
                    cards.Add(card.SubSystemName);
                }
                catch (System.NullReferenceException)
                {
                    try
                    {
                        PCIDevice cardalt = PCIIdentificationDatabase.GetDevice(gpu.VendorID, gpu.DeviceID);
                        cards.Add(cardalt.DeviceName.ToString());
                    }
                    catch
                    {
                        cards.Add("unknown");
                    }
                }
            }
            return(cards);
        }
Esempio n. 3
0
        private void StartDevice(PCIDeviceDriverRegistryEntry driver, Device device, PCIDevice pciDevice)
        {
            var ioPortRegions = new List <IOPortRegion>();
            var memoryRegions = new List <AddressRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                if (pciBaseAddress == null || pciBaseAddress.Size == 0)
                {
                    continue;
                }

                switch (pciBaseAddress.Region)
                {
                case AddressType.IO: ioPortRegions.Add(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;

                case AddressType.Memory: memoryRegions.Add(new AddressRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;

                default: break;
                }
            }

            //foreach (var ioportregion in ioPortRegions)
            //{
            //	HAL.DebugWriteLine("  I/O: 0x" + ioportregion.BaseIOPort.ToString("X") + " [" + ioportregion.Size.ToString("X") + "]");
            //}
            //foreach (var memoryregion in memoryRegions)
            //{
            //	HAL.DebugWriteLine("  Memory: 0x" + memoryregion.BaseAddress.ToString("X") + " [" + memoryregion.Size.ToString("X") + "]");
            //}

            var hardwareResources = new HardwareResources(ioPortRegions, memoryRegions, pciDevice.IRQ);

            DeviceService.Initialize(driver, device, driver.AutoStart, null, hardwareResources);
        }
Esempio n. 4
0
        private static void LoadATA()
        {
            PCIDevice xDevice = PCI.GetDeviceClass(0x1, 0x1); //Media Storage - IDE Controller

            if (xDevice != null)
            {
                //We are going to support only parallel ata
                PrimaryIDE  = new IDE(false);
                SecondayIDE = new IDE(true);

                if (PrimaryIDE.DriveInfo.Device != Device.IDE_None)
                {
                    Devices.Add(PrimaryIDE);
                    xINT.RegisterHandler(delegate() { PrimaryIDE.IRQInvoked = true; }, 0x2E);
                }

                if (SecondayIDE.DriveInfo.Device != Device.IDE_None)
                {
                    Devices.Add(SecondayIDE);
                    xINT.RegisterHandler(delegate() { SecondayIDE.IRQInvoked = true; }, 0x2F);
                }
            }

            /*
             * xDevice = PCI.GetDeviceClass(0x1, 0x6);//Media Storage - SATA
             * if (xDevice != null)
             * {
             *
             * }*/
        }
Esempio n. 5
0
 private static void CheckFunction(PCIDevice xPCIDevice)
 {
     HAL.PCIDevices.Add(xPCIDevice);
     if (xPCIDevice.ClassCode == 0x6 && xPCIDevice.Subclass == 0x4)
     {
         CheckBus(xPCIDevice.SecondaryBusNumber);
     }
 }
Esempio n. 6
0
 public ES1370(PCIDevice device) : base(device)
 {
     isr = (InterruptStatusRegister.Load(getMemReference()));
     sir = (SerialInterfaceRegister.Load(getMemReference()));
     uir = (UARTInterfaceRegister.Load(getMemReference()));
     cr  = (ControlRegister.Load(getMemReference()));
     //dacs.Add(new AK(new DACak4531(), cr.DAC1Enabled,(byte)MainRegister.Bit.SerialIntContr,MainRegister.Bit.Dac1FrameAddr, (byte)MainRegister.Bit.Dac1FrameSize));
     //dacs.Add(new DACManager(new DACak4531(), cr.DAC2Enabled, (byte)MainRegister.Bit.SerialIntContr, (byte)MainRegister.Bit.Dac2FrameAddr, (byte)MainRegister.Bit.Dac2FrameSize));
 }
Esempio n. 7
0
File: PCI.cs Progetto: iSalva/Cosmos
 private static void AddDevice(PCIDevice device, uint step)
 {
     string str = "";
     for (int i = 0; i < step; i++)
         str += "     ";
     Console.WriteLine(str + device.bus + ":" + device.slot + ":" + device.function + "   " + PCIDevice.DeviceClass.GetString(device));
     devices.Add(device);
     if (device is PCIDeviceBridge)
         EnumerateBus(((PCIDeviceBridge)device).SecondaryBusNumber, step + 1);
 }
Esempio n. 8
0
 public GenericSoundCard(PCIDevice device){
     if (device == null)
         throw new ArgumentException("PCI Device is null. Unable to get "+this.GetType()+" card");
     pciCard = device;
     mem = device.GetAddressSpace(1) as Cosmos.Kernel.MemoryAddressSpace;
     
     dacs = new List<DACManager>();
     adcs = new List<ADCManager>();
     uarts = new List<UARTManager>();
 }
Esempio n. 9
0
        public RTL8139(PCIDevice device)
        {
            if (device == null)
            {
                throw new ArgumentException("PCI Device is null. Unable to get Realtek 8139 card");
            }
            pciCard = device;

            // We are handling this device
            pciCard.Claimed = true;

            // Setup interrupt handling
            //Interrupts.IRQ11 += HandleNetworkInterrupt;
            //Interrupts.AddIRQHandler(device.InterruptLine, HandleNetworkInterrupt);

            // Get IO Address from PCI Bus
            io = pciCard.GetAddressSpace(0);

            // Enable the card
            pciCard.EnableDevice();

            // Turn on the card
            io.Write8(0x52, 0x01);

            //Do a software reset
            SoftwareReset();

            // Get the MAC Address
            byte[] eeprom_mac = new byte[6];
            for (uint b = 0; b < 6; b++)
            {
                eeprom_mac[b] = io.Read8(b);
            }

            this.mac = new MACAddress(eeprom_mac);

            // Get a receive buffer and assign it to the card
            rxBuffer = new ManagedMemorySpace(RxBufferSize + 2048 + 16, 4);

            RBStartRegister = rxBuffer.Offset;

            // Setup receive Configuration
            RecvConfigRegister = 0xF381;
            // Setup Transmit Configuration
            TransmitConfigRegister = 0x3000300;

            // Setup Interrupts
            IntMaskRegister   = 0x7F;
            IntStatusRegister = 0xFFFF;

            // Setup our Receive and Transmit Queues
            mRecvBuffer     = new Queue <byte[]>();
            mTransmitBuffer = new Queue <byte[]>();
        }
Esempio n. 10
0
 public PS2Keyboard(PCIDevice host) : base(host)
 {
     Label  = "PS2 Keyboard";
     buffer = new CircularBuffer(32);
     states = new byte[255];
     for (int i = 0; i < 255; i++)
     {
         states[i] = 0;
     }
     ISR.SetIntHandler(1, Handler);
 }
Esempio n. 11
0
        protected int GetMatchedPriority(PCIDeviceDriverRegistryEntry driver, PCIDevice pciDevice)
        {
            bool VendorID          = HasFlag(driver.PCIFields, PCIField.VendorID);
            bool DeviceID          = HasFlag(driver.PCIFields, PCIField.DeviceID);
            bool SubSystemID       = HasFlag(driver.PCIFields, PCIField.SubSystemID);
            bool SubSystemVendorID = HasFlag(driver.PCIFields, PCIField.SubSystemVendorID);
            bool ClassCode         = HasFlag(driver.PCIFields, PCIField.ClassCode);
            bool SubClassCode      = HasFlag(driver.PCIFields, PCIField.SubClassCode);
            bool ProgIF            = HasFlag(driver.PCIFields, PCIField.ProgIF);
            bool RevisionID        = HasFlag(driver.PCIFields, PCIField.RevisionID);

            if (VendorID && DeviceID && ClassCode && SubClassCode && ProgIF && RevisionID)
            {
                return(1);
            }
            else if (VendorID && DeviceID && ClassCode && SubClassCode && ProgIF)
            {
                return(2);
            }
            else if (VendorID && DeviceID && SubSystemVendorID && SubSystemID && RevisionID)
            {
                return(3);
            }
            else if (VendorID && DeviceID && SubSystemVendorID && SubSystemID)
            {
                return(4);
            }
            else if (VendorID && DeviceID && RevisionID)
            {
                return(5);
            }
            else if (VendorID && DeviceID)
            {
                return(6);
            }
            else if (ClassCode && SubClassCode && ProgIF && RevisionID)
            {
                return(7);
            }
            else if (ClassCode && SubClassCode && ProgIF)
            {
                return(8);
            }
            else if (ClassCode && SubClassCode && RevisionID)
            {
                return(9);
            }
            else if (ClassCode && SubClassCode)
            {
                return(10);
            }

            return(0);
        }
Esempio n. 12
0
        /// <summary>
        /// Reads the configuration.
        /// </summary>
        /// <returns></returns>
        protected byte ReadConfig8()
        {
            PCIDevice pciDevice = GetPCIDevice();

            if (pciDevice == null)
            {
                return(0xFF);
            }

            return(pciDevice.ReadConfig8((byte)(address & 0xFF)));
        }
Esempio n. 13
0
 public RTL8139_Old(PCIDevice device)
 {
     if (device == null)
     {
         throw new ArgumentException("PCI Device is null. Unable to get RTL8139 card");
     }
     pciCard  = device;
     mem      = device.GetAddressSpace(1) as Kernel.MemoryAddressSpace;
     valueReg = Register.ValueTypeRegisters.Load(mem);
     imr      = Register.InterruptMaskRegister.Load(mem);
     isr      = Register.InterruptStatusRegister.Load(mem);
 }
Esempio n. 14
0
        public GenericSoundCard(PCIDevice device)
        {
            if (device == null)
            {
                throw new ArgumentException("PCI Device is null. Unable to get " + this.GetType() + " card");
            }
            pciCard = device;
            mem     = device.GetAddressSpace(1) as Cosmos.Kernel.MemoryAddressSpace;

            dacs  = new List <DACManager>();
            adcs  = new List <ADCManager>();
            uarts = new List <UARTManager>();
        }
Esempio n. 15
0
        public static void Init(bool debug = true)
        {
            if (debug)
            {
                CustomConsole.WriteLineInfo("Finding nic...");
            }

            PCIDevice RTL8168 = PCI.GetDevice((VendorID)0x10EC, (DeviceID)0x8168);

            if (RTL8168 != null)
            {
                if (debug)
                {
                    CustomConsole.WriteLineOK("Found RTL8168 NIC on PCI " + RTL8168.bus + ":" + RTL8168.slot + ":" + RTL8168.function);
                    CustomConsole.WriteLineInfo("NIC IRQ: " + RTL8168.InterruptLine);
                }
                RTL8168NIC = new HAL.Drivers.Network.RTL8168(RTL8168);
                if (debug)
                {
                    CustomConsole.WriteLineInfo("NIC MAC Address: " + RTL8168NIC.MACAddress.ToString());
                }
                Network.NetworkStack.Init();
                RTL8168NIC.Enable();
            }
            PCIDevice AMDPCNETII = PCI.GetDevice(VendorID.AMD, DeviceID.PCNETII);

            if (AMDPCNETII != null)
            {
                if (debug)
                {
                    CustomConsole.WriteLineOK("Found AMDPCNETII NIC on PCI " + AMDPCNETII.bus + ":" + AMDPCNETII.slot + ":" + AMDPCNETII.function);
                    CustomConsole.WriteLineInfo("NIC IRQ: " + AMDPCNETII.InterruptLine);
                }
                AMDPCNetIINIC = new HAL.Drivers.Network.AMDPCNetII(AMDPCNETII);
                if (debug)
                {
                    CustomConsole.WriteLineInfo("NIC MAC Address: " + AMDPCNetIINIC.MACAddress.ToString());
                }
                Network.NetworkStack.Init();
                AMDPCNetIINIC.Enable();
            }
            if (RTL8168 == null && AMDPCNETII == null)
            {
                CustomConsole.WriteLineError("No supported network card found!!");
                return;
            }
            if (debug)
            {
                CustomConsole.WriteLineOK("Network initialization done!");
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Retrieve all AMD PCNetII network cards found on computer.
        /// </summary>
        public static void FindAll()
        {
            Console.WriteLine("Scanning for AMD PCNetII cards...");
            PCIDevice device = Cosmos.HAL.PCI.GetDevice(0x1022, 0x2000);

            if (device != null)
            {
                AMDPCNetII nic = new AMDPCNetII((PCIDeviceNormal)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());
            }
        }
Esempio n. 17
0
        public Intel8254X(PCIDevice dev)
        {
            this.dev = dev;
            dev.EnableDevice();
            BAR0 = (uint)(dev.BAR0 & (~3));
            INTs.SetIrqHandler(dev.InterruptLine, HandleIRQ);

            var HasEEPROM = DetectEEPROM();

            //Read the mac address
            if (!HasEEPROM)
            {
                address = new MACAddress(new byte[] { Read1ByteRegister(BAR0 + 0x5400), Read1ByteRegister(BAR0 + 0x5401), Read1ByteRegister(BAR0 + 0x5402), Read1ByteRegister(BAR0 + 0x5403), Read1ByteRegister(BAR0 + 0x5404), Read1ByteRegister(BAR0 + 0x5405) });
            }
            else
            {
                var firstWord  = ReadROM(0);
                var secondWord = ReadROM(1);
                var thirdWord  = ReadROM(2);
                address = new MACAddress(new byte[] {
                    (byte)(firstWord & 0xFF),
                    (byte)(firstWord >> 8),
                    (byte)(secondWord & 0xFF),
                    (byte)(secondWord >> 8),
                    (byte)(thirdWord & 0xFF),
                    (byte)(thirdWord >> 8)
                });
            }

            LinkUp();

            //zero out the MTA (multicast tabel array)
            for (int i = 0; i < 0x80; i++)
            {
                WriteRegister((ushort)(0x5200 + i * 4), 0);
            }

            //Enable interupts
            WriteRegister(REG_IMASK, 0x1F6DC);
            WriteRegister(REG_IMASK, 0xFF & ~4);
            ReadRegister(0xC0);

            RXInitialize();
            TXInitialize();
        }
Esempio n. 18
0
        protected bool IsMatch(PCIDeviceDriverRegistryEntry driver, PCIDevice pciDevice)
        {
            if (HasFlag(driver.PCIFields, PCIField.VendorID) && driver.VendorID != pciDevice.VendorID)
            {
                return(false);
            }

            if (HasFlag(driver.PCIFields, PCIField.DeviceID) && driver.DeviceID != pciDevice.DeviceID)
            {
                return(false);
            }

            if (HasFlag(driver.PCIFields, PCIField.SubSystemID) && driver.SubSystemID != pciDevice.SubSystemID)
            {
                return(false);
            }

            if (HasFlag(driver.PCIFields, PCIField.SubSystemVendorID) && driver.SubSystemVendorID != pciDevice.SubSystemVendorID)
            {
                return(false);
            }

            if (HasFlag(driver.PCIFields, PCIField.ClassCode) && driver.ClassCode != pciDevice.ClassCode)
            {
                return(false);
            }

            if (HasFlag(driver.PCIFields, PCIField.SubClassCode) && driver.SubClassCode != pciDevice.SubClassCode)
            {
                return(false);
            }

            if (HasFlag(driver.PCIFields, PCIField.ProgIF) && driver.ProgIF != pciDevice.ProgIF)
            {
                return(false);
            }

            if (HasFlag(driver.PCIFields, PCIField.RevisionID) && driver.RevisionID != pciDevice.RevisionID)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 19
0
        public static void DetectHyperVisor()
        {
            AreaInfo.HALDevInfo.WriteDevicePrefix("VIRT", "Detecting host platform...");
            PCIDevice Virtualizor = PCI.GetDevice((VendorID)PCIDevicesExtended.VendorID.Virtualbox, (DeviceID)PCIDevicesExtended.DeviceID.VirtualBox);

            Kernel.VM   = Kernel.Hypervisor.VirtualBox;
            Kernel.Host = PCIDevicesExtended.DeviceIDStr(PCIDevicesExtended.DeviceID.VirtualBox);
            if (Virtualizor == null)
            {
                Virtualizor = PCI.GetDevice(VendorID.VMWare, DeviceID.SVGAIIAdapter);
                Kernel.VM   = Kernel.Hypervisor.VMWare;
                Kernel.Host = PCIDevicesExtended.VendorIDStr(PCIDevicesExtended.VendorID.VMWare);
                if (Virtualizor == null)
                {
                    Kernel.IsVirtualised = false;
                    Kernel.VM            = Kernel.Hypervisor.RealShit;
                    Kernel.Host          = "Non-virtualised hardware or unrecognised host";
                }
            }
        }
Esempio n. 20
0
        public PS2Mouse(PCIDevice host) : base(host)
        {
            Label = "PS2 Mouse";
            WaitSignal();
            IOPort.outb(p64, 0xA8);
            WaitSignal();
            IOPort.outb(p64, 0x20);
            WaitData();
            byte status = (byte)(IOPort.inb(p60) | 2);

            WaitSignal();
            IOPort.outb(p64, 0x60);
            WaitSignal();
            IOPort.outb(p60, status);
            Write(0xF6);
            Read();
            Write(0xF4);
            Read();
            ISR.SetIntHandler(12, HandleMouse);
        }
Esempio n. 21
0
        /// <summary>
        /// Writes the configuration.
        /// </summary>
        /// <param name="data">The data.</param>
        protected void WriteConfig32(uint data)
        {
            PCIDevice pciDevice = GetPCIDevice();

            if (pciDevice == null)
            {
                return;
            }

            byte registry = (byte)(address & 0xFF);
            uint index    = GetIndex();

            uint barMask = 0xFFFFFFFF;

            if ((registry >= 0x10) && (registry < 0x28))
            {
                barMask = GetBarMask((byte)((index - 0x10) >> 2));
            }

            pciDevice.WriteConfig32(registry, data & barMask & GetWriteMask32(registry));
        }
Esempio n. 22
0
        public VMWareSVGAII()
        {
            device = (HAL.PCI.GetDevice(HAL.VendorID.VMWare, HAL.DeviceID.SVGAIIAdapter));
            device.EnableMemory(true);
            uint basePort = device.BaseAddressBar[0].BaseAddress;

            IndexPort = new IOPort((ushort)(basePort + (uint)IOPortOffset.Index));
            ValuePort = new IOPort((ushort)(basePort + (uint)IOPortOffset.Value));
            BiosPort  = new IOPort((ushort)(basePort + (uint)IOPortOffset.Bios));
            IRQPort   = new IOPort((ushort)(basePort + (uint)IOPortOffset.IRQ));

            WriteRegister(Register.ID, (uint)ID.V2);
            if (ReadRegister(Register.ID) != (uint)ID.V2)
            {
                return;
            }

            Video_Memory = new MemoryBlock(ReadRegister(Register.FrameBufferStart), ReadRegister(Register.VRamSize));
            capabilities = ReadRegister(Register.Capabilities);
            InitializeFIFO();
        }
Esempio n. 23
0
 private static void CheckBus(ushort xBus)
 {
     for (ushort device = 0; device < 32; device++)
     {
         if (PCIDevice.GetVendorID(xBus, device, 0x0) == 0xFFFF)
         {
             continue;
         }
         CheckFunction(new PCIDevice(xBus, device, 0x0));
         if ((PCIDevice.GetHeaderType(xBus, device, 0x0) & 0x80) != 0)
         {
             for (ushort fn = 1; fn < 8; fn++)
             {
                 if (PCIDevice.GetVendorID(xBus, device, fn) != 0xFFFF)
                 {
                     CheckFunction(new PCIDevice(xBus, device, fn));
                 }
             }
         }
     }
 }
Esempio n. 24
0
 public static void PCISetup()
 {
     HAL.dArea = deviceArea.PCI;
     AreaInfo.HALDevInfo.WriteDevicePrefix("PCI", "Detecting PCI Devices...");
     HAL.PCIDevices = new List <PCIDevice>();
     if ((PCIDevice.GetHeaderType(0x0, 0x0, 0x0) & 0x80) == 0)
     {
         CheckBus(0x0);
     }
     else
     {
         for (ushort fn = 0; fn < 8; fn++)
         {
             if (PCIDevice.GetVendorID(0x0, 0x0, fn) != 0xFFFF)
             {
                 break;
             }
             CheckBus(fn);
         }
     }
 }
Esempio n. 25
0
        public NVIDIA9500MGS(PCIDevice host) : base(host)
        {
            Label    = "NVIDIA 9500MGS";
            instance = this;
            Settings.EnterVideoMode = EnterGraphicsMode;
            host.EnableMemory(true);

            uint basePort = ((PCIDeviceNormal)host).BaseAddresses[0].BaseAddress();

            IndexPort = ((ushort)(basePort + (uint)IOPortOffset.Index));
            ValuePort = ((ushort)(basePort + (uint)IOPortOffset.Value));
            BiosPort  = ((ushort)(basePort + (uint)IOPortOffset.Bios));
            IRQPort   = ((ushort)(basePort + (uint)IOPortOffset.IRQ));

            WriteRegister(Register.ID, (uint)ID.V2);
            if (ReadRegister(Register.ID) != (uint)ID.V2)
            {
                return;
            }

            VIDEO_MEMORY = new Cosmos.Core.MemoryBlock(ReadRegister(Register.FrameBufferStart), ReadRegister(Register.VRamSize));
            capabilities = ReadRegister(Register.Capabilities);
            InitializeFIFO();
        }
Esempio n. 26
0
 /// <summary>
 /// Reads from configuration space
 /// </summary>
 /// <param name="pciDevice">The PCI Device.</param>
 /// <param name="register">The register.</param>
 /// <returns></returns>
 byte IPCIController.ReadConfig8(PCIDevice pciDevice, byte register)
 {
     configAddress.Write32(GetIndex(pciDevice.Bus, pciDevice.Slot, pciDevice.Function, register));
     return((byte)((configData.Read32() >> ((register % 4) * 8)) & 0xFF));
 }
Esempio n. 27
0
        public static void Execute(CommandExecutionContext *context)
        {
            TextMode.WriteLine("Device Resources:");

            Device[] devices = DeviceManager.GetDevices();

            foreach (Device device in devices)
            {
                if (!(device is PCIDevice))
                {
                    continue;
                }

                TextMode.Write("Resource: ");
                TextMode.Write(device.Name);

                if (device.Parent != null)
                {
                    TextMode.Write(" - Parent: ");
                    TextMode.Write(device.Parent.Name);
                }
                TextMode.WriteLine();

                if (device is PCIDevice)
                {
                    PCIDevice pciDevice = (device as PCIDevice);

                    TextMode.Write("  Vendor:0x");
                    TextMode.Write(pciDevice.VendorID.ToString("X"));
                    TextMode.Write(" Device:0x");
                    TextMode.Write(pciDevice.DeviceID.ToString("X"));
                    TextMode.Write(" Class:0x");
                    TextMode.Write(pciDevice.ClassCode.ToString("X"));
                    TextMode.Write(" Rev:0x");
                    TextMode.Write(pciDevice.RevisionID.ToString("X"));
                    TextMode.WriteLine();

                    foreach (PCIBaseAddress address in pciDevice.BaseAddresses)
                    {
                        if (address.Address != 0)
                        {
                            TextMode.Write("    ");
                            //TextMode.WriteLine (address.ToString ());

                            if (address.Region == AddressRegion.IO)
                            {
                                TextMode.Write("I/O Port at 0x");
                            }
                            else
                            {
                                TextMode.Write("Memory at 0x");
                            }

                            TextMode.Write(address.Address.ToString("X"));

                            TextMode.Write(" [size=");

                            if ((address.Size & 0xFFFFF) == 0)
                            {
                                TextMode.Write((address.Size >> 20).ToString());
                                TextMode.Write("M");
                            }
                            else if ((address.Size & 0x3FF) == 0)
                            {
                                TextMode.Write((address.Size >> 10).ToString());
                                TextMode.Write("K");
                            }
                            else
                            {
                                TextMode.Write(address.Size.ToString());
                            }

                            TextMode.Write("]");

                            if (address.Prefetchable)
                            {
                                TextMode.Write("(prefetchable)");
                            }

                            TextMode.WriteLine();
                        }
                    }

                    if (pciDevice.IRQ != 0)
                    {
                        TextMode.Write("    ");
                        TextMode.Write("IRQ at ");
                        TextMode.Write(pciDevice.IRQ.ToString());
                        TextMode.WriteLine();
                    }
                }
            }
        }
Esempio n. 28
0
        public VT6102(PCIDevice device)
        {
            if (device == null)
            {
                throw new ArgumentException("PCI Device is null. Unable to get VIA Rhine-II card");
            }
            pciCard = device;

            // We are handling this device
            pciCard.Claimed = true;

            // Setup interrupt handling
            //Interrupts.IRQ10 += HandleNetworkInterrupt;
            //Interrupts.AddIRQHandler(device.InterruptLine, HandleNetworkInterrupt);

            // Get IO Address from PCI Bus
            io = pciCard.GetAddressSpace(0) as Kernel.IOAddressSpace;

            // Enable the card
            pciCard.EnableDevice();

            // Get the EEPROM MAC Address and set it as the devices MAC
            byte[] eeprom_mac = new byte[6];
            UInt32 result = io.Read32(0x00);
            eeprom_mac[0] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[1] = BinaryHelper.GetByteFrom32bit(result, 8);
            eeprom_mac[2] = BinaryHelper.GetByteFrom32bit(result, 16);
            eeprom_mac[3] = BinaryHelper.GetByteFrom32bit(result, 24);
            result = io.Read32(0x04);
            eeprom_mac[4] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[5] = BinaryHelper.GetByteFrom32bit(result, 8);

            mac = new MACAddress(eeprom_mac);

            // Software Reset device
            SoftwareReset();

            // Configure Receive Config
            ReceiveConfigRegister = 0x1C;
            // Configure Transmit Config
            TransmitConfigRegister = 0x04;

            // Setup RX Descriptors
            mRxDescriptors = new ManagedMemorySpace(256, 16);

            // Setup TX Descriptors
            mTxDescriptors = new ManagedMemorySpace(256, 16);

            /* Initialize the RX and TX buffers, and set up the RX  descriptors to point
               to the buffers. Also, mark the RX descriptors as being owned by the card so data 
               can be received in them */
            mRxBuffers = new List<ManagedMemorySpace>();
            for (uint rxd = 0; rxd < 16; rxd++)
            {
                uint xOffset = rxd * 16;

                ManagedMemorySpace buffer = new ManagedMemorySpace(2048);
                mRxDescriptors.Write32(xOffset + 12, mRxDescriptors.Offset + xOffset + 16);
                mRxDescriptors.Write32(xOffset + 8, buffer.Offset);
                mRxDescriptors.Write32(xOffset + 4, buffer.Size);
                mRxDescriptors.Write32(xOffset, 0x80000000);
                mRxBuffers.Add(buffer);
            }
            mRxDescriptors.Write32(252, mRxDescriptors.Offset);
            for (uint txd = 0; txd < 16; txd++)
            {
                uint xOffset = txd * 16;

                mTxDescriptors.Write32(xOffset + 12, mTxDescriptors.Offset + xOffset + 16);
                mTxDescriptors.Write32(xOffset + 8, 0);
                mTxDescriptors.Write32(xOffset + 4, 0);
                mTxDescriptors.Write32(xOffset, 0);
            }
            mTxDescriptors.Write32(252, mTxDescriptors.Offset);

            mNextTXDesc = 0;

            RxDescAddressRegister = mRxDescriptors.Offset;
            TxDescAddressRegister = mTxDescriptors.Offset;

            // Setup and clear interrupts
            IntMaskRegister = 0xFFFF;
            IntStatusRegister = 0xFFFF;

            // Setup our Receive and Transmit Queues
            mTransmitBuffer = new Queue<byte[]>();
            mRecvBuffer = new Queue<byte[]>();
        }
Esempio n. 29
0
 /// <summary>
 /// Reads from configuration space
 /// </summary>
 /// <param name="pciDevice">The PCI Device.</param>
 /// <param name="register">The register.</param>
 /// <returns></returns>
 uint IPCIController.ReadConfig32(PCIDevice pciDevice, byte register)
 {
     configAddress.Write32(GetIndex(pciDevice.Bus, pciDevice.Slot, pciDevice.Function, register));
     return(configData.Read32());
 }
Esempio n. 30
0
        public AMDPCNetII(PCIDevice device)
            : base()
        {
            if (device == null)
            {
                throw new ArgumentException("PCI Device is null. Unable to get AMD PCNet card");
            }

            this.pciCard         = device;
            this.pciCard.Claimed = true;
            this.pciCard.EnableDevice();

            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
            byte[] eeprom_mac = new byte[6];
            UInt32 result     = io.MAC1.DWord;

            eeprom_mac[0] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[1] = BinaryHelper.GetByteFrom32bit(result, 8);
            eeprom_mac[2] = BinaryHelper.GetByteFrom32bit(result, 16);
            eeprom_mac[3] = BinaryHelper.GetByteFrom32bit(result, 24);
            result        = io.MAC2.DWord;
            eeprom_mac[4] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[5] = BinaryHelper.GetByteFrom32bit(result, 8);

            mac = new MACAddress(eeprom_mac);

            mInitBlock    = new ManagedMemoryBlock(28, 4);
            mRxDescriptor = new ManagedMemoryBlock(256, 16);
            mTxDescriptor = new ManagedMemoryBlock(256, 16);

            mInitBlock.Write32(0x00, (0x4 << 28) | (0x4 << 20));
            mInitBlock.Write32(0x04,
                               (UInt32)(eeprom_mac[0] | (eeprom_mac[1] << 8) | (eeprom_mac[2] << 16) | (eeprom_mac[3] << 24)));
            mInitBlock.Write32(0x08, (UInt32)(eeprom_mac[4] | (eeprom_mac[5] << 8)));
            mInitBlock.Write32(0x0C, 0x0);
            mInitBlock.Write32(0x10, 0x0);
            mInitBlock.Write32(0x14, mRxDescriptor.Offset);
            mInitBlock.Write32(0x18, mTxDescriptor.Offset);

            InitializationBlockAddress = mInitBlock.Offset;
            SoftwareStyleRegister      = 0x03;

            mRxBuffers = new List <ManagedMemoryBlock>();
            mTxBuffers = new List <ManagedMemoryBlock>();
            for (uint rxd = 0; rxd < 16; rxd++)
            {
                uint xOffset = rxd * 16;

                ManagedMemoryBlock buffer = new ManagedMemoryBlock(2048);
                mRxDescriptor.Write32(xOffset + 8, buffer.Offset);
                UInt16 buffer_len = (UInt16)(~buffer.Size);
                buffer_len++;
                UInt32 flags = (UInt32)(buffer_len & 0x0FFF) | 0xF000 | 0x80000000;
                mRxDescriptor.Write32(xOffset + 4, flags);
                mRxBuffers.Add(buffer);
            }
            for (uint txd = 0; txd < 16; txd++)
            {
                uint xOffset = txd * 16;

                ManagedMemoryBlock buffer = new ManagedMemoryBlock(2048);
                mTxDescriptor.Write32(xOffset + 8, buffer.Offset);
                mTxBuffers.Add(buffer);
            }

            mNextTXDesc = 0;

            // Setup our Receive and Transmit Queues
            mTransmitBuffer = new Queue <byte[]>();
            mRecvBuffer     = new Queue <byte[]>();

            INTs.SetIrqHandler(device.InterruptLine, HandleNetworkInterrupt);
        }
Esempio n. 31
0
        // Initialize a new instance of the AMD PCNet device driver
        public AMDPCNet(PCIDevice device)
        {
            if (device == null)
            {
                throw new ArgumentException("PCI Device is null. Unable to get AMD PCNet card");
            }
            pciCard = device;

            // We are handling this device
            pciCard.Claimed = true;

            // Setup interrupt handling
            //Interrupts.IRQ09 += HandleNetworkInterrupt;
            //Interrupts.AddIRQHandler(device.InterruptLine, HandleNetworkInterrupt);

            // Get IO Address from PCI Bus
            io = (Kernel.IOAddressSpace)pciCard.GetAddressSpace(0);
            // Enable the card
            pciCard.EnableDevice();
            // Set the device into 32-bit mode
            io.Write32(0x10, 0);

            // Get the EEPROM MAC Address and set it as the devices MAC
            byte[] eeprom_mac = new byte[6];
            UInt32 result = io.Read32(0x00);
            eeprom_mac[0] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[1] = BinaryHelper.GetByteFrom32bit(result, 8);
            eeprom_mac[2] = BinaryHelper.GetByteFrom32bit(result, 16);
            eeprom_mac[3] = BinaryHelper.GetByteFrom32bit(result, 24);
            result = io.Read32(0x04);
            eeprom_mac[4] = BinaryHelper.GetByteFrom32bit(result, 0);
            eeprom_mac[5] = BinaryHelper.GetByteFrom32bit(result, 8);

            mac = new MACAddress(eeprom_mac);

            // Allocate 32 bytes for the 28 byte Initialization block that has to be aligned to a 4 byte boundary
            //UInt32 address = Heap.MemAlloc(0x20);
            //mInitBlock = new ManagedUInt32Array(7); // 7 UInt32's, aligned on a 4byte boundary
            mInitBlock = new ManagedMemorySpace(28, 4);
            /*Console.Write("Allocated 32 bytes for initialization block @ 0x" + address.ToHex(8));
            Console.WriteLine("(Aligned to 0x" + aligned_address.ToHex(8) + ")");*/

            // Allocate 80 uints for the 16 RX and TX Descriptor rings. These addresses have to be aligned on a 16-byte boundary
            mTxDescriptor = new ManagedMemorySpace(256, 16);
            mRxDescriptor = new ManagedMemorySpace(256, 16);
            /*Console.Write("Allocated 320 bytes for RX ring descriptors @ 0x" + rd_address.ToHex(8));
            Console.WriteLine("(Aligned to 0x" + mRxDescriptorAddress.ToHex(8) + ")");
            Console.Write("Allocated 320 bytes for TX ring descriptors @ 0x" + tx_address.ToHex(8));
            Console.WriteLine("(Aligned to 0x" + mTxDescriptorAddress.ToHex(8) + ")");*/

            // Fill in the Initialization block
            mInitBlock.Write32(0x00, (0x4 << 28) | (0x4 << 20));
            mInitBlock.Write32(0x04, (uint)(eeprom_mac[0] | (eeprom_mac[1] << 8) | (eeprom_mac[2] << 16) | (eeprom_mac[3] << 24)));
            mInitBlock.Write32(0x08, (uint)(eeprom_mac[4] | (eeprom_mac[5] << 8)));
            mInitBlock.Write32(0x0C, 0x0);
            mInitBlock.Write32(0x10, 0x0);
            mInitBlock.Write32(0x14, mRxDescriptor.Offset);
            mInitBlock.Write32(0x18, mTxDescriptor.Offset);

            // Write the Initialization blocks address to the registers on the card
            InitializationBlockAddress = mInitBlock.Offset;
            // Set the device to PCNet-PCI II Controller mode (full 32-bit mode)
            SoftwareStyleRegister = 0x03;

            /* Initialize the RX and TX buffers, and set up the RX and TX descriptors to point
               to the buffers. Also, mark the RX descriptors as being owned by the card so data 
               can be received in them */
            mRxBuffers = new List<ManagedMemorySpace>();
            mTxBuffers = new List<ManagedMemorySpace>();
            for (uint rxd = 0; rxd < 16; rxd++)
            {
                uint xOffset = rxd * 16;

                ManagedMemorySpace buffer = new ManagedMemorySpace(2048);
                mRxDescriptor.Write32(xOffset + 8, buffer.Offset);
                UInt16 buffer_len = (UInt16)(~buffer.Size);
                buffer_len++;
                UInt32 flags = (UInt32)(buffer_len & 0x0FFF) | 0xF000 | 0x80000000;
                mRxDescriptor.Write32(xOffset + 4, flags);
                mRxBuffers.Add(buffer);
            }
            for (uint txd = 0; txd < 16; txd++)
            {
                uint xOffset = txd * 16;

                ManagedMemorySpace buffer = new ManagedMemorySpace(2048);
                mTxDescriptor.Write32(xOffset + 8, buffer.Offset);
                mTxBuffers.Add(buffer);
            }

            // Set TX Descriptor 0 as the first one to use... Increment this when we use one to use them in a circular fashion
            mNextTXDesc = 0;

            // Setup our Receive and Transmit Queues
            mTransmitBuffer = new Queue<byte[]>();
            mRecvBuffer = new Queue<byte[]>();
        }
Esempio n. 32
0
        /// <summary>
        /// Creates a new instance of the <see cref="AC97"/> class, with the
        /// given buffer size.
        /// </summary>
        /// <param name="bufferSize">The buffer size in samples to use. This value cannot be an odd number, as per the AC97 specification.</param>
        /// <exception cref="ArgumentException">Thrown when the given buffer size is invalid.</exception>
        /// <exception cref="InvalidOperationException">Thrown when no AC97-compatible sound card is present.</exception>
        private AC97(ushort bufferSize)
        {
            if (bufferSize % 2 != 0)
            {
                // As per the AC97 specification, the buffer size cannot be odd.
                // (1.2.4.2 PCM Buffer Restrictions, Intel document 302349-003)
                throw new ArgumentException("The buffer size must be an even number.", nameof(bufferSize));
            }

            PCIDevice pci = Cosmos.HAL.PCI.GetDeviceClass(
                ClassID.MultimediaDevice, // 0x04
                (SubclassID)0x01          // 0x01
                );

            if (pci == null || !pci.DeviceExists || pci.InterruptLine > 0xF)
            {
                throw new InvalidOperationException("No AC97-compatible device could be found.");
            }

            PCI = pci; // Expose PCI device to the public API

            pci.EnableBusMaster(true);
            pci.EnableMemory(true);
            pci.EnableDevice(); // enable I/O space

            INTs.SetIrqHandler(pci.InterruptLine, HandleInterrupt);

            ushort NAMbar  = (ushort)pci.BaseAddressBar[0].BaseAddress; // Native Audio Mixer
            ushort NABMbar = (ushort)pci.BaseAddressBar[1].BaseAddress; // Native Audio Bus Master

            pTransferControl   = new IOPort((ushort)(NABMbar + 0x1B));
            pMasterVolume      = new IOPort((ushort)(NAMbar + 0x02));
            pPCMOutVolume      = new IOPort((ushort)(NAMbar + 0x18));
            pBufferDescriptors = new IOPort((ushort)(NABMbar + 0x10));
            pTransferStatus    = new IOPort((ushort)(NABMbar + 0x16));
            pLastValidEntry    = new IOPort((ushort)(NABMbar + 0x15));
            pGlobalControl     = new IOPort((ushort)(NABMbar + 0x2C));
            pResetRegister     = new IOPort((ushort)(NAMbar + 0x00));

            // Reset device
            pGlobalControl.Byte  = 0x2;
            pResetRegister.DWord = 0xDEADBEEF; // any value will do here

            // Reset PCM out
            uint polls = 0; // The amount we polled the device for a reset

            pTransferControl.Byte = (byte)(pTransferControl.Byte | TC_TRANSFER_RESET);
            while ((pTransferControl.Byte & TC_TRANSFER_RESET) != 0 && polls < RESET_POLL_LIMIT)
            {
                // Wait until the byte is cleared
                polls++;
            }

            // The device hasn't responded to our reset request. Probably not a fully-compatible AC97 card.
            if (polls >= RESET_POLL_LIMIT)
            {
                throw new InvalidOperationException("No AC97-compatible device could be found - the reset timeout has expired.");
            }

            // Volume
            pMasterVolume.Word = CreateMixerVolumeValue(AC97_VOLUME_MAX, AC97_VOLUME_MAX, false);
            pPCMOutVolume.Word = CreateMixerVolumeValue(AC97_VOLUME_MAX, AC97_VOLUME_MAX, false);

            // Create all needed buffers
            CreateBuffers(bufferSize);

            // Initialization done - driver can now be activated by using Enable()
        }
Esempio n. 33
0
 public USBHostOHCI(PCIDevice pcidev)
 {
     mydevice = pcidev as PCIDeviceNormal;
     regs = new USBHostOHCIRegisters(pcidev.GetAddressSpace(0) as MemoryAddressSpace);
 }
Esempio n. 34
0
        public RTL8168(PCIDevice device) : base()
        {
            if (device == null)
            {
                throw new ArgumentException("PCI Device is null. Unable to get Realtek 8168 card");
            }
            pciCard = device;

            // We are handling this device
            pciCard.Claimed = true;

            BaseAddress = this.pciCard.BaseAddressBar[0].BaseAddress;

            // Enable the card
            pciCard.EnableDevice();

            SetIrqHandler(device.InterruptLine, HandleNetworkInterrupt);

            Ports.outb((ushort)(BaseAddress + 0xE0), 0x08);

            Reset();

            // Get the MAC Address
            byte[] eeprom_mac = new byte[6];
            for (uint b = 0; b < 6; b++)
            {
                eeprom_mac[b] = Ports.inb((ushort)(BaseAddress + b));
            }

            this.mac = new MACAddress(eeprom_mac);

            InitBuffers();

            Console.WriteLine("Init buffers done!");

            Ports.outd((ushort)(BaseAddress + 0x44), 0x0000E70F); // Enable RX

            Ports.outd((ushort)(BaseAddress + 0x37), 0x04);

            Ports.outd((ushort)(BaseAddress + 0x40), 0x03000700); // Enable TX

            Ports.outd((ushort)(BaseAddress + 0xDA), 2048);       // Max rx packet size

            Ports.outb((ushort)(BaseAddress + 0xEC), 0x3F);       // No early transmit

            Ports.outd((ushort)(BaseAddress + 0x20), mTxDescriptor.Offset);
            Console.WriteLine("addresstx desc: 0x" + Utilities.Conversion.DecToHex((int)mTxDescriptor.Offset));

            Ports.outd((ushort)(BaseAddress + 0xE4), mRxDescriptor.Offset);
            Console.WriteLine("addressrx desc: 0x" + Utilities.Conversion.DecToHex((int)mRxDescriptor.Offset));

            if (((GetMacVersion() & 0x7cf00000) == 0x54100000) || ((GetMacVersion() & 0x7cf00000) == 0x54000000))
            {
                Console.WriteLine("8168H Detected!");

                Ports.outd((ushort)(BaseAddress + 0x40), Ports.ind((ushort)(BaseAddress + 0x40)) | (1 << 7)); // AUTO TX FIFO
            }

            Ports.outw((ushort)(BaseAddress + 0x3C), 0xC3FF); //Activating all Interrupts

            Ports.outb((ushort)(BaseAddress + 0x37), 0x0C);   // Enabling receive and transmit

            Console.WriteLine("Netcard version: 0x" + Utilities.Conversion.DecToHex((int)GetMacVersion() & 0x7cf00000));
            Console.WriteLine("Netcard version: 0x" + Utilities.Conversion.DecToHex((int)GetMacVersion() & 0x7c800000));
        }
Esempio n. 35
0
        public VMWareSVGAII()
        {
            Device = PCI.GetDeviceVendorID(misc.PCI_VENDOR_ID_VMWARE, misc.PCI_DEVICE_ID_VMWARE_SVGA2);

            if (Device == null)
            {
                throw new Exception("Device Not Found");
            }

            Device.EnableMemory(true);

            //IO Ports
            var IOBase = Device.BaseAddressBar[0].BaseAddress;

            IndexPort = new IOPort((ushort)(IOBase + (ushort)IOPortOffset.Index));
            ValuePort = new IOPort((ushort)(IOBase + (ushort)IOPortOffset.Value));

            //Memory Block
            FB_Memory   = new MemoryBlock32(Device.BaseAddressBar[1].BaseAddress);
            FIFO_Memory = new MemoryBlock32(Device.BaseAddressBar[2].BaseAddress);

            //Version Check
            VersionID = (UInt32)Versions.SVGA_ID_2;
            do
            {
                WriteRegister(Registers.SVGA_REG_ID, VersionID);
                if (ReadRegister(Registers.SVGA_REG_ID) == VersionID)
                {
                    break;
                }
                else
                {
                    VersionID--;
                }
            }while (VersionID >= (UInt32)Versions.SVGA_ID_0);

            if (VersionID < (UInt32)Versions.SVGA_ID_0)
            {
                throw new Exception("Error negotiating SVGA device version.");
            }

            //Memory Block Length
            FB_Memory.Length   = ReadRegister(Registers.SVGA_REG_FB_SIZE);
            FIFO_Memory.Length = ReadRegister(Registers.SVGA_REG_MEM_SIZE);

            //Memory Block Length Check
            if (FB_Memory.Length < 0x100000)
            {
                throw new Exception("FB size very small, probably incorrect.");
            }

            if (FIFO_Memory.Length < 0x20000)
            {
                throw new Exception("FIFO size very small, probably incorrect.");
            }

            if (VersionID >= (UInt32)Versions.SVGA_ID_1)
            {
                Capabilities = ReadRegister(Registers.SVGA_REG_CAPABILITIES);
            }
        }
Esempio n. 36
0
 /// <summary>
 /// Writes to configuration space
 /// </summary>
 /// <param name="pciDevice">The PCI Device.</param>
 /// <param name="register">The register.</param>
 /// <param name="value">The value.</param>
 void IPCIController.WriteConfig8(PCIDevice pciDevice, byte register, byte value)
 {
     configAddress.Write32(GetIndex(pciDevice.Bus, pciDevice.Slot, pciDevice.Function, register));
     configData.Write8(value);
 }