2021-08-24 05:15:51 +01:00
|
|
|
/*
|
2021-10-04 20:59:10 +01:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2021-08-24 05:15:51 +01:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
namespace ams::nxboot {
|
|
|
|
|
2021-09-02 02:25:36 +01:00
|
|
|
void DoMemoryTrainingErista(int index, void *mtc_tables_buffer);
|
2021-09-02 03:06:46 +01:00
|
|
|
void DoMemoryTrainingMariko(bool *out_did_training, int index, void *mtc_tables_buffer);
|
|
|
|
|
|
|
|
void RestoreMemoryClockRateMariko(void *mtc_tables_buffer);
|
2021-08-24 05:15:51 +01:00
|
|
|
|
2021-08-25 00:51:16 +01:00
|
|
|
namespace {
|
|
|
|
|
2021-09-02 02:25:36 +01:00
|
|
|
alignas(4) constinit u8 g_mtc_tables_buffer[0x26C0];
|
|
|
|
|
2021-09-02 03:06:46 +01:00
|
|
|
constinit bool g_did_training_mariko = false;
|
|
|
|
|
2021-08-25 00:51:16 +01:00
|
|
|
constexpr const u8 MemoryTrainingTableIndex_Invalid = std::numeric_limits<u8>::max();
|
|
|
|
|
|
|
|
constexpr const u8 MemoryTrainingTableIndices[] = {
|
|
|
|
/* DramId_EristaIcosaSamsung4gb */ 0x00,
|
|
|
|
/* DramId_EristaIcosaHynix4gb */ 0x02,
|
|
|
|
/* DramId_EristaIcosaMicron4gb */ 0x03,
|
|
|
|
/* DramId_MarikoIowaHynix1y4gb */ 0x10,
|
|
|
|
/* DramId_EristaIcosaSamsung6gb */ 0x01,
|
|
|
|
/* DramId_MarikoHoagHynix1y4gb */ 0x10,
|
2021-09-16 00:25:32 +01:00
|
|
|
/* DramId_MarikoAulaHynix1y4gb */ 0x10,
|
2021-08-25 00:51:16 +01:00
|
|
|
/* DramId_MarikoIowax1x2Samsung4gb */ 0x00,
|
|
|
|
/* DramId_MarikoIowaSamsung4gb */ 0x05,
|
|
|
|
/* DramId_MarikoIowaSamsung8gb */ 0x06,
|
|
|
|
/* DramId_MarikoIowaHynix4gb */ 0x07,
|
|
|
|
/* DramId_MarikoIowaMicron4gb */ 0x08,
|
|
|
|
/* DramId_MarikoHoagSamsung4gb */ 0x05,
|
|
|
|
/* DramId_MarikoHoagSamsung8gb */ 0x06,
|
|
|
|
/* DramId_MarikoHoagHynix4gb */ 0x07,
|
|
|
|
/* DramId_MarikoHoagMicron4gb */ 0x08,
|
|
|
|
/* DramId_MarikoIowaSamsung4gbY */ 0x09,
|
|
|
|
/* DramId_MarikoIowaSamsung1y4gbX */ 0x0C,
|
|
|
|
/* DramId_MarikoIowaSamsung1y8gbX */ 0x0D,
|
|
|
|
/* DramId_MarikoHoagSamsung1y4gbX */ 0x0C,
|
2022-03-22 22:51:29 +00:00
|
|
|
/* DramId_MarikoIowaSamsung1z4gb */ 0x12,
|
|
|
|
/* DramId_MarikoHoagSamsung1z4gb */ 0x12,
|
|
|
|
/* DramId_MarikoAulaSamsung1z4gb */ 0x12,
|
2021-08-25 00:51:16 +01:00
|
|
|
/* DramId_MarikoHoagSamsung1y8gbX */ 0x0D,
|
|
|
|
/* DramId_MarikoAulaSamsung1y4gbX */ 0x0C,
|
|
|
|
/* DramId_MarikoIowaMicron1y4gb */ 0x0F,
|
|
|
|
/* DramId_MarikoHoagMicron1y4gb */ 0x0F,
|
|
|
|
/* DramId_MarikoAulaMicron1y4gb */ 0x0F,
|
|
|
|
/* DramId_MarikoAulaSamsung1y8gbX */ 0x0D,
|
|
|
|
};
|
|
|
|
|
2021-08-28 07:20:46 +01:00
|
|
|
int GetMemoryTrainingTableIndex() {
|
|
|
|
if (const auto dram_id = fuse::GetDramId(); dram_id < util::size(MemoryTrainingTableIndices) && MemoryTrainingTableIndices[dram_id] != MemoryTrainingTableIndex_Invalid) {
|
|
|
|
return static_cast<int>(MemoryTrainingTableIndices[dram_id]);
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-25 00:51:16 +01:00
|
|
|
}
|
|
|
|
|
2021-08-24 05:15:51 +01:00
|
|
|
void DoMemoryTraining() {
|
2021-08-28 07:20:46 +01:00
|
|
|
const auto index = GetMemoryTrainingTableIndex();
|
2021-08-24 05:15:51 +01:00
|
|
|
|
2021-08-28 07:20:46 +01:00
|
|
|
if (fuse::GetSocType() == fuse::SocType_Erista) {
|
2021-09-02 02:25:36 +01:00
|
|
|
DoMemoryTrainingErista(index, g_mtc_tables_buffer);
|
2021-08-25 00:51:16 +01:00
|
|
|
} else {
|
2021-09-02 03:06:46 +01:00
|
|
|
DoMemoryTrainingMariko(std::addressof(g_did_training_mariko), index, g_mtc_tables_buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreMemoryClockRate() {
|
|
|
|
/* NOTE: This resolves an off-by-one issue in PCV's detection of memory clock rate on Mariko. */
|
|
|
|
if (fuse::GetSocType() == fuse::SocType_Mariko && g_did_training_mariko) {
|
|
|
|
RestoreMemoryClockRateMariko(g_mtc_tables_buffer);
|
2021-08-25 00:51:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 05:15:51 +01:00
|
|
|
}
|