-
Notifications
You must be signed in to change notification settings - Fork 11
/
psp-dev-mp2.c
119 lines (92 loc) · 3.15 KB
/
psp-dev-mp2.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
118
/** @file
* PSP Emulator - MP2 device (ARM core configured as I2C controller) attached to SMN.
*/
/*
* 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 <string.h>
#include <common/cdefs.h>
#include <psp-devs.h>
/**
* MP2 device instance data.
*/
typedef struct PSPDEVMP2
{
/** SMN region handle for the firmware region. */
PSPIOMREGIONHANDLE hSmnFw;
/** SMN region handle for the SRAM1 region. */
PSPIOMREGIONHANDLE hSmnSram1;
/** The memory the firmware is loaded to residing at SMN address 0x3f00000. */
uint8_t abFw[192 * _1K];
/** An SRAM1 region used for some sort of config residing at SMN address 0x3f50000. */
uint8_t abSram1[1376];
} PSPDEVMP2;
/** Pointer to the device instance data. */
typedef PSPDEVMP2 *PPSPDEVMP2;
static void pspDevMp2FwRead(SMNADDR offSmn, size_t cbRead, void *pvDst, void *pvUser)
{
PPSPDEVMP2 pThis = (PPSPDEVMP2)pvUser;
memcpy(pvDst, &pThis->abFw[offSmn], cbRead);
}
static void pspDevMp2FwWrite(SMNADDR offSmn, size_t cbWrite, const void *pvVal, void *pvUser)
{
PPSPDEVMP2 pThis = (PPSPDEVMP2)pvUser;
memcpy(&pThis->abFw[offSmn], pvVal, cbWrite);
}
static void pspDevMp2Sram1Read(SMNADDR offSmn, size_t cbRead, void *pvDst, void *pvUser)
{
PPSPDEVMP2 pThis = (PPSPDEVMP2)pvUser;
memcpy(pvDst, &pThis->abSram1[offSmn], cbRead);
}
static void pspDevMp2Sram1Write(SMNADDR offSmn, size_t cbWrite, const void *pvVal, void *pvUser)
{
PPSPDEVMP2 pThis = (PPSPDEVMP2)pvUser;
memcpy(&pThis->abSram1[offSmn], pvVal, cbWrite);
}
static int pspDevMp2Init(PPSPDEV pDev)
{
PPSPDEVMP2 pThis = (PPSPDEVMP2)&pDev->abInstance[0];
int rc = PSPEmuIoMgrSmnRegister(pDev->hIoMgr, 0x03f00000, sizeof(pThis->abFw),
pspDevMp2FwRead, pspDevMp2FwWrite, pThis,
"MP2 SRAM0", &pThis->hSmnFw);
if (!rc)
rc = PSPEmuIoMgrSmnRegister(pDev->hIoMgr, 0x03f50000, sizeof(pThis->abSram1),
pspDevMp2Sram1Read, pspDevMp2Sram1Write, pThis,
"MP2 SRAM1", &pThis->hSmnSram1);
return rc;
}
static void pspDevMp2Destruct(PPSPDEV pDev)
{
/* Nothing to do so far. */
}
/**
* Device registration structure.
*/
const PSPDEVREG g_DevRegMp2 =
{
/** pszName */
"mp2",
/** pszDesc */
"MP2 device",
/** cbInstance */
sizeof(PSPDEVMP2),
/** pfnInit */
pspDevMp2Init,
/** pfnDestruct */
pspDevMp2Destruct,
/** pfnReset */
NULL
};