Example #1
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        static public void StartDevice(IPCIDevice pciDevice)
        {
            var deviceDriver = deviceDriverRegistry.FindDriver(pciDevice);

            if (deviceDriver == null)
            {
                pciDevice.SetNoDriverFound();
                return;
            }

            var hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType);

            if (hardwareDevice == null)
            {
                Mosa.Kernel.x86.Panic.Error("ERROR: hardwareDevice == null");
                return;
            }

            var iHardwareDevice = hardwareDevice as IHardwareDevice;

            if (iHardwareDevice == null)
            {
                Mosa.Kernel.x86.Panic.Error("ERROR: iHardwareDevice == null");
                return;
            }

            //Boot.Console.WriteLine("Found Driver");

            StartDevice(pciDevice, deviceDriver, iHardwareDevice);
        }
Example #2
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.HardwareSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList <IOPortRegion>();
            var memoryRegions = new LinkedList <MemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;

                case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;

                default: break;
                }
            }

            foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    var memory = Mosa.HardwareSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            foreach (var ioportregion in ioPortRegions)
            {
                Boot.Console.WriteLine("  I/O: 0x" + ioportregion.BaseIOPort.ToString("X") + " [" + ioportregion.Size.ToString("X") + "]");
            }

            foreach (var memoryregion in memoryRegions)
            {
                Boot.Console.WriteLine("  Memory: 0x" + memoryregion.BaseAddress.ToString("X") + " [" + memoryregion.Size.ToString("X") + "]");
            }

            //Boot.Console.WriteLine("  Command: 0x" + hardwareDevice...ToString("X"));

            var hardwareResources = new HardwareResources(
                ioPortRegions.ToArray(),
                memoryRegions.ToArray(),
                new InterruptHandler(InterruptManager, pciDevice.IRQ, hardwareDevice),
                pciDevice as IPCIDeviceResource
                );

            hardwareDevice.Setup(hardwareResources);

            deviceManager.Add(hardwareDevice);

            hardwareResources.EnableIRQ();

            if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
            {
                pciDevice.SetDeviceOnline();
            }
        }
Example #3
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        static public void StartDevice(IPCIDevice pciDevice)
        {
            DeviceDriver deviceDriver = deviceDriverRegistry.FindDriver(pciDevice);

            if (deviceDriver == null)
            {
                pciDevice.SetNoDriverFound();
                return;
            }

            IHardwareDevice hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice;

            // MR 07/21/09: Commenting out, causes mono xbuild to fail on MacOS X
            // PCIDeviceDriverAttribute attribute = deviceDriver.Attribute as PCIDeviceDriverAttribute;

            LinkedList <IIOPortRegion> ioPortRegions = new LinkedList <IIOPortRegion>();
            LinkedList <IMemoryRegion> memoryRegions = new LinkedList <IMemoryRegion>();

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

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

                default: break;
                }
            }

            foreach (DeviceDriverPhysicalMemoryAttribute memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    IMemory memory = HAL.RequestPhysicalMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.Add(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            HardwareResources hardwareResources = new HardwareResources(resourceManager, ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(resourceManager.InterruptManager, pciDevice.IRQ, hardwareDevice), pciDevice as IDeviceResource);

            if (resourceManager.ClaimResources(hardwareResources))
            {
                hardwareResources.EnableIRQ();
                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    pciDevice.SetDeviceOnline();
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        static public void StartDevice(IPCIDevice pciDevice)
        {
            var deviceDriver = deviceDriverRegistry.FindDriver(pciDevice);

            if (deviceDriver == null)
            {
                pciDevice.SetNoDriverFound();
                return;
            }

            var hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice;

            StartDevice(pciDevice, deviceDriver, hardwareDevice);
        }
Example #5
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.DeviceSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList <IIOPortRegion>();
            var memoryRegions = new LinkedList <IMemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;

                case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;

                default: break;
                }
            }

            foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    var memory = Mosa.DeviceSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            var hardwareResources = new HardwareResources(resourceManager, ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(resourceManager.InterruptManager, pciDevice.IRQ, hardwareDevice), pciDevice as IDeviceResource);

            if (resourceManager.ClaimResources(hardwareResources))
            {
                hardwareResources.EnableIRQ();
                hardwareDevice.Setup(hardwareResources);

                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    pciDevice.SetDeviceOnline();
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Finds the driver.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        /// <returns></returns>
        public DeviceDriver FindDriver(IPCIDevice pciDevice)
        {
            DeviceDriver bestDeviceDriver = null;
            int bestPriority = System.Int32.MaxValue;

            foreach (DeviceDriver deviceDriver in deviceDrivers) {
                if (deviceDriver.Attribute is PCIDeviceDriverAttribute) {
                    PCIDeviceDriverAttribute pciDeviceDriverAttribute = deviceDriver.Attribute as PCIDeviceDriverAttribute;
                    if ((pciDeviceDriverAttribute.Priority != 0) && (pciDeviceDriverAttribute.Priority < bestPriority)) {
                        if (pciDeviceDriverAttribute.CompareTo(pciDevice)) {
                            bestDeviceDriver = deviceDriver;
                            bestPriority = pciDeviceDriverAttribute.Priority;
                        }
                    }
                }
            }

            return bestDeviceDriver;
        }
Example #7
0
        /// <summary>
        /// Compares to.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        /// <returns></returns>
        public bool CompareTo(IPCIDevice pciDevice)
        {
            if (fields == 0)
            {
                return(false);
            }

            if (((fields & Field.VendorID) == Field.VendorID) && (pciDevice.VendorID != VendorID))
            {
                return(false);
            }
            if (((fields & Field.DeviceID) == Field.DeviceID) && (pciDevice.DeviceID != DeviceID))
            {
                return(false);
            }
            if (((fields & Field.SubVendorID) == Field.SubVendorID) && (pciDevice.SubVendorID != SubVendorID))
            {
                return(false);
            }
            if (((fields & Field.SubDeviceID) == Field.SubDeviceID) && (pciDevice.SubDeviceID != SubDeviceID))
            {
                return(false);
            }
            if (((fields & Field.RevisionID) == Field.RevisionID) && (pciDevice.RevisionID != RevisionID))
            {
                return(false);
            }
            if (((fields & Field.ProgIF) == Field.ProgIF) && (pciDevice.ProgIF != ProgIF))
            {
                return(false);
            }
            if (((fields & Field.ClassCode) == Field.ClassCode) && (pciDevice.ClassCode != ClassCode))
            {
                return(false);
            }
            if (((fields & Field.SubClassCode) == Field.SubClassCode) && (pciDevice.SubClassCode != SubClassCode))
            {
                return(false);
            }

            return(true);
        }
Example #8
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        static public void StartDevice(IPCIDevice pciDevice)
        {
            var deviceDriver = deviceDriverRegistry.FindDriver(pciDevice);

            if (deviceDriver == null)
            {
                pciDevice.SetNoDriverFound();
                return;
            }

            var hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType);

            StartDevice(pciDevice, deviceDriver, hardwareDevice as IHardwareDevice);

            if (pciDevice.VendorID == 0x15AD && pciDevice.DeviceID == 0x0405)
            {
                var display = hardwareDevice as IPixelGraphicsDevice;

                var color = new Color(255, 0, 0);

                display.WritePixel(color, 100, 100);
            }
        }
Example #9
0
        /// <summary>
        /// Finds the driver.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        /// <returns></returns>
        public DeviceDriver FindDriver(IPCIDevice pciDevice)
        {
            DeviceDriver bestDeviceDriver = null;
            int          bestPriority     = System.Int32.MaxValue;

            foreach (DeviceDriver deviceDriver in deviceDrivers)
            {
                if (deviceDriver.Attribute is PCIDeviceDriverAttribute)
                {
                    PCIDeviceDriverAttribute pciDeviceDriverAttribute = deviceDriver.Attribute as PCIDeviceDriverAttribute;
                    if ((pciDeviceDriverAttribute.Priority != 0) && (pciDeviceDriverAttribute.Priority < bestPriority))
                    {
                        if (pciDeviceDriverAttribute.CompareTo(pciDevice))
                        {
                            bestDeviceDriver = deviceDriver;
                            bestPriority     = pciDeviceDriverAttribute.Priority;
                        }
                    }
                }
            }

            return(bestDeviceDriver);
        }
Example #10
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        public static void StartDevice(IPCIDevice pciDevice)
        {
            DeviceDriver deviceDriver = deviceDriverRegistry.FindDriver(pciDevice);

            if (deviceDriver == null)
            {
                pciDevice.SetNoDriverFound();
                return;
            }

            IHardwareDevice hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice;

            LinkedList<IIOPortRegion> ioPortRegions = new LinkedList<IIOPortRegion>();
            LinkedList<IMemoryRegion> memoryRegions = new LinkedList<IMemoryRegion>();

            foreach (BaseAddress pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                    case AddressType.IO: ioPortRegions.Add(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;
                    case AddressType.Memory: memoryRegions.Add(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;
                    default: break;
                }
            }

            foreach (DeviceDriverPhysicalMemoryAttribute memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    IMemory memory = HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.Add(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            HardwareResources hardwareResources = new HardwareResources(resourceManager, ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(resourceManager.InterruptManager, pciDevice.IRQ, hardwareDevice), pciDevice as IDeviceResource);

            if (resourceManager.ClaimResources(hardwareResources))
            {
                hardwareResources.EnableIRQ();
                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    pciDevice.SetDeviceOnline();
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }
            }
        }
        /// <summary>
        /// Compares to.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        /// <returns></returns>
        public bool CompareTo(IPCIDevice pciDevice)
        {
            if (fields == 0)
                return false;

            if (((fields & Field.VendorID) == Field.VendorID) && (pciDevice.VendorID != VendorID))
                return false;
            if (((fields & Field.DeviceID) == Field.DeviceID) && (pciDevice.DeviceID != DeviceID))
                return false;
            if (((fields & Field.SubSystemVendorID) == Field.SubSystemVendorID) && (pciDevice.SubVendorID != SubSystemVendorID))
                return false;
            if (((fields & Field.SubSystemID) == Field.SubSystemID) && (pciDevice.SubSystemID != SubSystemID))
                return false;
            if (((fields & Field.RevisionID) == Field.RevisionID) && (pciDevice.RevisionID != RevisionID))
                return false;
            if (((fields & Field.ProgIF) == Field.ProgIF) && (pciDevice.ProgIF != ProgIF))
                return false;
            if (((fields & Field.ClassCode) == Field.ClassCode) && (pciDevice.ClassCode != ClassCode))
                return false;
            if (((fields & Field.SubClassCode) == Field.SubClassCode) && (pciDevice.SubClassCode != SubClassCode))
                return false;

            return true;
        }
Example #12
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.DeviceSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList<IIOPortRegion>();
            var memoryRegions = new LinkedList<IMemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                    case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;
                    case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;
                    default: break;
                }
            }

            foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    var memory = Mosa.DeviceSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            var hardwareResources = new HardwareResources(resourceManager, ioPortRegions.ToArray(), memoryRegions.ToArray(), new InterruptHandler(resourceManager.InterruptManager, pciDevice.IRQ, hardwareDevice), pciDevice as IDeviceResource);

            if (resourceManager.ClaimResources(hardwareResources))
            {
                hardwareResources.EnableIRQ();
                hardwareDevice.Setup(hardwareResources);

                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    pciDevice.SetDeviceOnline();
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }
            }
        }
Example #13
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        public static void StartDevice(IPCIDevice pciDevice)
        {
            var deviceDriver = deviceDriverRegistry.FindDriver(pciDevice);

            if (deviceDriver == null)
            {
                pciDevice.SetNoDriverFound();
                return;
            }

            var hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType);

            StartDevice(pciDevice, deviceDriver, hardwareDevice as IHardwareDevice);

            if (pciDevice.VendorID == 0x15AD && pciDevice.DeviceID == 0x0405)
            {
                var display = hardwareDevice as IPixelGraphicsDevice;

                var color = new Color(255, 0, 0);

                display.WritePixel(color, 100, 100);
            }
        }
Example #14
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        public static void StartDevice(IPCIDevice pciDevice)
        {
            var deviceDriver = deviceDriverRegistry.FindDriver(pciDevice);

            if (deviceDriver == null)
            {
                pciDevice.SetNoDriverFound();
                return;
            }

            var hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType);

            StartDevice(pciDevice, deviceDriver, hardwareDevice as IHardwareDevice);
        }
Example #15
0
        private static void StartDevice(IPCIDevice pciDevice, Mosa.HardwareSystem.DeviceDriver deviceDriver, IHardwareDevice hardwareDevice)
        {
            var ioPortRegions = new LinkedList<IOPortRegion>();
            var memoryRegions = new LinkedList<MemoryRegion>();

            foreach (var pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                    case AddressType.IO: ioPortRegions.AddLast(new IOPortRegion((ushort)pciBaseAddress.Address, (ushort)pciBaseAddress.Size)); break;
                    case AddressType.Memory: memoryRegions.AddLast(new MemoryRegion(pciBaseAddress.Address, pciBaseAddress.Size)); break;
                    default: break;
                }
            }

            foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    var memory = Mosa.HardwareSystem.HAL.AllocateMemory(memoryAttribute.MemorySize, memoryAttribute.MemoryAlignment);
                    memoryRegions.AddLast(new MemoryRegion(memory.Address, memory.Size));
                }
            }

            foreach (var ioportregion in ioPortRegions)
            {
                Boot.Console.WriteLine("  I/O: 0x" + ioportregion.BaseIOPort.ToString("X") + " [" + ioportregion.Size.ToString("X") + "]");
            }

            foreach (var memoryregion in memoryRegions)
            {
                Boot.Console.WriteLine("  Memory: 0x" + memoryregion.BaseAddress.ToString("X") + " [" + memoryregion.Size.ToString("X") + "]");
            }

            //Boot.Console.WriteLine("  Command: 0x" + hardwareDevice...ToString("X"));

            var hardwareResources = new HardwareResources(
                ioPortRegions.ToArray(),
                memoryRegions.ToArray(),
                new InterruptHandler(InterruptManager, pciDevice.IRQ, hardwareDevice),
                pciDevice as IPCIDeviceResource
            );

            hardwareDevice.Setup(hardwareResources);

            deviceManager.Add(hardwareDevice);

            hardwareResources.EnableIRQ();

            if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
            {
                pciDevice.SetDeviceOnline();
            }
        }
Example #16
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="pciDevice">The pci device.</param>
        public static void StartDevice(IPCIDevice pciDevice)
        {
            var deviceDriver = deviceDriverRegistry.FindDriver(pciDevice);

            if (deviceDriver == null)
            {
                pciDevice.SetNoDriverFound();
                return;
            }

            var hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType);

            if (hardwareDevice == null)
            {
                Mosa.Kernel.x86.Panic.Error("ERROR: hardwareDevice == null");
                return;
            }

            var iHardwareDevice = hardwareDevice as IHardwareDevice;

            if (iHardwareDevice == null)
            {
                Mosa.Kernel.x86.Panic.Error("ERROR: iHardwareDevice == null");
                return;
            }

            //Boot.Console.WriteLine("Found Driver");

            StartDevice(pciDevice, deviceDriver, iHardwareDevice);
        }