20 #include "Translation.h" 21 #include "pedigree/kernel/Log.h" 22 #include "pedigree/kernel/machine/openfirmware/Device.h" 23 #include "pedigree/kernel/machine/openfirmware/OpenFirmware.h" 24 #include "pedigree/kernel/panic.h" 26 Translations::Translations() : m_nTranslations(0)
30 OFDevice mmu(chosen.getProperty(
"mmu"));
33 "translations", m_pTranslations,
34 sizeof(Translation) * NUM_TRANSLATIONS) == -1)
38 panic(
"Translations not detected correctly");
43 mmu.getPropertyLength(
"translations") /
sizeof(Translation);
44 for (
unsigned int i = 0; i < m_nTranslations; i++)
47 "T: " <<
Hex << m_pTranslations[i].virt <<
", " 48 << m_pTranslations[i].phys <<
", " << m_pTranslations[i].size
49 <<
", " << m_pTranslations[i].mode);
53 Translations::~Translations()
59 return m_pTranslations[n];
64 return m_nTranslations;
68 uint32_t virt, uint32_t phys, uint32_t size, uint32_t mode)
70 m_pTranslations[m_nTranslations].virt = virt;
71 m_pTranslations[m_nTranslations].phys = phys;
72 m_pTranslations[m_nTranslations].size = size;
73 m_pTranslations[m_nTranslations].mode = mode;
75 if (m_nTranslations >= NUM_TRANSLATIONS)
76 panic(
"Too many translations!");
84 asm volatile(
"mfsdr1 %0" :
"=r"(sdr1));
88 for (uint32_t i = 0x000000; i < 0xFFFFFFFF - align; i += align)
94 for (
unsigned int j = 0; j < m_nTranslations; j++)
98 if ((m_pTranslations[j].phys >= addr) &&
99 (m_pTranslations[j].phys < addr + size))
105 uint32_t end = m_pTranslations[j].phys + m_pTranslations[j].size;
106 if ((end >= addr) && (end < addr + size))
113 if ((sdr1 >= addr && sdr1 < addr + size) ||
114 ((sdr1 + 0x1000000) >= addr && (sdr1 + 0x1000000) < (addr + size)))
128 for (
unsigned int i = 0; i < m_nTranslations; i++)
130 if (m_pTranslations[i].virt >= start &&
131 m_pTranslations[i].virt < end)
135 for (; i < m_nTranslations; i++)
136 m_pTranslations[i] = m_pTranslations[i + 1];
void removeRange(uintptr_t start, uintptr_t end)
static OpenFirmware & instance()
Translation getTranslation(size_t n)
void EXPORTED_PUBLIC panic(const char *msg) NORETURN
void addTranslation(uint32_t virt, uint32_t phys, uint32_t size, uint32_t mode)
uint32_t findFreePhysicalMemory(uint32_t size, uint32_t align=0x100000)
size_t getNumTranslations()