Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/res.c

    rd930980 r5b7ba8d  
    7676 * @return Error code.
    7777 */
    78 int get_my_registers(ddf_dev_t *dev,
     78int get_my_registers(const ddf_dev_t *dev,
    7979    uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no)
    8080{
     
    8282       
    8383        async_sess_t *parent_sess = devman_parent_device_connect(
    84             EXCHANGE_SERIALIZE, ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
     84            EXCHANGE_SERIALIZE, dev->handle, IPC_FLAG_BLOCKING);
    8585        if (!parent_sess)
    8686                return ENOMEM;
     
    109109        return EOK;
    110110}
    111 
     111/*----------------------------------------------------------------------------*/
    112112/** Calls the PCI driver with a request to enable interrupts
    113113 *
     
    115115 * @return Error code.
    116116 */
    117 int enable_interrupts(ddf_dev_t *device)
     117int enable_interrupts(const ddf_dev_t *device)
    118118{
    119119        async_sess_t *parent_sess = devman_parent_device_connect(
    120             EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
     120            EXCHANGE_SERIALIZE, device->handle, IPC_FLAG_BLOCKING);
    121121        if (!parent_sess)
    122122                return ENOMEM;
     
    127127        return enabled ? EOK : EIO;
    128128}
    129 
     129/*----------------------------------------------------------------------------*/
    130130/** Implements BIOS hands-off routine as described in EHCI spec
    131131 *
     
    134134 * @return Error code.
    135135 */
    136 static int disable_extended_caps(ddf_dev_t *device, unsigned eecp)
     136static int disable_extended_caps(const ddf_dev_t *device, unsigned eecp)
    137137{
    138138        /* nothing to do */
     
    141141
    142142        async_sess_t *parent_sess = devman_parent_device_connect(
    143             EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
     143            EXCHANGE_SERIALIZE, device->handle, IPC_FLAG_BLOCKING);
    144144        if (!parent_sess)
    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
    147154        /* Read the first EEC. i.e. Legacy Support register */
    148155        uint32_t usblegsup;
    149         int rc = pci_config_space_read_32(parent_sess,
     156        int ret = pci_config_space_read_32(parent_sess,
    150157            eecp + USBLEGSUP_OFFSET, &usblegsup);
    151         if (rc != EOK) {
    152                 usb_log_error("Failed to read USBLEGSUP: %s.\n",
    153                     str_error(rc));
    154                 goto error;
    155         }
    156 
     158        CHECK_RET_HANGUP_RETURN(ret,
     159            "Failed to read USBLEGSUP: %s.\n", str_error(ret));
    157160        usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
    158161
     
    160163         * byte. (OS Control semaphore)*/
    161164        usb_log_debug("Requesting OS control.\n");
    162         rc = pci_config_space_write_8(parent_sess,
     165        ret = pci_config_space_write_8(parent_sess,
    163166            eecp + USBLEGSUP_OFFSET + 3, 1);
    164         if (rc != EOK) {
    165                 usb_log_error("Failed to request OS EHCI control: %s.\n",
    166                     str_error(rc));
    167                 goto error;
    168         }
     167        CHECK_RET_HANGUP_RETURN(ret, "Failed to request OS EHCI control: %s.\n",
     168            str_error(ret));
    169169
    170170        size_t wait = 0;
    171171        /* Wait for BIOS to release control. */
    172         rc = pci_config_space_read_32(
     172        ret = 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 
    180174        while ((wait < DEFAULT_WAIT) && (usblegsup & USBLEGSUP_BIOS_CONTROL)) {
    181175                async_usleep(WAIT_STEP);
    182                 rc = pci_config_space_read_32(parent_sess,
     176                ret = pci_config_space_read_32(parent_sess,
    183177                    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                 }
    189178                wait += WAIT_STEP;
    190179        }
     
    199188        usb_log_warning( "BIOS failed to release control after "
    200189            "%zu usecs, force it.\n", wait);
    201         rc = pci_config_space_write_32(parent_sess,
     190        ret = pci_config_space_write_32(parent_sess,
    202191            eecp + USBLEGSUP_OFFSET, USBLEGSUP_OS_CONTROL);
    203         if (rc != EOK) {
    204                 usb_log_error("Failed to force OS control: "
    205                     "%s.\n", str_error(rc));
    206                 goto error;
    207         }
    208 
     192        CHECK_RET_HANGUP_RETURN(ret, "Failed to force OS control: "
     193            "%s.\n", str_error(ret));
    209194        /*
    210195         * Check capability type here, value of 01h identifies the capability
     
    216201                /* Read the second EEC Legacy Support and Control register */
    217202                uint32_t usblegctlsts;
    218                 rc = pci_config_space_read_32(parent_sess,
     203                ret = pci_config_space_read_32(parent_sess,
    219204                    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
    220                 if (rc != EOK) {
    221                         usb_log_error("Failed to get USBLEGCTLSTS: %s.\n",
    222                             str_error(rc));
    223                         goto error;
    224                 }
    225 
     205                CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS: %s.\n",
     206                    str_error(ret));
    226207                usb_log_debug("USBLEGCTLSTS: %" PRIx32 ".\n", usblegctlsts);
    227208                /*
     
    230211                 * interfering. NOTE: Three upper bits are WC
    231212                 */
    232                 rc = pci_config_space_write_32(parent_sess,
     213                ret = pci_config_space_write_32(parent_sess,
    233214                    eecp + USBLEGCTLSTS_OFFSET, 0xe0000000);
    234                 if (rc != EOK) {
    235                         usb_log_error("Failed(%d) zero USBLEGCTLSTS.\n", rc);
    236                         goto error;
    237                 }
    238 
     215                CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) zero USBLEGCTLSTS.\n", ret);
    239216                udelay(10);
    240                 rc = pci_config_space_read_32(parent_sess,
     217                ret = pci_config_space_read_32(parent_sess,
    241218                    eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts);
    242                 if (rc != EOK) {
    243                         usb_log_error("Failed to get USBLEGCTLSTS 2: %s.\n",
    244                             str_error(rc));
    245                         goto error;
    246                 }
    247 
     219                CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS 2: %s.\n",
     220                    str_error(ret));
    248221                usb_log_debug("Zeroed USBLEGCTLSTS: %" PRIx32 ".\n",
    249222                    usblegctlsts);
     
    251224
    252225        /* Read again Legacy Support register */
    253         rc = pci_config_space_read_32(parent_sess,
     226        ret = pci_config_space_read_32(parent_sess,
    254227            eecp + USBLEGSUP_OFFSET, &usblegsup);
    255         if (rc != EOK) {
    256                 usb_log_error("Failed to read USBLEGSUP: %s.\n",
    257                     str_error(rc));
    258                 goto error;
    259         }
    260 
     228        CHECK_RET_HANGUP_RETURN(ret, "Failed to read USBLEGSUP: %s.\n",
     229            str_error(ret));
    261230        usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup);
    262231        async_hangup(parent_sess);
    263232        return EOK;
    264 error:
    265         async_hangup(parent_sess);
    266         return rc;
     233#undef CHECK_RET_HANGUP_RETURN
    267234}
    268235
    269 int disable_legacy(ddf_dev_t *device, uintptr_t reg_base, size_t reg_size)
     236int disable_legacy(const ddf_dev_t *device, uintptr_t reg_base, size_t reg_size)
    270237{
    271238        assert(device);
    272239        usb_log_debug("Disabling EHCI legacy support.\n");
    273240
     241#define CHECK_RET_RETURN(ret, message...) \
     242        if (ret != EOK) { \
     243                usb_log_error(message); \
     244                return ret; \
     245        } else (void)0
     246
    274247        /* Map EHCI registers */
    275248        void *regs = NULL;
    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         }
     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));
    282252
    283253        usb_log_debug2("Registers mapped at: %p.\n", regs);
     
    293263        usb_log_debug("Value of EECP: %x.\n", eecp);
    294264
    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         }
     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
    301270
    302271        /*
     
    337306            usbcmd, *usbcmd, usbsts, *usbsts, usbint, *usbint, usbconf,*usbconf);
    338307
    339         return rc;
     308        return ret;
    340309}
    341310
Note: See TracChangeset for help on using the changeset viewer.