Changeset bb0eab1 in mainline


Ignore:
Timestamp:
2011-02-01T07:27:32Z (13 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.

Location:
uspace/srv/bd/ata_bd
Files:
2 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;
  • uspace/srv/bd/ata_bd/ata_hw.h

    r0d247f5 rbb0eab1  
    241241};
    242242
     243/** ATA packet command codes. */
     244enum ata_pkt_command {
     245        PCMD_INQUIRY            = 0x12,
     246        PCMD_READ_12            = 0xa8
     247};
     248
     249/** ATAPI Inquiry command */
     250typedef struct {
     251        uint8_t opcode;         /**< Operation code (PCMD_INQUIRY) */
     252        uint8_t _res0;
     253        uint8_t _res1;
     254        uint8_t _res2;
     255        uint8_t alloc_len;      /**< Allocation length */
     256        uint8_t _res3;
     257        uint8_t _res4;
     258        uint8_t _res5;
     259        uint32_t _res6;
     260} __attribute__ ((packed)) ata_pcmd_inquiry_t;
     261
     262/** ATAPI Read(12) command */
     263typedef struct {
     264        uint8_t opcode;         /**< Operation code (PCMD_READ_12) */
     265        uint8_t _res0;
     266        uint32_t ba;            /**< Starting block address */
     267        uint32_t nblocks;       /**< Number of blocks to transfer */
     268        uint8_t _res1;
     269        uint8_t _res2;
     270} __attribute__ ((packed)) ata_pcmd_read_12_t;
     271
     272/** Data returned from Inquiry command (mandatory part) */
     273typedef struct {
     274        uint8_t pdev_type;      /** Reserved, Peripheral device type */
     275        uint8_t rmb;            /** RMB, Reserved */
     276        uint8_t std_version;    /** ISO version, ECMA version, ANSI version */
     277        uint8_t atapi_ver_rdf;  /** ATAPI version, Response data format */
     278        uint8_t additional_len; /** Additional length */
     279        uint8_t _res0;
     280        uint8_t _res1;
     281        uint8_t _res2;
     282        uint8_t vendor_id[8];   /** Vendor ID */
     283        uint8_t product_id[8];  /** Product ID */
     284        uint8_t product_rev[4]; /** Product revision level */
     285} ata_inquiry_data_t;
     286
     287/** Extract value of ata_inquiry_data_t.pdev_type */
     288#define INQUIRY_PDEV_TYPE(val) ((val) & 0x1f)
     289
     290/** Values for ata_inquiry_data_t.pdev_type */
     291enum ata_pdev_type {
     292        PDEV_TYPE_CDROM         = 0x05
     293};
     294
    243295#endif
    244296
Note: See TracChangeset for help on using the changeset viewer.