Added DMI reader (Windows only).

This commit is contained in:
XMRig 2021-01-18 11:23:29 +07:00
parent ea367da064
commit 11e0d3de3a
No known key found for this signature in database
GPG key ID: 446A53638BE94409
13 changed files with 825 additions and 0 deletions

192
src/hw/dmi/DmiMemory.cpp Normal file
View file

@ -0,0 +1,192 @@
/* XMRig
* Copyright (c) 2000-2002 Alan Cox <alan@redhat.com>
* Copyright (c) 2005-2020 Jean Delvare <jdelvare@suse.de>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "hw/dmi/DmiMemory.h"
#include "hw/dmi/DmiTools.h"
#include <algorithm>
#include <array>
namespace xmrig {
static inline uint16_t dmi_memory_device_width(uint16_t code)
{
return (code == 0xFFFF || code == 0) ? 0 : code;
}
static const char *dmi_memory_device_form_factor(uint8_t code)
{
static const std::array<const char *, 0x10> form_factor
{
"Other",
"Unknown",
"SIMM",
"SIP",
"Chip",
"DIP",
"ZIP",
"Proprietary Card",
"DIMM",
"TSOP",
"Row Of Chips",
"RIMM",
"SODIMM",
"SRIMM",
"FB-DIMM",
"Die"
};
if (code >= 0x01 && code <= form_factor.size()) {
return form_factor[code - 0x01];
}
return form_factor[1];
}
static const char *dmi_memory_device_type(uint8_t code)
{
static const std::array<const char *, 0x23> type
{
"Other", /* 0x01 */
"Unknown",
"DRAM",
"EDRAM",
"VRAM",
"SRAM",
"RAM",
"ROM",
"Flash",
"EEPROM",
"FEPROM",
"EPROM",
"CDRAM",
"3DRAM",
"SDRAM",
"SGRAM",
"RDRAM",
"DDR",
"DDR2",
"DDR2 FB-DIMM",
"Reserved",
"Reserved",
"Reserved",
"DDR3",
"FBD2",
"DDR4",
"LPDDR",
"LPDDR2",
"LPDDR3",
"LPDDR4",
"Logical non-volatile device",
"HBM",
"HBM2",
"DDR5",
"LPDDR5"
};
if (code >= 0x01 && code <= type.size()) {
return type[code - 0x01];
}
return type[1];
}
static uint64_t dmi_memory_device_speed(uint16_t code1, uint32_t code2)
{
return (code1 == 0xFFFF) ? code2 : code1;
}
} // namespace xmrig
xmrig::DmiMemory::DmiMemory(dmi_header *h)
{
if (h->length < 0x15) {
return;
}
m_totalWidth = dmi_memory_device_width(dmi_get<uint16_t>(h, 0x08));
m_width = dmi_memory_device_width(dmi_get<uint16_t>(h, 0x0A));
auto size = dmi_get<uint16_t>(h, 0x0C);
if (h->length >= 0x20 && size == 0x7FFF) {
m_size = (dmi_get<uint32_t>(h, 0x1C) & 0x7FFFFFFFUL) * 1024ULL * 1024ULL;
}
else if (size) {
m_size = (1024ULL * (size & 0x7FFF) * ((size & 0x8000) ? 1 : 1024ULL));
}
m_formFactor = h->data[0x0E];
m_slot = dmi_string(h, 0x10);
m_bank = dmi_string(h, 0x11);
m_type = h->data[0x12];
if (!m_size || h->length < 0x17) {
return;
}
m_speed = dmi_memory_device_speed(dmi_get<uint16_t>(h, 0x15), h->length >= 0x5C ? dmi_get<uint32_t>(h, 0x54) : 0) * 1000000ULL;
if (h->length < 0x1B) {
return;
}
m_vendor = dmi_string(h, 0x17);
m_product = dmi_string(h, 0x1A);
if (h->length < 0x1C) {
return;
}
m_rank = h->data[0x1B] & 0x0F;
if (h->length < 0x22) {
return;
}
m_speed = std::max(m_speed, dmi_memory_device_speed(dmi_get<uint16_t>(h, 0x20), h->length >= 0x5C ? dmi_get<uint32_t>(h, 0x58) : 0) * 1000000ULL);
if (h->length < 0x28) {
return;
}
m_voltage = dmi_get<uint16_t>(h, 0x26);
}
const char *xmrig::DmiMemory::formFactor() const
{
return dmi_memory_device_form_factor(m_formFactor);
}
const char *xmrig::DmiMemory::type() const
{
return dmi_memory_device_type(m_type);
}