2018-08-06 18:41:45 +02:00
|
|
|
#pragma once
|
2024-01-29 23:27:10 +01:00
|
|
|
#include "stdint.h"
|
2020-04-27 00:14:37 +02:00
|
|
|
#include "types.h"
|
2018-08-06 18:41:45 +02:00
|
|
|
|
2023-05-01 17:58:35 +02:00
|
|
|
/**
|
|
|
|
* Physical Page management
|
2021-04-10 21:53:03 +02:00
|
|
|
*/
|
|
|
|
|
2019-04-11 22:34:20 +02:00
|
|
|
#define PAGE_SHIFT 12U
|
|
|
|
#define PAGE_SIZE (1U << PAGE_SHIFT)
|
2021-10-26 22:08:36 +02:00
|
|
|
#define PAGE_MASK (PAGE_SIZE - 1)
|
|
|
|
|
2018-08-06 18:41:45 +02:00
|
|
|
|
|
|
|
// Defined in linker.ld script
|
2023-11-20 00:02:22 +01:00
|
|
|
extern char __ld_kernel_begin;
|
|
|
|
extern char __ld_kernel_end;
|
2018-08-06 18:41:45 +02:00
|
|
|
|
2021-04-10 21:53:03 +02:00
|
|
|
struct phyMemDesc {
|
2020-04-27 00:14:37 +02:00
|
|
|
paddr_t phy_addr;
|
2021-02-10 21:15:35 +01:00
|
|
|
unsigned long ref;
|
2021-04-10 21:53:03 +02:00
|
|
|
struct phyMemDesc *next, *prev;
|
2018-08-06 18:41:45 +02:00
|
|
|
};
|
|
|
|
|
2023-05-01 17:58:35 +02:00
|
|
|
/**
|
|
|
|
* Initi Physical Page management subsystem
|
|
|
|
**/
|
2021-04-10 00:24:02 +02:00
|
|
|
int memSetup(paddr_t upperMem, paddr_t * firstUsed, paddr_t *lastUsed);
|
2023-05-01 17:58:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Declare a physical region to be managed by the physica page subsystem
|
|
|
|
**/
|
2021-01-23 00:42:09 +01:00
|
|
|
int memAddBank(paddr_t bottomMem, paddr_t topMem, int isFree);
|
2023-05-01 17:58:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Request @params nbPage free physical pages
|
|
|
|
**/
|
2020-08-28 22:38:05 +02:00
|
|
|
paddr_t allocPhyPage(uint nbPage);
|
2023-05-01 17:58:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrement the nb of user of a given physical page
|
|
|
|
**/
|
2018-11-09 21:49:23 +01:00
|
|
|
int unrefPhyPage(paddr_t addr);
|
2023-05-01 17:58:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increment the nb of user of a given physical page
|
|
|
|
**/
|
2018-11-09 21:49:23 +01:00
|
|
|
int refPhyPage(paddr_t addr);
|
2023-05-01 17:58:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of physical allocated pages
|
|
|
|
**/
|
2018-11-14 14:28:06 +01:00
|
|
|
unsigned long getNbAllocatedPage(void);
|
2021-01-23 21:51:00 +01:00
|
|
|
void memGetStat(uint *free, uint *used);
|