Changeset c2a6983 in mainline for uspace/drv


Ignore:
Timestamp:
2013-10-13T20:59:33Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
12d6c98
Parents:
820104d (diff), 39bcc99 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Location:
uspace/drv
Files:
17 added
42 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/block/ahci/ahci.c

    r820104d rc2a6983  
    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(RNGABS(hw_res_parsed.mem_ranges.ranges[0]),
    11561160            AHCI_MEMREGS_PAGES_COUNT, AS_AREA_READ | AS_AREA_WRITE,
    11571161            (void **) &ahci->memregs);
     
    11601164       
    11611165        /* Register interrupt handler */
    1162         ahci_ranges[0].base = (size_t) hw_res_parsed.mem_ranges.ranges[0].address;
     1166        ahci_ranges[0].base = RNGABS(hw_res_parsed.mem_ranges.ranges[0]);
    11631167        ahci_ranges[0].size = sizeof(ahci_memregs_t);
    11641168       
     
    11671171               
    11681172                ahci_cmds[base].addr =
    1169                     ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) +
     1173                    ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +
    11701174                    AHCI_PORTS_REGISTERS_OFFSET + port * AHCI_PORT_REGISTERS_SIZE +
    11711175                    AHCI_PORT_IS_REGISTER_OFFSET;
     
    11731177               
    11741178                ahci_cmds[base + 3].addr =
    1175                     ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) +
     1179                    ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +
    11761180                    AHCI_GHC_IS_REGISTER_OFFSET;
    11771181                ahci_cmds[base + 4].addr = ahci_cmds[base + 3].addr;
  • uspace/drv/block/ata_bd/ata_bd.c

    r820104d rc2a6983  
    11321132        cnt = 100;
    11331133        while ((status & ~n_reset) != 0 || (status & set) != set) {
    1134                 async_usleep(1);
    11351134                --cnt;
    11361135                if (cnt <= 0) break;
  • uspace/drv/block/ata_bd/main.c

    r820104d rc2a6983  
    8484        }
    8585
    86         ata_res->cmd = hw_res.io_ranges.ranges[0].address;
    87         ata_res->ctl = hw_res.io_ranges.ranges[1].address;
    88 
    89         if (hw_res.io_ranges.ranges[0].size < sizeof(ata_ctl_t)) {
     86        addr_range_t *cmd_rng = &hw_res.io_ranges.ranges[0];
     87        addr_range_t *ctl_rng = &hw_res.io_ranges.ranges[1];
     88        ata_res->cmd = RNGABS(*cmd_rng);
     89        ata_res->ctl = RNGABS(*ctl_rng);
     90
     91        if (RNGSZ(*ctl_rng) < sizeof(ata_ctl_t)) {
    9092                rc = EINVAL;
    9193                goto error;
    9294        }
    9395
    94         if (hw_res.io_ranges.ranges[1].size < sizeof(ata_cmd_t)) {
     96        if (RNGSZ(*cmd_rng) < sizeof(ata_cmd_t)) {
    9597                rc = EINVAL;
    9698                goto error;
  • uspace/drv/bus/isa/i8237.c

    r820104d rc2a6983  
    3838#include <stdbool.h>
    3939#include <errno.h>
     40#include <ddi.h>
     41#include <ddf/log.h>
    4042#include <fibril_synch.h>
    4143#include <ddi.h>
     
    198200        .channels = {
    199201                /* The first chip 8-bit */
    200                 {
    201                         (uint8_t *) 0x00,
    202                         (uint8_t *) 0x01,
    203                         (uint8_t *) 0x87,
    204                         (uint8_t *) 0x0a,
    205                         (uint8_t *) 0x0b,
    206                         (uint8_t *) 0x0c,
    207                 },
    208                 {
    209                         (uint8_t *) 0x02,
    210                         (uint8_t *) 0x03,
    211                         (uint8_t *) 0x83,
    212                         (uint8_t *) 0x0a,
    213                         (uint8_t *) 0x0b,
    214                         (uint8_t *) 0x0c,
    215                 },
    216                 {
    217                         (uint8_t *) 0x04,
    218                         (uint8_t *) 0x05,
    219                         (uint8_t *) 0x81,
    220                         (uint8_t *) 0x0a,
    221                         (uint8_t *) 0x0b,
    222                         (uint8_t *) 0x0c,
    223                 },
    224                 {
    225                         (uint8_t *) 0x06,
    226                         (uint8_t *) 0x07,
    227                         (uint8_t *) 0x82,
    228                         (uint8_t *) 0x0a,
    229                         (uint8_t *) 0x0b,
    230                         (uint8_t *) 0x0c,
     202                { /* Channel 0 - Unusable*/
     203                        .offset_reg_address = (uint8_t *) 0x00,
     204                        .size_reg_address = (uint8_t *) 0x01,
     205                        .page_reg_address = (uint8_t *) 0x87,
     206                        .single_mask_address = (uint8_t *) 0x0a,
     207                        .mode_address = (uint8_t *) 0x0b,
     208                        .flip_flop_address = (uint8_t *) 0x0c,
     209                },
     210                { /* Channel 1 */
     211                        .offset_reg_address = (uint8_t *) 0x02,
     212                        .size_reg_address = (uint8_t *) 0x03,
     213                        .page_reg_address = (uint8_t *) 0x83,
     214                        .single_mask_address = (uint8_t *) 0x0a,
     215                        .mode_address = (uint8_t *) 0x0b,
     216                        .flip_flop_address = (uint8_t *) 0x0c,
     217                },
     218                { /* Channel 2 */
     219                        .offset_reg_address = (uint8_t *) 0x04,
     220                        .size_reg_address = (uint8_t *) 0x05,
     221                        .page_reg_address = (uint8_t *) 0x81,
     222                        .single_mask_address = (uint8_t *) 0x0a,
     223                        .mode_address = (uint8_t *) 0x0b,
     224                        .flip_flop_address = (uint8_t *) 0x0c,
     225                },
     226                { /* Channel 3 */
     227                        .offset_reg_address = (uint8_t *) 0x06,
     228                        .size_reg_address = (uint8_t *) 0x07,
     229                        .page_reg_address = (uint8_t *) 0x82,
     230                        .single_mask_address = (uint8_t *) 0x0a,
     231                        .mode_address = (uint8_t *) 0x0b,
     232                        .flip_flop_address = (uint8_t *) 0x0c,
    231233                },
    232234               
    233235                /* The second chip 16-bit */
    234                 {
    235                         (uint8_t *) 0xc0,
    236                         (uint8_t *) 0xc2,
    237                         (uint8_t *) 0x8f,
    238                         (uint8_t *) 0xd4,
    239                         (uint8_t *) 0xd6,
    240                         (uint8_t *) 0xd8,
    241                 },
    242                 {
    243                         (uint8_t *) 0xc4,
    244                         (uint8_t *) 0xc6,
    245                         (uint8_t *) 0x8b,
    246                         (uint8_t *) 0xd4,
    247                         (uint8_t *) 0xd6,
    248                         (uint8_t *) 0xd8,
    249                 },
    250                 {
    251                         (uint8_t *) 0xc8,
    252                         (uint8_t *) 0xca,
    253                         (uint8_t *) 0x89,
    254                         (uint8_t *) 0xd4,
    255                         (uint8_t *) 0xd6,
    256                         (uint8_t *) 0xd8,
    257                 },
    258                 {
    259                         (uint8_t *) 0xcc,
    260                         (uint8_t *) 0xce,
    261                         (uint8_t *) 0x8a,
    262                         (uint8_t *) 0xd4,
    263                         (uint8_t *) 0xd6,
    264                         (uint8_t *) 0xd8,
     236                { /* Channel 4 - Unusable */
     237                        .offset_reg_address = (uint8_t *) 0xc0,
     238                        .size_reg_address = (uint8_t *) 0xc2,
     239                        .page_reg_address = (uint8_t *) 0x8f,
     240                        .single_mask_address = (uint8_t *) 0xd4,
     241                        .mode_address = (uint8_t *) 0xd6,
     242                        .flip_flop_address = (uint8_t *) 0xd8,
     243                },
     244                { /* Channel 5 */
     245                        .offset_reg_address = (uint8_t *) 0xc4,
     246                        .size_reg_address = (uint8_t *) 0xc6,
     247                        .page_reg_address = (uint8_t *) 0x8b,
     248                        .single_mask_address = (uint8_t *) 0xd4,
     249                        .mode_address = (uint8_t *) 0xd6,
     250                        .flip_flop_address = (uint8_t *) 0xd8,
     251                },
     252                { /* Channel 6 */
     253                        .offset_reg_address = (uint8_t *) 0xc8,
     254                        .size_reg_address = (uint8_t *) 0xca,
     255                        .page_reg_address = (uint8_t *) 0x89,
     256                        .single_mask_address = (uint8_t *) 0xd4,
     257                        .mode_address = (uint8_t *) 0xd6,
     258                        .flip_flop_address = (uint8_t *) 0xd8,
     259                },
     260                { /* Channel 7 */
     261                        .offset_reg_address = (uint8_t *) 0xcc,
     262                        .size_reg_address = (uint8_t *) 0xce,
     263                        .page_reg_address = (uint8_t *) 0x8a,
     264                        .single_mask_address = (uint8_t *) 0xd4,
     265                        .mode_address = (uint8_t *) 0xd6,
     266                        .flip_flop_address = (uint8_t *) 0xd8,
    265267                },
    266268        },
     
    272274};
    273275
    274 /* Initialize I/O access to DMA controller I/O ports.
     276/** Initialize I/O access to DMA controller I/O ports.
    275277 *
    276278 * @param controller DMA Controller structure to initialize.
     
    304306       
    305307        return EOK;
     308}
     309
     310/** Helper function. Channels 4,5,6, and 7 are 8 bit DMA.
     311 * @pram channel DMA channel.
     312 * @reutrn True, if channel is 4,5,6, or 7, false otherwise.
     313 */
     314static inline bool is_dma16(unsigned channel)
     315{
     316        return (channel >= 4) && (channel < 8);
     317}
     318
     319/** Helper function. Channels 0,1,2, and 3 are 8 bit DMA.
     320 * @pram channel DMA channel.
     321 * @reutrn True, if channel is 0,1,2, or 3, false otherwise.
     322 */
     323static inline bool is_dma8(unsigned channel)
     324{
     325        return (channel < 4);
    306326}
    307327
     
    320340 *
    321341 * @return Error code.
    322  *
    323  */
    324 int dma_setup_channel(unsigned int channel, uint32_t pa, uint16_t size,
     342 */
     343int dma_channel_setup(unsigned int channel, uint32_t pa, uint32_t size,
    325344    uint8_t mode)
    326345{
     346        if (!is_dma8(channel) && !is_dma16(channel))
     347                return ENOENT;
     348
    327349        if ((channel == 0) || (channel == 4))
    328350                return ENOTSUP;
    329        
    330         if (channel > 7)
    331                 return ENOENT;
    332351       
    333352        /* DMA is limited to 24bit addresses. */
     
    336355       
    337356        /* 8 bit channels use only 4 bits from the page register. */
    338         if ((channel > 0) && (channel < 4) && (pa >= (1 << 20)))
     357        if (is_dma8(channel) && (pa >= (1 << 20)))
     358                return EINVAL;
     359
     360        /* Buffers cannot cross 64K page boundaries */
     361        if ((pa & 0xffff0000) != ((pa + size - 1) & 0xffff0000))
    339362                return EINVAL;
    340363       
     
    352375        ddf_msg(LVL_DEBUG, "Unspoiled address %#" PRIx32 " (size %" PRIu16 ")",
    353376            pa, size);
    354         if (channel > 4) {
     377        if (is_dma16(channel)) {
    355378                /* Size must be aligned to 16 bits */
    356379                if ((size & 1) != 0) {
     
    358381                        return EINVAL;
    359382                }
    360                
     383                /* Size is in 2byte words */
    361384                size >>= 1;
    362                
    363385                /* Address is fun: lower 16 bits need to be shifted by 1 */
    364386                pa = ((pa & 0xffff) >> 1) | (pa & 0xff0000);
     
    426448}
    427449
     450/** Query remaining buffer size.
     451 *
     452 * @param channel DMA Channel 1, 2, 3 for 8 bit transfers,
     453 *                    5, 6, 7 for 16 bit.
     454 * @param size    Place to store number of bytes pending in the assigned buffer.
     455 *
     456 * @return Error code.
     457 */
     458int dma_channel_remain(unsigned channel, size_t *size)
     459{
     460        assert(size);
     461        if (!is_dma8(channel) && !is_dma16(channel))
     462                return ENOENT;
     463       
     464        if ((channel == 0) || (channel == 4))
     465                return ENOTSUP;
     466       
     467        fibril_mutex_lock(&guard);
     468        if (!controller_8237.initialized) {
     469                fibril_mutex_unlock(&guard);
     470                return EIO;
     471        }
     472
     473        const dma_channel_t dma_channel = controller_8237.channels[channel];
     474        /* Get size - reset flip-flop */
     475        pio_write_8(dma_channel.flip_flop_address, 0);
     476       
     477        /* Low byte */
     478        const uint8_t value_low = pio_read_8(dma_channel.size_reg_address);
     479        ddf_msg(LVL_DEBUG2, "Read size low byte: %p:%x.",
     480            dma_channel.size_reg_address, value_low);
     481       
     482        /* High byte */
     483        const uint8_t value_high = pio_read_8(dma_channel.size_reg_address);
     484        ddf_msg(LVL_DEBUG2, "Read size high byte: %p:%x.",
     485            dma_channel.size_reg_address, value_high);
     486        fibril_mutex_unlock(&guard);
     487
     488        uint16_t remain = (value_high << 8 | value_low) ;
     489        /* 16 bit DMA size is in words,
     490         * the upper bits are bogus for 16bit transfers so we need to get
     491         * rid of them. Using limited type works well.*/
     492        if (is_dma16(channel))
     493                remain <<= 1;
     494        *size =  is_dma16(channel) ? remain + 2: remain + 1;
     495        return EOK;
     496}
    428497/**
    429498 * @}
  • uspace/drv/bus/isa/i8237.h

    r820104d rc2a6983  
    3838#define DRV_BUS_ISA_I8237_H
    3939
    40 extern int dma_setup_channel(unsigned int, uint32_t, uint16_t, uint8_t);
     40extern int dma_channel_setup(unsigned, uint32_t, uint32_t, uint8_t);
     41extern int dma_channel_remain(unsigned, size_t *);
    4142
    4243#endif
  • uspace/drv/bus/isa/isa.c

    r820104d rc2a6983  
    6565#include <ddf/log.h>
    6666#include <ops/hw_res.h>
     67#include <ops/pio_window.h>
    6768
    6869#include <device/hw_res.h>
     70#include <device/pio_window.h>
    6971
    7072#include "i8237.h"
     
    7981        ddf_dev_t *dev;
    8082        ddf_fun_t *fctl;
     83        pio_window_t pio_win;
    8184        list_t functions;
    8285} isa_bus_t;
     
    8588        fibril_mutex_t mutex;
    8689        ddf_fun_t *fnode;
     90        hw_resource_t resources[ISA_MAX_HW_RES];
    8791        hw_resource_list_t hw_resources;
    8892        link_t bus_link;
     
    101105}
    102106
    103 static hw_resource_list_t *isa_get_fun_resources(ddf_fun_t *fnode)
     107static hw_resource_list_t *isa_fun_get_resources(ddf_fun_t *fnode)
    104108{
    105109        isa_fun_t *fun = isa_fun(fnode);
    106         assert(fun != NULL);
     110        assert(fun);
    107111
    108112        return &fun->hw_resources;
    109113}
    110114
    111 static bool isa_enable_fun_interrupt(ddf_fun_t *fnode)
     115static bool isa_fun_enable_interrupt(ddf_fun_t *fnode)
    112116{
    113117        /* This is an old ugly way, copied from pci driver */
    114118        assert(fnode);
    115119        isa_fun_t *fun = isa_fun(fnode);
     120        assert(fun);
    116121
    117122        sysarg_t apic;
     
    151156}
    152157
    153 static int isa_dma_channel_fun_setup(ddf_fun_t *fnode,
    154     unsigned int channel, uint32_t pa, uint16_t size, uint8_t mode)
     158static int isa_fun_setup_dma(ddf_fun_t *fnode,
     159    unsigned int channel, uint32_t pa, uint32_t size, uint8_t mode)
    155160{
    156161        assert(fnode);
    157162        isa_fun_t *fun = isa_fun(fnode);
     163        assert(fun);
    158164        const hw_resource_list_t *res = &fun->hw_resources;
    159165        assert(res);
    160        
    161         const unsigned int ch = channel;
     166
    162167        for (size_t i = 0; i < res->count; ++i) {
     168                /* Check for assigned channel */
    163169                if (((res->resources[i].type == DMA_CHANNEL_16) &&
    164                     (res->resources[i].res.dma_channel.dma16 == ch)) ||
     170                    (res->resources[i].res.dma_channel.dma16 == channel)) ||
    165171                    ((res->resources[i].type == DMA_CHANNEL_8) &&
    166                     (res->resources[i].res.dma_channel.dma8 == ch))) {
    167                         return dma_setup_channel(channel, pa, size, mode);
    168                 }
    169         }
    170        
     172                    (res->resources[i].res.dma_channel.dma8 == channel))) {
     173                        return dma_channel_setup(channel, pa, size, mode);
     174                }
     175        }
     176
    171177        return EINVAL;
    172178}
    173179
     180static int isa_fun_remain_dma(ddf_fun_t *fnode,
     181    unsigned channel, size_t *size)
     182{
     183        assert(size);
     184        assert(fnode);
     185        isa_fun_t *fun = isa_fun(fnode);
     186        assert(fun);
     187        const hw_resource_list_t *res = &fun->hw_resources;
     188        assert(res);
     189
     190        for (size_t i = 0; i < res->count; ++i) {
     191                /* Check for assigned channel */
     192                if (((res->resources[i].type == DMA_CHANNEL_16) &&
     193                    (res->resources[i].res.dma_channel.dma16 == channel)) ||
     194                    ((res->resources[i].type == DMA_CHANNEL_8) &&
     195                    (res->resources[i].res.dma_channel.dma8 == channel))) {
     196                        return dma_channel_remain(channel, size);
     197                }
     198        }
     199
     200        return EINVAL;
     201}
     202
    174203static hw_res_ops_t isa_fun_hw_res_ops = {
    175         .get_resource_list = isa_get_fun_resources,
    176         .enable_interrupt = isa_enable_fun_interrupt,
    177         .dma_channel_setup = isa_dma_channel_fun_setup,
     204        .get_resource_list = isa_fun_get_resources,
     205        .enable_interrupt = isa_fun_enable_interrupt,
     206        .dma_channel_setup = isa_fun_setup_dma,
     207        .dma_channel_remain = isa_fun_remain_dma,
    178208};
    179209
    180 static ddf_dev_ops_t isa_fun_ops;
     210static pio_window_t *isa_fun_get_pio_window(ddf_fun_t *fnode)
     211{
     212        ddf_dev_t *dev = ddf_fun_get_dev(fnode);
     213        isa_bus_t *isa = isa_bus(dev);
     214        assert(isa);
     215
     216        return &isa->pio_win;
     217}
     218
     219static pio_window_ops_t isa_fun_pio_window_ops = {
     220        .get_pio_window = isa_fun_get_pio_window
     221};
     222
     223static ddf_dev_ops_t isa_fun_ops= {
     224        .interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops,
     225        .interfaces[PIO_WINDOW_DEV_IFACE] = &isa_fun_pio_window_ops,
     226};
    181227
    182228static int isa_dev_add(ddf_dev_t *dev);
     
    212258
    213259        fibril_mutex_initialize(&fun->mutex);
     260        fun->hw_resources.resources = fun->resources;
     261
    214262        fun->fnode = fnode;
    215263        return fun;
     
    270318{
    271319        char *line = str;
     320        *next = NULL;
    272321
    273322        if (str == NULL) {
    274                 *next = NULL;
    275323                return NULL;
    276324        }
     
    282330        if (*str != '\0') {
    283331                *next = str + 1;
    284         } else {
    285                 *next = NULL;
    286332        }
    287333
     
    310356        /* Get the name part of the rest of the line. */
    311357        strtok(line, ":");
    312 
    313         /* Allocate output buffer. */
    314         size_t size = str_size(line) + 1;
    315         char *name = malloc(size);
    316 
    317         if (name != NULL) {
    318                 /* Copy the result to the output buffer. */
    319                 str_cpy(name, size, line);
    320         }
    321 
    322         return name;
    323 }
    324 
    325 static inline char *skip_spaces(char *line)
     358        return line;
     359}
     360
     361static inline const char *skip_spaces(const char *line)
    326362{
    327363        /* Skip leading spaces. */
     
    332368}
    333369
    334 static void isa_fun_set_irq(isa_fun_t *fun, int irq)
     370static void isa_fun_add_irq(isa_fun_t *fun, int irq)
    335371{
    336372        size_t count = fun->hw_resources.count;
     
    348384}
    349385
    350 static void isa_fun_set_dma(isa_fun_t *fun, int dma)
     386static void isa_fun_add_dma(isa_fun_t *fun, int dma)
    351387{
    352388        size_t count = fun->hw_resources.count;
     
    381417}
    382418
    383 static void isa_fun_set_io_range(isa_fun_t *fun, size_t addr, size_t len)
     419static void isa_fun_add_io_range(isa_fun_t *fun, size_t addr, size_t len)
    384420{
    385421        size_t count = fun->hw_resources.count;
    386422        hw_resource_t *resources = fun->hw_resources.resources;
     423
     424        isa_bus_t *isa = isa_bus(ddf_fun_get_dev(fun->fnode));
    387425
    388426        if (count < ISA_MAX_HW_RES) {
    389427                resources[count].type = IO_RANGE;
    390428                resources[count].res.io_range.address = addr;
     429                resources[count].res.io_range.address += isa->pio_win.io.base;
    391430                resources[count].res.io_range.size = len;
     431                resources[count].res.io_range.relative = false;
    392432                resources[count].res.io_range.endianness = LITTLE_ENDIAN;
    393433
     
    400440}
    401441
    402 static void fun_parse_irq(isa_fun_t *fun, char *val)
     442static void fun_parse_irq(isa_fun_t *fun, const char *val)
    403443{
    404444        int irq = 0;
     
    409449
    410450        if (val != end)
    411                 isa_fun_set_irq(fun, irq);
    412 }
    413 
    414 static void fun_parse_dma(isa_fun_t *fun, char *val)
    415 {
    416         unsigned int dma = 0;
     451                isa_fun_add_irq(fun, irq);
     452}
     453
     454static void fun_parse_dma(isa_fun_t *fun, const char *val)
     455{
    417456        char *end = NULL;
    418457       
    419458        val = skip_spaces(val);
    420         dma = (unsigned int) strtol(val, &end, 10);
     459        const int dma = strtol(val, &end, 10);
    421460       
    422461        if (val != end)
    423                 isa_fun_set_dma(fun, dma);
    424 }
    425 
    426 static void fun_parse_io_range(isa_fun_t *fun, char *val)
     462                isa_fun_add_dma(fun, dma);
     463}
     464
     465static void fun_parse_io_range(isa_fun_t *fun, const char *val)
    427466{
    428467        size_t addr, len;
     
    441480                return;
    442481
    443         isa_fun_set_io_range(fun, addr, len);
    444 }
    445 
    446 static void get_match_id(char **id, char *val)
    447 {
    448         char *end = val;
     482        isa_fun_add_io_range(fun, addr, len);
     483}
     484
     485static void get_match_id(char **id, const char *val)
     486{
     487        const char *end = val;
    449488
    450489        while (!isspace(*end))
     
    456495}
    457496
    458 static void fun_parse_match_id(isa_fun_t *fun, char *val)
     497static void fun_parse_match_id(isa_fun_t *fun, const char *val)
    459498{
    460499        char *id = NULL;
    461         int score = 0;
    462500        char *end = NULL;
    463         int rc;
    464501
    465502        val = skip_spaces(val);
    466503
    467         score = (int)strtol(val, &end, 10);
     504        int score = (int)strtol(val, &end, 10);
    468505        if (val == end) {
    469506                ddf_msg(LVL_ERROR, "Cannot read match score for function "
     
    483520            "function %s", id, score, ddf_fun_get_name(fun->fnode));
    484521
    485         rc = ddf_fun_add_match_id(fun->fnode, id, score);
     522        int rc = ddf_fun_add_match_id(fun->fnode, id, score);
    486523        if (rc != EOK) {
    487524                ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
     
    492529}
    493530
    494 static bool prop_parse(isa_fun_t *fun, char *line, const char *prop,
    495     void (*read_fn)(isa_fun_t *, char *))
     531static bool prop_parse(isa_fun_t *fun, const char *line, const char *prop,
     532    void (*read_fn)(isa_fun_t *, const char *))
    496533{
    497534        size_t proplen = str_size(prop);
     
    508545}
    509546
    510 static void fun_prop_parse(isa_fun_t *fun, char *line)
     547static void fun_prop_parse(isa_fun_t *fun, const char *line)
    511548{
    512549        /* Skip leading spaces. */
     
    523560}
    524561
    525 static void fun_hw_res_alloc(isa_fun_t *fun)
    526 {
    527         fun->hw_resources.resources =
    528             (hw_resource_t *) malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES);
    529 }
    530 
    531 static void fun_hw_res_free(isa_fun_t *fun)
    532 {
    533         free(fun->hw_resources.resources);
    534         fun->hw_resources.resources = NULL;
    535 }
    536 
    537562static char *isa_fun_read_info(char *fun_conf, isa_bus_t *isa)
    538563{
    539564        char *line;
    540         char *fun_name = NULL;
    541565
    542566        /* Skip empty lines. */
    543         while (true) {
     567        do {
    544568                line = str_get_line(fun_conf, &fun_conf);
    545569
     
    549573                }
    550574
    551                 if (!line_empty(line))
    552                         break;
    553         }
     575        } while (line_empty(line));
    554576
    555577        /* Get device name. */
    556         fun_name = get_device_name(line);
     578        const char *fun_name = get_device_name(line);
    557579        if (fun_name == NULL)
    558580                return NULL;
    559581
    560582        isa_fun_t *fun = isa_fun_create(isa, fun_name);
    561         free(fun_name);
    562583        if (fun == NULL) {
    563584                return NULL;
    564585        }
    565 
    566         /* Allocate buffer for the list of hardware resources of the device. */
    567         fun_hw_res_alloc(fun);
    568586
    569587        /* Get properties of the device (match ids, irq and io range). */
     
    596614}
    597615
    598 static void fun_conf_parse(char *conf, isa_bus_t *isa)
    599 {
     616static void isa_functions_add(isa_bus_t *isa)
     617{
     618        char *conf = fun_conf_read(CHILD_FUN_CONF_PATH);
    600619        while (conf != NULL && *conf != '\0') {
    601620                conf = isa_fun_read_info(conf, isa);
    602621        }
    603 }
    604 
    605 static void isa_functions_add(isa_bus_t *isa)
    606 {
    607         char *fun_conf;
    608 
    609         fun_conf = fun_conf_read(CHILD_FUN_CONF_PATH);
    610         if (fun_conf != NULL) {
    611                 fun_conf_parse(fun_conf, isa);
    612                 free(fun_conf);
    613         }
     622        free(conf);
    614623}
    615624
    616625static int isa_dev_add(ddf_dev_t *dev)
    617626{
    618         isa_bus_t *isa;
     627        async_sess_t *sess;
     628        int rc;
    619629
    620630        ddf_msg(LVL_DEBUG, "isa_dev_add, device handle = %d",
    621631            (int) ddf_dev_get_handle(dev));
    622632
    623         isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t));
     633        isa_bus_t *isa = ddf_dev_data_alloc(dev, sizeof(isa_bus_t));
    624634        if (isa == NULL)
    625635                return ENOMEM;
     
    628638        isa->dev = dev;
    629639        list_initialize(&isa->functions);
     640
     641        sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE);
     642        if (sess == NULL) {
     643                ddf_msg(LVL_ERROR, "isa_dev_add failed to connect to the "
     644                    "parent driver.");
     645                return ENOENT;
     646        }
     647
     648        rc = pio_window_get(sess, &isa->pio_win);
     649        if (rc != EOK) {
     650                ddf_msg(LVL_ERROR, "isa_dev_add failed to get PIO window "
     651                    "for the device.");
     652                return rc;
     653        }       
    630654
    631655        /* Make the bus device more visible. Does not do anything. */
     
    658682{
    659683        isa_bus_t *isa = isa_bus(dev);
    660         int rc;
    661684
    662685        fibril_mutex_lock(&isa->mutex);
     
    666689                    isa_fun_t, bus_link);
    667690
    668                 rc = ddf_fun_offline(fun->fnode);
     691                int rc = ddf_fun_offline(fun->fnode);
    669692                if (rc != EOK) {
    670693                        fibril_mutex_unlock(&isa->mutex);
     
    682705                list_remove(&fun->bus_link);
    683706
    684                 fun_hw_res_free(fun);
    685707                ddf_fun_destroy(fun->fnode);
    686708        }
     
    709731}
    710732
    711 
    712 static void isa_init()
    713 {
     733int main(int argc, char *argv[])
     734{
     735        printf(NAME ": HelenOS ISA bus driver\n");
    714736        ddf_log_init(NAME);
    715         isa_fun_ops.interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops;
    716 }
    717 
    718 int main(int argc, char *argv[])
    719 {
    720         printf(NAME ": HelenOS ISA bus driver\n");
    721         isa_init();
    722737        return ddf_driver_main(&isa_driver);
    723738}
  • uspace/drv/bus/pci/pciintel/pci.c

    r820104d rc2a6983  
    5757#include <ops/hw_res.h>
    5858#include <device/hw_res.h>
     59#include <ops/pio_window.h>
     60#include <device/pio_window.h>
    5961#include <ddi.h>
    6062#include <pci_dev_iface.h>
     
    141143}
    142144
     145static pio_window_t *pciintel_get_pio_window(ddf_fun_t *fnode)
     146{
     147        pci_fun_t *fun = pci_fun(fnode);
     148       
     149        if (fun == NULL)
     150                return NULL;
     151        return &fun->pio_window;
     152}
     153
     154
    143155static int pci_config_space_write_32(ddf_fun_t *fun, uint32_t address,
    144156    uint32_t data)
     
    198210        .get_resource_list = &pciintel_get_resources,
    199211        .enable_interrupt = &pciintel_enable_interrupt,
     212};
     213
     214static pio_window_ops_t pciintel_pio_window_ops = {
     215        .get_pio_window = &pciintel_get_pio_window
    200216};
    201217
     
    211227static ddf_dev_ops_t pci_fun_ops = {
    212228        .interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops,
     229        .interfaces[PIO_WINDOW_DEV_IFACE] = &pciintel_pio_window_ops,
    213230        .interfaces[PCI_DEV_IFACE] = &pci_dev_ops
    214231};
     
    233250static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len)
    234251{
     252        const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
    235253        pci_bus_t *bus = pci_bus_from_fun(fun);
     254        uint32_t val;
    236255       
    237256        fibril_mutex_lock(&bus->conf_mutex);
    238        
    239         const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
    240         void *addr = bus->conf_data_port + (reg & 3);
    241        
    242         pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));
    243        
     257
     258        pio_write_32(bus->conf_addr_reg, host2uint32_t_le(conf_addr));
     259
     260        /*
     261         * Always read full 32-bits from the PCI conf_data_port register and
     262         * get the desired portion of it afterwards. Some architectures do not
     263         * support shorter PIO reads offset from this register.
     264         */
     265        val = uint32_t_le2host(pio_read_32(bus->conf_data_reg));
     266
    244267        switch (len) {
    245268        case 1:
    246                 /* No endianness change for 1 byte */
    247                 buf[0] = pio_read_8(addr);
     269                *buf = (uint8_t) (val >> ((reg & 3) * 8));
    248270                break;
    249271        case 2:
    250                 ((uint16_t *) buf)[0] = uint16_t_le2host(pio_read_16(addr));
     272                *((uint16_t *) buf) = (uint16_t) (val >> ((reg & 3)) * 8);
    251273                break;
    252274        case 4:
    253                 ((uint32_t *) buf)[0] = uint32_t_le2host(pio_read_32(addr));
     275                *((uint32_t *) buf) = (uint32_t) val;
    254276                break;
    255277        }
     
    260282static void pci_conf_write(pci_fun_t *fun, int reg, uint8_t *buf, size_t len)
    261283{
     284        const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
    262285        pci_bus_t *bus = pci_bus_from_fun(fun);
     286        uint32_t val;
    263287       
    264288        fibril_mutex_lock(&bus->conf_mutex);
    265        
    266         const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
    267         void *addr = bus->conf_data_port + (reg & 3);
    268        
    269         pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));
     289
     290        /*
     291         * Prepare to write full 32-bits to the PCI conf_data_port register.
     292         * Some architectures do not support shorter PIO writes offset from this
     293         * register.
     294         */
     295
     296        if (len < 4) {
     297                /*
     298                 * We have fewer than full 32-bits, so we need to read the
     299                 * missing bits first.
     300                 */
     301                pio_write_32(bus->conf_addr_reg, host2uint32_t_le(conf_addr));
     302                val = uint32_t_le2host(pio_read_32(bus->conf_data_reg));
     303        }
    270304       
    271305        switch (len) {
    272306        case 1:
    273                 /* No endianness change for 1 byte */
    274                 pio_write_8(addr, buf[0]);
     307                val &= ~(0xffU << ((reg & 3) * 8));
     308                val |= *buf << ((reg & 3) * 8);
    275309                break;
    276310        case 2:
    277                 pio_write_16(addr, host2uint16_t_le(((uint16_t *) buf)[0]));
     311                val &= ~(0xffffU << ((reg & 3) * 8));
     312                val |= *((uint16_t *) buf) << ((reg & 3) * 8);
    278313                break;
    279314        case 4:
    280                 pio_write_32(addr, host2uint32_t_le(((uint32_t *) buf)[0]));
     315                val = *((uint32_t *) buf);
    281316                break;
    282317        }
     318
     319        pio_write_32(bus->conf_addr_reg, host2uint32_t_le(conf_addr));
     320        pio_write_32(bus->conf_data_reg, host2uint32_t_le(val));
    283321       
    284322        fibril_mutex_unlock(&bus->conf_mutex);
     
    411449                hw_resources[count].res.io_range.address = range_addr;
    412450                hw_resources[count].res.io_range.size = range_size;
     451                hw_resources[count].res.io_range.relative = true;
    413452                hw_resources[count].res.io_range.endianness = LITTLE_ENDIAN;
    414453        } else {
     
    416455                hw_resources[count].res.mem_range.address = range_addr;
    417456                hw_resources[count].res.mem_range.size = range_size;
     457                hw_resources[count].res.mem_range.relative = false;
    418458                hw_resources[count].res.mem_range.endianness = LITTLE_ENDIAN;
    419459        }
     
    433473{
    434474        /* Value of the BAR */
    435         uint32_t val, mask;
     475        uint32_t val;
     476        uint32_t bar;
     477        uint32_t mask;
     478
    436479        /* IO space address */
    437480        bool io;
     
    471514        /* Get the address mask. */
    472515        pci_conf_write_32(fun, addr, 0xffffffff);
    473         mask &= pci_conf_read_32(fun, addr);
    474        
     516        bar = pci_conf_read_32(fun, addr);
     517
     518        /*
     519         * Unimplemented BARs read back as all 0's.
     520         */
     521        if (!bar)
     522                return addr + (addrw64 ? 8 : 4);
     523
     524        mask &= bar;   
     525
    475526        /* Restore the original value. */
    476527        pci_conf_write_32(fun, addr, val);
     
    520571{
    521572        uint8_t irq = pci_conf_read_8(fun, PCI_BRIDGE_INT_LINE);
    522         if (irq != 0xff)
     573        uint8_t pin = pci_conf_read_8(fun, PCI_BRIDGE_INT_PIN);
     574
     575        if (pin != 0 && irq != 0xff)
    523576                pci_add_interrupt(fun, irq);
    524577}
     
    583636                        pci_read_bars(fun);
    584637                        pci_read_interrupt(fun);
     638
     639                        /* Propagate the PIO window to the function. */
     640                        fun->pio_window = bus->pio_win;
    585641                       
    586642                        ddf_fun_set_ops(fun->fnode, &pci_fun_ops);
     
    613669static int pci_dev_add(ddf_dev_t *dnode)
    614670{
     671        hw_resource_list_t hw_resources;
    615672        pci_bus_t *bus = NULL;
    616673        ddf_fun_t *ctl = NULL;
     
    638695                goto fail;
    639696        }
    640        
    641         hw_resource_list_t hw_resources;
     697
     698        rc = pio_window_get(sess, &bus->pio_win);
     699        if (rc != EOK) {
     700                ddf_msg(LVL_ERROR, "pci_dev_add failed to get PIO window "
     701                    "for the device.");
     702                goto fail;
     703        }
    642704       
    643705        rc = hw_res_get_resource_list(sess, &hw_resources);
     
    662724            hw_resources.resources[1].res.io_range.address);
    663725       
    664         bus->conf_io_addr =
    665             (uint32_t) hw_resources.resources[0].res.io_range.address;
    666         bus->conf_io_data =
    667             (uint32_t) hw_resources.resources[1].res.io_range.address;
    668        
    669         if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 4,
    670             &bus->conf_addr_port)) {
     726        if (pio_enable_resource(&bus->pio_win, &hw_resources.resources[0],
     727            (void **) &bus->conf_addr_reg)) {
    671728                ddf_msg(LVL_ERROR, "Failed to enable configuration ports.");
    672729                rc = EADDRNOTAVAIL;
    673730                goto fail;
    674731        }
    675         if (pio_enable((void *)(uintptr_t)bus->conf_io_data, 4,
    676             &bus->conf_data_port)) {
     732        if (pio_enable_resource(&bus->pio_win, &hw_resources.resources[1],
     733            (void **) &bus->conf_data_reg)) {
    677734                ddf_msg(LVL_ERROR, "Failed to enable configuration ports.");
    678735                rc = EADDRNOTAVAIL;
     
    729786{
    730787        ddf_log_init(NAME);
    731         pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops;
    732         pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops;
    733788}
    734789
  • uspace/drv/bus/pci/pciintel/pci.h

    r820104d rc2a6983  
    4040#include "pci_regs.h"
    4141
    42 #define PCI_MAX_HW_RES 8
     42#define PCI_MAX_HW_RES 10
    4343
    4444typedef struct pciintel_bus {
    4545        /** DDF device node */
    4646        ddf_dev_t *dnode;
    47         uint32_t conf_io_addr;
    48         uint32_t conf_io_data;
    49         void *conf_data_port;
    50         void *conf_addr_port;
     47        ioport32_t *conf_addr_reg;
     48        ioport32_t *conf_data_reg;
     49        pio_window_t pio_win;
    5150        fibril_mutex_t conf_mutex;
    5251} pci_bus_t;
     
    6867        hw_resource_list_t hw_resources;
    6968        hw_resource_t resources[PCI_MAX_HW_RES];
     69        pio_window_t pio_window;
    7070} pci_fun_t;
    7171
  • uspace/drv/bus/usb/ehci/main.c

    r820104d rc2a6983  
    7777        assert(device);
    7878
    79         uintptr_t reg_base = 0;
    80         size_t reg_size = 0;
     79        addr_range_t reg_range;
    8180        int irq = 0;
    8281
    83         int rc = get_my_registers(device, &reg_base, &reg_size, &irq);
     82        int rc = get_my_registers(device, &reg_range, &irq);
    8483        if (rc != EOK) {
    8584                usb_log_error("Failed to get memory addresses for %" PRIun
     
    8887        }
    8988
    90         usb_log_info("Memory mapped regs at 0x%" PRIxn " (size %zu), IRQ %d.\n",
    91             reg_base, reg_size, irq);
     89        usb_log_info("Memory mapped regs at %p (size %zu), IRQ %d.\n",
     90            RNGABSPTR(reg_range), RNGSZ(reg_range), irq);
    9291
    93         rc = disable_legacy(device, reg_base, reg_size);
     92        rc = disable_legacy(device, &reg_range);
    9493        if (rc != EOK) {
    9594                usb_log_error("Failed to disable legacy USB: %s.\n",
  • uspace/drv/bus/usb/ehci/res.c

    r820104d rc2a6983  
    7171 *
    7272 * @param[in] dev Device asking for the addresses.
    73  * @param[out] mem_reg_address Base address of the memory range.
    74  * @param[out] mem_reg_size Size of the memory range.
     73 * @param[out] mem_regs_p Pointer to the register range.
    7574 * @param[out] irq_no IRQ assigned to the device.
    7675 * @return Error code.
    7776 */
    7877int get_my_registers(ddf_dev_t *dev,
    79     uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no)
     78    addr_range_t *mem_regs_p, int *irq_no)
    8079{
    8180        assert(dev);
     
    9998        }
    10099
    101         if (mem_reg_address)
    102                 *mem_reg_address = hw_res.mem_ranges.ranges[0].address;
    103         if (mem_reg_size)
    104                 *mem_reg_size = hw_res.mem_ranges.ranges[0].size;
     100        if (mem_regs_p)
     101                *mem_regs_p = hw_res.mem_ranges.ranges[0];
    105102        if (irq_no)
    106103                *irq_no = hw_res.irqs.irqs[0];
     
    267264}
    268265
    269 int disable_legacy(ddf_dev_t *device, uintptr_t reg_base, size_t reg_size)
     266int disable_legacy(ddf_dev_t *device, addr_range_t *reg_range)
    270267{
    271268        assert(device);
     
    274271        /* Map EHCI registers */
    275272        void *regs = NULL;
    276         int rc = pio_enable((void*)reg_base, reg_size, &regs);
     273        int rc = pio_enable_range(reg_range, &regs);
    277274        if (rc != EOK) {
    278275                usb_log_error("Failed to map registers %p: %s.\n",
    279                     (void *) reg_base, str_error(rc));
     276                    RNGABSPTR(*reg_range), str_error(rc));
    280277                return rc;
    281278        }
  • uspace/drv/bus/usb/ehci/res.h

    r820104d rc2a6983  
    3737
    3838#include <ddf/driver.h>
     39#include <device/hw_res_parsed.h>
    3940
    40 int get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *);
     41int get_my_registers(ddf_dev_t *, addr_range_t *, int *);
    4142int enable_interrupts(ddf_dev_t *);
    42 int disable_legacy(ddf_dev_t *, uintptr_t, size_t);
     43int disable_legacy(ddf_dev_t *, addr_range_t *);
    4344
    4445#endif
  • uspace/drv/bus/usb/ohci/hc.c

    r820104d rc2a6983  
    106106 * @param[out] cmds Commands buffer.
    107107 * @param[in] cmds_size Size of the commands buffer (bytes).
    108  * @param[in] regs Physical address of device's registers.
    109  * @param[in] reg_size Size of the register area (bytes).
     108 * @param[in] regs Device's register range.
    110109 *
    111110 * @return Error code.
     
    113112int
    114113hc_get_irq_code(irq_pio_range_t ranges[], size_t ranges_size, irq_cmd_t cmds[],
    115     size_t cmds_size, uintptr_t regs, size_t reg_size)
     114    size_t cmds_size, addr_range_t *regs)
    116115{
    117116        if ((ranges_size < sizeof(ohci_pio_ranges)) ||
    118117            (cmds_size < sizeof(ohci_irq_commands)) ||
    119             (reg_size < sizeof(ohci_regs_t)))
     118            (RNGSZ(*regs) < sizeof(ohci_regs_t)))
    120119                return EOVERFLOW;
    121120
    122121        memcpy(ranges, ohci_pio_ranges, sizeof(ohci_pio_ranges));
    123         ranges[0].base = regs;
     122        ranges[0].base = RNGABS(*regs);
    124123
    125124        memcpy(cmds, ohci_irq_commands, sizeof(ohci_irq_commands));
    126         ohci_regs_t *registers = (ohci_regs_t *) regs;
     125        ohci_regs_t *registers = (ohci_regs_t *) RNGABSPTR(*regs);
    127126        cmds[0].addr = (void *) &registers->interrupt_status;
    128127        cmds[3].addr = (void *) &registers->interrupt_status;
     
    135134 *
    136135 * @param[in] device Host controller DDF device
    137  * @param[in] reg_base Register range base
    138  * @param[in] reg_size Register range size
     136 * @param[in] regs Register range
    139137 * @param[in] irq Interrupt number
    140138 * @paran[in] handler Interrupt handler
     
    142140 * @return EOK on success or negative error code
    143141 */
    144 int hc_register_irq_handler(ddf_dev_t *device, uintptr_t reg_base, size_t reg_size,
    145     int irq, interrupt_handler_t handler)
     142int hc_register_irq_handler(ddf_dev_t *device, addr_range_t *regs, int irq,
     143    interrupt_handler_t handler)
    146144{
    147145        int rc;
     
    158156
    159157        rc = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
    160             sizeof(irq_cmds), reg_base, reg_size);
     158            sizeof(irq_cmds), regs);
    161159        if (rc != EOK) {
    162160                usb_log_error("Failed to generate IRQ code: %s.\n",
     
    259257 *
    260258 * @param[in] instance Memory place for the structure.
    261  * @param[in] regs Address of the memory mapped I/O registers.
    262  * @param[in] reg_size Size of the memory mapped area.
     259 * @param[in] regs Device's I/O registers range.
    263260 * @param[in] interrupts True if w interrupts should be used
    264261 * @return Error code
    265262 */
    266 int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts)
    267 {
    268         assert(instance);
    269 
    270         int rc =
    271             pio_enable((void*)regs, reg_size, (void**)&instance->registers);
     263int hc_init(hc_t *instance, addr_range_t *regs, bool interrupts)
     264{
     265        assert(instance);
     266
     267        int rc = pio_enable_range(regs, (void **) &instance->registers);
    272268        if (rc != EOK) {
    273269                usb_log_error("Failed to gain access to device registers: %s.\n",
  • uspace/drv/bus/usb/ohci/hc.h

    r820104d rc2a6983  
    7575} hc_t;
    7676
    77 int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t, uintptr_t,
    78     size_t);
    79 int hc_register_irq_handler(ddf_dev_t *, uintptr_t, size_t, int, interrupt_handler_t);
     77int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t,
     78    addr_range_t *);
     79int hc_register_irq_handler(ddf_dev_t *, addr_range_t *, int,
     80    interrupt_handler_t);
    8081int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);
    81 int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts);
     82int hc_init(hc_t *instance, addr_range_t *regs, bool interrupts);
    8283
    8384/** Safely dispose host controller internal structures
  • uspace/drv/bus/usb/ohci/ohci.c

    r820104d rc2a6983  
    177177        ddf_fun_set_ops(instance->rh_fun, &rh_ops);
    178178
    179         uintptr_t reg_base = 0;
    180         size_t reg_size = 0;
     179        addr_range_t regs;
    181180        int irq = 0;
    182181
    183         rc = get_my_registers(device, &reg_base, &reg_size, &irq);
     182        rc = get_my_registers(device, &regs, &irq);
    184183        if (rc != EOK) {
    185184                usb_log_error("Failed to get register memory addresses "
     
    190189
    191190        usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n",
    192             (void *) reg_base, reg_size, irq);
    193 
    194         rc = hc_register_irq_handler(device, reg_base, reg_size, irq, irq_handler);
     191            RNGABSPTR(regs), RNGSZ(regs), irq);
     192
     193        rc = hc_register_irq_handler(device, &regs, irq, irq_handler);
    195194        if (rc != EOK) {
    196195                usb_log_error("Failed to register interrupt handler: %s.\n",
     
    215214        }
    216215
    217         rc = hc_init(&instance->hc, reg_base, reg_size, interrupts);
     216        rc = hc_init(&instance->hc, &regs, interrupts);
    218217        if (rc != EOK) {
    219218                usb_log_error("Failed to init ohci_hcd: %s.\n", str_error(rc));
  • uspace/drv/bus/usb/ohci/res.c

    r820104d rc2a6983  
    4848 *
    4949 * @param[in] dev Device asking for the addresses.
    50  * @param[out] mem_reg_address Base address of the memory range.
    51  * @param[out] mem_reg_size Size of the memory range.
     50 * @param[out] p_regs Pointer to register range.
    5251 * @param[out] irq_no IRQ assigned to the device.
    5352 * @return Error code.
    5453 */
    55 int get_my_registers(ddf_dev_t *dev,
    56     uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no)
     54int get_my_registers(ddf_dev_t *dev, addr_range_t *p_regs, int *irq_no)
    5755{
    5856        assert(dev);
     
    6664        hw_res_list_parsed_t hw_res;
    6765        hw_res_list_parsed_init(&hw_res);
    68         const int ret =  hw_res_get_list_parsed(parent_sess, &hw_res, 0);
     66        const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
    6967        async_hangup(parent_sess);
    7068        if (ret != EOK) {
     
    7876        }
    7977
    80         if (mem_reg_address)
    81                 *mem_reg_address = hw_res.mem_ranges.ranges[0].address;
    82         if (mem_reg_size)
    83                 *mem_reg_size = hw_res.mem_ranges.ranges[0].size;
     78        if (p_regs)
     79                *p_regs = hw_res.mem_ranges.ranges[0];
    8480        if (irq_no)
    8581                *irq_no = hw_res.irqs.irqs[0];
  • uspace/drv/bus/usb/ohci/res.h

    r820104d rc2a6983  
    3636
    3737#include <ddf/driver.h>
     38#include <device/hw_res_parsed.h>
    3839
    39 int get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *);
     40int get_my_registers(ddf_dev_t *, addr_range_t *, int *);
    4041int enable_interrupts(ddf_dev_t *);
    4142
  • uspace/drv/bus/usb/uhci/hc.c

    r820104d rc2a6983  
    105105 * @param[out] cmds Commands buffer.
    106106 * @param[in] cmds_size Size of the commands buffer (bytes).
    107  * @param[in] regs Physical address of device's registers.
    108  * @param[in] reg_size Size of the register area (bytes).
     107 * @param[in] regs Device's register range.
    109108 *
    110109 * @return Error code.
     
    112111int
    113112hc_get_irq_code(irq_pio_range_t ranges[], size_t ranges_size, irq_cmd_t cmds[],
    114     size_t cmds_size, uintptr_t regs, size_t reg_size)
     113    size_t cmds_size, addr_range_t *regs)
    115114{
    116115        if ((ranges_size < sizeof(uhci_irq_pio_ranges)) ||
    117116            (cmds_size < sizeof(uhci_irq_commands)) ||
    118             (reg_size < sizeof(uhci_regs_t)))
     117            (RNGSZ(*regs) < sizeof(uhci_regs_t)))
    119118                return EOVERFLOW;
    120119
    121120        memcpy(ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges));
    122         ranges[0].base = regs;
     121        ranges[0].base = RNGABS(*regs);
    123122
    124123        memcpy(cmds, uhci_irq_commands, sizeof(uhci_irq_commands));
    125         uhci_regs_t *registers = (uhci_regs_t *) regs;
     124        uhci_regs_t *registers = (uhci_regs_t *) RNGABSPTR(*regs);
    126125        cmds[0].addr = &registers->usbsts;
    127126        cmds[3].addr = &registers->usbsts;
     
    133132 *
    134133 * @param[in] device Host controller DDF device
    135  * @param[in] reg_base Register range base
    136  * @param[in] reg_size Register range size
     134 * @param[in] regs Register range
    137135 * @param[in] irq Interrupt number
    138136 * @paran[in] handler Interrupt handler
     
    140138 * @return EOK on success or negative error code
    141139 */
    142 int hc_register_irq_handler(ddf_dev_t *device, uintptr_t reg_base, size_t reg_size,
    143     int irq, interrupt_handler_t handler)
     140int hc_register_irq_handler(ddf_dev_t *device, addr_range_t *regs, int irq,
     141    interrupt_handler_t handler)
    144142{
    145143        int rc;
     
    147145        irq_cmd_t irq_cmds[hc_irq_cmd_count];
    148146        rc = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
    149             sizeof(irq_cmds), reg_base, reg_size);
     147            sizeof(irq_cmds), regs);
    150148        if (rc != EOK) {
    151149                usb_log_error("Failed to generate IRQ commands: %s.\n",
     
    232230 *
    233231 * @param[in] instance Memory place to initialize.
    234  * @param[in] regs Address of I/O control registers.
    235  * @param[in] reg_size Size of I/O control registers.
     232 * @param[in] regs Range of device's I/O control registers.
    236233 * @param[in] interrupts True if hw interrupts should be used.
    237234 * @return Error code.
     
    241238 * interrupt fibrils.
    242239 */
    243 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interrupts)
    244 {
    245         assert(reg_size >= sizeof(uhci_regs_t));
     240int hc_init(hc_t *instance, addr_range_t *regs, bool interrupts)
     241{
     242        assert(regs->size >= sizeof(uhci_regs_t));
    246243        int rc;
    247244
     
    251248        /* allow access to hc control registers */
    252249        uhci_regs_t *io;
    253         rc = pio_enable(regs, reg_size, (void **)&io);
     250        rc = pio_enable_range(regs, (void **) &io);
    254251        if (rc != EOK) {
    255252                usb_log_error("Failed to gain access to registers at %p: %s.\n",
     
    260257        instance->registers = io;
    261258        usb_log_debug(
    262             "Device registers at %p (%zuB) accessible.\n", io, reg_size);
     259            "Device registers at %p (%zuB) accessible.\n", io, regs->size);
    263260
    264261        rc = hc_init_mem_structures(instance);
  • uspace/drv/bus/usb/uhci/hc.h

    r820104d rc2a6983  
    3737
    3838#include <ddf/interrupt.h>
     39#include <device/hw_res_parsed.h>
    3940#include <fibril.h>
    4041#include <usb/host/hcd.h>
     
    120121} hc_t;
    121122
    122 int hc_register_irq_handler(ddf_dev_t *, uintptr_t, size_t, int, interrupt_handler_t);
    123 int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t, uintptr_t,
    124     size_t);
     123int hc_register_irq_handler(ddf_dev_t *, addr_range_t *, int,
     124    interrupt_handler_t);
     125int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t,
     126    addr_range_t *);
    125127void hc_interrupt(hc_t *instance, uint16_t status);
    126 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interupts);
     128int hc_init(hc_t *instance, addr_range_t *regs, bool interupts);
    127129
    128130/** Safely dispose host controller internal structures
     
    132134static inline void hc_fini(hc_t *instance) {} /* TODO: implement*/
    133135#endif
     136
    134137/**
    135138 * @}
  • uspace/drv/bus/usb/uhci/res.c

    r820104d rc2a6983  
    4646 *
    4747 * @param[in] dev Device asking for the addresses.
    48  * @param[out] io_reg_address Base address of the I/O range.
    49  * @param[out] io_reg_size Size of the I/O range.
     48 * @param[out] io_regs_p Pointer to register I/O range.
    5049 * @param[out] irq_no IRQ assigned to the device.
    5150 * @return Error code.
    5251 */
    53 int get_my_registers(ddf_dev_t *dev,
    54     uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no)
     52int get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p, int *irq_no)
    5553{
    5654        assert(dev);
     
    7674        }
    7775
    78         if (io_reg_address)
    79                 *io_reg_address = hw_res.io_ranges.ranges[0].address;
    80         if (io_reg_size)
    81                 *io_reg_size = hw_res.io_ranges.ranges[0].size;
     76        if (io_regs_p)
     77                *io_regs_p = hw_res.io_ranges.ranges[0];
    8278        if (irq_no)
    8379                *irq_no = hw_res.irqs.irqs[0];
  • uspace/drv/bus/usb/uhci/res.h

    r820104d rc2a6983  
    3737
    3838#include <ddf/driver.h>
     39#include <device/hw_res_parsed.h>
    3940
    40 int get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *);
     41int get_my_registers(ddf_dev_t *, addr_range_t *, int *);
    4142int enable_interrupts(ddf_dev_t *);
    4243int disable_legacy(ddf_dev_t *);
  • uspace/drv/bus/usb/uhci/uhci.c

    r820104d rc2a6983  
    184184        ddf_fun_data_implant(instance->rh_fun, &instance->rh);
    185185
    186         uintptr_t reg_base = 0;
    187         size_t reg_size = 0;
     186        addr_range_t regs;
    188187        int irq = 0;
    189188
    190         rc = get_my_registers(device, &reg_base, &reg_size, &irq);
     189        rc = get_my_registers(device, &regs, &irq);
    191190        if (rc != EOK) {
    192191                usb_log_error("Failed to get I/O addresses for %" PRIun ": %s.\n",
     
    194193                goto error;
    195194        }
    196         usb_log_debug("I/O regs at 0x%p (size %zu), IRQ %d.\n",
    197             (void *) reg_base, reg_size, irq);
     195        usb_log_debug("I/O regs at %p (size %zu), IRQ %d.\n",
     196            RNGABSPTR(regs), RNGSZ(regs), irq);
    198197
    199198        rc = disable_legacy(device);
     
    204203        }
    205204
    206         rc = hc_register_irq_handler(device, reg_base, reg_size, irq, irq_handler);
     205        rc = hc_register_irq_handler(device, &regs, irq, irq_handler);
    207206        if (rc != EOK) {
    208207                usb_log_error("Failed to register interrupt handler: %s.\n",
     
    223222        }
    224223
    225         rc = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts);
     224        rc = hc_init(&instance->hc, &regs, interrupts);
    226225        if (rc != EOK) {
    227226                usb_log_error("Failed to init uhci_hcd: %s.\n", str_error(rc));
  • uspace/drv/bus/usb/uhci/utils/malloc32.h

    r820104d rc2a6983  
    9292 */
    9393static inline void free32(void *addr)
    94         { free(addr); }
     94{
     95        free(addr);
     96}
    9597
    9698/** Create 4KB page mapping
     
    98100 * @return Address of the mapped page, NULL on failure.
    99101 */
    100 static inline void * get_page(void)
     102static inline void *get_page(void)
    101103{
    102         void *address, *phys;
     104        uintptr_t phys;
     105        void *address;
     106       
    103107        const int ret = dmamem_map_anonymous(UHCI_REQUIRED_PAGE_SIZE,
    104             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &address);
    105         return ret == EOK ? address : NULL;
     108            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
     109            &address);
     110       
     111        return ((ret == EOK) ? address : NULL);
    106112}
    107113
  • uspace/drv/bus/usb/uhcirh/main.c

    r820104d rc2a6983  
    4848#define NAME "uhcirh"
    4949
    50 static int hc_get_my_registers(ddf_dev_t *dev,
    51     uintptr_t *io_reg_address, size_t *io_reg_size);
     50static int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs);
    5251
    5352static int uhci_rh_dev_add(ddf_dev_t *device);
     
    9089            ddf_dev_get_handle(device));
    9190
    92         uintptr_t io_regs = 0;
    93         size_t io_size = 0;
     91        addr_range_t regs;
    9492        uhci_root_hub_t *rh = NULL;
    9593        int rc;
    9694
    97         rc = hc_get_my_registers(device, &io_regs, &io_size);
     95        rc = hc_get_my_registers(device, &regs);
    9896        if (rc != EOK) {
    9997                usb_log_error( "Failed to get registers from HC: %s.\n",
     
    103101
    104102        usb_log_debug("I/O regs at %p (size %zuB).\n",
    105             (void *) io_regs, io_size);
     103            RNGABSPTR(regs), RNGSZ(regs));
    106104
    107105        rh = ddf_dev_data_alloc(device, sizeof(uhci_root_hub_t));
     
    111109        }
    112110
    113         rc = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
     111        rc = uhci_root_hub_init(rh, &regs, device);
    114112        if (rc != EOK) {
    115113                usb_log_error("Failed(%d) to initialize rh driver instance: "
     
    127125 *
    128126 * @param[in] dev Device asking for the addresses.
    129  * @param[out] io_reg_address Base address of the memory range.
    130  * @param[out] io_reg_size Size of the memory range.
     127 * @param[out] io_regs_p Pointer to the device's register range.
    131128 * @return Error code.
    132129 */
    133 int hc_get_my_registers(
    134     ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size)
     130int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p)
    135131{
    136132        async_sess_t *parent_sess =
     
    153149        }
    154150
    155         if (io_reg_address != NULL)
    156                 *io_reg_address = hw_res.io_ranges.ranges[0].address;
    157 
    158         if (io_reg_size != NULL)
    159                 *io_reg_size = hw_res.io_ranges.ranges[0].size;
     151        if (io_regs_p != NULL)
     152                *io_regs_p = hw_res.io_ranges.ranges[0];
    160153
    161154        hw_res_list_parsed_clean(&hw_res);
  • uspace/drv/bus/usb/uhcirh/root_hub.c

    r820104d rc2a6983  
    3636#include <ddi.h>
    3737#include <usb/debug.h>
     38#include <device/hw_res_parsed.h>
    3839
    3940#include "root_hub.h"
     
    4243 *
    4344 * @param[in] instance Driver memory structure to use.
    44  * @param[in] addr Address of I/O registers.
    45  * @param[in] size Size of available I/O space.
     45 * @param[in] io_regs Range of I/O registers.
    4646 * @param[in] rh Pointer to DDF instance of the root hub driver.
    4747 * @return Error code.
    4848 */
    49 int uhci_root_hub_init(
    50   uhci_root_hub_t *instance, void *addr, size_t size, ddf_dev_t *rh)
     49int uhci_root_hub_init(uhci_root_hub_t *instance, addr_range_t *io_regs,
     50    ddf_dev_t *rh)
    5151{
     52        port_status_t *regs;
     53
    5254        assert(instance);
    5355        assert(rh);
    5456
    5557        /* Allow access to root hub port registers */
    56         assert(sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT <= size);
    57         port_status_t *regs;
    58         int ret = pio_enable(addr, size, (void**)&regs);
     58        assert(sizeof(*regs) * UHCI_ROOT_HUB_PORT_COUNT <= io_regs->size);
     59
     60        int ret = pio_enable_range(io_regs, (void **) &regs);
    5961        if (ret < 0) {
    6062                usb_log_error(
    6163                    "Failed(%d) to gain access to port registers at %p: %s.\n",
    62                     ret, regs, str_error(ret));
     64                    ret, RNGABSPTR(*io_regs), str_error(ret));
    6365                return ret;
    6466        }
  • uspace/drv/bus/usb/uhcirh/root_hub.h

    r820104d rc2a6983  
    3636
    3737#include <ddf/driver.h>
     38#include <device/hw_res_parsed.h>
    3839
    3940#include "port.h"
     
    4849} uhci_root_hub_t;
    4950
    50 int uhci_root_hub_init(
    51     uhci_root_hub_t *instance, void *addr, size_t size, ddf_dev_t *rh);
     51int uhci_root_hub_init(uhci_root_hub_t *instance, addr_range_t *regs,
     52    ddf_dev_t *rh);
    5253
    5354void uhci_root_hub_fini(uhci_root_hub_t *instance);
  • uspace/drv/bus/usb/usbmid/explore.c

    r820104d rc2a6983  
    5656static bool interface_in_list(const list_t *list, int interface_no)
    5757{
    58         list_foreach(*list, l) {
    59                 usbmid_interface_t *iface = usbmid_interface_from_link(l);
     58        list_foreach(*list, link, usbmid_interface_t, iface) {
    6059                if (iface->interface_no == interface_no) {
    6160                        return true;
     
    190189
    191190        /* Start child function for every interface. */
    192         list_foreach(usb_mid->interface_list, link) {
    193                 usbmid_interface_t *iface = usbmid_interface_from_link(link);
    194 
     191        list_foreach(usb_mid->interface_list, link, usbmid_interface_t, iface) {
    195192                usb_log_info("Creating child for interface %d (%s).\n",
    196193                    iface->interface_no,
  • uspace/drv/bus/usb/usbmid/usbmid.c

    r820104d rc2a6983  
    135135        }
    136136
    137         list_foreach(match_ids.ids, link) {
    138                 match_id_t *match_id = list_get_instance(link, match_id_t, link);
     137        list_foreach(match_ids.ids, link, match_id_t, match_id) {
    139138                rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
    140139                if (rc != EOK) {
  • uspace/drv/bus/usb/vhc/transfer.c

    r820104d rc2a6983  
    9292
    9393        bool target_found = false;
    94         list_foreach(vhc->devices, pos) {
    95                 vhc_virtdev_t *dev = list_get_instance(pos, vhc_virtdev_t, link);
     94        list_foreach(vhc->devices, link, vhc_virtdev_t, dev) {
    9695                fibril_mutex_lock(&dev->guard);
    9796                if (dev->address == transfer->address) {
  • uspace/drv/char/i8042/i8042.c

    r820104d rc2a6983  
    145145 *
    146146 * @param dev       Driver structure to initialize.
    147  * @param regs      I/O address of registers.
    148  * @param reg_size  size of the reserved I/O address space.
     147 * @param regs      I/O range  of registers.
    149148 * @param irq_kbd   IRQ for primary port.
    150149 * @param irq_mouse IRQ for aux port.
     
    154153 *
    155154 */
    156 int i8042_init(i8042_t *dev, void *regs, size_t reg_size, int irq_kbd,
     155int i8042_init(i8042_t *dev, addr_range_t *regs, int irq_kbd,
    157156    int irq_mouse, ddf_dev_t *ddf_dev)
    158157{
     
    162161        const size_t cmd_count = sizeof(i8042_cmds) / sizeof(irq_cmd_t);
    163162        irq_cmd_t cmds[cmd_count];
     163        i8042_regs_t *ar;
    164164
    165165        int rc;
     
    170170        dev->aux_fun = NULL;
    171171       
    172         if (reg_size < sizeof(i8042_regs_t)) {
     172        if (regs->size < sizeof(i8042_regs_t)) {
    173173                rc = EINVAL;
    174174                goto error;
    175175        }
    176176       
    177         if (pio_enable(regs, sizeof(i8042_regs_t), (void **) &dev->regs) != 0) {
     177        if (pio_enable_range(regs, (void **) &dev->regs) != 0) {
    178178                rc = EIO;
    179179                goto error;
     
    234234
    235235        memcpy(ranges, i8042_ranges, sizeof(i8042_ranges));
    236         ranges[0].base = (uintptr_t) regs;
    237 
     236        ranges[0].base = RNGABS(*regs);
     237
     238
     239        ar = RNGABSPTR(*regs);
    238240        memcpy(cmds, i8042_cmds, sizeof(i8042_cmds));
    239         cmds[0].addr = (void *) &(((i8042_regs_t *) regs)->status);
    240         cmds[3].addr = (void *) &(((i8042_regs_t *) regs)->data);
     241        cmds[0].addr = (void *) &ar->status;
     242        cmds[3].addr = (void *) &ar->data;
    241243
    242244        irq_code_t irq_code = {
  • uspace/drv/char/i8042/i8042.h

    r820104d rc2a6983  
    6868} i8042_t;
    6969
    70 int i8042_init(i8042_t *, void *, size_t, int, int, ddf_dev_t *);
     70int i8042_init(i8042_t *, addr_range_t *, int, int, ddf_dev_t *);
    7171
    7272#endif
  • uspace/drv/char/i8042/main.c

    r820104d rc2a6983  
    4949 *
    5050 * @param[in]  dev            Device asking for the addresses.
    51  * @param[out] io_reg_address Base address of the memory range.
    52  * @param[out] io_reg_size    Size of the memory range.
     51 * @param[out] p_io_reg       Pointer to register range.
    5352 * @param[out] kbd_irq        Primary port IRQ.
    5453 * @param[out] mouse_irq      Auxiliary port IRQ.
     
    5756 *
    5857 */
    59 static int get_my_registers(ddf_dev_t *dev, uintptr_t *io_reg_address,
    60     size_t *io_reg_size, int *kbd_irq, int *mouse_irq)
     58static int get_my_registers(ddf_dev_t *dev, addr_range_t *p_io_reg,
     59    int *kbd_irq, int *mouse_irq)
    6160{
    6261        assert(dev);
     
    7978        }
    8079       
    81         if (io_reg_address)
    82                 *io_reg_address = hw_resources.io_ranges.ranges[0].address;
    83        
    84         if (io_reg_size)
    85                 *io_reg_size = hw_resources.io_ranges.ranges[0].size;
     80        if (p_io_reg)
     81                *p_io_reg = hw_resources.io_ranges.ranges[0];
    8682       
    8783        if (kbd_irq)
     
    104100static int i8042_dev_add(ddf_dev_t *device)
    105101{
    106         uintptr_t io_regs = 0;
    107         size_t io_size = 0;
     102        addr_range_t io_regs;
    108103        int kbd = 0;
    109104        int mouse = 0;
     
    113108                return EINVAL;
    114109       
    115         rc = get_my_registers(device, &io_regs, &io_size, &kbd, &mouse);
     110        rc = get_my_registers(device, &io_regs, &kbd, &mouse);
    116111        if (rc != EOK) {
    117112                ddf_msg(LVL_ERROR, "Failed to get registers: %s.",
     
    120115        }
    121116       
    122         ddf_msg(LVL_DEBUG, "I/O regs at %p (size %zuB), IRQ kbd %d, IRQ mouse %d.",
    123             (void *) io_regs, io_size, kbd, mouse);
     117        ddf_msg(LVL_DEBUG,
     118            "I/O regs at %p (size %zuB), IRQ kbd %d, IRQ mouse %d.",
     119            RNGABSPTR(io_regs), RNGSZ(io_regs), kbd, mouse);
    124120       
    125121        i8042_t *i8042 = ddf_dev_data_alloc(device, sizeof(i8042_t));
     
    129125        }
    130126       
    131         rc = i8042_init(i8042, (void *) io_regs, io_size, kbd, mouse, device);
     127        rc = i8042_init(i8042, &io_regs, kbd, mouse, device);
    132128        if (rc != EOK) {
    133129                ddf_msg(LVL_ERROR, "Failed to initialize i8042 driver: %s.",
  • uspace/drv/fb/amdm37x_dispc/amdm37x_dispc.c

    r820104d rc2a6983  
    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");
    280281                return ret;
    281282        }
     283       
    282284        amdm37x_dispc_setup_fb(dispc->regs, x, y, bpp *8, (uint32_t)pa);
    283285        dispc->active_fb.idx = mode.index;
  • uspace/drv/fb/kfb/port.c

    r820104d rc2a6983  
    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/infrastructure/root/root.c

    r820104d rc2a6983  
    208208        /*
    209209         * Register virtual devices root.
    210          * We ignore error occurrence because virtual devices shall not be
     210         * We warn on error occurrence because virtual devices shall not be
    211211         * vital for the system.
    212212         */
    213         (void) add_virtual_root_fun(dev);
     213        int res = add_virtual_root_fun(dev);
     214        if (res != EOK)
     215                ddf_msg(LVL_WARN, "Failed to add virtual child.");
    214216
    215217        /* Register root device's children. */
    216         int res = add_platform_fun(dev);
     218        res = add_platform_fun(dev);
    217219        if (EOK != res)
    218220                ddf_msg(LVL_ERROR, "Failed adding child device for platform.");
  • uspace/drv/infrastructure/rootamdm37x/rootamdm37x.c

    r820104d rc2a6983  
    4848
    4949typedef struct {
     50        const char *name;
     51        match_id_t match_id;
    5052        hw_resource_list_t hw_resources;
    5153} rootamdm37x_fun_t;
    5254
    53 /* See amdm37x TRM page. 3316 for these values */
    54 #define OHCI_BASE_ADDRESS  0x48064400
    55 #define OHCI_SIZE  1024
    56 #define EHCI_BASE_ADDRESS  0x48064800
    57 #define EHCI_SIZE  1024
     55/* See amdm37x TRM page 3316 for these values */
     56#define OHCI_BASE_ADDRESS   0x48064400
     57#define OHCI_SIZE   1024
     58#define EHCI_BASE_ADDRESS   0x48064800
     59#define EHCI_SIZE   1024
     60
     61/* See amdm37x TRM page 1813 for these values */
     62#define DSS_BASE_ADDRESS   0x48050000
     63#define DSS_SIZE   512
     64#define DISPC_BASE_ADDRESS   0x48050400
     65#define DISPC_SIZE   1024
     66#define VIDEO_ENC_BASE_ADDRESS   0x48050C00
     67#define VIDEO_ENC_SIZE   256
     68
    5869
    5970static hw_resource_t ohci_res[] = {
     
    8899};
    89100
    90 static const rootamdm37x_fun_t ohci = {
    91         .hw_resources = {
    92             .resources = ohci_res,
    93             .count = sizeof(ohci_res)/sizeof(ohci_res[0]),
    94         }
    95 };
    96 
    97 static const rootamdm37x_fun_t ehci = {
    98         .hw_resources = {
    99             .resources = ehci_res,
    100             .count = sizeof(ehci_res) / sizeof(ehci_res[0]),
    101         }
    102 };
     101static hw_resource_t disp_res[] = {
     102        {
     103                .type = MEM_RANGE,
     104                .res.io_range = {
     105                        .address = DSS_BASE_ADDRESS,
     106                        .size = DSS_SIZE,
     107                        .endianness = LITTLE_ENDIAN
     108                },
     109        },
     110        {
     111                .type = MEM_RANGE,
     112                .res.io_range = {
     113                        .address = DISPC_BASE_ADDRESS,
     114                        .size = DISPC_SIZE,
     115                        .endianness = LITTLE_ENDIAN
     116                },
     117        },
     118        {
     119                .type = MEM_RANGE,
     120                .res.io_range = {
     121                        .address = VIDEO_ENC_BASE_ADDRESS,
     122                        .size = VIDEO_ENC_SIZE,
     123                        .endianness = LITTLE_ENDIAN
     124                },
     125        },
     126        {
     127                .type = INTERRUPT,
     128                .res.interrupt = { .irq = 25 },
     129        },
     130};
     131
     132static const rootamdm37x_fun_t amdm37x_funcs[] = {
     133{
     134        .name = "ohci",
     135        .match_id = { .id = "usb/host=ohci", .score = 90 },
     136        .hw_resources = { .resources = ohci_res, .count = ARRAY_SIZE(ohci_res) }
     137},
     138{
     139        .name = "ehci",
     140        .match_id = { .id = "usb/host=ehci", .score = 90 },
     141        .hw_resources = { .resources = ehci_res, .count = ARRAY_SIZE(ehci_res) }
     142},
     143{
     144        .name = "fb",
     145        .match_id = { .id = "amdm37x&dispc", .score = 90 },
     146        .hw_resources = { .resources = disp_res, .count = ARRAY_SIZE(disp_res) }
     147},
     148};
     149
    103150
    104151static hw_resource_list_t *rootamdm37x_get_resources(ddf_fun_t *fnode);
     
    114161};
    115162
    116 static int rootamdm37x_add_fun(ddf_dev_t *dev, const char *name,
    117     const char *str_match_id, const rootamdm37x_fun_t *fun)
    118 {
    119         ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
    120        
     163static int rootamdm37x_add_fun(ddf_dev_t *dev, const rootamdm37x_fun_t *fun)
     164{
     165        assert(dev);
     166        assert(fun);
     167
     168        ddf_msg(LVL_DEBUG, "Adding new function '%s'.", fun->name);
     169
    121170        /* Create new device function. */
    122         ddf_fun_t *fnode = ddf_fun_create(dev, fun_inner, name);
     171        ddf_fun_t *fnode = ddf_fun_create(dev, fun_inner, fun->name);
    123172        if (fnode == NULL)
    124173                return ENOMEM;
    125174       
    126175        /* Add match id */
    127         int ret = ddf_fun_add_match_id(fnode, str_match_id, 100);
     176        int ret = ddf_fun_add_match_id(fnode,
     177            fun->match_id.id, fun->match_id.score);
    128178        if (ret != EOK) {
    129179                ddf_fun_destroy(fnode);
     
    146196        ret = ddf_fun_bind(fnode);
    147197        if (ret != EOK) {
    148                 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
     198                ddf_msg(LVL_ERROR, "Failed binding function %s.", fun->name);
    149199                ddf_fun_destroy(fnode);
    150200                return ret;
     
    189239
    190240        /* Register functions */
    191         if (rootamdm37x_add_fun(dev, "ohci", "usb/host=ohci", &ohci) != EOK)
    192                 ddf_msg(LVL_ERROR, "Failed to add OHCI function for "
    193                     "BeagleBoard-xM platform.");
    194         if (rootamdm37x_add_fun(dev, "ehci", "usb/host=ehci", &ehci) != EOK)
    195                 ddf_msg(LVL_ERROR, "Failed to add EHCI function for "
    196                     "BeagleBoard-xM platform.");
    197         if (rootamdm37x_add_fun(dev, "dispc", "amdm37x&dispc", &ehci) != EOK)
    198                 ddf_msg(LVL_ERROR, "Failed to add dispc function for "
    199                     "BeagleBoard-xM platform.");
    200 
     241        for (unsigned i = 0; i < ARRAY_SIZE(amdm37x_funcs); ++i) {
     242                if (rootamdm37x_add_fun(dev, &amdm37x_funcs[i]) != EOK)
     243                        ddf_msg(LVL_ERROR, "Failed to add %s function for "
     244                            "BeagleBoard-xM platform.", amdm37x_funcs[i].name);
     245        }
    201246        return EOK;
    202247}
  • uspace/drv/infrastructure/rootamdm37x/uhh.h

    r820104d rc2a6983  
    8585#define UHH_DEBUG_CSR_EHCI_SIMULATION_MODE_FLAG  (1 << 6)
    8686#define UHH_DEBUG_CSR_OHCI_CNTSEL_FLAG  (1 << 7)
    87 #define UHH_DEBUG_CSR_OHCI_GLOBAL_sUSPEND_FLAG  (1 << 16)
     87#define UHH_DEBUG_CSR_OHCI_GLOBAL_SUSPEND_FLAG  (1 << 16)
    8888#define UHH_DEBUG_CSR_OHCI_CCS1_FLAG  (1 << 17)
    8989#define UHH_DEBUG_CSR_OHCI_CCS2_FLAG  (1 << 18)
  • uspace/drv/infrastructure/rootmac/rootmac.c

    r820104d rc2a6983  
    5454                        .address = 0xfec00000,
    5555                        .size = 4,
     56                        .relative = false,
    5657                        .endianness = LITTLE_ENDIAN
    5758                }
     
    6263                        .address = 0xfee00000,
    6364                        .size = 4,
     65                        .relative = false,
    6466                        .endianness = LITTLE_ENDIAN
    6567                }
  • uspace/drv/infrastructure/rootpc/rootpc.c

    r820104d rc2a6983  
    5151#include <ops/hw_res.h>
    5252#include <device/hw_res.h>
     53#include <ops/pio_window.h>
     54#include <device/pio_window.h>
    5355
    5456#define NAME "rootpc"
     
    5658typedef struct rootpc_fun {
    5759        hw_resource_list_t hw_resources;
     60        pio_window_t pio_window;
    5861} rootpc_fun_t;
    5962
     
    7881                        .address = 0xCF8,
    7982                        .size = 4,
     83                        .relative = false,
    8084                        .endianness = LITTLE_ENDIAN
    8185                }
     
    8690                        .address = 0xCFC,
    8791                        .size = 4,
     92                        .relative = false,
    8893                        .endianness = LITTLE_ENDIAN
    8994                }
     
    9398static rootpc_fun_t pci_data = {
    9499        .hw_resources = {
    95                 sizeof(pci_conf_regs)/sizeof(pci_conf_regs[0]),
     100                sizeof(pci_conf_regs) / sizeof(pci_conf_regs[0]),
    96101                pci_conf_regs
     102        },
     103        .pio_window = {
     104                .mem = {
     105                        .base = UINT32_C(0),
     106                        .size = UINT32_C(0xffffffff) /* practical maximum */
     107                },
     108                .io = {
     109                        .base = UINT32_C(0),
     110                        .size = UINT32_C(0x10000)
     111                }
    97112        }
    98113};
     
    117132       
    118133        return false;
     134}
     135
     136static pio_window_t *rootpc_get_pio_window(ddf_fun_t *fnode)
     137{
     138        rootpc_fun_t *fun = rootpc_fun(fnode);
     139       
     140        assert(fun != NULL);
     141        return &fun->pio_window;
    119142}
    120143
     
    122145        .get_resource_list = &rootpc_get_resources,
    123146        .enable_interrupt = &rootpc_enable_interrupt,
     147};
     148
     149static pio_window_ops_t fun_pio_window_ops = {
     150        .get_pio_window = &rootpc_get_pio_window
    124151};
    125152
     
    197224        ddf_log_init(NAME);
    198225        rootpc_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
     226        rootpc_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
    199227}
    200228
  • uspace/drv/nic/e1k/e1k.c

    r820104d rc2a6983  
    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       
     
    19371941        e1000->irq = hw_resources->irqs.irqs[0];
    19381942        e1000->reg_base_phys =
    1939             MEMADDR_TO_PTR(hw_resources->mem_ranges.ranges[0].address);
     1943            MEMADDR_TO_PTR(RNGABS(hw_resources->mem_ranges.ranges[0]));
    19401944       
    19411945        return EOK;
  • uspace/drv/nic/ne2k/ne2k.c

    r820104d rc2a6983  
    211211        ne2k->irq = hw_res_parsed.irqs.irqs[0];
    212212       
    213         ne2k->base_port = (void *) (uintptr_t)
    214             hw_res_parsed.io_ranges.ranges[0].address;
     213        addr_range_t regs = hw_res_parsed.io_ranges.ranges[0];
     214        ne2k->base_port = RNGABSPTR(regs);
    215215       
    216216        hw_res_list_parsed_clean(&hw_res_parsed);
    217217       
    218         /* Enable port I/O */
    219         if (pio_enable(ne2k->base_port, NE2K_IO_SIZE, &ne2k->port) != EOK)
     218        /* Enable programmed I/O */
     219        if (pio_enable_range(&regs, &ne2k->port) != EOK)
    220220                return EADDRNOTAVAIL;
    221        
    222221       
    223222        ne2k->data_port = ne2k->port + NE2K_DATA;
  • uspace/drv/nic/rtl8139/driver.c

    r820104d rc2a6983  
    10871087        ddf_msg(LVL_DEBUG, "%s device: irq 0x%x assigned", ddf_dev_get_name(dev), rtl8139->irq);
    10881088
    1089         rtl8139->io_addr = IOADDR_TO_PTR(hw_resources->io_ranges.ranges[0].address);
     1089        rtl8139->io_addr = IOADDR_TO_PTR(RNGABS(hw_resources->io_ranges.ranges[0]));
    10901090        if (hw_resources->io_ranges.ranges[0].size < RTL8139_IO_SIZE) {
    10911091                ddf_msg(LVL_ERROR, "i/o range assigned to the device "
     
    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

    r820104d rc2a6983  
    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.