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 * Initialise data-in buffer
144 *
145 * @v atacmd ATA command
146 * @v xferbuf Data transfer buffer
147 * @v buffer Available buffer
148 * @v len Available buffer length
149 */
150 void ( * data_in ) ( struct ata_command *atacmd,
151 struct xfer_buffer *xferbuf,
152 void *buffer, size_t len );
153 /**
154 * Initialise data-out buffer
155 *
156 * @v atacmd ATA command
157 * @v xferbuf Data transfer buffer
158 * @v buffer Available buffer
159 * @v len Available buffer length
160 */
161 void ( * data_out ) ( struct ata_command *atacmd,
162 struct xfer_buffer *xferbuf,
163 void *buffer, size_t len );
164 /**
165 * Handle ATA command completion
166 *
167 * @v atacmd ATA command
168 * @v rc Reason for completion
169 */
170 void ( * done ) ( struct ata_command *atacmd, int rc );
171};
172
173/**
174 * Get reference to ATA device
175 *
176 * @v atadev ATA device
177 * @ret atadev ATA device
178 */
179static inline __attribute__ (( always_inline )) struct ata_device *
180atadev_get ( struct ata_device *atadev ) {
181 ref_get ( &atadev->refcnt );
182 return atadev;
183}
184
185/**
186 * Drop reference to ATA device
187 *
188 * @v atadev ATA device
189 */
190static inline __attribute__ (( always_inline )) void
191atadev_put ( struct ata_device *atadev ) {
192 ref_put ( &atadev->refcnt );
193}
194
195/**
196 * Get reference to ATA command
197 *
198 * @v atacmd ATA command
199 * @ret atacmd ATA command
200 */
201static inline __attribute__ (( always_inline )) struct ata_command *
202atacmd_get ( struct ata_command *atacmd ) {
203 ref_get ( &atacmd->refcnt );
204 return atacmd;
205}
206
207/**
208 * Drop reference to ATA command
209 *
210 * @v atacmd ATA command
211 */
212static inline __attribute__ (( always_inline )) void
213atacmd_put ( struct ata_command *atacmd ) {
214 ref_put ( &atacmd->refcnt );
215}
216
217/**
218 * Get ATA command private data
219 *
220 * @v atacmd ATA command
221 * @ret priv Private data
222 */
223static inline __attribute__ (( always_inline )) void *
224atacmd_priv ( struct ata_command *atacmd ) {
225 return atacmd->priv;
226}
227
228/**
229 * Free ATA command
230 *
231 * @v refcnt Reference count
232 */
233static void atacmd_free ( struct refcnt *refcnt ) {
234 struct ata_command *atacmd =
236
237 /* Remove from list of commands */
238 list_del ( &atacmd->list );
239 atadev_put ( atacmd->atadev );
240
241 /* Free command */
242 free ( atacmd );
243}
244
245/**
246 * Close ATA command
247 *
248 * @v atacmd ATA command
249 * @v rc Reason for close
250 */
251static void atacmd_close ( struct ata_command *atacmd, int rc ) {
252 struct ata_device *atadev = atacmd->atadev;
253
254 if ( rc != 0 ) {
255 DBGC ( atadev, "ATA %p tag %08x closed: %s\n",
256 atadev, atacmd->tag, strerror ( rc ) );
257 }
258
259 /* Shut down interfaces */
260 intf_shutdown ( &atacmd->ata, rc );
261 intf_shutdown ( &atacmd->block, rc );
262}
263
264/**
265 * Handle ATA command completion
266 *
267 * @v atacmd ATA command
268 * @v rc Reason for close
269 */
270static void atacmd_done ( struct ata_command *atacmd, int rc ) {
271
272 /* Hand over to the command completion handler */
273 atacmd->type->done ( atacmd, rc );
274}
275
276/**
277 * Use provided data buffer for ATA command
278 *
279 * @v atacmd ATA command
280 * @v xferbuf Data transfer buffer
281 * @v buffer Available buffer
282 * @v len Available buffer length
283 */
284static void atacmd_data_buffer ( struct ata_command *atacmd __unused,
285 struct xfer_buffer *xferbuf,
286 void *buffer, size_t len ) {
287 xferbuf_fixed_init ( xferbuf, buffer, len );
288}
289
290/**
291 * Use no data buffer for ATA command
292 *
293 * @v atacmd ATA command
294 * @v xferbuf Data transfer buffer
295 * @v buffer Available buffer
296 * @v len Available buffer length
297 */
298static void atacmd_data_none ( struct ata_command *atacmd __unused,
299 struct xfer_buffer *xferbuf,
300 void *buffer __unused, size_t len __unused ) {
301 xferbuf_void_init ( xferbuf );
302}
303
304/**
305 * Use private data buffer for ATA command
306 *
307 * @v atacmd ATA command
308 * @v xferbuf Data transfer buffer
309 * @v buffer Available buffer
310 * @v len Available buffer length
311 */
312static void atacmd_data_priv ( struct ata_command *atacmd,
313 struct xfer_buffer *xferbuf,
314 void *buffer __unused, size_t len __unused ) {
315
316 xferbuf_fixed_init ( xferbuf, atacmd_priv ( atacmd ),
317 atacmd->type->priv_len );
318}
319
320/** ATA READ command type */
322 .name = "READ",
323 .cmd_lba = ATA_CMD_READ,
324 .cmd_lba48 = ATA_CMD_READ_EXT,
325 .data_in = atacmd_data_buffer,
326 .data_out = atacmd_data_none,
327 .done = atacmd_close,
328};
329
330/** ATA WRITE command type */
332 .name = "WRITE",
333 .cmd_lba = ATA_CMD_WRITE,
334 .cmd_lba48 = ATA_CMD_WRITE_EXT,
335 .data_in = atacmd_data_none,
336 .data_out = atacmd_data_buffer,
337 .done = atacmd_close,
338};
339
340/** ATA IDENTIFY private data */
342 /** Identity data */
344};
345
346/**
347 * Return ATA model string (for debugging)
348 *
349 * @v identify ATA identity data
350 * @ret model Model string
351 */
352static const char * ata_model ( struct ata_identity *identity ) {
353 static union {
354 uint16_t words[ sizeof ( identity->model ) / 2 ];
355 char text[ sizeof ( identity->model ) + 1 /* NUL */ ];
356 } buf;
357 unsigned int i;
358
359 for ( i = 0 ; i < ( sizeof ( identity->model ) / 2 ) ; i++ )
360 buf.words[i] = bswap_16 ( identity->model[i] );
361
362 return buf.text;
363}
364
365/**
366 * Handle ATA IDENTIFY command completion
367 *
368 * @v atacmd ATA command
369 * @v rc Reason for completion
370 */
371static void atacmd_identify_done ( struct ata_command *atacmd, int rc ) {
372 struct ata_device *atadev = atacmd->atadev;
373 struct ata_identify_private *priv = atacmd_priv ( atacmd );
374 struct ata_identity *identity = &priv->identity;
375 struct block_device_capacity capacity;
376
377 /* Close if command failed */
378 if ( rc != 0 ) {
379 atacmd_close ( atacmd, rc );
380 return;
381 }
382
383 /* Extract capacity */
384 if ( identity->supports_lba48 & cpu_to_le16 ( ATA_SUPPORTS_LBA48 ) ) {
385 atadev->lba48 = 1;
386 capacity.blocks = le64_to_cpu ( identity->lba48_sectors );
387 } else {
388 capacity.blocks = le32_to_cpu ( identity->lba_sectors );
389 }
390 capacity.blksize = ATA_SECTOR_SIZE;
391 capacity.max_count = atadev->max_count;
392 DBGC ( atadev, "ATA %p is a %s\n", atadev, ata_model ( identity ) );
393 DBGC ( atadev, "ATA %p has %#llx blocks (%ld MB) and uses %s\n",
394 atadev, capacity.blocks,
395 ( ( signed long ) ( capacity.blocks >> 11 ) ),
396 ( atadev->lba48 ? "LBA48" : "LBA" ) );
397
398 /* Return capacity to caller */
399 block_capacity ( &atacmd->block, &capacity );
400
401 /* Close command */
402 atacmd_close ( atacmd, 0 );
403}
404
405/** ATA IDENTITY command type */
407 .name = "IDENTIFY",
408 .priv_len = sizeof ( struct ata_identify_private ),
409 .cmd_lba = ATA_CMD_IDENTIFY,
410 .cmd_lba48 = ATA_CMD_IDENTIFY,
411 .data_in = atacmd_data_priv,
412 .data_out = atacmd_data_none,
413 .done = atacmd_identify_done,
414};
415
416/** ATA command block interface operations */
419};
420
421/** ATA command block interface descriptor */
424 atacmd_block_op, ata );
425
426/** ATA command ATA interface operations */
429};
430
431/** ATA command ATA interface descriptor */
433 INTF_DESC_PASSTHRU ( struct ata_command, ata,
435
436/**
437 * Create ATA command
438 *
439 * @v atadev ATA device
440 * @v block Block data interface
441 * @v type ATA command type
442 * @v lba Starting logical block address
443 * @v count Number of blocks to transfer
444 * @v buffer Data buffer
445 * @v len Length of data buffer
446 * @ret rc Return status code
447 */
448static int atadev_command ( struct ata_device *atadev,
449 struct interface *block,
450 struct ata_command_type *type,
451 uint64_t lba, unsigned int count,
452 void *buffer, size_t len ) {
453 struct ata_command *atacmd;
454 struct ata_cmd command;
455 int tag;
456 int rc;
457
458 /* Allocate and initialise structure */
459 atacmd = zalloc ( sizeof ( *atacmd ) + type->priv_len );
460 if ( ! atacmd ) {
461 rc = -ENOMEM;
462 goto err_zalloc;
463 }
464 ref_init ( &atacmd->refcnt, atacmd_free );
465 intf_init ( &atacmd->block, &atacmd_block_desc, &atacmd->refcnt );
466 intf_init ( &atacmd->ata, &atacmd_ata_desc,
467 &atacmd->refcnt );
468 atacmd->atadev = atadev_get ( atadev );
469 list_add ( &atacmd->list, &ata_commands );
470 atacmd->type = type;
471
472 /* Sanity check */
473 if ( len != ( count * ATA_SECTOR_SIZE ) ) {
474 DBGC ( atadev, "ATA %p tag %08x buffer length mismatch (count "
475 "%d len %zd)\n", atadev, atacmd->tag, count, len );
476 rc = -EINVAL;
477 goto err_len;
478 }
479
480 /* Construct command */
481 memset ( &command, 0, sizeof ( command ) );
482 command.cb.lba.native = lba;
483 command.cb.count.native = count;
484 command.cb.device = ( atadev->device | ATA_DEV_OBSOLETE | ATA_DEV_LBA );
485 command.cb.lba48 = atadev->lba48;
486 if ( ! atadev->lba48 )
487 command.cb.device |= command.cb.lba.bytes.low_prev;
488 command.cb.cmd_stat =
489 ( atadev->lba48 ? type->cmd_lba48 : type->cmd_lba );
490 type->data_in ( atacmd, &command.data_in, buffer, len );
491 type->data_out ( atacmd, &command.data_out, buffer, len );
492
493 /* Issue command */
494 if ( ( tag = ata_command ( &atadev->ata, &atacmd->ata,
495 &command ) ) < 0 ) {
496 rc = tag;
497 DBGC ( atadev, "ATA %p tag %08x could not issue command: %s\n",
498 atadev, atacmd->tag, strerror ( rc ) );
499 goto err_command;
500 }
501 atacmd->tag = tag;
502
503 DBGC2 ( atadev, "ATA %p tag %08x %s cmd %02x dev %02x LBA%s %08llx "
504 "count %04x\n", atadev, atacmd->tag, atacmd->type->name,
505 command.cb.cmd_stat, command.cb.device,
506 ( command.cb.lba48 ? "48" : "" ),
507 ( unsigned long long ) command.cb.lba.native,
508 command.cb.count.native );
509
510 /* Attach to parent interface, mortalise self, and return */
511 intf_plug_plug ( &atacmd->block, block );
512 ref_put ( &atacmd->refcnt );
513 return 0;
514
515 err_command:
516 err_len:
517 atacmd_close ( atacmd, rc );
518 ref_put ( &atacmd->refcnt );
519 err_zalloc:
520 return rc;
521}
522
523/**
524 * Issue ATA block read
525 *
526 * @v atadev ATA device
527 * @v block Block data interface
528 * @v lba Starting logical block address
529 * @v count Number of blocks to transfer
530 * @v buffer Data buffer
531 * @v len Length of data buffer
532 * @ret rc Return status code
533
534 */
535static int atadev_read ( struct ata_device *atadev,
536 struct interface *block,
537 uint64_t lba, unsigned int count,
538 void *buffer, size_t len ) {
539 return atadev_command ( atadev, block, &atacmd_read,
540 lba, count, buffer, len );
541}
542
543/**
544 * Issue ATA block write
545 *
546 * @v atadev ATA device
547 * @v block Block data interface
548 * @v lba Starting logical block address
549 * @v count Number of blocks to transfer
550 * @v buffer Data buffer
551 * @v len Length of data buffer
552 * @ret rc Return status code
553 */
554static int atadev_write ( struct ata_device *atadev,
555 struct interface *block,
556 uint64_t lba, unsigned int count,
557 void *buffer, size_t len ) {
558 return atadev_command ( atadev, block, &atacmd_write,
559 lba, count, buffer, len );
560}
561
562/**
563 * Read ATA device capacity
564 *
565 * @v atadev ATA device
566 * @v block Block data interface
567 * @ret rc Return status code
568 */
569static int atadev_read_capacity ( struct ata_device *atadev,
570 struct interface *block ) {
571 struct ata_identity *identity;
572
573 assert ( atacmd_identify.priv_len == sizeof ( *identity ) );
574 assert ( atacmd_identify.priv_len == ATA_SECTOR_SIZE );
575 return atadev_command ( atadev, block, &atacmd_identify,
576 0, 1, NULL, ATA_SECTOR_SIZE );
577}
578
579/**
580 * Close ATA device
581 *
582 * @v atadev ATA device
583 * @v rc Reason for close
584 */
585static void atadev_close ( struct ata_device *atadev, int rc ) {
586 struct ata_command *atacmd;
587 struct ata_command *tmp;
588
589 /* Shut down interfaces */
591 intf_shutdown ( &atadev->ata, rc );
592
593 /* Shut down any remaining commands */
594 list_for_each_entry_safe ( atacmd, tmp, &ata_commands, list ) {
595 if ( atacmd->atadev != atadev )
596 continue;
597 atacmd_get ( atacmd );
598 atacmd_close ( atacmd, rc );
599 atacmd_put ( atacmd );
600 }
601}
602
603/**
604 * Describe ATA device using EDD
605 *
606 * @v atadev ATA device
607 * @v type EDD interface type
608 * @v path EDD device path
609 * @ret rc Return status code
610 */
612 struct edd_interface_type *type,
613 union edd_device_path *path ) {
614
616 path->ata.slave = ( ( atadev->device == ATA_DEV_SLAVE ) ? 0x01 : 0x00 );
617 return 0;
618}
619
620/** ATA device block interface operations */
629
630/** ATA device block interface descriptor */
633 atadev_block_op, ata );
634
635/** ATA device ATA interface operations */
638};
639
640/** ATA device ATA interface descriptor */
642 INTF_DESC_PASSTHRU ( struct ata_device, ata,
644
645/**
646 * Open ATA device
647 *
648 * @v block Block control interface
649 * @v ata ATA control interface
650 * @v device ATA device number
651 * @v max_count Maximum number of blocks per single transfer
652 * @ret rc Return status code
653 */
654int ata_open ( struct interface *block, struct interface *ata,
655 unsigned int device, unsigned int max_count ) {
656 struct ata_device *atadev;
657
658 /* Allocate and initialise structure */
659 atadev = zalloc ( sizeof ( *atadev ) );
660 if ( ! atadev )
661 return -ENOMEM;
662 ref_init ( &atadev->refcnt, NULL );
663 intf_init ( &atadev->block, &atadev_block_desc, &atadev->refcnt );
664 intf_init ( &atadev->ata, &atadev_ata_desc, &atadev->refcnt );
665 atadev->device = device;
666 atadev->max_count = max_count;
667
668 /* Attach to ATA and parent and interfaces, mortalise self,
669 * and return
670 */
671 intf_plug_plug ( &atadev->ata, ata );
672 intf_plug_plug ( &atadev->block, block );
673 ref_put ( &atadev->refcnt );
674 return 0;
675}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
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:61
static struct ata_command * atacmd_get(struct ata_command *atacmd)
Get reference to ATA command.
Definition ata.c:202
static void atacmd_free(struct refcnt *refcnt)
Free ATA command.
Definition ata.c:233
static void atacmd_data_buffer(struct ata_command *atacmd __unused, struct xfer_buffer *xferbuf, void *buffer, size_t len)
Use provided data buffer for ATA command.
Definition ata.c:284
static void atadev_put(struct ata_device *atadev)
Drop reference to ATA device.
Definition ata.c:191
static int atadev_read_capacity(struct ata_device *atadev, struct interface *block)
Read ATA device capacity.
Definition ata.c:569
int ata_command(struct interface *control, struct interface *data, struct ata_cmd *command)
Issue ATA command.
Definition ata.c:60
int ata_open(struct interface *block, struct interface *ata, unsigned int device, unsigned int max_count)
Open ATA device.
Definition ata.c:654
static struct interface_operation atadev_block_op[]
ATA device block interface operations.
Definition ata.c:621
static struct interface_descriptor atadev_ata_desc
ATA device ATA interface descriptor.
Definition ata.c:641
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:611
static struct ata_command_type atacmd_write
ATA WRITE command type.
Definition ata.c:331
static struct interface_descriptor atadev_block_desc
ATA device block interface descriptor.
Definition ata.c:631
static struct interface_descriptor atacmd_ata_desc
ATA command ATA interface descriptor.
Definition ata.c:432
static struct ata_device * atadev_get(struct ata_device *atadev)
Get reference to ATA device.
Definition ata.c:180
static void atacmd_done(struct ata_command *atacmd, int rc)
Handle ATA command completion.
Definition ata.c:270
static void atacmd_put(struct ata_command *atacmd)
Drop reference to ATA command.
Definition ata.c:213
static void atacmd_data_none(struct ata_command *atacmd __unused, struct xfer_buffer *xferbuf, void *buffer __unused, size_t len __unused)
Use no data buffer for ATA command.
Definition ata.c:298
static struct interface_operation atadev_ata_op[]
ATA device ATA interface operations.
Definition ata.c:636
static void atadev_close(struct ata_device *atadev, int rc)
Close ATA device.
Definition ata.c:585
static void atacmd_identify_done(struct ata_command *atacmd, int rc)
Handle ATA IDENTIFY command completion.
Definition ata.c:371
static const char * ata_model(struct ata_identity *identity)
Return ATA model string (for debugging).
Definition ata.c:352
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:535
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:554
static void * atacmd_priv(struct ata_command *atacmd)
Get ATA command private data.
Definition ata.c:224
static struct interface_operation atacmd_ata_op[]
ATA command ATA interface operations.
Definition ata.c:427
static struct interface_operation atacmd_block_op[]
ATA command block interface operations.
Definition ata.c:417
static struct interface_descriptor atacmd_block_desc
ATA command block interface descriptor.
Definition ata.c:422
static void atacmd_close(struct ata_command *atacmd, int rc)
Close ATA command.
Definition ata.c:251
static void atacmd_data_priv(struct ata_command *atacmd, struct xfer_buffer *xferbuf, void *buffer __unused, size_t len __unused)
Use private data buffer for ATA command.
Definition ata.c:312
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:448
static struct ata_command_type atacmd_identify
ATA IDENTITY command type.
Definition ata.c:406
static struct ata_command_type atacmd_read
ATA READ command type.
Definition ata.c:321
ATA devices.
#define ATA_CMD_IDENTIFY
"Identify" command
Definition ata.h:139
#define ATA_DEV_SLAVE
Slave ("device 1") flag in the ATA device register.
Definition ata.h:118
#define ATA_CMD_READ_EXT
"Read sectors (ext)" command
Definition ata.h:130
#define ATA_CMD_READ
"Read sectors" command
Definition ata.h:127
#define ATA_SECTOR_SIZE
ATA sector size.
Definition ata.h:166
#define ATA_CMD_WRITE
"Write sectors" command
Definition ata.h:133
#define ata_command_TYPE(object_type)
Definition ata.h:180
#define ATA_SUPPORTS_LBA48
Supports LBA48 flag.
Definition ata.h:163
#define ATA_DEV_OBSOLETE
Obsolete bits in the ATA device register.
Definition ata.h:112
#define ATA_CMD_WRITE_EXT
"Write sectors (ext)" command
Definition ata.h:136
#define ATA_DEV_LBA
LBA flag in the ATA device register.
Definition ata.h:115
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:598
#define DBGC2(...)
Definition compiler.h:547
#define DBGC(...)
Definition compiler.h:530
uint64_t lba
Starting block number.
Definition int13.h:11
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
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define EINVAL
Invalid argument.
Definition errno.h:472
#define EOPNOTSUPP
Operation not supported on socket.
Definition errno.h:648
#define ENOMEM
Not enough space.
Definition errno.h:578
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#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:718
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:169
An ATA command type.
Definition ata.c:133
size_t priv_len
Additional working space.
Definition ata.c:137
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:170
uint8_t cmd_lba48
Command for LBA48-capable devices.
Definition ata.c:141
void(* data_in)(struct ata_command *atacmd, struct xfer_buffer *xferbuf, void *buffer, size_t len)
Initialise data-in buffer.
Definition ata.c:150
void(* data_out)(struct ata_command *atacmd, struct xfer_buffer *xferbuf, void *buffer, size_t len)
Initialise data-out buffer.
Definition ata.c:161
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:341
struct ata_identity identity
Identity data.
Definition ata.c:343
Structure returned by ATA IDENTIFY command.
Definition ata.h:150
uint64_t lba48_sectors
Definition ata.h:158
uint16_t model[20]
Definition ata.h:152
uint32_t lba_sectors
Definition ata.h:154
uint16_t supports_lba48
Definition ata.h:156
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
A data transfer buffer.
Definition xferbuf.h:21
static struct tlan_private * priv
Definition tlan.c:225
An EDD device path.
Definition edd.h:99
uint8_t slave
Slave.
Definition edd.h:103
static void xferbuf_fixed_init(struct xfer_buffer *xferbuf, void *data, size_t len)
Initialise fixed-size data transfer buffer.
Definition xferbuf.h:93
static void xferbuf_void_init(struct xfer_buffer *xferbuf)
Initialise void data transfer buffer.
Definition xferbuf.h:108