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