Exemple #1
0
        // Monitors the average DST temp over a 1 second interval
        static void ReadLoop()
        {
            int  r = 0, index = 0;
            uint eax = 0, edx = 0;

            // MSR_TEMPERATURE_TARGET
            // for PROCHOT assertion (probably same as TjMax), only works on i7
            r     = Ols.Rdmsr(0x1a2, ref eax, ref edx);
            tjmax = (eax >> 16) & 0xFF;

            while (true)
            {
                for (int i = 0; i < CORE_COUNT; i++)
                {
                    // for some reason you need to shift 2 bits on Win64
                    UIntPtr mask = (UIntPtr)(1 << (i * 4 / 2));

                    r = Ols.RdmsrPx(0x19c, ref eax, ref edx, mask);

                    if (r != 0 && (eax & 0x80000000) != 0)
                    {
                        samples[index, i] = eax;
                    }
                }

                Thread.Sleep(1000 / SAMPLE_RATE);

                index++;
                if (index == SAMPLE_RATE)
                {
                    index = 0;
                }
            }
        }
Exemple #2
0
        // a thread for the Real Time Clock (RTS)
        static void RTCLoop()
        {
            uint eax = 0, edx = 0;

            while (true)
            {
                var tsm1 = timeGetTime();

                // IA32_TIME_STAMP_COUNTER
                var r = Ols.Rdtsc(ref eax, ref edx);

                var tsc = eax | ((ulong)edx) << 32;

                Thread.Sleep(500);

                r = Ols.Rdtsc(ref eax, ref edx);

                var tsm2 = timeGetTime();

                var diff = (eax | ((ulong)edx) << 32) - tsc;

                var tsd2 = (tsm2 - tsm1) * 1.0;

                rtcspeed = diff / tsd2 / 1000;
            }
        }
Exemple #3
0
 public void SetReg(int slaveaddress, int reg, int data)
 {
     WaitForFree();
     Ols.WriteIoPortWord(Address(DATA0), (ushort)data);
     Ols.WriteIoPortWord(Address(DATA1), (ushort)data);
     Call(slaveaddress, reg, WRITE);
 }
Exemple #4
0
        public int Read(int index)
        {
            Ols.WriteIoPortByte((ushort)AddressPort, (byte)index);
            var d = Ols.ReadIoPortByte((ushort)DataPort);

            return(d);
        }
Exemple #5
0
        // Return [realCores, logicalCores]
        public int[] GetCoreCount()
        {
            uint eax = 0, ebx = 0, ecx = 0, edx = 0;
            int  logicalCores   = 0;
            int  threadsPerCore = 1;

            int[] count = { 0, 1 };

            if (Ols.Cpuid(0x00000001, ref eax, ref ebx, ref ecx, ref edx) == 1)
            {
                logicalCores = Convert.ToInt32((ebx >> 16) & 0xFF);

                if (Ols.Cpuid(0x8000001E, ref eax, ref ebx, ref ecx, ref edx) == 1)
                {
                    threadsPerCore = Convert.ToInt32(ebx >> 8 & 0xF) + 1;
                }
            }
            if (threadsPerCore == 0)
            {
                count[0] = logicalCores;
            }
            else
            {
                count[0] = logicalCores / threadsPerCore;
            }

            count[1] = logicalCores;

            return(count);
        }
Exemple #6
0
        static Processor()
        {
            uint eax = 0, ebx = 0, ecx = 0, edx = 0;

            Ols ols = new Ols();

            ols.Cpuid(0x0000000, ref eax, ref ebx, ref ecx, ref edx);

            _vendor = Uint_to_string(ebx) + Uint_to_string(edx) + Uint_to_string(ecx);

            ols.Cpuid(0x0000001, ref eax, ref ebx, ref ecx, ref edx);

            _stepping = (byte)((eax >> 0) & 0x0Fb);
            _model    = (byte)((eax >> 4) & 0xF);
            _family   = (byte)((eax >> 8) & 0xF);
            _type     = (byte)((eax >> 12) & 0x3);
            byte _ext_model  = (byte)((eax >> 16) & 0xF);
            byte _ext_family = (byte)((eax >> 20) & 0xFF);

            if (_family == 0xF)
            {
                _family += _ext_family;
                _model  += (byte)(_ext_model << 4);
            }
            else if (_family == 0x6)
            {
                _model += (byte)(_ext_model << 4);
            }

            _logical_core_count = (byte)(ebx >> 16);
        }
Exemple #7
0
        // a thread for the Time Stamp Counter (TSC)
        static void TSCLoop()
        {
            uint eax = 0, edx = 0;

            var sw = Stopwatch.StartNew();

            while (true)
            {
                var ts1 = sw.Elapsed;

                // IA32_TIME_STAMP_COUNTER
                var r = Ols.Rdtsc(ref eax, ref edx);

                var tsc = eax | ((ulong)edx) << 32;

                Thread.Sleep(500);

                r = Ols.Rdtsc(ref eax, ref edx);

                var ts2 = sw.Elapsed;

                var diff = (eax | ((ulong)edx) << 32) - tsc;

                var tsd = (ts2 - ts1).TotalMilliseconds;

                speed = diff / tsd / 1000;
            }
        }
Exemple #8
0
        public int GetReg(int slaveaddress, int reg, int length)
        {
            WaitForFree();
            Ols.WriteIoPortWord(Address(DATA0), 0);
            Ols.WriteIoPortWord(Address(DATA1), 0);
            var r = Call(slaveaddress, reg, READ, length);

            return(r & 0xffff);
        }
        public Smu(bool EnableDebug)
        {
            ShowDebug    = EnableDebug;
            RyzenAccesss = new Ols();
            //RyzenAccesss.InitializeOls();

            SMU_PCI_ADDR    = 0x00000000;
            SMU_OFFSET_ADDR = 0xB8;
            SMU_OFFSET_DATA = 0xBC;

            MP1_ADDR_MSG = 0x03B10528;
            MP1_ADDR_RSP = 0x03B10564;
            MP1_ADDR_ARG = 0x03B10998;

            PSMU_ADDR_MSG = 0x03B10A20;
            PSMU_ADDR_RSP = 0x03B10A80;
            PSMU_ADDR_ARG = 0x03B10A88;



            // Check WinRing0 status
            switch (RyzenAccesss.GetDllStatus())
            {
            case (uint)Ols.OlsDllStatus.OLS_DLL_NO_ERROR:
                if (ShowDebug)
                {
                    MessageBox.Show("Ols Dll is OK.", "Ols.OlsDllStatus:");
                }
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED:
                MessageBox.Show("WinRing OLS_DRIVER_NOT_LOADED", "Ols.OlsDllStatus:");
                throw new ApplicationException("WinRing OLS_DRIVER_NOT_LOADED");

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNSUPPORTED_PLATFORM:
                MessageBox.Show("WinRing OLS_UNSUPPORTED_PLATFORM", "Ols.OlsDllStatus:");
                throw new ApplicationException("WinRing OLS_UNSUPPORTED_PLATFORM");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_FOUND:
                MessageBox.Show("WinRing OLS_DLL_DRIVER_NOT_FOUND", "Ols.OlsDllStatus:");
                throw new ApplicationException("WinRing OLS_DLL_DRIVER_NOT_FOUND");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_UNLOADED:
                MessageBox.Show("WinRing OLS_DLL_DRIVER_UNLOADED", "Ols.OlsDllStatus:");
                throw new ApplicationException("WinRing OLS_DLL_DRIVER_UNLOADED");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK:
                MessageBox.Show("WinRing DRIVER_NOT_LOADED_ON_NETWORK", "Ols.OlsDllStatus:");
                throw new ApplicationException("WinRing DRIVER_NOT_LOADED_ON_NETWORK");

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNKNOWN_ERROR:
                MessageBox.Show("WinRing OLS_DLL_UNKNOWN_ERROR", "Ols.OlsDllStatus:");
                throw new ApplicationException("WinRing OLS_DLL_UNKNOWN_ERROR");
            }
            WriteReg(PSMU_ADDR_RSP, 0x1);
        }
Exemple #10
0
        public Ops()
        {
            amdSmuMutex = new Mutex();

            Ols = new Ols();
            CheckOlsStatus();
            CpuType     = GetCPUType(GetPackageType());
            Smu         = GetMaintainedSettings.GetByType(CpuType);
            Smu.Version = GetSmuVersion();
        }
Exemple #11
0
        public uint GetCpuId()
        {
            uint eax = 0, ebx = 0, ecx = 0, edx = 0;

            if (Ols.Cpuid(0x00000001, ref eax, ref ebx, ref ecx, ref edx) == 1)
            {
                return(eax);
            }
            return(0);
        }
Exemple #12
0
        public uint GetPkgType()
        {
            uint eax = 0, ebx = 0, ecx = 0, edx = 0;

            if (Ols.Cpuid(0x80000001, ref eax, ref ebx, ref ecx, ref edx) == 1)
            {
                return(ebx >> 28);
            }
            return(0);
        }
Exemple #13
0
        public int GetCpuNodes()
        {
            uint eax = 0, ebx = 0, ecx = 0, edx = 0;

            if (Ols.Cpuid(0x8000001E, ref eax, ref ebx, ref ecx, ref edx) == 1)
            {
                return(Convert.ToInt32(ecx >> 8 & 0x7) + 1);
            }
            return(1);
        }
Exemple #14
0
        public static Ols  InitIO()
        {
            var ols = new Ols();

            // Check support library sutatus
            switch (ols.GetStatus())
            {
            case (uint)Ols.Status.NO_ERROR:
                break;

            case (uint)Ols.Status.DLL_NOT_FOUND:
                MessageBox.Show("Status Error!! DLL_NOT_FOUND");
                return(null);

            case (uint)Ols.Status.DLL_INCORRECT_VERSION:
                MessageBox.Show("Status Error!! DLL_INCORRECT_VERSION");
                return(null);

            case (uint)Ols.Status.DLL_INITIALIZE_ERROR:
                MessageBox.Show("Status Error!! DLL_INITIALIZE_ERROR");
                return(null);
            }

            // Check WinRing0 status
            switch (ols.GetDllStatus())
            {
            case (uint)Ols.OlsDllStatus.OLS_DLL_NO_ERROR:
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED:
                MessageBox.Show("DLL Status Error!! OLS_DRIVER_NOT_LOADED");
                return(null);

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNSUPPORTED_PLATFORM:
                MessageBox.Show("DLL Status Error!! OLS_UNSUPPORTED_PLATFORM");
                return(null);

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_FOUND:
                MessageBox.Show("DLL Status Error!! OLS_DLL_DRIVER_NOT_FOUND");
                return(null);

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_UNLOADED:
                MessageBox.Show("DLL Status Error!! OLS_DLL_DRIVER_UNLOADED");
                return(null);

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK:
                MessageBox.Show("DLL Status Error!! DRIVER_NOT_LOADED_ON_NETWORK");
                return(null);

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNKNOWN_ERROR:
                MessageBox.Show("DLL Status Error!! OLS_DLL_UNKNOWN_ERROR");
                return(null);
            }
            return(ols);
        }
Exemple #15
0
        public string getStatus()
        {
            string status = "OK";

            // Check support library sutatus
            switch (Ols.GetStatus())
            {
            case (uint)Ols.Status.NO_ERROR:
                break;

            case (uint)Ols.Status.DLL_NOT_FOUND:
                status = "Status Error!! DLL_NOT_FOUND";
                break;

            case (uint)Ols.Status.DLL_INCORRECT_VERSION:
                status = "Status Error!! DLL_INCORRECT_VERSION";
                break;

            case (uint)Ols.Status.DLL_INITIALIZE_ERROR:
                status = "Status Error!! DLL_INITIALIZE_ERROR";
                break;
            }

            // Check WinRing0 status
            switch (Ols.GetDllStatus())
            {
            case (uint)Ols.OlsDllStatus.OLS_DLL_NO_ERROR:
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED:
                status = "DLL Status Error!! OLS_DRIVER_NOT_LOADED";
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNSUPPORTED_PLATFORM:
                status = "DLL Status Error!! OLS_UNSUPPORTED_PLATFORM";
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_FOUND:
                status = "DLL Status Error!! OLS_DLL_DRIVER_NOT_FOUND";
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_UNLOADED:
                status = "DLL Status Error!! OLS_DLL_DRIVER_UNLOADED";
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK:
                status = "DLL Status Error!! DRIVER_NOT_LOADED_ON_NETWORK";
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNKNOWN_ERROR:
                status = "DLL Status Error!! OLS_DLL_UNKNOWN_ERROR";
                break;
            }
            return(status);
        }
Exemple #16
0
        void WaitForEnd()
        {
            Thread.Sleep(1);
            var status = Ols.ReadIoPortByte(BaseAddress);

            while ((status & 1) == 1)
            {
                Thread.Sleep(1);
                status = Ols.ReadIoPortByte(BaseAddress);
            }
        }
Exemple #17
0
        public uint GetPatchLevel()
        {
            uint eax = 0, edx = 0;

            if (Ols.Rdmsr(0x8b, ref eax, ref edx) != 1)
            {
                return(0);
            }

            return(eax);
        }
Exemple #18
0
        public SMU.CpuFamily GetCpuFamily()
        {
            uint eax = 0, ebx = 0, ecx = 0, edx = 0;

            if (Ols.Cpuid(0x00000001, ref eax, ref ebx, ref ecx, ref edx) == 1)
            {
                SMU.CpuFamily family = (SMU.CpuFamily)(GetBits(eax, 8, 4) + GetBits(eax, 20, 7));
                return(family);
            }
            return(SMU.CpuFamily.UNSUPPORTED);
        }
Exemple #19
0
        public SMBus()
        {
            var dev = Ols.FindPciDeviceById(0x8086, 0x3b30, 0);

            if (dev != 0xffffffff)
            {
                var msb = Ols.ReadPciConfigByte(dev, 0x80);
                var lsb = Ols.ReadPciConfigByte(dev, 0x81);

                BaseAddress = (ushort)((msb << 8) | lsb);
            }
        }
Exemple #20
0
        public bool SmuWriteReg(uint addr, uint data)
        {
            bool res = false;

            amdSmuMutex.WaitOne(5000);
            if (Ols.WritePciConfigDwordEx(Smu.SMU_PCI_ADDR, Smu.SMU_OFFSET_ADDR, addr) == 1)
            {
                res = (Ols.WritePciConfigDwordEx(Smu.SMU_PCI_ADDR, Smu.SMU_OFFSET_DATA, data) == 1);
            }
            amdSmuMutex.ReleaseMutex();
            return(res);
        }
Exemple #21
0
        public Ops()
        {
            amdSmuMutex = new Mutex();

            Ols = new Ols();
            CheckOlsStatus();
            CpuType     = GetCPUType(GetPkgType());
            Smu         = GetMaintainedSettings.GetByType(CpuType);
            Smu.Version = GetSmuVersion();

            //if (!SendTestMessage())
            //    throw new ApplicationException("SMU is not responding");
        }
Exemple #22
0
        void WaitForFree()
        {
            var status = Ols.ReadIoPortByte(BaseAddress);

            while ((status & 1) != 0)
            {
                Thread.Sleep(1);
                status = Ols.ReadIoPortByte(BaseAddress);
            }
            if ((status & 0x1e) != 0)
            {
                Ols.WriteIoPortByte(BaseAddress, status);
            }
        }
Exemple #23
0
        public MainForm()
        {
            try
            {
                ols = new Ols();

                CheckOlsStatus();
                InitSystemInfo();
                InitializeComponent();
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Dispose();
                Application.Exit();
            }
        }
Exemple #24
0
        public int Call(int slaveaddress, int cmd, int rw, int length)
        {
            WaitForFree();

            Ols.WriteIoPortByte(Address(COMMAND), (byte)cmd);
            Ols.WriteIoPortByte(Address(SLAVE_TX), (byte)((slaveaddress << 1) | rw));
            Ols.WriteIoPortByte(Address(CONTROL), (byte)(length == 1 ? 0x48 : 0x4c));

            Thread.Sleep(1);
            WaitForEnd();

            var lsb = Ols.ReadIoPortByte(Address(DATA0));
            var msb = Ols.ReadIoPortByte(Address(DATA1));
            var r   = lsb | (msb << 8);

            return(r);
        }
Exemple #25
0
 private void writeEC(byte address, byte value)
 {
     /*
      * 1. Address = [EC_SC]
      * 2. Wait EC free
      * 3. Write 0x81 to [EC_SC]
      * 4. Wait IBF free
      * 5. Write Address to [EC_DATA]
      * 6. Wait IBF free
      * 7. Write Data to [EC_DATA]
      * 8. Wait IBF free
      */
     Ols.WriteIoPortByte((ushort)REG.EC_SC, 0x81);
     System.Threading.Thread.Sleep(150);
     Ols.WriteIoPortByte((ushort)REG.EC_DATA, address);
     System.Threading.Thread.Sleep(300);
     Ols.WriteIoPortByte((ushort)REG.EC_DATA, value);
 }
Exemple #26
0
 private byte readEC(byte address)
 {
     /*
      * Read Algorithm: (Thanks to Read & Write Utility)
      * 1.Address = [EC_SC]
      * 2.Wait EC free
      * 3.Write 0x80 to[EC_SC]
      * 4.Wait IBF free
      * 5.Write Address to[EC_DATA]
      * 6.Wait IBF free
      * 7.Wait OBF full
      * 8.Read Data from[EC_DATA]
      */
     Ols.WriteIoPortByte((ushort)REG.EC_SC, 0x80);
     System.Threading.Thread.Sleep(100);
     Ols.WriteIoPortByte((ushort)REG.EC_DATA, address);
     System.Threading.Thread.Sleep(100);
     return(Ols.ReadIoPortByte((ushort)REG.EC_DATA));
 }
Exemple #27
0
        public RyzenSmu()
        {
            RyzenAccesss = new Ols();
            //RyzenAccesss.InitializeOls();

            SMU_PCI_ADDR    = 0x00000000;
            SMU_OFFSET_ADDR = 0xB8;
            SMU_OFFSET_DATA = 0xBC;

            MP1_ADDR_MSG = 0x03B10528;
            MP1_ADDR_RSP = 0x03B10564;
            MP1_ADDR_ARG = 0x03B10998;

            PSMU_ADDR_MSG = 0x03B10A20;
            PSMU_ADDR_RSP = 0x03B10A80;
            PSMU_ADDR_ARG = 0x03B10A88;

            // Check WinRing0 status
            switch (RyzenAccesss.GetDllStatus())
            {
            case (uint)Ols.OlsDllStatus.OLS_DLL_NO_ERROR:
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED:
                throw new ApplicationException("WinRing OLS_DRIVER_NOT_LOADED");

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNSUPPORTED_PLATFORM:
                throw new ApplicationException("WinRing OLS_UNSUPPORTED_PLATFORM");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_FOUND:
                throw new ApplicationException("WinRing OLS_DLL_DRIVER_NOT_FOUND");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_UNLOADED:
                throw new ApplicationException("WinRing OLS_DLL_DRIVER_UNLOADED");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK:
                throw new ApplicationException("WinRing DRIVER_NOT_LOADED_ON_NETWORK");

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNKNOWN_ERROR:
                throw new ApplicationException("WinRing OLS_DLL_UNKNOWN_ERROR");
            }
            WriteReg(PSMU_ADDR_RSP, 0x1);
        }
Exemple #28
0
        public void CheckOlsStatus()
        {
            // Check support library status
            switch (Ols.GetStatus())
            {
            case (uint)Ols.Status.NO_ERROR:
                break;

            case (uint)Ols.Status.DLL_NOT_FOUND:
                throw new ApplicationException("WinRing DLL_NOT_FOUND");

            case (uint)Ols.Status.DLL_INCORRECT_VERSION:
                throw new ApplicationException("WinRing DLL_INCORRECT_VERSION");

            case (uint)Ols.Status.DLL_INITIALIZE_ERROR:
                throw new ApplicationException("WinRing DLL_INITIALIZE_ERROR");
            }

            // Check WinRing0 status
            switch (Ols.GetDllStatus())
            {
            case (uint)Ols.OlsDllStatus.OLS_DLL_NO_ERROR:
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED:
                throw new ApplicationException("WinRing OLS_DRIVER_NOT_LOADED");

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNSUPPORTED_PLATFORM:
                throw new ApplicationException("WinRing OLS_UNSUPPORTED_PLATFORM");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_FOUND:
                throw new ApplicationException("WinRing OLS_DLL_DRIVER_NOT_FOUND");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_UNLOADED:
                throw new ApplicationException("WinRing OLS_DLL_DRIVER_UNLOADED");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK:
                throw new ApplicationException("WinRing DRIVER_NOT_LOADED_ON_NETWORK");

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNKNOWN_ERROR:
                throw new ApplicationException("WinRing OLS_DLL_UNKNOWN_ERROR");
            }
        }
        public MainForm()
        {
            InitializeComponent();

            try
            {
                ols   = new Ols();
                utils = new Util();

                CheckOlsStatus();
                ReadTimings();
            }
            catch (ApplicationException ex)
            {
                SplashForm.CloseForm();
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Dispose();
                Application.Exit();
            }
        }
Exemple #30
0
        protected override bool OnStartup(StartupEventArgs e)
        {
            // First time app is launched
            ec   = new EC();
            cfg  = new Config();
            tray = new Tray();
            ols  = new Ols();

            supportMSR   = ols.GetStatus() == (uint)Ols.Status.NO_ERROR && ols.GetDllStatus() == (uint)Ols.OlsDllStatus.OLS_DLL_NO_ERROR;
            supportNVSMI = InitNVSMI();
            InitMonitor();
            tray.AddTrayIcon();
            controller = new Controller(cfg.FanCount, TimeSpan.FromMilliseconds(cfg.PollSpan));

            SetAutoStart();

            Application.ApplicationExit += onExit;
            Application.Run();
            return(false);
        }