[4f5caea] | 1 | /*
|
---|
[d7f7a4a] | 2 | * SPDX-FileCopyrightText: 2009 Jiri Svoboda
|
---|
[4f5caea] | 3 | *
|
---|
[d7f7a4a] | 4 | * SPDX-License-Identifier: BSD-3-Clause
|
---|
[4f5caea] | 5 | */
|
---|
| 6 |
|
---|
[c8ea6eca] | 7 | /** @addtogroup ata_bd
|
---|
[4f5caea] | 8 | * @{
|
---|
| 9 | */
|
---|
[d770deb] | 10 | /** @file ATA driver definitions.
|
---|
[4f5caea] | 11 | */
|
---|
| 12 |
|
---|
| 13 | #ifndef __ATA_BD_H__
|
---|
| 14 | #define __ATA_BD_H__
|
---|
| 15 |
|
---|
[66cb7a2] | 16 | #include <async.h>
|
---|
[4802dd7] | 17 | #include <bd_srv.h>
|
---|
[66cb7a2] | 18 | #include <ddf/driver.h>
|
---|
[1e4cada] | 19 | #include <fibril_synch.h>
|
---|
[19f857a] | 20 | #include <str.h>
|
---|
[8d2dd7f2] | 21 | #include <stdint.h>
|
---|
| 22 | #include <stddef.h>
|
---|
[66cb7a2] | 23 | #include "ata_hw.h"
|
---|
| 24 |
|
---|
| 25 | #define NAME "ata_bd"
|
---|
[4f5caea] | 26 |
|
---|
[e092dc5] | 27 | /** Base addresses for ATA I/O blocks. */
|
---|
| 28 | typedef struct {
|
---|
| 29 | uintptr_t cmd; /**< Command block base address. */
|
---|
| 30 | uintptr_t ctl; /**< Control block base address. */
|
---|
| 31 | } ata_base_t;
|
---|
| 32 |
|
---|
[31de325] | 33 | /** Timeout definitions. Unit is 10 ms. */
|
---|
| 34 | enum ata_timeout {
|
---|
| 35 | TIMEOUT_PROBE = 100, /* 1 s */
|
---|
| 36 | TIMEOUT_BSY = 100, /* 1 s */
|
---|
| 37 | TIMEOUT_DRDY = 1000 /* 10 s */
|
---|
| 38 | };
|
---|
| 39 |
|
---|
[7a56e33e] | 40 | enum ata_dev_type {
|
---|
| 41 | ata_reg_dev, /* Register device (no packet feature set support) */
|
---|
| 42 | ata_pkt_dev /* Packet device (supports packet feature set). */
|
---|
| 43 | };
|
---|
| 44 |
|
---|
| 45 | /** Register device block addressing mode. */
|
---|
| 46 | enum rd_addr_mode {
|
---|
[a1f48f6] | 47 | am_chs, /**< CHS block addressing */
|
---|
| 48 | am_lba28, /**< LBA-28 block addressing */
|
---|
| 49 | am_lba48 /**< LBA-48 block addressing */
|
---|
[a99cf073] | 50 | };
|
---|
| 51 |
|
---|
[5048be7] | 52 | /** Block coordinates */
|
---|
| 53 | typedef struct {
|
---|
[7a56e33e] | 54 | enum rd_addr_mode amode;
|
---|
[5048be7] | 55 |
|
---|
| 56 | union {
|
---|
| 57 | /** CHS coordinates */
|
---|
| 58 | struct {
|
---|
| 59 | uint8_t sector;
|
---|
| 60 | uint8_t cyl_lo;
|
---|
| 61 | uint8_t cyl_hi;
|
---|
| 62 | };
|
---|
| 63 | /** LBA coordinates */
|
---|
| 64 | struct {
|
---|
| 65 | uint8_t c0;
|
---|
| 66 | uint8_t c1;
|
---|
| 67 | uint8_t c2;
|
---|
| 68 | uint8_t c3;
|
---|
| 69 | uint8_t c4;
|
---|
| 70 | uint8_t c5;
|
---|
| 71 | };
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | /** Lower 4 bits for device/head register */
|
---|
| 75 | uint8_t h;
|
---|
| 76 | } block_coord_t;
|
---|
| 77 |
|
---|
[e092dc5] | 78 | /** ATA device state structure. */
|
---|
[4f5caea] | 79 | typedef struct {
|
---|
| 80 | bool present;
|
---|
[96cbd18] | 81 | struct ata_ctrl *ctrl;
|
---|
[66cb7a2] | 82 | struct ata_fun *afun;
|
---|
[7a56e33e] | 83 |
|
---|
| 84 | /** Device type */
|
---|
| 85 | enum ata_dev_type dev_type;
|
---|
| 86 |
|
---|
| 87 | /** Addressing mode to use (if register device) */
|
---|
| 88 | enum rd_addr_mode amode;
|
---|
[a99cf073] | 89 |
|
---|
| 90 | /*
|
---|
| 91 | * Geometry. Only valid if operating in CHS mode.
|
---|
| 92 | */
|
---|
| 93 | struct {
|
---|
| 94 | unsigned heads;
|
---|
| 95 | unsigned cylinders;
|
---|
| 96 | unsigned sectors;
|
---|
| 97 | } geom;
|
---|
| 98 |
|
---|
[4f5caea] | 99 | uint64_t blocks;
|
---|
[0d247f5] | 100 | size_t block_size;
|
---|
[12956e57] | 101 |
|
---|
[0e6dce8] | 102 | char model[STR_BOUNDS(40) + 1];
|
---|
| 103 |
|
---|
[4802dd7] | 104 | int disk_id;
|
---|
[4f5caea] | 105 | } disk_t;
|
---|
| 106 |
|
---|
[96cbd18] | 107 | /** ATA controller */
|
---|
| 108 | typedef struct ata_ctrl {
|
---|
[66cb7a2] | 109 | /** DDF device */
|
---|
| 110 | ddf_dev_t *dev;
|
---|
[96cbd18] | 111 | /** I/O base address of the command registers */
|
---|
| 112 | uintptr_t cmd_physical;
|
---|
| 113 | /** I/O base address of the control registers */
|
---|
| 114 | uintptr_t ctl_physical;
|
---|
| 115 |
|
---|
| 116 | /** Command registers */
|
---|
| 117 | ata_cmd_t *cmd;
|
---|
| 118 | /** Control registers */
|
---|
| 119 | ata_ctl_t *ctl;
|
---|
| 120 |
|
---|
| 121 | /** Per-disk state. */
|
---|
| 122 | disk_t disk[MAX_DISKS];
|
---|
[66cb7a2] | 123 |
|
---|
| 124 | fibril_mutex_t lock;
|
---|
[96cbd18] | 125 | } ata_ctrl_t;
|
---|
| 126 |
|
---|
[66cb7a2] | 127 | typedef struct ata_fun {
|
---|
| 128 | ddf_fun_t *fun;
|
---|
| 129 | disk_t *disk;
|
---|
| 130 | bd_srvs_t bds;
|
---|
| 131 | } ata_fun_t;
|
---|
| 132 |
|
---|
[b7fd2a0] | 133 | extern errno_t ata_ctrl_init(ata_ctrl_t *, ata_base_t *);
|
---|
| 134 | extern errno_t ata_ctrl_remove(ata_ctrl_t *);
|
---|
| 135 | extern errno_t ata_ctrl_gone(ata_ctrl_t *);
|
---|
[66cb7a2] | 136 |
|
---|
| 137 | extern bd_ops_t ata_bd_ops;
|
---|
| 138 |
|
---|
[4f5caea] | 139 | #endif
|
---|
| 140 |
|
---|
| 141 | /** @}
|
---|
| 142 | */
|
---|