CS350 COS
COS
Loading...
Searching...
No Matches
xmem.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include <sys/kconfig.h>
#include <sys/kassert.h>
#include <sys/kdebug.h>
#include <sys/kmem.h>
#include <machine/amd64.h>
#include <machine/amd64op.h>
#include <machine/pmap.h>
#include <machine/mp.h>
Include dependency graph for xmem.c:

Go to the source code of this file.

Data Structures

struct  XMem
 

Macros

#define MAX_XMEM_REGIONS   1024
 

Typedefs

typedef struct XMem XMem
 

Functions

void XMem_Init ()
 
XMemXMem_New ()
 
void XMem_Destroy (XMem *xmem)
 
uintptr_t XMem_GetBase (XMem *xmem)
 
uintptr_t XMem_GetLength (XMem *xmem)
 
bool XMem_Allocate (XMem *xmem, uintptr_t length)
 
static void Debug_XMemStats (int argc, const char *argv[])
 
 REGISTER_DBGCMD (xmemstats, "XMem statistics", Debug_XMemStats)
 

Variables

XMem regions [MAX_XMEM_REGIONS]
 

Data Structure Documentation

◆ XMem

struct XMem

Definition at line 17 of file xmem.c.

Collaboration diagram for XMem:
[legend]
Data Fields
uintptr_t base
bool inUse
uintptr_t length
uintptr_t maxLength

Macro Definition Documentation

◆ MAX_XMEM_REGIONS

#define MAX_XMEM_REGIONS   1024

Definition at line 15 of file xmem.c.

Typedef Documentation

◆ XMem

typedef struct XMem XMem

Function Documentation

◆ Debug_XMemStats()

static void Debug_XMemStats ( int  argc,
const char *  argv[] 
)
static

Definition at line 118 of file xmem.c.

119{
120 int r;
121
122 kprintf("Region Nr: %16s %16s\n", "Base", "Length");
123 for (r = 0; r < MAX_XMEM_REGIONS; r++)
124 {
125 if (regions[r].inUse) {
126 kprintf("Region %2d: %016llx %016llx\n", r,
127 regions[r].base, regions[r].length);
128 }
129 }
130}
int kprintf(const char *fmt,...)
Definition: printf.c:210
static uint16_t base
Definition: sercons.c:37
XMem regions[MAX_XMEM_REGIONS]
Definition: xmem.c:25
#define MAX_XMEM_REGIONS
Definition: xmem.c:15
Here is the call graph for this function:

◆ REGISTER_DBGCMD()

REGISTER_DBGCMD ( xmemstats  ,
"XMem statistics"  ,
Debug_XMemStats   
)

◆ XMem_Allocate()

bool XMem_Allocate ( XMem xmem,
uintptr_t  length 
)

Definition at line 92 of file xmem.c.

93{
94 uint64_t off;
95
96 // We already allocated up to that size
97 if (xmem->length > length)
98 return true;
99
100 // Allocation too long
101 if (length > xmem->maxLength)
102 return false;
103
104 for (off = xmem->length; off < length; off += PGSIZE) {
105 void *pg = PAlloc_AllocPage();
106 if (pg == NULL)
107 return false;
108
109 PMap_SystemMap(DMVA2PA((uint64_t)pg), xmem->base + off, 1, 0);
110
111 xmem->length += PGSIZE;
112 }
113
114 return true;
115}
void * PAlloc_AllocPage()
Definition: palloc.c:188
#define PGSIZE
Definition: malloc.c:21
#define DMVA2PA(dmva)
Definition: pmap.h:47
bool PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
Definition: pmap.c:514
#define NULL
Definition: stddef.h:6
unsigned long uint64_t
Definition: types.h:13
uintptr_t length
Definition: xmem.c:22
uintptr_t maxLength
Definition: xmem.c:21
uintptr_t base
Definition: xmem.c:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XMem_Destroy()

void XMem_Destroy ( XMem xmem)

Definition at line 63 of file xmem.c.

64{
65 uintptr_t off;
66 PageEntry *entry;
67
68 for (off = 0; off < xmem->length; off += PGSIZE) {
69 PMap_SystemLookup(xmem->base + off, &entry, PGSIZE);
70
71 // Compute DM
72
73 // Free Page
74 }
75
76 //PMap_SystemUnmap(virt, pages);
77}
uint64_t PageEntry
Definition: amd64.h:52
void PMap_SystemLookup(uint64_t va, PageEntry **entry, int size)
Definition: pmap.c:460
uint64_t uintptr_t
Definition: types.h:16
Here is the call graph for this function:

◆ XMem_GetBase()

uintptr_t XMem_GetBase ( XMem xmem)

Definition at line 80 of file xmem.c.

81{
82 return xmem->base;
83}
Here is the caller graph for this function:

◆ XMem_GetLength()

uintptr_t XMem_GetLength ( XMem xmem)

Definition at line 86 of file xmem.c.

87{
88 return xmem->length;
89}
Here is the caller graph for this function:

◆ XMem_Init()

void XMem_Init ( )

Definition at line 28 of file xmem.c.

29{
30 int r;
32
33 kprintf("Initializing XMEM ... ");
34
35 for (r = 0; r < MAX_XMEM_REGIONS; r++)
36 {
37 regions[r].inUse = false;
38 regions[r].base = MEM_XMAP_BASE + r * regionSize;
39 regions[r].maxLength = regionSize;
40 regions[r].length = 0;
41 }
42
43 kprintf("Done!\n");
44}
#define MEM_XMAP_LEN
Definition: pmap.h:43
#define MEM_XMAP_BASE
Definition: pmap.h:42
bool inUse
Definition: xmem.c:19
Here is the call graph for this function:
Here is the caller graph for this function:

◆ XMem_New()

XMem * XMem_New ( )

Definition at line 47 of file xmem.c.

48{
49 int r;
50
51 for (r = 0; r < MAX_XMEM_REGIONS; r++)
52 {
53 if (!regions[r].inUse) {
54 regions[r].inUse = true;
55 return &regions[r];
56 }
57 }
58
59 return NULL;
60}
Here is the caller graph for this function:

Variable Documentation

◆ regions

Definition at line 25 of file xmem.c.