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); }
/// <summary> /// Claims the resources. /// </summary> /// <param name="hardwareResources">The hardware resources.</param> /// <returns></returns> public bool ClaimResources(HardwareResources hardwareResources) { lock (_lock) { for (byte r = 0; r < hardwareResources.MemoryRegionCount; r++) { var region = hardwareResources.GetMemoryRegion(r); foreach (var memoryRegion in memoryRegions) { if (memoryRegion.Contains(region.BaseAddress) || memoryRegion.Contains(region.BaseAddress + region.Size)) { return(false); } } } for (byte r = 0; r < hardwareResources.MemoryRegionCount; r++) { memoryRegions.AddLast(hardwareResources.GetMemoryRegion(r)); } } return(true); }
/// <summary> /// Releases the resources. /// </summary> /// <param name="hardwareResources">The hardware resources.</param> public void ReleaseResources(HardwareResources hardwareResources) { lock (_lock) { for (byte r = 0; r < hardwareResources.MemoryRegionCount; r++) { memoryRegions.Remove(hardwareResources.GetMemoryRegion(r)); } } }
/// <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); } } }
/// <summary> /// Releases the resources. /// </summary> /// <param name="hardwareResources">The hardware resources.</param> public void ReleaseResources(HardwareResources hardwareResources) { spinLock.Enter(); for (byte r = 0; r < hardwareResources.MemoryRegionCount; r++) { memoryRegions.Remove(hardwareResources.GetMemoryRegion(r)); } spinLock.Exit(); }
/// <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); } } } }
public static void StartISADevice(ISADeviceDriverRegistryEntry driver) { var hardwareDevice = driver.Factory() as IHardwareDevice; var ioPortRegions = new List <IOPortRegion>(); var memoryRegions = new List <MemoryRegion>(); ioPortRegions.Add(new IOPortRegion(driver.BasePort, driver.PortRange)); if (driver.AltBasePort != 0x00) { ioPortRegions.Add(new IOPortRegion(driver.AltBasePort, driver.AltPortRange)); } if (driver.BaseAddress != 0x00) { memoryRegions.Add(new MemoryRegion(driver.BaseAddress, driver.AddressRange)); } //if (driver.PhysicalMemory != null) //{ // foreach (var physicalMemory in driver.PhysicalMemory) // { // if (physicalMemory.MemorySize > 0) // { // var memory = HAL.AllocateMemory(physicalMemory.MemorySize, physicalMemory.MemoryAlignment); // memoryRegions.Add(new MemoryRegion(memory.Address, memory.Size)); // } // } //} var interruptHandler = new InterruptHandler(InterruptManager, driver.IRQ, hardwareDevice); var hardwareResources = new HardwareResources(ioPortRegions, memoryRegions, interruptHandler); hardwareDevice.Setup(hardwareResources); if (!hardwareDevice.Probe()) { return; } DeviceManager.Add(hardwareDevice); hardwareResources.EnableIRQ(); hardwareDevice.Start(); }
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); } } }
/// <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> /// Starts the device. /// </summary> /// <param name="deviceDriver">The device driver.</param> public static void StartDevice(DeviceDriver deviceDriver) { ISADeviceDriverAttribute driverAtttribute = deviceDriver.Attribute as ISADeviceDriverAttribute; if (driverAtttribute.AutoLoad) { IHardwareDevice hardwareDevice = System.Activator.CreateInstance(deviceDriver.DriverType) as IHardwareDevice; 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.AllocateMemory(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); } } } }
/// <summary> /// Setups this hardware device driver /// </summary> /// <param name="hardwareResources"></param> /// <returns></returns> public abstract bool Setup(HardwareResources hardwareResources);
public Device Initialize(DeviceDriverRegistryEntry deviceDriverRegistryEntry, Device parent, BaseDeviceConfiguration configuration = null, HardwareResources resources = null) { var deviceDriver = deviceDriverRegistryEntry.Factory(); return(Initialize(deviceDriver, parent, configuration, resources, deviceDriverRegistryEntry)); }
public Device Initialize(BaseDeviceDriver deviceDriver, Device parent, BaseDeviceConfiguration configuration = null, HardwareResources resources = null, DeviceDriverRegistryEntry deviceDriverRegistryEntry = null) { var device = new Device() { DeviceDriver = deviceDriver, DeviceDriverRegistryEntry = deviceDriverRegistryEntry, Status = DeviceStatus.Initializing, Parent = parent, Configuration = configuration, Resources = resources, DeviceService = this, //Name = string.Empty, }; StartDevice(device); return(device); }
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); } } }
/// <summary> /// Starts the device. /// </summary> /// <param name="deviceDriver">The device driver.</param> public static void StartDevice(Mosa.DeviceSystem.DeviceDriver deviceDriver) { var driverAtttribute = deviceDriver.Attribute as ISADeviceDriverAttribute; // Don't load the VGAText and PIC drivers if (driverAtttribute.BasePort == 0x03B0 || driverAtttribute.BasePort == 0x20) return; 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 = 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, driverAtttribute.IRQ, hardwareDevice)); hardwareDevice.Setup(hardwareResources); //Mosa.CoolWorld.x86.Boot.BulletPoint(); Boot.Console.Write("Adding device "); Boot.InBrackets(hardwareDevice.Name, Mosa.Kernel.x86.Colors.White, Mosa.Kernel.x86.Colors.LightGreen); Boot.Console.WriteLine(); if (resourceManager.ClaimResources(hardwareResources)) { hardwareResources.EnableIRQ(); if (hardwareDevice.Start() == DeviceDriverStartStatus.Started) { deviceManager.Add(hardwareDevice); } else { hardwareResources.DisableIRQ(); resourceManager.ReleaseResources(hardwareResources); } } } }
/// <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); } } }