-
Notifications
You must be signed in to change notification settings - Fork 11
/
psp-dev-acpi.c
118 lines (101 loc) · 3.14 KB
/
psp-dev-acpi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/** @file
* PSP Emulator - ACPI PM interface accessible through x86 MMIO.
*/
/*
* Copyright (C) 2020 Alexander Eichner <alexander.eichner@campus.tu-berlin.de>
*
* 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, version 3.
*
* 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 <stdio.h>
#include <common/cdefs.h>
#include <psp-devs.h>
#include <psp-trace.h>
/**
* ACPI device instance data.
*/
typedef struct PSPDEVACPI
{
/** Pointer to the owning device instance. */
PPSPDEV pDev;
/** MMIO region handle. */
PSPIOMREGIONHANDLE hMmioX86;
} PSPDEVACPI;
/** Pointer to the device instance data. */
typedef PSPDEVACPI *PPSPDEVACPI;
static void pspDevX86AcpiRead(X86PADDR offMmio, size_t cbRead, void *pvVal, void *pvUser)
{
PPSPDEVACPI pThis = (PPSPDEVACPI)pvUser;
if (cbRead != sizeof(uint16_t))
{
PSPEmuTraceEvtAddString(NULL, PSPTRACEEVTSEVERITY_ERROR, PSPTRACEEVTORIGIN_ACPI,
"Invalid register read size %u cbRead=%zu", offMmio, cbRead);
return;
}
uint16_t *pu16Val = (uint16_t *)pvVal;
switch (pThis->pDev->pCfg->enmAcpiState)
{
case PSPEMUACPISTATE_S0:
*pu16Val = (0 & 0x7) << 10;
break;
case PSPEMUACPISTATE_S1:
*pu16Val = (1 & 0x7) << 10;
break;
case PSPEMUACPISTATE_S2:
*pu16Val = (2 & 0x7) << 10;
break;
case PSPEMUACPISTATE_S3:
*pu16Val = (3 & 0x7) << 10;
break;
case PSPEMUACPISTATE_S4:
*pu16Val = (4 & 0x7) << 10;
break;
case PSPEMUACPISTATE_S5:
*pu16Val = (5 & 0x7) << 10;
break;
default:
PSPEmuTraceEvtAddString(NULL, PSPTRACEEVTSEVERITY_ERROR, PSPTRACEEVTORIGIN_ACPI,
"Invalid ACPI state configured: %d", pThis->pDev->pCfg->enmAcpiState);
}
}
static int pspDevAcpiInit(PPSPDEV pDev)
{
PPSPDEVACPI pThis = (PPSPDEVACPI)&pDev->abInstance[0];
pThis->pDev = pDev;
/* Register MMIO ranges. */
int rc = PSPEmuIoMgrX86MmioRegister(pDev->hIoMgr, 0xfed80804, 2,
pspDevX86AcpiRead, NULL, pThis,
"AcpiPmCtrl", &pThis->hMmioX86);
return rc;
}
static void pspDevAcpiDestruct(PPSPDEV pDev)
{
/* Nothing to do so far. */
}
/**
* Device registration structure.
*/
const PSPDEVREG g_DevRegAcpi =
{
/** pszName */
"acpi",
/** pszDesc */
"ACPI related interfaces",
/** cbInstance */
sizeof(PSPDEVACPI),
/** pfnInit */
pspDevAcpiInit,
/** pfnDestruct */
pspDevAcpiDestruct,
/** pfnReset */
NULL
};