Ignore:
File:
1 edited

Legend:

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

    rdc0b964 r98000fb  
    2727 */
    2828
    29 /** @addtogroup ia32mm
     29/** @addtogroup ia32mm 
    3030 * @{
    3131 */
     
    4444#include <align.h>
    4545#include <macros.h>
     46
    4647#include <print.h>
    47 
    48 #define PHYSMEM_LIMIT32  UINT64_C(0x07c000000)
    49 #define PHYSMEM_LIMIT64  UINT64_C(0x200000000)
    5048
    5149size_t hardcoded_unmapped_ktext_size = 0;
     
    5755{
    5856        unsigned int i;
    59        
    6057        for (i = 0; i < e820counter; i++) {
    6158                uint64_t base = e820table[i].base_address;
     
    6360               
    6461#ifdef __32_BITS__
    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                  */
    8262               
    83                 if (base > PHYSMEM_LIMIT32)
     63                /* Ignore physical memory above 4 GB */
     64                if ((base >> 32) != 0)
    8465                        continue;
    8566               
    86                 if (base + size > PHYSMEM_LIMIT32)
    87                         size = PHYSMEM_LIMIT32 - base;
     67                /* Clip regions above 4 GB */
     68                if (((base + size) >> 32) != 0)
     69                        size = 0xffffffff - base;
     70               
    8871#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
     72                pfn_t pfn;
     73                size_t count;
    11174               
    11275                if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
    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);
     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));
    12079                       
    12180                        pfn_t conf;
     
    12887                       
    12988                        // XXX this has to be removed
    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);
     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));
    13897                       
    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);
     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));
    146105                       
    147                         zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
    148                             ZONE_RESERVED);
     106                        zone_create(pfn, count, 0, ZONE_FIRMWARE);
    149107                }
    150108        }
    151109}
    152110
    153 static const char *e820names[] = {
     111static char *e820names[] = {
    154112        "invalid",
    155113        "available",
     
    160118};
    161119
     120
    162121void physmem_print(void)
    163122{
    164123        unsigned int i;
    165         printf("[base            ] [size            ] [name   ]\n");
     124        char *name;
    166125       
     126        printf("Base               Size               Name\n");
     127        printf("------------------ ------------------ ---------\n");
     128               
    167129        for (i = 0; i < e820counter; i++) {
    168                 const char *name;
    169                
    170130                if (e820table[i].type <= MEMMAP_MEMORY_UNUSABLE)
    171131                        name = e820names[e820table[i].type];
     
    173133                        name = "invalid";
    174134               
    175                 printf("%#018" PRIx64 " %#018" PRIx64" %s\n", e820table[i].base_address,
    176                     e820table[i].size, name);
     135                printf("%#18llx %#18llx %s\n", e820table[i].base_address,
     136                        e820table[i].size, name);
    177137        }
    178138}
     
    188148#ifdef CONFIG_SMP
    189149                minconf = max(minconf,
    190                     ADDR2PFN(AP_BOOT_OFFSET + hardcoded_unmapped_ktext_size +
    191                     hardcoded_unmapped_kdata_size));
     150                        ADDR2PFN(AP_BOOT_OFFSET + hardcoded_unmapped_ktext_size +
     151                        hardcoded_unmapped_kdata_size));
    192152#endif
    193                
    194153                init_e820_memory(minconf);
    195154               
     
    199158#ifdef CONFIG_SMP
    200159                /* Reserve AP real mode bootstrap memory */
    201                 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH,
    202                     (hardcoded_unmapped_ktext_size +
    203                     hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
     160                frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH, 
     161                        (hardcoded_unmapped_ktext_size +
     162                        hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
    204163#endif
    205164        }
Note: See TracChangeset for help on using the changeset viewer.