Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Felix-Dev
Copy link
Member

@Felix-Dev Felix-Dev commented Feb 17, 2021

Description

This PR adds the fully reverse-engineered Power Service (power_0x.prx) to uofw.

Except for the PSP Go (PSP N-1000), all PSP series should be supported. We currently don't have support for the PSP Go model due to a missing reverse engineering of the PSP Go's exclusive hibernation feature. I don't have any plans right now to add that support, so if anyone wants to take a look at that, feel free to go ahead :)

Highlights

  • Power appears to work! (Check below for more info on how it was tested)
  • A full public API documentation!
  • Plenty of additional comments throughout the codebase explaining the power service implemention.

Motivation and Context

Closes #39.

How Has This Been Tested?

The module has been compiled and tested successfully on a PSP-1000. Testing included the following:

  • Verify that the PSP still boots and runs correctly (XMB & game)
  • Verify that the PSP suspends and resumes correctly
  • Verify that power saving features like dimming/turning off the PSP display work
  • Verify that battery data is displayed correctly in the system

Specific APIs have not been tested and as such might contain bugs. However, the overall impression after testing is that our power module can be run on a PSP device without causing any major issues.

Additional Context

Power service can be compiled using the archaic PSPSDK 0.11 release as well as the most recent PSPSDK as part of the PSP toolchain. Once we've updated the toolchain version used in our CI, support for PSPSDK 0.11 can be removed from power.

Note that if you want to run the power module on your PSP using the UOFW installer, make sure to comment out its patching of the power service to make sure no issue is introduced by running power through the UOFW installer.

Final Notes

I had started working on power all the way back in early 2013 and then stopped soon after that...until starting to work on it again since the beginning of this year. If it weren't for the amazing PSP community on discord, I doubt I would have ever gathered the necessary motivation and drive to finally bring power over the finish line. Many thanks to the PSP community 👍

Copy link
Contributor

@John-K John-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic work, @Felix-Dev! I can imagine some of it must have been quite tedious!

#define POWER_ERROR_H

/* This constant represents an unknown power service error (related to the PSP system chip's temperature). */
#define SCE_POWER_ERROR_0010 0x802B0010
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be a part of / be included from include/common/errors.h?

* This constant specifies that a search for a slot number from among the empty slots is to be automatically performed
* when a callback is registered with the ::scePowerRegisterCallback() function.
*/
#define SCE_POWER_CALLBACKSLOT_AUTO (-1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there is a lot of duplication with power_kernel.h can we re-factor this out into power_common.h?

* voltage, charge cycle,...). Internally, we set up a worker thread which periodically polls the battery to update
* the collected battery properties.
*
* Starting with the PSP N-1000 (PSP-Go) serie, the battery equipped by default no longer has hardware included to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Starting with the PSP N-1000 (PSP-Go) serie, the battery equipped by default no longer has hardware included to
* Starting with the PSP N-1000 (PSP-Go) series, the battery equipped by default no longer has hardware included to

* At the time of power service termination, there might be an active [permit battery charging] request
* in our battery manager. This request might currently be lined up in our battery worker thread for
* execution or scheduled to happen after some delay time. However, as we are in the process of shutting
* down the kernel (anf thus our battery worker thread) we will removed any scheduled/lined up work here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* down the kernel (anf thus our battery worker thread) we will removed any scheduled/lined up work here
* down the kernel (and thus our battery worker thread) we will remove any scheduled/lined up work here

#define SCE_SYSCON_BARYON_STATUS_ALARM (1 << 3)
#define SCE_SYSCON_BARYON_STATUS_POWER_SW_ON (1 << 4)
#define SCE_SYSCON_BARYON_STATUS_IS_LOW_BATTERY_01G (1 << 5)
#define SCE_SYSCON_BARYON_STATUS_HDD_POWER (1 << 18)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo? sceSysconGetBaryonStatus returns a u8, so (1 << 7) would be the max possible

* - Scratchpad memory
* - Graphic Engine and the Graphic Engine's eDRAM
* - DMA transfers for general-purpose memory copying
* - DMA transfers for the Memory Stic, WLAN, USB, LCD, or audio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - DMA transfers for the Memory Stic, WLAN, USB, LCD, or audio
* - DMA transfers for the Memory Stick, WLAN, USB, LCD, or audio

* - Graphic Engine and the Graphic Engine's eDRAM
* - DMA transfers for general-purpose memory copying
* - DMA transfers for the Memory Stic, WLAN, USB, LCD, or audio
* - DMA transfers for transfers to the MediaEngine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - DMA transfers for transfers to the MediaEngine
* - DMA transfers to the MediaEngine


u8 baryonVersionMajor = PSP_SYSCON_BARYON_GET_VERSION_MAJOR(g_Power.baryonVersion);
u8 baryonVersionMinor = PSP_SYSCON_BARYON_GET_VERSION_MINOR(g_Power.baryonVersion);
if (baryonVersionMajor == 0x2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be greatly simplified, but it seems like we're trying to match Sony's implementation which must have had the optimizer turned off or something.

}

// scePower_DB9D28DD
s32 scePowerUnregitserCallback(s32 slot) __attribute__((alias("scePowerUnregisterCallback")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely handled

Comment on lines 56 to 57
* used to contain a copy of the on-board eDRAM content as the 4MB eDRAM memory is volatile when the system is
* suspended. When the PSP resumes, this saved content is then written back to the on-board eDRAM.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* used to contain a copy of the on-board eDRAM content as the 4MB eDRAM memory is volatile when the system is
* suspended. When the PSP resumes, this saved content is then written back to the on-board eDRAM.
* used to contain a copy of the on-board eDRAM content as the 4MB eDRAM memory is volatile and lost when
* the system is suspended. When the PSP resumes, this saved content is then written back to the on-board eDRAM.

@fjtrujy
Copy link

fjtrujy commented May 19, 2022

I saw some .a files added to the PR, is that right?

@joel16
Copy link
Member

joel16 commented May 19, 2022

I saw some .a files added to the PR, is that right?

Yes these are stub libraries required to build the module.

@Linblow
Copy link
Contributor

Linblow commented Jan 27, 2024

Why is this not merged yet?

@joel16
Copy link
Member

joel16 commented Jan 28, 2024

Why is this not merged yet?

Well, it can't now because it has merge conflicts. Aything in this PR under the "src" directory needs to be moved to "src/kd/".

@artart78
Copy link
Member

Why is this not merged yet?

The stuff asked by Hedge a few years ago has not been fixed yet. Feel free to do it if you want. It could be ignored and merged anyway but I feel it'd be a waste to discard the remarks.

Well, it can't now because it has merge conflicts. Aything in this PR under the "src" directory needs to be moved to "src/kd/".

This is trivial to rebase anyway, that's not an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reverse Engineer power

7 participants