Esempio n. 1
0
        /// <summary>
        /// Initialize nvme device
        /// </summary>
        public void InitDevice()
        {
            CurrentCID = 1;

            mAddress        = (int)mDevice.BAR0.Address;
            mAddressVirtual = (int)Paging.MapToVirtual(Paging.CurrentDirectory, mAddress, 0x1000, Paging.PageFlags.Present | Paging.PageFlags.Writable);
            mRegs           = (NVMe_Registers *)mAddressVirtual;

            Pci.EnableBusMastering(mDevice);

            // TODO: Make this map the right size
            mTailsAndHeads = (int *)Paging.MapToVirtual(Paging.CurrentDirectory, mAddress + 0x1000, 0x4000, Paging.PageFlags.Present | Paging.PageFlags.Writable);

            ReadCapabilities();
            ReadVersion();
            ConfigureAdminQueue();
            EnableController();
            DoIdentify();
            CreateQueues();



            char *name = (char *)Heap.Alloc(6);

            name[0] = 'N';
            name[1] = 'V';
            name[2] = 'M';
            name[3] = 'E';
            name[4] = (char)('0' + mID++);
            name[5] = '\0';
            string nameStr = Util.CharPtrToString(name);

            Node node = new Node();

            node.Read  = readImpl;
            node.Write = writeImpl;

            NVMeCookie cookie = new NVMeCookie();

            cookie.NVMe = this;

            node.Cookie = cookie;


            Disk.InitalizeNode(node, nameStr);
            RootPoint dev = new RootPoint(nameStr, node);

            VFS.MountPointDevFS.AddEntry(dev);

            Console.Write("[NVME] Init with serialnumber ");
            for (int i = 0; i < 20; i++)
            {
                Console.Write(mSerialNumber[i]);
            }
            Console.WriteLine("");
        }
Esempio n. 2
0
        /// <summary>
        /// Read method for filesystem
        /// </summary>
        /// <param name="node">The node</param>
        /// <param name="offset">The offset</param>
        /// <param name="size">The size</param>
        /// <param name="buffer">The buffer</param>
        /// <returns>The amount of bytes read</returns>
        private static uint readImpl(Node node, uint offset, uint size, byte[] buffer)
        {
            // Only support sizes in magnitudes of 512
            if (size % 512 != 0)
            {
                return(0);
            }

            uint inSize = size / 512;

            NVMeCookie cookie = (NVMeCookie)node.Cookie;

            return((uint)cookie.NVMe.RWOperation(NVMe_RW_OP.READ, (byte *)Util.ObjectToVoidPtr(buffer), offset, inSize));
        }