Compare commits
277 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bd3ba7b3d | ||
|
|
bc06d65b72 | ||
|
|
7045332ef2 | ||
|
|
35bc76074c | ||
|
|
cdb725dc86 | ||
|
|
215ccf9001 | ||
|
|
ec21e47b53 | ||
|
|
17e27ad6e9 | ||
|
|
7489a861f6 | ||
|
|
ef65b4dea9 | ||
|
|
0829cc8545 | ||
|
|
5fb0899bb8 | ||
|
|
c17d5a3999 | ||
|
|
42045c5c88 | ||
|
|
6e6f7b4f9f | ||
|
|
0496839500 | ||
|
|
87911b8b9e | ||
|
|
d3c441f8ca | ||
|
|
af6b347762 | ||
|
|
96b6459282 | ||
|
|
371577954b | ||
|
|
6bdb79fc15 | ||
|
|
e625e4251a | ||
|
|
5d7a77074b | ||
|
|
3b907d3ca0 | ||
|
|
a697cac43c | ||
|
|
3d5147a6e2 | ||
|
|
f46d0a714b | ||
|
|
3896c89a5c | ||
|
|
dd645bb352 | ||
|
|
9afd3d44bd | ||
|
|
5db6ac9f25 | ||
|
|
95930746d2 | ||
|
|
81e6fb9699 | ||
|
|
8b9fbdf13d | ||
|
|
901ab93e58 | ||
|
|
eb75fb2274 | ||
|
|
dab17f527e | ||
|
|
aabff0e948 | ||
|
|
610bf9ad82 | ||
|
|
1a42ad1a67 | ||
|
|
71f31e8f6a | ||
|
|
d6bf10d113 | ||
|
|
decd02b564 | ||
|
|
3b681f8c90 | ||
|
|
95e68bd27e | ||
|
|
dfd5af7e80 | ||
|
|
0afef60198 | ||
|
|
714eebb889 | ||
|
|
a5f58bfb3a | ||
|
|
c29d6244a4 | ||
|
|
130f9101a2 | ||
|
|
308f39694c | ||
|
|
9e916b5d0f | ||
|
|
c2610472ce | ||
|
|
2dbd436307 | ||
|
|
d525991beb | ||
|
|
b3ff426bfe | ||
|
|
958ca0530d | ||
|
|
981874a450 | ||
|
|
4502dc6fdb | ||
|
|
cc78b6193a | ||
|
|
327d64f22d | ||
|
|
c36052d477 | ||
|
|
bc9c30de56 | ||
|
|
e1c3a7d018 | ||
|
|
179aee88af | ||
|
|
df4a59c269 | ||
|
|
4d389cda63 | ||
|
|
ae56a85811 | ||
|
|
3e75bd5b95 | ||
|
|
2454afd58f | ||
|
|
7244093f21 | ||
|
|
52894e4c93 | ||
|
|
4e0b54c1a8 | ||
|
|
b5876ede0e | ||
|
|
9558fd67bb | ||
|
|
59b62a835b | ||
|
|
ad6847ec59 | ||
|
|
061c255978 | ||
|
|
bb44d0907d | ||
|
|
2215b17a54 | ||
|
|
cc52eab3f6 | ||
|
|
155a4ce50a | ||
|
|
17739377bd | ||
|
|
782fae1624 | ||
|
|
59ca1f18d6 | ||
|
|
c6cda6eb30 | ||
|
|
9f3c5d8de6 | ||
|
|
e4c9ac6ee3 | ||
|
|
5d6500523b | ||
|
|
b111ccabb5 | ||
|
|
b90a67aa43 | ||
|
|
9ed72839f4 | ||
|
|
b8f50da45f | ||
|
|
1e4dada672 | ||
|
|
a943d14807 | ||
|
|
2cf437ff34 | ||
|
|
7cbccbbb5b | ||
|
|
f79af5b6f7 | ||
|
|
05af1d04ff | ||
|
|
2753646f06 | ||
|
|
2b3889c897 | ||
|
|
e01e346dea | ||
|
|
7735037ad9 | ||
|
|
b2bcd5fc3a | ||
|
|
a40ea357db | ||
|
|
7434c22772 | ||
|
|
f0eb25b88c | ||
|
|
7ec9827db5 | ||
|
|
eeca31c92e | ||
|
|
2cd736035c | ||
|
|
bc99616e43 | ||
|
|
732f27fcf6 | ||
|
|
54e8465e47 | ||
|
|
7ceb02c001 | ||
|
|
2450a348f1 | ||
|
|
7bd469939e | ||
|
|
89180359c0 | ||
|
|
4259ace5c4 | ||
|
|
d7e5c38a62 | ||
|
|
b601105998 | ||
|
|
ca07d0716f | ||
|
|
eb16df3450 | ||
|
|
b44684760d | ||
|
|
be3fc1bb84 | ||
|
|
e781e67b43 | ||
|
|
40800ffe4b | ||
|
|
4e704e59e8 | ||
|
|
06e5d5e3d1 | ||
|
|
06010d7cd6 | ||
|
|
2549cd9a71 | ||
|
|
e89e35436e | ||
|
|
f5029ee3e9 | ||
|
|
08a84e0a8b | ||
|
|
36c819de04 | ||
|
|
f62987af4b | ||
|
|
8d9b44d6ec | ||
|
|
a5babb722d | ||
|
|
bde65f094d | ||
|
|
3fa2cfabd3 | ||
|
|
b8f4d02e4f | ||
|
|
436b7feb8e | ||
|
|
8bab4dd6ee | ||
|
|
99dfea631b | ||
|
|
16501bd6a8 | ||
|
|
88201b7308 | ||
|
|
2fb680b06a | ||
|
|
fb8116107b | ||
|
|
e6b83a1db5 | ||
|
|
607a19048b | ||
|
|
0db831e0c3 | ||
|
|
863cca507d | ||
|
|
3916a252d4 | ||
|
|
1594b76851 | ||
|
|
9e14fc5241 | ||
|
|
54fd3e2fd1 | ||
|
|
2348f8dba2 | ||
|
|
f0a3dc48f9 | ||
|
|
58ad43213b | ||
|
|
4a505b7238 | ||
|
|
7c6c0e68d2 | ||
|
|
1c5b22710d | ||
|
|
75755528b1 | ||
|
|
4dadcaf574 | ||
|
|
5a88d53443 | ||
|
|
2bd5faa7d9 | ||
|
|
29cb868f50 | ||
|
|
4eb222f5aa | ||
|
|
eca6ab2297 | ||
|
|
749e5147df | ||
|
|
55e84d0051 | ||
|
|
8cd9727429 | ||
|
|
660e839bed | ||
|
|
afb16d2045 | ||
|
|
f4b025f33c | ||
|
|
e03c3b7be0 | ||
|
|
5a2ba5f785 | ||
|
|
e1463dca05 | ||
|
|
82972127a1 | ||
|
|
272eaed351 | ||
|
|
989e67daac | ||
|
|
dcec618ae9 | ||
|
|
bc12388b6d | ||
|
|
6625488180 | ||
|
|
1209337af6 | ||
|
|
0f608b1702 | ||
|
|
cf547d517b | ||
|
|
8c75c68dca | ||
|
|
ab020c0a90 | ||
|
|
44dc402b54 | ||
|
|
a1d047f48d | ||
|
|
cbed5e11ab | ||
|
|
1ad3f6c441 | ||
|
|
820a26ba2a | ||
|
|
f0952119b6 | ||
|
|
ca5ddbd779 | ||
|
|
be49a27118 | ||
|
|
190353dc11 | ||
|
|
4a1772df77 | ||
|
|
460d1b8471 | ||
|
|
2493c798bc | ||
|
|
7525baf567 | ||
|
|
3f9a5f61fb | ||
|
|
b9156d6861 | ||
|
|
5d59be7b77 | ||
|
|
dd4c5a8732 | ||
|
|
837543fb0f | ||
|
|
03ede8f171 | ||
|
|
078d8164fc | ||
|
|
ceff8a083e | ||
|
|
b32efcc177 | ||
|
|
d57fccc463 | ||
|
|
26cf028f2d | ||
|
|
6e80c9a75f | ||
|
|
42bdfb55f2 | ||
|
|
e0967a9fd6 | ||
|
|
2406ce4f86 | ||
|
|
3b40a4a3e5 | ||
|
|
38c408dde6 | ||
|
|
5e62eb3f5d | ||
|
|
b4b5599ed2 | ||
|
|
b4917f3e1a | ||
|
|
e6b4cb6612 | ||
|
|
b1ca62ce61 | ||
|
|
243f614887 | ||
|
|
a8577378f6 | ||
|
|
564703b7c5 | ||
|
|
5ef56bed25 | ||
|
|
afddb963a9 | ||
|
|
aa72176196 | ||
|
|
7af0721847 | ||
|
|
2a6320e646 | ||
|
|
fc212bb419 | ||
|
|
14e0053335 | ||
|
|
8f28daceef | ||
|
|
f1044673d0 | ||
|
|
61a0ebffee | ||
|
|
8de8f4013e | ||
|
|
dd447553d4 | ||
|
|
11c456e00c | ||
|
|
5efb4bdd6b | ||
|
|
e331f1249b | ||
|
|
786467d7ea | ||
|
|
496e77301b | ||
|
|
d657f1d156 | ||
|
|
7ab5c2f540 | ||
|
|
71900721cf | ||
|
|
0bc9547701 | ||
|
|
96ac254022 | ||
|
|
92f378a80f | ||
|
|
589af01ad8 | ||
|
|
e7f14b88e5 | ||
|
|
35a269e4a7 | ||
|
|
ff95ca527f | ||
|
|
550e4e5204 | ||
|
|
a088c4795a | ||
|
|
e8a264fa11 | ||
|
|
de681c20a0 | ||
|
|
22aef264ab | ||
|
|
309717c468 | ||
|
|
9b91d7487c | ||
|
|
c0b458243c | ||
|
|
7d9c60cdfe | ||
|
|
12c9effec2 | ||
|
|
6eeab63075 | ||
|
|
2d81c5e127 | ||
|
|
b1739cea74 | ||
|
|
aa607ab1a7 | ||
|
|
d1242a17d4 | ||
|
|
80701c2891 | ||
|
|
cfd0d84ac8 | ||
|
|
c33aabdc84 | ||
|
|
c70fd82e60 | ||
|
|
574c248d68 | ||
|
|
0ae65c8740 | ||
|
|
39fbe25afc |
22
.github/workflows/build.yml
vendored
22
.github/workflows/build.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
# Minimal devkitA64 container, apparently dkp-toolchain isn't needed?
|
||||
# Minimal devkitA64 container
|
||||
container:
|
||||
image: devkitpro/devkita64:20251231
|
||||
|
||||
@@ -47,9 +47,12 @@ jobs:
|
||||
# -------------------------------------------------
|
||||
# Get short commit SHA
|
||||
# -------------------------------------------------
|
||||
- name: Set commit SHA
|
||||
- name: Set commit SHA & dist
|
||||
id: vars
|
||||
run: echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
|
||||
run: |
|
||||
echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
|
||||
echo $SHORT_SHA > dist/.commit
|
||||
echo $GITHUB_SHA >> dist/.commit
|
||||
|
||||
- name: Clone Atmosphere
|
||||
run: git clone --depth=1 --single-branch https://github.com/Atmosphere-NX/Atmosphere.git atmosphere -b $(cat ams_ver.txt)
|
||||
@@ -149,23 +152,12 @@ jobs:
|
||||
- name: ccache stats
|
||||
run: ccache --show-stats
|
||||
|
||||
|
||||
# -------------------------------------------------
|
||||
# Package dist folder as ZIP with commit SHA
|
||||
# -------------------------------------------------
|
||||
- name: Package dist
|
||||
# working-directory: horizon-oc
|
||||
run: |
|
||||
ZIP_NAME="horizon-oc-zeus-dist-${SHORT_SHA}.zip"
|
||||
zip -r "$ZIP_NAME" dist
|
||||
echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV
|
||||
|
||||
# -------------------------------------------------
|
||||
# Upload ZIP artifact
|
||||
# -------------------------------------------------
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: horizon-oc-zeus-dist-${{ env.SHORT_SHA }}
|
||||
name: horizon-oc-zeus-dist
|
||||
path: dist/
|
||||
compression-level: 3
|
||||
|
||||
19
.gitmodules
vendored
19
.gitmodules
vendored
@@ -1,9 +1,12 @@
|
||||
[submodule "Source/Horizon-OC-Monitor/lib/Atmosphere-libs"]
|
||||
path = Source/Horizon-OC-Monitor/lib/Atmosphere-libs
|
||||
url = https://github.com/Atmosphere-NX/Atmosphere-libs
|
||||
[submodule "Source/Horizon-OC-Monitor/lib/libultrahand"]
|
||||
path = Source/Horizon-OC-Monitor/lib/libultrahand
|
||||
url = https://github.com/ppkantorski/libultrahand
|
||||
[submodule "Source/sys-clk/overlay/lib/libultrahand"]
|
||||
path = Source/sys-clk/overlay/lib/libultrahand
|
||||
[submodule "Source/Horizon-OC-Monitor/lib/Atmosphere-libs"]
|
||||
path = Source/Horizon-OC-Monitor/lib/Atmosphere-libs
|
||||
url = https://github.com/Atmosphere-NX/Atmosphere-libs
|
||||
branch = master
|
||||
[submodule "Source/Horizon-OC-Monitor/lib/libultrahand"]
|
||||
path = Source/Horizon-OC-Monitor/lib/libultrahand
|
||||
url = https://github.com/ppkantorski/libultrahand
|
||||
branch = main
|
||||
[submodule "Source/sys-clk/overlay/lib/libultrahand"]
|
||||
path = Source/sys-clk/overlay/lib/libultrahand
|
||||
url = https://github.com/ppkantorski/libultrahand
|
||||
branch = main
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -6,6 +6,8 @@
|
||||
|
||||
- Although "sys-clk" uses permissive license, all modifications towards it in this repo ("hoc-clk") are licensed under GPL v2.
|
||||
|
||||
- Status-Monitor is licensed under the GPLv2
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
|
||||
29
README.md
29
README.md
@@ -1,7 +1,7 @@
|
||||
|
||||
<div align="center">
|
||||
|
||||
<img src="assets/logo.png" alt="logo" width="350"/>
|
||||
<img src="assets/logo.png" alt="logo" width="768"/>
|
||||
|
||||
---
|
||||
|
||||
@@ -36,15 +36,13 @@ It enables advanced CPU, GPU, and RAM tuning with user-friendly configuration to
|
||||
|
||||
* **CPU:** Up to 1963MHz (Mariko) / 1785MHz (Erista)
|
||||
* **GPU:** Up to 1075MHz (Mariko) / 921MHz (Erista)
|
||||
* **RAM:** Up to 1866MHz (Mariko) / 1600MHz (Erista)
|
||||
* **RAM:** Up to 1866/2133MHz (Mariko) / 1600MHz (Erista)
|
||||
* Over/undervolting support
|
||||
* Built-in configurator
|
||||
* Compatible with most homebrew
|
||||
|
||||
> *Higher (potentially dangerous) frequencies are unlockable via configuration.*
|
||||
> *Erista and Mariko units can usually push a bit further fully safely with a bit of undervolting, however this may not work on all units.*
|
||||
> *The exact maximum overclock possible varies per console, although most consoles should be able to do this safely.*
|
||||
> *You may refer to the Clock Table to see clocks in more detail*
|
||||
> It is recommended to read the [guide](https://rentry.co/howtoget60fps) before proceeding, as this can help you get a *significant* performance boost over the default settings, often times with less power draw and heat output
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
@@ -58,7 +56,6 @@ It enables advanced CPU, GPU, and RAM tuning with user-friendly configuration to
|
||||
|
||||
```
|
||||
kip1=atmosphere/kips/hoc.kip
|
||||
secmon=exosphere.bin
|
||||
```
|
||||
|
||||
*(No changes needed if using fusee.)*
|
||||
@@ -91,15 +88,15 @@ Refer to COMPILATION.md
|
||||
* 1866 → mariko safe max (3733 Modules), JEDEC.
|
||||
* 1600 → official docked, boost mode, erista safe max, JEDEC.
|
||||
* 1331 → official handheld, JEDEC.
|
||||
* 1065
|
||||
* 1065
|
||||
* 800
|
||||
* 665
|
||||
|
||||
### CPU clocks
|
||||
* 2601 → mariko absolute max, very dangerous
|
||||
* 2499
|
||||
* 2397
|
||||
* 2295 → mariko safe max with UV (low speedo)
|
||||
* 2397 → mariko safe max with UV (low speedo)
|
||||
* 2295
|
||||
* 2193
|
||||
* 2091
|
||||
* 1963 → mariko no UV max clock
|
||||
@@ -116,6 +113,9 @@ Refer to COMPILATION.md
|
||||
* 816
|
||||
* 714
|
||||
* 612 → sleep mode
|
||||
|
||||
**Notes:**
|
||||
1. On Erista, CPU in handheld is capped to 1581MHz
|
||||
|
||||
### GPU clocks
|
||||
* 1536 → absolute max clock on mariko. very dangerous
|
||||
@@ -142,8 +142,10 @@ Refer to COMPILATION.md
|
||||
* 76 → boost mode
|
||||
|
||||
**Notes:**
|
||||
1. GPU overclock is capped at 460MHz in handheld and capped at 768MHz if charging, unless you're using the official charger.
|
||||
2. Clocks higher than 768MHz need the official charger is plugged in.
|
||||
1. GPU overclock is capped at 460MHz on erista in handheld
|
||||
2. On Mariko, cap with No uv is 614MHz, with SLT it is 691MHz and with HiOPT it's 768MHz
|
||||
3. Clocks higher than 768MHz on erista need the official charger is plugged in.
|
||||
4. On Mariko, cap with No uv is 844MHz, with SLT it is 921MHz and with HiOPT it's 998MHz
|
||||
|
||||
---
|
||||
|
||||
@@ -153,6 +155,7 @@ Refer to COMPILATION.md
|
||||
* **Souldbminer** – hoc-clk and loader development
|
||||
* **Lightos** – loader patches development
|
||||
* **SciresM** - Atmosphere CFW
|
||||
* **CTCaer** - L4T, Hekate, perfect ram timings
|
||||
* **KazushiMe** – Switch OC Suite
|
||||
* **hanai3bi (meha)** – Switch OC Suite, EOS, sys-clk-eos
|
||||
* **NaGaa95** – L4T-OC-kernel
|
||||
@@ -161,5 +164,5 @@ Refer to COMPILATION.md
|
||||
* **b0rd2death** – Ultrahand sys-clk & Status Monitor fork
|
||||
* **MasaGratoR and ZachyCatGames** - General help
|
||||
* **MasaGratoR** - Status Monitor & Display Refresh Rate Driver
|
||||
* **Dom, Samybigio, Arcdelta, Miki, Happy, Flopsider, Winnerboi77, Blaise, Alvise, TDRR, agjeococh and Xenshen** - Testing
|
||||
* **Dom, Samybigio, Arcdelta, Miki, Happy, Flopsider, Winnerboi77, Blaise, Alvise, TDRR, agjeococh, frost, letum00 and Xenshen** - Testing
|
||||
* **Samybigio2011** - Italian translations
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| 0.x | :white_check_mark: |
|
||||
| 1.x | :white_check_mark: |
|
||||
| 0.x | Not supported |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Contact me on discord (soul_9017) or email me (souldbminer@gmail.com)
|
||||
Contact Souldbminer or Lightos_ on discord (souldbminer, lightos_)
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define __ACCESS_TABLE_NAME__ SocthermAccessTable
|
||||
#define __ACCESS_TABLE_ADDRESS__ MemoryRegionPhysicalDeviceSoctherm.GetAddress()
|
||||
#define __ACCESS_TABLE_INC__ "secmon_soctherm_access_table_data.inc"
|
||||
#define __ACCESS_TABLE_NAME__ EmcAccessTable1
|
||||
#define __ACCESS_TABLE_ADDRESS__ MemoryRegionPhysicalDeviceExternalMemoryController1.GetAddress()
|
||||
#define __ACCESS_TABLE_INC__ "secmon_emc_access_table_data.inc"
|
||||
|
||||
#include "secmon_define_access_table.inc"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*/
|
||||
|
||||
#define __ACCESS_TABLE_NAME__ EmcAccessTable2
|
||||
#define __ACCESS_TABLE_ADDRESS__ MemoryRegionPhysicalDeviceExternalMemoryController2.GetAddress()
|
||||
#define __ACCESS_TABLE_INC__ "secmon_emc_access_table_data.inc"
|
||||
|
||||
#include "secmon_define_access_table.inc"
|
||||
|
||||
#undef __ACCESS_TABLE_INC__
|
||||
#undef __ACCESS_TABLE_ADDRESS__
|
||||
#undef __ACCESS_TABLE_NAME__
|
||||
@@ -965,3 +965,76 @@ SetRegisterAllowed(0xECC);
|
||||
SetRegisterAllowed(0xED0);
|
||||
SetRegisterAllowed(0xED4);
|
||||
SetRegisterAllowed(0xED8);
|
||||
SetRegisterAllowed(0xEDC);
|
||||
SetRegisterAllowed(0xEE0);
|
||||
SetRegisterAllowed(0xEE4);
|
||||
SetRegisterAllowed(0xEE8);
|
||||
SetRegisterAllowed(0xEEC);
|
||||
SetRegisterAllowed(0xEF0);
|
||||
SetRegisterAllowed(0xEF4);
|
||||
SetRegisterAllowed(0xEF8);
|
||||
SetRegisterAllowed(0xEFC);
|
||||
SetRegisterAllowed(0xF00);
|
||||
SetRegisterAllowed(0xF04);
|
||||
SetRegisterAllowed(0xF08);
|
||||
SetRegisterAllowed(0xF0C);
|
||||
SetRegisterAllowed(0xF10);
|
||||
SetRegisterAllowed(0xF14);
|
||||
SetRegisterAllowed(0xF18);
|
||||
SetRegisterAllowed(0xF1C);
|
||||
SetRegisterAllowed(0xF20);
|
||||
SetRegisterAllowed(0xF24);
|
||||
SetRegisterAllowed(0xF28);
|
||||
SetRegisterAllowed(0xF2C);
|
||||
SetRegisterAllowed(0xF30);
|
||||
SetRegisterAllowed(0xF34);
|
||||
SetRegisterAllowed(0xF38);
|
||||
SetRegisterAllowed(0xF3C);
|
||||
SetRegisterAllowed(0xF40);
|
||||
SetRegisterAllowed(0xF44);
|
||||
SetRegisterAllowed(0xF48);
|
||||
SetRegisterAllowed(0xF4C);
|
||||
SetRegisterAllowed(0xF50);
|
||||
SetRegisterAllowed(0xF54);
|
||||
SetRegisterAllowed(0xF58);
|
||||
SetRegisterAllowed(0xF5C);
|
||||
SetRegisterAllowed(0xF60);
|
||||
SetRegisterAllowed(0xF64);
|
||||
SetRegisterAllowed(0xF68);
|
||||
SetRegisterAllowed(0xF6C);
|
||||
SetRegisterAllowed(0xF70);
|
||||
SetRegisterAllowed(0xF74);
|
||||
SetRegisterAllowed(0xF78);
|
||||
SetRegisterAllowed(0xF7C);
|
||||
SetRegisterAllowed(0xF80);
|
||||
SetRegisterAllowed(0xF84);
|
||||
SetRegisterAllowed(0xF88);
|
||||
SetRegisterAllowed(0xF8C);
|
||||
SetRegisterAllowed(0xF90);
|
||||
SetRegisterAllowed(0xF94);
|
||||
SetRegisterAllowed(0xF98);
|
||||
SetRegisterAllowed(0xF9C);
|
||||
SetRegisterAllowed(0xFA0);
|
||||
SetRegisterAllowed(0xFA4);
|
||||
SetRegisterAllowed(0xFA8);
|
||||
SetRegisterAllowed(0xFAC);
|
||||
SetRegisterAllowed(0xFB0);
|
||||
SetRegisterAllowed(0xFB4);
|
||||
SetRegisterAllowed(0xFB8);
|
||||
SetRegisterAllowed(0xFBC);
|
||||
SetRegisterAllowed(0xFC0);
|
||||
SetRegisterAllowed(0xFC4);
|
||||
SetRegisterAllowed(0xFC8);
|
||||
SetRegisterAllowed(0xFCC);
|
||||
SetRegisterAllowed(0xFD0);
|
||||
SetRegisterAllowed(0xFD4);
|
||||
SetRegisterAllowed(0xFD8);
|
||||
SetRegisterAllowed(0xFDC);
|
||||
SetRegisterAllowed(0xFE0);
|
||||
SetRegisterAllowed(0xFE4);
|
||||
SetRegisterAllowed(0xFE8);
|
||||
SetRegisterAllowed(0xFEC);
|
||||
SetRegisterAllowed(0xFF0);
|
||||
SetRegisterAllowed(0xFF4);
|
||||
SetRegisterAllowed(0xFF8);
|
||||
SetRegisterAllowed(0xFFC);
|
||||
|
||||
@@ -129,33 +129,32 @@ namespace ams::secmon {
|
||||
constexpr inline const MemoryRegion MemoryRegionVirtualDeviceEmpty = MemoryRegion(MemoryRegionVirtualDevice.GetStartAddress(), 0);
|
||||
|
||||
#define AMS_SECMON_FOREACH_DEVICE_REGION(HANDLER, ...) \
|
||||
HANDLER(GicDistributor, Empty, UINT64_C(0x50041000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(GicCpuInterface, GicDistributor, UINT64_C(0x50042000), UINT64_C(0x2000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Uart, GicCpuInterface, UINT64_C(0x70006000), UINT64_C(0x1000), false, ## __VA_ARGS__) \
|
||||
HANDLER(ClkRst, Uart, UINT64_C(0x60006000), UINT64_C(0x1000), false, ## __VA_ARGS__) \
|
||||
HANDLER(RtcPmc, ClkRst, UINT64_C(0x7000E000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Timer, RtcPmc, UINT64_C(0x60005000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(System, Timer, UINT64_C(0x6000C000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(SecurityEngine, System, UINT64_C(0x70012000), UINT64_C(0x2000), true, ## __VA_ARGS__) \
|
||||
HANDLER(SecurityEngine2, SecurityEngine, UINT64_C(0x70412000), UINT64_C(0x2000), true, ## __VA_ARGS__) \
|
||||
HANDLER(SysCtr0, SecurityEngine2, UINT64_C(0x700F0000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(MemoryController, SysCtr0, UINT64_C(0x70019000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(ExternalMemoryController, MemoryController, UINT64_C(0x7001b000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(FuseKFuse, ExternalMemoryController, UINT64_C(0x7000F000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(ApbMisc, FuseKFuse, UINT64_C(0x70000000), UINT64_C(0x4000), true, ## __VA_ARGS__) \
|
||||
HANDLER(FlowController, ApbMisc, UINT64_C(0x60007000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(BootloaderParams, FlowController, UINT64_C(0x40000000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(I2c5, BootloaderParams, UINT64_C(0x7000D000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Gpio, I2c5, UINT64_C(0x6000D000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(I2c1, Gpio, UINT64_C(0x7000C000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(ExceptionVectors, I2c1, UINT64_C(0x6000F000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(MemoryController0, ExceptionVectors, UINT64_C(0x7001C000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(MemoryController1, MemoryController0, UINT64_C(0x7001D000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Sdmmc, MemoryController1, UINT64_C(0x700B0000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Disp1, Sdmmc, UINT64_C(0x54200000), UINT64_C(0x3000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Dsi, Disp1, UINT64_C(0x54300000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(MipiCal, Dsi, UINT64_C(0x700E3000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Soctherm, MipiCal, UINT64_C(0x700E2000), UINT64_C(0x1000), true, ## __VA_ARGS__)
|
||||
HANDLER(GicDistributor, Empty, UINT64_C(0x50041000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(GicCpuInterface, GicDistributor, UINT64_C(0x50042000), UINT64_C(0x2000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Uart, GicCpuInterface, UINT64_C(0x70006000), UINT64_C(0x1000), false, ## __VA_ARGS__) \
|
||||
HANDLER(ClkRst, Uart, UINT64_C(0x60006000), UINT64_C(0x1000), false, ## __VA_ARGS__) \
|
||||
HANDLER(RtcPmc, ClkRst, UINT64_C(0x7000E000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Timer, RtcPmc, UINT64_C(0x60005000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(System, Timer, UINT64_C(0x6000C000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(SecurityEngine, System, UINT64_C(0x70012000), UINT64_C(0x2000), true, ## __VA_ARGS__) \
|
||||
HANDLER(SecurityEngine2, SecurityEngine, UINT64_C(0x70412000), UINT64_C(0x2000), true, ## __VA_ARGS__) \
|
||||
HANDLER(SysCtr0, SecurityEngine2, UINT64_C(0x700F0000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(MemoryController, SysCtr0, UINT64_C(0x70019000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(ExternalMemoryController, MemoryController, UINT64_C(0x7001b000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(FuseKFuse, ExternalMemoryController, UINT64_C(0x7000F000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(ApbMisc, FuseKFuse, UINT64_C(0x70000000), UINT64_C(0x4000), true, ## __VA_ARGS__) \
|
||||
HANDLER(FlowController, ApbMisc, UINT64_C(0x60007000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(BootloaderParams, FlowController, UINT64_C(0x40000000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(I2c5, BootloaderParams, UINT64_C(0x7000D000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Gpio, I2c5, UINT64_C(0x6000D000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(I2c1, Gpio, UINT64_C(0x7000C000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(ExceptionVectors, I2c1, UINT64_C(0x6000F000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(MemoryController0, ExceptionVectors, UINT64_C(0x7001C000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(MemoryController1, MemoryController0, UINT64_C(0x7001D000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Sdmmc, MemoryController1, UINT64_C(0x700B0000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Disp1, Sdmmc, UINT64_C(0x54200000), UINT64_C(0x3000), true, ## __VA_ARGS__) \
|
||||
HANDLER(Dsi, Disp1, UINT64_C(0x54300000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
HANDLER(MipiCal, Dsi, UINT64_C(0x700E3000), UINT64_C(0x1000), true, ## __VA_ARGS__) \
|
||||
|
||||
#define DEFINE_DEVICE_REGION(_NAME_, _PREV_, _ADDRESS_, _SIZE_, _SECURE_) \
|
||||
constexpr inline const MemoryRegion MemoryRegionVirtualDevice##_NAME_ = MemoryRegion(MemoryRegionVirtualDevice##_PREV_.GetEndAddress() + 0x1000, _SIZE_); \
|
||||
|
||||
268
Source/Atmosphere-Patches/secmon_smc_handler.cpp
Normal file
268
Source/Atmosphere-Patches/secmon_smc_handler.cpp
Normal file
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 <exosphere.hpp>
|
||||
#include "../secmon_error.hpp"
|
||||
#include "../secmon_misc.hpp"
|
||||
#include "secmon_smc_common.hpp"
|
||||
#include "secmon_smc_handler.hpp"
|
||||
#include "secmon_smc_aes.hpp"
|
||||
#include "secmon_smc_carveout.hpp"
|
||||
#include "secmon_smc_device_unique_data.hpp"
|
||||
#include "secmon_smc_error.hpp"
|
||||
#include "secmon_smc_info.hpp"
|
||||
#include "secmon_smc_memory_access.hpp"
|
||||
#include "secmon_smc_power_management.hpp"
|
||||
#include "secmon_smc_random.hpp"
|
||||
#include "secmon_smc_register_access.hpp"
|
||||
#include "secmon_smc_result.hpp"
|
||||
#include "secmon_smc_rsa.hpp"
|
||||
|
||||
namespace ams::secmon::smc {
|
||||
|
||||
namespace {
|
||||
|
||||
struct HandlerInfo {
|
||||
u32 function_id;
|
||||
u32 restriction_mask;
|
||||
SmcHandler handler;
|
||||
};
|
||||
|
||||
struct HandlerTable {
|
||||
const HandlerInfo *entries;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
enum HandlerType : int {
|
||||
HandlerType_User = 0,
|
||||
HandlerType_Kern = 1,
|
||||
HandlerType_Count = 2,
|
||||
};
|
||||
|
||||
enum Restriction {
|
||||
Restriction_None = (0 << 0),
|
||||
Restriction_Normal = (1 << 0),
|
||||
Restriction_DeviceUniqueDataNotAllowed = (1 << 1),
|
||||
Restriction_SafeModeNotAllowed = (1 << 2),
|
||||
};
|
||||
|
||||
enum SmcCallRange {
|
||||
SmcCallRange_ArmArch = 0,
|
||||
SmcCallRange_Cpu = 1,
|
||||
SmcCallRange_Sip = 2,
|
||||
SmcCallRange_Oem = 3,
|
||||
SmcCallRange_Standard = 4,
|
||||
|
||||
SmcCallRange_TrustedApp = 0x30,
|
||||
};
|
||||
|
||||
enum SmcArgumentType {
|
||||
ArgumentType_Integer = 0,
|
||||
ArgumentType_Pointer = 1,
|
||||
};
|
||||
|
||||
enum SmcConvention {
|
||||
Convention_Smc32 = 0,
|
||||
Convention_Smc64 = 1,
|
||||
};
|
||||
|
||||
enum SmcCallType {
|
||||
SmcCallType_YieldingCall = 0,
|
||||
SmcCallType_FastCall = 1,
|
||||
};
|
||||
|
||||
struct SmcFunctionId {
|
||||
using FunctionId = util::BitPack64::Field< 0, 8, u32>;
|
||||
using ArgumentType0 = util::BitPack64::Field< 8, 1, SmcArgumentType>;
|
||||
using ArgumentType1 = util::BitPack64::Field< 9, 1, SmcArgumentType>;
|
||||
using ArgumentType2 = util::BitPack64::Field<10, 1, SmcArgumentType>;
|
||||
using ArgumentType3 = util::BitPack64::Field<11, 1, SmcArgumentType>;
|
||||
using ArgumentType4 = util::BitPack64::Field<12, 1, SmcArgumentType>;
|
||||
using ArgumentType5 = util::BitPack64::Field<13, 1, SmcArgumentType>;
|
||||
using ArgumentType6 = util::BitPack64::Field<14, 1, SmcArgumentType>;
|
||||
using ArgumentType7 = util::BitPack64::Field<15, 1, SmcArgumentType>;
|
||||
using Reserved = util::BitPack64::Field<16, 8, u32>;
|
||||
using CallRange = util::BitPack64::Field<24, 6, SmcCallRange>;
|
||||
using Convention = util::BitPack64::Field<30, 1, SmcConvention>;
|
||||
using CallType = util::BitPack64::Field<31, 1, SmcCallType>;
|
||||
using Reserved2 = util::BitPack64::Field<32, 32, u32>;
|
||||
};
|
||||
|
||||
constinit HandlerInfo g_user_handlers[] = {
|
||||
{ 0x00000000, Restriction_SafeModeNotAllowed, nullptr },
|
||||
{ 0xC3000401, Restriction_SafeModeNotAllowed, SmcSetConfig },
|
||||
{ 0xC3000002, Restriction_Normal, SmcGetConfigUser },
|
||||
{ 0xC3000003, Restriction_Normal, SmcGetResult },
|
||||
{ 0xC3000404, Restriction_Normal, SmcGetResultData },
|
||||
{ 0xC3000E05, Restriction_SafeModeNotAllowed, SmcModularExponentiate },
|
||||
{ 0xC3000006, Restriction_Normal, SmcGenerateRandomBytes },
|
||||
{ 0xC3000007, Restriction_Normal, SmcGenerateAesKek },
|
||||
{ 0xC3000008, Restriction_Normal, SmcLoadAesKey },
|
||||
{ 0xC3000009, Restriction_Normal, SmcComputeAes },
|
||||
{ 0xC300000A, Restriction_Normal, SmcGenerateSpecificAesKey },
|
||||
{ 0xC300040B, Restriction_Normal, SmcComputeCmac },
|
||||
{ 0xC300D60C, Restriction_Normal, SmcReencryptDeviceUniqueData },
|
||||
{ 0xC300100D, Restriction_DeviceUniqueDataNotAllowed, SmcDecryptDeviceUniqueData },
|
||||
{ 0xC300000E, Restriction_SafeModeNotAllowed, nullptr },
|
||||
{ 0xC300060F, Restriction_DeviceUniqueDataNotAllowed, SmcModularExponentiateByStorageKey },
|
||||
{ 0xC3000610, Restriction_SafeModeNotAllowed, SmcPrepareEsDeviceUniqueKey },
|
||||
{ 0xC3000011, Restriction_SafeModeNotAllowed, SmcLoadPreparedAesKey },
|
||||
{ 0xC3000012, Restriction_SafeModeNotAllowed, SmcPrepareEsCommonTitleKey }
|
||||
};
|
||||
|
||||
/* Deprecated handlerss. */
|
||||
constexpr inline const HandlerInfo DecryptAndImportEsDeviceKeyHandlerInfo = {
|
||||
0xC300100C, Restriction_Normal, SmcDecryptAndImportEsDeviceKey
|
||||
};
|
||||
|
||||
constexpr inline const HandlerInfo DecryptAndImportLotusKeyHandlerInfo = {
|
||||
0xC300100E, Restriction_SafeModeNotAllowed, SmcDecryptAndImportLotusKey
|
||||
};
|
||||
|
||||
constinit HandlerInfo g_kern_handlers[] = {
|
||||
{ 0x00000000, Restriction_SafeModeNotAllowed, nullptr },
|
||||
{ 0xC4000001, Restriction_SafeModeNotAllowed, SmcSuspendCpu },
|
||||
{ 0x84000002, Restriction_SafeModeNotAllowed, SmcPowerOffCpu },
|
||||
{ 0xC4000003, Restriction_SafeModeNotAllowed, SmcPowerOnCpu },
|
||||
{ 0xC3000004, Restriction_Normal, SmcGetConfigKern },
|
||||
{ 0xC3000005, Restriction_Normal, SmcGenerateRandomBytesNonBlocking },
|
||||
{ 0xC3000006, Restriction_Normal, SmcShowError },
|
||||
{ 0xC3000007, Restriction_Normal, SmcSetKernelCarveoutRegion },
|
||||
{ 0xC3000008, Restriction_Normal, SmcReadWriteRegister },
|
||||
|
||||
/* NOTE: Atmosphere extension for mesosphere. This ID is subject to change at any time. */
|
||||
{ 0xC3000409, Restriction_Normal, SmcSetConfig },
|
||||
};
|
||||
|
||||
constinit HandlerInfo g_ams_handlers[] = {
|
||||
{ 0x00000000, Restriction_SafeModeNotAllowed, nullptr },
|
||||
{ 0xF0000201, Restriction_None, SmcIramCopy },
|
||||
{ 0xF0000002, Restriction_None, SmcReadWriteRegister },
|
||||
{ 0xF0000003, Restriction_None, SmcWriteAddress },
|
||||
{ 0xF0000404, Restriction_None, SmcGetEmummcConfig },
|
||||
{ 0xF0000005, Restriction_None, SmcShowError },
|
||||
};
|
||||
|
||||
constexpr const HandlerInfo GetSecureDataHandlerInfo = {
|
||||
0x67891234, Restriction_None, SmcGetSecureData
|
||||
};
|
||||
|
||||
constinit HandlerTable g_handler_tables[] = {
|
||||
{ g_user_handlers, util::size(g_user_handlers) },
|
||||
{ g_kern_handlers, util::size(g_kern_handlers) },
|
||||
};
|
||||
|
||||
constinit HandlerTable g_ams_handler_table = {
|
||||
g_ams_handlers, util::size(g_ams_handlers)
|
||||
};
|
||||
|
||||
NORETURN void InvalidSmcError(u64 id) {
|
||||
SetError(pkg1::ErrorInfo_UnknownSmc);
|
||||
AMS_ABORT("Invalid SMC: %lx", id);
|
||||
}
|
||||
|
||||
const HandlerTable &GetHandlerTable(HandlerType type, u64 id) {
|
||||
/* Ensure we have a valid handler type. */
|
||||
if (AMS_UNLIKELY(!(0 <= type && type < HandlerType_Count))) {
|
||||
InvalidSmcError(id);
|
||||
}
|
||||
|
||||
/* Provide support for legacy SmcGetSecureData. */
|
||||
if (id == GetSecureDataHandlerInfo.function_id) {
|
||||
return g_handler_tables[HandlerType_User];
|
||||
}
|
||||
|
||||
/* Check if we're a user SMC. */
|
||||
if (type == HandlerType_User) {
|
||||
/* Nintendo uses OEM SMCs. */
|
||||
/* We will assign Atmosphere extension SMCs the TrustedApplication range. */
|
||||
if (util::BitPack64{id}.Get<SmcFunctionId::CallRange>() == SmcCallRange_TrustedApp) {
|
||||
return g_ams_handler_table;
|
||||
}
|
||||
|
||||
/* If we're not performing an atmosphere extension smc, require that we're being invoked by spl on core 3. */
|
||||
if (AMS_UNLIKELY(hw::GetCurrentCoreId() != 3)) {
|
||||
InvalidSmcError(id);
|
||||
}
|
||||
}
|
||||
|
||||
return g_handler_tables[type];
|
||||
}
|
||||
|
||||
const HandlerInfo &GetHandlerInfo(const HandlerTable &table, u64 id) {
|
||||
/* Provide support for legacy SmcGetSecureData. */
|
||||
if (id == GetSecureDataHandlerInfo.function_id) {
|
||||
return GetSecureDataHandlerInfo;
|
||||
}
|
||||
|
||||
/* Get and check the index. */
|
||||
const auto index = util::BitPack64{id}.Get<SmcFunctionId::FunctionId>();
|
||||
if (AMS_UNLIKELY(index >= table.count)) {
|
||||
InvalidSmcError(id);
|
||||
}
|
||||
|
||||
/* Get and check the handler info. */
|
||||
const auto &handler_info = table.entries[index];
|
||||
|
||||
/* Check that the handler isn't null. */
|
||||
if (AMS_UNLIKELY(handler_info.handler == nullptr)) {
|
||||
InvalidSmcError(id);
|
||||
}
|
||||
|
||||
/* Check that the handler's id matches. */
|
||||
if (AMS_UNLIKELY(handler_info.function_id != id)) {
|
||||
InvalidSmcError(id);
|
||||
}
|
||||
|
||||
return handler_info;
|
||||
}
|
||||
|
||||
bool IsHandlerRestricted(const HandlerInfo &info) {
|
||||
return (info.restriction_mask & secmon::GetRestrictedSmcMask()) != 0;
|
||||
}
|
||||
|
||||
SmcResult InvokeSmcHandler(const HandlerInfo &info, SmcArguments &args) {
|
||||
/* Check if the smc is restricted. */
|
||||
if (GetTargetFirmware() >= TargetFirmware_8_0_0 && AMS_UNLIKELY(IsHandlerRestricted(info))) {
|
||||
return SmcResult::NotPermitted;
|
||||
}
|
||||
|
||||
/* Invoke the smc. */
|
||||
return info.handler(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ConfigureSmcHandlersForTargetFirmware() {
|
||||
const auto target_fw = GetTargetFirmware();
|
||||
|
||||
if (target_fw < TargetFirmware_5_0_0) {
|
||||
g_user_handlers[DecryptAndImportEsDeviceKeyHandlerInfo.function_id & 0xFF] = DecryptAndImportEsDeviceKeyHandlerInfo;
|
||||
g_user_handlers[DecryptAndImportLotusKeyHandlerInfo.function_id & 0xFF] = DecryptAndImportLotusKeyHandlerInfo;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleSmc(int type, SmcArguments &args) {
|
||||
/* Get the table. */
|
||||
const auto &table = GetHandlerTable(static_cast<HandlerType>(type), args.r[0]);
|
||||
|
||||
/* Get the handler info. */
|
||||
const auto &info = GetHandlerInfo(table, args.r[0]);
|
||||
|
||||
/* Set the invocation result. */
|
||||
args.r[0] = static_cast<u64>(InvokeSmcHandler(info, args));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -99,14 +99,16 @@ namespace ams::secmon::smc {
|
||||
#include "secmon_define_pmc_access_table.inc"
|
||||
#include "secmon_define_mc_access_table.inc"
|
||||
#include "secmon_define_emc_access_table.inc"
|
||||
#include "secmon_define_soctherm_access_table.inc"
|
||||
#include "secmon_define_emc1_access_table.inc"
|
||||
#include "secmon_define_emc2_access_table.inc"
|
||||
#include "secmon_define_mc01_access_table.inc"
|
||||
|
||||
constexpr const AccessTableEntry AccessTables[] = {
|
||||
{ PmcAccessTable::ReducedAccessTable.data(), MemoryRegionVirtualDevicePmc.GetAddress(), PmcAccessTable::Address, PmcAccessTable::Size, },
|
||||
{ McAccessTable::ReducedAccessTable.data(), MemoryRegionVirtualDeviceMemoryController.GetAddress(), McAccessTable::Address, McAccessTable::Size, },
|
||||
{ EmcAccessTable::ReducedAccessTable.data(), MemoryRegionVirtualDeviceExternalMemoryController.GetAddress(), EmcAccessTable::Address, EmcAccessTable::Size, },
|
||||
{ SocthermAccessTable::ReducedAccessTable.data(), MemoryRegionVirtualDeviceSoctherm.GetAddress(), SocthermAccessTable::Address, SocthermAccessTable::Size, },
|
||||
{ EmcAccessTable1::ReducedAccessTable.data(), MemoryRegionVirtualDeviceExternalMemoryController1.GetAddress(), EmcAccessTable1::Address, EmcAccessTable1::Size, },
|
||||
{ EmcAccessTable2::ReducedAccessTable.data(), MemoryRegionVirtualDeviceExternalMemoryController2.GetAddress(), EmcAccessTable2::Address, EmcAccessTable2::Size, },
|
||||
{ Mc01AccessTable::ReducedAccessTable.data(), Mc01AccessTable::Address + MemoryRegionVirtualDeviceMemoryController0.GetAddress(), Mc01AccessTable::Address + MemoryRegionPhysicalDeviceMemoryController0.GetAddress(), Mc01AccessTable::Size, },
|
||||
{ Mc01AccessTable::ReducedAccessTable.data(), Mc01AccessTable::Address + MemoryRegionVirtualDeviceMemoryController1.GetAddress(), Mc01AccessTable::Address + MemoryRegionPhysicalDeviceMemoryController1.GetAddress(), Mc01AccessTable::Size, },
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -694,11 +694,11 @@ namespace ams::ldr {
|
||||
|
||||
/* Apply PCV and PTM patches */
|
||||
if (g_is_pcv) {
|
||||
oc::pcv::Patch(map_address, nso_size);
|
||||
hoc::pcv::Patch(map_address, nso_size);
|
||||
}
|
||||
|
||||
if (g_is_ptm) {
|
||||
oc::ptm::Patch(map_address, nso_size);
|
||||
hoc::ptm::Patch(map_address, nso_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,19 +26,21 @@
|
||||
#define DISABLED 0
|
||||
#define DEACTIVATED_GPU_FREQ 2000
|
||||
#define GPU_MIN_MIN_VOLT 480000
|
||||
#define CPU_MAX_MAX_VOLT 1235000
|
||||
#define CPU_MAX_MAX_VOLT 1200000
|
||||
|
||||
namespace ams::ldr::oc {
|
||||
namespace ams::ldr::hoc {
|
||||
|
||||
volatile CustomizeTable C = {
|
||||
|
||||
/* Disables RAM powerdown */
|
||||
.hpMode = DISABLED,
|
||||
|
||||
.commonEmcMemVolt = 1175000, // LPDDR4X JEDEC Specification
|
||||
.eristaEmcMaxClock = 1600000, // Maximum HB-MGCH ram rating
|
||||
.commonEmcMemVolt = 1175000, /* LPDDR4X JEDEC Specification */
|
||||
.eristaEmcMaxClock = 1600000, /* Maximum HB-MGCH ram rating */
|
||||
.eristaEmcMaxClock1 = 1600000,
|
||||
.eristaEmcMaxClock2 = 1600000,
|
||||
|
||||
.marikoEmcMaxClock = 1866000, // 1866MHz @ 1866tWRL is guaranteed to work on all Mariko units
|
||||
.marikoEmcVddqVolt = 600000,
|
||||
.marikoEmcMaxClock = 1866000, /* 1866MHz @ 1866tWRL is guaranteed to work on all Mariko units */
|
||||
.marikoEmcVddqVolt = 600000, /* Micron: 600mV, other manafacturers: 640mV */
|
||||
.emcDvbShift = 0,
|
||||
|
||||
// Primary
|
||||
@@ -52,9 +54,7 @@ volatile CustomizeTable C = {
|
||||
.t7_tWTR = 0,
|
||||
.t8_tREFI = 0,
|
||||
|
||||
/* Set to 4 read and 2 write for 1866b tWRL. */
|
||||
/* For 2133 tWRL: 8 read and 4 write. */
|
||||
|
||||
/* You can mix and match different latencies if needed */
|
||||
/*
|
||||
* Read:
|
||||
* 2133RL = 40
|
||||
@@ -67,8 +67,9 @@ volatile CustomizeTable C = {
|
||||
* 1600WL = 14
|
||||
* 1331WL = 12
|
||||
*/
|
||||
.mem_burst_read_latency = 36,
|
||||
.mem_burst_write_latency = 16,
|
||||
|
||||
.mem_burst_read_latency = RL_1866,
|
||||
.mem_burst_write_latency = WL_1866,
|
||||
|
||||
.eristaCpuUV = 0,
|
||||
.eristaCpuVmin = 800,
|
||||
@@ -78,9 +79,11 @@ volatile CustomizeTable C = {
|
||||
|
||||
.marikoCpuUVLow = 0, // No undervolt
|
||||
.marikoCpuUVHigh = 0, // No undervolt
|
||||
.tableConf = DEFAULT_TABLE,
|
||||
|
||||
.tableConf = TBREAK_1683,
|
||||
.marikoCpuLowVmin = 620,
|
||||
.marikoCpuHighVmin = 750,
|
||||
/* 1120mV is NVIDIA rating */
|
||||
.marikoCpuMaxVolt = 1120,
|
||||
|
||||
/* Supported values: 1963000, 2091000, 2193000, 2295000, 2397000, 2499000, 2601000, 2703000. */
|
||||
@@ -99,19 +102,22 @@ volatile CustomizeTable C = {
|
||||
.eristaGpuVmin = 810,
|
||||
|
||||
.marikoGpuUV = 0,
|
||||
|
||||
/* For automatic vmin detection, set this to AUTO. */
|
||||
/* vmin past 795mV won't work due to HOS limitation */
|
||||
/* Vmin is automatically set to 800mV when SoC temperature is below 20C */
|
||||
.marikoGpuVmin = AUTO,
|
||||
|
||||
.marikoGpuVmax = 800,
|
||||
|
||||
.commonGpuVoltOffset = 0,
|
||||
|
||||
/* Speedo is automatically set by hoc-clk on first boot */
|
||||
.gpuSpeedo = 1450,
|
||||
|
||||
/* This table is used with a gpu uv mode of 2. */
|
||||
/* Setting DEACTIVATED_GPU_FREQ on any freq will disable it and all freqs greater than it. (the latter is a bug :/) */
|
||||
/* AUTO: Voltage is optimally chosen; with commonGpuVoltOffset applied. */
|
||||
/* AUTO only works up to 1305 GPU on Mariko and 921 GPU on Erista */
|
||||
/* AUTO only works up to 1305 GPU on Mariko and 998 GPU on Erista (it is reccomended to manually set your 998MHz voltage though) */
|
||||
/* You can overwrite auto with any voltage (in mv) of your choice - offset will not be applied. */
|
||||
|
||||
.eristaGpuVoltArray = {
|
||||
@@ -159,8 +165,8 @@ volatile CustomizeTable C = {
|
||||
AUTO /* 921 */,
|
||||
AUTO /* 998 */,
|
||||
AUTO /* 1075 */,
|
||||
DEACTIVATED_GPU_FREQ /* 1152 */,
|
||||
DEACTIVATED_GPU_FREQ /* 1228 */,
|
||||
AUTO /* 1152 (SLT / HiOPT Only!) */,
|
||||
AUTO /* 1228 (HiOPT Only!) */,
|
||||
DEACTIVATED_GPU_FREQ /* 1267 (Disabled by default) */,
|
||||
DEACTIVATED_GPU_FREQ /* 1305 (Disabled by default) */,
|
||||
DEACTIVATED_GPU_FREQ /* 1344 (Disabled by default) */,
|
||||
@@ -171,6 +177,10 @@ volatile CustomizeTable C = {
|
||||
DEACTIVATED_GPU_FREQ /* 1536 (Disabled by default) */,
|
||||
},
|
||||
|
||||
/* Advanced. */
|
||||
.fineTune_t6_tRTW = 0,
|
||||
.fineTune_t7_tWTR = 0,
|
||||
|
||||
/* You shouldn't have to anything past here. */
|
||||
.eristaCpuDvfsTable = {
|
||||
{ 204000, { 721094, }, { } },
|
||||
@@ -189,9 +199,9 @@ volatile CustomizeTable C = {
|
||||
{ 1581000, { 1130000, }, { 2889664, -122173, 1834, } },
|
||||
{ 1683000, { 1168000, }, { 5100873, -279186, 4747, } },
|
||||
{ 1785000, { 1225000, }, { 5100873, -279186, 4747, } },
|
||||
// { 1887000, { 1225000, }, { 5100873, -279186, 4747, } },
|
||||
// { 1989000, { 1227500, }, { 5100873, -279186, 4747, } },
|
||||
// { 2091000, { 1256250, }, { 5100873, -279186, 4747, } },
|
||||
{ 1887000, { 1225000, }, { 5100873, -279186, 4747, } },
|
||||
{ 1989000, { 1227500, }, { 5100873, -279186, 4747, } },
|
||||
{ 2091000, { 1256250, }, { 5100873, -279186, 4747, } },
|
||||
},
|
||||
|
||||
.eristaCpuDvfsTableSLT = {
|
||||
@@ -212,10 +222,11 @@ volatile CustomizeTable C = {
|
||||
{ 1683000, { 1168000, }, { 5100873, -279186, 4747, } },
|
||||
{ 1785000, { 1225000, }, { 5100873, -279186, 4747, } },
|
||||
{ 1887000, { 1225000, }, { 5100873, -279186, 4747, } },
|
||||
{ 1989000, { 1227500, }, { 5100873, -279186, 4747, } },
|
||||
{ 2091000, { 1256250, }, { 5100873, -279186, 4747, } },
|
||||
{ 2193000, { 1256250, }, { 5100873, -279186, 4747, } },
|
||||
{ 1963500, { 1227500, }, { 5100873, -279186, 4747, } },
|
||||
{ 2091000, { 1227500, }, { 5100873, -279186, 4747, } },
|
||||
{ 2193000, { 1227500, }, { 5100873, -279186, 4747, } },
|
||||
{ 2295000, { 1256250, }, { 5100873, -279186, 4747, } },
|
||||
{ 2397000, { 1256250, }, { 5100873, -279186, 4747, } }, // Only for god speedo!
|
||||
},
|
||||
|
||||
.marikoCpuDvfsTable = {
|
||||
@@ -455,7 +466,7 @@ volatile CustomizeTable C = {
|
||||
{ 921600, { }, { 970060,-10108, -614,-179, 1508, -13 } },
|
||||
{ 998400, { }, { 1065665,-16075, -497,-179, 3213, 9 } },
|
||||
{ 1075200, { }, { 1132576,-16093, -648, 0, 1077, 40 } },
|
||||
{ 1152000, { }, { 1180029,-14534, -830, 0, 1469, 110 } },
|
||||
// { 1152000, { }, { 1180029,-14534, -830, 0, 1469, 110 } },
|
||||
// { 1228800, { }, { 1248293,-16383, -859, 0, 3722, 313 } },
|
||||
// { 1267200, { }, { 1286399,-17475, -867, 0, 3681, 559 } },
|
||||
},
|
||||
|
||||
@@ -20,20 +20,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define CUST_REV 11
|
||||
#define CUST_REV 1
|
||||
|
||||
#include "oc_common.hpp"
|
||||
#include "pcv/pcv_common.hpp"
|
||||
|
||||
namespace ams::ldr::oc {
|
||||
namespace ams::ldr::hoc {
|
||||
|
||||
#include "mtc_timing_table.hpp"
|
||||
|
||||
enum MtcConfig: u32 {
|
||||
AUTO_ADJ = 0,
|
||||
AUTO_ADJ_BL = 1,
|
||||
};
|
||||
|
||||
enum TableConfig: u32 {
|
||||
DEFAULT_TABLE = 1,
|
||||
TBREAK_1581 = 2,
|
||||
@@ -41,6 +36,33 @@ enum TableConfig: u32 {
|
||||
EXTREME_TABLE = 4,
|
||||
};
|
||||
|
||||
/*
|
||||
* Read:
|
||||
* 2133RL = 40
|
||||
* 1866RL = 36
|
||||
* 1600RL = 32
|
||||
* 1331RL = 28
|
||||
* Write:
|
||||
* 2133WL = 18
|
||||
* 1866WL = 16
|
||||
* 1600WL = 14
|
||||
* 1331WL = 12
|
||||
*/
|
||||
|
||||
enum ReadLatency: u32 {
|
||||
RL_2133 = 40,
|
||||
RL_1866 = 36,
|
||||
RL_1600 = 32,
|
||||
RL_1331 = 28,
|
||||
};
|
||||
|
||||
enum WriteLatency: u32 {
|
||||
WL_2133 = 18,
|
||||
WL_1866 = 16,
|
||||
WL_1600 = 14,
|
||||
WL_1331 = 12,
|
||||
};
|
||||
|
||||
using CustomizeCpuDvfsTable = pcv::cvb_entry_t[pcv::DvfsTableEntryLimit];
|
||||
using CustomizeGpuDvfsTable = pcv::cvb_entry_t[pcv::DvfsTableEntryLimit];
|
||||
static_assert(sizeof(CustomizeCpuDvfsTable) == sizeof(CustomizeGpuDvfsTable));
|
||||
@@ -53,11 +75,13 @@ typedef struct CustomizeTable {
|
||||
u8 cust[4] = {'C', 'U', 'S', 'T'};
|
||||
u32 custRev = CUST_REV;
|
||||
|
||||
u32 mtcConf;
|
||||
u32 placeholder;
|
||||
u32 hpMode;
|
||||
|
||||
u32 commonEmcMemVolt;
|
||||
u32 eristaEmcMaxClock;
|
||||
u32 eristaEmcMaxClock1;
|
||||
u32 eristaEmcMaxClock2;
|
||||
u32 marikoEmcMaxClock;
|
||||
u32 marikoEmcVddqVolt;
|
||||
u32 emcDvbShift;
|
||||
@@ -99,12 +123,16 @@ typedef struct CustomizeTable {
|
||||
|
||||
u32 commonGpuVoltOffset;
|
||||
|
||||
/* TODO: Automatically detect speedo. */
|
||||
u32 gpuSpeedo;
|
||||
|
||||
u32 eristaGpuVoltArray[27];
|
||||
u32 marikoGpuVoltArray[24];
|
||||
u32 reserved[64];
|
||||
|
||||
u32 fineTune_t6_tRTW;
|
||||
u32 fineTune_t7_tWTR;
|
||||
|
||||
u32 reserved[60];
|
||||
|
||||
CustomizeCpuDvfsTable eristaCpuDvfsTable;
|
||||
CustomizeCpuDvfsTable eristaCpuDvfsTableSLT;
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) Lightos_
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 "../oc_common.hpp"
|
||||
#include "../mtc_timing_value.hpp"
|
||||
|
||||
namespace ams::ldr::hoc::pcv::erista {
|
||||
|
||||
void CalculateTimings(double tCK_avg) {
|
||||
tR2W = FLOOR(FLOOR((5.0 / tCK_avg) + ((FLOOR(48.0 / WL) - 0.478) * 3.0)) / 1.501) + RL - (C.t6_tRTW * 3) + finetRTW;
|
||||
tWTPDEN = CEIL(((1.803 / tCK_avg) + MAX(RL + (2.694 / tCK_avg), static_cast<double>(tW2P))) + (BL / 2));
|
||||
tW2R = FLOOR(MAX((5.020 / tCK_avg) + 1.130, WL - MAX(-CEIL(0.258 * (WL - RL)), 1.964)) * 1.964) + WL - CEIL(tWTR / tCK_avg) + finetWTR;
|
||||
|
||||
pdex2rw = CEIL((CEIL(12.335 - tCK_avg) + (7.430 / tCK_avg) - CEIL(tCK_avg * 11.361)));
|
||||
tCLKSTOP = FLOOR(MIN(8.488 / tCK_avg, 23.0)) + 8.0;
|
||||
|
||||
const double tMMRI = tRCD + (tCK_avg * 3);
|
||||
pdex2mrr = tMMRI + 10;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Lightos_
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ams::ldr::hoc::pcv::erista {
|
||||
|
||||
void CalculateTimings(double tCK_avg);
|
||||
|
||||
}
|
||||
@@ -18,49 +18,16 @@
|
||||
#include "../mtc_timing_value.hpp"
|
||||
#include "timing_tables.hpp"
|
||||
|
||||
namespace ams::ldr::oc::pcv::mariko {
|
||||
namespace ams::ldr::hoc::pcv::mariko {
|
||||
|
||||
u32 GetRext() {
|
||||
void GetRext() {
|
||||
if (auto r = FindRext()) {
|
||||
return r->correct;
|
||||
rext = r->rext;
|
||||
return;
|
||||
}
|
||||
return 0x1A;
|
||||
}
|
||||
|
||||
void CalculateTWTPDEN() {
|
||||
tWTPDEN = tW2P + 1 + CEIL(tDQSS_max / tCK_avg) + CEIL(tDQS2DQ_max / tCK_avg) + 6;
|
||||
if (C.marikoEmcMaxClock >= 2'233'000 && C.marikoEmcMaxClock < 2'533'000) tWTPDEN++;
|
||||
if (C.marikoEmcMaxClock >= 2'433'000 && C.marikoEmcMaxClock < 2'800'000) tWTPDEN--;
|
||||
}
|
||||
|
||||
void CalculateTR2W() {
|
||||
tR2W = CEIL(RL_DBI + (tDQSCK_max / tCK_avg) + (BL / 2) - WL + tWPRE + FLOOR(tRPST) + 9.0) - (C.t6_tRTW * 3);
|
||||
|
||||
if (auto patch = FindTR2WPatch()) {
|
||||
tR2W += patch->adjust;
|
||||
}
|
||||
}
|
||||
|
||||
void CalculatePdex2rw() {
|
||||
double freq_mhz = C.marikoEmcMaxClock / 1000.0;
|
||||
|
||||
double pdex_local = (0.011 * freq_mhz) - 1.443;
|
||||
pdex2rw = static_cast<u32>(ROUND(pdex_local));
|
||||
|
||||
if (pdex2rw < 22) pdex2rw = 22;
|
||||
if (pdex2rw > 33) pdex2rw = 33;
|
||||
|
||||
if (auto patch = FindPdex2rwPatch()) {
|
||||
pdex2rw += patch->adjust;
|
||||
}
|
||||
}
|
||||
|
||||
void CalculateCke2pden() {
|
||||
cke2pden = (static_cast<double>((C.marikoEmcMaxClock / 1000.0) * 0.00875) - 0.65);
|
||||
|
||||
if (auto patch = FindCke2pdenPatch()) {
|
||||
cke2pden += patch->adjust;
|
||||
}
|
||||
/* Fallback. */
|
||||
rext = 0x1A;
|
||||
}
|
||||
|
||||
void CalculateMrw2() {
|
||||
@@ -76,7 +43,7 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
u32 wlIndex = 0;
|
||||
|
||||
for (u32 i = 0; i < std::size(rlMapDBI); ++i) {
|
||||
if (rlMapDBI[i] == RL_DBI) {
|
||||
if (rlMapDBI[i] == RL) {
|
||||
rlIndex = i;
|
||||
break;
|
||||
}
|
||||
@@ -93,11 +60,7 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
}
|
||||
|
||||
void CalculateTimings() {
|
||||
rext = GetRext();
|
||||
CalculateTWTPDEN();
|
||||
CalculateTR2W();
|
||||
CalculatePdex2rw();
|
||||
CalculateCke2pden();
|
||||
GetRext();
|
||||
CalculateMrw2();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ams::ldr::oc::pcv::mariko {
|
||||
namespace ams::ldr::hoc::pcv::mariko {
|
||||
|
||||
void CalculateTimings();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "../mtc_timing_value.hpp"
|
||||
#include "timing_tables.hpp"
|
||||
|
||||
namespace ams::ldr::oc::pcv::mariko {
|
||||
namespace ams::ldr::hoc::pcv::mariko {
|
||||
|
||||
const ReplacePatch g_rext_table[] = {
|
||||
{2'133'000, 0x1A}, {2'166'000, 0x19}, {2'200'000, 0x19},
|
||||
@@ -36,78 +36,11 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
const u32 g_rext_table_size = sizeof(g_rext_table) / sizeof(g_rext_table[0]);
|
||||
|
||||
const ReplacePatch *FindRext() {
|
||||
for (u32 i = 0; i < g_rext_table_size; i++)
|
||||
if (g_rext_table[i].freq == C.marikoEmcMaxClock)
|
||||
for (u32 i = 0; i < g_rext_table_size; i++) {
|
||||
if (g_rext_table[i].freq >= C.marikoEmcMaxClock) {
|
||||
return &g_rext_table[i];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const AdjustPatch g_tr2w_patches[] = {
|
||||
{2'500'000, 1},
|
||||
{2'533'000, 1},
|
||||
{2'566'000, 1},
|
||||
{2'866'000, -1},
|
||||
{3'100'000, 1},
|
||||
{3'133'000, 1},
|
||||
};
|
||||
|
||||
const u32 g_tr2w_table_size = sizeof(g_tr2w_patches) / sizeof(g_tr2w_patches[0]);
|
||||
|
||||
const AdjustPatch *FindTR2WPatch() {
|
||||
for (u32 i = 0; i < g_tr2w_table_size; i++)
|
||||
if (g_tr2w_patches[i].freq == C.marikoEmcMaxClock)
|
||||
return &g_tr2w_patches[i];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const AdjustPatch g_pdex2rw_patches[] = {
|
||||
{2'166'000, 1},
|
||||
{2'300'000, 1},
|
||||
{2'333'000, 1},
|
||||
{2'433'000, 1},
|
||||
{2'533'000, 0},
|
||||
{2'633'000, -1},
|
||||
{2'666'000, -1},
|
||||
{2'733'000, -1},
|
||||
{2'766'000, -1},
|
||||
{2'800'000, -1},
|
||||
{2'833'000, -1},
|
||||
{2'933'000, -1},
|
||||
{3'066'000, 1},
|
||||
};
|
||||
|
||||
const u32 g_pdex2rw_table_size = sizeof(g_pdex2rw_patches) / sizeof(g_pdex2rw_patches[0]);
|
||||
|
||||
const AdjustPatch *FindPdex2rwPatch() {
|
||||
for (u32 i = 0; i < g_pdex2rw_table_size; i++)
|
||||
if (g_pdex2rw_patches[i].freq == C.marikoEmcMaxClock)
|
||||
return &g_pdex2rw_patches[i];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const AdjustPatch g_cke2pden_patches[] = {
|
||||
{2'133'000, 1},
|
||||
{2'166'000, 1},
|
||||
{2'266'000, 1},
|
||||
{2'300'000, 1},
|
||||
{2'366'000, 1},
|
||||
{2'400'000, 1},
|
||||
{2'500'000, 1},
|
||||
{2'633'000, 1},
|
||||
{2'733'000, 1},
|
||||
{2'833'000, 1},
|
||||
{2'866'000, 1},
|
||||
{2'966'000, 1},
|
||||
{3'066'000, 1},
|
||||
{3'100'000, 1},
|
||||
};
|
||||
|
||||
const u32 g_cke2pden_table_size = sizeof(g_cke2pden_patches) / sizeof(g_cke2pden_patches[0]);
|
||||
|
||||
const AdjustPatch *FindCke2pdenPatch() {
|
||||
for (u32 i = 0; i < g_cke2pden_table_size; i++)
|
||||
if (g_cke2pden_patches[i].freq == C.marikoEmcMaxClock)
|
||||
return &g_cke2pden_patches[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,32 +17,15 @@
|
||||
#pragma once
|
||||
#include "../mtc_timing_value.hpp"
|
||||
|
||||
namespace ams::ldr::oc::pcv::mariko {
|
||||
namespace ams::ldr::hoc::pcv::mariko {
|
||||
|
||||
struct ReplacePatch {
|
||||
u32 freq;
|
||||
u32 correct;
|
||||
u32 rext;
|
||||
};
|
||||
|
||||
extern const ReplacePatch g_rext_table[];
|
||||
extern const u32 g_rext_table_size;
|
||||
const ReplacePatch *FindRext();
|
||||
|
||||
struct AdjustPatch {
|
||||
u32 freq;
|
||||
s32 adjust;
|
||||
};
|
||||
|
||||
extern const AdjustPatch g_tr2w_patches[];
|
||||
extern const u32 g_tr2w_table_size;
|
||||
const AdjustPatch *FindTR2WPatch();
|
||||
|
||||
extern const AdjustPatch g_pdex2rw_patches[];
|
||||
extern const u32 g_pdex2rw_table_size;
|
||||
const AdjustPatch *FindPdex2rwPatch();
|
||||
|
||||
extern const AdjustPatch g_cke2pden_patches[];
|
||||
extern const u32 g_cke2pden_table_size;
|
||||
const AdjustPatch *FindCke2pdenPatch();
|
||||
|
||||
}
|
||||
|
||||
@@ -20,35 +20,23 @@
|
||||
|
||||
#include "oc_common.hpp"
|
||||
|
||||
namespace ams::ldr::oc {
|
||||
#define MAX(A, B) std::max(A, B)
|
||||
#define MIN(A, B) std::min(A, B)
|
||||
#define CEIL(A) std::ceil(A)
|
||||
#define FLOOR(A) std::floor(A)
|
||||
#define ROUND(A) std::lround(A)
|
||||
namespace ams::ldr::hoc {
|
||||
#define MAX(A, B) std::max(A, B)
|
||||
#define MIN(A, B) std::min(A, B)
|
||||
#define CEIL(A) std::ceil(A)
|
||||
#define FLOOR(A) std::floor(A)
|
||||
#define ROUND(A) std::lround(A)
|
||||
|
||||
#define PACK_U32(high, low) ((static_cast<u32>(high) << 16) | (static_cast<u32>(low) & 0xFFFF))
|
||||
#define PACK_U32_NIBBLE_HIGH_BYTE_LOW(high, low) ((static_cast<u32>(high & 0xF) << 28) | (static_cast<u32>(low) & 0xFF))
|
||||
|
||||
/* Primary timings. */
|
||||
const std::array<u32, 8> tRCD_values = { 18, 17, 16, 15, 14, 13, 12, 11 };
|
||||
const std::array<u32, 8> tRP_values = { 18, 17, 16, 15, 14, 13, 12, 11 };
|
||||
const std::array<u32, 10> tRAS_values = { 42, 36, 34, 32, 30, 28, 26, 24, 22, 20 };
|
||||
const std::array<double, 7> tRRD_values = { /*10.0,*/ 7.5, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 }; /* 10.0 is used for <2133mhz; do we care? 8gb uses 7.5 tRRD on >=1331. */
|
||||
const std::array<u32, 11> tRFC_values = { 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40 };
|
||||
const std::array<u32, 10> tWTR_values = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
|
||||
const std::array<u32, 6> tREFpb_values = { 3900, 5850, 7800, 11700, 15600, 99999 };
|
||||
|
||||
/* Burst latency, not to be confused with base latency (tWRL). */
|
||||
const u32 BL = 16;
|
||||
|
||||
/* Base latency for read and write (tWRL). */
|
||||
const u32 RL = C.mem_burst_read_latency - 4; /* (This is a lazy fix for now) */
|
||||
const u32 RL = C.mem_burst_read_latency;
|
||||
const u32 WL = C.mem_burst_write_latency;
|
||||
|
||||
/* Switch uses RL_DBI, todo: get rid of non DBI_RL. */
|
||||
const u32 RL_DBI = RL + 4;
|
||||
|
||||
/* Precharge to Precharge Delay. (tCK) */
|
||||
const u32 tPPD = 4;
|
||||
|
||||
@@ -75,56 +63,14 @@ namespace ams::ldr::oc {
|
||||
/* Write recovery time. */
|
||||
const u32 tWR = 18;
|
||||
|
||||
/* TOOD: Fix erista */
|
||||
namespace pcv::erista {
|
||||
const double tCK_avg = 1000'000.0 / C.eristaEmcMaxClock;
|
||||
|
||||
const u32 tRCD = tRCD_values[C.t1_tRCD];
|
||||
const u32 tRPpb = tRP_values[C.t2_tRP];
|
||||
const u32 tRAS = tRAS_values[C.t3_tRAS];
|
||||
const double tRRD = tRRD_values[C.t4_tRRD];
|
||||
const u32 tRFCpb = tRFC_values[C.t5_tRFC];
|
||||
const u32 tWTR = 10 - tWTR_values[C.t7_tWTR];
|
||||
|
||||
const u32 tRC = tRAS + tRPpb;
|
||||
const u32 tRFCab = tRFCpb * 2;
|
||||
const double tXSR = (double) (tRFCab + 7.5);
|
||||
const u32 tFAW = static_cast<u32>(tRRD * 4.0);
|
||||
const double tRPab = tRPpb + 3;
|
||||
|
||||
const u32 tR2P = 12;
|
||||
|
||||
const u32 tW2P = (CEIL(WL * 1.7303) * 2) - 5;
|
||||
const u32 tW2R = CEIL(MAX(WL + (0.010322547033278747 * (C.eristaEmcMaxClock / 1000.0)), (WL * -0.2067922202979121) + FLOOR(((RL_DBI * -0.1331159971685554) + WL) * 3.654131957826108)) - (tWTR / tCK_avg));
|
||||
|
||||
const u32 wdv = WL;
|
||||
const u32 wsv = WL - 2;
|
||||
const u32 wev = 0xA + (WL - 14);
|
||||
|
||||
const double freq_mhz = C.eristaEmcMaxClock / 1000.0;
|
||||
|
||||
const u32 quse_width = CEIL(((3.7165006256863955 - freq_mhz) + (-0.002446584377651142 * freq_mhz)) - FLOOR(freq_mhz / -0.9952024303111688));
|
||||
const u32 quse = CEIL(MIN(RL_DBI + (2.991255208275918 - (quse_width + (-0.00511180626826906 * freq_mhz))), freq_mhz * 0.021333773138874437));
|
||||
const u32 ibdly = 0x10000000 + FLOOR(MAX(RL_DBI - 1.9999956603408224, quse - 5.9999987787411175) + (-0.0011929079761504341 * freq_mhz));
|
||||
const u32 obdlyHigh = 3 / FLOOR(MIN(static_cast<double>(2), tCK_avg * (WL - 7)));
|
||||
const u32 obdlyLow = WL - MIN(static_cast<double>(WL), 12 - (CEIL(-0.0003991 * freq_mhz) * 2));
|
||||
const u32 obdly = PACK_U32_NIBBLE_HIGH_BYTE_LOW(obdlyHigh, obdlyLow);
|
||||
const u32 tCKE = CEIL(1.0795 * CEIL(0.0074472 * (C.eristaEmcMaxClock / 1000.0)));
|
||||
|
||||
const double tMMRI = tRCD + (tCK_avg * 3);
|
||||
const double pdex2mrr = tMMRI + 10;
|
||||
const u32 tWTPDEN = tW2P + 1 + CEIL(tDQSS_max / tCK_avg) + CEIL(tDQS2DQ_max / tCK_avg) + 6;
|
||||
const u32 tR2W = CEIL(RL_DBI + (tDQSCK_max / tCK_avg) + (BL / 2) - WL + tWPRE + FLOOR(tRPST) + 9.0) - (C.t6_tRTW * 3);
|
||||
|
||||
const double pdex_local = (0.011 * freq_mhz) - 1.443;
|
||||
const u32 pdex2rw = static_cast<u32>(ROUND(pdex_local)) < 22 ? 22 : (static_cast<u32>(ROUND(pdex_local)) > 33 ? 33 : static_cast<u32>(ROUND(pdex_local)));
|
||||
|
||||
const double cke2pden = (static_cast<double>((C.eristaEmcMaxClock / 1000.0) * 0.00875) - 0.65);
|
||||
}
|
||||
|
||||
namespace pcv::mariko {
|
||||
const double tCK_avg = 1000'000.0 / C.marikoEmcMaxClock;
|
||||
const double ramFreqMhz = C.marikoEmcMaxClock / 1000.0;
|
||||
const std::array<u32, 8> tRCD_values = { 18, 17, 16, 15, 14, 13, 12, 11 };
|
||||
const std::array<u32, 8> tRP_values = { 18, 17, 16, 15, 14, 13, 12, 11 };
|
||||
const std::array<u32, 10> tRAS_values = { 42, 36, 34, 32, 30, 28, 26, 24, 22, 20 };
|
||||
const std::array<double, 8> tRRD_values = { 10.0, 7.5, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 };
|
||||
const std::array<u32, 6> tRFC_values = { 90, 80, 70, 60, 50, 40 };
|
||||
const std::array<u32, 10> tWTR_values = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
|
||||
const std::array<u32, 6> tREFpb_values = { 3900, 5850, 7800, 11700, 15600, 99999 };
|
||||
|
||||
const u32 tRCD = tRCD_values[C.t1_tRCD];
|
||||
const u32 tRPpb = tRP_values[C.t2_tRP];
|
||||
@@ -132,6 +78,8 @@ namespace ams::ldr::oc {
|
||||
const double tRRD = tRRD_values[C.t4_tRRD];
|
||||
const u32 tRFCpb = tRFC_values[C.t5_tRFC];
|
||||
const u32 tWTR = 10 - tWTR_values[C.t7_tWTR];
|
||||
const s32 finetRTW = C.fineTune_t6_tRTW;
|
||||
const s32 finetWTR = C.fineTune_t7_tWTR;
|
||||
|
||||
const u32 tRC = tRAS + tRPpb;
|
||||
const u32 tRFCab = tRFCpb * 2;
|
||||
@@ -139,43 +87,81 @@ namespace ams::ldr::oc {
|
||||
const u32 tFAW = static_cast<u32>(tRRD * 4.0);
|
||||
const double tRPab = tRPpb + 3;
|
||||
|
||||
const u32 tR2P = 12 + ((RL_DBI - 32) / 2);
|
||||
const u32 tR2P = CEIL((RL * 0.426) - 2.0);
|
||||
inline u32 tR2W;
|
||||
const u32 tRTM = RL + 9 + (tDQSCK_max / tCK_avg) + FLOOR(tRPST) + CEIL(10 / tCK_avg); // Fix?
|
||||
const u32 tRATM = tRTM + CEIL(10 / tCK_avg) - 12; // Fix?
|
||||
inline u32 rext;
|
||||
|
||||
const u32 rdv = FLOOR(17.02046755653219 + (RL_DBI + (ramFreqMhz * 0.00510056573299173)));
|
||||
const u32 qpop = rdv - 14;
|
||||
const u32 quse_width = CEIL(((3.7165006256863955 - ramFreqMhz) + (-0.002446584377651142 * ramFreqMhz)) - FLOOR(ramFreqMhz / -0.9952024303111688));
|
||||
const u32 quse = CEIL(MIN(RL_DBI + (2.991255208275918 - (quse_width + (-0.00511180626826906 * ramFreqMhz))), ramFreqMhz * 0.021333773138874437));
|
||||
const u32 einput_duration = CEIL(quse_width + (ramFreqMhz * 0.01) + 4);
|
||||
const u32 einput = 5 + qpop - einput_duration;
|
||||
const u32 ibdly = 0x10000000 + FLOOR(MAX(RL_DBI - 1.9999956603408224, quse - 5.9999987787411175) + (-0.0011929079761504341 * ramFreqMhz));
|
||||
const u32 qrst_duration = FLOOR((ramFreqMhz * 0.001477125119082522) + 4.272302254983803);
|
||||
const u32 qrstLow = MAX(static_cast<s32>(einput - qrst_duration - 2), static_cast<s32>(0));
|
||||
const u32 qrst = PACK_U32(qrst_duration, qrstLow);
|
||||
const u32 qsafe = (einput_duration + 3) + MAX(MIN(qrstLow * rdv, qrst_duration + qrst_duration), einput);
|
||||
|
||||
const u32 tW2P = (CEIL(WL * 1.7303) * 2) - 5;
|
||||
const u32 tW2P = (CEIL(WL * 1.7303) * 2) - 5;
|
||||
inline u32 tWTPDEN;
|
||||
const u32 tW2R = CEIL(MAX(WL + (0.010322547033278747 * ramFreqMhz), (WL * -0.2067922202979121) + FLOOR(((RL_DBI * -0.1331159971685554) + WL) * 3.654131957826108)) - (tWTR / tCK_avg));
|
||||
const u32 tWTM = WL + (BL / 2) + 1 + CEIL(7.5 / tCK_avg);
|
||||
const u32 tWATM = tWTM + CEIL(tWR / tCK_avg);
|
||||
inline u32 tW2R;
|
||||
|
||||
inline u32 pdex2rw;
|
||||
|
||||
inline u32 tCLKSTOP;
|
||||
|
||||
inline double pdex2mrr;
|
||||
}
|
||||
|
||||
namespace pcv::mariko {
|
||||
const std::array<u32, 8> tRCD_values = { 18, 17, 16, 15, 14, 13, 12, 11 };
|
||||
const std::array<u32, 8> tRP_values = { 18, 17, 16, 15, 14, 13, 12, 11 };
|
||||
const std::array<u32, 10> tRAS_values = { 42, 36, 34, 32, 30, 28, 26, 24, 22, 20 };
|
||||
const std::array<double, 7> tRRD_values = { /*10.0,*/ 7.5, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 }; /* 10.0 is used for <2133mhz; do we care? 8gb uses 7.5 tRRD on >=1331. */
|
||||
const std::array<u32, 11> tRFC_values = { 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40 };
|
||||
const std::array<u32, 10> tWTR_values = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
|
||||
const std::array<u32, 6> tREFpb_values = { 3900, 5850, 7800, 11700, 15600, 99999 };
|
||||
|
||||
const double tCK_avg = 1000'000.0 / C.marikoEmcMaxClock;
|
||||
|
||||
const u32 tRCD = tRCD_values[C.t1_tRCD];
|
||||
const u32 tRPpb = tRP_values[C.t2_tRP];
|
||||
const u32 tRAS = tRAS_values[C.t3_tRAS];
|
||||
const double tRRD = tRRD_values[C.t4_tRRD];
|
||||
const u32 tRFCpb = tRFC_values[C.t5_tRFC];
|
||||
const u32 tWTR = 10 - tWTR_values[C.t7_tWTR];
|
||||
const s32 finetRTW = C.fineTune_t6_tRTW;
|
||||
const s32 finetWTR = C.fineTune_t7_tWTR;
|
||||
|
||||
const u32 tRC = tRAS + tRPpb;
|
||||
const u32 tRFCab = tRFCpb * 2;
|
||||
const double tXSR = static_cast<double>(tRFCab + 7.5);
|
||||
const u32 tFAW = static_cast<u32>(tRRD * 4.0);
|
||||
const double tRPab = tRPpb + 3;
|
||||
|
||||
const u32 tR2P = CEIL((RL * 0.426) - 2.0);
|
||||
const u32 tR2W = FLOOR(FLOOR((5.0 / tCK_avg) + ((FLOOR(48.0 / WL) - 0.478) * 3.0)) / 1.501) + RL - (C.t6_tRTW * 3) + finetRTW;
|
||||
const u32 tRTM = FLOOR((10.0 + RL) + (3.502 / tCK_avg)) + FLOOR(7.489 / tCK_avg);
|
||||
const u32 tRATM = CEIL((tRTM - 10.0) + (RL * 0.426));
|
||||
inline u32 rext;
|
||||
|
||||
const u32 rdv = RL + FLOOR((5.105 / tCK_avg) + 17.017);
|
||||
const u32 qpop = rdv - 14;
|
||||
const u32 quse_width = CEIL(((4.897 / tCK_avg) - FLOOR(2.538 / tCK_avg)) + 3.782);
|
||||
const u32 quse = FLOOR(RL + ((5.082 / tCK_avg) + FLOOR(2.560 / tCK_avg))) - CEIL(4.820 / tCK_avg);
|
||||
const u32 einput_duration = FLOOR(9.936 / tCK_avg) + 5.0 + quse_width;
|
||||
const u32 einput = quse - CEIL(9.928 / tCK_avg);
|
||||
const u32 qrst_duration = FLOOR(8.399 - tCK_avg);
|
||||
const u32 qrstLow = MAX(static_cast<s32>(einput - qrst_duration - 2), static_cast<s32>(0));
|
||||
const u32 qrst = PACK_U32(qrst_duration, qrstLow);
|
||||
const u32 ibdly = PACK_U32_NIBBLE_HIGH_BYTE_LOW(1, quse - qrst_duration - 2.0);
|
||||
const u32 qsafe = (einput_duration + 3) + MAX(MIN(qrstLow * rdv, qrst_duration + qrst_duration), einput);
|
||||
const u32 tW2P = (CEIL(WL * 1.7303) * 2) - 5;
|
||||
const u32 tWTPDEN = CEIL(((1.803 / tCK_avg) + MAX(RL + (2.694 / tCK_avg), static_cast<double>(tW2P))) + (BL / 2));
|
||||
const u32 tW2R = FLOOR(MAX((5.020 / tCK_avg) + 1.130, WL - MAX(-CEIL(0.258 * (WL - RL)), 1.964)) * 1.964) + WL - CEIL(tWTR / tCK_avg) + finetWTR;
|
||||
const u32 tWTM = CEIL(WL + ((7.570 / tCK_avg) + 8.753));
|
||||
const u32 tWATM = (tWTM + (FLOOR(WL / 0.816) * 2.0)) - 4.0;
|
||||
|
||||
const u32 wdv = WL;
|
||||
const u32 wsv = WL - 2;
|
||||
const u32 wev = 0xA + (WL - 14);
|
||||
|
||||
const u32 obdlyHigh = 3 / FLOOR(MIN(static_cast<double>(2), tCK_avg * (WL - 7)));
|
||||
const u32 obdlyLow = WL - MIN(static_cast<double>(WL), 12 - (CEIL(-0.0003991 * ramFreqMhz) * 2));
|
||||
|
||||
const u32 obdlyLow = MAX(WL - FLOOR((126.0 / CEIL(tCK_avg + 8.601))), 0.0);
|
||||
const u32 obdly = PACK_U32_NIBBLE_HIGH_BYTE_LOW(obdlyHigh, obdlyLow);
|
||||
|
||||
inline u32 pdex2rw;
|
||||
inline u32 cke2pden;
|
||||
const u32 pdex2rw = CEIL((CEIL(12.335 - tCK_avg) + (7.430 / tCK_avg) - CEIL(tCK_avg * 11.361)));
|
||||
|
||||
const u32 tCKE = CEIL(1.0795 * CEIL(0.0074472 * ramFreqMhz));
|
||||
const u32 tCLKSTOP = FLOOR(MIN(8.488 / tCK_avg, 23.0)) + 8.0;
|
||||
|
||||
const double tMMRI = tRCD + (tCK_avg * 3);
|
||||
const double pdex2mrr = tMMRI + 10; /* Do this properly? */
|
||||
@@ -185,3 +171,4 @@ namespace ams::ldr::oc {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace ams::ldr {
|
||||
R_DEFINE_ERROR_RESULT(SafetyCheckFailure, 1015);
|
||||
}
|
||||
|
||||
namespace ams::ldr::oc {
|
||||
namespace ams::ldr::hoc {
|
||||
template<typename Pointer>
|
||||
struct PatcherEntry {
|
||||
using patternFn = bool(*)(Pointer* ptr);
|
||||
@@ -99,4 +99,25 @@ namespace ams::ldr::oc {
|
||||
R_SUCCEED();
|
||||
}
|
||||
};
|
||||
|
||||
namespace panic {
|
||||
/* Requires modifying g_ams_handlers in secmon_smc_handler.cpp */
|
||||
constexpr inline void SmcError(u32 rgb) {
|
||||
SecmonArgs args = {};
|
||||
constexpr u32 SmcShowErrorID = 0xF0000005;
|
||||
args.X[0] = SmcShowErrorID;
|
||||
args.X[1] = rgb;
|
||||
svcCallSecureMonitor(&args);
|
||||
}
|
||||
|
||||
constexpr inline u32 PackCode(u32 r, u32 g, u32 b) {
|
||||
return ((r & 0xF) << 8) | ((g & 0xF) << 4) | ((b & 0xF) << 0);
|
||||
}
|
||||
|
||||
constexpr u32 Gpu = PackCode(0xF, 0x7, 0x0);
|
||||
constexpr u32 Cpu = PackCode(0xF, 0x0, 0x0);
|
||||
constexpr u32 Emc = PackCode(0x0, 0xF, 0xF);
|
||||
constexpr u32 Patch = PackCode(0x8, 0x0, 0xF);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ void saveExec(const char* file_loc, const void* buf, size_t size) {
|
||||
}
|
||||
|
||||
Result Test_PcvDvfsTable() {
|
||||
using namespace ams::ldr::oc::pcv;
|
||||
using namespace ams::ldr::hoc::pcv;
|
||||
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&mariko::CpuCvbTableDefault)) == 18);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&erista::CpuCvbTableDefault)) == 16);
|
||||
@@ -76,19 +76,19 @@ Result Test_PcvDvfsTable() {
|
||||
cvb_entry_t last_mariko_cpu_cvb_entry_default = { 1963500, { 1675751, -38635, 27 }, { 1120000 } };
|
||||
assert(memcmp(GetDvfsTableLastEntry((cvb_entry_t *)(&mariko::CpuCvbTableDefault)), (void *)&last_mariko_cpu_cvb_entry_default, sizeof(last_mariko_cpu_cvb_entry_default)) == 0);
|
||||
assert(GetDvfsTableLastEntry((cvb_entry_t *)(&erista::GpuCvbTableDefault))->freq == 921600);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoCpuDvfsTableSLT)) == 25);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoCpuDvfsTableSLT)) == 25);
|
||||
|
||||
// Customized table default
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.eristaCpuDvfsTable)) == 19);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoCpuDvfsTable)) == 21);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoCpuDvfsTableSLT)) == 22);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.eristaCpuDvfsTable)) == 19);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoCpuDvfsTable)) == 21);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoCpuDvfsTableSLT)) == 22);
|
||||
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.eristaGpuDvfsTable)) == 12);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoGpuDvfsTable)) == 17);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoGpuDvfsTableSLT)) == 17);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::oc::C.marikoGpuDvfsTableHiOPT)) == 17);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.eristaGpuDvfsTable)) == 12);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoGpuDvfsTable)) == 17);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoGpuDvfsTableSLT)) == 17);
|
||||
assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoGpuDvfsTableHiOPT)) == 17);
|
||||
|
||||
constexpr size_t limit = ams::ldr::oc::pcv::DvfsTableEntryLimit;
|
||||
constexpr size_t limit = ams::ldr::hoc::pcv::DvfsTableEntryLimit;
|
||||
cvb_entry_t customized_table[limit] = {};
|
||||
for (size_t i = 0; i < limit; i++) {
|
||||
assert(GetDvfsTableEntryCount(customized_table) == i);
|
||||
@@ -156,14 +156,14 @@ int main(int argc, char** argv) {
|
||||
size_t exec_path_patched_len = exec_path_len + std::max(strlen(mariko_ext), strlen(erista_ext)) + 1;
|
||||
|
||||
if (exe_opt == EXE_PCV) {
|
||||
ams::ldr::oc::pcv::SafetyCheck();
|
||||
ams::ldr::hoc::pcv::SafetyCheck();
|
||||
|
||||
{
|
||||
void* erista_buf = malloc(file_size);
|
||||
std::memcpy(erista_buf, file_buffer, file_size);
|
||||
|
||||
printf("Patching %s for Erista...\n", pcv_opt);
|
||||
ams::ldr::oc::pcv::erista::Patch(reinterpret_cast<uintptr_t>(erista_buf), file_size);
|
||||
ams::ldr::hoc::pcv::erista::Patch(reinterpret_cast<uintptr_t>(erista_buf), file_size);
|
||||
if (save_patched) {
|
||||
char* exec_path_erista = reinterpret_cast<char *>(malloc(exec_path_patched_len));
|
||||
strncpy(exec_path_erista, exec_path, exec_path_patched_len);
|
||||
@@ -179,7 +179,7 @@ int main(int argc, char** argv) {
|
||||
std::memcpy(mariko_buf, file_buffer, file_size);
|
||||
|
||||
printf("Patching %s for Mariko...\n", pcv_opt);
|
||||
ams::ldr::oc::pcv::mariko::Patch(reinterpret_cast<uintptr_t>(mariko_buf), file_size);
|
||||
ams::ldr::hoc::pcv::mariko::Patch(reinterpret_cast<uintptr_t>(mariko_buf), file_size);
|
||||
if (save_patched) {
|
||||
char* exec_path_mariko = reinterpret_cast<char *>(malloc(exec_path_patched_len));
|
||||
strncpy(exec_path_mariko, exec_path, exec_path_patched_len);
|
||||
@@ -196,7 +196,7 @@ int main(int argc, char** argv) {
|
||||
std::memcpy(mariko_buf, file_buffer, file_size);
|
||||
|
||||
printf("Patching %s (Mariko Only)...\n", ptm_opt);
|
||||
ams::ldr::oc::ptm::Patch(reinterpret_cast<uintptr_t>(mariko_buf), file_size);
|
||||
ams::ldr::hoc::ptm::Patch(reinterpret_cast<uintptr_t>(mariko_buf), file_size);
|
||||
if (save_patched) {
|
||||
char* exec_path_mariko = reinterpret_cast<char *>(malloc(exec_path_patched_len));
|
||||
strncpy(exec_path_mariko, exec_path, exec_path_patched_len);
|
||||
|
||||
@@ -20,154 +20,165 @@
|
||||
|
||||
#include "pcv.hpp"
|
||||
|
||||
namespace ams::ldr::oc::pcv {
|
||||
namespace ams::ldr::hoc::pcv {
|
||||
|
||||
Result MemFreqPllmLimit(u32* ptr) {
|
||||
clk_pll_param* entry = reinterpret_cast<clk_pll_param *>(ptr);
|
||||
R_UNLESS(entry->freq == entry->vco_max, ldr::ResultInvalidMemPllmEntry());
|
||||
Result MemFreqPllmLimit(u32* ptr) {
|
||||
clk_pll_param* entry = reinterpret_cast<clk_pll_param *>(ptr);
|
||||
R_UNLESS(entry->freq == entry->vco_max, ldr::ResultInvalidMemPllmEntry());
|
||||
|
||||
// Double the max clk simply
|
||||
u32 max_clk = entry->freq * 2;
|
||||
entry->freq = max_clk;
|
||||
entry->vco_max = max_clk;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result MemVoltHandler(u32* ptr) {
|
||||
// ptr value might be default_uv or max_uv
|
||||
regulator* entries[2] = {
|
||||
reinterpret_cast<regulator *>(reinterpret_cast<u8 *>(ptr) - offsetof(regulator, type_1.default_uv)),
|
||||
reinterpret_cast<regulator *>(reinterpret_cast<u8 *>(ptr) - offsetof(regulator, type_1.max_uv)),
|
||||
};
|
||||
|
||||
constexpr u32 uv_step = 12'500;
|
||||
constexpr u32 uv_min = 600'000;
|
||||
|
||||
auto validator = [](regulator* entry) {
|
||||
R_UNLESS(entry->id == 1, ldr::ResultInvalidRegulatorEntry());
|
||||
R_UNLESS(entry->type == 1, ldr::ResultInvalidRegulatorEntry());
|
||||
R_UNLESS(entry->type_1.volt_reg == 0x17, ldr::ResultInvalidRegulatorEntry());
|
||||
R_UNLESS(entry->type_1.step_uv == uv_step, ldr::ResultInvalidRegulatorEntry());
|
||||
R_UNLESS(entry->type_1.min_uv == uv_min, ldr::ResultInvalidRegulatorEntry());
|
||||
// Double the max clk simply
|
||||
u32 max_clk = entry->freq * 2;
|
||||
entry->freq = max_clk;
|
||||
entry->vco_max = max_clk;
|
||||
R_SUCCEED();
|
||||
};
|
||||
|
||||
regulator* entry = nullptr;
|
||||
for (auto& i : entries) {
|
||||
if (R_SUCCEEDED(validator(i)))
|
||||
entry = i;
|
||||
}
|
||||
|
||||
R_UNLESS(entry, ldr::ResultInvalidRegulatorEntry());
|
||||
Result MemVoltHandler(u32* ptr) {
|
||||
// ptr value might be default_uv or max_uv
|
||||
regulator* entries[2] = {
|
||||
reinterpret_cast<regulator *>(reinterpret_cast<u8 *>(ptr) - offsetof(regulator, type_1.default_uv)),
|
||||
reinterpret_cast<regulator *>(reinterpret_cast<u8 *>(ptr) - offsetof(regulator, type_1.max_uv)),
|
||||
};
|
||||
|
||||
u32 emc_uv = C.commonEmcMemVolt;
|
||||
if (!emc_uv)
|
||||
R_SKIP();
|
||||
|
||||
if (emc_uv % uv_step)
|
||||
emc_uv = emc_uv / uv_step * uv_step; // rounding
|
||||
|
||||
PATCH_OFFSET(ptr, emc_uv);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void SafetyCheck() {
|
||||
// if (C.custRev != CUST_REV)
|
||||
// CRASH("Triggered");
|
||||
|
||||
struct sValidator {
|
||||
volatile u32 value;
|
||||
u32 min;
|
||||
u32 max;
|
||||
bool value_required = false;
|
||||
|
||||
Result check() {
|
||||
if (!value_required && !value)
|
||||
R_SUCCEED();
|
||||
|
||||
if (min && value < min)
|
||||
R_THROW(ldr::ResultSafetyCheckFailure());
|
||||
if (max && value > max)
|
||||
R_THROW(ldr::ResultSafetyCheckFailure());
|
||||
constexpr u32 uv_step = 12'500;
|
||||
constexpr u32 uv_min = 600'000;
|
||||
|
||||
auto validator = [](regulator* entry) {
|
||||
R_UNLESS(entry->id == 1, ldr::ResultInvalidRegulatorEntry());
|
||||
R_UNLESS(entry->type == 1, ldr::ResultInvalidRegulatorEntry());
|
||||
R_UNLESS(entry->type_1.volt_reg == 0x17, ldr::ResultInvalidRegulatorEntry());
|
||||
R_UNLESS(entry->type_1.step_uv == uv_step, ldr::ResultInvalidRegulatorEntry());
|
||||
R_UNLESS(entry->type_1.min_uv == uv_min, ldr::ResultInvalidRegulatorEntry());
|
||||
R_SUCCEED();
|
||||
};
|
||||
|
||||
regulator* entry = nullptr;
|
||||
for (auto& i : entries) {
|
||||
if (R_SUCCEEDED(validator(i))) {
|
||||
entry = i;
|
||||
}
|
||||
}
|
||||
};
|
||||
u32 eristaCpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaCpuDvfsTable)->freq);
|
||||
u32 marikoCpuDvfsMaxFreq;
|
||||
if (C.marikoCpuUVHigh) {
|
||||
marikoCpuDvfsMaxFreq = static_cast<u32>(
|
||||
GetDvfsTableLastEntry(C.marikoCpuDvfsTableSLT)->freq
|
||||
);
|
||||
} else {
|
||||
marikoCpuDvfsMaxFreq = static_cast<u32>(
|
||||
GetDvfsTableLastEntry(C.marikoCpuDvfsTable)->freq
|
||||
);
|
||||
|
||||
R_UNLESS(entry, ldr::ResultInvalidRegulatorEntry());
|
||||
|
||||
u32 emc_uv = C.commonEmcMemVolt;
|
||||
if (!emc_uv) {
|
||||
R_SKIP();
|
||||
}
|
||||
u32 eristaGpuDvfsMaxFreq;
|
||||
switch (C.eristaGpuUV)
|
||||
{
|
||||
case 0:
|
||||
eristaGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaGpuDvfsTable)->freq);
|
||||
break;
|
||||
case 1:
|
||||
eristaGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaGpuDvfsTableSLT)->freq);
|
||||
break;
|
||||
case 2:
|
||||
eristaGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaGpuDvfsTableHiOPT)->freq);
|
||||
break;
|
||||
default:
|
||||
eristaGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaGpuDvfsTable)->freq);
|
||||
break;
|
||||
|
||||
if (emc_uv % uv_step) {
|
||||
emc_uv = emc_uv / uv_step * uv_step; // rounding
|
||||
}
|
||||
|
||||
PATCH_OFFSET(ptr, emc_uv);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
u32 marikoGpuDvfsMaxFreq;
|
||||
switch (C.marikoGpuUV) {
|
||||
void SafetyCheck() {
|
||||
// if (C.custRev != CUST_REV)
|
||||
// CRASH("Triggered");
|
||||
|
||||
struct sValidator {
|
||||
volatile u32 value;
|
||||
u32 min;
|
||||
u32 max;
|
||||
bool value_required = false;
|
||||
u32 panic;
|
||||
|
||||
Result check() {
|
||||
if (!value_required && !value)
|
||||
R_SUCCEED();
|
||||
|
||||
if (min && value < min)
|
||||
R_THROW(ldr::ResultSafetyCheckFailure());
|
||||
if (max && value > max)
|
||||
R_THROW(ldr::ResultSafetyCheckFailure());
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
};
|
||||
|
||||
u32 eristaCpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaCpuDvfsTable)->freq);
|
||||
u32 marikoCpuDvfsMaxFreq;
|
||||
if (C.marikoCpuUVHigh) {
|
||||
marikoCpuDvfsMaxFreq = static_cast<u32>(
|
||||
GetDvfsTableLastEntry(C.marikoCpuDvfsTableSLT)->freq
|
||||
);
|
||||
} else {
|
||||
marikoCpuDvfsMaxFreq = static_cast<u32>(
|
||||
GetDvfsTableLastEntry(C.marikoCpuDvfsTable)->freq
|
||||
);
|
||||
}
|
||||
u32 eristaGpuDvfsMaxFreq;
|
||||
switch (C.eristaGpuUV) {
|
||||
case 0:
|
||||
marikoGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq);
|
||||
eristaGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaGpuDvfsTable)->freq);
|
||||
break;
|
||||
case 1:
|
||||
marikoGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.marikoGpuDvfsTableSLT)->freq);
|
||||
eristaGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaGpuDvfsTableSLT)->freq);
|
||||
break;
|
||||
case 2:
|
||||
marikoGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.marikoGpuDvfsTableHiOPT)->freq);
|
||||
eristaGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaGpuDvfsTableHiOPT)->freq);
|
||||
break;
|
||||
default:
|
||||
marikoGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq);
|
||||
eristaGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.eristaGpuDvfsTable)->freq);
|
||||
break;
|
||||
}
|
||||
|
||||
u32 marikoGpuDvfsMaxFreq;
|
||||
switch (C.marikoGpuUV) {
|
||||
case 0:
|
||||
marikoGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq);
|
||||
break;
|
||||
case 1:
|
||||
marikoGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.marikoGpuDvfsTableSLT)->freq);
|
||||
break;
|
||||
case 2:
|
||||
marikoGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.marikoGpuDvfsTableHiOPT)->freq);
|
||||
break;
|
||||
default:
|
||||
marikoGpuDvfsMaxFreq = static_cast<u32>(GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq);
|
||||
break;
|
||||
}
|
||||
|
||||
using namespace ams::ldr::hoc::pcv;
|
||||
sValidator validators[] = {
|
||||
{ C.eristaCpuBoostClock, 1020'000, 2295'000, true, panic::Cpu },
|
||||
{ C.marikoCpuBoostClock, 1020'000, 2703'000, true, panic::Cpu },
|
||||
{ C.eristaCpuMaxVolt, 1000, 1260, false, panic::Cpu },
|
||||
{ C.marikoCpuMaxVolt, 1000, 1200, false, panic::Cpu },
|
||||
{ eristaCpuDvfsMaxFreq, 1785'000, 2295'000, false, panic::Cpu },
|
||||
{ marikoCpuDvfsMaxFreq, 1785'000, 2703'000, false, panic::Cpu },
|
||||
{ C.commonEmcMemVolt, 912'500, 1350'000, false, panic::Emc }, // Official burst vmax for the RAMs is 1500mV
|
||||
{ GET_MAX_OF_ARR(erista::maxEmcClocks), 1600'000, 2600'000, false, panic::Emc },
|
||||
{ C.marikoEmcMaxClock, 1600'000, 3500'000, false, panic::Emc },
|
||||
{ C.marikoEmcVddqVolt, 250'000, 700'000, false, panic::Emc },
|
||||
{ eristaGpuDvfsMaxFreq, 768'000, 1152'000, false, panic::Gpu },
|
||||
{ marikoGpuDvfsMaxFreq, 768'000, 1570'000, false, panic::Gpu },
|
||||
{ C.marikoGpuVmax, 800, 960, false, panic::Gpu },
|
||||
};
|
||||
|
||||
for (auto &v : validators) {
|
||||
if (R_FAILED(v.check())) {
|
||||
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
|
||||
panic::SmcError(v.panic);
|
||||
#endif
|
||||
|
||||
CRASH("Validation FAIL");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sValidator validators[] = {
|
||||
{ C.eristaCpuBoostClock, 1020'000, 2295'000, true },
|
||||
{ C.marikoCpuBoostClock, 1020'000, 2703'000, true },
|
||||
{ C.commonEmcMemVolt, 912'500, 1350'000 }, // Official burst vmax for the RAMs is 1500mV
|
||||
{ C.eristaCpuMaxVolt, 1000, 1257 },
|
||||
{ C.eristaEmcMaxClock, 1600'000, 2600'000 },
|
||||
{ C.marikoCpuMaxVolt, 1000, 1235 },
|
||||
{ C.marikoEmcMaxClock, 1600'000, 3500'000 },
|
||||
{ C.marikoEmcVddqVolt, 250'000, 700'000 },
|
||||
{ eristaCpuDvfsMaxFreq, 1785'000, 2295'000 },
|
||||
{ marikoCpuDvfsMaxFreq, 1785'000, 2703'000 },
|
||||
{ eristaGpuDvfsMaxFreq, 768'000, 1152'000 },
|
||||
{ marikoGpuDvfsMaxFreq, 768'000, 1536'000 },
|
||||
};
|
||||
|
||||
for (auto& i : validators) {
|
||||
if (R_FAILED(i.check()))
|
||||
CRASH("Validation FAIL");
|
||||
void Patch(uintptr_t mapped_nso, size_t nso_size) {
|
||||
#ifdef ATMOSPHERE_IS_STRATOSPHERE
|
||||
SafetyCheck();
|
||||
bool isMariko = (spl::GetSocType() == spl::SocType_Mariko);
|
||||
if (isMariko)
|
||||
mariko::Patch(mapped_nso, nso_size);
|
||||
else
|
||||
erista::Patch(mapped_nso, nso_size);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Patch(uintptr_t mapped_nso, size_t nso_size) {
|
||||
#ifdef ATMOSPHERE_IS_STRATOSPHERE
|
||||
SafetyCheck();
|
||||
bool isMariko = (spl::GetSocType() == spl::SocType_Mariko);
|
||||
if (isMariko)
|
||||
mariko::Patch(mapped_nso, nso_size);
|
||||
else
|
||||
erista::Patch(mapped_nso, nso_size);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "../oc_common.hpp"
|
||||
#include "pcv_common.hpp"
|
||||
|
||||
namespace ams::ldr::oc::pcv {
|
||||
namespace ams::ldr::hoc::pcv {
|
||||
|
||||
namespace mariko {
|
||||
constexpr cvb_entry_t CpuCvbTableDefault[] = {
|
||||
@@ -178,6 +178,9 @@ namespace ams::ldr::oc::pcv {
|
||||
}
|
||||
|
||||
namespace erista {
|
||||
static u32 maxEmcClocks[] = { C.eristaEmcMaxClock2, C.eristaEmcMaxClock1, C.eristaEmcMaxClock, };
|
||||
#define GET_MAX_OF_ARR(ARR) (*std::max_element(ARR, ARR + std::size(ARR)))
|
||||
|
||||
constexpr cvb_entry_t CpuCvbTableDefault[] = {
|
||||
// CPU_PLL_CVB_TABLE_ODN
|
||||
{ 204000, {721094}, { } },
|
||||
@@ -199,30 +202,34 @@ namespace ams::ldr::oc::pcv {
|
||||
{ },
|
||||
};
|
||||
|
||||
|
||||
constexpr u32 CpuVoltOfficial = 1235;
|
||||
constexpr u32 CpuVoltOfficial = 1227;
|
||||
|
||||
constexpr u32 CpuVminOfficial = 825;
|
||||
|
||||
constexpr u32 CpuVoltL4T = 1235'000;
|
||||
constexpr u32 CpuVoltL4T = 1257'000;
|
||||
|
||||
static const u32 cpuVoltDvfsPattern[] = { 1227, 1000, 100, 1000, 0 };
|
||||
static const u32 cpuVoltDvfsOffsets[] = { 5, 6, 7, 8, 9 };
|
||||
static_assert(sizeof(cpuVoltDvfsPattern) == sizeof(cpuVoltDvfsOffsets), "Invalid cpuVoltDvfsPattern");
|
||||
static_assert(sizeof(cpuVoltDvfsPattern) == 0x14, "invalid cpuVoltDvfsPattern size");
|
||||
|
||||
static const u32 cpuVoltageThermalPattern[] = { 950, 1132, 0, 950, 1227, 0, 825, 1227, 15000, 825, 1170, 60000, 825, 1132, 80000 };
|
||||
static_assert(sizeof(cpuVoltageThermalPattern) == 0x3c, "invalid cpuVoltageThermalPattern size");
|
||||
|
||||
constexpr u32 GpuClkPllLimit = 921'600'000;
|
||||
constexpr u32 GpuClkPllLimit = 2'600'000;
|
||||
constexpr u32 GpuClkPllMax = 921'600'000;
|
||||
constexpr u32 GpuVminOfficial = 810;
|
||||
|
||||
constexpr u16 CpuMinVolts[] = { 950, 850, 825, 810 };
|
||||
|
||||
inline bool CpuMaxVoltPatternFn(u32* ptr32) {
|
||||
u32 val = *ptr32;
|
||||
return (val == 1132 || val == 1170 || val == 1227);
|
||||
}
|
||||
|
||||
static const u32 gpuVoltDvfsPattern[] = { 810, 1150, 1000, 100, 1000, 10, };
|
||||
static_assert(sizeof(gpuVoltDvfsPattern) == (sizeof(u32) * 6), "Invalid gpuVoltDvfsPattern");
|
||||
|
||||
static const u32 gpuVoltThermalPattern[] = { 950, 1132, 0, 810, 1132, 15000, 810, 1132, 30000, 810, 1132, 50000, 810, 1132, 70000, 810, 1132, 105000 };
|
||||
static_assert(sizeof(gpuVoltThermalPattern) == 0x48, "invalid gpuVoltageThermalPattern size");
|
||||
|
||||
|
||||
/* GPU Max Clock asm Pattern:
|
||||
*
|
||||
* MOV W11, #0x1000 MOV (wide immediate) 0x1000 0xB (11)
|
||||
@@ -277,6 +284,7 @@ namespace ams::ldr::oc::pcv {
|
||||
};
|
||||
|
||||
constexpr u32 MemVoltHOS = 1125'000;
|
||||
constexpr u32 EmcClkMinFreq = 40800; /* 40.8 MHz table only exists on erista. */
|
||||
constexpr u32 EmcClkPllmLimit = 1866'000'000;
|
||||
|
||||
constexpr u32 MTC_TABLE_REV = 7;
|
||||
|
||||
@@ -16,153 +16,154 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
namespace ams::ldr::oc::pcv {
|
||||
namespace ams::ldr::hoc::pcv {
|
||||
|
||||
typedef struct cvb_coefficients {
|
||||
s32 c0 = 0;
|
||||
s32 c1 = 0;
|
||||
s32 c2 = 0;
|
||||
s32 c3 = 0;
|
||||
s32 c4 = 0;
|
||||
s32 c5 = 0;
|
||||
} cvb_coefficients;
|
||||
typedef struct cvb_coefficients {
|
||||
s32 c0 = 0;
|
||||
s32 c1 = 0;
|
||||
s32 c2 = 0;
|
||||
s32 c3 = 0;
|
||||
s32 c4 = 0;
|
||||
s32 c5 = 0;
|
||||
} cvb_coefficients;
|
||||
|
||||
typedef struct cvb_entry_t {
|
||||
u64 freq;
|
||||
cvb_coefficients cvb_dfll_param;
|
||||
cvb_coefficients cvb_pll_param;
|
||||
} cvb_entry_t;
|
||||
static_assert(sizeof(cvb_entry_t) == 0x38);
|
||||
typedef struct cvb_entry_t {
|
||||
u64 freq;
|
||||
cvb_coefficients cvb_dfll_param;
|
||||
cvb_coefficients cvb_pll_param;
|
||||
} cvb_entry_t;
|
||||
static_assert(sizeof(cvb_entry_t) == 0x38);
|
||||
|
||||
typedef struct cvb_cpu_dfll_data {
|
||||
u32 tune0_low;
|
||||
u32 tune0_high;
|
||||
u32 tune1_low;
|
||||
u32 tune1_high;
|
||||
unsigned int tune_high_min_millivolts;
|
||||
unsigned int tune_high_margin_millivolts;
|
||||
unsigned long dvco_calibration_max;
|
||||
} cvb_cpu_dfll_data;
|
||||
typedef struct cvb_cpu_dfll_data {
|
||||
u32 tune0_low;
|
||||
u32 tune0_high;
|
||||
u32 tune1_low;
|
||||
u32 tune1_high;
|
||||
unsigned int tune_high_min_millivolts;
|
||||
unsigned int tune_high_margin_millivolts;
|
||||
unsigned long dvco_calibration_max;
|
||||
} cvb_cpu_dfll_data;
|
||||
|
||||
typedef struct emc_dvb_dvfs_table_t {
|
||||
u64 freq;
|
||||
s32 volt[4] = {0};
|
||||
} emc_dvb_dvfs_table_t;
|
||||
typedef struct emc_dvb_dvfs_table_t {
|
||||
u64 freq;
|
||||
s32 volt[4] = {0};
|
||||
} emc_dvb_dvfs_table_t;
|
||||
|
||||
typedef struct __attribute__((packed)) div_nmp {
|
||||
u8 divn_shift;
|
||||
u8 divn_width;
|
||||
u8 divm_shift;
|
||||
u8 divm_width;
|
||||
u8 divp_shift;
|
||||
u8 divp_width;
|
||||
u8 override_divn_shift;
|
||||
u8 override_divm_shift;
|
||||
u8 override_divp_shift;
|
||||
} div_nmp;
|
||||
typedef struct __attribute__((packed)) div_nmp {
|
||||
u8 divn_shift;
|
||||
u8 divn_width;
|
||||
u8 divm_shift;
|
||||
u8 divm_width;
|
||||
u8 divp_shift;
|
||||
u8 divp_width;
|
||||
u8 override_divn_shift;
|
||||
u8 override_divm_shift;
|
||||
u8 override_divp_shift;
|
||||
} div_nmp;
|
||||
|
||||
typedef struct __attribute__((packed)) clk_pll_param {
|
||||
u32 freq;
|
||||
u32 input_min;
|
||||
u32 input_max;
|
||||
u32 cf_min;
|
||||
u32 cf_max;
|
||||
u32 vco_min;
|
||||
u32 vco_max;
|
||||
s32 lock_delay;
|
||||
u32 fixed_rate;
|
||||
u32 unk_0;
|
||||
struct div_nmp *div_nmp;
|
||||
u32 unk_1[4];
|
||||
void (*unk_fn)(u64* unk_struct); // set_defaults?
|
||||
} clk_pll_param;
|
||||
typedef struct __attribute__((packed)) clk_pll_param {
|
||||
u32 freq;
|
||||
u32 input_min;
|
||||
u32 input_max;
|
||||
u32 cf_min;
|
||||
u32 cf_max;
|
||||
u32 vco_min;
|
||||
u32 vco_max;
|
||||
s32 lock_delay;
|
||||
u32 fixed_rate;
|
||||
u32 unk_0;
|
||||
struct div_nmp *div_nmp;
|
||||
u32 unk_1[4];
|
||||
void (*unk_fn)(u64* unk_struct); // set_defaults?
|
||||
} clk_pll_param;
|
||||
|
||||
typedef struct __attribute__((packed)) dvfs_rail {
|
||||
u32 id;
|
||||
u32 unk_0[5];
|
||||
u32 freq;
|
||||
u32 unk_1[8];
|
||||
u32 unk_flag;
|
||||
u32 min_mv;
|
||||
u32 step_mv;
|
||||
u32 max_mv;
|
||||
u32 unk_2[11];
|
||||
} dvfs_rail;
|
||||
typedef struct __attribute__((packed)) dvfs_rail {
|
||||
u32 id;
|
||||
u32 unk_0[5];
|
||||
u32 freq;
|
||||
u32 unk_1[8];
|
||||
u32 unk_flag;
|
||||
u32 min_mv;
|
||||
u32 step_mv;
|
||||
u32 max_mv;
|
||||
u32 unk_2[11];
|
||||
} dvfs_rail;
|
||||
|
||||
typedef struct __attribute__((packed)) regulator {
|
||||
u64 id;
|
||||
const char* name;
|
||||
u32 type;
|
||||
union {
|
||||
struct {
|
||||
u32 volt_reg;
|
||||
u32 step_uv;
|
||||
u32 min_uv;
|
||||
u32 default_uv;
|
||||
u32 max_uv;
|
||||
u32 unk_0[2];
|
||||
} type_1;
|
||||
struct {
|
||||
u32 unk_0;
|
||||
u32 step_uv;
|
||||
u32 unk_1;
|
||||
u32 min_uv;
|
||||
u32 max_uv;
|
||||
u32 unk_2;
|
||||
u32 default_uv;
|
||||
} type_2_3;
|
||||
};
|
||||
u32 unk_x[60];
|
||||
} regulator;
|
||||
static_assert(sizeof(regulator) == 0x120);
|
||||
typedef struct __attribute__((packed)) regulator {
|
||||
u64 id;
|
||||
const char* name;
|
||||
u32 type;
|
||||
union {
|
||||
struct {
|
||||
u32 volt_reg;
|
||||
u32 step_uv;
|
||||
u32 min_uv;
|
||||
u32 default_uv;
|
||||
u32 max_uv;
|
||||
u32 unk_0[2];
|
||||
} type_1;
|
||||
struct {
|
||||
u32 unk_0;
|
||||
u32 step_uv;
|
||||
u32 unk_1;
|
||||
u32 min_uv;
|
||||
u32 max_uv;
|
||||
u32 unk_2;
|
||||
u32 default_uv;
|
||||
} type_2_3;
|
||||
};
|
||||
u32 unk_x[60];
|
||||
} regulator;
|
||||
static_assert(sizeof(regulator) == 0x120);
|
||||
|
||||
constexpr u32 CpuClkOSLimit = 1785'000;
|
||||
constexpr u32 CpuClkOSLimit = 1785'000;
|
||||
|
||||
constexpr u32 EmcClkOSLimit = 1600'000;
|
||||
constexpr u32 EmcClkOSLimit = 1600'000;
|
||||
|
||||
#define R_SKIP() R_SUCCEED()
|
||||
#define R_SKIP() R_SUCCEED()
|
||||
|
||||
// Count 32 / Index 31 is reserved to be empty
|
||||
constexpr size_t DvfsTableEntryCount = 32;
|
||||
constexpr size_t DvfsTableEntryLimit = DvfsTableEntryCount - 1;
|
||||
// Count 32 / Index 31 is reserved to be empty
|
||||
constexpr size_t DvfsTableEntryCount = 32;
|
||||
constexpr size_t DvfsTableEntryLimit = DvfsTableEntryCount - 1;
|
||||
|
||||
template<typename T>
|
||||
size_t GetDvfsTableEntryCount(T* table_head) {
|
||||
using NT = std::remove_const_t<std::remove_volatile_t<T>>;
|
||||
template<typename T>
|
||||
size_t GetDvfsTableEntryCount(T* table_head) {
|
||||
using NT = std::remove_const_t<std::remove_volatile_t<T>>;
|
||||
|
||||
auto is_empty = [](NT* entry) {
|
||||
uint8_t* m = reinterpret_cast<uint8_t *>(entry);
|
||||
for (size_t i = 0; i < sizeof(NT); i++) {
|
||||
if (*(m + i))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
auto is_empty = [](NT* entry) {
|
||||
uint8_t* m = reinterpret_cast<uint8_t *>(entry);
|
||||
for (size_t i = 0; i < sizeof(NT); i++) {
|
||||
if (*(m + i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
NT* table = const_cast<NT *>(table_head);
|
||||
size_t count = 0;
|
||||
while (count < DvfsTableEntryLimit) {
|
||||
if (is_empty(table++)) {
|
||||
return count;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return DvfsTableEntryLimit;
|
||||
}
|
||||
NT* table = const_cast<NT *>(table_head);
|
||||
size_t count = 0;
|
||||
while (count < DvfsTableEntryLimit) {
|
||||
if (is_empty(table++)) {
|
||||
return count;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return DvfsTableEntryLimit;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* GetDvfsTableLastEntry(T* table_head) {
|
||||
using NT = std::remove_const_t<std::remove_volatile_t<T>>;
|
||||
template<typename T>
|
||||
T* GetDvfsTableLastEntry(T* table_head) {
|
||||
using NT = std::remove_const_t<std::remove_volatile_t<T>>;
|
||||
|
||||
NT* table = const_cast<NT *>(table_head);
|
||||
size_t count = GetDvfsTableEntryCount(table_head);
|
||||
if (!count) {
|
||||
return nullptr;
|
||||
}
|
||||
size_t index = count - 1;
|
||||
return table + index;
|
||||
}
|
||||
NT* table = const_cast<NT *>(table_head);
|
||||
size_t count = GetDvfsTableEntryCount(table_head);
|
||||
if (!count) {
|
||||
return nullptr;
|
||||
}
|
||||
size_t index = count - 1;
|
||||
return table + index;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,27 +20,28 @@
|
||||
|
||||
#include "pcv.hpp"
|
||||
#include "../mtc_timing_value.hpp"
|
||||
#include "../erista/calculate_timings_erista.hpp"
|
||||
|
||||
namespace ams::ldr::oc::pcv::erista {
|
||||
namespace ams::ldr::hoc::pcv::erista {
|
||||
|
||||
Result CpuVoltDvfs(u32 *ptr) {
|
||||
if (MatchesPattern(ptr, cpuVoltDvfsPattern, cpuVoltDvfsOffsets)) {
|
||||
if (C.eristaCpuVmin) {
|
||||
PATCH_OFFSET(ptr, C.eristaCpuVmin);
|
||||
}
|
||||
|
||||
if (C.eristaCpuUV) {
|
||||
PATCH_OFFSET(ptr - 2, C.eristaCpuVmin);
|
||||
}
|
||||
|
||||
if (C.eristaCpuMaxVolt) {
|
||||
PATCH_OFFSET(ptr + 5, C.eristaCpuMaxVolt);
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
if (std::memcmp(ptr + 5, cpuVoltDvfsPattern, sizeof(cpuVoltDvfsPattern))) {
|
||||
R_THROW(ldr::ResultInvalidCpuMinVolt());
|
||||
}
|
||||
|
||||
R_THROW(ldr::ResultInvalidCpuMinVolt());
|
||||
if (C.eristaCpuVmin) {
|
||||
PATCH_OFFSET(ptr, C.eristaCpuVmin);
|
||||
}
|
||||
|
||||
if (C.eristaCpuUV) {
|
||||
PATCH_OFFSET(ptr - 2, C.eristaCpuVmin);
|
||||
}
|
||||
|
||||
if (C.eristaCpuMaxVolt) {
|
||||
PATCH_OFFSET(ptr + 5, C.eristaCpuMaxVolt);
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result CpuVoltThermals(u32 *ptr) {
|
||||
@@ -51,7 +52,7 @@ namespace ams::ldr::oc::pcv::erista {
|
||||
if (C.eristaCpuVmin) {
|
||||
PATCH_OFFSET( ptr, C.eristaCpuVmin);
|
||||
PATCH_OFFSET(ptr + 3, C.eristaCpuVmin);
|
||||
PATCH_OFFSET(ptr + 9, C.eristaCpuVmin);
|
||||
PATCH_OFFSET(ptr + 6, C.eristaCpuVmin);
|
||||
}
|
||||
|
||||
if (C.eristaCpuMaxVolt) {
|
||||
@@ -66,12 +67,12 @@ namespace ams::ldr::oc::pcv::erista {
|
||||
|
||||
Result CpuVoltDfll(u32* ptr) {
|
||||
cvb_cpu_dfll_data *entry = reinterpret_cast<cvb_cpu_dfll_data *>(ptr);
|
||||
R_UNLESS(entry->tune0_low == 0xFFEAD0FF, ldr::ResultInvalidCpuVoltDfllEntry());
|
||||
R_UNLESS(entry->tune0_high == 0x0, ldr::ResultInvalidCpuVoltDfllEntry());
|
||||
R_UNLESS(entry->tune1_low == 0x0, ldr::ResultInvalidCpuVoltDfllEntry());
|
||||
R_UNLESS(entry->tune1_high == 0x0, ldr::ResultInvalidCpuVoltDfllEntry());
|
||||
R_UNLESS(entry->tune0_low == 0xFFEAD0FF, ldr::ResultInvalidCpuVoltDfllEntry());
|
||||
R_UNLESS(entry->tune0_high == 0x0, ldr::ResultInvalidCpuVoltDfllEntry());
|
||||
R_UNLESS(entry->tune1_low == 0x0, ldr::ResultInvalidCpuVoltDfllEntry());
|
||||
R_UNLESS(entry->tune1_high == 0x0, ldr::ResultInvalidCpuVoltDfllEntry());
|
||||
|
||||
if( !C.eristaCpuUV) {
|
||||
if (!C.eristaCpuUV) {
|
||||
R_SKIP();
|
||||
}
|
||||
|
||||
@@ -103,20 +104,19 @@ namespace ams::ldr::oc::pcv::erista {
|
||||
}
|
||||
|
||||
Result GpuVoltDVFS(u32 *ptr) {
|
||||
u32 result = std::memcmp(ptr, gpuVoltDvfsPattern, sizeof(gpuVoltDvfsPattern));
|
||||
|
||||
if (result)
|
||||
if (std::memcmp(ptr, gpuVoltDvfsPattern, sizeof(gpuVoltDvfsPattern))) {
|
||||
R_THROW(ldr::ResultInvalidGpuDvfs());
|
||||
}
|
||||
|
||||
if (C.eristaGpuVmin)
|
||||
if (C.eristaGpuVmin) {
|
||||
PATCH_OFFSET(ptr, C.eristaGpuVmin);
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GpuVoltThermals(u32 *ptr) {
|
||||
u32 result = std::memcmp(ptr - 3, gpuVoltThermalPattern, sizeof(gpuVoltThermalPattern));
|
||||
if (result) {
|
||||
if (std::memcmp(ptr - 3, gpuVoltThermalPattern, sizeof(gpuVoltThermalPattern))) {
|
||||
R_THROW(ldr::ResultInvalidGpuDvfs());
|
||||
}
|
||||
|
||||
@@ -166,339 +166,19 @@ namespace ams::ldr::oc::pcv::erista {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GpuFreqPllLimit(u32 *ptr) {
|
||||
clk_pll_param *entry = reinterpret_cast<clk_pll_param *>(ptr);
|
||||
|
||||
// All zero except for freq
|
||||
for (size_t i = 1; i < sizeof(clk_pll_param) / sizeof(u32); i++) {
|
||||
R_UNLESS(*(ptr + i) == 0, ldr::ResultInvalidGpuPllEntry());
|
||||
}
|
||||
|
||||
// Double the max clk simply
|
||||
u32 max_clk = entry->freq * 2;
|
||||
entry->freq = max_clk;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
// void MemMtcTableAutoAdjustBaseLatency(EristaMtcTable *table) {
|
||||
// using namespace pcv::erista;
|
||||
/* #define WRITE_PARAM_ALL_REG(TABLE, PARAM, VALUE) \
|
||||
TABLE->burst_regs.PARAM = VALUE; \
|
||||
TABLE->shadow_regs_ca_train.PARAM = VALUE; \
|
||||
TABLE->shadow_regs_quse_train.PARAM = VALUE; \
|
||||
TABLE->shadow_regs_rdwr_train.PARAM = VALUE;
|
||||
*/
|
||||
// #define GET_CYCLE(PARAM) ((u32)((double)(PARAM) / tCK_avg))
|
||||
|
||||
/* This condition is insane but it's done in eos. */
|
||||
/* Need to clean up at some point. */
|
||||
// u32 rext;
|
||||
// u32 wext;
|
||||
// if (C.eristaEmcMaxClock < 3200001) {
|
||||
// if (C.eristaEmcMaxClock < 2133001) {
|
||||
// rext = 26;
|
||||
// wext = 22;
|
||||
// } else {
|
||||
// rext = 28;
|
||||
// wext = 22;
|
||||
//
|
||||
// if (2400000 < C.eristaEmcMaxClock) {
|
||||
// wext = 25;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// rext = 30;
|
||||
// wext = 25;
|
||||
// }
|
||||
|
||||
// u32 refresh_raw = 0xFFFF;
|
||||
// u32 trefbw = 0;
|
||||
//
|
||||
// if (C.t8_tREFI != 6) {
|
||||
// refresh_raw = static_cast<u32>(std::floor(static_cast<double>(tREFpb_values[C.t8_tREFI]) / tCK_avg)) - 0x40;
|
||||
// refresh_raw = MIN(refresh_raw, static_cast<u32>(0xFFFF));
|
||||
// }
|
||||
//
|
||||
// trefbw = refresh_raw + 0x40;
|
||||
// trefbw = MIN(trefbw, static_cast<u32>(0x3FFF));
|
||||
//
|
||||
// if (C.hpMode) {
|
||||
// WRITE_PARAM_ALL_REG(table, emc_cfg, 0x13200000);
|
||||
// } else {
|
||||
// WRITE_PARAM_ALL_REG(table, emc_cfg, 0xF3200000);
|
||||
// }
|
||||
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rc, /*0x00000060*/ GET_CYCLE(tRC));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rfc, /*0x00000120*/ GET_CYCLE(tRFCab));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_ras, /*0x00000044*/ GET_CYCLE(tRAS));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rp, /*0x0000001D*/ GET_CYCLE(tRPpb));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_r2w, /*0x0000002A*/ tR2W);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_w2r, /*0x00000021*/ tW2R);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_r2p, 0x0000000C);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_w2p, 0x0000002D);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rd_rcd, /*0x0000001D*/ GET_CYCLE(tRCD));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wr_rcd, /*0x0000001D*/ GET_CYCLE(tRCD));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rrd, /*0x00000010*/ GET_CYCLE(tRRD));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rext, 0x00000017);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wdv, 0x0000000E);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_quse, 0x00000024);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_qrst, 0x0006000C);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_qsafe, 0x00000034);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rdv, 0x0000003C);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_refresh, /*0x00001820*/ refresh_raw);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_burst_refresh_num, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pdex2wr, 0x00000010);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pdex2rd, 0x00000010);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pchg2pden, 0x00000003);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_act2pden, 0x00000003);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_ar2pden, 0x00000003);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rw2pden, /*0x00000038*/ GET_CYCLE(tRW2PDEN));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_txsr, /*0x0000012C*/ MIN(GET_CYCLE(tXSR), (u32) 1022));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tcke, 0x0000000D);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tfaw, /*0x00000040*/ GET_CYCLE(tFAW));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_trpab, /*0x00000022*/ GET_CYCLE(tRPab));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tclkstable, 0x00000004);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tclkstop, 0x00000014);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_trefbw, /* 0x00001860*/ trefbw);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tppd, 0x00000004);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_odt_write, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pdex2mrr, /*0x0000002E*/ GET_CYCLE(pdex2mrr));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wext, 0x00000016);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rfc_slr, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_mrs_wait_cnt2, 0x01900017);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_mrs_wait_cnt, 0x0640002F);
|
||||
// // table->emc_mrs = 0x00000000;
|
||||
// // table->emc_emrs = 0x00000000;
|
||||
// // table->emc_mrw = 0x00170040;
|
||||
// WRITE_PARAM_ALL_REG(table, emc_fbio_spare, 0x00000012);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_fbio_cfg5, 0x9960A00D);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pdex2cke, 0x00000002);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_cke2pden, 0x0000000E);
|
||||
// // table->emc_emrs2 = 0x00000000;
|
||||
// // table->emc_mrw2 = 0x0802002D;
|
||||
// // table->emc_mrw3 = 0x0C0D00C0;
|
||||
// // table->emc_mrw4 = 0xC0000000;
|
||||
// WRITE_PARAM_ALL_REG(table, emc_r2r, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_einput, 0x00000014);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_einput_duration, 0x0000001D);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_puterm_extra, 0x0000001F);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tckesr, 0x00000018);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tpd, 0x0000000C);
|
||||
// table->emc_auto_cal_config = 0x201A51D8;
|
||||
// table->emc_cfg_2 = 0x00110835;
|
||||
// WRITE_PARAM_ALL_REG(table, emc_cfg_dig_dll, 0x002C03A9);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_cfg_dig_dll_period, 0x00008000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rdv_mask, 0x0000003E);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wdv_mask, 0x0000000E);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rdv_early_mask, 0x0000003C);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rdv_early, 0x0000003A);
|
||||
// table->emc_auto_cal_config8 = 0x00770000;
|
||||
// WRITE_PARAM_ALL_REG(table, emc_zcal_interval, 0x00064000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_zcal_wait_cnt, 0x00310640);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_fdpd_ctrl_dq, 0x8020221F);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_fdpd_ctrl_cmd, 0x0220F40F);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_cmd_brick_ctrl_fdpd, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_data_brick_ctrl_fdpd, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_brick_ctrl_rfu1, 0x1FFF1FFF);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_brick_ctrl_rfu2, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_timing_0, 0x01186190);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_tr_ctrl_1, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_rdv, 0x0000003C);
|
||||
// table->emc_sel_dpd_ctrl = 0x00040000;
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pre_refresh_req_cnt, /*0x00000608*/ (u32) (refresh_raw / 4));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_dyn_self_ref_control, 0x8000308C);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_txsrdll, /*0x0000012C*/ MIN(GET_CYCLE(tXSR), (u32) 1022));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_qpop, 0x0000002C);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_rdv_mask, 0x0000003E);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_qsafe, 0x00000034);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_qrst, 0x0006000C);
|
||||
// table->emc_auto_cal_config2 = 0x05500000;
|
||||
// table->emc_auto_cal_config3 = 0x00770000;
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_tr_dvfs, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_auto_cal_channel, 0xC1E0030A);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_ibdly, 0x1000001C);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_obdly, 0x10000002);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_txdsrvttgen, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_we_duration, 0x0000000D);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_ws_duration, 0x00000008);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wev, 0x0000000A);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wsv, 0x0000000C);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_cfg_3, 0x00000040);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_mrw6, 0x08037171);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_mrw7, 0x48037171);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_mrw8, 0x080B6666);
|
||||
// // table->emc_mrw9 = 0x0C0E7272;
|
||||
// // table->emc_mrw10 = 0x880C4848;
|
||||
// // table->emc_mrw11 = 0x480C4848; /* Check them maybe */
|
||||
// // table->emc_mrw12 = 0x880E1718;
|
||||
// // table->emc_mrw13 = 0x480E1814;
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_mrw14, 0x08161414);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_mrw15, 0x48161414);
|
||||
// // table->emc_fdpd_ctrl_cmd_no_ramp = 0x00000001;
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wdv_chk, 0x00000006);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_cfg_pipe_2, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_cfg_pipe_1, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_cfg_pipe, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_qpop, 0x0000002C);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_quse_width, 0x00000009);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_puterm_width, 0x0000000E);
|
||||
// table->emc_auto_cal_config7 = 0x00770000;
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_refctrl2, 0x00000000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_fbio_cfg7, 0x00003BFF);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rfcpb, /*0x00000090*/ GET_CYCLE(tRFCpb));
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_dqs_brlshft_0, 0x00000000); /* brlshft may or may not be important, I don't think it matters but who knows. */
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_dqs_brlshft_1, 0x00000000);
|
||||
// table->emc_auto_cal_config4 = 0x00770000;
|
||||
// table->emc_auto_cal_config5 = 0x00770000;
|
||||
// WRITE_PARAM_ALL_REG(table, emc_ccdmw, 0x00000020);
|
||||
// table->emc_auto_cal_config6 = 0x00770000;
|
||||
// WRITE_PARAM_ALL_REG(table, emc_dll_cfg_0, 0x1F13612F);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_dll_cfg_1, 0x00000014);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_config_sample_delay, 0x00000020);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_tx_pwrd_0, 0x10000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_tx_pwrd_1, 0x08000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_tx_pwrd_2, 0x08000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_tx_pwrd_3, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_tx_pwrd_4, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_tx_pwrd_5, 0x00001000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_bypass, 0xEFFF2210);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_pwrd_0, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_pwrd_1, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_pwrd_2, 0xDCDCDCDC);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_cmd_ctrl_0, 0x0A0A0A0A);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_cmd_ctrl_1, 0x0A0A0A0A);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_cmd_ctrl_2, 0x000A0A0A);
|
||||
// // table->trim_regs.emc_pmacro_ib_vref_dq_0 = 0x15171414;
|
||||
// // table->trim_regs.emc_pmacro_ib_vref_dq_1 = 0x15131513;
|
||||
// // table->trim_regs.emc_pmacro_ib_vref_dqs_0 = 0x11111111;
|
||||
// // table->trim_regs.emc_pmacro_ib_vref_dqs_1 = 0x11111111;
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_long_cmd_0, 0x000C000C);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_long_cmd_1, 0x000B000B);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_long_cmd_2, 0x000A000A);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_long_cmd_3, 0x000C000C);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_long_cmd_4, 0x0000000C);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_short_cmd_0, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_short_cmd_1, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ddll_short_cmd_2, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_vttgen_ctrl_0, 0x00030808);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_vttgen_ctrl_1, 0x00015C00);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_bg_bias_ctrl_0, 0x00000034);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_pad_cfg_ctrl, 0x00020000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_zctrl, 0x00000550);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_cmd_pad_rx_ctrl, 0x00000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_data_pad_rx_ctrl, 0x00000033);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_cmd_rx_term_mode, 0x00003000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_data_rx_term_mode, 0x00000011);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_cmd_pad_tx_ctrl, 0x02000000);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_data_pad_tx_ctrl, 0x02000101);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_common_pad_tx_ctrl, 0x00000007);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_autocal_cfg_common, 0x0000080D);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_vttgen_ctrl_2, 0x00102020);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_pmacro_ib_rxrt, 0x00000055);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_ctrl, 0x00009080);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_quse_cors_ctrl, 0x01124000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_quse_fine_ctrl, 0x01125B6A);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_quse_ctrl_misc, 0x0F081000);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_write_fine_ctrl, 0x1114FC00);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_write_ctrl_misc, 0x07004300);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_write_vref_ctrl, 0x00103200);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_read_fine_ctrl, 0x1110FC00);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_read_ctrl_misc, 0x0F085300);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_read_vref_ctrl, 0x00105800);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_ca_fine_ctrl, 0x0513801F);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_ca_ctrl_misc, 0x1F101100);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_ca_ctrl_misc1, 0x00000014);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_ca_vref_ctrl, 0x00103200);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_training_settle, 0x07070404);
|
||||
// // WRITE_PARAM_ALL_REG(table, emc_training_mpc, 0x00000000);
|
||||
//
|
||||
// const u32 mc_tRCD = (int) ((double) (GET_CYCLE(tRCD) >> 2) - 2.0);
|
||||
// const u32 mc_tRPpb = (int) (((double) (GET_CYCLE(tRPpb) >> 2) - 1.0) + 2.0);
|
||||
// const u32 mc_tRC = (uint) ((double) (GET_CYCLE(tRC) >> 2) - 1.0);
|
||||
// const u32 mc_tR2W = (uint) (((double) ((uint)tR2W >> 2) - 1.0) + 2.0);
|
||||
// const u32 mc_tW2R = (uint) (((double) (tW2R >> 2) - 1.0) + 2.0);
|
||||
// const u32 mc_tRAS = MIN(GET_CYCLE(tRAS), (u32) 0x7F);
|
||||
// const u32 mc_tRRD = MIN(GET_CYCLE(tRRD), (u32) 31);
|
||||
//
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_ras = (int) ((double) (mc_tRAS >> 2) - 2.0);
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_rcd = (int) ((double) (GET_CYCLE(tRCD) >> 2) - 2.0);
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_rp = (int) (((double) (GET_CYCLE(tRPpb) >> 2) - 1.0) + 2.0);
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_rc = (int) ((double) (GET_CYCLE(tRC) >> 2) - 1.0);
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_faw = (int) ((double) (GET_CYCLE(tFAW) >> 2) - 1.0);
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_rrd = (int) ((double) (mc_tRRD >> 2) - 1.0);
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_r2w = (uint) (((double) ((uint) tR2W >> 2) - 1.0) + 2.0);
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_w2r = (uint) (((double) (tW2R >> 2) - 1.0) + 2.0);
|
||||
//
|
||||
// table->burst_mc_regs.mc_emem_arb_da_turns = (table->burst_mc_regs.mc_emem_arb_da_turns & 0x0000FFFF) | (mc_tW2R << 24) | (mc_tR2W << 16);
|
||||
// table->burst_mc_regs.mc_emem_arb_da_covers = (((uint) (mc_tRCD + 3 + mc_tRPpb) >> 1 & 0xff) << 8) | (((uint) (mc_tRCD + 11 + mc_tRPpb) >> 1 & 0xff) << 0x10) | ((mc_tRC >> 1) & 0xff);
|
||||
// table->burst_mc_regs.mc_emem_arb_misc0 = (table->burst_mc_regs.mc_emem_arb_misc0 & 0xffe08000U) | ((mc_tRC + 1) & 0xff); /* Missing in l4t dump? TODO */
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_rfcpb = GET_CYCLE(tRFCpb) >> 2;
|
||||
//
|
||||
// table->burst_mc_regs.mc_emem_arb_cfg = 0x0000000c;
|
||||
// // table->burst_mc_regs.mc_emem_arb_timing_rcd = 0x00000006;
|
||||
// // table->burst_mc_regs.mc_emem_arb_timing_rp = 0x00000007;
|
||||
// // table->burst_mc_regs.mc_emem_arb_timing_rc = 0x00000018;
|
||||
// // table->burst_mc_regs.mc_emem_arb_timing_ras = 0x0000000f;
|
||||
// // table->burst_mc_regs.mc_emem_arb_timing_faw = 0x0000000f;
|
||||
// // table->burst_mc_regs.mc_emem_arb_timing_rrd = 0x00000003;
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_rap2pre = 0x00000003;
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_wap2pre = 0x0000000d;
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_r2r = 0x00000007;
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_w2w = 0x00000007;
|
||||
// // table->burst_mc_regs.mc_emem_arb_timing_r2w = 0x0000000c;
|
||||
// // table->burst_mc_regs.mc_emem_arb_timing_w2r = 0x0000000a;
|
||||
// // table->burst_mc_regs.mc_emem_arb_da_turns = 0x05060303;
|
||||
// // table->burst_mc_regs.mc_emem_arb_da_covers = 0x000d080c;
|
||||
// table->burst_mc_regs.mc_emem_arb_ring1_throttle = 0x001f0000;
|
||||
// // table->burst_mc_regs.mc_emem_arb_timing_rfcpb = 0x00000023;
|
||||
// table->burst_mc_regs.mc_emem_arb_timing_ccdmw = 0x00000008;
|
||||
// table->burst_mc_regs.mc_emem_arb_refpb_hp_ctrl = 0x000a1020;
|
||||
// table->burst_mc_regs.mc_emem_arb_refpb_bank_ctrl = 0x80001028;
|
||||
// // table->burst_mc_regs.mc_emem_arb_dhyst_ctrl = 0x00000002;
|
||||
// table->burst_mc_regs.mc_emem_arb_dhyst_timeout_util_0 = 0x0000001a;
|
||||
// table->burst_mc_regs.mc_emem_arb_dhyst_timeout_util_1 = 0x0000001a;
|
||||
// table->burst_mc_regs.mc_emem_arb_dhyst_timeout_util_2 = 0x0000001a;
|
||||
// table->burst_mc_regs.mc_emem_arb_dhyst_timeout_util_3 = 0x0000001a;
|
||||
// table->burst_mc_regs.mc_emem_arb_dhyst_timeout_util_4 = 0x0000001a;
|
||||
// table->burst_mc_regs.mc_emem_arb_dhyst_timeout_util_5 = 0x0000001a;
|
||||
// table->burst_mc_regs.mc_emem_arb_dhyst_timeout_util_6 = 0x0000001a;
|
||||
// table->burst_mc_regs.mc_emem_arb_dhyst_timeout_util_7 = 0x0000001a;
|
||||
// table->la_scale_regs.mc_mll_mpcorer_ptsa_rate = 0x000000d0;
|
||||
// table->la_scale_regs.mc_ftop_ptsa_rate = 0x00000018;
|
||||
// table->la_scale_regs.mc_ptsa_grant_decrement = 0x00001203;
|
||||
// table->la_scale_regs.mc_latency_allowance_avpc_0 = 0x00800004;
|
||||
// table->la_scale_regs.mc_latency_allowance_xusb_1 = 0x00800038;
|
||||
// table->la_scale_regs.mc_latency_allowance_sdmmcaa_0 = 0x00800005;
|
||||
// table->la_scale_regs.mc_latency_allowance_sdmmca_0 = 0x00800014;
|
||||
// table->la_scale_regs.mc_latency_allowance_isp2_0 = 0x0000002c;
|
||||
// table->la_scale_regs.mc_latency_allowance_isp2_1 = 0x00800080;
|
||||
// table->la_scale_regs.mc_latency_allowance_vic_0 = 0x0080001d;
|
||||
// table->la_scale_regs.mc_latency_allowance_nvdec_0 = 0x00800095;
|
||||
// table->la_scale_regs.mc_latency_allowance_tsec_0 = 0x00800041;
|
||||
// table->la_scale_regs.mc_latency_allowance_ppcs_1 = 0x00800080;
|
||||
// table->la_scale_regs.mc_latency_allowance_xusb_0 = 0x0080003d;
|
||||
// table->la_scale_regs.mc_latency_allowance_ppcs_0 = 0x00340049;
|
||||
// table->la_scale_regs.mc_latency_allowance_gpu2_0 = 0x00800019;
|
||||
// table->la_scale_regs.mc_latency_allowance_hc_1 = 0x00000080;
|
||||
// table->la_scale_regs.mc_latency_allowance_sdmmc_0 = 0x00800090;
|
||||
// table->la_scale_regs.mc_latency_allowance_mpcore_0 = 0x00800004;
|
||||
// table->la_scale_regs.mc_latency_allowance_vi2_0 = 0x00000080;
|
||||
// table->la_scale_regs.mc_latency_allowance_hc_0 = 0x00080016;
|
||||
// table->la_scale_regs.mc_latency_allowance_gpu_0 = 0x00800019;
|
||||
// table->la_scale_regs.mc_latency_allowance_sdmmcab_0 = 0x00800005;
|
||||
// table->la_scale_regs.mc_latency_allowance_nvenc_0 = 0x00800018;
|
||||
// table->dram_timings.t_rp = tRFCpb;
|
||||
// table->dram_timings.t_rfc = tRFCab;
|
||||
// }
|
||||
|
||||
/* These timings are slightly off from eos, I am not sure why but I am going to figure it out at some point. */
|
||||
/* Note: This does not have proper timings, so base latency adjustment will not work. */
|
||||
/* However, it may still achieve a slightly higher frequency, but not as much as it could be. */
|
||||
/* I'm certainly not insane enough to attempt this pain again, so this will have to do *for now*. */
|
||||
void MemMtcTableAutoAdjust(EristaMtcTable *table) {
|
||||
const double tCK_avg = 1000'000.0 / table->rate_khz;
|
||||
|
||||
#define WRITE_PARAM_ALL_REG(TABLE, PARAM, VALUE) \
|
||||
TABLE->burst_regs.PARAM = VALUE; \
|
||||
TABLE->shadow_regs_ca_train.PARAM = VALUE; \
|
||||
TABLE->shadow_regs_rdwr_train.PARAM = VALUE;
|
||||
|
||||
#define GET_CYCLE_CEIL(PARAM) u32(CEIL(double(PARAM) / tCK_avg))
|
||||
|
||||
/* Ram power down */
|
||||
/* B31: DRAM_CLKSTOP_PD */
|
||||
/* B30: DRAM_CLKSTOP_SR */
|
||||
@@ -515,9 +195,19 @@ namespace ams::ldr::oc::pcv::erista {
|
||||
refresh_raw = MIN(refresh_raw, static_cast<u32>(0xFFFF));
|
||||
}
|
||||
|
||||
if (table->rate_khz > 3200000) {
|
||||
rext = 30;
|
||||
} else if (table->rate_khz >= 2133001) {
|
||||
rext = 28;
|
||||
} else {
|
||||
rext = 26;
|
||||
}
|
||||
|
||||
u32 trefbw = refresh_raw + 0x40;
|
||||
trefbw = MIN(trefbw, static_cast<u32>(0x3FFF));
|
||||
|
||||
CalculateTimings(tCK_avg);
|
||||
|
||||
WRITE_PARAM_ALL_REG(table, emc_rd_rcd, GET_CYCLE_CEIL(tRCD));
|
||||
WRITE_PARAM_ALL_REG(table, emc_wr_rcd, GET_CYCLE_CEIL(tRCD));
|
||||
WRITE_PARAM_ALL_REG(table, emc_rc, MIN(GET_CYCLE_CEIL(tRC), static_cast<u32>(0xB8)));
|
||||
@@ -531,15 +221,15 @@ namespace ams::ldr::oc::pcv::erista {
|
||||
WRITE_PARAM_ALL_REG(table, emc_tfaw, GET_CYCLE_CEIL(tFAW));
|
||||
WRITE_PARAM_ALL_REG(table, emc_trpab, MIN(GET_CYCLE_CEIL(tRPab), static_cast<u32>(0x3F)));
|
||||
WRITE_PARAM_ALL_REG(table, emc_tckesr, GET_CYCLE_CEIL(tSR));
|
||||
WRITE_PARAM_ALL_REG(table, emc_tcke, tCKE);
|
||||
WRITE_PARAM_ALL_REG(table, emc_tcke, GET_CYCLE_CEIL(7.425) + 2);
|
||||
WRITE_PARAM_ALL_REG(table, emc_tpd, GET_CYCLE_CEIL(tXP));
|
||||
WRITE_PARAM_ALL_REG(table, emc_tclkstop, GET_CYCLE_CEIL(tXP) + 8);
|
||||
WRITE_PARAM_ALL_REG(table, emc_tclkstop, tCLKSTOP);
|
||||
WRITE_PARAM_ALL_REG(table, emc_r2p, tR2P);
|
||||
WRITE_PARAM_ALL_REG(table, emc_r2w, tR2W);
|
||||
WRITE_PARAM_ALL_REG(table, emc_w2p, tW2P);
|
||||
WRITE_PARAM_ALL_REG(table, emc_w2r, tW2R);
|
||||
WRITE_PARAM_ALL_REG(table, emc_rext, C.eristaEmcMaxClock < 2133001 ? 26 : 28); // rext shouldn't be causing issues?
|
||||
WRITE_PARAM_ALL_REG(table, emc_wext, (C.eristaEmcMaxClock >= 2533000) ? 0x19 : 0x16);
|
||||
WRITE_PARAM_ALL_REG(table, emc_rext, rext);
|
||||
WRITE_PARAM_ALL_REG(table, emc_wext, (table->rate_khz >= 2533000) ? 0x19 : 0x16);
|
||||
WRITE_PARAM_ALL_REG(table, emc_refresh, refresh_raw);
|
||||
WRITE_PARAM_ALL_REG(table, emc_pre_refresh_req_cnt, refresh_raw / 4);
|
||||
WRITE_PARAM_ALL_REG(table, emc_trefbw, trefbw);
|
||||
@@ -547,20 +237,46 @@ namespace ams::ldr::oc::pcv::erista {
|
||||
WRITE_PARAM_ALL_REG(table, emc_dyn_self_ref_control, dyn_self_ref_control);
|
||||
WRITE_PARAM_ALL_REG(table, emc_pdex2wr, pdex2rw);
|
||||
WRITE_PARAM_ALL_REG(table, emc_pdex2rd, pdex2rw);
|
||||
WRITE_PARAM_ALL_REG(table, emc_pchg2pden, GET_CYCLE_CEIL(1.75));
|
||||
WRITE_PARAM_ALL_REG(table, emc_pchg2pden, GET_CYCLE_CEIL(1.763));
|
||||
WRITE_PARAM_ALL_REG(table, emc_ar2pden, GET_CYCLE_CEIL(1.75));
|
||||
WRITE_PARAM_ALL_REG(table, emc_pdex2cke, GET_CYCLE_CEIL(1.05));
|
||||
WRITE_PARAM_ALL_REG(table, emc_act2pden, GET_CYCLE_CEIL(14.0));
|
||||
WRITE_PARAM_ALL_REG(table, emc_cke2pden, /* cke2pden */ GET_CYCLE_CEIL(8.5));
|
||||
(void) cke2pden;
|
||||
WRITE_PARAM_ALL_REG(table, emc_cke2pden, GET_CYCLE_CEIL(8.499));
|
||||
WRITE_PARAM_ALL_REG(table, emc_pdex2mrr, GET_CYCLE_CEIL(pdex2mrr));
|
||||
WRITE_PARAM_ALL_REG(table, emc_rw2pden, tWTPDEN);
|
||||
|
||||
/* Accept imperfection or prepare for suffering. */
|
||||
// WRITE_PARAM_ALL_REG(table, emc_einput, einput);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_einput_duration, einput_duration);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_obdly, obdly);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_ibdly, ibdly);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wdv_mask, wdv);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_quse_width, quse_width);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_quse, quse);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wdv, wdv);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wsv, wsv);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_wev, wev);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_qrst, qrst);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_qrst, qrst);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_qsafe, qsafe);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_qsafe, qsafe);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_qpop, qpop);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_qpop, qpop);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rdv, rdv);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_rdv_mask, rdv + 2);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rdv_early, rdv - 2);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rdv_early_mask, rdv);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_rdv_mask, rdv + 2);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_tr_rdv, rdv);
|
||||
// ams::ldr::hoc::pcv::mariko::CalculateMrw2();
|
||||
// table->emc_mrw2 = (table->emc_mrw2 & ~0xFFu) | static_cast<u32>(mrw2);
|
||||
// table->dram_timings.rl = RL;
|
||||
|
||||
/* This needs some clean up. */
|
||||
constexpr double MC_ARB_DIV = 4.0;
|
||||
constexpr u32 MC_ARB_SFA = 2;
|
||||
|
||||
table->burst_mc_regs.mc_emem_arb_cfg = C.eristaEmcMaxClock / (33.3 * 1000) / MC_ARB_DIV;
|
||||
table->burst_mc_regs.mc_emem_arb_cfg = table->rate_khz / (33.3 * 1000) / MC_ARB_DIV;
|
||||
table->burst_mc_regs.mc_emem_arb_timing_rcd = CEIL(GET_CYCLE_CEIL(tRCD) / MC_ARB_DIV) - 2;
|
||||
table->burst_mc_regs.mc_emem_arb_timing_rp = CEIL(GET_CYCLE_CEIL(tRPpb) / MC_ARB_DIV) - 1;
|
||||
table->burst_mc_regs.mc_emem_arb_timing_rc = CEIL(GET_CYCLE_CEIL(tRC) / MC_ARB_DIV) - 1;
|
||||
@@ -593,102 +309,153 @@ namespace ams::ldr::oc::pcv::erista {
|
||||
|
||||
table->burst_mc_regs.mc_emem_arb_misc0 = (table->burst_mc_regs.mc_emem_arb_misc0 & 0xFFE08000) | (table->burst_mc_regs.mc_emem_arb_timing_rc + 1);
|
||||
|
||||
table->la_scale_regs.mc_mll_mpcorer_ptsa_rate = 0x115;
|
||||
u32 mpcorer_ptsa_rate = MIN(static_cast<u32>(227), (table->rate_khz / 1600000) * 208);
|
||||
table->la_scale_regs.mc_mll_mpcorer_ptsa_rate = mpcorer_ptsa_rate;
|
||||
|
||||
if (C.eristaEmcMaxClock >= 2133000) {
|
||||
table->la_scale_regs.mc_ftop_ptsa_rate = 0x1F;
|
||||
} else {
|
||||
table->la_scale_regs.mc_ftop_ptsa_rate = 0x1B;
|
||||
}
|
||||
u32 ftop_ptsa_rate = MIN(static_cast<u32>(31), (table->rate_khz / 1600000) * 24);
|
||||
table->la_scale_regs.mc_ftop_ptsa_rate = ftop_ptsa_rate;
|
||||
|
||||
table->la_scale_regs.mc_ptsa_grant_decrement = 0x17ff;
|
||||
u32 grant_decrement = MIN(static_cast<u32>(6143), (table->rate_khz / 1600000) * 4611);
|
||||
table->la_scale_regs.mc_ptsa_grant_decrement = grant_decrement;
|
||||
|
||||
constexpr u32 MaskHigh = 0xFF00FFFF;
|
||||
constexpr u32 Mask2 = 0xFFFFFF00;
|
||||
constexpr u32 Mask3 = 0xFF00FF00;
|
||||
|
||||
const u32 allowance1 = static_cast<u32>(0x32000 / (C.eristaEmcMaxClock / 0x3E8)) & 0xFF;
|
||||
const u32 allowance2 = static_cast<u32>(0x9C40 / (C.eristaEmcMaxClock / 0x3E8)) & 0xFF;
|
||||
const u32 allowance3 = static_cast<u32>(0xB540 / (C.eristaEmcMaxClock / 0x3E8)) & 0xFF;
|
||||
const u32 allowance4 = static_cast<u32>(0x9600 / (C.eristaEmcMaxClock / 0x3E8)) & 0xFF;
|
||||
const u32 allowance5 = static_cast<u32>(0x8980 / (C.eristaEmcMaxClock / 0x3E8)) & 0xFF;
|
||||
const u32 allowance1 = static_cast<u32>(0x32000 / (table->rate_khz / 0x3E8)) & 0xFF;
|
||||
const u32 allowance2 = static_cast<u32>(0x9C40 / (table->rate_khz / 0x3E8)) & 0xFF;
|
||||
const u32 allowance3 = static_cast<u32>(0xB540 / (table->rate_khz / 0x3E8)) & 0xFF;
|
||||
const u32 allowance4 = static_cast<u32>(0x9600 / (table->rate_khz / 0x3E8)) & 0xFF;
|
||||
const u32 allowance5 = static_cast<u32>(0x8980 / (table->rate_khz / 0x3E8)) & 0xFF;
|
||||
|
||||
table->la_scale_regs.mc_latency_allowance_xusb_0 = (table->la_scale_regs.mc_latency_allowance_xusb_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_xusb_1 = (table->la_scale_regs.mc_latency_allowance_xusb_1 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_tsec_0 = (table->la_scale_regs.mc_latency_allowance_tsec_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmcaa_0 = (table->la_scale_regs.mc_latency_allowance_sdmmcaa_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmcab_0 = (table->la_scale_regs.mc_latency_allowance_sdmmcab_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmc_0 = (table->la_scale_regs.mc_latency_allowance_sdmmc_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmca_0 = (table->la_scale_regs.mc_latency_allowance_sdmmca_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_ppcs_1 = (table->la_scale_regs.mc_latency_allowance_ppcs_1 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_nvdec_0 = (table->la_scale_regs.mc_latency_allowance_nvdec_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_mpcore_0 = (table->la_scale_regs.mc_latency_allowance_mpcore_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_avpc_0 = (table->la_scale_regs.mc_latency_allowance_avpc_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_vic_0 = allowance3 | (table->la_scale_regs.mc_latency_allowance_vic_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_isp2_1 = (table->la_scale_regs.mc_latency_allowance_isp2_1 & Mask3) | (allowance1 << 16) | allowance1;
|
||||
table->la_scale_regs.mc_latency_allowance_nvenc_0 = allowance4 | (table->la_scale_regs.mc_latency_allowance_nvenc_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_hc_0 = (table->la_scale_regs.mc_latency_allowance_hc_0 & Mask2) | allowance5;
|
||||
table->la_scale_regs.mc_latency_allowance_gpu_0 = allowance2 | (table->la_scale_regs.mc_latency_allowance_gpu_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_gpu2_0 = allowance2 | (table->la_scale_regs.mc_latency_allowance_gpu2_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_hc_1 = (table->la_scale_regs.mc_latency_allowance_hc_1 & Mask2) | allowance1;
|
||||
table->la_scale_regs.mc_latency_allowance_vi2_0 = (table->la_scale_regs.mc_latency_allowance_vi2_0 & Mask2) | allowance1;
|
||||
table->la_scale_regs.mc_latency_allowance_xusb_0 = (table->la_scale_regs.mc_latency_allowance_xusb_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_xusb_1 = (table->la_scale_regs.mc_latency_allowance_xusb_1 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_tsec_0 = (table->la_scale_regs.mc_latency_allowance_tsec_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmcaa_0 = (table->la_scale_regs.mc_latency_allowance_sdmmcaa_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmcab_0 = (table->la_scale_regs.mc_latency_allowance_sdmmcab_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmc_0 = (table->la_scale_regs.mc_latency_allowance_sdmmc_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmca_0 = (table->la_scale_regs.mc_latency_allowance_sdmmca_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_ppcs_1 = (table->la_scale_regs.mc_latency_allowance_ppcs_1 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_nvdec_0 = (table->la_scale_regs.mc_latency_allowance_nvdec_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_mpcore_0 = (table->la_scale_regs.mc_latency_allowance_mpcore_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_avpc_0 = (table->la_scale_regs.mc_latency_allowance_avpc_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_isp2_1 = allowance1 | (table->la_scale_regs.mc_latency_allowance_isp2_1 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_gpu_0 = allowance2 | (table->la_scale_regs.mc_latency_allowance_gpu_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_gpu2_0 = allowance2 | (table->la_scale_regs.mc_latency_allowance_gpu2_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_vic_0 = allowance3 | (table->la_scale_regs.mc_latency_allowance_vic_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_nvenc_0 = allowance4 | (table->la_scale_regs.mc_latency_allowance_nvenc_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_hc_0 = (table->la_scale_regs.mc_latency_allowance_hc_0 & Mask2) | allowance5;
|
||||
table->la_scale_regs.mc_latency_allowance_hc_1 = (table->la_scale_regs.mc_latency_allowance_hc_1 & Mask2) | allowance1;
|
||||
table->la_scale_regs.mc_latency_allowance_vi2_0 = (table->la_scale_regs.mc_latency_allowance_vi2_0 & Mask2) | allowance1;
|
||||
|
||||
table->dram_timings.t_rp = tRFCpb;
|
||||
table->dram_timings.t_rfc = tRFCab;
|
||||
table->dram_timings.rl = RL_DBI;
|
||||
// WRITE_PARAM_ALL_REG(table, emc_obdly, obdly);
|
||||
// WRITE_PARAM_ALL_REG(table, emc_ibdly, ibdly);
|
||||
|
||||
table->emc_cfg_2 = 0x11083D;
|
||||
table->min_volt = std::min(static_cast<u32>(1050), 900 + C.emcDvbShift * 25);
|
||||
}
|
||||
|
||||
/* Probably more intuitive to point to 40800 rather than 1600000, but oh well. */
|
||||
Result MemFreqMtcTable(u32 *ptr) {
|
||||
if (GET_MAX_OF_ARR(maxEmcClocks) <= EmcClkOSLimit) {
|
||||
R_SKIP();
|
||||
}
|
||||
|
||||
Result MemFreqMtcTable(u32 *ptr) {
|
||||
u32 khz_list[] = {1600000, 1331200, 1065600, 800000, 665600, 408000, 204000, 102000, 68000, 40800};
|
||||
u32 khz_list_size = sizeof(khz_list) / sizeof(u32);
|
||||
u32 khz_list[] = { 40800, 68000, 102000, 204000, 408000, 665600, 800000, 1065600, 1331200, 1600000 };
|
||||
std::sort(maxEmcClocks, maxEmcClocks + std::size(maxEmcClocks));
|
||||
u32 khz_list_size = std::size(khz_list);
|
||||
|
||||
// Generate list for mtc table pointers
|
||||
EristaMtcTable *table_list[khz_list_size];
|
||||
for (u32 i = 0; i < khz_list_size; i++) {
|
||||
u32 mtcIndex = khz_list_size - 1 - i;
|
||||
u8 *table = reinterpret_cast<u8 *>(ptr) - offsetof(EristaMtcTable, rate_khz) - i * sizeof(EristaMtcTable);
|
||||
table_list[i] = reinterpret_cast<EristaMtcTable *>(table);
|
||||
R_UNLESS(table_list[i]->rate_khz == khz_list[i], ldr::ResultInvalidMtcTable());
|
||||
R_UNLESS(table_list[i]->rev == MTC_TABLE_REV, ldr::ResultInvalidMtcTable());
|
||||
table_list[mtcIndex] = reinterpret_cast<EristaMtcTable *>(table);
|
||||
R_UNLESS(table_list[mtcIndex]->rate_khz == khz_list[mtcIndex], ldr::ResultInvalidMtcTable());
|
||||
R_UNLESS(table_list[mtcIndex]->rev == MTC_TABLE_REV, ldr::ResultInvalidMtcTable());
|
||||
}
|
||||
|
||||
if (C.eristaEmcMaxClock <= EmcClkOSLimit)
|
||||
R_SKIP();
|
||||
/* If we oc ram at all, tables are always shifted by at least 1. */
|
||||
u32 tableShifts = 1;
|
||||
for (u32 i = 0; i < std::size(maxEmcClocks) - 1; ++i) {
|
||||
/* Duplicated mtc tables may cause pcv to not select frequencies properly, causing issues. */
|
||||
if (maxEmcClocks[i] != maxEmcClocks[i + 1] && maxEmcClocks[i] > EmcClkOSLimit) {
|
||||
++tableShifts;
|
||||
} else {
|
||||
maxEmcClocks[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Make room for new mtc table, discarding useless 40.8 MHz table
|
||||
// 40800 overwritten by 68000, ..., 1331200 overwritten by 1600000, leaving table_list[0] not overwritten
|
||||
for (u32 i = khz_list_size - 1; i > 0; i--)
|
||||
std::memcpy(static_cast<void *>(table_list[i]), static_cast<void *>(table_list[i - 1]), sizeof(EristaMtcTable));
|
||||
/* Erista has extra, useless mtc tables, such as 40.8 Mhz, overwrite them to make room for oc freqs. */
|
||||
/* More than 3 tables can be overwritten, but 3 is plenty. */
|
||||
std::memmove(table_list[0], table_list[tableShifts], sizeof(EristaMtcTable) * (khz_list_size - tableShifts));
|
||||
|
||||
MemMtcTableAutoAdjust(table_list[0]);
|
||||
/* Since we're not scaling r/w latency properly on Erista, we first overwrite the tables with the 1600 MHz table before scaling it. */
|
||||
for (u32 i = 0; i < tableShifts; ++i) {
|
||||
std::memcpy(table_list[khz_list_size - i - 1], table_list[khz_list_size - tableShifts - 1], sizeof(EristaMtcTable));
|
||||
}
|
||||
|
||||
for (u32 i = tableShifts, j = 0; i > 0 && j < std::size(maxEmcClocks); ++j) {
|
||||
if (!maxEmcClocks[j]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
table_list[khz_list_size - i]->rate_khz = maxEmcClocks[j];
|
||||
MemMtcTableAutoAdjust(table_list[khz_list_size - i]);
|
||||
--i;
|
||||
}
|
||||
|
||||
PATCH_OFFSET(ptr, C.eristaEmcMaxClock);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result MemFreqMax(u32 *ptr) {
|
||||
if (C.eristaEmcMaxClock <= EmcClkOSLimit)
|
||||
if (GET_MAX_OF_ARR(maxEmcClocks) <= EmcClkOSLimit) {
|
||||
R_SKIP();
|
||||
}
|
||||
|
||||
PATCH_OFFSET(ptr, C.eristaEmcMaxClock);
|
||||
PATCH_OFFSET(ptr, GET_MAX_OF_ARR(maxEmcClocks));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GpuFreqPllMax(u32 *ptr) {
|
||||
clk_pll_param *entry = reinterpret_cast<clk_pll_param *>(ptr);
|
||||
|
||||
// All zero except for freq
|
||||
for (size_t i = 1; i < sizeof(clk_pll_param) / sizeof(u32); i++) {
|
||||
R_UNLESS(*(ptr + i) == 0, ldr::ResultInvalidGpuPllEntry());
|
||||
}
|
||||
|
||||
// Double the max clk simply
|
||||
u32 max_clk = entry->freq * 2;
|
||||
entry->freq = max_clk;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
// patch out 1305MHz limit on erista, don't use this!
|
||||
// Result GpuFreqPllLimit(u32 *ptr) {
|
||||
// u32 prev_freq = *(ptr - 1);
|
||||
|
||||
// if (prev_freq != 128000 && prev_freq != 1300000 && prev_freq != 76800) {
|
||||
// R_THROW(ldr::ResultInvalidGpuPllEntry());
|
||||
// }
|
||||
|
||||
// PATCH_OFFSET(ptr, 3600000);
|
||||
|
||||
// R_SUCCEED();
|
||||
// }
|
||||
|
||||
void Patch(uintptr_t mapped_nso, size_t nso_size) {
|
||||
PatcherEntry<u32> patches[] = {
|
||||
{"CPU Freq Table", CpuFreqCvbTable<false>, 1, nullptr, static_cast<u32>(GetDvfsTableLastEntry(CpuCvbTableDefault)->freq)},
|
||||
{"CPU Volt DVFS", &CpuVoltDvfs, 1, nullptr, 825},
|
||||
{"CPU Volt Thermals", &CpuVoltThermals, 1, nullptr, 825},
|
||||
{"CPU Volt Dfll", &CpuVoltDfll, 1, nullptr, 0xFFEAD0FF},
|
||||
{"GPU Volt DVFS", &GpuVoltDVFS, 1, nullptr, 810},
|
||||
{"GPU Volt Thermals", &GpuVoltThermals, 1, nullptr, 810},
|
||||
{"CPU Volt DVFS", &CpuVoltDvfs, 1, nullptr, CpuVminOfficial},
|
||||
{"CPU Volt Thermals", &CpuVoltThermals, 1, nullptr, CpuVminOfficial},
|
||||
{"CPU Volt Dfll", &CpuVoltDfll, 1, nullptr, 0xFFEAD0FF},
|
||||
{"GPU Volt DVFS", &GpuVoltDVFS, 1, nullptr, GpuVminOfficial},
|
||||
{"GPU Volt Thermals", &GpuVoltThermals, 1, nullptr, GpuVminOfficial},
|
||||
{"GPU Freq Table", GpuFreqCvbTable<false>, 1, nullptr, static_cast<u32>(GetDvfsTableLastEntry(GpuCvbTableDefault)->freq)},
|
||||
{"GPU Freq Asm", &GpuFreqMaxAsm, 2, &GpuMaxClockPatternFn},
|
||||
{"GPU Freq PLL", &GpuFreqPllLimit, 1, nullptr, GpuClkPllLimit},
|
||||
{"GPU PLL Max", &GpuFreqPllMax, 1, nullptr, GpuClkPllMax},
|
||||
// {"GPU PLL Limit", &GpuFreqPllLimit, 4, nullptr, GpuClkPllLimit},
|
||||
{"MEM Freq Mtc", &MemFreqMtcTable, 0, nullptr, EmcClkOSLimit},
|
||||
{"MEM Freq Max", &MemFreqMax, 0, nullptr, EmcClkOSLimit},
|
||||
{"MEM Freq PLLM", &MemFreqPllmLimit, 2, nullptr, EmcClkPllmLimit},
|
||||
@@ -707,8 +474,13 @@ namespace ams::ldr::oc::pcv::erista {
|
||||
for (auto &entry : patches) {
|
||||
LOGGING("%s Count: %zu", entry.description, entry.patched_count);
|
||||
if (R_FAILED(entry.CheckResult())) {
|
||||
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
|
||||
panic::SmcError(panic::Patch);
|
||||
#endif
|
||||
|
||||
CRASH(entry.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "../mtc_timing_value.hpp"
|
||||
#include "../mariko/calculate_timings.hpp"
|
||||
|
||||
namespace ams::ldr::oc::pcv::mariko {
|
||||
namespace ams::ldr::hoc::pcv::mariko {
|
||||
|
||||
u32 GetGpuVminVoltage() {
|
||||
for (auto e : vminTable) {
|
||||
@@ -84,18 +84,18 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
}
|
||||
|
||||
/* C.marikoGpuVmin is zero, auto voltage is applied. */
|
||||
/* Get vmin depending on speedo and ram clock. */
|
||||
u32 autoVmin = GetAutoVoltage();
|
||||
PATCH_OFFSET(ptr, autoVmin);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GpuVoltThermals(u32 *ptr) {
|
||||
u32 vmin = std::memcmp(ptr - 3, gpuVoltThermalPattern, sizeof(gpuVoltThermalPattern));
|
||||
if (vmin) {
|
||||
if (std::memcmp(ptr - 3, gpuVoltThermalPattern, sizeof(gpuVoltThermalPattern))) {
|
||||
R_THROW(ldr::ResultInvalidGpuDvfs());
|
||||
}
|
||||
|
||||
u32 vmin = C.marikoGpuVmin;
|
||||
|
||||
/* Automatic voltage. */
|
||||
if (!C.marikoGpuVmin) {
|
||||
vmin = GetAutoVoltage();
|
||||
@@ -105,11 +105,10 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
PATCH_OFFSET(ptr + 9, vmin);
|
||||
} else {
|
||||
/* Manual voltage. */
|
||||
PATCH_OFFSET(ptr, C.marikoGpuVmin);
|
||||
PATCH_OFFSET(ptr + 3, C.marikoGpuVmin);
|
||||
PATCH_OFFSET(ptr + 6, C.marikoGpuVmin);
|
||||
PATCH_OFFSET(ptr + 9, C.marikoGpuVmin);
|
||||
vmin = C.marikoGpuVmin;
|
||||
PATCH_OFFSET(ptr, vmin);
|
||||
PATCH_OFFSET(ptr + 3, vmin);
|
||||
PATCH_OFFSET(ptr + 6, vmin);
|
||||
PATCH_OFFSET(ptr + 9, vmin);
|
||||
}
|
||||
|
||||
PATCH_OFFSET(ptr + 12, vmin);
|
||||
@@ -267,7 +266,6 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
switch (C.marikoCpuUVHigh) {
|
||||
case 1:
|
||||
PATCH_OFFSET(&(entry->tune1_high), 0);
|
||||
@@ -417,6 +415,8 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
u32 trefbw = refresh_raw + 0x40;
|
||||
trefbw = MIN(trefbw, static_cast<u32>(0x3FFF));
|
||||
|
||||
const u32 dyn_self_ref_control = (static_cast<u32>(7605.0 / tCK_avg) + 260) | (table->burst_regs.emc_dyn_self_ref_control & 0xffff0000);
|
||||
|
||||
CalculateTimings();
|
||||
|
||||
WRITE_PARAM_ALL_REG(table, emc_rd_rcd, GET_CYCLE_CEIL(tRCD));
|
||||
@@ -432,9 +432,9 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
WRITE_PARAM_ALL_REG(table, emc_tfaw, GET_CYCLE_CEIL(tFAW));
|
||||
WRITE_PARAM_ALL_REG(table, emc_trpab, MIN(GET_CYCLE_CEIL(tRPab), static_cast<u32>(0x3F)));
|
||||
WRITE_PARAM_ALL_REG(table, emc_tckesr, GET_CYCLE_CEIL(tSR));
|
||||
WRITE_PARAM_ALL_REG(table, emc_tcke, tCKE);
|
||||
WRITE_PARAM_ALL_REG(table, emc_tcke, GET_CYCLE_CEIL(7.425) + 2);
|
||||
WRITE_PARAM_ALL_REG(table, emc_tpd, GET_CYCLE_CEIL(tXP));
|
||||
WRITE_PARAM_ALL_REG(table, emc_tclkstop, GET_CYCLE_CEIL(tXP) + 8); // TODO analyse
|
||||
WRITE_PARAM_ALL_REG(table, emc_tclkstop, tCLKSTOP);
|
||||
WRITE_PARAM_ALL_REG(table, emc_r2p, tR2P);
|
||||
WRITE_PARAM_ALL_REG(table, emc_r2w, tR2W);
|
||||
WRITE_PARAM_ALL_REG(table, emc_trtm, tRTM);
|
||||
@@ -448,16 +448,14 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
WRITE_PARAM_ALL_REG(table, emc_refresh, refresh_raw);
|
||||
WRITE_PARAM_ALL_REG(table, emc_pre_refresh_req_cnt, refresh_raw / 4);
|
||||
WRITE_PARAM_ALL_REG(table, emc_trefbw, trefbw);
|
||||
const u32 dyn_self_ref_control = (static_cast<u32>(7605.0 / tCK_avg) + 260) | (table->burst_regs.emc_dyn_self_ref_control & 0xffff0000);
|
||||
WRITE_PARAM_ALL_REG(table, emc_dyn_self_ref_control, dyn_self_ref_control);
|
||||
WRITE_PARAM_ALL_REG(table, emc_pdex2wr, pdex2rw);
|
||||
WRITE_PARAM_ALL_REG(table, emc_pdex2rd, pdex2rw);
|
||||
WRITE_PARAM_ALL_REG(table, emc_pchg2pden, GET_CYCLE_CEIL(1.75));
|
||||
WRITE_PARAM_ALL_REG(table, emc_pchg2pden, GET_CYCLE_CEIL(1.763));
|
||||
WRITE_PARAM_ALL_REG(table, emc_ar2pden, GET_CYCLE_CEIL(1.75));
|
||||
WRITE_PARAM_ALL_REG(table, emc_pdex2cke, GET_CYCLE_CEIL(1.05));
|
||||
WRITE_PARAM_ALL_REG(table, emc_act2pden, GET_CYCLE_CEIL(14.0));
|
||||
WRITE_PARAM_ALL_REG(table, emc_cke2pden, /* cke2pden */ GET_CYCLE_CEIL(8.5));
|
||||
(void) cke2pden;
|
||||
WRITE_PARAM_ALL_REG(table, emc_cke2pden, GET_CYCLE_CEIL(8.499));
|
||||
WRITE_PARAM_ALL_REG(table, emc_pdex2mrr, GET_CYCLE_CEIL(pdex2mrr));
|
||||
WRITE_PARAM_ALL_REG(table, emc_rw2pden, tWTPDEN);
|
||||
WRITE_PARAM_ALL_REG(table, emc_einput, einput);
|
||||
@@ -482,8 +480,9 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
WRITE_PARAM_ALL_REG(table, emc_rdv_early_mask, rdv);
|
||||
WRITE_PARAM_ALL_REG(table, emc_rdv_mask, rdv + 2);
|
||||
WRITE_PARAM_ALL_REG(table, emc_tr_rdv, rdv);
|
||||
WRITE_PARAM_ALL_REG(table, emc_cmd_brlshft_2, 0x24)
|
||||
WRITE_PARAM_ALL_REG(table, emc_cmd_brlshft_3, 0x24)
|
||||
/* TODO: Check this out again at some point. */
|
||||
WRITE_PARAM_ALL_REG(table, emc_cmd_brlshft_2, 0x24);
|
||||
WRITE_PARAM_ALL_REG(table, emc_cmd_brlshft_3, 0x24);
|
||||
|
||||
/* This needs some clean up. */
|
||||
constexpr double MC_ARB_DIV = 4.0;
|
||||
@@ -501,7 +500,7 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
table->burst_mc_regs.mc_emem_arb_timing_wap2pre = CEIL(tW2P / MC_ARB_DIV) + MC_ARB_SFA;
|
||||
|
||||
/* Two consecutive reads between two different dram modules. */
|
||||
/* Only be above 1 for 8gb ram. */
|
||||
/* Only above 1 for 8gb ram. */
|
||||
if (table->burst_mc_regs.mc_emem_arb_timing_r2r > 1) {
|
||||
table->burst_mc_regs.mc_emem_arb_timing_r2r = CEIL(table->burst_regs.emc_rext / 4) - 1 + MC_ARB_SFA;
|
||||
}
|
||||
@@ -549,42 +548,34 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
const u32 allowance4 = static_cast<u32>(0x9600 / (C.marikoEmcMaxClock / 0x3E8)) & 0xFF;
|
||||
const u32 allowance5 = static_cast<u32>(0x8980 / (C.marikoEmcMaxClock / 0x3E8)) & 0xFF;
|
||||
|
||||
table->la_scale_regs.mc_latency_allowance_xusb_0 = (table->la_scale_regs.mc_latency_allowance_xusb_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_xusb_1 = (table->la_scale_regs.mc_latency_allowance_xusb_1 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_tsec_0 = (table->la_scale_regs.mc_latency_allowance_tsec_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmcaa_0 = (table->la_scale_regs.mc_latency_allowance_sdmmcaa_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmcab_0 = (table->la_scale_regs.mc_latency_allowance_sdmmcab_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmc_0 = (table->la_scale_regs.mc_latency_allowance_sdmmc_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmca_0 = (table->la_scale_regs.mc_latency_allowance_sdmmca_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_ppcs_1 = (table->la_scale_regs.mc_latency_allowance_ppcs_1 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_nvdec_0 = (table->la_scale_regs.mc_latency_allowance_nvdec_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_mpcore_0 = (table->la_scale_regs.mc_latency_allowance_mpcore_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_avpc_0 = (table->la_scale_regs.mc_latency_allowance_avpc_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_vic_0 = allowance3 | (table->la_scale_regs.mc_latency_allowance_vic_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_isp2_1 = (table->la_scale_regs.mc_latency_allowance_isp2_1 & Mask3) | (allowance1 << 16) | allowance1;
|
||||
table->la_scale_regs.mc_latency_allowance_nvenc_0 = allowance4 | (table->la_scale_regs.mc_latency_allowance_nvenc_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_hc_0 = (table->la_scale_regs.mc_latency_allowance_hc_0 & Mask2) | allowance5;
|
||||
table->la_scale_regs.mc_latency_allowance_gpu_0 = allowance2 | (table->la_scale_regs.mc_latency_allowance_gpu_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_gpu2_0 = allowance2 | (table->la_scale_regs.mc_latency_allowance_gpu2_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_hc_1 = (table->la_scale_regs.mc_latency_allowance_hc_1 & Mask2) | allowance1;
|
||||
table->la_scale_regs.mc_latency_allowance_vi2_0 = (table->la_scale_regs.mc_latency_allowance_vi2_0 & Mask2) | allowance1;
|
||||
table->la_scale_regs.mc_latency_allowance_xusb_0 = (table->la_scale_regs.mc_latency_allowance_xusb_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_xusb_1 = (table->la_scale_regs.mc_latency_allowance_xusb_1 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_tsec_0 = (table->la_scale_regs.mc_latency_allowance_tsec_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmcaa_0 = (table->la_scale_regs.mc_latency_allowance_sdmmcaa_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmcab_0 = (table->la_scale_regs.mc_latency_allowance_sdmmcab_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmc_0 = (table->la_scale_regs.mc_latency_allowance_sdmmc_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_sdmmca_0 = (table->la_scale_regs.mc_latency_allowance_sdmmca_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_ppcs_1 = (table->la_scale_regs.mc_latency_allowance_ppcs_1 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_nvdec_0 = (table->la_scale_regs.mc_latency_allowance_nvdec_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_mpcore_0 = (table->la_scale_regs.mc_latency_allowance_mpcore_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_avpc_0 = (table->la_scale_regs.mc_latency_allowance_avpc_0 & MaskHigh) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_isp2_1 = allowance1 | (table->la_scale_regs.mc_latency_allowance_isp2_1 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_gpu_0 = allowance2 | (table->la_scale_regs.mc_latency_allowance_gpu_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_gpu2_0 = allowance2 | (table->la_scale_regs.mc_latency_allowance_gpu2_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_vic_0 = allowance3 | (table->la_scale_regs.mc_latency_allowance_vic_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_nvenc_0 = allowance4 | (table->la_scale_regs.mc_latency_allowance_nvenc_0 & Mask3) | (allowance1 << 16);
|
||||
table->la_scale_regs.mc_latency_allowance_hc_0 = (table->la_scale_regs.mc_latency_allowance_hc_0 & Mask2) | allowance5;
|
||||
table->la_scale_regs.mc_latency_allowance_hc_1 = (table->la_scale_regs.mc_latency_allowance_hc_1 & Mask2) | allowance1;
|
||||
table->la_scale_regs.mc_latency_allowance_vi2_0 = (table->la_scale_regs.mc_latency_allowance_vi2_0 & Mask2) | allowance1;
|
||||
|
||||
table->dram_timings.t_rp = tRFCpb;
|
||||
table->dram_timings.t_rfc = tRFCab;
|
||||
table->dram_timings.rl = RL_DBI;
|
||||
table->dram_timings.rl = RL;
|
||||
|
||||
table->emc_mrw2 = (table->emc_mrw2 & ~0xFFu) | static_cast<u32>(mrw2);
|
||||
table->emc_cfg_2 = 0x11083D;
|
||||
}
|
||||
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pdex2wr, GET_CYCLE(10.0));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pdex2rd, GET_CYCLE(10.0));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pchg2pden, GET_CYCLE(1.75));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_ar2pden, GET_CYCLE(1.75));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_pdex2cke, GET_CYCLE(1.75));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_act2pden, GET_CYCLE(14.0));
|
||||
// WRITE_PARAM_ALL_REG(table, emc_cke2pden, GET_CYCLE(5.0));
|
||||
|
||||
void MemMtcPllmbDivisor(MarikoMtcTable *table) {
|
||||
constexpr u32 PllOscInKHz = 38400;
|
||||
constexpr u32 PllOscHalfKHz = 19200;
|
||||
@@ -663,9 +654,8 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
|
||||
// Copy unmodified 1600000 table to tmp
|
||||
std::memcpy(reinterpret_cast<void *>(tmp), reinterpret_cast<void *>(table_max), sizeof(MarikoMtcTable));
|
||||
// Adjust max freq mtc timing parameters with reference to 1331200 table
|
||||
/* TODO: Implement mariko */
|
||||
|
||||
/* Adjust timings properly according to the new frequency. */
|
||||
MemMtcTableAutoAdjust(table_max);
|
||||
|
||||
MemMtcPllmbDivisor(table_max);
|
||||
@@ -694,6 +684,7 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
|
||||
#define DVB_VOLT(zero, one, two) std::min(zero + voltAdd, 1050), std::min(one + voltAdd, 1025), std::min(two + voltAdd, 1000),
|
||||
|
||||
/* TODO: More fine tuned values? */
|
||||
if (C.marikoEmcMaxClock < 1862400) {
|
||||
std::memcpy(new_start, default_end, sizeof(emc_dvb_dvfs_table_t));
|
||||
} else if (C.marikoEmcMaxClock < 2131200) {
|
||||
@@ -821,6 +812,10 @@ namespace ams::ldr::oc::pcv::mariko {
|
||||
for (auto &entry : patches) {
|
||||
LOGGING("%s Count: %zu", entry.description, entry.patched_count);
|
||||
if (R_FAILED(entry.CheckResult())) {
|
||||
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
|
||||
panic::SmcError(panic::Patch);
|
||||
#endif
|
||||
|
||||
CRASH(entry.description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,118 +18,113 @@
|
||||
|
||||
#include "ptm.hpp"
|
||||
|
||||
namespace ams::ldr::oc::ptm {
|
||||
namespace ams::ldr::hoc::ptm {
|
||||
|
||||
Result CpuPtmBoost(perf_conf_entry* entry) {
|
||||
Result CpuPtmBoost(perf_conf_entry* entry) {
|
||||
#ifdef ATMOSPHERE_IS_STRATOSPHERE
|
||||
bool isMariko = (spl::GetSocType() == spl::SocType_Mariko);
|
||||
#else
|
||||
bool isMariko = true;
|
||||
#endif
|
||||
|
||||
#ifdef ATMOSPHERE_IS_STRATOSPHERE
|
||||
bool isMariko = (spl::GetSocType() == spl::SocType_Mariko);
|
||||
#else
|
||||
bool isMariko = true;
|
||||
#endif
|
||||
if (!C.eristaCpuBoostClock || !C.marikoCpuBoostClock) {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
u32 cpuPtmBoostNew = isMariko ? C.marikoCpuBoostClock * 1000 : C.eristaCpuBoostClock * 1000;
|
||||
|
||||
PATCH_OFFSET(&(entry->cpu_freq_1), cpuPtmBoostNew);
|
||||
PATCH_OFFSET(&(entry->cpu_freq_2), cpuPtmBoostNew);
|
||||
|
||||
if (!C.eristaCpuBoostClock || !C.marikoCpuBoostClock)
|
||||
R_SUCCEED();
|
||||
|
||||
u32 cpuPtmBoostNew = isMariko ? C.marikoCpuBoostClock * 1000 : C.eristaCpuBoostClock * 1000;
|
||||
|
||||
PATCH_OFFSET(&(entry->cpu_freq_1), cpuPtmBoostNew);
|
||||
PATCH_OFFSET(&(entry->cpu_freq_2), cpuPtmBoostNew);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result MemPtm(perf_conf_entry* entry) {
|
||||
PATCH_OFFSET(&(entry->emc_freq_1), memPtmLimit);
|
||||
PATCH_OFFSET(&(entry->emc_freq_2), memPtmLimit);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
bool PtmEntryIsValid(perf_conf_entry* entry) {
|
||||
return (entry->cpu_freq_1 == entry->cpu_freq_2 &&
|
||||
entry->gpu_freq_1 == entry->gpu_freq_2 &&
|
||||
entry->emc_freq_1 == entry->emc_freq_2);
|
||||
}
|
||||
|
||||
bool PtmTablePatternFn(u32* ptr) {
|
||||
perf_conf_entry* entry = reinterpret_cast<perf_conf_entry *>(ptr);
|
||||
if (!PtmEntryIsValid(entry))
|
||||
return false;
|
||||
|
||||
return entry->cpu_freq_1 == cpuPtmDefault;
|
||||
}
|
||||
|
||||
void Patch(uintptr_t mapped_nso, size_t nso_size) {
|
||||
perf_conf_entry* confTable = nullptr;
|
||||
for (uintptr_t ptr = mapped_nso;
|
||||
ptr <= mapped_nso + nso_size - sizeof(perf_conf_entry) * entryCnt;
|
||||
ptr += sizeof(u32))
|
||||
{
|
||||
u32* ptr32 = reinterpret_cast<u32 *>(ptr);
|
||||
if (PtmTablePatternFn(ptr32)) {
|
||||
confTable = reinterpret_cast<perf_conf_entry *>(ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!confTable) {
|
||||
CRASH("confTable not found!");
|
||||
Result MemPtm(perf_conf_entry* entry) {
|
||||
PATCH_OFFSET(&(entry->emc_freq_1), memPtmLimit);
|
||||
PATCH_OFFSET(&(entry->emc_freq_2), memPtmLimit);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
PatcherEntry<perf_conf_entry> cpuPtmBoostPatch = { "CPU Ptm Boost", &CpuPtmBoost, 2, };
|
||||
PatcherEntry<perf_conf_entry> memPtmPatch = { "MEM Ptm", &MemPtm, 16, };
|
||||
|
||||
#ifdef ATMOSPHERE_IS_STRATOSPHERE
|
||||
bool isMariko = (spl::GetSocType() == spl::SocType_Mariko);
|
||||
#else
|
||||
bool isMariko = true;
|
||||
#endif
|
||||
|
||||
|
||||
for (u32 i = 0; i < entryCnt; i++) {
|
||||
perf_conf_entry* entry = confTable + i;
|
||||
bool PtmEntryIsValid(perf_conf_entry* entry) {
|
||||
return (entry->cpu_freq_1 == entry->cpu_freq_2 && entry->gpu_freq_1 == entry->gpu_freq_2 && entry->emc_freq_1 == entry->emc_freq_2);
|
||||
}
|
||||
|
||||
bool PtmTablePatternFn(u32* ptr) {
|
||||
perf_conf_entry* entry = reinterpret_cast<perf_conf_entry *>(ptr);
|
||||
if (!PtmEntryIsValid(entry)) {
|
||||
LOGGING("@%p", &entry);
|
||||
CRASH("Invalid ptm confTable entry");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (entry->cpu_freq_1) {
|
||||
case cpuPtmBoost:
|
||||
cpuPtmBoostPatch.Apply(entry);
|
||||
return entry->cpu_freq_1 == cpuPtmDefault;
|
||||
}
|
||||
|
||||
void Patch(uintptr_t mapped_nso, size_t nso_size) {
|
||||
perf_conf_entry* confTable = nullptr;
|
||||
for (uintptr_t ptr = mapped_nso; ptr <= mapped_nso + nso_size - sizeof(perf_conf_entry) * entryCnt; ptr += sizeof(u32)) {
|
||||
u32* ptr32 = reinterpret_cast<u32 *>(ptr);
|
||||
if (PtmTablePatternFn(ptr32)) {
|
||||
confTable = reinterpret_cast<perf_conf_entry *>(ptr);
|
||||
break;
|
||||
case cpuPtmDefault:
|
||||
case cpuPtmDevOC:
|
||||
break;
|
||||
default:
|
||||
LOGGING("%u (0x%08x) @%p", entry->cpu_freq_1, entry->conf_id, &(entry->cpu_freq_1));
|
||||
CRASH("Unknown CPU Freq");
|
||||
}
|
||||
}
|
||||
|
||||
switch (entry->emc_freq_1) {
|
||||
case memPtmLimit:
|
||||
case memPtmAlt:
|
||||
case memPtmClamp:
|
||||
if (isMariko) {
|
||||
memPtmPatch.Apply(entry);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOGGING("%u (0x%08x) @%p", entry->emc_freq_1, entry->conf_id, &(entry->emc_freq_2));
|
||||
CRASH("Unknown MEM Freq");
|
||||
if (!confTable) {
|
||||
CRASH("confTable not found!");
|
||||
}
|
||||
|
||||
PatcherEntry<perf_conf_entry> cpuPtmBoostPatch = { "CPU Ptm Boost", &CpuPtmBoost, 2, };
|
||||
PatcherEntry<perf_conf_entry> memPtmPatch = { "MEM Ptm", &MemPtm, 16, };
|
||||
|
||||
#ifdef ATMOSPHERE_IS_STRATOSPHERE
|
||||
bool isMariko = (spl::GetSocType() == spl::SocType_Mariko);
|
||||
#else
|
||||
bool isMariko = true;
|
||||
#endif
|
||||
|
||||
for (u32 i = 0; i < entryCnt; i++) {
|
||||
perf_conf_entry *entry = confTable + i;
|
||||
|
||||
if (!PtmEntryIsValid(entry)) {
|
||||
LOGGING("@%p", &entry);
|
||||
CRASH("Invalid ptm confTable entry");
|
||||
}
|
||||
|
||||
switch (entry->cpu_freq_1) {
|
||||
case cpuPtmBoost:
|
||||
cpuPtmBoostPatch.Apply(entry);
|
||||
break;
|
||||
case cpuPtmDefault:
|
||||
case cpuPtmDevOC:
|
||||
break;
|
||||
default:
|
||||
LOGGING("%u (0x%08x) @%p", entry->cpu_freq_1, entry->conf_id, &(entry->cpu_freq_1));
|
||||
CRASH("Unknown CPU Freq");
|
||||
}
|
||||
|
||||
switch (entry->emc_freq_1) {
|
||||
case memPtmLimit:
|
||||
case memPtmAlt:
|
||||
case memPtmClamp:
|
||||
if (isMariko) {
|
||||
memPtmPatch.Apply(entry);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOGGING("%u (0x%08x) @%p", entry->emc_freq_1, entry->conf_id, &(entry->emc_freq_2));
|
||||
CRASH("Unknown MEM Freq");
|
||||
}
|
||||
}
|
||||
|
||||
LOGGING("%s Count: %zu", cpuPtmBoostPatch.description, cpuPtmBoostPatch.patched_count);
|
||||
if (R_FAILED(cpuPtmBoostPatch.CheckResult()))
|
||||
CRASH(cpuPtmBoostPatch.description);
|
||||
|
||||
if (isMariko) {
|
||||
LOGGING("%s Count: %zu", memPtmPatch.description, memPtmPatch.patched_count);
|
||||
if (R_FAILED(memPtmPatch.CheckResult()))
|
||||
CRASH(memPtmPatch.description);
|
||||
}
|
||||
}
|
||||
|
||||
LOGGING("%s Count: %zu", cpuPtmBoostPatch.description, cpuPtmBoostPatch.patched_count);
|
||||
if (R_FAILED(cpuPtmBoostPatch.CheckResult()))
|
||||
CRASH(cpuPtmBoostPatch.description);
|
||||
|
||||
if (isMariko) {
|
||||
LOGGING("%s Count: %zu", memPtmPatch.description, memPtmPatch.patched_count);
|
||||
if (R_FAILED(memPtmPatch.CheckResult()))
|
||||
CRASH(memPtmPatch.description);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,28 +20,28 @@
|
||||
|
||||
#include "../oc_common.hpp"
|
||||
|
||||
namespace ams::ldr::oc::ptm {
|
||||
namespace ams::ldr::hoc::ptm {
|
||||
|
||||
typedef struct {
|
||||
u32 conf_id;
|
||||
u32 cpu_freq_1; // min-max pair?
|
||||
u32 cpu_freq_2;
|
||||
u32 gpu_freq_1;
|
||||
u32 gpu_freq_2;
|
||||
u32 emc_freq_1;
|
||||
u32 emc_freq_2;
|
||||
u32 padding;
|
||||
} perf_conf_entry;
|
||||
typedef struct {
|
||||
u32 conf_id;
|
||||
u32 cpu_freq_1; // min-max pair?
|
||||
u32 cpu_freq_2;
|
||||
u32 gpu_freq_1;
|
||||
u32 gpu_freq_2;
|
||||
u32 emc_freq_1;
|
||||
u32 emc_freq_2;
|
||||
u32 padding;
|
||||
} perf_conf_entry;
|
||||
|
||||
constexpr u32 entryCnt = 16;
|
||||
constexpr u32 cpuPtmDefault = 1020'000'000;
|
||||
constexpr u32 cpuPtmDevOC = 1224'000'000;
|
||||
constexpr u32 cpuPtmBoost = 1785'000'000;
|
||||
constexpr u32 entryCnt = 16;
|
||||
constexpr u32 cpuPtmDefault = 1020'000'000;
|
||||
constexpr u32 cpuPtmDevOC = 1224'000'000;
|
||||
constexpr u32 cpuPtmBoost = 1785'000'000;
|
||||
|
||||
constexpr u32 memPtmLimit = 1600'000'000;
|
||||
constexpr u32 memPtmAlt = 1331'200'000;
|
||||
constexpr u32 memPtmClamp = 1065'600'000;
|
||||
constexpr u32 memPtmLimit = 1600'000'000;
|
||||
constexpr u32 memPtmAlt = 1331'200'000;
|
||||
constexpr u32 memPtmClamp = 1065'600'000;
|
||||
|
||||
void Patch(uintptr_t mapped_nso, size_t nso_size);
|
||||
void Patch(uintptr_t mapped_nso, size_t nso_size);
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ include $(DEVKITPRO)/libnx/switch_rules
|
||||
# NACP building is skipped as well.
|
||||
#---------------------------------------------------------------------------------
|
||||
APP_TITLE := Horizon OC Monitor
|
||||
APP_VERSION := 1.3.2+r4-hoc
|
||||
APP_VERSION := 1.3.2+r4-hoc-r2
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
|
||||
Submodule Source/Horizon-OC-Monitor/lib/Atmosphere-libs updated: 6cc765fcaa...132de9d7f2
Submodule Source/Horizon-OC-Monitor/lib/libultrahand updated: 8541ecbe95...57fc30ac37
@@ -685,7 +685,7 @@ void Misc2(void*) {
|
||||
|
||||
void Misc3(void*) {
|
||||
const bool isUsingEOS = usingEOS();
|
||||
|
||||
|
||||
// Initialize voltage reading if needed
|
||||
bool canReadVoltages = false;
|
||||
if (!isUsingEOS && realVoltsPolling) {
|
||||
@@ -694,7 +694,7 @@ void Misc3(void*) {
|
||||
realVoltsPolling = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
mutexLock(&mutex_Misc);
|
||||
|
||||
@@ -706,7 +706,7 @@ void Misc3(void*) {
|
||||
if (R_SUCCEEDED(tcCheck)) {
|
||||
tcGetSkinTemperatureMilliC(&skin_temperaturemiliC);
|
||||
}
|
||||
|
||||
|
||||
// Fan
|
||||
if (R_SUCCEEDED(pwmCheck)) {
|
||||
double temp = 0;
|
||||
@@ -720,16 +720,21 @@ void Misc3(void*) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// GPU Load
|
||||
if (R_SUCCEEDED(nvCheck)) {
|
||||
nvIoctl(fd, NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD, &GPU_Load_u);
|
||||
}
|
||||
|
||||
|
||||
SysClkContext sysclkCTX;
|
||||
if (R_SUCCEEDED(sysclkIpcGetCurrentContext(&sysclkCTX))) {
|
||||
partLoad[SysClkPartLoad_EMC] = sysclkCTX.partLoad[SysClkPartLoad_EMC];
|
||||
}
|
||||
|
||||
mutexUnlock(&mutex_Misc);
|
||||
|
||||
|
||||
} while (!leventWait(&threadexit, 1'000'000'000)); // 1 second timeout
|
||||
|
||||
|
||||
// Cleanup voltage reading if initialized
|
||||
if (canReadVoltages) {
|
||||
rgltrExit();
|
||||
@@ -2453,4 +2458,4 @@ ALWAYS_INLINE void GetConfigSettings(ResolutionSettings* settings) {
|
||||
convertToUpper(key);
|
||||
settings->disableScreenshots = (key != "FALSE");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -79,14 +79,17 @@ Result sysclkIpcGetAPIVersion(u32* out_ver)
|
||||
Result sysclkIpcGetVersionString(char* out, size_t len)
|
||||
{
|
||||
return serviceDispatch(&g_sysclkSrv, SysClkIpcCmd_GetVersionString,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
|
||||
.buffers = {{out, len}},
|
||||
);
|
||||
}
|
||||
|
||||
Result sysclkIpcGetCurrentContext(SysClkContext* out_context)
|
||||
{
|
||||
return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetCurrentContext, *out_context);
|
||||
return serviceDispatch(&g_sysclkSrv, SysClkIpcCmd_GetCurrentContext,
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
|
||||
.buffers = {{out_context, sizeof(SysClkContext)}},
|
||||
);
|
||||
}
|
||||
|
||||
Result sysclkIpcGetProfileCount(u64 tid, u8* out_count)
|
||||
@@ -112,7 +115,7 @@ Result sysclkIpcSetOverride(SysClkModule module, u32 hz)
|
||||
Result sysclkIpcGetProfiles(u64 tid, SysClkTitleProfileList* out_profiles)
|
||||
{
|
||||
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_GetProfiles, tid,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
|
||||
.buffers = {{out_profiles, sizeof(SysClkTitleProfileList)}},
|
||||
);
|
||||
}
|
||||
@@ -128,7 +131,7 @@ Result sysclkIpcSetProfiles(u64 tid, SysClkTitleProfileList* profiles)
|
||||
Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues)
|
||||
{
|
||||
return serviceDispatch(&g_sysclkSrv, SysClkIpcCmd_GetConfigValues,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
|
||||
.buffers = {{out_configValues, sizeof(SysClkConfigValueList)}},
|
||||
);
|
||||
}
|
||||
@@ -136,7 +139,7 @@ Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues)
|
||||
Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues)
|
||||
{
|
||||
return serviceDispatch(&g_sysclkSrv, SysClkIpcCmd_SetConfigValues,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In },
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_In },
|
||||
.buffers = {{configValues, sizeof(SysClkConfigValueList)}},
|
||||
);
|
||||
}
|
||||
@@ -153,12 +156,6 @@ Result sysclkIpcGetFreqList(SysClkModule module, u32* list, u32 maxCount, u32* o
|
||||
);
|
||||
}
|
||||
|
||||
Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode)
|
||||
{
|
||||
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetReverseNXRTMode, mode);
|
||||
}
|
||||
|
||||
|
||||
Result hocClkIpcSetKipData()
|
||||
{
|
||||
u32 temp = 0;
|
||||
@@ -169,15 +166,4 @@ Result hocClkIpcGetKipData()
|
||||
{
|
||||
u32 temp = 0;
|
||||
return serviceDispatchIn(&g_sysclkSrv, HocClkIpcCmd_GetKipData, temp);
|
||||
}
|
||||
|
||||
Result hocClkIpcUpdateEmcRegs()
|
||||
{
|
||||
u32 temp = 0;
|
||||
return serviceDispatchIn(&g_sysclkSrv, HocClkIpcCmd_UpdateEmcRegs, temp);
|
||||
}
|
||||
Result hocClkIpcCalculateGpuVmin()
|
||||
{
|
||||
u32 temp = 0;
|
||||
return serviceDispatchIn(&g_sysclkSrv, HocClkIpcCmd_CalculateGpuVmin, temp);
|
||||
}
|
||||
5
Source/rewrite-hoc-clk/.gitignore
vendored
Normal file
5
Source/rewrite-hoc-clk/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/dist
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
desktop.ini
|
||||
.vscode
|
||||
17
Source/rewrite-hoc-clk/.gitlab-ci.yml
Normal file
17
Source/rewrite-hoc-clk/.gitlab-ci.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
image: $CI_SERVER_HOST:4567/libretro/infrastructure/libretro-build-libnx-devkitpro:latest
|
||||
|
||||
variables:
|
||||
PACKAGE_FOLDER: "sys-clk"
|
||||
|
||||
stages:
|
||||
- package
|
||||
|
||||
nightly:
|
||||
stage: package
|
||||
script:
|
||||
- bash build.sh $PACKAGE_FOLDER
|
||||
artifacts:
|
||||
name: $PACKAGE_FOLDER
|
||||
expire_in: 24 hours
|
||||
paths:
|
||||
- $PACKAGE_FOLDER
|
||||
3
Source/rewrite-hoc-clk/.gitmodules
vendored
Normal file
3
Source/rewrite-hoc-clk/.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "overlay/lib/libultrahand"]
|
||||
path = overlay/lib/libultrahand
|
||||
url = https://github.com/ppkantorski/libultrahand
|
||||
7
Source/rewrite-hoc-clk/LICENSE
Normal file
7
Source/rewrite-hoc-clk/LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
--------------------------------------------------------------------------
|
||||
"THE BEER-WARE LICENSE" (Revision 42):
|
||||
<p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
wrote this file. As long as you retain this notice you can do whatever you
|
||||
want with this stuff. If you meet any of us some day, and you think this
|
||||
stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
--------------------------------------------------------------------------
|
||||
6
Source/rewrite-hoc-clk/README.md
Normal file
6
Source/rewrite-hoc-clk/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# hoc-clk
|
||||
|
||||
Switch sysmodule allowing you to set cpu/gpu/mem clocks according to the running application and docked state.
|
||||
Modified for Horizon OC
|
||||
|
||||
Support is only provided for FW 16.0.0+. This MAY work on older firmwares but support is NOT guaranteed
|
||||
53
Source/rewrite-hoc-clk/bitmap.py
Normal file
53
Source/rewrite-hoc-clk/bitmap.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from PIL import Image
|
||||
import argparse
|
||||
import os
|
||||
|
||||
def image_to_rgba8888_array(image_path, output_path):
|
||||
# Open and convert to RGBA
|
||||
img = Image.open(image_path).convert('RGBA')
|
||||
width, height = img.size
|
||||
|
||||
# Get pixel data
|
||||
pixels = img.tobytes()
|
||||
|
||||
# Write as C header file
|
||||
with open(output_path, 'w') as f:
|
||||
f.write('// This is a automatically generated file, do not edit manually.\n')
|
||||
f.write(f'// {os.path.basename(image_path)} - {width}x{height}\n')
|
||||
f.write(f'const unsigned int IMG_WIDTH = {width};\n')
|
||||
f.write(f'const unsigned int IMG_HEIGHT = {height};\n')
|
||||
f.write('const unsigned char IMG_DATA[] = {\n ')
|
||||
|
||||
for i, byte in enumerate(pixels):
|
||||
f.write(f'0x{byte:02X}')
|
||||
if i < len(pixels) - 1:
|
||||
f.write(', ')
|
||||
if (i + 1) % 12 == 0:
|
||||
f.write('\n ')
|
||||
|
||||
f.write('\n};\n')
|
||||
|
||||
print(f'Converted: {width}x{height} -> {len(pixels)} bytes')
|
||||
print(f'Output: {output_path}')
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='PNG to RGB8888 script'
|
||||
)
|
||||
parser.add_argument('input', help='Input image file (e.g. cat.png)')
|
||||
parser.add_argument(
|
||||
'-o', '--output',
|
||||
help='Output header file (default: <input>.h)'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
output_path = args.output
|
||||
if not output_path:
|
||||
base, _ = os.path.splitext(args.input)
|
||||
output_path = base + '.h'
|
||||
|
||||
image_to_rgba8888_array(args.input, output_path)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
42
Source/rewrite-hoc-clk/build.sh
Normal file
42
Source/rewrite-hoc-clk/build.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
DIST_DIR="$ROOT_DIR/dist"
|
||||
CORES="$(nproc --all)"
|
||||
|
||||
if [[ -n "$1" ]]; then
|
||||
DIST_DIR="$1"
|
||||
fi
|
||||
|
||||
echo "DIST_DIR: $DIST_DIR"
|
||||
echo "CORES: $CORES"
|
||||
|
||||
echo "*** sysmodule ***"
|
||||
TITLE_ID="$(grep -oP '"title_id":\s*"0x\K(\w+)' "$ROOT_DIR/sysmodule/perms.json")"
|
||||
|
||||
pushd "$ROOT_DIR/sysmodule"
|
||||
make -j$CORES
|
||||
popd > /dev/null
|
||||
|
||||
mkdir -p "$DIST_DIR/atmosphere/contents/$TITLE_ID/flags"
|
||||
cp -vf "$ROOT_DIR/sysmodule/out/horizon-oc.nsp" "$DIST_DIR/atmosphere/contents/$TITLE_ID/exefs.nsp"
|
||||
>"$DIST_DIR/atmosphere/contents/$TITLE_ID/flags/boot2.flag"
|
||||
cp -vf "$ROOT_DIR/sysmodule/toolbox.json" "$DIST_DIR/atmosphere/contents/$TITLE_ID/toolbox.json"
|
||||
|
||||
echo "*** overlay ***"
|
||||
pushd "$ROOT_DIR/overlay"
|
||||
make -j$CORES
|
||||
popd > /dev/null
|
||||
|
||||
mkdir -p "$DIST_DIR/switch/.overlays"
|
||||
cp -vf "$ROOT_DIR/overlay/out/horizon-oc-overlay.ovl" "$DIST_DIR/switch/.overlays/horizon-oc-overlay.ovl"
|
||||
|
||||
echo "*** assets ***"
|
||||
mkdir -p "$DIST_DIR/config/horizon-oc"
|
||||
cp -vf "$ROOT_DIR/config.ini.template" "$DIST_DIR/config/horizon-oc/config.ini.template"
|
||||
cp -vf "$ROOT_DIR/../../README.md" "$DIST_DIR/README.md"
|
||||
|
||||
echo "*** lang ***"
|
||||
|
||||
cp -r "$ROOT_DIR/overlay/lang/" "$DIST_DIR/config/horizon-oc/lang/"
|
||||
248
Source/rewrite-hoc-clk/common/include/SaltyNX.h
Normal file
248
Source/rewrite-hoc-clk/common/include/SaltyNX.h
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Copyright (c) MasaGratoR
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "ipc.h"
|
||||
|
||||
Handle saltysd_orig;
|
||||
|
||||
Result SaltySD_Connect() {
|
||||
for (int i = 0; i < 200; i++) {
|
||||
if (!svcConnectToNamedPort(&saltysd_orig, "SaltySD"))
|
||||
return 0;
|
||||
svcSleepThread(1000*1000);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
Result SaltySD_Term()
|
||||
{
|
||||
Result ret;
|
||||
IpcCommand c;
|
||||
|
||||
ipcInitialize(&c);
|
||||
ipcSendPid(&c);
|
||||
|
||||
struct input
|
||||
{
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 zero;
|
||||
u64 reserved[2];
|
||||
} *raw;
|
||||
|
||||
raw = (input*)ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 0;
|
||||
raw->zero = 0;
|
||||
|
||||
ret = ipcDispatch(saltysd_orig);
|
||||
|
||||
if (R_SUCCEEDED(ret))
|
||||
{
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct output {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp = (output*)r.Raw;
|
||||
|
||||
ret = resp->result;
|
||||
}
|
||||
|
||||
// Session terminated works too.
|
||||
svcCloseHandle(saltysd_orig);
|
||||
if (ret == 0xf601) return 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result SaltySD_CheckIfSharedMemoryAvailable(ptrdiff_t *offset, u64 size)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
// Send a command
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcSendPid(&c);
|
||||
|
||||
struct input {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 size;
|
||||
u32 reserved[2];
|
||||
} *raw;
|
||||
|
||||
raw = (input*)ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 6;
|
||||
raw->size = size;
|
||||
|
||||
ret = ipcDispatch(saltysd_orig);
|
||||
|
||||
if (R_SUCCEEDED(ret)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct output {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u64 offset;
|
||||
} *resp = (output*)r.Raw;
|
||||
|
||||
ret = resp->result;
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
*offset = resp->offset;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result SaltySD_GetSharedMemoryHandle(Handle *retrieve)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
// Send a command
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcSendPid(&c);
|
||||
|
||||
struct input {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u32 reserved[4];
|
||||
} *raw;
|
||||
|
||||
raw = (input*)ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 7;
|
||||
|
||||
ret = ipcDispatch(saltysd_orig);
|
||||
|
||||
if (R_SUCCEEDED(ret)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct output {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u64 reserved[2];
|
||||
} *resp = (output*)r.Raw;
|
||||
|
||||
ret = resp->result;
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
*retrieve = r.Handles[0];
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result SaltySD_GetDisplayRefreshRate(uint8_t* refreshRate)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
// Send a command
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcSendPid(&c);
|
||||
|
||||
struct input {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 zero;
|
||||
u64 reserved;
|
||||
} *raw;
|
||||
|
||||
raw = (input*)ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 10;
|
||||
raw->zero = 0;
|
||||
|
||||
ret = ipcDispatch(saltysd_orig);
|
||||
|
||||
if (R_SUCCEEDED(ret)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct output {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u64 refreshRate;
|
||||
u64 reserved;
|
||||
} *resp = (output*)r.Raw;
|
||||
|
||||
ret = resp->result;
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
*refreshRate = (uint8_t)(resp->refreshRate);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result SaltySD_SetDisplayRefreshRate(uint8_t refreshRate)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
// Send a command
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcSendPid(&c);
|
||||
|
||||
struct input {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
u64 refreshRate;
|
||||
u64 reserved;
|
||||
} *raw;
|
||||
|
||||
raw = (input*)ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 11;
|
||||
raw->refreshRate = refreshRate;
|
||||
|
||||
ret = ipcDispatch(saltysd_orig);
|
||||
|
||||
if (R_SUCCEEDED(ret)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct output {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u64 reserved[2];
|
||||
} *resp = (output*)r.Raw;
|
||||
|
||||
ret = resp->result;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
252
Source/rewrite-hoc-clk/common/include/battery.h
Normal file
252
Source/rewrite-hoc-clk/common/include/battery.h
Normal file
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
typedef enum {
|
||||
BatteryFlag_NoHub = BIT(0), // Hub is disconnected
|
||||
BatteryFlag_Rail = BIT(8), // At least one Joy-con is charging from rail
|
||||
BatteryFlag_SPDSRC = BIT(12), // OTG
|
||||
BatteryFlag_ACC = BIT(16) // Accessory
|
||||
} BatteryChargeFlags;
|
||||
|
||||
typedef enum {
|
||||
PDState_NewPDO = 1, // Received new Power Data Object
|
||||
PDState_NoPD = 2, // No Power Delivery source is detected
|
||||
PDState_AcceptedRDO = 3 // Received and accepted Request Data Object
|
||||
} BatteryPDControllerState;
|
||||
|
||||
// Charger type detection
|
||||
typedef enum {
|
||||
ChargerType_None = 0,
|
||||
ChargerType_PD = 1,
|
||||
ChargerType_TypeC_1500mA = 2,
|
||||
ChargerType_TypeC_3000mA = 3,
|
||||
ChargerType_DCP = 4, // Dedicated Charging Port
|
||||
ChargerType_CDP = 5, // Charging Downstream Port
|
||||
ChargerType_SDP = 6, // Standard Downstream Port
|
||||
ChargerType_Apple_500mA = 7,
|
||||
ChargerType_Apple_1000mA = 8,
|
||||
ChargerType_Apple_2000mA = 9
|
||||
} BatteryChargerType;
|
||||
typedef enum {
|
||||
PowerRole_Sink = 1, // Device is receiving power
|
||||
PowerRole_Source = 2 // Device is providing power
|
||||
} BatteryPowerRole;
|
||||
|
||||
typedef struct {
|
||||
int32_t InputCurrentLimit; // Input (Sink) current limit in mA
|
||||
int32_t VBUSCurrentLimit; // Output (Source/VBUS/OTG) current limit in mA
|
||||
int32_t ChargeCurrentLimit; // Battery charging current limit in mA
|
||||
int32_t ChargeVoltageLimit; // Battery charging voltage limit in mV
|
||||
int32_t unk_x10; // Unknown field (possibly enum)
|
||||
int32_t unk_x14; // Unknown field (possibly flags)
|
||||
BatteryPDControllerState PDControllerState; // PD Controller State
|
||||
int32_t BatteryTemperature; // Battery temperature in milli-Celsius
|
||||
int32_t RawBatteryCharge; // Battery charge in percentmille
|
||||
int32_t VoltageAvg; // Average voltage in mV
|
||||
int32_t BatteryAge; // Battery health (capacity full/design) in pcm
|
||||
BatteryPowerRole PowerRole; // Current power role
|
||||
BatteryChargerType ChargerType; // Type of charger connected
|
||||
int32_t ChargerVoltageLimit; // Charger voltage limit in mV
|
||||
int32_t ChargerCurrentLimit; // Charger current limit in mA
|
||||
BatteryChargeFlags Flags; // Various status flags
|
||||
} BatteryChargeInfo;
|
||||
|
||||
#define IS_BATTERY_CHARGING_ENABLED(info) (((info)->unk_x14 >> 8) & 1)
|
||||
|
||||
Result batteryInfoInitialize(void);
|
||||
|
||||
void batteryInfoExit(void);
|
||||
|
||||
Result batteryInfoGetChargeInfo(BatteryChargeInfo *out);
|
||||
|
||||
Result batteryInfoGetChargePercentage(u32 *out);
|
||||
|
||||
Result batteryInfoIsEnoughPowerSupplied(bool *out);
|
||||
|
||||
Result batteryInfoEnableCharging(void);
|
||||
Result batteryInfoDisableCharging(void);
|
||||
Result batteryInfoEnableFastCharging(void);
|
||||
Result batteryInfoDisableFastCharging(void);
|
||||
|
||||
const char* batteryInfoGetChargerTypeString(BatteryChargerType type);
|
||||
const char* batteryInfoGetPowerRoleString(BatteryPowerRole role);
|
||||
const char* batteryInfoGetPDStateString(BatteryPDControllerState state);
|
||||
|
||||
static inline int batteryInfoGetTemperatureMiliCelsius(BatteryChargeInfo *info) {
|
||||
return info->BatteryTemperature;
|
||||
}
|
||||
|
||||
static inline float batteryInfoGetChargePercent(BatteryChargeInfo *info) {
|
||||
return (float)info->RawBatteryCharge / 1000.0f;
|
||||
}
|
||||
|
||||
static inline float batteryInfoGetBatteryHealthPercent(BatteryChargeInfo *info) {
|
||||
return (float)info->BatteryAge / 1000.0f;
|
||||
}
|
||||
|
||||
static inline bool batteryInfoIsCharging(BatteryChargeInfo *info) {
|
||||
return IS_BATTERY_CHARGING_ENABLED(info);
|
||||
}
|
||||
|
||||
static const char* s_chargerTypeStrings[] = {
|
||||
"None",
|
||||
"Power Delivery",
|
||||
"USB-C @ 1.5A",
|
||||
"USB-C @ 3.0A",
|
||||
"USB-DCP",
|
||||
"USB-CDP",
|
||||
"USB-SDP",
|
||||
"Apple @ 0.5A",
|
||||
"Apple @ 1.0A",
|
||||
"Apple @ 2.0A",
|
||||
};
|
||||
|
||||
static const char* s_powerRoleStrings[] = {
|
||||
"Unknown",
|
||||
"Sink",
|
||||
"Source",
|
||||
};
|
||||
|
||||
static const char* s_pdStateStrings[] = {
|
||||
"Unknown",
|
||||
"New PDO Received",
|
||||
"No PD Source",
|
||||
"RDO Accepted"
|
||||
};
|
||||
|
||||
// Internal PSM service handle
|
||||
static Service g_psmService = {0};
|
||||
static bool g_batteryInfoInitialized = false;
|
||||
|
||||
// Internal PSM command implementations
|
||||
static Result psmGetBatteryChargeInfoFields(BatteryChargeInfo *out) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatchOut(&g_psmService, 17, *out);
|
||||
}
|
||||
|
||||
static Result psmEnableBatteryCharging_internal(void) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatch(&g_psmService, 2);
|
||||
}
|
||||
|
||||
static Result psmDisableBatteryCharging_internal(void) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatch(&g_psmService, 3);
|
||||
}
|
||||
|
||||
static Result psmEnableFastBatteryCharging_internal(void) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatch(&g_psmService, 10);
|
||||
}
|
||||
|
||||
static Result psmDisableFastBatteryCharging_internal(void) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatch(&g_psmService, 11);
|
||||
}
|
||||
|
||||
Result batteryInfoInitialize(void) {
|
||||
if (g_batteryInfoInitialized)
|
||||
return 0;
|
||||
|
||||
Result rc = psmInitialize();
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
memcpy(&g_psmService, psmGetServiceSession(), sizeof(Service));
|
||||
g_batteryInfoInitialized = true;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void batteryInfoExit(void) {
|
||||
if (g_batteryInfoInitialized) {
|
||||
psmExit();
|
||||
memset(&g_psmService, 0, sizeof(Service));
|
||||
g_batteryInfoInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
Result batteryInfoGetChargeInfo(BatteryChargeInfo *out) {
|
||||
if (!out)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||
|
||||
return psmGetBatteryChargeInfoFields(out);
|
||||
}
|
||||
|
||||
Result batteryInfoGetChargePercentage(u32 *out) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return psmGetBatteryChargePercentage(out);
|
||||
}
|
||||
|
||||
Result batteryInfoIsEnoughPowerSupplied(bool *out) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return psmIsEnoughPowerSupplied(out);
|
||||
}
|
||||
|
||||
Result batteryInfoEnableCharging(void) {
|
||||
return psmEnableBatteryCharging_internal();
|
||||
}
|
||||
|
||||
Result batteryInfoDisableCharging(void) {
|
||||
return psmDisableBatteryCharging_internal();
|
||||
}
|
||||
|
||||
Result batteryInfoEnableFastCharging(void) {
|
||||
return psmEnableFastBatteryCharging_internal();
|
||||
}
|
||||
|
||||
Result batteryInfoDisableFastCharging(void) {
|
||||
return psmDisableFastBatteryCharging_internal();
|
||||
}
|
||||
|
||||
const char* batteryInfoGetChargerTypeString(BatteryChargerType type) {
|
||||
if (type < 0 || type > ChargerType_Apple_2000mA)
|
||||
return "Unknown";
|
||||
|
||||
return s_chargerTypeStrings[type];
|
||||
}
|
||||
|
||||
const char* batteryInfoGetPowerRoleString(BatteryPowerRole role) {
|
||||
if (role < PowerRole_Sink || role > PowerRole_Source)
|
||||
return s_powerRoleStrings[0];
|
||||
|
||||
return s_powerRoleStrings[role];
|
||||
}
|
||||
|
||||
const char* batteryInfoGetPDStateString(BatteryPDControllerState state) {
|
||||
if (state < PDState_NewPDO || state > PDState_AcceptedRDO)
|
||||
return s_pdStateStrings[0];
|
||||
|
||||
return s_pdStateStrings[state];
|
||||
}
|
||||
53
Source/rewrite-hoc-clk/common/include/cpp_util.hpp
Normal file
53
Source/rewrite-hoc-clk/common/include/cpp_util.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) meha3945 (hanai3bi)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
template<typename F>
|
||||
class ScopeGuard {
|
||||
public:
|
||||
ScopeGuard(F&& f)
|
||||
: f(f), engaged(true) {};
|
||||
|
||||
~ScopeGuard() {
|
||||
if (engaged)
|
||||
f();
|
||||
};
|
||||
|
||||
ScopeGuard(ScopeGuard&& rhs)
|
||||
: f(std::move(rhs.f)) {};
|
||||
|
||||
void dismiss() { engaged = false; }
|
||||
|
||||
private:
|
||||
F f;
|
||||
bool engaged;
|
||||
};
|
||||
|
||||
struct MakeScopeExit {
|
||||
template<typename F>
|
||||
ScopeGuard<F> operator+=(F&& f) {
|
||||
return ScopeGuard<F>(std::move(f));
|
||||
};
|
||||
};
|
||||
|
||||
#define STRING_CAT2(x, y) x##y
|
||||
#define STRING_CAT(x, y) STRING_CAT2(x, y)
|
||||
#define SCOPE_GUARD MakeScopeExit() += [&]() __attribute__((always_inline))
|
||||
#define SCOPE_EXIT auto STRING_CAT(scope_exit_, __LINE__) = SCOPE_GUARD
|
||||
56
Source/rewrite-hoc-clk/common/include/crc32.h
Normal file
56
Source/rewrite-hoc-clk/common/include/crc32.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t crc32(const uint8_t *data, size_t length) {
|
||||
uint32_t crc = 0xFFFFFFFF;
|
||||
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
crc ^= data[i];
|
||||
for (int j = 0; j < 8; j++) {
|
||||
crc = (crc >> 1) ^ (0xEDB88320 & -(crc & 1));
|
||||
}
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
uint32_t checksum_file(const char *filename) {
|
||||
FILE *file = fopen(filename, "rb");
|
||||
if (!file) {
|
||||
perror("[crc32] Error opening file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t buffer[1024];
|
||||
uint32_t crc = 0xFFFFFFFF;
|
||||
size_t bytes_read;
|
||||
|
||||
while ((bytes_read = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
||||
for (size_t i = 0; i < bytes_read; i++) {
|
||||
crc ^= buffer[i];
|
||||
for (int j = 0; j < 8; j++) {
|
||||
crc = (crc >> 1) ^ (0xEDB88320 & -(crc & 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
return ~crc;
|
||||
}
|
||||
126
Source/rewrite-hoc-clk/common/include/display_refresh_rate.h
Normal file
126
Source/rewrite-hoc-clk/common/include/display_refresh_rate.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, based on reasearch by MasaGratoR and Cooler3D
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t hFrontPorch;
|
||||
uint8_t hSyncWidth;
|
||||
uint8_t hBackPorch;
|
||||
uint8_t vFrontPorch;
|
||||
uint8_t vSyncWidth;
|
||||
uint8_t vBackPorch;
|
||||
uint8_t VIC;
|
||||
uint32_t pixelClock_kHz;
|
||||
} DockedTimings;
|
||||
|
||||
typedef struct {
|
||||
uint8_t hSyncWidth;
|
||||
uint16_t hFrontPorch;
|
||||
uint8_t hBackPorch;
|
||||
uint8_t vSyncWidth;
|
||||
uint16_t vFrontPorch;
|
||||
uint8_t vBackPorch;
|
||||
uint32_t pixelClock_kHz;
|
||||
} HandheldTimings;
|
||||
|
||||
typedef struct {
|
||||
uint8_t min;
|
||||
uint8_t max;
|
||||
} MinMaxRefreshRate;
|
||||
|
||||
typedef struct {
|
||||
uint32_t unk0;
|
||||
uint32_t hActive;
|
||||
uint32_t vActive;
|
||||
uint32_t hSyncWidth;
|
||||
uint32_t vSyncWidth;
|
||||
uint32_t hFrontPorch;
|
||||
uint32_t vFrontPorch;
|
||||
uint32_t hBackPorch;
|
||||
uint32_t vBackPorch;
|
||||
uint32_t pclkKHz;
|
||||
uint32_t bitsPerPixel;
|
||||
uint32_t vmode;
|
||||
uint32_t sync;
|
||||
uint32_t unk1;
|
||||
uint32_t reserved;
|
||||
} NvdcMode2;
|
||||
|
||||
typedef struct {
|
||||
NvdcMode2 modes[201];
|
||||
uint32_t num_modes;
|
||||
} NvdcModeDB2;
|
||||
|
||||
typedef struct {
|
||||
unsigned int PLLD_DIVM: 8;
|
||||
unsigned int reserved_1: 3;
|
||||
unsigned int PLLD_DIVN: 8;
|
||||
unsigned int reserved_2: 1;
|
||||
unsigned int PLLD_DIVP: 3;
|
||||
unsigned int CSI_CLK_SRC: 1;
|
||||
unsigned int reserved_3: 1;
|
||||
unsigned int PLL_D: 1;
|
||||
unsigned int reserved_4: 1;
|
||||
unsigned int PLLD_LOCK: 1;
|
||||
unsigned int reserved_5: 1;
|
||||
unsigned int PLLD_REF_DIS: 1;
|
||||
unsigned int PLLD_ENABLE: 1;
|
||||
unsigned int PLLD_BYPASS: 1;
|
||||
} PLLD_BASE;
|
||||
|
||||
typedef struct {
|
||||
signed int PLLD_SDM_DIN: 16;
|
||||
unsigned int PLLD_EN_SDM: 1;
|
||||
unsigned int PLLD_LOCK_OVERRIDE: 1;
|
||||
unsigned int PLLD_EN_LCKDET: 1;
|
||||
unsigned int PLLD_FREQLOCK: 1;
|
||||
unsigned int PLLD_IDDQ: 1;
|
||||
unsigned int PLLD_ENABLE_CLK: 1;
|
||||
unsigned int PLLD_KVCO: 1;
|
||||
unsigned int PLLD_KCP: 2;
|
||||
unsigned int PLLD_PTS: 2;
|
||||
unsigned int PLLD_LDPULSE_ADJ: 3;
|
||||
unsigned int reserved: 2;
|
||||
} PLLD_MISC;
|
||||
|
||||
typedef struct {
|
||||
uint64_t clkVirtAddr;
|
||||
uint64_t dsiVirtAddr;
|
||||
bool isDocked;
|
||||
bool isLite;
|
||||
bool isRetroSUPER;
|
||||
bool isPossiblySpoofedRetro;
|
||||
bool dontForce60InDocked;
|
||||
bool matchLowestDocked;
|
||||
bool displaySync;
|
||||
bool displaySyncOutOfFocus60;
|
||||
bool displaySyncDocked;
|
||||
bool displaySyncDockedOutOfFocus60;
|
||||
} DisplayRefreshConfig;
|
||||
bool DisplayRefresh_Initialize(const DisplayRefreshConfig* config);
|
||||
void DisplayRefresh_SetDockedState(bool isDocked);
|
||||
bool DisplayRefresh_SetRate(uint32_t new_refreshRate);
|
||||
bool DisplayRefresh_GetRate(uint32_t* out_refreshRate, bool internal);
|
||||
uint8_t DisplayRefresh_GetDockedHighestAllowed(void);
|
||||
void DisplayRefresh_CorrectOledGamma(uint32_t refresh_rate);
|
||||
void DisplayRefresh_SetAllowedDockedRatesIPC(uint32_t refreshRates, bool is720p);
|
||||
void DisplayRefresh_Shutdown(void);
|
||||
62
Source/rewrite-hoc-clk/common/include/i2c.h
Normal file
62
Source/rewrite-hoc-clk/common/include/i2c.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2023 KazushiMe
|
||||
* Licensed under the GPLv2
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
// To use i2c service, sm and i2c should be intialized via smInitialize() and i2cInitialize().
|
||||
|
||||
Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val);
|
||||
|
||||
Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out);
|
||||
Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out);
|
||||
|
||||
// Max17050 fuel gauge
|
||||
float I2c_Max17050_GetBatteryCurrent();
|
||||
|
||||
const u8 MAX17050_CURRENT_REG = 0x0A;
|
||||
|
||||
// Buck Converter
|
||||
typedef enum I2c_BuckConverter_Reg {
|
||||
I2c_Max77620_SD1VOLT_REG = 0x17, // Used for Erista DDR VDDQ+VDD2 / Mariko VDD2
|
||||
I2c_Max77621_VOLT_REG = 0x00,
|
||||
I2c_Max77812_CPUVOLT_REG = 0x26,
|
||||
I2c_Max77812_GPUVOLT_REG = 0x23,
|
||||
I2c_Max77812_MEMVOLT_REG = 0x25, // Master 3 (GPU 1 + 2, DRAM 3, CPU 4), used for Mariko VDDQ
|
||||
} I2c_BuckConverter_Reg;
|
||||
|
||||
typedef struct I2c_BuckConverter_Domain {
|
||||
I2cDevice device;
|
||||
I2c_BuckConverter_Reg reg;
|
||||
u8 volt_mask;
|
||||
u32 uv_step;
|
||||
u32 uv_min;
|
||||
u32 uv_max;
|
||||
u8 por_val;
|
||||
} I2c_BuckConverter_Domain;
|
||||
|
||||
const I2c_BuckConverter_Domain I2c_Erista_CPU = { I2cDevice_Max77621Cpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000, };
|
||||
const I2c_BuckConverter_Domain I2c_Erista_GPU = { I2cDevice_Max77621Gpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000, };
|
||||
const I2c_BuckConverter_Domain I2c_Erista_DRAM = { I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1250000, };
|
||||
const I2c_BuckConverter_Domain I2c_Mariko_CPU = { I2cDevice_Max77812_2, I2c_Max77812_CPUVOLT_REG, 0xFF, 5000, 250000, 1525000, 0x78 };
|
||||
const I2c_BuckConverter_Domain I2c_Mariko_GPU = { I2cDevice_Max77812_2, I2c_Max77812_GPUVOLT_REG, 0xFF, 5000, 250000, 1525000, 0x78 };
|
||||
const I2c_BuckConverter_Domain I2c_Mariko_DRAM_VDDQ = { I2cDevice_Max77812_2, I2c_Max77812_MEMVOLT_REG, 0xFF, 5000, 250000, 700000, 0x78 };
|
||||
const I2c_BuckConverter_Domain I2c_Mariko_DRAM_VDD2 = { I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1250000, };
|
||||
|
||||
u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain* domain);
|
||||
Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain* domain, u32 mvolt);
|
||||
|
||||
// Bq24193 Battery management
|
||||
u32 I2c_Bq24193_Convert_Raw_mA(u8 raw);
|
||||
u8 I2c_Bq24193_Convert_mA_Raw(u32 ma);
|
||||
|
||||
Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma);
|
||||
Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma);
|
||||
|
||||
const u32 MA_RANGE_MIN = 512;
|
||||
const u32 MA_RANGE_MAX = 4544;
|
||||
|
||||
const u8 BQ24193_CHARGE_CURRENT_CONTROL_REG = 0x2;
|
||||
756
Source/rewrite-hoc-clk/common/include/ipc.h
Normal file
756
Source/rewrite-hoc-clk/common/include/ipc.h
Normal file
@@ -0,0 +1,756 @@
|
||||
/**
|
||||
* @file ipc.h
|
||||
* @brief Inter-process communication handling
|
||||
* @author plutoo
|
||||
* @copyright libnx Authors (ISC License)
|
||||
*/
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
|
||||
/// IPC input header magic
|
||||
#define SFCI_MAGIC 0x49434653
|
||||
/// IPC output header magic
|
||||
#define SFCO_MAGIC 0x4f434653
|
||||
|
||||
/// IPC invalid object ID
|
||||
#define IPC_INVALID_OBJECT_ID UINT32_MAX
|
||||
|
||||
///@name IPC request building
|
||||
///@{
|
||||
|
||||
/// IPC command (request) structure.
|
||||
#define IPC_MAX_BUFFERS 8
|
||||
#define IPC_MAX_OBJECTS 8
|
||||
|
||||
typedef enum {
|
||||
BufferType_Normal=0, ///< Regular buffer.
|
||||
BufferType_Type1=1, ///< Allows ProcessMemory and shared TransferMemory.
|
||||
BufferType_Invalid=2,
|
||||
BufferType_Type3=3 ///< Same as Type1 except remote process is not allowed to use device-mapping.
|
||||
} BufferType;
|
||||
|
||||
typedef enum {
|
||||
BufferDirection_Send=0,
|
||||
BufferDirection_Recv=1,
|
||||
BufferDirection_Exch=2,
|
||||
} BufferDirection;
|
||||
|
||||
typedef enum {
|
||||
IpcCommandType_Invalid = 0,
|
||||
IpcCommandType_LegacyRequest = 1,
|
||||
IpcCommandType_Close = 2,
|
||||
IpcCommandType_LegacyControl = 3,
|
||||
IpcCommandType_Request = 4,
|
||||
IpcCommandType_Control = 5,
|
||||
IpcCommandType_RequestWithContext = 6,
|
||||
IpcCommandType_ControlWithContext = 7,
|
||||
} IpcCommandType;
|
||||
|
||||
typedef enum {
|
||||
DomainMessageType_Invalid = 0,
|
||||
DomainMessageType_SendMessage = 1,
|
||||
DomainMessageType_Close = 2,
|
||||
} DomainMessageType;
|
||||
|
||||
/// IPC domain message header.
|
||||
typedef struct {
|
||||
u8 Type;
|
||||
u8 NumObjectIds;
|
||||
u16 Length;
|
||||
u32 ThisObjectId;
|
||||
u32 Pad[2];
|
||||
} DomainMessageHeader;
|
||||
|
||||
/// IPC domain response header.
|
||||
typedef struct {
|
||||
u32 NumObjectIds;
|
||||
u32 Pad[3];
|
||||
} DomainResponseHeader;
|
||||
|
||||
|
||||
typedef struct {
|
||||
size_t NumSend; // A
|
||||
size_t NumRecv; // B
|
||||
size_t NumExch; // W
|
||||
const void* Buffers[IPC_MAX_BUFFERS];
|
||||
size_t BufferSizes[IPC_MAX_BUFFERS];
|
||||
BufferType BufferTypes[IPC_MAX_BUFFERS];
|
||||
|
||||
size_t NumStaticIn; // X
|
||||
size_t NumStaticOut; // C
|
||||
const void* Statics[IPC_MAX_BUFFERS];
|
||||
size_t StaticSizes[IPC_MAX_BUFFERS];
|
||||
u8 StaticIndices[IPC_MAX_BUFFERS];
|
||||
|
||||
bool SendPid;
|
||||
size_t NumHandlesCopy;
|
||||
size_t NumHandlesMove;
|
||||
Handle Handles[IPC_MAX_OBJECTS];
|
||||
|
||||
size_t NumObjectIds;
|
||||
u32 ObjectIds[IPC_MAX_OBJECTS];
|
||||
} IpcCommand;
|
||||
|
||||
/**
|
||||
* @brief Initializes an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
*/
|
||||
static inline void ipcInitialize(IpcCommand* cmd) {
|
||||
*cmd = (IpcCommand){};
|
||||
}
|
||||
|
||||
/// IPC buffer descriptor.
|
||||
typedef struct {
|
||||
u32 Size; ///< Size of the buffer.
|
||||
u32 Addr; ///< Lower 32-bits of the address of the buffer
|
||||
u32 Packed; ///< Packed data (including higher bits of the address)
|
||||
} IpcBufferDescriptor;
|
||||
|
||||
/// IPC static send-buffer descriptor.
|
||||
typedef struct {
|
||||
u32 Packed; ///< Packed data (including higher bits of the address)
|
||||
u32 Addr; ///< Lower 32-bits of the address
|
||||
} IpcStaticSendDescriptor;
|
||||
|
||||
/// IPC static receive-buffer descriptor.
|
||||
typedef struct {
|
||||
u32 Addr; ///< Lower 32-bits of the address of the buffer
|
||||
u32 Packed; ///< Packed data (including higher bits of the address)
|
||||
} IpcStaticRecvDescriptor;
|
||||
|
||||
/**
|
||||
* @brief Adds a buffer to an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param buffer Address of the buffer.
|
||||
* @param size Size of the buffer.
|
||||
* @param type Buffer type.
|
||||
*/
|
||||
static inline void ipcAddSendBuffer(IpcCommand* cmd, const void* buffer, size_t size, BufferType type) {
|
||||
size_t off = cmd->NumSend;
|
||||
cmd->Buffers[off] = buffer;
|
||||
cmd->BufferSizes[off] = size;
|
||||
cmd->BufferTypes[off] = type;
|
||||
cmd->NumSend++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a receive-buffer to an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param buffer Address of the buffer.
|
||||
* @param size Size of the buffer.
|
||||
* @param type Buffer type.
|
||||
*/
|
||||
static inline void ipcAddRecvBuffer(IpcCommand* cmd, void* buffer, size_t size, BufferType type) {
|
||||
size_t off = cmd->NumSend + cmd->NumRecv;
|
||||
cmd->Buffers[off] = buffer;
|
||||
cmd->BufferSizes[off] = size;
|
||||
cmd->BufferTypes[off] = type;
|
||||
cmd->NumRecv++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds an exchange-buffer to an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param buffer Address of the buffer.
|
||||
* @param size Size of the buffer.
|
||||
* @param type Buffer type.
|
||||
*/
|
||||
static inline void ipcAddExchBuffer(IpcCommand* cmd, void* buffer, size_t size, BufferType type) {
|
||||
size_t off = cmd->NumSend + cmd->NumRecv + cmd->NumExch;
|
||||
cmd->Buffers[off] = buffer;
|
||||
cmd->BufferSizes[off] = size;
|
||||
cmd->BufferTypes[off] = type;
|
||||
cmd->NumExch++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a static-buffer to an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param buffer Address of the buffer.
|
||||
* @param size Size of the buffer.
|
||||
* @param index Index of buffer.
|
||||
*/
|
||||
static inline void ipcAddSendStatic(IpcCommand* cmd, const void* buffer, size_t size, u8 index) {
|
||||
size_t off = cmd->NumStaticIn;
|
||||
cmd->Statics[off] = buffer;
|
||||
cmd->StaticSizes[off] = size;
|
||||
cmd->StaticIndices[off] = index;
|
||||
cmd->NumStaticIn++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a static-receive-buffer to an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param buffer Address of the buffer.
|
||||
* @param size Size of the buffer.
|
||||
* @param index Index of buffer.
|
||||
*/
|
||||
static inline void ipcAddRecvStatic(IpcCommand* cmd, void* buffer, size_t size, u8 index) {
|
||||
size_t off = cmd->NumStaticIn + cmd->NumStaticOut;
|
||||
cmd->Statics[off] = buffer;
|
||||
cmd->StaticSizes[off] = size;
|
||||
cmd->StaticIndices[off] = index;
|
||||
cmd->NumStaticOut++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a smart-buffer (buffer + static-buffer pair) to an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param pointer_buffer_size Pointer buffer size.
|
||||
* @param buffer Address of the buffer.
|
||||
* @param size Size of the buffer.
|
||||
* @param index Index of buffer.
|
||||
*/
|
||||
static inline void ipcAddSendSmart(IpcCommand* cmd, size_t pointer_buffer_size, const void* buffer, size_t size, u8 index) {
|
||||
if (pointer_buffer_size != 0 && size <= pointer_buffer_size) {
|
||||
ipcAddSendBuffer(cmd, NULL, 0, BufferType_Normal);
|
||||
ipcAddSendStatic(cmd, buffer, size, index);
|
||||
} else {
|
||||
ipcAddSendBuffer(cmd, buffer, size, BufferType_Normal);
|
||||
ipcAddSendStatic(cmd, NULL, 0, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a smart-receive-buffer (buffer + static-receive-buffer pair) to an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param pointer_buffer_size Pointer buffer size.
|
||||
* @param buffer Address of the buffer.
|
||||
* @param size Size of the buffer.
|
||||
* @param index Index of buffer.
|
||||
*/
|
||||
static inline void ipcAddRecvSmart(IpcCommand* cmd, size_t pointer_buffer_size, void* buffer, size_t size, u8 index) {
|
||||
if (pointer_buffer_size != 0 && size <= pointer_buffer_size) {
|
||||
ipcAddRecvBuffer(cmd, NULL, 0, BufferType_Normal);
|
||||
ipcAddRecvStatic(cmd, buffer, size, index);
|
||||
} else {
|
||||
ipcAddRecvBuffer(cmd, buffer, size, BufferType_Normal);
|
||||
ipcAddRecvStatic(cmd, NULL, 0, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tags an IPC command structure to send the PID.
|
||||
* @param cmd IPC command structure.
|
||||
*/
|
||||
static inline void ipcSendPid(IpcCommand* cmd) {
|
||||
cmd->SendPid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a copy-handle to be sent through an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param h Handle to send.
|
||||
* @remark The receiving process gets a copy of the handle.
|
||||
*/
|
||||
static inline void ipcSendHandleCopy(IpcCommand* cmd, Handle h) {
|
||||
cmd->Handles[cmd->NumHandlesCopy++] = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a move-handle to be sent through an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param h Handle to send.
|
||||
* @remark The sending process loses ownership of the handle, which is transferred to the receiving process.
|
||||
*/
|
||||
static inline void ipcSendHandleMove(IpcCommand* cmd, Handle h) {
|
||||
cmd->Handles[cmd->NumHandlesCopy + cmd->NumHandlesMove++] = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prepares the header of an IPC command structure.
|
||||
* @param cmd IPC command structure.
|
||||
* @param sizeof_raw Size in bytes of the raw data structure to embed inside the IPC request
|
||||
* @return Pointer to the raw embedded data structure in the request, ready to be filled out.
|
||||
*/
|
||||
static inline void* ipcPrepareHeader(IpcCommand* cmd, size_t sizeof_raw) {
|
||||
u32* buf = (u32*)armGetTls();
|
||||
size_t i;
|
||||
*buf++ = IpcCommandType_Request | (cmd->NumStaticIn << 16) | (cmd->NumSend << 20) | (cmd->NumRecv << 24) | (cmd->NumExch << 28);
|
||||
|
||||
u32* fill_in_size_later = buf;
|
||||
|
||||
if (cmd->NumStaticOut > 0) {
|
||||
*buf = (cmd->NumStaticOut + 2) << 10;
|
||||
}
|
||||
else {
|
||||
*buf = 0;
|
||||
}
|
||||
|
||||
if (cmd->SendPid || cmd->NumHandlesCopy > 0 || cmd->NumHandlesMove > 0) {
|
||||
*buf++ |= 0x80000000;
|
||||
*buf++ = (!!cmd->SendPid) | (cmd->NumHandlesCopy << 1) | (cmd->NumHandlesMove << 5);
|
||||
|
||||
if (cmd->SendPid)
|
||||
buf += 2;
|
||||
|
||||
for (i=0; i<(cmd->NumHandlesCopy + cmd->NumHandlesMove); i++)
|
||||
*buf++ = cmd->Handles[i];
|
||||
}
|
||||
else {
|
||||
buf++;
|
||||
}
|
||||
|
||||
for (i=0; i<cmd->NumStaticIn; i++, buf+=2) {
|
||||
IpcStaticSendDescriptor* desc = (IpcStaticSendDescriptor*) buf;
|
||||
|
||||
uintptr_t ptr = (uintptr_t) cmd->Statics[i];
|
||||
desc->Addr = ptr;
|
||||
desc->Packed = cmd->StaticIndices[i] | (cmd->StaticSizes[i] << 16) |
|
||||
(((ptr >> 32) & 15) << 12) | (((ptr >> 36) & 15) << 6);
|
||||
}
|
||||
|
||||
for (i=0; i<(cmd->NumSend + cmd->NumRecv + cmd->NumExch); i++, buf+=3) {
|
||||
IpcBufferDescriptor* desc = (IpcBufferDescriptor*) buf;
|
||||
desc->Size = cmd->BufferSizes[i];
|
||||
|
||||
uintptr_t ptr = (uintptr_t) cmd->Buffers[i];
|
||||
desc->Addr = ptr;
|
||||
desc->Packed = cmd->BufferTypes[i] |
|
||||
(((ptr >> 32) & 15) << 28) | ((ptr >> 36) << 2);
|
||||
}
|
||||
|
||||
u32 padding = ((16 - (((uintptr_t) buf) & 15)) & 15) / 4;
|
||||
u32* raw = (u32*) (buf + padding);
|
||||
|
||||
size_t raw_size = (sizeof_raw/4) + 4;
|
||||
buf += raw_size;
|
||||
|
||||
u16* buf_u16 = (u16*) buf;
|
||||
|
||||
for (i=0; i<cmd->NumStaticOut; i++) {
|
||||
size_t off = cmd->NumStaticIn + i;
|
||||
size_t sz = (uintptr_t) cmd->StaticSizes[off];
|
||||
|
||||
buf_u16[i] = (sz > 0xFFFF) ? 0 : sz;
|
||||
}
|
||||
|
||||
size_t u16s_size = ((2*cmd->NumStaticOut) + 3)/4;
|
||||
buf += u16s_size;
|
||||
raw_size += u16s_size;
|
||||
|
||||
*fill_in_size_later |= raw_size;
|
||||
|
||||
for (i=0; i<cmd->NumStaticOut; i++, buf+=2) {
|
||||
IpcStaticRecvDescriptor* desc = (IpcStaticRecvDescriptor*) buf;
|
||||
size_t off = cmd->NumStaticIn + i;
|
||||
|
||||
uintptr_t ptr = (uintptr_t) cmd->Statics[off];
|
||||
desc->Addr = ptr;
|
||||
desc->Packed = (ptr >> 32) | (cmd->StaticSizes[off] << 16);
|
||||
}
|
||||
|
||||
return (void*) raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dispatches an IPC request.
|
||||
* @param session IPC session handle.
|
||||
* @return Result code.
|
||||
*/
|
||||
static inline Result ipcDispatch(Handle session) {
|
||||
return svcSendSyncRequest(session);
|
||||
}
|
||||
|
||||
///@}
|
||||
|
||||
///@name IPC response parsing
|
||||
///@{
|
||||
|
||||
/// IPC parsed command (response) structure.
|
||||
typedef struct {
|
||||
IpcCommandType CommandType; ///< Type of the command
|
||||
|
||||
bool HasPid; ///< true if the 'Pid' field is filled out.
|
||||
u64 Pid; ///< PID included in the response (only if HasPid is true)
|
||||
|
||||
size_t NumHandles; ///< Number of handles copied.
|
||||
Handle Handles[IPC_MAX_OBJECTS]; ///< Handles.
|
||||
bool WasHandleCopied[IPC_MAX_OBJECTS]; ///< true if the handle was moved, false if it was copied.
|
||||
|
||||
bool IsDomainRequest; ///< true if the the message is a Domain message.
|
||||
DomainMessageType InMessageType; ///< Type of the domain message.
|
||||
u32 InMessageLength; ///< Size of rawdata (for domain messages).
|
||||
u32 InThisObjectId; ///< Object ID to call the command on (for domain messages).
|
||||
size_t InNumObjectIds; ///< Number of object IDs (for domain messages).
|
||||
u32 InObjectIds[IPC_MAX_OBJECTS]; ///< Object IDs (for domain messages).
|
||||
|
||||
bool IsDomainResponse; ///< true if the the message is a Domain response.
|
||||
size_t OutNumObjectIds; ///< Number of object IDs (for domain responses).
|
||||
u32 OutObjectIds[IPC_MAX_OBJECTS]; ///< Object IDs (for domain responses).
|
||||
|
||||
size_t NumBuffers; ///< Number of buffers in the response.
|
||||
void* Buffers[IPC_MAX_BUFFERS]; ///< Pointers to the buffers.
|
||||
size_t BufferSizes[IPC_MAX_BUFFERS]; ///< Sizes of the buffers.
|
||||
BufferType BufferTypes[IPC_MAX_BUFFERS]; ///< Types of the buffers.
|
||||
BufferDirection BufferDirections[IPC_MAX_BUFFERS]; ///< Direction of each buffer.
|
||||
|
||||
size_t NumStatics; ///< Number of statics in the response.
|
||||
void* Statics[IPC_MAX_BUFFERS]; ///< Pointers to the statics.
|
||||
size_t StaticSizes[IPC_MAX_BUFFERS]; ///< Sizes of the statics.
|
||||
u8 StaticIndices[IPC_MAX_BUFFERS]; ///< Indices of the statics.
|
||||
|
||||
size_t NumStaticsOut; ///< Number of output statics available in the response.
|
||||
|
||||
void* Raw; ///< Pointer to the raw embedded data structure in the response.
|
||||
void* RawWithoutPadding; ///< Pointer to the raw embedded data structure, without padding.
|
||||
size_t RawSize; ///< Size of the raw embedded data.
|
||||
} IpcParsedCommand;
|
||||
|
||||
/**
|
||||
* @brief Parse an IPC command response into an IPC parsed command structure.
|
||||
* @param r IPC parsed command structure to fill in.
|
||||
* @return Result code.
|
||||
*/
|
||||
static inline Result ipcParse(IpcParsedCommand* r) {
|
||||
u32* buf = (u32*)armGetTls();
|
||||
u32 ctrl0 = *buf++;
|
||||
u32 ctrl1 = *buf++;
|
||||
size_t i;
|
||||
|
||||
r->IsDomainRequest = false;
|
||||
r->IsDomainResponse = false;
|
||||
|
||||
r->CommandType = (IpcCommandType) (ctrl0 & 0xffff);
|
||||
r->HasPid = false;
|
||||
r->RawSize = (ctrl1 & 0x1ff) * 4;
|
||||
r->NumHandles = 0;
|
||||
|
||||
r->NumStaticsOut = (ctrl1 >> 10) & 15;
|
||||
if (r->NumStaticsOut >> 1) r->NumStaticsOut--; // Value 2 -> Single descriptor
|
||||
if (r->NumStaticsOut >> 1) r->NumStaticsOut--; // Value 3+ -> (Value - 2) descriptors
|
||||
|
||||
if (ctrl1 & 0x80000000) {
|
||||
u32 ctrl2 = *buf++;
|
||||
|
||||
if (ctrl2 & 1) {
|
||||
r->HasPid = true;
|
||||
r->Pid = *buf++;
|
||||
r->Pid |= ((u64)(*buf++)) << 32;
|
||||
}
|
||||
|
||||
size_t num_handles_copy = ((ctrl2 >> 1) & 15);
|
||||
size_t num_handles_move = ((ctrl2 >> 5) & 15);
|
||||
|
||||
size_t num_handles = num_handles_copy + num_handles_move;
|
||||
u32* buf_after_handles = buf + num_handles;
|
||||
|
||||
if (num_handles > IPC_MAX_OBJECTS)
|
||||
num_handles = IPC_MAX_OBJECTS;
|
||||
|
||||
for (i=0; i<num_handles; i++)
|
||||
{
|
||||
r->Handles[i] = *(buf+i);
|
||||
r->WasHandleCopied[i] = (i < num_handles_copy);
|
||||
}
|
||||
|
||||
r->NumHandles = num_handles;
|
||||
buf = buf_after_handles;
|
||||
}
|
||||
|
||||
size_t num_statics = (ctrl0 >> 16) & 15;
|
||||
u32* buf_after_statics = buf + num_statics*2;
|
||||
|
||||
if (num_statics > IPC_MAX_BUFFERS)
|
||||
num_statics = IPC_MAX_BUFFERS;
|
||||
|
||||
for (i=0; i<num_statics; i++, buf+=2) {
|
||||
IpcStaticSendDescriptor* desc = (IpcStaticSendDescriptor*) buf;
|
||||
u64 packed = (u64) desc->Packed;
|
||||
|
||||
r->Statics[i] = (void*) (desc->Addr | (((packed >> 12) & 15) << 32) | (((packed >> 6) & 15) << 36));
|
||||
r->StaticSizes[i] = packed >> 16;
|
||||
r->StaticIndices[i] = packed & 63;
|
||||
}
|
||||
|
||||
r->NumStatics = num_statics;
|
||||
buf = buf_after_statics;
|
||||
|
||||
size_t num_bufs_send = (ctrl0 >> 20) & 15;
|
||||
size_t num_bufs_recv = (ctrl0 >> 24) & 15;
|
||||
size_t num_bufs_exch = (ctrl0 >> 28) & 15;
|
||||
|
||||
size_t num_bufs = num_bufs_send + num_bufs_recv + num_bufs_exch;
|
||||
r->Raw = (void*)(((uintptr_t)(buf + num_bufs*3) + 15) &~ 15);
|
||||
r->RawWithoutPadding = (void*)((uintptr_t)(buf + num_bufs*3));
|
||||
|
||||
if (num_bufs > IPC_MAX_BUFFERS)
|
||||
num_bufs = IPC_MAX_BUFFERS;
|
||||
|
||||
for (i=0; i<num_bufs; i++, buf+=3) {
|
||||
IpcBufferDescriptor* desc = (IpcBufferDescriptor*) buf;
|
||||
u64 packed = (u64) desc->Packed;
|
||||
|
||||
r->Buffers[i] = (void*) (desc->Addr | ((packed >> 28) << 32) | (((packed >> 2) & 15) << 36));
|
||||
r->BufferSizes[i] = desc->Size;
|
||||
r->BufferTypes[i] = (BufferType) (packed & 3);
|
||||
|
||||
if (i < num_bufs_send)
|
||||
r->BufferDirections[i] = BufferDirection_Send;
|
||||
else if (i < (num_bufs_send + num_bufs_recv))
|
||||
r->BufferDirections[i] = BufferDirection_Recv;
|
||||
else
|
||||
r->BufferDirections[i] = BufferDirection_Exch;
|
||||
}
|
||||
|
||||
r->NumBuffers = num_bufs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Queries the size of an IPC pointer buffer.
|
||||
* @param session IPC session handle.
|
||||
* @param size Output variable in which to store the size.
|
||||
* @return Result code.
|
||||
*/
|
||||
static inline Result ipcQueryPointerBufferSize(Handle session, size_t *size) {
|
||||
u32* buf = (u32*)armGetTls();
|
||||
|
||||
buf[0] = IpcCommandType_Control;
|
||||
buf[1] = 8;
|
||||
buf[2] = 0;
|
||||
buf[3] = 0;
|
||||
buf[4] = SFCI_MAGIC;
|
||||
buf[5] = 0;
|
||||
buf[6] = 3;
|
||||
buf[7] = 0;
|
||||
|
||||
Result rc = ipcDispatch(session);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct ipcQueryPointerBufferSizeResponse {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 size;
|
||||
} *raw = (struct ipcQueryPointerBufferSizeResponse*)r.Raw;
|
||||
|
||||
rc = raw->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*size = raw->size & 0xffff;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Closes the IPC session with proper clean up.
|
||||
* @param session IPC session handle.
|
||||
* @return Result code.
|
||||
*/
|
||||
static inline Result ipcCloseSession(Handle session) {
|
||||
u32* buf = (u32*)armGetTls();
|
||||
buf[0] = IpcCommandType_Close;
|
||||
buf[1] = 0;
|
||||
return ipcDispatch(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clones an IPC session.
|
||||
* @param session IPC session handle.
|
||||
* @param unk Unknown.
|
||||
* @param new_session_out Output cloned IPC session handle.
|
||||
* @return Result code.
|
||||
*/
|
||||
static inline Result ipcCloneSession(Handle session, u32 unk, Handle* new_session_out) {
|
||||
u32* buf = (u32*)armGetTls();
|
||||
|
||||
buf[0] = IpcCommandType_Control;
|
||||
buf[1] = 9;
|
||||
buf[2] = 0;
|
||||
buf[3] = 0;
|
||||
buf[4] = SFCI_MAGIC;
|
||||
buf[5] = 0;
|
||||
buf[6] = 4;
|
||||
buf[7] = 0;
|
||||
buf[8] = unk;
|
||||
|
||||
Result rc = ipcDispatch(session);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct ipcCloneSessionResponse {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *raw = (struct ipcCloneSessionResponse*)r.Raw;
|
||||
|
||||
rc = raw->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && new_session_out) {
|
||||
*new_session_out = r.Handles[0];
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
///@}
|
||||
|
||||
///@name IPC domain handling
|
||||
///@{
|
||||
|
||||
/**
|
||||
* @brief Converts an IPC session handle into a domain.
|
||||
* @param session IPC session handle.
|
||||
* @param object_id_out Output variable in which to store the object ID.
|
||||
* @return Result code.
|
||||
*/
|
||||
static inline Result ipcConvertSessionToDomain(Handle session, u32* object_id_out) {
|
||||
u32* buf = (u32*)armGetTls();
|
||||
|
||||
buf[0] = IpcCommandType_Control;
|
||||
buf[1] = 8;
|
||||
buf[4] = SFCI_MAGIC;
|
||||
buf[5] = 0;
|
||||
buf[6] = 0;
|
||||
buf[7] = 0;
|
||||
|
||||
Result rc = ipcDispatch(session);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct ipcConvertSessionToDomainResponse {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 object_id;
|
||||
} *raw = (struct ipcConvertSessionToDomainResponse*)r.Raw;
|
||||
|
||||
rc = raw->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*object_id_out = raw->object_id;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds an object ID to be sent through an IPC domain command structure.
|
||||
* @param cmd IPC domain command structure.
|
||||
* @param object_id Object ID to send.
|
||||
*/
|
||||
static inline void ipcSendObjectId(IpcCommand* cmd, u32 object_id) {
|
||||
cmd->ObjectIds[cmd->NumObjectIds++] = object_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prepares the header of an IPC command structure (domain version).
|
||||
* @param cmd IPC command structure.
|
||||
* @param sizeof_raw Size in bytes of the raw data structure to embed inside the IPC request
|
||||
* @param object_id Domain object ID.
|
||||
* @return Pointer to the raw embedded data structure in the request, ready to be filled out.
|
||||
*/
|
||||
static inline void* ipcPrepareHeaderForDomain(IpcCommand* cmd, size_t sizeof_raw, u32 object_id) {
|
||||
void* raw = ipcPrepareHeader(cmd, sizeof_raw + sizeof(DomainMessageHeader) + cmd->NumObjectIds*sizeof(u32));
|
||||
DomainMessageHeader* hdr = (DomainMessageHeader*) raw;
|
||||
u32 *object_ids = (u32*)(((uintptr_t) raw) + sizeof(DomainMessageHeader) + sizeof_raw);
|
||||
|
||||
hdr->Type = DomainMessageType_SendMessage;
|
||||
hdr->NumObjectIds = (u8)cmd->NumObjectIds;
|
||||
hdr->Length = sizeof_raw;
|
||||
hdr->ThisObjectId = object_id;
|
||||
hdr->Pad[0] = hdr->Pad[1] = 0;
|
||||
|
||||
for(size_t i = 0; i < cmd->NumObjectIds; i++)
|
||||
object_ids[i] = cmd->ObjectIds[i];
|
||||
return (void*)(((uintptr_t) raw) + sizeof(DomainMessageHeader));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse an IPC command request into an IPC parsed command structure (domain version).
|
||||
* @param r IPC parsed command structure to fill in.
|
||||
* @return Result code.
|
||||
*/
|
||||
static inline Result ipcParseDomainRequest(IpcParsedCommand* r) {
|
||||
Result rc = ipcParse(r);
|
||||
DomainMessageHeader *hdr;
|
||||
u32 *object_ids;
|
||||
if(R_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
hdr = (DomainMessageHeader*) r->Raw;
|
||||
object_ids = (u32*)(((uintptr_t) hdr) + sizeof(DomainMessageHeader) + hdr->Length);
|
||||
r->Raw = (void*)(((uintptr_t) r->Raw) + sizeof(DomainMessageHeader));
|
||||
|
||||
r->IsDomainRequest = true;
|
||||
r->InMessageType = (DomainMessageType)(hdr->Type);
|
||||
switch (r->InMessageType) {
|
||||
case DomainMessageType_SendMessage:
|
||||
case DomainMessageType_Close:
|
||||
break;
|
||||
default:
|
||||
return MAKERESULT(Module_Libnx, LibnxError_DomainMessageUnknownType);
|
||||
}
|
||||
|
||||
r->InThisObjectId = hdr->ThisObjectId;
|
||||
r->InNumObjectIds = hdr->NumObjectIds > 8 ? 8 : hdr->NumObjectIds;
|
||||
if ((uintptr_t)object_ids + sizeof(u32) * r->InNumObjectIds - (uintptr_t)armGetTls() >= 0x100) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_DomainMessageTooManyObjectIds);
|
||||
}
|
||||
for(size_t i = 0; i < r->InNumObjectIds; i++)
|
||||
r->InObjectIds[i] = object_ids[i];
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse an IPC command response into an IPC parsed command structure (domain version).
|
||||
* @param r IPC parsed command structure to fill in.
|
||||
* @param sizeof_raw Size in bytes of the raw data structure.
|
||||
* @return Result code.
|
||||
*/
|
||||
static inline Result ipcParseDomainResponse(IpcParsedCommand* r, size_t sizeof_raw) {
|
||||
Result rc = ipcParse(r);
|
||||
DomainResponseHeader *hdr;
|
||||
u32 *object_ids;
|
||||
if(R_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
hdr = (DomainResponseHeader*) r->Raw;
|
||||
r->Raw = (void*)(((uintptr_t) r->Raw) + sizeof(DomainResponseHeader));
|
||||
object_ids = (u32*)(((uintptr_t) r->Raw) + sizeof_raw);//Official sw doesn't align this.
|
||||
|
||||
r->IsDomainResponse = true;
|
||||
|
||||
r->OutNumObjectIds = hdr->NumObjectIds > 8 ? 8 : hdr->NumObjectIds;
|
||||
if ((uintptr_t)object_ids + sizeof(u32) * r->OutNumObjectIds - (uintptr_t)armGetTls() >= 0x100) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_DomainMessageTooManyObjectIds);
|
||||
}
|
||||
for(size_t i = 0; i < r->OutNumObjectIds; i++)
|
||||
r->OutObjectIds[i] = object_ids[i];
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Closes a domain object by ID.
|
||||
* @param session IPC session handle.
|
||||
* @param object_id ID of the object to close.
|
||||
* @return Result code.
|
||||
*/
|
||||
static inline Result ipcCloseObjectById(Handle session, u32 object_id) {
|
||||
IpcCommand c;
|
||||
DomainMessageHeader* hdr;
|
||||
|
||||
ipcInitialize(&c);
|
||||
hdr = (DomainMessageHeader*)ipcPrepareHeader(&c, sizeof(DomainMessageHeader));
|
||||
|
||||
hdr->Type = DomainMessageType_Close;
|
||||
hdr->NumObjectIds = 0;
|
||||
hdr->Length = 0;
|
||||
hdr->ThisObjectId = object_id;
|
||||
hdr->Pad[0] = hdr->Pad[1] = 0;
|
||||
|
||||
return ipcDispatch(session); // this command has no associated response
|
||||
}
|
||||
|
||||
///@}
|
||||
41
Source/rewrite-hoc-clk/common/include/memmem.h
Normal file
41
Source/rewrite-hoc-clk/common/include/memmem.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Roy Merkel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MEMMEM_IMPL_H
|
||||
#define MEMMEM_IMPL_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void *memmem_impl(const void *haystack, size_t haystacklen,
|
||||
const void *needle, size_t needlelen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
44
Source/rewrite-hoc-clk/common/include/notification.h
Normal file
44
Source/rewrite-hoc-clk/common/include/notification.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) ppkantorski (bord2death)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
|
||||
static void writeNotification(const std::string& message) {
|
||||
static const char* flagPath = "sdmc:/config/ultrahand/flags/NOTIFICATIONS.flag";
|
||||
|
||||
FILE* flagFile = fopen(flagPath, "r");
|
||||
if (!flagFile) {
|
||||
return;
|
||||
}
|
||||
fclose(flagFile);
|
||||
|
||||
std::string filename = "Horizon OC -" + std::to_string(std::time(nullptr)) + ".notify";
|
||||
std::string fullPath = "sdmc:/config/ultrahand/notifications/" + filename;
|
||||
|
||||
FILE* file = fopen(fullPath.c_str(), "w");
|
||||
if (file) {
|
||||
fprintf(file, "{\n");
|
||||
fprintf(file, " \"text\": \"%s\",\n", message.c_str());
|
||||
fprintf(file, " \"fontSize\": 28\n");
|
||||
fprintf(file, "}\n");
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
113
Source/rewrite-hoc-clk/common/include/pcv_types.h
Normal file
113
Source/rewrite-hoc-clk/common/include/pcv_types.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) ppkantorski (bord2death)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* SDx actual min is 625 mV. Multipliers 0/1 reserved.
|
||||
* SD0 max is 1400 mV
|
||||
* SD1 max is 1550 mV
|
||||
* SD2 max is 3787.5 mV
|
||||
* SD3 max is 3787.5 mV
|
||||
*/
|
||||
|
||||
/*
|
||||
* Switch Power domains (max77620):
|
||||
* Name | Usage | uV step | uV min | uV default | uV max | Init
|
||||
*-------+---------------+---------+--------+------------+---------+------------------
|
||||
* sd0 | SoC | 12500 | 600000 | 625000 | 1400000 | 1.125V (pkg1.1)
|
||||
* sd1 | SDRAM | 12500 | 600000 | 1125000 | 1125000 | 1.1V (pkg1.1)
|
||||
* sd2 | ldo{0-1, 7-8} | 12500 | 600000 | 1325000 | 1350000 | 1.325V (pcv)
|
||||
* sd3 | 1.8V general | 12500 | 600000 | 1800000 | 1800000 |
|
||||
* ldo0 | Display Panel | 25000 | 800000 | 1200000 | 1200000 | 1.2V (pkg1.1)
|
||||
* ldo1 | XUSB, PCIE | 25000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
|
||||
* ldo2 | SDMMC1 | 50000 | 800000 | 1800000 | 3300000 |
|
||||
* ldo3 | GC ASIC | 50000 | 800000 | 3100000 | 3100000 | 3.1V (pcv)
|
||||
* ldo4 | RTC | 12500 | 800000 | 850000 | 850000 | 0.85V (AO, pcv)
|
||||
* ldo5 | GC Card | 50000 | 800000 | 1800000 | 1800000 | 1.8V (pcv)
|
||||
* ldo6 | Touch, ALS | 50000 | 800000 | 2900000 | 2900000 | 2.9V (pcv)
|
||||
* ldo7 | XUSB | 50000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
|
||||
* ldo8 | XUSB, DP, MCU | 50000 | 800000 | 1050000 | 2800000 | 1.05V/2.8V (pcv)
|
||||
*/
|
||||
|
||||
|
||||
// GPIOs T210: 3: 3.3V, 5: CPU PMIC, 6: GPU PMIC, 7: DSI/VI 1.2V powered by ldo0.
|
||||
|
||||
/*
|
||||
* OTP: T210 - T210B01:
|
||||
* SD0: 1.0V 1.05V - SoC. EN Based on FPSSRC.
|
||||
* SD1: 1.15V 1.1V - DRAM for T210. EN Based on FPSSRC.
|
||||
* SD2: 1.35V 1.35V
|
||||
* SD3: 1.8V 1.8V
|
||||
* All powered off?
|
||||
* LDO0: -- -- - Display
|
||||
* LDO1: 1.05V 1.05V
|
||||
* LDO2: -- -- - SD
|
||||
* LDO3: 3.1V 3.1V - GC ASIC
|
||||
* LDO4: 1.0V 0.8V - Needed for RTC domain on T210.
|
||||
* LDO5: 3.1V 3.1V
|
||||
* LDO6: 2.8V 2.9V - Touch.
|
||||
* LDO7: 1.05V 1.0V
|
||||
* LDO8: 1.05V 1.0V
|
||||
*/
|
||||
|
||||
/*
|
||||
* MAX77620_AME_GPIO: control GPIO modes (bits 0 - 7 correspond to GPIO0 - GPIO7); 0 -> GPIO, 1 -> alt-mode
|
||||
* MAX77620_REG_GPIOx: 0x9 sets output and enable
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
PcvPowerDomain_Max77620_Sd0 = 0,
|
||||
PcvPowerDomain_Max77620_Sd1 = 1,
|
||||
PcvPowerDomain_Max77620_Sd2 = 2,
|
||||
PcvPowerDomain_Max77620_Sd3 = 3,
|
||||
PcvPowerDomain_Max77620_Ldo0 = 4,
|
||||
PcvPowerDomain_Max77620_Ldo1 = 5,
|
||||
PcvPowerDomain_Max77620_Ldo2 = 6,
|
||||
PcvPowerDomain_Max77620_Ldo3 = 7,
|
||||
PcvPowerDomain_Max77620_Ldo4 = 8,
|
||||
PcvPowerDomain_Max77620_Ldo5 = 9,
|
||||
PcvPowerDomain_Max77620_Ldo6 = 10,
|
||||
PcvPowerDomain_Max77620_Ldo7 = 11,
|
||||
PcvPowerDomain_Max77620_Ldo8 = 12,
|
||||
PcvPowerDomain_Max77621_Cpu = 13,
|
||||
PcvPowerDomain_Max77621_Gpu = 14,
|
||||
PcvPowerDomain_Max77812_Cpu = 15,
|
||||
PcvPowerDomain_Max77812_Gpu = 16,
|
||||
PcvPowerDomain_Max77812_Dram = 17,
|
||||
} PowerDomain;
|
||||
|
||||
typedef enum {
|
||||
PcvPowerDomainId_Max77620_Sd0 = 0x3A000080,
|
||||
PcvPowerDomainId_Max77620_Sd1 = 0x3A000081, // vdd2
|
||||
PcvPowerDomainId_Max77620_Sd2 = 0x3A000082,
|
||||
PcvPowerDomainId_Max77620_Sd3 = 0x3A000083,
|
||||
PcvPowerDomainId_Max77620_Ldo0 = 0x3A0000A0,
|
||||
PcvPowerDomainId_Max77620_Ldo1 = 0x3A0000A1,
|
||||
PcvPowerDomainId_Max77620_Ldo2 = 0x3A0000A2,
|
||||
PcvPowerDomainId_Max77620_Ldo3 = 0x3A0000A3,
|
||||
PcvPowerDomainId_Max77620_Ldo4 = 0x3A0000A4,
|
||||
PcvPowerDomainId_Max77620_Ldo5 = 0x3A0000A5,
|
||||
PcvPowerDomainId_Max77620_Ldo6 = 0x3A0000A6,
|
||||
PcvPowerDomainId_Max77620_Ldo7 = 0x3A0000A7,
|
||||
PcvPowerDomainId_Max77620_Ldo8 = 0x3A0000A8,
|
||||
PcvPowerDomainId_Max77621_Cpu = 0x3A000003,
|
||||
PcvPowerDomainId_Max77621_Gpu = 0x3A000004,
|
||||
PcvPowerDomainId_Max77812_Cpu = 0x3A000003,
|
||||
PcvPowerDomainId_Max77812_Gpu = 0x3A000004,
|
||||
PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq
|
||||
} PowerDomainId;
|
||||
39
Source/rewrite-hoc-clk/common/include/pwm.h
Normal file
39
Source/rewrite-hoc-clk/common/include/pwm.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) MasaGratoR
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
Service s;
|
||||
} PwmChannelSession;
|
||||
|
||||
Result pwmInitialize(void);
|
||||
void pwmExit(void);
|
||||
Service* pwmGetServiceSession(void);
|
||||
Result pwmOpenSession2(PwmChannelSession *out, u32 device_code);
|
||||
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double* out);
|
||||
void pwmChannelSessionClose(PwmChannelSession *c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
527
Source/rewrite-hoc-clk/common/include/registers.h
Normal file
527
Source/rewrite-hoc-clk/common/include/registers.h
Normal file
@@ -0,0 +1,527 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* Copyright (c) Linux 4 Tegra & Linux 4 Switch contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define EMC_INTSTATUS_0 0x0
|
||||
#define EMC_INTMASK_0 0x4
|
||||
#define EMC_DBG_0 0x8
|
||||
#define EMC_CFG_0 0xC
|
||||
#define EMC_ADR_CFG_0 0x10
|
||||
#define EMC_REFCTRL_0 0x20
|
||||
#define EMC_PIN_0 0x24
|
||||
#define EMC_TIMING_CONTROL_0 0x28
|
||||
#define EMC_RC_0 0x2C
|
||||
#define EMC_RFC_0 0x30
|
||||
#define EMC_RAS_0 0x34
|
||||
#define EMC_RP_0 0x38
|
||||
#define EMC_R2W_0 0x3C
|
||||
#define EMC_W2R_0 0x40
|
||||
#define EMC_R2P_0 0x44
|
||||
#define EMC_W2P_0 0x48
|
||||
#define EMC_RD_RCD_0 0x4C
|
||||
#define EMC_WR_RCD_0 0x50
|
||||
#define EMC_RRD_0 0x54
|
||||
#define EMC_REXT_0 0x58
|
||||
#define EMC_WDV_0 0x5C
|
||||
#define EMC_QUSE_0 0x60
|
||||
#define EMC_QRST_0 0x64
|
||||
#define EMC_QSAFE_0 0x68
|
||||
#define EMC_RDV_0 0x6C
|
||||
#define EMC_REFRESH_0 0x70
|
||||
#define EMC_BURST_REFRESH_NUM_0 0x74
|
||||
#define EMC_PDEX2WR_0 0x78
|
||||
#define EMC_PDEX2RD_0 0x7C
|
||||
#define EMC_PCHG2PDEN_0 0x80
|
||||
#define EMC_ACT2PDEN_0 0x84
|
||||
#define EMC_AR2PDEN_0 0x88
|
||||
#define EMC_RW2PDEN_0 0x8C
|
||||
#define EMC_TXSR_0 0x90
|
||||
#define EMC_TCKE_0 0x94
|
||||
#define EMC_TFAW_0 0x98
|
||||
#define EMC_TRPAB_0 0x9C
|
||||
#define EMC_TCLKSTABLE_0 0xA0
|
||||
#define EMC_TCLKSTOP_0 0xA4
|
||||
#define EMC_TREFBW_0 0xA8
|
||||
#define EMC_TPPD_0 0xAC
|
||||
#define EMC_ODT_WRITE_0 0xB0
|
||||
#define EMC_PDEX2MRR_0 0xB4
|
||||
#define EMC_WEXT_0 0xB8
|
||||
#define EMC_RFC_SLR_0 0xC0
|
||||
#define EMC_MRS_WAIT_CNT2_0 0xC4
|
||||
#define EMC_MRS_WAIT_CNT_0 0xC8
|
||||
#define EMC_MRS_0 0xCC
|
||||
#define EMC_EMRS_0 0xD0
|
||||
#define EMC_REF_0 0xD4
|
||||
#define EMC_PRE_0 0xD8
|
||||
#define EMC_NOP_0 0xDC
|
||||
#define EMC_SELF_REF_0 0xE0
|
||||
#define EMC_DPD_0 0xE4
|
||||
#define EMC_MRW_0 0xE8
|
||||
#define EMC_MRR_0 0xEC
|
||||
#define EMC_CMDQ_0 0xF0
|
||||
#define EMC_MC2EMCQ_0 0xF4
|
||||
#define EMC_FBIO_SPARE_0 0x100
|
||||
#define EMC_FBIO_CFG5_0 0x104
|
||||
#define EMC_FBIO_CFG6_0 0x114
|
||||
#define EMC_PDEX2CKE_0 0x118
|
||||
#define EMC_CKE2PDEN_0 0x11C
|
||||
#define EMC_CFG_RSV_0 0x120
|
||||
#define EMC_ACPD_CONTROL_0 0x124
|
||||
#define EMC_MPC_0 0x128
|
||||
#define EMC_EMRS2_0 0x12C
|
||||
#define EMC_EMRS3_0 0x130
|
||||
#define EMC_MRW2_0 0x134
|
||||
#define EMC_MRW3_0 0x138
|
||||
#define EMC_MRW4_0 0x13C
|
||||
#define EMC_CLKEN_OVERRIDE_0 0x140
|
||||
#define EMC_R2R_0 0x144
|
||||
#define EMC_W2W_0 0x148
|
||||
#define EMC_EINPUT_0 0x14C
|
||||
#define EMC_EINPUT_DURATION_0 0x150
|
||||
#define EMC_PUTERM_EXTRA_0 0x154
|
||||
#define EMC_TCKESR_0 0x158
|
||||
#define EMC_TPD_0 0x15C
|
||||
#define EMC_AUTO_CAL_CONFIG_0 0x2A4
|
||||
#define EMC_AUTO_CAL_INTERVAL_0 0x2A8
|
||||
#define EMC_AUTO_CAL_STATUS_0 0x2AC
|
||||
#define EMC_REQ_CTRL_0 0x2B0
|
||||
#define EMC_EMC_STATUS_0 0x2B4
|
||||
#define EMC_CFG_2_0 0x2B8
|
||||
#define EMC_CFG_DIG_DLL_0 0x2BC
|
||||
#define EMC_CFG_DIG_DLL_PERIOD_0 0x2C0
|
||||
#define EMC_DIG_DLL_STATUS_0 0x2C4
|
||||
#define EMC_CFG_DIG_DLL_1_0 0x2C8
|
||||
#define EMC_RDV_MASK_0 0x2CC
|
||||
#define EMC_WDV_MASK_0 0x2D0
|
||||
#define EMC_RDV_EARLY_MASK_0 0x2D4
|
||||
#define EMC_RDV_EARLY_0 0x2D8
|
||||
#define EMC_AUTO_CAL_CONFIG8_0 0x2DC
|
||||
#define EMC_ZCAL_INTERVAL_0 0x2E0
|
||||
#define EMC_ZCAL_WAIT_CNT_0 0x2E4
|
||||
#define EMC_ZCAL_MRW_CMD_0 0x2E8
|
||||
#define EMC_ZQ_CAL_0 0x2EC
|
||||
#define EMC_XM2COMPPADCTRL3_0 0x2F4
|
||||
#define EMC_AUTO_CAL_VREF_SEL_0_0 0x2F8
|
||||
#define EMC_AUTO_CAL_VREF_SEL_1_0 0x300
|
||||
#define EMC_XM2COMPPADCTRL_0 0x30C
|
||||
#define EMC_FDPD_CTRL_DQ_0 0x310
|
||||
#define EMC_FDPD_CTRL_CMD_0 0x314
|
||||
#define EMC_PMACRO_CMD_BRICK_CTRL_FDPD_0 0x318
|
||||
#define EMC_PMACRO_DATA_BRICK_CTRL_FDPD_0 0x31C
|
||||
#define EMC_SCRATCH0_0 0x324
|
||||
#define EMC_PMACRO_BRICK_CTRL_RFU1_0 0x330
|
||||
#define EMC_PMACRO_BRICK_CTRL_RFU2_0 0x334
|
||||
#define EMC_CMD_MAPPING_CMD0_0_0 0x380
|
||||
#define EMC_CMD_MAPPING_CMD0_1_0 0x384
|
||||
#define EMC_CMD_MAPPING_CMD0_2_0 0x388
|
||||
#define EMC_CMD_MAPPING_CMD1_0_0 0x38C
|
||||
#define EMC_CMD_MAPPING_CMD1_1_0 0x390
|
||||
#define EMC_CMD_MAPPING_CMD1_2_0 0x394
|
||||
#define EMC_CMD_MAPPING_CMD2_0_0 0x398
|
||||
#define EMC_CMD_MAPPING_CMD2_1_0 0x39C
|
||||
#define EMC_CMD_MAPPING_CMD2_2_0 0x3A0
|
||||
#define EMC_CMD_MAPPING_CMD3_0_0 0x3A4
|
||||
#define EMC_CMD_MAPPING_CMD3_1_0 0x3A8
|
||||
#define EMC_CMD_MAPPING_CMD3_2_0 0x3AC
|
||||
#define EMC_CMD_MAPPING_BYTE_0 0x3B0
|
||||
#define EMC_TR_TIMING_0_0 0x3B4
|
||||
#define EMC_TR_CTRL_0_0 0x3B8
|
||||
#define EMC_TR_CTRL_1_0 0x3BC
|
||||
#define EMC_SWITCH_BACK_CTRL_0 0x3C0
|
||||
#define EMC_TR_RDV_0 0x3C4
|
||||
#define EMC_STALL_THEN_EXE_BEFORE_CLKCHANGE_0 0x3C8
|
||||
#define EMC_STALL_THEN_EXE_AFTER_CLKCHANGE_0 0x3CC
|
||||
#define EMC_UNSTALL_RW_AFTER_CLKCHANGE_0 0x3D0
|
||||
#define EMC_AUTO_CAL_ 0x3D4
|
||||
#define EMC_SEL_DPD_CTRL_0 0x3D8
|
||||
#define EMC_PRE_REFRESH_REQ_CNT_0 0x3DC
|
||||
#define EMC_DYN_SELF_REF_CONTROL_0 0x3E0
|
||||
#define EMC_TXSRDLL_0 0x3E4
|
||||
#define EMC_CCFIFO_ADDR_0 0x3E8
|
||||
#define EMC_CCFIFO_DATA_0 0x3EC
|
||||
#define EMC_CCFIFO_STATUS_0 0x3F0
|
||||
#define EMC_TR_QPOP_0 0x3F4
|
||||
#define EMC_TR_RDV_MASK_0 0x3F8
|
||||
#define EMC_TR_QSAFE_0 0x3FC
|
||||
#define EMC_TR_QRST_0 0x400
|
||||
#define EMC_SWIZZLE_RANK0_BYTE0_0 0x404
|
||||
#define EMC_SWIZZLE_RANK0_BYTE1_0 0x408
|
||||
#define EMC_SWIZZLE_RANK0_BYTE2_0 0x40C
|
||||
#define EMC_SWIZZLE_RANK0_BYTE3_0 0x410
|
||||
#define EMC_SWIZZLE_RANK1_BYTE0_0 0x418
|
||||
#define EMC_SWIZZLE_RANK1_BYTE1_0 0x41C
|
||||
#define EMC_SWIZZLE_RANK1_BYTE2_0 0x420
|
||||
#define EMC_SWIZZLE_RANK1_BYTE3_0 0x424
|
||||
#define EMC_ISSUE_QRST_0 0x428
|
||||
#define EMC_PMC_SCRATCH1_0 0x440
|
||||
#define EMC_PMC_SCRATCH2_0 0x444
|
||||
#define EMC_PMC_SCRATCH3_0 0x448
|
||||
#define EMC_AUTO_CAL_CONFIG2_0 0x458
|
||||
#define EMC_AUTO_CAL_CONFIG3_0 0x45C
|
||||
#define EMC_TR_DVFS_0 0x460
|
||||
#define EMC_AUTO_CAL_CHANNEL_0 0x464
|
||||
#define EMC_IBDLY_0 0x468
|
||||
#define EMC_OBDLY_0 0x46C
|
||||
#define EMC_TXDSRVTTGEN_0 0x480
|
||||
#define EMC_WE_DURATION_0 0x48C
|
||||
#define EMC_WS_DURATION_0 0x490
|
||||
#define EMC_WEV_0 0x494
|
||||
#define EMC_WSV_0 0x498
|
||||
#define EMC_CFG_3_0 0x49C
|
||||
#define EMC_MRW5_0 0x4A0
|
||||
#define EMC_MRW6_0 0x4A4
|
||||
#define EMC_MRW7_0 0x4A8
|
||||
#define EMC_MRW8_0 0x4AC
|
||||
#define EMC_MRW9_0 0x4B0
|
||||
#define EMC_MRW10_0 0x4B4
|
||||
#define EMC_MRW11_0 0x4B8
|
||||
#define EMC_MRW12_0 0x4BC
|
||||
#define EMC_MRW13_0 0x4C0
|
||||
#define EMC_MRW14_0 0x4C4
|
||||
#define EMC_MRW15_0 0x4D0
|
||||
#define EMC_CFG_SYNC_0 0x4D4
|
||||
#define EMC_FDPD_CTRL_CMD_NO_RAMP_0 0x4D8
|
||||
#define EMC_WDV_CHK_0 0x4E0
|
||||
#define EMC_CFG_PIPE_2_0 0x554
|
||||
#define EMC_CFG_PIPE_CLK_0 0x558
|
||||
#define EMC_CFG_PIPE_1_0 0x55C
|
||||
#define EMC_CFG_PIPE_0 0x560
|
||||
#define EMC_QPOP_0 0x564
|
||||
#define EMC_QUSE_WIDTH_0 0x568
|
||||
#define EMC_PUTERM_WIDTH_0 0x56C
|
||||
#define EMC_BGBIAS_CTL0_0 0x570
|
||||
#define EMC_AUTO_CAL_CONFIG7_0 0x574
|
||||
#define EMC_XM2COMPPADCTRL2_0 0x578
|
||||
#define EMC_COMP_PAD_SW_CTRL_0 0x57C
|
||||
#define EMC_REFCTRL2_0 0x580
|
||||
#define EMC_FBIO_CFG7_0 0x584
|
||||
#define EMC_DATA_BRLSHFT_0_0 0x588
|
||||
#define EMC_DATA_BRLSHFT_1_0 0x58C
|
||||
#define EMC_RFCPB_0 0x590
|
||||
#define EMC_DQS_BRLSHFT_0_0 0x594
|
||||
#define EMC_DQS_BRLSHFT_1_0 0x598
|
||||
#define EMC_CMD_BRLSHFT_0_0 0x59C
|
||||
#define EMC_CMD_BRLSHFT_1_0 0x5A0
|
||||
#define EMC_CMD_BRLSHFT_2_0 0x5A4
|
||||
#define EMC_CMD_BRLSHFT_3_0 0x5A8
|
||||
#define EMC_QUSE_BRLSHFT_0_0 0x5AC
|
||||
#define EMC_AUTO_CAL_CONFIG4_0 0x5B0
|
||||
#define EMC_AUTO_CAL_CONFIG5_0 0x5B4
|
||||
#define EMC_QUSE_BRLSHFT_1_0 0x5B8
|
||||
#define EMC_QUSE_BRLSHFT_2_0 0x5BC
|
||||
#define EMC_CCDMW_0 0x5C0
|
||||
#define EMC_QUSE_BRLSHFT_3_0 0x5C4
|
||||
#define EMC_FBIO_CFG8_0 0x5C8
|
||||
#define EMC_AUTO_CAL_CONFIG6_0 0x5CC
|
||||
#define EMC_PROTOBIST_CONFIG_ADR_1_0 0x5D0
|
||||
#define EMC_PROTOBIST_CONFIG_ADR_2_0 0x5D4
|
||||
#define EMC_PROTOBIST_MISC_0 0x5D8
|
||||
#define EMC_PROTOBIST_WDATA_LOWER_0 0x5DC
|
||||
#define EMC_PROTOBIST_WDATA_UPPER_0 0x5E0
|
||||
#define EMC_PROTOBIST_RDATA_0 0x5EC
|
||||
#define EMC_DLL_CFG_0_0 0x5E4
|
||||
#define EMC_DLL_CFG_1_0 0x5E8
|
||||
#define EMC_CONFIG_SAMPLE_DELAY_0 0x5F0
|
||||
#define EMC_CFG_UPDATE_0 0x5F4
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK0_0_0 0x600
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK0_1_0 0x604
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK0_2_0 0x608
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK0_3_0 0x60C
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK0_4_0 0x610
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK0_5_0 0x614
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK1_0_0 0x620
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK1_1_0 0x624
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK1_2_0 0x628
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK1_3_0 0x62C
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK1_4_0 0x630
|
||||
#define EMC_PMACRO_QUSE_DDLL_RANK1_5_0 0x634
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_0_0 0x640
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_1_0 0x644
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_2_0 0x648
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_3_0 0x64C
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_4_0 0x650
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_5_0 0x654
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_0_0 0x660
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_1_0 0x664
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_2_0 0x668
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_3_0 0x66C
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_4_0 0x670
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_5_0 0x674
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_0_0 0x680
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_1_0 0x684
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_2_0 0x688
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_3_0 0x68C
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_4_0 0x690
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK0_5_0 0x694
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_0_0 0x6A0
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_1_0 0x6A4
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_2_0 0x6A8
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_3_0 0x6AC
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_4_0 0x6B0
|
||||
#define EMC_PMACRO_OB_DDLL_LONG_DQS_RANK1_5_0 0x6B4
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_0_0 0x6C0
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_1_0 0x6C4
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_2_0 0x6C8
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_3_0 0x6CC
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_4_0 0x6D0
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK0_5_0 0x6D4
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_0_0 0x6E0
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_1_0 0x6E4
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_2_0 0x6E8
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_3_0 0x6EC
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_4_0 0x6F0
|
||||
#define EMC_PMACRO_IB_DDLL_LONG_DQS_RANK1_5_0 0x6F4
|
||||
#define EMC_PMACRO_AUTOCAL_CFG_0_0 0x700
|
||||
#define EMC_PMACRO_AUTOCAL_CFG_1_0 0x704
|
||||
#define EMC_PMACRO_AUTOCAL_CFG_2_0 0x708
|
||||
#define EMC_PMACRO_TX_PWRD_0_0 0x720
|
||||
#define EMC_PMACRO_TX_PWRD_1_0 0x724
|
||||
#define EMC_PMACRO_TX_PWRD_2_0 0x728
|
||||
#define EMC_PMACRO_TX_PWRD_3_0 0x72C
|
||||
#define EMC_PMACRO_TX_PWRD_4_0 0x730
|
||||
#define EMC_PMACRO_TX_PWRD_5_0 0x734
|
||||
#define EMC_PMACRO_TX_SEL_CLK_SRC_0_0 0x740
|
||||
#define EMC_PMACRO_TX_SEL_CLK_SRC_1_0 0x744
|
||||
#define EMC_PMACRO_TX_SEL_CLK_SRC_2_0 0x748
|
||||
#define EMC_PMACRO_TX_SEL_CLK_SRC_3_0 0x74C
|
||||
#define EMC_PMACRO_TX_SEL_CLK_SRC_4_0 0x750
|
||||
#define EMC_PMACRO_TX_SEL_CLK_SRC_5_0 0x754
|
||||
#define EMC_PMACRO_DDLL_BYPASS_0 0x760
|
||||
#define EMC_PMACRO_DDLL_PWRD_0_0 0x770
|
||||
#define EMC_PMACRO_DDLL_PWRD_1_0 0x774
|
||||
#define EMC_PMACRO_DDLL_PWRD_2_0 0x778
|
||||
#define EMC_PMACRO_CMD_CTRL_0_0 0x780
|
||||
#define EMC_PMACRO_CMD_CTRL_1_0 0x784
|
||||
#define EMC_PMACRO_CMD_CTRL_2_0 0x788
|
||||
|
||||
#define MC_REGISTER_BASE 0x70019000
|
||||
#define MC_REGISTER_REGION_SIZE 0x1000
|
||||
|
||||
#define MC_INTSTATUS_0 0x000
|
||||
#define MC_INTMASK_0 0x004
|
||||
#define MC_ERR_STATUS_0 0x008
|
||||
#define MC_ERR_ADR_0 0x00C
|
||||
#define MC_SMMU_CONFIG_0 0x010
|
||||
#define MC_SMMU_PTB_ASID_0 0x01C
|
||||
#define MC_SMMU_PTB_DATA_0 0x020
|
||||
#define MC_SMMU_TLB_FLUSH_0 0x030
|
||||
#define MC_SMMU_PTC_FLUSH_0_0 0x034
|
||||
#define MC_EMEM_CFG_0 0x050
|
||||
#define MC_EMEM_ADR_CFG_0 0x054
|
||||
#define MC_EMEM_ARB_CFG_0 0x090
|
||||
#define MC_EMEM_ARB_OUTSTANDING_REQ_0 0x094
|
||||
#define MC_EMEM_ARB_TIMING_RCD_0 0x098
|
||||
#define MC_EMEM_ARB_TIMING_RP_0 0x09C
|
||||
#define MC_EMEM_ARB_TIMING_RC_0 0x0A0
|
||||
#define MC_EMEM_ARB_TIMING_RAS_0 0x0A4
|
||||
#define MC_EMEM_ARB_TIMING_FAW_0 0x0A8
|
||||
#define MC_EMEM_ARB_TIMING_RRD_0 0x0AC
|
||||
#define MC_EMEM_ARB_TIMING_RAP2PRE_0 0x0B0
|
||||
#define MC_EMEM_ARB_TIMING_WAP2PRE_0 0x0B4
|
||||
#define MC_EMEM_ARB_TIMING_R2R_0 0x0B8
|
||||
#define MC_EMEM_ARB_TIMING_W2W_0 0x0BC
|
||||
#define MC_EMEM_ARB_TIMING_R2W_0 0x0C0
|
||||
#define MC_EMEM_ARB_TIMING_W2R_0 0x0C4
|
||||
#define MC_EMEM_ARB_MISC2_0 0x0C8
|
||||
#define MC_EMEM_ARB_DA_TURNS_0 0x0D0
|
||||
#define MC_EMEM_ARB_DA_COVERS_0 0x0D4
|
||||
#define MC_EMEM_ARB_MISC0_0 0x0D8
|
||||
#define MC_EMEM_ARB_MISC1_0 0x0DC
|
||||
#define MC_TIMING_CONTROL_0 0xFC
|
||||
#define MC_EMEM_ARB_RING1_THROTTLE_0 0x0E0
|
||||
#define MC_CLIENT_HOTRESET_CTRL_0 0x200
|
||||
#define MC_CLIENT_HOTRESET_STATUS_0 0x204
|
||||
#define MC_SMMU_AFI_ASID_0 0x238
|
||||
#define MC_SMMU_DC_ASID_0 0x240
|
||||
#define MC_SMMU_DCB_ASID_0 0x244
|
||||
#define MC_SMMU_HC_ASID_0 0x250
|
||||
#define MC_SMMU_HDA_ASID_0 0x254
|
||||
#define MC_SMMU_ISP2_ASID_0 0x258
|
||||
#define MC_SMMU_MSENC_NVENC_ASID_0 0x264
|
||||
#define MC_SMMU_NV_ASID_0 0x268
|
||||
#define MC_SMMU_NV2_ASID_0 0x26C
|
||||
#define MC_SMMU_PPCS_ASID_0 0x270
|
||||
#define MC_SMMU_SATA_ASID_0 0x274
|
||||
#define MC_SMMU_VI_ASID_0 0x280
|
||||
#define MC_SMMU_VIC_ASID_0 0x284
|
||||
#define MC_SMMU_XUSB_HOST_ASID_0 0x288
|
||||
#define MC_SMMU_XUSB_DEV_ASID_0 0x28C
|
||||
#define MC_SMMU_TSEC_ASID_0 0x294
|
||||
#define MC_LATENCY_ALLOWANCE_AVPC_0 0x2E4
|
||||
#define MC_LATENCY_ALLOWANCE_DC_0 0x2E8
|
||||
#define MC_LATENCY_ALLOWANCE_DC_1 0x2EC
|
||||
#define MC_LATENCY_ALLOWANCE_DCB_0 0x2F4
|
||||
#define MC_LATENCY_ALLOWANCE_DCB_1 0x2F8
|
||||
#define MC_LATENCY_ALLOWANCE_HC_0 0x310
|
||||
#define MC_LATENCY_ALLOWANCE_HC_1 0x314
|
||||
#define MC_LATENCY_ALLOWANCE_MPCORE_0 0x320
|
||||
#define MC_LATENCY_ALLOWANCE_NVENC_0 0x328
|
||||
#define MC_LATENCY_ALLOWANCE_PPCS_0 0x344
|
||||
#define MC_LATENCY_ALLOWANCE_PPCS_1 0x348
|
||||
#define MC_LATENCY_ALLOWANCE_ISP2_0 0x370
|
||||
#define MC_LATENCY_ALLOWANCE_ISP2_1 0x374
|
||||
#define MC_LATENCY_ALLOWANCE_XUSB_0 0x37C
|
||||
#define MC_LATENCY_ALLOWANCE_XUSB_1 0x380
|
||||
#define MC_LATENCY_ALLOWANCE_TSEC_0 0x390
|
||||
#define MC_LATENCY_ALLOWANCE_VIC_0 0x394
|
||||
#define MC_LATENCY_ALLOWANCE_VI2_0 0x398
|
||||
#define MC_LATENCY_ALLOWANCE_GPU_0 0x3AC
|
||||
#define MC_LATENCY_ALLOWANCE_SDMMCA_0 0x3B8
|
||||
#define MC_LATENCY_ALLOWANCE_SDMMCAA_0 0x3BC
|
||||
#define MC_LATENCY_ALLOWANCE_SDMMC_0 0x3C0
|
||||
#define MC_LATENCY_ALLOWANCE_SDMMCAB_0 0x3C4
|
||||
#define MC_LATENCY_ALLOWANCE_NVDEC_0 0x3D8
|
||||
#define MC_LATENCY_ALLOWANCE_GPU2_0 0x3E8
|
||||
#define MC_DIS_PTSA_RATE_0 0x41C
|
||||
#define MC_DIS_PTSA_MIN_0 0x420
|
||||
#define MC_DIS_PTSA_MAX_0 0x424
|
||||
#define MC_DISB_PTSA_RATE_0 0x428
|
||||
#define MC_DISB_PTSA_MIN_0 0x42C
|
||||
#define MC_DISB_PTSA_MAX_0 0x430
|
||||
#define MC_VE_PTSA_RATE_0 0x434
|
||||
#define MC_VE_PTSA_MIN_0 0x438
|
||||
#define MC_VE_PTSA_MAX_0 0x43C
|
||||
#define MC_MLL_MPCORER_PTSA_RATE_0 0x44C
|
||||
#define MC_RING1_PTSA_RATE_0 0x47C
|
||||
#define MC_RING1_PTSA_MIN_0 0x480
|
||||
#define MC_RING1_PTSA_MAX_0 0x484
|
||||
#define MC_PCX_PTSA_RATE_0 0x4AC
|
||||
#define MC_PCX_PTSA_MIN_0 0x4B0
|
||||
#define MC_PCX_PTSA_MAX_0 0x4B4
|
||||
#define MC_MSE_PTSA_RATE_0 0x4C4
|
||||
#define MC_MSE_PTSA_MIN_0 0x4C8
|
||||
#define MC_MSE_PTSA_MAX_0 0x4CC
|
||||
#define MC_AHB_PTSA_RATE_0 0x4DC
|
||||
#define MC_AHB_PTSA_MIN_0 0x4E0
|
||||
#define MC_AHB_PTSA_MAX_0 0x4E4
|
||||
#define MC_APB_PTSA_RATE_0 0x4E8
|
||||
#define MC_APB_PTSA_MIN_0 0x4EC
|
||||
#define MC_APB_PTSA_MAX_0 0x4F0
|
||||
#define MC_FTOP_PTSA_RATE_0 0x50C
|
||||
#define MC_HOST_PTSA_RATE_0 0x518
|
||||
#define MC_HOST_PTSA_MIN_0 0x51C
|
||||
#define MC_HOST_PTSA_MAX_0 0x520
|
||||
#define MC_USBX_PTSA_RATE_0 0x524
|
||||
#define MC_USBX_PTSA_MIN_0 0x528
|
||||
#define MC_USBX_PTSA_MAX_0 0x52C
|
||||
#define MC_USBD_PTSA_RATE_0 0x530
|
||||
#define MC_USBD_PTSA_MIN_0 0x534
|
||||
#define MC_USBD_PTSA_MAX_0 0x538
|
||||
#define MC_GK_PTSA_RATE_0 0x53C
|
||||
#define MC_GK_PTSA_MIN_0 0x540
|
||||
#define MC_GK_PTSA_MAX_0 0x544
|
||||
#define MC_AUD_PTSA_RATE_0 0x548
|
||||
#define MC_AUD_PTSA_MIN_0 0x54C
|
||||
#define MC_AUD_PTSA_MAX_0 0x550
|
||||
#define MC_VICPC_PTSA_RATE_0 0x554
|
||||
#define MC_VICPC_PTSA_MIN_0 0x558
|
||||
#define MC_VICPC_PTSA_MAX_0 0x55C
|
||||
#define MC_JPG_PTSA_RATE_0 0x584
|
||||
#define MC_JPG_PTSA_MIN_0 0x588
|
||||
#define MC_JPG_PTSA_MAX_0 0x58C
|
||||
#define MC_GK2_PTSA_RATE_0 0x610
|
||||
#define MC_GK2_PTSA_MIN_0 0x614
|
||||
#define MC_GK2_PTSA_MAX_0 0x618
|
||||
#define MC_SDM_PTSA_RATE_0 0x61C
|
||||
#define MC_SDM_PTSA_MIN_0 0x620
|
||||
#define MC_SDM_PTSA_MAX_0 0x624
|
||||
#define MC_HDAPC_PTSA_RATE_0 0x628
|
||||
#define MC_HDAPC_PTSA_MIN_0 0x62C
|
||||
#define MC_HDAPC_PTSA_MAX_0 0x630
|
||||
#define MC_SEC_CARVEOUT_BOM_0 0x670
|
||||
#define MC_SEC_CARVEOUT_SIZE_MB_0 0x674
|
||||
#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0A_0 0x690
|
||||
#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0AB_0 0x694
|
||||
#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0B_0 0x698
|
||||
#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0BB_0 0x69C
|
||||
#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0C_0 0x6A0
|
||||
#define MC_SCALED_LATENCY_ALLOWANCE_DISPLAY0CB_0 0x6A4
|
||||
#define MC_EMEM_ARB_TIMING_RFCPB_0 0x6C0
|
||||
#define MC_EMEM_ARB_TIMING_CCDMW_0 0x6C4
|
||||
#define MC_EMEM_ARB_REFPB_HP_CTRL_0 0x6F0
|
||||
#define MC_EMEM_ARB_REFPB_BANK_CTRL_0 0x6F4
|
||||
#define MC_PTSA_GRANT_DECREMENT_0 0x960
|
||||
#define MC_CLIENT_HOTRESET_CTRL_1 0x970
|
||||
#define MC_CLIENT_HOTRESET_STATUS_1 0x974
|
||||
#define MC_SMMU_PTC_FLUSH_1 0x9B8
|
||||
#define MC_SMMU_DC1_ASID_0 0xA88
|
||||
#define MC_SMMU_SDMMC1A_ASID_0 0xA94
|
||||
#define MC_SMMU_SDMMC2A_ASID_0 0xA98
|
||||
#define MC_SMMU_SDMMC3A_ASID_0 0xA9C
|
||||
#define MC_SMMU_SDMMC4A_ASID_0 0xAA0
|
||||
#define MC_SMMU_ISP2B_ASID_0 0xAA4
|
||||
#define MC_SMMU_GPU_ASID_0 0xAA8
|
||||
#define MC_SMMU_GPUB_ASID_0 0xAAC
|
||||
#define MC_SMMU_PPCS2_ASID_0 0xAB0
|
||||
#define MC_SMMU_NVDEC_ASID_0 0xAB4
|
||||
#define MC_SMMU_APE_ASID_0 0xAB8
|
||||
#define MC_SMMU_SE_ASID_0 0xABC
|
||||
#define MC_SMMU_NVJPG_ASID_0 0xAC0
|
||||
#define MC_SMMU_HC1_ASID_0 0xAC4
|
||||
#define MC_SMMU_SE1_ASID_0 0xAC8
|
||||
#define MC_SMMU_AXIAP_ASID_0 0xACC
|
||||
#define MC_SMMU_ETR_ASID_0 0xAD0
|
||||
#define MC_SMMU_TSECB_ASID_0 0xAD4
|
||||
#define MC_SMMU_TSEC1_ASID_0 0xAD8
|
||||
#define MC_SMMU_TSECB1_ASID_0 0xADC
|
||||
#define MC_SMMU_NVDEC1_ASID_0 0xAE0
|
||||
#define MC_EMEM_ARB_DHYST_CTRL_0 0xBCC
|
||||
#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_0 0xBD0
|
||||
#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_1 0xBD4
|
||||
#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_2 0xBD8
|
||||
#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_3 0xBDC
|
||||
#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_4 0xBE0
|
||||
#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_5 0xBE4
|
||||
#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_6 0xBE8
|
||||
#define MC_EMEM_ARB_DHYST_TIMEOUT_UTIL_7 0xBEC
|
||||
#define MC_ERR_GENERALIZED_CARVEOUT_STATUS_0 0xC00
|
||||
#define MC_SECURITY_CARVEOUT2_BOM_0 0xC5C
|
||||
#define MC_SECURITY_CARVEOUT3_BOM_0 0xCAC
|
||||
|
||||
#define CLDVFS_REGION_BASE 0x70110000
|
||||
#define CLDVFS_REGION_SIZE 0x1000
|
||||
#define CL_DVFS_CTRL_0 0x0
|
||||
#define CL_DVFS_CONFIG_0 0x4
|
||||
#define CL_DVFS_PARAMS_0 0x8
|
||||
#define CL_DVFS_TUNE0_0 0xC
|
||||
#define CL_DVFS_TUNE1_0 0x10
|
||||
#define CL_DVFS_FREQ_REQ_0 0x14
|
||||
#define CL_DVFS_SCALE_RAMP_0 0x18
|
||||
#define CL_DVFS_DROOP_CTRL_0 0x1C
|
||||
#define CL_DVFS_OUTPUT_CFG_0 0x20
|
||||
#define CL_DVFS_OUTPUT_FORCE_0 0x24
|
||||
#define CL_DVFS_MONITOR_CTRL_0 0x28
|
||||
#define CL_DVFS_MONITOR_DATA_0 0x2C
|
||||
#define CL_DVFS_I2C_CFG_0 0x40
|
||||
#define CL_DVFS_I2C_VDD_REG_ADDR_0 0x44
|
||||
#define CL_DVFS_I2C_STS_0 0x48
|
||||
#define CL_DVFS_INTR_STS_0 0x5C
|
||||
#define CL_DVFS_INTR_EN_0 0x60
|
||||
#define DVFS_DFLL_THROTTLE_CTRL_0 0x64
|
||||
#define DVFS_DFLL_THROTTLE_LIGHT_0 0x68
|
||||
#define DVFS_DFLL_THROTTLE_MEDIUM_0 0x6C
|
||||
#define DVFS_DFLL_THROTTLE_HEAVY_0 0x70
|
||||
#define DVFS_CC4_HVC_0 0x74
|
||||
#define CL_DVFS_MONITOR_DATA_0 0x2C
|
||||
#define CL_DVFS_I2C_CFG_0 0x40
|
||||
#define CL_DVFS_I2C_VDD_REG_ADDR_0 0x44
|
||||
#define CL_DVFS_I2C_STS_0 0x48
|
||||
#define CL_DVFS_INTR_STS_0 0x5C
|
||||
#define CL_DVFS_I2C_CLK_DIVISOR_REGISTER_0 0x16C
|
||||
38
Source/rewrite-hoc-clk/common/include/rgltr.h
Normal file
38
Source/rewrite-hoc-clk/common/include/rgltr.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) ppkantorski (bord2death)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
#include "pcv_types.h"
|
||||
|
||||
typedef struct {
|
||||
Service s;
|
||||
} RgltrSession;
|
||||
|
||||
Result rgltrInitialize(void);
|
||||
|
||||
void rgltrExit(void);
|
||||
|
||||
Service* rgltrGetServiceSession(void);
|
||||
|
||||
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id);
|
||||
void rgltrCloseSession(RgltrSession* session);
|
||||
Result rgltrGetVoltage(RgltrSession* session, u32 *out_volt);
|
||||
Result rgltrGetPowerModuleNumLimit(u32 *out);
|
||||
Result rgltrGetVoltageEnabled(RgltrSession* session, u32 *out);
|
||||
Result rgltrRequestVoltage(RgltrSession* session, u32 microvolt);
|
||||
Result rgltrCancelVoltageRequest(RgltrSession* session);
|
||||
32
Source/rewrite-hoc-clk/common/include/rgltr_services.h
Normal file
32
Source/rewrite-hoc-clk/common/include/rgltr_services.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) ppkantorski (bord2death)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h> // for Service, Result, hosversionBefore(), smGetService(), serviceClose(), etc.
|
||||
#include "rgltr.h" // for RgltrSession, PowerDomainId, etc.
|
||||
|
||||
extern Service g_rgltrSrv;
|
||||
|
||||
Result rgltrInitialize(void);
|
||||
void rgltrExit(void);
|
||||
|
||||
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id);
|
||||
|
||||
Result rgltrGetVoltage(RgltrSession* session, u32* out_volt);
|
||||
|
||||
void rgltrCloseSession(RgltrSession* session);
|
||||
82
Source/rewrite-hoc-clk/common/include/service_guard.h
Normal file
82
Source/rewrite-hoc-clk/common/include/service_guard.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) MasaGratoR
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <switch/types.h>
|
||||
#include <switch/result.h>
|
||||
#include <switch/kernel/mutex.h>
|
||||
#include <switch/sf/service.h>
|
||||
#include <switch/services/sm.h>
|
||||
|
||||
typedef struct ServiceGuard {
|
||||
Mutex mutex;
|
||||
u32 refCount;
|
||||
} ServiceGuard;
|
||||
|
||||
NX_INLINE bool serviceGuardBeginInit(ServiceGuard* g)
|
||||
{
|
||||
mutexLock(&g->mutex);
|
||||
return (g->refCount++) == 0;
|
||||
}
|
||||
|
||||
NX_INLINE Result serviceGuardEndInit(ServiceGuard* g, Result rc, void (*cleanupFunc)(void))
|
||||
{
|
||||
if (R_FAILED(rc)) {
|
||||
cleanupFunc();
|
||||
--g->refCount;
|
||||
}
|
||||
mutexUnlock(&g->mutex);
|
||||
return rc;
|
||||
}
|
||||
|
||||
NX_INLINE void serviceGuardExit(ServiceGuard* g, void (*cleanupFunc)(void))
|
||||
{
|
||||
mutexLock(&g->mutex);
|
||||
if (g->refCount && (--g->refCount) == 0)
|
||||
cleanupFunc();
|
||||
mutexUnlock(&g->mutex);
|
||||
}
|
||||
|
||||
#define NX_GENERATE_SERVICE_GUARD_PARAMS(name, _paramdecl, _parampass) \
|
||||
\
|
||||
static ServiceGuard g_##name##Guard; \
|
||||
NX_INLINE Result _##name##Initialize _paramdecl; \
|
||||
static void _##name##Cleanup(void); \
|
||||
\
|
||||
Result name##Initialize _paramdecl \
|
||||
{ \
|
||||
Result rc = 0; \
|
||||
if (serviceGuardBeginInit(&g_##name##Guard)) \
|
||||
rc = _##name##Initialize _parampass; \
|
||||
return serviceGuardEndInit(&g_##name##Guard, rc, _##name##Cleanup); \
|
||||
} \
|
||||
\
|
||||
void name##Exit(void) \
|
||||
{ \
|
||||
serviceGuardExit(&g_##name##Guard, _##name##Cleanup); \
|
||||
}
|
||||
|
||||
#define NX_GENERATE_SERVICE_GUARD(name) NX_GENERATE_SERVICE_GUARD_PARAMS(name, (void), ())
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
55
Source/rewrite-hoc-clk/common/include/sysclk.h
Normal file
55
Source/rewrite-hoc-clk/common/include/sysclk.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <switch.h> // include libnx
|
||||
#ifdef __cplusplus
|
||||
#include "cpp_util.hpp"
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// typedef std::uint32_t Result;
|
||||
// typedef std::uint32_t u32;
|
||||
// typedef std::int32_t s32;
|
||||
// typedef std::uint64_t u64;
|
||||
// typedef std::int64_t s64;
|
||||
// typedef std::uint8_t u8;
|
||||
// typedef std::int16_t s16;
|
||||
// typedef std::uint16_t u16;
|
||||
|
||||
#include "sysclk/ipc.h"
|
||||
#include "sysclk/board.h"
|
||||
#include "sysclk/clock_manager.h"
|
||||
#include "sysclk/apm.h"
|
||||
#include "sysclk/config.h"
|
||||
#include "sysclk/errors.h"
|
||||
#include "sysclk/psm_ext.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
39
Source/rewrite-hoc-clk/common/include/sysclk/apm.h
Normal file
39
Source/rewrite-hoc-clk/common/include/sysclk/apm.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "board.h"
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
uint32_t cpu_hz;
|
||||
uint32_t gpu_hz;
|
||||
uint32_t mem_hz;
|
||||
} SysClkApmConfiguration;
|
||||
|
||||
extern SysClkApmConfiguration sysclk_g_apm_configurations[];
|
||||
270
Source/rewrite-hoc-clk/common/include/sysclk/board.h
Normal file
270
Source/rewrite-hoc-clk/common/include/sysclk/board.h
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <switch/types.h>
|
||||
typedef enum
|
||||
{
|
||||
SysClkSocType_Erista = 0,
|
||||
SysClkSocType_Mariko,
|
||||
SysClkSocType_EnumMax
|
||||
} SysClkSocType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HorizonOCConsoleType_Icosa = 0,
|
||||
HorizonOCConsoleType_Copper,
|
||||
HorizonOCConsoleType_Hoag,
|
||||
HorizonOCConsoleType_Iowa,
|
||||
HorizonOCConsoleType_Calcio,
|
||||
HorizonOCConsoleType_Aula,
|
||||
HorizonOCConsoleType_EnumMax,
|
||||
} HorizonOCConsoleType;
|
||||
|
||||
typedef enum {
|
||||
HocClkVoltage_SOC = 0,
|
||||
HocClkVoltage_EMCVDD2,
|
||||
HocClkVoltage_CPU,
|
||||
HocClkVoltage_GPU,
|
||||
HocClkVoltage_EMCVDDQ_MarikoOnly,
|
||||
HocClkVoltage_Display,
|
||||
HocClkVoltage_Battery,
|
||||
HocClkVoltage_EnumMax,
|
||||
} HocClkVoltage;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SysClkProfile_Handheld = 0,
|
||||
SysClkProfile_HandheldCharging,
|
||||
SysClkProfile_HandheldChargingUSB,
|
||||
SysClkProfile_HandheldChargingOfficial,
|
||||
SysClkProfile_Docked,
|
||||
SysClkProfile_EnumMax
|
||||
} SysClkProfile;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SysClkModule_CPU = 0,
|
||||
SysClkModule_GPU,
|
||||
SysClkModule_MEM,
|
||||
HorizonOCModule_Governor,
|
||||
HorizonOCModule_Display,
|
||||
SysClkModule_EnumMax,
|
||||
} SysClkModule;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SysClkThermalSensor_SOC = 0,
|
||||
SysClkThermalSensor_PCB,
|
||||
SysClkThermalSensor_Skin,
|
||||
HorizonOCThermalSensor_Battery,
|
||||
HorizonOCThermalSensor_PMIC,
|
||||
SysClkThermalSensor_EnumMax
|
||||
} SysClkThermalSensor;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SysClkPowerSensor_Now = 0,
|
||||
SysClkPowerSensor_Avg,
|
||||
SysClkPowerSensor_EnumMax
|
||||
} SysClkPowerSensor;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SysClkPartLoad_EMC = 0,
|
||||
SysClkPartLoad_EMCCpu,
|
||||
HocClkPartLoad_GPU,
|
||||
HocClkPartLoad_CPUMax,
|
||||
HocClkPartLoad_BAT,
|
||||
HocClkPartLoad_FAN,
|
||||
SysClkPartLoad_EnumMax
|
||||
} SysClkPartLoad;
|
||||
|
||||
typedef enum {
|
||||
HorizonOCSpeedo_CPU = 0,
|
||||
HorizonOCSpeedo_GPU,
|
||||
HorizonOCSpeedo_SOC,
|
||||
HorizonOCSpeedo_EnumMax,
|
||||
} HorizonOCSpeedo;
|
||||
|
||||
typedef enum {
|
||||
GPUUVLevel_NoUV = 0,
|
||||
GPUUVLevel_SLT,
|
||||
GPUUVLevel_HiOPT,
|
||||
GPUUVLevel_EnumMax,
|
||||
} GPUUndervoltLevel;
|
||||
|
||||
enum {
|
||||
DVFSMode_Disabled = 0,
|
||||
DVFSMode_Hijack,
|
||||
// DVFSMode_OfficialService,
|
||||
// DVFSMode_Hack,
|
||||
DVFSMode_EnumMax,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
GpuSchedulingMode_DoNotOverride = 0,
|
||||
GpuSchedulingMode_Enabled,
|
||||
GpuSchedulingMode_Disabled,
|
||||
GpuSchedulingMode_EnumMax,
|
||||
} GpuSchedulingMode;
|
||||
|
||||
typedef enum {
|
||||
GpuSchedulingOverrideMethod_Ini = 0,
|
||||
GpuSchedulingOverrideMethod_NvService,
|
||||
GpuSchedulingOverrideMethod_EnumMax,
|
||||
} GpuSchedulingOverrideMethod;
|
||||
typedef enum {
|
||||
ComponentGovernor_DoNotOverride = 0,
|
||||
ComponentGovernor_Disabled = 1,
|
||||
ComponentGovernor_Enabled = 2,
|
||||
ComponentGovernor_EnumMax,
|
||||
} ComponentGovernorState;
|
||||
typedef enum {
|
||||
RamDisplayMode_VDD2VDDQ = 0,
|
||||
RamDisplayMode_VDD2Usage,
|
||||
RamDisplayMode_VDDQUsage,
|
||||
RamDisplayMode_EnumMax,
|
||||
} RamDisplayMode;
|
||||
|
||||
#define SYSCLK_ENUM_VALID(n, v) ((v) < n##_EnumMax)
|
||||
|
||||
// Packed u32
|
||||
// Bits 0-7 - CPU
|
||||
// Bits 8-15 - GPU
|
||||
// Bits 16-23 - VRR
|
||||
// Bits 24-32 - unused
|
||||
|
||||
inline u32 GovernorStatePack(u8 cpu, u8 gpu, u8 vrr) {
|
||||
return (u32)cpu | ((u32)gpu << 8) | ((u32)vrr << 16);
|
||||
}
|
||||
inline u8 GovernorStateCpu(u32 p) {
|
||||
return (u8)(p & 0xFF);
|
||||
}
|
||||
inline u8 GovernorStateGpu(u32 p) {
|
||||
return (u8)((p >> 8) & 0xFF);
|
||||
}
|
||||
inline u8 GovernorStateVrr(u32 p) {
|
||||
return (u8)((p >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
static inline const char* sysclkFormatModule(SysClkModule module, bool pretty)
|
||||
{
|
||||
switch(module)
|
||||
{
|
||||
case SysClkModule_CPU:
|
||||
return pretty ? "CPU" : "cpu";
|
||||
case SysClkModule_GPU:
|
||||
return pretty ? "GPU" : "gpu";
|
||||
case SysClkModule_MEM:
|
||||
return pretty ? "Memory" : "mem";
|
||||
case HorizonOCModule_Display:
|
||||
return pretty ? "Display" : "display";
|
||||
case HorizonOCModule_Governor:
|
||||
return pretty ? "Governor" : "governor";
|
||||
default:
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
static inline const char* sysclkFormatThermalSensor(SysClkThermalSensor thermSensor, bool pretty)
|
||||
{
|
||||
switch(thermSensor)
|
||||
{
|
||||
case SysClkThermalSensor_SOC:
|
||||
return pretty ? "SOC" : "soc";
|
||||
case SysClkThermalSensor_PCB:
|
||||
return pretty ? "PCB" : "pcb";
|
||||
case SysClkThermalSensor_Skin:
|
||||
return pretty ? "Skin" : "skin";
|
||||
case HorizonOCThermalSensor_Battery:
|
||||
return pretty ? "BAT" : "battery";
|
||||
case HorizonOCThermalSensor_PMIC:
|
||||
return pretty ? "PMIC" : "pmic";
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline const char* sysclkFormatPowerSensor(SysClkPowerSensor powSensor, bool pretty)
|
||||
{
|
||||
switch(powSensor)
|
||||
{
|
||||
case SysClkPowerSensor_Now:
|
||||
return pretty ? "Now" : "now";
|
||||
case SysClkPowerSensor_Avg:
|
||||
return pretty ? "Avg" : "avg";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline const char* sysclkFormatProfile(SysClkProfile profile, bool pretty)
|
||||
{
|
||||
switch(profile)
|
||||
{
|
||||
case SysClkProfile_Docked:
|
||||
return pretty ? "Docked" : "docked";
|
||||
case SysClkProfile_Handheld:
|
||||
return pretty ? "Handheld" : "handheld";
|
||||
case SysClkProfile_HandheldCharging:
|
||||
return pretty ? "Charging" : "handheld_charging";
|
||||
case SysClkProfile_HandheldChargingUSB:
|
||||
return pretty ? "USB Charger" : "handheld_charging_usb";
|
||||
case SysClkProfile_HandheldChargingOfficial:
|
||||
return pretty ? "PD Charger" : "handheld_charging_official";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline const char* hocClkFormatVoltage(HocClkVoltage voltage, bool pretty)
|
||||
{
|
||||
switch(voltage)
|
||||
{
|
||||
case HocClkVoltage_CPU:
|
||||
return pretty ? "CPU" : "cpu";
|
||||
case HocClkVoltage_GPU:
|
||||
return pretty ? "GPU" : "gpu";
|
||||
case HocClkVoltage_EMCVDD2:
|
||||
return pretty ? "VDD2" : "emcvdd2";
|
||||
case HocClkVoltage_EMCVDDQ_MarikoOnly:
|
||||
return pretty ? "VDDQ" : "vddq";
|
||||
case HocClkVoltage_SOC:
|
||||
return pretty ? "SOC" : "soc";
|
||||
case HocClkVoltage_Display:
|
||||
return pretty ? "Display" : "display";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
57
Source/rewrite-hoc-clk/common/include/sysclk/client/ipc.h
Normal file
57
Source/rewrite-hoc-clk/common/include/sysclk/client/ipc.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "../config.h"
|
||||
#include "../board.h"
|
||||
#include "../ipc.h"
|
||||
|
||||
bool sysclkIpcRunning();
|
||||
Result sysclkIpcInitialize(void);
|
||||
void sysclkIpcExit(void);
|
||||
|
||||
Result sysclkIpcGetAPIVersion(u32* out_ver);
|
||||
Result sysclkIpcGetVersionString(char* out, size_t len);
|
||||
Result sysclkIpcGetCurrentContext(SysClkContext* out_context);
|
||||
Result sysclkIpcGetProfileCount(u64 tid, u8* out_count);
|
||||
Result sysclkIpcSetEnabled(bool enabled);
|
||||
Result sysclkIpcExitCmd();
|
||||
Result sysclkIpcSetOverride(SysClkModule module, u32 hz);
|
||||
Result sysclkIpcGetProfiles(u64 tid, SysClkTitleProfileList* out_profiles);
|
||||
Result sysclkIpcSetProfiles(u64 tid, SysClkTitleProfileList* profiles);
|
||||
Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues);
|
||||
Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues);
|
||||
Result sysclkIpcGetFreqList(SysClkModule module, u32* list, u32 maxCount, u32* outCount);
|
||||
Result hocClkIpcSetKipData();
|
||||
Result hocClkIpcGetKipData();
|
||||
|
||||
static inline Result sysclkIpcRemoveOverride(SysClkModule module)
|
||||
{
|
||||
return sysclkIpcSetOverride(module, 0);
|
||||
}
|
||||
46
Source/rewrite-hoc-clk/common/include/sysclk/client/types.h
Normal file
46
Source/rewrite-hoc-clk/common/include/sysclk/client/types.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __SWITCH__
|
||||
|
||||
#include <switch/types.h>
|
||||
#include <switch/result.h>
|
||||
|
||||
#else
|
||||
|
||||
#define R_FAILED(res) ((res) != 0)
|
||||
#define R_SUCCEEDED(res) ((res) == 0)
|
||||
|
||||
typedef std::uint32_t Result;
|
||||
typedef std::uint32_t u32;
|
||||
typedef std::int32_t s32;
|
||||
typedef std::uint64_t u64;
|
||||
typedef std::uint8_t u8;
|
||||
|
||||
#endif
|
||||
66
Source/rewrite-hoc-clk/common/include/sysclk/clock_manager.h
Normal file
66
Source/rewrite-hoc-clk/common/include/sysclk/clock_manager.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "board.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t applicationId;
|
||||
SysClkProfile profile;
|
||||
uint32_t freqs[SysClkModule_EnumMax];
|
||||
uint32_t realFreqs[SysClkModule_EnumMax];
|
||||
uint32_t overrideFreqs[SysClkModule_EnumMax];
|
||||
uint32_t temps[SysClkThermalSensor_EnumMax];
|
||||
int32_t power[SysClkPowerSensor_EnumMax];
|
||||
uint32_t partLoad[SysClkPartLoad_EnumMax];
|
||||
uint32_t voltages[HocClkVoltage_EnumMax];
|
||||
u16 speedos[HorizonOCSpeedo_EnumMax];
|
||||
u16 iddq[HorizonOCSpeedo_EnumMax];
|
||||
GpuSchedulingMode gpuSchedulingMode;
|
||||
bool isSysDockInstalled;
|
||||
bool isSaltyNXInstalled;
|
||||
u8 maxDisplayFreq;
|
||||
u8 dramID;
|
||||
bool isDram8GB;
|
||||
u8 fps;
|
||||
u16 resolutionHeight;
|
||||
} SysClkContext;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union {
|
||||
uint32_t mhz[+SysClkProfile_EnumMax * +SysClkModule_EnumMax];
|
||||
uint32_t mhzMap[+SysClkProfile_EnumMax][+SysClkModule_EnumMax];
|
||||
};
|
||||
} SysClkTitleProfileList;
|
||||
|
||||
#define SYSCLK_FREQ_LIST_MAX 32
|
||||
|
||||
#define GLOBAL_PROFILE_ID 0xA111111111111111
|
||||
594
Source/rewrite-hoc-clk/common/include/sysclk/config.h
Normal file
594
Source/rewrite-hoc-clk/common/include/sysclk/config.h
Normal file
@@ -0,0 +1,594 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum {
|
||||
SysClkConfigValue_PollingIntervalMs = 0,
|
||||
SysClkConfigValue_TempLogIntervalMs,
|
||||
SysClkConfigValue_FreqLogIntervalMs,
|
||||
SysClkConfigValue_PowerLogIntervalMs,
|
||||
SysClkConfigValue_CsvWriteIntervalMs,
|
||||
|
||||
HocClkConfigValue_UncappedClocks,
|
||||
HocClkConfigValue_OverwriteBoostMode,
|
||||
|
||||
HocClkConfigValue_EristaMaxCpuClock,
|
||||
HocClkConfigValue_MarikoMaxCpuClock,
|
||||
|
||||
HocClkConfigValue_ThermalThrottle,
|
||||
HocClkConfigValue_ThermalThrottleThreshold,
|
||||
|
||||
HocClkConfigValue_HandheldTDP,
|
||||
HocClkConfigValue_HandheldTDPLimit,
|
||||
|
||||
HocClkConfigValue_LiteTDPLimit,
|
||||
|
||||
HorizonOCConfigValue_BatteryChargeCurrent,
|
||||
|
||||
HorizonOCConfigValue_OverwriteRefreshRate,
|
||||
HorizonOCConfigValue_MaxDisplayClockH,
|
||||
|
||||
HorizonOCConfigValue_DVFSMode,
|
||||
HorizonOCConfigValue_DVFSOffset,
|
||||
HorizonOCConfigValue_LiveCpuUv,
|
||||
HorizonOCConfigValue_EnableExperimentalSettings,
|
||||
|
||||
HorizonOCConfigValue_GPUScheduling,
|
||||
HorizonOCConfigValue_GPUSchedulingMethod,
|
||||
|
||||
HorizonOCConfigValue_RAMVoltUsageDisplayMode,
|
||||
HorizonOCConfigValue_CpuGovernorMinimumFreq,
|
||||
|
||||
KipConfigValue_custRev,
|
||||
// KipConfigValue_mtcConf,
|
||||
KipConfigValue_hpMode,
|
||||
|
||||
KipConfigValue_commonEmcMemVolt,
|
||||
KipConfigValue_eristaEmcMaxClock,
|
||||
KipConfigValue_eristaEmcMaxClock1,
|
||||
KipConfigValue_eristaEmcMaxClock2,
|
||||
KipConfigValue_marikoEmcMaxClock,
|
||||
KipConfigValue_marikoEmcVddqVolt,
|
||||
KipConfigValue_emcDvbShift,
|
||||
|
||||
KipConfigValue_t1_tRCD,
|
||||
KipConfigValue_t2_tRP,
|
||||
KipConfigValue_t3_tRAS,
|
||||
KipConfigValue_t4_tRRD,
|
||||
KipConfigValue_t5_tRFC,
|
||||
KipConfigValue_t6_tRTW,
|
||||
KipConfigValue_t7_tWTR,
|
||||
KipConfigValue_t8_tREFI,
|
||||
KipConfigValue_mem_burst_read_latency,
|
||||
KipConfigValue_mem_burst_write_latency,
|
||||
|
||||
KipConfigValue_eristaCpuUV,
|
||||
KipConfigValue_eristaCpuVmin,
|
||||
KipConfigValue_eristaCpuMaxVolt,
|
||||
KipConfigValue_eristaCpuUnlock,
|
||||
|
||||
KipConfigValue_marikoCpuUVLow,
|
||||
KipConfigValue_marikoCpuUVHigh,
|
||||
KipConfigValue_tableConf,
|
||||
KipConfigValue_marikoCpuLowVmin,
|
||||
KipConfigValue_marikoCpuHighVmin,
|
||||
KipConfigValue_marikoCpuMaxVolt,
|
||||
KipConfigValue_marikoCpuMaxClock,
|
||||
KipConfigValue_eristaCpuBoostClock,
|
||||
KipConfigValue_marikoCpuBoostClock,
|
||||
|
||||
KipConfigValue_eristaGpuUV,
|
||||
KipConfigValue_eristaGpuVmin,
|
||||
|
||||
KipConfigValue_marikoGpuUV,
|
||||
KipConfigValue_marikoGpuVmin,
|
||||
KipConfigValue_marikoGpuVmax,
|
||||
|
||||
KipConfigValue_commonGpuVoltOffset,
|
||||
KipConfigValue_gpuSpeedo,
|
||||
|
||||
KipConfigValue_g_volt_76800,
|
||||
KipConfigValue_g_volt_153600,
|
||||
KipConfigValue_g_volt_230400,
|
||||
KipConfigValue_g_volt_307200,
|
||||
KipConfigValue_g_volt_384000,
|
||||
KipConfigValue_g_volt_460800,
|
||||
KipConfigValue_g_volt_537600,
|
||||
KipConfigValue_g_volt_614400,
|
||||
KipConfigValue_g_volt_691200,
|
||||
KipConfigValue_g_volt_768000,
|
||||
KipConfigValue_g_volt_844800,
|
||||
KipConfigValue_g_volt_921600,
|
||||
KipConfigValue_g_volt_998400,
|
||||
KipConfigValue_g_volt_1075200,
|
||||
KipConfigValue_g_volt_1152000,
|
||||
KipConfigValue_g_volt_1228800,
|
||||
KipConfigValue_g_volt_1267200,
|
||||
KipConfigValue_g_volt_1305600,
|
||||
KipConfigValue_g_volt_1344000,
|
||||
KipConfigValue_g_volt_1382400,
|
||||
KipConfigValue_g_volt_1420800,
|
||||
KipConfigValue_g_volt_1459200,
|
||||
KipConfigValue_g_volt_1497600,
|
||||
KipConfigValue_g_volt_1536000,
|
||||
|
||||
KipConfigValue_g_volt_e_76800,
|
||||
KipConfigValue_g_volt_e_115200,
|
||||
KipConfigValue_g_volt_e_153600,
|
||||
KipConfigValue_g_volt_e_192000,
|
||||
KipConfigValue_g_volt_e_230400,
|
||||
KipConfigValue_g_volt_e_268800,
|
||||
KipConfigValue_g_volt_e_307200,
|
||||
KipConfigValue_g_volt_e_345600,
|
||||
KipConfigValue_g_volt_e_384000,
|
||||
KipConfigValue_g_volt_e_422400,
|
||||
KipConfigValue_g_volt_e_460800,
|
||||
KipConfigValue_g_volt_e_499200,
|
||||
KipConfigValue_g_volt_e_537600,
|
||||
KipConfigValue_g_volt_e_576000,
|
||||
KipConfigValue_g_volt_e_614400,
|
||||
KipConfigValue_g_volt_e_652800,
|
||||
KipConfigValue_g_volt_e_691200,
|
||||
KipConfigValue_g_volt_e_729600,
|
||||
KipConfigValue_g_volt_e_768000,
|
||||
KipConfigValue_g_volt_e_806400,
|
||||
KipConfigValue_g_volt_e_844800,
|
||||
KipConfigValue_g_volt_e_883200,
|
||||
KipConfigValue_g_volt_e_921600,
|
||||
KipConfigValue_g_volt_e_960000,
|
||||
KipConfigValue_g_volt_e_998400,
|
||||
KipConfigValue_g_volt_e_1036800,
|
||||
KipConfigValue_g_volt_e_1075200,
|
||||
|
||||
KipConfigValue_t6_tRTW_fine_tune,
|
||||
KipConfigValue_t7_tWTR_fine_tune,
|
||||
|
||||
KipCrc32,
|
||||
HocClkConfigValue_IsFirstLoad,
|
||||
SysClkConfigValue_EnumMax,
|
||||
} SysClkConfigValue;
|
||||
|
||||
typedef struct {
|
||||
uint64_t values[SysClkConfigValue_EnumMax];
|
||||
} SysClkConfigValueList;
|
||||
|
||||
static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pretty)
|
||||
{
|
||||
switch(val)
|
||||
{
|
||||
case SysClkConfigValue_PollingIntervalMs:
|
||||
return pretty ? "Polling Interval (ms)" : "poll_interval_ms";
|
||||
case SysClkConfigValue_TempLogIntervalMs:
|
||||
return pretty ? "Temperature logging interval (ms)" : "temp_log_interval_ms";
|
||||
case SysClkConfigValue_FreqLogIntervalMs:
|
||||
return pretty ? "Frequency logging interval (ms)" : "freq_log_interval_ms";
|
||||
case SysClkConfigValue_PowerLogIntervalMs:
|
||||
return pretty ? "Power logging interval (ms)" : "power_log_interval_ms";
|
||||
case SysClkConfigValue_CsvWriteIntervalMs:
|
||||
return pretty ? "CSV write interval (ms)" : "csv_write_interval_ms";
|
||||
|
||||
case HocClkConfigValue_UncappedClocks:
|
||||
return pretty ? "Uncapped Clocks" : "uncapped_clocks";
|
||||
case HocClkConfigValue_OverwriteBoostMode:
|
||||
return pretty ? "Overwrite Boost Mode" : "ow_boost";
|
||||
|
||||
case HocClkConfigValue_EristaMaxCpuClock:
|
||||
return pretty ? "CPU Max Clock" : "cpu_max_e";
|
||||
|
||||
case HocClkConfigValue_MarikoMaxCpuClock:
|
||||
return pretty ? "CPU Max Display Clock" : "cpu_max_m";
|
||||
|
||||
case HocClkConfigValue_ThermalThrottle:
|
||||
return pretty ? "Thermal Throttle" : "thermal_throttle";
|
||||
|
||||
case HocClkConfigValue_ThermalThrottleThreshold:
|
||||
return pretty ? "Thermal Throttle Threshold" : "thermal_throttle_threshold";
|
||||
|
||||
case HocClkConfigValue_HandheldTDP:
|
||||
return pretty ? "Handheld TDP" : "handheld_tdp";
|
||||
|
||||
case HocClkConfigValue_HandheldTDPLimit:
|
||||
return pretty ? "Handheld TDP Limit" : "tdp_limit";
|
||||
|
||||
case HocClkConfigValue_LiteTDPLimit:
|
||||
return pretty ? "Handheld TDP Limit" : "tdp_limit_l";
|
||||
|
||||
case HorizonOCConfigValue_BatteryChargeCurrent:
|
||||
return pretty ? "Battery Charge Current" : "bat_charge_current";
|
||||
|
||||
case HorizonOCConfigValue_OverwriteRefreshRate:
|
||||
return pretty ? "Display Refresh Rate Changing" : "drr_changing";
|
||||
|
||||
case HorizonOCConfigValue_MaxDisplayClockH:
|
||||
return pretty ? "Max Display Clock (Handheld)" : "drr_max_clock";
|
||||
|
||||
case HorizonOCConfigValue_DVFSMode:
|
||||
return pretty ? "DVFS Mode" : "dvfs_mode";
|
||||
|
||||
case HorizonOCConfigValue_DVFSOffset:
|
||||
return pretty ? "DVFS Offset" : "dvfs_offset";
|
||||
|
||||
case HorizonOCConfigValue_GPUScheduling:
|
||||
return pretty ? "GPU Scheduling" : "gpu_scheduling";
|
||||
|
||||
case HorizonOCConfigValue_GPUSchedulingMethod:
|
||||
return pretty ? "GPU Scheduling Method" : "gpu_sched_method";
|
||||
|
||||
case HorizonOCConfigValue_LiveCpuUv:
|
||||
return pretty ? "Live CPU Undervolt" : "live_cpu_uv";
|
||||
|
||||
case HorizonOCConfigValue_EnableExperimentalSettings:
|
||||
return pretty ? "Enable Experimental Settings" : "enable_experimental_settings";
|
||||
|
||||
case HorizonOCConfigValue_RAMVoltUsageDisplayMode:
|
||||
return pretty ? "RAM Voltage / Usage Display Mode" : "ram_volt_usage_display_mode";
|
||||
case HorizonOCConfigValue_CpuGovernorMinimumFreq:
|
||||
return pretty ? "CPU Governor Minimum Frequency" : "cpu_gov_min_freq";
|
||||
// KIP config values
|
||||
case KipConfigValue_custRev:
|
||||
return pretty ? "Custom Revision" : "kip_cust_rev";
|
||||
// case KipConfigValue_mtcConf:
|
||||
// return pretty ? "MTC Config" : "kip_mtc_conf";
|
||||
case KipConfigValue_hpMode:
|
||||
return pretty ? "HP Mode" : "kip_hp_mode";
|
||||
|
||||
// EMC
|
||||
case KipConfigValue_commonEmcMemVolt:
|
||||
return pretty ? "Common EMC/MEM Voltage" : "common_emc_mem_volt";
|
||||
case KipConfigValue_eristaEmcMaxClock:
|
||||
return pretty ? "Erista EMC Max Clock 1" : "erista_emc_max_clock";
|
||||
case KipConfigValue_eristaEmcMaxClock1:
|
||||
return pretty ? "Erista EMC Max Clock 2" : "erista_emc_max_clock1";
|
||||
case KipConfigValue_eristaEmcMaxClock2:
|
||||
return pretty ? "Erista EMC Max Clock 3" : "erista_emc_max_clock2";
|
||||
case KipConfigValue_marikoEmcMaxClock:
|
||||
return pretty ? "Mariko EMC Max Clock" : "mariko_emc_max_clock";
|
||||
case KipConfigValue_marikoEmcVddqVolt:
|
||||
return pretty ? "Mariko EMC VDDQ Voltage" : "mariko_emc_vddq_volt";
|
||||
case KipConfigValue_emcDvbShift:
|
||||
return pretty ? "EMC DVB Shift" : "emc_dvb_shift";
|
||||
|
||||
// Memory timings
|
||||
case KipConfigValue_t1_tRCD:
|
||||
return pretty ? "t1 - tRCD" : "t1_trcd";
|
||||
case KipConfigValue_t2_tRP:
|
||||
return pretty ? "t2 - tRP" : "t2_trp";
|
||||
case KipConfigValue_t3_tRAS:
|
||||
return pretty ? "t3 - tRAS" : "t3_tras";
|
||||
case KipConfigValue_t4_tRRD:
|
||||
return pretty ? "t4 - tRRD" : "t4_trrd";
|
||||
case KipConfigValue_t5_tRFC:
|
||||
return pretty ? "t5 - tRFC" : "t5_trfc";
|
||||
case KipConfigValue_t6_tRTW:
|
||||
return pretty ? "t6 - tRTW" : "t6_trtw";
|
||||
case KipConfigValue_t7_tWTR:
|
||||
return pretty ? "t7 - tWTR" : "t7_twtr";
|
||||
case KipConfigValue_t8_tREFI:
|
||||
return pretty ? "t8 - tREFI" : "t8_trefi";
|
||||
case KipConfigValue_mem_burst_read_latency:
|
||||
return pretty ? "Memory Burst Read Latency" : "mem_burst_read_latency";
|
||||
case KipConfigValue_mem_burst_write_latency:
|
||||
return pretty ? "Memory Burst Write Latency" : "mem_burst_write_latency";
|
||||
|
||||
// CPU – Erista
|
||||
case KipConfigValue_eristaCpuUV:
|
||||
return pretty ? "Erista CPU Undervolt" : "erista_cpu_uv";
|
||||
case KipConfigValue_eristaCpuVmin:
|
||||
return pretty ? "Erista CPU vMin" : "erista_cpu_vmin";
|
||||
case KipConfigValue_eristaCpuMaxVolt:
|
||||
return pretty ? "Erista CPU Max Voltage" : "erista_cpu_max_volt";
|
||||
case KipConfigValue_eristaCpuUnlock:
|
||||
return pretty ? "Erista CPU Unlock" : "erista_cpu_unlock";
|
||||
|
||||
// CPU – Mariko
|
||||
case KipConfigValue_marikoCpuUVLow:
|
||||
return pretty ? "Mariko CPU Undervolt (Low)" : "mariko_cpu_uv_low";
|
||||
case KipConfigValue_marikoCpuUVHigh:
|
||||
return pretty ? "Mariko CPU Undervolt (High)" : "mariko_cpu_uv_high";
|
||||
case KipConfigValue_tableConf:
|
||||
return pretty ? "Table Config" : "kip_table_conf";
|
||||
case KipConfigValue_marikoCpuLowVmin:
|
||||
return pretty ? "Mariko CPU Low Vmin" : "mariko_cpu_low_vmin";
|
||||
case KipConfigValue_marikoCpuHighVmin:
|
||||
return pretty ? "Mariko CPU High Vmin" : "mariko_cpu_high_vmin";
|
||||
case KipConfigValue_marikoCpuMaxVolt:
|
||||
return pretty ? "Mariko CPU Max Voltage" : "mariko_cpu_max_volt";
|
||||
|
||||
case KipConfigValue_eristaCpuBoostClock:
|
||||
return pretty ? "Erista CPU Boost Clock" : "erista_cpu_boost_clock";
|
||||
case KipConfigValue_marikoCpuBoostClock:
|
||||
return pretty ? "Mariko CPU Boost Clock" : "mariko_cpu_boost_clock";
|
||||
|
||||
case KipConfigValue_marikoCpuMaxClock:
|
||||
return pretty ? "Mariko CPU Max Clock" : "mariko_cpu_max_clock";
|
||||
|
||||
// GPU – Erista
|
||||
case KipConfigValue_eristaGpuUV:
|
||||
return pretty ? "Erista GPU Undervolt" : "erista_gpu_uv";
|
||||
case KipConfigValue_eristaGpuVmin:
|
||||
return pretty ? "Erista GPU Vmin" : "erista_gpu_vmin";
|
||||
|
||||
// GPU – Mariko
|
||||
case KipConfigValue_marikoGpuUV:
|
||||
return pretty ? "Mariko GPU Undervolt" : "mariko_gpu_uv";
|
||||
case KipConfigValue_marikoGpuVmin:
|
||||
return pretty ? "Mariko GPU Vmin" : "mariko_gpu_vmin";
|
||||
case KipConfigValue_marikoGpuVmax:
|
||||
return pretty ? "Mariko GPU Vmax" : "mariko_gpu_vmax";
|
||||
|
||||
case KipConfigValue_commonGpuVoltOffset:
|
||||
return pretty ? "Common GPU Voltage Offset" : "common_gpu_volt_offset";
|
||||
case KipConfigValue_gpuSpeedo:
|
||||
return pretty ? "GPU Speedo" : "gpu_speedo";
|
||||
|
||||
// Mariko GPU voltages (24)
|
||||
case KipConfigValue_g_volt_76800: return pretty ? "Mariko GPU Volt 76 MHz" : "g_volt_76800";
|
||||
case KipConfigValue_g_volt_153600: return pretty ? "Mariko GPU Volt 153 MHz" : "g_volt_153600";
|
||||
case KipConfigValue_g_volt_230400: return pretty ? "Mariko GPU Volt 230 MHz" : "g_volt_230400";
|
||||
case KipConfigValue_g_volt_307200: return pretty ? "Mariko GPU Volt 307 MHz" : "g_volt_307200";
|
||||
case KipConfigValue_g_volt_384000: return pretty ? "Mariko GPU Volt 384 MHz" : "g_volt_384000";
|
||||
case KipConfigValue_g_volt_460800: return pretty ? "Mariko GPU Volt 460 MHz" : "g_volt_460800";
|
||||
case KipConfigValue_g_volt_537600: return pretty ? "Mariko GPU Volt 537 MHz" : "g_volt_537600";
|
||||
case KipConfigValue_g_volt_614400: return pretty ? "Mariko GPU Volt 614 MHz" : "g_volt_614400";
|
||||
case KipConfigValue_g_volt_691200: return pretty ? "Mariko GPU Volt 691 MHz" : "g_volt_691200";
|
||||
case KipConfigValue_g_volt_768000: return pretty ? "Mariko GPU Volt 768 MHz" : "g_volt_768000";
|
||||
case KipConfigValue_g_volt_844800: return pretty ? "Mariko GPU Volt 844 MHz" : "g_volt_844800";
|
||||
case KipConfigValue_g_volt_921600: return pretty ? "Mariko GPU Volt 921 MHz" : "g_volt_921600";
|
||||
case KipConfigValue_g_volt_998400: return pretty ? "Mariko GPU Volt 998 MHz" : "g_volt_998400";
|
||||
case KipConfigValue_g_volt_1075200: return pretty ? "Mariko GPU Volt 1075 MHz" : "g_volt_1075200";
|
||||
case KipConfigValue_g_volt_1152000: return pretty ? "Mariko GPU Volt 1152 MHz" : "g_volt_1152000";
|
||||
case KipConfigValue_g_volt_1228800: return pretty ? "Mariko GPU Volt 1228 MHz" : "g_volt_1228800";
|
||||
case KipConfigValue_g_volt_1267200: return pretty ? "Mariko GPU Volt 1267 MHz" : "g_volt_1267200";
|
||||
case KipConfigValue_g_volt_1305600: return pretty ? "Mariko GPU Volt 1305 MHz" : "g_volt_1305600";
|
||||
case KipConfigValue_g_volt_1344000: return pretty ? "Mariko GPU Volt 1344 MHz" : "g_volt_1344000";
|
||||
case KipConfigValue_g_volt_1382400: return pretty ? "Mariko GPU Volt 1382 MHz" : "g_volt_1382400";
|
||||
case KipConfigValue_g_volt_1420800: return pretty ? "Mariko GPU Volt 1420 MHz" : "g_volt_1420800";
|
||||
case KipConfigValue_g_volt_1459200: return pretty ? "Mariko GPU Volt 1459 MHz" : "g_volt_1459200";
|
||||
case KipConfigValue_g_volt_1497600: return pretty ? "Mariko GPU Volt 1497 MHz" : "g_volt_1497600";
|
||||
case KipConfigValue_g_volt_1536000: return pretty ? "Mariko GPU Volt 1536 MHz" : "g_volt_1536000";
|
||||
|
||||
// Erista GPU voltages (27)
|
||||
case KipConfigValue_g_volt_e_76800: return pretty ? "Erista GPU Volt 76 MHz" : "g_volt_e_76800";
|
||||
case KipConfigValue_g_volt_e_115200: return pretty ? "Erista GPU Volt 115 MHz" : "g_volt_e_115200";
|
||||
case KipConfigValue_g_volt_e_153600: return pretty ? "Erista GPU Volt 153 MHz" : "g_volt_e_153600";
|
||||
case KipConfigValue_g_volt_e_192000: return pretty ? "Erista GPU Volt 192 MHz" : "g_volt_e_192000";
|
||||
case KipConfigValue_g_volt_e_230400: return pretty ? "Erista GPU Volt 230 MHz" : "g_volt_e_230400";
|
||||
case KipConfigValue_g_volt_e_268800: return pretty ? "Erista GPU Volt 268 MHz" : "g_volt_e_268800";
|
||||
case KipConfigValue_g_volt_e_307200: return pretty ? "Erista GPU Volt 307 MHz" : "g_volt_e_307200";
|
||||
case KipConfigValue_g_volt_e_345600: return pretty ? "Erista GPU Volt 345 MHz" : "g_volt_e_345600";
|
||||
case KipConfigValue_g_volt_e_384000: return pretty ? "Erista GPU Volt 384 MHz" : "g_volt_e_384000";
|
||||
case KipConfigValue_g_volt_e_422400: return pretty ? "Erista GPU Volt 422 MHz" : "g_volt_e_422400";
|
||||
case KipConfigValue_g_volt_e_460800: return pretty ? "Erista GPU Volt 460 MHz" : "g_volt_e_460800";
|
||||
case KipConfigValue_g_volt_e_499200: return pretty ? "Erista GPU Volt 499 MHz" : "g_volt_e_499200";
|
||||
case KipConfigValue_g_volt_e_537600: return pretty ? "Erista GPU Volt 537 MHz" : "g_volt_e_537600";
|
||||
case KipConfigValue_g_volt_e_576000: return pretty ? "Erista GPU Volt 576 MHz" : "g_volt_e_576000";
|
||||
case KipConfigValue_g_volt_e_614400: return pretty ? "Erista GPU Volt 614 MHz" : "g_volt_e_614400";
|
||||
case KipConfigValue_g_volt_e_652800: return pretty ? "Erista GPU Volt 652 MHz" : "g_volt_e_652800";
|
||||
case KipConfigValue_g_volt_e_691200: return pretty ? "Erista GPU Volt 691 MHz" : "g_volt_e_691200";
|
||||
case KipConfigValue_g_volt_e_729600: return pretty ? "Erista GPU Volt 729 MHz" : "g_volt_e_729600";
|
||||
case KipConfigValue_g_volt_e_768000: return pretty ? "Erista GPU Volt 768 MHz" : "g_volt_e_768000";
|
||||
case KipConfigValue_g_volt_e_806400: return pretty ? "Erista GPU Volt 806 MHz" : "g_volt_e_806400";
|
||||
case KipConfigValue_g_volt_e_844800: return pretty ? "Erista GPU Volt 844 MHz" : "g_volt_e_844800";
|
||||
case KipConfigValue_g_volt_e_883200: return pretty ? "Erista GPU Volt 883 MHz" : "g_volt_e_883200";
|
||||
case KipConfigValue_g_volt_e_921600: return pretty ? "Erista GPU Volt 921 MHz" : "g_volt_e_921600";
|
||||
case KipConfigValue_g_volt_e_960000: return pretty ? "Erista GPU Volt 960 MHz" : "g_volt_e_960000";
|
||||
case KipConfigValue_g_volt_e_998400: return pretty ? "Erista GPU Volt 998 MHz" : "g_volt_e_998400";
|
||||
case KipConfigValue_g_volt_e_1036800: return pretty ? "Erista GPU Volt 1036 MHz" : "g_volt_e_1036800";
|
||||
case KipConfigValue_g_volt_e_1075200: return pretty ? "Erista GPU Volt 1075 MHz" : "g_volt_e_1075200";
|
||||
case KipConfigValue_t6_tRTW_fine_tune: return pretty ? "t6 - tRTW Fine Tune" : "t6_tRTW_fine_fune";
|
||||
case KipConfigValue_t7_tWTR_fine_tune: return pretty ? "t7 - tWTR Fine Tune" : "t7_tWTR_fine_tune";
|
||||
case KipCrc32:
|
||||
return pretty ? "CRC32" : "crc32";
|
||||
case HocClkConfigValue_IsFirstLoad:
|
||||
return pretty ? "Is First Load" : "is_first_load";
|
||||
default:
|
||||
return pretty ? "[cfg] no enum format string" : "err_no_format_string";
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
|
||||
{
|
||||
switch(val)
|
||||
{
|
||||
case SysClkConfigValue_PollingIntervalMs:
|
||||
return 300ULL;
|
||||
case SysClkConfigValue_TempLogIntervalMs:
|
||||
case SysClkConfigValue_FreqLogIntervalMs:
|
||||
case SysClkConfigValue_PowerLogIntervalMs:
|
||||
case SysClkConfigValue_CsvWriteIntervalMs:
|
||||
case HocClkConfigValue_UncappedClocks:
|
||||
case HocClkConfigValue_OverwriteBoostMode:
|
||||
case HorizonOCConfigValue_BatteryChargeCurrent:
|
||||
case HorizonOCConfigValue_OverwriteRefreshRate:
|
||||
case HorizonOCConfigValue_GPUScheduling:
|
||||
case HorizonOCConfigValue_LiveCpuUv:
|
||||
case HorizonOCConfigValue_GPUSchedulingMethod:
|
||||
return 0ULL;
|
||||
case HocClkConfigValue_EristaMaxCpuClock:
|
||||
return 1785ULL;
|
||||
|
||||
case HocClkConfigValue_MarikoMaxCpuClock:
|
||||
return 1963ULL;
|
||||
|
||||
case HocClkConfigValue_ThermalThrottle:
|
||||
case HocClkConfigValue_HandheldTDP:
|
||||
case HocClkConfigValue_IsFirstLoad:
|
||||
case HorizonOCConfigValue_DVFSMode:
|
||||
return 1ULL;
|
||||
case HocClkConfigValue_ThermalThrottleThreshold:
|
||||
return 70ULL;
|
||||
case HocClkConfigValue_HandheldTDPLimit:
|
||||
return 9600ULL; // 8600mW will trigger on erista stock, so raise it a bit
|
||||
case HocClkConfigValue_LiteTDPLimit:
|
||||
return 6400ULL; // 0.5C
|
||||
case HorizonOCConfigValue_CpuGovernorMinimumFreq:
|
||||
return 612000000ULL; // 612MHz
|
||||
case HorizonOCConfigValue_MaxDisplayClockH:
|
||||
return 60ULL;
|
||||
default:
|
||||
return 0ULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t input)
|
||||
{
|
||||
switch(val)
|
||||
{
|
||||
case HocClkConfigValue_EristaMaxCpuClock:
|
||||
case HocClkConfigValue_MarikoMaxCpuClock:
|
||||
case HocClkConfigValue_ThermalThrottleThreshold:
|
||||
case HocClkConfigValue_HandheldTDPLimit:
|
||||
case HocClkConfigValue_LiteTDPLimit:
|
||||
case SysClkConfigValue_PollingIntervalMs:
|
||||
case HorizonOCConfigValue_MaxDisplayClockH:
|
||||
return input > 0;
|
||||
|
||||
case SysClkConfigValue_TempLogIntervalMs:
|
||||
case SysClkConfigValue_FreqLogIntervalMs:
|
||||
case SysClkConfigValue_PowerLogIntervalMs:
|
||||
case SysClkConfigValue_CsvWriteIntervalMs:
|
||||
case HocClkConfigValue_UncappedClocks:
|
||||
case HocClkConfigValue_OverwriteBoostMode:
|
||||
case HocClkConfigValue_ThermalThrottle:
|
||||
case HocClkConfigValue_HandheldTDP:
|
||||
case HorizonOCConfigValue_OverwriteRefreshRate:
|
||||
case HocClkConfigValue_IsFirstLoad:
|
||||
case HorizonOCConfigValue_EnableExperimentalSettings:
|
||||
case HorizonOCConfigValue_LiveCpuUv:
|
||||
case HorizonOCConfigValue_GPUSchedulingMethod:
|
||||
return (input & 0x1) == input;
|
||||
|
||||
case KipConfigValue_custRev:
|
||||
// case KipConfigValue_mtcConf:
|
||||
case KipConfigValue_hpMode:
|
||||
case KipConfigValue_commonEmcMemVolt:
|
||||
case KipConfigValue_eristaEmcMaxClock:
|
||||
case KipConfigValue_eristaEmcMaxClock1:
|
||||
case KipConfigValue_eristaEmcMaxClock2:
|
||||
case KipConfigValue_marikoEmcMaxClock:
|
||||
case KipConfigValue_marikoEmcVddqVolt:
|
||||
case KipConfigValue_emcDvbShift:
|
||||
case KipConfigValue_t1_tRCD:
|
||||
case KipConfigValue_t2_tRP:
|
||||
case KipConfigValue_t3_tRAS:
|
||||
case KipConfigValue_t4_tRRD:
|
||||
case KipConfigValue_t5_tRFC:
|
||||
case KipConfigValue_t6_tRTW:
|
||||
case KipConfigValue_t7_tWTR:
|
||||
case KipConfigValue_t8_tREFI:
|
||||
case KipConfigValue_mem_burst_read_latency:
|
||||
case KipConfigValue_mem_burst_write_latency:
|
||||
case KipConfigValue_eristaCpuUV:
|
||||
case KipConfigValue_eristaCpuMaxVolt:
|
||||
case KipConfigValue_marikoCpuUVLow:
|
||||
case KipConfigValue_marikoCpuUVHigh:
|
||||
case KipConfigValue_tableConf:
|
||||
case KipConfigValue_marikoCpuLowVmin:
|
||||
case KipConfigValue_marikoCpuHighVmin:
|
||||
case KipConfigValue_marikoCpuMaxVolt:
|
||||
case KipConfigValue_eristaCpuBoostClock:
|
||||
case KipConfigValue_marikoCpuBoostClock:
|
||||
case KipConfigValue_marikoCpuMaxClock:
|
||||
case KipConfigValue_eristaGpuUV:
|
||||
case KipConfigValue_eristaGpuVmin:
|
||||
case KipConfigValue_marikoGpuUV:
|
||||
case KipConfigValue_marikoGpuVmin:
|
||||
case KipConfigValue_marikoGpuVmax:
|
||||
case KipConfigValue_commonGpuVoltOffset:
|
||||
case KipConfigValue_gpuSpeedo:
|
||||
case KipConfigValue_g_volt_76800:
|
||||
case KipConfigValue_g_volt_153600:
|
||||
case KipConfigValue_g_volt_230400:
|
||||
case KipConfigValue_g_volt_307200:
|
||||
case KipConfigValue_g_volt_384000:
|
||||
case KipConfigValue_g_volt_460800:
|
||||
case KipConfigValue_g_volt_537600:
|
||||
case KipConfigValue_g_volt_614400:
|
||||
case KipConfigValue_g_volt_691200:
|
||||
case KipConfigValue_g_volt_768000:
|
||||
case KipConfigValue_g_volt_844800:
|
||||
case KipConfigValue_g_volt_921600:
|
||||
case KipConfigValue_g_volt_998400:
|
||||
case KipConfigValue_g_volt_1075200:
|
||||
case KipConfigValue_g_volt_1152000:
|
||||
case KipConfigValue_g_volt_1228800:
|
||||
case KipConfigValue_g_volt_1267200:
|
||||
case KipConfigValue_g_volt_1305600:
|
||||
case KipConfigValue_g_volt_1344000:
|
||||
case KipConfigValue_g_volt_1382400:
|
||||
case KipConfigValue_g_volt_1420800:
|
||||
case KipConfigValue_g_volt_1459200:
|
||||
case KipConfigValue_g_volt_1497600:
|
||||
case KipConfigValue_g_volt_1536000:
|
||||
case KipConfigValue_g_volt_e_76800:
|
||||
case KipConfigValue_g_volt_e_115200:
|
||||
case KipConfigValue_g_volt_e_153600:
|
||||
case KipConfigValue_g_volt_e_192000:
|
||||
case KipConfigValue_g_volt_e_230400:
|
||||
case KipConfigValue_g_volt_e_268800:
|
||||
case KipConfigValue_g_volt_e_307200:
|
||||
case KipConfigValue_g_volt_e_345600:
|
||||
case KipConfigValue_g_volt_e_384000:
|
||||
case KipConfigValue_g_volt_e_422400:
|
||||
case KipConfigValue_g_volt_e_460800:
|
||||
case KipConfigValue_g_volt_e_499200:
|
||||
case KipConfigValue_g_volt_e_537600:
|
||||
case KipConfigValue_g_volt_e_576000:
|
||||
case KipConfigValue_g_volt_e_614400:
|
||||
case KipConfigValue_g_volt_e_652800:
|
||||
case KipConfigValue_g_volt_e_691200:
|
||||
case KipConfigValue_g_volt_e_729600:
|
||||
case KipConfigValue_g_volt_e_768000:
|
||||
case KipConfigValue_g_volt_e_806400:
|
||||
case KipConfigValue_g_volt_e_844800:
|
||||
case KipConfigValue_g_volt_e_883200:
|
||||
case KipConfigValue_g_volt_e_921600:
|
||||
case KipConfigValue_g_volt_e_960000:
|
||||
case KipConfigValue_g_volt_e_998400:
|
||||
case KipConfigValue_g_volt_e_1036800:
|
||||
case KipConfigValue_g_volt_e_1075200:
|
||||
case KipConfigValue_eristaCpuVmin:
|
||||
case KipConfigValue_eristaCpuUnlock:
|
||||
case KipConfigValue_t6_tRTW_fine_tune:
|
||||
case KipConfigValue_t7_tWTR_fine_tune:
|
||||
case KipCrc32:
|
||||
case HorizonOCConfigValue_DVFSMode:
|
||||
case HorizonOCConfigValue_DVFSOffset:
|
||||
case HorizonOCConfigValue_GPUScheduling:
|
||||
case HorizonOCConfigValue_RAMVoltUsageDisplayMode:
|
||||
case HorizonOCConfigValue_CpuGovernorMinimumFreq:
|
||||
return true;
|
||||
case HorizonOCConfigValue_BatteryChargeCurrent:
|
||||
return ((input >= 1024) && (input <= 3072)) || !input;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
39
Source/rewrite-hoc-clk/common/include/sysclk/errors.h
Normal file
39
Source/rewrite-hoc-clk/common/include/sysclk/errors.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#define SYSCLK_ERROR_MODULE 388
|
||||
#define SYSCLK_ERROR(desc) ((SYSCLK_ERROR_MODULE & 0x1FF) | (SysClkError_##desc & 0x1FFF)<<9)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SysClkError_Generic = 0,
|
||||
SysClkError_ConfigNotLoaded = 1,
|
||||
SysClkError_ConfigSaveFailed = 2,
|
||||
// HocClkError_SocThermFail = 3,
|
||||
} SysClkError;
|
||||
72
Source/rewrite-hoc-clk/common/include/sysclk/ipc.h
Normal file
72
Source/rewrite-hoc-clk/common/include/sysclk/ipc.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "board.h"
|
||||
#include "clock_manager.h"
|
||||
|
||||
#define SYSCLK_IPC_API_VERSION 1
|
||||
#define SYSCLK_IPC_SERVICE_NAME "hoc:clk"
|
||||
|
||||
enum SysClkIpcCmd
|
||||
{
|
||||
SysClkIpcCmd_GetApiVersion = 0,
|
||||
SysClkIpcCmd_GetVersionString = 1,
|
||||
SysClkIpcCmd_GetCurrentContext = 2,
|
||||
SysClkIpcCmd_Exit = 3,
|
||||
SysClkIpcCmd_GetProfileCount = 4,
|
||||
SysClkIpcCmd_GetProfiles = 5,
|
||||
SysClkIpcCmd_SetProfiles = 6,
|
||||
SysClkIpcCmd_SetEnabled = 7,
|
||||
SysClkIpcCmd_SetOverride = 8,
|
||||
SysClkIpcCmd_GetConfigValues = 9,
|
||||
SysClkIpcCmd_SetConfigValues = 10,
|
||||
SysClkIpcCmd_GetFreqList = 11,
|
||||
HocClkIpcCmd_SetKipData = 12,
|
||||
HocClkIpcCmd_GetKipData = 13,
|
||||
};
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t tid;
|
||||
SysClkTitleProfileList profiles;
|
||||
} SysClkIpc_SetProfiles_Args;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SysClkModule module;
|
||||
uint32_t hz;
|
||||
} SysClkIpc_SetOverride_Args;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SysClkModule module;
|
||||
uint32_t maxCount;
|
||||
} SysClkIpc_GetFreqList_Args;
|
||||
94
Source/rewrite-hoc-clk/common/include/sysclk/psm_ext.h
Normal file
94
Source/rewrite-hoc-clk/common/include/sysclk/psm_ext.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) KazushiMe
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
typedef enum {
|
||||
PsmPDC_NewPDO = 1, //Received new Power Data Object
|
||||
PsmPDC_NoPD = 2, //No Power Delivery source is detected
|
||||
PsmPDC_AcceptedRDO = 3 //Received and accepted Request Data Object
|
||||
} PsmChargeInfoPDC; //BM92T series
|
||||
|
||||
typedef enum {
|
||||
PsmPowerRole_Sink = 1,
|
||||
PsmPowerRole_Source = 2
|
||||
} PsmPowerRole;
|
||||
|
||||
const char* PsmPowerRoleToStr(PsmPowerRole role);
|
||||
|
||||
typedef enum {
|
||||
PsmInfoChargerType_None = 0,
|
||||
PsmInfoChargerType_PD = 1,
|
||||
PsmInfoChargerType_TypeC_1500mA = 2,
|
||||
PsmInfoChargerType_TypeC_3000mA = 3,
|
||||
PsmInfoChargerType_DCP = 4,
|
||||
PsmInfoChargerType_CDP = 5,
|
||||
PsmInfoChargerType_SDP = 6,
|
||||
PsmInfoChargerType_Apple_500mA = 7,
|
||||
PsmInfoChargerType_Apple_1000mA = 8,
|
||||
PsmInfoChargerType_Apple_2000mA = 9
|
||||
} PsmInfoChargerType;
|
||||
|
||||
const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type);
|
||||
|
||||
typedef enum {
|
||||
PsmFlags_NoHub = BIT(0), //If hub is disconnected
|
||||
PsmFlags_Rail = BIT(8), //At least one Joy-con is charging from rail
|
||||
PsmFlags_SPDSRC = BIT(12), //OTG
|
||||
PsmFlags_ACC = BIT(16) //Accessory
|
||||
} PsmChargeInfoFlags;
|
||||
|
||||
typedef struct {
|
||||
int32_t InputCurrentLimit; //Input (Sink) current limit in mA
|
||||
int32_t VBUSCurrentLimit; //Output (Source/VBUS/OTG) current limit in mA
|
||||
int32_t ChargeCurrentLimit; //Battery charging current limit in mA (512mA when Docked, 768mA when BatteryTemperature < 17.0 C)
|
||||
int32_t ChargeVoltageLimit; //Battery charging voltage limit in mV (3952mV when BatteryTemperature >= 51.0 C)
|
||||
int32_t unk_x10; //Possibly an emum, getting the same value as PowerRole in all tested cases
|
||||
int32_t unk_x14; //Possibly flags
|
||||
PsmChargeInfoPDC PDCState; //Power Delivery Controller State
|
||||
int32_t BatteryTemperature; //Battery temperature in milli C
|
||||
int32_t RawBatteryCharge; //Raw battery charged capacity per cent-mille (i.e. 100% = 100000 pcm)
|
||||
int32_t VoltageAvg; //Voltage avg in mV (more in Notes)
|
||||
int32_t BatteryAge; //Battery age (capacity full / capacity design) per cent-mille (i.e. 100% = 100000 pcm)
|
||||
PsmPowerRole PowerRole;
|
||||
PsmInfoChargerType ChargerType;
|
||||
int32_t ChargerVoltageLimit; //Charger and external device voltage limit in mV
|
||||
int32_t ChargerCurrentLimit; //Charger and external device current limit in mA
|
||||
PsmChargeInfoFlags Flags; //Unknown flags
|
||||
} PsmChargeInfo;
|
||||
|
||||
typedef enum {
|
||||
Psm_EnableBatteryCharging = 2,
|
||||
Psm_DisableBatteryCharging = 3,
|
||||
Psm_EnableFastBatteryCharging = 10,
|
||||
Psm_DisableFastBatteryCharging = 11,
|
||||
Psm_GetBatteryChargeInfoFields = 17,
|
||||
} IPsmServerCmd;
|
||||
|
||||
bool PsmIsChargerConnected(const PsmChargeInfo* info);
|
||||
bool PsmIsCharging(const PsmChargeInfo* info);
|
||||
|
||||
typedef enum {
|
||||
PsmBatteryState_Discharging,
|
||||
PsmBatteryState_ChargingPaused,
|
||||
PsmBatteryState_FastCharging
|
||||
} PsmBatteryState;
|
||||
|
||||
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info);
|
||||
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info);
|
||||
49
Source/rewrite-hoc-clk/common/src/apm_profile_table.c
Normal file
49
Source/rewrite-hoc-clk/common/src/apm_profile_table.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include <sysclk/apm.h>
|
||||
|
||||
SysClkApmConfiguration sysclk_g_apm_configurations[] = {
|
||||
{0x00010000, 1020000000, 384000000, 1600000000},
|
||||
{0x00010001, 1020000000, 768000000, 1600000000},
|
||||
{0x00010002, 1224000000, 691200000, 1600000000},
|
||||
{0x00020000, 1020000000, 230400000, 1600000000},
|
||||
{0x00020001, 1020000000, 307200000, 1600000000},
|
||||
{0x00020002, 1224000000, 230400000, 1600000000},
|
||||
{0x00020003, 1020000000, 307200000, 1331200000},
|
||||
{0x00020004, 1020000000, 384000000, 1331200000},
|
||||
{0x00020005, 1020000000, 307200000, 1065600000},
|
||||
{0x00020006, 1020000000, 384000000, 1065600000},
|
||||
{0x92220007, 1020000000, 460800000, 1600000000},
|
||||
{0x92220008, 1020000000, 460800000, 1331200000},
|
||||
{0x92220009, 1785000000, 76800000, 1600000000},
|
||||
{0x9222000A, 1785000000, 76800000, 1331200000},
|
||||
{0x9222000B, 1020000000, 76800000, 1600000000},
|
||||
{0x9222000C, 1020000000, 76800000, 1331200000},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
|
||||
169
Source/rewrite-hoc-clk/common/src/client/ipc.c
Normal file
169
Source/rewrite-hoc-clk/common/src/client/ipc.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
* wrote this file. As long as you retain this notice you can do whatever you
|
||||
* want with this stuff. If you meet any of us some day, and you think this
|
||||
* stuff is worth it, you can buy us a beer in return. - The sys-clk authors
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#define NX_SERVICE_ASSUME_NON_DOMAIN
|
||||
#include <switch.h>
|
||||
#include <string.h>
|
||||
#include <stdatomic.h>
|
||||
#include <sysclk/client/ipc.h>
|
||||
|
||||
static Service g_sysclkSrv;
|
||||
static atomic_size_t g_refCnt;
|
||||
|
||||
bool sysclkIpcRunning()
|
||||
{
|
||||
Handle handle;
|
||||
bool running = R_FAILED(smRegisterService(&handle, smEncodeName(SYSCLK_IPC_SERVICE_NAME), false, 1));
|
||||
|
||||
if (!running)
|
||||
{
|
||||
smUnregisterService(smEncodeName(SYSCLK_IPC_SERVICE_NAME));
|
||||
}
|
||||
|
||||
return running;
|
||||
}
|
||||
|
||||
Result sysclkIpcInitialize(void)
|
||||
{
|
||||
Result rc = 0;
|
||||
|
||||
g_refCnt++;
|
||||
|
||||
if (serviceIsActive(&g_sysclkSrv))
|
||||
return 0;
|
||||
|
||||
rc = smGetService(&g_sysclkSrv, SYSCLK_IPC_SERVICE_NAME);
|
||||
|
||||
if (R_FAILED(rc)) sysclkIpcExit();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void sysclkIpcExit(void)
|
||||
{
|
||||
if (--g_refCnt == 0)
|
||||
{
|
||||
serviceClose(&g_sysclkSrv);
|
||||
}
|
||||
}
|
||||
|
||||
Result sysclkIpcGetAPIVersion(u32* out_ver)
|
||||
{
|
||||
return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetApiVersion, *out_ver);
|
||||
}
|
||||
|
||||
Result sysclkIpcGetVersionString(char* out, size_t len)
|
||||
{
|
||||
return serviceDispatch(&g_sysclkSrv, SysClkIpcCmd_GetVersionString,
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
|
||||
.buffers = {{out, len}},
|
||||
);
|
||||
}
|
||||
|
||||
Result sysclkIpcGetCurrentContext(SysClkContext* out_context)
|
||||
{
|
||||
return serviceDispatch(&g_sysclkSrv, SysClkIpcCmd_GetCurrentContext,
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
|
||||
.buffers = {{out_context, sizeof(SysClkContext)}},
|
||||
);
|
||||
}
|
||||
|
||||
Result sysclkIpcGetProfileCount(u64 tid, u8* out_count)
|
||||
{
|
||||
return serviceDispatchInOut(&g_sysclkSrv, SysClkIpcCmd_GetProfileCount, tid, *out_count);
|
||||
}
|
||||
|
||||
Result sysclkIpcSetEnabled(bool enabled)
|
||||
{
|
||||
u8 enabledRaw = (u8)enabled;
|
||||
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetEnabled, enabledRaw);
|
||||
}
|
||||
|
||||
Result sysclkIpcSetOverride(SysClkModule module, u32 hz)
|
||||
{
|
||||
SysClkIpc_SetOverride_Args args = {
|
||||
.module = module,
|
||||
.hz = hz
|
||||
};
|
||||
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetOverride, args);
|
||||
}
|
||||
|
||||
Result sysclkIpcGetProfiles(u64 tid, SysClkTitleProfileList* out_profiles)
|
||||
{
|
||||
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_GetProfiles, tid,
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
|
||||
.buffers = {{out_profiles, sizeof(SysClkTitleProfileList)}},
|
||||
);
|
||||
}
|
||||
|
||||
Result sysclkIpcSetProfiles(u64 tid, SysClkTitleProfileList* profiles)
|
||||
{
|
||||
SysClkIpc_SetProfiles_Args args;
|
||||
args.tid = tid;
|
||||
memcpy(&args.profiles, profiles, sizeof(SysClkTitleProfileList));
|
||||
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetProfiles, args);
|
||||
}
|
||||
|
||||
Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues)
|
||||
{
|
||||
return serviceDispatch(&g_sysclkSrv, SysClkIpcCmd_GetConfigValues,
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
|
||||
.buffers = {{out_configValues, sizeof(SysClkConfigValueList)}},
|
||||
);
|
||||
}
|
||||
|
||||
Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues)
|
||||
{
|
||||
return serviceDispatch(&g_sysclkSrv, SysClkIpcCmd_SetConfigValues,
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_In },
|
||||
.buffers = {{configValues, sizeof(SysClkConfigValueList)}},
|
||||
);
|
||||
}
|
||||
|
||||
Result sysclkIpcGetFreqList(SysClkModule module, u32* list, u32 maxCount, u32* outCount)
|
||||
{
|
||||
SysClkIpc_GetFreqList_Args args = {
|
||||
.module = module,
|
||||
.maxCount = maxCount
|
||||
};
|
||||
return serviceDispatchInOut(&g_sysclkSrv, SysClkIpcCmd_GetFreqList, args, *outCount,
|
||||
.buffer_attrs = { SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out },
|
||||
.buffers = {{list, maxCount * sizeof(u32)}},
|
||||
);
|
||||
}
|
||||
|
||||
Result hocClkIpcSetKipData()
|
||||
{
|
||||
u32 temp = 0;
|
||||
return serviceDispatchIn(&g_sysclkSrv, HocClkIpcCmd_SetKipData, temp);
|
||||
}
|
||||
|
||||
Result hocClkIpcGetKipData()
|
||||
{
|
||||
u32 temp = 0;
|
||||
return serviceDispatchIn(&g_sysclkSrv, HocClkIpcCmd_GetKipData, temp);
|
||||
}
|
||||
720
Source/rewrite-hoc-clk/common/src/display_refresh_rate.cpp
Normal file
720
Source/rewrite-hoc-clk/common/src/display_refresh_rate.cpp
Normal file
@@ -0,0 +1,720 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, based on reasearch by MasaGratoR and Cooler3D
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 "display_refresh_rate.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <switch.h>
|
||||
#define DSI_CLOCK_HZ 234000000llu
|
||||
#define NVDISP_GET_MODE2 0x803C021B
|
||||
#define NVDISP_SET_MODE2 0x403C021C
|
||||
#define NVDISP_VALIDATE_MODE2 0xC03C021D
|
||||
#define NVDISP_GET_MODE_DB2 0xEF20021E
|
||||
#define NVDISP_GET_PANEL_DATA 0xC01C0226
|
||||
|
||||
#define MAX_REFRESH_RATE 72
|
||||
|
||||
static DisplayRefreshConfig g_config = {0};
|
||||
static bool g_initialized = false;
|
||||
|
||||
static uint8_t g_dockedHighestRefreshRate = 60;
|
||||
static uint8_t g_dockedLinkRate = 10;
|
||||
static bool g_wasRetroSuperTurnedOff = false;
|
||||
static uint32_t g_lastVActive = 1080;
|
||||
static bool g_canChangeRefreshRateDocked = false;
|
||||
static uint8_t g_lastVActiveSet = 0;
|
||||
|
||||
static const uint8_t g_dockedRefreshRates[] = {40, 45, 50, 55, 60, 70, 72, 75, 80, 90, 95, 100, 110, 120, 130, 140, 144, 150, 160, 165, 170, 180, 190, 200, 210, 220, 230, 240};
|
||||
// Calculate with this tool:
|
||||
|
||||
// https://tomverbeure.github.io/video_timings_calculator?horiz_pixels=1920&vert_pixels=1080&refresh_rate=240&margins=false&interlaced=false&bpc=8&color_fmt=rgb444&video_opt=false&custom_hblank=80&custom_vblank=6
|
||||
|
||||
/*
|
||||
typedef struct {
|
||||
uint16_t hFrontPorch;
|
||||
uint8_t hSyncWidth;
|
||||
uint8_t hBackPorch;
|
||||
uint8_t vFrontPorch;
|
||||
uint8_t vSyncWidth;
|
||||
uint8_t vBackPorch;
|
||||
uint8_t VIC;
|
||||
uint32_t pixelClock_kHz;
|
||||
} DockedTimings;
|
||||
*/
|
||||
static const DockedTimings g_dockedTimings1080p[] = {
|
||||
{8, 32, 40, 7, 8, 6, 0, 88080}, // 40Hz
|
||||
{8, 32, 40, 9, 8, 6, 0, 99270}, // 45Hz
|
||||
{528, 44, 148, 4, 5, 36, 31, 148500}, // 50Hz
|
||||
{8, 32, 40, 15, 8, 6, 0, 121990}, // 55Hz
|
||||
{88, 44, 148, 4, 5, 36, 16, 148500}, // 60Hz
|
||||
{8, 32, 40, 22, 8, 6, 0, 156240}, // 70Hz
|
||||
{8, 32, 40, 23, 8, 6, 0, 160848}, // 72Hz
|
||||
{8, 32, 40, 25, 8, 6, 0, 167850}, // 75Hz
|
||||
{8, 32, 40, 28, 8, 6, 0, 179520}, // 80Hz
|
||||
{8, 32, 40, 33, 8, 6, 0, 202860}, // 90Hz
|
||||
{8, 32, 40, 36, 8, 6, 0, 214700}, // 95Hz
|
||||
{528, 44, 148, 4, 5, 36, 64, 297000}, // 100Hz
|
||||
{8, 32, 40, 44, 8, 6, 0, 250360}, // 110Hz
|
||||
{88, 44, 148, 4, 5, 36, 63, 297000}, // 120Hz
|
||||
{8, 32, 40, 55, 8, 6, 0, 298750}, //130Hz CVT-RBv2
|
||||
{8, 32, 40, 61, 8, 6, 0, 323400}, //140Hz CVT-RBv2
|
||||
{8, 32, 40, 63, 8, 6, 0, 333216}, //144Hz CVT-RBv2
|
||||
{8, 32, 40, 67, 8, 6, 0, 348300}, //150Hz CVT-RBv2
|
||||
{8, 32, 40, 72, 8, 6, 0, 373120}, //160Hz CVT-RBv2
|
||||
{8, 32, 40, 75, 8, 6, 0, 385770}, //165Hz CVT-RBv2
|
||||
{8, 32, 40, 78, 8, 6, 0, 398480}, //170Hz CVT-RBv2
|
||||
{8, 32, 40, 84, 8, 6, 0, 424080}, //180Hz CVT-RBv2
|
||||
{8, 32, 40, 90, 8, 6, 0, 449920}, //190Hz CVT-RBv2
|
||||
{8, 32, 40, 96, 8, 6, 0, 476000}, //200Hz CVT-RBv2
|
||||
{8, 32, 40, 102, 8, 6, 0, 502320}, //210Hz CVT-RBv2
|
||||
{8, 32, 40, 108, 8, 6, 0, 528880}, //220Hz CVT-RBv2
|
||||
{8, 32, 40, 114, 8, 6, 0, 555680}, //230Hz CVT-RBv2
|
||||
{8, 32, 40, 121, 8, 6, 0, 583200}, //240Hz CVT-RBv2
|
||||
// technically you can go to 476hz, but in practice, why would you?
|
||||
};
|
||||
|
||||
static const HandheldTimings g_handheldTimingsRETRO[] = {
|
||||
{72, 136, 72, 1, 660, 9, 78000},
|
||||
{72, 136, 72, 1, 443, 9, 77985},
|
||||
{72, 136, 72, 1, 270, 9, 78000},
|
||||
{72, 136, 72, 1, 128, 9, 77990},
|
||||
{72, 136, 72, 1, 10, 9, 78000}
|
||||
};
|
||||
|
||||
static const MinMaxRefreshRate g_handheldModeRefreshRate = {40, 80};
|
||||
|
||||
static uint8_t _getDockedRefreshRateIterator(uint32_t refreshRate) {
|
||||
for (size_t i = 0; i < sizeof(g_dockedRefreshRates) / sizeof(g_dockedRefreshRates[0]); i++) {
|
||||
if (g_dockedRefreshRates[i] == refreshRate) return i;
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
static void _changeOledElvssSettings(const uint32_t* offsets, const uint32_t* value, uint32_t size, uint32_t start) {
|
||||
if (!g_config.dsiVirtAddr || !value || !size) return;
|
||||
|
||||
volatile uint32_t* dsi = (uint32_t*)g_config.dsiVirtAddr;
|
||||
|
||||
#define DSI_VIDEO_MODE_CONTROL 0x4E
|
||||
#define DSI_WR_DATA 0xA
|
||||
#define DSI_TRIGGER 0x13
|
||||
#define MIPI_DSI_DCS_SHORT_WRITE_PARAM 0x15
|
||||
#define MIPI_DSI_DCS_LONG_WRITE 0x39
|
||||
#define MIPI_DCS_PRIV_SM_SET_REG_OFFSET 0xB0
|
||||
#define MIPI_DCS_PRIV_SM_SET_ELVSS 0xB1
|
||||
|
||||
dsi[DSI_VIDEO_MODE_CONTROL] = true;
|
||||
svcSleepThread(20000000);
|
||||
|
||||
dsi[DSI_WR_DATA] = MIPI_DSI_DCS_LONG_WRITE | (5 << 8);
|
||||
dsi[DSI_WR_DATA] = 0x5A5A5AE2;
|
||||
dsi[DSI_WR_DATA] = 0x5A;
|
||||
dsi[DSI_TRIGGER] = 0;
|
||||
|
||||
for (size_t i = start; i < size; i++) {
|
||||
dsi[DSI_WR_DATA] = ((MIPI_DCS_PRIV_SM_SET_REG_OFFSET | ((offsets[i] % 0x100) << 8)) << 8) | MIPI_DSI_DCS_SHORT_WRITE_PARAM;
|
||||
dsi[DSI_TRIGGER] = 0;
|
||||
dsi[DSI_WR_DATA] = ((MIPI_DCS_PRIV_SM_SET_ELVSS | (value[i] << 8)) << 8) | MIPI_DSI_DCS_SHORT_WRITE_PARAM;
|
||||
dsi[DSI_TRIGGER] = 0;
|
||||
}
|
||||
|
||||
dsi[DSI_WR_DATA] = MIPI_DSI_DCS_LONG_WRITE | (5 << 8);
|
||||
dsi[DSI_WR_DATA] = 0xA55A5AE2;
|
||||
dsi[DSI_WR_DATA] = 0xA5;
|
||||
dsi[DSI_TRIGGER] = 0;
|
||||
|
||||
dsi[DSI_VIDEO_MODE_CONTROL] = false;
|
||||
svcSleepThread(20000000);
|
||||
}
|
||||
void DisplayRefresh_SetDockedState(bool isDocked) {
|
||||
g_config.isDocked = isDocked;
|
||||
}
|
||||
|
||||
bool DisplayRefresh_Initialize(const DisplayRefreshConfig* config) {
|
||||
if (!config) return false;
|
||||
|
||||
g_config = *config;
|
||||
g_initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DisplayRefresh_CorrectOledGamma(uint32_t refresh_rate) {
|
||||
static uint32_t last_refresh_rate = 60;
|
||||
static int counter = 0;
|
||||
|
||||
if (g_config.isDocked || refresh_rate < 45 || refresh_rate > 60) {
|
||||
last_refresh_rate = 60;
|
||||
return;
|
||||
}
|
||||
|
||||
if (counter != 9) {
|
||||
counter++;
|
||||
return;
|
||||
}
|
||||
counter = 0;
|
||||
|
||||
uint32_t offsets[] = {0x1A, 0x24, 0x25};
|
||||
uint32_t values[] = {2, 0, 0x83};
|
||||
|
||||
if (refresh_rate == 60) {
|
||||
if (last_refresh_rate == 60) return;
|
||||
} else if (refresh_rate == 45) {
|
||||
if (last_refresh_rate == 45) return;
|
||||
uint32_t vals[] = {4, 1, 0};
|
||||
memcpy(values, vals, sizeof(vals));
|
||||
} else if (refresh_rate == 50) {
|
||||
if (last_refresh_rate == 50) return;
|
||||
uint32_t vals[] = {3, 1, 0};
|
||||
memcpy(values, vals, sizeof(vals));
|
||||
} else if (refresh_rate == 55) {
|
||||
if (last_refresh_rate == 55) return;
|
||||
uint32_t vals[] = {3, 1, 0};
|
||||
memcpy(values, vals, sizeof(vals));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
_changeOledElvssSettings(offsets, values, 3, 0);
|
||||
}
|
||||
last_refresh_rate = refresh_rate;
|
||||
}
|
||||
|
||||
void DisplayRefresh_SetAllowedDockedRatesIPC(uint32_t refreshRates, bool is720p) {
|
||||
// Function kept for API compatibility but does nothing
|
||||
(void)refreshRates;
|
||||
(void)is720p;
|
||||
}
|
||||
|
||||
uint8_t DisplayRefresh_GetDockedHighestAllowed(void) {
|
||||
return (g_dockedHighestRefreshRate > 60) ? g_dockedHighestRefreshRate : 60;
|
||||
}
|
||||
|
||||
static void _getDockedHighestRefreshRate(uint32_t fd_in) {
|
||||
uint8_t highestRefreshRate = 60;
|
||||
uint32_t fd = fd_in;
|
||||
|
||||
if(!fd) nvOpen(&fd, "/dev/nvdisp-disp1");
|
||||
NvdcModeDB2 db2 = {0};
|
||||
int rc = nvIoctl(fd, NVDISP_GET_MODE_DB2, &db2);
|
||||
|
||||
if (rc == 0) {
|
||||
for (size_t i = 0; i < db2.num_modes; i++) {
|
||||
if (db2.modes[i].hActive < 1920 || db2.modes[i].vActive < 1080)
|
||||
continue;
|
||||
|
||||
uint32_t v_total = db2.modes[i].vActive + db2.modes[i].vSyncWidth + db2.modes[i].vFrontPorch + db2.modes[i].vBackPorch;
|
||||
uint32_t h_total = db2.modes[i].hActive + db2.modes[i].hSyncWidth + db2.modes[i].hFrontPorch + db2.modes[i].hBackPorch;
|
||||
double refreshRate = round((double)(db2.modes[i].pclkKHz * 1000) / (double)(v_total * h_total));
|
||||
|
||||
if (highestRefreshRate < (uint8_t)refreshRate)
|
||||
highestRefreshRate = (uint8_t)refreshRate;
|
||||
}
|
||||
} else {
|
||||
g_dockedHighestRefreshRate = 60;
|
||||
}
|
||||
|
||||
const size_t numRates = sizeof(g_dockedRefreshRates) / sizeof(g_dockedRefreshRates[0]);
|
||||
if (highestRefreshRate > g_dockedRefreshRates[numRates - 1])
|
||||
highestRefreshRate = g_dockedRefreshRates[numRates - 1];
|
||||
|
||||
NvdcMode2 display_b = {0};
|
||||
rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
|
||||
|
||||
struct dpaux_read_0x100 {
|
||||
uint32_t cmd;
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
struct {
|
||||
unsigned char link_rate;
|
||||
unsigned int lane_count: 5;
|
||||
unsigned int unk1: 2;
|
||||
unsigned int isFramingEnhanced: 1;
|
||||
unsigned char downspread;
|
||||
unsigned char training_pattern;
|
||||
unsigned char lane_pattern[4];
|
||||
unsigned char unk2[8];
|
||||
} set;
|
||||
} dpaux = {6, 0x100, 0x10};
|
||||
|
||||
rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
||||
if (rc == 0) {
|
||||
g_dockedLinkRate = dpaux.set.link_rate;
|
||||
// if (display_b.hActive == 1920 && display_b.vActive == 1080 && highestRefreshRate > 75 && dpaux.set.link_rate < 20 && )
|
||||
// highestRefreshRate = 75;
|
||||
}
|
||||
|
||||
if (!fd_in) nvClose(fd);
|
||||
g_dockedHighestRefreshRate = highestRefreshRate;
|
||||
}
|
||||
|
||||
static bool _setPLLDHandheldRefreshRate(uint32_t new_refreshRate) {
|
||||
if (!g_config.clkVirtAddr) return false;
|
||||
|
||||
uint32_t fd = 0;
|
||||
if (nvOpen(&fd, "/dev/nvdisp-disp0")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct dpaux_read {
|
||||
uint32_t cmd;
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
struct {
|
||||
unsigned int rev_minor : 4;
|
||||
unsigned int rev_major : 4;
|
||||
unsigned char link_rate;
|
||||
unsigned int lane_count: 5;
|
||||
unsigned int unk1: 2;
|
||||
unsigned int isFramingEnhanced: 1;
|
||||
unsigned char unk2[13];
|
||||
} DPCD;
|
||||
} dpaux = {6, 0, 0x10};
|
||||
|
||||
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
||||
nvClose(fd);
|
||||
if (rc != 0x75c) return false;
|
||||
|
||||
PLLD_BASE base = {0};
|
||||
PLLD_MISC misc = {0};
|
||||
memcpy(&base, (void*)(g_config.clkVirtAddr + 0xD0), 4);
|
||||
memcpy(&misc, (void*)(g_config.clkVirtAddr + 0xDC), 4);
|
||||
|
||||
uint32_t value = ((base.PLLD_DIVN / base.PLLD_DIVM) * 10) / 4;
|
||||
if (value == 0 || value == 80) return false;
|
||||
|
||||
if (new_refreshRate > g_handheldModeRefreshRate.max) {
|
||||
new_refreshRate = g_handheldModeRefreshRate.max;
|
||||
} else if (new_refreshRate < g_handheldModeRefreshRate.min) {
|
||||
bool skip = false;
|
||||
for (size_t i = 2; i <= 4; i++) {
|
||||
if (new_refreshRate * i == 60) {
|
||||
skip = true;
|
||||
new_refreshRate = 60;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!skip) {
|
||||
for (size_t i = 2; i <= 4; i++) {
|
||||
if (((new_refreshRate * i) >= g_handheldModeRefreshRate.min) && ((new_refreshRate * i) <= g_handheldModeRefreshRate.max)) {
|
||||
skip = true;
|
||||
new_refreshRate *= i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!skip) new_refreshRate = 60;
|
||||
}
|
||||
|
||||
uint32_t pixelClock = (9375 * ((4096 * ((2 * base.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * base.PLLD_DIVM);
|
||||
uint16_t refreshRateNow = pixelClock / (DSI_CLOCK_HZ / 60);
|
||||
|
||||
if (refreshRateNow == new_refreshRate) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t base_refreshRate = new_refreshRate - (new_refreshRate % 5);
|
||||
base.PLLD_DIVN = (4 * base_refreshRate) / 10;
|
||||
base.PLLD_DIVM = 1;
|
||||
|
||||
uint64_t expected_pixel_clock = (DSI_CLOCK_HZ * new_refreshRate) / 60;
|
||||
misc.PLLD_SDM_DIN = ((8 * base.PLLD_DIVM * expected_pixel_clock) / 9375) - (4096 * ((2 * base.PLLD_DIVN) + 1));
|
||||
|
||||
memcpy((void*)(g_config.clkVirtAddr + 0xD0), &base, 4);
|
||||
memcpy((void*)(g_config.clkVirtAddr + 0xDC), &misc, 4);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _setNvDispDockedRefreshRate(uint32_t new_refreshRate) {
|
||||
if (g_config.isLite || !g_canChangeRefreshRateDocked)
|
||||
return false;
|
||||
|
||||
uint32_t fd = 0;
|
||||
if (nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NvdcMode2 display_b = {0};
|
||||
int rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
|
||||
if (rc != 0) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!display_b.pclkKHz) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!((display_b.vActive == 480 && display_b.hActive == 720) ||
|
||||
(display_b.vActive == 720 && display_b.hActive == 1280) ||
|
||||
(display_b.vActive == 1080 && display_b.hActive == 1920))) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (display_b.vActive != g_lastVActiveSet) {
|
||||
g_lastVActiveSet = display_b.vActive;
|
||||
}
|
||||
|
||||
uint32_t h_total = display_b.hActive + display_b.hFrontPorch + display_b.hSyncWidth + display_b.hBackPorch;
|
||||
uint32_t v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch;
|
||||
uint32_t refreshRateNow = ((display_b.pclkKHz) * 1000 + 999) / (h_total * v_total);
|
||||
|
||||
int8_t itr = -1;
|
||||
const size_t numRates = sizeof(g_dockedRefreshRates) / sizeof(g_dockedRefreshRates[0]);
|
||||
|
||||
// Find closest matching refresh rate
|
||||
if ((new_refreshRate <= 60) && ((60 % new_refreshRate) == 0)) {
|
||||
itr = _getDockedRefreshRateIterator(60);
|
||||
}
|
||||
|
||||
if (itr == -1) {
|
||||
for (size_t i = 0; i < numRates; i++) {
|
||||
uint8_t val = g_dockedRefreshRates[i];
|
||||
if ((val % new_refreshRate) == 0) {
|
||||
itr = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itr == -1) {
|
||||
if (!g_config.matchLowestDocked) {
|
||||
itr = _getDockedRefreshRateIterator(60);
|
||||
} else {
|
||||
for (size_t i = 0; i < numRates; i++) {
|
||||
if (new_refreshRate < g_dockedRefreshRates[i]) {
|
||||
itr = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itr == -1) itr = _getDockedRefreshRateIterator(60);
|
||||
|
||||
// Clamp to highest allowed refresh rate
|
||||
if (g_dockedRefreshRates[itr] > g_dockedHighestRefreshRate) {
|
||||
for (int8_t i = itr; i >= 0; i--) {
|
||||
if (g_dockedRefreshRates[i] <= g_dockedHighestRefreshRate) {
|
||||
itr = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (refreshRateNow == g_dockedRefreshRates[itr]) {
|
||||
nvClose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (itr >= 0 && itr < (int8_t)numRates) {
|
||||
if (display_b.vActive == 720) {
|
||||
uint32_t clock = ((h_total * v_total) * g_dockedRefreshRates[itr]) / 1000;
|
||||
display_b.pclkKHz = clock;
|
||||
} else {
|
||||
display_b.hFrontPorch = g_dockedTimings1080p[itr].hFrontPorch;
|
||||
display_b.hSyncWidth = g_dockedTimings1080p[itr].hSyncWidth;
|
||||
display_b.hBackPorch = g_dockedTimings1080p[itr].hBackPorch;
|
||||
display_b.vFrontPorch = g_dockedTimings1080p[itr].vFrontPorch;
|
||||
display_b.vSyncWidth = g_dockedTimings1080p[itr].vSyncWidth;
|
||||
display_b.vBackPorch = g_dockedTimings1080p[itr].vBackPorch;
|
||||
display_b.pclkKHz = g_dockedTimings1080p[itr].pixelClock_kHz;
|
||||
display_b.vmode = (g_dockedRefreshRates[itr] >= 100 ? 0x400000 : 0x200000);
|
||||
display_b.unk1 = (g_dockedRefreshRates[itr] >= 100 ? 0x80 : 0);
|
||||
display_b.sync = 3;
|
||||
display_b.bitsPerPixel = 24;
|
||||
}
|
||||
|
||||
rc = nvIoctl(fd, NVDISP_VALIDATE_MODE2, &display_b);
|
||||
if (rc == 0) {
|
||||
rc = nvIoctl(fd, NVDISP_SET_MODE2, &display_b);
|
||||
}
|
||||
}
|
||||
|
||||
nvClose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _setNvDispHandheldRefreshRate(uint32_t new_refreshRate) {
|
||||
if (!g_config.isRetroSUPER) return false;
|
||||
|
||||
if (!g_config.displaySync) {
|
||||
g_wasRetroSuperTurnedOff = false;
|
||||
} else if (g_wasRetroSuperTurnedOff) {
|
||||
svcSleepThread(2000000000);
|
||||
g_wasRetroSuperTurnedOff = false;
|
||||
}
|
||||
|
||||
svcSleepThread(1000000000);
|
||||
|
||||
uint32_t fd = 0;
|
||||
if (nvOpen(&fd, "/dev/nvdisp-disp0")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NvdcMode2 display_b = {0};
|
||||
int rc = nvIoctl(fd, NVDISP_GET_MODE2, &display_b);
|
||||
if (rc != 0) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!display_b.pclkKHz) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((display_b.vActive == 1280 && display_b.hActive == 720) == false) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t h_total = display_b.hActive + display_b.hFrontPorch + display_b.hSyncWidth + display_b.hBackPorch;
|
||||
uint32_t v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch;
|
||||
uint32_t refreshRateNow = ((display_b.pclkKHz) * 1000 + 999) / (h_total * v_total);
|
||||
|
||||
if (new_refreshRate > g_handheldModeRefreshRate.max) {
|
||||
new_refreshRate = g_handheldModeRefreshRate.max;
|
||||
} else if (new_refreshRate < g_handheldModeRefreshRate.min) {
|
||||
bool skip = false;
|
||||
for (size_t i = 2; i <= 4; i++) {
|
||||
if (new_refreshRate * i == 60) {
|
||||
skip = true;
|
||||
new_refreshRate = 60;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!skip) {
|
||||
for (size_t i = 2; i <= (sizeof(g_handheldTimingsRETRO) / sizeof(g_handheldTimingsRETRO[0])); i++) {
|
||||
if (((new_refreshRate * i) >= g_handheldModeRefreshRate.min) && ((new_refreshRate * i) <= g_handheldModeRefreshRate.max)) {
|
||||
skip = true;
|
||||
new_refreshRate *= i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!skip) new_refreshRate = 60;
|
||||
}
|
||||
|
||||
if (new_refreshRate == refreshRateNow) {
|
||||
nvClose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t itr = (new_refreshRate - 40) / 5;
|
||||
display_b.hFrontPorch = g_handheldTimingsRETRO[itr].hFrontPorch;
|
||||
display_b.hSyncWidth = g_handheldTimingsRETRO[itr].hSyncWidth;
|
||||
display_b.hBackPorch = g_handheldTimingsRETRO[itr].hBackPorch;
|
||||
display_b.vFrontPorch = g_handheldTimingsRETRO[itr].vFrontPorch;
|
||||
display_b.vSyncWidth = g_handheldTimingsRETRO[itr].vSyncWidth;
|
||||
display_b.vBackPorch = g_handheldTimingsRETRO[itr].vBackPorch;
|
||||
display_b.pclkKHz = g_handheldTimingsRETRO[itr].pixelClock_kHz;
|
||||
|
||||
rc = nvIoctl(fd, NVDISP_VALIDATE_MODE2, &display_b);
|
||||
if (rc == 0) {
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
nvIoctl(fd, NVDISP_SET_MODE2, &display_b);
|
||||
}
|
||||
}
|
||||
|
||||
nvClose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DisplayRefresh_SetRate(uint32_t new_refreshRate) {
|
||||
if (!new_refreshRate || !g_initialized) return false;
|
||||
|
||||
uint32_t fd = 0;
|
||||
|
||||
if (g_config.isLite && g_config.isPossiblySpoofedRetro) {
|
||||
g_config.isRetroSUPER = false; // Would check flag file here in original, but i dont care lol
|
||||
}
|
||||
|
||||
if (g_config.isRetroSUPER && !g_config.isDocked) {
|
||||
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
||||
}
|
||||
|
||||
else if ((!g_config.isRetroSUPER && g_config.isLite) || R_FAILED(nvOpen(&fd, "/dev/nvdisp-disp1"))) {
|
||||
if (_setPLLDHandheldRefreshRate(new_refreshRate) == false)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
struct dpaux_read {
|
||||
uint32_t cmd;
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
struct {
|
||||
unsigned int rev_minor : 4;
|
||||
unsigned int rev_major : 4;
|
||||
unsigned char link_rate;
|
||||
unsigned int lane_count: 5;
|
||||
unsigned int unk1: 2;
|
||||
unsigned int isFramingEnhanced: 1;
|
||||
unsigned char unk2[13];
|
||||
} DPCD;
|
||||
} dpaux = {6, 0, 0x10};
|
||||
|
||||
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
||||
nvClose(fd);
|
||||
|
||||
if (rc != 0) {
|
||||
if (!g_config.isRetroSUPER) {
|
||||
return _setPLLDHandheldRefreshRate(new_refreshRate);
|
||||
} else {
|
||||
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
||||
}
|
||||
} else {
|
||||
if(g_config.isDocked)
|
||||
return _setNvDispDockedRefreshRate(new_refreshRate);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DisplayRefresh_GetRate(uint32_t* out_refreshRate, bool internal) {
|
||||
if (!out_refreshRate || !g_initialized || !g_config.clkVirtAddr) return false;
|
||||
static uint32_t value = 60;
|
||||
|
||||
if (g_config.isRetroSUPER && !g_config.isDocked) {
|
||||
uint32_t fd = 0;
|
||||
PLLD_BASE temp = {0};
|
||||
PLLD_MISC misc = {0};
|
||||
memcpy(&temp, (void*)(g_config.clkVirtAddr + 0xD0), 4);
|
||||
memcpy(&misc, (void*)(g_config.clkVirtAddr + 0xDC), 4);
|
||||
|
||||
value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4;
|
||||
|
||||
if (value != 0 && value != 80) {
|
||||
if (!nvOpen(&fd, "/dev/nvdisp-disp0")) {
|
||||
NvdcMode2 display_b = {0};
|
||||
if (nvIoctl(fd, NVDISP_GET_MODE2, &display_b) == 0) {
|
||||
uint32_t h_total = display_b.hActive + display_b.hFrontPorch + display_b.hSyncWidth + display_b.hBackPorch;
|
||||
uint32_t v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch;
|
||||
uint32_t pixelClock = display_b.pclkKHz * 1000 + 999;
|
||||
value = pixelClock / (h_total * v_total);
|
||||
}
|
||||
nvClose(fd);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
g_wasRetroSuperTurnedOff = true;
|
||||
}
|
||||
}
|
||||
else if ((!g_config.isPossiblySpoofedRetro) || (g_config.isPossiblySpoofedRetro && !g_config.isRetroSUPER)) {
|
||||
PLLD_BASE temp = {0};
|
||||
PLLD_MISC misc = {0};
|
||||
memcpy(&temp, (void*)(g_config.clkVirtAddr + 0xD0), 4);
|
||||
memcpy(&misc, (void*)(g_config.clkVirtAddr + 0xDC), 4);
|
||||
|
||||
value = ((temp.PLLD_DIVN / temp.PLLD_DIVM) * 10) / 4;
|
||||
|
||||
if (value == 0 || value == 80) {
|
||||
// Docked mode
|
||||
if (g_config.isLite) return false;
|
||||
|
||||
g_config.isDocked = true;
|
||||
|
||||
if (!g_canChangeRefreshRateDocked) {
|
||||
uint32_t fd = 0;
|
||||
if (!nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
||||
struct dpaux_read_0x100 {
|
||||
uint32_t cmd;
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
struct {
|
||||
unsigned char link_rate;
|
||||
unsigned int lane_count: 5;
|
||||
unsigned int unk1: 2;
|
||||
unsigned int isFramingEnhanced: 1;
|
||||
unsigned char downspread;
|
||||
unsigned char training_pattern;
|
||||
unsigned char lane_pattern[4];
|
||||
unsigned char unk2[8];
|
||||
} set;
|
||||
} dpaux = {6, 0x100, 0x10};
|
||||
|
||||
int rc = nvIoctl(fd, NVDISP_GET_PANEL_DATA, &dpaux);
|
||||
nvClose(fd);
|
||||
|
||||
if (rc == 0) {
|
||||
_getDockedHighestRefreshRate(0);
|
||||
g_canChangeRefreshRateDocked = true;
|
||||
} else {
|
||||
svcSleepThread(1000000000);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(internal) {
|
||||
*out_refreshRate = value;
|
||||
return true;
|
||||
}
|
||||
uint32_t fd = 0;
|
||||
if (!nvOpen(&fd, "/dev/nvdisp-disp1")) {
|
||||
NvdcMode2 display_b = {0};
|
||||
if (nvIoctl(fd, NVDISP_GET_MODE2, &display_b) == 0) {
|
||||
if (!display_b.pclkKHz) {
|
||||
nvClose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (g_lastVActive != display_b.vActive) {
|
||||
g_lastVActive = display_b.vActive;
|
||||
_getDockedHighestRefreshRate(fd);
|
||||
}
|
||||
|
||||
uint32_t h_total = display_b.hActive + display_b.hFrontPorch + display_b.hSyncWidth + display_b.hBackPorch;
|
||||
uint32_t v_total = display_b.vActive + display_b.vFrontPorch + display_b.vSyncWidth + display_b.vBackPorch;
|
||||
uint32_t pixelClock = display_b.pclkKHz * 1000 + 999;
|
||||
value = pixelClock / (h_total * v_total);
|
||||
} else {
|
||||
value = 60;
|
||||
}
|
||||
nvClose(fd);
|
||||
} else {
|
||||
value = 60;
|
||||
}
|
||||
}
|
||||
else if (!g_config.isRetroSUPER) {
|
||||
// Handheld mode
|
||||
g_config.isDocked = false;
|
||||
g_canChangeRefreshRateDocked = false;
|
||||
|
||||
uint32_t pixelClock = (9375 * ((4096 * ((2 * temp.PLLD_DIVN) + 1)) + misc.PLLD_SDM_DIN)) / (8 * temp.PLLD_DIVM);
|
||||
value = pixelClock / (DSI_CLOCK_HZ / 60);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
*out_refreshRate = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DisplayRefresh_Shutdown(void) {
|
||||
g_initialized = false;
|
||||
memset(&g_config, 0, sizeof(g_config));
|
||||
}
|
||||
202
Source/rewrite-hoc-clk/common/src/i2c.cpp
Normal file
202
Source/rewrite-hoc-clk/common/src/i2c.cpp
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) KazushiMe
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 "i2c.h"
|
||||
|
||||
Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val) {
|
||||
// ams::fatal::srv::StopSoundTask::StopSound()
|
||||
// I2C Bus Communication Reference: https://www.ti.com/lit/an/slva704/slva704.pdf
|
||||
struct {
|
||||
u8 reg;
|
||||
u8 val;
|
||||
} __attribute__((packed)) cmd;
|
||||
|
||||
I2cSession _session;
|
||||
Result res = i2cOpenSession(&_session, dev);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
cmd.reg = reg;
|
||||
cmd.val = val;
|
||||
res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
i2csessionClose(&_session);
|
||||
return res;
|
||||
}
|
||||
|
||||
Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out) {
|
||||
struct { u8 reg; } __attribute__((packed)) cmd;
|
||||
struct { u8 val; } __attribute__((packed)) rec;
|
||||
|
||||
I2cSession _session;
|
||||
Result res = i2cOpenSession(&_session, dev);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
cmd.reg = reg;
|
||||
res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
if (res) {
|
||||
i2csessionClose(&_session);
|
||||
return res;
|
||||
}
|
||||
|
||||
res = i2csessionReceiveAuto(&_session, &rec, sizeof(rec), I2cTransactionOption_All);
|
||||
i2csessionClose(&_session);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
|
||||
*out = rec.val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out) {
|
||||
struct { u8 reg; } __attribute__((packed)) cmd;
|
||||
struct { u16 val; } __attribute__((packed)) rec;
|
||||
|
||||
I2cSession _session;
|
||||
Result res = i2cOpenSession(&_session, dev);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
cmd.reg = reg;
|
||||
res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||
if (res) {
|
||||
i2csessionClose(&_session);
|
||||
return res;
|
||||
}
|
||||
|
||||
res = i2csessionReceiveAuto(&_session, &rec, sizeof(rec), I2cTransactionOption_All);
|
||||
i2csessionClose(&_session);
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
|
||||
*out = rec.val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
float I2c_Max17050_GetBatteryCurrent() {
|
||||
u16 val;
|
||||
Result res = I2cRead_OutU16(I2cDevice_Max17050, MAX17050_CURRENT_REG, &val);
|
||||
if (res)
|
||||
return 0.f;
|
||||
|
||||
const float SenseResistor = 5.; // in uOhm
|
||||
const float CGain = 1.99993;
|
||||
return (s16)val * (1.5625 / (SenseResistor * CGain));
|
||||
}
|
||||
|
||||
u32 I2c_BuckConverter_MultiplierToMvOut(const I2c_BuckConverter_Domain* domain, u8 multiplier) {
|
||||
return (domain->uv_min + domain->uv_step * multiplier) / 1000;
|
||||
}
|
||||
|
||||
u8 I2c_BuckConverter_MvOutToMultiplier(const I2c_BuckConverter_Domain* domain, u32 mvolt) {
|
||||
u32 uvolt = mvolt * 1000;
|
||||
if (uvolt < domain->uv_min)
|
||||
uvolt = domain->uv_min;
|
||||
if (uvolt > domain->uv_max)
|
||||
uvolt = domain->uv_max;
|
||||
|
||||
return (uvolt - domain->uv_min) / domain->uv_step;
|
||||
}
|
||||
|
||||
u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain* domain) {
|
||||
u8 val;
|
||||
// Retry 5 times if received POR value
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (R_FAILED(I2cRead_OutU8(domain->device, domain->reg, &val)))
|
||||
return 0u;
|
||||
|
||||
// Wait 1us
|
||||
svcSleepThread(1E3);
|
||||
|
||||
if (!domain->por_val || val != domain->por_val)
|
||||
break;
|
||||
}
|
||||
return I2c_BuckConverter_MultiplierToMvOut(domain, val & domain->volt_mask);
|
||||
}
|
||||
|
||||
Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain* domain, u32 mvolt) {
|
||||
u8 val;
|
||||
Result res = I2cRead_OutU8(domain->device, domain->reg, &val);
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
u8 multiplier = I2c_BuckConverter_MvOutToMultiplier(domain, mvolt);
|
||||
val &= ~domain->volt_mask;
|
||||
val |= multiplier & domain->volt_mask;
|
||||
|
||||
res = I2cSet_U8(domain->device, domain->reg, val);
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
// 5ms Ramp delay
|
||||
svcSleepThread(5E6);
|
||||
u8 new_val;
|
||||
res = I2cRead_OutU8(domain->device, domain->reg, &new_val);
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
if (new_val != val)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 I2c_Bq24193_Convert_mA_Raw(u32 ma) {
|
||||
// Adjustment is required
|
||||
u8 raw = 0;
|
||||
|
||||
if (ma > MA_RANGE_MAX) // capping
|
||||
ma = MA_RANGE_MAX;
|
||||
|
||||
bool pct20 = ma <= (MA_RANGE_MIN - 64);
|
||||
if (pct20) {
|
||||
ma = ma * 5;
|
||||
raw |= 0x1;
|
||||
}
|
||||
|
||||
ma -= ma % 100; // round to 100
|
||||
ma -= (MA_RANGE_MIN - 64); // ceiling
|
||||
raw |= (ma >> 6) << 2;
|
||||
|
||||
return raw;
|
||||
};
|
||||
|
||||
u32 I2c_Bq24193_Convert_Raw_mA(u8 raw) {
|
||||
// No adjustment is allowed
|
||||
u32 ma = (((raw >> 2)) << 6) + MA_RANGE_MIN;
|
||||
|
||||
bool pct20 = raw & 1;
|
||||
if (pct20)
|
||||
ma = ma * 20 / 100;
|
||||
|
||||
return ma;
|
||||
};
|
||||
|
||||
Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma) {
|
||||
u8 raw;
|
||||
Result res = I2cRead_OutU8(I2cDevice_Bq24193, BQ24193_CHARGE_CURRENT_CONTROL_REG, &raw);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
*ma = I2c_Bq24193_Convert_Raw_mA(raw);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma) {
|
||||
u8 raw = I2c_Bq24193_Convert_mA_Raw(ma);
|
||||
return I2cSet_U8(I2cDevice_Bq24193, BQ24193_CHARGE_CURRENT_CONTROL_REG, raw);
|
||||
}
|
||||
83
Source/rewrite-hoc-clk/common/src/memmem.c
Normal file
83
Source/rewrite-hoc-clk/common/src/memmem.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Roy Merkel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "memmem.h"
|
||||
|
||||
void *memmem_impl(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
|
||||
{
|
||||
const unsigned char *cmpp;
|
||||
const unsigned char *p;
|
||||
const unsigned char *endp;
|
||||
const unsigned char *q;
|
||||
const unsigned char *endq;
|
||||
unsigned char found;
|
||||
|
||||
if(haystack == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if(needle == NULL)
|
||||
{
|
||||
return (void*)haystack;
|
||||
}
|
||||
if(haystacklen == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if(needlelen == 0)
|
||||
{
|
||||
return (void*)haystack;
|
||||
}
|
||||
|
||||
if(needlelen > haystacklen)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
endp = haystack + haystacklen - needlelen;
|
||||
endq = needle + needlelen;
|
||||
for(p = haystack; p <= endp; p++)
|
||||
{
|
||||
found = 1;
|
||||
cmpp = p;
|
||||
for(q = needle; q < endq; q++)
|
||||
{
|
||||
if(*cmpp != *q)
|
||||
{
|
||||
found = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmpp++;
|
||||
}
|
||||
}
|
||||
if(found)
|
||||
{
|
||||
return (void*)p;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
67
Source/rewrite-hoc-clk/common/src/psm_ext.c
Normal file
67
Source/rewrite-hoc-clk/common/src/psm_ext.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) KazushiMe
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 <sysclk/psm_ext.h>
|
||||
|
||||
const char* PsmPowerRoleToStr(PsmPowerRole role) {
|
||||
switch (role) {
|
||||
case PsmPowerRole_Sink: return "Sink";
|
||||
case PsmPowerRole_Source: return "Source";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type) {
|
||||
switch (type) {
|
||||
case PsmInfoChargerType_None: return "None";
|
||||
case PsmInfoChargerType_PD: return "USB-C PD";
|
||||
case PsmInfoChargerType_TypeC_1500mA:
|
||||
case PsmInfoChargerType_TypeC_3000mA: return "USB-C";
|
||||
case PsmInfoChargerType_DCP: return "USB DCP";
|
||||
case PsmInfoChargerType_CDP: return "USB CDP";
|
||||
case PsmInfoChargerType_SDP: return "USB SDP";
|
||||
case PsmInfoChargerType_Apple_500mA:
|
||||
case PsmInfoChargerType_Apple_1000mA:
|
||||
case PsmInfoChargerType_Apple_2000mA: return "Apple";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
bool PsmIsChargerConnected(const PsmChargeInfo* info) {
|
||||
return info->ChargerType != PsmInfoChargerType_None;
|
||||
}
|
||||
|
||||
bool PsmIsCharging(const PsmChargeInfo* info) {
|
||||
return PsmIsChargerConnected(info) && ((info->unk_x14 >> 8) & 1);
|
||||
}
|
||||
|
||||
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) {
|
||||
if (!PsmIsChargerConnected(info))
|
||||
return PsmBatteryState_Discharging;
|
||||
if (!PsmIsCharging(info))
|
||||
return PsmBatteryState_ChargingPaused;
|
||||
return PsmBatteryState_FastCharging;
|
||||
}
|
||||
|
||||
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info) {
|
||||
switch (PsmGetBatteryState(info)) {
|
||||
case PsmBatteryState_Discharging: return "\u25c0"; // ◀
|
||||
case PsmBatteryState_ChargingPaused:return "| |";
|
||||
case PsmBatteryState_FastCharging: return "\u25b6"; // ▶
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
52
Source/rewrite-hoc-clk/common/src/pwm.c
Normal file
52
Source/rewrite-hoc-clk/common/src/pwm.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) MasaGratoR
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#define NX_SERVICE_ASSUME_NON_DOMAIN
|
||||
#include <switch.h>
|
||||
#include "service_guard.h"
|
||||
#include "pwm.h"
|
||||
|
||||
static Service g_pwmSrv;
|
||||
|
||||
NX_GENERATE_SERVICE_GUARD(pwm);
|
||||
|
||||
Result _pwmInitialize(void) {
|
||||
return smGetService(&g_pwmSrv, "pwm");
|
||||
}
|
||||
|
||||
void _pwmCleanup(void) {
|
||||
serviceClose(&g_pwmSrv);
|
||||
}
|
||||
|
||||
Service* pwmGetServiceSession(void) {
|
||||
return &g_pwmSrv;
|
||||
}
|
||||
|
||||
Result pwmOpenSession2(PwmChannelSession *out, u32 device_code) {
|
||||
return serviceDispatchIn(&g_pwmSrv, 2, device_code,
|
||||
.out_num_objects = 1,
|
||||
.out_objects = &out->s,
|
||||
);
|
||||
}
|
||||
|
||||
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double* out) {
|
||||
return serviceDispatchOut(&c->s, 7, *out);
|
||||
}
|
||||
|
||||
void pwmChannelSessionClose(PwmChannelSession *controller) {
|
||||
serviceClose(&controller->s);
|
||||
}
|
||||
66
Source/rewrite-hoc-clk/common/src/rgltr_services.cpp
Normal file
66
Source/rewrite-hoc-clk/common/src/rgltr_services.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) ppkantorski (bord2death)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 <switch.h>
|
||||
#include "rgltr.h"
|
||||
#include "rgltr_services.h" // for extern Service g_rgltrSrv, etc.
|
||||
|
||||
// Global service handle
|
||||
Service g_rgltrSrv;
|
||||
|
||||
Result rgltrInitialize(void) {
|
||||
if (hosversionBefore(8, 0, 0)) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
|
||||
}
|
||||
return smGetService(&g_rgltrSrv, "rgltr");
|
||||
}
|
||||
|
||||
void rgltrExit(void) {
|
||||
serviceClose(&g_rgltrSrv);
|
||||
}
|
||||
|
||||
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id) {
|
||||
const u32 in = (u32)module_id;
|
||||
return serviceDispatchIn(
|
||||
&g_rgltrSrv,
|
||||
0,
|
||||
in,
|
||||
.out_num_objects = 1,
|
||||
.out_objects = &session_out->s
|
||||
);
|
||||
}
|
||||
|
||||
Result rgltrGetVoltage(RgltrSession* session, u32* out_volt) {
|
||||
u32 temp = 0;
|
||||
Result rc = serviceDispatchOut(&session->s, 4, temp);
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out_volt = temp;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result rgltrRequestVoltage(RgltrSession* session, u32 microvolt) {
|
||||
return serviceDispatchIn(&session->s, 5, microvolt);
|
||||
}
|
||||
|
||||
Result rgltrCancelVoltageRequest(RgltrSession* session) {
|
||||
return serviceDispatch(&session->s, 6);
|
||||
}
|
||||
|
||||
void rgltrCloseSession(RgltrSession* session) {
|
||||
serviceClose(&session->s);
|
||||
}
|
||||
19
Source/rewrite-hoc-clk/config.ini.template
Normal file
19
Source/rewrite-hoc-clk/config.ini.template
Normal file
@@ -0,0 +1,19 @@
|
||||
[values]
|
||||
; Defines how often sys-clk log temperatures, in milliseconds (set 0 to disable)
|
||||
temp_log_interval_ms=0
|
||||
; Defines how often sys-clk writes to the CSV, in milliseconds (set 0 to disable)
|
||||
csv_write_interval_ms=0
|
||||
|
||||
; Example #1: BOTW
|
||||
; Overclock CPU when docked
|
||||
; Overclock MEM to docked clocks when handheld
|
||||
;[01007EF00011E000]
|
||||
;docked_cpu=1224
|
||||
;handheld_mem=1600
|
||||
|
||||
; Example #2: Picross
|
||||
; Underclock to save battery
|
||||
;[0100BA0003EEA000]
|
||||
;handheld_cpu=816
|
||||
;handheld_gpu=153
|
||||
;handheld_mem=800
|
||||
2
Source/rewrite-hoc-clk/sysmodule/.gitignore
vendored
Normal file
2
Source/rewrite-hoc-clk/sysmodule/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/out
|
||||
/build
|
||||
164
Source/rewrite-hoc-clk/sysmodule/Makefile
Normal file
164
Source/rewrite-hoc-clk/sysmodule/Makefile
Normal file
@@ -0,0 +1,164 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITPRO)/libnx/switch_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm".
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := horizon-oc
|
||||
BUILD := build
|
||||
OUTDIR := out
|
||||
RESOURCES := res
|
||||
SOURCES := src src/nx/ipc ../common/src
|
||||
DATA := data
|
||||
INCLUDES := ../common/include
|
||||
EXEFS_SRC := exefs_src
|
||||
LIBNAMES := minIni nxExt
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# version control constants
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET_VERSION := $(shell git describe --dirty --always --tags)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
DEFINES := -DDISABLE_IPC -DTARGET="\"$(TARGET)\"" -DTARGET_VERSION="\"$(TARGET_VERSION)\""
|
||||
|
||||
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
|
||||
|
||||
CFLAGS := -g -Wall -Os -ffunction-sections \
|
||||
$(ARCH) $(DEFINES)
|
||||
|
||||
CFLAGS += $(INCLUDE) -D__SWITCH__
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -std=gnu++17
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := $(foreach lib,$(LIBNAMES),-l$(lib)) -lnx
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS) $(LIBNX) $(foreach lib,$(LIBNAMES),$(TOPDIR)/lib/$(lib))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(OUTDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
|
||||
|
||||
export APP_JSON := $(TOPDIR)/perms.json
|
||||
|
||||
.PHONY: $(BUILD) clean clean-libs clean-build all libs
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
libs:
|
||||
@$(foreach lib,$(LIBNAMES),$(MAKE) --no-print-directory -C $(TOPDIR)/lib/$(lib) && ) true
|
||||
|
||||
$(LIBNAMES):
|
||||
@echo $@
|
||||
|
||||
$(BUILD): libs
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@[ -d $(OUTDIR) ] || mkdir -p $(OUTDIR)
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean-libs:
|
||||
@echo clean libs $(LIBNAMES) ...
|
||||
@$(foreach lib,$(LIBNAMES),$(MAKE) -C $(TOPDIR)/lib/$(lib) clean && ) true
|
||||
|
||||
clean-build:
|
||||
@echo clean build ...
|
||||
@rm -fr $(BUILD) $(TARGET).kip $(TARGET).nsp $(TARGET).npdm $(TARGET).nso $(TARGET).elf $(OUTDIR)
|
||||
|
||||
clean: clean-libs clean-build
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all $(LIBFILES)
|
||||
|
||||
LIBFILES := $(foreach lib,$(LIBNAMES),$(TOPDIR)/lib/$(lib)/lib/lib$(lib).a)
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
all: $(OUTPUT).nsp
|
||||
|
||||
$(OUTPUT).nsp: $(OUTPUT).nso $(OUTPUT).npdm
|
||||
|
||||
$(OUTPUT).elf: $(OFILES) $(LIBFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
13
Source/rewrite-hoc-clk/sysmodule/lib/minIni/.gitignore
vendored
Normal file
13
Source/rewrite-hoc-clk/sysmodule/lib/minIni/.gitignore
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Editor files
|
||||
*.swp
|
||||
*~
|
||||
|
||||
# Objects
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Lib
|
||||
lib
|
||||
release
|
||||
debug
|
||||
12
Source/rewrite-hoc-clk/sysmodule/lib/minIni/.gitrepo
Normal file
12
Source/rewrite-hoc-clk/sysmodule/lib/minIni/.gitrepo
Normal file
@@ -0,0 +1,12 @@
|
||||
; DO NOT EDIT (unless you know what you are doing)
|
||||
;
|
||||
; This subdirectory is a git "subrepo", and this file is maintained by the
|
||||
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
|
||||
;
|
||||
[subrepo]
|
||||
remote = https://github.com/compuphase/minIni
|
||||
branch = master
|
||||
commit = 8ce144c3c287fa4e59f8ed4c405cd8b7e29f189b
|
||||
parent = f32c0b1bca87a6d7e55fb341f8db9ef33b13819f
|
||||
method = merge
|
||||
cmdver = 0.4.0
|
||||
189
Source/rewrite-hoc-clk/sysmodule/lib/minIni/LICENSE
Normal file
189
Source/rewrite-hoc-clk/sysmodule/lib/minIni/LICENSE
Normal file
@@ -0,0 +1,189 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
|
||||
EXCEPTION TO THE APACHE 2.0 LICENSE
|
||||
|
||||
As a special exception to the Apache License 2.0 (and referring to the
|
||||
definitions in Section 1 of this license), you may link, statically or
|
||||
dynamically, the "Work" to other modules to produce an executable file
|
||||
containing portions of the "Work", and distribute that executable file
|
||||
in "Object" form under the terms of your choice, without any of the
|
||||
additional requirements listed in Section 4 of the Apache License 2.0.
|
||||
This exception applies only to redistributions in "Object" form (not
|
||||
"Source" form) and only if no modifications have been made to the "Work".
|
||||
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
133
Source/rewrite-hoc-clk/sysmodule/lib/minIni/Makefile
Normal file
133
Source/rewrite-hoc-clk/sysmodule/lib/minIni/Makefile
Normal file
@@ -0,0 +1,133 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
|
||||
include $(DEVKITPRO)/libnx/switch_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
SOURCES := dev
|
||||
DATA := data
|
||||
INCLUDES := dev
|
||||
SRC_H_FILES :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
|
||||
|
||||
CFLAGS := -g -Wall -Werror \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
$(ARCH) \
|
||||
$(BUILD_CFLAGS)
|
||||
|
||||
CFLAGS += $(INCLUDE)
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS) $(LIBNX)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
CFILES := minIni.c
|
||||
CPPFILES :=
|
||||
SFILES :=
|
||||
BINFILES :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
.PHONY: clean all lib/lib$(TARGET).a
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: lib/lib$(TARGET).a
|
||||
|
||||
lib:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
release:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
debug:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
lib/lib$(TARGET).a : lib release $(SOURCES) $(INCLUDES)
|
||||
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
|
||||
BUILD_CFLAGS="-DNDEBUG=1 -O2" \
|
||||
DEPSDIR=$(CURDIR)/release \
|
||||
--no-print-directory -C release \
|
||||
-f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr release debug lib
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT) : $(OFILES)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%_bin.h %.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
12
Source/rewrite-hoc-clk/sysmodule/lib/minIni/NOTICE
Normal file
12
Source/rewrite-hoc-clk/sysmodule/lib/minIni/NOTICE
Normal file
@@ -0,0 +1,12 @@
|
||||
minIni is a programmer's library to read and write "INI" files in embedded
|
||||
systems. The library takes little resources and can be configured for various
|
||||
kinds of file I/O libraries.
|
||||
|
||||
The method for portable INI file management in minIni is, in part based, on the
|
||||
article "Multiplatform .INI Files" by Joseph J. Graf in the March 1994 issue of
|
||||
Dr. Dobb's Journal.
|
||||
|
||||
The C++ class in minIni.h was contributed by Steven Van Ingelgem.
|
||||
|
||||
The option to compile minIni as a read-only library was contributed by Luca
|
||||
Bassanello.
|
||||
170
Source/rewrite-hoc-clk/sysmodule/lib/minIni/README.md
Normal file
170
Source/rewrite-hoc-clk/sysmodule/lib/minIni/README.md
Normal file
@@ -0,0 +1,170 @@
|
||||
# minIni
|
||||
minIni is a portable and configurable library for reading and writing ".INI" files. At 830 lines of commented source
|
||||
code
|
||||
(version 1.2), minIni truly is a "mini" INI file parser, especially considering its features.
|
||||
|
||||
The library does not require the file I/O functions from the standard C/C++ library, but instead lets you configure
|
||||
the file I/O interface to use via macros. minIni uses limited stack space and does not use dynamic memory (malloc and
|
||||
friends) at all.
|
||||
|
||||
Some minor variations on standard INI files are supported too, notably minIni supports INI files that lack sections.
|
||||
|
||||
|
||||
# Acknowledgement
|
||||
|
||||
minIni is derived from an earlier INI file parser (which I wrote) for desktop systems.
|
||||
|
||||
In turn, that earlier parser was a re-write of the code from the article "Multiplatform .INI Files" by Joseph J. Graf
|
||||
in the March 1994 issue of Dr. Dobb's Journal. In other words, minIni has its roots in the work of Joseph Graf (even
|
||||
though the code has been almost completely re-written).
|
||||
|
||||
|
||||
# Features
|
||||
|
||||
minIni is a programmer's library to read and write "INI" files in embedded systems. minIni takes little resources,
|
||||
can be configured for various kinds of file I/O libraries and provides functionality for reading, writing and
|
||||
deleting keys from an INI file.
|
||||
|
||||
Although the main feature of minIni is that it is small and minimal, it has a few other features:
|
||||
|
||||
* minIni supports reading keys that are outside a section, and it thereby supports configuration files that do not use sections (but that are otherwise compatible with INI files).
|
||||
* You may use a colon to separate key and value; the colon is equivalent to the equal sign. That is, the strings "Name: Value" and "Name=Value" have the same meaning.
|
||||
* The hash character ("#") is an alternative for the semicolon to start a comment. Trailing comments (i.e. behind a key/value pair on a line) are allowed.
|
||||
* Leading and trailing white space around key names and values is ignored.
|
||||
* When writing a value that contains a comment character (";" or "#"), that value will automatically be put between double quotes; when reading the value, these quotes are removed. When a double-quote itself appears in the setting, these characters are escaped.
|
||||
* Section and key enumeration are supported.
|
||||
* You can optionally set the line termination (for text files) that minIni will use. (This is a compile-time setting, not a run-time setting.)
|
||||
* Since writing speed is much lower than reading speed in Flash memory (SD/MMC cards, USB memory sticks), minIni minimizes "file writes" at the expense of double "file reads".
|
||||
* The memory footprint is deterministic. There is no dynamic memory allocation.
|
||||
|
||||
## INI file reading paradigms
|
||||
|
||||
There are two approaches to reading settings from an INI file. One way is to call a function, such as
|
||||
GetProfileString() for every section and key that you need. This is especially convenient if there is a large
|
||||
INI file, but you only need a few settings from that file at any time —especially if the INI file can also
|
||||
change while your program runs. This is the approach that the Microsoft Windows API uses.
|
||||
|
||||
The above procedure is quite inefficient, however, when you need to retrieve quite a few settings in a row from
|
||||
the INI file —especially if the INI file is not cached in memory (which it isn't, in minIni). A different approach
|
||||
to getting settings from an INI file is to call a "parsing" function and let that function call the application
|
||||
back with the section and key names plus the associated data. XML parsing libraries often use this approach; see
|
||||
for example the Expat library.
|
||||
|
||||
minIni supports both approaches. For reading a single setting, use functions like ini_gets(). For the callback
|
||||
approach, implement a callback and call ini_browse(). See the minIni manual for details.
|
||||
|
||||
|
||||
# INI file syntax
|
||||
|
||||
INI files are best known from Microsoft Windows, but they are also used with applications that run on other
|
||||
platforms (although their file extension is sometimes ".cfg" instead of ".ini").
|
||||
|
||||
INI files have a simple syntax with name/value pairs in a plain text file. The name must be unique (per section)
|
||||
and the value must fit on a single line. INI files are commonly separated into sections —in minIni, this is
|
||||
optional. A section is a name between square brackets, like "[Network]" in the example below.
|
||||
|
||||
```
|
||||
[Network]
|
||||
hostname=My Computer
|
||||
address=dhcp
|
||||
dns = 192.168.1.1
|
||||
```
|
||||
|
||||
In the API and in this documentation, the "name" for a setting is denoted as the key for the setting. The key
|
||||
and the value are separated by an equal sign ("="). minIni supports the colon (":") as an alternative to the
|
||||
equal sign for the key/value delimiter.
|
||||
|
||||
Leading a trailing spaces around values or key names are removed. If you need to include leading and/or trailing
|
||||
spaces in a value, put the value between double quotes. The ini_gets() function (from the minIni library, see the
|
||||
minIni manual) strips off the double quotes from the returned value. Function ini_puts() adds double quotes if
|
||||
the value to write contains trailing white space (or special characters).
|
||||
|
||||
minIni ignores spaces around the "=" or ":" delimiters, but it does not ignore spaces between the brackets in a
|
||||
section name. In other words, it is best not to put spaces behind the opening bracket "[" or before the closing
|
||||
bracket "]" of a section name.
|
||||
|
||||
Comments in the INI must start with a semicolon (";") or a hash character ("#"), and run to the end of the line.
|
||||
A comment can be a line of its own, or it may follow a key/value pair (the "#" character and trailing comments
|
||||
are extensions of minIni).
|
||||
|
||||
For more details on the format, please see http://en.wikipedia.org/wiki/INI_file.
|
||||
|
||||
|
||||
# Adapting minIni to a file system
|
||||
|
||||
The minIni library must be configured for a platform with the help of a so- called "glue file". This glue file
|
||||
contains macros (and possibly functions) that map file reading and writing functions used by the minIni library
|
||||
to those provided by the operating system. The glue file must be called "minGlue.h".
|
||||
|
||||
To get you started, the minIni distribution comes with the following example glue files:
|
||||
|
||||
* a glue file that maps to the standard C/C++ library (specifically the file I/O functions from the "stdio" package),
|
||||
* a glue file for Microchip's "Memory Disk Drive File System Library" (see http://www.microchip.com/),
|
||||
* a glue file for the FAT library provided with the CCS PIC compiler (see http://www.ccsinfo.com/)
|
||||
* a glue file for the EFS Library (EFSL, http://www.efsl.be/),
|
||||
* and a glue file for the FatFs and Petit-FatFs libraries (http://elm-chan.org/fsw/ff/00index_e.html).
|
||||
|
||||
The minIni library does not rely on the availability of a standard C library, because embedded operating systems
|
||||
may have limited support for file I/O. Even on full operating systems, separating the file I/O from the INI format
|
||||
parsing carries advantages, because it allows you to cache the INI file and thereby enhance performance.
|
||||
|
||||
The glue file must specify the type that identifies a file, whether it is a handle or a pointer. For the standard
|
||||
C/C++ file I/O library, this would be:
|
||||
|
||||
```C
|
||||
#define INI_FILETYPE FILE*
|
||||
```
|
||||
|
||||
If you are not using the standard C/C++ file I/O library, chances are that you need a different handle or
|
||||
"structure" to identify the storage than the ubiquitous "FILE*" type. For example, the glue file for the FatFs
|
||||
library uses the following declaration:
|
||||
|
||||
```C
|
||||
#define INI_FILETYPE FIL
|
||||
```
|
||||
|
||||
The minIni functions declare variables of this INI_FILETYPE type and pass these variables to sub-functions
|
||||
(including the glue interface functions) by reference.
|
||||
|
||||
For "write support", another type that must be defined is for variables that hold the "current position" in a
|
||||
file. For the standard C/C++ I/O library, this is "fpos_t".
|
||||
|
||||
Another item that needs to be configured is the buffer size. The functions in the minIni library allocate this
|
||||
buffer on the stack, so the buffer size is directly related to the stack usage. In addition, the buffer size
|
||||
determines the maximum line length that is supported in the INI file and the maximum path name length for the
|
||||
temporary file. For example, minGlue.h could contain the definition:
|
||||
|
||||
```C
|
||||
#define INI_BUFFERSIZE 512
|
||||
```
|
||||
|
||||
The above macro limits the line length of the INI files supported by minIni to 512 characters.
|
||||
|
||||
The temporary file is only used when writing to INI files. The minIni routines copy/change the INI file to a
|
||||
temporary file and then rename that temporary file to the original file. This approach uses the least amount of
|
||||
memory. The path name of the temporary file is the same as the input file, but with the last character set to a
|
||||
tilde ("~").
|
||||
|
||||
Below is an example of a glue file (this is the one that maps to the C/C++ "stdio" library).
|
||||
|
||||
```C
|
||||
#include <stdio.h>
|
||||
|
||||
#define INI_FILETYPE FILE*
|
||||
#define ini_openread(filename,file) ((*(file) = fopen((filename),"r")) != NULL)
|
||||
#define ini_openwrite(filename,file) ((*(file) = fopen((filename),"w")) != NULL)
|
||||
#define ini_close(file) (fclose(*(file)) == 0)
|
||||
#define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL)
|
||||
#define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0)
|
||||
#define ini_rename(source,dest) (rename((source), (dest)) == 0)
|
||||
#define ini_remove(filename) (remove(filename) == 0)
|
||||
|
||||
#define INI_FILEPOS fpos_t
|
||||
#define ini_tell(file,pos) (fgetpos(*(file), (pos)) == 0)
|
||||
#define ini_seek(file,pos) (fsetpos(*(file), (pos)) == 0)
|
||||
```
|
||||
|
||||
As you can see, a glue file is mostly a set of macros that wraps one function definition around another.
|
||||
|
||||
The glue file may contain more settings, for support of rational numbers, to explicitly set the line termination
|
||||
character(s), or to disable write support (for example). See the manual that comes with the archive for the details.
|
||||
@@ -0,0 +1,37 @@
|
||||
/* Glue functions for the minIni library, based on the FatFs and Petit-FatFs
|
||||
* libraries, see http://elm-chan.org/fsw/ff/00index_e.html
|
||||
*
|
||||
* By CompuPhase, 2008-2012
|
||||
* This "glue file" is in the public domain. It is distributed without
|
||||
* warranties or conditions of any kind, either express or implied.
|
||||
*
|
||||
* (The FatFs and Petit-FatFs libraries are copyright by ChaN and licensed at
|
||||
* its own terms.)
|
||||
*/
|
||||
|
||||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
|
||||
|
||||
/* You must set _USE_STRFUNC to 1 or 2 in the include file ff.h (or tff.h)
|
||||
* to enable the "string functions" fgets() and fputs().
|
||||
*/
|
||||
#include "ff.h" /* include tff.h for Tiny-FatFs */
|
||||
|
||||
#define INI_FILETYPE FIL
|
||||
#define ini_openread(filename,file) (f_open((file), (filename), FA_READ+FA_OPEN_EXISTING) == FR_OK)
|
||||
#define ini_openwrite(filename,file) (f_open((file), (filename), FA_WRITE+FA_CREATE_ALWAYS) == FR_OK)
|
||||
#define ini_close(file) (f_close(file) == FR_OK)
|
||||
#define ini_read(buffer,size,file) f_gets((buffer), (size),(file))
|
||||
#define ini_write(buffer,file) f_puts((buffer), (file))
|
||||
#define ini_remove(filename) (f_unlink(filename) == FR_OK)
|
||||
|
||||
#define INI_FILEPOS DWORD
|
||||
#define ini_tell(file,pos) (*(pos) = f_tell((file)))
|
||||
#define ini_seek(file,pos) (f_lseek((file), *(pos)) == FR_OK)
|
||||
|
||||
static int ini_rename(TCHAR *source, const TCHAR *dest)
|
||||
{
|
||||
/* Function f_rename() does not allow drive letters in the destination file */
|
||||
char *drive = strchr(dest, ':');
|
||||
drive = (drive == NULL) ? dest : drive + 1;
|
||||
return (f_rename(source, drive) == FR_OK);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/* minIni glue functions for FAT library by CCS, Inc. (as provided with their
|
||||
* PIC MCU compiler)
|
||||
*
|
||||
* By CompuPhase, 2011-2012
|
||||
* This "glue file" is in the public domain. It is distributed without
|
||||
* warranties or conditions of any kind, either express or implied.
|
||||
*
|
||||
* (The FAT library is copyright (c) 2007 Custom Computer Services, and
|
||||
* licensed at its own terms.)
|
||||
*/
|
||||
|
||||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
|
||||
|
||||
#ifndef FAT_PIC_C
|
||||
#error FAT library must be included before this module
|
||||
#endif
|
||||
#define const /* keyword not supported by CCS */
|
||||
|
||||
#define INI_FILETYPE FILE
|
||||
#define ini_openread(filename,file) (fatopen((filename), "r", (file)) == GOODEC)
|
||||
#define ini_openwrite(filename,file) (fatopen((filename), "w", (file)) == GOODEC)
|
||||
#define ini_close(file) (fatclose((file)) == 0)
|
||||
#define ini_read(buffer,size,file) (fatgets((buffer), (size), (file)) != NULL)
|
||||
#define ini_write(buffer,file) (fatputs((buffer), (file)) == GOODEC)
|
||||
#define ini_remove(filename) (rm_file((filename)) == 0)
|
||||
|
||||
#define INI_FILEPOS fatpos_t
|
||||
#define ini_tell(file,pos) (fatgetpos((file), (pos)) == 0)
|
||||
#define ini_seek(file,pos) (fatsetpos((file), (pos)) == 0)
|
||||
|
||||
#ifndef INI_READONLY
|
||||
/* CCS FAT library lacks a rename function, so instead we copy the file to the
|
||||
* new name and delete the old file
|
||||
*/
|
||||
static int ini_rename(char *source, char *dest)
|
||||
{
|
||||
FILE fr, fw;
|
||||
int n;
|
||||
|
||||
if (fatopen(source, "r", &fr) != GOODEC)
|
||||
return 0;
|
||||
if (rm_file(dest) != 0)
|
||||
return 0;
|
||||
if (fatopen(dest, "w", &fw) != GOODEC)
|
||||
return 0;
|
||||
|
||||
/* With some "insider knowledge", we can save some memory: the "source"
|
||||
* parameter holds a filename that was built from the "dest" parameter. It
|
||||
* was built in a local buffer with the size INI_BUFFERSIZE. We can reuse
|
||||
* this buffer for copying the file.
|
||||
*/
|
||||
while (n=fatread(source, 1, INI_BUFFERSIZE, &fr))
|
||||
fatwrite(source, 1, n, &fw);
|
||||
|
||||
fatclose(&fr);
|
||||
fatclose(&fw);
|
||||
|
||||
/* Now we need to delete the source file. However, we have garbled the buffer
|
||||
* that held the filename of the source. So we need to build it again.
|
||||
*/
|
||||
ini_tempname(source, dest, INI_BUFFERSIZE);
|
||||
return rm_file(source) == 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
/* Glue functions for the minIni library, based on the EFS Library, see
|
||||
* http://www.efsl.be/
|
||||
*
|
||||
* By CompuPhase, 2008-2012
|
||||
* This "glue file" is in the public domain. It is distributed without
|
||||
* warranties or conditions of any kind, either express or implied.
|
||||
*
|
||||
* (EFSL is copyright 2005-2006 Lennart Ysboodt and Michael De Nil, and
|
||||
* licensed under the GPL with an exception clause for static linking.)
|
||||
*/
|
||||
|
||||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
|
||||
#define INI_LINETERM "\r\n" /* set line termination explicitly */
|
||||
|
||||
#include "efs.h"
|
||||
extern EmbeddedFileSystem g_efs;
|
||||
|
||||
#define INI_FILETYPE EmbeddedFile
|
||||
#define ini_openread(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'r') == 0)
|
||||
#define ini_openwrite(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'w') == 0)
|
||||
#define ini_close(file) file_fclose(file)
|
||||
#define ini_read(buffer,size,file) (file_read((file), (size), (buffer)) > 0)
|
||||
#define ini_write(buffer,file) (file_write((file), strlen(buffer), (char*)(buffer)) > 0)
|
||||
#define ini_remove(filename) rmfile(&g_efs.myFs, (char*)(filename))
|
||||
|
||||
#define INI_FILEPOS euint32
|
||||
#define ini_tell(file,pos) (*(pos) = (file)->FilePtr))
|
||||
#define ini_seek(file,pos) file_setpos((file), (*pos))
|
||||
|
||||
#if ! defined INI_READONLY
|
||||
/* EFSL lacks a rename function, so instead we copy the file to the new name
|
||||
* and delete the old file
|
||||
*/
|
||||
static int ini_rename(char *source, const char *dest)
|
||||
{
|
||||
EmbeddedFile fr, fw;
|
||||
int n;
|
||||
|
||||
if (file_fopen(&fr, &g_efs.myFs, source, 'r') != 0)
|
||||
return 0;
|
||||
if (rmfile(&g_efs.myFs, (char*)dest) != 0)
|
||||
return 0;
|
||||
if (file_fopen(&fw, &g_efs.myFs, (char*)dest, 'w') != 0)
|
||||
return 0;
|
||||
|
||||
/* With some "insider knowledge", we can save some memory: the "source"
|
||||
* parameter holds a filename that was built from the "dest" parameter. It
|
||||
* was built in buffer and this buffer has the size INI_BUFFERSIZE. We can
|
||||
* reuse this buffer for copying the file.
|
||||
*/
|
||||
while (n=file_read(&fr, INI_BUFFERSIZE, source))
|
||||
file_write(&fw, n, source);
|
||||
|
||||
file_fclose(&fr);
|
||||
file_fclose(&fw);
|
||||
|
||||
/* Now we need to delete the source file. However, we have garbled the buffer
|
||||
* that held the filename of the source. So we need to build it again.
|
||||
*/
|
||||
ini_tempname(source, dest, INI_BUFFERSIZE);
|
||||
return rmfile(&g_efs.myFs, source) == 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
/* Glue functions for the minIni library, based on the "FAT Filing System"
|
||||
* library by embedded-code.com
|
||||
*
|
||||
* By CompuPhase, 2008-2012
|
||||
* This "glue file" is in the public domain. It is distributed without
|
||||
* warranties or conditions of any kind, either express or implied.
|
||||
*
|
||||
* (The "FAT Filing System" library itself is copyright embedded-code.com, and
|
||||
* licensed at its own terms.)
|
||||
*/
|
||||
|
||||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
|
||||
#include <mem-ffs.h>
|
||||
|
||||
#define INI_FILETYPE FFS_FILE*
|
||||
#define ini_openread(filename,file) ((*(file) = ffs_fopen((filename),"r")) != NULL)
|
||||
#define ini_openwrite(filename,file) ((*(file) = ffs_fopen((filename),"w")) != NULL)
|
||||
#define ini_close(file) (ffs_fclose(*(file)) == 0)
|
||||
#define ini_read(buffer,size,file) (ffs_fgets((buffer),(size),*(file)) != NULL)
|
||||
#define ini_write(buffer,file) (ffs_fputs((buffer),*(file)) >= 0)
|
||||
#define ini_rename(source,dest) (ffs_rename((source), (dest)) == 0)
|
||||
#define ini_remove(filename) (ffs_remove(filename) == 0)
|
||||
|
||||
#define INI_FILEPOS long
|
||||
#define ini_tell(file,pos) (ffs_fgetpos(*(file), (pos)) == 0)
|
||||
#define ini_seek(file,pos) (ffs_fsetpos(*(file), (pos)) == 0)
|
||||
@@ -0,0 +1,58 @@
|
||||
/* minIni glue functions for Microchip's "Memory Disk Drive" file system
|
||||
* library, as presented in Microchip application note AN1045.
|
||||
*
|
||||
* By CompuPhase, 2011-2014
|
||||
* This "glue file" is in the public domain. It is distributed without
|
||||
* warranties or conditions of any kind, either express or implied.
|
||||
*
|
||||
* (The "Microchip Memory Disk Drive File System" is copyright (c) Microchip
|
||||
* Technology Incorporated, and licensed at its own terms.)
|
||||
*/
|
||||
|
||||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
|
||||
|
||||
#include "MDD File System\fsio.h"
|
||||
#include <string.h>
|
||||
|
||||
#define INI_FILETYPE FSFILE*
|
||||
#define ini_openread(filename,file) ((*(file) = FSfopen((filename),FS_READ)) != NULL)
|
||||
#define ini_openwrite(filename,file) ((*(file) = FSfopen((filename),FS_WRITE)) != NULL)
|
||||
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),FS_READPLUS)) != NULL)
|
||||
#define ini_close(file) (FSfclose(*(file)) == 0)
|
||||
#define ini_write(buffer,file) (FSfwrite((buffer), 1, strlen(buffer), (*file)) > 0)
|
||||
#define ini_remove(filename) (FSremove((filename)) == 0)
|
||||
|
||||
#define INI_FILEPOS long int
|
||||
#define ini_tell(file,pos) (*(pos) = FSftell(*(file)))
|
||||
#define ini_seek(file,pos) (FSfseek(*(file), *(pos), SEEK_SET) == 0)
|
||||
|
||||
/* Since the Memory Disk Drive file system library reads only blocks of files,
|
||||
* the function to read a text line does so by "over-reading" a block of the
|
||||
* of the maximum size and truncating it behind the end-of-line.
|
||||
*/
|
||||
static int ini_read(char *buffer, int size, INI_FILETYPE *file)
|
||||
{
|
||||
size_t numread = size;
|
||||
char *eol;
|
||||
|
||||
if ((numread = FSfread(buffer, 1, size, *file)) == 0)
|
||||
return 0; /* at EOF */
|
||||
if ((eol = strchr(buffer, '\n')) == NULL)
|
||||
eol = strchr(buffer, '\r');
|
||||
if (eol != NULL) {
|
||||
/* terminate the buffer */
|
||||
*++eol = '\0';
|
||||
/* "unread" the data that was read too much */
|
||||
FSfseek(*file, - (int)(numread - (size_t)(eol - buffer)), SEEK_CUR);
|
||||
} /* if */
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef INI_READONLY
|
||||
static int ini_rename(const char *source, const char *dest)
|
||||
{
|
||||
FSFILE* ftmp = FSfopen((source), FS_READ);
|
||||
FSrename((dest), ftmp);
|
||||
return FSfclose(ftmp) == 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/* Glue functions for the minIni library, based on the C/C++ stdio library
|
||||
*
|
||||
* Or better said: this file contains macros that maps the function interface
|
||||
* used by minIni to the standard C/C++ file I/O functions.
|
||||
*
|
||||
* By CompuPhase, 2008-2014
|
||||
* This "glue file" is in the public domain. It is distributed without
|
||||
* warranties or conditions of any kind, either express or implied.
|
||||
*/
|
||||
|
||||
/* map required file I/O types and functions to the standard C library */
|
||||
#include <stdio.h>
|
||||
|
||||
#define INI_FILETYPE FILE*
|
||||
#define ini_openread(filename,file) ((*(file) = fopen((filename),"rb")) != NULL)
|
||||
#define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wb")) != NULL)
|
||||
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),"r+b")) != NULL)
|
||||
#define ini_close(file) (fclose(*(file)) == 0)
|
||||
#define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL)
|
||||
#define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0)
|
||||
#define ini_rename(source,dest) (rename((source), (dest)) == 0)
|
||||
#define ini_remove(filename) (remove(filename) == 0)
|
||||
|
||||
#define INI_FILEPOS long int
|
||||
#define ini_tell(file,pos) (*(pos) = ftell(*(file)))
|
||||
#define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0)
|
||||
|
||||
/* for floating-point support, define additional types and functions */
|
||||
#define INI_REAL float
|
||||
#define ini_ftoa(string,value) sprintf((string),"%f",(value))
|
||||
#define ini_atof(string) (INI_REAL)strtod((string),NULL)
|
||||
35
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/minGlue.h
Normal file
35
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/minGlue.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* Glue functions for the minIni library, based on the C/C++ stdio library
|
||||
*
|
||||
* Or better said: this file contains macros that maps the function interface
|
||||
* used by minIni to the standard C/C++ file I/O functions.
|
||||
*
|
||||
* By CompuPhase, 2008-2014
|
||||
* This "glue file" is in the public domain. It is distributed without
|
||||
* warranties or conditions of any kind, either express or implied.
|
||||
*/
|
||||
|
||||
/* map required file I/O types and functions to the standard C library */
|
||||
#include <stdio.h>
|
||||
|
||||
#define INI_FILETYPE FILE*
|
||||
#define ini_openread(filename,file) ((*(file) = fopen((filename),"rb")) != NULL)
|
||||
#define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wb")) != NULL)
|
||||
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),"r+b")) != NULL)
|
||||
#define ini_close(file) (fclose(*(file)) == 0)
|
||||
#define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL)
|
||||
#define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0)
|
||||
#define ini_rename(source,dest) (rename((source), (dest)) == 0)
|
||||
#define ini_remove(filename) (remove(filename) == 0)
|
||||
|
||||
#define INI_FILEPOS long int
|
||||
#define ini_tell(file,pos) (*(pos) = ftell(*(file)))
|
||||
#define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0)
|
||||
|
||||
/* for floating-point support, define additional types and functions */
|
||||
//#define INI_REAL float
|
||||
//#define ini_ftoa(string,value) sprintf((string),"%f",(value))
|
||||
//#define ini_atof(string) (INI_REAL)strtod((string),NULL)
|
||||
|
||||
#define INI_ANSIONLY
|
||||
#define INI_LINETERM "\n"
|
||||
#define PORTABLE_STRNICMP
|
||||
1009
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/minIni.c
Normal file
1009
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/minIni.c
Normal file
File diff suppressed because it is too large
Load Diff
68
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/minIni.h
Normal file
68
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/minIni.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* minIni - Multi-Platform INI file parser, suitable for embedded systems
|
||||
*
|
||||
* Copyright (c) CompuPhase, 2008-2017
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Version: $Id: minIni.h 53 2015-01-18 13:35:11Z thiadmer.riemersma@gmail.com $
|
||||
*/
|
||||
#ifndef MININI_H
|
||||
#define MININI_H
|
||||
|
||||
#include "minGlue.h"
|
||||
|
||||
#if (defined _UNICODE || defined __UNICODE__ || defined UNICODE) && !defined INI_ANSIONLY
|
||||
#include <tchar.h>
|
||||
#define mTCHAR TCHAR
|
||||
#else
|
||||
/* force TCHAR to be "char", but only for minIni */
|
||||
#define mTCHAR char
|
||||
#endif
|
||||
|
||||
#if !defined INI_BUFFERSIZE
|
||||
#define INI_BUFFERSIZE 512
|
||||
#endif
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int ini_getbool(const mTCHAR *Section, const mTCHAR *Key, int DefValue, const mTCHAR *Filename);
|
||||
long ini_getl(const mTCHAR *Section, const mTCHAR *Key, long DefValue, const mTCHAR *Filename);
|
||||
int ini_gets(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *DefValue, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename);
|
||||
int ini_getsection(int idx, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename);
|
||||
int ini_getkey(const mTCHAR *Section, int idx, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename);
|
||||
|
||||
#if defined INI_REAL
|
||||
INI_REAL ini_getf(const mTCHAR *Section, const mTCHAR *Key, INI_REAL DefValue, const mTCHAR *Filename);
|
||||
#endif
|
||||
|
||||
#if !defined INI_READONLY
|
||||
int ini_putl(const mTCHAR *Section, const mTCHAR *Key, long Value, const mTCHAR *Filename);
|
||||
int ini_puts(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Value, const mTCHAR *Filename);
|
||||
int ini_putsection(const mTCHAR *Section, const mTCHAR **Keys, const mTCHAR **Values, const mTCHAR *Filename);
|
||||
#if defined INI_REAL
|
||||
int ini_putf(const mTCHAR *Section, const mTCHAR *Key, INI_REAL Value, const mTCHAR *Filename);
|
||||
#endif
|
||||
#endif /* INI_READONLY */
|
||||
|
||||
#if !defined INI_NOBROWSE
|
||||
typedef int (*INI_CALLBACK)(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Value, void *UserData);
|
||||
int ini_browse(INI_CALLBACK Callback, void *UserData, const mTCHAR *Filename);
|
||||
#endif /* INI_NOBROWSE */
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MININI_H */
|
||||
117
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/test.c
Normal file
117
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/test.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/* Simple test program
|
||||
*
|
||||
* gcc -o test test.c minIni.c
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "minIni.h"
|
||||
|
||||
#define sizearray(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
const char inifile[] = "test.ini";
|
||||
const char inifile2[] = "testplain.ini";
|
||||
|
||||
int Callback(const char *section, const char *key, const char *value, void *userdata)
|
||||
{
|
||||
(void)userdata; /* this parameter is not used in this example */
|
||||
printf(" [%s]\t%s=%s\n", section, key, value);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char str[100];
|
||||
long n;
|
||||
int s, k;
|
||||
char section[50];
|
||||
|
||||
/* string reading */
|
||||
n = ini_gets("first", "string", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==4 && strcmp(str,"noot")==0);
|
||||
n = ini_gets("second", "string", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==4 && strcmp(str,"mies")==0);
|
||||
n = ini_gets("first", "undefined", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==5 && strcmp(str,"dummy")==0);
|
||||
/* ----- */
|
||||
n = ini_gets("", "string", "dummy", str, sizearray(str), inifile2);
|
||||
assert(n==4 && strcmp(str,"noot")==0);
|
||||
n = ini_gets(NULL, "string", "dummy", str, sizearray(str), inifile2);
|
||||
assert(n==4 && strcmp(str,"noot")==0);
|
||||
/* ----- */
|
||||
printf("1. String reading tests passed\n");
|
||||
|
||||
/* value reading */
|
||||
n = ini_getl("first", "val", -1, inifile);
|
||||
assert(n==1);
|
||||
n = ini_getl("second", "val", -1, inifile);
|
||||
assert(n==2);
|
||||
n = ini_getl("first", "undefined", -1, inifile);
|
||||
assert(n==-1);
|
||||
/* ----- */
|
||||
n = ini_getl(NULL, "val", -1, inifile2);
|
||||
assert(n==1);
|
||||
/* ----- */
|
||||
printf("2. Value reading tests passed\n");
|
||||
|
||||
/* string writing */
|
||||
n = ini_puts("first", "alt", "flagged as \"correct\"", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("first", "alt", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==20 && strcmp(str,"flagged as \"correct\"")==0);
|
||||
/* ----- */
|
||||
n = ini_puts("second", "alt", "correct", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==7 && strcmp(str,"correct")==0);
|
||||
/* ----- */
|
||||
n = ini_puts("third", "test", "correct", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("third", "test", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==7 && strcmp(str,"correct")==0);
|
||||
/* ----- */
|
||||
n = ini_puts("second", "alt", "overwrite", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==9 && strcmp(str,"overwrite")==0);
|
||||
/* ----- */
|
||||
n = ini_puts("second", "alt", "123456789", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==9 && strcmp(str,"123456789")==0);
|
||||
/* ----- */
|
||||
n = ini_puts(NULL, "alt", "correct", inifile2);
|
||||
assert(n==1);
|
||||
n = ini_gets(NULL, "alt", "dummy", str, sizearray(str), inifile2);
|
||||
assert(n==7 && strcmp(str,"correct")==0);
|
||||
/* ----- */
|
||||
printf("3. String writing tests passed\n");
|
||||
|
||||
/* section/key enumeration */
|
||||
printf("4. Section/key enumeration, file structure follows\n");
|
||||
for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) {
|
||||
printf(" [%s]\n", section);
|
||||
for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
|
||||
printf("\t%s\n", str);
|
||||
} /* for */
|
||||
} /* for */
|
||||
|
||||
/* browsing through the file */
|
||||
printf("5. browse through all settings, file field list follows\n");
|
||||
ini_browse(Callback, NULL, inifile);
|
||||
|
||||
/* string deletion */
|
||||
n = ini_puts("first", "alt", NULL, inifile);
|
||||
assert(n==1);
|
||||
n = ini_puts("second", "alt", NULL, inifile);
|
||||
assert(n==1);
|
||||
n = ini_puts("third", NULL, NULL, inifile);
|
||||
assert(n==1);
|
||||
/* ----- */
|
||||
n = ini_puts(NULL, "alt", NULL, inifile2);
|
||||
assert(n==1);
|
||||
printf("6. String deletion tests passed\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
8
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/test.ini
Normal file
8
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/test.ini
Normal file
@@ -0,0 +1,8 @@
|
||||
[First]
|
||||
String=noot # trailing commment
|
||||
Val=1
|
||||
|
||||
[Second]
|
||||
Val = 2
|
||||
#comment=3
|
||||
String = mies
|
||||
80
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/test2.cc
Normal file
80
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/test2.cc
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
gcc -o minIni.o -c minIni.c
|
||||
g++ -o test2.o -c test2.cc
|
||||
g++ -o test2 test2.o minIni.o
|
||||
./test2
|
||||
*/
|
||||
|
||||
|
||||
#include <assert>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std ;
|
||||
|
||||
#include "minIni.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
minIni ini("test.ini");
|
||||
string s;
|
||||
|
||||
/* string reading */
|
||||
s = ini.gets( "first", "string" , "aap" );
|
||||
assert(s == "noot");
|
||||
s = ini.gets( "second", "string" , "aap" );
|
||||
assert(s == "mies");
|
||||
s = ini.gets( "first", "dummy" , "aap" );
|
||||
assert(s == "aap");
|
||||
cout << "1. String reading tests passed" << endl ;
|
||||
|
||||
|
||||
/* value reading */
|
||||
long n;
|
||||
n = ini.getl("first", "val", -1 );
|
||||
assert(n==1);
|
||||
n = ini.getl("second", "val", -1);
|
||||
assert(n==2);
|
||||
n = ini.getl("first", "dummy", -1);
|
||||
assert(n==-1);
|
||||
cout << "2. Value reading tests passed" << endl ;
|
||||
|
||||
|
||||
/* string writing */
|
||||
bool b;
|
||||
b = ini.put("first", "alt", "flagged as \"correct\"");
|
||||
assert(b);
|
||||
s = ini.gets("first", "alt", "aap");
|
||||
assert(s=="flagged as \"correct\"");
|
||||
|
||||
b = ini.put("second", "alt", "correct");
|
||||
assert(b);
|
||||
s = ini.gets("second", "alt", "aap");
|
||||
assert(s=="correct");
|
||||
|
||||
b = ini.put("third", "alt", "correct");
|
||||
assert(b);
|
||||
s = ini.gets("third", "alt", "aap" );
|
||||
assert(s=="correct");
|
||||
cout << "3. String writing tests passed" << endl;
|
||||
|
||||
/* section/key enumeration */
|
||||
cout << "4. section/key enumeration; file contents follows" << endl;
|
||||
string section;
|
||||
for (int is = 0; section = ini.getsection(is), section.length() > 0; is++) {
|
||||
cout << " [" << section.c_str() << "]" << endl;
|
||||
for (int ik = 0; s = ini.getkey(section, ik), s.length() > 0; ik++) {
|
||||
cout << "\t" << s.c_str() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/* string deletion */
|
||||
b = ini.del("first", "alt");
|
||||
assert(b);
|
||||
b = ini.del("second", "alt");
|
||||
assert(b);
|
||||
b = ini.del("third");
|
||||
assert(b);
|
||||
cout << "5. string deletion passed " << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
String=noot # trailing commment
|
||||
#comment=3
|
||||
Val=1
|
||||
101
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/wxMinIni.h
Normal file
101
Source/rewrite-hoc-clk/sysmodule/lib/minIni/dev/wxMinIni.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/* minIni - Multi-Platform INI file parser, wxWidgets interface
|
||||
*
|
||||
* Copyright (c) CompuPhase, 2008-2012
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Version: $Id: wxMinIni.h 44 2012-01-04 15:52:56Z thiadmer.riemersma@gmail.com $
|
||||
*/
|
||||
#ifndef WXMININI_H
|
||||
#define WXMININI_H
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include "minIni.h"
|
||||
|
||||
class minIni
|
||||
{
|
||||
public:
|
||||
minIni(const wxString& filename) : iniFilename(filename)
|
||||
{ }
|
||||
|
||||
bool getbool(const wxString& Section, const wxString& Key, bool DefValue=false) const
|
||||
{ return ini_getbool(Section.utf8_str(), Key.utf8_str(), int(DefValue), iniFilename.utf8_str()) != 0; }
|
||||
|
||||
long getl(const wxString& Section, const wxString& Key, long DefValue=0) const
|
||||
{ return ini_getl(Section.utf8_str(), Key.utf8_str(), DefValue, iniFilename.utf8_str()); }
|
||||
|
||||
int geti(const wxString& Section, const wxString& Key, int DefValue=0) const
|
||||
{ return static_cast<int>(ini_getl(Section.utf8_str(), Key.utf8_str(), (long)DefValue, iniFilename.utf8_str())); }
|
||||
|
||||
wxString gets(const wxString& Section, const wxString& Key, const wxString& DefValue=wxT("")) const
|
||||
{
|
||||
char buffer[INI_BUFFERSIZE];
|
||||
ini_gets(Section.utf8_str(), Key.utf8_str(), DefValue.utf8_str(), buffer, INI_BUFFERSIZE, iniFilename.utf8_str());
|
||||
wxString result = wxString::FromUTF8(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
wxString getsection(int idx) const
|
||||
{
|
||||
char buffer[INI_BUFFERSIZE];
|
||||
ini_getsection(idx, buffer, INI_BUFFERSIZE, iniFilename.utf8_str());
|
||||
wxString result = wxString::FromUTF8(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
wxString getkey(const wxString& Section, int idx) const
|
||||
{
|
||||
char buffer[INI_BUFFERSIZE];
|
||||
ini_getkey(Section.utf8_str(), idx, buffer, INI_BUFFERSIZE, iniFilename.utf8_str());
|
||||
wxString result = wxString::FromUTF8(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined INI_REAL
|
||||
INI_REAL getf(const wxString& Section, wxString& Key, INI_REAL DefValue=0) const
|
||||
{ return ini_getf(Section.utf8_str(), Key.utf8_str(), DefValue, iniFilename.utf8_str()); }
|
||||
#endif
|
||||
|
||||
#if ! defined INI_READONLY
|
||||
bool put(const wxString& Section, const wxString& Key, long Value) const
|
||||
{ return ini_putl(Section.utf8_str(), Key.utf8_str(), Value, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool put(const wxString& Section, const wxString& Key, int Value) const
|
||||
{ return ini_putl(Section.utf8_str(), Key.utf8_str(), (long)Value, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool put(const wxString& Section, const wxString& Key, bool Value) const
|
||||
{ return ini_putl(Section.utf8_str(), Key.utf8_str(), (long)Value, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool put(const wxString& Section, const wxString& Key, const wxString& Value) const
|
||||
{ return ini_puts(Section.utf8_str(), Key.utf8_str(), Value.utf8_str(), iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool put(const wxString& Section, const wxString& Key, const char* Value) const
|
||||
{ return ini_puts(Section.utf8_str(), Key.utf8_str(), Value, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
#if defined INI_REAL
|
||||
bool put(const wxString& Section, const wxString& Key, INI_REAL Value) const
|
||||
{ return ini_putf(Section.utf8_str(), Key.utf8_str(), Value, iniFilename.utf8_str()) != 0; }
|
||||
#endif
|
||||
|
||||
bool del(const wxString& Section, const wxString& Key) const
|
||||
{ return ini_puts(Section.utf8_str(), Key.utf8_str(), 0, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool del(const wxString& Section) const
|
||||
{ return ini_puts(Section.utf8_str(), 0, 0, iniFilename.utf8_str()) != 0; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
wxString iniFilename;
|
||||
};
|
||||
|
||||
#endif /* WXMININI_H */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user