예제 #1
0
        public bool Reset()
        {
            var acpi = DeviceService.GetFirstDevice <IACPI>(DeviceStatus.Online).DeviceDriver as IACPI;

            if (acpi == null)
            {
                return(false);
            }

            BaseIOPortWrite address = acpi.ResetAddress;
            byte            value   = acpi.ResetValue;

            if (address != null)
            {
                address.Write8(value);

                // Map memory
                Pointer         ptr            = HAL.GetPhysicalMemory((Pointer)(uint)address.Address, 1).Address;
                BaseIOPortWrite mappedResetReg = HAL.GetWriteIOPort((ushort)ptr);

                mappedResetReg.Write8(value);

                // Write to PCI Configuration Space (we're actually writing on the host bridge controller)
                // TODO: Fix

                /*var controller = DeviceService.GetFirstDevice<IHostBridgeController>(DeviceStatus.Online).DeviceDriver as IHostBridgeController;
                 *
                 * controller.SetCPUResetInformation((byte)address.Address, value);
                 * controller.CPUReset();*/

                return(true);
            }

            return(false);
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Starts the device.
        /// </summary>
        /// <param name="deviceDriver">The device driver.</param>
        static public void StartDevice(DeviceDriver deviceDriver)
        {
            ISADeviceDriverAttribute driverAtttribute = deviceDriver.Attribute as ISADeviceDriverAttribute;

            if (driverAtttribute.AutoLoad)
            {
                IHardwareDevice hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice;
                //UNUSED:
                //ISADeviceDriverAttribute attribute = deviceDriver.Attribute as ISADeviceDriverAttribute;

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

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

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

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

                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));
                    }
                }

                IHardwareResources 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);
                    }
                }
            }
        }
예제 #4
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);
                }
            }
        }
예제 #5
0
        public static void Initialize(BaseHardwareAbstraction hardware)
        {
            // Create Device Manager
            DeviceManager = new DeviceManager();

            // Create Interrupt Manager
            InterruptManager = new InterruptManager();

            // Create the Device Driver Manager
            DeviceDriverRegistry = new DeviceDriverRegistry(PlatformArchitecture.X86);

            // Create the PCI Controller Manager
            PCIControllerManager = new PCIControllerManager(DeviceManager);

            // Set device driver system to the hardware HAL
            HAL.SetHardwareAbstraction(hardware);

            // Set the interrupt handler
            HAL.SetInterruptHandler(InterruptManager.ProcessInterrupt);
        }
예제 #6
0
 /// <summary>
 /// Gets the memory.
 /// </summary>
 /// <param name="address">The address.</param>
 /// <param name="size">The size.</param>
 /// <returns></returns>
 public Memory GetMemory(uint address, uint size)
 {
     return(HAL.RequestPhysicalMemory(address, size));
 }
예제 #7
0
 /// <summary>
 /// Gets the IO port.
 /// </summary>
 /// <param name="region">The region.</param>
 /// <param name="index">The index.</param>
 /// <returns></returns>
 public IOPortRead GetIOPortRead(byte region, ushort index)
 {
     return(HAL.RequestReadIOPort((ushort)(ioPortRegions[region].BaseIOPort + index)));
 }
예제 #8
0
 /// <summary>
 /// Gets the memory.
 /// </summary>
 /// <param name="region">The region.</param>
 /// <returns></returns>
 public Memory GetMemory(byte region)
 {
     return(HAL.RequestPhysicalMemory(memoryRegions[region].BaseAddress, memoryRegions[region].Size));
 }
예제 #9
0
 /// <summary>
 /// Gets the IO port.
 /// </summary>
 /// <param name="region">The region.</param>
 /// <param name="index">The index.</param>
 /// <returns></returns>
 public BaseIOPortReadWrite GetIOPortReadWrite(byte region, ushort index)
 {
     return(HAL.GetReadWriteIOPort((ushort)(ioPortRegions[region].BaseIOPort + index)));
 }
예제 #10
0
 /// <summary>
 /// Gets the IO port.
 /// </summary>
 /// <param name="index">The region.</param>
 /// <param name="offset">The index.</param>
 /// <returns></returns>
 public BaseIOPortRead GetIOPortRead(byte index, ushort offset)
 {
     return(HAL.GetReadIOPort((ushort)(ioPortRegions[index].BaseIOPort + offset)));
 }
예제 #11
0
 /// <summary>
 /// Gets the memory.
 /// </summary>
 /// <param name="region">The region.</param>
 /// <returns></returns>
 public ConstrainedPointer GetMemory(byte region)
 {
     return(HAL.GetPhysicalMemory(addressRegions[region].Address, addressRegions[region].Size));
 }