Changeset e49e234 in mainline for kernel/arch/ia32


Ignore:
Timestamp:
2009-02-27T11:32:31Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c1f7f6ea
Parents:
5f0f29ce
Message:

kernel memory management revisited (phase 2): map physical memory according to zones

  • ia32: register reserved and ACPI zones
  • pareas are now used only for mapping of present physical memory (hw_area() is gone)
  • firmware zones and physical addresses outside any zones are allowed to be mapped generally
  • fix nasty antient bug in zones_insert_zone()
Location:
kernel/arch/ia32
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/include/boot/memmap.h

    r5f0f29ce re49e234  
    2727 */
    2828
    29 /** @addtogroup ia32   
     29/** @addtogroup ia32
    3030 * @{
    3131 */
     
    3636#define KERN_ia32_MEMMAP_H_
    3737
    38 /* E820h memory range types - other values*/
    39         /* Free memory */
    40 #define MEMMAP_MEMORY_AVAILABLE 1
    41         /* Not available for OS */
    42 #define MEMMAP_MEMORY_RESERVED  2
    43         /* OS may use it after reading ACPI table */
    44 #define MEMMAP_MEMORY_ACPI      3
    45         /* Unusable, required to be saved and restored across an NVS sleep */
    46 #define MEMMAP_MEMORY_NVS       4
    47         /* Corrupted memory */
    48 #define MEMMAP_MEMORY_UNUSABLE  5
     38/* E820h memory range types */
    4939
    50          /* size of one entry */
    51 #define MEMMAP_E820_RECORD_SIZE 20
    52         /* maximum entries */
    53 #define MEMMAP_E820_MAX_RECORDS 32
     40/* Free memory */
     41#define MEMMAP_MEMORY_AVAILABLE  1
    5442
     43/* Not available for OS */
     44#define MEMMAP_MEMORY_RESERVED   2
     45
     46/* OS may use it after reading ACPI table */
     47#define MEMMAP_MEMORY_ACPI       3
     48
     49/* Unusable, required to be saved and restored across an NVS sleep */
     50#define MEMMAP_MEMORY_NVS        4
     51
     52/* Corrupted memory */
     53#define MEMMAP_MEMORY_UNUSABLE   5
     54
     55/* Size of one entry */
     56#define MEMMAP_E820_RECORD_SIZE  20
     57
     58/* Maximum entries */
     59#define MEMMAP_E820_MAX_RECORDS  32
    5560
    5661#ifndef __ASM__
  • kernel/arch/ia32/include/mm/frame.h

    r5f0f29ce re49e234  
    2727 */
    2828
    29 /** @addtogroup ia32mm 
     29/** @addtogroup ia32mm
    3030 * @{
    3131 */
     
    3636#define KERN_ia32_FRAME_H_
    3737
    38 #define FRAME_WIDTH     12      /* 4K */
    39 #define FRAME_SIZE      (1 << FRAME_WIDTH)
     38#define FRAME_WIDTH  12  /* 4K */
     39#define FRAME_SIZE   (1 << FRAME_WIDTH)
    4040
    4141#ifdef KERNEL
     
    4545
    4646extern uintptr_t last_frame;
    47 extern uintptr_t end_frame;
    4847
    4948extern void frame_arch_init(void);
  • kernel/arch/ia32/src/mm/frame.c

    r5f0f29ce re49e234  
    5151
    5252uintptr_t last_frame = 0;
    53 uintptr_t end_frame = 0;
    5453
    5554static void init_e820_memory(pfn_t minconf)
    5655{
    5756        unsigned int i;
    58         pfn_t start, conf;
    59         size_t size;
    60        
    6157        for (i = 0; i < e820counter; i++) {
     58                uint64_t base = e820table[i].base_address;
     59                uint64_t size = e820table[i].size;
     60               
     61#ifdef __32_BITS__
     62               
     63                /* Ignore physical memory above 4 GB */
     64                if ((base >> 32) != 0)
     65                        continue;
     66               
     67                /* Clip regions above 4 GB */
     68                if (((base + size) >> 32) != 0)
     69                        size = 0xffffffff - base;
     70               
     71#endif
     72                pfn_t pfn;
     73                count_t count;
     74               
    6275                if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
    63                         start = ADDR2PFN(ALIGN_UP(e820table[i].base_address, FRAME_SIZE));
    64                         size = SIZE2FRAMES(ALIGN_DOWN(e820table[i].size, FRAME_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));
    6579                       
    66                         if ((minconf < start) || (minconf >= start + size))
    67                                 conf = start;
     80                        pfn_t conf;
     81                        if ((minconf < pfn) || (minconf >= pfn + count))
     82                                conf = pfn;
    6883                        else
    6984                                conf = minconf;
    7085                       
    71                         zone_create(start, size, conf, 0);
     86                        zone_create(pfn, count, conf, ZONE_AVAILABLE);
    7287                       
    73                         if (last_frame < ALIGN_UP(e820table[i].base_address +
    74                             e820table[i].size, FRAME_SIZE))
    75                                 last_frame =
    76                                     ALIGN_UP(e820table[i].base_address + e820table[i].size, FRAME_SIZE);
     88                        // 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);
    77107                }
    78108        }
    79        
    80         end_frame = last_frame;
    81109}
    82110
  • kernel/arch/ia32/src/mm/page.c

    r5f0f29ce re49e234  
    3535#include <arch/mm/page.h>
    3636#include <genarch/mm/page_pt.h>
    37 #include <genarch/drivers/ega/ega.h>
    38 #include <genarch/drivers/legacy/ia32/io.h>
    3937#include <arch/mm/frame.h>
    4038#include <mm/frame.h>
     
    5149#include <print.h>
    5250#include <interrupt.h>
    53 #include <ddi/ddi.h>
    54 
    55 /** Physical memory area for devices. */
    56 static parea_t dev_area;
    57 static parea_t ega_area;
    5851
    5952void page_arch_init(void)
     
    6154        uintptr_t cur;
    6255        int flags;
    63 
     56       
    6457        if (config.cpu_active == 1) {
    6558                page_mapping_operations = &pt_mapping_operations;
     
    7467                        page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
    7568                }
    76 
     69               
    7770                exc_register(14, "page_fault", (iroutine) page_fault);
    7871                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    7972        } else
    8073                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    81 
     74       
    8275        paging_on();
    8376}
     
    9992       
    10093        return virtaddr;
    101 }
    102 
    103 void hw_area(void)
    104 {
    105         dev_area.pbase = end_frame;
    106         dev_area.frames = SIZE2FRAMES(0xffffffff - end_frame);
    107         ddi_parea_register(&dev_area);
    108        
    109         ega_area.pbase = EGA_VIDEORAM;
    110         ega_area.frames = SIZE2FRAMES(EGA_VRAM_SIZE);
    111         ddi_parea_register(&ega_area);
    11294}
    11395
Note: See TracChangeset for help on using the changeset viewer.