Replace WinRing0 with PawnIO for SMBus and Super-IO access on Windows
Commits squashed, files cleaned up, and rebased by Adam Honse <calcprogrammer1@gmail.com>master
parent
a1449d99cf
commit
30a250c7df
Binary file not shown.
@ -0,0 +1,75 @@
|
||||
// PawnIOLib - Library and tooling source to be used with PawnIO.
|
||||
// Copyright (C) 2023 namazso <admin@namazso.eu>
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#ifndef PAWNIOLIB_LIBRARY_H
|
||||
#define PAWNIOLIB_LIBRARY_H
|
||||
|
||||
#ifdef PawnIOLib_EXPORTS
|
||||
#define PAWNIO_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define PAWNIO_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
#define PAWNIOAPI EXTERN_C PAWNIO_EXPORT HRESULT STDAPICALLTYPE
|
||||
|
||||
/// Get PawnIOLib version.
|
||||
///
|
||||
/// @p version A pointer to a ULONG which receives the version.
|
||||
/// @return A HRESULT.
|
||||
PAWNIOAPI pawnio_version(PULONG version);
|
||||
|
||||
/// Open a PawnIO executor.
|
||||
///
|
||||
/// @p handle A handle to the executor, or NULL.
|
||||
/// @return A HRESULT.
|
||||
PAWNIOAPI pawnio_open(PHANDLE handle);
|
||||
|
||||
/// Load a PawnIO blob.
|
||||
///
|
||||
/// @p handle Handle from @c pawnio_open.
|
||||
/// @p blob Blob to load.
|
||||
/// @p size Size of blob.
|
||||
/// @return A HRESULT.
|
||||
PAWNIOAPI pawnio_load(HANDLE handle, const UCHAR* blob, SIZE_T size);
|
||||
|
||||
/// Executes a function from the loaded blob.
|
||||
///
|
||||
/// @p handle Handle from @c pawnio_open.
|
||||
/// @p name Function name to execute.
|
||||
/// @p in Input buffer.
|
||||
/// @p in_size Input buffer count.
|
||||
/// @p out Output buffer.
|
||||
/// @p out_size Output buffer count.
|
||||
/// @p return_size Entries written in out_size.
|
||||
/// @return A HRESULT.
|
||||
PAWNIOAPI pawnio_execute(
|
||||
HANDLE handle,
|
||||
PCSTR name,
|
||||
const ULONG64* in,
|
||||
SIZE_T in_size,
|
||||
PULONG64 out,
|
||||
SIZE_T out_size,
|
||||
PSIZE_T return_size
|
||||
);
|
||||
|
||||
/// Close a PawnIO executor.
|
||||
///
|
||||
/// @p handle Handle from @c pawnio_open.
|
||||
/// @return A HRESULT.
|
||||
PAWNIOAPI pawnio_close(HANDLE handle);
|
||||
|
||||
#endif //PAWNIOLIB_LIBRARY_H
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,580 +0,0 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Author : hiyohiyo
|
||||
// Mail : hiyohiyo@crystalmark.info
|
||||
// Web : http://openlibsys.org/
|
||||
// License : The modified BSD license
|
||||
//
|
||||
// Copyright 2007-2009 OpenLibSys.org. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
// for WinRing0 1.3.x
|
||||
|
||||
#pragma once
|
||||
|
||||
/******************************************************************************
|
||||
**
|
||||
** DLL Information
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GetDllStatus
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // DLL Status, defined OLS_DLL_****
|
||||
WINAPI GetDllStatus();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GetDllVersion
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // DLL Version, defined OLS_VERSION
|
||||
WINAPI GetDllVersion(
|
||||
PBYTE major, // major version
|
||||
PBYTE minor, // minor version
|
||||
PBYTE revision, // revision
|
||||
PBYTE release // release/build
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GetDriverVersion
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // Device Driver Version, defined OLS_DRIVER_VERSION
|
||||
WINAPI GetDriverVersion(
|
||||
PBYTE major, // major version
|
||||
PBYTE minor, // minor version
|
||||
PBYTE revision, // revision
|
||||
PBYTE release // release/build
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// GetDriverType
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // Device Driver Type, defined OLS_DRIVER_TYPE_****
|
||||
WINAPI GetDriverType();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// InitializeOls
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI InitializeOls();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// DeinitializeOls
|
||||
//-----------------------------------------------------------------------------
|
||||
VOID WINAPI DeinitializeOls();
|
||||
|
||||
/******************************************************************************
|
||||
**
|
||||
** CPU
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IsCpuid
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: support CPUID instruction, FALSE: not support CPUID instruction
|
||||
WINAPI IsCpuid();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IsMsr
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: support MSR(Model-Specific Register), FALSE: not support MSR
|
||||
WINAPI IsMsr();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IsTsc
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: support TSC(Time Stamp Counter), FALSE: not support TSC
|
||||
WINAPI IsTsc();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Rdmsr
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI Rdmsr(
|
||||
DWORD index, // MSR index
|
||||
PDWORD eax, // bit 0-31
|
||||
PDWORD edx // bit 32-63
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RdmsrTx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI RdmsrTx(
|
||||
DWORD index, // MSR index
|
||||
PDWORD eax, // bit 0-31
|
||||
PDWORD edx, // bit 32-63
|
||||
DWORD_PTR threadAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RdmsrPx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI RdmsrPx(
|
||||
DWORD index, // MSR index
|
||||
PDWORD eax, // bit 0-31
|
||||
PDWORD edx, // bit 32-63
|
||||
DWORD_PTR processAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Wrmsr
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI Wrmsr(
|
||||
DWORD index, // MSR index
|
||||
DWORD eax, // bit 0-31
|
||||
DWORD edx // bit 32-63
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WrmsrTx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI WrmsrTx(
|
||||
DWORD index, // MSR index
|
||||
DWORD eax, // bit 0-31
|
||||
DWORD edx, // bit 32-63
|
||||
DWORD_PTR threadAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WrmsrPx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI WrmsrPx(
|
||||
DWORD index, // MSR index
|
||||
DWORD eax, // bit 0-31
|
||||
DWORD edx, // bit 32-63
|
||||
DWORD_PTR processAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Rdpmc
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI Rdpmc(
|
||||
DWORD index, // PMC index
|
||||
PDWORD eax, // bit 0-31
|
||||
PDWORD edx // bit 32-63
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RdmsrTx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI RdpmcTx(
|
||||
DWORD index, // PMC index
|
||||
PDWORD eax, // bit 0-31
|
||||
PDWORD edx, // bit 32-63
|
||||
DWORD_PTR threadAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RdmsrPx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI RdpmcPx(
|
||||
DWORD index, // PMC index
|
||||
PDWORD eax, // bit 0-31
|
||||
PDWORD edx, // bit 32-63
|
||||
DWORD_PTR processAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Cpuid
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI Cpuid(
|
||||
DWORD index, // CPUID index
|
||||
PDWORD eax,
|
||||
PDWORD ebx,
|
||||
PDWORD ecx,
|
||||
PDWORD edx
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CpuidTx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI CpuidTx(
|
||||
DWORD index, // CPUID index
|
||||
PDWORD eax,
|
||||
PDWORD ebx,
|
||||
PDWORD ecx,
|
||||
PDWORD edx,
|
||||
DWORD_PTR threadAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// CpuidPx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI CpuidPx(
|
||||
DWORD index, // CPUID index
|
||||
PDWORD eax,
|
||||
PDWORD ebx,
|
||||
PDWORD ecx,
|
||||
PDWORD edx,
|
||||
DWORD_PTR processAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Rdtsc
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI Rdtsc(
|
||||
PDWORD eax, // bit 0-31
|
||||
PDWORD edx // bit 32-63
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RdmsrTx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI RdtscTx(
|
||||
PDWORD eax, // bit 0-31
|
||||
PDWORD edx, // bit 32-63
|
||||
DWORD_PTR threadAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RdmsrPx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI RdtscPx(
|
||||
PDWORD eax, // bit 0-31
|
||||
PDWORD edx, // bit 32-63
|
||||
DWORD_PTR processAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hlt
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI Hlt();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HltTx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI HltTx(
|
||||
DWORD_PTR threadAffinityMask
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HltPx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI HltTx(
|
||||
DWORD_PTR processAffinityMask
|
||||
);
|
||||
|
||||
/******************************************************************************
|
||||
**
|
||||
** I/O
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadIoPortByte
|
||||
//-----------------------------------------------------------------------------
|
||||
BYTE // Read Value
|
||||
WINAPI ReadIoPortByte(
|
||||
WORD port // I/O port address
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadIoPortWord
|
||||
//-----------------------------------------------------------------------------
|
||||
WORD // Read Value
|
||||
WINAPI ReadIoPortWord(
|
||||
WORD port // I/O port address
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadIoPortDword
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // Read Value
|
||||
WINAPI ReadIoPortDword(
|
||||
WORD port // I/O port address
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadIoPortByteEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI ReadIoPortByteEx(
|
||||
WORD port, // I/O port address
|
||||
PBYTE value // Read Value
|
||||
);
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadIoPortWordEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI ReadIoPortWordEx(
|
||||
WORD port, // I/O port address
|
||||
PWORD value // Read Value
|
||||
);
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadIoPortDwordEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI ReadIoPortDwordEx(
|
||||
WORD port, // I/O port address
|
||||
PDWORD value // Read Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WriteIoPortByte
|
||||
//-----------------------------------------------------------------------------
|
||||
VOID
|
||||
WINAPI WriteIoPortByte(
|
||||
WORD port, // I/O port address
|
||||
BYTE value // Write Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WriteIoPortDword
|
||||
//-----------------------------------------------------------------------------
|
||||
VOID
|
||||
WINAPI WriteIoPortDword(
|
||||
WORD port, // I/O port address
|
||||
DWORD value // Write Value
|
||||
);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WriteIoPortWord
|
||||
//-----------------------------------------------------------------------------
|
||||
VOID
|
||||
WINAPI WriteIoPortWord(
|
||||
WORD port, // I/O port address
|
||||
WORD value // Write Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WriteIoPortByteEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI WriteIoPortByteEx(
|
||||
WORD port, // I/O port address
|
||||
BYTE value // Write Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WriteIoPortWordEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI WriteIoPortWordEx(
|
||||
WORD port, // I/O port address
|
||||
WORD value // Write Value
|
||||
);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WriteIoPortDwordEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI WriteIoPortDwordEx(
|
||||
WORD port, // I/O port address
|
||||
DWORD value // Write Value
|
||||
);
|
||||
|
||||
/******************************************************************************
|
||||
**
|
||||
** PCI
|
||||
**
|
||||
******************************************************************************/
|
||||
// pciAddress
|
||||
// 0- 2: Function Number
|
||||
// 3- 7: Device Number
|
||||
// 8-15: PCI Bus Number
|
||||
// 16-31: Reserved
|
||||
// 0xFFFFFFFF : Error
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// SetPciMaxBusNo
|
||||
//-----------------------------------------------------------------------------
|
||||
VOID
|
||||
WINAPI SetPciMaxBusIndex(
|
||||
BYTE max // Max PCI Bus to Scan
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadPciConfigByte
|
||||
//-----------------------------------------------------------------------------
|
||||
BYTE // Read Value
|
||||
WINAPI ReadPciConfigByte(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
BYTE regAddress // Configuration Address 0-255
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadPciConfigWord
|
||||
//-----------------------------------------------------------------------------
|
||||
WORD // Read Value
|
||||
WINAPI ReadPciConfigWord(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
BYTE regAddress // Configuration Address 0-255
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadPciConfigDword
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // Read Value
|
||||
WINAPI ReadPciConfigDword(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
BYTE regAddress // Configuration Address 0-255
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadPciConfigByteEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI ReadPciConfigByteEx(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
DWORD regAddress, // Configuration Address 0-whatever
|
||||
PBYTE value // Read Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadPciConfigWordEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI ReadPciConfigWordEx(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
DWORD regAddress, // Configuration Address 0-whatever
|
||||
PWORD value // Read Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadPciConfigDwordEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI ReadPciConfigDwordEx(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
DWORD regAddress, // Configuration Address 0-whatever
|
||||
PDWORD value // Read Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WritePciConfigByte
|
||||
//-----------------------------------------------------------------------------
|
||||
VOID
|
||||
WINAPI WritePciConfigByte(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
BYTE regAddress, // Configuration Address 0-255
|
||||
BYTE value // Write Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WritePciConfigWord
|
||||
//-----------------------------------------------------------------------------
|
||||
VOID
|
||||
WINAPI WritePciConfigWord(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
BYTE regAddress, // Configuration Address 0-255
|
||||
WORD value // Write Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WritePciConfigDword
|
||||
//-----------------------------------------------------------------------------
|
||||
VOID
|
||||
WINAPI WritePciConfigDword(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
BYTE regAddress, // Configuration Address 0-255
|
||||
DWORD value // Write Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WritePciConfigByteEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI WritePciConfigByteEx(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
DWORD regAddress, // Configuration Address 0-whatever
|
||||
BYTE value // Write Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WritePciConfigWordEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI WritePciConfigWordEx(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
DWORD regAddress, // Configuration Address 0-whatever
|
||||
WORD value // Write Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WritePciConfigDwordEx
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL // TRUE: success, FALSE: failure
|
||||
WINAPI WritePciConfigDwordEx(
|
||||
DWORD pciAddress, // PCI Device Address
|
||||
DWORD regAddress, // Configuration Address 0-whatever
|
||||
DWORD value // Write Value
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// FindPciDeviceById
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // pciAddress, 0xFFFFFFFF: failure
|
||||
WINAPI FindPciDeviceById(
|
||||
WORD vendorId, // Vendor ID
|
||||
WORD deviceId, // Device ID
|
||||
BYTE index // Index
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// FindPciDeviceByClass
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // pciAddress, 0xFFFFFFFF: failure
|
||||
WINAPI FindPciDeviceByClass(
|
||||
BYTE baseClass, // Base Class
|
||||
BYTE subClass, // Sub Class
|
||||
BYTE programIf, // Program Interface
|
||||
BYTE index // Index
|
||||
);
|
||||
|
||||
/******************************************************************************
|
||||
**
|
||||
** Memory (Special API)
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef _PHYSICAL_MEMORY_SUPPORT
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadDmiMemory
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // Read size(byte), 0: failure
|
||||
WINAPI ReadDmiMemory(
|
||||
PBYTE buffer, // Buffer
|
||||
DWORD count, // Count
|
||||
DWORD unitSize // Unit Size (BYTE, WORD, DWORD)
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ReadPhysicalMemory
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // Read size(byte), 0: failure
|
||||
WINAPI ReadPhysicalMemory(
|
||||
DWORD_PTR address, // Physical Memory Address
|
||||
PBYTE buffer, // Buffer
|
||||
DWORD count, // Count
|
||||
DWORD unitSize // Unit Size (BYTE, WORD, DWORD)
|
||||
);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WritePhysicalMemory
|
||||
//-----------------------------------------------------------------------------
|
||||
DWORD // Write size(byte), 0: failure
|
||||
WINAPI WritePhysicalMemory(
|
||||
DWORD_PTR address, // Physical Memory Address
|
||||
PBYTE buffer, // Buffer
|
||||
DWORD count, // Count
|
||||
DWORD unitSize // Unit Size (BYTE, WORD, DWORD)
|
||||
);
|
||||
#endif
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,558 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| i2c_smbus_pawnio.cpp |
|
||||
| |
|
||||
| PawnIO SMBUS driver for Windows |
|
||||
| |
|
||||
| Stephen Horvath (Steve-Tech) 04 May 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include "Detector.h"
|
||||
#include "i2c_smbus_pawnio.h"
|
||||
#include "LogManager.h"
|
||||
#include "PawnIOLib.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "SettingsManager.h"
|
||||
#include "wmi.h"
|
||||
|
||||
std::unordered_map<std::string, int> i2c_smbus_pawnio::using_handle;
|
||||
|
||||
i2c_smbus_pawnio::i2c_smbus_pawnio(HANDLE handle, std::string name)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Get driver settings |
|
||||
\*-----------------------------------------------------*/
|
||||
json drivers_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Drivers");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get shared SMBus access setting |
|
||||
\*-----------------------------------------------------*/
|
||||
bool shared_smbus_access = true;
|
||||
|
||||
if(drivers_settings.contains("shared_smbus_access"))
|
||||
{
|
||||
shared_smbus_access = drivers_settings["shared_smbus_access"].get<bool>();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create global SMBus mutex if enabled |
|
||||
\*-----------------------------------------------------*/
|
||||
if(shared_smbus_access)
|
||||
{
|
||||
global_smbus_access_handle = CreateMutexA(NULL, FALSE, GLOBAL_SMBUS_MUTEX_NAME);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Store bus information |
|
||||
| TODO: Remove name field once all drivers use the same |
|
||||
| ioctl names |
|
||||
\*-----------------------------------------------------*/
|
||||
this->handle = handle;
|
||||
this->name = name;
|
||||
|
||||
using_handle[name]++;
|
||||
}
|
||||
|
||||
i2c_smbus_pawnio::~i2c_smbus_pawnio()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Close global SMBus mutex |
|
||||
\*-----------------------------------------------------*/
|
||||
if(global_smbus_access_handle != NULL)
|
||||
{
|
||||
CloseHandle(global_smbus_access_handle);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| TODO: find a way to do this without name field |
|
||||
\*-----------------------------------------------------*/
|
||||
if(--using_handle[name] == 0 && pawnio_close(handle))
|
||||
{
|
||||
LOG_ERROR("PawnIO failed to close");
|
||||
}
|
||||
}
|
||||
|
||||
s32 i2c_smbus_pawnio::pawnio_read(u8 addr, char /*read_write*/, u8 command, int size, i2c_smbus_data* data)
|
||||
{
|
||||
SIZE_T return_size;
|
||||
|
||||
switch(size)
|
||||
{
|
||||
case I2C_SMBUS_BYTE:
|
||||
{
|
||||
const SIZE_T in_size = 1;
|
||||
ULONG64 in[in_size] = {addr};
|
||||
const SIZE_T out_size = 1;
|
||||
ULONG64 out[out_size];
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Execute PawnIO read_byte ioctl |
|
||||
\*---------------------------------------------*/
|
||||
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_read_byte").c_str(), in, in_size, out, out_size, &return_size);
|
||||
data->byte = (u8)out[0];
|
||||
|
||||
return(status ? -EIO : 0);
|
||||
}
|
||||
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
{
|
||||
const SIZE_T in_size = 2;
|
||||
ULONG64 in[in_size] = {addr, command};
|
||||
const SIZE_T out_size = 1;
|
||||
ULONG64 out[out_size];
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Execute PawnIO read_byte_data ioctl |
|
||||
\*---------------------------------------------*/
|
||||
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_read_byte_data").c_str(), in, in_size, out, out_size, &return_size);
|
||||
data->byte = (u8)out[0];
|
||||
|
||||
return(status ? -EIO : 0);
|
||||
}
|
||||
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
{
|
||||
const SIZE_T in_size = 2;
|
||||
ULONG64 in[in_size] = {addr, command};
|
||||
const SIZE_T out_size = 1;
|
||||
ULONG64 out[out_size];
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Execute PawnIO read_word_data ioctl |
|
||||
\*---------------------------------------------*/
|
||||
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_read_word_data").c_str(), in, in_size, out, out_size, &return_size);
|
||||
data->word = (u16)out[0];
|
||||
|
||||
return(status ? -EIO : 0);
|
||||
}
|
||||
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
{
|
||||
const SIZE_T in_size = 2;
|
||||
ULONG64 in[in_size] = {addr, command};
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Calculate output data buffer size |
|
||||
| Pawn only deals with 64-bit cells, divide by |
|
||||
| 8 to convert bytes to qwords. |
|
||||
| The first cell is also the length. |
|
||||
\*---------------------------------------------*/
|
||||
const SIZE_T out_size = 1 + (I2C_SMBUS_BLOCK_MAX / 8);
|
||||
ULONG64 out[out_size];
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Execute PawnIO read_block_data ioctl |
|
||||
\*---------------------------------------------*/
|
||||
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_read_block_data").c_str(), in, in_size, out, out_size, &return_size);
|
||||
|
||||
if(status)
|
||||
{
|
||||
return(-EIO);
|
||||
}
|
||||
|
||||
if(out[0] == 0 || out[0] > I2C_SMBUS_BLOCK_MAX)
|
||||
{
|
||||
return(-EPROTO);
|
||||
}
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Unpack bytes from 64bit Pawn cells |
|
||||
\*---------------------------------------------*/
|
||||
u8 *out_bytes = (u8*)(&out[1]);
|
||||
memcpy(&data->block[1], out_bytes, out[0]);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
default:
|
||||
return(-EOPNOTSUPP);
|
||||
}
|
||||
}
|
||||
|
||||
s32 i2c_smbus_pawnio::pawnio_write(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data)
|
||||
{
|
||||
SIZE_T return_size;
|
||||
|
||||
switch(size)
|
||||
{
|
||||
case I2C_SMBUS_QUICK:
|
||||
{
|
||||
const SIZE_T in_size = 2;
|
||||
ULONG64 in[in_size] = {addr, (u8)read_write};
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Execute PawnIO write_quick ioctl |
|
||||
\*---------------------------------------------*/
|
||||
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_quick").c_str(), in, in_size, NULL, 0, &return_size);
|
||||
|
||||
return(status ? -EIO : 0);
|
||||
}
|
||||
|
||||
case I2C_SMBUS_BYTE:
|
||||
{
|
||||
const SIZE_T in_size = 2;
|
||||
ULONG64 in[in_size] = {addr, data->byte};
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Execute PawnIO write_byte ioctl |
|
||||
\*---------------------------------------------*/
|
||||
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_byte").c_str(), in, in_size, NULL, 0, &return_size);
|
||||
|
||||
return(status ? -EIO : 0);
|
||||
}
|
||||
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
{
|
||||
const SIZE_T in_size = 3;
|
||||
ULONG64 in[in_size] = {addr, command, data->byte};
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Execute PawnIO write_byte_data ioctl |
|
||||
\*---------------------------------------------*/
|
||||
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_byte_data").c_str(), in, in_size, NULL, 0, &return_size);
|
||||
|
||||
return(status ? -EIO : 0);
|
||||
}
|
||||
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
{
|
||||
const SIZE_T in_size = 3;
|
||||
ULONG64 in[in_size] = {addr, command, data->word};
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Execute PawnIO write_word_data ioctl |
|
||||
\*---------------------------------------------*/
|
||||
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_word_data").c_str(), in, in_size, NULL, 0, &return_size);
|
||||
|
||||
return(status ? -EIO : 0);
|
||||
}
|
||||
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
{
|
||||
SIZE_T len = data->block[0];
|
||||
if(len == 0 || len > I2C_SMBUS_BLOCK_MAX)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
const SIZE_T in_size = 3 + (I2C_SMBUS_BLOCK_MAX/8);
|
||||
ULONG64 in[3 + (I2C_SMBUS_BLOCK_MAX/8)] = {addr, command, len};
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Pack bytes into 64bit Pawn cells |
|
||||
\*---------------------------------------------*/
|
||||
u8 *in_bytes = (u8*)&in[3];
|
||||
memcpy(in_bytes, &data->block[1], len);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Execute PawnIO write_block_data ioctl |
|
||||
\*---------------------------------------------*/
|
||||
HRESULT status = pawnio_execute(handle, ("ioctl_" + name + "_write_block_data").c_str(), in, in_size, NULL, 0, &return_size);
|
||||
|
||||
return(status ? -EIO : 0);
|
||||
}
|
||||
|
||||
default:
|
||||
return(-EOPNOTSUPP);
|
||||
}
|
||||
}
|
||||
|
||||
s32 i2c_smbus_pawnio::i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data)
|
||||
{
|
||||
if(global_smbus_access_handle != NULL)
|
||||
{
|
||||
WaitForSingleObject(global_smbus_access_handle, INFINITE);
|
||||
}
|
||||
|
||||
int status = -ENXIO;
|
||||
|
||||
if(read_write && size != I2C_SMBUS_QUICK) {
|
||||
status = pawnio_read(addr, read_write, command, size, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = pawnio_write(addr, read_write, command, size, data);
|
||||
}
|
||||
|
||||
if(global_smbus_access_handle != NULL)
|
||||
{
|
||||
ReleaseMutex(global_smbus_access_handle);
|
||||
}
|
||||
|
||||
return(status);
|
||||
}
|
||||
|
||||
s32 i2c_smbus_pawnio::i2c_xfer(u8 /*addr*/, char /*read_write*/, int* /*size*/, u8* /*data*/)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// TODO: Find a better place for this function
|
||||
HRESULT i2c_smbus_pawnio::start_pawnio(std::string filename, PHANDLE phandle)
|
||||
{
|
||||
char exePath[MAX_PATH];
|
||||
HANDLE handle;
|
||||
HRESULT status;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Open PawnIO driver |
|
||||
\*-----------------------------------------------------*/
|
||||
status = pawnio_open(phandle);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Check result |
|
||||
\*-----------------------------------------------------*/
|
||||
if(status)
|
||||
{
|
||||
if(status == E_ACCESSDENIED)
|
||||
{
|
||||
LOG_ERROR("Permission Denied, PawnIO initialization aborted");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Could not open PawnIO, PawnIO initialization aborted");
|
||||
}
|
||||
|
||||
return(status);
|
||||
}
|
||||
|
||||
handle = *phandle;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get the path of the executable |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!GetModuleFileNameA(NULL, exePath, MAX_PATH))
|
||||
{
|
||||
LOG_ERROR("Failed to get executable path, PawnIO initialization aborted");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Construct the path to `filename` in the executable's |
|
||||
| directory |
|
||||
\*-----------------------------------------------------*/
|
||||
std::filesystem::path exeDir = std::filesystem::path(exePath).parent_path();
|
||||
std::filesystem::path filePath = exeDir / filename;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Check if the file exists |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!std::filesystem::exists(filePath))
|
||||
{
|
||||
LOG_ERROR("Failed to find %s in the executable's directory, PawnIO initialization aborted", filename.c_str());
|
||||
return(E_FAIL);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Open the file |
|
||||
\*-----------------------------------------------------*/
|
||||
std::ifstream file(filePath, std::ios::binary);
|
||||
|
||||
if(!file.is_open())
|
||||
{
|
||||
LOG_ERROR("Failed to open %s, PawnIO initialization aborted", filename.c_str());
|
||||
return(E_FAIL);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Read the contents of the file into a vector of bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<char> blob((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Close the file |
|
||||
\*-----------------------------------------------------*/
|
||||
file.close();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Load the file into PawnIO |
|
||||
\*-----------------------------------------------------*/
|
||||
status = pawnio_load(handle, reinterpret_cast<const UCHAR*>(blob.data()), blob.size());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Check if the load was successful |
|
||||
\*-----------------------------------------------------*/
|
||||
if(status)
|
||||
{
|
||||
LOG_ERROR("Failed to load %s, PawnIO initialization aborted", filename.c_str());
|
||||
return(status);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Log a message and return OK if PawnIO successfully |
|
||||
| opened |
|
||||
\*-----------------------------------------------------*/
|
||||
LOG_INFO("PawnIO initialized");
|
||||
return(S_OK);
|
||||
}
|
||||
|
||||
s32 piix4_port_sel(HANDLE pawnio_handle, s32 port)
|
||||
{
|
||||
const SIZE_T in_size = 1;
|
||||
ULONG64 in[in_size] = {(ULONG64)port};
|
||||
const SIZE_T out_size = 1;
|
||||
ULONG64 out[out_size];
|
||||
SIZE_T return_size;
|
||||
HRESULT status;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Execute PIIX4 port_sel ioctl |
|
||||
\*-----------------------------------------------------*/
|
||||
status = pawnio_execute(pawnio_handle, "ioctl_piix4_port_sel", in, in_size, out, 1, &return_size);
|
||||
|
||||
return(status ? -EIO : 0);
|
||||
}
|
||||
|
||||
bool i2c_smbus_pawnio_detect()
|
||||
{
|
||||
ULONG dll_version;
|
||||
if(pawnio_version(&dll_version))
|
||||
{
|
||||
LOG_INFO("PawnIO is not loaded, PawnIO I2C bus detection aborted");
|
||||
return(false);
|
||||
}
|
||||
|
||||
i2c_smbus_interface * bus;
|
||||
HRESULT hres;
|
||||
Wmi wmi;
|
||||
HANDLE pawnio_handle;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Query WMI for Win32_PnPSignedDriver entries with |
|
||||
| names matching "SMBUS" or "SM BUS". These devices |
|
||||
| may be browsed under Device Manager -> System Devices |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<QueryObj> q_res_PnPSignedDriver;
|
||||
hres = wmi.query("SELECT * FROM Win32_PnPSignedDriver WHERE Description LIKE '%SMBUS%' OR Description LIKE '%SM BUS%'", q_res_PnPSignedDriver);
|
||||
|
||||
if(hres)
|
||||
{
|
||||
LOG_INFO("WMI query failed, I2C bus detection aborted");
|
||||
return(false);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| For each detected SMBus adapter, try enumerating it |
|
||||
| as either AMD (piix4) or Intel (i801) |
|
||||
\*-----------------------------------------------------*/
|
||||
for(QueryObj &i : q_res_PnPSignedDriver)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Intel SMBus controllers do show I/O resources in |
|
||||
| Device Manager. Analysis of many Intel boards |
|
||||
| has shown that Intel SMBus adapter I/O space |
|
||||
| varies between boards. We can query |
|
||||
| Win32_PnPAllocatedResource entries and look up |
|
||||
| the PCI device ID to find the allocated I/O space.|
|
||||
| |
|
||||
| Intel SMBus adapters use the i801 driver |
|
||||
\*-------------------------------------------------*/
|
||||
if((i["Manufacturer"].find("Intel") != std::string::npos)
|
||||
|| (i["Manufacturer"].find("INTEL") != std::string::npos))
|
||||
{
|
||||
std::string pnp_str = i["DeviceID"];
|
||||
|
||||
std::size_t ven_loc = pnp_str.find("VEN_");
|
||||
std::size_t dev_loc = pnp_str.find("DEV_");
|
||||
std::size_t sub_loc = pnp_str.find("SUBSYS_");
|
||||
|
||||
std::string ven_str = pnp_str.substr(ven_loc + 4, 4);
|
||||
std::string dev_str = pnp_str.substr(dev_loc + 4, 4);
|
||||
std::string sbv_str = pnp_str.substr(sub_loc + 11, 4);
|
||||
std::string sbd_str = pnp_str.substr(sub_loc + 7, 4);
|
||||
|
||||
int ven_id = (int)std::stoul(ven_str, nullptr, 16);
|
||||
int dev_id = (int)std::stoul(dev_str, nullptr, 16);
|
||||
int sbv_id = (int)std::stoul(sbv_str, nullptr, 16);
|
||||
int sbd_id = (int)std::stoul(sbd_str, nullptr, 16);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Create bus |
|
||||
\*---------------------------------------------*/
|
||||
if(i2c_smbus_pawnio::start_pawnio("SmbusI801.bin", &pawnio_handle) != S_OK)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
bus = new i2c_smbus_pawnio(pawnio_handle, "i801");
|
||||
bus->pci_vendor = ven_id;
|
||||
bus->pci_device = dev_id;
|
||||
bus->pci_subsystem_vendor = sbv_id;
|
||||
bus->pci_subsystem_device = sbd_id;
|
||||
strncpy(bus->device_name, i["Description"].c_str(), sizeof bus->device_name);
|
||||
ResourceManager::get()->RegisterI2CBus(bus);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| AMD SMBus adapters use the PIIX4 driver |
|
||||
\*-------------------------------------------------*/
|
||||
else if(i["Manufacturer"].find("Advanced Micro Devices, Inc") != std::string::npos)
|
||||
{
|
||||
std::string pnp_str = i["DeviceID"];
|
||||
|
||||
std::size_t ven_loc = pnp_str.find("VEN_");
|
||||
std::size_t dev_loc = pnp_str.find("DEV_");
|
||||
std::size_t sub_loc = pnp_str.find("SUBSYS_");
|
||||
|
||||
std::string ven_str = pnp_str.substr(ven_loc + 4, 4);
|
||||
std::string dev_str = pnp_str.substr(dev_loc + 4, 4);
|
||||
std::string sbv_str = pnp_str.substr(sub_loc + 11, 4);
|
||||
std::string sbd_str = pnp_str.substr(sub_loc + 7, 4);
|
||||
|
||||
int ven_id = (int)std::stoul(ven_str, nullptr, 16);
|
||||
int dev_id = (int)std::stoul(dev_str, nullptr, 16);
|
||||
int sbv_id = (int)std::stoul(sbv_str, nullptr, 16);
|
||||
int sbd_id = (int)std::stoul(sbd_str, nullptr, 16);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Create primary bus |
|
||||
\*---------------------------------------------*/
|
||||
if(i2c_smbus_pawnio::start_pawnio("SmbusPIIX4.bin", &pawnio_handle) != S_OK)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Select port 0 |
|
||||
\*---------------------------------------------*/
|
||||
piix4_port_sel(pawnio_handle, 0);
|
||||
|
||||
bus = new i2c_smbus_pawnio(pawnio_handle, "piix4");
|
||||
bus->pci_vendor = ven_id;
|
||||
bus->pci_device = dev_id;
|
||||
bus->pci_subsystem_vendor = sbv_id;
|
||||
bus->pci_subsystem_device = sbd_id;
|
||||
strncpy(bus->device_name, i["Description"].c_str(), sizeof bus->device_name);
|
||||
strncat(bus->device_name, " port 0", sizeof bus->device_name);
|
||||
ResourceManager::get()->RegisterI2CBus(bus);
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Create secondary bus |
|
||||
\*---------------------------------------------*/
|
||||
if(i2c_smbus_pawnio::start_pawnio("SmbusPIIX4.bin", &pawnio_handle) != S_OK)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
|
||||
/*---------------------------------------------*\
|
||||
| Select port 1 |
|
||||
\*---------------------------------------------*/
|
||||
piix4_port_sel(pawnio_handle, 1);
|
||||
|
||||
bus = new i2c_smbus_pawnio(pawnio_handle, "piix4");
|
||||
bus->pci_vendor = ven_id;
|
||||
bus->pci_device = dev_id;
|
||||
bus->pci_subsystem_vendor = sbv_id;
|
||||
bus->pci_subsystem_device = sbd_id;
|
||||
strncpy(bus->device_name, i["Description"].c_str(), sizeof bus->device_name);
|
||||
strncat(bus->device_name, " port 1", sizeof bus->device_name);
|
||||
ResourceManager::get()->RegisterI2CBus(bus);
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
REGISTER_I2C_BUS_DETECTOR(i2c_smbus_pawnio_detect);
|
||||
@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| i2c_smbus_piix4_pawnio.h |
|
||||
| |
|
||||
| PawnIO PIIX4 SMBUS driver for Windows |
|
||||
| |
|
||||
| Stephen Horvath (Steve-Tech) 21 Apr 2025 |
|
||||
| Based on original OpenRGB PIIX4 source code |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
#include "i2c_smbus.h"
|
||||
|
||||
#define GLOBAL_SMBUS_MUTEX_NAME "Global\\Access_SMBUS.HTP.Method"
|
||||
|
||||
class i2c_smbus_pawnio : public i2c_smbus_interface
|
||||
{
|
||||
public:
|
||||
static std::unordered_map<std::string, int> using_handle;
|
||||
i2c_smbus_pawnio(HANDLE handle, std::string name);
|
||||
~i2c_smbus_pawnio();
|
||||
|
||||
static HRESULT start_pawnio(std::string filename, PHANDLE phandle);
|
||||
|
||||
private:
|
||||
s32 pawnio_read(u8 addr, char read_write, u8 command, int size, i2c_smbus_data *data);
|
||||
s32 pawnio_write(u8 addr, char read_write, u8 command, int size, i2c_smbus_data *data);
|
||||
s32 i2c_smbus_xfer(u8 addr, char read_write, u8 command, int size, i2c_smbus_data* data);
|
||||
s32 i2c_xfer(u8 addr, char read_write, int* size, u8* data);
|
||||
|
||||
HANDLE global_smbus_access_handle;
|
||||
std::string name;
|
||||
HANDLE handle;
|
||||
};
|
||||
@ -0,0 +1,120 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| super_io_pawnio.cpp |
|
||||
| |
|
||||
| Functions for interfacing with Super-IO using PawnIO |
|
||||
| |
|
||||
| Stephen Horvath (Steve-Tech) 05 May 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "super_io_pawnio.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include "PawnIOLib.h"
|
||||
#include "i2c_smbus_pawnio.h"
|
||||
|
||||
|
||||
static HANDLE pawnio_handle = NULL;
|
||||
|
||||
static int pawnio_chip_type = 0;
|
||||
|
||||
static int addr_to_pawnio(int addr)
|
||||
{
|
||||
switch (addr)
|
||||
{
|
||||
case 0x2E:
|
||||
return 0;
|
||||
case 0x4E:
|
||||
return 1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* pawnio_superio_enter *
|
||||
* *
|
||||
* Put the Super IO chip into Extended Function Mode *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void superio_enter(int ioreg)
|
||||
{
|
||||
HRESULT status;
|
||||
SIZE_T return_size;
|
||||
|
||||
if (pawnio_handle == NULL)
|
||||
{
|
||||
status = i2c_smbus_pawnio::start_pawnio("superio", &pawnio_handle);
|
||||
if (status != S_OK)
|
||||
{
|
||||
// TODO: Figure out how to handle errors
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (pawnio_chip_type == 0)
|
||||
{
|
||||
int in_reg = addr_to_pawnio(ioreg);
|
||||
if (in_reg == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const SIZE_T in_size = 1;
|
||||
ULONG64 in[in_size] = {(ULONG64)in_reg};
|
||||
const SIZE_T out_size = 1;
|
||||
ULONG64 out[out_size];
|
||||
status = pawnio_execute(pawnio_handle, "ioctl_detect", in, in_size, out, out_size, &return_size);
|
||||
if (status != S_OK || out[0] == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pawnio_chip_type = (int)out[0];
|
||||
}
|
||||
|
||||
pawnio_execute(pawnio_handle, "ioctl_enter", NULL, 0, NULL, 0, &return_size);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* pawnio_superio_outb *
|
||||
* *
|
||||
* Write a byte to the Super IO configuration register *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void superio_outb([[maybe_unused]] int ioreg, int reg, int val)
|
||||
{
|
||||
const SIZE_T in_size = 2;
|
||||
ULONG64 in[in_size] = {(ULONG64)reg, (ULONG64)val};
|
||||
SIZE_T return_size;
|
||||
pawnio_execute(pawnio_handle, "ioctl_write", in, in_size, NULL, 0, &return_size);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* pawnio_superio_inb *
|
||||
* *
|
||||
* Read a byte from the Super IO configuration register *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
int superio_inb([[maybe_unused]] int ioreg, int reg)
|
||||
{
|
||||
const SIZE_T in_size = 1;
|
||||
ULONG64 in[in_size] = {(ULONG64)reg};
|
||||
const SIZE_T out_size = 1;
|
||||
ULONG64 out[out_size];
|
||||
SIZE_T return_size;
|
||||
HRESULT status = pawnio_execute(pawnio_handle, "ioctl_read", in, in_size, out, out_size, &return_size);
|
||||
if (status != S_OK)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return (int)out[0];
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| super_io_pawnio.h |
|
||||
| |
|
||||
| Functions for interfacing with Super-IO using PawnIO |
|
||||
| |
|
||||
| Stephen Horvath (Steve-Tech) 05 May 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-only |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void superio_enter(int ioreg);
|
||||
|
||||
void superio_outb(int ioreg, int reg, int val);
|
||||
|
||||
int superio_inb(int ioreg, int reg);
|
||||
Loading…
Reference in New Issue