/// <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>
        /// Probes for a PCI device.
        /// </summary>
        /// <param name="pciController">The pci controller.</param>
        /// <param name="bus">The bus.</param>
        /// <param name="slot">The slot.</param>
        /// <param name="fun">The fun.</param>
        /// <returns></returns>
        protected bool ProbeDevice(IPCIController pciController, byte bus, byte slot, byte fun)
        {
            uint value = pciController.ReadConfig32(bus, slot, fun, 0);

            //HAL.DebugWrite(": " + value.ToString("x"));
            return value != 0xFFFFFFFF;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the partition devices.
        /// </summary>
        private void CreatePCIDevices(Device device, IPCIController pciController)
        {
            // For each controller
            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))
                        {
                            continue;
                        }

                        // TODO: Check for duplicate

                        var configuration = new PCIDeviceConfiguration()
                        {
                            Bus      = (byte)bus,
                            Slot     = (byte)slot,
                            Function = (byte)fun
                        };

                        DeviceService.Initialize(new PCIDevice(), device, configuration, null, null);
                    }
                }
            }
        }
        /// <summary>
        /// Probes for a PCI device.
        /// </summary>
        /// <param name="pciController">The pci controller.</param>
        /// <param name="bus">The bus.</param>
        /// <param name="slot">The slot.</param>
        /// <param name="fun">The fun.</param>
        /// <returns></returns>
        protected bool ProbeDevice(IPCIController pciController, byte bus, byte slot, byte fun)
        {
            uint value = pciController.ReadConfig32(bus, slot, fun, 0);

            //HAL.DebugWrite(": " + value.ToString("x"));
            return(value != 0xFFFFFFFF);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a new PCIDevice instance
        /// </summary>
        /// <param name="pciController">The pci controller.</param>
        /// <param name="bus">The bus.</param>
        /// <param name="slot">The slot.</param>
        /// <param name="fun">The fun.</param>
        public PCIDevice(IPCIController pciController, byte bus, byte slot, byte fun)
        {
            base.parent       = pciController as Device;
            base.name         = base.parent.Name + "/" + bus.ToString() + "." + slot.ToString() + "." + fun.ToString();
            base.deviceStatus = DeviceStatus.Available;

            this.pciController = pciController;
            Bus      = bus;
            Slot     = slot;
            Function = fun;

            ioPortRegionCount = memoryRegionCount = 0;
            BaseAddresses     = new BaseAddress[8];

            for (byte i = 0; i < 6; i++)
            {
                uint address = pciController.ReadConfig32(bus, slot, fun, (byte)(16 + (i * 4)));

                if (address != 0)
                {
                    HAL.DisableAllInterrupts();

                    pciController.WriteConfig32(bus, slot, fun, (byte)(16 + (i * 4)), 0xFFFFFFFF);
                    uint mask = pciController.ReadConfig32(bus, slot, fun, (byte)(16 + (i * 4)));
                    pciController.WriteConfig32(bus, slot, fun, (byte)(16 + (i * 4)), address);

                    HAL.EnableAllInterrupts();

                    if (address % 2 == 1)
                    {
                        BaseAddresses[i] = new BaseAddress(AddressType.IO, address & 0x0000FFF8, (~(mask & 0xFFF8) + 1) & 0xFFFF, false);
                    }
                    else
                    {
                        BaseAddresses[i] = new BaseAddress(AddressType.Memory, address & 0xFFFFFFF0, ~(mask & 0xFFFFFFF0) + 1, ((address & 0x08) == 1));
                    }
                }
            }

            if ((ClassCode == 0x03) && (SubClassCode == 0x00) && (ProgIF == 0x00))
            {
                // Special case for generic VGA
                BaseAddresses[6] = new BaseAddress(AddressType.Memory, 0xA0000, 0x1FFFF, false);
                BaseAddresses[7] = new BaseAddress(AddressType.IO, 0x3B0, 0x0F, false);
            }

            foreach (var baseAddress in BaseAddresses)
            {
                if (baseAddress != null)
                {
                    switch (baseAddress.Region)
                    {
                    case AddressType.IO: ioPortRegionCount++; break;

                    case AddressType.Memory: memoryRegionCount++; break;
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a new PCIDevice instance
        /// </summary>
        /// <param name="pciController">The pci controller.</param>
        /// <param name="bus">The bus.</param>
        /// <param name="slot">The slot.</param>
        /// <param name="fun">The fun.</param>
        public PCIDevice(IPCIController pciController, byte bus, byte slot, byte fun)
        {
            base.Parent = pciController as Device;
            base.Name = base.Parent.Name + "/" + bus.ToString() + "." + slot.ToString() + "." + fun.ToString();
            base.DeviceStatus = DeviceStatus.Available;

            this.pciController = pciController;
            Bus = bus;
            Slot = slot;
            Function = fun;

            ioPortRegionCount = memoryRegionCount = 0;
            BaseAddresses = new BaseAddress[8];

            for (byte i = 0; i < 6; i++)
            {
                byte barr = (byte)(PCIConfigurationHeader.BaseAddressRegisterBase + (i * 4));
                uint address = pciController.ReadConfig32(bus, slot, fun, barr);

                if (address == 0)
                    continue;

                HAL.DisableAllInterrupts();

                pciController.WriteConfig32(bus, slot, fun, barr, 0xFFFFFFFF);
                uint mask = pciController.ReadConfig32(bus, slot, fun, barr);
                pciController.WriteConfig32(bus, slot, fun, barr, address);

                HAL.EnableAllInterrupts();

                if (address % 2 == 1)
                    BaseAddresses[i] = new BaseAddress(AddressType.IO, address & 0x0000FFF8, (~(mask & 0xFFF8) + 1) & 0xFFFF, false);
                else
                    BaseAddresses[i] = new BaseAddress(AddressType.Memory, address & 0xFFFFFFF0, ~(mask & 0xFFFFFFF0) + 1, ((address & 0x08) == 1));
            }

            if ((ClassCode == 0x03) && (SubClassCode == 0x00) && (ProgIF == 0x00))
            {
                // Special case for generic VGA
                BaseAddresses[6] = new BaseAddress(AddressType.Memory, 0xA0000, 0x1FFFF, false);
                BaseAddresses[7] = new BaseAddress(AddressType.IO, 0x3B0, 0x0F, false);
            }

            foreach (var baseAddress in BaseAddresses)
            {
                if (baseAddress == null)
                    continue;

                switch (baseAddress.Region)
                {
                    case AddressType.IO: ioPortRegionCount++; break;
                    case AddressType.Memory: memoryRegionCount++; break;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create a new PCIDevice instance
        /// </summary>
        /// <param name="pciController">The pci controller.</param>
        /// <param name="bus">The bus.</param>
        /// <param name="slot">The slot.</param>
        /// <param name="fun">The fun.</param>
        public PCIDevice(IPCIController pciController, byte bus, byte slot, byte fun)
        {
            base.parent = pciController as Device;
            base.name = base.parent.Name + "/" + bus.ToString() + "." + slot.ToString() + "." + fun.ToString();
            base.deviceStatus = DeviceStatus.Available;

            this.pciController = pciController;
            this.bus = bus;
            this.slot = slot;
            this.function = fun;

            ioPortRegionCount = memoryRegionCount = 0;
            this.baseAddresses = new BaseAddress[8];

            for (byte i = 0; i < 6; i++)
            {
                uint address = pciController.ReadConfig32(bus, slot, fun, (byte)(16 + (i * 4)));

                if (address != 0)
                {
                    HAL.DisableAllInterrupts();

                    pciController.WriteConfig32(bus, slot, fun, (byte)(16 + (i * 4)), 0xFFFFFFFF);
                    uint mask = pciController.ReadConfig32(bus, slot, fun, (byte)(16 + (i * 4)));
                    pciController.WriteConfig32(bus, slot, fun, (byte)(16 + (i * 4)), address);

                    HAL.EnableAllInterrupts();

                    if (address % 2 == 1)
                        this.baseAddresses[i] = new BaseAddress(AddressType.IO, address & 0x0000FFF8, (~(mask & 0xFFF8) + 1) & 0xFFFF, false);
                    else
                        this.baseAddresses[i] = new BaseAddress(AddressType.Memory, address & 0xFFFFFFF0, ~(mask & 0xFFFFFFF0) + 1, ((address & 0x08) == 1));
                }
            }

            if ((ClassCode == 0x03) && (SubClassCode == 0x00) && (ProgIF == 0x00))
            {
                // Special case for generic VGA
                this.baseAddresses[6] = new BaseAddress(AddressType.Memory, 0xA0000, 0x1FFFF, false);
                this.baseAddresses[7] = new BaseAddress(AddressType.IO, 0x3B0, 0x0F, false);
            }

            foreach (BaseAddress baseAddress in this.baseAddresses)
                if (baseAddress != null)
                    switch (baseAddress.Region)
                    {
                        case AddressType.IO: ioPortRegionCount++; break;
                        case AddressType.Memory: memoryRegionCount++; break;
                    }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create a new PCIDevice instance at the selected PCI address
        /// </summary>
        public PCIDevice(IPCIController pciController, uint bus, uint slot, uint fun)
        {
            base.parent       = pciController as Device;
            base.name         = base.parent.Name + "/" + bus.ToString() + "/" + slot.ToString() + "/" + fun.ToString();
            base.deviceStatus = DeviceStatus.Offline;

            this.pciController = pciController;
            this.bus           = bus;
            this.slot          = slot;
            this.function      = fun;

            this.addresses = new PCIBaseAddress[6];

            uint data = pciController.ReadConfig(bus, slot, fun, 0);

            this.vendorID = (ushort)(data & 0xFFFF);
            this.deviceID = (ushort)((data >> 16) & 0xFFFF);

            data            = pciController.ReadConfig(bus, slot, fun, 0x08);
            this.revisionID = (byte)(data & 0xFF);
            this.progIF     = (byte)((data >> 8) & 0xFF);
            this.classCode  = (ushort)((data >> 16) & 0xFFFF);
            this.subClass   = (byte)((data >> 16) & 0xFF);
            this.baseClass  = (byte)((data >> 24) & 0xFF);

            data = pciController.ReadConfig(bus, slot, fun, 0x3c);

            if ((data & 0xFF00) != 0)
            {
                this.irq = (byte)(data & 0xFF);
            }

            for (uint i = 0; i < 6; i++)
            {
                uint cur = pciController.ReadConfig(bus, slot, fun, 16 + (i * 4));
                ///TODO: disable interrupts
                pciController.WriteConfig(bus, slot, fun, 16 + (i * 4), 0xFFFFFFFF);
                uint mask = pciController.ReadConfig(bus, slot, fun, 16 + (i * 4));
                pciController.WriteConfig(bus, slot, fun, 16 + (i * 4), cur);
                ///TODO: enable interrupts
                if (cur % 2 == 1)
                {
                    addresses[i] = new PCIBaseAddress(cur & 0x0000FFF8, (~(mask & 0xFFF8) + 1) & 0xFFFF, AddressRegion.IO, false);
                }
                else
                {
                    addresses[i] = new PCIBaseAddress(cur & 0xFFFFFFF0, ~(mask & 0xFFFFFFF0) + 1, AddressRegion.Memory, ((cur & 0x08) == 1));
                }
            }
        }
Exemplo n.º 9
0
		/// <summary>
		/// Create a new PCIDevice instance at the selected PCI address
		/// </summary>
		public PCIDevice (IPCIController pciController, uint bus, uint slot, uint fun)
		{
			base.parent = pciController as Device;
			base.name = base.parent.Name + "/" + bus.ToString () + "/" + slot.ToString () + "/" + fun.ToString ();
			base.deviceStatus = DeviceStatus.Offline;

			this.pciController = pciController;
			this.bus = bus;
			this.slot = slot;
			this.function = fun;

			this.addresses = new PCIBaseAddress[6];

			uint data = pciController.ReadConfig (bus, slot, fun, 0);
			this.vendorID = (ushort)(data & 0xFFFF);
			this.deviceID = (ushort)((data >> 16) & 0xFFFF);

			data = pciController.ReadConfig (bus, slot, fun, 0x08);
			this.revisionID = (byte)(data & 0xFF);
			this.progIF = (byte)((data >> 8) & 0xFF);
			this.classCode = (ushort)((data >> 16) & 0xFFFF);
			this.subClass = (byte)((data >> 16) & 0xFF);
			this.baseClass = (byte)((data >> 24) & 0xFF);

			data = pciController.ReadConfig (bus, slot, fun, 0x3c);
			
			if ((data & 0xFF00) != 0)
				this.irq = (byte)(data & 0xFF);	

			for (uint i = 0; i < 6; i++) {
				uint cur = pciController.ReadConfig (bus, slot, fun, 16 + (i * 4));
				///TODO: disable interrupts
				pciController.WriteConfig (bus, slot, fun, 16 + (i * 4), 0xFFFFFFFF);
				uint mask = pciController.ReadConfig (bus, slot, fun, 16 + (i * 4));
				pciController.WriteConfig (bus, slot, fun, 16 + (i * 4), cur);
				///TODO: enable interrupts
				if (cur % 2 == 1)
					addresses[i] = new PCIBaseAddress (cur & 0x0000FFF8, (~(mask & 0xFFF8) + 1) & 0xFFFF, AddressRegion.IO, false);
				else
					addresses[i] = new PCIBaseAddress (cur & 0xFFFFFFF0, ~(mask & 0xFFFFFFF0) + 1, AddressRegion.Memory, ((cur & 0x08) == 1));
			}
		}
Exemplo n.º 10
0
 /// <summary>
 /// Probes for a PCI device.
 /// </summary>
 /// <param name="pciController">The pci controller.</param>
 /// <param name="bus">The bus.</param>
 /// <param name="slot">The slot.</param>
 /// <param name="fun">The fun.</param>
 /// <returns></returns>
 protected bool ProbeDevice(IPCIController pciController, byte bus, byte slot, byte fun)
 {
     return pciController.ReadConfig32(bus, slot, fun, 0) != 0xFFFFFFFF;
 }
Exemplo n.º 11
0
        public override void Initialize()
        {
            pciController = Device.Parent.DeviceDriver as IPCIController;

            var configuration = Device.Configuration as PCIDeviceConfiguration;

            Bus      = configuration.Bus;
            Slot     = configuration.Slot;
            Function = configuration.Function;

            Device.Name = Device.Parent.Name + '/' + Bus.ToString() + '.' + Slot.ToString() + '.' + Function.ToString();

            ioPortRegionCount = memoryRegionCount = 0;
            BaseAddresses     = new BaseAddress[8];

            for (byte i = 0; i < 6; i++)
            {
                byte barr = (byte)(PCIConfigurationHeader.BaseAddressRegisterBase + (i * 4));

                uint address = pciController.ReadConfig32(Bus, Slot, Function, barr);

                if (address == 0)
                {
                    continue;
                }

                HAL.DisableAllInterrupts();

                pciController.WriteConfig32(Bus, Slot, Function, barr, 0xFFFFFFFF);
                uint mask = pciController.ReadConfig32(Bus, Slot, Function, barr);
                pciController.WriteConfig32(Bus, Slot, Function, barr, address);

                HAL.EnableAllInterrupts();

                if (address % 2 == 1)
                {
                    BaseAddresses[i] = new BaseAddress(AddressType.IO, new IntPtr(address & 0x0000FFF8), (~(mask & 0xFFF8) + 1) & 0xFFFF, false);
                }
                else
                {
                    BaseAddresses[i] = new BaseAddress(AddressType.Memory, new IntPtr(address & 0xFFFFFFF0), ~(mask & 0xFFFFFFF0) + 1, (address & 0x08) == 1);
                }
            }

            // FIXME: Special case for generic VGA
            if (ClassCode == 0x03 && SubClassCode == 0x00 && ProgIF == 0x00)
            {
                BaseAddresses[6] = new BaseAddress(AddressType.Memory, new IntPtr(0xA0000), 0x1FFFF, false);
                BaseAddresses[7] = new BaseAddress(AddressType.IO, new IntPtr(0x3B0), 0x0F, false);
            }

            foreach (var baseAddress in BaseAddresses)
            {
                if (baseAddress == null)
                {
                    continue;
                }

                if (baseAddress.Region == AddressType.Undefined)
                {
                    continue;
                }

                switch (baseAddress.Region)
                {
                case AddressType.IO: ioPortRegionCount++; break;

                case AddressType.Memory: memoryRegionCount++; break;
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Probes for a PCI device.
        /// </summary>
        /// <param name="pciController">The pci controller.</param>
        /// <param name="bus">The bus.</param>
        /// <param name="slot">The slot.</param>
        /// <param name="fun">The fun.</param>
        /// <returns></returns>
        protected bool ProbeDevice(IPCIController pciController, byte bus, byte slot, byte fun)
        {
            uint value = pciController.ReadConfig32(bus, slot, fun, 0);

            return(value != 0xFFFFFFFF);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Probes for a PCI device.
 /// </summary>
 /// <param name="pciController">The pci controller.</param>
 /// <param name="bus">The bus.</param>
 /// <param name="slot">The slot.</param>
 /// <param name="fun">The fun.</param>
 /// <returns></returns>
 protected bool ProbeDevice(IPCIController pciController, byte bus, byte slot, byte fun)
 {
     return(pciController.ReadConfig32(bus, slot, fun, 0) != 0xFFFFFFFF);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Probes for a PCI device.
        /// </summary>
        /// <param name="pciController">The pci controller.</param>
        /// <param name="bus">The bus.</param>
        /// <param name="slot">The slot.</param>
        /// <param name="fun">The fun.</param>
        /// <returns></returns>
        protected bool ProbeDevice(IPCIController pciController, byte bus, byte slot, byte fun)
        {
            uint value = pciController.ReadConfig32(bus, slot, fun, 0);

            return value != 0xFFFFFFFF;
        }