Changeset e6c4b94 in mainline


Ignore:
Timestamp:
2011-11-16T19:52:33Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fadb07a
Parents:
19c8030
Message:

Adjust matching of zone flags to suport low/high memory distinction.

  • Make ZONE_AVAILABLE a non-zero bit.
  • Remove zone_flags_available().
  • Define portion of the zone flag bits that need to match exactly. The rest of the bits in the flags need not match exactly.
  • Add FRAME_HIGHMEM and ZONE_HIGHMEM.
Location:
kernel
Files:
3 edited

Legend:

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

    r19c8030 re6c4b94  
    8888
    8989        zone_create(ADDR2PFN(config.identity_size), frames, conf,
    90             ZONE_AVAILABLE);
     90            ZONE_AVAILABLE | ZONE_HIGHMEM);
    9191}
    9292
  • kernel/generic/include/mm/frame.h

    r19c8030 re6c4b94  
    5050typedef uint8_t frame_flags_t;
    5151
     52#define FRAME_NONE        0x0
    5253/** Convert the frame address to kernel VA. */
    5354#define FRAME_KA          0x1
     
    6061/** Allocate a frame which can be identity-mapped. */
    6162#define FRAME_LOWMEM      0x10
     63/** Allocate a frame which cannot be identity-mapped. */
     64#define FRAME_HIGHMEM     0x20
    6265
    6366typedef uint8_t zone_flags_t;
    6467
     68#define ZONE_NONE       0x0
    6569/** Available zone (free for allocation) */
    66 #define ZONE_AVAILABLE  0x0
     70#define ZONE_AVAILABLE  0x1
    6771/** Zone is reserved (not available for allocation) */
    68 #define ZONE_RESERVED   0x8
     72#define ZONE_RESERVED   0x2
    6973/** Zone is used by firmware (not available for allocation) */
    70 #define ZONE_FIRMWARE   0x10
     74#define ZONE_FIRMWARE   0x4
    7175/** Zone contains memory that can be identity-mapped */
    72 #define ZONE_LOWMEM     0x20
     76#define ZONE_LOWMEM     0x8
     77/** Zone contains memory that cannot be identity-mapped */
     78#define ZONE_HIGHMEM    0x10
    7379
    74 #define FRAME_TO_ZONE_FLAGS(ff) (((ff) & FRAME_LOWMEM) ? ZONE_LOWMEM : 0)
     80/** Mask of zone bits that must be matched exactly. */
     81#define ZONE_EF_MASK    0x7
     82
     83#define FRAME_TO_ZONE_FLAGS(ff) \
     84        ((((ff) & FRAME_LOWMEM) ? ZONE_LOWMEM : \
     85            (((ff) & FRAME_HIGHMEM) ? ZONE_HIGHMEM : ZONE_NONE)) | \
     86            (ZONE_AVAILABLE | ZONE_LOWMEM | ZONE_HIGHMEM))
     87
     88#define ZONE_FLAGS_MATCH(zf, f) \
     89        (((((zf) & ZONE_EF_MASK)) == ((f) & ZONE_EF_MASK)) && \
     90            (((zf) & ~ZONE_EF_MASK) & (f)))
    7591
    7692typedef struct {
     
    131147}
    132148
    133 NO_TRACE static inline bool zone_flags_available(zone_flags_t flags)
    134 {
    135         return ((flags & (ZONE_RESERVED | ZONE_FIRMWARE)) == 0);
    136 }
    137 
    138149#define IS_BUDDY_ORDER_OK(index, order) \
    139150    ((~(((sysarg_t) -1) << (order)) & (index)) == 0)
  • kernel/generic/src/mm/frame.c

    r19c8030 re6c4b94  
    240240NO_TRACE static bool zone_can_alloc(zone_t *zone, uint8_t order)
    241241{
    242         return (zone_flags_available(zone->flags)
    243             && buddy_system_can_alloc(zone->buddy_system, order));
     242        return ((zone->flags & ZONE_AVAILABLE) &&
     243            buddy_system_can_alloc(zone->buddy_system, order));
    244244}
    245245
     
    265265                 * Check whether the zone meets the search criteria.
    266266                 */
    267                 if ((zones.info[i].flags & flags) == flags) {
     267                if (ZONE_FLAGS_MATCH(zones.info[i].flags, flags)) {
    268268                        /*
    269269                         * Check if the zone has 2^order frames area available.
     
    460460NO_TRACE static pfn_t zone_frame_alloc(zone_t *zone, uint8_t order)
    461461{
    462         ASSERT(zone_flags_available(zone->flags));
     462        ASSERT(zone->flags & ZONE_AVAILABLE);
    463463       
    464464        /* Allocate frames from zone buddy system */
     
    490490NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx)
    491491{
    492         ASSERT(zone_flags_available(zone->flags));
     492        ASSERT(zone->flags & ZONE_AVAILABLE);
    493493       
    494494        frame_t *frame = &zone->frames[frame_idx];
     
    518518NO_TRACE static void zone_mark_unavailable(zone_t *zone, size_t frame_idx)
    519519{
    520         ASSERT(zone_flags_available(zone->flags));
     520        ASSERT(zone->flags & ZONE_AVAILABLE);
    521521       
    522522        frame_t *frame = zone_get_frame(zone, frame_idx);
     
    549549    buddy_system_t *buddy)
    550550{
    551         ASSERT(zone_flags_available(zones.info[z1].flags));
    552         ASSERT(zone_flags_available(zones.info[z2].flags));
     551        ASSERT(zones.info[z1].flags & ZONE_AVAILABLE);
     552        ASSERT(zones.info[z2].flags & ZONE_AVAILABLE);
    553553        ASSERT(zones.info[z1].flags == zones.info[z2].flags);
    554554        ASSERT(zones.info[z1].base < zones.info[z2].base);
     
    645645NO_TRACE static void return_config_frames(size_t znum, pfn_t pfn, size_t count)
    646646{
    647         ASSERT(zone_flags_available(zones.info[znum].flags));
     647        ASSERT(zones.info[znum].flags & ZONE_AVAILABLE);
    648648       
    649649        size_t cframes = SIZE2FRAMES(zone_conf_size(count));
     
    681681    size_t count)
    682682{
    683         ASSERT(zone_flags_available(zones.info[znum].flags));
     683        ASSERT(zones.info[znum].flags & ZONE_AVAILABLE);
    684684        ASSERT(frame_idx + count < zones.info[znum].count);
    685685       
     
    723723         * set of flags
    724724         */
    725         if ((z1 >= zones.count) || (z2 >= zones.count)
    726             || (z2 - z1 != 1)
    727             || (!zone_flags_available(zones.info[z1].flags))
    728             || (!zone_flags_available(zones.info[z2].flags))
    729             || (zones.info[z1].flags != zones.info[z2].flags)) {
     725        if ((z1 >= zones.count) || (z2 >= zones.count) || (z2 - z1 != 1) ||
     726            (zones.info[z1].flags != zones.info[z2].flags)) {
    730727                ret = false;
    731728                goto errout;
     
    828825        zone->buddy_system = buddy;
    829826       
    830         if (zone_flags_available(flags)) {
     827        if (flags & ZONE_AVAILABLE) {
    831828                /*
    832829                 * Compute order for buddy system and initialize
     
    897894        irq_spinlock_lock(&zones.lock, true);
    898895       
    899         if (zone_flags_available(flags)) {  /* Create available zone */
     896        if (flags & ZONE_AVAILABLE) {  /* Create available zone */
    900897                /* Theoretically we could have NULL here, practically make sure
    901898                 * nobody tries to do that. If some platform requires, remove
     
    13031300                *total += (uint64_t) FRAMES2SIZE(zones.info[i].count);
    13041301               
    1305                 if (zone_flags_available(zones.info[i].flags)) {
     1302                if (zones.info[i].flags & ZONE_AVAILABLE) {
    13061303                        *busy += (uint64_t) FRAMES2SIZE(zones.info[i].busy_count);
    13071304                        *free += (uint64_t) FRAMES2SIZE(zones.info[i].free_count);
     
    13541351                irq_spinlock_unlock(&zones.lock, true);
    13551352               
    1356                 bool available = zone_flags_available(flags);
     1353                bool available = ((flags & ZONE_AVAILABLE) != 0);
    13571354               
    13581355                printf("%-4zu", i);
     
    13661363#endif
    13671364               
    1368                 printf(" %12zu %c%c%c      ", count,
    1369                     available ? 'A' : ' ',
    1370                     (flags & ZONE_RESERVED) ? 'R' : ' ',
    1371                     (flags & ZONE_FIRMWARE) ? 'F' : ' ');
     1365                printf(" %12zu %c%c%c%c%c    ", count,
     1366                    available ? 'A' : '-',
     1367                    (flags & ZONE_RESERVED) ? 'R' : '-',
     1368                    (flags & ZONE_FIRMWARE) ? 'F' : '-',
     1369                    (flags & ZONE_LOWMEM) ? 'L' : '-',
     1370                    (flags & ZONE_HIGHMEM) ? 'H' : '-');
    13721371               
    13731372                if (available)
     
    14111410        irq_spinlock_unlock(&zones.lock, true);
    14121411       
    1413         bool available = zone_flags_available(flags);
     1412        bool available = ((flags & ZONE_AVAILABLE) != 0);
    14141413       
    14151414        uint64_t size;
     
    14211420        printf("Zone size:         %zu frames (%" PRIu64 " %s)\n", count,
    14221421            size, size_suffix);
    1423         printf("Zone flags:        %c%c%c\n",
    1424             available ? 'A' : ' ',
    1425             (flags & ZONE_RESERVED) ? 'R' : ' ',
    1426             (flags & ZONE_FIRMWARE) ? 'F' : ' ');
     1422        printf("Zone flags:        %c%c%c%c%c\n",
     1423            available ? 'A' : '-',
     1424            (flags & ZONE_RESERVED) ? 'R' : '-',
     1425            (flags & ZONE_FIRMWARE) ? 'F' : '-',
     1426            (flags & ZONE_LOWMEM) ? 'L' : '-',
     1427            (flags & ZONE_HIGHMEM) ? 'H' : '-');
    14271428       
    14281429        if (available) {
Note: See TracChangeset for help on using the changeset viewer.