xref: /haiku/src/add-ons/kernel/bus_managers/ata/ATAInfoBlock.h (revision a085e81e62d7a860f809b4fb7c7bf5654c396985)
1 /*
2  * Copyright 2010-2013, Axel Dörfler, axeld@pinc-software.de.
3  * Copyright 2009, Michael Lotz, mmlr@mlotz.ch.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef ATA_INFOBLOCK_H
7 #define ATA_INFOBLOCK_H
8 
9 
10 #include <lendian_bitfield.h>
11 
12 
13 #define ATA_WORD_0_ATA_DEVICE		0
14 #define ATA_WORD_0_ATAPI_DEVICE		2
15 #define ATA_WORD_0_CFA_MAGIC		0x848a
16 
17 
18 typedef struct ata_device_infoblock {
19 	union {
20 		struct {
21 			LBITFIELD8(
22 				word_0_bit_0_reserved			: 1,
23 				word_0_bit_1_retired			: 1,
24 				response_incomplete				: 1,
25 				word_0_bit_3_5_retired			: 3,
26 				word_0_bit_6_obsolete			: 1,
27 				removable_media_device			: 1,
28 				word_0_bit_8_14_retired			: 7,
29 				ata_device						: 1		// 0 means ATA
30 			);
31 		} ata;
32 		struct {
33 			LBITFIELD8(
34 				packet_length					: 2,	// 0 = 12, 1 = 16 bytes
35 				response_incomplete				: 1,
36 				word_0_bit_3_4_reserved			: 2,
37 				data_request_delay				: 2,	// 0 = 3ms, 2 = 50us
38 				removable_media_device			: 1,
39 				command_packet_set				: 5,
40 				word_0_bit_13_reserved			: 1,
41 				atapi_device					: 2		// 2 means ATAPI
42 			);
43 		} atapi;
44 		uint16 raw;
45 	} word_0;
46 
47 	uint16	word_1_obsolete;
48 	uint16	specific_configuration;
49 	uint16	word_3_obsolete;
50 	uint16	word_4_5_retired[2];
51 	uint16	word_6_obsolete;
52 	uint16	word_7_8_reserved_compact_flash_assoc[2];
53 	uint16	word_9_retired;
54 	char	serial_number[20];
55 	uint16	word_20_21_retired[2];
56 	uint16	word_22_obsolete;
57 	char	firmware_revision[8];
58 	char	model_number[40];
59 
60 	LBITFIELD2(
61 		max_sectors_per_interrupt				: 8,
62 		word_47_bit_8_15_80h					: 8		// should be 0x80
63 	);
64 
65 	uint16	word_48_reserved;
66 
67 	LBITFIELD9(
68 		word_49_bit_0_7_retired					: 8,
69 		dma_supported							: 1,
70 		lba_supported							: 1,
71 		io_ready_disable						: 1,
72 		io_ready_supported						: 1,
73 		word_19_bit_12_obsolete					: 1,
74 		standby_timer_standard					: 1,
75 		atapi_command_queuing_supported			: 1,
76 		atapi_interleaved_dma_supported			: 1
77 	);
78 
79 	LBITFIELD5(
80 		standby_timer_value_min					: 1,
81 		word_50_bit_1_obsolete					: 1,
82 		word_50_bit_2_13_reserved				: 12,
83 		word_50_bit_14_one						: 1,
84 		word_50_bit_15_zero						: 1
85 	);
86 
87 	uint16	word_51_52_obsolete[2];
88 
89 	LBITFIELD4(
90 		word_53_bit_0_obsolete					: 1,
91 		word_64_70_valid						: 1,
92 		word_88_valid							: 1,
93 		word_53_bit_3_15						: 13
94 	);
95 
96 	uint16	word_54_58_obsolete[5];
97 
98 	LBITFIELD3(
99 		current_sectors_per_interrupt			: 8,
100 		multiple_sector_setting_valid			: 1,
101 		word_59_bit_9_15_reserved				: 7
102 	);
103 
104 	uint32	lba_sector_count;
105 	uint16	word_62_obsolete;
106 
107 	LBITFIELD8(
108 		multiword_dma_0_supported				: 1,
109 		multiword_dma_1_supported				: 1,
110 		multiword_dma_2_supported				: 1,
111 		word_63_bit_3_7_resereved				: 5,
112 		multiword_dma_0_selected				: 1,
113 		multiword_dma_1_selected				: 1,
114 		multiword_dma_2_selected				: 1,
115 		word_63_bit_11_15_reserved				: 5
116 	);
117 
118 	LBITFIELD2(
119 		pio_modes_supported						: 8,
120 		word_64_bit_8_15_reserved				: 8
121 	);
122 
123 	uint16	min_multiword_dma_cycle_time;
124 	uint16	recommended_multiword_dma_cycle_time;
125 	uint16	min_pio_cycle_time;
126 	uint16	min_pio_cycle_time_io_ready;
127 	uint16	word_69_70_reserved[2];
128 	uint16	atapi_packet_received_to_bus_release_time_ns;
129 	uint16	atapi_service_command_to_busy_clear_time_ns;
130 	uint16	word_71_74_reserved[2];
131 
132 	LBITFIELD2(
133 		max_queue_depth_minus_one				: 5,
134 		word_75_bit_5_15_reserved				: 11
135 	);
136 
137 	uint16	word_76_79_reserved[4];
138 
139 	LBITFIELD15(
140 		word_80_bit_0_reserved					: 1,
141 		word_80_bot_1_2_obsolete				: 2,
142 		supports_ata_3							: 1,
143 		supports_ata_atapi_4					: 1,
144 		supports_ata_atapi_5					: 1,
145 		supports_ata_atapi_6					: 1,
146 		supports_ata_atapi_7					: 1,
147 		supports_ata_atapi_8					: 1,
148 		supports_ata_atapi_9					: 1,
149 		supports_ata_atapi_10					: 1,
150 		supports_ata_atapi_11					: 1,
151 		supports_ata_atapi_12					: 1,
152 		supports_ata_atapi_13					: 1,
153 		supports_ata_atapi_14					: 1,
154 		word_80_bit_15_reserved					: 1
155 	);
156 
157 	uint16	minor_version;
158 
159 	LBITFIELD16(
160 		smart_supported							: 1,
161 		security_mode_supported					: 1,
162 		removable_media_supported				: 1,
163 		mandatory_power_management_supported	: 1,
164 		packet_supported						: 1,
165 		write_cache_supported					: 1,
166 		look_ahead_supported					: 1,
167 		release_interrupt_supported				: 1,
168 		service_interrupt_supported				: 1,
169 		device_reset_supported					: 1,
170 		host_protected_area_supported			: 1,
171 		word_82_bit_11_obsolete					: 1,
172 		write_buffer_command_supported			: 1,
173 		read_buffer_command_supported			: 1,
174 		nop_supported							: 1,
175 		word_82_bit_15_obsolete					: 1
176 	);
177 
178 	LBITFIELD16(
179 		download_microcode_supported			: 1,
180 		read_write_dma_queued_supported			: 1,
181 		compact_flash_assoc_supported			: 1,
182 		advanced_power_management_supported		: 1,
183 		removable_media_status_supported		: 1,
184 		power_up_in_standby_supported			: 1,
185 		set_features_required_for_spinup		: 1,
186 		word_83_bit_7_reserved					: 1,
187 		set_max_security_extension_supported	: 1,
188 		automatic_acoustic_management_supported	: 1,
189 		lba48_supported							: 1,
190 		device_configuration_overlay_supported	: 1,
191 		mandatory_flush_cache_supported			: 1,
192 		flush_cache_ext_supported				: 1,
193 		word_83_bit_14_one						: 1,
194 		word_83_bit_15_zero						: 1
195 	);
196 
197 	LBITFIELD9(
198 		smart_error_logging_supported			: 1,
199 		smart_self_test_supported				: 1,
200 		media_serial_number_supported			: 1,
201 		media_card_pass_through_supported		: 1,
202 		word_84_bit_4_reserved					: 1,
203 		general_purpose_logging_supported		: 1,
204 		word_84_bit_6_13_reserved				: 8,
205 		word_84_bit_14_one						: 1,
206 		word_84_bit_15_zero						: 1
207 	);
208 
209 	LBITFIELD16(
210 		smart_enabled							: 1,
211 		security_mode_enabled					: 1,
212 		removable_media_enabled					: 1,
213 		mandatory_power_management_enabled		: 1,
214 		packet_enabled							: 1,
215 		write_cache_enabled						: 1,
216 		look_ahead_enabled						: 1,
217 		release_interrupt_enabled				: 1,
218 		service_interrupt_enabled				: 1,
219 		device_reset_enabled					: 1,
220 		host_protected_area_enabled				: 1,
221 		word_85_bit_11_obsolete					: 1,
222 		write_buffer_command_enabled			: 1,
223 		read_buffer_command_enabled				: 1,
224 		nop_enabled								: 1,
225 		word_85_bit_15_obsolete					: 1
226 	);
227 
228 	LBITFIELD15(
229 		download_microcode_supported_2			: 1,
230 		read_write_dma_queued_supported_2		: 1,
231 		compact_flash_assoc_enabled				: 1,
232 		advanced_power_management_enabled		: 1,
233 		removable_media_status_enabled			: 1,
234 		power_up_in_standby_enabled				: 1,
235 		set_features_required_for_spinup_2		: 1,
236 		word_86_bit_7_reserved					: 1,
237 		set_max_security_extension_enabled		: 1,
238 		automatic_acoustic_management_enabled	: 1,
239 		lba48_supported_2						: 1,
240 		device_configuration_overlay_supported_2: 1,
241 		mandatory_flush_cache_supported_2		: 1,
242 		flush_cache_ext_supported_2				: 1,
243 		word_86_bit_14_15_reserved				: 2
244 	);
245 
246 	LBITFIELD9(
247 		smart_error_logging_supported_2			: 1,
248 		smart_self_test_supported_2				: 1,
249 		media_serial_number_valid				: 1,
250 		media_card_pass_through_enabled			: 1,
251 		word_87_bit_4_reserved					: 1,
252 		general_purpose_logging_supported_2		: 1,
253 		word_87_bit_6_13_reserved				: 8,
254 		word_87_bit_14_one						: 1,
255 		word_87_bit_15_zero						: 1
256 	);
257 
258 	LBITFIELD16(
259 		ultra_dma_0_supported					: 1,
260 		ultra_dma_1_supported					: 1,
261 		ultra_dma_2_supported					: 1,
262 		ultra_dma_3_supported					: 1,
263 		ultra_dma_4_supported					: 1,
264 		ultra_dma_5_supported					: 1,
265 		ultra_dma_6_supported					: 1,
266 		word_88_bit_7_reserved					: 1,
267 		ultra_dma_0_selected					: 1,
268 		ultra_dma_1_selected					: 1,
269 		ultra_dma_2_selected					: 1,
270 		ultra_dma_3_selected					: 1,
271 		ultra_dma_4_selected					: 1,
272 		ultra_dma_5_selected					: 1,
273 		ultra_dma_6_selected					: 1,
274 		word_88_bit_15_reserved					: 1
275 	);
276 
277 	uint16	security_erase_unit_duration;
278 	uint16	enhanced_security_erase_duration;
279 	uint16	current_advanced_power_management_value;
280 	uint16	master_password_revision_code;
281 
282 	LBITFIELD5(
283 		device_0_hardware_reset_result			: 8,
284 		device_1_hardware_reset_result			: 5,
285 		cable_id_detected						: 1,
286 		word_93_bit_14_one						: 1,
287 		word_93_bit_15_zero						: 1
288 	);
289 
290 	LBITFIELD2(
291 		current_acoustic_management_value		: 8,
292 		recommended_acoustic_management_value	: 8
293 	);
294 
295 	uint16	word_95_99_reserved[5];
296 	uint64	lba48_sector_count;
297 	uint16	word_104_105_reserved[2];
298 
299 	LBITFIELD6(
300 		logical_sectors_per_physical_sector		: 4,	// 2^x exponent
301 		word_106_bit_4_11_reserved				: 8,
302 		logical_sector_not_512_bytes			: 1,
303 		multiple_logical_per_physical_sectors	: 1,
304 		word_106_bit_14_one						: 1,
305 		word_106_bit_15_zero					: 1
306 	);
307 
308 	uint16	word_107_116_reserved[10];
309 
310 	uint32	logical_sector_size;						// in words, see 106
311 
312 	uint16	word_119_126_reserved[8];
313 
314 	LBITFIELD2(
315 		removable_media_status_supported_2		: 2,	// 1 = supported
316 		word_127_bit_2_15_reserved				: 14
317 	);
318 
319 	LBITFIELD9(
320 		security_supported						: 1,
321 		security_enabled						: 1,
322 		security_locked							: 1,
323 		security_frozen							: 1,
324 		security_count_expired					: 1,
325 		ehnaced_security_erase_supported		: 1,
326 		word_128_bit_6_7_reserved				: 2,
327 		security_level							: 1,	// 0 = high, 1 = max
328 		word_128_bit_9_15						: 7
329 	);
330 
331 	uint16	word_129_159_vendor_specific[31];
332 
333 	LBITFIELD5(
334 		cfa_max_current_milli_ampers			: 12,
335 		cfa_power_mode_1_disabled				: 1,
336 		cfa_power_mode_1_required				: 1,
337 		word_160_bit_14_reserved				: 1,
338 		word_160_supported						: 1
339 	);
340 
341 	uint16	word_161_167_reserved_compact_flash_assoc[7];
342 	LBITFIELD2(
343 		device_nominal_form_factor				: 4,
344 		word_168_bits_4_15_reserved				: 12
345 	);
346 	LBITFIELD2(
347 		data_set_management_support				: 1,
348 		word_169_bits_1_15_reserved				: 15
349 	);
350 	uint16	additional_product_identifier[4];
351 	uint16	word_174_175_reserved[2];
352 	uint16	current_media_serial_number[30];
353 	uint16	word_206_208_reserved[3];
354 
355 	LBITFIELD3(
356 		logical_sector_offset					: 14,
357 		word_209_bit_14_one						: 1,
358 		word_209_bit_15_zero					: 1
359 	);
360 
361 	uint16	word_210_254_reserved[45];
362 
363 	LBITFIELD2(
364 		signature								: 8,
365 		checksum								: 8
366 	);
367 
368 	uint64 SectorCount(bool& use48Bits, bool force)
369 	{
370 		if (lba48_supported && lba48_sector_count >= lba_sector_count) {
371 			use48Bits = true;
372 			return lba48_sector_count;
373 		}
374 
375 		use48Bits = force ? lba48_supported : false;
376 		return lba_sector_count;
377 	}
378 
379 	uint32 PhysicalSectorSize()
380 	{
381 		uint32 blockSize = 512;
382 		if (word_106_bit_14_one && !word_106_bit_15_zero) {
383 			// contains a valid block size configuration
384 			if (logical_sector_not_512_bytes)
385 				blockSize = logical_sector_size * 2;
386 
387 			if (multiple_logical_per_physical_sectors)
388 				return blockSize << logical_sectors_per_physical_sector;
389 		}
390 		return blockSize;
391 	}
392 
393 	uint32 SectorSize()
394 	{
395 		if (word_106_bit_14_one && !word_106_bit_15_zero) {
396 			// contains a valid block size configuration
397 			if (logical_sector_not_512_bytes)
398 				return logical_sector_size * 2;
399 		}
400 		return 512;
401 	}
402 
403 	uint32 BlockOffset()
404 	{
405 		if (word_209_bit_14_one && !word_209_bit_15_zero) {
406 			// contains a valid logical block offset configuration
407 			return logical_sector_offset;
408 		}
409 		return 0;
410 	}
411 } _PACKED ata_device_infoblock;
412 
413 
414 #endif // ATA_INFOBLOCK_H
415