Changeset f8ddd17 in mainline for uspace


Ignore:
Timestamp:
2006-12-09T20:20:50Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b82a13c
Parents:
9ab9c2ec
Message:

Rework support for virtually indexed cache.
Instead of repeatedly flushing the data cache, which was a huge overkill, refuse to create an illegal address alias
in the kernel (again) and allocate appropriate page color in userspace instead. Extend the detection also to
SYS_PHYSMEM_MAP syscall.

Add support for tracking physical memory areas mappable by SYS_PHYSMEM_MAP.

Lots of coding style changes.

Location:
uspace
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • uspace/fb/ega.c

    r9ab9c2ec rf8ddd17  
    3535 */
    3636
    37 
    3837#include <stdlib.h>
    3938#include <unistd.h>
     
    6362saved_screen saved_screens[MAX_SAVED_SCREENS];
    6463
    65 
    6664#define EGA_IO_ADDRESS 0x3d4
    6765#define EGA_IO_SIZE 2
     
    127125        int i;
    128126        if (rows > 0) {
    129                 memcpy (scr_addr,((char *)scr_addr) + rows * scr_width * 2, scr_width * scr_height * 2 - rows * scr_width * 2);
     127                memcpy (scr_addr,((char *)scr_addr) + rows * scr_width * 2,
     128                        scr_width * scr_height * 2 - rows * scr_width * 2);
    130129                for (i = 0; i < rows * scr_width ; i ++)
    131                         (((short *)scr_addr) + scr_width * scr_height - rows * scr_width) [i] = ((style << 8) + ' ');
     130                        (((short *)scr_addr) + scr_width * scr_height - rows *
     131                                scr_width) [i] = ((style << 8) + ' ');
    132132        } else if (rows < 0) {
    133 
    134                 memcpy (((char *)scr_addr) - rows * scr_width * 2 ,scr_addr ,scr_width * scr_height * 2 + rows * scr_width * 2);
     133                memcpy (((char *)scr_addr) - rows * scr_width * 2, scr_addr,
     134                        scr_width * scr_height * 2 + rows * scr_width * 2);
    135135                for (i = 0; i < - rows * scr_width ; i++)
    136136                        ((short *)scr_addr) [i] = ((style << 8 ) + ' ');
     
    309309        scr_width=sysinfo_value("fb.width");
    310310        scr_height=sysinfo_value("fb.height");
    311         iospace_enable(task_get_id(),(void *)EGA_IO_ADDRESS,2);
    312 
    313         sz = scr_width*scr_height*2;
    314         scr_addr = as_get_mappable_page(sz);
    315 
    316         physmem_map(ega_ph_addr, scr_addr, ALIGN_UP(sz, PAGE_SIZE) >> PAGE_WIDTH,
    317                     AS_AREA_READ | AS_AREA_WRITE);
     311        iospace_enable(task_get_id(), (void *) EGA_IO_ADDRESS, 2);
     312
     313        sz = scr_width * scr_height * 2;
     314        scr_addr = as_get_mappable_page(sz, (int)
     315                sysinfo_value("fb.address.color"));
     316
     317        physmem_map(ega_ph_addr, scr_addr, ALIGN_UP(sz, PAGE_SIZE) >>
     318                PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
    318319
    319320        async_set_client_connection(ega_client_connection);
  • uspace/fb/fb.c

    r9ab9c2ec rf8ddd17  
    705705                /* We accept one area for data interchange */
    706706                if (IPC_GET_ARG1(*call) == shm_id) {
    707                         void *dest = as_get_mappable_page(IPC_GET_ARG2(*call));
     707                        void *dest = as_get_mappable_page(IPC_GET_ARG2(*call),
     708                                PAGE_COLOR(IPC_GET_ARG1(*call)));
    708709                        shm_size = IPC_GET_ARG2(*call);
    709                         if (!ipc_answer_fast(callid, 0, (sysarg_t)dest, 0))
     710                        if (!ipc_answer_fast(callid, 0, (sysarg_t) dest, 0))
    710711                                shm = dest;
    711712                        else
     
    717718                } else {
    718719                        intersize = IPC_GET_ARG2(*call);
    719                         receive_comm_area(callid,call,(void *)&interbuffer);
     720                        receive_comm_area(callid, call, (void *) &interbuffer);
    720721                }
    721722                return 1;
     
    12831284
    12841285        asz = fb_scanline * fb_height;
    1285         fb_addr = as_get_mappable_page(asz);
     1286        fb_addr = as_get_mappable_page(asz, (int) sysinfo_value("fb.address.color"));
    12861287       
    12871288        physmem_map(fb_ph_addr, fb_addr, ALIGN_UP(asz, PAGE_SIZE) >> PAGE_WIDTH,
    12881289                    AS_AREA_READ | AS_AREA_WRITE);
    12891290
    1290         if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual, fb_invert_colors))
     1291        if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual,
     1292                fb_invert_colors))
    12911293                return 0;
    12921294       
  • uspace/fb/main.c

    r9ab9c2ec rf8ddd17  
    4444        void *dest;
    4545
    46         dest = as_get_mappable_page(IPC_GET_ARG2(*call));
     46        dest = as_get_mappable_page(IPC_GET_ARG2(*call),
     47                PAGE_COLOR(IPC_GET_ARG1(*call)));
    4748        if (ipc_answer_fast(callid, 0, (sysarg_t)dest, 0) == 0) {
    4849                if (*area)
  • uspace/klog/klog.c

    r9ab9c2ec rf8ddd17  
    6464        printf("Kernel console output.\n");
    6565       
    66         mapping = as_get_mappable_page(PAGE_SIZE);
     66        mapping = as_get_mappable_page(PAGE_SIZE, sysinfo_value("klog.fcolor"));
    6767        res = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_RECV,
    68                               (sysarg_t)mapping, PAGE_SIZE, SERVICE_MEM_KLOG,
    69                               NULL,NULL,NULL);
     68                              (sysarg_t) mapping, PAGE_SIZE, SERVICE_MEM_KLOG,
     69                              NULL, NULL, NULL);
    7070        if (res) {
    7171                printf("Failed to initialize klog memarea\n");
  • uspace/libc/arch/amd64/include/config.h

    r9ab9c2ec rf8ddd17  
    3838#define PAGE_WIDTH      12
    3939#define PAGE_SIZE       (1<<PAGE_WIDTH)
     40#define PAGE_COLOR_BITS 0               /* dummy */
    4041
    4142#endif
  • uspace/libc/arch/ia32/include/config.h

    r9ab9c2ec rf8ddd17  
    3838#define PAGE_WIDTH      12
    3939#define PAGE_SIZE       (1<<PAGE_WIDTH)
     40#define PAGE_COLOR_BITS 0               /* dummy */
    4041
    4142#endif
  • uspace/libc/arch/ia64/include/config.h

    r9ab9c2ec rf8ddd17  
    3838#define PAGE_WIDTH      14
    3939#define PAGE_SIZE       (1<<PAGE_WIDTH)
     40#define PAGE_COLOR_BITS 0               /* dummy */
    4041
    4142#endif
  • uspace/libc/arch/mips32/include/config.h

    r9ab9c2ec rf8ddd17  
    3838#define PAGE_WIDTH      14
    3939#define PAGE_SIZE       (1<<PAGE_WIDTH)
     40#define PAGE_COLOR_BITS 0               /* dummy */
    4041
    4142#endif
  • uspace/libc/arch/ppc32/include/config.h

    r9ab9c2ec rf8ddd17  
    3838#define PAGE_WIDTH      12
    3939#define PAGE_SIZE       (1<<PAGE_WIDTH)
     40#define PAGE_COLOR_BITS 0               /* dummy */
    4041
    4142#endif
  • uspace/libc/arch/ppc64/include/config.h

    r9ab9c2ec rf8ddd17  
    3838#define PAGE_WIDTH      12
    3939#define PAGE_SIZE       (1<<PAGE_WIDTH)
     40#define PAGE_COLOR_BITS 0               /* dummy */
    4041
    4142#endif
  • uspace/libc/arch/sparc64/include/config.h

    r9ab9c2ec rf8ddd17  
    3838#define PAGE_WIDTH      13
    3939#define PAGE_SIZE       (1<<PAGE_WIDTH)
     40#define PAGE_COLOR_BITS 1               /**< Bit 13 is the page color. */
    4041
    4142#endif
  • uspace/libc/generic/as.c

    r9ab9c2ec rf8ddd17  
    3838#include <align.h>
    3939#include <types.h>
     40#include <bitops.h>
    4041
    4142/**
     
    5455void *as_area_create(void *address, size_t size, int flags)
    5556{
    56         return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t ) address, (sysarg_t) size, (sysarg_t) flags);
     57        return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t ) address,
     58                (sysarg_t) size, (sysarg_t) flags);
    5759}
    5860
    5961/** Resize address space area.
    6062 *
    61  * @param address Virtual address pointing into already existing address space area.
     63 * @param address Virtual address pointing into already existing address space
     64 *      area.
    6265 * @param size New requested size of the area.
    6366 * @param flags Currently unused.
     
    6770int as_area_resize(void *address, size_t size, int flags)
    6871{
    69         return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t ) address, (sysarg_t) size, (sysarg_t) flags);
     72        return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t ) address, (sysarg_t)
     73                size, (sysarg_t) flags);
    7074}
    7175
    7276/** Destroy address space area.
    7377 *
    74  * @param address Virtual address pointing into the address space area being destroyed.
     78 * @param address Virtual address pointing into the address space area being
     79 *      destroyed.
    7580 *
    7681 * @return Zero on success or a code from @ref errno.h on failure.
     
    134139        /* Return pointer to area not managed by sbrk */
    135140        return ((void *) &_heap + maxheapsize);
    136 
    137141}
    138142
    139143/** Return pointer to some unmapped area, where fits new as_area
    140144 *
     145 * @param sz Requested size of the allocation.
     146 * @param color Requested virtual color of the allocation.
     147 *
     148 * @return Pointer to the beginning
     149 *
    141150 * TODO: make some first_fit/... algorithm, we are now just incrementing
    142151 *       the pointer to last area
    143152 */
    144 void * as_get_mappable_page(size_t sz)
     153#include <stdio.h>
     154void *as_get_mappable_page(size_t sz, int color)
    145155{
    146156        void *res;
     157        uint64_t asz;
     158        int i;
     159       
     160        if (!sz)
     161                return NULL;   
     162
     163        asz = 1 << (fnzb64(sz - 1) + 1);
    147164
    148165        /* Set heapsize to some meaningful value */
     
    150167                set_maxheapsize(MAX_HEAP_SIZE);
    151168       
    152         if (!last_allocated)
    153                 last_allocated = (void *) ALIGN_UP((void *) &_heap + maxheapsize, PAGE_SIZE);
    154        
    155         sz = ALIGN_UP(sz, PAGE_SIZE);
     169        /*
     170         * Make sure we allocate from naturally aligned address and a page of
     171         * appropriate color.
     172         */
     173        i = 0;
     174        do {
     175                if (!last_allocated) {
     176                        last_allocated = (void *) ALIGN_UP((void *) &_heap +
     177                                maxheapsize, asz);
     178                } else {
     179                        last_allocated = (void *) ALIGN_UP(((uintptr_t)
     180                                last_allocated) + (int) (i > 0), asz);
     181                }
     182        } while ((asz < (1 << (PAGE_COLOR_BITS + PAGE_WIDTH))) &&
     183                (PAGE_COLOR((uintptr_t) last_allocated) != color) &&
     184                (++i < (1 << PAGE_COLOR_BITS)));
     185
    156186        res = last_allocated;
    157         last_allocated += sz;
     187        last_allocated += ALIGN_UP(sz, PAGE_SIZE);
    158188
    159189        return res;
  • uspace/libc/generic/mman.c

    r9ab9c2ec rf8ddd17  
    4040{
    4141        if (!start)
    42                 start = as_get_mappable_page(length);
     42                start = as_get_mappable_page(length, 0);
    4343       
    4444//      if (! ((flags & MAP_SHARED) ^ (flags & MAP_PRIVATE)))
  • uspace/libc/generic/time.c

    r9ab9c2ec rf8ddd17  
    4141#include <atomic.h>
    4242#include <futex.h>
     43#include <sysinfo.h>
    4344#include <ipc/services.h>
    4445
     
    7273
    7374        if (!ktime) {
    74                 mapping = as_get_mappable_page(PAGE_SIZE);
     75                mapping = as_get_mappable_page(PAGE_SIZE, (int)
     76                        sysinfo_value("clock.fcolor"));
    7577                /* Get the mapping of kernel clock */
    76                 res = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_RECV, (sysarg_t) mapping, PAGE_SIZE, SERVICE_MEM_REALTIME, NULL, &rights, NULL);
     78                res = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_RECV, (sysarg_t)
     79                        mapping, PAGE_SIZE, SERVICE_MEM_REALTIME, NULL, &rights,
     80                        NULL);
    7781                if (res) {
    7882                        printf("Failed to initialize timeofday memarea\n");
  • uspace/libc/include/as.h

    r9ab9c2ec rf8ddd17  
    4040#include <kernel/arch/mm/as.h>
    4141#include <kernel/mm/as.h>
     42#include <libarch/config.h>
     43
     44#define PAGE_COLOR(va)  (((va) >> PAGE_WIDTH) & ((1 << PAGE_COLOR_BITS) - 1))
    4245
    4346extern void *as_area_create(void *address, size_t size, int flags);
     
    4548extern int as_area_destroy(void *address);
    4649extern void *set_maxheapsize(size_t mhs);
    47 extern void * as_get_mappable_page(size_t sz);
     50extern void * as_get_mappable_page(size_t sz, int color);
    4851
    4952#endif
  • uspace/ns/ns.c

    r9ab9c2ec rf8ddd17  
    8484static void *klogaddr = NULL;
    8585
    86 static void get_as_area(ipc_callid_t callid, ipc_call_t *call, char *name, void **addr)
     86static void get_as_area(ipc_callid_t callid, ipc_call_t *call, char *name, char *colstr, void **addr)
    8787{
    8888        void *ph_addr;
     89        int ph_color;
    8990
    9091        if (!*addr) {
    91                 ph_addr = (void *)sysinfo_value(name);
     92                ph_addr = (void *) sysinfo_value(name);
    9293                if (!ph_addr) {
    9394                        ipc_answer_fast(callid, ENOENT, 0, 0);
    9495                        return;
    9596                }
    96                 *addr = as_get_mappable_page(PAGE_SIZE);
     97                ph_color = (int) sysinfo_value(colstr);
     98                *addr = as_get_mappable_page(PAGE_SIZE, ph_color);
    9799                physmem_map(ph_addr, *addr, 1, AS_AREA_READ | AS_AREA_CACHEABLE);
    98100        }
     
    117119                        switch (IPC_GET_ARG3(call)) {
    118120                        case SERVICE_MEM_REALTIME:
    119                                 get_as_area(callid, &call, "clock.faddr", &clockaddr);
     121                                get_as_area(callid, &call, "clock.faddr",
     122                                        "clock.fcolor", &clockaddr);
    120123                                break;
    121124                        case SERVICE_MEM_KLOG:
    122                                 get_as_area(callid, &call, "klog.faddr", &klogaddr);
     125                                get_as_area(callid, &call, "klog.faddr",
     126                                        "klog.fcolor", &klogaddr);
    123127                                break;
    124128                        default:
  • uspace/rd/rd.c

    r9ab9c2ec rf8ddd17  
    7474        size_t rd_size = sysinfo_value("rd.size");
    7575        void * rd_ph_addr = (void *) sysinfo_value("rd.address.physical");
     76        int rd_color = (int) sysinfo_value("rd.address.color");
    7677       
    7778        if (rd_size == 0)
    7879                return false;
    7980       
    80         void * rd_addr = as_get_mappable_page(rd_size);
     81        void * rd_addr = as_get_mappable_page(rd_size, rd_color);
    8182       
    8283        physmem_map(rd_ph_addr, rd_addr, ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE);
Note: See TracChangeset for help on using the changeset viewer.