Changeset 8442d10 in mainline for uspace/drv


Ignore:
Timestamp:
2013-09-09T21:48:12Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c67dbd6
Parents:
2e2c18a1
Message:

improve the API of physmem_map(), dmamem_map() and dmamem_map_anonymous()
the "constraint" argument of dmamem_map_anonymous() should be used to specify bits disallowed in the physical frame address

Location:
uspace/drv
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/dsp.c

    r2e2c18a1 r8442d10  
    173173{
    174174        assert(dsp);
    175         if (size > MAX_BUFFER_SIZE || size == 0 || (size % 2) == 1)
     175       
     176        if ((size > MAX_BUFFER_SIZE) || (size == 0) || ((size % 2) == 1))
    176177                size = MAX_BUFFER_SIZE;
    177         void *buffer = NULL, *pa = NULL;
    178         int ret = dmamem_map_anonymous(size, AS_AREA_WRITE | AS_AREA_READ,
    179             0, &pa, &buffer);
     178       
     179        uintptr_t pa = 0;
     180        void *buffer = NULL;
     181       
     182        int ret = dmamem_map_anonymous(size, DMAMEM_16MiB,
     183            AS_AREA_WRITE | AS_AREA_READ, 0, &pa, &buffer);
    180184        if (ret != EOK) {
    181185                ddf_log_error("Failed to allocate DMA buffer.");
    182186                return ENOMEM;
    183187        }
    184 
    185         ddf_log_verbose("Setup dma buffer at %p(%p) %zu.", buffer, pa, size);
    186         assert((uintptr_t)pa < (1 << 25));
    187 
     188       
     189        ddf_log_verbose("Setup DMA buffer at %p (%zu) %zu.", buffer, pa, size);
     190        assert(pa < (1 << 24));
     191       
    188192        /* Setup 16 bit channel */
    189         ret = setup_dma(dsp, (uintptr_t)pa, size);
     193        ret = setup_dma(dsp, pa, size);
    190194        if (ret == EOK) {
    191195                dsp->buffer.data = buffer;
     
    196200                dmamem_unmap_anonymous(buffer);
    197201        }
     202       
    198203        return ret;
    199204}
  • uspace/drv/block/ahci/ahci.c

    r2e2c18a1 r8442d10  
    119119static int ahci_identify_device(sata_dev_t *);
    120120static int ahci_set_highest_ultra_dma_mode(sata_dev_t *);
    121 static int ahci_rb_fpdma(sata_dev_t *, void *, uint64_t);
    122 static int ahci_wb_fpdma(sata_dev_t *, void *, uint64_t);
     121static int ahci_rb_fpdma(sata_dev_t *, uintptr_t, uint64_t);
     122static int ahci_wb_fpdma(sata_dev_t *, uintptr_t, uint64_t);
    123123
    124124static void ahci_sata_devices_create(ahci_dev_t *, ddf_dev_t *);
     
    233233        sata_dev_t *sata = fun_sata_dev(fun);
    234234       
    235         void *phys;
     235        uintptr_t phys;
    236236        void *ibuf;
    237         int rc = dmamem_map_anonymous(sata->block_size, AS_AREA_READ | AS_AREA_WRITE,
    238             0, &phys, (void **) &ibuf);
     237        int rc = dmamem_map_anonymous(sata->block_size, DMAMEM_4GiB,
     238            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &ibuf);
    239239        if (rc != EOK) {
    240240                ddf_msg(LVL_ERROR, "Cannot allocate read buffer.");
     
    276276        sata_dev_t *sata = fun_sata_dev(fun);
    277277       
    278         void *phys;
     278        uintptr_t phys;
    279279        void *ibuf;
    280         int rc = dmamem_map_anonymous(sata->block_size, AS_AREA_READ | AS_AREA_WRITE,
    281             0, &phys, (void **) &ibuf);
     280        int rc = dmamem_map_anonymous(sata->block_size, DMAMEM_4GiB,
     281            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &ibuf);
    282282        if (rc != EOK) {
    283283                ddf_msg(LVL_ERROR, "Cannot allocate write buffer.");
     
    336336 *
    337337 */
    338 static void ahci_identify_device_cmd(sata_dev_t *sata, void *phys)
     338static void ahci_identify_device_cmd(sata_dev_t *sata, uintptr_t phys)
    339339{
    340340        volatile sata_std_command_frame_t *cmd =
     
    381381 *
    382382 */
    383 static void ahci_identify_packet_device_cmd(sata_dev_t *sata, void *phys)
     383static void ahci_identify_packet_device_cmd(sata_dev_t *sata, uintptr_t phys)
    384384{
    385385        volatile sata_std_command_frame_t *cmd =
     
    435435        }
    436436       
    437         void *phys;
     437        uintptr_t phys;
    438438        sata_identify_data_t *idata;
    439439        int rc = dmamem_map_anonymous(SATA_IDENTIFY_DEVICE_BUFFER_LENGTH,
    440             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, (void **) &idata);
     440            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
     441            (void **) &idata);
    441442        if (rc != EOK) {
    442443                ddf_msg(LVL_ERROR, "Cannot allocate buffer to identify device.");
     
    561562 *
    562563 */
    563 static void ahci_set_mode_cmd(sata_dev_t *sata, void* phys, uint8_t mode)
     564static void ahci_set_mode_cmd(sata_dev_t *sata, uintptr_t phys, uint8_t mode)
    564565{
    565566        volatile sata_std_command_frame_t *cmd =
     
    567568       
    568569        cmd->fis_type = SATA_CMD_FIS_TYPE;
    569         cmd->c = SATA_CMD_FIS_COMMAND_INDICATOR; 
     570        cmd->c = SATA_CMD_FIS_COMMAND_INDICATOR;
    570571        cmd->command = 0xef;
    571572        cmd->features = 0x03;
     
    628629        }
    629630       
    630         void *phys;
     631        uintptr_t phys;
    631632        sata_identify_data_t *idata;
    632633        int rc = dmamem_map_anonymous(SATA_SET_FEATURE_BUFFER_LENGTH,
    633             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, (void **) &idata);
     634            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
     635            (void **) &idata);
    634636        if (rc != EOK) {
    635637                ddf_msg(LVL_ERROR, "Cannot allocate buffer for device set mode.");
     
    677679 *
    678680 */
    679 static void ahci_rb_fpdma_cmd(sata_dev_t *sata, void *phys, uint64_t blocknum)
     681static void ahci_rb_fpdma_cmd(sata_dev_t *sata, uintptr_t phys,
     682    uint64_t blocknum)
    680683{
    681684        volatile sata_ncq_command_frame_t *cmd =
     
    734737 *
    735738 */
    736 static int ahci_rb_fpdma(sata_dev_t *sata, void *phys, uint64_t blocknum)
     739static int ahci_rb_fpdma(sata_dev_t *sata, uintptr_t phys, uint64_t blocknum)
    737740{
    738741        if (sata->is_invalid_device) {
     
    763766 *
    764767 */
    765 static void ahci_wb_fpdma_cmd(sata_dev_t *sata, void *phys, uint64_t blocknum)
     768static void ahci_wb_fpdma_cmd(sata_dev_t *sata, uintptr_t phys,
     769    uint64_t blocknum)
    766770{
    767771        volatile sata_ncq_command_frame_t *cmd =
     
    821825 *
    822826 */
    823 static int ahci_wb_fpdma(sata_dev_t *sata, void *phys, uint64_t blocknum)
     827static int ahci_wb_fpdma(sata_dev_t *sata, uintptr_t phys, uint64_t blocknum)
    824828{
    825829        if (sata->is_invalid_device) {
     
    933937{
    934938        size_t size = 4096;
    935         void *phys = NULL;
     939        uintptr_t phys = 0;
    936940        void *virt_fb = NULL;
    937941        void *virt_cmd = NULL;
     
    949953       
    950954        /* Allocate and init retfis structure. */
    951         int rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0,
    952             &phys, &virt_fb);
     955        int rc = dmamem_map_anonymous(size, DMAMEM_4GiB,
     956            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &virt_fb);
    953957        if (rc != EOK)
    954958                goto error_retfis;
     
    959963       
    960964        /* Allocate and init command header structure. */
    961         rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0,
    962             &phys, &virt_cmd);
     965        rc = dmamem_map_anonymous(size, DMAMEM_4GiB,
     966            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &virt_cmd);
    963967        if (rc != EOK)
    964968                goto error_cmd;
     
    970974       
    971975        /* Allocate and init command table structure. */
    972         rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0,
    973             &phys, &virt_table);
     976        rc = dmamem_map_anonymous(size, DMAMEM_4GiB,
     977            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &virt_table);
    974978        if (rc != EOK)
    975979                goto error_table;
     
    11531157        ahci->memregs = NULL;
    11541158       
    1155         physmem_map((void *) (size_t) (hw_res_parsed.mem_ranges.ranges[0].address),
     1159        physmem_map((uintptr_t) (hw_res_parsed.mem_ranges.ranges[0].address),
    11561160            AHCI_MEMREGS_PAGES_COUNT, AS_AREA_READ | AS_AREA_WRITE,
    11571161            (void **) &ahci->memregs);
  • uspace/drv/bus/usb/uhci/utils/malloc32.h

    r2e2c18a1 r8442d10  
    100100static inline void * get_page(void)
    101101{
    102         void *address, *phys;
     102        uintptr_t phys;
     103        void *address;
     104       
    103105        const int ret = dmamem_map_anonymous(UHCI_REQUIRED_PAGE_SIZE,
    104             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &address);
     106            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
     107            &address);
    105108        return ret == EOK ? address : NULL;
    106109}
  • uspace/drv/fb/amdm37x_dispc/amdm37x_dispc.c

    r2e2c18a1 r8442d10  
    273273        ddf_log_note("Setting mode: %ux%ux%u\n", x, y, bpp*8);
    274274        const size_t size = ALIGN_UP(x * y * bpp, PAGE_SIZE);
    275         void *buffer, *pa;
    276         int ret = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE,
    277             0, &pa, &buffer);
     275        uintptr_t pa;
     276        void *buffer;
     277        int ret = dmamem_map_anonymous(size, DMAMEM_4GiB,
     278            AS_AREA_READ | AS_AREA_WRITE, 0, &pa, &buffer);
    278279        if (ret != EOK) {
    279280                ddf_log_error("Failed to get new FB\n");
  • uspace/drv/fb/kfb/port.c

    r2e2c18a1 r8442d10  
    333333       
    334334        kfb.size = scanline * height;
    335         rc = physmem_map((void *) paddr + offset,
     335        rc = physmem_map(paddr + offset,
    336336            ALIGN_UP(kfb.size, PAGE_SIZE) >> PAGE_WIDTH,
    337337            AS_AREA_READ | AS_AREA_WRITE, (void *) &kfb.addr);
  • uspace/drv/nic/e1k/e1k.c

    r2e2c18a1 r8442d10  
    129129       
    130130        /** Physical tx ring address */
    131         void *tx_ring_phys;
     131        uintptr_t tx_ring_phys;
    132132        /** Virtual tx ring address */
    133133        void *tx_ring_virt;
    134134       
    135135        /** Ring of TX frames, physical address */
    136         void **tx_frame_phys;
     136        uintptr_t *tx_frame_phys;
    137137        /** Ring of TX frames, virtual address */
    138138        void **tx_frame_virt;
    139139       
    140140        /** Physical rx ring address */
    141         void *rx_ring_phys;
     141        uintptr_t rx_ring_phys;
    142142        /** Virtual rx ring address */
    143143        void *rx_ring_virt;
    144144       
    145145        /** Ring of RX frames, physical address */
    146         void **rx_frame_phys;
     146        uintptr_t *rx_frame_phys;
    147147        /** Ring of RX frames, virtual address */
    148148        void **rx_frame_virt;
     
    13771377        int rc = dmamem_map_anonymous(
    13781378            E1000_RX_FRAME_COUNT * sizeof(e1000_rx_descriptor_t),
    1379             AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->rx_ring_phys,
    1380             &e1000->rx_ring_virt);
     1379            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0,
     1380            &e1000->rx_ring_phys, &e1000->rx_ring_virt);
    13811381        if (rc != EOK)
    13821382                return rc;
     
    13871387            (uint32_t) PTR_TO_U64(e1000->rx_ring_phys));
    13881388       
    1389         e1000->rx_frame_phys =
    1390             calloc(E1000_RX_FRAME_COUNT, sizeof(void *));
     1389        e1000->rx_frame_phys = (uintptr_t *)
     1390            calloc(E1000_RX_FRAME_COUNT, sizeof(uintptr_t));
    13911391        e1000->rx_frame_virt =
    13921392            calloc(E1000_RX_FRAME_COUNT, sizeof(void *));
    1393         if (e1000->rx_frame_phys == NULL || e1000->rx_frame_virt == NULL) {
     1393        if ((e1000->rx_frame_phys == NULL) || (e1000->rx_frame_virt == NULL)) {
    13941394                rc = ENOMEM;
    13951395                goto error;
     
    13971397       
    13981398        size_t i;
     1399        uintptr_t frame_phys;
    13991400        void *frame_virt;
    1400         void *frame_phys;
    14011401       
    14021402        for (i = 0; i < E1000_RX_FRAME_COUNT; i++) {
    1403                 rc = dmamem_map_anonymous(
    1404                     E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE,
    1405                     0, &frame_phys, &frame_virt);
     1403                rc = dmamem_map_anonymous(E1000_MAX_SEND_FRAME_SIZE,
     1404                    DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0,
     1405                    &frame_phys, &frame_virt);
    14061406                if (rc != EOK)
    14071407                        goto error;
    14081408               
     1409                e1000->rx_frame_phys[i] = frame_phys;
    14091410                e1000->rx_frame_virt[i] = frame_virt;
    1410                 e1000->rx_frame_phys[i] = frame_phys;
    14111411        }
    14121412       
     
    14241424                if (e1000->rx_frame_virt[i] != NULL) {
    14251425                        dmamem_unmap_anonymous(e1000->rx_frame_virt[i]);
     1426                        e1000->rx_frame_phys[i] = 0;
    14261427                        e1000->rx_frame_virt[i] = NULL;
    1427                         e1000->rx_frame_phys[i] = NULL;
    14281428                }
    14291429        }
     
    14361436        if (e1000->rx_frame_virt != NULL) {
    14371437                free(e1000->rx_frame_virt);
    1438                 e1000->rx_frame_phys = NULL;
     1438                e1000->rx_frame_virt = NULL;
    14391439        }
    14401440       
     
    14541454        for (unsigned int offset = 0; offset < E1000_RX_FRAME_COUNT; offset++) {
    14551455                dmamem_unmap_anonymous(e1000->rx_frame_virt[offset]);
     1456                e1000->rx_frame_phys[offset] = 0;
    14561457                e1000->rx_frame_virt[offset] = NULL;
    1457                 e1000->rx_frame_phys[offset] = NULL;
    14581458        }
    14591459       
    14601460        free(e1000->rx_frame_virt);
    1461         free(e1000->rx_frame_phys);
     1461       
     1462        e1000->rx_frame_phys = NULL;
    14621463        e1000->rx_frame_virt = NULL;
    1463         e1000->rx_frame_phys = NULL;
     1464       
    14641465        dmamem_unmap_anonymous(e1000->rx_ring_virt);
    14651466}
     
    15691570        fibril_mutex_lock(&e1000->tx_lock);
    15701571       
    1571         e1000->tx_ring_phys = NULL;
     1572        e1000->tx_ring_phys = 0;
    15721573        e1000->tx_ring_virt = NULL;
     1574       
    15731575        e1000->tx_frame_phys = NULL;
    15741576        e1000->tx_frame_virt = NULL;
     
    15761578        int rc = dmamem_map_anonymous(
    15771579            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t),
    1578             AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->tx_ring_phys,
    1579             &e1000->tx_ring_virt);
     1580            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0,
     1581            &e1000->tx_ring_phys, &e1000->tx_ring_virt);
    15801582        if (rc != EOK)
    15811583                goto error;
     
    15841586            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t));
    15851587       
    1586         e1000->tx_frame_phys = calloc(E1000_TX_FRAME_COUNT, sizeof(void *));
    1587         e1000->tx_frame_virt = calloc(E1000_TX_FRAME_COUNT, sizeof(void *));
    1588 
    1589         if (e1000->tx_frame_phys == NULL || e1000->tx_frame_virt == NULL) {
     1588        e1000->tx_frame_phys = (uintptr_t *)
     1589            calloc(E1000_TX_FRAME_COUNT, sizeof(uintptr_t));
     1590        e1000->tx_frame_virt =
     1591            calloc(E1000_TX_FRAME_COUNT, sizeof(void *));
     1592
     1593        if ((e1000->tx_frame_phys == NULL) || (e1000->tx_frame_virt == NULL)) {
    15901594                rc = ENOMEM;
    15911595                goto error;
     
    15931597       
    15941598        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    1595                 rc = dmamem_map_anonymous(
    1596                     E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE,
     1599                rc = dmamem_map_anonymous(E1000_MAX_SEND_FRAME_SIZE,
     1600                    DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,
    15971601                    0, &e1000->tx_frame_phys[i], &e1000->tx_frame_virt[i]);
    15981602                if (rc != EOK)
     
    16161620        }
    16171621       
    1618         if (e1000->tx_frame_phys != NULL && e1000->tx_frame_virt != NULL) {
     1622        if ((e1000->tx_frame_phys != NULL) && (e1000->tx_frame_virt != NULL)) {
    16191623                for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    16201624                        if (e1000->tx_frame_virt[i] != NULL) {
    16211625                                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
     1626                                e1000->tx_frame_phys[i] = 0;
    16221627                                e1000->tx_frame_virt[i] = NULL;
    1623                                 e1000->tx_frame_phys[i] = NULL;
    16241628                        }
    16251629                }
     
    16331637        if (e1000->tx_frame_virt != NULL) {
    16341638                free(e1000->tx_frame_virt);
    1635                 e1000->tx_frame_phys = NULL;
     1639                e1000->tx_frame_virt = NULL;
    16361640        }
    16371641       
     
    16501654        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    16511655                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
     1656                e1000->tx_frame_phys[i] = 0;
    16521657                e1000->tx_frame_virt[i] = NULL;
    1653                 e1000->tx_frame_phys[i] = NULL;
    16541658        }
    16551659       
     
    16611665        if (e1000->tx_frame_virt != NULL) {
    16621666                free(e1000->tx_frame_virt);
    1663                 e1000->tx_frame_phys = NULL;
     1667                e1000->tx_frame_virt = NULL;
    16641668        }
    16651669       
  • uspace/drv/nic/rtl8139/driver.c

    r2e2c18a1 r8442d10  
    11441144        ddf_msg(LVL_DEBUG, "Creating buffers");
    11451145
    1146         rc = dmamem_map_anonymous(TX_PAGES * PAGE_SIZE, AS_AREA_WRITE, 0,
    1147             &rtl8139->tx_buff_phys, &rtl8139->tx_buff_virt);
     1146        rc = dmamem_map_anonymous(TX_PAGES * PAGE_SIZE, DMAMEM_4GiB,
     1147            AS_AREA_WRITE, 0, &rtl8139->tx_buff_phys, &rtl8139->tx_buff_virt);
    11481148        if (rc != EOK) {
    11491149                ddf_msg(LVL_ERROR, "Can not allocate transmitter buffers.");
     
    11641164            RxBUF_TOT_LENGTH);
    11651165
    1166         rc = dmamem_map_anonymous(RxBUF_TOT_LENGTH, AS_AREA_READ, 0,
    1167             &rtl8139->rx_buff_phys, &rtl8139->rx_buff_virt);
     1166        rc = dmamem_map_anonymous(RxBUF_TOT_LENGTH, DMAMEM_4GiB,
     1167            AS_AREA_READ, 0, &rtl8139->rx_buff_phys, &rtl8139->rx_buff_virt);
    11681168        if (rc != EOK) {
    11691169                ddf_msg(LVL_ERROR, "Can not allocate receive buffer.");
  • uspace/drv/nic/rtl8139/driver.h

    r2e2c18a1 r8442d10  
    100100         *  Each buffer takes 2kB
    101101         */
    102         void *tx_buff_phys;
     102        uintptr_t tx_buff_phys;
    103103        void *tx_buff_virt;
    104104
     
    117117
    118118        /** Buffer for receiving frames */
    119         void *rx_buff_phys;
     119        uintptr_t rx_buff_phys;
    120120        void *rx_buff_virt;
    121121
Note: See TracChangeset for help on using the changeset viewer.