/// <summary> /// Creates the partition devices. /// </summary> public void CreatePCIDevices() { // Find PCI controller devices LinkedList <IDevice> devices = deviceManager.GetDevices(new FindDevice.IsPCIController(), new FindDevice.IsOnline()); // For each controller foreach (IDevice device in devices) { IPCIController pciController = device as IPCIController; for (int bus = 0; bus < 255; bus++) { for (int slot = 0; slot < 16; slot++) { for (int fun = 0; fun < 7; fun++) { if (ProbeDevice(pciController, (byte)bus, (byte)slot, (byte)fun)) { deviceManager.Add(new Mosa.DeviceSystem.PCI.PCIDevice(pciController, (byte)bus, (byte)slot, (byte)fun)); } } } } } }
/// <summary> /// Creates the partition devices. /// </summary> public void CreatePartitionDevices() { // FIXME: Do not create multiple partition devices if this method executed more than once // Find all online disk devices foreach (var device in deviceManager.GetDevices(new FindDevice.IsDiskDevice(), new FindDevice.IsOnline())) { var diskDevice = device as IDiskDevice; var mbr = new MasterBootBlock(diskDevice); if (!mbr.Valid) { return; } for (uint i = 0; i < MasterBootBlock.MaxMBRPartitions; i++) { if (mbr.Partitions[i].PartitionType != PartitionType.Empty) { deviceManager.Add(new PartitionDevice(diskDevice, mbr.Partitions[i], false)); } } } }
/// <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="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); } } } }
/// <summary> /// Creates the disk devices. /// </summary> public void CreateDiskDevices() { // FIXME: Do not create disk devices if this method executed more than once // Find disk controller devices LinkedList <IDevice> devices = deviceManager.GetDevices(new FindDevice.IsDiskControllerDevice(), new FindDevice.IsOnline()); // For each controller foreach (IDevice device in devices) { IDiskControllerDevice controller = device as IDiskControllerDevice; // Create disk devices LinkedList <IDevice> disks = CreateDevices(controller); // Add them to the device manager foreach (IDevice disk in disks) { deviceManager.Add(disk); } } }