Exemple #1
0
        private static unsafe void initHandler(PciDevice dev)
        {
            buffer    = new byte[2048];
            m_dev     = dev;
            m_io_base = (ushort)(dev.BAR0.Address);

            Pci.EnableBusMastering(dev);
            Pci.EnableIOSpace(dev);

            /**
             * Read current mac
             */
            ReadMac();

            /**
             * Do a software reset because we want 32bitjes :)
             */
            SoftwareReset();

            writeCSR(0, 0x04);

            /**
             * Initalize buffers
             */
            InitBuffers();

            InitCard();

            /**
             * Set interrupt
             */
            Pci.SetInterruptHandler(dev, handler);


            // Enable card
            writeCSR(0, 0x41);


            writeCSR(4, 0x4C00 | readCSR(4));

            writeCSR(0, 0x42);


            /**
             * Register device as the main network device
             */
            Network.NetDevice netDev = new Network.NetDevice();
            netDev.ID       = dev.Device;
            netDev.Transmit = Transmit;
            netDev.GetMac   = GetMac;

            Network.Set(netDev);
        }
Exemple #2
0
        /// <summary>
        /// PCI init handler
        /// </summary>
        /// <param name="dev"></param>
        private static unsafe void initHandler(PciDevice dev)
        {
            m_register_base = (uint)dev.BAR0.Address;
            m_flash_base    = (uint)dev.BAR1.Address;

            /**
             * Check if there is a memory bar
             */
            if ((dev.BAR0.flags & Pci.BAR_IO) > 0)
            {
                Console.WriteLine("[E1000] Device not MMIO!");
                return;
            }

            m_packetBuffer = new byte[9500];

            /**
             * Enable bus mastering
             */
            Pci.EnableBusMastering(dev);

            /**
             * Map device
             */
            m_register_base = (uint)Paging.MapToVirtual(Paging.KernelDirectory, (int)m_register_base, 20 * 0x1000, Paging.PageFlags.Writable | Paging.PageFlags.Present);
            Pci.SetInterruptHandler(dev, handler);

            readMac();
            start();

            /**
             * Waiting for link to go up
             */
            Console.WriteLine("[E1000] Waiting for link to go up....");
            while (m_linkup == 0)
            {
                CPU.HLT();
            }

            /**
             * Register device as the main network device
             */
            Network.NetDevice netDev = new Network.NetDevice();
            netDev.ID       = dev.Device;
            netDev.Transmit = Transmit;
            netDev.GetMac   = GetMac;

            Network.Set(netDev);
        }
Exemple #3
0
        /// <summary>
        /// Initialization handler
        /// </summary>
        /// <param name="dev">This PCI device</param>
        private static unsafe void initHandler(PciDevice dev)
        {
            m_io_base = (ushort)(dev.BAR0.Address);

            /**
             * Check if I/O bar
             */
            if ((dev.BAR0.flags & Pci.BAR_IO) == 0)
            {
                Console.WriteLine("[RTL8139] RTL8139 should be an I/O bar, not a memory bar!");
                return;
            }

            /**
             * Set interrupt
             */
            Pci.SetInterruptHandler(dev, handler);

            /**
             * Enable bus mastering
             */
            Pci.EnableBusMastering(dev);

            /**
             * Enable device
             */
            PortIO.Out8((ushort)(m_io_base + REG_CONF1), 0);

            /**
             *  Do a software reset
             */
            softwareReset();

            /**
             * Initalize and allocate buffers
             */
            initializeBuffers();

            /**
             * Setup interrupts
             */
            setInterruptMask(IMR_TOK | IMR_TER | IMR_ROK | IMR_RER);

            /**
             * Initalize transmit
             */
            txInit();

            /**
             * Initalize receive
             */
            rxInit();

            /**
             * Read mac address
             */
            readMac();

            /**
             * Update link status
             */
            updateLinkStatus();

            /**
             * Enable receiving and transmitting!
             */
            PortIO.Out8((ushort)(m_io_base + REG_CMD), CMD_TE | CMD_RE);

            Console.WriteLine("[RTL8139] Initialized");

            /**
             * Register device as the main network device
             */
            Network.NetDevice netDev = new Network.NetDevice();
            netDev.ID       = dev.Device;
            netDev.Transmit = Transmit;
            netDev.GetMac   = GetMac;

            Network.Set(netDev);
        }