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

Changeset 7de1988c in mainline


Ignore:
Timestamp:
2013-09-12T20:53:09Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
ddd0499d
Parents:
8049b79
Message:

Adapt drivers using parsed HW resources to use the new interface.

Location:
uspace/drv
Files:
27 edited

Legend:

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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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/usb/ehci/main.c

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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/nic/e1k/e1k.c

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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

    r8049b79 r7de1988c  
    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 "
Note: See TracChangeset for help on using the changeset viewer.