Changeset bb0eab1 in mainline for uspace/srv/bd/ata_bd/ata_bd.c


Ignore:
Timestamp:
2011-02-01T07:27:32Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
aa893e0
Parents:
0d247f5
Message:

Use structures and constants instead of magic numbers.

File:
1 edited

Legend:

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

    r0d247f5 rbb0eab1  
    5656#include <as.h>
    5757#include <fibril_synch.h>
     58#include <stdint.h>
    5859#include <str.h>
    5960#include <devmap.h>
     
    6263#include <errno.h>
    6364#include <bool.h>
     65#include <byteorder.h>
    6466#include <task.h>
    6567#include <macros.h>
     
    368370        identify_data_t idata;
    369371        uint8_t model[40];
    370         uint8_t inq_buf[36];
     372        ata_inquiry_data_t inq_data;
    371373        uint16_t w;
    372374        uint8_t c;
     
    471473        if (d->dev_type == ata_pkt_dev) {
    472474                /* Send inquiry. */
    473                 rc = ata_pcmd_inquiry(0, inq_buf, 36);
     475                rc = ata_pcmd_inquiry(0, &inq_data, sizeof(inq_data));
    474476                if (rc != EOK) {
    475477                        printf("Device inquiry failed.\n");
     
    479481
    480482                /* Check device type. */
    481                 if ((inq_buf[0] & 0x1f) != 0x05)
     483                if (INQUIRY_PDEV_TYPE(inq_data.pdev_type) != PDEV_TYPE_CDROM)
    482484                        printf("Warning: Peripheral device type is not CD-ROM.\n");
    483 
    484                 /* XXX Test some reading */
    485                 uint8_t rdbuf[4096];
    486                 rc = ata_pcmd_read_12(0, 0, 1, rdbuf, 4096);
    487                 if (rc != EOK) {
    488                         printf("read(12) failed\n");
    489                 } else {
    490                         printf("read(12) succeeded\n");
    491                 }
    492485
    493486                /* Assume 2k block size for now. */
     
    714707        data_size = (uint16_t) pio_read_8(&cmd->cylinder_low) +
    715708            ((uint16_t) pio_read_8(&cmd->cylinder_high) << 8);
    716         printf("data_size = %u\n", data_size);
    717709
    718710        /* Check whether data fits into output buffer. */
     
    749741static int ata_pcmd_inquiry(int dev_idx, void *obuf, size_t obuf_size)
    750742{
    751         uint8_t cp[12];
     743        ata_pcmd_inquiry_t cp;
    752744        int rc;
    753745
    754         memset(cp, 0, 12);
    755         cp[0] = 0x12; /* Inquiry */
    756         cp[4] = min(obuf_size, 0xff); /* Allocation length */
    757 
    758         rc = ata_cmd_packet(0, cp, 12, obuf, obuf_size);
     746        memset(&cp, 0, sizeof(cp));
     747
     748        cp.opcode = PCMD_INQUIRY;
     749        cp.alloc_len = min(obuf_size, 0xff); /* Allocation length */
     750
     751        rc = ata_cmd_packet(0, &cp, sizeof(cp), obuf, obuf_size);
    759752        if (rc != EOK)
    760753                return rc;
     
    766759    void *obuf, size_t obuf_size)
    767760{
    768         uint8_t cp[12];
     761        ata_pcmd_read_12_t cp;
    769762        int rc;
    770763
    771         if (ba > 0xffffffff)
     764        if (ba > UINT32_MAX)
    772765                return EINVAL;
    773766
    774         memset(cp, 0, 12);
    775         cp[0] = 0xa8; /* Read(12) */
    776         cp[2] = (ba >> 24) & 0xff;
    777         cp[3] = (ba >> 16) & 0xff;
    778         cp[4] = (ba >> 8) & 0xff;
    779         cp[5] = ba & 0xff;
    780 
    781         cp[6] = (cnt >> 24) & 0xff;
    782         cp[7] = (cnt >> 16) & 0xff;
    783         cp[8] = (cnt >> 8) & 0xff;
    784         cp[9] = cnt & 0xff;
    785 
    786         rc = ata_cmd_packet(0, cp, 12, obuf, obuf_size);
     767        memset(&cp, 0, sizeof(cp));
     768
     769        cp.opcode = PCMD_READ_12;
     770        cp.ba = host2uint32_t_be(ba);
     771        cp.nblocks = host2uint32_t_be(cnt);
     772
     773        rc = ata_cmd_packet(0, &cp, sizeof(cp), obuf, obuf_size);
    787774        if (rc != EOK)
    788775                return rc;
Note: See TracChangeset for help on using the changeset viewer.