diff --git a/super_io/super_io_pawnio.cpp b/super_io/super_io_pawnio.cpp index 13ab08f85..aac7d4d81 100644 --- a/super_io/super_io_pawnio.cpp +++ b/super_io/super_io_pawnio.cpp @@ -9,15 +9,14 @@ | SPDX-License-Identifier: GPL-2.0-or-later | \*---------------------------------------------------------*/ +#include +#include "i2c_smbus_pawnio.h" +#include "LogManager.h" +#include "PawnIOLib.h" #include "super_io.h" -#include -#include "PawnIOLib.h" -#include "i2c_smbus_pawnio.h" - -static HANDLE pawnio_handle = NULL; - -static int pawnio_chip_type = 0; +static HANDLE pawnio_handle = NULL; +static bool pawnio_superio_initialized = false; static int addr_to_pawnio(int addr) { @@ -45,36 +44,41 @@ void superio_enter(int ioreg) HRESULT status; SIZE_T return_size; - if (pawnio_handle == NULL) + if(pawnio_handle == NULL) { status = i2c_smbus_pawnio::start_pawnio("LpcIO.bin", &pawnio_handle); - if (status != S_OK) + if(status != S_OK) { - // TODO: Figure out how to handle errors return; } + else + { + LOG_TRACE("[superio] LpcIO loaded"); + } } - if (pawnio_chip_type == 0) + int in_reg = addr_to_pawnio(ioreg); + + if(in_reg == -1) { - 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]; + return; } - pawnio_execute(pawnio_handle, "ioctl_enter", NULL, 0, NULL, 0, &return_size); + const SIZE_T in_size = 1; + ULONG64 in[in_size] = {(ULONG64)in_reg}; + const SIZE_T out_size = 0; + ULONG64 out[1]; + + status = pawnio_execute(pawnio_handle, "ioctl_select_slot", in, in_size, out, out_size, &return_size); + + if(status != S_OK || out[0] == 0) + { + LOG_ERROR("[superio] LpcIO ioctl_select_slot failed with status %d", status); + return; + } + + superio_inb(ioreg, 0x87); + superio_inb(ioreg, 0x87); } @@ -88,10 +92,16 @@ void superio_enter(int ioreg) 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); + const SIZE_T in_size = 2; + ULONG64 in[in_size] = {(ULONG64)reg, (ULONG64)val}; + SIZE_T return_size; + + HRESULT status = pawnio_execute(pawnio_handle, "ioctl_superio_outb", in, in_size, NULL, 0, &return_size); + + if(status != S_OK) + { + LOG_ERROR("[superio] LpcIO ioctl_superio_outb failed at reg %04X, value %02X with status %d", reg, val, status); + } } @@ -105,15 +115,19 @@ void superio_outb([[maybe_unused]] int ioreg, int reg, int val) 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) + 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_superio_inb", in, in_size, out, out_size, &return_size); + + if(status != S_OK) { + LOG_ERROR("[superio] LpcIO ioctl_superio_inb failed at reg %04X with status %d", reg, status); return -1; } - return (int)out[0]; + + return((int)out[0]); }