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

Last change on this file since 443 was 442, checked in by alain, 10 years ago

Removing the _printf() function in the boot code i
and in the drivers used by the boot code.

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