source: mainline/uspace/drv/block/ata_bd/ata_bd.h@ 95feb3e9

Last change on this file since 95feb3e9 was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Replace some license headers with SPDX identifier

Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2009 Jiri Svoboda
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/** @addtogroup ata_bd
8 * @{
9 */
10/** @file ATA driver definitions.
11 */
12
13#ifndef __ATA_BD_H__
14#define __ATA_BD_H__
15
16#include <async.h>
17#include <bd_srv.h>
18#include <ddf/driver.h>
19#include <fibril_synch.h>
20#include <str.h>
21#include <stdint.h>
22#include <stddef.h>
23#include "ata_hw.h"
24
25#define NAME "ata_bd"
26
27/** Base addresses for ATA I/O blocks. */
28typedef struct {
29 uintptr_t cmd; /**< Command block base address. */
30 uintptr_t ctl; /**< Control block base address. */
31} ata_base_t;
32
33/** Timeout definitions. Unit is 10 ms. */
34enum ata_timeout {
35 TIMEOUT_PROBE = 100, /* 1 s */
36 TIMEOUT_BSY = 100, /* 1 s */
37 TIMEOUT_DRDY = 1000 /* 10 s */
38};
39
40enum 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. */
46enum rd_addr_mode {
47 am_chs, /**< CHS block addressing */
48 am_lba28, /**< LBA-28 block addressing */
49 am_lba48 /**< LBA-48 block addressing */
50};
51
52/** Block coordinates */
53typedef struct {
54 enum rd_addr_mode amode;
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
78/** ATA device state structure. */
79typedef struct {
80 bool present;
81 struct ata_ctrl *ctrl;
82 struct ata_fun *afun;
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;
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
99 uint64_t blocks;
100 size_t block_size;
101
102 char model[STR_BOUNDS(40) + 1];
103
104 int disk_id;
105} disk_t;
106
107/** ATA controller */
108typedef struct ata_ctrl {
109 /** DDF device */
110 ddf_dev_t *dev;
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];
123
124 fibril_mutex_t lock;
125} ata_ctrl_t;
126
127typedef struct ata_fun {
128 ddf_fun_t *fun;
129 disk_t *disk;
130 bd_srvs_t bds;
131} ata_fun_t;
132
133extern errno_t ata_ctrl_init(ata_ctrl_t *, ata_base_t *);
134extern errno_t ata_ctrl_remove(ata_ctrl_t *);
135extern errno_t ata_ctrl_gone(ata_ctrl_t *);
136
137extern bd_ops_t ata_bd_ops;
138
139#endif
140
141/** @}
142 */
Note: See TracBrowser for help on using the repository browser.