Changeset a1b9f63 in mainline for kernel/generic/src


Ignore:
Timestamp:
2018-08-31T10:32:40Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6bf5b8c
Parents:
b1834a01
git-author:
Jakub Jermar <jakub@…> (2018-08-31 09:54:11)
git-committer:
Jakub Jermar <jakub@…> (2018-08-31 10:32:40)
Message:

Add alignment argument to km_map()

km_map() currently always applies alignment requirement equal to the
size of the mapped region. Most of the time, the natural alignment is
unnecessarily strong and especially on 32-bit systems may contribute to
km_map() failures for regions with size in the order of several hundred
megabytes.

This change adds an extra argument to km_map() which allows the caller
to indicate the desired alignment. The old behaviour can be specified
by passing KM_NATURAL_ALIGNMENT as alignment.

This change only adds the alignment argument, but does not change the
alignment requirement anywhere.

Location:
kernel/generic/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/cmd.c

    rb1834a01 ra1b9f63  
    728728#endif
    729729                ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
    730                     PAGE_NOT_CACHEABLE);
     730                    PAGE_SIZE, PAGE_NOT_CACHEABLE);
    731731
    732732        const uint8_t val = pio_read_8(ptr);
     
    758758#endif
    759759                ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
    760                     PAGE_NOT_CACHEABLE);
     760                    PAGE_SIZE, PAGE_NOT_CACHEABLE);
    761761
    762762        const uint16_t val = pio_read_16(ptr);
     
    788788#endif
    789789                ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
    790                     PAGE_NOT_CACHEABLE);
     790                    PAGE_SIZE, PAGE_NOT_CACHEABLE);
    791791
    792792        const uint32_t val = pio_read_32(ptr);
     
    818818#endif
    819819                ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
    820                     PAGE_NOT_CACHEABLE);
     820                    PAGE_SIZE, PAGE_NOT_CACHEABLE);
    821821
    822822        printf("write %" PRIxn ": %" PRIx8 "\n", argv[0].intval,
     
    849849#endif
    850850                ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
    851                     PAGE_NOT_CACHEABLE);
     851                    PAGE_SIZE, PAGE_NOT_CACHEABLE);
    852852
    853853        printf("write %" PRIxn ": %" PRIx16 "\n", argv[0].intval,
     
    880880#endif
    881881                ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
    882                     PAGE_NOT_CACHEABLE);
     882                    PAGE_SIZE, PAGE_NOT_CACHEABLE);
    883883
    884884        printf("write %" PRIxn ": %" PRIx32 "\n", argv[0].intval,
  • kernel/generic/src/ipc/irq.c

    rb1834a01 ra1b9f63  
    9595#endif
    9696                ranges[i].base = km_map(pbase[i], ranges[i].size,
     97                    KM_NATURAL_ALIGNMENT,
    9798                    PAGE_READ | PAGE_WRITE | PAGE_KERNEL | PAGE_NOT_CACHEABLE);
    9899                if (!ranges[i].base) {
  • kernel/generic/src/main/kinit.c

    rb1834a01 ra1b9f63  
    249249                 */
    250250                uintptr_t page = km_map(init.tasks[i].paddr,
    251                     init.tasks[i].size,
     251                    init.tasks[i].size, KM_NATURAL_ALIGNMENT,
    252252                    PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
    253253                assert(page);
  • kernel/generic/src/mm/km.c

    rb1834a01 ra1b9f63  
    130130
    131131static uintptr_t
    132 km_map_aligned(uintptr_t paddr, size_t size, unsigned int flags)
     132km_map_aligned(uintptr_t paddr, size_t size, size_t align, unsigned int flags)
    133133{
    134134        uintptr_t vaddr;
    135         size_t align;
    136135        uintptr_t offs;
     136
     137        if (align == KM_NATURAL_ALIGNMENT)
     138                align = ispwr2(size) ? size : (1U << (fnzb(size) + 1));
    137139
    138140        assert(ALIGN_DOWN(paddr, FRAME_SIZE) == paddr);
    139141        assert(ALIGN_UP(size, FRAME_SIZE) == size);
    140 
    141         /* Enforce natural or at least PAGE_SIZE alignment. */
    142         align = ispwr2(size) ? size : (1U << (fnzb(size) + 1));
     142        assert(ispwr2(align));
     143
     144        /* Enforce at least PAGE_SIZE alignment. */
    143145        vaddr = km_page_alloc(size, max(PAGE_SIZE, align));
    144146
     
    185187 * @return New virtual address mapped to paddr.
    186188 */
    187 uintptr_t km_map(uintptr_t paddr, size_t size, unsigned int flags)
     189uintptr_t km_map(uintptr_t paddr, size_t size, size_t align, unsigned int flags)
    188190{
    189191        uintptr_t page;
     
    192194        offs = paddr - ALIGN_DOWN(paddr, FRAME_SIZE);
    193195        page = km_map_aligned(ALIGN_DOWN(paddr, FRAME_SIZE),
    194             ALIGN_UP(size + offs, FRAME_SIZE), flags);
     196            ALIGN_UP(size + offs, FRAME_SIZE), align, flags);
    195197
    196198        return page + offs;
     
    256258        frame = frame_alloc(1, FRAME_HIGHMEM | FRAME_ATOMIC | flags, 0);
    257259        if (frame) {
    258                 page = km_map(frame, PAGE_SIZE,
     260                page = km_map(frame, PAGE_SIZE, PAGE_SIZE,
    259261                    PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
    260262                if (!page) {
Note: See TracChangeset for help on using the changeset viewer.