Example #1
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;

            int ioRegionCount = 0;
            int memoryRegionCount = 0;

            foreach (BaseAddress pciBaseAddress in pciDevice.BaseAddresses)
            {
                switch (pciBaseAddress.Region)
                {
                    case AddressType.IO: ioRegionCount++; break;
                    case AddressType.Memory: memoryRegionCount++; break;
                    default: break;
                }
            }

            foreach (DeviceDriverPhysicalMemoryAttribute memoryAttribute in deviceDriver.MemoryAttributes)
            {
                if (memoryAttribute.MemorySize > 0)
                {
                    memoryRegionCount++;
                }
            }

            IIOPortRegion[] ioPortRegions = new IIOPortRegion[ioRegionCount];
            IMemoryRegion[] memoryRegions = new IMemoryRegion[memoryRegionCount];

            int ioRegionIndex = 0;
            int memoryRegionIndex = 0;

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

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

            HardwareResources hardwareResources = new HardwareResources(resourceManager, ioPortRegions, memoryRegions, 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 #2
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="deviceDriver">The device driver.</param>
        public static void StartDevice(ISADeviceDriverAttribute driverAtttribute, IHardwareDevice hardwareDevice)
        {
            int ioRegionCount = 1;
            int memoryRegionCount = 0;

            if (driverAtttribute.AltBasePort != 0x00)
            {
                ioRegionCount++;
            }

            if (driverAtttribute.BaseAddress != 0x00)
                memoryRegionCount++;

            IIOPortRegion[] ioPortRegions = new IIOPortRegion[ioRegionCount];
            IMemoryRegion[] memoryRegions = new IMemoryRegion[memoryRegionCount];

            ioPortRegions[0] = new IOPortRegion(driverAtttribute.BasePort, driverAtttribute.PortRange);

            if (driverAtttribute.AltBasePort != 0x00)
            {
                ioPortRegions[1] = new IOPortRegion(driverAtttribute.AltBasePort, driverAtttribute.AltPortRange);
            }

            if (driverAtttribute.BaseAddress != 0x00)
            {
                memoryRegions[0] = new MemoryRegion(driverAtttribute.BaseAddress, driverAtttribute.AddressRange);
            }

            IHardwareResources hardwareResources = new HardwareResources(resourceManager, ioPortRegions, memoryRegions, new InterruptHandler(resourceManager.InterruptManager, driverAtttribute.IRQ, hardwareDevice));

            hardwareDevice.Setup(hardwareResources);

            Mosa.Kernel.x86.Screen.NextLine();
            Mosa.CoolWorld.x86.Boot.BulletPoint();
            Console.Write("Adding device ");
            Boot.InBrackets(hardwareDevice.Name, Colors.White, Colors.LightGreen);
            Console.WriteLine();

            if (resourceManager.ClaimResources(hardwareResources))
            {
                hardwareResources.EnableIRQ();
                if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                {
                    deviceManager.Add(hardwareDevice);
                }
                else
                {
                    hardwareResources.DisableIRQ();
                    resourceManager.ReleaseResources(hardwareResources);
                }

            }
        }