Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/ata_bd/ata_bd.c

    raa893e0 r029b13c  
    5151#include <libarch/ddi.h>
    5252#include <ddi.h>
    53 #include <ipc/ipc.h>
    5453#include <ipc/bd.h>
    5554#include <async.h>
     
    282281        sysarg_t method;
    283282        devmap_handle_t dh;
    284         int flags;
     283        unsigned int flags;
    285284        int retval;
    286285        uint64_t ba;
     
    298297
    299298        if (disk_id < 0 || disk[disk_id].present == false) {
    300                 ipc_answer_0(iid, EINVAL);
     299                async_answer_0(iid, EINVAL);
    301300                return;
    302301        }
    303302
    304303        /* Answer the IPC_M_CONNECT_ME_TO call. */
    305         ipc_answer_0(iid, EOK);
     304        async_answer_0(iid, EOK);
    306305
    307306        if (!async_share_out_receive(&callid, &comm_size, &flags)) {
    308                 ipc_answer_0(callid, EHANGUP);
     307                async_answer_0(callid, EHANGUP);
    309308                return;
    310309        }
     
    312311        fs_va = as_get_mappable_page(comm_size);
    313312        if (fs_va == NULL) {
    314                 ipc_answer_0(callid, EHANGUP);
     313                async_answer_0(callid, EHANGUP);
    315314                return;
    316315        }
     
    324323                case IPC_M_PHONE_HUNGUP:
    325324                        /* The other side has hung up. */
    326                         ipc_answer_0(callid, EOK);
     325                        async_answer_0(callid, EOK);
    327326                        return;
    328327                case BD_READ_BLOCKS:
     
    347346                        break;
    348347                case BD_GET_BLOCK_SIZE:
    349                         ipc_answer_1(callid, EOK, disk[disk_id].block_size);
     348                        async_answer_1(callid, EOK, disk[disk_id].block_size);
    350349                        continue;
    351350                case BD_GET_NUM_BLOCKS:
    352                         ipc_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks),
     351                        async_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks),
    353352                            UPPER32(disk[disk_id].blocks));
    354353                        continue;
     
    357356                        break;
    358357                }
    359                 ipc_answer_0(callid, retval);
     358                async_answer_0(callid, retval);
    360359        }
    361360}
     
    373372        uint16_t w;
    374373        uint8_t c;
     374        uint16_t bc;
    375375        size_t pos, len;
    376376        int rc;
     
    388388        } else if (rc == EIO) {
    389389                /*
    390                  * There is something, but not a register device.
    391                  * It could be a packet device.
     390                 * There is something, but not a register device. Check to see
     391                 * whether the IDENTIFY command left the packet signature in
     392                 * the registers in case this is a packet device.
     393                 *
     394                 * According to the ATA specification, the LBA low and
     395                 * interrupt reason registers should be set to 0x01. However,
     396                 * there are many devices that do not follow this and only set
     397                 * the byte count registers. So, only check these.
    392398                 */
    393                 rc = identify_pkt_dev(disk_id, &idata);
    394                 if (rc == EOK) {
    395                         /* We have a packet device. */
    396                         d->dev_type = ata_pkt_dev;
     399                bc = ((uint16_t)pio_read_8(&cmd->cylinder_high) << 8) |
     400                    pio_read_8(&cmd->cylinder_low);
     401
     402                if (bc == PDEV_SIGNATURE_BC) {
     403                        rc = identify_pkt_dev(disk_id, &idata);
     404                        if (rc == EOK) {
     405                                /* We have a packet device. */
     406                                d->dev_type = ata_pkt_dev;
     407                        } else {
     408                                return EIO;
     409                        }
    397410                } else {
    398411                        /* Nope. Something's there, but not recognized. */
     
    404417        }
    405418
    406         printf("device caps: 0x%04x\n", idata.caps);
    407419        if (d->dev_type == ata_pkt_dev) {
    408420                /* Packet device */
     
    567579
    568580        /*
    569          * This is where we would most likely expect a non-existing device to
    570          * show up by not setting SR_DRDY.
     581         * Do not wait for DRDY to be set in case this is a packet device.
     582         * We determine whether the device is present by waiting for DRQ to be
     583         * set after issuing the command.
    571584         */
    572         if (wait_status(SR_DRDY, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
     585        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
    573586                return ETIMEOUT;
    574587
     
    578591                return ETIMEOUT;
    579592
     593        /*
     594         * If ERR is set, this may be a packet device, so return EIO to cause
     595         * the caller to check for one.
     596         */
     597        if ((status & SR_ERR) != 0) {
     598                return EIO;
     599        }
     600
     601        if (wait_status(SR_DRQ, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK)
     602                return ETIMEOUT;
     603
    580604        /* Read data from the disk buffer. */
    581605
    582         if ((status & SR_DRQ) != 0) {
    583                 for (i = 0; i < identify_data_size / 2; i++) {
    584                         data = pio_read_16(&cmd->data_port);
    585                         ((uint16_t *) buf)[i] = data;
    586                 }
    587         }
    588 
    589         if ((status & SR_ERR) != 0) {
    590                 return EIO;
     606        for (i = 0; i < identify_data_size / 2; i++) {
     607                data = pio_read_16(&cmd->data_port);
     608                ((uint16_t *) buf)[i] = data;
    591609        }
    592610
Note: See TracChangeset for help on using the changeset viewer.