mirror of
https://gitea.tendokyu.moe/Hay1tsme/segatools.git
synced 2024-11-30 19:54:27 +01:00
platform: Add basic hwreset implementation for ALLS
This commit is contained in:
parent
cd5ae172b8
commit
cc95389646
@ -14,6 +14,7 @@
|
||||
#include "platform/config.h"
|
||||
#include "platform/dns.h"
|
||||
#include "platform/hwmon.h"
|
||||
#include "platform/hwreset.h"
|
||||
#include "platform/misc.h"
|
||||
#include "platform/netenv.h"
|
||||
#include "platform/nusec.h"
|
||||
@ -30,6 +31,7 @@ void platform_config_load(struct platform_config *cfg, const wchar_t *filename)
|
||||
clock_config_load(&cfg->clock, filename);
|
||||
dns_config_load(&cfg->dns, filename);
|
||||
hwmon_config_load(&cfg->hwmon, filename);
|
||||
hwreset_config_load(&cfg->hwreset, filename);
|
||||
misc_config_load(&cfg->misc, filename);
|
||||
pcbid_config_load(&cfg->pcbid, filename);
|
||||
netenv_config_load(&cfg->netenv, filename);
|
||||
@ -117,9 +119,18 @@ void hwmon_config_load(struct hwmon_config *cfg, const wchar_t *filename)
|
||||
cfg->enable = GetPrivateProfileIntW(L"hwmon", L"enable", 1, filename);
|
||||
}
|
||||
|
||||
void hwreset_config_load(struct hwreset_config *cfg, const wchar_t *filename)
|
||||
{
|
||||
assert(cfg != NULL);
|
||||
assert(filename != NULL);
|
||||
|
||||
cfg->enable = GetPrivateProfileIntW(L"hwreset", L"enable", 1, filename);
|
||||
}
|
||||
|
||||
void misc_config_load(struct misc_config *cfg, const wchar_t *filename)
|
||||
{
|
||||
assert(cfg != NULL);
|
||||
assert(filename != NULL);
|
||||
|
||||
cfg->enable = GetPrivateProfileIntW(L"misc", L"enable", 1, filename);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "platform/clock.h"
|
||||
#include "platform/dns.h"
|
||||
#include "platform/hwmon.h"
|
||||
#include "platform/hwreset.h"
|
||||
#include "platform/misc.h"
|
||||
#include "platform/netenv.h"
|
||||
#include "platform/nusec.h"
|
||||
@ -25,6 +26,7 @@ void amvideo_config_load(struct amvideo_config *cfg, const wchar_t *filename);
|
||||
void clock_config_load(struct clock_config *cfg, const wchar_t *filename);
|
||||
void dns_config_load(struct dns_config *cfg, const wchar_t *filename);
|
||||
void hwmon_config_load(struct hwmon_config *cfg, const wchar_t *filename);
|
||||
void hwreset_config_load(struct hwreset_config *cfg, const wchar_t *filename);
|
||||
void misc_config_load(struct misc_config *cfg, const wchar_t *filename);
|
||||
void netenv_config_load(struct netenv_config *cfg, const wchar_t *filename);
|
||||
void nusec_config_load(struct nusec_config *cfg, const wchar_t *filename);
|
||||
|
107
platform/hwreset.c
Normal file
107
platform/hwreset.c
Normal file
@ -0,0 +1,107 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "hook/iohook.h"
|
||||
|
||||
#include "platform/hwreset.h"
|
||||
|
||||
#include "util/dprintf.h"
|
||||
#include "util/str.h"
|
||||
|
||||
enum {
|
||||
HWRESET_IOCTL_RESTART = 0x80002000,
|
||||
};
|
||||
|
||||
static HRESULT hwreset_handle_irp(struct irp *irp);
|
||||
static HRESULT hwreset_handle_open(struct irp *irp);
|
||||
static HRESULT hwreset_handle_close(struct irp *irp);
|
||||
static HRESULT hwreset_handle_ioctl(struct irp *irp);
|
||||
|
||||
static HRESULT hwreset_ioctl_restart(struct irp *irp);
|
||||
|
||||
static HANDLE hwreset_fd;
|
||||
|
||||
HRESULT hwreset_hook_init(const struct hwreset_config *cfg)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
assert(cfg != NULL);
|
||||
|
||||
if (!cfg->enable) {
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
hr = iohook_open_nul_fd(&hwreset_fd);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = iohook_push_handler(hwreset_handle_irp);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT hwreset_handle_irp(struct irp *irp)
|
||||
{
|
||||
assert(irp != NULL);
|
||||
|
||||
if (irp->op != IRP_OP_OPEN && irp->fd != hwreset_fd) {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
switch (irp->op) {
|
||||
case IRP_OP_OPEN: return hwreset_handle_open(irp);
|
||||
case IRP_OP_CLOSE: return hwreset_handle_close(irp);
|
||||
case IRP_OP_IOCTL: return hwreset_handle_ioctl(irp);
|
||||
default: return HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
|
||||
}
|
||||
}
|
||||
|
||||
static HRESULT hwreset_handle_open(struct irp *irp)
|
||||
{
|
||||
if (!wstr_ieq(irp->open_filename, L"\\\\.\\sghwreset")) {
|
||||
return iohook_invoke_next(irp);
|
||||
}
|
||||
|
||||
dprintf("Hwreset: Opened device\n");
|
||||
irp->fd = hwreset_fd;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT hwreset_handle_close(struct irp *irp)
|
||||
{
|
||||
dprintf("Hwreset: Closed device\n");
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT hwreset_handle_ioctl(struct irp *irp)
|
||||
{
|
||||
switch (irp->ioctl) {
|
||||
case HWRESET_IOCTL_RESTART:
|
||||
return hwreset_ioctl_restart(irp);
|
||||
|
||||
default:
|
||||
dprintf("Hwreset: Unknown ioctl %08x, write %i read %i\n",
|
||||
irp->ioctl,
|
||||
(int) irp->write.nbytes,
|
||||
(int) irp->read.nbytes);
|
||||
|
||||
return HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
|
||||
}
|
||||
}
|
||||
|
||||
static HRESULT hwreset_ioctl_restart(struct irp *irp)
|
||||
{
|
||||
dprintf("Hwreset: Reset requested\n");
|
||||
|
||||
return iobuf_write_le32(&irp->read, 1);
|
||||
}
|
11
platform/hwreset.h
Normal file
11
platform/hwreset.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct hwreset_config {
|
||||
bool enable;
|
||||
};
|
||||
|
||||
HRESULT hwreset_hook_init(const struct hwreset_config *cfg);
|
@ -18,6 +18,8 @@ platform_lib = static_library(
|
||||
'dns.h',
|
||||
'hwmon.c',
|
||||
'hwmon.h',
|
||||
'hwreset.c',
|
||||
'hwreset.h',
|
||||
'misc.c',
|
||||
'misc.h',
|
||||
'netenv.c',
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "platform/clock.h"
|
||||
#include "platform/dns.h"
|
||||
#include "platform/hwmon.h"
|
||||
#include "platform/hwreset.h"
|
||||
#include "platform/misc.h"
|
||||
#include "platform/netenv.h"
|
||||
#include "platform/nusec.h"
|
||||
@ -17,6 +18,7 @@ struct platform_config {
|
||||
struct clock_config clock;
|
||||
struct dns_config dns;
|
||||
struct hwmon_config hwmon;
|
||||
struct hwreset_config hwreset;
|
||||
struct misc_config misc;
|
||||
struct pcbid_config pcbid;
|
||||
struct netenv_config netenv;
|
||||
|
Loading…
Reference in New Issue
Block a user