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

Changeset ddd0499d in mainline


Ignore:
Timestamp:
2013-09-12T22:05:13Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
4285851
Parents:
695b6ff (diff), 7de1988c (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:

Support for PIO window-relative and absolute HW resource ranges.

The goal of this merge is to allow bus drivers to pass resources with IO
and memory ranges to the child drivers either in the PIO window-relative
form or system bus absolute form. Using the PIO window and the
relative/absolute attribute of a range, each driver can now reconstruct
both forms. Helper functions are provided to automate these
transformations as much as possible.

Changes in this merge in a greater detail:

  • Support for PIO_WINDOW_DEV_IFACE in isa so that it can provide the PIO window to its children.
  • Add 'relative' member to both hw_resource_t.res.mem_range and hw_resource_t.res.io_range so that the drivers can actually tell whether a range is absolute (eg. it was absolutized by its parent).
  • Add pio_enable_resource() to allow drivers to enable PIO without the need to actually care about what kind of range the resource contains. This is used by pci now.
  • Automate things even more for drivers that use hw_res_get_list_parsed(). The parsed HW resources compute both forms (relative/absolute) and offer it to the driver which is using them. Such a driver then uses whatever form is more fit for it and its purposes.
  • Drivers using the parsed resources can use pio_enable_range() to enable PIO and RNGABS*()/RNGREL()/RNGSZ courtesy macros for easier access to the actual range address/size are provided.
  • Device drivers affected by these API changes were converted.
  • uhcirh now requires uhci to provide PIO_WINDOW_DEV_IFACE; however, the uhcirh driver is removed in the feature USB branch so there was no point in implementing this feature and UHCI USB is thus temporarily broken.
Location:
uspace
Files:
38 edited

Legend:

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

    r695b6ff rddd0499d  
    4949
    5050static int sb_add_device(ddf_dev_t *device);
    51 static int sb_get_res(ddf_dev_t *device, uintptr_t *sb_regs,
    52     size_t *sb_regs_size, uintptr_t *mpu_regs, size_t *mpu_regs_size,
    53     int *irq, int *dma8, int *dma16);
     51static int sb_get_res(ddf_dev_t *device, addr_range_t **pp_sb_regs,
     52    addr_range_t **pp_mpu_regs, int *irq, int *dma8, int *dma16);
    5453static int sb_enable_interrupts(ddf_dev_t *device);
    5554
     
    103102        }
    104103
    105         uintptr_t sb_regs = 0, mpu_regs = 0;
    106         size_t sb_regs_size = 0, mpu_regs_size = 0;
     104        addr_range_t sb_regs;
     105        addr_range_t *p_sb_regs = &sb_regs;
     106        addr_range_t mpu_regs;
     107        addr_range_t *p_mpu_regs = &mpu_regs;
    107108        int irq = 0, dma8 = 0, dma16 = 0;
    108109
    109         rc = sb_get_res(device, &sb_regs, &sb_regs_size, &mpu_regs,
    110             &mpu_regs_size, &irq, &dma8, &dma16);
     110        rc = sb_get_res(device, &p_sb_regs, &p_mpu_regs, &irq, &dma8, &dma16);
    111111        if (rc != EOK) {
    112112                ddf_log_error("Failed to get resources: %s.", str_error(rc));
     
    114114        }
    115115
    116         sb16_irq_code((void*)sb_regs, dma8, dma16, irq_cmds, irq_ranges);
     116        sb16_irq_code(p_sb_regs, dma8, dma16, irq_cmds, irq_ranges);
    117117
    118118        irq_code_t irq_code = {
     
    139139        }
    140140
    141         rc = sb16_init_sb16(soft_state, (void*)sb_regs, sb_regs_size, device,
    142             dma8, dma16);
     141        rc = sb16_init_sb16(soft_state, p_sb_regs, device, dma8, dma16);
    143142        if (rc != EOK) {
    144143                ddf_log_error("Failed to init sb16 driver: %s.",
     
    147146        }
    148147
    149         rc = sb16_init_mpu(soft_state, (void*)mpu_regs, mpu_regs_size);
     148        rc = sb16_init_mpu(soft_state, p_mpu_regs);
    150149        if (rc == EOK) {
    151150                ddf_fun_t *mpu_fun =
     
    173172}
    174173
    175 static int sb_get_res(ddf_dev_t *device, uintptr_t *sb_regs,
    176     size_t *sb_regs_size, uintptr_t *mpu_regs, size_t *mpu_regs_size,
    177     int *irq, int *dma8, int *dma16)
     174static int sb_get_res(ddf_dev_t *device, addr_range_t **pp_sb_regs,
     175    addr_range_t **pp_mpu_regs, int *irq, int *dma8, int *dma16)
    178176{
    179177        assert(device);
     
    225223        }
    226224
    227 
    228225        if (hw_res.io_ranges.count == 1) {
    229                 if (sb_regs)
    230                         *sb_regs = hw_res.io_ranges.ranges[0].address;
    231                 if (sb_regs_size)
    232                         *sb_regs_size = hw_res.io_ranges.ranges[0].size;
     226                if (pp_sb_regs && *pp_sb_regs)
     227                        **pp_sb_regs = hw_res.io_ranges.ranges[0];
     228                if (pp_mpu_regs)
     229                        *pp_mpu_regs = NULL;
    233230        } else {
    234231                const int sb =
    235232                    (hw_res.io_ranges.ranges[0].size >= sizeof(sb16_regs_t))
    236                         ? 1 : 0;
     233                        ? 0 : 1;
    237234                const int mpu = 1 - sb;
    238                 if (sb_regs)
    239                         *sb_regs = hw_res.io_ranges.ranges[sb].address;
    240                 if (sb_regs_size)
    241                         *sb_regs_size = hw_res.io_ranges.ranges[sb].size;
    242                 if (mpu_regs)
    243                         *sb_regs = hw_res.io_ranges.ranges[mpu].address;
    244                 if (mpu_regs_size)
    245                         *sb_regs_size = hw_res.io_ranges.ranges[mpu].size;
     235                if (pp_sb_regs && *pp_sb_regs)
     236                        **pp_sb_regs = hw_res.io_ranges.ranges[sb];
     237                if (pp_mpu_regs && *pp_mpu_regs)
     238                        **pp_mpu_regs = hw_res.io_ranges.ranges[mpu];
    246239        }
    247240
     
    261254        return enabled ? EOK : EIO;
    262255}
     256
    263257/**
    264258 * @}
  • uspace/drv/audio/sb16/sb16.c

    r695b6ff rddd0499d  
    7777}
    7878
    79 void sb16_irq_code(void *regs, int dma8, int dma16, irq_cmd_t cmds[], irq_pio_range_t ranges[])
     79void sb16_irq_code(addr_range_t *regs, int dma8, int dma16, irq_cmd_t cmds[],
     80    irq_pio_range_t ranges[])
    8081{
    8182        assert(regs);
    8283        assert(dma8 > 0 && dma8 < 4);
    83         sb16_regs_t *registers = regs;
     84
     85        sb16_regs_t *registers = RNGABSPTR(*regs);
    8486        memcpy(cmds, irq_cmds, sizeof(irq_cmds));
    85         cmds[0].addr = (void*)&registers->dsp_read_status;
    86         ranges[0].base = (uintptr_t)registers;
     87        cmds[0].addr = (void *) &registers->dsp_read_status;
     88        ranges[0].base = (uintptr_t) registers;
    8789        ranges[0].size = sizeof(*registers);
    8890        if (dma16 > 4 && dma16 < 8) {
    8991                /* Valid dma16 */
    90                 cmds[1].addr = (void*)&registers->dma16_ack;
     92                cmds[1].addr = (void *) &registers->dma16_ack;
    9193        } else {
    9294                cmds[1].cmd = CMD_ACCEPT;
     
    9496}
    9597
    96 int sb16_init_sb16(sb16_t *sb, void *regs, size_t size,
    97     ddf_dev_t *dev, int dma8, int dma16)
     98int sb16_init_sb16(sb16_t *sb, addr_range_t *regs, ddf_dev_t *dev, int dma8,
     99    int dma16)
    98100{
    99101        assert(sb);
     102
    100103        /* Setup registers */
    101         int ret = pio_enable(regs, size, (void**)&sb->regs);
     104        int ret = pio_enable_range(regs, (void **) &sb->regs);
    102105        if (ret != EOK)
    103106                return ret;
    104         ddf_log_debug("PIO registers at %p accessible.", sb->regs);
     107        ddf_log_note("PIO registers at %p accessible.", sb->regs);
    105108
    106109        /* Initialize DSP */
     
    187190}
    188191
    189 int sb16_init_mpu(sb16_t *sb, void *regs, size_t size)
     192int sb16_init_mpu(sb16_t *sb, addr_range_t *regs)
    190193{
    191194        sb->mpu_regs = NULL;
  • uspace/drv/audio/sb16/sb16.h

    r695b6ff rddd0499d  
    3838#include <ddf/driver.h>
    3939#include <ddi.h>
     40#include <device/hw_res_parsed.h>
    4041
    4142#include "dsp.h"
     
    5152
    5253size_t sb16_irq_code_size(void);
    53 void sb16_irq_code(void *regs, int dma8, int dma16, irq_cmd_t cmds[], irq_pio_range_t ranges[]);
    54 int sb16_init_sb16(sb16_t *sb, void *regs, size_t size,
    55     ddf_dev_t *dev, int dma8, int dma16);
    56 int sb16_init_mpu(sb16_t *sb, void *regs, size_t size);
     54void sb16_irq_code(addr_range_t *regs, int dma8, int dma16, irq_cmd_t cmds[], irq_pio_range_t ranges[]);
     55int sb16_init_sb16(sb16_t *sb, addr_range_t *regs, ddf_dev_t *dev, int dma8, int dma16);
     56int sb16_init_mpu(sb16_t *sb, addr_range_t *regs);
    5757void sb16_interrupt(sb16_t *sb);
    5858
  • uspace/drv/block/ahci/ahci.c

    r695b6ff rddd0499d  
    11571157        ahci->memregs = NULL;
    11581158       
    1159         physmem_map((uintptr_t) (hw_res_parsed.mem_ranges.ranges[0].address),
     1159        physmem_map(RNGABS(hw_res_parsed.mem_ranges.ranges[0]),
    11601160            AHCI_MEMREGS_PAGES_COUNT, AS_AREA_READ | AS_AREA_WRITE,
    11611161            (void **) &ahci->memregs);
     
    11641164       
    11651165        /* Register interrupt handler */
    1166         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]);
    11671167        ahci_ranges[0].size = sizeof(ahci_memregs_t);
    11681168       
     
    11711171               
    11721172                ahci_cmds[base].addr =
    1173                     ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) +
     1173                    ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +
    11741174                    AHCI_PORTS_REGISTERS_OFFSET + port * AHCI_PORT_REGISTERS_SIZE +
    11751175                    AHCI_PORT_IS_REGISTER_OFFSET;
     
    11771177               
    11781178                ahci_cmds[base + 3].addr =
    1179                     ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) +
     1179                    ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +
    11801180                    AHCI_GHC_IS_REGISTER_OFFSET;
    11811181                ahci_cmds[base + 4].addr = ahci_cmds[base + 3].addr;
  • uspace/drv/block/ata_bd/main.c

    r695b6ff rddd0499d  
    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/isa.c

    r695b6ff rddd0499d  
    6565#include <ddf/log.h>
    6666#include <ops/hw_res.h>
     67#include <ops/pio_window.h>
    6768
    6869#include <device/hw_res.h>
     
    104105}
    105106
    106 static hw_resource_list_t *isa_get_fun_resources(ddf_fun_t *fnode)
    107 {
    108         isa_fun_t *isa = isa_fun(fnode);
    109         assert(isa);
    110 
    111         return &isa->hw_resources;
     107static hw_resource_list_t *isa_fun_get_resources(ddf_fun_t *fnode)
     108{
     109        isa_fun_t *fun = isa_fun(fnode);
     110        assert(fun);
     111
     112        return &fun->hw_resources;
    112113}
    113114
     
    116117        /* This is an old ugly way, copied from pci driver */
    117118        assert(fnode);
    118         isa_fun_t *isa = isa_fun(fnode);
    119         assert(isa);
     119        isa_fun_t *fun = isa_fun(fnode);
     120        assert(fun);
    120121
    121122        sysarg_t apic;
     
    133134                return false;
    134135
    135         const hw_resource_list_t *res = &isa->hw_resources;
     136        const hw_resource_list_t *res = &fun->hw_resources;
    136137        assert(res);
    137138        for (size_t i = 0; i < res->count; ++i) {
     
    159160{
    160161        assert(fnode);
    161         isa_fun_t *isa = isa_fun(fnode);
    162         assert(isa);
    163         const hw_resource_list_t *res = &isa->hw_resources;
     162        isa_fun_t *fun = isa_fun(fnode);
     163        assert(fun);
     164        const hw_resource_list_t *res = &fun->hw_resources;
    164165        assert(res);
    165166
     
    182183        assert(size);
    183184        assert(fnode);
    184         isa_fun_t *isa = isa_fun(fnode);
    185         assert(isa);
    186         const hw_resource_list_t *res = &isa->hw_resources;
     185        isa_fun_t *fun = isa_fun(fnode);
     186        assert(fun);
     187        const hw_resource_list_t *res = &fun->hw_resources;
    187188        assert(res);
    188189
     
    201202
    202203static hw_res_ops_t isa_fun_hw_res_ops = {
    203         .get_resource_list = isa_get_fun_resources,
     204        .get_resource_list = isa_fun_get_resources,
    204205        .enable_interrupt = isa_fun_enable_interrupt,
    205206        .dma_channel_setup = isa_fun_setup_dma,
     
    207208};
    208209
     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
    209223static ddf_dev_ops_t isa_fun_ops= {
    210224        .interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops,
     225        .interfaces[PIO_WINDOW_DEV_IFACE] = &isa_fun_pio_window_ops,
    211226};
    212227
     
    414429                resources[count].res.io_range.address += isa->pio_win.io.base;
    415430                resources[count].res.io_range.size = len;
     431                resources[count].res.io_range.relative = false;
    416432                resources[count].res.io_range.endianness = LITTLE_ENDIAN;
    417433
  • uspace/drv/bus/pci/pciintel/pci.c

    r695b6ff rddd0499d  
    256256        fibril_mutex_lock(&bus->conf_mutex);
    257257
    258         pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));
     258        pio_write_32(bus->conf_addr_reg, host2uint32_t_le(conf_addr));
    259259
    260260        /*
     
    263263         * support shorter PIO reads offset from this register.
    264264         */
    265         val = uint32_t_le2host(pio_read_32(bus->conf_data_port));
     265        val = uint32_t_le2host(pio_read_32(bus->conf_data_reg));
    266266
    267267        switch (len) {
     
    299299                 * missing bits first.
    300300                 */
    301                 pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));
    302                 val = uint32_t_le2host(pio_read_32(bus->conf_data_port));
     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));
    303303        }
    304304       
     
    317317        }
    318318
    319         pio_write_32(bus->conf_addr_port, host2uint32_t_le(conf_addr));
    320         pio_write_32(bus->conf_data_port, host2uint32_t_le(val));
     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));
    321321       
    322322        fibril_mutex_unlock(&bus->conf_mutex);
     
    449449                hw_resources[count].res.io_range.address = range_addr;
    450450                hw_resources[count].res.io_range.size = range_size;
     451                hw_resources[count].res.io_range.relative = true;
    451452                hw_resources[count].res.io_range.endianness = LITTLE_ENDIAN;
    452453        } else {
     
    454455                hw_resources[count].res.mem_range.address = range_addr;
    455456                hw_resources[count].res.mem_range.size = range_size;
     457                hw_resources[count].res.mem_range.relative = false;
    456458                hw_resources[count].res.mem_range.endianness = LITTLE_ENDIAN;
    457459        }
     
    722724            hw_resources.resources[1].res.io_range.address);
    723725       
    724         bus->conf_io_addr =
    725             (uint32_t) hw_resources.resources[0].res.io_range.address;
    726         bus->conf_io_data =
    727             (uint32_t) hw_resources.resources[1].res.io_range.address;
    728        
    729         if (pio_enable((void *)(uintptr_t)bus->conf_io_addr, 4,
    730             &bus->conf_addr_port)) {
     726        if (pio_enable_resource(&bus->pio_win, &hw_resources.resources[0],
     727            (void **) &bus->conf_addr_reg)) {
    731728                ddf_msg(LVL_ERROR, "Failed to enable configuration ports.");
    732729                rc = EADDRNOTAVAIL;
    733730                goto fail;
    734731        }
    735         if (pio_enable((void *)(uintptr_t)bus->conf_io_data, 4,
    736             &bus->conf_data_port)) {
     732        if (pio_enable_resource(&bus->pio_win, &hw_resources.resources[1],
     733            (void **) &bus->conf_data_reg)) {
    737734                ddf_msg(LVL_ERROR, "Failed to enable configuration ports.");
    738735                rc = EADDRNOTAVAIL;
  • uspace/drv/bus/pci/pciintel/pci.h

    r695b6ff rddd0499d  
    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;
    5149        pio_window_t pio_win;
    5250        fibril_mutex_t conf_mutex;
  • uspace/drv/bus/usb/ehci/main.c

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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/uhcirh/main.c

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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/char/i8042/i8042.c

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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/infrastructure/rootmac/rootmac.c

    r695b6ff rddd0499d  
    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/rootmalta/rootmalta.c

    r695b6ff rddd0499d  
    9999                        .address = GT_BASE + GT_PCI_CONFADDR,
    100100                        .size = 4,
     101                        .relative = false,
    101102                        .endianness = LITTLE_ENDIAN
    102103                }
     
    107108                        .address = GT_BASE + GT_PCI_CONFDATA,
    108109                        .size = 4,
     110                        .relative = false,
    109111                        .endianness = LITTLE_ENDIAN
    110112                }
  • uspace/drv/infrastructure/rootpc/rootpc.c

    r695b6ff rddd0499d  
    8181                        .address = 0xCF8,
    8282                        .size = 4,
     83                        .relative = false,
    8384                        .endianness = LITTLE_ENDIAN
    8485                }
     
    8990                        .address = 0xCFC,
    9091                        .size = 4,
     92                        .relative = false,
    9193                        .endianness = LITTLE_ENDIAN
    9294                }
  • uspace/drv/nic/e1k/e1k.c

    r695b6ff rddd0499d  
    19411941        e1000->irq = hw_resources->irqs.irqs[0];
    19421942        e1000->reg_base_phys =
    1943             MEMADDR_TO_PTR(hw_resources->mem_ranges.ranges[0].address);
     1943            MEMADDR_TO_PTR(RNGABS(hw_resources->mem_ranges.ranges[0]));
    19441944       
    19451945        return EOK;
  • uspace/drv/nic/ne2k/ne2k.c

    r695b6ff rddd0499d  
    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

    r695b6ff rddd0499d  
    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 "
  • uspace/lib/c/generic/ddi.c

    r695b6ff rddd0499d  
    4242#include <ddi.h>
    4343#include <libarch/ddi.h>
     44#include <device/hw_res.h>
     45#include <device/hw_res_parsed.h>
     46#include <device/pio_window.h>
    4447#include <libc.h>
    4548#include <task.h>
     
    134137       
    135138        return __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg);
     139}
     140
     141/** Enable PIO for specified address range.
     142 *
     143 * @param range I/O range to be enable.
     144 * @param virt  Virtual address for application's PIO operations.
     145 */
     146int pio_enable_range(addr_range_t *range, void **virt)
     147{
     148        return pio_enable(RNGABSPTR(*range), RNGSZ(*range), virt);
     149}
     150
     151/** Enable PIO for specified HW resource wrt. to the PIO window.
     152 *
     153 * @param win      PIO window. May be NULL if the resources are known to be
     154 *                 absolute.
     155 * @param res      Resources specifying the I/O range wrt. to the PIO window.
     156 * @param virt     Virtual address for application's PIO operations.
     157 *
     158 * @return EOK on success.
     159 * @return Negative error code on failure.
     160 *
     161 */
     162int pio_enable_resource(pio_window_t *win, hw_resource_t *res, void **virt)
     163{
     164        uintptr_t addr;
     165        size_t size;
     166
     167        switch (res->type) {
     168        case IO_RANGE:
     169                addr = res->res.io_range.address;
     170                if (res->res.io_range.relative) {
     171                        if (!win)
     172                                return EINVAL;
     173                        addr += win->io.base;
     174                }
     175                size = res->res.io_range.size;
     176                break;
     177        case MEM_RANGE:
     178                addr = res->res.mem_range.address;
     179                if (res->res.mem_range.relative) {
     180                        if (!win)
     181                                return EINVAL;
     182                        addr += win->mem.base;
     183                }
     184                size = res->res.mem_range.size;
     185                break;
     186        default:
     187                return EINVAL;
     188        }
     189
     190        return pio_enable((void *) addr, size, virt);   
    136191}
    137192
  • uspace/lib/c/generic/device/hw_res_parsed.c

    r695b6ff rddd0499d  
    8080}
    8181
     82static uint64_t absolutize(uint64_t addr, bool relative, uint64_t base)
     83{
     84        if (!relative)
     85                return addr;
     86        else
     87                return addr + base;
     88}
     89
     90static uint64_t relativize(uint64_t addr, bool relative, uint64_t base)
     91{
     92        if (relative)
     93                return addr;
     94        else
     95                return addr - base;
     96}
     97
    8298static void hw_res_parse_add_io_range(hw_res_list_parsed_t *out,
    83     const hw_resource_t *res, int flags)
    84 {
     99    const pio_window_t *win, const hw_resource_t *res, int flags)
     100{
     101        endianness_t endianness;
     102        uint64_t absolute;
     103        uint64_t relative;
     104        size_t size;
     105
    85106        assert(res && (res->type == IO_RANGE));
    86107       
    87         uint64_t address = res->res.io_range.address;
    88         endianness_t endianness = res->res.io_range.endianness;
    89         size_t size = res->res.io_range.size;
     108        absolute = absolutize(res->res.io_range.address,
     109            res->res.io_range.relative, win->io.base);
     110        relative = relativize(res->res.io_range.address,
     111            res->res.io_range.relative, win->io.base);
     112        size = res->res.io_range.size;
     113        endianness = res->res.io_range.endianness;
    90114       
    91115        if ((size == 0) && (!(flags & HW_RES_KEEP_ZERO_AREA)))
     
    97121        if (!keep_duplicit) {
    98122                for (size_t i = 0; i < count; i++) {
    99                         uint64_t s_address = out->io_ranges.ranges[i].address;
    100                         size_t s_size = out->io_ranges.ranges[i].size;
     123                        uint64_t s_address;
     124                        size_t s_size;
     125
     126                        s_address = RNGABS(out->io_ranges.ranges[i]);
     127                        s_size = RNGSZ(out->io_ranges.ranges[i]);
    101128                       
    102                         if ((address == s_address) && (size == s_size))
    103                                 return;
    104                 }
    105         }
    106        
    107         out->io_ranges.ranges[count].address = address;
     129                        if ((absolute == s_address) && (size == s_size))
     130                                return;
     131                }
     132        }
     133       
     134        RNGABS(out->io_ranges.ranges[count]) = absolute;
     135        RNGREL(out->io_ranges.ranges[count]) = relative;
     136        RNGSZ(out->io_ranges.ranges[count]) = size;
    108137        out->io_ranges.ranges[count].endianness = endianness;
    109         out->io_ranges.ranges[count].size = size;
    110138        out->io_ranges.count++;
    111139}
    112140
    113141static void hw_res_parse_add_mem_range(hw_res_list_parsed_t *out,
    114     const hw_resource_t *res, int flags)
    115 {
     142    const pio_window_t *win, const hw_resource_t *res, int flags)
     143{
     144        endianness_t endianness;
     145        uint64_t absolute;
     146        uint64_t relative;
     147        size_t size;
     148       
    116149        assert(res && (res->type == MEM_RANGE));
    117150       
    118         uint64_t address = res->res.mem_range.address;
    119         endianness_t endianness = res->res.mem_range.endianness;
    120         size_t size = res->res.mem_range.size;
     151        absolute = absolutize(res->res.mem_range.address,
     152            res->res.mem_range.relative, win->mem.base);
     153        relative = relativize(res->res.mem_range.address,
     154            res->res.mem_range.relative, win->mem.base);
     155        size = res->res.mem_range.size;
     156        endianness = res->res.mem_range.endianness;
    121157       
    122158        if ((size == 0) && (!(flags & HW_RES_KEEP_ZERO_AREA)))
     
    128164        if (!keep_duplicit) {
    129165                for (size_t i = 0; i < count; ++i) {
    130                         uint64_t s_address = out->mem_ranges.ranges[i].address;
    131                         size_t s_size = out->mem_ranges.ranges[i].size;
     166                        uint64_t s_address;
     167                        size_t s_size;
     168
     169                        s_address = RNGABS(out->mem_ranges.ranges[i]);;
     170                        s_size = RNGSZ(out->mem_ranges.ranges[i]);
    132171                       
    133                         if ((address == s_address) && (size == s_size))
    134                                 return;
    135                 }
    136         }
    137        
    138         out->mem_ranges.ranges[count].address = address;
     172                        if ((absolute == s_address) && (size == s_size))
     173                                return;
     174                }
     175        }
     176       
     177        RNGABS(out->mem_ranges.ranges[count]) = absolute;
     178        RNGREL(out->mem_ranges.ranges[count]) = relative;
     179        RNGSZ(out->mem_ranges.ranges[count]) = size;
    139180        out->mem_ranges.ranges[count].endianness = endianness;
    140         out->mem_ranges.ranges[count].size = size;
    141181        out->mem_ranges.count++;
    142182}
     
    144184/** Parse list of hardware resources
    145185 *
    146  * @param      hw_resources Original structure resource
    147  * @param[out] out          Output parsed resources
    148  * @param      flags        Flags of the parsing.
    149  *                          HW_RES_KEEP_ZERO_AREA for keeping
    150  *                          zero-size areas, HW_RES_KEEP_DUPLICITIES
    151  *                          for keep duplicit areas
     186 * @param      win          PIO window.
     187 * @param      res          Original structure resource.
     188 * @param[out] out          Output parsed resources.
     189 * @param      flags        Flags of the parsing:
     190 *                          HW_RES_KEEP_ZERO_AREA for keeping zero-size areas,
     191 *                          HW_RES_KEEP_DUPLICITIES to keep duplicit areas.
    152192 *
    153193 * @return EOK if succeed, error code otherwise.
    154194 *
    155195 */
    156 int hw_res_list_parse(const hw_resource_list_t *hw_resources,
    157     hw_res_list_parsed_t *out, int flags)
    158 {
    159         if ((!hw_resources) || (!out))
     196int hw_res_list_parse(const pio_window_t *win,
     197    const hw_resource_list_t *res, hw_res_list_parsed_t *out, int flags)
     198{
     199        if (!res || !out)
    160200                return EINVAL;
    161201       
    162         size_t res_count = hw_resources->count;
     202        size_t res_count = res->count;
    163203        hw_res_list_parsed_clean(out);
    164204       
     
    174214       
    175215        for (size_t i = 0; i < res_count; ++i) {
    176                 const hw_resource_t *resource = &(hw_resources->resources[i]);
     216                const hw_resource_t *resource = &res->resources[i];
    177217               
    178218                switch (resource->type) {
     
    181221                        break;
    182222                case IO_RANGE:
    183                         hw_res_parse_add_io_range(out, resource, flags);
     223                        hw_res_parse_add_io_range(out, win, resource, flags);
    184224                        break;
    185225                case MEM_RANGE:
    186                         hw_res_parse_add_mem_range(out, resource, flags);
     226                        hw_res_parse_add_mem_range(out, win, resource, flags);
    187227                        break;
    188228                case DMA_CHANNEL_8:
     
    216256    hw_res_list_parsed_t *hw_res_parsed, int flags)
    217257{
     258        pio_window_t pio_window;
     259        int rc;
     260
    218261        if (!hw_res_parsed)
    219262                return EBADMEM;
     
    222265        hw_res_list_parsed_clean(hw_res_parsed);
    223266        memset(&hw_resources, 0, sizeof(hw_resource_list_t));
    224        
    225         int rc = hw_res_get_resource_list(sess, &hw_resources);
     267
     268        rc = pio_window_get(sess, &pio_window);
     269        if (rc != EOK)
     270                return rc;
     271       
     272        rc = hw_res_get_resource_list(sess, &hw_resources);
    226273        if (rc != EOK)
    227274                return rc;
    228        
    229         rc = hw_res_list_parse(&hw_resources, hw_res_parsed, flags);
     275
     276        rc = hw_res_list_parse(&pio_window, &hw_resources, hw_res_parsed,
     277            flags);
    230278        hw_res_clean_resource_list(&hw_resources);
    231279       
  • uspace/lib/c/include/ddi.h

    r695b6ff rddd0499d  
    4040#include <sys/time.h>
    4141#include <abi/ddi/irq.h>
     42#include <device/hw_res.h>
     43#include <device/hw_res_parsed.h>
     44#include <device/pio_window.h>
    4245#include <task.h>
    4346
     
    5558extern int dmamem_unmap_anonymous(void *);
    5659
     60extern int pio_enable_range(addr_range_t *, void **);
     61extern int pio_enable_resource(pio_window_t *, hw_resource_t *, void **);
    5762extern int pio_enable(void *, size_t, void **);
    5863
  • uspace/lib/c/include/device/hw_res.h

    r695b6ff rddd0499d  
    7676                struct {
    7777                        uint64_t address;
     78                        size_t size;
     79                        bool relative;
    7880                        endianness_t endianness;
    79                         size_t size;
    8081                } mem_range;
    8182               
    8283                struct {
    8384                        uint64_t address;
     85                        size_t size;
     86                        bool relative;
    8487                        endianness_t endianness;
    85                         size_t size;
    8688                } io_range;
    8789               
  • uspace/lib/c/include/device/hw_res_parsed.h

    r695b6ff rddd0499d  
    3737
    3838#include <device/hw_res.h>
     39#include <device/pio_window.h>
    3940#include <str.h>
    4041
     
    4546#define HW_RES_KEEP_DUPLICIT   0x2
    4647
     48
     49#define RNGABS(rng)     (rng).address.absolute
     50#define RNGREL(rng)     (rng).address.relative
     51#define RNGSZ(rng)      (rng).size
     52
     53#define RNGABSPTR(rng)  ((void *) ((uintptr_t) RNGABS((rng))))
     54
     55typedef struct address64 {
     56        /** Aboslute address. */
     57        uint64_t absolute;
     58        /** PIO window base relative address. */
     59        uint64_t relative;
     60} address64_t;
     61
    4762/** Address range structure */
    4863typedef struct addr_range {
    4964        /** Start address */
    50         uint64_t address;
    51        
    52         /** Endianness */
    53         endianness_t endianness;
     65        address64_t address;
    5466       
    5567        /** Area size */
    5668        size_t size;
     69
     70        /** Endianness */
     71        endianness_t endianness;
    5772} addr_range_t;
    5873
     
    139154}
    140155
    141 extern int hw_res_list_parse(const hw_resource_list_t *,
     156extern int hw_res_list_parse(const pio_window_t *, const hw_resource_list_t *,
    142157    hw_res_list_parsed_t *, int);
    143158extern int hw_res_get_list_parsed(async_sess_t *, hw_res_list_parsed_t *, int);
Note: See TracChangeset for help on using the changeset viewer.