source: soft/giet_vm/giet_common/pmem.c @ 752

Last change on this file since 752 was 752, checked in by alain, 8 years ago

Cosmetic.

File size: 3.6 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : pmem.c
3// Date     : 01/07/2012
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
8#include <tty0.h>
9#include <utils.h>
10#include <pmem.h>
11#include <giet_config.h>
12
13///////////////////////////////////////////////////////////////////////////////////
14//     Global variable : array of physical memory allocators (one per cluster)
15///////////////////////////////////////////////////////////////////////////////////
16
17extern pmem_alloc_t _boot_pmem_alloc[X_SIZE][Y_SIZE];
18
19////////////////////////////////////////
20void _pmem_alloc_init( unsigned int x,
21                       unsigned int y,
22                       unsigned int base,
23                       unsigned int size )
24{
25    if ( (base & 0x1FFFFF) || (size & 0x1FFFFF) )
26    {
27        _puts("\n[GIET ERROR] in _pmem_alloc_init() : pseg in cluster[");
28        _putd( x );
29        _puts(",");
30        _putd( y );
31        _puts("] not aligned on 2 Mbytes\n");
32        _exit();
33    }
34
35    pmem_alloc_t* p       = &_boot_pmem_alloc[x][y];
36
37    unsigned int  bppi_min = base >> 21;
38    unsigned int  bppi_max = (base + size) >> 21;
39
40    p->x        = x;
41    p->y        = y;
42
43    p->nxt_bppi = bppi_min;
44    p->max_bppi = bppi_max;
45
46    p->nxt_sppi = 0;
47    p->max_sppi = 0;
48
49    // first page reserved in cluster [0][0]
50    if ( (x==0) && (y==0) ) p->nxt_bppi = p->nxt_bppi + 1;
51
52} // end pmem_alloc_init()
53
54/////////////////////////////////////////////
55unsigned int _get_big_ppn( pmem_alloc_t*  p, 
56                           unsigned int   n )
57{
58    unsigned int x   = p->x;
59    unsigned int y   = p->y;
60    unsigned int bpi = p->nxt_bppi;  // bpi : BPPI of the first allocated big page
61
62    if ( (bpi + n) > p->max_bppi )
63    {
64        _puts("\n[GIET ERROR] in _get_big_ppn() : not enough BPP in cluster[");
65        _putd( x );
66        _puts(",");
67        _putd( y );
68        _puts("]\n");
69        _exit();
70    }
71   
72    // update allocator state
73    p->nxt_bppi = bpi + n;
74
75    return (x << 24) + (y << 20) + (bpi << 9);
76
77} // end get_big_ppn()
78
79///////////////////////////////////////////////
80unsigned int _get_small_ppn( pmem_alloc_t*  p,
81                             unsigned int   n )
82{
83    unsigned int x    = p->x;
84    unsigned int y    = p->y;
85    unsigned int spi  = p->nxt_sppi;   // spi : SPPI of the first allocated small page
86    unsigned int bpi  = p->spp_bppi;   // bpi : BPPI of the first allocated small page
87
88    // get a new big page if not enough contiguous small pages
89    // in the big page currently used to allocate small pages
90    if ( spi + n > p->max_sppi ) 
91    {
92        if ( p->nxt_bppi + 1 > p->max_bppi )
93        {
94            _puts("\n[GIET ERROR] in _get_small_ppn() : not enough BPP in cluster[");
95            _putd( x );
96            _puts(",");
97            _putd( y );
98            _puts("]\n");
99            _exit();
100        }
101
102        // update the allocator state for the new big page
103        p->spp_bppi = p->nxt_bppi;
104        p->nxt_bppi = p->nxt_bppi + 1;
105        p->nxt_sppi = 0;
106        p->max_sppi = 512;
107
108        // set the spi and bpi values
109        spi = p->nxt_sppi;
110        bpi = p->spp_bppi;
111    }
112
113    // update allocator state for the n small pages
114    p->nxt_sppi = p->nxt_sppi + n;
115
116    return (x << 24) + (y << 20) + (bpi << 9) + spi;
117
118} // end _get_small_ppn()
119
120
121
122// Local Variables:
123// tab-width: 4
124// c-basic-offset: 4
125// c-file-offsets:((innamespace . 0)(inline-open . 0))
126// indent-tabs-mode: nil
127// End:
128// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
129
130
Note: See TracBrowser for help on using the repository browser.