iPXE
ata.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27#include <stddef.h>
28#include <stdlib.h>
29#include <string.h>
30#include <assert.h>
31#include <errno.h>
32#include <byteswap.h>
33#include <ipxe/list.h>
34#include <ipxe/interface.h>
35#include <ipxe/blockdev.h>
36#include <ipxe/edd.h>
37#include <ipxe/ata.h>
38
39/** @file
40 *
41 * ATA block device
42 *
43 */
44
45/******************************************************************************
46 *
47 * Interface methods
48 *
49 ******************************************************************************
50 */
51
52/**
53 * Issue ATA command
54 *
55 * @v control ATA control interface
56 * @v data ATA data interface
57 * @v command ATA command
58 * @ret tag Command tag, or negative error
59 */
61 struct ata_cmd *command ) {
62 struct interface *dest;
63 ata_command_TYPE ( void * ) *op =
65 void *object = intf_object ( dest );
66 int tag;
67
68 if ( op ) {
69 tag = op ( object, data, command );
70 } else {
71 /* Default is to fail to issue the command */
72 tag = -EOPNOTSUPP;
73 }
74
75 intf_put ( dest );
76 return tag;
77}
78
79/******************************************************************************
80 *
81 * ATA devices and commands
82 *
83 ******************************************************************************
84 */
85
86/** List of all ATA commands */
87static LIST_HEAD ( ata_commands );
88
89/** An ATA device */
90struct ata_device {
91 /** Reference count */
92 struct refcnt refcnt;
93 /** Block control interface */
95 /** ATA control interface */
96 struct interface ata;
97
98 /** Device number
99 *
100 * Must be ATA_DEV_MASTER or ATA_DEV_SLAVE.
101 */
102 unsigned int device;
103 /** Maximum number of blocks per single transfer */
104 unsigned int max_count;
105 /** Device uses LBA48 extended addressing */
106 int lba48;
107};
108
109/** An ATA command */
111 /** Reference count */
113 /** ATA device */
115 /** List of ATA commands */
117
118 /** Block data interface */
120 /** ATA data interface */
122
123 /** Command type */
125 /** Command tag */
127
128 /** Private data */
130};
131
132/** An ATA command type */
134 /** Name */
135 const char *name;
136 /** Additional working space */
137 size_t priv_len;
138 /** Command for non-LBA48-capable devices */
140 /** Command for LBA48-capable devices */
142 /**
143 * Calculate data-in buffer
144 *
145 * @v atacmd ATA command
146 * @v buffer Available buffer
147 * @v len Available buffer length
148 * @ret data_in Data-in buffer
149 * @ret data_in_len Data-in buffer length
150 */
151 void ( * data_in ) ( struct ata_command *atacmd, void *buffer,
152 size_t len, void **data_in,
153 size_t *data_in_len );
154 /**
155 * Calculate data-out buffer
156 *
157 *
158 * @v atacmd ATA command
159 * @v buffer Available buffer
160 * @v len Available buffer length
161 * @ret data_out Data-out buffer
162 * @ret data_out_len Data-out buffer length
163 */
164 void ( * data_out ) ( struct ata_command *atacmd, void *buffer,
165 size_t len, void **data_out,
166 size_t *data_out_len );
167 /**
168 * Handle ATA command completion
169 *
170 * @v atacmd ATA command
171 * @v rc Reason for completion
172 */
173 void ( * done ) ( struct ata_command *atacmd, int rc );
174};
175
176/**
177 * Get reference to ATA device
178 *
179 * @v atadev ATA device
180 * @ret atadev ATA device
181 */
182static inline __attribute__ (( always_inline )) struct ata_device *
183atadev_get ( struct ata_device *atadev ) {
184 ref_get ( &atadev->refcnt );
185 return atadev;
186}
187
188/**
189 * Drop reference to ATA device
190 *
191 * @v atadev ATA device
192 */
193static inline __attribute__ (( always_inline )) void
194atadev_put ( struct ata_device *atadev ) {
195 ref_put ( &atadev->refcnt );
196}
197
198/**
199 * Get reference to ATA command
200 *
201 * @v atacmd ATA command
202 * @ret atacmd ATA command
203 */
204static inline __attribute__ (( always_inline )) struct ata_command *
205atacmd_get ( struct ata_command *atacmd ) {
206 ref_get ( &atacmd->refcnt );
207 return atacmd;
208}
209
210/**
211 * Drop reference to ATA command
212 *
213 * @v atacmd ATA command
214 */
215static inline __attribute__ (( always_inline )) void
216atacmd_put ( struct ata_command *atacmd ) {
217 ref_put ( &atacmd->refcnt );
218}
219
220/**
221 * Get ATA command private data
222 *
223 * @v atacmd ATA command
224 * @ret priv Private data
225 */
226static inline __attribute__ (( always_inline )) void *
227atacmd_priv ( struct ata_command *atacmd ) {
228 return atacmd->priv;
229}
230
231/**
232 * Free ATA command
233 *
234 * @v refcnt Reference count
235 */
236static void atacmd_free ( struct refcnt *refcnt ) {
237 struct ata_command *atacmd =
239
240 /* Remove from list of commands */
241 list_del ( &atacmd->list );
242 atadev_put ( atacmd->atadev );
243
244 /* Free command */
245 free ( atacmd );
246}
247
248/**
249 * Close ATA command
250 *
251 * @v atacmd ATA command
252 * @v rc Reason for close
253 */
254static void atacmd_close ( struct ata_command *atacmd, int rc ) {
255 struct ata_device *atadev = atacmd->atadev;
256
257 if ( rc != 0 ) {
258 DBGC ( atadev, "ATA %p tag %08x closed: %s\n",
259 atadev, atacmd->tag, strerror ( rc ) );
260 }
261
262 /* Shut down interfaces */
263 intf_shutdown ( &atacmd->ata, rc );
264 intf_shutdown ( &atacmd->block, rc );
265}
266
267/**
268 * Handle ATA command completion
269 *
270 * @v atacmd ATA command
271 * @v rc Reason for close
272 */
273static void atacmd_done ( struct ata_command *atacmd, int rc ) {
274
275 /* Hand over to the command completion handler */
276 atacmd->type->done ( atacmd, rc );
277}
278
279/**
280 * Use provided data buffer for ATA command
281 *
282 * @v atacmd ATA command
283 * @v buffer Available buffer
284 * @v len Available buffer length
285 * @ret data Data buffer
286 * @ret data_len Data buffer length
287 */
288static void atacmd_data_buffer ( struct ata_command *atacmd __unused,
289 void *buffer, size_t len,
290 void **data, size_t *data_len ) {
291 *data = buffer;
292 *data_len = len;
293}
294
295/**
296 * Use no data buffer for ATA command
297 *
298 * @v atacmd ATA command
299 * @v buffer Available buffer
300 * @v len Available buffer length
301 * @ret data Data buffer
302 * @ret data_len Data buffer length
303 */
304static void atacmd_data_none ( struct ata_command *atacmd __unused,
305 void *buffer __unused, size_t len __unused,
306 void **data __unused,
307 size_t *data_len __unused ) {
308 /* Nothing to do */
309}
310
311/**
312 * Use private data buffer for ATA command
313 *
314 * @v atacmd ATA command
315 * @v buffer Available buffer
316 * @v len Available buffer length
317 * @ret data Data buffer
318 * @ret data_len Data buffer length
319 */
320static void atacmd_data_priv ( struct ata_command *atacmd,
321 void *buffer __unused, size_t len __unused,
322 void **data, size_t *data_len ) {
323 *data = atacmd_priv ( atacmd );
324 *data_len = atacmd->type->priv_len;
325}
326
327/** ATA READ command type */
329 .name = "READ",
330 .cmd_lba = ATA_CMD_READ,
331 .cmd_lba48 = ATA_CMD_READ_EXT,
332 .data_in = atacmd_data_buffer,
333 .data_out = atacmd_data_none,
334 .done = atacmd_close,
335};
336
337/** ATA WRITE command type */
339 .name = "WRITE",
340 .cmd_lba = ATA_CMD_WRITE,
341 .cmd_lba48 = ATA_CMD_WRITE_EXT,
342 .data_in = atacmd_data_none,
343 .data_out = atacmd_data_buffer,
344 .done = atacmd_close,
345};
346
347/** ATA IDENTIFY private data */
349 /** Identity data */
351};
352
353/**
354 * Return ATA model string (for debugging)
355 *
356 * @v identify ATA identity data
357 * @ret model Model string
358 */
359static const char * ata_model ( struct ata_identity *identity ) {
360 static union {
361 uint16_t words[ sizeof ( identity->model ) / 2 ];
362 char text[ sizeof ( identity->model ) + 1 /* NUL */ ];
363 } buf;
364 unsigned int i;
365
366 for ( i = 0 ; i < ( sizeof ( identity->model ) / 2 ) ; i++ )
367 buf.words[i] = bswap_16 ( identity->model[i] );
368
369 return buf.text;
370}
371
372/**
373 * Handle ATA IDENTIFY command completion
374 *
375 * @v atacmd ATA command
376 * @v rc Reason for completion
377 */
378static void atacmd_identify_done ( struct ata_command *atacmd, int rc ) {
379 struct ata_device *atadev = atacmd->atadev;
380 struct ata_identify_private *priv = atacmd_priv ( atacmd );
381 struct ata_identity *identity = &priv->identity;
382 struct block_device_capacity capacity;
383
384 /* Close if command failed */
385 if ( rc != 0 ) {
386 atacmd_close ( atacmd, rc );
387 return;
388 }
389
390 /* Extract capacity */
391 if ( identity->supports_lba48 & cpu_to_le16 ( ATA_SUPPORTS_LBA48 ) ) {
392 atadev->lba48 = 1;
393 capacity.blocks = le64_to_cpu ( identity->lba48_sectors );
394 } else {
395 capacity.blocks = le32_to_cpu ( identity->lba_sectors );
396 }
397 capacity.blksize = ATA_SECTOR_SIZE;
398 capacity.max_count = atadev->max_count;
399 DBGC ( atadev, "ATA %p is a %s\n", atadev, ata_model ( identity ) );
400 DBGC ( atadev, "ATA %p has %#llx blocks (%ld MB) and uses %s\n",
401 atadev, capacity.blocks,
402 ( ( signed long ) ( capacity.blocks >> 11 ) ),
403 ( atadev->lba48 ? "LBA48" : "LBA" ) );
404
405 /* Return capacity to caller */
406 block_capacity ( &atacmd->block, &capacity );
407
408 /* Close command */
409 atacmd_close ( atacmd, 0 );
410}
411
412/** ATA IDENTITY command type */
414 .name = "IDENTIFY",
415 .priv_len = sizeof ( struct ata_identify_private ),
416 .cmd_lba = ATA_CMD_IDENTIFY,
417 .cmd_lba48 = ATA_CMD_IDENTIFY,
418 .data_in = atacmd_data_priv,
419 .data_out = atacmd_data_none,
420 .done = atacmd_identify_done,
421};
422
423/** ATA command block interface operations */
426};
427
428/** ATA command block interface descriptor */
431 atacmd_block_op, ata );
432
433/** ATA command ATA interface operations */
436};
437
438/** ATA command ATA interface descriptor */
440 INTF_DESC_PASSTHRU ( struct ata_command, ata,
442
443/**
444 * Create ATA command
445 *
446 * @v atadev ATA device
447 * @v block Block data interface
448 * @v type ATA command type
449 * @v lba Starting logical block address
450 * @v count Number of blocks to transfer
451 * @v buffer Data buffer
452 * @v len Length of data buffer
453 * @ret rc Return status code
454 */
455static int atadev_command ( struct ata_device *atadev,
456 struct interface *block,
457 struct ata_command_type *type,
458 uint64_t lba, unsigned int count,
459 void *buffer, size_t len ) {
460 struct ata_command *atacmd;
461 struct ata_cmd command;
462 int tag;
463 int rc;
464
465 /* Allocate and initialise structure */
466 atacmd = zalloc ( sizeof ( *atacmd ) + type->priv_len );
467 if ( ! atacmd ) {
468 rc = -ENOMEM;
469 goto err_zalloc;
470 }
471 ref_init ( &atacmd->refcnt, atacmd_free );
472 intf_init ( &atacmd->block, &atacmd_block_desc, &atacmd->refcnt );
473 intf_init ( &atacmd->ata, &atacmd_ata_desc,
474 &atacmd->refcnt );
475 atacmd->atadev = atadev_get ( atadev );
476 list_add ( &atacmd->list, &ata_commands );
477 atacmd->type = type;
478
479 /* Sanity check */
480 if ( len != ( count * ATA_SECTOR_SIZE ) ) {
481 DBGC ( atadev, "ATA %p tag %08x buffer length mismatch (count "
482 "%d len %zd)\n", atadev, atacmd->tag, count, len );
483 rc = -EINVAL;
484 goto err_len;
485 }
486
487 /* Construct command */
488 memset ( &command, 0, sizeof ( command ) );
489 command.cb.lba.native = lba;
490 command.cb.count.native = count;
491 command.cb.device = ( atadev->device | ATA_DEV_OBSOLETE | ATA_DEV_LBA );
492 command.cb.lba48 = atadev->lba48;
493 if ( ! atadev->lba48 )
494 command.cb.device |= command.cb.lba.bytes.low_prev;
495 command.cb.cmd_stat =
496 ( atadev->lba48 ? type->cmd_lba48 : type->cmd_lba );
497 type->data_in ( atacmd, buffer, len,
498 &command.data_in, &command.data_in_len );
499 type->data_out ( atacmd, buffer, len,
500 &command.data_out, &command.data_out_len );
501
502 /* Issue command */
503 if ( ( tag = ata_command ( &atadev->ata, &atacmd->ata,
504 &command ) ) < 0 ) {
505 rc = tag;
506 DBGC ( atadev, "ATA %p tag %08x could not issue command: %s\n",
507 atadev, atacmd->tag, strerror ( rc ) );
508 goto err_command;
509 }
510 atacmd->tag = tag;
511
512 DBGC2 ( atadev, "ATA %p tag %08x %s cmd %02x dev %02x LBA%s %08llx "
513 "count %04x\n", atadev, atacmd->tag, atacmd->type->name,
514 command.cb.cmd_stat, command.cb.device,
515 ( command.cb.lba48 ? "48" : "" ),
516 ( unsigned long long ) command.cb.lba.native,
517 command.cb.count.native );
518
519 /* Attach to parent interface, mortalise self, and return */
520 intf_plug_plug ( &atacmd->block, block );
521 ref_put ( &atacmd->refcnt );
522 return 0;
523
524 err_command:
525 err_len:
526 atacmd_close ( atacmd, rc );
527 ref_put ( &atacmd->refcnt );
528 err_zalloc:
529 return rc;
530}
531
532/**
533 * Issue ATA block read
534 *
535 * @v atadev ATA device
536 * @v block Block data interface
537 * @v lba Starting logical block address
538 * @v count Number of blocks to transfer
539 * @v buffer Data buffer
540 * @v len Length of data buffer
541 * @ret rc Return status code
542
543 */
544static int atadev_read ( struct ata_device *atadev,
545 struct interface *block,
546 uint64_t lba, unsigned int count,
547 void *buffer, size_t len ) {
548 return atadev_command ( atadev, block, &atacmd_read,
549 lba, count, buffer, len );
550}
551
552/**
553 * Issue ATA block write
554 *
555 * @v atadev ATA device
556 * @v block Block data interface
557 * @v lba Starting logical block address
558 * @v count Number of blocks to transfer
559 * @v buffer Data buffer
560 * @v len Length of data buffer
561 * @ret rc Return status code
562 */
563static int atadev_write ( struct ata_device *atadev,
564 struct interface *block,
565 uint64_t lba, unsigned int count,
566 void *buffer, size_t len ) {
567 return atadev_command ( atadev, block, &atacmd_write,
568 lba, count, buffer, len );
569}
570
571/**
572 * Read ATA device capacity
573 *
574 * @v atadev ATA device
575 * @v block Block data interface
576 * @ret rc Return status code
577 */
578static int atadev_read_capacity ( struct ata_device *atadev,
579 struct interface *block ) {
580 struct ata_identity *identity;
581
582 assert ( atacmd_identify.priv_len == sizeof ( *identity ) );
583 assert ( atacmd_identify.priv_len == ATA_SECTOR_SIZE );
584 return atadev_command ( atadev, block, &atacmd_identify,
585 0, 1, NULL, ATA_SECTOR_SIZE );
586}
587
588/**
589 * Close ATA device
590 *
591 * @v atadev ATA device
592 * @v rc Reason for close
593 */
594static void atadev_close ( struct ata_device *atadev, int rc ) {
595 struct ata_command *atacmd;
596 struct ata_command *tmp;
597
598 /* Shut down interfaces */
600 intf_shutdown ( &atadev->ata, rc );
601
602 /* Shut down any remaining commands */
603 list_for_each_entry_safe ( atacmd, tmp, &ata_commands, list ) {
604 if ( atacmd->atadev != atadev )
605 continue;
606 atacmd_get ( atacmd );
607 atacmd_close ( atacmd, rc );
608 atacmd_put ( atacmd );
609 }
610}
611
612/**
613 * Describe ATA device using EDD
614 *
615 * @v atadev ATA device
616 * @v type EDD interface type
617 * @v path EDD device path
618 * @ret rc Return status code
619 */
621 struct edd_interface_type *type,
622 union edd_device_path *path ) {
623
625 path->ata.slave = ( ( atadev->device == ATA_DEV_SLAVE ) ? 0x01 : 0x00 );
626 return 0;
627}
628
629/** ATA device block interface operations */
638
639/** ATA device block interface descriptor */
642 atadev_block_op, ata );
643
644/** ATA device ATA interface operations */
647};
648
649/** ATA device ATA interface descriptor */
651 INTF_DESC_PASSTHRU ( struct ata_device, ata,
653
654/**
655 * Open ATA device
656 *
657 * @v block Block control interface
658 * @v ata ATA control interface
659 * @v device ATA device number
660 * @v max_count Maximum number of blocks per single transfer
661 * @ret rc Return status code
662 */
663int ata_open ( struct interface *block, struct interface *ata,
664 unsigned int device, unsigned int max_count ) {
665 struct ata_device *atadev;
666
667 /* Allocate and initialise structure */
668 atadev = zalloc ( sizeof ( *atadev ) );
669 if ( ! atadev )
670 return -ENOMEM;
671 ref_init ( &atadev->refcnt, NULL );
672 intf_init ( &atadev->block, &atadev_block_desc, &atadev->refcnt );
673 intf_init ( &atadev->ata, &atadev_ata_desc, &atadev->refcnt );
674 atadev->device = device;
675 atadev->max_count = max_count;
676
677 /* Attach to ATA and parent and interfaces, mortalise self,
678 * and return
679 */
680 intf_plug_plug ( &atadev->ata, ata );
681 intf_plug_plug ( &atadev->block, block );
682 ref_put ( &atadev->refcnt );
683 return 0;
684}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
static void atacmd_free(struct refcnt *refcnt)
Free ATA command.
Definition ata.c:236
static int atadev_read_capacity(struct ata_device *atadev, struct interface *block)
Read ATA device capacity.
Definition ata.c:578
int ata_command(struct interface *control, struct interface *data, struct ata_cmd *command)
Issue ATA command.
Definition ata.c:60
static void atacmd_data_none(struct ata_command *atacmd __unused, void *buffer __unused, size_t len __unused, void **data __unused, size_t *data_len __unused)
Use no data buffer for ATA command.
Definition ata.c:304
int ata_open(struct interface *block, struct interface *ata, unsigned int device, unsigned int max_count)
Open ATA device.
Definition ata.c:663
static struct interface_operation atadev_block_op[]
ATA device block interface operations.
Definition ata.c:630
static struct interface_descriptor atadev_ata_desc
ATA device ATA interface descriptor.
Definition ata.c:650
static int atadev_edd_describe(struct ata_device *atadev, struct edd_interface_type *type, union edd_device_path *path)
Describe ATA device using EDD.
Definition ata.c:620
static struct ata_command_type atacmd_write
ATA WRITE command type.
Definition ata.c:338
static struct interface_descriptor atadev_block_desc
ATA device block interface descriptor.
Definition ata.c:640
static void atacmd_data_buffer(struct ata_command *atacmd __unused, void *buffer, size_t len, void **data, size_t *data_len)
Use provided data buffer for ATA command.
Definition ata.c:288
static struct interface_descriptor atacmd_ata_desc
ATA command ATA interface descriptor.
Definition ata.c:439
static void atacmd_done(struct ata_command *atacmd, int rc)
Handle ATA command completion.
Definition ata.c:273
static void atacmd_data_priv(struct ata_command *atacmd, void *buffer __unused, size_t len __unused, void **data, size_t *data_len)
Use private data buffer for ATA command.
Definition ata.c:320
static struct interface_operation atadev_ata_op[]
ATA device ATA interface operations.
Definition ata.c:645
static void atadev_close(struct ata_device *atadev, int rc)
Close ATA device.
Definition ata.c:594
static void atacmd_identify_done(struct ata_command *atacmd, int rc)
Handle ATA IDENTIFY command completion.
Definition ata.c:378
static const char * ata_model(struct ata_identity *identity)
Return ATA model string (for debugging)
Definition ata.c:359
static int atadev_read(struct ata_device *atadev, struct interface *block, uint64_t lba, unsigned int count, void *buffer, size_t len)
Issue ATA block read.
Definition ata.c:544
static int atadev_write(struct ata_device *atadev, struct interface *block, uint64_t lba, unsigned int count, void *buffer, size_t len)
Issue ATA block write.
Definition ata.c:563
static struct interface_operation atacmd_ata_op[]
ATA command ATA interface operations.
Definition ata.c:434
static struct interface_operation atacmd_block_op[]
ATA command block interface operations.
Definition ata.c:424
static struct interface_descriptor atacmd_block_desc
ATA command block interface descriptor.
Definition ata.c:429
static void atacmd_close(struct ata_command *atacmd, int rc)
Close ATA command.
Definition ata.c:254
static int atadev_command(struct ata_device *atadev, struct interface *block, struct ata_command_type *type, uint64_t lba, unsigned int count, void *buffer, size_t len)
Create ATA command.
Definition ata.c:455
static struct ata_command_type atacmd_identify
ATA IDENTITY command type.
Definition ata.c:413
static struct ata_command_type atacmd_read
ATA READ command type.
Definition ata.c:328
ATA devices.
#define ATA_CMD_IDENTIFY
"Identify" command
Definition ata.h:138
#define ATA_DEV_SLAVE
Slave ("device 1") flag in the ATA device register.
Definition ata.h:117
#define ATA_CMD_READ_EXT
"Read sectors (ext)" command
Definition ata.h:129
#define ATA_CMD_READ
"Read sectors" command
Definition ata.h:126
#define ATA_SECTOR_SIZE
ATA sector size.
Definition ata.h:165
#define ATA_CMD_WRITE
"Write sectors" command
Definition ata.h:132
#define ata_command_TYPE(object_type)
Definition ata.h:197
#define ATA_SUPPORTS_LBA48
Supports LBA48 flag.
Definition ata.h:162
#define ATA_DEV_OBSOLETE
Obsolete bits in the ATA device register.
Definition ata.h:111
#define ATA_CMD_WRITE_EXT
"Write sectors (ext)" command
Definition ata.h:135
#define ATA_DEV_LBA
LBA flag in the ATA device register.
Definition ata.h:114
int block_read_capacity(struct interface *control, struct interface *data)
Read block device capacity.
Definition blockdev.c:106
int block_write(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, void *buffer, size_t len)
Write to block device.
Definition blockdev.c:79
int block_read(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, void *buffer, size_t len)
Read from block device.
Definition blockdev.c:48
void block_capacity(struct interface *intf, struct block_device_capacity *capacity)
Report block device capacity.
Definition blockdev.c:130
Block devices.
ring len
Length.
Definition dwmac.h:226
int edd_describe(struct interface *intf, struct edd_interface_type *type, union edd_device_path *path)
Describe a disk device using EDD.
Definition edd.c:45
Enhanced Disk Drive specification.
uint64_t tag
Identity tag.
Definition edd.h:1
#define EDD_INTF_TYPE_ATA
EDD ATA interface type.
Definition edd.h:56
uint32_t type
Operating system type.
Definition ena.h:1
uint8_t data[48]
Additional event data.
Definition ena.h:11
Error codes.
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define DBGC2(...)
Definition compiler.h:522
#define DBGC(...)
Definition compiler.h:505
static unsigned int count
Number of entries.
Definition dwmac.h:220
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
uint64_t lba
Starting block number.
Definition int13.h:11
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define EINVAL
Invalid argument.
Definition errno.h:429
#define EOPNOTSUPP
Operation not supported on socket.
Definition errno.h:605
#define ENOMEM
Not enough space.
Definition errno.h:535
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define cpu_to_le64(value)
Definition byteswap.h:109
#define le64_to_cpu(value)
Definition byteswap.h:115
#define le32_to_cpu(value)
Definition byteswap.h:114
#define cpu_to_le16(value)
Definition byteswap.h:107
#define bswap_16(value)
Definition byteswap.h:59
#define __attribute__(x)
Definition compiler.h:10
String functions.
void * memset(void *dest, int character, size_t len) __nonnull
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition interface.c:250
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition interface.c:160
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition interface.c:150
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition interface.c:279
Object interfaces.
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition interface.h:270
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
Definition interface.h:98
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition interface.h:33
unsigned long tmp
Definition linux_pci.h:65
Linked lists.
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition list.h:459
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define LIST_HEAD(list)
Declare a static list head.
Definition list.h:38
#define list_add(new, head)
Add a new entry to the head of a list.
Definition list.h:70
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
uint8_t block[3][8]
DES-encrypted blocks.
Definition mschapv2.h:1
uint32_t control
Control.
Definition myson.h:3
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
#define ref_get(refcnt)
Get additional reference to object.
Definition refcnt.h:93
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
An ATA command information unit.
Definition ata.h:168
An ATA command type.
Definition ata.c:133
size_t priv_len
Additional working space.
Definition ata.c:137
void(* data_in)(struct ata_command *atacmd, void *buffer, size_t len, void **data_in, size_t *data_in_len)
Calculate data-in buffer.
Definition ata.c:151
uint8_t cmd_lba
Command for non-LBA48-capable devices.
Definition ata.c:139
void(* done)(struct ata_command *atacmd, int rc)
Handle ATA command completion.
Definition ata.c:173
uint8_t cmd_lba48
Command for LBA48-capable devices.
Definition ata.c:141
void(* data_out)(struct ata_command *atacmd, void *buffer, size_t len, void **data_out, size_t *data_out_len)
Calculate data-out buffer.
Definition ata.c:164
const char * name
Name.
Definition ata.c:135
An ATA command.
Definition ata.c:110
struct ata_device * atadev
ATA device.
Definition ata.c:114
struct ata_command_type * type
Command type.
Definition ata.c:124
uint32_t tag
Command tag.
Definition ata.c:126
struct interface ata
ATA data interface.
Definition ata.c:121
struct list_head list
List of ATA commands.
Definition ata.c:116
uint8_t priv[0]
Private data.
Definition ata.c:129
struct interface block
Block data interface.
Definition ata.c:119
struct refcnt refcnt
Reference count.
Definition ata.c:112
An ATA device.
Definition ata.c:90
int lba48
Device uses LBA48 extended addressing.
Definition ata.c:106
unsigned int device
Device number.
Definition ata.c:102
struct refcnt refcnt
Reference count.
Definition ata.c:92
unsigned int max_count
Maximum number of blocks per single transfer.
Definition ata.c:104
struct interface ata
ATA control interface.
Definition ata.c:96
struct interface block
Block control interface.
Definition ata.c:94
ATA IDENTIFY private data.
Definition ata.c:348
struct ata_identity identity
Identity data.
Definition ata.c:350
Structure returned by ATA IDENTIFY command.
Definition ata.h:149
uint64_t lba48_sectors
Definition ata.h:157
uint16_t model[20]
Definition ata.h:151
uint32_t lba_sectors
Definition ata.h:153
uint16_t supports_lba48
Definition ata.h:155
Block device capacity.
Definition blockdev.h:18
uint64_t blocks
Total number of blocks.
Definition blockdev.h:20
unsigned int max_count
Maximum number of blocks per single transfer.
Definition blockdev.h:24
size_t blksize
Block size.
Definition blockdev.h:22
A command-line command.
Definition command.h:10
A hardware device.
Definition device.h:77
An EDD interface type.
Definition edd.h:41
An object interface descriptor.
Definition interface.h:56
An object interface operation.
Definition interface.h:18
An object interface.
Definition interface.h:125
A doubly-linked list entry (or list head)
Definition list.h:19
A reference counter.
Definition refcnt.h:27
static struct tlan_private * priv
Definition tlan.c:225
uint32_t data_len
Microcode data size (or 0 to indicate 2000 bytes)
Definition ucode.h:15
An EDD device path.
Definition edd.h:99
uint8_t slave
Slave.
Definition edd.h:103