Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/src/mm/frame.c

    r98000fb rdc0b964  
    2727 */
    2828
    29 /** @addtogroup ia32mm 
     29/** @addtogroup ia32mm
    3030 * @{
    3131 */
     
    4444#include <align.h>
    4545#include <macros.h>
    46 
    4746#include <print.h>
     47
     48#define PHYSMEM_LIMIT32  UINT64_C(0x07c000000)
     49#define PHYSMEM_LIMIT64  UINT64_C(0x200000000)
    4850
    4951size_t hardcoded_unmapped_ktext_size = 0;
     
    5557{
    5658        unsigned int i;
     59       
    5760        for (i = 0; i < e820counter; i++) {
    5861                uint64_t base = e820table[i].base_address;
     
    6063               
    6164#ifdef __32_BITS__
    62                
    63                 /* Ignore physical memory above 4 GB */
    64                 if ((base >> 32) != 0)
     65                /*
     66                 * XXX FIXME:
     67                 *
     68                 * Ignore zones which start above PHYSMEM_LIMIT32
     69                 * or clip zones which go beyond PHYSMEM_LIMIT32.
     70                 *
     71                 * The PHYSMEM_LIMIT32 (2 GB - 64 MB) is a rather
     72                 * arbitrary constant which allows to have at
     73                 * least 64 MB in the kernel address space to
     74                 * map hardware resources.
     75                 *
     76                 * The kernel uses fixed 1:1 identity mapping
     77                 * of the physical memory with 2:2 GB split.
     78                 * This is a severe limitation of the current
     79                 * kernel memory management.
     80                 *
     81                 */
     82               
     83                if (base > PHYSMEM_LIMIT32)
    6584                        continue;
    6685               
    67                 /* Clip regions above 4 GB */
    68                 if (((base + size) >> 32) != 0)
    69                         size = 0xffffffff - base;
    70                
    71 #endif
    72                 pfn_t pfn;
    73                 size_t count;
     86                if (base + size > PHYSMEM_LIMIT32)
     87                        size = PHYSMEM_LIMIT32 - base;
     88#endif
     89               
     90#ifdef __64_BITS__
     91                /*
     92                 * XXX FIXME:
     93                 *
     94                 * Ignore zones which start above PHYSMEM_LIMIT64
     95                 * or clip zones which go beyond PHYSMEM_LIMIT64.
     96                 *
     97                 * The PHYSMEM_LIMIT64 (8 GB) is the size of the
     98                 * fixed 1:1 identically mapped physical memory
     99                 * accessible during the bootstrap process.
     100                 * This is a severe limitation of the current
     101                 * kernel memory management.
     102                 *
     103                 */
     104               
     105                if (base > PHYSMEM_LIMIT64)
     106                        continue;
     107               
     108                if (base + size > PHYSMEM_LIMIT64)
     109                        size = PHYSMEM_LIMIT64 - base;
     110#endif
    74111               
    75112                if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
    76                         /* To be safe, make available zone possibly smaller */
    77                         pfn = ADDR2PFN(ALIGN_UP(base, FRAME_SIZE));
    78                         count = SIZE2FRAMES(ALIGN_DOWN(size, FRAME_SIZE));
     113                        /* To be safe, make the available zone possibly smaller */
     114                        uint64_t new_base = ALIGN_UP(base, FRAME_SIZE);
     115                        uint64_t new_size = ALIGN_DOWN(size - (new_base - base),
     116                            FRAME_SIZE);
     117                       
     118                        pfn_t pfn = ADDR2PFN(new_base);
     119                        size_t count = SIZE2FRAMES(new_size);
    79120                       
    80121                        pfn_t conf;
     
    87128                       
    88129                        // XXX this has to be removed
    89                         if (last_frame < ALIGN_UP(base + size, FRAME_SIZE))
    90                                 last_frame = ALIGN_UP(base + size, FRAME_SIZE);
    91                 }
    92                
    93                 if (e820table[i].type == MEMMAP_MEMORY_RESERVED) {
    94                         /* To be safe, make reserved zone possibly larger */
    95                         pfn = ADDR2PFN(ALIGN_DOWN(base, FRAME_SIZE));
    96                         count = SIZE2FRAMES(ALIGN_UP(size, FRAME_SIZE));
    97                        
    98                         zone_create(pfn, count, 0, ZONE_RESERVED);
    99                 }
    100                
    101                 if (e820table[i].type == MEMMAP_MEMORY_ACPI) {
    102                         /* To be safe, make firmware zone possibly larger */
    103                         pfn = ADDR2PFN(ALIGN_DOWN(base, (uintptr_t) FRAME_SIZE));
    104                         count = SIZE2FRAMES(ALIGN_UP(size, (uintptr_t) FRAME_SIZE));
    105                        
    106                         zone_create(pfn, count, 0, ZONE_FIRMWARE);
     130                        if (last_frame < ALIGN_UP(new_base + new_size, FRAME_SIZE))
     131                                last_frame = ALIGN_UP(new_base + new_size, FRAME_SIZE);
     132                } else if ((e820table[i].type == MEMMAP_MEMORY_ACPI) ||
     133                    (e820table[i].type == MEMMAP_MEMORY_NVS)) {
     134                        /* To be safe, make the firmware zone possibly larger */
     135                        uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
     136                        uint64_t new_size = ALIGN_UP(size + (base - new_base),
     137                            FRAME_SIZE);
     138                       
     139                        zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
     140                            ZONE_FIRMWARE);
     141                } else {
     142                        /* To be safe, make the reserved zone possibly larger */
     143                        uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
     144                        uint64_t new_size = ALIGN_UP(size + (base - new_base),
     145                            FRAME_SIZE);
     146                       
     147                        zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
     148                            ZONE_RESERVED);
    107149                }
    108150        }
    109151}
    110152
    111 static char *e820names[] = {
     153static const char *e820names[] = {
    112154        "invalid",
    113155        "available",
     
    118160};
    119161
    120 
    121162void physmem_print(void)
    122163{
    123164        unsigned int i;
    124         char *name;
     165        printf("[base            ] [size            ] [name   ]\n");
    125166       
    126         printf("Base               Size               Name\n");
    127         printf("------------------ ------------------ ---------\n");
    128                
    129167        for (i = 0; i < e820counter; i++) {
     168                const char *name;
     169               
    130170                if (e820table[i].type <= MEMMAP_MEMORY_UNUSABLE)
    131171                        name = e820names[e820table[i].type];
     
    133173                        name = "invalid";
    134174               
    135                 printf("%#18llx %#18llx %s\n", e820table[i].base_address,
    136                         e820table[i].size, name);
     175                printf("%#018" PRIx64 " %#018" PRIx64" %s\n", e820table[i].base_address,
     176                    e820table[i].size, name);
    137177        }
    138178}
     
    148188#ifdef CONFIG_SMP
    149189                minconf = max(minconf,
    150                         ADDR2PFN(AP_BOOT_OFFSET + hardcoded_unmapped_ktext_size +
    151                         hardcoded_unmapped_kdata_size));
    152 #endif
     190                    ADDR2PFN(AP_BOOT_OFFSET + hardcoded_unmapped_ktext_size +
     191                    hardcoded_unmapped_kdata_size));
     192#endif
     193               
    153194                init_e820_memory(minconf);
    154195               
     
    158199#ifdef CONFIG_SMP
    159200                /* Reserve AP real mode bootstrap memory */
    160                 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH, 
    161                         (hardcoded_unmapped_ktext_size +
    162                         hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
     201                frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH,
     202                    (hardcoded_unmapped_ktext_size +
     203                    hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
    163204#endif
    164205        }
Note: See TracChangeset for help on using the changeset viewer.