Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset bf9cb2f in mainline


Ignore:
Timestamp:
2014-05-19T01:01:27Z (8 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
10ef47ba
Parents:
527f1ca
Message:

complete the desired API semantics of physmem_map() and dmamem_map_anonymous() to be compatible with as_area_create()
(the user is allowed to request a specific virtual memory base address, the kernel uses an available base address if AS_AREA_ANY is used)

Files:
17 edited

Legend:

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

    r527f1ca rbf9cb2f  
    229229    void *virt_ptr, uintptr_t bound)
    230230{
    231         uintptr_t virt = (uintptr_t) -1;
    232         int rc = physmem_map(ALIGN_DOWN(phys, FRAME_SIZE), pages, flags,
    233             &virt, bound);
     231        uintptr_t virt;
     232        int rc = copy_from_uspace(&virt, virt_ptr, sizeof(virt));
     233        if (rc != EOK)
     234                return rc;
     235       
     236        rc = physmem_map(ALIGN_DOWN(phys, FRAME_SIZE), pages, flags, &virt,
     237            bound);
    234238        if (rc != EOK)
    235239                return rc;
     
    390394                        return rc;
    391395               
     396                uintptr_t virt;
     397                rc = copy_from_uspace(&virt, virt_ptr, sizeof(virt));
     398                if (rc != EOK)
     399                        return rc;
     400               
    392401                uintptr_t phys;
    393                 uintptr_t virt = (uintptr_t) -1;
    394402                rc = dmamem_map_anonymous(size, constraint, map_flags, flags,
    395403                    &phys, &virt, bound);
  • uspace/app/kio/kio.c

    r527f1ca rbf9cb2f  
    6363
    6464/* Pointer to kio area */
    65 static wchar_t *kio;
     65static wchar_t *kio = (wchar_t *) AS_AREA_ANY;
    6666static size_t kio_length;
    6767
  • uspace/drv/audio/sb16/dsp.c

    r527f1ca rbf9cb2f  
    178178       
    179179        uintptr_t pa = 0;
    180         void *buffer = NULL;
     180        void *buffer = AS_AREA_ANY;
    181181       
    182182        int ret = dmamem_map_anonymous(size, DMAMEM_16MiB | 0x0000ffff,
  • uspace/drv/block/ahci/ahci.c

    r527f1ca rbf9cb2f  
    234234       
    235235        uintptr_t phys;
    236         void *ibuf;
     236        void *ibuf = AS_AREA_ANY;
    237237        int rc = dmamem_map_anonymous(sata->block_size, DMAMEM_4GiB,
    238238            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &ibuf);
     
    277277       
    278278        uintptr_t phys;
    279         void *ibuf;
     279        void *ibuf = AS_AREA_ANY;
    280280        int rc = dmamem_map_anonymous(sata->block_size, DMAMEM_4GiB,
    281281            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &ibuf);
     
    436436       
    437437        uintptr_t phys;
    438         sata_identify_data_t *idata;
     438        sata_identify_data_t *idata = AS_AREA_ANY;
    439439        int rc = dmamem_map_anonymous(SATA_IDENTIFY_DEVICE_BUFFER_LENGTH,
    440440            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
    441             (void **) &idata);
     441            (void *) &idata);
    442442        if (rc != EOK) {
    443443                ddf_msg(LVL_ERROR, "Cannot allocate buffer to identify device.");
     
    630630       
    631631        uintptr_t phys;
    632         sata_identify_data_t *idata;
     632        sata_identify_data_t *idata = AS_AREA_ANY;
    633633        int rc = dmamem_map_anonymous(SATA_SET_FEATURE_BUFFER_LENGTH,
    634634            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
    635             (void **) &idata);
     635            (void *) &idata);
    636636        if (rc != EOK) {
    637637                ddf_msg(LVL_ERROR, "Cannot allocate buffer for device set mode.");
     
    938938        size_t size = 4096;
    939939        uintptr_t phys = 0;
    940         void *virt_fb = NULL;
    941         void *virt_cmd = NULL;
    942         void *virt_table = NULL;
     940        void *virt_fb = AS_AREA_ANY;
     941        void *virt_cmd = AS_AREA_ANY;
     942        void *virt_table = AS_AREA_ANY;
    943943        ddf_fun_t *fun;
    944944       
     
    11551155       
    11561156        /* Map AHCI registers. */
    1157         ahci->memregs = NULL;
     1157        ahci->memregs = AS_AREA_ANY;
    11581158       
    11591159        physmem_map(RNGABS(hw_res_parsed.mem_ranges.ranges[0]),
    11601160            AHCI_MEMREGS_PAGES_COUNT, AS_AREA_READ | AS_AREA_WRITE,
    1161             (void **) &ahci->memregs);
     1161            (void *) &ahci->memregs);
    11621162        if (ahci->memregs == NULL)
    11631163                goto error_map_registers;
  • uspace/drv/bus/usb/uhci/utils/malloc32.h

    r527f1ca rbf9cb2f  
    103103{
    104104        uintptr_t phys;
    105         void *address;
     105        void *address = AS_AREA_ANY;
    106106       
    107107        const int ret = dmamem_map_anonymous(UHCI_REQUIRED_PAGE_SIZE,
  • uspace/drv/fb/amdm37x_dispc/amdm37x_dispc.c

    r527f1ca rbf9cb2f  
    3838#include <ddf/log.h>
    3939#include <ddi.h>
    40 #include <abi/mm/as.h>
     40#include <as.h>
    4141
    4242#include "amdm37x_dispc.h"
     
    274274        const size_t size = ALIGN_UP(x * y * bpp, PAGE_SIZE);
    275275        uintptr_t pa;
    276         void *buffer;
     276        void *buffer = AS_AREA_ANY;
    277277        int ret = dmamem_map_anonymous(size, DMAMEM_4GiB,
    278278            AS_AREA_READ | AS_AREA_WRITE, 0, &pa, &buffer);
  • uspace/drv/fb/kfb/port.c

    r527f1ca rbf9cb2f  
    333333       
    334334        kfb.size = scanline * height;
     335        kfb.addr = AS_AREA_ANY;
     336       
    335337        rc = physmem_map(paddr + offset,
    336338            ALIGN_UP(kfb.size, PAGE_SIZE) >> PAGE_WIDTH,
  • uspace/drv/nic/e1k/e1k.c

    r527f1ca rbf9cb2f  
    13751375        fibril_mutex_lock(&e1000->rx_lock);
    13761376       
     1377        e1000->rx_ring_virt = AS_AREA_ANY;
    13771378        int rc = dmamem_map_anonymous(
    13781379            E1000_RX_FRAME_COUNT * sizeof(e1000_rx_descriptor_t),
     
    13961397        }
    13971398       
    1398         size_t i;
    1399         uintptr_t frame_phys;
    1400         void *frame_virt;
    1401        
    1402         for (i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     1399        for (size_t i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     1400                uintptr_t frame_phys;
     1401                void *frame_virt = AS_AREA_ANY;
     1402               
    14031403                rc = dmamem_map_anonymous(E1000_MAX_SEND_FRAME_SIZE,
    14041404                    DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0,
     
    14121412       
    14131413        /* Write descriptor */
    1414         for (i = 0; i < E1000_RX_FRAME_COUNT; i++)
     1414        for (size_t i = 0; i < E1000_RX_FRAME_COUNT; i++)
    14151415                e1000_fill_new_rx_descriptor(nic, i);
    14161416       
     
    14211421       
    14221422error:
    1423         for (i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     1423        for (size_t i = 0; i < E1000_RX_FRAME_COUNT; i++) {
    14241424                if (e1000->rx_frame_virt[i] != NULL) {
    14251425                        dmamem_unmap_anonymous(e1000->rx_frame_virt[i]);
     
    15711571       
    15721572        e1000->tx_ring_phys = 0;
    1573         e1000->tx_ring_virt = NULL;
     1573        e1000->tx_ring_virt = AS_AREA_ANY;
    15741574       
    15751575        e1000->tx_frame_phys = NULL;
     
    15971597       
    15981598        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
     1599                e1000->tx_frame_virt[i] = AS_AREA_ANY;
    15991600                rc = dmamem_map_anonymous(E1000_MAX_SEND_FRAME_SIZE,
    16001601                    DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,
  • uspace/drv/nic/rtl8139/driver.c

    r527f1ca rbf9cb2f  
    11411141
    11421142        ddf_msg(LVL_DEBUG, "Creating buffers");
    1143 
     1143       
     1144        rtl8139->tx_buff_virt = AS_AREA_ANY;
    11441145        rc = dmamem_map_anonymous(TX_PAGES * PAGE_SIZE, DMAMEM_4GiB,
    11451146            AS_AREA_WRITE, 0, &rtl8139->tx_buff_phys, &rtl8139->tx_buff_virt);
     
    11611162        ddf_msg(LVL_DEBUG, "Allocating receiver buffer of the size %d bytes",
    11621163            RxBUF_TOT_LENGTH);
    1163 
     1164       
     1165        rtl8139->rx_buff_virt = AS_AREA_ANY;
    11641166        rc = dmamem_map_anonymous(RxBUF_TOT_LENGTH, DMAMEM_4GiB,
    11651167            AS_AREA_READ, 0, &rtl8139->rx_buff_phys, &rtl8139->rx_buff_virt);
  • uspace/lib/c/generic/ddi.c

    r527f1ca rbf9cb2f  
    7171 * @param flags Flags for the new address space area.
    7272 * @param virt  Virtual address of the starting page.
    73  *
    74  * @return EOK on success
    75  * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability
    76  * @return ENOENT if there is no task with specified ID
     73 *              If set to AS_AREA_ANY ((void *) -1), a suitable value
     74 *              is found by the kernel, otherwise the kernel tries to
     75 *              obey the desired value.
     76 *
     77 * @return EOK on success.
     78 * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability.
    7779 * @return ENOMEM if there was some problem in creating
    7880 *         the address space area.
     
    8587}
    8688
     89/** Lock a piece physical memory for DMA transfers.
     90 *
     91 * The mapping of the specified virtual memory address
     92 * to physical memory address is locked in order to
     93 * make it safe for DMA transferts.
     94 *
     95 * Caller of this function must have the CAP_MEM_MANAGER capability.
     96 *
     97 * @param virt      Virtual address of the memory to be locked.
     98 * @param size      Number of bytes to lock.
     99 * @param map_flags Desired virtual memory area flags.
     100 * @param flags     Flags for the physical memory address.
     101 * @param phys      Locked physical memory address.
     102 *
     103 * @return EOK on success.
     104 * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability.
     105 * @return ENOMEM if there was some problem in creating
     106 *         the address space area.
     107 *
     108 */
    87109int dmamem_map(void *virt, size_t size, unsigned int map_flags,
    88110    unsigned int flags, uintptr_t *phys)
     
    93115}
    94116
     117/** Map a piece of physical memory suitable for DMA transfers.
     118 *
     119 * Caller of this function must have the CAP_MEM_MANAGER capability.
     120 *
     121 * @param size       Number of bytes to map.
     122 * @param constraint Bit mask defining the contraint on the physical
     123 *                   address to be mapped.
     124 * @param map_flags  Desired virtual memory area flags.
     125 * @param flags      Flags for the physical memory address.
     126 * @param virt       Virtual address of the starting page.
     127 *                   If set to AS_AREA_ANY ((void *) -1), a suitable value
     128 *                   is found by the kernel, otherwise the kernel tries to
     129 *                   obey the desired value.
     130 *
     131 * @return EOK on success.
     132 * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability.
     133 * @return ENOMEM if there was some problem in creating
     134 *         the address space area.
     135 *
     136 */
    95137int dmamem_map_anonymous(size_t size, uintptr_t constraint,
    96138    unsigned int map_flags, unsigned int flags, uintptr_t *phys, void **virt)
     
    221263        size_t pages = SIZE2PAGES(offset + size);
    222264       
    223         void *virt_page;
     265        void *virt_page = AS_AREA_ANY;
    224266        int rc = physmem_map(phys_frame, pages,
    225267            AS_AREA_READ | AS_AREA_WRITE, &virt_page);
  • uspace/lib/c/generic/time.c

    r527f1ca rbf9cb2f  
    555555                }
    556556               
    557                 void *addr;
     557                void *addr = AS_AREA_ANY;
    558558                rc = physmem_map(faddr, 1, AS_AREA_READ | AS_AREA_CACHEABLE,
    559559                    &addr);
  • uspace/srv/bd/rd/rd.c

    r527f1ca rbf9cb2f  
    6060
    6161/** Pointer to the ramdisk's image */
    62 static void *rd_addr;
     62static void *rd_addr = AS_AREA_ANY;
    6363
    6464/** Size of the ramdisk */
  • uspace/srv/hid/input/port/niagara.c

    r527f1ca rbf9cb2f  
    7474        uint64_t read_ptr;
    7575        char data[INPUT_BUFFER_SIZE];
    76 }
    77         __attribute__ ((packed))
    78         __attribute__ ((aligned(PAGE_SIZE)))
    79         *input_buffer_t;
     76} __attribute__((packed)) __attribute__((aligned(PAGE_SIZE))) *input_buffer_t;
    8077
    8178/* virtual address of the shared buffer */
    82 static input_buffer_t input_buffer;
     79static input_buffer_t input_buffer = (input_buffer_t) AS_AREA_ANY;
    8380
    8481static volatile bool polling_disabled = false;
     
    8784/**
    8885 * Initializes the Niagara driver.
    89  * Maps the shared buffer and creates the polling thread. 
     86 * Maps the shared buffer and creates the polling thread.
    9087 */
    9188static int niagara_port_init(kbd_dev_t *kdev)
  • uspace/srv/hid/output/port/ega.c

    r527f1ca rbf9cb2f  
    215215       
    216216        ega.size = (ega.cols * ega.rows) << 1;
     217        ega.addr = AS_AREA_ANY;
    217218       
    218219        rc = physmem_map(paddr,
  • uspace/srv/hid/output/port/kchar.c

    r527f1ca rbf9cb2f  
    8484                return rc;
    8585       
     86        kchar.addr = AS_AREA_ANY;
     87       
    8688        rc = physmem_map(paddr,
    8789            ALIGN_UP(1, PAGE_SIZE) >> PAGE_WIDTH,
  • uspace/srv/hid/output/port/niagara.c

    r527f1ca rbf9cb2f  
    104104                return rc;
    105105       
     106        niagara.fifo = (output_fifo_t *) AS_AREA_ANY;
     107       
    106108        rc = physmem_map(paddr, 1, AS_AREA_READ | AS_AREA_WRITE,
    107109            (void *) &niagara.fifo);
  • uspace/srv/hw/irc/obio/obio.c

    r527f1ca rbf9cb2f  
    7070
    7171static uintptr_t base_phys;
    72 static volatile uint64_t *base_virt;
     72static volatile uint64_t *base_virt = (volatile uint64_t *) AS_AREA_ANY;
    7373
    7474/** Handle one connection to obio.
Note: See TracChangeset for help on using the changeset viewer.