Changes in / [695b6ff:ddd0499d] in mainline
- Location:
- uspace
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/main.c
r695b6ff rddd0499d 49 49 50 50 static 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); 51 static 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); 54 53 static int sb_enable_interrupts(ddf_dev_t *device); 55 54 … … 103 102 } 104 103 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; 107 108 int irq = 0, dma8 = 0, dma16 = 0; 108 109 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); 111 111 if (rc != EOK) { 112 112 ddf_log_error("Failed to get resources: %s.", str_error(rc)); … … 114 114 } 115 115 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); 117 117 118 118 irq_code_t irq_code = { … … 139 139 } 140 140 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); 143 142 if (rc != EOK) { 144 143 ddf_log_error("Failed to init sb16 driver: %s.", … … 147 146 } 148 147 149 rc = sb16_init_mpu(soft_state, (void*)mpu_regs, mpu_regs_size);148 rc = sb16_init_mpu(soft_state, p_mpu_regs); 150 149 if (rc == EOK) { 151 150 ddf_fun_t *mpu_fun = … … 173 172 } 174 173 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) 174 static 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) 178 176 { 179 177 assert(device); … … 225 223 } 226 224 227 228 225 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; 233 230 } else { 234 231 const int sb = 235 232 (hw_res.io_ranges.ranges[0].size >= sizeof(sb16_regs_t)) 236 ? 1 : 0;233 ? 0 : 1; 237 234 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]; 246 239 } 247 240 … … 261 254 return enabled ? EOK : EIO; 262 255 } 256 263 257 /** 264 258 * @} -
uspace/drv/audio/sb16/sb16.c
r695b6ff rddd0499d 77 77 } 78 78 79 void sb16_irq_code(void *regs, int dma8, int dma16, irq_cmd_t cmds[], irq_pio_range_t ranges[]) 79 void sb16_irq_code(addr_range_t *regs, int dma8, int dma16, irq_cmd_t cmds[], 80 irq_pio_range_t ranges[]) 80 81 { 81 82 assert(regs); 82 83 assert(dma8 > 0 && dma8 < 4); 83 sb16_regs_t *registers = regs; 84 85 sb16_regs_t *registers = RNGABSPTR(*regs); 84 86 memcpy(cmds, irq_cmds, sizeof(irq_cmds)); 85 cmds[0].addr = (void *)®isters->dsp_read_status;86 ranges[0].base = (uintptr_t) registers;87 cmds[0].addr = (void *) ®isters->dsp_read_status; 88 ranges[0].base = (uintptr_t) registers; 87 89 ranges[0].size = sizeof(*registers); 88 90 if (dma16 > 4 && dma16 < 8) { 89 91 /* Valid dma16 */ 90 cmds[1].addr = (void *)®isters->dma16_ack;92 cmds[1].addr = (void *) ®isters->dma16_ack; 91 93 } else { 92 94 cmds[1].cmd = CMD_ACCEPT; … … 94 96 } 95 97 96 int sb16_init_sb16(sb16_t *sb, void *regs, size_t size,97 ddf_dev_t *dev, int dma8,int dma16)98 int sb16_init_sb16(sb16_t *sb, addr_range_t *regs, ddf_dev_t *dev, int dma8, 99 int dma16) 98 100 { 99 101 assert(sb); 102 100 103 /* Setup registers */ 101 int ret = pio_enable (regs, size, (void**)&sb->regs);104 int ret = pio_enable_range(regs, (void **) &sb->regs); 102 105 if (ret != EOK) 103 106 return ret; 104 ddf_log_ debug("PIO registers at %p accessible.", sb->regs);107 ddf_log_note("PIO registers at %p accessible.", sb->regs); 105 108 106 109 /* Initialize DSP */ … … 187 190 } 188 191 189 int sb16_init_mpu(sb16_t *sb, void *regs, size_t size)192 int sb16_init_mpu(sb16_t *sb, addr_range_t *regs) 190 193 { 191 194 sb->mpu_regs = NULL; -
uspace/drv/audio/sb16/sb16.h
r695b6ff rddd0499d 38 38 #include <ddf/driver.h> 39 39 #include <ddi.h> 40 #include <device/hw_res_parsed.h> 40 41 41 42 #include "dsp.h" … … 51 52 52 53 size_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); 54 void sb16_irq_code(addr_range_t *regs, int dma8, int dma16, irq_cmd_t cmds[], irq_pio_range_t ranges[]); 55 int sb16_init_sb16(sb16_t *sb, addr_range_t *regs, ddf_dev_t *dev, int dma8, int dma16); 56 int sb16_init_mpu(sb16_t *sb, addr_range_t *regs); 57 57 void sb16_interrupt(sb16_t *sb); 58 58 -
uspace/drv/block/ahci/ahci.c
r695b6ff rddd0499d 1157 1157 ahci->memregs = NULL; 1158 1158 1159 physmem_map( (uintptr_t) (hw_res_parsed.mem_ranges.ranges[0].address),1159 physmem_map(RNGABS(hw_res_parsed.mem_ranges.ranges[0]), 1160 1160 AHCI_MEMREGS_PAGES_COUNT, AS_AREA_READ | AS_AREA_WRITE, 1161 1161 (void **) &ahci->memregs); … … 1164 1164 1165 1165 /* 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]); 1167 1167 ahci_ranges[0].size = sizeof(ahci_memregs_t); 1168 1168 … … 1171 1171 1172 1172 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])) + 1174 1174 AHCI_PORTS_REGISTERS_OFFSET + port * AHCI_PORT_REGISTERS_SIZE + 1175 1175 AHCI_PORT_IS_REGISTER_OFFSET; … … 1177 1177 1178 1178 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])) + 1180 1180 AHCI_GHC_IS_REGISTER_OFFSET; 1181 1181 ahci_cmds[base + 4].addr = ahci_cmds[base + 3].addr; -
uspace/drv/block/ata_bd/main.c
r695b6ff rddd0499d 84 84 } 85 85 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)) { 90 92 rc = EINVAL; 91 93 goto error; 92 94 } 93 95 94 if ( hw_res.io_ranges.ranges[1].size< sizeof(ata_cmd_t)) {96 if (RNGSZ(*cmd_rng) < sizeof(ata_cmd_t)) { 95 97 rc = EINVAL; 96 98 goto error; -
uspace/drv/bus/isa/isa.c
r695b6ff rddd0499d 65 65 #include <ddf/log.h> 66 66 #include <ops/hw_res.h> 67 #include <ops/pio_window.h> 67 68 68 69 #include <device/hw_res.h> … … 104 105 } 105 106 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;107 static 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; 112 113 } 113 114 … … 116 117 /* This is an old ugly way, copied from pci driver */ 117 118 assert(fnode); 118 isa_fun_t * isa= isa_fun(fnode);119 assert( isa);119 isa_fun_t *fun = isa_fun(fnode); 120 assert(fun); 120 121 121 122 sysarg_t apic; … … 133 134 return false; 134 135 135 const hw_resource_list_t *res = & isa->hw_resources;136 const hw_resource_list_t *res = &fun->hw_resources; 136 137 assert(res); 137 138 for (size_t i = 0; i < res->count; ++i) { … … 159 160 { 160 161 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; 164 165 assert(res); 165 166 … … 182 183 assert(size); 183 184 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; 187 188 assert(res); 188 189 … … 201 202 202 203 static 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, 204 205 .enable_interrupt = isa_fun_enable_interrupt, 205 206 .dma_channel_setup = isa_fun_setup_dma, … … 207 208 }; 208 209 210 static 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 219 static pio_window_ops_t isa_fun_pio_window_ops = { 220 .get_pio_window = isa_fun_get_pio_window 221 }; 222 209 223 static ddf_dev_ops_t isa_fun_ops= { 210 224 .interfaces[HW_RES_DEV_IFACE] = &isa_fun_hw_res_ops, 225 .interfaces[PIO_WINDOW_DEV_IFACE] = &isa_fun_pio_window_ops, 211 226 }; 212 227 … … 414 429 resources[count].res.io_range.address += isa->pio_win.io.base; 415 430 resources[count].res.io_range.size = len; 431 resources[count].res.io_range.relative = false; 416 432 resources[count].res.io_range.endianness = LITTLE_ENDIAN; 417 433 -
uspace/drv/bus/pci/pciintel/pci.c
r695b6ff rddd0499d 256 256 fibril_mutex_lock(&bus->conf_mutex); 257 257 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)); 259 259 260 260 /* … … 263 263 * support shorter PIO reads offset from this register. 264 264 */ 265 val = uint32_t_le2host(pio_read_32(bus->conf_data_ port));265 val = uint32_t_le2host(pio_read_32(bus->conf_data_reg)); 266 266 267 267 switch (len) { … … 299 299 * missing bits first. 300 300 */ 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)); 303 303 } 304 304 … … 317 317 } 318 318 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)); 321 321 322 322 fibril_mutex_unlock(&bus->conf_mutex); … … 449 449 hw_resources[count].res.io_range.address = range_addr; 450 450 hw_resources[count].res.io_range.size = range_size; 451 hw_resources[count].res.io_range.relative = true; 451 452 hw_resources[count].res.io_range.endianness = LITTLE_ENDIAN; 452 453 } else { … … 454 455 hw_resources[count].res.mem_range.address = range_addr; 455 456 hw_resources[count].res.mem_range.size = range_size; 457 hw_resources[count].res.mem_range.relative = false; 456 458 hw_resources[count].res.mem_range.endianness = LITTLE_ENDIAN; 457 459 } … … 722 724 hw_resources.resources[1].res.io_range.address); 723 725 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)) { 731 728 ddf_msg(LVL_ERROR, "Failed to enable configuration ports."); 732 729 rc = EADDRNOTAVAIL; 733 730 goto fail; 734 731 } 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)) { 737 734 ddf_msg(LVL_ERROR, "Failed to enable configuration ports."); 738 735 rc = EADDRNOTAVAIL; -
uspace/drv/bus/pci/pciintel/pci.h
r695b6ff rddd0499d 45 45 /** DDF device node */ 46 46 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; 51 49 pio_window_t pio_win; 52 50 fibril_mutex_t conf_mutex; -
uspace/drv/bus/usb/ehci/main.c
r695b6ff rddd0499d 77 77 assert(device); 78 78 79 uintptr_t reg_base = 0; 80 size_t reg_size = 0; 79 addr_range_t reg_range; 81 80 int irq = 0; 82 81 83 int rc = get_my_registers(device, ®_ base, ®_size, &irq);82 int rc = get_my_registers(device, ®_range, &irq); 84 83 if (rc != EOK) { 85 84 usb_log_error("Failed to get memory addresses for %" PRIun … … 88 87 } 89 88 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); 92 91 93 rc = disable_legacy(device, reg_base, reg_size);92 rc = disable_legacy(device, ®_range); 94 93 if (rc != EOK) { 95 94 usb_log_error("Failed to disable legacy USB: %s.\n", -
uspace/drv/bus/usb/ehci/res.c
r695b6ff rddd0499d 71 71 * 72 72 * @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. 75 74 * @param[out] irq_no IRQ assigned to the device. 76 75 * @return Error code. 77 76 */ 78 77 int 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) 80 79 { 81 80 assert(dev); … … 99 98 } 100 99 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]; 105 102 if (irq_no) 106 103 *irq_no = hw_res.irqs.irqs[0]; … … 267 264 } 268 265 269 int disable_legacy(ddf_dev_t *device, uintptr_t reg_base, size_t reg_size)266 int disable_legacy(ddf_dev_t *device, addr_range_t *reg_range) 270 267 { 271 268 assert(device); … … 274 271 /* Map EHCI registers */ 275 272 void *regs = NULL; 276 int rc = pio_enable ((void*)reg_base, reg_size, ®s);273 int rc = pio_enable_range(reg_range, ®s); 277 274 if (rc != EOK) { 278 275 usb_log_error("Failed to map registers %p: %s.\n", 279 (void *) reg_base, str_error(rc));276 RNGABSPTR(*reg_range), str_error(rc)); 280 277 return rc; 281 278 } -
uspace/drv/bus/usb/ehci/res.h
r695b6ff rddd0499d 37 37 38 38 #include <ddf/driver.h> 39 #include <device/hw_res_parsed.h> 39 40 40 int get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *);41 int get_my_registers(ddf_dev_t *, addr_range_t *, int *); 41 42 int enable_interrupts(ddf_dev_t *); 42 int disable_legacy(ddf_dev_t *, uintptr_t, size_t);43 int disable_legacy(ddf_dev_t *, addr_range_t *); 43 44 44 45 #endif -
uspace/drv/bus/usb/ohci/hc.c
r695b6ff rddd0499d 106 106 * @param[out] cmds Commands buffer. 107 107 * @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. 110 109 * 111 110 * @return Error code. … … 113 112 int 114 113 hc_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) 116 115 { 117 116 if ((ranges_size < sizeof(ohci_pio_ranges)) || 118 117 (cmds_size < sizeof(ohci_irq_commands)) || 119 ( reg_size< sizeof(ohci_regs_t)))118 (RNGSZ(*regs) < sizeof(ohci_regs_t))) 120 119 return EOVERFLOW; 121 120 122 121 memcpy(ranges, ohci_pio_ranges, sizeof(ohci_pio_ranges)); 123 ranges[0].base = regs;122 ranges[0].base = RNGABS(*regs); 124 123 125 124 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); 127 126 cmds[0].addr = (void *) ®isters->interrupt_status; 128 127 cmds[3].addr = (void *) ®isters->interrupt_status; … … 135 134 * 136 135 * @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 139 137 * @param[in] irq Interrupt number 140 138 * @paran[in] handler Interrupt handler … … 142 140 * @return EOK on success or negative error code 143 141 */ 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)142 int hc_register_irq_handler(ddf_dev_t *device, addr_range_t *regs, int irq, 143 interrupt_handler_t handler) 146 144 { 147 145 int rc; … … 158 156 159 157 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); 161 159 if (rc != EOK) { 162 160 usb_log_error("Failed to generate IRQ code: %s.\n", … … 259 257 * 260 258 * @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. 263 260 * @param[in] interrupts True if w interrupts should be used 264 261 * @return Error code 265 262 */ 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); 263 int 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); 272 268 if (rc != EOK) { 273 269 usb_log_error("Failed to gain access to device registers: %s.\n", -
uspace/drv/bus/usb/ohci/hc.h
r695b6ff rddd0499d 75 75 } hc_t; 76 76 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); 77 int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t, 78 addr_range_t *); 79 int hc_register_irq_handler(ddf_dev_t *, addr_range_t *, int, 80 interrupt_handler_t); 80 81 int 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);82 int hc_init(hc_t *instance, addr_range_t *regs, bool interrupts); 82 83 83 84 /** Safely dispose host controller internal structures -
uspace/drv/bus/usb/ohci/ohci.c
r695b6ff rddd0499d 177 177 ddf_fun_set_ops(instance->rh_fun, &rh_ops); 178 178 179 uintptr_t reg_base = 0; 180 size_t reg_size = 0; 179 addr_range_t regs; 181 180 int irq = 0; 182 181 183 rc = get_my_registers(device, ® _base, ®_size, &irq);182 rc = get_my_registers(device, ®s, &irq); 184 183 if (rc != EOK) { 185 184 usb_log_error("Failed to get register memory addresses " … … 190 189 191 190 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, ®s, irq, irq_handler); 195 194 if (rc != EOK) { 196 195 usb_log_error("Failed to register interrupt handler: %s.\n", … … 215 214 } 216 215 217 rc = hc_init(&instance->hc, reg_base, reg_size, interrupts);216 rc = hc_init(&instance->hc, ®s, interrupts); 218 217 if (rc != EOK) { 219 218 usb_log_error("Failed to init ohci_hcd: %s.\n", str_error(rc)); -
uspace/drv/bus/usb/ohci/res.c
r695b6ff rddd0499d 48 48 * 49 49 * @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. 52 51 * @param[out] irq_no IRQ assigned to the device. 53 52 * @return Error code. 54 53 */ 55 int get_my_registers(ddf_dev_t *dev, 56 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no) 54 int get_my_registers(ddf_dev_t *dev, addr_range_t *p_regs, int *irq_no) 57 55 { 58 56 assert(dev); … … 66 64 hw_res_list_parsed_t hw_res; 67 65 hw_res_list_parsed_init(&hw_res); 68 const int ret = 66 const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0); 69 67 async_hangup(parent_sess); 70 68 if (ret != EOK) { … … 78 76 } 79 77 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]; 84 80 if (irq_no) 85 81 *irq_no = hw_res.irqs.irqs[0]; -
uspace/drv/bus/usb/ohci/res.h
r695b6ff rddd0499d 36 36 37 37 #include <ddf/driver.h> 38 #include <device/hw_res_parsed.h> 38 39 39 int get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *);40 int get_my_registers(ddf_dev_t *, addr_range_t *, int *); 40 41 int enable_interrupts(ddf_dev_t *); 41 42 -
uspace/drv/bus/usb/uhci/hc.c
r695b6ff rddd0499d 105 105 * @param[out] cmds Commands buffer. 106 106 * @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. 109 108 * 110 109 * @return Error code. … … 112 111 int 113 112 hc_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) 115 114 { 116 115 if ((ranges_size < sizeof(uhci_irq_pio_ranges)) || 117 116 (cmds_size < sizeof(uhci_irq_commands)) || 118 ( reg_size< sizeof(uhci_regs_t)))117 (RNGSZ(*regs) < sizeof(uhci_regs_t))) 119 118 return EOVERFLOW; 120 119 121 120 memcpy(ranges, uhci_irq_pio_ranges, sizeof(uhci_irq_pio_ranges)); 122 ranges[0].base = regs;121 ranges[0].base = RNGABS(*regs); 123 122 124 123 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); 126 125 cmds[0].addr = ®isters->usbsts; 127 126 cmds[3].addr = ®isters->usbsts; … … 133 132 * 134 133 * @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 137 135 * @param[in] irq Interrupt number 138 136 * @paran[in] handler Interrupt handler … … 140 138 * @return EOK on success or negative error code 141 139 */ 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)140 int hc_register_irq_handler(ddf_dev_t *device, addr_range_t *regs, int irq, 141 interrupt_handler_t handler) 144 142 { 145 143 int rc; … … 147 145 irq_cmd_t irq_cmds[hc_irq_cmd_count]; 148 146 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); 150 148 if (rc != EOK) { 151 149 usb_log_error("Failed to generate IRQ commands: %s.\n", … … 232 230 * 233 231 * @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. 236 233 * @param[in] interrupts True if hw interrupts should be used. 237 234 * @return Error code. … … 241 238 * interrupt fibrils. 242 239 */ 243 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interrupts)244 { 245 assert(reg _size >= sizeof(uhci_regs_t));240 int hc_init(hc_t *instance, addr_range_t *regs, bool interrupts) 241 { 242 assert(regs->size >= sizeof(uhci_regs_t)); 246 243 int rc; 247 244 … … 251 248 /* allow access to hc control registers */ 252 249 uhci_regs_t *io; 253 rc = pio_enable (regs, reg_size, (void **)&io);250 rc = pio_enable_range(regs, (void **) &io); 254 251 if (rc != EOK) { 255 252 usb_log_error("Failed to gain access to registers at %p: %s.\n", … … 260 257 instance->registers = io; 261 258 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); 263 260 264 261 rc = hc_init_mem_structures(instance); -
uspace/drv/bus/usb/uhci/hc.h
r695b6ff rddd0499d 37 37 38 38 #include <ddf/interrupt.h> 39 #include <device/hw_res_parsed.h> 39 40 #include <fibril.h> 40 41 #include <usb/host/hcd.h> … … 120 121 } hc_t; 121 122 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); 123 int hc_register_irq_handler(ddf_dev_t *, addr_range_t *, int, 124 interrupt_handler_t); 125 int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t, 126 addr_range_t *); 125 127 void hc_interrupt(hc_t *instance, uint16_t status); 126 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interupts);128 int hc_init(hc_t *instance, addr_range_t *regs, bool interupts); 127 129 128 130 /** Safely dispose host controller internal structures … … 132 134 static inline void hc_fini(hc_t *instance) {} /* TODO: implement*/ 133 135 #endif 136 134 137 /** 135 138 * @} -
uspace/drv/bus/usb/uhci/res.c
r695b6ff rddd0499d 46 46 * 47 47 * @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. 50 49 * @param[out] irq_no IRQ assigned to the device. 51 50 * @return Error code. 52 51 */ 53 int get_my_registers(ddf_dev_t *dev, 54 uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no) 52 int get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p, int *irq_no) 55 53 { 56 54 assert(dev); … … 76 74 } 77 75 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]; 82 78 if (irq_no) 83 79 *irq_no = hw_res.irqs.irqs[0]; -
uspace/drv/bus/usb/uhci/res.h
r695b6ff rddd0499d 37 37 38 38 #include <ddf/driver.h> 39 #include <device/hw_res_parsed.h> 39 40 40 int get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *);41 int get_my_registers(ddf_dev_t *, addr_range_t *, int *); 41 42 int enable_interrupts(ddf_dev_t *); 42 43 int disable_legacy(ddf_dev_t *); -
uspace/drv/bus/usb/uhci/uhci.c
r695b6ff rddd0499d 184 184 ddf_fun_data_implant(instance->rh_fun, &instance->rh); 185 185 186 uintptr_t reg_base = 0; 187 size_t reg_size = 0; 186 addr_range_t regs; 188 187 int irq = 0; 189 188 190 rc = get_my_registers(device, ® _base, ®_size, &irq);189 rc = get_my_registers(device, ®s, &irq); 191 190 if (rc != EOK) { 192 191 usb_log_error("Failed to get I/O addresses for %" PRIun ": %s.\n", … … 194 193 goto error; 195 194 } 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); 198 197 199 198 rc = disable_legacy(device); … … 204 203 } 205 204 206 rc = hc_register_irq_handler(device, reg_base, reg_size, irq, irq_handler);205 rc = hc_register_irq_handler(device, ®s, irq, irq_handler); 207 206 if (rc != EOK) { 208 207 usb_log_error("Failed to register interrupt handler: %s.\n", … … 223 222 } 224 223 225 rc = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts);224 rc = hc_init(&instance->hc, ®s, interrupts); 226 225 if (rc != EOK) { 227 226 usb_log_error("Failed to init uhci_hcd: %s.\n", str_error(rc)); -
uspace/drv/bus/usb/uhcirh/main.c
r695b6ff rddd0499d 48 48 #define NAME "uhcirh" 49 49 50 static int hc_get_my_registers(ddf_dev_t *dev, 51 uintptr_t *io_reg_address, size_t *io_reg_size); 50 static int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs); 52 51 53 52 static int uhci_rh_dev_add(ddf_dev_t *device); … … 90 89 ddf_dev_get_handle(device)); 91 90 92 uintptr_t io_regs = 0; 93 size_t io_size = 0; 91 addr_range_t regs; 94 92 uhci_root_hub_t *rh = NULL; 95 93 int rc; 96 94 97 rc = hc_get_my_registers(device, & io_regs, &io_size);95 rc = hc_get_my_registers(device, ®s); 98 96 if (rc != EOK) { 99 97 usb_log_error( "Failed to get registers from HC: %s.\n", … … 103 101 104 102 usb_log_debug("I/O regs at %p (size %zuB).\n", 105 (void *) io_regs, io_size);103 RNGABSPTR(regs), RNGSZ(regs)); 106 104 107 105 rh = ddf_dev_data_alloc(device, sizeof(uhci_root_hub_t)); … … 111 109 } 112 110 113 rc = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);111 rc = uhci_root_hub_init(rh, ®s, device); 114 112 if (rc != EOK) { 115 113 usb_log_error("Failed(%d) to initialize rh driver instance: " … … 127 125 * 128 126 * @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. 131 128 * @return Error code. 132 129 */ 133 int hc_get_my_registers( 134 ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size) 130 int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p) 135 131 { 136 132 async_sess_t *parent_sess = … … 153 149 } 154 150 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]; 160 153 161 154 hw_res_list_parsed_clean(&hw_res); -
uspace/drv/bus/usb/uhcirh/root_hub.c
r695b6ff rddd0499d 36 36 #include <ddi.h> 37 37 #include <usb/debug.h> 38 #include <device/hw_res_parsed.h> 38 39 39 40 #include "root_hub.h" … … 42 43 * 43 44 * @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. 46 46 * @param[in] rh Pointer to DDF instance of the root hub driver. 47 47 * @return Error code. 48 48 */ 49 int uhci_root_hub_init( 50 uhci_root_hub_t *instance, void *addr, size_t size,ddf_dev_t *rh)49 int uhci_root_hub_init(uhci_root_hub_t *instance, addr_range_t *io_regs, 50 ddf_dev_t *rh) 51 51 { 52 port_status_t *regs; 53 52 54 assert(instance); 53 55 assert(rh); 54 56 55 57 /* 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**)®s);58 assert(sizeof(*regs) * UHCI_ROOT_HUB_PORT_COUNT <= io_regs->size); 59 60 int ret = pio_enable_range(io_regs, (void **) ®s); 59 61 if (ret < 0) { 60 62 usb_log_error( 61 63 "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)); 63 65 return ret; 64 66 } -
uspace/drv/bus/usb/uhcirh/root_hub.h
r695b6ff rddd0499d 36 36 37 37 #include <ddf/driver.h> 38 #include <device/hw_res_parsed.h> 38 39 39 40 #include "port.h" … … 48 49 } uhci_root_hub_t; 49 50 50 int uhci_root_hub_init( 51 uhci_root_hub_t *instance, void *addr, size_t size,ddf_dev_t *rh);51 int uhci_root_hub_init(uhci_root_hub_t *instance, addr_range_t *regs, 52 ddf_dev_t *rh); 52 53 53 54 void uhci_root_hub_fini(uhci_root_hub_t *instance); -
uspace/drv/char/i8042/i8042.c
r695b6ff rddd0499d 145 145 * 146 146 * @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. 149 148 * @param irq_kbd IRQ for primary port. 150 149 * @param irq_mouse IRQ for aux port. … … 154 153 * 155 154 */ 156 int i8042_init(i8042_t *dev, void *regs, size_t reg_size, int irq_kbd,155 int i8042_init(i8042_t *dev, addr_range_t *regs, int irq_kbd, 157 156 int irq_mouse, ddf_dev_t *ddf_dev) 158 157 { … … 162 161 const size_t cmd_count = sizeof(i8042_cmds) / sizeof(irq_cmd_t); 163 162 irq_cmd_t cmds[cmd_count]; 163 i8042_regs_t *ar; 164 164 165 165 int rc; … … 170 170 dev->aux_fun = NULL; 171 171 172 if (reg _size < sizeof(i8042_regs_t)) {172 if (regs->size < sizeof(i8042_regs_t)) { 173 173 rc = EINVAL; 174 174 goto error; 175 175 } 176 176 177 if (pio_enable (regs, sizeof(i8042_regs_t), (void **) &dev->regs) != 0) {177 if (pio_enable_range(regs, (void **) &dev->regs) != 0) { 178 178 rc = EIO; 179 179 goto error; … … 234 234 235 235 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); 238 240 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; 241 243 242 244 irq_code_t irq_code = { -
uspace/drv/char/i8042/i8042.h
r695b6ff rddd0499d 68 68 } i8042_t; 69 69 70 int i8042_init(i8042_t *, void *, size_t, int, int, ddf_dev_t *);70 int i8042_init(i8042_t *, addr_range_t *, int, int, ddf_dev_t *); 71 71 72 72 #endif -
uspace/drv/char/i8042/main.c
r695b6ff rddd0499d 49 49 * 50 50 * @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. 53 52 * @param[out] kbd_irq Primary port IRQ. 54 53 * @param[out] mouse_irq Auxiliary port IRQ. … … 57 56 * 58 57 */ 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)58 static int get_my_registers(ddf_dev_t *dev, addr_range_t *p_io_reg, 59 int *kbd_irq, int *mouse_irq) 61 60 { 62 61 assert(dev); … … 79 78 } 80 79 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]; 86 82 87 83 if (kbd_irq) … … 104 100 static int i8042_dev_add(ddf_dev_t *device) 105 101 { 106 uintptr_t io_regs = 0; 107 size_t io_size = 0; 102 addr_range_t io_regs; 108 103 int kbd = 0; 109 104 int mouse = 0; … … 113 108 return EINVAL; 114 109 115 rc = get_my_registers(device, &io_regs, & io_size, &kbd, &mouse);110 rc = get_my_registers(device, &io_regs, &kbd, &mouse); 116 111 if (rc != EOK) { 117 112 ddf_msg(LVL_ERROR, "Failed to get registers: %s.", … … 120 115 } 121 116 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); 124 120 125 121 i8042_t *i8042 = ddf_dev_data_alloc(device, sizeof(i8042_t)); … … 129 125 } 130 126 131 rc = i8042_init(i8042, (void *) io_regs, io_size, kbd, mouse, device);127 rc = i8042_init(i8042, &io_regs, kbd, mouse, device); 132 128 if (rc != EOK) { 133 129 ddf_msg(LVL_ERROR, "Failed to initialize i8042 driver: %s.", -
uspace/drv/infrastructure/rootmac/rootmac.c
r695b6ff rddd0499d 54 54 .address = 0xfec00000, 55 55 .size = 4, 56 .relative = false, 56 57 .endianness = LITTLE_ENDIAN 57 58 } … … 62 63 .address = 0xfee00000, 63 64 .size = 4, 65 .relative = false, 64 66 .endianness = LITTLE_ENDIAN 65 67 } -
uspace/drv/infrastructure/rootmalta/rootmalta.c
r695b6ff rddd0499d 99 99 .address = GT_BASE + GT_PCI_CONFADDR, 100 100 .size = 4, 101 .relative = false, 101 102 .endianness = LITTLE_ENDIAN 102 103 } … … 107 108 .address = GT_BASE + GT_PCI_CONFDATA, 108 109 .size = 4, 110 .relative = false, 109 111 .endianness = LITTLE_ENDIAN 110 112 } -
uspace/drv/infrastructure/rootpc/rootpc.c
r695b6ff rddd0499d 81 81 .address = 0xCF8, 82 82 .size = 4, 83 .relative = false, 83 84 .endianness = LITTLE_ENDIAN 84 85 } … … 89 90 .address = 0xCFC, 90 91 .size = 4, 92 .relative = false, 91 93 .endianness = LITTLE_ENDIAN 92 94 } -
uspace/drv/nic/e1k/e1k.c
r695b6ff rddd0499d 1941 1941 e1000->irq = hw_resources->irqs.irqs[0]; 1942 1942 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])); 1944 1944 1945 1945 return EOK; -
uspace/drv/nic/ne2k/ne2k.c
r695b6ff rddd0499d 211 211 ne2k->irq = hw_res_parsed.irqs.irqs[0]; 212 212 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); 215 215 216 216 hw_res_list_parsed_clean(&hw_res_parsed); 217 217 218 /* Enable p ortI/O */219 if (pio_enable (ne2k->base_port, NE2K_IO_SIZE, &ne2k->port) != EOK)218 /* Enable programmed I/O */ 219 if (pio_enable_range(®s, &ne2k->port) != EOK) 220 220 return EADDRNOTAVAIL; 221 222 221 223 222 ne2k->data_port = ne2k->port + NE2K_DATA; -
uspace/drv/nic/rtl8139/driver.c
r695b6ff rddd0499d 1087 1087 ddf_msg(LVL_DEBUG, "%s device: irq 0x%x assigned", ddf_dev_get_name(dev), rtl8139->irq); 1088 1088 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])); 1090 1090 if (hw_resources->io_ranges.ranges[0].size < RTL8139_IO_SIZE) { 1091 1091 ddf_msg(LVL_ERROR, "i/o range assigned to the device " -
uspace/lib/c/generic/ddi.c
r695b6ff rddd0499d 42 42 #include <ddi.h> 43 43 #include <libarch/ddi.h> 44 #include <device/hw_res.h> 45 #include <device/hw_res_parsed.h> 46 #include <device/pio_window.h> 44 47 #include <libc.h> 45 48 #include <task.h> … … 134 137 135 138 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 */ 146 int 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 */ 162 int 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); 136 191 } 137 192 -
uspace/lib/c/generic/device/hw_res_parsed.c
r695b6ff rddd0499d 80 80 } 81 81 82 static 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 90 static 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 82 98 static 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 85 106 assert(res && (res->type == IO_RANGE)); 86 107 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; 90 114 91 115 if ((size == 0) && (!(flags & HW_RES_KEEP_ZERO_AREA))) … … 97 121 if (!keep_duplicit) { 98 122 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]); 101 128 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; 108 137 out->io_ranges.ranges[count].endianness = endianness; 109 out->io_ranges.ranges[count].size = size;110 138 out->io_ranges.count++; 111 139 } 112 140 113 141 static 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 116 149 assert(res && (res->type == MEM_RANGE)); 117 150 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; 121 157 122 158 if ((size == 0) && (!(flags & HW_RES_KEEP_ZERO_AREA))) … … 128 164 if (!keep_duplicit) { 129 165 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]); 132 171 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; 139 180 out->mem_ranges.ranges[count].endianness = endianness; 140 out->mem_ranges.ranges[count].size = size;141 181 out->mem_ranges.count++; 142 182 } … … 144 184 /** Parse list of hardware resources 145 185 * 146 * @param hw_resources Original structure resource147 * @param [out] out Output parsed resources148 * @param flags Flags of the parsing.149 * HW_RES_KEEP_ZERO_AREA for keeping150 * zero-size areas, HW_RES_KEEP_DUPLICITIES151 * for keep duplicit areas186 * @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. 152 192 * 153 193 * @return EOK if succeed, error code otherwise. 154 194 * 155 195 */ 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))196 int 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) 160 200 return EINVAL; 161 201 162 size_t res_count = hw_resources->count;202 size_t res_count = res->count; 163 203 hw_res_list_parsed_clean(out); 164 204 … … 174 214 175 215 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]; 177 217 178 218 switch (resource->type) { … … 181 221 break; 182 222 case IO_RANGE: 183 hw_res_parse_add_io_range(out, resource, flags);223 hw_res_parse_add_io_range(out, win, resource, flags); 184 224 break; 185 225 case MEM_RANGE: 186 hw_res_parse_add_mem_range(out, resource, flags);226 hw_res_parse_add_mem_range(out, win, resource, flags); 187 227 break; 188 228 case DMA_CHANNEL_8: … … 216 256 hw_res_list_parsed_t *hw_res_parsed, int flags) 217 257 { 258 pio_window_t pio_window; 259 int rc; 260 218 261 if (!hw_res_parsed) 219 262 return EBADMEM; … … 222 265 hw_res_list_parsed_clean(hw_res_parsed); 223 266 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); 226 273 if (rc != EOK) 227 274 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); 230 278 hw_res_clean_resource_list(&hw_resources); 231 279 -
uspace/lib/c/include/ddi.h
r695b6ff rddd0499d 40 40 #include <sys/time.h> 41 41 #include <abi/ddi/irq.h> 42 #include <device/hw_res.h> 43 #include <device/hw_res_parsed.h> 44 #include <device/pio_window.h> 42 45 #include <task.h> 43 46 … … 55 58 extern int dmamem_unmap_anonymous(void *); 56 59 60 extern int pio_enable_range(addr_range_t *, void **); 61 extern int pio_enable_resource(pio_window_t *, hw_resource_t *, void **); 57 62 extern int pio_enable(void *, size_t, void **); 58 63 -
uspace/lib/c/include/device/hw_res.h
r695b6ff rddd0499d 76 76 struct { 77 77 uint64_t address; 78 size_t size; 79 bool relative; 78 80 endianness_t endianness; 79 size_t size;80 81 } mem_range; 81 82 82 83 struct { 83 84 uint64_t address; 85 size_t size; 86 bool relative; 84 87 endianness_t endianness; 85 size_t size;86 88 } io_range; 87 89 -
uspace/lib/c/include/device/hw_res_parsed.h
r695b6ff rddd0499d 37 37 38 38 #include <device/hw_res.h> 39 #include <device/pio_window.h> 39 40 #include <str.h> 40 41 … … 45 46 #define HW_RES_KEEP_DUPLICIT 0x2 46 47 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 55 typedef struct address64 { 56 /** Aboslute address. */ 57 uint64_t absolute; 58 /** PIO window base relative address. */ 59 uint64_t relative; 60 } address64_t; 61 47 62 /** Address range structure */ 48 63 typedef struct addr_range { 49 64 /** Start address */ 50 uint64_t address; 51 52 /** Endianness */ 53 endianness_t endianness; 65 address64_t address; 54 66 55 67 /** Area size */ 56 68 size_t size; 69 70 /** Endianness */ 71 endianness_t endianness; 57 72 } addr_range_t; 58 73 … … 139 154 } 140 155 141 extern int hw_res_list_parse(const hw_resource_list_t *,156 extern int hw_res_list_parse(const pio_window_t *, const hw_resource_list_t *, 142 157 hw_res_list_parsed_t *, int); 143 158 extern 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.