Add types.h to distinguish physical/virt mem

This commit is contained in:
Mathieu Maret 2018-11-09 21:49:23 +01:00
parent 149b197a65
commit 93c8c87285
3 changed files with 16 additions and 8 deletions

View File

@ -34,7 +34,7 @@ int memSetup(unsigned long upper_mem)
return 0;
}
struct mem_desc *addr2memDesc(unsigned long addr)
struct mem_desc *addr2memDesc(paddr_t addr)
{
if (addr > top_mem || addr < bottom_mem)
return NULL;
@ -43,7 +43,7 @@ struct mem_desc *addr2memDesc(unsigned long addr)
return page_desc + idx;
}
unsigned long allocPhyPage(void)
paddr_t allocPhyPage(void)
{
if (list_is_empty(free_page)) {
return (unsigned long)NULL;
@ -54,7 +54,7 @@ unsigned long allocPhyPage(void)
return mem->phy_addr;
}
int unrefPhyPage(unsigned long addr)
int unrefPhyPage(paddr_t addr)
{
struct mem_desc *mem = addr2memDesc(addr);
if (!mem) {
@ -69,7 +69,7 @@ int unrefPhyPage(unsigned long addr)
return 0;
}
int refPhyPage(unsigned long addr)
int refPhyPage(paddr_t addr)
{
struct mem_desc *mem = addr2memDesc(addr);
if (!mem) {

View File

@ -1,4 +1,5 @@
#pragma once
#include "types.h"
#include "stdarg.h"
@ -10,13 +11,13 @@ extern uint32_t __ld_kernel_begin;
extern uint32_t __ld_kernel_end;
struct mem_desc{
unsigned long phy_addr;
paddr_t phy_addr;
unsigned long ref;
struct mem_desc *next, *prev;
};
int memSetup(unsigned long upper_mem);
unsigned long allocPhyPage(void);
int unrefPhyPage(unsigned long addr);
int refPhyPage(unsigned long addr);
paddr_t allocPhyPage(void);
int unrefPhyPage(paddr_t addr);
int refPhyPage(paddr_t addr);

7
core/types.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
// Virtual address
typedef unsigned long vaddr_t;
// Physical address
typedef unsigned long paddr_t;