Changeset e49e234 in mainline for kernel/generic/src/mm/frame.c


Ignore:
Timestamp:
2009-02-27T11:32:31Z (16 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()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/frame.c

    r5f0f29ce re49e234  
    4949#include <debug.h>
    5050#include <adt/list.h>
    51 #include <synch/spinlock.h>
    5251#include <synch/mutex.h>
    5352#include <synch/condvar.h>
     
    6160#include <config.h>
    6261
    63 typedef struct {
    64         count_t refcount;     /**< Tracking of shared frames */
    65         uint8_t buddy_order;  /**< Buddy system block order */
    66         link_t buddy_link;    /**< Link to the next free block inside
    67                                one order */
    68         void *parent;         /**< If allocated by slab, this points there */
    69 } frame_t;
    70 
    71 typedef struct {
    72         pfn_t base;                    /**< Frame_no of the first frame
    73                                         in the frames array */
    74         count_t count;                 /**< Size of zone */
    75         count_t free_count;            /**< Number of free frame_t
    76                                         structures */
    77         count_t busy_count;            /**< Number of busy frame_t
    78                                         structures */
    79         zone_flags_t flags;            /**< Type of the zone */
    80        
    81         frame_t *frames;               /**< Array of frame_t structures
    82                                         in this zone */
    83         buddy_system_t *buddy_system;  /**< Buddy system for the zone */
    84 } zone_t;
    85 
    86 /*
    87  * The zoneinfo.lock must be locked when accessing zoneinfo structure.
    88  * Some of the attributes in zone_t structures are 'read-only'
    89  */
    90 typedef struct {
    91         SPINLOCK_DECLARE(lock);
    92         count_t count;
    93         zone_t info[ZONES_MAX];
    94 } zones_t;
    95 
    96 static zones_t zones;
     62zones_t zones;
    9763
    9864/*
     
    12793{
    12894        return (frame - zone->frames);
    129 }
    130 
    131 static inline bool zone_flags_available(zone_flags_t flags)
    132 {
    133         return ((flags & (ZONE_RESERVED | ZONE_FIRMWARE)) == 0);
    13495}
    13596
     
    181142        /* Move other zones up */
    182143        count_t j;
    183         for (j = i; j < zones.count; j++)
    184                 zones.info[j + 1] = zones.info[j];
     144        for (j = zones.count; j > i; j--) {
     145                zones.info[j] = zones.info[j - 1];
     146                zones.info[j].buddy_system->data =
     147                    (void *) &zones.info[j - 1];
     148        }
    185149       
    186150        zones.count++;
     
    207171}
    208172
    209 /** Find a zone with a given frame.
     173/** Find a zone with a given frames.
    210174 *
    211175 * Assume interrupts are disabled and zones lock is
     
    213177 *
    214178 * @param frame Frame number contained in zone.
     179 * @param count Number of frames to look for.
    215180 * @param hint  Used as zone hint.
    216181 *
     
    218183 *
    219184 */
    220 static count_t find_zone(pfn_t frame, count_t hint)
     185count_t find_zone(pfn_t frame, count_t count, count_t hint)
    221186{
    222187        if (hint >= zones.count)
     
    226191        do {
    227192                if ((zones.info[i].base <= frame)
    228                     && (zones.info[i].base + zones.info[i].count > frame))
     193                    && (zones.info[i].base + zones.info[i].count >= frame + count))
    229194                        return i;
    230195               
     
    766731            zones.info[z2].count);
    767732       
    768         /* Shift existing zones */
     733        /* Move zones down */
    769734        count_t i;
    770         for (i = z2 + 1; i < zones.count; i++)
     735        for (i = z2 + 1; i < zones.count; i++) {
    771736                zones.info[i - 1] = zones.info[i];
     737                zones.info[i - 1].buddy_system->data =
     738                    (void *) &zones.info[i - 1];
     739        }
     740       
    772741        zones.count--;
    773742       
     
    965934        spinlock_lock(&zones.lock);
    966935       
    967         count_t znum = find_zone(pfn, hint);
     936        count_t znum = find_zone(pfn, 1, hint);
    968937       
    969938        ASSERT(znum != (count_t) -1);
     
    981950        spinlock_lock(&zones.lock);
    982951       
    983         count_t znum = find_zone(pfn, hint);
     952        count_t znum = find_zone(pfn, 1, hint);
    984953       
    985954        ASSERT(znum != (count_t) -1);
     
    11121081         */
    11131082        pfn_t pfn = ADDR2PFN(frame);
    1114         count_t znum = find_zone(pfn, NULL);
     1083        count_t znum = find_zone(pfn, 1, NULL);
    11151084       
    11161085        ASSERT(znum != (count_t) -1);
     
    11511120         * First, find host frame zone for addr.
    11521121         */
    1153         count_t znum = find_zone(pfn, NULL);
     1122        count_t znum = find_zone(pfn, 1, NULL);
    11541123       
    11551124        ASSERT(znum != (count_t) -1);
     
    11691138        count_t i;
    11701139        for (i = 0; i < count; i++) {
    1171                 count_t znum = find_zone(start + i, 0);
     1140                count_t znum = find_zone(start + i, 1, 0);
    11721141                if (znum == (count_t) -1)  /* PFN not found */
    11731142                        continue;
     
    12381207{
    12391208#ifdef __32_BITS__
    1240         printf("#  base address flags    free frames  busy frames\n");
    1241         printf("-- ------------ -------- ------------ ------------\n");
     1209        printf("#  base address frames       flags    free frames  busy frames\n");
     1210        printf("-- ------------ ------------ -------- ------------ ------------\n");
    12421211#endif
    12431212
    12441213#ifdef __64_BITS__
    1245         printf("#  base address         flags    free frames  busy frames\n");
    1246         printf("-- -------------------- -------- ------------ ------------\n");
     1214        printf("#  base address          frames      flags    free frames  busy frames\n");
     1215        printf("-- -------------------- ------------ -------- ------------ ------------\n");
    12471216#endif
    12481217       
     
    12701239               
    12711240                uintptr_t base = PFN2ADDR(zones.info[i].base);
     1241                count_t count = zones.info[i].count;
    12721242                zone_flags_t flags = zones.info[i].flags;
    12731243                count_t free_count = zones.info[i].free_count;
     
    12791249                bool available = zone_flags_available(flags);
    12801250               
     1251                printf("%-2" PRIc, i);
     1252               
    12811253#ifdef __32_BITS__
    1282                 printf("%-2" PRIc "   %10p %c%c%c      ", i, base,
     1254                printf("   %10p", base);
     1255#endif
     1256               
     1257#ifdef __64_BITS__
     1258                printf("   %18p", base);
     1259#endif
     1260               
     1261                printf(" %12" PRIc " %c%c%c      ", count,
    12831262                    available ? 'A' : ' ',
    12841263                    (flags & ZONE_RESERVED) ? 'R' : ' ',
    12851264                    (flags & ZONE_FIRMWARE) ? 'F' : ' ');
    1286 #endif
    1287                
    1288 #ifdef __64_BITS__
    1289                 printf("%-2" PRIc "   %18p %c%c%c      ", i, base,
    1290                     available ? 'A' : ' ',
    1291                     (flags & ZONE_RESERVED) ? 'R' : ' ',
    1292                     (flags & ZONE_FIRMWARE) ? 'F' : ' ');
    1293 #endif
    12941265               
    12951266                if (available)
    12961267                        printf("%12" PRIc " %12" PRIc,
    12971268                            free_count, busy_count);
     1269               
    12981270                printf("\n");
    12991271        }
Note: See TracChangeset for help on using the changeset viewer.