Changeset 482f968 in mainline for kernel/generic/src


Ignore:
Timestamp:
2018-10-31T16:48:51Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
91a8f83, bab75df6
Parents:
37781819
Message:

Make FRAME_HIGHMEM fall back to low memory on failure.

Which is what existing users of it are doing, and there is no reason
not to as far as I can see.

Also make sure calls to frame_alloc all have either FRAME_LOWMEM or
FRAME_HIGHMEM explicitly set, as appropriate.

Location:
kernel/generic/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ddi/ddi.c

    r37781819 r482f968  
    385385                return EINVAL;
    386386
     387        // FIXME: probably need to ensure that the memory is suitable for DMA
    387388        *phys = frame_alloc(frames, FRAME_ATOMIC, constraint);
    388389        if (*phys == 0)
  • kernel/generic/src/mm/frame.c

    r37781819 r482f968  
    815815}
    816816
     817static size_t try_find_zone(size_t count, bool lowmem,
     818    pfn_t frame_constraint, size_t hint)
     819{
     820        if (!lowmem) {
     821                size_t znum = find_free_zone(count,
     822                    ZONE_HIGHMEM | ZONE_AVAILABLE, frame_constraint, hint);
     823                if (znum != (size_t) -1)
     824                        return znum;
     825        }
     826
     827        return find_free_zone(count, ZONE_LOWMEM | ZONE_AVAILABLE,
     828            frame_constraint, hint);
     829}
     830
    817831/** Allocate frames of physical memory.
    818832 *
     
    843857        irq_spinlock_lock(&zones.lock, true);
    844858
     859        // TODO: Print diagnostic if neither is explicitly specified.
     860        bool lowmem = (flags & FRAME_LOWMEM) || !(flags & FRAME_HIGHMEM);
     861
    845862        /*
    846863         * First, find suitable frame zone.
    847864         */
    848         size_t znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
    849             frame_constraint, hint);
     865        size_t znum = try_find_zone(count, lowmem, frame_constraint, hint);
    850866
    851867        /*
     
    859875
    860876                if (freed > 0)
    861                         znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
     877                        znum = try_find_zone(count, lowmem,
    862878                            frame_constraint, hint);
    863879
     
    868884
    869885                        if (freed > 0)
    870                                 znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
     886                                znum = try_find_zone(count, lowmem,
    871887                                    frame_constraint, hint);
    872888                }
  • kernel/generic/src/mm/km.c

    r37781819 r482f968  
    121121                return base;
    122122        else
    123                 return (uintptr_t) NULL;
     123                panic("Kernel ran out of virtual address space.");
    124124}
    125125
     
    256256        uintptr_t frame;
    257257
    258         frame = frame_alloc(1, FRAME_HIGHMEM | FRAME_ATOMIC | flags, 0);
    259         if (frame) {
     258        frame = frame_alloc(1, FRAME_HIGHMEM | flags, 0);
     259        if (frame >= config.identity_size) {
    260260                page = km_map(frame, PAGE_SIZE, PAGE_SIZE,
    261261                    PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
    262                 if (!page) {
    263                         frame_free(frame, 1);
    264                         goto lowmem;
    265                 }
    266262        } else {
    267         lowmem:
    268                 frame = frame_alloc(1, FRAME_LOWMEM | flags, 0);
    269                 if (!frame)
    270                         return (uintptr_t) NULL;
    271 
    272263                page = PA2KA(frame);
    273264        }
  • kernel/generic/src/mm/slab.c

    r37781819 r482f968  
    188188
    189189        uintptr_t data_phys =
    190             frame_alloc_generic(cache->frames, flags, 0, &zone);
     190            frame_alloc_generic(cache->frames, FRAME_LOWMEM | flags, 0, &zone);
    191191        if (!data_phys)
    192192                return NULL;
  • kernel/generic/src/time/clock.c

    r37781819 r482f968  
    8181void clock_counter_init(void)
    8282{
    83         uintptr_t faddr = frame_alloc(1, FRAME_ATOMIC, 0);
     83        uintptr_t faddr = frame_alloc(1, FRAME_LOWMEM | FRAME_ATOMIC, 0);
    8484        if (faddr == 0)
    8585                panic("Cannot allocate page for clock.");
Note: See TracChangeset for help on using the changeset viewer.