示例#1
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="deviceDriver">The device driver.</param>
        static public void StartDevice(DeviceDriver deviceDriver)
        {
            var driverAtttribute = deviceDriver.Attribute as ISADeviceDriverAttribute;

            if (driverAtttribute.AutoLoad)
            {
                var hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice;

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

                ioPortRegions.AddLast(new IOPortRegion(driverAtttribute.BasePort, driverAtttribute.PortRange));

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

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

                foreach (var memoryAttribute in deviceDriver.MemoryAttributes)
                {
                    if (memoryAttribute.MemorySize > 0)
                    {
                        IMemory memory = 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, driverAtttribute.IRQ, hardwareDevice));

                hardwareDevice.Setup(hardwareResources);

                if (resourceManager.ClaimResources(hardwareResources))
                {
                    hardwareResources.EnableIRQ();
                    if (hardwareDevice.Start() == DeviceDriverStartStatus.Started)
                    {
                        deviceManager.Add(hardwareDevice);
                    }
                    else
                    {
                        hardwareResources.DisableIRQ();
                        resourceManager.ReleaseResources(hardwareResources);
                    }
                }
            }
        }
示例#2
0
        static private void StartDevice(IPCIDevice pciDevice, 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 = 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);
                }
            }
        }