Changeset cdc8a391 in mainline


Ignore:
Timestamp:
2013-07-12T14:08:06Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
322ac35c
Parents:
98abd40 (diff), b66ffb1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Location:
uspace
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/binutils/toolchain.sh

    r98abd40 rcdc8a391  
    7272                echo '  ld $LD_ARGS'
    7373                echo 'else'
    74                 CFLAGS="`echo " $3" | \
     74                CFLAGS="`echo " $3 " | \
    7575                        sed 's/ -O[^ ]*//g' | \
    7676                        sed 's/ -W[^ ]*//g' | \
    7777                        sed 's/ -pipe//g' | \
    78                         sed 's/ -g//g' | \
     78                        sed 's/ -g[^ ]*//g' | \
    7979                        sed 's/ [ ]*/ /g'`"
    8080                echo '  CONFTEST="`echo \"$*\" | grep '\' conftest \''`"'
  • uspace/app/mkmfs/mkmfs.c

    r98abd40 rcdc8a391  
    649649                mark_bmap(ibmap_buf, i, FREE);
    650650
    651         for (i = sb->first_data_zone + 1; i < sb->n_zones; ++i)
     651        for (i = 2; i < sb->n_zones; ++i)
    652652                mark_bmap(zbmap_buf, i, FREE);
    653653
  • uspace/drv/bus/usb/ehci/main.c

    r98abd40 rcdc8a391  
    3333 * Main routines of EHCI driver.
    3434 */
     35
    3536#include <ddf/driver.h>
    3637#include <ddf/interrupt.h>
    3738#include <device/hw_res.h>
    3839#include <errno.h>
     40#include <stdbool.h>
    3941#include <str_error.h>
    4042
     
    7072static int ehci_dev_add(ddf_dev_t *device)
    7173{
     74        ddf_fun_t *hc_fun = NULL;
     75        bool fun_bound = false;
     76
    7277        assert(device);
    73 #define CHECK_RET_RETURN(ret, message...) \
    74 if (ret != EOK) { \
    75         usb_log_error(message); \
    76         return ret; \
    77 }
    7878
    7979        uintptr_t reg_base = 0;
     
    8181        int irq = 0;
    8282
    83         int ret = get_my_registers(device, &reg_base, &reg_size, &irq);
    84         CHECK_RET_RETURN(ret,
    85             "Failed to get memory addresses for %" PRIun ": %s.\n",
    86             ddf_dev_get_handle(device), str_error(ret));
     83        int rc = get_my_registers(device, &reg_base, &reg_size, &irq);
     84        if (rc != EOK) {
     85                usb_log_error("Failed to get memory addresses for %" PRIun
     86                    ": %s.\n", ddf_dev_get_handle(device), str_error(rc));
     87                goto error;
     88        }
     89
    8790        usb_log_info("Memory mapped regs at 0x%" PRIxn " (size %zu), IRQ %d.\n",
    8891            reg_base, reg_size, irq);
    8992
    90         ret = disable_legacy(device, reg_base, reg_size);
    91         CHECK_RET_RETURN(ret,
    92             "Failed to disable legacy USB: %s.\n", str_error(ret));
     93        rc = disable_legacy(device, reg_base, reg_size);
     94        if (rc != EOK) {
     95                usb_log_error("Failed to disable legacy USB: %s.\n",
     96                    str_error(rc));
     97                goto error;
     98        }
    9399
    94         ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
     100        hc_fun = ddf_fun_create(device, fun_exposed, "ehci_hc");
    95101        if (hc_fun == NULL) {
    96102                usb_log_error("Failed to create EHCI function.\n");
    97                 return ENOMEM;
     103                rc = ENOMEM;
     104                goto error;
    98105        }
     106
    99107        hcd_t *ehci_hc = ddf_fun_data_alloc(hc_fun, sizeof(hcd_t));
    100108        if (ehci_hc == NULL) {
    101109                usb_log_error("Failed to alloc generic HC driver.\n");
    102                 return ENOMEM;
     110                rc = ENOMEM;
     111                goto error;
    103112        }
     113
    104114        /* High Speed, no bandwidth */
    105115        hcd_init(ehci_hc, USB_SPEED_HIGH, 0, NULL);
    106116        ddf_fun_set_ops(hc_fun,  &hc_ops);
    107117
    108         ret = ddf_fun_bind(hc_fun);
    109         CHECK_RET_RETURN(ret,
    110             "Failed to bind EHCI function: %s.\n",
    111             str_error(ret));
    112         ret = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
    113         CHECK_RET_RETURN(ret,
    114             "Failed to add EHCI to HC class: %s.\n",
    115             str_error(ret));
     118        rc = ddf_fun_bind(hc_fun);
     119        if (rc != EOK) {
     120                usb_log_error("Failed to bind EHCI function: %s.\n",
     121                    str_error(rc));
     122                goto error;
     123        }
     124
     125        fun_bound = true;
     126
     127        rc = ddf_fun_add_to_category(hc_fun, USB_HC_CATEGORY);
     128        if (rc != EOK) {
     129                usb_log_error("Failed to add EHCI to HC class: %s.\n",
     130                    str_error(rc));
     131                goto error;
     132        }
    116133
    117134        usb_log_info("Controlling new EHCI device `%s' (handle %" PRIun ").\n",
     
    119136
    120137        return EOK;
    121 #undef CHECK_RET_RETURN
     138error:
     139        if (fun_bound)
     140                ddf_fun_unbind(hc_fun);
     141        if (hc_fun != NULL)
     142                ddf_fun_destroy(hc_fun);
     143        return rc;
    122144}
    123145
  • uspace/drv/bus/usb/ehci/res.c

    r98abd40 rcdc8a391  
    145145                return ENOMEM;
    146146
    147 #define CHECK_RET_HANGUP_RETURN(ret, message...) \
    148         if (ret != EOK) { \
    149                 usb_log_error(message); \
    150                 async_hangup(parent_sess); \
    151                 return ret; \
    152         } else (void)0
    153 
    154147        /* Read the first EEC. i.e. Legacy Support register */
    155148        uint32_t usblegsup;
    156         int ret = pci_config_space_read_32(parent_sess,
     149        int rc = pci_config_space_read_32(parent_sess,
    157150            eecp + USBLEGSUP_OFFSET, &usblegsup);
    158         CHECK_RET_HANGUP_RETURN(ret,
    159             "Failed to read USBLEGSUP: %s.\n", str_error(ret));
     151        if (rc != EOK) {
     152                usb_log_error("Failed to read USBLEGSUP: %s.\n",
     153                    str_error(rc));
     154                goto error;
     155        }
     156
    160157        usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
    161158
     
    163160         * byte. (OS Control semaphore)*/
    164161        usb_log_debug("Requesting OS control.\n");
    165         ret = pci_config_space_write_8(parent_sess,
     162        rc = pci_config_space_write_8(parent_sess,
    166163            eecp + USBLEGSUP_OFFSET + 3, 1);
    167         CHECK_RET_HANGUP_RETURN(ret, "Failed to request OS EHCI control: %s.\n",
    168             str_error(ret));
     164        if (rc != EOK) {
     165                usb_log_error("Failed to request OS EHCI control: %s.\n",
     166                    str_error(rc));
     167                goto error;
     168        }
    169169
    170170        size_t wait = 0;
    171171        /* Wait for BIOS to release control. */
    172         ret = pci_config_space_read_32(
     172        rc = pci_config_space_read_32(
    173173            parent_sess, eecp + USBLEGSUP_OFFSET, &usblegsup);
     174        if (rc != EOK) {
     175                usb_log_error("Failed reading PCI config space: %s.\n",
     176                    str_error(rc));
     177                goto error;
     178        }
     179
    174180        while ((wait < DEFAULT_WAIT) && (usblegsup & USBLEGSUP_BIOS_CONTROL)) {
    175181                async_usleep(WAIT_STEP);
    176                 ret = pci_config_space_read_32(parent_sess,
     182                rc = pci_config_space_read_32(parent_sess,
    177183                    eecp + USBLEGSUP_OFFSET, &usblegsup);
     184                if (rc != EOK) {
     185                        usb_log_error("Failed reading PCI config space: %s.\n",
     186                            str_error(rc));
     187                        goto error;
     188                }
    178189                wait += WAIT_STEP;
    179190        }
     
    188199        usb_log_warning( "BIOS failed to release control after "
    189200            "%zu usecs, force it.\n", wait);
    190         ret = pci_config_space_write_32(parent_sess,
     201        rc = pci_config_space_write_32(parent_sess,
    191202            eecp + USBLEGSUP_OFFSET, USBLEGSUP_OS_CONTROL);
    192         CHECK_RET_HANGUP_RETURN(ret, "Failed to force OS control: "
    193             "%s.\n", str_error(ret));
     203        if (rc != EOK) {
     204                usb_log_error("Failed to force OS control: "
     205                    "%s.\n", str_error(rc));
     206                goto error;
     207        }
     208
    194209        /*
    195210         * Check capability type here, value of 01h identifies the capability
     
    201216                /* Read the second EEC Legacy Support and Control register */
    202217                uint32_t usblegctlsts;
    203                 ret = pci_config_space_read_32(parent_sess,
     218                rc = pci_config_space_read_32(parent_sess,
    204219                    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
    205                 CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS: %s.\n",
    206                     str_error(ret));
     220                if (rc != EOK) {
     221                        usb_log_error("Failed to get USBLEGCTLSTS: %s.\n",
     222                            str_error(rc));
     223                        goto error;
     224                }
     225
    207226                usb_log_debug("USBLEGCTLSTS: %" PRIx32 ".\n", usblegctlsts);
    208227                /*
     
    211230                 * interfering. NOTE: Three upper bits are WC
    212231                 */
    213                 ret = pci_config_space_write_32(parent_sess,
     232                rc = pci_config_space_write_32(parent_sess,
    214233                    eecp + USBLEGCTLSTS_OFFSET, 0xe0000000);
    215                 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) zero USBLEGCTLSTS.\n", ret);
     234                if (rc != EOK) {
     235                        usb_log_error("Failed(%d) zero USBLEGCTLSTS.\n", rc);
     236                        goto error;
     237                }
     238
    216239                udelay(10);
    217                 ret = pci_config_space_read_32(parent_sess,
     240                rc = pci_config_space_read_32(parent_sess,
    218241                    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
    219                 CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS 2: %s.\n",
    220                     str_error(ret));
     242                if (rc != EOK) {
     243                        usb_log_error("Failed to get USBLEGCTLSTS 2: %s.\n",
     244                            str_error(rc));
     245                        goto error;
     246                }
     247
    221248                usb_log_debug("Zeroed USBLEGCTLSTS: %" PRIx32 ".\n",
    222249                    usblegctlsts);
     
    224251
    225252        /* Read again Legacy Support register */
    226         ret = pci_config_space_read_32(parent_sess,
     253        rc = pci_config_space_read_32(parent_sess,
    227254            eecp + USBLEGSUP_OFFSET, &usblegsup);
    228         CHECK_RET_HANGUP_RETURN(ret, "Failed to read USBLEGSUP: %s.\n",
    229             str_error(ret));
     255        if (rc != EOK) {
     256                usb_log_error("Failed to read USBLEGSUP: %s.\n",
     257                    str_error(rc));
     258                goto error;
     259        }
     260
    230261        usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
    231262        async_hangup(parent_sess);
    232263        return EOK;
    233 #undef CHECK_RET_HANGUP_RETURN
     264error:
     265        async_hangup(parent_sess);
     266        return rc;
    234267}
    235268
     
    239272        usb_log_debug("Disabling EHCI legacy support.\n");
    240273
    241 #define CHECK_RET_RETURN(ret, message...) \
    242         if (ret != EOK) { \
    243                 usb_log_error(message); \
    244                 return ret; \
    245         } else (void)0
    246 
    247274        /* Map EHCI registers */
    248275        void *regs = NULL;
    249         int ret = pio_enable((void*)reg_base, reg_size, &regs);
    250         CHECK_RET_RETURN(ret, "Failed to map registers %p: %s.\n",
    251             (void *) reg_base, str_error(ret));
     276        int rc = pio_enable((void*)reg_base, reg_size, &regs);
     277        if (rc != EOK) {
     278                usb_log_error("Failed to map registers %p: %s.\n",
     279                    (void *) reg_base, str_error(rc));
     280                return rc;
     281        }
    252282
    253283        usb_log_debug2("Registers mapped at: %p.\n", regs);
     
    263293        usb_log_debug("Value of EECP: %x.\n", eecp);
    264294
    265         ret = disable_extended_caps(device, eecp);
    266         CHECK_RET_RETURN(ret, "Failed to disable extended capabilities: %s.\n",
    267             str_error(ret));
    268 
    269 #undef CHECK_RET_RETURN
     295        rc = disable_extended_caps(device, eecp);
     296        if (rc != EOK) {
     297                usb_log_error("Failed to disable extended capabilities: %s.\n",
     298                    str_error(rc));
     299                return rc;
     300        }
    270301
    271302        /*
     
    306337            usbcmd, *usbcmd, usbsts, *usbsts, usbint, *usbint, usbconf,*usbconf);
    307338
    308         return ret;
     339        return rc;
    309340}
    310341
  • uspace/drv/bus/usb/ohci/hc.c

    r98abd40 rcdc8a391  
    3535
    3636#include <errno.h>
     37#include <stdbool.h>
    3738#include <str_error.h>
    3839#include <adt/list.h>
     
    183184int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
    184185{
     186        bool addr_reqd = false;
     187        bool ep_added = false;
     188        bool fun_bound = false;
     189        int rc;
     190
    185191        assert(instance);
    186192        assert(hub_fun);
     
    188194        /* Try to get address 1 for root hub. */
    189195        instance->rh.address = 1;
    190         int ret = usb_device_manager_request_address(
     196        rc = usb_device_manager_request_address(
    191197            &instance->generic.dev_manager, &instance->rh.address, false,
    192198            USB_SPEED_FULL);
    193         if (ret != EOK) {
     199        if (rc != EOK) {
    194200                usb_log_error("Failed to get OHCI root hub address: %s\n",
    195                     str_error(ret));
    196                 return ret;
    197         }
    198 
    199 #define CHECK_RET_UNREG_RETURN(ret, message...) \
    200 if (ret != EOK) { \
    201         usb_log_error(message); \
    202         usb_endpoint_manager_remove_ep( \
    203             &instance->generic.ep_manager, instance->rh.address, 0, \
    204             USB_DIRECTION_BOTH, NULL, NULL); \
    205         usb_device_manager_release_address( \
    206             &instance->generic.dev_manager, instance->rh.address); \
    207         return ret; \
    208 } else (void)0
    209 
    210         ret = usb_endpoint_manager_add_ep(
     201                    str_error(rc));
     202                goto error;
     203        }
     204
     205        addr_reqd = true;
     206
     207        rc = usb_endpoint_manager_add_ep(
    211208            &instance->generic.ep_manager, instance->rh.address, 0,
    212209            USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64,
    213210            0, NULL, NULL);
    214         CHECK_RET_UNREG_RETURN(ret,
    215             "Failed to register root hub control endpoint: %s.\n",
    216             str_error(ret));
    217 
    218         ret = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
    219         CHECK_RET_UNREG_RETURN(ret,
    220             "Failed to add root hub match-id: %s.\n", str_error(ret));
    221 
    222         ret = ddf_fun_bind(hub_fun);
    223         CHECK_RET_UNREG_RETURN(ret,
    224             "Failed to bind root hub function: %s.\n", str_error(ret));
    225 
    226         ret = usb_device_manager_bind_address(&instance->generic.dev_manager,
     211        if (rc != EOK) {
     212                usb_log_error("Failed to register root hub control endpoint: %s.\n",
     213                    str_error(rc));
     214                goto error;
     215        }
     216
     217        ep_added = true;
     218
     219        rc = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
     220        if (rc != EOK) {
     221                usb_log_error("Failed to add root hub match-id: %s.\n",
     222                    str_error(rc));
     223                goto error;
     224        }
     225
     226        rc = ddf_fun_bind(hub_fun);
     227        if (rc != EOK) {
     228                usb_log_error("Failed to bind root hub function: %s.\n",
     229                    str_error(rc));
     230                goto error;
     231        }
     232
     233        fun_bound = true;
     234
     235        rc = usb_device_manager_bind_address(&instance->generic.dev_manager,
    227236            instance->rh.address, ddf_fun_get_handle(hub_fun));
    228         if (ret != EOK)
     237        if (rc != EOK) {
    229238                usb_log_warning("Failed to bind root hub address: %s.\n",
    230                     str_error(ret));
    231 
    232         return EOK;
    233 #undef CHECK_RET_RELEASE
     239                    str_error(rc));
     240        }
     241
     242        return EOK;
     243error:
     244        if (fun_bound)
     245                ddf_fun_unbind(hub_fun);
     246        if (ep_added) {
     247                usb_endpoint_manager_remove_ep(
     248                    &instance->generic.ep_manager, instance->rh.address, 0,
     249                    USB_DIRECTION_BOTH, NULL, NULL);
     250        }
     251        if (addr_reqd) {
     252                usb_device_manager_release_address(
     253                    &instance->generic.dev_manager, instance->rh.address);
     254        }
     255        return rc;
    234256}
    235257
     
    246268        assert(instance);
    247269
    248 #define CHECK_RET_RETURN(ret, message...) \
    249 if (ret != EOK) { \
    250         usb_log_error(message); \
    251         return ret; \
    252 } else (void)0
    253 
    254         int ret =
     270        int rc =
    255271            pio_enable((void*)regs, reg_size, (void**)&instance->registers);
    256         CHECK_RET_RETURN(ret,
    257             "Failed to gain access to device registers: %s.\n", str_error(ret));
     272        if (rc != EOK) {
     273                usb_log_error("Failed to gain access to device registers: %s.\n",
     274                    str_error(rc));
     275                return rc;
     276        }
    258277
    259278        list_initialize(&instance->pending_batches);
     
    266285        instance->generic.ep_remove_hook = ohci_endpoint_fini;
    267286
    268         ret = hc_init_memory(instance);
    269         CHECK_RET_RETURN(ret, "Failed to create OHCI memory structures: %s.\n",
    270             str_error(ret));
    271 #undef CHECK_RET_RETURN
     287        rc = hc_init_memory(instance);
     288        if (rc != EOK) {
     289                usb_log_error("Failed to create OHCI memory structures: %s.\n",
     290                    str_error(rc));
     291                return rc;
     292        }
    272293
    273294        fibril_mutex_initialize(&instance->guard);
  • uspace/drv/bus/usb/uhci/hc.c

    r98abd40 rcdc8a391  
    9090static int hc_debug_checker(void *arg);
    9191
    92 
    93 /** Get number of PIO ranges used in IRQ code.
    94  * @return Number of ranges.
    95  */
    96 size_t hc_irq_pio_range_count(void)
    97 {
    98         return sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t);
    99 }
    100 
    101 /** Get number of commands used in IRQ code.
    102  * @return Number of commands.
    103  */
    104 size_t hc_irq_cmd_count(void)
    105 {
    106         return sizeof(uhci_irq_commands) / sizeof(irq_cmd_t);
    107 }
     92enum {
     93        /** Number of PIO ranges used in IRQ code */
     94        hc_irq_pio_range_count =
     95            sizeof(uhci_irq_pio_ranges) / sizeof(irq_pio_range_t),
     96
     97        /* Number of commands used in IRQ code */
     98        hc_irq_cmd_count =
     99            sizeof(uhci_irq_commands) / sizeof(irq_cmd_t)
     100};
    108101
    109102/** Generate IRQ code.
     
    133126        cmds[0].addr = &registers->usbsts;
    134127        cmds[3].addr = &registers->usbsts;
     128
     129        return EOK;
     130}
     131
     132/** Register interrupt handler.
     133 *
     134 * @param[in] device Host controller DDF device
     135 * @param[in] reg_base Register range base
     136 * @param[in] reg_size Register range size
     137 * @param[in] irq Interrupt number
     138 * @paran[in] handler Interrupt handler
     139 *
     140 * @return EOK on success or negative error code
     141 */
     142int hc_register_irq_handler(ddf_dev_t *device, uintptr_t reg_base, size_t reg_size,
     143    int irq, interrupt_handler_t handler)
     144{
     145        int rc;
     146        irq_pio_range_t irq_ranges[hc_irq_pio_range_count];
     147        irq_cmd_t irq_cmds[hc_irq_cmd_count];
     148        rc = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
     149            sizeof(irq_cmds), reg_base, reg_size);
     150        if (rc != EOK) {
     151                usb_log_error("Failed to generate IRQ commands: %s.\n",
     152                    str_error(rc));
     153                return rc;
     154        }
     155
     156        irq_code_t irq_code = {
     157                .rangecount = hc_irq_pio_range_count,
     158                .ranges = irq_ranges,
     159                .cmdcount = hc_irq_cmd_count,
     160                .cmds = irq_cmds
     161        };
     162
     163        /* Register handler to avoid interrupt lockup */
     164        rc = register_interrupt_handler(device, irq, handler, &irq_code);
     165        if (rc != EOK) {
     166                usb_log_error("Failed to register interrupt handler: %s.\n",
     167                    str_error(rc));
     168                return rc;
     169        }
    135170
    136171        return EOK;
     
    209244{
    210245        assert(reg_size >= sizeof(uhci_regs_t));
    211         int ret;
    212 
    213 #define CHECK_RET_RETURN(ret, message...) \
    214         if (ret != EOK) { \
    215                 usb_log_error(message); \
    216                 return ret; \
    217         } else (void) 0
     246        int rc;
    218247
    219248        instance->hw_interrupts = interrupts;
     
    222251        /* allow access to hc control registers */
    223252        uhci_regs_t *io;
    224         ret = pio_enable(regs, reg_size, (void **)&io);
    225         CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p: %s.\n",
    226             io, str_error(ret));
     253        rc = pio_enable(regs, reg_size, (void **)&io);
     254        if (rc != EOK) {
     255                usb_log_error("Failed to gain access to registers at %p: %s.\n",
     256                    io, str_error(rc));
     257                return rc;
     258        }
     259
    227260        instance->registers = io;
    228261        usb_log_debug(
    229262            "Device registers at %p (%zuB) accessible.\n", io, reg_size);
    230263
    231         ret = hc_init_mem_structures(instance);
    232         CHECK_RET_RETURN(ret,
    233             "Failed to initialize UHCI memory structures: %s.\n",
    234             str_error(ret));
    235 
    236 #undef CHECK_RET_RETURN
     264        rc = hc_init_mem_structures(instance);
     265        if (rc != EOK) {
     266                usb_log_error("Failed to initialize UHCI memory structures: %s.\n",
     267                    str_error(rc));
     268                return rc;
     269        }
    237270
    238271        hcd_init(&instance->generic, USB_SPEED_FULL,
     
    397430
    398431        return EOK;
    399 #undef CHECK_RET_CLEAR_RETURN
    400432}
    401433
  • uspace/drv/bus/usb/uhci/hc.h

    r98abd40 rcdc8a391  
    3636#define DRV_UHCI_HC_H
    3737
     38#include <ddf/interrupt.h>
    3839#include <fibril.h>
    3940#include <usb/host/hcd.h>
     
    119120} hc_t;
    120121
    121 size_t hc_irq_pio_range_count(void);
    122 size_t hc_irq_cmd_count(void);
     122int hc_register_irq_handler(ddf_dev_t *, uintptr_t, size_t, int, interrupt_handler_t);
    123123int hc_get_irq_code(irq_pio_range_t [], size_t, irq_cmd_t [], size_t, uintptr_t,
    124124    size_t);
  • uspace/drv/bus/usb/uhci/uhci.c

    r98abd40 rcdc8a391  
    3838
    3939#include <errno.h>
     40#include <stdbool.h>
    4041#include <str_error.h>
    4142#include <ddf/interrupt.h>
     
    149150int device_setup_uhci(ddf_dev_t *device)
    150151{
     152        bool ih_registered = false;
     153        bool hc_inited = false;
     154        bool fun_bound = false;
     155        int rc;
     156
    151157        if (!device)
    152158                return EBADMEM;
     
    158164        }
    159165
    160 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
    161 if (ret != EOK) { \
    162         if (instance->hc_fun) \
    163                 ddf_fun_destroy(instance->hc_fun); \
    164         if (instance->rh_fun) {\
    165                 ddf_fun_destroy(instance->rh_fun); \
    166         } \
    167         usb_log_error(message); \
    168         return ret; \
    169 } else (void)0
    170 
    171         instance->rh_fun = NULL;
    172166        instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci_hc");
    173         int ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
    174         CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI HC function.\n");
     167        if (instance->hc_fun == NULL) {
     168                usb_log_error("Failed to create UHCI HC function.\n");
     169                rc = ENOMEM;
     170                goto error;
     171        }
     172
    175173        ddf_fun_set_ops(instance->hc_fun, &hc_ops);
    176174        ddf_fun_data_implant(instance->hc_fun, &instance->hc.generic);
    177175
    178176        instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci_rh");
    179         ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
    180         CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI RH function.\n");
     177        if (instance->rh_fun == NULL) {
     178                usb_log_error("Failed to create UHCI RH function.\n");
     179                rc = ENOMEM;
     180                goto error;
     181        }
     182
    181183        ddf_fun_set_ops(instance->rh_fun, &rh_ops);
    182184        ddf_fun_data_implant(instance->rh_fun, &instance->rh);
     
    186188        int irq = 0;
    187189
    188         ret = get_my_registers(device, &reg_base, &reg_size, &irq);
    189         CHECK_RET_DEST_FREE_RETURN(ret,
    190             "Failed to get I/O addresses for %" PRIun ": %s.\n",
    191             ddf_dev_get_handle(device), str_error(ret));
     190        rc = get_my_registers(device, &reg_base, &reg_size, &irq);
     191        if (rc != EOK) {
     192                usb_log_error("Failed to get I/O addresses for %" PRIun ": %s.\n",
     193                    ddf_dev_get_handle(device), str_error(rc));
     194                goto error;
     195        }
    192196        usb_log_debug("I/O regs at 0x%p (size %zu), IRQ %d.\n",
    193197            (void *) reg_base, reg_size, irq);
    194198
    195         ret = disable_legacy(device);
    196         CHECK_RET_DEST_FREE_RETURN(ret,
    197             "Failed to disable legacy USB: %s.\n", str_error(ret));
    198 
    199         const size_t ranges_count = hc_irq_pio_range_count();
    200         const size_t cmds_count = hc_irq_cmd_count();
    201         irq_pio_range_t irq_ranges[ranges_count];
    202         irq_cmd_t irq_cmds[cmds_count];
    203         ret = hc_get_irq_code(irq_ranges, sizeof(irq_ranges), irq_cmds,
    204             sizeof(irq_cmds), reg_base, reg_size);
    205         CHECK_RET_DEST_FREE_RETURN(ret,
    206             "Failed to generate IRQ commands: %s.\n", str_error(ret));
    207 
    208         irq_code_t irq_code = {
    209                 .rangecount = ranges_count,
    210                 .ranges = irq_ranges,
    211                 .cmdcount = cmds_count,
    212                 .cmds = irq_cmds
    213         };
    214 
    215         /* Register handler to avoid interrupt lockup */
    216         ret = register_interrupt_handler(device, irq, irq_handler, &irq_code);
    217         CHECK_RET_DEST_FREE_RETURN(ret,
    218             "Failed to register interrupt handler: %s.\n", str_error(ret));
     199        rc = disable_legacy(device);
     200        if (rc != EOK) {
     201                usb_log_error("Failed to disable legacy USB: %s.\n",
     202                    str_error(rc));
     203                goto error;
     204        }
     205
     206        rc = hc_register_irq_handler(device, reg_base, reg_size, irq, irq_handler);
     207        if (rc != EOK) {
     208                usb_log_error("Failed to register interrupt handler: %s.\n",
     209                    str_error(rc));
     210                goto error;
     211        }
     212
     213        ih_registered = true;
    219214
    220215        bool interrupts = false;
    221         ret = enable_interrupts(device);
    222         if (ret != EOK) {
     216        rc = enable_interrupts(device);
     217        if (rc != EOK) {
    223218                usb_log_warning("Failed to enable interrupts: %s."
    224                     " Falling back to polling.\n", str_error(ret));
     219                    " Falling back to polling.\n", str_error(rc));
    225220        } else {
    226221                usb_log_debug("Hw interrupts enabled.\n");
     
    228223        }
    229224
    230         ret = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts);
    231         CHECK_RET_DEST_FREE_RETURN(ret,
    232             "Failed to init uhci_hcd: %s.\n", str_error(ret));
    233 
    234 #define CHECK_RET_FINI_RETURN(ret, message...) \
    235 if (ret != EOK) { \
    236         hc_fini(&instance->hc); \
    237         CHECK_RET_DEST_FREE_RETURN(ret, message); \
    238         return ret; \
    239 } else (void)0
    240 
    241         ret = ddf_fun_bind(instance->hc_fun);
    242         CHECK_RET_FINI_RETURN(ret, "Failed to bind UHCI device function: %s.\n",
    243             str_error(ret));
    244 
    245         ret = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
    246         CHECK_RET_FINI_RETURN(ret,
    247             "Failed to add UHCI to HC class: %s.\n", str_error(ret));
    248 
    249         ret = rh_init(&instance->rh, instance->rh_fun,
     225        rc = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts);
     226        if (rc != EOK) {
     227                usb_log_error("Failed to init uhci_hcd: %s.\n", str_error(rc));
     228                goto error;
     229        }
     230
     231        hc_inited = true;
     232
     233        rc = ddf_fun_bind(instance->hc_fun);
     234        if (rc != EOK) {
     235                usb_log_error("Failed to bind UHCI device function: %s.\n",
     236                    str_error(rc));
     237                goto error;
     238        }
     239
     240        fun_bound = true;
     241
     242        rc = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
     243        if (rc != EOK) {
     244                usb_log_error("Failed to add UHCI to HC class: %s.\n",
     245                    str_error(rc));
     246                goto error;
     247        }
     248
     249        rc = rh_init(&instance->rh, instance->rh_fun,
    250250            (uintptr_t)instance->hc.registers + 0x10, 4);
    251         CHECK_RET_FINI_RETURN(ret,
    252             "Failed to setup UHCI root hub: %s.\n", str_error(ret));
    253 
    254         ret = ddf_fun_bind(instance->rh_fun);
    255         CHECK_RET_FINI_RETURN(ret,
    256             "Failed to register UHCI root hub: %s.\n", str_error(ret));
     251        if (rc != EOK) {
     252                usb_log_error("Failed to setup UHCI root hub: %s.\n",
     253                    str_error(rc));
     254                goto error;
     255        }
     256
     257        rc = ddf_fun_bind(instance->rh_fun);
     258        if (rc != EOK) {
     259                usb_log_error("Failed to register UHCI root hub: %s.\n",
     260                    str_error(rc));
     261                goto error;
     262        }
    257263
    258264        return EOK;
    259 #undef CHECK_RET_FINI_RETURN
     265
     266error:
     267        if (fun_bound)
     268                ddf_fun_unbind(instance->hc_fun);
     269        if (hc_inited)
     270                hc_fini(&instance->hc);
     271        if (ih_registered)
     272                unregister_interrupt_handler(device, irq);
     273        if (instance->hc_fun != NULL)
     274                ddf_fun_destroy(instance->hc_fun);
     275        if (instance->rh_fun != NULL) {
     276                ddf_fun_destroy(instance->rh_fun);
     277        }
     278        return rc;
    260279}
    261280/**
  • uspace/drv/bus/usb/uhcirh/main.c

    r98abd40 rcdc8a391  
    9393        size_t io_size = 0;
    9494        uhci_root_hub_t *rh = NULL;
    95         int ret = EOK;
     95        int rc;
    9696
    97 #define CHECK_RET_FREE_RH_RETURN(ret, message...) \
    98 if (ret != EOK) { \
    99         usb_log_error(message); \
    100         return ret; \
    101 } else (void)0
     97        rc = hc_get_my_registers(device, &io_regs, &io_size);
     98        if (rc != EOK) {
     99                usb_log_error( "Failed to get registers from HC: %s.\n",
     100                    str_error(rc));
     101                return rc;
     102        }
    102103
    103         ret = hc_get_my_registers(device, &io_regs, &io_size);
    104         CHECK_RET_FREE_RH_RETURN(ret,
    105             "Failed to get registers from HC: %s.\n", str_error(ret));
    106104        usb_log_debug("I/O regs at %p (size %zuB).\n",
    107105            (void *) io_regs, io_size);
    108106
    109107        rh = ddf_dev_data_alloc(device, sizeof(uhci_root_hub_t));
    110         ret = (rh == NULL) ? ENOMEM : EOK;
    111         CHECK_RET_FREE_RH_RETURN(ret,
    112             "Failed to allocate rh driver instance.\n");
     108        if (rh == NULL) {
     109                usb_log_error("Failed to allocate rh driver instance.\n");
     110                return ENOMEM;
     111        }
    113112
    114         ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
    115         CHECK_RET_FREE_RH_RETURN(ret,
    116             "Failed(%d) to initialize rh driver instance: %s.\n",
    117             ret, str_error(ret));
     113        rc = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
     114        if (rc != EOK) {
     115                usb_log_error("Failed(%d) to initialize rh driver instance: "
     116                    "%s.\n", rc, str_error(rc));
     117                return rc;
     118        }
    118119
    119120        usb_log_info("Controlling root hub '%s' (%" PRIun ").\n",
    120121            ddf_dev_get_name(device), ddf_dev_get_handle(device));
     122
    121123        return EOK;
    122124}
  • uspace/drv/bus/usb/uhcirh/port.c

    r98abd40 rcdc8a391  
    150150{
    151151        uhci_port_t *instance = port;
     152        int rc;
    152153        assert(instance);
    153154
    154155        unsigned allowed_failures = MAX_ERROR_COUNT;
    155 #define CHECK_RET_FAIL(ret, msg...) \
    156         if (ret != EOK) { \
    157                 usb_log_error(msg); \
    158                 if (!(allowed_failures-- > 0)) { \
    159                         usb_log_fatal( \
    160                            "Maximum number of failures reached, " \
    161                            "bailing out.\n"); \
    162                         return ret; \
    163                 } \
    164                 continue; \
    165         } else (void)0
    166156
    167157        while (1) {
     
    182172                    instance->id_string, port_status);
    183173
    184                 int ret = usb_hc_connection_open(&instance->hc_connection);
    185                 CHECK_RET_FAIL(ret, "%s: Failed to connect to HC %s.\n",
    186                     instance->id_string, str_error(ret));
     174                rc = usb_hc_connection_open(&instance->hc_connection);
     175                if (rc != EOK) {
     176                        usb_log_error("%s: Failed to connect to HC %s.\n",
     177                            instance->id_string, str_error(rc));
     178                        if (!(allowed_failures-- > 0))
     179                                goto fatal_error;
     180                        continue;
     181                }
    187182
    188183                /* Remove any old device */
     
    204199                }
    205200
    206                 ret = usb_hc_connection_close(&instance->hc_connection);
    207                 CHECK_RET_FAIL(ret, "%s: Failed to disconnect from hc: %s.\n",
    208                     instance->id_string, str_error(ret));
    209         }
    210         return EOK;
     201                rc = usb_hc_connection_close(&instance->hc_connection);
     202                if (rc != EOK) {
     203                        usb_log_error("%s: Failed to disconnect from HC %s.\n",
     204                            instance->id_string, str_error(rc));
     205                        if (!(allowed_failures-- > 0))
     206                                goto fatal_error;
     207                        continue;
     208                }
     209        }
     210
     211        return EOK;
     212
     213fatal_error:
     214        usb_log_fatal("Maximum number of failures reached, bailing out.\n");
     215        return rc;
    211216}
    212217
  • uspace/drv/char/ns8250/ns8250.c

    r98abd40 rcdc8a391  
    420420                        ns->irq = res->res.interrupt.irq;
    421421                        irq = true;
    422                         ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.",
     422                        ddf_msg(LVL_NOTE, "Device %s was assigned irq = 0x%x.",
    423423                            ddf_dev_get_name(ns->dev), ns->irq);
    424424                        break;
     
    433433                        }
    434434                        ioport = true;
    435                         ddf_msg(LVL_NOTE, "Device %s was asigned I/O address = "
     435                        ddf_msg(LVL_NOTE, "Device %s was assigned I/O address = "
    436436                            "0x%x.", ddf_dev_get_name(ns->dev), ns->io_addr);
    437437                        break;
     
    827827        ddf_fun_t *fun = NULL;
    828828        bool need_cleanup = false;
     829        bool need_unreg_intr_handler = false;
    829830        int rc;
    830831       
     
    869870                goto fail;
    870871        }
     872        need_unreg_intr_handler = true;
    871873       
    872874        /* Enable interrupt. */
     
    903905        if (fun != NULL)
    904906                ddf_fun_destroy(fun);
     907        if (need_unreg_intr_handler)
     908                ns8250_unregister_interrupt_handler(ns);
    905909        if (need_cleanup)
    906910                ns8250_dev_cleanup(ns);
  • uspace/srv/fs/mfs/mfs_balloc.c

    r98abd40 rcdc8a391  
    128128                start_block = 2 + sbi->ibmap_blocks;
    129129                if (idx > sbi->nzones) {
    130                         printf(NAME ": Error! Trying to free beyond the" \
     130                        printf(NAME ": Error! Trying to free beyond the "
    131131                            "bitmap max size\n");
    132132                        return -1;
     
    137137                start_block = 2;
    138138                if (idx > sbi->ninodes) {
    139                         printf(NAME ": Error! Trying to free beyond the" \
     139                        printf(NAME ": Error! Trying to free beyond the "
    140140                            "bitmap max size\n");
    141141                        return -1;
     
    202202                start_block = 2;
    203203                nblocks = sbi->ibmap_blocks;
    204                 limit = sbi->ninodes;
     204                limit = sbi->ninodes - 1;
    205205        }
    206206        bits_per_block = sbi->block_size * 8;
  • uspace/srv/fs/mfs/mfs_dentry.c

    r98abd40 rcdc8a391  
    3636 *
    3737 * @param mnode         Pointer to the directory node.
    38  * @param d_info        Pointer to a directory entry structure where the dentry info
    39  *                      will be stored.
     38 * @param d_info        Pointer to a directory entry structure where
     39 *                      the dentry info will be stored.
    4040 * @param index         index of the dentry in the list.
    4141 *
     
    101101/**Write a directory entry on disk.
    102102 *
    103  * @param d_info Pointer to the directory entry structure to write on disk.
     103 * @param d_info The directory entry to write to disk.
    104104 *
    105105 * @return       EOK on success or a negative error code.
     
    240240                                goto out;
    241241                        r = mfs_write_map(mnode, pos, b, &dummy);
    242                         if (r != EOK)
     242                        if (r != EOK) {
     243                                mfs_free_zone(mnode->instance, b);
    243244                                goto out;
     245                        }
    244246                }
    245247
  • uspace/srv/fs/mfs/mfs_ops.c

    r98abd40 rcdc8a391  
    8888
    8989/* Hash table interface for open nodes hash table */
    90 
    9190typedef struct {
    9291        service_id_t service_id;
     
    190189                /* This is a V1 or V2 Minix filesystem */
    191190                magic = sb->s_magic;
    192         } else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) {
     191        } else if (check_magic_number(sb3->s_magic, &native,
     192            &version, &longnames)) {
    193193                /* This is a V3 Minix filesystem */
    194194                magic = sb3->s_magic;
     
    345345        uint32_t inum;
    346346
    347         mfsdebug("%s()\n", __FUNCTION__);
    348 
    349347        r = mfs_instance_get(service_id, &inst);
    350348        if (r != EOK)
     
    379377                ino_i->i_mode = S_IFDIR;
    380378                ino_i->i_nlinks = 1; /* This accounts for the '.' dentry */
    381         } else
     379        } else {
    382380                ino_i->i_mode = S_IFREG;
     381                ino_i->i_nlinks = 0;
     382        }
    383383
    384384        ino_i->i_uid = 0;
     
    419419        free(ino_i);
    420420out_err:
     421        mfs_free_inode(inst, inum);
    421422        return r;
    422423}
     
    429430        struct mfs_dentry_info d_info;
    430431        int r;
    431 
    432         mfsdebug("%s()\n", __FUNCTION__);
    433432
    434433        if (!S_ISDIR(ino_i->i_mode))
     
    478477        struct mfs_instance *instance;
    479478
    480         mfsdebug("%s()\n", __FUNCTION__);
    481 
    482479        rc = mfs_instance_get(service_id, &instance);
    483480        if (rc != EOK)
     
    492489        int rc = EOK;
    493490        struct mfs_node *mnode = fsnode->data;
    494 
    495         mfsdebug("%s()\n", __FUNCTION__);
    496491
    497492        fibril_mutex_lock(&open_nodes_lock);
     
    554549        int rc;
    555550
    556         mfsdebug("%s()\n", __FUNCTION__);
    557 
    558551        fibril_mutex_lock(&open_nodes_lock);
    559552
     
    568561        if (already_open) {
    569562                mnode = hash_table_get_inst(already_open, struct mfs_node, link);
     563
    570564                *rfn = mnode->fsnode;
    571565                mnode->refcnt++;
     
    649643        bool destroy_dentry = false;
    650644
    651         mfsdebug("%s()\n", __FUNCTION__);
    652 
    653645        if (str_size(name) > sbi->max_name_len)
    654646                return ENAMETOOLONG;
     
    673665                r = mfs_insert_dentry(child, "..", parent->ino_i->index);
    674666                if (r != EOK) {
     667                        mfs_remove_dentry(child, ".");
    675668                        destroy_dentry = true;
    676669                        goto exit;
     
    700693        bool has_children;
    701694        int r;
    702 
    703         mfsdebug("%s()\n", __FUNCTION__);
    704695
    705696        if (!parent)
     
    924915               
    925916                r = mfs_write_map(mnode, pos, block, &dummy);
    926                 if (r != EOK)
     917                if (r != EOK) {
     918                        mfs_free_zone(mnode->instance, block);
    927919                        goto out_err;
     920                }
    928921
    929922                flags = BLOCK_FLAGS_NOREAD;
     
    965958mfs_destroy(service_id_t service_id, fs_index_t index)
    966959{
    967         fs_node_t *fn;
     960        fs_node_t *fn = NULL;
    968961        int r;
    969962
Note: See TracChangeset for help on using the changeset viewer.