/// <summary> /// Registers the device drivers. /// </summary> /// <param name="assemblyInfo">The assembly info.</param> public void RegisterDeviceDrivers(System.Reflection.Assembly assemblyInfo) { System.Type[] types = assemblyInfo.GetTypes(); foreach (System.Type type in types) { object[] attributes = type.GetCustomAttributes(typeof(IDeviceDriver), false); foreach (object attribute in attributes) { if (((attribute as IDeviceDriver).Platforms & platformArchitecture) != 0) { DeviceDriver deviceDriver = new DeviceDriver(attribute as IDeviceDriver, type); object[] memAttributes = type.GetCustomAttributes(typeof(DeviceDriverPhysicalMemoryAttribute), false); foreach (object memAttribute in memAttributes) { deviceDriver.Add(memAttribute as DeviceDriverPhysicalMemoryAttribute); } deviceDrivers.Add(deviceDriver); } } } }
/// <summary> /// Starts the device. /// </summary> /// <param name="deviceDriver">The device driver.</param> static public 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)); if (resourceManager.ClaimResources(hardwareResources)) { hardwareResources.EnableIRQ(); hardwareDevice.Setup(hardwareResources); if (hardwareDevice.Start() == DeviceDriverStartStatus.Started) { deviceManager.Add(hardwareDevice); } else { hardwareResources.DisableIRQ(); resourceManager.ReleaseResources(hardwareResources); } } } }
/// <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> /// 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); } } } }
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> /// Registers the device drivers. /// </summary> /// <param name="assemblyInfo">The assembly info.</param> public void RegisterDeviceDrivers(Assembly assemblyInfo) { var types = assemblyInfo.DefinedTypes; foreach (var type in types) { var attributes = type.CustomAttributes; foreach (var attributeData in attributes) { if (attributeData.AttributeType != typeof(ISADeviceDriverAttribute) && attributeData.AttributeType != typeof(PCIDeviceDriverAttribute)) { continue; } IDeviceDriver attribute = GetIDeviceDriver(attributeData); if ((attribute.Platforms & platformArchitecture) != 0) { DeviceDriver deviceDriver = new DeviceDriver(attribute, type.AsType()); foreach (var memAttributeData in attributes) { if (memAttributeData.AttributeType != typeof(DeviceDriverPhysicalMemoryAttribute)) { continue; } var memAttribute = GetDeviceDriverPhysicalMemoryAttribute(memAttributeData); deviceDriver.Add(memAttribute); } AddDeviceDriver(deviceDriver); } } } }
/// <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); }
/// <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); } } } }
public void AddDeviceDriver(DeviceDriver deviceDriver) { deviceDrivers.AddLast(deviceDriver); }
/// <summary> /// Registers the device drivers. /// </summary> /// <param name="assemblyInfo">The assembly info.</param> public void RegisterDeviceDrivers(System.Reflection.Assembly assemblyInfo) { System.Type[] types = assemblyInfo.GetTypes(); foreach (System.Type type in types) { object[] attributes = type.GetCustomAttributes(typeof(IDeviceDriver), false); foreach (object attribute in attributes) if (((attribute as IDeviceDriver).Platforms & platformArchitecture) != 0) { DeviceDriver deviceDriver = new DeviceDriver(attribute as IDeviceDriver, type); object[] memAttributes = type.GetCustomAttributes(typeof(DeviceDriverPhysicalMemoryAttribute), false); foreach (object memAttribute in memAttributes) deviceDriver.Add(memAttribute as DeviceDriverPhysicalMemoryAttribute); deviceDrivers.Add(deviceDriver); } } }
/// <summary> /// Registers the device drivers. /// </summary> /// <param name="assemblyInfo">The assembly info.</param> public void RegisterDeviceDrivers(Assembly assemblyInfo) { var types = assemblyInfo.DefinedTypes; foreach (var type in types) { var attributes = type.CustomAttributes; foreach (var attributeData in attributes) { if (attributeData.AttributeType != typeof(ISADeviceDriverAttribute) && attributeData.AttributeType != typeof(PCIDeviceDriverAttribute)) continue; var attribute = GetIDeviceDriver(attributeData); if ((attribute.Platforms & platformArchitecture) != 0) { var deviceDriver = new DeviceDriver(attribute, type.AsType()); foreach (var memAttributeData in attributes) { if (memAttributeData.AttributeType != typeof(DeviceDriverPhysicalMemoryAttribute)) continue; var memAttribute = GetDeviceDriverPhysicalMemoryAttribute(memAttributeData); deviceDriver.Add(memAttribute); } AddDeviceDriver(deviceDriver); } } } }
private static 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); } } }